Stop coredump on pam password change with pam_pwdb.so module on error.
[Samba/gbeck.git] / source / passdb / pampass.c
blob68024f94810651bd951371d6b8a7c4dbbbb90656
1 /*
2 Unix SMB/Netbios implementation.
3 Version 2.2.
4 PAM Password checking
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
31 #include "includes.h"
33 extern int DEBUGLEVEL;
35 #ifdef WITH_PAM
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 char *PAM_username;
53 char *PAM_password;
54 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 /*******************************************************************
65 PAM error handler.
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)));
74 return False;
76 return True;
79 /*******************************************************************
80 This function is a sanity check, to make sure that we NEVER report
81 failure as sucess.
82 *********************************************************************/
84 static BOOL smb_pam_nt_status_error_handler(pam_handle_t *pamh, int pam_error,
85 char *msg, int dbglvl, uint32 *nt_status)
87 if (smb_pam_error_handler(pamh, pam_error, msg, dbglvl))
88 return True;
90 if (*nt_status == NT_STATUS_NOPROBLEMO) {
91 /* Complain LOUDLY */
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;
96 return False;
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,
108 void *appdata_ptr)
110 int replies = 0;
111 struct pam_response *reply = NULL;
112 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
114 *resp = NULL;
116 reply = malloc(sizeof(struct pam_response) * num_msg);
117 if (!reply)
118 return PAM_CONV_ERR;
120 for (replies = 0; replies < num_msg; replies++) {
121 switch (msg[replies]->msg_style) {
122 case PAM_PROMPT_ECHO_ON:
123 reply[replies].resp_retcode = PAM_SUCCESS;
124 reply[replies].resp = COPY_STRING(udp->PAM_username);
125 /* PAM frees resp */
126 break;
128 case PAM_PROMPT_ECHO_OFF:
129 reply[replies].resp_retcode = PAM_SUCCESS;
130 reply[replies].resp = COPY_STRING(udp->PAM_password);
131 /* PAM frees resp */
132 break;
134 case PAM_TEXT_INFO:
135 /* fall through */
137 case PAM_ERROR_MSG:
138 /* ignore it... */
139 reply[replies].resp_retcode = PAM_SUCCESS;
140 reply[replies].resp = NULL;
141 break;
143 default:
144 /* Must be an error of some sort... */
145 free(reply);
146 return PAM_CONV_ERR;
149 if (reply)
150 *resp = reply;
151 return PAM_SUCCESS;
155 * PAM password change conversation function
156 * Here we assume (for now, at least) that echo on means login name, and
157 * echo off means password.
160 static int smb_pam_passchange_conv(int num_msg,
161 const struct pam_message **msg,
162 struct pam_response **resp,
163 void *appdata_ptr)
165 int replies = 0;
166 struct pam_response *reply = NULL;
167 fstring currentpw_prompt;
168 fstring newpw_prompt;
169 fstring repeatpw_prompt;
170 char *p = lp_passwd_chat();
171 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
173 /* Get the prompts... */
175 if (!next_token(&p, currentpw_prompt, NULL, sizeof(fstring)))
176 return PAM_CONV_ERR;
177 if (!next_token(&p, newpw_prompt, NULL, sizeof(fstring)))
178 return PAM_CONV_ERR;
179 if (!next_token(&p, repeatpw_prompt, NULL, sizeof(fstring)))
180 return PAM_CONV_ERR;
182 *resp = NULL;
184 reply = malloc(sizeof(struct pam_response) * num_msg);
185 if (!reply)
186 return PAM_CONV_ERR;
188 for (replies = 0; replies < num_msg; replies++) {
189 switch (msg[replies]->msg_style) {
190 case PAM_PROMPT_ECHO_ON:
191 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: Replied: %s\n", msg[replies]->msg));
192 reply[replies].resp_retcode = PAM_SUCCESS;
193 reply[replies].resp = COPY_STRING(udp->PAM_username);
194 /* PAM frees resp */
195 break;
197 case PAM_PROMPT_ECHO_OFF:
198 reply[replies].resp_retcode = PAM_SUCCESS;
199 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: Replied: %s\n", msg[replies]->msg));
200 if (strncmp(currentpw_prompt, msg[replies]->msg, strlen(currentpw_prompt)) == 0) {
201 reply[replies].resp = COPY_STRING(udp->PAM_password);
202 } else if (strncmp(newpw_prompt, msg[replies]->msg, strlen(newpw_prompt)) == 0) {
203 reply[replies].resp = COPY_STRING(udp->PAM_newpassword);
204 } else if (strncmp(repeatpw_prompt, msg[replies]->msg, strlen(repeatpw_prompt)) == 0) {
205 reply[replies].resp = COPY_STRING(udp->PAM_newpassword);
206 } else {
207 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
208 DEBUG(5,("smb_pam_passchange_conv: Prompts available:\n CurrentPW: \"%s\"\n NewPW: \"%s\"\n \
209 RepeatPW: \"%s\"\n",currentpw_prompt,newpw_prompt,repeatpw_prompt));
210 free(reply);
211 reply = NULL;
212 return PAM_CONV_ERR;
214 /* PAM frees resp */
215 break;
217 case PAM_TEXT_INFO:
218 /* fall through */
220 case PAM_ERROR_MSG:
221 /* ignore it... */
222 reply[replies].resp_retcode = PAM_SUCCESS;
223 reply[replies].resp = NULL;
224 break;
226 default:
227 /* Must be an error of some sort... */
228 free(reply);
229 reply = NULL;
230 return PAM_CONV_ERR;
234 if (reply)
235 *resp = reply;
236 return PAM_SUCCESS;
239 /***************************************************************************
240 Free up a malloced pam_conv struct.
241 ****************************************************************************/
243 static void smb_free_pam_conv(struct pam_conv *pconv)
245 if (pconv)
246 safe_free(pconv->appdata_ptr);
248 safe_free(pconv);
251 /***************************************************************************
252 Allocate a pam_conv struct.
253 ****************************************************************************/
255 static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, char *user,
256 char *passwd, char *newpass)
258 struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv));
259 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata));
261 if (pconv == NULL || udp == NULL) {
262 safe_free(pconv);
263 safe_free(udp);
264 return NULL;
267 udp->PAM_username = user;
268 udp->PAM_password = passwd;
269 udp->PAM_newpassword = newpass;
271 pconv->conv = smb_pam_conv_fnptr;
272 pconv->appdata_ptr = (void *)udp;
273 return pconv;
277 * PAM Closing out cleanup handler
280 static BOOL smb_pam_end(pam_handle_t *pamh, struct pam_conv *smb_pam_conv_ptr)
282 int pam_error;
284 smb_free_pam_conv(smb_pam_conv_ptr);
286 if( pamh != NULL ) {
287 pam_error = pam_end(pamh, 0);
288 if(smb_pam_error_handler(pamh, pam_error, "End Cleanup Failed", 2) == True) {
289 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
290 return True;
293 DEBUG(2,("smb_pam_end: PAM: not initialised"));
294 return False;
298 * Start PAM authentication for specified account
301 static BOOL smb_pam_start(pam_handle_t **pamh, char *user, char *rhost, struct pam_conv *pconv)
303 int pam_error;
305 *pamh = (pam_handle_t *)NULL;
307 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user));
309 pam_error = pam_start("samba", user, pconv, pamh);
310 if( !smb_pam_error_handler(*pamh, pam_error, "Init Failed", 0)) {
311 *pamh = (pam_handle_t *)NULL;
312 return False;
315 if (rhost == NULL) {
316 rhost = client_name();
317 if (strequal(rhost,"UNKNOWN"))
318 rhost = client_addr();
321 #ifdef PAM_RHOST
322 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", rhost));
323 pam_error = pam_set_item(*pamh, PAM_RHOST, rhost);
324 if(!smb_pam_error_handler(*pamh, pam_error, "set rhost failed", 0)) {
325 smb_pam_end(*pamh, pconv);
326 *pamh = (pam_handle_t *)NULL;
327 return False;
329 #endif
330 #ifdef PAM_TTY
331 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
332 pam_error = pam_set_item(*pamh, PAM_TTY, "samba");
333 if (!smb_pam_error_handler(*pamh, pam_error, "set tty failed", 0)) {
334 smb_pam_end(*pamh, pconv);
335 *pamh = (pam_handle_t *)NULL;
336 return False;
338 #endif
339 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user));
340 return True;
344 * PAM Authentication Handler
346 static uint32 smb_pam_auth(pam_handle_t *pamh, char *user)
348 int pam_error;
349 uint32 nt_status = NT_STATUS_LOGON_FAILURE;
352 * To enable debugging set in /etc/pam.d/samba:
353 * auth required /lib/security/pam_pwdb.so nullok shadow audit
356 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user));
357 pam_error = pam_authenticate(pamh, PAM_SILENT | lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK);
358 switch( pam_error ){
359 case PAM_AUTH_ERR:
360 DEBUG(2, ("smb_pam_auth: PAM: Athentication Error for user %s\n", user));
361 nt_status = NT_STATUS_WRONG_PASSWORD;
362 break;
363 case PAM_CRED_INSUFFICIENT:
364 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user));
365 nt_status = NT_STATUS_INSUFFICIENT_LOGON_INFO;
366 break;
367 case PAM_AUTHINFO_UNAVAIL:
368 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user));
369 nt_status = NT_STATUS_LOGON_FAILURE;
370 break;
371 case PAM_USER_UNKNOWN:
372 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user));
373 nt_status = NT_STATUS_NO_SUCH_USER;
374 break;
375 case PAM_MAXTRIES:
376 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user));
377 nt_status = NT_STATUS_REMOTE_SESSION_LIMIT;
378 break;
379 case PAM_ABORT:
380 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user));
381 nt_status = NT_STATUS_LOGON_FAILURE;
382 break;
383 case PAM_SUCCESS:
384 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user));
385 nt_status = NT_STATUS_NOPROBLEMO;
386 break;
387 default:
388 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user));
389 nt_status = NT_STATUS_LOGON_FAILURE;
390 break;
393 smb_pam_nt_status_error_handler(pamh, pam_error, "Authentication Failure", 2, &nt_status);
394 return nt_status;
398 * PAM Account Handler
400 static uint32 smb_pam_account(pam_handle_t *pamh, char * user)
402 int pam_error;
403 uint32 nt_status = NT_STATUS_ACCOUNT_DISABLED;
405 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user));
406 pam_error = pam_acct_mgmt(pamh, PAM_SILENT); /* Is user account enabled? */
407 switch( pam_error ) {
408 case PAM_AUTHTOK_EXPIRED:
409 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user));
410 nt_status = NT_STATUS_PASSWORD_EXPIRED;
411 break;
412 case PAM_ACCT_EXPIRED:
413 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user));
414 nt_status = NT_STATUS_ACCOUNT_EXPIRED;
415 break;
416 case PAM_AUTH_ERR:
417 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user));
418 nt_status = NT_STATUS_LOGON_FAILURE;
419 break;
420 case PAM_PERM_DENIED:
421 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user));
422 nt_status = NT_STATUS_ACCOUNT_RESTRICTION;
423 break;
424 case PAM_USER_UNKNOWN:
425 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user));
426 nt_status = NT_STATUS_NO_SUCH_USER;
427 break;
428 case PAM_SUCCESS:
429 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user));
430 nt_status = NT_STATUS_NOPROBLEMO;
431 break;
432 default:
433 nt_status = NT_STATUS_ACCOUNT_DISABLED;
434 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error, user));
435 break;
438 smb_pam_nt_status_error_handler(pamh, pam_error, "Account Check Failed", 2, &nt_status);
439 return nt_status;
443 * PAM Credential Setting
446 static uint32 smb_pam_setcred(pam_handle_t *pamh, char * user)
448 int pam_error;
449 uint32 nt_status = NT_STATUS_NO_TOKEN;
452 * This will allow samba to aquire a kerberos token. And, when
453 * exporting an AFS cell, be able to /write/ to this cell.
456 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user));
457 pam_error = pam_setcred(pamh, (PAM_ESTABLISH_CRED|PAM_SILENT));
458 switch( pam_error ) {
459 case PAM_CRED_UNAVAIL:
460 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user ));
461 nt_status = NT_STATUS_NO_TOKEN;
462 break;
463 case PAM_CRED_EXPIRED:
464 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user ));
465 nt_status = NT_STATUS_PASSWORD_EXPIRED;
466 break;
467 case PAM_USER_UNKNOWN:
468 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user ));
469 nt_status = NT_STATUS_NO_SUCH_USER;
470 break;
471 case PAM_CRED_ERR:
472 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user ));
473 nt_status = NT_STATUS_LOGON_FAILURE;
474 break;
475 case PAM_SUCCESS:
476 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user));
477 nt_status = NT_STATUS_NOPROBLEMO;
478 break;
479 default:
480 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error, user));
481 nt_status = NT_STATUS_NO_TOKEN;
482 break;
485 smb_pam_nt_status_error_handler(pamh, pam_error, "Set Credential Failure", 2, &nt_status);
486 return nt_status;
490 * PAM Internal Session Handler
492 static BOOL smb_internal_pam_session(pam_handle_t *pamh, char *user, char *tty, BOOL flag)
494 int pam_error;
496 #ifdef PAM_TTY
497 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty));
498 pam_error = pam_set_item(pamh, PAM_TTY, tty);
499 if (!smb_pam_error_handler(pamh, pam_error, "set tty failed", 0))
500 return False;
501 #endif
503 if (flag) {
504 pam_error = pam_open_session(pamh, PAM_SILENT);
505 if (!smb_pam_error_handler(pamh, pam_error, "session setup failed", 0))
506 return False;
507 } else {
508 pam_setcred(pamh, (PAM_DELETE_CRED|PAM_SILENT)); /* We don't care if this fails */
509 pam_error = pam_close_session(pamh, PAM_SILENT); /* This will probably pick up the error anyway */
510 if (!smb_pam_error_handler(pamh, pam_error, "session close failed", 0))
511 return False;
513 return (True);
517 * Internal PAM Password Changer.
520 static BOOL smb_pam_chauthtok(pam_handle_t *pamh, char * user)
522 int pam_error;
524 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user));
526 pam_error = pam_chauthtok(pamh, PAM_SILENT); /* Change Password */
528 switch( pam_error ) {
529 case PAM_AUTHTOK_ERR:
530 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
531 break;
533 /* This doesn't seem to be defined on Solaris. JRA */
534 #ifdef PAM_AUTHTOK_RECOVER_ERR
535 case PAM_AUTHTOK_RECOVER_ERR:
536 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
537 break;
538 #endif
540 case PAM_AUTHTOK_LOCK_BUSY:
541 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
542 break;
543 case PAM_AUTHTOK_DISABLE_AGING:
544 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
545 break;
546 case PAM_PERM_DENIED:
547 DEBUG(0, ("PAM: Permission denied.\n"));
548 break;
549 case PAM_TRY_AGAIN:
550 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
551 break;
552 case PAM_USER_UNKNOWN:
553 DEBUG(0, ("PAM: User not known to PAM\n"));
554 break;
555 case PAM_SUCCESS:
556 DEBUG(4, ("PAM: Account OK for User: %s\n", user));
557 break;
558 default:
559 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error, user));
562 if(!smb_pam_error_handler(pamh, pam_error, "Password Change Failed", 2)) {
563 return False;
566 /* If this point is reached, the password has changed. */
567 return True;
571 * PAM Externally accessible Session handler
574 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
576 pam_handle_t *pamh = NULL;
577 struct pam_conv *pconv = NULL;
579 /* Ignore PAM if told to. */
581 if (!lp_obey_pam_restrictions())
582 return True;
584 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
585 return False;
587 if (!smb_pam_start(&pamh, user, rhost, pconv))
588 return False;
590 if (!smb_internal_pam_session(pamh, user, tty, True)) {
591 smb_pam_end(pamh, pconv);
592 return False;
595 return smb_pam_end(pamh, pconv);
599 * PAM Externally accessible Session handler
602 BOOL smb_pam_close_session(char *user, char *tty, char *rhost)
604 pam_handle_t *pamh = NULL;
605 struct pam_conv *pconv = NULL;
607 /* Ignore PAM if told to. */
609 if (!lp_obey_pam_restrictions())
610 return True;
612 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
613 return False;
615 if (!smb_pam_start(&pamh, user, rhost, pconv))
616 return False;
618 if (!smb_internal_pam_session(pamh, user, tty, False)) {
619 smb_pam_end(pamh, pconv);
620 return False;
623 return smb_pam_end(pamh, pconv);
627 * PAM Externally accessible Account handler
630 uint32 smb_pam_accountcheck(char * user)
632 uint32 nt_status = NT_STATUS_ACCOUNT_DISABLED;
633 pam_handle_t *pamh = NULL;
634 struct pam_conv *pconv = NULL;
636 /* Ignore PAM if told to. */
638 if (!lp_obey_pam_restrictions())
639 return NT_STATUS_NOPROBLEMO;
641 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
642 return False;
644 if (!smb_pam_start(&pamh, user, NULL, pconv))
645 return NT_STATUS_ACCOUNT_DISABLED;
647 if ((nt_status = smb_pam_account(pamh, user)) != NT_STATUS_NOPROBLEMO)
648 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user));
650 smb_pam_end(pamh, pconv);
651 return nt_status;
655 * PAM Password Validation Suite
658 uint32 smb_pam_passcheck(char * user, char * password)
660 pam_handle_t *pamh = NULL;
661 uint32 nt_status = NT_STATUS_LOGON_FAILURE;
662 struct pam_conv *pconv = NULL;
665 * Note we can't ignore PAM here as this is the only
666 * way of doing auths on plaintext passwords when
667 * compiled --with-pam.
670 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, password, NULL)) == NULL)
671 return NT_STATUS_LOGON_FAILURE;
673 if (!smb_pam_start(&pamh, user, NULL, pconv))
674 return NT_STATUS_LOGON_FAILURE;
676 if ((nt_status = smb_pam_auth(pamh, user)) != NT_STATUS_NOPROBLEMO) {
677 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user));
678 smb_pam_end(pamh, pconv);
679 return nt_status;
682 if ((nt_status = smb_pam_account(pamh, user)) != NT_STATUS_NOPROBLEMO) {
683 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user));
684 smb_pam_end(pamh, pconv);
685 return nt_status;
688 if ((nt_status = smb_pam_setcred(pamh, user)) != NT_STATUS_NOPROBLEMO) {
689 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user));
690 smb_pam_end(pamh, pconv);
691 return nt_status;
694 smb_pam_end(pamh, pconv);
695 return nt_status;
699 * PAM Password Change Suite
702 BOOL smb_pam_passchange(char * user, char * oldpassword, char * newpassword)
704 /* Appropriate quantities of root should be obtained BEFORE calling this function */
705 struct pam_conv *pconv = NULL;
706 pam_handle_t *pamh = NULL;
708 if ((pconv = smb_setup_pam_conv(smb_pam_passchange_conv, user, oldpassword, newpassword)) == NULL)
709 return False;
711 if(!smb_pam_start(&pamh, user, NULL, pconv))
712 return False;
714 if (!smb_pam_chauthtok(pamh, user)) {
715 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user));
716 smb_pam_end(pamh, pconv);
717 return False;
720 return smb_pam_end(pamh, pconv);
723 #else
725 /* If PAM not used, no PAM restrictions on accounts. */
726 uint32 smb_pam_accountcheck(char * user)
728 return NT_STATUS_NOPROBLEMO;
731 /* If PAM not used, also no PAM restrictions on sessions. */
732 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
734 return True;
737 /* If PAM not used, also no PAM restrictions on sessions. */
738 BOOL smb_pam_close_session(char *in_user, char *tty, char *rhost)
740 return True;
742 #endif /* WITH_PAM */