Namespace changes

added slap_ and ldbm_ to many structures
  added typedefs to many structures
  used typedefs
New main.c argument parsing with ldap url support (replacing -a address).
New sockaddr_in handling and support for multiple listeners.
This commit is contained in:
Kurt Zeilenga 1999-07-19 19:40:33 +00:00
parent 543aafd991
commit 170836751a
23 changed files with 544 additions and 481 deletions

View file

@ -38,7 +38,7 @@ access_allowed(
)
{
int rc;
struct acl *a;
AccessControl *a;
char *edn;
regmatch_t matches[MAXREMATCHES];
@ -93,7 +93,7 @@ access_allowed(
* acl_access_allowed().
*/
struct acl *
AccessControl *
acl_get_applicable(
Backend *be,
Operation *op,
@ -104,7 +104,7 @@ acl_get_applicable(
)
{
int i;
struct acl *a;
AccessControl *a;
char *edn;
Debug( LDAP_DEBUG_ACL, "\n=> acl_get: entry (%s) attr (%s)\n",
@ -200,7 +200,7 @@ acl_get_applicable(
int
acl_access_allowed(
struct acl *a,
AccessControl *a,
Backend *be,
Connection *conn,
Entry *e,
@ -212,7 +212,7 @@ acl_access_allowed(
)
{
int i;
struct access *b;
Access *b;
Attribute *at;
struct berval bv;
int default_access;
@ -398,7 +398,7 @@ acl_check_modlist(
)
{
int i;
struct acl *a;
AccessControl *a;
char *edn = e->e_ndn;
for ( ; mlist != NULL; mlist = mlist->ml_next ) {

View file

@ -13,12 +13,12 @@
#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
@ -88,8 +88,8 @@ parse_acl(
{
int i;
char *left, *right;
struct acl *a;
struct access *b;
AccessControl *a;
Access *b;
a = NULL;
for ( i = 1; i < argc; i++ ) {
@ -101,7 +101,7 @@ parse_acl(
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--;
@ -181,7 +181,7 @@ parse_acl(
* 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,
@ -400,7 +400,7 @@ split(
}
static void
access_append( struct access **l, struct access *a )
access_append( Access **l, Access *a )
{
for ( ; *l != NULL; l = &(*l)->a_next )
; /* NULL */
@ -409,7 +409,7 @@ access_append( struct access **l, struct access *a )
}
static void
acl_append( struct acl **l, struct acl *a )
acl_append( AccessControl **l, AccessControl *a )
{
for ( ; *l != NULL; l = &(*l)->acl_next )
; /* NULL */
@ -420,7 +420,7 @@ acl_append( struct acl **l, struct acl *a )
#ifdef LDAP_DEBUG
static void
print_access( struct access *b )
print_access( Access *b )
{
fprintf( stderr, "\tby" );
@ -451,10 +451,10 @@ print_access( struct access *b )
}
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" );

View file

@ -13,7 +13,7 @@
static int
ainfo_type_cmp(
char *type,
struct attrinfo *a
AttrInfo *a
)
{
return( strcasecmp( type, a->ai_type ) );
@ -21,8 +21,8 @@ ainfo_type_cmp(
static int
ainfo_cmp(
struct attrinfo *a,
struct attrinfo *b
AttrInfo *a,
AttrInfo *b
)
{
return( strcasecmp( a->ai_type, b->ai_type ) );
@ -37,8 +37,8 @@ ainfo_cmp(
static int
ainfo_dup(
struct attrinfo *a,
struct attrinfo *b
AttrInfo *a,
AttrInfo *b
)
{
/*
@ -62,13 +62,13 @@ attr_masks(
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;
}
@ -93,14 +93,14 @@ attr_index_config(
{
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 ) {

View file

@ -69,7 +69,7 @@ typedef ID ID_BLOCK;
#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;
@ -77,13 +77,13 @@ struct cache {
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;
@ -91,10 +91,10 @@ struct dbcache {
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
@ -110,7 +110,7 @@ struct attrinfo {
#define SYNTAX_BIN 0x04
... etc. ...
*/
};
} AttrInfo;
#define MAXDBCACHE 10
@ -130,11 +130,11 @@ struct ldbminfo {
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

View file

@ -13,7 +13,7 @@
#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 */
/*
@ -28,14 +28,14 @@ struct ldbm_entry_info {
#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
@ -120,7 +120,7 @@ cache_entry_private_destroy( Entry*e )
}
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;
@ -209,7 +209,7 @@ cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
*/
int
cache_add_entry_rw(
struct cache *cache,
Cache *cache,
Entry *e,
int rw
)
@ -330,7 +330,7 @@ cache_add_entry_rw(
*/
int
cache_update_entry(
struct cache *cache,
Cache *cache,
Entry *e
)
{
@ -430,7 +430,7 @@ cache_update_entry(
ID
cache_find_entry_dn2id(
Backend *be,
struct cache *cache,
Cache *cache,
char *dn
)
{
@ -509,7 +509,7 @@ try_again:
Entry *
cache_find_entry_id(
struct cache *cache,
Cache *cache,
ID id,
int rw
)
@ -608,7 +608,7 @@ try_again:
*/
int
cache_delete_entry(
struct cache *cache,
Cache *cache,
Entry *e
)
{
@ -631,7 +631,7 @@ cache_delete_entry(
static int
cache_delete_entry_internal(
struct cache *cache,
Cache *cache,
Entry *e
)
{
@ -670,7 +670,7 @@ cache_delete_entry_internal(
#ifdef SLAP_CLEANUP
void
cache_release_all( struct cache *cache )
cache_release_all( Cache *cache )
{
Entry *e;
int rc;
@ -703,7 +703,7 @@ cache_release_all( struct cache *cache )
#ifdef LDAP_DEBUG
static void
lru_print( struct cache *cache )
lru_print( Cache *cache )
{
Entry *e;

View file

@ -19,7 +19,7 @@
#include "slap.h"
#include "back-ldbm.h"
struct dbcache *
DBCache *
ldbm_cache_open(
Backend *be,
char *name,
@ -127,7 +127,7 @@ ldbm_cache_open(
}
void
ldbm_cache_close( Backend *be, struct dbcache *db )
ldbm_cache_close( Backend *be, DBCache *db )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
@ -139,7 +139,7 @@ ldbm_cache_close( Backend *be, struct dbcache *db )
}
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;
@ -188,7 +188,7 @@ ldbm_cache_flush_all( Backend *be )
Datum
ldbm_cache_fetch(
struct dbcache *db,
DBCache *db,
Datum key
)
{
@ -203,7 +203,7 @@ ldbm_cache_fetch(
int
ldbm_cache_store(
struct dbcache *db,
DBCache *db,
Datum key,
Datum data,
int flags
@ -236,7 +236,7 @@ ldbm_cache_store(
int
ldbm_cache_delete(
struct dbcache *db,
DBCache *db,
Datum key
)
{

View file

@ -19,7 +19,7 @@ dn2id_add(
)
{
int rc, flags;
struct dbcache *db;
DBCache *db;
Datum key, data;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
@ -62,7 +62,7 @@ dn2id(
)
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
struct dbcache *db;
DBCache *db;
ID id;
Datum key, data;
@ -116,7 +116,7 @@ dn2id_delete(
char *dn
)
{
struct dbcache *db;
DBCache *db;
Datum key;
int rc;

View file

@ -17,7 +17,7 @@ id2children_add(
Entry *e
)
{
struct dbcache *db;
DBCache *db;
Datum key;
char buf[20];
@ -59,7 +59,7 @@ id2children_remove(
Entry *e
)
{
struct dbcache *db;
DBCache *db;
Datum key;
char buf[20];
@ -105,7 +105,7 @@ has_children(
Entry *p
)
{
struct dbcache *db;
DBCache *db;
Datum key;
int rc = 0;
ID_BLOCK *idl;

View file

@ -18,7 +18,7 @@ int
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;
@ -60,7 +60,7 @@ int
id2entry_delete( Backend *be, Entry *e )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
struct dbcache *db;
DBCache *db;
Datum key;
int rc;
@ -104,7 +104,7 @@ Entry *
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;

View file

@ -61,7 +61,7 @@ idl_free( ID_BLOCK *idl )
static ID_BLOCK *
idl_fetch_one(
Backend *be,
struct dbcache *db,
DBCache *db,
Datum key
)
{
@ -97,7 +97,7 @@ idl_fetch_one(
ID_BLOCK *
idl_fetch(
Backend *be,
struct dbcache *db,
DBCache *db,
Datum key
)
{
@ -191,7 +191,7 @@ idl_fetch(
static int
idl_store(
Backend *be,
struct dbcache *db,
DBCache *db,
Datum key,
ID_BLOCK *idl
)
@ -277,7 +277,7 @@ idl_split_block(
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 */
@ -321,7 +321,7 @@ idl_change_first(
int
idl_insert_key(
Backend *be,
struct dbcache *db,
DBCache *db,
Datum key,
ID id
)
@ -662,7 +662,7 @@ idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
int
idl_delete_key (
Backend *be,
struct dbcache *db,
DBCache *db,
Datum key,
ID id
)

View file

@ -11,13 +11,13 @@
#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
@ -116,7 +116,7 @@ index_read(
char *val
)
{
struct dbcache *db;
DBCache *db;
Datum key;
ID_BLOCK *idl;
int indexmask, syntax;
@ -188,12 +188,12 @@ index_read(
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;
@ -257,10 +257,10 @@ index_change_values(
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;

View file

@ -39,31 +39,31 @@ void attr_index_destroy LDAP_P(( Avlnode *tree ));
* 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
@ -114,10 +114,10 @@ Entry * id2entry_rw LDAP_P(( Backend *be, ID id, int rw ));
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 ));
@ -130,7 +130,8 @@ ID idl_nextid LDAP_P(( ID_BLOCK *idl, ID id ));
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
@ -164,8 +165,9 @@ int index_change_values LDAP_P(( Backend *be,
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

View file

@ -21,7 +21,7 @@
*/
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;
@ -45,8 +45,10 @@ read_config( char *fname )
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;

View file

@ -273,12 +273,16 @@ long connection_init(
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",
@ -394,10 +398,12 @@ long connection_init(
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 );

View file

@ -21,24 +21,26 @@ int deny_severity = LOG_NOTICE;
#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;
@ -64,12 +66,10 @@ static
#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;
@ -194,13 +194,183 @@ static void slapd_close(ber_socket_t s) {
}
int
set_socket( struct sockaddr_in *addr )
Listener *
open_listener(
char* url,
int port,
int tls_port )
{
ber_socket_t tcps = AC_SOCKET_INVALID;
int tmp, rc;
Listener l;
Listener *li;
LDAPURLDesc *lud;
if ( !daemon_initialized ) sockinit();
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 );
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 )
{
int i, rc;
char **u;
#ifndef HAVE_TLS
assert( tls_port == 0 );
#endif
if( rc = sockinit() ) {
return rc;
}
#ifdef HAVE_SYSCONF
dtblsize = sysconf( _SC_OPEN_MAX );
@ -216,133 +386,82 @@ set_socket( struct sockaddr_in *addr )
}
#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;
return tcps;
charray_free( u );
ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
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
time( &starttime );
inetd = ( listeners[0].addr == NULL);
if ( !daemon_initialized ) sockinit();
for ( l = 0; slap_listeners[l] != NULL; l++ ) {
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
continue;
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 );
}
} 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. */
@ -401,10 +520,10 @@ slapd_daemon_task(
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
@ -425,13 +544,14 @@ slapd_daemon_task(
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,
@ -482,23 +602,24 @@ slapd_daemon_task(
/* 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 )
continue;
if ( !FD_ISSET( listeners[l].tcps, &readfds ) )
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
continue;
if ( (s = accept( listeners[l].tcps,
if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
continue;
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;
@ -580,7 +701,13 @@ slapd_daemon_task(
#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,
@ -617,8 +744,8 @@ slapd_daemon_task(
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;
}
@ -655,8 +782,8 @@ slapd_daemon_task(
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;
}
@ -700,8 +827,8 @@ slapd_daemon_task(
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;
}
@ -744,9 +871,10 @@ slapd_daemon_task(
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;
}
}
@ -763,12 +891,10 @@ slapd_daemon_task(
}
int slapd_daemon( struct slapd_args *args )
int slapd_daemon( void )
{
int rc;
if ( !daemon_initialized ) sockinit();
connections_init();
#define SLAPD_LISTENER_THREAD 1
@ -776,12 +902,12 @@ int slapd_daemon( struct slapd_args *args )
/* 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 */
@ -789,23 +915,15 @@ int slapd_daemon( struct slapd_args *args )
#else
/* expermimental code */
listener_tid = pthread_self();
slapd_daemon_task( args );
slapd_daemon_task( NULL );
#endif
rc = 0;
return 0;
destory:
connections_destroy();
#ifdef HAVE_WINSOCK
WSACleanup( );
#endif
return rc;
}
#ifdef HAVE_WINSOCK2
void sockinit()
int sockinit(void)
{
WORD wVersionRequested;
WSADATA wsaData;
@ -817,7 +935,7 @@ void sockinit()
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.*/
@ -831,13 +949,21 @@ void sockinit()
{
/* 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;
@ -867,17 +993,27 @@ void hit_socket()
}
#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;
}
#else
void sockinit()
static int sockdestroy(void)
{
daemon_initialized = 1;
WSACleanup();
return 0;
}
#else
static int sockinit(void)
{
return 0;
}
static int sockdestroy(void)
{
return 0;
}
#endif
@ -895,9 +1031,9 @@ slap_set_shutdown( int sig )
/* 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

View file

@ -29,7 +29,7 @@ extern SERVICE_STATUS_HANDLE hSLAPDServiceStatus;
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,
@ -48,10 +48,6 @@ void *getRegParam( char *svc, char *value );
#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
@ -94,34 +90,39 @@ static int cnvt_str2int( char *, STRDISP_P, int );
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
#ifdef HAVE_WINSOCK
"\t-n NTserviceName\tNT service name\n"
#endif
"\t-p port\tLDAP Port\n"
#ifdef HAVE_TLS
"\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)
fprintf( stderr, " [-u user] [-g group]" );
"\t-u user\tUser (id or name) to ran as\n"
#endif
fprintf( stderr, "\n" );
);
}
time_t starttime;
struct sockaddr_in bind_addr;
ber_int_t tcps;
#ifdef HAVE_TLS
struct sockaddr_in tls_bind_addr;
ber_int_t tls_tcps;
#endif
#ifdef HAVE_WINSOCK
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
#else
@ -129,10 +130,8 @@ int main( int argc, char **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;
@ -148,39 +147,37 @@ int main( int argc, char **argv )
#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 )
{
slap_debug = *newDebugLevel;
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 = *i;
Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
}
newConfigFile = (char*)getRegParam( NULL, "ConfigFile" );
@ -193,7 +190,7 @@ int main( int argc, char **argv )
#endif
while ( (i = getopt( argc, argv,
"d:f:ia:p:s:u"
"d:f:h:p:s:u"
#ifdef LOG_LOCAL4
"l:"
#endif
@ -210,62 +207,17 @@ int main( int argc, char **argv )
"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 */
@ -278,26 +230,26 @@ int main( int argc, char **argv )
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
@ -308,8 +260,8 @@ int main( int argc, char **argv )
#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
@ -336,15 +288,11 @@ int main( int argc, char **argv )
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] );
@ -372,9 +320,12 @@ int main( int argc, char **argv )
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 ) {
@ -394,19 +345,6 @@ int main( int argc, char **argv )
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
@ -426,14 +364,12 @@ int main( int argc, char **argv )
#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;
@ -441,14 +377,9 @@ int main( int argc, char **argv )
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 ) &&
@ -467,24 +398,13 @@ int main( int argc, char **argv )
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. */
@ -503,12 +423,15 @@ stop:
#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);
}
@ -568,7 +491,6 @@ cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
}
return (retVal);
} /* cnvt_str2int */
}
#endif /* LOG_LOCAL4 */

View file

@ -13,11 +13,12 @@ int access_allowed LDAP_P(( Backend *be, Connection *conn,
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 ));
@ -147,7 +148,8 @@ int connections_timeout_idle LDAP_P((time_t));
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 ));
@ -398,7 +400,7 @@ extern ldap_pvt_thread_mutex_t crypt_mutex;
#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));
@ -407,17 +409,9 @@ int slap_destroy LDAP_P((void));
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));

View file

@ -441,15 +441,18 @@ send_search_result(
/* 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;
}
}
@ -494,7 +497,7 @@ send_search_entry(
BerElement *ber;
Attribute *a;
int i, rc=-1, bytes;
struct acl *acl;
AccessControl *acl;
char *edn;
int allattrs;

View file

@ -80,12 +80,12 @@ struct slap_conn;
/*
* 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;
@ -95,7 +95,7 @@ typedef struct mra {
/*
* 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 {
@ -109,7 +109,7 @@ typedef struct filter {
Mra f_un_fra;
/* and, or, not */
struct filter *f_un_complex;
struct slap_filter *f_un_complex;
/* substrings */
struct sub {
@ -137,17 +137,17 @@ typedef struct filter {
#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;
/*
@ -164,12 +164,12 @@ typedef struct attr {
* 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
@ -190,7 +190,7 @@ typedef struct entry {
*/
/* the "by" part */
struct access {
typedef struct slap_access {
#define ACL_NONE 0x0001
#define ACL_AUTH 0x0004
@ -240,11 +240,11 @@ struct access {
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;
@ -252,10 +252,10 @@ struct acl {
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
@ -346,8 +346,8 @@ typedef struct slap_object_class {
* 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;
@ -368,7 +368,7 @@ typedef BackendDB Backend;
#define nbackends nBackendDB
#define backends backendDB
struct backend_db {
struct slap_backend_db {
BackendInfo *bd_info; /* pointer to shared backend info */
/* BackendInfo accessors */
@ -401,7 +401,7 @@ struct backend_db {
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) */
@ -414,7 +414,7 @@ struct backend_db {
void *be_private; /* anything the backend database needs */
};
struct backend_info {
struct slap_backend_info {
char *bi_type; /* type of backend */
/*
@ -537,7 +537,7 @@ typedef struct slap_op {
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 */
@ -601,8 +601,10 @@ typedef struct slap_conn {
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 */

View file

@ -139,10 +139,6 @@ LINK32=link.exe
# 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

View file

@ -31,13 +31,13 @@
#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;
@ -373,7 +373,7 @@ main( int argc, char **argv )
}
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 )
@ -570,10 +570,10 @@ edit_entry( char c, Datum *data )
}
#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' ) {
@ -599,7 +599,7 @@ openfile( char *name, int namesiz, int mode, int verbose, char c )
return( dbc );
}
static struct dbcache *
static DBCache *
openchoice( char c, int mode, int verbose, char **fname )
{
static char name[MAXPATHLEN];

View file

@ -37,7 +37,7 @@ main( int argc, char **argv )
int lmax, lcur;
int dbnum;
ID id;
struct dbcache *db, *db2;
DBCache *db, *db2;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;

View file

@ -34,7 +34,7 @@ main( int argc, char **argv )
int lmax, lcur;
int dbnum;
ID id;
struct dbcache *db;
DBCache *db;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;