typedef struct ldap_syntax {
char *syn_oid; /* REQUIRED */
+ char **syn_names; /* OPTIONAL */
char *syn_desc; /* OPTIONAL */
LDAP_SCHEMA_EXTENSION_ITEM **syn_extensions; /* OPTIONAL */
} LDAP_SYNTAX;
#define LDAP_SCHEMA_STRUCTURAL 1
#define LDAP_SCHEMA_AUXILIARY 2
+/*
+ * Flags that control how liberal the parsing routines are.
+ */
+#define LDAP_SCHEMA_ALLOW_NONE 0x00 /* Strict parsing */
+#define LDAP_SCHEMA_ALLOW_NO_OID 0x01 /* Allow missing oid */
+#define LDAP_SCHEMA_ALLOW_QUOTED 0x02 /* Allow bogus extra quotes */
+#define LDAP_SCHEMA_ALLOW_DESCR 0x04 /* Allow descr instead of OID */
+#define LDAP_SCHEMA_ALLOW_DESCR_PREFIX 0x08 /* Allow descr as OID prefix */
+#define LDAP_SCHEMA_ALLOW_ALL 0x0f /* Be very liberal in parsing */
+
LIBLDAP_F( LDAP_CONST char * )
ldap_syntax2name LDAP_P((
LDAP_SYNTAX * syn ));
ldap_str2objectclass LDAP_P((
LDAP_CONST char * s,
int * code,
- LDAP_CONST char ** errp ));
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags ));
LIBLDAP_F( LDAP_ATTRIBUTE_TYPE * )
ldap_str2attributetype LDAP_P((
LDAP_CONST char * s,
int * code,
- LDAP_CONST char ** errp ));
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags ));
LIBLDAP_F( LDAP_SYNTAX * )
ldap_str2syntax LDAP_P((
LDAP_CONST char * s,
int * code,
- LDAP_CONST char ** errp ));
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags ));
LIBLDAP_F( LDAP_MATCHING_RULE * )
ldap_str2matchingrule LDAP_P((
LDAP_CONST char * s,
int * code,
- LDAP_CONST char ** errp ));
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags ));
LIBLDAP_F( char *)
ldap_objectclass2str LDAP_P((
#include <ldap_schema.h>
-
static LDAP_CONST char *
choose_name( char *names[], LDAP_CONST char *fallback )
{
/* Parse a sequence of dot-separated decimal strings */
static char *
-parse_numericoid(const char **sp, int *code, const int allow_quoted)
+parse_numericoid(const char **sp, int *code, const int flags)
{
char * res;
const char * start = *sp;
int quoted = 0;
/* Netscape puts the SYNTAX value in quotes (incorrectly) */
- if ( allow_quoted && **sp == '\'' ) {
+ if ( flags & LDAP_SCHEMA_ALLOW_QUOTED && **sp == '\'' ) {
quoted = 1;
(*sp)++;
start++;
}
strncpy(res,start,len);
res[len] = '\0';
- if ( allow_quoted && quoted ) {
+ if ( flags & LDAP_SCHEMA_ALLOW_QUOTED && quoted ) {
if ( **sp == '\'' ) {
(*sp)++;
} else {
}
LDAP_SYNTAX *
-ldap_str2syntax( const char * s, int * code, const char ** errp )
+ldap_str2syntax( const char * s, int * code, const char ** errp, const int flags )
{
int kind;
const char * ss = s;
char * sval;
+ int seen_name = 0;
int seen_desc = 0;
LDAP_SYNTAX * syn;
char ** ext_vals;
case TK_RIGHTPAREN:
return syn;
case TK_BAREWORD:
- if ( !strcmp(sval,"DESC") ) {
+ if ( !strcmp(sval,"NAME") ) {
+ LDAP_FREE(sval);
+ if ( seen_name ) {
+ *code = LDAP_SCHERR_DUPOPT;
+ *errp = ss;
+ ldap_syntax_free(syn);
+ return(NULL);
+ }
+ seen_name = 1;
+ syn->syn_names = parse_qdescrs(&ss,code);
+ if ( !syn->syn_names ) {
+ if ( *code != LDAP_SCHERR_OUTOFMEM )
+ *code = LDAP_SCHERR_BADNAME;
+ *errp = ss;
+ ldap_syntax_free(syn);
+ return NULL;
+ }
+ } else if ( !strcmp(sval,"DESC") ) {
LDAP_FREE(sval);
if ( seen_desc ) {
*code = LDAP_SCHERR_DUPOPT;
}
LDAP_MATCHING_RULE *
-ldap_str2matchingrule( const char * s, int * code, const char ** errp )
+ldap_str2matchingrule( const char * s, int * code, const char ** errp, const int flags )
{
int kind;
const char * ss = s;
char * sval;
- int be_liberal = 1; /* Future additional argument */
int seen_name = 0;
int seen_desc = 0;
int seen_obsolete = 0;
parse_whsp(&ss);
savepos = ss;
- mr->mr_oid = parse_numericoid(&ss,code,be_liberal);
+ mr->mr_oid = parse_numericoid(&ss,code,flags);
if ( !mr->mr_oid ) {
- if ( be_liberal ) {
+ if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
/* Backtracking */
ss = savepos;
kind = get_token(&ss,&sval);
seen_syntax = 1;
parse_whsp(&ss);
mr->mr_syntax_oid =
- parse_numericoid(&ss,code,be_liberal);
+ parse_numericoid(&ss,code,flags);
if ( !mr->mr_syntax_oid ) {
*errp = ss;
ldap_matchingrule_free(mr);
}
LDAP_ATTRIBUTE_TYPE *
-ldap_str2attributetype( const char * s, int * code, const char ** errp )
+ldap_str2attributetype( const char * s, int * code, const char ** errp, const int flags )
{
int kind;
const char * ss = s;
char * sval;
- int be_liberal = 1; /* Future additional argument */
int seen_name = 0;
int seen_desc = 0;
int seen_obsolete = 0;
savepos = ss;
at->at_oid = parse_numericoid(&ss,code,0);
if ( !at->at_oid ) {
- if ( be_liberal ) {
+ if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
/* Backtracking */
ss = savepos;
kind = get_token(&ss,&sval);
parse_noidlen(&ss,
code,
&at->at_syntax_len,
- be_liberal);
+ flags);
if ( !at->at_syntax_oid ) {
*errp = ss;
ldap_attributetype_free(at);
}
LDAP_OBJECT_CLASS *
-ldap_str2objectclass( const char * s, int * code, const char ** errp )
+ldap_str2objectclass( const char * s, int * code, const char ** errp, const int flags )
{
int kind;
const char * ss = s;
char * sval;
- int be_liberal = 1; /* Future additional argument */
int seen_name = 0;
int seen_desc = 0;
int seen_obsolete = 0;
savepos = ss;
oc->oc_oid = parse_numericoid(&ss,code,0);
if ( !oc->oc_oid ) {
- if ( be_liberal ) {
+ if ( flags & LDAP_SCHEMA_ALLOW_ALL ) {
/* Backtracking */
ss = savepos;
kind = get_token(&ss,&sval);
seen_sup = 1;
oc->oc_sup_oids = parse_oids(&ss,
code,
- be_liberal);
+ flags);
if ( !oc->oc_sup_oids ) {
*errp = ss;
ldap_objectclass_free(oc);
const char *err;
char *oid = NULL;
- oc = ldap_str2objectclass(line,&code,&err);
+ oc = ldap_str2objectclass(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
if ( !oc ) {
fprintf( stderr, "%s: line %d: %s before %s\n",
fname, lineno, ldap_scherr2str(code), err );
break;
}
}
- at = ldap_str2attributetype(line,&code,&err);
+ at = ldap_str2attributetype(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
if ( !at ) {
fprintf( stderr, "%s: line %d: %s before %s\n",
fname, lineno, ldap_scherr2str(code), err );