diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 14 | ||||
-rw-r--r-- | source3/include/rpc_client.h | 1 | ||||
-rw-r--r-- | source3/include/smb.h | 5 | ||||
-rw-r--r-- | source3/lib/compression/mszip.c | 676 | ||||
-rw-r--r-- | source3/lib/compression/mszip.h | 33 | ||||
-rw-r--r-- | source3/librpc/ndr/libndr.h | 3 | ||||
-rw-r--r-- | source3/librpc/ndr/ndr_compression.c | 293 | ||||
-rw-r--r-- | source3/librpc/ndr/ndr_compression.h | 51 | ||||
-rw-r--r-- | source3/librpc/ndr/ndr_drsuapi.c | 180 | ||||
-rw-r--r-- | source3/librpc/ndr/ndr_drsuapi.h | 35 | ||||
-rw-r--r-- | source3/libsmb/asn1.c | 84 | ||||
-rw-r--r-- | source3/rpc_parse/parse_rpc.c | 1 |
12 files changed, 1373 insertions, 3 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index f9d0753bb6..b42a99902b 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -274,6 +274,13 @@ SERVER_MUTEX_OBJ = lib/server_mutex.o PASSCHANGE_OBJ = libsmb/passchange.o +LIBNDR_DRSUAPI_OBJ = librpc/ndr/ndr_drsuapi.o \ + librpc/ndr/ndr_compression.o + +COMPRESSION_OBJ = lib/compression/mszip.o + +DRSUAPI_OBJ = $(LIBNDR_DRSUAPI_OBJ) \ + $(COMPRESSION_OBJ) LIBNDR_OBJ = librpc/ndr/ndr_basic.o \ librpc/ndr/ndr.o \ @@ -283,7 +290,8 @@ LIBNDR_OBJ = librpc/ndr/ndr_basic.o \ librpc/ndr/ndr_sec_helper.o \ librpc/ndr/ndr_string.o \ librpc/ndr/sid.o \ - librpc/ndr/uuid.o + librpc/ndr/uuid.o \ + $(DRSUAPI_OBJ) RPCCLIENT_NDR_OBJ = rpc_client/ndr.o @@ -301,7 +309,8 @@ LIBNDR_GEN_OBJ = librpc/gen_ndr/ndr_wkssvc.o \ librpc/gen_ndr/ndr_notify.o \ librpc/gen_ndr/ndr_xattr.o \ librpc/gen_ndr/ndr_epmapper.o \ - librpc/gen_ndr/ndr_ntsvcs.o + librpc/gen_ndr/ndr_ntsvcs.o \ + librpc/gen_ndr/ndr_drsuapi.o RPC_PARSE_OBJ0 = rpc_parse/parse_prs.o rpc_parse/parse_misc.o @@ -478,6 +487,7 @@ LIBMSRPC_GEN_OBJ = librpc/gen_ndr/cli_lsa.o \ librpc/gen_ndr/cli_dssetup.o \ librpc/gen_ndr/cli_ntsvcs.o \ librpc/gen_ndr/cli_epmapper.o \ + librpc/gen_ndr/cli_drsuapi.o \ $(LIBNDR_GEN_OBJ) \ $(RPCCLIENT_NDR_OBJ) diff --git a/source3/include/rpc_client.h b/source3/include/rpc_client.h index 4d1b1a77d1..466370ef7a 100644 --- a/source3/include/rpc_client.h +++ b/source3/include/rpc_client.h @@ -36,6 +36,7 @@ #include "librpc/gen_ndr/cli_dssetup.h" #include "librpc/gen_ndr/cli_ntsvcs.h" #include "librpc/gen_ndr/cli_epmapper.h" +#include "librpc/gen_ndr/cli_drsuapi.h" #define prs_init_empty( _ps_, _ctx_, _io_ ) (void) prs_init((_ps_), 0, (_ctx_), (_io_)) diff --git a/source3/include/smb.h b/source3/include/smb.h index 02151043a6..e7860b7903 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -190,6 +190,7 @@ typedef uint32 codepoint_t; #define PIPE_SVCCTL "\\PIPE\\svcctl" #define PIPE_EVENTLOG "\\PIPE\\eventlog" #define PIPE_EPMAPPER "\\PIPE\\epmapper" +#define PIPE_DRSUAPI "\\PIPE\\drsuapi" #define PIPE_NETLOGON_PLAIN "\\NETLOGON" @@ -208,7 +209,8 @@ typedef uint32 codepoint_t; #define PI_EVENTLOG 12 #define PI_NTSVCS 13 #define PI_EPMAPPER 14 -#define PI_MAX_PIPES 15 +#define PI_DRSUAPI 15 +#define PI_MAX_PIPES 16 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */ typedef uint64_t NTTIME; @@ -314,6 +316,7 @@ extern const DATA_BLOB data_blob_null; #include "librpc/gen_ndr/krb5pac.h" #include "librpc/gen_ndr/ntsvcs.h" #include "librpc/gen_ndr/nbt.h" +#include "librpc/gen_ndr/drsuapi.h" struct lsa_dom_info { bool valid; diff --git a/source3/lib/compression/mszip.c b/source3/lib/compression/mszip.c new file mode 100644 index 0000000000..aeeb2d8afd --- /dev/null +++ b/source3/lib/compression/mszip.c @@ -0,0 +1,676 @@ +/* mszip decompression - based on cabextract.c code from + * Stuart Caie + * + * adapted for Samba by Andrew Tridgell and Stefan Metzmacher 2005 + * + * (C) 2000-2001 Stuart Caie <kyzer@4u.net> + * reaktivate-specifics by Malte Starostik <malte@kde.org> + * + * 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 "lib/compression/mszip.h" + +/*--------------------------------------------------------------------------*/ +/* our archiver information / state */ + +/* MSZIP stuff */ +#define ZIPWSIZE 0x8000 /* window size */ +#define ZIPLBITS 9 /* bits in base literal/length lookup table */ +#define ZIPDBITS 6 /* bits in base distance lookup table */ +#define ZIPBMAX 16 /* maximum bit length of any code */ +#define ZIPN_MAX 288 /* maximum number of codes in any set */ + +struct Ziphuft { + uint8_t e; /* number of extra bits or operation */ + uint8_t b; /* number of bits in this code or subcode */ + union { + uint16_t n; /* literal, length base, or distance base */ + struct Ziphuft *t; /* pointer to next level of table */ + } v; +}; + +struct ZIPstate { + uint32_t window_posn; /* current offset within the window */ + uint32_t bb; /* bit buffer */ + uint32_t bk; /* bits in bit buffer */ + uint32_t ll[288+32]; /* literal/length and distance code lengths */ + uint32_t c[ZIPBMAX+1]; /* bit length count table */ + int32_t lx[ZIPBMAX+1]; /* memory for l[-1..ZIPBMAX-1] */ + struct Ziphuft *u[ZIPBMAX]; /* table stack */ + uint32_t v[ZIPN_MAX]; /* values in order of bit length */ + uint32_t x[ZIPBMAX+1]; /* bit offsets, then code stack */ + uint8_t *inpos; +}; + +/* generic stuff */ +#define CAB(x) (decomp_state->x) +#define ZIP(x) (decomp_state->methods.zip.x) + +/* CAB data blocks are <= 32768 bytes in uncompressed form. Uncompressed + * blocks have zero growth. MSZIP guarantees that it won't grow above + * uncompressed size by more than 12 bytes. LZX guarantees it won't grow + * more than 6144 bytes. + */ +#define CAB_BLOCKMAX (32768) +#define CAB_INPUTMAX (CAB_BLOCKMAX+6144) + +struct decomp_state { + struct folder *current; /* current folder we're extracting from */ + uint32_t offset; /* uncompressed offset within folder */ + uint8_t *outpos; /* (high level) start of data to use up */ + uint16_t outlen; /* (high level) amount of data to use up */ + uint16_t split; /* at which split in current folder? */ + int (*decompress)(int, int); /* the chosen compression func */ + uint8_t inbuf[CAB_INPUTMAX+2]; /* +2 for lzx bitbuffer overflows! */ + uint8_t outbuf[CAB_BLOCKMAX]; + union { + struct ZIPstate zip; + } methods; +}; + + +/* MSZIP decruncher */ + +/* Dirk Stoecker wrote the ZIP decoder, based on the InfoZip deflate code */ + +/* Tables for deflate from PKZIP's appnote.txt. */ +static const uint8_t Zipborder[] = /* Order of the bit length code lengths */ +{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; +static const uint16_t Zipcplens[] = /* Copy lengths for literal codes 257..285 */ +{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, + 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; +static const uint16_t Zipcplext[] = /* Extra bits for literal codes 257..285 */ +{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, + 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */ +static const uint16_t Zipcpdist[] = /* Copy offsets for distance codes 0..29 */ +{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, +513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; +static const uint16_t Zipcpdext[] = /* Extra bits for distance codes */ +{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, +10, 11, 11, 12, 12, 13, 13}; + +/* And'ing with Zipmask[n] masks the lower n bits */ +static const uint16_t Zipmask[17] = { + 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff +}; + +#define ZIPNEEDBITS(n) {while(k<(n)){int32_t c=*(ZIP(inpos)++);\ + b|=((uint32_t)c)<<k;k+=8;}} +#define ZIPDUMPBITS(n) {b>>=(n);k-=(n);} + +static void Ziphuft_free(struct Ziphuft *t) +{ + register struct Ziphuft *p, *q; + + /* Go through linked list, freeing from the allocated (t[-1]) address. */ + p = t; + while (p != (struct Ziphuft *)NULL) + { + q = (--p)->v.t; + free(p); + p = q; + } +} + +static int32_t Ziphuft_build(struct decomp_state *decomp_state, + uint32_t *b, uint32_t n, uint32_t s, const uint16_t *d, const uint16_t *e, + struct Ziphuft **t, int32_t *m) +{ + uint32_t a; /* counter for codes of length k */ + uint32_t el; /* length of EOB code (value 256) */ + uint32_t f; /* i repeats in table every f entries */ + int32_t g; /* maximum code length */ + int32_t h; /* table level */ + register uint32_t i; /* counter, current code */ + register uint32_t j; /* counter */ + register int32_t k; /* number of bits in current code */ + int32_t *l; /* stack of bits per table */ + register uint32_t *p; /* pointer into ZIP(c)[],ZIP(b)[],ZIP(v)[] */ + register struct Ziphuft *q; /* points to current table */ + struct Ziphuft r; /* table entry for structure assignment */ + register int32_t w; /* bits before this table == (l * h) */ + uint32_t *xp; /* pointer into x */ + int32_t y; /* number of dummy codes added */ + uint32_t z; /* number of entries in current table */ + + l = ZIP(lx)+1; + + /* Generate counts for each bit length */ + el = n > 256 ? b[256] : ZIPBMAX; /* set length of EOB code, if any */ + + for(i = 0; i < ZIPBMAX+1; ++i) + ZIP(c)[i] = 0; + p = b; i = n; + do + { + ZIP(c)[*p]++; p++; /* assume all entries <= ZIPBMAX */ + } while (--i); + if (ZIP(c)[0] == n) /* null input--all zero length codes */ + { + *t = (struct Ziphuft *)NULL; + *m = 0; + return 0; + } + + /* Find minimum and maximum length, bound *m by those */ + for (j = 1; j <= ZIPBMAX; j++) + if (ZIP(c)[j]) + break; + k = j; /* minimum code length */ + if ((uint32_t)*m < j) + *m = j; + for (i = ZIPBMAX; i; i--) + if (ZIP(c)[i]) + break; + g = i; /* maximum code length */ + if ((uint32_t)*m > i) + *m = i; + + /* Adjust last length count to fill out codes, if needed */ + for (y = 1 << j; j < i; j++, y <<= 1) + if ((y -= ZIP(c)[j]) < 0) + return 2; /* bad input: more codes than bits */ + if ((y -= ZIP(c)[i]) < 0) + return 2; + ZIP(c)[i] += y; + + /* Generate starting offsets int32_to the value table for each length */ + ZIP(x)[1] = j = 0; + p = ZIP(c) + 1; xp = ZIP(x) + 2; + while (--i) + { /* note that i == g from above */ + *xp++ = (j += *p++); + } + + /* Make a table of values in order of bit lengths */ + p = b; i = 0; + do{ + if ((j = *p++) != 0) + ZIP(v)[ZIP(x)[j]++] = i; + } while (++i < n); + + + /* Generate the Huffman codes and for each, make the table entries */ + ZIP(x)[0] = i = 0; /* first Huffman code is zero */ + p = ZIP(v); /* grab values in bit order */ + h = -1; /* no tables yet--level -1 */ + w = l[-1] = 0; /* no bits decoded yet */ + ZIP(u)[0] = (struct Ziphuft *)NULL; /* just to keep compilers happy */ + q = (struct Ziphuft *)NULL; /* ditto */ + z = 0; /* ditto */ + + /* go through the bit lengths (k already is bits in shortest code) */ + for (; k <= g; k++) + { + a = ZIP(c)[k]; + while (a--) + { + /* here i is the Huffman code of length k bits for value *p */ + /* make tables up to required level */ + while (k > w + l[h]) + { + w += l[h++]; /* add bits already decoded */ + + /* compute minimum size table less than or equal to *m bits */ + z = (z = g - w) > (uint32_t)*m ? *m : z; /* upper limit */ + if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ + { /* too few codes for k-w bit table */ + f -= a + 1; /* deduct codes from patterns left */ + xp = ZIP(c) + k; + while (++j < z) /* try smaller tables up to z bits */ + { + if ((f <<= 1) <= *++xp) + break; /* enough codes to use up j bits */ + f -= *xp; /* else deduct codes from patterns */ + } + } + if ((uint32_t)w + j > el && (uint32_t)w < el) + j = el - w; /* make EOB code end at table */ + z = 1 << j; /* table entries for j-bit table */ + l[h] = j; /* set table size in stack */ + + /* allocate and link in new table */ + if (!(q = (struct Ziphuft *)SMB_MALLOC((z + 1)*sizeof(struct Ziphuft)))) + { + if(h) + Ziphuft_free(ZIP(u)[0]); + return 3; /* not enough memory */ + } + *t = q + 1; /* link to list for Ziphuft_free() */ + *(t = &(q->v.t)) = (struct Ziphuft *)NULL; + ZIP(u)[h] = ++q; /* table starts after link */ + + /* connect to last table, if there is one */ + if (h) + { + ZIP(x)[h] = i; /* save pattern for backing up */ + r.b = (uint8_t)l[h-1]; /* bits to dump before this table */ + r.e = (uint8_t)(16 + j); /* bits in this table */ + r.v.t = q; /* pointer to this table */ + j = (i & ((1 << w) - 1)) >> (w - l[h-1]); + ZIP(u)[h-1][j] = r; /* connect to last table */ + } + } + + /* set up table entry in r */ + r.b = (uint8_t)(k - w); + if (p >= ZIP(v) + n) + r.e = 99; /* out of values--invalid code */ + else if (*p < s) + { + r.e = (uint8_t)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */ + r.v.n = *p++; /* simple code is just the value */ + } + else + { + r.e = (uint8_t)e[*p - s]; /* non-simple--look up in lists */ + r.v.n = d[*p++ - s]; + } + + /* fill code-like entries with r */ + f = 1 << (k - w); + for (j = i >> w; j < z; j += f) + q[j] = r; + + /* backwards increment the k-bit code i */ + for (j = 1 << (k - 1); i & j; j >>= 1) + i ^= j; + i ^= j; + + /* backup over finished tables */ + while ((i & ((1 << w) - 1)) != ZIP(x)[h]) + w -= l[--h]; /* don't need to update q */ + } + } + + /* return actual size of base table */ + *m = l[0]; + + /* Return true (1) if we were given an incomplete table */ + return y != 0 && g != 1; +} + +static int32_t Zipinflate_codes(struct decomp_state *decomp_state, + struct Ziphuft *tl, struct Ziphuft *td, + int32_t bl, int32_t bd) +{ + register uint32_t e; /* table entry flag/number of extra bits */ + uint32_t n, d; /* length and index for copy */ + uint32_t w; /* current window position */ + struct Ziphuft *t; /* pointer to table entry */ + uint32_t ml, md; /* masks for bl and bd bits */ + register uint32_t b; /* bit buffer */ + register uint32_t k; /* number of bits in bit buffer */ + + DEBUG(10,("Zipinflate_codes\n")); + + /* make local copies of globals */ + b = ZIP(bb); /* initialize bit buffer */ + k = ZIP(bk); + w = ZIP(window_posn); /* initialize window position */ + + /* inflate the coded data */ + ml = Zipmask[bl]; /* precompute masks for speed */ + md = Zipmask[bd]; + + for(;;) + { + ZIPNEEDBITS((uint32_t)bl) + if((e = (t = tl + ((uint32_t)b & ml))->e) > 16) + do + { + if (e == 99) + return 1; + ZIPDUMPBITS(t->b) + e -= 16; + ZIPNEEDBITS(e) + } while ((e = (t = t->v.t + ((uint32_t)b & Zipmask[e]))->e) > 16); + ZIPDUMPBITS(t->b) + if (w >= CAB_BLOCKMAX) break; + if (e == 16) /* then it's a literal */ + CAB(outbuf)[w++] = (uint8_t)t->v.n; + else /* it's an EOB or a length */ + { + /* exit if end of block */ + if(e == 15) + break; + + /* get length of block to copy */ + ZIPNEEDBITS(e) + n = t->v.n + ((uint32_t)b & Zipmask[e]); + ZIPDUMPBITS(e); + + /* decode distance of block to copy */ + ZIPNEEDBITS((uint32_t)bd) + if ((e = (t = td + ((uint32_t)b & md))->e) > 16) + do { + if (e == 99) + return 1; + ZIPDUMPBITS(t->b) + e -= 16; + ZIPNEEDBITS(e) + } while ((e = (t = t->v.t + ((uint32_t)b & Zipmask[e]))->e) > 16); + ZIPDUMPBITS(t->b) + ZIPNEEDBITS(e) + d = w - t->v.n - ((uint32_t)b & Zipmask[e]); + ZIPDUMPBITS(e) + do + { + n -= (e = (e = ZIPWSIZE - ((d &= ZIPWSIZE-1) > w ? d : w)) > n ?n:e); + do + { + CAB(outbuf)[w++] = CAB(outbuf)[d++]; + } while (--e); + } while (n); + } + } + + /* restore the globals from the locals */ + ZIP(window_posn) = w; /* restore global window pointer */ + ZIP(bb) = b; /* restore global bit buffer */ + ZIP(bk) = k; + + /* done */ + return 0; +} + +/* "decompress" an inflated type 0 (stored) block. */ +static int32_t Zipinflate_stored(struct decomp_state *decomp_state) +{ + uint32_t n; /* number of bytes in block */ + uint32_t w; /* current window position */ + register uint32_t b; /* bit buffer */ + register uint32_t k; /* number of bits in bit buffer */ + + /* make local copies of globals */ + b = ZIP(bb); /* initialize bit buffer */ + k = ZIP(bk); + w = ZIP(window_posn); /* initialize window position */ + + /* go to byte boundary */ + n = k & 7; + ZIPDUMPBITS(n); + + /* get the length and its complement */ + ZIPNEEDBITS(16) + n = ((uint32_t)b & 0xffff); + ZIPDUMPBITS(16) + ZIPNEEDBITS(16) + if (n != (uint32_t)((~b) & 0xffff)) + return 1; /* error in compressed data */ + ZIPDUMPBITS(16) + + /* read and output the compressed data */ + while(n--) + { + ZIPNEEDBITS(8) + CAB(outbuf)[w++] = (uint8_t)b; + ZIPDUMPBITS(8) + } + + /* restore the globals from the locals */ + ZIP(window_posn) = w; /* restore global window pointer */ + ZIP(bb) = b; /* restore global bit buffer */ + ZIP(bk) = k; + return 0; +} + +static int32_t Zipinflate_fixed(struct decomp_state *decomp_state) +{ + struct Ziphuft *fixed_tl; + struct Ziphuft *fixed_td; + int32_t fixed_bl, fixed_bd; + int32_t i; /* temporary variable */ + uint32_t *l; + + l = ZIP(ll); + + /* literal table */ + for(i = 0; i < 144; i++) + l[i] = 8; + for(; i < 256; i++) + l[i] = 9; + for(; i < 280; i++) + l[i] = 7; + for(; i < 288; i++) /* make a complete, but wrong code set */ + l[i] = 8; + fixed_bl = 7; + if((i = Ziphuft_build(decomp_state, l, 288, 257, Zipcplens, Zipcplext, &fixed_tl, &fixed_bl))) + return i; + + /* distance table */ + for(i = 0; i < 30; i++) /* make an incomplete code set */ + l[i] = 5; + fixed_bd = 5; + if((i = Ziphuft_build(decomp_state, l, 30, 0, Zipcpdist, Zipcpdext, &fixed_td, &fixed_bd)) > 1) + { + Ziphuft_free(fixed_tl); + return i; + } + + /* decompress until an end-of-block code */ + i = Zipinflate_codes(decomp_state, fixed_tl, fixed_td, fixed_bl, fixed_bd); + + Ziphuft_free(fixed_td); + Ziphuft_free(fixed_tl); + return i; +} + +/* decompress an inflated type 2 (dynamic Huffman codes) block. */ +static int32_t Zipinflate_dynamic(struct decomp_state *decomp_state) +{ + int32_t i; /* temporary variables */ + uint32_t j; + uint32_t *ll; + uint32_t l; /* last length */ + uint32_t m; /* mask for bit lengths table */ + uint32_t n; /* number of lengths to get */ + struct Ziphuft *tl; /* literal/length code table */ + struct Ziphuft *td; /* distance code table */ + int32_t bl; /* lookup bits for tl */ + int32_t bd; /* lookup bits for td */ + uint32_t nb; /* number of bit length codes */ + uint32_t nl; /* number of literal/length codes */ + uint32_t nd; /* number of distance codes */ + register uint32_t b; /* bit buffer */ + register uint32_t k; /* number of bits in bit buffer */ + + /* make local bit buffer */ + b = ZIP(bb); + k = ZIP(bk); + ll = ZIP(ll); + + /* read in table lengths */ + ZIPNEEDBITS(5) + nl = 257 + ((uint32_t)b & 0x1f); /* number of literal/length codes */ + ZIPDUMPBITS(5) + ZIPNEEDBITS(5) + nd = 1 + ((uint32_t)b & 0x1f); /* number of distance codes */ + ZIPDUMPBITS(5) + ZIPNEEDBITS(4) + nb = 4 + ((uint32_t)b & 0xf); /* number of bit length codes */ + ZIPDUMPBITS(4) + if(nl > 288 || nd > 32) + return 1; /* bad lengths */ + + /* read in bit-length-code lengths */ + for(j = 0; j < nb; j++) + { + ZIPNEEDBITS(3) + ll[Zipborder[j]] = (uint32_t)b & 7; + ZIPDUMPBITS(3) + } + for(; j < 19; j++) + ll[Zipborder[j]] = 0; + + /* build decoding table for trees--single level, 7 bit lookup */ + bl = 7; + if((i = Ziphuft_build(decomp_state, ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) + { + if(i == 1) + Ziphuft_free(tl); + return i; /* incomplete code set */ + } + + /* read in literal and distance code lengths */ + n = nl + nd; + m = Zipmask[bl]; + i = l = 0; + while((uint32_t)i < n) + { + ZIPNEEDBITS((uint32_t)bl) + j = (td = tl + ((uint32_t)b & m))->b; + ZIPDUMPBITS(j) + j = td->v.n; + if (j < 16) /* length of code in bits (0..15) */ + ll[i++] = l = j; /* save last length in l */ + else if (j == 16) /* repeat last length 3 to 6 times */ + { + ZIPNEEDBITS(2) + j = 3 + ((uint32_t)b & 3); + ZIPDUMPBITS(2) + if((uint32_t)i + j > n) + return 1; + while (j--) + ll[i++] = l; + } + else if (j == 17) /* 3 to 10 zero length codes */ + { + ZIPNEEDBITS(3) + j = 3 + ((uint32_t)b & 7); + ZIPDUMPBITS(3) + if ((uint32_t)i + j > n) + return 1; + while (j--) + ll[i++] = 0; + l = 0; + } + else /* j == 18: 11 to 138 zero length codes */ + { + ZIPNEEDBITS(7) + j = 11 + ((uint32_t)b & 0x7f); + ZIPDUMPBITS(7) + if ((uint32_t)i + j > n) + return 1; + while (j--) + ll[i++] = 0; + l = 0; + } + } + + /* free decoding table for trees */ + Ziphuft_free(tl); + + /* restore the global bit buffer */ + ZIP(bb) = b; + ZIP(bk) = k; + + /* build the decoding tables for literal/length and distance codes */ + bl = ZIPLBITS; + if((i = Ziphuft_build(decomp_state, ll, nl, 257, Zipcplens, Zipcplext, &tl, &bl)) != 0) + { + if(i == 1) + Ziphuft_free(tl); + return i; /* incomplete code set */ + } + bd = ZIPDBITS; + Ziphuft_build(decomp_state, ll + nl, nd, 0, Zipcpdist, Zipcpdext, &td, &bd); + + /* decompress until an end-of-block code */ + if(Zipinflate_codes(decomp_state, tl, td, bl, bd)) + return 1; + + /* free the decoding tables, return */ + Ziphuft_free(tl); + Ziphuft_free(td); + return 0; +} + +/* e == last block flag */ +static int32_t Zipinflate_block(struct decomp_state *decomp_state, int32_t *e) +{ /* decompress an inflated block */ + uint32_t t; /* block type */ + register uint32_t b; /* bit buffer */ + register uint32_t k; /* number of bits in bit buffer */ + + DEBUG(10,("Zipinflate_block\n")); + + /* make local bit buffer */ + b = ZIP(bb); + k = ZIP(bk); + + /* read in last block bit */ + ZIPNEEDBITS(1) + *e = (int32_t)b & 1; + ZIPDUMPBITS(1) + + /* read in block type */ + ZIPNEEDBITS(2) + t = (uint32_t)b & 3; + ZIPDUMPBITS(2) + + /* restore the global bit buffer */ + ZIP(bb) = b; + ZIP(bk) = k; + + DEBUG(10,("inflate type %d\n", t)); + + /* inflate that block type */ + if(t == 2) + return Zipinflate_dynamic(decomp_state); + if(t == 0) + return Zipinflate_stored(decomp_state); + if(t == 1) + return Zipinflate_fixed(decomp_state); + /* bad block type */ + return 2; +} + +_PUBLIC_ struct decomp_state *ZIPdecomp_state(TALLOC_CTX *mem_ctx) +{ + return talloc_zero(mem_ctx, struct decomp_state); +} + +int ZIPdecompress(struct decomp_state *decomp_state, DATA_BLOB *inbuf, DATA_BLOB *outbuf) +{ + int32_t e = 0;/* last block flag */ + + ZIP(inpos) = CAB(inbuf); + ZIP(bb) = ZIP(bk) = ZIP(window_posn) = 0; + + if (inbuf->length > sizeof(decomp_state->inbuf)) return DECR_INPUT; + + if (outbuf->length > sizeof(decomp_state->outbuf)) return DECR_OUTPUT; + + if (outbuf->length > ZIPWSIZE) return DECR_DATAFORMAT; + + memcpy(decomp_state->inbuf, inbuf->data, inbuf->length); + + /* CK = Chris Kirmse, official Microsoft purloiner */ + if (ZIP(inpos)[0] != 'C' || ZIP(inpos)[1] != 'K') return DECR_ILLEGALDATA; + ZIP(inpos) += 2; + + while (!e) { + if (Zipinflate_block(decomp_state, &e)) { + return DECR_ILLEGALDATA; + } + } + + memcpy(outbuf->data, decomp_state->outbuf, outbuf->length); + + return DECR_OK; +} diff --git a/source3/lib/compression/mszip.h b/source3/lib/compression/mszip.h new file mode 100644 index 0000000000..bb835f2595 --- /dev/null +++ b/source3/lib/compression/mszip.h @@ -0,0 +1,33 @@ +/* mszip decompression - based on cabextract.c code from + * Stuart Caie + * + * adapted for Samba by Andrew Tridgell and Stefan Metzmacher 2005 + * + * (C) 2000-2001 Stuart Caie <kyzer@4u.net> + * reaktivate-specifics by Malte Starostik <malte@kde.org> + * + * 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/>. + */ + +struct decomp_state; +struct decomp_state *ZIPdecomp_state(TALLOC_CTX *mem_ctx); + +#define DECR_OK (0) +#define DECR_DATAFORMAT (1) +#define DECR_ILLEGALDATA (2) +#define DECR_NOMEMORY (3) +#define DECR_CHECKSUM (4) +#define DECR_INPUT (5) +#define DECR_OUTPUT (6) +int ZIPdecompress(struct decomp_state *decomp_state, DATA_BLOB *inbuf, DATA_BLOB *outbuf); diff --git a/source3/librpc/ndr/libndr.h b/source3/librpc/ndr/libndr.h index 35a5b136a7..155f5f1f7d 100644 --- a/source3/librpc/ndr/libndr.h +++ b/source3/librpc/ndr/libndr.h @@ -348,4 +348,7 @@ enum ndr_err_code ndr_pull_ ## name(struct ndr_pull *ndr, int ndr_flags, type *v void ndr_print_ ## name(struct ndr_print *ndr, const char *var_name, const type *v); +void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid); +size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags); + #endif /* __LIBNDR_H__ */ diff --git a/source3/librpc/ndr/ndr_compression.c b/source3/librpc/ndr/ndr_compression.c new file mode 100644 index 0000000000..9da0773f28 --- /dev/null +++ b/source3/librpc/ndr/ndr_compression.c @@ -0,0 +1,293 @@ +/* + Unix SMB/CIFS implementation. + + libndr compression support + + 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 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 "lib/compression/mszip.h" +#include "librpc/ndr/libndr.h" +#include "librpc/ndr/ndr_compression.h" + +static enum ndr_err_code ndr_pull_compression_mszip_chunk(struct ndr_pull *ndrpull, + struct ndr_push *ndrpush, + struct decomp_state *decomp_state, + bool *last) +{ + DATA_BLOB comp_chunk; + uint32_t comp_chunk_offset; + uint32_t comp_chunk_size; + DATA_BLOB plain_chunk; + uint32_t plain_chunk_offset; + uint32_t plain_chunk_size; + int ret; + + NDR_CHECK(ndr_pull_uint32(ndrpull, NDR_SCALARS, &plain_chunk_size)); + if (plain_chunk_size > 0x00008000) { + return ndr_pull_error(ndrpull, NDR_ERR_COMPRESSION, "Bad MSZIP plain chunk size %08X > 0x00008000 (PULL)", + plain_chunk_size); + } + + NDR_CHECK(ndr_pull_uint32(ndrpull, NDR_SCALARS, &comp_chunk_size)); + + DEBUG(10,("MSZIP plain_chunk_size: %08X (%u) comp_chunk_size: %08X (%u)\n", + plain_chunk_size, plain_chunk_size, comp_chunk_size, comp_chunk_size)); + + comp_chunk_offset = ndrpull->offset; + NDR_CHECK(ndr_pull_advance(ndrpull, comp_chunk_size)); + comp_chunk.length = comp_chunk_size; + comp_chunk.data = ndrpull->data + comp_chunk_offset; + + plain_chunk_offset = ndrpush->offset; + NDR_CHECK(ndr_push_zero(ndrpush, plain_chunk_size)); + plain_chunk.length = plain_chunk_size; + plain_chunk.data = ndrpush->data + plain_chunk_offset; + + ret = ZIPdecompress(decomp_state, &comp_chunk, &plain_chunk); + if (ret != DECR_OK) { + return ndr_pull_error(ndrpull, NDR_ERR_COMPRESSION, "Bad ZIPdecompress() error %d (PULL)", + ret); + } + + if ((plain_chunk_size < 0x00008000) || (ndrpull->offset+4 >= ndrpull->data_size)) { + /* this is the last chunk */ + *last = true; + } + + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_compression_mszip(struct ndr_pull *subndr, + struct ndr_pull **_comndr, + ssize_t decompressed_len) +{ + struct ndr_push *ndrpush; + struct ndr_pull *comndr; + DATA_BLOB uncompressed; + uint32_t payload_header[4]; + uint32_t payload_size; + uint32_t payload_offset; + uint8_t *payload; + struct decomp_state *decomp_state; + bool last = false; + + ndrpush = ndr_push_init_ctx(subndr); + NDR_ERR_HAVE_NO_MEMORY(ndrpush); + + decomp_state = ZIPdecomp_state(subndr); + NDR_ERR_HAVE_NO_MEMORY(decomp_state); + + while (!last) { + NDR_CHECK(ndr_pull_compression_mszip_chunk(subndr, ndrpush, decomp_state, &last)); + } + + uncompressed = ndr_push_blob(ndrpush); + + if (uncompressed.length != decompressed_len) { + return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP uncompressed_len [%u] != [%d] (PULL)", + (int)uncompressed.length, (int)decompressed_len); + } + + comndr = talloc_zero(subndr, struct ndr_pull); + NDR_ERR_HAVE_NO_MEMORY(comndr); + comndr->flags = subndr->flags; + comndr->current_mem_ctx = subndr->current_mem_ctx; + + comndr->data = uncompressed.data; + comndr->data_size = uncompressed.length; + comndr->offset = 0; + + NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[0])); + NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[1])); + NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[2])); + NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[3])); + + if (payload_header[0] != 0x00081001) { + return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP payload_header[0] [0x%08X] != [0x00081001] (PULL)", + payload_header[0]); + } + if (payload_header[1] != 0xCCCCCCCC) { + return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP payload_header[1] [0x%08X] != [0xCCCCCCCC] (PULL)", + payload_header[1]); + } + + payload_size = payload_header[2]; + + if (payload_header[3] != 0x00000000) { + return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP payload_header[3] [0x%08X] != [0x00000000] (PULL)", + payload_header[3]); + } + + payload_offset = comndr->offset; + NDR_CHECK(ndr_pull_advance(comndr, payload_size)); + payload = comndr->data + payload_offset; + + comndr->data = payload; + comndr->data_size = payload_size; + comndr->offset = 0; + + *_comndr = comndr; + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_push_compression_mszip(struct ndr_push *subndr, + struct ndr_push *comndr) +{ + return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "Sorry MSZIP compression is not supported yet (PUSH)"); +} + +static enum ndr_err_code ndr_pull_compression_xpress_chunk(struct ndr_pull *ndrpull, + struct ndr_push *ndrpush, + bool *last) +{ + DATA_BLOB comp_chunk; + uint32_t comp_chunk_offset; + uint32_t comp_chunk_size; + uint32_t plain_chunk_size; + + comp_chunk_offset = ndrpull->offset; + + NDR_CHECK(ndr_pull_uint32(ndrpull, NDR_SCALARS, &plain_chunk_size)); + if (plain_chunk_size > 0x00010000) { + return ndr_pull_error(ndrpull, NDR_ERR_COMPRESSION, "Bad XPRESS plain chunk size %08X > 0x00010000 (PULL)", + plain_chunk_size); + } + + NDR_CHECK(ndr_pull_uint32(ndrpull, NDR_SCALARS, &comp_chunk_size)); + + NDR_CHECK(ndr_pull_advance(ndrpull, comp_chunk_size)); + comp_chunk.length = comp_chunk_size + 8; + comp_chunk.data = ndrpull->data + comp_chunk_offset; + + DEBUG(10,("XPRESS plain_chunk_size: %08X (%u) comp_chunk_size: %08X (%u)\n", + plain_chunk_size, plain_chunk_size, comp_chunk_size, comp_chunk_size)); + + /* For now, we just copy over the compressed blob */ + NDR_CHECK(ndr_push_bytes(ndrpush, comp_chunk.data, comp_chunk.length)); + + if ((plain_chunk_size < 0x00010000) || (ndrpull->offset+4 >= ndrpull->data_size)) { + /* this is the last chunk */ + *last = true; + } + + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_compression_xpress(struct ndr_pull *subndr, + struct ndr_pull **_comndr, + ssize_t decompressed_len) +{ + struct ndr_push *ndrpush; + struct ndr_pull *comndr; + DATA_BLOB uncompressed; + bool last = false; + + ndrpush = ndr_push_init_ctx(subndr); + NDR_ERR_HAVE_NO_MEMORY(ndrpush); + + while (!last) { + NDR_CHECK(ndr_pull_compression_xpress_chunk(subndr, ndrpush, &last)); + } + + uncompressed = ndr_push_blob(ndrpush); + + comndr = talloc_zero(subndr, struct ndr_pull); + NDR_ERR_HAVE_NO_MEMORY(comndr); + comndr->flags = subndr->flags; + comndr->current_mem_ctx = subndr->current_mem_ctx; + + comndr->data = uncompressed.data; + comndr->data_size = uncompressed.length; + comndr->offset = 0; + + *_comndr = comndr; + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_push_compression_xpress(struct ndr_push *subndr, + struct ndr_push *comndr) +{ + return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "XPRESS compression is not supported yet (PUSH)"); +} + +/* + handle compressed subcontext buffers, which in midl land are user-marshalled, but + we use magic in pidl to make them easier to cope with +*/ +enum ndr_err_code ndr_pull_compression_start(struct ndr_pull *subndr, + struct ndr_pull **_comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) +{ + switch (compression_alg) { + case NDR_COMPRESSION_MSZIP: + return ndr_pull_compression_mszip(subndr, _comndr, decompressed_len); + case NDR_COMPRESSION_XPRESS: + return ndr_pull_compression_xpress(subndr, _comndr, decompressed_len); + default: + return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad compression algorithm %d (PULL)", + compression_alg); + } + return NDR_ERR_SUCCESS; +} + +enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr, + struct ndr_pull *comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) +{ + return NDR_ERR_SUCCESS; +} + +/* + push a compressed subcontext +*/ +enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr, + struct ndr_push **_comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) +{ + struct ndr_push *comndr; + + comndr = ndr_push_init_ctx(subndr); + NDR_ERR_HAVE_NO_MEMORY(comndr); + comndr->flags = subndr->flags; + + *_comndr = comndr; + return NDR_ERR_SUCCESS; +} + +/* + push a compressed subcontext +*/ +enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr, + struct ndr_push *comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) +{ + switch (compression_alg) { + case NDR_COMPRESSION_MSZIP: + return ndr_push_compression_mszip(subndr, comndr); + case NDR_COMPRESSION_XPRESS: + return ndr_push_compression_xpress(subndr, comndr); + default: + return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "Bad compression algorithm %d (PUSH)", + compression_alg); + } + return NDR_ERR_SUCCESS; +} diff --git a/source3/librpc/ndr/ndr_compression.h b/source3/librpc/ndr/ndr_compression.h new file mode 100644 index 0000000000..4cebbe190c --- /dev/null +++ b/source3/librpc/ndr/ndr_compression.h @@ -0,0 +1,51 @@ +#ifndef __LIBRPC_NDR_NDR_COMPRESSION_H__ +#define __LIBRPC_NDR_NDR_COMPRESSION_H__ + +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2) +/* This file was automatically generated by mkproto.pl. DO NOT EDIT */ + +#ifndef _PUBLIC_ +#define _PUBLIC_ +#endif + +#ifndef _PURE_ +#define _PURE_ +#endif + +#ifndef _NORETURN_ +#define _NORETURN_ +#endif + +#ifndef _DEPRECATED_ +#define _DEPRECATED_ +#endif + +#ifndef _WARN_UNUSED_RESULT_ +#define _WARN_UNUSED_RESULT_ +#endif + + +/* The following definitions come from librpc/ndr/ndr_compression.c */ + +enum ndr_err_code ndr_pull_compression_start(struct ndr_pull *subndr, + struct ndr_pull **_comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len); +enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr, + struct ndr_pull *comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len); +enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr, + struct ndr_push **_comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len); +enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr, + struct ndr_push *comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len); +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) + +#endif /* __LIBRPC_NDR_NDR_COMPRESSION_H__ */ + diff --git a/source3/librpc/ndr/ndr_drsuapi.c b/source3/librpc/ndr/ndr_drsuapi.c new file mode 100644 index 0000000000..3c15e013ee --- /dev/null +++ b/source3/librpc/ndr/ndr_drsuapi.c @@ -0,0 +1,180 @@ +/* + Unix SMB/CIFS implementation. + + routines for printing some linked list structs in DRSUAPI + + Copyright (C) Stefan (metze) 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 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 "librpc/gen_ndr/ndr_drsuapi.h" +#include "librpc/gen_ndr/ndr_misc.h" + +bool ber_write_OID_String(DATA_BLOB *blob, const char *OID); +bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID); + +void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print *ndr, const char *name, + const struct drsuapi_DsReplicaObjectListItem *r) +{ + ndr_print_struct(ndr, name, "drsuapi_DsReplicaObjectListItem"); + ndr->depth++; + ndr_print_ptr(ndr, "next_object", r->next_object); + ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object); + ndr->depth--; + if (r->next_object) { + ndr_print_drsuapi_DsReplicaObjectListItem(ndr, "next_object", r->next_object); + } +} + +void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaObjectListItemEx *r) +{ + ndr_print_struct(ndr, name, "drsuapi_DsReplicaObjectListItemEx"); + ndr->depth++; + ndr_print_ptr(ndr, "next_object", r->next_object); + ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object); + ndr_print_uint32(ndr, "unknown1", r->unknown1); + ndr_print_ptr(ndr, "parent_object_guid", r->parent_object_guid); + ndr->depth++; + if (r->parent_object_guid) { + ndr_print_GUID(ndr, "parent_object_guid", r->parent_object_guid); + } + ndr->depth--; + ndr_print_ptr(ndr, "meta_data_ctr", r->meta_data_ctr); + ndr->depth++; + if (r->meta_data_ctr) { + ndr_print_drsuapi_DsReplicaMetaDataCtr(ndr, "meta_data_ctr", r->meta_data_ctr); + } + ndr->depth--; + ndr->depth--; + if (r->next_object) { + ndr_print_drsuapi_DsReplicaObjectListItemEx(ndr, "next_object", r->next_object); + } +} + +#define _OID_PUSH_CHECK(call) do { \ + bool _status; \ + _status = call; \ + if (_status != true) { \ + return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \ + } \ +} while (0) + +#define _OID_PULL_CHECK(call) do { \ + bool _status; \ + _status = call; \ + if (_status != true) { \ + return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \ + } \ +} while (0) + +enum ndr_err_code ndr_push_drsuapi_DsReplicaOID(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsReplicaOID *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_size_drsuapi_DsReplicaOID_oid(r->oid, 0))); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->oid)); + } + if (ndr_flags & NDR_BUFFERS) { + if (r->oid) { + DATA_BLOB blob; + + if (StrnCaseCmp("ff", r->oid, 2) == 0) { + blob = strhex_to_data_blob(NULL, r->oid); + if (!blob.data) { + return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, + "HEX String Conversion Error: %s\n", + __location__); + } + } else { + _OID_PUSH_CHECK(ber_write_OID_String(&blob, r->oid)); + } + talloc_steal(ndr, blob.data); + + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, blob.length)); + NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, blob.data, blob.length)); + } + } + return NDR_ERR_SUCCESS; +} + +enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r) +{ + uint32_t _ptr_oid; + TALLOC_CTX *_mem_save_oid_0; + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->__ndr_size)); + if (r->__ndr_size < 0 || r->__ndr_size > 10000) { + return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range"); + } + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_oid)); + if (_ptr_oid) { + NDR_PULL_ALLOC(ndr, r->oid); + } else { + r->oid = NULL; + } + } + if (ndr_flags & NDR_BUFFERS) { + if (r->oid) { + DATA_BLOB _oid_array; + const char *_oid; + + _mem_save_oid_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, ndr, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->oid)); + _oid_array.length = ndr_get_array_size(ndr, &r->oid); + NDR_PULL_ALLOC_N(ndr, _oid_array.data, _oid_array.length); + NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, _oid_array.data, _oid_array.length)); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_oid_0, 0); + + if (_oid_array.length && _oid_array.data[0] == 0xFF) { + _oid = data_blob_hex_string(ndr, &_oid_array); + NDR_ERR_HAVE_NO_MEMORY(_oid); + } else { + _OID_PULL_CHECK(ber_read_OID_String(ndr, _oid_array, &_oid)); + } + data_blob_free(&_oid_array); + talloc_steal(r->oid, _oid); + r->oid = _oid; + } + if (r->oid) { + NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->oid, r->__ndr_size)); + } + } + return NDR_ERR_SUCCESS; +} + +size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags) +{ + DATA_BLOB _blob; + size_t ret = 0; + + if (!oid) return 0; + + if (StrnCaseCmp("ff", oid, 2) == 0) { + _blob = strhex_to_data_blob(NULL, oid); + if (_blob.data) { + ret = _blob.length; + } + } else { + if (ber_write_OID_String(&_blob, oid)) { + ret = _blob.length; + } + } + data_blob_free(&_blob); + return ret; +} diff --git a/source3/librpc/ndr/ndr_drsuapi.h b/source3/librpc/ndr/ndr_drsuapi.h new file mode 100644 index 0000000000..c663eadd7a --- /dev/null +++ b/source3/librpc/ndr/ndr_drsuapi.h @@ -0,0 +1,35 @@ +/* + Unix SMB/CIFS implementation. + + routines for printing some linked list structs in DRSUAPI + + Copyright (C) Stefan (metze) Metzmacher 2005-2006 + + 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/>. +*/ + +#ifndef _LIBRPC_NDR_NDR_DRSUAPI_H +#define _LIBRPC_NDR_NDR_DRSUAPI_H + +void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print *ndr, const char *name, + const struct drsuapi_DsReplicaObjectListItem *r); + +void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const char *name, + const struct drsuapi_DsReplicaObjectListItemEx *r); + +enum ndr_err_code ndr_push_drsuapi_DsReplicaOID(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsReplicaOID *r); +enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r); +size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags); + +#endif /* _LIBRPC_NDR_NDR_DRSUAPI_H */ diff --git a/source3/libsmb/asn1.c b/source3/libsmb/asn1.c index bdbe49b111..39413e252e 100644 --- a/source3/libsmb/asn1.c +++ b/source3/libsmb/asn1.c @@ -516,3 +516,87 @@ bool asn1_write_enumerated(ASN1_DATA *data, uint8 v) asn1_pop_tag(data); return !data->has_error; } + +bool ber_write_OID_String(DATA_BLOB *blob, const char *OID) +{ + uint_t v, v2; + const char *p = (const char *)OID; + char *newp; + int i; + + v = strtoul(p, &newp, 10); + if (newp[0] != '.') return false; + p = newp + 1; + + v2 = strtoul(p, &newp, 10); + if (newp[0] != '.') return false; + p = newp + 1; + + /*the ber representation can't use more space then the string one */ + *blob = data_blob(NULL, strlen(OID)); + if (!blob->data) return false; + + blob->data[0] = 40*v + v2; + + i = 1; + while (*p) { + v = strtoul(p, &newp, 10); + if (newp[0] == '.') { + p = newp + 1; + } else if (newp[0] == '\0') { + p = newp; + } else { + data_blob_free(blob); + return false; + } + if (v >= (1<<28)) blob->data[i++] = (0x80 | ((v>>28)&0x7f)); + if (v >= (1<<21)) blob->data[i++] = (0x80 | ((v>>21)&0x7f)); + if (v >= (1<<14)) blob->data[i++] = (0x80 | ((v>>14)&0x7f)); + if (v >= (1<<7)) blob->data[i++] = (0x80 | ((v>>7)&0x7f)); + blob->data[i++] = (v&0x7f); + } + + blob->length = i; + + return true; +} + +/* read an object ID from a data blob */ +bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID) +{ + int i; + uint8_t *b; + uint_t v; + char *tmp_oid = NULL; + + if (blob.length < 2) return false; + + b = blob.data; + + tmp_oid = talloc_asprintf(mem_ctx, "%u", b[0]/40); + if (!tmp_oid) goto nomem; + tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", b[0]%40); + if (!tmp_oid) goto nomem; + + for(i = 1, v = 0; i < blob.length; i++) { + v = (v<<7) | (b[i]&0x7f); + if ( ! (b[i] & 0x80)) { + tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", v); + v = 0; + } + if (!tmp_oid) goto nomem; + } + + if (v != 0) { + talloc_free(tmp_oid); + return false; + } + + *OID = tmp_oid; + return true; + +nomem: + return false; +} + + diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c index 81719512ae..fbdc3ed483 100644 --- a/source3/rpc_parse/parse_rpc.c +++ b/source3/rpc_parse/parse_rpc.c @@ -60,6 +60,7 @@ const struct pipe_id_info pipe_names [] = { PIPE_EVENTLOG, &ndr_table_eventlog.syntax_id, PIPE_EVENTLOG , &ndr_transfer_syntax }, { PIPE_NTSVCS , &ndr_table_ntsvcs.syntax_id, PIPE_NTSVCS , &ndr_transfer_syntax }, { PIPE_EPMAPPER , &ndr_table_epmapper.syntax_id, PIPE_EPMAPPER , &ndr_transfer_syntax }, + { PIPE_DRSUAPI , &ndr_table_drsuapi.syntax_id, PIPE_DRSUAPI , &ndr_transfer_syntax }, { NULL , NULL , NULL , NULL } }; |