9 #include <security/pam_modules.h>
13 /* --- authentication management functions --- */
15 PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags,
16 int argc, const char **argv)
21 PAM_EXTERN int pam_sm_setcred(pam_handle_t * pamh, int flags, int argc,
25 return PAM_CRED_UNAVAIL;
28 /* --- account management functions --- */
30 PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t * pamh, int flags, int argc,
33 char realm[256], errmsg[256];
37 openlog("pam_itkacl", 0, LOG_AUTHPRIV);
39 /* We want and need exactly one argument: realm='whatever' */
41 syslog(LOG_CRIT, "wrong number of arguments: expected 1, got %d", argc);
42 return PAM_SERVICE_ERR;
44 if (sscanf(argv[0], "realm='%[^']'", realm) != 1) {
45 syslog(LOG_CRIT, "realm in bad format: got %s, expected realm='/foo/bar'", argv[0]);
46 return PAM_SERVICE_ERR;
49 /* Get the user name from PAM */
50 ret = pam_get_item(pamh, PAM_USER, (const void **)&username);
51 if (ret != PAM_SUCCESS || username == NULL) {
52 syslog(LOG_CRIT, "Couldn't get username from PAM");
53 return PAM_USER_UNKNOWN;
56 /* Root should always be able to log in */
57 if (strcmp(username, "root") == 0)
60 ret = itkacl_check(realm, username, errmsg, 256);
62 syslog(LOG_ERR, "itkacl_check() returned an error: %s", errmsg);
63 return PAM_SERVICE_ERR;
69 return PAM_ACCT_EXPIRED;
73 /* --- password management --- */
75 PAM_EXTERN int pam_sm_chauthtok(pam_handle_t * pamh, int flags, int argc,
78 return PAM_AUTHTOK_ERR;
81 /* --- session management --- */
83 PAM_EXTERN int pam_sm_open_session(pam_handle_t * pamh, int flags,
84 int argc, const char **argv)
86 return PAM_SYSTEM_ERR;
89 PAM_EXTERN int pam_sm_close_session(pam_handle_t * pamh, int flags,
90 int argc, const char **argv)
92 return PAM_SYSTEM_ERR;
95 /* end of module definition */
97 /* static module data */
99 struct pam_module _pam_itkacl_modstruct = {
105 pam_sm_close_session,