Commit 0c389957 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

More changes from -devel.

parent 6f0bc8c9
......@@ -13,13 +13,9 @@
#ifndef _LBER_H
#define _LBER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ldap_cdefs.h>
#if !defined( NEEDPROTOS ) && defined(__STDC__)
#define NEEDPROTOS 1
#endif
LDAP_BEGIN_DECL
/* BER classes and mask */
#define LBER_CLASS_UNIVERSAL 0x00
......@@ -58,12 +54,9 @@ extern "C" {
#define OLD_LBER_SEQUENCE 0x10L /* w/o constructed bit - broken */
#define OLD_LBER_SET 0x11L /* w/o constructed bit - broken */
#ifdef NEEDPROTOS
typedef int (*BERTranslateProc)( char **bufp, unsigned long *buflenp,
int free_input );
#else /* NEEDPROTOS */
typedef int (*BERTranslateProc)();
#endif /* NEEDPROTOS */
typedef int (*BERTranslateProc) LDAP_P(( char **bufp,
unsigned long *buflenp,
int free_input ));
typedef struct berelement {
char *ber_buf;
......@@ -123,62 +116,80 @@ struct berval {
char *bv_val;
};
#ifndef NEEDPROTOS
extern BerElement *ber_alloc();
extern BerElement *der_alloc();
extern BerElement *ber_alloc_t();
extern BerElement *ber_dup();
#ifdef LDAP_DEBUG
extern int lber_debug;
extern void ber_bvfree();
extern void ber_bvecfree();
extern struct berval *ber_bvdup();
extern void ber_dump();
extern void ber_sos_dump();
extern void lber_bprint();
extern void ber_reset();
extern void ber_init();
#else /* NEEDPROTOS */
#if defined(WINSOCK)
#include "proto-lb.h"
#else
#include "proto-lber.h"
#endif
#endif /* NEEDPROTOS */
#if !defined(__alpha) || defined(VMS)
#define LBER_HTONL( l ) htonl( l )
#define LBER_NTOHL( l ) ntohl( l )
#else /* __alpha */
/*
* htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
* lower-order 32-bits of a (64-bit) long, so we define correct versions
* here.
* in bprint.c:
*/
#define LBER_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
| htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
LDAP_F void lber_bprint LDAP_P(( char *data, int len ));
#define LBER_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
| ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
#endif /* __alpha */
/*
* in decode.c:
*/
LDAP_F unsigned long ber_get_tag LDAP_P(( BerElement *ber ));
LDAP_F unsigned long ber_skip_tag LDAP_P(( BerElement *ber, unsigned long *len ));
LDAP_F unsigned long ber_peek_tag LDAP_P(( BerElement *ber, unsigned long *len ));
LDAP_F unsigned long ber_get_int LDAP_P(( BerElement *ber, long *num ));
LDAP_F unsigned long ber_get_stringb LDAP_P(( BerElement *ber, char *buf,
unsigned long *len ));
LDAP_F unsigned long ber_get_stringa LDAP_P(( BerElement *ber, char **buf ));
LDAP_F unsigned long ber_get_stringal LDAP_P(( BerElement *ber, struct berval **bv ));
LDAP_F unsigned long ber_get_bitstringa LDAP_P(( BerElement *ber, char **buf,
unsigned long *len ));
LDAP_F unsigned long ber_get_null LDAP_P(( BerElement *ber ));
LDAP_F unsigned long ber_get_boolean LDAP_P(( BerElement *ber, int *boolval ));
LDAP_F unsigned long ber_first_element LDAP_P(( BerElement *ber, unsigned long *len,
char **last ));
LDAP_F unsigned long ber_next_element LDAP_P(( BerElement *ber, unsigned long *len,
char *last ));
LDAP_F unsigned long ber_scanf LDAP_P(( BerElement *ber, char *fmt, ... ));
LDAP_F void ber_bvfree LDAP_P(( struct berval *bv ));
LDAP_F void ber_bvecfree LDAP_P(( struct berval **bv ));
LDAP_F struct berval *ber_bvdup LDAP_P(( struct berval *bv ));
LDAP_F void ber_set_string_translators LDAP_P(( BerElement *ber,
BERTranslateProc encode_proc, BERTranslateProc decode_proc ));
/*
* in encode.c
*/
LDAP_F int ber_put_enum LDAP_P(( BerElement *ber, long num, unsigned long tag ));
LDAP_F int ber_put_int LDAP_P(( BerElement *ber, long num, unsigned long tag ));
LDAP_F int ber_put_ostring LDAP_P(( BerElement *ber, char *str, unsigned long len,
unsigned long tag ));
LDAP_F int ber_put_string LDAP_P(( BerElement *ber, char *str, unsigned long tag ));
LDAP_F int ber_put_bitstring LDAP_P(( BerElement *ber, char *str,
unsigned long bitlen, unsigned long tag ));
LDAP_F int ber_put_null LDAP_P(( BerElement *ber, unsigned long tag ));
LDAP_F int ber_put_boolean LDAP_P(( BerElement *ber, int boolval,
unsigned long tag ));
LDAP_F int ber_start_seq LDAP_P(( BerElement *ber, unsigned long tag ));
LDAP_F int ber_start_set LDAP_P(( BerElement *ber, unsigned long tag ));
LDAP_F int ber_put_seq LDAP_P(( BerElement *ber ));
LDAP_F int ber_put_set LDAP_P(( BerElement *ber ));
LDAP_F int ber_printf LDAP_P(( BerElement *ber, char *fmt, ... ));
/*
* SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
* in io.c:
*/
#ifdef MACOS
#define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
#else /* MACOS */
#ifdef sunos4
#define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
#else /* sunos4 */
#define SAFEMEMCPY( d, s, n ) memmove( d, s, n )
#endif /* sunos4 */
#endif /* MACOS */
LDAP_F long ber_read LDAP_P(( BerElement *ber, char *buf, unsigned long len ));
LDAP_F long ber_write LDAP_P(( BerElement *ber, char *buf, unsigned long len,
int nosos ));
LDAP_F void ber_free LDAP_P(( BerElement *ber, int freebuf ));
LDAP_F int ber_flush LDAP_P(( Sockbuf *sb, BerElement *ber, int freeit ));
LDAP_F BerElement *ber_alloc LDAP_P(( void ));
LDAP_F BerElement *der_alloc LDAP_P(( void ));
LDAP_F BerElement *ber_alloc_t LDAP_P(( int options ));
LDAP_F BerElement *ber_dup LDAP_P(( BerElement *ber ));
LDAP_F void ber_dump LDAP_P(( BerElement *ber, int inout ));
LDAP_F void ber_sos_dump LDAP_P(( Seqorset *sos ));
LDAP_F unsigned long ber_get_next LDAP_P(( Sockbuf *sb, unsigned long *len,
BerElement *ber ));
LDAP_F void ber_init LDAP_P(( BerElement *ber, int options ));
LDAP_F void ber_reset LDAP_P(( BerElement *ber, int was_writing ));
LDAP_END_DECL
#ifdef __cplusplus
}
#endif
#endif /* _LBER_H */
......@@ -5,30 +5,21 @@
* cldap.c - synchronous, retrying interface to the cldap protocol
*/
#include "portable.h"
#ifdef CLDAP
#ifdef LDAP_CONNECTIONLESS
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1990, 1994 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef MACOS
#include <stdlib.h>
#include "macos.h"
#else /* MACOS */
#ifdef DOS
#include "msdos.h"
#else /* DOS */
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif /* DOS */
#endif /* MACOS */
#include <ac/errno.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include "lber.h"
#include "ldap.h"
......@@ -37,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;
......@@ -49,17 +36,14 @@ struct cldap_retinfo {
long cri_timeout;
};
#ifdef NEEDPROTOS
static int add_addr( LDAP *ld, struct sockaddr *sap );
static int cldap_result( LDAP *ld, int msgid, LDAPMessage **res,
struct cldap_retinfo *crip, char *base );
static int cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber,
LDAPMessage **res, char *base );
#else /* NEEDPROTOS */
static int add_addr();
static int cldap_result();
static int cldap_parsemsg();
#endif /* NEEDPROTOS */
static int add_addr LDAP_P((
LDAP *ld, struct sockaddr *sap ));
static int cldap_result LDAP_P((
LDAP *ld, int msgid, LDAPMessage **res,
struct cldap_retinfo *crip, char *base ));
static int cldap_parsemsg LDAP_P((
LDAP *ld, int msgid, BerElement *ber,
LDAPMessage **res, char *base ));
/*
* cldap_open - initialize and connect to an ldap server. A magic cookie to
......@@ -127,7 +111,7 @@ cldap_open( char *host, int port )
}
}
if ( (address = inet_addr( host )) == -1 ) {
if ( (address = inet_addr( host )) == -1UL ) {
if ( (hp = gethostbyname( host )) == NULL ) {
errno = EHOSTUNREACH;
continue;
......@@ -170,7 +154,7 @@ cldap_open( char *host, int port )
if ( ld->ld_sb.sb_addrs == NULL
#ifdef LDAP_REFERRALS
|| ( ld->ld_defconn = new_connection( ld, NULL, 1,0,0 )) == NULL
|| ( ld->ld_defconn = ldap_new_connection( ld, NULL, 1,0,0 )) == NULL
#endif /* LDAP_REFERRALS */
) {
free( ld );
......@@ -240,7 +224,7 @@ cldap_search_s( LDAP *ld, char *base, int scope, char *filter, char **attrs,
attrsonly )) == -1 ) {
return( ld->ld_errno );
}
#ifndef NO_CACHE
#ifndef LDAP_NOCACHE
if ( ld->ld_cache != NULL && ld->ld_responses != NULL ) {
Debug( LDAP_DEBUG_TRACE, "cldap_search_s res from cache\n",
0, 0, 0 );
......@@ -248,7 +232,7 @@ cldap_search_s( LDAP *ld, char *base, int scope, char *filter, char **attrs,
ld->ld_responses = ld->ld_responses->lm_next;
return( ldap_result2error( ld, *res, 0 ));
}
#endif /* NO_CACHE */
#endif /* LDAP_NOCACHE */
ret = cldap_result( ld, msgid, res, &cri, base );
} while (ret == -1);
......@@ -316,7 +300,7 @@ cldap_result( LDAP *ld, int msgid, LDAPMessage **res,
"cldap_result waiting up to %d seconds for a response\n",
tv.tv_sec, 0, 0 );
ber_init( &ber, 0 );
set_ber_options( ld, &ber );
ldap_set_ber_options( ld, &ber );
if ( cldap_getmsg( ld, &tv, &ber ) == -1 ) {
ret = ld->ld_errno;
......@@ -432,7 +416,7 @@ cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber,
tag != LBER_DEFAULT && rc != LDAP_SUCCESS;
tag = ber_next_element( ber, &len, cookie )) {
if (( ldm = (LDAPMessage *)calloc( 1, sizeof(LDAPMessage)))
== NULL || ( ldm->lm_ber = alloc_ber_with_options( ld ))
== NULL || ( ldm->lm_ber = ldap_alloc_ber_with_options( ld ))
== NULLBER ) {
rc = LDAP_NO_MEMORY;
break; /* return w/error*/
......@@ -504,11 +488,11 @@ cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber,
}
#endif /* LDAP_DEBUG */
#ifndef NO_CACHE
#ifndef LDAP_NOCACHE
if ( ld->ld_cache != NULL ) {
add_result_to_cache( ld, ldm );
ldap_add_result_to_cache( ld, ldm );
}
#endif /* NO_CACHE */
#endif /* LDAP_NOCACHE */
if ( chain == NULL ) {
chain = ldm;
......@@ -534,4 +518,4 @@ cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber,
*res = chain;
return(( *res == NULLMSG ) ? rc : ldap_result2error( ld, *res, 0 ));
}
#endif /* CLDAP */
#endif /* LDAP_CONNECTIONLESS */
......@@ -5,68 +5,33 @@
* os-ip.c -- platform-specific TCP & UDP related code
*/
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <ac/errno.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include <ac/unistd.h>
#ifdef _WIN32
#ifdef HAVE_IO_H
#include <io.h>
#include "msdos.h"
#else /* _WIN32 */
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif /* _WIN32 */
#ifdef _AIX
#include <sys/select.h>
#endif /* _AIX */
#ifdef VMS
#include "ucx_select.h"
#endif /* VMS */
#include "portable.h"
#include "lber.h"
#include "ldap.h"
#endif /* HAVE_IO_H */
#ifdef LDAP_REFERRALS
#ifdef USE_SYSCONF
#include <unistd.h>
#endif /* USE_SYSCONF */
#ifdef notyet
#ifdef NEED_FILIO
#if defined( HAVE_SYS_FILIO_H )
#include <sys/filio.h>
#else /* NEED_FILIO */
#elif defined( HAVE_SYS_IOCTL_H )
#include <sys/ioctl.h>
#endif /* NEED_FILIO */
#endif /* notyet */
#endif /* LDAP_REFERRALS */
#ifdef MACOS
#define tcp_close( s ) tcpclose( s )
#else /* MACOS */
#ifdef DOS
#ifdef PCNFS
#define tcp_close( s ) close( s )
#endif /* PCNFS */
#ifdef NCSA
#define tcp_close( s ) netclose( s ); netshut()
#endif /* NCSA */
#ifdef WINSOCK
#define tcp_close( s ) closesocket( s ); WSACleanup();
#endif /* WINSOCK */
#else /* DOS */
#define tcp_close( s ) close( s )
#endif /* DOS */
#endif /* MACOS */
#endif
#include "lber.h"
#include "ldap.h"
#include "ldap-int.h"
int
connect_to_host( Sockbuf *sb, char *host, unsigned long address,
ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
int port, int async )
/*
* if host == NULL, connect using address
......@@ -76,23 +41,28 @@ connect_to_host( Sockbuf *sb, char *host, unsigned long address,
* XXX async is not used yet!
*/
{
int rc, i, s, connected, use_hp;
int rc, i, s = 0;
int connected, use_hp;
struct sockaddr_in sin;
struct hostent *hp;
struct hostent *hp = NULL;
#ifdef notyet
#ifdef LDAP_REFERRALS
int status; /* for ioctl call */
#endif /* LDAP_REFERRALS */
#endif /* notyet */
Debug( LDAP_DEBUG_TRACE, "connect_to_host: %s:%d\n",
( host == NULL ) ? "(by address)" : host, ntohs( port ), 0 );
Debug( LDAP_DEBUG_TRACE, "ldap_connect_to_host: %s:%d\n",
( host == NULL ) ? "(by address)" : host, (int) ntohs( (short) port ), 0 );
connected = use_hp = 0;
if ( host != NULL && ( address = inet_addr( host )) == -1 ) {
if ( host != NULL && ( address = inet_addr( host )) == -1UL ) {
if ( (hp = gethostbyname( host )) == NULL ) {
#ifdef HAVE_WINSOCK
errno = WSAGetLastError();
#else
errno = EHOSTUNREACH; /* not exactly right, but... */
#endif
return( -1 );
}
use_hp = 1;
......@@ -125,6 +95,9 @@ connect_to_host( Sockbuf *sb, char *host, unsigned long address,
rc = 0;
break;
} else {
#ifdef HAVE_WINSOCK
errno = WSAGetLastError();
#endif
#ifdef notyet
#ifdef LDAP_REFERRALS
#ifdef EAGAIN
......@@ -145,7 +118,7 @@ connect_to_host( Sockbuf *sb, char *host, unsigned long address,
perror( (char *)inet_ntoa( sin.sin_addr ));
}
#endif
close( s );
tcp_close( s );
if ( !use_hp ) {
break;
}
......@@ -166,7 +139,7 @@ connect_to_host( Sockbuf *sb, char *host, unsigned long address,
#endif /* notyet */
Debug( LDAP_DEBUG_TRACE, "sd %d connected to: %s\n",
s, inet_ntoa( sin.sin_addr ), 0 );
s, (char *) inet_ntoa( sin.sin_addr ), 0 );
}
return( rc );
......@@ -174,15 +147,15 @@ connect_to_host( Sockbuf *sb, char *host, unsigned long address,
void
close_connection( Sockbuf *sb )
ldap_close_connection( Sockbuf *sb )
{
tcp_close( sb->sb_sd );
}
#ifdef KERBEROS
#ifdef HAVE_KERBEROS
char *
host_connected_to( Sockbuf *sb )
ldap_host_connected_to( Sockbuf *sb )
{
struct hostent *hp;
char *p;
......@@ -209,7 +182,7 @@ host_connected_to( Sockbuf *sb )
return( NULL );
}
#endif /* KERBEROS */
#endif /* HAVE_KERBEROS */
#ifdef LDAP_REFERRALS
......@@ -223,45 +196,45 @@ struct selectinfo {
void
mark_select_write( LDAP *ld, Sockbuf *sb )
ldap_mark_select_write( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
sip = (struct selectinfo *)ld->ld_selectinfo;
if ( !FD_ISSET( sb->sb_sd, &sip->si_writefds )) {
FD_SET( sb->sb_sd, &sip->si_writefds );
FD_SET( (u_int) sb->sb_sd, &sip->si_writefds );
}
}
void
mark_select_read( LDAP *ld, Sockbuf *sb )
ldap_mark_select_read( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
sip = (struct selectinfo *)ld->ld_selectinfo;
if ( !FD_ISSET( sb->sb_sd, &sip->si_readfds )) {
FD_SET( sb->sb_sd, &sip->si_readfds );
FD_SET( (u_int) sb->sb_sd, &sip->si_readfds );
}
}
void
mark_select_clear( LDAP *ld, Sockbuf *sb )
ldap_mark_select_clear( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
sip = (struct selectinfo *)ld->ld_selectinfo;
FD_CLR( sb->sb_sd, &sip->si_writefds );
FD_CLR( sb->sb_sd, &sip->si_readfds );
FD_CLR( (u_int) sb->sb_sd, &sip->si_writefds );
FD_CLR( (u_int) sb->sb_sd, &sip->si_readfds );
}
int
is_write_ready( LDAP *ld, Sockbuf *sb )
ldap_is_write_ready( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
......@@ -272,7 +245,7 @@ is_write_ready( LDAP *ld, Sockbuf *sb )
int
is_read_ready( LDAP *ld, Sockbuf *sb )
ldap_is_read_ready( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
......@@ -283,7 +256,7 @@ is_read_ready( LDAP *ld, Sockbuf *sb )
void *
new_select_info()
ldap_new_select_info()
{
struct selectinfo *sip;
......@@ -298,7 +271,7 @@ new_select_info()
void
free_select_info( void *sip )
ldap_free_select_info( void *sip )
{
free( sip );
}
......@@ -313,11 +286,17 @@ do_ldap_select( LDAP *ld, struct timeval *timeout )
Debug( LDAP_DEBUG_TRACE, "do_ldap_select\n", 0, 0, 0 );
if ( tblsize == 0 ) {
#ifdef USE_SYSCONF
#if defined( HAVE_SYSCONF )
tblsize = sysconf( _SC_OPEN_MAX );
#else /* USE_SYSCONF */
#elif defined( HAVE_GETDTABLESIZE )
tblsize = getdtablesize();
#endif /* USE_SYSCONF */
#endif /* !USE_SYSCONF */
#ifdef FD_SETSIZE
if( tblsize > FD_SETSIZE ) {
tblsize = FD_SETSIZE;
}
#endif /* FD_SETSIZE*/
}
sip = (struct selectinfo *)ld->ld_selectinfo;
......
......@@ -10,19 +10,24 @@
* is provided ``as is'' without express or implied warranty.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/socket.h>
#include <quipu/commonarg.h>
#include <quipu/attrvalue.h>
#include <quipu/ds_error.h>
#include <quipu/abandon.h>
#include <quipu/dap2.h>
#include <quipu/dua.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "lber.h"
#include "ldap.h"
#include "common.h"
int
do_abandon(
struct conn *dsaconn,
BerElement *ber,
......
......@@ -10,27 +10,32 @@
* is provided ``as is'' without express or implied warranty.
*/
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <ac/errno.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include <quipu/commonarg.h>
#include <quipu/ds_error.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include "lber.h"