update locking codes, remove old platform specific defines

This commit is contained in:
Kurt Zeilenga 1998-10-24 20:18:31 +00:00
parent 5c296dc0ba
commit 6c6d3d8f0c
13 changed files with 33 additions and 183 deletions

View File

@ -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 */

View File

@ -19,7 +19,7 @@
#include <ac/string.h>
#include <ac/socket.h>
#ifdef MACOS
#ifdef HAVE_CONSOLE_H
#include <console.h>
#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 */

View File

@ -11,9 +11,9 @@
#include <ac/socket.h>
#include <ac/string.h>
#ifdef MACOS
#ifdef HAVE_CONSOLE_H
#include <console.h>
#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 );

View File

@ -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;

View File

@ -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 );
}

View File

@ -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 );
}
}

View File

@ -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

View File

@ -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 */

View File

@ -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 */

View File

@ -911,11 +911,6 @@ time2text( char *ldtimestr, int dateonly )
/* gtime.c - inverse gmtime */
#if !defined( MACOS ) && !defined( _WIN32 ) && !defined( DOS )
#include <sys/time.h>
#endif /* !MACOS */
/* gtime(): the inverse of localtime().
This routine was supplied by Mike Accetta at CMU many years ago.
*/

View File

@ -6,7 +6,7 @@
#include <ac/socket.h>
#include <ac/time.h>
#ifdef MACOS
#ifdef HAVE_CONSOLE_H
#include <console.h>
#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 ) {
;

View File

@ -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 );
}

View File

@ -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 );