1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | libndr interface
|
---|
5 |
|
---|
6 | Copyright (C) Andrew Tridgell 2003
|
---|
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 |
|
---|
24 | NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
|
---|
25 | {
|
---|
26 | switch (ndr_err) {
|
---|
27 | case NDR_ERR_SUCCESS:
|
---|
28 | return NT_STATUS_OK;
|
---|
29 | case NDR_ERR_BUFSIZE:
|
---|
30 | return NT_STATUS_BUFFER_TOO_SMALL;
|
---|
31 | case NDR_ERR_TOKEN:
|
---|
32 | return NT_STATUS_INTERNAL_ERROR;
|
---|
33 | case NDR_ERR_ALLOC:
|
---|
34 | return NT_STATUS_NO_MEMORY;
|
---|
35 | case NDR_ERR_ARRAY_SIZE:
|
---|
36 | return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
|
---|
37 | case NDR_ERR_INVALID_POINTER:
|
---|
38 | return NT_STATUS_INVALID_PARAMETER_MIX;
|
---|
39 | case NDR_ERR_UNREAD_BYTES:
|
---|
40 | return NT_STATUS_PORT_MESSAGE_TOO_LONG;
|
---|
41 | default:
|
---|
42 | break;
|
---|
43 | }
|
---|
44 |
|
---|
45 | /* we should map all error codes to different status codes */
|
---|
46 | return NT_STATUS_INVALID_PARAMETER;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * Convert an ndr error to string
|
---|
51 | */
|
---|
52 |
|
---|
53 | const char *ndr_errstr(enum ndr_err_code err)
|
---|
54 | {
|
---|
55 | switch (err) {
|
---|
56 | case NDR_ERR_SUCCESS:
|
---|
57 | return "NDR_ERR_SUCCESS";
|
---|
58 | break;
|
---|
59 | case NDR_ERR_ARRAY_SIZE:
|
---|
60 | return "NDR_ERR_ARRAY_SIZE";
|
---|
61 | break;
|
---|
62 | case NDR_ERR_BAD_SWITCH:
|
---|
63 | return "NDR_ERR_BAD_SWITCH";
|
---|
64 | break;
|
---|
65 | case NDR_ERR_OFFSET:
|
---|
66 | return "NDR_ERR_OFFSET";
|
---|
67 | break;
|
---|
68 | case NDR_ERR_RELATIVE:
|
---|
69 | return "NDR_ERR_RELATIVE";
|
---|
70 | break;
|
---|
71 | case NDR_ERR_CHARCNV:
|
---|
72 | return "NDR_ERR_CHARCNV";
|
---|
73 | break;
|
---|
74 | case NDR_ERR_LENGTH:
|
---|
75 | return "NDR_ERR_LENGTH";
|
---|
76 | break;
|
---|
77 | case NDR_ERR_SUBCONTEXT:
|
---|
78 | return "NDR_ERR_SUBCONTEXT";
|
---|
79 | break;
|
---|
80 | case NDR_ERR_COMPRESSION:
|
---|
81 | return "NDR_ERR_COMPRESSION";
|
---|
82 | break;
|
---|
83 | case NDR_ERR_STRING:
|
---|
84 | return "NDR_ERR_STRING";
|
---|
85 | break;
|
---|
86 | case NDR_ERR_VALIDATE:
|
---|
87 | return "NDR_ERR_VALIDATE";
|
---|
88 | break;
|
---|
89 | case NDR_ERR_BUFSIZE:
|
---|
90 | return "NDR_ERR_BUFSIZE";
|
---|
91 | break;
|
---|
92 | case NDR_ERR_ALLOC:
|
---|
93 | return "NDR_ERR_ALLOC";
|
---|
94 | break;
|
---|
95 | case NDR_ERR_RANGE:
|
---|
96 | return "NDR_ERR_RANGE";
|
---|
97 | break;
|
---|
98 | case NDR_ERR_TOKEN:
|
---|
99 | return "NDR_ERR_TOKEN";
|
---|
100 | break;
|
---|
101 | case NDR_ERR_IPV4ADDRESS:
|
---|
102 | return "NDR_ERR_IPV4ADDRESS";
|
---|
103 | break;
|
---|
104 | case NDR_ERR_INVALID_POINTER:
|
---|
105 | return "NDR_ERR_INVALID_POINTER";
|
---|
106 | break;
|
---|
107 | case NDR_ERR_UNREAD_BYTES:
|
---|
108 | return "NDR_ERR_UNREAD_BYTES";
|
---|
109 | break;
|
---|
110 | case NDR_ERR_NDR64:
|
---|
111 | return "NDR_ERR_NDR64";
|
---|
112 | break;
|
---|
113 | }
|
---|
114 |
|
---|
115 | return talloc_asprintf(talloc_tos(), "Unknown NDR error: %d", err);
|
---|
116 | }
|
---|
117 |
|
---|
118 | enum ndr_err_code ndr_push_server_id(struct ndr_push *ndr, int ndr_flags, const struct server_id *r)
|
---|
119 | {
|
---|
120 | if (ndr_flags & NDR_SCALARS) {
|
---|
121 | NDR_CHECK(ndr_push_align(ndr, 4));
|
---|
122 | NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS,
|
---|
123 | (uint32_t)r->pid));
|
---|
124 | #ifdef CLUSTER_SUPPORT
|
---|
125 | NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS,
|
---|
126 | (uint32_t)r->vnn));
|
---|
127 | #endif
|
---|
128 | }
|
---|
129 | if (ndr_flags & NDR_BUFFERS) {
|
---|
130 | }
|
---|
131 | return NDR_ERR_SUCCESS;
|
---|
132 | }
|
---|
133 |
|
---|
134 | enum ndr_err_code ndr_pull_server_id(struct ndr_pull *ndr, int ndr_flags, struct server_id *r)
|
---|
135 | {
|
---|
136 | if (ndr_flags & NDR_SCALARS) {
|
---|
137 | uint32_t pid;
|
---|
138 | NDR_CHECK(ndr_pull_align(ndr, 4));
|
---|
139 | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &pid));
|
---|
140 | #ifdef CLUSTER_SUPPORT
|
---|
141 | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->vnn));
|
---|
142 | #endif
|
---|
143 | r->pid = (pid_t)pid;
|
---|
144 | }
|
---|
145 | if (ndr_flags & NDR_BUFFERS) {
|
---|
146 | }
|
---|
147 | return NDR_ERR_SUCCESS;
|
---|
148 | }
|
---|
149 |
|
---|
150 | void ndr_print_server_id(struct ndr_print *ndr, const char *name, const struct server_id *r)
|
---|
151 | {
|
---|
152 | ndr_print_struct(ndr, name, "server_id");
|
---|
153 | ndr->depth++;
|
---|
154 | ndr_print_uint32(ndr, "id", (uint32_t)r->pid);
|
---|
155 | #ifdef CLUSTER_SUPPORT
|
---|
156 | ndr_print_uint32(ndr, "vnn", (uint32_t)r->vnn);
|
---|
157 | #endif
|
---|
158 | ndr->depth--;
|
---|
159 | }
|
---|
160 |
|
---|
161 | enum ndr_err_code ndr_push_file_id(struct ndr_push *ndr, int ndr_flags, const struct file_id *r)
|
---|
162 | {
|
---|
163 | if (ndr_flags & NDR_SCALARS) {
|
---|
164 | NDR_CHECK(ndr_push_align(ndr, 4));
|
---|
165 | NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS,
|
---|
166 | (uint64_t)r->devid));
|
---|
167 | NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS,
|
---|
168 | (uint64_t)r->inode));
|
---|
169 | NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS,
|
---|
170 | (uint64_t)r->extid));
|
---|
171 | }
|
---|
172 | if (ndr_flags & NDR_BUFFERS) {
|
---|
173 | }
|
---|
174 | return NDR_ERR_SUCCESS;
|
---|
175 | }
|
---|
176 |
|
---|
177 | enum ndr_err_code ndr_pull_file_id(struct ndr_pull *ndr, int ndr_flags, struct file_id *r)
|
---|
178 | {
|
---|
179 | if (ndr_flags & NDR_SCALARS) {
|
---|
180 | NDR_CHECK(ndr_pull_align(ndr, 4));
|
---|
181 | NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->devid));
|
---|
182 | NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->inode));
|
---|
183 | NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->extid));
|
---|
184 | }
|
---|
185 | if (ndr_flags & NDR_BUFFERS) {
|
---|
186 | }
|
---|
187 | return NDR_ERR_SUCCESS;
|
---|
188 | }
|
---|
189 |
|
---|
190 | void ndr_print_file_id(struct ndr_print *ndr, const char *name, const struct file_id *r)
|
---|
191 | {
|
---|
192 | ndr_print_struct(ndr, name, "file_id");
|
---|
193 | ndr->depth++;
|
---|
194 | ndr_print_udlong(ndr, "devid", (uint64_t)r->devid);
|
---|
195 | ndr_print_udlong(ndr, "inode", (uint64_t)r->inode);
|
---|
196 | ndr_print_udlong(ndr, "extid", (uint64_t)r->extid);
|
---|
197 | ndr->depth--;
|
---|
198 | }
|
---|
199 |
|
---|
200 | _PUBLIC_ void ndr_print_bool(struct ndr_print *ndr, const char *name, const bool b)
|
---|
201 | {
|
---|
202 | ndr->print(ndr, "%-25s: %s", name, b?"true":"false");
|
---|
203 | }
|
---|
204 |
|
---|
205 | _PUBLIC_ void ndr_print_sockaddr_storage(struct ndr_print *ndr, const char *name, const struct sockaddr_storage *ss)
|
---|
206 | {
|
---|
207 | char addr[INET6_ADDRSTRLEN];
|
---|
208 | ndr->print(ndr, "%-25s: %s", name, print_sockaddr(addr, sizeof(addr), ss));
|
---|
209 | }
|
---|
210 |
|
---|
211 | void *cmdline_lp_ctx;
|
---|
212 | struct smb_iconv_convenience *lp_iconv_convenience(void *lp_ctx)
|
---|
213 | {
|
---|
214 | return NULL;
|
---|
215 | }
|
---|
216 |
|
---|
217 | const struct ndr_syntax_id null_ndr_syntax_id =
|
---|
218 | { { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } }, 0 };
|
---|