2 * Unix SMB/CIFS implementation.
3 * map unix to NT errors, an excerpt of libsmb/errormap.c
4 * Copyright (C) Andrew Tridgell 2001
5 * Copyright (C) Andrew Bartlett 2001
6 * Copyright (C) Tim Potter 2000
7 * Copyright (C) Jeremy Allison 2007
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* Mapping from Unix, to NT error numbers */
30 } unix_nt_errmap
[] = {
31 { EAGAIN
, NT_STATUS_NETWORK_BUSY
},
32 { EINTR
, NT_STATUS_RETRY
},
34 { ENOBUFS
, NT_STATUS_INSUFFICIENT_RESOURCES
},
37 { EWOULDBLOCK
, NT_STATUS_NETWORK_BUSY
},
39 { EPERM
, NT_STATUS_ACCESS_DENIED
},
40 { EACCES
, NT_STATUS_ACCESS_DENIED
},
41 { ENOENT
, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
42 { ENOTDIR
, NT_STATUS_NOT_A_DIRECTORY
},
43 { EIO
, NT_STATUS_IO_DEVICE_ERROR
},
44 { EBADF
, NT_STATUS_INVALID_HANDLE
},
45 { EINVAL
, NT_STATUS_INVALID_PARAMETER
},
46 { EEXIST
, NT_STATUS_OBJECT_NAME_COLLISION
},
47 { ENFILE
, NT_STATUS_TOO_MANY_OPENED_FILES
},
48 { EMFILE
, NT_STATUS_TOO_MANY_OPENED_FILES
},
49 { ENOSPC
, NT_STATUS_DISK_FULL
},
50 { ENOMEM
, NT_STATUS_NO_MEMORY
},
51 { EISDIR
, NT_STATUS_FILE_IS_A_DIRECTORY
},
53 { EPIPE
, NT_STATUS_CONNECTION_DISCONNECTED
},
55 { EMLINK
, NT_STATUS_TOO_MANY_LINKS
},
56 { ENOSYS
, NT_STATUS_NOT_SUPPORTED
},
58 { ELOOP
, NT_STATUS_OBJECT_PATH_NOT_FOUND
},
61 { EFTYPE
, NT_STATUS_OBJECT_PATH_NOT_FOUND
},
64 { EDQUOT
, NT_STATUS_DISK_FULL
}, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */
67 { ENOTEMPTY
, NT_STATUS_DIRECTORY_NOT_EMPTY
},
70 { EXDEV
, NT_STATUS_NOT_SAME_DEVICE
},
73 { EROFS
, NT_STATUS_ACCESS_DENIED
},
76 { ENAMETOOLONG
, NT_STATUS_OBJECT_NAME_INVALID
},
79 { EFBIG
, NT_STATUS_DISK_FULL
},
82 { EADDRINUSE
, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED
},
85 { ENETUNREACH
, NT_STATUS_NETWORK_UNREACHABLE
},
88 { EHOSTUNREACH
, NT_STATUS_HOST_UNREACHABLE
},
91 { ECONNREFUSED
, NT_STATUS_CONNECTION_REFUSED
},
94 { ETIMEDOUT
, NT_STATUS_IO_TIMEOUT
},
97 { ECONNABORTED
, NT_STATUS_CONNECTION_ABORTED
},
100 { ECONNRESET
, NT_STATUS_CONNECTION_RESET
},
103 { ENODEV
, NT_STATUS_DEVICE_DOES_NOT_EXIST
},
106 { ENOATTR
, NT_STATUS_NOT_FOUND
},
109 { ECANCELED
, NT_STATUS_CANCELLED
},
112 { ENOTSUP
, NT_STATUS_NOT_SUPPORTED
},
115 { ETXTBSY
, NT_STATUS_SHARING_VIOLATION
},
119 /*********************************************************************
120 Map an NT error code from a Unix error code.
121 *********************************************************************/
123 NTSTATUS
map_nt_error_from_unix(int unix_error
)
127 if (unix_error
== 0) {
128 /* we map this to an error, not success, as this
129 function is only called in an error path. Lots of
130 our virtualised functions may fail without making a
131 unix system call that fails (such as when they are
132 checking for some handle existing), so unix_error
135 return NT_STATUS_UNSUCCESSFUL
;
138 /* Look through list */
139 for (i
=0;i
<ARRAY_SIZE(unix_nt_errmap
);i
++) {
140 if (unix_nt_errmap
[i
].unix_error
== unix_error
) {
141 return unix_nt_errmap
[i
].nt_error
;
146 return NT_STATUS_ACCESS_DENIED
;
149 /* Return a UNIX errno from a NT status code */
150 static const struct {
154 {NT_STATUS_ACCESS_VIOLATION
, EACCES
},
155 {NT_STATUS_INVALID_HANDLE
, EBADF
},
156 {NT_STATUS_ACCESS_DENIED
, EACCES
},
157 {NT_STATUS_OBJECT_NAME_NOT_FOUND
, ENOENT
},
158 {NT_STATUS_OBJECT_PATH_NOT_FOUND
, ENOENT
},
159 {NT_STATUS_SHARING_VIOLATION
, EBUSY
},
160 {NT_STATUS_OBJECT_PATH_INVALID
, ENOTDIR
},
161 {NT_STATUS_OBJECT_NAME_COLLISION
, EEXIST
},
162 {NT_STATUS_PATH_NOT_COVERED
, ENOENT
},
163 {NT_STATUS_UNSUCCESSFUL
, EINVAL
},
164 {NT_STATUS_NOT_IMPLEMENTED
, ENOSYS
},
165 {NT_STATUS_IN_PAGE_ERROR
, EFAULT
},
166 {NT_STATUS_BAD_NETWORK_NAME
, ENOENT
},
168 {NT_STATUS_PAGEFILE_QUOTA
, EDQUOT
},
169 {NT_STATUS_QUOTA_EXCEEDED
, EDQUOT
},
170 {NT_STATUS_REGISTRY_QUOTA_LIMIT
, EDQUOT
},
171 {NT_STATUS_LICENSE_QUOTA_EXCEEDED
, EDQUOT
},
174 {NT_STATUS_TIMER_NOT_CANCELED
, ETIME
},
176 {NT_STATUS_INVALID_PARAMETER
, EINVAL
},
177 {NT_STATUS_NO_SUCH_DEVICE
, ENODEV
},
178 {NT_STATUS_NO_SUCH_FILE
, ENOENT
},
180 {NT_STATUS_END_OF_FILE
, ENODATA
},
183 {NT_STATUS_NO_MEDIA_IN_DEVICE
, ENOMEDIUM
},
184 {NT_STATUS_NO_MEDIA
, ENOMEDIUM
},
186 {NT_STATUS_NONEXISTENT_SECTOR
, ESPIPE
},
187 {NT_STATUS_NO_MEMORY
, ENOMEM
},
188 {NT_STATUS_CONFLICTING_ADDRESSES
, EADDRINUSE
},
189 {NT_STATUS_NOT_MAPPED_VIEW
, EINVAL
},
190 {NT_STATUS_UNABLE_TO_FREE_VM
, EADDRINUSE
},
191 {NT_STATUS_ACCESS_DENIED
, EACCES
},
192 {NT_STATUS_BUFFER_TOO_SMALL
, ENOBUFS
},
193 {NT_STATUS_WRONG_PASSWORD
, EACCES
},
194 {NT_STATUS_LOGON_FAILURE
, EACCES
},
195 {NT_STATUS_INVALID_WORKSTATION
, EACCES
},
196 {NT_STATUS_INVALID_LOGON_HOURS
, EACCES
},
197 {NT_STATUS_PASSWORD_EXPIRED
, EACCES
},
198 {NT_STATUS_ACCOUNT_DISABLED
, EACCES
},
199 {NT_STATUS_DISK_FULL
, ENOSPC
},
200 {NT_STATUS_INVALID_PIPE_STATE
, EPIPE
},
201 {NT_STATUS_PIPE_BUSY
, EPIPE
},
202 {NT_STATUS_PIPE_DISCONNECTED
, EPIPE
},
203 {NT_STATUS_PIPE_NOT_AVAILABLE
, ENOSYS
},
204 {NT_STATUS_FILE_IS_A_DIRECTORY
, EISDIR
},
205 {NT_STATUS_NOT_SUPPORTED
, ENOSYS
},
206 {NT_STATUS_NOT_A_DIRECTORY
, ENOTDIR
},
207 {NT_STATUS_DIRECTORY_NOT_EMPTY
, ENOTEMPTY
},
208 {NT_STATUS_NETWORK_UNREACHABLE
, ENETUNREACH
},
209 {NT_STATUS_HOST_UNREACHABLE
, EHOSTUNREACH
},
210 {NT_STATUS_CONNECTION_ABORTED
, ECONNABORTED
},
211 {NT_STATUS_CONNECTION_REFUSED
, ECONNREFUSED
},
212 {NT_STATUS_TOO_MANY_LINKS
, EMLINK
},
213 {NT_STATUS_NETWORK_BUSY
, EBUSY
},
214 {NT_STATUS_DEVICE_DOES_NOT_EXIST
, ENODEV
},
216 {NT_STATUS_DLL_NOT_FOUND
, ELIBACC
},
218 {NT_STATUS_PIPE_BROKEN
, EPIPE
},
219 {NT_STATUS_REMOTE_NOT_LISTENING
, ECONNREFUSED
},
220 {NT_STATUS_NETWORK_ACCESS_DENIED
, EACCES
},
221 {NT_STATUS_TOO_MANY_OPENED_FILES
, EMFILE
},
223 {NT_STATUS_DEVICE_PROTOCOL_ERROR
, EPROTO
},
225 {NT_STATUS_FLOAT_OVERFLOW
, ERANGE
},
226 {NT_STATUS_FLOAT_UNDERFLOW
, ERANGE
},
227 {NT_STATUS_INTEGER_OVERFLOW
, ERANGE
},
228 {NT_STATUS_MEDIA_WRITE_PROTECTED
, EROFS
},
229 {NT_STATUS_PIPE_CONNECTED
, EISCONN
},
230 {NT_STATUS_MEMORY_NOT_ALLOCATED
, EFAULT
},
231 {NT_STATUS_FLOAT_INEXACT_RESULT
, ERANGE
},
232 {NT_STATUS_ILL_FORMED_PASSWORD
, EACCES
},
233 {NT_STATUS_PASSWORD_RESTRICTION
, EACCES
},
234 {NT_STATUS_ACCOUNT_RESTRICTION
, EACCES
},
235 {NT_STATUS_PORT_CONNECTION_REFUSED
, ECONNREFUSED
},
236 {NT_STATUS_NAME_TOO_LONG
, ENAMETOOLONG
},
237 {NT_STATUS_REMOTE_DISCONNECT
, ESHUTDOWN
},
238 {NT_STATUS_CONNECTION_DISCONNECTED
, ECONNABORTED
},
239 {NT_STATUS_CONNECTION_RESET
, ENETRESET
},
241 {NT_STATUS_IP_ADDRESS_CONFLICT1
, ENOTUNIQ
},
242 {NT_STATUS_IP_ADDRESS_CONFLICT2
, ENOTUNIQ
},
244 {NT_STATUS_PORT_MESSAGE_TOO_LONG
, EMSGSIZE
},
245 {NT_STATUS_PROTOCOL_UNREACHABLE
, ENOPROTOOPT
},
246 {NT_STATUS_ADDRESS_ALREADY_EXISTS
, EADDRINUSE
},
247 {NT_STATUS_PORT_UNREACHABLE
, EHOSTUNREACH
},
248 {NT_STATUS_IO_TIMEOUT
, ETIMEDOUT
},
249 {NT_STATUS_RETRY
, EAGAIN
},
251 {NT_STATUS_DUPLICATE_NAME
, ENOTUNIQ
},
254 {NT_STATUS_NET_WRITE_FAULT
, ECOMM
},
257 {NT_STATUS_NOT_SAME_DEVICE
, EXDEV
},
261 int map_errno_from_nt_status(NTSTATUS status
)
264 DEBUG(10,("map_errno_from_nt_status: 32 bit codes: code=%08x\n",
265 NT_STATUS_V(status
)));
267 /* Status codes without this bit set are not errors */
269 if (!(NT_STATUS_V(status
) & 0xc0000000)) {
273 for (i
=0;i
<ARRAY_SIZE(nt_errno_map
);i
++) {
274 if (NT_STATUS_V(nt_errno_map
[i
].status
) ==
275 NT_STATUS_V(status
)) {
276 return nt_errno_map
[i
].error
;
280 /* for all other cases - a default code */