From 04e07e8cc9d6615381e0501cd36cf7d78aeed189 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 8 Jun 2005 03:48:40 +0000 Subject: r7385: Rewrite the RPC bind parsing functions to follow the spec. I haven't yet tested this so I may have screwed this up - however it now follows the DCE spec. valgrinded tests to follow.... Jeremy. (This used to be commit 877e0a61f5821c89149b1403d08675dd7db8039e) --- source3/include/rpc_dce.h | 179 +++++++++++++++++------------------------- source3/rpc_client/cli_pipe.c | 15 ++-- source3/rpc_parse/parse_rpc.c | 101 +++++++++++++++++------- source3/rpc_server/srv_pipe.c | 6 +- source3/smbd/notify_kernel.c | 1 - 5 files changed, 157 insertions(+), 145 deletions(-) (limited to 'source3') diff --git a/source3/include/rpc_dce.h b/source3/include/rpc_dce.h index 57b1184bd9..68cc55bf31 100644 --- a/source3/include/rpc_dce.h +++ b/source3/include/rpc_dce.h @@ -28,8 +28,7 @@ /* DCE/RPC packet types */ -enum RPC_PKT_TYPE -{ +enum RPC_PKT_TYPE { RPC_REQUEST = 0x00, RPC_RESPONSE = 0x02, RPC_FAULT = 0x03, @@ -74,8 +73,7 @@ enum RPC_PKT_TYPE #define NETLOGON_NEG_SCHANNEL 0x40000000 #define NETLOGON_NEG_DOMAIN_TRUST_ACCOUNT 0x2010b000 -enum netsec_direction -{ +enum netsec_direction { SENDER_IS_INITIATOR, SENDER_IS_ACCEPTOR }; @@ -91,17 +89,14 @@ enum netsec_direction #define MAX_PDU_FRAG_LEN 0x10b8 /* this is what w2k sets */ /* RPC_IFACE */ -typedef struct rpc_iface_info -{ - struct uuid uuid; /* 16 bytes of rpc interface identification */ - uint32 version; /* the interface version number */ - +typedef struct rpc_iface_info { + struct uuid uuid; /* 16 bytes of rpc interface identification */ + uint32 version; /* the interface version number */ } RPC_IFACE; #define RPC_IFACE_LEN (UUID_SIZE + 4) -struct pipe_id_info -{ +struct pipe_id_info { /* the names appear not to matter: the syntaxes _do_ matter */ const char *client_pipe; @@ -112,49 +107,42 @@ struct pipe_id_info }; /* RPC_HDR - dce rpc header */ -typedef struct rpc_hdr_info -{ - uint8 major; /* 5 - RPC major version */ - uint8 minor; /* 0 - RPC minor version */ - uint8 pkt_type; /* RPC_PKT_TYPE - RPC response packet */ - uint8 flags; /* DCE/RPC flags */ - uint8 pack_type[4]; /* 0x1000 0000 - little-endian packed data representation */ - uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */ - uint16 auth_len; /* 0 - authentication length */ - uint32 call_id; /* call identifier. matches 12th uint32 of incoming RPC data. */ - +typedef struct rpc_hdr_info { + uint8 major; /* 5 - RPC major version */ + uint8 minor; /* 0 - RPC minor version */ + uint8 pkt_type; /* RPC_PKT_TYPE - RPC response packet */ + uint8 flags; /* DCE/RPC flags */ + uint8 pack_type[4]; /* 0x1000 0000 - little-endian packed data representation */ + uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */ + uint16 auth_len; /* 0 - authentication length */ + uint32 call_id; /* call identifier. matches 12th uint32 of incoming RPC data. */ } RPC_HDR; #define RPC_HEADER_LEN 16 /* RPC_HDR_REQ - ms request rpc header */ -typedef struct rpc_hdr_req_info -{ - uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */ - uint16 context_id; /* presentation context identifier */ - uint16 opnum; /* opnum */ - +typedef struct rpc_hdr_req_info { + uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */ + uint16 context_id; /* presentation context identifier */ + uint16 opnum; /* opnum */ } RPC_HDR_REQ; #define RPC_HDR_REQ_LEN 8 /* RPC_HDR_RESP - ms response rpc header */ -typedef struct rpc_hdr_resp_info -{ - uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */ - uint16 context_id; /* 0 - presentation context identifier */ - uint8 cancel_count; /* 0 - cancel count */ - uint8 reserved; /* 0 - reserved. */ - +typedef struct rpc_hdr_resp_info { + uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */ + uint16 context_id; /* 0 - presentation context identifier */ + uint8 cancel_count; /* 0 - cancel count */ + uint8 reserved; /* 0 - reserved. */ } RPC_HDR_RESP; #define RPC_HDR_RESP_LEN 8 /* RPC_HDR_FAULT - fault rpc header */ -typedef struct rpc_hdr_fault_info -{ - NTSTATUS status; - uint32 reserved; /* 0x0000 0000 */ +typedef struct rpc_hdr_fault_info { + NTSTATUS status; + uint32 reserved; /* 0x0000 0000 */ } RPC_HDR_FAULT; #define RPC_HDR_FAULT_LEN 8 @@ -167,27 +155,22 @@ typedef struct rpc_hdr_fault_info * "NETLOGON", "\\PIPE\\NETLOGON" */ /* RPC_ADDR_STR */ -typedef struct rpc_addr_info -{ - uint16 len; /* length of the string including null terminator */ - fstring str; /* the string above in single byte, null terminated form */ - +typedef struct rpc_addr_info { + uint16 len; /* length of the string including null terminator */ + fstring str; /* the string above in single byte, null terminated form */ } RPC_ADDR_STR; /* RPC_HDR_BBA */ -typedef struct rpc_hdr_bba_info -{ - uint16 max_tsize; /* maximum transmission fragment size (0x1630) */ - uint16 max_rsize; /* max receive fragment size (0x1630) */ - uint32 assoc_gid; /* associated group id (0x0) */ - +typedef struct rpc_hdr_bba_info { + uint16 max_tsize; /* maximum transmission fragment size (0x1630) */ + uint16 max_rsize; /* max receive fragment size (0x1630) */ + uint32 assoc_gid; /* associated group id (0x0) */ } RPC_HDR_BBA; #define RPC_HDR_BBA_LEN 8 /* RPC_HDR_AUTHA */ -typedef struct rpc_hdr_autha_info -{ +typedef struct rpc_hdr_autha_info { uint16 max_tsize; /* maximum transmission fragment size (0x1630) */ uint16 max_rsize; /* max receive fragment size (0x1630) */ @@ -197,21 +180,18 @@ typedef struct rpc_hdr_autha_info uint8 padding; /* padding */ uint32 unknown; /* 0x0014a0c0 */ - } RPC_HDR_AUTHA; #define RPC_HDR_AUTHA_LEN 12 /* RPC_HDR_AUTH */ -typedef struct rpc_hdr_auth_info -{ +typedef struct rpc_hdr_auth_info { uint8 auth_type; /* 0x0a */ uint8 auth_level; /* 0x06 */ uint8 padding; uint8 reserved; /* padding */ uint32 auth_context; /* pointer */ - } RPC_HDR_AUTH; #define RPC_HDR_AUTH_LEN 8 @@ -219,8 +199,7 @@ typedef struct rpc_hdr_auth_info /* this is TEMPORARILY coded up as a specific structure */ /* this structure comes after the bind request */ /* RPC_AUTH_NETSEC_NEG */ -typedef struct rpc_auth_netsec_neg_info -{ +typedef struct rpc_auth_netsec_neg_info { uint32 type1; /* Always zero ? */ uint32 type2; /* Types 0x3 and 0x13 seen. Check AcquireSecurityContext() docs.... */ fstring domain; /* calling workstations's domain */ @@ -229,80 +208,75 @@ typedef struct rpc_auth_netsec_neg_info /* attached to the end of encrypted rpc requests and responses */ /* RPC_AUTH_NETSEC_CHK */ -typedef struct rpc_auth_netsec_chk_info -{ +typedef struct rpc_auth_netsec_chk_info { uint8 sig [8]; /* 77 00 7a 00 ff ff 00 00 */ uint8 packet_digest[8]; /* checksum over the packet, MD5'ed with session key */ uint8 seq_num[8]; /* verifier, seq num */ uint8 confounder[8]; /* random 8-byte nonce */ } RPC_AUTH_NETSEC_CHK; -struct netsec_auth_struct -{ +struct netsec_auth_struct { uchar sess_key[16]; uint32 seq_num; int auth_flags; }; -/* RPC_BIND_REQ - ms req bind */ -typedef struct rpc_bind_req_info -{ - RPC_HDR_BBA bba; +typedef struct rpc_context { + uint16 context_id; /* presentation context identifier. */ + uint8 num_transfer_syntaxes; /* the number of syntaxes */ + RPC_IFACE abstract; /* num and vers. of interface client is using */ + RPC_IFACE *transfer; /* Array of transfer interfaces. */ +} RPC_CONTEXT; - uint32 num_elements; /* the number of elements (0x1) */ - uint16 context_id; /* presentation context identifier (0x0) */ - uint8 num_syntaxes; /* the number of syntaxes (has always been 1?)(0x1) */ - - RPC_IFACE abstract; /* num and vers. of interface client is using */ - RPC_IFACE transfer; /* num and vers. of interface to use for replies */ - +/* RPC_BIND_REQ - ms req bind */ +typedef struct rpc_bind_req_info { + RPC_HDR_BBA bba; + uint32 num_contexts; /* the number of contexts */ + RPC_CONTEXT *rpc_context; } RPC_HDR_RB; /* - * The following length is 8 bytes RPC_HDR_BBA_LEN, 8 bytes internals - * (with 3 bytes padding), + 2 x RPC_IFACE_LEN bytes for RPC_IFACE structs. + * The following length is 8 bytes RPC_HDR_BBA_LEN + + * 4 bytes size of context count + + * (context_count * (4 bytes of context_id, size of transfer syntax count + RPC_IFACE_LEN bytes + + * (transfer_syntax_count * RPC_IFACE_LEN bytes))) */ -#define RPC_HDR_RB_LEN (RPC_HDR_BBA_LEN + 8 + (2*RPC_IFACE_LEN)) +#define RPC_HDR_RB_LEN(rpc_hdr_rb) (RPC_HDR_BBA_LEN + 4 + \ + ((rpc_hdr_rb)->num_contexts) * (4 + RPC_IFACE_LEN + (((rpc_hdr_rb)->rpc_context->num_transfer_syntaxes)*RPC_IFACE_LEN))) /* RPC_RESULTS - can only cope with one reason, right now... */ -typedef struct rpc_results_info -{ -/* uint8[] # 4-byte alignment padding, against SMB header */ - - uint8 num_results; /* the number of results (0x01) */ +typedef struct rpc_results_info { + /* uint8[] # 4-byte alignment padding, against SMB header */ -/* uint8[] # 4-byte alignment padding, against SMB header */ + uint8 num_results; /* the number of results (0x01) */ - uint16 result; /* result (0x00 = accept) */ - uint16 reason; /* reason (0x00 = no reason specified) */ + /* uint8[] # 4-byte alignment padding, against SMB header */ + uint16 result; /* result (0x00 = accept) */ + uint16 reason; /* reason (0x00 = no reason specified) */ } RPC_RESULTS; /* RPC_HDR_BA */ -typedef struct rpc_hdr_ba_info -{ - RPC_HDR_BBA bba; - - RPC_ADDR_STR addr ; /* the secondary address string, as described earlier */ - RPC_RESULTS res ; /* results and reasons */ - RPC_IFACE transfer; /* the transfer syntax from the request */ +typedef struct rpc_hdr_ba_info { + RPC_HDR_BBA bba; + RPC_ADDR_STR addr ; /* the secondary address string, as described earlier */ + RPC_RESULTS res ; /* results and reasons */ + RPC_IFACE transfer; /* the transfer syntax from the request */ } RPC_HDR_BA; /* RPC_AUTH_VERIFIER */ -typedef struct rpc_auth_verif_info -{ +typedef struct rpc_auth_verif_info { fstring signature; /* "NTLMSSP".. Ok, not quite anymore */ uint32 msg_type; /* NTLMSSP_MESSAGE_TYPE (1,2,3) and 5 for schannel */ - } RPC_AUTH_VERIFIER; /* this is TEMPORARILY coded up as a specific structure */ /* this structure comes after the bind request */ /* RPC_AUTH_NTLMSSP_NEG */ -typedef struct rpc_auth_ntlmssp_neg_info -{ + +typedef struct rpc_auth_ntlmssp_neg_info { uint32 neg_flgs; /* 0x0000 b2b3 */ STRHDR hdr_myname; /* offset is against START of this structure */ @@ -310,27 +284,23 @@ typedef struct rpc_auth_ntlmssp_neg_info fstring myname; /* calling workstation's name */ fstring domain; /* calling workstations's domain */ - } RPC_AUTH_NTLMSSP_NEG; /* this is TEMPORARILY coded up as a specific structure */ /* this structure comes after the bind acknowledgement */ /* RPC_AUTH_NTLMSSP_CHAL */ -typedef struct rpc_auth_ntlmssp_chal_info -{ +typedef struct rpc_auth_ntlmssp_chal_info { uint32 unknown_1; /* 0x0000 0000 */ uint32 unknown_2; /* 0x0000 0028 */ uint32 neg_flags; /* 0x0000 82b1 */ uint8 challenge[8]; /* ntlm challenge */ uint8 reserved [8]; /* zeros */ - } RPC_AUTH_NTLMSSP_CHAL; /* RPC_AUTH_NTLMSSP_RESP */ -typedef struct rpc_auth_ntlmssp_resp_info -{ +typedef struct rpc_auth_ntlmssp_resp_info { STRHDR hdr_lm_resp; /* 24 byte response */ STRHDR hdr_nt_resp; /* 24 byte response */ STRHDR hdr_domain; @@ -345,18 +315,15 @@ typedef struct rpc_auth_ntlmssp_resp_info fstring domain; fstring nt_resp; fstring lm_resp; - } RPC_AUTH_NTLMSSP_RESP; /* attached to the end of encrypted rpc requests and responses */ /* RPC_AUTH_NTLMSSP_CHK */ -typedef struct rpc_auth_ntlmssp_chk_info -{ +typedef struct rpc_auth_ntlmssp_chk_info { uint32 ver; /* 0x0000 0001 */ uint32 reserved; uint32 crc32; /* checksum using 0xEDB8 8320 as a polynomial */ uint32 seq_num; - } RPC_AUTH_NTLMSSP_CHK; #define RPC_AUTH_NTLMSSP_CHK_LEN 16 diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c index 52cbae6326..8f6576a165 100644 --- a/source3/rpc_client/cli_pipe.c +++ b/source3/rpc_client/cli_pipe.c @@ -652,6 +652,7 @@ static NTSTATUS create_rpc_bind_req(struct cli_state *cli, prs_struct *rpc_out, RPC_HDR hdr; RPC_HDR_RB hdr_rb; RPC_HDR_AUTH hdr_auth; + RPC_CONTEXT rpc_ctx; int auth_len = 0; int auth_type, auth_level; size_t saved_hdr_offset = 0; @@ -734,21 +735,25 @@ static NTSTATUS create_rpc_bind_req(struct cli_state *cli, prs_struct *rpc_out, auth_len = prs_offset(&auth_info) - saved_hdr_offset; } + /* create the RPC context. */ + init_rpc_context(&rpc_ctx, 0 /* context id */, + abstract, transfer); + + /* create the bind request RPC_HDR_RB */ + init_rpc_hdr_rb(&hdr_rb, MAX_PDU_FRAG_LEN, MAX_PDU_FRAG_LEN, 0x0, &rpc_ctx); + /* Create the request RPC_HDR */ init_rpc_hdr(&hdr, RPC_BIND, 0x3, rpc_call_id, - RPC_HEADER_LEN + RPC_HDR_RB_LEN + prs_offset(&auth_info), + RPC_HEADER_LEN + RPC_HDR_RB_LEN(&hdr_rb) + prs_offset(&auth_info), auth_len); + /* Marshall the RPC header */ if(!smb_io_rpc_hdr("hdr" , &hdr, rpc_out, 0)) { DEBUG(0,("create_rpc_bind_req: failed to marshall RPC_HDR.\n")); prs_mem_free(&auth_info); return NT_STATUS_NO_MEMORY; } - /* create the bind request RPC_HDR_RB */ - init_rpc_hdr_rb(&hdr_rb, MAX_PDU_FRAG_LEN, MAX_PDU_FRAG_LEN, 0x0, - 0x1, 0x0, 0x1, abstract, transfer); - /* Marshall the bind request data */ if(!smb_io_rpc_hdr_rb("", &hdr_rb, rpc_out, 0)) { DEBUG(0,("create_rpc_bind_req: failed to marshall RPC_HDR_RB.\n")); diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c index 6bdab2e437..ef5c230d2d 100644 --- a/source3/rpc_parse/parse_rpc.c +++ b/source3/rpc_parse/parse_rpc.c @@ -376,27 +376,75 @@ static BOOL smb_io_rpc_hdr_bba(const char *desc, RPC_HDR_BBA *rpc, prs_struct * return True; } +/******************************************************************* + Inits an RPC_CONTEXT structure. + Note the transfer pointer must remain valid until this is marshalled. +********************************************************************/ + +void init_rpc_context(RPC_CONTEXT *rpc_ctx, uint16 context_id, RPC_IFACE *abstract, RPC_IFACE *transfer) +{ + rpc_ctx->context_id = context_id ; /* presentation context identifier (0x0) */ + rpc_ctx->num_transfer_syntaxes = 1 ; /* the number of syntaxes (has always been 1?)(0x1) */ + + /* num and vers. of interface client is using */ + rpc_ctx->abstract = *abstract; + + /* vers. of interface to use for replies */ + rpc_ctx->transfer = transfer; +} + /******************************************************************* Inits an RPC_HDR_RB structure. + Note the context pointer must remain valid until this is marshalled. ********************************************************************/ void init_rpc_hdr_rb(RPC_HDR_RB *rpc, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid, - uint32 num_elements, uint16 context_id, uint8 num_syntaxes, - RPC_IFACE *abstract, RPC_IFACE *transfer) + RPC_CONTEXT *context) { init_rpc_hdr_bba(&rpc->bba, max_tsize, max_rsize, assoc_gid); - rpc->num_elements = num_elements ; /* the number of elements (0x1) */ - rpc->context_id = context_id ; /* presentation context identifier (0x0) */ - rpc->num_syntaxes = num_syntaxes ; /* the number of syntaxes (has always been 1?)(0x1) */ + rpc->num_contexts = 1; + rpc->rpc_context = context; +} - /* num and vers. of interface client is using */ - rpc->abstract = *abstract; +/******************************************************************* + Reads or writes an RPC_CONTEXT structure. +********************************************************************/ - /* num and vers. of interface to use for replies */ - rpc->transfer = *transfer; -} +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. @@ -404,7 +452,6 @@ void init_rpc_hdr_rb(RPC_HDR_RB *rpc, BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int depth) { - RPC_HDR_RB rpc2; int i; if (rpc == NULL) @@ -416,31 +463,25 @@ BOOL smb_io_rpc_hdr_rb(const char *desc, RPC_HDR_RB *rpc, prs_struct *ps, int de if(!smb_io_rpc_hdr_bba("", &rpc->bba, ps, depth)) return False; - if(!prs_uint32("num_elements", ps, depth, &rpc->num_elements)) - return False; - if(!prs_uint16("context_id ", ps, depth, &rpc->context_id )) - return False; - if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc->num_syntaxes)) + if(!prs_uint32("num_contexts", ps, depth, &rpc->num_contexts)) return False; - if(!smb_io_rpc_iface("", &rpc->abstract, ps, depth)) - return False; - if(!smb_io_rpc_iface("", &rpc->transfer, ps, depth)) + rpc->num_contexts &= 0xff; /* Actually a 1 byte field.. */ + + /* num_contexts must not be zero. */ + if (rpc->num_contexts == 0) return False; - - /* just chew through extra context id's for now */ - - for ( i=1; inum_elements; i++ ) { - if(!prs_uint16("context_id ", ps, depth, &rpc2.context_id )) - return False; - if(!prs_uint8 ("num_syntaxes", ps, depth, &rpc2.num_syntaxes)) - return False; - if(!smb_io_rpc_iface("", &rpc2.abstract, ps, depth)) + if (UNMARSHALLING(ps)) { + if (!(rpc->rpc_context = PRS_ALLOC_MEM(ps, RPC_CONTEXT, rpc->num_contexts))) { return False; - if(!smb_io_rpc_iface("", &rpc2.transfer, ps, depth)) + } + } + + for (i = 0; i < rpc->num_contexts; i++ ) { + if (!smb_io_rpc_context("", &rpc->rpc_context[i], ps, depth)) return False; - } + } return True; } diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index ee4e803d9f..9cf61d6357 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -1068,15 +1068,15 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p) unknown to NT4) Needed when adding entries to a DACL from NT5 - SK */ - if(check_bind_req(p, &hdr_rb.abstract, &hdr_rb.transfer, hdr_rb.context_id )) - { + if(check_bind_req(p, &hdr_rb.rpc_context[0].abstract, &hdr_rb.rpc_context[0].transfer[0], + hdr_rb.rpc_context[0].context_id )) { init_rpc_hdr_ba(&hdr_ba, MAX_PDU_FRAG_LEN, MAX_PDU_FRAG_LEN, assoc_gid, ack_pipe_name, 0x1, 0x0, 0x0, - &hdr_rb.transfer); + &hdr_rb.rpc_context[0].transfer[0]); } else { RPC_IFACE null_interface; ZERO_STRUCT(null_interface); diff --git a/source3/smbd/notify_kernel.c b/source3/smbd/notify_kernel.c index b2ccfc2796..6d1f550241 100644 --- a/source3/smbd/notify_kernel.c +++ b/source3/smbd/notify_kernel.c @@ -217,7 +217,6 @@ struct cnotify_fns *kernel_notify_init(void) ZERO_STRUCT(act); - act.sa_handler = NULL; act.sa_sigaction = signal_handler; act.sa_flags = SA_SIGINFO; sigemptyset( &act.sa_mask ); -- cgit