parse_net.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 2,161 行 · 第 1/5 页
C
2,161 行
if (UNMARSHALLING(ps)) { ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1); if (ctr == NULL) return False; } if (ctr == NULL) return False; /* don't 4-byte align here! */ if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value)) return False; switch (ctr->switch_value) { case 1: if(!net_io_id_info1("", &ctr->auth.id1, ps, depth)) return False; break; case 2: if(!net_io_id_info2("", &ctr->auth.id2, ps, depth)) return False; break; default: /* PANIC! */ DEBUG(4,("smb_io_sam_info: unknown switch_value!\n")); break; } return True;}/******************************************************************* Reads or writes a DOM_SAM_INFO structure. ********************************************************************/static BOOL smb_io_sam_info(const char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth){ if (sam == NULL) return False; prs_debug(ps, depth, desc, "smb_io_sam_info"); depth++; if(!prs_align(ps)) return False; if(!smb_io_clnt_info2("", &sam->client, ps, depth)) return False; if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred)) return False; if(!smb_io_cred("", &sam->rtn_cred, ps, depth)) return False; if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level)) return False; if (sam->logon_level != 0) { if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth)) return False; } return True;}/************************************************************************* Inits a NET_USER_INFO_3 structure. This is a network logon reply packet, and contains much information about the user. This information is passed as a (very long) paramater list to avoid having to link in the PASSDB code to every program that deals with this file. *************************************************************************/void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr, uint32 user_rid, uint32 group_rid, const char* user_name, const char* full_name, const char* home_dir, const char* dir_drive, const char* logon_script, const char* profile_path, time_t unix_logon_time, time_t unix_logoff_time, time_t unix_kickoff_time, time_t unix_pass_last_set_time, time_t unix_pass_can_change_time, time_t unix_pass_must_change_time, uint16 logon_count, uint16 bad_pw_count, uint32 num_groups, const DOM_GID *gids, uint32 user_flgs, uchar user_session_key[16], uchar lm_session_key[16], const char *logon_srv, const char *logon_dom, const DOM_SID *dom_sid, const char *other_sids){ /* only cope with one "other" sid, right now. */ /* need to count the number of space-delimited sids */ unsigned int i; int num_other_sids = 0; NTTIME logon_time, logoff_time, kickoff_time, pass_last_set_time, pass_can_change_time, pass_must_change_time; ZERO_STRUCTP(usr); usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */ /* Create NTTIME structs */ unix_to_nt_time (&logon_time, unix_logon_time); unix_to_nt_time (&logoff_time, unix_logoff_time); unix_to_nt_time (&kickoff_time, unix_kickoff_time); unix_to_nt_time (&pass_last_set_time, unix_pass_last_set_time); unix_to_nt_time (&pass_can_change_time, unix_pass_can_change_time); unix_to_nt_time (&pass_must_change_time, unix_pass_must_change_time); usr->logon_time = logon_time; usr->logoff_time = logoff_time; usr->kickoff_time = kickoff_time; usr->pass_last_set_time = pass_last_set_time; usr->pass_can_change_time = pass_can_change_time; usr->pass_must_change_time = pass_must_change_time; usr->logon_count = logon_count; usr->bad_pw_count = bad_pw_count; usr->user_rid = user_rid; usr->group_rid = group_rid; usr->num_groups = num_groups; usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */ usr->user_flgs = user_flgs; if (user_session_key != NULL) memcpy(usr->user_sess_key, user_session_key, sizeof(usr->user_sess_key)); else memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key)); usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */ memset((char *)usr->lm_sess_key, '\0', sizeof(usr->lm_sess_key)); memset(&usr->acct_flags, '\0', sizeof(usr->acct_flags)); for (i=0; i<7; i++) { memset(&usr->unknown[i], '\0', sizeof(usr->unknown)); } if (lm_session_key != NULL) { memcpy(usr->lm_sess_key, lm_session_key, sizeof(usr->lm_sess_key)); } num_other_sids = init_dom_sid2s(ctx, other_sids, &usr->other_sids); usr->num_other_sids = num_other_sids; usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0; init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name); init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name); init_unistr2(&usr->uni_logon_script, logon_script, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script); init_unistr2(&usr->uni_profile_path, profile_path, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path); init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir); init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive); usr->num_groups2 = num_groups; usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups); if (usr->gids == NULL && num_groups>0) return; for (i = 0; i < num_groups; i++) usr->gids[i] = gids[i]; init_unistr2(&usr->uni_logon_srv, logon_srv, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_logon_srv, &usr->uni_logon_srv); init_unistr2(&usr->uni_logon_dom, logon_dom, UNI_FLAGS_NONE); init_uni_hdr(&usr->hdr_logon_dom, &usr->uni_logon_dom); init_dom_sid2(&usr->dom_sid, dom_sid); /* "other" sids are set up above */}/******************************************************************* This code has been modified to cope with a NET_USER_INFO_2 - which is exactly the same as a NET_USER_INFO_3, minus the other sids parameters. We use validation level to determine if we're marshalling a info 2 or INFO_3 - be we always return an INFO_3. Based on code donated by Marc Jacobsen at HP. JRA.********************************************************************/BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, int depth, uint16 validation_level, BOOL kerb_validation_level){ unsigned int i; if (usr == NULL) return False; prs_debug(ps, depth, desc, "net_io_user_info3"); depth++; if (UNMARSHALLING(ps)) ZERO_STRUCTP(usr); if(!prs_align(ps)) return False; if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info)) return False; if (usr->ptr_user_info == 0) return True; if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */ return False; if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */ return False; if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */ return False; if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */ return False; if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */ return False; if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */ return False; if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth)) /* username unicode string header */ return False; if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */ return False; if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */ return False; if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */ return False; if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */ return False; if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */ return False; if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */ return False; if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */ return False; if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User RID */ return False; if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group RID */ return False; if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */ return False; if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */ return False; if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */ return False; if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* user session key */ return False; if(!smb_io_unihdr("hdr_logon_srv", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */ return False; if(!smb_io_unihdr("hdr_logon_dom", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */ return False; if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */ return False; if(!prs_uint8s(False, "lm_sess_key", ps, depth, usr->lm_sess_key, 8)) /* lm session key */ return False; if(!prs_uint32("acct_flags ", ps, depth, &usr->acct_flags)) /* Account flags */ return False; for (i = 0; i < 7; i++) { if (!prs_uint32("unkown", ps, depth, &usr->unknown[i])) /* unknown */ return False; } if (validation_level == 3) { if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */ return False; if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */ return False; } else { if (UNMARSHALLING(ps)) { usr->num_other_sids = 0; usr->buffer_other_sids = 0; } } /* get kerb validation info (not really part of user_info_3) - Guenther */ if (kerb_validation_level) { if(!prs_uint32("ptr_res_group_dom_sid", ps, depth, &usr->ptr_res_group_dom_sid)) return False; if(!prs_uint32("res_group_count", ps, depth, &usr->res_group_count)) return False; if(!prs_uint32("ptr_res_groups", ps, depth, &usr->ptr_res_groups)) return False; } if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */ return False; if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */ return False; if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */ return False; if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */ return False; if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */ return False; if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */ return False; if(!prs_align(ps)) return False; if (usr->num_groups > 0) { if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups2 */ return False; if (usr->num_groups != usr->num_groups2) { DEBUG(3,("net_io_user_info3: num_groups mismatch! (%d != %d)\n", usr->num_groups, usr->num_groups2)); return False; } if (UNMARSHALLING(ps)) { usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups); if (usr->gids == NULL) return False; } for (i = 0; i < usr->num_groups; i++) { if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */ return False; } } if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */ return False; if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_dom.buffer, ps, depth)) /* logon domain unicode string */ return False; if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth)) /* domain SID */ return False; if (usr->buffer_other_sids) { uint32 num_other_sids = usr->num_other_sids; if (!(usr->user_flgs & LOGON_EXTRA_SIDS)) { DEBUG(10,("net_io_user_info3: user_flgs attribute does not have LOGON_EXTRA_SIDS\n")); /* return False; */ } if (!prs_uint32("num_other_sids", ps, depth, &num_other_sids)) return False; if (num_other_sids != usr->num_other_sids) return False; if (UNMARSHALLING(ps)) { usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids); usr->other_sids_attrib = PRS_ALLOC_MEM(ps, uint32, usr->num_other_sids); if ((num_other_sids != 0) && ((usr->other_sids == NULL) || (usr->other_sids_attrib == NULL))) return False; } /* First the pointers to the SIDS and attributes */ depth++; for (i=0; i<usr->num_other_sids; i++) { uint32 ptr = 1; if (!prs_uint32("sid_ptr", ps, depth, &ptr)) return False; if (UNMARSHALLING(ps) && (ptr == 0)) return False; if (!prs_uint32("attribute", ps, depth, &usr->other_sids_attrib[i])) return False; } for (i = 0; i < usr->num_other_sids; i++) { if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */ return False; } depth--; } return True;}/******************************************************************* Reads or writes a structure.********************************************************************/BOOL net_io_q_sam_logon(const char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth){ if (q_l == NULL) return False; prs_debug(ps, depth, desc, "net_io_q_sam_logon"); depth++; if(!prs_align(ps)) return False;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?