mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-04-06 15:00:40 +08:00
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.
This commit is contained in:
parent
c51e647870
commit
3550bc48c0
@ -3,7 +3,7 @@
|
||||
slapd \- Stand-alone LDAP Daemon
|
||||
.SH SYNOPSIS
|
||||
.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
|
||||
.SH DESCRIPTION
|
||||
@ -87,10 +87,16 @@ facility.
|
||||
Specifies the slapd configuration file. The default is
|
||||
.BR ETCDIR/slapd.conf .
|
||||
.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"
|
||||
.B slapd
|
||||
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
|
||||
.B \-i
|
||||
This option tells
|
||||
|
@ -50,12 +50,12 @@ extern char *slapd_args_file;
|
||||
|
||||
void *
|
||||
slapd_daemon(
|
||||
void *port
|
||||
void *ptr
|
||||
)
|
||||
{
|
||||
struct sockaddr_in *addr = ptr;
|
||||
int i;
|
||||
int tcps, ns;
|
||||
struct sockaddr_in addr;
|
||||
fd_set readfds;
|
||||
fd_set writefds;
|
||||
FILE *fp;
|
||||
@ -104,11 +104,7 @@ slapd_daemon(
|
||||
"unknown", 0 );
|
||||
}
|
||||
|
||||
(void) memset( (void *) &addr, '\0', sizeof(addr) );
|
||||
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 ) {
|
||||
if ( bind( tcps, (struct sockaddr *) addr, sizeof(*addr) ) == -1 ) {
|
||||
Debug( LDAP_DEBUG_ANY, "bind() failed errno %d (%s)\n",
|
||||
errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
|
||||
"unknown", 0 );
|
||||
|
@ -62,7 +62,7 @@ main( int argc, char **argv )
|
||||
int i;
|
||||
int inetd = 0;
|
||||
int rc = 0;
|
||||
int port;
|
||||
struct sockaddr_in bind_addr;
|
||||
int udp;
|
||||
#ifdef LOG_LOCAL4
|
||||
int syslogUser = DEFAULT_SYSLOG_USER;
|
||||
@ -72,16 +72,27 @@ main( int argc, char **argv )
|
||||
int serverMode = SLAP_SERVER_MODE;
|
||||
|
||||
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_argv = argv;
|
||||
|
||||
#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
|
||||
while ( (i = getopt( argc, argv, "d:f:ip:s:u" )) != EOF ) {
|
||||
while ( (i = getopt( argc, argv, "d:f:ia:p:s:u" )) != EOF ) {
|
||||
#endif
|
||||
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
|
||||
case 'd': /* turn on debugging */
|
||||
if ( optarg[0] == '?' ) {
|
||||
@ -132,21 +143,24 @@ main( int argc, char **argv )
|
||||
inetd = 1;
|
||||
break;
|
||||
|
||||
case 'p': /* port on which to listen */
|
||||
port = atoi( optarg );
|
||||
break;
|
||||
case 'p': { /* port on which to listen */
|
||||
int port = atoi( optarg );
|
||||
if(! port ) {
|
||||
fprintf(stderr, "-p %s must be numeric\n", optarg);
|
||||
} else {
|
||||
bind_addr.sin_port = htons(port);
|
||||
}
|
||||
} break;
|
||||
|
||||
case 's': /* set syslog level */
|
||||
ldap_syslog = atoi( optarg );
|
||||
break;
|
||||
|
||||
#ifdef LOG_LOCAL4
|
||||
|
||||
case 'l': /* set syslog local user */
|
||||
syslogUser = cnvt_str2int( optarg, syslog_types,
|
||||
DEFAULT_SYSLOG_USER );
|
||||
break;
|
||||
|
||||
#endif
|
||||
|
||||
case 'u': /* do udp */
|
||||
@ -221,7 +235,7 @@ main( int argc, char **argv )
|
||||
time( &starttime );
|
||||
|
||||
status = ldap_pvt_thread_create( &listener_tid, 0,
|
||||
slapd_daemon, (void *) port );
|
||||
slapd_daemon, &bind_addr );
|
||||
if ( status != 0 )
|
||||
{
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
|
@ -35,6 +35,7 @@ LDAPADD=../clients/tools/ldapadd
|
||||
LDAPMODRDN=../clients/tools/ldapmodrdn
|
||||
SLAPDTESTER=$PROGDIR/slapd-tester
|
||||
LVL=5
|
||||
ADDR=127.0.0.1
|
||||
PORT=9009
|
||||
SLAVEPORT=9010
|
||||
DBDIR=./test-db
|
||||
|
@ -28,7 +28,7 @@ if [ $RC != 0 ]; then
|
||||
fi
|
||||
|
||||
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=$!
|
||||
|
||||
echo "Using ldapsearch to retrieve all the entries..."
|
||||
|
@ -28,7 +28,7 @@ if [ $RC != 0 ]; then
|
||||
fi
|
||||
|
||||
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=$!
|
||||
|
||||
echo "Using ldapsearch to retrieve all the entries..."
|
||||
|
Loading…
x
Reference in New Issue
Block a user