2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-2001
6 Copyright (C) John H Terpsta 1999-2001
7 Copyright (C) Andrew Bartlett 2001
8 Copyright (C) Jeremy Allison 2001
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * This module provides PAM based functions for validation of
27 * username/password pairs, account managment, session and access control.
28 * Note: SMB password checking is done in smbpass.c
35 /*******************************************************************
36 * Handle PAM authentication
37 * - Access, Authentication, Session, Password
38 * Note: See PAM Documentation and refer to local system PAM implementation
39 * which determines what actions/limitations/allowances become affected.
40 *********************************************************************/
42 #include <security/pam_appl.h>
45 * Structure used to communicate between the conversation function
46 * and the server_login/change password functions.
49 struct smb_pam_userdata {
52 char *PAM_newpassword;
55 typedef int (*smb_pam_conv_fn)(int, const struct pam_message **, struct pam_response **, void *appdata_ptr);
58 * Macros to help make life easy
60 #define COPY_STRING(s) (s) ? strdup(s) : NULL
62 /*******************************************************************
64 *********************************************************************/
66 static BOOL smb_pam_error_handler(pam_handle_t *pamh, int pam_error, char *msg, int dbglvl)
69 if( pam_error != PAM_SUCCESS) {
70 DEBUG(dbglvl, ("smb_pam_error_handler: PAM: %s : %s\n",
71 msg, pam_strerror(pamh, pam_error)));
78 /*******************************************************************
79 This function is a sanity check, to make sure that we NEVER report
81 *********************************************************************/
83 static BOOL smb_pam_nt_status_error_handler(pam_handle_t *pamh, int pam_error,
84 char *msg, int dbglvl,
87 if (smb_pam_error_handler(pamh, pam_error, msg, dbglvl))
90 if (NT_STATUS_IS_OK(*nt_status)) {
92 DEBUG(0, ("smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
93 error MISMATCH, forcing to NT_STATUS_LOGON_FAILURE"));
94 *nt_status = NT_STATUS_LOGON_FAILURE;
100 * PAM conversation function
101 * Here we assume (for now, at least) that echo on means login name, and
102 * echo off means password.
105 static int smb_pam_conv(int num_msg,
106 const struct pam_message **msg,
107 struct pam_response **resp,
111 struct pam_response *reply = NULL;
112 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
120 * Apparantly HPUX has a buggy PAM that doesn't support the
121 * appdata_ptr. Fail if this is the case. JRA.
125 DEBUG(0,("smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
129 reply = malloc(sizeof(struct pam_response) * num_msg);
133 memset(reply, '\0', sizeof(struct pam_response) * num_msg);
135 for (replies = 0; replies < num_msg; replies++) {
136 switch (msg[replies]->msg_style) {
137 case PAM_PROMPT_ECHO_ON:
138 reply[replies].resp_retcode = PAM_SUCCESS;
139 reply[replies].resp = COPY_STRING(udp->PAM_username);
143 case PAM_PROMPT_ECHO_OFF:
144 reply[replies].resp_retcode = PAM_SUCCESS;
145 reply[replies].resp = COPY_STRING(udp->PAM_password);
154 reply[replies].resp_retcode = PAM_SUCCESS;
155 reply[replies].resp = NULL;
159 /* Must be an error of some sort... */
170 * PAM password change conversation function
171 * Here we assume (for now, at least) that echo on means login name, and
172 * echo off means password.
175 static void special_char_sub(char *buf)
177 all_string_sub(buf, "\\n", "", 0);
178 all_string_sub(buf, "\\r", "", 0);
179 all_string_sub(buf, "\\s", " ", 0);
180 all_string_sub(buf, "\\t", "\t", 0);
183 static void pwd_sub(char *buf, char *username, char *oldpass, char *newpass)
185 pstring_sub(buf, "%u", username);
186 all_string_sub(buf, "%o", oldpass, sizeof(fstring));
187 all_string_sub(buf, "%n", newpass, sizeof(fstring));
192 struct chat_struct *next, *prev;
197 /**************************************************************
198 Create a linked list containing chat data.
199 ***************************************************************/
201 static struct chat_struct *make_pw_chat(char *p)
205 struct chat_struct *list = NULL;
206 struct chat_struct *t;
207 struct chat_struct *tmp;
210 t = (struct chat_struct *)malloc(sizeof(*t));
212 DEBUG(0,("make_pw_chat: malloc failed!\n"));
218 DLIST_ADD_END(list, t, tmp);
220 if (!next_token(&p, prompt, NULL, sizeof(fstring)))
223 if (strequal(prompt,"."))
226 special_char_sub(prompt);
227 fstrcpy(t->prompt, prompt);
229 trim_string(t->prompt, " ", " ");
231 if (!next_token(&p, reply, NULL, sizeof(fstring)))
234 if (strequal(reply,"."))
237 special_char_sub(reply);
238 fstrcpy(t->reply, reply);
240 trim_string(t->reply, " ", " ");
246 static void free_pw_chat(struct chat_struct *list)
249 struct chat_struct *old_head = list;
250 DLIST_REMOVE(list, list);
255 static int smb_pam_passchange_conv(int num_msg,
256 const struct pam_message **msg,
257 struct pam_response **resp,
261 struct pam_response *reply = NULL;
262 fstring current_prompt;
263 fstring current_reply;
264 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
265 struct chat_struct *pw_chat= make_pw_chat(lp_passwd_chat());
266 struct chat_struct *t;
270 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg));
279 * Apparantly HPUX has a buggy PAM that doesn't support the
280 * appdata_ptr. Fail if this is the case. JRA.
284 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
285 free_pw_chat(pw_chat);
289 reply = malloc(sizeof(struct pam_response) * num_msg);
291 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
292 free_pw_chat(pw_chat);
296 for (replies = 0; replies < num_msg; replies++) {
298 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies));
299 switch (msg[replies]->msg_style) {
300 case PAM_PROMPT_ECHO_ON:
301 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg[replies]->msg));
302 fstrcpy(current_prompt, msg[replies]->msg);
303 trim_string(current_prompt, " ", " ");
304 for (t=pw_chat; t; t=t->next) {
306 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
307 t->prompt, current_prompt ));
309 if (wild_match(t->prompt, current_prompt) == 0) {
310 fstrcpy(current_reply, t->reply);
311 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply));
312 pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
313 #ifdef DEBUG_PASSWORD
314 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply));
316 reply[replies].resp_retcode = PAM_SUCCESS;
317 reply[replies].resp = COPY_STRING(current_reply);
324 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
325 free_pw_chat(pw_chat);
331 case PAM_PROMPT_ECHO_OFF:
332 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg[replies]->msg));
333 fstrcpy(current_prompt, msg[replies]->msg);
334 trim_string(current_prompt, " ", " ");
335 for (t=pw_chat; t; t=t->next) {
337 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
338 t->prompt, current_prompt ));
340 if (wild_match(t->prompt, current_prompt) == 0) {
341 fstrcpy(current_reply, t->reply);
342 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply));
343 pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
344 reply[replies].resp_retcode = PAM_SUCCESS;
345 reply[replies].resp = COPY_STRING(current_reply);
346 #ifdef DEBUG_PASSWORD
347 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply));
356 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
357 free_pw_chat(pw_chat);
368 reply[replies].resp_retcode = PAM_SUCCESS;
369 reply[replies].resp = NULL;
373 /* Must be an error of some sort... */
374 free_pw_chat(pw_chat);
380 free_pw_chat(pw_chat);
386 /***************************************************************************
387 Free up a malloced pam_conv struct.
388 ****************************************************************************/
390 static void smb_free_pam_conv(struct pam_conv *pconv)
393 SAFE_FREE(pconv->appdata_ptr);
398 /***************************************************************************
399 Allocate a pam_conv struct.
400 ****************************************************************************/
402 static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, char *user,
403 char *passwd, char *newpass)
405 struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv));
406 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata));
408 if (pconv == NULL || udp == NULL) {
414 udp->PAM_username = user;
415 udp->PAM_password = passwd;
416 udp->PAM_newpassword = newpass;
418 pconv->conv = smb_pam_conv_fnptr;
419 pconv->appdata_ptr = (void *)udp;
424 * PAM Closing out cleanup handler
427 static BOOL smb_pam_end(pam_handle_t *pamh, struct pam_conv *smb_pam_conv_ptr)
431 smb_free_pam_conv(smb_pam_conv_ptr);
434 pam_error = pam_end(pamh, 0);
435 if(smb_pam_error_handler(pamh, pam_error, "End Cleanup Failed", 2) == True) {
436 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
440 DEBUG(2,("smb_pam_end: PAM: not initialised"));
445 * Start PAM authentication for specified account
448 static BOOL smb_pam_start(pam_handle_t **pamh, char *user, char *rhost, struct pam_conv *pconv)
452 *pamh = (pam_handle_t *)NULL;
454 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user));
456 pam_error = pam_start("samba", user, pconv, pamh);
457 if( !smb_pam_error_handler(*pamh, pam_error, "Init Failed", 0)) {
458 *pamh = (pam_handle_t *)NULL;
463 rhost = client_name();
464 if (strequal(rhost,"UNKNOWN"))
465 rhost = client_addr();
469 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", rhost));
470 pam_error = pam_set_item(*pamh, PAM_RHOST, rhost);
471 if(!smb_pam_error_handler(*pamh, pam_error, "set rhost failed", 0)) {
472 smb_pam_end(*pamh, pconv);
473 *pamh = (pam_handle_t *)NULL;
478 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
479 pam_error = pam_set_item(*pamh, PAM_TTY, "samba");
480 if (!smb_pam_error_handler(*pamh, pam_error, "set tty failed", 0)) {
481 smb_pam_end(*pamh, pconv);
482 *pamh = (pam_handle_t *)NULL;
486 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user));
491 * PAM Authentication Handler
493 static NTSTATUS smb_pam_auth(pam_handle_t *pamh, char *user)
496 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
499 * To enable debugging set in /etc/pam.d/samba:
500 * auth required /lib/security/pam_pwdb.so nullok shadow audit
503 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user));
504 pam_error = pam_authenticate(pamh, PAM_SILENT | lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK);
507 DEBUG(2, ("smb_pam_auth: PAM: Athentication Error for user %s\n", user));
508 nt_status = NT_STATUS_WRONG_PASSWORD;
510 case PAM_CRED_INSUFFICIENT:
511 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user));
512 nt_status = NT_STATUS_INSUFFICIENT_LOGON_INFO;
514 case PAM_AUTHINFO_UNAVAIL:
515 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user));
516 nt_status = NT_STATUS_LOGON_FAILURE;
518 case PAM_USER_UNKNOWN:
519 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user));
520 nt_status = NT_STATUS_NO_SUCH_USER;
523 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user));
524 nt_status = NT_STATUS_REMOTE_SESSION_LIMIT;
527 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user));
528 nt_status = NT_STATUS_LOGON_FAILURE;
531 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user));
532 nt_status = NT_STATUS_OK;
535 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user));
536 nt_status = NT_STATUS_LOGON_FAILURE;
540 smb_pam_nt_status_error_handler(pamh, pam_error, "Authentication Failure", 2, &nt_status);
545 * PAM Account Handler
547 static NTSTATUS smb_pam_account(pam_handle_t *pamh, char * user)
550 NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
552 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user));
553 pam_error = pam_acct_mgmt(pamh, PAM_SILENT); /* Is user account enabled? */
554 switch( pam_error ) {
555 case PAM_AUTHTOK_EXPIRED:
556 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user));
557 nt_status = NT_STATUS_PASSWORD_EXPIRED;
559 case PAM_ACCT_EXPIRED:
560 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user));
561 nt_status = NT_STATUS_ACCOUNT_EXPIRED;
564 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user));
565 nt_status = NT_STATUS_LOGON_FAILURE;
567 case PAM_PERM_DENIED:
568 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user));
569 nt_status = NT_STATUS_ACCOUNT_RESTRICTION;
571 case PAM_USER_UNKNOWN:
572 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user));
573 nt_status = NT_STATUS_NO_SUCH_USER;
576 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user));
577 nt_status = NT_STATUS_OK;
580 nt_status = NT_STATUS_ACCOUNT_DISABLED;
581 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error, user));
585 smb_pam_nt_status_error_handler(pamh, pam_error, "Account Check Failed", 2, &nt_status);
590 * PAM Credential Setting
593 static NTSTATUS smb_pam_setcred(pam_handle_t *pamh, char * user)
596 NTSTATUS nt_status = NT_STATUS_NO_TOKEN;
599 * This will allow samba to aquire a kerberos token. And, when
600 * exporting an AFS cell, be able to /write/ to this cell.
603 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user));
604 pam_error = pam_setcred(pamh, (PAM_ESTABLISH_CRED|PAM_SILENT));
605 switch( pam_error ) {
606 case PAM_CRED_UNAVAIL:
607 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user ));
608 nt_status = NT_STATUS_NO_TOKEN;
610 case PAM_CRED_EXPIRED:
611 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user ));
612 nt_status = NT_STATUS_PASSWORD_EXPIRED;
614 case PAM_USER_UNKNOWN:
615 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user ));
616 nt_status = NT_STATUS_NO_SUCH_USER;
619 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user ));
620 nt_status = NT_STATUS_LOGON_FAILURE;
623 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user));
624 nt_status = NT_STATUS_OK;
627 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error, user));
628 nt_status = NT_STATUS_NO_TOKEN;
632 smb_pam_nt_status_error_handler(pamh, pam_error, "Set Credential Failure", 2, &nt_status);
637 * PAM Internal Session Handler
639 static BOOL smb_internal_pam_session(pam_handle_t *pamh, char *user, char *tty, BOOL flag)
644 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty));
645 pam_error = pam_set_item(pamh, PAM_TTY, tty);
646 if (!smb_pam_error_handler(pamh, pam_error, "set tty failed", 0))
651 pam_error = pam_open_session(pamh, PAM_SILENT);
652 if (!smb_pam_error_handler(pamh, pam_error, "session setup failed", 0))
655 pam_setcred(pamh, (PAM_DELETE_CRED|PAM_SILENT)); /* We don't care if this fails */
656 pam_error = pam_close_session(pamh, PAM_SILENT); /* This will probably pick up the error anyway */
657 if (!smb_pam_error_handler(pamh, pam_error, "session close failed", 0))
664 * Internal PAM Password Changer.
667 static BOOL smb_pam_chauthtok(pam_handle_t *pamh, char * user)
671 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user));
673 pam_error = pam_chauthtok(pamh, PAM_SILENT); /* Change Password */
675 switch( pam_error ) {
676 case PAM_AUTHTOK_ERR:
677 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
680 /* This doesn't seem to be defined on Solaris. JRA */
681 #ifdef PAM_AUTHTOK_RECOVER_ERR
682 case PAM_AUTHTOK_RECOVER_ERR:
683 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
687 case PAM_AUTHTOK_LOCK_BUSY:
688 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
690 case PAM_AUTHTOK_DISABLE_AGING:
691 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
693 case PAM_PERM_DENIED:
694 DEBUG(0, ("PAM: Permission denied.\n"));
697 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
699 case PAM_USER_UNKNOWN:
700 DEBUG(0, ("PAM: User not known to PAM\n"));
703 DEBUG(4, ("PAM: Account OK for User: %s\n", user));
706 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error, user));
709 if(!smb_pam_error_handler(pamh, pam_error, "Password Change Failed", 2)) {
713 /* If this point is reached, the password has changed. */
718 * PAM Externally accessible Session handler
721 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
723 pam_handle_t *pamh = NULL;
724 struct pam_conv *pconv = NULL;
726 /* Ignore PAM if told to. */
728 if (!lp_obey_pam_restrictions())
731 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
734 if (!smb_pam_start(&pamh, user, rhost, pconv))
737 if (!smb_internal_pam_session(pamh, user, tty, True)) {
738 smb_pam_end(pamh, pconv);
742 return smb_pam_end(pamh, pconv);
746 * PAM Externally accessible Session handler
749 BOOL smb_pam_close_session(char *user, char *tty, char *rhost)
751 pam_handle_t *pamh = NULL;
752 struct pam_conv *pconv = NULL;
754 /* Ignore PAM if told to. */
756 if (!lp_obey_pam_restrictions())
759 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
762 if (!smb_pam_start(&pamh, user, rhost, pconv))
765 if (!smb_internal_pam_session(pamh, user, tty, False)) {
766 smb_pam_end(pamh, pconv);
770 return smb_pam_end(pamh, pconv);
774 * PAM Externally accessible Account handler
777 NTSTATUS smb_pam_accountcheck(char * user)
779 NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
780 pam_handle_t *pamh = NULL;
781 struct pam_conv *pconv = NULL;
783 /* Ignore PAM if told to. */
785 if (!lp_obey_pam_restrictions())
788 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
789 return NT_STATUS_NO_MEMORY;
791 if (!smb_pam_start(&pamh, user, NULL, pconv))
792 return NT_STATUS_ACCOUNT_DISABLED;
794 if (!NT_STATUS_IS_OK(nt_status = smb_pam_account(pamh, user)))
795 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user));
797 smb_pam_end(pamh, pconv);
802 * PAM Password Validation Suite
805 NTSTATUS smb_pam_passcheck(char * user, char * password)
807 pam_handle_t *pamh = NULL;
808 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
809 struct pam_conv *pconv = NULL;
812 * Note we can't ignore PAM here as this is the only
813 * way of doing auths on plaintext passwords when
814 * compiled --with-pam.
817 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, password, NULL)) == NULL)
818 return NT_STATUS_LOGON_FAILURE;
820 if (!smb_pam_start(&pamh, user, NULL, pconv))
821 return NT_STATUS_LOGON_FAILURE;
823 if (!NT_STATUS_IS_OK(nt_status = smb_pam_auth(pamh, user))) {
824 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user));
825 smb_pam_end(pamh, pconv);
829 if (!NT_STATUS_IS_OK(nt_status = smb_pam_account(pamh, user))) {
830 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user));
831 smb_pam_end(pamh, pconv);
835 if (!NT_STATUS_IS_OK(nt_status = smb_pam_setcred(pamh, user))) {
836 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user));
837 smb_pam_end(pamh, pconv);
841 smb_pam_end(pamh, pconv);
846 * PAM Password Change Suite
849 BOOL smb_pam_passchange(char * user, char * oldpassword, char * newpassword)
851 /* Appropriate quantities of root should be obtained BEFORE calling this function */
852 struct pam_conv *pconv = NULL;
853 pam_handle_t *pamh = NULL;
855 if ((pconv = smb_setup_pam_conv(smb_pam_passchange_conv, user, oldpassword, newpassword)) == NULL)
858 if(!smb_pam_start(&pamh, user, NULL, pconv))
861 if (!smb_pam_chauthtok(pamh, user)) {
862 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user));
863 smb_pam_end(pamh, pconv);
867 return smb_pam_end(pamh, pconv);
872 /* If PAM not used, no PAM restrictions on accounts. */
873 NTSTATUS smb_pam_accountcheck(char * user)
878 /* If PAM not used, also no PAM restrictions on sessions. */
879 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
884 /* If PAM not used, also no PAM restrictions on sessions. */
885 BOOL smb_pam_close_session(char *in_user, char *tty, char *rhost)
889 #endif /* WITH_PAM */