libcli: Remove define for STATUS_INVALID_EA_FLAG
[samba.git] / libcli / util / ntstatus.h
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 "libcli/util/ntstatus_gen.h"
27
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 
32 */
33
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
43
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)
50
51 /* Other error codes that aren't in the list we use */
52 #define NT_STATUS_OK                      NT_STATUS_SUCCESS
53
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 STATUS_NOTIFY_CLEANUP             NT_STATUS_NOTIFY_CLEANUP
60 #define STATUS_NOTIFY_ENUM_DIR            NT_STATUS_NOTIFY_ENUM_DIR
61 #define STATUS_PENDING                    NT_STATUS_PENDING
62 #define STATUS_STOPPED_ON_SYMLINK         NT_STATUS_STOPPED_ON_SYMLINK
63 #define STATUS_EA_LIST_INCONSISTENT       NT_STATUS_EA_LIST_INCONSISTENT
64 #define NT_STATUS_INACCESSIBLE_SYSTEM_SHORTCUT          NT_STATUS(0x8000002d)
65
66 #define NT_STATUS_ABIOS_NOT_PRESENT             NT_STATUS(0xC0000000 | 0x010f)
67 #define NT_STATUS_ABIOS_LID_NOT_EXIST           NT_STATUS(0xC0000000 | 0x0110)
68 #define NT_STATUS_ABIOS_LID_ALREADY_OWNED       NT_STATUS(0xC0000000 | 0x0111)
69 #define NT_STATUS_ABIOS_NOT_LID_OWNER           NT_STATUS(0xC0000000 | 0x0112)
70 #define NT_STATUS_ABIOS_INVALID_COMMAND         NT_STATUS(0xC0000000 | 0x0113)
71 #define NT_STATUS_ABIOS_INVALID_LID             NT_STATUS(0xC0000000 | 0x0114)
72 #define NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE  NT_STATUS(0xC0000000 | 0x0115)
73 #define NT_STATUS_ABIOS_INVALID_SELECTOR        NT_STATUS(0xC0000000 | 0x0116)
74
75 #define NT_STATUS_HANDLE_NOT_WAITABLE           NT_STATUS(0xC0000000 | 0x0036)
76 #define NT_STATUS_DEVICE_POWER_FAILURE          NT_STATUS(0xC0000000 | 0x009e)
77 #define NT_STATUS_VHD_SHARED                    NT_STATUS(0xC05CFF0A)
78 #define NT_STATUS_SMB_BAD_CLUSTER_DIALECT       NT_STATUS(0xC05D0001)
79 #define NT_STATUS_NO_SUCH_JOB                   NT_STATUS(0xC0000000 | 0xEDE)
80
81 /*
82                        --------------
83                       /              \
84                      /      REST      \
85                     /        IN        \
86                    /       PEACE        \
87                   /                      \
88                   | NT_STATUS_NOPROBLEMO |
89                   |                      |
90                   |                      |
91                   |      4 September     |
92                   |                      |
93                   |         2001         |
94                  *|     *  *  *          | *
95         _________)/\\_//(\/(/\)/\//\/\///|_)_______
96 */
97
98 /* I use NT_STATUS_FOOBAR when I have no idea what error code to use -
99  * this means we need a torture test */
100 #define NT_STATUS_FOOBAR NT_STATUS_UNSUCCESSFUL
101
102 /*****************************************************************************
103  returns an NT error message.  not amazingly helpful, but better than a number.
104  *****************************************************************************/
105 const char *nt_errstr(NTSTATUS nt_code);
106
107 /************************************************************************
108  Print friendler version fo NT error code
109  ***********************************************************************/
110 const char *get_friendly_nt_error_msg(NTSTATUS nt_code);
111
112 /*****************************************************************************
113  returns an NT_STATUS constant as a string for inclusion in autogen C code
114  *****************************************************************************/
115 const char *get_nt_error_c_code(void *mem_ctx, NTSTATUS nt_code);
116
117 /*****************************************************************************
118  returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
119  *****************************************************************************/
120 NTSTATUS nt_status_string_to_code(const char *nt_status_str);
121
122 /* we need these here for openchange */
123 #ifndef likely
124 #define likely(x) (x)
125 #endif
126 #ifndef unlikely
127 #define unlikely(x) (x)
128 #endif
129
130 #define NT_STATUS_IS_OK(x) (likely(NT_STATUS_V(x) == 0))
131 #define NT_STATUS_IS_ERR(x) (unlikely((NT_STATUS_V(x) & 0xc0000000) == 0xc0000000))
132 #define NT_STATUS_EQUAL(x,y) (NT_STATUS_V(x) == NT_STATUS_V(y))
133
134 /*
135  * These macros (with the embedded return) are considered poor coding
136  * style per README.Coding
137  *
138  * Please do not use them in new code, and do not rely on them in
139  * projects external to Samba as they will go away at some point.
140  */
141
142 #define NT_STATUS_HAVE_NO_MEMORY(x) do { \
143         if (unlikely(!(x))) {           \
144                 return NT_STATUS_NO_MEMORY;\
145         }\
146 } while (0)
147
148 /* This varient is for when you want to free a local
149    temporary memory context in the error path */
150 #define NT_STATUS_HAVE_NO_MEMORY_AND_FREE(x, ctx) do {  \
151         if (!(x)) {\
152                 talloc_free(ctx); \
153                 return NT_STATUS_NO_MEMORY;\
154         }\
155 } while (0)
156
157 #define NT_STATUS_IS_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(x) do { \
164         if (!NT_STATUS_IS_OK(x)) {\
165                 return x;\
166         }\
167 } while (0)
168
169 #define NT_STATUS_NOT_OK_RETURN_AND_FREE(x, ctx) do {   \
170         if (!NT_STATUS_IS_OK(x)) {\
171                 talloc_free(ctx); \
172                 return x;\
173         }\
174 } while (0)
175
176 #define NT_STATUS_IS_ERR_RETURN(x) do { \
177         if (NT_STATUS_IS_ERR(x)) {\
178                 return x;\
179         }\
180 } while (0)
181
182 #define NT_STATUS_NOT_ERR_RETURN(x) do { \
183         if (!NT_STATUS_IS_ERR(x)) {\
184                 return x;\
185         }\
186 } while (0)
187
188 /* this defines special NTSTATUS codes to represent DOS errors.  I
189    have chosen this macro to produce status codes in the invalid
190    NTSTATUS range */
191 #define NT_STATUS_DOS(class, code) NT_STATUS(0xF1000000 | ((class)<<16) | code)
192 #define NT_STATUS_IS_DOS(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF1000000)
193 #define NT_STATUS_DOS_CLASS(status) ((NT_STATUS_V(status) >> 16) & 0xFF)
194 #define NT_STATUS_DOS_CODE(status) (NT_STATUS_V(status) & 0xFFFF)
195
196 /* define ldap error codes as NTSTATUS codes */
197 #define NT_STATUS_LDAP(code) NT_STATUS(0xF2000000 | code)
198 #define NT_STATUS_IS_LDAP(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF2000000)
199 #define NT_STATUS_LDAP_CODE(status) (NT_STATUS_V(status) & ~0xFF000000)
200
201 #define NT_STATUS_IS_RPC(status) \
202         (((NT_STATUS_V(status) & 0xFFFF) == 0xC0020000) || \
203          ((NT_STATUS_V(status) & 0xFFFF) == 0xC0030000))
204
205 #endif /* _NTSTATUS_H */