summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-04-11 13:25:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:11:30 -0500
commit5eff721651a7d8a56891319dbcf3616a2a09be19 (patch)
tree2b82520e6b308b0a17fe33cb1315377f060ce241 /source4
parent0af9ba91794468d23eee47eb6e3092251df03adb (diff)
downloadsamba-5eff721651a7d8a56891319dbcf3616a2a09be19.tar.gz
samba-5eff721651a7d8a56891319dbcf3616a2a09be19.tar.bz2
samba-5eff721651a7d8a56891319dbcf3616a2a09be19.zip
r6294: - add obfuscate support, which is used in MAPI rpc's, (the ^= 0xA5 stuff),
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)
Diffstat (limited to 'source4')
-rw-r--r--source4/build/pidl/ndr_parser.pm98
-rw-r--r--source4/build/pidl/validator.pm5
-rw-r--r--source4/librpc/config.mk1
-rw-r--r--source4/librpc/ndr/ndr_obfuscate.c52
4 files changed, 134 insertions, 22 deletions
diff --git a/source4/build/pidl/ndr_parser.pm b/source4/build/pidl/ndr_parser.pm
index 842402f430..6601dc10ff 100644
--- a/source4/build/pidl/ndr_parser.pm
+++ b/source4/build/pidl/ndr_parser.pm
@@ -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;
diff --git a/source4/build/pidl/validator.pm b/source4/build/pidl/validator.pm
index 7bd82f1506..42e9f699dc 100644
--- a/source4/build/pidl/validator.pm
+++ b/source4/build/pidl/validator.pm
@@ -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
diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk
index 770d2416d5..be4d536108 100644
--- a/source4/librpc/config.mk
+++ b/source4/librpc/config.mk
@@ -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
index 0000000000..4f875f19a7
--- /dev/null
+++ b/source4/librpc/ndr/ndr_obfuscate.c
@@ -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;
+}