parse_net.c

来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 2,161 行 · 第 1/5 页

C
2,161
字号
{	DEBUG(5,("init_q_auth_3: %d\n", __LINE__));	init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);	memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));	q_a->clnt_flgs.neg_flags = clnt_flgs;	DEBUG(5,("init_q_auth_3: %d\n", __LINE__));}/******************************************************************* Reads or writes a structure.********************************************************************/BOOL net_io_q_auth_3(const char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth){	if (q_a == NULL)		return False;	prs_debug(ps, depth, desc, "net_io_q_auth_3");	depth++;	if(!prs_align(ps))		return False;    	if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */		return False;	if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))		return False;	if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))		return False;	return True;}/******************************************************************* Reads or writes a structure.********************************************************************/BOOL net_io_r_auth_3(const char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth){	if (r_a == NULL)		return False;	prs_debug(ps, depth, desc, "net_io_r_auth_3");	depth++;	if(!prs_align(ps))		return False;    	if(!smb_io_chal("srv_chal", &r_a->srv_chal, ps, depth)) /* server challenge */		return False;	if(!net_io_neg_flags("srv_flgs", &r_a->srv_flgs, ps, depth))		return False;	if (!prs_uint32("unknown", ps, depth, &r_a->unknown))		return False;	if(!prs_ntstatus("status", ps, depth, &r_a->status))		return False;	return True;}/******************************************************************* Inits a NET_Q_SRV_PWSET.********************************************************************/void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,		const char *logon_srv, const char *sess_key, const char *acct_name,                 uint16 sec_chan, const char *comp_name,		DOM_CRED *cred, const uchar hashed_mach_pwd[16]){	unsigned char nt_cypher[16];		DEBUG(5,("init_q_srv_pwset\n"));		/* Process the new password. */	cred_hash3( nt_cypher, hashed_mach_pwd, (const unsigned char *)sess_key, 1);	init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);	memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd)); }/******************************************************************* Reads or writes a structure.********************************************************************/BOOL net_io_q_srv_pwset(const char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth){	if (q_s == NULL)		return False;	prs_debug(ps, depth, desc, "net_io_q_srv_pwset");	depth++;	if(!prs_align(ps))		return False;    	if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */		return False;	if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */		return False;	return True;}/******************************************************************* Reads or writes a structure.********************************************************************/BOOL net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth){	if (r_s == NULL)		return False;	prs_debug(ps, depth, desc, "net_io_r_srv_pwset");	depth++;	if(!prs_align(ps))		return False;    	if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */		return False;	if(!prs_ntstatus("status", ps, depth, &r_s->status))		return False;	return True;}/************************************************************************* Init DOM_SID2 array from a string containing multiple sids *************************************************************************/static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids){	const char *ptr;	pstring s2;	int count = 0;	DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));	*ppsids = NULL;	if(sids_str) {		int number;		DOM_SID2 *sids;		/* Count the number of valid SIDs. */		for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {			DOM_SID tmpsid;			if (string_to_sid(&tmpsid, s2))				count++;		}		/* Now allocate space for them. */		*ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);		if (*ppsids == NULL)			return 0;		sids = *ppsids;		for (number = 0, ptr = sids_str; next_token(&ptr, s2, NULL, sizeof(s2)); ) {			DOM_SID tmpsid;			if (string_to_sid(&tmpsid, s2)) {				/* count only valid sids */				init_dom_sid2(&sids[number], &tmpsid);				number++;			}		}	}	return count;}/******************************************************************* Inits a NET_ID_INFO_1 structure.********************************************************************/void init_id_info1(NET_ID_INFO_1 *id, const char *domain_name,				uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,				const char *user_name, const char *wksta_name,				const char *sess_key,				unsigned char lm_cypher[16], unsigned char nt_cypher[16]){	unsigned char lm_owf[16];	unsigned char nt_owf[16];	DEBUG(5,("init_id_info1: %d\n", __LINE__));	id->ptr_id_info1 = 1;	id->param_ctrl = param_ctrl;	init_logon_id(&id->logon_id, log_id_low, log_id_high);	if (lm_cypher && nt_cypher) {		unsigned char key[16];#ifdef DEBUG_PASSWORD		DEBUG(100,("lm cypher:"));		dump_data(100, (char *)lm_cypher, 16);		DEBUG(100,("nt cypher:"));		dump_data(100, (char *)nt_cypher, 16);#endif		memset(key, 0, 16);		memcpy(key, sess_key, 8);		memcpy(lm_owf, lm_cypher, 16);		SamOEMhash(lm_owf, key, 16);		memcpy(nt_owf, nt_cypher, 16);		SamOEMhash(nt_owf, key, 16);#ifdef DEBUG_PASSWORD		DEBUG(100,("encrypt of lm owf password:"));		dump_data(100, (char *)lm_owf, 16);		DEBUG(100,("encrypt of nt owf password:"));		dump_data(100, (char *)nt_owf, 16);#endif		/* set up pointers to cypher blocks */		lm_cypher = lm_owf;		nt_cypher = nt_owf;	}	init_owf_info(&id->lm_owf, lm_cypher);	init_owf_info(&id->nt_owf, nt_cypher);	init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);	init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);	init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);	init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);	init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);	init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);}/******************************************************************* Reads or writes an NET_ID_INFO_1 structure.********************************************************************/static BOOL net_io_id_info1(const char *desc,  NET_ID_INFO_1 *id, prs_struct *ps, int depth){	if (id == NULL)		return False;	prs_debug(ps, depth, desc, "net_io_id_info1");	depth++;	if(!prs_align(ps))		return False;		if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))		return False;	if (id->ptr_id_info1 != 0) {		if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))			return False;		if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))			return False;		if(!smb_io_logon_id("", &id->logon_id, ps, depth))			return False;		if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))			return False;		if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))			return False;		if(!smb_io_owf_info("", &id->lm_owf, ps, depth))			return False;		if(!smb_io_owf_info("", &id->nt_owf, ps, depth))			return False;		if(!smb_io_unistr2("unistr2", &id->uni_domain_name,				id->hdr_domain_name.buffer, ps, depth))			return False;		if(!smb_io_unistr2("unistr2", &id->uni_user_name,				id->hdr_user_name.buffer, ps, depth))			return False;		if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,				id->hdr_wksta_name.buffer, ps, depth))			return False;	}	return True;}/*******************************************************************Inits a NET_ID_INFO_2 structure.This is a network logon packet. The log_id parametersare what an NT server would generate for LUID once theuser is logged on. I don't think we care about them.Note that this has no access to the NT and LM hashed passwords,so it forwards the challenge, and the NT and LM responses (24bytes each) over the secure channel to the Domain controllerfor it to say yea or nay. This is the preferred method of checking for a logon as it doesn't export the passwordhashes to anyone who has compromised the secure channel. JRA.********************************************************************/void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,		   uint32 param_ctrl,		   uint32 log_id_low, uint32 log_id_high,		   const char *user_name, const char *wksta_name,		   const uchar lm_challenge[8],		   const uchar * lm_chal_resp, size_t lm_chal_resp_len,		   const uchar * nt_chal_resp, size_t nt_chal_resp_len){	DEBUG(5,("init_id_info2: %d\n", __LINE__));	id->ptr_id_info2 = 1;	id->param_ctrl = param_ctrl;	init_logon_id(&id->logon_id, log_id_low, log_id_high);	memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));	init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);	init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);	init_unistr2(&id->uni_domain_name, domain_name, UNI_FLAGS_NONE);	init_uni_hdr(&id->hdr_domain_name, &id->uni_domain_name);	init_unistr2(&id->uni_user_name, user_name, UNI_FLAGS_NONE);	init_uni_hdr(&id->hdr_user_name, &id->uni_user_name);	init_unistr2(&id->uni_wksta_name, wksta_name, UNI_FLAGS_NONE);	init_uni_hdr(&id->hdr_wksta_name, &id->uni_wksta_name);	init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);	init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);}/******************************************************************* Reads or writes an NET_ID_INFO_2 structure.********************************************************************/static BOOL net_io_id_info2(const char *desc,  NET_ID_INFO_2 *id, prs_struct *ps, int depth){	if (id == NULL)		return False;	prs_debug(ps, depth, desc, "net_io_id_info2");	depth++;	if(!prs_align(ps))		return False;		if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))		return False;	if (id->ptr_id_info2 != 0) {		if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))			return False;		if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))			return False;		if(!smb_io_logon_id("", &id->logon_id, ps, depth))			return False;		if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))			return False;		if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))			return False;		if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */			return False;		if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))			return False;		if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))			return False;		if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,				id->hdr_domain_name.buffer, ps, depth))			return False;		if(!smb_io_unistr2("uni_user_name  ", &id->uni_user_name,				id->hdr_user_name.buffer, ps, depth))			return False;		if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,				id->hdr_wksta_name.buffer, ps, depth))			return False;		if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,				id->hdr_nt_chal_resp.buffer, ps, depth))			return False;		if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,				id->hdr_lm_chal_resp.buffer, ps, depth))			return False;	}	return True;}/******************************************************************* Inits a DOM_SAM_INFO structure.********************************************************************/void init_sam_info(DOM_SAM_INFO *sam,				const char *logon_srv, const char *comp_name,				DOM_CRED *clnt_cred,				DOM_CRED *rtn_cred, uint16 logon_level,				NET_ID_INFO_CTR *ctr){	DEBUG(5,("init_sam_info: %d\n", __LINE__));	init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);	if (rtn_cred != NULL) {		sam->ptr_rtn_cred = 1;		memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));	} else {		sam->ptr_rtn_cred = 0;	}	sam->logon_level  = logon_level;	sam->ctr          = ctr;}/******************************************************************* Reads or writes a DOM_SAM_INFO structure.********************************************************************/static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth){	NET_ID_INFO_CTR *ctr = *pp_ctr;	prs_debug(ps, depth, desc, "smb_io_sam_info");	depth++;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?