-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
#include "portable.h"
-#include "slap.h"
-#include "ldapconfig.h"
-extern void daemon();
-extern int lber_debug;
+#include <stdio.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+
+#include "ldapconfig.h"
+#include "slap.h"
+#include "lutil.h" /* Get lutil_detach() */
-extern char Versionstr[];
/*
* read-only global variables or variables only written by the listener
* thread (after they are initialized) - no need to protect them with a mutex.
*/
-int ldap_debug;
+int ldap_debug = 0;
#ifdef LDAP_DEBUG
int ldap_syslog = LDAP_DEBUG_STATS;
#else
int active_threads;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
+#ifdef SLAPD_CRYPT
+pthread_mutex_t crypt_mutex;
+#endif
long ops_initiated;
long ops_completed;
int num_conns;
*/
pthread_mutex_t entry2str_mutex;
pthread_mutex_t replog_mutex;
-#ifndef sunos5
-pthread_mutex_t regex_mutex;
-#endif
-static
-usage( name )
- char *name;
+static void
+usage( char *name )
{
- fprintf( stderr, "usage: %s [-d debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name );
+ fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name );
}
-main( argc, argv )
- int argc;
- char **argv;
+int
+main( int argc, char **argv )
{
int i;
int inetd = 0;
char *myname;
Backend *be = NULL;
FILE *fp = NULL;
- extern char *optarg;
configfile = SLAPD_DEFAULT_CONFIGFILE;
port = LDAP_PORT;
LDAP_DEBUG_CONFIG );
printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
LDAP_DEBUG_ACL );
- printf( "\tLDAP_DEBUG_STATS\t\t%d\n",
+ printf( "\tLDAP_DEBUG_STATS\t%d\n",
LDAP_DEBUG_STATS );
- printf( "\tLDAP_DEBUG_STATS2\t\t%d\n",
+ printf( "\tLDAP_DEBUG_STATS2\t%d\n",
LDAP_DEBUG_STATS2 );
- printf( "\tLDAP_DEBUG_SHELL\t\t%d\n",
+ printf( "\tLDAP_DEBUG_SHELL\t%d\n",
LDAP_DEBUG_SHELL );
- printf( "\tLDAP_DEBUG_PARSE\t\t%d\n",
+ printf( "\tLDAP_DEBUG_PARSE\t%d\n",
LDAP_DEBUG_PARSE );
printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
LDAP_DEBUG_ANY );
exit( 0 );
} else {
- ldap_debug = atoi( optarg );
+ ldap_debug |= atoi( optarg );
lber_debug = (ldap_debug & LDAP_DEBUG_BER);
}
break;
#endif
case 'f': /* read config file */
- configfile = strdup( optarg );
+ configfile = ch_strdup( optarg );
break;
case 'i': /* run from inetd */
Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );
if ( (myname = strrchr( argv[0], '/' )) == NULL ) {
- myname = strdup( argv[0] );
+ myname = ch_strdup( argv[0] );
} else {
- myname = strdup( myname + 1 );
+ myname = ch_strdup( myname + 1 );
}
if ( ! inetd ) {
/* pre-open config file before detach in case it is a relative path */
fp = fopen( configfile, "r" );
- detach();
+#ifdef LDAP_DEBUG
+ lutil_detach( ldap_debug, 0 );
+#else
+ lutil_detach( 0, 0 );
+#endif
}
#ifdef LOG_LOCAL4
openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
read_config( configfile, &be, fp );
if ( ! inetd ) {
- pthread_attr_t attr;
int status;
time( &starttime );
- pthread_attr_init( &attr );
- pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
- if ( pthread_create( &listener_tid, attr, (void *) daemon,
+ if ( pthread_create( &listener_tid, NULL, slapd_daemon,
(void *) port ) != 0 ) {
Debug( LDAP_DEBUG_ANY,
"listener pthread_create failed\n", 0, 0, 0 );
exit( 1 );
}
- pthread_attr_destroy( &attr );
+
+#ifdef HAVE_PHREADS_FINAL
+ pthread_join( listener_tid, (void *) NULL );
+#else
pthread_join( listener_tid, (void *) &status );
- pthread_exit( 0 );
+#endif
+
+ return 0;
+
} else {
Connection c;
Operation *o;
#endif
flen = sizeof(from);
if ( getpeername( 0, (struct sockaddr *) &from, &flen ) == 0 ) {
-#ifdef REVERSE_LOOKUP
+#ifdef SLAPD_RLOOKUPS
hp = gethostbyaddr( (char *) &(from.sin_addr.s_addr),
sizeof(from.sin_addr.s_addr), AF_INET );
#else
inet_ntoa( from.sin_addr ), 0 );
c.c_addr = inet_ntoa( from.sin_addr );
- c.c_domain = strdup( hp == NULL ? "" : hp->h_name );
+ c.c_domain = ch_strdup( hp == NULL ? "" : hp->h_name );
} else {
Debug( LDAP_DEBUG_ARGS, "connection from unknown\n",
0, 0, 0 );
!= LDAP_TAG_MSGID ) {
/* log and send error */
Debug( LDAP_DEBUG_ANY,
- "ber_get_int returns 0x%x\n", tag, 0, 0 );
- return;
+ "ber_get_int returns 0x%lx\n", tag, 0, 0 );
+ ber_free( &ber, 1 );
+ return 1;
}
if ( (tag = ber_peek_tag( &ber, &len ))
== LBER_ERROR ) {
/* log, close and send error */
Debug( LDAP_DEBUG_ANY,
- "ber_peek_tag returns 0x%x\n", tag, 0, 0 );
+ "ber_peek_tag returns 0x%lx\n", tag, 0, 0 );
ber_free( &ber, 1 );
close( c.c_sb.sb_sd );
c.c_sb.sb_sd = -1;
- return;
+ return 1;
}
connection_activity( &c );
ber_free( &ber, 1 );
}
}
+ return 1;
}