opshared.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  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. slapi_entry_free(pb->pb_pw_entry);
  1343. pb->pb_pw_entry = NULL;
  1344. continue;
  1345. }
  1346. /*
  1347. * It's a regular entry, or it's a referral and
  1348. * managedsait control is on. In either case, send
  1349. * the entry.
  1350. */
  1351. switch (send_ldap_search_entry(pb, e, NULL, attrs, attrsonly))
  1352. {
  1353. case 0: /* entry sent ok */
  1354. (*pnentries)++;
  1355. slapi_pblock_set(pb, SLAPI_NENTRIES, pnentries);
  1356. break;
  1357. case 1: /* entry not sent */
  1358. break;
  1359. case -1: /* connection closed */
  1360. /*
  1361. * mark the operation as abandoned so the backend
  1362. * next entry function gets called again and has
  1363. * a chance to clean things up.
  1364. */
  1365. pb->pb_op->o_status = SLAPI_OP_STATUS_ABANDONED;
  1366. break;
  1367. }
  1368. slapi_entry_free(pb->pb_pw_entry);
  1369. pb->pb_pw_entry = NULL;
  1370. if (pagesize == *pnentries)
  1371. {
  1372. /* PAGED RESULTS: reached the pagesize */
  1373. /* We don't set "done = 1" here.
  1374. * We read ahead next entry to check whether there is
  1375. * more entries to return or not. */
  1376. pr_stat = PAGEDRESULTS_PAGE_END;
  1377. }
  1378. }
  1379. }
  1380. else
  1381. {
  1382. /* no more entries */
  1383. done = 1;
  1384. pr_stat = PAGEDRESULTS_SEARCH_END;
  1385. }
  1386. }
  1387. if (pr_statp) {
  1388. *pr_statp = pr_stat;
  1389. }
  1390. return rval;
  1391. }
  1392. static int timelimit_reslimit_handle = -1;
  1393. static int sizelimit_reslimit_handle = -1;
  1394. static int pagedsizelimit_reslimit_handle = -1;
  1395. /*
  1396. * Register size and time limit with the binder-based resource limits
  1397. * subsystem. A SLAPI_RESLIMIT_STATUS_... code is returned.
  1398. */
  1399. int
  1400. search_register_reslimits( void )
  1401. {
  1402. int rc1, rc2, rc3;
  1403. rc1 = slapi_reslimit_register( SLAPI_RESLIMIT_TYPE_INT,
  1404. "nsSizeLimit" , &sizelimit_reslimit_handle );
  1405. rc2 = slapi_reslimit_register( SLAPI_RESLIMIT_TYPE_INT,
  1406. "nsTimeLimit", &timelimit_reslimit_handle );
  1407. rc3 = slapi_reslimit_register( SLAPI_RESLIMIT_TYPE_INT,
  1408. "nsPagedSizeLimit", &pagedsizelimit_reslimit_handle );
  1409. return (rc1 != SLAPI_RESLIMIT_STATUS_SUCCESS) ? rc1 :
  1410. ((rc2 != SLAPI_RESLIMIT_STATUS_SUCCESS) ? rc2 : rc3);
  1411. }
  1412. /*
  1413. * Compute size and time limits based on the connection (bind identity).
  1414. * Binder-based resource limits get top priority, followed by those associated
  1415. * with the backend we are using.
  1416. *
  1417. * If the binder is the root DN and there is nothing in the root DN's entry
  1418. * to say otherwise, no limits are used. Otherwise, the lower of the limit
  1419. * that was sent in the LDAP request and that available based on the
  1420. * connection bind identity or configured backend limit is used.
  1421. */
  1422. static void
  1423. compute_limits (Slapi_PBlock *pb)
  1424. {
  1425. int timelimit, sizelimit;
  1426. int requested_timelimit, max_timelimit, requested_sizelimit, max_sizelimit;
  1427. int isroot;
  1428. int isCertAuth;
  1429. Slapi_ComponentId *component_id = NULL;
  1430. Slapi_Backend *be;
  1431. Slapi_Operation *op;
  1432. slapi_pblock_get (pb, SLAPI_SEARCH_TIMELIMIT, &requested_timelimit);
  1433. slapi_pblock_get (pb, SLAPI_SEARCH_SIZELIMIT, &requested_sizelimit);
  1434. slapi_pblock_get (pb, SLAPI_REQUESTOR_ISROOT, &isroot);
  1435. slapi_pblock_get (pb, SLAPI_BACKEND, &be);
  1436. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  1437. /* If the search belongs to the client authentication process, take the value at
  1438. * nsslapd-timelimit as the actual time limit.
  1439. */
  1440. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &component_id);
  1441. if (component_id) {
  1442. isCertAuth = (! strcasecmp(component_id->sci_component_name, COMPONENT_CERT_AUTH) ) ? 1 : 0;
  1443. if (isCertAuth) {
  1444. timelimit = config_get_timelimit();
  1445. goto set_timelimit;
  1446. }
  1447. }
  1448. /*
  1449. * Compute the time limit.
  1450. */
  1451. if ( slapi_reslimit_get_integer_limit( pb->pb_conn,
  1452. timelimit_reslimit_handle, &max_timelimit )
  1453. != SLAPI_RESLIMIT_STATUS_SUCCESS ) {
  1454. /*
  1455. * no limit associated with binder/connection or some other error
  1456. * occurred. use the default maximum.
  1457. */
  1458. if ( isroot ) {
  1459. max_timelimit = -1; /* no limit */
  1460. } else {
  1461. max_timelimit = be->be_timelimit;
  1462. }
  1463. }
  1464. if ( requested_timelimit ) {
  1465. /* requested limit should be applied to all (including root) */
  1466. if ( isroot ) {
  1467. timelimit = requested_timelimit;
  1468. } else if ( (max_timelimit == -1) ||
  1469. (requested_timelimit < max_timelimit) ) {
  1470. timelimit = requested_timelimit;
  1471. } else {
  1472. timelimit = max_timelimit;
  1473. }
  1474. } else if ( isroot ) {
  1475. timelimit = -1; /* no limit */
  1476. } else {
  1477. timelimit = max_timelimit;
  1478. }
  1479. set_timelimit:
  1480. slapi_pblock_set(pb, SLAPI_SEARCH_TIMELIMIT, &timelimit);
  1481. /*
  1482. * Compute the size limit.
  1483. */
  1484. if ( slapi_reslimit_get_integer_limit( pb->pb_conn,
  1485. sizelimit_reslimit_handle, &max_sizelimit )
  1486. != SLAPI_RESLIMIT_STATUS_SUCCESS ) {
  1487. /*
  1488. * no limit associated with binder/connection or some other error
  1489. * occurred. use the default maximum.
  1490. */
  1491. if ( isroot ) {
  1492. max_sizelimit = -1; /* no limit */
  1493. } else {
  1494. max_sizelimit = be->be_sizelimit;
  1495. }
  1496. }
  1497. if (op_is_pagedresults(op)) {
  1498. if ( slapi_reslimit_get_integer_limit( pb->pb_conn,
  1499. pagedsizelimit_reslimit_handle, &max_sizelimit )
  1500. != SLAPI_RESLIMIT_STATUS_SUCCESS ) {
  1501. /*
  1502. * no limit associated with binder/connection or some other error
  1503. * occurred. use the default maximum.
  1504. */
  1505. if ( be->be_pagedsizelimit ) {
  1506. max_sizelimit = be->be_pagedsizelimit;
  1507. }
  1508. /* else was already set above */
  1509. }
  1510. }
  1511. if ( requested_sizelimit ) {
  1512. /* requested limit should be applied to all (including root) */
  1513. if ( isroot ) {
  1514. sizelimit = requested_sizelimit;
  1515. } else if ( (max_sizelimit == -1) ||
  1516. (requested_sizelimit < max_sizelimit) ) {
  1517. sizelimit = requested_sizelimit;
  1518. } else {
  1519. sizelimit = max_sizelimit;
  1520. }
  1521. } else if ( isroot ) {
  1522. sizelimit = -1; /* no limit */
  1523. } else {
  1524. sizelimit = max_sizelimit;
  1525. }
  1526. slapi_pblock_set(pb, SLAPI_SEARCH_SIZELIMIT, &sizelimit);
  1527. LDAPDebug( LDAP_DEBUG_TRACE,
  1528. "=> compute_limits: sizelimit=%d, timelimit=%d\n",
  1529. sizelimit, timelimit, 0 );
  1530. }
  1531. /* Iterates through results and send them to the client.
  1532. * Returns 0 if successful and -1 otherwise
  1533. */
  1534. static int
  1535. send_results_ext(Slapi_PBlock *pb, int send_result, int *nentries, int pagesize, unsigned int *pr_stat)
  1536. {
  1537. Slapi_Backend *be;
  1538. int rc;
  1539. slapi_pblock_get (pb, SLAPI_BACKEND, &be);
  1540. if (be->be_next_search_entry == NULL)
  1541. {
  1542. /* we need to send the result, but the function to iterate through
  1543. the result set is not implemented */
  1544. /* ONREPL - log error */
  1545. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, "Search not supported", 0, NULL);
  1546. return -1;
  1547. }
  1548. /* Iterate through the returned result set */
  1549. if (be->be_next_search_entry_ext != NULL)
  1550. {
  1551. /* The iterate look ahead is causing a whole mess with the ACL.
  1552. ** the entries are now visiting the ACL land in a random way
  1553. ** and not the ordered way it was before. Until we figure out
  1554. ** let's not change the behavior.
  1555. **
  1556. ** Don't use iterate_with_lookahead because it sends the result
  1557. * in the same times as the entry and this can cause failure
  1558. * of the mapping tree scanning algorithme
  1559. * if (getFrontendConfig()->result_tweak)
  1560. * {
  1561. * rc = iterate_with_lookahead(pb, be, send_result, nentries);
  1562. * }
  1563. * else
  1564. */
  1565. rc = iterate(pb, be, send_result, nentries, pagesize, pr_stat);
  1566. }
  1567. else
  1568. {
  1569. rc = iterate(pb, be, send_result, nentries, pagesize, pr_stat);
  1570. }
  1571. switch(rc)
  1572. {
  1573. case -1: /* an error occured */
  1574. case 0 : /* everything is ok - result is sent */
  1575. /* If this happens we are dead but hopefully iterate
  1576. * never sends the result itself
  1577. */
  1578. break;
  1579. case 1: /* everything is ok - don't send the result */
  1580. rc = 0;
  1581. }
  1582. return rc;
  1583. }
  1584. void op_shared_log_error_access (Slapi_PBlock *pb, const char *type, const char *dn, const char *msg)
  1585. {
  1586. char *proxydn = NULL;
  1587. char *proxystr = NULL;
  1588. if ((proxyauth_get_dn(pb, &proxydn, NULL) == LDAP_SUCCESS)) {
  1589. proxystr = slapi_ch_smprintf(" authzid=\"%s\"", proxydn);
  1590. }
  1591. slapi_log_access( LDAP_DEBUG_STATS, "conn=%" NSPRIu64 " op=%d %s dn=\"%s\"%s, %s\n",
  1592. ( pb->pb_conn ? pb->pb_conn->c_connid : 0),
  1593. ( pb->pb_op ? pb->pb_op->o_opid : 0),
  1594. type,
  1595. dn,
  1596. proxystr ? proxystr : "",
  1597. msg ? msg : "" );
  1598. slapi_ch_free_string(&proxydn);
  1599. slapi_ch_free_string(&proxystr);
  1600. }