1
0

7bit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. /*
  42. * 7bit.c
  43. *
  44. * Implements a directory server pre-operation plugin to test
  45. * attributes for 7 bit clean within a defined subtree in the
  46. * directory.
  47. *
  48. */
  49. #include <stdio.h>
  50. #include <slapi-plugin.h>
  51. #include <string.h>
  52. /* DBDB this should be pulled from a common header file */
  53. #ifdef _WIN32
  54. #ifndef strcasecmp
  55. #define strcasecmp(x,y) strcmpi(x,y)
  56. #endif
  57. #endif
  58. #if defined( LDAP_DEBUG ) && !defined( DEBUG )
  59. #define DEBUG
  60. #endif
  61. /*
  62. * ISSUES:
  63. * How should this plugin handle ACL issues? It seems wrong to reject
  64. * adds and modifies because there is already a conflicting UID, when
  65. * the request would have failed because of an ACL check anyway.
  66. *
  67. * This code currently defines a maximum filter string size of 512. Is
  68. * this large enough?
  69. *
  70. * This code currently does not quote the value portion of the filter as
  71. * it is created. This is a bug.
  72. */
  73. /* */
  74. #define BEGIN do {
  75. #define END } while(0);
  76. /*
  77. * Slapi plugin descriptor
  78. */
  79. static char *plugin_name = "NS7bitAttr";
  80. static Slapi_PluginDesc
  81. pluginDesc = { "NS7bitAttr", VENDOR, DS_PACKAGE_VERSION,
  82. "Enforce 7-bit clean attribute values" };
  83. /*
  84. * More information about constraint failure
  85. */
  86. static char *moreInfo =
  87. "The value is not 7-bit clean: ";
  88. /* ------------------------------------------------------------ */
  89. /*
  90. * op_error - Record (and report) an operational error.
  91. */
  92. static int
  93. op_error(int internal_error)
  94. {
  95. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  96. "Internal error: %d\n", internal_error);
  97. return LDAP_OPERATIONS_ERROR;
  98. }
  99. static void
  100. issue_error(Slapi_PBlock *pb, int result, char *type, char *value)
  101. {
  102. char *moreinfop;
  103. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  104. "%s result %d\n", type, result);
  105. if (value == NULL) {
  106. value = "unknown";
  107. }
  108. moreinfop = slapi_ch_smprintf("%s%s", moreInfo, value);
  109. /* Send failure to the client */
  110. slapi_send_ldap_result(pb, result, 0, moreinfop, 0, 0);
  111. slapi_ch_free((void **)&moreinfop);
  112. return;
  113. }
  114. /*
  115. * Check 'value' for 7-bit cleanliness.
  116. */
  117. static int
  118. bit_check_one_berval(const struct berval *value, char **violated)
  119. {
  120. int result;
  121. char *ch;
  122. int i;
  123. #ifdef DEBUG
  124. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name, "7-bit checking begin\n");
  125. #endif
  126. result = LDAP_SUCCESS;
  127. /* If no value, can't possibly be a conflict */
  128. if ( (struct berval *)NULL == value )
  129. return result;
  130. for(i=0, ch=value->bv_val; ch && i < (int)(value->bv_len) ;
  131. ch++, i++)
  132. {
  133. if (( 0x80 & *ch ) != 0 )
  134. {
  135. result = LDAP_CONSTRAINT_VIOLATION;
  136. *violated = value->bv_val;
  137. break;
  138. }
  139. }
  140. return result;
  141. }
  142. /*
  143. * Check a set of values for 7-bit cleanliness.
  144. *
  145. * If 'attr' is NULL, the values are taken from 'values'.
  146. * If 'attr' is non-NULL, the values are taken from 'attr'.
  147. */
  148. static int
  149. bit_check(Slapi_Attr *attr, struct berval **values, char **violated)
  150. {
  151. int result = LDAP_SUCCESS;
  152. *violated = NULL;
  153. /* If no values, can't possibly be a conflict */
  154. if ( (Slapi_Attr *)NULL == attr && (struct berval **)NULL == values )
  155. return result;
  156. if ( (Slapi_Attr *)NULL != attr )
  157. {
  158. Slapi_Value *v = NULL;
  159. int vhint = -1;
  160. for ( vhint = slapi_attr_first_value( attr, &v );
  161. vhint != -1 && LDAP_SUCCESS == result;
  162. vhint = slapi_attr_next_value( attr, vhint, &v ))
  163. {
  164. result = bit_check_one_berval(slapi_value_get_berval(v), violated);
  165. }
  166. }
  167. else
  168. {
  169. for (;*values != NULL && LDAP_SUCCESS == result; values++)
  170. {
  171. result = bit_check_one_berval(*values, violated);
  172. }
  173. }
  174. #ifdef DEBUG
  175. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  176. "7 bit check result = %d\n", result);
  177. #endif
  178. return result;
  179. }
  180. /* ------------------------------------------------------------ */
  181. /*
  182. * preop_add - pre-operation plug-in for add
  183. */
  184. static int
  185. preop_add(Slapi_PBlock *pb)
  186. {
  187. int result;
  188. char *violated = NULL;
  189. #ifdef DEBUG
  190. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name, "ADD begin\n");
  191. #endif
  192. result = LDAP_SUCCESS;
  193. /*
  194. * Do constraint check on the added entry. Set result.
  195. */
  196. BEGIN
  197. int err;
  198. int argc;
  199. char **argv;
  200. char **attrName;
  201. char *dn;
  202. Slapi_Entry *e;
  203. Slapi_Attr *attr;
  204. char **firstSubtree;
  205. char **subtreeDN;
  206. int subtreeCnt;
  207. int is_replicated_operation;
  208. /*
  209. * Get the arguments
  210. */
  211. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc);
  212. if (err) { result = op_error(53); break; }
  213. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
  214. if (err) { result = op_error(54); break; }
  215. /*
  216. * If this is a replication update, just be a noop.
  217. */
  218. err = slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  219. if (err) { result = op_error(56); break; }
  220. if (is_replicated_operation)
  221. {
  222. break;
  223. }
  224. /*
  225. * Get the target DN for this add operation
  226. */
  227. err = slapi_pblock_get(pb, SLAPI_ADD_TARGET, &dn);
  228. if (err) { result = op_error(50); break; }
  229. #ifdef DEBUG
  230. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name, "ADD target=%s\n", dn);
  231. #endif
  232. /*
  233. * Get the entry data for this add. Check whether it
  234. * contains a value for the unique attribute
  235. */
  236. err = slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
  237. if (err) { result = op_error(51); break; }
  238. for ( firstSubtree = argv; strcmp(*firstSubtree, ",") != 0;
  239. firstSubtree++, argc--) {}
  240. firstSubtree++;
  241. argc--;
  242. for (attrName = argv; strcmp(*attrName, ",") != 0; attrName++ )
  243. {
  244. /*
  245. * if the attribute is userpassword, check unhashed#user#password
  246. * instead. "userpassword" is encoded; it will always pass the 7bit
  247. * check.
  248. */
  249. char *attr_name;
  250. if ( strcasecmp(*attrName, "userpassword") == 0 )
  251. {
  252. attr_name = "unhashed#user#password";
  253. } else {
  254. attr_name = *attrName;
  255. }
  256. err = slapi_entry_attr_find(e, attr_name, &attr);
  257. if (err) continue; /* break;*/ /* no 7-bit attribute */
  258. /*
  259. * For each DN in the managed list, do 7-bit checking if
  260. * the target DN is a subnode in the tree.
  261. */
  262. for( subtreeDN=firstSubtree, subtreeCnt=argc ;subtreeCnt > 0;
  263. subtreeCnt--,subtreeDN++)
  264. {
  265. /*
  266. * issuffix determines whether the target is under the
  267. * subtree *subtreeDN
  268. */
  269. if (slapi_dn_issuffix(dn, *subtreeDN))
  270. {
  271. #ifdef DEBUG
  272. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  273. "ADD subtree=%s\n", *subtreeDN);
  274. #endif
  275. /*
  276. * Check if the value is 7-bit clean
  277. */
  278. result = bit_check(attr, NULL, &violated);
  279. if (result) break;
  280. }
  281. }
  282. /* don't have to go on if there is a value not 7-bit clean */
  283. if (result) break;
  284. }
  285. END
  286. if (result) {
  287. issue_error(pb, result, "ADD", violated);
  288. }
  289. return (result==LDAP_SUCCESS)?0:-1;
  290. }
  291. static void
  292. addMod(LDAPMod ***modary, int *capacity, int *nmods, LDAPMod *toadd)
  293. {
  294. if (*nmods == *capacity) {
  295. *capacity += 4;
  296. if (*modary) {
  297. *modary = (LDAPMod **)slapi_ch_realloc((char *)*modary, *capacity * sizeof(LDAPMod *));
  298. } else {
  299. *modary = (LDAPMod **)slapi_ch_malloc(*capacity * sizeof(LDAPMod *));
  300. }
  301. }
  302. (*modary)[*nmods] = toadd;
  303. (*nmods)++;
  304. }
  305. /* ------------------------------------------------------------ */
  306. /*
  307. * preop_modify - pre-operation plug-in for modify
  308. */
  309. static int
  310. preop_modify(Slapi_PBlock *pb)
  311. {
  312. int result;
  313. char *violated = NULL;
  314. LDAPMod **checkmods = NULL; /* holds mods to check */
  315. int checkmodsCapacity = 0; /* max capacity of checkmods */
  316. #ifdef DEBUG
  317. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  318. "MODIFY begin\n");
  319. #endif
  320. result = LDAP_SUCCESS;
  321. BEGIN
  322. int err;
  323. int argc;
  324. char **argv;
  325. char **attrName;
  326. LDAPMod **mods;
  327. LDAPMod **firstMods;
  328. LDAPMod *mod;
  329. char *target;
  330. char **firstSubtree;
  331. char **subtreeDN;
  332. int subtreeCnt;
  333. int is_replicated_operation;
  334. /*
  335. * Get the arguments
  336. */
  337. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc);
  338. if (err) { result = op_error(13); break; }
  339. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
  340. if (err) { result = op_error(14); break; }
  341. /*
  342. * If this is a replication update, just be a noop.
  343. */
  344. err = slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  345. if (err) { result = op_error(16); break; }
  346. if (is_replicated_operation)
  347. {
  348. break;
  349. }
  350. err = slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &firstMods);
  351. if (err) { result = op_error(10); break; }
  352. /* Get the target DN */
  353. err = slapi_pblock_get(pb, SLAPI_MODIFY_TARGET, &target);
  354. if (err) { result = op_error(11); break; }
  355. /*
  356. * Look for managed trees that include the target
  357. * Arguments before "," are the 7-bit clean attribute names. Arguemnts
  358. * after "," are subtreeDN's.
  359. */
  360. for ( firstSubtree = argv; strcmp(*firstSubtree, ",") != 0;
  361. firstSubtree++, argc--) {}
  362. firstSubtree++;
  363. argc--;
  364. for (attrName = argv; strcmp(*attrName, ",") != 0; attrName++ )
  365. {
  366. int modcount = 0;
  367. int ii = 0;
  368. /*
  369. * if the attribute is userpassword, check unhashed#user#password
  370. * instead. "userpassword" is encoded; it will always pass the 7bit
  371. * check.
  372. */
  373. char *attr_name;
  374. if ( strcasecmp(*attrName, "userpassword") == 0 )
  375. {
  376. attr_name = "unhashed#user#password";
  377. } else {
  378. attr_name = *attrName;
  379. }
  380. /* There may be more than one mod that matches e.g.
  381. changetype: modify
  382. delete: uid
  383. uid: balster1950
  384. -
  385. add: uid
  386. uid: scottg
  387. So, we need to first find all mods that contain the attribute
  388. which are add or replace ops and are bvalue encoded
  389. */
  390. /* find out how many mods meet this criteria */
  391. for(mods=firstMods;*mods;mods++)
  392. {
  393. mod = *mods;
  394. if ((slapi_attr_type_cmp(mod->mod_type, attr_name, 1) == 0) && /* mod contains target attr */
  395. (mod->mod_op & LDAP_MOD_BVALUES) && /* mod is bval encoded (not string val) */
  396. (mod->mod_bvalues && mod->mod_bvalues[0]) && /* mod actually contains some values */
  397. (SLAPI_IS_MOD_ADD(mod->mod_op) || /* mod is add */
  398. SLAPI_IS_MOD_REPLACE(mod->mod_op))) /* mod is replace */
  399. {
  400. addMod(&checkmods, &checkmodsCapacity, &modcount, mod);
  401. }
  402. }
  403. if (modcount == 0) {
  404. continue; /* no mods to check, go to next attr */
  405. }
  406. /*
  407. * stop checking at first mod that fails the check
  408. */
  409. for (ii = 0; (result == 0) && (ii < modcount); ++ii)
  410. {
  411. mod = checkmods[ii];
  412. /*
  413. * For each DN in the managed list, do 7-bit checking if
  414. * the target DN is a subnode in the tree.
  415. */
  416. for( subtreeDN=firstSubtree, subtreeCnt=argc ;subtreeCnt > 0;
  417. subtreeCnt--,subtreeDN++)
  418. {
  419. /*
  420. * issuffix determines whether the target is under the
  421. * subtree *subtreeDN
  422. */
  423. if (slapi_dn_issuffix(target, *subtreeDN))
  424. {
  425. #ifdef DEBUG
  426. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  427. "MODIFY subtree=%s\n", *subtreeDN);
  428. #endif
  429. /*
  430. * Check if the value is 7-bit clean
  431. */
  432. result = bit_check(NULL, mod->mod_bvalues, &violated);
  433. if (result) break;
  434. }
  435. }
  436. }
  437. /* don't have to go on if there is a value not 7-bit clean */
  438. if (result) break;
  439. }
  440. END
  441. slapi_ch_free((void **)&checkmods);
  442. if (result) {
  443. issue_error(pb, result, "MODIFY", violated);
  444. }
  445. return (result==LDAP_SUCCESS)?0:-1;
  446. }
  447. /* ------------------------------------------------------------ */
  448. /*
  449. * preop_modrdn - Pre-operation call for modify RDN
  450. *
  451. * Check that the new RDN does not include attributes that
  452. * cause a constraint violation
  453. */
  454. static int
  455. preop_modrdn(Slapi_PBlock *pb)
  456. {
  457. int result;
  458. Slapi_Entry *e;
  459. char *violated = NULL;
  460. #ifdef DEBUG
  461. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  462. "MODRDN begin\n");
  463. #endif
  464. /* Init */
  465. result = LDAP_SUCCESS;
  466. e = 0;
  467. BEGIN
  468. int err;
  469. int argc;
  470. char **argv;
  471. char **attrName;
  472. char *target;
  473. char *superior;
  474. char *rdn;
  475. Slapi_Attr *attr;
  476. char **firstSubtree;
  477. char **subtreeDN;
  478. int subtreeCnt;
  479. int is_replicated_operation;
  480. /*
  481. * Get the arguments
  482. */
  483. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc);
  484. if (err) { result = op_error(30); break; }
  485. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
  486. if (err) { result = op_error(31); break; }
  487. /*
  488. * If this is a replication update, just be a noop.
  489. */
  490. err = slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  491. if (err) { result = op_error(16); break; }
  492. if (is_replicated_operation)
  493. {
  494. break;
  495. }
  496. /* Get the DN of the entry being renamed */
  497. err = slapi_pblock_get(pb, SLAPI_MODRDN_TARGET, &target);
  498. if (err) { result = op_error(22); break; }
  499. /* Get superior value - unimplemented in 3.0 DS */
  500. err = slapi_pblock_get(pb, SLAPI_MODRDN_NEWSUPERIOR, &superior);
  501. if (err) { result = op_error(20); break; }
  502. /*
  503. * No superior means the entry is just renamed at
  504. * its current level in the tree. Use the target DN for
  505. * determining which managed tree this belongs to
  506. */
  507. if (!superior) superior = target;
  508. /* Get the new RDN - this has the attribute values */
  509. err = slapi_pblock_get(pb, SLAPI_MODRDN_NEWRDN, &rdn);
  510. if (err) { result = op_error(33); break; }
  511. #ifdef DEBUG
  512. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  513. "MODRDN newrdn=%s\n", rdn);
  514. #endif
  515. /*
  516. * Parse the RDN into attributes by creating a "dummy" entry
  517. * and setting the attributes from the RDN.
  518. *
  519. * The new entry must be freed.
  520. */
  521. e = slapi_entry_alloc();
  522. if (!e) { result = op_error(32); break; }
  523. /* NOTE: strdup on the rdn, since it will be freed when
  524. * the entry is freed */
  525. slapi_entry_set_dn(e, slapi_ch_strdup(rdn));
  526. err = slapi_entry_add_rdn_values(e);
  527. if (err)
  528. {
  529. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  530. "MODRDN bad rdn value=%s\n", rdn);
  531. break; /* Bad DN */
  532. }
  533. /*
  534. * arguments before "," are the 7-bit clean attribute names. Arguemnts
  535. * after "," are subtreeDN's.
  536. */
  537. for ( firstSubtree = argv; strcmp(*firstSubtree, ",") != 0;
  538. firstSubtree++, argc--) {}
  539. firstSubtree++;
  540. argc--;
  541. /*
  542. * Find out if the node is being moved into one of
  543. * the managed subtrees
  544. */
  545. for (attrName = argv; strcmp(*attrName, ",") != 0; attrName++ )
  546. {
  547. /*
  548. * If the attribut type is userpassword, do not replace it by
  549. * unhashed#user#password because unhashed#user#password does not exist
  550. * in this case.
  551. */
  552. /*
  553. * Find any 7-bit attribute data in the new RDN
  554. */
  555. err = slapi_entry_attr_find(e, *attrName, &attr);
  556. if (err) continue; /* break;*/ /* no 7-bit attribute */
  557. /*
  558. * For each DN in the managed list, do 7-bit checking if
  559. * the target DN is a subnode in the tree.
  560. */
  561. for( subtreeDN=firstSubtree, subtreeCnt=argc ;subtreeCnt > 0;
  562. subtreeCnt--,subtreeDN++)
  563. {
  564. /*
  565. * issuffix determines whether the target is under the
  566. * subtree *subtreeDN
  567. */
  568. if (slapi_dn_issuffix(superior, *subtreeDN))
  569. {
  570. #ifdef DEBUG
  571. slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name,
  572. "MODRDN subtree=%s\n", *subtreeDN);
  573. #endif
  574. /*
  575. * Check if the value is 7-bit clean
  576. */
  577. result = bit_check(attr, NULL, &violated);
  578. if (result) break;
  579. }
  580. }
  581. /* don't have to go on if there is a value not 7-bit clean */
  582. if (result) break;
  583. }
  584. END
  585. /* Clean-up */
  586. if (e) slapi_entry_free(e);
  587. if (result) {
  588. issue_error(pb, result, "MODRDN", violated);
  589. }
  590. return (result==LDAP_SUCCESS)?0:-1;
  591. }
  592. /* ------------------------------------------------------------ */
  593. /*
  594. * Initialize the plugin
  595. *
  596. */
  597. int
  598. NS7bitAttr_Init(Slapi_PBlock *pb)
  599. {
  600. int err = 0;
  601. BEGIN
  602. int argc;
  603. char **argv;
  604. /* Declare plugin version */
  605. err = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
  606. SLAPI_PLUGIN_VERSION_01);
  607. if (err) break;
  608. /*
  609. * Get and normalize arguments
  610. */
  611. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc);
  612. if (err) break;
  613. err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
  614. if (err) break;
  615. /*
  616. * Arguments before "," are the 7-bit attribute names. Arguments after
  617. * "," are the subtree DN's.
  618. */
  619. if (argc < 1) { err = -1; break; }
  620. for(;strcmp(*argv, ",") != 0 && argc > 0; argc--, argv++)
  621. {};
  622. if (argc == 0) { err = -1; break; }
  623. argv++; argc--;
  624. for(;argc > 0;argc--, argv++)
  625. slapi_dn_normalize_case(*argv);
  626. /* Provide descriptive information */
  627. err = slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  628. (void*)&pluginDesc);
  629. if (err) break;
  630. /* Register functions */
  631. err = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN,
  632. (void*)preop_add);
  633. if (err) break;
  634. err = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN,
  635. (void*)preop_modify);
  636. if (err) break;
  637. err = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODRDN_FN,
  638. (void*)preop_modrdn);
  639. if (err) break;
  640. END
  641. if (err) {
  642. slapi_log_error(SLAPI_LOG_PLUGIN, "NS7bitAttr_Init",
  643. "Error: %d\n", err);
  644. err = -1;
  645. }
  646. else
  647. slapi_log_error(SLAPI_LOG_PLUGIN, "NS7bitAttr_Init",
  648. "plugin loaded\n");
  649. return err;
  650. }