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
34 /*******************************************************************
35 * Handle PAM authentication
36 * - Access, Authentication, Session, Password
37 * Note: See PAM Documentation and refer to local system PAM implementation
38 * which determines what actions/limitations/allowances become affected.
39 *********************************************************************/
41 #include <security/pam_appl.h>
44 * Structure used to communicate between the conversation function
45 * and the server_login/change password functions.
48 struct smb_pam_userdata {
49 const char *PAM_username;
50 const char *PAM_password;
51 const char *PAM_newpassword;
54 typedef int (*smb_pam_conv_fn)(int, const struct pam_message **, struct pam_response **, void *appdata_ptr);
57 * Macros to help make life easy
59 #define COPY_STRING(s) (s) ? strdup(s) : NULL
61 /*******************************************************************
63 *********************************************************************/
65 static BOOL smb_pam_error_handler(pam_handle_t *pamh, int pam_error, char *msg, int dbglvl)
68 if( pam_error != PAM_SUCCESS) {
69 DEBUG(dbglvl, ("smb_pam_error_handler: PAM: %s : %s\n",
70 msg, pam_strerror(pamh, pam_error)));
77 /*******************************************************************
78 This function is a sanity check, to make sure that we NEVER report
80 *********************************************************************/
82 static BOOL smb_pam_nt_status_error_handler(pam_handle_t *pamh, int pam_error,
83 char *msg, int dbglvl,
86 if (smb_pam_error_handler(pamh, pam_error, msg, dbglvl))
89 if (NT_STATUS_IS_OK(*nt_status)) {
91 DEBUG(0, ("smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
92 error MISMATCH, forcing to NT_STATUS_LOGON_FAILURE"));
93 *nt_status = NT_STATUS_LOGON_FAILURE;
99 * PAM conversation function
100 * Here we assume (for now, at least) that echo on means login name, and
101 * echo off means password.
104 static int smb_pam_conv(int num_msg,
105 const struct pam_message **msg,
106 struct pam_response **resp,
110 struct pam_response *reply = NULL;
111 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
119 * Apparantly HPUX has a buggy PAM that doesn't support the
120 * appdata_ptr. Fail if this is the case. JRA.
124 DEBUG(0,("smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
128 reply = malloc(sizeof(struct pam_response) * num_msg);
132 memset(reply, '\0', sizeof(struct pam_response) * num_msg);
134 for (replies = 0; replies < num_msg; replies++) {
135 switch (msg[replies]->msg_style) {
136 case PAM_PROMPT_ECHO_ON:
137 reply[replies].resp_retcode = PAM_SUCCESS;
138 reply[replies].resp = COPY_STRING(udp->PAM_username);
142 case PAM_PROMPT_ECHO_OFF:
143 reply[replies].resp_retcode = PAM_SUCCESS;
144 reply[replies].resp = COPY_STRING(udp->PAM_password);
153 reply[replies].resp_retcode = PAM_SUCCESS;
154 reply[replies].resp = NULL;
158 /* Must be an error of some sort... */
169 * PAM password change conversation function
170 * Here we assume (for now, at least) that echo on means login name, and
171 * echo off means password.
174 static void special_char_sub(char *buf)
176 all_string_sub(buf, "\\n", "", 0);
177 all_string_sub(buf, "\\r", "", 0);
178 all_string_sub(buf, "\\s", " ", 0);
179 all_string_sub(buf, "\\t", "\t", 0);
182 static void pwd_sub(char *buf, const char *username, const char *oldpass, const char *newpass)
184 pstring_sub(buf, "%u", username);
185 all_string_sub(buf, "%o", oldpass, sizeof(fstring));
186 all_string_sub(buf, "%n", newpass, sizeof(fstring));
191 struct chat_struct *next, *prev;
196 /**************************************************************
197 Create a linked list containing chat data.
198 ***************************************************************/
200 static struct chat_struct *make_pw_chat(char *p)
204 struct chat_struct *list = NULL;
205 struct chat_struct *t;
206 struct chat_struct *tmp;
209 t = (struct chat_struct *)malloc(sizeof(*t));
211 DEBUG(0,("make_pw_chat: malloc failed!\n"));
217 DLIST_ADD_END(list, t, tmp);
219 if (!next_token(&p, prompt, NULL, sizeof(fstring)))
222 if (strequal(prompt,"."))
225 special_char_sub(prompt);
226 fstrcpy(t->prompt, prompt);
228 trim_string(t->prompt, " ", " ");
230 if (!next_token(&p, reply, NULL, sizeof(fstring)))
233 if (strequal(reply,"."))
236 special_char_sub(reply);
237 fstrcpy(t->reply, reply);
239 trim_string(t->reply, " ", " ");
245 static void free_pw_chat(struct chat_struct *list)
248 struct chat_struct *old_head = list;
249 DLIST_REMOVE(list, list);
254 static int smb_pam_passchange_conv(int num_msg,
255 const struct pam_message **msg,
256 struct pam_response **resp,
260 struct pam_response *reply = NULL;
261 fstring current_prompt;
262 fstring current_reply;
263 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
264 struct chat_struct *pw_chat= make_pw_chat(lp_passwd_chat());
265 struct chat_struct *t;
269 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg));
278 * Apparantly HPUX has a buggy PAM that doesn't support the
279 * appdata_ptr. Fail if this is the case. JRA.
283 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
284 free_pw_chat(pw_chat);
288 reply = malloc(sizeof(struct pam_response) * num_msg);
290 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
291 free_pw_chat(pw_chat);
295 for (replies = 0; replies < num_msg; replies++) {
297 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies));
298 switch (msg[replies]->msg_style) {
299 case PAM_PROMPT_ECHO_ON:
300 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg[replies]->msg));
301 fstrcpy(current_prompt, msg[replies]->msg);
302 trim_string(current_prompt, " ", " ");
303 for (t=pw_chat; t; t=t->next) {
305 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
306 t->prompt, current_prompt ));
308 if (unix_wild_match(t->prompt, current_prompt) == 0) {
309 fstrcpy(current_reply, t->reply);
310 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply));
311 pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
312 #ifdef DEBUG_PASSWORD
313 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply));
315 reply[replies].resp_retcode = PAM_SUCCESS;
316 reply[replies].resp = COPY_STRING(current_reply);
323 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
324 free_pw_chat(pw_chat);
330 case PAM_PROMPT_ECHO_OFF:
331 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg[replies]->msg));
332 fstrcpy(current_prompt, msg[replies]->msg);
333 trim_string(current_prompt, " ", " ");
334 for (t=pw_chat; t; t=t->next) {
336 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
337 t->prompt, current_prompt ));
339 if (unix_wild_match(t->prompt, current_prompt) == 0) {
340 fstrcpy(current_reply, t->reply);
341 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply));
342 pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
343 reply[replies].resp_retcode = PAM_SUCCESS;
344 reply[replies].resp = COPY_STRING(current_reply);
345 #ifdef DEBUG_PASSWORD
346 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply));
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);
367 reply[replies].resp_retcode = PAM_SUCCESS;
368 reply[replies].resp = NULL;
372 /* Must be an error of some sort... */
373 free_pw_chat(pw_chat);
379 free_pw_chat(pw_chat);
385 /***************************************************************************
386 Free up a malloced pam_conv struct.
387 ****************************************************************************/
389 static void smb_free_pam_conv(struct pam_conv *pconv)
392 SAFE_FREE(pconv->appdata_ptr);
397 /***************************************************************************
398 Allocate a pam_conv struct.
399 ****************************************************************************/
401 static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user,
402 const char *passwd, const char *newpass)
404 struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv));
405 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata));
407 if (pconv == NULL || udp == NULL) {
413 udp->PAM_username = user;
414 udp->PAM_password = passwd;
415 udp->PAM_newpassword = newpass;
417 pconv->conv = smb_pam_conv_fnptr;
418 pconv->appdata_ptr = (void *)udp;
423 * PAM Closing out cleanup handler
426 static BOOL smb_pam_end(pam_handle_t *pamh, struct pam_conv *smb_pam_conv_ptr)
430 smb_free_pam_conv(smb_pam_conv_ptr);
433 pam_error = pam_end(pamh, 0);
434 if(smb_pam_error_handler(pamh, pam_error, "End Cleanup Failed", 2) == True) {
435 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
439 DEBUG(2,("smb_pam_end: PAM: not initialised"));
444 * Start PAM authentication for specified account
447 static BOOL smb_pam_start(pam_handle_t **pamh, const char *user, const char *rhost, struct pam_conv *pconv)
450 const char *our_rhost;
452 *pamh = (pam_handle_t *)NULL;
454 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user));
456 pam_error = pam_start("samba", user, pconv, pamh);
457 if( !smb_pam_error_handler(*pamh, pam_error, "Init Failed", 0)) {
458 *pamh = (pam_handle_t *)NULL;
463 our_rhost = client_name();
464 if (strequal(rhost,"UNKNOWN"))
465 our_rhost = client_addr();
471 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost));
472 pam_error = pam_set_item(*pamh, PAM_RHOST, our_rhost);
473 if(!smb_pam_error_handler(*pamh, pam_error, "set rhost failed", 0)) {
474 smb_pam_end(*pamh, pconv);
475 *pamh = (pam_handle_t *)NULL;
480 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
481 pam_error = pam_set_item(*pamh, PAM_TTY, "samba");
482 if (!smb_pam_error_handler(*pamh, pam_error, "set tty failed", 0)) {
483 smb_pam_end(*pamh, pconv);
484 *pamh = (pam_handle_t *)NULL;
488 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user));
493 * PAM Authentication Handler
495 static NTSTATUS smb_pam_auth(pam_handle_t *pamh, char *user)
498 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
501 * To enable debugging set in /etc/pam.d/samba:
502 * auth required /lib/security/pam_pwdb.so nullok shadow audit
505 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user));
506 pam_error = pam_authenticate(pamh, PAM_SILENT | lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK);
509 DEBUG(2, ("smb_pam_auth: PAM: Athentication Error for user %s\n", user));
510 nt_status = NT_STATUS_WRONG_PASSWORD;
512 case PAM_CRED_INSUFFICIENT:
513 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user));
514 nt_status = NT_STATUS_INSUFFICIENT_LOGON_INFO;
516 case PAM_AUTHINFO_UNAVAIL:
517 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user));
518 nt_status = NT_STATUS_LOGON_FAILURE;
520 case PAM_USER_UNKNOWN:
521 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user));
522 nt_status = NT_STATUS_NO_SUCH_USER;
525 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user));
526 nt_status = NT_STATUS_REMOTE_SESSION_LIMIT;
529 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user));
530 nt_status = NT_STATUS_LOGON_FAILURE;
533 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user));
534 nt_status = NT_STATUS_OK;
537 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user));
538 nt_status = NT_STATUS_LOGON_FAILURE;
542 smb_pam_nt_status_error_handler(pamh, pam_error, "Authentication Failure", 2, &nt_status);
547 * PAM Account Handler
549 static NTSTATUS smb_pam_account(pam_handle_t *pamh, const char * user)
552 NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
554 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user));
555 pam_error = pam_acct_mgmt(pamh, PAM_SILENT); /* Is user account enabled? */
556 switch( pam_error ) {
557 case PAM_AUTHTOK_EXPIRED:
558 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user));
559 nt_status = NT_STATUS_PASSWORD_EXPIRED;
561 case PAM_ACCT_EXPIRED:
562 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user));
563 nt_status = NT_STATUS_ACCOUNT_EXPIRED;
566 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user));
567 nt_status = NT_STATUS_LOGON_FAILURE;
569 case PAM_PERM_DENIED:
570 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user));
571 nt_status = NT_STATUS_ACCOUNT_RESTRICTION;
573 case PAM_USER_UNKNOWN:
574 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user));
575 nt_status = NT_STATUS_NO_SUCH_USER;
578 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user));
579 nt_status = NT_STATUS_OK;
582 nt_status = NT_STATUS_ACCOUNT_DISABLED;
583 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error, user));
587 smb_pam_nt_status_error_handler(pamh, pam_error, "Account Check Failed", 2, &nt_status);
592 * PAM Credential Setting
595 static NTSTATUS smb_pam_setcred(pam_handle_t *pamh, char * user)
598 NTSTATUS nt_status = NT_STATUS_NO_TOKEN;
601 * This will allow samba to aquire a kerberos token. And, when
602 * exporting an AFS cell, be able to /write/ to this cell.
605 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user));
606 pam_error = pam_setcred(pamh, (PAM_ESTABLISH_CRED|PAM_SILENT));
607 switch( pam_error ) {
608 case PAM_CRED_UNAVAIL:
609 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user ));
610 nt_status = NT_STATUS_NO_TOKEN;
612 case PAM_CRED_EXPIRED:
613 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user ));
614 nt_status = NT_STATUS_PASSWORD_EXPIRED;
616 case PAM_USER_UNKNOWN:
617 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user ));
618 nt_status = NT_STATUS_NO_SUCH_USER;
621 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user ));
622 nt_status = NT_STATUS_LOGON_FAILURE;
625 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user));
626 nt_status = NT_STATUS_OK;
629 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error, user));
630 nt_status = NT_STATUS_NO_TOKEN;
634 smb_pam_nt_status_error_handler(pamh, pam_error, "Set Credential Failure", 2, &nt_status);
639 * PAM Internal Session Handler
641 static BOOL smb_internal_pam_session(pam_handle_t *pamh, char *user, char *tty, BOOL flag)
646 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty));
647 pam_error = pam_set_item(pamh, PAM_TTY, tty);
648 if (!smb_pam_error_handler(pamh, pam_error, "set tty failed", 0))
653 pam_error = pam_open_session(pamh, PAM_SILENT);
654 if (!smb_pam_error_handler(pamh, pam_error, "session setup failed", 0))
657 pam_setcred(pamh, (PAM_DELETE_CRED|PAM_SILENT)); /* We don't care if this fails */
658 pam_error = pam_close_session(pamh, PAM_SILENT); /* This will probably pick up the error anyway */
659 if (!smb_pam_error_handler(pamh, pam_error, "session close failed", 0))
666 * Internal PAM Password Changer.
669 static BOOL smb_pam_chauthtok(pam_handle_t *pamh, const char * user)
673 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user));
675 pam_error = pam_chauthtok(pamh, PAM_SILENT); /* Change Password */
677 switch( pam_error ) {
678 case PAM_AUTHTOK_ERR:
679 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
682 /* This doesn't seem to be defined on Solaris. JRA */
683 #ifdef PAM_AUTHTOK_RECOVER_ERR
684 case PAM_AUTHTOK_RECOVER_ERR:
685 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
689 case PAM_AUTHTOK_LOCK_BUSY:
690 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
692 case PAM_AUTHTOK_DISABLE_AGING:
693 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
695 case PAM_PERM_DENIED:
696 DEBUG(0, ("PAM: Permission denied.\n"));
699 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
701 case PAM_USER_UNKNOWN:
702 DEBUG(0, ("PAM: User not known to PAM\n"));
705 DEBUG(4, ("PAM: Account OK for User: %s\n", user));
708 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error, user));
711 if(!smb_pam_error_handler(pamh, pam_error, "Password Change Failed", 2)) {
715 /* If this point is reached, the password has changed. */
720 * PAM Externally accessible Session handler
723 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
725 pam_handle_t *pamh = NULL;
726 struct pam_conv *pconv = NULL;
728 /* Ignore PAM if told to. */
730 if (!lp_obey_pam_restrictions())
733 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
736 if (!smb_pam_start(&pamh, user, rhost, pconv))
739 if (!smb_internal_pam_session(pamh, user, tty, True)) {
740 smb_pam_end(pamh, pconv);
744 return smb_pam_end(pamh, pconv);
748 * PAM Externally accessible Session handler
751 BOOL smb_pam_close_session(char *user, char *tty, char *rhost)
753 pam_handle_t *pamh = NULL;
754 struct pam_conv *pconv = NULL;
756 /* Ignore PAM if told to. */
758 if (!lp_obey_pam_restrictions())
761 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
764 if (!smb_pam_start(&pamh, user, rhost, pconv))
767 if (!smb_internal_pam_session(pamh, user, tty, False)) {
768 smb_pam_end(pamh, pconv);
772 return smb_pam_end(pamh, pconv);
776 * PAM Externally accessible Account handler
779 NTSTATUS smb_pam_accountcheck(const char * user)
781 NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
782 pam_handle_t *pamh = NULL;
783 struct pam_conv *pconv = NULL;
785 /* Ignore PAM if told to. */
787 if (!lp_obey_pam_restrictions())
790 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
791 return NT_STATUS_NO_MEMORY;
793 if (!smb_pam_start(&pamh, user, NULL, pconv))
794 return NT_STATUS_ACCOUNT_DISABLED;
796 if (!NT_STATUS_IS_OK(nt_status = smb_pam_account(pamh, user)))
797 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user));
799 smb_pam_end(pamh, pconv);
804 * PAM Password Validation Suite
807 NTSTATUS smb_pam_passcheck(char * user, char * password)
809 pam_handle_t *pamh = NULL;
810 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
811 struct pam_conv *pconv = NULL;
814 * Note we can't ignore PAM here as this is the only
815 * way of doing auths on plaintext passwords when
816 * compiled --with-pam.
819 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, password, NULL)) == NULL)
820 return NT_STATUS_LOGON_FAILURE;
822 if (!smb_pam_start(&pamh, user, NULL, pconv))
823 return NT_STATUS_LOGON_FAILURE;
825 if (!NT_STATUS_IS_OK(nt_status = smb_pam_auth(pamh, user))) {
826 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user));
827 smb_pam_end(pamh, pconv);
831 if (!NT_STATUS_IS_OK(nt_status = smb_pam_account(pamh, user))) {
832 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user));
833 smb_pam_end(pamh, pconv);
837 if (!NT_STATUS_IS_OK(nt_status = smb_pam_setcred(pamh, user))) {
838 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user));
839 smb_pam_end(pamh, pconv);
843 smb_pam_end(pamh, pconv);
848 * PAM Password Change Suite
851 BOOL smb_pam_passchange(const char * user, const char * oldpassword, const char * newpassword)
853 /* Appropriate quantities of root should be obtained BEFORE calling this function */
854 struct pam_conv *pconv = NULL;
855 pam_handle_t *pamh = NULL;
857 if ((pconv = smb_setup_pam_conv(smb_pam_passchange_conv, user, oldpassword, newpassword)) == NULL)
860 if(!smb_pam_start(&pamh, user, NULL, pconv))
863 if (!smb_pam_chauthtok(pamh, user)) {
864 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user));
865 smb_pam_end(pamh, pconv);
869 return smb_pam_end(pamh, pconv);
874 /* If PAM not used, no PAM restrictions on accounts. */
875 NTSTATUS smb_pam_accountcheck(const char * user)
880 /* If PAM not used, also no PAM restrictions on sessions. */
881 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
886 /* If PAM not used, also no PAM restrictions on sessions. */
887 BOOL smb_pam_close_session(char *in_user, char *tty, char *rhost)
891 #endif /* WITH_PAM */