plugin_syntax.c 28 KB

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