summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorRuss Allbery <rra@dropbox.com>2016-07-28 01:12:22 -0700
committerRuss Allbery <rra@dropbox.com>2016-07-28 01:40:26 -0700
commit5f8d20b8e04376252d0cea8f77e4a84c0d0a2262 (patch)
tree54709dfc258f2a6a9457443e6ba45d68f90c4787 /server
parent5dce1ad30db769d0a8ceaaf040df6fa229462d60 (diff)
Add REMCTL_HOST support to remctl-shell
Also add a warning to the documentation for both remctld and remctl-shell that this is based on a reverse DNS lookup and isn't reliable.
Diffstat (limited to 'server')
-rw-r--r--server/server-ssh.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/server/server-ssh.c b/server/server-ssh.c
index e7b2faa..1b48447 100644
--- a/server/server-ssh.c
+++ b/server/server-ssh.c
@@ -13,6 +13,7 @@
#include <config.h>
#include <portable/event.h>
+#include <portable/socket.h>
#include <portable/system.h>
#include <ctype.h>
@@ -233,6 +234,10 @@ server_ssh_new_client(void)
struct client *client;
const char *ssh_client, *user;
struct vector *client_info;
+ struct addrinfo hints;
+ struct addrinfo *result;
+ char *buffer;
+ int status;
/* Parse client identity from ssh environment variables. */
user = getenv("REMCTL_USER");
@@ -251,6 +256,22 @@ server_ssh_new_client(void)
client->protocol = 3;
client->user = xstrdup(user);
+ /* Get the remote hostname. */
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ status = getaddrinfo(client->ipaddress, NULL, &hints, &result);
+ if (status == 0) {
+ buffer = xmalloc(NI_MAXHOST);
+ status = getnameinfo(result->ai_addr, result->ai_addrlen, buffer,
+ NI_MAXHOST, NULL, 0, NI_NAMEREQD);
+ if (status == 0)
+ client->hostname = buffer;
+ else
+ free(buffer);
+ freeaddrinfo(result);
+ }
+
/* Add ssh protocol callbacks. */
client->setup = command_setup;
client->finish = command_finish;