X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=servers%2Fslapd%2Fslapcommon.c;h=3afa9d271bcb4ad3009a961640b6cd2288a69576;hb=deb316e6d8a50035facc069de540113c06ba71b7;hp=10a1548ec65dc8520b34022e7ad390e7585ebacf;hpb=04391a9ec6b2f9c2e395dfab468bcde9e5ab8213;p=openldap diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 10a1548ec6..3afa9d271b 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2007 The OpenLDAP Foundation. * Portions Copyright 1998-2003 Kurt D. Zeilenga. * Portions Copyright 2003 IBM Corporation. * All rights reserved. @@ -36,6 +36,7 @@ #include "slapcommon.h" #include "lutil.h" +#include "ldif.h" tool_vars tool_globals; @@ -44,6 +45,8 @@ static char *leakfilename; static FILE *leakfile; #endif +static LDIFFP dummy; + static void usage( int tool, const char *progname ) { @@ -59,8 +62,8 @@ usage( int tool, const char *progname ) break; case SLAPADD: - options = " [-c]\n\t[-n databasenumber | -b suffix]\n" - "\t[-l ldiffile] [-q] [-u] [-w]\n"; + options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n" + "\t[-l ldiffile] [-q] [-u] [-s] [-w]\n"; break; case SLAPAUTH: @@ -68,7 +71,7 @@ usage( int tool, const char *progname ) break; case SLAPCAT: - options = " [-c]\n\t[-n databasenumber | -b suffix]" + options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]" " [-l ldiffile] [-a filter]\n"; break; @@ -77,7 +80,7 @@ usage( int tool, const char *progname ) break; case SLAPINDEX: - options = " [-c]\n\t[-n databasenumber | -b suffix] [-q]\n"; + options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [-q]\n"; break; case SLAPTEST: @@ -130,16 +133,28 @@ parse_slapacl( void ) ber_str2bv( p, 0, 1, &sock_name ); } else if ( strncasecmp( optarg, "ssf", len ) == 0 ) { - ssf = atoi( p ); + if ( lutil_atou( &ssf, p ) ) { + Debug( LDAP_DEBUG_ANY, "unable to parse ssf=\"%s\".\n", p, 0, 0 ); + return -1; + } } else if ( strncasecmp( optarg, "transport_ssf", len ) == 0 ) { - transport_ssf = atoi( p ); + if ( lutil_atou( &transport_ssf, p ) ) { + Debug( LDAP_DEBUG_ANY, "unable to parse transport_ssf=\"%s\".\n", p, 0, 0 ); + return -1; + } } else if ( strncasecmp( optarg, "tls_ssf", len ) == 0 ) { - tls_ssf = atoi( p ); + if ( lutil_atou( &tls_ssf, p ) ) { + Debug( LDAP_DEBUG_ANY, "unable to parse tls_ssf=\"%s\".\n", p, 0, 0 ); + return -1; + } } else if ( strncasecmp( optarg, "sasl_ssf", len ) == 0 ) { - sasl_ssf = atoi( p ); + if ( lutil_atou( &sasl_ssf, p ) ) { + Debug( LDAP_DEBUG_ANY, "unable to parse sasl_ssf=\"%s\".\n", p, 0, 0 ); + return -1; + } } else if ( strncasecmp( optarg, "authzDN", len ) == 0 ) { ber_str2bv( p, 0, 1, &authzDN ); @@ -159,6 +174,8 @@ parse_slapacl( void ) * argc, argv command line arguments */ +static int need_shutdown; + void slap_tool_init( const char* progname, @@ -166,15 +183,23 @@ slap_tool_init( int argc, char **argv ) { char *options; - char *conffile = SLAPD_DEFAULT_CONFIGFILE; - char *confdir = SLAPD_DEFAULT_CONFIGDIR; + char *conffile = NULL; + char *confdir = NULL; struct berval base = BER_BVNULL; char *filterstr = NULL; char *subtree = NULL; char *ldiffile = NULL; + char **debug_unknowns = NULL; int rc, i, dbnum; int mode = SLAP_TOOL_MODE; int truncatemode = 0; + int use_glue = 1; + +#ifdef LDAP_DEBUG + /* tools default to "none", so that at least LDAP_DEBUG_ANY + * messages show up; use -d 0 to reset */ + slap_debug = LDAP_DEBUG_NONE; +#endif #ifdef CSRIMALLOC leakfilename = malloc( strlen( progname ) + STRLENOF( ".leak" ) + 1 ); @@ -187,11 +212,11 @@ slap_tool_init( switch( tool ) { case SLAPADD: - options = "b:cd:f:F:l:n:qtuvw"; + options = "b:cd:f:F:gl:n:qstuvw"; break; case SLAPCAT: - options = "a:b:cd:f:F:l:n:s:v"; + options = "a:b:cd:f:F:gl:n:s:v"; mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY; break; @@ -211,7 +236,7 @@ slap_tool_init( break; case SLAPINDEX: - options = "b:cd:f:F:n:qv"; + options = "b:cd:f:F:gn:qv"; mode |= SLAP_TOOL_READMAIN; break; @@ -240,9 +265,26 @@ slap_tool_init( continuemode++; break; - case 'd': /* turn on debugging */ - ldap_debug += atoi( optarg ); - break; + case 'd': { /* turn on debugging */ + int level = 0; + + if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) { + usage( tool, progname ); + } +#ifdef LDAP_DEBUG + if ( level == 0 ) { + /* allow to reset log level */ + slap_debug = 0; + + } else { + slap_debug |= level; + } +#else + if ( level != 0 ) + fputs( "must compile with LDAP_DEBUG for debugging\n", + stderr ); +#endif + } break; case 'D': ber_str2bv( optarg, 0, 1, &authcDN ); @@ -256,6 +298,10 @@ slap_tool_init( confdir = strdup( optarg ); break; + case 'g': /* disable subordinate glue */ + use_glue = 0; + break; + case 'l': /* LDIF file */ ldiffile = strdup( optarg ); break; @@ -272,7 +318,9 @@ slap_tool_init( break; case 'n': /* which config file db to index */ - dbnum = atoi( optarg ); + if ( lutil_atoi( &dbnum, optarg ) ) { + usage( tool, progname ); + } break; case 'o': @@ -297,7 +345,10 @@ slap_tool_init( break; case 's': /* dump subtree */ - subtree = strdup( optarg ); + if ( tool == SLAPADD ) + mode |= SLAP_TOOL_NO_SCHEMA_CHECK; + else if ( tool == SLAPCAT ) + subtree = strdup( optarg ); break; case 't': /* turn on truncate */ @@ -376,9 +427,10 @@ slap_tool_init( ldap_syslog = 0; if ( ldiffile == NULL ) { - ldiffp = tool == SLAPCAT ? stdout : stdin; + dummy.fp = tool == SLAPCAT ? stdout : stdin; + ldiffp = &dummy; - } else if ((ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" )) + } else if ((ldiffp = ldif_open( ldiffile, tool == SLAPCAT ? "w" : "r" )) == NULL ) { perror( ldiffile ); @@ -389,44 +441,28 @@ slap_tool_init( * initialize stuff and figure out which backend we're dealing with */ -#ifdef SLAPD_MODULES - if ( module_init() != 0 ) { - fprintf( stderr, "%s: module_init failed!\n", progname ); - exit( EXIT_FAILURE ); - } -#endif - - rc = slap_schema_init(); - - if ( rc != 0 ) { - fprintf( stderr, "%s: slap_schema_init failed!\n", progname ); - exit( EXIT_FAILURE ); - } - rc = slap_init( mode, progname ); - if ( rc != 0 ) { fprintf( stderr, "%s: slap_init failed!\n", progname ); exit( EXIT_FAILURE ); } - if ( frontend_init() ) { - fprintf( stderr, "%s: frontend_init failed!\n", progname ); - exit( EXIT_FAILURE ); - } - - if ( overlay_init() ) { - fprintf( stderr, "%s: overlay_init failed!\n", progname ); - exit( EXIT_FAILURE ); - } - rc = read_config( conffile, confdir ); if ( rc != 0 ) { - fprintf( stderr, "%s: bad configuration file!\n", progname ); + fprintf( stderr, "%s: bad configuration %s!\n", + progname, confdir ? "directory" : "file" ); exit( EXIT_FAILURE ); } + if ( debug_unknowns ) { + rc = parse_debug_unknowns( debug_unknowns, &slap_debug ); + ldap_charray_free( debug_unknowns ); + debug_unknowns = NULL; + if ( rc ) + exit( EXIT_FAILURE ); + } + at_oc_cache = 1; switch ( tool ) { @@ -444,6 +480,16 @@ slap_tool_init( break; } + if ( use_glue ) { + rc = glue_sub_attach(); + + if ( rc != 0 ) { + fprintf( stderr, + "%s: subordinate configuration error\n", progname ); + exit( EXIT_FAILURE ); + } + } + rc = slap_schema_check(); if ( rc != 0 ) { @@ -521,12 +567,17 @@ slap_tool_init( } } else if ( dbnum == -1 ) { + /* no suffix and no dbnum specified, just default to + * the first available database + */ if ( nbackends <= 0 ) { fprintf( stderr, "No available databases\n" ); exit( EXIT_FAILURE ); } LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { dbnum++; + + /* db #0 is cn=config, don't select it as a default */ if ( dbnum < 1 ) continue; if ( SLAP_MONITOR(be)) @@ -548,19 +599,19 @@ slap_tool_init( exit( EXIT_FAILURE ); } - if ( nosubordinates == 0 && dbnum > 0 ) { + if ( nosubordinates == 0 && dbnum > 1 ) { Debug( LDAP_DEBUG_ANY, "The first database does not allow %s;" " using the first available one (%d)\n", - progname, dbnum + 1, 0 ); + progname, dbnum, 0 ); } } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { fprintf( stderr, "Database number selected via -n is out of range\n" - "Must be in the range 1 to %d" - " (number of databases in the config file)\n", - nbackends ); + "Must be in the range 0 to %d" + " (number of configured databases)\n", + nbackends-1 ); exit( EXIT_FAILURE ); } else { @@ -576,27 +627,42 @@ startup:; mal_leaktrace(1); #endif - if ( !dryrun && be && slap_startup( be ) ) { - switch ( tool ) { - case SLAPTEST: - fprintf( stderr, "slap_startup failed " - "(test would succeed using " - "the -u switch)\n" ); - break; + if ( conffile != NULL ) { + ch_free( conffile ); + } - default: - fprintf( stderr, "slap_startup failed\n" ); - break; + if ( ldiffile != NULL ) { + ch_free( ldiffile ); + } + + /* slapdn doesn't specify a backend to startup */ + if ( !dryrun && tool != SLAPDN ) { + need_shutdown = 1; + + if ( slap_startup( be ) ) { + switch ( tool ) { + case SLAPTEST: + fprintf( stderr, "slap_startup failed " + "(test would succeed using " + "the -u switch)\n" ); + break; + + default: + fprintf( stderr, "slap_startup failed\n" ); + break; + } + + exit( EXIT_FAILURE ); } - - exit( EXIT_FAILURE ); } } void slap_tool_destroy( void ) { if ( !dryrun ) { - slap_shutdown( be ); + if ( need_shutdown ) { + slap_shutdown( be ); + } slap_destroy(); } #ifdef SLAPD_MODULES