/* * Copyright (c) 2000, 2001 Boris Popov * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Boris Popov. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/mchain.h,v 1.1 2001/02/24 15:44:30 bp Exp $ */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * Copyright 2018 Nexenta Systems, Inc. All rights reserved. */ #ifndef _MCHAIN_H_ #define _MCHAIN_H_ #include #include #include #ifdef _LITTLE_ENDIAN /* little-endian values on little-endian */ #define htoles(x) ((uint16_t)(x)) #define letohs(x) ((uint16_t)(x)) #define htolel(x) ((uint32_t)(x)) #define letohl(x) ((uint32_t)(x)) #define htoleq(x) ((uint64_t)(x)) #define letohq(x) ((uint64_t)(x)) /* * big-endian values on little-endian (swap) * * Use the BSWAP macros because they're fastest, and they're * available in all environments where we use this header. */ #define htobes(x) BSWAP_16(x) #define betohs(x) BSWAP_16(x) #define htobel(x) BSWAP_32(x) #define betohl(x) BSWAP_32(x) #define htobeq(x) BSWAP_64(x) #define betohq(x) BSWAP_64(x) #else /* (BYTE_ORDER == LITTLE_ENDIAN) */ /* little-endian values on big-endian (swap) */ #define letohs(x) BSWAP_16(x) #define htoles(x) BSWAP_16(x) #define letohl(x) BSWAP_32(x) #define htolel(x) BSWAP_32(x) #define letohq(x) BSWAP_64(x) #define htoleq(x) BSWAP_64(x) /* big-endian values on big-endian */ #define htobes(x) ((uint16_t)(x)) #define betohs(x) ((uint16_t)(x)) #define htobel(x) ((uint32_t)(x)) #define betohl(x) ((uint32_t)(x)) #define htobeq(x) ((uint64_t)(x)) #define betohq(x) ((uint64_t)(x)) #endif /* (BYTE_ORDER == LITTLE_ENDIAN) */ /* * Additions for Solaris to replace things that came from * in the Darwin code. These are mostly just * wrappers for streams functions. See: subr_mchain.c */ #if defined(_KERNEL) || defined(_FAKE_KERNEL) /* * BSD-style mbuf "shim" for kernel code. Note, this * does NOT implement BSD mbufs in the kernel. Rather, * macros and wrapper functions are used so that code * fomerly using mbuf_t now use STREAMS mblk_t instead. */ #include /* mblk_t */ #include /* MBLKL */ typedef mblk_t mbuf_t; /* BEGIN CSTYLED */ /* * BSD-style mbufs, vs SysV-style mblks: * One big difference: the mbuf payload is: * m_data ... (m_data + m_len) * In Unix STREAMS, the mblk payload is: * b_rptr ... b_wptr * * Here are some handy conversion notes: * * struct mbuf struct mblk * m->m_next m->b_cont * m->m_nextpkt m->b_next * m->m_data m->b_rptr * m->m_len MBLKL(m) * m->m_dat[] m->b_datap->db_base * &m->m_dat[MLEN] m->b_datap->db_lim * M_TRAILINGSPACE(m) MBLKTAIL(m) * m_freem(m) freemsg(m) * * Note that mbufs chains also have a special "packet" header, * which has the length of the whole message. In STREAMS one * typically just calls msgdsize(m) to get that. */ /* END CSTYLED */ #define mtod(m, t) ((t)((m)->b_rptr)) /* length arg for m_copym to "copy all" */ #define M_COPYALL -1 mblk_t *m_copym(mblk_t *, int, int, int); mblk_t *m_pullup(mblk_t *, int); mblk_t *m_split(mblk_t *, int, int); void m_cat(mblk_t *, mblk_t *); #define m_freem(x) freemsg(x) mblk_t *m_getblk(int, int); int m_fixhdr(mblk_t *m); #else /* _KERNEL */ /* * BSD-style mbuf work-alike, for user-level. * See libsmbfs mbuf.c */ typedef struct mbuf { int m_len; int m_maxlen; char *m_data; struct mbuf *m_next; } mbuf_t; #define mtod(m, t) ((t)(m)->m_data) int m_get(int, mbuf_t **); void m_freem(mbuf_t *); #endif /* _KERNEL */ /* * BSD-style mbchain/mdchain work-alike */ /* * Type of copy for mb_{put|get}_mem() */ #define MB_MSYSTEM 0 /* use bcopy() */ #define MB_MUSER 1 /* use copyin()/copyout() */ #define MB_MINLINE 2 /* use an inline copy loop */ #define MB_MZERO 3 /* bzero(), mb_put_mem only */ #define MB_MCUSTOM 4 /* use an user defined function */ #if defined(_KERNEL) || defined(_FAKE_KERNEL) struct mbchain { mblk_t *mb_top; mblk_t *mb_cur; uint_t mb_count; }; typedef struct mbchain mbchain_t; struct mdchain { mblk_t *md_top; /* head of mblk chain */ mblk_t *md_cur; /* current mblk */ uchar_t *md_pos; /* position in md_cur */ /* NB: md_pos is same type as mblk_t b_rptr, b_wptr members. */ }; typedef struct mdchain mdchain_t; mblk_t *mb_detach(mbchain_t *mbp); int mb_fixhdr(mbchain_t *mbp); int mb_put_uio(mbchain_t *mbp, uio_t *uiop, size_t size); void md_append_record(mdchain_t *mdp, mblk_t *top); void md_next_record(mdchain_t *mdp); int md_get_uio(mdchain_t *mdp, uio_t *uiop, size_t size); #else /* _KERNEL */ /* * user-level code uses the same struct for both (MB, MD) */ typedef struct mbdata { mbuf_t *mb_top; /* head of mbuf chain */ mbuf_t *mb_cur; /* current mbuf */ char *mb_pos; /* position in mb_cur (get) */ /* NB: mb_pos is same type as mbuf_t m_data member. */ int mb_count; /* bytes marshalled (put) */ } mbdata_t; typedef struct mbdata mbchain_t; typedef struct mbdata mdchain_t; #endif /* _KERNEL */ int mb_init(mbchain_t *); void mb_initm(mbchain_t *, mbuf_t *); void mb_done(mbchain_t *); void *mb_reserve(mbchain_t *, int size); int mb_put_align8(mbchain_t *mbp); int mb_put_padbyte(mbchain_t *mbp); int mb_put_uint8(mbchain_t *, uint8_t); int mb_put_uint16be(mbchain_t *, uint16_t); int mb_put_uint16le(mbchain_t *, uint16_t); int mb_put_uint32be(mbchain_t *, uint32_t); int mb_put_uint32le(mbchain_t *, uint32_t); int mb_put_uint64be(mbchain_t *, uint64_t); int mb_put_uint64le(mbchain_t *, uint64_t); int mb_put_mem(mbchain_t *, const void *, int, int); int mb_put_mbuf(mbchain_t *, mbuf_t *); int mb_put_mbchain(mbchain_t *, mbchain_t *); int md_init(mdchain_t *mdp); void md_initm(mdchain_t *mbp, mbuf_t *m); void md_done(mdchain_t *mdp); int md_get_uint8(mdchain_t *, uint8_t *); int md_get_uint16be(mdchain_t *, uint16_t *); int md_get_uint16le(mdchain_t *, uint16_t *); int md_get_uint32be(mdchain_t *, uint32_t *); int md_get_uint32le(mdchain_t *, uint32_t *); int md_get_uint64be(mdchain_t *, uint64_t *); int md_get_uint64le(mdchain_t *, uint64_t *); int md_get_mem(mdchain_t *, void *, int, int); int md_get_mbuf(mdchain_t *, int, mbuf_t **); int md_seek(mdchain_t *, uint32_t); uint32_t md_tell(mdchain_t *); #endif /* !_MCHAIN_H_ */ /* * Copyright (c) 2000-2001 Boris Popov * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Boris Popov. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: netbios.h,v 1.5 2004/03/19 01:49:45 lindak Exp $ */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _NETSMB_NETBIOS_H_ #define _NETSMB_NETBIOS_H_ #ifndef _NETINET_IN_H_ #include #endif /* * This is a fake address family number, used to * recognize our fake sockaddr_nb objects. * This is never handed to bind or connect. */ #ifndef AF_NETBIOS #define AF_NETBIOS (AF_MAX+2) #endif #define PF_NETBIOS AF_NETBIOS /* * NetBIOS port numbers by the names used in the Darwin code. * XXX: Change the code to use IPPORT_xxx from in.h directly. * XXX: Add IPPORT_SMB_OVER_TCP or some such (port 445) */ #define NBNS_UDP_PORT IPPORT_NETBIOS_NS /* 137 */ #define SMB_TCP_PORT IPPORT_NETBIOS_SSN /* 139 */ #define NBPROTO_TCPSSN 1 /* NETBIOS session over TCP */ #define NB_NAMELEN 16 #define NB_ENCNAMELEN NB_NAMELEN * 2 #define NB_MAXLABLEN 63 #define NB_MAXPKTLEN 0x1FFFF #define NB_MINSALEN (sizeof (struct sockaddr_nb)) /* * name types */ #define NBT_WKSTA 0x00 #define NBT_CLIENT 0x03 #define NBT_RASSRVR 0x06 #define NBT_DMB 0x1B #define NBT_IP 0x1C #define NBT_MB 0x1D #define NBT_BS 0x1E #define NBT_NETDDE 0x1F #define NBT_SERVER 0x20 #define NBT_RASCLNT 0x21 #define NBT_NMAGENT 0xBE #define NBT_NMUTIL 0xBF /* * Session packet types */ #define NB_SSN_MESSAGE 0x0 #define NB_SSN_REQUEST 0x81 #define NB_SSN_POSRESP 0x82 #define NB_SSN_NEGRESP 0x83 #define NB_SSN_RTGRESP 0x84 #define NB_SSN_KEEPALIVE 0x85 /* * resolver: Opcodes */ #define NBNS_OPCODE_QUERY 0x00 #define NBNS_OPCODE_REGISTER 0x05 #define NBNS_OPCODE_RELEASE 0x06 #define NBNS_OPCODE_WACK 0x07 #define NBNS_OPCODE_REFRESH 0x08 #define NBNS_OPCODE_RESPONSE 0x10 /* or'ed with other opcodes */ /* * resolver: NM_FLAGS */ #define NBNS_NMFLAG_BCAST 0x01 #define NBNS_NMFLAG_RA 0x08 /* recursion available */ #define NBNS_NMFLAG_RD 0x10 /* recursion desired */ #define NBNS_NMFLAG_TC 0x20 /* truncation occured */ #define NBNS_NMFLAG_AA 0x40 /* authoritative answer */ /* * resolver: Question types */ #define NBNS_QUESTION_TYPE_NB 0x0020 #define NBNS_QUESTION_TYPE_NBSTAT 0x0021 /* * resolver: Question class */ #define NBNS_QUESTION_CLASS_IN 0x0001 /* * resolver: Limits */ #define NBNS_MAXREDIRECTS 3 /* max number of accepted redirects */ #define NBDG_MAXSIZE 576 /* maximum nbns datagram size */ /* * NETBIOS addressing */ struct nb_name { uint_t nn_type; char nn_name[NB_NAMELEN]; char *nn_scope; }; typedef struct nb_name nb_name_t; /* * Our private NetBIOS socket address format. * Note that it's LARGER than sockaddr. * * XXX: Also note that the library code is sloppy about * casting this to sockaddr_in so let's keep snb_ipaddr * at the same offset, at least until that's fixed. */ struct sockaddr_nb { sa_family_t snb_family; /* address family */ uint16_t snb_flags; /* NBNS_GROUPFLG, etc. */ uint32_t snb_ipaddr; /* always IPv4 */ char snb_name[NB_NAMELEN]; /* NOT encoded */ }; typedef struct sockaddr_nb sockaddr_nb_t; #endif /* !_NETSMB_NETBIOS_H_ */ /* * Copyright (c) 2000-2001 Boris Popov * All rights reserved. * * Now many of these defines are from samba4 code, by Andrew Tridgell. * (Permission given to Conrad Minshall at CIFS plugfest Aug 13 2003.) * (Note the main decision was whether to use defines found in MS includes * and web pages, versus Samba, and the deciding factor is which developers * are more likely to be looking at this code base.) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Boris Popov. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: smb.h,v 1.36.90.1 2005/05/27 02:35:29 lindak Exp $ */ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2018 Nexenta Systems, Inc. All rights reserved. */ #ifndef _NETSMB_SMB_H_ #define _NETSMB_SMB_H_ /* * Common definitions and structures for SMB/CIFS protocol * This file should be purely SMB protocol definition stuff. * (Please don't make it a catch-all:) */ #include #include #include #include /* * SMB dialects that we have to deal with. */ enum smb_dialects { SMB_DIALECT_NONE, SMB_DIALECT_CORE, /* PC NETWORK PROGRAM 1.0, PCLAN1.0 */ SMB_DIALECT_COREPLUS, /* MICROSOFT NETWORKS 1.03 */ SMB_DIALECT_LANMAN1_0, /* MICROSOFT NETWORKS 3.0, LANMAN1.0 */ SMB_DIALECT_LANMAN2_0, /* LM1.2X002, DOS LM1.2X002, Samba */ SMB_DIALECT_LANMAN2_1, /* DOS LANMAN2.1, LANMAN2.1 */ SMB_DIALECT_NTLM0_12, /* NT LM 0.12, etc. */ SMB_DIALECT_SMB2_FF /* SMB1 negotiate to SMB2 */ }; /* * Formats of data/string buffers */ #define SMB_DT_DATA 1 #define SMB_DT_DIALECT 2 #define SMB_DT_PATHNAME 3 #define SMB_DT_ASCII 4 #define SMB_DT_VARIABLE 5 /* * SMB header */ #define SMB_SIGNATURE "\xFFSMB" #define SMB_SIGLEN 4 #define SMB_HDRCMD(p) (*((uchar_t *)(p) + SMB_SIGLEN)) #define SMB_HDRMID(p) (*(ushort_t *)((uchar_t *)(p) + 30)) #define SMB_HDR_OFF_MID 30 #define SMB_HDRLEN 32 #define SMB_HDR_V1 0xFF #define SMB_HDR_V2 0xFE #define SMB_HDR_V3E 0xFD /* SMB3 encrypted */ /* * bits in the smb_flags field */ #define SMB_FLAGS_SUPPORT_LOCKREAD 0x01 #define SMB_FLAGS_CLIENT_BUF_AVAIL 0x02 #define SMB_FLAGS_CASELESS 0x08 #define SMB_FLAGS_CANONICAL_PATHNAMES 0x10 #define SMB_FLAGS_REQUEST_OPLOCK 0x20 #define SMB_FLAGS_REQUEST_BATCH_OPLOCK 0x40 #define SMB_FLAGS_SERVER_RESP 0x80 /* * bits in the smb_flags2 field */ #define SMB_FLAGS2_KNOWS_LONG_NAMES 0x0001 #define SMB_FLAGS2_KNOWS_EAS 0x0002 /* client know about EAs */ #define SMB_FLAGS2_SECURITY_SIGNATURE 0x0004 /* check SMB integrity */ #define SMB_FLAGS2_IS_LONG_NAME 0x0040 /* any path name is long name */ #define SMB_FLAGS2_EXT_SEC 0x0800 /* client aware of Extended */ /* Security negotiation */ #define SMB_FLAGS2_DFS 0x1000 /* resolve paths in DFS */ #define SMB_FLAGS2_PAGING_IO 0x2000 /* for exec */ #define SMB_FLAGS2_ERR_STATUS 0x4000 /* 1 - status.status */ #define SMB_FLAGS2_UNICODE 0x8000 /* use Unicode for strings */ #define SMB_UID_UNKNOWN 0xffff #define SMB_TID_UNKNOWN 0xffff #define SMB_FID_UNUSED 0xffff /* * Security mode bits */ #define SMB_SM_USER 0x01 /* server in the user security mode */ #define SMB_SM_ENCRYPT 0x02 /* use challenge/responce */ #define SMB_SM_SIGS 0x04 #define SMB_SM_SIGS_REQUIRE 0x08 /* * Action bits in session setup reply */ #define SMB_ACT_GUEST 0x01 /* * NTLM capabilities */ #define SMB_CAP_RAW_MODE 0x0001 #define SMB_CAP_MPX_MODE 0x0002 #define SMB_CAP_UNICODE 0x0004 #define SMB_CAP_LARGE_FILES 0x0008 /* 64 bit offsets supported */ #define SMB_CAP_NT_SMBS 0x0010 #define SMB_CAP_RPC_REMOTE_APIS 0x0020 #define SMB_CAP_STATUS32 0x0040 #define SMB_CAP_LEVEL_II_OPLOCKS 0x0080 #define SMB_CAP_LOCK_AND_READ 0x0100 #define SMB_CAP_NT_FIND 0x0200 #define SMB_CAP_DFS 0x1000 #define SMB_CAP_INFOLEVEL_PASSTHRU 0x2000 #define SMB_CAP_LARGE_READX 0x4000 #define SMB_CAP_LARGE_WRITEX 0x8000 #define SMB_CAP_UNIX 0x00800000 #define SMB_CAP_BULK_TRANSFER 0x20000000 #define SMB_CAP_COMPRESSED_DATA 0x40000000 #define SMB_CAP_EXT_SECURITY 0x80000000 /* SMB_COM_TREE_CONNECT_ANDX flags. See [MS-SMB] for a complete description. */ #define TREE_CONNECT_ANDX_DISCONNECT_TID 0x0001 #define TREE_CONNECT_ANDX_EXTENDED_SIGNATURES 0x0004 #define TREE_CONNECT_ANDX_EXTENDED_RESPONSE 0x0008 /* * SMB_COM_TREE_CONNECT_ANDX optional support flags. See [MS-SMB] for a * complete description. */ #define SMB_SUPPORT_SEARCH_BITS 0x0001 /* supports SearchAttributes */ #define SMB_SHARE_IS_IN_DFS 0x0002 /* share is managed by DFS */ #define SMB_CSC_MASK 0x000C /* Offline-caching bits. */ #define SMB_UNIQUE_FILE_NAME 0x0010 /* Long file names only */ #define SMB_EXTENDED_SIGNATURES 0x0020 /* Signing key protection. */ /* See [MS-SMB] for a complete description of SMB_CSC_MASK bits. */ #define SMB_CSC_CACHE_MANUAL_REINT 0x0000 #define SMB_CSC_CACHE_AUTO_REINT 0x0004 #define SMB_CSC_CACHE_VDO 0x0008 /* * File attributes */ #define SMB_FA_RDONLY 0x01 #define SMB_FA_HIDDEN 0x02 #define SMB_FA_SYSTEM 0x04 #define SMB_FA_VOLUME 0x08 #define SMB_FA_DIR 0x10 #define SMB_FA_ARCHIVE 0x20 /* * Extended file attributes */ #define SMB_EFA_RDONLY 0x00000001 #define SMB_EFA_HIDDEN 0x00000002 #define SMB_EFA_SYSTEM 0x00000004 #define SMB_EFA_VOLUME 0x00000008 #define SMB_EFA_DIRECTORY 0x00000010 #define SMB_EFA_ARCHIVE 0x00000020 #define SMB_EFA_DEVICE 0x00000040 #define SMB_EFA_NORMAL 0x00000080 #define SMB_EFA_TEMPORARY 0x00000100 #define SMB_EFA_SPARSE 0x00000200 #define SMB_EFA_REPARSE_POINT 0x00000400 #define SMB_EFA_COMPRESSED 0x00000800 #define SMB_EFA_OFFLINE 0x00001000 #define SMB_EFA_NONINDEXED 0x00002000 #define SMB_EFA_ENCRYPTED 0x00004000 #define SMB_EFA_POSIX_SEMANTICS 0x01000000 #define SMB_EFA_BACKUP_SEMANTICS 0x02000000 #define SMB_EFA_DELETE_ON_CLOSE 0x04000000 #define SMB_EFA_SEQUENTIAL_SCAN 0x08000000 #define SMB_EFA_RANDOM_ACCESS 0x10000000 #define SMB_EFA_NO_BUFFERING 0x20000000 #define SMB_EFA_WRITE_THROUGH 0x80000000 /* * Access Mode Encoding */ #define SMB_AM_OPENREAD 0x0000 #define SMB_AM_OPENWRITE 0x0001 #define SMB_AM_OPENRW 0x0002 #define SMB_AM_OPENEXEC 0x0003 #define SMB_AM_OPENMODE 0x0003 /* mask for access mode bits */ #define SMB_SM_COMPAT 0x0000 #define SMB_SM_EXCLUSIVE 0x0010 #define SMB_SM_DENYWRITE 0x0020 #define SMB_SM_DENYREADEXEC 0x0030 #define SMB_SM_DENYNONE 0x0040 /* NT_CREATE_ANDX flags */ #define NTCREATEX_FLAGS_REQUEST_OPLOCK 0x02 #define NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK 0x04 #define NTCREATEX_FLAGS_OPEN_DIRECTORY 0x08 #define NTCREATEX_FLAGS_EXTENDED 0x10 /* NT_CREATE_ANDX share_access (share mode) */ #define NTCREATEX_SHARE_ACCESS_NONE 0 #define NTCREATEX_SHARE_ACCESS_READ 1 #define NTCREATEX_SHARE_ACCESS_WRITE 2 #define NTCREATEX_SHARE_ACCESS_DELETE 4 #define NTCREATEX_SHARE_ACCESS_ALL 7 /* NT_CREATE_ANDX open_disposition */ #define NTCREATEX_DISP_SUPERSEDE 0 /* if file exists supersede it */ #define NTCREATEX_DISP_OPEN 1 /* exists ? open it : fail */ #define NTCREATEX_DISP_CREATE 2 /* exists ? fail : create it */ #define NTCREATEX_DISP_OPEN_IF 3 /* exists ? open it : create it */ #define NTCREATEX_DISP_OVERWRITE 4 /* exists ? overwrite : fail */ #define NTCREATEX_DISP_OVERWRITE_IF 5 /* exists ? overwrite : create */ /* NT_CREATE_ANDX create_options */ #define NTCREATEX_OPTIONS_DIRECTORY 0x0001 #define NTCREATEX_OPTIONS_WRITE_THROUGH 0x0002 #define NTCREATEX_OPTIONS_SEQUENTIAL_ONLY 0x0004 #define NTCREATEX_OPTIONS_SYNC_ALERT 0x0010 #define NTCREATEX_OPTIONS_ASYNC_ALERT 0x0020 #define NTCREATEX_OPTIONS_NON_DIRECTORY_FILE 0x0040 #define NTCREATEX_OPTIONS_NO_EA_KNOWLEDGE 0x0200 #define NTCREATEX_OPTIONS_EIGHT_DOT_THREE_ONLY 0x0400 #define NTCREATEX_OPTIONS_RANDOM_ACCESS 0x0800 #define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 #define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 /* NT_CREATE_ANDX "impersonation" */ #define NTCREATEX_IMPERSONATION_ANONYMOUS 0 #define NTCREATEX_IMPERSONATION_IDENTIFICATION 1 #define NTCREATEX_IMPERSONATION_IMPERSONATION 2 #define NTCREATEX_IMPERSONATION_DELEGATION 3 /* NT_CREATE_ANDX security flags */ #define NTCREATEX_SECURITY_DYNAMIC 1 #define NTCREATEX_SECURITY_ALL 2 /* NT_CREATE_ANDX create_action in reply */ #define NTCREATEX_ACTION_EXISTED 1 #define NTCREATEX_ACTION_CREATED 2 #define NTCREATEX_ACTION_TRUNCATED 3 /* SMB_TRANS2_FIND_FIRST2/SMB_TRANS2_FIND_NEXT2 flags */ #define FIND2_CLOSE_AFTER_REQUEST 0x0001 #define FIND2_CLOSE_ON_EOS 0x0002 #define FIND2_RETURN_RESUME_KEYS 0x0004 #define FIND2_CONTINUE_SEARCH 0x0008 #define FIND2_BACKUP_INTENT 0x0010 /* * SMB commands */ #define SMB_COM_CREATE_DIRECTORY 0x00 #define SMB_COM_DELETE_DIRECTORY 0x01 #define SMB_COM_OPEN 0x02 #define SMB_COM_CREATE 0x03 #define SMB_COM_CLOSE 0x04 #define SMB_COM_FLUSH 0x05 #define SMB_COM_DELETE 0x06 #define SMB_COM_RENAME 0x07 #define SMB_COM_QUERY_INFORMATION 0x08 #define SMB_COM_SET_INFORMATION 0x09 #define SMB_COM_READ 0x0A #define SMB_COM_WRITE 0x0B #define SMB_COM_LOCK_BYTE_RANGE 0x0C #define SMB_COM_UNLOCK_BYTE_RANGE 0x0D #define SMB_COM_CREATE_TEMPORARY 0x0E #define SMB_COM_CREATE_NEW 0x0F #define SMB_COM_CHECK_DIRECTORY 0x10 #define SMB_COM_PROCESS_EXIT 0x11 #define SMB_COM_SEEK 0x12 #define SMB_COM_LOCK_AND_READ 0x13 #define SMB_COM_WRITE_AND_UNLOCK 0x14 #define SMB_COM_READ_RAW 0x1A #define SMB_COM_READ_MPX 0x1B #define SMB_COM_READ_MPX_SECONDARY 0x1C #define SMB_COM_WRITE_RAW 0x1D #define SMB_COM_WRITE_MPX 0x1E #define SMB_COM_WRITE_COMPLETE 0x20 #define SMB_COM_SET_INFORMATION2 0x22 #define SMB_COM_QUERY_INFORMATION2 0x23 #define SMB_COM_LOCKING_ANDX 0x24 #define SMB_COM_TRANSACTION 0x25 #define SMB_COM_TRANSACTION_SECONDARY 0x26 #define SMB_COM_IOCTL 0x27 #define SMB_COM_IOCTL_SECONDARY 0x28 #define SMB_COM_COPY 0x29 #define SMB_COM_MOVE 0x2A #define SMB_COM_ECHO 0x2B #define SMB_COM_WRITE_AND_CLOSE 0x2C #define SMB_COM_OPEN_ANDX 0x2D #define SMB_COM_READ_ANDX 0x2E #define SMB_COM_WRITE_ANDX 0x2F #define SMB_COM_CLOSE_AND_TREE_DISC 0x31 #define SMB_COM_TRANSACTION2 0x32 #define SMB_COM_TRANSACTION2_SECONDARY 0x33 #define SMB_COM_FIND_CLOSE2 0x34 #define SMB_COM_FIND_NOTIFY_CLOSE 0x35 #define SMB_COM_TREE_CONNECT 0x70 #define SMB_COM_TREE_DISCONNECT 0x71 #define SMB_COM_NEGOTIATE 0x72 #define SMB_COM_SESSION_SETUP_ANDX 0x73 #define SMB_COM_LOGOFF_ANDX 0x74 #define SMB_COM_TREE_CONNECT_ANDX 0x75 #define SMB_COM_QUERY_INFORMATION_DISK 0x80 #define SMB_COM_SEARCH 0x81 #define SMB_COM_FIND 0x82 #define SMB_COM_FIND_UNIQUE 0x83 #define SMB_COM_NT_TRANSACT 0xA0 #define SMB_COM_NT_TRANSACT_SECONDARY 0xA1 #define SMB_COM_NT_CREATE_ANDX 0xA2 #define SMB_COM_NT_CANCEL 0xA4 #define SMB_COM_OPEN_PRINT_FILE 0xC0 #define SMB_COM_WRITE_PRINT_FILE 0xC1 #define SMB_COM_CLOSE_PRINT_FILE 0xC2 #define SMB_COM_GET_PRINT_QUEUE 0xC3 #define SMB_COM_READ_BULK 0xD8 #define SMB_COM_WRITE_BULK 0xD9 #define SMB_COM_WRITE_BULK_DATA 0xDA /* * SMB_COM_TRANSACTION2 subcommands */ #define SMB_TRANS2_OPEN2 0x00 #define SMB_TRANS2_FIND_FIRST2 0x01 #define SMB_TRANS2_FIND_NEXT2 0x02 #define SMB_TRANS2_QUERY_FS_INFORMATION 0x03 #define SMB_TRANS2_SETFSINFO 0x04 #define SMB_TRANS2_QUERY_PATH_INFORMATION 0x05 #define SMB_TRANS2_SET_PATH_INFORMATION 0x06 #define SMB_TRANS2_QUERY_FILE_INFORMATION 0x07 #define SMB_TRANS2_SET_FILE_INFORMATION 0x08 #define SMB_TRANS2_FSCTL 0x09 #define SMB_TRANS2_IOCTL2 0x0A #define SMB_TRANS2_FIND_NOTIFY_FIRST 0x0B #define SMB_TRANS2_FIND_NOTIFY_NEXT 0x0C #define SMB_TRANS2_CREATE_DIRECTORY 0x0D #define SMB_TRANS2_SESSION_SETUP 0x0E #define SMB_TRANS2_GET_DFS_REFERRAL 0x10 #define SMB_TRANS2_REPORT_DFS_INCONSISTENCY 0x11 /* * SMB_COM_NT_TRANSACT subcommands */ #define NT_TRANSACT_CREATE 0x01 #define NT_TRANSACT_IOCTL 0x02 #define NT_TRANSACT_SET_SECURITY_DESC 0x03 #define NT_TRANSACT_NOTIFY_CHANGE 0x04 #define NT_TRANSACT_RENAME 0x05 #define NT_TRANSACT_QUERY_SECURITY_DESC 0x06 #define NT_TRANSACT_GET_USER_QUOTA 0x07 #define NT_TRANSACT_SET_USER_QUOTA 0x08 /* * SMB_TRANS2_QUERY_FS_INFORMATION levels */ #define SMB_QFS_ALLOCATION 1 #define SMB_QFS_VOLUME 2 #define SMB_QFS_LABEL_INFO 0x101 #define SMB_QFS_VOLUME_INFO 0x102 #define SMB_QFS_SIZE_INFO 0x103 #define SMB_QFS_DEVICE_INFO 0x104 #define SMB_QFS_ATTRIBUTE_INFO 0x105 #define SMB_QFS_UNIX_INFO 0x200 #define SMB_QFS_POSIX_WHOAMI 0x202 #define SMB_QFS_MAC_FS_INFO 0x301 #define SMB_QFS_VOLUME_INFORMATION 1001 #define SMB_QFS_SIZE_INFORMATION 1003 #define SMB_QFS_DEVICE_INFORMATION 1004 #define SMB_QFS_ATTRIBUTE_INFORMATION 1005 #define SMB_QFS_QUOTA_INFORMATION 1006 #define SMB_QFS_FULL_SIZE_INFORMATION 1007 #define SMB_QFS_OBJECTID_INFORMATION 1008 /* * NT Notify Change Compeletion Filter * NT Notify Actions * (We don't use these.) */ /* * SMB_QFS_ATTRIBUTE_INFO bits. * The following info found in msdn * (http://msdn.microsoft.com/library/default.asp? * url=/library/en-us/wmisdk/wmi/win32_cdromdrive.asp) * Naming is mostly as in samba, to help Those Who Google. */ #define FILE_CASE_SENSITIVE_SEARCH 0x00000001 #define FILE_CASE_PRESERVED_NAMES 0x00000002 #define FILE_UNICODE_ON_DISK 0x00000004 #define FILE_PERSISTENT_ACLS 0x00000008 #define FILE_FILE_COMPRESSION 0x00000010 #define FILE_VOLUME_QUOTAS 0x00000020 #define FILE_SUPPORTS_SPARSE_FILES 0x00000040 #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 #define FILE_SUPPORTS_LONG_NAMES 0x00004000 #define FILE_VOLUME_IS_COMPRESSED 0x00008000 #define FILE_SUPPORTS_OBJECT_IDS 0x00010000 #define FILE_SUPPORTS_ENCRYPTION 0x00020000 #define FILE_NAMED_STREAMS 0x00040000 #define FILE_READ_ONLY_VOLUME 0x00080000 /* * SMB_TRANS2_QUERY_PATH levels */ #define SMB_QFILEINFO_STANDARD 1 #define SMB_QFILEINFO_EA_SIZE 2 #define SMB_QFILEINFO_EAS_FROM_LIST 3 #define SMB_QFILEINFO_ALL_EAS 4 #define SMB_QFILEINFO_IS_NAME_VALID 6 /* QPATHINFO only? */ #define SMB_QFILEINFO_BASIC_INFO 0x101 #define SMB_QFILEINFO_STANDARD_INFO 0x102 #define SMB_QFILEINFO_EA_INFO 0x103 #define SMB_QFILEINFO_NAME_INFO 0x104 #define SMB_QFILEINFO_ALLOCATION_INFO 0x105 #define SMB_QFILEINFO_END_OF_FILE_INFO 0x106 #define SMB_QFILEINFO_ALL_INFO 0x107 #define SMB_QFILEINFO_ALT_NAME_INFO 0x108 #define SMB_QFILEINFO_STREAM_INFO 0x109 #define SMB_QFILEINFO_COMPRESSION_INFO 0x10b #define SMB_QFILEINFO_UNIX_BASIC 0x200 #define SMB_QFILEINFO_UNIX_LINK 0x201 #define SMB_QFILEINFO_POSIX_ACL 0x204 #define SMB_QFILEINFO_UNIX_INFO2 0x20B #define SMB_QFILEINFO_MAC_DT_GET_APPL 0x306 #define SMB_QFILEINFO_MAC_DT_GET_ICON 0x307 #define SMB_QFILEINFO_MAC_DT_GET_ICON_INFO 0x308 #define SMB_QFILEINFO_MAC_SPOTLIGHT 0x310 #define SMB_QFILEINFO_BASIC_INFORMATION 1004 #define SMB_QFILEINFO_STANDARD_INFORMATION 1005 #define SMB_QFILEINFO_INTERNAL_INFORMATION 1006 #define SMB_QFILEINFO_EA_INFORMATION 1007 #define SMB_QFILEINFO_ACCESS_INFORMATION 1008 #define SMB_QFILEINFO_NAME_INFORMATION 1009 #define SMB_QFILEINFO_POSITION_INFORMATION 1014 #define SMB_QFILEINFO_MODE_INFORMATION 1016 #define SMB_QFILEINFO_ALIGNMENT_INFORMATION 1017 #define SMB_QFILEINFO_ALL_INFORMATION 1018 #define SMB_QFILEINFO_ALT_NAME_INFORMATION 1021 #define SMB_QFILEINFO_STREAM_INFORMATION 1022 #define SMB_QFILEINFO_COMPRESSION_INFORMATION 1028 #define SMB_QFILEINFO_NETWORK_OPEN_INFORMATION 1034 #define SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION 1035 /* * SMB_TRANS2_FIND_FIRST2 information levels */ #define SMB_FIND_STANDARD 1 #define SMB_FIND_EA_SIZE 2 #define SMB_FIND_EAS_FROM_LIST 3 #define SMB_FIND_DIRECTORY_INFO 0x101 #define SMB_FIND_FULL_DIRECTORY_INFO 0x102 #define SMB_FIND_NAME_INFO 0x103 #define SMB_FIND_BOTH_DIRECTORY_INFO 0x104 #define SMB_FIND_UNIX_INFO 0x200 /* Transact 2 Find First levels */ #define SMB_FIND_FILE_UNIX 0x202 #define SMB_FIND_FILE_UNIX_INFO2 0x20B /* UNIX File Info2 */ /* * Selectors for NT_TRANSACT_QUERY_SECURITY_DESC and * NT_TRANSACT_SET_SECURITY_DESC. Details found in the MSDN * library by searching on security_information. * Note the protected/unprotected bits did not exist in NT. */ #define OWNER_SECURITY_INFORMATION 0x00000001 #define GROUP_SECURITY_INFORMATION 0x00000002 #define DACL_SECURITY_INFORMATION 0x00000004 #define SACL_SECURITY_INFORMATION 0x00000008 #define UNPROTECTED_SACL_SECURITY_INFORMATION 0x10000000 #define UNPROTECTED_DACL_SECURITY_INFORMATION 0x20000000 #define PROTECTED_SACL_SECURITY_INFORMATION 0x40000000 #define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000 /* * security descriptor header * it is followed by the optional SIDs and ACLs * note this is "raw", ie little-endian */ struct ntsecdesc { uint8_t sd_revision; /* 0x01 observed between W2K */ uint8_t sd_pad1; uint16_t sd_flags; uint32_t sd_owneroff; /* offset to owner SID */ uint32_t sd_groupoff; /* offset to group SID */ uint32_t sd_sacloff; /* offset to system/audit ACL */ uint32_t sd_dacloff; /* offset to discretionary ACL */ }; /* XXX: __attribute__((__packed__)); */ typedef struct ntsecdesc ntsecdesc_t; #define wset_sdrevision(s) ((s)->sd_revision = 0x01) #define sdflags(s) (letohs((s)->sd_flags)) #define wset_sdflags(s, f) ((s)->sd_flags = letohs(f)) #define sdowner(s) \ ((struct ntsid *)((s)->sd_owneroff ? \ (char *)(s) + letohl((s)->sd_owneroff) : \ NULL)) #define wset_sdowneroff(s, o) ((s)->sd_owneroff = htolel(o)) #define sdgroup(s) \ ((struct ntsid *)((s)->sd_groupoff ? \ (char *)(s) + letohl((s)->sd_groupoff) : \ NULL)) #define wset_sdgroupoff(s, o) ((s)->sd_groupoff = htolel(o)) #define sdsacl(s) \ ((struct ntacl *)((s)->sd_sacloff ? \ (char *)(s) + letohl((s)->sd_sacloff) : \ NULL)) #define wset_sdsacloff(s, o) ((s)->sd_sacloff = htolel(o)) #define sddacl(s) \ ((struct ntacl *)((s)->sd_dacloff ? \ (char *)(s) + letohl((s)->sd_dacloff) : \ NULL)) #define wset_sddacloff(s, o) ((s)->sd_dacloff = htolel(o)) /* * sd_flags bits */ #define SD_OWNER_DEFAULTED 0x0001 #define SD_GROUP_DEFAULTED 0x0002 #define SD_DACL_PRESENT 0x0004 #define SD_DACL_DEFAULTED 0x0008 #define SD_SACL_PRESENT 0x0010 #define SD_SACL_DEFAULTED 0x0020 #define SD_DACL_TRUSTED 0x0040 #define SD_SERVER_SECURITY 0x0080 #define SD_DACL_AUTO_INHERIT_REQ 0x0100 #define SD_SACL_AUTO_INHERIT_REQ 0x0200 #define SD_DACL_AUTO_INHERITED 0x0400 #define SD_SACL_AUTO_INHERITED 0x0800 #define SD_DACL_PROTECTED 0x1000 #define SD_SACL_PROTECTED 0x2000 #define SD_RM_CONTROL_VALID 0x4000 #define SD_SELF_RELATIVE 0x8000 /* * access control list header * it is followed by the ACEs * note this is "raw", ie little-endian */ struct ntacl { uint8_t acl_revision; /* 0x02 observed with W2K */ uint8_t acl_pad1; uint16_t acl_len; /* bytes; includes this header */ uint16_t acl_acecount; uint16_t acl_pad2; }; /* XXX: __attribute__((__packed__)); */ typedef struct ntacl ntacl_t; #define wset_aclrevision(a) ((a)->acl_revision = 0x02) #define acllen(a) (letohs((a)->acl_len)) #define wset_acllen(a, l) ((a)->acl_len = htoles(l)) #define aclacecount(a) (letohs((a)->acl_acecount)) #define wset_aclacecount(a, c) ((a)->acl_acecount = htoles(c)) #define aclace(a) ((struct ntace *)((char *)(a) + sizeof (struct ntacl))) /* * access control entry header * it is followed by type-specific ace data, * which for the simple types is just a SID * note this is "raw", ie little-endian */ struct ntace { uint8_t ace_type; uint8_t ace_flags; uint16_t ace_len; /* bytes; includes this header */ uint32_t ace_rights; /* generic, standard, specific, etc */ }; /* XXX: __attribute__((__packed__)); */ #define acetype(a) ((a)->ace_type) #define wset_acetype(a, t) ((a)->ace_type = (t)) #define aceflags(a) ((a)->ace_flags) #define wset_aceflags(a, f) ((a)->ace_flags = (f)) #define acelen(a) (letohs((a)->ace_len)) #define wset_acelen(a, l) ((a)->ace_len = htoles(l)) #define acerights(a) (letohl((a)->ace_rights)) #define wset_acerights(a, r) ((a)->ace_rights = htolel(r)) #define aceace(a) ((struct ntace *)((char *)(a) + acelen(a))) #define acesid(a) ((struct ntsid *)((char *)(a) + sizeof (struct ntace))) /* * ace_rights * (Samba bit names are used here, with permission, as the shorter Windows * names are more likely to cause namespace collisions) */ #define SA_RIGHT_FILE_READ_DATA 0x00000001 #define SA_RIGHT_FILE_WRITE_DATA 0x00000002 #define SA_RIGHT_FILE_APPEND_DATA 0x00000004 #define SA_RIGHT_FILE_READ_EA 0x00000008 #define SA_RIGHT_FILE_WRITE_EA 0x00000010 #define SA_RIGHT_FILE_EXECUTE 0x00000020 #define SA_RIGHT_FILE_DELETE_CHILD 0x00000040 #define SA_RIGHT_FILE_READ_ATTRIBUTES 0x00000080 #define SA_RIGHT_FILE_WRITE_ATTRIBUTES 0x00000100 #define SA_RIGHT_FILE_ALL_ACCESS 0x000001FF #define STD_RIGHT_DELETE_ACCESS 0x00010000 #define STD_RIGHT_READ_CONTROL_ACCESS 0x00020000 #define STD_RIGHT_WRITE_DAC_ACCESS 0x00040000 #define STD_RIGHT_WRITE_OWNER_ACCESS 0x00080000 #define STD_RIGHT_SYNCHRONIZE_ACCESS 0x00100000 #define STD_RIGHT_ALL_ACCESS 0x001F0000 #define SEC_RIGHT_SYSTEM_SECURITY 0x01000000 /* * Don't use MAXIMUM_ALLOWED as Samba (2.2.3 at least) will * return NT_STATUS_INVALID_LOCK_SEQUENCE */ #define SEC_RIGHT_MAXIMUM_ALLOWED 0x02000000 #define GENERIC_RIGHT_ALL_ACCESS 0x10000000 #define GENERIC_RIGHT_EXECUTE_ACCESS 0x20000000 #define GENERIC_RIGHT_WRITE_ACCESS 0x40000000 #define GENERIC_RIGHT_READ_ACCESS 0x80000000 /* * these mappings are from Windows sample code but are likely incomplete * * GENERIC_RIGHT_READ_ACCESS : * STD_RIGHT_SYNCHRONIZE_ACCESS | * STD_RIGHT_READ_CONTROL_ACCESS | * SA_RIGHT_FILE_READ_ATTRIBUTES | * SA_RIGHT_FILE_READ_EA | * SA_RIGHT_FILE_READ_DATA * GENERIC_RIGHT_WRITE_ACCESS : * STD_RIGHT_SYNCHRONIZE_ACCESS | * STD_RIGHT_READ_CONTROL_ACCESS | * SA_RIGHT_FILE_WRITE_ATTRIBUTES | * SA_RIGHT_FILE_WRITE_EA | * SA_RIGHT_FILE_APPEND_DATA | * SA_RIGHT_FILE_WRITE_DATA * GENERIC_RIGHT_EXECUTE_ACCESS : * STD_RIGHT_SYNCHRONIZE_ACCESS | * STD_RIGHT_READ_CONTROL_ACCESS | * SA_RIGHT_FILE_READ_ATTRIBUTES | * SA_RIGHT_FILE_EXECUTE * GENERIC_RIGHT_ALL_ACCESS : * STD_RIGHT_SYNCHRONIZE_ACCESS | * STD_RIGHT_WRITE_OWNER_ACCESS | * STD_RIGHT_WRITE_DAC_ACCESS | * STD_RIGHT_READ_CONTROL_ACCESS | * STD_RIGHT_DELETE_ACCESS | * SA_RIGHT_FILE_ALL_ACCESS */ /* * security identifier header * it is followed by sid_numauth sub-authorities, * which are 32 bits each. * note the subauths are little-endian on the wire, but * need to be big-endian for memberd/DS */ #define SIDAUTHSIZE 6 struct ntsid { uint8_t sid_revision; uint8_t sid_subauthcount; uint8_t sid_authority[SIDAUTHSIZE]; /* ie not little endian */ }; /* XXX: __attribute__((__packed__)); */ typedef struct ntsid ntsid_t; #define sidsubauthcount(s) (s->sid_subauthcount) #define sidlen(s) (sizeof (struct ntsid) + 4 * (s)->sid_subauthcount) #define MAXSIDLEN (sizeof (struct ntsid) + 4 * KAUTH_NTSID_MAX_AUTHORITIES) #define sidsub(s) ((uint32_t *)((char *)(s) + sizeof (struct ntsid))) /* * MS' defined values for ace_type */ #define ACCESS_ALLOWED_ACE_TYPE 0x0 #define ACCESS_DENIED_ACE_TYPE 0x1 #define SYSTEM_AUDIT_ACE_TYPE 0x2 #define SYSTEM_ALARM_ACE_TYPE 0x3 #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x4 #define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x5 #define ACCESS_DENIED_OBJECT_ACE_TYPE 0x6 #define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x7 #define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x8 #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x9 #define ACCESS_DENIED_CALLBACK_ACE_TYPE 0xA #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0xB #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0xC #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0xD #define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0xE #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0xF #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* * MS' defined values for ace_flags */ #define OBJECT_INHERIT_ACE_FLAG 0x01 #define CONTAINER_INHERIT_ACE_FLAG 0x02 #define NO_PROPAGATE_INHERIT_ACE_FLAG 0x04 #define INHERIT_ONLY_ACE_FLAG 0x08 #define INHERITED_ACE_FLAG 0x10 #define UNDEF_ACE_FLAG 0x20 /* MS doesn't define it */ #define VALID_INHERIT_ACE_FLAGS 0x1F #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40 #define FAILED_ACCESS_ACE_FLAG 0x80 /* * Set PATH/FILE information levels */ #define SMB_SFILEINFO_STANDARD 1 #define SMB_SFILEINFO_EA_SET 2 #define SMB_SFILEINFO_BASIC_INFO 0x101 #define SMB_SFILEINFO_DISPOSITION_INFO 0x102 #define SMB_SFILEINFO_ALLOCATION_INFO 0x103 #define SMB_SFILEINFO_END_OF_FILE_INFO 0x104 #define SMB_SFILEINFO_UNIX_BASIC 0x200 #define SMB_SFILEINFO_UNIX_LINK 0x201 #define SMB_SFILEINFO_UNIX_HLINK 0x203 #define SMB_SFILEINFO_POSIX_ACL 0x204 #define SMB_SFILEINFO_POSIX_UNLINK 0x20A #define SMB_SFILEINFO_UNIX_INFO2 0x20B #define SMB_SFILEINFO_DIRECTORY_INFORMATION 1001 #define SMB_SFILEINFO_FULL_DIRECTORY_INFORMATION 1002 #define SMB_SFILEINFO_BOTH_DIRECTORY_INFORMATION 1003 #define SMB_SFILEINFO_BASIC_INFORMATION 1004 #define SMB_SFILEINFO_STANDARD_INFORMATION 1005 #define SMB_SFILEINFO_INTERNAL_INFORMATION 1006 #define SMB_SFILEINFO_EA_INFORMATION 1007 #define SMB_SFILEINFO_ACCESS_INFORMATION 1008 #define SMB_SFILEINFO_NAME_INFORMATION 1009 #define SMB_SFILEINFO_RENAME_INFORMATION 1010 #define SMB_SFILEINFO_LINK_INFORMATION 1011 #define SMB_SFILEINFO_NAMES_INFORMATION 1012 #define SMB_SFILEINFO_DISPOSITION_INFORMATION 1013 #define SMB_SFILEINFO_POSITION_INFORMATION 1014 #define SMB_SFILEINFO_1015 1015 /* ? */ #define SMB_SFILEINFO_MODE_INFORMATION 1016 #define SMB_SFILEINFO_ALIGNMENT_INFORMATION 1017 #define SMB_SFILEINFO_ALL_INFORMATION 1018 #define SMB_SFILEINFO_ALLOCATION_INFORMATION 1019 #define SMB_SFILEINFO_END_OF_FILE_INFORMATION 1020 #define SMB_SFILEINFO_ALT_NAME_INFORMATION 1021 #define SMB_SFILEINFO_STREAM_INFORMATION 1022 #define SMB_SFILEINFO_PIPE_INFORMATION 1023 #define SMB_SFILEINFO_PIPE_LOCAL_INFORMATION 1024 #define SMB_SFILEINFO_PIPE_REMOTE_INFORMATION 1025 #define SMB_SFILEINFO_MAILSLOT_QUERY_INFORMATION 1026 #define SMB_SFILEINFO_MAILSLOT_SET_INFORMATION 1027 #define SMB_SFILEINFO_COMPRESSION_INFORMATION 1028 #define SMB_SFILEINFO_OBJECT_ID_INFORMATION 1029 #define SMB_SFILEINFO_COMPLETION_INFORMATION 1030 #define SMB_SFILEINFO_MOVE_CLUSTER_INFORMATION 1031 #define SMB_SFILEINFO_QUOTA_INFORMATION 1032 #define SMB_SFILEINFO_REPARSE_POINT_INFORMATION 1033 #define SMB_SFILEINFO_NETWORK_OPEN_INFORMATION 1034 #define SMB_SFILEINFO_ATTRIBUTE_TAG_INFORMATION 1035 #define SMB_SFILEINFO_TRACKING_INFORMATION 1036 #define SMB_SFILEINFO_MAXIMUM_INFORMATION 1037 /* * LOCKING_ANDX LockType flags */ #define SMB_LOCKING_ANDX_SHARED_LOCK 0x01 #define SMB_LOCKING_ANDX_OPLOCK_RELEASE 0x02 #define SMB_LOCKING_ANDX_CHANGE_LOCKTYPE 0x04 #define SMB_LOCKING_ANDX_CANCEL_LOCK 0x08 #define SMB_LOCKING_ANDX_LARGE_FILES 0x10 /* * size of the GUID returned in an extended security negotiate response */ #define SMB_GUIDLEN 16 typedef uint16_t smbfh; /* * NTLMv2 blob header structure. */ struct ntlmv2_blobhdr { uint32_t header; uint32_t reserved; uint64_t timestamp; uint64_t client_nonce; uint32_t unknown1; }; typedef struct ntlmv2_blobhdr ntlmv2_blobhdr_t; /* * NTLMv2 name header structure, for names in a blob. */ struct ntlmv2_namehdr { uint16_t type; uint16_t len; }; typedef struct ntlmv2_namehdr ntlmv2_namehdr_t; #define NAMETYPE_EOL 0x0000 /* end of list of names */ #define NAMETYPE_MACHINE_NB 0x0001 /* NetBIOS machine name */ #define NAMETYPE_DOMAIN_NB 0x0002 /* NetBIOS domain name */ #define NAMETYPE_MACHINE_DNS 0x0003 /* DNS machine name */ #define NAMETYPE_DOMAIN_DNS 0x0004 /* DNS Active Directory domain name */ /* * Named pipe commands. */ #define TRANS_CALL_NAMED_PIPE 0x54 /* open/write/read/close pipe */ #define TRANS_WAIT_NAMED_PIPE 0x53 /* wait for pipe to be !busy */ #define TRANS_PEEK_NAMED_PIPE 0x23 /* read but don't remove data */ #define TRANS_Q_NAMED_PIPE_HAND_STATE 0x21 /* query pipe handle modes */ #define TRANS_SET_NAMED_PIPE_HAND_STATE 0x01 /* set pipe handle modes */ #define TRANS_Q_NAMED_PIPE_INFO 0x22 /* query pipe attributes */ #define TRANS_TRANSACT_NAMED_PIPE 0x26 /* r/w operation on pipe */ #define TRANS_READ_NAMED_PIPE 0x11 /* read pipe in "raw" mode */ /* (non message mode) */ #define TRANS_WRITE_NAMED_PIPE 0x31 /* write pipe "raw" mode */ /* (non message mode) */ /* * Share types, visible via NetShareEnum */ #define STYPE_DISKTREE 0x00000000 #define STYPE_PRINTQ 0x00000001 #define STYPE_DEVICE 0x00000002 #define STYPE_IPC 0x00000003 #define STYPE_UNKNOWN 0x00000004 #define STYPE_MASK 0x0000000F #define STYPE_TEMPORARY 0x40000000 #define STYPE_HIDDEN 0x80000000 /* * Characters that are not allowed in an SMB file name component. * From MSDN: Naming Files, Paths, ... * < (less than) * > (greater than) * : (colon) * " (double quote) * / (forward slash) * \ (backslash) * | (vertical bar or pipe) * ? (question mark) * * (asterisk) */ #define SMB_FILENAME_INVALID_CHARS "<>:\"/\\|?*" #endif /* _NETSMB_SMB_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2018 Nexenta Systems, Inc. All rights reserved. * Copyright 2025 RackTop Systems, Inc. */ #ifndef _NETSMB_SMB2_H #define _NETSMB_SMB2_H #ifdef __cplusplus extern "C" { #endif #define SMB2_PROTOCOL_ID { 0xFE, 'S', 'M', 'B' } #define SMB2_HDR_SIZE 64 #define SMB2_HDRLEN SMB2_HDR_SIZE /* * SMB2 header command codes. * These are uint16_t on the wire. */ typedef enum { SMB2_NEGOTIATE = 0, SMB2_SESSION_SETUP, SMB2_LOGOFF, SMB2_TREE_CONNECT, SMB2_TREE_DISCONNECT, SMB2_CREATE, SMB2_CLOSE, SMB2_FLUSH, SMB2_READ, SMB2_WRITE, SMB2_LOCK, SMB2_IOCTL, SMB2_CANCEL, SMB2_ECHO, SMB2_QUERY_DIRECTORY, SMB2_CHANGE_NOTIFY, SMB2_QUERY_INFO, SMB2_SET_INFO, SMB2_OPLOCK_BREAK, /* * The above (oplock break) is the last real SMB2 op-code. * We use one more slot to represent invalid commands, and * the final enum value is used for array sizes. Keep last! */ SMB2_INVALID_CMD, SMB2__NCMDS } SMB2_cmd_code; /* * SMB2 header flags. */ /* * SERVER_TO_REDIR * When set, indicates the message is a response rather than * a request. This MUST be set on responses sent from the * server to the client, and MUST NOT be set on requests * sent from the client to the server. */ #define SMB2_FLAGS_SERVER_TO_REDIR 0x00000001 /* * ASYNC_COMMAND * When set, indicates that this is an ASYNC SMB2 header. * Always set for headers of the form described in this * section. */ #define SMB2_FLAGS_ASYNC_COMMAND 0x00000002 /* * RELATED_OPERATIONS * When set in an SMB2 request, indicates that this request * is a related operation in a compounded request chain. * [MS-SMB2 sec. 3.2.4.1.4] * * When set in an SMB2 compound response, indicates that * the request corresponding to this response was part of a * related operation in a compounded request chain. * [MS-SMB2 sec. 3.3.5.2.7.2] */ #define SMB2_FLAGS_RELATED_OPERATIONS 0x00000004 /* * SIGNED * When set, indicates that this packet has been signed. * [MS-SMB2 3.1.5.1] */ #define SMB2_FLAGS_SIGNED 0x00000008 /* * [MS-SMB2] 3.2.5.3.1 The SessionKey MUST be set to the * first 16 bytes of the cryptographic key from GSSAPI. * (Padded with zeros if the GSSAPI key is shorter.) */ #define SMB2_SESSION_KEY_LEN 16 /* * DFS_OPERATIONS * When set, indicates that this command is a Distributed * File System (DFS) operation. [MS-SMB2 3.3.5.9] */ #define SMB2_FLAGS_DFS_OPERATIONS 0x10000000 /* * REPLAY_OPERATION * This flag is only valid for the SMB 3.0 dialect. When set, * it indicates that this command is a replay operation. * The client MUST ignore this bit on receipt. */ #define SMB2_FLAGS_REPLAY_OPERATION 0x20000000 /* * SMB2 Netgotiate [MS-SMB2 2.2.3] */ #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x01 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x02 #define SMB2_CAP_DFS 0x00000001 /* Added with SMB2.1 */ #define SMB2_CAP_DFS 0x00000001 #define SMB2_CAP_LEASING 0x00000002 /* * LARGE_MTU: * When set, indicates that the client supports multi-credit operations. */ #define SMB2_CAP_LARGE_MTU 0x00000004 /* Added with SMB3.0 */ #define SMB2_CAP_MULTI_CHANNEL 0x00000008 #define SMB2_CAP_PERSISTENT_HANDLES 0x00000010 #define SMB2_CAP_DIRECTORY_LEASING 0x00000020 #define SMB2_CAP_ENCRYPTION 0x00000040 /* * SMB3.1.1 Negotiate Context pre-authentication hash * there's only the one. */ #define SMB3_HASH_SHA512 1 /* * SMB3.1.1 Negotiate Context encryption ciphers */ #define SMB3_CIPHER_NONE 0 #define SMB3_CIPHER_AES128_CCM 1 #define SMB3_CIPHER_AES128_GCM 2 #define SMB3_CIPHER_AES256_CCM 3 #define SMB3_CIPHER_AES256_GCM 4 /* * SMB3.1.1 Negotiate Context signing algorithms */ #define SMB3_SIGN_SHA256_HMAC 0 /* 2.x */ #define SMB3_SIGN_AES128_CMAC 1 /* 3.0 */ #define SMB3_SIGN_AES128_GMAC 2 /* 3.1.1 */ /* * SMB2 Session Setup [MS-SMB2 2.2.5] */ /* SMB2 session flags */ #define SMB2_SESSION_FLAG_IS_GUEST 0x0001 #define SMB2_SESSION_FLAG_IS_NULL 0x0002 #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004 /* * SMB2 Tree connect, disconnect */ /* SMB2 sharetype flags */ #define SMB2_SHARE_TYPE_DISK 0x1 #define SMB2_SHARE_TYPE_PIPE 0x2 #define SMB2_SHARE_TYPE_PRINT 0x3 /* SMB2 share flags */ #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030 #define SMB2_SHAREFLAG_DFS 0x00000001 #define SMB2_SHAREFLAG_DFS_ROOT 0x00000002 #define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS 0x00000100 #define SMB2_SHAREFLAG_FORCE_SHARED_DELETE 0x00000200 #define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING 0x00000400 #define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM 0x00000800 #define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK 0x00001000 /* SMB 3.0 */ #define SMB2_SHAREFLAG_ENABLE_HASH_V1 0x00002000 #define SMB2_SHAREFLAG_ENABLE_HASH_V2 0x00004000 #define SMB2_SHAREFLAG_ENCRYPT_DATA 0x00008000 /* SMB2 share capabilities */ #define SMB2_SHARE_CAP_DFS 0x00000008 /* SMB 3.0 */ #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY 0x00000010 #define SMB2_SHARE_CAP_SCALEOUT 0x00000020 #define SMB2_SHARE_CAP_CLUSTER 0x00000040 /* * SMB2 Create (open) */ /* SMB2 requested oplock levels */ #define SMB2_OPLOCK_LEVEL_NONE 0x00 #define SMB2_OPLOCK_LEVEL_II 0x01 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 #define SMB2_OPLOCK_LEVEL_BATCH 0x09 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF /* SMB2 impersonation levels */ #define SMB2_IMPERSONATION_ANONYMOUS 0x00 #define SMB2_IMPERSONATION_IDENTIFICATION 0x01 #define SMB2_IMPERSONATION_IMPERSONATION 0x02 #define SMB2_IMPERSONATION_DELEGATE 0x03 /* * Note: ShareAccess, CreateDispositon, CreateOptions, * all use the same definitions as SMB1 (from MS-FSA). * Ditto FileAccess flags (as with ACLs) */ /* SMB2 Create Context tags */ #define SMB2_CREATE_EA_BUFFER 0x45787441 /* ("ExtA") */ /* * The data contains the extended attributes * that MUST be stored on the created file. * This value MUST NOT be set for named * pipes and print files. */ #define SMB2_CREATE_SD_BUFFER 0x53656344 /* ("SecD") */ /* * The data contains a security descriptor that * MUST be stored on the created file. * This value MUST NOT be set for named * pipes and print files. */ #define SMB2_CREATE_DURABLE_HANDLE_REQUEST 0x44486e51 /* ("DHnQ") */ /* The client is requesting the open to be durable */ #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT 0x44486e43 /* ("DHnC") */ /* * The client is requesting to reconnect to a * durable open after being disconnected */ #define SMB2_CREATE_ALLOCATION_SIZE 0x416c5369 /* ("AISi") */ /* * The data contains the required allocation * size of the newly created file. */ #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS 0x4d784163 /* ("MxAc") */ /* * The client is requesting that the server * return maximal access information. */ #define SMB2_CREATE_TIMEWARP_TOKEN 0x54577270 /* ("TWrp") */ /* * The client is requesting that the server * open an earlier version of the file identified * by the provided time stamp. */ #define SMB2_CREATE_QUERY_ON_DISK_ID 0x51466964 /* ("QFid") */ /* * The client is requesting that the server return a 32-byte * opaque BLOB that uniquely identifies the file being opened * on disk. No data is passed to the server by the client. */ #define SMB2_CREATE_REQUEST_LEASE 0x52714c73 /* ("RqLs") */ /* * The client is requesting that the server return a lease. * This value is only supported for the SMB 2.1 and 3.0 dialects. */ /* SMB2 create request lease */ #define SMB2_LEASE_NONE 0x00 #define SMB2_LEASE_READ_CACHING 0x01 #define SMB2_LEASE_HANDLE_CACHING 0x02 #define SMB2_LEASE_WRITE_CACHING 0x04 /* SMB2 lease break notification flags */ #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED 0x01 /* * SMB2 Close */ #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB 0x0001 /* * SMB2 Write */ #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* * SMB2 Lock Request */ /* SMB2 lock flags */ /* * SMB2_LOCKFLAG_SHARED_LOCK * The range MUST be locked shared, allowing other opens * to read from or take a shared lock on the range. All opens * MUST NOT be allowed to write within the range. Other * locks can be requested and taken on this range. */ #define SMB2_LOCKFLAG_SHARED_LOCK 0x00000001 /* * SMB2_LOCKFLAG_EXCLUSIVE_LOCK * The range MUST be locked exclusive, not allowing other * opens to read, write, or lock within the range. */ #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x00000002 /* * SMB2_LOCKFLAG_UNLOCK * The range MUST be unlocked from a previous lock taken * on this range. The unlock range MUST be identical to the * lock range. Sub-ranges cannot be unlocked. */ #define SMB2_LOCKFLAG_UNLOCK 0x00000004 /* * SMB2_LOCKFLAG_FAIL_IMMEDIATELY * The lock operation MUST fail immediately if it conflicts * with an existing lock, instead of waiting for the range to * become available. This can be OR'ed with either of * shared_lock, exclusive_lock (nothing else). */ #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x00000010 /* * SMB2 Ioctl Request */ #define SMB2_IOCTL_IS_FSCTL 0x00000001 /* * SMB2 Query Directory */ /* * SMB2 query directory info levels * Same as SMB1 (see ntifs.h) */ /* * SMB2 Query Directory Flags * (our own names for these - spec. used poor names) */ #define SMB2_QDIR_FLAG_RESTART 0x01 /* SMB2_RESTART_SCANS */ #define SMB2_QDIR_FLAG_SINGLE 0x02 /* SMB2_RETURN_SINGLE_ENTRY */ #define SMB2_QDIR_FLAG_INDEX 0x04 /* SMB2_INDEX_SPECIFIED */ #define SMB2_QDIR_FLAG_REOPEN 0x10 /* SMB2_REOPEN */ /* * SMB2 Query Info Request */ /* info type */ #define SMB2_0_INFO_FILE 0x01 /* The file information is requested. */ #define SMB2_0_INFO_FILESYSTEM 0x02 /* The underlying object store information is requested. */ #define SMB2_0_INFO_SECURITY 0x03 /* The security information is requested. */ #define SMB2_0_INFO_QUOTA 0x04 /* The underlying object store quota information is requested. */ /* * MS-FSCC 2.5 FileSystem Information Classes. * Also see MSDN for ZwQueryVolumeInformationFile. */ typedef enum _FS_INFORMATION_CLASS { FileFsVolumeInformation = 1, /* Query */ FileFsLabelInformation = 2, /* Set */ FileFsSizeInformation = 3, /* Query */ FileFsDeviceInformation = 4, /* Query */ FileFsAttributeInformation = 5, /* Query */ FileFsControlInformation = 6, /* Query, Set */ FileFsFullSizeInformation = 7, /* Query */ FileFsObjectIdInformation = 8, /* Query, Set */ FileFsDriverPathInformation = 9 /* Query */ } FS_INFORMATION_CLASS; /* * MS-FSCC 2.4 File Information Classes */ typedef enum _FILE_INFORMATION_CLASS { FileDirectoryInformation = 1, FileFullDirectoryInformation = 2, FileBothDirectoryInformation = 3, FileBasicInformation = 4, FileStandardInformation = 5, FileInternalInformation = 6, FileEaInformation = 7, FileAccessInformation = 8, FileNameInformation = 9, FileRenameInformation = 10, FileLinkInformation = 11, FileNamesInformation = 12, FileDispositionInformation = 13, FilePositionInformation = 14, FileFullEaInformation = 15, FileModeInformation = 16, FileAlignmentInformation = 17, FileAllInformation = 18, FileAllocationInformation = 19, FileEndOfFileInformation = 20, FileAlternateNameInformation = 21, FileStreamInformation = 22, FilePipeInformation = 23, FilePipeLocalInformation = 24, FilePipeRemoteInformation = 25, FileMailslotQueryInformation = 26, FileMailslotSetInformation = 27, FileCompressionInformation = 28, FileObjectIdInformation = 29, FileMoveClusterInformation = 31, FileQuotaInformation = 32, FileReparsePointInformation = 33, FileNetworkOpenInformation = 34, FileAttributeTagInformation = 35, FileTrackingInformation = 36, FileIdBothDirectoryInformation = 37, FileIdFullDirectoryInformation = 38, FileValidDataLengthInformation = 39, FileShortNameInformation = 40, FileSfioReserveInformation = 44, FileSfioVolumeInformation = 45, FileHardLinkInformation = 46, FileNormalizedNameInformation = 48, FileIdGlobalTxDirectoryInformation = 50, FileStandardLinkInformation = 54 } FILE_INFORMATION_CLASS; /* * SMB2 Change Nofity Request */ #define SMB2_WATCH_TREE 0x00000001 /* * After here, added stuff from darwin */ #define SMB2_TID_UNKNOWN 0 #define SMB2_FID_UNUSED 0xffffffffffffffff /* smb2_durable_handle flags */ typedef enum _SMB2_DURABLE_HANDLE_FLAGS { SMB2_DURABLE_HANDLE_REQUEST = 0x0001, SMB2_DURABLE_HANDLE_RECONNECT = 0x0002, SMB2_DURABLE_HANDLE_GRANTED = 0x0004, SMB2_LEASE_GRANTED = 0x0008 } _SMB2_DURABLE_HANDLE_FLAGS; struct smb2_durable_handle { uint64_t fid; /* SMBFID to reconnect in durable handle reconnect */ uint64_t flags; uint64_t lease_key_hi; /* atomic increment number */ uint64_t lease_key_low; /* node hash value */ uint32_t lease_state; uint32_t pad; }; #ifdef __cplusplus } #endif #endif /* _NETSMB_SMB2_H */ /* * Copyright (c) 2000-2001 Boris Popov * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Boris Popov. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: smb_dev.h,v 1.10.178.1 2005/05/27 02:35:29 lindak Exp $ */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * Copyright 2018 Nexenta Systems, Inc. All rights reserved. * Copyright 2021-2025 RackTop Systems, Inc. */ #ifndef _NETSMB_DEV_H_ #define _NETSMB_DEV_H_ /* * This file defines an internal ABI for the "nsmb" driver, * particularly the various data structures passed to ioctl. * In order to avoid some messy 32-bit to 64-bit conversions * in the driver, we take pains to define all data structures * that pass across the user/kernel boundary in a way that * makes them invariant across 32-bit and 64-bit ABIs. * This invariance is checked during the driver build * using a mechanism similar to genassym.h builds. * * If you change any of the ioctl data structures in * this file, YOU MUST ALSO edit this file: * uts/common/fs/smbclnt/netsmb/offsets.in * and then verify the invariance describe above. * * Also, remember to "bump" NSMB_VER below when * any part of this user/kernel I/F changes. */ #include #include #include #define NSMB_NAME "nsmb" /* * Update NSMB_VER* if any of the ioctl codes and/or * associated structures change in ways that would * make them incompatible with an old driver. */ #define NSMB_VERMAJ 2 #define NSMB_VERMIN 0x100 #define NSMB_VERSION ((NSMB_VERMAJ << 16) | NSMB_VERMIN) /* * Some errno values we need to expose to the library. * NB: these are also defined in the library smbfs_api.h * to avoid exposing all of this stuff in that API. * * EBADRPC is used for message decoding errors. * EAUTH is used for CIFS authentication errors. */ #ifndef EBADRPC #define EBADRPC 113 #endif #ifndef EAUTH #define EAUTH 114 #endif /* * Upper/lower case options */ #define SMB_CS_NONE 0x0000 #define SMB_CS_UPPER 0x0001 /* convert passed string to upper case */ #define SMB_CS_LOWER 0x0002 /* convert passed string to lower case */ /* * access mode stuff (see also smb_lib.h) */ #define SMBM_ANY_OWNER ((uid_t)-1) #define SMBM_ANY_GROUP ((gid_t)-1) /* * Option flags in smbioc_ossn.ioc_opt * and vcspec.optflags */ #define SMBVOPT_CREATE 0x0001 /* create object if necessary */ #define SMBVOPT_PRIVATE 0x0002 /* connection should be private */ #define SMBVOPT_SINGLESHARE 0x0004 /* keep only one share at this VC */ #define SMBVOPT_PERMANENT 0x0010 /* object will keep last reference */ #define SMBVOPT_ANONYMOUS 0x0020 /* using a NULL session */ #define SMBVOPT_SIGNING_ENABLED 0x10000 /* sign if server agrees */ #define SMBVOPT_SIGNING_REQUIRED 0x20000 /* signing required */ #define SMBVOPT_SIGNING_MASK 0x30000 /* all signing bits */ #define SMB2_DIALECT_BASE 0x0200 #define SMB2_DIALECT_0202 0x0202 #define SMB2_DIALECT_02ff 0x02ff #define SMB2_DIALECT_0210 0x0210 #define SMB2_DIALECT_0300 0x0300 #define SMB2_DIALECT_0302 0x0302 #define SMB2_DIALECT_0311 0x0311 /* Maximum supported dialect (for ssn_maxver) */ #define SMB2_DIALECT_MAX SMB2_DIALECT_0311 /* * Option flags in smbioc_oshare.ioc_opt * and sharespec.optflags */ #define SMBSOPT_CREATE SMBVOPT_CREATE #define SMBSOPT_PERMANENT SMBVOPT_PERMANENT /* All user and machine names. */ #define SMBIOC_MAX_NAME 256 /* * Size of storage for p/w hashes. * Also for SMBIOC_GETSSNKEY. */ #define SMBIOC_HASH_SZ 16 /* * network IO daemon states */ enum smbiod_state { SMBIOD_ST_UNINIT = 0, /* uninitialized */ SMBIOD_ST_RECONNECT, /* a [re]connect attempt requested */ SMBIOD_ST_RCFAILED, /* a reconnect attempt has failed */ SMBIOD_ST_CONNECTED, /* Transport (TCP) connected */ SMBIOD_ST_NEGOTIATED, /* Negotiated SMB/SMB2+ */ SMBIOD_ST_AUTHCONT, /* Session setup continuing */ SMBIOD_ST_AUTHFAIL, /* Session setup failed */ SMBIOD_ST_AUTHOK, /* Session setup success */ SMBIOD_ST_VCACTIVE, /* iod_work running */ SMBIOD_ST_IDLE, /* no trees, will go DEAD */ SMBIOD_ST_DEAD /* connection gone, no IOD */ }; /* * We're now using structures that are invariant * across 32-bit vs 64-bit compilers for all * member sizes and offsets. Scalar members * simply have to use fixed-size types. * Pointers are a little harder... * We use this union for all pointers that * must pass between user and kernel. */ typedef union lptr { uint64_t lp_ll; #ifdef _LP64 void *lp_ptr; #endif #ifdef _ILP32 void *_lp_p2[2]; #ifdef _LITTLE_ENDIAN #define lp_ptr _lp_p2[0] #define lp_pad _lp_p2[1] #else /* _ENDIAN */ #define lp_pad _lp_p2[0] #define lp_ptr _lp_p2[1] #endif /* _ENDIAN */ #endif /* _ILP32 */ } lptr_t; /* * Handy union of sockaddr types we use. * Type discriminator is sa_family */ union smbioc_sockaddr { struct sockaddr sa; /* generic */ struct sockaddr_in sin; struct sockaddr_in6 sin6; }; typedef union smbioc_sockaddr smbioc_sockaddr_t; /* * This is what identifies a session. */ struct smbioc_ssn_ident { smbioc_sockaddr_t id_srvaddr; char id_domain[SMBIOC_MAX_NAME]; char id_user[SMBIOC_MAX_NAME]; }; typedef struct smbioc_ssn_ident smbioc_ssn_ident_t; /* * Flags for smbioc_ossn.ssn_opt */ #define SMBLK_CREATE SMBVOPT_CREATE /* * Structure used with SMBIOC_SSN_FIND, _CREATE */ struct smbioc_ossn { uint32_t ssn_owner; /* Unix owner (UID) */ uint32_t ssn_vopt; /* i.e. SMBVOPT_CREATE */ uint16_t ssn_minver; /* Min SMB version. */ uint16_t ssn_maxver; /* Max SMB version. */ smbioc_ssn_ident_t ssn_id; char ssn_srvname[SMBIOC_MAX_NAME]; }; typedef struct smbioc_ossn smbioc_ossn_t; /* Convenience names for members under ssn_id */ #define ssn_srvaddr ssn_id.id_srvaddr #define ssn_domain ssn_id.id_domain #define ssn_user ssn_id.id_user /* * Structure used with SMBIOC_TREE_FIND, _CONNECT */ struct smbioc_oshare { uint32_t sh_use; /* requested */ uint32_t sh_type; /* returned */ char sh_name[SMBIOC_MAX_NAME]; char sh_pass[SMBIOC_MAX_NAME]; }; typedef struct smbioc_oshare smbioc_oshare_t; typedef struct smbioc_tcon { int32_t tc_flags; int32_t tc_opt; smbioc_oshare_t tc_sh; } smbioc_tcon_t; /* * This is the operational state information passed * in and out of the driver for SMBIOC_SSN_WORK */ struct smbioc_ssn_work { uint32_t wk_out_state; /* out-only */ uint32_t wk_u_ssnkey_len; /* ssn key length */ lptr_t wk_u_ssnkey_buf; /* user-space ptr! */ uint32_t wk_u_auth_rlen; /* recv auth tok len */ uint32_t wk_u_auth_wlen; /* send auth tok len */ lptr_t wk_u_auth_rbuf; /* recv auth tok buf */ lptr_t wk_u_auth_wbuf; /* send auth tok buf */ uint8_t wk_cl_guid[16]; /* client GUID */ }; typedef struct smbioc_ssn_work smbioc_ssn_work_t; /* * User-level SMB requests */ typedef struct smbioc_rw { uint32_t ioc_cnt; uint32_t ioc_flags; lloff_t _ioc_offset; lptr_t _ioc_base; } smbioc_rw_t; #define ioc_offset _ioc_offset._f #define ioc_base _ioc_base.lp_ptr /* Transact on named pipe (send/recv) */ typedef struct smbioc_xnp { uint32_t ioc_tdlen; /* transmit len */ uint32_t ioc_rdlen; /* recv maxlen */ uint32_t ioc_more; /* more data to read */ uint32_t ioc_pad1; lptr_t _ioc_tdata; lptr_t _ioc_rdata; } smbioc_xnp_t; #define ioc_tdata _ioc_tdata.lp_ptr #define ioc_rdata _ioc_rdata.lp_ptr typedef struct smbioc_ntcreate { uint32_t ioc_req_acc; uint32_t ioc_efattr; uint32_t ioc_share_acc; uint32_t ioc_open_disp; uint32_t ioc_creat_opts; char ioc_name[SMBIOC_MAX_NAME]; } smbioc_ntcreate_t; typedef struct smbioc_printjob { uint16_t ioc_setuplen; uint16_t ioc_prmode; char ioc_title[SMBIOC_MAX_NAME]; } smbioc_printjob_t; /* Password Keychain (PK) support. */ typedef struct smbioc_pk { uid_t pk_uid; /* UID for PAM use */ char pk_dom[SMBIOC_MAX_NAME]; /* CIFS domain name */ char pk_usr[SMBIOC_MAX_NAME]; /* CIFS user name */ uchar_t pk_lmhash[SMBIOC_HASH_SZ]; /* LanMan p/w hash */ uchar_t pk_nthash[SMBIOC_HASH_SZ]; /* NTLM p/w hash */ } smbioc_pk_t; /* * Device IOCTLs * * Define ioctl codes the way ZFS does. * The "base" value is arbitrary, and can * occupy the high word if we like, because * our driver does its own copyin/copyout. * Keep GETVERS first and use it to verify * driver compatibility with the library. */ #define SMBIOC_BASE ((('n' << 8) | 's') << 8) typedef enum nsmb_ioc { SMBIOC_GETVERS = SMBIOC_BASE, /* keep first */ SMBIOC_FLAGS2, /* obsolete */ SMBIOC_GETSSNKEY, /* get SMB session key */ SMBIOC_DUP_DEV, /* duplicate dev handle */ SMBIOC_READ, /* read (pipe) */ SMBIOC_WRITE, /* write (pipe) */ SMBIOC_XACTNP, /* "transact" (pipe) */ SMBIOC_NTCREATE, /* open or create */ SMBIOC_PRINTJOB, /* open print job */ SMBIOC_CLOSEFH, /* from ntcreate or printjob */ SMBIOC_SSN_CREATE, SMBIOC_SSN_FIND, SMBIOC_SSN_KILL, /* force disconnect */ SMBIOC_SSN_RELE, /* drop our reference */ SMBIOC_TREE_CONNECT, /* create and connect */ SMBIOC_TREE_FIND, SMBIOC_TREE_KILL, SMBIOC_TREE_RELE, SMBIOC_IOD_CONNECT, /* Setup connection */ SMBIOC_IOD_NEGOTIATE, /* SMB/SMB2 negotiate */ SMBIOC_IOD_SSNSETUP, /* SMB/SMB2 session setup */ SMBIOC_IOD_WORK, /* work on session requests */ SMBIOC_IOD_IDLE, /* wait for requests on this session */ SMBIOC_IOD_RCFAIL, /* tell driver reconnect failed */ /* Password Keychain (PK) support. */ SMBIOC_PK_ADD, /* Add/Modify a password entry */ SMBIOC_PK_CHK, /* Check for a password entry */ SMBIOC_PK_DEL, /* Delete specified password entry */ SMBIOC_PK_DEL_OWNER, /* all owned by the caller */ SMBIOC_PK_DEL_EVERYONE /* all owned by everyone */ } nsmb_ioc_t; #endif /* _NETSMB_DEV_H_ */