Wrap authentication in an account management function in modules that really
just do authorization.
diff -uNr Linux-PAM-0.75/modules/pam_listfile/pam_listfile.c Linux-PAM-0.75.wrap/modules/pam_listfile/pam_listfile.c
--- Linux-PAM-0.75/modules/pam_listfile/pam_listfile.c	Mon Oct  1 16:43:32 2001
+++ Linux-PAM-0.75.wrap/modules/pam_listfile/pam_listfile.c	Mon Oct  1 16:42:38 2001
@@ -36,6 +36,7 @@
  */
 
 #define PAM_SM_AUTH
+#define PAM_SM_ACCOUNT
 #include "../../libpam/include/security/pam_modules.h"
 
 #include "../../libpam/include/security/_pam_macros.h"
@@ -419,6 +420,13 @@
     return PAM_SUCCESS;
 }
 
+PAM_EXTERN
+int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv)
+{
+    D(("called."));
+    return pam_sm_authenticate(pamh, 0, argc, argv);
+}
+
 #ifdef PAM_STATIC
 
 /* static module data */
@@ -427,7 +435,7 @@
     "pam_listfile",
     pam_sm_authenticate,
     pam_sm_setcred,
-    NULL,
+    pam_sm_acct_mgmt,
     NULL,
     NULL,
     NULL,
diff -uNr Linux-PAM-0.75/modules/pam_nologin/pam_nologin.c Linux-PAM-0.75.wrap/modules/pam_nologin/pam_nologin.c
--- Linux-PAM-0.75/modules/pam_nologin/pam_nologin.c	Mon Oct  1 16:43:32 2001
+++ Linux-PAM-0.75.wrap/modules/pam_nologin/pam_nologin.c	Mon Oct  1 16:42:17 2001
@@ -24,6 +24,7 @@
  */
 
 #define PAM_SM_AUTH
+#define PAM_SM_ACCOUNT
 #include "../../libpam/include/security/pam_modules.h"
 
 #include "../../libpam/include/security/pam_modules.h"
@@ -91,6 +92,14 @@
      return PAM_SUCCESS;
 }
 
+PAM_EXTERN
+int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc,
+                     const char **argv)
+{
+     return pam_sm_authenticate(pamh, 0, argc, argv);
+}
+
+
 
 #ifdef PAM_STATIC
 
@@ -100,7 +109,7 @@
      "pam_nologin",
      pam_sm_authenticate,
      pam_sm_setcred,
-     NULL,
+     pam_sm_acct_mgmt,
      NULL,
      NULL,
      NULL,
diff -uNr Linux-PAM-0.75/modules/pam_securetty/pam_securetty.c Linux-PAM-0.75.wrap/modules/pam_securetty/pam_securetty.c
--- Linux-PAM-0.75/modules/pam_securetty/pam_securetty.c	Mon Oct  1 16:43:32 2001
+++ Linux-PAM-0.75.wrap/modules/pam_securetty/pam_securetty.c	Mon Oct  1 16:42:53 2001
@@ -31,6 +31,7 @@
  */
 
 #define PAM_SM_AUTH
+#define PAM_SM_ACCOUNT
 #include "../../libpam/include/security/pam_modules.h"
 
 #include "../../libpam/include/security/pam_modules.h"
@@ -71,7 +72,7 @@
     return ctrl;
 }
 
-/* --- authentication management functions (only) --- */
+/* --- authentication management functions --- */
 
 PAM_EXTERN
 int pam_sm_authenticate(pam_handle_t *pamh,int flags,int argc
@@ -171,6 +172,25 @@
      return PAM_SUCCESS;
 }
 
+/* --- account management function --- */
+
+PAM_EXTERN
+int pam_sm_acct_mgmt(pam_handle_t *pamh,int flags,int argc
+		     ,const char **argv)
+{
+    int ctrl;
+
+    /* parse the arguments */
+    ctrl = _pam_parse(argc, argv);
+
+    /* log a trail for debugging */
+    if (ctrl & PAM_DEBUG_ARG)
+	_pam_log(LOG_DEBUG, "pam_securetty called as an account module, calling"
+		 " authentication module");
+
+    /* take the easy route */
+    return pam_sm_authenticate(pamh, 0, argc, argv);
+}
 
 #ifdef PAM_STATIC
 
@@ -180,7 +200,7 @@
      "pam_securetty",
      pam_sm_authenticate,
      pam_sm_setcred,
-     NULL,
+     pam_sm_acct_mgmt,
      NULL,
      NULL,
      NULL,
diff -uNr Linux-PAM-0.75/modules/pam_shells/pam_shells.c Linux-PAM-0.75.wrap/modules/pam_shells/pam_shells.c
--- Linux-PAM-0.75/modules/pam_shells/pam_shells.c	Mon Oct  1 16:43:32 2001
+++ Linux-PAM-0.75.wrap/modules/pam_shells/pam_shells.c	Mon Oct  1 16:41:24 2001
@@ -115,6 +115,12 @@
      return PAM_SUCCESS;
 }
 
