From 6a8857a89a8f3cdf9905235c78e21908ac4093dc Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 20 Jan 1999 01:26:03 +0000 Subject: [PATCH] Import Ksp's improved slapd logging & args/pid options --- CHANGES | 2 + doc/man/man8/slapd.8 | 50 ++++++++++++++++-- include/ldapconfig.h.edit | 10 ++-- include/ldapconfig.h.nt | 12 ++--- servers/slapd/daemon.c | 31 +++++++++-- servers/slapd/main.c | 108 +++++++++++++++++++++++++++++++++++--- 6 files changed, 186 insertions(+), 27 deletions(-) diff --git a/CHANGES b/CHANGES index e9e54e8212..a094fe6c4b 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,8 @@ Changes included in OpenLDAP 1.2 Add ldappasswd() tool Add salted MD5/SHA1 password support Add client/tools password prompting (-W) + Add slapd logging option + Add slapd alternative args/pid file locations Fix lber leaking ber_scanf Update client/tools Kerberos option handling diff --git a/doc/man/man8/slapd.8 b/doc/man/man8/slapd.8 index be0c97d3bf..85f3aa830a 100644 --- a/doc/man/man8/slapd.8 +++ b/doc/man/man8/slapd.8 @@ -1,10 +1,10 @@ -.TH SLAPD 8C "6 November 1995" "U-M LDAP LDVERSION" +.TH SLAPD 8C "22 September 1998" "OpenLDAP LDVERSION" .SH NAME slapd \- Stand-alone LDAP Daemon .SH SYNOPSIS -.B ETCDIR/slapd [\-d debug\-level] +.B LIBEXECDIR/slapd [\-d debug\-level] .B [\-f slapd\-config\-file] [\-p port\-number] -.B [\-s syslog\-level] [\-i] +.B [\-s syslog\-level] [\-l syslog\-local\-user] [\-i] .B .SH DESCRIPTION .LP @@ -18,6 +18,26 @@ is typically invoked at boot time, usually out of Upon startup, .B slapd normally forks and disassociates itself from the invoking tty. +In this case, the +.B slapd +process will print its process ID to a +.B .pid +file ( see +.BR getpid (2) +), as well as the command line options during invocation to an +.B .args +file. By default, these files are located in the directory +.B LOCALSTATEDIR. +The files' base names are derived from the +.B slapd +binary name, making it possible to run several +.B slapd +servers with differet names on the same machine, with each having +its own +.B .pid/.args +files. (Those +.B slapd +names might be obtained via symbolic links to one binary file.) If the .B \-d flag is given and debugging is set to some non-zero @@ -55,6 +75,21 @@ at what level debugging statements should be logged to the .BR syslog (8) facility. .TP +.BI \-l " syslog\-local\-user" +Selects the local user of the +.BR syslog (8) +facility. Values can be +.BR LOCAL0 , +.BR LOCAL1 , +and so on, up to +.BR LOCAL7 . +The default is +.BR LOCAL4 . +However, this option is only permitted on systems that support +local users with the +.BR syslog (8) +facility. +.TP .BI \-f " slapd\-config\-file" Specifies the slapd configuration file. The default is .BR ETCDIR/slapd.conf . @@ -78,7 +113,7 @@ the LDAP databases defined in the default config file, just type: .LP .nf .ft tt - ETCDIR/slapd + LIBEXECDIR/slapd .ft .fi .LP @@ -89,7 +124,7 @@ on voluminous debugging which will be printed on standard error, type: .LP .nf .ft tt - ETCDIR/slapd -f /usr/local/slapd/slapd.conf -d 255 + LIBEXECDIR/slapd -f ETCDIR/slapd.conf -d 255 .ft .fi .LP @@ -102,3 +137,8 @@ on voluminous debugging which will be printed on standard error, type: .SH BUGS When using the LDBM database backend, the Modify RDN operation does not update the attribute values in the entry that are affected by the change. +.SH ACKNOWLEDGEMENTS +.B OpenLDAP +is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). +.B OpenLDAP +is derived from University of Michigan LDAP 3.3 Release. diff --git a/include/ldapconfig.h.edit b/include/ldapconfig.h.edit index 4acdfd8cd4..ff3233768a 100644 --- a/include/ldapconfig.h.edit +++ b/include/ldapconfig.h.edit @@ -31,11 +31,13 @@ /* * SHARED DEFINITIONS - things you should change */ +#define DEFAULT_DIRSEP "/" #define DEFAULT_BINDIR "%BINDIR%" #define DEFAULT_SBINDIR "%SBINDIR%" #define DEFAULT_DATADIR "%DATADIR%" #define DEFAULT_SYSCONFDIR "%SYSCONFDIR%" #define DEFAULT_LIBEXECDIR "%LIBEXECDIR%" +#define DEFAULT_RUNDIR "%RUNDIR%" #define DEFAULT_LDAP_CONF_FILE "%SYSCONFDIR%/ldap.conf" #define DEFAULT_LDAP_USERRC_FILE "ldaprc" @@ -213,10 +215,10 @@ Please try again later.\r\n" #define SLAPD_DEFAULT_SIZELIMIT 500 /* default timelimit to spend on a search */ #define SLAPD_DEFAULT_TIMELIMIT 3600 - /* location of the slapd pid file */ -#define SLAPD_PIDFILE "%RUNDIR%/slapd.pid" - /* location of the slapd args file */ -#define SLAPD_ARGSFILE "%RUNDIR%/slapd.args" + /* extension of the slapd pid file */ +#define SLAPD_PIDEXT ".pid" + /* extension of the slapd args file */ +#define SLAPD_ARGSEXT ".args" /* dn of the special "monitor" entry */ #define SLAPD_MONITOR_DN "cn=monitor" /* dn of the special "config" entry */ diff --git a/include/ldapconfig.h.nt b/include/ldapconfig.h.nt index 94881f0082..4590031ed0 100644 --- a/include/ldapconfig.h.nt +++ b/include/ldapconfig.h.nt @@ -31,9 +31,7 @@ /* * SHARED DEFINITIONS - things you should change */ -/* - * SHARED DEFINITIONS - things you should change - */ +#define DEFAULT_DIRSEP "\\" #define DEFAULT_BINDIR "C:\\OpenLDAP\\bin" #define DEFAULT_SBINDIR "C:\\OpenLDAP\\sbin" #define DEFAULT_DATADIR "C:\\OpenLDAP\\share" @@ -217,10 +215,10 @@ Please try again later.\r\n" #define SLAPD_DEFAULT_SIZELIMIT 500 /* default timelimit to spend on a search */ #define SLAPD_DEFAULT_TIMELIMIT 3600 - /* location of the slapd pid file */ -#define SLAPD_PIDFILE "C:\\OpenLDAP\\run\\slapd.pid" - /* location of the slapd args file */ -#define SLAPD_ARGSFILE "C:\\OpenLDAP\\run\\slapd.args" + /* extension of the slapd pid file */ +#define SLAPD_PIDEXT ".pid" + /* extension of the slapd args file */ +#define SLAPD_ARGSEXT ".args" /* dn of the special "monitor" entry */ #define SLAPD_MONITOR_DN "cn=monitor" /* dn of the special "config" entry */ diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index b03b80b933..85954be7cb 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -40,6 +40,12 @@ static int slapd_shutdown = 0; static void set_shutdown(int sig); static void do_nothing (int sig); +/* we need the server's name for constructing the pid/args file names */ +#if defined( SLAPD_PIDEXT ) || defined( SLAPD_ARGSEXT ) +extern char *serverName; +#define DEFAULT_SERVERNAME "slapd" +#endif + void * slapd_daemon( void *port @@ -56,6 +62,13 @@ slapd_daemon( FILE *fp; int on = 1; +#ifdef SLAPD_PIDEXT + char pidFile[BUFSIZ]; +#endif +#ifdef SLAPD_ARGSEXT + char argsFile[BUFSIZ]; +#endif + #ifdef HAVE_SYSCONF dtblsize = sysconf( _SC_OPEN_MAX ); #elif HAVE_GETDTABLESIZE @@ -135,14 +148,22 @@ slapd_daemon( (void) SIGNAL( SIGHUP, set_shutdown ); Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 ); -#ifdef SLAPD_PIDFILE - if ( (fp = fopen( SLAPD_PIDFILE, "w" )) != NULL ) { + +#if defined( SLAPD_PIDEXT ) || defined( SLAPD_ARGSEXT ) + if ( !serverName ) serverName = DEFAULT_SERVERNAME; + +#ifdef SLAPD_PIDEXT + sprintf( pidFile, "%s%s%s%s", DEFAULT_RUNDIR, DEFAULT_DIRSEP, + serverName, SLAPD_PIDEXT ); + if ( (fp = fopen( pidFile, "w" )) != NULL ) { fprintf( fp, "%d\n", (int) getpid() ); fclose( fp ); } #endif -#ifdef SLAPD_ARGSFILE - if ( (fp = fopen( SLAPD_ARGSFILE, "w" )) != NULL ) { +#ifdef SLAPD_ARGSEXT + sprintf( argsFile, "%s%s%s%s", DEFAULT_RUNDIR, DEFAULT_DIRSEP, + serverName, SLAPD_ARGSEXT ); + if ( (fp = fopen( argsFile, "w" )) != NULL ) { for ( i = 0; i < g_argc; i++ ) { fprintf( fp, "%s ", g_argv[i] ); } @@ -150,6 +171,8 @@ slapd_daemon( fclose( fp ); } #endif +#endif + while ( !slapd_shutdown ) { struct sockaddr_in from; diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 4f8c778bcd..b19e290f75 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -11,10 +11,58 @@ #include "slap.h" #include "lutil.h" /* Get lutil_detach() */ +/* + * 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 + */ + +#ifdef LOG_LOCAL4 + +#define DEFAULT_SYSLOG_USER LOG_LOCAL4 + +typedef struct _str2intDispatch { + + char *stringVal; + int abbr; + int intVal; + +} STRDISP, *STRDISP_P; + + +/* table to compute syslog-options to integer */ +static STRDISP syslog_types[] = { + + { "LOCAL0", 6, LOG_LOCAL0 }, + { "LOCAL1", 6, LOG_LOCAL1 }, + { "LOCAL2", 6, LOG_LOCAL2 }, + { "LOCAL3", 6, LOG_LOCAL3 }, + { "LOCAL4", 6, LOG_LOCAL4 }, + { "LOCAL5", 6, LOG_LOCAL5 }, + { "LOCAL6", 6, LOG_LOCAL6 }, + { "LOCAL7", 6, LOG_LOCAL7 }, + NULL + +}; + +static int cnvt_str2int(); + +#endif /* LOG_LOCAL4 */ + +/* + * the server's name must be accessible from the daemon module, + * to construct the pid/args file names + */ +char *serverName = NULL; + + static void usage( char *name ) { - fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name ); + fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name ); +#ifdef LOG_LOCAL4 + fprintf( stderr, " [-l sysloguser]" ); +#endif + fprintf( stderr, "\n" ); } int @@ -23,11 +71,13 @@ main( int argc, char **argv ) int i; int inetd = 0; int port; - char *myname; int udp; Backend *be = NULL; FILE *fp = NULL; char *configfile; +#ifdef LOG_LOCAL4 + int syslogUser = DEFAULT_SYSLOG_USER; +#endif configfile = SLAPD_DEFAULT_CONFIGFILE; port = LDAP_PORT; @@ -95,6 +145,15 @@ main( int argc, char **argv ) ldap_syslog = atoi( optarg ); break; +#ifdef LOG_LOCAL4 + + case 'l': /* set syslog local user */ + syslogUser = cnvt_str2int( optarg, syslog_types, + DEFAULT_SYSLOG_USER ); + break; + +#endif + case 'u': /* do udp */ udp = 1; break; @@ -107,10 +166,10 @@ main( int argc, char **argv ) Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 ); - if ( (myname = strrchr( argv[0], '/' )) == NULL ) { - myname = ch_strdup( argv[0] ); + if ( (serverName = strrchr( argv[0], '/' )) == NULL ) { + serverName = ch_strdup( argv[0] ); } else { - myname = ch_strdup( myname + 1 ); + serverName = ch_strdup( serverName + 1 ); } if ( ! inetd ) { @@ -122,10 +181,11 @@ main( int argc, char **argv ) lutil_detach( 0, 0 ); #endif } + #ifdef LOG_LOCAL4 - openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL4 ); + openlog( serverName, OPENLOG_OPTIONS, syslogUser ); #else - openlog( myname, OPENLOG_OPTIONS ); + openlog( serverName, OPENLOG_OPTIONS ); #endif init(); @@ -231,3 +291,37 @@ main( int argc, char **argv ) } return 1; } + + +#ifdef LOG_LOCAL4 + +/* + * Convert a string to an integer by means of a dispatcher table + * if the string is not in the table return the default + */ + +static int +cnvt_str2int (stringVal, dispatcher, defaultVal) +char *stringVal; +STRDISP_P dispatcher; +int defaultVal; +{ + int retVal = defaultVal; + STRDISP_P disp; + + for (disp = dispatcher; disp->stringVal; disp++) { + + if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) { + + retVal = disp->intVal; + break; + + } + } + + return (retVal); + +} /* cnvt_str2int */ + +#endif /* LOG_LOCAL4 */ + -- 2.47.2