Blame SOURCES/0001-Fix-rDNS-with-IPv6.patch

993209
From 01b646d2af0ed885d01d31a6479898a3c423a630 Mon Sep 17 00:00:00 2001
993209
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
993209
Date: Thu, 26 Apr 2018 10:00:19 +0200
993209
Subject: [PATCH] Fix rDNS with IPv6
993209
993209
Previously IPv6 addresses were not translated to hostnames for PAM to use.
993209
---
993209
 privops.c    |  3 ++-
993209
 sysdeputil.c | 28 +++++++++++++++-------------
993209
 sysdeputil.h |  5 ++++-
993209
 sysutil.c    | 35 +++++++++++++++++++++++++++++++++++
993209
 sysutil.h    |  4 ++++
993209
 5 files changed, 60 insertions(+), 15 deletions(-)
993209
993209
diff --git a/privops.c b/privops.c
993209
index f27c5c4..e577a27 100644
993209
--- a/privops.c
993209
+++ b/privops.c
993209
@@ -383,7 +383,8 @@ handle_local_login(struct vsf_session* p_sess,
993209
                    struct mystr* p_user_str,
993209
                    const struct mystr* p_pass_str)
993209
 {
993209
-  if (!vsf_sysdep_check_auth(p_user_str, p_pass_str, &p_sess->remote_ip_str))
993209
+  if (!vsf_sysdep_check_auth(p_sess, p_user_str, p_pass_str,
993209
+                             &p_sess->remote_ip_str))
993209
   {
993209
     return kVSFLoginFail;
993209
   }
993209
diff --git a/sysdeputil.c b/sysdeputil.c
993209
index 2063c87..4fe56c2 100644
993209
--- a/sysdeputil.c
993209
+++ b/sysdeputil.c
993209
@@ -16,10 +16,6 @@
993209
 #include "tunables.h"
993209
 #include "builddefs.h"
993209
 
993209
-/* For gethostbyaddr, inet_addr */
993209
-#include <netdb.h>
993209
-#include <arpa/inet.h>
993209
-
993209
 /* For Linux, this adds nothing :-) */
993209
 #include "port/porting_junk.h"
993209
 
993209
@@ -242,13 +238,15 @@ void vsf_remove_uwtmp(void);
993209
 
993209
 #ifndef VSF_SYSDEP_HAVE_PAM
993209
 int
993209
-vsf_sysdep_check_auth(struct mystr* p_user_str,
993209
+vsf_sysdep_check_auth(struct vsf_session* p_sess,
993209
+                      struct mystr* p_user_str,
993209
                       const struct mystr* p_pass_str,
993209
                       const struct mystr* p_remote_host)
993209
 {
993209
   const char* p_crypted;
993209
   const struct passwd* p_pwd = getpwnam(str_getbuf(p_user_str));
993209
   (void) p_remote_host;
993209
+  (void) p_sess;
993209
   if (p_pwd == NULL)
993209
   {
993209
     return 0;
993209
@@ -322,14 +320,14 @@ static int pam_conv_func(int nmsg, const struct pam_message** p_msg,
993209
 static void vsf_auth_shutdown(void);
993209
 
993209
 int
993209
-vsf_sysdep_check_auth(struct mystr* p_user_str,
993209
+vsf_sysdep_check_auth(struct vsf_session* p_sess,
993209
+                      struct mystr* p_user_str,
993209
                       const struct mystr* p_pass_str,
993209
                       const struct mystr* p_remote_host)
993209
 {
993209
   int retval = -1;
993209
 #ifdef PAM_RHOST
993209
-  struct sockaddr_in sin;
993209
-  struct hostent *host;
993209
+  struct mystr hostname = INIT_MYSTR;
993209
 #endif
993209
   pam_item_t item;
993209
   const char* pam_user_name = 0;
993209
@@ -354,13 +352,17 @@ vsf_sysdep_check_auth(struct mystr* p_user_str,
993209
     return 0;
993209
   }
993209
 #ifdef PAM_RHOST
993209
-  if (tunable_reverse_lookup_enable) {
993209
-    sin.sin_addr.s_addr = inet_addr(str_getbuf(p_remote_host));
993209
-    host = gethostbyaddr((char*)&sin.sin_addr.s_addr,sizeof(struct in_addr),AF_INET);
993209
-    if (host != (struct hostent*)0)
993209
-      retval = pam_set_item(s_pamh, PAM_RHOST, host->h_name);
993209
+  if (tunable_reverse_lookup_enable)
993209
+  {
993209
+    if (vsf_sysutil_get_hostname(p_sess->p_remote_addr, &hostname) == 0)
993209
+    {
993209
+      retval = pam_set_item(s_pamh, PAM_RHOST, str_getbuf(&hostname));
993209
+      str_free(&hostname);
993209
+    }
993209
     else
993209
+    {
993209
       retval = pam_set_item(s_pamh, PAM_RHOST, str_getbuf(p_remote_host));
993209
+    }
993209
   } else {
993209
     retval = pam_set_item(s_pamh, PAM_RHOST, str_getbuf(p_remote_host));
993209
   }
993209
diff --git a/sysdeputil.h b/sysdeputil.h
993209
index 3b6b30a..6f2aa0a 100644
993209
--- a/sysdeputil.h
993209
+++ b/sysdeputil.h
993209
@@ -5,6 +5,8 @@
993209
 #include "filesize.h"
993209
 #endif
993209
 
993209
+#include "session.h"
993209
+
993209
 /* VSF_SYSDEPUTIL_H:
993209
  * Support for highly system dependent features, and querying for support
993209
  * or lack thereof
993209
@@ -15,7 +17,8 @@ struct mystr;
993209
 
993209
 /* Authentication of local users */
993209
 /* Return 0 for fail, 1 for success */
993209
-int vsf_sysdep_check_auth(struct mystr* p_user,
993209
+int vsf_sysdep_check_auth(struct vsf_session* p_sess,
993209
+                          struct mystr* p_user,
993209
                           const struct mystr* p_pass,
993209
                           const struct mystr* p_remote_host);
993209
 
993209
diff --git a/sysutil.c b/sysutil.c
993209
index e847650..b68583b 100644
993209
--- a/sysutil.c
993209
+++ b/sysutil.c
993209
@@ -2356,6 +2356,41 @@ vsf_sysutil_dns_resolve(struct vsf_sysutil_sockaddr** p_sockptr,
993209
   }
993209
 }
993209
 
993209
+int
993209
+vsf_sysutil_get_hostname(struct vsf_sysutil_sockaddr *p_addr,
993209
+                         struct mystr* p_str)
993209
+{
993209
+  struct sockaddr *sa;
993209
+  socklen_t sa_len = 0;
993209
+  char hostname[NI_MAXHOST];
993209
+  int res;
993209
+
993209
+  sa = &p_addr->u.u_sockaddr;
993209
+  if (sa->sa_family == AF_INET)
993209
+  {
993209
+    sa_len = sizeof(struct sockaddr_in);
993209
+  }
993209
+  else if (sa->sa_family == AF_INET6)
993209
+  {
993209
+    sa_len = sizeof(struct sockaddr_in6);
993209
+  }
993209
+  else
993209
+  {
993209
+    die("can only support ipv4 and ipv6 currently");
993209
+  }
993209
+  res = getnameinfo(sa, sa_len, hostname, sizeof(hostname), NULL, 0,
993209
+                    NI_NAMEREQD);
993209
+  if (res == 0)
993209
+  {
993209
+    str_alloc_text(p_str, hostname);
993209
+    return 0;
993209
+  }
993209
+  else
993209
+  {
993209
+    return -1;
993209
+  }
993209
+}
993209
+
993209
 struct vsf_sysutil_user*
993209
 vsf_sysutil_getpwuid(const unsigned int uid)
993209
 {
993209
diff --git a/sysutil.h b/sysutil.h
993209
index 7a59f13..2df14ed 100644
993209
--- a/sysutil.h
993209
+++ b/sysutil.h
993209
@@ -7,6 +7,8 @@
993209
 #include "filesize.h"
993209
 #endif
993209
 
993209
+#include "str.h"
993209
+
993209
 /* Return value queries */
993209
 int vsf_sysutil_retval_is_error(int retval);
993209
 enum EVSFSysUtilError
993209
@@ -266,6 +268,8 @@ int vsf_sysutil_connect_timeout(int fd,
993209
                                 unsigned int wait_seconds);
993209
 void vsf_sysutil_dns_resolve(struct vsf_sysutil_sockaddr** p_sockptr,
993209
                              const char* p_name);
993209
+int vsf_sysutil_get_hostname(struct vsf_sysutil_sockaddr *p_addr,
993209
+                             struct mystr* p_str);
993209
 /* Option setting on sockets */
993209
 void vsf_sysutil_activate_keepalive(int fd);
993209
 void vsf_sysutil_rcvtimeo(int fd);
993209
-- 
993209
2.14.3
993209