Blame SOURCES/0005-Use-hostname-when-calling-PAM-authentication-module.patch

90e381
From 08c49b78942d40c99fae8c40e7668aa73e1bd695 Mon Sep 17 00:00:00 2001
90e381
From: Martin Sehnoutka <msehnout@redhat.com>
90e381
Date: Tue, 6 Sep 2016 15:01:23 +0200
90e381
Subject: [PATCH 05/59] Use hostname when calling PAM authentication module.
90e381
90e381
Currently the vsftpd passes all logins as IP addresses
90e381
into PAM. This prevents administrators from setting up
90e381
ACLs based on domain (e.g. .example.com). This patch
90e381
enables reverse host lookup and use hostname instead
90e381
of address if there is one.
90e381
---
90e381
 sysdeputil.c | 19 ++++++++++++++++---
90e381
 1 file changed, 16 insertions(+), 3 deletions(-)
90e381
90e381
diff --git a/sysdeputil.c b/sysdeputil.c
90e381
index 06f01f4..b2782da 100644
90e381
--- a/sysdeputil.c
90e381
+++ b/sysdeputil.c
90e381
@@ -16,6 +16,10 @@
90e381
 #include "tunables.h"
90e381
 #include "builddefs.h"
90e381
 
90e381
+/* For gethostbyaddr, inet_addr */
90e381
+#include <netdb.h>
90e381
+#include <arpa/inet.h>
90e381
+
90e381
 /* For Linux, this adds nothing :-) */
90e381
 #include "port/porting_junk.h"
90e381
 
90e381
@@ -323,6 +327,10 @@ vsf_sysdep_check_auth(struct mystr* p_user_str,
90e381
                       const struct mystr* p_remote_host)
90e381
 {
90e381
   int retval = -1;
90e381
+#ifdef PAM_RHOST
90e381
+  struct sockaddr_in sin;
90e381
+  struct hostent *host;
90e381
+#endif
90e381
   pam_item_t item;
90e381
   const char* pam_user_name = 0;
90e381
   struct pam_conv the_conv =
90e381
@@ -346,7 +354,12 @@ vsf_sysdep_check_auth(struct mystr* p_user_str,
90e381
     return 0;
90e381
   }
90e381
 #ifdef PAM_RHOST
90e381
-  retval = pam_set_item(s_pamh, PAM_RHOST, str_getbuf(p_remote_host));
90e381
+  sin.sin_addr.s_addr = inet_addr(str_getbuf(p_remote_host));
90e381
+  host = gethostbyaddr((char*)&sin.sin_addr.s_addr,sizeof(struct in_addr),AF_INET);
90e381
+  if (host != (struct hostent*)0)
90e381
+    retval = pam_set_item(s_pamh, PAM_RHOST, host->h_name);
90e381
+  else
90e381
+    retval = pam_set_item(s_pamh, PAM_RHOST, str_getbuf(p_remote_host));
90e381
   if (retval != PAM_SUCCESS)
90e381
   {
90e381
     (void) pam_end(s_pamh, retval);
90e381
@@ -559,7 +572,7 @@ vsf_sysdep_has_capabilities(void)
90e381
   }
90e381
   return s_runtime_has_caps;
90e381
 }
90e381
-  
90e381
+
90e381
   #ifndef VSF_SYSDEP_HAVE_LIBCAP
90e381
 static int
90e381
 do_checkcap(void)
90e381
@@ -1081,7 +1094,7 @@ vsf_sysutil_recv_fd(const int sock_fd)
90e381
   msg.msg_flags = 0;
90e381
   /* In case something goes wrong, set the fd to -1 before the syscall */
90e381
   p_fd = (int*)CMSG_DATA(CMSG_FIRSTHDR(&msg));
90e381
-  *p_fd = -1;  
90e381
+  *p_fd = -1;
90e381
   retval = recvmsg(sock_fd, &msg, 0);
90e381
   if (retval != 1)
90e381
   {
90e381
-- 
90e381
2.14.4
90e381