summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--log.c20
-rw-r--r--log.h3
-rw-r--r--ssh.19
-rw-r--r--ssh.c28
-rw-r--r--sshd.89
-rw-r--r--sshd.c19
7 files changed, 72 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 47c7ce01c..51077256d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -39,6 +39,10 @@
39 - markus@cvs.openbsd.org 2013/04/06 16:07:00 39 - markus@cvs.openbsd.org 2013/04/06 16:07:00
40 [channels.c sshd.c] 40 [channels.c sshd.c]
41 handle ECONNABORTED for accept(); ok deraadt some time ago... 41 handle ECONNABORTED for accept(); ok deraadt some time ago...
42 - dtucker@cvs.openbsd.org 2013/04/07 02:10:33
43 [log.c log.h ssh.1 ssh.c sshd.8 sshd.c]
44 Add -E option to ssh and sshd to append debugging logs to a specified file
45 instead of stderr or syslog. ok markus@, man page help jmc@
42 46
4320130418 4720130418
44 - (djm) [config.guess config.sub] Update to last versions before they switch 48 - (djm) [config.guess config.sub] Update to last versions before they switch
diff --git a/log.c b/log.c
index d69154a67..81497a442 100644
--- a/log.c
+++ b/log.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: log.c,v 1.43 2012/09/06 04:37:39 dtucker Exp $ */ 1/* $OpenBSD: log.c,v 1.44 2013/04/07 02:10:33 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -38,6 +38,7 @@
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40 40
41#include <fcntl.h>
41#include <stdarg.h> 42#include <stdarg.h>
42#include <stdio.h> 43#include <stdio.h>
43#include <stdlib.h> 44#include <stdlib.h>
@@ -54,6 +55,7 @@
54 55
55static LogLevel log_level = SYSLOG_LEVEL_INFO; 56static LogLevel log_level = SYSLOG_LEVEL_INFO;
56static int log_on_stderr = 1; 57static int log_on_stderr = 1;
58static int log_stderr_fd = STDERR_FILENO;
57static int log_facility = LOG_AUTH; 59static int log_facility = LOG_AUTH;
58static char *argv0; 60static char *argv0;
59static log_handler_fn *log_handler; 61static log_handler_fn *log_handler;
@@ -344,6 +346,20 @@ log_is_on_stderr(void)
344 return log_on_stderr; 346 return log_on_stderr;
345} 347}
346 348
349/* redirect what would usually get written to stderr to specified file */
350void
351log_redirect_stderr_to(const char *logfile)
352{
353 int fd;
354
355 if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600)) == -1) {
356 fprintf(stderr, "Couldn't open logfile %s: %s\n", logfile,
357 strerror(errno));
358 exit(1);
359 }
360 log_stderr_fd = fd;
361}
362
347#define MSGBUFSIZ 1024 363#define MSGBUFSIZ 1024
348 364
349void 365void
@@ -429,7 +445,7 @@ do_log(LogLevel level, const char *fmt, va_list args)
429 log_handler = tmp_handler; 445 log_handler = tmp_handler;
430 } else if (log_on_stderr) { 446 } else if (log_on_stderr) {
431 snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); 447 snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
432 write(STDERR_FILENO, msgbuf, strlen(msgbuf)); 448 write(log_stderr_fd, msgbuf, strlen(msgbuf));
433 } else { 449 } else {
434#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) 450#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
435 openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata); 451 openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
diff --git a/log.h b/log.h
index e3e328b06..ae7df25d3 100644
--- a/log.h
+++ b/log.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: log.h,v 1.19 2012/09/06 04:37:39 dtucker Exp $ */ 1/* $OpenBSD: log.h,v 1.20 2013/04/07 02:10:33 dtucker Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -51,6 +51,7 @@ typedef void (log_handler_fn)(LogLevel, const char *, void *);
51void log_init(char *, LogLevel, SyslogFacility, int); 51void log_init(char *, LogLevel, SyslogFacility, int);
52void log_change_level(LogLevel); 52void log_change_level(LogLevel);
53int log_is_on_stderr(void); 53int log_is_on_stderr(void);
54void log_redirect_stderr_to(const char *);
54 55
55SyslogFacility log_facility_number(char *); 56SyslogFacility log_facility_number(char *);
56const char * log_facility_name(SyslogFacility); 57const char * log_facility_name(SyslogFacility);
diff --git a/ssh.1 b/ssh.1
index a5576edb6..d77494b83 100644
--- a/ssh.1
+++ b/ssh.1
@@ -33,8 +33,8 @@
33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: ssh.1,v 1.330 2012/10/04 13:21:50 markus Exp $ 36.\" $OpenBSD: ssh.1,v 1.331 2013/04/07 02:10:33 dtucker Exp $
37.Dd $Mdocdate: October 4 2012 $ 37.Dd $Mdocdate: April 7 2013 $
38.Dt SSH 1 38.Dt SSH 1
39.Os 39.Os
40.Sh NAME 40.Sh NAME
@@ -47,6 +47,7 @@
47.Op Fl b Ar bind_address 47.Op Fl b Ar bind_address
48.Op Fl c Ar cipher_spec 48.Op Fl c Ar cipher_spec
49.Op Fl D Oo Ar bind_address : Oc Ns Ar port 49.Op Fl D Oo Ar bind_address : Oc Ns Ar port
50.Op Fl E Ar log_file
50.Op Fl e Ar escape_char 51.Op Fl e Ar escape_char
51.Op Fl F Ar configfile 52.Op Fl F Ar configfile
52.Op Fl I Ar pkcs11 53.Op Fl I Ar pkcs11
@@ -217,6 +218,10 @@ indicates that the listening port be bound for local use only, while an
217empty address or 218empty address or
218.Sq * 219.Sq *
219indicates that the port should be available from all interfaces. 220indicates that the port should be available from all interfaces.
221.It Fl E Ar log_file
222Append debug logs to
223.Ar log_file
224instead of standard error.
220.It Fl e Ar escape_char 225.It Fl e Ar escape_char
221Sets the escape character for sessions with a pty (default: 226Sets the escape character for sessions with a pty (default:
222.Ql ~ ) . 227.Ql ~ ) .
diff --git a/ssh.c b/ssh.c
index b50fca38f..cd56f8a74 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.374 2013/03/08 06:32:58 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.375 2013/04/07 02:10:33 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -197,8 +197,8 @@ usage(void)
197{ 197{
198 fprintf(stderr, 198 fprintf(stderr,
199"usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]\n" 199"usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]\n"
200" [-D [bind_address:]port] [-e escape_char] [-F configfile]\n" 200" [-D [bind_address:]port] [-E log_file] [-e escape_char]\n"
201" [-I pkcs11] [-i identity_file]\n" 201" [-F configfile] [-I pkcs11] [-i identity_file]\n"
202" [-L [bind_address:]port:host:hostport]\n" 202" [-L [bind_address:]port:host:hostport]\n"
203" [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\n" 203" [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\n"
204" [-R [bind_address:]port:host:hostport] [-S ctl_path]\n" 204" [-R [bind_address:]port:host:hostport] [-S ctl_path]\n"
@@ -238,7 +238,7 @@ int
238main(int ac, char **av) 238main(int ac, char **av)
239{ 239{
240 int i, r, opt, exit_status, use_syslog; 240 int i, r, opt, exit_status, use_syslog;
241 char *p, *cp, *line, *argv0, buf[MAXPATHLEN], *host_arg; 241 char *p, *cp, *line, *argv0, buf[MAXPATHLEN], *host_arg, *logfile;
242 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV]; 242 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
243 struct stat st; 243 struct stat st;
244 struct passwd *pw; 244 struct passwd *pw;
@@ -322,11 +322,12 @@ main(int ac, char **av)
322 /* Parse command-line arguments. */ 322 /* Parse command-line arguments. */
323 host = NULL; 323 host = NULL;
324 use_syslog = 0; 324 use_syslog = 0;
325 logfile = NULL;
325 argv0 = av[0]; 326 argv0 = av[0];
326 327
327 again: 328 again:
328 while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx" 329 while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx"
329 "ACD:F:I:KL:MNO:PR:S:TVw:W:XYy")) != -1) { 330 "ACD:E:F:I:KL:MNO:PR:S:TVw:W:XYy")) != -1) {
330 switch (opt) { 331 switch (opt) {
331 case '1': 332 case '1':
332 options.protocol = SSH_PROTO_1; 333 options.protocol = SSH_PROTO_1;
@@ -356,6 +357,9 @@ main(int ac, char **av)
356 case 'y': 357 case 'y':
357 use_syslog = 1; 358 use_syslog = 1;
358 break; 359 break;
360 case 'E':
361 logfile = xstrdup(optarg);
362 break;
359 case 'Y': 363 case 'Y':
360 options.forward_x11 = 1; 364 options.forward_x11 = 1;
361 options.forward_x11_trusted = 1; 365 options.forward_x11_trusted = 1;
@@ -427,9 +431,8 @@ main(int ac, char **av)
427 } else { 431 } else {
428 if (options.log_level < SYSLOG_LEVEL_DEBUG3) 432 if (options.log_level < SYSLOG_LEVEL_DEBUG3)
429 options.log_level++; 433 options.log_level++;
430 break;
431 } 434 }
432 /* FALLTHROUGH */ 435 break;
433 case 'V': 436 case 'V':
434 fprintf(stderr, "%s, %s\n", 437 fprintf(stderr, "%s, %s\n",
435 SSH_RELEASE, SSLeay_version(SSLEAY_VERSION)); 438 SSH_RELEASE, SSLeay_version(SSLEAY_VERSION));
@@ -663,12 +666,21 @@ main(int ac, char **av)
663 666
664 /* 667 /*
665 * Initialize "log" output. Since we are the client all output 668 * Initialize "log" output. Since we are the client all output
666 * actually goes to stderr. 669 * goes to stderr unless otherwise specified by -y or -E.
667 */ 670 */
671 if (use_syslog && logfile != NULL)
672 fatal("Can't specify both -y and -E");
673 if (logfile != NULL) {
674 log_redirect_stderr_to(logfile);
675 xfree(logfile);
676 }
668 log_init(argv0, 677 log_init(argv0,
669 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level, 678 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
670 SYSLOG_FACILITY_USER, !use_syslog); 679 SYSLOG_FACILITY_USER, !use_syslog);
671 680
681 if (debug_flag)
682 logit("%s, %s", SSH_VERSION, SSLeay_version(SSLEAY_VERSION));
683
672 /* 684 /*
673 * Read per-user configuration file. Ignore the system wide config 685 * Read per-user configuration file. Ignore the system wide config
674 * file if the user specifies a config file on the command line. 686 * file if the user specifies a config file on the command line.
diff --git a/sshd.8 b/sshd.8
index 132397839..3ce0da6a3 100644
--- a/sshd.8
+++ b/sshd.8
@@ -33,8 +33,8 @@
33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: sshd.8,v 1.267 2012/10/04 13:21:50 markus Exp $ 36.\" $OpenBSD: sshd.8,v 1.268 2013/04/07 02:10:33 dtucker Exp $
37.Dd $Mdocdate: October 4 2012 $ 37.Dd $Mdocdate: April 7 2013 $
38.Dt SSHD 8 38.Dt SSHD 8
39.Os 39.Os
40.Sh NAME 40.Sh NAME
@@ -47,6 +47,7 @@
47.Op Fl b Ar bits 47.Op Fl b Ar bits
48.Op Fl C Ar connection_spec 48.Op Fl C Ar connection_spec
49.Op Fl c Ar host_certificate_file 49.Op Fl c Ar host_certificate_file
50.Op Fl E Ar log_file
50.Op Fl f Ar config_file 51.Op Fl f Ar config_file
51.Op Fl g Ar login_grace_time 52.Op Fl g Ar login_grace_time
52.Op Fl h Ar host_key_file 53.Op Fl h Ar host_key_file
@@ -146,6 +147,10 @@ Multiple
146.Fl d 147.Fl d
147options increase the debugging level. 148options increase the debugging level.
148Maximum is 3. 149Maximum is 3.
150.It Fl E Ar log_file
151Append debug logs to
152.Ar log_file
153instead of the system log.
149.It Fl e 154.It Fl e
150When this option is specified, 155When this option is specified,
151.Nm 156.Nm
diff --git a/sshd.c b/sshd.c
index 5fb2897fa..a0f5c0d26 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.398 2013/04/06 16:07:00 markus Exp $ */ 1/* $OpenBSD: sshd.c,v 1.399 2013/04/07 02:10:33 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -900,8 +900,9 @@ usage(void)
900 SSH_RELEASE, SSLeay_version(SSLEAY_VERSION)); 900 SSH_RELEASE, SSLeay_version(SSLEAY_VERSION));
901 fprintf(stderr, 901 fprintf(stderr,
902"usage: sshd [-46DdeiqTt] [-b bits] [-C connection_spec] [-c host_cert_file]\n" 902"usage: sshd [-46DdeiqTt] [-b bits] [-C connection_spec] [-c host_cert_file]\n"
903" [-f config_file] [-g login_grace_time] [-h host_key_file]\n" 903" [-E log_file] [-f config_file] [-g login_grace_time]\n"
904" [-k key_gen_time] [-o option] [-p port] [-u len]\n" 904" [-h host_key_file] [-k key_gen_time] [-o option] [-p port]\n"
905" [-u len]\n"
905 ); 906 );
906 exit(1); 907 exit(1);
907} 908}
@@ -1335,7 +1336,7 @@ main(int ac, char **av)
1335 int sock_in = -1, sock_out = -1, newsock = -1; 1336 int sock_in = -1, sock_out = -1, newsock = -1;
1336 const char *remote_ip; 1337 const char *remote_ip;
1337 int remote_port; 1338 int remote_port;
1338 char *line; 1339 char *line, *logfile = NULL;
1339 int config_s[2] = { -1 , -1 }; 1340 int config_s[2] = { -1 , -1 };
1340 u_int n; 1341 u_int n;
1341 u_int64_t ibytes, obytes; 1342 u_int64_t ibytes, obytes;
@@ -1373,7 +1374,7 @@ main(int ac, char **av)
1373 initialize_server_options(&options); 1374 initialize_server_options(&options);
1374 1375
1375 /* Parse command-line arguments. */ 1376 /* Parse command-line arguments. */
1376 while ((opt = getopt(ac, av, "f:p:b:k:h:g:u:o:C:dDeiqrtQRT46")) != -1) { 1377 while ((opt = getopt(ac, av, "f:p:b:k:h:g:u:o:C:dDeE:iqrtQRT46")) != -1) {
1377 switch (opt) { 1378 switch (opt) {
1378 case '4': 1379 case '4':
1379 options.address_family = AF_INET; 1380 options.address_family = AF_INET;
@@ -1402,6 +1403,9 @@ main(int ac, char **av)
1402 case 'D': 1403 case 'D':
1403 no_daemon_flag = 1; 1404 no_daemon_flag = 1;
1404 break; 1405 break;
1406 case 'E':
1407 logfile = xstrdup(optarg);
1408 /* FALLTHROUGH */
1405 case 'e': 1409 case 'e':
1406 log_stderr = 1; 1410 log_stderr = 1;
1407 break; 1411 break;
@@ -1499,6 +1503,11 @@ main(int ac, char **av)
1499 1503
1500 OpenSSL_add_all_algorithms(); 1504 OpenSSL_add_all_algorithms();
1501 1505
1506 /* If requested, redirect the logs to the specified logfile. */
1507 if (logfile != NULL) {
1508 log_redirect_stderr_to(logfile);
1509 xfree(logfile);
1510 }
1502 /* 1511 /*
1503 * Force logging to stderr until we have loaded the private host 1512 * Force logging to stderr until we have loaded the private host
1504 * key (unless started from inetd) 1513 * key (unless started from inetd)