summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-11-05 15:16:52 +1100
committerDamien Miller <djm@mindrot.org>2005-11-05 15:16:52 +1100
commit24ecf612614d83622d9777349b4ecd21ee22bb2a (patch)
tree60adc67bc4916fd177de9fc664f6cbbe5b115837
parent83d0d39d0e30d545d9caa94089b92739a479dff1 (diff)
- dtucker@cvs.openbsd.org 2005/11/03 13:38:29
[canohost.c] Cache reverse lookups with and without DNS separately; ok markus@
-rw-r--r--ChangeLog5
-rw-r--r--canohost.c27
-rw-r--r--serverloop.c36
3 files changed, 53 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index e4f703fe..cefc3e0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -90,6 +90,9 @@
- jmc@cvs.openbsd.org 2005/10/31 19:55:25
[ssh-keygen.1]
grammar;
+ - dtucker@cvs.openbsd.org 2005/11/03 13:38:29
+ [canohost.c]
+ Cache reverse lookups with and without DNS separately; ok markus@
20051102
- (dtucker) [openbsd-compat/bsd-misc.c] Bug #1108: fix broken strdup().
@@ -3223,4 +3226,4 @@
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
-$Id: ChangeLog,v 1.3949 2005/11/05 04:16:27 djm Exp $
+$Id: ChangeLog,v 1.3950 2005/11/05 04:16:52 djm Exp $
diff --git a/canohost.c b/canohost.c
index 66867c10..bd7f830d 100644
--- a/canohost.c
+++ b/canohost.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: canohost.c,v 1.46 2005/10/30 08:29:29 dtucker Exp $");
+RCSID("$OpenBSD: canohost.c,v 1.47 2005/11/03 13:38:29 dtucker Exp $");
#include "packet.h"
#include "xmalloc.h"
@@ -198,26 +198,27 @@ ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)
const char *
get_canonical_hostname(int use_dns)
{
+ char *host;
static char *canonical_host_name = NULL;
- static int use_dns_done = 0;
+ static char *remote_ip = NULL;
/* Check if we have previously retrieved name with same option. */
- if (canonical_host_name != NULL) {
- if (use_dns_done != use_dns)
- xfree(canonical_host_name);
- else
- return canonical_host_name;
- }
+ if (use_dns && canonical_host_name != NULL)
+ return canonical_host_name;
+ if (!use_dns && remote_ip != NULL)
+ return remote_ip;
/* Get the real hostname if socket; otherwise return UNKNOWN. */
if (packet_connection_is_on_socket())
- canonical_host_name = get_remote_hostname(
- packet_get_connection_in(), use_dns);
+ host = get_remote_hostname(packet_get_connection_in(), use_dns);
else
- canonical_host_name = xstrdup("UNKNOWN");
+ host = "UNKNOWN";
- use_dns_done = use_dns;
- return canonical_host_name;
+ if (use_dns)
+ canonical_host_name = host;
+ else
+ remote_ip = host;
+ return host;
}
/*
diff --git a/serverloop.c b/serverloop.c
index 208f7e1e..03376bac 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -35,7 +35,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: serverloop.c,v 1.120 2005/10/30 08:52:17 djm Exp $");
+RCSID("$OpenBSD: serverloop.c,v 1.121 2005/10/31 11:48:29 djm Exp $");
#include "xmalloc.h"
#include "packet.h"
@@ -61,6 +61,7 @@ extern ServerOptions options;
/* XXX */
extern Kex *xxx_kex;
extern Authctxt *the_authctxt;
+extern int use_privsep;
static Buffer stdin_buffer; /* Buffer for stdin data. */
static Buffer stdout_buffer; /* Buffer for stdout data. */
@@ -90,6 +91,9 @@ static int client_alive_timeouts = 0;
static volatile sig_atomic_t child_terminated = 0; /* The child has terminated. */
+/* Cleanup on signals (!use_privsep case only) */
+static volatile sig_atomic_t received_sigterm = 0;
+
/* prototypes */
static void server_init_dispatch(void);
@@ -151,6 +155,12 @@ sigchld_handler(int sig)
errno = save_errno;
}
+static void
+sigterm_handler(int sig)
+{
+ received_sigterm = sig;
+}
+
/*
* Make packets from buffered stderr data, and buffer it for sending
* to the client.
@@ -502,6 +512,12 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
child_terminated = 0;
mysignal(SIGCHLD, sigchld_handler);
+ if (!use_privsep) {
+ signal(SIGTERM, sigterm_handler);
+ signal(SIGINT, sigterm_handler);
+ signal(SIGQUIT, sigterm_handler);
+ }
+
/* Initialize our global variables. */
fdin = fdin_arg;
fdout = fdout_arg;
@@ -629,6 +645,12 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
wait_until_can_do_something(&readset, &writeset, &max_fd,
&nalloc, max_time_milliseconds);
+ if (received_sigterm) {
+ logit("Exiting on signal %d", received_sigterm);
+ /* Clean up sessions, utmp, etc. */
+ cleanup_exit(255);
+ }
+
/* Process any channel events. */
channel_after_select(readset, writeset);
@@ -749,6 +771,12 @@ server_loop2(Authctxt *authctxt)
connection_in = packet_get_connection_in();
connection_out = packet_get_connection_out();
+ if (!use_privsep) {
+ signal(SIGTERM, sigterm_handler);
+ signal(SIGINT, sigterm_handler);
+ signal(SIGQUIT, sigterm_handler);
+ }
+
notify_setup();
max_fd = MAX(connection_in, connection_out);
@@ -766,6 +794,12 @@ server_loop2(Authctxt *authctxt)
wait_until_can_do_something(&readset, &writeset, &max_fd,
&nalloc, 0);
+ if (received_sigterm) {
+ logit("Exiting on signal %d", received_sigterm);
+ /* Clean up sessions, utmp, etc. */
+ cleanup_exit(255);
+ }
+
collect_children();
if (!rekeying) {
channel_after_select(readset, writeset);