Coverage Report

Created: 2025-12-31 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/librpc/ndr/ndr_backupkey.c
Line
Count
Source
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
306
{
29
306
  struct GUID tmp;
30
306
  NTSTATUS status;
31
306
  bool match;
32
33
306
  status = GUID_from_string(BACKUPKEY_RESTORE_GUID, &tmp);
34
306
  if (NT_STATUS_IS_OK(status)) {
35
306
    match = GUID_equal(guid, &tmp);
36
306
    if (match) {
37
32
      return BACKUPKEY_RESTORE_GUID_INTEGER;
38
32
    }
39
306
  }
40
41
274
  status = GUID_from_string(BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID, &tmp);
42
274
  if (NT_STATUS_IS_OK(status)) {
43
274
    match = GUID_equal(guid, &tmp);
44
274
    if (match) {
45
1
      return BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID_INTEGER;
46
1
    }
47
274
  }
48
49
273
  return BACKUPKEY_INVALID_GUID_INTEGER;
50
274
}
51
52
_PUBLIC_ void ndr_print_bkrp_BackupKey(struct ndr_print *ndr, const char *name, ndr_flags_type flags, const struct bkrp_BackupKey *r)
53
8.06k
{
54
8.06k
  ndr_print_struct(ndr, name, "bkrp_BackupKey");
55
8.06k
  if (r == NULL) { ndr_print_null(ndr); return; }
56
8.06k
  ndr->depth++;
57
8.06k
  if (flags & NDR_SET_VALUES) {
58
0
    ndr->flags |= LIBNDR_PRINT_SET_VALUES;
59
0
  }
60
8.06k
  if (flags & NDR_IN) {
61
306
    union bkrp_data_in_blob inblob = {
62
306
      .empty._empty_ = '\0',
63
306
    };
64
306
    DATA_BLOB blob;
65
306
    uint32_t level;
66
306
    enum ndr_err_code ndr_err;
67
68
306
    ndr_print_struct(ndr, "in", "bkrp_BackupKey");
69
306
    ndr->depth++;
70
306
    ndr_print_ptr(ndr, "guidActionAgent", r->in.guidActionAgent);
71
306
    ndr->depth++;
72
306
    ndr_print_GUID(ndr, "guidActionAgent", r->in.guidActionAgent);
73
306
    ndr->depth--;
74
75
306
    level = backupkeyguid_to_uint(r->in.guidActionAgent);
76
306
    ndr_err = ndr_print_set_switch_value(ndr, &inblob, level);
77
306
    if (unlikely(!NDR_ERR_CODE_IS_SUCCESS(ndr_err))) { \
78
0
      DEBUG(0,("ERROR: ndr_print_bkrp_BackupKey ndr_print_set_switch_value failed: %d\n", ndr_err));
79
0
      return;
80
0
    }
81
306
    blob.data = r->in.data_in;
82
306
    blob.length = r->in.data_in_len;
83
306
    ndr_err = ndr_pull_union_blob(&blob, ndr, &inblob, level,
84
306
        (ndr_pull_flags_fn_t)ndr_pull_bkrp_data_in_blob);
85
86
306
    ndr_print_ptr(ndr, "data_in", r->in.data_in);
87
306
    ndr->depth++;
88
306
    if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
89
6
      ndr_print_bkrp_data_in_blob(ndr, "data_in", &inblob);
90
300
    } else {
91
300
      ndr_print_array_uint8(ndr, "data_in", r->in.data_in, r->in.data_in_len);
92
300
    }
93
306
    ndr->depth--;
94
95
306
    ndr_print_uint32(ndr, "data_in_len", r->in.data_in_len);
96
306
    ndr_print_uint32(ndr, "param", r->in.param);
97
306
    ndr->depth--;
98
306
  }
99
8.06k
  if (flags & NDR_OUT) {
100
7.76k
    ndr_print_struct(ndr, "out", "bkrp_BackupKey");
101
7.76k
    ndr->depth++;
102
7.76k
    ndr_print_ptr(ndr, "data_out", r->out.data_out);
103
7.76k
    ndr->depth++;
104
7.76k
    ndr_print_ptr(ndr, "data_out", *r->out.data_out);
105
7.76k
    ndr->depth++;
106
107
7.76k
    if (*r->out.data_out) {
108
79
      ndr_print_array_uint8(ndr, "data_out", *r->out.data_out, *r->out.data_out_len);
109
79
    }
110
7.76k
    ndr->depth--;
111
7.76k
    ndr->depth--;
112
7.76k
    ndr_print_ptr(ndr, "data_out_len", r->out.data_out_len);
113
7.76k
    ndr->depth++;
114
7.76k
    ndr_print_uint32(ndr, "data_out_len", *r->out.data_out_len);
115
7.76k
    ndr->depth--;
116
7.76k
    ndr_print_WERROR(ndr, "result", r->out.result);
117
7.76k
    ndr->depth--;
118
7.76k
  }
