2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2003 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;
1199 } else if ( kind == TK_QDESCR ) {
1200 res = LDAP_CALLOC(2,sizeof(char *));
1202 *code = LDAP_SCHERR_OUTOFMEM;
1211 *code = LDAP_SCHERR_BADNAME;
1218 parse_woid(const char **sp, int *code)
1224 kind = get_token(sp, &sval);
1225 if ( kind != TK_BAREWORD ) {
1227 *code = LDAP_SCHERR_UNEXPTOKEN;
1234 /* Parse a noidlen */
1236 parse_noidlen(const char **sp, int *code, int *len, int allow_quoted)
1242 /* Netscape puts the SYNTAX value in quotes (incorrectly) */
1243 if ( allow_quoted && **sp == '\'' ) {
1247 sval = ldap_int_parse_numericoid(sp, code, 0);
1251 if ( **sp == '{' /*}*/ ) {
1254 while ( LDAP_DIGIT(**sp) )
1256 if ( **sp != /*{*/ '}' ) {
1257 *code = LDAP_SCHERR_UNEXPTOKEN;
1263 if ( allow_quoted && quoted ) {
1264 if ( **sp == '\'' ) {
1267 *code = LDAP_SCHERR_UNEXPTOKEN;
1276 * Next routine will accept a qdstring in place of an oid if
1277 * allow_quoted is set. This is necessary to interoperate with
1278 * Netscape Directory server that will improperly quote each oid (at
1279 * least those of the descr kind) in the SUP clause.
1282 /* Parse a woid or a $-separated list of them enclosed in () */
1284 parse_oids(const char **sp, int *code, const int allow_quoted)
1294 * Strictly speaking, doing this here accepts whsp before the
1295 * ( at the begining of an oidlist, but this is harmless. Also,
1296 * we are very liberal in what we accept as an OID. Maybe
1300 kind = get_token(sp,&sval);
1301 if ( kind == TK_LEFTPAREN ) {
1302 /* Let's presume there will be at least 2 entries */
1304 res = LDAP_CALLOC(3,sizeof(char *));
1306 *code = LDAP_SCHERR_OUTOFMEM;
1311 kind = get_token(sp,&sval);
1312 if ( kind == TK_BAREWORD ||
1313 ( allow_quoted && kind == TK_QDSTRING ) ) {
1317 *code = LDAP_SCHERR_UNEXPTOKEN;
1324 kind = get_token(sp,&sval);
1325 if ( kind == TK_RIGHTPAREN )
1327 if ( kind == TK_DOLLAR ) {
1329 kind = get_token(sp,&sval);
1330 if ( kind == TK_BAREWORD ||
1332 kind == TK_QDSTRING ) ) {
1333 if ( pos == size-2 ) {
1335 res1 = LDAP_REALLOC(res,size*sizeof(char *));
1339 *code = LDAP_SCHERR_OUTOFMEM;
1347 *code = LDAP_SCHERR_UNEXPTOKEN;
1354 *code = LDAP_SCHERR_UNEXPTOKEN;
1363 } else if ( kind == TK_BAREWORD ||
1364 ( allow_quoted && kind == TK_QDSTRING ) ) {
1365 res = LDAP_CALLOC(2,sizeof(char *));
1368 *code = LDAP_SCHERR_OUTOFMEM;
1377 *code = LDAP_SCHERR_BADNAME;
1383 add_extension(LDAPSchemaExtensionItem ***extensions,
1384 char * name, char ** values)
1387 LDAPSchemaExtensionItem **tmp, *ext;
1389 ext = LDAP_CALLOC(1, sizeof(LDAPSchemaExtensionItem));
1392 ext->lsei_name = name;
1393 ext->lsei_values = values;
1395 if ( !*extensions ) {
1397 LDAP_CALLOC(2, sizeof(LDAPSchemaExtensionItem *));
1402 for ( n=0; (*extensions)[n] != NULL; n++ )
1404 tmp = LDAP_REALLOC(*extensions,
1405 (n+2)*sizeof(LDAPSchemaExtensionItem *));
1410 (*extensions)[n] = ext;
1411 (*extensions)[n+1] = NULL;
1416 free_extensions(LDAPSchemaExtensionItem **extensions)
1418 LDAPSchemaExtensionItem **ext;
1421 for ( ext = extensions; *ext != NULL; ext++ ) {
1422 LDAP_FREE((*ext)->lsei_name);
1423 LDAP_VFREE((*ext)->lsei_values);
1426 LDAP_FREE(extensions);
1431 ldap_syntax_free( LDAPSyntax * syn )
1433 LDAP_FREE(syn->syn_oid);
1434 if (syn->syn_names) LDAP_VFREE(syn->syn_names);
1435 if (syn->syn_desc) LDAP_FREE(syn->syn_desc);
1436 free_extensions(syn->syn_extensions);
1441 ldap_str2syntax( LDAP_CONST char * s,
1443 LDAP_CONST char ** errp,
1444 LDAP_CONST unsigned flags )
1447 const char * ss = s;
1455 *code = LDAP_SCHERR_EMPTY;
1461 syn = LDAP_CALLOC(1,sizeof(LDAPSyntax));
1464 *code = LDAP_SCHERR_OUTOFMEM;
1468 kind = get_token(&ss,&sval);
1469 if ( kind != TK_LEFTPAREN ) {
1471 *code = LDAP_SCHERR_NOLEFTPAREN;
1472 ldap_syntax_free(syn);
1477 syn->syn_oid = ldap_int_parse_numericoid(&ss,code,0);
1478 if ( !syn->syn_oid ) {
1480 ldap_syntax_free(syn);
1486 * Beyond this point we will be liberal and accept the items
1490 kind = get_token(&ss,&sval);
1493 *code = LDAP_SCHERR_NORIGHTPAREN;
1495 ldap_syntax_free(syn);
1500 if ( !strcmp(sval,"NAME") ) {
1503 *code = LDAP_SCHERR_DUPOPT;
1505 ldap_syntax_free(syn);
1509 syn->syn_names = parse_qdescrs(&ss,code);
1510 if ( !syn->syn_names ) {
1511 if ( *code != LDAP_SCHERR_OUTOFMEM )
1512 *code = LDAP_SCHERR_BADNAME;
1514 ldap_syntax_free(syn);
1517 } else if ( !strcmp(sval,"DESC") ) {
1520 *code = LDAP_SCHERR_DUPOPT;
1522 ldap_syntax_free(syn);
1527 kind = get_token(&ss,&sval);
1528 if ( kind != TK_QDSTRING ) {
1529 *code = LDAP_SCHERR_UNEXPTOKEN;
1532 ldap_syntax_free(syn);
1535 syn->syn_desc = sval;
1537 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1538 /* Should be parse_qdstrings */
1539 ext_vals = parse_qdescrs(&ss, code);
1542 ldap_syntax_free(syn);
1545 if ( add_extension(&syn->syn_extensions,
1547 *code = LDAP_SCHERR_OUTOFMEM;
1550 ldap_syntax_free(syn);
1554 *code = LDAP_SCHERR_UNEXPTOKEN;
1557 ldap_syntax_free(syn);
1562 *code = LDAP_SCHERR_UNEXPTOKEN;
1565 ldap_syntax_free(syn);
1572 ldap_matchingrule_free( LDAPMatchingRule * mr )
1574 LDAP_FREE(mr->mr_oid);
1575 if (mr->mr_names) LDAP_VFREE(mr->mr_names);
1576 if (mr->mr_desc) LDAP_FREE(mr->mr_desc);
1577 if (mr->mr_syntax_oid) LDAP_FREE(mr->mr_syntax_oid);
1578 free_extensions(mr->mr_extensions);
1583 ldap_str2matchingrule( LDAP_CONST char * s,
1585 LDAP_CONST char ** errp,
1586 LDAP_CONST unsigned flags )
1589 const char * ss = s;
1593 int seen_obsolete = 0;
1594 int seen_syntax = 0;
1595 LDAPMatchingRule * mr;
1597 const char * savepos;
1600 *code = LDAP_SCHERR_EMPTY;
1606 mr = LDAP_CALLOC(1,sizeof(LDAPMatchingRule));
1609 *code = LDAP_SCHERR_OUTOFMEM;
1613 kind = get_token(&ss,&sval);
1614 if ( kind != TK_LEFTPAREN ) {
1615 *code = LDAP_SCHERR_NOLEFTPAREN;
1617 ldap_matchingrule_free(mr);
1623 mr->mr_oid = ldap_int_parse_numericoid(&ss,code,flags);
1624 if ( !mr->mr_oid ) {
1625 if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
1628 kind = get_token(&ss,&sval);
1629 if ( kind == TK_BAREWORD ) {
1630 if ( !strcmp(sval, "NAME") ||
1631 !strcmp(sval, "DESC") ||
1632 !strcmp(sval, "OBSOLETE") ||
1633 !strcmp(sval, "SYNTAX") ||
1634 !strncmp(sval, "X-", 2) ) {
1635 /* Missing OID, backtrack */
1638 /* Non-numerical OID, ignore */
1644 ldap_matchingrule_free(mr);
1651 * Beyond this point we will be liberal and accept the items
1655 kind = get_token(&ss,&sval);
1658 *code = LDAP_SCHERR_NORIGHTPAREN;
1660 ldap_matchingrule_free(mr);
1663 if( !seen_syntax ) {
1664 *code = LDAP_SCHERR_MISSING;
1665 ldap_matchingrule_free(mr);
1670 if ( !strcmp(sval,"NAME") ) {
1673 *code = LDAP_SCHERR_DUPOPT;
1675 ldap_matchingrule_free(mr);
1679 mr->mr_names = parse_qdescrs(&ss,code);
1680 if ( !mr->mr_names ) {
1681 if ( *code != LDAP_SCHERR_OUTOFMEM )
1682 *code = LDAP_SCHERR_BADNAME;
1684 ldap_matchingrule_free(mr);
1687 } else if ( !strcmp(sval,"DESC") ) {
1690 *code = LDAP_SCHERR_DUPOPT;
1692 ldap_matchingrule_free(mr);
1697 kind = get_token(&ss,&sval);
1698 if ( kind != TK_QDSTRING ) {
1699 *code = LDAP_SCHERR_UNEXPTOKEN;
1702 ldap_matchingrule_free(mr);
1707 } else if ( !strcmp(sval,"OBSOLETE") ) {
1709 if ( seen_obsolete ) {
1710 *code = LDAP_SCHERR_DUPOPT;
1712 ldap_matchingrule_free(mr);
1716 mr->mr_obsolete = LDAP_SCHEMA_YES;
1718 } else if ( !strcmp(sval,"SYNTAX") ) {
1720 if ( seen_syntax ) {
1721 *code = LDAP_SCHERR_DUPOPT;
1723 ldap_matchingrule_free(mr);
1729 ldap_int_parse_numericoid(&ss,code,flags);
1730 if ( !mr->mr_syntax_oid ) {
1732 ldap_matchingrule_free(mr);
1736 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1737 /* Should be parse_qdstrings */
1738 ext_vals = parse_qdescrs(&ss, code);
1741 ldap_matchingrule_free(mr);
1744 if ( add_extension(&mr->mr_extensions,
1746 *code = LDAP_SCHERR_OUTOFMEM;
1749 ldap_matchingrule_free(mr);
1753 *code = LDAP_SCHERR_UNEXPTOKEN;
1756 ldap_matchingrule_free(mr);
1761 *code = LDAP_SCHERR_UNEXPTOKEN;
1764 ldap_matchingrule_free(mr);
1771 ldap_matchingruleuse_free( LDAPMatchingRuleUse * mru )
1773 LDAP_FREE(mru->mru_oid);
1774 if (mru->mru_names) LDAP_VFREE(mru->mru_names);
1775 if (mru->mru_desc) LDAP_FREE(mru->mru_desc);
1776 if (mru->mru_applies_oids) LDAP_VFREE(mru->mru_applies_oids);
1777 free_extensions(mru->mru_extensions);
1781 LDAPMatchingRuleUse *
1782 ldap_str2matchingruleuse( LDAP_CONST char * s,
1784 LDAP_CONST char ** errp,
1785 LDAP_CONST unsigned flags )
1788 const char * ss = s;
1792 int seen_obsolete = 0;
1793 int seen_applies = 0;
1794 LDAPMatchingRuleUse * mru;
1796 const char * savepos;
1799 *code = LDAP_SCHERR_EMPTY;
1805 mru = LDAP_CALLOC(1,sizeof(LDAPMatchingRuleUse));
1808 *code = LDAP_SCHERR_OUTOFMEM;
1812 kind = get_token(&ss,&sval);
1813 if ( kind != TK_LEFTPAREN ) {
1814 *code = LDAP_SCHERR_NOLEFTPAREN;
1816 ldap_matchingruleuse_free(mru);
1822 mru->mru_oid = ldap_int_parse_numericoid(&ss,code,flags);
1823 if ( !mru->mru_oid ) {
1824 if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
1827 kind = get_token(&ss,&sval);
1828 if ( kind == TK_BAREWORD ) {
1829 if ( !strcmp(sval, "NAME") ||
1830 !strcmp(sval, "DESC") ||
1831 !strcmp(sval, "OBSOLETE") ||
1832 !strcmp(sval, "APPLIES") ||
1833 !strncmp(sval, "X-", 2) ) {
1834 /* Missing OID, backtrack */
1837 /* Non-numerical OID, ignore */
1843 ldap_matchingruleuse_free(mru);
1850 * Beyond this point we will be liberal and accept the items
1854 kind = get_token(&ss,&sval);
1857 *code = LDAP_SCHERR_NORIGHTPAREN;
1859 ldap_matchingruleuse_free(mru);
1862 if( !seen_applies ) {
1863 *code = LDAP_SCHERR_MISSING;
1864 ldap_matchingruleuse_free(mru);
1869 if ( !strcmp(sval,"NAME") ) {
1872 *code = LDAP_SCHERR_DUPOPT;
1874 ldap_matchingruleuse_free(mru);
1878 mru->mru_names = parse_qdescrs(&ss,code);
1879 if ( !mru->mru_names ) {
1880 if ( *code != LDAP_SCHERR_OUTOFMEM )
1881 *code = LDAP_SCHERR_BADNAME;
1883 ldap_matchingruleuse_free(mru);
1886 } else if ( !strcmp(sval,"DESC") ) {
1889 *code = LDAP_SCHERR_DUPOPT;
1891 ldap_matchingruleuse_free(mru);
1896 kind = get_token(&ss,&sval);
1897 if ( kind != TK_QDSTRING ) {
1898 *code = LDAP_SCHERR_UNEXPTOKEN;
1901 ldap_matchingruleuse_free(mru);
1904 mru->mru_desc = sval;
1906 } else if ( !strcmp(sval,"OBSOLETE") ) {
1908 if ( seen_obsolete ) {
1909 *code = LDAP_SCHERR_DUPOPT;
1911 ldap_matchingruleuse_free(mru);
1915 mru->mru_obsolete = LDAP_SCHEMA_YES;
1917 } else if ( !strcmp(sval,"APPLIES") ) {
1919 if ( seen_applies ) {
1920 *code = LDAP_SCHERR_DUPOPT;
1922 ldap_matchingruleuse_free(mru);
1926 mru->mru_applies_oids = parse_oids(&ss,
1929 if ( !mru->mru_applies_oids ) {
1931 ldap_matchingruleuse_free(mru);
1934 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1935 /* Should be parse_qdstrings */
1936 ext_vals = parse_qdescrs(&ss, code);
1939 ldap_matchingruleuse_free(mru);
1942 if ( add_extension(&mru->mru_extensions,
1944 *code = LDAP_SCHERR_OUTOFMEM;
1947 ldap_matchingruleuse_free(mru);
1951 *code = LDAP_SCHERR_UNEXPTOKEN;
1954 ldap_matchingruleuse_free(mru);
1959 *code = LDAP_SCHERR_UNEXPTOKEN;
1962 ldap_matchingruleuse_free(mru);
1969 ldap_attributetype_free(LDAPAttributeType * at)
1971 LDAP_FREE(at->at_oid);
1972 if (at->at_names) LDAP_VFREE(at->at_names);
1973 if (at->at_desc) LDAP_FREE(at->at_desc);
1974 if (at->at_sup_oid) LDAP_FREE(at->at_sup_oid);
1975 if (at->at_equality_oid) LDAP_FREE(at->at_equality_oid);
1976 if (at->at_ordering_oid) LDAP_FREE(at->at_ordering_oid);
1977 if (at->at_substr_oid) LDAP_FREE(at->at_substr_oid);
1978 if (at->at_syntax_oid) LDAP_FREE(at->at_syntax_oid);
1979 free_extensions(at->at_extensions);
1984 ldap_str2attributetype( LDAP_CONST char * s,
1986 LDAP_CONST char ** errp,
1987 LDAP_CONST unsigned flags )
1990 const char * ss = s;
1994 int seen_obsolete = 0;
1996 int seen_equality = 0;
1997 int seen_ordering = 0;
1998 int seen_substr = 0;
1999 int seen_syntax = 0;
2001 LDAPAttributeType * at;
2003 const char * savepos;
2006 *code = LDAP_SCHERR_EMPTY;
2012 at = LDAP_CALLOC(1,sizeof(LDAPAttributeType));
2015 *code = LDAP_SCHERR_OUTOFMEM;
2019 kind = get_token(&ss,&sval);
2020 if ( kind != TK_LEFTPAREN ) {
2021 *code = LDAP_SCHERR_NOLEFTPAREN;
2023 ldap_attributetype_free(at);
2028 * Definitions MUST begin with an OID in the numericoid format.
2029 * However, this routine is used by clients to parse the response
2030 * from servers and very well known servers will provide an OID
2031 * in the wrong format or even no OID at all. We do our best to
2032 * extract info from those servers.
2036 at->at_oid = ldap_int_parse_numericoid(&ss,code,0);
2037 if ( !at->at_oid ) {
2038 if ( ( flags & ( LDAP_SCHEMA_ALLOW_NO_OID
2039 | LDAP_SCHEMA_ALLOW_OID_MACRO ) )
2040 && (ss == savepos) ) {
2043 kind = get_token(&ss,&sval);
2044 if ( kind == TK_BAREWORD ) {
2045 if ( !strcmp(sval, "NAME") ||
2046 !strcmp(sval, "DESC") ||
2047 !strcmp(sval, "OBSOLETE") ||
2048 !strcmp(sval, "SUP") ||
2049 !strcmp(sval, "EQUALITY") ||
2050 !strcmp(sval, "ORDERING") ||
2051 !strcmp(sval, "SUBSTR") ||
2052 !strcmp(sval, "SYNTAX") ||
2053 !strcmp(sval, "SINGLE-VALUE") ||
2054 !strcmp(sval, "COLLECTIVE") ||
2055 !strcmp(sval, "NO-USER-MODIFICATION") ||
2056 !strcmp(sval, "USAGE") ||
2057 !strncmp(sval, "X-", 2) ) {
2058 /* Missing OID, backtrack */
2061 & LDAP_SCHEMA_ALLOW_OID_MACRO) {
2062 /* Non-numerical OID ... */
2063 int len = ss-savepos;
2064 at->at_oid = LDAP_MALLOC(len+1);
2065 strncpy(at->at_oid, savepos, len);
2066 at->at_oid[len] = 0;
2072 ldap_attributetype_free(at);
2079 * Beyond this point we will be liberal and accept the items
2083 kind = get_token(&ss,&sval);
2086 *code = LDAP_SCHERR_NORIGHTPAREN;
2088 ldap_attributetype_free(at);
2093 if ( !strcmp(sval,"NAME") ) {
2096 *code = LDAP_SCHERR_DUPOPT;
2098 ldap_attributetype_free(at);
2102 at->at_names = parse_qdescrs(&ss,code);
2103 if ( !at->at_names ) {
2104 if ( *code != LDAP_SCHERR_OUTOFMEM )
2105 *code = LDAP_SCHERR_BADNAME;
2107 ldap_attributetype_free(at);
2110 } else if ( !strcmp(sval,"DESC") ) {
2113 *code = LDAP_SCHERR_DUPOPT;
2115 ldap_attributetype_free(at);
2120 kind = get_token(&ss,&sval);
2121 if ( kind != TK_QDSTRING ) {
2122 *code = LDAP_SCHERR_UNEXPTOKEN;
2125 ldap_attributetype_free(at);
2130 } else if ( !strcmp(sval,"OBSOLETE") ) {
2132 if ( seen_obsolete ) {
2133 *code = LDAP_SCHERR_DUPOPT;
2135 ldap_attributetype_free(at);
2139 at->at_obsolete = LDAP_SCHEMA_YES;
2141 } else if ( !strcmp(sval,"SUP") ) {
2144 *code = LDAP_SCHERR_DUPOPT;
2146 ldap_attributetype_free(at);
2150 at->at_sup_oid = parse_woid(&ss,code);
2151 if ( !at->at_sup_oid ) {
2153 ldap_attributetype_free(at);
2156 } else if ( !strcmp(sval,"EQUALITY") ) {
2158 if ( seen_equality ) {
2159 *code = LDAP_SCHERR_DUPOPT;
2161 ldap_attributetype_free(at);
2165 at->at_equality_oid = parse_woid(&ss,code);
2166 if ( !at->at_equality_oid ) {
2168 ldap_attributetype_free(at);
2171 } else if ( !strcmp(sval,"ORDERING") ) {
2173 if ( seen_ordering ) {
2174 *code = LDAP_SCHERR_DUPOPT;
2176 ldap_attributetype_free(at);
2180 at->at_ordering_oid = parse_woid(&ss,code);
2181 if ( !at->at_ordering_oid ) {
2183 ldap_attributetype_free(at);
2186 } else if ( !strcmp(sval,"SUBSTR") ) {
2188 if ( seen_substr ) {
2189 *code = LDAP_SCHERR_DUPOPT;
2191 ldap_attributetype_free(at);
2195 at->at_substr_oid = parse_woid(&ss,code);
2196 if ( !at->at_substr_oid ) {
2198 ldap_attributetype_free(at);
2201 } else if ( !strcmp(sval,"SYNTAX") ) {
2203 if ( seen_syntax ) {
2204 *code = LDAP_SCHERR_DUPOPT;
2206 ldap_attributetype_free(at);
2217 if ( !at->at_syntax_oid ) {
2218 if ( flags & LDAP_SCHEMA_ALLOW_OID_MACRO ) {
2219 kind = get_token(&ss,&sval);
2220 if (kind == TK_BAREWORD)
2222 char *sp = strchr(sval, '{');
2223 at->at_syntax_oid = sval;
2227 at->at_syntax_len = atoi(sp);
2228 while ( LDAP_DIGIT(*sp) )
2231 *code = LDAP_SCHERR_UNEXPTOKEN;
2233 ldap_attributetype_free(at);
2240 ldap_attributetype_free(at);
2245 } else if ( !strcmp(sval,"SINGLE-VALUE") ) {
2247 if ( at->at_single_value ) {
2248 *code = LDAP_SCHERR_DUPOPT;
2250 ldap_attributetype_free(at);
2253 at->at_single_value = LDAP_SCHEMA_YES;
2255 } else if ( !strcmp(sval,"COLLECTIVE") ) {
2257 if ( at->at_collective ) {
2258 *code = LDAP_SCHERR_DUPOPT;
2260 ldap_attributetype_free(at);
2263 at->at_collective = LDAP_SCHEMA_YES;
2265 } else if ( !strcmp(sval,"NO-USER-MODIFICATION") ) {
2267 if ( at->at_no_user_mod ) {
2268 *code = LDAP_SCHERR_DUPOPT;
2270 ldap_attributetype_free(at);
2273 at->at_no_user_mod = LDAP_SCHEMA_YES;
2275 } else if ( !strcmp(sval,"USAGE") ) {
2278 *code = LDAP_SCHERR_DUPOPT;
2280 ldap_attributetype_free(at);
2285 kind = get_token(&ss,&sval);
2286 if ( kind != TK_BAREWORD ) {
2287 *code = LDAP_SCHERR_UNEXPTOKEN;
2290 ldap_attributetype_free(at);
2293 if ( !strcasecmp(sval,"userApplications") )
2295 LDAP_SCHEMA_USER_APPLICATIONS;
2296 else if ( !strcasecmp(sval,"directoryOperation") )
2298 LDAP_SCHEMA_DIRECTORY_OPERATION;
2299 else if ( !strcasecmp(sval,"distributedOperation") )
2301 LDAP_SCHEMA_DISTRIBUTED_OPERATION;
2302 else if ( !strcasecmp(sval,"dSAOperation") )
2304 LDAP_SCHEMA_DSA_OPERATION;
2306 *code = LDAP_SCHERR_UNEXPTOKEN;
2309 ldap_attributetype_free(at);
2314 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
2315 /* Should be parse_qdstrings */
2316 ext_vals = parse_qdescrs(&ss, code);
2319 ldap_attributetype_free(at);
2322 if ( add_extension(&at->at_extensions,
2324 *code = LDAP_SCHERR_OUTOFMEM;
2327 ldap_attributetype_free(at);
2331 *code = LDAP_SCHERR_UNEXPTOKEN;
2334 ldap_attributetype_free(at);
2339 *code = LDAP_SCHERR_UNEXPTOKEN;
2342 ldap_attributetype_free(at);
2349 ldap_objectclass_free(LDAPObjectClass * oc)
2351 LDAP_FREE(oc->oc_oid);
2352 if (oc->oc_names) LDAP_VFREE(oc->oc_names);
2353 if (oc->oc_desc) LDAP_FREE(oc->oc_desc);
2354 if (oc->oc_sup_oids) LDAP_VFREE(oc->oc_sup_oids);
2355 if (oc->oc_at_oids_must) LDAP_VFREE(oc->oc_at_oids_must);
2356 if (oc->oc_at_oids_may) LDAP_VFREE(oc->oc_at_oids_may);
2357 free_extensions(oc->oc_extensions);
2362 ldap_str2objectclass( LDAP_CONST char * s,
2364 LDAP_CONST char ** errp,
2365 LDAP_CONST unsigned flags )
2368 const char * ss = s;
2372 int seen_obsolete = 0;
2377 LDAPObjectClass * oc;
2379 const char * savepos;
2382 *code = LDAP_SCHERR_EMPTY;
2388 oc = LDAP_CALLOC(1,sizeof(LDAPObjectClass));
2391 *code = LDAP_SCHERR_OUTOFMEM;
2394 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
2396 kind = get_token(&ss,&sval);
2397 if ( kind != TK_LEFTPAREN ) {
2398 *code = LDAP_SCHERR_NOLEFTPAREN;
2400 ldap_objectclass_free(oc);
2405 * Definitions MUST begin with an OID in the numericoid format.
2406 * However, this routine is used by clients to parse the response
2407 * from servers and very well known servers will provide an OID
2408 * in the wrong format or even no OID at all. We do our best to
2409 * extract info from those servers.
2413 oc->oc_oid = ldap_int_parse_numericoid(&ss,code,0);
2414 if ( !oc->oc_oid ) {
2415 if ( (flags & LDAP_SCHEMA_ALLOW_ALL) && (ss == savepos) ) {
2418 kind = get_token(&ss,&sval);
2419 if ( kind == TK_BAREWORD ) {
2420 if ( !strcmp(sval, "NAME") ||
2421 !strcmp(sval, "DESC") ||
2422 !strcmp(sval, "OBSOLETE") ||
2423 !strcmp(sval, "SUP") ||
2424 !strcmp(sval, "ABSTRACT") ||
2425 !strcmp(sval, "STRUCTURAL") ||
2426 !strcmp(sval, "AUXILIARY") ||
2427 !strcmp(sval, "MUST") ||
2428 !strcmp(sval, "MAY") ||
2429 !strncmp(sval, "X-", 2) ) {
2430 /* Missing OID, backtrack */
2433 LDAP_SCHEMA_ALLOW_OID_MACRO ) {
2434 /* Non-numerical OID, ignore */
2435 int len = ss-savepos;
2436 oc->oc_oid = LDAP_MALLOC(len+1);
2437 strncpy(oc->oc_oid, savepos, len);
2438 oc->oc_oid[len] = 0;
2444 ldap_objectclass_free(oc);
2451 * Beyond this point we will be liberal an accept the items
2455 kind = get_token(&ss,&sval);
2458 *code = LDAP_SCHERR_NORIGHTPAREN;
2460 ldap_objectclass_free(oc);
2465 if ( !strcmp(sval,"NAME") ) {
2468 *code = LDAP_SCHERR_DUPOPT;
2470 ldap_objectclass_free(oc);
2474 oc->oc_names = parse_qdescrs(&ss,code);
2475 if ( !oc->oc_names ) {
2476 if ( *code != LDAP_SCHERR_OUTOFMEM )
2477 *code = LDAP_SCHERR_BADNAME;
2479 ldap_objectclass_free(oc);
2482 } else if ( !strcmp(sval,"DESC") ) {
2485 *code = LDAP_SCHERR_DUPOPT;
2487 ldap_objectclass_free(oc);
2492 kind = get_token(&ss,&sval);
2493 if ( kind != TK_QDSTRING ) {
2494 *code = LDAP_SCHERR_UNEXPTOKEN;
2497 ldap_objectclass_free(oc);
2502 } else if ( !strcmp(sval,"OBSOLETE") ) {
2504 if ( seen_obsolete ) {
2505 *code = LDAP_SCHERR_DUPOPT;
2507 ldap_objectclass_free(oc);
2511 oc->oc_obsolete = LDAP_SCHEMA_YES;
2513 } else if ( !strcmp(sval,"SUP") ) {
2516 *code = LDAP_SCHERR_DUPOPT;
2518 ldap_objectclass_free(oc);
2522 oc->oc_sup_oids = parse_oids(&ss,
2525 if ( !oc->oc_sup_oids ) {
2527 ldap_objectclass_free(oc);
2530 } else if ( !strcmp(sval,"ABSTRACT") ) {
2533 *code = LDAP_SCHERR_DUPOPT;
2535 ldap_objectclass_free(oc);
2539 oc->oc_kind = LDAP_SCHEMA_ABSTRACT;
2541 } else if ( !strcmp(sval,"STRUCTURAL") ) {
2544 *code = LDAP_SCHERR_DUPOPT;
2546 ldap_objectclass_free(oc);
2550 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
2552 } else if ( !strcmp(sval,"AUXILIARY") ) {
2555 *code = LDAP_SCHERR_DUPOPT;
2557 ldap_objectclass_free(oc);
2561 oc->oc_kind = LDAP_SCHEMA_AUXILIARY;
2563 } else if ( !strcmp(sval,"MUST") ) {
2566 *code = LDAP_SCHERR_DUPOPT;
2568 ldap_objectclass_free(oc);
2572 oc->oc_at_oids_must = parse_oids(&ss,code,0);
2573 if ( !oc->oc_at_oids_must ) {
2575 ldap_objectclass_free(oc);
2579 } else if ( !strcmp(sval,"MAY") ) {
2582 *code = LDAP_SCHERR_DUPOPT;
2584 ldap_objectclass_free(oc);
2588 oc->oc_at_oids_may = parse_oids(&ss,code,0);
2589 if ( !oc->oc_at_oids_may ) {
2591 ldap_objectclass_free(oc);
2595 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
2596 /* Should be parse_qdstrings */
2597 ext_vals = parse_qdescrs(&ss, code);
2600 ldap_objectclass_free(oc);
2603 if ( add_extension(&oc->oc_extensions,
2605 *code = LDAP_SCHERR_OUTOFMEM;
2608 ldap_objectclass_free(oc);
2612 *code = LDAP_SCHERR_UNEXPTOKEN;
2615 ldap_objectclass_free(oc);
2620 *code = LDAP_SCHERR_UNEXPTOKEN;
2623 ldap_objectclass_free(oc);
2630 ldap_contentrule_free(LDAPContentRule * cr)
2632 LDAP_FREE(cr->cr_oid);
2633 if (cr->cr_names) LDAP_VFREE(cr->cr_names);
2634 if (cr->cr_desc) LDAP_FREE(cr->cr_desc);
2635 if (cr->cr_oc_oids_aux) LDAP_VFREE(cr->cr_oc_oids_aux);
2636 if (cr->cr_at_oids_must) LDAP_VFREE(cr->cr_at_oids_must);
2637 if (cr->cr_at_oids_may) LDAP_VFREE(cr->cr_at_oids_may);
2638 if (cr->cr_at_oids_not) LDAP_VFREE(cr->cr_at_oids_not);
2639 free_extensions(cr->cr_extensions);
2644 ldap_str2contentrule( LDAP_CONST char * s,
2646 LDAP_CONST char ** errp,
2647 LDAP_CONST unsigned flags )
2650 const char * ss = s;
2654 int seen_obsolete = 0;
2659 LDAPContentRule * cr;
2661 const char * savepos;
2664 *code = LDAP_SCHERR_EMPTY;
2670 cr = LDAP_CALLOC(1,sizeof(LDAPContentRule));
2673 *code = LDAP_SCHERR_OUTOFMEM;
2677 kind = get_token(&ss,&sval);
2678 if ( kind != TK_LEFTPAREN ) {
2679 *code = LDAP_SCHERR_NOLEFTPAREN;
2681 ldap_contentrule_free(cr);
2686 * Definitions MUST begin with an OID in the numericoid format.
2690 cr->cr_oid = ldap_int_parse_numericoid(&ss,code,0);
2691 if ( !cr->cr_oid ) {
2693 ldap_contentrule_free(cr);
2699 * Beyond this point we will be liberal an accept the items
2703 kind = get_token(&ss,&sval);
2706 *code = LDAP_SCHERR_NORIGHTPAREN;
2708 ldap_contentrule_free(cr);
2713 if ( !strcmp(sval,"NAME") ) {
2716 *code = LDAP_SCHERR_DUPOPT;
2718 ldap_contentrule_free(cr);
2722 cr->cr_names = parse_qdescrs(&ss,code);
2723 if ( !cr->cr_names ) {
2724 if ( *code != LDAP_SCHERR_OUTOFMEM )
2725 *code = LDAP_SCHERR_BADNAME;
2727 ldap_contentrule_free(cr);
2730 } else if ( !strcmp(sval,"DESC") ) {
2733 *code = LDAP_SCHERR_DUPOPT;
2735 ldap_contentrule_free(cr);
2740 kind = get_token(&ss,&sval);
2741 if ( kind != TK_QDSTRING ) {
2742 *code = LDAP_SCHERR_UNEXPTOKEN;
2745 ldap_contentrule_free(cr);
2750 } else if ( !strcmp(sval,"OBSOLETE") ) {
2752 if ( seen_obsolete ) {
2753 *code = LDAP_SCHERR_DUPOPT;
2755 ldap_contentrule_free(cr);
2759 cr->cr_obsolete = LDAP_SCHEMA_YES;
2761 } else if ( !strcmp(sval,"AUX") ) {
2764 *code = LDAP_SCHERR_DUPOPT;
2766 ldap_contentrule_free(cr);
2770 cr->cr_oc_oids_aux = parse_oids(&ss,code,0);
2771 if ( !cr->cr_oc_oids_aux ) {
2773 ldap_contentrule_free(cr);
2777 } else if ( !strcmp(sval,"MUST") ) {
2780 *code = LDAP_SCHERR_DUPOPT;
2782 ldap_contentrule_free(cr);
2786 cr->cr_at_oids_must = parse_oids(&ss,code,0);
2787 if ( !cr->cr_at_oids_must ) {
2789 ldap_contentrule_free(cr);
2793 } else if ( !strcmp(sval,"MAY") ) {
2796 *code = LDAP_SCHERR_DUPOPT;
2798 ldap_contentrule_free(cr);
2802 cr->cr_at_oids_may = parse_oids(&ss,code,0);
2803 if ( !cr->cr_at_oids_may ) {
2805 ldap_contentrule_free(cr);
2809 } else if ( !strcmp(sval,"NOT") ) {
2812 *code = LDAP_SCHERR_DUPOPT;
2814 ldap_contentrule_free(cr);
2818 cr->cr_at_oids_not = parse_oids(&ss,code,0);
2819 if ( !cr->cr_at_oids_not ) {
2821 ldap_contentrule_free(cr);
2825 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
2826 /* Should be parse_qdstrings */
2827 ext_vals = parse_qdescrs(&ss, code);
2830 ldap_contentrule_free(cr);
2833 if ( add_extension(&cr->cr_extensions,
2835 *code = LDAP_SCHERR_OUTOFMEM;
2838 ldap_contentrule_free(cr);
2842 *code = LDAP_SCHERR_UNEXPTOKEN;
2845 ldap_contentrule_free(cr);
2850 *code = LDAP_SCHERR_UNEXPTOKEN;
2853 ldap_contentrule_free(cr);
2860 ldap_structurerule_free(LDAPStructureRule * sr)
2862 if (sr->sr_names) LDAP_VFREE(sr->sr_names);
2863 if (sr->sr_desc) LDAP_FREE(sr->sr_desc);
2864 if (sr->sr_nameform) LDAP_FREE(sr->sr_nameform);
2865 if (sr->sr_sup_ruleids) LDAP_FREE(sr->sr_sup_ruleids);
2866 free_extensions(sr->sr_extensions);
2871 ldap_str2structurerule( LDAP_CONST char * s,
2873 LDAP_CONST char ** errp,
2874 LDAP_CONST unsigned flags )
2877 const char * ss = s;
2881 int seen_obsolete = 0;
2882 int seen_nameform = 0;
2883 LDAPStructureRule * sr;
2885 const char * savepos;
2888 *code = LDAP_SCHERR_EMPTY;
2894 sr = LDAP_CALLOC(1,sizeof(LDAPStructureRule));
2897 *code = LDAP_SCHERR_OUTOFMEM;
2901 kind = get_token(&ss,&sval);
2902 if ( kind != TK_LEFTPAREN ) {
2903 *code = LDAP_SCHERR_NOLEFTPAREN;
2905 ldap_structurerule_free(sr);
2910 * Definitions MUST begin with a ruleid.
2914 ret = ldap_int_parse_ruleid(&ss,code,0,&sr->sr_ruleid);
2917 ldap_structurerule_free(sr);
2923 * Beyond this point we will be liberal an accept the items
2927 kind = get_token(&ss,&sval);
2930 *code = LDAP_SCHERR_NORIGHTPAREN;
2932 ldap_structurerule_free(sr);
2935 if( !seen_nameform ) {
2936 *code = LDAP_SCHERR_MISSING;
2937 ldap_structurerule_free(sr);
2942 if ( !strcmp(sval,"NAME") ) {
2945 *code = LDAP_SCHERR_DUPOPT;
2947 ldap_structurerule_free(sr);
2951 sr->sr_names = parse_qdescrs(&ss,code);
2952 if ( !sr->sr_names ) {
2953 if ( *code != LDAP_SCHERR_OUTOFMEM )
2954 *code = LDAP_SCHERR_BADNAME;
2956 ldap_structurerule_free(sr);
2959 } else if ( !strcmp(sval,"DESC") ) {
2962 *code = LDAP_SCHERR_DUPOPT;
2964 ldap_structurerule_free(sr);
2969 kind = get_token(&ss,&sval);
2970 if ( kind != TK_QDSTRING ) {
2971 *code = LDAP_SCHERR_UNEXPTOKEN;
2974 ldap_structurerule_free(sr);
2979 } else if ( !strcmp(sval,"OBSOLETE") ) {
2981 if ( seen_obsolete ) {
2982 *code = LDAP_SCHERR_DUPOPT;
2984 ldap_structurerule_free(sr);
2988 sr->sr_obsolete = LDAP_SCHEMA_YES;
2990 } else if ( !strcmp(sval,"FORM") ) {
2992 if ( seen_nameform ) {
2993 *code = LDAP_SCHERR_DUPOPT;
2995 ldap_structurerule_free(sr);
2999 sr->sr_nameform = parse_woid(&ss,code);
3000 if ( !sr->sr_nameform ) {
3002 ldap_structurerule_free(sr);
3006 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
3007 /* Should be parse_qdstrings */
3008 ext_vals = parse_qdescrs(&ss, code);
3011 ldap_structurerule_free(sr);
3014 if ( add_extension(&sr->sr_extensions,
3016 *code = LDAP_SCHERR_OUTOFMEM;
3019 ldap_structurerule_free(sr);
3023 *code = LDAP_SCHERR_UNEXPTOKEN;
3026 ldap_structurerule_free(sr);
3031 *code = LDAP_SCHERR_UNEXPTOKEN;
3034 ldap_structurerule_free(sr);
3041 ldap_nameform_free(LDAPNameForm * nf)
3043 LDAP_FREE(nf->nf_oid);
3044 if (nf->nf_names) LDAP_VFREE(nf->nf_names);
3045 if (nf->nf_desc) LDAP_FREE(nf->nf_desc);
3046 if (nf->nf_objectclass) LDAP_FREE(nf->nf_objectclass);
3047 if (nf->nf_at_oids_must) LDAP_VFREE(nf->nf_at_oids_must);
3048 if (nf->nf_at_oids_may) LDAP_VFREE(nf->nf_at_oids_may);
3049 free_extensions(nf->nf_extensions);
3054 ldap_str2nameform( LDAP_CONST char * s,
3056 LDAP_CONST char ** errp,
3057 LDAP_CONST unsigned flags )
3060 const char * ss = s;
3064 int seen_obsolete = 0;
3070 const char * savepos;
3073 *code = LDAP_SCHERR_EMPTY;
3079 nf = LDAP_CALLOC(1,sizeof(LDAPNameForm));
3082 *code = LDAP_SCHERR_OUTOFMEM;
3086 kind = get_token(&ss,&sval);
3087 if ( kind != TK_LEFTPAREN ) {
3088 *code = LDAP_SCHERR_NOLEFTPAREN;
3090 ldap_nameform_free(nf);
3095 * Definitions MUST begin with an OID in the numericoid format.
3096 * However, this routine is used by clients to parse the response
3097 * from servers and very well known servers will provide an OID
3098 * in the wrong format or even no OID at all. We do our best to
3099 * extract info from those servers.
3103 nf->nf_oid = ldap_int_parse_numericoid(&ss,code,0);
3104 if ( !nf->nf_oid ) {
3106 ldap_nameform_free(nf);
3112 * Beyond this point we will be liberal an accept the items
3116 kind = get_token(&ss,&sval);
3119 *code = LDAP_SCHERR_NORIGHTPAREN;
3121 ldap_nameform_free(nf);
3124 if( !seen_class || !seen_must ) {
3125 *code = LDAP_SCHERR_MISSING;
3126 ldap_nameform_free(nf);
3131 if ( !strcmp(sval,"NAME") ) {
3134 *code = LDAP_SCHERR_DUPOPT;
3136 ldap_nameform_free(nf);
3140 nf->nf_names = parse_qdescrs(&ss,code);
3141 if ( !nf->nf_names ) {
3142 if ( *code != LDAP_SCHERR_OUTOFMEM )
3143 *code = LDAP_SCHERR_BADNAME;
3145 ldap_nameform_free(nf);
3148 } else if ( !strcmp(sval,"DESC") ) {
3151 *code = LDAP_SCHERR_DUPOPT;
3153 ldap_nameform_free(nf);
3158 kind = get_token(&ss,&sval);
3159 if ( kind != TK_QDSTRING ) {
3160 *code = LDAP_SCHERR_UNEXPTOKEN;
3163 ldap_nameform_free(nf);
3168 } else if ( !strcmp(sval,"OBSOLETE") ) {
3170 if ( seen_obsolete ) {
3171 *code = LDAP_SCHERR_DUPOPT;
3173 ldap_nameform_free(nf);
3177 nf->nf_obsolete = LDAP_SCHEMA_YES;
3179 } else if ( !strcmp(sval,"MUST") ) {
3182 *code = LDAP_SCHERR_DUPOPT;
3184 ldap_nameform_free(nf);
3188 nf->nf_at_oids_must = parse_oids(&ss,code,0);
3189 if ( !nf->nf_at_oids_must ) {
3191 ldap_nameform_free(nf);
3195 } else if ( !strcmp(sval,"MAY") ) {
3198 *code = LDAP_SCHERR_DUPOPT;
3200 ldap_nameform_free(nf);
3204 nf->nf_at_oids_may = parse_oids(&ss,code,0);
3205 if ( !nf->nf_at_oids_may ) {
3207 ldap_nameform_free(nf);
3211 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
3212 /* Should be parse_qdstrings */
3213 ext_vals = parse_qdescrs(&ss, code);
3216 ldap_nameform_free(nf);
3219 if ( add_extension(&nf->nf_extensions,
3221 *code = LDAP_SCHERR_OUTOFMEM;
3224 ldap_nameform_free(nf);
3228 *code = LDAP_SCHERR_UNEXPTOKEN;
3231 ldap_nameform_free(nf);
3236 *code = LDAP_SCHERR_UNEXPTOKEN;
3239 ldap_nameform_free(nf);
3245 static char *const err2text[] = {
3247 N_("Out of memory"),
3248 N_("Unexpected token"),
3249 N_("Missing opening parenthesis"),
3250 N_("Missing closing parenthesis"),
3251 N_("Expecting digit"),
3252 N_("Expecting a name"),
3253 N_("Bad description"),
3254 N_("Bad superiors"),
3255 N_("Duplicate option"),
3256 N_("Unexpected end of data"),
3257 N_("Missing required field"),
3258 N_("Out of order field")
3262 ldap_scherr2str(int code)
3264 if ( code < 0 || code >= (int)(sizeof(err2text)/sizeof(char *)) ) {
3265 return _("Unknown error");
3267 return _(err2text[code]);