]> git.sur5r.net Git - openldap/blobdiff - clients/gopher/go500.c
s/<stdlib.h>/<ac/stdlib.h>/
[openldap] / clients / gopher / go500.c
index 3f21c9cbbcff2f02b05f262e0940ba60f0d84b12..7b5141bbed4888792882f4de23fdc3e0f063c3e5 100644 (file)
@@ -13,7 +13,8 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
 #include <ac/signal.h>
@@ -23,9 +24,6 @@
 #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>
 
@@ -33,18 +31,25 @@ extern int gethostname (char *, int);
 #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;
 
@@ -83,7 +88,6 @@ main( int argc, char **argv )
        struct hostent          *hp;
        struct sockaddr_in      from;
        int                     fromlen;
-       extern char             *optarg;
 
 #if defined( LDAP_PROCTITLE ) && !defined( HAVE_SETPROCTITLE )
        /* for setproctitle */
@@ -98,7 +102,7 @@ main( int argc, char **argv )
                        break;
 
                case 'd':       /* debug level */
-                       debug = atoi( optarg );
+                       debug |= atoi( optarg );
                        break;
 
                case 'f':       /* ldap filter file */
@@ -158,7 +162,6 @@ main( int argc, char **argv )
        }
 #endif /* FD_SETSIZE*/
 
-
        /* detach if stderr is redirected or no debugging */
        if ( inetd == 0 )
                lutil_detach( debug && !isatty( 1 ), 1 );
@@ -168,6 +171,15 @@ main( int argc, char **argv )
        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 );
@@ -245,7 +257,7 @@ main( int argc, char **argv )
 
                switch( pid = fork() ) {
                case 0:         /* child */
-                       close( s );
+                       tcp_close( s );
                        do_queries( ns );
                        break;
 
@@ -254,7 +266,7 @@ main( int argc, char **argv )
                        break;
 
                default:        /* parent */
-                       close( ns );
+                       tcp_close( ns );
                        if ( debug )
                                fprintf( stderr, "forked child %d\n", pid );
                        break;
@@ -316,10 +328,10 @@ wait4child( int sig )
         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
 
@@ -356,7 +368,7 @@ do_queries( int s )
        if ( debug ) {
                fprintf( stderr, "got %d bytes\n", len );
 #ifdef LDAP_DEBUG
-               lber_bprint( buf, len );
+               ber_bprint( buf, len );
 #endif
        }
 
@@ -371,7 +383,7 @@ do_queries( int s )
        query = buf;
 
        /* strip off leading white space */
-       while ( isspace( *query )) {
+       while ( isspace( (unsigned char) *query )) {
                ++query;
                --len;
        }
@@ -380,7 +392,7 @@ do_queries( int s )
 
        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 );
@@ -559,7 +571,7 @@ do_search( LDAP *ld, FILE *fp, char *buf )
 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