Commit e5635b26 authored by Gary Williams's avatar Gary Williams
Browse files

NT port

parent b454005e
......@@ -10,6 +10,10 @@
#include "slap.h"
#ifdef HAVE_WINSOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
/* protected by connections_mutex */
static ldap_pvt_thread_mutex_t connections_mutex;
static Connection *connections = NULL;
......@@ -28,6 +32,7 @@ static long conn_nextid = 0;
#define SLAP_C_BINDING 0x3 /* binding */
#define SLAP_C_CLOSING 0x4 /* closing */
void slapd_remove(int s);
static Connection* connection_get( int s );
static int connection_input( Connection *c );
......@@ -67,6 +72,9 @@ int connections_init(void)
return -1;
}
for ( i = 0; i < dtblsize; i++ )
memset( &connections[i], 0, sizeof(Connection) );
/*
* per entry initialization of the Connection array initialization
* will be done by connection_init()
......@@ -96,24 +104,24 @@ static Connection* connection_get( int s )
int i;
for(i=0; i<dtblsize; i++) {
if( connections[i].c_struct_state == SLAP_C_STRUCT_UNINITIALIZED ) {
if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
assert( connections[i].c_conn_state == SLAP_C_INVALID );
assert( connections[s].c_sb.sb_sd == 0 );
assert( connections[i].c_sb.sb_sd == 0 );
break;
}
if( connections[i].c_struct_state == SLAP_C_STRUCT_UNUSED ) {
if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
assert( connections[i].c_conn_state == SLAP_C_INVALID );
assert( connections[s].c_sb.sb_sd == -1 );
assert( connections[i].c_sb.sb_sd == -1 );
continue;
}
assert( connections[i].c_struct_state == SLAP_C_STRUCT_USED );
assert( connections[i].c_struct_state == SLAP_C_USED );
assert( connections[i].c_conn_state != SLAP_C_INVALID );
assert( connections[s].c_sb.sb_sd != -1 );
assert( connections[i].c_sb.sb_sd != -1 );
if( connections[i].c_sb.sb_sd == s ) {
c = &connections[s];
c = &connections[i];
break;
}
}
......@@ -163,116 +171,116 @@ long connection_init(
{
int i;
for( i=0; i < dtblsize; i++ {
if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
assert( connections[i].c_sb.sb_sd == 0 );
c = &connections[i];
break;
}
if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
assert( connections[i].c_sb.sb_sd == -1 );
c = &connections[i];
break;
}
assert( connections[i].c_struct_state == SLAP_C_USED );
assert( connections[i].c_conn_state != SLAP_C_INVALID );
assert( connections[i].c_sb.sb_sd != -1 );
}
if( c == NULL ) {
ldap_pvt_thread_mutex_unlock( &connections_mutex );
return -1;
}
}
for( i=0; i < dtblsize; i++) {
if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
assert( connections[i].c_sb.sb_sd == 0 );
c = &connections[i];
break;
}
if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
assert( connections[i].c_sb.sb_sd == -1 );
c = &connections[i];
break;
}
assert( connections[i].c_struct_state == SLAP_C_USED );
assert( connections[i].c_conn_state != SLAP_C_INVALID );
assert( connections[i].c_sb.sb_sd != -1 );
}
if( c == NULL ) {
ldap_pvt_thread_mutex_unlock( &connections_mutex );
return -1;
}
}
#endif
assert( c != NULL );
assert( c->c_struct_state != SLAP_C_USED );
assert( c->c_conn_state == SLAP_C_INVALID );
assert( c != NULL );
assert( c->c_struct_state != SLAP_C_USED );
assert( c->c_conn_state == SLAP_C_INVALID );
if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
c->c_dn = NULL;
c->c_cdn = NULL;
c->c_client_name = NULL;
c->c_client_addr = NULL;
c->c_ops = NULL;
c->c_pending_ops = NULL;
if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
c->c_dn = NULL;
c->c_cdn = NULL;
c->c_client_name = NULL;
c->c_client_addr = NULL;
c->c_ops = NULL;
c->c_pending_ops = NULL;
lber_pvt_sb_init( &c->c_sb );
lber_pvt_sb_init( &c->c_sb );
/* should check status of thread calls */
ldap_pvt_thread_mutex_init( &c->c_mutex );
ldap_pvt_thread_mutex_init( &c->c_write_mutex );
ldap_pvt_thread_cond_init( &c->c_write_cv );
/* should check status of thread calls */
ldap_pvt_thread_mutex_init( &c->c_mutex );
ldap_pvt_thread_mutex_init( &c->c_write_mutex );
ldap_pvt_thread_cond_init( &c->c_write_cv );
c->c_struct_state = SLAP_C_UNUSED;
}
c->c_struct_state = SLAP_C_UNUSED;
}
ldap_pvt_thread_mutex_lock( &c->c_mutex );
ldap_pvt_thread_mutex_lock( &c->c_mutex );
assert( c->c_struct_state == SLAP_C_UNUSED );
assert( c->c_dn == NULL );
assert( c->c_cdn == NULL );
assert( c->c_client_name == NULL );
assert( c->c_client_addr == NULL );
assert( c->c_ops == NULL );
assert( c->c_pending_ops == NULL );
assert( c->c_struct_state == SLAP_C_UNUSED );
assert( c->c_dn == NULL );
assert( c->c_cdn == NULL );
assert( c->c_client_name == NULL );
assert( c->c_client_addr == NULL );
assert( c->c_ops == NULL );
assert( c->c_pending_ops == NULL );
c->c_client_name = ch_strdup( name == NULL ? "" : name );
c->c_client_addr = ch_strdup( addr );
c->c_client_name = ch_strdup( name == NULL ? "" : name );
c->c_client_addr = ch_strdup( addr );
c->c_n_ops_received = 0;
c->c_n_ops_received = 0;
#ifdef LDAP_COUNTERS
c->c_n_ops_executing = 0;
c->c_n_ops_pending = 0;
c->c_n_ops_completed = 0;
c->c_n_ops_executing = 0;
c->c_n_ops_pending = 0;
c->c_n_ops_completed = 0;
#endif
c->c_starttime = slap_get_time();
c->c_starttime = slap_get_time();
lber_pvt_sb_set_desc( &c->c_sb, s );
lber_pvt_sb_set_io( &c->c_sb, &lber_pvt_sb_io_tcp, NULL );
lber_pvt_sb_set_desc( &c->c_sb, s );
lber_pvt_sb_set_io( &c->c_sb, &lber_pvt_sb_io_tcp, NULL );
if( lber_pvt_sb_set_nonblock( &c->c_sb, 1 ) < 0 ) {
Debug( LDAP_DEBUG_ANY,
"connection_init(%d, %s, %s): set nonblocking failed\n",
s, c->c_client_name, c->c_client_addr);
}
if( lber_pvt_sb_set_nonblock( &c->c_sb, 1 ) < 0 ) {
Debug( LDAP_DEBUG_ANY,
"connection_init(%d, %s, %s): set nonblocking failed\n",
s, c->c_client_name, c->c_client_addr);
}
id = c->c_connid = conn_nextid++;
id = c->c_connid = conn_nextid++;
c->c_conn_state = SLAP_C_INACTIVE;
c->c_struct_state = SLAP_C_USED;
c->c_conn_state = SLAP_C_INACTIVE;
c->c_struct_state = SLAP_C_USED;
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
ldap_pvt_thread_mutex_unlock( &connections_mutex );
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
ldap_pvt_thread_mutex_unlock( &connections_mutex );
return id;
return id;
}
static void
connection_destroy( Connection *c )
{
assert( connections != NULL );
assert( c != NULL );
assert( c->c_struct_state != SLAP_C_UNUSED );
assert( c->c_conn_state != SLAP_C_INVALID );
assert( c->c_ops == NULL );
assert( connections != NULL );
assert( c != NULL );
assert( c->c_struct_state != SLAP_C_UNUSED );
assert( c->c_conn_state != SLAP_C_INVALID );
assert( c->c_ops == NULL );
c->c_struct_state = SLAP_C_UNUSED;
c->c_conn_state = SLAP_C_INVALID;
c->c_struct_state = SLAP_C_UNUSED;
c->c_conn_state = SLAP_C_INVALID;
c->c_version = 0;
c->c_protocol = 0;
c->c_version = 0;
c->c_protocol = 0;
c->c_starttime = 0;
c->c_starttime = 0;
if(c->c_dn != NULL) {
free(c->c_dn);
c->c_dn = NULL;
}
if(c->c_dn != NULL) {
free(c->c_dn);
c->c_dn = NULL;
}
if(c->c_cdn != NULL) {
free(c->c_cdn);
c->c_cdn = NULL;
......@@ -632,7 +640,6 @@ connection_input(
return -1;
}
return 1;
}
......@@ -692,7 +699,7 @@ connection_resched( Connection *conn )
if( conn->c_conn_state != SLAP_C_ACTIVE ) {
/* other states need different handling */
return;
return 0;
}
for( op = slap_op_pop( &conn->c_pending_ops );
......@@ -705,6 +712,7 @@ connection_resched( Connection *conn )
break;
}
}
return 0;
}
static int connection_op_activate( Connection *conn, Operation *op )
......
......@@ -159,7 +159,7 @@ slapd_daemon_task(
#elif HAVE_GETDTABLESIZE
dtblsize = getdtablesize();
#else
dtblsize = FD_SETSIZE
dtblsize = FD_SETSIZE;
#endif
#ifdef FD_SETSIZE
......@@ -168,6 +168,15 @@ slapd_daemon_task(
}
#endif /* !FD_SETSIZE */
#ifdef HAVE_WINSOCK
{
WORD vers = MAKEWORD( 2, 0);
int err;
WSADATA wsaData;
err = WSAStartup( vers, &wsaData );
}
#endif
connections_init();
ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
......@@ -431,7 +440,16 @@ slapd_daemon_task(
#ifdef LDAP_DEBUG
Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
#ifdef HAVE_WINSOCK
for ( i = 0; i < readfds.fd_count; i++ )
{
Debug( LDAP_DEBUG_CONNS, " %d%s", readfds.fd_array[i], "r" );
}
for ( i = 0; i < writefds.fd_count; i++ )
{
Debug( LDAP_DEBUG_CONNS, " %d%s", writefds.fd_array[i], "w" );
}
#else
for ( i = 0; i < nfds; i++ ) {
int a, r, w;
......@@ -442,16 +460,31 @@ slapd_daemon_task(
r ? "r" : "", w ? "w" : "" );
}
}
#endif
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
#endif
/* loop through the writers */
#ifdef HAVE_WINSOCK
for ( i = 0; i < writefds.fd_count; i++ ) {
if ( writefds.fd_array[i] == tcps ) {
continue;
}
Debug( LDAP_DEBUG_CONNS,
"daemon: signalling write waiter on %d\n",
writefds.fd_array[i], 0, 0 );
assert( FD_ISSET( 0, &slap_daemon.sd_actives) );
slapd_clr_write( writefds.fd_array[i], 0 );
if ( connection_write( writefds.fd_array[i] ) < 0 ) {
FD_CLR( writefds.fd_array[i], &readfds );
slapd_close( writefds.fd_array[i] );
}
#else
for ( i = 0; i < nfds; i++ ) {
if ( i == tcps ) {
continue;
}
if ( FD_ISSET( i, &writefds ) ) {
Debug( LDAP_DEBUG_CONNS,
"daemon: signaling write waiter on %d\n", i, 0, 0 );
......@@ -466,8 +499,23 @@ slapd_daemon_task(
slapd_close( i );
}
}
#endif
}
#ifdef HAVE_WINSOCK
for ( i = 0; i < readfds.fd_count; i++ ) {
if ( readfds.fd_array[i] == tcps ) {
continue;
}
Debug ( LDAP_DEBUG_CONNS,
"daemon: read activity on %d\n", readfds.fd_array[i], 0, 0 );
assert( FD_ISSET( readfds.fd_array[i], &slap_daemon.sd_actives) );
if ( connection_read( readfds.fd_array[i] ) < 0 ) {
slapd_close( i );
}
}
#else
for ( i = 0; i < nfds; i++ ) {
if ( i == tcps ) {
continue;
......@@ -484,7 +532,7 @@ slapd_daemon_task(
}
}
}
#endif
ldap_pvt_thread_yield();
}
......
......@@ -12,7 +12,9 @@
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include "slap.h"
FILE *
......
......@@ -70,7 +70,7 @@ main( int argc, char **argv )
{
int i;
int inetd = 0;
int status, rc;
int rc;
struct sockaddr_in bind_addr, *slapd_addr;
int udp;
#ifdef LOG_LOCAL4
......@@ -97,7 +97,11 @@ main( int argc, char **argv )
#endif
switch ( i ) {
case 'a': /* bind address */
#ifdef HAVE_WINSOCK
if(!(bind_addr.sin_addr.S_un.S_addr = inet_addr(optarg))) {
#else
if(!inet_aton(optarg, &bind_addr.sin_addr)) {
#endif
fprintf(stderr, "invalid address (%s) for -a option", optarg);
}
break;
......@@ -153,7 +157,7 @@ main( int argc, char **argv )
break;
case 'p': { /* port on which to listen */
int port = atoi( optarg );
short port = (short)atoi( optarg );
if(! port ) {
fprintf(stderr, "-p %s must be numeric\n", optarg);
} else {
......@@ -230,6 +234,7 @@ main( int argc, char **argv )
(void) SIGNAL( LDAP_SIGCHLD, wait4child );
#endif
#ifndef WIN32
if(!inetd) {
#ifdef LDAP_DEBUG
lutil_detach( ldap_debug, 0 );
......@@ -237,6 +242,7 @@ main( int argc, char **argv )
lutil_detach( 0, 0 );
#endif
}
#endif /* WIN32 */
if ( slap_startup(-1) != 0 ) {
rc = 1;
......
......@@ -13,6 +13,10 @@
#include "slap.h"
#ifdef HAVE_WINSOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
static void
send_ldap_result2(
Connection *conn,
......
......@@ -5,10 +5,6 @@
#include <stdlib.h>
#ifndef LDAP_SYSLOG
#define LDAP_SYSLOG 1
#endif
#include <sys/types.h>
#include <ac/syslog.h>
#include <ac/regex.h>
......
......@@ -40,7 +40,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
......@@ -61,9 +61,10 @@ LINK32=link.exe
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "../../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\include" /I "..\..\libraries\regex" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
......@@ -71,7 +72,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ..\..\..\db-2.7.3\build_win32\debug\libdbs.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
......@@ -79,6 +80,9 @@ LINK32=link.exe
# Name "slapd - Win32 Release"
# Name "slapd - Win32 Debug"
# Begin Group "Source"
# PROP Default_Filter ".c"
# Begin Source File
SOURCE=.\abandon.c
......@@ -185,15 +189,15 @@ SOURCE=.\monitor.c
# End Source File
# Begin Source File
SOURCE=.\operation.c
SOURCE=.\nt_debug.c
# End Source File
# Begin Source File
SOURCE=.\phonetic.c
SOURCE=.\operation.c
# End Source File
# Begin Source File
SOURCE=".\proto-slap.h"
SOURCE=.\phonetic.c
# End Source File
# Begin Source File
......@@ -217,10 +221,6 @@ SOURCE=.\search.c
# End Source File
# Begin Source File
SOURCE=.\slap.h
# End Source File
# Begin Source File
SOURCE=.\str2filter.c
# End Source File
# Begin Source File
......@@ -235,5 +235,22 @@ SOURCE=.\unbind.c
SOURCE=.\value.c
# End Source File
# Begin Source File
SOURCE=.\Version.c
# End Source File
# End Group
# Begin Group "Headers"
# PROP Default_Filter ".h"
# Begin Source File
SOURCE=".\proto-slap.h"
# End Source File
# Begin Source File
SOURCE=.\slap.h
# End Source File
# End Group
# End Target
# End Project
......@@ -3,6 +3,18 @@ Microsoft Developer Studio Workspace File, Format Version 5.00
###############################################################################
Project: "backbdb2"=".\back-bdb2\backbdb2.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "backldbm"=".\back-ldbm\backldbm.dsp" - Package Owner=<4>
Package=<5>
......@@ -15,6 +27,18 @@ Package=<4>
###############################################################################
Project: "libavl"=..\..\libraries\libavl\libavl.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "liblber"=..\..\libraries\liblber\liblber.dsp - Package Owner=<4>
Package=<5>
......@@ -27,6 +51,18 @@ Package=<4>
###############################################################################
Project: "libldap"=..\..\libraries\libldap\libldap.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "libldap_r"=..\..\libraries\libldap_r\libldap_r.dsp - Package Owner=<4>
Package=<5>
......@@ -39,6 +75,54 @@ Package=<4>
###############################################################################
Project: "libldbm"=..\..\libraries\libldbm\libldbm.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{