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
32 #define DBGC_CLASS DBGC_AUTH
36 /*******************************************************************
37 * Handle PAM authentication
38 * - Access, Authentication, Session, Password
39 * Note: See PAM Documentation and refer to local system PAM implementation
40 * which determines what actions/limitations/allowances become affected.
41 *********************************************************************/
43 #if defined(HAVE_SECURITY_PAM_APPL_H)
44 #include <security/pam_appl.h>
45 #elif defined(HAVE_PAM_PAM_APPL_H)
46 #include <pam/pam_appl.h>
50 * Structure used to communicate between the conversation function
51 * and the server_login/change password functions.
54 struct smb_pam_userdata
{
55 const char *PAM_username
;
56 const char *PAM_password
;
57 const char *PAM_newpassword
;
60 typedef int (*smb_pam_conv_fn
)(int, const struct pam_message
**, struct pam_response
**, void *appdata_ptr
);
63 * Macros to help make life easy
65 #define COPY_STRING(s) (s) ? SMB_STRDUP(s) : NULL
66 #define COPY_FSTRING(s) (s[0]) ? SMB_STRDUP(s) : NULL
68 /*******************************************************************
70 *********************************************************************/
72 static bool smb_pam_error_handler(pam_handle_t
*pamh
, int pam_error
, const char *msg
, int dbglvl
)
75 if( pam_error
!= PAM_SUCCESS
) {
76 DEBUG(dbglvl
, ("smb_pam_error_handler: PAM: %s : %s\n",
77 msg
, pam_strerror(pamh
, pam_error
)));
84 /*******************************************************************
85 This function is a sanity check, to make sure that we NEVER report
87 *********************************************************************/
89 static bool smb_pam_nt_status_error_handler(pam_handle_t
*pamh
, int pam_error
,
90 const char *msg
, int dbglvl
,
93 *nt_status
= pam_to_nt_status(pam_error
);
95 if (smb_pam_error_handler(pamh
, pam_error
, msg
, dbglvl
))
98 if (NT_STATUS_IS_OK(*nt_status
)) {
100 DEBUG(0, ("smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
101 error MISMATCH, forcing to NT_STATUS_LOGON_FAILURE"));
102 *nt_status
= NT_STATUS_LOGON_FAILURE
;
108 * PAM conversation function
109 * Here we assume (for now, at least) that echo on means login name, and
110 * echo off means password.
113 static int smb_pam_conv(int num_msg
,
114 const struct pam_message
**msg
,
115 struct pam_response
**resp
,
119 struct pam_response
*reply
= NULL
;
120 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
128 * Apparantly HPUX has a buggy PAM that doesn't support the
129 * appdata_ptr. Fail if this is the case. JRA.
133 DEBUG(0,("smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
137 reply
= SMB_MALLOC_ARRAY(struct pam_response
, num_msg
);
141 memset(reply
, '\0', sizeof(struct pam_response
) * num_msg
);
143 for (replies
= 0; replies
< num_msg
; replies
++) {
144 switch (msg
[replies
]->msg_style
) {
145 case PAM_PROMPT_ECHO_ON
:
146 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
147 reply
[replies
].resp
= COPY_STRING(udp
->PAM_username
);
151 case PAM_PROMPT_ECHO_OFF
:
152 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
153 reply
[replies
].resp
= COPY_STRING(udp
->PAM_password
);
162 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
163 reply
[replies
].resp
= NULL
;
167 /* Must be an error of some sort... */
178 * PAM password change conversation function
179 * Here we assume (for now, at least) that echo on means login name, and
180 * echo off means password.
183 static void special_char_sub(char *buf
)
185 all_string_sub(buf
, "\\n", "", 0);
186 all_string_sub(buf
, "\\r", "", 0);
187 all_string_sub(buf
, "\\s", " ", 0);
188 all_string_sub(buf
, "\\t", "\t", 0);
191 static void pwd_sub(char *buf
, const char *username
, const char *oldpass
, const char *newpass
)
193 fstring_sub(buf
, "%u", username
);
194 all_string_sub(buf
, "%o", oldpass
, sizeof(fstring
));
195 all_string_sub(buf
, "%n", newpass
, sizeof(fstring
));
200 struct chat_struct
*next
, *prev
;
205 /**************************************************************
206 Create a linked list containing chat data.
207 ***************************************************************/
209 static struct chat_struct
*make_pw_chat(const char *p
)
213 struct chat_struct
*list
= NULL
;
214 struct chat_struct
*t
;
215 TALLOC_CTX
*frame
= talloc_stackframe();
218 t
= SMB_MALLOC_P(struct chat_struct
);
220 DEBUG(0,("make_pw_chat: malloc failed!\n"));
227 DLIST_ADD_END(list
, t
, struct chat_struct
*);
229 if (!next_token_talloc(frame
, &p
, &prompt
, NULL
)) {
233 if (strequal(prompt
,".")) {
237 special_char_sub(prompt
);
238 fstrcpy(t
->prompt
, prompt
);
239 strlower_m(t
->prompt
);
240 trim_char(t
->prompt
, ' ', ' ');
242 if (!next_token_talloc(frame
, &p
, &reply
, NULL
)) {
246 if (strequal(reply
,".")) {
250 special_char_sub(reply
);
251 fstrcpy(t
->reply
, reply
);
252 strlower_m(t
->reply
);
253 trim_char(t
->reply
, ' ', ' ');
260 static void free_pw_chat(struct chat_struct
*list
)
263 struct chat_struct
*old_head
= list
;
264 DLIST_REMOVE(list
, list
);
269 static int smb_pam_passchange_conv(int num_msg
,
270 const struct pam_message
**msg
,
271 struct pam_response
**resp
,
275 struct pam_response
*reply
= NULL
;
276 fstring current_prompt
;
277 fstring current_reply
;
278 struct smb_pam_userdata
*udp
= (struct smb_pam_userdata
*)appdata_ptr
;
279 struct chat_struct
*pw_chat
;
280 struct chat_struct
*t
;
284 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg
));
289 if ((pw_chat
= make_pw_chat(lp_passwd_chat())) == NULL
)
293 * Apparantly HPUX has a buggy PAM that doesn't support the
294 * appdata_ptr. Fail if this is the case. JRA.
298 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
299 free_pw_chat(pw_chat
);
303 reply
= SMB_MALLOC_ARRAY(struct pam_response
, num_msg
);
305 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
306 free_pw_chat(pw_chat
);
310 for (replies
= 0; replies
< num_msg
; replies
++) {
312 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies
));
313 switch (msg
[replies
]->msg_style
) {
314 case PAM_PROMPT_ECHO_ON
:
315 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg
[replies
]->msg
));
316 fstrcpy(current_prompt
, msg
[replies
]->msg
);
317 trim_char(current_prompt
, ' ', ' ');
318 for (t
=pw_chat
; t
; t
=t
->next
) {
320 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
321 t
->prompt
, current_prompt
));
323 if (unix_wild_match(t
->prompt
, current_prompt
)) {
324 fstrcpy(current_reply
, t
->reply
);
325 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply
));
326 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
327 #ifdef DEBUG_PASSWORD
328 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply
));
330 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
331 reply
[replies
].resp
= COPY_FSTRING(current_reply
);
338 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
339 free_pw_chat(pw_chat
);
345 case PAM_PROMPT_ECHO_OFF
:
346 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg
[replies
]->msg
));
347 fstrcpy(current_prompt
, msg
[replies
]->msg
);
348 trim_char(current_prompt
, ' ', ' ');
349 for (t
=pw_chat
; t
; t
=t
->next
) {
351 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
352 t
->prompt
, current_prompt
));
354 if (unix_wild_match(t
->prompt
, current_prompt
)) {
355 fstrcpy(current_reply
, t
->reply
);
356 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply
));
357 pwd_sub(current_reply
, udp
->PAM_username
, udp
->PAM_password
, udp
->PAM_newpassword
);
358 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
359 reply
[replies
].resp
= COPY_FSTRING(current_reply
);
360 #ifdef DEBUG_PASSWORD
361 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply
));
370 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg
[replies
]->msg
));
371 free_pw_chat(pw_chat
);
382 reply
[replies
].resp_retcode
= PAM_SUCCESS
;
383 reply
[replies
].resp
= NULL
;
387 /* Must be an error of some sort... */
388 free_pw_chat(pw_chat
);
394 free_pw_chat(pw_chat
);
400 /***************************************************************************
401 Free up a malloced pam_conv struct.
402 ****************************************************************************/
404 static void smb_free_pam_conv(struct pam_conv
*pconv
)
407 SAFE_FREE(pconv
->appdata_ptr
);
412 /***************************************************************************
413 Allocate a pam_conv struct.
414 ****************************************************************************/
416 static struct pam_conv
*smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr
, const char *user
,
417 const char *passwd
, const char *newpass
)
419 struct pam_conv
*pconv
= SMB_MALLOC_P(struct pam_conv
);
420 struct smb_pam_userdata
*udp
= SMB_MALLOC_P(struct smb_pam_userdata
);
422 if (pconv
== NULL
|| udp
== NULL
) {
428 udp
->PAM_username
= user
;
429 udp
->PAM_password
= passwd
;
430 udp
->PAM_newpassword
= newpass
;
432 pconv
->conv
= smb_pam_conv_fnptr
;
433 pconv
->appdata_ptr
= (void *)udp
;
438 * PAM Closing out cleanup handler
441 static bool smb_pam_end(pam_handle_t
*pamh
, struct pam_conv
*smb_pam_conv_ptr
)
445 smb_free_pam_conv(smb_pam_conv_ptr
);
448 pam_error
= pam_end(pamh
, 0);
449 if(smb_pam_error_handler(pamh
, pam_error
, "End Cleanup Failed", 2) == True
) {
450 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
454 DEBUG(2,("smb_pam_end: PAM: not initialised"));
459 * Start PAM authentication for specified account
462 static bool smb_pam_start(pam_handle_t
**pamh
, const char *user
, const char *rhost
, struct pam_conv
*pconv
)
466 const char *our_rhost
;
467 char addr
[INET6_ADDRSTRLEN
];
470 *pamh
= (pam_handle_t
*)NULL
;
472 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user
));
474 pam_error
= pam_start("samba", user
, pconv
, pamh
);
475 if( !smb_pam_error_handler(*pamh
, pam_error
, "Init Failed", 0)) {
476 *pamh
= (pam_handle_t
*)NULL
;
482 our_rhost
= client_name(get_client_fd());
483 if (strequal(our_rhost
,"UNKNOWN"))
484 our_rhost
= client_addr(get_client_fd(),addr
,sizeof(addr
));
489 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost
));
490 pam_error
= pam_set_item(*pamh
, PAM_RHOST
, our_rhost
);
491 if(!smb_pam_error_handler(*pamh
, pam_error
, "set rhost failed", 0)) {
492 smb_pam_end(*pamh
, pconv
);
493 *pamh
= (pam_handle_t
*)NULL
;
498 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
499 pam_error
= pam_set_item(*pamh
, PAM_TTY
, "samba");
500 if (!smb_pam_error_handler(*pamh
, pam_error
, "set tty failed", 0)) {
501 smb_pam_end(*pamh
, pconv
);
502 *pamh
= (pam_handle_t
*)NULL
;
506 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user
));
511 * PAM Authentication Handler
513 static NTSTATUS
smb_pam_auth(pam_handle_t
*pamh
, const char *user
)
516 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
519 * To enable debugging set in /etc/pam.d/samba:
520 * auth required /lib/security/pam_pwdb.so nullok shadow audit
523 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user
));
524 pam_error
= pam_authenticate(pamh
, PAM_SILENT
| lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK
);
527 DEBUG(2, ("smb_pam_auth: PAM: Authentication Error for user %s\n", user
));
529 case PAM_CRED_INSUFFICIENT
:
530 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user
));
532 case PAM_AUTHINFO_UNAVAIL
:
533 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user
));
535 case PAM_USER_UNKNOWN
:
536 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user
));
539 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user
));
542 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user
));
545 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user
));
548 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user
));
552 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Authentication Failure", 2, &nt_status
);
557 * PAM Account Handler
559 static NTSTATUS
smb_pam_account(pam_handle_t
*pamh
, const char * user
)
562 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
564 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user
));
565 pam_error
= pam_acct_mgmt(pamh
, PAM_SILENT
); /* Is user account enabled? */
566 switch( pam_error
) {
567 case PAM_AUTHTOK_EXPIRED
:
568 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user
));
570 case PAM_ACCT_EXPIRED
:
571 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user
));
574 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user
));
576 case PAM_PERM_DENIED
:
577 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user
));
579 case PAM_USER_UNKNOWN
:
580 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user
));
583 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user
));
586 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error
, user
));
590 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Account Check Failed", 2, &nt_status
);
595 * PAM Credential Setting
598 static NTSTATUS
smb_pam_setcred(pam_handle_t
*pamh
, const char * user
)
601 NTSTATUS nt_status
= NT_STATUS_NO_TOKEN
;
604 * This will allow samba to aquire a kerberos token. And, when
605 * exporting an AFS cell, be able to /write/ to this cell.
608 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user
));
609 pam_error
= pam_setcred(pamh
, (PAM_ESTABLISH_CRED
|PAM_SILENT
));
610 switch( pam_error
) {
611 case PAM_CRED_UNAVAIL
:
612 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user
));
614 case PAM_CRED_EXPIRED
:
615 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user
));
617 case PAM_USER_UNKNOWN
:
618 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user
));
621 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user
));
624 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user
));
627 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error
, user
));
631 smb_pam_nt_status_error_handler(pamh
, pam_error
, "Set Credential Failure", 2, &nt_status
);
636 * PAM Internal Session Handler
638 static bool smb_internal_pam_session(pam_handle_t
*pamh
, const char *user
, const char *tty
, bool flag
)
643 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty
));
644 pam_error
= pam_set_item(pamh
, PAM_TTY
, tty
);
645 if (!smb_pam_error_handler(pamh
, pam_error
, "set tty failed", 0))
650 pam_error
= pam_open_session(pamh
, PAM_SILENT
);
651 if (!smb_pam_error_handler(pamh
, pam_error
, "session setup failed", 0))
654 pam_setcred(pamh
, (PAM_DELETE_CRED
|PAM_SILENT
)); /* We don't care if this fails */
655 pam_error
= pam_close_session(pamh
, PAM_SILENT
); /* This will probably pick up the error anyway */
656 if (!smb_pam_error_handler(pamh
, pam_error
, "session close failed", 0))
663 * Internal PAM Password Changer.
666 static bool smb_pam_chauthtok(pam_handle_t
*pamh
, const char * user
)
670 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user
));
672 pam_error
= pam_chauthtok(pamh
, PAM_SILENT
); /* Change Password */
674 switch( pam_error
) {
675 case PAM_AUTHTOK_ERR
:
676 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
679 /* This doesn't seem to be defined on Solaris. JRA */
680 #ifdef PAM_AUTHTOK_RECOVER_ERR
681 case PAM_AUTHTOK_RECOVER_ERR
:
682 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
686 case PAM_AUTHTOK_LOCK_BUSY
:
687 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
689 case PAM_AUTHTOK_DISABLE_AGING
:
690 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
692 case PAM_PERM_DENIED
:
693 DEBUG(0, ("PAM: Permission denied.\n"));
696 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
698 case PAM_USER_UNKNOWN
:
699 DEBUG(0, ("PAM: User not known to PAM\n"));
702 DEBUG(4, ("PAM: Account OK for User: %s\n", user
));
705 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error
, user
));
708 if(!smb_pam_error_handler(pamh
, pam_error
, "Password Change Failed", 2)) {
712 /* If this point is reached, the password has changed. */
717 * PAM Externally accessible Session handler
720 bool smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
722 pam_handle_t
*pamh
= NULL
;
723 struct pam_conv
*pconv
= NULL
;
725 /* Ignore PAM if told to. */
727 if (!lp_obey_pam_restrictions())
730 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
733 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
736 if (!smb_internal_pam_session(pamh
, user
, tty
, True
)) {
737 smb_pam_end(pamh
, pconv
);
741 return smb_pam_end(pamh
, pconv
);
745 * PAM Externally accessible Session handler
748 bool smb_pam_close_session(char *user
, char *tty
, char *rhost
)
750 pam_handle_t
*pamh
= NULL
;
751 struct pam_conv
*pconv
= NULL
;
753 /* Ignore PAM if told to. */
755 if (!lp_obey_pam_restrictions())
758 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
761 if (!smb_pam_start(&pamh
, user
, rhost
, pconv
))
764 if (!smb_internal_pam_session(pamh
, user
, tty
, False
)) {
765 smb_pam_end(pamh
, pconv
);
769 return smb_pam_end(pamh
, pconv
);
773 * PAM Externally accessible Account handler
776 NTSTATUS
smb_pam_accountcheck(const char * user
)
778 NTSTATUS nt_status
= NT_STATUS_ACCOUNT_DISABLED
;
779 pam_handle_t
*pamh
= NULL
;
780 struct pam_conv
*pconv
= NULL
;
782 /* Ignore PAM if told to. */
784 if (!lp_obey_pam_restrictions())
787 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, NULL
, NULL
)) == NULL
)
788 return NT_STATUS_NO_MEMORY
;
790 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
791 return NT_STATUS_ACCOUNT_DISABLED
;
793 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
)))
794 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user
));
796 smb_pam_end(pamh
, pconv
);
801 * PAM Password Validation Suite
804 NTSTATUS
smb_pam_passcheck(const char * user
, const char * password
)
806 pam_handle_t
*pamh
= NULL
;
807 NTSTATUS nt_status
= NT_STATUS_LOGON_FAILURE
;
808 struct pam_conv
*pconv
= NULL
;
811 * Note we can't ignore PAM here as this is the only
812 * way of doing auths on plaintext passwords when
813 * compiled --with-pam.
816 if ((pconv
= smb_setup_pam_conv(smb_pam_conv
, user
, password
, NULL
)) == NULL
)
817 return NT_STATUS_LOGON_FAILURE
;
819 if (!smb_pam_start(&pamh
, user
, NULL
, pconv
))
820 return NT_STATUS_LOGON_FAILURE
;
822 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_auth(pamh
, user
))) {
823 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user
));
824 smb_pam_end(pamh
, pconv
);
828 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_account(pamh
, user
))) {
829 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user
));
830 smb_pam_end(pamh
, pconv
);
834 if (!NT_STATUS_IS_OK(nt_status
= smb_pam_setcred(pamh
, user
))) {
835 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user
));
836 smb_pam_end(pamh
, pconv
);
840 smb_pam_end(pamh
, pconv
);
845 * PAM Password Change Suite
848 bool smb_pam_passchange(const char * user
, const char * oldpassword
, const char * newpassword
)
850 /* Appropriate quantities of root should be obtained BEFORE calling this function */
851 struct pam_conv
*pconv
= NULL
;
852 pam_handle_t
*pamh
= NULL
;
854 if ((pconv
= smb_setup_pam_conv(smb_pam_passchange_conv
, user
, oldpassword
, newpassword
)) == NULL
)
857 if(!smb_pam_start(&pamh
, user
, NULL
, pconv
))
860 if (!smb_pam_chauthtok(pamh
, user
)) {
861 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user
));
862 smb_pam_end(pamh
, pconv
);
866 return smb_pam_end(pamh
, pconv
);
871 /* If PAM not used, no PAM restrictions on accounts. */
872 NTSTATUS
smb_pam_accountcheck(const char * user
)
877 /* If PAM not used, also no PAM restrictions on sessions. */
878 bool smb_pam_claim_session(char *user
, char *tty
, char *rhost
)
883 /* If PAM not used, also no PAM restrictions on sessions. */
884 bool smb_pam_close_session(char *in_user
, char *tty
, char *rhost
)
888 #endif /* WITH_PAM */