#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
#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;
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 */
* 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"
#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;
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
}
}
- if ( (address = inet_addr( host )) == -1 ) {
+ if ( (address = inet_addr( host )) == -1UL ) {
if ( (hp = gethostbyname( host )) == NULL ) {
errno = EHOSTUNREACH;
continue;
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 );
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 );
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);
"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;
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*/
}
#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;
*res = chain;
return(( *res == NULLMSG ) ? rc : ldap_result2error( ld, *res, 0 ));
}
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
* 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
* 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;
rc = 0;
break;
} else {
+#ifdef HAVE_WINSOCK
+ errno = WSAGetLastError();
+#endif
#ifdef notyet
#ifdef LDAP_REFERRALS
#ifdef EAGAIN
perror( (char *)inet_ntoa( sin.sin_addr ));
}
#endif
- close( s );
+ tcp_close( s );
if ( !use_hp ) {
break;
}
#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 );
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;
return( NULL );
}
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
#ifdef LDAP_REFERRALS
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;
int
-is_read_ready( LDAP *ld, Sockbuf *sb )
+ldap_is_read_ready( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
void *
-new_select_info()
+ldap_new_select_info()
{
struct selectinfo *sip;
void
-free_select_info( void *sip )
+ldap_free_select_info( void *sip )
{
free( sip );
}
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;
* 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,
* 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"
#include "ldap.h"
+
#if ISODEPACKAGE == IC
#include <ll/isoaddrs.h>
#else
#include <isoaddrs.h>
#endif
#include "common.h"
-#ifdef SVR4
-#if !defined(_AIX) && !defined(__osf__)
-#include <sys/filio.h>
+
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
#endif
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
#endif
#ifdef __hpux
conns = new;
}
-static psap_cmp( struct PSAPaddr *a, struct PSAPaddr *b )
+static int
+psap_cmp( struct PSAPaddr *a, struct PSAPaddr *b )
{
return( bcmp( (char *) a, (char *) b, sizeof(struct PSAPaddr) ) );
}
* donated by Eric Rosenquist and BNR
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include <quipu/commonarg.h>
#include <quipu/attrvalue.h>
#include <quipu/ds_error.h>
#include <quipu/ds_search.h>
#include <quipu/dap2.h>
#include <quipu/dua.h>
+
#include "lber.h"
#include "ldap.h"
#include "common.h"
{
extern short ldap_certif_syntax;
sntx_table *syntax_table;
- extern sntx_table *get_syntax_table();
+ extern sntx_table *get_syntax_table( short int sntx );
- if (syntax_table = get_syntax_table(ldap_certif_syntax)) {
+ if ((syntax_table = get_syntax_table(ldap_certif_syntax)) != NULL) {
syntax_table->s_print = (void *) ldap_certif_print;
syntax_table->s_parse = (void *) ldap_str2cert;
} else
#include "lber.h"
#include "ldap.h"
#include "common.h"
+#include "lutil.h" /* Get lutil_detach() */
#ifdef HAVE_TCPD
#include <tcpd.h>
#endif /* TCP_WRAPPERS */
void log_and_exit();
-static set_socket();
-static do_queries();
+static int set_socket();
+static void do_queries();
static RETSIGTYPE wait4child();
#ifdef LDAP_CONNECTIONLESS
-static udp_init();
+static int udp_init();
#endif
#ifdef LDAP_DEBUG
extern char Versionstr[];
-static usage( name )
-char *name;
+static void
+usage( char *name )
{
fprintf( stderr, "usage: %s [-d debuglvl] [-p port] [-l] [-c dsa] [-r referraltimeout]", name );
#ifdef LDAP_CONNECTIONLESS
fprintf( stderr, "\n" );
}
+int
main (argc, argv)
int argc;
char **argv;
(void) get_syntaxes();
if (RunFromInetd) {
len = sizeof( socktype );
- getsockopt( ns, SOL_SOCKET, SO_TYPE, &socktype, &len );
+ getsockopt( ns, SOL_SOCKET, SO_TYPE, (char *)&socktype, &len );
if ( socktype == SOCK_DGRAM ) {
#ifdef LDAP_CONNECTIONLESS
Debug( LDAP_DEBUG_ARGS,
/* NOT REACHED */
}
-static
+static void
do_queries(
int clientsock,
int udp /* is this a UDP (CLDAP) request? */
)
{
fd_set readfds;
- int rc, i;
+ int rc;
struct timeval timeout;
Sockbuf sb;
#ifdef LDAP_CONNECTIONLESS
#ifdef LDAP_DEBUG
if ( ldap_debug & LDAP_DEBUG_CONNS ) {
+ int i;
Debug( LDAP_DEBUG_CONNS, "FDLIST:", 0, 0, 0 );
for ( i = 0; i < dtblsize; i++ ) {
if ( FD_ISSET( i, &readfds ) ) {
/* NOT REACHED */
}
-static set_socket(
+static int
+set_socket(
int port,
int udp /* UDP port? */
)
* is provided ``as is'' without express or implied warranty.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include <quipu/commonarg.h>
#include <quipu/ds_error.h>
+
#include "lber.h"
#include "ldap.h"
#include "common.h"
new->m_conn->c_refcnt++;
new->m_next = NULL;
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
new->m_cldap = udp;
new->m_searchbase = NULLDN;
}
if ( cur == NULL ) {
- Debug( LDAP_DEBUG_ANY, "delmsg: cannot find msg %x\n", m,
- 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "delmsg: cannot find msg %lx\n",
+ (unsigned long) m, 0, 0 );
return( -1 );
}
conn_free( cur->m_conn );
modlist_free( cur->m_mods );
ber_free( cur->m_ber, 1 );
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( cur->m_searchbase != NULLDN ) {
dn_free( cur->m_searchbase );
}
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
free( (char *) cur );
return( 0 );
}
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
struct msg *
get_cldap_msg(
int msgid,
return( tmp );
}
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
* is provided ``as is'' without express or implied warranty.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <sys/wait.h>
-#include <signal.h>
+
+#include <ac/signal.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/syslog.h>
+#include <ac/time.h>
+#include <ac/wait.h>
+
#include <quipu/commonarg.h>
#include <quipu/ds_error.h>
#include <quipu/dap2.h>
#include <quipu/dua.h>
-#ifdef __hpux
-#include <syslog.h>
-#else
-#include <sys/syslog.h>
-#endif
+
#include "lber.h"
#include "ldap.h"
#include "common.h"
static int bound;
extern char *bound_dn, *bound_pw;
struct PSAPaddr *psap_cpy();
-#ifdef COMPAT
+#ifdef LDAP_COMPAT
extern int ldap_compat;
#endif
log_and_exit( 1 );
}
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( udp && dosyslog ) {
syslog( LOG_INFO, "UDP request from unknown (%s)",
inet_ntoa( ((struct sockaddr_in *)
trace_ber( tag, len, ber.ber_buf, stderr, 1, 1 );
#endif
-#ifdef COMPAT
+#ifdef LDAP_COMPAT
/*
* This tag should be a normal SEQUENCE tag. In release 2.0 this
* tag is 0x10. In the new stuff this is 0x30. To distinguish
ttag = ber_skip_tag( &tber, &tlen );
ttag = ber_peek_tag( &tber, &tlen );
- Debug( LDAP_DEBUG_ANY, "checking for 3.0 tag 0x%x\n",
- ttag, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "checking for 3.0 tag 0x%lx\n",
+ ttag, 0, 0 );
if ( ttag == LBER_SEQUENCE ) {
Debug( LDAP_DEBUG_ANY, "version 3.0 detected\n",
0, 0, 0 );
return;
}
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( udp ) {
char *logdn = NULL;
free( logdn );
}
}
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
tag = ber_skip_tag( &ber, &len );
else
#endif
tag = ber_peek_tag( &ber, &len );
if ( !udp && bound == 0 && tag != LDAP_REQ_BIND
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
&& tag != OLD_LDAP_REQ_BIND
#endif
) {
return;
}
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if (udp && tag != LDAP_REQ_SEARCH && tag != LDAP_REQ_ABANDON ) {
send_ldap_result( clientsb, tag, msgid, LDAP_OPERATIONS_ERROR,
NULL, "Only search is supported over UDP/CLDAP" );
copyofber = ber_dup( &ber );
m = add_msg( msgid, tag, copyofber, dsaconn, udp,
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
(struct sockaddr *)clientsb->sb_fromaddr );
#else
NULL );
Debug( LDAP_DEBUG_TRACE, "do_request\n", 0, 0, 0 );
switch ( m->m_msgtype ) {
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_BIND:
#endif
case LDAP_REQ_BIND:
resp_required = do_bind( clientsb, m, ber, bound );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_UNBIND:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_REQ_UNBIND_30:
#endif
case LDAP_REQ_UNBIND:
log_and_exit( 0 );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_ADD:
#endif
case LDAP_REQ_ADD:
resp_required = do_add( clientsb, m, ber );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_DELETE:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_REQ_DELETE_30:
#endif
case LDAP_REQ_DELETE:
resp_required = do_delete( clientsb, m, ber );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_MODRDN:
#endif
case LDAP_REQ_MODRDN:
resp_required = do_modrdn( clientsb, m, ber );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_MODIFY:
#endif
case LDAP_REQ_MODIFY:
resp_required = do_modify( clientsb, m, ber );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_COMPARE:
#endif
case LDAP_REQ_COMPARE:
resp_required = do_compare( clientsb, m, ber );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_SEARCH:
#endif
case LDAP_REQ_SEARCH:
resp_required = do_search( clientsb, m, ber );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_REQ_ABANDON:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_REQ_ABANDON_30:
#endif
case LDAP_REQ_ABANDON:
* is provided ``as is'' without express or implied warranty.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include <quipu/commonarg.h>
#include <quipu/attrvalue.h>
#include <quipu/ds_error.h>
#include <quipu/ds_search.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"
-static get_filter();
-static get_filter_list();
-static get_substring_filter();
+static int get_filter();
+static int get_filter_list();
+static int get_substring_filter();
-#ifdef COMPAT
+#ifdef LDAP_COMPAT
extern int version;
extern int ldap_compat;
#define SEARCHRESTAG (ldap_compat == 20 ? OLD_LDAP_RES_SEARCH_RESULT : LDAP_RES_SEARCH_RESULT)
rc = initiate_dap_operation( OP_SEARCH, m, &sa );
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( m->m_cldap )
m->m_searchbase = sa.sra_baseobject;
else
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
dn_free( sa.sra_baseobject );
filter_free( sa.sra_filter );
return( 1 );
}
-static get_filter( BerElement *ber, Filter *filt )
+static int
+get_filter( BerElement *ber, Filter *filt )
{
unsigned long tag, len;
int err;
err = 0;
switch (tag = ber_peek_tag( ber, &len )) {
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_EQUALITY:
#endif
case LDAP_FILTER_EQUALITY:
Debug( LDAP_DEBUG_ARGS, "EQUALITY\n", 0, 0, 0 );
f->flt_type = FILTER_ITEM;
f->FUITEM.fi_type = FILTERITEM_EQUALITY;
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
}
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_SUBSTRINGS:
#endif
case LDAP_FILTER_SUBSTRINGS:
err = get_substring_filter( ber, f );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_GE:
#endif
case LDAP_FILTER_GE:
Debug( LDAP_DEBUG_ARGS, "GE\n", 0, 0, 0 );
f->flt_type = FILTER_ITEM;
f->FUITEM.fi_type = FILTERITEM_GREATEROREQUAL;
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
}
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_LE:
#endif
case LDAP_FILTER_LE:
Debug( LDAP_DEBUG_ARGS, "LE\n", 0, 0, 0 );
f->flt_type = FILTER_ITEM;
f->FUITEM.fi_type = FILTERITEM_LESSOREQUAL;
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
}
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_PRESENT:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_FILTER_PRESENT_30:
#endif
case LDAP_FILTER_PRESENT:
f->flt_type = FILTER_ITEM;
f->FUITEM.fi_type = FILTERITEM_PRESENT;
len = sizeof(typestr);
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
return( LDAP_UNDEFINED_TYPE );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_APPROX:
#endif
case LDAP_FILTER_APPROX:
Debug( LDAP_DEBUG_ARGS, "APPROX\n", 0, 0, 0 );
f->flt_type = FILTER_ITEM;
f->FUITEM.fi_type = FILTERITEM_APPROX;
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
}
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_AND:
#endif
case LDAP_FILTER_AND:
err = get_filter_list( ber, f );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_OR:
#endif
case LDAP_FILTER_OR:
err = get_filter_list( ber, f );
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_FILTER_NOT:
#endif
case LDAP_FILTER_NOT:
break;
default:
- Debug( LDAP_DEBUG_ANY, "unknown filter type %d\n", tag, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "unknown filter type %lu\n", tag, 0, 0 );
free( f );
return( LDAP_PROTOCOL_ERROR );
break;
return( err );
}
-static get_filter_list( BerElement *ber, Filter f )
+static int
+get_filter_list( BerElement *ber, Filter f )
{
Filter new, tail;
int err;
Debug( LDAP_DEBUG_TRACE, "get_filter_list\n", 0, 0, 0 );
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
return( 0 );
}
-static get_substring_filter( BerElement *ber, Filter f )
+static int
+get_substring_filter( BerElement *ber, Filter f )
{
unsigned long tag, len;
char typestr[64];
Debug( LDAP_DEBUG_TRACE, "get_substring_filter\n", 0, 0, 0 );
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 )
(void) ber_skip_tag( ber, &len );
#endif
tag = ber_next_element( ber, &len, last ) ) {
AV_Sequence avs, any_end;
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 ) {
if ( ber_scanf( ber, "{a}", &valstr ) == LBER_ERROR ) {
return( LDAP_PROTOCOL_ERROR );
return( LDAP_OPERATIONS_ERROR );
switch ( tag ) {
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_SUBSTRING_INITIAL:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_SUBSTRING_INITIAL_30:
#endif
case LDAP_SUBSTRING_INITIAL:
f->FUITEM.UNSUB.fi_sub_initial = avs;
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_SUBSTRING_ANY:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_SUBSTRING_ANY_30:
#endif
case LDAP_SUBSTRING_ANY:
any_end = avs;
break;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
case OLD_LDAP_SUBSTRING_FINAL:
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
case LDAP_SUBSTRING_FINAL_30:
#endif
case LDAP_SUBSTRING_FINAL:
correlate_search_results( sr );
}
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( m->m_cldap ) {
if ((ber = der_alloc()) == NULLBER ) {
send_ldap_msgresult( sb, SEARCHRESTAG, m,
for ( e = sr->CSR_entries; e != NULLENTRYINFO; e = e->ent_next ) {
Debug( LDAP_DEBUG_ARGS, "\tentry:\n", 0, 0, 0 );
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( !m->m_cldap )
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
if ( (ber = der_alloc()) == NULLBER ) {
send_ldap_msgresult( sb, SEARCHRESTAG, m,
return;
}
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
if ( version == 1 ) {
if ( ber_printf( ber, "t{it{", OLD_LBER_SEQUENCE,
m->m_msgid, OLD_LDAP_RES_SEARCH_ENTRY ) == -1 ) {
}
} else
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 ) {
if ( ber_printf( ber, "{it{{", m->m_msgid,
LDAP_RES_SEARCH_ENTRY ) == -1 ) {
}
} else
#endif
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( m->m_cldap )
rc = ber_printf( ber, "t{", LDAP_RES_SEARCH_ENTRY );
else
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
rc = ber_printf( ber, "{it{", m->m_msgid,
LDAP_RES_SEARCH_ENTRY );
return;
}
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( m->m_cldap )
rc = encode_dn( ber, e->ent_dn, m->m_searchbase );
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
else
rc = encode_dn( ber, e->ent_dn, NULLDN );
return;
}
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
if ( version == 1 ) {
if ( ber_printf( ber, "}}" ) == -1 ) {
send_ldap_msgresult( sb, SEARCHRESTAG, m,
}
} else
#endif
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
if ( ldap_compat == 30 ) {
if ( ber_printf( ber, "}}}" ) == -1 ) {
send_ldap_msgresult( sb, SEARCHRESTAG, m,
}
} else
#endif
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( m->m_cldap )
rc = ber_printf( ber, "}" );
else
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
rc = ber_printf( ber, "}}" );
if ( rc == -1 ) {
ber->ber_buf, stderr, 0, 0 );
#endif
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( !m->m_cldap )
#endif
(void) ber_flush( sb, ber, 1 );
Debug( LDAP_DEBUG_ARGS, "\tresult:\n", 0, 0, 0 );
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
if ( m->m_cldap ) {
if ( ber_printf( ber, "t{ess}}}", SEARCHRESTAG, rc, "", "" )
== -1 ) {
* is provided ``as is'' without express or implied warranty.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
+
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include <quipu/commonarg.h>
#include <quipu/attrvalue.h>
#include <quipu/ds_error.h>
#include <quipu/ds_search.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"
static void de_t61( char *s, int t61mark );
static int syntax_is_string( short syntax );
-static get_one_syntax( char *attrib, int required )
+static int
+get_one_syntax( char *attrib, int required )
{
oid_table_attr *p, *name2attr();
return( rc );
}
-static put_jpeg_value( BerElement *ber, AttributeValue av )
+static int
+put_jpeg_value( BerElement *ber, AttributeValue av )
{
PE pe;
int len;
return( 0 );
}
-static put_audio_value( BerElement *ber, AttributeValue av )
+static int
+put_audio_value( BerElement *ber, AttributeValue av )
{
struct qbuf *qb, *p;
int rc, len;
return( rc );
}
-static put_photo_value( BerElement *ber, AttributeValue av )
+static int
+put_photo_value( BerElement *ber, AttributeValue av )
{
PE pe;
PS ps;
return( 0 );
}
-static put_values(
+static int
+put_values(
BerElement *ber,
PS ps,
short syntax,
encode_attrs( BerElement *ber, Attr_Sequence as )
{
PS ps;
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
extern int ldap_compat;
#endif
if ( str_setup( ps, NULLCP, 0, 0 ) == NOTOK )
return( -1 );
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
if ( ber_printf( ber, "t{", ldap_compat == 20 ? OLD_LBER_SEQUENCE :
LBER_SEQUENCE ) == -1 ) {
#else
AttrT_print( ps, as->attr_type, EDBOUT );
*ps->ps_ptr = '\0';
-#ifdef COMPAT20
+#ifdef LDAP_COMPAT20
if ( ber_printf( ber, "t{st[", ldap_compat == 20 ?
OLD_LBER_SEQUENCE : LBER_SEQUENCE, ps->ps_base,
ldap_compat == 20 ? OLD_LBER_SET : LBER_SET ) == -1 ) {
/* abandon.c - ldbm backend abandon routine */
+#include "portable.h"
+
+int
ldbm_back_abandon()
{
}
--- /dev/null
+/*
+ * Copyright (c) 1998 Will Ballantyne, ITSD, Government of BC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to ITSD, Government of BC. The name of ITSD
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <ac/socket.h> /* Get struct sockaddr for slap.h */
+#include "slap.h"
+#include "back-ldbm.h"
+#include "proto-back-ldbm.h"
+
+/*
+ * given an alias object, dereference it to its end point.
+ * entry returned has reader lock
+ */
+Entry *derefAlias_r ( Backend *be,
+ Connection *conn,
+ Operation *op,
+ Entry *e)
+{
+ Attribute *a;
+ int depth;
+ char **pastAliases;
+ char *matched;
+
+ Debug( LDAP_DEBUG_TRACE, "<= checking for alias for dn %s\n", e->e_dn, 0, 0 );
+
+ /*
+ * try to deref fully, up to a maximum depth. If the max depth exceeded
+ * then send an error
+ */
+ for ( depth = 0;
+ ( ( a = attr_find( e->e_attrs, "aliasedobjectname" ) ) != NULL) &&
+ ( depth < be->be_maxDerefDepth );
+ ++depth)
+ {
+
+ /*
+ * make sure there is a defined aliasedobjectname.
+ * can only have one value so just use first value (0) in the attr list.
+ */
+ if (a->a_vals[0] && a->a_vals[0]->bv_val) {
+ char *newDN, *oldDN;
+
+ Debug( LDAP_DEBUG_TRACE, "<= %s is an alias for %s\n",
+ e->e_dn, a->a_vals[0]->bv_val, 0 );
+ newDN = strdup (a->a_vals[0]->bv_val);
+ oldDN = strdup (e->e_dn);
+
+ /*
+ * ok, so what happens if there is an alias in the DN of a dereferenced
+ * alias object?
+ */
+ if ( (e = dn2entry_r( be, newDN, &matched )) == NULL ) {
+
+ /* could not deref return error */
+ Debug( LDAP_DEBUG_TRACE,
+ "<= %s is a dangling alias to %s\n",
+ oldDN, newDN, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Dangling Alias" );
+
+ if(matched != NULL) free(matched);
+ }
+ free (newDN);
+ free (oldDN);
+ }
+ else {
+ /*
+ * there was an aliasedobjectname defined but no data.
+ * this can't happen, right?
+ */
+ Debug( LDAP_DEBUG_TRACE,
+ "<= %s has no data in aliasedobjectname attribute\n",
+ e->e_dn, 0, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Alias missing aliasedobjectname" );
+ }
+ }
+
+ /*
+ * warn if we pulled out due to exceeding the maximum deref depth
+ */
+ if ( depth >= be->be_maxDerefDepth ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<= %s exceeded maximum deref depth %d\n",
+ e->e_dn, be->be_maxDerefDepth, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Maximum alias dereference depth exceeded" );
+ }
+
+ return e;
+}
+
+/*
+ * given a DN fully deref it and return the real DN or original DN if it fails
+ */
+char *derefDN ( Backend *be,
+ Connection *conn,
+ Operation *op,
+ char *dn
+)
+{
+ struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+ char *matched;
+ char *newDN;
+ int depth;
+ Entry *eMatched;
+ Entry *eDeref;
+ Entry *eNew;
+
+
+ Debug( LDAP_DEBUG_TRACE,
+ "<= dereferencing dn %s\n",
+ dn, 0, 0 );
+
+ newDN = strdup ( dn );
+
+ /* while we don't have a matched dn, deref the DN */
+ for ( depth = 0;
+ ( (eMatched = dn2entry_r( be, newDN, &matched )) == NULL) &&
+ (depth < be->be_maxDerefDepth);
+ ++depth ) {
+
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eMatched);
+
+ if (*matched) {
+ char *submatch;
+
+ /*
+ * make sure there actually is an entry for the matched part
+ */
+ if ( (eMatched = dn2entry_r( be, matched, &submatch )) != NULL) {
+ char *remainder; /* part before the aliased part */
+ int rlen = strlen(newDN) - strlen(matched);
+
+ Debug( LDAP_DEBUG_TRACE, "<= matched %s\n", matched, 0, 0 );
+
+ remainder = ch_malloc (rlen + 1);
+ strncpy ( remainder, newDN, rlen );
+ remainder[rlen] = '\0';
+
+ Debug( LDAP_DEBUG_TRACE, "<= remainder %s\n", remainder, 0, 0 );
+
+ if ((eNew = derefAlias_r( be, conn, op, eMatched )) == NULL) {
+ free (matched);
+ free (newDN);
+ free (remainder);
+ break; /* no associated entry, dont deref */
+ }
+ else {
+
+ Debug( LDAP_DEBUG_TRACE, "<= l&g we have %s vs %s \n", matched, eNew->e_dn, 0 );
+
+ if (!strcasecmp (matched, eNew->e_dn)) {
+ /* newDN same as old so not an alias, no need to go further */
+ free (newDN);
+ free (matched);
+ free (remainder);
+ break;
+ }
+
+ /*
+ * we have dereferenced the aliased part so put
+ * the new dn together
+ */
+ free (newDN);
+ free (matched);
+
+ newDN = ch_malloc (strlen(eMatched->e_dn) + rlen + 1);
+ strcpy (newDN, remainder);
+ strcat (newDN, eMatched->e_dn);
+ Debug( LDAP_DEBUG_TRACE, "<= expanded to %s\n", newDN, 0, 0 );
+
+ free (remainder);
+
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eNew);
+ }
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eMatched);
+ }
+ else {
+ if(submatch != NULL) free(submatch);
+ break; /* there was no entry for the matched part */
+ }
+ }
+ else {
+ break; /* there was no matched part */
+ }
+ }
+
+ /*
+ * the final part of the DN might be an alias
+ * so try to dereference it.
+ */
+ if ( (eNew = dn2entry_r( be, newDN, &matched )) != NULL) {
+ if ((eDeref = derefAlias_r( be, conn, op, eNew )) != NULL) {
+ free (newDN);
+ newDN = strdup (eDeref->e_dn);
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eDeref);
+ }
+ /* free reader lock */
+ cache_return_entry_r(&li->li_cache, eNew);
+ }
+
+ /*
+ * warn if we exceeded the max depth as the resulting DN may not be dereferenced
+ */
+ if (depth >= be->be_maxDerefDepth) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<= max deref depth exceeded in derefDN for %s, result %s\n",
+ dn, newDN, 0 );
+ send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
+ "Maximum alias dereference depth exceeded for base" );
+ }
+
+ Debug( LDAP_DEBUG_TRACE, "<= returning deref DN of %s\n", newDN, 0, 0 );
+
+ free(matched);
+
+ return newDN;
+}
/* cache.c - routines to maintain an in-core cache of entries */
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/socket.h>
#include "slap.h"
+
#include "back-ldbm.h"
static int cache_delete_entry_internal();
pthread_mutex_unlock( &cache->c_mutex );
}
-void
+static void
cache_return_entry( struct cache *cache, Entry *e )
{
/* set cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
}
+static void
+cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
+{
+ Debug( LDAP_DEBUG_TRACE, "====> cache_return_entry_%s\n",
+ rw ? "w" : "r", 0, 0);
+ entry_rdwr_unlock(e, rw);;
+ cache_return_entry(cache, e);
+}
+
+void
+cache_return_entry_r( struct cache *cache, Entry *e )
+{
+ cache_return_entry_rw(cache, e, 0);
+}
+
+void
+cache_return_entry_w( struct cache *cache, Entry *e )
+{
+ cache_return_entry_rw(cache, e, 1);
+}
+
+
#define LRU_DELETE( cache, e ) { \
if ( e->e_lruprev != NULL ) { \
e->e_lruprev->e_lrunext = e->e_lrunext; \
/* set cache mutex */
pthread_mutex_lock( &cache->c_mutex );
- if ( avl_insert( &cache->c_dntree, e, cache_entrydn_cmp, avl_dup_error )
- != 0 ) {
+ if ( avl_insert( &cache->c_dntree, (caddr_t) e,
+ cache_entrydn_cmp, avl_dup_error ) != 0 )
+ {
Debug( LDAP_DEBUG_TRACE,
- "entry %20s id %d already in dn cache\n", e->e_dn,
- e->e_id, 0 );
+ "====> cache_add_entry lock: entry %20s id %d already in dn cache\n",
+ e->e_dn, e->e_id, 0 );
/* free cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
}
/* id tree */
- if ( avl_insert( &cache->c_idtree, e, cache_entryid_cmp, avl_dup_error )
- != 0 ) {
- Debug( LDAP_DEBUG_ANY, "entry %20s id %d already in id cache\n",
+ if ( avl_insert( &cache->c_idtree, (caddr_t) e,
+ cache_entryid_cmp, avl_dup_error ) != 0 )
+ {
+ Debug( LDAP_DEBUG_ANY,
+ "====> entry %20s id %d already in id cache\n",
e->e_dn, e->e_id, 0 );
/* delete from dn tree inserted above */
- if ( avl_delete( &cache->c_dntree, e, cache_entrydn_cmp )
- == NULL ) {
- Debug( LDAP_DEBUG_ANY, "can't delete from dn cache\n",
+ if ( avl_delete( &cache->c_dntree, (caddr_t) e,
+ cache_entrydn_cmp ) == NULL )
+ {
+ Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
}
== 0 && cache->c_cursize > cache->c_maxsize ) {
e = cache->c_lrutail;
+ /* XXX check for writer lock - should also check no readers pending */
+#ifdef LDAP_DEBUG
+ assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#endif
+
/* delete from cache and lru q */
rc = cache_delete_entry_internal( cache, e );
}
/*
- * cache_find_entry_dn - find an entry in the cache, given dn
+ * cache_find_entry_dn2id - find an entry in the cache, given dn
*/
-Entry *
-cache_find_entry_dn(
+ID
+cache_find_entry_dn2id(
+ Backend *be,
struct cache *cache,
char *dn
)
{
+ struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Entry e, *ep;
+ ID id;
/* set cache mutex */
pthread_mutex_lock( &cache->c_mutex );
e.e_dn = dn;
- if ( (ep = (Entry *) avl_find( cache->c_dntree, &e, cache_entrydn_cmp ))
- != NULL ) {
+
+ if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
+ cache_entrydn_cmp )) != NULL )
+ {
+ Debug(LDAP_DEBUG_TRACE, "====> cache_find_entry_dn2id: found dn: %s\n",
+ dn, 0, 0);
+
/*
* entry is deleted or not fully created yet
*/
if ( ep->e_state == ENTRY_STATE_DELETED ||
- ep->e_state == ENTRY_STATE_CREATING )
+ ep->e_state == ENTRY_STATE_CREATING )
{
/* free cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
- return( NULL );
+ return( NOID );
}
+
+ /* XXX is this safe without writer lock? */
ep->e_refcnt++;
/* lru */
LRU_DELETE( cache, ep );
LRU_ADD( cache, ep );
+
+ /* acquire reader lock */
+ entry_rdwr_lock(ep, 0);
+
+ /* re-check */
+ if ( ep->e_state == ENTRY_STATE_DELETED ||
+ ep->e_state == ENTRY_STATE_CREATING )
+ {
+ /* XXX check that is is required */
+ ep->e_refcnt--;
+
+ /* free reader lock */
+ entry_rdwr_unlock(ep, 0);
+ /* free cache mutex */
+ pthread_mutex_unlock( &cache->c_mutex );
+
+ return( NOID );
+ }
+
+ /* save id */
+ id = ep->e_id;
+
+ /* free reader lock */
+ entry_rdwr_unlock(ep, 0);
+
+ /* free cache mutex */
+ pthread_mutex_unlock( &cache->c_mutex );
+
+ cache_return_entry( &li->li_cache, ep );
+
+ return( id );
}
/* free cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
- return( ep );
+ return( NOID );
}
/*
Entry *
cache_find_entry_id(
- struct cache *cache,
- ID id
+ struct cache *cache,
+ ID id,
+ int rw
)
{
Entry e;
pthread_mutex_lock( &cache->c_mutex );
e.e_id = id;
- if ( (ep = (Entry *) avl_find( cache->c_idtree, &e, cache_entryid_cmp ))
- != NULL ) {
+
+ if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
+ cache_entryid_cmp )) != NULL )
+ {
+ Debug(LDAP_DEBUG_TRACE,
+ "====> cache_find_entry_dn2id: found id: %ld rw: %d\n",
+ id, rw, 0);
+
/*
* entry is deleted or not fully created yet
*/
if ( ep->e_state == ENTRY_STATE_DELETED ||
- ep->e_state == ENTRY_STATE_CREATING )
+ ep->e_state == ENTRY_STATE_CREATING )
{
/* free cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
return( NULL );
}
+ /* XXX is this safe without writer lock? */
ep->e_refcnt++;
/* lru */
LRU_DELETE( cache, ep );
LRU_ADD( cache, ep );
+
+ /* acquire reader lock */
+ entry_rdwr_lock(ep, 0);
+
+ /* re-check */
+ if ( ep->e_state == ENTRY_STATE_DELETED ||
+ ep->e_state == ENTRY_STATE_CREATING ) {
+
+ /* XXX check that is is required */
+ ep->e_refcnt--;
+
+ /* free reader lock */
+ entry_rdwr_unlock(ep, 0);
+
+ /* free cache mutex */
+ pthread_mutex_unlock( &cache->c_mutex );
+ return( NULL );
+ }
+
+ if ( rw ) {
+ entry_rdwr_unlock(ep, 0);
+ entry_rdwr_lock(ep, 1);
+ }
+
+ /* free cache mutex */
+ pthread_mutex_unlock( &cache->c_mutex );
+
+ return( ep );
}
/* free cache mutex */
pthread_mutex_unlock( &cache->c_mutex );
- return( ep );
+ return( NULL );
}
/*
{
int rc;
+ Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry:\n", 0, 0, 0 );
+
+ /* XXX check for writer lock - should also check no readers pending */
+#ifdef LDAP_DEBUG
+ assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#endif
+
/* set cache mutex */
pthread_mutex_lock( &cache->c_mutex );
)
{
/* dn tree */
- if ( avl_delete( &cache->c_dntree, e, cache_entrydn_cmp ) == NULL ) {
+ if ( avl_delete( &cache->c_dntree, (caddr_t) e, cache_entrydn_cmp )
+ == NULL )
+ {
return( -1 );
}
/* id tree */
- if ( avl_delete( &cache->c_idtree, e, cache_entryid_cmp ) == NULL ) {
+ if ( avl_delete( &cache->c_idtree, (caddr_t) e, cache_entryid_cmp )
+ == NULL )
+ {
return( -1 );
}
}
#endif
+
/* compare.c - ldbm backend compare routine */
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include "slap.h"
#include "back-ldbm.h"
+#include "proto-back-ldbm.h"
-extern Entry *dn2entry();
extern Attribute *attr_find();
int
char *matched;
Entry *e;
Attribute *a;
- int i;
+ int rc;
- if ( (e = dn2entry( be, dn, &matched )) == NULL ) {
+ /* get entry with reader lock */
+ if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
return( 1 );
}
+ /* check for deleted */
if ( ! access_allowed( be, conn, op, e, ava->ava_type, &ava->ava_value,
op->o_dn, ACL_COMPARE ) ) {
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
- cache_return_entry( &li->li_cache, e );
- return( 1 );
+ rc = 1;
+ goto return_results;
}
if ( (a = attr_find( e->e_attrs, ava->ava_type )) == NULL ) {
send_ldap_result( conn, op, LDAP_NO_SUCH_ATTRIBUTE, "", "" );
- cache_return_entry( &li->li_cache, e );
- return( 1 );
+ rc = 1;
+ goto return_results;
}
- if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 ) {
+ if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 )
send_ldap_result( conn, op, LDAP_COMPARE_TRUE, "", "" );
- cache_return_entry( &li->li_cache, e );
- return( 0 );
- }
+ else
+ send_ldap_result( conn, op, LDAP_COMPARE_FALSE, "", "" );
+
+ rc = 0;
- send_ldap_result( conn, op, LDAP_COMPARE_FALSE, "", "" );
- cache_return_entry( &li->li_cache, e );
- return( 0 );
+return_results:;
+ cache_return_entry_r( &li->li_cache, e );
+ return( rc );
}
/* id2children.c - routines to deal with the id2children index */
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/socket.h>
+
#include "slap.h"
#include "back-ldbm.h"
)
{
struct dbcache *db;
- Datum key, data;
+ Datum key;
int len, rc;
IDList *idl;
char buf[20];
+#ifdef HAVE_BERKELEY_DB2
+ Datum data;
+ memset( &key, 0, sizeof( key ) );
+ memset( &data, 0, sizeof( data ) );
+#endif
+
Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %d, %d )\n", p ? p->e_id
: 0, e->e_id, 0 );
return( -1 );
}
- sprintf( buf, "%c%d", EQ_PREFIX, p ? p->e_id : 0 );
+ sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 );
key.dptr = buf;
key.dsize = strlen( buf ) + 1;
IDList *idl;
char buf[20];
+#ifdef HAVE_BERKELEY_DB2
+ memset( &key, 0, sizeof( key ) );
+#endif
+
Debug( LDAP_DEBUG_TRACE, "=> has_children( %d )\n", p->e_id , 0, 0 );
if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
return( 0 );
}
- sprintf( buf, "%c%d", EQ_PREFIX, p->e_id );
+ sprintf( buf, "%c%ld", EQ_PREFIX, p->e_id );
key.dptr = buf;
key.dsize = strlen( buf ) + 1;
/* id2entry.c - routines to deal with the id2entry index */
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/socket.h>
+
#include "slap.h"
#include "back-ldbm.h"
extern Datum ldbm_cache_fetch();
extern char *dn_parent();
extern Entry *str2entry();
-extern Entry *cache_find_entry_id();
extern char *entry2str();
extern pthread_mutex_t entry2str_mutex;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
struct dbcache *db;
Datum key, data;
- int len, rc;
+ int len, rc, flags;
+
+#ifdef HAVE_BERKELEY_DB2
+ memset( &key, 0, sizeof( key ) );
+ memset( &data, 0, sizeof( data ) );
+#endif
Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %d, \"%s\" )\n", e->e_id,
e->e_dn, 0 );
data.dptr = entry2str( e, &len, 1 );
data.dsize = len + 1;
- /* store it - LDBM_SYNC ensures id2entry is always consistent */
- rc = ldbm_cache_store( db, key, data, LDBM_REPLACE|LDBM_SYNC );
+ /* store it */
+ flags = LDBM_REPLACE;
+ if ( li->li_flush_wrt ) flags |= LDBM_SYNC;
+ rc = ldbm_cache_store( db, key, data, flags );
pthread_mutex_unlock( &entry2str_mutex );
(void) cache_add_entry_lock( &li->li_cache, e, 0 );
Debug( LDAP_DEBUG_TRACE, "<= id2entry_add %d\n", rc, 0, 0 );
+
+ /* XXX should entries be born locked, i.e. apply writer lock here? */
return( rc );
}
Debug( LDAP_DEBUG_TRACE, "=> id2entry_delete( %d, \"%s\" )\n", e->e_id,
e->e_dn, 0 );
+ /* XXX - check for writer lock - should also check no reader pending */
+#ifdef LDAP_DEBUG
+ assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#endif
+
+#ifdef HAVE_BERKELEY_DB2
+ memset( &key, 0, sizeof( key ) );
+#endif
+
+ /* XXX - check for writer lock - should also check no reader pending */
+ Debug (LDAP_DEBUG_TRACE,
+ "rdwr_Xchk: readers_reading: %d writer_writing: %d\n",
+ e->e_rdwr.readers_reading, e->e_rdwr.writer_writing, 0);
+
if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
- == NULL ) {
+ == NULL ) {
Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
LDBM_SUFFIX, 0, 0 );
return( -1 );
return( rc );
}
+/* XXX returns entry with reader/writer lock */
Entry *
-id2entry( Backend *be, ID id )
+id2entry( Backend *be, ID id, int rw )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
struct dbcache *db;
Datum key, data;
Entry *e;
- Debug( LDAP_DEBUG_TRACE, "=> id2entry( %ld )\n", id, 0, 0 );
+#ifdef HAVE_BERKELEY_DB2
+ memset( &key, 0, sizeof( key ) );
+ memset( &data, 0, sizeof( data ) );
+#endif
+
+ Debug( LDAP_DEBUG_TRACE, "=> id2entry_%s( %ld )\n",
+ rw ? "w" : "r", id, 0 );
- if ( (e = cache_find_entry_id( &li->li_cache, id )) != NULL ) {
- Debug( LDAP_DEBUG_TRACE, "<= id2entry 0x%x (cache)\n", e, 0,
- 0 );
+ if ( (e = cache_find_entry_id( &li->li_cache, id, rw )) != NULL ) {
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s 0x%x (cache)\n",
+ rw ? "w" : "r", e, 0 );
return( e );
}
if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
- == NULL ) {
+ == NULL ) {
Debug( LDAP_DEBUG_ANY, "Could not open id2entry%s\n",
LDBM_SUFFIX, 0, 0 );
return( NULL );
data = ldbm_cache_fetch( db, key );
if ( data.dptr == NULL ) {
- Debug( LDAP_DEBUG_TRACE, "<= id2entry( %ld ) not found\n", id,
- 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) not found\n",
+ rw ? "w" : "r", id, 0 );
ldbm_cache_close( be, db );
return( NULL );
}
- if ( (e = str2entry( data.dptr )) != NULL ) {
- e->e_id = id;
- (void) cache_add_entry_lock( &li->li_cache, e, 0 );
- }
+ e = str2entry( data.dptr );
ldbm_datum_free( db->dbc_db, data );
ldbm_cache_close( be, db );
- Debug( LDAP_DEBUG_TRACE, "<= id2entry( %ld ) 0x%x (disk)\n", id, e, 0 );
+ if ( e == NULL ) {
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (failed)\n",
+ rw ? "w" : "r", id, 0 );
+ return( NULL );
+ }
+
+ /* acquire required reader/writer lock */
+ if (entry_rdwr_lock(e, rw)) {
+ /* XXX set DELETE flag?? */
+ entry_free(e);
+ return(NULL);
+ }
+
+ e->e_id = id;
+ (void) cache_add_entry_lock( &li->li_cache, e, 0 );
+
+ Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (disk)\n",
+ rw ? "w" : "r", id, 0 );
return( e );
}
+
+Entry *
+id2entry_r( Backend *be, ID id )
+{
+ return( id2entry( be, id, 0 ) );
+}
+
+Entry *
+id2entry_2( Backend *be, ID id )
+{
+ return( id2entry( be, id, 1 ) );
+}
+
/* idl.c - ldap id list handling routines */
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
#include "slap.h"
#include "ldapconfig.h"
#include "back-ldbm.h"
Datum key
)
{
- Datum data, k2;
+ Datum data;
IDList *idl;
- IDList **tmp;
- char *kstr;
- int i, nids;
+
+#ifdef HAVE_BERKELEY_DB2
+ Datum k2;
+ memset( &k2, 0, sizeof( k2 ) );
+ memset( &data, 0, sizeof( data ) );
+#endif
/* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */
char *kstr;
int i, nids;
+#ifdef HAVE_BERKELEY_DB2
+ memset( &k2, 0, sizeof( k2 ) );
+ memset( &data, 0, sizeof( data ) );
+#endif
+
/* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch\n", 0, 0, 0 ); */
data = ldbm_cache_fetch( db, key );
kstr = (char *) ch_malloc( key.dsize + 20 );
nids = 0;
for ( i = 0; idl->b_ids[i] != NOID; i++ ) {
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr, idl->b_ids[i] );
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, idl->b_ids[i] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
IDList *idl
)
{
- int rc;
+ int rc, flags;
Datum data;
+ struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+
+#ifdef HAVE_BERKELEY_DB2
+ memset( &data, 0, sizeof( data ) );
+#endif
/* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
data.dptr = (char *) idl;
data.dsize = (2 + idl->b_nmax) * sizeof(ID);
+
+#ifdef LDBM_DEBUG
+ Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
+ rc, 0, 0, 0, 0 );
+#endif
- rc = ldbm_cache_store( db, key, data, LDBM_REPLACE );
+ flags = LDBM_REPLACE;
+ if( li->li_flush_wrt ) flags |= LDBM_SYNC;
+ rc = ldbm_cache_store( db, key, data, flags );
/* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
return( rc );
IDList **n2
)
{
- int i;
+ unsigned int i;
/* find where to split the block */
for ( i = 0; i < b->b_nids && id > b->b_ids[i]; i++ )
}
/* write block with new key */
- sprintf( bkey.dptr, "%c%s%d", CONT_PREFIX, hkey.dptr, b->b_ids[0] );
+ sprintf( bkey.dptr, "%c%s%ld", CONT_PREFIX, hkey.dptr, b->b_ids[0] );
bkey.dsize = strlen( bkey.dptr ) + 1;
if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
Debug( LDAP_DEBUG_ANY,
char *kstr;
Datum k2;
+#ifdef HAVE_BERKELEY_DB2
+ memset( &k2, 0, sizeof( k2 ) );
+#endif
+
if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
+#ifdef LDBM_DEBUG
+ Statslog( LDAP_DEBUG_STATS, "=> idl_insert_key(): no key yet\n",
+ 0, 0, 0, 0, 0 );
+#endif
+
idl = idl_alloc( 1 );
idl->b_ids[idl->b_nids++] = id;
rc = idl_store( be, db, key, idl );
/* store the first id block */
kstr = (char *) ch_malloc( key.dsize + 20 );
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr,
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
tmp->b_ids[0] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
rc = idl_store( be, db, k2, tmp );
/* store the second id block */
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr,
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
tmp2->b_ids[0] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
/* get the block */
kstr = (char *) ch_malloc( key.dsize + 20 );
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr, idl->b_ids[i] );
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, idl->b_ids[i] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
/* is there a next block? */
if ( !first && idl->b_ids[i + 1] != NOID ) {
/* read it in */
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr,
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
idl->b_ids[i + 1] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
/* delete all indirect blocks */
for ( j = 0; idl->b_ids[j] != NOID; j++ ) {
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr,
+ sprintf( kstr,"%c%s%ld", CONT_PREFIX, key.dptr,
idl->b_ids[j] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
rc = idl_store( be, db, key, tmp );
/* store the first id block */
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr,
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
tmp2->b_ids[0] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
rc = idl_store( be, db, k2, tmp2 );
/* store the second id block */
- sprintf( kstr, "%c%s%d", CONT_PREFIX, key.dptr,
+ sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
tmp3->b_ids[0] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
int
idl_insert( IDList **idl, ID id, int maxids )
{
- int i, j;
+ unsigned int i, j;
if ( ALLIDS( *idl ) ) {
return( 2 ); /* already there */
IDList *b
)
{
- int ai, bi, ni;
- IDList *n;
+ unsigned int ai, bi, ni;
+ IDList *n;
if ( a == NULL || b == NULL ) {
return( NULL );
IDList *b
)
{
- int ai, bi, ni;
- IDList *n;
+ unsigned int ai, bi, ni;
+ IDList *n;
if ( a == NULL ) {
return( idl_dup( b ) );
IDList *b
)
{
- int ni, ai, bi;
- IDList *n;
+ unsigned int ni, ai, bi;
+ IDList *n;
if ( a == NULL ) {
return( NULL );
}
- if ( b == NULL ) {
+ if ( b == NULL || ALLIDS( b )) {
return( idl_dup( a ) );
}
- if ( ALLIDS( b ) ) {
- return( NULL );
- }
if ( ALLIDS( a ) ) {
n = idl_alloc( SLAPD_LDBM_MIN_MAXIDS );
ID
idl_nextid( IDList *idl, ID id )
{
- int i;
+ unsigned int i;
if ( ALLIDS( idl ) ) {
return( ++id < idl->b_nids ? id : NOID );
/* index.c - routines for dealing with attribute indexes */
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
#include "slap.h"
#include "back-ldbm.h"
char *realval, *tmpval;
char buf[BUFSIZ];
+#ifdef HAVE_BERKELEY_DB2
+ memset( &key, 0, sizeof( key ) );
+#endif
+
prefix = index2prefix( indextype );
Debug( LDAP_DEBUG_TRACE, "=> index_read( \"%s\" \"%c\" \"%s\" )\n",
type, prefix, val );
realval = val;
tmpval = NULL;
if ( prefix != '\0' ) {
- int len;
+ unsigned int len = strlen( val );
- if ( (len = strlen( val )) < sizeof(buf) ) {
- buf[0] = prefix;
- strcpy( &buf[1], val );
+ if ( (len + 2) < sizeof(buf) ) {
realval = buf;
} else {
/* value + prefix + null */
tmpval = (char *) ch_malloc( len + 2 );
- tmpval[0] = prefix;
- strcat( &tmpval[1], val );
realval = tmpval;
}
+ realval[0] = prefix;
+ strcpy( &realval[1], val );
}
key.dptr = realval;
key.dsize = strlen( realval ) + 1;
idl = idl_fetch( be, db, key );
+ if ( tmpval != NULL ) {
+ free( tmpval );
+ }
ldbm_cache_close( be, db );
char *realval, *tmpval, *s;
char buf[BUFSIZ];
+#ifdef HAVE_BERKELEY_DB2
+ memset( &key, 0, sizeof( key ) );
+#endif
+
prefix = index2prefix( indextype );
Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 );
tmpval = NULL;
idl = NULL;
if ( prefix != '\0' ) {
- int len;
+ unsigned int len = strlen( val );
- if ( (len = strlen( val )) < sizeof(buf) ) {
- buf[0] = prefix;
- strcpy( &buf[1], val );
+ if ( (len + 2) < sizeof(buf) ) {
realval = buf;
} else {
/* value + prefix + null */
tmpval = (char *) ch_malloc( len + 2 );
- tmpval[0] = prefix;
- strcat( &tmpval[1], val );
realval = tmpval;
}
+ realval[0] = prefix;
+ strcpy( &realval[1], val );
}
key.dptr = realval;
/* modify.c - ldbm backend modify routine */
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
#include "slap.h"
#include "back-ldbm.h"
+#include "proto-back-ldbm.h"
extern int global_schemacheck;
-extern Entry *dn2entry();
extern Attribute *attr_find();
static int add_values();
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
char *matched = NULL;
Entry *e;
- int i, err, modtype;
+ int i, err;
LDAPMod *mod;
- if ( (e = dn2entry( be, dn, &matched )) == NULL ) {
+ Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
+
+ if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
NULL );
if ( matched != NULL ) {
}
return( -1 );
}
+
+ /* check for deleted */
+
/* lock entry */
if ( (err = acl_check_mods( be, conn, op, e, mods )) != LDAP_SUCCESS ) {
send_ldap_result( conn, op, err, NULL, NULL );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
+ goto error_return;
}
for ( mod = mods; mod != NULL; mod = mod->mod_next ) {
if ( err != LDAP_SUCCESS ) {
/* unlock entry, delete from cache */
send_ldap_result( conn, op, err, NULL, NULL );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
+ goto error_return;
}
}
+ /* check that the entry still obeys the schema */
+ if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
+ Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
+ send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL, NULL );
+ goto error_return;
+ }
+
/* check for abandon */
pthread_mutex_lock( &op->o_abandonmutex );
if ( op->o_abandon ) {
pthread_mutex_unlock( &op->o_abandonmutex );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
+ goto error_return;
}
pthread_mutex_unlock( &op->o_abandonmutex );
- /* check that the entry still obeys the schema */
- if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
- send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL,
- NULL );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
- }
-
/* modify indexes */
if ( index_add_mods( be, mods, e->e_id ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
+ goto error_return;
}
/* check for abandon */
pthread_mutex_lock( &op->o_abandonmutex );
if ( op->o_abandon ) {
pthread_mutex_unlock( &op->o_abandonmutex );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
+ goto error_return;
}
pthread_mutex_unlock( &op->o_abandonmutex );
/* change the entry itself */
if ( id2entry_add( be, e ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
- cache_return_entry( &li->li_cache, e );
- return( -1 );
+ goto error_return;
}
send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
- cache_return_entry( &li->li_cache, e );
-
+ cache_return_entry_w( &li->li_cache, e );
return( 0 );
+
+error_return:;
+ cache_return_entry_w( &li->li_cache, e );
+ return( -1 );
}
static int
/* entry.c - routines for dealing with entries */
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include "slap.h"
void entry_free();
* or newline.
*/
- Debug( LDAP_DEBUG_TRACE, "=> str2entry\n", s, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "=> str2entry\n",
+ s ? s : "NULL", 0, 0 );
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
+ /* initialize reader/writer lock */
+ entry_rdwr_init(e);
/* check to see if there's an id included */
next = s;
}
Debug( LDAP_DEBUG_TRACE, "<= str2entry 0x%x\n", e, 0, 0 );
+
return( e );
}
int i;
Attribute *a, *next;
+ /* XXX check that no reader/writer locks exist */
+#ifdef LDAP_DEBUG
+ assert( !pthread_rdwr_wchk_np(&e->e_rdwr) &&
+ !pthread_rdwr_rchk_np(&e->e_rdwr) );
+#endif
+
if ( e->e_dn != NULL ) {
free( e->e_dn );
}
}
free( e );
}
+
+int
+entry_rdwr_lock(Entry *e, int rw)
+{
+ Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%slock: ID: %ld\n",
+ rw ? "w" : "r", e->e_id, 0);
+ if (rw)
+ return pthread_rdwr_wlock_np(&e->e_rdwr);
+ else
+ return pthread_rdwr_rlock_np(&e->e_rdwr);
+}
+
+int
+entry_rdwr_rlock(Entry *e)
+{
+ return entry_rdwr_lock( e, 0 );
+}
+
+int
+entry_rdwr_wlock(Entry *e)
+{
+ return entry_rdwr_lock( e, 1 );
+}
+
+int
+entry_rdwr_unlock(Entry *e, int rw)
+{
+ Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%sunlock: ID: %ld\n",
+ rw ? "w" : "r", e->e_id, 0);
+ if (rw)
+ return pthread_rdwr_wunlock_np(&e->e_rdwr);
+ else
+ return pthread_rdwr_runlock_np(&e->e_rdwr);
+}
+
+int
+entry_rdwr_runlock(Entry *e)
+{
+ return entry_rdwr_unlock( e, 0 );
+}
+
+int
+entry_rdwr_wunlock(Entry *e)
+{
+ return entry_rdwr_unlock( e, 1 );
+}
+
+int
+entry_rdwr_init(Entry *e)
+{
+ return pthread_rdwr_init_np(&e->e_rdwr, NULL);
+}
+
#include "slap.h"
#include "ldapconfig.h"
+#include "lutil.h" /* Get lutil_detach() */
extern void slapd_daemon();
extern int lber_debug;
pthread_mutex_t entry2str_mutex;
pthread_mutex_t replog_mutex;
-static
+static void
usage( name )
char *name;
{
fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name );
}
+int
main( argc, argv )
int argc;
char **argv;
/* log and send error */
Debug( LDAP_DEBUG_ANY,
"ber_get_int returns 0x%x\n", tag, 0, 0 );
- return;
+ return 1;
}
if ( (tag = ber_peek_tag( &ber, &len ))
ber_free( &ber, 1 );
close( c.c_sb.sb_sd );
c.c_sb.sb_sd = -1;
- return;
+ return 1;
}
connection_activity( &c );
ber_free( &ber, 1 );
}
}
+ return 1;
}
--- /dev/null
+/*
+ * Copyright (c) 1998 Will Ballantyne, ITSD, Government of BC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to ITSD, Government of BC. The name of ITSD
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <ac/socket.h> /* Get struct sockaddr for slap.h */
+#include "slap.h"
+
+/*
+ * given a dn (or root part), return an aliased dn if any of the
+ * alias suffixes match
+ */
+char *suffixAlias ( dn, op, be )
+ char *dn;
+ Operation *op;
+ Backend *be;
+{
+ int i, dnLength;
+
+ dnLength = strlen ( dn );
+ op->o_suffix = NULL;
+ op->o_suffixAliased = NULL;
+ for ( i = 0;
+ be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
+ i += 2) {
+ int aliasLength = strlen (be->be_suffixAlias[i]);
+ if (aliasLength > dnLength) {
+ continue;
+ }
+
+ if (!strcasecmp(be->be_suffixAlias[i],
+ dn + (dnLength - aliasLength))) {
+ char *oldDN = dn;
+ op->o_suffixAliased = strdup ( be->be_suffixAlias[i] );
+ dn = ch_malloc ( (dnLength - aliasLength) +
+ strlen (be->be_suffixAlias[ i+1 ]) + 1);
+ strncpy (dn, oldDN, dnLength - aliasLength);
+ strcpy (dn + (dnLength - aliasLength), be->be_suffixAlias[ i+1 ]);
+ op->o_suffix = strdup (dn);
+ Debug( LDAP_DEBUG_ARGS, "ALIAS: converted %s to %s", oldDN, dn, 0);
+ free (oldDN);
+ break;
+ }
+ }
+ return dn;
+}
* args.c - process command-line arguments, and set appropriate globals.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
+
+#include <ac/string.h>
+#include <ac/time.h>
#include <lber.h>
#include <ldap.h>
#include "globals.h"
-static int
+static void
usage( char *name )
{
fprintf( stderr, "usage: %s\t[-d debug-level] [-s syslog-level]\n", name );
fprintf( stderr, "\t\t[-f slapd-config-file] [-r replication-log-file]\n" );
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
fprintf( stderr, "\t\t[-t tmp-dir] [-o] [-k srvtab-file]\n" );
-#else /* KERBEROS */
+#else /* HAVE_KERBEROS */
fprintf( stderr, "\t\t[-t tmp-dir] [-o]\n" );
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
}
g->slurpd_rdir = strdup( optarg );
break;
case 'k': /* name of kerberos srvtab file */
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
g->default_srvtab = strdup( optarg );
-#else /* KERBEROS */
+#else /* HAVE_KERBEROS */
fprintf( stderr, "must compile with KERBEROS to use -k option\n" );
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
break;
case 'h':
usage( g->myname );
* ch_malloc.c - malloc() and friends, with check for NULL return.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/socket.h>
+
#include "../slapd/slap.h"
char *new;
if ( (new = (char *) malloc( size )) == NULL ) {
- fprintf( stderr, "malloc of %d bytes failed\n", size );
+ fprintf( stderr, "malloc of %lu bytes failed\n", size );
exit( 1 );
}
}
if ( (new = (char *) realloc( block, size )) == NULL ) {
- fprintf( stderr, "realloc of %d bytes failed\n", size );
+ fprintf( stderr, "realloc of %lu bytes failed\n", size );
exit( 1 );
}
char *new;
if ( (new = (char *) calloc( nelem, size )) == NULL ) {
- fprintf( stderr, "calloc of %d elems of %d bytes failed\n",
+ fprintf( stderr, "calloc of %lu elems of %lu bytes failed\n",
nelem, size );
exit( 1 );
}
* config.c - configuration file handling routines
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/ctype.h>
#include <lber.h>
#include <ldap.h>
#define MAXARGS 100
/* Forward declarations */
-#ifdef NEEDPROTOS
-static void add_replica( char **, int );
-static int parse_replica_line( char **, int, Ri *);
-static void parse_line( char *, int *, char ** );
-static char *getline( FILE * );
-static char *strtok_quote( char *, char * );
-#else /* NEEDPROTOS */
-static void add_replica();
-static int parse_replica_line();
-static void parse_line();
-static char *getline();
-static char *strtok_quote();
-#endif /* NEEDPROTOS */
+static void add_replica LDAP_P(( char **, int ));
+static int parse_replica_line LDAP_P(( char **, int, Ri *));
+static void parse_line LDAP_P(( char *, int *, char ** ));
+static char *getline LDAP_P(( FILE * ));
+static char *strtok_quote LDAP_P(( char *, char * ));
/* current config file line # */
static int lineno;
)
{
FILE *fp;
- char buf[BUFSIZ];
- char *line, *p;
+ char *line;
int cargc;
char *cargv[MAXARGS];
*p = '\0';
}
lineno++;
- if ( ! isspace( buf[0] ) ) {
+ if ( ! isspace( (unsigned char) buf[0] ) ) {
return( line );
}
strlen( BINDMETHSTR ))) {
val = cargv[ i ] + strlen( BINDMETHSTR ) + 1;
if ( !strcasecmp( val, KERBEROSSTR )) {
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
ri->ri_bind_method = AUTH_KERBEROS;
if ( ri->ri_srvtab == NULL ) {
ri->ri_srvtab = strdup( sglob->default_srvtab );
}
gots |= GOT_METHOD;
-#else /* KERBEROS */
+#else /* HAVE_KERBEROS */
fprintf( stderr, "Error: a bind method of \"kerberos\" was\n" );
fprintf( stderr, "specified in the slapd configuration file,\n" );
fprintf( stderr, "but slurpd was not built with kerberos.\n" );
fprintf( stderr, "kerberos support if you wish to use\n" );
fprintf( stderr, "bindmethod=kerberos\n" );
exit( 1 );
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
} else if ( !strcasecmp( val, SIMPLESTR )) {
ri->ri_bind_method = AUTH_SIMPLE;
gots |= GOT_METHOD;
* ldap_op.c - routines to perform LDAP operations
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#ifdef KERBEROS
-#include <krb.h>
-#endif /* KERBEROS */
+#include <ac/errno.h>
+#include <ac/string.h>
+#include <ac/ctype.h>
+#include <ac/time.h>
+
+#include <ac/krb.h>
#include <lber.h>
#include <ldap.h>
-#include "portable.h"
#include "slurp.h"
/* Forward references */
-static int get_changetype( char * );
-static struct berval **make_singlevalued_berval( char *, int );
-static int op_ldap_add( Ri *, Re *, char ** );
-static int op_ldap_modify( Ri *, Re *, char ** );
-static int op_ldap_delete( Ri *, Re *, char ** );
-static int op_ldap_modrdn( Ri *, Re *, char ** );
-static LDAPMod *alloc_ldapmod();
-static void free_ldapmod( LDAPMod * );
-static void free_ldmarr( LDAPMod ** );
-static int getmodtype( char * );
-static void dump_ldm_array( LDAPMod ** );
-static char **read_krbnames( Ri * );
-static void upcase( char * );
-static int do_bind( Ri *, int * );
-static int do_unbind( Ri * );
+static struct berval **make_singlevalued_berval LDAP_P(( char *, int ));
+static int op_ldap_add LDAP_P(( Ri *, Re *, char ** ));
+static int op_ldap_modify LDAP_P(( Ri *, Re *, char ** ));
+static int op_ldap_delete LDAP_P(( Ri *, Re *, char ** ));
+static int op_ldap_modrdn LDAP_P(( Ri *, Re *, char ** ));
+static LDAPMod *alloc_ldapmod LDAP_P(());
+static void free_ldapmod LDAP_P(( LDAPMod * ));
+static void free_ldmarr LDAP_P(( LDAPMod ** ));
+static int getmodtype LDAP_P(( char * ));
+static void dump_ldm_array LDAP_P(( LDAPMod ** ));
+static char **read_krbnames LDAP_P(( Ri * ));
+static void upcase LDAP_P(( char * ));
+static int do_bind LDAP_P(( Ri *, int * ));
+static int do_unbind LDAP_P(( Ri * ));
/* External references */
-#ifndef SYSERRLIST_IN_STDIO
-extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO */
-
-extern char *ch_malloc( unsigned long );
+extern char *ch_malloc LDAP_P(( unsigned long ));
static char *kattrs[] = {"kerberosName", NULL };
static struct timeval kst = {30L, 0L};
int rc = 0;
int lderr = LDAP_SUCCESS;
int retry = 2;
- char *msg;
*errmsg = NULL;
int state; /* This code is a simple-minded state machine */
int nvals; /* Number of values we're modifying */
int nops; /* Number of LDAPMod structs in ldmarr */
- LDAPMod *ldm, *nldm, **ldmarr;
+ LDAPMod *ldm, **ldmarr;
int i, len;
char *type, *value;
int rc = 0;
int *lderr
)
{
- int rc;
int ldrc;
- char msgbuf[ 1024];
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
+ int rc;
int retval = 0;
int kni, got_tgt;
char **krbnames;
char realm[ REALM_SZ ];
char name[ ANAME_SZ ];
char instance[ INST_SZ ];
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
*lderr = 0;
switch ( ri->ri_bind_method ) {
case AUTH_KERBEROS:
-#ifndef KERBEROS
+#ifndef HAVE_KERBEROS
Debug( LDAP_DEBUG_ANY,
"Error: Kerberos bind for %s:%d, but not compiled w/kerberos\n",
ri->ri_hostname, ri->ri_port, 0 );
return( BIND_ERR_KERBEROS_FAILED );
-#else /* KERBEROS */
+#else /* HAVE_KERBEROS */
/*
* Bind using kerberos.
* If "bindprincipal" was given in the config file, then attempt
}
return( retval);
break;
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
case AUTH_SIMPLE:
/*
* Bind with a plaintext password.
if ( ldm->mod_bvalues != NULL ) {
for ( j = 0; ( b = ldm->mod_bvalues[ j ] ) != NULL; j++ ) {
msgbuf = ch_malloc( b->bv_len + 512 );
- sprintf( msgbuf, "***** bv[ %d ] len = %d, val = <%s>",
+ sprintf( msgbuf, "***** bv[ %d ] len = %ld, val = <%s>",
j, b->bv_len, b->bv_val );
Debug( LDAP_DEBUG_TRACE,
"Trace (%d):%s\n", getpid(), msgbuf, 0 );
char *p;
for ( p = s; ( p != NULL ) && ( *p != '\0' ); p++ ) {
- if ( islower( *p )) {
- *p = toupper( *p );
- }
+ *p = TOUPPER( (unsigned char) *p );
}
}
* lock.c - routines to open and apply an advisory lock to a file
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/time.h>
-#include <sys/types.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+
#include <sys/file.h>
#include <sys/param.h>
-#include <sys/socket.h>
-#include "portable.h"
-#ifdef USE_LOCKF
-#include <unistd.h>
-#endif
+
#include "../slapd/slap.h"
}
/* acquire the lock */
-#ifdef USE_LOCKF
- while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 ) {
+#ifdef HAVE_FLOCK
+ while ( flock( fileno( *lfp ), LOCK_EX ) != 0 )
#else
- while ( flock( fileno( *lfp ), LOCK_EX ) != 0 ) {
+ while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 )
#endif
+ {
; /* NULL */
}
if ( (fp = fopen( fname, type )) == NULL ) {
Debug( LDAP_DEBUG_ANY,
"Error: 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 );
}
)
{
/* unlock */
-#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
fclose( lfp );
extern void start_lwp_scheduler();
#endif /* HAVE_LWP */
+int
main(
int argc,
char **argv
)
{
- pthread_attr_t attr;
- int status;
- int i;
-
#ifdef NO_THREADS
/* Haven't yet written the non-threaded version */
- fprintf( stderr, "slurpd currently requires threads support\n" );
- exit( 1 );
+ fputs( "slurpd currently requires threads support\n", stderr );
+ return( 1 );
#else
+ pthread_attr_t attr;
+ int status;
+ int i;
+
/*
* Create and initialize globals. init_globals() also initializes
* the main replication queue.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/errno.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/ctype.h>
#include "../slapd/slap.h"
#include "slurp.h"
#include "globals.h"
/* externs */
-extern char *str_getline( char **next );
-extern void ch_free( char *p );
-
-extern char *sys_errlist[];
+extern char *str_getline LDAP_P(( char **next ));
+extern void ch_free LDAP_P(( char *p ));
/* Forward references */
-static Rh *get_repl_hosts( char *, int *, char ** );
-static int gettype( char * );
-static int getchangetype( char *);
-static int Re_parse( Re *re, char *replbuf );
-static void Re_dump( Re *re, FILE *fp );
-static void warn_unknown_replica( char *, int port );
+static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** ));
+static int gettype LDAP_P(( char * ));
+static int getchangetype LDAP_P(( char * ));
+static int Re_parse LDAP_P(( Re *re, char *replbuf ));
+static void Re_dump LDAP_P(( Re *re, FILE *fp ));
+static void warn_unknown_replica LDAP_P(( char *, int port ));
/* Globals, scoped within this file */
static int nur = 0; /* Number of unknown replicas */
"Warning: freeing re (dn: %s) with nonzero refcnt\n",
re->re_dn, 0, 0 );
}
-#if !defined( THREAD_SUNOS4_LWP )
+#if !defined( HAVE_LWP )
/* This seems to have problems under SunOS lwp */
pthread_mutex_destroy( &re->re_mutex );
-#endif /* THREAD_SUNOS4_LWP */
+#endif /* HAVE_LWP */
ch_free( re->re_timestamp );
if (( rh = re->re_replicas ) != NULL ) {
for ( i = 0; rh[ i ].rh_hostname != NULL; i++ ) {
*p++ = '\0';
}
re->re_timestamp = strdup( value );
- if ( p != NULL && isdigit( *p )) {
+ if ( p != NULL && isdigit( (unsigned char) *p )) {
re->re_seq = atoi( p );
}
state |= GOT_TIME;
break;
case T_DN:
- re->re_dn = strdup( value );
+ re->re_dn = ch_malloc( len + 1 );
+ memcpy( re->re_dn, value, len );
+ re->re_dn[ len ]='\0';
state |= GOT_DN;
break;
default:
sizeof( Mi ) * ( nml + 2 ));
re->re_mods[ nml ].mi_type = strdup( type );
if ( value != NULL ) {
- re->re_mods[ nml ].mi_val = strdup( value );
+ re->re_mods[ nml ].mi_val = ch_malloc( len + 1 );
+ memcpy( re->re_mods[ nml ].mi_val, value, len );
+ re->re_mods[ nml ].mi_val[ len ] = '\0';
re->re_mods[ nml ].mi_len = len;
} else {
re->re_mods[ nml ].mi_val = NULL;
int i;
char *s;
int rc = 0;
- Rh *rh;
if ( re == NULL || fp == NULL ) {
Debug( LDAP_DEBUG_ANY, "Internal error: Re_write: NULL argument\n",
* replica.c - code to start up replica threads.
*/
+#include "portable.h"
#include <stdio.h>
Ri *ri
)
{
- int i;
- unsigned long seq;
-
Debug( LDAP_DEBUG_ARGS, "begin replication thread for %s:%d\n",
ri->ri_hostname, ri->ri_port, 0 );
pthread_attr_t attr;
pthread_attr_init( &attr );
+#ifdef NOTDEF
+ /* if main wants to join with us, we shouldn't detach */
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
+#endif
- if ( pthread_create( &(ri->ri_tid), attr, (void *) replicate,
+#if !defined(HAVE_PTHREAD_D4) && !defined(HAVE_DCE)
+ /* POSIX_THREADS or compatible
+ * This is a draft 10 or standard pthreads implementation
+ */
+ if ( pthread_create( &(ri->ri_tid), &attr, replicate,
+ (void *) ri ) != 0 ) {
+ Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n",
+ ri->ri_hostname, ri->ri_port, 0 );
+ pthread_attr_destroy( &attr );
+ return -1;
+ }
+#else /* !final */
+ /*
+ * This is a draft 4 or earlier pthreads implementation
+ */
+ if ( pthread_create( &(ri->ri_tid), attr, replicate,
(void *) ri ) != 0 ) {
Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n",
ri->ri_hostname, ri->ri_port, 0 );
pthread_attr_destroy( &attr );
return -1;
}
+#endif /* !final */
+
pthread_attr_destroy( &attr );
return 0;
}
*/
+#include "portable.h"
#include <stdio.h>
-#include <signal.h>
+#include <ac/signal.h>
#include "slurp.h"
#include "globals.h"
/* External references */
-#ifdef NEEDPROTOS
-extern void write_reject( Ri *, Re *, int, char * );
-extern void do_nothing();
-#else /* NEEDPROTOS */
-extern void write_reject();
-extern void do_nothing();
-#endif /* NEEDPROTOS */
+extern void write_reject LDAP_P(( Ri *, Re *, int, char * ));
+extern void do_nothing LDAP_P(());
/* Forward references */
-#ifdef NEEDPROTOS
-static int ismine( Ri *, Re * );
-static int isnew( Ri *, Re * );
-void tsleep( time_t );
-#else /* NEEDPROTOS */
-static int ismine();
-static int isnew();
-void tsleep();
-#endif /* NEEDPROTOS */
+static int ismine LDAP_P(( Ri *, Re * ));
+static int isnew LDAP_P(( Ri *, Re * ));
+void tsleep LDAP_P(( time_t ));
/*
{
Rq *rq = sglob->rq;
Re *re, *new_re;
- int i;
int rc ;
char *errmsg;
- (void) SIGNAL( SIGUSR1, (void *) do_nothing );
+#ifdef HAVE_LINUX_THREADS
+ (void) SIGNAL( SIGSTKFLT, do_nothing );
+#else
+ (void) SIGNAL( SIGUSR1, do_nothing );
+#endif
(void) SIGNAL( SIGPIPE, SIG_IGN );
if ( ri == NULL ) {
Debug( LDAP_DEBUG_ANY, "Error: Ri_process: ri == NULL!\n", 0, 0, 0 );
/*
- * Wake a replication thread which may be sleeping. Send it a SIGUSR1.
+ * Wake a replication thread which may be sleeping.
+ * Send it a SIG(STKFLT|USR1).
*/
static void
Ri_wake(
if ( ri == NULL ) {
return;
}
+#ifdef HAVE_LINUX_THREADS
+ pthread_kill( ri->ri_tid, SIGSTKFLT );
+ (void) SIGNAL( SIGSTKFLT, do_nothing );
+#else
pthread_kill( ri->ri_tid, SIGUSR1 );
- (void) SIGNAL( SIGUSR1, (void *) do_nothing );
+ (void) SIGNAL( SIGUSR1, do_nothing );
+#endif
}