spoolss: remove unused spoolss_StringArray2.
[ira/wip.git] / librpc / ndr / ndr_xattr.c
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 {
28         char *attrib_hex = NULL;
29
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;
47                 }
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;
54         }
55
56         return attrib_hex;
57 }
58
59 _PUBLIC_ enum ndr_err_code ndr_push_xattr_DOSATTRIB(struct ndr_push *ndr,
60                                                 int ndr_flags,
61                                                 const struct xattr_DOSATTRIB *r)
62 {
63         if (ndr_flags & NDR_SCALARS) {
64                 char *attrib_hex = NULL;
65
66                 attrib_hex = ndr_compat_xattr_attrib_hex(ndr, r);
67                 NDR_ERR_HAVE_NO_MEMORY(attrib_hex);
68
69                 NDR_CHECK(ndr_push_align(ndr, 4));
70                 {
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;
75                 }
76                 if (r->version == 0xFFFF) {
77                         return NDR_ERR_SUCCESS;
78                 }
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));
82         }
83         if (ndr_flags & NDR_BUFFERS) {
84         }
85         return NDR_ERR_SUCCESS;
86 }
87
88 _PUBLIC_ enum ndr_err_code ndr_pull_xattr_DOSATTRIB(struct ndr_pull *ndr, int ndr_flags, struct xattr_DOSATTRIB *r)
89 {
90         if (ndr_flags & NDR_SCALARS) {
91                 NDR_CHECK(ndr_pull_align(ndr, 4));
92                 {
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;
97                 }
98                 if (ndr->offset >= ndr->data_size) {
99                         unsigned int dosattr;
100                         int ret;
101
102                         if (r->attrib_hex[0] != '0') {
103
104                         }
105                         if (r->attrib_hex[1] != 'x') {
106
107                         }
108                         ret = sscanf(r->attrib_hex, "%x", &dosattr);
109                         if (ret != 1) {
110                         }
111                         r->version = 0xFFFF;
112                         r->info.compatinfoFFFF.attrib = dosattr;
113                         return NDR_ERR_SUCCESS;
114                 }
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);
121                 }
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));
124         }
125         if (ndr_flags & NDR_BUFFERS) {
126         }
127         return NDR_ERR_SUCCESS;
128 }
129
130 _PUBLIC_ void ndr_print_xattr_DOSATTRIB(struct ndr_print *ndr, const char *name, const struct xattr_DOSATTRIB *r)
131 {
132         char *attrib_hex;
133
134         ndr_print_struct(ndr, name, "xattr_DOSATTRIB");
135         ndr->depth++;
136
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);
141         }
142         ndr_print_string(ndr, "attrib_hex", attrib_hex);
143
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--;
148 }