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) ? SMB_STRDUP(s) : NULL
64 /*******************************************************************
66 *********************************************************************/
68 static BOOL
smb_pam_error_handler(pam_handle_t
*pamh
, int pam_error
, const 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 const 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
= SMB_MALLOC_ARRAY(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(const char *p
)
209 struct chat_struct
*list
= NULL
;
210 struct chat_struct
*t
;
213 t
= SMB_MALLOC_P(struct chat_struct
);
215 DEBUG(0,("make_pw_chat: malloc failed!\n"));
221 DLIST_ADD_END(list
, t
, struct chat_struct
*);
223 if (!next_token(&p
, prompt
, NULL
, sizeof(fstring
)))
226 if (strequal(prompt
,"."))
229 special_char_sub(prompt
);
230 fstrcpy(t
->prompt
, prompt
);
231 strlower_m(t
->prompt
);
232 trim_char(t
->prompt
, ' ', ' ');
234 if (!next_token(&p
, reply
, NULL
, sizeof(fstring
)))
237 if (strequal(reply
,"."))
240 special_char_sub(reply
);
241 fstrcpy(t
->reply
, reply
);
242 strlower_m(t
->reply
);
243 trim_char(t
->reply
, ' ', ' ');
249 static void free_pw_chat(struct chat_struct
*list
)
252 struct chat_struct
*old_head
= list
;
253 DLIST_REMOVE(list
, list
);
258 static int smb_pam_passchange_conv(int num_msg
,
259 const struct pam_message
**msg
,
260 struct pam_response
**resp
,
264 struct pam_response
*reply
= NULL
;
265 fstring current_prompt
;
266 fstring current_reply
;
267 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
268 struct chat_struct
*pw_chat
= make_pw_chat(lp_passwd_chat());
269 struct chat_struct
*t
;
273 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg
));
282 * Apparantly HPUX has a buggy PAM that doesn't support the
283 * appdata_ptr. Fail if this is the case. JRA.
287 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
288 free_pw_chat(pw_chat
);
292 reply
= SMB_MALLOC_ARRAY(struct pam_response
, num_msg
);
294 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
295 free_pw_chat(pw_chat
);
299 for (replies
= 0; replies
< num_msg
; replies
++) {
301 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies
));
302 switch (msg
[replies
]->msg_style
) {
303 case PAM_PROMPT_ECHO_ON
:
304 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg
[replies
]->msg
));
305 fstrcpy(current_prompt
, msg
[replies
]->msg
);
306 trim_char(current_prompt
, ' ', ' ');
307 for (t
=pw_chat
; t
; t
=t
->next
) {
309 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
310 t
->prompt
, current_prompt
));
312 if (unix_wild_match(t
->prompt
, current_prompt
)) {
313 fstrcpy(current_reply
, t
->reply
);
314 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply
));
315 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
316 #ifdef DEBUG_PASSWORD
317 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply
));
319 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
320 reply
[replies
].resp
= COPY_STRING(current_reply
);
327 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
328 free_pw_chat(pw_chat
);
334 case PAM_PROMPT_ECHO_OFF
:
335 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg
[replies
]->msg
));
336 fstrcpy(current_prompt
, msg
[replies
]->msg
);
337 trim_char(current_prompt
, ' ', ' ');
338 for (t
=pw_chat
; t
; t
=t
->next
) {
340 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
341 t
->prompt
, current_prompt
));
343 if (unix_wild_match(t
->prompt
, current_prompt
)) {
344 fstrcpy(current_reply
, t
->reply
);
345 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply
));
346 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
347 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
348 reply
[replies
].resp
= COPY_STRING(current_reply
);
349 #ifdef DEBUG_PASSWORD
350 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply
));
359 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
360 free_pw_chat(pw_chat
);
371 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
372 reply
[replies
].resp
= NULL
;
376 /* Must be an error of some sort... */
377 free_pw_chat(pw_chat
);
383 free_pw_chat(pw_chat
);
389 /***************************************************************************
390 Free up a malloced pam_conv struct.
391 ****************************************************************************/
393 static void smb_free_pam_conv(struct pam_conv
*pconv
)
396 SAFE_FREE(pconv
->appdata_ptr
);
401 /***************************************************************************
402 Allocate a pam_conv struct.
403 ****************************************************************************/
405 static struct pam_conv
*smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr
, const char *user
,
406 const char *passwd
, const char *newpass
)
408 struct pam_conv
*pconv
= SMB_MALLOC_P(struct pam_conv
);
409 struct smb_pam_userdata
*udp
= SMB_MALLOC_P(struct smb_pam_userdata
);
411 if (pconv
== NULL
|| udp
== NULL
) {
417 udp
->PAM_username
= user
;
418 udp
->PAM_password
= passwd
;
419 udp
->PAM_newpassword
= newpass
;
421 pconv
->conv
= smb_pam_conv_fnptr
;
422 pconv
->appdata_ptr
= (void *)udp
;
427 * PAM Closing out cleanup handler
430 static BOOL
smb_pam_end(pam_handle_t
*pamh
, struct pam_conv
*smb_pam_conv_ptr
)
434 smb_free_pam_conv(smb_pam_conv_ptr
);
437 pam_error
= pam_end(pamh
, 0);
438 if(smb_pam_error_handler(pamh
, pam_error
, "End Cleanup Failed", 2) == True
) {
439 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
443 DEBUG(2,("smb_pam_end: PAM: not initialised"));
448 * Start PAM authentication for specified account
451 static BOOL
smb_pam_start(pam_handle_t
**pamh
, const char *user
, const char *rhost
, struct pam_conv
*pconv
)
454 const char *our_rhost
;
456 *pamh
= (pam_handle_t
*)NULL
;
458 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user
));
460 pam_error
= pam_start("samba", user
, pconv
, pamh
);
461 if( !smb_pam_error_handler(*pamh
, pam_error
, "Init Failed", 0)) {
462 *pamh
= (pam_handle_t
*)NULL
;
467 our_rhost
= client_name();
468 if (strequal(our_rhost
,"UNKNOWN"))
469 our_rhost
= client_addr();
475 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost
));
476 pam_error
= pam_set_item(*pamh
, PAM_RHOST
, our_rhost
);
477 if(!smb_pam_error_handler(*pamh
, pam_error
, "set rhost failed", 0)) {
478 smb_pam_end(*pamh
, pconv
);
479 *pamh
= (pam_handle_t
*)NULL
;
484 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
485 pam_error
= pam_set_item(*pamh
, PAM_TTY
, "samba");
486 if (!smb_pam_error_handler(*pamh
, pam_error
, "set tty failed", 0)) {
487 smb_pam_end(*pamh
, pconv
);
488 *pamh
= (pam_handle_t
*)NULL
;
492 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user
));
497 * PAM Authentication Handler
499 static NTSTATUS
smb_pam_auth(pam_handle_t
*pamh
, const char *user
)
502 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
505 * To enable debugging set in /etc/pam.d/samba:
506 * auth required /lib/security/pam_pwdb.so nullok shadow audit
509 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user
));
510 pam_error
= pam_authenticate(pamh
, PAM_SILENT
| lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK
);
513 DEBUG(2, ("smb_pam_auth: PAM: Authentication Error for user %s\n", user
));
515 case PAM_CRED_INSUFFICIENT
:
516 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user
));
518 case PAM_AUTHINFO_UNAVAIL
:
519 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user
));
521 case PAM_USER_UNKNOWN
:
522 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user
));
525 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user
));
528 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user
));
531 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user
));
534 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user
));
538 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Authentication Failure", 2, &nt_status
);
543 * PAM Account Handler
545 static NTSTATUS
smb_pam_account(pam_handle_t
*pamh
, const char * user
)
548 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
550 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user
));
551 pam_error
= pam_acct_mgmt(pamh
, PAM_SILENT
); /* Is user account enabled? */
552 switch( pam_error
) {
553 case PAM_AUTHTOK_EXPIRED
:
554 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user
));
556 case PAM_ACCT_EXPIRED
:
557 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user
));
560 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user
));
562 case PAM_PERM_DENIED
:
563 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user
));
565 case PAM_USER_UNKNOWN
:
566 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user
));
569 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user
));
572 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error
, user
));
576 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Account Check Failed", 2, &nt_status
);
581 * PAM Credential Setting
584 static NTSTATUS
smb_pam_setcred(pam_handle_t
*pamh
, const char * user
)
587 NTSTATUS nt_status
= NT_STATUS_NO_TOKEN
;
590 * This will allow samba to aquire a kerberos token. And, when
591 * exporting an AFS cell, be able to /write/ to this cell.
594 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user
));
595 pam_error
= pam_setcred(pamh
, (PAM_ESTABLISH_CRED
|PAM_SILENT
));
596 switch( pam_error
) {
597 case PAM_CRED_UNAVAIL
:
598 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user
));
600 case PAM_CRED_EXPIRED
:
601 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user
));
603 case PAM_USER_UNKNOWN
:
604 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user
));
607 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user
));
610 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user
));
613 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error
, user
));
617 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Set Credential Failure", 2, &nt_status
);
622 * PAM Internal Session Handler
624 static BOOL
smb_internal_pam_session(pam_handle_t
*pamh
, const char *user
, const char *tty
, BOOL flag
)
629 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty
));
630 pam_error
= pam_set_item(pamh
, PAM_TTY
, tty
);
631 if (!smb_pam_error_handler(pamh
, pam_error
, "set tty failed", 0))
636 pam_error
= pam_open_session(pamh
, PAM_SILENT
);
637 if (!smb_pam_error_handler(pamh
, pam_error
, "session setup failed", 0))
640 pam_setcred(pamh
, (PAM_DELETE_CRED
|PAM_SILENT
)); /* We don't care if this fails */
641 pam_error
= pam_close_session(pamh
, PAM_SILENT
); /* This will probably pick up the error anyway */
642 if (!smb_pam_error_handler(pamh
, pam_error
, "session close failed", 0))
649 * Internal PAM Password Changer.
652 static BOOL
smb_pam_chauthtok(pam_handle_t
*pamh
, const char * user
)
656 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user
));
658 pam_error
= pam_chauthtok(pamh
, PAM_SILENT
); /* Change Password */
660 switch( pam_error
) {
661 case PAM_AUTHTOK_ERR
:
662 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
665 /* This doesn't seem to be defined on Solaris. JRA */
666 #ifdef PAM_AUTHTOK_RECOVER_ERR
667 case PAM_AUTHTOK_RECOVER_ERR
:
668 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
672 case PAM_AUTHTOK_LOCK_BUSY
:
673 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
675 case PAM_AUTHTOK_DISABLE_AGING
:
676 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
678 case PAM_PERM_DENIED
:
679 DEBUG(0, ("PAM: Permission denied.\n"));
682 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
684 case PAM_USER_UNKNOWN
:
685 DEBUG(0, ("PAM: User not known to PAM\n"));
688 DEBUG(4, ("PAM: Account OK for User: %s\n", user
));
691 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error
, user
));
694 if(!smb_pam_error_handler(pamh
, pam_error
, "Password Change Failed", 2)) {
698 /* If this point is reached, the password has changed. */
703 * PAM Externally accessible Session handler
706 BOOL
smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
708 pam_handle_t
*pamh
= NULL
;
709 struct pam_conv
*pconv
= NULL
;
711 /* Ignore PAM if told to. */
713 if (!lp_obey_pam_restrictions())
716 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
719 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
722 if (!smb_internal_pam_session(pamh
, user
, tty
, True
)) {
723 smb_pam_end(pamh
, pconv
);
727 return smb_pam_end(pamh
, pconv
);
731 * PAM Externally accessible Session handler
734 BOOL
smb_pam_close_session(char *user
, char *tty
, char *rhost
)
736 pam_handle_t
*pamh
= NULL
;
737 struct pam_conv
*pconv
= NULL
;
739 /* Ignore PAM if told to. */
741 if (!lp_obey_pam_restrictions())
744 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
747 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
750 if (!smb_internal_pam_session(pamh
, user
, tty
, False
)) {
751 smb_pam_end(pamh
, pconv
);
755 return smb_pam_end(pamh
, pconv
);
759 * PAM Externally accessible Account handler
762 NTSTATUS
smb_pam_accountcheck(const char * user
)
764 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
765 pam_handle_t
*pamh
= NULL
;
766 struct pam_conv
*pconv
= NULL
;
768 /* Ignore PAM if told to. */
770 if (!lp_obey_pam_restrictions())
773 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
774 return NT_STATUS_NO_MEMORY
;
776 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
777 return NT_STATUS_ACCOUNT_DISABLED
;
779 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
)))
780 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user
));
782 smb_pam_end(pamh
, pconv
);
787 * PAM Password Validation Suite
790 NTSTATUS
smb_pam_passcheck(const char * user
, const char * password
)
792 pam_handle_t
*pamh
= NULL
;
793 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
794 struct pam_conv
*pconv
= NULL
;
797 * Note we can't ignore PAM here as this is the only
798 * way of doing auths on plaintext passwords when
799 * compiled --with-pam.
802 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, password
, NULL
)) == NULL
)
803 return NT_STATUS_LOGON_FAILURE
;
805 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
806 return NT_STATUS_LOGON_FAILURE
;
808 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_auth(pamh
, user
))) {
809 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user
));
810 smb_pam_end(pamh
, pconv
);
814 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
))) {
815 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user
));
816 smb_pam_end(pamh
, pconv
);
820 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_setcred(pamh
, user
))) {
821 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user
));
822 smb_pam_end(pamh
, pconv
);
826 smb_pam_end(pamh
, pconv
);
831 * PAM Password Change Suite
834 BOOL
smb_pam_passchange(const char * user
, const char * oldpassword
, const char * newpassword
)
836 /* Appropriate quantities of root should be obtained BEFORE calling this function */
837 struct pam_conv
*pconv
= NULL
;
838 pam_handle_t
*pamh
= NULL
;
840 if ((pconv
= smb_setup_pam_conv(smb_pam_passchange_conv
, user
, oldpassword
, newpassword
)) == NULL
)
843 if(!smb_pam_start(&pamh
, user
, NULL
, pconv
))
846 if (!smb_pam_chauthtok(pamh
, user
)) {
847 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user
));
848 smb_pam_end(pamh
, pconv
);
852 return smb_pam_end(pamh
, pconv
);
857 /* If PAM not used, no PAM restrictions on accounts. */
858 NTSTATUS
smb_pam_accountcheck(const char * user
)
863 /* If PAM not used, also no PAM restrictions on sessions. */
864 BOOL
smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
869 /* If PAM not used, also no PAM restrictions on sessions. */
870 BOOL
smb_pam_close_session(char *in_user
, char *tty
, char *rhost
)
874 #endif /* WITH_PAM */