Skip to content
Snippets Groups Projects
Commit 3550bc48 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Add slapd -a address support. Allows you to bind to a specific

address.  Useful for running multiple servers in a virtual hosting
environment.
Modified test001-ldif2ldbm to verify this functionality.  Assumes
localhost is 127.0.0.1.
parent c51e6478
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
slapd \- Stand-alone LDAP Daemon slapd \- Stand-alone LDAP Daemon
.SH SYNOPSIS .SH SYNOPSIS
.B LIBEXECDIR/slapd [\-d debug\-level] .B LIBEXECDIR/slapd [\-d debug\-level]
.B [\-f slapd\-config\-file] [\-p port\-number] .B [\-f slapd\-config\-file] [\-a address] [\-p port\-number]
.B [\-s syslog\-level] [\-l syslog\-local\-user] [\-i] .B [\-s syslog\-level] [\-l syslog\-local\-user] [\-i]
.B .B
.SH DESCRIPTION .SH DESCRIPTION
...@@ -87,10 +87,16 @@ facility. ...@@ -87,10 +87,16 @@ facility.
Specifies the slapd configuration file. The default is Specifies the slapd configuration file. The default is
.BR ETCDIR/slapd.conf . .BR ETCDIR/slapd.conf .
.TP .TP
.BI \-a " address"
.B slapd
will listen on all addresses (INADDR_ANY) unless this option
is given to override the default. The address is expected in
Internet standard '.' format.
.TP
.BI \-p " port\-number" .BI \-p " port\-number"
.B slapd .B slapd
will listen on the default LDAP port (389) unless this option is given will listen on the default LDAP port (389) unless this option is given
to override the default. to override the default. A numeric port number is expected.
.TP .TP
.B \-i .B \-i
This option tells This option tells
......
...@@ -50,12 +50,12 @@ extern char *slapd_args_file; ...@@ -50,12 +50,12 @@ extern char *slapd_args_file;
void * void *
slapd_daemon( slapd_daemon(
void *port void *ptr
) )
{ {
struct sockaddr_in *addr = ptr;
int i; int i;
int tcps, ns; int tcps, ns;
struct sockaddr_in addr;
fd_set readfds; fd_set readfds;
fd_set writefds; fd_set writefds;
FILE *fp; FILE *fp;
...@@ -104,11 +104,7 @@ slapd_daemon( ...@@ -104,11 +104,7 @@ slapd_daemon(
"unknown", 0 ); "unknown", 0 );
} }
(void) memset( (void *) &addr, '\0', sizeof(addr) ); if ( bind( tcps, (struct sockaddr *) addr, sizeof(*addr) ) == -1 ) {
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons( (int)port );
if ( bind( tcps, (struct sockaddr *) &addr, sizeof(addr) ) == -1 ) {
Debug( LDAP_DEBUG_ANY, "bind() failed errno %d (%s)\n", Debug( LDAP_DEBUG_ANY, "bind() failed errno %d (%s)\n",
errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] : errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
"unknown", 0 ); "unknown", 0 );
......
...@@ -62,7 +62,7 @@ main( int argc, char **argv ) ...@@ -62,7 +62,7 @@ main( int argc, char **argv )
int i; int i;
int inetd = 0; int inetd = 0;
int rc = 0; int rc = 0;
int port; struct sockaddr_in bind_addr;
int udp; int udp;
#ifdef LOG_LOCAL4 #ifdef LOG_LOCAL4
int syslogUser = DEFAULT_SYSLOG_USER; int syslogUser = DEFAULT_SYSLOG_USER;
...@@ -72,16 +72,27 @@ main( int argc, char **argv ) ...@@ -72,16 +72,27 @@ main( int argc, char **argv )
int serverMode = SLAP_SERVER_MODE; int serverMode = SLAP_SERVER_MODE;
configfile = SLAPD_DEFAULT_CONFIGFILE; configfile = SLAPD_DEFAULT_CONFIGFILE;
port = LDAP_PORT;
(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(LDAP_PORT);
g_argc = argc; g_argc = argc;
g_argv = argv; g_argv = argv;
#ifdef SLAPD_BDB2 #ifdef SLAPD_BDB2
while ( (i = getopt( argc, argv, "d:f:ip:s:ut" )) != EOF ) { while ( (i = getopt( argc, argv, "d:f:ia:p:s:ut" )) != EOF ) {
#else #else
while ( (i = getopt( argc, argv, "d:f:ip:s:u" )) != EOF ) { while ( (i = getopt( argc, argv, "d:f:ia:p:s:u" )) != EOF ) {
#endif #endif
switch ( i ) { switch ( i ) {
case 'a': /* bind address */
if(!inet_aton(optarg, &bind_addr.sin_addr)) {
fprintf(stderr, "invalid address (%s) for -a option", optarg);
}
break;
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
case 'd': /* turn on debugging */ case 'd': /* turn on debugging */
if ( optarg[0] == '?' ) { if ( optarg[0] == '?' ) {
...@@ -132,21 +143,24 @@ main( int argc, char **argv ) ...@@ -132,21 +143,24 @@ main( int argc, char **argv )
inetd = 1; inetd = 1;
break; break;
case 'p': /* port on which to listen */ case 'p': { /* port on which to listen */
port = atoi( optarg ); int port = atoi( optarg );
break; if(! port ) {
fprintf(stderr, "-p %s must be numeric\n", optarg);
} else {
bind_addr.sin_port = htons(port);
}
} break;
case 's': /* set syslog level */ case 's': /* set syslog level */
ldap_syslog = atoi( optarg ); ldap_syslog = atoi( optarg );
break; break;
#ifdef LOG_LOCAL4 #ifdef LOG_LOCAL4
case 'l': /* set syslog local user */ case 'l': /* set syslog local user */
syslogUser = cnvt_str2int( optarg, syslog_types, syslogUser = cnvt_str2int( optarg, syslog_types,
DEFAULT_SYSLOG_USER ); DEFAULT_SYSLOG_USER );
break; break;
#endif #endif
case 'u': /* do udp */ case 'u': /* do udp */
...@@ -221,7 +235,7 @@ main( int argc, char **argv ) ...@@ -221,7 +235,7 @@ main( int argc, char **argv )
time( &starttime ); time( &starttime );
status = ldap_pvt_thread_create( &listener_tid, 0, status = ldap_pvt_thread_create( &listener_tid, 0,
slapd_daemon, (void *) port ); slapd_daemon, &bind_addr );
if ( status != 0 ) if ( status != 0 )
{ {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
......
...@@ -35,6 +35,7 @@ LDAPADD=../clients/tools/ldapadd ...@@ -35,6 +35,7 @@ LDAPADD=../clients/tools/ldapadd
LDAPMODRDN=../clients/tools/ldapmodrdn LDAPMODRDN=../clients/tools/ldapmodrdn
SLAPDTESTER=$PROGDIR/slapd-tester SLAPDTESTER=$PROGDIR/slapd-tester
LVL=5 LVL=5
ADDR=127.0.0.1
PORT=9009 PORT=9009
SLAVEPORT=9010 SLAVEPORT=9010
DBDIR=./test-db DBDIR=./test-db
......
...@@ -28,7 +28,7 @@ if [ $RC != 0 ]; then ...@@ -28,7 +28,7 @@ if [ $RC != 0 ]; then
fi fi
echo "Starting slapd on TCP/IP port $PORT..." echo "Starting slapd on TCP/IP port $PORT..."
$SLAPD -f $CONF -p $PORT -d $LVL $TIMING > $MASTERLOG 2>&1 & $SLAPD -f $CONF -p $PORT -a $ADDR -d $LVL $TIMING > $MASTERLOG 2>&1 &
PID=$! PID=$!
echo "Using ldapsearch to retrieve all the entries..." echo "Using ldapsearch to retrieve all the entries..."
......
...@@ -28,7 +28,7 @@ if [ $RC != 0 ]; then ...@@ -28,7 +28,7 @@ if [ $RC != 0 ]; then
fi fi
echo "Starting slapd on TCP/IP port $PORT..." echo "Starting slapd on TCP/IP port $PORT..."
$SLAPD -f $CONF -p $PORT -d $LVL $TIMING > $MASTERLOG 2>&1 & $SLAPD -f $CONF -p $PORT -a $ADDR -d $LVL $TIMING > $MASTERLOG 2>&1 &
PID=$! PID=$!
echo "Using ldapsearch to retrieve all the entries..." echo "Using ldapsearch to retrieve all the entries..."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment