r6294: - add obfuscate support, which is used in MAPI rpc's, (the ^= 0xA5 stuff),
authorStefan Metzmacher <metze@samba.org>
Mon, 11 Apr 2005 13:25:38 +0000 (13:25 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:11:30 +0000 (13:11 -0500)
  based on a patch from j.kerihuel@openchange.org

- remove unused $ndr_flags argument for the ParseCompression*Start() function's

metze
(This used to be commit 27ccdd61822ba1a24244086522b9f8fe97fe0a78)

source4/build/pidl/ndr_parser.pm
source4/build/pidl/validator.pm
source4/librpc/config.mk
source4/librpc/ndr/ndr_obfuscate.c [new file with mode: 0644]

index 842402f4300fe3d6b9d5638c0093d9cdfb1b0328..6601dc10ffe1ce0b257a0a244b01441d53ab518f 100644 (file)
@@ -421,11 +421,10 @@ sub compression_dlen($)
        return ParseExpr($e, $dlen, "r->");
 }
 
-sub ParseCompressionPushStart($$$)
+sub ParseCompressionPushStart($$)
 {
        my $e = shift;
        my $subndr = shift;
-       my $ndr_flags = shift;
        my $comndr = $subndr."_compressed";
 
        pidl "{";
@@ -452,11 +451,10 @@ sub ParseCompressionPushEnd($$)
        pidl "}";
 }
 
-sub ParseCompressionPullStart($$$)
+sub ParseCompressionPullStart($$)
 {
        my $e = shift;
        my $subndr = shift;
-       my $ndr_flags = shift;
        my $comndr = $subndr."_compressed";
        my $alg = compression_alg($e);
        my $dlen = compression_dlen($e);
@@ -480,28 +478,69 @@ sub ParseCompressionPullEnd($$)
        pidl "}";
 }
 
+sub ParseObfuscationPushStart($$)
+{
+       my $e = shift;
+       my $ndr = shift;
+
+       # nothing to do here
+
+       return $ndr;
+}
+
+sub ParseObfuscationPushEnd($$)
+{
+       my $e = shift;
+       my $ndr = shift;
+       my $obfuscation = util::has_property($e, "obfuscation");
+
+       pidl "NDR_CHECK(ndr_push_obfuscation($ndr, $obfuscation));";
+}
+
+sub ParseObfuscationPullStart($$)
+{
+       my $e = shift;
+       my $ndr = shift;
+       my $obfuscation = util::has_property($e, "obfuscation");
+
+       pidl "NDR_CHECK(ndr_pull_obfuscation($ndr, $obfuscation));";
+
+       return $ndr;
+}
+
+sub ParseObfuscationPullEnd($$)
+{
+       my $e = shift;
+       my $ndr = shift;
+
+       # nothing to do here
+}
+
 sub ParseSubcontextPushStart($$)
 {
        my $e = shift;
        my $ndr_flags = shift;
        my $compression = util::has_property($e, "compression");
-       my $retndr;
+       my $obfuscation = util::has_property($e, "obfuscation");
+       my $retndr = "_ndr_$e->{NAME}";
 
        pidl "if (($ndr_flags) & NDR_SCALARS) {";
        indent;
-       pidl "struct ndr_push *_ndr_$e->{NAME};";
+       pidl "struct ndr_push *$retndr;";
        pidl "";
-       pidl "_ndr_$e->{NAME} = ndr_push_init_ctx(ndr);";
-       pidl "if (!_ndr_$e->{NAME}) return NT_STATUS_NO_MEMORY;";
-       pidl "_ndr_$e->{NAME}->flags = ndr->flags;";
+       pidl "$retndr = ndr_push_init_ctx(ndr);";
+       pidl "if (!$retndr) return NT_STATUS_NO_MEMORY;";
+       pidl "$retndr->flags = ndr->flags;";
        pidl "";
-       
-       $retndr = "_ndr_$e->{NAME}";
 
        if (defined $compression) {
-               $retndr = ParseCompressionPushStart($e, $retndr, "NDR_SCALARS");
+               $retndr = ParseCompressionPushStart($e, $retndr);
        }
-       
+
+       if (defined $obfuscation) {
+               $retndr = ParseObfuscationPushStart($e, $retndr);
+       }
+
        return $retndr
 }
 
@@ -511,8 +550,13 @@ sub ParseSubcontextPushEnd($)
        my $header_size = util::has_property($e, "subcontext");
        my $size_is = util::has_property($e, "subcontext_size");
        my $compression = util::has_property($e, "compression");
+       my $obfuscation = util::has_property($e, "obfuscation");
        my $ndr = "_ndr_$e->{NAME}";
 
+       if (defined $obfuscation) {
+               ParseObfuscationPushEnd($e, $ndr);
+       }
+
        if (defined $compression) {
                ParseCompressionPushEnd($e, $ndr);
        }
@@ -530,11 +574,12 @@ sub ParseSubcontextPushEnd($)
 sub ParseSubcontextPullStart($$)
 {
        my $e = shift;
-       my $ndr_flags = shift;  
+       my $ndr_flags = shift;
        my $header_size = util::has_property($e, "subcontext");
        my $size_is = util::has_property($e, "subcontext_size");
-       my $retndr = "_ndr_$e->{NAME}";
        my $compression = util::has_property($e, "compression");
+       my $obfuscation = util::has_property($e, "obfuscation");
+       my $retndr = "_ndr_$e->{NAME}";
 
        if (not defined($size_is)) {
                $size_is = "-1";
@@ -544,10 +589,14 @@ sub ParseSubcontextPullStart($$)
        indent;
        pidl "struct ndr_pull *$retndr;";
        pidl "NDR_ALLOC(ndr, $retndr);";
-       pidl "NDR_CHECK(ndr_pull_subcontext_header(ndr, $header_size, $size_is, $retndr));"; 
+       pidl "NDR_CHECK(ndr_pull_subcontext_header(ndr, $header_size, $size_is, $retndr));";
 
        if (defined $compression) {
-               $retndr = ParseCompressionPullStart($e, $retndr, $ndr_flags);
+               $retndr = ParseCompressionPullStart($e, $retndr);
+       }
+
+       if (defined $obfuscation) {
+               $retndr = ParseObfuscationPullStart($e, $retndr);
        }
        
        return $retndr;
@@ -558,20 +607,25 @@ sub ParseSubcontextPullEnd($)
        my $e = shift;
        my $header_size = util::has_property($e, "subcontext");
        my $size_is = util::has_property($e, "subcontext_size");
-       my $subndr = "_ndr_$e->{NAME}";
        my $compression = util::has_property($e, "compression");
+       my $obfuscation = util::has_property($e, "obfuscation");
+       my $ndr = "_ndr_$e->{NAME}";
+
+       if (defined $obfuscation) {
+               ParseObfuscationPullEnd($e, $ndr);
+       }
 
        if (defined $compression) {
-               ParseCompressionPullEnd($e, $subndr);
+               ParseCompressionPullEnd($e, $ndr);
        }
 
        my $advance;
        if (defined ($size_is)) {
-               $advance = "$size_is";  
+               $advance = "$size_is";
        } elsif ($header_size) {
-               $advance = "$subndr->data_size";
+               $advance = "$ndr->data_size";
        } else {
-               $advance = "$subndr->offset";
+               $advance = "$ndr->offset";
        }
        pidl "NDR_CHECK(ndr_pull_advance(ndr, $advance));";
        deindent;
index 7bd82f150690a8d9800fef66ad12550561650635..42e9f699dc38dc14cd6ca85c5cf4ba704b5fc45c 100644 (file)
@@ -86,6 +86,7 @@ my %property_list = (
        "subcontext"            => {},
        "subcontext_size"       => {},
        "compression"           => {},
+       "obfuscation"           => {},
 
        # enum
        "enum8bit"              => {},
@@ -167,6 +168,10 @@ sub ValidElement($)
                fatal(el_name($e) . " : compression() on non-subcontext element");
        }
 
+       if (defined (util::has_property($e, "obfuscation")) and not defined(util::has_property($e, "subcontext"))) {
+               fatal(el_name($e) . " : obfuscation() on non-subcontext element");
+       }
+
        if (!$e->{POINTERS} && (
                util::has_property($e, "ptr") or
                util::has_property($e, "unique") or
index 770d2416d556dc6a4f1320a2b46a7967eb346a41..be4d5361089cb3653c03ef36a9269c510f3cbaa0 100644 (file)
@@ -6,6 +6,7 @@ INIT_OBJ_FILES = \
 ADD_OBJ_FILES = \
                librpc/ndr/ndr_basic.o \
                librpc/ndr/ndr_compression.o \
+               librpc/ndr/ndr_obfuscate.o \
                librpc/ndr/ndr_misc.o
 REQUIRED_SUBSYSTEMS = LIBCLI_UTILS LIBCOMPRESSION
 # End SUBSYSTEM LIBNDR_RAW
diff --git a/source4/librpc/ndr/ndr_obfuscate.c b/source4/librpc/ndr/ndr_obfuscate.c
new file mode 100644 (file)
index 0000000..4f875f1
--- /dev/null
@@ -0,0 +1,52 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   libndr obfuscate support (MAPI)
+
+   Copyright (C) Stefan Metzmacher 2005
+   
+   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"
+
+/*
+  handle obfuscated subcontext buffers, which in midl land are user-marshalled, but
+  we use magic in pidl to make them easier to cope with
+*/
+NTSTATUS ndr_pull_obfuscation(struct ndr_pull *ndr, uint8_t salt)
+{
+       uint32_t i;
+
+       for (i=0; i<ndr->data_size; i++) {
+               ndr->data[i] ^= salt;
+       }
+
+       return NT_STATUS_OK;
+}
+
+/*
+  push a obfuscated subcontext
+*/
+NTSTATUS ndr_push_obfuscation(struct ndr_push *ndr, uint8_t salt)
+{
+       uint32_t i;
+
+       for (i=0; i<ndr->offset; i++) {
+               ndr->data[i] ^= salt;
+       }
+
+       return NT_STATUS_OK;
+}