travis-ci: Remove hooks for Travis CI (typically used with GitHub)
[Samba.git] / librpc / ndr / ndr_backupkey.c
blobadb6e3932874a5ee81c92656c58b32c3912ec999
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 .empty._empty_ = '\0',
64 DATA_BLOB blob;
65 uint32_t level;
66 enum ndr_err_code ndr_err;
68 ndr_print_struct(ndr, "in", "bkrp_BackupKey");
69 ndr->depth++;
70 ndr_print_ptr(ndr, "guidActionAgent", r->in.guidActionAgent);
71 ndr->depth++;
72 ndr_print_GUID(ndr, "guidActionAgent", r->in.guidActionAgent);
73 ndr->depth--;
75 level = backupkeyguid_to_uint(r->in.guidActionAgent);
76 ndr_err = ndr_print_set_switch_value(ndr, &inblob, level);
77 if (unlikely(!NDR_ERR_CODE_IS_SUCCESS(ndr_err))) { \
78 DEBUG(0,("ERROR: ndr_print_bkrp_BackupKey ndr_print_set_switch_value failed: %d\n", ndr_err));
79 return;
81 blob.data = r->in.data_in;
82 blob.length = r->in.data_in_len;
83 ndr_err = ndr_pull_union_blob(&blob, ndr, &inblob, level,
84 (ndr_pull_flags_fn_t)ndr_pull_bkrp_data_in_blob);
86 ndr_print_ptr(ndr, "data_in", r->in.data_in);
87 ndr->depth++;
88 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
89 ndr_print_bkrp_data_in_blob(ndr, "data_in", &inblob);
90 } else {
91 ndr_print_array_uint8(ndr, "data_in", r->in.data_in, r->in.data_in_len);
93 ndr->depth--;
95 ndr_print_uint32(ndr, "data_in_len", r->in.data_in_len);
96 ndr_print_uint32(ndr, "param", r->in.param);
97 ndr->depth--;
99 if (flags & NDR_OUT) {
100 ndr_print_struct(ndr, "out", "bkrp_BackupKey");
101 ndr->depth++;
102 ndr_print_ptr(ndr, "data_out", r->out.data_out);
103 ndr->depth++;
104 ndr_print_ptr(ndr, "data_out", *r->out.data_out);
105 ndr->depth++;
107 if (*r->out.data_out) {
108 ndr_print_array_uint8(ndr, "data_out", *r->out.data_out, *r->out.data_out_len);
110 ndr->depth--;
111 ndr->depth--;
112 ndr_print_ptr(ndr, "data_out_len", r->out.data_out_len);
113 ndr->depth++;
114 ndr_print_uint32(ndr, "data_out_len", *r->out.data_out_len);
115 ndr->depth--;
116 ndr_print_WERROR(ndr, "result", r->out.result);
117 ndr->depth--;
119 ndr->depth--;
122 /* We have manual push/pull because we didn't manage to do the alignment
123 * purely in PIDL as the padding is sized so that the whole access_check_v3
124 * struct size is a multiple of 8 (as specified in 2.2.2.3 of ms-bkrp.pdf)
126 _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)
128 if (ndr_flags & NDR_SCALARS) {
129 size_t ofs;
130 size_t pad;
131 NDR_CHECK(ndr_push_align(ndr, 4));
132 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
133 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
134 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
135 NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
136 /* We articially increment the offset of 20 bytes (size of hash
137 * comming after the pad) so that ndr_align can determine easily
138 * the correct pad size to make the whole struct 8 bytes aligned
140 ofs = ndr->offset + 20;
141 pad = ndr_align_size(ofs, 8);
142 NDR_CHECK(ndr_push_zero(ndr, pad));
143 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
144 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
146 if (ndr_flags & NDR_BUFFERS) {
148 return NDR_ERR_SUCCESS;
151 _PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v2(struct ndr_pull *ndr, int ndr_flags, struct bkrp_access_check_v2 *r)
153 if (ndr_flags & NDR_SCALARS) {
154 size_t ofs;
155 size_t pad;
156 NDR_CHECK(ndr_pull_align(ndr, 4));
157 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
158 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
159 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
160 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
161 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
162 ofs = ndr->offset + 20;
163 pad = ndr_align_size(ofs, 8);
164 NDR_CHECK(ndr_pull_advance(ndr, pad));
165 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
166 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
168 if (ndr_flags & NDR_BUFFERS) {
170 return NDR_ERR_SUCCESS;
173 /* We have manual push/pull because we didn't manage to do the alignment
174 * purely in PIDL as the padding is sized so that the whole access_check_v3
175 * struct size is a multiple of 16 (as specified in 2.2.2.4 of ms-bkrp.pdf)
177 _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)
179 if (ndr_flags & NDR_SCALARS) {
180 size_t ofs;
181 size_t pad;
182 NDR_CHECK(ndr_push_align(ndr, 4));
183 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
184 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
185 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
186 NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
187 /* We articially increment the offset of 64 bytes (size of hash
188 * comming after the pad) so that ndr_align can determine easily
189 * the correct pad size to make the whole struct 16 bytes aligned
191 ofs = ndr->offset + 64;
192 pad = ndr_align_size(ofs, 16);
193 NDR_CHECK(ndr_push_zero(ndr, pad));
194 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
195 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
197 if (ndr_flags & NDR_BUFFERS) {
199 return NDR_ERR_SUCCESS;
202 _PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v3(struct ndr_pull *ndr, int ndr_flags, struct bkrp_access_check_v3 *r)
204 if (ndr_flags & NDR_SCALARS) {
205 size_t ofs;
206 size_t pad;
207 NDR_CHECK(ndr_pull_align(ndr, 4));
208 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
209 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
210 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
211 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
212 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
213 ofs = ndr->offset + 64;
214 pad = ndr_align_size(ofs, 16);
215 NDR_CHECK(ndr_pull_advance(ndr, pad));
216 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
217 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
219 if (ndr_flags & NDR_BUFFERS) {
221 return NDR_ERR_SUCCESS;