119
8.06k
  ndr->depth--;
120
8.06k
}
121
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)
125
 */
126
_PUBLIC_ enum ndr_err_code ndr_push_bkrp_access_check_v2(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct bkrp_access_check_v2 *r)
127
86
{
128
86
  if (ndr_flags & NDR_SCALARS) {
129
86
    size_t ofs;
130
86
    size_t pad;
131
86
    NDR_CHECK(ndr_push_align(ndr, 4));
132
86
    NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
133
86
    NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
134
86
    NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
135
86
    NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
136
    /* We articially increment the offset of 20 bytes (size of hash
137
     * coming after the pad) so that ndr_align can determine easily
138
     * the correct pad size to make the whole struct 8 bytes aligned
139
     */
140
86
    ofs = ndr->offset + 20;
141
86
    pad = ndr_align_size(ofs, 8);
142
86
    NDR_CHECK(ndr_push_zero(ndr, pad));
143
86
    NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
144
86
    NDR_CHECK(ndr_push_trailer_align(ndr, 4));
145
86
  }
146
86
  if (ndr_flags & NDR_BUFFERS) {
147
86
  }
148
86
  return NDR_ERR_SUCCESS;
149
86
}
150
151
_PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v2(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct bkrp_access_check_v2 *r)
152
253
{
153
253
  if (ndr_flags & NDR_SCALARS) {
154
253
    size_t ofs;
155
253
    size_t pad;
156
253
    NDR_CHECK(ndr_pull_align(ndr, 4));
157
253
    NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
158
251
    NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
159
250
    NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
160
247
    NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
161
207
    NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
162
101
    ofs = ndr->offset + 20;
163
101
    pad = ndr_align_size(ofs, 8);
164
101
    NDR_CHECK(ndr_pull_advance(ndr, pad));
165
97
    NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
166
86
    NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
167
86
  }
168
86
  if (ndr_flags & NDR_BUFFERS) {
169
86
  }
170
86
  return NDR_ERR_SUCCESS;
171
253
}
172
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)
176
 */
177
_PUBLIC_ enum ndr_err_code ndr_push_bkrp_access_check_v3(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct bkrp_access_check_v3 *r)
178
21
{
179
21
  if (ndr_flags & NDR_SCALARS) {
180
21
    size_t ofs;
181
21
    size_t pad;
182
21
    NDR_CHECK(ndr_push_align(ndr, 4));
183
21
    NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
184
21
    NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
185
21
    NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
186
21
    NDR_CHECK(ndr_push_dom_sid(ndr, NDR_SCALARS, &r->sid));
187
    /* We articially increment the offset of 64 bytes (size of hash
188
     * coming after the pad) so that ndr_align can determine easily
189
     * the correct pad size to make the whole struct 16 bytes aligned
190
     */
191
21
    ofs = ndr->offset + 64;
192
21
    pad = ndr_align_size(ofs, 16);
193
21
    NDR_CHECK(ndr_push_zero(ndr, pad));
194
21
    NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
195
21
    NDR_CHECK(ndr_push_trailer_align(ndr, 4));
196
21
  }
197
21
  if (ndr_flags & NDR_BUFFERS) {
198
21
  }
199
21
  return NDR_ERR_SUCCESS;
200
21
}
201
202
_PUBLIC_ enum ndr_err_code ndr_pull_bkrp_access_check_v3(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct bkrp_access_check_v3 *r)
203
139
{
204
139
  if (ndr_flags & NDR_SCALARS) {
205
139
    size_t ofs;
206
139
    size_t pad;
207
139
    NDR_CHECK(ndr_pull_align(ndr, 4));
208
139
    NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
209
138
    NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
210
137
    NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
211
135
    NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
212
124
    NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
213
65
    ofs = ndr->offset + 64;
214
65
    pad = ndr_align_size(ofs, 16);
215
65
    NDR_CHECK(ndr_pull_advance(ndr, pad));
216
45
    NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
217
21
    NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
218
21
  }
219
21
  if (ndr_flags & NDR_BUFFERS) {
220
21
  }
221
21
  return NDR_ERR_SUCCESS;
222
139
}