2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-2001
5 Copyright (C) John H Terpsta 1999-2001
6 Copyright (C) Andrew Bartlett 2001
7 Copyright (C) Jeremy Allison 2001
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * This module provides PAM based functions for validation of
25 * username/password pairs, account managment, session and access control.
26 * Note: SMB password checking is done in smbpass.c
31 #include "../libcli/auth/pam_errors.h"
32 #include "lib/util/string_wrappers.h"
35 #define DBGC_CLASS DBGC_AUTH
39 /*******************************************************************
40 * Handle PAM authentication
41 * - Access, Authentication, Session, Password
42 * Note: See PAM Documentation and refer to local system PAM implementation
43 * which determines what actions/limitations/allowances become affected.
44 *********************************************************************/
46 #if defined(HAVE_SECURITY_PAM_APPL_H)
47 #include <security/pam_appl.h>
48 #elif defined(HAVE_PAM_PAM_APPL_H)
49 #include <pam/pam_appl.h>
53 * Structure used to communicate between the conversation function
54 * and the server_login/change password functions.
57 struct smb_pam_userdata
{
58 const char *PAM_username
;
59 const char *PAM_password
;
60 const char *PAM_newpassword
;
63 typedef int (*smb_pam_conv_fn
)(int, const struct pam_message
**, struct pam_response
**, void *appdata_ptr
);
65 static char *smb_pam_copy_string(const char *s
)
73 static char *smb_pam_copy_fstring(const char *s
)
81 /*******************************************************************
83 *********************************************************************/
85 static bool smb_pam_error_handler(pam_handle_t
*pamh
, int pam_error
, const char *msg
, int dbglvl
)
88 if( pam_error
!= PAM_SUCCESS
) {
89 DEBUG(dbglvl
, ("smb_pam_error_handler: PAM: %s : %s\n",
90 msg
, pam_strerror(pamh
, pam_error
)));
96 /*******************************************************************
97 This function is a sanity check, to make sure that we NEVER report
99 *********************************************************************/
101 static bool smb_pam_nt_status_error_handler(pam_handle_t
*pamh
, int pam_error
,
102 const char *msg
, int dbglvl
,
105 *nt_status
= pam_to_nt_status(pam_error
);
107 if (smb_pam_error_handler(pamh
, pam_error
, msg
, dbglvl
))
110 if (NT_STATUS_IS_OK(*nt_status
)) {
111 /* Complain LOUDLY */
112 DEBUG(0, ("smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
113 error MISMATCH, forcing to NT_STATUS_LOGON_FAILURE"));
114 *nt_status
= NT_STATUS_LOGON_FAILURE
;
120 * PAM conversation function
121 * Here we assume (for now, at least) that echo on means login name, and
122 * echo off means password.
125 static int smb_pam_conv(int num_msg
,
126 const struct pam_message
**msg
,
127 struct pam_response
**resp
,
131 struct pam_response
*reply
= NULL
;
132 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
140 * Apparantly HPUX has a buggy PAM that doesn't support the
141 * appdata_ptr. Fail if this is the case. JRA.
145 DEBUG(0,("smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
149 reply
= SMB_MALLOC_ARRAY(struct pam_response
, num_msg
);
153 memset(reply
, '\0', sizeof(struct pam_response
) * num_msg
);
155 for (replies
= 0; replies
< num_msg
; replies
++) {
156 switch (msg
[replies
]->msg_style
) {
157 case PAM_PROMPT_ECHO_ON
:
158 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
159 reply
[replies
].resp
= smb_pam_copy_string(
164 case PAM_PROMPT_ECHO_OFF
:
165 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
166 reply
[replies
].resp
= smb_pam_copy_string(
176 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
177 reply
[replies
].resp
= NULL
;
181 /* Must be an error of some sort... */
192 * PAM password change conversation function
193 * Here we assume (for now, at least) that echo on means login name, and
194 * echo off means password.
197 static void special_char_sub(char *buf
)
199 all_string_sub(buf
, "\\n", "", 0);
200 all_string_sub(buf
, "\\r", "", 0);
201 all_string_sub(buf
, "\\s", " ", 0);
202 all_string_sub(buf
, "\\t", "\t", 0);
205 static void pwd_sub(char *buf
, const char *username
, const char *oldpass
, const char *newpass
)
207 fstring_sub(buf
, "%u", username
);
208 all_string_sub(buf
, "%o", oldpass
, sizeof(fstring
));
209 all_string_sub(buf
, "%n", newpass
, sizeof(fstring
));
214 struct chat_struct
*next
, *prev
;
219 /**************************************************************
220 Create a linked list containing chat data.
221 ***************************************************************/
223 static struct chat_struct
*make_pw_chat(const char *p
)
227 struct chat_struct
*list
= NULL
;
228 struct chat_struct
*t
;
229 TALLOC_CTX
*frame
= talloc_stackframe();
232 t
= SMB_MALLOC_P(struct chat_struct
);
234 DEBUG(0,("make_pw_chat: malloc failed!\n"));
241 DLIST_ADD_END(list
, t
);
243 if (!next_token_talloc(frame
, &p
, &prompt
, NULL
)) {
247 if (strequal(prompt
,".")) {
251 special_char_sub(prompt
);
252 fstrcpy(t
->prompt
, prompt
);
253 (void)strlower_m(t
->prompt
);
254 trim_char(t
->prompt
, ' ', ' ');
256 if (!next_token_talloc(frame
, &p
, &reply
, NULL
)) {
260 if (strequal(reply
,".")) {
264 special_char_sub(reply
);
265 fstrcpy(t
->reply
, reply
);
266 (void)strlower_m(t
->reply
);
267 trim_char(t
->reply
, ' ', ' ');
274 static void free_pw_chat(struct chat_struct
*list
)
277 struct chat_struct
*old_head
= list
;
278 DLIST_REMOVE(list
, list
);
283 static int smb_pam_passchange_conv(int num_msg
,
284 const struct pam_message
**msg
,
285 struct pam_response
**resp
,
289 struct pam_response
*reply
= NULL
;
290 fstring current_prompt
;
291 fstring current_reply
;
292 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
293 struct chat_struct
*pw_chat
;
294 struct chat_struct
*t
;
295 const struct loadparm_substitution
*lp_sub
=
296 loadparm_s3_global_substitution();
300 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg
));
305 if ((pw_chat
= make_pw_chat(lp_passwd_chat(talloc_tos(), lp_sub
))) == NULL
)
309 * Apparantly HPUX has a buggy PAM that doesn't support the
310 * appdata_ptr. Fail if this is the case. JRA.
314 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
315 free_pw_chat(pw_chat
);
319 reply
= SMB_MALLOC_ARRAY(struct pam_response
, num_msg
);
321 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
322 free_pw_chat(pw_chat
);
326 for (replies
= 0; replies
< num_msg
; replies
++) {
328 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies
));
329 switch (msg
[replies
]->msg_style
) {
330 case PAM_PROMPT_ECHO_ON
:
331 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg
[replies
]->msg
));
332 fstrcpy(current_prompt
, msg
[replies
]->msg
);
333 trim_char(current_prompt
, ' ', ' ');
334 for (t
=pw_chat
; t
; t
=t
->next
) {
336 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
337 t
->prompt
, current_prompt
));
339 if (unix_wild_match(t
->prompt
, current_prompt
)) {
340 fstrcpy(current_reply
, t
->reply
);
341 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply
));
342 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
343 #ifdef DEBUG_PASSWORD
344 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actually sent: %s\n", current_reply
));
346 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
347 reply
[replies
].resp
= smb_pam_copy_fstring(
355 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
356 free_pw_chat(pw_chat
);
362 case PAM_PROMPT_ECHO_OFF
:
363 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg
[replies
]->msg
));
364 fstrcpy(current_prompt
, msg
[replies
]->msg
);
365 trim_char(current_prompt
, ' ', ' ');
366 for (t
=pw_chat
; t
; t
=t
->next
) {
368 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
369 t
->prompt
, current_prompt
));
371 if (unix_wild_match(t
->prompt
, current_prompt
)) {
372 fstrcpy(current_reply
, t
->reply
);
373 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply
));
374 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
375 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
376 reply
[replies
].resp
= smb_pam_copy_fstring(
378 #ifdef DEBUG_PASSWORD
379 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actually sent: %s\n", current_reply
));
388 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
389 free_pw_chat(pw_chat
);
400 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
401 reply
[replies
].resp
= NULL
;
405 /* Must be an error of some sort... */
406 free_pw_chat(pw_chat
);
412 free_pw_chat(pw_chat
);
418 /***************************************************************************
419 Free up a malloced pam_conv struct.
420 ****************************************************************************/
422 static void smb_free_pam_conv(struct pam_conv
*pconv
)
425 SAFE_FREE(pconv
->appdata_ptr
);
430 /***************************************************************************
431 Allocate a pam_conv struct.
432 ****************************************************************************/
434 static struct pam_conv
*smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr
, const char *user
,
435 const char *passwd
, const char *newpass
)
437 struct pam_conv
*pconv
= SMB_MALLOC_P(struct pam_conv
);
438 struct smb_pam_userdata
*udp
= SMB_MALLOC_P(struct smb_pam_userdata
);
440 if (pconv
== NULL
|| udp
== NULL
) {
446 udp
->PAM_username
= user
;
447 udp
->PAM_password
= passwd
;
448 udp
->PAM_newpassword
= newpass
;
450 pconv
->conv
= smb_pam_conv_fnptr
;
451 pconv
->appdata_ptr
= (void *)udp
;
456 * PAM Closing out cleanup handler
459 static bool smb_pam_end(pam_handle_t
*pamh
, struct pam_conv
*smb_pam_conv_ptr
)
463 smb_free_pam_conv(smb_pam_conv_ptr
);
466 pam_error
= pam_end(pamh
, 0);
467 if(smb_pam_error_handler(pamh
, pam_error
, "End Cleanup Failed", 2) == True
) {
468 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
472 DEBUG(2,("smb_pam_end: PAM: not initialised"));
477 * Start PAM authentication for specified account
480 static bool smb_pam_start(pam_handle_t
**pamh
, const char *user
, const char *rhost
, struct pam_conv
*pconv
)
484 *pamh
= (pam_handle_t
*)NULL
;
486 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user
));
488 pam_error
= pam_start("samba", user
, pconv
, pamh
);
489 if( !smb_pam_error_handler(*pamh
, pam_error
, "Init Failed", 0)) {
490 *pamh
= (pam_handle_t
*)NULL
;
494 #ifdef HAVE_PAM_RHOST
495 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", rhost
));
496 pam_error
= pam_set_item(*pamh
, PAM_RHOST
, rhost
);
497 if(!smb_pam_error_handler(*pamh
, pam_error
, "set rhost failed", 0)) {
498 smb_pam_end(*pamh
, pconv
);
499 *pamh
= (pam_handle_t
*)NULL
;
504 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
505 pam_error
= pam_set_item(*pamh
, PAM_TTY
, "samba");
506 if (!smb_pam_error_handler(*pamh
, pam_error
, "set tty failed", 0)) {
507 smb_pam_end(*pamh
, pconv
);
508 *pamh
= (pam_handle_t
*)NULL
;
512 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user
));
517 * PAM Authentication Handler
519 static NTSTATUS
smb_pam_auth(pam_handle_t
*pamh
, const char *user
)
522 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
525 * To enable debugging set in /etc/pam.d/samba:
526 * auth required /lib/security/pam_pwdb.so nullok shadow audit
529 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user
));
530 pam_error
= pam_authenticate(pamh
, PAM_SILENT
| (lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK
));
533 DEBUG(2, ("smb_pam_auth: PAM: Authentication Error for user %s\n", user
));
535 case PAM_CRED_INSUFFICIENT
:
536 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user
));
538 case PAM_AUTHINFO_UNAVAIL
:
539 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user
));
541 case PAM_USER_UNKNOWN
:
542 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user
));
545 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user
));
548 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user
));
551 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user
));
554 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user
));
558 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Authentication Failure", 2, &nt_status
);
563 * PAM Account Handler
565 static NTSTATUS
smb_pam_account(pam_handle_t
*pamh
, const char * user
)
568 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
570 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user
));
571 pam_error
= pam_acct_mgmt(pamh
, PAM_SILENT
); /* Is user account enabled? */
572 switch( pam_error
) {
573 case PAM_AUTHTOK_EXPIRED
:
574 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user
));
576 case PAM_ACCT_EXPIRED
:
577 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user
));
580 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user
));
582 case PAM_PERM_DENIED
:
583 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user
));
585 case PAM_USER_UNKNOWN
:
586 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user
));
589 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user
));
592 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error
, user
));
596 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Account Check Failed", 2, &nt_status
);
601 * PAM Credential Setting
604 static NTSTATUS
smb_pam_setcred(pam_handle_t
*pamh
, const char * user
)
607 NTSTATUS nt_status
= NT_STATUS_NO_TOKEN
;
610 * This will allow samba to aquire a kerberos token. And, when
611 * exporting an AFS cell, be able to /write/ to this cell.
614 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user
));
615 pam_error
= pam_setcred(pamh
, (PAM_ESTABLISH_CRED
|PAM_SILENT
));
616 switch( pam_error
) {
617 case PAM_CRED_UNAVAIL
:
618 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user
));
620 case PAM_CRED_EXPIRED
:
621 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user
));
623 case PAM_USER_UNKNOWN
:
624 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user
));
627 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user
));
630 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user
));
633 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error
, user
));
637 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Set Credential Failure", 2, &nt_status
);
642 * PAM Internal Session Handler
644 static bool smb_internal_pam_session(pam_handle_t
*pamh
, const char *user
, const char *tty
, bool flag
)
649 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty
));
650 pam_error
= pam_set_item(pamh
, PAM_TTY
, tty
);
651 if (!smb_pam_error_handler(pamh
, pam_error
, "set tty failed", 0))
656 pam_error
= pam_open_session(pamh
, PAM_SILENT
);
657 if (!smb_pam_error_handler(pamh
, pam_error
, "session setup failed", 0))
660 pam_setcred(pamh
, (PAM_DELETE_CRED
|PAM_SILENT
)); /* We don't care if this fails */
661 pam_error
= pam_close_session(pamh
, PAM_SILENT
); /* This will probably pick up the error anyway */
662 if (!smb_pam_error_handler(pamh
, pam_error
, "session close failed", 0))
669 * Internal PAM Password Changer.
672 static bool smb_pam_chauthtok(pam_handle_t
*pamh
, const char * user
)
676 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user
));
678 pam_error
= pam_chauthtok(pamh
, PAM_SILENT
); /* Change Password */
680 switch( pam_error
) {
681 case PAM_AUTHTOK_ERR
:
682 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
685 /* This doesn't seem to be defined on Solaris. JRA */
686 #ifdef PAM_AUTHTOK_RECOVER_ERR
687 case PAM_AUTHTOK_RECOVER_ERR
:
688 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
692 case PAM_AUTHTOK_LOCK_BUSY
:
693 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
695 case PAM_AUTHTOK_DISABLE_AGING
:
696 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
698 case PAM_PERM_DENIED
:
699 DEBUG(0, ("PAM: Permission denied.\n"));
702 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
704 case PAM_USER_UNKNOWN
:
705 DEBUG(0, ("PAM: User not known to PAM\n"));
708 DEBUG(4, ("PAM: Account OK for User: %s\n", user
));
711 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error
, user
));
714 if(!smb_pam_error_handler(pamh
, pam_error
, "Password Change Failed", 2)) {
718 /* If this point is reached, the password has changed. */
723 * PAM Externally accessible Session handler
726 bool smb_pam_claim_session(const char *user
, const char *tty
, const char *rhost
)
728 pam_handle_t
*pamh
= NULL
;
729 struct pam_conv
*pconv
= NULL
;
731 /* Ignore PAM if told to. */
733 if (!lp_obey_pam_restrictions())
736 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
739 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
742 if (!smb_internal_pam_session(pamh
, user
, tty
, True
)) {
743 smb_pam_end(pamh
, pconv
);
747 return smb_pam_end(pamh
, pconv
);
751 * PAM Externally accessible Session handler
754 bool smb_pam_close_session(const char *user
, const char *tty
, const char *rhost
)
756 pam_handle_t
*pamh
= NULL
;
757 struct pam_conv
*pconv
= NULL
;
759 /* Ignore PAM if told to. */
761 if (!lp_obey_pam_restrictions())
764 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
767 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
770 if (!smb_internal_pam_session(pamh
, user
, tty
, False
)) {
771 smb_pam_end(pamh
, pconv
);
775 return smb_pam_end(pamh
, pconv
);
779 * PAM Externally accessible Account handler
782 NTSTATUS
smb_pam_accountcheck(const char *user
, const char *rhost
)
784 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
785 pam_handle_t
*pamh
= NULL
;
786 struct pam_conv
*pconv
= NULL
;
788 /* Ignore PAM if told to. */
790 if (!lp_obey_pam_restrictions())
793 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
794 return NT_STATUS_NO_MEMORY
;
796 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
797 return NT_STATUS_ACCOUNT_DISABLED
;
799 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
)))
800 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user
));
802 smb_pam_end(pamh
, pconv
);
807 * PAM Password Validation Suite
810 NTSTATUS
smb_pam_passcheck(const char * user
, const char * rhost
,
811 const char * password
)
813 pam_handle_t
*pamh
= NULL
;
814 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
815 struct pam_conv
*pconv
= NULL
;
818 * Note we can't ignore PAM here as this is the only
819 * way of doing auths on plaintext passwords when
820 * compiled --with-pam.
823 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, password
, NULL
)) == NULL
)
824 return NT_STATUS_LOGON_FAILURE
;
826 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
827 return NT_STATUS_LOGON_FAILURE
;
829 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_auth(pamh
, user
))) {
830 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user
));
831 smb_pam_end(pamh
, pconv
);
835 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
))) {
836 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user
));
837 smb_pam_end(pamh
, pconv
);
841 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_setcred(pamh
, user
))) {
842 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user
));
843 smb_pam_end(pamh
, pconv
);
847 smb_pam_end(pamh
, pconv
);
852 * PAM Password Change Suite
855 bool smb_pam_passchange(const char *user
, const char *rhost
,
856 const char *oldpassword
, const char *newpassword
)
858 /* Appropriate quantities of root should be obtained BEFORE calling this function */
859 struct pam_conv
*pconv
= NULL
;
860 pam_handle_t
*pamh
= NULL
;
862 if ((pconv
= smb_setup_pam_conv(smb_pam_passchange_conv
, user
, oldpassword
, newpassword
)) == NULL
)
865 if(!smb_pam_start(&pamh
, user
, rhost
, pconv
))
868 if (!smb_pam_chauthtok(pamh
, user
)) {
869 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user
));
870 smb_pam_end(pamh
, pconv
);
874 return smb_pam_end(pamh
, pconv
);
879 /* If PAM not used, no PAM restrictions on accounts. */
880 NTSTATUS
smb_pam_accountcheck(const char *user
, const char *rhost
)
885 /* If PAM not used, also no PAM restrictions on sessions. */
886 bool smb_pam_claim_session(const char *user
, const char *tty
, const char *rhost
)
891 /* If PAM not used, also no PAM restrictions on sessions. */
892 bool smb_pam_close_session(const char *in_user
, const char *tty
, const char *rhost
)
896 #endif /* WITH_PAM */