1998-08-09 08:43:13 +08:00
|
|
|
/* init.c - initialize various things */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-07 07:07:46 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
2002-08-23 16:49:19 +08:00
|
|
|
#include "lber_pvt.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-12 02:36:40 +08:00
|
|
|
/*
|
|
|
|
* read-only global variables or variables only written by the listener
|
|
|
|
* thread (after they are initialized) - no need to protect them with a mutex.
|
|
|
|
*/
|
|
|
|
int slap_debug = 0;
|
|
|
|
|
|
|
|
#ifdef LDAP_DEBUG
|
|
|
|
int ldap_syslog = LDAP_DEBUG_STATS;
|
|
|
|
#else
|
|
|
|
int ldap_syslog;
|
|
|
|
#endif
|
|
|
|
|
1999-11-02 05:25:22 +08:00
|
|
|
#ifdef LOG_DEBUG
|
1999-01-12 02:36:40 +08:00
|
|
|
int ldap_syslog_level = LOG_DEBUG;
|
1999-11-02 05:25:22 +08:00
|
|
|
#endif
|
|
|
|
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray default_referral = NULL;
|
1999-01-12 02:36:40 +08:00
|
|
|
|
2002-08-23 16:49:19 +08:00
|
|
|
struct berval AllUser = BER_BVC( LDAP_ALL_USER_ATTRIBUTES );
|
|
|
|
struct berval AllOper = BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES );
|
|
|
|
struct berval NoAttrs = BER_BVC( LDAP_NO_ATTRS );
|
|
|
|
|
1999-01-12 02:36:40 +08:00
|
|
|
/*
|
|
|
|
* global variables that need mutex protection
|
|
|
|
*/
|
2000-06-08 03:27:33 +08:00
|
|
|
ldap_pvt_thread_pool_t connection_pool;
|
2001-12-10 17:50:06 +08:00
|
|
|
int connection_pool_max = SLAP_MAX_WORKER_THREADS;
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_t gmtime_mutex;
|
2000-10-10 03:09:28 +08:00
|
|
|
#if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
|
2000-09-20 08:28:57 +08:00
|
|
|
ldap_pvt_thread_mutex_t passwd_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
#endif
|
|
|
|
|
2002-04-09 02:41:15 +08:00
|
|
|
unsigned long num_ops_initiated = 0;
|
|
|
|
unsigned long num_ops_completed = 0;
|
2002-04-09 03:13:13 +08:00
|
|
|
#ifdef SLAPD_MONITOR
|
|
|
|
unsigned long num_ops_initiated_[SLAP_OP_LAST];
|
2002-04-09 02:41:15 +08:00
|
|
|
unsigned long num_ops_completed_[SLAP_OP_LAST];
|
2002-04-09 03:13:13 +08:00
|
|
|
#endif /* SLAPD_MONITOR */
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_t num_ops_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
|
2001-12-27 07:26:55 +08:00
|
|
|
unsigned long num_entries_sent;
|
|
|
|
unsigned long num_refs_sent;
|
|
|
|
unsigned long num_bytes_sent;
|
|
|
|
unsigned long num_pdu_sent;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_t num_sent_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
/*
|
|
|
|
* these mutexes must be used when calling the entry2str()
|
|
|
|
* routine since it returns a pointer to static data.
|
|
|
|
*/
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_t entry2str_mutex;
|
|
|
|
ldap_pvt_thread_mutex_t replog_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
static const char* slap_name = NULL;
|
1999-02-08 19:42:14 +08:00
|
|
|
int slapMode = SLAP_UNDEFINED_MODE;
|
1999-02-05 17:03:47 +08:00
|
|
|
|
2002-08-29 22:39:31 +08:00
|
|
|
/*
|
|
|
|
* all known control OIDs should be added to this list
|
|
|
|
*/
|
|
|
|
char *slap_known_controls[] = {
|
|
|
|
#ifdef LDAP_CONTROL_REFERRALS
|
|
|
|
LDAP_CONTROL_REFERRALS,
|
|
|
|
#endif /* LDAP_CONTROL_REFERRALS */
|
|
|
|
|
|
|
|
LDAP_CONTROL_MANAGEDSAIT,
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_SUBENTRIES
|
|
|
|
LDAP_CONTROL_SUBENTRIES,
|
|
|
|
#endif /* LDAP_CONTROL_SUBENTRIES */
|
|
|
|
|
|
|
|
LDAP_CONTROL_NOOP,
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_DUPENT_REQUEST
|
|
|
|
LDAP_CONTROL_DUPENT_REQUEST,
|
|
|
|
#endif /* LDAP_CONTROL_DUPENT_REQUEST */
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_DUPENT_RESPONSE
|
|
|
|
LDAP_CONTROL_DUPENT_RESPONSE,
|
|
|
|
#endif /* LDAP_CONTROL_DUPENT_RESPONSE */
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_DUPENT_ENTRY
|
|
|
|
LDAP_CONTROL_DUPENT_ENTRY,
|
|
|
|
#endif /* LDAP_CONTROL_DUPENT_ENTRY */
|
|
|
|
|
|
|
|
LDAP_CONTROL_PAGEDRESULTS,
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_SORTREQUEST
|
|
|
|
LDAP_CONTROL_SORTREQUEST,
|
|
|
|
#endif /* LDAP_CONTROL_SORTREQUEST */
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_SORTRESPONSE
|
|
|
|
LDAP_CONTROL_SORTRESPONSE,
|
|
|
|
#endif /* LDAP_CONTROL_SORTRESPONSE */
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_VLVREQUEST
|
|
|
|
LDAP_CONTROL_VLVREQUEST,
|
|
|
|
#endif /* LDAP_CONTROL_VLVREQUEST */
|
|
|
|
|
|
|
|
#ifdef LDAP_CONTROL_VLVRESPONSE
|
|
|
|
LDAP_CONTROL_VLVRESPONSE,
|
|
|
|
#endif /* LDAP_CONTROL_VLVRESPONSE */
|
|
|
|
|
|
|
|
LDAP_CONTROL_VALUESRETURNFILTER,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
int
|
2000-05-22 11:46:57 +08:00
|
|
|
slap_init( int mode, const char *name )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-02-05 17:03:47 +08:00
|
|
|
int rc;
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
assert( mode );
|
|
|
|
|
1999-02-08 19:42:14 +08:00
|
|
|
if( slapMode != SLAP_UNDEFINED_MODE ) {
|
2001-01-16 03:17:29 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, CRIT,
|
|
|
|
"init: %s init called twice (old=%d, new=%d)\n",
|
|
|
|
name, slapMode, mode );
|
2001-01-16 03:17:29 +08:00
|
|
|
#else
|
1999-02-05 17:03:47 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2001-01-18 00:35:53 +08:00
|
|
|
"%s init: init called twice (old=%d, new=%d)\n",
|
|
|
|
name, slapMode, mode );
|
2001-01-16 03:17:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
slapMode = mode;
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
switch ( slapMode & SLAP_MODE ) {
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TOOL_MODE:
|
2001-01-16 03:17:29 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, DETAIL1,
|
|
|
|
"init: %s initiation, initiated %s.\n",
|
|
|
|
name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ?
|
|
|
|
"tool" : "server", 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#else
|
1999-02-12 22:36:16 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-05-16 00:33:07 +08:00
|
|
|
"%s init: initiated %s.\n", name,
|
2000-05-16 00:53:05 +08:00
|
|
|
(mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
|
2000-05-16 00:33:07 +08:00
|
|
|
0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
slap_name = name;
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
(void) ldap_pvt_thread_initialize();
|
2000-06-13 10:42:13 +08:00
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
|
1999-01-28 12:34:55 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &entry2str_mutex );
|
|
|
|
ldap_pvt_thread_mutex_init( &replog_mutex );
|
1999-03-26 10:51:33 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &num_ops_mutex );
|
1999-02-12 22:36:16 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &num_sent_mutex );
|
1999-03-22 15:14:54 +08:00
|
|
|
|
2002-04-10 07:54:45 +08:00
|
|
|
#ifdef SLAPD_MONITOR
|
2002-04-09 02:41:15 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for ( i = 0; i < SLAP_OP_LAST; i++ ) {
|
|
|
|
num_ops_initiated_[ i ] = 0;
|
|
|
|
num_ops_completed_[ i ] = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-04-10 07:54:45 +08:00
|
|
|
#endif
|
2002-04-09 02:41:15 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &gmtime_mutex );
|
2000-10-10 03:09:28 +08:00
|
|
|
#if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
|
2000-09-20 08:28:57 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &passwd_mutex );
|
1998-12-30 05:45:08 +08:00
|
|
|
#endif
|
1999-02-05 17:03:47 +08:00
|
|
|
|
2000-07-14 06:54:38 +08:00
|
|
|
rc = slap_sasl_init();
|
|
|
|
|
|
|
|
if( rc == 0 ) {
|
|
|
|
rc = backend_init( );
|
|
|
|
}
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-01-16 03:17:29 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, ERR,
|
|
|
|
"init: %s init, undefined mode (%d).\n", name, mode, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#else
|
1999-02-12 22:36:16 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2001-01-18 00:35:53 +08:00
|
|
|
"%s init: undefined mode (%d).\n", name, mode, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
int slap_startup( Backend *be )
|
1999-02-05 17:03:47 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-01-16 03:17:29 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, CRIT, "slap_startup: %s started\n", slap_name, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#else
|
1999-02-05 17:03:47 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s startup: initiated.\n",
|
|
|
|
slap_name, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
rc = backend_startup( be );
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
int slap_shutdown( Backend *be )
|
1999-02-05 17:03:47 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-01-16 03:17:29 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, CRIT,
|
|
|
|
"slap_shutdown: %s shutdown initiated.\n", slap_name, 0, 0);
|
2001-01-16 03:17:29 +08:00
|
|
|
#else
|
1999-02-05 17:03:47 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s shutdown: initiated\n",
|
|
|
|
slap_name, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
|
2000-07-14 06:54:38 +08:00
|
|
|
slap_sasl_destroy();
|
1999-08-04 07:23:05 +08:00
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
/* let backends do whatever cleanup they need to do */
|
1999-08-18 03:00:59 +08:00
|
|
|
rc = backend_shutdown( be );
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
int slap_destroy(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2001-01-16 03:17:29 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, INFO,
|
|
|
|
"slap_destroy: %s freeing system resources.\n", slap_name, 0, 0);
|
2001-01-16 03:17:29 +08:00
|
|
|
#else
|
1999-02-05 17:03:47 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s shutdown: freeing system resources.\n",
|
|
|
|
slap_name, 0, 0 );
|
2001-01-16 03:17:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
rc = backend_destroy();
|
|
|
|
|
1999-08-20 01:06:28 +08:00
|
|
|
entry_destroy();
|
|
|
|
|
1999-04-07 05:57:16 +08:00
|
|
|
ldap_pvt_thread_destroy();
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
/* should destory the above mutex */
|
|
|
|
return rc;
|
|
|
|
}
|