diff options
author | Damien Miller <djm@mindrot.org> | 1999-11-25 00:26:21 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 1999-11-25 00:26:21 +1100 |
commit | 95def09838fc61b37b6ea7cd5c234a465b4b129b (patch) | |
tree | 042744f76f40a326b873cb1c3690a6d7d966bc3e /log.c | |
parent | 4d2f15f895f4c795afc008aeff3fd2ceffbc44f4 (diff) |
- Merged very large OpenBSD source code reformat
- OpenBSD CVS updates
- [channels.c cipher.c compat.c log-client.c scp.c serverloop.c]
[ssh.h sshd.8 sshd.c]
syslog changes:
* Unified Logmessage for all auth-types, for success and for failed
* Standard connections get only ONE line in the LOG when level==LOG:
Auth-attempts are logged only, if authentication is:
a) successfull or
b) with passwd or
c) we had more than AUTH_FAIL_LOG failues
* many log() became verbose()
* old behaviour with level=VERBOSE
- [readconf.c readconf.h ssh.1 ssh.h sshconnect.c sshd.c]
tranfer s/key challenge/response data in SSH_SMSG_AUTH_TIS_CHALLENGE
messages. allows use of s/key in windows (ttssh, securecrt) and
ssh-1.2.27 clients without 'ssh -v', ok: niels@
- [sshd.8]
-V, for fallback to openssh in SSH2 compatibility mode
- [sshd.c]
fix sigchld race; cjc5@po.cwru.edu
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 219 |
1 files changed, 105 insertions, 114 deletions
@@ -1,11 +1,11 @@ | |||
1 | /* | 1 | /* |
2 | 2 | * | |
3 | Shared versions of debug(), log(), etc. | 3 | * Shared versions of debug(), log(), etc. |
4 | 4 | * | |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "includes.h" | 7 | #include "includes.h" |
8 | RCSID("$OpenBSD: log.c,v 1.2 1999/11/19 16:04:17 markus Exp $"); | 8 | RCSID("$OpenBSD: log.c,v 1.5 1999/11/24 00:26:02 deraadt Exp $"); |
9 | 9 | ||
10 | #include "ssh.h" | 10 | #include "ssh.h" |
11 | #include "xmalloc.h" | 11 | #include "xmalloc.h" |
@@ -13,66 +13,65 @@ RCSID("$OpenBSD: log.c,v 1.2 1999/11/19 16:04:17 markus Exp $"); | |||
13 | /* Fatal messages. This function never returns. */ | 13 | /* Fatal messages. This function never returns. */ |
14 | 14 | ||
15 | void | 15 | void |
16 | fatal(const char *fmt, ...) | 16 | fatal(const char *fmt,...) |
17 | { | 17 | { |
18 | va_list args; | 18 | va_list args; |
19 | va_start(args, fmt); | 19 | va_start(args, fmt); |
20 | do_log(SYSLOG_LEVEL_FATAL, fmt, args); | 20 | do_log(SYSLOG_LEVEL_FATAL, fmt, args); |
21 | va_end(args); | 21 | va_end(args); |
22 | fatal_cleanup(); | 22 | fatal_cleanup(); |
23 | } | 23 | } |
24 | 24 | ||
25 | /* Error messages that should be logged. */ | 25 | /* Error messages that should be logged. */ |
26 | 26 | ||
27 | void | 27 | void |
28 | error(const char *fmt, ...) | 28 | error(const char *fmt,...) |
29 | { | 29 | { |
30 | va_list args; | 30 | va_list args; |
31 | va_start(args, fmt); | 31 | va_start(args, fmt); |
32 | do_log(SYSLOG_LEVEL_ERROR, fmt, args); | 32 | do_log(SYSLOG_LEVEL_ERROR, fmt, args); |
33 | va_end(args); | 33 | va_end(args); |
34 | } | 34 | } |
35 | 35 | ||
36 | /* Log this message (information that usually should go to the log). */ | 36 | /* Log this message (information that usually should go to the log). */ |
37 | 37 | ||
38 | void | 38 | void |
39 | log(const char *fmt, ...) | 39 | log(const char *fmt,...) |
40 | { | 40 | { |
41 | va_list args; | 41 | va_list args; |
42 | va_start(args, fmt); | 42 | va_start(args, fmt); |
43 | do_log(SYSLOG_LEVEL_INFO, fmt, args); | 43 | do_log(SYSLOG_LEVEL_INFO, fmt, args); |
44 | va_end(args); | 44 | va_end(args); |
45 | } | 45 | } |
46 | 46 | ||
47 | /* More detailed messages (information that does not need to go to the log). */ | 47 | /* More detailed messages (information that does not need to go to the log). */ |
48 | 48 | ||
49 | void | 49 | void |
50 | chat(const char *fmt, ...) | 50 | verbose(const char *fmt,...) |
51 | { | 51 | { |
52 | va_list args; | 52 | va_list args; |
53 | va_start(args, fmt); | 53 | va_start(args, fmt); |
54 | do_log(SYSLOG_LEVEL_CHAT, fmt, args); | 54 | do_log(SYSLOG_LEVEL_VERBOSE, fmt, args); |
55 | va_end(args); | 55 | va_end(args); |
56 | } | 56 | } |
57 | 57 | ||
58 | /* Debugging messages that should not be logged during normal operation. */ | 58 | /* Debugging messages that should not be logged during normal operation. */ |
59 | 59 | ||
60 | void | 60 | void |
61 | debug(const char *fmt, ...) | 61 | debug(const char *fmt,...) |
62 | { | 62 | { |
63 | va_list args; | 63 | va_list args; |
64 | va_start(args, fmt); | 64 | va_start(args, fmt); |
65 | do_log(SYSLOG_LEVEL_DEBUG, fmt, args); | 65 | do_log(SYSLOG_LEVEL_DEBUG, fmt, args); |
66 | va_end(args); | 66 | va_end(args); |
67 | } | 67 | } |
68 | 68 | ||
69 | /* Fatal cleanup */ | 69 | /* Fatal cleanup */ |
70 | 70 | ||
71 | struct fatal_cleanup | 71 | struct fatal_cleanup { |
72 | { | 72 | struct fatal_cleanup *next; |
73 | struct fatal_cleanup *next; | 73 | void (*proc) (void *); |
74 | void (*proc)(void *); | 74 | void *context; |
75 | void *context; | ||
76 | }; | 75 | }; |
77 | 76 | ||
78 | static struct fatal_cleanup *fatal_cleanups = NULL; | 77 | static struct fatal_cleanup *fatal_cleanups = NULL; |
@@ -80,116 +79,108 @@ static struct fatal_cleanup *fatal_cleanups = NULL; | |||
80 | /* Registers a cleanup function to be called by fatal() before exiting. */ | 79 | /* Registers a cleanup function to be called by fatal() before exiting. */ |
81 | 80 | ||
82 | void | 81 | void |
83 | fatal_add_cleanup(void (*proc)(void *), void *context) | 82 | fatal_add_cleanup(void (*proc) (void *), void *context) |
84 | { | 83 | { |
85 | struct fatal_cleanup *cu; | 84 | struct fatal_cleanup *cu; |
86 | 85 | ||
87 | cu = xmalloc(sizeof(*cu)); | 86 | cu = xmalloc(sizeof(*cu)); |
88 | cu->proc = proc; | 87 | cu->proc = proc; |
89 | cu->context = context; | 88 | cu->context = context; |
90 | cu->next = fatal_cleanups; | 89 | cu->next = fatal_cleanups; |
91 | fatal_cleanups = cu; | 90 | fatal_cleanups = cu; |
92 | } | 91 | } |
93 | 92 | ||
94 | /* Removes a cleanup frunction to be called at fatal(). */ | 93 | /* Removes a cleanup frunction to be called at fatal(). */ |
95 | 94 | ||
96 | void | 95 | void |
97 | fatal_remove_cleanup(void (*proc)(void *context), void *context) | 96 | fatal_remove_cleanup(void (*proc) (void *context), void *context) |
98 | { | 97 | { |
99 | struct fatal_cleanup **cup, *cu; | 98 | struct fatal_cleanup **cup, *cu; |
100 | 99 | ||
101 | for (cup = &fatal_cleanups; *cup; cup = &cu->next) | 100 | for (cup = &fatal_cleanups; *cup; cup = &cu->next) { |
102 | { | 101 | cu = *cup; |
103 | cu = *cup; | 102 | if (cu->proc == proc && cu->context == context) { |
104 | if (cu->proc == proc && cu->context == context) | 103 | *cup = cu->next; |
105 | { | 104 | xfree(cu); |
106 | *cup = cu->next; | 105 | return; |
107 | xfree(cu); | 106 | } |
108 | return; | ||
109 | } | 107 | } |
110 | } | 108 | fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx\n", |
111 | fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx\n", | 109 | (unsigned long) proc, (unsigned long) context); |
112 | (unsigned long)proc, (unsigned long)context); | ||
113 | } | 110 | } |
114 | 111 | ||
115 | /* Cleanup and exit */ | 112 | /* Cleanup and exit */ |
116 | void | 113 | void |
117 | fatal_cleanup(void) | 114 | fatal_cleanup(void) |
118 | { | 115 | { |
119 | struct fatal_cleanup *cu, *next_cu; | 116 | struct fatal_cleanup *cu, *next_cu; |
120 | static int called = 0; | 117 | static int called = 0; |
121 | if (called) | 118 | |
122 | exit(255); | 119 | if (called) |
123 | called = 1; | 120 | exit(255); |
124 | 121 | called = 1; | |
125 | /* Call cleanup functions. */ | 122 | /* Call cleanup functions. */ |
126 | for (cu = fatal_cleanups; cu; cu = next_cu) | 123 | for (cu = fatal_cleanups; cu; cu = next_cu) { |
127 | { | 124 | next_cu = cu->next; |
128 | next_cu = cu->next; | 125 | debug("Calling cleanup 0x%lx(0x%lx)", |
129 | debug("Calling cleanup 0x%lx(0x%lx)", | 126 | (unsigned long) cu->proc, (unsigned long) cu->context); |
130 | (unsigned long)cu->proc, (unsigned long)cu->context); | 127 | (*cu->proc) (cu->context); |
131 | (*cu->proc)(cu->context); | 128 | } |
132 | } | 129 | exit(255); |
133 | |||
134 | exit(255); | ||
135 | } | 130 | } |
136 | 131 | ||
137 | /* textual representation of log-facilities/levels */ | 132 | /* textual representation of log-facilities/levels */ |
138 | 133 | ||
139 | 134 | static struct { | |
140 | static struct | 135 | const char *name; |
141 | { | 136 | SyslogFacility val; |
142 | const char *name; | 137 | } log_facilities[] = { |
143 | SyslogFacility val; | 138 | { "DAEMON", SYSLOG_FACILITY_DAEMON }, |
144 | } log_facilities[] = | 139 | { "USER", SYSLOG_FACILITY_USER }, |
145 | { | 140 | { "AUTH", SYSLOG_FACILITY_AUTH }, |
146 | { "DAEMON", SYSLOG_FACILITY_DAEMON }, | 141 | { "LOCAL0", SYSLOG_FACILITY_LOCAL0 }, |
147 | { "USER", SYSLOG_FACILITY_USER }, | 142 | { "LOCAL1", SYSLOG_FACILITY_LOCAL1 }, |
148 | { "AUTH", SYSLOG_FACILITY_AUTH }, | 143 | { "LOCAL2", SYSLOG_FACILITY_LOCAL2 }, |
149 | { "LOCAL0", SYSLOG_FACILITY_LOCAL0 }, | 144 | { "LOCAL3", SYSLOG_FACILITY_LOCAL3 }, |
150 | { "LOCAL1", SYSLOG_FACILITY_LOCAL1 }, | 145 | { "LOCAL4", SYSLOG_FACILITY_LOCAL4 }, |
151 | { "LOCAL2", SYSLOG_FACILITY_LOCAL2 }, | 146 | { "LOCAL5", SYSLOG_FACILITY_LOCAL5 }, |
152 | { "LOCAL3", SYSLOG_FACILITY_LOCAL3 }, | 147 | { "LOCAL6", SYSLOG_FACILITY_LOCAL6 }, |
153 | { "LOCAL4", SYSLOG_FACILITY_LOCAL4 }, | 148 | { "LOCAL7", SYSLOG_FACILITY_LOCAL7 }, |
154 | { "LOCAL5", SYSLOG_FACILITY_LOCAL5 }, | 149 | { NULL, 0 } |
155 | { "LOCAL6", SYSLOG_FACILITY_LOCAL6 }, | ||
156 | { "LOCAL7", SYSLOG_FACILITY_LOCAL7 }, | ||
157 | { NULL, 0 } | ||
158 | }; | 150 | }; |
159 | 151 | ||
160 | static struct | 152 | static struct { |
161 | { | 153 | const char *name; |
162 | const char *name; | 154 | LogLevel val; |
163 | LogLevel val; | ||
164 | } log_levels[] = | 155 | } log_levels[] = |
165 | { | 156 | { |
166 | { "QUIET", SYSLOG_LEVEL_QUIET }, | 157 | { "QUIET", SYSLOG_LEVEL_QUIET }, |
167 | { "FATAL", SYSLOG_LEVEL_FATAL }, | 158 | { "FATAL", SYSLOG_LEVEL_FATAL }, |
168 | { "ERROR", SYSLOG_LEVEL_ERROR }, | 159 | { "ERROR", SYSLOG_LEVEL_ERROR }, |
169 | { "INFO", SYSLOG_LEVEL_INFO }, | 160 | { "INFO", SYSLOG_LEVEL_INFO }, |
170 | { "CHAT", SYSLOG_LEVEL_CHAT }, | 161 | { "VERBOSE", SYSLOG_LEVEL_VERBOSE }, |
171 | { "DEBUG", SYSLOG_LEVEL_DEBUG }, | 162 | { "DEBUG", SYSLOG_LEVEL_DEBUG }, |
172 | { NULL, 0 } | 163 | { NULL, 0 } |
173 | }; | 164 | }; |
174 | 165 | ||
175 | SyslogFacility | 166 | SyslogFacility |
176 | log_facility_number(char *name) | 167 | log_facility_number(char *name) |
177 | { | 168 | { |
178 | int i; | 169 | int i; |
179 | if (name != NULL) | 170 | if (name != NULL) |
180 | for (i = 0; log_facilities[i].name; i++) | 171 | for (i = 0; log_facilities[i].name; i++) |
181 | if (strcasecmp(log_facilities[i].name, name) == 0) | 172 | if (strcasecmp(log_facilities[i].name, name) == 0) |
182 | return log_facilities[i].val; | 173 | return log_facilities[i].val; |
183 | return (SyslogFacility)-1; | 174 | return (SyslogFacility) - 1; |
184 | } | 175 | } |
185 | 176 | ||
186 | LogLevel | 177 | LogLevel |
187 | log_level_number(char *name) | 178 | log_level_number(char *name) |
188 | { | 179 | { |
189 | int i; | 180 | int i; |
190 | if (name != NULL) | 181 | if (name != NULL) |
191 | for (i = 0; log_levels[i].name; i++) | 182 | for (i = 0; log_levels[i].name; i++) |
192 | if (strcasecmp(log_levels[i].name, name) == 0) | 183 | if (strcasecmp(log_levels[i].name, name) == 0) |
193 | return log_levels[i].val; | 184 | return log_levels[i].val; |
194 | return (LogLevel)-1; | 185 | return (LogLevel) - 1; |
195 | } | 186 | } |