Bug 973

Summary: sshd behaves differently while doing syslog entries for tcpwrappers denied message, with -r and without -r option.
Product: Portable OpenSSH Reporter: Logu <logsnaath>
Component: sshdAssignee: OpenSSH Bugzilla mailing list <openssh-bugs>
Status: CLOSED FIXED    
Severity: normal CC: atlunde
Priority: P2 Keywords: patch
Version: 3.9p1   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 914    
Attachments:
Description Flags
reinit log after receiving config after reexec
none
reinit log after reexec, take 2
none
reinit log after reexec, take 3
none
force log_init to reopen syslog
none
force reopen of syslog (fixed for openlog_r too) none

Description Logu 2005-01-17 13:40:51 AEDT
When sshd is run without -r option the syslog messages from tcpwrappers denied 
message are not written to the configured syslog file. This happens when syslog
facility is given as local7 and the level is given as info in the sshd
configuration file
Comment 1 Darren Tucker 2005-01-17 15:29:23 AEDT
Created attachment 769 [details]
reinit log after receiving config after reexec

I think I see the problem: when reexec is enabled, log_init() is called before
recv_rexec_state() and load_server_config(), so the log will be pointing to
whatever the default is.

Please try this patch.
Comment 2 Darren Tucker 2005-01-17 15:34:28 AEDT
Created attachment 770 [details]
reinit log after reexec, take 2

Please try this one instead, it should also work when the log params are left
unset.
Comment 3 Logu 2005-01-17 21:55:15 AEDT
I tried both the patches but still the log messages of tcp wrapper are not 
written to configured syslog file. 
Comment 4 Darren Tucker 2005-01-17 22:03:43 AEDT
What platform (and version) are you seeing the problem on ?
Comment 5 Logu 2005-01-17 22:47:53 AEDT
OpenSSH Version : 3.9p1
Platform :  Fedora core 2
kernel : 2.6.5-1.358
Comment 6 Darren Tucker 2005-01-17 23:11:14 AEDT
Which message is missing?  Is it this one:
sshd: refused connect from [foo] ?
Comment 7 Logu 2005-01-17 23:39:58 AEDT
I have these two entries in /etc/syslog.conf
local7.info                                             /var/log/ssh.log
*.info;mail.none;authpriv.none;cron.none;local7.none    /var/log/messages

The message "sshd: refused connect from [foo]" appears in /var/log/messages but
not in /var/log/ssh.log.

But when sshd is run with -r option the message goes to /var/log/ssh.log alone
Comment 8 Darren Tucker 2005-01-17 23:48:56 AEDT
What do you have SyslogFacility and LogLevel set to in sshd_config? 
Comment 9 Logu 2005-01-18 00:30:49 AEDT
my /etc/sshd_config file has
SyslogFacility LOCAL7
LogLevel INFO

Comment 10 Darren Tucker 2005-01-19 19:22:11 AEDT
Created attachment 772 [details]
reinit log after reexec, take 3

OK, I think I have it: log_init doesn't get called correctly at the point
refuse() is called, so the messages get sent to the wrong place.

Please try this patch.	If it works I'll dig out my ouija board and try to
determine how it's supposed to work when reexec is enabled :-)
Comment 11 Logu 2005-01-19 21:28:34 AEDT
I tried the patch 3, but still the problem persists. 
Comment 12 Darren Tucker 2005-01-19 22:51:51 AEDT
Created attachment 773 [details]
force log_init to reopen syslog

Sigh.  OK, new theory: although log_init has been called, openlog() hasn't so
when libwrap calls syslog it still points to the default settings.

Since the log functions do openlog/closelog, logging *anything* means that it
will be pointing at the right place afterward (which meant that the debugging I
added while working on it that made the problem go away, not the alleged fixes.
 A neato Heisenbug).

Hopefully this patch will finally nail it; I mean, at some point I have to run
out of wrong ideas, right :-?
Comment 13 Logu 2005-01-20 00:05:52 AEDT
Great. This patch worked. 
Comment 14 Darren Tucker 2005-01-24 22:15:13 AEDT
*** Bug 948 has been marked as a duplicate of this bug. ***
Comment 15 Darren Tucker 2005-01-24 23:47:31 AEDT
It appears that OpenBSD's libwrap (or, more likely, its syslog libraries) are
not fooled so easily.  The refuse message always goes to the default log
(/var/log/messages on my box) and not to sshd's SyslogFacility, regardless of
whether or not reexec is invoked and/or messages are logged before the refuse.

I suspect it boils down to what the OS does in this case:

openlog(..., int facility);
syslog(..., "message1");
closelog();
syslog(..., "message2");

It appears that on OpenBSD, message1 will go to different places if the facility
is set.  On other platforms, message2 will end up wherever message1 went (as you
saw).

The upshot is that if we're going to do something about it, it ought to be
-Portable only (new patch to follow).
Comment 16 Darren Tucker 2005-01-24 23:50:13 AEDT
Created attachment 786 [details]
force reopen of syslog (fixed for openlog_r too)

Force reopen of syslog, which should mean that behaviour should at least be
consistent on all platforms regardless of whether or not reexec is enabled. 
OK?
Comment 17 Darren Tucker 2005-02-01 17:36:06 AEDT
Patch #786 committed.  Thanks for the report.
Comment 18 Darren Tucker 2005-03-10 09:07:44 AEDT
With the release of OpenSSH 4.0, these bugs are now closed. For details, see:
http://www.openssh.com/txt/release-4.0