r8227: add STR_LARGE_SIZE flag, to support strings where the size is length+1,
[samba.git] / source4 / librpc / ndr / ndr_obfuscate.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    libndr obfuscate support (MAPI)
5
6    Copyright (C) Stefan Metzmacher 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 /*
26   handle obfuscated subcontext buffers, which in midl land are user-marshalled, but
27   we use magic in pidl to make them easier to cope with
28 */
29 NTSTATUS ndr_pull_obfuscation(struct ndr_pull *ndr, uint8_t salt)
30 {
31         uint32_t i;
32
33         for (i=0; i<ndr->data_size; i++) {
34                 ndr->data[i] ^= salt;
35         }
36
37         return NT_STATUS_OK;
38 }
39
40 /*
41   push a obfuscated subcontext
42 */
43 NTSTATUS ndr_push_obfuscation(struct ndr_push *ndr, uint8_t salt)
44 {
45         uint32_t i;
46
47         for (i=0; i<ndr->offset; i++) {
48                 ndr->data[i] ^= salt;
49         }
50
51         return NT_STATUS_OK;
52 }