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

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