1999-10-27 03:42:43 +00:00
|
|
|
/*
|
1999-11-24 13:26:21 +00:00
|
|
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
|
|
|
* All rights reserved
|
|
|
|
* Server-side versions of debug(), log(), etc. These normally send the output
|
|
|
|
* to the system log.
|
2000-04-16 01:18:38 +00:00
|
|
|
*
|
2000-09-16 02:29:08 +00:00
|
|
|
* As far as I am concerned, the code I have written for this software
|
|
|
|
* can be used freely for any purpose. Any derived versions of this
|
|
|
|
* software must be clearly marked as such, and if the derived work is
|
|
|
|
* incompatible with the protocol description in the RFC file, it must be
|
|
|
|
* called by a name other than "ssh" or "Secure Shell".
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000 Markus Friedl. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1999-11-24 13:26:21 +00:00
|
|
|
*/
|
1999-10-27 03:42:43 +00:00
|
|
|
|
|
|
|
#include "includes.h"
|
2000-09-16 02:29:08 +00:00
|
|
|
RCSID("$OpenBSD: log-server.c,v 1.17 2000/09/12 20:53:10 markus Exp $");
|
1999-10-27 03:42:43 +00:00
|
|
|
|
|
|
|
#include <syslog.h>
|
|
|
|
#include "packet.h"
|
|
|
|
#include "xmalloc.h"
|
|
|
|
#include "ssh.h"
|
|
|
|
|
1999-11-11 06:57:39 +00:00
|
|
|
static LogLevel log_level = SYSLOG_LEVEL_INFO;
|
1999-10-27 03:42:43 +00:00
|
|
|
static int log_on_stderr = 0;
|
1999-11-15 04:25:10 +00:00
|
|
|
static int log_facility = LOG_AUTH;
|
1999-10-27 03:42:43 +00:00
|
|
|
|
|
|
|
/* Initialize the log.
|
1999-11-24 13:26:21 +00:00
|
|
|
* av0 program name (should be argv[0])
|
|
|
|
* on_stderr print also on stderr
|
|
|
|
* level logging level
|
|
|
|
*/
|
1999-10-27 03:42:43 +00:00
|
|
|
|
2000-04-16 01:18:38 +00:00
|
|
|
void
|
1999-11-24 13:26:21 +00:00
|
|
|
log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
|
1999-10-27 03:42:43 +00:00
|
|
|
{
|
1999-11-24 13:26:21 +00:00
|
|
|
switch (level) {
|
|
|
|
case SYSLOG_LEVEL_QUIET:
|
|
|
|
case SYSLOG_LEVEL_ERROR:
|
|
|
|
case SYSLOG_LEVEL_FATAL:
|
|
|
|
case SYSLOG_LEVEL_INFO:
|
|
|
|
case SYSLOG_LEVEL_VERBOSE:
|
2000-09-16 02:29:08 +00:00
|
|
|
case SYSLOG_LEVEL_DEBUG1:
|
|
|
|
case SYSLOG_LEVEL_DEBUG2:
|
|
|
|
case SYSLOG_LEVEL_DEBUG3:
|
1999-11-24 13:26:21 +00:00
|
|
|
log_level = level;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unrecognized internal syslog level code %d\n",
|
|
|
|
(int) level);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
switch (facility) {
|
|
|
|
case SYSLOG_FACILITY_DAEMON:
|
|
|
|
log_facility = LOG_DAEMON;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_USER:
|
|
|
|
log_facility = LOG_USER;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_AUTH:
|
|
|
|
log_facility = LOG_AUTH;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL0:
|
|
|
|
log_facility = LOG_LOCAL0;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL1:
|
|
|
|
log_facility = LOG_LOCAL1;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL2:
|
|
|
|
log_facility = LOG_LOCAL2;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL3:
|
|
|
|
log_facility = LOG_LOCAL3;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL4:
|
|
|
|
log_facility = LOG_LOCAL4;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL5:
|
|
|
|
log_facility = LOG_LOCAL5;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL6:
|
|
|
|
log_facility = LOG_LOCAL6;
|
|
|
|
break;
|
|
|
|
case SYSLOG_FACILITY_LOCAL7:
|
|
|
|
log_facility = LOG_LOCAL7;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unrecognized internal syslog facility code %d\n",
|
|
|
|
(int) facility);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
log_on_stderr = on_stderr;
|
1999-10-27 03:42:43 +00:00
|
|
|
}
|
|
|
|
|
- OpenBSD CVS updates to v1.2.3
[ssh.h atomicio.c]
- int atomicio -> ssize_t (for alpha). ok deraadt@
[auth-rsa.c]
- delay MD5 computation until client sends response, free() early, cleanup.
[cipher.c]
- void* -> unsigned char*, ok niels@
[hostfile.c]
- remove unused variable 'len'. fix comments.
- remove unused variable
[log-client.c log-server.c]
- rename a cpp symbol, to avoid param.h collision
[packet.c]
- missing xfree()
- getsockname() requires initialized tolen; andy@guildsoftware.com
- use getpeername() in packet_connection_is_on_socket(), fixes sshd -i;
from Holger.Trapp@Informatik.TU-Chemnitz.DE
[pty.c pty.h]
- register cleanup for pty earlier. move code for pty-owner handling to
pty.c ok provos@, dugsong@
[readconf.c]
- turn off x11-fwd for the client, too.
[rsa.c]
- PKCS#1 padding
[scp.c]
- allow '.' in usernames; from jedgar@fxp.org
[servconf.c]
- typo: ignore_user_known_hosts int->flag; naddy@mips.rhein-neckar.de
- sync with sshd_config
[ssh-keygen.c]
- enable ssh-keygen -l -f ~/.ssh/known_hosts, ok deraadt@
[ssh.1]
- Change invalid 'CHAT' loglevel to 'VERBOSE'
[ssh.c]
- suppress AAAA query host when '-4' is used; from shin@nd.net.fujitsu.co.jp
- turn off x11-fwd for the client, too.
[sshconnect.c]
- missing xfree()
- retry rresvport_af(), too. from sumikawa@ebina.hitachi.co.jp.
- read error vs. "Connection closed by remote host"
[sshd.8]
- ie. -> i.e.,
- do not link to a commercial page..
- sync with sshd_config
[sshd.c]
- no need for poll.h; from bright@wintelcom.net
- log with level log() not fatal() if peer behaves badly.
- don't panic if client behaves strange. ok deraadt@
- make no-port-forwarding for RSA keys deny both -L and -R style fwding
- delay close() of pty until the pty has been chowned back to root
- oops, fix comment, too.
- missing xfree()
- move XAUTHORITY to subdir. ok dugsong@. fixes debian bug #57907, too.
(http://cgi.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=57907)
- register cleanup for pty earlier. move code for pty-owner handling to
pty.c ok provos@, dugsong@
- create x11 cookie file
- fix pr 1113, fclose() -> pclose(), todo: remote popen()
- version 1.2.3
- Cleaned up
2000-03-09 10:27:49 +00:00
|
|
|
#define MSGBUFSIZ 1024
|
1999-10-27 03:42:43 +00:00
|
|
|
|
1999-11-11 06:57:39 +00:00
|
|
|
void
|
|
|
|
do_log(LogLevel level, const char *fmt, va_list args)
|
1999-10-27 03:42:43 +00:00
|
|
|
{
|
- OpenBSD CVS updates to v1.2.3
[ssh.h atomicio.c]
- int atomicio -> ssize_t (for alpha). ok deraadt@
[auth-rsa.c]
- delay MD5 computation until client sends response, free() early, cleanup.
[cipher.c]
- void* -> unsigned char*, ok niels@
[hostfile.c]
- remove unused variable 'len'. fix comments.
- remove unused variable
[log-client.c log-server.c]
- rename a cpp symbol, to avoid param.h collision
[packet.c]
- missing xfree()
- getsockname() requires initialized tolen; andy@guildsoftware.com
- use getpeername() in packet_connection_is_on_socket(), fixes sshd -i;
from Holger.Trapp@Informatik.TU-Chemnitz.DE
[pty.c pty.h]
- register cleanup for pty earlier. move code for pty-owner handling to
pty.c ok provos@, dugsong@
[readconf.c]
- turn off x11-fwd for the client, too.
[rsa.c]
- PKCS#1 padding
[scp.c]
- allow '.' in usernames; from jedgar@fxp.org
[servconf.c]
- typo: ignore_user_known_hosts int->flag; naddy@mips.rhein-neckar.de
- sync with sshd_config
[ssh-keygen.c]
- enable ssh-keygen -l -f ~/.ssh/known_hosts, ok deraadt@
[ssh.1]
- Change invalid 'CHAT' loglevel to 'VERBOSE'
[ssh.c]
- suppress AAAA query host when '-4' is used; from shin@nd.net.fujitsu.co.jp
- turn off x11-fwd for the client, too.
[sshconnect.c]
- missing xfree()
- retry rresvport_af(), too. from sumikawa@ebina.hitachi.co.jp.
- read error vs. "Connection closed by remote host"
[sshd.8]
- ie. -> i.e.,
- do not link to a commercial page..
- sync with sshd_config
[sshd.c]
- no need for poll.h; from bright@wintelcom.net
- log with level log() not fatal() if peer behaves badly.
- don't panic if client behaves strange. ok deraadt@
- make no-port-forwarding for RSA keys deny both -L and -R style fwding
- delay close() of pty until the pty has been chowned back to root
- oops, fix comment, too.
- missing xfree()
- move XAUTHORITY to subdir. ok dugsong@. fixes debian bug #57907, too.
(http://cgi.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=57907)
- register cleanup for pty earlier. move code for pty-owner handling to
pty.c ok provos@, dugsong@
- create x11 cookie file
- fix pr 1113, fclose() -> pclose(), todo: remote popen()
- version 1.2.3
- Cleaned up
2000-03-09 10:27:49 +00:00
|
|
|
char msgbuf[MSGBUFSIZ];
|
|
|
|
char fmtbuf[MSGBUFSIZ];
|
1999-11-24 13:26:21 +00:00
|
|
|
char *txt = NULL;
|
|
|
|
int pri = LOG_INFO;
|
2000-11-17 03:47:20 +00:00
|
|
|
extern char *__progname;
|
1999-11-24 13:26:21 +00:00
|
|
|
|
|
|
|
if (level > log_level)
|
|
|
|
return;
|
|
|
|
switch (level) {
|
|
|
|
case SYSLOG_LEVEL_ERROR:
|
|
|
|
txt = "error";
|
|
|
|
pri = LOG_ERR;
|
|
|
|
break;
|
|
|
|
case SYSLOG_LEVEL_FATAL:
|
|
|
|
txt = "fatal";
|
|
|
|
pri = LOG_ERR;
|
|
|
|
break;
|
|
|
|
case SYSLOG_LEVEL_INFO:
|
|
|
|
case SYSLOG_LEVEL_VERBOSE:
|
|
|
|
pri = LOG_INFO;
|
|
|
|
break;
|
2000-09-16 02:29:08 +00:00
|
|
|
case SYSLOG_LEVEL_DEBUG1:
|
|
|
|
txt = "debug1";
|
|
|
|
pri = LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
case SYSLOG_LEVEL_DEBUG2:
|
|
|
|
txt = "debug2";
|
|
|
|
pri = LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
case SYSLOG_LEVEL_DEBUG3:
|
|
|
|
txt = "debug3";
|
1999-11-24 13:26:21 +00:00
|
|
|
pri = LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
txt = "internal error";
|
|
|
|
pri = LOG_ERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (txt != NULL) {
|
|
|
|
snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", txt, fmt);
|
|
|
|
vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args);
|
|
|
|
} else {
|
|
|
|
vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
|
|
|
|
}
|
2000-04-01 01:09:21 +00:00
|
|
|
if (log_on_stderr) {
|
1999-11-24 13:26:21 +00:00
|
|
|
fprintf(stderr, "%s\n", msgbuf);
|
2000-04-01 01:09:21 +00:00
|
|
|
} else {
|
|
|
|
openlog(__progname, LOG_PID, log_facility);
|
|
|
|
syslog(pri, "%.500s", msgbuf);
|
|
|
|
closelog();
|
|
|
|
}
|
1999-10-27 03:42:43 +00:00
|
|
|
}
|