+PAM_EXTERN
+int pam_sm_acct_mgmt(pam_handle_t *pamh,int flags,int argc
+		     ,const char **argv)
+{
+     return pam_sm_authenticate(pamh, 0, argc, argv);
+}
 
 #ifdef PAM_STATIC
 
@@ -124,7 +130,7 @@
      "pam_shells",
      pam_sm_authenticate,
      pam_sm_setcred,
-     NULL,
+     pam_sm_acct_mgmt,
      NULL,
      NULL,
      NULL,
diff -uNr Linux-PAM-0.75/modules/pam_userdb/pam_userdb.c Linux-PAM-0.75.wrap/modules/pam_userdb/pam_userdb.c
--- Linux-PAM-0.75/modules/pam_userdb/pam_userdb.c	Mon Oct  1 16:43:32 2001
+++ Linux-PAM-0.75.wrap/modules/pam_userdb/pam_userdb.c	Mon Oct  1 16:41:24 2001
@@ -333,11 +333,61 @@
     return PAM_SUCCESS;
 }
 
+/*
+ * Account management. We want to verify that the account exists in the given
+ * database before returning PAM_SUCCESS
+ */
 PAM_EXTERN
 int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
 		   int argc, const char **argv)
 {
-    return PAM_SUCCESS;
+    const char *username;
+    int retval = PAM_USER_UNKNOWN;
+
+    /* parse arguments */
+    ctrl = _pam_parse(argc, argv);
+
+    /* Do we have a database ? */
+    if (database == NULL) {
+	_pam_log(LOG_ERR, "no database supplied; must use db=<database_path> arg");
+	return PAM_SERVICE_ERR;
+    }	
+
+    /* Get the username */
+    retval = pam_get_user(pamh, &username, NULL);
+    if ((retval != PAM_SUCCESS) || (!username)) {
+	if (ctrl & PAM_DEBUG_ARG)
+	    _pam_log(LOG_DEBUG,"can not get the username");
+	return PAM_SERVICE_ERR;
+    }
+
+    /* Verify the username */
+    retval = valid_user(username);
+    switch (retval) {
+	case -1:
+	    /* some sort of system error. The log was already printed */
+	    return PAM_SERVICE_ERR;
+	case 1:
+	    /* the user does not exist in the database */
+	    if (ctrl & PAM_DEBUG_ARG)
+		_pam_log(LOG_NOTICE, "user `%s' not found in the database",
+			 username);
+	    if (ctrl & PAM_UNKNOWN_OK_ARG)
+		return PAM_IGNORE;
+	    return PAM_USER_UNKNOWN;
+	case 0:
+	    /* Otherwise, the authentication looked good */
+	    _pam_log(LOG_NOTICE, "user '%s' granted acces", username);
+	    return PAM_SUCCESS;
+	default:
+	    /* we don't know anything about this return value */
+	    _pam_log(LOG_ERR, "internal module error (retval = %d, user = `%s'",
+		     retval, username);
+	    return PAM_SERVICE_ERR;
+    }
+    
+    /* should not be reached */
+    return PAM_IGNORE;
 }
 
 
@@ -346,10 +396,10 @@
 /* static module data */
 
 struct pam_module _pam_userdb_modstruct = {
-     "pam_userdb",
+     MODULE_NAME,
      pam_sm_authenticate,
      pam_sm_setcred,
-     NULL,
+     pam_sm_acct_mgmt,
      NULL,
      NULL,
      NULL,
diff -uNr Linux-PAM-0.75/modules/pam_wheel/pam_wheel.c Linux-PAM-0.75.wrap/modules/pam_wheel/pam_wheel.c
--- Linux-PAM-0.75/modules/pam_wheel/pam_wheel.c	Mon Oct  1 16:43:32 2001
+++ Linux-PAM-0.75.wrap/modules/pam_wheel/pam_wheel.c	Mon Oct  1 16:41:24 2001
@@ -39,6 +39,7 @@
  */
 
 #define PAM_SM_AUTH
+#define PAM_SM_ACCOUNT
 
 #include "../../libpam/include/security/pam_modules.h"
 
@@ -222,6 +223,23 @@
      return PAM_SUCCESS;
 }
 
+/* --- account management function --- */
+
+PAM_EXTERN
+int pam_sm_acct_mgmt(pam_handle_t *pamh,int flags,int argc
+		     ,const char **argv)
+{
+    int ctrl;
+    char use_group[BUFSIZ];
+
+    /* parse arguments */
+    ctrl = _pam_parse(argc, argv, use_group, sizeof(use_group));
+
+    if (ctrl & PAM_DEBUG_ARG)
+        _pam_log(LOG_DEBUG,"pam_wheel called for account management, calling "
+		 "authentication function");
+    return pam_sm_authenticate(pamh, 0, argc, argv);
+}
 
 #ifdef PAM_STATIC
 
@@ -231,7 +249,7 @@
      "pam_wheel",
      pam_sm_authenticate,
      pam_sm_setcred,
-     NULL,
+     pam_sm_acct_mgmt,
      NULL,
      NULL,
      NULL,
