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
|
|
|
|
*/
|
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
|
|
|
|
|
2001-12-27 07:26:55 +08:00
|
|
|
unsigned long num_ops_initiated;
|
|
|
|
unsigned long num_ops_completed;
|
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
|
|
|
|
|
|
|
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
|
2001-01-18 00:35:53 +08:00
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_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
|
2001-01-18 00:35:53 +08:00
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
|
|
|
|
"init: %s initiation, initiated %s.\n",
|
|
|
|
name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server" ));
|
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
|
|
|
|
|
|
|
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
|
2001-01-18 00:35:53 +08:00
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
|
|
|
|
"init: %s init, undefined mode (%d).\n", name, mode ));
|
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
|
2001-01-18 00:35:53 +08:00
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
|
|
|
|
"slap_startup: %s started\n", slap_name ));
|
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
|
2001-01-18 00:35:53 +08:00
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
|
|
|
|
"slap_shutdown: %s shutdown initiated.\n", slap_name));
|
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
|
2001-01-18 00:35:53 +08:00
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
|
|
|
|
"slap_destroy: %s freeing system resources.\n",
|
|
|
|
slap_name ));
|
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;
|
|
|
|
}
|