param: remove swat specific flags.
[Samba.git] / librpc / ndr / ndr_backupkey.c
blob827bc69423061bcc3911fb676e46e7c4500cb5d1
1 /*
2 Unix SMB/CIFS implementation.
4 routines for top backup key protocol marshalling/unmarshalling
6 Copyright (C) Matthieu Patou 2010
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.
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.
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/>.
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"
27 static uint32_t backupkeyguid_to_uint(const struct GUID *guid)
29 struct GUID tmp;
30 NTSTATUS status;
31 bool match;
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;
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;
49 return BACKUPKEY_INVALID_GUID_INTEGER;
52 _PUBLIC_ void ndr_print_bkrp_BackupKey(struct ndr_print *ndr, const char *name, int flags, const struct bkrp_BackupKey *r)
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;
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;
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--;
73 level = backupkeyguid_to_uint(r->in.guidActionAgent);
74 ndr_err = ndr_print_set_switch_value(ndr, &inblob, level);
75 if (unlikely(!NDR_ERR_CODE_IS_SUCCESS(ndr_err))) { \
76 DEBUG(0,("ERROR: ndr_print_bkrp_BackupKey ndr_print_set_switch_value failed: %d\n", ndr_err));
77 return;
79 blob.data = r->in.data_in;
80 blob.length = r->in.data_in_len;
81 ndr_err = ndr_pull_union_blob(&blob, ndr, &inblob, level,
82 (ndr_pull_flags_fn_t)ndr_pull_bkrp_data_in_blob);
84 ndr_print_ptr(ndr, "data_in", r->in.data_in);
85 ndr->depth++;
86 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
87 ndr_print_bkrp_data_in_blob(ndr, "data_in", &inblob);
88 } else {
89 ndr_print_array_uint8(ndr, "data_in", r->in.data_in, r->in.data_in_len);
91 ndr->depth--;
93 ndr_print_uint32(ndr, "data_in_len", r->in.data_in_len);
94 ndr_print_uint32(ndr, "param", r->in.param);
95 ndr->depth--;
97 if (flags & NDR_OUT) {
98 ndr_print_struct(ndr, "out", "bkrp_BackupKey");
99 ndr->depth++;
100 ndr_print_ptr(ndr, "data_out", r->out.data_out);
101 ndr->depth++;
102 ndr_print_ptr(ndr, "data_out", *r->out.data_out);
103 ndr->depth++;
105 if (*r->out.data_out) {
106 ndr_print_array_uint8(ndr, "data_out", *r->out.data_out, *r->out.data_out_len);
108 ndr->depth--;
109 ndr->depth--;
110 ndr_print_ptr(ndr, "data_out_len", r->out.data_out_len);
111 ndr->depth++;
112 ndr_print_uint32(ndr, "data_out_len", *r->out.data_out_len);
113 ndr->depth--;
114 ndr_print_WERROR(ndr, "result", r->out.result);
115 ndr->depth--;
117 ndr->depth--;
120 /* We have manual push/pull because we didn't manage to do the alignment
121 * purely in PIDL as the padding is sized so that the whole access_check_v3
122 * struct size is a multiple of 8 (as specified in 2.2.2.3 of ms-bkrp.pdf)
124 _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)
126 if (ndr_flags & NDR_SCALARS) {
127 size_t ofs;
128 size_t pad;
129 NDR_CHECK(ndr_push_align(ndr, 4));
130 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
131 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
132 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
133 NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
134 /* We articially increment the offset of 20 bytes (size of hash
135 * comming after the pad) so that ndr_align can determine easily
136 * the correct pad size to make the whole struct 8 bytes aligned
138 ofs = ndr->offset + 20;
139 pad = ndr_align_size(ofs, 8);
140 NDR_CHECK(ndr_push_zero(ndr, pad));
141 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
142 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
144 if (ndr_flags & NDR_BUFFERS) {
146 return NDR_ERR_SUCCESS;
149 _PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v2(struct ndr_pull *ndr, int ndr_flags, struct bkrp_access_check_v2 *r)
151 if (ndr_flags & NDR_SCALARS) {
152 size_t ofs;
153 size_t pad;
154 NDR_CHECK(ndr_pull_align(ndr, 4));
155 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
156 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
157 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
158 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
159 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
160 ofs = ndr->offset + 20;
161 pad = ndr_align_size(ofs, 8);
162 NDR_CHECK(ndr_pull_advance(ndr, pad));
163 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
164 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
166 if (ndr_flags & NDR_BUFFERS) {
168 return NDR_ERR_SUCCESS;
171 /* We have manual push/pull because we didn't manage to do the alignment
172 * purely in PIDL as the padding is sized so that the whole access_check_v3
173 * struct size is a multiple of 16 (as specified in 2.2.2.4 of ms-bkrp.pdf)
175 _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)
177 if (ndr_flags & NDR_SCALARS) {
178 size_t ofs;
179 size_t pad;
180 NDR_CHECK(ndr_push_align(ndr, 4));
181 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
182 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
183 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
184 NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
185 /* We articially increment the offset of 64 bytes (size of hash
186 * comming after the pad) so that ndr_align can determine easily
187 * the correct pad size to make the whole struct 16 bytes aligned
189 ofs = ndr->offset + 64;
190 pad = ndr_align_size(ofs, 16);
191 NDR_CHECK(ndr_push_zero(ndr, pad));
192 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
193 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
195 if (ndr_flags & NDR_BUFFERS) {
197 return NDR_ERR_SUCCESS;
200 _PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v3(struct ndr_pull *ndr, int ndr_flags, struct bkrp_access_check_v3 *r)
202 if (ndr_flags & NDR_SCALARS) {
203 size_t ofs;
204 size_t pad;
205 NDR_CHECK(ndr_pull_align(ndr, 4));
206 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
207 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
208 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
209 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
210 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
211 ofs = ndr->offset + 64;
212 pad = ndr_align_size(ofs, 16);
213 NDR_CHECK(ndr_pull_advance(ndr, pad));
214 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
215 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
217 if (ndr_flags & NDR_BUFFERS) {
219 return NDR_ERR_SUCCESS;