acleffectiverights.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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) 2005 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. #ifdef HAVE_CONFIG_H
  38. # include <config.h>
  39. #endif
  40. #include <ldap.h>
  41. #include "acl.h"
  42. /* safer than doing strcat unprotected */
  43. /* news2 is optional, provided as a convenience */
  44. /* capacity is the capacity of the gerstr, size is the current length */
  45. static void
  46. _append_gerstr(
  47. char **gerstr,
  48. size_t *capacity,
  49. size_t *size,
  50. const char *news,
  51. const char *news2
  52. )
  53. {
  54. size_t len;
  55. size_t increment = 128;
  56. size_t fornull;
  57. if (!news) {
  58. return;
  59. }
  60. /* find out how much space we need */
  61. len = strlen(news);
  62. fornull = 1;
  63. if (news2) {
  64. len += strlen(news2);
  65. fornull++;
  66. }
  67. /* increase space if needed */
  68. while ((*size + len + fornull) > *capacity) {
  69. if ((len + fornull) > increment) {
  70. *capacity += len + fornull; /* just go ahead and grow the string enough */
  71. } else {
  72. *capacity += increment; /* rather than having lots of small increments */
  73. }
  74. }
  75. if (!*gerstr) {
  76. *gerstr = slapi_ch_malloc(*capacity);
  77. **gerstr = 0;
  78. } else {
  79. *gerstr = slapi_ch_realloc(*gerstr, *capacity);
  80. }
  81. strcat(*gerstr, news);
  82. if (news2) {
  83. strcat(*gerstr, news2);
  84. }
  85. *size += len;
  86. return;
  87. }
  88. static int
  89. _ger_g_permission_granted (
  90. Slapi_PBlock *pb,
  91. Slapi_Entry *e,
  92. const char *subjectdn,
  93. char **errbuf
  94. )
  95. {
  96. char *proxydn = NULL;
  97. Slapi_DN *requestor_sdn, *entry_sdn;
  98. char *errtext = NULL;
  99. int isroot;
  100. int rc;
  101. /*
  102. * Theorically, we should check if the entry has "g"
  103. * permission granted to the requestor. If granted,
  104. * allows the effective rights on that entry and its
  105. * attributes within the entry to be returned for
  106. * ANY subject.
  107. *
  108. * "G" permission granting has not been implemented yet,
  109. * the current release assumes that "g" permission be
  110. * granted to root and owner of any entry.
  111. */
  112. /*
  113. * The requestor may be either the bind dn or a proxy dn
  114. */
  115. if ((proxyauth_get_dn( pb, &proxydn, &errtext ) == LDAP_SUCCESS) && ( proxydn != NULL ))
  116. {
  117. requestor_sdn = slapi_sdn_new_dn_passin ( proxydn );
  118. }
  119. else
  120. {
  121. slapi_ch_free_string(&proxydn); /* this could still have been set - free it */
  122. requestor_sdn = &(pb->pb_op->o_sdn);
  123. }
  124. if ( slapi_sdn_get_dn (requestor_sdn) == NULL )
  125. {
  126. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  127. "_ger_g_permission_granted: anonymous has no g permission\n" );
  128. rc = LDAP_INSUFFICIENT_ACCESS;
  129. goto bailout;
  130. }
  131. isroot = slapi_dn_isroot ( slapi_sdn_get_dn (requestor_sdn) );
  132. if ( isroot )
  133. {
  134. /* Root has "g" permission on any entry */
  135. rc = LDAP_SUCCESS;
  136. goto bailout;
  137. }
  138. entry_sdn = slapi_entry_get_sdn ( e );
  139. if ( entry_sdn == NULL || slapi_sdn_get_dn (entry_sdn) == NULL )
  140. {
  141. rc = LDAP_SUCCESS;
  142. goto bailout;
  143. }
  144. if ( slapi_sdn_compare ( requestor_sdn, entry_sdn ) == 0 )
  145. {
  146. /* Owner has "g" permission on his own entry */
  147. rc = LDAP_SUCCESS;
  148. goto bailout;
  149. }
  150. /* if the requestor and the subject user are identical, let's grant it */
  151. if ( strcasecmp ( slapi_sdn_get_ndn(requestor_sdn), subjectdn ) == 0)
  152. {
  153. /* Requestor should see his own permission rights on any entry */
  154. rc = LDAP_SUCCESS;
  155. goto bailout;
  156. }
  157. aclutil_str_append ( errbuf, "get-effective-rights: requestor has no g permission on the entry" );
  158. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  159. "_ger_g_permission_granted: %s\n", *errbuf);
  160. rc = LDAP_INSUFFICIENT_ACCESS;
  161. bailout:
  162. if ( proxydn )
  163. {
  164. /* The ownership of proxydn has passed to requestor_sdn */
  165. slapi_sdn_free ( &requestor_sdn );
  166. }
  167. return rc;
  168. }
  169. static int
  170. _ger_parse_control (
  171. Slapi_PBlock *pb,
  172. char **subjectndn,
  173. int *iscritical,
  174. char **errbuf
  175. )
  176. {
  177. LDAPControl **requestcontrols;
  178. struct berval *subjectber;
  179. BerElement *ber;
  180. size_t subjectndnlen = 0;
  181. char *orig = NULL;
  182. char *normed = NULL;
  183. if (NULL == subjectndn)
  184. {
  185. return LDAP_OPERATIONS_ERROR;
  186. }
  187. *subjectndn = NULL;
  188. /*
  189. * Get the control
  190. */
  191. slapi_pblock_get ( pb, SLAPI_REQCONTROLS, (void *) &requestcontrols );
  192. slapi_control_present ( requestcontrols,
  193. LDAP_CONTROL_GET_EFFECTIVE_RIGHTS,
  194. &subjectber,
  195. iscritical );
  196. if ( subjectber == NULL || subjectber->bv_val == NULL ||
  197. subjectber->bv_len == 0 )
  198. {
  199. aclutil_str_append ( errbuf, "get-effective-rights: missing subject" );
  200. slapi_log_error (SLAPI_LOG_FATAL, plugin_name, "%s\n", *errbuf );
  201. if (iscritical)
  202. return LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* RFC 4511 4.1.11 */
  203. else
  204. return LDAP_INVALID_SYNTAX;
  205. }
  206. if ( strncasecmp ( "dn:", subjectber->bv_val, 3 ) == 0 )
  207. {
  208. /*
  209. * This is a non-standard support to allow the subject being a plain
  210. * or base64 encoding string. Hence users using -J option in
  211. * ldapsearch don't have to do BER encoding for the subject.
  212. */
  213. orig = slapi_ch_malloc ( subjectber->bv_len + 1 );
  214. strncpy ( orig, subjectber->bv_val, subjectber->bv_len );
  215. *(orig + subjectber->bv_len) = '\0';
  216. }
  217. else
  218. {
  219. ber = ber_init (subjectber);
  220. if ( ber == NULL )
  221. {
  222. aclutil_str_append ( errbuf, "get-effective-rights: ber_init failed for the subject" );
  223. slapi_log_error (SLAPI_LOG_FATAL, plugin_name, "%s\n", *errbuf );
  224. if (iscritical)
  225. return LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* RFC 4511 4.1.11 */
  226. else
  227. return LDAP_OPERATIONS_ERROR;
  228. }
  229. /* "a" means to allocate storage as needed for octet string */
  230. if ( ber_scanf (ber, "a", &orig) == LBER_ERROR )
  231. {
  232. aclutil_str_append ( errbuf, "get-effective-rights: invalid ber tag in the subject" );
  233. slapi_log_error (SLAPI_LOG_FATAL, plugin_name, "%s\n", *errbuf );
  234. ber_free ( ber, 1 );
  235. if (iscritical)
  236. return LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* RFC 4511 4.1.11 */
  237. else
  238. return LDAP_INVALID_SYNTAX;
  239. }
  240. ber_free ( ber, 1 );
  241. }
  242. /*
  243. * The current implementation limits the subject to authorization ID
  244. * (see section 9 of RFC 2829) only. It also only supports the "dnAuthzId"
  245. * flavor, which looks like "dn:<DN>" where null <DN> is for anonymous.
  246. */
  247. subjectndnlen = orig ? strlen(orig) : 0;
  248. if ( NULL == orig || subjectndnlen < 3 || strncasecmp ( "dn:", orig, 3 ) != 0 )
  249. {
  250. aclutil_str_append ( errbuf, "get-effective-rights: subject is not dnAuthzId" );
  251. slapi_log_error (SLAPI_LOG_FATAL, plugin_name, "%s\n", *errbuf );
  252. slapi_ch_free_string(&orig);
  253. if (iscritical)
  254. return LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* RFC 4511 4.1.11 */
  255. else
  256. return LDAP_INVALID_SYNTAX;
  257. }
  258. /* memmove is safe for overlapping copy */
  259. normed = slapi_create_dn_string("%s", orig + 3);
  260. if (NULL == normed) {
  261. aclutil_str_append (errbuf, "get-effective-rights: failed to normalize dn: ");
  262. aclutil_str_append (errbuf, orig);
  263. slapi_log_error (SLAPI_LOG_FATAL, plugin_name, "%s\n", *errbuf);
  264. slapi_ch_free_string(&orig);
  265. if (iscritical)
  266. return LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* RFC 4511 4.1.11 */
  267. else
  268. return LDAP_INVALID_SYNTAX;
  269. }
  270. slapi_ch_free_string(&orig);
  271. *subjectndn = normed;
  272. slapi_dn_ignore_case(*subjectndn);
  273. return LDAP_SUCCESS;
  274. }
  275. static void
  276. _ger_release_gerpb (
  277. Slapi_PBlock **gerpb,
  278. void **aclcb, /* original aclcb */
  279. Slapi_PBlock *pb /* original pb */
  280. )
  281. {
  282. if ( *gerpb )
  283. {
  284. slapi_pblock_destroy ( *gerpb );
  285. *gerpb = NULL;
  286. }
  287. /* Put the original aclcb back to pb */
  288. if ( *aclcb )
  289. {
  290. Connection *conn = NULL;
  291. slapi_pblock_get ( pb, SLAPI_CONNECTION, &conn );
  292. if (conn)
  293. {
  294. struct aclcb *geraclcb;
  295. geraclcb = (struct aclcb *) acl_get_ext ( ACL_EXT_CONNECTION, conn );
  296. acl_conn_ext_destructor ( geraclcb, NULL, NULL );
  297. acl_set_ext ( ACL_EXT_CONNECTION, conn, *aclcb );
  298. *aclcb = NULL;
  299. }
  300. }
  301. }
  302. static int
  303. _ger_new_gerpb (
  304. Slapi_PBlock *pb,
  305. Slapi_Entry *e,
  306. const char *subjectndn,
  307. Slapi_PBlock **gerpb,
  308. void **aclcb, /* original aclcb */
  309. char **errbuf
  310. )
  311. {
  312. Connection *conn;
  313. struct acl_cblock *geraclcb;
  314. Acl_PBlock *geraclpb;
  315. Operation *gerop;
  316. int rc = LDAP_SUCCESS;
  317. *aclcb = NULL;
  318. *gerpb = slapi_pblock_new ();
  319. if ( *gerpb == NULL )
  320. {
  321. rc = LDAP_NO_MEMORY;
  322. goto bailout;
  323. }
  324. {
  325. /* aclpb initialization needs the backend */
  326. Slapi_Backend *be;
  327. slapi_pblock_get ( pb, SLAPI_BACKEND, &be );
  328. slapi_pblock_set ( *gerpb, SLAPI_BACKEND, be );
  329. }
  330. {
  331. int isroot = slapi_dn_isroot ( subjectndn );
  332. slapi_pblock_set ( *gerpb, SLAPI_REQUESTOR_ISROOT, &isroot );
  333. }
  334. /* Save requestor's aclcb and set subjectdn's one */
  335. {
  336. slapi_pblock_get ( pb, SLAPI_CONNECTION, &conn );
  337. slapi_pblock_set ( *gerpb, SLAPI_CONNECTION, conn );
  338. /* Can't share the conn->aclcb because of different context */
  339. geraclcb = (struct acl_cblock *) acl_conn_ext_constructor ( NULL, NULL);
  340. if ( geraclcb == NULL )
  341. {
  342. rc = LDAP_NO_MEMORY;
  343. goto bailout;
  344. }
  345. slapi_sdn_set_ndn_byval ( geraclcb->aclcb_sdn, subjectndn );
  346. *aclcb = acl_get_ext ( ACL_EXT_CONNECTION, conn );
  347. acl_set_ext ( ACL_EXT_CONNECTION, conn, (void *) geraclcb );
  348. }
  349. {
  350. gerop = operation_new ( OP_FLAG_INTERNAL );
  351. if ( gerop == NULL )
  352. {
  353. rc = LDAP_NO_MEMORY;
  354. goto bailout;
  355. }
  356. /*
  357. * conn is a no-use parameter in the functions
  358. * chained down from factory_create_extension
  359. */
  360. gerop->o_extension = factory_create_extension ( get_operation_object_type(), (void *)gerop, (void *)conn );
  361. slapi_pblock_set ( *gerpb, SLAPI_OPERATION, gerop );
  362. slapi_sdn_set_ndn_byval ( &gerop->o_sdn, subjectndn );
  363. geraclpb = acl_get_ext ( ACL_EXT_OPERATION, (void *)gerop);
  364. acl_init_aclpb ( *gerpb, geraclpb, subjectndn, 0 );
  365. geraclpb->aclpb_res_type |= ACLPB_EFFECTIVE_RIGHTS;
  366. }
  367. bailout:
  368. if ( rc != LDAP_SUCCESS )
  369. {
  370. _ger_release_gerpb ( gerpb, aclcb, pb );
  371. }
  372. return rc;
  373. }
  374. /*
  375. * Callers should have already allocated *gerstr to hold at least
  376. * "entryLevelRights: adnvxxx\n".
  377. */
  378. unsigned long
  379. _ger_get_entry_rights (
  380. Slapi_PBlock *gerpb,
  381. Slapi_Entry *e,
  382. const char *subjectndn,
  383. char **gerstr,
  384. size_t *gerstrsize,
  385. size_t *gerstrcap,
  386. char **errbuf
  387. )
  388. {
  389. unsigned long entryrights = 0;
  390. Slapi_RDN *rdn = NULL;
  391. char *rdntype = NULL;
  392. char *rdnvalue = NULL;
  393. _append_gerstr(gerstr, gerstrsize, gerstrcap, "entryLevelRights: ", NULL);
  394. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  395. "_ger_get_entry_rights: SLAPI_ACL_READ\n" );
  396. if (acl_access_allowed(gerpb, e, "*", NULL, SLAPI_ACL_READ) == LDAP_SUCCESS)
  397. {
  398. /* v - view e */
  399. entryrights |= SLAPI_ACL_READ;
  400. _append_gerstr(gerstr, gerstrsize, gerstrcap, "v", NULL);
  401. }
  402. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  403. "_ger_get_entry_rights: SLAPI_ACL_ADD\n" );
  404. if (acl_access_allowed(gerpb, e, NULL, NULL, SLAPI_ACL_ADD) == LDAP_SUCCESS)
  405. {
  406. /* a - add child entry below e */
  407. entryrights |= SLAPI_ACL_ADD;
  408. _append_gerstr(gerstr, gerstrsize, gerstrcap, "a", NULL);
  409. }
  410. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  411. "_ger_get_entry_rights: SLAPI_ACL_DELETE\n" );
  412. if (acl_access_allowed(gerpb, e, NULL, NULL, SLAPI_ACL_DELETE) == LDAP_SUCCESS)
  413. {
  414. /* d - delete e */
  415. entryrights |= SLAPI_ACL_DELETE;
  416. _append_gerstr(gerstr, gerstrsize, gerstrcap, "d", NULL);
  417. }
  418. if (config_get_moddn_aci()) {
  419. /* The server enforces the new MODDN aci right.
  420. * So the status 'n' is set if this right is granted.
  421. * Opposed to the legacy mode where this flag is set if
  422. * WRITE was granted on rdn attrbibute
  423. */
  424. if (acl_access_allowed(gerpb, e, NULL, NULL, SLAPI_ACL_MODDN) == LDAP_SUCCESS) {
  425. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  426. "_ger_get_entry_rights: SLAPI_ACL_MODDN %s\n", slapi_entry_get_ndn(e));
  427. /* n - rename e */
  428. entryrights |= SLAPI_ACL_MODDN;
  429. _append_gerstr(gerstr, gerstrsize, gerstrcap, "n", NULL);
  430. }
  431. } else {
  432. /*
  433. * Some limitation/simplification applied here:
  434. * - The modrdn right requires the rights to delete the old rdn and
  435. * the new one. However we have no knowledge of what the new rdn
  436. * is going to be.
  437. * - In multi-valued RDN case, we check the right on
  438. * the first rdn type only for now.
  439. */
  440. rdn = slapi_rdn_new_dn(slapi_entry_get_ndn(e));
  441. slapi_rdn_get_first(rdn, &rdntype, &rdnvalue);
  442. if (NULL != rdntype) {
  443. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  444. "_ger_get_entry_rights: SLAPI_ACL_WRITE_DEL & _ADD %s\n", rdntype);
  445. if (acl_access_allowed(gerpb, e, rdntype, NULL,
  446. ACLPB_SLAPI_ACL_WRITE_DEL) == LDAP_SUCCESS &&
  447. acl_access_allowed(gerpb, e, rdntype, NULL,
  448. ACLPB_SLAPI_ACL_WRITE_ADD) == LDAP_SUCCESS) {
  449. /* n - rename e */
  450. entryrights |= SLAPI_ACL_WRITE;
  451. _append_gerstr(gerstr, gerstrsize, gerstrcap, "n", NULL);
  452. }
  453. }
  454. slapi_rdn_free(&rdn);
  455. }
  456. if ( entryrights == 0 )
  457. {
  458. _append_gerstr(gerstr, gerstrsize, gerstrcap, "none", NULL);
  459. }
  460. _append_gerstr(gerstr, gerstrsize, gerstrcap, "\n", NULL);
  461. return entryrights;
  462. }
  463. /*
  464. * *gerstr should point to a heap buffer since it may need
  465. * to expand dynamically.
  466. */
  467. unsigned long
  468. _ger_get_attr_rights (
  469. Slapi_PBlock *gerpb,
  470. Slapi_Entry *e,
  471. const char *subjectndn,
  472. char *type,
  473. char **gerstr,
  474. size_t *gerstrsize,
  475. size_t *gerstrcap,
  476. int isfirstattr,
  477. char **errbuf
  478. )
  479. {
  480. unsigned long attrrights = 0;
  481. if (!isfirstattr)
  482. {
  483. _append_gerstr(gerstr, gerstrsize, gerstrcap, ", ", NULL);
  484. }
  485. _append_gerstr(gerstr, gerstrsize, gerstrcap, type, ":");
  486. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  487. "_ger_get_attr_rights: SLAPI_ACL_READ %s\n", type );
  488. if (acl_access_allowed(gerpb, e, type, NULL, SLAPI_ACL_READ) == LDAP_SUCCESS)
  489. {
  490. /* r - read the values of type */
  491. attrrights |= SLAPI_ACL_READ;
  492. _append_gerstr(gerstr, gerstrsize, gerstrcap, "r", NULL);
  493. }
  494. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  495. "_ger_get_attr_rights: SLAPI_ACL_SEARCH %s\n", type );
  496. if (acl_access_allowed(gerpb, e, type, NULL, SLAPI_ACL_SEARCH) == LDAP_SUCCESS)
  497. {
  498. /* s - search the values of type */
  499. attrrights |= SLAPI_ACL_SEARCH;
  500. _append_gerstr(gerstr, gerstrsize, gerstrcap, "s", NULL);
  501. }
  502. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  503. "_ger_get_attr_rights: SLAPI_ACL_COMPARE %s\n", type );
  504. if (acl_access_allowed(gerpb, e, type, NULL, SLAPI_ACL_COMPARE) == LDAP_SUCCESS)
  505. {
  506. /* c - compare the values of type */
  507. attrrights |= SLAPI_ACL_COMPARE;
  508. _append_gerstr(gerstr, gerstrsize, gerstrcap, "c", NULL);
  509. }
  510. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  511. "_ger_get_attr_rights: SLAPI_ACL_WRITE_ADD %s\n", type );
  512. if (acl_access_allowed(gerpb, e, type, NULL, ACLPB_SLAPI_ACL_WRITE_ADD) == LDAP_SUCCESS)
  513. {
  514. /* w - add the values of type */
  515. attrrights |= ACLPB_SLAPI_ACL_WRITE_ADD;
  516. _append_gerstr(gerstr, gerstrsize, gerstrcap, "w", NULL);
  517. }
  518. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  519. "_ger_get_attr_rights: SLAPI_ACL_WRITE_DEL %s\n", type );
  520. if (acl_access_allowed(gerpb, e, type, NULL, ACLPB_SLAPI_ACL_WRITE_DEL) == LDAP_SUCCESS)
  521. {
  522. /* o - delete the values of type */
  523. attrrights |= ACLPB_SLAPI_ACL_WRITE_DEL;
  524. _append_gerstr(gerstr, gerstrsize, gerstrcap, "o", NULL);
  525. }
  526. /* If subjectdn has no general write right, check for self write */
  527. if ( 0 == (attrrights & (ACLPB_SLAPI_ACL_WRITE_DEL | ACLPB_SLAPI_ACL_WRITE_ADD)) )
  528. {
  529. struct berval val;
  530. val.bv_val = (char *)subjectndn;
  531. val.bv_len = strlen (subjectndn);
  532. if (acl_access_allowed(gerpb, e, type, &val, ACLPB_SLAPI_ACL_WRITE_ADD) == LDAP_SUCCESS)
  533. {
  534. /* W - add self to the attribute */
  535. attrrights |= ACLPB_SLAPI_ACL_WRITE_ADD;
  536. _append_gerstr(gerstr, gerstrsize, gerstrcap, "W", NULL);
  537. }
  538. if (acl_access_allowed(gerpb, e, type, &val, ACLPB_SLAPI_ACL_WRITE_DEL) == LDAP_SUCCESS)
  539. {
  540. /* O - delete self from the attribute */
  541. attrrights |= ACLPB_SLAPI_ACL_WRITE_DEL;
  542. _append_gerstr(gerstr, gerstrsize, gerstrcap, "O", NULL);
  543. }
  544. }
  545. if ( attrrights == 0 )
  546. {
  547. _append_gerstr(gerstr, gerstrsize, gerstrcap, "none", NULL);
  548. }
  549. return attrrights;
  550. }
  551. #define GER_GET_ATTR_RIGHTS(attrs) \
  552. for (thisattr = (attrs); thisattr && *thisattr; thisattr++) \
  553. { \
  554. _ger_get_attr_rights (gerpb, e, subjectndn, *thisattr, \
  555. gerstr, gerstrsize, gerstrcap, isfirstattr, errbuf); \
  556. isfirstattr = 0; \
  557. } \
  558. #define GER_GET_ATTR_RIGHTA_EXT(c, inattrs, exattrs); \
  559. for ( i = 0; attrs[i]; i++ ) \
  560. { \
  561. if ((c) != *attrs[i] && charray_inlist((inattrs), attrs[i]) && \
  562. !charray_inlist((exattrs), attrs[i])) \
  563. { \
  564. _ger_get_attr_rights ( gerpb, e, subjectndn, attrs[i], \
  565. gerstr, gerstrsize, gerstrcap, isfirstattr, errbuf ); \
  566. isfirstattr = 0; \
  567. } \
  568. }
  569. void
  570. _ger_get_attrs_rights (
  571. Slapi_PBlock *gerpb,
  572. Slapi_Entry *e,
  573. const char *subjectndn,
  574. char **attrs,
  575. char **gerstr,
  576. size_t *gerstrsize,
  577. size_t *gerstrcap,
  578. char **errbuf
  579. )
  580. {
  581. int isfirstattr = 1;
  582. /* gerstr was initially allocated with enough space for one more line */
  583. _append_gerstr(gerstr, gerstrsize, gerstrcap, "attributeLevelRights: ", NULL);
  584. /*
  585. * If it's stated attribute list is given,
  586. * the first attr in the list should not be empty.
  587. * Otherwise, it's considered the list is not given.
  588. */
  589. if (attrs && *attrs && (strlen(*attrs) > 0))
  590. {
  591. int i = 0;
  592. char **allattrs = NULL;
  593. char **opattrs = NULL;
  594. char **noexpattrs = NULL; /* attrs not to expose */
  595. char **myattrs = NULL;
  596. char **thisattr = NULL;
  597. int hasstar = charray_inlist(attrs, "*");
  598. int hasplus = charray_inlist(attrs, "+");
  599. Slapi_Attr *objclasses = NULL;
  600. Slapi_ValueSet *objclassvals = NULL;
  601. int isextensibleobj = 0;
  602. /* get all attrs available for the entry */
  603. slapi_entry_attr_find(e, "objectclass", &objclasses);
  604. if (NULL != objclasses) {
  605. Slapi_Value *v;
  606. slapi_attr_get_valueset(objclasses, &objclassvals);
  607. i = slapi_valueset_first_value(objclassvals, &v);
  608. if (-1 != i)
  609. {
  610. const char *ocname = NULL;
  611. allattrs = slapi_schema_list_objectclass_attributes(
  612. (const char *)v->bv.bv_val,
  613. SLAPI_OC_FLAG_REQUIRED|SLAPI_OC_FLAG_ALLOWED);
  614. /* check if this entry is an extensble object or not */
  615. ocname = slapi_value_get_string(v);
  616. if ( strcasecmp( ocname, "extensibleobject" ) == 0 )
  617. {
  618. isextensibleobj = 1;
  619. }
  620. /* add "aci" to the allattrs to adjust to do_search */
  621. charray_add(&allattrs, slapi_attr_syntax_normalize("aci"));
  622. while (-1 != i)
  623. {
  624. i = slapi_valueset_next_value(objclassvals, i, &v);
  625. if (-1 != i)
  626. {
  627. myattrs = slapi_schema_list_objectclass_attributes(
  628. (const char *)v->bv.bv_val,
  629. SLAPI_OC_FLAG_REQUIRED|SLAPI_OC_FLAG_ALLOWED);
  630. /* check if this entry is an extensble object or not */
  631. ocname = slapi_value_get_string(v);
  632. if ( strcasecmp( ocname, "extensibleobject" ) == 0 )
  633. {
  634. isextensibleobj = 1;
  635. }
  636. charray_merge_nodup(&allattrs, myattrs, 1/*copy_strs*/);
  637. charray_free(myattrs);
  638. }
  639. }
  640. }
  641. slapi_valueset_free(objclassvals);
  642. }
  643. /* get operational attrs */
  644. opattrs = slapi_schema_list_attribute_names(SLAPI_ATTR_FLAG_OPATTR);
  645. noexpattrs = slapi_schema_list_attribute_names(SLAPI_ATTR_FLAG_NOEXPOSE);
  646. /* subtract no expose attrs from opattrs (e.g., unhashed pw) */
  647. charray_subtract(opattrs, noexpattrs, NULL);
  648. if (isextensibleobj)
  649. {
  650. for ( i = 0; attrs[i]; i++ )
  651. {
  652. if ('\0' == *attrs[i]) {
  653. continue; /* skip an empty attr */
  654. }
  655. _ger_get_attr_rights ( gerpb, e, subjectndn, attrs[i], gerstr,
  656. gerstrsize, gerstrcap, isfirstattr, errbuf );
  657. isfirstattr = 0;
  658. }
  659. }
  660. else
  661. {
  662. if (hasstar && hasplus)
  663. {
  664. GER_GET_ATTR_RIGHTS(allattrs);
  665. GER_GET_ATTR_RIGHTS(opattrs);
  666. }
  667. else if (hasstar)
  668. {
  669. GER_GET_ATTR_RIGHTS(allattrs);
  670. GER_GET_ATTR_RIGHTA_EXT('*', opattrs, allattrs);
  671. }
  672. else if (hasplus)
  673. {
  674. GER_GET_ATTR_RIGHTS(opattrs);
  675. GER_GET_ATTR_RIGHTA_EXT('+', allattrs, opattrs);
  676. }
  677. else
  678. {
  679. for ( i = 0; attrs[i]; i++ )
  680. {
  681. if ('\0' == *attrs[i]) {
  682. continue; /* skip an empty attr */
  683. }
  684. if (charray_inlist(noexpattrs, attrs[i]))
  685. {
  686. continue;
  687. }
  688. else if (charray_inlist(allattrs, attrs[i]) ||
  689. charray_inlist(opattrs, attrs[i]) ||
  690. (0 == strcasecmp(attrs[i], "dn")) ||
  691. (0 == strcasecmp(attrs[i], "distinguishedName")))
  692. {
  693. _ger_get_attr_rights ( gerpb, e, subjectndn, attrs[i],
  694. gerstr, gerstrsize, gerstrcap, isfirstattr, errbuf );
  695. isfirstattr = 0;
  696. }
  697. else
  698. {
  699. /* if the attr does not belong to the entry,
  700. "<attr>:none" is returned */
  701. if (!isfirstattr)
  702. {
  703. _append_gerstr(gerstr, gerstrsize, gerstrcap, ", ", NULL);
  704. }
  705. _append_gerstr(gerstr, gerstrsize, gerstrcap, attrs[i], ":");
  706. _append_gerstr(gerstr, gerstrsize, gerstrcap, "none", NULL);
  707. isfirstattr = 0;
  708. }
  709. }
  710. }
  711. }
  712. charray_free(allattrs);
  713. charray_free(opattrs);
  714. }
  715. else
  716. {
  717. Slapi_Attr *prevattr = NULL, *attr;
  718. char *type;
  719. while ( slapi_entry_next_attr ( e, prevattr, &attr ) == 0 )
  720. {
  721. if ( ! slapi_attr_flag_is_set (attr, SLAPI_ATTR_FLAG_OPATTR) )
  722. {
  723. slapi_attr_get_type ( attr, &type );
  724. _ger_get_attr_rights ( gerpb, e, subjectndn, type, gerstr,
  725. gerstrsize, gerstrcap, isfirstattr, errbuf );
  726. isfirstattr = 0;
  727. }
  728. prevattr = attr;
  729. }
  730. }
  731. if ( isfirstattr )
  732. {
  733. /* not a single attribute was retrived or specified */
  734. _append_gerstr(gerstr, gerstrsize, gerstrcap, "*:none", NULL);
  735. }
  736. return;
  737. }
  738. /*
  739. * controlType = LDAP_CONTROL_GET_EFFECTIVE_RIGHTS;
  740. * criticality = n/a;
  741. * controlValue = OCTET STRING of BER encoding of the SEQUENCE of
  742. * ENUMERATED LDAP code
  743. */
  744. void
  745. _ger_set_response_control (
  746. Slapi_PBlock *pb,
  747. int iscritical,
  748. int rc
  749. )
  750. {
  751. LDAPControl **resultctrls = NULL;
  752. LDAPControl gerrespctrl;
  753. BerElement *ber = NULL;
  754. struct berval *berval = NULL;
  755. int found = 0;
  756. int i;
  757. if ( (ber = der_alloc ()) == NULL )
  758. {
  759. goto bailout;
  760. }
  761. /* begin sequence, enumeration, end sequence */
  762. ber_printf ( ber, "{e}", rc );
  763. if ( ber_flatten ( ber, &berval ) != LDAP_SUCCESS )
  764. {
  765. goto bailout;
  766. }
  767. gerrespctrl.ldctl_oid = LDAP_CONTROL_GET_EFFECTIVE_RIGHTS;
  768. gerrespctrl.ldctl_iscritical = iscritical;
  769. gerrespctrl.ldctl_value.bv_val = berval->bv_val;
  770. gerrespctrl.ldctl_value.bv_len = berval->bv_len;
  771. slapi_pblock_get ( pb, SLAPI_RESCONTROLS, &resultctrls );
  772. for (i = 0; resultctrls && resultctrls[i]; i++)
  773. {
  774. if (strcmp(resultctrls[i]->ldctl_oid, LDAP_CONTROL_GET_EFFECTIVE_RIGHTS) == 0)
  775. {
  776. /*
  777. * We get here if search returns more than one entry
  778. * and this is not the first entry.
  779. */
  780. ldap_control_free ( resultctrls[i] );
  781. resultctrls[i] = slapi_dup_control (&gerrespctrl);
  782. found = 1;
  783. break;
  784. }
  785. }
  786. if ( !found )
  787. {
  788. /* slapi_pblock_set() will dup the control */
  789. slapi_pblock_set ( pb, SLAPI_ADD_RESCONTROL, &gerrespctrl );
  790. }
  791. bailout:
  792. ber_free ( ber, 1 ); /* ber_free() checks for NULL param */
  793. ber_bvfree ( berval ); /* ber_bvfree() checks for NULL param */
  794. }
  795. int
  796. _ger_generate_template_entry (
  797. Slapi_PBlock *pb
  798. )
  799. {
  800. Slapi_Entry *e = NULL;
  801. char **gerattrs = NULL;
  802. char **attrs = NULL;
  803. char **allowedattrs = NULL;
  804. char *templateentry = NULL;
  805. char *object = NULL;
  806. char *superior = NULL;
  807. char *p = NULL;
  808. const char *dn = NULL;
  809. Slapi_DN *sdn = NULL;
  810. char *dntype = NULL;
  811. int siz = 0;
  812. int len = 0;
  813. int i = 0;
  814. int notfirst = 0;
  815. int rc = LDAP_SUCCESS;
  816. slapi_pblock_get( pb, SLAPI_SEARCH_GERATTRS, &gerattrs );
  817. if (NULL == gerattrs)
  818. {
  819. slapi_log_error (SLAPI_LOG_FATAL, plugin_name,
  820. "Objectclass info is expected "
  821. "in the attr list, e.g., \"*@person\"\n");
  822. rc = LDAP_SUCCESS;
  823. goto bailout;
  824. }
  825. for (i = 0; gerattrs && gerattrs[i]; i++)
  826. {
  827. object = strchr(gerattrs[i], '@');
  828. if (NULL != object && '\0' != *(++object))
  829. {
  830. break;
  831. }
  832. }
  833. if (NULL == object)
  834. {
  835. rc = LDAP_SUCCESS; /* no objectclass info; ok to return */
  836. goto bailout;
  837. }
  838. /*
  839. * Either @objectclass or @objectclass:dntype is accepted.
  840. * If @objectclass, the first MUST attributetype (or the first MAY
  841. * attributetype if MUST does not exist) is used for the attribute
  842. * type in the leaf RDN.
  843. * If @objectclass:dntype, dntype is used for the attribute type in the
  844. * leaf RDN.
  845. */
  846. dntype = strchr(object, ':');
  847. if (dntype) { /* @objectclasse:dntype */
  848. *dntype++ = '\0';
  849. }
  850. attrs = slapi_schema_list_objectclass_attributes(
  851. (const char *)object, SLAPI_OC_FLAG_REQUIRED);
  852. allowedattrs = slapi_schema_list_objectclass_attributes(
  853. (const char *)object, SLAPI_OC_FLAG_ALLOWED);
  854. charray_merge(&attrs, allowedattrs, 0 /* no copy */);
  855. slapi_ch_free((void **)&allowedattrs); /* free just allowedattrs */
  856. if (NULL == attrs) {
  857. rc = LDAP_SUCCESS; /* bogus objectclass info; ok to return */
  858. goto bailout;
  859. }
  860. for (i = 0; attrs[i]; i++)
  861. {
  862. if (0 == strcasecmp(attrs[i], "objectclass"))
  863. {
  864. /* <*attrp>: <object>\n\0 */
  865. siz += strlen(attrs[i]) + 4 + strlen(object);
  866. }
  867. else
  868. {
  869. /* <*attrp>: (template_attribute)\n\0 */
  870. siz += strlen(attrs[i]) + 4 + 20;
  871. }
  872. }
  873. /* get the target dn where the template entry is located */
  874. slapi_pblock_get( pb, SLAPI_TARGET_SDN, &sdn );
  875. dn = slapi_sdn_get_dn(sdn);
  876. if (dn)
  877. {
  878. /* dn: <attr>=<template_name>,<dn>\n\0 */
  879. if (dntype) {
  880. siz += strlen(dntype) + 30 + strlen(object) + strlen(dn);
  881. } else {
  882. siz += strlen(attrs[0]) + 30 + strlen(object) + strlen(dn);
  883. }
  884. }
  885. else
  886. {
  887. /* dn: <attr>=<template_name>\n\0 */
  888. if (dntype) {
  889. siz += strlen(dntype) + 30 + strlen(object);
  890. } else {
  891. siz += strlen(attrs[0]) + 30 + strlen(object);
  892. }
  893. }
  894. templateentry = (char *)slapi_ch_malloc(siz);
  895. if (NULL != dn && strlen(dn) > 0)
  896. {
  897. PR_snprintf(templateentry, siz,
  898. "dn: %s=template_%s_objectclass,%s\n",
  899. dntype?dntype:attrs[0], object, dn);
  900. }
  901. else
  902. {
  903. PR_snprintf(templateentry, siz,
  904. "dn: %s=template_%s_objectclass\n",
  905. dntype?dntype:attrs[0], object);
  906. }
  907. for (--i; i >= 0; i--)
  908. {
  909. len = strlen(templateentry);
  910. p = templateentry + len;
  911. if (0 == strcasecmp(attrs[i], "objectclass"))
  912. {
  913. PR_snprintf(p, siz - len, "%s: %s\n", attrs[i], object);
  914. }
  915. else
  916. {
  917. PR_snprintf(p, siz - len, "%s: (template_attribute)\n", attrs[i]);
  918. }
  919. }
  920. charray_free(attrs);
  921. while ((superior = slapi_schema_get_superior_name(object)) &&
  922. (0 != strcasecmp(superior, "top")))
  923. {
  924. if (notfirst)
  925. {
  926. slapi_ch_free_string(&object);
  927. }
  928. notfirst = 1;
  929. object = superior;
  930. attrs = slapi_schema_list_objectclass_attributes(
  931. (const char *)superior, SLAPI_OC_FLAG_REQUIRED);
  932. for (i = 0; attrs && attrs[i]; i++)
  933. {
  934. if (0 == strcasecmp(attrs[i], "objectclass"))
  935. {
  936. /* <*attrp>: <object>\n\0 */
  937. siz += strlen(attrs[i]) + 4 + strlen(object);
  938. }
  939. }
  940. templateentry = (char *)slapi_ch_realloc(templateentry, siz);
  941. for (--i; i >= 0; i--)
  942. {
  943. len = strlen(templateentry);
  944. p = templateentry + len;
  945. if (0 == strcasecmp(attrs[i], "objectclass"))
  946. {
  947. PR_snprintf(p, siz - len, "%s: %s\n", attrs[i], object);
  948. }
  949. }
  950. charray_free(attrs);
  951. }
  952. if (notfirst)
  953. {
  954. slapi_ch_free_string(&object);
  955. }
  956. slapi_ch_free_string(&superior);
  957. siz += 18; /* objectclass: top\n\0 */
  958. len = strlen(templateentry);
  959. templateentry = (char *)slapi_ch_realloc(templateentry, siz);
  960. p = templateentry + len;
  961. PR_snprintf(p, siz - len, "objectclass: top\n");
  962. e = slapi_str2entry(templateentry, SLAPI_STR2ENTRY_NOT_WELL_FORMED_LDIF);
  963. /* set the template entry to send the result to clients */
  964. slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_ENTRY, e);
  965. bailout:
  966. slapi_ch_free_string(&templateentry);
  967. return rc;
  968. }
  969. int
  970. acl_get_effective_rights (
  971. Slapi_PBlock *pb,
  972. Slapi_Entry *e, /* target entry */
  973. char **attrs, /* Attribute of the entry */
  974. struct berval *val, /* value of attr. NOT USED */
  975. int access, /* requested access rights */
  976. char **errbuf
  977. )
  978. {
  979. Slapi_PBlock *gerpb = NULL;
  980. void *aclcb = NULL;
  981. char *subjectndn = NULL;
  982. char *gerstr = NULL;
  983. size_t gerstrsize = 0;
  984. size_t gerstrcap = 0;
  985. int iscritical = 0; /* critical may be missing or false http://tools.ietf.org/html/draft-ietf-ldapext-acl-model-08 */
  986. int rc = LDAP_SUCCESS;
  987. *errbuf = '\0';
  988. if (NULL == e) /* create a template entry from SLAPI_SEARCH_GERATTRS */
  989. {
  990. rc = _ger_generate_template_entry ( pb );
  991. slapi_pblock_get ( pb, SLAPI_SEARCH_RESULT_ENTRY, &e );
  992. if ( rc != LDAP_SUCCESS || NULL == e )
  993. {
  994. goto bailout;
  995. }
  996. }
  997. /*
  998. * Get the subject
  999. */
  1000. rc = _ger_parse_control (pb, &subjectndn, &iscritical, errbuf );
  1001. if ( rc != LDAP_SUCCESS )
  1002. {
  1003. goto bailout;
  1004. }
  1005. /*
  1006. * The requestor should have g permission on the entry
  1007. * to get the effective rights.
  1008. */
  1009. rc = _ger_g_permission_granted (pb, e, subjectndn, errbuf);
  1010. if ( rc != LDAP_SUCCESS )
  1011. {
  1012. goto bailout;
  1013. }
  1014. /*
  1015. * Construct a new pb
  1016. */
  1017. rc = _ger_new_gerpb ( pb, e, subjectndn, &gerpb, &aclcb, errbuf );
  1018. if ( rc != LDAP_SUCCESS )
  1019. {
  1020. goto bailout;
  1021. }
  1022. /* Get entry level effective rights */
  1023. _ger_get_entry_rights ( gerpb, e, subjectndn, &gerstr, &gerstrsize, &gerstrcap, errbuf );
  1024. /*
  1025. * Attribute level effective rights may not be NULL
  1026. * even if entry level's is.
  1027. */
  1028. _ger_get_attrs_rights ( gerpb, e, subjectndn, attrs, &gerstr, &gerstrsize, &gerstrcap, errbuf );
  1029. bailout:
  1030. /*
  1031. * Now construct the response control
  1032. */
  1033. _ger_set_response_control ( pb, iscritical, rc );
  1034. if ( rc != LDAP_SUCCESS )
  1035. {
  1036. gerstr = slapi_ch_smprintf("entryLevelRights: %d\nattributeLevelRights: *:%d", rc, rc );
  1037. }
  1038. slapi_log_error (SLAPI_LOG_ACLSUMMARY, plugin_name,
  1039. "###### Effective Rights on Entry (%s) for Subject (%s) ######\n",
  1040. e?slapi_entry_get_ndn(e):"null", subjectndn?subjectndn:"null");
  1041. slapi_log_error (SLAPI_LOG_ACLSUMMARY, plugin_name, "%s\n", gerstr);
  1042. /* Restore pb */
  1043. _ger_release_gerpb ( &gerpb, &aclcb, pb );
  1044. /*
  1045. * General plugin uses SLAPI_RESULT_TEXT for error text. Here
  1046. * SLAPI_PB_RESULT_TEXT is exclusively shared with add, dse and schema.
  1047. * slapi_pblock_set() will free any previous data, and
  1048. * pblock_done() will free SLAPI_PB_RESULT_TEXT.
  1049. */
  1050. slapi_pblock_set (pb, SLAPI_PB_RESULT_TEXT, gerstr);
  1051. if ( !iscritical )
  1052. {
  1053. /*
  1054. * If return code is not LDAP_SUCCESS, the server would
  1055. * abort sending the data of the entry to the client.
  1056. */
  1057. rc = LDAP_SUCCESS;
  1058. }
  1059. slapi_ch_free ( (void **) &subjectndn );
  1060. slapi_ch_free ( (void **) &gerstr );
  1061. return rc;
  1062. }