Merge branch 'master' of /home/tridge/samba/git/combined
[Samba/aatanasov.git] / libcli / util / doserr.c
blob6af197284f97e3db1d380660353f593ae56ab3f8
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_UNKNOWN_PRINTPROCESSOR", WERR_UNKNOWN_PRINTPROCESSOR },
56 { "WERR_INVALID_SEPARATOR_FILE", WERR_INVALID_SEPARATOR_FILE },
57 { "WERR_INVALID_PRIORITY", WERR_INVALID_PRIORITY },
58 { "WERR_UNKNOWN_PORT", WERR_UNKNOWN_PORT },
59 { "WERR_INVALID_PRINTER_NAME", WERR_INVALID_PRINTER_NAME },
60 { "WERR_PRINTER_ALREADY_EXISTS", WERR_PRINTER_ALREADY_EXISTS },
61 { "WERR_INVALID_DATATYPE", WERR_INVALID_DATATYPE },
62 { "WERR_INVALID_ENVIRONMENT", WERR_INVALID_ENVIRONMENT },
63 { "WERR_INVALID_FORM_NAME", WERR_INVALID_FORM_NAME },
64 { "WERR_INVALID_FORM_SIZE", WERR_INVALID_FORM_SIZE },
65 { "WERR_ALREADY_SHARED", WERR_ALREADY_SHARED },
66 { "WERR_BUF_TOO_SMALL", WERR_BUF_TOO_SMALL },
67 { "WERR_JOB_NOT_FOUND", WERR_JOB_NOT_FOUND },
68 { "WERR_DEST_NOT_FOUND", WERR_DEST_NOT_FOUND },
69 { "WERR_GROUP_NOT_FOUND", WERR_GROUP_NOT_FOUND },
70 { "WERR_USER_NOT_FOUND", WERR_USER_NOT_FOUND },
71 { "WERR_NOT_LOCAL_DOMAIN", WERR_NOT_LOCAL_DOMAIN },
72 { "WERR_DOMAIN_CONTROLLER_NOT_FOUND", WERR_DOMAIN_CONTROLLER_NOT_FOUND },
73 { "WERR_TIME_DIFF_AT_DC", WERR_TIME_DIFF_AT_DC },
74 { "WERR_SETUP_NOT_JOINED", WERR_SETUP_NOT_JOINED },
75 { "WERR_SETUP_ALREADY_JOINED", WERR_SETUP_ALREADY_JOINED },
76 { "WERR_SETUP_DOMAIN_CONTROLLER", WERR_SETUP_DOMAIN_CONTROLLER },
77 { "WERR_DEVICE_NOT_AVAILABLE", WERR_DEVICE_NOT_AVAILABLE },
78 { "WERR_DEFAULT_JOIN_REQUIRED", WERR_DEFAULT_JOIN_REQUIRED },
79 { "WERR_USER_EXISTS", WERR_USER_EXISTS },
80 { "WERR_REVISION_MISMATCH", WERR_REVISION_MISMATCH },
81 { "WERR_NO_LOGON_SERVERS", WERR_NO_LOGON_SERVERS },
82 { "WERR_NO_SUCH_LOGON_SESSION", WERR_NO_SUCH_LOGON_SESSION },
83 { "WERR_USER_ALREADY_EXISTS", WERR_USER_ALREADY_EXISTS },
84 { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
85 { "WERR_GROUP_EXISTS", WERR_GROUP_EXISTS },
86 { "WERR_NO_SUCH_GROUP", WERR_NO_SUCH_GROUP },
87 { "WERR_MEMBER_IN_GROUP", WERR_MEMBER_IN_GROUP },
88 { "WERR_USER_NOT_IN_GROUP", WERR_USER_NOT_IN_GROUP },
89 { "WERR_PRINTER_DRIVER_IN_USE", WERR_PRINTER_DRIVER_IN_USE },
90 { "WERR_STATUS_MORE_ENTRIES", WERR_STATUS_MORE_ENTRIES },
91 { "WERR_NET_NAME_NOT_FOUND", WERR_NET_NAME_NOT_FOUND },
92 { "WERR_DEVICE_NOT_SHARED", WERR_DEVICE_NOT_SHARED },
93 { "WERR_DFS_NO_SUCH_VOL", WERR_DFS_NO_SUCH_VOL },
94 { "WERR_DFS_NO_SUCH_SHARE", WERR_DFS_NO_SUCH_SHARE },
95 { "WERR_DFS_NO_SUCH_SERVER", WERR_DFS_NO_SUCH_SERVER },
96 { "WERR_DFS_INTERNAL_ERROR", WERR_DFS_INTERNAL_ERROR },
97 { "WERR_DFS_CANT_CREATE_JUNCT", WERR_DFS_CANT_CREATE_JUNCT },
98 { "WERR_LOGON_FAILURE", WERR_LOGON_FAILURE },
99 { "WERR_INVALID_SECURITY_DESCRIPTOR", WERR_INVALID_SECURITY_DESCRIPTOR },
100 { "WERR_INVALID_DOMAIN_ROLE", WERR_INVALID_DOMAIN_ROLE },
101 { "WERR_UNKNOWN_REVISION", WERR_UNKNOWN_REVISION },
102 { "WERR_REVISION_MISMATCH", WERR_REVISION_MISMATCH },
103 { "WERR_INVALID_OWNER", WERR_INVALID_OWNER },
104 { "WERR_INVALID_PRIMARY_GROUP", WERR_INVALID_PRIMARY_GROUP },
105 { "WERR_INVALID_COMPUTERNAME", WERR_INVALID_COMPUTERNAME },
106 { "WERR_INVALID_DOMAINNAME", WERR_INVALID_DOMAINNAME },
107 { "WERR_MACHINE_LOCKED", WERR_MACHINE_LOCKED },
108 { "WERR_DC_NOT_FOUND", WERR_DC_NOT_FOUND },
109 { "WERR_NO_LOGON_SERVERS", WERR_NO_LOGON_SERVERS },
110 { "WERR_NO_SUCH_LOGON_SESSION", WERR_NO_SUCH_LOGON_SESSION },
111 { "WERR_NO_SUCH_PRIVILEGE", WERR_NO_SUCH_PRIVILEGE },
112 { "WERR_PRIVILEGE_NOT_HELD", WERR_PRIVILEGE_NOT_HELD },
113 { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
114 { "WERR_NO_SUCH_DOMAIN", WERR_NO_SUCH_DOMAIN },
115 { "WERR_NO_SYSTEM_RESOURCES", WERR_NO_SYSTEM_RESOURCES },
116 { "WERR_DS_NO_ATTRIBUTE_OR_VALUE", WERR_DS_NO_ATTRIBUTE_OR_VALUE },
117 { "WERR_DS_INVALID_ATTRIBUTE_SYNTAX", WERR_DS_INVALID_ATTRIBUTE_SYNTAX },
118 { "WERR_DS_ATTRIBUTE_TYPE_UNDEFINED", WERR_DS_ATTRIBUTE_TYPE_UNDEFINED },
119 { "WERR_DS_ATTRIBUTE_OR_VALUE_EXISTS", WERR_DS_ATTRIBUTE_OR_VALUE_EXISTS },
120 { "WERR_DS_BUSY", WERR_DS_BUSY },
121 { "WERR_DS_UNAVAILABLE", WERR_DS_UNAVAILABLE },
122 { "WERR_DS_OBJ_CLASS_VIOLATION", WERR_DS_OBJ_CLASS_VIOLATION },
123 { "WERR_DS_CANT_ON_NON_LEAF", WERR_DS_CANT_ON_NON_LEAF },
124 { "WERR_DS_CANT_ON_RDN", WERR_DS_CANT_ON_RDN },
125 { "WERR_DS_CANT_MOD_OBJ_CLASS", WERR_DS_CANT_MOD_OBJ_CLASS },
126 { "WERR_DS_OPERATIONS_ERROR", WERR_DS_OPERATIONS_ERROR },
127 { "WERR_DS_PROTOCOL_ERROR", WERR_DS_PROTOCOL_ERROR },
128 { "WERR_DS_TIMELIMIT_EXCEEEDED", WERR_DS_TIMELIMIT_EXCEEDED },
129 { "WERR_DS_SIZE_LIMIT_EXCEEDED", WERR_DS_SIZE_LIMIT_EXCEEDED },
130 { "WERR_DS_ADMIN_LIMIT_EXCEEEDED", WERR_DS_ADMIN_LIMIT_EXCEEDED },
131 { "WERR_DS_COMPARE_FALSE", WERR_DS_COMPARE_FALSE },
132 { "WERR_DS_COMPARE_TRUE", WERR_DS_COMPARE_TRUE },
133 { "WERR_DS_AUTH_METHOD_NOT_SUPPORTED", WERR_DS_AUTH_METHOD_NOT_SUPPORTED },
134 { "WERR_DS_STRONG_AUTH_REQUIRED", WERR_DS_STRONG_AUTH_REQUIRED },
135 { "WERR_DS_INAPPROPRIATE_AUTH", WERR_DS_INAPPROPRIATE_AUTH },
136 { "WERR_DS_REFERRAL", WERR_DS_REFERRAL },
137 { "WERR_DS_UNAVAILABLE_CRIT_EXTENSION", WERR_DS_UNAVAILABLE_CRIT_EXTENSION },
138 { "WERR_DS_CONFIDENTIALITY_REQUIRED", WERR_DS_CONFIDENTIALITY_REQUIRED },
139 { "WERR_DS_INAPPROPRIATE_MATCHING", WERR_DS_INAPPROPRIATE_MATCHING },
140 { "WERR_DS_CONSTRAINT_VIOLATION", WERR_DS_CONSTRAINT_VIOLATION },
141 { "WERR_DS_NO_SUCH_OBJECT", WERR_DS_NO_SUCH_OBJECT },
142 { "WERR_DS_ALIAS_PROBLEM", WERR_DS_ALIAS_PROBLEM },
143 { "WERR_DS_INVALID_DN_SYNTAX", WERR_DS_INVALID_DN_SYNTAX },
144 { "WERR_DS_ALIAS_DEREF_PROBLEM", WERR_DS_ALIAS_DEREF_PROBLEM },
145 { "WERR_DS_UNWILLING_TO_PERFORM", WERR_DS_UNWILLING_TO_PERFORM },
146 { "WERR_DS_LOOP_DETECT", WERR_DS_LOOP_DETECT },
147 { "WERR_DS_NAMING_VIOLATION", WERR_DS_NAMING_VIOLATION },
148 { "WERR_DS_AFFECTS_MULTIPLE_DSAS", WERR_DS_AFFECTS_MULTIPLE_DSAS },
149 { "WERR_DS_OBJ_STRING_NAME_EXISTS", WERR_DS_OBJ_STRING_NAME_EXISTS },
150 { "WERR_DS_OBJ_NOT_FOUND", WERR_DS_OBJ_NOT_FOUND },
151 { "WERR_DS_GENERIC_ERROR", WERR_DS_GENERIC_ERROR },
152 { "WERR_DS_INSUFF_ACCESS_RIGHTS", WERR_DS_INSUFF_ACCESS_RIGHTS },
153 { "WERR_DS_SCHEMA_NOT_LOADED", WERR_DS_SCHEMA_NOT_LOADED },
154 { "WERR_DS_SCHEMA_ALLOC_FAILED", WERR_DS_SCHEMA_ALLOC_FAILED },
155 { "WERR_DS_ATT_SCHEMA_REQ_SYNTAX", WERR_DS_ATT_SCHEMA_REQ_SYNTAX },
156 { "WERR_DS_DRA_SCHEMA_MISMATCH", WERR_DS_DRA_SCHEMA_MISMATCH },
157 { "WERR_DS_DRA_INVALID_PARAMETER", WERR_DS_DRA_INVALID_PARAMETER },
158 { "WERR_DS_DRA_BAD_DN", WERR_DS_DRA_BAD_DN },
159 { "WERR_DS_DRA_BAD_NC", WERR_DS_DRA_BAD_NC },
160 { "WERR_DS_DRA_INTERNAL_ERROR", WERR_DS_DRA_INTERNAL_ERROR },
161 { "WERR_DS_DRA_OUT_OF_MEM", WERR_DS_DRA_OUT_OF_MEM },
162 { "WERR_DS_SINGLE_VALUE_CONSTRAINT", WERR_DS_SINGLE_VALUE_CONSTRAINT },
163 { "WERR_DS_DRA_DB_ERROR", WERR_DS_DRA_DB_ERROR },
164 { "WERR_DS_DRA_NO_REPLICA", WERR_DS_DRA_NO_REPLICA },
165 { "WERR_DS_DRA_ACCESS_DENIED", WERR_DS_DRA_ACCESS_DENIED },
166 { "WERR_DS_DRA_SOURCE_DISABLED", WERR_DS_DRA_SOURCE_DISABLED },
167 { "WERR_DS_DNS_LOOKUP_FAILURE", WERR_DS_DNS_LOOKUP_FAILURE },
168 { "WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX", WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX },
169 { "WERR_DS_NO_MSDS_INTID", WERR_DS_NO_MSDS_INTID },
170 { "WERR_DS_DUP_MSDS_INTID", WERR_DS_DUP_MSDS_INTID },
171 { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
172 { "WERR_PRINTQ_FULL", WERR_PRINTQ_FULL },
173 { "WERR_NO_SPOOL_SPACE", WERR_NO_SPOOL_SPACE },
174 { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE },
175 { "WERR_INVALID_FLAGS", WERR_INVALID_FLAGS },
176 { "WERR_DEVICE_NOT_CONNECTED", WERR_DEVICE_NOT_CONNECTED },
177 { "WERR_NOT_FOUND", WERR_NOT_FOUND },
178 { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
179 { "WERR_INVALID_USER_BUFFER", WERR_INVALID_USER_BUFFER },
180 { "WERR_NO_TRUST_SAM_ACCOUNT", WERR_NO_TRUST_SAM_ACCOUNT },
181 { "WERR_INVALID_PRINTER_COMMAND", WERR_INVALID_PRINTER_COMMAND },
182 { "WERR_CLASS_NOT_REGISTERED", WERR_CLASS_NOT_REGISTERED },
183 { "WERR_NO_SHUTDOWN_IN_PROGRESS", WERR_NO_SHUTDOWN_IN_PROGRESS },
184 { "WERR_SHUTDOWN_ALREADY_IN_PROGRESS", WERR_SHUTDOWN_ALREADY_IN_PROGRESS },
185 { "WERR_SEC_E_ENCRYPT_FAILURE", WERR_SEC_E_ENCRYPT_FAILURE },
186 { "WERR_SEC_E_DECRYPT_FAILURE", WERR_SEC_E_DECRYPT_FAILURE },
187 { "WERR_SEC_E_ALGORITHM_MISMATCH", WERR_SEC_E_ALGORITHM_MISMATCH },
188 { "WERR_NOT_AUTHENTICATED", WERR_NOT_AUTHENTICATED },
189 { "WERR_CALL_NOT_IMPLEMENTED", WERR_CALL_NOT_IMPLEMENTED },
190 { "WERR_FRS_INVALID_SERVICE_PARAMETER", WERR_FRS_INVALID_SERVICE_PARAMETER },
191 { "WERR_FRS_SYSVOL_IS_BUSY", WERR_FRS_SYSVOL_IS_BUSY },
192 { "WERR_FRS_INSUFFICIENT_PRIV", WERR_FRS_INSUFFICIENT_PRIV },
193 { "WERR_RPC_E_REMOTE_DISABLED", WERR_RPC_E_REMOTE_DISABLED },
194 { "WERR_NOT_CONNECTED", WERR_NOT_CONNECTED },
195 { "WERR_NAME_NOT_FOUND", WERR_NAME_NOT_FOUND},
196 { "WERR_NONE_MAPPED", WERR_NONE_MAPPED },
197 { "WERR_INVALID_DOMAIN_STATE", WERR_INVALID_DOMAIN_STATE },
198 { "WERR_SPECIAL_ACCOUNT", WERR_SPECIAL_ACCOUNT },
199 { "WERR_ALIAS_EXISTS", WERR_ALIAS_EXISTS },
200 { "WERR_NO_SUCH_ALIAS", WERR_NO_SUCH_ALIAS },
201 { "WERR_MEMBER_IN_ALIAS", WERR_MEMBER_IN_ALIAS },
202 { "WERR_TIME_SKEW", WERR_TIME_SKEW },
203 { "WERR_IO_PENDING", WERR_IO_PENDING },
204 { "WERR_INVALID_SERVICE_CONTROL", WERR_INVALID_SERVICE_CONTROL },
205 { "WERR_SERVICE_ALREADY_RUNNING", WERR_SERVICE_ALREADY_RUNNING },
206 { "WERR_REG_CORRUPT", WERR_REG_CORRUPT },
207 { "WERR_REG_IO_FAILURE", WERR_REG_IO_FAILURE },
208 { "WERR_REG_FILE_INVALID", WERR_REG_FILE_INVALID },
209 { "WERR_NO_SUCH_SERVICE", WERR_NO_SUCH_SERVICE },
210 { "WERR_SERVICE_DISABLED", WERR_SERVICE_DISABLED },
211 { "WERR_SERVICE_MARKED_FOR_DELETE", WERR_SERVICE_MARKED_FOR_DELETE },
212 { "WERR_SERVICE_EXISTS", WERR_SERVICE_EXISTS },
213 { "WERR_SERVICE_NEVER_STARTED", WERR_SERVICE_NEVER_STARTED },
214 { "WERR_DUPLICATE_SERVICE_NAME", WERR_DUPLICATE_SERVICE_NAME },
215 { "WERR_PASSWORD_MUST_CHANGE", WERR_PASSWORD_MUST_CHANGE },
216 { "WERR_ACCOUNT_LOCKED_OUT", WERR_ACCOUNT_LOCKED_OUT },
217 { "WERR_UNKNOWN_PRINT_MONITOR", WERR_UNKNOWN_PRINT_MONITOR },
218 { "WERR_PASSWORD_RESTRICTION", WERR_PASSWORD_RESTRICTION },
219 { "WERR_WRONG_PASSWORD", WERR_WRONG_PASSWORD },
220 { NULL, W_ERROR(0) }
226 /* DFS errors */
228 /*****************************************************************************
229 returns a windows error message. not amazingly helpful, but better than a number.
230 *****************************************************************************/
231 const char *win_errstr(WERROR werror)
233 static char msg[40];
234 int idx = 0;
236 while (dos_errs[idx].dos_errstr != NULL) {
237 if (W_ERROR_V(dos_errs[idx].werror) ==
238 W_ERROR_V(werror))
239 return dos_errs[idx].dos_errstr;
240 idx++;
243 slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
245 return msg;
248 struct werror_str_struct {
249 WERROR werror;
250 const char *friendly_errstr;
253 const struct werror_str_struct dos_err_strs[] = {
254 { WERR_OK, "Success" },
255 { WERR_ACCESS_DENIED, "Access is denied" },
256 { WERR_INVALID_PARAM, "Invalid parameter" },
257 { WERR_NOT_SUPPORTED, "Not supported" },
258 { WERR_BAD_PASSWORD, "A bad password was supplied" },
259 { WERR_NOMEM, "Out of memory" },
260 { WERR_NO_LOGON_SERVERS, "No logon servers found" },
261 { WERR_NO_SUCH_LOGON_SESSION, "No such logon session" },
262 { WERR_DOMAIN_CONTROLLER_NOT_FOUND, "A domain controller could not be found" },
263 { WERR_DC_NOT_FOUND, "A domain controller could not be found" },
264 { WERR_SETUP_NOT_JOINED, "Join failed" },
265 { WERR_SETUP_ALREADY_JOINED, "Machine is already joined" },
266 { WERR_SETUP_DOMAIN_CONTROLLER, "Machine is a Domain Controller" },
267 { WERR_LOGON_FAILURE, "Invalid logon credentials" },
268 { WERR_USER_EXISTS, "User account already exists" },
269 { WERR_PASSWORD_MUST_CHANGE, "The password must be changed" },
270 { WERR_ACCOUNT_LOCKED_OUT, "Account locked out" },
271 { WERR_TIME_SKEW, "Time difference between client and server" },
272 { WERR_USER_ALREADY_EXISTS, "User already exists" },
273 { WERR_PASSWORD_RESTRICTION, "Password does not meet restrictions" },
274 { WERR_NONE_MAPPED, "Could not map names to SIDs" },
275 { WERR_NO_SUCH_USER, "No such User" },
276 { WERR_GROUP_EXISTS, "Group already exists" },
277 { WERR_NO_SUCH_GROUP, "No such Group" },
278 { WERR_INVALID_PRIMARY_GROUP, "The account's primary group is invalid" },
279 { WERR_DS_DRA_BAD_DN, "An invalid distinguished name was specified for this replication" },
280 { WERR_DS_DRA_BAD_NC, "An invalid naming context was specified for this replication operation" },
281 { WERR_WRONG_PASSWORD, "The current password is incorrect" }
286 /*****************************************************************************
287 Get friendly error string for WERRORs
288 *****************************************************************************/
290 const char *get_friendly_werror_msg(WERROR werror)
292 int i = 0;
294 for (i = 0; i < ARRAY_SIZE(dos_err_strs); i++) {
295 if (W_ERROR_V(dos_err_strs[i].werror) ==
296 W_ERROR_V(werror)) {
297 return dos_err_strs[i].friendly_errstr;
301 return win_errstr(werror);