diff options
Diffstat (limited to 'other/openssh-reverse/log-server.c')
| -rw-r--r-- | other/openssh-reverse/log-server.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/other/openssh-reverse/log-server.c b/other/openssh-reverse/log-server.c new file mode 100644 index 0000000..9db77d9 --- /dev/null +++ b/other/openssh-reverse/log-server.c | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * log-server.c | ||
| 4 | * | ||
| 5 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | ||
| 6 | * | ||
| 7 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | ||
| 8 | * All rights reserved | ||
| 9 | * | ||
| 10 | * Created: Mon Mar 20 21:19:30 1995 ylo | ||
| 11 | * | ||
| 12 | * Server-side versions of debug(), log(), etc. These normally send the output | ||
| 13 | * to the system log. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "includes.h" | ||
| 18 | RCSID("$OpenBSD: log-server.c,v 1.15 2000/06/20 01:39:42 markus Exp $"); | ||
| 19 | |||
| 20 | #include <syslog.h> | ||
| 21 | #include "packet.h" | ||
| 22 | #include "xmalloc.h" | ||
| 23 | #include "ssh.h" | ||
| 24 | |||
| 25 | #ifdef HAVE___PROGNAME | ||
| 26 | extern char *__progname; | ||
| 27 | #else /* HAVE___PROGNAME */ | ||
| 28 | static const char *__progname = "sshd"; | ||
| 29 | #endif /* HAVE___PROGNAME */ | ||
| 30 | |||
| 31 | static LogLevel log_level = SYSLOG_LEVEL_INFO; | ||
| 32 | static int log_on_stderr = 0; | ||
| 33 | static int log_facility = LOG_AUTH; | ||
| 34 | |||
| 35 | /* Initialize the log. | ||
| 36 | * av0 program name (should be argv[0]) | ||
| 37 | * on_stderr print also on stderr | ||
| 38 | * level logging level | ||
| 39 | */ | ||
| 40 | |||
| 41 | void | ||
| 42 | log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr) | ||
| 43 | { | ||
| 44 | switch (level) { | ||
| 45 | case SYSLOG_LEVEL_QUIET: | ||
| 46 | case SYSLOG_LEVEL_ERROR: | ||
| 47 | case SYSLOG_LEVEL_FATAL: | ||
| 48 | case SYSLOG_LEVEL_INFO: | ||
| 49 | case SYSLOG_LEVEL_VERBOSE: | ||
| 50 | case SYSLOG_LEVEL_DEBUG: | ||
| 51 | log_level = level; | ||
| 52 | break; | ||
| 53 | default: | ||
| 54 | fprintf(stderr, "Unrecognized internal syslog level code %d\n", | ||
| 55 | (int) level); | ||
| 56 | exit(1); | ||
| 57 | } | ||
| 58 | switch (facility) { | ||
| 59 | case SYSLOG_FACILITY_DAEMON: | ||
| 60 | log_facility = LOG_DAEMON; | ||
| 61 | break; | ||
| 62 | case SYSLOG_FACILITY_USER: | ||
| 63 | log_facility = LOG_USER; | ||
| 64 | break; | ||
| 65 | case SYSLOG_FACILITY_AUTH: | ||
| 66 | log_facility = LOG_AUTH; | ||
| 67 | break; | ||
| 68 | case SYSLOG_FACILITY_LOCAL0: | ||
| 69 | log_facility = LOG_LOCAL0; | ||
| 70 | break; | ||
| 71 | case SYSLOG_FACILITY_LOCAL1: | ||
| 72 | log_facility = LOG_LOCAL1; | ||
| 73 | break; | ||
| 74 | case SYSLOG_FACILITY_LOCAL2: | ||
| 75 | log_facility = LOG_LOCAL2; | ||
| 76 | break; | ||
| 77 | case SYSLOG_FACILITY_LOCAL3: | ||
| 78 | log_facility = LOG_LOCAL3; | ||
| 79 | break; | ||
| 80 | case SYSLOG_FACILITY_LOCAL4: | ||
| 81 | log_facility = LOG_LOCAL4; | ||
| 82 | break; | ||
| 83 | case SYSLOG_FACILITY_LOCAL5: | ||
| 84 | log_facility = LOG_LOCAL5; | ||
| 85 | break; | ||
| 86 | case SYSLOG_FACILITY_LOCAL6: | ||
| 87 | log_facility = LOG_LOCAL6; | ||
| 88 | break; | ||
| 89 | case SYSLOG_FACILITY_LOCAL7: | ||
| 90 | log_facility = LOG_LOCAL7; | ||
| 91 | break; | ||
| 92 | default: | ||
| 93 | fprintf(stderr, "Unrecognized internal syslog facility code %d\n", | ||
| 94 | (int) facility); | ||
| 95 | exit(1); | ||
| 96 | } | ||
| 97 | log_on_stderr = on_stderr; | ||
| 98 | } | ||
| 99 | |||
| 100 | #define MSGBUFSIZ 1024 | ||
| 101 | |||
| 102 | void | ||
| 103 | do_log(LogLevel level, const char *fmt, va_list args) | ||
| 104 | { | ||
| 105 | char msgbuf[MSGBUFSIZ]; | ||
| 106 | char fmtbuf[MSGBUFSIZ]; | ||
| 107 | char *txt = NULL; | ||
| 108 | int pri = LOG_INFO; | ||
| 109 | |||
| 110 | if (level > log_level) | ||
| 111 | return; | ||
| 112 | switch (level) { | ||
| 113 | case SYSLOG_LEVEL_ERROR: | ||
| 114 | txt = "error"; | ||
| 115 | pri = LOG_ERR; | ||
| 116 | break; | ||
| 117 | case SYSLOG_LEVEL_FATAL: | ||
| 118 | txt = "fatal"; | ||
| 119 | pri = LOG_ERR; | ||
| 120 | break; | ||
| 121 | case SYSLOG_LEVEL_INFO: | ||
| 122 | case SYSLOG_LEVEL_VERBOSE: | ||
| 123 | pri = LOG_INFO; | ||
| 124 | break; | ||
| 125 | case SYSLOG_LEVEL_DEBUG: | ||
| 126 | txt = "debug"; | ||
| 127 | pri = LOG_DEBUG; | ||
| 128 | break; | ||
| 129 | default: | ||
| 130 | txt = "internal error"; | ||
| 131 | pri = LOG_ERR; | ||
| 132 | break; | ||
| 133 | } | ||
| 134 | if (txt != NULL) { | ||
| 135 | snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", txt, fmt); | ||
| 136 | vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args); | ||
| 137 | } else { | ||
| 138 | vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); | ||
| 139 | } | ||
| 140 | if (log_on_stderr) { | ||
| 141 | fprintf(stderr, "%s\n", msgbuf); | ||
| 142 | } else { | ||
| 143 | openlog(__progname, LOG_PID, log_facility); | ||
| 144 | syslog(pri, "%.500s", msgbuf); | ||
| 145 | closelog(); | ||
| 146 | } | ||
| 147 | } | ||
