X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fmain.c;h=944faff679c8cefdb3285fe57b004a65dbf3035b;hb=af866c3b44ba37577671f2bffd482499f4b8bc00;hp=0270b05bfa77055f493346cb219eb3d90313e8b0;hpb=fda3d6260e25f1d0b9c035b0d520b2c9d0f22e49;p=openldap diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 0270b05bfa..944faff679 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2004 The OpenLDAP Foundation. + * Copyright 1998-2005 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -133,16 +133,18 @@ static int cnvt_str2int( char *, STRDISP_P, int ); static int check = CHECK_NONE; static int version = 0; +void *slap_tls_ctx; + static int slapd_opt_slp( const char *val, void *arg ) { #ifdef HAVE_SLP /* NULL is default */ if ( val == NULL || strcasecmp( val, "on" ) == 0 ) { - SLAPD_GLOBAL(register_slp) = 1; + slapd_register_slp = 1; } else if ( strcasecmp( val, "off" ) == 0 ) { - SLAPD_GLOBAL(register_slp) = 0; + slapd_register_slp = 0; /* NOTE: add support for URL specification? */ @@ -251,13 +253,14 @@ int main( int argc, char **argv ) #ifdef HAVE_NT_SERVICE_MANAGER char *configfile = ".\\slapd.conf"; + char *configdir = ".\\slapd.d"; #else char *configfile = SLAPD_DEFAULT_CONFIGFILE; + char *configdir = SLAPD_DEFAULT_CONFIGDIR; #endif char *serverName; int serverMode = SLAP_SERVER_MODE; - struct berval cookie = BER_BVNULL; struct sync_cookie *scp = NULL; struct sync_cookie *scp_entry = NULL; @@ -272,8 +275,6 @@ int main( int argc, char **argv ) slap_sl_mem_init(); - config_init(); /* sets frontendDB */ - serverName = lutil_progname( "slapd", argc, argv ); if ( strcmp( serverName, "slapd" ) ) { @@ -289,6 +290,7 @@ int main( int argc, char **argv ) { int *i; char *newConfigFile; + char *newConfigDir; char *newUrls; char *regService = NULL; @@ -320,11 +322,17 @@ int main( int argc, char **argv ) configfile = newConfigFile; Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 ); } + + newConfigDir = (char*)lutil_getRegParam( regService, "ConfigDir" ); + if ( newConfigDir != NULL ) { + configdir = newConfigDir; + Debug ( LDAP_DEBUG_ANY, "new config dir from registry is: %s\n", configdir, 0, 0 ); + } } #endif while ( (i = getopt( argc, argv, - "c:d:f:h:n:o:s:StT:V" + "c:d:f:F:h:n:o:s:StT:V" #if LDAP_PF_INET6 "46" #endif @@ -354,12 +362,12 @@ int main( int argc, char **argv ) break; case 'c': /* provide sync cookie, override if exist in replica */ - scp = (struct sync_cookie *) ch_calloc( 1, sizeof( struct sync_cookie )); - ber_str2bv( optarg, strlen( optarg ), 1, &cookie ); - ber_bvarray_add( &scp->octet_str, &cookie ); + scp = (struct sync_cookie *) ch_calloc( 1, + sizeof( struct sync_cookie )); + ber_str2bv( optarg, 0, 1, &scp->octet_str ); slap_parse_sync_cookie( scp ); - LDAP_STAILQ_FOREACH( scp_entry, &SLAPD_GLOBAL(sync_cookie), sc_next ) { + LDAP_STAILQ_FOREACH( scp_entry, &slap_sync_cookie, sc_next ) { if ( scp->rid == scp_entry->rid ) { Debug( LDAP_DEBUG_ANY, "main: duplicated replica id in cookies\n", @@ -368,7 +376,7 @@ int main( int argc, char **argv ) goto destroy; } } - LDAP_STAILQ_INSERT_TAIL( &SLAPD_GLOBAL(sync_cookie), scp, sc_next ); + LDAP_STAILQ_INSERT_TAIL( &slap_sync_cookie, scp, sc_next ); break; case 'd': /* set debug level and 'do not detach' flag */ @@ -386,6 +394,10 @@ int main( int argc, char **argv ) configfile = ch_strdup( optarg ); break; + case 'F': /* use config dir */ + configdir = ch_strdup( optarg ); + break; + case 'o': { char *val = strchr( optarg, '=' ); struct berval opt; @@ -500,7 +512,6 @@ unhandled_option:; (void) ldap_pvt_thread_initialize(); - lutil_set_debug_level( "slapd", slap_debug ); ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug); ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug); ldif_debug = slap_debug; @@ -620,7 +631,13 @@ unhandled_option:; goto destroy; } - if ( read_config( configfile, 0 ) != 0 ) { +#ifdef SLAP_DYNACL + if ( acl_init() ) { + goto destroy; + } +#endif /* SLAP_DYNACL */ + + if ( read_config( configfile, configdir ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 ); @@ -641,13 +658,6 @@ unhandled_option:; } } - if ( glue_sub_init( ) != 0 ) { - Debug( LDAP_DEBUG_ANY, - "subordinate config error\n", - 0, 0, 0 ); - goto destroy; - } - if ( slap_schema_check( ) != 0 ) { Debug( LDAP_DEBUG_ANY, "schema prep error\n", @@ -686,7 +696,7 @@ unhandled_option:; goto destroy; } /* Retrieve slapd's own ctx */ - ldap_pvt_tls_get_option( NULL, LDAP_OPT_X_TLS_CTX, &SLAPD_GLOBAL(tls_ctx) ); + ldap_pvt_tls_get_option( NULL, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx ); /* Restore previous ctx */ ldap_pvt_tls_set_option( NULL, LDAP_OPT_X_TLS_CTX, def_ctx ); } @@ -703,6 +713,9 @@ unhandled_option:; #endif (void) SIGNAL( SIGINT, slap_sig_shutdown ); (void) SIGNAL( SIGTERM, slap_sig_shutdown ); +#ifdef SIGTRAP + (void) SIGNAL( SIGTRAP, slap_sig_shutdown ); +#endif #ifdef LDAP_SIGCHLD (void) SIGNAL( LDAP_SIGCHLD, wait4child ); #endif @@ -723,7 +736,7 @@ unhandled_option:; * FIXME: moved here from slapd_daemon_task() * because back-monitor db_open() needs it */ - time( &SLAPD_GLOBAL(starttime) ); + time( &starttime ); if ( slap_startup( NULL ) != 0 ) { rc = 1; @@ -734,21 +747,21 @@ unhandled_option:; Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 ); - if ( SLAPD_GLOBAL(pid_file) != NULL ) { - FILE *fp = fopen( SLAPD_GLOBAL(pid_file), "w" ); + if ( slapd_pid_file != NULL ) { + FILE *fp = fopen( slapd_pid_file, "w" ); if( fp != NULL ) { fprintf( fp, "%d\n", (int) getpid() ); fclose( fp ); } else { - free(SLAPD_GLOBAL(pid_file)); - SLAPD_GLOBAL(pid_file) = NULL; + free(slapd_pid_file); + slapd_pid_file = NULL; } } - if ( SLAPD_GLOBAL(args_file) != NULL ) { - FILE *fp = fopen( SLAPD_GLOBAL(args_file), "w" ); + if ( slapd_args_file != NULL ) { + FILE *fp = fopen( slapd_args_file, "w" ); if( fp != NULL ) { for ( i = 0; i < g_argc; i++ ) { @@ -757,8 +770,8 @@ unhandled_option:; fprintf( fp, "\n" ); fclose( fp ); } else { - free(SLAPD_GLOBAL(args_file)); - SLAPD_GLOBAL(args_file) = NULL; + free(slapd_args_file); + slapd_args_file = NULL; } } @@ -783,9 +796,9 @@ destroy: /* remember an error during destroy */ rc |= slap_destroy(); - while ( !LDAP_STAILQ_EMPTY( &SLAPD_GLOBAL(sync_cookie) )) { - scp = LDAP_STAILQ_FIRST( &SLAPD_GLOBAL(sync_cookie) ); - LDAP_STAILQ_REMOVE_HEAD( &SLAPD_GLOBAL(sync_cookie), sc_next ); + while ( !LDAP_STAILQ_EMPTY( &slap_sync_cookie )) { + scp = LDAP_STAILQ_FIRST( &slap_sync_cookie ); + LDAP_STAILQ_REMOVE_HEAD( &slap_sync_cookie, sc_next ); ch_free( scp ); } @@ -825,11 +838,11 @@ stop: ldap_pvt_tls_destroy(); #endif - if ( SLAPD_GLOBAL(pid_file) != NULL ) { - unlink( SLAPD_GLOBAL(pid_file) ); + if ( slapd_pid_file != NULL ) { + unlink( slapd_pid_file ); } - if ( SLAPD_GLOBAL(args_file) != NULL ) { - unlink( SLAPD_GLOBAL(args_file) ); + if ( slapd_args_file != NULL ) { + unlink( slapd_args_file ); } config_destroy();