14bff34ethurlow/*
24bff34ethurlow * Copyright (c) 2000-2001 Boris Popov
34bff34ethurlow * All rights reserved.
44bff34ethurlow *
54bff34ethurlow * Redistribution and use in source and binary forms, with or without
64bff34ethurlow * modification, are permitted provided that the following conditions
74bff34ethurlow * are met:
84bff34ethurlow * 1. Redistributions of source code must retain the above copyright
94bff34ethurlow *    notice, this list of conditions and the following disclaimer.
104bff34ethurlow * 2. Redistributions in binary form must reproduce the above copyright
114bff34ethurlow *    notice, this list of conditions and the following disclaimer in the
124bff34ethurlow *    documentation and/or other materials provided with the distribution.
134bff34ethurlow * 3. All advertising materials mentioning features or use of this software
144bff34ethurlow *    must display the following acknowledgement:
154bff34ethurlow *    This product includes software developed by Boris Popov.
164bff34ethurlow * 4. Neither the name of the author nor the names of any co-contributors
174bff34ethurlow *    may be used to endorse or promote products derived from this software
184bff34ethurlow *    without specific prior written permission.
194bff34ethurlow *
204bff34ethurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34ethurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34ethurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34ethurlow * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34ethurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34ethurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34ethurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34ethurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34ethurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34ethurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34ethurlow * SUCH DAMAGE.
314bff34ethurlow *
324bff34ethurlow * $Id: smb_subr.c,v 1.27.108.1 2005/06/02 00:55:39 lindak Exp $
334bff34ethurlow */
344bff34ethurlow
35613a2f6Gordon Ross/*
36148c5f4Alan Wright * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3740c0e23Gordon Ross * Portions Copyright (C) 2001 - 2013 Apple Inc. All rights reserved.
3840c0e23Gordon Ross * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
39613a2f6Gordon Ross */
404bff34ethurlow
414bff34ethurlow#include <sys/param.h>
424bff34ethurlow#include <sys/systm.h>
434bff34ethurlow#include <sys/kmem.h>
444bff34ethurlow#include <sys/proc.h>
454bff34ethurlow#include <sys/lock.h>
464bff34ethurlow#include <sys/socket.h>
474bff34ethurlow#include <sys/isa_defs.h>
484bff34ethurlow#include <sys/stream.h>
494bff34ethurlow#include <sys/strsun.h>
504bff34ethurlow#include <sys/sunddi.h>
514bff34ethurlow#include <sys/cmn_err.h>
524bff34ethurlow#include <sys/sdt.h>
534bff34ethurlow#include <sys/priv.h>
544bff34ethurlow#include <sys/u8_textprep.h>
554bff34ethurlow
564bff34ethurlow#include <netsmb/smb_osdep.h>
574bff34ethurlow#include <netsmb/smb.h>
584bff34ethurlow#include <netsmb/smb_conn.h>
594bff34ethurlow#include <netsmb/smb_rq.h>
604bff34ethurlow#include <netsmb/smb_subr.h>
614bff34ethurlow
624bff34ethurlowvoid
63613a2f6Gordon Rosssmb_credinit(struct smb_cred *scred, cred_t *cr)
644bff34ethurlow{
65613a2f6Gordon Ross	/* cr arg is optional */
66613a2f6Gordon Ross	if (cr == NULL)
67613a2f6Gordon Ross		cr = ddi_get_cred();
688329232Gordon Ross#ifdef	_KERNEL
694bff34ethurlow	if (is_system_labeled()) {
70613a2f6Gordon Ross		cr = crdup(cr);
71613a2f6Gordon Ross		(void) setpflags(NET_MAC_AWARE, 1, cr);
728329232Gordon Ross	} else
738329232Gordon Ross#endif
748329232Gordon Ross	{
75613a2f6Gordon Ross		crhold(cr);
764bff34ethurlow	}
77613a2f6Gordon Ross	scred->scr_cred = cr;
784bff34ethurlow}
794bff34ethurlow
804bff34ethurlowvoid
814bff34ethurlowsmb_credrele(struct smb_cred *scred)
824bff34ethurlow{
83613a2f6Gordon Ross	if (scred->scr_cred != NULL) {
84613a2f6Gordon Ross		crfree(scred->scr_cred);
85613a2f6Gordon Ross		scred->scr_cred = NULL;
864bff34ethurlow	}
874bff34ethurlow}
884bff34ethurlow
89adee678Gordon Ross#ifndef	_KERNEL
90adee678Gordon Ross/* ARGSUSED */
91adee678Gordon Rossvoid
92adee678Gordon Rosssmb_debugmsg(const char *func, char *msg)
93adee678Gordon Ross{
94adee678Gordon Ross}
95adee678Gordon Ross#endif	/* _KERNEL */
96adee678Gordon Ross
974bff34ethurlow/*
984bff34ethurlow * Helper for the SMBERROR macro, etc.
994bff34ethurlow * This is also a good place for a breakpoint
1004bff34ethurlow * or a dtrace probe, i.e. fbt:nsmb:smb_errmsg
1014bff34ethurlow */
1024bff34ethurlowvoid
1034bff34ethurlowsmb_errmsg(int cel, const char *func_name, const char *fmt, ...)
1044bff34ethurlow{
1054bff34ethurlow	va_list adx;
1064bff34ethurlow	char buf[100];
1074bff34ethurlow
1084bff34ethurlow	va_start(adx, fmt);
1094bff34ethurlow	if (cel == CE_CONT) {
1104bff34ethurlow		/*
1114bff34ethurlow		 * This is one of our xxxDEBUG macros.
1124bff34ethurlow		 * Don't bother to log these, but just
1134bff34ethurlow		 * fire a dtrace probe with the message.
1144bff34ethurlow		 */
11502d09e0Gordon Ross		(void) vsnprintf(buf, sizeof (buf), fmt, adx);
1164bff34ethurlow		DTRACE_PROBE2(debugmsg2,
1174bff34ethurlow		    (char *), func_name,
1184bff34ethurlow		    (char *), buf);
119adee678Gordon Ross#ifndef	_KERNEL
120adee678Gordon Ross		smb_debugmsg(func_name, buf);
121adee678Gordon Ross#endif
1224bff34ethurlow	} else {
1234bff34ethurlow		/*
1244bff34ethurlow		 * This is one of our xxxERROR macros.
1254bff34ethurlow		 * Add a prefix to the fmt string,
1264bff34ethurlow		 * then let vcmn_err do the args.
1274bff34ethurlow		 */
12802d09e0Gordon Ross		(void) snprintf(buf, sizeof (buf), "?%s: %s", func_name, fmt);
1294bff34ethurlow		DTRACE_PROBE3(debugmsg3,
1304bff34ethurlow		    (char *), func_name,
1314bff34ethurlow		    (char *), buf,
1324bff34ethurlow		    va_list, adx);
1334bff34ethurlow		vcmn_err(cel, buf, adx);
1344bff34ethurlow	}
1354bff34ethurlow	va_end(adx);
1364bff34ethurlow}
1374bff34ethurlow
1384bff34ethurlow#if 1 /* def SMB_SOCKETDATA_DEBUG */
1394bff34ethurlowvoid
1404bff34ethurlowm_dumpm(mblk_t *m)
1414bff34ethurlow{
1424bff34ethurlow	int len, seg;
1434bff34ethurlow
1444bff34ethurlow	len = msgdsize(m);
1454bff34ethurlow	DTRACE_PROBE2(dsize, int, len, (mblk_t *), m);
1464bff34ethurlow
1474bff34ethurlow	for (seg = 0; m; seg++) {
1484bff34ethurlow		DTRACE_PROBE2(mblk, int, seg, (mblk_t *), m);
1494bff34ethurlow		m = m->b_cont;
1504bff34ethurlow	}
1514bff34ethurlow}
1524bff34ethurlow#endif
1534bff34ethurlow
1544bff34ethurlow#ifndef EPROTO
1554bff34ethurlow#define	EPROTO ECONNABORTED
1564bff34ethurlow#endif
1574bff34ethurlow#ifndef ELIBACC
1584bff34ethurlow#define	ELIBACC ENOENT
1594bff34ethurlow#endif
1604bff34ethurlow#ifndef ENODATA
1614bff34ethurlow#define	ENODATA EINVAL
1624bff34ethurlow#endif
1634bff34ethurlow#ifndef ENOTUNIQ
1644bff34ethurlow#define	ENOTUNIQ EADDRINUSE
1654bff34ethurlow#endif
1664bff34ethurlow#ifndef ECOMM
1674bff34ethurlow#define	ECOMM EIO
1684bff34ethurlow#endif
1694bff34ethurlow#ifndef ENOMEDIUM
17002d09e0Gordon Ross#define	ENOMEDIUM ENXIO
1714bff34ethurlow#endif
1724bff34ethurlow#ifndef ETIME
1734bff34ethurlow#define	ETIME ETIMEDOUT
1744bff34ethurlow#endif
175adee678Gordon Ross#ifndef	EMOREDATA
176adee678Gordon Ross#define	EMOREDATA (0x7fff)
177adee678Gordon Ross#endif
1784bff34ethurlow
179ae3d7f9Gordon Ross/*
180ae3d7f9Gordon Ross * Log any un-handled NT or DOS errors we encounter.
181ae3d7f9Gordon Ross * Make these log NOTICE in a debug build to ensure
182ae3d7f9Gordon Ross * they get noticed during tests.  In the field these
183ae3d7f9Gordon Ross * are unimportant, so just fire a Dtrace probe.
184ae3d7f9Gordon Ross */
185ae3d7f9Gordon Rossstatic int unknown_err_logpri =
186ae3d7f9Gordon Ross#ifdef	DEBUG
187ae3d7f9Gordon Ross	CE_NOTE;
188ae3d7f9Gordon Ross#else
189ae3d7f9Gordon Ross	CE_CONT;
190ae3d7f9Gordon Ross#endif
191ae3d7f9Gordon Ross
192148c5f4Alan Wrighttypedef struct nt2errno {
19302d09e0Gordon Ross	unsigned int nterr;
194148c5f4Alan Wright	int errno;
195148c5f4Alan Wright} nt2errno_t;
196148c5f4Alan Wright
197148c5f4Alan Wrightstatic const nt2errno_t nt2errno[] = {
19802d09e0Gordon Ross	/* Alphabetical order. */
1994bff34ethurlow	{NT_STATUS_ACCESS_DENIED,		EACCES},
2004bff34ethurlow	{NT_STATUS_ACCESS_VIOLATION,		EACCES},
2014bff34ethurlow	{NT_STATUS_ACCOUNT_DISABLED,		EACCES},
20202d09e0Gordon Ross	{NT_STATUS_ACCOUNT_EXPIRED,		EACCES},
20302d09e0Gordon Ross	{NT_STATUS_ACCOUNT_LOCKED_OUT,		EACCES},
2044bff34ethurlow	{NT_STATUS_ACCOUNT_RESTRICTION,		EACCES},
2054bff34ethurlow	{NT_STATUS_ADDRESS_ALREADY_EXISTS,	EADDRINUSE},
2064bff34ethurlow	{NT_STATUS_BAD_NETWORK_NAME,		ENOENT},
20740c0e23Gordon Ross	{NT_STATUS_BAD_NETWORK_PATH,		ENOENT},
20840c0e23Gordon Ross	{NT_STATUS_BUFFER_TOO_SMALL,		E2BIG},
20940c0e23Gordon Ross	{NT_STATUS_CANCELLED,			ECANCELED},
2104bff34ethurlow	{NT_STATUS_CANNOT_DELETE,		EACCES},
2114bff34ethurlow	{NT_STATUS_CONFLICTING_ADDRESSES,	EADDRINUSE},
2124bff34ethurlow	{NT_STATUS_CONNECTION_ABORTED,		ECONNABORTED},
2134bff34ethurlow	{NT_STATUS_CONNECTION_DISCONNECTED,	ECONNABORTED},
2144bff34ethurlow	{NT_STATUS_CONNECTION_REFUSED,		ECONNREFUSED},
2154bff34ethurlow	{NT_STATUS_CONNECTION_RESET,		ENETRESET},
21602d09e0Gordon Ross	{NT_STATUS_DELETE_PENDING,		EACCES},
2174bff34ethurlow	{NT_STATUS_DEVICE_DOES_NOT_EXIST,	ENODEV},
2184bff34ethurlow	{NT_STATUS_DEVICE_PROTOCOL_ERROR,	EPROTO},
2194bff34ethurlow	{NT_STATUS_DIRECTORY_NOT_EMPTY,		ENOTEMPTY},
2204bff34ethurlow	{NT_STATUS_DISK_FULL,			ENOSPC},
2214bff34ethurlow	{NT_STATUS_DLL_NOT_FOUND,		ELIBACC},
222ae3d7f9Gordon Ross	{NT_STATUS_DUPLICATE_NAME,		EINVAL},
22340c0e23Gordon Ross	{NT_STATUS_EAS_NOT_SUPPORTED,		ENOTSUP},
22440c0e23Gordon Ross	{NT_STATUS_EA_TOO_LARGE,		E2BIG},
2254bff34ethurlow	{NT_STATUS_END_OF_FILE,			ENODATA},
22640c0e23Gordon Ross	{NT_STATUS_FILE_CLOSED,			EBADF},
22740c0e23Gordon Ross	{NT_STATUS_FILE_DELETED,		ENOENT},
22840c0e23Gordon Ross	{NT_STATUS_FILE_INVALID,		EIO},
2294bff34ethurlow	{NT_STATUS_FILE_IS_A_DIRECTORY,		EISDIR},
23002d09e0Gordon Ross	{NT_STATUS_FILE_LOCK_CONFLICT,		EAGAIN},
23140c0e23Gordon Ross	{NT_STATUS_FILE_RENAMED,		ENOENT},
2324bff34ethurlow	{NT_STATUS_FLOAT_INEXACT_RESULT,	ERANGE},
2334bff34ethurlow	{NT_STATUS_FLOAT_OVERFLOW,		ERANGE},
2344bff34ethurlow	{NT_STATUS_FLOAT_UNDERFLOW,		ERANGE},
2354bff34ethurlow	{NT_STATUS_HOST_UNREACHABLE,		EHOSTUNREACH},
23640c0e23Gordon Ross	{NT_STATUS_ILL_FORMED_PASSWORD,		EAUTH},
23740c0e23Gordon Ross	{NT_STATUS_INFO_LENGTH_MISMATCH,	EINVAL},
23840c0e23Gordon Ross	{NT_STATUS_INSUFFICIENT_RESOURCES,	EAGAIN},
23940c0e23Gordon Ross	{NT_STATUS_INSUFF_SERVER_RESOURCES,	EAGAIN},
2404bff34ethurlow	{NT_STATUS_INTEGER_OVERFLOW,		ERANGE},
24140c0e23Gordon Ross	{NT_STATUS_INVALID_ACCOUNT_NAME,	EAUTH},
24240c0e23Gordon Ross	{NT_STATUS_INVALID_BUFFER_SIZE,		EIO},
24340c0e23Gordon Ross	{NT_STATUS_INVALID_DEVICE_REQUEST,	EINVAL},
2444bff34ethurlow	{NT_STATUS_INVALID_HANDLE,		EBADF},
24540c0e23Gordon Ross	{NT_STATUS_INVALID_INFO_CLASS,		EINVAL},
24602d09e0Gordon Ross	{NT_STATUS_INVALID_LEVEL,		ENOTSUP},
24740c0e23Gordon Ross	{NT_STATUS_INVALID_LOCK_SEQUENCE,	EINVAL},
24840c0e23Gordon Ross	{NT_STATUS_INVALID_LOGON_HOURS,		EAUTH},
249148c5f4Alan Wright	{NT_STATUS_INVALID_OWNER,		EINVAL},
2504bff34ethurlow	{NT_STATUS_INVALID_PARAMETER,		EINVAL},
2514bff34ethurlow	{NT_STATUS_INVALID_PIPE_STATE,		EPIPE},
252148c5f4Alan Wright	{NT_STATUS_INVALID_PRIMARY_GROUP,	EINVAL},
2534bff34ethurlow	{NT_STATUS_INVALID_WORKSTATION,		EACCES},
2544bff34ethurlow	{NT_STATUS_IN_PAGE_ERROR,		EFAULT},
25540c0e23Gordon Ross	{NT_STATUS_IO_DEVICE_ERROR,		EIO},
2564bff34ethurlow	{NT_STATUS_IO_TIMEOUT,			ETIMEDOUT},
25740c0e23Gordon Ross	{NT_STATUS_IP_ADDRESS_CONFLICT1,	EADDRINUSE},
25840c0e23Gordon Ross	{NT_STATUS_IP_ADDRESS_CONFLICT2,	EADDRINUSE},
2594bff34ethurlow	{NT_STATUS_LICENSE_QUOTA_EXCEEDED,	EDQUOT},
26002d09e0Gordon Ross	{NT_STATUS_LOCK_NOT_GRANTED,		EAGAIN},
26140c0e23Gordon Ross	{NT_STATUS_LOGIN_TIME_RESTRICTION,	EAUTH},
26240c0e23Gordon Ross	{NT_STATUS_LOGON_FAILURE,		EAUTH},
26340c0e23Gordon Ross	{NT_STATUS_LOGON_TYPE_NOT_GRANTED,	EAUTH},
2644bff34ethurlow	{NT_STATUS_MEDIA_WRITE_PROTECTED,	EROFS},
2654bff34ethurlow	{NT_STATUS_MEMORY_NOT_ALLOCATED,	EFAULT},
26640c0e23Gordon Ross	{NT_STATUS_MORE_PROCESSING_REQUIRED,	EINPROGRESS},
2674bff34ethurlow	{NT_STATUS_NAME_TOO_LONG,		ENAMETOOLONG},
2684bff34ethurlow	{NT_STATUS_NETWORK_ACCESS_DENIED,	EACCES},
2694bff34ethurlow	{NT_STATUS_NETWORK_BUSY,		EBUSY},
27040c0e23Gordon Ross	{NT_STATUS_NETWORK_NAME_DELETED,	ENOENT},
2714bff34ethurlow	{NT_STATUS_NETWORK_UNREACHABLE,		ENETUNREACH},
2724bff34ethurlow	{NT_STATUS_NET_WRITE_FAULT,		ECOMM},
27340c0e23Gordon Ross	{NT_STATUS_NONEXISTENT_EA_ENTRY,	ENOENT},
2744bff34ethurlow	{NT_STATUS_NONEXISTENT_SECTOR,		ESPIPE},
27502d09e0Gordon Ross	{NT_STATUS_NONE_MAPPED,			EINVAL},
2764bff34ethurlow	{NT_STATUS_NOT_A_DIRECTORY,		ENOTDIR},
27740c0e23Gordon Ross	{NT_STATUS_NOT_FOUND,			ENOENT},
278ae3d7f9Gordon Ross	{NT_STATUS_NOT_IMPLEMENTED,		ENOTSUP},
27940c0e23Gordon Ross	{NT_STATUS_NOT_LOCKED,			ENOLCK},
2804bff34ethurlow	{NT_STATUS_NOT_MAPPED_VIEW,		EINVAL},
281ae3d7f9Gordon Ross	{NT_STATUS_NOT_SUPPORTED,		ENOTSUP},
28240c0e23Gordon Ross	{NT_STATUS_NO_EAS_ON_FILE,		ENOENT},
28340c0e23Gordon Ross	{NT_STATUS_NO_LOGON_SERVERS,		EAUTH},
2844bff34ethurlow	{NT_STATUS_NO_MEDIA,			ENOMEDIUM},
2854bff34ethurlow	{NT_STATUS_NO_MEDIA_IN_DEVICE,		ENOMEDIUM},
2864bff34ethurlow	{NT_STATUS_NO_MEMORY,			ENOMEM},
2874bff34ethurlow	{NT_STATUS_NO_SUCH_DEVICE,		ENODEV},
2884bff34ethurlow	{NT_STATUS_NO_SUCH_FILE,		ENOENT},
28940c0e23Gordon Ross	{NT_STATUS_NO_SUCH_LOGON_SESSION,	EAUTH},
29040c0e23Gordon Ross	{NT_STATUS_NO_SUCH_USER,		EAUTH},
29140c0e23Gordon Ross	{NT_STATUS_NO_TRUST_LSA_SECRET,		EAUTH},
29240c0e23Gordon Ross	{NT_STATUS_NO_TRUST_SAM_ACCOUNT,	EAUTH},
2934bff34ethurlow	{NT_STATUS_OBJECT_NAME_COLLISION,	EEXIST},
29491d632cgwr	{NT_STATUS_OBJECT_NAME_INVALID,		EINVAL},
29502d09e0Gordon Ross	{NT_STATUS_OBJECT_NAME_NOT_FOUND,	ENOENT},
2964bff34ethurlow	{NT_STATUS_OBJECT_PATH_INVALID,		ENOTDIR},
29702d09e0Gordon Ross	{NT_STATUS_OBJECT_PATH_NOT_FOUND,	ENOENT},
29840c0e23Gordon Ross	{NT_STATUS_OBJECT_PATH_SYNTAX_BAD,	EINVAL},
29940c0e23Gordon Ross	{NT_STATUS_OBJECT_TYPE_MISMATCH,	EBADF},
3004bff34ethurlow	{NT_STATUS_PAGEFILE_QUOTA,		EDQUOT},
30140c0e23Gordon Ross	{NT_STATUS_PASSWORD_EXPIRED,		EAUTH},
30240c0e23Gordon Ross	{NT_STATUS_PASSWORD_MUST_CHANGE,	EAUTH},
30340c0e23Gordon Ross	{NT_STATUS_PASSWORD_RESTRICTION,	EAUTH},
3044bff34ethurlow	{NT_STATUS_PATH_NOT_COVERED,		ENOENT},
3054bff34ethurlow	{NT_STATUS_PIPE_BROKEN,			EPIPE},
3064bff34ethurlow	{NT_STATUS_PIPE_BUSY,			EPIPE},
3074bff34ethurlow	{NT_STATUS_PIPE_CONNECTED,		EISCONN},
3084bff34ethurlow	{NT_STATUS_PIPE_DISCONNECTED,		EPIPE},
309ae3d7f9Gordon Ross	{NT_STATUS_PIPE_NOT_AVAILABLE,		EBUSY},
3104bff34ethurlow	{NT_STATUS_PORT_CONNECTION_REFUSED,	ECONNREFUSED},
31140c0e23Gordon Ross	{NT_STATUS_PORT_DISCONNECTED,		EBADF},
3124bff34ethurlow	{NT_STATUS_PORT_MESSAGE_TOO_LONG,	EMSGSIZE},
3134bff34ethurlow	{NT_STATUS_PORT_UNREACHABLE,		EHOSTUNREACH},
3144bff34ethurlow	{NT_STATUS_PROTOCOL_UNREACHABLE,	ENOPROTOOPT},
3154bff34ethurlow	{NT_STATUS_QUOTA_EXCEEDED,		EDQUOT},
31640c0e23Gordon Ross	{NT_STATUS_RANGE_NOT_LOCKED,		EAGAIN}, /* like F_SETLK */
3174bff34ethurlow	{NT_STATUS_REGISTRY_QUOTA_LIMIT,	EDQUOT},
3184bff34ethurlow	{NT_STATUS_REMOTE_DISCONNECT,		ESHUTDOWN},
3194bff34ethurlow	{NT_STATUS_REMOTE_NOT_LISTENING,	ECONNREFUSED},
3204bff34ethurlow	{NT_STATUS_REQUEST_NOT_ACCEPTED,	EACCES},
3214bff34ethurlow	{NT_STATUS_RETRY,			EAGAIN},
3224bff34ethurlow	{NT_STATUS_SHARING_VIOLATION,		EBUSY},
3234bff34ethurlow	{NT_STATUS_TIMER_NOT_CANCELED,		ETIME},
3244bff34ethurlow	{NT_STATUS_TOO_MANY_LINKS,		EMLINK},
3254bff34ethurlow	{NT_STATUS_TOO_MANY_OPENED_FILES,	EMFILE},
32640c0e23Gordon Ross	{NT_STATUS_TRUSTED_DOMAIN_FAILURE,	EAUTH},
32740c0e23Gordon Ross	{NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE, EAUTH},
3284bff34ethurlow	{NT_STATUS_UNABLE_TO_FREE_VM,		EADDRINUSE},
3294bff34ethurlow	{NT_STATUS_UNSUCCESSFUL,		EINVAL},
33040c0e23Gordon Ross	{NT_STATUS_WRONG_PASSWORD,		EAUTH},
3314bff34ethurlow	{0,	0}
3324bff34ethurlow};
3334bff34ethurlow
334148c5f4Alan Wright/*
335148c5f4Alan Wright * Table for converting NT STATUS values to DOS class/code.
336148c5f4Alan Wright * Rows ordered by integer value of last column (NT STATUS)
337148c5f4Alan Wright */
338148c5f4Alan Wrighttypedef struct nt2doserr {
33902d09e0Gordon Ross	unsigned short dclass;
34002d09e0Gordon Ross	unsigned short derr;
34102d09e0Gordon Ross	unsigned int nterr;
342148c5f4Alan Wright} nt2doserr_t;
343148c5f4Alan Wright
344148c5f4Alan Wrightstatic const nt2doserr_t nt2doserr[] = {
3454bff34ethurlow	{ERRDOS,	ERRgeneral,	NT_STATUS_UNSUCCESSFUL},
3464bff34ethurlow	{ERRDOS,	ERRbadfunc,	NT_STATUS_NOT_IMPLEMENTED},
347148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_INFO_CLASS},
348148c5f4Alan Wright	{ERRDOS, ERROR_BAD_LENGTH,	NT_STATUS_INFO_LENGTH_MISMATCH},
3494bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_ACCESS_VIOLATION},
3504bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_IN_PAGE_ERROR},
3514bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_PAGEFILE_QUOTA},
3524bff34ethurlow	{ERRDOS,	ERRbadfid,	NT_STATUS_INVALID_HANDLE},
3534bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_INITIAL_STACK},
354148c5f4Alan Wright	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_BAD_INITIAL_PC},
355148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_CID},
3564bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_TIMER_NOT_CANCELED},
357148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_INVALID_PARAMETER},
3584bff34ethurlow	{ERRDOS,	ERRbadfile,	NT_STATUS_NO_SUCH_DEVICE},
3594bff34ethurlow	{ERRDOS,	ERRbadfile,	NT_STATUS_NO_SUCH_FILE},
3604bff34ethurlow	{ERRDOS,	ERRbadfunc,	NT_STATUS_INVALID_DEVICE_REQUEST},
361148c5f4Alan Wright	{ERRDOS, ERROR_HANDLE_EOF,	NT_STATUS_END_OF_FILE},
362148c5f4Alan Wright	{ERRDOS, ERROR_WRONG_DISK,	NT_STATUS_WRONG_VOLUME},
363148c5f4Alan Wright	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_NO_MEDIA_IN_DEVICE},
3644bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_UNRECOGNIZED_MEDIA},
365148c5f4Alan Wright	{ERRDOS, ERROR_SECTOR_NOT_FOUND,	NT_STATUS_NONEXISTENT_SECTOR},
3664bff34ethurlow	{ERRDOS,	ERRnomem,	NT_STATUS_NO_MEMORY},
367148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_CONFLICTING_ADDRESSES},
368148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_NOT_MAPPED_VIEW},
369148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_UNABLE_TO_FREE_VM},
370148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_UNABLE_TO_DELETE_SECTION},
371148c5f4Alan Wright	{ERRDOS, NERR_InvalidAPI,	NT_STATUS_INVALID_SYSTEM_SERVICE},
3724bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_ILLEGAL_INSTRUCTION},
3734bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_INVALID_LOCK_SEQUENCE},
3744bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_INVALID_VIEW_SIZE},
375148c5f4Alan Wright	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_FILE_FOR_SECTION},
3764bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_ALREADY_COMMITTED},
3774bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_ACCESS_DENIED},
378148c5f4Alan Wright	{ERRDOS, ERROR_BUFFER_OVERFLOW,	NT_STATUS_BUFFER_TOO_SMALL},
3794bff34ethurlow	{ERRDOS,	ERRbadfid,	NT_STATUS_OBJECT_TYPE_MISMATCH},
3804bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NONCONTINUABLE_EXCEPTION},
3814bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_DISPOSITION},
3824bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_UNWIND},
3834bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_STACK},
3844bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_UNWIND_TARGET},
385148c5f4Alan Wright	{ERRDOS, ERROR_NOT_LOCKED,	NT_STATUS_NOT_LOCKED},
3864bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_PARITY_ERROR},
387148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_UNABLE_TO_DECOMMIT_VM},
388148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_NOT_COMMITTED},
3894bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PORT_ATTRIBUTES},
3904bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_PORT_MESSAGE_TOO_LONG},
391148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_INVALID_PARAMETER_MIX},
3924bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_QUOTA_LOWER},
3934bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_DISK_CORRUPT_ERROR},
394148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_NAME,	NT_STATUS_OBJECT_NAME_INVALID},
3954bff34ethurlow	{ERRDOS,	ERRbadfile,	NT_STATUS_OBJECT_NAME_NOT_FOUND},
396148c5f4Alan Wright	{ERRDOS, ERROR_ALREADY_EXISTS,	NT_STATUS_OBJECT_NAME_COLLISION},
3974bff34ethurlow	{ERRDOS,	ERRbadfid,	NT_STATUS_PORT_DISCONNECTED},
3984bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_ALREADY_ATTACHED},
399148c5f4Alan Wright	{ERRDOS, ERROR_BAD_PATHNAME,	NT_STATUS_OBJECT_PATH_INVALID},
4004bff34ethurlow	{ERRDOS,	ERRbadpath,	NT_STATUS_OBJECT_PATH_NOT_FOUND},
401148c5f4Alan Wright	{ERRDOS, ERROR_BAD_PATHNAME,	NT_STATUS_OBJECT_PATH_SYNTAX_BAD},
4024bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_OVERRUN},
4034bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_DATA_LATE_ERROR},
404148c5f4Alan Wright	{ERRDOS, ERROR_CRC,		NT_STATUS_DATA_ERROR},
405148c5f4Alan Wright	{ERRDOS, ERROR_CRC,		NT_STATUS_CRC_ERROR},
4064bff34ethurlow	{ERRDOS,	ERRnomem,	NT_STATUS_SECTION_TOO_BIG},
4074bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_PORT_CONNECTION_REFUSED},
4084bff34ethurlow	{ERRDOS,	ERRbadfid,	NT_STATUS_INVALID_PORT_HANDLE},
409148c5f4Alan Wright	{ERRDOS, ERROR_SHARING_VIOLATION,	NT_STATUS_SHARING_VIOLATION},
4104bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_QUOTA_EXCEEDED},
411148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_INVALID_PAGE_PROTECTION},
412148c5f4Alan Wright	{ERRDOS, ERROR_NOT_OWNER,	NT_STATUS_MUTANT_NOT_OWNED},
413148c5f4Alan Wright	{ERRDOS, ERROR_TOO_MANY_POSTS,	NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED},
414148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_PORT_ALREADY_SET},
415148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_SECTION_NOT_IMAGE},
416148c5f4Alan Wright	{ERRDOS, ERROR_SIGNAL_REFUSED,	NT_STATUS_SUSPEND_COUNT_EXCEEDED},
4174bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_THREAD_IS_TERMINATING},
418148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_BAD_WORKING_SET_LIMIT},
419148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER, NT_STATUS_INCOMPATIBLE_FILE_MAP},
420148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_PARAMETER,	NT_STATUS_SECTION_PROTECTION},
421148c5f4Alan Wright	{ERRDOS, ERROR_EAS_NOT_SUPPORTED,	NT_STATUS_EAS_NOT_SUPPORTED},
422148c5f4Alan Wright	{ERRDOS, ERROR_EA_LIST_INCONSISTENT,	NT_STATUS_EA_TOO_LARGE},
4234bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NONEXISTENT_EA_ENTRY},
4244bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_EAS_ON_FILE},
4254bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_EA_CORRUPT_ERROR},
426148c5f4Alan Wright	{ERRDOS, ERROR_LOCK_VIOLATION,	NT_STATUS_FILE_LOCK_CONFLICT},
427148c5f4Alan Wright	{ERRDOS, ERROR_LOCK_VIOLATION,	NT_STATUS_LOCK_NOT_GRANTED},
4284bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_DELETE_PENDING},
429148c5f4Alan Wright	{ERRDOS, ERROR_NOT_SUPPORTED,	NT_STATUS_CTL_FILE_NOT_SUPPORTED},
4304bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_UNKNOWN_REVISION},
4314bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_REVISION_MISMATCH},
4324bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_OWNER},
4334bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_PRIMARY_GROUP},
4344bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_IMPERSONATION_TOKEN},
4354bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_DISABLE_MANDATORY},
436148c5f4Alan Wright	{ERRDOS, NERR_LogonServerNotFound,	NT_STATUS_NO_LOGON_SERVERS},
4374bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_LOGON_SESSION},
4384bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_PRIVILEGE},
4394bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_PRIVILEGE_NOT_HELD},
4404bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ACCOUNT_NAME},
4414bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_USER_EXISTS},
4424bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_NO_SUCH_USER},
4434bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_GROUP_EXISTS},
4444bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_SUCH_GROUP},
4454bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_IN_GROUP},
4464bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_MEMBER_NOT_IN_GROUP},
4474bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_LAST_ADMIN},
4484bff34ethurlow	{ERRSRV,	ERRbadpw,	NT_STATUS_WRONG_PASSWORD},
4494bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_ILL_FORMED_PASSWORD},
4504bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_PASSWORD_RESTRICTION},
4514bff34ethurlow	{ERRDOS,	ERRnoaccess,	NT_STATUS_LOGON_FAILURE},
4524bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_ACCOUNT_RESTRICTION},
453148c5f4Alan Wright	{ERRSRV, NERR_InvalidLogonHours,	NT_STATUS_INVALID_LOGON_HOURS},
454148c5f4Alan Wright	{ERRSRV, NERR_InvalidWorkstation,	NT_STATUS_INVALID_WORKSTATION},
455148c5f4Alan Wright	{ERRSRV, NERR_PasswordExpired,	NT_STATUS_PASSWORD_EXPIRED},
456148c5f4Alan Wright	{ERRSRV, NERR_AccountExpired,	NT_STATUS_ACCOUNT_DISABLED},
4574bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NONE_MAPPED},
4584bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_TOO_MANY_LUIDS_REQUESTED},
4594bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_LUIDS_EXHAUSTED},
4604bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SUB_AUTHORITY},
4614bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ACL},
4624bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SID},
4634bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_SECURITY_DESCR},
464148c5f4Alan Wright	{ERRDOS, ERROR_PROC_NOT_FOUND,	NT_STATUS_PROCEDURE_NOT_FOUND},
465148c5f4Alan Wright	{ERRDOS, ERROR_BAD_EXE_FORMAT,	NT_STATUS_INVALID_IMAGE_FORMAT},
4664bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_NO_TOKEN},
4674bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_INHERITANCE_ACL},
468148c5f4Alan Wright	{ERRDOS, ERROR_NOT_LOCKED,	NT_STATUS_RANGE_NOT_LOCKED},
469148c5f4Alan Wright	{ERRDOS, ERROR_DISK_FULL,	NT_STATUS_DISK_FULL},
4704bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_SERVER_DISABLED},
4714bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_SERVER_NOT_DISABLED},
472148c5f4Alan Wright	{ERRDOS, ERROR_TOO_MANY_NAMES,	NT_STATUS_TOO_MANY_GUIDS_REQUESTED},
473148c5f4Alan Wright	{ERRDOS, ERROR_NO_MORE_ITEMS,	NT_STATUS_GUIDS_EXHAUSTED},
4744bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_ID_AUTHORITY},
475148c5f4Alan Wright	{ERRDOS, ERROR_NO_MORE_ITEMS,	NT_STATUS_AGENTS_EXHAUSTED},
476148c5f4Alan Wright	{ERRDOS, ERROR_LABEL_TOO_LONG,	NT_STATUS_INVALID_VOLUME_LABEL},
477148c5f4Alan Wright	{ERRDOS, ERROR_OUTOFMEMORY,	NT_STATUS_SECTION_NOT_EXTENDED},
478148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_NOT_MAPPED_DATA},
4794bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_DATA_NOT_FOUND},
4804bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_TYPE_NOT_FOUND},
4814bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_RESOURCE_NAME_NOT_FOUND},
4824bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_ARRAY_BOUNDS_EXCEEDED},
4834bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_DENORMAL_OPERAND},
4844bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_DIVIDE_BY_ZERO},
4854bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_INEXACT_RESULT},
4864bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_INVALID_OPERATION},
4874bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_OVERFLOW},
4884bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_STACK_CHECK},
4894bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FLOAT_UNDERFLOW},
4904bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INTEGER_DIVIDE_BY_ZERO},
491148c5f4Alan Wright	{ERRDOS, ERROR_ARITHMETIC_OVERFLOW,	NT_STATUS_INTEGER_OVERFLOW},
4924bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_PRIVILEGED_INSTRUCTION},
4934bff34ethurlow	{ERRDOS,	ERRnomem,	NT_STATUS_TOO_MANY_PAGING_FILES},
4944bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_FILE_INVALID},
4954bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
4964bff34ethurlow	{ERRDOS,	ERRnomem,	NT_STATUS_INSUFFICIENT_RESOURCES},
4974bff34ethurlow	{ERRDOS,	ERRbadpath,	NT_STATUS_DFS_EXIT_PATH_FOUND},
498148c5f4Alan Wright	{ERRDOS, ERROR_CRC,		NT_STATUS_DEVICE_DATA_ERROR},
4994bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_DEVICE_NOT_CONNECTED},
500148c5f4Alan Wright	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_DEVICE_POWER_FAILURE},
501148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_FREE_VM_NOT_AT_BASE},
502148c5f4Alan Wright	{ERRDOS, ERROR_INVALID_ADDRESS,	NT_STATUS_MEMORY_NOT_ALLOCATED},
5034bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_WORKING_SET_QUOTA},
504148c5f4Alan Wright	{ERRDOS, ERROR_WRITE_PROTECT,	NT_STATUS_MEDIA_WRITE_PROTECTED},
505148c5f4Alan Wright	{ERRDOS, ERROR_NOT_READY,	NT_STATUS_DEVICE_NOT_READY},
5064bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_INVALID_GROUP_ATTRIBUTES},
5074bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_IMPERSONATION_LEVEL},
5084bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_CANT_OPEN_ANONYMOUS},
5094bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_VALIDATION_CLASS},
5104bff34ethurlow	{ERRHRD,	ERRgeneral,	NT_STATUS_BAD_TOKEN_TYPE},
511