2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
17 * schema.c: parsing routines used by servers and clients to process
24 #include <ac/stdlib.h>
26 #include <ac/string.h>
31 #include <ldap_schema.h>
34 choose_name( char *names[], const char *fallback )
36 return (names != NULL && names[0] != NULL) ? names[0] : fallback;
40 ldap_syntax2name( LDAPSyntax * syn )
42 return( syn->syn_oid );
46 ldap_matchingrule2name( LDAPMatchingRule * mr )
48 return( choose_name( mr->mr_names, mr->mr_oid ) );
52 ldap_matchingruleuse2name( LDAPMatchingRuleUse * mru )
54 return( choose_name( mru->mru_names, mru->mru_oid ) );
58 ldap_attributetype2name( LDAPAttributeType * at )
60 return( choose_name( at->at_names, at->at_oid ) );
64 ldap_objectclass2name( LDAPObjectClass * oc )
66 return( choose_name( oc->oc_names, oc->oc_oid ) );
70 ldap_contentrule2name( LDAPContentRule * cr )
72 return( choose_name( cr->cr_names, cr->cr_oid ) );
76 ldap_nameform2name( LDAPNameForm * nf )
78 return( choose_name( nf->nf_names, nf->nf_oid ) );
82 ldap_structurerule2name( LDAPStructureRule * sr )
84 return( choose_name( sr->sr_names, NULL ) );
88 * When pretty printing the entities we will be appending to a buffer.
89 * Since checking for overflow, realloc'ing and checking if no error
90 * is extremely boring, we will use a protection layer that will let
91 * us blissfully ignore the error until the end. This layer is
92 * implemented with the help of the next type.
95 typedef struct safe_string {
103 new_safe_string(int size)
107 ss = LDAP_MALLOC(sizeof(safe_string));
111 ss->val = LDAP_MALLOC(size);
125 safe_string_free(safe_string * ss)
135 safe_string_val(safe_string * ss)
137 ss->val[ss->pos] = '\0';
143 safe_strdup(safe_string * ss)
145 char *ret = LDAP_MALLOC(ss->pos+1);
148 AC_MEMCPY(ret, ss->val, ss->pos);
154 append_to_safe_string(safe_string * ss, char * s)
160 * Some runaway process is trying to append to a string that
161 * overflowed and we could not extend.
166 /* We always make sure there is at least one position available */
167 if ( ss->pos + l >= ss->size-1 ) {
169 if ( ss->pos + l >= ss->size-1 ) {
170 ss->size = ss->pos + l + 1;
173 temp = LDAP_REALLOC(ss->val, ss->size);
175 /* Trouble, out of memory */
181 strncpy(&ss->val[ss->pos], s, l);
183 if ( ss->pos > 0 && LDAP_SPACE(ss->val[ss->pos-1]) )
192 print_literal(safe_string *ss, char *s)
194 return(append_to_safe_string(ss,s));
198 print_whsp(safe_string *ss)
201 return(append_to_safe_string(ss,""));
203 return(append_to_safe_string(ss," "));
207 print_numericoid(safe_string *ss, char *s)
210 return(append_to_safe_string(ss,s));
212 return(append_to_safe_string(ss,""));
215 /* This one is identical to print_qdescr */
217 print_qdstring(safe_string *ss, char *s)
220 print_literal(ss,"'");
221 append_to_safe_string(ss,s);
222 print_literal(ss,"'");
223 return(print_whsp(ss));
227 print_qdescr(safe_string *ss, char *s)
230 print_literal(ss,"'");
231 append_to_safe_string(ss,s);
232 print_literal(ss,"'");
233 return(print_whsp(ss));
237 print_qdescrlist(safe_string *ss, char **sa)
242 for (sp=sa; *sp; sp++) {
243 ret = print_qdescr(ss,*sp);
245 /* If the list was empty, we return zero that is potentially
246 * incorrect, but since we will be still appending things, the
247 * overflow will be detected later. Maybe FIX.
253 print_qdescrs(safe_string *ss, char **sa)
255 /* The only way to represent an empty list is as a qdescrlist
256 * so, if the list is empty we treat it as a long list.
257 * Really, this is what the syntax mandates. We should not
258 * be here if the list was empty, but if it happens, a label
259 * has already been output and we cannot undo it.
261 if ( !sa[0] || ( sa[0] && sa[1] ) ) {
263 print_literal(ss,"("/*)*/);
264 print_qdescrlist(ss,sa);
265 print_literal(ss,/*(*/")");
266 return(print_whsp(ss));
268 return(print_qdescr(ss,*sa));
273 print_woid(safe_string *ss, char *s)
276 append_to_safe_string(ss,s);
277 return print_whsp(ss);
281 print_oidlist(safe_string *ss, char **sa)
285 for (sp=sa; *(sp+1); sp++) {
287 print_literal(ss,"$");
289 return(print_woid(ss,*sp));
293 print_oids(safe_string *ss, char **sa)
295 if ( sa[0] && sa[1] ) {
296 print_literal(ss,"("/*)*/);
297 print_oidlist(ss,sa);
299 return(print_literal(ss,/*(*/")"));
301 return(print_woid(ss,*sa));
306 print_noidlen(safe_string *ss, char *s, int l)
311 ret = print_numericoid(ss,s);
313 snprintf(buf, sizeof buf, "{%d}",l);
314 ret = print_literal(ss,buf);
320 print_ruleid(safe_string *ss, int rid)
323 snprintf(buf, sizeof buf, "%d", rid);
324 return print_literal(ss,buf);
328 print_ruleids(safe_string *ss, int n, int *rids)
333 print_ruleid(ss,rids[0]);
334 return print_whsp(ss);
336 print_literal(ss,"("/*)*/);
337 for( i=0; i<n; i++ ) {
339 print_ruleid(ss,rids[i]);
342 return print_literal(ss,/*(*/")");
348 print_extensions(safe_string *ss, LDAPSchemaExtensionItem **extensions)
350 LDAPSchemaExtensionItem **ext;
354 for ( ext = extensions; *ext != NULL; ext++ ) {
355 print_literal(ss, (*ext)->lsei_name);
357 /* Should be print_qdstrings */
358 print_qdescrs(ss, (*ext)->lsei_values);
367 ldap_syntax2str( LDAPSyntax * syn )
370 if (ldap_syntax2bv( syn, &bv ))
377 ldap_syntax2bv( LDAPSyntax * syn, struct berval *bv )
381 ss = new_safe_string(256);
385 print_literal(ss,"("/*)*/);
388 print_numericoid(ss, syn->syn_oid);
391 if ( syn->syn_desc ) {
392 print_literal(ss,"DESC");
393 print_qdstring(ss,syn->syn_desc);
398 print_extensions(ss, syn->syn_extensions);
400 print_literal(ss,/*(*/ ")");
402 bv->bv_val = safe_strdup(ss);
403 bv->bv_len = ss->pos;
404 safe_string_free(ss);
409 ldap_matchingrule2str( LDAPMatchingRule * mr )
412 if (ldap_matchingrule2bv( mr, &bv ))
419 ldap_matchingrule2bv( LDAPMatchingRule * mr, struct berval *bv )
423 ss = new_safe_string(256);
427 print_literal(ss,"(" /*)*/);
430 print_numericoid(ss, mr->mr_oid);
433 if ( mr->mr_names ) {
434 print_literal(ss,"NAME");
435 print_qdescrs(ss,mr->mr_names);
439 print_literal(ss,"DESC");
440 print_qdstring(ss,mr->mr_desc);
443 if ( mr->mr_obsolete ) {
444 print_literal(ss, "OBSOLETE");
448 if ( mr->mr_syntax_oid ) {
449 print_literal(ss,"SYNTAX");
451 print_literal(ss, mr->mr_syntax_oid);
457 print_extensions(ss, mr->mr_extensions);
459 print_literal(ss,/*(*/")");
461 bv->bv_val = safe_strdup(ss);
462 bv->bv_len = ss->pos;
463 safe_string_free(ss);
468 ldap_matchingruleuse2str( LDAPMatchingRuleUse * mru )
471 if (ldap_matchingruleuse2bv( mru, &bv ))
478 ldap_matchingruleuse2bv( LDAPMatchingRuleUse * mru, struct berval *bv )
482 ss = new_safe_string(256);
486 print_literal(ss,"(" /*)*/);
489 print_numericoid(ss, mru->mru_oid);
492 if ( mru->mru_names ) {
493 print_literal(ss,"NAME");
494 print_qdescrs(ss,mru->mru_names);
497 if ( mru->mru_desc ) {
498 print_literal(ss,"DESC");
499 print_qdstring(ss,mru->mru_desc);
502 if ( mru->mru_obsolete ) {
503 print_literal(ss, "OBSOLETE");
507 if ( mru->mru_applies_oids ) {
508 print_literal(ss,"APPLIES");
510 print_oids(ss, mru->mru_applies_oids);
516 print_extensions(ss, mru->mru_extensions);
518 print_literal(ss,/*(*/")");
520 bv->bv_val = safe_strdup(ss);
521 bv->bv_len = ss->pos;
522 safe_string_free(ss);
527 ldap_objectclass2str( LDAPObjectClass * oc )
530 if (ldap_objectclass2bv( oc, &bv ))
537 ldap_objectclass2bv( LDAPObjectClass * oc, struct berval *bv )
541 ss = new_safe_string(256);
545 print_literal(ss,"("/*)*/);
548 print_numericoid(ss, oc->oc_oid);
551 if ( oc->oc_names ) {
552 print_literal(ss,"NAME");
553 print_qdescrs(ss,oc->oc_names);
557 print_literal(ss,"DESC");
558 print_qdstring(ss,oc->oc_desc);
561 if ( oc->oc_obsolete ) {
562 print_literal(ss, "OBSOLETE");
566 if ( oc->oc_sup_oids ) {
567 print_literal(ss,"SUP");
569 print_oids(ss,oc->oc_sup_oids);
573 switch (oc->oc_kind) {
574 case LDAP_SCHEMA_ABSTRACT:
575 print_literal(ss,"ABSTRACT");
577 case LDAP_SCHEMA_STRUCTURAL:
578 print_literal(ss,"STRUCTURAL");
580 case LDAP_SCHEMA_AUXILIARY:
581 print_literal(ss,"AUXILIARY");
584 print_literal(ss,"KIND-UNKNOWN");
589 if ( oc->oc_at_oids_must ) {
590 print_literal(ss,"MUST");
592 print_oids(ss,oc->oc_at_oids_must);
596 if ( oc->oc_at_oids_may ) {
597 print_literal(ss,"MAY");
599 print_oids(ss,oc->oc_at_oids_may);
605 print_extensions(ss, oc->oc_extensions);
607 print_literal(ss, /*(*/")");
609 bv->bv_val = safe_strdup(ss);
610 bv->bv_len = ss->pos;
611 safe_string_free(ss);
616 ldap_contentrule2str( LDAPContentRule * cr )
619 if (ldap_contentrule2bv( cr, &bv ))
626 ldap_contentrule2bv( LDAPContentRule * cr, struct berval *bv )
630 ss = new_safe_string(256);
634 print_literal(ss,"("/*)*/);
637 print_numericoid(ss, cr->cr_oid);
640 if ( cr->cr_names ) {
641 print_literal(ss,"NAME");
642 print_qdescrs(ss,cr->cr_names);
646 print_literal(ss,"DESC");
647 print_qdstring(ss,cr->cr_desc);
650 if ( cr->cr_obsolete ) {
651 print_literal(ss, "OBSOLETE");
655 if ( cr->cr_oc_oids_aux ) {
656 print_literal(ss,"AUX");
658 print_oids(ss,cr->cr_oc_oids_aux);
662 if ( cr->cr_at_oids_must ) {
663 print_literal(ss,"MUST");
665 print_oids(ss,cr->cr_at_oids_must);
669 if ( cr->cr_at_oids_may ) {
670 print_literal(ss,"MAY");
672 print_oids(ss,cr->cr_at_oids_may);
676 if ( cr->cr_at_oids_not ) {
677 print_literal(ss,"NOT");
679 print_oids(ss,cr->cr_at_oids_not);
684 print_extensions(ss, cr->cr_extensions);
686 print_literal(ss, /*(*/")");
688 bv->bv_val = safe_strdup(ss);
689 bv->bv_len = ss->pos;
690 safe_string_free(ss);
695 ldap_structurerule2str( LDAPStructureRule * sr )
698 if (ldap_structurerule2bv( sr, &bv ))
705 ldap_structurerule2bv( LDAPStructureRule * sr, struct berval *bv )
709 ss = new_safe_string(256);
713 print_literal(ss,"("/*)*/);
716 print_ruleid(ss, sr->sr_ruleid);
719 if ( sr->sr_names ) {
720 print_literal(ss,"NAME");
721 print_qdescrs(ss,sr->sr_names);
725 print_literal(ss,"DESC");
726 print_qdstring(ss,sr->sr_desc);
729 if ( sr->sr_obsolete ) {
730 print_literal(ss, "OBSOLETE");
734 print_literal(ss,"FORM");
736 print_woid(ss,sr->sr_nameform);
739 if ( sr->sr_nsup_ruleids ) {
740 print_literal(ss,"SUP");
742 print_ruleids(ss,sr->sr_nsup_ruleids,sr->sr_sup_ruleids);
747 print_extensions(ss, sr->sr_extensions);
749 print_literal(ss, /*(*/")");
751 bv->bv_val = safe_strdup(ss);
752 bv->bv_len = ss->pos;
753 safe_string_free(ss);
759 ldap_nameform2str( LDAPNameForm * nf )
762 if (ldap_nameform2bv( nf, &bv ))
769 ldap_nameform2bv( LDAPNameForm * nf, struct berval *bv )
773 ss = new_safe_string(256);
777 print_literal(ss,"("/*)*/);
780 print_numericoid(ss, nf->nf_oid);
783 if ( nf->nf_names ) {
784 print_literal(ss,"NAME");
785 print_qdescrs(ss,nf->nf_names);
789 print_literal(ss,"DESC");
790 print_qdstring(ss,nf->nf_desc);
793 if ( nf->nf_obsolete ) {
794 print_literal(ss, "OBSOLETE");
798 print_literal(ss,"OC");
800 print_woid(ss,nf->nf_objectclass);
803 print_literal(ss,"MUST");
805 print_oids(ss,nf->nf_at_oids_must);
809 if ( nf->nf_at_oids_may ) {
810 print_literal(ss,"MAY");
812 print_oids(ss,nf->nf_at_oids_may);
817 print_extensions(ss, nf->nf_extensions);
819 print_literal(ss, /*(*/")");
821 bv->bv_val = safe_strdup(ss);
822 bv->bv_len = ss->pos;
823 safe_string_free(ss);
828 ldap_attributetype2str( LDAPAttributeType * at )
831 if (ldap_attributetype2bv( at, &bv ))
838 ldap_attributetype2bv( LDAPAttributeType * at, struct berval *bv )
842 ss = new_safe_string(256);
846 print_literal(ss,"("/*)*/);
849 print_numericoid(ss, at->at_oid);
852 if ( at->at_names ) {
853 print_literal(ss,"NAME");
854 print_qdescrs(ss,at->at_names);
858 print_literal(ss,"DESC");
859 print_qdstring(ss,at->at_desc);
862 if ( at->at_obsolete ) {
863 print_literal(ss, "OBSOLETE");
867 if ( at->at_sup_oid ) {
868 print_literal(ss,"SUP");
869 print_woid(ss,at->at_sup_oid);
872 if ( at->at_equality_oid ) {
873 print_literal(ss,"EQUALITY");
874 print_woid(ss,at->at_equality_oid);
877 if ( at->at_ordering_oid ) {
878 print_literal(ss,"ORDERING");
879 print_woid(ss,at->at_ordering_oid);
882 if ( at->at_substr_oid ) {
883 print_literal(ss,"SUBSTR");
884 print_woid(ss,at->at_substr_oid);
887 if ( at->at_syntax_oid ) {
888 print_literal(ss,"SYNTAX");
890 print_noidlen(ss,at->at_syntax_oid,at->at_syntax_len);
894 if ( at->at_single_value == LDAP_SCHEMA_YES ) {
895 print_literal(ss,"SINGLE-VALUE");
899 if ( at->at_collective == LDAP_SCHEMA_YES ) {
900 print_literal(ss,"COLLECTIVE");
904 if ( at->at_no_user_mod == LDAP_SCHEMA_YES ) {
905 print_literal(ss,"NO-USER-MODIFICATION");
909 if ( at->at_usage != LDAP_SCHEMA_USER_APPLICATIONS ) {
910 print_literal(ss,"USAGE");
912 switch (at->at_usage) {
913 case LDAP_SCHEMA_DIRECTORY_OPERATION:
914 print_literal(ss,"directoryOperation");
916 case LDAP_SCHEMA_DISTRIBUTED_OPERATION:
917 print_literal(ss,"distributedOperation");
919 case LDAP_SCHEMA_DSA_OPERATION:
920 print_literal(ss,"dSAOperation");
923 print_literal(ss,"UNKNOWN");
930 print_extensions(ss, at->at_extensions);
932 print_literal(ss,/*(*/")");
934 bv->bv_val = safe_strdup(ss);
935 bv->bv_len = ss->pos;
936 safe_string_free(ss);
941 * Now come the parsers. There is one parser for each entity type:
942 * objectclasses, attributetypes, etc.
944 * Each of them is written as a recursive-descent parser, except that
945 * none of them is really recursive. But the idea is kept: there
946 * is one routine per non-terminal that eithers gobbles lexical tokens
947 * or calls lower-level routines, etc.
949 * The scanner is implemented in the routine get_token. Actually,
950 * get_token is more than a scanner and will return tokens that are
951 * in fact non-terminals in the grammar. So you can see the whole
952 * approach as the combination of a low-level bottom-up recognizer
953 * combined with a scanner and a number of top-down parsers. Or just
954 * consider that the real grammars recognized by the parsers are not
955 * those of the standards. As a matter of fact, our parsers are more
956 * liberal than the spec when there is no ambiguity.
958 * The difference is pretty academic (modulo bugs or incorrect
959 * interpretation of the specs).
962 #define TK_NOENDQUOTE -2
963 #define TK_OUTOFMEM -1
965 #define TK_UNEXPCHAR 1
966 #define TK_BAREWORD 2
967 #define TK_QDSTRING 3
968 #define TK_LEFTPAREN 4
969 #define TK_RIGHTPAREN 5
971 #define TK_QDESCR TK_QDSTRING
979 get_token( const char ** sp, char ** token_val )
997 kind = TK_RIGHTPAREN;
1008 while ( **sp != '\'' && **sp != '\0' )
1010 if ( **sp == '\'' ) {
1012 res = LDAP_MALLOC(q-p+1);
1022 kind = TK_NOENDQUOTE;
1028 while ( !LDAP_SPACE(**sp) &&
1036 res = LDAP_MALLOC(q-p+1);
1045 /* kind = TK_UNEXPCHAR; */
1052 /* Gobble optional whitespace */
1054 parse_whsp(const char **sp)
1056 while (LDAP_SPACE(**sp))
1061 * General note for all parsers: to guarantee the algorithm halts they
1062 * must always advance the pointer even when an error is found. For
1063 * this one is not that important since an error here is fatal at the
1064 * upper layers, but it is a simple strategy that will not get in
1068 /* Parse a sequence of dot-separated decimal strings */
1070 ldap_int_parse_numericoid(const char **sp, int *code, const int flags)
1073 const char * start = *sp;
1077 /* Netscape puts the SYNTAX value in quotes (incorrectly) */
1078 if ( flags & LDAP_SCHEMA_ALLOW_QUOTED && **sp == '\'' ) {
1083 /* Each iteration of this loop gets one decimal string */
1085 if ( !LDAP_DIGIT(**sp) ) {
1087 * Initial char is not a digit or char after dot is
1090 *code = LDAP_SCHERR_NODIGIT;
1094 while ( LDAP_DIGIT(**sp) )
1098 /* Otherwise, gobble the dot and loop again */
1101 /* Now *sp points at the char past the numericoid. Perfect. */
1103 if ( flags & LDAP_SCHEMA_ALLOW_QUOTED && quoted ) {
1104 if ( **sp == '\'' ) {
1107 *code = LDAP_SCHERR_UNEXPTOKEN;
1111 if (flags & LDAP_SCHEMA_SKIP) {
1112 res = (char *)start;
1114 res = LDAP_MALLOC(len+1);
1116 *code = LDAP_SCHERR_OUTOFMEM;
1119 strncpy(res,start,len);
1125 /* Parse a sequence of dot-separated decimal strings */
1127 ldap_int_parse_ruleid(const char **sp, int *code, const int flags, int *ruleid)
1131 if ( !LDAP_DIGIT(**sp) ) {
1132 *code = LDAP_SCHERR_NODIGIT;
1135 *ruleid = (**sp) - '0';
1138 while ( LDAP_DIGIT(**sp) ) {
1140 *ruleid += (**sp) - '0';
1147 /* Parse a qdescr or a list of them enclosed in () */
1149 parse_qdescrs(const char **sp, int *code)
1159 kind = get_token(sp,&sval);
1160 if ( kind == TK_LEFTPAREN ) {
1161 /* Let's presume there will be at least 2 entries */
1163 res = LDAP_CALLOC(3,sizeof(char *));
1165 *code = LDAP_SCHERR_OUTOFMEM;
1171 kind = get_token(sp,&sval);
1172 if ( kind == TK_RIGHTPAREN )
1174 if ( kind == TK_QDESCR ) {
1175 if ( pos == size-2 ) {
1177 res1 = LDAP_REALLOC(res,size*sizeof(char *));
1181 *code = LDAP_SCHERR_OUTOFMEM;
1192 *code = LDAP_SCHERR_UNEXPTOKEN;
1198 } else if ( kind == TK_QDESCR ) {
1199 res = LDAP_CALLOC(2,sizeof(char *));
1201 *code = LDAP_SCHERR_OUTOFMEM;
1210 *code = LDAP_SCHERR_BADNAME;
1217 parse_woid(const char **sp, int *code)
1223 kind = get_token(sp, &sval);
1224 if ( kind != TK_BAREWORD ) {
1226 *code = LDAP_SCHERR_UNEXPTOKEN;
1233 /* Parse a noidlen */
1235 parse_noidlen(const char **sp, int *code, int *len, int allow_quoted)
1241 /* Netscape puts the SYNTAX value in quotes (incorrectly) */
1242 if ( allow_quoted && **sp == '\'' ) {
1246 sval = ldap_int_parse_numericoid(sp, code, 0);
1250 if ( **sp == '{' /*}*/ ) {
1253 while ( LDAP_DIGIT(**sp) )
1255 if ( **sp != /*{*/ '}' ) {
1256 *code = LDAP_SCHERR_UNEXPTOKEN;
1262 if ( allow_quoted && quoted ) {
1263 if ( **sp == '\'' ) {
1266 *code = LDAP_SCHERR_UNEXPTOKEN;
1275 * Next routine will accept a qdstring in place of an oid if
1276 * allow_quoted is set. This is necessary to interoperate with
1277 * Netscape Directory server that will improperly quote each oid (at
1278 * least those of the descr kind) in the SUP clause.
1281 /* Parse a woid or a $-separated list of them enclosed in () */
1283 parse_oids(const char **sp, int *code, const int allow_quoted)
1293 * Strictly speaking, doing this here accepts whsp before the
1294 * ( at the begining of an oidlist, but this is harmless. Also,
1295 * we are very liberal in what we accept as an OID. Maybe
1299 kind = get_token(sp,&sval);
1300 if ( kind == TK_LEFTPAREN ) {
1301 /* Let's presume there will be at least 2 entries */
1303 res = LDAP_CALLOC(3,sizeof(char *));
1305 *code = LDAP_SCHERR_OUTOFMEM;
1310 kind = get_token(sp,&sval);
1311 if ( kind == TK_BAREWORD ||
1312 ( allow_quoted && kind == TK_QDSTRING ) ) {
1316 *code = LDAP_SCHERR_UNEXPTOKEN;
1323 kind = get_token(sp,&sval);
1324 if ( kind == TK_RIGHTPAREN )
1326 if ( kind == TK_DOLLAR ) {
1328 kind = get_token(sp,&sval);
1329 if ( kind == TK_BAREWORD ||
1331 kind == TK_QDSTRING ) ) {
1332 if ( pos == size-2 ) {
1334 res1 = LDAP_REALLOC(res,size*sizeof(char *));
1338 *code = LDAP_SCHERR_OUTOFMEM;
1346 *code = LDAP_SCHERR_UNEXPTOKEN;
1353 *code = LDAP_SCHERR_UNEXPTOKEN;
1361 } else if ( kind == TK_BAREWORD ||
1362 ( allow_quoted && kind == TK_QDSTRING ) ) {
1363 res = LDAP_CALLOC(2,sizeof(char *));
1366 *code = LDAP_SCHERR_OUTOFMEM;
1375 *code = LDAP_SCHERR_BADNAME;
1381 add_extension(LDAPSchemaExtensionItem ***extensions,
1382 char * name, char ** values)
1385 LDAPSchemaExtensionItem **tmp, *ext;
1387 ext = LDAP_CALLOC(1, sizeof(LDAPSchemaExtensionItem));
1390 ext->lsei_name = name;
1391 ext->lsei_values = values;
1393 if ( !*extensions ) {
1395 LDAP_CALLOC(2, sizeof(LDAPSchemaExtensionItem *));
1400 for ( n=0; (*extensions)[n] != NULL; n++ )
1402 tmp = LDAP_REALLOC(*extensions,
1403 (n+2)*sizeof(LDAPSchemaExtensionItem *));
1408 (*extensions)[n] = ext;
1409 (*extensions)[n+1] = NULL;
1414 free_extensions(LDAPSchemaExtensionItem **extensions)
1416 LDAPSchemaExtensionItem **ext;
1419 for ( ext = extensions; *ext != NULL; ext++ ) {
1420 LDAP_FREE((*ext)->lsei_name);
1421 LDAP_VFREE((*ext)->lsei_values);
1424 LDAP_FREE(extensions);
1429 ldap_syntax_free( LDAPSyntax * syn )
1431 LDAP_FREE(syn->syn_oid);
1432 if (syn->syn_names) LDAP_VFREE(syn->syn_names);
1433 if (syn->syn_desc) LDAP_FREE(syn->syn_desc);
1434 free_extensions(syn->syn_extensions);
1439 ldap_str2syntax( LDAP_CONST char * s,
1441 LDAP_CONST char ** errp,
1442 LDAP_CONST unsigned flags )
1445 const char * ss = s;
1453 *code = LDAP_SCHERR_EMPTY;
1459 syn = LDAP_CALLOC(1,sizeof(LDAPSyntax));
1462 *code = LDAP_SCHERR_OUTOFMEM;
1466 kind = get_token(&ss,&sval);
1467 if ( kind != TK_LEFTPAREN ) {
1469 *code = LDAP_SCHERR_NOLEFTPAREN;
1470 ldap_syntax_free(syn);
1475 syn->syn_oid = ldap_int_parse_numericoid(&ss,code,0);
1476 if ( !syn->syn_oid ) {
1478 ldap_syntax_free(syn);
1484 * Beyond this point we will be liberal and accept the items
1488 kind = get_token(&ss,&sval);
1491 *code = LDAP_SCHERR_NORIGHTPAREN;
1493 ldap_syntax_free(syn);
1498 if ( !strcasecmp(sval,"NAME") ) {
1501 *code = LDAP_SCHERR_DUPOPT;
1503 ldap_syntax_free(syn);
1507 syn->syn_names = parse_qdescrs(&ss,code);
1508 if ( !syn->syn_names ) {
1509 if ( *code != LDAP_SCHERR_OUTOFMEM )
1510 *code = LDAP_SCHERR_BADNAME;
1512 ldap_syntax_free(syn);
1515 } else if ( !strcasecmp(sval,"DESC") ) {
1518 *code = LDAP_SCHERR_DUPOPT;
1520 ldap_syntax_free(syn);
1525 kind = get_token(&ss,&sval);
1526 if ( kind != TK_QDSTRING ) {
1527 *code = LDAP_SCHERR_UNEXPTOKEN;
1530 ldap_syntax_free(syn);
1533 syn->syn_desc = sval;
1535 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1536 /* Should be parse_qdstrings */
1537 ext_vals = parse_qdescrs(&ss, code);
1540 ldap_syntax_free(syn);
1543 if ( add_extension(&syn->syn_extensions,
1545 *code = LDAP_SCHERR_OUTOFMEM;
1548 ldap_syntax_free(syn);
1552 *code = LDAP_SCHERR_UNEXPTOKEN;
1555 ldap_syntax_free(syn);
1560 *code = LDAP_SCHERR_UNEXPTOKEN;
1563 ldap_syntax_free(syn);
1570 ldap_matchingrule_free( LDAPMatchingRule * mr )
1572 LDAP_FREE(mr->mr_oid);
1573 if (mr->mr_names) LDAP_VFREE(mr->mr_names);
1574 if (mr->mr_desc) LDAP_FREE(mr->mr_desc);
1575 if (mr->mr_syntax_oid) LDAP_FREE(mr->mr_syntax_oid);
1576 free_extensions(mr->mr_extensions);
1581 ldap_str2matchingrule( LDAP_CONST char * s,
1583 LDAP_CONST char ** errp,
1584 LDAP_CONST unsigned flags )
1587 const char * ss = s;
1591 int seen_obsolete = 0;
1592 int seen_syntax = 0;
1593 LDAPMatchingRule * mr;
1595 const char * savepos;
1598 *code = LDAP_SCHERR_EMPTY;
1604 mr = LDAP_CALLOC(1,sizeof(LDAPMatchingRule));
1607 *code = LDAP_SCHERR_OUTOFMEM;
1611 kind = get_token(&ss,&sval);
1612 if ( kind != TK_LEFTPAREN ) {
1613 *code = LDAP_SCHERR_NOLEFTPAREN;
1615 ldap_matchingrule_free(mr);
1621 mr->mr_oid = ldap_int_parse_numericoid(&ss,code,flags);
1622 if ( !mr->mr_oid ) {
1623 if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
1626 kind = get_token(&ss,&sval);
1627 if ( kind == TK_BAREWORD ) {
1628 if ( !strcasecmp(sval, "NAME") ||
1629 !strcasecmp(sval, "DESC") ||
1630 !strcasecmp(sval, "OBSOLETE") ||
1631 !strcasecmp(sval, "SYNTAX") ||
1632 !strncasecmp(sval, "X-", 2) ) {
1633 /* Missing OID, backtrack */
1636 /* Non-numerical OID, ignore */
1642 ldap_matchingrule_free(mr);
1649 * Beyond this point we will be liberal and accept the items
1653 kind = get_token(&ss,&sval);
1656 *code = LDAP_SCHERR_NORIGHTPAREN;
1658 ldap_matchingrule_free(mr);
1661 if( !seen_syntax ) {
1662 *code = LDAP_SCHERR_MISSING;
1663 ldap_matchingrule_free(mr);
1668 if ( !strcasecmp(sval,"NAME") ) {
1671 *code = LDAP_SCHERR_DUPOPT;
1673 ldap_matchingrule_free(mr);
1677 mr->mr_names = parse_qdescrs(&ss,code);
1678 if ( !mr->mr_names ) {
1679 if ( *code != LDAP_SCHERR_OUTOFMEM )
1680 *code = LDAP_SCHERR_BADNAME;
1682 ldap_matchingrule_free(mr);
1685 } else if ( !strcasecmp(sval,"DESC") ) {
1688 *code = LDAP_SCHERR_DUPOPT;
1690 ldap_matchingrule_free(mr);
1695 kind = get_token(&ss,&sval);
1696 if ( kind != TK_QDSTRING ) {
1697 *code = LDAP_SCHERR_UNEXPTOKEN;
1700 ldap_matchingrule_free(mr);
1705 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
1707 if ( seen_obsolete ) {
1708 *code = LDAP_SCHERR_DUPOPT;
1710 ldap_matchingrule_free(mr);
1714 mr->mr_obsolete = LDAP_SCHEMA_YES;
1716 } else if ( !strcasecmp(sval,"SYNTAX") ) {
1718 if ( seen_syntax ) {
1719 *code = LDAP_SCHERR_DUPOPT;
1721 ldap_matchingrule_free(mr);
1727 ldap_int_parse_numericoid(&ss,code,flags);
1728 if ( !mr->mr_syntax_oid ) {
1730 ldap_matchingrule_free(mr);
1734 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1735 /* Should be parse_qdstrings */
1736 ext_vals = parse_qdescrs(&ss, code);
1739 ldap_matchingrule_free(mr);
1742 if ( add_extension(&mr->mr_extensions,
1744 *code = LDAP_SCHERR_OUTOFMEM;
1747 ldap_matchingrule_free(mr);
1751 *code = LDAP_SCHERR_UNEXPTOKEN;
1754 ldap_matchingrule_free(mr);
1759 *code = LDAP_SCHERR_UNEXPTOKEN;
1762 ldap_matchingrule_free(mr);
1769 ldap_matchingruleuse_free( LDAPMatchingRuleUse * mru )
1771 LDAP_FREE(mru->mru_oid);
1772 if (mru->mru_names) LDAP_VFREE(mru->mru_names);
1773 if (mru->mru_desc) LDAP_FREE(mru->mru_desc);
1774 if (mru->mru_applies_oids) LDAP_VFREE(mru->mru_applies_oids);
1775 free_extensions(mru->mru_extensions);
1779 LDAPMatchingRuleUse *
1780 ldap_str2matchingruleuse( LDAP_CONST char * s,
1782 LDAP_CONST char ** errp,
1783 LDAP_CONST unsigned flags )
1786 const char * ss = s;
1790 int seen_obsolete = 0;
1791 int seen_applies = 0;
1792 LDAPMatchingRuleUse * mru;
1794 const char * savepos;
1797 *code = LDAP_SCHERR_EMPTY;
1803 mru = LDAP_CALLOC(1,sizeof(LDAPMatchingRuleUse));
1806 *code = LDAP_SCHERR_OUTOFMEM;
1810 kind = get_token(&ss,&sval);
1811 if ( kind != TK_LEFTPAREN ) {
1812 *code = LDAP_SCHERR_NOLEFTPAREN;
1814 ldap_matchingruleuse_free(mru);
1820 mru->mru_oid = ldap_int_parse_numericoid(&ss,code,flags);
1821 if ( !mru->mru_oid ) {
1822 if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
1825 kind = get_token(&ss,&sval);
1826 if ( kind == TK_BAREWORD ) {
1827 if ( !strcasecmp(sval, "NAME") ||
1828 !strcasecmp(sval, "DESC") ||
1829 !strcasecmp(sval, "OBSOLETE") ||
1830 !strcasecmp(sval, "APPLIES") ||
1831 !strncasecmp(sval, "X-", 2) ) {
1832 /* Missing OID, backtrack */
1835 /* Non-numerical OID, ignore */
1841 ldap_matchingruleuse_free(mru);
1848 * Beyond this point we will be liberal and accept the items
1852 kind = get_token(&ss,&sval);
1855 *code = LDAP_SCHERR_NORIGHTPAREN;
1857 ldap_matchingruleuse_free(mru);
1860 if( !seen_applies ) {
1861 *code = LDAP_SCHERR_MISSING;
1862 ldap_matchingruleuse_free(mru);
1867 if ( !strcasecmp(sval,"NAME") ) {
1870 *code = LDAP_SCHERR_DUPOPT;
1872 ldap_matchingruleuse_free(mru);
1876 mru->mru_names = parse_qdescrs(&ss,code);
1877 if ( !mru->mru_names ) {
1878 if ( *code != LDAP_SCHERR_OUTOFMEM )
1879 *code = LDAP_SCHERR_BADNAME;
1881 ldap_matchingruleuse_free(mru);
1884 } else if ( !strcasecmp(sval,"DESC") ) {
1887 *code = LDAP_SCHERR_DUPOPT;
1889 ldap_matchingruleuse_free(mru);
1894 kind = get_token(&ss,&sval);
1895 if ( kind != TK_QDSTRING ) {
1896 *code = LDAP_SCHERR_UNEXPTOKEN;
1899 ldap_matchingruleuse_free(mru);
1902 mru->mru_desc = sval;
1904 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
1906 if ( seen_obsolete ) {
1907 *code = LDAP_SCHERR_DUPOPT;
1909 ldap_matchingruleuse_free(mru);
1913 mru->mru_obsolete = LDAP_SCHEMA_YES;
1915 } else if ( !strcasecmp(sval,"APPLIES") ) {
1917 if ( seen_applies ) {
1918 *code = LDAP_SCHERR_DUPOPT;
1920 ldap_matchingruleuse_free(mru);
1924 mru->mru_applies_oids = parse_oids(&ss,
1927 if ( !mru->mru_applies_oids ) {
1929 ldap_matchingruleuse_free(mru);
1932 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1933 /* Should be parse_qdstrings */
1934 ext_vals = parse_qdescrs(&ss, code);
1937 ldap_matchingruleuse_free(mru);
1940 if ( add_extension(&mru->mru_extensions,
1942 *code = LDAP_SCHERR_OUTOFMEM;
1945 ldap_matchingruleuse_free(mru);
1949 *code = LDAP_SCHERR_UNEXPTOKEN;
1952 ldap_matchingruleuse_free(mru);
1957 *code = LDAP_SCHERR_UNEXPTOKEN;
1960 ldap_matchingruleuse_free(mru);
1967 ldap_attributetype_free(LDAPAttributeType * at)
1969 LDAP_FREE(at->at_oid);
1970 if (at->at_names) LDAP_VFREE(at->at_names);
1971 if (at->at_desc) LDAP_FREE(at->at_desc);
1972 if (at->at_sup_oid) LDAP_FREE(at->at_sup_oid);
1973 if (at->at_equality_oid) LDAP_FREE(at->at_equality_oid);
1974 if (at->at_ordering_oid) LDAP_FREE(at->at_ordering_oid);
1975 if (at->at_substr_oid) LDAP_FREE(at->at_substr_oid);
1976 if (at->at_syntax_oid) LDAP_FREE(at->at_syntax_oid);
1977 free_extensions(at->at_extensions);
1982 ldap_str2attributetype( LDAP_CONST char * s,
1984 LDAP_CONST char ** errp,
1985 LDAP_CONST unsigned flags )
1988 const char * ss = s;
1992 int seen_obsolete = 0;
1994 int seen_equality = 0;
1995 int seen_ordering = 0;
1996 int seen_substr = 0;
1997 int seen_syntax = 0;
1999 LDAPAttributeType * at;
2001 const char * savepos;
2004 *code = LDAP_SCHERR_EMPTY;
2010 at = LDAP_CALLOC(1,sizeof(LDAPAttributeType));
2013 *code = LDAP_SCHERR_OUTOFMEM;
2017 kind = get_token(&ss,&sval);
2018 if ( kind != TK_LEFTPAREN ) {
2019 *code = LDAP_SCHERR_NOLEFTPAREN;
2021 ldap_attributetype_free(at);
2026 * Definitions MUST begin with an OID in the numericoid format.
2027 * However, this routine is used by clients to parse the response
2028 * from servers and very well known servers will provide an OID
2029 * in the wrong format or even no OID at all. We do our best to
2030 * extract info from those servers.
2034 at->at_oid = ldap_int_parse_numericoid(&ss,code,0);
2035 if ( !at->at_oid ) {
2036 if ( ( flags & ( LDAP_SCHEMA_ALLOW_NO_OID
2037 | LDAP_SCHEMA_ALLOW_OID_MACRO ) )
2038 && (ss == savepos) ) {
2041 kind = get_token(&ss,&sval);
2042 if ( kind == TK_BAREWORD ) {
2043 if ( !strcasecmp(sval, "NAME") ||
2044 !strcasecmp(sval, "DESC") ||
2045 !strcasecmp(sval, "OBSOLETE") ||
2046 !strcasecmp(sval, "SUP") ||
2047 !strcasecmp(sval, "EQUALITY") ||
2048 !strcasecmp(sval, "ORDERING") ||
2049 !strcasecmp(sval, "SUBSTR") ||
2050 !strcasecmp(sval, "SYNTAX") ||
2051 !strcasecmp(sval, "SINGLE-VALUE") ||
2052 !strcasecmp(sval, "COLLECTIVE") ||
2053 !strcasecmp(sval, "NO-USER-MODIFICATION") ||
2054 !strcasecmp(sval, "USAGE") ||
2055 !strncasecmp(sval, "X-", 2) ) {
2056 /* Missing OID, backtrack */
2059 & LDAP_SCHEMA_ALLOW_OID_MACRO) {
2060 /* Non-numerical OID ... */
2061 int len = ss-savepos;
2062 at->at_oid = LDAP_MALLOC(len+1);
2063 strncpy(at->at_oid, savepos, len);
2064 at->at_oid[len] = 0;
2070 ldap_attributetype_free(at);
2077 * Beyond this point we will be liberal and accept the items
2081 kind = get_token(&ss,&sval);
2084 *code = LDAP_SCHERR_NORIGHTPAREN;
2086 ldap_attributetype_free(at);
2091 if ( !strcasecmp(sval,"NAME") ) {
2094 *code = LDAP_SCHERR_DUPOPT;
2096 ldap_attributetype_free(at);
2100 at->at_names = parse_qdescrs(&ss,code);
2101 if ( !at->at_names ) {
2102 if ( *code != LDAP_SCHERR_OUTOFMEM )
2103 *code = LDAP_SCHERR_BADNAME;
2105 ldap_attributetype_free(at);
2108 } else if ( !strcasecmp(sval,"DESC") ) {
2111 *code = LDAP_SCHERR_DUPOPT;
2113 ldap_attributetype_free(at);
2118 kind = get_token(&ss,&sval);
2119 if ( kind != TK_QDSTRING ) {
2120 *code = LDAP_SCHERR_UNEXPTOKEN;
2123 ldap_attributetype_free(at);
2128 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
2130 if ( seen_obsolete ) {
2131 *code = LDAP_SCHERR_DUPOPT;
2133 ldap_attributetype_free(at);
2137 at->at_obsolete = LDAP_SCHEMA_YES;
2139 } else if ( !strcasecmp(sval,"SUP") ) {
2142 *code = LDAP_SCHERR_DUPOPT;
2144 ldap_attributetype_free(at);
2148 at->at_sup_oid = parse_woid(&ss,code);
2149 if ( !at->at_sup_oid ) {
2151 ldap_attributetype_free(at);
2154 } else if ( !strcasecmp(sval,"EQUALITY") ) {
2156 if ( seen_equality ) {
2157 *code = LDAP_SCHERR_DUPOPT;
2159 ldap_attributetype_free(at);
2163 at->at_equality_oid = parse_woid(&ss,code);
2164 if ( !at->at_equality_oid ) {
2166 ldap_attributetype_free(at);
2169 } else if ( !strcasecmp(sval,"ORDERING") ) {
2171 if ( seen_ordering ) {
2172 *code = LDAP_SCHERR_DUPOPT;
2174 ldap_attributetype_free(at);
2178 at->at_ordering_oid = parse_woid(&ss,code);
2179 if ( !at->at_ordering_oid ) {
2181 ldap_attributetype_free(at);
2184 } else if ( !strcasecmp(sval,"SUBSTR") ) {
2186 if ( seen_substr ) {
2187 *code = LDAP_SCHERR_DUPOPT;
2189 ldap_attributetype_free(at);
2193 at->at_substr_oid = parse_woid(&ss,code);
2194 if ( !at->at_substr_oid ) {
2196 ldap_attributetype_free(at);
2199 } else if ( !strcasecmp(sval,"SYNTAX") ) {
2201 if ( seen_syntax ) {
2202 *code = LDAP_SCHERR_DUPOPT;
2204 ldap_attributetype_free(at);
2215 if ( !at->at_syntax_oid ) {
2216 if ( flags & LDAP_SCHEMA_ALLOW_OID_MACRO ) {
2217 kind = get_token(&ss,&sval);
2218 if (kind == TK_BAREWORD)
2220 char *sp = strchr(sval, '{');
2221 at->at_syntax_oid = sval;
2225 at->at_syntax_len = atoi(sp);
2226 while ( LDAP_DIGIT(*sp) )
2229 *code = LDAP_SCHERR_UNEXPTOKEN;
2231 ldap_attributetype_free(at);
2238 ldap_attributetype_free(at);
2243 } else if ( !strcasecmp(sval,"SINGLE-VALUE") ) {
2245 if ( at->at_single_value ) {
2246 *code = LDAP_SCHERR_DUPOPT;
2248 ldap_attributetype_free(at);
2251 at->at_single_value = LDAP_SCHEMA_YES;
2253 } else if ( !strcasecmp(sval,"COLLECTIVE") ) {
2255 if ( at->at_collective ) {
2256 *code = LDAP_SCHERR_DUPOPT;
2258 ldap_attributetype_free(at);
2261 at->at_collective = LDAP_SCHEMA_YES;
2263 } else if ( !strcasecmp(sval,"NO-USER-MODIFICATION") ) {
2265 if ( at->at_no_user_mod ) {
2266 *code = LDAP_SCHERR_DUPOPT;
2268 ldap_attributetype_free(at);
2271 at->at_no_user_mod = LDAP_SCHEMA_YES;
2273 } else if ( !strcasecmp(sval,"USAGE") ) {
2276 *code = LDAP_SCHERR_DUPOPT;
2278 ldap_attributetype_free(at);
2283 kind = get_token(&ss,&sval);
2284 if ( kind != TK_BAREWORD ) {
2285 *code = LDAP_SCHERR_UNEXPTOKEN;
2288 ldap_attributetype_free(at);
2291 if ( !strcasecmp(sval,"userApplications") )
2293 LDAP_SCHEMA_USER_APPLICATIONS;
2294 else if ( !strcasecmp(sval,"directoryOperation") )
2296 LDAP_SCHEMA_DIRECTORY_OPERATION;
2297 else if ( !strcasecmp(sval,"distributedOperation") )
2299 LDAP_SCHEMA_DISTRIBUTED_OPERATION;
2300 else if ( !strcasecmp(sval,"dSAOperation") )
2302 LDAP_SCHEMA_DSA_OPERATION;
2304 *code = LDAP_SCHERR_UNEXPTOKEN;
2307 ldap_attributetype_free(at);
2312 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
2313 /* Should be parse_qdstrings */
2314 ext_vals = parse_qdescrs(&ss, code);
2317 ldap_attributetype_free(at);
2320 if ( add_extension(&at->at_extensions,
2322 *code = LDAP_SCHERR_OUTOFMEM;
2325 ldap_attributetype_free(at);
2329 *code = LDAP_SCHERR_UNEXPTOKEN;
2332 ldap_attributetype_free(at);
2337 *code = LDAP_SCHERR_UNEXPTOKEN;
2340 ldap_attributetype_free(at);
2347 ldap_objectclass_free(LDAPObjectClass * oc)
2349 LDAP_FREE(oc->oc_oid);
2350 if (oc->oc_names) LDAP_VFREE(oc->oc_names);
2351 if (oc->oc_desc) LDAP_FREE(oc->oc_desc);
2352 if (oc->oc_sup_oids) LDAP_VFREE(oc->oc_sup_oids);
2353 if (oc->oc_at_oids_must) LDAP_VFREE(oc->oc_at_oids_must);
2354 if (oc->oc_at_oids_may) LDAP_VFREE(oc->oc_at_oids_may);
2355 free_extensions(oc->oc_extensions);
2360 ldap_str2objectclass( LDAP_CONST char * s,
2362 LDAP_CONST char ** errp,
2363 LDAP_CONST unsigned flags )
2366 const char * ss = s;
2370 int seen_obsolete = 0;
2375 LDAPObjectClass * oc;
2377 const char * savepos;
2380 *code = LDAP_SCHERR_EMPTY;
2386 oc = LDAP_CALLOC(1,sizeof(LDAPObjectClass));
2389 *code = LDAP_SCHERR_OUTOFMEM;
2392 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
2394 kind = get_token(&ss,&sval);
2395 if ( kind != TK_LEFTPAREN ) {
2396 *code = LDAP_SCHERR_NOLEFTPAREN;
2398 ldap_objectclass_free(oc);
2403 * Definitions MUST begin with an OID in the numericoid format.
2404 * However, this routine is used by clients to parse the response
2405 * from servers and very well known servers will provide an OID
2406 * in the wrong format or even no OID at all. We do our best to
2407 * extract info from those servers.
2411 oc->oc_oid = ldap_int_parse_numericoid(&ss,code,0);
2412 if ( !oc->oc_oid ) {
2413 if ( (flags & LDAP_SCHEMA_ALLOW_ALL) && (ss == savepos) ) {
2416 kind = get_token(&ss,&sval);
2417 if ( kind == TK_BAREWORD ) {
2418 if ( !strcasecmp(sval, "NAME") ||
2419 !strcasecmp(sval, "DESC") ||
2420 !strcasecmp(sval, "OBSOLETE") ||
2421 !strcasecmp(sval, "SUP") ||
2422 !strcasecmp(sval, "ABSTRACT") ||
2423 !strcasecmp(sval, "STRUCTURAL") ||
2424 !strcasecmp(sval, "AUXILIARY") ||
2425 !strcasecmp(sval, "MUST") ||
2426 !strcasecmp(sval, "MAY") ||
2427 !strncasecmp(sval, "X-", 2) ) {
2428 /* Missing OID, backtrack */
2431 LDAP_SCHEMA_ALLOW_OID_MACRO ) {
2432 /* Non-numerical OID, ignore */
2433 int len = ss-savepos;
2434 oc->oc_oid = LDAP_MALLOC(len+1);
2435 strncpy(oc->oc_oid, savepos, len);
2436 oc->oc_oid[len] = 0;
2442 ldap_objectclass_free(oc);
2449 * Beyond this point we will be liberal an accept the items
2453 kind = get_token(&ss,&sval);
2456 *code = LDAP_SCHERR_NORIGHTPAREN;
2458 ldap_objectclass_free(oc);
2463 if ( !strcasecmp(sval,"NAME") ) {
2466 *code = LDAP_SCHERR_DUPOPT;
2468 ldap_objectclass_free(oc);
2472 oc->oc_names = parse_qdescrs(&ss,code);
2473 if ( !oc->oc_names ) {
2474 if ( *code != LDAP_SCHERR_OUTOFMEM )
2475 *code = LDAP_SCHERR_BADNAME;
2477 ldap_objectclass_free(oc);
2480 } else if ( !strcasecmp(sval,"DESC") ) {
2483 *code = LDAP_SCHERR_DUPOPT;
2485 ldap_objectclass_free(oc);
2490 kind = get_token(&ss,&sval);
2491 if ( kind != TK_QDSTRING ) {
2492 *code = LDAP_SCHERR_UNEXPTOKEN;
2495 ldap_objectclass_free(oc);
2500 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
2502 if ( seen_obsolete ) {
2503 *code = LDAP_SCHERR_DUPOPT;
2505 ldap_objectclass_free(oc);
2509 oc->oc_obsolete = LDAP_SCHEMA_YES;
2511 } else if ( !strcasecmp(sval,"SUP") ) {
2514 *code = LDAP_SCHERR_DUPOPT;
2516 ldap_objectclass_free(oc);
2520 oc->oc_sup_oids = parse_oids(&ss,
2523 if ( !oc->oc_sup_oids ) {
2525 ldap_objectclass_free(oc);
2528 } else if ( !strcasecmp(sval,"ABSTRACT") ) {
2531 *code = LDAP_SCHERR_DUPOPT;
2533 ldap_objectclass_free(oc);
2537 oc->oc_kind = LDAP_SCHEMA_ABSTRACT;
2539 } else if ( !strcasecmp(sval,"STRUCTURAL") ) {
2542 *code = LDAP_SCHERR_DUPOPT;
2544 ldap_objectclass_free(oc);
2548 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
2550 } else if ( !strcasecmp(sval,"AUXILIARY") ) {
2553 *code = LDAP_SCHERR_DUPOPT;
2555 ldap_objectclass_free(oc);
2559 oc->oc_kind = LDAP_SCHEMA_AUXILIARY;
2561 } else if ( !strcasecmp(sval,"MUST") ) {
2564 *code = LDAP_SCHERR_DUPOPT;
2566 ldap_objectclass_free(oc);
2570 oc->oc_at_oids_must = parse_oids(&ss,code,0);
2571 if ( !oc->oc_at_oids_must ) {
2573 ldap_objectclass_free(oc);
2577 } else if ( !strcasecmp(sval,"MAY") ) {
2580 *code = LDAP_SCHERR_DUPOPT;
2582 ldap_objectclass_free(oc);
2586 oc->oc_at_oids_may = parse_oids(&ss,code,0);
2587 if ( !oc->oc_at_oids_may ) {
2589 ldap_objectclass_free(oc);
2593 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
2594 /* Should be parse_qdstrings */
2595 ext_vals = parse_qdescrs(&ss, code);
2598 ldap_objectclass_free(oc);
2601 if ( add_extension(&oc->oc_extensions,
2603 *code = LDAP_SCHERR_OUTOFMEM;
2606 ldap_objectclass_free(oc);
2610 *code = LDAP_SCHERR_UNEXPTOKEN;
2613 ldap_objectclass_free(oc);
2618 *code = LDAP_SCHERR_UNEXPTOKEN;
2621 ldap_objectclass_free(oc);
2628 ldap_contentrule_free(LDAPContentRule * cr)
2630 LDAP_FREE(cr->cr_oid);
2631 if (cr->cr_names) LDAP_VFREE(cr->cr_names);
2632 if (cr->cr_desc) LDAP_FREE(cr->cr_desc);
2633 if (cr->cr_oc_oids_aux) LDAP_VFREE(cr->cr_oc_oids_aux);
2634 if (cr->cr_at_oids_must) LDAP_VFREE(cr->cr_at_oids_must);
2635 if (cr->cr_at_oids_may) LDAP_VFREE(cr->cr_at_oids_may);
2636 if (cr->cr_at_oids_not) LDAP_VFREE(cr->cr_at_oids_not);
2637 free_extensions(cr->cr_extensions);
2642 ldap_str2contentrule( LDAP_CONST char * s,
2644 LDAP_CONST char ** errp,
2645 LDAP_CONST unsigned flags )
2648 const char * ss = s;
2652 int seen_obsolete = 0;
2657 LDAPContentRule * cr;
2659 const char * savepos;
2662 *code = LDAP_SCHERR_EMPTY;
2668 cr = LDAP_CALLOC(1,sizeof(LDAPContentRule));
2671 *code = LDAP_SCHERR_OUTOFMEM;
2675 kind = get_token(&ss,&sval);
2676 if ( kind != TK_LEFTPAREN ) {
2677 *code = LDAP_SCHERR_NOLEFTPAREN;
2679 ldap_contentrule_free(cr);
2684 * Definitions MUST begin with an OID in the numericoid format.
2688 cr->cr_oid = ldap_int_parse_numericoid(&ss,code,0);
2689 if ( !cr->cr_oid ) {
2690 if ( (flags & LDAP_SCHEMA_ALLOW_ALL) && (ss == savepos) ) {
2693 kind = get_token(&ss,&sval);
2694 if ( kind == TK_BAREWORD ) {
2695 if ( !strcasecmp(sval, "NAME") ||
2696 !strcasecmp(sval, "DESC") ||
2697 !strcasecmp(sval, "OBSOLETE") ||
2698 !strcasecmp(sval, "AUX") ||
2699 !strcasecmp(sval, "MUST") ||
2700 !strcasecmp(sval, "MAY") ||
2701 !strcasecmp(sval, "NOT") ||
2702 !strncasecmp(sval, "X-", 2) ) {
2703 /* Missing OID, backtrack */
2706 LDAP_SCHEMA_ALLOW_OID_MACRO ) {
2707 /* Non-numerical OID, ignore */
2708 int len = ss-savepos;
2709 cr->cr_oid = LDAP_MALLOC(len+1);
2710 strncpy(cr->cr_oid, savepos, len);
2711 cr->cr_oid[len] = 0;
2717 ldap_contentrule_free(cr);
2724 * Beyond this point we will be liberal an accept the items
2728 kind = get_token(&ss,&sval);
2731 *code = LDAP_SCHERR_NORIGHTPAREN;
2733 ldap_contentrule_free(cr);
2738 if ( !strcasecmp(sval,"NAME") ) {
2741 *code = LDAP_SCHERR_DUPOPT;
2743 ldap_contentrule_free(cr);
2747 cr->cr_names = parse_qdescrs(&ss,code);
2748 if ( !cr->cr_names ) {
2749 if ( *code != LDAP_SCHERR_OUTOFMEM )
2750 *code = LDAP_SCHERR_BADNAME;
2752 ldap_contentrule_free(cr);
2755 } else if ( !strcasecmp(sval,"DESC") ) {
2758 *code = LDAP_SCHERR_DUPOPT;
2760 ldap_contentrule_free(cr);
2765 kind = get_token(&ss,&sval);
2766 if ( kind != TK_QDSTRING ) {
2767 *code = LDAP_SCHERR_UNEXPTOKEN;
2770 ldap_contentrule_free(cr);
2775 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
2777 if ( seen_obsolete ) {
2778 *code = LDAP_SCHERR_DUPOPT;
2780 ldap_contentrule_free(cr);
2784 cr->cr_obsolete = LDAP_SCHEMA_YES;
2786 } else if ( !strcasecmp(sval,"AUX") ) {
2789 *code = LDAP_SCHERR_DUPOPT;
2791 ldap_contentrule_free(cr);
2795 cr->cr_oc_oids_aux = parse_oids(&ss,code,0);
2796 if ( !cr->cr_oc_oids_aux ) {
2798 ldap_contentrule_free(cr);
2802 } else if ( !strcasecmp(sval,"MUST") ) {
2805 *code = LDAP_SCHERR_DUPOPT;
2807 ldap_contentrule_free(cr);
2811 cr->cr_at_oids_must = parse_oids(&ss,code,0);
2812 if ( !cr->cr_at_oids_must ) {
2814 ldap_contentrule_free(cr);
2818 } else if ( !strcasecmp(sval,"MAY") ) {
2821 *code = LDAP_SCHERR_DUPOPT;
2823 ldap_contentrule_free(cr);
2827 cr->cr_at_oids_may = parse_oids(&ss,code,0);
2828 if ( !cr->cr_at_oids_may ) {
2830 ldap_contentrule_free(cr);
2834 } else if ( !strcasecmp(sval,"NOT") ) {
2837 *code = LDAP_SCHERR_DUPOPT;
2839 ldap_contentrule_free(cr);
2843 cr->cr_at_oids_not = parse_oids(&ss,code,0);
2844 if ( !cr->cr_at_oids_not ) {
2846 ldap_contentrule_free(cr);
2850 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
2851 /* Should be parse_qdstrings */
2852 ext_vals = parse_qdescrs(&ss, code);
2855 ldap_contentrule_free(cr);
2858 if ( add_extension(&cr->cr_extensions,
2860 *code = LDAP_SCHERR_OUTOFMEM;
2863 ldap_contentrule_free(cr);
2867 *code = LDAP_SCHERR_UNEXPTOKEN;
2870 ldap_contentrule_free(cr);
2875 *code = LDAP_SCHERR_UNEXPTOKEN;
2878 ldap_contentrule_free(cr);
2885 ldap_structurerule_free(LDAPStructureRule * sr)
2887 if (sr->sr_names) LDAP_VFREE(sr->sr_names);
2888 if (sr->sr_desc) LDAP_FREE(sr->sr_desc);
2889 if (sr->sr_nameform) LDAP_FREE(sr->sr_nameform);
2890 if (sr->sr_sup_ruleids) LDAP_FREE(sr->sr_sup_ruleids);
2891 free_extensions(sr->sr_extensions);
2896 ldap_str2structurerule( LDAP_CONST char * s,
2898 LDAP_CONST char ** errp,
2899 LDAP_CONST unsigned flags )
2902 const char * ss = s;
2906 int seen_obsolete = 0;
2907 int seen_nameform = 0;
2908 LDAPStructureRule * sr;
2910 const char * savepos;
2913 *code = LDAP_SCHERR_EMPTY;
2919 sr = LDAP_CALLOC(1,sizeof(LDAPStructureRule));
2922 *code = LDAP_SCHERR_OUTOFMEM;
2926 kind = get_token(&ss,&sval);
2927 if ( kind != TK_LEFTPAREN ) {
2928 *code = LDAP_SCHERR_NOLEFTPAREN;
2930 ldap_structurerule_free(sr);
2935 * Definitions MUST begin with a ruleid.
2939 ret = ldap_int_parse_ruleid(&ss,code,0,&sr->sr_ruleid);
2942 ldap_structurerule_free(sr);
2948 * Beyond this point we will be liberal an accept the items
2952 kind = get_token(&ss,&sval);
2955 *code = LDAP_SCHERR_NORIGHTPAREN;
2957 ldap_structurerule_free(sr);
2960 if( !seen_nameform ) {
2961 *code = LDAP_SCHERR_MISSING;
2962 ldap_structurerule_free(sr);
2967 if ( !strcasecmp(sval,"NAME") ) {
2970 *code = LDAP_SCHERR_DUPOPT;
2972 ldap_structurerule_free(sr);
2976 sr->sr_names = parse_qdescrs(&ss,code);
2977 if ( !sr->sr_names ) {
2978 if ( *code != LDAP_SCHERR_OUTOFMEM )
2979 *code = LDAP_SCHERR_BADNAME;
2981 ldap_structurerule_free(sr);
2984 } else if ( !strcasecmp(sval,"DESC") ) {
2987 *code = LDAP_SCHERR_DUPOPT;
2989 ldap_structurerule_free(sr);
2994 kind = get_token(&ss,&sval);
2995 if ( kind != TK_QDSTRING ) {
2996 *code = LDAP_SCHERR_UNEXPTOKEN;
2999 ldap_structurerule_free(sr);
3004 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
3006 if ( seen_obsolete ) {
3007 *code = LDAP_SCHERR_DUPOPT;
3009 ldap_structurerule_free(sr);
3013 sr->sr_obsolete = LDAP_SCHEMA_YES;
3015 } else if ( !strcasecmp(sval,"FORM") ) {
3017 if ( seen_nameform ) {
3018 *code = LDAP_SCHERR_DUPOPT;
3020 ldap_structurerule_free(sr);
3024 sr->sr_nameform = parse_woid(&ss,code);
3025 if ( !sr->sr_nameform ) {
3027 ldap_structurerule_free(sr);
3031 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
3032 /* Should be parse_qdstrings */
3033 ext_vals = parse_qdescrs(&ss, code);
3036 ldap_structurerule_free(sr);
3039 if ( add_extension(&sr->sr_extensions,
3041 *code = LDAP_SCHERR_OUTOFMEM;
3044 ldap_structurerule_free(sr);
3048 *code = LDAP_SCHERR_UNEXPTOKEN;
3051 ldap_structurerule_free(sr);
3056 *code = LDAP_SCHERR_UNEXPTOKEN;
3059 ldap_structurerule_free(sr);
3066 ldap_nameform_free(LDAPNameForm * nf)
3068 LDAP_FREE(nf->nf_oid);
3069 if (nf->nf_names) LDAP_VFREE(nf->nf_names);
3070 if (nf->nf_desc) LDAP_FREE(nf->nf_desc);
3071 if (nf->nf_objectclass) LDAP_FREE(nf->nf_objectclass);
3072 if (nf->nf_at_oids_must) LDAP_VFREE(nf->nf_at_oids_must);
3073 if (nf->nf_at_oids_may) LDAP_VFREE(nf->nf_at_oids_may);
3074 free_extensions(nf->nf_extensions);
3079 ldap_str2nameform( LDAP_CONST char * s,
3081 LDAP_CONST char ** errp,
3082 LDAP_CONST unsigned flags )
3085 const char * ss = s;
3089 int seen_obsolete = 0;
3095 const char * savepos;
3098 *code = LDAP_SCHERR_EMPTY;
3104 nf = LDAP_CALLOC(1,sizeof(LDAPNameForm));
3107 *code = LDAP_SCHERR_OUTOFMEM;
3111 kind = get_token(&ss,&sval);
3112 if ( kind != TK_LEFTPAREN ) {
3113 *code = LDAP_SCHERR_NOLEFTPAREN;
3115 ldap_nameform_free(nf);
3120 * Definitions MUST begin with an OID in the numericoid format.
3121 * However, this routine is used by clients to parse the response
3122 * from servers and very well known servers will provide an OID
3123 * in the wrong format or even no OID at all. We do our best to
3124 * extract info from those servers.
3128 nf->nf_oid = ldap_int_parse_numericoid(&ss,code,0);
3129 if ( !nf->nf_oid ) {
3131 ldap_nameform_free(nf);
3137 * Beyond this point we will be liberal an accept the items
3141 kind = get_token(&ss,&sval);
3144 *code = LDAP_SCHERR_NORIGHTPAREN;
3146 ldap_nameform_free(nf);
3149 if( !seen_class || !seen_must ) {
3150 *code = LDAP_SCHERR_MISSING;
3151 ldap_nameform_free(nf);
3156 if ( !strcasecmp(sval,"NAME") ) {
3159 *code = LDAP_SCHERR_DUPOPT;
3161 ldap_nameform_free(nf);
3165 nf->nf_names = parse_qdescrs(&ss,code);
3166 if ( !nf->nf_names ) {
3167 if ( *code != LDAP_SCHERR_OUTOFMEM )
3168 *code = LDAP_SCHERR_BADNAME;
3170 ldap_nameform_free(nf);
3173 } else if ( !strcasecmp(sval,"DESC") ) {
3176 *code = LDAP_SCHERR_DUPOPT;
3178 ldap_nameform_free(nf);
3183 kind = get_token(&ss,&sval);
3184 if ( kind != TK_QDSTRING ) {
3185 *code = LDAP_SCHERR_UNEXPTOKEN;
3188 ldap_nameform_free(nf);
3193 } else if ( !strcasecmp(sval,"OBSOLETE") ) {
3195 if ( seen_obsolete ) {
3196 *code = LDAP_SCHERR_DUPOPT;
3198 ldap_nameform_free(nf);
3202 nf->nf_obsolete = LDAP_SCHEMA_YES;
3204 } else if ( !strcasecmp(sval,"MUST") ) {
3207 *code = LDAP_SCHERR_DUPOPT;
3209 ldap_nameform_free(nf);
3213 nf->nf_at_oids_must = parse_oids(&ss,code,0);
3214 if ( !nf->nf_at_oids_must ) {
3216 ldap_nameform_free(nf);
3220 } else if ( !strcasecmp(sval,"MAY") ) {
3223 *code = LDAP_SCHERR_DUPOPT;
3225 ldap_nameform_free(nf);
3229 nf->nf_at_oids_may = parse_oids(&ss,code,0);
3230 if ( !nf->nf_at_oids_may ) {
3232 ldap_nameform_free(nf);
3236 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
3237 /* Should be parse_qdstrings */
3238 ext_vals = parse_qdescrs(&ss, code);
3241 ldap_nameform_free(nf);
3244 if ( add_extension(&nf->nf_extensions,
3246 *code = LDAP_SCHERR_OUTOFMEM;
3249 ldap_nameform_free(nf);
3253 *code = LDAP_SCHERR_UNEXPTOKEN;
3256 ldap_nameform_free(nf);
3261 *code = LDAP_SCHERR_UNEXPTOKEN;
3264 ldap_nameform_free(nf);
3270 static char *const err2text[] = {
3272 N_("Out of memory"),
3273 N_("Unexpected token"),
3274 N_("Missing opening parenthesis"),
3275 N_("Missing closing parenthesis"),
3276 N_("Expecting digit"),
3277 N_("Expecting a name"),
3278 N_("Bad description"),
3279 N_("Bad superiors"),
3280 N_("Duplicate option"),
3281 N_("Unexpected end of data"),
3282 N_("Missing required field"),
3283 N_("Out of order field")
3287 ldap_scherr2str(int code)
3289 if ( code < 0 || code >= (int)(sizeof(err2text)/sizeof(char *)) ) {
3290 return _("Unknown error");
3292 return _(err2text[code]);