#include "portable.h"
#include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
#include <ac/ctype.h>
#include <ac/signal.h>
#include <ac/time.h>
#include <ac/unistd.h>
#include <ac/wait.h>
-extern char *strdup (const char *);
-extern int strcasecmp(const char *, const char *);
-extern int gethostname (char *, int);
#include <ac/setproctitle.h>
#include <sys/param.h>
#endif
+#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
+#endif
#include "ldapconfig.h"
#include "lber.h"
#include "ldap.h"
+
+#define ldap_debug debug
#include "ldap_log.h"
+
#include "lutil.h"
#include "disptmpl.h"
int debug;
int dosyslog;
+int ldap_syslog;
+int ldap_syslog_level;
int inetd;
int dtblsize;
struct hostent *hp;
struct sockaddr_in from;
int fromlen;
- extern char *optarg;
#if defined( LDAP_PROCTITLE ) && !defined( HAVE_SETPROCTITLE )
/* for setproctitle */
break;
case 'd': /* debug level */
- debug = atoi( optarg );
+ debug |= atoi( optarg );
break;
case 'f': /* ldap filter file */
}
#endif /* FD_SETSIZE*/
-
/* detach if stderr is redirected or no debugging */
if ( inetd == 0 )
lutil_detach( debug && !isatty( 1 ), 1 );
else
myname = strdup( myname + 1 );
+ if ( debug ) {
+ ber_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug);
+ ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug);
+ }
+
+#ifdef SIGPIPE
+ (void) SIGNAL( SIGPIPE, SIG_IGN );
+#endif
+
if ( dosyslog ) {
#ifdef LOG_LOCAL3
openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL3 );
switch( pid = fork() ) {
case 0: /* child */
- close( s );
+ tcp_close( s );
do_queries( ns );
break;
break;
default: /* parent */
- close( ns );
+ tcp_close( ns );
if ( debug )
fprintf( stderr, "forked child %d\n", pid );
break;
if ( debug ) printf( "parent: catching child status\n" );
#ifdef HAVE_WAITPID
- while (waitpid ((pid_t) -1, 0, WAIT_FLAGS) > 0)
+ while (waitpid ((pid_t) -1, (int *) NULL, WAIT_FLAGS) > 0)
; /* NULL */
#else
- while ( wait3( &status, WAIT_FLAGS, 0 ) > 0 )
+ while ( wait4((pid_t) -1, &status, WAIT_FLAGS, 0 ) > 0 )
; /* NULL */
#endif
if ( debug ) {
fprintf( stderr, "got %d bytes\n", len );
#ifdef LDAP_DEBUG
- lber_bprint( buf, len );
+ ber_bprint( buf, len );
#endif
}
query = buf;
/* strip off leading white space */
- while ( isspace( *query )) {
+ while ( isspace( (unsigned char) *query )) {
++query;
--len;
}
if ( *query == '~' || *query == '@' ) {
ld = NULL;
- } else if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
+ } else if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
fprintf(fp,
"0An error occurred (explanation)\t@%d\t%s\t%d\r\n",
LDAP_SERVER_DOWN, myhost, myport );
static int
entry2textwrite( void *fp, char *buf, int len )
{
- return( fwrite( buf, len, 1, (FILE *)fp ) == 0 ? -1 : len );
+ return( fwrite( buf, len, 1, (FILE *)fp ) == 0 ? -1 : len );
}
static void