LCOV - code coverage report
Current view: top level - librpc/ndr - ndr_backupkey.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 58 137 42.3 %
Date: 2024-04-21 15:09:00 Functions: 4 6 66.7 %

          Line data    Source code
       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           0 : static uint32_t backupkeyguid_to_uint(const struct GUID *guid)
      28             : {
      29           0 :         struct GUID tmp;
      30           0 :         NTSTATUS status;
      31           0 :         bool match;
      32             : 
      33           0 :         status = GUID_from_string(BACKUPKEY_RESTORE_GUID, &tmp);
      34           0 :         if (NT_STATUS_IS_OK(status)) {
      35           0 :                 match = GUID_equal(guid, &tmp);
      36           0 :                 if (match) {
      37           0 :                         return BACKUPKEY_RESTORE_GUID_INTEGER;
      38             :                 }
      39             :         }
      40             : 
      41           0 :         status = GUID_from_string(BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID, &tmp);
      42           0 :         if (NT_STATUS_IS_OK(status)) {
      43           0 :                 match = GUID_equal(guid, &tmp);
      44           0 :                 if (match) {
      45           0 :                         return BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID_INTEGER;
      46             :                 }
      47             :         }
      48             : 
      49           0 :         return BACKUPKEY_INVALID_GUID_INTEGER;
      50             : }
      51             : 
      52           0 : _PUBLIC_ void ndr_print_bkrp_BackupKey(struct ndr_print *ndr, const char *name, ndr_flags_type flags, const struct bkrp_BackupKey *r)
      53             : {
      54           0 :         ndr_print_struct(ndr, name, "bkrp_BackupKey");
      55           0 :         if (r == NULL) { ndr_print_null(ndr); return; }
      56           0 :         ndr->depth++;
      57           0 :         if (flags & NDR_SET_VALUES) {
      58           0 :                 ndr->flags |= LIBNDR_PRINT_SET_VALUES;
      59             :         }
      60           0 :         if (flags & NDR_IN) {
      61           0 :                 union bkrp_data_in_blob inblob = {
      62             :                         .empty._empty_ = '\0',
      63             :                 };
      64           0 :                 DATA_BLOB blob;
      65           0 :                 uint32_t level;
      66           0 :                 enum ndr_err_code ndr_err;
      67             : 
      68           0 :                 ndr_print_struct(ndr, "in", "bkrp_BackupKey");
      69           0 :                 ndr->depth++;
      70           0 :                 ndr_print_ptr(ndr, "guidActionAgent", r->in.guidActionAgent);
      71           0 :                 ndr->depth++;
      72           0 :                 ndr_print_GUID(ndr, "guidActionAgent", r->in.guidActionAgent);
      73           0 :                 ndr->depth--;
      74             : 
      75           0 :                 level = backupkeyguid_to_uint(r->in.guidActionAgent);
      76           0 :                 ndr_err = ndr_print_set_switch_value(ndr, &inblob, level);
      77           0 :                 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             :                 }
      81           0 :                 blob.data = r->in.data_in;
      82           0 :                 blob.length = r->in.data_in_len;
      83           0 :                 ndr_err = ndr_pull_union_blob(&blob, ndr, &inblob, level,
      84             :                                 (ndr_pull_flags_fn_t)ndr_pull_bkrp_data_in_blob);
      85             : 
      86           0 :                 ndr_print_ptr(ndr, "data_in", r->in.data_in);
      87           0 :                 ndr->depth++;
      88           0 :                 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
      89           0 :                         ndr_print_bkrp_data_in_blob(ndr, "data_in", &inblob);
      90             :                 } else {
      91           0 :                         ndr_print_array_uint8(ndr, "data_in", r->in.data_in, r->in.data_in_len);
      92             :                 }
      93           0 :                 ndr->depth--;
      94             : 
      95           0 :                 ndr_print_uint32(ndr, "data_in_len", r->in.data_in_len);
      96           0 :                 ndr_print_uint32(ndr, "param", r->in.param);
      97           0 :                 ndr->depth--;
      98             :         }
      99           0 :         if (flags & NDR_OUT) {
     100           0 :                 ndr_print_struct(ndr, "out", "bkrp_BackupKey");
     101           0 :                 ndr->depth++;
     102           0 :                 ndr_print_ptr(ndr, "data_out", r->out.data_out);
     103           0 :                 ndr->depth++;
     104           0 :                 ndr_print_ptr(ndr, "data_out", *r->out.data_out);
     105           0 :                 ndr->depth++;
     106             : 
     107           0 :                 if (*r->out.data_out) {
     108           0 :                         ndr_print_array_uint8(ndr, "data_out", *r->out.data_out, *r->out.data_out_len);
     109             :                 }
     110           0 :                 ndr->depth--;
     111           0 :                 ndr->depth--;
     112           0 :                 ndr_print_ptr(ndr, "data_out_len", r->out.data_out_len);
     113           0 :                 ndr->depth++;
     114           0 :                 ndr_print_uint32(ndr, "data_out_len", *r->out.data_out_len);
     115           0 :                 ndr->depth--;
     116           0 :                 ndr_print_WERROR(ndr, "result", r->out.result);
     117           0 :                 ndr->depth--;
     118             :         }
     119           0 :         ndr->depth--;
     120             : }
     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           7 : _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             : {
     128           7 :         if (ndr_flags & NDR_SCALARS) {
     129           0 :                 size_t ofs;
     130           0 :                 size_t pad;
     131           7 :                 NDR_CHECK(ndr_push_align(ndr, 4));
     132           7 :                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
     133           7 :                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
     134           7 :                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
     135           7 :                 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           7 :                 ofs = ndr->offset + 20;
     141           7 :                 pad = ndr_align_size(ofs, 8);
     142           7 :                 NDR_CHECK(ndr_push_zero(ndr, pad));
     143           7 :                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
     144           7 :                 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
     145             :         }
     146           7 :         if (ndr_flags & NDR_BUFFERS) {
     147           0 :         }
     148           7 :         return NDR_ERR_SUCCESS;
     149             : }
     150             : 
     151           5 : _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             : {
     153           5 :         if (ndr_flags & NDR_SCALARS) {
     154           0 :                 size_t ofs;
     155           0 :                 size_t pad;
     156           5 :                 NDR_CHECK(ndr_pull_align(ndr, 4));
     157           5 :                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
     158           5 :                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
     159           5 :                 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
     160           5 :                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
     161           5 :                 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
     162           5 :                 ofs = ndr->offset + 20;
     163           5 :                 pad = ndr_align_size(ofs, 8);
     164           5 :                 NDR_CHECK(ndr_pull_advance(ndr, pad));
     165           5 :                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 20));
     166           5 :                 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
     167             :         }
     168           5 :         if (ndr_flags & NDR_BUFFERS) {
     169           0 :         }
     170           5 :         return NDR_ERR_SUCCESS;
     171             : }
     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           4 : _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             : {
     179           4 :         if (ndr_flags & NDR_SCALARS) {
     180           0 :                 size_t ofs;
     181           0 :                 size_t pad;
     182           4 :                 NDR_CHECK(ndr_push_align(ndr, 4));
     183           4 :                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x00000001));
     184           4 :                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->nonce_len));
     185           4 :                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
     186           4 :                 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           4 :                 ofs = ndr->offset + 64;
     192           4 :                 pad = ndr_align_size(ofs, 16);
     193           4 :                 NDR_CHECK(ndr_push_zero(ndr, pad));
     194           4 :                 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
     195           4 :                 NDR_CHECK(ndr_push_trailer_align(ndr, 4));
     196             :         }
     197           4 :         if (ndr_flags & NDR_BUFFERS) {
     198           0 :         }
     199           4 :         return NDR_ERR_SUCCESS;
     200             : }
     201             : 
     202           1 : _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             : {
     204           1 :         if (ndr_flags & NDR_SCALARS) {
     205           0 :                 size_t ofs;
     206           0 :                 size_t pad;
     207           1 :                 NDR_CHECK(ndr_pull_align(ndr, 4));
     208           1 :                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->magic));
     209           1 :                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->nonce_len));
     210           1 :                 NDR_PULL_ALLOC_N(ndr, r->nonce, r->nonce_len);
     211           1 :                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->nonce, r->nonce_len));
     212           1 :                 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->sid));
     213           1 :                 ofs = ndr->offset + 64;
     214           1 :                 pad = ndr_align_size(ofs, 16);
     215           1 :                 NDR_CHECK(ndr_pull_advance(ndr, pad));
     216           1 :                 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->hash, 64));
     217           1 :                 NDR_CHECK(ndr_pull_trailer_align(ndr, 4));
     218             :         }
     219           1 :         if (ndr_flags & NDR_BUFFERS) {
     220           0 :         }
     221           1 :         return NDR_ERR_SUCCESS;
     222             : }

Generated by: LCOV version 1.14