From 6c6d3d8f0c1288ed37981b8b30b18a6f9429b9fa Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 24 Oct 1998 20:18:31 +0000 Subject: [PATCH] update locking codes, remove old platform specific defines --- include/ac/socket.h | 4 ++ libraries/liblber/dtest.c | 4 +- libraries/liblber/etest.c | 6 +-- libraries/libldap/cldap.c | 4 -- libraries/libldap/friendly.c | 2 - libraries/libldap/getfilter.c | 6 --- libraries/libldap/open.c | 8 ---- libraries/libldap/result.c | 82 +---------------------------------- libraries/libldap/test.c | 61 +++----------------------- libraries/libldap/tmplout.c | 5 --- libraries/libldap/tmpltest.c | 4 +- servers/slapd/lock.c | 12 ++--- servers/slurpd/lock.c | 18 ++++---- 13 files changed, 33 insertions(+), 183 deletions(-) diff --git a/include/ac/socket.h b/include/ac/socket.h index a27da0db87..3530b4896b 100644 --- a/include/ac/socket.h +++ b/include/ac/socket.h @@ -39,6 +39,10 @@ #define INADDR_LOOPBACK ((unsigned long) 0x7f000001) #endif +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 +#endif + #ifdef MACOS #define tcp_close( s ) tcpclose( s ) #else /* MACOS */ diff --git a/libraries/liblber/dtest.c b/libraries/liblber/dtest.c index 5b60292cee..57f43c3dbf 100644 --- a/libraries/liblber/dtest.c +++ b/libraries/liblber/dtest.c @@ -19,7 +19,7 @@ #include #include -#ifdef MACOS +#ifdef HAVE_CONSOLE_H #include #endif /* MACOS */ @@ -39,7 +39,7 @@ main( int argc, char **argv ) Sockbuf sb; extern char *optarg; -#ifdef MACOS +#ifdef HAVE_CONSOLE_H ccommand( &argv ); cshow( stdout ); #endif /* MACOS */ diff --git a/libraries/liblber/etest.c b/libraries/liblber/etest.c index ee890ac601..ae1321b568 100644 --- a/libraries/liblber/etest.c +++ b/libraries/liblber/etest.c @@ -11,9 +11,9 @@ #include #include -#ifdef MACOS +#ifdef HAVE_CONSOLE_H #include -#endif /* MACOS */ +#endif /* HAVE_CONSOLE_H */ #include "lber.h" @@ -43,7 +43,7 @@ main( int argc, char **argv ) sb.sb_sd = 1; sb.sb_ber.ber_buf = NULL; -#ifdef MACOS +#ifdef HAVE_CONSOLE_H ccommand( &argv ); cshow( stdout ); diff --git a/libraries/libldap/cldap.c b/libraries/libldap/cldap.c index 8ab0318572..3f2fe861a0 100644 --- a/libraries/libldap/cldap.c +++ b/libraries/libldap/cldap.c @@ -28,10 +28,6 @@ static char copyright[] = "@(#) Copyright (c) 1990, 1994 Regents of the Universi #define DEF_CLDAP_TIMEOUT 3 #define DEF_CLDAP_TRIES 4 -#ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK ((unsigned long) 0x7f000001) -#endif - struct cldap_retinfo { int cri_maxtries; diff --git a/libraries/libldap/friendly.c b/libraries/libldap/friendly.c index 686ac882aa..0f5aa6acad 100644 --- a/libraries/libldap/friendly.c +++ b/libraries/libldap/friendly.c @@ -32,9 +32,7 @@ ldap_friendly_name( char *filename, char *uname, FriendlyMap **map ) char buf[BUFSIZ]; if ( map == NULL ) { -#if !defined( MACOS ) && !defined( DOS ) errno = EINVAL; -#endif return( uname ); } diff --git a/libraries/libldap/getfilter.c b/libraries/libldap/getfilter.c index fa286bc960..3e5ea7b511 100644 --- a/libraries/libldap/getfilter.c +++ b/libraries/libldap/getfilter.c @@ -127,9 +127,7 @@ ldap_init_getfilter_buf( char *buf, long buflen ) ldap_getfilter_free( lfdp ); fprintf( stderr, "bad regular expresssion %s, %s\n", nextflp->lfl_pattern, error ); -#if !defined( MACOS ) && !defined( DOS ) errno = EINVAL; -#endif #endif /* LDAP_LIBUI */ free_strarray( tok ); return( NULL ); @@ -179,9 +177,7 @@ ldap_init_getfilter_buf( char *buf, long buflen ) } else { free_strarray( tok ); ldap_getfilter_free( lfdp ); -#if !defined( MACOS ) && !defined( DOS ) errno = EINVAL; -#endif return( NULL ); } free( tok[ 2 ] ); @@ -198,9 +194,7 @@ ldap_init_getfilter_buf( char *buf, long buflen ) default: free_strarray( tok ); ldap_getfilter_free( lfdp ); -#if !defined( MACOS ) && !defined( DOS ) errno = EINVAL; -#endif return( NULL ); } } diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index f92147f415..7fa90682ee 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -30,14 +30,6 @@ static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of int ldap_debug; #endif -#ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK ((unsigned long) 0x7f000001) -#endif - -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 -#endif - /* * ldap_open - initialize and connect to an ldap server. A magic cookie to diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index dd0c5e71a2..dd6f5dbd44 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -170,12 +170,8 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout, if ( ld->ld_sb.sb_ber.ber_ptr >= ld->ld_sb.sb_ber.ber_end ) { rc = ldap_select1( ld, tvp ); -#if !defined( MACOS ) && !defined( DOS ) if ( rc == 0 || ( rc == -1 && (( ld->ld_options & LDAP_OPT_RESTART ) == 0 || errno != EINTR ))) { -#else - if ( rc == -1 || rc == 0 ) { -#endif ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : LDAP_TIMEOUT); return( rc ); @@ -207,7 +203,7 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout, rc = do_ldap_select( ld, tvp ); -#if defined( LDAP_DEBUG ) && !defined( MACOS ) && !defined( DOS ) +#ifdef LDAP_DEBUG if ( rc == -1 ) { Debug( LDAP_DEBUG_TRACE, "do_ldap_select returned -1: errno %d\n", @@ -215,12 +211,8 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout, } #endif -#if !defined( MACOS ) && !defined( DOS ) if ( rc == 0 || ( rc == -1 && (( ld->ld_options & LDAP_OPT_RESTART ) == 0 || errno != EINTR ))) { -#else - if ( rc == -1 || rc == 0 ) { -#endif ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : LDAP_TIMEOUT); return( rc ); @@ -589,7 +581,7 @@ merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ) #if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_REFERRALS ) -#if !defined( MACOS ) && !defined( DOS ) && !defined( _WIN32 ) + static int ldap_select1( LDAP *ld, struct timeval *timeout ) { @@ -616,77 +608,7 @@ ldap_select1( LDAP *ld, struct timeval *timeout ) return( select( tblsize, &readfds, 0, 0, timeout ) ); } -#endif /* !MACOS */ - - -#ifdef MACOS -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - return( tcpselect( ld->ld_sb.sb_sd, timeout )); -} -#endif /* MACOS */ - - -#if ( defined( DOS ) && defined( WINSOCK )) || defined( _WIN32 ) -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - fd_set readfds; - int rc; - - FD_ZERO( &readfds ); - FD_SET( ld->ld_sb.sb_sd, &readfds ); - - rc = select( 1, &readfds, 0, 0, timeout ); - return( rc == SOCKET_ERROR ? -1 : rc ); -} -#endif /* WINSOCK || _WIN32 */ - -#ifdef DOS -#ifdef PCNFS -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - fd_set readfds; - int res; - - FD_ZERO( &readfds ); - FD_SET( ld->ld_sb.sb_sd, &readfds ); - - res = select( FD_SETSIZE, &readfds, NULL, NULL, timeout ); - if ( res == -1 && errno == EINTR) { - /* We've been CTRL-C'ed at this point. It'd be nice to - carry on but PC-NFS currently won't let us! */ - printf("\n*** CTRL-C ***\n"); - exit(-1); - } - return( res ); -} -#endif /* PCNFS */ - -#ifdef NCSA -static int -ldap_select1( LDAP *ld, struct timeval *timeout ) -{ - int rc; - clock_t endtime; - - if ( timeout != NULL ) { - endtime = timeout->tv_sec * CLK_TCK + - timeout->tv_usec * CLK_TCK / 1000000 + clock(); - } - - do { - Stask(); - rc = netqlen( ld->ld_sb.sb_sd ); - } while ( rc <= 0 && ( timeout == NULL || clock() < endtime )); - - return( rc > 0 ? 1 : 0 ); -} -#endif /* NCSA */ -#endif /* DOS */ #endif /* !LDAP_REFERRALS */ diff --git a/libraries/libldap/test.c b/libraries/libldap/test.c index 340fae9b96..34c1eb9250 100644 --- a/libraries/libldap/test.c +++ b/libraries/libldap/test.c @@ -29,10 +29,6 @@ */ #include "ldap-int.h" -#if !defined( PCNFS ) && !defined( WINSOCK ) && !defined( MACOS ) -#define MOD_USE_BVALS -#endif /* !PCNFS && !WINSOCK && !MACOS */ - static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm )); static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s )); static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res )); @@ -42,7 +38,7 @@ static void free_list LDAP_P(( char **list )); char *dnsuffix; -#ifndef WINSOCK +#ifndef HAVE_GETLINE static char * getline( char *line, int len, FILE *fp, char *prompt ) { @@ -55,7 +51,7 @@ getline( char *line, int len, FILE *fp, char *prompt ) return( line ); } -#endif /* WINSOCK */ +#endif static char ** get_list( char *prompt ) @@ -103,7 +99,6 @@ free_list( char **list ) } -#ifdef MOD_USE_BVALS static int file_read( char *path, struct berval *bv ) { @@ -148,7 +143,6 @@ file_read( char *path, struct berval *bv ) return( bv->bv_len ); } -#endif /* MOD_USE_BVALS */ static LDAPMod ** @@ -158,9 +152,7 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 ) int num; LDAPMod tmp; LDAPMod **result; -#ifdef MOD_USE_BVALS struct berval **bvals; -#endif /* MOD_USE_BVALS */ num = 0; result = NULL; @@ -179,7 +171,7 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 ) tmp.mod_type = strdup( buf ); tmp.mod_values = get_list( prompt3 ); -#ifdef MOD_USE_BVALS + if ( tmp.mod_values != NULL ) { int i; @@ -205,7 +197,6 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 ) tmp.mod_bvalues = bvals; tmp.mod_op |= LDAP_MOD_BVALUES; } -#endif /* MOD_USE_BVALS */ if ( result == NULL ) result = (LDAPMod **) malloc( sizeof(LDAPMod *) ); @@ -265,12 +256,7 @@ bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp, int -#ifdef WINSOCK -ldapmain( -#else /* WINSOCK */ -main( -#endif /* WINSOCK */ - int argc, char **argv ) +main( int argc, char **argv ) { LDAP *ld = NULL; int i, c, port, cldapflg, errflg, method, id, msgtype; @@ -290,15 +276,6 @@ main( extern char *optarg; extern int optind; -#ifdef MACOS - if (( argv = get_list( "cmd line arg?" )) == NULL ) { - exit( 1 ); - } - for ( argc = 0; argv[ argc ] != NULL; ++argc ) { - ; - } -#endif /* MACOS */ - host = NULL; port = LDAP_PORT; dnsuffix = ""; @@ -337,7 +314,6 @@ main( port = atoi( optarg ); break; -#if !defined(MACOS) && !defined(DOS) case 't': /* copy ber's to given file */ copyfname = strdup( optarg ); copyoptions = LBER_TO_FILE; @@ -347,7 +323,6 @@ main( copyfname = strdup( optarg ); copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY); break; -#endif default: ++errflg; @@ -380,7 +355,6 @@ main( exit(1); } -#if !defined(MACOS) && !defined(DOS) if ( copyfname != NULL ) { if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT, 0600 )) == -1 ) { @@ -389,7 +363,6 @@ main( } ld->ld_sb.sb_options = copyoptions; } -#endif bound = 0; timeout.tv_sec = 0; @@ -947,13 +920,9 @@ print_search_entry( LDAP *ld, LDAPMessage *res ) ufn = ldap_dn2ufn( dn ); printf( "\tUFN: %s\n", ufn ); -#ifdef WINSOCK - ldap_memfree( dn ); - ldap_memfree( ufn ); -#else /* WINSOCK */ + free( dn ); free( ufn ); -#endif /* WINSOCK */ for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL; a = ldap_next_attribute( ld, e, ber ) ) { @@ -992,23 +961,3 @@ print_search_entry( LDAP *ld, LDAPMessage *res ) || res->lm_chain != NULLMSG ) print_ldap_result( ld, res, "search" ); } - - -#ifdef WINSOCK -void -ldap_perror( LDAP *ld, char *s ) -{ - char *errs; - - if ( ld == NULL ) { - perror( s ); - return; - } - - errs = ldap_err2string( ld->ld_errno ); - printf( "%s: %s\n", s, errs == NULL ? "unknown error" : errs ); - if ( ld->ld_error != NULL && *ld->ld_error != '\0' ) { - printf( "%s: additional info: %s\n", s, ld->ld_error ); - } -} -#endif /* WINSOCK */ diff --git a/libraries/libldap/tmplout.c b/libraries/libldap/tmplout.c index 308745ec84..823b36a30c 100644 --- a/libraries/libldap/tmplout.c +++ b/libraries/libldap/tmplout.c @@ -911,11 +911,6 @@ time2text( char *ldtimestr, int dateonly ) /* gtime.c - inverse gmtime */ - -#if !defined( MACOS ) && !defined( _WIN32 ) && !defined( DOS ) -#include -#endif /* !MACOS */ - /* gtime(): the inverse of localtime(). This routine was supplied by Mike Accetta at CMU many years ago. */ diff --git a/libraries/libldap/tmpltest.c b/libraries/libldap/tmpltest.c index aa860b9a37..5bd25241b4 100644 --- a/libraries/libldap/tmpltest.c +++ b/libraries/libldap/tmpltest.c @@ -6,7 +6,7 @@ #include #include -#ifdef MACOS +#ifdef HAVE_CONSOLE_H #include #endif /* MACOS */ @@ -27,7 +27,7 @@ main( int argc, char **argv ) struct ldap_searchobj *so, *sop; int err; -#ifdef MACOS +#ifdef HAVE_CONSOLE_H ccommand( &argv ); for ( argc = 0; argv[ argc ] != NULL; ++argc ) { ; diff --git a/servers/slapd/lock.c b/servers/slapd/lock.c index debc102e2e..aee7c31cfb 100644 --- a/servers/slapd/lock.c +++ b/servers/slapd/lock.c @@ -27,10 +27,10 @@ lock_fopen( char *fname, char *type, FILE **lfp ) } /* acquire the lock */ -#ifdef USE_LOCKF - while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 ) { -#else +#ifdef HAVE_FLOCK while ( flock( fileno( *lfp ), LOCK_EX ) != 0 ) { +#else + while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 ) { #endif ; /* NULL */ } @@ -38,10 +38,10 @@ lock_fopen( char *fname, char *type, FILE **lfp ) /* open the log file */ if ( (fp = fopen( fname, type )) == NULL ) { Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", fname, 0, 0 ); -#ifdef USE_LOCKF - lockf( fileno( *lfp ), F_ULOCK, 0 ); -#else +#ifdef HAVE_FLOCK flock( fileno( *lfp ), LOCK_UN ); +#else + lockf( fileno( *lfp ), F_ULOCK, 0 ); #endif return( NULL ); } diff --git a/servers/slurpd/lock.c b/servers/slurpd/lock.c index 2e42fd8b2d..048c42529c 100644 --- a/servers/slurpd/lock.c +++ b/servers/slurpd/lock.c @@ -49,10 +49,10 @@ lock_fopen( } /* acquire the lock */ -#ifdef HAVE_LOCKF - while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 ) -#else +#ifdef HAVE_FLOCK while ( flock( fileno( *lfp ), LOCK_EX ) != 0 ) +#else + while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 ) #endif { ; /* NULL */ @@ -62,10 +62,10 @@ lock_fopen( if ( (fp = fopen( fname, type )) == NULL ) { Debug( LDAP_DEBUG_ANY, "Error: could not open \"%s\"\n", fname, 0, 0 ); -#ifdef HAVE_LOCKF - lockf( fileno( *lfp ), F_ULOCK, 0 ); -#else +#ifdef HAVE_FLOCK flock( fileno( *lfp ), LOCK_UN ); +#else + lockf( fileno( *lfp ), F_ULOCK, 0 ); #endif return( NULL ); } @@ -82,10 +82,10 @@ lock_fclose( ) { /* unlock */ -#ifdef HAVE_LOCKF - lockf( fileno( lfp ), F_ULOCK, 0 ); -#else +#ifdef HAVE_FLOCK flock( fileno( lfp ), LOCK_UN ); +#else + lockf( fileno( lfp ), F_ULOCK, 0 ); #endif fclose( lfp ); -- 2.39.5