Coverage Report

Created: 2026-05-24 06:47

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