plugin_syntax.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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. * plugin_syntax.c - routines for calling syntax plugins
  43. */
  44. #include "slap.h"
  45. struct slapdplugin *
  46. plugin_syntax_find( const char *nameoroid )
  47. {
  48. struct slapdplugin *pi;
  49. /* LDAPDebug( LDAP_DEBUG_FILTER, "=> plugin_syntax_find (%s)\n", nameoroid, 0, 0 ); */
  50. for ( pi = get_plugin_list(PLUGIN_LIST_SYNTAX); pi != NULL; pi = pi->plg_next ) {
  51. if ( charray_inlist( pi->plg_syntax_names, (char *)nameoroid ) ) {
  52. break;
  53. }
  54. }
  55. /* LDAPDebug( LDAP_DEBUG_FILTER, "<= plugin_syntax_find %d\n", pi, 0, 0 ); */
  56. return ( pi );
  57. }
  58. /*
  59. * Enumerate all the syntax plugins, calling (*sef)() for each one.
  60. */
  61. void
  62. plugin_syntax_enumerate( SyntaxEnumFunc sef, void *arg )
  63. {
  64. struct slapdplugin *pi;
  65. for ( pi = get_plugin_list(PLUGIN_LIST_SYNTAX); pi != NULL;
  66. pi = pi->plg_next ) {
  67. (*sef)( pi->plg_syntax_names, &pi->plg_desc, arg );
  68. }
  69. }
  70. struct slapdplugin *
  71. slapi_get_global_syntax_plugins()
  72. {
  73. return get_plugin_list(PLUGIN_LIST_SYNTAX);
  74. }
  75. char *
  76. plugin_syntax2oid( struct slapdplugin *pi )
  77. {
  78. LDAPDebug(LDAP_DEBUG_ANY,
  79. "the function plugin_syntax2oid is deprecated - please use attr_get_syntax_oid instead\n", 0, 0, 0);
  80. PR_ASSERT(0);
  81. return( NULL );
  82. }
  83. int
  84. plugin_call_syntax_get_compare_fn(
  85. void *vpi,
  86. value_compare_fn_type *compare_fn
  87. )
  88. {
  89. LDAPDebug(LDAP_DEBUG_ANY,
  90. "the function plugin_call_syntax_get_compare_fn is deprecated - please use attr_get_value_cmp_fn instead\n", 0, 0, 0);
  91. PR_ASSERT(0);
  92. return( 0 );
  93. }
  94. int
  95. plugin_call_syntax_filter_ava(
  96. const Slapi_Attr *a,
  97. int ftype,
  98. struct ava *ava
  99. )
  100. {
  101. return(plugin_call_syntax_filter_ava_sv(a,ftype,ava,NULL,0 /*Present*/));
  102. }
  103. int
  104. plugin_call_syntax_filter_ava_sv(
  105. const Slapi_Attr *a,
  106. int ftype,
  107. struct ava *ava,
  108. Slapi_Value **retVal,
  109. int useDeletedValues
  110. )
  111. {
  112. int rc;
  113. Slapi_PBlock pipb;
  114. IFP ava_fn = NULL;
  115. LDAPDebug( LDAP_DEBUG_FILTER,
  116. "=> plugin_call_syntax_filter_ava %s=%s\n", ava->ava_type,
  117. ava->ava_value.bv_val, 0 );
  118. if ( ( a->a_mr_eq_plugin == NULL ) && ( a->a_mr_ord_plugin == NULL ) && ( a->a_plugin == NULL ) ) {
  119. LDAPDebug( LDAP_DEBUG_FILTER,
  120. "<= plugin_call_syntax_filter_ava no plugin for attr (%s)\n",
  121. a->a_type, 0, 0 );
  122. return( LDAP_PROTOCOL_ERROR ); /* syntax unkonwn */
  123. }
  124. pblock_init( &pipb );
  125. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
  126. rc = -1; /* does not match by default */
  127. switch ( ftype ) {
  128. case LDAP_FILTER_GE:
  129. case LDAP_FILTER_LE:
  130. if ((a->a_mr_ord_plugin == NULL) &&
  131. ((a->a_plugin->plg_syntax_flags &
  132. SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0)) {
  133. LDAPDebug( LDAP_DEBUG_FILTER,
  134. "<= plugin_call_syntax_filter_ava: attr (%s) has no ordering matching rule, and syntax does not define a compare function\n",
  135. a->a_type, 0, 0 );
  136. rc = LDAP_PROTOCOL_ERROR;
  137. break;
  138. }
  139. /* if the attribute has an ordering matching rule plugin, use that,
  140. otherwise, just use the syntax plugin */
  141. if (a->a_mr_ord_plugin != NULL) {
  142. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_mr_ord_plugin );
  143. ava_fn = a->a_mr_ord_plugin->plg_mr_filter_ava;
  144. } else {
  145. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
  146. ava_fn = a->a_plugin->plg_syntax_filter_ava;
  147. }
  148. /* FALL */
  149. case LDAP_FILTER_EQUALITY:
  150. case LDAP_FILTER_APPROX:
  151. if (NULL == ava_fn) {
  152. /* if we have an equality matching rule plugin, use that,
  153. otherwise, just use the syntax plugin */
  154. if (a->a_mr_eq_plugin) {
  155. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_mr_eq_plugin );
  156. ava_fn = a->a_mr_eq_plugin->plg_mr_filter_ava;
  157. } else {
  158. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
  159. ava_fn = a->a_plugin->plg_syntax_filter_ava;
  160. }
  161. }
  162. if ( ava_fn != NULL ) {
  163. /* JCM - Maybe the plugin should use the attr value iterator too... */
  164. Slapi_Value **va;
  165. if(useDeletedValues) {
  166. va= valueset_get_valuearray(&a->a_deleted_values);
  167. } else {
  168. va= valueset_get_valuearray(&a->a_present_values);
  169. }
  170. if(va!=NULL) {
  171. rc = (*ava_fn)( &pipb, &ava->ava_value, va, ftype, retVal );
  172. }
  173. } else {
  174. LDAPDebug( LDAP_DEBUG_FILTER,
  175. "<= plugin_call_syntax_filter_ava: attr (%s) has no ava filter function\n",
  176. a->a_type, 0, 0 );
  177. }
  178. break;
  179. default:
  180. LDAPDebug( LDAP_DEBUG_ANY, "plugin_call_syntax_filter_ava: "
  181. "unknown filter type %d\n", ftype, 0, 0 );
  182. rc = LDAP_PROTOCOL_ERROR;
  183. break;
  184. }
  185. LDAPDebug( LDAP_DEBUG_FILTER,
  186. "<= plugin_call_syntax_filter_ava %d\n", rc, 0, 0 );
  187. return( rc );
  188. }
  189. int
  190. plugin_call_syntax_filter_sub(
  191. Slapi_PBlock *pb,
  192. Slapi_Attr *a,
  193. struct subfilt *fsub
  194. )
  195. {
  196. return(plugin_call_syntax_filter_sub_sv(pb,a,fsub));
  197. }
  198. int
  199. plugin_call_syntax_filter_sub_sv(
  200. Slapi_PBlock *pb,
  201. Slapi_Attr *a,
  202. struct subfilt *fsub
  203. )
  204. {
  205. Slapi_PBlock pipb;
  206. int rc;
  207. IFP sub_fn = NULL;
  208. LDAPDebug( LDAP_DEBUG_FILTER,
  209. "=> plugin_call_syntax_filter_sub_sv\n", 0, 0, 0 );
  210. if ( ( a->a_mr_sub_plugin == NULL ) && ( a->a_plugin == NULL ) ) {
  211. LDAPDebug( LDAP_DEBUG_FILTER,
  212. "<= plugin_call_syntax_filter_sub_sv attribute (%s) has no substring matching rule or syntax plugin\n",
  213. a->a_type, 0, 0 );
  214. return( -1 ); /* syntax unkonwn - does not match */
  215. }
  216. pblock_init( &pipb );
  217. /* use the substr matching rule plugin if available, otherwise, use
  218. the syntax plugin */
  219. if (a->a_mr_sub_plugin) {
  220. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_mr_sub_plugin );
  221. sub_fn = a->a_mr_sub_plugin->plg_mr_filter_sub;
  222. } else {
  223. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
  224. sub_fn = a->a_plugin->plg_syntax_filter_sub;
  225. }
  226. if ( sub_fn != NULL )
  227. {
  228. Slapi_Value **va= valueset_get_valuearray(&a->a_present_values);
  229. if (pb)
  230. {
  231. Operation *op = NULL;
  232. /* to pass SLAPI_SEARCH_TIMELIMIT & SLAPI_OPINITATED_TIME */
  233. slapi_pblock_get( pb, SLAPI_OPERATION, &op );
  234. slapi_pblock_set( &pipb, SLAPI_OPERATION, op );
  235. }
  236. rc = (*sub_fn)( &pipb, fsub->sf_initial, fsub->sf_any, fsub->sf_final, va);
  237. } else {
  238. rc = -1;
  239. }
  240. LDAPDebug( LDAP_DEBUG_FILTER, "<= plugin_call_syntax_filter_sub_sv %d\n",
  241. rc, 0, 0 );
  242. return( rc );
  243. }
  244. /* Checks if the DN string is valid according to the Distinguished Name
  245. * syntax. Setting override to 1 will force syntax checking to be performed,
  246. * even if syntax checking is disabled in the config. Setting override to 0
  247. * will obey the config settings.
  248. *
  249. * Returns 1 if there is a syntax violation and sets the error message
  250. * appropriately. Returns 0 if everything checks out fine.
  251. */
  252. int
  253. slapi_dn_syntax_check(
  254. Slapi_PBlock *pb, char *dn, int override
  255. )
  256. {
  257. int ret = 0;
  258. int is_replicated_operation = 0;
  259. int syntaxcheck = config_get_syntaxcheck();
  260. int syntaxlogging = config_get_syntaxlogging();
  261. char errtext[ BUFSIZ ];
  262. char *errp = &errtext[0];
  263. struct slapdplugin *dn_plugin = NULL;
  264. struct berval dn_bval = {0};
  265. if (pb != NULL) {
  266. slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  267. }
  268. /* If syntax checking and logging are off, or if this is a
  269. * replicated operation, just return that the syntax is OK. */
  270. if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
  271. is_replicated_operation) {
  272. goto exit;
  273. }
  274. /* Locate the dn syntax plugin. */
  275. slapi_attr_type2plugin("distinguishedName", (void **)&dn_plugin);
  276. /* Assume the value is valid if we don't find a dn validate function */
  277. if (dn_plugin && dn_plugin->plg_syntax_validate != NULL) {
  278. /* Create a berval to pass to the validate function. */
  279. if (dn) {
  280. dn_bval.bv_val = dn;
  281. dn_bval.bv_len = strlen(dn);
  282. /* Validate the value. */
  283. if (dn_plugin->plg_syntax_validate(&dn_bval) != 0) {
  284. if (syntaxlogging) {
  285. slapi_log_error( SLAPI_LOG_FATAL, "Syntax Check",
  286. "DN value (%s) invalid per syntax\n", dn);
  287. }
  288. if (syntaxcheck || override) {
  289. if (pb) {
  290. errp += PR_snprintf( errp, sizeof(errtext),
  291. "DN value invalid per syntax\n" );
  292. }
  293. ret = 1;
  294. }
  295. }
  296. }
  297. }
  298. /* See if we need to set the error text in the pblock. */
  299. if (pb && errp != &errtext[0]) {
  300. /* SLAPI_PB_RESULT_TEXT duplicates the text in slapi_pblock_set */
  301. slapi_pblock_set( pb, SLAPI_PB_RESULT_TEXT, errtext );
  302. }
  303. exit:
  304. return( ret );
  305. }
  306. /* Checks if the values of all attributes in an entry are valid for the
  307. * syntax specified for the attribute in question. Setting override to
  308. * 1 will force syntax checking to be performed, even if syntax checking
  309. * is disabled in the config. Setting override to 0 will obey the config
  310. * settings.
  311. *
  312. * Returns 1 if there is a syntax violation and sets the error message
  313. * appropriately. Returns 0 if everything checks out fine.
  314. *
  315. * Note: this function allows NULL pb. If NULL, is_replicated_operation
  316. * will not checked and error message will not be generated and returned.
  317. */
  318. int
  319. slapi_entry_syntax_check(
  320. Slapi_PBlock *pb, Slapi_Entry *e, int override
  321. )
  322. {
  323. int ret = 0;
  324. int i = 0;
  325. int is_replicated_operation = 0;
  326. int syntaxcheck = config_get_syntaxcheck();
  327. int syntaxlogging = config_get_syntaxlogging();
  328. Slapi_Attr *prevattr = NULL;
  329. Slapi_Attr *a = NULL;
  330. char errtext[ BUFSIZ ];
  331. char *errp = &errtext[0];
  332. size_t err_remaining = sizeof(errtext);
  333. if (pb != NULL) {
  334. slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  335. }
  336. /* If syntax checking and logging are off, or if this is a
  337. * replicated operation, just return that the syntax is OK. */
  338. if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
  339. is_replicated_operation) {
  340. goto exit;
  341. }
  342. i = slapi_entry_first_attr(e, &a);
  343. while ((-1 != i) && a && (a->a_plugin != NULL)) {
  344. /* If no validate function is available for this type, just
  345. * assume that the value is valid. */
  346. if ( a->a_plugin->plg_syntax_validate != NULL ) {
  347. int numvals = 0;
  348. slapi_attr_get_numvalues(a, &numvals);
  349. if ( numvals > 0 ) {
  350. Slapi_Value *val = NULL;
  351. const struct berval *bval = NULL;
  352. int hint = slapi_attr_first_value(a, &val);
  353. /* iterate through each value to check if it's valid */
  354. while (val != NULL) {
  355. bval = slapi_value_get_berval(val);
  356. if ((a->a_plugin->plg_syntax_validate( bval )) != 0) {
  357. if (syntaxlogging) {
  358. slapi_log_error( SLAPI_LOG_FATAL, "Syntax Check",
  359. "\"%s\": (%s) value #%d invalid per syntax\n",
  360. slapi_entry_get_dn(e), a->a_type, hint );
  361. }
  362. if (syntaxcheck || override) {
  363. if (pb) {
  364. /* Append new text to any existing text. */
  365. errp += PR_snprintf( errp, err_remaining,
  366. "%s: value #%d invalid per syntax\n", a->a_type, hint );
  367. err_remaining -= errp - &errtext[0];
  368. }
  369. ret = 1;
  370. }
  371. }
  372. hint = slapi_attr_next_value(a, hint, &val);
  373. }
  374. }
  375. }
  376. prevattr = a;
  377. i = slapi_entry_next_attr(e, prevattr, &a);
  378. }
  379. /* See if we need to set the error text in the pblock. */
  380. if (pb && (errp != &errtext[0])) { /* Check pb for coverity */
  381. /* SLAPI_PB_RESULT_TEXT duplicates the text in slapi_pblock_set */
  382. slapi_pblock_set( pb, SLAPI_PB_RESULT_TEXT, errtext );
  383. }
  384. exit:
  385. return( ret );
  386. }
  387. /* Checks if the values of all attributes being added in a Slapi_Mods
  388. * are valid for the syntax specified for the attribute in question.
  389. * The new values in an add or replace modify operation and the newrdn
  390. * value for a modrdn operation will be checked.
  391. * Returns 1 if there is a syntax violation and sets the error message
  392. * appropriately. Returns 0 if everything checks out fine.
  393. *
  394. * Note: this function allows NULL pb. If NULL, is_replicated_operation
  395. * will not checked and error message will not be generated and returned.
  396. */
  397. int
  398. slapi_mods_syntax_check(
  399. Slapi_PBlock *pb, LDAPMod **mods, int override
  400. )
  401. {
  402. int ret = 0;
  403. int i, j = 0;
  404. int is_replicated_operation = 0;
  405. int syntaxcheck = config_get_syntaxcheck();
  406. int syntaxlogging = config_get_syntaxlogging();
  407. char errtext[ BUFSIZ ];
  408. char *errp = &errtext[0];
  409. size_t err_remaining = sizeof(errtext);
  410. char *dn = NULL;
  411. LDAPMod *mod = NULL;
  412. if (mods == NULL) {
  413. ret = 1;
  414. goto exit;
  415. }
  416. if (pb != NULL) {
  417. slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  418. slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
  419. }
  420. /* If syntax checking and logging are off, or if this is a
  421. * replicated operation, just return that the syntax is OK. */
  422. if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
  423. is_replicated_operation) {
  424. goto exit;
  425. }
  426. /* Loop through mods */
  427. for (i = 0; mods[i] != NULL; i++) {
  428. mod = mods[i];
  429. /* We only care about replace and add modify operations that
  430. * are truly adding new values to the entry. */
  431. if ((SLAPI_IS_MOD_REPLACE(mod->mod_op) || SLAPI_IS_MOD_ADD(mod->mod_op)) &&
  432. (mod->mod_bvalues != NULL)) {
  433. struct slapdplugin *syntax_plugin = NULL;
  434. /* Find the plug-in for this type, then call it's
  435. * validate function.*/
  436. slapi_attr_type2plugin(mod->mod_type, (void **)&syntax_plugin);
  437. if ((syntax_plugin != NULL) && (syntax_plugin->plg_syntax_validate != NULL)) {
  438. /* Loop through the values and validate each one */
  439. for (j = 0; mod->mod_bvalues[j] != NULL; j++) {
  440. if (syntax_plugin->plg_syntax_validate(mod->mod_bvalues[j]) != 0) {
  441. if (syntaxlogging) {
  442. slapi_log_error( SLAPI_LOG_FATAL, "Syntax Check", "\"%s\": (%s) value #%d invalid per syntax\n",
  443. dn ? dn : "NULL", mod->mod_type, j );
  444. }
  445. if (syntaxcheck || override) {
  446. if (pb) {
  447. /* Append new text to any existing text. */
  448. errp += PR_snprintf( errp, err_remaining,
  449. "%s: value #%d invalid per syntax\n", mod->mod_type, j );
  450. err_remaining -= errp - &errtext[0];
  451. }
  452. ret = 1;
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. /* See if we need to set the error text in the pblock. */
  460. if (pb && (errp != &errtext[0])) { /* Check pb for coverity */
  461. /* SLAPI_PB_RESULT_TEXT duplicates the text in slapi_pblock_set */
  462. slapi_pblock_set( pb, SLAPI_PB_RESULT_TEXT, errtext );
  463. }
  464. exit:
  465. return( ret );
  466. }
  467. SLAPI_DEPRECATED int
  468. slapi_call_syntax_values2keys( /* JCM SLOW FUNCTION */
  469. void *vpi,
  470. struct berval **vals,
  471. struct berval ***ivals,
  472. int ftype
  473. )
  474. {
  475. int rc;
  476. Slapi_Value **svin= NULL;
  477. Slapi_Value **svout= NULL;
  478. valuearray_init_bervalarray(vals,&svin); /* JCM SLOW FUNCTION */
  479. rc= slapi_call_syntax_values2keys_sv(vpi,svin,&svout,ftype);
  480. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  481. valuearray_free(&svout);
  482. valuearray_free(&svin);
  483. return rc;
  484. }
  485. int
  486. slapi_call_syntax_values2keys_sv(
  487. void *vpi,
  488. Slapi_Value **vals,
  489. Slapi_Value ***ivals,
  490. int ftype
  491. )
  492. {
  493. int rc;
  494. Slapi_PBlock pipb;
  495. struct slapdplugin *pi = vpi;
  496. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_call_syntax_values2keys\n",
  497. 0, 0, 0 );
  498. pblock_init( &pipb );
  499. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  500. *ivals = NULL;
  501. rc = -1; /* means no values2keys function */
  502. if ( pi != NULL && pi->plg_syntax_values2keys != NULL ) {
  503. rc = pi->plg_syntax_values2keys( &pipb, vals, ivals, ftype );
  504. }
  505. LDAPDebug( LDAP_DEBUG_FILTER,
  506. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  507. return( rc );
  508. }
  509. int
  510. slapi_attr_values2keys_sv_pb(
  511. const Slapi_Attr *sattr,
  512. Slapi_Value **vals,
  513. Slapi_Value ***ivals,
  514. int ftype,
  515. Slapi_PBlock *pb
  516. )
  517. {
  518. int rc;
  519. struct slapdplugin *pi = NULL;
  520. IFP v2k_fn = NULL;
  521. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_attr_values2keys_sv\n",
  522. 0, 0, 0 );
  523. switch (ftype) {
  524. case LDAP_FILTER_EQUALITY:
  525. case LDAP_FILTER_APPROX:
  526. if (sattr->a_mr_eq_plugin) {
  527. pi = sattr->a_mr_eq_plugin;
  528. v2k_fn = sattr->a_mr_eq_plugin->plg_mr_values2keys;
  529. } else if (sattr->a_plugin) {
  530. pi = sattr->a_plugin;
  531. v2k_fn = sattr->a_plugin->plg_syntax_values2keys;
  532. }
  533. break;
  534. case LDAP_FILTER_SUBSTRINGS:
  535. if (sattr->a_mr_sub_plugin) {
  536. pi = sattr->a_mr_sub_plugin;
  537. v2k_fn = sattr->a_mr_sub_plugin->plg_mr_values2keys;
  538. } else if (sattr->a_plugin) {
  539. pi = sattr->a_plugin;
  540. v2k_fn = sattr->a_plugin->plg_syntax_values2keys;
  541. }
  542. break;
  543. default:
  544. LDAPDebug( LDAP_DEBUG_ANY, "<= slapi_attr_values2keys_sv: ERROR: unsupported filter type %d\n",
  545. ftype, 0, 0 );
  546. rc = LDAP_PROTOCOL_ERROR;
  547. goto done;
  548. }
  549. slapi_pblock_set( pb, SLAPI_PLUGIN, pi );
  550. *ivals = NULL;
  551. rc = -1; /* means no values2keys function */
  552. if ( ( pi != NULL ) && ( v2k_fn != NULL ) ) {
  553. rc = (*v2k_fn)( pb, vals, ivals, ftype );
  554. }
  555. done:
  556. LDAPDebug( LDAP_DEBUG_FILTER,
  557. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  558. return( rc );
  559. }
  560. int
  561. slapi_attr_values2keys_sv(
  562. const Slapi_Attr *sattr,
  563. Slapi_Value **vals,
  564. Slapi_Value ***ivals,
  565. int ftype
  566. )
  567. {
  568. Slapi_PBlock pb;
  569. pblock_init(&pb);
  570. return slapi_attr_values2keys_sv_pb(sattr, vals, ivals, ftype, &pb);
  571. }
  572. SLAPI_DEPRECATED int
  573. slapi_attr_values2keys( /* JCM SLOW FUNCTION */
  574. const Slapi_Attr *sattr,
  575. struct berval **vals,
  576. struct berval ***ivals,
  577. int ftype
  578. )
  579. {
  580. int rc;
  581. Slapi_Value **svin= NULL;
  582. Slapi_Value **svout= NULL;
  583. valuearray_init_bervalarray(vals,&svin); /* JCM SLOW FUNCTION */
  584. rc= slapi_attr_values2keys_sv(sattr,svin,&svout,ftype);
  585. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  586. valuearray_free(&svout);
  587. valuearray_free(&svin);
  588. return rc;
  589. }
  590. /*
  591. * almost identical to slapi_call_syntax_values2keys_sv except accepting
  592. * pblock to pass some info such as substrlen.
  593. */
  594. int
  595. slapi_call_syntax_values2keys_sv_pb(
  596. void *vpi,
  597. Slapi_Value **vals,
  598. Slapi_Value ***ivals,
  599. int ftype,
  600. Slapi_PBlock *pb
  601. )
  602. {
  603. int rc;
  604. struct slapdplugin *pi = vpi;
  605. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_call_syntax_values2keys\n",
  606. 0, 0, 0 );
  607. slapi_pblock_set( pb, SLAPI_PLUGIN, vpi );
  608. *ivals = NULL;
  609. rc = -1; /* means no values2keys function */
  610. if ( pi != NULL && pi->plg_syntax_values2keys != NULL ) {
  611. rc = pi->plg_syntax_values2keys( pb, vals, ivals, ftype );
  612. }
  613. LDAPDebug( LDAP_DEBUG_FILTER,
  614. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  615. return( rc );
  616. }
  617. SLAPI_DEPRECATED int
  618. slapi_call_syntax_assertion2keys_ava( /* JCM SLOW FUNCTION */
  619. void *vpi,
  620. struct berval *val,
  621. struct berval ***ivals,
  622. int ftype
  623. )
  624. {
  625. int rc;
  626. Slapi_Value svin;
  627. Slapi_Value **svout= NULL;
  628. slapi_value_init_berval(&svin, val);
  629. rc= slapi_call_syntax_assertion2keys_ava_sv(vpi,&svin,&svout,ftype);
  630. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  631. valuearray_free(&svout);
  632. value_done(&svin);
  633. return rc;
  634. }
  635. SLAPI_DEPRECATED int
  636. slapi_call_syntax_assertion2keys_ava_sv(
  637. void *vpi,
  638. Slapi_Value *val,
  639. Slapi_Value ***ivals,
  640. int ftype
  641. )
  642. {
  643. int rc;
  644. Slapi_PBlock pipb;
  645. struct slapdplugin *pi = vpi;
  646. LDAPDebug( LDAP_DEBUG_FILTER,
  647. "=> slapi_call_syntax_assertion2keys_ava\n", 0, 0, 0 );
  648. pblock_init( &pipb );
  649. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  650. rc = -1; /* means no assertion2keys function */
  651. if ( pi->plg_syntax_assertion2keys_ava != NULL ) {
  652. rc = pi->plg_syntax_assertion2keys_ava( &pipb, val, ivals, ftype );
  653. }
  654. LDAPDebug( LDAP_DEBUG_FILTER,
  655. "<= slapi_call_syntax_assertion2keys_ava %d\n", rc, 0, 0 );
  656. return( rc );
  657. }
  658. int
  659. slapi_attr_assertion2keys_ava_sv(
  660. const Slapi_Attr *sattr,
  661. Slapi_Value *val,
  662. Slapi_Value ***ivals,
  663. int ftype
  664. )
  665. {
  666. int rc;
  667. Slapi_PBlock pipb;
  668. struct slapdplugin *pi = NULL;
  669. IFP a2k_fn = NULL;
  670. LDAPDebug( LDAP_DEBUG_FILTER,
  671. "=> slapi_attr_assertion2keys_ava_sv\n", 0, 0, 0 );
  672. switch (ftype) {
  673. case LDAP_FILTER_EQUALITY:
  674. case LDAP_FILTER_APPROX:
  675. case LDAP_FILTER_EQUALITY_FAST:
  676. if (sattr->a_mr_eq_plugin) {
  677. pi = sattr->a_mr_eq_plugin;
  678. a2k_fn = sattr->a_mr_eq_plugin->plg_mr_assertion2keys_ava;
  679. } else if (sattr->a_plugin) {
  680. pi = sattr->a_plugin;
  681. a2k_fn = sattr->a_plugin->plg_syntax_assertion2keys_ava;
  682. }
  683. break;
  684. default:
  685. LDAPDebug( LDAP_DEBUG_ANY, "<= slapi_attr_assertion2keys_ava_sv: ERROR: unsupported filter type %d\n",
  686. ftype, 0, 0 );
  687. rc = LDAP_PROTOCOL_ERROR;
  688. goto done;
  689. }
  690. pblock_init( &pipb );
  691. slapi_pblock_set( &pipb, SLAPI_PLUGIN, pi );
  692. rc = -1; /* means no assertion2keys function */
  693. if ( a2k_fn != NULL ) {
  694. rc = (*a2k_fn)( &pipb, val, ivals, ftype );
  695. }
  696. done:
  697. LDAPDebug( LDAP_DEBUG_FILTER,
  698. "<= slapi_attr_assertion2keys_ava_sv %d\n", rc, 0, 0 );
  699. return( rc );
  700. }
  701. SLAPI_DEPRECATED int
  702. slapi_attr_assertion2keys_ava( /* JCM SLOW FUNCTION */
  703. const Slapi_Attr *sattr,
  704. struct berval *val,
  705. struct berval ***ivals,
  706. int ftype
  707. )
  708. {
  709. int rc;
  710. Slapi_Value svin;
  711. Slapi_Value **svout= NULL;
  712. slapi_value_init_berval(&svin, val);
  713. rc= slapi_attr_assertion2keys_ava_sv(sattr,&svin,&svout,ftype);
  714. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  715. valuearray_free(&svout);
  716. value_done(&svin);
  717. return rc;
  718. }
  719. SLAPI_DEPRECATED int
  720. slapi_call_syntax_assertion2keys_sub( /* JCM SLOW FUNCTION */
  721. void *vpi,
  722. char *initial,
  723. char **any,
  724. char *final,
  725. struct berval ***ivals
  726. )
  727. {
  728. int rc;
  729. Slapi_Value **svout= NULL;
  730. rc= slapi_call_syntax_assertion2keys_sub_sv(vpi,initial,any,final,&svout);
  731. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  732. valuearray_free(&svout);
  733. return rc;
  734. }
  735. int
  736. slapi_call_syntax_assertion2keys_sub_sv(
  737. void *vpi,
  738. char *initial,
  739. char **any,
  740. char *final,
  741. Slapi_Value ***ivals
  742. )
  743. {
  744. int rc;
  745. Slapi_PBlock pipb;
  746. struct slapdplugin *pi = vpi;
  747. LDAPDebug( LDAP_DEBUG_FILTER,
  748. "=> slapi_call_syntax_assertion2keys_sub\n", 0, 0, 0 );
  749. pblock_init( &pipb );
  750. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  751. rc = -1; /* means no assertion2keys function */
  752. *ivals = NULL;
  753. if ( pi->plg_syntax_assertion2keys_sub != NULL ) {
  754. rc = pi->plg_syntax_assertion2keys_sub( &pipb, initial, any,
  755. final, ivals );
  756. }
  757. LDAPDebug( LDAP_DEBUG_FILTER,
  758. "<= slapi_call_syntax_assertion2keys_sub %d\n", rc, 0, 0 );
  759. return( rc );
  760. }
  761. int
  762. slapi_attr_assertion2keys_sub_sv(
  763. const Slapi_Attr *sattr,
  764. char *initial,
  765. char **any,
  766. char *final,
  767. Slapi_Value ***ivals
  768. )
  769. {
  770. int rc;
  771. Slapi_PBlock pipb;
  772. struct slapdplugin *pi = NULL;
  773. IFP a2k_fn = NULL;
  774. LDAPDebug( LDAP_DEBUG_FILTER,
  775. "=> slapi_attr_assertion2keys_sub_sv\n", 0, 0, 0 );
  776. if (sattr->a_mr_sub_plugin) {
  777. pi = sattr->a_mr_sub_plugin;
  778. a2k_fn = sattr->a_mr_sub_plugin->plg_mr_assertion2keys_sub;
  779. } else if (sattr->a_plugin) {
  780. pi = sattr->a_plugin;
  781. a2k_fn = sattr->a_plugin->plg_syntax_assertion2keys_sub;
  782. }
  783. pblock_init( &pipb );
  784. slapi_pblock_set( &pipb, SLAPI_PLUGIN, pi );
  785. rc = -1; /* means no assertion2keys function */
  786. *ivals = NULL;
  787. if ( a2k_fn != NULL ) {
  788. rc = (*a2k_fn)( &pipb, initial, any, final, ivals );
  789. }
  790. LDAPDebug( LDAP_DEBUG_FILTER,
  791. "<= slapi_attr_assertion2keys_sub_sv %d\n", rc, 0, 0 );
  792. return( rc );
  793. }
  794. SLAPI_DEPRECATED int
  795. slapi_attr_assertion2keys_sub( /* JCM SLOW FUNCTION */
  796. const Slapi_Attr *sattr,
  797. char *initial,
  798. char **any,
  799. char *final,
  800. struct berval ***ivals
  801. )
  802. {
  803. int rc;
  804. Slapi_Value **svout= NULL;
  805. rc= slapi_attr_assertion2keys_sub_sv(sattr,initial,any,final,&svout);
  806. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  807. valuearray_free(&svout);
  808. return rc;
  809. }