r4066: add a mapping for NT_STATUS_NO_MORE_ENTRIES
[gd/samba-autobuild/.git] / source4 / libcli / util / errormap.c
index a257c2d0ea3a24960ac07d6111208b3c543d4a50..4a57e436c7c5ac4d3756ee69cf6c48d3372a1e25 100644 (file)
 
 /* NT status -> dos error map */
 static const struct {
-       uint8 dos_class;
-       uint32 dos_code;
+       uint8_t dos_class;
+       uint32_t dos_code;
        NTSTATUS ntstatus;
 } ntstatus_to_dos_map[] = {
+       {ERRDOS,        ERRnofiles,     STATUS_NO_MORE_FILES},
+       {ERRDOS,        ERRnofiles,     NT_STATUS_NO_MORE_ENTRIES},
        {ERRDOS,        ERRgeneral,     NT_STATUS_UNSUCCESSFUL},
        {ERRDOS,        ERRbadfunc,     NT_STATUS_NOT_IMPLEMENTED},
        {ERRDOS,        87,     NT_STATUS_INVALID_INFO_CLASS},
@@ -64,7 +66,7 @@ static const struct {
        {ERRHRD,        ERRgeneral,     NT_STATUS_TIMER_NOT_CANCELED},
        {ERRDOS,        87,     NT_STATUS_INVALID_PARAMETER},
        {ERRDOS,        ERRbadfile,     NT_STATUS_NO_SUCH_DEVICE},
-       {ERRDOS,        ERRbadfile,     NT_STATUS_NO_SUCH_FILE},
+       {ERRDOS,        ERRnofiles,     NT_STATUS_NO_SUCH_FILE},
        {ERRDOS,        ERRbadfunc,     NT_STATUS_INVALID_DEVICE_REQUEST},
        {ERRDOS,        38,     NT_STATUS_END_OF_FILE},
        {ERRDOS,        34,     NT_STATUS_WRONG_VOLUME},
@@ -612,10 +614,11 @@ static const struct {
 
 /* dos -> nt status error map */
 static const struct {
-       uint8 dos_class;
-       uint32 dos_code;
+       uint8_t dos_class;
+       uint32_t dos_code;
        NTSTATUS ntstatus;
 } dos_to_ntstatus_map[] = {
+       {ERRDOS,        ERRnofiles,     STATUS_NO_MORE_FILES},
        {ERRDOS,        ERRbadfunc,     NT_STATUS_NOT_IMPLEMENTED},
        {ERRDOS,        ERRbadfile,     NT_STATUS_NO_SUCH_FILE},
        {ERRDOS,        ERRbadpath,     NT_STATUS_OBJECT_PATH_NOT_FOUND},
@@ -628,7 +631,6 @@ static const struct {
        {ERRDOS,        14,     NT_STATUS_SECTION_NOT_EXTENDED},
        {ERRDOS,        ERRremcd,       NT_STATUS_DIRECTORY_NOT_EMPTY},
        {ERRDOS,        ERRdiffdevice,  NT_STATUS_NOT_SAME_DEVICE},
-       {ERRDOS,        ERRnofiles,     NT_STATUS(0x80000006)},
        {ERRDOS,        19,     NT_STATUS_MEDIA_WRITE_PROTECTED},
        {ERRDOS,        21,     NT_STATUS_NO_MEDIA_IN_DEVICE},
        {ERRDOS,        22,     NT_STATUS_INVALID_DEVICE_STATE},
@@ -746,6 +748,7 @@ static const struct {
        {ERRSRV,        ERRnoroom,      NT_STATUS_DISK_FULL},
        {ERRSRV,        ERRnoresource,  NT_STATUS_REQUEST_NOT_ACCEPTED},
        {ERRSRV,        ERRtoomanyuids, NT_STATUS_TOO_MANY_SESSIONS},
+       {ERRSRV,        ERRbaduid,      NT_STATUS_INVALID_HANDLE},
        {ERRSRV,        123,    NT_STATUS_OBJECT_NAME_INVALID},
        {ERRSRV,        206,    NT_STATUS_OBJECT_NAME_INVALID},
        {ERRHRD,        1,      NT_STATUS_NOT_IMPLEMENTED},
@@ -1410,7 +1413,7 @@ static const struct {
 /*****************************************************************************
 convert a dos eclas/ecode to a NT status32 code
  *****************************************************************************/
-NTSTATUS dos_to_ntstatus(uint8 eclass, uint32 ecode)
+NTSTATUS dos_to_ntstatus(uint8_t eclass, uint32_t ecode)
 {
        int i;
        if (eclass == 0 && ecode == 0) return NT_STATUS_OK;
@@ -1427,7 +1430,7 @@ NTSTATUS dos_to_ntstatus(uint8 eclass, uint32 ecode)
 /*****************************************************************************
 convert a NT status code to a dos class/code
  *****************************************************************************/
-void ntstatus_to_dos(NTSTATUS ntstatus, uint8 *eclass, uint32 *ecode)
+void ntstatus_to_dos(NTSTATUS ntstatus, uint8_t *eclass, uint32_t *ecode)
 {
        int i;
        if (NT_STATUS_IS_OK(ntstatus)) {
@@ -1486,61 +1489,90 @@ WERROR ntstatus_to_werror(NTSTATUS error)
 
 /* Mapping between Unix, DOS and 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_OBJECT_PATH_NOT_FOUND },
-       { 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 },
-       { EISDIR, ERRDOS, ERRbadpath, NT_STATUS_FILE_IS_A_DIRECTORY },
+struct unix_error_map {
+       int unix_error;
+       NTSTATUS nt_error;
+};
+
+const struct unix_error_map unix_nt_errmap[] = {
+       { EAGAIN,       STATUS_MORE_ENTRIES },
+       { EINTR,        STATUS_MORE_ENTRIES },
+       { EINPROGRESS,  STATUS_MORE_ENTRIES },
+       { EPERM,        NT_STATUS_ACCESS_DENIED },
+       { EACCES,       NT_STATUS_ACCESS_DENIED },
+       { ENOENT,       NT_STATUS_OBJECT_NAME_NOT_FOUND },
+       { ENOTDIR,      NT_STATUS_NOT_A_DIRECTORY },
+       { EIO,          NT_STATUS_IO_DEVICE_ERROR },
+       { EBADF,        NT_STATUS_INVALID_HANDLE },
+       { EINVAL,       NT_STATUS_INVALID_PARAMETER },
+       { EEXIST,       NT_STATUS_OBJECT_NAME_COLLISION},
+       { ENFILE,       NT_STATUS_TOO_MANY_OPENED_FILES },
+       { EMFILE,       NT_STATUS_TOO_MANY_OPENED_FILES },
+       { ENOSPC,       NT_STATUS_DISK_FULL },
+       { EISDIR,       NT_STATUS_FILE_IS_A_DIRECTORY },
+       { ENOTSOCK,     NT_STATUS_INVALID_HANDLE },
+       { EFAULT,       NT_STATUS_INVALID_PARAMETER },
+       { EMSGSIZE,     NT_STATUS_INVALID_BUFFER_SIZE },
+       { ENOBUFS,      NT_STATUS_NO_MEMORY },
+       { ENOMEM,       NT_STATUS_NO_MEMORY },
+       { EPIPE,        NT_STATUS_CONNECTION_DISCONNECTED },
+       { ECONNREFUSED, NT_STATUS_CONNECTION_REFUSED },
+       { EBUSY,        NT_STATUS_SHARING_VIOLATION },
+       { ENOTSUP,      NT_STATUS_NOT_SUPPORTED},
+#ifdef EHOSTUNREACH
+       { EHOSTUNREACH, NT_STATUS_HOST_UNREACHABLE },
+#endif
+#ifdef ENETUNREACH
+       { ENETUNREACH, NT_STATUS_NETWORK_UNREACHABLE },
+#endif
+#ifdef ETIMEDOUT
+       { ETIMEDOUT, NT_STATUS_IO_TIMEOUT },
+#endif
+#ifdef EADDRINUSE
+       { EADDRINUSE,   NT_STATUS_ADDRESS_ALREADY_ASSOCIATED },
+#endif
+#ifdef ENOATTR
+       { ENOATTR,      NT_STATUS_NOT_FOUND },
+#endif
+#ifdef ENODATA
+       { ENODATA,      NT_STATUS_NOT_FOUND },
+#endif
 #ifdef EDQUOT
-       { EDQUOT, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL },
+       { EDQUOT,       NT_STATUS_QUOTA_EXCEEDED },
 #endif
 #ifdef ENOTEMPTY
-       { ENOTEMPTY, ERRDOS, ERRnoaccess, NT_STATUS_DIRECTORY_NOT_EMPTY },
+       { ENOTEMPTY,    NT_STATUS_DIRECTORY_NOT_EMPTY },
 #endif
 #ifdef EXDEV
-       { EXDEV, ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE },
+       { EXDEV,        NT_STATUS_NOT_SAME_DEVICE },
 #endif
 #ifdef EROFS
-       { EROFS, ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED },
+       { EROFS,        NT_STATUS_MEDIA_WRITE_PROTECTED },
 #endif
 #ifdef ENAMETOOLONG
-       { ENAMETOOLONG, ERRDOS, 206, NT_STATUS_OBJECT_NAME_INVALID },
+       { ENAMETOOLONG, NT_STATUS_NAME_TOO_LONG },
 #endif
 #ifdef EFBIG
-       { EFBIG, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL },
+       { EFBIG,        NT_STATUS_DISK_FULL },
 #endif
-#ifdef EFBIG
-       { EBUSY, ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION },
-#endif
-       { 0, 0, 0, NT_STATUS_OK }
+       { 0, NT_STATUS_UNSUCCESSFUL }
 };
 
+
 /*********************************************************************
  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;
+       int i;
 
        /* 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++;
+       for (i=0;i<ARRAY_SIZE(unix_nt_errmap);i++) {
+               if (unix_nt_errmap[i].unix_error == unix_error) {
+                       return unix_nt_errmap[i].nt_error;
+               }
        }
 
        /* Default return */
-       return NT_STATUS_ACCESS_DENIED;
+       return NT_STATUS_UNSUCCESSFUL;
 }