1 /* pam_shishi.c PAM module using Shishi.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <vasprintf.h>
36 /* Libtool defines PIC for shared objects */
41 /* These #defines must be present according to PAM documentation. */
43 #define PAM_SM_ACCOUNT
44 #define PAM_SM_SESSION
45 #define PAM_SM_PASSWORD
47 #ifdef HAVE_SECURITY_PAM_APPL_H
48 #include <security/pam_appl.h>
50 #ifdef HAVE_SECURITY_PAM_MODULES_H
51 #include <security/pam_modules.h>
54 #if defined(DEBUG_PAM) && defined(HAVE_SECURITY__PAM_MACROS_H)
56 #include <security/_pam_macros.h>
58 #define D(x) /* nothing */
63 #define PAM_EXTERN static
65 #define PAM_EXTERN extern
70 pam_sm_authenticate (pam_handle_t
* pamh
,
71 int flags
, int argc
, const char **argv
)
74 Shishi_key
*key
= NULL
;
75 Shishi_tkt
*tkt
= NULL
;
77 const char *user
= NULL
;
78 const char *password
= NULL
;
80 struct pam_conv
*conv
;
81 struct pam_message
*pmsg
[1], msg
[1];
82 struct pam_response
*resp
;
86 D (("flags %d argc %d", flags
, argc
));
87 for (i
= 0; i
< argc
; i
++)
88 D (("argv[%d]=%s", i
, argv
[i
]));
90 rc
= shishi_init (&h
);
94 D (("shishi_init() failed: %s", shishi_strerror (retval
)));
95 retval
= PAM_AUTHINFO_UNAVAIL
;
99 retval
= pam_get_user (pamh
, &user
, NULL
);
100 if (retval
!= PAM_SUCCESS
)
102 D (("get user returned error: %s", pam_strerror (pamh
, retval
)));
105 D (("get user returned: %s", user
));
107 shishi_principal_default_set (h
, user
);
109 retval
= pam_get_item (pamh
, PAM_AUTHTOK
, (const void **) &password
);
110 if (retval
!= PAM_SUCCESS
)
112 D (("get password returned error: %s", pam_strerror (pamh
, retval
)));
115 D (("get password returned: %s", password
));
117 if (password
== NULL
)
119 retval
= pam_get_item (pamh
, PAM_CONV
, (const void **) &conv
);
120 if (retval
!= PAM_SUCCESS
)
122 D (("get conv returned error: %s", pam_strerror (pamh
, retval
)));
127 asprintf ((char **) &msg
[0].msg
, "Password for `%s@%s': ",
128 shishi_principal_default (h
), shishi_realm_default (h
));
129 msg
[0].msg_style
= PAM_PROMPT_ECHO_ON
;
132 retval
= conv
->conv (nargs
, (const struct pam_message
**) pmsg
,
133 &resp
, conv
->appdata_ptr
);
135 free ((char *) msg
[0].msg
);
137 if (retval
!= PAM_SUCCESS
)
139 D (("conv returned error: %s", pam_strerror (pamh
, retval
)));
143 D (("conv returned: %s", resp
->resp
));
145 password
= resp
->resp
;
148 tkt
= shishi_tkts_get_for_localservicepasswd (shishi_tkts_default (h
),
152 D (("TGS exchange failed: %s\n", shishi_error (h
)));
153 retval
= PAM_AUTHINFO_UNAVAIL
;
157 key
= shishi_hostkeys_for_localservice (h
, "host");
160 D (("Key not found: %s\n", shishi_error (h
)));
161 retval
= PAM_AUTHINFO_UNAVAIL
;
165 rc
= shishi_tkt_decrypt (tkt
, key
);
168 D (("Could not decrypt ticket: %s\n", shishi_strerror (rc
)));
169 retval
= PAM_AUTHINFO_UNAVAIL
;
173 retval
= PAM_SUCCESS
;
178 pam_set_data (pamh
, "shishi_setcred_return", (void *) retval
, NULL
);
179 D (("done. [%s]", pam_strerror (pamh
, retval
)));
185 pam_sm_setcred (pam_handle_t
* pamh
, int flags
, int argc
, const char **argv
)
192 retval
= pam_get_data (pamh
, "shishi_setcred_return",
193 (const void **) &auth_retval
);
194 if (retval
!= PAM_SUCCESS
)
195 return PAM_CRED_UNAVAIL
;
197 /* XXX save ticket in user's file here
198 XXX support CRED_EXPIRED */
203 retval
= PAM_SUCCESS
;
206 case PAM_USER_UNKNOWN
:
207 retval
= PAM_USER_UNKNOWN
;
212 retval
= PAM_CRED_ERR
;
216 D (("done. [%s]", pam_strerror (pamh
, retval
)));
222 pam_sm_acct_mgmt (pam_handle_t
* pamh
, int flags
, int argc
, const char **argv
)
228 /* TODO: check if password expired? */
229 retval
= PAM_SUCCESS
;
231 D (("done. [%s]", pam_strerror (pamh
, retval
)));
237 pam_sm_open_session (pam_handle_t
* pamh
,
238 int flags
, int argc
, const char **argv
)
244 /* TODO: afslog()? */
245 retval
= PAM_SUCCESS
;
247 D (("done. [%s]", pam_strerror (pamh
, retval
)));
253 pam_sm_close_session (pam_handle_t
* pamh
,
254 int flags
, int argc
, const char **argv
)
260 /* TODO: destroy tickets? destroy AFS tokens? */
261 retval
= PAM_SUCCESS
;
263 D (("done. [%s]", pam_strerror (pamh
, retval
)));
269 pam_sm_chauthtok (pam_handle_t
* pamh
, int flags
, int argc
, const char **argv
)
275 /* TODO: Change password */
276 retval
= PAM_SUCCESS
;
278 D (("done. [%s]", pam_strerror (pamh
, retval
)));
285 struct pam_module _pam_shishi_modstruct
= {
291 pam_sm_close_session
,