#include "ldap_defaults.h"
#include "slap.h"
-#include "lutil.h" /* Get lutil_detach() */
-
-int set_socket( struct sockaddr_in *addr );
+#include "lutil.h"
#ifdef LDAP_SIGCHLD
static RETSIGTYPE wait4child( int sig );
#endif
short port = LDAP_PORT;
+#ifdef HAVE_TLS
+short tls_port = LDAP_TLS_PORT;
+#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
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]" );
+ fprintf( stderr, " [-n NTserviceName]" );
#endif
#if LDAP_CONNECTIONLESS
fprintf( stderr, " [-c]" );
time_t starttime;
struct sockaddr_in bind_addr;
-int tcps;
+ber_int_t tcps;
+#ifdef HAVE_TLS
+struct sockaddr_in tls_bind_addr;
+ber_int_t tls_tcps;
+#endif
#ifdef HAVE_WINSOCK
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
-{
#else
int main( int argc, char **argv )
-{
#endif
-
+{
int i;
int inetd = 0;
int rc;
#endif
char *serverName;
int serverMode = SLAP_SERVER_MODE;
+ int use_tls_port = 0;
(void) memset( (void*) &bind_addr, '\0', sizeof(bind_addr));
bind_addr.sin_family = AF_INET;
bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
bind_addr.sin_port = htons(port);
+#ifdef HAVE_TLS
+ tls_bind_addr.sin_family = AF_INET;
+ tls_bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ tls_bind_addr.sin_port = htons(tls_port);
+#endif
g_argc = argc;
g_argv = argv;
Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
}
}
-
#endif
while ( (i = getopt( argc, argv,
"c"
#endif
#ifdef HAVE_WINSOCK
- "v:"
+ "n:"
+#endif
+#ifdef HAVE_TLS
+ "P:T"
#endif
)) != EOF ) {
switch ( i ) {
{
fprintf(stderr, "invalid address (%s) for -a option", optarg);
}
+#ifdef HAVE_TLS
+#ifdef HAVE_WINSOCK
+ tls_bind_addr.sin_addr.S_un.S_addr = inet_addr(optarg);
+#else
+ inet_aton(optarg, &tls_bind_addr.sin_addr);
+#endif
+#endif
break;
#ifdef LDAP_DEBUG
}
} break;
+#ifdef HAVE_TLS
+ case 'P': { /* port on which to listen for TLS */
+ tls_port = (short)atoi( optarg );
+ if(! tls_port ) {
+ fprintf(stderr, "-P %s must be numeric\n", optarg);
+ } else {
+ tls_bind_addr.sin_port = htons(tls_port);
+ }
+ } break;
+#endif
+
case 's': /* set syslog level */
ldap_syslog = atoi( optarg );
break;
break;
#endif /* SETUID && GETUID */
#ifdef HAVE_WINSOCK
- case 'v': /* NT service name */
+ case 'n': /* NT service name */
NTservice = ch_strdup( optarg );
break;
+#endif
+#ifdef HAVE_TLS
+ case 'T': /* Bind on TLS port */
+ use_tls_port = 1;
+ break;
#endif
default:
usage( argv[0] );
goto destroy;
}
+#ifdef HAVE_TLS
+ ldap_pvt_tls_init();
+ ldap_pvt_tls_init_def_ctx();
+#endif
tcps = set_socket( inetd ? NULL : &bind_addr );
if ( tcps == -1 )
goto destroy;
+#ifdef HAVE_TLS
+ if ( use_tls_port ) {
+ tls_tcps = set_socket( inetd ? NULL : &tls_bind_addr );
+ if ( tls_tcps == -1 )
+ goto destroy;
+ } else {
+ tls_tcps = -1;
+ }
+#endif
(void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing );
(void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown );
#ifdef LDAP_SIGCHLD
(void) SIGNAL( LDAP_SIGCHLD, wait4child );
#endif
-#ifdef HAVE_WINSOCK
+#ifdef SIGBREAK
/* SIGBREAK is generated when Ctrl-Break is pressed. */
(void) SIGNAL( SIGBREAK, slap_set_shutdown );
#endif
FILE *fp;
args.addr = &bind_addr;
+#ifdef HAVE_TLS
+ args.tls_addr = &tls_bind_addr;
+#endif
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
} else {
args.addr = NULL;
+#ifdef HAVE_TLS
+ args.tls_addr = NULL;
+#endif
}
args.tcps = tcps;
+#ifdef HAVE_TLS
+ args.tls_tcps = tls_tcps;
+#endif
time( &starttime );
#ifdef HAVE_WINSOCK
ldap_pvt_thread_cond_destroy( &started_event );
#endif
-
shutdown:
/* remember an error during shutdown */
rc |= slap_shutdown(-1);