]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/config.c
Fixup bdb_entry_release now that entry_decode uses two memory blocks
[openldap] / servers / slapd / config.c
index f20979649e9ef35a147ac6257fa660a805167063..addef851a9794c199e995af6f617b7ac1c1847da 100644 (file)
 #include <ac/string.h>
 #include <ac/ctype.h>
 #include <ac/socket.h>
+#include <ac/errno.h>
 
 #include "lutil.h"
 #include "ldap_pvt.h"
 #include "slap.h"
 
-#define MAXARGS        200
+#define MAXARGS        500
 
 /*
  * defaults for various global variables
@@ -85,16 +86,21 @@ read_config( const char *fname )
 
        if ( (fp = fopen( fname, "r" )) == NULL ) {
                ldap_syslog = 1;
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "config", LDAP_LEVEL_ENTRY, "read_config: "
+                       "could not open config file \"%s\": %s (%d)\n",
+                   fname, strerror(errno), errno ));
+#else
                Debug( LDAP_DEBUG_ANY,
-                   "could not open config file \"%s\" - absolute path?\n",
-                   fname, 0, 0 );
-               perror( fname );
+                   "could not open config file \"%s\": %s (%d)\n",
+                   fname, strerror(errno), errno );
+#endif
                return 1;
        }
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "config", LDAP_LEVEL_ENTRY,
-                  "read_config: reading config file %s\n", fname ));
+               "read_config: reading config file %s\n", fname ));
 #else
        Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
 #endif
@@ -859,11 +865,11 @@ read_config( const char *fname )
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
 "%s: line %d: \"%s\" is reserved for monitoring slapd\n", 
-                                       SLAPD_MONITOR_DN, fname, lineno ));
+                                       fname, lineno, SLAPD_MONITOR_DN ));
 #else
                                Debug( LDAP_DEBUG_ANY,
 "%s: line %d: \"%s\" is reserved for monitoring slapd\n",
-                                       SLAPD_MONITOR_DN, fname, lineno );
+                                       fname, lineno, SLAPD_MONITOR_DN );
 #endif
                                return( 1 );
 #endif /* SLAPD_MONITOR_DN */
@@ -1481,6 +1487,19 @@ read_config( const char *fname )
                                return( 1 );
                        }
 
+                       if( validate_global_referral( cargv[1] ) ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
+                                       "invalid URL (%s) in \"referral\" line.\n",
+                                       fname, lineno, cargv[1] ));
+#else
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "invalid URL (%s) in \"referral\" line.\n",
+                                   fname, lineno, cargv[1] );
+#endif
+                               return 1;
+                       }
+
                        vals[0]->bv_val = cargv[1];
                        vals[0]->bv_len = strlen( vals[0]->bv_val );
                        value_add( &default_referral, vals );
@@ -1685,22 +1704,21 @@ read_config( const char *fname )
                                } else {
                                        for ( i = 1; i < cargc; i++ ) {
                                                if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
-                                                       char *nsuffix = ch_strdup( cargv[i] + 7 );
-                                                       if ( dn_normalize( nsuffix ) != NULL ) {
-                                                               if ( select_backend( nsuffix, 0 ) == be ) {
-                                                                       charray_add( &be->be_replica[nr]->ri_nsuffix, nsuffix );
-                                                               } else {
+
+                                                       switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
+                                                       case 1:
 #ifdef NEW_LOGGING
-                                                                       LDAP_LOG(( "config", LDAP_LEVEL_INFO,
-                                                                                               "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
-                                                                                               fname, lineno, cargv[i] + 7 ));
+                                                               LDAP_LOG(( "config", LDAP_LEVEL_INFO,
+                                                                               "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
+                                                                               fname, lineno, cargv[i] + 7 ));
 #else
-                                                                       Debug( LDAP_DEBUG_ANY,
-                                                                                       "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
-                                                                                       fname, lineno, cargv[i] + 7 );
+                                                               Debug( LDAP_DEBUG_ANY,
+                                                                               "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
+                                                                               fname, lineno, cargv[i] + 7 );
 #endif
-                                                               }
-                                                       } else {
+                                                               break;
+
+                                                       case 2:
 #ifdef NEW_LOGGING
                                                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
                                                                                        "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
@@ -1710,8 +1728,8 @@ read_config( const char *fname )
                                                                                 "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
                                                                                 fname, lineno, 0 );
 #endif
+                                                               break;
                                                        }
-                                                       free( nsuffix );
                                                }
                                        }
                                }
