summaryrefslogtreecommitdiffstats
path: root/log-server.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-11 17:57:39 +1100
committerDamien Miller <djm@mindrot.org>1999-11-11 17:57:39 +1100
commit5ce662a9202240a2f5fa6a9334d58186bdaba50c (patch)
tree9fe37122fa27f070abc3c9c28531877d43673b7f /log-server.c
parentab5e0d0c27e00dca463c67395c2b5941e778836e (diff)
- Merged more OpenBSD CVS changes:
- [auth-krb4.c auth-passwd.c] remove x11- and krb-cleanup from fatal() + krb-cleanup cleanup - [clientloop.c log-client.c log-server.c ] [readconf.c readconf.h servconf.c servconf.h ] [ssh.1 ssh.c ssh.h sshd.8] add LogLevel {QUIET, FATAL, ERROR, INFO, CHAT, DEBUG} to ssh/sshd, obsoletes QuietMode and FascistLogging in sshd.
Diffstat (limited to 'log-server.c')
-rw-r--r--log-server.c202
1 files changed, 58 insertions, 144 deletions
diff --git a/log-server.c b/log-server.c
index fce96b01..6642dbed 100644
--- a/log-server.c
+++ b/log-server.c
@@ -15,29 +15,42 @@ to the system log.
*/
#include "includes.h"
-RCSID("$Id: log-server.c,v 1.1 1999/10/27 03:42:44 damien Exp $");
+RCSID("$Id: log-server.c,v 1.2 1999/11/11 06:57:39 damien Exp $");
#include <syslog.h>
#include "packet.h"
#include "xmalloc.h"
#include "ssh.h"
-static int log_debug = 0;
-static int log_quiet = 0;
+static LogLevel log_level = SYSLOG_LEVEL_INFO;
static int log_on_stderr = 0;
/* Initialize the log.
av0 program name (should be argv[0])
on_stderr print also on stderr
- debug send debugging messages to system log
- quiet don\'t log anything
+ level logging level
*/
-void log_init(char *av0, int on_stderr, int debug, int quiet,
- SyslogFacility facility)
+void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
{
int log_facility;
+ switch (level)
+ {
+ case SYSLOG_LEVEL_QUIET:
+ case SYSLOG_LEVEL_ERROR:
+ case SYSLOG_LEVEL_FATAL:
+ case SYSLOG_LEVEL_INFO:
+ case SYSLOG_LEVEL_CHAT:
+ case SYSLOG_LEVEL_DEBUG:
+ log_level = level;
+ break;
+ default:
+ fprintf(stderr, "Unrecognized internal syslog level code %d\n",
+ (int)level);
+ exit(1);
+ }
+
switch (facility)
{
case SYSLOG_FACILITY_DAEMON:
@@ -79,8 +92,6 @@ void log_init(char *av0, int on_stderr, int debug, int quiet,
exit(1);
}
- log_debug = debug;
- log_quiet = quiet;
log_on_stderr = on_stderr;
closelog(); /* Close any previous log. */
openlog(av0, LOG_PID, log_facility);
@@ -88,146 +99,49 @@ void log_init(char *av0, int on_stderr, int debug, int quiet,
#define MSGBUFSIZE 1024
-#define DECL_MSGBUF char msgbuf[MSGBUFSIZE]
-
-/* Log this message (information that usually should go to the log). */
-
-void log(const char *fmt, ...)
-{
- va_list args;
- DECL_MSGBUF;
- if (log_quiet)
- return;
- va_start(args, fmt);
- vsnprintf(msgbuf, MSGBUFSIZE, fmt, args);
- va_end(args);
- if (log_on_stderr)
- fprintf(stderr, "log: %s\n", msgbuf);
- syslog(LOG_INFO, "log: %.500s", msgbuf);
-}
-
-/* Debugging messages that should not be logged during normal operation. */
-
-void debug(const char *fmt, ...)
+void
+do_log(LogLevel level, const char *fmt, va_list args)
{
- va_list args;
- DECL_MSGBUF;
- if (!log_debug || log_quiet)
- return;
- va_start(args, fmt);
- vsnprintf(msgbuf, MSGBUFSIZE, fmt, args);
- va_end(args);
- if (log_on_stderr)
- fprintf(stderr, "debug: %s\n", msgbuf);
- syslog(LOG_DEBUG, "debug: %.500s", msgbuf);
-}
+ char msgbuf[MSGBUFSIZE];
+ char fmtbuf[MSGBUFSIZE];
+ char *txt = NULL;
+ int pri = LOG_INFO;
-/* Error messages that should be logged. */
-
-void error(const char *fmt, ...)
-{
- va_list args;
- DECL_MSGBUF;
- if (log_quiet)
+ if (level > log_level)
return;
- va_start(args, fmt);
- vsnprintf(msgbuf, MSGBUFSIZE, fmt, args);
- va_end(args);
- if (log_on_stderr)
- fprintf(stderr, "error: %s\n", msgbuf);
- syslog(LOG_ERR, "error: %.500s", msgbuf);
-}
-
-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)
+ switch (level)
{
- cu = *cup;
- if (cu->proc == proc && cu->context == context)
- {
- *cup = cu->next;
- xfree(cu);
- return;
- }
+ case SYSLOG_LEVEL_ERROR:
+ txt = "error";
+ pri = LOG_ERR;
+ break;
+ case SYSLOG_LEVEL_FATAL:
+ txt = "fatal";
+ pri = LOG_ERR;
+ break;
+ case SYSLOG_LEVEL_INFO:
+ pri = LOG_INFO;
+ break;
+ case SYSLOG_LEVEL_CHAT:
+ pri = LOG_INFO;
+ break;
+ case SYSLOG_LEVEL_DEBUG:
+ txt = "debug";
+ pri = LOG_DEBUG;
+ break;
+ default:
+ txt = "internal error";
+ pri = LOG_ERR;
+ break;
}
- fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx\n",
- (unsigned long)proc, (unsigned long)context);
-}
-
-/* Fatal messages. This function never returns. */
-void fatal(const char *fmt, ...)
-{
- va_list args;
- struct fatal_cleanup *cu, *next_cu;
- static int fatal_called = 0;
-#if defined(KRB4)
- extern char *ticket;
-#endif /* KRB4 */
- DECL_MSGBUF;
-
- if (log_quiet)
- exit(1);
- va_start(args, fmt);
- vsnprintf(msgbuf, MSGBUFSIZE, fmt, args);
- va_end(args);
+ if (txt != NULL) {
+ snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", txt, fmt);
+ vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args);
+ }else{
+ vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
+ }
if (log_on_stderr)
- fprintf(stderr, "fatal: %s\n", msgbuf);
- syslog(LOG_ERR, "fatal: %.500s", msgbuf);
-
- if (fatal_called)
- exit(1);
- fatal_called = 1;
-
- /* Call cleanup functions. */
- for (cu = fatal_cleanups; cu; cu = next_cu)
- {
- next_cu = cu->next;
- debug("Calling cleanup 0x%lx(0x%lx)",
- (unsigned long)cu->proc, (unsigned long)cu->context);
- (*cu->proc)(cu->context);
- }
-#if defined(KRB4)
- /* If you forwarded a ticket you get one shot for proper
- authentication. */
- /* If tgt was passed unlink file */
- if (ticket)
- {
- if (strcmp(ticket,"none"))
- unlink(ticket);
- else
- ticket = NULL;
- }
-#endif /* KRB4 */
-
- /* If local XAUTHORITY was created, remove it. */
- if (xauthfile) unlink(xauthfile);
-
- exit(1);
+ fprintf(stderr, "%s\n", msgbuf);
+ syslog(pri, "%.500s", msgbuf);
}