Use ntvfs session close to close downstream session
[Samba/vfs_proxy.git] / libcli / util / doserr.c
blob160e7bc3e0bb7ca7014beccbd9eb9f0dbb70b89a
1 /*
2 * Unix SMB/CIFS implementation.
3 * DOS error routines
4 * Copyright (C) Tim Potter 2002.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* DOS error codes. please read doserr.h */
22 #include "includes.h"
24 struct werror_code_struct {
25 const char *dos_errstr;
26 WERROR werror;
29 static const struct werror_code_struct dos_errs[] =
31 { "WERR_OK", WERR_OK },
32 { "WERR_BADFILE", WERR_BADFILE },
33 { "WERR_ACCESS_DENIED", WERR_ACCESS_DENIED },
34 { "WERR_BADFID", WERR_BADFID },
35 { "WERR_BADFUNC", WERR_BADFUNC },
36 { "WERR_BAD_NETPATH", WERR_BAD_NETPATH },
37 { "WERR_BAD_NET_RESP", WERR_BAD_NET_RESP },
38 { "WERR_UNEXP_NET_ERR", WERR_UNEXP_NET_ERR },
39 { "WERR_INSUFFICIENT_BUFFER", WERR_INSUFFICIENT_BUFFER },
40 { "WERR_SEM_TIMEOUT", WERR_SEM_TIMEOUT },
41 { "WERR_NO_SUCH_SHARE", WERR_NO_SUCH_SHARE },
42 { "WERR_FILE_EXISTS", WERR_FILE_EXISTS },
43 { "WERR_INVALID_PARAM", WERR_INVALID_PARAM },
44 { "WERR_NOT_SUPPORTED", WERR_NOT_SUPPORTED },
45 { "WERR_DUP_NAME", WERR_DUP_NAME },
46 { "WERR_BAD_PASSWORD", WERR_BAD_PASSWORD },
47 { "WERR_NOMEM", WERR_NOMEM },
48 { "WERR_INVALID_NAME", WERR_INVALID_NAME },
49 { "WERR_UNKNOWN_LEVEL", WERR_UNKNOWN_LEVEL },
50 { "WERR_OBJECT_PATH_INVALID", WERR_OBJECT_PATH_INVALID },
51 { "WERR_ALREADY_EXISTS", WERR_ALREADY_EXISTS },
52 { "WERR_NO_MORE_ITEMS", WERR_NO_MORE_ITEMS },
53 { "WERR_MORE_DATA", WERR_MORE_DATA },
54 { "WERR_UNKNOWN_PRINTER_DRIVER", WERR_UNKNOWN_PRINTER_DRIVER },
55 { "WERR_INVALID_PRINTER_NAME", WERR_INVALID_PRINTER_NAME },
56 { "WERR_PRINTER_ALREADY_EXISTS", WERR_PRINTER_ALREADY_EXISTS },
57 { "WERR_INVALID_DATATYPE", WERR_INVALID_DATATYPE },
58 { "WERR_INVALID_ENVIRONMENT", WERR_INVALID_ENVIRONMENT },
59 { "WERR_INVALID_FORM_NAME", WERR_INVALID_FORM_NAME },
60 { "WERR_INVALID_FORM_SIZE", WERR_INVALID_FORM_SIZE },
61 { "WERR_ALREADY_SHARED", WERR_ALREADY_SHARED },
62 { "WERR_BUF_TOO_SMALL", WERR_BUF_TOO_SMALL },
63 { "WERR_JOB_NOT_FOUND", WERR_JOB_NOT_FOUND },
64 { "WERR_DEST_NOT_FOUND", WERR_DEST_NOT_FOUND },
65 { "WERR_GROUP_NOT_FOUND", WERR_GROUP_NOT_FOUND },
66 { "WERR_USER_NOT_FOUND", WERR_USER_NOT_FOUND },
67 { "WERR_NOT_LOCAL_DOMAIN", WERR_NOT_LOCAL_DOMAIN },
68 { "WERR_DOMAIN_CONTROLLER_NOT_FOUND", WERR_DOMAIN_CONTROLLER_NOT_FOUND },
69 { "WERR_TIME_DIFF_AT_DC", WERR_TIME_DIFF_AT_DC },
70 { "WERR_SETUP_NOT_JOINED", WERR_SETUP_NOT_JOINED },
71 { "WERR_SETUP_ALREADY_JOINED", WERR_SETUP_ALREADY_JOINED },
72 { "WERR_SETUP_DOMAIN_CONTROLLER", WERR_SETUP_DOMAIN_CONTROLLER },
73 { "WERR_DEVICE_NOT_AVAILABLE", WERR_DEVICE_NOT_AVAILABLE },
74 { "WERR_DEFAULT_JOIN_REQUIRED", WERR_DEFAULT_JOIN_REQUIRED },
75 { "WERR_USER_EXISTS", WERR_USER_EXISTS },
76 { "WERR_REVISION_MISMATCH", WERR_REVISION_MISMATCH },
77 { "WERR_NO_LOGON_SERVERS", WERR_NO_LOGON_SERVERS },
78 { "WERR_NO_SUCH_LOGON_SESSION", WERR_NO_SUCH_LOGON_SESSION },
79 { "WERR_USER_ALREADY_EXISTS", WERR_USER_ALREADY_EXISTS },
80 { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
81 { "WERR_GROUP_EXISTS", WERR_GROUP_EXISTS },
82 { "WERR_MEMBER_IN_GROUP", WERR_MEMBER_IN_GROUP },
83 { "WERR_USER_NOT_IN_GROUP", WERR_USER_NOT_IN_GROUP },
84 { "WERR_PRINTER_DRIVER_IN_USE", WERR_PRINTER_DRIVER_IN_USE },
85 { "WERR_STATUS_MORE_ENTRIES", WERR_STATUS_MORE_ENTRIES },
86 { "WERR_NET_NAME_NOT_FOUND", WERR_NET_NAME_NOT_FOUND },
87 { "WERR_DEVICE_NOT_SHARED", WERR_DEVICE_NOT_SHARED },
88 { "WERR_DFS_NO_SUCH_VOL", WERR_DFS_NO_SUCH_VOL },
89 { "WERR_DFS_NO_SUCH_SHARE", WERR_DFS_NO_SUCH_SHARE },
90 { "WERR_DFS_NO_SUCH_SERVER", WERR_DFS_NO_SUCH_SERVER },
91 { "WERR_DFS_INTERNAL_ERROR", WERR_DFS_INTERNAL_ERROR },
92 { "WERR_DFS_CANT_CREATE_JUNCT", WERR_DFS_CANT_CREATE_JUNCT },
93 { "WERR_LOGON_FAILURE", WERR_LOGON_FAILURE },
94 { "WERR_INVALID_SECURITY_DESCRIPTOR", WERR_INVALID_SECURITY_DESCRIPTOR },
95 { "WERR_INVALID_DOMAIN_ROLE", WERR_INVALID_DOMAIN_ROLE },
96 { "WERR_UNKNOWN_REVISION", WERR_UNKNOWN_REVISION },
97 { "WERR_REVISION_MISMATCH", WERR_REVISION_MISMATCH },
98 { "WERR_INVALID_OWNER", WERR_INVALID_OWNER },
99 { "WERR_INVALID_COMPUTERNAME", WERR_INVALID_COMPUTERNAME },
100 { "WERR_INVALID_DOMAINNAME", WERR_INVALID_DOMAINNAME },
101 { "WERR_MACHINE_LOCKED", WERR_MACHINE_LOCKED },
102 { "WERR_DC_NOT_FOUND", WERR_DC_NOT_FOUND },
103 { "WERR_NO_LOGON_SERVERS", WERR_NO_LOGON_SERVERS },
104 { "WERR_NO_SUCH_LOGON_SESSION", WERR_NO_SUCH_LOGON_SESSION },
105 { "WERR_NO_SUCH_PRIVILEGE", WERR_NO_SUCH_PRIVILEGE },
106 { "WERR_PRIVILEGE_NOT_HELD", WERR_PRIVILEGE_NOT_HELD },
107 { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
108 { "WERR_NO_SUCH_DOMAIN", WERR_NO_SUCH_DOMAIN },
109 { "WERR_NO_SYSTEM_RESOURCES", WERR_NO_SYSTEM_RESOURCES },
110 { "WERR_DS_SERVICE_BUSY", WERR_DS_SERVICE_BUSY },
111 { "WERR_DS_SERVICE_UNAVAILABLE", WERR_DS_SERVICE_UNAVAILABLE },
112 { "WERR_DS_NO_SUCH_OBJECT", WERR_DS_NO_SUCH_OBJECT },
113 { "WERR_DS_OBJ_NOT_FOUND", WERR_DS_OBJ_NOT_FOUND },
114 { "WERR_DS_SCHEMA_NOT_LOADED", WERR_DS_SCHEMA_NOT_LOADED },
115 { "WERR_DS_SCHEMA_ALLOC_FAILED", WERR_DS_SCHEMA_ALLOC_FAILED },
116 { "WERR_DS_ATT_SCHEMA_REQ_SYNTAX", WERR_DS_ATT_SCHEMA_REQ_SYNTAX },
117 { "WERR_DS_DRA_SCHEMA_MISMATCH", WERR_DS_DRA_SCHEMA_MISMATCH },
118 { "WERR_DS_DRA_INVALID_PARAMETER", WERR_DS_DRA_INVALID_PARAMETER },
119 { "WERR_DS_DRA_BAD_DN", WERR_DS_DRA_BAD_DN },
120 { "WERR_DS_DRA_BAD_NC", WERR_DS_DRA_BAD_NC },
121 { "WERR_DS_DRA_INTERNAL_ERROR", WERR_DS_DRA_INTERNAL_ERROR },
122 { "WERR_DS_DRA_OUT_OF_MEM", WERR_DS_DRA_OUT_OF_MEM },
123 { "WERR_DS_SINGLE_VALUE_CONSTRAINT", WERR_DS_SINGLE_VALUE_CONSTRAINT },
124 { "WERR_DS_DRA_DB_ERROR", WERR_DS_DRA_DB_ERROR },
125 { "WERR_DS_DRA_NO_REPLICA", WERR_DS_DRA_NO_REPLICA },
126 { "WERR_DS_DRA_ACCESS_DENIED", WERR_DS_DRA_ACCESS_DENIED },
127 { "WERR_DS_DNS_LOOKUP_FAILURE", WERR_DS_DNS_LOOKUP_FAILURE },
128 { "WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX", WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX },
129 { "WERR_DS_NO_MSDS_INTID", WERR_DS_NO_MSDS_INTID },
130 { "WERR_DS_DUP_MSDS_INTID", WERR_DS_DUP_MSDS_INTID },
131 { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
132 { "WERR_PRINTQ_FULL", WERR_PRINTQ_FULL },
133 { "WERR_NO_SPOOL_SPACE", WERR_NO_SPOOL_SPACE },
134 { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE },
135 { "WERR_INVALID_FLAGS", WERR_INVALID_FLAGS },
136 { "WERR_NOT_FOUND", WERR_NOT_FOUND },
137 { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
138 { "WERR_NO_TRUST_SAM_ACCOUNT", WERR_NO_TRUST_SAM_ACCOUNT },
139 { "WERR_CLASS_NOT_REGISTERED", WERR_CLASS_NOT_REGISTERED },
140 { "WERR_NO_SHUTDOWN_IN_PROGRESS", WERR_NO_SHUTDOWN_IN_PROGRESS },
141 { "WERR_SHUTDOWN_ALREADY_IN_PROGRESS", WERR_SHUTDOWN_ALREADY_IN_PROGRESS },
142 { "WERR_SEC_E_ENCRYPT_FAILURE", WERR_SEC_E_ENCRYPT_FAILURE },
143 { "WERR_SEC_E_DECRYPT_FAILURE", WERR_SEC_E_DECRYPT_FAILURE },
144 { "WERR_SEC_E_ALGORITHM_MISMATCH", WERR_SEC_E_ALGORITHM_MISMATCH },
145 { "WERR_NOT_AUTHENTICATED", WERR_NOT_AUTHENTICATED },
146 { "WERR_CALL_NOT_IMPLEMENTED", WERR_CALL_NOT_IMPLEMENTED },
147 { "WERR_FRS_INVALID_SERVICE_PARAMETER", WERR_FRS_INVALID_SERVICE_PARAMETER },
148 { "WERR_FRS_SYSVOL_IS_BUSY", WERR_FRS_SYSVOL_IS_BUSY },
149 { "WERR_FRS_INSUFFICIENT_PRIV", WERR_FRS_INSUFFICIENT_PRIV },
150 { "WERR_RPC_E_REMOTE_DISABLED", WERR_RPC_E_REMOTE_DISABLED },
151 { "WERR_NOT_CONNECTED", WERR_NOT_CONNECTED },
152 { "WERR_NAME_NOT_FOUND", WERR_NAME_NOT_FOUND},
153 { "WERR_NONE_MAPPED", WERR_NONE_MAPPED },
154 { "WERR_INVALID_DOMAIN_STATE", WERR_INVALID_DOMAIN_STATE },
155 { "WERR_SPECIAL_ACCOUNT", WERR_SPECIAL_ACCOUNT },
156 { "WERR_ALIAS_EXISTS", WERR_ALIAS_EXISTS },
157 { "WERR_NO_SUCH_ALIAS", WERR_NO_SUCH_ALIAS },
158 { "WERR_MEMBER_IN_ALIAS", WERR_MEMBER_IN_ALIAS },
159 { "WERR_TIME_SKEW", WERR_TIME_SKEW },
160 { "WERR_IO_PENDING", WERR_IO_PENDING },
161 { "WERR_INVALID_SERVICE_CONTROL", WERR_INVALID_SERVICE_CONTROL },
162 { "WERR_SERVICE_ALREADY_RUNNING", WERR_SERVICE_ALREADY_RUNNING },
163 { "WERR_REG_CORRUPT", WERR_REG_CORRUPT },
164 { "WERR_REG_IO_FAILURE", WERR_REG_IO_FAILURE },
165 { "WERR_REG_FILE_INVALID", WERR_REG_FILE_INVALID },
166 { "WERR_NO_SUCH_SERVICE", WERR_NO_SUCH_SERVICE },
167 { "WERR_SERVICE_DISABLED", WERR_SERVICE_DISABLED },
168 { "WERR_SERVICE_NEVER_STARTED", WERR_SERVICE_NEVER_STARTED },
169 { "WERR_PASSWORD_MUST_CHANGE", WERR_PASSWORD_MUST_CHANGE },
170 { "WERR_ACCOUNT_LOCKED_OUT", WERR_ACCOUNT_LOCKED_OUT },
171 { NULL, W_ERROR(0) }
177 /* DFS errors */
179 /*****************************************************************************
180 returns a windows error message. not amazingly helpful, but better than a number.
181 *****************************************************************************/
182 const char *win_errstr(WERROR werror)
184 static char msg[40];
185 int idx = 0;
187 while (dos_errs[idx].dos_errstr != NULL) {
188 if (W_ERROR_V(dos_errs[idx].werror) ==
189 W_ERROR_V(werror))
190 return dos_errs[idx].dos_errstr;
191 idx++;
194 slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
196 return msg;
199 struct werror_str_struct {
200 WERROR werror;
201 const char *friendly_errstr;
204 const struct werror_str_struct dos_err_strs[] = {
205 { WERR_OK, "Success" },
206 { WERR_ACCESS_DENIED, "Access is denied" },
207 { WERR_INVALID_PARAM, "Invalid parameter" },
208 { WERR_NOT_SUPPORTED, "Not supported" },
209 { WERR_BAD_PASSWORD, "A bad password was supplied" },
210 { WERR_NOMEM, "Out of memory" },
211 { WERR_NO_LOGON_SERVERS, "No logon servers found" },
212 { WERR_NO_SUCH_LOGON_SESSION, "No such logon session" },
213 { WERR_DOMAIN_CONTROLLER_NOT_FOUND, "A domain controller could not be found" },
214 { WERR_DC_NOT_FOUND, "A domain controller could not be found" },
215 { WERR_SETUP_NOT_JOINED, "Join failed" },
216 { WERR_SETUP_ALREADY_JOINED, "Machine is already joined" },
217 { WERR_SETUP_DOMAIN_CONTROLLER, "Machine is a Domain Controller" },
218 { WERR_LOGON_FAILURE, "Invalid logon credentials" },
219 { WERR_USER_EXISTS, "User account already exists" },
220 { WERR_PASSWORD_MUST_CHANGE, "The password must be changed" },
221 { WERR_ACCOUNT_LOCKED_OUT, "Account locked out" },
222 { WERR_TIME_SKEW, "Time difference between client and server" },
223 { WERR_USER_ALREADY_EXISTS, "User already exists" },
224 { WERR_PASSWORD_RESTRICTION, "Password does not meet restrictions" },
225 { WERR_NONE_MAPPED, "Could not map names to SIDs" },
226 { WERR_NO_SUCH_USER, "No such User" },
227 { WERR_GROUP_EXISTS, "Group already exists" },
228 { WERR_DS_DRA_BAD_DN, "An invalid distinguished name was specified for this replication" },
229 { WERR_DS_DRA_BAD_NC, "An invalid naming context was specified for this replication operation" },
230 { WERR_WRONG_PASSWORD, "The current password is incorrect" }
235 /*****************************************************************************
236 Get friendly error string for WERRORs
237 *****************************************************************************/
239 const char *get_friendly_werror_msg(WERROR werror)
241 int i = 0;
243 for (i = 0; i < ARRAY_SIZE(dos_err_strs); i++) {
244 if (W_ERROR_V(dos_err_strs[i].werror) ==
245 W_ERROR_V(werror)) {
246 return dos_err_strs[i].friendly_errstr;
250 return win_errstr(werror);