waf: Correctly check for prctl in just one place.
[sfrench/samba-autobuild/.git] / librpc / ndr / ndr_backupkey.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    routines for top backup key protocol marshalling/unmarshalling
5
6    Copyright (C) Matthieu Patou 2010
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_misc.h"
24 #include "librpc/gen_ndr/ndr_backupkey.h"
25 #include "librpc/gen_ndr/ndr_security.h"
26
27 static uint32_t backupkeyguid_to_uint(const struct GUID *guid)
28 {
29         struct GUID tmp;
30         NTSTATUS status;
31         bool match;
32
33         status = GUID_from_string(BACKUPKEY_RESTORE_GUID, &tmp);
34         if (NT_STATUS_IS_OK(status)) {
35                 match = GUID_equal(guid, &tmp);
36                 if (match) {
37                         return BACKUPKEY_RESTORE_GUID_INTEGER;
38                 }
39         }
40
41         status = GUID_from_string(BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID, &tmp);
42         if (NT_STATUS_IS_OK(status)) {
43                 match = GUID_equal(guid, &tmp);
44                 if (match) {
45                         return BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID_INTEGER;
46                 }
47         }
48
49         return BACKUPKEY_INVALID_GUID_INTEGER;
50 }
51
52 _PUBLIC_ void ndr_print_bkrp_BackupKey(struct ndr_print *ndr, const char *name, int flags, const struct bkrp_BackupKey *r)
53 {
54         ndr_print_struct(ndr, name, "bkrp_BackupKey");
55         if (r == NULL) { ndr_print_null(ndr); return; }
56         ndr->depth++;
57         if (flags & NDR_SET_VALUES) {
58                 ndr->flags |= LIBNDR_PRINT_SET_VALUES;
59         }
60         if (flags & NDR_IN) {
61                 union bkrp_data_in_blob inblob;
62                 DATA_BLOB blob;
63                 uint32_t level;
64                 enum ndr_err_code ndr_err;
65
66                 ndr_print_struct(ndr, "in", "bkrp_BackupKey");
67                 ndr->depth++;
68                 ndr_print_ptr(ndr, "guidActionAgent", r->in.guidActionAgent);
69                 ndr->depth++;
70                 ndr_print_GUID(ndr, "guidActionAgent", r->in.guidActionAgent);
71                 ndr->depth--;
72
73                 level = backupkeyguid_to_uint(r->in.guidActionAgent);
74                 blob.data = r->in.data_in;
75                 blob.length = r->in.data_in_len;
76                 ndr_err = ndr_pull_union_blob(&blob, ndr, &inblob, level,
77                                 (ndr_pull_flags_fn_t)ndr_pull_bkrp_data_in_blob);
78
79                 ndr_print_ptr(ndr, "data_in", r->in.data_in);
80                 ndr->depth++;
81                 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
82                         ndr_print_bkrp_data_in_blob(ndr, "data_in", &inblob);
83                 } else {
84                         ndr_print_array_uint8(ndr, "data_in", r->in.data_in, r->in.data_in_len);
85                 }
86                 ndr->depth--;
87
88                 ndr_print_uint32(ndr, "data_in_len", r->in.data_in_len);
89                 ndr_print_uint32(ndr, "param", r->in.param);
90                 ndr->depth--;
91         }
92         if (flags & NDR_OUT) {
93                 ndr_print_struct(ndr, "out", "bkrp_BackupKey");
94                 ndr->depth++;
95                 ndr_print_ptr(ndr, "data_out", r->out.data_out);
96                 ndr->depth++;
97                 ndr_print_ptr(ndr, "data_out", *r->out.data_out);
98                 ndr->depth++;
99
100                 if (*r->out.data_out) {
101                         ndr_print_array_uint8(ndr, "data_out", *r->out.data_out, *r->out.data_out_len);
102                 }
103                 ndr->depth--;
104                 ndr->depth--;
105                 ndr_print_ptr(ndr, "data_out_len", r->out.data_out_len);
106                 ndr->depth++;
107                 ndr_print_uint32(ndr, "data_out_len", *r->out.data_out_len);
108                 ndr->depth--;
109                 ndr_print_WERROR(ndr, "result", r->out.result);
110                 ndr->depth--;
111         }
112         ndr->depth--;
113 }
114
115 /* We have manual push/pull because we didn't manage to do the alignment
116  * purely in PIDL as the padding is sized so that the whole access_check_v3
117  * struct size is a multiple of 8 (as specified in 2.2.2.3 of ms-bkrp.pdf)
118  */
119 _PUBLIC_ enum ndr_err_code ndr_push_bkrp_access_check_v2(struct ndr_push *ndr, int ndr_flags, const struct bkrp_access_check_v2 *r)
120 {
121         if (ndr_flags & NDR_SCALARS) {
122                 size_t ofs;
123                 size_t pad;
124                 NDR_CHECK(ndr_push_align(ndr, 4));
125                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
126                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
127                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
128                 NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
129                 /* We articially increment the offset of 20 bytes (size of hash
130                  * comming after the pad) so that ndr_align can determine easily
131                  * the correct pad size to make the whole struct 8 bytes aligned
132                  */
133                 ofs = ndr->offset + 20;
134                 pad = ndr_align_size(ofs, 8);
135                 NDR_CHECK(ndr_push_zero(ndr, pad));
136                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
137                 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
138         }
139         if (ndr_flags & NDR_BUFFERS) {
140         }
141         return NDR_ERR_SUCCESS;
142 }
143
144 _PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v2(struct ndr_pull *ndr, int ndr_flags, struct bkrp_access_check_v2 *r)
145 {
146         if (ndr_flags & NDR_SCALARS) {
147                 size_t ofs;
148                 size_t pad;
149                 NDR_CHECK(ndr_pull_align(ndr, 4));
150                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
151                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
152                 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
153                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
154                 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
155                 ofs = ndr->offset + 20;
156                 pad = ndr_align_size(ofs, 8);
157                 NDR_CHECK(ndr_pull_advance(ndr, pad));
158                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
159                 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
160         }
161         if (ndr_flags & NDR_BUFFERS) {
162         }
163         return NDR_ERR_SUCCESS;
164 }
165
166 /* We have manual push/pull because we didn't manage to do the alignment
167  * purely in PIDL as the padding is sized so that the whole access_check_v3
168  * struct size is a multiple of 16 (as specified in 2.2.2.4 of ms-bkrp.pdf)
169  */
170 _PUBLIC_ enum ndr_err_code ndr_push_bkrp_access_check_v3(struct ndr_push *ndr, int ndr_flags, const struct bkrp_access_check_v3 *r)
171 {
172         if (ndr_flags & NDR_SCALARS) {
173                 size_t ofs;
174                 size_t pad;
175                 NDR_CHECK(ndr_push_align(ndr, 4));
176                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
177                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
178                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
179                 NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
180                 /* We articially increment the offset of 64 bytes (size of hash
181                  * comming after the pad) so that ndr_align can determine easily
182                  * the correct pad size to make the whole struct 16 bytes aligned
183                  */
184                 ofs = ndr->offset + 64;
185                 pad = ndr_align_size(ofs, 16);
186                 NDR_CHECK(ndr_push_zero(ndr, pad));
187                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
188                 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
189         }
190         if (ndr_flags & NDR_BUFFERS) {
191         }
192         return NDR_ERR_SUCCESS;
193 }
194
195 _PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v3(struct ndr_pull *ndr, int ndr_flags, struct bkrp_access_check_v3 *r)
196 {
197         if (ndr_flags & NDR_SCALARS) {
198                 size_t ofs;
199                 size_t pad;
200                 NDR_CHECK(ndr_pull_align(ndr, 4));
201                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
202                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
203                 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
204                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
205                 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
206                 ofs = ndr->offset + 64;
207                 pad = ndr_align_size(ofs, 16);
208                 NDR_CHECK(ndr_pull_advance(ndr, pad));
209                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
210                 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
211         }
212         if (ndr_flags & NDR_BUFFERS) {
213         }
214         return NDR_ERR_SUCCESS;
215 }