errormap: Add wbcErr to NTSTATUS mappings
[samba.git] / libcli / util / doserr.c
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.
10  *  
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.
15  *  
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/>.
18  */
19
20 /* DOS error codes.  please read doserr.h */
21
22 #include "includes.h"
23
24 struct werror_code_struct {
25         const char *dos_errstr;
26         WERROR werror;
27 };
28
29 static const struct werror_code_struct dos_errs[] =
30 {
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_DRA_SOURCE_DISABLED", WERR_DS_DRA_SOURCE_DISABLED },
128         { "WERR_DS_DNS_LOOKUP_FAILURE", WERR_DS_DNS_LOOKUP_FAILURE },
129         { "WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX", WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX },
130         { "WERR_DS_NO_MSDS_INTID", WERR_DS_NO_MSDS_INTID },
131         { "WERR_DS_DUP_MSDS_INTID", WERR_DS_DUP_MSDS_INTID },
132         { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
133         { "WERR_PRINTQ_FULL", WERR_PRINTQ_FULL },
134         { "WERR_NO_SPOOL_SPACE", WERR_NO_SPOOL_SPACE },
135         { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE },
136         { "WERR_INVALID_FLAGS", WERR_INVALID_FLAGS },
137         { "WERR_DEVICE_NOT_CONNECTED", WERR_DEVICE_NOT_CONNECTED },
138         { "WERR_NOT_FOUND", WERR_NOT_FOUND },
139         { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
140         { "WERR_INVALID_USER_BUFFER", WERR_INVALID_USER_BUFFER },
141         { "WERR_NO_TRUST_SAM_ACCOUNT", WERR_NO_TRUST_SAM_ACCOUNT },
142         { "WERR_CLASS_NOT_REGISTERED", WERR_CLASS_NOT_REGISTERED },
143         { "WERR_NO_SHUTDOWN_IN_PROGRESS", WERR_NO_SHUTDOWN_IN_PROGRESS },
144         { "WERR_SHUTDOWN_ALREADY_IN_PROGRESS", WERR_SHUTDOWN_ALREADY_IN_PROGRESS },
145         { "WERR_SEC_E_ENCRYPT_FAILURE", WERR_SEC_E_ENCRYPT_FAILURE },
146         { "WERR_SEC_E_DECRYPT_FAILURE", WERR_SEC_E_DECRYPT_FAILURE },
147         { "WERR_SEC_E_ALGORITHM_MISMATCH", WERR_SEC_E_ALGORITHM_MISMATCH },
148         { "WERR_NOT_AUTHENTICATED", WERR_NOT_AUTHENTICATED },
149         { "WERR_CALL_NOT_IMPLEMENTED", WERR_CALL_NOT_IMPLEMENTED },
150         { "WERR_FRS_INVALID_SERVICE_PARAMETER", WERR_FRS_INVALID_SERVICE_PARAMETER },
151         { "WERR_FRS_SYSVOL_IS_BUSY", WERR_FRS_SYSVOL_IS_BUSY },
152         { "WERR_FRS_INSUFFICIENT_PRIV", WERR_FRS_INSUFFICIENT_PRIV },
153         { "WERR_RPC_E_REMOTE_DISABLED", WERR_RPC_E_REMOTE_DISABLED },
154         { "WERR_NOT_CONNECTED", WERR_NOT_CONNECTED },
155         { "WERR_NAME_NOT_FOUND", WERR_NAME_NOT_FOUND},
156         { "WERR_NONE_MAPPED", WERR_NONE_MAPPED },
157         { "WERR_INVALID_DOMAIN_STATE", WERR_INVALID_DOMAIN_STATE },
158         { "WERR_SPECIAL_ACCOUNT", WERR_SPECIAL_ACCOUNT },
159         { "WERR_ALIAS_EXISTS", WERR_ALIAS_EXISTS },
160         { "WERR_NO_SUCH_ALIAS", WERR_NO_SUCH_ALIAS },
161         { "WERR_MEMBER_IN_ALIAS", WERR_MEMBER_IN_ALIAS },
162         { "WERR_TIME_SKEW", WERR_TIME_SKEW },
163         { "WERR_IO_PENDING", WERR_IO_PENDING },
164         { "WERR_INVALID_SERVICE_CONTROL", WERR_INVALID_SERVICE_CONTROL },
165         { "WERR_SERVICE_ALREADY_RUNNING", WERR_SERVICE_ALREADY_RUNNING },
166         { "WERR_REG_CORRUPT", WERR_REG_CORRUPT },
167         { "WERR_REG_IO_FAILURE", WERR_REG_IO_FAILURE },
168         { "WERR_REG_FILE_INVALID", WERR_REG_FILE_INVALID },
169         { "WERR_NO_SUCH_SERVICE", WERR_NO_SUCH_SERVICE },
170         { "WERR_SERVICE_DISABLED", WERR_SERVICE_DISABLED },
171         { "WERR_SERVICE_MARKED_FOR_DELETE", WERR_SERVICE_MARKED_FOR_DELETE },
172         { "WERR_SERVICE_EXISTS", WERR_SERVICE_EXISTS },
173         { "WERR_SERVICE_NEVER_STARTED", WERR_SERVICE_NEVER_STARTED },
174         { "WERR_DUPLICATE_SERVICE_NAME", WERR_DUPLICATE_SERVICE_NAME },
175         { "WERR_PASSWORD_MUST_CHANGE", WERR_PASSWORD_MUST_CHANGE },
176         { "WERR_ACCOUNT_LOCKED_OUT", WERR_ACCOUNT_LOCKED_OUT },
177         { "WERR_UNKNOWN_PRINT_MONITOR", WERR_UNKNOWN_PRINT_MONITOR },
178         { NULL, W_ERROR(0) }
179 };
180
181
182
183
184 /* DFS errors */
185
186 /*****************************************************************************
187  returns a windows error message.  not amazingly helpful, but better than a number.
188  *****************************************************************************/
189 const char *win_errstr(WERROR werror)
190 {
191         static char msg[40];
192         int idx = 0;
193
194         while (dos_errs[idx].dos_errstr != NULL) {
195                 if (W_ERROR_V(dos_errs[idx].werror) == 
196                     W_ERROR_V(werror))
197                         return dos_errs[idx].dos_errstr;
198                 idx++;
199         }
200
201         slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
202
203         return msg;
204 }
205
206 struct werror_str_struct {
207         WERROR werror;
208         const char *friendly_errstr;
209 };
210
211 const struct werror_str_struct dos_err_strs[] = {
212         { WERR_OK, "Success" },
213         { WERR_ACCESS_DENIED, "Access is denied" },
214         { WERR_INVALID_PARAM, "Invalid parameter" },
215         { WERR_NOT_SUPPORTED, "Not supported" },
216         { WERR_BAD_PASSWORD, "A bad password was supplied" },
217         { WERR_NOMEM, "Out of memory" },
218         { WERR_NO_LOGON_SERVERS, "No logon servers found" },
219         { WERR_NO_SUCH_LOGON_SESSION, "No such logon session" },
220         { WERR_DOMAIN_CONTROLLER_NOT_FOUND, "A domain controller could not be found" },
221         { WERR_DC_NOT_FOUND, "A domain controller could not be found" },
222         { WERR_SETUP_NOT_JOINED, "Join failed" },
223         { WERR_SETUP_ALREADY_JOINED, "Machine is already joined" },
224         { WERR_SETUP_DOMAIN_CONTROLLER, "Machine is a Domain Controller" },
225         { WERR_LOGON_FAILURE, "Invalid logon credentials" },
226         { WERR_USER_EXISTS, "User account already exists" },
227         { WERR_PASSWORD_MUST_CHANGE, "The password must be changed" },
228         { WERR_ACCOUNT_LOCKED_OUT, "Account locked out" },
229         { WERR_TIME_SKEW, "Time difference between client and server" },
230         { WERR_USER_ALREADY_EXISTS, "User already exists" },
231         { WERR_PASSWORD_RESTRICTION, "Password does not meet restrictions" },
232         { WERR_NONE_MAPPED, "Could not map names to SIDs" },
233         { WERR_NO_SUCH_USER, "No such User" },
234         { WERR_GROUP_EXISTS, "Group already exists" },
235         { WERR_DS_DRA_BAD_DN, "An invalid distinguished name was specified for this replication" },
236         { WERR_DS_DRA_BAD_NC, "An invalid naming context was specified for this replication operation" },
237         { WERR_WRONG_PASSWORD, "The current password is incorrect" }
238 };
239
240
241
242 /*****************************************************************************
243  Get friendly error string for WERRORs
244  *****************************************************************************/
245
246 const char *get_friendly_werror_msg(WERROR werror)
247 {
248         int i = 0;
249
250         for (i = 0; i < ARRAY_SIZE(dos_err_strs); i++) {
251                 if (W_ERROR_V(dos_err_strs[i].werror) ==
252                     W_ERROR_V(werror)) {
253                         return dos_err_strs[i].friendly_errstr;
254                 }
255         }
256
257         return win_errstr(werror);
258 }