]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / main.c
index 1c08e6bd417b6a5d243f63c9784739fc29a8da26..3176411796b5336c491291ba608aa7563b0afe16 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 static RETSIGTYPE wait4child( int sig );
 #endif
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_SERVICE_MANAGER
 #define MAIN_RETURN(x) return
 struct sockaddr_in     bind_addr;
 
 /* in nt_main.c */
-extern SERVICE_STATUS                  SLAPDServiceStatus;
-extern SERVICE_STATUS_HANDLE   hSLAPDServiceStatus;
+LIBLUTIL_F (SERVICE_STATUS)            SLAPDServiceStatus;
+LIBLUTIL_F (SERVICE_STATUS_HANDLE)     hSLAPDServiceStatus;
 extern ldap_pvt_thread_cond_t  started_event,          stopped_event;
 extern int       is_NT_Service;
 
-void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
-void LogSlapdStoppedEvent( char *svc );
-
 void CommenceStartupProcessing( LPCTSTR serviceName,
                                                           void(*stopper)(int));
 void ReportSlapdShutdownComplete( void );
 void *getRegParam( char *svc, char *value );
 
-#define SERVICE_EXIT( e, n ) \
-               if ( is_NT_Service ) \
-{ \
-                       SLAPDServiceStatus.dwWin32ExitCode                              = e; \
-                       SLAPDServiceStatus.dwServiceSpecificExitCode    = n; \
-} 
+#define SERVICE_EXIT( e, n )   do { \
+       if ( is_NT_Service ) { \
+               SLAPDServiceStatus.dwWin32ExitCode                              = (e); \
+               SLAPDServiceStatus.dwServiceSpecificExitCode    = (n); \
+       } \
+} while ( 0 )
+
 #else
 #define SERVICE_EXIT( e, n )
 #define MAIN_RETURN(x) return(x)
 #endif
 
+#ifdef HAVE_NT_EVENT_LOG
+void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
+void LogSlapdStoppedEvent( char *svc );
+#endif
+
 /*
  * when more than one slapd is running on one machine, each one might have
  * it's own LOCAL for syslogging and must have its own pid/args files
@@ -108,14 +112,10 @@ usage( char *name )
 #ifdef LOG_LOCAL4
                "\t-l sysloguser\tSyslog User (default: LOCAL4)\n"
 #endif
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_EVENT_LOG
                "\t-n NTserviceName\tNT service name\n"
 #endif
 
-               "\t-p port\tLDAP Port\n"
-#ifdef HAVE_TLS
-               "\t-P port\tLDAP over TLS Port\n"
-#endif
                "\t-s level\tSyslog Level\n"
 #ifdef SLAPD_BDB2
                "\t-t\t\tEnable BDB2 timing\n"
@@ -126,7 +126,7 @@ usage( char *name )
     );
 }
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_SERVICE_MANAGER
 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
 #else
 int main( int argc, char **argv )
@@ -142,8 +142,11 @@ int main( int argc, char **argv )
 #ifdef LOG_LOCAL4
     int     syslogUser = DEFAULT_SYSLOG_USER;
 #endif
-#ifdef HAVE_WINSOCK
+
+#ifdef HAVE_NT_EVENT_LOG
        char        *NTservice  = SERVICE_NAME;
+#endif
+#ifdef HAVE_NT_SERVICE_MANAGER
        char            *configfile = ".\\slapd.conf";
 #else
        char            *configfile = SLAPD_DEFAULT_CONFIGFILE;
@@ -151,13 +154,6 @@ int main( int argc, char **argv )
        char        *serverName;
        int         serverMode = SLAP_SERVER_MODE;
 
-       int port = LDAP_PORT;
-#ifdef HAVE_TLS
-       int tls_port = LDAPS_PORT;
-#else
-       int tls_port = 0;
-#endif
-
 #ifdef CSRIMALLOC
        FILE *leakfile;
        if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
@@ -168,7 +164,7 @@ int main( int argc, char **argv )
        g_argc = argc;
        g_argv = argv;
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_SERVICE_MANAGER
        {
                int *i;
                char *newConfigFile;
@@ -177,20 +173,6 @@ int main( int argc, char **argv )
                        CommenceStartupProcessing( NTservice, slap_sig_shutdown );
                }
 
-               i = (int*)getRegParam( NULL, "Port" );
-               if ( i != NULL )
-               {
-                       port = *i;
-                       Debug ( LDAP_DEBUG_ANY, "new port from registry is: %d\n", port, 0, 0 );
-               }
-#ifdef HAVE_TLS
-               i = (int*)getRegParam( NULL, "TLSPort" );
-               if ( i != NULL )
-               {
-                       tls_port = *i;
-                       Debug ( LDAP_DEBUG_ANY, "new TLS port from registry is: %d\n", tls_port, 0, 0 );
-               }
-#endif
                i = (int*)getRegParam( NULL, "DebugLevel" );
                if ( i != NULL ) 
                {
@@ -207,7 +189,7 @@ int main( int argc, char **argv )
 #endif
 
        while ( (i = getopt( argc, argv,
-                            "d:f:h:p:s:"
+                            "d:f:h:s:"
 #ifdef LOG_LOCAL4
                             "l:"
 #endif
@@ -220,11 +202,8 @@ int main( int argc, char **argv )
 #ifdef LDAP_CONNECTIONLESS
                                 "c"
 #endif
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_EVENT_LOG
                                 "n:"
-#endif
-#ifdef HAVE_TLS
-                            "P:"
 #endif
                             )) != EOF ) {
                switch ( i ) {
@@ -248,30 +227,6 @@ int main( int argc, char **argv )
                        configfile = ch_strdup( optarg );
                        break;
 
-               case 'p': {     /* port on which to listen */
-                               int p = atoi( optarg );
-                               if(! p ) {
-                                       fprintf(stderr, "-p %s must be numeric\n", optarg);
-                               } else if( p < 0 || p >= 1<<16) {
-                                       fprintf(stderr, "-p %s invalid\n", optarg);
-                               } else {
-                                       port = p;
-                               }
-                       } break;
-
-#ifdef HAVE_TLS
-               case 'P': {     /* port on which to listen for TLS */
-                               int p = atoi( optarg );
-                               if(! p ) {
-                                       fprintf(stderr, "-P %s must be numeric\n", optarg);
-                               } else if( p < 0 || p >= 1<<16) {
-                                       fprintf(stderr, "-P %s invalid\n", optarg);
-                               } else {
-                                       tls_port = p;
-                               }
-                       } break;
-#endif
-
                case 's':       /* set syslog level */
                        ldap_syslog = atoi( optarg );
                        break;
