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

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