1 | /*
|
---|
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
|
---|
8 | *
|
---|
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.
|
---|
13 | *
|
---|
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.
|
---|
18 | *
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 |
|
---|
25 | /* Mapping from Unix, to NT error numbers */
|
---|
26 |
|
---|
27 | const struct unix_error_map unix_dos_nt_errmap[] = {
|
---|
28 | { EPERM, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
|
---|
29 | { EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
|
---|
30 | { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND },
|
---|
31 | { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_NOT_A_DIRECTORY },
|
---|
32 | { EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR },
|
---|
33 | { EBADF, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE },
|
---|
34 | { EINVAL, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE },
|
---|
35 | { EEXIST, ERRDOS, ERRfilexists, NT_STATUS_OBJECT_NAME_COLLISION},
|
---|
36 | { ENFILE, ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES },
|
---|
37 | { EMFILE, ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES },
|
---|
38 | { ENOSPC, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL },
|
---|
39 | { ENOMEM, ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY },
|
---|
40 | { EISDIR, ERRDOS, ERRnoaccess, NT_STATUS_FILE_IS_A_DIRECTORY},
|
---|
41 | { EMLINK, ERRDOS, ERRgeneral, NT_STATUS_TOO_MANY_LINKS },
|
---|
42 | { EINTR, ERRHRD, ERRgeneral, NT_STATUS_RETRY },
|
---|
43 | #ifdef ELOOP
|
---|
44 | { ELOOP, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND },
|
---|
45 | #endif
|
---|
46 | #ifdef EDQUOT
|
---|
47 | { EDQUOT, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL }, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */
|
---|
48 | #endif
|
---|
49 | #ifdef ENOTEMPTY
|
---|
50 | { ENOTEMPTY, ERRDOS, ERRnoaccess, NT_STATUS_DIRECTORY_NOT_EMPTY },
|
---|
51 | #endif
|
---|
52 | #ifdef EXDEV
|
---|
53 | { EXDEV, ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE },
|
---|
54 | #endif
|
---|
55 | #ifdef EROFS
|
---|
56 | { EROFS, ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED },
|
---|
57 | #endif
|
---|
58 | #ifdef ENAMETOOLONG
|
---|
59 | { ENAMETOOLONG, ERRDOS, 206, NT_STATUS_OBJECT_NAME_INVALID },
|
---|
60 | #endif
|
---|
61 | #ifdef EFBIG
|
---|
62 | { EFBIG, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL },
|
---|
63 | #endif
|
---|
64 | #ifdef ENOBUFS
|
---|
65 | { ENOBUFS, ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES },
|
---|
66 | #endif
|
---|
67 | { EAGAIN, ERRDOS, 111, NT_STATUS_NETWORK_BUSY },
|
---|
68 | #ifdef EADDRINUSE
|
---|
69 | { EADDRINUSE, ERRDOS, 52, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED},
|
---|
70 | #endif
|
---|
71 | #ifdef ENETUNREACH
|
---|
72 | { ENETUNREACH, ERRHRD, ERRgeneral, NT_STATUS_NETWORK_UNREACHABLE},
|
---|
73 | #endif
|
---|
74 | #ifdef EHOSTUNREACH
|
---|
75 | { EHOSTUNREACH, ERRHRD, ERRgeneral, NT_STATUS_HOST_UNREACHABLE},
|
---|
76 | #endif
|
---|
77 | #ifdef ECONNREFUSED
|
---|
78 | { ECONNREFUSED, ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_REFUSED},
|
---|
79 | #endif
|
---|
80 | #ifdef ETIMEDOUT
|
---|
81 | { ETIMEDOUT, ERRHRD, 121, NT_STATUS_IO_TIMEOUT},
|
---|
82 | #endif
|
---|
83 | #ifdef ECONNABORTED
|
---|
84 | { ECONNABORTED, ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ABORTED},
|
---|
85 | #endif
|
---|
86 | #ifdef ENODEV
|
---|
87 | { ENODEV, ERRDOS, 55, NT_STATUS_DEVICE_DOES_NOT_EXIST},
|
---|
88 | #endif
|
---|
89 | #ifdef EPIPE
|
---|
90 | { EPIPE, ERRDOS, 109, NT_STATUS_PIPE_BROKEN},
|
---|
91 | #endif
|
---|
92 | #ifdef EWOULDBLOCK
|
---|
93 | { EWOULDBLOCK, ERRDOS, 111, NT_STATUS_NETWORK_BUSY },
|
---|
94 | #endif
|
---|
95 | #ifdef ENOATTR
|
---|
96 | { ENOATTR, ERRDOS, ERRbadfile, NT_STATUS_NOT_FOUND },
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | { 0, 0, 0, NT_STATUS_OK }
|
---|
100 | };
|
---|
101 |
|
---|
102 | /*********************************************************************
|
---|
103 | Map an NT error code from a Unix error code.
|
---|
104 | *********************************************************************/
|
---|
105 |
|
---|
106 | NTSTATUS map_nt_error_from_unix(int unix_error)
|
---|
107 | {
|
---|
108 | int i = 0;
|
---|
109 |
|
---|
110 | if (unix_error == 0) {
|
---|
111 | /* we map this to an error, not success, as this
|
---|
112 | function is only called in an error path. Lots of
|
---|
113 | our virtualised functions may fail without making a
|
---|
114 | unix system call that fails (such as when they are
|
---|
115 | checking for some handle existing), so unix_error
|
---|
116 | may be unset
|
---|
117 | */
|
---|
118 | return NT_STATUS_UNSUCCESSFUL;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /* Look through list */
|
---|
122 | while(unix_dos_nt_errmap[i].unix_error != 0) {
|
---|
123 | if (unix_dos_nt_errmap[i].unix_error == unix_error)
|
---|
124 | return unix_dos_nt_errmap[i].nt_error;
|
---|
125 | i++;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /* Default return */
|
---|
129 | return NT_STATUS_ACCESS_DENIED;
|
---|
130 | }
|
---|