]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
More system schema checks
[openldap] / servers / slapd / schema_init.c
index d452ae50200d1fc7e57b97c0fd1f285e2c794f8d..cfd141b2fcba882a814eb77db8dc1ce76c30d46d 100644 (file)
@@ -1,7 +1,7 @@
 /* schema_init.c - init builtin schema */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -222,38 +222,38 @@ nameUIDValidate(
        struct berval *in )
 {
        int rc;
-       struct berval *dn;
+       struct berval dn;
 
        if( in->bv_len == 0 ) return LDAP_SUCCESS;
 
-       dn = ber_bvdup( in );
-       if( !dn ) return LDAP_OTHER;
+       ber_dupbv( &dn, in );
+       if( !dn.bv_val ) return LDAP_OTHER;
 
-       if( dn->bv_val[dn->bv_len-1] == 'B'
-               && dn->bv_val[dn->bv_len-2] == '\'' )
+       if( dn.bv_val[dn.bv_len-1] == 'B'
+               && dn.bv_val[dn.bv_len-2] == '\'' )
        {
                /* assume presence of optional UID */
                ber_len_t i;
 
-               for(i=dn->bv_len-3; i>1; i--) {
-                       if( dn->bv_val[i] != '0' &&     dn->bv_val[i] != '1' ) {
+               for(i=dn.bv_len-3; i>1; i--) {
+                       if( dn.bv_val[i] != '0' &&      dn.bv_val[i] != '1' ) {
                                break;
                        }
                }
-               if( dn->bv_val[i] != '\'' ||
-                   dn->bv_val[i-1] != '#' ) {
-                       ber_bvfree( dn );
+               if( dn.bv_val[i] != '\'' ||
+                   dn.bv_val[i-1] != '#' ) {
+                       ber_memfree( dn.bv_val );
                        return LDAP_INVALID_SYNTAX;
                }
 
                /* trim the UID to allow use of dnValidate */
-               dn->bv_val[i-1] = '\0';
-               dn->bv_len = i-1;
+               dn.bv_val[i-1] = '\0';
+               dn.bv_len = i-1;
        }
 
-       rc = dnValidate( NULL, dn );
+       rc = dnValidate( NULL, &dn );
 
-       ber_bvfree( dn );
+       ber_memfree( &dn );
        return rc;
 }
 
@@ -303,12 +303,12 @@ nameUIDNormalize(
                if( uidlen ) {
                        struct berval b2;
                        b2.bv_val = ch_malloc(dnlen + uidlen + 1);
-                       SAFEMEMCPY( b2.bv_val, normalized->bv_val, dnlen );
+                       AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
 
                        /* restore the separator */
                        *uid = '#';
                        /* shift the UID */
-                       SAFEMEMCPY( normalized->bv_val+dnlen, uid, uidlen );
+                       AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
                        b2.bv_len = dnlen + uidlen;
                        normalized->bv_val[dnlen+uidlen] = '\0';
                        free(normalized->bv_val);
@@ -567,7 +567,7 @@ UTF8StringNormalize(
 static SubstringsAssertion *
 UTF8SubstringsassertionNormalize(
        SubstringsAssertion *sa,
-       char casefold )
+       unsigned casefold )
 {
        SubstringsAssertion *nsa;
        int i;
@@ -634,7 +634,7 @@ strip8bitChars(
                        while( *++q & 0x80 ) {
                                /* empty */
                        }
-                       p = memmove(p, q, strlen(q) + 1);
+                       p = AC_MEMCPY(p, q, strlen(q) + 1);
                } else {
                        p++;
                }
@@ -666,7 +666,7 @@ approxMatch(
        size_t avlen;
 
        /* Yes, this is necessary */
-       nval = UTF8normalize( value, UTF8_NOCASEFOLD );
+       nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
        if( nval == NULL ) {
                *matchp = 1;
                return LDAP_SUCCESS;
@@ -675,7 +675,7 @@ approxMatch(
 
        /* Yes, this is necessary */
        assertv = UTF8normalize( ((struct berval *)assertedValue),
-                                UTF8_NOCASEFOLD );
+               LDAP_UTF8_NOCASEFOLD );
        if( assertv == NULL ) {
                ch_free( nval );
                *matchp = 1;
@@ -781,7 +781,7 @@ approxIndexer(
 
        for( j=0; values[j].bv_val != NULL; j++ ) {
                /* Yes, this is necessary */
-               val = UTF8normalize( &values[j], UTF8_NOCASEFOLD );
+               val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
                strip8bitChars( val );
 
                /* Isolate how many words there are. There will be a key for each */
@@ -796,7 +796,7 @@ approxIndexer(
                /* Allocate/increase storage to account for new keys */
                newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1) 
                        * sizeof(struct berval) );
-               memcpy( newkeys, keys, keycount * sizeof(struct berval) );
+               AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
                if( keys ) ch_free( keys );
                keys = newkeys;
 
@@ -833,7 +833,7 @@ approxFilter(
 
        /* Yes, this is necessary */
        val = UTF8normalize( ((struct berval *)assertValue),
-                            UTF8_NOCASEFOLD );
+               LDAP_UTF8_NOCASEFOLD );
        if( val == NULL ) {
                keys = (struct berval *)ch_malloc( sizeof(struct berval) );
                keys[0].bv_val = NULL;
@@ -999,7 +999,7 @@ caseExactMatch(
 {
        *matchp = UTF8normcmp( value->bv_val,
                ((struct berval *) assertedValue)->bv_val,
-               UTF8_NOCASEFOLD );
+               LDAP_UTF8_NOCASEFOLD );
        return LDAP_SUCCESS;
 }
 
@@ -1017,10 +1017,11 @@ caseExactIgnoreSubstringsMatch(
        struct berval left;
        int i;
        ber_len_t inlen=0;
-       char *nav, casefold;
+       char *nav;
+       unsigned casefold;
 
        casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
-               ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
+               ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
        nav = UTF8normalize( value, casefold );
        if( nav == NULL ) {
@@ -1172,7 +1173,7 @@ static int caseExactIgnoreIndexer(
        BVarray *keysp )
 {
        int i;
-       char casefold;
+       unsigned casefold;
        size_t slen, mlen;
        BVarray keys;
        HASH_CONTEXT   HASHcontext;
@@ -1194,7 +1195,7 @@ static int caseExactIgnoreIndexer(
        mlen = mr->smr_oidlen;
 
        casefold = strcmp( mr->smr_oid, caseExactMatchOID )
-               ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
+               ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
        for( i=0; values[i].bv_val != NULL; i++ ) {
                struct berval value;
@@ -1234,7 +1235,7 @@ static int caseExactIgnoreFilter(
        void * assertValue,
        BVarray *keysp )
 {
-       char casefold;
+       unsigned casefold;
        size_t slen, mlen;
        BVarray keys;
        HASH_CONTEXT   HASHcontext;
@@ -1248,7 +1249,7 @@ static int caseExactIgnoreFilter(
        mlen = mr->smr_oidlen;
 
        casefold = strcmp( mr->smr_oid, caseExactMatchOID )
-               ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
+               ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
        ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
                0, 0, &value );
@@ -1293,7 +1294,7 @@ static int caseExactIgnoreSubstringsIndexer(
        BVarray values,
        BVarray *keysp )
 {
-       char casefold;
+       unsigned casefold;
        ber_len_t i, nkeys;
        size_t slen, mlen;
        BVarray keys;
@@ -1315,7 +1316,7 @@ static int caseExactIgnoreSubstringsIndexer(
        assert( i > 0 );
 
        casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
-               ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
+               ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
        nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
        for( i=0; values[i].bv_val != NULL; i++ ) {
@@ -1475,7 +1476,8 @@ static int caseExactIgnoreSubstringsFilter(
        BVarray *keysp )
 {
        SubstringsAssertion *sa;
-       char pre, casefold;
+       char pre;
+       unsigned casefold;
        ber_len_t nkeys = 0;
        size_t slen, mlen, klen;
        BVarray keys;
@@ -1485,7 +1487,7 @@ static int caseExactIgnoreSubstringsFilter(
        struct berval digest;
 
        casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
-               ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
+               ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
        sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
        if( sa == NULL ) {
@@ -1651,7 +1653,7 @@ caseIgnoreMatch(
 {
        *matchp = UTF8normcmp( value->bv_val,
                ((struct berval *) assertedValue)->bv_val,
-               UTF8_CASEFOLD );
+               LDAP_UTF8_CASEFOLD );
        return LDAP_SUCCESS;
 }
        
@@ -1855,7 +1857,7 @@ integerNormalize(
                if( negative ) {
                        normalized->bv_val[0] = '-';
                }
-               memcpy( normalized->bv_val + negative, p, len );
+               AC_MEMCPY( normalized->bv_val + negative, p, len );
        }
 
        return LDAP_SUCCESS;
@@ -1937,8 +1939,6 @@ printableStringValidate(
 {
        ber_len_t i;
 
-       if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
-
        for(i=0; i < val->bv_len; i++) {
                if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
                        return LDAP_INVALID_SYNTAX;
@@ -1955,8 +1955,6 @@ printablesStringValidate(
 {
        ber_len_t i;
 
-       if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
-
        for(i=0; i < val->bv_len; i++) {
                if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
                        return LDAP_INVALID_SYNTAX;
@@ -1973,10 +1971,10 @@ IA5StringValidate(
 {
        ber_len_t i;
 
-       if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
-
        for(i=0; i < val->bv_len; i++) {
-               if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
+               if( !LDAP_ASCII(val->bv_val[i]) ) {
+                       return LDAP_INVALID_SYNTAX;
+               }
        }
 
        return LDAP_SUCCESS;
@@ -1997,10 +1995,6 @@ IA5StringNormalize(
                p++;
        }
 
-       if( *p == '\0' ) {
-               return LDAP_INVALID_SYNTAX;
-       }
-
        normalized->bv_val = ch_strdup( p );
        p = q = normalized->bv_val;
 
@@ -2017,12 +2011,9 @@ IA5StringNormalize(
                }
        }
 
-       assert( normalized->bv_val < p );
+       assert( normalized->bv_val <= p );
        assert( q <= p );
 
-       /* cannot start with a space */
-       assert( !ASCII_SPACE(*normalized->bv_val) );
-
        /*
         * If the string ended in space, backup the pointer one
         * position.  One is enough because the above loop collapsed
@@ -2033,9 +2024,6 @@ IA5StringNormalize(
                --q;
        }
 
-       /* cannot end with a space */
-       assert( !ASCII_SPACE( q[-1] ) );
-
        /* null terminate */
        *q = '\0';
 
@@ -3531,12 +3519,12 @@ certificateExactConvert(
 
        X509_free(xcert);
 
-       out->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
+       out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
        out->bv_val = ch_malloc(out->bv_len);
        p = out->bv_val;
        AC_MEMCPY(p, serial->bv_val, serial->bv_len);
        p += serial->bv_len;
-       AC_MEMCPY(p, " $ ", 3);
+       AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
        p += 3;
        AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
        p += issuer_dn->bv_len;
@@ -3587,7 +3575,7 @@ serial_and_issuer_parse(
 
        bv.bv_len = end-begin+1;
        bv.bv_val = begin;
-       *serial = ber_bvdup(&bv);
+       *serial = ber_dupbv(NULL, &bv);
 
        /* now extract the issuer, remember p was at the dollar sign */
        begin = p+1;
@@ -4041,7 +4029,7 @@ nisNetgroupTripleValidate(
                return LDAP_INVALID_SYNTAX;
        }
 
-       for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
+       for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
                if ( *p == ',' ) {
                        commas++;
                        if ( commas > 2 ) {
@@ -4125,15 +4113,18 @@ static struct syntax_defs_rec {
        slap_syntax_transform_func *sd_str2ber;
 #endif
 } syntax_defs[] = {
-       {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
+       {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
+               X_BINARY X_NOT_H_R ")",
                SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
                0, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
                0, NULL, NULL, NULL},
-       {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
+       {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
+               X_NOT_H_R ")",
                SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
-       {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
+       {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
+               X_NOT_H_R ")",
                SLAP_SYNTAX_BER, berValidate, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
                0, bitStringValidate, bitStringNormalize, NULL },
@@ -4214,6 +4205,9 @@ static struct syntax_defs_rec {
                0, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
                0, printableStringValidate, IA5StringNormalize, NULL},
+       {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
+               X_BINARY X_NOT_H_R ")",
+               SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
                X_BINARY X_NOT_H_R ")",
                SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
@@ -4258,9 +4252,11 @@ static struct syntax_defs_rec {
                UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
                NULL, NULL},
 
+#ifdef SLAPD_AUTHPASSWD
        /* needs updating */
        {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
                SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
+#endif
 
        /* OpenLDAP Void Syntax */
        {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
@@ -4308,7 +4304,7 @@ static struct mrule_defs_rec {
         */
        {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
-               SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
+               SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
                NULL, NULL,
                directoryStringApproxMatch,
                directoryStringApproxIndexer, 
@@ -4317,7 +4313,7 @@ static struct mrule_defs_rec {
 
        {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
-               SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
+               SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
                NULL, NULL,
                IA5StringApproxMatch,
                IA5StringApproxIndexer, 
@@ -4557,6 +4553,7 @@ static struct mrule_defs_rec {
                caseExactIA5SubstringsFilter,
                NULL},
 
+#ifdef SLAPD_AUTHPASSWD
        /* needs updating */
        {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
@@ -4564,6 +4561,7 @@ static struct mrule_defs_rec {
                NULL, NULL,
                authPasswordMatch, NULL, NULL,
                NULL},
+#endif
 
        {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
                "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
@@ -4590,7 +4588,7 @@ static struct mrule_defs_rec {
 };
 
 int
-schema_init( void )
+slap_schema_init( void )
 {
        int             res;
        int             i;
@@ -4612,7 +4610,7 @@ schema_init( void )
                );
 
                if ( res ) {
-                       fprintf( stderr, "schema_init: Error registering syntax %s\n",
+                       fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
                                 syntax_defs[i].sd_desc );
                        return LDAP_OTHER;
                }
@@ -4621,7 +4619,7 @@ schema_init( void )
        for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
                if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
                        fprintf( stderr,
-                               "schema_init: Ingoring unusable matching rule %s\n",
+                               "slap_schema_init: Ingoring unusable matching rule %s\n",
                                 mrule_defs[i].mrd_desc );
                        continue;
                }
@@ -4638,13 +4636,15 @@ schema_init( void )
 
                if ( res ) {
                        fprintf( stderr,
-                               "schema_init: Error registering matching rule %s\n",
+                               "slap_schema_init: Error registering matching rule %s\n",
                                 mrule_defs[i].mrd_desc );
                        return LDAP_OTHER;
                }
        }
+
+       res = slap_schema_load();
        schema_init_done = 1;
-       return LDAP_SUCCESS;
+       return res;
 }
 
 void