guide.c 20 KB

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