parse_rpc.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 862 行 · 第 1/2 页
C
862 行
/* * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-1997, * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, * Copyright (C) Paul Ashton 1997. * Copyright (C) Jeremy Allison 1999. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "includes.h"#undef DBGC_CLASS#define DBGC_CLASS DBGC_RPC_PARSE/*******************************************************************interface/version dce/rpc pipe identification********************************************************************/#define TRANS_SYNT_V2 \{ \ { \ 0x8a885d04, 0x1ceb, 0x11c9, \ { 0x9f, 0xe8 }, \ { 0x08, 0x00, \ 0x2b, 0x10, 0x48, 0x60 } \ }, 0x02 \}#define SYNT_NETLOGON_V2 \{ \ { \ 0x8a885d04, 0x1ceb, 0x11c9, \ { 0x9f, 0xe8 }, \ { 0x08, 0x00, \ 0x2b, 0x10, 0x48, 0x60 } \ }, 0x02 \}#define SYNT_WKSSVC_V1 \{ \ { \ 0x6bffd098, 0xa112, 0x3610, \ { 0x98, 0x33 }, \ { 0x46, 0xc3, \ 0xf8, 0x7e, 0x34, 0x5a } \ }, 0x01 \}#define SYNT_SRVSVC_V3 \{ \ { \ 0x4b324fc8, 0x1670, 0x01d3, \ { 0x12, 0x78 }, \ { 0x5a, 0x47, \ 0xbf, 0x6e, 0xe1, 0x88 } \ }, 0x03 \}#define SYNT_LSARPC_V0 \{ \ { \ 0x12345778, 0x1234, 0xabcd, \ { 0xef, 0x00 }, \ { 0x01, 0x23, \ 0x45, 0x67, 0x89, 0xab } \ }, 0x00 \}#define SYNT_LSARPC_V0_DS \{ \ { \ 0x3919286a, 0xb10c, 0x11d0, \ { 0x9b, 0xa8 }, \ { 0x00, 0xc0, \ 0x4f, 0xd9, 0x2e, 0xf5 } \ }, 0x00 \}#define SYNT_SAMR_V1 \{ \ { \ 0x12345778, 0x1234, 0xabcd, \ { 0xef, 0x00 }, \ { 0x01, 0x23, \ 0x45, 0x67, 0x89, 0xac } \ }, 0x01 \}#define SYNT_NETLOGON_V1 \{ \ { \ 0x12345678, 0x1234, 0xabcd, \ { 0xef, 0x00 }, \ { 0x01, 0x23, \ 0x45, 0x67, 0xcf, 0xfb } \ }, 0x01 \}#define SYNT_WINREG_V1 \{ \ { \ 0x338cd001, 0x2244, 0x31f1, \ { 0xaa, 0xaa }, \ { 0x90, 0x00, \ 0x38, 0x00, 0x10, 0x03 } \ }, 0x01 \}#define SYNT_SPOOLSS_V1 \{ \ { \ 0x12345678, 0x1234, 0xabcd, \ { 0xef, 0x00 }, \ { 0x01, 0x23, \ 0x45, 0x67, 0x89, 0xab } \ }, 0x01 \}#define SYNT_NONE_V0 \{ \ { \ 0x0, 0x0, 0x0, \ { 0x00, 0x00 }, \ { 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00 } \ }, 0x00 \}#define SYNT_NETDFS_V3 \{ \ { \ 0x4fc742e0, 0x4a10, 0x11cf, \ { 0x82, 0x73 }, \ { 0x00, 0xaa, \ 0x00, 0x4a, 0xe6, 0x73 } \ }, 0x03 \}#define SYNT_ECHO_V1 \{ \ { \ 0x60a15ec5, 0x4de8, 0x11d7, \ { 0xa6, 0x37 }, \ { 0x00, 0x50, \ 0x56, 0xa2, 0x01, 0x82 } \ }, 0x01 \}#define SYNT_SHUTDOWN_V1 \{ \ { \ 0x894de0c0, 0x0d55, 0x11d3, \ { 0xa3, 0x22 }, \ { 0x00, 0xc0, \ 0x4f, 0xa3, 0x21, 0xa1 } \ }, 0x01 \}#define SYNT_SVCCTL_V2 \{ \ { \ 0x367abb81, 0x9844, 0x35f1, \ { 0xad, 0x32 }, \ { 0x98, 0xf0, \ 0x38, 0x00, 0x10, 0x03 } \ }, 0x02 \}#define SYNT_EVENTLOG_V0 \{ \ { \ 0x82273fdc, 0xe32a, 0x18c3, \ { 0x3f, 0x78 }, \ { 0x82, 0x79, \ 0x29, 0xdc, 0x23, 0xea } \ }, 0x00 \}#define SYNT_UNIXINFO_V0 \{ \ { \ 0x9c54e310, 0xa955, 0x4885, \ { 0xbd, 0x31 }, \ { 0x78, 0x78, \ 0x71, 0x47, 0xdf, 0xa6 } \ }, 0x00 \}#define SYNT_NTSVCS_V1 \{ \ { \ 0x8d9f4e40, 0xa03d, 0x11ce, \ { 0x8f, 0x69}, \ { 0x08, 0x00, \ 0x3e, 0x30, 0x05, 0x1b } \ }, 0x01 \}/* * IMPORTANT!! If you update this structure, make sure to * update the index #defines in smb.h. */const struct pipe_id_info pipe_names [] ={ /* client pipe , abstract syntax , server pipe , transfer syntax */ { PIPE_LSARPC , SYNT_LSARPC_V0 , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_LSARPC , SYNT_LSARPC_V0_DS , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_SAMR , SYNT_SAMR_V1 , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_NETLOGON, SYNT_NETLOGON_V1 , PIPE_LSASS , TRANS_SYNT_V2 }, { PIPE_SRVSVC , SYNT_SRVSVC_V3 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { PIPE_WKSSVC , SYNT_WKSSVC_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { PIPE_WINREG , SYNT_WINREG_V1 , PIPE_WINREG , TRANS_SYNT_V2 }, { PIPE_SPOOLSS , SYNT_SPOOLSS_V1 , PIPE_SPOOLSS , TRANS_SYNT_V2 }, { PIPE_NETDFS , SYNT_NETDFS_V3 , PIPE_NETDFS , TRANS_SYNT_V2 }, { PIPE_ECHO , SYNT_ECHO_V1 , PIPE_ECHO , TRANS_SYNT_V2 }, { PIPE_SHUTDOWN, SYNT_SHUTDOWN_V1 , PIPE_SHUTDOWN , TRANS_SYNT_V2 }, { PIPE_SVCCTL , SYNT_SVCCTL_V2 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { PIPE_EVENTLOG, SYNT_EVENTLOG_V0 , PIPE_EVENTLOG , TRANS_SYNT_V2 }, { PIPE_NTSVCS , SYNT_NTSVCS_V1 , PIPE_NTSVCS , TRANS_SYNT_V2 }, { NULL , SYNT_NONE_V0 , NULL , SYNT_NONE_V0 }};/**************************************************************************** Return the pipe name from the index. ****************************************************************************/const char *cli_get_pipe_name(int pipe_idx){ return &pipe_names[pipe_idx].client_pipe[5];}/******************************************************************* Inits an RPC_HDR structure.********************************************************************/void init_rpc_hdr(RPC_HDR *hdr, enum RPC_PKT_TYPE pkt_type, uint8 flags, uint32 call_id, int data_len, int auth_len){ hdr->major = 5; /* RPC version 5 */ hdr->minor = 0; /* minor version 0 */ hdr->pkt_type = pkt_type; /* RPC packet type */ hdr->flags = flags; /* dce/rpc flags */ hdr->pack_type[0] = 0x10; /* little-endian data representation */ hdr->pack_type[1] = 0; /* packed data representation */ hdr->pack_type[2] = 0; /* packed data representation */ hdr->pack_type[3] = 0; /* packed data representation */ hdr->frag_len = data_len; /* fragment length, fill in later */ hdr->auth_len = auth_len; /* authentication length */ hdr->call_id = call_id; /* call identifier - match incoming RPC */}/******************************************************************* Reads or writes an RPC_HDR structure.********************************************************************/BOOL smb_io_rpc_hdr(const char *desc, RPC_HDR *rpc, prs_struct *ps, int depth){ if (rpc == NULL) return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr"); depth++; if(!prs_uint8 ("major ", ps, depth, &rpc->major)) return False; if(!prs_uint8 ("minor ", ps, depth, &rpc->minor)) return False; if(!prs_uint8 ("pkt_type ", ps, depth, &rpc->pkt_type)) return False; if(!prs_uint8 ("flags ", ps, depth, &rpc->flags)) return False; /* We always marshall in little endian format. */ if (MARSHALLING(ps)) rpc->pack_type[0] = 0x10; if(!prs_uint8("pack_type0", ps, depth, &rpc->pack_type[0])) return False; if(!prs_uint8("pack_type1", ps, depth, &rpc->pack_type[1])) return False; if(!prs_uint8("pack_type2", ps, depth, &rpc->pack_type[2])) return False; if(!prs_uint8("pack_type3", ps, depth, &rpc->pack_type[3])) return False; /* * If reading and pack_type[0] == 0 then the data is in big-endian * format. Set the flag in the prs_struct to specify reverse-endainness. */ if (UNMARSHALLING(ps) && rpc->pack_type[0] == 0) { DEBUG(10,("smb_io_rpc_hdr: PDU data format is big-endian. Setting flag.\n")); prs_set_endian_data(ps, RPC_BIG_ENDIAN); } if(!prs_uint16("frag_len ", ps, depth, &rpc->frag_len)) return False; if(!prs_uint16("auth_len ", ps, depth, &rpc->auth_len)) return False; if(!prs_uint32("call_id ", ps, depth, &rpc->call_id)) return False; return True;}/******************************************************************* Reads or writes an RPC_IFACE structure.********************************************************************/static BOOL smb_io_rpc_iface(const char *desc, RPC_IFACE *ifc, prs_struct *ps, int depth){ if (ifc == NULL) return False; prs_debug(ps, depth, desc, "smb_io_rpc_iface"); depth++; if (!prs_align(ps)) return False; if (!smb_io_uuid( "uuid", &ifc->uuid, ps, depth)) return False; if(!prs_uint32 ("version", ps, depth, &ifc->version)) return False; return True;}/******************************************************************* Inits an RPC_ADDR_STR structure.********************************************************************/static void init_rpc_addr_str(RPC_ADDR_STR *str, const char *name){ str->len = strlen(name) + 1; fstrcpy(str->str, name);}/******************************************************************* Reads or writes an RPC_ADDR_STR structure.********************************************************************/static BOOL smb_io_rpc_addr_str(const char *desc, RPC_ADDR_STR *str, prs_struct *ps, int depth){ if (str == NULL) return False; prs_debug(ps, depth, desc, "smb_io_rpc_addr_str"); depth++; if(!prs_align(ps)) return False; if(!prs_uint16 ( "len", ps, depth, &str->len)) return False; if(!prs_uint8s (True, "str", ps, depth, (uchar*)str->str, MIN(str->len, sizeof(str->str)) )) return False; return True;}/******************************************************************* Inits an RPC_HDR_BBA structure.********************************************************************/static void init_rpc_hdr_bba(RPC_HDR_BBA *bba, uint16 max_tsize, uint16 max_rsize, uint32 assoc_gid){ bba->max_tsize = max_tsize; /* maximum transmission fragment size (0x1630) */ bba->max_rsize = max_rsize; /* max receive fragment size (0x1630) */ bba->assoc_gid = assoc_gid; /* associated group id (0x0) */ }/******************************************************************* Reads or writes an RPC_HDR_BBA structure.********************************************************************/static BOOL smb_io_rpc_hdr_bba(const char *desc, RPC_HDR_BBA *rpc, prs_struct *ps, int depth){ if (rpc == NULL) return False; prs_debug(ps, depth, desc, "smb_io_rpc_hdr_bba"); depth++; if(!prs_uint16("max_tsize", ps, depth, &rpc->max_tsize)) return False; if(!prs_uint16("max_rsize", ps, depth, &rpc->max_rsize)) return False; if(!prs_uint32("assoc_gid", ps, depth, &rpc->assoc_gid)) return False; 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,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?