LCOV - code coverage report
Current view: top level - librpc/ndr - ndr_xattr.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 39 85 45.9 %
Date: 2024-04-21 15:09:00 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    helper routines for XATTR marshalling
       5             : 
       6             :    Copyright (C) Stefan (metze) Metzmacher 2009
       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_xattr.h"
      24             : 
      25      175550 : static char *ndr_compat_xattr_attrib_hex(TALLOC_CTX *mem_ctx,
      26             :                                         const struct xattr_DOSATTRIB *r)
      27             : {
      28      175550 :         char *attrib_hex = NULL;
      29             : 
      30      175550 :         switch (r->version) {
      31           0 :         case 0xFFFF:
      32           0 :                 attrib_hex = talloc_asprintf(mem_ctx, "0x%"PRIx32,
      33           0 :                                         r->info.compatinfoFFFF.attrib);
      34           0 :                 break;
      35           0 :         case 1:
      36           0 :                 attrib_hex = talloc_asprintf(mem_ctx, "0x%"PRIx32,
      37           0 :                                         r->info.info1.attrib);
      38           0 :                 break;
      39           0 :         case 2:
      40           0 :                 attrib_hex = talloc_asprintf(mem_ctx, "0x%"PRIx32,
      41           0 :                                         r->info.oldinfo2.attrib);
      42           0 :                 break;
      43           0 :         case 3:
      44           0 :                 if (!(r->info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
      45           0 :                         attrib_hex = talloc_strdup(mem_ctx, "");
      46           0 :                         break;
      47             :                 }
      48           0 :                 attrib_hex = talloc_asprintf(mem_ctx, "0x%"PRIx32,
      49           0 :                                         r->info.info3.attrib);
      50           0 :                 break;
      51      175550 :         default:
      52      175550 :                 attrib_hex = talloc_strdup(mem_ctx, "");
      53      175550 :                 break;
      54             :         }
      55             : 
      56      175550 :         return attrib_hex;
      57             : }
      58             : 
      59      175550 : _PUBLIC_ enum ndr_err_code ndr_push_xattr_DOSATTRIB(struct ndr_push *ndr,
      60             :                                                 ndr_flags_type ndr_flags,
      61             :                                                 const struct xattr_DOSATTRIB *r)
      62             : {
      63      175550 :         if (ndr_flags & NDR_SCALARS) {
      64      175550 :                 char *attrib_hex = NULL;
      65             : 
      66      175550 :                 attrib_hex = ndr_compat_xattr_attrib_hex(ndr, r);
      67      175550 :                 NDR_ERR_HAVE_NO_MEMORY(attrib_hex);
      68             : 
      69      175550 :                 NDR_CHECK(ndr_push_align(ndr, 4));
      70             :                 {
      71      175550 :                         libndr_flags _flags_save_string = ndr->flags;
      72      175550 :                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM);
      73      175550 :                         NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, attrib_hex));
      74      175550 :                         ndr->flags = _flags_save_string;
      75             :                 }
      76      175550 :                 if (r->version == 0xFFFF) {
      77           0 :                         return NDR_ERR_SUCCESS;
      78             :                 }
      79      175550 :                 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->version));
      80      175550 :                 NDR_CHECK(ndr_push_set_switch_value(ndr, &r->info, r->version));
      81      175550 :                 NDR_CHECK(ndr_push_xattr_DosInfo(ndr, NDR_SCALARS, &r->info));
      82             :         }
      83      175550 :         if (ndr_flags & NDR_BUFFERS) {
      84         467 :         }
      85      175550 :         return NDR_ERR_SUCCESS;
      86             : }
      87             : 
      88     1343975 : _PUBLIC_ enum ndr_err_code ndr_pull_xattr_DOSATTRIB(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct xattr_DOSATTRIB *r)
      89             : {
      90     1343975 :         if (ndr_flags & NDR_SCALARS) {
      91     1343975 :                 NDR_CHECK(ndr_pull_align(ndr, 4));
      92             :                 {
      93     1343975 :                         libndr_flags _flags_save_string = ndr->flags;
      94     1343975 :                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM);
      95     1343975 :                         NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->attrib_hex));
      96     1343975 :                         ndr->flags = _flags_save_string;
      97             :                 }
      98     1343975 :                 if (ndr->offset >= ndr->data_size) {
      99           0 :                         unsigned int dosattr;
     100           0 :                         int ret;
     101             : 
     102           0 :                         if (r->attrib_hex[0] != '0') {
     103             : 
     104           0 :                         }
     105           0 :                         if (r->attrib_hex[1] != 'x') {
     106             : 
     107           0 :                         }
     108           0 :                         ret = sscanf(r->attrib_hex, "%x", &dosattr);
     109           0 :                         if (ret != 1) {
     110           0 :                         }
     111           0 :                         r->version = 0xFFFF;
     112           0 :                         r->info.compatinfoFFFF.attrib = dosattr;
     113           0 :                         return NDR_ERR_SUCCESS;
     114             :                 }
     115     1343975 :                 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->version));
     116     1343975 :                 if (r->version == 0xFFFF) {
     117           0 :                         return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH,
     118             :                                         "ndr_pull_xattr_DOSATTRIB: "
     119             :                                         "invalid level 0x%02"PRIX16,
     120             :                                         r->version);
     121             :                 }
     122     1343975 :                 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->info, r->version));
     123     1343975 :                 NDR_CHECK(ndr_pull_xattr_DosInfo(ndr, NDR_SCALARS, &r->info));
     124             :         }
     125     1343975 :         if (ndr_flags & NDR_BUFFERS) {
     126        2134 :         }
     127     1343975 :         return NDR_ERR_SUCCESS;
     128             : }
     129             : 
     130           0 : _PUBLIC_ void ndr_print_xattr_DOSATTRIB(struct ndr_print *ndr, const char *name, const struct xattr_DOSATTRIB *r)
     131             : {
     132           0 :         char *attrib_hex;
     133             : 
     134           0 :         ndr_print_struct(ndr, name, "xattr_DOSATTRIB");
     135           0 :         ndr->depth++;
     136             : 
     137           0 :         if (ndr->flags & LIBNDR_PRINT_SET_VALUES) {
     138           0 :                 attrib_hex = ndr_compat_xattr_attrib_hex(ndr, r);
     139             :         } else {
     140           0 :                 attrib_hex = talloc_strdup(ndr, r->attrib_hex);
     141             :         }
     142           0 :         ndr_print_string(ndr, "attrib_hex", attrib_hex);
     143             : 
     144           0 :         ndr_print_uint16(ndr, "version", r->version);
     145           0 :         ndr_print_set_switch_value(ndr, &r->info, r->version);
     146           0 :         ndr_print_xattr_DosInfo(ndr, "info", &r->info);
     147           0 :         ndr->depth--;
     148           0 : }

Generated by: LCOV version 1.14