xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
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 2009 Sun Microsystems, Inc.  All rights reserved.
37  * Use is subject to license terms.
38  */
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kmem.h>
43 #include <sys/proc.h>
44 #include <sys/lock.h>
45 #include <sys/socket.h>
46 #include <sys/isa_defs.h>
47 #include <sys/stream.h>
48 #include <sys/strsun.h>
49 #include <sys/sunddi.h>
50 #include <sys/cmn_err.h>
51 #include <sys/sdt.h>
52 #include <sys/priv.h>
53 #include <sys/u8_textprep.h>
54 
55 #include <netsmb/smb_osdep.h>
56 #include <netsmb/smb.h>
57 #include <netsmb/smb_conn.h>
58 #include <netsmb/smb_rq.h>
59 #include <netsmb/smb_subr.h>
60 
61 /*
62  * XXX:This conversion might not be fully MS-Compatible
63  * for calculating hashes. The output length may differ
64  * for some locales and needs to be handled from where
65  * the call is made.
66  */
67 int
68 smb_toupper(const char *inbuf, char *outbuf, size_t outlen)
69 {
70 	int err = 0;
71 	size_t inlen, inrem, outrem;
72 
73 	inrem = inlen = strlen(inbuf);
74 	outrem = outlen;
75 	(void) u8_textprep_str((char *)inbuf, &inrem, outbuf, &outrem,
76 	    U8_TEXTPREP_TOUPPER, U8_UNICODE_LATEST, &err);
77 	/* inrem, outrem are bytes unused, remaining */
78 	if (inrem) {
79 		SMBSDEBUG("input %d remains: %s\n", (int)inrem, inbuf);
80 		inlen -= inrem;
81 	}
82 	if (outrem) {
83 		outlen -= outrem;
84 		outbuf[outlen] = '\0';
85 	}
86 	if (outlen > inlen) {
87 		SMBSDEBUG("outlen > inlen! (%d > %d)\n",
88 		    (int)outlen, (int)inlen);
89 		/* Truncate to inlen here? */
90 	}
91 
92 	return (err);
93 }
94 
95 void
96 smb_credinit(struct smb_cred *scred, cred_t *cr)
97 {
98 	/* cr arg is optional */
99 	if (cr == NULL)
100 		cr = ddi_get_cred();
101 	if (is_system_labeled()) {
102 		cr = crdup(cr);
103 		(void) setpflags(NET_MAC_AWARE, 1, cr);
104 	} else {
105 		crhold(cr);
106 	}
107 	scred->scr_cred = cr;
108 }
109 
110 void
111 smb_credrele(struct smb_cred *scred)
112 {
113 	if (scred->scr_cred != NULL) {
114 		crfree(scred->scr_cred);
115 		scred->scr_cred = NULL;
116 	}
117 }
118 
119 /*
120  * Helper for the SMBERROR macro, etc.
121  * This is also a good place for a breakpoint
122  * or a dtrace probe, i.e. fbt:nsmb:smb_errmsg
123  */
124 void
125 smb_errmsg(int cel, const char *func_name, const char *fmt, ...)
126 {
127 	va_list adx;
128 	char buf[100];
129 
130 	va_start(adx, fmt);
131 	if (cel == CE_CONT) {
132 		/*
133 		 * This is one of our xxxDEBUG macros.
134 		 * Don't bother to log these, but just
135 		 * fire a dtrace probe with the message.
136 		 */
137 		vsnprintf(buf, sizeof (buf), fmt, adx);
138 		DTRACE_PROBE2(debugmsg2,
139 		    (char *), func_name,
140 		    (char *), buf);
141 	} else {
142 		/*
143 		 * This is one of our xxxERROR macros.
144 		 * Add a prefix to the fmt string,
145 		 * then let vcmn_err do the args.
146 		 */
147 		snprintf(buf, sizeof (buf), "?%s: %s", func_name, fmt);
148 		DTRACE_PROBE3(debugmsg3,
149 		    (char *), func_name,
150 		    (char *), buf,
151 		    va_list, adx);
152 		vcmn_err(cel, buf, adx);
153 	}
154 	va_end(adx);
155 }
156 
157 #if 1 /* def SMB_SOCKETDATA_DEBUG */
158 void
159 m_dumpm(mblk_t *m)
160 {
161 	int len, seg;
162 
163 	len = msgdsize(m);
164 	DTRACE_PROBE2(dsize, int, len, (mblk_t *), m);
165 
166 	for (seg = 0; m; seg++) {
167 		DTRACE_PROBE2(mblk, int, seg, (mblk_t *), m);
168 		m = m->b_cont;
169 	}
170 }
171 #endif
172 
173 #ifndef EPROTO
174 #define	EPROTO ECONNABORTED
175 #endif
176 #ifndef ELIBACC
177 #define	ELIBACC ENOENT
178 #endif
179 #ifndef ENODATA
180 #define	ENODATA EINVAL
181 #endif
182 #ifndef ENOTUNIQ
183 #define	ENOTUNIQ EADDRINUSE
184 #endif
185 #ifndef ECOMM
186 #define	ECOMM EIO
187 #endif
188 #ifndef ENOMEDIUM
189 #define	ENOMEDIUM EIO
190 #endif
191 #ifndef ETIME
192 #define	ETIME ETIMEDOUT
193 #endif
194 
195 static struct {
196 	unsigned nterr;
197 	unsigned errno;
198 } nt2errno[] = {
199 	{NT_STATUS_ACCESS_DENIED,		EACCES},
200 	{NT_STATUS_ACCESS_VIOLATION,		EACCES},
201 	{NT_STATUS_ACCOUNT_DISABLED,		EACCES},
202 	{NT_STATUS_ACCOUNT_RESTRICTION,		EACCES},
203 	{NT_STATUS_ADDRESS_ALREADY_EXISTS,	EADDRINUSE},
204 	{NT_STATUS_BAD_NETWORK_NAME,		ENOENT},
205 	{NT_STATUS_BUFFER_TOO_SMALL,		EMOREDATA},
206 	{NT_STATUS_CANNOT_DELETE,		EACCES},
207 	{NT_STATUS_CONFLICTING_ADDRESSES,	EADDRINUSE},
208 	{NT_STATUS_CONNECTION_ABORTED,		ECONNABORTED},
209 	{NT_STATUS_CONNECTION_DISCONNECTED,	ECONNABORTED},
210 	{NT_STATUS_CONNECTION_REFUSED,		ECONNREFUSED},
211 	{NT_STATUS_CONNECTION_RESET,		ENETRESET},
212 	{NT_STATUS_DEVICE_DOES_NOT_EXIST,	ENODEV},
213 	{NT_STATUS_DEVICE_PROTOCOL_ERROR,	EPROTO},
214 	{NT_STATUS_DIRECTORY_NOT_EMPTY,		ENOTEMPTY},
215 	{NT_STATUS_DISK_FULL,			ENOSPC},
216 	{NT_STATUS_DLL_NOT_FOUND,		ELIBACC},
217 	{NT_STATUS_END_OF_FILE,			ENODATA},
218 	{NT_STATUS_FILE_IS_A_DIRECTORY,		EISDIR},
219 	{NT_STATUS_FLOAT_INEXACT_RESULT,	ERANGE},
220 	{NT_STATUS_FLOAT_OVERFLOW,		ERANGE},
221 	{NT_STATUS_FLOAT_UNDERFLOW,		ERANGE},
222 	{NT_STATUS_HOST_UNREACHABLE,		EHOSTUNREACH},
223 	{NT_STATUS_ILL_FORMED_PASSWORD,		EACCES},
224 	{NT_STATUS_INTEGER_OVERFLOW,		ERANGE},
225 	{NT_STATUS_INVALID_HANDLE,		EBADF},
226 	{NT_STATUS_INVALID_LOGON_HOURS,		EACCES},
227 	{NT_STATUS_INVALID_PARAMETER,		EINVAL},
228 	{NT_STATUS_INVALID_PIPE_STATE,		EPIPE},
229 	{NT_STATUS_INVALID_WORKSTATION,		EACCES},
230 	{NT_STATUS_IN_PAGE_ERROR,		EFAULT},
231 	{NT_STATUS_IO_TIMEOUT,			ETIMEDOUT},
232 	{NT_STATUS_IP_ADDRESS_CONFLICT1,	ENOTUNIQ},
233 	{NT_STATUS_IP_ADDRESS_CONFLICT2,	ENOTUNIQ},
234 	{NT_STATUS_LICENSE_QUOTA_EXCEEDED,	EDQUOT},
235 	{NT_STATUS_LOGON_FAILURE,		EACCES},
236 	{NT_STATUS_MEDIA_WRITE_PROTECTED,	EROFS},
237 	{NT_STATUS_MEMORY_NOT_ALLOCATED,	EFAULT},
238 	{NT_STATUS_NAME_TOO_LONG,		ENAMETOOLONG},
239 	{NT_STATUS_NETWORK_ACCESS_DENIED,	EACCES},
240 	{NT_STATUS_NETWORK_BUSY,		EBUSY},
241 	{NT_STATUS_NETWORK_UNREACHABLE,		ENETUNREACH},
242 	{NT_STATUS_NET_WRITE_FAULT,		ECOMM},
243 	{NT_STATUS_NONEXISTENT_SECTOR,		ESPIPE},
244 	{NT_STATUS_NOT_A_DIRECTORY,		ENOTDIR},
245 	{NT_STATUS_NOT_IMPLEMENTED,		ENOSYS},
246 	{NT_STATUS_NOT_MAPPED_VIEW,		EINVAL},
247 	{NT_STATUS_NOT_SUPPORTED,		ENOSYS},
248 	{NT_STATUS_NO_MEDIA,			ENOMEDIUM},
249 	{NT_STATUS_NO_MEDIA_IN_DEVICE,		ENOMEDIUM},
250 	{NT_STATUS_NO_MEMORY,			ENOMEM},
251 	{NT_STATUS_NO_SUCH_DEVICE,		ENODEV},
252 	{NT_STATUS_NO_SUCH_FILE,		ENOENT},
253 	{NT_STATUS_OBJECT_NAME_COLLISION,	EEXIST},
254 	{NT_STATUS_OBJECT_NAME_NOT_FOUND,	ENOENT},
255 	{NT_STATUS_OBJECT_NAME_INVALID,		EINVAL},
256 	{NT_STATUS_OBJECT_PATH_INVALID,		ENOTDIR},
257 	{NT_STATUS_PAGEFILE_QUOTA,		EDQUOT},
258 	{NT_STATUS_PASSWORD_EXPIRED,		EACCES},
259 	{NT_STATUS_PASSWORD_RESTRICTION,	EACCES},
260 	{NT_STATUS_PATH_NOT_COVERED,		ENOENT},
261 	{NT_STATUS_PIPE_BROKEN,			EPIPE},
262 	{NT_STATUS_PIPE_BUSY,			EPIPE},
263 	{NT_STATUS_PIPE_CONNECTED,		EISCONN},
264 	{NT_STATUS_PIPE_DISCONNECTED,		EPIPE},
265 	{NT_STATUS_PIPE_NOT_AVAILABLE,		ENOSYS},
266 	{NT_STATUS_PORT_CONNECTION_REFUSED,	ECONNREFUSED},
267 	{NT_STATUS_PORT_MESSAGE_TOO_LONG,	EMSGSIZE},
268 	{NT_STATUS_PORT_UNREACHABLE,		EHOSTUNREACH},
269 	{NT_STATUS_PROTOCOL_UNREACHABLE,	ENOPROTOOPT},
270 	{NT_STATUS_QUOTA_EXCEEDED,		EDQUOT},
271 	{NT_STATUS_REGISTRY_QUOTA_LIMIT,	EDQUOT},
272 	{NT_STATUS_REMOTE_DISCONNECT,		ESHUTDOWN},
273 	{NT_STATUS_REMOTE_NOT_LISTENING,	ECONNREFUSED},
274 	{NT_STATUS_REQUEST_NOT_ACCEPTED,	EACCES},
275 	{NT_STATUS_RETRY,			EAGAIN},
276 	{NT_STATUS_SHARING_VIOLATION,		EBUSY},
277 	{NT_STATUS_TIMER_NOT_CANCELED,		ETIME},
278 	{NT_STATUS_TOO_MANY_LINKS,		EMLINK},
279 	{NT_STATUS_TOO_MANY_OPENED_FILES,	EMFILE},
280 	{NT_STATUS_UNABLE_TO_FREE_VM,		EADDRINUSE},
281 	{NT_STATUS_UNSUCCESSFUL,		EINVAL},
282 	{NT_STATUS_WRONG_PASSWORD,		EACCES},
283 	{0,	0}
284 };
285 
286 static struct {
287 	unsigned dclass;
288 	unsigned derr;
289 	unsigned nterr;
290 } nt2doserr[] = {
291 	{ERRDOS,	ERRgeneral,	NT_STATUS_UNSUCCESSFUL},
292 	{ERRDOS,	ERRbadfunc,	NT_STATUS_NOT_IMPLEMENTED},
293 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_INFO_CLASS},
294 	{ERRDOS,	ERRbadlength,	NT_STATUS_INFO_LENGTH_MISMATCH},
295 	{ERRHRD,	ERRgeneral,	NT_STATUS_ACCESS_VIOLATION},
296 	{ERRHRD,	ERRgeneral,	NT_STATUS_IN_PAGE_ERROR},
297 	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_QUOTA},
298 	{ERRDOS,	ERRbadfid,	NT_STATUS_INVALID_HANDLE},
299 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_INITIAL_STACK},
300 	{ERRDOS,	193,	NT_STATUS_BAD_INITIAL_PC},
301 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_CID},
302 	{ERRHRD,	ERRgeneral,	NT_STATUS_TIMER_NOT_CANCELED},
303 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER},
304 	{ERRDOS,	ERRbadfile,	NT_STATUS_NO_SUCH_DEVICE},
305 	{ERRDOS,	ERRbadfile,	NT_STATUS_NO_SUCH_FILE},
306 	{ERRDOS,	ERRbadfunc,	NT_STATUS_INVALID_DEVICE_REQUEST},
307 	{ERRDOS,	ERRhandleeof,	NT_STATUS_END_OF_FILE},
308 	{ERRDOS,	ERRwrongdisk,	NT_STATUS_WRONG_VOLUME},
309 	{ERRDOS,	ERRnotready,	NT_STATUS_NO_MEDIA_IN_DEVICE},
310 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNRECOGNIZED_MEDIA},
311 	{ERRDOS,	ERRsectornotfound,	NT_STATUS_NONEXISTENT_SECTOR},
312 	{ERRDOS,	ERRnomem,	NT_STATUS_NO_MEMORY},
313 	{ERRDOS,	487,	NT_STATUS_CONFLICTING_ADDRESSES},
314 	{ERRDOS,	487,	NT_STATUS_NOT_MAPPED_VIEW},
315 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_UNABLE_TO_FREE_VM},
316 	{ERRDOS,	ERRinvalidparam, NT_STATUS_UNABLE_TO_DELETE_SECTION},
317 	{ERRDOS,	2142,	NT_STATUS_INVALID_SYSTEM_SERVICE},
318 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_INSTRUCTION},
319 	{ERRDOS,	ERRnoaccess,	NT_STATUS_INVALID_LOCK_SEQUENCE},
320 	{ERRDOS,	ERRnoaccess,	NT_STATUS_INVALID_VIEW_SIZE},
321 	{ERRDOS,	193,	NT_STATUS_INVALID_FILE_FOR_SECTION},
322 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ALREADY_COMMITTED},
323 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ACCESS_DENIED},
324 	{ERRDOS,	111,	NT_STATUS_BUFFER_TOO_SMALL},
325 	{ERRDOS,	ERRbadfid,	NT_STATUS_OBJECT_TYPE_MISMATCH},
326 	{ERRHRD,	ERRgeneral,	NT_STATUS_NONCONTINUABLE_EXCEPTION},
327 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DISPOSITION},
328 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNWIND},
329 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_STACK},
330 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_UNWIND_TARGET},
331 	{ERRDOS,	158,	NT_STATUS_NOT_LOCKED},
332 	{ERRHRD,	ERRgeneral,	NT_STATUS_PARITY_ERROR},
333 	{ERRDOS,	487,	NT_STATUS_UNABLE_TO_DECOMMIT_VM},
334 	{ERRDOS,	487,	NT_STATUS_NOT_COMMITTED},
335 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PORT_ATTRIBUTES},
336 	{ERRHRD,	ERRgeneral,	NT_STATUS_PORT_MESSAGE_TOO_LONG},
337 	{ERRDOS,	ERRinvalidparam, NT_STATUS_INVALID_PARAMETER_MIX},
338 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_QUOTA_LOWER},
339 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_CORRUPT_ERROR},
340 	{ERRDOS,	ERRinvalidname,	NT_STATUS_OBJECT_NAME_INVALID},
341 	{ERRDOS,	ERRbadfile,	NT_STATUS_OBJECT_NAME_NOT_FOUND},
342 	{ERRDOS,	183,	NT_STATUS_OBJECT_NAME_COLLISION},
343 	{ERRHRD,	ERRgeneral,	NT_STATUS_HANDLE_NOT_WAITABLE},
344 	{ERRDOS,	ERRbadfid,	NT_STATUS_PORT_DISCONNECTED},
345 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_ALREADY_ATTACHED},
346 	{ERRDOS,	161,	NT_STATUS_OBJECT_PATH_INVALID},
347 	{ERRDOS,	ERRbadpath,	NT_STATUS_OBJECT_PATH_NOT_FOUND},
348 	{ERRDOS,	161,	NT_STATUS_OBJECT_PATH_SYNTAX_BAD},
349 	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_OVERRUN},
350 	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_LATE_ERROR},
351 	{ERRDOS,	ERRcrc,	NT_STATUS_DATA_ERROR},
352 	{ERRDOS,	ERRcrc,	NT_STATUS_CRC_ERROR},
353 	{ERRDOS,	ERRnomem,	NT_STATUS_SECTION_TOO_BIG},
354 	{ERRDOS,	ERRnoaccess,	NT_STATUS_PORT_CONNECTION_REFUSED},
355 	{ERRDOS,	ERRbadfid,	NT_STATUS_INVALID_PORT_HANDLE},
356 	{ERRDOS,	ERRbadshare,	NT_STATUS_SHARING_VIOLATION},
357 	{ERRHRD,	ERRgeneral,	NT_STATUS_QUOTA_EXCEEDED},
358 	{ERRDOS,	ERRinvalidparam, NT_STATUS_INVALID_PAGE_PROTECTION},
359 	{ERRDOS,	288,	NT_STATUS_MUTANT_NOT_OWNED},
360 	{ERRDOS,	298,	NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED},
361 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_PORT_ALREADY_SET},
362 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_SECTION_NOT_IMAGE},
363 	{ERRDOS,	156,	NT_STATUS_SUSPEND_COUNT_EXCEEDED},
364 	{ERRDOS,	ERRnoaccess,	NT_STATUS_THREAD_IS_TERMINATING},
365 	{ERRDOS,	ERRinvalidparam, NT_STATUS_BAD_WORKING_SET_LIMIT},
366 	{ERRDOS,	ERRinvalidparam, NT_STATUS_INCOMPATIBLE_FILE_MAP},
367 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_SECTION_PROTECTION},
368 	{ERRDOS,	282,	NT_STATUS_EAS_NOT_SUPPORTED},
369 	{ERRDOS,	255,	NT_STATUS_EA_TOO_LARGE},
370 	{ERRHRD,	ERRgeneral,	NT_STATUS_NONEXISTENT_EA_ENTRY},
371 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_EAS_ON_FILE},
372 	{ERRHRD,	ERRgeneral,	NT_STATUS_EA_CORRUPT_ERROR},
373 	{ERRDOS,	ERRlock,	NT_STATUS_FILE_LOCK_CONFLICT},
374 	{ERRDOS,	ERRlock,	NT_STATUS_LOCK_NOT_GRANTED},
375 	{ERRDOS,	ERRnoaccess,	NT_STATUS_DELETE_PENDING},
376 	{ERRDOS,	ERRunsup,	NT_STATUS_CTL_FILE_NOT_SUPPORTED},
377 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNKNOWN_REVISION},
378 	{ERRHRD,	ERRgeneral,	NT_STATUS_REVISION_MISMATCH},
379 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_OWNER},
380 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PRIMARY_GROUP},
381 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_IMPERSONATION_TOKEN},
382 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_DISABLE_MANDATORY},
383 	{ERRDOS,	2215,	NT_STATUS_NO_LOGON_SERVERS},
384 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_LOGON_SESSION},
385 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_PRIVILEGE},
386 	{ERRDOS,	ERRnoaccess,	NT_STATUS_PRIVILEGE_NOT_HELD},
387 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ACCOUNT_NAME},
388 	{ERRHRD,	ERRgeneral,	NT_STATUS_USER_EXISTS},
389 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_SUCH_USER},
390 	{ERRHRD,	ERRgeneral,	NT_STATUS_GROUP_EXISTS},
391 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_GROUP},
392 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_IN_GROUP},
393 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_NOT_IN_GROUP},
394 	{ERRHRD,	ERRgeneral,	NT_STATUS_LAST_ADMIN},
395 	{ERRSRV,	ERRbadpw,	NT_STATUS_WRONG_PASSWORD},
396 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILL_FORMED_PASSWORD},
397 	{ERRHRD,	ERRgeneral,	NT_STATUS_PASSWORD_RESTRICTION},
398 	{ERRDOS,	ERRnoaccess,	NT_STATUS_LOGON_FAILURE},
399 	{ERRHRD,	ERRgeneral,	NT_STATUS_ACCOUNT_RESTRICTION},
400 	{ERRSRV,	2241,	NT_STATUS_INVALID_LOGON_HOURS},
401 	{ERRSRV,	2240,	NT_STATUS_INVALID_WORKSTATION},
402 	{ERRSRV,	2242,	NT_STATUS_PASSWORD_EXPIRED},
403 	{ERRSRV,	2239,	NT_STATUS_ACCOUNT_DISABLED},
404 	{ERRHRD,	ERRgeneral,	NT_STATUS_NONE_MAPPED},
405 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_LUIDS_REQUESTED},
406 	{ERRHRD,	ERRgeneral,	NT_STATUS_LUIDS_EXHAUSTED},
407 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SUB_AUTHORITY},
408 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ACL},
409 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SID},
410 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SECURITY_DESCR},
411 	{ERRDOS,	127,	NT_STATUS_PROCEDURE_NOT_FOUND},
412 	{ERRDOS,	193,	NT_STATUS_INVALID_IMAGE_FORMAT},
413 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_TOKEN},
414 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_INHERITANCE_ACL},
415 	{ERRDOS,	158,	NT_STATUS_RANGE_NOT_LOCKED},
416 	{ERRDOS,	112,	NT_STATUS_DISK_FULL},
417 	{ERRHRD,	ERRgeneral,	NT_STATUS_SERVER_DISABLED},
418 	{ERRHRD,	ERRgeneral,	NT_STATUS_SERVER_NOT_DISABLED},
419 	{ERRDOS,	ERRtoomanynames, NT_STATUS_TOO_MANY_GUIDS_REQUESTED},
420 	{ERRDOS,	259,	NT_STATUS_GUIDS_EXHAUSTED},
421 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ID_AUTHORITY},
422 	{ERRDOS,	259,	NT_STATUS_AGENTS_EXHAUSTED},
423 	{ERRDOS,	154,	NT_STATUS_INVALID_VOLUME_LABEL},
424 	{ERRDOS,	ERRoutofmem,	NT_STATUS_SECTION_NOT_EXTENDED},
425 	{ERRDOS,	487,	NT_STATUS_NOT_MAPPED_DATA},
426 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_DATA_NOT_FOUND},
427 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_TYPE_NOT_FOUND},
428 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_NAME_NOT_FOUND},
429 	{ERRHRD,	ERRgeneral,	NT_STATUS_ARRAY_BOUNDS_EXCEEDED},
430 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_DENORMAL_OPERAND},
431 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_DIVIDE_BY_ZERO},
432 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_INEXACT_RESULT},
433 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_INVALID_OPERATION},
434 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_OVERFLOW},
435 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_STACK_CHECK},
436 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_UNDERFLOW},
437 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTEGER_DIVIDE_BY_ZERO},
438 	{ERRDOS,	534,	NT_STATUS_INTEGER_OVERFLOW},
439 	{ERRHRD,	ERRgeneral,	NT_STATUS_PRIVILEGED_INSTRUCTION},
440 	{ERRDOS,	ERRnomem,	NT_STATUS_TOO_MANY_PAGING_FILES},
441 	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_INVALID},
442 	{ERRHRD,	ERRgeneral,	NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
443 	{ERRDOS,	ERRnomem,	NT_STATUS_INSUFFICIENT_RESOURCES},
444 	{ERRDOS,	ERRbadpath,	NT_STATUS_DFS_EXIT_PATH_FOUND},
445 	{ERRDOS,	ERRcrc,	NT_STATUS_DEVICE_DATA_ERROR},
446 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_NOT_CONNECTED},
447 	{ERRDOS,	ERRnotready,	NT_STATUS_DEVICE_POWER_FAILURE},
448 	{ERRDOS,	487,	NT_STATUS_FREE_VM_NOT_AT_BASE},
449 	{ERRDOS,	487,	NT_STATUS_MEMORY_NOT_ALLOCATED},
450 	{ERRHRD,	ERRgeneral,	NT_STATUS_WORKING_SET_QUOTA},
451 	{ERRDOS,	ERRwriteprotect, NT_STATUS_MEDIA_WRITE_PROTECTED},
452 	{ERRDOS,	ERRnotready,	NT_STATUS_DEVICE_NOT_READY},
453 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_GROUP_ATTRIBUTES},
454 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_IMPERSONATION_LEVEL},
455 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_OPEN_ANONYMOUS},
456 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_VALIDATION_CLASS},
457 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_TOKEN_TYPE},
458 	{ERRDOS,	ERRinvalidparam, NT_STATUS_BAD_MASTER_BOOT_RECORD},
459 	{ERRHRD,	ERRgeneral,	NT_STATUS_INSTRUCTION_MISALIGNMENT},
460 	{ERRDOS,	ERRpipebusy,	NT_STATUS_INSTANCE_NOT_AVAILABLE},
461 	{ERRDOS,	ERRpipebusy,	NT_STATUS_PIPE_NOT_AVAILABLE},
462 	{ERRDOS,	ERRbadpipe,	NT_STATUS_INVALID_PIPE_STATE},
463 	{ERRDOS,	ERRpipebusy,	NT_STATUS_PIPE_BUSY},
464 	{ERRDOS,	ERRbadfunc,	NT_STATUS_ILLEGAL_FUNCTION},
465 	{ERRDOS,	ERRnotconnected,	NT_STATUS_PIPE_DISCONNECTED},
466 	{ERRDOS,	ERRpipeclosing,	NT_STATUS_PIPE_CLOSING},
467 	{ERRHRD,	ERRgeneral,	NT_STATUS_PIPE_CONNECTED},
468 	{ERRHRD,	ERRgeneral,	NT_STATUS_PIPE_LISTENING},
469 	{ERRDOS,	ERRbadpipe,	NT_STATUS_INVALID_READ_MODE},
470 	{ERRDOS,	121,	NT_STATUS_IO_TIMEOUT},
471 	{ERRDOS,	ERRhandleeof,	NT_STATUS_FILE_FORCED_CLOSED},
472 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROFILING_NOT_STARTED},
473 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROFILING_NOT_STOPPED},
474 	{ERRHRD,	ERRgeneral,	NT_STATUS_COULD_NOT_INTERPRET},
475 	{ERRDOS,	ERRnoaccess,	NT_STATUS_FILE_IS_A_DIRECTORY},
476 	{ERRDOS,	ERRunsup,	NT_STATUS_NOT_SUPPORTED},
477 	{ERRDOS,	51,	NT_STATUS_REMOTE_NOT_LISTENING},
478 	{ERRDOS,	52,	NT_STATUS_DUPLICATE_NAME},
479 	{ERRDOS,	53,	NT_STATUS_BAD_NETWORK_PATH},
480 	{ERRDOS,	54,	NT_STATUS_NETWORK_BUSY},
481 	{ERRDOS,	55,	NT_STATUS_DEVICE_DOES_NOT_EXIST},
482 	{ERRDOS,	56,	NT_STATUS_TOO_MANY_COMMANDS},
483 	{ERRDOS,	57,	NT_STATUS_ADAPTER_HARDWARE_ERROR},
484 	{ERRDOS,	58,	NT_STATUS_INVALID_NETWORK_RESPONSE},
485 	{ERRDOS,	59,	NT_STATUS_UNEXPECTED_NETWORK_ERROR},
486 	{ERRDOS,	60,	NT_STATUS_BAD_REMOTE_ADAPTER},
487 	{ERRDOS,	61,	NT_STATUS_PRINT_QUEUE_FULL},
488 	{ERRDOS,	62,	NT_STATUS_NO_SPOOL_SPACE},
489 	{ERRDOS,	63,	NT_STATUS_PRINT_CANCELLED},
490 	{ERRDOS,	64,	NT_STATUS_NETWORK_NAME_DELETED},
491 	{ERRDOS,	65,	NT_STATUS_NETWORK_ACCESS_DENIED},
492 	{ERRDOS,	66,	NT_STATUS_BAD_DEVICE_TYPE},
493 	{ERRDOS,	ERRnosuchshare,	NT_STATUS_BAD_NETWORK_NAME},
494 	{ERRDOS,	68,	NT_STATUS_TOO_MANY_NAMES},
495 	{ERRDOS,	69,	NT_STATUS_TOO_MANY_SESSIONS},
496 	{ERRDOS,	70,	NT_STATUS_SHARING_PAUSED},
497 	{ERRDOS,	71,	NT_STATUS_REQUEST_NOT_ACCEPTED},
498 	{ERRDOS,	72,	NT_STATUS_REDIRECTOR_PAUSED},
499 	{ERRDOS,	88,	NT_STATUS_NET_WRITE_FAULT},
500 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROFILING_AT_LIMIT},
501 	{ERRDOS,	ERRdiffdevice,	NT_STATUS_NOT_SAME_DEVICE},
502 	{ERRDOS,	ERRnoaccess,	NT_STATUS_FILE_RENAMED},
503 	{ERRDOS,	240,	NT_STATUS_VIRTUAL_CIRCUIT_CLOSED},
504 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SECURITY_ON_OBJECT},
505 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_WAIT},
506 	{ERRDOS,	ERRpipeclosing,	NT_STATUS_PIPE_EMPTY},
507 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_ACCESS_DOMAIN_INFO},
508 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_TERMINATE_SELF},
509 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SERVER_STATE},
510 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DOMAIN_STATE},
511 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DOMAIN_ROLE},
512 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_DOMAIN},
513 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_EXISTS},
514 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_LIMIT_EXCEEDED},
515 	{ERRDOS,	300,	NT_STATUS_OPLOCK_NOT_GRANTED},
516 	{ERRDOS,	301,	NT_STATUS_INVALID_OPLOCK_PROTOCOL},
517 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTERNAL_DB_CORRUPTION},
518 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTERNAL_ERROR},
519 	{ERRHRD,	ERRgeneral,	NT_STATUS_GENERIC_NOT_MAPPED},
520 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_DESCRIPTOR_FORMAT},
521 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_USER_BUFFER},
522 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_IO_ERROR},
523 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_MM_CREATE_ERR},
524 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_MM_MAP_ERROR},
525 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNEXPECTED_MM_EXTEND_ERR},
526 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_LOGON_PROCESS},
527 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_SESSION_EXISTS},
528 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_1},
529 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_2},
530 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_3},
531 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_4},
532 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_5},
533 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_6},
534 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_7},
535 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_8},
536 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_9},
537 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_10},
538 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_11},
539 	{ERRDOS,	ERRinvalidparam,	NT_STATUS_INVALID_PARAMETER_12},
540 	{ERRDOS,	ERRbadpath,	NT_STATUS_REDIRECTOR_NOT_STARTED},
541 	{ERRHRD,	ERRgeneral,	NT_STATUS_REDIRECTOR_STARTED},
542 	{ERRHRD,	ERRgeneral,	NT_STATUS_STACK_OVERFLOW},
543 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_PACKAGE},
544 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_FUNCTION_TABLE},
545 	{ERRDOS,	203,	NT_STATUS_VARIABLE_NOT_FOUND},
546 	{ERRDOS,	145,	NT_STATUS_DIRECTORY_NOT_EMPTY},
547 	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_CORRUPT_ERROR},
548 	{ERRDOS,	267,	NT_STATUS_NOT_A_DIRECTORY},
549 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_LOGON_SESSION_STATE},
550 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_SESSION_COLLISION},
551 	{ERRDOS,	206,	NT_STATUS_NAME_TOO_LONG},
552 	{ERRDOS,	2401,	NT_STATUS_FILES_OPEN},
553 	{ERRDOS,	2404,	NT_STATUS_CONNECTION_IN_USE},
554 	{ERRHRD,	ERRgeneral,	NT_STATUS_MESSAGE_NOT_FOUND},
555 	{ERRDOS,	ERRnoaccess,	NT_STATUS_PROCESS_IS_TERMINATING},
556 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LOGON_TYPE},
557 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_GUID_TRANSLATION},
558 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANNOT_IMPERSONATE},
559 	{ERRHRD,	ERRgeneral,	NT_STATUS_IMAGE_ALREADY_LOADED},
560 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_NOT_PRESENT},
561 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_LID_NOT_EXIST},
562 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_LID_ALREADY_OWNED},
563 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_NOT_LID_OWNER},
564 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_INVALID_COMMAND},
565 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_INVALID_LID},
566 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE},
567 	{ERRHRD,	ERRgeneral,	NT_STATUS_ABIOS_INVALID_SELECTOR},
568 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_LDT},
569 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LDT_SIZE},
570 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LDT_OFFSET},
571 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_LDT_DESCRIPTOR},
572 	{ERRDOS,	193,	NT_STATUS_INVALID_IMAGE_NE_FORMAT},
573 	{ERRHRD,	ERRgeneral,	NT_STATUS_RXACT_INVALID_STATE},
574 	{ERRHRD,	ERRgeneral,	NT_STATUS_RXACT_COMMIT_FAILURE},
575 	{ERRHRD,	ERRgeneral,	NT_STATUS_MAPPED_FILE_SIZE_ZERO},
576 	{ERRDOS,	ERRnofids,	NT_STATUS_TOO_MANY_OPENED_FILES},
577 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANCELLED},
578 	{ERRDOS,	ERRnoaccess,	NT_STATUS_CANNOT_DELETE},
579 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_COMPUTER_NAME},
580 	{ERRDOS,	ERRnoaccess,	NT_STATUS_FILE_DELETED},
581 	{ERRHRD,	ERRgeneral,	NT_STATUS_SPECIAL_ACCOUNT},
582 	{ERRHRD,	ERRgeneral,	NT_STATUS_SPECIAL_GROUP},
583 	{ERRHRD,	ERRgeneral,	NT_STATUS_SPECIAL_USER},
584 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBERS_PRIMARY_GROUP},
585 	{ERRDOS,	ERRbadfid,	NT_STATUS_FILE_CLOSED},
586 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_THREADS},
587 	{ERRHRD,	ERRgeneral,	NT_STATUS_THREAD_NOT_IN_PROCESS},
588 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOKEN_ALREADY_IN_USE},
589 	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_QUOTA_EXCEEDED},
590 	{ERRHRD,	ERRgeneral,	NT_STATUS_COMMITMENT_LIMIT},
591 	{ERRDOS,	193,	NT_STATUS_INVALID_IMAGE_LE_FORMAT},
592 	{ERRDOS,	193,	NT_STATUS_INVALID_IMAGE_NOT_MZ},
593 	{ERRDOS,	193,	NT_STATUS_INVALID_IMAGE_PROTECT},
594 	{ERRDOS,	193,	NT_STATUS_INVALID_IMAGE_WIN_16},
595 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_SERVER_CONFLICT},
596 	{ERRHRD,	ERRgeneral,	NT_STATUS_TIME_DIFFERENCE_AT_DC},
597 	{ERRHRD,	ERRgeneral,	NT_STATUS_SYNCHRONIZATION_REQUIRED},
598 	{ERRDOS,	126,	NT_STATUS_DLL_NOT_FOUND},
599 	{ERRHRD,	ERRgeneral,	NT_STATUS_OPEN_FAILED},
600 	{ERRHRD,	ERRgeneral,	NT_STATUS_IO_PRIVILEGE_FAILED},
601 	{ERRDOS,	182,	NT_STATUS_ORDINAL_NOT_FOUND},
602 	{ERRDOS,	127,	NT_STATUS_ENTRYPOINT_NOT_FOUND},
603 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONTROL_C_EXIT},
604 	{ERRDOS,	64,	NT_STATUS_LOCAL_DISCONNECT},
605 	{ERRDOS,	64,	NT_STATUS_REMOTE_DISCONNECT},
606 	{ERRDOS,	51,	NT_STATUS_REMOTE_RESOURCES},
607 	{ERRDOS,	59,	NT_STATUS_LINK_FAILED},
608 	{ERRDOS,	59,	NT_STATUS_LINK_TIMEOUT},
609 	{ERRDOS,	59,	NT_STATUS_INVALID_CONNECTION},
610 	{ERRDOS,	59,	NT_STATUS_INVALID_ADDRESS},
611 	{ERRHRD,	ERRgeneral,	NT_STATUS_DLL_INIT_FAILED},
612 	{ERRHRD,	ERRgeneral,	NT_STATUS_MISSING_SYSTEMFILE},
613 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNHANDLED_EXCEPTION},
614 	{ERRHRD,	ERRgeneral,	NT_STATUS_APP_INIT_FAILURE},
615 	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_CREATE_FAILED},
616 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_PAGEFILE},
617 	{ERRDOS,	124,	NT_STATUS_INVALID_LEVEL},
618 	{ERRDOS,	86,	NT_STATUS_WRONG_PASSWORD_CORE},
619 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_FLOAT_CONTEXT},
620 	{ERRDOS,	109,	NT_STATUS_PIPE_BROKEN},
621 	{ERRHRD,	ERRgeneral,	NT_STATUS_REGISTRY_CORRUPT},
622 	{ERRHRD,	ERRgeneral,	NT_STATUS_REGISTRY_IO_FAILED},
623 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_EVENT_PAIR},
624 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNRECOGNIZED_VOLUME},
625 	{ERRHRD,	ERRgeneral,	NT_STATUS_SERIAL_NO_DEVICE_INITED},
626 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_ALIAS},
627 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_NOT_IN_ALIAS},
628 	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_IN_ALIAS},
629 	{ERRHRD,	ERRgeneral,	NT_STATUS_ALIAS_EXISTS},
630 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGON_NOT_GRANTED},
631 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_SECRETS},
632 	{ERRHRD,	ERRgeneral,	NT_STATUS_SECRET_TOO_LONG},
633 	{ERRHRD,	ERRgeneral,	NT_STATUS_INTERNAL_DB_ERROR},
634 	{ERRHRD,	ERRgeneral,	NT_STATUS_FULLSCREEN_MODE},
635 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_CONTEXT_IDS},
636 	{ERRDOS,	ERRnoaccess,	NT_STATUS_LOGON_TYPE_NOT_GRANTED},
637 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_REGISTRY_FILE},
638 	{ERRHRD,	ERRgeneral,	NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED},
639 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR},
640 	{ERRHRD,	ERRgeneral,	NT_STATUS_FT_MISSING_MEMBER},
641 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILL_FORMED_SERVICE_ENTRY},
642 	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_CHARACTER},
643 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNMAPPABLE_CHARACTER},
644 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNDEFINED_CHARACTER},
645 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_VOLUME},
646 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND},
647 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_WRONG_CYLINDER},
648 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_UNKNOWN_ERROR},
649 	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOPPY_BAD_REGISTERS},
650 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_RECALIBRATE_FAILED},
651 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_OPERATION_FAILED},
652 	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_RESET_FAILED},
653 	{ERRHRD,	ERRgeneral,	NT_STATUS_SHARED_IRQ_BUSY},
654 	{ERRHRD,	ERRgeneral,	NT_STATUS_FT_ORPHANING},
655 	{ERRHRD,	ERRgeneral, NT_STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT},
656 	{ERRHRD,	ERRgeneral,	NT_STATUS_16F},
657 	{ERRHRD,	ERRgeneral,	NT_STATUS_170},
658 	{ERRHRD,	ERRgeneral,	NT_STATUS_171},
659 	{ERRHRD,	ERRgeneral,	NT_STATUS_PARTITION_FAILURE},
660 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_BLOCK_LENGTH},
661 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_NOT_PARTITIONED},
662 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNABLE_TO_LOCK_MEDIA},
663 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNABLE_TO_UNLOAD_MEDIA},
664 	{ERRHRD,	ERRgeneral,	NT_STATUS_EOM_OVERFLOW},
665 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_MEDIA},
666 	{ERRHRD,	ERRgeneral,	NT_STATUS_179},
667 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_MEMBER},
668 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_MEMBER},
669 	{ERRHRD,	ERRgeneral,	NT_STATUS_KEY_DELETED},
670 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_LOG_SPACE},
671 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_SIDS},
672 	{ERRHRD,	ERRgeneral,	NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED},
673 	{ERRHRD,	ERRgeneral,	NT_STATUS_KEY_HAS_CHILDREN},
674 	{ERRHRD,	ERRgeneral,	NT_STATUS_CHILD_MUST_BE_VOLATILE},
675 	{ERRDOS,	ERRinvalidparam, NT_STATUS_DEVICE_CONFIGURATION_ERROR},
676 	{ERRHRD,	ERRgeneral,	NT_STATUS_DRIVER_INTERNAL_ERROR},
677 	{ERRDOS,	ERRbadcmd,	NT_STATUS_INVALID_DEVICE_STATE},
678 	{ERRHRD,	ERRgeneral,	NT_STATUS_IO_DEVICE_ERROR},
679 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_PROTOCOL_ERROR},
680 	{ERRHRD,	ERRgeneral,	NT_STATUS_BACKUP_CONTROLLER},
681 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOG_FILE_FULL},
682 	{ERRDOS,	ERRwriteprotect,	NT_STATUS_TOO_LATE},
683 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_TRUST_LSA_SECRET},
684 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_TRUST_SAM_ACCOUNT},
685 	{ERRDOS,	ERRnoaccess,	NT_STATUS_TRUSTED_DOMAIN_FAILURE},
686 	{ERRDOS,	ERRnoaccess,	NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE},
687 	{ERRHRD,	ERRgeneral,	NT_STATUS_EVENTLOG_FILE_CORRUPT},
688 	{ERRHRD,	ERRgeneral,	NT_STATUS_EVENTLOG_CANT_START},
689 	{ERRDOS,	ERRnoaccess,	NT_STATUS_TRUST_FAILURE},
690 	{ERRHRD,	ERRgeneral,	NT_STATUS_MUTANT_LIMIT_EXCEEDED},
691 	{ERRDOS,	ERRinvgroup,	NT_STATUS_NETLOGON_NOT_STARTED},
692 	{ERRSRV,	2239,	NT_STATUS_ACCOUNT_EXPIRED},
693 	{ERRHRD,	ERRgeneral,	NT_STATUS_POSSIBLE_DEADLOCK},
694 	{ERRHRD,	ERRgeneral,	NT_STATUS_NETWORK_CREDENTIAL_CONFLICT},
695 	{ERRHRD,	ERRgeneral,	NT_STATUS_REMOTE_SESSION_LIMIT},
696 	{ERRHRD,	ERRgeneral,	NT_STATUS_EVENTLOG_FILE_CHANGED},
697 	{ERRDOS,	ERRnoaccess,
698 	    NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT},
699 	{ERRDOS,	ERRnoaccess,
700 		NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT},
701 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
702 	{ERRDOS,	ERRnoaccess,	NT_STATUS_DOMAIN_TRUST_INCONSISTENT},
703 	{ERRHRD,	ERRgeneral,	NT_STATUS_FS_DRIVER_REQUIRED},
704 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_USER_SESSION_KEY},
705 	{ERRDOS,	59,	NT_STATUS_USER_SESSION_DELETED},
706 	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_LANG_NOT_FOUND},
707 	{ERRDOS,	ERRnomem,	NT_STATUS_INSUFF_SERVER_RESOURCES},
708 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_BUFFER_SIZE},
709 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ADDRESS_COMPONENT},
710 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ADDRESS_WILDCARD},
711 	{ERRDOS,	68,	NT_STATUS_TOO_MANY_ADDRESSES},
712 	{ERRDOS,	52,	NT_STATUS_ADDRESS_ALREADY_EXISTS},
713 	{ERRDOS,	64,	NT_STATUS_ADDRESS_CLOSED},
714 	{ERRDOS,	64,	NT_STATUS_CONNECTION_DISCONNECTED},
715 	{ERRDOS,	64,	NT_STATUS_CONNECTION_RESET},
716 	{ERRDOS,	68,	NT_STATUS_TOO_MANY_NODES},
717 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_ABORTED},
718 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_TIMED_OUT},
719 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_NO_RELEASE},
720 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_NO_MATCH},
721 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_RESPONDED},
722 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_INVALID_ID},
723 	{ERRDOS,	59,	NT_STATUS_TRANSACTION_INVALID_TYPE},
724 	{ERRDOS,	ERRunsup,	NT_STATUS_NOT_SERVER_SESSION},
725 	{ERRDOS,	ERRunsup,	NT_STATUS_NOT_CLIENT_SESSION},
726 	{ERRHRD,	ERRgeneral,	NT_STATUS_CANNOT_LOAD_REGISTRY_FILE},
727 	{ERRHRD,	ERRgeneral,	NT_STATUS_DEBUG_ATTACH_FAILED},
728 	{ERRHRD,	ERRgeneral,	NT_STATUS_SYSTEM_PROCESS_TERMINATED},
729 	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_NOT_ACCEPTED},
730 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_BROWSER_SERVERS_FOUND},
731 	{ERRHRD,	ERRgeneral,	NT_STATUS_VDM_HARD_ERROR},
732 	{ERRHRD,	ERRgeneral,	NT_STATUS_DRIVER_CANCEL_TIMEOUT},
733 	{ERRHRD,	ERRgeneral,	NT_STATUS_REPLY_MESSAGE_MISMATCH},
734 	{ERRHRD,	ERRgeneral,	NT_STATUS_MAPPED_ALIGNMENT},
735 	{ERRDOS,	193,	NT_STATUS_IMAGE_CHECKSUM_MISMATCH},
736 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOST_WRITEBEHIND_DATA},
737 	{ERRHRD,	ERRgeneral, NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID},
738 	{ERRSRV,	2242,	NT_STATUS_PASSWORD_MUST_CHANGE},
739 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_FOUND},
740 	{ERRHRD,	ERRgeneral,	NT_STATUS_NOT_TINY_STREAM},
741 	{ERRHRD,	ERRgeneral,	NT_STATUS_RECOVERY_FAILURE},
742 	{ERRHRD,	ERRgeneral,	NT_STATUS_STACK_OVERFLOW_READ},
743 	{ERRHRD,	ERRgeneral,	NT_STATUS_FAIL_CHECK},
744 	{ERRHRD,	ERRgeneral,	NT_STATUS_DUPLICATE_OBJECTID},
745 	{ERRHRD,	ERRgeneral,	NT_STATUS_OBJECTID_EXISTS},
746 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONVERT_TO_LARGE},
747 	{ERRHRD,	ERRgeneral,	NT_STATUS_RETRY},
748 	{ERRHRD,	ERRgeneral,	NT_STATUS_FOUND_OUT_OF_SCOPE},
749 	{ERRHRD,	ERRgeneral,	NT_STATUS_ALLOCATE_BUCKET},
750 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROPSET_NOT_FOUND},
751 	{ERRHRD,	ERRgeneral,	NT_STATUS_MARSHALL_OVERFLOW},
752 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_VARIANT},
753 	{ERRHRD,	ERRgeneral,	NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND},
754 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ACCOUNT_LOCKED_OUT},
755 	{ERRDOS,	ERRbadfid,	NT_STATUS_HANDLE_NOT_CLOSABLE},
756 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_REFUSED},
757 	{ERRHRD,	ERRgeneral,	NT_STATUS_GRACEFUL_DISCONNECT},
758 	{ERRHRD,	ERRgeneral,	NT_STATUS_ADDRESS_ALREADY_ASSOCIATED},
759 	{ERRHRD,	ERRgeneral,	NT_STATUS_ADDRESS_NOT_ASSOCIATED},
760 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_INVALID},
761 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_ACTIVE},
762 	{ERRHRD,	ERRgeneral,	NT_STATUS_NETWORK_UNREACHABLE},
763 	{ERRHRD,	ERRgeneral,	NT_STATUS_HOST_UNREACHABLE},
764 	{ERRHRD,	ERRgeneral,	NT_STATUS_PROTOCOL_UNREACHABLE},
765 	{ERRHRD,	ERRgeneral,	NT_STATUS_PORT_UNREACHABLE},
766 	{ERRHRD,	ERRgeneral,	NT_STATUS_REQUEST_ABORTED},
767 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_ABORTED},
768 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_COMPRESSION_BUFFER},
769 	{ERRHRD,	ERRgeneral,	NT_STATUS_USER_MAPPED_FILE},
770 	{ERRHRD,	ERRgeneral,	NT_STATUS_AUDIT_FAILED},
771 	{ERRHRD,	ERRgeneral,	NT_STATUS_TIMER_RESOLUTION_NOT_SET},
772 	{ERRHRD,	ERRgeneral,	NT_STATUS_CONNECTION_COUNT_LIMIT},
773 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGIN_TIME_RESTRICTION},
774 	{ERRHRD,	ERRgeneral,	NT_STATUS_LOGIN_WKSTA_RESTRICTION},
775 	{ERRDOS,	193,	NT_STATUS_IMAGE_MP_UP_MISMATCH},
776 	{ERRHRD,	ERRgeneral,	0x000024a},
777 	{ERRHRD,	ERRgeneral,	0x000024b},
778 	{ERRHRD,	ERRgeneral,	0x000024c},
779 	{ERRHRD,	ERRgeneral,	0x000024d},
780 	{ERRHRD,	ERRgeneral,	0x000024e},
781 	{ERRHRD,	ERRgeneral,	0x000024f},
782 	{ERRHRD,	ERRgeneral,	NT_STATUS_INSUFFICIENT_LOGON_INFO},
783 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_DLL_ENTRYPOINT},
784 	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_SERVICE_ENTRYPOINT},
785 	{ERRHRD,	ERRgeneral,	NT_STATUS_LPC_REPLY_LOST},
786 	{ERRHRD,	ERRgeneral,	NT_STATUS_IP_ADDRESS_CONFLICT1},
787 	{ERRHRD,	ERRgeneral,	NT_STATUS_IP_ADDRESS_CONFLICT2},
788 	{ERRHRD,	ERRgeneral,	NT_STATUS_REGISTRY_QUOTA_LIMIT},
789 	{ERRSRV,	ERRbadtype,	NT_STATUS_PATH_NOT_COVERED},
790 	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_CALLBACK_ACTIVE},
791 	{ERRHRD,	ERRgeneral,	NT_STATUS_LICENSE_QUOTA_EXCEEDED},
792 	{ERRHRD,	ERRgeneral,	NT_STATUS_PWD_TOO_SHORT},
793 	{ERRHRD,	ERRgeneral,	NT_STATUS_PWD_TOO_RECENT},
794 	{ERRHRD,	ERRgeneral,	NT_STATUS_PWD_HISTORY_CONFLICT},
795 	{ERRHRD,	ERRgeneral,	0x000025d},
796 	{ERRHRD,	ERRgeneral,	NT_STATUS_PLUGPLAY_NO_DEVICE},
797 	{ERRHRD,	ERRgeneral,	NT_STATUS_UNSUPPORTED_COMPRESSION},
798 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_HW_PROFILE},
799 	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH},
800 	{ERRDOS,	182,		NT_STATUS_DRIVER_ORDINAL_NOT_FOUND},
801 	{ERRDOS,	127,		NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND},
802 	{ERRDOS,	288,		NT_STATUS_RESOURCE_NOT_OWNED},
803 	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_LINKS},
804 	{ERRHRD,	ERRgeneral,	NT_STATUS_QUOTA_LIST_INCONSISTENT},
805 	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_IS_OFFLINE},
806 	{ERRDOS,	ERRnotready,		NT_STATUS_VOLUME_DISMOUNTED},
807 	{ERRDOS,	161,		NT_STATUS_DIRECTORY_IS_A_REPARSE_POINT},
808 	{ERRDOS,	ERRnoaccess,	NT_STATUS_ENCRYPTION_FAILED},
809 	{ERRDOS,	ERRnoaccess,	NT_STATUS_DECRYPTION_FAILED},
810 	{ERRHRD,	ERRgeneral,	NT_STATUS_RANGE_NOT_FOUND},
811 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_RECOVERY_POLICY},
812 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_EFS},
813 	{ERRDOS,	ERRnoaccess,	NT_STATUS_WRONG_EFS},
814 	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_USER_KEYS},
815 	{ERRDOS,	ERRbadfunc,	NT_STATUS_VOLUME_NOT_UPGRADED},
816 };
817 
818 u_int32_t
819 smb_maperr32(u_int32_t eno)
820 {
821 	int	i;
822 	unsigned	orig = eno;
823 
824 	/*
825 	 * Hi two bits are "severity".  Ignore "success" (0) and
826 	 * "informational" (1) values.
827 	 */
828 	if (!(eno & 0x80000000))
829 		return (0);
830 	/* mask off "severity" and the "component"  bit */
831 	eno &= ~(0xe0000000);
832 
833 	/* first try direct map to unix */
834 	for (i = 0; nt2errno[i].errno; i++)
835 		if (nt2errno[i].nterr == eno)
836 			return (nt2errno[i].errno);
837 	SMBERROR("no direct map for 32 bit server error (0x%x)\n", orig);
838 
839 	/* ok, then try mapping to dos to unix */
840 	for (i = 0; nt2doserr[i].derr; i++)
841 		if (nt2doserr[i].nterr == eno)
842 			return (smb_maperror(nt2doserr[i].dclass,
843 			    nt2doserr[i].derr));
844 	return (smb_maperror(ERRHRD, ERRgeneral));
845 }
846 
847 
848 int
849 smb_maperror(int eclass, int eno)
850 {
851 	if (eclass == 0 && eno == 0)
852 		return (0);
853 	switch (eclass) {
854 	case ERRDOS:
855 		switch (eno) {
856 		case ERRbadfunc:
857 		case ERRbadenv:
858 		case ERRbadformat:
859 		case ERRremcd:
860 		case ERRrmuns:
861 		case ERRunknownlevel:
862 			return (EINVAL);
863 		case ERRbadfile:
864 		case ERRbadpath:
865 		case ERRnoipc:
866 		case ERRnosuchshare:
867 			return (ENOENT);
868 		case ERRnofids:
869 			return (EMFILE);
870 		case ERRnoaccess:
871 			/*
872 			 * XXX CSM Reported on samba-technical 12/7/2002
873 			 *
874 			 * There is a case for which server(s) return
875 			 * ERRnoaccess but should return ERRdiskfull: When
876 			 * the offset for a write is exactly the server
877 			 * file size limit then Samba (at least) thinks
878 			 * the reason for zero bytes having been written
879 			 * must have been "access denied" from the local
880 			 * filesystem.  This cannot be easily worked
881 			 * around since the server behaviour is
882 			 * indistinguishable from actual access denied.
883 			 * An incomplete workaround: attempt a 2 byte write
884 			 * from "offset-1".  (That may require reading at
885 			 * offset-1 first.)  The flaw is that reading or
886 			 * writing at offset-1 could cause an
887 			 * unrelated error (due to a byte range lock
888 			 * for instance) and we can't presume the
889 			 * order servers check errors in.
890 			 */
891 		case ERRbadaccess:
892 			return (EACCES);
893 		case ERRbadshare:
894 			return (EBUSY);
895 		case ERRbadfid:
896 			return (EBADF);
897 		case ERRbadmcb:
898 			return (EIO);
899 		case ERRnomem:
900 			return (ENOMEM);	/* actually remote no mem... */
901 		case ERRbadmem:
902 			return (EFAULT);
903 		case ERRbaddata:
904 			return (E2BIG);
905 		case ERRbaddrive:
906 		case ERRnotready:	/* nt */
907 			return (ENXIO);
908 		case ERRdiffdevice:
909 			return (EXDEV);
910 		case ERRnofiles:
911 			return (0);	/* eeof ? */
912 		case ERRlock:
913 			return (EDEADLK);
914 		case ERRfilexists:
915 			return (EEXIST);
916 		case ERRinvalidname:	/* samba maps as noent */
917 			return (ENOENT);
918 		case ERRdirnotempty:		/* samba */
919 			return (ENOTEMPTY);
920 		case ERRnotlocked:
921 			return (0); /* 0 since bsd unlocks on any close */
922 		case ERRrename:
923 			return (EEXIST);
924 		case ERRmoredata:
925 			return (EMOREDATA);
926 		}
927 		break;
928 	case ERRSRV:
929 		switch (eno) {
930 		case ERRerror:
931 			return (EINVAL);
932 		case ERRbadpw:
933 			return (EAUTH);
934 		case ERRaccess:
935 		case ERRbaduid:
936 			return (EACCES);
937 		case ERRinvnid:
938 			return (ENETRESET);
939 		case ERRinvnetname:
940 			SMBERROR("NetBIOS name is invalid: %d\n",
941 			    ERRinvnetname);
942 			return (EAUTH);
943 		case ERRbadtype:		/* reserved and returned */
944 			return (EIO);
945 		case ERRacctexpired: /* NT: account exists but disabled */
946 			return (EPERM);
947 		}
948 		break;
949 	case ERRHRD:
950 		switch (eno) {
951 		case ERRnowrite:
952 			return (EROFS);
953 		case ERRbadunit:
954 			return (ENODEV);
955 		case ERRbadreq:
956 			return (EBADRPC);
957 		case ERRbadshare:
958 			return (ETXTBSY);
959 		case ERRlock:
960 			return (EDEADLK);
961 		case ERRdiskfull:
962 			return (EFBIG);
963 		case ERRnotready:
964 		case ERRbadcmd:
965 		case ERRdata:
966 		case ERRgeneral:
967 			return (EIO);
968 		default:
969 			SMBERROR("Unmapped DOS error %d:%d\n", eclass, eno);
970 			return (EIO);
971 		}
972 	}
973 	SMBERROR("Unmapped DOS error %d:%d\n", eclass, eno);
974 	return (EBADRPC);
975 }
976 
977 #if defined(NOICONVSUPPORT) || defined(lint)
978 extern int iconv_conv(void *handle, const char **inbuf,
979     size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
980 #endif
981 
982 #define	SMALL_CONV 256
983 
984 /*ARGSUSED*/
985 int
986 smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp, const char *src,
987 	int size, int caseopt, int *lenp)
988 {
989 	uint16_t convbuf[SMALL_CONV];
990 	uint16_t *cbuf;
991 	size_t cbufalloc, inlen, outlen;
992 	int error;
993 
994 	if (size <= 0)
995 		return (0);
996 
997 	/*
998 	 * Handle the easy case (non-unicode).
999 	 * XXX: Technically, we should convert
1000 	 * the string to OEM codeset first...
1001 	 * Modern servers all use Unicode, so
1002 	 * this is good enough.
1003 	 */
1004 	if (SMB_UNICODE_STRINGS(vcp) == 0) {
1005 		error = mb_put_mem(mbp, src, size, MB_MSYSTEM);
1006 		if (!error && lenp)
1007 			*lenp += size;
1008 		return (error);
1009 	}
1010 
1011 	/*
1012 	 * Convert to UCS-2 (really UTF-16).
1013 	 * Use stack buffer if the string is
1014 	 * small enough, else allocate.
1015 	 */
1016 	if (size <= SMALL_CONV) {
1017 		cbufalloc = 0;
1018 		outlen = SMALL_CONV;
1019 		cbuf = convbuf;
1020 	} else {
1021 		outlen = size; /* in utf-16 characters */
1022 		cbufalloc = outlen * 2;
1023 		cbuf = kmem_alloc(cbufalloc, KM_SLEEP);
1024 	}
1025 
1026 	inlen = size;
1027 	error = uconv_u8tou16((uchar_t *)src, &inlen, cbuf, &outlen,
1028 	    UCONV_OUT_LITTLE_ENDIAN | UCONV_IGNORE_NULL);
1029 	outlen *= 2;  /* convert to bytes */
1030 
1031 	if (!error) {
1032 		(void) mb_put_padbyte(mbp); /* align */
1033 		error = mb_put_mem(mbp, (char *)cbuf, outlen, MB_MSYSTEM);
1034 	}
1035 	if (!error && lenp)
1036 		*lenp += outlen;
1037 
1038 	if (cbufalloc)
1039 		kmem_free(cbuf, cbufalloc);
1040 
1041 	return (error);
1042 }
1043 
1044 int
1045 smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp, const char *src,
1046 	int caseopt)
1047 {
1048 	int error, len;
1049 
1050 	/*
1051 	 * Let smb_put_dmem put both the string
1052 	 * and the terminating null.
1053 	 */
1054 	len = strlen(src) + 1;
1055 	error = smb_put_dmem(mbp, vcp, src, len, caseopt, NULL);
1056 	if (error)
1057 		return (error);
1058 
1059 	return (error);
1060 }
1061