]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/config.c
cleanup comments
[openldap] / servers / slapd / config.c
index 656fb12d712e99cdcdc3f7fde7e8f4fd4c5b1284..14b092b19cae6d1f6be1e1c3fe84cc7bcc29b808 100644 (file)
@@ -52,6 +52,10 @@ char **cargv;
 struct berval default_search_base = { 0, NULL };
 struct berval default_search_nbase = { 0, NULL };
 unsigned               num_subordinates = 0;
+#ifdef SLAPD_SCHEMA_DN
+struct berval global_schemadn = { 0, NULL };
+struct berval global_schemandn = { 0, NULL };
+#endif
 
 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
@@ -75,7 +79,7 @@ static char   *strtok_quote(char *line, char *sep);
 static int      load_ucdata(char *path);
 
 int
-read_config( const char *fname )
+read_config( const char *fname, int depth )
 {
        FILE    *fp;
        char    *line, *savefname, *saveline;
@@ -90,8 +94,10 @@ read_config( const char *fname )
 
        vals[1].bv_val = NULL;
 
-       cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
-       cargv_size = ARGS_STEP + 1;
+       if ( depth == 0 ) {
+               cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
+               cargv_size = ARGS_STEP + 1;
+       }
 
        if ( (fp = fopen( fname, "r" )) == NULL ) {
                ldap_syslog = 1;
@@ -562,6 +568,42 @@ read_config( const char *fname )
                                return 1;
 #endif /* HAVE_CYRUS_SASL */
 
+#ifdef SLAPD_SCHEMA_DN
+               } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
+                       struct berval dn;
+                       if ( cargc < 2 ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( CONFIG, CRIT, 
+                                          "%s: line %d: missing dn in "
+                                          "\"schemadn <dn>\" line.\n", fname, lineno, 0  );
+#else
+                               Debug( LDAP_DEBUG_ANY,
+           "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
+                                   fname, lineno, 0 );
+#endif
+                               return 1 ;
+                       }
+                       ber_str2bv( cargv[1], 0, 0, &dn );
+                       if ( be ) {
+                               rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
+                                       &be->be_schemandn );
+                       } else {
+                               rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
+                                       &global_schemandn );
+                       }
+                       if ( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( CONFIG, CRIT, 
+                                       "%s: line %d: schemadn DN is invalid.\n",
+                                       fname, lineno , 0 );
+#else
+                               Debug( LDAP_DEBUG_ANY,
+                                       "%s: line %d: schemadn DN is invalid\n",
+                                       fname, lineno, 0 );
+#endif
+                               return 1;
+                       }
+#endif /* SLAPD_SCHEMA_DN */
                /* set UCDATA path */
                } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
                        int err;
@@ -2012,7 +2054,7 @@ read_config( const char *fname )
                        savefname = ch_strdup( cargv[1] );
                        savelineno = lineno;
 
-                       if ( read_config( savefname ) != 0 ) {
+                       if ( read_config( savefname, depth+1 ) != 0 ) {
                                return( 1 );
                        }
 
@@ -2257,6 +2299,16 @@ read_config( const char *fname )
        }
        fclose( fp );
 
+       if ( depth == 0 ) ch_free( cargv );
+
+#ifdef SLAPD_SCHEMA_DN
+       if ( !global_schemadn.bv_val ) {
+               ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
+                       &global_schemadn );
+               dnNormalize2( NULL, &global_schemadn, &global_schemandn );
+       }
+#endif
+
        if ( load_ucdata( NULL ) < 0 ) return 1;
        return( 0 );
 }
@@ -2275,22 +2327,29 @@ fp_parse_line(
        token = strtok_quote( line, " \t" );
 
        logline = line;
-       if ( token &&
-            (strcasecmp( token, "rootpw" ) == 0 ||
-             strcasecmp( token, "replica" ) == 0 || /* contains "credentials" */
-             strcasecmp( token, "bindpw" ) == 0 ||       /* used in back-ldap */
-             strcasecmp( token, "pseudorootpw" ) == 0 || /* used in back-meta */
-                 strcasecmp( token, "dbpasswd" ) == 0 ) )    /* used in back-sql */
-               sprintf( logline = logbuf, "%s ***", token );
-       if ( strtok_quote_ptr )
+
+       if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
+               strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
+               strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
+               strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
+               strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
+       {
+               snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
+       }
+
+       if ( strtok_quote_ptr ) {
                *strtok_quote_ptr = ' ';
+       }
+
 #ifdef NEW_LOGGING
        LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
 #else
        Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
 #endif
-       if ( strtok_quote_ptr )
+
+       if ( strtok_quote_ptr ) {
                *strtok_quote_ptr = '\0';
+       }
 
        for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
                if ( cargc == cargv_size - 1 ) {
@@ -2373,18 +2432,18 @@ strtok_quote( char *line, char *sep )
 
 static char    buf[BUFSIZ];
 static char    *line;
-static int     lmax, lcur;
-
-#define CATLINE( buf ) \
-       int     len; \
-       len = strlen( buf ); \
-       while ( lcur + len + 1 > lmax ) { \
-               lmax += BUFSIZ; \
-               line = (char *) ch_realloc( line, lmax ); \
-       } \
-       strcpy( line + lcur, buf ); \
-       lcur += len; \
-}
+static size_t lmax, lcur;
+
+#define CATLINE( buf ) \
+       do { \
+               size_t len = strlen( buf ); \
+               while ( lcur + len + 1 > lmax ) { \
+                       lmax += BUFSIZ; \
+                       line = (char *) ch_realloc( line, lmax ); \
+               } \
+               strcpy( line + lcur, buf ); \
+               lcur += len; \
+       } while( 0 )
 
 static char *
 fp_getline( FILE *fp, int *lineno )
@@ -2469,6 +2528,10 @@ void
 config_destroy( )
 {
        ucdata_unload( UCDATA_ALL );
+#ifdef SLAPD_SCHEMA_DN
+       free( global_schemandn.bv_val );
+       free( global_schemadn.bv_val );
+#endif
        free( line );
        if ( slapd_args_file )
                free ( slapd_args_file );