1
0

guide.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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) 2009 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* guide.c - Guide and Enhanced Guide syntax routines */
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include <sys/types.h>
  45. #include "syntax.h"
  46. static int guide_filter_ava( Slapi_PBlock *pb, struct berval *bvfilter,
  47. Slapi_Value **bvals, int ftype, Slapi_Value **retVal );
  48. static int guide_filter_sub( Slapi_PBlock *pb, char *initial, char **any,
  49. char *final, Slapi_Value **bvals );
  50. static int guide_values2keys( Slapi_PBlock *pb, Slapi_Value **val,
  51. Slapi_Value ***ivals, int ftype );
  52. static int guide_assertion2keys_ava( Slapi_PBlock *pb, Slapi_Value *val,
  53. Slapi_Value ***ivals, int ftype );
  54. static int guide_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any,
  55. char *final, Slapi_Value ***ivals );
  56. static int guide_compare(struct berval *v1, struct berval *v2);
  57. static int enhancedguide_validate(struct berval *val);
  58. static int guide_validate(struct berval *val);
  59. static int criteria_validate(const char *start, const char *end);
  60. static int andterm_validate(const char *start, const char *end, const char **last);
  61. static int term_validate(const char *start, const char *end, const char **last);
  62. static void guide_normalize(
  63. Slapi_PBlock *pb,
  64. char *s,
  65. int trim_spaces,
  66. char **alt
  67. );
  68. /* the first name is the official one from RFC 4517 */
  69. static char *guide_names[] = { "Guide", "guide", GUIDE_SYNTAX_OID, 0 };
  70. static char *enhancedguide_names[] = { "Enhanced Guide", "enhancedguide",
  71. ENHANCEDGUIDE_SYNTAX_OID, 0 };
  72. static Slapi_PluginDesc guide_pdesc = { "guide-syntax", VENDOR, DS_PACKAGE_VERSION,
  73. "Guide attribute syntax plugin" };
  74. static Slapi_PluginDesc enhancedguide_pdesc = { "enhancedguide-syntax",
  75. VENDOR, DS_PACKAGE_VERSION,
  76. "Enhanced Guide attribute syntax plugin" };
  77. int
  78. guide_init( Slapi_PBlock *pb )
  79. {
  80. int rc, flags;
  81. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> guide_init\n", 0, 0, 0 );
  82. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  83. (void *) SLAPI_PLUGIN_VERSION_01 );
  84. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  85. (void *)&guide_pdesc );
  86. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_AVA,
  87. (void *) guide_filter_ava );
  88. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_SUB,
  89. (void *) guide_filter_sub );
  90. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALUES2KEYS,
  91. (void *) guide_values2keys );
  92. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA,
  93. (void *) guide_assertion2keys_ava );
  94. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB,
  95. (void *) guide_assertion2keys_sub );
  96. flags = SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING;
  97. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FLAGS,
  98. (void *) &flags );
  99. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NAMES,
  100. (void *) guide_names );
  101. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_OID,
  102. (void *) GUIDE_SYNTAX_OID );
  103. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_COMPARE,
  104. (void *) guide_compare );
  105. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
  106. (void *) guide_validate );
  107. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
  108. (void *) guide_normalize );
  109. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= guide_init %d\n", rc, 0, 0 );
  110. return( rc );
  111. }
  112. int
  113. enhancedguide_init( Slapi_PBlock *pb )
  114. {
  115. int rc, flags;
  116. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> guide_init\n", 0, 0, 0 );
  117. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  118. (void *) SLAPI_PLUGIN_VERSION_01 );
  119. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  120. (void *)&enhancedguide_pdesc );
  121. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_AVA,
  122. (void *) guide_filter_ava );
  123. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_SUB,
  124. (void *) guide_filter_sub );
  125. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALUES2KEYS,
  126. (void *) guide_values2keys );
  127. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA,
  128. (void *) guide_assertion2keys_ava );
  129. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB,
  130. (void *) guide_assertion2keys_sub );
  131. flags = SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING;
  132. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FLAGS,
  133. (void *) &flags );
  134. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NAMES,
  135. (void *) enhancedguide_names );
  136. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_OID,
  137. (void *) ENHANCEDGUIDE_SYNTAX_OID );
  138. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_COMPARE,
  139. (void *) guide_compare );
  140. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
  141. (void *) enhancedguide_validate );
  142. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= guide_init %d\n", rc, 0, 0 );
  143. return( rc );
  144. }
  145. static int
  146. guide_filter_ava(
  147. Slapi_PBlock *pb,
  148. struct berval *bvfilter,
  149. Slapi_Value **bvals,
  150. int ftype,
  151. Slapi_Value **retVal
  152. )
  153. {
  154. int filter_normalized = 0;
  155. int syntax = SYNTAX_CIS;
  156. if (pb) {
  157. slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED,
  158. &filter_normalized );
  159. if (filter_normalized) {
  160. syntax |= SYNTAX_NORM_FILT;
  161. }
  162. }
  163. return( string_filter_ava( bvfilter, bvals, syntax,
  164. ftype, retVal ) );
  165. }
  166. static int
  167. guide_filter_sub(
  168. Slapi_PBlock *pb,
  169. char *initial,
  170. char **any,
  171. char *final,
  172. Slapi_Value **bvals
  173. )
  174. {
  175. return( string_filter_sub( pb, initial, any, final, bvals, SYNTAX_CIS ) );
  176. }
  177. static int
  178. guide_values2keys(
  179. Slapi_PBlock *pb,
  180. Slapi_Value **vals,
  181. Slapi_Value ***ivals,
  182. int ftype
  183. )
  184. {
  185. return( string_values2keys( pb, vals, ivals, SYNTAX_CIS,
  186. ftype ) );
  187. }
  188. static int
  189. guide_assertion2keys_ava(
  190. Slapi_PBlock *pb,
  191. Slapi_Value *val,
  192. Slapi_Value ***ivals,
  193. int ftype
  194. )
  195. {
  196. return(string_assertion2keys_ava( pb, val, ivals,
  197. SYNTAX_CIS, ftype ));
  198. }
  199. static int
  200. guide_assertion2keys_sub(
  201. Slapi_PBlock *pb,
  202. char *initial,
  203. char **any,
  204. char *final,
  205. Slapi_Value ***ivals
  206. )
  207. {
  208. return( string_assertion2keys_sub( pb, initial, any, final, ivals,
  209. SYNTAX_CIS ) );
  210. }
  211. static int guide_compare(
  212. struct berval *v1,
  213. struct berval *v2
  214. )
  215. {
  216. return value_cmp(v1, v2, SYNTAX_CIS, 3 /* Normalise both values */);
  217. }
  218. static int
  219. enhancedguide_validate(
  220. struct berval *val
  221. )
  222. {
  223. int rc = 0; /* assume the value is valid */
  224. const char *start = NULL;
  225. const char *end = NULL;
  226. const char *p = NULL;
  227. const char *sharp = NULL;
  228. /* Per RFC4517:
  229. *
  230. * EnhancedGuide = object-class SHARP WSP criteria WSP
  231. * SHARP WSP subset
  232. * subset = "baseobject" / "oneLevel" / "wholeSubtree"
  233. */
  234. /* Don't allow a 0 length string */
  235. if ((val == NULL) || (val->bv_len == 0)) {
  236. rc = 1;
  237. goto exit;
  238. }
  239. start = &(val->bv_val[0]);
  240. end = &(val->bv_val[val->bv_len - 1]);
  241. /* Find the first SHARP. */
  242. for (p = start; p <= end; p++) {
  243. if (IS_SHARP(*p)) {
  244. sharp = p;
  245. break;
  246. }
  247. }
  248. /* Fail if we didn't find a SHARP, or if SHARP
  249. * is at the start or end of the value. */
  250. if ((sharp == NULL) || (sharp == start) || (sharp == end)){
  251. rc = 1;
  252. goto exit;
  253. }
  254. /* Reset p and end to validate the object-class. */
  255. p = start;
  256. end = sharp - 1;
  257. /* Skip any leading spaces. */
  258. while ((p < sharp) && IS_SPACE(*p)) {
  259. p++;
  260. }
  261. /* Skip any trailing spaces. */
  262. while ((end > p) && IS_SPACE(*end)) {
  263. end--;
  264. }
  265. /* See if we only found spaces before the SHARP. */
  266. if (end < p) {
  267. rc = 1;
  268. goto exit;
  269. }
  270. /* Validate p to end as object-class. This is the same
  271. * as an oid, which is either a keystring or a numericoid. */
  272. if (IS_LEADKEYCHAR(*p)) {
  273. rc = keystring_validate(p, end);
  274. /* check if the value matches the numericoid form */
  275. } else if (isdigit(*p)) {
  276. rc = numericoid_validate(p, end);
  277. } else {
  278. rc = 1;
  279. }
  280. /* We're done if the object-class failed to validate. */
  281. if (rc != 0) {
  282. goto exit;
  283. }
  284. /* Reset start and end to validate the criteria. */
  285. start = sharp + 1;
  286. end = &(val->bv_val[val->bv_len - 1]);
  287. /* Find the next SHARP. */
  288. for (p = start; p <= end; p++) {
  289. if (IS_SHARP(*p)) {
  290. sharp = p;
  291. break;
  292. }
  293. }
  294. /* Fail if we didn't find a SHARP, or if SHARP
  295. * is at the start or end of the value. */
  296. if ((sharp == NULL) || (sharp == start) || (sharp == end)){
  297. rc = 1;
  298. goto exit;
  299. }
  300. /* Reset p and end to validate the criteria. */
  301. p = start;
  302. end = sharp - 1;
  303. /* Skip any leading spaces. */
  304. while ((p < sharp) && IS_SPACE(*p)) {
  305. p++;
  306. }
  307. /* Skip any trailing spaces. */
  308. while ((end > p) && IS_SPACE(*end)) {
  309. end--;
  310. }
  311. /* See if we only found spaces before the SHARP. */
  312. if (end < p) {
  313. rc = 1;
  314. goto exit;
  315. }
  316. /* Validate p to end as criteria. */
  317. if ((rc = criteria_validate(p, end)) != 0) {
  318. goto exit;
  319. }
  320. /* Reset start and end to validate the subset. We're
  321. * guaranteed to have a character after sharp. */
  322. p = start = sharp + 1;
  323. end = &(val->bv_val[val->bv_len - 1]);
  324. /* Skip any leading spaces. */
  325. while ((p < end) && IS_SPACE(*p)) {
  326. p ++;
  327. }
  328. /* Validate the subset. */
  329. switch (end - p + 1) {
  330. case 8:
  331. if (strncmp(p, "oneLevel", 8) != 0) {
  332. rc = 1;
  333. }
  334. break;
  335. case 10:
  336. if (strncmp(p, "baseobject", 10) != 0) {
  337. rc = 1;
  338. }
  339. break;
  340. case 12:
  341. if (strncmp(p, "wholeSubtree", 12) != 0) {
  342. rc = 1;
  343. }
  344. break;
  345. default:
  346. rc = 1;
  347. }
  348. exit:
  349. return rc;
  350. }
  351. static int
  352. guide_validate(
  353. struct berval *val
  354. )
  355. {
  356. int rc = 0; /* assume the value is valid */
  357. const char *start = NULL;
  358. const char *end = NULL;
  359. const char *p = NULL;
  360. const char *sharp = NULL;
  361. /* Per RFC4517:
  362. *
  363. * Guide = [ object-class SHARP ] criteria
  364. * object-class = WSP oid WSP
  365. * criteria = and-term *( BAR and-term )
  366. * and-term = term *( AMPERSAND term )
  367. * term = EXCLAIM term /
  368. * attributetype DOLLAR match-type /
  369. * LPAREN criteria RPAREN /
  370. * true /
  371. * false
  372. * match-type = "EQ" / "SUBSTR" / "GE" / "LE" / "APPROX"
  373. * true = "?true"
  374. * false = "?false"
  375. */
  376. /* Don't allow a 0 length string */
  377. if ((val == NULL) || (val->bv_len == 0)) {
  378. rc = 1;
  379. goto exit;
  380. }
  381. start = &(val->bv_val[0]);
  382. end = &(val->bv_val[val->bv_len - 1]);
  383. /* Look for a SHARP. If we have one, the value should
  384. * begin with the optional object-class. */
  385. for (p = start; p <= end; p++) {
  386. if (IS_SHARP(*p)) {
  387. sharp = p;
  388. break;
  389. }
  390. }
  391. if (sharp) {
  392. /* "criteria" must exist, so the SHARP
  393. * can't be at the end of the value. */
  394. if (sharp == end) {
  395. rc = 1;
  396. goto exit;
  397. }
  398. /* An optional object-class should be present. Reset
  399. * p to the beginning of the value and end to just
  400. * before the SHARP to validate the object-class.
  401. * We'll reset end later. */
  402. p = start;
  403. end = sharp - 1;
  404. /* This can happen if the value begins with SHARP. */
  405. if (end < start) {
  406. rc = 1;
  407. goto exit;
  408. }
  409. /* Skip any leading spaces. */
  410. while ((p < sharp) && IS_SPACE(*p)) {
  411. p++;
  412. }
  413. /* Skip any trailing spaces. */
  414. while ((end > p) && IS_SPACE(*end)) {
  415. end--;
  416. }
  417. /* See if we only found spaces before the SHARP. */
  418. if (end < p) {
  419. rc = 1;
  420. goto exit;
  421. }
  422. /* Validate p to end as object-class. This is the same
  423. * as an oid, which is either a keystring or a numericoid. */
  424. if (IS_LEADKEYCHAR(*p)) {
  425. rc = keystring_validate(p, end);
  426. /* check if the value matches the numericoid form */
  427. } else if (isdigit(*p)) {
  428. rc = numericoid_validate(p, end);
  429. } else {
  430. rc = 1;
  431. }
  432. /* If the object-class failed to validate, we're done. */
  433. if (rc != 0) {
  434. goto exit;
  435. }
  436. /* Reset p and end to point to the criteria. */
  437. p = sharp + 1;
  438. end = &(val->bv_val[val->bv_len - 1]);
  439. } else {
  440. /* Reset p. */
  441. p = start;
  442. }
  443. /* Validate the criteria. */
  444. rc = criteria_validate(p, end);
  445. exit:
  446. return rc;
  447. }
  448. /* criteria_validate()
  449. *
  450. * Helper to validate criteria element.
  451. */
  452. static int
  453. criteria_validate(const char *start, const char *end)
  454. {
  455. const char *p = start;
  456. const char *last = NULL;
  457. int rc = 0;
  458. /* Validate the criteria, which is just made up of a number
  459. * of and-term elements. Validate one and-term at a time. */
  460. while (p <= end) {
  461. if ((rc = andterm_validate(p, end, &last)) != 0) {
  462. goto exit;
  463. }
  464. p = last + 1;
  465. /* p should be pointing at a BAR, or one past
  466. * the end of the entire value. If we have
  467. * not reached the end, ensure that the next
  468. * character is a BAR and that there is at
  469. * least another character after the BAR. */
  470. if ((p <= end) && ((p == end) || (*p != '|'))) {
  471. rc = 1;
  472. goto exit;
  473. }
  474. /* Advance the pointer past the BAR so
  475. * it points at the beginning of the
  476. * next and-term (if there is one). */
  477. p++;
  478. }
  479. exit:
  480. return rc;
  481. }
  482. /*
  483. * andterm_validate()
  484. *
  485. * This function will validate a single and-term. If the and-term
  486. * is valid, 0 will be returned, otherwise non-zero will be returned.
  487. * A pointer to the last character of the and-term will be set in the
  488. * "last" parameter in the valid case.
  489. */
  490. static int
  491. andterm_validate(const char *start, const char *end, const char **last)
  492. {
  493. const char *p = start;
  494. int rc = 0;
  495. if ((start == NULL) || (end == NULL)) {
  496. rc = 1;
  497. goto exit;
  498. }
  499. while (p <= end) {
  500. if ((rc = term_validate(p, end, last)) != 0) {
  501. goto exit;
  502. }
  503. p = *last + 1;
  504. /* p should be pointing at an ampersand, a bar, or
  505. * one past the end of the entire value. If we have
  506. * not reached the end, ensure that the next
  507. * character is an ampersand or a bar and that
  508. * there is at least another character afterwards. */
  509. if ((p <= end) && ((p == end) || ((*p != '&') && (*p != '|')))) {
  510. rc = 1;
  511. goto exit;
  512. }
  513. /* If p is a bar, we're done. */
  514. if (*p == '|') {
  515. break;
  516. }
  517. /* Advance the pointer past the ampersand
  518. * or bar so it points at the beginning of
  519. * the next term or and-term (if there is
  520. * one). */
  521. p++;
  522. }
  523. exit:
  524. return rc;
  525. }
  526. static int
  527. term_validate(const char *start, const char *end, const char **last)
  528. {
  529. int rc = 0;
  530. const char *p = start;
  531. /* Per RFC 4517:
  532. *
  533. * term = EXCLAIM term /
  534. * attributetype DOLLAR match-type /
  535. * LPAREN criteria RPAREN /
  536. * true /
  537. * false
  538. * match-type = "EQ" / "SUBSTR" / "GE" / "LE" / "APPROX"
  539. * true = "?true"
  540. * false = "?false"
  541. */
  542. /* See if the term is prefixed by an EXCLAIM. */
  543. if (*p == '!') {
  544. p++;
  545. /* Ensure the value doesn't end with an EXCLAIM. */
  546. if (p > end) {
  547. rc = 1;
  548. goto exit;
  549. }
  550. }
  551. /* Check for valid terms. */
  552. switch (*p) {
  553. case '?':
  554. {
  555. /* true or false */
  556. int length = 0;
  557. p++;
  558. length = end - p + 1;
  559. if ((length >= 5) && (strncmp(p, "false", 5) == 0)) {
  560. /* Found false. We're done. */
  561. *last = p + 4;
  562. goto exit;
  563. }
  564. if ((length >= 4) && (strncmp(p, "true", 4) == 0)) {
  565. /* Found true. We're done. */
  566. *last = p + 3;
  567. goto exit;
  568. }
  569. /* We didn't find true or false. Fail. */
  570. rc = 1;
  571. goto exit;
  572. }
  573. case '(':
  574. {
  575. /* LPAREN criteria RPAREN */
  576. const char *lparen = p;
  577. while ((p <= end) && !IS_RPAREN(*p)) {
  578. p++;
  579. }
  580. if (p > end) {
  581. /* We didn't find a RPAREN. Fail. */
  582. rc = 1;
  583. goto exit;
  584. } else {
  585. /* p is pointing at the RPAREN. Validate
  586. * everything between the parens as criteria. */
  587. rc = criteria_validate(lparen + 1, p - 1);
  588. *last = p;
  589. }
  590. break;
  591. }
  592. default:
  593. {
  594. /* attributetype DOLLAR match-type */
  595. const char *attrtype = p;
  596. while ((p <= end) && !IS_DOLLAR(*p)) {
  597. p++;
  598. }
  599. if (p > end) {
  600. /* We didn't find a DOLLAR. Fail. */
  601. rc = 1;
  602. goto exit;
  603. } else {
  604. /* p is pointing at the DOLLAR. Validate
  605. * the attributetype before the DOLLAR. */
  606. if (IS_LEADKEYCHAR(*attrtype)) {
  607. rc = keystring_validate(attrtype, p - 1);
  608. /* check if the value matches the numericoid form */
  609. } else if (isdigit(*attrtype)) {
  610. rc = numericoid_validate(attrtype, p - 1);
  611. } else {
  612. rc = 1;
  613. }
  614. /* If the attributetype was invalid, we're done. */
  615. if (rc != 0) {
  616. goto exit;
  617. }
  618. /* Validate that a valid match-type
  619. * is after the DOLLAR. */
  620. if (p == end) {
  621. rc = 1;
  622. goto exit;
  623. } else {
  624. int length = 0;
  625. p++;
  626. length = end - p + 1;
  627. if (length >= 6) {
  628. /* APPROX, SUBSTR */
  629. if ((strncmp(p, "APPROX", 6) == 0) ||
  630. (strncmp(p, "SUBSTR", 6) == 0)) {
  631. /* We found a valid match-type.
  632. * We're done. */
  633. *last = p + 5;
  634. goto exit;
  635. }
  636. }
  637. if (length >= 2) {
  638. /* EQ, GE, LE */
  639. if ((strncmp(p, "EQ", 2) == 0) ||
  640. (strncmp(p, "GE", 2) == 0) ||
  641. (strncmp(p, "LE", 2) == 0)) {
  642. /* We found a valid match-type.
  643. * We're done. */
  644. *last = p + 1;
  645. goto exit;
  646. }
  647. }
  648. /* We failed to find a valid match-type. */
  649. rc = 1;
  650. goto exit;
  651. }
  652. }
  653. }
  654. }
  655. exit:
  656. return rc;
  657. }
  658. static void guide_normalize(
  659. Slapi_PBlock *pb,
  660. char *s,
  661. int trim_spaces,
  662. char **alt
  663. )
  664. {
  665. value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
  666. return;
  667. }