From 6426d8b4a0fceb352641e936e632bf5bb0f84525 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 29 May 2007 19:09:38 +0000 Subject: r23224: Move map_nt_error_from_unix to lib/errmap_unix.c. This function is useful even in binaries that don't link in libsmb (This used to be commit 52545d119277b42a46d13b5b031c85f47d96b84c) --- source3/lib/errmap_unix.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 source3/lib/errmap_unix.c (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c new file mode 100644 index 0000000000..0c5d3246e2 --- /dev/null +++ b/source3/lib/errmap_unix.c @@ -0,0 +1,92 @@ +/* + * Unix SMB/CIFS implementation. + * map unix to NT errors, an excerpt of libsmb/errormap.c + * Copyright (C) Andrew Tridgell 2001 + * Copyright (C) Andrew Bartlett 2001 + * Copyright (C) Tim Potter 2000 + * Copyright (C) Jeremy Allison 2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Mapping from Unix, to NT error numbers */ + +const struct unix_error_map unix_dos_nt_errmap[] = { + { EPERM, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, + { EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED }, + { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND }, + { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_NOT_A_DIRECTORY }, + { EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR }, + { EBADF, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE }, + { EINVAL, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE }, + { EEXIST, ERRDOS, ERRfilexists, NT_STATUS_OBJECT_NAME_COLLISION}, + { ENFILE, ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES }, + { EMFILE, ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES }, + { ENOSPC, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL }, + { ENOMEM, ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY }, + { EISDIR, ERRDOS, ERRnoaccess, NT_STATUS_FILE_IS_A_DIRECTORY}, + { EMLINK, ERRDOS, ERRgeneral, NT_STATUS_TOO_MANY_LINKS }, + { EINTR, ERRHRD, ERRgeneral, NT_STATUS_RETRY }, +#ifdef EDQUOT + { EDQUOT, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL }, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */ +#endif +#ifdef ENOTEMPTY + { ENOTEMPTY, ERRDOS, ERRnoaccess, NT_STATUS_DIRECTORY_NOT_EMPTY }, +#endif +#ifdef EXDEV + { EXDEV, ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE }, +#endif +#ifdef EROFS + { EROFS, ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED }, +#endif +#ifdef ENAMETOOLONG + { ENAMETOOLONG, ERRDOS, 206, NT_STATUS_OBJECT_NAME_INVALID }, +#endif +#ifdef EFBIG + { EFBIG, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL }, +#endif +#ifdef ENOBUFS + { ENOBUFS, ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES }, +#endif + { EAGAIN, ERRDOS, 111, NT_STATUS_NETWORK_BUSY }, +#ifdef EWOULDBLOCK + { EWOULDBLOCK, ERRDOS, 111, NT_STATUS_NETWORK_BUSY }, +#endif + { 0, 0, 0, NT_STATUS_OK } +}; + +/********************************************************************* + Map an NT error code from a Unix error code. +*********************************************************************/ + +NTSTATUS map_nt_error_from_unix(int unix_error) +{ + int i = 0; + + if (unix_error == 0) + return NT_STATUS_OK; + + /* Look through list */ + while(unix_dos_nt_errmap[i].unix_error != 0) { + if (unix_dos_nt_errmap[i].unix_error == unix_error) + return unix_dos_nt_errmap[i].nt_error; + i++; + } + + /* Default return */ + return NT_STATUS_ACCESS_DENIED; +} -- cgit From 4a77ae5af8d50761cca27299d76d8a7c5cab9e2b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Jun 2007 01:26:18 +0000 Subject: r23550: Add more UNIX error -> NT status mappings. Jeremy. (This used to be commit 1e66a8340e7db9c42507d93d67ad33abadabd2a1) --- source3/lib/errmap_unix.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index 0c5d3246e2..8ec0e5faca 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -63,9 +63,34 @@ const struct unix_error_map unix_dos_nt_errmap[] = { { ENOBUFS, ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES }, #endif { EAGAIN, ERRDOS, 111, NT_STATUS_NETWORK_BUSY }, +#ifdef EADDRINUSE + { EADDRINUSE, ERRDOS, 52, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED}, +#endif +#ifdef ENETUNREACH + { ENETUNREACH, ERRHRD, ERRgeneral, NT_STATUS_NETWORK_UNREACHABLE}, +#endif +#ifdef EHOSTUNREACH + { EHOSTUNREACH, ERRHRD, ERRgeneral, NT_STATUS_HOST_UNREACHABLE}, +#endif +#ifdef ECONNREFUSED + { ECONNREFUSED, ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_REFUSED}, +#endif +#ifdef ETIMEDOUT + { ETIMEDOUT, ERRHRD, 121, NT_STATUS_IO_TIMEOUT}, +#endif +#ifdef ECONNABORTED + { ECONNABORTED, ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ABORTED}, +#endif +#ifdef ENODEV + { ENODEV, ERRDOS, 55, NT_STATUS_DEVICE_DOES_NOT_EXIST}, +#endif +#ifdef EPIPE + { EPIPE, ERRDOS, 109, NT_STATUS_PIPE_BROKEN}, +#endif #ifdef EWOULDBLOCK { EWOULDBLOCK, ERRDOS, 111, NT_STATUS_NETWORK_BUSY }, #endif + { 0, 0, 0, NT_STATUS_OK } }; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/errmap_unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index 8ec0e5faca..cd2e7a53da 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -8,7 +8,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/lib/errmap_unix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index cd2e7a53da..79cdd886cf 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -17,8 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From da0758cb048b5d5c804ea4e73ffb822532cd3a00 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Jul 2007 23:40:14 +0000 Subject: r23845: Second part of the fix for #4777. Looks like on AIX opendir returns an errno of ELOOP for a symlink of msdfs:server\path\to\link. Cope with this by mapping to a known error NT_STATUS_OBJECT_PATH_NOT_FOUND that we know dfs_path_lookup should ignore. Jeremy. (This used to be commit d4a7411c4886c601a917b0f0e53facc7e10dd18e) --- source3/lib/errmap_unix.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index 79cdd886cf..885a1c55b2 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -40,6 +40,9 @@ const struct unix_error_map unix_dos_nt_errmap[] = { { EISDIR, ERRDOS, ERRnoaccess, NT_STATUS_FILE_IS_A_DIRECTORY}, { EMLINK, ERRDOS, ERRgeneral, NT_STATUS_TOO_MANY_LINKS }, { EINTR, ERRHRD, ERRgeneral, NT_STATUS_RETRY }, +#ifdef ELOOP + { ELOOP, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND }, +#endif #ifdef EDQUOT { EDQUOT, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL }, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */ #endif -- cgit From 14e7c292bc76b0edb8cafcaa728a612fa806fa6d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Jan 2008 22:44:55 +0100 Subject: Add an error mapping for ENOATTR (This used to be commit 9f0d778490415b05224f36287df999672ee16928) --- source3/lib/errmap_unix.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index 885a1c55b2..8194cf80cc 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -92,6 +92,9 @@ const struct unix_error_map unix_dos_nt_errmap[] = { #ifdef EWOULDBLOCK { EWOULDBLOCK, ERRDOS, 111, NT_STATUS_NETWORK_BUSY }, #endif +#ifdef ENOATTR + { ENOATTR, ERRDOS, ERRbadfile, NT_STATUS_NOT_FOUND }, +#endif { 0, 0, 0, NT_STATUS_OK } }; -- cgit From 8b25ce06ceb4ad57fa585e76c1a6be12a4c7d3d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 10 Aug 2008 10:43:36 +1000 Subject: I found lots of places where we assume error will be set when calling one of our virtualised functions, such as db_open(), but error is only set when a system call fails, and it is not uncommon for us to fail a function internally without ever making a system call. That led to us passing back success when a function had in fact failed. I found two places where we relied on map_nt_error_from_unix() returning success when errno==0, but lots and lots of places where we relied on the reverse, so I fixed those two places. map_nt_error_from_unix() will now always return an error, returning NT_STATUS_UNSUCCESSFUL if errno is 0 (cherry picked from commit 69d40ca4c1af925d4b0e59ddc69ef8c26e6501d1) (This used to be commit 834684a524a24bb4eb46b4af583d39947dc87d95) --- source3/lib/errmap_unix.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/lib/errmap_unix.c') diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index 8194cf80cc..2cd2386c5c 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -107,8 +107,16 @@ NTSTATUS map_nt_error_from_unix(int unix_error) { int i = 0; - if (unix_error == 0) - return NT_STATUS_OK; + if (unix_error == 0) { + /* we map this to an error, not success, as this + function is only called in an error path. Lots of + our virtualised functions may fail without making a + unix system call that fails (such as when they are + checking for some handle existing), so unix_error + may be unset + */ + return NT_STATUS_UNSUCCESSFUL; + } /* Look through list */ while(unix_dos_nt_errmap[i].unix_error != 0) { -- cgit