]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
Import resetting of c_dn/c_cdn after anonymous bind.
[openldap] / servers / slapd / main.c
index b06198a62d5db519418dc679c6a1dfeee9482a44..dd7ecf0027a33e20ad5f5a530391c7d47c2bea68 100644 (file)
 #include "slap.h"
 #include "lutil.h"                     /* Get lutil_detach() */
 
-
-/*
- * 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            ldap_debug = 0;
-#ifdef LDAP_DEBUG
-int            ldap_syslog = LDAP_DEBUG_STATS;
-#else
-int            ldap_syslog;
-#endif
-int            ldap_syslog_level = LOG_DEBUG;
-int            udp;
-int            slapd_shutdown;
-char           *default_referral;
-char           *configfile;
-time_t         starttime;
-pthread_t      listener_tid;
-int            g_argc;
-char           **g_argv;
 /*
- * global variables that need mutex protection
+ * 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
  */
-time_t         currenttime;
-pthread_mutex_t        currenttime_mutex;
-pthread_mutex_t        strtok_mutex;
-int            active_threads;
-pthread_mutex_t        active_threads_mutex;
-pthread_mutex_t        new_conn_mutex;
-#ifdef SLAPD_CRYPT
-pthread_mutex_t crypt_mutex;
-#endif
-long           ops_initiated;
-long           ops_completed;
-int            num_conns;
-pthread_mutex_t        ops_mutex;
-long           num_entries_sent;
-long           num_bytes_sent;
-pthread_mutex_t        num_sent_mutex;
+
+#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 */
+
 /*
- * these mutexes must be used when calling the entry2str()
- * routine since it returns a pointer to static data.
+ * the server's name must be accessible from the daemon module,
+ * to construct the pid/args file names
  */
-pthread_mutex_t        entry2str_mutex;
-pthread_mutex_t        replog_mutex;
+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
@@ -69,9 +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;
@@ -139,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;
@@ -151,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 ) {
@@ -166,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();
@@ -206,6 +222,7 @@ main( int argc, char **argv )
                struct hostent          *hp;
 
                c.c_dn = NULL;
+               c.c_cdn = NULL;
                c.c_ops = NULL;
                c.c_sb.sb_sd = 0;
                c.c_sb.sb_options = 0;
@@ -275,3 +292,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 */
+