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 #include "includes.h"
00026
00027 #undef DBGC_CLASS
00028 #define DBGC_CLASS DBGC_PASSDB
00029
00030
00031
00032
00033
00034
00035
00036
00037 #define PDB_NOT_QUITE_NULL ""
00038
00039
00040
00041
00042
00043 uint32 pdb_get_acct_ctrl(const struct samu *sampass)
00044 {
00045 return sampass->acct_ctrl;
00046 }
00047
00048 time_t pdb_get_logon_time(const struct samu *sampass)
00049 {
00050 return sampass->logon_time;
00051 }
00052
00053 time_t pdb_get_logoff_time(const struct samu *sampass)
00054 {
00055 return sampass->logoff_time;
00056 }
00057
00058 time_t pdb_get_kickoff_time(const struct samu *sampass)
00059 {
00060 return sampass->kickoff_time;
00061 }
00062
00063 time_t pdb_get_bad_password_time(const struct samu *sampass)
00064 {
00065 return sampass->bad_password_time;
00066 }
00067
00068 time_t pdb_get_pass_last_set_time(const struct samu *sampass)
00069 {
00070 return sampass->pass_last_set_time;
00071 }
00072
00073 time_t pdb_get_pass_can_change_time(const struct samu *sampass)
00074 {
00075 uint32 allow;
00076
00077
00078
00079
00080 if (sampass->pass_last_set_time == 0)
00081 return (time_t) 0;
00082
00083
00084
00085
00086
00087 if (sampass->pass_can_change_time == get_time_t_max() &&
00088 pdb_get_init_flags(sampass, PDB_CANCHANGETIME) == PDB_CHANGED)
00089 return sampass->pass_can_change_time;
00090
00091 if (!pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &allow))
00092 allow = 0;
00093
00094
00095 return sampass->pass_last_set_time + allow;
00096 }
00097
00098
00099
00100 time_t pdb_get_pass_can_change_time_noncalc(const struct samu *sampass)
00101 {
00102 return sampass->pass_can_change_time;
00103 }
00104
00105 time_t pdb_get_pass_must_change_time(const struct samu *sampass)
00106 {
00107 uint32 expire;
00108
00109 if (sampass->pass_last_set_time == 0)
00110 return (time_t) 0;
00111
00112 if (sampass->acct_ctrl & ACB_PWNOEXP)
00113 return get_time_t_max();
00114
00115 if (!pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &expire)
00116 || expire == (uint32)-1 || expire == 0)
00117 return get_time_t_max();
00118
00119 return sampass->pass_last_set_time + expire;
00120 }
00121
00122 BOOL pdb_get_pass_can_change(const struct samu *sampass)
00123 {
00124 if (sampass->pass_can_change_time == get_time_t_max() &&
00125 sampass->pass_last_set_time != 0)
00126 return False;
00127 return True;
00128 }
00129
00130 uint16 pdb_get_logon_divs(const struct samu *sampass)
00131 {
00132 return sampass->logon_divs;
00133 }
00134
00135 uint32 pdb_get_hours_len(const struct samu *sampass)
00136 {
00137 return sampass->hours_len;
00138 }
00139
00140 const uint8 *pdb_get_hours(const struct samu *sampass)
00141 {
00142 return (sampass->hours);
00143 }
00144
00145 const uint8 *pdb_get_nt_passwd(const struct samu *sampass)
00146 {
00147 SMB_ASSERT((!sampass->nt_pw.data)
00148 || sampass->nt_pw.length == NT_HASH_LEN);
00149 return (uint8 *)sampass->nt_pw.data;
00150 }
00151
00152 const uint8 *pdb_get_lanman_passwd(const struct samu *sampass)
00153 {
00154 SMB_ASSERT((!sampass->lm_pw.data)
00155 || sampass->lm_pw.length == LM_HASH_LEN);
00156 return (uint8 *)sampass->lm_pw.data;
00157 }
00158
00159 const uint8 *pdb_get_pw_history(const struct samu *sampass, uint32 *current_hist_len)
00160 {
00161 SMB_ASSERT((!sampass->nt_pw_his.data)
00162 || ((sampass->nt_pw_his.length % PW_HISTORY_ENTRY_LEN) == 0));
00163 *current_hist_len = sampass->nt_pw_his.length / PW_HISTORY_ENTRY_LEN;
00164 return (uint8 *)sampass->nt_pw_his.data;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 const char *pdb_get_plaintext_passwd(const struct samu *sampass)
00174 {
00175 return sampass->plaintext_pw;
00176 }
00177
00178 const DOM_SID *pdb_get_user_sid(const struct samu *sampass)
00179 {
00180 return &sampass->user_sid;
00181 }
00182
00183 const DOM_SID *pdb_get_group_sid(struct samu *sampass)
00184 {
00185 DOM_SID *gsid;
00186 struct passwd *pwd;
00187
00188
00189 if ( sampass->group_sid ) {
00190 return sampass->group_sid;
00191 }
00192
00193
00194
00195 if ( !(gsid = TALLOC_P( sampass, DOM_SID )) ) {
00196 return NULL;
00197 }
00198
00199
00200
00201
00202
00203
00204 if ( sampass->unix_pw ) {
00205 pwd = sampass->unix_pw;
00206 } else {
00207 pwd = Get_Pwnam_alloc( sampass, pdb_get_username(sampass) );
00208 }
00209
00210 if ( !pwd ) {
00211 DEBUG(0,("pdb_get_group_sid: Failed to find Unix account for %s\n", pdb_get_username(sampass) ));
00212 return NULL;
00213 }
00214
00215 if ( pdb_gid_to_sid(pwd->pw_gid, gsid) ) {
00216 enum lsa_SidType type = SID_NAME_UNKNOWN;
00217 TALLOC_CTX *mem_ctx = talloc_init("pdb_get_group_sid");
00218 BOOL lookup_ret;
00219
00220 if (!mem_ctx) {
00221 return NULL;
00222 }
00223
00224
00225
00226 lookup_ret = lookup_sid(mem_ctx, gsid, NULL, NULL, &type);
00227
00228 TALLOC_FREE( mem_ctx );
00229
00230 if ( lookup_ret && (type == SID_NAME_DOM_GRP) ) {
00231 sampass->group_sid = gsid;
00232 return sampass->group_sid;
00233 }
00234
00235 DEBUG(3, ("Primary group for user %s is a %s and not a domain group\n",
00236 pwd->pw_name, sid_type_lookup(type)));
00237 }
00238
00239
00240
00241
00242 sid_copy( gsid, get_global_sam_sid() );
00243 sid_append_rid( gsid, DOMAIN_GROUP_RID_USERS );
00244
00245 sampass->group_sid = gsid;
00246
00247 return sampass->group_sid;
00248 }
00249
00250
00251
00252
00253
00254
00255
00256 enum pdb_value_state pdb_get_init_flags(const struct samu *sampass, enum pdb_elements element)
00257 {
00258 enum pdb_value_state ret = PDB_DEFAULT;
00259
00260 if (!sampass->change_flags || !sampass->set_flags)
00261 return ret;
00262
00263 if (bitmap_query(sampass->set_flags, element)) {
00264 DEBUG(11, ("element %d: SET\n", element));
00265 ret = PDB_SET;
00266 }
00267
00268 if (bitmap_query(sampass->change_flags, element)) {
00269 DEBUG(11, ("element %d: CHANGED\n", element));
00270 ret = PDB_CHANGED;
00271 }
00272
00273 if (ret == PDB_DEFAULT) {
00274 DEBUG(11, ("element %d: DEFAULT\n", element));
00275 }
00276
00277 return ret;
00278 }
00279
00280 const char *pdb_get_username(const struct samu *sampass)
00281 {
00282 return sampass->username;
00283 }
00284
00285 const char *pdb_get_domain(const struct samu *sampass)
00286 {
00287 return sampass->domain;
00288 }
00289
00290 const char *pdb_get_nt_username(const struct samu *sampass)
00291 {
00292 return sampass->nt_username;
00293 }
00294
00295 const char *pdb_get_fullname(const struct samu *sampass)
00296 {
00297 return sampass->full_name;
00298 }
00299
00300 const char *pdb_get_homedir(const struct samu *sampass)
00301 {
00302 return sampass->home_dir;
00303 }
00304
00305 const char *pdb_get_unix_homedir(const struct samu *sampass)
00306 {
00307 if (sampass->unix_pw ) {
00308 return sampass->unix_pw->pw_dir;
00309 }
00310 return NULL;
00311 }
00312
00313 const char *pdb_get_dir_drive(const struct samu *sampass)
00314 {
00315 return sampass->dir_drive;
00316 }
00317
00318 const char *pdb_get_logon_script(const struct samu *sampass)
00319 {
00320 return sampass->logon_script;
00321 }
00322
00323 const char *pdb_get_profile_path(const struct samu *sampass)
00324 {
00325 return sampass->profile_path;
00326 }
00327
00328 const char *pdb_get_acct_desc(const struct samu *sampass)
00329 {
00330 return sampass->acct_desc;
00331 }
00332
00333 const char *pdb_get_workstations(const struct samu *sampass)
00334 {
00335 return sampass->workstations;
00336 }
00337
00338 const char *pdb_get_comment(const struct samu *sampass)
00339 {
00340 return sampass->comment;
00341 }
00342
00343 const char *pdb_get_munged_dial(const struct samu *sampass)
00344 {
00345 return sampass->munged_dial;
00346 }
00347
00348 uint16 pdb_get_bad_password_count(const struct samu *sampass)
00349 {
00350 return sampass->bad_password_count;
00351 }
00352
00353 uint16 pdb_get_logon_count(const struct samu *sampass)
00354 {
00355 return sampass->logon_count;
00356 }
00357
00358 uint32 pdb_get_unknown_6(const struct samu *sampass)
00359 {
00360 return sampass->unknown_6;
00361 }
00362
00363 void *pdb_get_backend_private_data(const struct samu *sampass, const struct pdb_methods *my_methods)
00364 {
00365 if (my_methods == sampass->backend_private_methods) {
00366 return sampass->backend_private_data;
00367 } else {
00368 return NULL;
00369 }
00370 }
00371
00372
00373
00374
00375
00376 BOOL pdb_set_acct_ctrl(struct samu *sampass, uint32 acct_ctrl, enum pdb_value_state flag)
00377 {
00378 sampass->acct_ctrl = acct_ctrl;
00379 return pdb_set_init_flags(sampass, PDB_ACCTCTRL, flag);
00380 }
00381
00382 BOOL pdb_set_logon_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00383 {
00384 sampass->logon_time = mytime;
00385 return pdb_set_init_flags(sampass, PDB_LOGONTIME, flag);
00386 }
00387
00388 BOOL pdb_set_logoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00389 {
00390 sampass->logoff_time = mytime;
00391 return pdb_set_init_flags(sampass, PDB_LOGOFFTIME, flag);
00392 }
00393
00394 BOOL pdb_set_kickoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00395 {
00396 sampass->kickoff_time = mytime;
00397 return pdb_set_init_flags(sampass, PDB_KICKOFFTIME, flag);
00398 }
00399
00400 BOOL pdb_set_bad_password_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00401 {
00402 sampass->bad_password_time = mytime;
00403 return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_TIME, flag);
00404 }
00405
00406 BOOL pdb_set_pass_can_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00407 {
00408 sampass->pass_can_change_time = mytime;
00409 return pdb_set_init_flags(sampass, PDB_CANCHANGETIME, flag);
00410 }
00411
00412 BOOL pdb_set_pass_must_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00413 {
00414 sampass->pass_must_change_time = mytime;
00415 return pdb_set_init_flags(sampass, PDB_MUSTCHANGETIME, flag);
00416 }
00417
00418 BOOL pdb_set_pass_last_set_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag)
00419 {
00420 sampass->pass_last_set_time = mytime;
00421 return pdb_set_init_flags(sampass, PDB_PASSLASTSET, flag);
00422 }
00423
00424 BOOL pdb_set_hours_len(struct samu *sampass, uint32 len, enum pdb_value_state flag)
00425 {
00426 sampass->hours_len = len;
00427 return pdb_set_init_flags(sampass, PDB_HOURSLEN, flag);
00428 }
00429
00430 BOOL pdb_set_logon_divs(struct samu *sampass, uint16 hours, enum pdb_value_state flag)
00431 {
00432 sampass->logon_divs = hours;
00433 return pdb_set_init_flags(sampass, PDB_LOGONDIVS, flag);
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
00443 BOOL pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pdb_value_state value_flag)
00444 {
00445 if (!sampass->set_flags) {
00446 if ((sampass->set_flags =
00447 bitmap_talloc(sampass,
00448 PDB_COUNT))==NULL) {
00449 DEBUG(0,("bitmap_talloc failed\n"));
00450 return False;
00451 }
00452 }
00453 if (!sampass->change_flags) {
00454 if ((sampass->change_flags =
00455 bitmap_talloc(sampass,
00456 PDB_COUNT))==NULL) {
00457 DEBUG(0,("bitmap_talloc failed\n"));
00458 return False;
00459 }
00460 }
00461
00462 switch(value_flag) {
00463 case PDB_CHANGED:
00464 if (!bitmap_set(sampass->change_flags, element)) {
00465 DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
00466 return False;
00467 }
00468 if (!bitmap_set(sampass->set_flags, element)) {
00469 DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
00470 return False;
00471 }
00472 DEBUG(11, ("element %d -> now CHANGED\n", element));
00473 break;
00474 case PDB_SET:
00475 if (!bitmap_clear(sampass->change_flags, element)) {
00476 DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
00477 return False;
00478 }
00479 if (!bitmap_set(sampass->set_flags, element)) {
00480 DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
00481 return False;
00482 }
00483 DEBUG(11, ("element %d -> now SET\n", element));
00484 break;
00485 case PDB_DEFAULT:
00486 default:
00487 if (!bitmap_clear(sampass->change_flags, element)) {
00488 DEBUG(0,("Can't set flag: %d in change_flags.\n",element));
00489 return False;
00490 }
00491 if (!bitmap_clear(sampass->set_flags, element)) {
00492 DEBUG(0,("Can't set flag: %d in set_flags.\n",element));
00493 return False;
00494 }
00495 DEBUG(11, ("element %d -> now DEFAULT\n", element));
00496 break;
00497 }
00498
00499 return True;
00500 }
00501
00502 BOOL pdb_set_user_sid(struct samu *sampass, const DOM_SID *u_sid, enum pdb_value_state flag)
00503 {
00504 if (!u_sid)
00505 return False;
00506
00507 sid_copy(&sampass->user_sid, u_sid);
00508
00509 DEBUG(10, ("pdb_set_user_sid: setting user sid %s\n",
00510 sid_string_static(&sampass->user_sid)));
00511
00512 return pdb_set_init_flags(sampass, PDB_USERSID, flag);
00513 }
00514
00515 BOOL pdb_set_user_sid_from_string(struct samu *sampass, fstring u_sid, enum pdb_value_state flag)
00516 {
00517 DOM_SID new_sid;
00518
00519 if (!u_sid)
00520 return False;
00521
00522 DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
00523 u_sid));
00524
00525 if (!string_to_sid(&new_sid, u_sid)) {
00526 DEBUG(1, ("pdb_set_user_sid_from_string: %s isn't a valid SID!\n", u_sid));
00527 return False;
00528 }
00529
00530 if (!pdb_set_user_sid(sampass, &new_sid, flag)) {
00531 DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on struct samu!\n", u_sid));
00532 return False;
00533 }
00534
00535 return True;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 BOOL pdb_set_group_sid(struct samu *sampass, const DOM_SID *g_sid, enum pdb_value_state flag)
00547 {
00548 gid_t gid;
00549
00550 if (!g_sid)
00551 return False;
00552
00553 if ( !(sampass->group_sid = TALLOC_P( sampass, DOM_SID )) ) {
00554 return False;
00555 }
00556
00557
00558
00559
00560 if ( sid_to_gid( g_sid, &gid ) ) {
00561 sid_copy(sampass->group_sid, g_sid);
00562 } else {
00563 sid_copy( sampass->group_sid, get_global_sam_sid() );
00564 sid_append_rid( sampass->group_sid, DOMAIN_GROUP_RID_USERS );
00565 }
00566
00567 DEBUG(10, ("pdb_set_group_sid: setting group sid %s\n",
00568 sid_string_static(sampass->group_sid)));
00569
00570 return pdb_set_init_flags(sampass, PDB_GROUPSID, flag);
00571 }
00572
00573
00574
00575
00576
00577 BOOL pdb_set_username(struct samu *sampass, const char *username, enum pdb_value_state flag)
00578 {
00579 if (username) {
00580 DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", username,
00581 (sampass->username)?(sampass->username):"NULL"));
00582
00583 sampass->username = talloc_strdup(sampass, username);
00584
00585 if (!sampass->username) {
00586 DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
00587 return False;
00588 }
00589 } else {
00590 sampass->username = PDB_NOT_QUITE_NULL;
00591 }
00592
00593 return pdb_set_init_flags(sampass, PDB_USERNAME, flag);
00594 }
00595
00596
00597
00598
00599
00600 BOOL pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_state flag)
00601 {
00602 if (domain) {
00603 DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", domain,
00604 (sampass->domain)?(sampass->domain):"NULL"));
00605
00606 sampass->domain = talloc_strdup(sampass, domain);
00607
00608 if (!sampass->domain) {
00609 DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
00610 return False;
00611 }
00612 } else {
00613 sampass->domain = PDB_NOT_QUITE_NULL;
00614 }
00615
00616 return pdb_set_init_flags(sampass, PDB_DOMAIN, flag);
00617 }
00618
00619
00620
00621
00622
00623 BOOL pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb_value_state flag)
00624 {
00625 if (nt_username) {
00626 DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", nt_username,
00627 (sampass->nt_username)?(sampass->nt_username):"NULL"));
00628
00629 sampass->nt_username = talloc_strdup(sampass, nt_username);
00630
00631 if (!sampass->nt_username) {
00632 DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
00633 return False;
00634 }
00635 } else {
00636 sampass->nt_username = PDB_NOT_QUITE_NULL;
00637 }
00638
00639 return pdb_set_init_flags(sampass, PDB_NTUSERNAME, flag);
00640 }
00641
00642
00643
00644
00645
00646 BOOL pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_value_state flag)
00647 {
00648 if (full_name) {
00649 DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", full_name,
00650 (sampass->full_name)?(sampass->full_name):"NULL"));
00651
00652 sampass->full_name = talloc_strdup(sampass, full_name);
00653
00654 if (!sampass->full_name) {
00655 DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
00656 return False;
00657 }
00658 } else {
00659 sampass->full_name = PDB_NOT_QUITE_NULL;
00660 }
00661
00662 return pdb_set_init_flags(sampass, PDB_FULLNAME, flag);
00663 }
00664
00665
00666
00667
00668
00669 BOOL pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum pdb_value_state flag)
00670 {
00671 if (logon_script) {
00672 DEBUG(10, ("pdb_set_logon_script: setting logon script %s, was %s\n", logon_script,
00673 (sampass->logon_script)?(sampass->logon_script):"NULL"));
00674
00675 sampass->logon_script = talloc_strdup(sampass, logon_script);
00676
00677 if (!sampass->logon_script) {
00678 DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
00679 return False;
00680 }
00681 } else {
00682 sampass->logon_script = PDB_NOT_QUITE_NULL;
00683 }
00684
00685 return pdb_set_init_flags(sampass, PDB_LOGONSCRIPT, flag);
00686 }
00687
00688
00689
00690
00691
00692 BOOL pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum pdb_value_state flag)
00693 {
00694 if (profile_path) {
00695 DEBUG(10, ("pdb_set_profile_path: setting profile path %s, was %s\n", profile_path,
00696 (sampass->profile_path)?(sampass->profile_path):"NULL"));
00697
00698 sampass->profile_path = talloc_strdup(sampass, profile_path);
00699
00700 if (!sampass->profile_path) {
00701 DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
00702 return False;
00703 }
00704 } else {
00705 sampass->profile_path = PDB_NOT_QUITE_NULL;
00706 }
00707
00708 return pdb_set_init_flags(sampass, PDB_PROFILE, flag);
00709 }
00710
00711
00712
00713
00714
00715 BOOL pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_value_state flag)
00716 {
00717 if (dir_drive) {
00718 DEBUG(10, ("pdb_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
00719 (sampass->dir_drive)?(sampass->dir_drive):"NULL"));
00720
00721 sampass->dir_drive = talloc_strdup(sampass, dir_drive);
00722
00723 if (!sampass->dir_drive) {
00724 DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
00725 return False;
00726 }
00727
00728 } else {
00729 sampass->dir_drive = PDB_NOT_QUITE_NULL;
00730 }
00731
00732 return pdb_set_init_flags(sampass, PDB_DRIVE, flag);
00733 }
00734
00735
00736
00737
00738
00739 BOOL pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_state flag)
00740 {
00741 if (home_dir) {
00742 DEBUG(10, ("pdb_set_homedir: setting home dir %s, was %s\n", home_dir,
00743 (sampass->home_dir)?(sampass->home_dir):"NULL"));
00744
00745 sampass->home_dir = talloc_strdup(sampass, home_dir);
00746
00747 if (!sampass->home_dir) {
00748 DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
00749 return False;
00750 }
00751 } else {
00752 sampass->home_dir = PDB_NOT_QUITE_NULL;
00753 }
00754
00755 return pdb_set_init_flags(sampass, PDB_SMBHOME, flag);
00756 }
00757
00758
00759
00760
00761
00762 BOOL pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_value_state flag)
00763 {
00764 if (acct_desc) {
00765 sampass->acct_desc = talloc_strdup(sampass, acct_desc);
00766
00767 if (!sampass->acct_desc) {
00768 DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
00769 return False;
00770 }
00771 } else {
00772 sampass->acct_desc = PDB_NOT_QUITE_NULL;
00773 }
00774
00775 return pdb_set_init_flags(sampass, PDB_ACCTDESC, flag);
00776 }
00777
00778
00779
00780
00781
00782 BOOL pdb_set_workstations(struct samu *sampass, const char *workstations, enum pdb_value_state flag)
00783 {
00784 if (workstations) {
00785 DEBUG(10, ("pdb_set_workstations: setting workstations %s, was %s\n", workstations,
00786 (sampass->workstations)?(sampass->workstations):"NULL"));
00787
00788 sampass->workstations = talloc_strdup(sampass, workstations);
00789
00790 if (!sampass->workstations) {
00791 DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
00792 return False;
00793 }
00794 } else {
00795 sampass->workstations = PDB_NOT_QUITE_NULL;
00796 }
00797
00798 return pdb_set_init_flags(sampass, PDB_WORKSTATIONS, flag);
00799 }
00800
00801
00802
00803
00804 BOOL pdb_set_comment(struct samu *sampass, const char *comment, enum pdb_value_state flag)
00805 {
00806 if (comment) {
00807 sampass->comment = talloc_strdup(sampass, comment);
00808
00809 if (!sampass->comment) {
00810 DEBUG(0, ("pdb_set_comment: talloc_strdup() failed!\n"));
00811 return False;
00812 }
00813 } else {
00814 sampass->comment = PDB_NOT_QUITE_NULL;
00815 }
00816
00817 return pdb_set_init_flags(sampass, PDB_COMMENT, flag);
00818 }
00819
00820
00821
00822
00823
00824 BOOL pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb_value_state flag)
00825 {
00826 if (munged_dial) {
00827 sampass->munged_dial = talloc_strdup(sampass, munged_dial);
00828
00829 if (!sampass->munged_dial) {
00830 DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
00831 return False;
00832 }
00833 } else {
00834 sampass->munged_dial = PDB_NOT_QUITE_NULL;
00835 }
00836
00837 return pdb_set_init_flags(sampass, PDB_MUNGEDDIAL, flag);
00838 }
00839
00840
00841
00842
00843
00844 BOOL pdb_set_nt_passwd(struct samu *sampass, const uint8 pwd[NT_HASH_LEN], enum pdb_value_state flag)
00845 {
00846 data_blob_clear_free(&sampass->nt_pw);
00847
00848 if (pwd) {
00849 sampass->nt_pw =
00850 data_blob_talloc(sampass, pwd, NT_HASH_LEN);
00851 } else {
00852 sampass->nt_pw = data_blob(NULL, 0);
00853 }
00854
00855 return pdb_set_init_flags(sampass, PDB_NTPASSWD, flag);
00856 }
00857
00858
00859
00860
00861
00862 BOOL pdb_set_lanman_passwd(struct samu *sampass, const uint8 pwd[LM_HASH_LEN], enum pdb_value_state flag)
00863 {
00864 data_blob_clear_free(&sampass->lm_pw);
00865
00866
00867
00868 if (pwd && lp_lanman_auth() ) {
00869 sampass->lm_pw = data_blob_talloc(sampass, pwd, LM_HASH_LEN);
00870 } else {
00871 sampass->lm_pw = data_blob(NULL, 0);
00872 }
00873
00874 return pdb_set_init_flags(sampass, PDB_LMPASSWD, flag);
00875 }
00876
00877
00878
00879
00880
00881
00882
00883
00884 BOOL pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32 historyLen, enum pdb_value_state flag)
00885 {
00886 if (historyLen && pwd){
00887 sampass->nt_pw_his = data_blob_talloc(sampass,
00888 pwd, historyLen*PW_HISTORY_ENTRY_LEN);
00889 if (!sampass->nt_pw_his.length) {
00890 DEBUG(0, ("pdb_set_pw_history: data_blob_talloc() failed!\n"));
00891 return False;
00892 }
00893 } else {
00894 sampass->nt_pw_his = data_blob_talloc(sampass, NULL, 0);
00895 }
00896
00897 return pdb_set_init_flags(sampass, PDB_PWHISTORY, flag);
00898 }
00899
00900
00901
00902
00903
00904
00905 BOOL pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum pdb_value_state flag)
00906 {
00907 if (password) {
00908 if (sampass->plaintext_pw!=NULL)
00909 memset(sampass->plaintext_pw,'\0',strlen(sampass->plaintext_pw)+1);
00910
00911 sampass->plaintext_pw = talloc_strdup(sampass, password);
00912
00913 if (!sampass->plaintext_pw) {
00914 DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
00915 return False;
00916 }
00917 } else {
00918 sampass->plaintext_pw = NULL;
00919 }
00920
00921 return pdb_set_init_flags(sampass, PDB_PLAINTEXT_PW, flag);
00922 }
00923
00924 BOOL pdb_set_bad_password_count(struct samu *sampass, uint16 bad_password_count, enum pdb_value_state flag)
00925 {
00926 sampass->bad_password_count = bad_password_count;
00927 return pdb_set_init_flags(sampass, PDB_BAD_PASSWORD_COUNT, flag);
00928 }
00929
00930 BOOL pdb_set_logon_count(struct samu *sampass, uint16 logon_count, enum pdb_value_state flag)
00931 {
00932 sampass->logon_count = logon_count;
00933 return pdb_set_init_flags(sampass, PDB_LOGON_COUNT, flag);
00934 }
00935
00936 BOOL pdb_set_unknown_6(struct samu *sampass, uint32 unkn, enum pdb_value_state flag)
00937 {
00938 sampass->unknown_6 = unkn;
00939 return pdb_set_init_flags(sampass, PDB_UNKNOWN6, flag);
00940 }
00941
00942 BOOL pdb_set_hours(struct samu *sampass, const uint8 *hours, enum pdb_value_state flag)
00943 {
00944 if (!hours) {
00945 memset ((char *)sampass->hours, 0, MAX_HOURS_LEN);
00946 } else {
00947 memcpy (sampass->hours, hours, MAX_HOURS_LEN);
00948 }
00949
00950 return pdb_set_init_flags(sampass, PDB_HOURS, flag);
00951 }
00952
00953 BOOL pdb_set_backend_private_data(struct samu *sampass, void *private_data,
00954 void (*free_fn)(void **),
00955 const struct pdb_methods *my_methods,
00956 enum pdb_value_state flag)
00957 {
00958 if (sampass->backend_private_data &&
00959 sampass->backend_private_data_free_fn) {
00960 sampass->backend_private_data_free_fn(
00961 &sampass->backend_private_data);
00962 }
00963
00964 sampass->backend_private_data = private_data;
00965 sampass->backend_private_data_free_fn = free_fn;
00966 sampass->backend_private_methods = my_methods;
00967
00968 return pdb_set_init_flags(sampass, PDB_BACKEND_PRIVATE_DATA, flag);
00969 }
00970
00971
00972
00973
00974 BOOL pdb_set_pass_can_change(struct samu *sampass, BOOL canchange)
00975 {
00976 return pdb_set_pass_can_change_time(sampass,
00977 canchange ? 0 : get_time_t_max(),
00978 PDB_CHANGED);
00979 }
00980
00981
00982
00983
00984
00985
00986
00987 BOOL pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext)
00988 {
00989 uchar new_lanman_p16[LM_HASH_LEN];
00990 uchar new_nt_p16[NT_HASH_LEN];
00991
00992 if (!plaintext)
00993 return False;
00994
00995
00996 E_md4hash(plaintext, new_nt_p16);
00997
00998 if (!pdb_set_nt_passwd (sampass, new_nt_p16, PDB_CHANGED))
00999 return False;
01000
01001 if (!E_deshash(plaintext, new_lanman_p16)) {
01002
01003
01004
01005
01006
01007 if (!pdb_set_lanman_passwd (sampass, NULL, PDB_CHANGED))
01008 return False;
01009 } else {
01010 if (!pdb_set_lanman_passwd (sampass, new_lanman_p16, PDB_CHANGED))
01011 return False;
01012 }
01013
01014 if (!pdb_set_plaintext_pw_only (sampass, plaintext, PDB_CHANGED))
01015 return False;
01016
01017 if (!pdb_set_pass_last_set_time (sampass, time(NULL), PDB_CHANGED))
01018 return False;
01019
01020
01021 if (pdb_get_acct_ctrl(sampass) & ACB_NORMAL) {
01022 uchar *pwhistory;
01023 uint32 pwHistLen;
01024 pdb_get_account_policy(AP_PASSWORD_HISTORY, &pwHistLen);
01025 if (pwHistLen != 0){
01026 uint32 current_history_len;
01027
01028
01029
01030 pwhistory = (uchar *)pdb_get_pw_history(sampass, ¤t_history_len);
01031
01032 if (current_history_len != pwHistLen) {
01033
01034
01035
01036
01037
01038
01039 if (current_history_len < pwHistLen) {
01040
01041 uchar *new_history = (uchar *)TALLOC(sampass,
01042 pwHistLen*PW_HISTORY_ENTRY_LEN);
01043 if (!new_history) {
01044 return False;
01045 }
01046
01047
01048 if (current_history_len) {
01049 memcpy(new_history, pwhistory,
01050 current_history_len*PW_HISTORY_ENTRY_LEN);
01051 }
01052
01053 memset(&new_history[current_history_len*PW_HISTORY_ENTRY_LEN],
01054 '\0', (pwHistLen-current_history_len)*PW_HISTORY_ENTRY_LEN);
01055
01056 pwhistory = new_history;
01057 }
01058 }
01059 if (pwhistory && pwHistLen){
01060
01061 if (pwHistLen > 1) {
01062 memmove(&pwhistory[PW_HISTORY_ENTRY_LEN],
01063 pwhistory, (pwHistLen -1)*PW_HISTORY_ENTRY_LEN );
01064 }
01065
01066 generate_random_buffer(pwhistory, PW_HISTORY_SALT_LEN);
01067
01068
01069
01070
01071 E_md5hash(pwhistory, new_nt_p16, &pwhistory[PW_HISTORY_SALT_LEN]);
01072 pdb_set_pw_history(sampass, pwhistory, pwHistLen, PDB_CHANGED);
01073 } else {
01074 DEBUG (10,("pdb_get_set.c: pdb_set_plaintext_passwd: pwhistory was NULL!\n"));
01075 }
01076 } else {
01077
01078 pdb_set_pw_history(sampass, NULL, 0, PDB_CHANGED);
01079 }
01080 }
01081
01082 return True;
01083 }
01084
01085
01086 uint32 pdb_build_fields_present(struct samu *sampass)
01087 {
01088
01089 return 0x00ffffff;
01090 }