xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
1 /*
2  * Copyright (c) 2000-2001 Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: smb_subr.c,v 1.27.108.1 2005/06/02 00:55:39 lindak Exp $
33  */
34 
35 /*
36  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37  * Portions Copyright (C) 2001 - 2013 Apple Inc. All rights reserved.
38  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
39  */
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kmem.h>
44 #include <sys/proc.h>
45 #include <sys/lock.h>
46 #include <sys/socket.h>
47 #include <sys/isa_defs.h>
48 #include <sys/stream.h>
49 #include <sys/strsun.h>
50 #include <sys/sunddi.h>
51 #include <sys/cmn_err.h>
52 #include <sys/sdt.h>
53 #include <sys/priv.h>
54 #include <sys/u8_textprep.h>
55 
56 #include <netsmb/smb_osdep.h>
57 #include <netsmb/smb.h>
58 #include <netsmb/smb_conn.h>
59 #include <netsmb/smb_rq.h>
60 #include <netsmb/smb_subr.h>
61 
62 void
63 smb_credinit(struct smb_cred *scred, cred_t *cr)
64 {
65 	/* cr arg is optional */
66 	if (cr == NULL)
67 		cr = ddi_get_cred();
68 #ifdef	_KERNEL
69 	if (is_system_labeled()) {
70 		cr = crdup(cr);
71 		(void) setpflags(NET_MAC_AWARE, 1, cr);
72 	} else
73 #endif
74 	{
75 		crhold(cr);
76 	}
77 	scred->scr_cred = cr;
78 }
79 
80 void
81 smb_credrele(struct smb_cred *scred)
82 {
83 	if (scred->scr_cred != NULL) {
84 		crfree(scred->scr_cred);
85 		scred->scr_cred = NULL;
86 	}
87 }
88 
89 #ifndef	_KERNEL
90 /* ARGSUSED */
91 void
92 smb_debugmsg(const char *func, char *msg)
93 {
94 }
95 #endif	/* _KERNEL */
96 
97 /*
98  * Helper for the SMBERROR macro, etc.
99  * This is also a good place for a breakpoint
100  * or a dtrace probe, i.e. fbt:nsmb:smb_errmsg
101  */
102 void
103 smb_errmsg(int cel, const char *func_name, const char *fmt, ...)
104 {
105 	va_list adx;
106 	char buf[100];
107 
108 	va_start(adx, fmt);
109 	if (cel == CE_CONT) {
110 		/*
111 		 * This is one of our xxxDEBUG macros.
112 		 * Don't bother to log these, but just
113 		 * fire a dtrace probe with the message.
114 		 */
115 		(void) vsnprintf(buf, sizeof (buf), fmt, adx);
116 		DTRACE_PROBE2(debugmsg2,
117 		    (char *), func_name,
118 		    (char *), buf);
119 #ifndef	_KERNEL
120 		smb_debugmsg(func_name, buf);
121 #endif
122 	} else {
123 		/*
124 		 * This is one of our xxxERROR macros.
125 		 * Add a prefix to the fmt string,
126 		 * then let vcmn_err do the args.
127 		 */
128 		(void) snprintf(buf, sizeof (buf), "?%s: %s", func_name, fmt);
129 		DTRACE_PROBE3(debugmsg3,
130 		    (char *), func_name,
131 		    (char *), buf,
132 		    va_list, adx);
133 		vcmn_err(cel, buf, adx);
134 	}
135 	va_end(adx);
136 }
137 
138 #if 1 /* def SMB_SOCKETDATA_DEBUG */
139 void
140 m_dumpm(mblk_t *m)
141 {
142 	int len, seg;
143 
144 	len = msgdsize(m);
145 	DTRACE_PROBE2(dsize, int, len, (mblk_t *), m);
146 
147 	for (seg = 0; m; seg++) {
148 		DTRACE_PROBE2(mblk, int, seg, (mblk_t *), m);
149 		m = m->b_cont;
150 	}
151 }
152 #endif
153 
154 #ifndef EPROTO
155 #define	EPROTO ECONNABORTED
156 #endif
157 #ifndef ELIBACC
158 #define	ELIBACC ENOENT
159 #endif
160 #ifndef ENODATA
161 #define	ENODATA EINVAL
162 #endif
163 #ifndef ENOTUNIQ
164 #define	ENOTUNIQ EADDRINUSE
165 #endif
166 #ifndef ECOMM
167 #define	ECOMM EIO
168 #endif
169 #ifndef ENOMEDIUM
170 #define	ENOMEDIUM ENXIO
171 #endif
172 #ifndef ETIME
173 #define	ETIME ETIMEDOUT
174 #endif
175 #ifndef	EMOREDATA
176 #define	EMOREDATA (0x7fff)
177 #endif
178 
179 /*
180  * Log any un-handled NT or DOS errors we encounter.
181  * Make these log NOTICE in a debug build to ensure
182  * they get noticed during tests.  In the field these
183  * are unimportant, so just fire a Dtrace probe.
184  */
185 static int unknown_err_logpri =
186 #ifdef	DEBUG
187 	CE_NOTE;
188 #else
189 	CE_CONT;
190 #endif
191 
192 typedef struct nt2errno {
193 	unsigned int nterr;
194 	int errno;
195 } nt2errno_t;
196 
197 static const nt2errno_t nt2errno[] = {
198 	/* Alphabetical order. */
199 	{NT_STATUS_ACCESS_DENIED,		EACCES},
200 	{NT_STATUS_ACCESS_VIOLATION,		EACCES},
201 	{NT_STATUS_ACCOUNT_DISABLED,		EACCES},
202 	{NT_STATUS_ACCOUNT_EXPIRED,		EACCES},
203 	{NT_STATUS_ACCOUNT_LOCKED_OUT,		EACCES},
204 	{NT_STATUS_ACCOUNT_RESTRICTION,		EACCES},
205 	{NT_STATUS_ADDRESS_ALREADY_EXISTS,	EADDRINUSE},
206 	{NT_STATUS_BAD_NETWORK_NAME,		ENOENT},
207 	{NT_STATUS_BAD_NETWORK_PATH,		ENOENT},
208 	{NT_STATUS_BUFFER_TOO_SMALL,		E2BIG},
209 	{NT_STATUS_CANCELLED,			ECANCELED},
210 	{NT_STATUS_CANNOT_DELETE,		EACCES},
211 	{NT_STATUS_CONFLICTING_ADDRESSES,	EADDRINUSE},
212 	{NT_STATUS_CONNECTION_ABORTED,		ECONNABORTED},
213 	{NT_STATUS_CONNECTION_DISCONNECTED,	ECONNABORTED},
214 	{NT_STATUS_CONNECTION_REFUSED,		ECONNREFUSED},
215 	{NT_STATUS_CONNECTION_RESET,		ENETRESET},
216 	{NT_STATUS_DELETE_PENDING,		EACCES},
217 	{NT_STATUS_DEVICE_DOES_NOT_EXIST,	ENODEV},
218 	{NT_STATUS_DEVICE_PROTOCOL_ERROR,	EPROTO},
219 	{NT_STATUS_DIRECTORY_NOT_EMPTY,		ENOTEMPTY},
220 	{NT_STATUS_DISK_FULL,			ENOSPC},
221 	{NT_STATUS_DLL_NOT_FOUND,		ELIBACC},
222 	{NT_STATUS_DUPLICATE_NAME,		EINVAL},
223 	{NT_STATUS_EAS_NOT_SUPPORTED,		ENOTSUP},
224 	{NT_STATUS_EA_TOO_LARGE,		E2BIG},
225 	{NT_STATUS_END_OF_FILE,			ENODATA},
226 	{NT_STATUS_FILE_CLOSED,			EBADF},
227 	{NT_STATUS_FILE_DELETED,		ENOENT},
228 	{NT_STATUS_FILE_INVALID,		EIO},
229 	{NT_STATUS_FILE_IS_A_DIRECTORY,		EISDIR},
230 	{NT_STATUS_FILE_LOCK_CONFLICT,		EAGAIN},
231 	{NT_STATUS_FILE_RENAMED,		ENOENT},
232 	{NT_STATUS_FLOAT_INEXACT_RESULT,	ERANGE},
233 	{NT_STATUS_FLOAT_OVERFLOW,		ERANGE},
234 	{NT_STATUS_FLOAT_UNDERFLOW,		ERANGE},
235 	{NT_STATUS_HOST_UNREACHABLE,		EHOSTUNREACH},
236 	{NT_STATUS_ILL_FORMED_PASSWORD,		EAUTH},
237 	{NT_STATUS_INFO_LENGTH_MISMATCH,	EINVAL},
238 	{NT_STATUS_INSUFFICIENT_RESOURCES,	EAGAIN},
239 	{NT_STATUS_INSUFF_SERVER_RESOURCES,	EAGAIN},
240 	{NT_STATUS_INTEGER_OVERFLOW,		ERANGE},
241 	{NT_STATUS_INVALID_ACCOUNT_NAME,	EAUTH},
242 	{NT_STATUS_INVALID_BUFFER_SIZE,		EIO},
243 	{NT_STATUS_INVALID_DEVICE_REQUEST,	EINVAL},
244 	{NT_STATUS_INVALID_HANDLE,		EBADF},
245 	{NT_STATUS_INVALID_INFO_CLASS,		EINVAL},
246 	{NT_STATUS_INVALID_LEVEL,		ENOTSUP},
247 	{NT_STATUS_INVALID_LOCK_SEQUENCE,	EINVAL},
248 	{NT_STATUS_INVALID_LOGON_HOURS,		EAUTH},
249 	{NT_STATUS_INVALID_OWNER,		EINVAL},
250 	{NT_STATUS_INVALID_PARAMETER,		EINVAL},
251 	{NT_STATUS_INVALID_PIPE_STATE,		EPIPE},
252 	{NT_STATUS_INVALID_PRIMARY_GROUP,	EINVAL},
253 	{NT_STATUS_INVALID_WORKSTATION,		EACCES},
254 	{NT_STATUS_IN_PAGE_ERROR,		EFAULT},
255 	{NT_STATUS_IO_DEVICE_ERROR,		EIO},
256 	{NT_STATUS_IO_TIMEOUT,			ETIMEDOUT},
257 	{NT_STATUS_IP_ADDRESS_CONFLICT1,	EADDRINUSE},
258 	{NT_STATUS_IP_ADDRESS_CONFLICT2,	EADDRINUSE},
259 	{NT_STATUS_LICENSE_QUOTA_EXCEEDED,	EDQUOT},
260 	{NT_STATUS_LOCK_NOT_GRANTED,		EAGAIN},
261 	{NT_STATUS_LOGIN_TIME_RESTRICTION,	EAUTH},
262 	{NT_STATUS_LOGON_FAILURE,		EAUTH},
263 	{NT_STATUS_LOGON_TYPE_NOT_GRANTED,	EAUTH},
264 	{NT_STATUS_MEDIA_WRITE_PROTECTED,	EROFS},
265 	{NT_STATUS_MEMORY_NOT_ALLOCATED,	EFAULT},
266 	{NT_STATUS_MORE_PROCESSING_REQUIRED,	EINPROGRESS},
267 	{NT_STATUS_NAME_TOO_LONG,		ENAMETOOLONG},
268 	{NT_STATUS_NETWORK_ACCESS_DENIED,	EACCES},
269 	{NT_STATUS_NETWORK_BUSY,		EBUSY},
270 	{NT_STATUS_NETWORK_NAME_DELETED,	ENOENT},
271 	{NT_STATUS_NETWORK_UNREACHABLE,		ENETUNREACH},
272 	{NT_STATUS_NET_WRITE_FAULT,		ECOMM},
273 	{NT_STATUS_NONEXISTENT_EA_ENTRY,	ENOENT},
274 	{NT_STATUS_NONEXISTENT_SECTOR,		ESPIPE},
275 	{NT_STATUS_NONE_MAPPED,			EINVAL},
276 	{NT_STATUS_NOT_A_DIRECTORY,		ENOTDIR},
277 	{NT_STATUS_NOT_FOUND,			ENOENT},
278 	{NT_STATUS_NOT_IMPLEMENTED,		ENOTSUP},
279 	{NT_STATUS_NOT_LOCKED,			ENOLCK},
280 	{NT_STATUS_NOT_MAPPED_VIEW,		EINVAL},
281 	{NT_STATUS_NOT_SUPPORTED,		ENOTSUP},
282 	{NT_STATUS_NO_EAS_ON_FILE,		ENOENT},
283 	{NT_STATUS_NO_LOGON_SERVERS,		EAUTH},
284 	{NT_STATUS_NO_MEDIA,			ENOMEDIUM},
285 	{NT_STATUS_NO_MEDIA_IN_DEVICE,		ENOMEDIUM},
286 	{NT_STATUS_NO_MEMORY,			ENOMEM},
287 	{NT_STATUS_NO_SUCH_DEVICE,		ENODEV},
288 	{NT_STATUS_NO_SUCH_FILE,		ENOENT},
289 	{NT_STATUS_NO_SUCH_LOGON_SESSION,	EAUTH},
290 	{NT_STATUS_NO_SUCH_USER,		EAUTH},
291 	{NT_STATUS_NO_TRUST_LSA_SECRET,		EAUTH},
292 	{NT_STATUS_NO_TRUST_SAM_ACCOUNT,	EAUTH},
293 	{NT_STATUS_OBJECT_NAME_COLLISION,	EEXIST},
294 	{NT_STATUS_OBJECT_NAME_INVALID,		EINVAL},
295 	{NT_STATUS_OBJECT_NAME_NOT_FOUND,	ENOENT},
296 	{NT_STATUS_OBJECT_PATH_INVALID,		ENOTDIR},
297 	{NT_STATUS_OBJECT_PATH_NOT_FOUND,	ENOENT},
298 	{NT_STATUS_OBJECT_PATH_SYNTAX_BAD,	EINVAL},
299 	{NT_STATUS_OBJECT_TYPE_MISMATCH,	EBADF},
300 	{NT_STATUS_PAGEFILE_QUOTA,		EDQUOT},
301 	{NT_STATUS_PASSWORD_EXPIRED,		EAUTH},
302 	{NT_STATUS_PASSWORD_MUST_CHANGE,	EAUTH},
303 	{NT_STATUS_PASSWORD_RESTRICTION,	EAUTH},
304 	{NT_STATUS_PATH_NOT_COVERED,		ENOENT},
305 	{NT_STATUS_PIPE_BROKEN,			EPIPE},
306 	{NT_STATUS_PIPE_BUSY,			EPIPE},
307 	{NT_STATUS_PIPE_CONNECTED,		EISCONN},
308 	{NT_STATUS_PIPE_DISCONNECTED,		EPIPE},
309 	{NT_STATUS_PIPE_NOT_AVAILABLE,		EBUSY},
310 	{NT_STATUS_PORT_CONNECTION_REFUSED,	ECONNREFUSED},
311 	{NT_STATUS_PORT_DISCONNECTED,		EBADF},
312 	{NT_STATUS_PORT_MESSAGE_TOO_LONG,	EMSGSIZE},
313 	{NT_STATUS_PORT_UNREACHABLE,		EHOSTUNREACH},
314 	{NT_STATUS_PROTOCOL_UNREACHABLE,	ENOPROTOOPT},
315 	{NT_STATUS_QUOTA_EXCEEDED,		EDQUOT},
316 	{NT_STATUS_RANGE_NOT_LOCKED,		EAGAIN}, /* like F_SETLK */
317 	{NT_STATUS_REGISTRY_QUOTA_LIMIT,	EDQUOT},
318 	{NT_STATUS_REMOTE_DISCONNECT,		ESHUTDOWN},
319 	{NT_STATUS_REMOTE_NOT_LISTENING,	ECONNREFUSED},
320 	{NT_STATUS_REQUEST_NOT_ACCEPTED,	EACCES},
321 	{NT_STATUS_RETRY,			EAGAIN},
322 	{NT_STATUS_SHARING_VIOLATION,		EBUSY},
323 	{NT_STATUS_TIMER_NOT_CANCELED,		ETIME},
324 	{NT_STATUS_TOO_MANY_LINKS,		EMLINK},
325 	{NT_STATUS_TOO_MANY_OPENED_FILES,	EMFILE},
326 	{NT_STATUS_TRUSTED_DOMAIN_FAILURE,	EAUTH},
327 	{NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE, EAUTH},
328 	{NT_STATUS_UNABLE_TO_FREE_VM,		EADDRINUSE},
329 	{NT_STATUS_UNSUCCESSFUL,		EINVAL},
330 	{NT_STATUS_WRONG_PASSWORD,		EAUTH},
331 	{0,	0}
332 };
333 
334 /*
335  * Table for converting NT STATUS values to DOS class/code.
336  * Rows ordered by integer value of last column (NT STATUS)
337  */
338 typedef struct nt2doserr {
339 	unsigned short dclass;
340 	unsigned short derr;
341 	unsigned int nterr;
342 } nt2doserr_t;
343 
344 static const nt2doserr_t nt2doserr[] = {
345 	{ERRDOS,	ERRgeneral,	NT_STATUS_UNSUCCESSFUL},
346 	{ERRDOS,	ERRbadfunc,	NT_STATUS_NOT_IMPLEMENTED},
347 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_INFO_CLASS},
348 	{ERRDOS, ERROR_BAD_LENGTH,	NT_STATUS_INFO_LENGTH_MISMATCH},
349 	{ERRHRD,	ERRgeneral,	NT_STATUS_ACCESS_VIOLATION},
350 	{ERRHRD,	ERRgeneral,	NT_STATUS_IN_PAGE_ERROR},
351 	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_QUOTA},
352 	{ERRDOS,	ERRbadfid,	NT_STATUS_INVALID_HANDLE},
353 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_INITIAL_STACK},
354 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_BAD_INITIAL_PC},
355 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_CID},
356 	{ERRHRD,	ERRgeneral,	NT_STATUS_TIMER_NOT_CANCELED},
357 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER},
358 	{ERRDOS,	ERRbadfile,	NT_STATUS_NO_SUCH_DEVICE},
359 	{ERRDOS,	ERRbadfile,	NT_STATUS_NO_SUCH_FILE},
360 	{ERRDOS,	ERRbadfunc,	NT_STATUS_INVALID_DEVICE_REQUEST},
361 	{ERRDOS, ERROR_HANDLE_EOF,	NT_STATUS_END_OF_FILE},
362 	{ERRDOS, ERROR_WRONG_DISK,	NT_STATUS_WRONG_VOLUME},
363 	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_NO_MEDIA_IN_DEVICE},
364 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNRECOGNIZED_MEDIA},
365 	{ERRDOS, ERROR_SECTOR_NOT_FOUND,	NT_STATUS_NONEXISTENT_SECTOR},
366 	{ERRDOS,	ERRnomem,	NT_STATUS_NO_MEMORY},
367 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_CONFLICTING_ADDRESSES},
368 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_NOT_MAPPED_VIEW},
369 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_UNABLE_TO_FREE_VM},
370 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_UNABLE_TO_DELETE_SECTION},
371 	{ERRDOS, NERR_InvalidAPI,	NT_STATUS_INVALID_SYSTEM_SERVICE},
372 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_INSTRUCTION},
373 	{ERRDOS,	ERRnoaccess,	NT_STATUS_INVALID_LOCK_SEQUENCE},
374 	{ERRDOS,	ERRnoaccess,	NT_STATUS_INVALID_VIEW_SIZE},
375 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_FILE_FOR_SECTION},
376 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ALREADY_COMMITTED},
377 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ACCESS_DENIED},
378 	{ERRDOS, ERROR_BUFFER_OVERFLOW,	NT_STATUS_BUFFER_TOO_SMALL},
379 	{ERRDOS,	ERRbadfid,	NT_STATUS_OBJECT_TYPE_MISMATCH},
380 	{ERRHRD,	ERRgeneral,	NT_STATUS_NONCONTINUABLE_EXCEPTION},
381 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DISPOSITION},
382 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNWIND},
383 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_STACK},
384 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_UNWIND_TARGET},
385 	{ERRDOS, ERROR_NOT_LOCKED,	NT_STATUS_NOT_LOCKED},
386 	{ERRHRD,	ERRgeneral,	NT_STATUS_PARITY_ERROR},
387 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_UNABLE_TO_DECOMMIT_VM},
388 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_NOT_COMMITTED},
389 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PORT_ATTRIBUTES},
390 	{ERRHRD,	ERRgeneral,	NT_STATUS_PORT_MESSAGE_TOO_LONG},
391 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_INVALID_PARAMETER_MIX},
392 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_QUOTA_LOWER},
393 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_CORRUPT_ERROR},
394 	{ERRDOS, ERROR_INVALID_NAME,	NT_STATUS_OBJECT_NAME_INVALID},
395 	{ERRDOS,	ERRbadfile,	NT_STATUS_OBJECT_NAME_NOT_FOUND},
396 	{ERRDOS, ERROR_ALREADY_EXISTS,	NT_STATUS_OBJECT_NAME_COLLISION},
397 	{ERRDOS,	ERRbadfid,	NT_STATUS_PORT_DISCONNECTED},
398 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_ALREADY_ATTACHED},
399 	{ERRDOS, ERROR_BAD_PATHNAME,	NT_STATUS_OBJECT_PATH_INVALID},
400 	{ERRDOS,	ERRbadpath,	NT_STATUS_OBJECT_PATH_NOT_FOUND},
401 	{ERRDOS, ERROR_BAD_PATHNAME,	NT_STATUS_OBJECT_PATH_SYNTAX_BAD},
402 	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_OVERRUN},
403 	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_LATE_ERROR},
404 	{ERRDOS, ERROR_CRC,		NT_STATUS_DATA_ERROR},
405 	{ERRDOS, ERROR_CRC,		NT_STATUS_CRC_ERROR},
406 	{ERRDOS,	ERRnomem,	NT_STATUS_SECTION_TOO_BIG},
407 	{ERRDOS,	ERRnoaccess,	NT_STATUS_PORT_CONNECTION_REFUSED},
408 	{ERRDOS,	ERRbadfid,	NT_STATUS_INVALID_PORT_HANDLE},
409 	{ERRDOS, ERROR_SHARING_VIOLATION,	NT_STATUS_SHARING_VIOLATION},
410 	{ERRHRD,	ERRgeneral,	NT_STATUS_QUOTA_EXCEEDED},
411 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_INVALID_PAGE_PROTECTION},
412 	{ERRDOS, ERROR_NOT_OWNER,	NT_STATUS_MUTANT_NOT_OWNED},
413 	{ERRDOS, ERROR_TOO_MANY_POSTS,	NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED},
414 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_PORT_ALREADY_SET},
415 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_SECTION_NOT_IMAGE},
416 	{ERRDOS, ERROR_SIGNAL_REFUSED,	NT_STATUS_SUSPEND_COUNT_EXCEEDED},
417 	{ERRDOS,	ERRnoaccess,	NT_STATUS_THREAD_IS_TERMINATING},
418 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_BAD_WORKING_SET_LIMIT},
419 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_INCOMPATIBLE_FILE_MAP},
420 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_SECTION_PROTECTION},
421 	{ERRDOS, ERROR_EAS_NOT_SUPPORTED,	NT_STATUS_EAS_NOT_SUPPORTED},
422 	{ERRDOS, ERROR_EA_LIST_INCONSISTENT,	NT_STATUS_EA_TOO_LARGE},
423 	{ERRHRD,	ERRgeneral,	NT_STATUS_NONEXISTENT_EA_ENTRY},
424 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_EAS_ON_FILE},
425 	{ERRHRD,	ERRgeneral,	NT_STATUS_EA_CORRUPT_ERROR},
426 	{ERRDOS, ERROR_LOCK_VIOLATION,	NT_STATUS_FILE_LOCK_CONFLICT},
427 	{ERRDOS, ERROR_LOCK_VIOLATION,	NT_STATUS_LOCK_NOT_GRANTED},
428 	{ERRDOS,	ERRnoaccess,	NT_STATUS_DELETE_PENDING},
429 	{ERRDOS, ERROR_NOT_SUPPORTED,	NT_STATUS_CTL_FILE_NOT_SUPPORTED},
430 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNKNOWN_REVISION},
431 	{ERRHRD,	ERRgeneral,	NT_STATUS_REVISION_MISMATCH},
432 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_OWNER},
433 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PRIMARY_GROUP},
434 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_IMPERSONATION_TOKEN},
435 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_DISABLE_MANDATORY},
436 	{ERRDOS, NERR_LogonServerNotFound,	NT_STATUS_NO_LOGON_SERVERS},
437 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_LOGON_SESSION},
438 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_PRIVILEGE},
439 	{ERRDOS,	ERRnoaccess,	NT_STATUS_PRIVILEGE_NOT_HELD},
440 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ACCOUNT_NAME},
441 	{ERRHRD,	ERRgeneral,	NT_STATUS_USER_EXISTS},
442 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_SUCH_USER},
443 	{ERRHRD,	ERRgeneral,	NT_STATUS_GROUP_EXISTS},
444 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_GROUP},
445 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_IN_GROUP},
446 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_NOT_IN_GROUP},
447 	{ERRHRD,	ERRgeneral,	NT_STATUS_LAST_ADMIN},
448 	{ERRSRV,	ERRbadpw,	NT_STATUS_WRONG_PASSWORD},
449 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILL_FORMED_PASSWORD},
450 	{ERRHRD,	ERRgeneral,	NT_STATUS_PASSWORD_RESTRICTION},
451 	{ERRDOS,	ERRnoaccess,	NT_STATUS_LOGON_FAILURE},
452 	{ERRHRD,	ERRgeneral,	NT_STATUS_ACCOUNT_RESTRICTION},
453 	{ERRSRV, NERR_InvalidLogonHours,	NT_STATUS_INVALID_LOGON_HOURS},
454 	{ERRSRV, NERR_InvalidWorkstation,	NT_STATUS_INVALID_WORKSTATION},
455 	{ERRSRV, NERR_PasswordExpired,	NT_STATUS_PASSWORD_EXPIRED},
456 	{ERRSRV, NERR_AccountExpired,	NT_STATUS_ACCOUNT_DISABLED},
457 	{ERRHRD,	ERRgeneral,	NT_STATUS_NONE_MAPPED},
458 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_LUIDS_REQUESTED},
459 	{ERRHRD,	ERRgeneral,	NT_STATUS_LUIDS_EXHAUSTED},
460 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SUB_AUTHORITY},
461 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ACL},
462 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SID},
463 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SECURITY_DESCR},
464 	{ERRDOS, ERROR_PROC_NOT_FOUND,	NT_STATUS_PROCEDURE_NOT_FOUND},
465 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_FORMAT},
466 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_TOKEN},
467 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_INHERITANCE_ACL},
468 	{ERRDOS, ERROR_NOT_LOCKED,	NT_STATUS_RANGE_NOT_LOCKED},
469 	{ERRDOS, ERROR_DISK_FULL,	NT_STATUS_DISK_FULL},
470 	{ERRHRD,	ERRgeneral,	NT_STATUS_SERVER_DISABLED},
471 	{ERRHRD,	ERRgeneral,	NT_STATUS_SERVER_NOT_DISABLED},
472 	{ERRDOS, ERROR_TOO_MANY_NAMES,	NT_STATUS_TOO_MANY_GUIDS_REQUESTED},
473 	{ERRDOS, ERROR_NO_MORE_ITEMS,	NT_STATUS_GUIDS_EXHAUSTED},
474 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ID_AUTHORITY},
475 	{ERRDOS, ERROR_NO_MORE_ITEMS,	NT_STATUS_AGENTS_EXHAUSTED},
476 	{ERRDOS, ERROR_LABEL_TOO_LONG,	NT_STATUS_INVALID_VOLUME_LABEL},
477 	{ERRDOS, ERROR_OUTOFMEMORY,	NT_STATUS_SECTION_NOT_EXTENDED},
478 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_NOT_MAPPED_DATA},
479 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_DATA_NOT_FOUND},
480 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_TYPE_NOT_FOUND},
481 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_NAME_NOT_FOUND},
482 	{ERRHRD,	ERRgeneral,	NT_STATUS_ARRAY_BOUNDS_EXCEEDED},
483 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_DENORMAL_OPERAND},
484 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_DIVIDE_BY_ZERO},
485 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_INEXACT_RESULT},
486 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_INVALID_OPERATION},
487 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_OVERFLOW},
488 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_STACK_CHECK},
489 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_UNDERFLOW},
490 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTEGER_DIVIDE_BY_ZERO},
491 	{ERRDOS, ERROR_ARITHMETIC_OVERFLOW,	NT_STATUS_INTEGER_OVERFLOW},
492 	{ERRHRD,	ERRgeneral,	NT_STATUS_PRIVILEGED_INSTRUCTION},
493 	{ERRDOS,	ERRnomem,	NT_STATUS_TOO_MANY_PAGING_FILES},
494 	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_INVALID},
495 	{ERRHRD,	ERRgeneral,	NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
496 	{ERRDOS,	ERRnomem,	NT_STATUS_INSUFFICIENT_RESOURCES},
497 	{ERRDOS,	ERRbadpath,	NT_STATUS_DFS_EXIT_PATH_FOUND},
498 	{ERRDOS, ERROR_CRC,		NT_STATUS_DEVICE_DATA_ERROR},
499 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_NOT_CONNECTED},
500 	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_DEVICE_POWER_FAILURE},
501 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_FREE_VM_NOT_AT_BASE},
502 	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_MEMORY_NOT_ALLOCATED},
503 	{ERRHRD,	ERRgeneral,	NT_STATUS_WORKING_SET_QUOTA},
504 	{ERRDOS, ERROR_WRITE_PROTECT,	NT_STATUS_MEDIA_WRITE_PROTECTED},
505 	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_DEVICE_NOT_READY},
506 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_GROUP_ATTRIBUTES},
507 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_IMPERSONATION_LEVEL},
508 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_OPEN_ANONYMOUS},
509 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_VALIDATION_CLASS},
510 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_TOKEN_TYPE},
511 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_BAD_MASTER_BOOT_RECORD},
512 	{ERRHRD,	ERRgeneral,	NT_STATUS_INSTRUCTION_MISALIGNMENT},
513 	{ERRDOS, ERROR_PIPE_BUSY,	NT_STATUS_INSTANCE_NOT_AVAILABLE},
514 	{ERRDOS, ERROR_PIPE_BUSY,	NT_STATUS_PIPE_NOT_AVAILABLE},
515 	{ERRDOS, ERROR_BAD_PIPE,	NT_STATUS_INVALID_PIPE_STATE},
516 	{ERRDOS, ERROR_PIPE_BUSY,	NT_STATUS_PIPE_BUSY},
517 	{ERRDOS,	ERRbadfunc,	NT_STATUS_ILLEGAL_FUNCTION},
518 	{ERRDOS, ERROR_PIPE_NOT_CONNECTED,	NT_STATUS_PIPE_DISCONNECTED},
519 	{ERRDOS, ERROR_NO_DATA,	NT_STATUS_PIPE_CLOSING},
520 	{ERRHRD,	ERRgeneral,	NT_STATUS_PIPE_CONNECTED},
521 	{ERRHRD,	ERRgeneral,	NT_STATUS_PIPE_LISTENING},
522 	{ERRDOS, ERROR_BAD_PIPE,	NT_STATUS_INVALID_READ_MODE},
523 	{ERRDOS, ERROR_SEM_TIMEOUT,	NT_STATUS_IO_TIMEOUT},
524 	{ERRDOS, ERROR_HANDLE_EOF,	NT_STATUS_FILE_FORCED_CLOSED},
525 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROFILING_NOT_STARTED},
526 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROFILING_NOT_STOPPED},
527 	{ERRHRD,	ERRgeneral,	NT_STATUS_COULD_NOT_INTERPRET},
528 	{ERRDOS,	ERRnoaccess,	NT_STATUS_FILE_IS_A_DIRECTORY},
529 	{ERRDOS, ERROR_NOT_SUPPORTED,	NT_STATUS_NOT_SUPPORTED},
530 	{ERRDOS, ERROR_REM_NOT_LIST,	NT_STATUS_REMOTE_NOT_LISTENING},
531 	{ERRDOS, ERROR_DUP_NAME,	NT_STATUS_DUPLICATE_NAME},
532 	{ERRDOS, ERROR_BAD_NETPATH,	NT_STATUS_BAD_NETWORK_PATH},
533 	{ERRDOS, ERROR_NETWORK_BUSY,	NT_STATUS_NETWORK_BUSY},
534 	{ERRDOS, ERROR_DEV_NOT_EXIST,	NT_STATUS_DEVICE_DOES_NOT_EXIST},
535 	{ERRDOS, ERROR_TOO_MANY_CMDS,	NT_STATUS_TOO_MANY_COMMANDS},
536 	{ERRDOS, ERROR_ADAP_HDW_ERR,	NT_STATUS_ADAPTER_HARDWARE_ERROR},
537 	{ERRDOS, ERROR_BAD_NET_RESP,	NT_STATUS_INVALID_NETWORK_RESPONSE},
538 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_UNEXPECTED_NETWORK_ERROR},
539 	{ERRDOS, ERROR_BAD_REM_ADAP,	NT_STATUS_BAD_REMOTE_ADAPTER},
540 	{ERRDOS, ERROR_PRINTQ_FULL,	NT_STATUS_PRINT_QUEUE_FULL},
541 	{ERRDOS, ERROR_NO_SPOOL_SPACE,	NT_STATUS_NO_SPOOL_SPACE},
542 	{ERRDOS, ERROR_PRINT_CANCELLED,	NT_STATUS_PRINT_CANCELLED},
543 	{ERRDOS, ERROR_NETNAME_DELETED,	NT_STATUS_NETWORK_NAME_DELETED},
544 	{ERRDOS, ERROR_NETWORK_ACCESS_DENIED, NT_STATUS_NETWORK_ACCESS_DENIED},
545 	{ERRDOS, ERROR_BAD_DEV_TYPE,	NT_STATUS_BAD_DEVICE_TYPE},
546 	{ERRDOS, ERROR_BAD_NET_NAME,	NT_STATUS_BAD_NETWORK_NAME},
547 	{ERRDOS, ERROR_TOO_MANY_NAMES,	NT_STATUS_TOO_MANY_NAMES},
548 	{ERRDOS, ERROR_TOO_MANY_SESS,	NT_STATUS_TOO_MANY_SESSIONS},
549 	{ERRDOS, ERROR_SHARING_PAUSED,	NT_STATUS_SHARING_PAUSED},
550 	{ERRDOS, ERROR_REQ_NOT_ACCEP,	NT_STATUS_REQUEST_NOT_ACCEPTED},
551 	{ERRDOS, ERROR_REDIR_PAUSED,	NT_STATUS_REDIRECTOR_PAUSED},
552 	{ERRDOS, ERROR_NET_WRITE_FAULT,	NT_STATUS_NET_WRITE_FAULT},
553 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROFILING_AT_LIMIT},
554 	{ERRDOS, ERROR_NOT_SAME_DEVICE,	NT_STATUS_NOT_SAME_DEVICE},
555 	{ERRDOS,	ERRnoaccess,	NT_STATUS_FILE_RENAMED},
556 	{ERRDOS, ERROR_VC_DISCONNECTED,	NT_STATUS_VIRTUAL_CIRCUIT_CLOSED},
557 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SECURITY_ON_OBJECT},
558 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_WAIT},
559 	{ERRDOS, ERROR_NO_DATA,		NT_STATUS_PIPE_EMPTY},
560 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_ACCESS_DOMAIN_INFO},
561 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_TERMINATE_SELF},
562 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SERVER_STATE},
563 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DOMAIN_STATE},
564 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DOMAIN_ROLE},
565 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_DOMAIN},
566 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_EXISTS},
567 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_LIMIT_EXCEEDED},
568 	{ERRDOS, ERROR_OPLOCK_NOT_GRANTED, NT_STATUS_OPLOCK_NOT_GRANTED},
569 	{ERRDOS, ERROR_INVALID_OPLOCK_PROTOCOL,
570 					NT_STATUS_INVALID_OPLOCK_PROTOCOL},
571 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTERNAL_DB_CORRUPTION},
572 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTERNAL_ERROR},
573 	{ERRHRD,	ERRgeneral,	NT_STATUS_GENERIC_NOT_MAPPED},
574 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_DESCRIPTOR_FORMAT},
575 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_USER_BUFFER},
576 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_IO_ERROR},
577 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_MM_CREATE_ERR},
578 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_MM_MAP_ERROR},
579 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_MM_EXTEND_ERR},
580 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_LOGON_PROCESS},
581 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_SESSION_EXISTS},
582 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_1},
583 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_2},
584 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_3},
585 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_4},
586 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_5},
587 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_6},
588 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_7},
589 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_8},
590 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_9},
591 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_10},
592 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_11},
593 	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER_12},
594 	{ERRDOS,	ERRbadpath,	NT_STATUS_REDIRECTOR_NOT_STARTED},
595 	{ERRHRD,	ERRgeneral,	NT_STATUS_REDIRECTOR_STARTED},
596 	{ERRHRD,	ERRgeneral,	NT_STATUS_STACK_OVERFLOW},
597 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_PACKAGE},
598 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_FUNCTION_TABLE},
599 	{ERRDOS, ERROR_ENVVAR_NOT_FOUND,	NT_STATUS_VARIABLE_NOT_FOUND},
600 	{ERRDOS, ERROR_DIR_NOT_EMPTY,	NT_STATUS_DIRECTORY_NOT_EMPTY},
601 	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_CORRUPT_ERROR},
602 	{ERRDOS, ERROR_DIRECTORY,	NT_STATUS_NOT_A_DIRECTORY},
603 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_LOGON_SESSION_STATE},
604 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_SESSION_COLLISION},
605 	{ERRDOS, ERROR_FILENAME_EXCED_RANGE,	NT_STATUS_NAME_TOO_LONG},
606 	{ERRDOS, NERR_OpenFiles,	NT_STATUS_FILES_OPEN},
607 	{ERRDOS, NERR_DevInUse,		NT_STATUS_CONNECTION_IN_USE},
608 	{ERRHRD,	ERRgeneral,	NT_STATUS_MESSAGE_NOT_FOUND},
609 	{ERRDOS,	ERRnoaccess,	NT_STATUS_PROCESS_IS_TERMINATING},
610 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LOGON_TYPE},
611 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_GUID_TRANSLATION},
612 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANNOT_IMPERSONATE},
613 	{ERRHRD,	ERRgeneral,	NT_STATUS_IMAGE_ALREADY_LOADED},
614 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_LDT},
615 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LDT_SIZE},
616 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LDT_OFFSET},
617 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LDT_DESCRIPTOR},
618 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_NE_FORMAT},
619 	{ERRHRD,	ERRgeneral,	NT_STATUS_RXACT_INVALID_STATE},
620 	{ERRHRD,	ERRgeneral,	NT_STATUS_RXACT_COMMIT_FAILURE},
621 	{ERRHRD,	ERRgeneral,	NT_STATUS_MAPPED_FILE_SIZE_ZERO},
622 	{ERRDOS,	ERRnofids,	NT_STATUS_TOO_MANY_OPENED_FILES},
623 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANCELLED},
624 	{ERRDOS,	ERRnoaccess,	NT_STATUS_CANNOT_DELETE},
625 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_COMPUTER_NAME},
626 	{ERRDOS,	ERRnoaccess,	NT_STATUS_FILE_DELETED},
627 	{ERRHRD,	ERRgeneral,	NT_STATUS_SPECIAL_ACCOUNT},
628 	{ERRHRD,	ERRgeneral,	NT_STATUS_SPECIAL_GROUP},
629 	{ERRHRD,	ERRgeneral,	NT_STATUS_SPECIAL_USER},
630 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBERS_PRIMARY_GROUP},
631 	{ERRDOS,	ERRbadfid,	NT_STATUS_FILE_CLOSED},
632 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_THREADS},
633 	{ERRHRD,	ERRgeneral,	NT_STATUS_THREAD_NOT_IN_PROCESS},
634 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOKEN_ALREADY_IN_USE},
635 	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_QUOTA_EXCEEDED},
636 	{ERRHRD,	ERRgeneral,	NT_STATUS_COMMITMENT_LIMIT},
637 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_LE_FORMAT},
638 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_NOT_MZ},
639 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_PROTECT},
640 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_WIN_16},
641 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_SERVER_CONFLICT},
642 	{ERRHRD,	ERRgeneral,	NT_STATUS_TIME_DIFFERENCE_AT_DC},
643 	{ERRHRD,	ERRgeneral,	NT_STATUS_SYNCHRONIZATION_REQUIRED},
644 	{ERRDOS, ERROR_MOD_NOT_FOUND,	NT_STATUS_DLL_NOT_FOUND},
645 	{ERRHRD,	ERRgeneral,	NT_STATUS_OPEN_FAILED},
646 	{ERRHRD,	ERRgeneral,	NT_STATUS_IO_PRIVILEGE_FAILED},
647 	{ERRDOS, ERROR_INVALID_ORDINAL,	NT_STATUS_ORDINAL_NOT_FOUND},
648 	{ERRDOS, ERROR_PROC_NOT_FOUND,	NT_STATUS_ENTRYPOINT_NOT_FOUND},
649 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONTROL_C_EXIT},
650 	{ERRDOS, ERROR_NETNAME_DELETED,	NT_STATUS_LOCAL_DISCONNECT},
651 	{ERRDOS, ERROR_NETNAME_DELETED,	NT_STATUS_REMOTE_DISCONNECT},
652 	{ERRDOS, ERROR_REM_NOT_LIST,	NT_STATUS_REMOTE_RESOURCES},
653 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_LINK_FAILED},
654 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_LINK_TIMEOUT},
655 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_INVALID_CONNECTION},
656 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_INVALID_ADDRESS},
657 	{ERRHRD,	ERRgeneral,	NT_STATUS_DLL_INIT_FAILED},
658 	{ERRHRD,	ERRgeneral,	NT_STATUS_MISSING_SYSTEMFILE},
659 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNHANDLED_EXCEPTION},
660 	{ERRHRD,	ERRgeneral,	NT_STATUS_APP_INIT_FAILURE},
661 	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_CREATE_FAILED},
662 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_PAGEFILE},
663 	{ERRDOS, ERROR_INVALID_LEVEL,	NT_STATUS_INVALID_LEVEL},
664 	{ERRDOS, ERROR_INVALID_PASSWORD,	NT_STATUS_WRONG_PASSWORD_CORE},
665 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_FLOAT_CONTEXT},
666 	{ERRDOS, ERROR_BROKEN_PIPE,	NT_STATUS_PIPE_BROKEN},
667 	{ERRHRD,	ERRgeneral,	NT_STATUS_REGISTRY_CORRUPT},
668 	{ERRHRD,	ERRgeneral,	NT_STATUS_REGISTRY_IO_FAILED},
669 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_EVENT_PAIR},
670 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNRECOGNIZED_VOLUME},
671 	{ERRHRD,	ERRgeneral,	NT_STATUS_SERIAL_NO_DEVICE_INITED},
672 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_ALIAS},
673 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_NOT_IN_ALIAS},
674 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_IN_ALIAS},
675 	{ERRHRD,	ERRgeneral,	NT_STATUS_ALIAS_EXISTS},
676 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_NOT_GRANTED},
677 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_SECRETS},
678 	{ERRHRD,	ERRgeneral,	NT_STATUS_SECRET_TOO_LONG},
679 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTERNAL_DB_ERROR},
680 	{ERRHRD,	ERRgeneral,	NT_STATUS_FULLSCREEN_MODE},
681 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_CONTEXT_IDS},
682 	{ERRDOS,	ERRnoaccess,	NT_STATUS_LOGON_TYPE_NOT_GRANTED},
683 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_REGISTRY_FILE},
684 	{ERRHRD,	ERRgeneral,	NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED},
685 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR},
686 	{ERRHRD,	ERRgeneral,	NT_STATUS_FT_MISSING_MEMBER},
687 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILL_FORMED_SERVICE_ENTRY},
688 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_CHARACTER},
689 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNMAPPABLE_CHARACTER},
690 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNDEFINED_CHARACTER},
691 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_VOLUME},
692 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND},
693 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_WRONG_CYLINDER},
694 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_UNKNOWN_ERROR},
695 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_BAD_REGISTERS},
696 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_RECALIBRATE_FAILED},
697 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_OPERATION_FAILED},
698 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_RESET_FAILED},
699 	{ERRHRD,	ERRgeneral,	NT_STATUS_SHARED_IRQ_BUSY},
700 	{ERRHRD,	ERRgeneral,	NT_STATUS_FT_ORPHANING},
701 	{ERRHRD,	ERRgeneral,
702 		NT_STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT},
703 	{ERRHRD,	ERRgeneral,	NT_STATUS_PARTITION_FAILURE},
704 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_BLOCK_LENGTH},
705 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_NOT_PARTITIONED},
706 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNABLE_TO_LOCK_MEDIA},
707 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNABLE_TO_UNLOAD_MEDIA},
708 	{ERRHRD,	ERRgeneral,	NT_STATUS_EOM_OVERFLOW},
709 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_MEDIA},
710 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_MEMBER},
711 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_MEMBER},
712 	{ERRHRD,	ERRgeneral,	NT_STATUS_KEY_DELETED},
713 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_LOG_SPACE},
714 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_SIDS},
715 	{ERRHRD,	ERRgeneral,	NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED},
716 	{ERRHRD,	ERRgeneral,	NT_STATUS_KEY_HAS_CHILDREN},
717 	{ERRHRD,	ERRgeneral,	NT_STATUS_CHILD_MUST_BE_VOLATILE},
718 	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_DEVICE_CONFIGURATION_ERROR},
719 	{ERRHRD,	ERRgeneral,	NT_STATUS_DRIVER_INTERNAL_ERROR},
720 	{ERRDOS, ERROR_BAD_COMMAND,	NT_STATUS_INVALID_DEVICE_STATE},
721 	{ERRHRD,	ERRgeneral,	NT_STATUS_IO_DEVICE_ERROR},
722 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_PROTOCOL_ERROR},
723 	{ERRHRD,	ERRgeneral,	NT_STATUS_BACKUP_CONTROLLER},
724 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOG_FILE_FULL},
725 	{ERRDOS, ERROR_WRITE_PROTECT,	NT_STATUS_TOO_LATE},
726 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_TRUST_LSA_SECRET},
727 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_TRUST_SAM_ACCOUNT},
728 	{ERRDOS,	ERRnoaccess,	NT_STATUS_TRUSTED_DOMAIN_FAILURE},
729 	{ERRDOS,	ERRnoaccess,	NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE},
730 	{ERRHRD,	ERRgeneral,	NT_STATUS_EVENTLOG_FILE_CORRUPT},
731 	{ERRHRD,	ERRgeneral,	NT_STATUS_EVENTLOG_CANT_START},
732 	{ERRDOS,	ERRnoaccess,	NT_STATUS_TRUST_FAILURE},
733 	{ERRHRD,	ERRgeneral,	NT_STATUS_MUTANT_LIMIT_EXCEEDED},
734 	{ERRDOS, NERR_NetlogonNotStarted,	NT_STATUS_NETLOGON_NOT_STARTED},
735 	{ERRSRV, NERR_AccountExpired,	NT_STATUS_ACCOUNT_EXPIRED},
736 	{ERRHRD,	ERRgeneral,	NT_STATUS_POSSIBLE_DEADLOCK},
737 	{ERRHRD,	ERRgeneral,	NT_STATUS_NETWORK_CREDENTIAL_CONFLICT},
738 	{ERRHRD,	ERRgeneral,	NT_STATUS_REMOTE_SESSION_LIMIT},
739 	{ERRHRD,	ERRgeneral,	NT_STATUS_EVENTLOG_FILE_CHANGED},
740 	{ERRDOS,	ERRnoaccess,
741 		NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT},
742 	{ERRDOS,	ERRnoaccess,
743 		NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT},
744 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
745 	{ERRDOS,	ERRnoaccess,	NT_STATUS_DOMAIN_TRUST_INCONSISTENT},
746 	{ERRHRD,	ERRgeneral,	NT_STATUS_FS_DRIVER_REQUIRED},
747 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_USER_SESSION_KEY},
748 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_USER_SESSION_DELETED},
749 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_LANG_NOT_FOUND},
750 	{ERRDOS,	ERRnomem,	NT_STATUS_INSUFF_SERVER_RESOURCES},
751 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_BUFFER_SIZE},
752 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ADDRESS_COMPONENT},
753 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ADDRESS_WILDCARD},
754 	{ERRDOS, ERROR_TOO_MANY_NAMES,	NT_STATUS_TOO_MANY_ADDRESSES},
755 	{ERRDOS, ERROR_DUP_NAME,	NT_STATUS_ADDRESS_ALREADY_EXISTS},
756 	{ERRDOS, ERROR_NETNAME_DELETED,	NT_STATUS_ADDRESS_CLOSED},
757 	{ERRDOS, ERROR_NETNAME_DELETED,	NT_STATUS_CONNECTION_DISCONNECTED},
758 	{ERRDOS, ERROR_NETNAME_DELETED,	NT_STATUS_CONNECTION_RESET},
759 	{ERRDOS, ERROR_TOO_MANY_NAMES,	NT_STATUS_TOO_MANY_NODES},
760 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_ABORTED},
761 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_TIMED_OUT},
762 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_NO_RELEASE},
763 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_NO_MATCH},
764 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_RESPONDED},
765 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_INVALID_ID},
766 	{ERRDOS, ERROR_UNEXP_NET_ERR,	NT_STATUS_TRANSACTION_INVALID_TYPE},
767 	{ERRDOS, ERROR_NOT_SUPPORTED,	NT_STATUS_NOT_SERVER_SESSION},
768 	{ERRDOS, ERROR_NOT_SUPPORTED,	NT_STATUS_NOT_CLIENT_SESSION},
769 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANNOT_LOAD_REGISTRY_FILE},
770 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEBUG_ATTACH_FAILED},
771 	{ERRHRD,	ERRgeneral,	NT_STATUS_SYSTEM_PROCESS_TERMINATED},
772 	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_NOT_ACCEPTED},
773 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_BROWSER_SERVERS_FOUND},
774 	{ERRHRD,	ERRgeneral,	NT_STATUS_VDM_HARD_ERROR},
775 	{ERRHRD,	ERRgeneral,	NT_STATUS_DRIVER_CANCEL_TIMEOUT},
776 	{ERRHRD,	ERRgeneral,	NT_STATUS_REPLY_MESSAGE_MISMATCH},
777 	{ERRHRD,	ERRgeneral,	NT_STATUS_MAPPED_ALIGNMENT},
778 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_IMAGE_CHECKSUM_MISMATCH},
779 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOST_WRITEBEHIND_DATA},
780 	{ERRHRD,	ERRgeneral, NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID},
781 	{ERRSRV, NERR_PasswordExpired,	NT_STATUS_PASSWORD_MUST_CHANGE},
782 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_FOUND},
783 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_TINY_STREAM},
784 	{ERRHRD,	ERRgeneral,	NT_STATUS_RECOVERY_FAILURE},
785 	{ERRHRD,	ERRgeneral,	NT_STATUS_STACK_OVERFLOW_READ},
786 	{ERRHRD,	ERRgeneral,	NT_STATUS_FAIL_CHECK},
787 	{ERRHRD,	ERRgeneral,	NT_STATUS_DUPLICATE_OBJECTID},
788 	{ERRHRD,	ERRgeneral,	NT_STATUS_OBJECTID_EXISTS},
789 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONVERT_TO_LARGE},
790 	{ERRHRD,	ERRgeneral,	NT_STATUS_RETRY},
791 	{ERRHRD,	ERRgeneral,	NT_STATUS_FOUND_OUT_OF_SCOPE},
792 	{ERRHRD,	ERRgeneral,	NT_STATUS_ALLOCATE_BUCKET},
793 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROPSET_NOT_FOUND},
794 	{ERRHRD,	ERRgeneral,	NT_STATUS_MARSHALL_OVERFLOW},
795 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_VARIANT},
796 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND},
797 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ACCOUNT_LOCKED_OUT},
798 	{ERRDOS,	ERRbadfid,	NT_STATUS_HANDLE_NOT_CLOSABLE},
799 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_REFUSED},
800 	{ERRHRD,	ERRgeneral,	NT_STATUS_GRACEFUL_DISCONNECT},
801 	{ERRHRD,	ERRgeneral,	NT_STATUS_ADDRESS_ALREADY_ASSOCIATED},
802 	{ERRHRD,	ERRgeneral,	NT_STATUS_ADDRESS_NOT_ASSOCIATED},
803 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_INVALID},
804 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_ACTIVE},
805 	{ERRHRD,	ERRgeneral,	NT_STATUS_NETWORK_UNREACHABLE},
806 	{ERRHRD,	ERRgeneral,	NT_STATUS_HOST_UNREACHABLE},
807 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROTOCOL_UNREACHABLE},
808 	{ERRHRD,	ERRgeneral,	NT_STATUS_PORT_UNREACHABLE},
809 	{ERRHRD,	ERRgeneral,	NT_STATUS_REQUEST_ABORTED},
810 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_ABORTED},
811 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_COMPRESSION_BUFFER},
812 	{ERRHRD,	ERRgeneral,	NT_STATUS_USER_MAPPED_FILE},
813 	{ERRHRD,	ERRgeneral,	NT_STATUS_AUDIT_FAILED},
814 	{ERRHRD,	ERRgeneral,	NT_STATUS_TIMER_RESOLUTION_NOT_SET},
815 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_COUNT_LIMIT},
816 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGIN_TIME_RESTRICTION},
817 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGIN_WKSTA_RESTRICTION},
818 	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_IMAGE_MP_UP_MISMATCH},
819 	{ERRHRD,	ERRgeneral,	NT_STATUS_INSUFFICIENT_LOGON_INFO},
820 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_DLL_ENTRYPOINT},
821 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_SERVICE_ENTRYPOINT},
822 	{ERRHRD,	ERRgeneral,	NT_STATUS_LPC_REPLY_LOST},
823 	{ERRHRD,	ERRgeneral,	NT_STATUS_IP_ADDRESS_CONFLICT1},
824 	{ERRHRD,	ERRgeneral,	NT_STATUS_IP_ADDRESS_CONFLICT2},
825 	{ERRHRD,	ERRgeneral,	NT_STATUS_REGISTRY_QUOTA_LIMIT},
826 	{ERRSRV,	ERRbadtype,	NT_STATUS_PATH_NOT_COVERED},
827 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_CALLBACK_ACTIVE},
828 	{ERRHRD,	ERRgeneral,	NT_STATUS_LICENSE_QUOTA_EXCEEDED},
829 	{ERRHRD,	ERRgeneral,	NT_STATUS_PWD_TOO_SHORT},
830 	{ERRHRD,	ERRgeneral,	NT_STATUS_PWD_TOO_RECENT},
831 	{ERRHRD,	ERRgeneral,	NT_STATUS_PWD_HISTORY_CONFLICT},
832 	{ERRHRD,	ERRgeneral,	NT_STATUS_PLUGPLAY_NO_DEVICE},
833 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNSUPPORTED_COMPRESSION},
834 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_HW_PROFILE},
835 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH},
836 	{ERRDOS, ERROR_INVALID_ORDINAL,	NT_STATUS_DRIVER_ORDINAL_NOT_FOUND},
837 	{ERRDOS, ERROR_PROC_NOT_FOUND,	NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND},
838 	{ERRDOS, ERROR_NOT_OWNER,	NT_STATUS_RESOURCE_NOT_OWNED},
839 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_LINKS},
840 	{ERRHRD,	ERRgeneral,	NT_STATUS_QUOTA_LIST_INCONSISTENT},
841 	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_IS_OFFLINE},
842 	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_VOLUME_DISMOUNTED},
843 	{ERRDOS, ERROR_BAD_PATHNAME,	NT_STATUS_DIRECTORY_IS_A_REPARSE_POINT},
844 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ENCRYPTION_FAILED},
845 	{ERRDOS,	ERRnoaccess,	NT_STATUS_DECRYPTION_FAILED},
846 	{ERRHRD,	ERRgeneral,	NT_STATUS_RANGE_NOT_FOUND},
847 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_RECOVERY_POLICY},
848 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_EFS},
849 	{ERRDOS,	ERRnoaccess,	NT_STATUS_WRONG_EFS},
850 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_USER_KEYS},
851 	{ERRDOS,	ERRbadfunc,	NT_STATUS_VOLUME_NOT_UPGRADED},
852 	{0, 0, 0}
853 };
854 
855 int
856 smb_maperr32(uint32_t nterr)
857 {
858 	const nt2errno_t *nt2e;
859 	const nt2doserr_t *nt2d;
860 
861 	switch (NT_SC_SEVERITY(nterr)) {
862 	case NT_STATUS_SEVERITY_SUCCESS:
863 	case NT_STATUS_SEVERITY_INFORMATIONAL:
864 		return (0);
865 	}
866 
867 	/* first try direct map to unix */
868 	for (nt2e = nt2errno; nt2e->errno; nt2e++)
869 		if (nt2e->nterr == nterr)
870 			return (nt2e->errno);
871 	smb_errmsg(unknown_err_logpri, "smb_maperr32",
872 	    "No direct map for 32 bit server error (0x%x)\n", nterr);
873 
874 	/* ok, then try mapping to dos to unix */
875 	for (nt2d = nt2doserr; nt2d->nterr; nt2d++)
876 		if (nt2d->nterr == nterr)
877 			return (smb_maperror(nt2d->dclass, nt2d->derr));
878 	return (EIO);
879 }
880 
881 uint_t
882 smb_doserr2status(int dclass, int derr)
883 {
884 	const nt2doserr_t *nt2d;
885 
886 	if (dclass == 0 && derr == 0)
887 		return (0);
888 
889 	for (nt2d = nt2doserr; nt2d->nterr; nt2d++)
890 		if (nt2d->dclass == dclass && nt2d->derr == derr)
891 			return (nt2d->nterr);
892 	return (NT_STATUS_UNSUCCESSFUL);
893 }
894 
895 int
896 smb_maperror(int eclass, int eno)
897 {
898 	if (eclass == 0 && eno == 0)
899 		return (0);
900 	switch (eclass) {
901 	case ERRDOS:
902 		switch (eno) {
903 		case ERROR_INVALID_LEVEL:
904 			return (ENOTSUP);
905 		case ERRbadfunc:
906 		case ERRbadenv:
907 		case ERRbadformat:
908 		case ERRremcd:
909 		case ERRrmuns:
910 			return (EINVAL);
911 		case ERRbadfile:
912 		case ERRbadpath:
913 		case ERROR_BAD_DEV_TYPE:
914 		case ERROR_BAD_NET_NAME:
915 			return (ENOENT);
916 		case ERRnofids:
917 			return (EMFILE);
918 		case ERRnoaccess:
919 			/*
920 			 * XXX CSM Reported on samba-technical 12/7/2002
921 			 *
922 			 * There is a case for which server(s) return
923 			 * ERRnoaccess but should return ERRdiskfull: When
924 			 * the offset for a write is exactly the server
925 			 * file size limit then Samba (at least) thinks
926 			 * the reason for zero bytes having been written
927 			 * must have been "access denied" from the local
928 			 * filesystem.  This cannot be easily worked
929 			 * around since the server behaviour is
930 			 * indistinguishable from actual access denied.
931 			 * An incomplete workaround: attempt a 2 byte write
932 			 * from "offset-1".  (That may require reading at
933 			 * offset-1 first.)  The flaw is that reading or
934 			 * writing at offset-1 could cause an
935 			 * unrelated error (due to a byte range lock
936 			 * for instance) and we can't presume the
937 			 * order servers check errors in.
938 			 */
939 		case ERRbadaccess:
940 			return (EACCES);
941 		case ERRbadshare:
942 			return (EBUSY);
943 		case ERRbadfid:
944 			return (EBADF);
945 		case ERRbadmcb:
946 			return (EIO);
947 		case ERRnomem:
948 			return (ENOMEM);	/* actually remote no mem... */
949 		case ERRbadmem:
950 			return (EFAULT);
951 		case ERRbaddata:
952 			return (E2BIG);
953 		case ERRbaddrive:
954 		case ERRnotready:	/* nt */
955 			return (ENXIO);
956 		case ERRdiffdevice:
957 			return (EXDEV);
958 		case ERRnofiles:
959 			return (0);	/* eeof ? */
960 		case ERRlock:
961 			return (EAGAIN);
962 		case ERRfilexists:
963 			return (EEXIST);
964 		case ERROR_INVALID_NAME:
965 			return (ENOENT);
966 		case ERROR_DIR_NOT_EMPTY:
967 			return (ENOTEMPTY);
968 		case ERROR_NOT_LOCKED:
969 			return (0); /* we unlock on any close */
970 		case ERROR_ALREADY_EXISTS:
971 			return (EEXIST);
972 		case ERRmoredata:
973 			return (EMOREDATA);
974 		}
975 		break;
976 	case ERRSRV:
977 		switch (eno) {
978 		case ERRerror:
979 			return (EINVAL);
980 		case ERRbadpw:
981 			return (EAUTH);
982 		case ERRaccess:
983 		case ERRbaduid:
984 			return (EACCES);
985 		case ERRinvnid:
986 			return (ENETRESET);
987 		case ERRinvnetname:
988 			return (ENXIO);
989 		case ERRbadtype:		/* reserved and returned */
990 			return (EIO);
991 		case NERR_AccountExpired: /* account exists but disabled */
992 			return (EPERM);
993 		}
994 		break;
995 	case ERRHRD:
996 		switch (eno) {
997 		case ERRnowrite:
998 			return (EROFS);
999 		case ERRbadunit:
1000 			return (ENODEV);
1001 		case ERRbadreq:
1002 			return (EBADRPC);
1003 		case ERRbadshare:
1004 			return (ETXTBSY);
1005 		case ERRlock:
1006 			return (EAGAIN);
1007 		case ERRdiskfull:
1008 			return (EFBIG);
1009 		case ERRnotready:
1010 		case ERRbadcmd:
1011 		case ERRdata:
1012 		case ERRgeneral:
1013 			return (EIO);
1014 		}
1015 	}
1016 
1017 	smb_errmsg(unknown_err_logpri, "smb_maperror",
1018 	    "Unknown DOS error %d/%d\n", eclass, eno);
1019 	return (EIO);
1020 }
1021 
1022 #define	SMALL_CONV 256
1023 
1024 /*
1025  * Decode an SMB OTW string (Unicode or OEM chars)
1026  * converting to UTF-8 in the output buffer.
1027  * outlen is in/out (max size on input)
1028  * insize is the wire size (2 * chars if unicode)
1029  * The output string is null terminated.
1030  * Output length does not include the null.
1031  */
1032 int
1033 smb_get_dstring(struct mdchain *mdc, struct smb_vc *vcp,
1034 	char *outbuf, size_t *outlen, int insize)
1035 {
1036 	uint16_t convbuf[SMALL_CONV];
1037 	uint16_t *cbuf;
1038 	size_t cbufalloc, inlen, outsize;
1039 	int error;
1040 
1041 	if (insize <= 0)
1042 		return (0);
1043 	/* Note: inlen is UTF-16 symbols. */
1044 	inlen = insize / 2;
1045 
1046 	if (*outlen < 2)
1047 		return (EINVAL);
1048 	outsize = *outlen - 1; /* room for null */
1049 
1050 	/*
1051 	 * Get a buffer for the conversion and fill it.
1052 	 * Use stack buffer if the string is
1053 	 * small enough, else allocate.
1054 	 */
1055 	if (insize < sizeof (convbuf)) {
1056 		cbufalloc = 0;
1057 		cbuf = convbuf;
1058 	} else {
1059 		cbufalloc = insize + 2;
1060 		cbuf = kmem_alloc(cbufalloc, KM_SLEEP);
1061 	}
1062 	error = md_get_mem(mdc, cbuf, insize, MB_MSYSTEM);
1063 	if (error != 0)
1064 		goto out;
1065 	cbuf[inlen] = 0;
1066 
1067 	/*
1068 	 * Handle the easy case (non-unicode).
1069 	 * XXX: Technically, we should convert
1070 	 * the string to OEM codeset first...
1071 	 * Modern servers all use Unicode, so
1072 	 * this is good enough.
1073 	 */
1074 	if (SMB_UNICODE_STRINGS(vcp) == 0) {
1075 		*outlen = strlcpy(outbuf, (char *)cbuf, outsize);
1076 		if (*outlen > outsize) {
1077 			*outlen = outsize;
1078 			error = E2BIG;
1079 		}
1080 	} else {
1081 		/*
1082 		 * Convert from UTF-16 to UTF-8
1083 		 */
1084 		error = uconv_u16tou8(cbuf, &inlen,
1085 		    (uchar_t *)outbuf, outlen,
1086 		    UCONV_IN_LITTLE_ENDIAN);
1087 		if (error == 0) {
1088 			outbuf[*outlen] = '\0';
1089 		}
1090 	}
1091 
1092 	ASSERT(*outlen == strlen(outbuf));
1093 
1094 out:
1095 	if (cbufalloc != 0)
1096 		kmem_free(cbuf, cbufalloc);
1097 
1098 	return (error);
1099 }
1100 
1101 /*
1102  * It's surprising that this function does utf8-ucs2 conversion.
1103  * One would expect only smb_put_dstring to do that.
1104  * Fixing that will require changing a bunch of callers. XXX
1105  */
1106 /*ARGSUSED*/
1107 int
1108 smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp, const char *src,
1109 	int size, int caseopt, int *lenp)
1110 {
1111 	uint16_t convbuf[SMALL_CONV];
1112 	uint16_t *cbuf;
1113 	size_t cbufalloc, inlen, outlen;
1114 	int error;
1115 
1116 	if (size <= 0)
1117 		return (0);
1118 
1119 	/*
1120 	 * Handle the easy case (non-unicode).
1121 	 * XXX: Technically, we should convert
1122 	 * the string to OEM codeset first...
1123 	 * Modern servers all use Unicode, so
1124 	 * this is good enough.
1125 	 */
1126 	if (SMB_UNICODE_STRINGS(vcp) == 0) {
1127 		error = mb_put_mem(mbp, src, size, MB_MSYSTEM);
1128 		if (!error && lenp)
1129 			*lenp += size;
1130 		return (error);
1131 	}
1132 
1133 	/*
1134 	 * Convert to UCS-2 (really UTF-16).
1135 	 * Use stack buffer if the string is
1136 	 * small enough, else allocate.
1137 	 */
1138 	if (size <= SMALL_CONV) {
1139 		cbufalloc = 0;
1140 		outlen = SMALL_CONV;
1141 		cbuf = convbuf;
1142 	} else {
1143 		outlen = size; /* in utf-16 characters */
1144 		cbufalloc = outlen * 2;
1145 		cbuf = kmem_alloc(cbufalloc, KM_SLEEP);
1146 	}
1147 
1148 	inlen = size;
1149 	error = uconv_u8tou16((uchar_t *)src, &inlen, cbuf, &outlen,
1150 	    UCONV_OUT_LITTLE_ENDIAN | UCONV_IGNORE_NULL);
1151 	outlen *= 2;  /* convert to bytes */
1152 
1153 	if (!error) {
1154 		(void) mb_put_padbyte(mbp); /* align */
1155 		error = mb_put_mem(mbp, (char *)cbuf, outlen, MB_MSYSTEM);
1156 	}
1157 	if (!error && lenp)
1158 		*lenp += outlen;
1159 
1160 	if (cbufalloc)
1161 		kmem_free(cbuf, cbufalloc);
1162 
1163 	return (error);
1164 }
1165 
1166 int
1167 smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp, const char *src,
1168 	int caseopt)
1169 {
1170 	int error, len;
1171 
1172 	/*
1173 	 * Let smb_put_dmem put both the string
1174 	 * and the terminating null.
1175 	 */
1176 	len = strlen(src) + 1;
1177 	error = smb_put_dmem(mbp, vcp, src, len, caseopt, NULL);
1178 	if (error)
1179 		return (error);
1180 
1181 	return (error);
1182 }
1183 int
1184 smb_smb_ntcreate(struct smb_share *ssp, struct mbchain *name_mb,
1185 	uint32_t crflag, uint32_t req_acc, uint32_t efa, uint32_t sh_acc,
1186 	uint32_t disp, uint32_t createopt,  uint32_t impersonate,
1187 	struct smb_cred *scrp, smb_fh_t *fhp,
1188 	uint32_t *cr_act_p, struct smbfattr *fap)
1189 {
1190 	int err;
1191 
1192 	if (SSTOVC(ssp)->vc_flags & SMBV_SMB2) {
1193 		err = smb2_smb_ntcreate(ssp, name_mb, NULL, NULL,
1194 		   crflag, req_acc, efa, sh_acc, disp, createopt,
1195 		   impersonate, scrp, &fhp->fh_fid2, cr_act_p, fap);
1196 	} else {
1197 		err = smb1_smb_ntcreate(ssp, name_mb, crflag, req_acc,
1198 		    efa, sh_acc, disp, createopt,  impersonate, scrp,
1199 		    &fhp->fh_fid1, cr_act_p, fap);
1200 	}
1201 	return (err);
1202 }
1203 
1204 int
1205 smb_smb_close(struct smb_share *ssp, smb_fh_t *fhp,
1206 	struct smb_cred *scrp)
1207 {
1208 	int err;
1209 
1210 	if (SSTOVC(ssp)->vc_flags & SMBV_SMB2) {
1211 		err = smb2_smb_close(ssp, &fhp->fh_fid2, scrp);
1212 	} else {
1213 		err = smb1_smb_close(ssp, fhp->fh_fid1, NULL, scrp);
1214 	}
1215 
1216 	return (err);
1217 }
1218 
1219 /*
1220  * Largest size to use with LARGE_READ/LARGE_WRITE.
1221  * Specs say up to 64k data bytes, but Windows traffic
1222  * uses 60k... no doubt for some good reason.
1223  * (Probably to keep 4k block alignment.)
1224  */
1225 uint32_t smb1_large_io_max = (60*1024);
1226 
1227 /*
1228  * Common function for read/write with UIO.
1229  * Called by netsmb smb_usr_rw,
1230  *  smbfs_readvnode, smbfs_writevnode
1231  */
1232 int
1233 smb_rwuio(smb_fh_t *fhp, uio_rw_t rw,
1234 	uio_t *uiop, smb_cred_t *scred, int timo)
1235 {
1236 	struct smb_share *ssp = FHTOSS(fhp);
1237 	struct smb_vc *vcp = SSTOVC(ssp);
1238 	ssize_t  save_resid;
1239 	uint32_t len, rlen, maxlen;
1240 	int error = 0;
1241 	int (*iofun)(smb_fh_t *, uint32_t *,
1242 	    uio_t *, smb_cred_t *, int);
1243 
1244 	/* After reconnect, the fid is invalid. */
1245 	if (fhp->fh_vcgenid != ssp->ss_vcgenid)
1246 		return (ESTALE);
1247 
1248 	if (SSTOVC(ssp)->vc_flags & SMBV_SMB2) {
1249 		if (rw == UIO_READ) {
1250 			iofun = smb2_smb_read;
1251 			maxlen = vcp->vc_sopt.sv2_maxread;
1252 		} else { /* UIO_WRITE */
1253 			iofun = smb2_smb_write;
1254 			maxlen = vcp->vc_sopt.sv2_maxwrite;
1255 		}
1256 	} else {
1257 		/*
1258 		 * Using NT LM 0.12, so readx, writex.
1259 		 * Make sure we can represent the offset.
1260 		 */
1261 		if ((vcp->vc_sopt.sv_caps & SMB_CAP_LARGE_FILES) == 0 &&
1262 		    (uiop->uio_loffset + uiop->uio_resid) > UINT32_MAX)
1263 			return (EFBIG);
1264 
1265 		if (rw == UIO_READ) {
1266 			iofun = smb_smb_readx;
1267 			if (vcp->vc_sopt.sv_caps & SMB_CAP_LARGE_READX)
1268 				maxlen = smb1_large_io_max;
1269 			else
1270 				maxlen = vcp->vc_rxmax;
1271 		} else { /* UIO_WRITE */
1272 			iofun = smb_smb_writex;
1273 			if (vcp->vc_sopt.sv_caps & SMB_CAP_LARGE_WRITEX)
1274 				maxlen = smb1_large_io_max;
1275 			else
1276 				maxlen = vcp->vc_wxmax;
1277 		}
1278 	}
1279 
1280 	save_resid = uiop->uio_resid;
1281 	while (uiop->uio_resid > 0) {
1282 		/* Lint: uio_resid may be 64-bits */
1283 		rlen = len = (uint32_t)min(maxlen, uiop->uio_resid);
1284 		error = (*iofun)(fhp, &rlen, uiop, scred, timo);
1285 
1286 		/*
1287 		 * Note: the iofun called uio_update, so
1288 		 * not doing that here as one might expect.
1289 		 *
1290 		 * Quit the loop either on error, or if we
1291 		 * transferred less then requested.
1292 		 */
1293 		if (error || (rlen < len))
1294 			break;
1295 
1296 		timo = 0; /* only first I/O should wait */
1297 	}
1298 	if (error && (save_resid != uiop->uio_resid)) {
1299 		/*
1300 		 * Stopped on an error after having
1301 		 * successfully transferred data.
1302 		 * Suppress this error.
1303 		 */
1304 		SMBSDEBUG("error %d suppressed\n", error);
1305 		error = 0;
1306 	}
1307 
1308 	return (error);
1309 }
1310