]> andersk Git - gssapi-openssh.git/blobdiff - openssh/log.c
check for existence of globus_gss_assist_map_and_authorize()
[gssapi-openssh.git] / openssh / log.c
index d27dbaa56f0a187e03ca82cf2b59e72d12501c2b..96ab24b04b43bc1a65275fbbd622cd0aac54c547 100644 (file)
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: log.c,v 1.24 2002/07/19 15:43:33 markus Exp $");
+RCSID("$OpenBSD: log.c,v 1.29 2003/09/23 20:17:11 markus Exp $");
 
 #include "log.h"
 #include "xmalloc.h"
 
 #include <syslog.h>
+#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
+# include <vis.h>
+#endif
 
 static LogLevel log_level = SYSLOG_LEVEL_INFO;
 static int log_on_stderr = 1;
@@ -48,6 +51,9 @@ static char *argv0;
 
 extern char *__progname;
 
+#define LOG_SYSLOG_VIS (VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL)
+#define LOG_STDERR_VIS (VIS_SAFE|VIS_OCTAL)
+
 /* textual representation of log-facilities/levels */
 
 static struct {
@@ -127,7 +133,7 @@ error(const char *fmt,...)
 /* Log this message (information that usually should go to the log). */
 
 void
-log(const char *fmt,...)
+logit(const char *fmt,...)
 {
        va_list args;
 
@@ -180,82 +186,6 @@ debug3(const char *fmt,...)
        va_end(args);
 }
 
-/* Fatal cleanup */
-
-struct fatal_cleanup {
-       struct fatal_cleanup *next;
-       void (*proc) (void *);
-       void *context;
-};
-
-static struct fatal_cleanup *fatal_cleanups = NULL;
-
-/* Registers a cleanup function to be called by fatal() before exiting. */
-
-void
-fatal_add_cleanup(void (*proc) (void *), void *context)
-{
-       struct fatal_cleanup *cu;
-
-       cu = xmalloc(sizeof(*cu));
-       cu->proc = proc;
-       cu->context = context;
-       cu->next = fatal_cleanups;
-       fatal_cleanups = cu;
-}
-
-/* Removes a cleanup frunction to be called at fatal(). */
-
-void
-fatal_remove_cleanup(void (*proc) (void *context), void *context)
-{
-       struct fatal_cleanup **cup, *cu;
-
-       for (cup = &fatal_cleanups; *cup; cup = &cu->next) {
-               cu = *cup;
-               if (cu->proc == proc && cu->context == context) {
-                       *cup = cu->next;
-                       xfree(cu);
-                       return;
-               }
-       }
-       fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx",
-           (u_long) proc, (u_long) context);
-}
-
-/* Remove all cleanups, to be called after fork() */
-void
-fatal_remove_all_cleanups(void)
-{
-       struct fatal_cleanup *cu, *next_cu;
-
-       for (cu = fatal_cleanups; cu; cu = next_cu) {
-               next_cu = cu->next;
-               xfree(cu);
-       }
-}
-
-/* Cleanup and exit */
-void
-fatal_cleanup(void)
-{
-       struct fatal_cleanup *cu, *next_cu;
-       static int called = 0;
-
-       if (called)
-               exit(255);
-       called = 1;
-       /* Call cleanup functions. */
-       for (cu = fatal_cleanups; cu; cu = next_cu) {
-               next_cu = cu->next;
-               debug("Calling cleanup 0x%lx(0x%lx)",
-                   (u_long) cu->proc, (u_long) cu->context);
-               (*cu->proc) (cu->context);
-       }
-       exit(255);
-}
-
-
 /*
  * Initialize the log.
  */
@@ -263,6 +193,10 @@ fatal_cleanup(void)
 void
 log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
 {
+#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
+       struct syslog_data sdata = SYSLOG_DATA_INIT;
+#endif
+
        argv0 = av0;
 
        switch (level) {
@@ -331,6 +265,19 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
                    (int) facility);
                exit(1);
        }
+
+       /*
+        * If an external library (eg libwrap) attempts to use syslog
+        * immediately after reexec, syslog may be pointing to the wrong
+        * facility, so we force an open/close of syslog here.
+        */
+#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
+       openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
+       closelog_r(&sdata);
+#else
+       openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
+       closelog();
+#endif
 }
 
 #define MSGBUFSIZ 1024
@@ -338,6 +285,9 @@ log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
 void
 do_log(LogLevel level, const char *fmt, va_list args)
 {
+#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
+       struct syslog_data sdata = SYSLOG_DATA_INIT;
+#endif
        char msgbuf[MSGBUFSIZ];
        char fmtbuf[MSGBUFSIZ];
        char *txt = NULL;
@@ -386,11 +336,20 @@ do_log(LogLevel level, const char *fmt, va_list args)
        } else {
                vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
        }
+       strnvis(fmtbuf, msgbuf, sizeof(fmtbuf),
+           log_on_stderr ? LOG_STDERR_VIS : LOG_SYSLOG_VIS);
        if (log_on_stderr) {
-               fprintf(stderr, "%d: %s\r\n", getpid(), msgbuf);
+               snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
+               write(STDERR_FILENO, msgbuf, strlen(msgbuf));
        } else {
+#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
+               openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
+               syslog_r(pri, &sdata, "%.500s", fmtbuf);
+               closelog_r(&sdata);
+#else
                openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
-               syslog(pri, "%.500s", msgbuf);
+               syslog(pri, "%.500s", fmtbuf);
                closelog();
+#endif
        }
 }
This page took 0.050334 seconds and 4 git commands to generate.