opshared.c 60 KB

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