)
{
int rc;
- struct acl *a;
+ AccessControl *a;
char *edn;
regmatch_t matches[MAXREMATCHES];
* acl_access_allowed().
*/
-struct acl *
+AccessControl *
acl_get_applicable(
Backend *be,
Operation *op,
)
{
int i;
- struct acl *a;
+ AccessControl *a;
char *edn;
Debug( LDAP_DEBUG_ACL, "\n=> acl_get: entry (%s) attr (%s)\n",
int
acl_access_allowed(
- struct acl *a,
+ AccessControl *a,
Backend *be,
Connection *conn,
Entry *e,
)
{
int i;
- struct access *b;
+ Access *b;
Attribute *at;
struct berval bv;
int default_access;
)
{
int i;
- struct acl *a;
+ AccessControl *a;
char *edn = e->e_ndn;
for ( ; mlist != NULL; mlist = mlist->ml_next ) {
#include "slap.h"
static void split(char *line, int splitchar, char **left, char **right);
-static void acl_append(struct acl **l, struct acl *a);
-static void access_append(struct access **l, struct access *a);
+static void acl_append(AccessControl **l, AccessControl *a);
+static void access_append(Access **l, Access *a);
static void acl_usage(void);
#ifdef LDAP_DEBUG
-static void print_acl(struct acl *a);
-static void print_access(struct access *b);
+static void print_acl(AccessControl *a);
+static void print_access(Access *b);
#endif
static int
{
int i;
char *left, *right;
- struct acl *a;
- struct access *b;
+ AccessControl *a;
+ Access *b;
a = NULL;
for ( i = 1; i < argc; i++ ) {
fname, lineno );
acl_usage();
}
- a = (struct acl *) ch_calloc( 1, sizeof(struct acl) );
+ a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
for ( ++i; i < argc; i++ ) {
if ( strcasecmp( argv[i], "by" ) == 0 ) {
i--;
* by clause consists of <who> and <access>
*/
- b = (struct access *) ch_calloc( 1, sizeof(struct access) );
+ b = (Access *) ch_calloc( 1, sizeof(Access) );
if ( ++i == argc ) {
fprintf( stderr,
}
static void
-access_append( struct access **l, struct access *a )
+access_append( Access **l, Access *a )
{
for ( ; *l != NULL; l = &(*l)->a_next )
; /* NULL */
}
static void
-acl_append( struct acl **l, struct acl *a )
+acl_append( AccessControl **l, AccessControl *a )
{
for ( ; *l != NULL; l = &(*l)->acl_next )
; /* NULL */
#ifdef LDAP_DEBUG
static void
-print_access( struct access *b )
+print_access( Access *b )
{
fprintf( stderr, "\tby" );
}
static void
-print_acl( struct acl *a )
+print_acl( AccessControl *a )
{
int i;
- struct access *b;
+ Access *b;
if ( a == NULL ) {
fprintf( stderr, "NULL\n" );
static int
ainfo_type_cmp(
char *type,
- struct attrinfo *a
+ AttrInfo *a
)
{
return( strcasecmp( type, a->ai_type ) );
static int
ainfo_cmp(
- struct attrinfo *a,
- struct attrinfo *b
+ AttrInfo *a,
+ AttrInfo *b
)
{
return( strcasecmp( a->ai_type, b->ai_type ) );
static int
ainfo_dup(
- struct attrinfo *a,
- struct attrinfo *b
+ AttrInfo *a,
+ AttrInfo *b
)
{
/*
int *syntaxmask
)
{
- struct attrinfo *a;
+ AttrInfo *a;
*indexmask = 0;
*syntaxmask = 0;
- if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
+ if ( (a = (AttrInfo *) avl_find( li->li_attrs, type,
(AVL_CMP) ainfo_type_cmp )) == NULL ) {
- if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
+ if ( (a = (AttrInfo *) avl_find( li->li_attrs, "default",
(AVL_CMP) ainfo_type_cmp )) == NULL ) {
return;
}
{
int i, j;
char **attrs, **indexes;
- struct attrinfo *a;
+ AttrInfo *a;
attrs = str2charray( argv[0], "," );
if ( argc > 1 ) {
indexes = str2charray( argv[1], "," );
}
for ( i = 0; attrs[i] != NULL; i++ ) {
- a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
+ a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
a->ai_type = ch_strdup( attrs[i] );
a->ai_syntaxmask = attr_syntax( a->ai_type );
if ( argc == 1 ) {
#define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
/* for the in-core cache of entries */
-struct cache {
+typedef struct ldbm_cache {
int c_maxsize;
int c_cursize;
Avlnode *c_dntree;
Entry *c_lruhead; /* lru - add accessed entries here */
Entry *c_lrutail; /* lru - rem lru entries from here */
ldap_pvt_thread_mutex_t c_mutex;
-};
+} Cache;
#define CACHE_READ_LOCK 0
#define CACHE_WRITE_LOCK 1
/* for the cache of open index files */
-struct dbcache {
+typedef struct ldbm_dbcache {
int dbc_refcnt;
int dbc_maxids;
int dbc_maxindirect;
long dbc_blksize;
char *dbc_name;
LDBM dbc_db;
-};
+} DBCache;
/* for the cache of attribute information (which are indexed, etc.) */
-struct attrinfo {
+typedef struct ldbm_attrinfo {
char *ai_type; /* type name (cn, sn, ...) */
int ai_indexmask; /* how the attr is indexed */
#define INDEX_PRESENCE 0x01
#define SYNTAX_BIN 0x04
... etc. ...
*/
-};
+} AttrInfo;
#define MAXDBCACHE 10
ldap_pvt_thread_mutex_t li_nextid_mutex;
int li_mode;
char *li_directory;
- struct cache li_cache;
+ Cache li_cache;
Avlnode *li_attrs;
int li_dbcachesize;
int li_dbcachewsync;
- struct dbcache li_dbcache[MAXDBCACHE];
+ DBCache li_dbcache[MAXDBCACHE];
ldap_pvt_thread_mutex_t li_dbcache_mutex;
ldap_pvt_thread_cond_t li_dbcache_cv;
#ifdef HAVE_BERKELEY_DB2
#include "back-ldbm.h"
/* LDBM backend specific entry info -- visible only to the cache */
-struct ldbm_entry_info {
+typedef struct ldbm_entry_info {
ldap_pvt_thread_rdwr_t lei_rdwr; /* reader/writer lock */
/*
#define CACHE_ENTRY_DELETED 3
int lei_refcnt; /* # threads ref'ing this entry */
- struct entry *lei_lrunext; /* for cache lru list */
- struct entry *lei_lruprev;
-};
-#define LEI(e) ((struct ldbm_entry_info *) ((e)->e_private))
+ Entry *lei_lrunext; /* for cache lru list */
+ Entry *lei_lruprev;
+} EntryInfo;
+#define LEI(e) ((EntryInfo *) ((e)->e_private))
-static int cache_delete_entry_internal(struct cache *cache, Entry *e);
+static int cache_delete_entry_internal(Cache *cache, Entry *e);
#ifdef LDAP_DEBUG
-static void lru_print(struct cache *cache);
+static void lru_print(Cache *cache);
#endif
static int
}
void
-cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
+cache_return_entry_rw( Cache *cache, Entry *e, int rw )
{
ID id;
int refcnt;
*/
int
cache_add_entry_rw(
- struct cache *cache,
+ Cache *cache,
Entry *e,
int rw
)
*/
int
cache_update_entry(
- struct cache *cache,
+ Cache *cache,
Entry *e
)
{
ID
cache_find_entry_dn2id(
Backend *be,
- struct cache *cache,
+ Cache *cache,
char *dn
)
{
Entry *
cache_find_entry_id(
- struct cache *cache,
+ Cache *cache,
ID id,
int rw
)
*/
int
cache_delete_entry(
- struct cache *cache,
+ Cache *cache,
Entry *e
)
{
static int
cache_delete_entry_internal(
- struct cache *cache,
+ Cache *cache,
Entry *e
)
{
#ifdef SLAP_CLEANUP
void
-cache_release_all( struct cache *cache )
+cache_release_all( Cache *cache )
{
Entry *e;
int rc;
#ifdef LDAP_DEBUG
static void
-lru_print( struct cache *cache )
+lru_print( Cache *cache )
{
Entry *e;
#include "slap.h"
#include "back-ldbm.h"
-struct dbcache *
+DBCache *
ldbm_cache_open(
Backend *be,
char *name,
}
void
-ldbm_cache_close( Backend *be, struct dbcache *db )
+ldbm_cache_close( Backend *be, DBCache *db )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
}
void
-ldbm_cache_really_close( Backend *be, struct dbcache *db )
+ldbm_cache_really_close( Backend *be, DBCache *db )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Datum
ldbm_cache_fetch(
- struct dbcache *db,
+ DBCache *db,
Datum key
)
{
int
ldbm_cache_store(
- struct dbcache *db,
+ DBCache *db,
Datum key,
Datum data,
int flags
int
ldbm_cache_delete(
- struct dbcache *db,
+ DBCache *db,
Datum key
)
{
)
{
int rc, flags;
- struct dbcache *db;
+ DBCache *db;
Datum key, data;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
)
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- struct dbcache *db;
+ DBCache *db;
ID id;
Datum key, data;
char *dn
)
{
- struct dbcache *db;
+ DBCache *db;
Datum key;
int rc;
Entry *e
)
{
- struct dbcache *db;
+ DBCache *db;
Datum key;
char buf[20];
Entry *e
)
{
- struct dbcache *db;
+ DBCache *db;
Datum key;
char buf[20];
Entry *p
)
{
- struct dbcache *db;
+ DBCache *db;
Datum key;
int rc = 0;
ID_BLOCK *idl;
id2entry_add( Backend *be, Entry *e )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- struct dbcache *db;
+ DBCache *db;
Datum key, data;
int len, rc, flags;
id2entry_delete( Backend *be, Entry *e )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- struct dbcache *db;
+ DBCache *db;
Datum key;
int rc;
id2entry_rw( Backend *be, ID id, int rw )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- struct dbcache *db;
+ DBCache *db;
Datum key, data;
Entry *e;
static ID_BLOCK *
idl_fetch_one(
Backend *be,
- struct dbcache *db,
+ DBCache *db,
Datum key
)
{
ID_BLOCK *
idl_fetch(
Backend *be,
- struct dbcache *db,
+ DBCache *db,
Datum key
)
{
static int
idl_store(
Backend *be,
- struct dbcache *db,
+ DBCache *db,
Datum key,
ID_BLOCK *idl
)
static int
idl_change_first(
Backend *be,
- struct dbcache *db,
+ DBCache *db,
Datum hkey, /* header block key */
ID_BLOCK *h, /* header block */
int pos, /* pos in h to update */
int
idl_insert_key(
Backend *be,
- struct dbcache *db,
+ DBCache *db,
Datum key,
ID id
)
int
idl_delete_key (
Backend *be,
- struct dbcache *db,
+ DBCache *db,
Datum key,
ID id
)
#include "back-ldbm.h"
static int change_value(Backend *be,
- struct dbcache *db,
+ DBCache *db,
char *type,
int indextype,
char *val,
ID id,
int
- (*idl_func)(Backend *, struct dbcache *, Datum, ID));
+ (*idl_func)(Backend *, DBCache *, Datum, ID));
static int index2prefix(int indextype);
int
char *val
)
{
- struct dbcache *db;
+ DBCache *db;
Datum key;
ID_BLOCK *idl;
int indexmask, syntax;
static int
change_value(
Backend *be,
- struct dbcache *db,
+ DBCache *db,
char *type,
int indextype,
char *val,
ID id,
- int (*idl_func)(Backend *, struct dbcache *, Datum, ID)
+ int (*idl_func)(Backend *, DBCache *, Datum, ID)
)
{
int rc;
char buf[SUBLEN + 1];
char vbuf[BUFSIZ];
char *bigbuf;
- struct dbcache *db;
+ DBCache *db;
int (*idl_funct)(Backend *,
- struct dbcache *,
+ DBCache *,
Datum, ID);
char *at_cn; /* Attribute canonical name */
int mode;
* cache.c
*/
-int cache_add_entry_rw LDAP_P(( struct cache *cache, Entry *e, int rw ));
-int cache_update_entry LDAP_P(( struct cache *cache, Entry *e ));
-void cache_return_entry_rw LDAP_P(( struct cache *cache, Entry *e, int rw ));
+int cache_add_entry_rw LDAP_P(( Cache *cache, Entry *e, int rw ));
+int cache_update_entry LDAP_P(( Cache *cache, Entry *e ));
+void cache_return_entry_rw LDAP_P(( Cache *cache, Entry *e, int rw ));
#define cache_return_entry_r(c, e) cache_return_entry_rw((c), (e), 0)
#define cache_return_entry_w(c, e) cache_return_entry_rw((c), (e), 1)
-ID cache_find_entry_dn2id LDAP_P(( Backend *be, struct cache *cache, char *dn ));
-Entry * cache_find_entry_id LDAP_P(( struct cache *cache, ID id, int rw ));
-int cache_delete_entry LDAP_P(( struct cache *cache, Entry *e ));
+ID cache_find_entry_dn2id LDAP_P(( Backend *be, Cache *cache, char *dn ));
+Entry * cache_find_entry_id LDAP_P(( Cache *cache, ID id, int rw ));
+int cache_delete_entry LDAP_P(( Cache *cache, Entry *e ));
#ifdef SLAP_CLEANUP
-void cache_release_all LDAP_P(( struct cache *cache ));
+void cache_release_all LDAP_P(( Cache *cache ));
#endif
/*
* dbcache.c
*/
-struct dbcache * ldbm_cache_open LDAP_P(( Backend *be, char *name, char *suffix,
- int flags ));
-void ldbm_cache_close LDAP_P(( Backend *be, struct dbcache *db ));
-void ldbm_cache_really_close LDAP_P(( Backend *be, struct dbcache *db ));
+DBCache * ldbm_cache_open LDAP_P(( Backend *be,
+ char *name, char *suffix, int flags ));
+void ldbm_cache_close LDAP_P(( Backend *be, DBCache *db ));
+void ldbm_cache_really_close LDAP_P(( Backend *be, DBCache *db ));
void ldbm_cache_flush_all LDAP_P(( Backend *be ));
-Datum ldbm_cache_fetch LDAP_P(( struct dbcache *db, Datum key ));
-int ldbm_cache_store LDAP_P(( struct dbcache *db, Datum key, Datum data, int flags ));
-int ldbm_cache_delete LDAP_P(( struct dbcache *db, Datum key ));
+Datum ldbm_cache_fetch LDAP_P(( DBCache *db, Datum key ));
+int ldbm_cache_store LDAP_P(( DBCache *db, Datum key, Datum data, int flags ));
+int ldbm_cache_delete LDAP_P(( DBCache *db, Datum key ));
/*
* dn2id.c
ID_BLOCK * idl_alloc LDAP_P(( unsigned int nids ));
ID_BLOCK * idl_allids LDAP_P(( Backend *be ));
void idl_free LDAP_P(( ID_BLOCK *idl ));
-ID_BLOCK * idl_fetch LDAP_P(( Backend *be, struct dbcache *db, Datum key ));
-int idl_insert_key LDAP_P(( Backend *be, struct dbcache *db, Datum key, ID id ));
+ID_BLOCK * idl_fetch LDAP_P(( Backend *be, DBCache *db, Datum key ));
+int idl_insert_key LDAP_P(( Backend *be, DBCache *db, Datum key, ID id ));
int idl_insert LDAP_P(( ID_BLOCK **idl, ID id, unsigned int maxids ));
-int idl_delete_key LDAP_P(( Backend *be, struct dbcache *db, Datum key, ID id ));
+int idl_delete_key LDAP_P(( Backend *be, DBCache *db, Datum key, ID id ));
ID_BLOCK * idl_intersection LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b ));
ID_BLOCK * idl_union LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b ));
ID_BLOCK * idl_notin LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b ));
int index_add_entry LDAP_P(( Backend *be, Entry *e ));
int index_add_mods LDAP_P(( Backend *be, LDAPModList *ml, ID id ));
-ID_BLOCK * index_read LDAP_P(( Backend *be, char *type, int indextype, char *val ));
+ID_BLOCK * index_read LDAP_P(( Backend *be,
+ char *type, int indextype, char *val ));
/* Possible operations supported (op) by index_change_values() */
#define __INDEX_ADD_OP 0x0001
#define __INDEX_DELETE_OP 0x0002
int add_values LDAP_P(( Entry *e, LDAPMod *mod, char *dn ));
int delete_values LDAP_P(( Entry *e, LDAPMod *mod, char *dn ));
int replace_values LDAP_P(( Entry *e, LDAPMod *mod, char *dn ));
-int ldbm_modify_internal LDAP_P((Backend *be, Connection *conn, Operation *op,
- char *dn, LDAPModList *mods, Entry *e));
+int ldbm_modify_internal LDAP_P((Backend *be,
+ Connection *conn, Operation *op,
+ char *dn, LDAPModList *mods, Entry *e));
/*
* nextid.c
*/
int defsize = SLAPD_DEFAULT_SIZELIMIT;
int deftime = SLAPD_DEFAULT_TIMELIMIT;
-struct acl *global_acl = NULL;
+AccessControl *global_acl = NULL;
int global_default_access = ACL_READ;
char *replogfile;
int global_lastmod;
char *line, *savefname, *saveline;
int cargc, savelineno;
char *cargv[MAXARGS];
- int lineno, i, rc;
-
+ int lineno, i;
+#ifdef HAVE_TLS
+ int rc;
+#endif
struct berval *vals[2];
struct berval val;
ber_socket_t s,
const char* name,
const char* addr,
- int use_tls)
+ int use_tls )
{
unsigned long id;
Connection *c;
assert( connections != NULL );
+#ifndef HAVE_TLS
+ assert( !use_tls );
+#endif
+
if( s == AC_SOCKET_INVALID ) {
Debug( LDAP_DEBUG_ANY,
"connection_init(%ld): invalid.\n",
c->c_conn_state = SLAP_C_INACTIVE;
c->c_struct_state = SLAP_C_USED;
+#ifdef HAVE_TLS
if ( use_tls ) {
c->c_is_tls = 1;
c->c_needs_tls_accept = 1;
}
+#endif
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
ldap_pvt_thread_mutex_unlock( &connections_mutex );
#endif /* TCP Wrappers */
/* globals */
+time_t starttime;
ber_socket_t dtblsize;
+
+typedef struct slap_listener {
+ char* sl_url;
#ifdef HAVE_TLS
-#define N_LISTENERS 2
-#else
-#define N_LISTENERS 1
+ int sl_is_tls;
#endif
-struct listener_rec {
- ber_socket_t tcps;
- struct sockaddr_in *addr;
- int use_tls;
-} listeners[N_LISTENERS];
+ ber_socket_t sl_sd;
+ struct sockaddr_in sl_addr;
+} Listener;
+
+Listener **slap_listeners;
#ifdef HAVE_WINSOCK2
/* in nt_main.c */
extern ldap_pvt_thread_cond_t started_event;
/* forward reference */
-void hit_socket();
+static void hit_socket(void);
/* In wsa_err.c */
char *WSAGetLastErrorString();
static ldap_pvt_thread_t hit_tid;
#endif
volatile sig_atomic_t slapd_shutdown = 0;
-static int daemon_initialized = 0;
static ldap_pvt_thread_t listener_tid;
static volatile sig_atomic_t slapd_listener = 0;
-void sockinit();
-struct slap_daemon {
+static struct slap_daemon {
ldap_pvt_thread_mutex_t sd_mutex;
int sd_nactives;
}
+Listener *
+open_listener(
+ char* url,
+ int port,
+ int tls_port )
+{
+ int tmp, rc;
+ Listener l;
+ Listener *li;
+ LDAPURLDesc *lud;
+
+ rc = ldap_url_parse( url, &lud );
+
+ if( rc != LDAP_URL_SUCCESS ) {
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: listen URL \"%s\" parse error=%d\n",
+ url, rc, 0 );
+ return NULL;
+ }
+
+#ifndef HAVE_TLS
+ if( lud->lud_ldaps ) {
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: TLS not supported (%s)\n",
+ url, 0, 0 );
+ ldap_free_urldesc( lud );
+ return NULL;
+ }
+
+ if(! lud->lud_port ) {
+ lud->lud_port = port;
+ }
+
+#else
+ if(! lud->lud_port ) {
+ lud->lud_port = lud->lud_ldaps ? tls_port : port;
+ }
+#endif
+
+ (void) memset( (void*) &l.sl_addr, '\0', sizeof(l.sl_addr) );
+
+ l.sl_addr.sin_family = AF_INET;
+ l.sl_addr.sin_port = htons( (unsigned short) lud->lud_port );
+
+ if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
+ || strcmp(lud->lud_host, "*") == 0 )
+ {
+ l.sl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ } else {
+ /* host or address was specified */
+
+ if( isdigit( lud->lud_host[0] ) ) {
+#ifdef HAVE_WINSOCK
+ if(!(l.sl_addr.sin_addr.S_un.S_addr = inet_addr(lud->lud_host)))
+#else
+ if(!inet_aton(lud->lud_host, &l.sl_addr.sin_addr))
+#endif
+ {
+ Debug( LDAP_DEBUG_ANY, "invalid address (%s) in URL: %s",
+ lud->lud_host, url, 0);
+ ldap_free_urldesc( lud );
+ return NULL;
+ }
+
+ } else {
+ struct hostent *he = gethostbyname( lud->lud_host );
+ if( he == NULL ) {
+ Debug( LDAP_DEBUG_ANY, "invalid host (%s) in URL: %s",
+ lud->lud_host, url, 0);
+ ldap_free_urldesc( lud );
+ return NULL;
+ }
+
+#ifdef HAVE_WINSOCK
+ if(!(l.sl_addr.sin_addr.S_un.S_addr = inet_addr(he->h_addr)))
+#else
+ if(!inet_aton(he->h_addr, &l.sl_addr.sin_addr))
+#endif
+ {
+ Debug( LDAP_DEBUG_ANY, "%s has invalid address (%s) in URL: %s",
+ lud->lud_host, he->h_addr, url );
+ ldap_free_urldesc( lud );
+ return NULL;
+ }
+ }
+ }
+
+ ldap_free_urldesc( lud );
+
-int
-set_socket( struct sockaddr_in *addr )
+ if ( (l.sl_sd = socket( AF_INET, SOCK_STREAM, 0 )) == AC_SOCKET_INVALID ) {
+#ifndef HAVE_WINSOCK
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: socket() failed errno %d (%s)\n", err,
+ err > -1 && err < sys_nerr ? sys_errlist[err] :
+ "unknown", 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: socket() failed errno %d (%s)\n",
+ WSAGetLastError(),
+ WSAGetLastErrorString(), 0 );
+#endif
+ return( AC_SOCKET_INVALID );
+ }
+
+#ifndef HAVE_WINSOCK
+ if ( l.sl_sd >= dtblsize ) {
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: listener descriptor %ld is too great %ld\n",
+ (long) l.sl_sd, (long) dtblsize, 0 );
+ tcp_close( l.sl_sd );
+ return( AC_SOCKET_INVALID );
+ }
+#endif
+
+#ifdef SO_REUSEADDR
+ tmp = 1;
+ if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &tmp, sizeof(tmp) ) == -1 )
+ {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "slapd(%ld): setsockopt() failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ }
+#endif
+#ifdef SO_KEEPALIVE
+ tmp = 1;
+ if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE,
+ (char *) &tmp, sizeof(tmp) ) == -1 )
+ {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "slapd(%ld): setsockopt(KEEPALIVE) failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ }
+#endif
+
+ if ( bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) ) == -1 ) {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ tcp_close( l.sl_sd );
+ return AC_SOCKET_INVALID;
+ }
+
+ l.sl_url = ch_strdup( url );
+
+ li = ch_malloc( sizeof( Listener ) );
+ *li = l;
+
+ return li;
+}
+
+static int sockinit(void);
+static int sockdestroy(void);
+
+slapd_daemon_init(char *urls, int port, int tls_port )
{
- ber_socket_t tcps = AC_SOCKET_INVALID;
+ int i, rc;
+ char **u;
- if ( !daemon_initialized ) sockinit();
+#ifndef HAVE_TLS
+ assert( tls_port == 0 );
+#endif
+
+ if( rc = sockinit() ) {
+ return rc;
+ }
#ifdef HAVE_SYSCONF
dtblsize = sysconf( _SC_OPEN_MAX );
}
#endif /* !FD_SETSIZE */
- if( addr != NULL ) {
- int tmp;
+ FD_ZERO( &slap_daemon.sd_readers );
+ FD_ZERO( &slap_daemon.sd_writers );
- if ( (tcps = socket( AF_INET, SOCK_STREAM, 0 )) == AC_SOCKET_INVALID ) {
-#ifndef HAVE_WINSOCK
- int err = errno;
- Debug( LDAP_DEBUG_ANY,
- "daemon: socket() failed errno %d (%s)\n", err,
- err > -1 && err < sys_nerr ? sys_errlist[err] :
- "unknown", 0 );
-#else
- Debug( LDAP_DEBUG_ANY,
- "daemon: socket() failed errno %d (%s)\n",
- WSAGetLastError(),
- WSAGetLastErrorString(), 0 );
-#endif
- return( -1 );
- }
+ if( urls == NULL ) {
+ urls = ch_strdup("ldap://");
+ }
-#ifndef HAVE_WINSOCK
- if ( tcps >= dtblsize ) {
- Debug( LDAP_DEBUG_ANY,
- "daemon: listener descriptor %ld is too great %ld\n",
- (long) tcps, (long) dtblsize, 0 );
- return( -1);
- }
-#endif
+ u = str2charray( urls, " " );
-#ifdef SO_REUSEADDR
- tmp = 1;
- if ( setsockopt( tcps, SOL_SOCKET, SO_REUSEADDR,
- (char *) &tmp, sizeof(tmp) ) == -1 )
- {
- int err = errno;
- Debug( LDAP_DEBUG_ANY,
- "slapd(%ld): setsockopt() failed errno %d (%s)\n",
- (long) tcps, err,
- err > -1 && err < sys_nerr
- ? sys_errlist[err] : "unknown" );
- }
-#endif
-#ifdef SO_KEEPALIVE
- tmp = 1;
- if ( setsockopt( tcps, SOL_SOCKET, SO_KEEPALIVE,
- (char *) &tmp, sizeof(tmp) ) == -1 )
- {
- int err = errno;
- Debug( LDAP_DEBUG_ANY,
- "slapd(%ld): setsockopt(KEEPALIVE) failed errno %d (%s)\n",
- (long) tcps, err,
- err > -1 && err < sys_nerr
- ? sys_errlist[err] : "unknown" );
- }
-#endif
+ if( u == NULL ) {
+ return -1;
+ }
+ for(i = 0; u[i] == NULL; i++ ) {
+ /* EMPTY */ ;
+ }
- if ( bind( tcps, (struct sockaddr *) addr, sizeof(*addr) ) == -1 ) {
- int err = errno;
- Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno %d (%s)\n",
- (long) tcps, err,
- err > -1 && err < sys_nerr
- ? sys_errlist[err] : "unknown" );
+ slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) );
+
+ for(i = 0; u[i] == NULL; i++ ) {
+ slap_listeners[i] = open_listener( u[i], port, tls_port );
+
+ if( slap_listeners[i] == NULL ) {
return -1;
}
}
+ slap_listeners[i] = NULL;
+
+
+ charray_free( u );
+
+ ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
- return tcps;
+ return 0;
}
+
+slapd_daemon_destroy(void)
+{
+ connections_destroy();
+ sockdestroy();
+ return 0;
+}
+
+
static void *
slapd_daemon_task(
void *ptr
)
{
- int inetd;
- struct slapd_args *args = (struct slapd_args *) ptr;
int l;
- listeners[0].tcps = args->tcps;
- listeners[0].addr = args->addr;
- listeners[0].use_tls = 0;
-#ifdef HAVE_TLS
- listeners[1].tcps = args->tls_tcps;
- listeners[1].addr = args->tls_addr;
- listeners[1].use_tls = 1;
-#endif
-
- inetd = ( listeners[0].addr == NULL);
- if ( !daemon_initialized ) sockinit();
+ time( &starttime );
- slapd_listener=1;
-
- ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
- FD_ZERO( &slap_daemon.sd_readers );
- FD_ZERO( &slap_daemon.sd_writers );
-
- if( !inetd ) {
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( listeners[l].tcps < 0 )
- continue;
- if ( listen( listeners[l].tcps, 5 ) == -1 ) {
- int err = errno;
- Debug( LDAP_DEBUG_ANY,
- "daemon: listen(%ld, 5) failed errno %d (%s)\n",
- (long) listeners[l].tcps, err,
- err > -1 && err < sys_nerr
- ? sys_errlist[err] : "unknown" );
- return( (void*)-1 );
- }
-
- slapd_add( listeners[l].tcps );
- }
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
+ continue;
- } else {
- if( connection_init( (ber_socket_t) 0, NULL, NULL, 0 ) ) {
+ if ( listen( slap_listeners[l]->sl_sd, 5 ) == -1 ) {
+ int err = errno;
Debug( LDAP_DEBUG_ANY,
- "connection_init(%d) failed.\n",
- 0, 0, 0 );
+ "daemon: listen(%s, 5) failed errno %d (%s)\n",
+ (long) slap_listeners[l]->sl_url, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+
return( (void*)-1 );
}
- slapd_add( 0 );
+ slapd_add( slap_listeners[l]->sl_sd );
}
#ifdef HAVE_WINSOCK
- if ( started_event != NULL )
+ if ( started_event != NULL ) {
ldap_pvt_thread_cond_signal( &started_event );
+ }
#endif
/* initialization complete. Here comes the loop. */
memcpy( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
#endif
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( listeners[l].tcps < 0 )
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
continue;
- FD_SET( (unsigned) listeners[l].tcps, &readfds );
+ FD_SET( slap_listeners[l]->sl_sd, &readfds );
}
#ifndef HAVE_WINSOCK
tvp = at ? &zero : NULL;
#endif
- for ( i = 0; i < N_LISTENERS; i++ ) {
- if ( listeners[l].tcps < 0 )
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
continue;
+
Debug( LDAP_DEBUG_CONNS,
- "daemon: select: tcps=%d active_threads=%d tvp=%s\n",
- listeners[i].tcps, at,
- tvp == NULL ? "NULL" : "zero" );
+ "daemon: select: listen=%d active_threads=%d tvp=%s\n",
+ slap_listeners[l]->sl_sd, at,
+ tvp == NULL ? "NULL" : "zero" );
}
switch(ns = select( nfds, &readfds,
/* FALL THRU */
}
- for ( l = 0; l < N_LISTENERS; l++ ) {
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
ber_int_t s;
socklen_t len = sizeof(from);
long id;
- if ( listeners[l].tcps < 0 )
+ if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
continue;
- if ( !FD_ISSET( listeners[l].tcps, &readfds ) )
+
+ if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
continue;
- if ( (s = accept( listeners[l].tcps,
+ if ( (s = accept( slap_listeners[l]->sl_sd,
(struct sockaddr *) &from, &len )) == AC_SOCKET_INVALID )
{
int err = errno;
Debug( LDAP_DEBUG_ANY,
"daemon: accept(%ld) failed errno %d (%s)\n", err,
- (long) listeners[l].tcps,
+ (long) slap_listeners[l]->sl_sd,
err >= 0 && err < sys_nerr ?
sys_errlist[err] : "unknown");
continue;
#endif /* HAVE_TCPD */
if( (id = connection_init(s, client_name, client_addr,
- listeners[l].use_tls)) < 0 ) {
+#ifdef HAVE_TLS
+ slap_listeners[l]->sl_is_tls
+#else
+ 0
+#endif
+ )) < 0 )
+ {
Debug( LDAP_DEBUG_ANY,
"daemon: connection_init(%ld, %s, %s) failed.\n",
(long) s,
int a, r, w;
int is_listener = 0;
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( i == listeners[l].tcps ) {
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( i == slap_listeners[l]->sl_sd ) {
is_listener = 1;
break;
}
wd = i;
#endif
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( wd == listeners[l].tcps ) {
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( i == slap_listeners[l]->sl_sd ) {
is_listener = 1;
break;
}
rd = i;
#endif
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( rd == listeners[l].tcps ) {
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( i == slap_listeners[l]->sl_sd ) {
is_listener = 1;
break;
}
0, 0, 0 );
}
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( listeners[l].tcps >= 0 ) {
- slapd_close( listeners[l].tcps );
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
+ slapd_close( slap_listeners[l]->sl_sd );
+ break;
}
}
}
-int slapd_daemon( struct slapd_args *args )
+int slapd_daemon( void )
{
int rc;
- if ( !daemon_initialized ) sockinit();
-
connections_init();
#define SLAPD_LISTENER_THREAD 1
/* listener as a separate THREAD */
rc = ldap_pvt_thread_create( &listener_tid,
- 0, slapd_daemon_task, args );
+ 0, slapd_daemon_task, NULL );
if ( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
- goto destory;
+ return rc;
}
/* wait for the listener thread to complete */
#else
/* expermimental code */
listener_tid = pthread_self();
- slapd_daemon_task( args );
+ slapd_daemon_task( NULL );
#endif
- rc = 0;
-
-destory:
- connections_destroy();
+ return 0;
-#ifdef HAVE_WINSOCK
- WSACleanup( );
-#endif
-
- return rc;
}
#ifdef HAVE_WINSOCK2
-void sockinit()
+int sockinit(void)
{
WORD wVersionRequested;
WSADATA wsaData;
if ( err != 0 ) {
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
- return;
+ return -1;
}
/* Confirm that the WinSock DLL supports 2.0.*/
{
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
- WSACleanup( );
- return;
+ WSACleanup();
+ return -1;
}
- daemon_initialized = 1;
-} /* The WinSock DLL is acceptable. Proceed. */
-void hit_socket()
+ /* The WinSock DLL is acceptable. Proceed. */
+ return 0;
+}
+
+int sockdestroy(void)
+{
+ WSACleanup();
+ return 0;
+}
+
+void hit_socket(void)
{
ber_socket_t s;
int on = 1;
}
#elif HAVE_WINSOCK
-void sockinit()
+static int sockinit(void)
{ WSADATA wsaData;
if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
- return( NULL );
+ return -1;
}
- daemon_initialized = 1;
+ return 0;
}
+static int sockdestroy(void)
+{
+ WSACleanup();
+ return 0;
+}
+
#else
-void sockinit()
+static int sockinit(void)
+{
+ return 0;
+}
+static int sockdestroy(void)
{
- daemon_initialized = 1;
+ return 0;
}
#endif
/* trying to "hit" the socket seems to always get a */
/* EWOULDBLOCK error, so just close the listen socket to */
/* break out of the select since we're shutting down anyway */
- for ( l = 0; l < N_LISTENERS; l++ ) {
- if ( listeners[l].tcps >= 0 ) {
- tcp_close( listeners[l].tcps );
+ for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+ if ( slap_listeners[l]->sl_sd >= 0 ) {
+ tcp_close( slap_listeners[l]->sl_sd );
}
}
#endif
extern ldap_pvt_thread_cond_t started_event, stopped_event;
extern int is_NT_Service;
-void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, short port, int udp );
+void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
void LogSlapdStoppedEvent( char *svc );
void CommenceStartupProcessing( LPCTSTR serviceName,
#define MAIN_RETURN(x) return(x)
#endif
-short port = LDAP_PORT;
-#ifdef HAVE_TLS
-short tls_port = LDAP_TLS_PORT;
-#endif
/*
* when more than one slapd is running on one machine, each one might have
* it's own LOCAL for syslogging and must have its own pid/args files
static void
usage( char *name )
{
- fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name );
- fprintf( stderr, "\n [-a bind-address] [-i] [-u]" );
-#ifdef HAVE_WINSOCK
- fprintf( stderr, " [-n NTserviceName]" );
-#endif
+ fprintf( stderr,
+ "usage: %s options\n", name );
+ fprintf( stderr,
#if LDAP_CONNECTIONLESS
- fprintf( stderr, " [-c]" );
+ "\t-c\t\tEnable (experimental) Connectionless LDAP\n"
#endif
-#ifdef SLAPD_BDB2
- fprintf( stderr, " [-t]" );
+ "\t-d level\tDebug Level" "\n"
+ "\t-f filename\tConfiguration File\n"
+#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
+ "\t-g group\tGroup (id or name) to ran as\n"
#endif
+ "\t-h URLs\tList of URLs to serve"
#ifdef LOG_LOCAL4
- fprintf( stderr, " [-l sysloguser]" );
+ "\t-l sysloguser\tSyslog User (default: LOCAL4)\n"
#endif
-#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
- fprintf( stderr, " [-u user] [-g group]" );
+#ifdef HAVE_WINSOCK
+ "\t-n NTserviceName\tNT service name\n"
#endif
- fprintf( stderr, "\n" );
-}
-time_t starttime;
-struct sockaddr_in bind_addr;
-ber_int_t tcps;
+ "\t-p port\tLDAP Port\n"
#ifdef HAVE_TLS
-struct sockaddr_in tls_bind_addr;
-ber_int_t tls_tcps;
+ "\t-P port\tLDAP over TLS Port\n"
+#endif
+ "\t-s level\tSyslog Level\n"
+#ifdef SLAPD_BDB2
+ "\t-t\t\tEnable BDB2 timing\n"
#endif
+#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
+ "\t-u user\tUser (id or name) to ran as\n"
+#endif
+ );
+}
#ifdef HAVE_WINSOCK
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
#endif
{
int i;
- int inetd = 0;
int rc;
- struct slapd_args args;
- int udp;
+ char *urls = NULL;
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
char *username = NULL;
char *groupname = NULL;
#endif
char *serverName;
int serverMode = SLAP_SERVER_MODE;
- int use_tls_port = 0;
- (void) memset( (void*) &bind_addr, '\0', sizeof(bind_addr));
- bind_addr.sin_family = AF_INET;
- bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- bind_addr.sin_port = htons(port);
-#ifdef HAVE_TLS
- tls_bind_addr.sin_family = AF_INET;
- tls_bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- tls_bind_addr.sin_port = htons(tls_port);
-#endif
+ int port = LDAP_PORT;
+ int tls_port = LDAPS_PORT;
g_argc = argc;
g_argv = argv;
#ifdef HAVE_WINSOCK
{
- int *newPort;
- int *newDebugLevel;
+ int *i;
char *newConfigFile;
ldap_debug = 0xffff;
if ( is_NT_Service ) CommenceStartupProcessing( NTservice, slap_set_shutdown );
- newPort = (int*)getRegParam( NULL, "Port" );
- if ( newPort != NULL )
+ i = (int*)getRegParam( NULL, "Port" );
+ if ( i != NULL )
{
- port = *newPort;
- bind_addr.sin_port = htons(port);
+ port = *i;
Debug ( LDAP_DEBUG_ANY, "new port from registry is: %d\n", port, 0, 0 );
}
- newDebugLevel = (int*)getRegParam( NULL, "DebugLevel" );
- if ( newDebugLevel != NULL )
+#ifdef HAVE_TLS
+ i = (int*)getRegParam( NULL, "TLSPort" );
+ if ( i != NULL )
+ {
+ tls_port = *i;
+ Debug ( LDAP_DEBUG_ANY, "new TLS port from registry is: %d\n", tls_port, 0, 0 );
+ }
+#endif
+ i = (int*)getRegParam( NULL, "DebugLevel" );
+ if ( i != NULL )
{
- slap_debug = *newDebugLevel;
+ slap_debug = *i;
Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
}
newConfigFile = (char*)getRegParam( NULL, "ConfigFile" );
#endif
while ( (i = getopt( argc, argv,
- "d:f:ia:p:s:u"
+ "d:f:h:p:s:u"
#ifdef LOG_LOCAL4
"l:"
#endif
"n:"
#endif
#ifdef HAVE_TLS
- "P:T"
+ "P:"
#endif
)) != EOF ) {
switch ( i ) {
- case 'a': /* bind address */
-#ifdef HAVE_WINSOCK
- if(!(bind_addr.sin_addr.S_un.S_addr = inet_addr(optarg)))
-#else
- if(!inet_aton(optarg, &bind_addr.sin_addr))
-#endif
- {
- fprintf(stderr, "invalid address (%s) for -a option", optarg);
- }
-#ifdef HAVE_TLS
-#ifdef HAVE_WINSOCK
- tls_bind_addr.sin_addr.S_un.S_addr = inet_addr(optarg);
-#else
- inet_aton(optarg, &tls_bind_addr.sin_addr);
-#endif
-#endif
+ case 'h': /* listen URLs */
+ urls = ch_strdup( optarg );
break;
#ifdef LDAP_DEBUG
case 'd': /* turn on debugging */
- if ( optarg[0] == '?' ) {
- printf( "Debug levels:\n" );
- printf( "\tLDAP_DEBUG_TRACE\t%d\n",
- LDAP_DEBUG_TRACE );
- printf( "\tLDAP_DEBUG_PACKETS\t%d\n",
- LDAP_DEBUG_PACKETS );
- printf( "\tLDAP_DEBUG_ARGS\t\t%d\n",
- LDAP_DEBUG_ARGS );
- printf( "\tLDAP_DEBUG_CONNS\t%d\n",
- LDAP_DEBUG_CONNS );
- printf( "\tLDAP_DEBUG_BER\t\t%d\n",
- LDAP_DEBUG_BER );
- printf( "\tLDAP_DEBUG_FILTER\t%d\n",
- LDAP_DEBUG_FILTER );
- printf( "\tLDAP_DEBUG_CONFIG\t%d\n",
- LDAP_DEBUG_CONFIG );
- printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
- LDAP_DEBUG_ACL );
- printf( "\tLDAP_DEBUG_STATS\t%d\n",
- LDAP_DEBUG_STATS );
- printf( "\tLDAP_DEBUG_STATS2\t%d\n",
- LDAP_DEBUG_STATS2 );
- printf( "\tLDAP_DEBUG_SHELL\t%d\n",
- LDAP_DEBUG_SHELL );
- printf( "\tLDAP_DEBUG_PARSE\t%d\n",
- LDAP_DEBUG_PARSE );
- printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
- LDAP_DEBUG_ANY );
- exit( 0 );
- } else {
- slap_debug |= atoi( optarg );
- }
+ slap_debug |= atoi( optarg );
break;
#else
case 'd': /* turn on debugging */
configfile = ch_strdup( optarg );
break;
- case 'i': /* run from inetd */
- inetd = 1;
- break;
-
case 'p': { /* port on which to listen */
- port = (short)atoi( optarg );
- if(! port ) {
+ int p = atoi( optarg );
+ if(! p ) {
fprintf(stderr, "-p %s must be numeric\n", optarg);
+ } else if( p < 0 || p >= 1<<16) {
+ fprintf(stderr, "-p %s invalid\n", optarg);
} else {
- bind_addr.sin_port = htons(port);
+ port = p;
}
} break;
#ifdef HAVE_TLS
case 'P': { /* port on which to listen for TLS */
- tls_port = (short)atoi( optarg );
- if(! tls_port ) {
+ int p = atoi( optarg );
+ if(! p ) {
fprintf(stderr, "-P %s must be numeric\n", optarg);
+ } else if( p < 0 || p >= 1<<16) {
+ fprintf(stderr, "-P %s invalid\n", optarg);
} else {
- tls_bind_addr.sin_port = htons(tls_port);
+ tls_port = p;
}
} break;
#endif
#ifdef LOG_LOCAL4
case 'l': /* set syslog local user */
- syslogUser = cnvt_str2int( optarg, syslog_types,
- DEFAULT_SYSLOG_USER );
+ syslogUser = cnvt_str2int( optarg,
+ syslog_types, DEFAULT_SYSLOG_USER );
break;
#endif
groupname = ch_strdup( optarg );
break;
#endif /* SETUID && GETUID */
+
#ifdef HAVE_WINSOCK
case 'n': /* NT service name */
NTservice = ch_strdup( optarg );
break;
-#endif
-#ifdef HAVE_TLS
- case 'T': /* Bind on TLS port */
- use_tls_port = 1;
- break;
#endif
default:
usage( argv[0] );
openlog( serverName, OPENLOG_OPTIONS );
#endif
+ slapd_daemon_init( urls, port, tls_port );
+
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
- if ( username != NULL || groupname != NULL )
+ if ( username != NULL || groupname != NULL ) {
slap_init_user( username, groupname );
+ }
#endif
if ( slap_init( serverMode, serverName ) != 0 ) {
ldap_pvt_tls_init_def_ctx();
#endif
- tcps = set_socket( inetd ? NULL : &bind_addr );
- if ( tcps == -1 )
- goto destroy;
-#ifdef HAVE_TLS
- if ( use_tls_port ) {
- tls_tcps = set_socket( inetd ? NULL : &tls_bind_addr );
- if ( tls_tcps == -1 )
- goto destroy;
- } else {
- tls_tcps = -1;
- }
-#endif
-
(void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing );
(void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown );
#ifdef SIGPIPE
#endif
#ifndef HAVE_WINSOCK
- if(!inetd) {
#ifdef LDAP_DEBUG
lutil_detach( ldap_debug, 0 );
#else
lutil_detach( 0, 0 );
#endif
- }
-#endif /* HAVE_WINSOC */
+#endif /* HAVE_WINSOCK */
if ( slap_startup(-1) != 0 ) {
rc = 1;
goto shutdown;
}
- if(!inetd) {
+ {
FILE *fp;
- args.addr = &bind_addr;
-#ifdef HAVE_TLS
- args.tls_addr = &tls_bind_addr;
-#endif
-
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
if (( slapd_pid_file != NULL ) &&
fprintf( fp, "\n" );
fclose( fp );
}
-
- } else {
- args.addr = NULL;
-#ifdef HAVE_TLS
- args.tls_addr = NULL;
-#endif
}
- args.tcps = tcps;
-#ifdef HAVE_TLS
- args.tls_tcps = tls_tcps;
-#endif
- time( &starttime );
#ifdef HAVE_WINSOCK
- LogSlapdStartedEvent( NTservice, slap_debug, configfile, port, udp );
+ LogSlapdStartedEvent( NTservice, slap_debug, configfile, urls );
#endif
- rc = slapd_daemon( &args );
+ rc = slapd_daemon();
#ifdef HAVE_WINSOCK
/* Throw away the event that we used during the startup process. */
#ifdef HAVE_WINSOCK
LogSlapdStoppedEvent( NTservice );
#endif
+
Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
+
#ifdef HAVE_WINSOCK
ReportSlapdShutdownComplete();
#endif
closelog();
+ slapd_daemon_destroy();
MAIN_RETURN(rc);
}
}
return (retVal);
-
-} /* cnvt_str2int */
+}
#endif /* LOG_LOCAL4 */
Operation *op, Entry *e,
char *attr, struct berval *val, int access ));
-struct acl * acl_get_applicable LDAP_P(( Backend *be,
+AccessControl * acl_get_applicable LDAP_P(( Backend *be,
Operation *op, Entry *e,
char *attr, int nmatches, regmatch_t *matches ));
-int acl_access_allowed LDAP_P(( struct acl *a, Backend *be, Connection *conn, Entry *e,
+int acl_access_allowed LDAP_P((
+ AccessControl *a, Backend *be, Connection *conn, Entry *e,
struct berval *val, Operation *op, int access, char *edn,
regmatch_t *matches ));
long connection_init LDAP_P((
ber_socket_t s,
- const char* name, const char* addr, int use_tls));
+ const char* name, const char* addr,
+ int use_tls ));
void connection_closing LDAP_P(( Connection *c ));
int connection_state_closing LDAP_P(( Connection *c ));
#endif
extern ldap_pvt_thread_mutex_t gmtime_mutex;
-extern struct acl *global_acl;
+extern AccessControl *global_acl;
int slap_init LDAP_P((int mode, char* name));
int slap_startup LDAP_P((int dbnum));
struct sockaddr_in;
-struct slapd_args {
- struct sockaddr_in *addr;
- int tcps;
-#ifdef HAVE_TLS
- struct sockaddr_in *tls_addr;
- int tls_tcps;
-#endif
-};
-
-extern int slapd_daemon LDAP_P((struct slapd_args *args));
-extern int set_socket LDAP_P((struct sockaddr_in *addr));
+extern int slapd_daemon_init( char *urls, int port, int tls_port );
+extern int slapd_daemon_destroy(void);
+extern int slapd_daemon(void);
extern void slapd_set_write LDAP_P((ber_socket_t s, int wake));
extern void slapd_clr_write LDAP_P((ber_socket_t s, int wake));
/* send references in search results */
if( err == LDAP_REFERRAL ) {
err = LDAP_PARTIAL_RESULTS;
- tmp = text = v2ref( refs );
- refs = NULL;
}
+ tmp = text = v2ref( refs );
+ refs = NULL;
+
} else {
/* don't send references in search results */
+ assert( refs == NULL );
+ refs = NULL;
+
if( err == LDAP_REFERRAL ) {
err = LDAP_SUCCESS;
- refs = NULL;
}
}
BerElement *ber;
Attribute *a;
int i, rc=-1, bytes;
- struct acl *acl;
+ AccessControl *acl;
char *edn;
int allattrs;
/*
* represents an attribute value assertion (i.e., attr=value)
*/
-typedef struct ava {
+typedef struct slap_ava {
char *ava_type;
struct berval ava_value;
} Ava;
-typedef struct mra {
+typedef struct slap_mra {
char *mra_rule;
char *mra_type;
char *mra_value;
/*
* represents a search filter
*/
-typedef struct filter {
+typedef struct slap_filter {
ber_tag_t f_choice; /* values taken from ldap.h */
union f_un_u {
Mra f_un_fra;
/* and, or, not */
- struct filter *f_un_complex;
+ struct slap_filter *f_un_complex;
/* substrings */
struct sub {
#define f_sub_any f_un.f_un_sub.f_un_sub_any
#define f_sub_final f_un.f_un_sub.f_un_sub_final
- struct filter *f_next;
+ struct slap_filter *f_next;
} Filter;
/*
* represents an attribute (type + values + syntax)
*/
-typedef struct attr {
+typedef struct slap_attr {
char *a_type;
struct berval **a_vals;
int a_syntax;
- struct attr *a_next;
+ struct slap_attr *a_next;
} Attribute;
/*
* the id used in the indexes to refer to an entry
*/
typedef unsigned long ID;
-#define NOID ((unsigned long)~0)
+#define NOID ((ID)~0)
/*
* represents an entry in core
*/
-typedef struct entry {
+typedef struct slap_entry {
/*
* The ID field should only be changed before entry is
* inserted into a cache. The ID value is backend
*/
/* the "by" part */
-struct access {
+typedef struct slap_access {
#define ACL_NONE 0x0001
#define ACL_AUTH 0x0004
char *a_group_oc;
char *a_group_at;
- struct access *a_next;
-};
+ struct slap_access *a_next;
+} Access;
/* the "to" part */
-struct acl {
+typedef struct slap_acl {
/* "to" part: the entries this acl applies to */
Filter *acl_filter;
regex_t acl_dnre;
char **acl_attrs;
/* "by" part: list of who has what access to the entries */
- struct access *acl_access;
+ Access *acl_access;
- struct acl *acl_next;
-};
+ struct slap_acl *acl_next;
+} AccessControl;
/*
* A list of LDAPMods
* represents a backend
*/
-typedef struct backend_info BackendInfo; /* per backend type */
-typedef struct backend_db BackendDB; /* per backend database */
+typedef struct slap_backend_info BackendInfo; /* per backend type */
+typedef struct slap_backend_db BackendDB; /* per backend database */
extern int nBackendInfo;
extern int nBackendDB;
#define nbackends nBackendDB
#define backends backendDB
-struct backend_db {
+struct slap_backend_db {
BackendInfo *bd_info; /* pointer to shared backend info */
/* BackendInfo accessors */
unsigned int be_max_deref_depth; /* limit for depth of an alias deref */
int be_sizelimit; /* size limit for this backend */
int be_timelimit; /* time limit for this backend */
- struct acl *be_acl; /* access control list for this backend */
+ AccessControl *be_acl; /* access control list for this backend */
int be_dfltaccess; /* access given if no acl matches */
char **be_replica; /* replicas of this backend (in master) */
char *be_replogfile; /* replication log file (in master) */
void *be_private; /* anything the backend database needs */
};
-struct backend_info {
+struct slap_backend_info {
char *bi_type; /* type of backend */
/*
ber_tag_t o_tag; /* tag of the request */
time_t o_time; /* time op was initiated */
- int o_bind_in_progress; /* multi-op bind in progress */
+ int o_bind_in_progress; /* multi-step bind in progress */
char *o_dn; /* dn bound when op was initiated */
char *o_ndn; /* normalized dn bound when op was initiated */
BerElement *c_currentber; /* ber we're attempting to read */
int c_writewaiter; /* true if writer is waiting */
+#ifdef HAVE_TLS
int c_is_tls; /* true if this LDAP over raw TLS */
int c_needs_tls_accept; /* true if SSL_accept should be called */
+#endif
long c_n_ops_received; /* num of ops received (next op_id) */
long c_n_ops_executing; /* num of ops currently executing */
# Name "slapd - Win32 Single Release"
# Begin Source File
-SOURCE=.\daemon.c
-# End Source File
-# Begin Source File
-
SOURCE=.\main.c
# End Source File
# Begin Source File
#include "../slap.h"
#include "../back-ldbm/back-ldbm.h"
-static struct dbcache *openchoice(char c, int mode, int verbose, char **fname);
+static DBCache *openchoice(char c, int mode, int verbose, char **fname);
static void print_entry(FILE *fp, char c, Datum *key, char *klabel, Datum *data, char *dlabel);
-static void free_and_close(struct dbcache *dbc, Datum key, Datum data);
+static void free_and_close(DBCache *dbc, Datum key, Datum data);
static void edit_entry(char c, Datum *data);
static void get_keydata(FILE *fp, char c, Datum *key, Datum *data);
-static struct dbcache *dbc;
+static DBCache *dbc;
static LDBM dbp;
static Backend *be = NULL;
}
static void
-free_and_close( struct dbcache *dbc, Datum key, Datum data )
+free_and_close( DBCache *dbc, Datum key, Datum data )
{
ldbm_cache_really_close( be, dbc );
if ( key.dptr != NULL )
}
#endif
-static struct dbcache *
+static DBCache *
openfile( char *name, int namesiz, int mode, int verbose, char c )
{
- struct dbcache *dbc;
+ DBCache *dbc;
if ( name == NULL || *name == '\0' ) {
if ( c == 'f' ) {
return( dbc );
}
-static struct dbcache *
+static DBCache *
openchoice( char c, int mode, int verbose, char **fname )
{
static char name[MAXPATHLEN];
int lmax, lcur;
int dbnum;
ID id;
- struct dbcache *db, *db2;
+ DBCache *db, *db2;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;
int lmax, lcur;
int dbnum;
ID id;
- struct dbcache *db;
+ DBCache *db;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;