1
0

guide.c 17 KB

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