opshared.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* opshared.c - functions shared between regular and internal operations */
  13. #include "slap.h"
  14. #include "index_subsys.h"
  15. #define PAGEDRESULTS_PAGE_END 1
  16. #define PAGEDRESULTS_SEARCH_END 2
  17. /* helper functions */
  18. static void compute_limits (Slapi_PBlock *pb);
  19. /* attributes that no clients are allowed to add or modify */
  20. static char *protected_attrs_all [] = { PSEUDO_ATTR_UNHASHEDUSERPASSWORD,
  21. NULL };
  22. static char *pwpolicy_lock_attrs_all [] = { "passwordRetryCount",
  23. "retryCountResetTime",
  24. "accountUnlockTime",
  25. NULL};
  26. /* Forward declarations */
  27. static void compute_limits (Slapi_PBlock *pb);
  28. static int send_results_ext (Slapi_PBlock *pb, int send_result, int *nentries, int pagesize, unsigned int *pr_stat);
  29. static int process_entry(Slapi_PBlock *pb, Slapi_Entry *e, int send_result);
  30. int op_shared_is_allowed_attr (const char *attr_name, int replicated_op)
  31. {
  32. int i;
  33. slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
  34. /* ONREPL - should allow backends to plugin here to specify
  35. attributes that are not allowed */
  36. if (!replicated_op) {
  37. struct asyntaxinfo *asi;
  38. int no_user_mod = 0;
  39. /* check list of attributes that no client is allowed to specify */
  40. for (i = 0; protected_attrs_all[i]; i ++) {
  41. if (strcasecmp (attr_name, protected_attrs_all[i]) == 0) {
  42. /* this attribute is not allowed */
  43. return 0;
  44. }
  45. }
  46. /*
  47. * check to see if attribute is marked as one clients can't modify
  48. */
  49. asi = attr_syntax_get_by_name( attr_name, 0 );
  50. if ( NULL != asi &&
  51. 0 != ( asi->asi_flags & SLAPI_ATTR_FLAG_NOUSERMOD )) {
  52. /* this attribute is not allowed */
  53. no_user_mod = 1;
  54. }
  55. attr_syntax_return( asi );
  56. if ( no_user_mod ) {
  57. return( 0 );
  58. }
  59. } else if (!slapdFrontendConfig->pw_is_global_policy) {
  60. /* check list of password policy attributes for locking accounts */
  61. for (i = 0; pwpolicy_lock_attrs_all[i]; i ++)
  62. {
  63. if (strcasecmp (attr_name, pwpolicy_lock_attrs_all[i]) == 0)
  64. {
  65. /* this attribute is not allowed */
  66. return 0;
  67. }
  68. }
  69. }
  70. /* this attribute is ok */
  71. return 1;
  72. }
  73. static ps_service_fn_ptr ps_service_fn = NULL;
  74. void
  75. do_ps_service(Slapi_Entry *e, Slapi_Entry *eprev, ber_int_t chgtype, ber_int_t chgnum)
  76. {
  77. if (NULL == ps_service_fn) {
  78. if (get_entry_point(ENTRY_POINT_PS_SERVICE, (caddr_t *)(&ps_service_fn)) < 0) {
  79. return;
  80. }
  81. }
  82. (ps_service_fn)(e, eprev, chgtype, chgnum);
  83. }
  84. void
  85. modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
  86. {
  87. char buf[20];
  88. char *plugin_dn = NULL;
  89. char *binddn = NULL;
  90. struct berval bv;
  91. struct berval *bvals[2];
  92. time_t curtime;
  93. struct tm utm;
  94. Operation *op;
  95. struct slapdplugin *plugin = NULL;
  96. struct slapi_componentid *cid = NULL;
  97. slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
  98. LDAPDebug(LDAP_DEBUG_TRACE, "modify_update_last_modified_attr\n", 0, 0, 0);
  99. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  100. bvals[0] = &bv;
  101. bvals[1] = NULL;
  102. if(slapdFrontendConfig->plugin_track){
  103. /* plugin bindDN tracking is enabled, grab the bind dn from thread local storage */
  104. if(slapi_sdn_isempty(&op->o_sdn)){
  105. bv.bv_val = "";
  106. bv.bv_len = 0;
  107. } else {
  108. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &cid);
  109. if (cid){
  110. plugin=(struct slapdplugin *) cid->sci_plugin;
  111. } else {
  112. slapi_pblock_get (pb, SLAPI_PLUGIN, &plugin);
  113. }
  114. if(plugin)
  115. plugin_dn = plugin_get_dn (plugin);
  116. if(plugin_dn){
  117. bv.bv_val = plugin_dn;
  118. bv.bv_len = strlen(bv.bv_val);
  119. } else {
  120. bv.bv_val = (char*)slapi_sdn_get_dn(&op->o_sdn);
  121. bv.bv_len = strlen(bv.bv_val);
  122. }
  123. }
  124. slapi_mods_add_modbvps(smods, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES,
  125. "internalModifiersName", bvals);
  126. slapi_ch_free_string(&plugin_dn);
  127. /* Grab the thread data(binddn) */
  128. slapi_td_get_dn(&binddn);
  129. if(binddn == NULL){
  130. /* anonymous bind */
  131. bv.bv_val = "";
  132. bv.bv_len = 0;
  133. } else {
  134. bv.bv_val = binddn;
  135. bv.bv_len = strlen(bv.bv_val);
  136. }
  137. } else {
  138. /* fill in modifiersname */
  139. if (slapi_sdn_isempty(&op->o_sdn)) {
  140. bv.bv_val = "";
  141. bv.bv_len = 0;
  142. } else {
  143. bv.bv_val = (char*)slapi_sdn_get_dn(&op->o_sdn);
  144. bv.bv_len = strlen(bv.bv_val);
  145. }
  146. }
  147. slapi_mods_add_modbvps(smods, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES,
  148. "modifiersname", bvals);
  149. /* fill in modifytimestamp */
  150. curtime = current_time();
  151. gmtime_r(&curtime, &utm);
  152. strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", &utm);
  153. bv.bv_val = buf;
  154. bv.bv_len = strlen(bv.bv_val);
  155. slapi_mods_add_modbvps(smods, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES,
  156. "modifytimestamp", bvals);
  157. }
  158. /*
  159. * If the attribute is one of the last mod attributes return 1,
  160. * otherwise return 0;
  161. */
  162. int
  163. slapi_attr_is_last_mod(char *attr)
  164. {
  165. if(strcasecmp (attr, "modifytimestamp") == 0 ||
  166. strcasecmp (attr, "modifiersname") == 0 ||
  167. strcasecmp (attr, "internalmodifytimestamp") == 0 ||
  168. strcasecmp (attr, "internalmodifiersname") == 0)
  169. {
  170. return 1;
  171. }
  172. return 0;
  173. }
  174. /*
  175. * Returns: 0 - if the operation is successful
  176. * < 0 - if operation fails.
  177. * Note that an operation is considered "failed" if a result is sent
  178. * directly to the client when send_result is 0.
  179. */
  180. void
  181. op_shared_search (Slapi_PBlock *pb, int send_result)
  182. {
  183. char *base = NULL;
  184. const char *normbase = NULL;
  185. char *fstr;
  186. int scope;
  187. Slapi_Backend *be = NULL;
  188. Slapi_Backend *be_single = NULL;
  189. Slapi_Backend *be_list[BE_LIST_SIZE+1];
  190. Slapi_Entry *referral_list[BE_LIST_SIZE+1];
  191. char attrlistbuf[ 1024 ], *attrliststr, **attrs = NULL;
  192. int rc = 0;
  193. int internal_op;
  194. Slapi_DN *basesdn = NULL;
  195. Slapi_DN *sdn = NULL;
  196. Slapi_Operation *operation = NULL;
  197. Slapi_Entry *referral = NULL;
  198. char *proxydn = NULL;
  199. char *proxystr = NULL;
  200. int proxy_err = LDAP_SUCCESS;
  201. char *errtext = NULL;
  202. char errorbuf[BUFSIZ];
  203. int nentries,pnentries;
  204. int flag_search_base_found = 0;
  205. int flag_no_such_object = 0;
  206. int flag_referral = 0;
  207. int flag_psearch = 0;
  208. int err_code = LDAP_SUCCESS;
  209. LDAPControl **ctrlp;
  210. struct berval *ctl_value = NULL;
  211. int iscritical = 0;
  212. char *be_name = NULL;
  213. int index = 0;
  214. int sent_result = 0;
  215. unsigned int pr_stat = 0;
  216. ber_int_t pagesize = -1;
  217. ber_int_t estimate = 0; /* estimated search result set size */
  218. int curr_search_count = 0;
  219. Slapi_Backend *pr_be = NULL;
  220. void *pr_search_result = NULL;
  221. int pr_idx = -1;
  222. Slapi_DN *orig_sdn = NULL;
  223. int free_sdn = 0;
  224. be_list[0] = NULL;
  225. referral_list[0] = NULL;
  226. /* get search parameters */
  227. slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET_DN, &base);
  228. slapi_pblock_get(pb, SLAPI_SEARCH_TARGET_SDN, &sdn);
  229. if (NULL == sdn) {
  230. sdn = slapi_sdn_new_dn_byval(base);
  231. slapi_pblock_set(pb, SLAPI_SEARCH_TARGET_SDN, sdn);
  232. free_sdn = 1;
  233. } else {
  234. /* save it so we can restore it later - may have to replace it internally
  235. e.g. for onelevel and subtree searches, but need to restore it */
  236. orig_sdn = sdn;
  237. }
  238. normbase = slapi_sdn_get_dn(sdn);
  239. if (base && (strlen(base) > 0) && (NULL == normbase)) {
  240. /* normalization failed */
  241. op_shared_log_error_access(pb, "SRCH", base, "invalid dn");
  242. send_ldap_result(pb, LDAP_INVALID_DN_SYNTAX, NULL, "invalid dn", 0, NULL);
  243. rc = -1;
  244. goto free_and_return_nolock;
  245. }
  246. basesdn = slapi_sdn_dup(sdn);
  247. slapi_pblock_get(pb, SLAPI_SEARCH_SCOPE, &scope);
  248. slapi_pblock_get(pb, SLAPI_SEARCH_STRFILTER, &fstr);
  249. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRS, &attrs);
  250. slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
  251. internal_op= operation_is_flag_set(operation, OP_FLAG_INTERNAL);
  252. flag_psearch = operation_is_flag_set(operation, OP_FLAG_PS);
  253. /* get the proxy auth dn if the proxy auth control is present */
  254. proxy_err = proxyauth_get_dn(pb, &proxydn, &errtext);
  255. if (operation_is_flag_set(operation,OP_FLAG_ACTION_LOG_ACCESS))
  256. {
  257. char *fmtstr;
  258. #define SLAPD_SEARCH_FMTSTR_BASE "conn=%" NSPRIu64 " op=%d SRCH base=\"%s\" scope=%d "
  259. #define SLAPD_SEARCH_FMTSTR_BASE_INT "conn=%s op=%d SRCH base=\"%s\" scope=%d "
  260. #define SLAPD_SEARCH_FMTSTR_REMAINDER " attrs=%s%s%s\n"
  261. PR_ASSERT(fstr);
  262. if ( strlen(fstr) > 1024 )
  263. {
  264. /*
  265. * slapi_log_access() throws away log lines that are longer than
  266. * 2048 characters, so we limit the filter string to 1024 (better
  267. * to log something rather than nothing)
  268. */
  269. if ( !internal_op )
  270. {
  271. fmtstr = SLAPD_SEARCH_FMTSTR_BASE "filter=\"%.1024s...\"" SLAPD_SEARCH_FMTSTR_REMAINDER;
  272. }
  273. else
  274. {
  275. fmtstr = SLAPD_SEARCH_FMTSTR_BASE_INT "filter=\"%.1024s...\"" SLAPD_SEARCH_FMTSTR_REMAINDER;
  276. }
  277. } else {
  278. if ( !internal_op )
  279. {
  280. fmtstr = SLAPD_SEARCH_FMTSTR_BASE "filter=\"%s\"" SLAPD_SEARCH_FMTSTR_REMAINDER;
  281. }
  282. else
  283. {
  284. fmtstr = SLAPD_SEARCH_FMTSTR_BASE_INT "filter=\"%s\"" SLAPD_SEARCH_FMTSTR_REMAINDER;
  285. }
  286. }
  287. if ( NULL == attrs ) {
  288. attrliststr = "ALL";
  289. } else {
  290. strarray2str( attrs, attrlistbuf, sizeof( attrlistbuf ),
  291. 1 /* include quotes */ );
  292. attrliststr = attrlistbuf;
  293. }
  294. if (proxydn)
  295. {
  296. proxystr = slapi_ch_smprintf(" authzid=\"%s\"", proxydn);
  297. }
  298. if ( !internal_op )
  299. {
  300. slapi_log_access(LDAP_DEBUG_STATS, fmtstr,
  301. pb->pb_conn->c_connid,
  302. pb->pb_op->o_opid,
  303. normbase,
  304. scope, fstr, attrliststr,
  305. flag_psearch ? " options=persistent" : "",
  306. proxystr ? proxystr : "");
  307. }
  308. else
  309. {
  310. slapi_log_access(LDAP_DEBUG_ARGS, fmtstr,
  311. LOG_INTERNAL_OP_CON_ID,
  312. LOG_INTERNAL_OP_OP_ID,
  313. normbase,
  314. scope, fstr, attrliststr,
  315. flag_psearch ? " options=persistent" : "",
  316. proxystr ? proxystr : "");
  317. }
  318. }
  319. /* If we encountered an error parsing the proxy control, return an error
  320. * to the client. We do this here to ensure that we log the operation first.
  321. */
  322. if (proxy_err != LDAP_SUCCESS)
  323. {
  324. rc = -1;
  325. send_ldap_result(pb, proxy_err, NULL, errtext, 0, NULL);
  326. goto free_and_return_nolock;
  327. }
  328. /* target spec is used to decide which plugins are applicable for
  329. * the operation. basesdn is duplicated and set to target spec.
  330. */
  331. operation_set_target_spec (pb->pb_op, basesdn);
  332. /*
  333. * this is time to check if mapping tree specific control was used to
  334. * specify that we want to parse only one backend.
  335. */
  336. slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
  337. if (ctrlp)
  338. {
  339. if (slapi_control_present(ctrlp, MTN_CONTROL_USE_ONE_BACKEND_EXT_OID,
  340. &ctl_value, &iscritical))
  341. {
  342. /* this control is the smart version of MTN_CONTROL_USE_ONE_BACKEND_OID,
  343. * it works out for itself what back end is required (thereby relieving
  344. * the client of working out which backend it needs) by looking at the
  345. * base of the search if no value is supplied
  346. */
  347. if((ctl_value->bv_len != 0) && ctl_value->bv_val)
  348. {
  349. be_name = ctl_value->bv_val;
  350. }
  351. else
  352. {
  353. /* we don't need no steenkin values */
  354. Slapi_Backend *searchbe = slapi_be_select( sdn );
  355. if(searchbe && searchbe != defbackend_get_backend())
  356. {
  357. be_name = slapi_be_get_name(searchbe);
  358. }
  359. }
  360. }
  361. else
  362. {
  363. if (slapi_control_present(ctrlp, MTN_CONTROL_USE_ONE_BACKEND_OID,
  364. &ctl_value, &iscritical))
  365. {
  366. if ((ctl_value->bv_len == 0) || (ctl_value->bv_val == NULL))
  367. {
  368. rc = -1;
  369. if (iscritical)
  370. send_ldap_result(pb, LDAP_UNAVAILABLE_CRITICAL_EXTENSION, NULL, NULL, 0, NULL);
  371. else
  372. send_ldap_result(pb, LDAP_PROTOCOL_ERROR, NULL, NULL, 0, NULL);
  373. goto free_and_return_nolock;
  374. }
  375. else
  376. {
  377. be_name = ctl_value->bv_val;
  378. if (be_name == NULL)
  379. {
  380. rc = -1;
  381. if (iscritical)
  382. send_ldap_result(pb, LDAP_UNAVAILABLE_CRITICAL_EXTENSION, NULL, NULL, 0, NULL);
  383. else
  384. send_ldap_result(pb, LDAP_PROTOCOL_ERROR, NULL, NULL, 0, NULL);
  385. goto free_and_return_nolock;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. if (be_name == NULL) {
  392. /* no specific backend was requested, use the mapping tree
  393. */
  394. err_code = slapi_mapping_tree_select_all(pb, be_list, referral_list, errorbuf);
  395. if (((err_code != LDAP_SUCCESS) && (err_code != LDAP_OPERATIONS_ERROR) && (err_code != LDAP_REFERRAL))
  396. || ((err_code == LDAP_OPERATIONS_ERROR) && (be_list[0] == NULL))) {
  397. send_ldap_result(pb, err_code, NULL, errorbuf, 0, NULL);
  398. rc = -1;
  399. goto free_and_return;
  400. }
  401. if (be_list[0] != NULL) {
  402. index = 0;
  403. while (be_list[index] && be_list[index+1]) {
  404. index++;
  405. }
  406. be = be_list[index];
  407. } else {
  408. be = NULL;
  409. }
  410. } else {
  411. /* specific backend be_name was requested, use slapi_be_select_by_instance_name
  412. */
  413. be_single = be = slapi_be_select_by_instance_name(be_name);
  414. if (be_single) {
  415. slapi_be_Rlock(be_single);
  416. }
  417. be_list[0] = NULL;
  418. referral_list[0] = NULL;
  419. referral = NULL;
  420. }
  421. /* Handle the rest of the controls. */
  422. if (ctrlp)
  423. {
  424. if ( slapi_control_present (ctrlp, LDAP_CONTROL_GET_EFFECTIVE_RIGHTS,
  425. &ctl_value, &iscritical) )
  426. {
  427. operation->o_flags |= OP_FLAG_GET_EFFECTIVE_RIGHTS;
  428. }
  429. if ( slapi_control_present (ctrlp, LDAP_CONTROL_PAGEDRESULTS,
  430. &ctl_value, &iscritical) )
  431. {
  432. /* be is set only when this request is new. otherwise, prev be is honored. */
  433. rc = pagedresults_parse_control_value(pb, ctl_value, &pagesize, &pr_idx, be);
  434. /* Let's set pr_idx even if it fails; in case, pr_idx == -1. */
  435. slapi_pblock_set(pb, SLAPI_PAGED_RESULTS_INDEX, &pr_idx);
  436. if ((LDAP_SUCCESS == rc) || (LDAP_CANCELLED == rc) || (0 == pagesize)) {
  437. unsigned int opnote = SLAPI_OP_NOTE_SIMPLEPAGED;
  438. op_set_pagedresults(operation);
  439. pr_be = pagedresults_get_current_be(pb->pb_conn, pr_idx);
  440. if (be_name) {
  441. if (pr_be != be_single) {
  442. slapi_be_Unlock(be_single);
  443. be_single = be = pr_be;
  444. slapi_be_Rlock(be_single);
  445. }
  446. } else if (be_list[0]) {
  447. if (pr_be) { /* PAGED RESULT: be is found from the previous paging. */
  448. /* move the index in the be_list which matches pr_be */
  449. index = 0;
  450. while (be_list[index] && be_list[index+1] && pr_be != be_list[index]) {
  451. index++;
  452. }
  453. be = be_list[index];
  454. }
  455. }
  456. pr_search_result = pagedresults_get_search_result(pb->pb_conn, operation, 0/*not locked*/, pr_idx);
  457. estimate = pagedresults_get_search_result_set_size_estimate(pb->pb_conn, operation, pr_idx);
  458. if (pagedresults_get_unindexed(pb->pb_conn, operation, pr_idx)) {
  459. opnote |= SLAPI_OP_NOTE_UNINDEXED;
  460. }
  461. slapi_pblock_set( pb, SLAPI_OPERATION_NOTES, &opnote );
  462. if ((LDAP_CANCELLED == rc) || (0 == pagesize)) {
  463. /* paged-results-request was abandoned; making an empty cookie. */
  464. pagedresults_set_response_control(pb, 0, estimate, -1, pr_idx);
  465. send_ldap_result(pb, 0, NULL,
  466. "Simple Paged Results Search abandoned",
  467. 0, NULL);
  468. rc = LDAP_SUCCESS;
  469. goto free_and_return;
  470. }
  471. } else if (LDAP_UNWILLING_TO_PERFORM == rc) {
  472. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  473. "Simple Paged Results Search exceeded administration limit",
  474. 0, NULL);
  475. goto free_and_return;
  476. } else {
  477. /* parse paged-results-control failed */
  478. if (iscritical) { /* return an error since it's critical */
  479. send_ldap_result(pb, LDAP_UNAVAILABLE_CRITICAL_EXTENSION, NULL,
  480. "Simple Paged Results Search failed",
  481. 0, NULL);
  482. goto free_and_return;
  483. }
  484. }
  485. }
  486. }
  487. slapi_pblock_set(pb, SLAPI_BACKEND_COUNT, &index);
  488. if (be)
  489. {
  490. slapi_pblock_set(pb, SLAPI_BACKEND, be);
  491. /* adjust time and size limits */
  492. compute_limits (pb);
  493. /* set the timelimit to clean up the too-long-lived-paged results requests */
  494. if (op_is_pagedresults(operation)) {
  495. time_t optime, time_up;
  496. int tlimit;
  497. slapi_pblock_get( pb, SLAPI_SEARCH_TIMELIMIT, &tlimit );
  498. slapi_pblock_get( pb, SLAPI_OPINITIATED_TIME, &optime );
  499. time_up = (tlimit==-1 ? -1 : optime + tlimit); /* -1: no time limit */
  500. pagedresults_set_timelimit(pb->pb_conn, pb->pb_op, time_up, pr_idx);
  501. }
  502. /*
  503. * call the pre-search plugins. if they succeed, call the backend
  504. * search function. then call the post-search plugins.
  505. */
  506. /* ONREPL - should regular plugin be called for internal searches ? */
  507. if (plugin_call_plugins(pb, SLAPI_PLUGIN_PRE_SEARCH_FN) == 0)
  508. {
  509. slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
  510. set_db_default_result_handlers(pb);
  511. /* Now would be a good time to call the search rewriters for computed attrs */
  512. rc = compute_rewrite_search_filter(pb);
  513. switch (rc)
  514. {
  515. case 1: /* A rewriter says that we should refuse to perform this search.
  516. The potential exists that we will refuse to perform a search
  517. which we were going to refer, perhaps to a server which would
  518. be willing to perform the search. That's bad. The rewriter
  519. could be clever enough to spot this and do the right thing though. */
  520. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, "Search not supported", 0, NULL);
  521. rc = -1;
  522. goto free_and_return;
  523. case -2: /* memory was allocated */
  524. /* take note of any changes */
  525. slapi_pblock_get(pb, SLAPI_SEARCH_TARGET_SDN, &sdn);
  526. slapi_pblock_get(pb, SLAPI_SEARCH_SCOPE, &scope);
  527. if (NULL == sdn) {
  528. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  529. "target dn is lost", 0, NULL);
  530. rc = -1;
  531. goto free_and_return;
  532. }
  533. if (slapi_sdn_compare(basesdn, sdn)) {
  534. slapi_sdn_free(&basesdn);
  535. basesdn = operation_get_target_spec(pb->pb_op);
  536. slapi_sdn_free(&basesdn);
  537. basesdn = slapi_sdn_dup(sdn);
  538. operation_set_target_spec (pb->pb_op, basesdn);
  539. }
  540. break;
  541. case -1:
  542. case 0: /* OK */
  543. break;
  544. case 2: /* Operations error */
  545. send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, "search rewriter", 0, NULL);
  546. rc = -1;
  547. goto free_and_return;
  548. }
  549. } else {
  550. /*
  551. * A pre-operation plugin handled this search. Grab the return code
  552. * (it may have been set by a plugin) and return.
  553. *
  554. * In DS 5.x, the following two lines of code did not exist, which
  555. * means a pre-search function might return a non-zero value (which
  556. * indicates that a result was returned to the client) but the code
  557. * below would execute the search anyway. This was a regression from
  558. * the documented plugin API behavior (and from DS 3.x and 4.x).
  559. */
  560. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &rc);
  561. goto free_and_return;
  562. }
  563. }
  564. /* PAR: now filters have been rewritten, we can assign plugins to work on them */
  565. index_subsys_assign_filter_decoders(pb);
  566. nentries = 0;
  567. rc = -1; /* zero backends would mean failure */
  568. while (be)
  569. {
  570. const Slapi_DN *be_suffix;
  571. int err = 0;
  572. Slapi_Backend *next_be = NULL;
  573. if (be->be_search == NULL)
  574. {
  575. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, "Function not implemented", 0, NULL);
  576. rc = -1;
  577. goto free_and_return;
  578. }
  579. pnentries = 0;
  580. /* the backends returns no such object when a
  581. * search is attempted in a node above their nsslapd-suffix
  582. * this is correct but a bit annoying when a backends
  583. * is below another backend because in that case the
  584. * such searches should sometimes succeed
  585. * To allow this we therefore have to change the
  586. * SLAPI_SEARCH_TARGET_SDN parameter in the pblock
  587. *
  588. * Also when we climb down the mapping tree we have to
  589. * change ONE-LEVEL searches to BASE
  590. */
  591. /* that means we only support one suffix per backend */
  592. be_suffix = slapi_be_getsuffix(be, 0);
  593. if (be_list[0] == NULL)
  594. {
  595. next_be = NULL;
  596. }
  597. else
  598. {
  599. index--;
  600. if (index>=0)
  601. next_be = be_list[index];
  602. else
  603. next_be = NULL;
  604. }
  605. if (op_is_pagedresults(operation) && pr_search_result) {
  606. void *sr = NULL;
  607. /* PAGED RESULTS and already have the search results from the prev op */
  608. pagedresults_lock(pb->pb_conn, pr_idx);
  609. /*
  610. * In async paged result case, the search result might be released
  611. * by other theads. We need to double check it in the locked region.
  612. */
  613. PR_EnterMonitor(pb->pb_conn->c_mutex);
  614. pr_search_result = pagedresults_get_search_result(pb->pb_conn, operation, 1/*locked*/, pr_idx);
  615. if (pr_search_result) {
  616. if (pagedresults_is_abandoned_or_notavailable(pb->pb_conn, 1/*locked*/, pr_idx)) {
  617. pagedresults_unlock(pb->pb_conn, pr_idx);
  618. /* Previous operation was abandoned and the simplepaged object is not in use. */
  619. send_ldap_result(pb, 0, NULL, "Simple Paged Results Search abandoned", 0, NULL);
  620. rc = LDAP_SUCCESS;
  621. PR_ExitMonitor(pb->pb_conn->c_mutex);
  622. goto free_and_return;
  623. } else {
  624. slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET, pr_search_result );
  625. rc = send_results_ext (pb, 1, &pnentries, pagesize, &pr_stat);
  626. /* search result could be reset in the backend/dse */
  627. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_SET, &sr);
  628. pagedresults_set_search_result(pb->pb_conn, operation, sr, 1/*locked*/, pr_idx);
  629. PR_ExitMonitor(pb->pb_conn->c_mutex);
  630. }
  631. } else {
  632. pr_stat = PAGEDRESULTS_SEARCH_END;
  633. }
  634. pagedresults_unlock(pb->pb_conn, pr_idx);
  635. if (PAGEDRESULTS_SEARCH_END == pr_stat) {
  636. /* no more entries to send in the backend */
  637. if (NULL == next_be) {
  638. /* no more entries && no more backends */
  639. curr_search_count = -1;
  640. } else {
  641. curr_search_count = pnentries;
  642. }
  643. estimate = 0;
  644. } else {
  645. curr_search_count = pnentries;
  646. estimate -= estimate?curr_search_count:0;
  647. }
  648. pagedresults_set_response_control(pb, 0, estimate,
  649. curr_search_count, pr_idx);
  650. if (pagedresults_get_with_sort(pb->pb_conn, operation, pr_idx)) {
  651. sort_make_sort_response_control(pb, CONN_GET_SORT_RESULT_CODE, NULL);
  652. }
  653. pagedresults_set_search_result_set_size_estimate(pb->pb_conn,
  654. operation,
  655. estimate, pr_idx);
  656. if (PAGEDRESULTS_SEARCH_END == pr_stat) {
  657. pagedresults_lock(pb->pb_conn, pr_idx);
  658. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_SET, NULL);
  659. if (!pagedresults_is_abandoned_or_notavailable(pb->pb_conn, 0/*not locked*/, pr_idx)) {
  660. pagedresults_free_one(pb->pb_conn, operation, pr_idx);
  661. }
  662. pagedresults_unlock(pb->pb_conn, pr_idx);
  663. if (next_be) {
  664. /* no more entries, but at least another backend */
  665. if (pagedresults_set_current_be(pb->pb_conn, next_be, pr_idx, 0) < 0) {
  666. goto free_and_return;
  667. }
  668. }
  669. next_be = NULL; /* to break the loop */
  670. } else if (PAGEDRESULTS_PAGE_END == pr_stat) {
  671. next_be = NULL; /* to break the loop */
  672. }
  673. } else {
  674. /* be_suffix null means that we are searching the default backend
  675. * -> don't change the search parameters in pblock
  676. */
  677. if (be_suffix != NULL)
  678. {
  679. if ((be_name == NULL) && (scope == LDAP_SCOPE_ONELEVEL))
  680. {
  681. /* one level searches
  682. * - depending on the suffix of the backend we might have to
  683. * do a one level search or a base search
  684. * - we might also have to change the search target
  685. */
  686. if (slapi_sdn_isparent(basesdn, be_suffix) ||
  687. (slapi_sdn_get_ndn_len(basesdn) == 0))
  688. {
  689. int tmp_scope = LDAP_SCOPE_BASE;
  690. slapi_pblock_set(pb, SLAPI_SEARCH_SCOPE, &tmp_scope);
  691. if (free_sdn) {
  692. slapi_pblock_get(pb, SLAPI_SEARCH_TARGET_SDN, &sdn);
  693. slapi_sdn_free(&sdn);
  694. }
  695. sdn = slapi_sdn_dup(be_suffix);
  696. slapi_pblock_set(pb, SLAPI_SEARCH_TARGET_SDN, (void *)sdn);
  697. free_sdn = 1;
  698. }
  699. else if (slapi_sdn_issuffix(basesdn, be_suffix))
  700. {
  701. int tmp_scope = LDAP_SCOPE_ONELEVEL;
  702. slapi_pblock_set(pb, SLAPI_SEARCH_SCOPE, &tmp_scope);
  703. }
  704. else
  705. goto next_be;
  706. }
  707. /* subtree searches :
  708. * if the search was started above the backend suffix
  709. * - temporarily set the SLAPI_SEARCH_TARGET_SDN to the
  710. * base of the node so that we don't get a NO SUCH OBJECT error
  711. * - do not change the scope
  712. */
  713. if (scope == LDAP_SCOPE_SUBTREE)
  714. {
  715. if (slapi_sdn_issuffix(be_suffix, basesdn))
  716. {
  717. if (free_sdn) {
  718. slapi_pblock_get(pb, SLAPI_SEARCH_TARGET_SDN, &sdn);
  719. slapi_sdn_free(&sdn);
  720. }
  721. sdn = slapi_sdn_dup(be_suffix);
  722. slapi_pblock_set(pb, SLAPI_SEARCH_TARGET_SDN, (void *)sdn);
  723. free_sdn = 1;
  724. }
  725. }
  726. }
  727. slapi_pblock_set(pb, SLAPI_BACKEND, be);
  728. slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
  729. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_SET, NULL);
  730. /* ONREPL - we need to be able to tell the backend not to send results directly */
  731. rc = (*be->be_search)(pb);
  732. switch (rc)
  733. {
  734. case 1:
  735. /* if the backend returned LDAP_NO_SUCH_OBJECT for a SEARCH request,
  736. * it will not have sent back a result - otherwise, it will have
  737. * sent a result */
  738. rc = SLAPI_FAIL_GENERAL;
  739. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &err);
  740. if (err == LDAP_NO_SUCH_OBJECT)
  741. {
  742. /* may be the object exist somewhere else
  743. * wait the end of the loop to send back this error
  744. */
  745. flag_no_such_object = 1;
  746. } else {
  747. /* err something other than LDAP_NO_SUCH_OBJECT, so the backend will
  748. * have sent the result -
  749. * Set a flag here so we don't return another result. */
  750. sent_result = 1;
  751. }
  752. /* fall through */
  753. case -1: /* an error occurred */
  754. /* PAGED RESULTS */
  755. if (op_is_pagedresults(operation)) {
  756. /* cleanup the slot */
  757. PR_EnterMonitor(pb->pb_conn->c_mutex);
  758. pagedresults_set_search_result(pb->pb_conn, operation, NULL, 1, pr_idx);
  759. rc = pagedresults_set_current_be(pb->pb_conn, NULL, pr_idx, 1);
  760. PR_ExitMonitor(pb->pb_conn->c_mutex);
  761. }
  762. if (1 == flag_no_such_object) {
  763. break;
  764. }
  765. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &err);
  766. if (err == LDAP_NO_SUCH_OBJECT)
  767. {
  768. /* may be the object exist somewhere else
  769. * wait the end of the loop to send back this error
  770. */
  771. flag_no_such_object = 1;
  772. break;
  773. }
  774. else
  775. {
  776. /* for error other than LDAP_NO_SUCH_OBJECT
  777. * the error has already been sent
  778. * stop the search here
  779. */
  780. goto free_and_return;
  781. }
  782. /* when rc == SLAPI_FAIL_DISKFULL this case is executed */
  783. case SLAPI_FAIL_DISKFULL:
  784. operation_out_of_disk_space();
  785. goto free_and_return;
  786. case 0: /* search was successful and we need to send the result */
  787. flag_search_base_found++;
  788. rc = send_results_ext (pb, 1, &pnentries, pagesize, &pr_stat);
  789. /* PAGED RESULTS */
  790. if (op_is_pagedresults(operation)) {
  791. void *sr = NULL;
  792. int with_sort = operation->o_flags & OP_FLAG_SERVER_SIDE_SORTING;
  793. curr_search_count = pnentries;
  794. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_SET, &sr);
  795. if (PAGEDRESULTS_SEARCH_END == pr_stat) {
  796. /* no more entries, but at least another backend */
  797. PR_EnterMonitor(pb->pb_conn->c_mutex);
  798. pagedresults_set_search_result(pb->pb_conn, operation, NULL, 1, pr_idx);
  799. be->be_search_results_release(&sr);
  800. rc = pagedresults_set_current_be(pb->pb_conn, next_be, pr_idx, 1);
  801. PR_ExitMonitor(pb->pb_conn->c_mutex);
  802. if (NULL == next_be) {
  803. /* no more entries && no more backends */
  804. curr_search_count = -1;
  805. } else if (rc < 0) {
  806. goto free_and_return;
  807. }
  808. } else {
  809. curr_search_count = pnentries;
  810. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_SET_SIZE_ESTIMATE, &estimate);
  811. pagedresults_lock(pb->pb_conn, pr_idx);
  812. if ((pagedresults_set_current_be(pb->pb_conn, be, pr_idx, 0) < 0) ||
  813. (pagedresults_set_search_result(pb->pb_conn, operation, sr, 0, pr_idx) < 0) ||
  814. (pagedresults_set_search_result_count(pb->pb_conn, operation, curr_search_count, pr_idx) < 0) ||
  815. (pagedresults_set_search_result_set_size_estimate(pb->pb_conn, operation, estimate, pr_idx) < 0) ||
  816. (pagedresults_set_with_sort(pb->pb_conn, operation, with_sort, pr_idx) < 0)) {
  817. pagedresults_unlock(pb->pb_conn, pr_idx);
  818. goto free_and_return;
  819. }
  820. pagedresults_unlock(pb->pb_conn, pr_idx);
  821. }
  822. slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET, NULL );
  823. next_be = NULL; /* to break the loop */
  824. if (operation->o_status & SLAPI_OP_STATUS_ABANDONED) {
  825. /* It turned out this search was abandoned. */
  826. PR_EnterMonitor(pb->pb_conn->c_mutex);
  827. pagedresults_free_one_msgid_nolock( pb->pb_conn, operation->o_msgid);
  828. PR_ExitMonitor(pb->pb_conn->c_mutex);
  829. /* paged-results-request was abandoned; making an empty cookie. */
  830. pagedresults_set_response_control(pb, 0, estimate, -1, pr_idx);
  831. send_ldap_result(pb, 0, NULL, "Simple Paged Results Search abandoned", 0, NULL);
  832. rc = LDAP_SUCCESS;
  833. goto free_and_return;
  834. }
  835. pagedresults_set_response_control(pb, 0, estimate, curr_search_count, pr_idx);
  836. if (curr_search_count == -1) {
  837. pagedresults_free_one(pb->pb_conn, operation, pr_idx);
  838. }
  839. }
  840. /* if rc != 0 an error occurred while sending back the entries
  841. * to the LDAP client
  842. * LDAP error should already have been sent to the client
  843. * stop the search, free and return
  844. */
  845. if (rc != 0)
  846. goto free_and_return;
  847. break;
  848. }
  849. }
  850. nentries += pnentries;
  851. next_be:
  852. be = next_be; /* this be won't be used for PAGED_RESULTS */
  853. }
  854. /* if referrals were sent back by the mapping tree
  855. * add them to the list of referral in the pblock instead
  856. * of searching the backend
  857. */
  858. index = 0;
  859. while ((referral = referral_list[index++]) != NULL)
  860. {
  861. slapi_pblock_set(pb, SLAPI_BACKEND, NULL);
  862. if (err_code == LDAP_REFERRAL)
  863. {
  864. send_referrals_from_entry(pb,referral);
  865. goto free_and_return;
  866. }
  867. else
  868. {
  869. if (process_entry(pb, referral, 1))
  870. {
  871. flag_referral++;
  872. }
  873. else
  874. {
  875. /* Manage DSA was set, referral must be sent as an entry */
  876. int attrsonly;
  877. char **attrs = NULL;
  878. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRS, &attrs);
  879. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly);
  880. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_ENTRY, referral);
  881. switch (send_ldap_search_entry(pb, referral, NULL, attrs, attrsonly))
  882. {
  883. case 0:
  884. flag_search_base_found++;
  885. nentries++;
  886. break;
  887. case 1: /* entry not sent */
  888. case -1: /* connection closed */
  889. break;
  890. }
  891. }
  892. }
  893. }
  894. if (flag_search_base_found || flag_referral) {
  895. rc = 0;
  896. }
  897. /* ONREPL - we currently call postop only if operation is successful;
  898. We should always send result and pass error code to the plugin */
  899. if (rc == 0) {
  900. plugin_call_plugins(pb, SLAPI_PLUGIN_POST_SEARCH_FN);
  901. }
  902. else
  903. {
  904. plugin_call_plugins(pb, SLAPI_PLUGIN_POST_SEARCH_FAIL_FN);
  905. }
  906. if (send_result) {
  907. if (rc == 0)
  908. {
  909. /* at least one backend returned something and there was no critical error
  910. * from the LDAP client point of view the search was successful
  911. */
  912. struct berval **urls = NULL;
  913. slapi_pblock_get(pb, SLAPI_SEARCH_REFERRALS, &urls);
  914. send_ldap_result(pb, err_code, NULL, NULL, nentries, urls);
  915. }
  916. else if (flag_no_such_object)
  917. {
  918. /* there was at least 1 backend that was called to process
  919. * the operation and all backends returned NO SUCH OBJECTS.
  920. * Don't send the result if it's already been handled above.
  921. */
  922. if (!sent_result) {
  923. slapi_send_ldap_result_from_pb(pb);
  924. }
  925. }
  926. else
  927. {
  928. /* No backend was found in the mapping tree to process
  929. * the operation : return NO SUCH OBJECT
  930. */
  931. send_ldap_result(pb, LDAP_NO_SUCH_OBJECT, NULL, NULL, 0, NULL);
  932. }
  933. } else {
  934. /* persistent search: ignore error locating base entry */
  935. rc = 0;
  936. }
  937. free_and_return:
  938. if ((be_list[0] != NULL) || (referral_list[0] != NULL)) {
  939. slapi_mapping_tree_free_all(be_list, referral_list);
  940. } else if (be_single) {
  941. slapi_be_Unlock(be_single);
  942. }
  943. free_and_return_nolock:
  944. slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, &rc);
  945. index_subsys_filter_decoders_done(pb);
  946. if (free_sdn) {
  947. slapi_pblock_get(pb, SLAPI_SEARCH_TARGET_SDN, &sdn);
  948. slapi_sdn_free(&sdn);
  949. }
  950. slapi_sdn_free(&basesdn);
  951. slapi_pblock_set(pb, SLAPI_SEARCH_TARGET_SDN, orig_sdn);
  952. slapi_ch_free_string(&proxydn);
  953. slapi_ch_free_string(&proxystr);
  954. }
  955. /* Returns 1 if this processing on this entry is finished
  956. * and doesn't need to be sent.
  957. */
  958. static int
  959. process_entry(Slapi_PBlock *pb, Slapi_Entry *e, int send_result)
  960. {
  961. int managedsait;
  962. Slapi_Attr *a=NULL;
  963. int numValues=0, i;
  964. if (!send_result)
  965. {
  966. /* server requested that we don't send results to the client,
  967. for instance, in case of a persistent search
  968. */
  969. return 1;
  970. }
  971. /* ONREPL - check if the entry should be referred (because of the copyingFrom) */
  972. /*
  973. * If this is a referral, and the managedsait control is not present,
  974. * arrange for a referral to be sent. For v2 connections,
  975. * the referrals are just squirreled away and sent with the
  976. * final result. For v3, the referrals are sent in separate LDAP messages.
  977. */
  978. slapi_pblock_get(pb, SLAPI_MANAGEDSAIT, &managedsait);
  979. if (!managedsait && slapi_entry_attr_find(e, "ref", &a)== 0)
  980. {
  981. /* to fix 522189: when rootDSE, don't interpret attribute ref as a referral entry */
  982. if ( slapi_is_rootdse(slapi_entry_get_dn_const(e)) )
  983. return 0; /* more to do for this entry, e.g., send it back to the client */
  984. /* end fix */
  985. slapi_attr_get_numvalues(a, &numValues );
  986. if (numValues == 0)
  987. {
  988. LDAPDebug1Arg(LDAP_DEBUG_ANY, "null ref in (%s)\n",
  989. slapi_entry_get_dn_const(e));
  990. }
  991. else
  992. {
  993. Slapi_Value *val=NULL;
  994. struct berval **refscopy=NULL;
  995. struct berval **urls, **tmpUrls=NULL;
  996. tmpUrls=(struct berval **) slapi_ch_malloc((numValues + 1) * sizeof(struct berval*));
  997. for ( i = slapi_attr_first_value(a, &val); i != -1;
  998. i = slapi_attr_next_value(a, i, &val)) {
  999. tmpUrls[i]=(struct berval*)slapi_value_get_berval(val);
  1000. }
  1001. tmpUrls[numValues]=NULL;
  1002. refscopy = ref_adjust(pb, tmpUrls, slapi_entry_get_sdn_const(e), 1);
  1003. slapi_pblock_get(pb, SLAPI_SEARCH_REFERRALS, &urls);
  1004. send_ldap_referral(pb, e, refscopy, &urls);
  1005. slapi_pblock_set(pb, SLAPI_SEARCH_REFERRALS, urls);
  1006. if (NULL != refscopy)
  1007. {
  1008. ber_bvecfree(refscopy);
  1009. refscopy = NULL;
  1010. }
  1011. slapi_ch_free( (void **)&tmpUrls );
  1012. }
  1013. return 1; /* done with this entry */
  1014. }
  1015. return 0;
  1016. }
  1017. #if 0
  1018. /* Loops through search entries and sends them to the client.
  1019. * returns -1 on error, 0 if result packet was sent or 1 if
  1020. * result packet wasn't sent
  1021. */
  1022. static int
  1023. iterate_with_lookahead(Slapi_PBlock *pb, Slapi_Backend *be, int send_result, int *pnentries)
  1024. {
  1025. int rc;
  1026. int attrsonly;
  1027. int done = 0;
  1028. Slapi_Entry *e;
  1029. void *backend_info_ptr;
  1030. Slapi_Entry *next_e;
  1031. void *next_backend_info_ptr;
  1032. char **attrs = NULL;
  1033. int send_result_status = 0;
  1034. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRS, &attrs);
  1035. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly);
  1036. /* setup for the loop */
  1037. rc = be->be_next_search_entry_ext(pb, 1);
  1038. if (rc < 0)
  1039. {
  1040. /*
  1041. * Some exceptional condition occurred. Results
  1042. * have been sent, so we're finished.
  1043. */
  1044. if (rc == SLAPI_FAIL_DISKFULL)
  1045. {
  1046. operation_out_of_disk_space();
  1047. }
  1048. return -1;
  1049. }
  1050. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_ENTRY, &next_e);
  1051. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_ENTRY_EXT, &next_backend_info_ptr);
  1052. if (NULL == next_e)
  1053. {
  1054. /* no entries */
  1055. done = 1;
  1056. }
  1057. backend_info_ptr = NULL;
  1058. /* Done setting up the loop, now here it comes */
  1059. while (!done)
  1060. {
  1061. /* Allow the backend to free the entry we just finished using */
  1062. /* It is ok to call this when backend_info_ptr is NULL */
  1063. be->be_entry_release(pb, backend_info_ptr);
  1064. e = next_e;
  1065. backend_info_ptr = next_backend_info_ptr;
  1066. rc = be->be_next_search_entry_ext(pb, 1);
  1067. if (rc < 0)
  1068. {
  1069. /*
  1070. * Some exceptional condition occurred. Results
  1071. * have been sent, so we're finished.
  1072. */
  1073. if (rc == SLAPI_FAIL_DISKFULL)
  1074. {
  1075. operation_out_of_disk_space();
  1076. }
  1077. return -1;
  1078. }
  1079. else
  1080. {
  1081. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_ENTRY, &next_e);
  1082. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_ENTRY_EXT, &next_backend_info_ptr);
  1083. if (next_e == NULL)
  1084. {
  1085. /* no more entries */
  1086. done = 1;
  1087. }
  1088. }
  1089. if (process_entry(pb, e, send_result))
  1090. {
  1091. /* shouldn't send this entry */
  1092. continue;
  1093. }
  1094. /*
  1095. * It's a regular entry, or it's a referral and
  1096. * managedsait control is on. In either case, send the entry.
  1097. */
  1098. if (done)
  1099. {
  1100. struct berval **urls = NULL;
  1101. /* Send the entry and the result at the same time */
  1102. slapi_pblock_get(pb, SLAPI_SEARCH_REFERRALS, &urls);
  1103. rc = send_ldap_search_entry_ext(pb, e, NULL, attrs, attrsonly, 1,
  1104. (*pnentries)+1, urls);
  1105. if (rc == 1)
  1106. {
  1107. /* this means we didn't have access to the entry. Since the
  1108. * entry was not sent, we need to send the done packet.
  1109. */
  1110. send_result_status = 1;
  1111. }
  1112. }
  1113. else
  1114. {
  1115. /* Send the entry */
  1116. rc = send_ldap_search_entry(pb, e, NULL, attrs,
  1117. attrsonly);
  1118. }
  1119. switch (rc)
  1120. {
  1121. case 0: /* entry sent ok */
  1122. (*pnentries)++;
  1123. slapi_pblock_set(pb, SLAPI_NENTRIES, pnentries);
  1124. break;
  1125. case 1: /* entry not sent */
  1126. break;
  1127. case -1: /* connection closed */
  1128. /*
  1129. * mark the operation as abandoned so the backend
  1130. * next entry function gets called again and has
  1131. * a chance to clean things up.
  1132. */
  1133. pb->pb_op->o_status = SLAPI_OP_STATUS_ABANDONED;
  1134. break;
  1135. }
  1136. }
  1137. be->be_entry_release(pb, backend_info_ptr);
  1138. if (*pnentries == 0 || send_result_status)
  1139. {
  1140. /* We didn't send the result done message so the caller
  1141. * must send it */
  1142. return 1;
  1143. }
  1144. else
  1145. {
  1146. /* The result message has been sent */
  1147. return 0;
  1148. }
  1149. }
  1150. #endif
  1151. /* Loops through search entries and sends them to the client.
  1152. * returns -1 on error or 1 if result packet wasn't sent.
  1153. * This function never returns 0 because it doesn't send
  1154. * the result packet back with the last entry like
  1155. * iterate_with_lookahead trys to do.
  1156. */
  1157. static int
  1158. iterate(Slapi_PBlock *pb, Slapi_Backend *be, int send_result,
  1159. int *pnentries, int pagesize, unsigned int *pr_statp)
  1160. {
  1161. int rc;
  1162. int rval = 1; /* no error, by default */
  1163. int attrsonly;
  1164. int done = 0;
  1165. Slapi_Entry *e = NULL;
  1166. char **attrs = NULL;
  1167. unsigned int pr_stat = 0;
  1168. int pr_idx = -1;
  1169. if ( NULL == pb ) {
  1170. return rval;
  1171. }
  1172. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRS, &attrs);
  1173. slapi_pblock_get(pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly);
  1174. slapi_pblock_get(pb, SLAPI_PAGED_RESULTS_INDEX, &pr_idx);
  1175. *pnentries = 0;
  1176. while (!done)
  1177. {
  1178. Slapi_Entry *gerentry = NULL;
  1179. Slapi_Operation *operation;
  1180. slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
  1181. rc = be->be_next_search_entry(pb);
  1182. if (rc < 0)
  1183. {
  1184. /*
  1185. * Some exceptional condition occurred. Results have been sent,
  1186. * so we're finished.
  1187. */
  1188. if (rc == SLAPI_FAIL_DISKFULL)
  1189. {
  1190. operation_out_of_disk_space();
  1191. }
  1192. pr_stat = PAGEDRESULTS_SEARCH_END;
  1193. rval = -1;
  1194. done = 1;
  1195. continue;
  1196. }
  1197. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_ENTRY, &e);
  1198. /* Check for possible get_effective_rights control */
  1199. if (e) {
  1200. if (operation->o_flags & OP_FLAG_GET_EFFECTIVE_RIGHTS) {
  1201. char *errbuf = NULL;
  1202. char **gerattrs = NULL;
  1203. char **gerattrsdup = NULL;
  1204. char **gap = NULL;
  1205. char *gapnext = NULL;
  1206. if (PAGEDRESULTS_PAGE_END == pr_stat)
  1207. {
  1208. /*
  1209. * read ahead -- there is at least more entry.
  1210. * undo it and return the PAGE_END
  1211. */
  1212. be->be_prev_search_results(pb);
  1213. done = 1;
  1214. continue;
  1215. }
  1216. slapi_pblock_get( pb, SLAPI_SEARCH_GERATTRS, &gerattrs );
  1217. gerattrsdup = cool_charray_dup(gerattrs);
  1218. gap = gerattrsdup;
  1219. do
  1220. {
  1221. gapnext = NULL;
  1222. if (gap)
  1223. {
  1224. if (*gap && *(gap+1))
  1225. {
  1226. gapnext = *(gap+1);
  1227. *(gap+1) = NULL;
  1228. }
  1229. slapi_pblock_set( pb, SLAPI_SEARCH_GERATTRS, gap );
  1230. rc = plugin_call_acl_plugin (pb, e, attrs, NULL,
  1231. SLAPI_ACL_ALL, ACLPLUGIN_ACCESS_GET_EFFECTIVE_RIGHTS,
  1232. &errbuf);
  1233. if (NULL != gapnext)
  1234. {
  1235. *(gap+1) = gapnext;
  1236. }
  1237. }
  1238. else if (NULL != e)
  1239. {
  1240. rc = plugin_call_acl_plugin (pb, e, attrs, NULL,
  1241. SLAPI_ACL_ALL, ACLPLUGIN_ACCESS_GET_EFFECTIVE_RIGHTS,
  1242. &errbuf);
  1243. }
  1244. if (NULL == e) {
  1245. /* get the template entry, if any */
  1246. slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_ENTRY, &e);
  1247. if (NULL == e) {
  1248. /* everything is ok - don't send the result */
  1249. pr_stat = PAGEDRESULTS_SEARCH_END;
  1250. done = 1;
  1251. continue;
  1252. }
  1253. gerentry = e;
  1254. }
  1255. if ( rc != LDAP_SUCCESS ) {
  1256. /* Send error result and
  1257. abort op if the control is critical */
  1258. LDAPDebug( LDAP_DEBUG_ANY,
  1259. "Failed to get effective rights for entry (%s), rc=%d\n",
  1260. slapi_entry_get_dn_const(e), rc, 0 );
  1261. send_ldap_result( pb, rc, NULL, errbuf, 0, NULL );
  1262. slapi_ch_free ( (void**)&errbuf );
  1263. if (gerentry)
  1264. {
  1265. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_ENTRY, NULL);
  1266. slapi_entry_free(gerentry);
  1267. gerentry = e = NULL;
  1268. }
  1269. pr_stat = PAGEDRESULTS_SEARCH_END;
  1270. rval = -1;
  1271. done = 1;
  1272. continue;
  1273. }
  1274. slapi_ch_free ( (void**)&errbuf );
  1275. if (process_entry(pb, e, send_result))
  1276. {
  1277. /* shouldn't send this entry */
  1278. if (gerentry)
  1279. {
  1280. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_ENTRY, NULL);
  1281. slapi_entry_free(gerentry);
  1282. gerentry = e = NULL;
  1283. }
  1284. continue;
  1285. }
  1286. /*
  1287. * It's a regular entry, or it's a referral and
  1288. * managedsait control is on. In either case, send
  1289. * the entry.
  1290. */
  1291. switch (send_ldap_search_entry(pb, e, NULL, attrs, attrsonly))
  1292. {
  1293. case 0: /* entry sent ok */
  1294. (*pnentries)++;
  1295. slapi_pblock_set(pb, SLAPI_NENTRIES, pnentries);
  1296. break;
  1297. case 1: /* entry not sent */
  1298. break;
  1299. case -1: /* connection closed */
  1300. /*
  1301. * mark the operation as abandoned so the backend
  1302. * next entry function gets called again and has
  1303. * a chance to clean things up.
  1304. */
  1305. pb->pb_op->o_status = SLAPI_OP_STATUS_ABANDONED;
  1306. break;
  1307. }
  1308. if (gerentry)
  1309. {
  1310. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_ENTRY, NULL);
  1311. slapi_entry_free(gerentry);
  1312. gerentry = e = NULL;
  1313. }
  1314. }
  1315. while (gap && ++gap && *gap);
  1316. slapi_pblock_set( pb, SLAPI_SEARCH_GERATTRS, gerattrs );
  1317. cool_charray_free(gerattrsdup);
  1318. if (pagesize == *pnentries)
  1319. {
  1320. /* PAGED RESULTS: reached the pagesize */
  1321. /* We don't set "done = 1" here.
  1322. * We read ahead next entry to check whether there is
  1323. * more entries to return or not. */
  1324. pr_stat = PAGEDRESULTS_PAGE_END;
  1325. }
  1326. } else { /* not GET_EFFECTIVE_RIGHTS */
  1327. if (PAGEDRESULTS_PAGE_END == pr_stat)
  1328. {
  1329. /*
  1330. * read ahead -- there is at least more entry.
  1331. * undo it and return the PAGE_END
  1332. */
  1333. be->be_prev_search_results(pb);
  1334. done = 1;
  1335. continue;
  1336. }
  1337. /* Adding shadow password attrs. */
  1338. add_shadow_ext_password_attrs(pb, e);
  1339. if (process_entry(pb, e, send_result))
  1340. {
  1341. /* shouldn't send this entry */
  1342. continue;
  1343. }
  1344. /*
  1345. * It's a regular entry, or it's a referral and
  1346. * managedsait control is on. In either case, send
  1347. * the entry.
  1348. */
  1349. switch (send_ldap_search_entry(pb, e, NULL, attrs, attrsonly))
  1350. {
  1351. case 0: /* entry sent ok */
  1352. (*pnentries)++;
  1353. slapi_pblock_set(pb, SLAPI_NENTRIES, pnentries);
  1354. break;
  1355. case 1: /* entry not sent */
  1356. break;
  1357. case -1: /* connection closed */
  1358. /*
  1359. * mark the operation as abandoned so the backend
  1360. * next entry function gets called again and has
  1361. * a chance to clean things up.
  1362. */
  1363. pb->pb_op->o_status = SLAPI_OP_STATUS_ABANDONED;
  1364. break;
  1365. }
  1366. if (pagesize == *pnentries)
  1367. {
  1368. /* PAGED RESULTS: reached the pagesize */
  1369. /* We don't set "done = 1" here.
  1370. * We read ahead next entry to check whether there is
  1371. * more entries to return or not. */
  1372. pr_stat = PAGEDRESULTS_PAGE_END;
  1373. }
  1374. }
  1375. }
  1376. else
  1377. {
  1378. /* no more entries */
  1379. done = 1;
  1380. pr_stat = PAGEDRESULTS_SEARCH_END;
  1381. }
  1382. }
  1383. if (pr_statp) {
  1384. *pr_statp = pr_stat;
  1385. }
  1386. return rval;
  1387. }
  1388. static int timelimit_reslimit_handle = -1;
  1389. static int sizelimit_reslimit_handle = -1;
  1390. static int pagedsizelimit_reslimit_handle = -1;
  1391. /*
  1392. * Register size and time limit with the binder-based resource limits
  1393. * subsystem. A SLAPI_RESLIMIT_STATUS_... code is returned.
  1394. */
  1395. int
  1396. search_register_reslimits( void )
  1397. {
  1398. int rc1, rc2, rc3;
  1399. rc1 = slapi_reslimit_register( SLAPI_RESLIMIT_TYPE_INT,
  1400. "nsSizeLimit" , &sizelimit_reslimit_handle );
  1401. rc2 = slapi_reslimit_register( SLAPI_RESLIMIT_TYPE_INT,
  1402. "nsTimeLimit", &timelimit_reslimit_handle );
  1403. rc3 = slapi_reslimit_register( SLAPI_RESLIMIT_TYPE_INT,
  1404. "nsPagedSizeLimit", &pagedsizelimit_reslimit_handle );
  1405. return (rc1 != SLAPI_RESLIMIT_STATUS_SUCCESS) ? rc1 :
  1406. ((rc2 != SLAPI_RESLIMIT_STATUS_SUCCESS) ? rc2 : rc3);
  1407. }
  1408. /*
  1409. * Compute size and time limits based on the connection (bind identity).
  1410. * Binder-based resource limits get top priority, followed by those associated
  1411. * with the backend we are using.
  1412. *
  1413. * If the binder is the root DN and there is nothing in the root DN's entry
  1414. * to say otherwise, no limits are used. Otherwise, the lower of the limit
  1415. * that was sent in the LDAP request and that available based on the
  1416. * connection bind identity or configured backend limit is used.
  1417. */
  1418. static void
  1419. compute_limits (Slapi_PBlock *pb)
  1420. {
  1421. int timelimit, sizelimit;
  1422. int requested_timelimit, max_timelimit, requested_sizelimit, max_sizelimit;
  1423. int isroot;
  1424. int isCertAuth;
  1425. Slapi_ComponentId *component_id = NULL;
  1426. Slapi_Backend *be;
  1427. Slapi_Operation *op;
  1428. slapi_pblock_get (pb, SLAPI_SEARCH_TIMELIMIT, &requested_timelimit);
  1429. slapi_pblock_get (pb, SLAPI_SEARCH_SIZELIMIT, &requested_sizelimit);
  1430. slapi_pblock_get (pb, SLAPI_REQUESTOR_ISROOT, &isroot);
  1431. slapi_pblock_get (pb, SLAPI_BACKEND, &be);
  1432. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  1433. /* If the search belongs to the client authentication process, take the value at
  1434. * nsslapd-timelimit as the actual time limit.
  1435. */
  1436. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &component_id);
  1437. if (component_id) {
  1438. isCertAuth = (! strcasecmp(component_id->sci_component_name, COMPONENT_CERT_AUTH) ) ? 1 : 0;
  1439. if (isCertAuth) {
  1440. timelimit = config_get_timelimit();
  1441. goto set_timelimit;
  1442. }
  1443. }
  1444. /*
  1445. * Compute the time limit.
  1446. */
  1447. if ( slapi_reslimit_get_integer_limit( pb->pb_conn,
  1448. timelimit_reslimit_handle, &max_timelimit )
  1449. != SLAPI_RESLIMIT_STATUS_SUCCESS ) {
  1450. /*
  1451. * no limit associated with binder/connection or some other error
  1452. * occurred. use the default maximum.
  1453. */
  1454. if ( isroot ) {
  1455. max_timelimit = -1; /* no limit */
  1456. } else {
  1457. max_timelimit = be->be_timelimit;
  1458. }
  1459. }
  1460. if ( requested_timelimit ) {
  1461. /* requested limit should be applied to all (including root) */
  1462. if ( isroot ) {
  1463. timelimit = requested_timelimit;
  1464. } else if ( (max_timelimit == -1) ||
  1465. (requested_timelimit < max_timelimit) ) {
  1466. timelimit = requested_timelimit;
  1467. } else {
  1468. timelimit = max_timelimit;
  1469. }
  1470. } else if ( isroot ) {
  1471. timelimit = -1; /* no limit */
  1472. } else {
  1473. timelimit = max_timelimit;
  1474. }
  1475. set_timelimit:
  1476. slapi_pblock_set(pb, SLAPI_SEARCH_TIMELIMIT, &timelimit);
  1477. /*
  1478. * Compute the size limit.
  1479. */
  1480. if ( slapi_reslimit_get_integer_limit( pb->pb_conn,
  1481. sizelimit_reslimit_handle, &max_sizelimit )
  1482. != SLAPI_RESLIMIT_STATUS_SUCCESS ) {
  1483. /*
  1484. * no limit associated with binder/connection or some other error
  1485. * occurred. use the default maximum.
  1486. */
  1487. if ( isroot ) {
  1488. max_sizelimit = -1; /* no limit */
  1489. } else {
  1490. max_sizelimit = be->be_sizelimit;
  1491. }
  1492. }
  1493. if (op_is_pagedresults(op)) {
  1494. if ( slapi_reslimit_get_integer_limit( pb->pb_conn,
  1495. pagedsizelimit_reslimit_handle, &max_sizelimit )
  1496. != SLAPI_RESLIMIT_STATUS_SUCCESS ) {
  1497. /*
  1498. * no limit associated with binder/connection or some other error
  1499. * occurred. use the default maximum.
  1500. */
  1501. if ( be->be_pagedsizelimit ) {
  1502. max_sizelimit = be->be_pagedsizelimit;
  1503. }
  1504. /* else was already set above */
  1505. }
  1506. }
  1507. if ( requested_sizelimit ) {
  1508. /* requested limit should be applied to all (including root) */
  1509. if ( isroot ) {
  1510. sizelimit = requested_sizelimit;
  1511. } else if ( (max_sizelimit == -1) ||
  1512. (requested_sizelimit < max_sizelimit) ) {
  1513. sizelimit = requested_sizelimit;
  1514. } else {
  1515. sizelimit = max_sizelimit;
  1516. }
  1517. } else if ( isroot ) {
  1518. sizelimit = -1; /* no limit */
  1519. } else {
  1520. sizelimit = max_sizelimit;
  1521. }
  1522. slapi_pblock_set(pb, SLAPI_SEARCH_SIZELIMIT, &sizelimit);
  1523. LDAPDebug( LDAP_DEBUG_TRACE,
  1524. "=> compute_limits: sizelimit=%d, timelimit=%d\n",
  1525. sizelimit, timelimit, 0 );
  1526. }
  1527. /* Iterates through results and send them to the client.
  1528. * Returns 0 if successful and -1 otherwise
  1529. */
  1530. static int
  1531. send_results_ext(Slapi_PBlock *pb, int send_result, int *nentries, int pagesize, unsigned int *pr_stat)
  1532. {
  1533. Slapi_Backend *be;
  1534. int rc;
  1535. slapi_pblock_get (pb, SLAPI_BACKEND, &be);
  1536. if (be->be_next_search_entry == NULL)
  1537. {
  1538. /* we need to send the result, but the function to iterate through
  1539. the result set is not implemented */
  1540. /* ONREPL - log error */
  1541. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, "Search not supported", 0, NULL);
  1542. return -1;
  1543. }
  1544. /* Iterate through the returned result set */
  1545. if (be->be_next_search_entry_ext != NULL)
  1546. {
  1547. /* The iterate look ahead is causing a whole mess with the ACL.
  1548. ** the entries are now visiting the ACL land in a random way
  1549. ** and not the ordered way it was before. Until we figure out
  1550. ** let's not change the behavior.
  1551. **
  1552. ** Don't use iterate_with_lookahead because it sends the result
  1553. * in the same times as the entry and this can cause failure
  1554. * of the mapping tree scanning algorithme
  1555. * if (getFrontendConfig()->result_tweak)
  1556. * {
  1557. * rc = iterate_with_lookahead(pb, be, send_result, nentries);
  1558. * }
  1559. * else
  1560. */
  1561. rc = iterate(pb, be, send_result, nentries, pagesize, pr_stat);
  1562. }
  1563. else
  1564. {
  1565. rc = iterate(pb, be, send_result, nentries, pagesize, pr_stat);
  1566. }
  1567. switch(rc)
  1568. {
  1569. case -1: /* an error occured */
  1570. case 0 : /* everything is ok - result is sent */
  1571. /* If this happens we are dead but hopefully iterate
  1572. * never sends the result itself
  1573. */
  1574. break;
  1575. case 1: /* everything is ok - don't send the result */
  1576. rc = 0;
  1577. }
  1578. return rc;
  1579. }
  1580. void op_shared_log_error_access (Slapi_PBlock *pb, const char *type, const char *dn, const char *msg)
  1581. {
  1582. char *proxydn = NULL;
  1583. char *proxystr = NULL;
  1584. if ((proxyauth_get_dn(pb, &proxydn, NULL) == LDAP_SUCCESS)) {
  1585. proxystr = slapi_ch_smprintf(" authzid=\"%s\"", proxydn);
  1586. }
  1587. slapi_log_access( LDAP_DEBUG_STATS, "conn=%" NSPRIu64 " op=%d %s dn=\"%s\"%s, %s\n",
  1588. ( pb->pb_conn ? pb->pb_conn->c_connid : 0),
  1589. ( pb->pb_op ? pb->pb_op->o_opid : 0),
  1590. type,
  1591. dn,
  1592. proxystr ? proxystr : "",
  1593. msg ? msg : "" );
  1594. slapi_ch_free_string(&proxydn);
  1595. slapi_ch_free_string(&proxystr);
  1596. }