-$(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)
/* 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
#endif
#endif NOTDEF
+#ifndef DISABLE_BRIDGE
/*
* Are sys_errlist and sys_nerr declared in stdio.h?
*/
#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__ )
/*
extern char *strdup();
#endif /* ultrix || nextstep */
-#endif /* LDAP_BRIDGE */
+#endif /* _LDAP_BRIDGE_H */
#ifndef _DISPTMPL_H
#define _DISPTMPL_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <ldap_cdefs.h>
+LDAP_BEGIN_DECL
#define LDAP_TEMPLATE_VERSION 1
#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 */
#ifndef _SRCHPREF_H
#define _SRCHPREF_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <ldap_cdefs.h>
+LDAP_BEGIN_DECL
struct ldap_searchattr {
char *sa_attrlabel;
#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
#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 */
* 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>
* 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>
#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;
)
{
Datum data;
+#ifdef LDBM_USE_DB2
+ memset( &data, 0, sizeof( data ) );
+#endif
pthread_mutex_lock( &db->dbc_mutex );
#ifdef reentrant_database
}
#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();
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
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 );
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>
#include <sys/select.h>
#endif
#include "slap.h"
-#include "portable.h"
#include "ldapconfig.h"
#ifdef NEED_FILIO
#include <sys/filio.h>
#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;
static void do_nothing();
void
-daemon(
+slapd_daemon(
int port
)
{
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) );
}
(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 );
struct timeval *tvp;
int len, pid;
+ char *client_name;
+ char *client_addr;
+
FD_ZERO( &writefds );
FD_ZERO( &readfds );
FD_SET( tcps, &readfds );
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 );
}
}
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",
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( ¤ttime_mutex );
}
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 );
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 *)
&(from.sin_addr.s_addr),
sizeof(from.sin_addr.s_addr), AF_INET );
-#else
- hp = NULL;
-#endif
- Statslog( LDAP_DEBUG_STATS,
- "conn=%d fd=%d connection from %s (%s)\n",
- c[ns].c_connid, ns, hp == NULL ? "unknown"
- : hp->h_name, inet_ntoa( from.sin_addr ),
- 0 );
+ if(hp) {
+ client_name = hp->h_name;
- if ( c[ns].c_addr != NULL ) {
- free( c[ns].c_addr );
- }
- c[ns].c_addr = strdup( inet_ntoa(
- from.sin_addr ) );
- if ( c[ns].c_domain != NULL ) {
- free( c[ns].c_domain );
- }
- c[ns].c_domain = strdup( hp == NULL ? "" :
- hp->h_name );
- /* normalize the domain */
- for ( s = c[ns].c_domain; *s; s++ ) {
- *s = TOLOWER( *s );
+ /* normalize the domain */
+ for ( s = client_name; *s; s++ ) {
+ *s = TOLOWER( *s );
+ }
+
+ } else {
+ client_name = NULL;
}
+#else
+ client_name = NULL;
+#endif
+
} else {
+ client_name = NULL;;
+ client_addr = NULL;
+ }
+
+#ifdef TCP_WRAPPERS
+ if(!hosts_ctl("slapd", client_name, client_addr,
+ STRING_UNKNOWN))
+ {
+ /* DENY ACCESS */
Statslog( LDAP_DEBUG_STATS,
- "conn=%d fd=%d connection from unknown\n",
- c[ns].c_connid, ns, 0, 0, 0 );
+ "conn=%d fd=%d connection from %s (%s) denied.\n",
+ c[ns].c_connid, ns,
+ client_name == NULL ? "unknown" : client_name,
+ client_addr == NULL ? "unknown" : client_addr,
+ 0 );
+
+ close(ns);
+ pthread_mutex_unlock( &new_conn_mutex );
+ continue;
+ }
+#endif /* TCP_WRAPPERS */
+
+ Statslog( LDAP_DEBUG_STATS,
+ "conn=%d fd=%d connection from %s (%s) accepted.\n",
+ c[ns].c_connid, ns,
+ client_name == NULL ? "unknown" : client_name,
+ client_addr == NULL ? "unknown" : client_addr,
+ 0 );
+
+ if ( c[ns].c_addr != NULL ) {
+ free( c[ns].c_addr );
}
+ c[ns].c_addr = strdup( client_addr );
+
+ if ( c[ns].c_domain != NULL ) {
+ free( c[ns].c_domain );
+ }
+
+ c[ns].c_domain = strdup( client_name == NULL
+ ? "" : client_name );
+
pthread_mutex_lock( &c[ns].c_dnmutex );
if ( c[ns].c_dn != NULL ) {
free( c[ns].c_dn );
{
Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal\n", 0, 0, 0 );
slapd_shutdown = 1;
+#ifdef linux
+ /*
+ * LinuxThreads are implemented using SIGUSR1/USR2,
+ * so we'll use SIGSTKFLT and SIGUNUSED
+ */
+ pthread_kill( listener_tid, SIGSTKFLT );
+ (void) SIGNAL( SIGUNUSED, (void *) set_shutdown );
+#else /* !linux */
pthread_kill( listener_tid, SIGUSR1 );
(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 );
}
static void
do_nothing()
{
- Debug( LDAP_DEBUG_TRACE, "slapd got SIGUSR1\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal\n", 0, 0, 0 );
+#ifdef linux
+ /*
+ * LinuxThreads are implemented using SIGUSR1/USR2,
+ * so we'll use SIGSTKFLT and SIGUNUSED
+ */
+ (void) SIGNAL( SIGSTKFLT, (void *) do_nothing );
+#else /* !linux */
(void) SIGNAL( SIGUSR1, (void *) do_nothing );
+#endif /* !linux */
}
/* result.c - routines to send ldap results, errors, and referrals */
+#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 <netinet/in.h>
#include <errno.h>
#include <signal.h>
-#include "portable.h"
#include "slap.h"
-#ifndef SYSERRLIST_IN_STDIO
+#ifndef DECL_SYS_ERRLIST
extern int sys_nerr;
extern char *sys_errlist[];
#endif
+
extern int active_threads;
extern pthread_mutex_t active_threads_mutex;
extern pthread_mutex_t new_conn_mutex;
pthread_mutex_lock( &active_threads_mutex );
active_threads--;
conn->c_writewaiter = 1;
+
+#ifdef linux
+ pthread_kill( listener_tid, SIGSTKFLT );
+#else /* !linux */
pthread_kill( listener_tid, SIGUSR1 );
+#endif /* !linux */
+
pthread_cond_wait( &conn->c_wcv, &active_threads_mutex );
pthread_mutex_unlock( &active_threads_mutex );
Attribute *a;
int i, rc, bytes, sd;
struct acl *acl;
+ char *edn;
Debug( LDAP_DEBUG_TRACE, "=> send_search_entry (%s)\n", e->e_dn, 0, 0 );
return( 1 );
}
+ edn = dn_normalize_case( strdup( e->e_dn ) );
+
#ifdef COMPAT30
if ( (ber = ber_alloc_t( conn->c_version == 30 ? 0 : LBER_USE_DER ))
- == NULLBER ) {
+ == NULLBER )
#else
- if ( (ber = der_alloc()) == NULLBER ) {
+ if ( (ber = der_alloc()) == NULLBER )
#endif
+ {
Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
- "ber_alloc" );
+ "ber_alloc" );
+ free(edn);
return( 1 );
}
LDAP_RES_SEARCH_ENTRY, e->e_dn );
} else
#endif
+ {
rc = ber_printf( ber, "{it{s{", op->o_msgid,
- LDAP_RES_SEARCH_ENTRY, e->e_dn );
+ LDAP_RES_SEARCH_ENTRY, e->e_dn );
+ }
if ( rc == -1 ) {
Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
ber_free( ber, 1 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
"ber_printf dn" );
+ free(edn);
return( 1 );
}
for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
+ regmatch_t matches[MAXREMATCHES];
+
if ( attrs != NULL && ! charray_inlist( attrs, a->a_type ) ) {
continue;
}
- acl = acl_get_applicable( be, op, e, a->a_type );
+ /* the lastmod attributes are ignored by ACL checking */
+ if ( strcasecmp( a->a_type, "modifiersname" ) == 0 ||
+ strcasecmp( a->a_type, "modifytimestamp" ) == 0 ||
+ strcasecmp( a->a_type, "creatorsname" ) == 0 ||
+ strcasecmp( a->a_type, "createtimestamp" ) == 0 )
+ {
+ Debug( LDAP_DEBUG_ACL, "LASTMOD attribute: %s access DEFAULT\n",
+ a->a_type, 0, 0 );
+ acl = NULL;
+ } else {
+ acl = acl_get_applicable( be, op, e, a->a_type, edn,
+ MAXREMATCHES, matches );
+ }
- if ( ! acl_access_allowed( acl, be, conn, e, NULL, op,
- ACL_READ ) ) {
+ if ( ! acl_access_allowed( acl, be, conn, e, NULL, op, ACL_READ,
+ edn, matches ) )
+ {
continue;
}
ber_free( ber, 1 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
NULL, "ber_printf type" );
+ free(edn);
return( 1 );
}
if ( ! attrsonly ) {
for ( i = 0; a->a_vals[i] != NULL; i++ ) {
- if ( a->a_syntax & SYNTAX_DN &&
- ! acl_access_allowed( acl, be, conn, e,
- a->a_vals[i], op, ACL_READ ) )
+ if ( a->a_syntax & SYNTAX_DN &&
+ ! acl_access_allowed( acl, be, conn, e, a->a_vals[i], op,
+ ACL_READ, edn, matches) )
{
continue;
}
send_ldap_result( conn, op,
LDAP_OPERATIONS_ERROR, NULL,
"ber_printf value" );
+ free(edn);
return( 1 );
}
}
ber_free( ber, 1 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
NULL, "ber_printf type end" );
+ free(edn);
return( 1 );
}
}
+ free(edn);
+
#ifdef COMPAT30
if ( conn->c_version == 30 ) {
rc = ber_printf( ber, "}}}}" );
* fm.c - file management routines.
*/
+#define DISABLE_BRIDGE
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <signal.h>
+#include <ac/string.h>
+#include <sys/signal.h>
#include "slurp.h"
#include "globals.h"
-extern void do_admin();
-
-static void set_shutdown();
-void do_nothing();
/*
* Externs
*/
-#ifdef NEEDPROTOS
-extern int file_nonempty( char * );
-extern int acquire_lock(char *, FILE **, FILE ** );
-extern int relinquish_lock(char *, FILE *, FILE * );
-#else /* NEEDPROTOS */
-extern int file_nonempty();
-extern int acquire_lock();
-extern int relinquish_lock();
-#endif /* NEEDPROTOS */
+extern void do_admin LDAP_P((void));
+extern int file_nonempty LDAP_P(( char * ));
+extern int acquire_lock LDAP_P((char *, FILE **, FILE ** ));
+extern int relinquish_lock LDAP_P((char *, FILE *, FILE * ));
/*
* Forward references
*/
-#ifdef NEEDPROTOS
-static char *get_record( FILE * );
-static void populate_queue( char *f );
-static void set_shutdown();
-void do_nothing();
-#else /* NEEDPROTOS */
-static char *get_record();
-static void populate_queue();
-static void set_shutdown();
-void do_nothing();
-#endif /* NEEDPROTOS */
-
-#ifndef SYSERRLIST_IN_STDIO
+static char *get_record LDAP_P(( FILE * ));
+static void populate_queue LDAP_P(( char *f ));
+static void set_shutdown LDAP_P((void));
+void do_nothing LDAP_P((void));
+
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO */
+#endif /* DECL_SYS_ERRLIST */
/* Set up our signal handlers:
* SIG{TERM,INT,HUP} causes a shutdown
- * SIGUSR1 - does nothing, used to wake up sleeping threads.
- * SIGUSR2 - causes slurpd to read its administrative interface file.
+ * SIG(STKFLT|USR1) - does nothing, used to wake up sleeping threads.
+ * SIG(UNUSED|USR2) - causes slurpd to read its administrative interface file.
* (not yet implemented).
*/
+#ifdef SIGSTKFLT
+ (void) SIGNAL( SIGSTKFLT, (void *) do_nothing );
+#else
(void) SIGNAL( SIGUSR1, (void *) do_nothing );
+#endif
+#ifdef SIGUNUSED
+ (void) SIGNAL( SIGUNUSED, (void *) do_admin );
+#else
(void) SIGNAL( SIGUSR2, (void *) do_admin );
+#endif
(void) SIGNAL( SIGTERM, (void *) set_shutdown );
(void) SIGNAL( SIGINT, (void *) set_shutdown );
(void) SIGNAL( SIGHUP, (void *) set_shutdown );
int i;
sglob->slurpd_shutdown = 1; /* set flag */
+#ifdef SIGSTKFLT
+ pthread_kill( sglob->fm_tid, SIGSTKFLT ); /* wake up file mgr */
+#else
pthread_kill( sglob->fm_tid, SIGUSR1 ); /* wake up file mgr */
+#endif
sglob->rq->rq_lock( sglob->rq ); /* lock queue */
pthread_cond_broadcast( &(sglob->rq->rq_more) ); /* wake repl threads */
for ( i = 0; i < sglob->num_replicas; i++ ) {
void
do_nothing()
{
+#ifdef SIGSTKFLT
+ (void) SIGNAL( SIGSTKFLT, (void *) do_nothing );
+#else
(void) SIGNAL( SIGUSR1, (void *) do_nothing );
+#endif
}
* ldap_op.c - routines to perform LDAP operations
*/
+#define DISABLE_BRIDGE
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
+#include <ac/string.h>
+#include <ac/time.h>
#include <sys/types.h>
-#include <sys/time.h>
#ifdef KERBEROS
+#ifdef KERBEROS_V
+#include <kerberosIV/krb.h>
+#else
#include <krb.h>
+#endif /* KERBEROS_V */
#endif /* KERBEROS */
#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 int get_changetype LDAP_P(( char * ));
+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
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO */
+#endif /* DECL_SYS_ERRLIST */
extern char *ch_malloc( unsigned long );
*/
+#define DISABLE_BRIDGE
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
+#include <ac/string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "globals.h"
/* externs */
-extern char *str_getline( char **next );
-extern void ch_free( char *p );
+extern char *str_getline LDAP_P(( char **next ));
+extern void ch_free LDAP_P(( char *p ));
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
+#endif /* DECL_SYS_ERRLIST */
/* 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 */
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;
* to a replica LDAP server.
*/
+#define DISABLE_BRIDGE
+#include "portable.h"
#include <stdio.h>
#include <sys/types.h>
#include "slurp.h"
#include "globals.h"
-#ifndef SYSERRLIST_IN_STDIO
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO */
+#endif /* DECL_SYS_ERRLIST */
/*
* replog.c - routines which read and write replication log files.
*/
+#define DISABLE_BRIDGE
+#include "portable.h"
+
#include <errno.h>
#include <stdio.h>
#include <syslog.h>
-#include <sys/time.h>
+#include <ac/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <fcntl.h>
#include <unistd.h>
-#include <string.h>
+#include <ac/string.h>
-#include "portable.h"
#include "slurp.h"
#include "globals.h"
/*
* Externs
*/
-#ifdef NEEDPROTOS
-extern FILE *lock_fopen( char *, char *, FILE ** );
-extern char *ch_malloc( unsigned long );
-#else /* NEEDPROTOS */
-extern FILE *lock_fopen();
-extern char *ch_malloc();
-#endif /* NEEDPROTOS */
+extern FILE *lock_fopen LDAP_P(( char *, char *, FILE ** ));
+extern char *ch_malloc LDAP_P(( unsigned long ));
/*
* Forward declarations
*/
-#ifdef NEEDPROTOS
-int file_nonempty( char * );
-#else /* NEEDPROTOS */
-int file_nonempty();
-#endif /* NEEDPROTOS */
+int file_nonempty LDAP_P(( char * ));
-#ifndef SYSERRLIST_IN_STDIO
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
#endif
static int duplicate_replog( char *, char * );
-
-
/*
* Copy the replication log. Returns 0 on success, 1 if a temporary
* error occurs, and -1 if a fatal error occurs.
*
*/
+#define DISABLE_BRIDGE
+#include "portable.h"
+
#include <stdio.h>
#include "slurp.h"
/* externs */
-#ifdef NEEDPROTOS
-extern void Re_dump( Re *re );
-#else /* NEEDPROTOS */
-extern void Re_dump();
-#endif /* NEEDPROTOS */
-
+extern void Re_dump LDAP_P(( Re *re ));
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
-
+#endif /* DECL_SYS_ERRLIST */
/*
* Lock the replication queue.
}
-
-
-
/*
* Unlock the replication queue.
*/
}
-
-
/*
* Return the next item in the queue. Callers should lock the queue before
* calling this routine.
}
-
-
/*
* Delete the item at the head of the list. The queue should be locked
* by the caller before calling this routine.
}
-
-
/*
* Add an entry to the tail of the replication queue. Locking is handled
* internally. When items are added to the queue, this routine wakes
}
-
-
/*
* Garbage-collect the replication queue. Locking is handled internally.
*/
}
-
/*
* For debugging: dump the contents of the replication queue to a file.
* Locking is handled internally.
}
-
/*
* Write the contents of a replication queue to a file. Returns zero if
* successful, -1 if not. Handles queue locking internally. Callers should
}
-
-
/*
* Check to see if the private slurpd replication log needs trimming.
* The current criteria are:
}
-
-
/*
* Allocate and initialize an Rq object.
*/
* writing status information to disk.
*/
-
+#define DISABLE_BRIDGE
+#include "portable.h"
#include <stdio.h>
-#include <string.h>
+#include <ac/string.h>
#include <unistd.h>
#include "slurp.h"
#include "globals.h"
-#ifndef SYSERRLIST_IN_STDIO
+#ifndef DECL_SYS_ERRLIST
extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO */
+#endif /* DECL_SYS_ERRLIST */
/*
* Add information about replica host specified by Ri to list
pthread_mutex_unlock( &(st->st_mutex ));
return NULL;
}
- st->st_data[ ind ] = ( Stel * ) ch_malloc( st->st_data,
- sizeof( Stel ));
+ st->st_data[ ind ] = ( Stel * ) ch_malloc( sizeof( Stel ) );
if ( st->st_data[ ind ] == NULL ) {
pthread_mutex_unlock( &(st->st_mutex ));
return NULL;