#include <ldap_schema.h>
-static LDAP_CONST char *
-choose_name( char *names[], LDAP_CONST char *fallback )
+static const char *
+choose_name( char *names[], const char *fallback )
{
return( (names != NULL && names[0] != NULL) ? names[0] : fallback );
}
return(ss->val);
}
+static char *
+safe_strdup(safe_string * ss)
+{
+ char *ret = LDAP_MALLOC(ss->pos+1);
+ if (!ret)
+ return NULL;
+ AC_MEMCPY(ret, ss->val, ss->pos);
+ ret[ss->pos] = '\0';
+ return ret;
+}
+
static int
append_to_safe_string(safe_string * ss, char * s)
{
/* We always make sure there is at least one position available */
if ( ss->pos + l >= ss->size-1 ) {
ss->size *= 2;
+ if ( ss->pos + l >= ss->size-1 ) {
+ ss->size = ss->pos + l + 1;
+ }
+
temp = LDAP_REALLOC(ss->val, ss->size);
if ( !temp ) {
/* Trouble, out of memory */
}
char *
-ldap_syntax2str( const LDAPSyntax * syn )
+ldap_syntax2str( LDAPSyntax * syn )
+{
+ struct berval bv;
+ if (ldap_syntax2bv( syn, &bv ))
+ return(bv.bv_val);
+ else
+ return NULL;
+}
+
+struct berval *
+ldap_syntax2bv( LDAPSyntax * syn, struct berval *bv )
{
safe_string * ss;
- char * retstring;
ss = new_safe_string(256);
if ( !ss )
print_literal(ss,/*(*/ ")");
- retstring = LDAP_STRDUP(safe_string_val(ss));
+ bv->bv_val = safe_strdup(ss);
+ bv->bv_len = ss->pos;
safe_string_free(ss);
- return(retstring);
+ return(bv);
}
char *
-ldap_matchingrule2str( const LDAPMatchingRule * mr )
+ldap_matchingrule2str( LDAPMatchingRule * mr )
+{
+ struct berval bv;
+ if (ldap_matchingrule2bv( mr, &bv ))
+ return(bv.bv_val);
+ else
+ return NULL;
+}
+
+struct berval *
+ldap_matchingrule2bv( LDAPMatchingRule * mr, struct berval *bv )
{
safe_string * ss;
- char * retstring;
ss = new_safe_string(256);
if ( !ss )
print_literal(ss,/*(*/")");
- retstring = LDAP_STRDUP(safe_string_val(ss));
+ bv->bv_val = safe_strdup(ss);
+ bv->bv_len = ss->pos;
safe_string_free(ss);
- return(retstring);
+ return(bv);
}
char *
-ldap_matchingruleuse2str( const LDAPMatchingRuleUse * mru )
+ldap_matchingruleuse2str( LDAPMatchingRuleUse * mru )
+{
+ struct berval bv;
+ if (ldap_matchingruleuse2bv( mru, &bv ))
+ return(bv.bv_val);
+ else
+ return NULL;
+}
+
+struct berval *
+ldap_matchingruleuse2bv( LDAPMatchingRuleUse * mru, struct berval *bv )
{
safe_string * ss;
- char * retstring;
ss = new_safe_string(256);
if ( !ss )
print_literal(ss,/*(*/")");
- retstring = LDAP_STRDUP(safe_string_val(ss));
+ bv->bv_val = safe_strdup(ss);
+ bv->bv_len = ss->pos;
safe_string_free(ss);
- return(retstring);
+ return(bv);
}
char *
-ldap_objectclass2str( const LDAPObjectClass * oc )
+ldap_objectclass2str( LDAPObjectClass * oc )
+{
+ struct berval bv;
+ if (ldap_objectclass2bv( oc, &bv ))
+ return(bv.bv_val);
+ else
+ return NULL;
+}
+
+struct berval *
+ldap_objectclass2bv( LDAPObjectClass * oc, struct berval *bv )
{
safe_string * ss;
- char * retstring;
ss = new_safe_string(256);
if ( !ss )
print_literal(ss, /*(*/")");
- retstring = LDAP_STRDUP(safe_string_val(ss));
+ bv->bv_val = safe_strdup(ss);
+ bv->bv_len = ss->pos;
safe_string_free(ss);
- return(retstring);
+ return(bv);
}
char *
-ldap_attributetype2str( const LDAPAttributeType * at )
+ldap_attributetype2str( LDAPAttributeType * at )
+{
+ struct berval bv;
+ if (ldap_attributetype2bv( at, &bv ))
+ return(bv.bv_val);
+ else
+ return NULL;
+}
+
+struct berval *
+ldap_attributetype2bv( LDAPAttributeType * at, struct berval *bv )
{
safe_string * ss;
- char * retstring;
ss = new_safe_string(256);
if ( !ss )
print_literal(ss,/*(*/")");
- retstring = LDAP_STRDUP(safe_string_val(ss));
+ bv->bv_val = safe_strdup(ss);
+ bv->bv_len = ss->pos;
safe_string_free(ss);
- return(retstring);
+ return(bv);
}
/*
};
static int
-get_token(const char ** sp, char ** token_val)
+get_token( const char ** sp, char ** token_val )
{
int kind;
const char * p;
*/
/* Parse a sequence of dot-separated decimal strings */
-static char *
-parse_numericoid(const char **sp, int *code, const int flags)
+char *
+ldap_int_parse_numericoid(const char **sp, int *code, const int flags)
{
- char * res;
+ char * res = NULL;
const char * start = *sp;
int len;
int quoted = 0;
}
/* Now *sp points at the char past the numericoid. Perfect. */
len = *sp - start;
- res = LDAP_MALLOC(len+1);
- if (!res) {
- *code = LDAP_SCHERR_OUTOFMEM;
- return(NULL);
- }
- strncpy(res,start,len);
- res[len] = '\0';
if ( flags & LDAP_SCHEMA_ALLOW_QUOTED && quoted ) {
if ( **sp == '\'' ) {
(*sp)++;
} else {
*code = LDAP_SCHERR_UNEXPTOKEN;
- LDAP_FREE(res);
return NULL;
}
}
+ if (flags & LDAP_SCHEMA_SKIP) {
+ res = (char *)start;
+ } else {
+ res = LDAP_MALLOC(len+1);
+ if (!res) {
+ *code = LDAP_SCHERR_OUTOFMEM;
+ return(NULL);
+ }
+ strncpy(res,start,len);
+ res[len] = '\0';
+ }
return(res);
}
quoted = 1;
(*sp)++;
}
- sval = parse_numericoid(sp, code, 0);
+ sval = ldap_int_parse_numericoid(sp, code, 0);
if ( !sval ) {
return NULL;
}
ldap_syntax_free( LDAPSyntax * syn )
{
LDAP_FREE(syn->syn_oid);
- LDAP_VFREE(syn->syn_names);
- LDAP_FREE(syn->syn_desc);
+ if (syn->syn_names) LDAP_VFREE(syn->syn_names);
+ if (syn->syn_desc) LDAP_FREE(syn->syn_desc);
free_extensions(syn->syn_extensions);
LDAP_FREE(syn);
}
LDAPSyntax *
-ldap_str2syntax( const char * s, int * code, const char ** errp, const int flags )
+ldap_str2syntax( LDAP_CONST char * s,
+ int * code,
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags )
{
int kind;
const char * ss = s;
}
parse_whsp(&ss);
- syn->syn_oid = parse_numericoid(&ss,code,0);
+ syn->syn_oid = ldap_int_parse_numericoid(&ss,code,0);
if ( !syn->syn_oid ) {
*errp = ss;
ldap_syntax_free(syn);
ldap_matchingrule_free( LDAPMatchingRule * mr )
{
LDAP_FREE(mr->mr_oid);
- LDAP_VFREE(mr->mr_names);
- LDAP_FREE(mr->mr_desc);
- LDAP_FREE(mr->mr_syntax_oid);
+ if (mr->mr_names) LDAP_VFREE(mr->mr_names);
+ if (mr->mr_desc) LDAP_FREE(mr->mr_desc);
+ if (mr->mr_syntax_oid) LDAP_FREE(mr->mr_syntax_oid);
free_extensions(mr->mr_extensions);
LDAP_FREE(mr);
}
LDAPMatchingRule *
-ldap_str2matchingrule( const char * s, int * code, const char ** errp, const int flags )
+ldap_str2matchingrule( LDAP_CONST char * s,
+ int * code,
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags )
{
int kind;
const char * ss = s;
parse_whsp(&ss);
savepos = ss;
- mr->mr_oid = parse_numericoid(&ss,code,flags);
+ mr->mr_oid = ldap_int_parse_numericoid(&ss,code,flags);
if ( !mr->mr_oid ) {
if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
/* Backtracking */
seen_syntax = 1;
parse_whsp(&ss);
mr->mr_syntax_oid =
- parse_numericoid(&ss,code,flags);
+ ldap_int_parse_numericoid(&ss,code,flags);
if ( !mr->mr_syntax_oid ) {
*errp = ss;
ldap_matchingrule_free(mr);
ldap_matchingruleuse_free( LDAPMatchingRuleUse * mru )
{
LDAP_FREE(mru->mru_oid);
- LDAP_VFREE(mru->mru_names);
- LDAP_FREE(mru->mru_desc);
- LDAP_VFREE(mru->mru_applies_oids);
+ if (mru->mru_names) LDAP_VFREE(mru->mru_names);
+ if (mru->mru_desc) LDAP_FREE(mru->mru_desc);
+ if (mru->mru_applies_oids) LDAP_VFREE(mru->mru_applies_oids);
free_extensions(mru->mru_extensions);
LDAP_FREE(mru);
}
LDAPMatchingRuleUse *
-ldap_str2matchingruleuse( const char * s, int * code, const char ** errp, const int flags )
+ldap_str2matchingruleuse( LDAP_CONST char * s,
+ int * code,
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags )
{
int kind;
const char * ss = s;
parse_whsp(&ss);
savepos = ss;
- mru->mru_oid = parse_numericoid(&ss,code,flags);
+ mru->mru_oid = ldap_int_parse_numericoid(&ss,code,flags);
if ( !mru->mru_oid ) {
if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
/* Backtracking */
ldap_attributetype_free(LDAPAttributeType * at)
{
LDAP_FREE(at->at_oid);
- LDAP_VFREE(at->at_names);
- LDAP_FREE(at->at_desc);
- LDAP_FREE(at->at_sup_oid);
- LDAP_FREE(at->at_equality_oid);
- LDAP_FREE(at->at_ordering_oid);
- LDAP_FREE(at->at_substr_oid);
- LDAP_FREE(at->at_syntax_oid);
+ if (at->at_names) LDAP_VFREE(at->at_names);
+ if (at->at_desc) LDAP_FREE(at->at_desc);
+ if (at->at_sup_oid) LDAP_FREE(at->at_sup_oid);
+ if (at->at_equality_oid) LDAP_FREE(at->at_equality_oid);
+ if (at->at_ordering_oid) LDAP_FREE(at->at_ordering_oid);
+ if (at->at_substr_oid) LDAP_FREE(at->at_substr_oid);
+ if (at->at_syntax_oid) LDAP_FREE(at->at_syntax_oid);
free_extensions(at->at_extensions);
LDAP_FREE(at);
}
LDAPAttributeType *
-ldap_str2attributetype( const char * s, int * code, const char ** errp, const int flags )
+ldap_str2attributetype( LDAP_CONST char * s,
+ int * code,
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags )
{
int kind;
const char * ss = s;
*/
parse_whsp(&ss);
savepos = ss;
- at->at_oid = parse_numericoid(&ss,code,0);
+ at->at_oid = ldap_int_parse_numericoid(&ss,code,0);
if ( !at->at_oid ) {
- if ( flags & LDAP_SCHEMA_ALLOW_NO_OID ) {
+ if ( ( flags & ( LDAP_SCHEMA_ALLOW_NO_OID
+ | LDAP_SCHEMA_ALLOW_OID_MACRO ) )
+ && (ss == savepos) ) {
/* Backtracking */
ss = savepos;
kind = get_token(&ss,&sval);
!strncmp(sval, "X-", 2) ) {
/* Missing OID, backtrack */
ss = savepos;
- } else {
- /* Non-numerical OID, ignore */
+ } else if ( flags
+ & LDAP_SCHEMA_ALLOW_OID_MACRO) {
+ /* Non-numerical OID ... */
+ int len = ss-savepos;
+ at->at_oid = LDAP_MALLOC(len+1);
+ strncpy(at->at_oid, savepos, len);
+ at->at_oid[len] = 0;
}
}
LDAP_FREE(sval);
}
seen_syntax = 1;
parse_whsp(&ss);
+ savepos = ss;
at->at_syntax_oid =
parse_noidlen(&ss,
code,
&at->at_syntax_len,
flags);
if ( !at->at_syntax_oid ) {
+ if ( flags & LDAP_SCHEMA_ALLOW_OID_MACRO ) {
+ kind = get_token(&ss,&sval);
+ if (kind == TK_BAREWORD)
+ {
+ char *sp = strchr(sval, '{');
+ at->at_syntax_oid = sval;
+ if (sp)
+ {
+ *sp++ = 0;
+ at->at_syntax_len = atoi(sp);
+ while ( LDAP_DIGIT(*sp) )
+ sp++;
+ if ( *sp != '}' ) {
+ *code = LDAP_SCHERR_UNEXPTOKEN;
+ *errp = ss;
+ ldap_attributetype_free(at);
+ return NULL;
+ }
+ }
+ }
+ } else {
*errp = ss;
ldap_attributetype_free(at);
return NULL;
+ }
}
parse_whsp(&ss);
} else if ( !strcmp(sval,"SINGLE-VALUE") ) {
ldap_objectclass_free(LDAPObjectClass * oc)
{
LDAP_FREE(oc->oc_oid);
- LDAP_VFREE(oc->oc_names);
- LDAP_FREE(oc->oc_desc);
- LDAP_VFREE(oc->oc_sup_oids);
- LDAP_VFREE(oc->oc_at_oids_must);
- LDAP_VFREE(oc->oc_at_oids_may);
+ if (oc->oc_names) LDAP_VFREE(oc->oc_names);
+ if (oc->oc_desc) LDAP_FREE(oc->oc_desc);
+ if (oc->oc_sup_oids) LDAP_VFREE(oc->oc_sup_oids);
+ if (oc->oc_at_oids_must) LDAP_VFREE(oc->oc_at_oids_must);
+ if (oc->oc_at_oids_may) LDAP_VFREE(oc->oc_at_oids_may);
free_extensions(oc->oc_extensions);
LDAP_FREE(oc);
}
LDAPObjectClass *
-ldap_str2objectclass( const char * s, int * code, const char ** errp, const int flags )
+ldap_str2objectclass( LDAP_CONST char * s,
+ int * code,
+ LDAP_CONST char ** errp,
+ LDAP_CONST int flags )
{
int kind;
const char * ss = s;
*code = LDAP_SCHERR_OUTOFMEM;
return NULL;
}
+ oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
kind = get_token(&ss,&sval);
if ( kind != TK_LEFTPAREN ) {
*/
parse_whsp(&ss);
savepos = ss;
- oc->oc_oid = parse_numericoid(&ss,code,0);
+ oc->oc_oid = ldap_int_parse_numericoid(&ss,code,0);
if ( !oc->oc_oid ) {
- if ( flags & LDAP_SCHEMA_ALLOW_ALL ) {
+ if ( (flags & LDAP_SCHEMA_ALLOW_ALL) && (ss == savepos) ) {
/* Backtracking */
ss = savepos;
kind = get_token(&ss,&sval);
!strncmp(sval, "X-", 2) ) {
/* Missing OID, backtrack */
ss = savepos;
- } else {
+ } else if ( flags &
+ LDAP_SCHEMA_ALLOW_OID_MACRO ) {
/* Non-numerical OID, ignore */
+ int len = ss-savepos;
+ oc->oc_oid = LDAP_MALLOC(len+1);
+ strncpy(oc->oc_oid, savepos, len);
+ oc->oc_oid[len] = 0;
}
}
LDAP_FREE(sval);