Commit 6949ab31 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Use ldap_cdefs.h more. Use bridge.h less.

parent 84864e55
......@@ -9,6 +9,7 @@ install-local: FORCE
-$(MKDIR) -p $(includedir)
$(INSTALL) $(INSTALLFLAGS) -m 644 ldap.h $(includedir)
$(INSTALL) $(INSTALLFLAGS) -m 644 lber.h $(includedir)
$(INSTALL) $(INSTALLFLAGS) -m 644 ldap_cdefs.h $(includedir)
$(INSTALL) $(INSTALLFLAGS) -m 644 proto-lber.h $(includedir)
$(INSTALL) $(INSTALLFLAGS) -m 644 proto-ldap.h $(includedir)
$(INSTALL) $(INSTALLFLAGS) -m 644 disptmpl.h $(includedir)
......
......@@ -12,8 +12,8 @@
/* This file SHOULD go away !!! */
#ifndef LDAP_BRIDGE
#define LDAP_BRIDGE
#ifndef _LDAP_BRIDGE_H
#define _LDAP_BRIDGE_H
/*
* portable.h for LDAP -- this is where we define common stuff to make
......@@ -122,6 +122,7 @@
#endif
#endif NOTDEF
#ifndef DISABLE_BRIDGE
/*
* Are sys_errlist and sys_nerr declared in stdio.h?
*/
......@@ -142,6 +143,7 @@
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
#endif /* FD_SET */
#endif
#if defined( hpux ) && defined( __STDC__ )
/*
......@@ -209,4 +211,4 @@
extern char *strdup();
#endif /* ultrix || nextstep */
#endif /* LDAP_BRIDGE */
#endif /* _LDAP_BRIDGE_H */
......@@ -16,10 +16,9 @@
#ifndef _DISPTMPL_H
#define _DISPTMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ldap_cdefs.h>
LDAP_BEGIN_DECL
#define LDAP_TEMPLATE_VERSION 1
......@@ -221,110 +220,95 @@ struct ldap_disptmpl {
#define LDAP_DTMPL_BUFSIZ 8192
#ifndef NEEDPROTOS
typedef int (*writeptype) LDAP_P(( void *writeparm, char *p, int len ));
typedef int (*writeptype)();
LDAP_F int
ldap_init_templates LDAP_P(( char *file, struct ldap_disptmpl **tmpllistp ));
int ldap_init_templates();
int ldap_init_templates_buf();
void ldap_free_templates();
struct ldap_disptmpl *ldap_first_disptmpl();
struct ldap_disptmpl *ldap_next_disptmpl();
struct ldap_disptmpl *ldap_name2template();
struct ldap_disptmpl *ldap_oc2template();
char **ldap_tmplattrs();
struct ldap_tmplitem *ldap_first_tmplrow();
struct ldap_tmplitem *ldap_next_tmplrow();
struct ldap_tmplitem *ldap_first_tmplcol();
struct ldap_tmplitem *ldap_next_tmplcol();
int ldap_entry2text_search();
int ldap_entry2text();
int ldap_vals2text();
int ldap_entry2html_search();
int ldap_entry2html();
int ldap_vals2html();
LDAP_F int
ldap_init_templates_buf LDAP_P(( char *buf,
long buflen,
struct ldap_disptmpl **tmpllistp ));
#else /* !NEEDPROTOS */
LDAP_F void
ldap_free_templates LDAP_P(( struct ldap_disptmpl *tmpllist ));
typedef int (*writeptype)( void *writeparm, char *p, int len );
LDAP_F struct ldap_disptmpl *
ldap_first_disptmpl LDAP_P(( struct ldap_disptmpl *tmpllist ));
LDAPFUNCDECL int
ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp );
LDAP_F struct ldap_disptmpl *
ldap_next_disptmpl LDAP_P(( struct ldap_disptmpl *tmpllist,
struct ldap_disptmpl *tmpl ));
LDAPFUNCDECL int
ldap_init_templates_buf( char *buf, long buflen,
struct ldap_disptmpl **tmpllistp );
LDAP_F struct ldap_disptmpl *
ldap_name2template LDAP_P(( char *name,
struct ldap_disptmpl *tmpllist ));
LDAPFUNCDECL void
ldap_free_templates( struct ldap_disptmpl *tmpllist );
LDAP_F struct ldap_disptmpl *
ldap_oc2template LDAP_P(( char **oclist,
struct ldap_disptmpl *tmpllist ));
LDAPFUNCDECL struct ldap_disptmpl *
ldap_first_disptmpl( struct ldap_disptmpl *tmpllist );
LDAP_F char **
ldap_tmplattrs LDAP_P(( struct ldap_disptmpl *tmpl,
char **includeattrs,
int exclude,
unsigned long syntaxmask ));
LDAPFUNCDECL struct ldap_disptmpl *
ldap_next_disptmpl( struct ldap_disptmpl *tmpllist,
struct ldap_disptmpl *tmpl );
LDAP_F struct ldap_tmplitem *
ldap_first_tmplrow LDAP_P(( struct ldap_disptmpl *tmpl ));
LDAPFUNCDECL struct ldap_disptmpl *
ldap_name2template( char *name, struct ldap_disptmpl *tmpllist );
LDAP_F struct ldap_tmplitem *
ldap_next_tmplrow LDAP_P(( struct ldap_disptmpl *tmpl,
struct ldap_tmplitem *row ));
LDAPFUNCDECL struct ldap_disptmpl *
ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist );
LDAP_F struct ldap_tmplitem *
ldap_first_tmplcol LDAP_P(( struct ldap_disptmpl *tmpl,
struct ldap_tmplitem *row ));
LDAPFUNCDECL char **
ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, int exclude,
unsigned long syntaxmask );
LDAP_F struct ldap_tmplitem *
ldap_next_tmplcol LDAP_P(( struct ldap_disptmpl *tmpl,
struct ldap_tmplitem *row,
struct ldap_tmplitem *col ));
LDAPFUNCDECL struct ldap_tmplitem *
ldap_first_tmplrow( struct ldap_disptmpl *tmpl );
LDAPFUNCDECL struct ldap_tmplitem *
ldap_next_tmplrow( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row );
LDAPFUNCDECL struct ldap_tmplitem *
ldap_first_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row );
LDAPFUNCDECL struct ldap_tmplitem *
ldap_next_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row,
struct ldap_tmplitem *col );
LDAPFUNCDECL int
ldap_entry2text( LDAP *ld, char *buf, LDAPMessage *entry,
LDAP_F int
ldap_entry2text LDAP_P(( LDAP *ld,
char *buf, LDAPMessage *entry,
struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals,
writeptype writeproc, void *writeparm, char *eol, int rdncount,
unsigned long opts );
unsigned long opts ));
LDAPFUNCDECL int
ldap_vals2text( LDAP *ld, char *buf, char **vals, char *label, int labelwidth,
LDAP_F int
ldap_vals2text LDAP_P(( LDAP *ld,
char *buf, char **vals, char *label, int labelwidth,
unsigned long syntaxid, writeptype writeproc, void *writeparm,
char *eol, int rdncount );
char *eol, int rdncount ));
LDAPFUNCDECL int
ldap_entry2text_search( LDAP *ld, char *dn, char *base, LDAPMessage *entry,
LDAP_F int
ldap_entry2text_search LDAP_P(( LDAP *ld,
char *dn, char *base, LDAPMessage *entry,
struct ldap_disptmpl *tmpllist, char **defattrs, char ***defvals,
writeptype writeproc, void *writeparm, char *eol, int rdncount,
unsigned long opts );
unsigned long opts ));
LDAPFUNCDECL int
ldap_entry2html( LDAP *ld, char *buf, LDAPMessage *entry,
LDAP_F int
ldap_entry2html LDAP_P(( LDAP *ld,
char *buf, LDAPMessage *entry,
struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals,
writeptype writeproc, void *writeparm, char *eol, int rdncount,
unsigned long opts, char *urlprefix, char *base );
unsigned long opts, char *urlprefix, char *base ));
LDAPFUNCDECL int
ldap_vals2html( LDAP *ld, char *buf, char **vals, char *label, int labelwidth,
LDAP_F int
ldap_vals2html LDAP_P(( LDAP *ld,
char *buf, char **vals, char *label, int labelwidth,
unsigned long syntaxid, writeptype writeproc, void *writeparm,
char *eol, int rdncount, char *urlprefix );
char *eol, int rdncount, char *urlprefix ));
LDAPFUNCDECL int
ldap_entry2html_search( LDAP *ld, char *dn, char *base, LDAPMessage *entry,
LDAP_F int
ldap_entry2html_search LDAP_P(( LDAP
*ld, char *dn, char *base, LDAPMessage *entry,
struct ldap_disptmpl *tmpllist, char **defattrs, char ***defvals,
writeptype writeproc, void *writeparm, char *eol, int rdncount,
unsigned long opts, char *urlprefix );
#endif /* !NEEDPROTOS */
unsigned long opts, char *urlprefix ));
#ifdef __cplusplus
}
#endif
LDAP_END_DECL
#endif /* _DISPTMPL_H */
......@@ -17,10 +17,9 @@
#ifndef _SRCHPREF_H
#define _SRCHPREF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ldap_cdefs.h>
LDAP_BEGIN_DECL
struct ldap_searchattr {
char *sa_attrlabel;
......@@ -60,7 +59,7 @@ struct ldap_searchobj {
#define LDAP_SEARCHOBJ_OPT_INTERNAL 0x00000001
#define LDAP_IS_SEARCHOBJ_OPTION_SET( so, option ) \
(((so)->so_options & option ) != 0 )
(((so)->so_options & (option) ) != 0 )
#define LDAP_SEARCHPREF_VERSION_ZERO 0
#define LDAP_SEARCHPREF_VERSION 1
......@@ -71,36 +70,26 @@ struct ldap_searchobj {
#define LDAP_SEARCHPREF_ERR_FILE 4
#ifndef NEEDPROTOS
int ldap_init_searchprefs();
int ldap_init_searchprefs_buf();
void ldap_free_searchprefs();
struct ldap_searchobj *ldap_first_searchobj();
struct ldap_searchobj *ldap_next_searchobj();
LDAP_F int
ldap_init_searchprefs LDAP_P(( char *file,
struct ldap_searchobj **solistp ));
#else /* !NEEDPROTOS */
LDAP_F int
ldap_init_searchprefs_buf LDAP_P(( char *buf,
long buflen,
struct ldap_searchobj **solistp ));
LDAPFUNCDECL int
ldap_init_searchprefs( char *file, struct ldap_searchobj **solistp );
LDAP_F void
ldap_free_searchprefs LDAP_P(( struct ldap_searchobj *solist ));
LDAPFUNCDECL int
ldap_init_searchprefs_buf( char *buf, long buflen,
struct ldap_searchobj **solistp );
LDAP_F struct ldap_searchobj *
ldap_first_searchobj LDAP_P(( struct ldap_searchobj *solist ));
LDAPFUNCDECL void
ldap_free_searchprefs( struct ldap_searchobj *solist );
LDAP_F struct ldap_searchobj *
ldap_next_searchobj LDAP_P(( struct ldap_searchobj *sollist,
struct ldap_searchobj *so ));
LDAPFUNCDECL struct ldap_searchobj *
ldap_first_searchobj( struct ldap_searchobj *solist );
LDAPFUNCDECL struct ldap_searchobj *
ldap_next_searchobj( struct ldap_searchobj *sollist,
struct ldap_searchobj *so );
LDAP_END_DECL
#endif /* !NEEDPROTOS */
#ifdef __cplusplus
}
#endif
#endif /* _SRCHPREF_H */
......@@ -11,7 +11,7 @@
* is provided ``as is'' without express or implied warranty.
*/
#define LDAP_BRIDGE /* disable LDAP_BRIDGE code */
#define DISABLE_BRIDGE /* disable LDAP_BRIDGE code */
#include "portable.h"
#include <stdio.h>
......
......@@ -15,9 +15,8 @@
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#define SHA1HANDSOFF /* Copies data before messing with it. */
#define LDAP_BRIDGE
#define DISABLE_BRIDGE
#include "portable.h"
#include <sys/param.h>
......@@ -25,6 +24,7 @@
#include "lutil_sha1.h"
#define SHA1HANDSOFF /* Copies data before messing with it. */
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/*
......
/* ldbmcache.c - maintain a cache of open ldbm files */
#define DISABLE_BRIDGE /* disable LDAP_BRIDGE code */
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <ac/string.h>
#include <ac/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
#include "portable.h"
#include "slap.h"
#include "ldapconfig.h"
#include "back-ldbm.h"
#include "ldapconfig.h"
#ifndef SYSERRLIST_IN_STDIO
#ifndef DECL_SYS_ERRLIST
extern int sys_nerr;
extern char *sys_errlist[];
#endif
extern time_t currenttime;
extern pthread_mutex_t currenttime_mutex;
......@@ -176,6 +181,9 @@ ldbm_cache_fetch(
)
{
Datum data;
#ifdef LDBM_USE_DB2
memset( &data, 0, sizeof( data ) );
#endif
pthread_mutex_lock( &db->dbc_mutex );
#ifdef reentrant_database
......@@ -216,6 +224,24 @@ ldbm_cache_store(
}
#endif
#ifdef LDBM_DEBUG
Statslog( LDAP_DEBUG_STATS,
"=> ldbm_cache_store(): key.dptr=%s, key.dsize=%d\n",
key.dptr, key.dsize, 0, 0, 0 );
Statslog( LDAP_DEBUG_STATS,
"=> ldbm_cache_store(): key.dptr=0x%08x, data.dptr=0x%0 8x\n",
key.dptr, data.dptr, 0, 0, 0 );
Statslog( LDAP_DEBUG_STATS,
"=> ldbm_cache_store(): data.dptr=%s, data.dsize=%d\n",
data.dptr, data.dsize, 0, 0, 0 );
Statslog( LDAP_DEBUG_STATS,
"=> ldbm_cache_store(): flags=0x%08x\n",
flags, 0, 0, 0, 0 );
#endif /* LDBM_DEBUG */
rc = ldbm_store( db->dbc_db, key, data, flags );
pthread_mutex_unlock( &db->dbc_mutex );
......
#define DISABLE_BRIDGE
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <ac/string.h>
#include <ac/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <signal.h>
#include "portable.h"
#include "slap.h"
extern Operation *op_add();
......@@ -16,7 +18,8 @@ extern long ops_initiated;
extern long ops_completed;
extern pthread_mutex_t ops_mutex;
extern pthread_t listener_tid;
#ifndef SYSERRLIST_IN_STDIO
#ifndef DECL_SYS_ERRLIST
extern int sys_nerr;
extern char *sys_errlist[];
#endif
......@@ -203,6 +206,22 @@ connection_activity(
pthread_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
#ifndef THREAD_MIT_PTHREADS
/* POSIX_THREADS or compatible
* This is a draft 10 or standard pthreads implementation
*/
if ( pthread_create( &arg->co_op->o_tid, &attr,
(void *) connection_operation, (void *) arg ) != 0 ) {
Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
} else {
pthread_mutex_lock( &active_threads_mutex );
active_threads++;
pthread_mutex_unlock( &active_threads_mutex );
}
#else /* !THREAD_MIT_PTHREAD */
/*
* This is a draft 4 or earlier pthreads implementation
*/
if ( pthread_create( &arg->co_op->o_tid, attr,
(void *) connection_operation, (void *) arg ) != 0 ) {
Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
......@@ -211,5 +230,6 @@ connection_activity(
active_threads++;
pthread_mutex_unlock( &active_threads_mutex );
}
#endif /* !THREAD_MIT_PTHREAD */
pthread_attr_destroy( &attr );
}
/* Revision history
*
* 5-Jun-96 hodges
* Added locking of new_conn_mutex when traversing the c[] array.
*/
#define DISABLE_BRIDGE /* disable bridge code */
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <ac/string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <sys/time.h>
#include <ac/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
......@@ -12,7 +22,6 @@
#include <sys/select.h>
#endif
#include "slap.h"
#include "portable.h"
#include "ldapconfig.h"
#ifdef NEED_FILIO
#include <sys/filio.h>
......@@ -23,12 +32,20 @@
#include <unistd.h>
#endif /* USE_SYSCONF */
#ifdef TCP_WRAPPERS
#include <tcpd.h>
int allow_severity = LOG_INFO;
int deny_severity = LOG_NOTICE;
#endif /* TCP_WRAPPERS */
extern Operation *op_add();
#ifndef SYSERRLIST_IN_STDIO
#ifndef DECL_SYS_ERRLIST
extern int sys_nerr;
extern char *sys_errlist[];
#endif
extern time_t currenttime;
extern pthread_mutex_t currenttime_mutex;
extern int active_threads;
......@@ -48,7 +65,7 @@ static void set_shutdown();
static void do_nothing();
void
daemon(
slapd_daemon(
int port
)
{
......@@ -64,10 +81,18 @@ daemon(
int on = 1;
#ifdef USE_SYSCONF
dtblsize = sysconf( _SC_OPEN_MAX );
dtblsize = sysconf( _SC_OPEN_MAX );
#else /* USE_SYSCONF */
dtblsize = getdtablesize();
dtblsize = getdtablesize();
#endif /* USE_SYSCONF */
/*
* Add greg@greg.rim.or.jp
*/
#ifdef FD_SETSIZE
if(dtblsize > FD_SETSIZE) {
dtblsize = FD_SETSIZE;
}
#endif /* !FD_SETSIZE */
c = (Connection *) ch_calloc( 1, dtblsize * sizeof(Connection) );
......@@ -127,9 +152,19 @@ daemon(
}
(void) SIGNAL( SIGPIPE, SIG_IGN );
#ifdef linux
/*
* LinuxThreads are implemented using SIGUSR1/USR2,
* so we'll use SIGSTKFLT and SIGUNUSED
*/
(void) SIGNAL( SIGSTKFLT, (void *) do_nothing );
(void) SIGNAL( SIGUNUSED, (void *) set_shutdown );
#else /* !linux */
(void) SIGNAL( SIGUSR1, (void *) do_nothing );
(void) SIGNAL( SIGUSR2, (void *) set_shutdown );
#endif /* !linux */
(void) SIGNAL( SIGTERM, (void *) set_shutdown );
(void) SIGNAL( SIGINT, (void *) set_shutdown );
(void) SIGNAL( SIGHUP, (void *) set_shutdown );
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
......@@ -156,6 +191,9 @@ daemon(
struct timeval *tvp;
int len, pid;
char *client_name;
char *client_addr;
FD_ZERO( &writefds );
FD_ZERO( &readfds );
FD_SET( tcps, &readfds );
......@@ -164,6 +202,8 @@ daemon(
Debug( LDAP_DEBUG_CONNS,
"listening for connections on %d, activity on:",
tcps, 0, 0 );
pthread_mutex_lock( &new_conn_mutex );
for ( i = 0; i < dtblsize; i++ ) {
if ( c[i].c_sb.sb_sd != -1 ) {
FD_SET( c[i].c_sb.sb_sd, &readfds );
......@@ -176,19 +216,20 @@ daemon(
}
}
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
pthread_mutex_unlock( &new_conn_mutex );
zero.tv_sec = 0;
zero.tv_usec = 0;
Debug( LDAP_DEBUG_CONNS, "before select active_threads %d\n",
active_threads, 0, 0 );
#ifdef PTHREAD_PREEMPTIVE
#if defined(PTHREAD_PREEMPTIVE) || defined(NO_THREADS)
tvp = NULL;
#else
tvp = active_threads ? &zero : NULL;
#endif
pthread_mutex_unlock( &active_threads_mutex );
switch ( select( dtblsize, &readfds, &writefds, 0, tvp ) ) {
switch ( i = select( dtblsize, &readfds, &writefds, 0, tvp ) ) {
case -1: /* failure - try again */
Debug( LDAP_DEBUG_CONNS,
"select failed errno %d (%s)\n",
......@@ -203,7 +244,7 @@ daemon(
continue;
default: /* something happened - deal with it */
Debug( LDAP_DEBUG_CONNS, "select activity\n", 0, 0, 0 );
Debug( LDAP_DEBUG_CONNS, "select activity on %d descriptors\n", i, 0, 0 );
; /* FALL */
}
pthread_mutex_lock( &currenttime_mutex );
......@@ -225,8 +266,9 @@ daemon(
}
if ( ioctl( ns, FIONBIO, (caddr_t) &on ) == -1 ) {
Debug( LDAP_DEBUG_ANY,
"FIONBIO ioctl on %d faled\n", ns, 0, 0 );
"FIONBIO ioctl on %d failed\n", ns, 0, 0 );
}
c[ns].c_sb.sb_sd = ns;
Debug( LDAP_DEBUG_CONNS, "new connection on %d\n", ns,
0, 0 );
......@@ -234,43 +276,76 @@ daemon(
pthread_mutex_lock( &ops_mutex );
c[ns].c_connid = num_conns++;
pthread_mutex_unlock( &ops_mutex );
len = sizeof(from);
if ( getpeername( ns, (struct sockaddr *) &from, &len )
== 0 ) {
char *s;
#ifdef REVERSE_LOOKUP
char *s;
client_addr = inet_ntoa( from.sin_addr );
#if defined(REVERSE_LOOKUP) || defined(TCP_WRAPPERS)
hp = gethostbyaddr( (char *)