| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
NT error code constants |
| 4 |
Copyright (C) Andrew Tridgell 1992-2000 |
| 5 |
Copyright (C) John H Terpstra 1996-2000 |
| 6 |
Copyright (C) Luke Kenneth Casson Leighton 1996-2000 |
| 7 |
Copyright (C) Paul Ashton 1998-2000 |
| 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 |
#ifndef _NTSTATUS_H |
| 24 |
#define _NTSTATUS_H |
| 25 |
|
| 26 |
#include <stdint.h> |
| 27 |
|
| 28 |
#include "libcli/util/ntstatus_gen.h" |
| 29 |
|
| 30 |
/* the following rather strange looking definitions of NTSTATUS |
| 31 |
are there in order to catch common coding errors where different error types |
| 32 |
are mixed up. This is especially important as we slowly convert Samba |
| 33 |
from using bool for internal functions |
| 34 |
*/ |
| 35 |
|
| 36 |
#if defined(HAVE_IMMEDIATE_STRUCTURES) |
| 37 |
typedef struct {uint32_t v;} NTSTATUS; |
| 38 |
#define NT_STATUS(x) ((NTSTATUS) { x }) |
| 39 |
#define NT_STATUS_V(x) ((x).v) |
| 40 |
#else |
| 41 |
typedef uint32_t NTSTATUS; |
| 42 |
#define NT_STATUS(x) (x) |
| 43 |
#define NT_STATUS_V(x) (x) |
| 44 |
#endif |
| 45 |
|
| 46 |
/* Win32 status codes. */ |
| 47 |
#define ERROR_INVALID_PARAMETER NT_STATUS(0x0057) |
| 48 |
#define ERROR_INSUFFICIENT_BUFFER NT_STATUS(0x007a) |
| 49 |
#define NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS NT_STATUS(0x2071) |
| 50 |
#define NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION NT_STATUS(0x2177) |
| 51 |
#define NT_STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP NT_STATUS(0xC05D0000) |
| 52 |
|
| 53 |
/* Other error codes that aren't in the list we use */ |
| 54 |
#define STATUS_MORE_ENTRIES NT_STATUS_MORE_ENTRIES |
| 55 |
#define STATUS_BUFFER_OVERFLOW NT_STATUS_BUFFER_OVERFLOW |
| 56 |
#define STATUS_NO_MORE_FILES NT_STATUS_NO_MORE_FILES |
| 57 |
#define STATUS_INVALID_EA_NAME NT_STATUS_INVALID_EA_NAME |
| 58 |
#define STATUS_SOME_UNMAPPED NT_STATUS_SOME_NOT_MAPPED |
| 59 |
|
| 60 |
#define NT_STATUS_ABIOS_NOT_PRESENT NT_STATUS(0xC0000000 | 0x010f) |
| 61 |
#define NT_STATUS_ABIOS_LID_NOT_EXIST NT_STATUS(0xC0000000 | 0x0110) |
| 62 |
#define NT_STATUS_ABIOS_LID_ALREADY_OWNED NT_STATUS(0xC0000000 | 0x0111) |
| 63 |
#define NT_STATUS_ABIOS_NOT_LID_OWNER NT_STATUS(0xC0000000 | 0x0112) |
| 64 |
#define NT_STATUS_ABIOS_INVALID_COMMAND NT_STATUS(0xC0000000 | 0x0113) |
| 65 |
#define NT_STATUS_ABIOS_INVALID_LID NT_STATUS(0xC0000000 | 0x0114) |
| 66 |
#define NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE NT_STATUS(0xC0000000 | 0x0115) |
| 67 |
#define NT_STATUS_ABIOS_INVALID_SELECTOR NT_STATUS(0xC0000000 | 0x0116) |
| 68 |
|
| 69 |
#define NT_STATUS_HANDLE_NOT_WAITABLE NT_STATUS(0xC0000000 | 0x0036) |
| 70 |
#define NT_STATUS_DEVICE_POWER_FAILURE NT_STATUS(0xC0000000 | 0x009e) |
| 71 |
#define NT_STATUS_VHD_SHARED NT_STATUS(0xC05CFF0A) |
| 72 |
#define NT_STATUS_SMB_BAD_CLUSTER_DIALECT NT_STATUS(0xC05D0001) |
| 73 |
#define NT_STATUS_NO_SUCH_JOB NT_STATUS(0xC0000000 | 0xEDE) |
| 74 |
|
| 75 |
/* |
| 76 |
-------------- |
| 77 |
/ \ |
| 78 |
/ REST \ |
| 79 |
/ IN \ |
| 80 |
/ PEACE \ |
| 81 |
/ \ |
| 82 |
| NT_STATUS_NOPROBLEMO | |
| 83 |
| | |
| 84 |
| | |
| 85 |
| 4 September | |
| 86 |
| | |
| 87 |
| 2001 | |
| 88 |
*| * * * | * |
| 89 |
_________)/\\_//(\/(/\)/\//\/\///|_)_______ |
| 90 |
*/ |
| 91 |
|
| 92 |
/* I use NT_STATUS_FOOBAR when I have no idea what error code to use - |
| 93 |
* this means we need a torture test */ |
| 94 |
#define NT_STATUS_FOOBAR NT_STATUS_UNSUCCESSFUL |
| 95 |
|
| 96 |
/***************************************************************************** |
| 97 |
returns an NT error message. not amazingly helpful, but better than a number. |
| 98 |
*****************************************************************************/ |
| 99 |
const char *nt_errstr(NTSTATUS nt_code); |
| 100 |
|
| 101 |
/************************************************************************ |
| 102 |
Print friendlier version of NT error code |
| 103 |
***********************************************************************/ |
| 104 |
const char *get_friendly_nt_error_msg(NTSTATUS nt_code); |
| 105 |
|
| 106 |
/***************************************************************************** |
| 107 |
returns an NT_STATUS constant as a string for inclusion in autogen C code |
| 108 |
*****************************************************************************/ |
| 109 |
const char *get_nt_error_c_code(void *mem_ctx, NTSTATUS nt_code); |
| 110 |
|
| 111 |
/***************************************************************************** |
| 112 |
returns the NT_STATUS constant matching the string supplied (as an NTSTATUS) |
| 113 |
*****************************************************************************/ |
| 114 |
NTSTATUS nt_status_string_to_code(const char *nt_status_str); |
| 115 |
|
| 116 |
/* we need these here for openchange */ |
| 117 |
#ifndef likely |
| 118 |
#define likely(x) (x) |
| 119 |
#endif |
| 120 |
#ifndef unlikely |
| 121 |
#define unlikely(x) (x) |
| 122 |
#endif |
| 123 |
|
| 124 |
#define NT_STATUS_IS_OK(x) (likely(NT_STATUS_V(x) == 0)) |
| 125 |
#define NT_STATUS_IS_ERR(x) (unlikely((NT_STATUS_V(x) & 0xc0000000) == 0xc0000000)) |
| 126 |
#define NT_STATUS_EQUAL(x,y) (NT_STATUS_V(x) == NT_STATUS_V(y)) |
| 127 |
|
| 128 |
/* |
| 129 |
* These macros (with the embedded return) are considered poor coding |
| 130 |
* style per README.Coding |
| 131 |
* |
| 132 |
* Please do not use them in new code, and do not rely on them in |
| 133 |
* projects external to Samba as they will go away at some point. |
| 134 |
*/ |
| 135 |
|
| 136 |
#define NT_STATUS_HAVE_NO_MEMORY(x) do { \ |
| 137 |
if (unlikely(!(x))) { \ |
| 138 |
return NT_STATUS_NO_MEMORY;\ |
| 139 |
}\ |
| 140 |
} while (0) |
| 141 |
|
| 142 |
/* This variant is for when you want to free a local |
| 143 |
temporary memory context in the error path */ |
| 144 |
#define NT_STATUS_HAVE_NO_MEMORY_AND_FREE(x, ctx) do { \ |
| 145 |
if (!(x)) {\ |
| 146 |
talloc_free(ctx); \ |
| 147 |
return NT_STATUS_NO_MEMORY;\ |
| 148 |
}\ |
| 149 |
} while (0) |
| 150 |
|
| 151 |
#define NT_STATUS_IS_OK_RETURN(x) do { \ |
| 152 |
if (NT_STATUS_IS_OK(x)) {\ |
| 153 |
return x;\ |
| 154 |
}\ |
| 155 |
} while (0) |
| 156 |
|
| 157 |
#define NT_STATUS_NOT_OK_RETURN(x) do { \ |
| 158 |
if (!NT_STATUS_IS_OK(x)) {\ |
| 159 |
return x;\ |
| 160 |
}\ |
| 161 |
} while (0) |
| 162 |
|
| 163 |
#define NT_STATUS_NOT_OK_RETURN_AND_FREE(x, ctx) do { \ |
| 164 |
if (!NT_STATUS_IS_OK(x)) {\ |
| 165 |
talloc_free(ctx); \ |
| 166 |
return x;\ |
| 167 |
}\ |
| 168 |
} while (0) |
| 169 |
|
| 170 |
#define NT_STATUS_IS_ERR_RETURN(x) do { \ |
| 171 |
if (NT_STATUS_IS_ERR(x)) {\ |
| 172 |
return x;\ |
| 173 |
}\ |
| 174 |
} while (0) |
| 175 |
|
| 176 |
#define NT_STATUS_NOT_ERR_RETURN(x) do { \ |
| 177 |
if (!NT_STATUS_IS_ERR(x)) {\ |
| 178 |
return x;\ |
| 179 |
}\ |
| 180 |
} while (0) |
| 181 |
|
| 182 |
/* this defines special NTSTATUS codes to represent DOS errors. I |
| 183 |
have chosen this macro to produce status codes in the invalid |
| 184 |
NTSTATUS range */ |
| 185 |
#define NT_STATUS_DOS(class, code) NT_STATUS(0xF1000000 | ((class)<<16) | code) |
| 186 |
#define NT_STATUS_IS_DOS(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF1000000) |
| 187 |
#define NT_STATUS_DOS_CLASS(status) ((NT_STATUS_V(status) >> 16) & 0xFF) |
| 188 |
#define NT_STATUS_DOS_CODE(status) (NT_STATUS_V(status) & 0xFFFF) |
| 189 |
|
| 190 |
/* define ldap error codes as NTSTATUS codes */ |
| 191 |
#define NT_STATUS_LDAP(code) NT_STATUS(0xF2000000 | code) |
| 192 |
#define NT_STATUS_IS_LDAP(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF2000000) |
| 193 |
#define NT_STATUS_LDAP_CODE(status) (NT_STATUS_V(status) & ~0xFF000000) |
| 194 |
|
| 195 |
#define NT_STATUS_IS_RPC(status) \ |
| 196 |
(((NT_STATUS_V(status) & 0xFFFF) == 0xC0020000) || \ |
| 197 |
((NT_STATUS_V(status) & 0xFFFF) == 0xC0030000)) |
| 198 |
|
| 199 |
#endif /* _NTSTATUS_H */ |