Blame SOURCES/cvs-1.11.21-pam.patch

83a95a
diff -up cvs-1.11.23/configure.in.pam cvs-1.11.23/configure.in
83a95a
--- cvs-1.11.23/configure.in.pam	2008-07-15 15:40:50.000000000 -0400
83a95a
+++ cvs-1.11.23/configure.in	2008-07-15 15:40:50.000000000 -0400
83a95a
@@ -904,6 +904,36 @@ if test no != "$enable_server"; then
83a95a
       [The high water mark in bytes for server flow control.  Required if
83a95a
        SERVER_FLOWCONTROL is defined, and useless otherwise.])
83a95a
   fi # enable_server_flow_control
83a95a
+  
83a95a
+  dnl
83a95a
+  dnl Give the confiscator control over whether the pam support is used
83a95a
+  dnl
83a95a
+  AC_ARG_ENABLE(
83a95a
+    [pam],
83a95a
+    AC_HELP_STRING(
83a95a
+      [--enable-pam],
83a95a
+      [Include code for running with pam code (default)]), ,
83a95a
+    [if test "$ac_cv_search_connect" != yes; then
83a95a
+       enable_pam=no
83a95a
+     fi])
83a95a
+
83a95a
+  if test no != "$enable_pam"; then
83a95a
+    AC_DEFINE(
83a95a
+      [PAM_SUPPORT], [1],
83a95a
+      [Define if you want CVS to be able to serve repositories to remote
83a95a
+       clients.])  
83a95a
+       
83a95a
+      dnl
83a95a
+      dnl Finding the pam_authenticate function. 
83a95a
+      dnl
83a95a
+      AC_SEARCH_LIBS(
83a95a
+      [pam_authenticate], [pam],
83a95a
+      [AC_DEFINE(
83a95a
+         [HAVE_PAM], [1],
83a95a
+         [Define if you have the pam_authenticate function.])
83a95a
+      ]) dnl AC_SEARCH_LIBS
83a95a
+  fi #enable_pam
83a95a
+  
83a95a
 fi # enable_server
83a95a
 
83a95a
 
83a95a
diff -up cvs-1.11.23/src/server.c.pam cvs-1.11.23/src/server.c
83a95a
--- cvs-1.11.23/src/server.c.pam	2008-07-15 15:40:50.000000000 -0400
83a95a
+++ cvs-1.11.23/src/server.c	2008-07-15 15:42:02.000000000 -0400
83a95a
@@ -20,6 +20,12 @@
83a95a
 # include <process.h>
83a95a
 #endif
83a95a
 
83a95a
+/* needed for PAM authentication - fk 2000 */
83a95a
+#if PAM_SUPPORT
83a95a
+#include <security/pam_appl.h>
83a95a
+#include <security/pam_misc.h>
83a95a
+#endif
83a95a
+
83a95a
 int server_active = 0;
83a95a
 
83a95a
 #if defined(SERVER_SUPPORT) || defined(CLIENT_SUPPORT)
83a95a
@@ -5673,7 +5679,36 @@ check_repository_password (username, pas
83a95a
     return retval;
83a95a
 }
83a95a
 
83a95a
-
83a95a
+/* callback for PAM authentication - fk 2000 */
83a95a
+#if PAM_SUPPORT
83a95a
+int silent_conv(int num_msg, const struct pam_message **msgm,
83a95a
+      struct pam_response **response, void *appdata) {
83a95a
+      int replies;
83a95a
+      struct pam_response *reply = NULL;
83a95a
+
83a95a
+      reply = calloc(num_msg,sizeof(struct pam_response));
83a95a
+      for (replies=0; replies
83a95a
+              switch (msgm[replies]->msg_style) {
83a95a
+                      case PAM_PROMPT_ECHO_ON:
83a95a
+                      case PAM_PROMPT_ECHO_OFF:
83a95a
+                              /* printf("Prompt: %s\n",msgm[replies]->msg); */
83a95a
+                              reply[replies].resp_retcode = PAM_SUCCESS;
83a95a
+                              reply[replies].resp = strdup((char*)appdata);
83a95a
+                              break;
83a95a
+                      case PAM_ERROR_MSG:
83a95a
+                      case PAM_TEXT_INFO:
83a95a
+                              reply[replies].resp_retcode = PAM_SUCCESS;
83a95a
+                              reply[replies].resp = NULL;
83a95a
+                              break;
83a95a
+                      default:
83a95a
+                              free(reply);
83a95a
+                              return PAM_CONV_ERR;
83a95a
+              }
83a95a
+      }
83a95a
+      *response = reply;
83a95a
+      return PAM_SUCCESS;
83a95a
+}
83a95a
+#endif
83a95a
 
83a95a
 /* Return a hosting username if password matches, else NULL. */
83a95a
 static char *
83a95a
@@ -5761,6 +5796,34 @@ error 0 %s: no such user\n", username);
83a95a
     if (*found_passwd)
83a95a
     {
83a95a
 	/* user exists and has a password */
83a95a
+#if PAM_SUPPORT
83a95a
+        pam_handle_t *pamh = NULL;
83a95a
+        struct pam_conv conv;
83a95a
+        int retval;
83a95a
+
83a95a
+        conv.conv = silent_conv;
83a95a
+        conv.appdata_ptr = password;
83a95a
+
83a95a
+        retval = pam_start("cvs", username, &conv, &pamh);
83a95a
+
83a95a
+        if (retval == PAM_SUCCESS)
83a95a
+            retval = pam_authenticate(pamh, 0); /* is user really user? */
83a95a
+
83a95a
+        if (retval == PAM_SUCCESS)
83a95a
+            retval = pam_acct_mgmt(pamh, 0);    /* permitted access? */
83a95a
+
83a95a
+        /* This is where we have been authorized or not. */
83a95a
+
83a95a
+        if (retval == PAM_SUCCESS) {
83a95a
+            host_user = xstrdup (username);
83a95a
+        } else {
83a95a
+            host_user = NULL;
83a95a
+        }
83a95a
+
83a95a
+        if (pam_end(pamh,retval) != PAM_SUCCESS) {   /* close Linux-PAM */
83a95a
+            pamh = NULL;
83a95a
+        }
83a95a
+#else
83a95a
 	if (strcmp (found_passwd, crypt (password, found_passwd)) == 0)
83a95a
 	{
83a95a
 	    host_user = xstrdup (username);
83a95a
@@ -5774,6 +5837,7 @@ error 0 %s: no such user\n", username);
83a95a
 		    crypt(password, found_passwd), found_passwd);
83a95a
 #endif
83a95a
 	}
83a95a
+#endif
83a95a
 	goto handle_return;
83a95a
     }
83a95a