[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Second try, Multiple slapd masters
Hi,
I have modified OpenLDAP-1.02 to support multiple master LDAP
servers.
I did this by changing slapd to monitor a second port that will
not log entries to
the replog. Each slurpd daemon is then pointed to the secondary
port so that
no replication entries will be made. This resloves the problem
of one LDAP server
sending the same changes back to the originator.
slapd performs exactly as before if no replicant port is
specified.
slapd -p 389 -r 390 -f slapd.conf
No replication entries will be made for any changes made on port
390.
The replicant port must be specified on the command line for
slapd to
open the second port.
Below is the context diff from release version 1.02
Any comments or suggestions?
Since this is my first time sending out code modifications.
rwroth@netdox.com
diff -c servers/slapd/add.c ../myldap/servers/slapd/add.c
*** servers/slapd/add.c Tue Aug 18 18:30:57 1998
--- ../myldap/servers/slapd/add.c Mon Oct 5 09:51:03 1998
***************
*** 25,30 ****
--- 25,34 ----
extern pthread_mutex_t currenttime_mutex;
extern int global_lastmod;
+ /* rwroth@netdox.com 10/05/1998 */
+ extern int Replicantport;
+ /* End rwroth */
+
static void add_created_attrs();
void
***************
*** 126,132 ****
add_created_attrs( op, e );
}
if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
! replog( be, LDAP_REQ_ADD, e->e_dn, e, 0
);
}
} else {
--- 130,140 ----
add_created_attrs( op, e );
}
if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
! /* rwroth@netdox.com 10/05/1998 */
! if ( conn->port != Replicantport )
! /* End rwroth */
! replog( be, LDAP_REQ_ADD,
e->e_dn,
! e, 0 );
}
} else {
diff -c servers/slapd/daemon.c ../myldap/servers/slapd/daemon.c
*** servers/slapd/daemon.c Sat Sep 5 12:39:31 1998
--- ../myldap/servers/slapd/daemon.c Tue Oct 6 10:36:00 1998
***************
*** 55,60 ****
--- 55,64 ----
extern int g_argc;
extern char **g_argv;
+ /* rwroth@netdox.com 10/05/1998 */
+ extern int Replicantport;
+ /* End rwroth */
+
int dtblsize;
Connection *c;
***************
*** 76,81 ****
--- 80,94 ----
fd_set writefds;
FILE *fp;
int on = 1;
+ /*
+ * rwroth@netdox.com 10/05/1998
+ * tcpr- Replicant tcp socket, tcpc Current socket connection
+ * source = replicant or slapd (for debug messages)
+ */
+ int tcpr, tcpc;
+ char *source;
+ struct sockaddr_in raddr;
+ /* End rwroth */
#ifdef USE_SYSCONF
dtblsize = sysconf( _SC_OPEN_MAX );
***************
*** 148,153 ****
--- 161,211 ----
exit( 1 );
}
+ /* rwroth@netdox.com 10/05/1998 */
+ if ( Replicantport ) {
+ if ( (tcpr = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
{
+ Debug( LDAP_DEBUG_ANY,
+ "replicant: socket() failed errno %d (%s)",
+ errno, errno > -1 && errno < sys_nerr ?
+ sys_errlist[errno] : "unknown", 0 );
+
+ exit( 1 );
+ }
+
+ i = 1;
+ if ( setsockopt( tcpr, SOL_SOCKET, SO_REUSEADDR, (char
*) &i,
+ sizeof(i) ) == -1 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "replicant: setsockopt() failed errno %d
(%s)",
+ errno, errno > -1 && errno < sys_nerr ?
+ sys_errlist[errno] : "unknown", 0 );
+ }
+
+ (void) memset( (void *) &raddr, '\0', sizeof(addr) );
+ raddr.sin_family = AF_INET;
+ raddr.sin_addr.s_addr = INADDR_ANY;
+ raddr.sin_port = htons( Replicantport );
+ if ( bind( tcpr, (struct sockaddr *) &raddr,
+ sizeof(raddr) ) == -1 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "replicant: bind() failed errno %d (%s)\n",
+ errno, errno > -1 && errno < sys_nerr ?
+ sys_errlist[errno] : "unknown", 0 );
+
+ exit( 1 );
+ }
+
+ if ( listen( tcpr, 5 ) == -1 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "replicant: listen() failed errno %d (%s)",
+ errno, errno > -1 && errno < sys_nerr ?
+ sys_errlist[errno] : "unknown", 0 );
+
+ exit( 1 );
+ }
+ }
+ /* End rwroth */
+
(void) SIGNAL( SIGPIPE, SIG_IGN );
#ifdef linux
/*
***************
*** 164,170 ****
(void) SIGNAL( SIGINT, (void *) set_shutdown );
(void) SIGNAL( SIGHUP, (void *) set_shutdown );
! Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
#ifdef SLAPD_PIDFILE
if ( (fp = fopen( SLAPD_PIDFILE, "w" )) != NULL ) {
fprintf( fp, "%d\n", getpid() );
--- 222,238 ----
(void) SIGNAL( SIGINT, (void *) set_shutdown );
(void) SIGNAL( SIGHUP, (void *) set_shutdown );
! /* rwroth@netdox.com 10/05/1998 */
! if ( Replicantport ) {
! Debug( LDAP_DEBUG_ANY,
! "slapd starting port %d, Replicant port %d\n",
! port, Replicantport, 0 );
! }
! else {
! Debug( LDAP_DEBUG_ANY, "slapd starting port %d\n", port,
0, 0 );
! }
! /* End rwroth */
!
#ifdef SLAPD_PIDFILE
if ( (fp = fopen( SLAPD_PIDFILE, "w" )) != NULL ) {
fprintf( fp, "%d\n", getpid() );
***************
*** 195,205 ****
FD_ZERO( &readfds );
FD_SET( tcps, &readfds );
pthread_mutex_lock( &active_threads_mutex );
- Debug( LDAP_DEBUG_CONNS,
- "listening for connections on %d, activity on:",
- tcps, 0, 0 );
pthread_mutex_lock( &new_conn_mutex );
for ( i = 0; i < dtblsize; i++ ) {
if ( c[i].c_sb.sb_sd != -1 ) {
--- 263,289 ----
FD_ZERO( &readfds );
FD_SET( tcps, &readfds );
+ /* rwroth@netdox.com 10/05/1998 */
+ if ( Replicantport ) {
+ FD_SET( tcpr, &readfds );
+ }
+ /* End rwroth */
+
pthread_mutex_lock( &active_threads_mutex );
+ /* rwroth@netdox.com 10/05/1998 */
+ if ( Replicantport ) {
+ Debug( LDAP_DEBUG_CONNS,
+ "listening for connections on %d/%d,
activity on:",
+ tcps, tcpr, 0 );
+ }
+ else {
+ Debug( LDAP_DEBUG_CONNS,
+ "listening for connections on %d, activity
on:",
+ tcps, 0, 0 );
+ }
+ /* End rwroth */
+
pthread_mutex_lock( &new_conn_mutex );
for ( i = 0; i < dtblsize; i++ ) {
if ( c[i].c_sb.sb_sd != -1 ) {
***************
*** 217,222 ****
--- 301,307 ----
zero.tv_sec = 0;
zero.tv_usec = 0;
+
Debug( LDAP_DEBUG_CONNS, "before select active_threads
%d\n",
active_threads, 0, 0 );
#if defined(PTHREAD_PREEMPTIVE) || defined(NO_THREADS)
***************
*** 250,275 ****
/* new connection */
pthread_mutex_lock( &new_conn_mutex );
if ( FD_ISSET( tcps, &readfds ) ) {
len = sizeof(from);
! if ( (ns = accept( tcps, (struct sockaddr *)
&from,
&len )) == -1 ) {
Debug( LDAP_DEBUG_ANY,
! "accept() failed errno %d (%s)",
errno,
errno > -1 && errno < sys_nerr ?
! sys_errlist[errno] : "unknown", 0 );
pthread_mutex_unlock( &new_conn_mutex );
continue;
}
if ( ioctl( ns, FIONBIO, (caddr_t) &on ) == -1 )
{
Debug( LDAP_DEBUG_ANY,
! "FIONBIO ioctl on %d failed\n", ns,
0, 0 );
}
c[ns].c_sb.sb_sd = ns;
- Debug( LDAP_DEBUG_CONNS, "new connection on
%d\n", ns,
- 0, 0 );
pthread_mutex_lock( &ops_mutex );
c[ns].c_connid = num_conns++;
pthread_mutex_unlock( &ops_mutex );
--- 335,394 ----
/* new connection */
pthread_mutex_lock( &new_conn_mutex );
+
+ /* rwroth@netdox.com 10/05/1998 */
+ tcpc = (int)NULL;
+ /* End rwroth */
if ( FD_ISSET( tcps, &readfds ) ) {
+ tcpc = tcps;
+ source = "slapd";
+ }
+ /* rwroth@netdox.com 10/05/1998 */
+ else if ( Replicantport ) {
+ if ( FD_ISSET( tcpr, &readfds ) ) {
+ tcpc = tcpr;
+ source = "replicant";
+ }
+ }
+
+ if ( tcpc ) {
+ /* End rwroth */
len = sizeof(from);
! /* rwroth@netdox.com 10/05/1998 */
! if ( (ns = accept( tcpc, (struct sockaddr *)
&from,
&len )) == -1 ) {
Debug( LDAP_DEBUG_ANY,
! "%s: accept() failed errno %d (%s)",
! source, errno,
errno > -1 && errno < sys_nerr ?
! sys_errlist[errno] : "unknown" );
! /* End rwroth */
!
pthread_mutex_unlock( &new_conn_mutex );
continue;
}
if ( ioctl( ns, FIONBIO, (caddr_t) &on ) == -1 )
{
+
+ /* rwroth@netdox.com 10/05/1998 */
Debug( LDAP_DEBUG_ANY,
! "%s: FIONBIO ioctl on %d failed\n",
! source, ns, 0 );
! /* End rwroth */
}
+ /* rwroth@netdox.com 10/05/1998 */
+ if ( tcpc == tcpr )
+ c[ns].port = Replicantport;
+ else
+ c[ns].port = port;
+ /* End rwroth */
c[ns].c_sb.sb_sd = ns;
+ /* rwroth@netdox.com 10/05/1998 */
+ Debug( LDAP_DEBUG_CONNS,
+ "%s: new connection on %d\n", source, ns, 0
);
+ /* End rwroth */
+
pthread_mutex_lock( &ops_mutex );
c[ns].c_connid = num_conns++;
pthread_mutex_unlock( &ops_mutex );
***************
*** 311,323 ****
STRING_UNKNOWN))
{
/* DENY ACCESS */
Statslog( LDAP_DEBUG_STATS,
! "conn=%d fd=%d connection from %s (%s)
denied.\n",
c[ns].c_connid, ns,
! client_name == NULL ?
"unknown" : client_name,
! client_addr == NULL ?
"unknown" : client_addr,
! 0 );
close(ns);
pthread_mutex_unlock( &new_conn_mutex );
continue;
--- 430,447 ----
STRING_UNKNOWN))
{
/* DENY ACCESS */
+ /* rwroth@netdox.com 10/05/1998 */
Statslog( LDAP_DEBUG_STATS,
! "%s: conn=%d fd=%d connection from %s
(%s) denied.\n",
! source,
c[ns].c_connid, ns,
! client_name == NULL ?
! "unknown" : client_name,
! client_addr == NULL ?
! "unknown" : client_addr, );
+ /* End rwroth */
+
close(ns);
pthread_mutex_unlock( &new_conn_mutex );
continue;
***************
*** 324,336 ****
}
#endif /* TCP_WRAPPERS */
Statslog( LDAP_DEBUG_STATS,
! "conn=%d fd=%d connection from %s (%s)
accepted.\n",
c[ns].c_connid, ns,
! client_name == NULL ? "unknown"
: client_name,
! client_addr == NULL ? "unknown"
: client_addr,
! 0 );
if ( c[ns].c_addr != NULL ) {
free( c[ns].c_addr );
}
--- 448,463 ----
}
#endif /* TCP_WRAPPERS */
+ /* rwroth@netdox.com 10/05/1998 */
Statslog( LDAP_DEBUG_STATS,
! "%s: conn=%d fd=%d connection from %s (%s)
accepted.\n",
! source,
c[ns].c_connid, ns,
! client_name == NULL ? "unknown" :
client_name,
! client_addr == NULL ? "unknown" :
client_addr );
+ /* End rwroth */
+
if ( c[ns].c_addr != NULL ) {
free( c[ns].c_addr );
}
***************
*** 355,367 ****
}
pthread_mutex_unlock( &new_conn_mutex );
! Debug( LDAP_DEBUG_CONNS, "activity on:", 0, 0, 0 );
for ( i = 0; i < dtblsize; i++ ) {
int r, w;
r = FD_ISSET( i, &readfds );
w = FD_ISSET( i, &writefds );
! if ( i != tcps && (r || w) ) {
Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
r ? "r" : "", w ? "w" : "" );
}
--- 482,499 ----
}
pthread_mutex_unlock( &new_conn_mutex );
! /* rwroth@netdox.com 10/05/1998 */
! Debug( LDAP_DEBUG_CONNS, "%s: activity on:", source, 0,
0 );
! /* End rwroth */
!
for ( i = 0; i < dtblsize; i++ ) {
int r, w;
r = FD_ISSET( i, &readfds );
w = FD_ISSET( i, &writefds );
! /* rwroth@netdox.com 10/05/1998 */
! if ( i != tcpc && (r || w) ) {
! /* End rwroth */
Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
r ? "r" : "", w ? "w" : "" );
}
***************
*** 369,382 ****
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
for ( i = 0; i < dtblsize; i++ ) {
! if ( i == tcps || (! FD_ISSET( i, &readfds ) &&
! FD_ISSET( i, &writefds )) ) {
continue;
}
if ( FD_ISSET( i, &writefds ) ) {
Debug( LDAP_DEBUG_CONNS,
! "signaling write waiter on %d\n", i,
0, 0 );
pthread_mutex_lock(
&active_threads_mutex );
pthread_cond_signal( &c[i].c_wcv );
--- 501,519 ----
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
for ( i = 0; i < dtblsize; i++ ) {
! /* rwroth@netdox.com 10/05/1998 */
! if ( i == tcpc || (! FD_ISSET( i, &readfds ) &&
! /* End rwroth */
! FD_ISSET( i, &writefds )) ) {
continue;
}
if ( FD_ISSET( i, &writefds ) ) {
+ /* rwroth@netdox.com 10/05/1998 */
Debug( LDAP_DEBUG_CONNS,
! "%s: signaling write waiter on
%d\n",
! source, i, 0 );
! /* End rwroth */
pthread_mutex_lock(
&active_threads_mutex );
pthread_cond_signal( &c[i].c_wcv );
***************
*** 386,393 ****
}
if ( FD_ISSET( i, &readfds ) ) {
Debug( LDAP_DEBUG_CONNS,
! "read activity on %d\n", i, 0, 0 );
connection_activity( &c[i] );
}
--- 523,532 ----
}
if ( FD_ISSET( i, &readfds ) ) {
+ /* rwroth@netdox.com 10/05/1998 */
Debug( LDAP_DEBUG_CONNS,
! "%s: read activity on %d\n", source,
i, 0 );
! /* End rwroth */
connection_activity( &c[i] );
}
***************
*** 397,402 ****
--- 536,547 ----
}
close( tcps );
+ /* rwroth@netdox.com 10/05/1998 */
+ if ( Replicantport )
+ close( tcpr );
+
+ /* End rwroth */
+
pthread_mutex_lock( &active_threads_mutex );
Debug( LDAP_DEBUG_ANY,
"slapd shutting down - waiting for %d threads to
terminate\n",
diff -c servers/slapd/delete.c ../myldap/servers/slapd/delete.c
*** servers/slapd/delete.c Sat Aug 8 17:43:13 1998
--- ../myldap/servers/slapd/delete.c Mon Oct 5 09:51:11 1998
***************
*** 20,25 ****
--- 20,29 ----
extern char *default_referral;
+ /* rwroth@netdox.com 10/05/1998 */
+ extern int Replicantport;
+ /* End rwroth */
+
void
do_delete(
Connection *conn,
***************
*** 73,79 ****
if ( be->be_updatedn == NULL || strcasecmp(
be->be_updatedn,
op->o_dn ) == 0 ) {
if ( (*be->be_delete)( be, conn, op, dn ) == 0 )
{
! replog( be, LDAP_REQ_DELETE, odn, NULL,
0 );
}
} else {
send_ldap_result( conn, op,
LDAP_PARTIAL_RESULTS, NULL,
--- 77,87 ----
if ( be->be_updatedn == NULL || strcasecmp(
be->be_updatedn,
op->o_dn ) == 0 ) {
if ( (*be->be_delete)( be, conn, op, dn ) == 0 )
{
! /* rwroth@netdox.com 10/05/1998 */
! if ( conn->port != Replicantport )
! /* End rwroth */
! replog( be, LDAP_REQ_DELETE,
! odn, NULL, 0 );
}
} else {
send_ldap_result( conn, op,
LDAP_PARTIAL_RESULTS, NULL,
diff -c servers/slapd/main.c ../myldap/servers/slapd/main.c
*** servers/slapd/main.c Thu Aug 20 23:33:42 1998
--- ../myldap/servers/slapd/main.c Mon Oct 5 09:39:49 1998
***************
*** 19,25 ****
--- 19,31 ----
/*
* read-only global variables or variables only written by the
listener
* thread (after they are initialized) - no need to protect them with
a mutex.
+ * slurpd non replication
*/
+
+ /* rwroth@netdox.com 10/05/1998 */
+ int Replicantport = 0;
+ /* End rwroth */
+
int ldap_debug = 0;
#ifdef LDAP_DEBUG
int ldap_syslog = LDAP_DEBUG_STATS;
***************
*** 81,87 ****
g_argc = argc;
g_argv = argv;
! while ( (i = getopt( argc, argv, "d:f:ip:s:u" )) != EOF ) {
switch ( i ) {
#ifdef LDAP_DEBUG
case 'd': /* turn on debugging */
--- 87,93 ----
g_argc = argc;
g_argv = argv;
! while ( (i = getopt( argc, argv, "d:f:ip:r:s:u" )) != EOF ) {
switch ( i ) {
#ifdef LDAP_DEBUG
case 'd': /* turn on debugging */
***************
*** 138,143 ****
--- 144,156 ----
port = atoi( optarg );
break;
+ /*
+ * RWR 10/05/1998 rwroth@netdox.com
+ */
+ case 'r': /* slurpd replicant port on which to
listen */
+ Replicantport = atoi( optarg );
+ break;
+
case 's': /* set syslog level */
ldap_syslog = atoi( optarg );
break;
diff -c servers/slapd/modify.c ../myldap/servers/slapd/modify.c
*** servers/slapd/modify.c Tue Aug 18 18:30:57 1998
--- ../myldap/servers/slapd/modify.c Mon Oct 5 09:51:18 1998
***************
*** 25,30 ****
--- 25,34 ----
extern pthread_mutex_t currenttime_mutex;
extern int global_lastmod;
+ /* rwroth@netdox.com 10/05/1998 */
+ extern int Replicantport;
+ /* End rwroth */
+
static void modlist_free();
static void add_lastmods();
***************
*** 163,169 ****
add_lastmods( op, &mods );
}
if ( (*be->be_modify)( be, conn, op, odn, mods )
== 0 ) {
! replog( be, LDAP_REQ_MODIFY, dn, mods, 0
);
}
/* send a referral */
--- 167,177 ----
add_lastmods( op, &mods );
}
if ( (*be->be_modify)( be, conn, op, odn, mods )
== 0 ) {
! /* rwroth@netdox.com 10/05/1998 */
! if ( conn->port != Replicantport )
! /* End rwroth */
! replog( be, LDAP_REQ_MODIFY,
! dn, mods, 0 );
}
/* send a referral */
diff -c servers/slapd/modrdn.c ../myldap/servers/slapd/modrdn.c
*** servers/slapd/modrdn.c Sat Aug 8 17:43:13 1998
--- ../myldap/servers/slapd/modrdn.c Mon Oct 5 09:51:24 1998
***************
*** 20,25 ****
--- 20,29 ----
extern char *default_referral;
+ /* rwroth@netdox.com 10/05/1998 */
+ extern int Replicantport;
+ /* End rwroth */
+
void
do_modrdn(
Connection *conn,
***************
*** 84,91 ****
op->o_dn ) == 0 ) {
if ( (*be->be_modrdn)( be, conn, op, dn, newrdn,
deloldrdn ) == 0 ) {
! replog( be, LDAP_REQ_MODRDN, odn,
newrdn,
! deloldrdn );
}
} else {
send_ldap_result( conn, op,
LDAP_PARTIAL_RESULTS, NULL,
--- 88,98 ----
op->o_dn ) == 0 ) {
if ( (*be->be_modrdn)( be, conn, op, dn, newrdn,
deloldrdn ) == 0 ) {
! /* rwroth@netdox.com 10/05/1998 */
! if ( conn->port != Replicantport )
! /* End rwroth */
! replog( be, LDAP_REQ_MODRDN,
! odn, newrdn, deloldrdn );
}
} else {
send_ldap_result( conn, op,
LDAP_PARTIAL_RESULTS, NULL,
diff -c servers/slapd/slap.h ../myldap/servers/slapd/slap.h
*** servers/slapd/slap.h Thu Aug 20 23:33:42 1998
--- ../myldap/servers/slapd/slap.h Mon Oct 5 09:29:58 1998
***************
*** 238,243 ****
--- 238,244 ----
*/
typedef struct conn {
+ int port; /* rwroth@netdox.com 10/05/1998
*/
Sockbuf c_sb; /* ber connection stuff
*/
char *c_dn; /* current DN bound to this conn
*/
pthread_mutex_t c_dnmutex; /* mutex for c_dn field
*/