summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--log.c259
-rw-r--r--ssh.c12
3 files changed, 212 insertions, 64 deletions
diff --git a/ChangeLog b/ChangeLog
index 1eab73d8d..0c4349e68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -140,6 +140,9 @@
140 - markus@cvs.openbsd.org 2001/03/03 23:52:22 140 - markus@cvs.openbsd.org 2001/03/03 23:52:22
141 [sftp.c] 141 [sftp.c]
142 clean up arg processing. based on work by Christophe_Moret@hp.com 142 clean up arg processing. based on work by Christophe_Moret@hp.com
143 - markus@cvs.openbsd.org 2001/03/03 23:59:34
144 [log.c ssh.c]
145 log*.c -> log.c
143 146
14420010304 14720010304
145 - (bal) Remove make-ssh-known-hosts.1 since it's no longer valid. 148 - (bal) Remove make-ssh-known-hosts.1 since it's no longer valid.
@@ -4332,4 +4335,4 @@
4332 - Wrote replacements for strlcpy and mkdtemp 4335 - Wrote replacements for strlcpy and mkdtemp
4333 - Released 1.0pre1 4336 - Released 1.0pre1
4334 4337
4335$Id: ChangeLog,v 1.894 2001/03/05 07:10:47 mouring Exp $ 4338$Id: ChangeLog,v 1.895 2001/03/05 07:24:46 mouring Exp $
diff --git a/log.c b/log.c
index 7e01384fa..c9c1631c9 100644
--- a/log.c
+++ b/log.c
@@ -10,8 +10,6 @@
10 * called by a name other than "ssh" or "Secure Shell". 10 * called by a name other than "ssh" or "Secure Shell".
11 */ 11 */
12/* 12/*
13 * Shared versions of debug(), log(), etc.
14 *
15 * Copyright (c) 2000 Markus Friedl. All rights reserved. 13 * Copyright (c) 2000 Markus Friedl. All rights reserved.
16 * 14 *
17 * Redistribution and use in source and binary forms, with or without 15 * Redistribution and use in source and binary forms, with or without
@@ -36,11 +34,78 @@
36 */ 34 */
37 35
38#include "includes.h" 36#include "includes.h"
39RCSID("$OpenBSD: log.c,v 1.15 2001/01/21 19:05:51 markus Exp $"); 37RCSID("$OpenBSD: log.c,v 1.17 2001/03/04 17:42:28 millert Exp $");
40 38
41#include "log.h" 39#include "log.h"
42#include "xmalloc.h" 40#include "xmalloc.h"
43 41
42#include <syslog.h>
43
44static LogLevel log_level = SYSLOG_LEVEL_INFO;
45static int log_on_stderr = 1;
46static int log_facility = LOG_AUTH;
47static char *argv0;
48
49extern char *__progname;
50
51/* textual representation of log-facilities/levels */
52
53static struct {
54 const char *name;
55 SyslogFacility val;
56} log_facilities[] = {
57 { "DAEMON", SYSLOG_FACILITY_DAEMON },
58 { "USER", SYSLOG_FACILITY_USER },
59 { "AUTH", SYSLOG_FACILITY_AUTH },
60 { "LOCAL0", SYSLOG_FACILITY_LOCAL0 },
61 { "LOCAL1", SYSLOG_FACILITY_LOCAL1 },
62 { "LOCAL2", SYSLOG_FACILITY_LOCAL2 },
63 { "LOCAL3", SYSLOG_FACILITY_LOCAL3 },
64 { "LOCAL4", SYSLOG_FACILITY_LOCAL4 },
65 { "LOCAL5", SYSLOG_FACILITY_LOCAL5 },
66 { "LOCAL6", SYSLOG_FACILITY_LOCAL6 },
67 { "LOCAL7", SYSLOG_FACILITY_LOCAL7 },
68 { NULL, 0 }
69};
70
71static struct {
72 const char *name;
73 LogLevel val;
74} log_levels[] =
75{
76 { "QUIET", SYSLOG_LEVEL_QUIET },
77 { "FATAL", SYSLOG_LEVEL_FATAL },
78 { "ERROR", SYSLOG_LEVEL_ERROR },
79 { "INFO", SYSLOG_LEVEL_INFO },
80 { "VERBOSE", SYSLOG_LEVEL_VERBOSE },
81 { "DEBUG", SYSLOG_LEVEL_DEBUG1 },
82 { "DEBUG1", SYSLOG_LEVEL_DEBUG1 },
83 { "DEBUG2", SYSLOG_LEVEL_DEBUG2 },
84 { "DEBUG3", SYSLOG_LEVEL_DEBUG3 },
85 { NULL, 0 }
86};
87
88SyslogFacility
89log_facility_number(char *name)
90{
91 int i;
92 if (name != NULL)
93 for (i = 0; log_facilities[i].name; i++)
94 if (strcasecmp(log_facilities[i].name, name) == 0)
95 return log_facilities[i].val;
96 return (SyslogFacility) - 1;
97}
98
99LogLevel
100log_level_number(char *name)
101{
102 int i;
103 if (name != NULL)
104 for (i = 0; log_levels[i].name; i++)
105 if (strcasecmp(log_levels[i].name, name) == 0)
106 return log_levels[i].val;
107 return (LogLevel) - 1;
108}
44/* Fatal messages. This function never returns. */ 109/* Fatal messages. This function never returns. */
45 110
46void 111void
@@ -154,8 +219,8 @@ fatal_remove_cleanup(void (*proc) (void *context), void *context)
154 return; 219 return;
155 } 220 }
156 } 221 }
157 fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx\n", 222 fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx",
158 (u_long) proc, (u_long) context); 223 (u_long) proc, (u_long) context);
159} 224}
160 225
161/* Cleanup and exit */ 226/* Cleanup and exit */
@@ -178,64 +243,142 @@ fatal_cleanup(void)
178 exit(255); 243 exit(255);
179} 244}
180 245
181/* textual representation of log-facilities/levels */
182 246
183static struct { 247/*
184 const char *name; 248 * Initialize the log.
185 SyslogFacility val; 249 */
186} log_facilities[] = {
187 { "DAEMON", SYSLOG_FACILITY_DAEMON },
188 { "USER", SYSLOG_FACILITY_USER },
189 { "AUTH", SYSLOG_FACILITY_AUTH },
190#ifdef LOG_AUTHPRIV
191 { "AUTHPRIV", SYSLOG_FACILITY_AUTHPRIV },
192#endif
193 { "LOCAL0", SYSLOG_FACILITY_LOCAL0 },
194 { "LOCAL1", SYSLOG_FACILITY_LOCAL1 },
195 { "LOCAL2", SYSLOG_FACILITY_LOCAL2 },
196 { "LOCAL3", SYSLOG_FACILITY_LOCAL3 },
197 { "LOCAL4", SYSLOG_FACILITY_LOCAL4 },
198 { "LOCAL5", SYSLOG_FACILITY_LOCAL5 },
199 { "LOCAL6", SYSLOG_FACILITY_LOCAL6 },
200 { "LOCAL7", SYSLOG_FACILITY_LOCAL7 },
201 { NULL, 0 }
202};
203 250
204static struct { 251void
205 const char *name; 252log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
206 LogLevel val;
207} log_levels[] =
208{ 253{
209 { "QUIET", SYSLOG_LEVEL_QUIET }, 254 argv0 = av0;
210 { "FATAL", SYSLOG_LEVEL_FATAL },
211 { "ERROR", SYSLOG_LEVEL_ERROR },
212 { "INFO", SYSLOG_LEVEL_INFO },
213 { "VERBOSE", SYSLOG_LEVEL_VERBOSE },
214 { "DEBUG", SYSLOG_LEVEL_DEBUG1 },
215 { "DEBUG1", SYSLOG_LEVEL_DEBUG1 },
216 { "DEBUG2", SYSLOG_LEVEL_DEBUG2 },
217 { "DEBUG3", SYSLOG_LEVEL_DEBUG3 },
218 { NULL, 0 }
219};
220 255
221SyslogFacility 256 switch (level) {
222log_facility_number(char *name) 257 case SYSLOG_LEVEL_QUIET:
223{ 258 case SYSLOG_LEVEL_FATAL:
224 int i; 259 case SYSLOG_LEVEL_ERROR:
225 if (name != NULL) 260 case SYSLOG_LEVEL_INFO:
226 for (i = 0; log_facilities[i].name; i++) 261 case SYSLOG_LEVEL_VERBOSE:
227 if (strcasecmp(log_facilities[i].name, name) == 0) 262 case SYSLOG_LEVEL_DEBUG1:
228 return log_facilities[i].val; 263 case SYSLOG_LEVEL_DEBUG2:
229 return (SyslogFacility) - 1; 264 case SYSLOG_LEVEL_DEBUG3:
265 log_level = level;
266 break;
267 default:
268 fprintf(stderr, "Unrecognized internal syslog level code %d\n",
269 (int) level);
270 exit(1);
271 }
272
273 log_on_stderr = on_stderr;
274 if (on_stderr)
275 return;
276
277 switch (facility) {
278 case SYSLOG_FACILITY_DAEMON:
279 log_facility = LOG_DAEMON;
280 break;
281 case SYSLOG_FACILITY_USER:
282 log_facility = LOG_USER;
283 break;
284 case SYSLOG_FACILITY_AUTH:
285 log_facility = LOG_AUTH;
286 break;
287#ifdef LOG_AUTHPRIV /** BAL: Verify */
288 case SYSLOG_FACILITY_AUTHPRIV
289 log_facility = AUTHPRIV;
290 break
291#endif
292 case SYSLOG_FACILITY_LOCAL0:
293 log_facility = LOG_LOCAL0;
294 break;
295 case SYSLOG_FACILITY_LOCAL1:
296 log_facility = LOG_LOCAL1;
297 break;
298 case SYSLOG_FACILITY_LOCAL2:
299 log_facility = LOG_LOCAL2;
300 break;
301 case SYSLOG_FACILITY_LOCAL3:
302 log_facility = LOG_LOCAL3;
303 break;
304 case SYSLOG_FACILITY_LOCAL4:
305 log_facility = LOG_LOCAL4;
306 break;
307 case SYSLOG_FACILITY_LOCAL5:
308 log_facility = LOG_LOCAL5;
309 break;
310 case SYSLOG_FACILITY_LOCAL6:
311 log_facility = LOG_LOCAL6;
312 break;
313 case SYSLOG_FACILITY_LOCAL7:
314 log_facility = LOG_LOCAL7;
315 break;
316 default:
317 fprintf(stderr,
318 "Unrecognized internal syslog facility code %d\n",
319 (int) facility);
320 exit(1);
321 }
230} 322}
231 323
232LogLevel 324#define MSGBUFSIZ 1024
233log_level_number(char *name) 325
326void
327do_log(LogLevel level, const char *fmt, va_list args)
234{ 328{
235 int i; 329 char msgbuf[MSGBUFSIZ];
236 if (name != NULL) 330 char fmtbuf[MSGBUFSIZ];
237 for (i = 0; log_levels[i].name; i++) 331 char *txt = NULL;
238 if (strcasecmp(log_levels[i].name, name) == 0) 332 int pri = LOG_INFO;
239 return log_levels[i].val; 333
240 return (LogLevel) - 1; 334 if (level > log_level)
335 return;
336
337 switch (level) {
338 case SYSLOG_LEVEL_FATAL:
339 if (!log_on_stderr)
340 txt = "fatal";
341 pri = LOG_CRIT;
342 break;
343 case SYSLOG_LEVEL_ERROR:
344 if (!log_on_stderr)
345 txt = "error";
346 pri = LOG_ERR;
347 break;
348 case SYSLOG_LEVEL_INFO:
349 pri = LOG_INFO;
350 break;
351 case SYSLOG_LEVEL_VERBOSE:
352 pri = LOG_INFO;
353 break;
354 case SYSLOG_LEVEL_DEBUG1:
355 txt = "debug1";
356 pri = LOG_DEBUG;
357 break;
358 case SYSLOG_LEVEL_DEBUG2:
359 txt = "debug2";
360 pri = LOG_DEBUG;
361 break;
362 case SYSLOG_LEVEL_DEBUG3:
363 txt = "debug3";
364 pri = LOG_DEBUG;
365 break;
366 default:
367 txt = "internal error";
368 pri = LOG_ERR;
369 break;
370 }
371 if (txt != NULL) {
372 snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", txt, fmt);
373 vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args);
374 } else {
375 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
376 }
377 if (log_on_stderr) {
378 fprintf(stderr, "%s\r\n", msgbuf);
379 } else {
380 openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
381 syslog(pri, "%.500s", msgbuf);
382 closelog();
383 }
241} 384}
diff --git a/ssh.c b/ssh.c
index c76c7bb71..a08ddf397 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: ssh.c,v 1.100 2001/03/01 22:46:37 markus Exp $"); 42RCSID("$OpenBSD: ssh.c,v 1.101 2001/03/03 23:59:34 markus Exp $");
43 43
44#include <openssl/evp.h> 44#include <openssl/evp.h>
45#include <openssl/err.h> 45#include <openssl/err.h>
@@ -556,9 +556,11 @@ main(int ac, char **av)
556 /* Take a copy of the returned structure. */ 556 /* Take a copy of the returned structure. */
557 pw = pwcopy(pw); 557 pw = pwcopy(pw);
558 558
559 /* Initialize "log" output. Since we are the client all output 559 /*
560 actually goes to the terminal. */ 560 * Initialize "log" output. Since we are the client all output
561 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 0); 561 * actually goes to stderr.
562 */
563 log_init(av[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
562 564
563 /* Read per-user configuration file. */ 565 /* Read per-user configuration file. */
564 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, _PATH_SSH_USER_CONFFILE); 566 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, _PATH_SSH_USER_CONFFILE);
@@ -571,7 +573,7 @@ main(int ac, char **av)
571 fill_default_options(&options); 573 fill_default_options(&options);
572 574
573 /* reinit */ 575 /* reinit */
574 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 0); 576 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 1);
575 577
576 if (options.user == NULL) 578 if (options.user == NULL)
577 options.user = xstrdup(pw->pw_name); 579 options.user = xstrdup(pw->pw_name);