s3-utils: Fix scanf format in smbacls.
[Samba.git] / librpc / ndr / ndr_backupkey.c
blobddbaeea0007fa66eed73585333b990604f5362ce
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 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);
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);
86 ndr->depth--;
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--;
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++;
100 if (*r->out.data_out) {
101 ndr_print_array_uint8(ndr, "data_out", *r->out.data_out, *r->out.data_out_len);
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--;
112 ndr->depth--;
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)
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)
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
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));
139 if (ndr_flags & NDR_BUFFERS) {
141 return NDR_ERR_SUCCESS;
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)
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));
161 if (ndr_flags & NDR_BUFFERS) {
163 return NDR_ERR_SUCCESS;
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)
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)
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
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));
190 if (ndr_flags & NDR_BUFFERS) {
192 return NDR_ERR_SUCCESS;
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)
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));
212 if (ndr_flags & NDR_BUFFERS) {
214 return NDR_ERR_SUCCESS;