plugin_syntax.c 27 KB

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