2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
5 * Copyright (C) Luke Kenneth Casson Leighton 1997-2001.
6 * Copyright (C) Andrew Bartlett
7 * Copyright (C) Andrew Tridgell
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 /* NT error codes. please read nterr.h */
26 #include "../libcli/ldap/ldap_errors.h"
30 #define N_(string) string
33 #define DOS_CODE(class, code) { #class ":" #code, NT_STATUS_DOS(class, code) }
34 #define LDAP_CODE(code) { #code, NT_STATUS_LDAP(code) }
38 const char *nt_errstr
;
42 #include "nterr_gen.c"
44 /* Errors which aren't in the generated code because they're not in the
45 * same table as the other ones. */
46 static const nt_err_code_struct special_errs
[] =
48 { "STATUS_NO_MORE_FILES", STATUS_NO_MORE_FILES
},
49 { "STATUS_INVALID_EA_NAME", STATUS_INVALID_EA_NAME
},
50 { "STATUS_BUFFER_OVERFLOW", STATUS_BUFFER_OVERFLOW
},
51 { "STATUS_MORE_ENTRIES", STATUS_MORE_ENTRIES
},
52 { "STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED
},
53 { "NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS", NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS
},
54 { "NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION", NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION
},
55 { "NT_STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP", NT_STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP
},
56 { "NT_STATUS_ABIOS_NOT_PRESENT", NT_STATUS_ABIOS_NOT_PRESENT
},
57 { "NT_STATUS_ABIOS_LID_NOT_EXIST", NT_STATUS_ABIOS_LID_NOT_EXIST
},
58 { "NT_STATUS_ABIOS_LID_ALREADY_OWNED", NT_STATUS_ABIOS_LID_ALREADY_OWNED
},
59 { "NT_STATUS_ABIOS_NOT_LID_OWNER", NT_STATUS_ABIOS_NOT_LID_OWNER
},
60 { "NT_STATUS_ABIOS_INVALID_COMMAND", NT_STATUS_ABIOS_INVALID_COMMAND
},
61 { "NT_STATUS_ABIOS_INVALID_LID", NT_STATUS_ABIOS_INVALID_LID
},
62 { "NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE", NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE
},
63 { "NT_STATUS_ABIOS_INVALID_SELECTOR", NT_STATUS_ABIOS_INVALID_SELECTOR
},
64 { "NT_STATUS_HANDLE_NOT_WAITABLE", NT_STATUS_HANDLE_NOT_WAITABLE
},
65 { "NT_STATUS_DEVICE_POWER_FAILURE", NT_STATUS_DEVICE_POWER_FAILURE
},
66 { "NT_STATUS_VHD_SHARED", NT_STATUS_VHD_SHARED
},
67 { "NT_STATUS_SMB_BAD_CLUSTER_DIALECT", NT_STATUS_SMB_BAD_CLUSTER_DIALECT
},
68 { "NT_STATUS_NO_SUCH_JOB", NT_STATUS_NO_SUCH_JOB
},
70 DOS_CODE(ERRDOS
, ERRsuccess
),
71 DOS_CODE(ERRDOS
, ERRbadfunc
),
72 DOS_CODE(ERRDOS
, ERRbadfile
),
73 DOS_CODE(ERRDOS
, ERRbadpath
),
74 DOS_CODE(ERRDOS
, ERRnofids
),
75 DOS_CODE(ERRDOS
, ERRnoaccess
),
76 DOS_CODE(ERRDOS
, ERRbadfid
),
77 DOS_CODE(ERRDOS
, ERRbadmcb
),
78 DOS_CODE(ERRDOS
, ERRnomem
),
79 DOS_CODE(ERRDOS
, ERRbadmem
),
80 DOS_CODE(ERRDOS
, ERRbadenv
),
81 DOS_CODE(ERRDOS
, ERRbadaccess
),
82 DOS_CODE(ERRDOS
, ERRbaddata
),
83 DOS_CODE(ERRDOS
, ERRres
),
84 DOS_CODE(ERRDOS
, ERRbaddrive
),
85 DOS_CODE(ERRDOS
, ERRremcd
),
86 DOS_CODE(ERRDOS
, ERRdiffdevice
),
87 DOS_CODE(ERRDOS
, ERRnofiles
),
88 DOS_CODE(ERRDOS
, ERRgeneral
),
89 DOS_CODE(ERRDOS
, ERRbadshare
),
90 DOS_CODE(ERRDOS
, ERRlock
),
91 DOS_CODE(ERRDOS
, ERRunsup
),
92 DOS_CODE(ERRDOS
, ERRnetnamedel
),
93 DOS_CODE(ERRDOS
, ERRnosuchshare
),
94 DOS_CODE(ERRDOS
, ERRfilexists
),
95 DOS_CODE(ERRDOS
, ERRinvalidparam
),
96 DOS_CODE(ERRDOS
, ERRcannotopen
),
97 DOS_CODE(ERRDOS
, ERRinsufficientbuffer
),
98 DOS_CODE(ERRDOS
, ERRinvalidname
),
99 DOS_CODE(ERRDOS
, ERRunknownlevel
),
100 DOS_CODE(ERRDOS
, ERRnotlocked
),
101 DOS_CODE(ERRDOS
, ERRinvalidpath
),
102 DOS_CODE(ERRDOS
, ERRcancelviolation
),
103 DOS_CODE(ERRDOS
, ERRnoatomiclocks
),
104 DOS_CODE(ERRDOS
, ERRrename
),
105 DOS_CODE(ERRDOS
, ERRbadpipe
),
106 DOS_CODE(ERRDOS
, ERRpipebusy
),
107 DOS_CODE(ERRDOS
, ERRpipeclosing
),
108 DOS_CODE(ERRDOS
, ERRnotconnected
),
109 DOS_CODE(ERRDOS
, ERRmoredata
),
110 DOS_CODE(ERRDOS
, ERRnomoreitems
),
111 DOS_CODE(ERRDOS
, ERRbaddirectory
),
112 DOS_CODE(ERRDOS
, ERReasnotsupported
),
113 DOS_CODE(ERRDOS
, ERRlogonfailure
),
114 DOS_CODE(ERRDOS
, ERRbuftoosmall
),
115 DOS_CODE(ERRDOS
, ERRunknownipc
),
116 DOS_CODE(ERRDOS
, ERRnosuchprintjob
),
117 DOS_CODE(ERRDOS
, ERRinvgroup
),
118 DOS_CODE(ERRDOS
, ERRnoipc
),
119 DOS_CODE(ERRDOS
, ERRdriveralreadyinstalled
),
120 DOS_CODE(ERRDOS
, ERRunknownprinterport
),
121 DOS_CODE(ERRDOS
, ERRunknownprinterdriver
),
122 DOS_CODE(ERRDOS
, ERRunknownprintprocessor
),
123 DOS_CODE(ERRDOS
, ERRinvalidseparatorfile
),
124 DOS_CODE(ERRDOS
, ERRinvalidjobpriority
),
125 DOS_CODE(ERRDOS
, ERRinvalidprintername
),
126 DOS_CODE(ERRDOS
, ERRprinteralreadyexists
),
127 DOS_CODE(ERRDOS
, ERRinvalidprintercommand
),
128 DOS_CODE(ERRDOS
, ERRinvaliddatatype
),
129 DOS_CODE(ERRDOS
, ERRinvalidenvironment
),
130 DOS_CODE(ERRDOS
, ERRunknownprintmonitor
),
131 DOS_CODE(ERRDOS
, ERRprinterdriverinuse
),
132 DOS_CODE(ERRDOS
, ERRspoolfilenotfound
),
133 DOS_CODE(ERRDOS
, ERRnostartdoc
),
134 DOS_CODE(ERRDOS
, ERRnoaddjob
),
135 DOS_CODE(ERRDOS
, ERRprintprocessoralreadyinstalled
),
136 DOS_CODE(ERRDOS
, ERRprintmonitoralreadyinstalled
),
137 DOS_CODE(ERRDOS
, ERRinvalidprintmonitor
),
138 DOS_CODE(ERRDOS
, ERRprintmonitorinuse
),
139 DOS_CODE(ERRDOS
, ERRprinterhasjobsqueued
),
140 DOS_CODE(ERRDOS
, ERReainconsistent
),
142 DOS_CODE(ERRSRV
, ERRerror
),
143 DOS_CODE(ERRSRV
, ERRbadpw
),
144 DOS_CODE(ERRSRV
, ERRbadtype
),
145 DOS_CODE(ERRSRV
, ERRaccess
),
146 DOS_CODE(ERRSRV
, ERRinvnid
),
147 DOS_CODE(ERRSRV
, ERRinvnetname
),
148 DOS_CODE(ERRSRV
, ERRinvdevice
),
149 DOS_CODE(ERRSRV
, ERRqfull
),
150 DOS_CODE(ERRSRV
, ERRqtoobig
),
151 DOS_CODE(ERRSRV
, ERRinvpfid
),
152 DOS_CODE(ERRSRV
, ERRsmbcmd
),
153 DOS_CODE(ERRSRV
, ERRsrverror
),
154 DOS_CODE(ERRSRV
, ERRfilespecs
),
155 DOS_CODE(ERRSRV
, ERRbadlink
),
156 DOS_CODE(ERRSRV
, ERRbadpermits
),
157 DOS_CODE(ERRSRV
, ERRbadpid
),
158 DOS_CODE(ERRSRV
, ERRsetattrmode
),
159 DOS_CODE(ERRSRV
, ERRpaused
),
160 DOS_CODE(ERRSRV
, ERRmsgoff
),
161 DOS_CODE(ERRSRV
, ERRnoroom
),
162 DOS_CODE(ERRSRV
, ERRrmuns
),
163 DOS_CODE(ERRSRV
, ERRtimeout
),
164 DOS_CODE(ERRSRV
, ERRnoresource
),
165 DOS_CODE(ERRSRV
, ERRtoomanyuids
),
166 DOS_CODE(ERRSRV
, ERRbaduid
),
167 DOS_CODE(ERRSRV
, ERRuseMPX
),
168 DOS_CODE(ERRSRV
, ERRuseSTD
),
169 DOS_CODE(ERRSRV
, ERRcontMPX
),
170 DOS_CODE(ERRSRV
, ERRnosupport
),
171 DOS_CODE(ERRSRV
, ERRunknownsmb
),
173 DOS_CODE(ERRHRD
, ERRnowrite
),
174 DOS_CODE(ERRHRD
, ERRbadunit
),
175 DOS_CODE(ERRHRD
, ERRnotready
),
176 DOS_CODE(ERRHRD
, ERRbadcmd
),
177 DOS_CODE(ERRHRD
, ERRdata
),
178 DOS_CODE(ERRHRD
, ERRbadreq
),
179 DOS_CODE(ERRHRD
, ERRseek
),
180 DOS_CODE(ERRHRD
, ERRbadmedia
),
181 DOS_CODE(ERRHRD
, ERRbadsector
),
182 DOS_CODE(ERRHRD
, ERRnopaper
),
183 DOS_CODE(ERRHRD
, ERRwrite
),
184 DOS_CODE(ERRHRD
, ERRread
),
185 DOS_CODE(ERRHRD
, ERRgeneral
),
186 DOS_CODE(ERRHRD
, ERRwrongdisk
),
187 DOS_CODE(ERRHRD
, ERRFCBunavail
),
188 DOS_CODE(ERRHRD
, ERRsharebufexc
),
189 DOS_CODE(ERRHRD
, ERRdiskfull
),
191 LDAP_CODE(LDAP_SUCCESS
),
192 LDAP_CODE(LDAP_OPERATIONS_ERROR
),
193 LDAP_CODE(LDAP_PROTOCOL_ERROR
),
194 LDAP_CODE(LDAP_TIME_LIMIT_EXCEEDED
),
195 LDAP_CODE(LDAP_SIZE_LIMIT_EXCEEDED
),
196 LDAP_CODE(LDAP_COMPARE_FALSE
),
197 LDAP_CODE(LDAP_COMPARE_TRUE
),
198 LDAP_CODE(LDAP_AUTH_METHOD_NOT_SUPPORTED
),
199 LDAP_CODE(LDAP_STRONG_AUTH_REQUIRED
),
200 LDAP_CODE(LDAP_REFERRAL
),
201 LDAP_CODE(LDAP_ADMIN_LIMIT_EXCEEDED
),
202 LDAP_CODE(LDAP_UNAVAILABLE_CRITICAL_EXTENSION
),
203 LDAP_CODE(LDAP_CONFIDENTIALITY_REQUIRED
),
204 LDAP_CODE(LDAP_SASL_BIND_IN_PROGRESS
),
205 LDAP_CODE(LDAP_NO_SUCH_ATTRIBUTE
),
206 LDAP_CODE(LDAP_UNDEFINED_ATTRIBUTE_TYPE
),
207 LDAP_CODE(LDAP_INAPPROPRIATE_MATCHING
),
208 LDAP_CODE(LDAP_CONSTRAINT_VIOLATION
),
209 LDAP_CODE(LDAP_ATTRIBUTE_OR_VALUE_EXISTS
),
210 LDAP_CODE(LDAP_INVALID_ATTRIBUTE_SYNTAX
),
211 LDAP_CODE(LDAP_NO_SUCH_OBJECT
),
212 LDAP_CODE(LDAP_ALIAS_PROBLEM
),
213 LDAP_CODE(LDAP_INVALID_DN_SYNTAX
),
214 LDAP_CODE(LDAP_ALIAS_DEREFERENCING_PROBLEM
),
215 LDAP_CODE(LDAP_INAPPROPRIATE_AUTHENTICATION
),
216 LDAP_CODE(LDAP_INVALID_CREDENTIALS
),
217 LDAP_CODE(LDAP_INSUFFICIENT_ACCESS_RIGHTS
),
218 LDAP_CODE(LDAP_BUSY
),
219 LDAP_CODE(LDAP_UNAVAILABLE
),
220 LDAP_CODE(LDAP_UNWILLING_TO_PERFORM
),
221 LDAP_CODE(LDAP_LOOP_DETECT
),
222 LDAP_CODE(LDAP_NAMING_VIOLATION
),
223 LDAP_CODE(LDAP_OBJECT_CLASS_VIOLATION
),
224 LDAP_CODE(LDAP_NOT_ALLOWED_ON_NON_LEAF
),
225 LDAP_CODE(LDAP_NOT_ALLOWED_ON_RDN
),
226 LDAP_CODE(LDAP_ENTRY_ALREADY_EXISTS
),
227 LDAP_CODE(LDAP_OBJECT_CLASS_MODS_PROHIBITED
),
228 LDAP_CODE(LDAP_AFFECTS_MULTIPLE_DSAS
),
229 LDAP_CODE(LDAP_OTHER
),
231 { NULL
, NT_STATUS(0) }
234 /*****************************************************************************
235 Returns an NT_STATUS constant as a string for inclusion in autogen C code.
236 *****************************************************************************/
238 const char *get_nt_error_c_code(TALLOC_CTX
*mem_ctx
, NTSTATUS nt_code
)
243 while (special_errs
[idx
].nt_errstr
!= NULL
) {
244 if (NT_STATUS_V(special_errs
[idx
].nt_errcode
) ==
245 NT_STATUS_V(nt_code
)) {
246 result
= talloc_strdup(mem_ctx
, special_errs
[idx
].nt_errstr
);
254 while (nt_errs
[idx
].nt_errstr
!= NULL
) {
255 if (NT_STATUS_V(nt_errs
[idx
].nt_errcode
) ==
256 NT_STATUS_V(nt_code
)) {
257 result
= talloc_strdup(mem_ctx
, nt_errs
[idx
].nt_errstr
);
263 result
= talloc_asprintf(mem_ctx
, "NT_STATUS(0x%08x)",
264 NT_STATUS_V(nt_code
));
268 /*****************************************************************************
269 Returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
270 *****************************************************************************/
272 NTSTATUS
nt_status_string_to_code(const char *nt_status_str
)
276 while (special_errs
[idx
].nt_errstr
!= NULL
) {
277 if (strcasecmp(special_errs
[idx
].nt_errstr
, nt_status_str
) == 0) {
278 return special_errs
[idx
].nt_errcode
;
285 while (nt_errs
[idx
].nt_errstr
!= NULL
) {
286 if (strcasecmp(nt_errs
[idx
].nt_errstr
, nt_status_str
) == 0) {
287 return nt_errs
[idx
].nt_errcode
;
292 return NT_STATUS_UNSUCCESSFUL
;
296 * Squash an NT_STATUS in line with security requirements.
297 * In an attempt to avoid giving the whole game away when users
298 * are authenticating, NT replaces both NT_STATUS_NO_SUCH_USER and
299 * NT_STATUS_WRONG_PASSWORD with NT_STATUS_LOGON_FAILURE in certain situations
300 * (session setups in particular).
302 * @param nt_status NTSTATUS input for squashing.
303 * @return the 'squashed' nt_status
306 NTSTATUS
nt_status_squash(NTSTATUS nt_status
)
308 if NT_STATUS_IS_OK(nt_status
) {
310 } else if NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_SUCH_USER
) {
311 /* Match WinXP and don't give the game away */
312 return NT_STATUS_LOGON_FAILURE
;
314 } else if NT_STATUS_EQUAL(nt_status
, NT_STATUS_WRONG_PASSWORD
) {
315 /* Match WinXP and don't give the game away */
316 return NT_STATUS_LOGON_FAILURE
;
322 /*****************************************************************************
323 Returns an NT error message. not amazingly helpful, but better than a number.
324 *****************************************************************************/
326 const char *nt_errstr(NTSTATUS nt_code
)
331 while (special_errs
[idx
].nt_errstr
!= NULL
) {
332 if (NT_STATUS_V(special_errs
[idx
].nt_errcode
) ==
333 NT_STATUS_V(nt_code
)) {
334 return special_errs
[idx
].nt_errstr
;
341 while (nt_errs
[idx
].nt_errstr
!= NULL
) {
342 if (NT_STATUS_V(nt_errs
[idx
].nt_errcode
) ==
343 NT_STATUS_V(nt_code
)) {
344 return nt_errs
[idx
].nt_errstr
;
350 * This should not really happen, we should have all error codes
351 * available. We have a problem that this might get wrongly
352 * overwritten by later calls in the same DEBUG statement.
355 snprintf(msg
, sizeof(msg
), "NT code 0x%08x", NT_STATUS_V(nt_code
));
359 /************************************************************************
360 Print friendlier version of NT error code
361 ***********************************************************************/
363 const char *get_friendly_nt_error_msg(NTSTATUS nt_code
)
367 while (nt_err_desc
[idx
].nt_errstr
!= NULL
) {
368 if (NT_STATUS_V(nt_err_desc
[idx
].nt_errcode
) == NT_STATUS_V(nt_code
)) {
369 return nt_err_desc
[idx
].nt_errstr
;
374 /* fall back to NT_STATUS_XXX string */
376 return nt_errstr(nt_code
);