From 542ad675b9d241d5c508e49bd6b324658728c4e9 Mon Sep 17 00:00:00 2001 From: David Dykstra Date: Fri, 2 Aug 2002 15:39:43 +0000 Subject: [PATCH] Put in better method of checking whether or not daemon over --rsh mode is in place: simply check the "am_server" global variable, which is not set true when the daemon is listening for connections (daemon_main is not called in main.c if am_server is set). --- clientname.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/clientname.c b/clientname.c index 93ca68e1..9bd15cb4 100644 --- a/clientname.c +++ b/clientname.c @@ -34,6 +34,8 @@ #include "rsync.h" static const char default_name[] = "UNKNOWN"; +extern int am_daemon; +extern int am_server; /** @@ -44,6 +46,7 @@ char *client_addr(int fd) struct sockaddr_storage ss; socklen_t length = sizeof ss; char *ssh_client, *p; + int len; static char addr_buf[100]; static int initialised; @@ -51,14 +54,19 @@ char *client_addr(int fd) initialised = 1; - if ((ssh_client = getenv("SSH_CLIENT")) != NULL) { - strlcpy(addr_buf, ssh_client, sizeof(addr_buf)); - /* truncate SSH_CLIENT to just IP address */ - p = strchr(addr_buf, ' '); - if (p) - *p = '\0'; - else - strlcpy(addr_buf, "0.0.0.0", sizeof("0.0.0.0")); + if (am_server) { + /* daemon over --rsh mode */ + strcpy(addr_buf, "0.0.0.0"); + if ((ssh_client = getenv("SSH_CLIENT")) != NULL) { + /* truncate SSH_CLIENT to just IP address */ + p = strchr(ssh_client, ' '); + if (p) { + len = MIN((unsigned int) (p - ssh_client), + sizeof(addr_buf) - 1); + strncpy(addr_buf, ssh_client, len); + *(addr_buf + len) = '\0'; + } + } } else client_sockaddr(fd, &ss, &length); @@ -101,8 +109,9 @@ char *client_name(int fd) strcpy(name_buf, default_name); initialised = 1; - if (getenv("SSH_CLIENT") != NULL) { - /* Look up name of IP address given in $SSH_CLIENT */ + if (am_server) { + /* daemon over --rsh mode */ + char *addr = client_addr(fd); struct sockaddr_in sin; #ifdef INET6 -- 2.34.1