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
|
|
|
/*
|
2000-05-13 10:47:56 +08:00
|
|
|
* Copyright 1998-2000 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"
|
|
|
|
|
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
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
struct berval **default_referral = NULL;
|
1999-01-12 02:36:40 +08:00
|
|
|
int g_argc;
|
|
|
|
char **g_argv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* global variables that need mutex protection
|
|
|
|
*/
|
|
|
|
int active_threads;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_t active_threads_mutex;
|
|
|
|
ldap_pvt_thread_cond_t active_threads_cond;
|
1999-01-12 02:36:40 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_t gmtime_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
#ifdef SLAPD_CRYPT
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_t crypt_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int num_conns;
|
1999-03-26 10:51:33 +08:00
|
|
|
long num_ops_initiated;
|
|
|
|
long num_ops_completed;
|
|
|
|
ldap_pvt_thread_mutex_t num_ops_mutex;
|
1999-01-12 02:36:40 +08:00
|
|
|
|
|
|
|
long num_entries_sent;
|
1999-07-16 10:45:46 +08:00
|
|
|
long num_refs_sent;
|
1999-01-12 02:36:40 +08:00
|
|
|
long num_bytes_sent;
|
1999-07-16 10:45:46 +08:00
|
|
|
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
|
|
|
|
1999-09-16 10:31:29 +08:00
|
|
|
static 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
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
static ldap_pvt_thread_mutex_t currenttime_mutex;
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
int
|
|
|
|
slap_init( int mode, 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 ) {
|
1999-02-05 17:03:47 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s init: init called twice (old=%d, new=%d)\n",
|
|
|
|
name, slapMode, mode );
|
|
|
|
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:
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-05-16 00:33:07 +08:00
|
|
|
"%s init: initiated %s.\n", name,
|
|
|
|
(mode & SLAP_MODE) == SLAPD_TOOL_MODE ? "tool" : "server",
|
|
|
|
0 );
|
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();
|
1999-01-28 12:34:55 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &active_threads_mutex );
|
|
|
|
ldap_pvt_thread_cond_init( &active_threads_cond );
|
1999-01-28 12:34:55 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
ldap_pvt_thread_mutex_init( ¤ttime_mutex );
|
|
|
|
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
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_init( &gmtime_mutex );
|
1998-12-30 05:45:08 +08:00
|
|
|
#ifdef SLAPD_CRYPT
|
1999-02-12 22:36:16 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &crypt_mutex );
|
1998-12-30 05:45:08 +08:00
|
|
|
#endif
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
rc = backend_init( );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s init: undefined mode (%d).\n", name, mode, 0 );
|
|
|
|
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;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s startup: initiated.\n",
|
|
|
|
slap_name, 0, 0 );
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
rc = backend_startup( be );
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-08-04 07:23:05 +08:00
|
|
|
if( rc == 0 ) {
|
|
|
|
rc = sasl_init();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s shutdown: initiated\n",
|
|
|
|
slap_name, 0, 0 );
|
|
|
|
|
1999-08-04 07:23:05 +08:00
|
|
|
sasl_destroy();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s shutdown: freeing system resources.\n",
|
|
|
|
slap_name, 0, 0 );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
/* should create a utils.c for these */
|
|
|
|
time_t slap_get_time(void)
|
|
|
|
{
|
|
|
|
time_t t;
|
|
|
|
ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
|
1999-03-22 15:38:27 +08:00
|
|
|
time( &t );
|
1999-03-22 15:14:54 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
|
|
|
|
return t;
|
|
|
|
}
|