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