@@ -309,7 +264,7 @@ int main( int argc, char **argv )
                        break;
 #endif /* SETUID && GETUID */
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_EVENT_LOG
                case 'n':  /* NT service name */
                        NTservice = ch_strdup( optarg );
                        break;
@@ -336,11 +291,11 @@ int main( int argc, char **argv )
 
 #ifdef LOG_LOCAL4
        openlog( serverName, OPENLOG_OPTIONS, syslogUser );
-#else
+#elif LOG_DEBUG
        openlog( serverName, OPENLOG_OPTIONS );
 #endif
 
-       if( slapd_daemon_init( urls, port, tls_port ) != 0 ) {
+       if( slapd_daemon_init( urls ) != 0 ) {
                rc = 1;
                SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
                goto stop;
@@ -352,6 +307,16 @@ int main( int argc, char **argv )
        }
 #endif
 
+       extops_init();
+
+#ifdef SLAPD_MODULES
+       if ( module_init() != 0 ) {
+               rc = 1;
+               SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 17 );
+               goto destroy;
+       }
+#endif
+
        if ( slap_init( serverMode, serverName ) != 0 ) {
                rc = 1;
                SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
@@ -389,7 +354,7 @@ int main( int argc, char **argv )
 #endif
 
 #ifndef HAVE_WINSOCK
-               lutil_detach( no_detach, 0 );
+       lutil_detach( no_detach, 0 );
 #endif /* HAVE_WINSOCK */
 
 #ifdef CSRIMALLOC
@@ -425,13 +390,13 @@ int main( int argc, char **argv )
                }
        }
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_EVENT_LOG
        LogSlapdStartedEvent( NTservice, slap_debug, configfile, urls );
 #endif
 
        rc = slapd_daemon();
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_SERVICE_MANAGER
        /* Throw away the event that we used during the startup process. */
        if ( is_NT_Service )
                ldap_pvt_thread_cond_destroy( &started_event );
@@ -445,18 +410,26 @@ destroy:
        /* remember an error during destroy */
        rc |= slap_destroy();
 
+#ifdef SLAPD_MODULES
+       module_kill();
+#endif
+
+       extops_kill();
+
 stop:
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_EVENT_LOG
        LogSlapdStoppedEvent( NTservice );
 #endif
 
        Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
 
-#ifdef HAVE_WINSOCK
+#ifdef HAVE_NT_SERVICE_MANAGER
        ReportSlapdShutdownComplete();
 #endif
 
+#ifdef LOG_DEBUG
     closelog();
+#endif
        slapd_daemon_destroy();
 
 #ifdef CSRIMALLOC