2 * Copyright 1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5 * schema.c: parsing routines used by servers and clients to process
12 #include <ac/stdlib.h>
15 #include <ac/string.h>
20 #include <ldap_schema.h>
23 * When pretty printing the entities we will be appending to a buffer.
24 * Since checking for overflow, realloc'ing and checking if no error
25 * is extremely boring, we will use a protection layer that will let
26 * us blissfully ignore the error until the end. This layer is
27 * implemented with the help of the next type.
30 typedef struct safe_string {
38 new_safe_string(int size)
42 ss = LDAP_MALLOC(sizeof(safe_string));
46 ss->val = LDAP_MALLOC(size);
60 safe_string_free(safe_string * ss)
69 safe_string_val(safe_string * ss)
71 ss->val[ss->pos] = '\0';
76 append_to_safe_string(safe_string * ss, char * s)
82 * Some runaway process is trying to append to a string that
83 * overflowed and we could not extend.
88 /* We always make sure there is at least one position available */
89 if ( ss->pos + l >= ss->size-1 ) {
91 temp = LDAP_REALLOC(ss->val, ss->size);
93 /* Trouble, out of memory */
99 strncpy(&ss->val[ss->pos], s, l);
101 if ( ss->pos > 0 && isspace(ss->val[ss->pos-1]) )
110 print_literal(safe_string *ss, char *s)
112 return(append_to_safe_string(ss,s));
116 print_whsp(safe_string *ss)
119 return(append_to_safe_string(ss,""));
121 return(append_to_safe_string(ss," "));
125 print_numericoid(safe_string *ss, char *s)
128 return(append_to_safe_string(ss,s));
131 /* This one is identical to print_qdescr */
133 print_qdstring(safe_string *ss, char *s)
136 print_literal(ss,"'");
137 append_to_safe_string(ss,s);
138 print_literal(ss,"'");
139 return(print_whsp(ss));
143 print_qdescr(safe_string *ss, char *s)
146 print_literal(ss,"'");
147 append_to_safe_string(ss,s);
148 print_literal(ss,"'");
149 return(print_whsp(ss));
153 print_qdescrlist(safe_string *ss, char **sa)
158 for (sp=sa; *sp; sp++) {
159 ret = print_qdescr(ss,*sp);
161 /* If the list was empty, we return zero that is potentially
162 * incorrect, but since we will be still appending things, the
163 * overflow will be detected later. Maybe FIX.
169 print_qdescrs(safe_string *ss, char **sa)
171 /* The only way to represent an empty list is as a qdescrlist
172 * so, if the list is empty we treat it as a long list.
173 * Really, this is what the syntax mandates. We should not
174 * be here if the list was empty, but if it happens, a label
175 * has already been output and we cannot undo it.
177 if ( !sa[0] || ( sa[0] && sa[1] ) ) {
179 print_literal(ss,"(");
180 print_qdescrlist(ss,sa);
181 print_literal(ss,")");
182 return(print_whsp(ss));
184 return(print_qdescr(ss,*sa));
189 print_woid(safe_string *ss, char *s)
192 append_to_safe_string(ss,s);
193 return print_whsp(ss);
197 print_oidlist(safe_string *ss, char **sa)
201 for (sp=sa; *(sp+1); sp++) {
203 print_literal(ss,"$");
205 return(print_woid(ss,*sp));
209 print_oids(safe_string *ss, char **sa)
211 if ( sa[0] && sa[1] ) {
212 print_literal(ss,"(");
213 print_oidlist(ss,sa);
215 return(print_literal(ss,")"));
217 return(print_woid(ss,*sa));
222 print_noidlen(safe_string *ss, char *s, int l)
227 ret = print_numericoid(ss,s);
229 sprintf(buf,"{%d}",l);
230 ret = print_literal(ss,buf);
236 ldap_syntax2str( LDAP_SYNTAX * syn )
241 ss = new_safe_string(256);
245 print_literal(ss,"(");
248 print_numericoid(ss, syn->syn_oid);
251 if ( syn->syn_desc ) {
252 print_literal(ss,"DESC");
253 print_qdstring(ss,syn->syn_desc);
257 print_literal(ss,")");
259 retstring = LDAP_STRDUP(safe_string_val(ss));
260 safe_string_free(ss);
265 ldap_objectclass2str( LDAP_OBJECT_CLASS * oc )
270 ss = new_safe_string(256);
274 print_literal(ss,"(");
277 print_numericoid(ss, oc->oc_oid);
280 if ( oc->oc_names ) {
281 print_literal(ss,"NAME");
282 print_qdescrs(ss,oc->oc_names);
286 print_literal(ss,"DESC");
287 print_qdstring(ss,oc->oc_desc);
290 if ( oc->oc_obsolete == LDAP_SCHEMA_YES ) {
291 print_literal(ss, "OBSOLETE");
295 if ( oc->oc_sup_oids ) {
296 print_literal(ss,"SUP");
298 print_oids(ss,oc->oc_sup_oids);
302 switch (oc->oc_kind) {
303 case LDAP_SCHEMA_ABSTRACT:
304 print_literal(ss,"ABSTRACT");
306 case LDAP_SCHEMA_STRUCTURAL:
307 print_literal(ss,"STRUCTURAL");
309 case LDAP_SCHEMA_AUXILIARY:
310 print_literal(ss,"AUXILIARY");
313 print_literal(ss,"KIND-UNKNOWN");
318 if ( oc->oc_at_oids_must ) {
319 print_literal(ss,"MUST");
321 print_oids(ss,oc->oc_at_oids_must);
325 if ( oc->oc_at_oids_may ) {
326 print_literal(ss,"MAY");
328 print_oids(ss,oc->oc_at_oids_may);
333 print_literal(ss,")");
335 retstring = LDAP_STRDUP(safe_string_val(ss));
336 safe_string_free(ss);
341 ldap_attributetype2str( LDAP_ATTRIBUTE_TYPE * at )
346 ss = new_safe_string(256);
350 print_literal(ss,"(");
353 print_numericoid(ss, at->at_oid);
356 if ( at->at_names ) {
357 print_literal(ss,"NAME");
358 print_qdescrs(ss,at->at_names);
362 print_literal(ss,"DESC");
363 print_qdstring(ss,at->at_desc);
366 if ( at->at_obsolete == LDAP_SCHEMA_YES ) {
367 print_literal(ss, "OBSOLETE");
371 if ( at->at_sup_oid ) {
372 print_literal(ss,"SUP");
373 print_woid(ss,at->at_sup_oid);
376 if ( at->at_equality_oid ) {
377 print_literal(ss,"EQUALITY");
378 print_woid(ss,at->at_equality_oid);
381 if ( at->at_ordering_oid ) {
382 print_literal(ss,"ORDERING");
383 print_woid(ss,at->at_ordering_oid);
386 if ( at->at_substr_oid ) {
387 print_literal(ss,"SUBSTR");
388 print_woid(ss,at->at_substr_oid);
391 if ( at->at_syntax_oid ) {
392 print_literal(ss,"SYNTAX");
394 print_noidlen(ss,at->at_syntax_oid,at->at_syntax_len);
398 if ( at->at_single_value == LDAP_SCHEMA_YES ) {
399 print_literal(ss,"SINGLE-VALUE");
403 if ( at->at_collective == LDAP_SCHEMA_YES ) {
404 print_literal(ss,"COLLECTIVE");
408 if ( at->at_no_user_mod == LDAP_SCHEMA_YES ) {
409 print_literal(ss,"NO-USER-MODIFICATION");
413 if ( at->at_usage != LDAP_SCHEMA_USER_APPLICATIONS ) {
414 print_literal(ss,"USAGE");
416 switch (at->at_usage) {
417 case LDAP_SCHEMA_DIRECTORY_OPERATION:
418 print_literal(ss,"directoryOperation");
420 case LDAP_SCHEMA_DISTRIBUTED_OPERATION:
421 print_literal(ss,"distributedOperation");
423 case LDAP_SCHEMA_DSA_OPERATION:
424 print_literal(ss,"dSAOperation");
427 print_literal(ss,"UNKNOWN");
433 print_literal(ss,")");
435 retstring = LDAP_STRDUP(safe_string_val(ss));
436 safe_string_free(ss);
441 * Now come the parsers. There is one parser for each entity type:
442 * objectclasses, attributetypes, etc.
444 * Each of them is written as a recursive-descent parser, except that
445 * none of them is really recursive. But the idea is kept: there
446 * is one routine per non-terminal that eithers gobbles lexical tokens
447 * or calls lower-level routines, etc.
449 * The scanner is implemented in the routine get_token. Actually,
450 * get_token is more than a scanner and will return tokens that are
451 * in fact non-terminals in the grammar. So you can see the whole
452 * approach as the combination of a low-level bottom-up recognizer
453 * combined with a scanner and a number of top-down parsers. Or just
454 * consider that the real grammars recognized by the parsers are not
455 * those of the standards. As a matter of fact, our parsers are more
456 * liberal than the spec when there is no ambiguity.
458 * The difference is pretty academic (modulo bugs or incorrect
459 * interpretation of the specs).
462 #define TK_NOENDQUOTE -2
463 #define TK_OUTOFMEM -1
465 #define TK_UNEXPCHAR 1
466 #define TK_BAREWORD 2
467 #define TK_QDSTRING 3
468 #define TK_LEFTPAREN 4
469 #define TK_RIGHTPAREN 5
471 #define TK_QDESCR TK_QDSTRING
479 get_token(char ** sp, char ** token_val)
496 kind = TK_RIGHTPAREN;
507 while ( **sp != '\'' && **sp != '\0' )
509 if ( **sp == '\'' ) {
511 res = LDAP_MALLOC(q-p+1);
521 kind = TK_NOENDQUOTE;
527 while ( !isspace(**sp) && **sp != '\0' )
530 res = LDAP_MALLOC(q-p+1);
539 /* kind = TK_UNEXPCHAR; */
546 /* Gobble optional whitespace */
548 parse_whsp(char **sp)
550 while (isspace(**sp))
555 * General note for all parsers: to guarantee the algorithm halts they
556 * must always advance the pointer even when an error is found. For
557 * this one is not that important since an error here is fatal at the
558 * upper layers, but it is a simple strategy that will not get in
562 /* Parse a sequence of dot-separated decimal strings */
564 parse_numericoid(char **sp, int *code)
570 /* Each iteration of this loop gets one decimal string */
572 if ( !isdigit(**sp) ) {
574 * Initial char is not a digit or char after dot is
577 *code = LDAP_SCHERR_NODIGIT;
581 while ( isdigit(**sp) )
585 /* Otherwise, gobble the dot and loop again */
588 /* Now *sp points at the char past the numericoid. Perfect. */
590 res = LDAP_MALLOC(len+1);
592 *code = LDAP_SCHERR_OUTOFMEM;
595 strncpy(res,start,len);
600 /* Parse a qdescr or a list of them enclosed in () */
602 parse_qdescrs(char **sp, int *code)
612 kind = get_token(sp,&sval);
613 if ( kind == TK_LEFTPAREN ) {
614 /* Let's presume there will be at least 2 entries */
616 res = LDAP_CALLOC(3,sizeof(char *));
618 *code = LDAP_SCHERR_OUTOFMEM;
624 kind = get_token(sp,&sval);
625 if ( kind == TK_RIGHTPAREN )
627 if ( kind == TK_QDESCR ) {
628 if ( pos == size-2 ) {
630 res1 = LDAP_REALLOC(res,size*sizeof(char *));
633 *code = LDAP_SCHERR_OUTOFMEM;
643 *code = LDAP_SCHERR_UNEXPTOKEN;
650 } else if ( kind == TK_QDESCR ) {
651 res = LDAP_CALLOC(2,sizeof(char *));
653 *code = LDAP_SCHERR_OUTOFMEM;
661 *code = LDAP_SCHERR_BADNAME;
668 parse_woid(char **sp, int *code)
674 kind = get_token(sp, &sval);
675 if ( kind != TK_BAREWORD ) {
676 *code = LDAP_SCHERR_UNEXPTOKEN;
683 /* Parse a noidlen */
685 parse_noidlen(char **sp, int *code, int *len)
691 sval = parse_numericoid(sp, code);
698 while ( isdigit(**sp) )
701 *code = LDAP_SCHERR_UNEXPTOKEN;
711 * Next routine will accept a qdstring in place of an oid. This is
712 * necessary to interoperate with Netscape Directory server that
713 * will improperly quote each oid (at least those of the descr kind)
717 /* Parse a woid or a $-separated list of them enclosed in () */
719 parse_oids(char **sp, int *code)
729 * Strictly speaking, doing this here accepts whsp before the
730 * ( at the begining of an oidlist, but this is harmless. Also,
731 * we are very liberal in what we accept as an OID. Maybe
735 kind = get_token(sp,&sval);
736 if ( kind == TK_LEFTPAREN ) {
737 /* Let's presume there will be at least 2 entries */
739 res = LDAP_CALLOC(3,sizeof(char *));
741 *code = LDAP_SCHERR_OUTOFMEM;
746 kind = get_token(sp,&sval);
747 if ( kind == TK_BAREWORD || kind == TK_QDSTRING ) {
751 *code = LDAP_SCHERR_UNEXPTOKEN;
757 kind = get_token(sp,&sval);
758 if ( kind == TK_RIGHTPAREN )
760 if ( kind == TK_DOLLAR ) {
762 kind = get_token(sp,&sval);
763 if ( kind == TK_BAREWORD ||
764 kind == TK_QDSTRING ) {
765 if ( pos == size-2 ) {
767 res1 = LDAP_REALLOC(res,size*sizeof(char *));
770 *code = LDAP_SCHERR_OUTOFMEM;
778 *code = LDAP_SCHERR_UNEXPTOKEN;
784 *code = LDAP_SCHERR_UNEXPTOKEN;
792 } else if ( kind == TK_BAREWORD || kind == TK_QDSTRING ) {
793 res = LDAP_CALLOC(2,sizeof(char *));
795 *code = LDAP_SCHERR_OUTOFMEM;
803 *code = LDAP_SCHERR_BADNAME;
809 ldap_syntax_free(LDAP_SYNTAX * syn)
811 LDAP_FREE(syn->syn_oid);
812 LDAP_FREE(syn->syn_desc);
817 ldap_str2syntax( char * s, int * code, char ** errp )
827 *code = LDAP_SCHERR_EMPTY;
833 syn = LDAP_CALLOC(1,sizeof(LDAP_SYNTAX));
836 *code = LDAP_SCHERR_OUTOFMEM;
840 kind = get_token(&ss,&sval);
841 if ( kind != TK_LEFTPAREN ) {
842 *code = LDAP_SCHERR_NOLEFTPAREN;
843 ldap_syntax_free(syn);
848 syn->syn_oid = parse_numericoid(&ss,code);
849 if ( !syn->syn_oid ) {
851 ldap_syntax_free(syn);
857 * Beyond this point we will be liberal and accept the items
861 kind = get_token(&ss,&sval);
864 *code = LDAP_SCHERR_NORIGHTPAREN;
866 ldap_syntax_free(syn);
871 if ( !strcmp(sval,"DESC") ) {
873 *code = LDAP_SCHERR_DUPOPT;
875 ldap_syntax_free(syn);
880 kind = get_token(&ss,&sval);
881 if ( kind != TK_QDSTRING ) {
882 *code = LDAP_SCHERR_UNEXPTOKEN;
884 ldap_syntax_free(syn);
887 syn->syn_desc = sval;
889 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
890 /* Should be parse_qdstrings */
891 ssdummy = parse_qdescrs(&ss, code);
894 ldap_syntax_free(syn);
898 *code = LDAP_SCHERR_UNEXPTOKEN;
900 ldap_syntax_free(syn);
905 *code = LDAP_SCHERR_UNEXPTOKEN;
907 ldap_syntax_free(syn);
914 ldap_attributetype_free(LDAP_ATTRIBUTE_TYPE * at)
916 LDAP_FREE(at->at_oid);
917 LDAP_VFREE(at->at_names);
918 LDAP_FREE(at->at_desc);
919 LDAP_FREE(at->at_sup_oid);
920 LDAP_FREE(at->at_equality_oid);
921 LDAP_FREE(at->at_ordering_oid);
922 LDAP_FREE(at->at_substr_oid);
923 LDAP_FREE(at->at_syntax_oid);
927 LDAP_ATTRIBUTE_TYPE *
928 ldap_str2attributetype( char * s, int * code, char ** errp )
933 int be_liberal = 1; /* Future additional argument */
936 int seen_obsolete = 0;
938 int seen_equality = 0;
939 int seen_ordering = 0;
946 LDAP_ATTRIBUTE_TYPE * at;
951 *code = LDAP_SCHERR_EMPTY;
957 at = LDAP_CALLOC(1,sizeof(LDAP_ATTRIBUTE_TYPE));
960 *code = LDAP_SCHERR_OUTOFMEM;
964 kind = get_token(&ss,&sval);
965 if ( kind != TK_LEFTPAREN ) {
966 *code = LDAP_SCHERR_NOLEFTPAREN;
967 ldap_attributetype_free(at);
972 * Definitions MUST begin with an OID in the numericoid format.
973 * However, this routine is used by clients to parse the response
974 * from servers and very well known servers will provide an OID
975 * in the wrong format or even no OID at all. We do our best to
976 * extract info from those servers.
980 at->at_oid = parse_numericoid(&ss,code);
985 kind = get_token(&ss,&sval);
986 if ( kind == TK_BAREWORD ) {
987 if ( !strcmp(sval, "NAME") ||
988 !strcmp(sval, "DESC") ||
989 !strcmp(sval, "OBSOLETE") ||
990 !strcmp(sval, "SUP") ||
991 !strcmp(sval, "EQUALITY") ||
992 !strcmp(sval, "ORDERING") ||
993 !strcmp(sval, "SUBSTR") ||
994 !strcmp(sval, "SYNTAX") ||
995 !strcmp(sval, "SINGLE-VALUE") ||
996 !strcmp(sval, "COLLECTIVE") ||
997 !strcmp(sval, "NO-USER-MODIFICATION") ||
998 !strcmp(sval, "USAGE") ||
999 !strncmp(sval, "X-", 2) ) {
1000 /* Missing OID, backtrack */
1003 /* Non-numerical OID, ignore */
1008 ldap_attributetype_free(at);
1015 * Beyond this point we will be liberal and accept the items
1019 kind = get_token(&ss,&sval);
1022 *code = LDAP_SCHERR_NORIGHTPAREN;
1024 ldap_attributetype_free(at);
1029 if ( !strcmp(sval,"NAME") ) {
1031 *code = LDAP_SCHERR_DUPOPT;
1033 ldap_attributetype_free(at);
1037 at->at_names = parse_qdescrs(&ss,code);
1038 if ( !at->at_names ) {
1039 if ( *code != LDAP_SCHERR_OUTOFMEM )
1040 *code = LDAP_SCHERR_BADNAME;
1042 ldap_attributetype_free(at);
1045 } else if ( !strcmp(sval,"DESC") ) {
1047 *code = LDAP_SCHERR_DUPOPT;
1049 ldap_attributetype_free(at);
1054 kind = get_token(&ss,&sval);
1055 if ( kind != TK_QDSTRING ) {
1056 *code = LDAP_SCHERR_UNEXPTOKEN;
1058 ldap_attributetype_free(at);
1063 } else if ( !strcmp(sval,"OBSOLETE") ) {
1064 if ( seen_obsolete ) {
1065 *code = LDAP_SCHERR_DUPOPT;
1067 ldap_attributetype_free(at);
1071 at->at_obsolete = LDAP_SCHEMA_YES;
1073 } else if ( !strcmp(sval,"SUP") ) {
1075 *code = LDAP_SCHERR_DUPOPT;
1077 ldap_attributetype_free(at);
1081 at->at_sup_oid = parse_woid(&ss,code);
1082 if ( !at->at_sup_oid ) {
1084 ldap_attributetype_free(at);
1087 } else if ( !strcmp(sval,"EQUALITY") ) {
1088 if ( seen_equality ) {
1089 *code = LDAP_SCHERR_DUPOPT;
1091 ldap_attributetype_free(at);
1095 at->at_equality_oid = parse_woid(&ss,code);
1096 if ( !at->at_equality_oid ) {
1098 ldap_attributetype_free(at);
1101 } else if ( !strcmp(sval,"ORDERING") ) {
1102 if ( seen_ordering ) {
1103 *code = LDAP_SCHERR_DUPOPT;
1105 ldap_attributetype_free(at);
1109 at->at_ordering_oid = parse_woid(&ss,code);
1110 if ( !at->at_ordering_oid ) {
1112 ldap_attributetype_free(at);
1115 } else if ( !strcmp(sval,"SUBSTR") ) {
1116 if ( seen_substr ) {
1117 *code = LDAP_SCHERR_DUPOPT;
1119 ldap_attributetype_free(at);
1123 at->at_substr_oid = parse_woid(&ss,code);
1124 if ( !at->at_substr_oid ) {
1126 ldap_attributetype_free(at);
1129 } else if ( !strcmp(sval,"SYNTAX") ) {
1130 if ( seen_syntax ) {
1131 *code = LDAP_SCHERR_DUPOPT;
1133 ldap_attributetype_free(at);
1138 at->at_syntax_oid = parse_noidlen(&ss,code,&at->at_syntax_len);
1139 if ( !at->at_syntax_oid ) {
1141 ldap_attributetype_free(at);
1145 } else if ( !strcmp(sval,"SINGLE-VALUE") ) {
1146 if ( at->at_single_value ) {
1147 *code = LDAP_SCHERR_DUPOPT;
1149 ldap_attributetype_free(at);
1152 at->at_single_value = LDAP_SCHEMA_YES;
1154 } else if ( !strcmp(sval,"COLLECTIVE") ) {
1155 if ( at->at_collective ) {
1156 *code = LDAP_SCHERR_DUPOPT;
1158 ldap_attributetype_free(at);
1161 at->at_collective = LDAP_SCHEMA_YES;
1163 } else if ( !strcmp(sval,"NO-USER-MODIFICATION") ) {
1164 if ( at->at_no_user_mod ) {
1165 *code = LDAP_SCHERR_DUPOPT;
1167 ldap_attributetype_free(at);
1170 at->at_no_user_mod = LDAP_SCHEMA_YES;
1172 } else if ( !strcmp(sval,"USAGE") ) {
1174 *code = LDAP_SCHERR_DUPOPT;
1176 ldap_attributetype_free(at);
1181 kind = get_token(&ss,&sval);
1182 if ( kind != TK_BAREWORD ) {
1183 *code = LDAP_SCHERR_UNEXPTOKEN;
1185 ldap_attributetype_free(at);
1188 if ( !strcasecmp(sval,"userApplications") )
1190 LDAP_SCHEMA_USER_APPLICATIONS;
1191 else if ( !strcasecmp(sval,"directoryOperation") )
1193 LDAP_SCHEMA_DIRECTORY_OPERATION;
1194 else if ( !strcasecmp(sval,"distributedOperation") )
1196 LDAP_SCHEMA_DISTRIBUTED_OPERATION;
1197 else if ( !strcasecmp(sval,"dSAOperation") )
1199 LDAP_SCHEMA_DSA_OPERATION;
1201 *code = LDAP_SCHERR_UNEXPTOKEN;
1203 ldap_attributetype_free(at);
1207 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1208 /* Should be parse_qdstrings */
1209 ssdummy = parse_qdescrs(&ss, code);
1212 ldap_attributetype_free(at);
1216 *code = LDAP_SCHERR_UNEXPTOKEN;
1218 ldap_attributetype_free(at);
1223 *code = LDAP_SCHERR_UNEXPTOKEN;
1225 ldap_attributetype_free(at);
1232 ldap_objectclass_free(LDAP_OBJECT_CLASS * oc)
1234 LDAP_FREE(oc->oc_oid);
1235 LDAP_VFREE(oc->oc_names);
1236 LDAP_FREE(oc->oc_desc);
1237 LDAP_VFREE(oc->oc_sup_oids);
1238 LDAP_VFREE(oc->oc_at_oids_must);
1239 LDAP_VFREE(oc->oc_at_oids_may);
1244 ldap_str2objectclass( char * s, int * code, char ** errp )
1249 int be_liberal = 1; /* Future additional argument */
1252 int seen_obsolete = 0;
1257 LDAP_OBJECT_CLASS * oc;
1262 *code = LDAP_SCHERR_EMPTY;
1268 oc = LDAP_CALLOC(1,sizeof(LDAP_OBJECT_CLASS));
1271 *code = LDAP_SCHERR_OUTOFMEM;
1275 kind = get_token(&ss,&sval);
1276 if ( kind != TK_LEFTPAREN ) {
1277 *code = LDAP_SCHERR_NOLEFTPAREN;
1278 ldap_objectclass_free(oc);
1283 * Definitions MUST begin with an OID in the numericoid format.
1284 * However, this routine is used by clients to parse the response
1285 * from servers and very well known servers will provide an OID
1286 * in the wrong format or even no OID at all. We do our best to
1287 * extract info from those servers.
1290 oc->oc_oid = parse_numericoid(&ss,code);
1291 if ( !oc->oc_oid ) {
1295 kind = get_token(&ss,&sval);
1296 if ( kind == TK_BAREWORD ) {
1297 if ( !strcmp(sval, "NAME") ||
1298 !strcmp(sval, "DESC") ||
1299 !strcmp(sval, "OBSOLETE") ||
1300 !strcmp(sval, "SUP") ||
1301 !strcmp(sval, "ABSTRACT") ||
1302 !strcmp(sval, "STRUCTURAL") ||
1303 !strcmp(sval, "AUXILIARY") ||
1304 !strcmp(sval, "MUST") ||
1305 !strncmp(sval, "X-", 2) ) {
1306 /* Missing OID, backtrack */
1309 /* Non-numerical OID, ignore */
1314 ldap_objectclass_free(oc);
1321 * Beyond this point we will be liberal an accept the items
1325 kind = get_token(&ss,&sval);
1328 *code = LDAP_SCHERR_NORIGHTPAREN;
1330 ldap_objectclass_free(oc);
1335 if ( !strcmp(sval,"NAME") ) {
1337 *code = LDAP_SCHERR_DUPOPT;
1339 ldap_objectclass_free(oc);
1343 oc->oc_names = parse_qdescrs(&ss,code);
1344 if ( !oc->oc_names ) {
1345 if ( *code != LDAP_SCHERR_OUTOFMEM )
1346 *code = LDAP_SCHERR_BADNAME;
1348 ldap_objectclass_free(oc);
1351 } else if ( !strcmp(sval,"DESC") ) {
1353 *code = LDAP_SCHERR_DUPOPT;
1355 ldap_objectclass_free(oc);
1360 kind = get_token(&ss,&sval);
1361 if ( kind != TK_QDSTRING ) {
1362 *code = LDAP_SCHERR_UNEXPTOKEN;
1364 ldap_objectclass_free(oc);
1369 } else if ( !strcmp(sval,"OBSOLETE") ) {
1370 if ( seen_obsolete ) {
1371 *code = LDAP_SCHERR_DUPOPT;
1373 ldap_objectclass_free(oc);
1377 oc->oc_obsolete = LDAP_SCHEMA_YES;
1379 } else if ( !strcmp(sval,"SUP") ) {
1381 *code = LDAP_SCHERR_DUPOPT;
1383 ldap_objectclass_free(oc);
1387 oc->oc_sup_oids = parse_oids(&ss,code);
1388 if ( !oc->oc_sup_oids ) {
1390 ldap_objectclass_free(oc);
1393 } else if ( !strcmp(sval,"ABSTRACT") ) {
1395 *code = LDAP_SCHERR_DUPOPT;
1397 ldap_objectclass_free(oc);
1401 oc->oc_kind = LDAP_SCHEMA_ABSTRACT;
1403 } else if ( !strcmp(sval,"STRUCTURAL") ) {
1405 *code = LDAP_SCHERR_DUPOPT;
1407 ldap_objectclass_free(oc);
1411 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
1413 } else if ( !strcmp(sval,"AUXILIARY") ) {
1415 *code = LDAP_SCHERR_DUPOPT;
1417 ldap_objectclass_free(oc);
1421 oc->oc_kind = LDAP_SCHEMA_AUXILIARY;
1423 } else if ( !strcmp(sval,"MUST") ) {
1425 *code = LDAP_SCHERR_DUPOPT;
1427 ldap_objectclass_free(oc);
1431 oc->oc_at_oids_must = parse_oids(&ss,code);
1432 if ( !oc->oc_at_oids_must ) {
1434 ldap_objectclass_free(oc);
1438 } else if ( !strcmp(sval,"MAY") ) {
1440 *code = LDAP_SCHERR_DUPOPT;
1442 ldap_objectclass_free(oc);
1446 oc->oc_at_oids_may = parse_oids(&ss,code);
1447 if ( !oc->oc_at_oids_may ) {
1449 ldap_objectclass_free(oc);
1453 } else if ( sval[0] == 'X' && sval[1] == '-' ) {
1454 /* Should be parse_qdstrings */
1455 ssdummy = parse_qdescrs(&ss, code);
1458 ldap_objectclass_free(oc);
1462 *code = LDAP_SCHERR_UNEXPTOKEN;
1464 ldap_objectclass_free(oc);
1469 *code = LDAP_SCHERR_UNEXPTOKEN;
1471 ldap_objectclass_free(oc);
1477 static char *err2text[] = {
1481 "Missing opening parenthesis",
1482 "Missing closing parenthesis",
1488 "Unexpected end of data"
1492 ldap_scherr2str(int code)
1494 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
1495 return "Unknown error";
1497 return err2text[code];