00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "includes.h"
00031
00032 #undef DBGC_CLASS
00033 #define DBGC_CLASS DBGC_AUTH
00034
00035 #ifdef WITH_PAM
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <security/pam_appl.h>
00045
00046
00047
00048
00049
00050
00051 struct smb_pam_userdata {
00052 const char *PAM_username;
00053 const char *PAM_password;
00054 const char *PAM_newpassword;
00055 };
00056
00057 typedef int (*smb_pam_conv_fn)(int, const struct pam_message **, struct pam_response **, void *appdata_ptr);
00058
00059
00060
00061
00062 #define COPY_STRING(s) (s) ? SMB_STRDUP(s) : NULL
00063
00064
00065
00066
00067
00068 static BOOL smb_pam_error_handler(pam_handle_t *pamh, int pam_error, const char *msg, int dbglvl)
00069 {
00070
00071 if( pam_error != PAM_SUCCESS) {
00072 DEBUG(dbglvl, ("smb_pam_error_handler: PAM: %s : %s\n",
00073 msg, pam_strerror(pamh, pam_error)));
00074
00075 return False;
00076 }
00077 return True;
00078 }
00079
00080
00081
00082
00083
00084
00085 static BOOL smb_pam_nt_status_error_handler(pam_handle_t *pamh, int pam_error,
00086 const char *msg, int dbglvl,
00087 NTSTATUS *nt_status)
00088 {
00089 *nt_status = pam_to_nt_status(pam_error);
00090
00091 if (smb_pam_error_handler(pamh, pam_error, msg, dbglvl))
00092 return True;
00093
00094 if (NT_STATUS_IS_OK(*nt_status)) {
00095
00096 DEBUG(0, ("smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
00097 error MISMATCH, forcing to NT_STATUS_LOGON_FAILURE"));
00098 *nt_status = NT_STATUS_LOGON_FAILURE;
00099 }
00100 return False;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 static int smb_pam_conv(int num_msg,
00110 const struct pam_message **msg,
00111 struct pam_response **resp,
00112 void *appdata_ptr)
00113 {
00114 int replies = 0;
00115 struct pam_response *reply = NULL;
00116 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
00117
00118 *resp = NULL;
00119
00120 if (num_msg <= 0)
00121 return PAM_CONV_ERR;
00122
00123
00124
00125
00126
00127
00128 if (udp == NULL) {
00129 DEBUG(0,("smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
00130 return PAM_CONV_ERR;
00131 }
00132
00133 reply = SMB_MALLOC_ARRAY(struct pam_response, num_msg);
00134 if (!reply)
00135 return PAM_CONV_ERR;
00136
00137 memset(reply, '\0', sizeof(struct pam_response) * num_msg);
00138
00139 for (replies = 0; replies < num_msg; replies++) {
00140 switch (msg[replies]->msg_style) {
00141 case PAM_PROMPT_ECHO_ON:
00142 reply[replies].resp_retcode = PAM_SUCCESS;
00143 reply[replies].resp = COPY_STRING(udp->PAM_username);
00144
00145 break;
00146
00147 case PAM_PROMPT_ECHO_OFF:
00148 reply[replies].resp_retcode = PAM_SUCCESS;
00149 reply[replies].resp = COPY_STRING(udp->PAM_password);
00150
00151 break;
00152
00153 case PAM_TEXT_INFO:
00154
00155
00156 case PAM_ERROR_MSG:
00157
00158 reply[replies].resp_retcode = PAM_SUCCESS;
00159 reply[replies].resp = NULL;
00160 break;
00161
00162 default:
00163
00164 SAFE_FREE(reply);
00165 return PAM_CONV_ERR;
00166 }
00167 }
00168 if (reply)
00169 *resp = reply;
00170 return PAM_SUCCESS;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 static void special_char_sub(char *buf)
00180 {
00181 all_string_sub(buf, "\\n", "", 0);
00182 all_string_sub(buf, "\\r", "", 0);
00183 all_string_sub(buf, "\\s", " ", 0);
00184 all_string_sub(buf, "\\t", "\t", 0);
00185 }
00186
00187 static void pwd_sub(char *buf, const char *username, const char *oldpass, const char *newpass)
00188 {
00189 fstring_sub(buf, "%u", username);
00190 all_string_sub(buf, "%o", oldpass, sizeof(fstring));
00191 all_string_sub(buf, "%n", newpass, sizeof(fstring));
00192 }
00193
00194
00195 struct chat_struct {
00196 struct chat_struct *next, *prev;
00197 fstring prompt;
00198 fstring reply;
00199 };
00200
00201
00202
00203
00204
00205 static struct chat_struct *make_pw_chat(const char *p)
00206 {
00207 fstring prompt;
00208 fstring reply;
00209 struct chat_struct *list = NULL;
00210 struct chat_struct *t;
00211
00212 while (1) {
00213 t = SMB_MALLOC_P(struct chat_struct);
00214 if (!t) {
00215 DEBUG(0,("make_pw_chat: malloc failed!\n"));
00216 return NULL;
00217 }
00218
00219 ZERO_STRUCTP(t);
00220
00221 DLIST_ADD_END(list, t, struct chat_struct*);
00222
00223 if (!next_token(&p, prompt, NULL, sizeof(fstring)))
00224 break;
00225
00226 if (strequal(prompt,"."))
00227 fstrcpy(prompt,"*");
00228
00229 special_char_sub(prompt);
00230 fstrcpy(t->prompt, prompt);
00231 strlower_m(t->prompt);
00232 trim_char(t->prompt, ' ', ' ');
00233
00234 if (!next_token(&p, reply, NULL, sizeof(fstring)))
00235 break;
00236
00237 if (strequal(reply,"."))
00238 fstrcpy(reply,"");
00239
00240 special_char_sub(reply);
00241 fstrcpy(t->reply, reply);
00242 strlower_m(t->reply);
00243 trim_char(t->reply, ' ', ' ');
00244
00245 }
00246 return list;
00247 }
00248
00249 static void free_pw_chat(struct chat_struct *list)
00250 {
00251 while (list) {
00252 struct chat_struct *old_head = list;
00253 DLIST_REMOVE(list, list);
00254 SAFE_FREE(old_head);
00255 }
00256 }
00257
00258 static int smb_pam_passchange_conv(int num_msg,
00259 const struct pam_message **msg,
00260 struct pam_response **resp,
00261 void *appdata_ptr)
00262 {
00263 int replies = 0;
00264 struct pam_response *reply = NULL;
00265 fstring current_prompt;
00266 fstring current_reply;
00267 struct smb_pam_userdata *udp = (struct smb_pam_userdata *)appdata_ptr;
00268 struct chat_struct *pw_chat= make_pw_chat(lp_passwd_chat());
00269 struct chat_struct *t;
00270 BOOL found;
00271 *resp = NULL;
00272
00273 DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg));
00274
00275 if (num_msg <= 0)
00276 return PAM_CONV_ERR;
00277
00278 if (pw_chat == NULL)
00279 return PAM_CONV_ERR;
00280
00281
00282
00283
00284
00285
00286 if (udp == NULL) {
00287 DEBUG(0,("smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL !\n"));
00288 free_pw_chat(pw_chat);
00289 return PAM_CONV_ERR;
00290 }
00291
00292 reply = SMB_MALLOC_ARRAY(struct pam_response, num_msg);
00293 if (!reply) {
00294 DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
00295 free_pw_chat(pw_chat);
00296 return PAM_CONV_ERR;
00297 }
00298
00299 for (replies = 0; replies < num_msg; replies++) {
00300 found = False;
00301 DEBUG(10,("smb_pam_passchange_conv: Processing message %d\n", replies));
00302 switch (msg[replies]->msg_style) {
00303 case PAM_PROMPT_ECHO_ON:
00304 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg[replies]->msg));
00305 fstrcpy(current_prompt, msg[replies]->msg);
00306 trim_char(current_prompt, ' ', ' ');
00307 for (t=pw_chat; t; t=t->next) {
00308
00309 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
00310 t->prompt, current_prompt ));
00311
00312 if (unix_wild_match(t->prompt, current_prompt)) {
00313 fstrcpy(current_reply, t->reply);
00314 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply));
00315 pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
00316 #ifdef DEBUG_PASSWORD
00317 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply));
00318 #endif
00319 reply[replies].resp_retcode = PAM_SUCCESS;
00320 reply[replies].resp = COPY_STRING(current_reply);
00321 found = True;
00322 break;
00323 }
00324 }
00325
00326 if (!found) {
00327 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
00328 free_pw_chat(pw_chat);
00329 SAFE_FREE(reply);
00330 return PAM_CONV_ERR;
00331 }
00332 break;
00333
00334 case PAM_PROMPT_ECHO_OFF:
00335 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg[replies]->msg));
00336 fstrcpy(current_prompt, msg[replies]->msg);
00337 trim_char(current_prompt, ' ', ' ');
00338 for (t=pw_chat; t; t=t->next) {
00339
00340 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
00341 t->prompt, current_prompt ));
00342
00343 if (unix_wild_match(t->prompt, current_prompt)) {
00344 fstrcpy(current_reply, t->reply);
00345 DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply));
00346 pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
00347 reply[replies].resp_retcode = PAM_SUCCESS;
00348 reply[replies].resp = COPY_STRING(current_reply);
00349 #ifdef DEBUG_PASSWORD
00350 DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply));
00351 #endif
00352 found = True;
00353 break;
00354 }
00355 }
00356
00357
00358 if (!found) {
00359 DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
00360 free_pw_chat(pw_chat);
00361 SAFE_FREE(reply);
00362 return PAM_CONV_ERR;
00363 }
00364 break;
00365
00366 case PAM_TEXT_INFO:
00367
00368
00369 case PAM_ERROR_MSG:
00370
00371 reply[replies].resp_retcode = PAM_SUCCESS;
00372 reply[replies].resp = NULL;
00373 break;
00374
00375 default:
00376
00377 free_pw_chat(pw_chat);
00378 SAFE_FREE(reply);
00379 return PAM_CONV_ERR;
00380 }
00381 }
00382
00383 free_pw_chat(pw_chat);
00384 if (reply)
00385 *resp = reply;
00386 return PAM_SUCCESS;
00387 }
00388
00389
00390
00391
00392
00393 static void smb_free_pam_conv(struct pam_conv *pconv)
00394 {
00395 if (pconv)
00396 SAFE_FREE(pconv->appdata_ptr);
00397
00398 SAFE_FREE(pconv);
00399 }
00400
00401
00402
00403
00404
00405 static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user,
00406 const char *passwd, const char *newpass)
00407 {
00408 struct pam_conv *pconv = SMB_MALLOC_P(struct pam_conv);
00409 struct smb_pam_userdata *udp = SMB_MALLOC_P(struct smb_pam_userdata);
00410
00411 if (pconv == NULL || udp == NULL) {
00412 SAFE_FREE(pconv);
00413 SAFE_FREE(udp);
00414 return NULL;
00415 }
00416
00417 udp->PAM_username = user;
00418 udp->PAM_password = passwd;
00419 udp->PAM_newpassword = newpass;
00420
00421 pconv->conv = smb_pam_conv_fnptr;
00422 pconv->appdata_ptr = (void *)udp;
00423 return pconv;
00424 }
00425
00426
00427
00428
00429
00430 static BOOL smb_pam_end(pam_handle_t *pamh, struct pam_conv *smb_pam_conv_ptr)
00431 {
00432 int pam_error;
00433
00434 smb_free_pam_conv(smb_pam_conv_ptr);
00435
00436 if( pamh != NULL ) {
00437 pam_error = pam_end(pamh, 0);
00438 if(smb_pam_error_handler(pamh, pam_error, "End Cleanup Failed", 2) == True) {
00439 DEBUG(4, ("smb_pam_end: PAM: PAM_END OK.\n"));
00440 return True;
00441 }
00442 }
00443 DEBUG(2,("smb_pam_end: PAM: not initialised"));
00444 return False;
00445 }
00446
00447
00448
00449
00450
00451 static BOOL smb_pam_start(pam_handle_t **pamh, const char *user, const char *rhost, struct pam_conv *pconv)
00452 {
00453 int pam_error;
00454 const char *our_rhost;
00455
00456 *pamh = (pam_handle_t *)NULL;
00457
00458 DEBUG(4,("smb_pam_start: PAM: Init user: %s\n", user));
00459
00460 pam_error = pam_start("samba", user, pconv, pamh);
00461 if( !smb_pam_error_handler(*pamh, pam_error, "Init Failed", 0)) {
00462 *pamh = (pam_handle_t *)NULL;
00463 return False;
00464 }
00465
00466 if (rhost == NULL) {
00467 our_rhost = client_name();
00468 if (strequal(our_rhost,"UNKNOWN"))
00469 our_rhost = client_addr();
00470 } else {
00471 our_rhost = rhost;
00472 }
00473
00474 #ifdef PAM_RHOST
00475 DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost));
00476 pam_error = pam_set_item(*pamh, PAM_RHOST, our_rhost);
00477 if(!smb_pam_error_handler(*pamh, pam_error, "set rhost failed", 0)) {
00478 smb_pam_end(*pamh, pconv);
00479 *pamh = (pam_handle_t *)NULL;
00480 return False;
00481 }
00482 #endif
00483 #ifdef PAM_TTY
00484 DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
00485 pam_error = pam_set_item(*pamh, PAM_TTY, "samba");
00486 if (!smb_pam_error_handler(*pamh, pam_error, "set tty failed", 0)) {
00487 smb_pam_end(*pamh, pconv);
00488 *pamh = (pam_handle_t *)NULL;
00489 return False;
00490 }
00491 #endif
00492 DEBUG(4,("smb_pam_start: PAM: Init passed for user: %s\n", user));
00493 return True;
00494 }
00495
00496
00497
00498
00499 static NTSTATUS smb_pam_auth(pam_handle_t *pamh, const char *user)
00500 {
00501 int pam_error;
00502 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
00503
00504
00505
00506
00507
00508
00509 DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user));
00510 pam_error = pam_authenticate(pamh, PAM_SILENT | lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK);
00511 switch( pam_error ){
00512 case PAM_AUTH_ERR:
00513 DEBUG(2, ("smb_pam_auth: PAM: Authentication Error for user %s\n", user));
00514 break;
00515 case PAM_CRED_INSUFFICIENT:
00516 DEBUG(2, ("smb_pam_auth: PAM: Insufficient Credentials for user %s\n", user));
00517 break;
00518 case PAM_AUTHINFO_UNAVAIL:
00519 DEBUG(2, ("smb_pam_auth: PAM: Authentication Information Unavailable for user %s\n", user));
00520 break;
00521 case PAM_USER_UNKNOWN:
00522 DEBUG(2, ("smb_pam_auth: PAM: Username %s NOT known to Authentication system\n", user));
00523 break;
00524 case PAM_MAXTRIES:
00525 DEBUG(2, ("smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded\n", user));
00526 break;
00527 case PAM_ABORT:
00528 DEBUG(0, ("smb_pam_auth: PAM: One or more PAM modules failed to load for user %s\n", user));
00529 break;
00530 case PAM_SUCCESS:
00531 DEBUG(4, ("smb_pam_auth: PAM: User %s Authenticated OK\n", user));
00532 break;
00533 default:
00534 DEBUG(0, ("smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s\n", user));
00535 break;
00536 }
00537
00538 smb_pam_nt_status_error_handler(pamh, pam_error, "Authentication Failure", 2, &nt_status);
00539 return nt_status;
00540 }
00541
00542
00543
00544
00545 static NTSTATUS smb_pam_account(pam_handle_t *pamh, const char * user)
00546 {
00547 int pam_error;
00548 NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
00549
00550 DEBUG(4,("smb_pam_account: PAM: Account Management for User: %s\n", user));
00551 pam_error = pam_acct_mgmt(pamh, PAM_SILENT);
00552 switch( pam_error ) {
00553 case PAM_AUTHTOK_EXPIRED:
00554 DEBUG(2, ("smb_pam_account: PAM: User %s is valid but password is expired\n", user));
00555 break;
00556 case PAM_ACCT_EXPIRED:
00557 DEBUG(2, ("smb_pam_account: PAM: User %s no longer permitted to access system\n", user));
00558 break;
00559 case PAM_AUTH_ERR:
00560 DEBUG(2, ("smb_pam_account: PAM: There was an authentication error for user %s\n", user));
00561 break;
00562 case PAM_PERM_DENIED:
00563 DEBUG(0, ("smb_pam_account: PAM: User %s is NOT permitted to access system at this time\n", user));
00564 break;
00565 case PAM_USER_UNKNOWN:
00566 DEBUG(0, ("smb_pam_account: PAM: User \"%s\" is NOT known to account management\n", user));
00567 break;
00568 case PAM_SUCCESS:
00569 DEBUG(4, ("smb_pam_account: PAM: Account OK for User: %s\n", user));
00570 break;
00571 default:
00572 DEBUG(0, ("smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s\n", pam_error, user));
00573 break;
00574 }
00575
00576 smb_pam_nt_status_error_handler(pamh, pam_error, "Account Check Failed", 2, &nt_status);
00577 return nt_status;
00578 }
00579
00580
00581
00582
00583
00584 static NTSTATUS smb_pam_setcred(pam_handle_t *pamh, const char * user)
00585 {
00586 int pam_error;
00587 NTSTATUS nt_status = NT_STATUS_NO_TOKEN;
00588
00589
00590
00591
00592
00593
00594 DEBUG(4,("PAM: Account Management SetCredentials for User: %s\n", user));
00595 pam_error = pam_setcred(pamh, (PAM_ESTABLISH_CRED|PAM_SILENT));
00596 switch( pam_error ) {
00597 case PAM_CRED_UNAVAIL:
00598 DEBUG(0, ("smb_pam_setcred: PAM: Credentials not found for user:%s\n", user ));
00599 break;
00600 case PAM_CRED_EXPIRED:
00601 DEBUG(0, ("smb_pam_setcred: PAM: Credentials for user: \"%s\" EXPIRED!\n", user ));
00602 break;
00603 case PAM_USER_UNKNOWN:
00604 DEBUG(0, ("smb_pam_setcred: PAM: User: \"%s\" is NOT known so can not set credentials!\n", user ));
00605 break;
00606 case PAM_CRED_ERR:
00607 DEBUG(0, ("smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s\n", user ));
00608 break;
00609 case PAM_SUCCESS:
00610 DEBUG(4, ("smb_pam_setcred: PAM: SetCredentials OK for User: %s\n", user));
00611 break;
00612 default:
00613 DEBUG(0, ("smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s\n", pam_error, user));
00614 break;
00615 }
00616
00617 smb_pam_nt_status_error_handler(pamh, pam_error, "Set Credential Failure", 2, &nt_status);
00618 return nt_status;
00619 }
00620
00621
00622
00623
00624 static BOOL smb_internal_pam_session(pam_handle_t *pamh, const char *user, const char *tty, BOOL flag)
00625 {
00626 int pam_error;
00627
00628 #ifdef PAM_TTY
00629 DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty));
00630 pam_error = pam_set_item(pamh, PAM_TTY, tty);
00631 if (!smb_pam_error_handler(pamh, pam_error, "set tty failed", 0))
00632 return False;
00633 #endif
00634
00635 if (flag) {
00636 pam_error = pam_open_session(pamh, PAM_SILENT);
00637 if (!smb_pam_error_handler(pamh, pam_error, "session setup failed", 0))
00638 return False;
00639 } else {
00640 pam_setcred(pamh, (PAM_DELETE_CRED|PAM_SILENT));
00641 pam_error = pam_close_session(pamh, PAM_SILENT);
00642 if (!smb_pam_error_handler(pamh, pam_error, "session close failed", 0))
00643 return False;
00644 }
00645 return (True);
00646 }
00647
00648
00649
00650
00651
00652 static BOOL smb_pam_chauthtok(pam_handle_t *pamh, const char * user)
00653 {
00654 int pam_error;
00655
00656 DEBUG(4,("smb_pam_chauthtok: PAM: Password Change for User: %s\n", user));
00657
00658 pam_error = pam_chauthtok(pamh, PAM_SILENT);
00659
00660 switch( pam_error ) {
00661 case PAM_AUTHTOK_ERR:
00662 DEBUG(2, ("PAM: unable to obtain the new authentication token - is password to weak?\n"));
00663 break;
00664
00665
00666 #ifdef PAM_AUTHTOK_RECOVER_ERR
00667 case PAM_AUTHTOK_RECOVER_ERR:
00668 DEBUG(2, ("PAM: unable to obtain the old authentication token - was the old password wrong?.\n"));
00669 break;
00670 #endif
00671
00672 case PAM_AUTHTOK_LOCK_BUSY:
00673 DEBUG(2, ("PAM: unable to change the authentication token since it is currently locked.\n"));
00674 break;
00675 case PAM_AUTHTOK_DISABLE_AGING:
00676 DEBUG(2, ("PAM: Authentication token aging has been disabled.\n"));
00677 break;
00678 case PAM_PERM_DENIED:
00679 DEBUG(0, ("PAM: Permission denied.\n"));
00680 break;
00681 case PAM_TRY_AGAIN:
00682 DEBUG(0, ("PAM: Could not update all authentication token(s). No authentication tokens were updated.\n"));
00683 break;
00684 case PAM_USER_UNKNOWN:
00685 DEBUG(0, ("PAM: User not known to PAM\n"));
00686 break;
00687 case PAM_SUCCESS:
00688 DEBUG(4, ("PAM: Account OK for User: %s\n", user));
00689 break;
00690 default:
00691 DEBUG(0, ("PAM: UNKNOWN PAM ERROR (%d) for User: %s\n", pam_error, user));
00692 }
00693
00694 if(!smb_pam_error_handler(pamh, pam_error, "Password Change Failed", 2)) {
00695 return False;
00696 }
00697
00698
00699 return True;
00700 }
00701
00702
00703
00704
00705
00706 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
00707 {
00708 pam_handle_t *pamh = NULL;
00709 struct pam_conv *pconv = NULL;
00710
00711
00712
00713 if (!lp_obey_pam_restrictions())
00714 return True;
00715
00716 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
00717 return False;
00718
00719 if (!smb_pam_start(&pamh, user, rhost, pconv))
00720 return False;
00721
00722 if (!smb_internal_pam_session(pamh, user, tty, True)) {
00723 smb_pam_end(pamh, pconv);
00724 return False;
00725 }
00726
00727 return smb_pam_end(pamh, pconv);
00728 }
00729
00730
00731
00732
00733
00734 BOOL smb_pam_close_session(char *user, char *tty, char *rhost)
00735 {
00736 pam_handle_t *pamh = NULL;
00737 struct pam_conv *pconv = NULL;
00738
00739
00740
00741 if (!lp_obey_pam_restrictions())
00742 return True;
00743
00744 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
00745 return False;
00746
00747 if (!smb_pam_start(&pamh, user, rhost, pconv))
00748 return False;
00749
00750 if (!smb_internal_pam_session(pamh, user, tty, False)) {
00751 smb_pam_end(pamh, pconv);
00752 return False;
00753 }
00754
00755 return smb_pam_end(pamh, pconv);
00756 }
00757
00758
00759
00760
00761
00762 NTSTATUS smb_pam_accountcheck(const char * user)
00763 {
00764 NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
00765 pam_handle_t *pamh = NULL;
00766 struct pam_conv *pconv = NULL;
00767
00768
00769
00770 if (!lp_obey_pam_restrictions())
00771 return NT_STATUS_OK;
00772
00773 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, NULL, NULL)) == NULL)
00774 return NT_STATUS_NO_MEMORY;
00775
00776 if (!smb_pam_start(&pamh, user, NULL, pconv))
00777 return NT_STATUS_ACCOUNT_DISABLED;
00778
00779 if (!NT_STATUS_IS_OK(nt_status = smb_pam_account(pamh, user)))
00780 DEBUG(0, ("smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s!\n", user));
00781
00782 smb_pam_end(pamh, pconv);
00783 return nt_status;
00784 }
00785
00786
00787
00788
00789
00790 NTSTATUS smb_pam_passcheck(const char * user, const char * password)
00791 {
00792 pam_handle_t *pamh = NULL;
00793 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
00794 struct pam_conv *pconv = NULL;
00795
00796
00797
00798
00799
00800
00801
00802 if ((pconv = smb_setup_pam_conv(smb_pam_conv, user, password, NULL)) == NULL)
00803 return NT_STATUS_LOGON_FAILURE;
00804
00805 if (!smb_pam_start(&pamh, user, NULL, pconv))
00806 return NT_STATUS_LOGON_FAILURE;
00807
00808 if (!NT_STATUS_IS_OK(nt_status = smb_pam_auth(pamh, user))) {
00809 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s !\n", user));
00810 smb_pam_end(pamh, pconv);
00811 return nt_status;
00812 }
00813
00814 if (!NT_STATUS_IS_OK(nt_status = smb_pam_account(pamh, user))) {
00815 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s !\n", user));
00816 smb_pam_end(pamh, pconv);
00817 return nt_status;
00818 }
00819
00820 if (!NT_STATUS_IS_OK(nt_status = smb_pam_setcred(pamh, user))) {
00821 DEBUG(0, ("smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s !\n", user));
00822 smb_pam_end(pamh, pconv);
00823 return nt_status;
00824 }
00825
00826 smb_pam_end(pamh, pconv);
00827 return nt_status;
00828 }
00829
00830
00831
00832
00833
00834 BOOL smb_pam_passchange(const char * user, const char * oldpassword, const char * newpassword)
00835 {
00836
00837 struct pam_conv *pconv = NULL;
00838 pam_handle_t *pamh = NULL;
00839
00840 if ((pconv = smb_setup_pam_conv(smb_pam_passchange_conv, user, oldpassword, newpassword)) == NULL)
00841 return False;
00842
00843 if(!smb_pam_start(&pamh, user, NULL, pconv))
00844 return False;
00845
00846 if (!smb_pam_chauthtok(pamh, user)) {
00847 DEBUG(0, ("smb_pam_passchange: PAM: Password Change Failed for user %s!\n", user));
00848 smb_pam_end(pamh, pconv);
00849 return False;
00850 }
00851
00852 return smb_pam_end(pamh, pconv);
00853 }
00854
00855 #else
00856
00857
00858 NTSTATUS smb_pam_accountcheck(const char * user)
00859 {
00860 return NT_STATUS_OK;
00861 }
00862
00863
00864 BOOL smb_pam_claim_session(char *user, char *tty, char *rhost)
00865 {
00866 return True;
00867 }
00868
00869
00870 BOOL smb_pam_close_session(char *in_user, char *tty, char *rhost)
00871 {
00872 return True;
00873 }
00874 #endif