Blame SOURCES/cvs-1.11.23-Set-PAM_TTY-and-PAM_RHOST-on-PAM-authentication.patch

814382
From 923dc05d68031a217684aba87acdadc7f711c88a Mon Sep 17 00:00:00 2001
814382
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
814382
Date: Thu, 10 Mar 2011 15:16:04 +0100
814382
Subject: [PATCH] Set PAM_TTY and PAM_RHOST on PAM authentication
814382
814382
When loging to server, PAM can make decision on client network address, so set
814382
it appropriately. Also some modules require non-empy console name, thus set
814382
PAM_TTY to cvs PAM service name (`cvs').
814382
814382
PAM failure is reported back to client.
814382
814382
This code is back-ported from from upstream developemt tree (r1.489).
814382
`peer' and `len' types fixed to cover any address family.
814382
---
814382
 src/server.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
814382
 1 files changed, 46 insertions(+), 1 deletions(-)
814382
814382
diff --git a/src/server.c b/src/server.c
814382
index 0505ab9..bc6f0d0 100644
814382
--- a/src/server.c
814382
+++ b/src/server.c
814382
@@ -5799,18 +5799,61 @@ error 0 %s: no such user\n", username);
814382
 #if PAM_SUPPORT
814382
         pam_handle_t *pamh = NULL;
814382
         struct pam_conv conv;
814382
+        char *pam_stage = "start";
814382
+        struct sockaddr_storage peer;
814382
+        socklen_t len;
814382
+        char host[NI_MAXHOST];
814382
         int retval;
814382
 
814382
+        /* get the client's ip address */
814382
+        len = sizeof (peer);
814382
+        if (getpeername (STDIN_FILENO, (struct sockaddr *)&peer, &len) < 0)
814382
+        {
814382
+            printf ("E Fatal error, aborting.\n\
814382
+error %s getpeername failed\n", strerror (errno));
814382
+            exit (EXIT_FAILURE);
814382
+        }
814382
+
814382
+        /* convert the ip address to text */
814382
+        if (getnameinfo((struct sockaddr *)&peer, len, host, NI_MAXHOST,
814382
+                    NULL, 0, NI_NUMERICHOST) < 0)
814382
+        {
814382
+            printf ("E Fatal error, aborting.\n\
814382
+error %s getnameinfo failed\n", strerror (errno));
814382
+            exit (EXIT_FAILURE);
814382
+        }
814382
+
814382
         conv.conv = silent_conv;
814382
         conv.appdata_ptr = password;
814382
 
814382
-        retval = pam_start("cvs", username, &conv, &pamh);
814382
+#define PAM_SERVICE_NAME "cvs"
814382
+        retval = pam_start(PAM_SERVICE_NAME, username, &conv, &pamh);
814382
+
814382
+        /* sets a dummy tty name which pam modules can check for */
814382
+        if (retval == PAM_SUCCESS)
814382
+        {
814382
+            pam_stage = "set dummy tty";
814382
+            retval = pam_set_item (pamh, PAM_TTY, PAM_SERVICE_NAME);
814382
+        }
814382
+#undef PAM_SERVICE_NAME
814382
+
814382
+        if (retval == PAM_SUCCESS)
814382
+        {
814382
+            pam_stage = "set remote host ip";
814382
+            retval = pam_set_item (pamh, PAM_RHOST, host);
814382
+        }
814382
 
814382
         if (retval == PAM_SUCCESS)
814382
+        {
814382
+            pam_stage = "authenticate";
814382
             retval = pam_authenticate(pamh, 0); /* is user really user? */
814382
+        }
814382
 
814382
         if (retval == PAM_SUCCESS)
814382
+        {
814382
+            pam_stage = "account";
814382
             retval = pam_acct_mgmt(pamh, 0);    /* permitted access? */
814382
+        }
814382
 
814382
         /* This is where we have been authorized or not. */
814382
 
814382
@@ -5818,6 +5861,8 @@ error 0 %s: no such user\n", username);
814382
             host_user = xstrdup (username);
814382
         } else {
814382
             host_user = NULL;
814382
+            printf ("E PAM %s error: %s\n",
814382
+                 pam_stage, pam_strerror (pamh, retval));
814382
         }
814382
 
814382
         if (pam_end(pamh,retval) != PAM_SUCCESS) {   /* close Linux-PAM */
814382
-- 
814382
1.7.4
814382