s3/libsmb: Fix typo in error message.
[Samba.git] / source / include / nt_status.h
blob30174e4b51904f9d2bab07e1150ffad63adaac05
1 /*
2 Unix SMB/CIFS implementation.
3 SMB parameters and setup, plus a whole lot more.
5 Copyright (C) Andrew Tridgell 2001
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _NT_STATUS_H
22 #define _NT_STATUS_H
24 /* The Splint code analysis tool doesn't like immediate structures. */
26 #ifdef _SPLINT_ /* http://www.splint.org */
27 #undef HAVE_IMMEDIATE_STRUCTURES
28 #endif
30 /* The following rather strange looking definitions of NTSTATUS and WERROR
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.
36 #if defined(HAVE_IMMEDIATE_STRUCTURES)
37 typedef struct {uint32 v;} NTSTATUS;
38 #define NT_STATUS(x) ((NTSTATUS) { x })
39 #define NT_STATUS_V(x) ((x).v)
40 #else
41 typedef uint32 NTSTATUS;
42 #define NT_STATUS(x) (x)
43 #define NT_STATUS_V(x) (x)
44 #endif
46 #if defined(HAVE_IMMEDIATE_STRUCTURES)
47 typedef struct {uint32 w;} WERROR;
48 #define W_ERROR(x) ((WERROR) { x })
49 #define W_ERROR_V(x) ((x).w)
50 #else
51 typedef uint32 WERROR;
52 #define W_ERROR(x) (x)
53 #define W_ERROR_V(x) (x)
54 #endif
56 #define NT_STATUS_IS_OK(x) (NT_STATUS_V(x) == 0)
57 #define NT_STATUS_IS_ERR(x) ((NT_STATUS_V(x) & 0xc0000000) == 0xc0000000)
58 #define NT_STATUS_EQUAL(x,y) (NT_STATUS_V(x) == NT_STATUS_V(y))
59 #define W_ERROR_IS_OK(x) (W_ERROR_V(x) == 0)
60 #define W_ERROR_EQUAL(x,y) (W_ERROR_V(x) == W_ERROR_V(y))
62 #define NT_STATUS_HAVE_NO_MEMORY(x) do { \
63 if (!(x)) {\
64 return NT_STATUS_NO_MEMORY;\
66 } while (0)
68 #define NT_STATUS_NOT_OK_RETURN(x) do { \
69 if (!NT_STATUS_IS_OK(x)) {\
70 return x;\
72 } while (0)
74 #define W_ERROR_HAVE_NO_MEMORY(x) do { \
75 if (!(x)) {\
76 return WERR_NOMEM;\
78 } while (0)
80 #define W_ERROR_NOT_OK_RETURN(x) do { \
81 if (!W_ERROR_IS_OK(x)) {\
82 return x;\
84 } while (0)
86 /* The top byte in an NTSTATUS code is used as a type field.
87 * Windows only uses value 0xC0 as an indicator for an NT error
88 * and 0x00 for success.
89 * So we can use the type field to store other types of error codes
90 * inside the three lower bytes.
91 * NB: The system error codes (errno) are not integrated via a type of
92 * their own but are mapped to genuine NT error codes via
93 * map_nt_error_from_unix() */
95 #define NT_STATUS_TYPE(status) ((NT_STATUS_V(status) & 0xFF000000) >> 24)
97 #define NT_STATUS_TYPE_DOS 0xF1
98 #define NT_STATUS_TYPE_LDAP 0xF2
100 /* this defines special NTSTATUS codes to represent DOS errors. I
101 have chosen this macro to produce status codes in the invalid
102 NTSTATUS range */
103 #define NT_STATUS_DOS_MASK (NT_STATUS_TYPE_DOS << 24)
104 #define NT_STATUS_DOS(class, code) NT_STATUS(NT_STATUS_DOS_MASK | ((class)<<16) | code)
105 #define NT_STATUS_IS_DOS(status) ((NT_STATUS_V(status) & 0xFF000000) == NT_STATUS_DOS_MASK)
106 #define NT_STATUS_DOS_CLASS(status) ((NT_STATUS_V(status) >> 16) & 0xFF)
107 #define NT_STATUS_DOS_CODE(status) (NT_STATUS_V(status) & 0xFFFF)
109 /* define ldap error codes as NTSTATUS codes */
110 #define NT_STATUS_LDAP_MASK (NT_STATUS_TYPE_LDAP << 24)
111 #define NT_STATUS_LDAP(code) NT_STATUS(NT_STATUS_LDAP_MASK | code)
112 #define NT_STATUS_IS_LDAP(status) ((NT_STATUS_V(status) & 0xFF000000) == NT_STATUS_LDAP_MASK)
113 #define NT_STATUS_LDAP_CODE(status) (NT_STATUS_V(status) & ~0xFF000000)
115 #endif