CVE-2021-3738 s4:rpc_server/drsuapi: make use of assoc_group aware dcesrv_samdb_conne...
[Samba.git] / libcli / util / ntstatus.h
blob66cfd11bc5887dd8a3989094983c5cae90ee56b3
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
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/>.
23 #ifndef _NTSTATUS_H
24 #define _NTSTATUS_H
26 #include "libcli/util/ntstatus_gen.h"
28 /* the following rather strange looking definitions of NTSTATUS
29 are there in order to catch common coding errors where different error types
30 are mixed up. This is especially important as we slowly convert Samba
31 from using bool for internal functions
34 #if defined(HAVE_IMMEDIATE_STRUCTURES)
35 typedef struct {uint32_t v;} NTSTATUS;
36 #define NT_STATUS(x) ((NTSTATUS) { x })
37 #define NT_STATUS_V(x) ((x).v)
38 #else
39 typedef uint32_t NTSTATUS;
40 #define NT_STATUS(x) (x)
41 #define NT_STATUS_V(x) (x)
42 #endif
44 /* Win32 status codes. */
45 #define ERROR_INVALID_PARAMETER NT_STATUS(0x0057)
46 #define ERROR_INSUFFICIENT_BUFFER NT_STATUS(0x007a)
47 #define NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS NT_STATUS(0x2071)
48 #define NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION NT_STATUS(0x2177)
49 #define NT_STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP NT_STATUS(0xC05D0000)
51 /* Other error codes that aren't in the list we use */
52 #define NT_STATUS_OK NT_STATUS_SUCCESS
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 #define NT_STATUS_INACCESSIBLE_SYSTEM_SHORTCUT NT_STATUS(0x8000002d)
61 #define NT_STATUS_ABIOS_NOT_PRESENT NT_STATUS(0xC0000000 | 0x010f)
62 #define NT_STATUS_ABIOS_LID_NOT_EXIST NT_STATUS(0xC0000000 | 0x0110)
63 #define NT_STATUS_ABIOS_LID_ALREADY_OWNED NT_STATUS(0xC0000000 | 0x0111)
64 #define NT_STATUS_ABIOS_NOT_LID_OWNER NT_STATUS(0xC0000000 | 0x0112)
65 #define NT_STATUS_ABIOS_INVALID_COMMAND NT_STATUS(0xC0000000 | 0x0113)
66 #define NT_STATUS_ABIOS_INVALID_LID NT_STATUS(0xC0000000 | 0x0114)
67 #define NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE NT_STATUS(0xC0000000 | 0x0115)
68 #define NT_STATUS_ABIOS_INVALID_SELECTOR NT_STATUS(0xC0000000 | 0x0116)
70 #define NT_STATUS_HANDLE_NOT_WAITABLE NT_STATUS(0xC0000000 | 0x0036)
71 #define NT_STATUS_DEVICE_POWER_FAILURE NT_STATUS(0xC0000000 | 0x009e)
72 #define NT_STATUS_VHD_SHARED NT_STATUS(0xC05CFF0A)
73 #define NT_STATUS_SMB_BAD_CLUSTER_DIALECT NT_STATUS(0xC05D0001)
74 #define NT_STATUS_NO_SUCH_JOB NT_STATUS(0xC0000000 | 0xEDE)
77 --------------
78 / \
79 / REST \
80 / IN \
81 / PEACE \
82 / \
83 | NT_STATUS_NOPROBLEMO |
84 | |
85 | |
86 | 4 September |
87 | |
88 | 2001 |
89 *| * * * | *
90 _________)/\\_//(\/(/\)/\//\/\///|_)_______
93 /* I use NT_STATUS_FOOBAR when I have no idea what error code to use -
94 * this means we need a torture test */
95 #define NT_STATUS_FOOBAR NT_STATUS_UNSUCCESSFUL
97 /*****************************************************************************
98 returns an NT error message. not amazingly helpful, but better than a number.
99 *****************************************************************************/
100 const char *nt_errstr(NTSTATUS nt_code);
102 /************************************************************************
103 Print friendler version fo NT error code
104 ***********************************************************************/
105 const char *get_friendly_nt_error_msg(NTSTATUS nt_code);
107 /*****************************************************************************
108 returns an NT_STATUS constant as a string for inclusion in autogen C code
109 *****************************************************************************/
110 const char *get_nt_error_c_code(void *mem_ctx, NTSTATUS nt_code);
112 /*****************************************************************************
113 returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
114 *****************************************************************************/
115 NTSTATUS nt_status_string_to_code(const char *nt_status_str);
117 /* we need these here for openchange */
118 #ifndef likely
119 #define likely(x) (x)
120 #endif
121 #ifndef unlikely
122 #define unlikely(x) (x)
123 #endif
125 #define NT_STATUS_IS_OK(x) (likely(NT_STATUS_V(x) == 0))
126 #define NT_STATUS_IS_ERR(x) (unlikely((NT_STATUS_V(x) & 0xc0000000) == 0xc0000000))
127 #define NT_STATUS_EQUAL(x,y) (NT_STATUS_V(x) == NT_STATUS_V(y))
130 * These macros (with the embedded return) are considered poor coding
131 * style per README.Coding
133 * Please do not use them in new code, and do not rely on them in
134 * projects external to Samba as they will go away at some point.
137 #define NT_STATUS_HAVE_NO_MEMORY(x) do { \
138 if (unlikely(!(x))) { \
139 return NT_STATUS_NO_MEMORY;\
141 } while (0)
143 /* This varient is for when you want to free a local
144 temporary memory context in the error path */
145 #define NT_STATUS_HAVE_NO_MEMORY_AND_FREE(x, ctx) do { \
146 if (!(x)) {\
147 talloc_free(ctx); \
148 return NT_STATUS_NO_MEMORY;\
150 } while (0)
152 #define NT_STATUS_IS_OK_RETURN(x) do { \
153 if (NT_STATUS_IS_OK(x)) {\
154 return x;\
156 } while (0)
158 #define NT_STATUS_NOT_OK_RETURN(x) do { \
159 if (!NT_STATUS_IS_OK(x)) {\
160 return x;\
162 } while (0)
164 #define NT_STATUS_NOT_OK_RETURN_AND_FREE(x, ctx) do { \
165 if (!NT_STATUS_IS_OK(x)) {\
166 talloc_free(ctx); \
167 return x;\
169 } while (0)
171 #define NT_STATUS_IS_ERR_RETURN(x) do { \
172 if (NT_STATUS_IS_ERR(x)) {\
173 return x;\
175 } while (0)
177 #define NT_STATUS_NOT_ERR_RETURN(x) do { \
178 if (!NT_STATUS_IS_ERR(x)) {\
179 return x;\
181 } while (0)
183 /* this defines special NTSTATUS codes to represent DOS errors. I
184 have chosen this macro to produce status codes in the invalid
185 NTSTATUS range */
186 #define NT_STATUS_DOS(class, code) NT_STATUS(0xF1000000 | ((class)<<16) | code)
187 #define NT_STATUS_IS_DOS(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF1000000)
188 #define NT_STATUS_DOS_CLASS(status) ((NT_STATUS_V(status) >> 16) & 0xFF)
189 #define NT_STATUS_DOS_CODE(status) (NT_STATUS_V(status) & 0xFFFF)
191 /* define ldap error codes as NTSTATUS codes */
192 #define NT_STATUS_LDAP(code) NT_STATUS(0xF2000000 | code)
193 #define NT_STATUS_IS_LDAP(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF2000000)
194 #define NT_STATUS_LDAP_CODE(status) (NT_STATUS_V(status) & ~0xFF000000)
196 #define NT_STATUS_IS_RPC(status) \
197 (((NT_STATUS_V(status) & 0xFFFF) == 0xC0020000) || \
198 ((NT_STATUS_V(status) & 0xFFFF) == 0xC0030000))
200 #endif /* _NTSTATUS_H */