plugin_syntax.c 25 KB

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