@@ -1767,12 +1785,12 @@ read_config( const char *fname )
                } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
                        if ( cargc < 2 ) {
 #ifdef NEW_LOGGING
-                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
-                                          "%s: line %d: missing dn in \"updateref <ldapurl>\" "
-                                          "line.\n", fname, lineno ));
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
+                                       "missing url in \"updateref <ldapurl>\" line.\n",
+                                       fname, lineno ));
 #else
-                               Debug( LDAP_DEBUG_ANY,
-                   "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "missing url in \"updateref <ldapurl>\" line\n",
                                    fname, lineno, 0 );
 #endif
 
@@ -1780,32 +1798,46 @@ read_config( const char *fname )
                        }
                        if ( be == NULL ) {
 #ifdef NEW_LOGGING
-                               LDAP_LOG(( "config", LDAP_LEVEL_INFO,
-                                          "%s: line %d: updateref line must appear inside "
-                                          "a database definition (ignored)\n", fname, lineno ));
+                               LDAP_LOG(( "config", LDAP_LEVEL_INFO, "%s: line %d: "
+                                       "updateref line must appear inside a database definition "
+                                       "(ignored)\n", fname, lineno ));
 #else
-                               Debug( LDAP_DEBUG_ANY,
-"%s: line %d: updateref line must appear inside a database definition (ignored)\n",
-                                   fname, lineno, 0 );
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "updateref line must appear inside a database definition "
+                                       "(ignored)\n", fname, lineno, 0 );
 #endif
+                               return 1;
 
                        } else if ( be->be_update_ndn == NULL ) {
 #ifdef NEW_LOGGING
-                               LDAP_LOG(( "config", LDAP_LEVEL_INFO,
-                                          "%s: line %d: updateref line must come after updatedn "
-                                          "(ignored).\n", fname, lineno ));
+                               LDAP_LOG(( "config", LDAP_LEVEL_INFO, "%s: line %d: "
+                                       "updateref line must come after updatedn (ignored).\n",
+                                       fname, lineno ));
 #else
-                               Debug( LDAP_DEBUG_ANY,
-"%s: line %d: updateref line must after updatedn (ignored)\n",
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "updateref line must after updatedn (ignored)\n",
                                    fname, lineno, 0 );
 #endif
+                               return 1;
+                       }
 
-                       } else {
-                               vals[0]->bv_val = cargv[1];
-                               vals[0]->bv_len = strlen( vals[0]->bv_val );
-                               value_add( &be->be_update_refs, vals );
+                       if( validate_global_referral( cargv[1] ) ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
+                                       "invalid URL (%s) in \"updateref\" line.\n",
+                                       fname, lineno, cargv[1] ));
+#else
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "invalid URL (%s) in \"updateref\" line.\n",
+                                   fname, lineno, cargv[1] );
+#endif
+                               return 1;
                        }
 
+                       vals[0]->bv_val = cargv[1];
+                       vals[0]->bv_len = strlen( vals[0]->bv_val );
+                       value_add( &be->be_update_refs, vals );
+
                /* replication log file to which changes are appended */
                } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
                        if ( cargc < 2 ) {
@@ -1815,7 +1847,7 @@ read_config( const char *fname )
                                           " line.\n", fname, lineno ));
 #else
                                Debug( LDAP_DEBUG_ANY,
-           "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
+           "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
                                    fname, lineno, 0 );
 #endif
 
@@ -1827,6 +1859,34 @@ read_config( const char *fname )
                                replogfile = ch_strdup( cargv[1] );
                        }
 
+               /* file from which to read additional rootdse attrs */
+               } else if ( strcasecmp( cargv[0], "rootdse" ) == 0) {
+                       if ( cargc < 2 ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
+                                       "missing filename in \"rootDSEfile <filename>\" line.\n",
+                                       fname, lineno ));
+#else
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "missing filename in \"rootDSEfile <filename>\" line.\n",
+                                   fname, lineno, 0 );
+#endif
+                               return 1;
+                       }
+
+                       if( read_root_dse_file( cargv[1] ) ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
+                                       "could not read \"rootDSEfile <filename>\" line.\n",
+                                       fname, lineno ));
+#else
+                               Debug( LDAP_DEBUG_ANY, "%s: line %d: "
+                                       "could not read \"rootDSEfile <filename>\" line\n",
+                                   fname, lineno, 0 );
+#endif
+                               return 1;
+                       }
+
                /* maintain lastmodified{by,time} attributes */
                } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
                        if ( cargc < 2 ) {
@@ -2221,7 +2281,9 @@ fp_getline( FILE *fp, int *lineno )
        }
 
        while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
+               /* trim off \r\n or \n */
                if ( (p = strchr( buf, '\n' )) != NULL ) {
+                       if( p > buf && p[-1] == '\r' ) --p;
                        *p = '\0';
                }
                if ( ! isspace( (unsigned char) buf[0] ) ) {