parse_rpc.c

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

C
862
字号
				uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,				RPC_CONTEXT *context){	init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid);	rpc->num_contexts = 1;	rpc->rpc_context = context;}/******************************************************************* Reads or writes an RPC_CONTEXT structure.********************************************************************/BOOL smb_io_rpc_context(const char *desc, RPC_CONTEXT *rpc_ctx, prs_struct *ps, int depth){	int i;	if (rpc_ctx == NULL)		return False;	if(!prs_align(ps))		return False;	if(!prs_uint16("context_id  ", ps, depth, &rpc_ctx->context_id ))		return False;	if(!prs_uint8 ("num_transfer_syntaxes", ps, depth, &rpc_ctx->num_transfer_syntaxes))		return False;	/* num_transfer_syntaxes must not be zero. */	if (rpc_ctx->num_transfer_syntaxes == 0)		return False;	if(!smb_io_rpc_iface("", &rpc_ctx->abstract, ps, depth))		return False;	if (UNMARSHALLING(ps)) {		if (!(rpc_ctx->transfer = PRS_ALLOC_MEM(ps, RPC_IFACE, rpc_ctx->num_transfer_syntaxes))) {			return False;		}	}	for (i = 0; i < rpc_ctx->num_transfer_syntaxes; i++ ) {		if (!smb_io_rpc_iface("", &rpc_ctx->transfer[i], ps, depth))			return False;	}	return True;} /******************************************************************* Reads or writes an RPC_HDR_RB structure.********************************************************************/BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth){	int i;		if (rpc == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_rb");	depth++;	if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))		return False;	if(!prs_uint8("num_contexts", ps, depth, &rpc->num_contexts))		return False;	/* 3 pad bytes following - will be mopped up by the prs_align in smb_io_rpc_context(). */	/* num_contexts must not be zero. */	if (rpc->num_contexts == 0)		return False;	if (UNMARSHALLING(ps)) {		if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) {			return False;		}	}	for (i = 0; i < rpc->num_contexts; i++ ) {		if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth))			return False;	}	return True;}/******************************************************************* Inits an RPC_RESULTS structure. lkclXXXX only one reason at the moment!********************************************************************/static void init_rpc_results(RPC_RESULTS *res, 				uint8 num_results, uint16 result, uint16 reason){	res->num_results = num_results; /* the number of results (0x01) */	res->result      = result     ;  /* result (0x00 = accept) */	res->reason      = reason     ;  /* reason (0x00 = no reason specified) */}/******************************************************************* Reads or writes an RPC_RESULTS structure. lkclXXXX only one reason at the moment!********************************************************************/static BOOL smb_io_rpc_results(const char *desc, RPC_RESULTS *res, prs_struct *ps, int depth){	if (res == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_results");	depth++;	if(!prs_align(ps))		return False;		if(!prs_uint8 ("num_results", ps, depth, &res->num_results))			return False;	if(!prs_align(ps))		return False;		if(!prs_uint16("result     ", ps, depth, &res->result))		return False;	if(!prs_uint16("reason     ", ps, depth, &res->reason))		return False;	return True;}/******************************************************************* Init an RPC_HDR_BA structure. lkclXXXX only one reason at the moment!********************************************************************/void init_rpc_hdr_ba(RPC_HDR_BA *rpc, 				uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid,				const char *pipe_addr,				uint8 num_results, uint16 result, uint16 reason,				RPC_IFACE *transfer){	init_rpc_hdr_bba (&rpc->bba, max_tsize, max_rsize, assoc_gid);	init_rpc_addr_str(&rpc->addr, pipe_addr);	init_rpc_results (&rpc->res, num_results, result, reason);	/* the transfer syntax from the request */	memcpy(&rpc->transfer, transfer, sizeof(rpc->transfer));}/******************************************************************* Reads or writes an RPC_HDR_BA structure.********************************************************************/BOOL smb_io_rpc_hdr_ba(const char *desc, RPC_HDR_BA *rpc, prs_struct *ps, int depth){	if (rpc == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_ba");	depth++;	if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth))		return False;	if(!smb_io_rpc_addr_str("", &rpc->addr, ps, depth))		return False;	if(!smb_io_rpc_results("", &rpc->res, ps, depth))		return False;	if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth))		return False;	return True;}/******************************************************************* Init an RPC_HDR_REQ structure.********************************************************************/void init_rpc_hdr_req(RPC_HDR_REQ *hdr, uint32 alloc_hint, uint16 opnum){	hdr->alloc_hint   = alloc_hint; /* allocation hint */	hdr->context_id   = 0;         /* presentation context identifier */	hdr->opnum        = opnum;     /* opnum */}/******************************************************************* Reads or writes an RPC_HDR_REQ structure.********************************************************************/BOOL smb_io_rpc_hdr_req(const char *desc, RPC_HDR_REQ *rpc, prs_struct *ps, int depth){	if (rpc == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_req");	depth++;	if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))		return False;	if(!prs_uint16("context_id", ps, depth, &rpc->context_id))		return False;	if(!prs_uint16("opnum     ", ps, depth, &rpc->opnum))		return False;	return True;}/******************************************************************* Reads or writes an RPC_HDR_RESP structure.********************************************************************/BOOL smb_io_rpc_hdr_resp(const char *desc, RPC_HDR_RESP *rpc, prs_struct *ps, int depth){	if (rpc == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_resp");	depth++;	if(!prs_uint32("alloc_hint", ps, depth, &rpc->alloc_hint))		return False;	if(!prs_uint16("context_id", ps, depth, &rpc->context_id))		return False;	if(!prs_uint8 ("cancel_ct ", ps, depth, &rpc->cancel_count))		return False;	if(!prs_uint8 ("reserved  ", ps, depth, &rpc->reserved))		return False;	return True;}/******************************************************************* Reads or writes an RPC_HDR_FAULT structure.********************************************************************/BOOL smb_io_rpc_hdr_fault(const char *desc, RPC_HDR_FAULT *rpc, prs_struct *ps, int depth){	if (rpc == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_fault");	depth++;	if(!prs_ntstatus("status  ", ps, depth, &rpc->status))		return False;	if(!prs_uint32("reserved", ps, depth, &rpc->reserved))		return False;    return True;}/******************************************************************* Inits an RPC_HDR_AUTH structure.********************************************************************/void init_rpc_hdr_auth(RPC_HDR_AUTH *rai,				uint8 auth_type, uint8 auth_level,				uint8 auth_pad_len,				uint32 auth_context_id){	rai->auth_type     = auth_type;	rai->auth_level    = auth_level;	rai->auth_pad_len  = auth_pad_len;	rai->auth_reserved = 0;	rai->auth_context_id = auth_context_id;}/******************************************************************* Reads or writes an RPC_HDR_AUTH structure.********************************************************************/BOOL smb_io_rpc_hdr_auth(const char *desc, RPC_HDR_AUTH *rai, prs_struct *ps, int depth){	if (rai == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_hdr_auth");	depth++;	if(!prs_align(ps))		return False;	if(!prs_uint8 ("auth_type    ", ps, depth, &rai->auth_type))		return False;	if(!prs_uint8 ("auth_level   ", ps, depth, &rai->auth_level))		return False;	if(!prs_uint8 ("auth_pad_len ", ps, depth, &rai->auth_pad_len))		return False;	if(!prs_uint8 ("auth_reserved", ps, depth, &rai->auth_reserved))		return False;	if(!prs_uint32("auth_context_id", ps, depth, &rai->auth_context_id))		return False;	return True;}/******************************************************************* Checks an RPC_AUTH_VERIFIER structure.********************************************************************/BOOL rpc_auth_verifier_chk(RPC_AUTH_VERIFIER *rav,				const char *signature, uint32 msg_type){	return (strequal(rav->signature, signature) && rav->msg_type == msg_type);}/******************************************************************* Inits an RPC_AUTH_VERIFIER structure.********************************************************************/void init_rpc_auth_verifier(RPC_AUTH_VERIFIER *rav,				const char *signature, uint32 msg_type){	fstrcpy(rav->signature, signature); /* "NTLMSSP" */	rav->msg_type = msg_type; /* NTLMSSP_MESSAGE_TYPE */}/******************************************************************* Reads or writes an RPC_AUTH_VERIFIER structure.********************************************************************/BOOL smb_io_rpc_auth_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth){	if (rav == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_auth_verifier");	depth++;	/* "NTLMSSP" */	if(!prs_string("signature", ps, depth, rav->signature,			sizeof(rav->signature)))		return False;	if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type)) /* NTLMSSP_MESSAGE_TYPE */		return False;	return True;}/******************************************************************* This parses an RPC_AUTH_VERIFIER for schannel. I think********************************************************************/BOOL smb_io_rpc_schannel_verifier(const char *desc, RPC_AUTH_VERIFIER *rav, prs_struct *ps, int depth){	if (rav == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_schannel_verifier");	depth++;	if(!prs_string("signature", ps, depth, rav->signature, sizeof(rav->signature)))		return False;	if(!prs_uint32("msg_type ", ps, depth, &rav->msg_type))		return False;	return True;}/*******************************************************************creates an RPC_AUTH_SCHANNEL_NEG structure.********************************************************************/void init_rpc_auth_schannel_neg(RPC_AUTH_SCHANNEL_NEG *neg,			      const char *domain, const char *myname){	neg->type1 = 0;	neg->type2 = 0x3;	fstrcpy(neg->domain, domain);	fstrcpy(neg->myname, myname);}/******************************************************************* Reads or writes an RPC_AUTH_SCHANNEL_NEG structure.********************************************************************/BOOL smb_io_rpc_auth_schannel_neg(const char *desc, RPC_AUTH_SCHANNEL_NEG *neg,				prs_struct *ps, int depth){	if (neg == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_neg");	depth++;	if(!prs_align(ps))		return False;	if(!prs_uint32("type1", ps, depth, &neg->type1))		return False;	if(!prs_uint32("type2", ps, depth, &neg->type2))		return False;	if(!prs_string("domain  ", ps, depth, neg->domain, sizeof(neg->domain)))		return False;	if(!prs_string("myname  ", ps, depth, neg->myname, sizeof(neg->myname)))		return False;	return True;}/*******************************************************************reads or writes an RPC_AUTH_SCHANNEL_CHK structure.********************************************************************/BOOL smb_io_rpc_auth_schannel_chk(const char *desc, int auth_len,                                 RPC_AUTH_SCHANNEL_CHK * chk,				prs_struct *ps, int depth){	if (chk == NULL)		return False;	prs_debug(ps, depth, desc, "smb_io_rpc_auth_schannel_chk");	depth++;	if ( !prs_uint8s(False, "sig  ", ps, depth, chk->sig, sizeof(chk->sig)) )		return False;			if ( !prs_uint8s(False, "seq_num", ps, depth, chk->seq_num, sizeof(chk->seq_num)) )		return False;			if ( !prs_uint8s(False, "packet_digest", ps, depth, chk->packet_digest, sizeof(chk->packet_digest)) )		return False;		if ( auth_len == RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ) {		if ( !prs_uint8s(False, "confounder", ps, depth, chk->confounder, sizeof(chk->confounder)) )			return False;	}	return True;}

⌨️ 快捷键说明

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