dcerpc.idl: add dcerpc_sec_verification_trailer
authorStefan Metzmacher <metze@samba.org>
Thu, 2 Jan 2014 10:18:38 +0000 (11:18 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 6 Jan 2014 23:27:12 +0000 (00:27 +0100)
See [MS-RPCE] 2.2.2.13 Verification Trailer for details.

Pair-Programmed-With: Gregor Beck <gbeck@sernet.de>

Signed-off-by: Gregor Beck <gbeck@sernet.de>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
librpc/idl/dcerpc.idl
librpc/ndr/ndr_dcerpc.c [new file with mode: 0644]
librpc/wscript_build

index 23cac89464c07bfb87ef955610574c5b904f3526..8e9be0ee40b86df9a57ba0611a1284b151b418f2 100644 (file)
@@ -19,6 +19,8 @@
 */
 import "misc.idl";
 
+cpp_quote("extern const uint8_t DCERPC_SEC_VT_MAGIC[8];")
+
 interface dcerpc
 {
        typedef struct {
@@ -514,4 +516,69 @@ interface dcerpc
                uint8 serial_low;
                [switch_is(ptype)] dcerpc_payload u;
        } ncadg_packet;
+
+       typedef [bitmap16bit] bitmap {
+               DCERPC_SEC_VT_COMMAND_ENUM  = 0x3FFF,
+               DCERPC_SEC_VT_COMMAND_END   = 0x4000,
+               DCERPC_SEC_VT_MUST_PROCESS  = 0x8000
+       } dcerpc_sec_vt_command;
+
+       typedef [enum16bit] enum {
+               DCERPC_SEC_VT_COMMAND_BITMASK1  = 0x0001,
+               DCERPC_SEC_VT_COMMAND_PCONTEXT  = 0x0002,
+               DCERPC_SEC_VT_COMMAND_HEADER2   = 0x0003
+       } dcerpc_sec_vt_command_enum;
+
+       typedef [bitmap32bit] bitmap {
+               DCERPC_SEC_VT_CLIENT_SUPPORTS_HEADER_SIGNING = 0x00000001
+       } dcerpc_sec_vt_bitmask1;
+
+       typedef struct {
+               ndr_syntax_id abstract_syntax;
+               ndr_syntax_id transfer_syntax;
+       } dcerpc_sec_vt_pcontext;
+
+       typedef struct {
+               dcerpc_pkt_type ptype;  /* Packet type */
+               [value(0)] uint8 reserved1;
+               [value(0)] uint16 reserved2;
+               uint8 drep[4];          /* NDR data representation */
+               uint32 call_id;         /* Call identifier */
+               uint16 context_id;
+               uint16 opnum;
+       } dcerpc_sec_vt_header2;
+
+       typedef [switch_type(dcerpc_sec_vt_command_enum),nodiscriminant] union {
+       [case(DCERPC_SEC_VT_COMMAND_BITMASK1)] dcerpc_sec_vt_bitmask1 bitmask1;
+       [case(DCERPC_SEC_VT_COMMAND_PCONTEXT)] dcerpc_sec_vt_pcontext pcontext;
+       [case(DCERPC_SEC_VT_COMMAND_HEADER2)] dcerpc_sec_vt_header2 header2;
+       [default,flag(NDR_REMAINING)] DATA_BLOB _unknown;
+       } dcerpc_sec_vt_union;
+
+       typedef struct {
+               dcerpc_sec_vt_command command;
+               [switch_is(command & DCERPC_SEC_VT_COMMAND_ENUM)]
+                       [subcontext(2),flag(NDR_SUBCONTEXT_NO_UNREAD_BYTES)]
+                       dcerpc_sec_vt_union u;
+       } dcerpc_sec_vt;
+
+       typedef [public,nopush,nopull] struct {
+               uint16 count;
+       } dcerpc_sec_vt_count;
+
+       /*
+        * We assume that the whole verification trailer fits into
+        * the last 1024 bytes after the stub data.
+        *
+        * There're currently only 3 commands defined and each should
+        * only be used once.
+        */
+       const uint16 DCERPC_SEC_VT_MAX_SIZE = 1024;
+
+       typedef [public,flag(NDR_PAHEX)] struct {
+               [flag(NDR_ALIGN4)] DATA_BLOB _pad;
+               [value(DCERPC_SEC_VT_MAGIC)] uint8 magic[8];
+               dcerpc_sec_vt_count count;
+               dcerpc_sec_vt commands[count.count];
+       } dcerpc_sec_verification_trailer;
 }
diff --git a/librpc/ndr/ndr_dcerpc.c b/librpc/ndr/ndr_dcerpc.c
new file mode 100644 (file)
index 0000000..88a7f38
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Manually parsed structures found in the DCERPC protocol
+
+   Copyright (C) Stefan Metzmacher 2014
+   Copyright (C) Gregor Beck 2014
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "bin/default/librpc/gen_ndr/ndr_dcerpc.h"
+
+#include "librpc/gen_ndr/ndr_misc.h"
+
+const uint8_t DCERPC_SEC_VT_MAGIC[] = {0x8a,0xe3,0x13,0x71,0x02,0xf4,0x36,0x71};
+
+_PUBLIC_ enum ndr_err_code ndr_push_dcerpc_sec_vt_count(struct ndr_push *ndr, int ndr_flags, const struct dcerpc_sec_vt_count *r)
+{
+       NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
+       /* nothing */
+       return NDR_ERR_SUCCESS;
+}
+
+_PUBLIC_ enum ndr_err_code ndr_pull_dcerpc_sec_vt_count(struct ndr_pull *ndr, int ndr_flags, struct dcerpc_sec_vt_count *r)
+{
+       uint32_t _saved_ofs = ndr->offset;
+
+       NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
+
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NDR_ERR_SUCCESS;
+       }
+
+       r->count = 0;
+
+       while (true) {
+               uint16_t command;
+               uint16_t length;
+
+               NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &command));
+               NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &length));
+               NDR_CHECK(ndr_pull_advance(ndr, length));
+
+               r->count += 1;
+
+               if (command & DCERPC_SEC_VT_COMMAND_END) {
+                       break;
+               }
+       }
+
+       ndr->offset = _saved_ofs;
+       return NDR_ERR_SUCCESS;
+}
index 2017a291fc379b9c740f3419f0a6b58ea680e042..a5cf687f1bf4c7774d4f50d00e286de8d46347de 100644 (file)
@@ -301,7 +301,7 @@ bld.SAMBA_SUBSYSTEM('NDR_FSRVP',
        )
 
 bld.SAMBA_SUBSYSTEM('NDR_DCERPC',
-    source='gen_ndr/ndr_dcerpc.c',
+    source='gen_ndr/ndr_dcerpc.c ndr/ndr_dcerpc.c',
     public_deps='ndr',
     public_headers='gen_ndr/ndr_dcerpc.h gen_ndr/dcerpc.h',
     header_path= [ ('*gen_ndr*', 'gen_ndr') ],