2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
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/>.
24 NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
30 return NT_STATUS_BUFFER_TOO_SMALL;
32 return NT_STATUS_INTERNAL_ERROR;
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;
45 /* we should map all error codes to different status codes */
46 return NT_STATUS_INVALID_PARAMETER;
50 * Convert an ndr error to string
53 const char *ndr_errstr(enum ndr_err_code err)
57 return "NDR_ERR_SUCCESS";
59 case NDR_ERR_ARRAY_SIZE:
60 return "NDR_ERR_ARRAY_SIZE";
62 case NDR_ERR_BAD_SWITCH:
63 return "NDR_ERR_BAD_SWITCH";
66 return "NDR_ERR_OFFSET";
68 case NDR_ERR_RELATIVE:
69 return "NDR_ERR_RELATIVE";
72 return "NDR_ERR_CHARCNV";
75 return "NDR_ERR_LENGTH";
77 case NDR_ERR_SUBCONTEXT:
78 return "NDR_ERR_SUBCONTEXT";
80 case NDR_ERR_COMPRESSION:
81 return "NDR_ERR_COMPRESSION";
84 return "NDR_ERR_STRING";
86 case NDR_ERR_VALIDATE:
87 return "NDR_ERR_VALIDATE";
90 return "NDR_ERR_BUFSIZE";
93 return "NDR_ERR_ALLOC";
96 return "NDR_ERR_RANGE";
99 return "NDR_ERR_TOKEN";
101 case NDR_ERR_IPV4ADDRESS:
102 return "NDR_ERR_IPV4ADDRESS";
104 case NDR_ERR_IPV6ADDRESS:
105 return "NDR_ERR_IPV6ADDRESS";
107 case NDR_ERR_INVALID_POINTER:
108 return "NDR_ERR_INVALID_POINTER";
110 case NDR_ERR_UNREAD_BYTES:
111 return "NDR_ERR_UNREAD_BYTES";
114 return "NDR_ERR_NDR64";
118 return talloc_asprintf(talloc_tos(), "Unknown NDR error: %d", err);
121 enum ndr_err_code ndr_push_server_id(struct ndr_push *ndr, int ndr_flags, const struct server_id *r)
123 if (ndr_flags & NDR_SCALARS) {
124 NDR_CHECK(ndr_push_align(ndr, 4));
125 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS,
127 #ifdef CLUSTER_SUPPORT
128 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS,
132 if (ndr_flags & NDR_BUFFERS) {
134 return NDR_ERR_SUCCESS;
137 enum ndr_err_code ndr_pull_server_id(struct ndr_pull *ndr, int ndr_flags, struct server_id *r)
139 if (ndr_flags & NDR_SCALARS) {
141 NDR_CHECK(ndr_pull_align(ndr, 4));
142 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &pid));
143 #ifdef CLUSTER_SUPPORT
144 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->vnn));
148 if (ndr_flags & NDR_BUFFERS) {
150 return NDR_ERR_SUCCESS;
153 void ndr_print_server_id(struct ndr_print *ndr, const char *name, const struct server_id *r)
155 ndr_print_struct(ndr, name, "server_id");
157 ndr_print_uint32(ndr, "id", (uint32_t)r->pid);
158 #ifdef CLUSTER_SUPPORT
159 ndr_print_uint32(ndr, "vnn", (uint32_t)r->vnn);
164 _PUBLIC_ void ndr_print_sockaddr_storage(struct ndr_print *ndr, const char *name, const struct sockaddr_storage *ss)
166 char addr[INET6_ADDRSTRLEN];
167 ndr->print(ndr, "%-25s: %s", name, print_sockaddr(addr, sizeof(addr), ss));
170 const struct ndr_syntax_id null_ndr_syntax_id =
171 { { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } }, 0 };