Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : * error mapping functions
4 : * Copyright (C) Andrew Tridgell 2001
5 : * Copyright (C) Andrew Bartlett 2001
6 : * Copyright (C) Tim Potter 2000
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 : /* Mapping between Unix, and NT error numbers */
25 :
26 : static const struct {
27 : int unix_error;
28 : NTSTATUS nt_error;
29 : } unix_nt_errmap[] = {
30 : { EAGAIN, STATUS_MORE_ENTRIES },
31 : { EINTR, STATUS_MORE_ENTRIES },
32 : { ENOBUFS, STATUS_MORE_ENTRIES },
33 : #ifdef EWOULDBLOCK
34 : { EWOULDBLOCK, STATUS_MORE_ENTRIES },
35 : #endif
36 : { EINPROGRESS, NT_STATUS_MORE_PROCESSING_REQUIRED },
37 : { EPERM, NT_STATUS_ACCESS_DENIED },
38 : { EACCES, NT_STATUS_ACCESS_DENIED },
39 : { ENOENT, NT_STATUS_OBJECT_NAME_NOT_FOUND },
40 : { ENOTDIR, NT_STATUS_NOT_A_DIRECTORY },
41 : { EIO, NT_STATUS_IO_DEVICE_ERROR },
42 : { EBADF, NT_STATUS_INVALID_HANDLE },
43 : { EINVAL, NT_STATUS_INVALID_PARAMETER },
44 : { EEXIST, NT_STATUS_OBJECT_NAME_COLLISION},
45 : { ENFILE, NT_STATUS_TOO_MANY_OPENED_FILES },
46 : { EMFILE, NT_STATUS_TOO_MANY_OPENED_FILES },
47 : { ENOSPC, NT_STATUS_DISK_FULL },
48 : { ENOTSOCK, NT_STATUS_INVALID_HANDLE },
49 : { EFAULT, NT_STATUS_INVALID_PARAMETER },
50 : { EMSGSIZE, NT_STATUS_INVALID_BUFFER_SIZE },
51 : { ENOMEM, NT_STATUS_NO_MEMORY },
52 : { EISDIR, NT_STATUS_FILE_IS_A_DIRECTORY},
53 : #ifdef EPIPE
54 : { EPIPE, NT_STATUS_CONNECTION_DISCONNECTED },
55 : #endif
56 : { EBUSY, NT_STATUS_SHARING_VIOLATION },
57 : { ENOSYS, NT_STATUS_INVALID_SYSTEM_SERVICE },
58 : #ifdef EOPNOTSUPP
59 : { EOPNOTSUPP, NT_STATUS_NOT_SUPPORTED},
60 : #endif
61 : { EMLINK, NT_STATUS_TOO_MANY_LINKS },
62 : { ENOSYS, NT_STATUS_NOT_SUPPORTED },
63 : #ifdef ELOOP
64 : { ELOOP, NT_STATUS_OBJECT_PATH_NOT_FOUND },
65 : #endif
66 : #ifdef ENODATA
67 : { ENODATA, NT_STATUS_NOT_FOUND },
68 : #endif
69 : #ifdef EFTYPE
70 : { EFTYPE, NT_STATUS_OBJECT_PATH_NOT_FOUND },
71 : #endif
72 : #ifdef EDQUOT
73 : { EDQUOT, NT_STATUS_DISK_FULL }, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */
74 : #endif
75 : #ifdef ENOTEMPTY
76 : { ENOTEMPTY, NT_STATUS_DIRECTORY_NOT_EMPTY },
77 : #endif
78 : #ifdef EXDEV
79 : { EXDEV, NT_STATUS_NOT_SAME_DEVICE },
80 : #endif
81 : #ifdef EROFS
82 : { EROFS, NT_STATUS_MEDIA_WRITE_PROTECTED },
83 : #endif
84 : #ifdef ENAMETOOLONG
85 : { ENAMETOOLONG, NT_STATUS_NAME_TOO_LONG },
86 : #endif
87 : #ifdef EFBIG
88 : { EFBIG, NT_STATUS_DISK_FULL },
89 : #endif
90 : #ifdef EADDRINUSE
91 : { EADDRINUSE, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED},
92 : #endif
93 : #ifdef ENETUNREACH
94 : { ENETUNREACH, NT_STATUS_NETWORK_UNREACHABLE},
95 : #endif
96 : #ifdef EHOSTUNREACH
97 : { EHOSTUNREACH, NT_STATUS_HOST_UNREACHABLE},
98 : #endif
99 : #ifdef ECONNREFUSED
100 : { ECONNREFUSED, NT_STATUS_CONNECTION_REFUSED},
101 : #endif
102 : #ifdef EADDRNOTAVAIL
103 : { EADDRNOTAVAIL,NT_STATUS_ADDRESS_NOT_ASSOCIATED },
104 : #endif
105 : #ifdef ETIMEDOUT
106 : { ETIMEDOUT, NT_STATUS_IO_TIMEOUT},
107 : #endif
108 : #ifdef ESOCKTNOSUPPORT
109 : { ESOCKTNOSUPPORT,NT_STATUS_INVALID_PARAMETER_MIX },
110 : #endif
111 : #ifdef EAFNOSUPPORT
112 : { EAFNOSUPPORT, NT_STATUS_INVALID_PARAMETER_MIX },
113 : #endif
114 : #ifdef ECONNABORTED
115 : { ECONNABORTED, NT_STATUS_CONNECTION_ABORTED},
116 : #endif
117 : #ifdef ECONNRESET
118 : { ECONNRESET, NT_STATUS_CONNECTION_RESET},
119 : #endif
120 : #ifdef ENOPROTOOPT
121 : { ENOPROTOOPT, NT_STATUS_INVALID_PARAMETER_MIX },
122 : #endif
123 : #ifdef ENODEV
124 : { ENODEV, NT_STATUS_NO_SUCH_DEVICE },
125 : #endif
126 : #ifdef ENOATTR
127 : { ENOATTR, NT_STATUS_NOT_FOUND },
128 : #endif
129 : #ifdef ECANCELED
130 : { ECANCELED, NT_STATUS_CANCELLED},
131 : #endif
132 : #ifdef ENOTSUP
133 : { ENOTSUP, NT_STATUS_NOT_SUPPORTED},
134 : #endif
135 :
136 : { 0, NT_STATUS_UNSUCCESSFUL }
137 : };
138 :
139 :
140 : /*********************************************************************
141 : Map an NT error code from a Unix error code.
142 : *********************************************************************/
143 19416218 : NTSTATUS map_nt_error_from_unix_common(int unix_error)
144 : {
145 25393 : size_t i;
146 :
147 : /* Look through list */
148 636843829 : for (i=0;i<ARRAY_SIZE(unix_nt_errmap);i++) {
149 636843829 : if (unix_nt_errmap[i].unix_error == unix_error) {
150 19416218 : return unix_nt_errmap[i].nt_error;
151 : }
152 : }
153 :
154 : /* Default return */
155 0 : return NT_STATUS_UNSUCCESSFUL;
156 : }
157 :
158 : /* Return a UNIX errno from a NT status code */
159 : static const struct {
160 : NTSTATUS status;
161 : int error;
162 : } nt_errno_map[] = {
163 : {NT_STATUS_ACCESS_VIOLATION, EACCES},
164 : {NT_STATUS_INVALID_HANDLE, EBADF},
165 : {NT_STATUS_ACCESS_DENIED, EACCES},
166 : {NT_STATUS_OBJECT_NAME_NOT_FOUND, ENOENT},
167 : {NT_STATUS_OBJECT_PATH_NOT_FOUND, ENOENT},
168 : {NT_STATUS_SHARING_VIOLATION, EBUSY},
169 : {NT_STATUS_OBJECT_PATH_INVALID, ENOTDIR},
170 : {NT_STATUS_OBJECT_NAME_COLLISION, EEXIST},
171 : {NT_STATUS_PATH_NOT_COVERED, ENOENT},
172 : {NT_STATUS_UNSUCCESSFUL, EINVAL},
173 : {NT_STATUS_NOT_IMPLEMENTED, ENOSYS},
174 : {NT_STATUS_IN_PAGE_ERROR, EFAULT},
175 : {NT_STATUS_BAD_NETWORK_NAME, ENOENT},
176 : #ifdef EDQUOT
177 : {NT_STATUS_PAGEFILE_QUOTA, EDQUOT},
178 : {NT_STATUS_QUOTA_EXCEEDED, EDQUOT},
179 : {NT_STATUS_REGISTRY_QUOTA_LIMIT, EDQUOT},
180 : {NT_STATUS_LICENSE_QUOTA_EXCEEDED, EDQUOT},
181 : #endif
182 : #ifdef ETIME
183 : {NT_STATUS_TIMER_NOT_CANCELED, ETIME},
184 : #endif
185 : {NT_STATUS_INVALID_PARAMETER, EINVAL},
186 : {NT_STATUS_NO_SUCH_DEVICE, ENODEV},
187 : {NT_STATUS_NO_SUCH_FILE, ENOENT},
188 : #ifdef ENODATA
189 : {NT_STATUS_END_OF_FILE, ENODATA},
190 : #endif
191 : #ifdef ENOMEDIUM
192 : {NT_STATUS_NO_MEDIA_IN_DEVICE, ENOMEDIUM},
193 : {NT_STATUS_NO_MEDIA, ENOMEDIUM},
194 : #endif
195 : {NT_STATUS_NONEXISTENT_SECTOR, ESPIPE},
196 : {NT_STATUS_NO_MEMORY, ENOMEM},
197 : {NT_STATUS_CONFLICTING_ADDRESSES, EADDRINUSE},
198 : {NT_STATUS_NOT_MAPPED_VIEW, EINVAL},
199 : {NT_STATUS_UNABLE_TO_FREE_VM, EADDRINUSE},
200 : {NT_STATUS_ACCESS_DENIED, EACCES},
201 : {NT_STATUS_BUFFER_TOO_SMALL, ENOBUFS},
202 : {NT_STATUS_WRONG_PASSWORD, EACCES},
203 : {NT_STATUS_LOGON_FAILURE, EACCES},
204 : {NT_STATUS_INVALID_WORKSTATION, EACCES},
205 : {NT_STATUS_INVALID_LOGON_HOURS, EACCES},
206 : {NT_STATUS_PASSWORD_EXPIRED, EACCES},
207 : {NT_STATUS_ACCOUNT_DISABLED, EACCES},
208 : {NT_STATUS_DISK_FULL, ENOSPC},
209 : {NT_STATUS_INVALID_PIPE_STATE, EPIPE},
210 : {NT_STATUS_PIPE_BUSY, EPIPE},
211 : {NT_STATUS_PIPE_DISCONNECTED, EPIPE},
212 : {NT_STATUS_PIPE_NOT_AVAILABLE, ENOSYS},
213 : {NT_STATUS_FILE_IS_A_DIRECTORY, EISDIR},
214 : {NT_STATUS_NOT_SUPPORTED, ENOSYS},
215 : {NT_STATUS_NOT_A_DIRECTORY, ENOTDIR},
216 : {NT_STATUS_DIRECTORY_NOT_EMPTY, ENOTEMPTY},
217 : {NT_STATUS_NETWORK_UNREACHABLE, ENETUNREACH},
218 : {NT_STATUS_HOST_UNREACHABLE, EHOSTUNREACH},
219 : {NT_STATUS_CONNECTION_ABORTED, ECONNABORTED},
220 : {NT_STATUS_CONNECTION_REFUSED, ECONNREFUSED},
221 : {NT_STATUS_TOO_MANY_LINKS, EMLINK},
222 : {NT_STATUS_NETWORK_BUSY, EBUSY},
223 : {NT_STATUS_DEVICE_DOES_NOT_EXIST, ENODEV},
224 : #ifdef ELIBACC
225 : {NT_STATUS_DLL_NOT_FOUND, ELIBACC},
226 : #endif
227 : {NT_STATUS_PIPE_BROKEN, EPIPE},
228 : {NT_STATUS_REMOTE_NOT_LISTENING, ECONNREFUSED},
229 : {NT_STATUS_NETWORK_ACCESS_DENIED, EACCES},
230 : {NT_STATUS_TOO_MANY_OPENED_FILES, EMFILE},
231 : #ifdef EPROTO
232 : {NT_STATUS_DEVICE_PROTOCOL_ERROR, EPROTO},
233 : #endif
234 : {NT_STATUS_FLOAT_OVERFLOW, ERANGE},
235 : {NT_STATUS_FLOAT_UNDERFLOW, ERANGE},
236 : {NT_STATUS_INTEGER_OVERFLOW, ERANGE},
237 : {NT_STATUS_MEDIA_WRITE_PROTECTED, EROFS},
238 : {NT_STATUS_PIPE_CONNECTED, EISCONN},
239 : {NT_STATUS_MEMORY_NOT_ALLOCATED, EFAULT},
240 : {NT_STATUS_FLOAT_INEXACT_RESULT, ERANGE},
241 : {NT_STATUS_ILL_FORMED_PASSWORD, EACCES},
242 : {NT_STATUS_PASSWORD_RESTRICTION, EACCES},
243 : {NT_STATUS_ACCOUNT_RESTRICTION, EACCES},
244 : {NT_STATUS_PORT_CONNECTION_REFUSED, ECONNREFUSED},
245 : {NT_STATUS_NAME_TOO_LONG, ENAMETOOLONG},
246 : {NT_STATUS_REMOTE_DISCONNECT, ESHUTDOWN},
247 : {NT_STATUS_CONNECTION_DISCONNECTED, ECONNABORTED},
248 : {NT_STATUS_CONNECTION_RESET, ENETRESET},
249 : #ifdef ENOTUNIQ
250 : {NT_STATUS_IP_ADDRESS_CONFLICT1, ENOTUNIQ},
251 : {NT_STATUS_IP_ADDRESS_CONFLICT2, ENOTUNIQ},
252 : #endif
253 : {NT_STATUS_PORT_MESSAGE_TOO_LONG, EMSGSIZE},
254 : {NT_STATUS_PROTOCOL_UNREACHABLE, ENOPROTOOPT},
255 : {NT_STATUS_ADDRESS_ALREADY_EXISTS, EADDRINUSE},
256 : {NT_STATUS_PORT_UNREACHABLE, EHOSTUNREACH},
257 : {NT_STATUS_IO_TIMEOUT, ETIMEDOUT},
258 : {NT_STATUS_RETRY, EAGAIN},
259 : #ifdef ENOTUNIQ
260 : {NT_STATUS_DUPLICATE_NAME, ENOTUNIQ},
261 : #endif
262 : #ifdef ECOMM
263 : {NT_STATUS_NET_WRITE_FAULT, ECOMM},
264 : #endif
265 : #ifdef EXDEV
266 : {NT_STATUS_NOT_SAME_DEVICE, EXDEV},
267 : #endif
268 : #ifdef ECANCELED
269 : {NT_STATUS_CANCELLED, ECANCELED},
270 : #endif
271 : };
272 :
273 : /*********************************************************************
274 : Map a Unix error code from a NT error code.
275 : *********************************************************************/
276 9497 : int map_errno_from_nt_status(NTSTATUS status)
277 : {
278 1 : size_t i;
279 :
280 9497 : DBG_DEBUG("32 bit codes: code=%08x\n", NT_STATUS_V(status));
281 :
282 : /* Status codes without this bit set are not errors */
283 :
284 9497 : if (!(NT_STATUS_V(status) & 0xc0000000)) {
285 14 : return 0;
286 : }
287 :
288 39398 : for (i=0;i<ARRAY_SIZE(nt_errno_map);i++) {
289 39394 : if (NT_STATUS_V(nt_errno_map[i].status) ==
290 39390 : NT_STATUS_V(status)) {
291 9479 : return nt_errno_map[i].error;
292 : }
293 : }
294 :
295 : /* for all other cases - a default code */
296 4 : return EINVAL;
297 : }
|