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
{
50 const char *PAM_username
;
51 const char *PAM_password
;
52 const 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
, const char *username
, const char *oldpass
, const 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 (unix_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 (unix_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
, const char *user
,
403 const char *passwd
, const 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
, const char *user
, const char *rhost
, struct pam_conv
*pconv
)
451 const char *our_rhost
;
453 *pamh
= (pam_handle_t
*)NULL
;
455 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user
));
457 pam_error
= pam_start("samba", user
, pconv
, pamh
);
458 if( !smb_pam_error_handler(*pamh
, pam_error
, "Init Failed", 0)) {
459 *pamh
= (pam_handle_t
*)NULL
;
464 our_rhost
= client_name();
465 if (strequal(rhost
,"UNKNOWN"))
466 our_rhost
= client_addr();
472 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost
));
473 pam_error
= pam_set_item(*pamh
, PAM_RHOST
, our_rhost
);
474 if(!smb_pam_error_handler(*pamh
, pam_error
, "set rhost failed", 0)) {
475 smb_pam_end(*pamh
, pconv
);
476 *pamh
= (pam_handle_t
*)NULL
;
481 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
482 pam_error
= pam_set_item(*pamh
, PAM_TTY
, "samba");
483 if (!smb_pam_error_handler(*pamh
, pam_error
, "set tty failed", 0)) {
484 smb_pam_end(*pamh
, pconv
);
485 *pamh
= (pam_handle_t
*)NULL
;
489 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user
));
494 * PAM Authentication Handler
496 static NTSTATUS
smb_pam_auth(pam_handle_t
*pamh
, char *user
)
499 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
502 * To enable debugging set in /etc/pam.d/samba:
503 * auth required /lib/security/pam_pwdb.so nullok shadow audit
506 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user
));
507 pam_error
= pam_authenticate(pamh
, PAM_SILENT
| lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK
);
510 DEBUG(2, ("smb_pam_auth: PAM: Athentication Error for user %s\n", user
));
511 nt_status
= NT_STATUS_WRONG_PASSWORD
;
513 case PAM_CRED_INSUFFICIENT
:
514 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user
));
515 nt_status
= NT_STATUS_INSUFFICIENT_LOGON_INFO
;
517 case PAM_AUTHINFO_UNAVAIL
:
518 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user
));
519 nt_status
= NT_STATUS_LOGON_FAILURE
;
521 case PAM_USER_UNKNOWN
:
522 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user
));
523 nt_status
= NT_STATUS_NO_SUCH_USER
;
526 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user
));
527 nt_status
= NT_STATUS_REMOTE_SESSION_LIMIT
;
530 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user
));
531 nt_status
= NT_STATUS_LOGON_FAILURE
;
534 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user
));
535 nt_status
= NT_STATUS_OK
;
538 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user
));
539 nt_status
= NT_STATUS_LOGON_FAILURE
;
543 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Authentication Failure", 2, &nt_status
);
548 * PAM Account Handler
550 static NTSTATUS
smb_pam_account(pam_handle_t
*pamh
, const char * user
)
553 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
555 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user
));
556 pam_error
= pam_acct_mgmt(pamh
, PAM_SILENT
); /* Is user account enabled? */
557 switch( pam_error
) {
558 case PAM_AUTHTOK_EXPIRED
:
559 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user
));
560 nt_status
= NT_STATUS_PASSWORD_EXPIRED
;
562 case PAM_ACCT_EXPIRED
:
563 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user
));
564 nt_status
= NT_STATUS_ACCOUNT_EXPIRED
;
567 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user
));
568 nt_status
= NT_STATUS_LOGON_FAILURE
;
570 case PAM_PERM_DENIED
:
571 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user
));
572 nt_status
= NT_STATUS_ACCOUNT_RESTRICTION
;
574 case PAM_USER_UNKNOWN
:
575 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user
));
576 nt_status
= NT_STATUS_NO_SUCH_USER
;
579 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user
));
580 nt_status
= NT_STATUS_OK
;
583 nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
584 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error
, user
));
588 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Account Check Failed", 2, &nt_status
);
593 * PAM Credential Setting
596 static NTSTATUS
smb_pam_setcred(pam_handle_t
*pamh
, char * user
)
599 NTSTATUS nt_status
= NT_STATUS_NO_TOKEN
;
602 * This will allow samba to aquire a kerberos token. And, when
603 * exporting an AFS cell, be able to /write/ to this cell.
606 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user
));
607 pam_error
= pam_setcred(pamh
, (PAM_ESTABLISH_CRED
|PAM_SILENT
));
608 switch( pam_error
) {
609 case PAM_CRED_UNAVAIL
:
610 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user
));
611 nt_status
= NT_STATUS_NO_TOKEN
;
613 case PAM_CRED_EXPIRED
:
614 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user
));
615 nt_status
= NT_STATUS_PASSWORD_EXPIRED
;
617 case PAM_USER_UNKNOWN
:
618 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user
));
619 nt_status
= NT_STATUS_NO_SUCH_USER
;
622 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user
));
623 nt_status
= NT_STATUS_LOGON_FAILURE
;
626 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user
));
627 nt_status
= NT_STATUS_OK
;
630 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error
, user
));
631 nt_status
= NT_STATUS_NO_TOKEN
;
635 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Set Credential Failure", 2, &nt_status
);
640 * PAM Internal Session Handler
642 static BOOL
smb_internal_pam_session(pam_handle_t
*pamh
, char *user
, char *tty
, BOOL flag
)
647 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty
));
648 pam_error
= pam_set_item(pamh
, PAM_TTY
, tty
);
649 if (!smb_pam_error_handler(pamh
, pam_error
, "set tty failed", 0))
654 pam_error
= pam_open_session(pamh
, PAM_SILENT
);
655 if (!smb_pam_error_handler(pamh
, pam_error
, "session setup failed", 0))
658 pam_setcred(pamh
, (PAM_DELETE_CRED
|PAM_SILENT
)); /* We don't care if this fails */
659 pam_error
= pam_close_session(pamh
, PAM_SILENT
); /* This will probably pick up the error anyway */
660 if (!smb_pam_error_handler(pamh
, pam_error
, "session close failed", 0))
667 * Internal PAM Password Changer.
670 static BOOL
smb_pam_chauthtok(pam_handle_t
*pamh
, const char * user
)
674 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user
));
676 pam_error
= pam_chauthtok(pamh
, PAM_SILENT
); /* Change Password */
678 switch( pam_error
) {
679 case PAM_AUTHTOK_ERR
:
680 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
683 /* This doesn't seem to be defined on Solaris. JRA */
684 #ifdef PAM_AUTHTOK_RECOVER_ERR
685 case PAM_AUTHTOK_RECOVER_ERR
:
686 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
690 case PAM_AUTHTOK_LOCK_BUSY
:
691 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
693 case PAM_AUTHTOK_DISABLE_AGING
:
694 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
696 case PAM_PERM_DENIED
:
697 DEBUG(0, ("PAM: Permission denied.\n"));
700 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
702 case PAM_USER_UNKNOWN
:
703 DEBUG(0, ("PAM: User not known to PAM\n"));
706 DEBUG(4, ("PAM: Account OK for User: %s\n", user
));
709 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error
, user
));
712 if(!smb_pam_error_handler(pamh
, pam_error
, "Password Change Failed", 2)) {
716 /* If this point is reached, the password has changed. */
721 * PAM Externally accessible Session handler
724 BOOL
smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
726 pam_handle_t
*pamh
= NULL
;
727 struct pam_conv
*pconv
= NULL
;
729 /* Ignore PAM if told to. */
731 if (!lp_obey_pam_restrictions())
734 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
737 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
740 if (!smb_internal_pam_session(pamh
, user
, tty
, True
)) {
741 smb_pam_end(pamh
, pconv
);
745 return smb_pam_end(pamh
, pconv
);
749 * PAM Externally accessible Session handler
752 BOOL
smb_pam_close_session(char *user
, char *tty
, char *rhost
)
754 pam_handle_t
*pamh
= NULL
;
755 struct pam_conv
*pconv
= NULL
;
757 /* Ignore PAM if told to. */
759 if (!lp_obey_pam_restrictions())
762 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
765 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
768 if (!smb_internal_pam_session(pamh
, user
, tty
, False
)) {
769 smb_pam_end(pamh
, pconv
);
773 return smb_pam_end(pamh
, pconv
);
777 * PAM Externally accessible Account handler
780 NTSTATUS
smb_pam_accountcheck(const char * user
)
782 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
783 pam_handle_t
*pamh
= NULL
;
784 struct pam_conv
*pconv
= NULL
;
786 /* Ignore PAM if told to. */
788 if (!lp_obey_pam_restrictions())
791 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
792 return NT_STATUS_NO_MEMORY
;
794 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
795 return NT_STATUS_ACCOUNT_DISABLED
;
797 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
)))
798 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user
));
800 smb_pam_end(pamh
, pconv
);
805 * PAM Password Validation Suite
808 NTSTATUS
smb_pam_passcheck(char * user
, char * password
)
810 pam_handle_t
*pamh
= NULL
;
811 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
812 struct pam_conv
*pconv
= NULL
;
815 * Note we can't ignore PAM here as this is the only
816 * way of doing auths on plaintext passwords when
817 * compiled --with-pam.
820 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, password
, NULL
)) == NULL
)
821 return NT_STATUS_LOGON_FAILURE
;
823 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
824 return NT_STATUS_LOGON_FAILURE
;
826 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_auth(pamh
, user
))) {
827 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user
));
828 smb_pam_end(pamh
, pconv
);
832 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
))) {
833 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user
));
834 smb_pam_end(pamh
, pconv
);
838 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_setcred(pamh
, user
))) {
839 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user
));
840 smb_pam_end(pamh
, pconv
);
844 smb_pam_end(pamh
, pconv
);
849 * PAM Password Change Suite
852 BOOL
smb_pam_passchange(const char * user
, const char * oldpassword
, const char * newpassword
)
854 /* Appropriate quantities of root should be obtained BEFORE calling this function */
855 struct pam_conv
*pconv
= NULL
;
856 pam_handle_t
*pamh
= NULL
;
858 if ((pconv
= smb_setup_pam_conv(smb_pam_passchange_conv
, user
, oldpassword
, newpassword
)) == NULL
)
861 if(!smb_pam_start(&pamh
, user
, NULL
, pconv
))
864 if (!smb_pam_chauthtok(pamh
, user
)) {
865 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user
));
866 smb_pam_end(pamh
, pconv
);
870 return smb_pam_end(pamh
, pconv
);
875 /* If PAM not used, no PAM restrictions on accounts. */
876 NTSTATUS
smb_pam_accountcheck(const char * user
)
881 /* If PAM not used, also no PAM restrictions on sessions. */
882 BOOL
smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
887 /* If PAM not used, also no PAM restrictions on sessions. */
888 BOOL
smb_pam_close_session(char *in_user
, char *tty
, char *rhost
)
892 #endif /* WITH_PAM */