tdb: always open internal databases with incompatible hash.
[Samba.git] / librpc / ndr / ndr_xattr.c
blob930f5106122d3834290460bfe93755afaa818327
1 /*
2 Unix SMB/CIFS implementation.
4 helper routines for XATTR marshalling
6 Copyright (C) Stefan (metze) Metzmacher 2009
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_xattr.h"
25 static char *ndr_compat_xattr_attrib_hex(TALLOC_CTX *mem_ctx,
26 const struct xattr_DOSATTRIB *r)
28 char *attrib_hex = NULL;
30 switch (r->version) {
31 case 0xFFFF:
32 attrib_hex = talloc_asprintf(mem_ctx, "0x%x",
33 r->info.compatinfoFFFF.attrib);
34 break;
35 case 1:
36 attrib_hex = talloc_asprintf(mem_ctx, "0x%x",
37 r->info.info1.attrib);
38 break;
39 case 2:
40 attrib_hex = talloc_asprintf(mem_ctx, "0x%x",
41 r->info.oldinfo2.attrib);
42 break;
43 case 3:
44 if (!(r->info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
45 attrib_hex = talloc_strdup(mem_ctx, "");
46 break;
48 attrib_hex = talloc_asprintf(mem_ctx, "0x%x",
49 r->info.info3.attrib);
50 break;
51 default:
52 attrib_hex = talloc_strdup(mem_ctx, "");
53 break;
56 return attrib_hex;
59 _PUBLIC_ enum ndr_err_code ndr_push_xattr_DOSATTRIB(struct ndr_push *ndr,
60 int ndr_flags,
61 const struct xattr_DOSATTRIB *r)
63 if (ndr_flags & NDR_SCALARS) {
64 char *attrib_hex = NULL;
66 attrib_hex = ndr_compat_xattr_attrib_hex(ndr, r);
67 NDR_ERR_HAVE_NO_MEMORY(attrib_hex);
69 NDR_CHECK(ndr_push_align(ndr, 4));
71 uint32_t _flags_save_string = ndr->flags;
72 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM);
73 NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, attrib_hex));
74 ndr->flags = _flags_save_string;
76 if (r->version == 0xFFFF) {
77 return NDR_ERR_SUCCESS;
79 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->version));
80 NDR_CHECK(ndr_push_set_switch_value(ndr, &r->info, r->version));
81 NDR_CHECK(ndr_push_xattr_DosInfo(ndr, NDR_SCALARS, &r->info));
83 if (ndr_flags & NDR_BUFFERS) {
85 return NDR_ERR_SUCCESS;
88 _PUBLIC_ enum ndr_err_code ndr_pull_xattr_DOSATTRIB(struct ndr_pull *ndr, int ndr_flags, struct xattr_DOSATTRIB *r)
90 if (ndr_flags & NDR_SCALARS) {
91 NDR_CHECK(ndr_pull_align(ndr, 4));
93 uint32_t _flags_save_string = ndr->flags;
94 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM);
95 NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->attrib_hex));
96 ndr->flags = _flags_save_string;
98 if (ndr->offset >= ndr->data_size) {
99 unsigned int dosattr;
100 int ret;
102 if (r->attrib_hex[0] != '0') {
105 if (r->attrib_hex[1] != 'x') {
108 ret = sscanf(r->attrib_hex, "%x", &dosattr);
109 if (ret != 1) {
111 r->version = 0xFFFF;
112 r->info.compatinfoFFFF.attrib = dosattr;
113 return NDR_ERR_SUCCESS;
115 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->version));
116 if (r->version == 0xFFFF) {
117 return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH,
118 "ndr_pull_xattr_DOSATTRIB: "
119 "invalid level 0x%02X",
120 r->version);
122 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->info, r->version));
123 NDR_CHECK(ndr_pull_xattr_DosInfo(ndr, NDR_SCALARS, &r->info));
125 if (ndr_flags & NDR_BUFFERS) {
127 return NDR_ERR_SUCCESS;
130 _PUBLIC_ void ndr_print_xattr_DOSATTRIB(struct ndr_print *ndr, const char *name, const struct xattr_DOSATTRIB *r)
132 char *attrib_hex;
134 ndr_print_struct(ndr, name, "xattr_DOSATTRIB");
135 ndr->depth++;
137 if (ndr->flags & LIBNDR_PRINT_SET_VALUES) {
138 attrib_hex = ndr_compat_xattr_attrib_hex(ndr, r);
139 } else {
140 attrib_hex = talloc_strdup(ndr, r->attrib_hex);
142 ndr_print_string(ndr, "attrib_hex", attrib_hex);
144 ndr_print_uint16(ndr, "version", r->version);
145 ndr_print_set_switch_value(ndr, &r->info, r->version);
146 ndr_print_xattr_DosInfo(ndr, "info", &r->info);
147 ndr->depth--;