plugin_syntax.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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 ? 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 (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. int
  316. slapi_entry_syntax_check(
  317. Slapi_PBlock *pb, Slapi_Entry *e, int override
  318. )
  319. {
  320. int ret = 0;
  321. int i = 0;
  322. int is_replicated_operation = 0;
  323. int syntaxcheck = config_get_syntaxcheck();
  324. int syntaxlogging = config_get_syntaxlogging();
  325. Slapi_Attr *prevattr = NULL;
  326. Slapi_Attr *a = NULL;
  327. char errtext[ BUFSIZ ];
  328. char *errp = &errtext[0];
  329. size_t err_remaining = sizeof(errtext);
  330. if (pb != NULL) {
  331. slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  332. }
  333. /* If syntax checking and logging are off, or if this is a
  334. * replicated operation, just return that the syntax is OK. */
  335. if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
  336. is_replicated_operation) {
  337. goto exit;
  338. }
  339. i = slapi_entry_first_attr(e, &a);
  340. while ((-1 != i) && a && (a->a_plugin != NULL)) {
  341. /* If no validate function is available for this type, just
  342. * assume that the value is valid. */
  343. if ( a->a_plugin->plg_syntax_validate != NULL ) {
  344. int numvals = 0;
  345. slapi_attr_get_numvalues(a, &numvals);
  346. if ( numvals > 0 ) {
  347. Slapi_Value *val = NULL;
  348. const struct berval *bval = NULL;
  349. int hint = slapi_attr_first_value(a, &val);
  350. /* iterate through each value to check if it's valid */
  351. while (val != NULL) {
  352. bval = slapi_value_get_berval(val);
  353. if ((a->a_plugin->plg_syntax_validate( bval )) != 0) {
  354. if (syntaxlogging) {
  355. slapi_log_error( SLAPI_LOG_FATAL, "Syntax Check",
  356. "\"%s\": (%s) value #%d invalid per syntax\n",
  357. slapi_entry_get_dn(e), a->a_type, hint );
  358. }
  359. if (syntaxcheck || override) {
  360. if (pb) {
  361. /* Append new text to any existing text. */
  362. errp += PR_snprintf( errp, err_remaining,
  363. "%s: value #%d invalid per syntax\n", a->a_type, hint );
  364. err_remaining -= errp - &errtext[0];
  365. }
  366. ret = 1;
  367. }
  368. }
  369. hint = slapi_attr_next_value(a, hint, &val);
  370. }
  371. }
  372. }
  373. prevattr = a;
  374. i = slapi_entry_next_attr(e, prevattr, &a);
  375. }
  376. /* See if we need to set the error text in the pblock. */
  377. if (errp != &errtext[0]) {
  378. /* SLAPI_PB_RESULT_TEXT duplicates the text in slapi_pblock_set */
  379. slapi_pblock_set( pb, SLAPI_PB_RESULT_TEXT, errtext );
  380. }
  381. exit:
  382. return( ret );
  383. }
  384. /* Checks if the values of all attributes being added in a Slapi_Mods
  385. * are valid for the syntax specified for the attribute in question.
  386. * The new values in an add or replace modify operation and the newrdn
  387. * value for a modrdn operation will be checked.
  388. * Returns 1 if there is a syntax violation and sets the error message
  389. * appropriately. Returns 0 if everything checks out fine.
  390. */
  391. int
  392. slapi_mods_syntax_check(
  393. Slapi_PBlock *pb, LDAPMod **mods, int override
  394. )
  395. {
  396. int ret = 0;
  397. int i, j = 0;
  398. int is_replicated_operation = 0;
  399. int syntaxcheck = config_get_syntaxcheck();
  400. int syntaxlogging = config_get_syntaxlogging();
  401. char errtext[ BUFSIZ ];
  402. char *errp = &errtext[0];
  403. size_t err_remaining = sizeof(errtext);
  404. char *dn = NULL;
  405. LDAPMod *mod = NULL;
  406. if (mods == NULL) {
  407. ret = 1;
  408. goto exit;
  409. }
  410. if (pb != NULL) {
  411. slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
  412. slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
  413. }
  414. /* If syntax checking and logging are off, or if this is a
  415. * replicated operation, just return that the syntax is OK. */
  416. if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
  417. is_replicated_operation) {
  418. goto exit;
  419. }
  420. /* Loop through mods */
  421. for (i = 0; mods[i] != NULL; i++) {
  422. mod = mods[i];
  423. /* We only care about replace and add modify operations that
  424. * are truly adding new values to the entry. */
  425. if ((SLAPI_IS_MOD_REPLACE(mod->mod_op) || SLAPI_IS_MOD_ADD(mod->mod_op)) &&
  426. (mod->mod_bvalues != NULL)) {
  427. struct slapdplugin *syntax_plugin = NULL;
  428. /* Find the plug-in for this type, then call it's
  429. * validate function.*/
  430. slapi_attr_type2plugin(mod->mod_type, (void **)&syntax_plugin);
  431. if ((syntax_plugin != NULL) && (syntax_plugin->plg_syntax_validate != NULL)) {
  432. /* Loop through the values and validate each one */
  433. for (j = 0; mod->mod_bvalues[j] != NULL; j++) {
  434. if (syntax_plugin->plg_syntax_validate(mod->mod_bvalues[j]) != 0) {
  435. if (syntaxlogging) {
  436. slapi_log_error( SLAPI_LOG_FATAL, "Syntax Check", "\"%s\": (%s) value #%d invalid per syntax\n",
  437. dn ? dn : "NULL", mod->mod_type, j );
  438. }
  439. if (syntaxcheck || override) {
  440. if (pb) {
  441. /* Append new text to any existing text. */
  442. errp += PR_snprintf( errp, err_remaining,
  443. "%s: value #%d invalid per syntax\n", mod->mod_type, j );
  444. err_remaining -= errp - &errtext[0];
  445. }
  446. ret = 1;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. /* See if we need to set the error text in the pblock. */
  454. if (errp != &errtext[0]) {
  455. /* SLAPI_PB_RESULT_TEXT duplicates the text in slapi_pblock_set */
  456. slapi_pblock_set( pb, SLAPI_PB_RESULT_TEXT, errtext );
  457. }
  458. exit:
  459. return( ret );
  460. }
  461. SLAPI_DEPRECATED int
  462. slapi_call_syntax_values2keys( /* JCM SLOW FUNCTION */
  463. void *vpi,
  464. struct berval **vals,
  465. struct berval ***ivals,
  466. int ftype
  467. )
  468. {
  469. int rc;
  470. Slapi_Value **svin= NULL;
  471. Slapi_Value **svout= NULL;
  472. valuearray_init_bervalarray(vals,&svin); /* JCM SLOW FUNCTION */
  473. rc= slapi_call_syntax_values2keys_sv(vpi,svin,&svout,ftype);
  474. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  475. valuearray_free(&svout);
  476. valuearray_free(&svin);
  477. return rc;
  478. }
  479. int
  480. slapi_call_syntax_values2keys_sv(
  481. void *vpi,
  482. Slapi_Value **vals,
  483. Slapi_Value ***ivals,
  484. int ftype
  485. )
  486. {
  487. int rc;
  488. Slapi_PBlock pipb;
  489. struct slapdplugin *pi = vpi;
  490. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_call_syntax_values2keys\n",
  491. 0, 0, 0 );
  492. pblock_init( &pipb );
  493. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  494. *ivals = NULL;
  495. rc = -1; /* means no values2keys function */
  496. if ( pi != NULL && pi->plg_syntax_values2keys != NULL ) {
  497. rc = pi->plg_syntax_values2keys( &pipb, vals, ivals, ftype );
  498. }
  499. LDAPDebug( LDAP_DEBUG_FILTER,
  500. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  501. return( rc );
  502. }
  503. int
  504. slapi_attr_values2keys_sv_pb(
  505. const Slapi_Attr *sattr,
  506. Slapi_Value **vals,
  507. Slapi_Value ***ivals,
  508. int ftype,
  509. Slapi_PBlock *pb
  510. )
  511. {
  512. int rc;
  513. struct slapdplugin *pi = NULL;
  514. IFP v2k_fn = NULL;
  515. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_attr_values2keys_sv\n",
  516. 0, 0, 0 );
  517. switch (ftype) {
  518. case LDAP_FILTER_EQUALITY:
  519. case LDAP_FILTER_APPROX:
  520. if (sattr->a_mr_eq_plugin) {
  521. pi = sattr->a_mr_eq_plugin;
  522. v2k_fn = sattr->a_mr_eq_plugin->plg_mr_values2keys;
  523. } else if (sattr->a_plugin) {
  524. pi = sattr->a_plugin;
  525. v2k_fn = sattr->a_plugin->plg_syntax_values2keys;
  526. }
  527. break;
  528. case LDAP_FILTER_SUBSTRINGS:
  529. if (sattr->a_mr_sub_plugin) {
  530. pi = sattr->a_mr_sub_plugin;
  531. v2k_fn = sattr->a_mr_sub_plugin->plg_mr_values2keys;
  532. } else if (sattr->a_plugin) {
  533. pi = sattr->a_plugin;
  534. v2k_fn = sattr->a_plugin->plg_syntax_values2keys;
  535. }
  536. break;
  537. default:
  538. LDAPDebug( LDAP_DEBUG_ANY, "<= slapi_attr_values2keys_sv: ERROR: unsupported filter type %d\n",
  539. ftype, 0, 0 );
  540. rc = LDAP_PROTOCOL_ERROR;
  541. goto done;
  542. }
  543. slapi_pblock_set( pb, SLAPI_PLUGIN, pi );
  544. *ivals = NULL;
  545. rc = -1; /* means no values2keys function */
  546. if ( ( pi != NULL ) && ( v2k_fn != NULL ) ) {
  547. rc = (*v2k_fn)( pb, vals, ivals, ftype );
  548. }
  549. done:
  550. LDAPDebug( LDAP_DEBUG_FILTER,
  551. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  552. return( rc );
  553. }
  554. int
  555. slapi_attr_values2keys_sv(
  556. const Slapi_Attr *sattr,
  557. Slapi_Value **vals,
  558. Slapi_Value ***ivals,
  559. int ftype
  560. )
  561. {
  562. Slapi_PBlock pb;
  563. pblock_init(&pb);
  564. return slapi_attr_values2keys_sv_pb(sattr, vals, ivals, ftype, &pb);
  565. }
  566. SLAPI_DEPRECATED int
  567. slapi_attr_values2keys( /* JCM SLOW FUNCTION */
  568. const Slapi_Attr *sattr,
  569. struct berval **vals,
  570. struct berval ***ivals,
  571. int ftype
  572. )
  573. {
  574. int rc;
  575. Slapi_Value **svin= NULL;
  576. Slapi_Value **svout= NULL;
  577. valuearray_init_bervalarray(vals,&svin); /* JCM SLOW FUNCTION */
  578. rc= slapi_attr_values2keys_sv(sattr,svin,&svout,ftype);
  579. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  580. valuearray_free(&svout);
  581. valuearray_free(&svin);
  582. return rc;
  583. }
  584. /*
  585. * almost identical to slapi_call_syntax_values2keys_sv except accepting
  586. * pblock to pass some info such as substrlen.
  587. */
  588. int
  589. slapi_call_syntax_values2keys_sv_pb(
  590. void *vpi,
  591. Slapi_Value **vals,
  592. Slapi_Value ***ivals,
  593. int ftype,
  594. Slapi_PBlock *pb
  595. )
  596. {
  597. int rc;
  598. struct slapdplugin *pi = vpi;
  599. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_call_syntax_values2keys\n",
  600. 0, 0, 0 );
  601. slapi_pblock_set( pb, SLAPI_PLUGIN, vpi );
  602. *ivals = NULL;
  603. rc = -1; /* means no values2keys function */
  604. if ( pi != NULL && pi->plg_syntax_values2keys != NULL ) {
  605. rc = pi->plg_syntax_values2keys( pb, vals, ivals, ftype );
  606. }
  607. LDAPDebug( LDAP_DEBUG_FILTER,
  608. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  609. return( rc );
  610. }
  611. SLAPI_DEPRECATED int
  612. slapi_call_syntax_assertion2keys_ava( /* JCM SLOW FUNCTION */
  613. void *vpi,
  614. struct berval *val,
  615. struct berval ***ivals,
  616. int ftype
  617. )
  618. {
  619. int rc;
  620. Slapi_Value svin;
  621. Slapi_Value **svout= NULL;
  622. slapi_value_init_berval(&svin, val);
  623. rc= slapi_call_syntax_assertion2keys_ava_sv(vpi,&svin,&svout,ftype);
  624. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  625. valuearray_free(&svout);
  626. value_done(&svin);
  627. return rc;
  628. }
  629. SLAPI_DEPRECATED int
  630. slapi_call_syntax_assertion2keys_ava_sv(
  631. void *vpi,
  632. Slapi_Value *val,
  633. Slapi_Value ***ivals,
  634. int ftype
  635. )
  636. {
  637. int rc;
  638. Slapi_PBlock pipb;
  639. struct slapdplugin *pi = vpi;
  640. LDAPDebug( LDAP_DEBUG_FILTER,
  641. "=> slapi_call_syntax_assertion2keys_ava\n", 0, 0, 0 );
  642. pblock_init( &pipb );
  643. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  644. rc = -1; /* means no assertion2keys function */
  645. if ( pi->plg_syntax_assertion2keys_ava != NULL ) {
  646. rc = pi->plg_syntax_assertion2keys_ava( &pipb, val, ivals, ftype );
  647. }
  648. LDAPDebug( LDAP_DEBUG_FILTER,
  649. "<= slapi_call_syntax_assertion2keys_ava %d\n", rc, 0, 0 );
  650. return( rc );
  651. }
  652. int
  653. slapi_attr_assertion2keys_ava_sv(
  654. const Slapi_Attr *sattr,
  655. Slapi_Value *val,
  656. Slapi_Value ***ivals,
  657. int ftype
  658. )
  659. {
  660. int rc;
  661. Slapi_PBlock pipb;
  662. struct slapdplugin *pi = NULL;
  663. IFP a2k_fn = NULL;
  664. LDAPDebug( LDAP_DEBUG_FILTER,
  665. "=> slapi_attr_assertion2keys_ava_sv\n", 0, 0, 0 );
  666. switch (ftype) {
  667. case LDAP_FILTER_EQUALITY:
  668. case LDAP_FILTER_APPROX:
  669. case LDAP_FILTER_EQUALITY_FAST:
  670. if (sattr->a_mr_eq_plugin) {
  671. pi = sattr->a_mr_eq_plugin;
  672. a2k_fn = sattr->a_mr_eq_plugin->plg_mr_assertion2keys_ava;
  673. } else if (sattr->a_plugin) {
  674. pi = sattr->a_plugin;
  675. a2k_fn = sattr->a_plugin->plg_syntax_assertion2keys_ava;
  676. }
  677. break;
  678. default:
  679. LDAPDebug( LDAP_DEBUG_ANY, "<= slapi_attr_assertion2keys_ava_sv: ERROR: unsupported filter type %d\n",
  680. ftype, 0, 0 );
  681. rc = LDAP_PROTOCOL_ERROR;
  682. goto done;
  683. }
  684. pblock_init( &pipb );
  685. slapi_pblock_set( &pipb, SLAPI_PLUGIN, pi );
  686. rc = -1; /* means no assertion2keys function */
  687. if ( a2k_fn != NULL ) {
  688. rc = (*a2k_fn)( &pipb, val, ivals, ftype );
  689. }
  690. done:
  691. LDAPDebug( LDAP_DEBUG_FILTER,
  692. "<= slapi_attr_assertion2keys_ava_sv %d\n", rc, 0, 0 );
  693. return( rc );
  694. }
  695. SLAPI_DEPRECATED int
  696. slapi_attr_assertion2keys_ava( /* JCM SLOW FUNCTION */
  697. const Slapi_Attr *sattr,
  698. struct berval *val,
  699. struct berval ***ivals,
  700. int ftype
  701. )
  702. {
  703. int rc;
  704. Slapi_Value svin;
  705. Slapi_Value **svout= NULL;
  706. slapi_value_init_berval(&svin, val);
  707. rc= slapi_attr_assertion2keys_ava_sv(sattr,&svin,&svout,ftype);
  708. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  709. valuearray_free(&svout);
  710. value_done(&svin);
  711. return rc;
  712. }
  713. SLAPI_DEPRECATED int
  714. slapi_call_syntax_assertion2keys_sub( /* JCM SLOW FUNCTION */
  715. void *vpi,
  716. char *initial,
  717. char **any,
  718. char *final,
  719. struct berval ***ivals
  720. )
  721. {
  722. int rc;
  723. Slapi_Value **svout= NULL;
  724. rc= slapi_call_syntax_assertion2keys_sub_sv(vpi,initial,any,final,&svout);
  725. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  726. valuearray_free(&svout);
  727. return rc;
  728. }
  729. int
  730. slapi_call_syntax_assertion2keys_sub_sv(
  731. void *vpi,
  732. char *initial,
  733. char **any,
  734. char *final,
  735. Slapi_Value ***ivals
  736. )
  737. {
  738. int rc;
  739. Slapi_PBlock pipb;
  740. struct slapdplugin *pi = vpi;
  741. LDAPDebug( LDAP_DEBUG_FILTER,
  742. "=> slapi_call_syntax_assertion2keys_sub\n", 0, 0, 0 );
  743. pblock_init( &pipb );
  744. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  745. rc = -1; /* means no assertion2keys function */
  746. *ivals = NULL;
  747. if ( pi->plg_syntax_assertion2keys_sub != NULL ) {
  748. rc = pi->plg_syntax_assertion2keys_sub( &pipb, initial, any,
  749. final, ivals );
  750. }
  751. LDAPDebug( LDAP_DEBUG_FILTER,
  752. "<= slapi_call_syntax_assertion2keys_sub %d\n", rc, 0, 0 );
  753. return( rc );
  754. }
  755. int
  756. slapi_attr_assertion2keys_sub_sv(
  757. const Slapi_Attr *sattr,
  758. char *initial,
  759. char **any,
  760. char *final,
  761. Slapi_Value ***ivals
  762. )
  763. {
  764. int rc;
  765. Slapi_PBlock pipb;
  766. struct slapdplugin *pi = NULL;
  767. IFP a2k_fn = NULL;
  768. LDAPDebug( LDAP_DEBUG_FILTER,
  769. "=> slapi_attr_assertion2keys_sub_sv\n", 0, 0, 0 );
  770. if (sattr->a_mr_sub_plugin) {
  771. pi = sattr->a_mr_sub_plugin;
  772. a2k_fn = sattr->a_mr_sub_plugin->plg_mr_assertion2keys_sub;
  773. } else if (sattr->a_plugin) {
  774. pi = sattr->a_plugin;
  775. a2k_fn = sattr->a_plugin->plg_syntax_assertion2keys_sub;
  776. }
  777. pblock_init( &pipb );
  778. slapi_pblock_set( &pipb, SLAPI_PLUGIN, pi );
  779. rc = -1; /* means no assertion2keys function */
  780. *ivals = NULL;
  781. if ( a2k_fn != NULL ) {
  782. rc = (*a2k_fn)( &pipb, initial, any, final, ivals );
  783. }
  784. LDAPDebug( LDAP_DEBUG_FILTER,
  785. "<= slapi_attr_assertion2keys_sub_sv %d\n", rc, 0, 0 );
  786. return( rc );
  787. }
  788. SLAPI_DEPRECATED int
  789. slapi_attr_assertion2keys_sub( /* JCM SLOW FUNCTION */
  790. const Slapi_Attr *sattr,
  791. char *initial,
  792. char **any,
  793. char *final,
  794. struct berval ***ivals
  795. )
  796. {
  797. int rc;
  798. Slapi_Value **svout= NULL;
  799. rc= slapi_attr_assertion2keys_sub_sv(sattr,initial,any,final,&svout);
  800. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  801. valuearray_free(&svout);
  802. return rc;
  803. }