📄 passdb.c
字号:
else { pdb_set_homedir(sampass, talloc_sub_basic(sampass->mem_ctx, username, lp_logon_home()), PDB_DEFAULT); } if (dir_drive) pdb_set_dir_drive(sampass, dir_drive, PDB_SET); else pdb_set_dir_drive(sampass, lp_logon_drive(), PDB_DEFAULT ); if (logon_script) { fstrcpy( tmpstring, logon_script ); if (expand_explicit) { standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); } pdb_set_logon_script(sampass, tmpstring, PDB_SET); } else { pdb_set_logon_script(sampass, talloc_sub_basic(sampass->mem_ctx, username, lp_logon_script()), PDB_DEFAULT); } if (profile_path) { fstrcpy( tmpstring, profile_path ); if (expand_explicit) { standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); } pdb_set_profile_path(sampass, tmpstring, PDB_SET); } else { pdb_set_profile_path(sampass, talloc_sub_basic(sampass->mem_ctx, username, lp_logon_path()), PDB_DEFAULT); } pdb_set_acct_desc(sampass, acct_desc, PDB_SET); pdb_set_workstations(sampass, workstations, PDB_SET); pdb_set_munged_dial(sampass, munged_dial, PDB_SET); if (lm_pw_ptr && lm_pw_len == LM_HASH_LEN) { if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr, PDB_SET)) { ret = False; goto done; } } if (nt_pw_ptr && nt_pw_len == NT_HASH_LEN) { if (!pdb_set_nt_passwd(sampass, nt_pw_ptr, PDB_SET)) { ret = False; goto done; } } /* Change from V1 is addition of password history field. */ pdb_get_account_policy(AP_PASSWORD_HISTORY, &pwHistLen); if (pwHistLen) { uint8 *pw_hist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN); if (!pw_hist) { ret = False; goto done; } memset(pw_hist, '\0', pwHistLen * PW_HISTORY_ENTRY_LEN); if (nt_pw_hist_ptr && nt_pw_hist_len) { int i; SMB_ASSERT((nt_pw_hist_len % PW_HISTORY_ENTRY_LEN) == 0); nt_pw_hist_len /= PW_HISTORY_ENTRY_LEN; for (i = 0; (i < pwHistLen) && (i < nt_pw_hist_len); i++) { memcpy(&pw_hist[i*PW_HISTORY_ENTRY_LEN], &nt_pw_hist_ptr[i*PW_HISTORY_ENTRY_LEN], PW_HISTORY_ENTRY_LEN); } } if (!pdb_set_pw_history(sampass, pw_hist, pwHistLen, PDB_SET)) { SAFE_FREE(pw_hist); ret = False; goto done; } SAFE_FREE(pw_hist); } else { pdb_set_pw_history(sampass, NULL, 0, PDB_SET); } pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET); pdb_set_group_sid_from_rid(sampass, group_rid, PDB_SET); pdb_set_hours_len(sampass, hours_len, PDB_SET); pdb_set_bad_password_count(sampass, bad_password_count, PDB_SET); pdb_set_logon_count(sampass, logon_count, PDB_SET); pdb_set_unknown_6(sampass, unknown_6, PDB_SET); pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET); pdb_set_logon_divs(sampass, logon_divs, PDB_SET); pdb_set_hours(sampass, hours, PDB_SET);done: SAFE_FREE(username); SAFE_FREE(domain); SAFE_FREE(nt_username); SAFE_FREE(fullname); SAFE_FREE(homedir); SAFE_FREE(dir_drive); SAFE_FREE(logon_script); SAFE_FREE(profile_path); SAFE_FREE(acct_desc); SAFE_FREE(workstations); SAFE_FREE(munged_dial); SAFE_FREE(unknown_str); SAFE_FREE(lm_pw_ptr); SAFE_FREE(nt_pw_ptr); SAFE_FREE(nt_pw_hist_ptr); SAFE_FREE(hours); return ret;}uint32 init_buffer_from_sam_v2 (uint8 **buf, const SAM_ACCOUNT *sampass, BOOL size_only){ size_t len, buflen; /* times are stored as 32bit integer take care on system with 64bit wide time_t --SSS */ uint32 logon_time, logoff_time, kickoff_time, bad_password_time, pass_last_set_time, pass_can_change_time, pass_must_change_time; uint32 user_rid, group_rid; const char *username; const char *domain; const char *nt_username; const char *dir_drive; const char *unknown_str; const char *munged_dial; const char *fullname; const char *homedir; const char *logon_script; const char *profile_path; const char *acct_desc; const char *workstations; uint32 username_len, domain_len, nt_username_len, dir_drive_len, unknown_str_len, munged_dial_len, fullname_len, homedir_len, logon_script_len, profile_path_len, acct_desc_len, workstations_len; const uint8 *lm_pw; const uint8 *nt_pw; const uint8 *nt_pw_hist; uint32 lm_pw_len = 16; uint32 nt_pw_len = 16; uint32 nt_pw_hist_len; uint32 pwHistLen = 0; /* do we have a valid SAM_ACCOUNT pointer? */ if (sampass == NULL) { DEBUG(0, ("init_buffer_from_sam: SAM_ACCOUNT is NULL!\n")); return -1; } *buf = NULL; buflen = 0; logon_time = (uint32)pdb_get_logon_time(sampass); logoff_time = (uint32)pdb_get_logoff_time(sampass); kickoff_time = (uint32)pdb_get_kickoff_time(sampass); bad_password_time = (uint32)pdb_get_bad_password_time(sampass); pass_can_change_time = (uint32)pdb_get_pass_can_change_time(sampass); pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass); pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass); user_rid = pdb_get_user_rid(sampass); group_rid = pdb_get_group_rid(sampass); username = pdb_get_username(sampass); if (username) { username_len = strlen(username) +1; } else { username_len = 0; } domain = pdb_get_domain(sampass); if (domain) { domain_len = strlen(domain) +1; } else { domain_len = 0; } nt_username = pdb_get_nt_username(sampass); if (nt_username) { nt_username_len = strlen(nt_username) +1; } else { nt_username_len = 0; } fullname = pdb_get_fullname(sampass); if (fullname) { fullname_len = strlen(fullname) +1; } else { fullname_len = 0; } /* * Only updates fields which have been set (not defaults from smb.conf) */ if (!IS_SAM_DEFAULT(sampass, PDB_DRIVE)) { dir_drive = pdb_get_dir_drive(sampass); } else { dir_drive = NULL; } if (dir_drive) { dir_drive_len = strlen(dir_drive) +1; } else { dir_drive_len = 0; } if (!IS_SAM_DEFAULT(sampass, PDB_SMBHOME)) { homedir = pdb_get_homedir(sampass); } else { homedir = NULL; } if (homedir) { homedir_len = strlen(homedir) +1; } else { homedir_len = 0; } if (!IS_SAM_DEFAULT(sampass, PDB_LOGONSCRIPT)) { logon_script = pdb_get_logon_script(sampass); } else { logon_script = NULL; } if (logon_script) { logon_script_len = strlen(logon_script) +1; } else { logon_script_len = 0; } if (!IS_SAM_DEFAULT(sampass, PDB_PROFILE)) { profile_path = pdb_get_profile_path(sampass); } else { profile_path = NULL; } if (profile_path) { profile_path_len = strlen(profile_path) +1; } else { profile_path_len = 0; } lm_pw = pdb_get_lanman_passwd(sampass); if (!lm_pw) { lm_pw_len = 0; } nt_pw = pdb_get_nt_passwd(sampass); if (!nt_pw) { nt_pw_len = 0; } pdb_get_account_policy(AP_PASSWORD_HISTORY, &pwHistLen); nt_pw_hist = pdb_get_pw_history(sampass, &nt_pw_hist_len); if (pwHistLen && nt_pw_hist && nt_pw_hist_len) { nt_pw_hist_len *= PW_HISTORY_ENTRY_LEN; } else { nt_pw_hist_len = 0; } acct_desc = pdb_get_acct_desc(sampass); if (acct_desc) { acct_desc_len = strlen(acct_desc) +1; } else { acct_desc_len = 0; } workstations = pdb_get_workstations(sampass); if (workstations) { workstations_len = strlen(workstations) +1; } else { workstations_len = 0; } unknown_str = NULL; unknown_str_len = 0; munged_dial = pdb_get_munged_dial(sampass); if (munged_dial) { munged_dial_len = strlen(munged_dial) +1; } else { munged_dial_len = 0; }/* TDB_FORMAT_STRING_V2 "dddddddBBBBBBBBBBBBddBBBwwdBwwd" */ /* one time to get the size needed */ len = tdb_pack(NULL, 0, TDB_FORMAT_STRING_V2, logon_time, /* d */ logoff_time, /* d */ kickoff_time, /* d */ bad_password_time, /* d */ pass_last_set_time, /* d */ pass_can_change_time, /* d */ pass_must_change_time, /* d */ username_len, username, /* B */ domain_len, domain, /* B */ nt_username_len, nt_username, /* B */ fullname_len, fullname, /* B */ homedir_len, homedir, /* B */ dir_drive_len, dir_drive, /* B */ logon_script_len, logon_script, /* B */ profile_path_len, profile_path, /* B */ acct_desc_len, acct_desc, /* B */ workstations_len, workstations, /* B */ unknown_str_len, unknown_str, /* B */ munged_dial_len, munged_dial, /* B */ user_rid, /* d */ group_rid, /* d */ lm_pw_len, lm_pw, /* B */ nt_pw_len, nt_pw, /* B */ nt_pw_hist_len, nt_pw_hist, /* B */ pdb_get_acct_ctrl(sampass), /* w */ pdb_get_logon_divs(sampass), /* w */ pdb_get_hours_len(sampass), /* d */ MAX_HOURS_LEN, pdb_get_hours(sampass), /* B */ pdb_get_bad_password_count(sampass), /* w */ pdb_get_logon_count(sampass), /* w */ pdb_get_unknown_6(sampass)); /* d */ if (size_only) { return buflen; } /* malloc the space needed */ if ( (*buf=(uint8*)SMB_MALLOC(len)) == NULL) { DEBUG(0,("init_buffer_from_sam_v2: Unable to malloc() memory for buffer!\n")); return (-1); } /* now for the real call to tdb_pack() */ buflen = tdb_pack((char *)*buf, len, TDB_FORMAT_STRING_V2, logon_time, /* d */ logoff_time, /* d */ kickoff_time, /* d */ bad_password_time, /* d */ pass_last_set_time, /* d */ pass_can_change_time, /* d */ pass_must_change_time, /* d */ username_len, username, /* B */ domain_len, domain, /* B */ nt_username_len, nt_username, /* B */ fullname_len, fullname, /* B */ homedir_len, homedir, /* B */ dir_drive_len, dir_drive, /* B */ logon_script_len, logon_script, /* B */ profile_path_len, profile_path, /* B */ acct_desc_len, acct_desc, /* B */ workstations_len, workstations, /* B */ unknown_str_len, unknown_str, /* B */ munged_dial_len, munged_dial, /* B */ user_rid, /* d */ group_rid, /* d */ lm_pw_len, lm_pw, /* B */ nt_pw_len, nt_pw, /* B */ nt_pw_hist_len, nt_pw_hist, /* B */ pdb_get_acct_ctrl(sampass), /* w */ pdb_get_logon_divs(sampass), /* w */ pdb_get_hours_len(sampass), /* d */ MAX_HOURS_LEN, pdb_get_hours(sampass), /* B */ pdb_get_bad_password_count(sampass), /* w */ pdb_get_logon_count(sampass), /* w */ pdb_get_unknown_6(sampass)); /* d */ /* check to make sure we got it correct */ if (buflen != len) { DEBUG(0, ("init_buffer_from_sam_v2: somthing odd is going on here: bufflen (%lu) != len (%lu) in tdb_pack operations!\n", (unsigned long)buflen, (unsigned long)len)); /* error */ SAFE_FREE (*buf); return (-1); } return (buflen);}BOOL pdb_copy_sam_account(const SAM_ACCOUNT *src, SAM_ACCOUNT **dst){ BOOL result; uint8 *buf; int len; if ((*dst == NULL) && (!NT_STATUS_IS_OK(pdb_init_sam(dst)))) return False; len = init_buffer_from_sam_v2(&buf, src, False); if (len == -1) return False; result = init_sam_from_buffer_v2(*dst, buf, len); (*dst)->methods = src->methods; free(buf); return result;}/********************************************************************************************************************************************/static BOOL get_free_ugid_range(uint32 *low, uint32 *high){ uid_t u_low, u_high; gid_t g_low, g_high; if (!lp_idmap_uid(&u_low, &u_high) || !lp_idmap_gid(&g_low, &g_high)) { return False; } *low = (u_low < g_low) ? u_low : g_low; *high = (u_high < g_high) ? u_high : g_high; return True;}/****************************************************************** Get the the non-algorithmic RID range if idmap range are defined******************************************************************/BOOL get_free_rid_range(uint32 *low, uint32 *high){ uint32 id_low, id_high; if (!lp_enable_rid_algorithm()) { *low = BASE_RID; *high = (uint32)-1; } if (!get_free_ugid_range(&id_low, &id_high)) { return False; } *low = algorithmic_pdb_uid_to_user_rid(id_low); if (algorithmic_pdb_user_rid_to_uid((uint32)-1) < id_high) { *high = (uint32)-1; } else { *high = algorithmic_pdb_uid_to_user_rid(id_high);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -