Fix --remove-source-files sanity check w/--copy-links the right way.
[rsync.git] / clientname.c
index 364169fa6f57d9b87cb80511b875fcc37cc1d4c3..4ac8b485aa73f7fc5c5fa0096cfe45f73f192f1c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1992-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2002-2008 Wayne Davison
+ * Copyright (C) 2002-2018 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,6 @@ char *client_addr(int fd)
        static int initialised;
        struct sockaddr_storage ss;
        socklen_t length = sizeof ss;
-       char *ssh_info, *p;
 
        if (initialised)
                return addr_buf;
@@ -49,11 +48,14 @@ char *client_addr(int fd)
        initialised = 1;
 
        if (am_server) {        /* daemon over --rsh mode */
+               char *env_str;
                strlcpy(addr_buf, "0.0.0.0", sizeof addr_buf);
-               if ((ssh_info = getenv("SSH_CONNECTION")) != NULL
-                   || (ssh_info = getenv("SSH_CLIENT")) != NULL
-                   || (ssh_info = getenv("SSH2_CLIENT")) != NULL) {
-                       strlcpy(addr_buf, ssh_info, sizeof addr_buf);
+               if ((env_str = getenv("REMOTE_HOST")) != NULL
+                || (env_str = getenv("SSH_CONNECTION")) != NULL
+                || (env_str = getenv("SSH_CLIENT")) != NULL
+                || (env_str = getenv("SSH2_CLIENT")) != NULL) {
+                       char *p;
+                       strlcpy(addr_buf, env_str, sizeof addr_buf);
                        /* Truncate the value to just the IP address. */
                        if ((p = strchr(addr_buf, ' ')) != NULL)
                                *p = '\0';
@@ -108,6 +110,9 @@ char *client_name(int fd)
                struct addrinfo hint, *answer;
                int err;
 
+               if (strcmp(addr, "0.0.0.0") == 0)
+                       return name_buf;
+
                memset(&hint, 0, sizeof hint);
 
 #ifdef AI_NUMERICHOST