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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * This module provides PAM based functions for validation of
26 * username/password pairs, account managment, session and access control.
27 * Note: SMB password checking is done in smbpass.c
33 #define DBGC_CLASS DBGC_AUTH
37 /*******************************************************************
38 * Handle PAM authentication
39 * - Access, Authentication, Session, Password
40 * Note: See PAM Documentation and refer to local system PAM implementation
41 * which determines what actions/limitations/allowances become affected.
42 *********************************************************************/
44 #include <security/pam_appl.h>
47 * Structure used to communicate between the conversation function
48 * and the server_login/change password functions.
51 struct smb_pam_userdata
{
52 const char *PAM_username
;
53 const char *PAM_password
;
54 const char *PAM_newpassword
;
57 typedef int (*smb_pam_conv_fn
)(int, const struct pam_message
**, struct pam_response
**, void *appdata_ptr
);
60 * Macros to help make life easy
62 #define COPY_STRING(s) (s) ? strdup(s) : NULL
64 /*******************************************************************
66 *********************************************************************/
68 static BOOL
smb_pam_error_handler(pam_handle_t
*pamh
, int pam_error
, char *msg
, int dbglvl
)
71 if( pam_error
!= PAM_SUCCESS
) {
72 DEBUG(dbglvl
, ("smb_pam_error_handler: PAM: %s : %s\n",
73 msg
, pam_strerror(pamh
, pam_error
)));
80 /*******************************************************************
81 This function is a sanity check, to make sure that we NEVER report
83 *********************************************************************/
85 static BOOL
smb_pam_nt_status_error_handler(pam_handle_t
*pamh
, int pam_error
,
86 char *msg
, int dbglvl
,
89 *nt_status
= pam_to_nt_status(pam_error
);
91 if (smb_pam_error_handler(pamh
, pam_error
, msg
, dbglvl
))
94 if (NT_STATUS_IS_OK(*nt_status
)) {
96 DEBUG(0, ("smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
97 error MISMATCH, forcing to NT_STATUS_LOGON_FAILURE"));
98 *nt_status
= NT_STATUS_LOGON_FAILURE
;
104 * PAM conversation function
105 * Here we assume (for now, at least) that echo on means login name, and
106 * echo off means password.
109 static int smb_pam_conv(int num_msg
,
110 const struct pam_message
**msg
,
111 struct pam_response
**resp
,
115 struct pam_response
*reply
= NULL
;
116 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
124 * Apparantly HPUX has a buggy PAM that doesn't support the
125 * appdata_ptr. Fail if this is the case. JRA.
129 DEBUG(0,("smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
133 reply
= malloc(sizeof(struct pam_response
) * num_msg
);
137 memset(reply
, '\0', sizeof(struct pam_response
) * num_msg
);
139 for (replies
= 0; replies
< num_msg
; replies
++) {
140 switch (msg
[replies
]->msg_style
) {
141 case PAM_PROMPT_ECHO_ON
:
142 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
143 reply
[replies
].resp
= COPY_STRING(udp
->PAM_username
);
147 case PAM_PROMPT_ECHO_OFF
:
148 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
149 reply
[replies
].resp
= COPY_STRING(udp
->PAM_password
);
158 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
159 reply
[replies
].resp
= NULL
;
163 /* Must be an error of some sort... */
174 * PAM password change conversation function
175 * Here we assume (for now, at least) that echo on means login name, and
176 * echo off means password.
179 static void special_char_sub(char *buf
)
181 all_string_sub(buf
, "\\n", "", 0);
182 all_string_sub(buf
, "\\r", "", 0);
183 all_string_sub(buf
, "\\s", " ", 0);
184 all_string_sub(buf
, "\\t", "\t", 0);
187 static void pwd_sub(char *buf
, const char *username
, const char *oldpass
, const char *newpass
)
189 fstring_sub(buf
, "%u", username
);
190 all_string_sub(buf
, "%o", oldpass
, sizeof(fstring
));
191 all_string_sub(buf
, "%n", newpass
, sizeof(fstring
));
196 struct chat_struct
*next
, *prev
;
201 /**************************************************************
202 Create a linked list containing chat data.
203 ***************************************************************/
205 static struct chat_struct
*make_pw_chat(char *p
)
209 struct chat_struct
*list
= NULL
;
210 struct chat_struct
*t
;
211 struct chat_struct
*tmp
;
214 t
= (struct chat_struct
*)malloc(sizeof(*t
));
216 DEBUG(0,("make_pw_chat: malloc failed!\n"));
222 DLIST_ADD_END(list
, t
, tmp
);
224 if (!next_token(&p
, prompt
, NULL
, sizeof(fstring
)))
227 if (strequal(prompt
,"."))
230 special_char_sub(prompt
);
231 fstrcpy(t
->prompt
, prompt
);
233 trim_string(t
->prompt
, " ", " ");
235 if (!next_token(&p
, reply
, NULL
, sizeof(fstring
)))
238 if (strequal(reply
,"."))
241 special_char_sub(reply
);
242 fstrcpy(t
->reply
, reply
);
244 trim_string(t
->reply
, " ", " ");
250 static void free_pw_chat(struct chat_struct
*list
)
253 struct chat_struct
*old_head
= list
;
254 DLIST_REMOVE(list
, list
);
259 static int smb_pam_passchange_conv(int num_msg
,
260 const struct pam_message
**msg
,
261 struct pam_response
**resp
,
265 struct pam_response
*reply
= NULL
;
266 fstring current_prompt
;
267 fstring current_reply
;
268 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
269 struct chat_struct
*pw_chat
= make_pw_chat(lp_passwd_chat());
270 struct chat_struct
*t
;
274 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg
));
283 * Apparantly HPUX has a buggy PAM that doesn't support the
284 * appdata_ptr. Fail if this is the case. JRA.
288 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
289 free_pw_chat(pw_chat
);
293 reply
= malloc(sizeof(struct pam_response
) * num_msg
);
295 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
296 free_pw_chat(pw_chat
);
300 for (replies
= 0; replies
< num_msg
; replies
++) {
302 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies
));
303 switch (msg
[replies
]->msg_style
) {
304 case PAM_PROMPT_ECHO_ON
:
305 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg
[replies
]->msg
));
306 fstrcpy(current_prompt
, msg
[replies
]->msg
);
307 trim_string(current_prompt
, " ", " ");
308 for (t
=pw_chat
; t
; t
=t
->next
) {
310 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
311 t
->prompt
, current_prompt
));
313 if (unix_wild_match(t
->prompt
, current_prompt
) == 0) {
314 fstrcpy(current_reply
, t
->reply
);
315 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply
));
316 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
317 #ifdef DEBUG_PASSWORD
318 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply
));
320 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
321 reply
[replies
].resp
= COPY_STRING(current_reply
);
328 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
329 free_pw_chat(pw_chat
);
335 case PAM_PROMPT_ECHO_OFF
:
336 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg
[replies
]->msg
));
337 fstrcpy(current_prompt
, msg
[replies
]->msg
);
338 trim_string(current_prompt
, " ", " ");
339 for (t
=pw_chat
; t
; t
=t
->next
) {
341 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
342 t
->prompt
, current_prompt
));
344 if (unix_wild_match(t
->prompt
, current_prompt
) == 0) {
345 fstrcpy(current_reply
, t
->reply
);
346 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply
));
347 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
348 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
349 reply
[replies
].resp
= COPY_STRING(current_reply
);
350 #ifdef DEBUG_PASSWORD
351 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply
));
360 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
361 free_pw_chat(pw_chat
);
372 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
373 reply
[replies
].resp
= NULL
;
377 /* Must be an error of some sort... */
378 free_pw_chat(pw_chat
);
384 free_pw_chat(pw_chat
);
390 /***************************************************************************
391 Free up a malloced pam_conv struct.
392 ****************************************************************************/
394 static void smb_free_pam_conv(struct pam_conv
*pconv
)
397 SAFE_FREE(pconv
->appdata_ptr
);
402 /***************************************************************************
403 Allocate a pam_conv struct.
404 ****************************************************************************/
406 static struct pam_conv
*smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr
, const char *user
,
407 const char *passwd
, const char *newpass
)
409 struct pam_conv
*pconv
= (struct pam_conv
*)malloc(sizeof(struct pam_conv
));
410 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)malloc(sizeof(struct smb_pam_userdata
));
412 if (pconv
== NULL
|| udp
== NULL
) {
418 udp
->PAM_username
= user
;
419 udp
->PAM_password
= passwd
;
420 udp
->PAM_newpassword
= newpass
;
422 pconv
->conv
= smb_pam_conv_fnptr
;
423 pconv
->appdata_ptr
= (void *)udp
;
428 * PAM Closing out cleanup handler
431 static BOOL
smb_pam_end(pam_handle_t
*pamh
, struct pam_conv
*smb_pam_conv_ptr
)
435 smb_free_pam_conv(smb_pam_conv_ptr
);
438 pam_error
= pam_end(pamh
, 0);
439 if(smb_pam_error_handler(pamh
, pam_error
, "End Cleanup Failed", 2) == True
) {
440 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
444 DEBUG(2,("smb_pam_end: PAM: not initialised"));
449 * Start PAM authentication for specified account
452 static BOOL
smb_pam_start(pam_handle_t
**pamh
, const char *user
, const char *rhost
, struct pam_conv
*pconv
)
455 const char *our_rhost
;
457 *pamh
= (pam_handle_t
*)NULL
;
459 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user
));
461 pam_error
= pam_start("samba", user
, pconv
, pamh
);
462 if( !smb_pam_error_handler(*pamh
, pam_error
, "Init Failed", 0)) {
463 *pamh
= (pam_handle_t
*)NULL
;
468 our_rhost
= client_name();
469 if (strequal(rhost
,"UNKNOWN"))
470 our_rhost
= client_addr();
476 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost
));
477 pam_error
= pam_set_item(*pamh
, PAM_RHOST
, our_rhost
);
478 if(!smb_pam_error_handler(*pamh
, pam_error
, "set rhost failed", 0)) {
479 smb_pam_end(*pamh
, pconv
);
480 *pamh
= (pam_handle_t
*)NULL
;
485 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
486 pam_error
= pam_set_item(*pamh
, PAM_TTY
, "samba");
487 if (!smb_pam_error_handler(*pamh
, pam_error
, "set tty failed", 0)) {
488 smb_pam_end(*pamh
, pconv
);
489 *pamh
= (pam_handle_t
*)NULL
;
493 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user
));
498 * PAM Authentication Handler
500 static NTSTATUS
smb_pam_auth(pam_handle_t
*pamh
, const char *user
)
503 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
506 * To enable debugging set in /etc/pam.d/samba:
507 * auth required /lib/security/pam_pwdb.so nullok shadow audit
510 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user
));
511 pam_error
= pam_authenticate(pamh
, PAM_SILENT
| lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK
);
514 DEBUG(2, ("smb_pam_auth: PAM: Athentication Error for user %s\n", user
));
516 case PAM_CRED_INSUFFICIENT
:
517 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user
));
519 case PAM_AUTHINFO_UNAVAIL
:
520 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user
));
522 case PAM_USER_UNKNOWN
:
523 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user
));
526 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user
));
529 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user
));
532 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user
));
535 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user
));
539 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Authentication Failure", 2, &nt_status
);
544 * PAM Account Handler
546 static NTSTATUS
smb_pam_account(pam_handle_t
*pamh
, const char * user
)
549 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
551 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user
));
552 pam_error
= pam_acct_mgmt(pamh
, PAM_SILENT
); /* Is user account enabled? */
553 switch( pam_error
) {
554 case PAM_AUTHTOK_EXPIRED
:
555 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user
));
557 case PAM_ACCT_EXPIRED
:
558 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user
));
561 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user
));
563 case PAM_PERM_DENIED
:
564 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user
));
566 case PAM_USER_UNKNOWN
:
567 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user
));
570 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user
));
573 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error
, user
));
577 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Account Check Failed", 2, &nt_status
);
582 * PAM Credential Setting
585 static NTSTATUS
smb_pam_setcred(pam_handle_t
*pamh
, const char * user
)
588 NTSTATUS nt_status
= NT_STATUS_NO_TOKEN
;
591 * This will allow samba to aquire a kerberos token. And, when
592 * exporting an AFS cell, be able to /write/ to this cell.
595 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user
));
596 pam_error
= pam_setcred(pamh
, (PAM_ESTABLISH_CRED
|PAM_SILENT
));
597 switch( pam_error
) {
598 case PAM_CRED_UNAVAIL
:
599 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user
));
601 case PAM_CRED_EXPIRED
:
602 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user
));
604 case PAM_USER_UNKNOWN
:
605 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user
));
608 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user
));
611 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user
));
614 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error
, user
));
618 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Set Credential Failure", 2, &nt_status
);
623 * PAM Internal Session Handler
625 static BOOL
smb_internal_pam_session(pam_handle_t
*pamh
, const char *user
, const char *tty
, BOOL flag
)
630 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty
));
631 pam_error
= pam_set_item(pamh
, PAM_TTY
, tty
);
632 if (!smb_pam_error_handler(pamh
, pam_error
, "set tty failed", 0))
637 pam_error
= pam_open_session(pamh
, PAM_SILENT
);
638 if (!smb_pam_error_handler(pamh
, pam_error
, "session setup failed", 0))
641 pam_setcred(pamh
, (PAM_DELETE_CRED
|PAM_SILENT
)); /* We don't care if this fails */
642 pam_error
= pam_close_session(pamh
, PAM_SILENT
); /* This will probably pick up the error anyway */
643 if (!smb_pam_error_handler(pamh
, pam_error
, "session close failed", 0))
650 * Internal PAM Password Changer.
653 static BOOL
smb_pam_chauthtok(pam_handle_t
*pamh
, const char * user
)
657 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user
));
659 pam_error
= pam_chauthtok(pamh
, PAM_SILENT
); /* Change Password */
661 switch( pam_error
) {
662 case PAM_AUTHTOK_ERR
:
663 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
666 /* This doesn't seem to be defined on Solaris. JRA */
667 #ifdef PAM_AUTHTOK_RECOVER_ERR
668 case PAM_AUTHTOK_RECOVER_ERR
:
669 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
673 case PAM_AUTHTOK_LOCK_BUSY
:
674 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
676 case PAM_AUTHTOK_DISABLE_AGING
:
677 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
679 case PAM_PERM_DENIED
:
680 DEBUG(0, ("PAM: Permission denied.\n"));
683 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
685 case PAM_USER_UNKNOWN
:
686 DEBUG(0, ("PAM: User not known to PAM\n"));
689 DEBUG(4, ("PAM: Account OK for User: %s\n", user
));
692 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error
, user
));
695 if(!smb_pam_error_handler(pamh
, pam_error
, "Password Change Failed", 2)) {
699 /* If this point is reached, the password has changed. */
704 * PAM Externally accessible Session handler
707 BOOL
smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
709 pam_handle_t
*pamh
= NULL
;
710 struct pam_conv
*pconv
= NULL
;
712 /* Ignore PAM if told to. */
714 if (!lp_obey_pam_restrictions())
717 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
720 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
723 if (!smb_internal_pam_session(pamh
, user
, tty
, True
)) {
724 smb_pam_end(pamh
, pconv
);
728 return smb_pam_end(pamh
, pconv
);
732 * PAM Externally accessible Session handler
735 BOOL
smb_pam_close_session(char *user
, char *tty
, char *rhost
)
737 pam_handle_t
*pamh
= NULL
;
738 struct pam_conv
*pconv
= NULL
;
740 /* Ignore PAM if told to. */
742 if (!lp_obey_pam_restrictions())
745 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
748 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
751 if (!smb_internal_pam_session(pamh
, user
, tty
, False
)) {
752 smb_pam_end(pamh
, pconv
);
756 return smb_pam_end(pamh
, pconv
);
760 * PAM Externally accessible Account handler
763 NTSTATUS
smb_pam_accountcheck(const char * user
)
765 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
766 pam_handle_t
*pamh
= NULL
;
767 struct pam_conv
*pconv
= NULL
;
769 /* Ignore PAM if told to. */
771 if (!lp_obey_pam_restrictions())
774 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
775 return NT_STATUS_NO_MEMORY
;
777 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
778 return NT_STATUS_ACCOUNT_DISABLED
;
780 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
)))
781 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user
));
783 smb_pam_end(pamh
, pconv
);
788 * PAM Password Validation Suite
791 NTSTATUS
smb_pam_passcheck(const char * user
, const char * password
)
793 pam_handle_t
*pamh
= NULL
;
794 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
795 struct pam_conv
*pconv
= NULL
;
798 * Note we can't ignore PAM here as this is the only
799 * way of doing auths on plaintext passwords when
800 * compiled --with-pam.
803 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, password
, NULL
)) == NULL
)
804 return NT_STATUS_LOGON_FAILURE
;
806 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
807 return NT_STATUS_LOGON_FAILURE
;
809 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_auth(pamh
, user
))) {
810 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user
));
811 smb_pam_end(pamh
, pconv
);
815 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
))) {
816 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user
));
817 smb_pam_end(pamh
, pconv
);
821 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_setcred(pamh
, user
))) {
822 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user
));
823 smb_pam_end(pamh
, pconv
);
827 smb_pam_end(pamh
, pconv
);
832 * PAM Password Change Suite
835 BOOL
smb_pam_passchange(const char * user
, const char * oldpassword
, const char * newpassword
)
837 /* Appropriate quantities of root should be obtained BEFORE calling this function */
838 struct pam_conv
*pconv
= NULL
;
839 pam_handle_t
*pamh
= NULL
;
841 if ((pconv
= smb_setup_pam_conv(smb_pam_passchange_conv
, user
, oldpassword
, newpassword
)) == NULL
)
844 if(!smb_pam_start(&pamh
, user
, NULL
, pconv
))
847 if (!smb_pam_chauthtok(pamh
, user
)) {
848 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user
));
849 smb_pam_end(pamh
, pconv
);
853 return smb_pam_end(pamh
, pconv
);
858 /* If PAM not used, no PAM restrictions on accounts. */
859 NTSTATUS
smb_pam_accountcheck(const char * user
)
864 /* If PAM not used, also no PAM restrictions on sessions. */
865 BOOL
smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
870 /* If PAM not used, also no PAM restrictions on sessions. */
871 BOOL
smb_pam_close_session(char *in_user
, char *tty
, char *rhost
)
875 #endif /* WITH_PAM */