#include "ldap_defaults.h"
#include "slap.h"
-#ifndef HAVE_WINSOCK
#include "lutil.h" /* Get lutil_detach() */
-#endif
+
+int set_socket( struct sockaddr_in *addr );
#ifdef LDAP_SIGCHLD
static RETSIGTYPE wait4child( int sig );
#endif
#ifdef HAVE_WINSOCK
-#define SERVICE_NAME "OpenLDAP"
-
+#define MAIN_RETURN(x) return
struct sockaddr_in bind_addr;
-// in nt_main.c
+/* in nt_main.c */
extern SERVICE_STATUS SLAPDServiceStatus;
extern SERVICE_STATUS_HANDLE hSLAPDServiceStatus;
extern ldap_pvt_thread_cond_t started_event, stopped_event;
}
#else
#define SERVICE_EXIT( e, n )
+#define MAIN_RETURN(x) return(x)
#endif
short port = LDAP_PORT;
{
fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name );
fprintf( stderr, "\n [-a bind-address] [-i] [-u]" );
+#ifdef HAVE_WINSOCK
+ fprintf( stderr, " [-v NTserviceName]" );
+#endif
#if LDAP_CONNECTIONLESS
fprintf( stderr, " [-c]" );
#endif
int syslogUser = DEFAULT_SYSLOG_USER;
#endif
#ifdef HAVE_WINSOCK
+ char *NTservice = SERVICE_NAME;
char *configfile = ".\\slapd.conf";
#else
char *configfile = SLAPD_DEFAULT_CONFIGFILE;
g_argv = argv;
#ifdef HAVE_WINSOCK
- //if ( is_NT_Service )
{
int *newPort;
int *newDebugLevel;
char *newConfigFile;
ldap_debug = 0xffff;
- if ( is_NT_Service ) CommenceStartupProcessing( SERVICE_NAME, slap_set_shutdown );
+ if ( is_NT_Service ) CommenceStartupProcessing( NTservice, slap_set_shutdown );
newPort = (int*)getRegParam( NULL, "Port" );
if ( newPort != NULL )
{
#endif
#ifdef LDAP_CONNECTIONLESS
"c"
+#endif
+#ifdef HAVE_WINSOCK
+ "v:"
#endif
)) != EOF ) {
switch ( i ) {
groupname = ch_strdup( optarg );
break;
#endif /* SETUID && GETUID */
-
+#ifdef HAVE_WINSOCK
+ case 'v': /* NT service name */
+ NTservice = ch_strdup( optarg );
+ break;
+#endif
default:
usage( argv[0] );
rc = 1;
Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );
- if ( (serverName = strrchr( argv[0], '/' )) == NULL ) {
+ if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
serverName = ch_strdup( argv[0] );
} else {
serverName = ch_strdup( serverName + 1 );
tcps = set_socket( inetd ? NULL : &bind_addr );
+ if ( tcps == -1 )
+ goto destroy;
(void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing );
(void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown );
(void) SIGNAL( LDAP_SIGCHLD, wait4child );
#endif
#ifdef HAVE_WINSOCK
- // SIGBREAK is generated when Ctrl-Break is pressed.
+ /* SIGBREAK is generated when Ctrl-Break is pressed. */
(void) SIGNAL( SIGBREAK, slap_set_shutdown );
#endif
time( &starttime );
#ifdef HAVE_WINSOCK
- LogSlapdStartedEvent( SERVICE_NAME, slap_debug, configfile, port, udp );
+ LogSlapdStartedEvent( NTservice, slap_debug, configfile, port, udp );
#endif
rc = slapd_daemon( &args );
#ifdef HAVE_WINSOCK
- // Throw away the event that we used during the startup process.
+ /* Throw away the event that we used during the startup process. */
if ( is_NT_Service )
ldap_pvt_thread_cond_destroy( &started_event );
#endif
stop:
#ifdef HAVE_WINSOCK
- LogSlapdStoppedEvent( SERVICE_NAME );
+ LogSlapdStoppedEvent( NTservice );
#endif
Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
#ifdef HAVE_WINSOCK
closelog();
- return rc;
+ MAIN_RETURN(rc);
}