4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011-2022 Tintri by DDN, Inc. All rights reserved.
24 * Copyright 2017-2023 RackTop Systems, Inc.
28 * Structures and type definitions for the SMB module.
31 #ifndef _SMBSRV_SMB_KTYPES_H
32 #define _SMBSRV_SMB_KTYPES_H
39 #include <sys/systm.h>
40 #include <sys/param.h>
41 #include <sys/types.h>
42 #include <sys/synch.h>
43 #include <sys/taskq.h>
44 #include <sys/socket.h>
48 #include <sys/vnode.h>
50 #include <netinet/in.h>
51 #include <sys/ksocket.h>
53 #include <smbsrv/smb.h>
54 #include <smbsrv/smb2.h>
55 #include <smbsrv/smbinfo.h>
56 #include <smbsrv/mbuf.h>
57 #include <smbsrv/smb_sid.h>
58 #include <smbsrv/smb_xdr.h>
59 #include <smbsrv/netbios.h>
60 #include <smbsrv/smb_vops.h>
61 #include <smbsrv/smb_kstat.h>
63 struct __door_handle
; /* <sys/door.h> */
64 struct edirent
; /* <sys/extdirent.h> */
67 struct smb_disp_entry
;
74 * Accumulated time and queue length statistics.
76 * Accumulated time statistics are kept as a running sum of "active" time.
77 * Queue length statistics are kept as a running sum of the product of queue
78 * length and elapsed time at that length -- i.e., a Riemann sum for queue
79 * length integrated against time. (You can also think of the active time as a
80 * Riemann sum, for the boolean function (queue_length > 0) integrated against
81 * time, or you can think of it as the Lebesgue measure of the set on which
89 * Length | _________ | |
94 * |_______________________________|
97 * At each change of state (entry or exit from the queue), we add the elapsed
98 * time (since the previous state change) to the active time if the queue length
99 * was non-zero during that interval; and we add the product of the elapsed time
100 * times the queue length to the running length*time sum.
102 * This method is generalizable to measuring residency in any defined system:
103 * instead of queue lengths, think of "outstanding RPC calls to server X".
105 * A large number of I/O subsystems have at least two basic "lists" of
106 * transactions they manage: one for transactions that have been accepted for
107 * processing but for which processing has yet to begin, and one for
108 * transactions which are actively being processed (but not done). For this
109 * reason, two cumulative time statistics are defined here: wait (pre-service)
110 * time, and run (service) time.
112 * All times are 64-bit nanoseconds (hrtime_t), as returned by gethrtime().
114 * The units of cumulative busy time are accumulated nanoseconds. The units of
115 * cumulative length*time products are elapsed time times queue length.
117 * Updates to the fields below are performed implicitly by calls to
121 * smb_srqueue_destroy()
122 * smb_srqueue_waitq_enter()
123 * smb_srqueue_runq_exit()
124 * smb_srqueue_waitq_to_runq()
125 * smb_srqueue_update()
127 * These fields should never be updated by any other means.
129 typedef struct smb_srqueue
{
131 hrtime_t srq_wlastupdate
;
133 hrtime_t srq_wlentime
;
134 hrtime_t srq_rlastupdate
;
136 hrtime_t srq_rlentime
;
142 * The fields with the prefix 'ly_a' contain the statistics collected since the
143 * server was last started ('a' for 'aggregated'). The fields with the prefix
144 * 'ly_d' contain the statistics collected since the last snapshot ('d' for
147 typedef struct smb_latency
{
152 hrtime_t ly_a_stddev
;
156 hrtime_t ly_d_stddev
;
159 typedef struct smb_disp_stats
{
160 volatile uint64_t sdt_txb
;
161 volatile uint64_t sdt_rxb
;
162 smb_latency_t sdt_lat
;
165 int smb_noop(void *, size_t, int);
167 #define SMB_AUDIT_STACK_DEPTH 16
168 #define SMB_AUDIT_BUF_MAX_REC 16
169 #define SMB_AUDIT_NODE 0x00000001
172 * Maximum number of records returned in SMBsearch, SMBfind
173 * and SMBfindunique response. Value set to 10 for compatibility
176 #define SMB_MAX_SEARCH 10
178 #define SMB_SEARCH_ATTRIBUTES \
179 (FILE_ATTRIBUTE_HIDDEN | \
180 FILE_ATTRIBUTE_SYSTEM | \
181 FILE_ATTRIBUTE_DIRECTORY)
183 #define SMB_SEARCH_HIDDEN(sattr) ((sattr) & FILE_ATTRIBUTE_HIDDEN)
184 #define SMB_SEARCH_SYSTEM(sattr) ((sattr) & FILE_ATTRIBUTE_SYSTEM)
185 #define SMB_SEARCH_DIRECTORY(sattr) ((sattr) & FILE_ATTRIBUTE_DIRECTORY)
186 #define SMB_SEARCH_ALL(sattr) ((sattr) & SMB_SEARCH_ATTRIBUTES)
191 pc_t anr_stack
[SMB_AUDIT_STACK_DEPTH
];
192 } smb_audit_record_node_t
;
197 smb_audit_record_node_t anb_records
[SMB_AUDIT_BUF_MAX_REC
];
198 } smb_audit_buf_node_t
;
201 * Thread State Machine
202 * --------------------
205 * smb_thread_destroy() <-------+ +------- smb_thread_init()
208 * +-----------------------------+
209 * | SMB_THREAD_STATE_EXITED |<---+
210 * +-----------------------------+ |
213 * +-----------------------------+ |
214 * | SMB_THREAD_STATE_STARTING | |
215 * +-----------------------------+ |
218 * +-----------------------------+ |
219 * | SMB_THREAD_STATE_RUNNING | |
220 * +-----------------------------+ |
223 * +-----------------------------+ |
224 * | SMB_THREAD_STATE_EXITING |----+
225 * +-----------------------------+
229 * This transition is executed in smb_thread_init().
233 * This transition is executed in smb_thread_start().
237 * This transition is executed by the thread itself when it starts running.
241 * This transition is executed by the thread itself in
242 * smb_thread_entry_point() just before calling thread_exit().
247 * This transition is executed in smb_thread_stop().
251 * This transition is executed in smb_thread_destroy().
253 typedef enum smb_thread_state
{
254 SMB_THREAD_STATE_STARTING
= 0,
255 SMB_THREAD_STATE_RUNNING
,
256 SMB_THREAD_STATE_EXITING
,
257 SMB_THREAD_STATE_EXITED
,
258 SMB_THREAD_STATE_FAILED
259 } smb_thread_state_t
;
263 typedef void (*smb_thread_ep_t
)(struct _smb_thread
*, void *ep_arg
);
265 #define SMB_THREAD_MAGIC 0x534D4254 /* SMBT */
267 typedef struct _smb_thread
{
270 smb_thread_state_t sth_state
;
271 struct smb_server
*sth_server
;
274 smb_thread_ep_t sth_ep
;
286 * A pool of IDs is a pool of 16 bit numbers. It is implemented as a bitmap.
287 * A bit set to '1' indicates that that particular value has been allocated.
288 * The allocation process is done shifting a bit through the whole bitmap.
289 * The current position of that index bit is kept in the smb_idpool_t
290 * structure and represented by a byte index (0 to buffer size minus 1) and
291 * a bit index (0 to 7).
293 * The pools start with a size of 8 bytes or 64 IDs. Each time the pool runs
294 * out of IDs its current size is doubled until it reaches its maximum size
295 * (8192 bytes or 65536 IDs). The IDs 0 and 65535 are never given out which
296 * means that a pool can have a maximum number of 65534 IDs available.
298 #define SMB_IDPOOL_MAGIC 0x4944504C /* IDPL */
299 #define SMB_IDPOOL_MIN_SIZE 64 /* Number of IDs to begin with */
300 #define SMB_IDPOOL_MAX_SIZE 64 * 1024
302 typedef struct smb_idpool
{
312 uint32_t id_free_counter
;
313 uint32_t id_max_free_counter
;
317 * Maximum size of a Transport Data Unit when CAP_LARGE_READX and
318 * CAP_LARGE_WRITEX are not set. CAP_LARGE_READX/CAP_LARGE_WRITEX
319 * allow the payload to exceed the negotiated buffer size.
320 * 4 --> NBT/TCP Transport Header.
322 * 1 --> Word Count byte
323 * 510 --> Maximum Number of bytes of the Word Table (2 * 255)
324 * 2 --> Byte count of the data
325 * 65535 --> Maximum size of the data
329 #define SMB_REQ_MAX_SIZE 66560 /* 65KB */
330 #define SMB_XPRT_MAX_SIZE (SMB_REQ_MAX_SIZE + NETBIOS_HDR_SZ)
332 #define SMB_TXREQ_MAGIC 0X54524251 /* 'TREQ' */
337 uint8_t tr_buf
[SMB_XPRT_MAX_SIZE
];
340 #define SMB_TXLST_MAGIC 0X544C5354 /* 'TLST' */
344 kcondvar_t tl_wait_cv
;
349 * Maximum buffer size for NT is 37KB. If all clients are Windows 2000, this
350 * can be changed to 64KB. 37KB must be used with a mix of NT/Windows 2000
351 * clients because NT loses directory entries when values greater than 37KB are
354 * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to
355 * account for the NBT header.
358 #define SMB_NT_MAXBUF (37 * 1024)
360 #define OUTBUFSIZE (65 * 1024)
361 #define SMBHEADERSIZE 32
362 #define SMBND_HASH_MASK (0xFF)
363 #define MAX_IOVEC 512
364 #define MAX_READREF (8 * 1024)
366 #define SMB_WORKER_MIN 4
367 #define SMB_WORKER_DEFAULT 64
368 #define SMB_WORKER_MAX 1024
371 * Destructor object used in the locked-list delete queue.
373 #define SMB_DTOR_MAGIC 0x44544F52 /* DTOR */
374 #define SMB_DTOR_VALID(d) \
375 ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC))
377 typedef void (*smb_dtorproc_t
)(void *);
379 typedef struct smb_dtor
{
383 smb_dtorproc_t dt_proc
;
386 typedef struct smb_lavl
{
392 uint32_t la_deleteq_count
;
393 boolean_t la_flushing
;
396 typedef struct smb_llist
{
403 uint32_t ll_deleteq_count
;
404 boolean_t ll_flushing
;
407 typedef struct smb_bucket
{
412 typedef struct smb_hash
{
414 uint32_t num_buckets
;
415 smb_bucket_t
*buckets
;
418 typedef struct smb_slist
{
423 boolean_t sl_waiting
;
427 * smb_avl_t State Machine
428 * --------------------
430 * +-----------------------------+
431 * | SMB_AVL_STATE_START |
432 * +-----------------------------+
435 * +-----------------------------+
436 * | SMB_AVL_STATE_READY |
437 * +-----------------------------+
440 * +-----------------------------+
441 * | SMB_AVL_STATE_DESTROYING |
442 * +-----------------------------+
446 * This transition is executed in smb_avl_create().
450 * This transition is executed in smb_avl_destroy().
454 SMB_AVL_STATE_START
= 0,
456 SMB_AVL_STATE_DESTROYING
459 typedef struct smb_avl_nops
{
460 int (*avln_cmp
) (const void *, const void *);
461 void (*avln_hold
)(const void *);
462 boolean_t (*avln_rele
)(const void *);
463 void (*avln_destroy
)(void *);
466 typedef struct smb_avl_cursor
{
468 uint32_t avlc_sequence
;
471 typedef struct smb_avl
{
476 smb_avl_state_t avl_state
;
478 uint32_t avl_sequence
;
479 const smb_avl_nops_t
*avl_nops
;
486 boolean_t rwx_waiting
;
489 typedef struct smb_export
{
492 smb_avl_t e_share_avl
;
493 smb_slist_t e_unexport_list
;
494 smb_thread_t e_unexport_thread
;
498 * NOTIFY CHANGE, a.k.a. File Change Notification (FCN)
502 * These FCN filter mask values are not from MS-FSCC, but
503 * must not overlap with any FILE_NOTIFY_VALID_MASK values.
505 #define FILE_NOTIFY_CHANGE_EV_SUBDIR 0x00010000
506 #define FILE_NOTIFY_CHANGE_EV_DELETE 0x00020000
507 #define FILE_NOTIFY_CHANGE_EV_CLOSED 0x00040000
508 #define FILE_NOTIFY_CHANGE_EV_OVERFLOW 0x00080000
511 * Note: These FCN action values are not from MS-FSCC, but must
512 * follow in sequence from FILE_ACTION_MODIFIED_STREAM.
514 * FILE_ACTION_SUBDIR_CHANGED is used internally for
515 * "watch tree" support, posted to all parents of a
516 * directory that had one of the changes above.
518 * FILE_ACTION_DELETE_PENDING is used internally to tell
519 * notify change requests when the "delete-on-close" flag
520 * has been set on the directory being watched.
522 * FILE_ACTION_HANDLE_CLOSED is used to wakeup notify change
523 * requests when the watched directory handle is closed.
525 #define FILE_ACTION_SUBDIR_CHANGED 0x00000009
526 #define FILE_ACTION_DELETE_PENDING 0x0000000a
527 #define FILE_ACTION_HANDLE_CLOSED 0x0000000b
530 * Sub-struct within smb_ofile_t
532 typedef struct smb_notify
{
533 list_t nc_waiters
; /* Waiting SRs */
534 mbuf_chain_t nc_buffer
;
538 boolean_t nc_subscribed
;
542 * SMB operates over a NetBIOS-over-TCP transport (NBT) or directly
543 * over TCP, which is also known as direct hosted NetBIOS-less SMB
546 * NBT messages have a 4-byte header that defines the message type
547 * (8-bits), a 7-bit flags field and a 17-bit length.
549 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
550 * | TYPE | FLAGS |E| LENGTH |
551 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
553 * 8-bit type Defined in RFC 1002
554 * 7-bit flags Bits 0-6 reserved (must be 0)
555 * Bit 7: Length extension bit (E)
556 * 17-bit length Includes bit 7 of the flags byte
559 * SMB-over-TCP is defined to use a modified version of the NBT header
560 * containing an 8-bit message type and 24-bit message length.
562 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
564 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
566 * 8-bit type Must be 0
569 * The following structure is used to represent a generic, in-memory
570 * SMB transport header; it is not intended to map directly to either
571 * of the over-the-wire formats.
578 int MBC_LENGTH(struct mbuf_chain
*);
579 int MBC_MAXBYTES(struct mbuf_chain
*);
580 void MBC_SETUP(struct mbuf_chain
*, uint32_t);
581 void MBC_INIT(struct mbuf_chain
*, uint32_t);
582 void MBC_FLUSH(struct mbuf_chain
*);
583 void MBC_ATTACH_MBUF(struct mbuf_chain
*, struct mbuf
*);
584 void MBC_APPEND_MBUF(struct mbuf_chain
*, struct mbuf
*);
585 void MBC_ATTACH_BUF(struct mbuf_chain
*MBC
, unsigned char *BUF
, int LEN
);
586 int MBC_SHADOW_CHAIN(struct mbuf_chain
*SUBMBC
, struct mbuf_chain
*MBC
,
589 #define MBC_ROOM_FOR(b, n) (((b)->chain_offset + (n)) <= (b)->max_bytes)
592 * Per smb_node oplock state
594 typedef struct smb_oplock
{
596 boolean_t ol_fem
; /* fem monitor installed? */
597 struct smb_ofile
*excl_open
;
604 kcondvar_t WaitingOpenCV
;
608 * Per smb_ofile oplock state
610 typedef struct smb_oplock_grant
{
611 /* smb protocol-level state */
612 uint32_t og_state
; /* what client has now */
613 uint32_t og_breakto
; /* level breaking to */
614 boolean_t og_breaking
;
615 uint16_t og_dialect
; /* how to send breaks */
616 kcondvar_t og_ack_cv
; /* Wait for ACK */
617 /* File-system level state */
622 uint8_t BreakingToRead
;
623 } smb_oplock_grant_t
;
625 #define SMB_LEASE_KEY_SZ 16
627 typedef struct smb_lease
{
628 list_node_t ls_lnd
; /* sv_lease_ht */
629 kmutex_t ls_mutex
; /* for ls_refcnt */
630 smb_llist_t
*ls_bucket
;
631 struct smb_node
*ls_node
;
633 * With a lease, just one ofile has the oplock.
634 * This (used only for comparison) identifies which.
636 void *ls_oplock_ofile
;
638 uint32_t ls_state
; /* what client has now */
639 uint32_t ls_breakto
; /* level breaking to */
642 boolean_t ls_breaking
;
643 boolean_t ls_destroying
;
644 kcondvar_t ls_ack_cv
; /* Wait for ACK */
645 uint8_t ls_key
[SMB_LEASE_KEY_SZ
];
646 uint8_t ls_clnt
[SMB_LEASE_KEY_SZ
];
649 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */
650 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC)
653 SMB_NODE_STATE_AVAILABLE
= 0,
654 SMB_NODE_STATE_DESTROYING
658 * waiting_event # of clients requesting FCN
659 * n_timestamps cached timestamps
660 * n_allocsz cached file allocation size
661 * n_dnode directory node
662 * n_unode unnamed stream node
663 * delete_on_close_cred credentials for delayed delete
665 typedef struct smb_node
{
670 smb_node_state_t n_state
;
673 smb_llist_t
*n_hash_bucket
;
674 uint32_t n_open_count
;
675 uint32_t n_opening_count
;
676 smb_llist_t n_ofile_list
;
677 /* If entering both, go in order n_lock_list, n_wlock_list */
678 smb_llist_t n_lock_list
; /* active locks */
679 smb_llist_t n_wlock_list
; /* waiting locks */
681 u_offset_t n_allocsz
;
682 uint32_t n_fcn_count
;
683 smb_oplock_t n_oplock
;
684 struct smb_node
*n_dnode
;
685 struct smb_node
*n_unode
;
686 cred_t
*delete_on_close_cred
;
687 uint32_t n_delete_on_close_flags
;
688 char od_name
[MAXNAMELEN
];
690 smb_audit_buf_node_t
*n_audit_buf
;
693 #define NODE_FLAGS_REPARSE 0x00001000
694 #define NODE_FLAGS_DFSLINK 0x00002000
695 #define NODE_FLAGS_VFSROOT 0x00004000
696 #define NODE_FLAGS_SYSTEM 0x00008000
697 #define NODE_FLAGS_WRITE_THROUGH 0x00100000
698 #define NODE_XATTR_DIR 0x01000000
699 #define NODE_FLAGS_DELETE_COMMITTED 0x20000000
700 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000
701 #define NODE_FLAGS_EXECUTABLE 0x80000000
703 #define SMB_NODE_VFS(node) ((node)->vp->v_vfsp)
704 #define SMB_NODE_FSID(node) ((node)->vp->v_vfsp->vfs_fsid)
706 /* Maximum buffer size for encryption key */
707 #define SMB_ENCRYPT_KEY_MAXLEN 32
709 #define SMB_SHARE_MAGIC 0x4B534852 /* KSHR */
711 typedef struct smb_kshare
{
724 uint32_t shr_autocnt
;
727 char *shr_access_none
;
730 smb_node_t
*shr_root_node
;
731 smb_node_t
*shr_ca_dir
;
732 void *shr_import_busy
;
733 smb_cfg_val_t shr_encrypt
; /* Share.EncryptData */
737 typedef struct smb_arg_negotiate
{
741 uint32_t ni_capabilities
;
742 uint16_t ni_maxmpxcount
;
743 int16_t ni_tzcorrection
;
745 uint8_t ni_key
[SMB_ENCRYPT_KEY_MAXLEN
];
746 timestruc_t ni_servertime
;
747 } smb_arg_negotiate_t
;
750 SMB_SSNSETUP_PRE_NTLM012
= 1,
751 SMB_SSNSETUP_NTLM012_NOEXT
,
752 SMB_SSNSETUP_NTLM012_EXTSEC
753 } smb_ssnsetup_type_t
;
755 typedef struct smb_arg_sessionsetup
{
756 smb_ssnsetup_type_t ssi_type
;
759 /* LM password hash, f.k.a. case-insensitive p/w */
760 uint16_t ssi_lmpwlen
;
762 /* NT password hash, f.k.a. case-sensitive p/w */
763 uint16_t ssi_ntpwlen
;
765 /* Incoming security blob */
766 uint16_t ssi_iseclen
;
767 uint8_t *ssi_isecblob
;
768 /* Incoming security blob */
769 uint16_t ssi_oseclen
;
770 uint8_t *ssi_osecblob
;
772 uint16_t ssi_maxbufsize
;
773 uint16_t ssi_maxmpxcount
;
774 uint32_t ssi_capabilities
;
777 } smb_arg_sessionsetup_t
;
779 typedef struct tcon
{
786 uint16_t optional_support
;
791 * Based on section 2.6.1.2 (Connection Management) of the June 13,
792 * 1996 CIFS spec, a server may terminate the transport connection
793 * due to inactivity. The client software is expected to be able to
794 * automatically reconnect to the server if this happens. Like much
795 * of the useful background information, this section appears to
796 * have been dropped from later revisions of the document.
798 * Each session has an activity timestamp that's updated whenever a
799 * request is dispatched. If the session is idle, i.e. receives no
800 * requests, for SMB_SESSION_INACTIVITY_TIMEOUT minutes it will be
803 * Each session has an I/O semaphore to serialize communication with
804 * the client. For example, after receiving a raw-read request, the
805 * server is not allowed to send an oplock break to the client until
806 * after it has sent the raw-read data.
808 #define SMB_SESSION_INACTIVITY_TIMEOUT (15 * 60)
823 uint8_t key
[32]; /* fit AES-256 key */
826 #define SMB_SIGNING_ENABLED 1
827 #define SMB_SIGNING_CHECK 2
831 * If you hold the mutex/lock on an object, don't flush the deleteq
832 * of the objects directly below it in the logical hierarchy
833 * (i.e. via smb_llist_exit()). I.e. don't drop s_tree_list when
834 * you hold u_mutex, because deleted trees need u_mutex to
837 * Note that this also applies to u_mutex and t_ofile_list.
841 * The "session" object.
843 * Note that the smb_session_t object here corresponds to what MS-SMB2
844 * calls a "connection". Adding to the confusion, what MS calls a
845 * "session" corresponds to our smb_user_t (below).
849 * Session State Machine
850 * ---------------------
853 * +-----------------------------+ +----------------------------+
854 * | SMB_SESSION_STATE_CONNECTED | | SMB_SESSION_STATE_SHUTDOWN |
855 * +-----------------------------+ +----------------------------+
858 * | +------------------------------+
859 * | | SMB_SESSION_STATE_TERMINATED |
860 * T0| +------------------------------+
861 * +--------------------+ ^
863 * +-------------------------------+ | +--------------------------------+
864 * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED |
865 * +-------------------------------+ +--------------------------------+
869 * +------------------------------+
870 * | SMB_SESSION_STATE_NEGOTIATED |
871 * +------------------------------+
903 #define SMB_SESSION_MAGIC 0x53455353 /* 'SESS' */
904 #define SMB_SESSION_VALID(p) \
905 ASSERT(((p) != NULL) && ((p)->s_magic == SMB_SESSION_MAGIC))
907 #define SMB_CHALLENGE_SZ 8
908 #define SMB3_PREAUTH_HASHVAL_SZ 64
911 SMB_SESSION_STATE_INITIALIZED
= 0,
912 SMB_SESSION_STATE_DISCONNECTED
,
913 SMB_SESSION_STATE_CONNECTED
,
914 SMB_SESSION_STATE_ESTABLISHED
,
915 SMB_SESSION_STATE_NEGOTIATED
,
916 SMB_SESSION_STATE_TERMINATED
,
917 SMB_SESSION_STATE_SHUTDOWN
,
918 SMB_SESSION_STATE_SENTINEL
919 } smb_session_state_t
;
921 /* Bits in s_flags below */
922 #define SMB_SSN_AAPL_CCEXT 1 /* Saw "AAPL" create ctx. ext. */
923 #define SMB_SSN_AAPL_READDIR 2 /* Wants MacOS ext. readdir */
925 typedef struct smb_session
{
930 smb_session_state_t s_state
;
934 int (*newrq_func
)(struct smb_request
*);
935 struct smb_server
*s_server
;
936 smb_kmod_cfg_t s_cfg
;
940 uint16_t s_local_port
;
941 uint16_t s_remote_port
;
943 smb_inaddr_t local_ipaddr
;
948 kmutex_t s_credits_mutex
;
949 uint16_t s_cur_credits
;
950 uint16_t s_max_credits
;
952 uint32_t capabilities
;
955 struct smb_sign signing
; /* SMB1 */
956 void *sign_mech
; /* mechanism info */
960 /* SMB2/SMB3 signing support */
961 int (*sign_calc
)(struct smb_request
*,
962 struct mbuf_chain
*, uint8_t *);
963 void (*sign_fini
)(struct smb_session
*);
967 smb_slist_t s_req_list
;
968 smb_llist_t s_xa_list
;
969 smb_llist_t s_user_list
;
970 smb_llist_t s_tree_list
;
971 smb_idpool_t s_uid_pool
;
972 smb_idpool_t s_tid_pool
;
975 volatile uint32_t s_tree_cnt
;
976 volatile uint32_t s_file_cnt
;
977 volatile uint32_t s_dir_cnt
;
979 uint16_t cli_secmode
;
980 uint16_t srv_secmode
;
982 uint32_t challenge_len
;
983 unsigned char challenge_key
[SMB_CHALLENGE_SZ
];
984 int64_t activity_timestamp
;
985 timeout_id_t s_auth_tmo
;
988 * Maximum negotiated buffer sizes between SMB client and server
989 * in SMB_SESSION_SETUP_ANDX
993 uint16_t smb_msg_size
;
994 uint16_t smb_max_mpx
;
995 smb_srqueue_t
*s_srqueue
;
998 uint16_t smb31_enc_cipherid
;
999 uint16_t smb31_preauth_hashid
;
1000 uint8_t smb31_preauth_hashval
[SMB3_PREAUTH_HASHVAL_SZ
];
1002 unsigned char MAC_key
[44];
1003 char ip_addr_str
[INET6_ADDRSTRLEN
];
1004 uint8_t clnt_uuid
[16];
1005 char workstation
[SMB_PI_MAX_HOST
];
1009 * The "user" object.
1011 * Note that smb_user_t object here corresponds to what MS-SMB2 calls
1012 * a "session". (Our smb_session_t is something else -- see above).
1015 #define SMB_USER_MAGIC 0x55534552 /* 'USER' */
1016 #define SMB_USER_VALID(u) \
1017 ASSERT(((u) != NULL) && ((u)->u_magic == SMB_USER_MAGIC))
1019 /* These flags are all <= 0x00000010 */
1020 #define SMB_USER_FLAG_GUEST SMB_ATF_GUEST
1021 #define SMB_USER_FLAG_ANON SMB_ATF_ANON
1022 #define SMB_USER_FLAG_ADMIN SMB_ATF_ADMIN
1023 #define SMB_USER_FLAG_POWER_USER SMB_ATF_POWERUSER
1024 #define SMB_USER_FLAG_BACKUP_OPERATOR SMB_ATF_BACKUPOP
1026 #define SMB_USER_IS_ADMIN(U) (((U)->u_flags & SMB_USER_FLAG_ADMIN) != 0)
1027 #define SMB_USER_IS_GUEST(U) (((U)->u_flags & SMB_USER_FLAG_GUEST) != 0)
1030 * Internal privilege flags derived from smb_privilege.h numbers
1031 * Would rather not include that in this file.
1033 #define SMB_USER_PRIV_SECURITY (1<<8) /* SE_SECURITY_LUID */
1034 #define SMB_USER_PRIV_TAKE_OWNERSHIP (1<<9) /* SE_TAKE_OWNERSHIP_LUID */
1035 #define SMB_USER_PRIV_BACKUP (1<<17) /* SE_BACKUP_LUID */
1036 #define SMB_USER_PRIV_RESTORE (1<<18) /* SE_RESTORE_LUID */
1037 #define SMB_USER_PRIV_CHANGE_NOTIFY (1<<23) /* SE_CHANGE_NOTIFY_LUID */
1038 #define SMB_USER_PRIV_READ_FILE (1<<25) /* SE_READ_FILE_LUID */
1039 #define SMB_USER_PRIV_WRITE_FILE (1<<26) /* SE_WRITE_FILE_LUID */
1042 * See the long "User State Machine" comment in smb_user.c
1045 SMB_USER_STATE_LOGGING_ON
= 0,
1046 SMB_USER_STATE_LOGGED_ON
,
1047 SMB_USER_STATE_LOGGING_OFF
,
1048 SMB_USER_STATE_LOGGED_OFF
,
1049 SMB_USER_STATE_SENTINEL
1053 SMB2_DH_PRESERVE_NONE
= 0,
1054 SMB2_DH_PRESERVE_SOME
,
1055 SMB2_DH_PRESERVE_ALL
1056 } smb_preserve_type_t
;
1058 typedef struct smb_user
{
1062 smb_user_state_t u_state
;
1064 struct smb_server
*u_server
;
1065 smb_session_t
*u_session
;
1066 ksocket_t u_authsock
;
1067 timeout_id_t u_auth_tmo
;
1068 uint16_t u_name_len
;
1070 uint16_t u_domain_len
;
1072 time_t u_logon_time
;
1076 uint64_t u_ssnid
; /* unique server-wide */
1079 smb_preserve_type_t preserve_opens
;
1080 uint32_t u_privileges
;
1081 uint16_t u_uid
; /* unique per-session */
1082 uint32_t u_audit_sid
;
1083 uint32_t u_owned_tree_cnt
;
1084 kcondvar_t u_owned_tree_cv
;
1086 uint32_t u_sign_flags
;
1087 struct smb_key u_sign_key
; /* SMB2 signing */
1089 struct smb_key u_enc_key
;
1090 struct smb_key u_dec_key
;
1091 volatile uint64_t u_nonce_cnt
;
1092 uint8_t u_nonce_fixed
[4];
1094 smb_cfg_val_t u_encrypt
;
1096 /* SMB 3.1.1 preauth session hashval */
1097 uint8_t u_preauth_hashval
[SMB3_PREAUTH_HASHVAL_SZ
];
1100 #define SMB_TREE_MAGIC 0x54524545 /* 'TREE' */
1101 #define SMB_TREE_VALID(p) \
1102 ASSERT((p != NULL) && ((p)->t_magic == SMB_TREE_MAGIC))
1104 #define SMB_TYPENAMELEN _ST_FSTYPSZ
1105 #define SMB_VOLNAMELEN 32
1107 #define SMB_TREE_READONLY 0x00000001
1108 #define SMB_TREE_SUPPORTS_ACLS 0x00000002
1109 #define SMB_TREE_STREAMS 0x00000004
1110 #define SMB_TREE_CASEINSENSITIVE 0x00000008
1111 #define SMB_TREE_NO_CASESENSITIVE 0x00000010
1112 #define SMB_TREE_NO_EXPORT 0x00000020
1113 #define SMB_TREE_OPLOCKS 0x00000040
1114 #define SMB_TREE_SHORTNAMES 0x00000080
1115 #define SMB_TREE_XVATTR 0x00000100
1116 #define SMB_TREE_DIRENTFLAGS 0x00000200
1117 #define SMB_TREE_ACLONCREATE 0x00000400
1118 #define SMB_TREE_ACEMASKONACCESS 0x00000800
1119 #define SMB_TREE_NFS_MOUNTED 0x00001000
1120 #define SMB_TREE_UNICODE_ON_DISK 0x00002000
1121 #define SMB_TREE_CATIA 0x00004000
1122 #define SMB_TREE_ABE 0x00008000
1123 #define SMB_TREE_QUOTA 0x00010000
1124 #define SMB_TREE_DFSROOT 0x00020000
1125 #define SMB_TREE_SPARSE 0x00040000
1126 #define SMB_TREE_TRAVERSE_MOUNTS 0x00080000
1127 #define SMB_TREE_FORCE_L2_OPLOCK 0x00100000
1128 #define SMB_TREE_CA 0x00200000
1129 /* Note: SMB_TREE_... in the mdb module too. */
1132 * See the long "Tree State Machine" comment in smb_tree.c
1135 SMB_TREE_STATE_CONNECTED
= 0,
1136 SMB_TREE_STATE_DISCONNECTING
,
1137 SMB_TREE_STATE_DISCONNECTED
,
1138 SMB_TREE_STATE_SENTINEL
1141 typedef struct smb_tree
{
1145 smb_tree_state_t t_state
;
1147 struct smb_server
*t_server
;
1148 smb_session_t
*t_session
;
1150 * user whose uid was in the tree connect message
1151 * ("owner" in MS-CIFS parlance, see section 2.2.1.6 definition of FID)
1153 smb_user_t
*t_owner
;
1154 smb_node_t
*t_snode
;
1156 smb_lavl_t t_ofile_list
;
1157 smb_idpool_t t_fid_pool
;
1159 smb_llist_t t_odir_list
;
1160 smb_idpool_t t_odid_pool
;
1167 char t_sharename
[MAXNAMELEN
];
1168 char t_resource
[MAXPATHLEN
];
1169 char t_typename
[SMB_TYPENAMELEN
];
1170 char t_volume
[SMB_VOLNAMELEN
];
1171 acl_type_t t_acltype
;
1173 uint32_t t_execflags
;
1174 time_t t_connect_time
;
1175 volatile uint32_t t_open_files
;
1176 smb_cfg_val_t t_encrypt
; /* Share.EncryptData */
1177 timestruc_t t_create_time
;
1180 #define SMB_TREE_VFS(tree) ((tree)->t_snode->vp->v_vfsp)
1181 #define SMB_TREE_FSID(tree) ((tree)->t_snode->vp->v_vfsp->vfs_fsid)
1183 #define SMB_TREE_IS_READONLY(sr) \
1184 ((sr) != NULL && (sr)->tid_tree != NULL && \
1185 !((sr)->tid_tree->t_access & ACE_ALL_WRITE_PERMS))
1187 #define SMB_TREE_IS_CASEINSENSITIVE(sr) \
1188 (((sr) && (sr)->tid_tree) ? \
1189 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CASEINSENSITIVE) : 0)
1191 #define SMB_TREE_HAS_ACCESS(sr, acemask) \
1192 ((sr) == NULL ? ACE_ALL_PERMS : ( \
1193 (((sr) && (sr)->tid_tree) ? \
1194 (((sr)->tid_tree->t_access) & (acemask)) : 0)))
1196 #define SMB_TREE_SUPPORTS_CATIA(sr) \
1197 (((sr) && (sr)->tid_tree) ? \
1198 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CATIA) : 0)
1200 #define SMB_TREE_SUPPORTS_ABE(sr) \
1201 (((sr) && (sr)->tid_tree) ? \
1202 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_ABE) : 0)
1204 #define SMB_TREE_IS_DFSROOT(sr) \
1205 (((sr) && (sr)->tid_tree) ? \
1206 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_DFSROOT) : 0)
1208 #define SMB_TREE_SUPPORTS_SHORTNAMES(sr) \
1209 (((sr) && (sr)->tid_tree) ? \
1210 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_SHORTNAMES) : 0)
1213 * SMB_TREE_CONTAINS_NODE is used to check if a node is on the same
1214 * file system as the tree's root filesystem, or if mount point traversal
1215 * should be allowed. Note that this is also called in some cases with
1216 * sr=NULL, where it is expected to evaluate to TRUE.
1219 #define SMB_TREE_CONTAINS_NODE(sr, node) \
1220 ((sr) == NULL || (sr)->tid_tree == NULL || \
1221 SMB_TREE_VFS((sr)->tid_tree) == SMB_NODE_VFS(node) || \
1222 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_TRAVERSE_MOUNTS))
1225 * SMB_PATHFILE_IS_READONLY indicates whether or not a file is
1226 * readonly when the caller has a path rather than an ofile.
1228 #define SMB_PATHFILE_IS_READONLY(sr, node) \
1229 (SMB_TREE_IS_READONLY((sr)) || \
1230 smb_node_file_is_readonly((node)))
1232 #define SMB_ODIR_MAGIC 0x4F444952 /* 'ODIR' */
1233 #define SMB_ODIR_VALID(p) \
1234 ASSERT((p != NULL) && ((p)->d_magic == SMB_ODIR_MAGIC))
1236 #define SMB_ODIR_BUFSIZE (8 * 1024)
1238 /* smb_odir_t d_flags */
1239 #define SMB_ODIR_FLAG_WILDCARDS 0x0001
1240 #define SMB_ODIR_FLAG_IGNORE_CASE 0x0002
1241 #define SMB_ODIR_FLAG_XATTR 0x0004
1242 #define SMB_ODIR_FLAG_EDIRENT 0x0008
1243 #define SMB_ODIR_FLAG_CATIA 0x0010
1244 #define SMB_ODIR_FLAG_ABE 0x0020
1245 #define SMB_ODIR_FLAG_SHORTNAMES 0x0040
1246 #define SMB_ODIR_FLAG_RESTRICTED 0x0080
1247 #define SMB_ODIR_FLAG_ACEACCESS 0x0100
1250 SMB_ODIR_STATE_OPEN
= 0,
1251 SMB_ODIR_STATE_IN_USE
,
1252 SMB_ODIR_STATE_CLOSING
,
1253 SMB_ODIR_STATE_CLOSED
,
1254 SMB_ODIR_STATE_SENTINEL
1258 SMB_ODIR_RESUME_CONT
,
1259 SMB_ODIR_RESUME_IDX
,
1260 SMB_ODIR_RESUME_COOKIE
,
1261 SMB_ODIR_RESUME_FNAME
1262 } smb_odir_resume_type_t
;
1264 typedef struct smb_odir_resume
{
1265 smb_odir_resume_type_t or_type
;
1269 } smb_odir_resume_t
;
1272 * Flags used when opening an odir
1274 #define SMB_ODIR_OPENF_BACKUP_INTENT 0x01
1276 typedef struct smb_odir
{
1280 smb_odir_state_t d_state
;
1281 smb_session_t
*d_session
;
1284 smb_node_t
*d_dnode
;
1286 uint32_t d_opened_by_pid
;
1296 struct edirent
*u_edp
;
1297 struct dirent64
*u_dp
;
1299 uint32_t d_last_cookie
;
1300 uint32_t d_cookies
[SMB_MAX_SEARCH
];
1301 char d_pattern
[MAXNAMELEN
];
1302 char d_buf
[SMB_ODIR_BUFSIZE
];
1303 char d_last_name
[MAXNAMELEN
];
1305 #define d_bufptr d_u.u_bufptr
1306 #define d_edp d_u.u_edp
1307 #define d_dp d_u.u_dp
1309 typedef struct smb_odirent
{
1310 char od_name
[MAXNAMELEN
]; /* on disk name */
1315 #define SMB_OPIPE_MAGIC 0x50495045 /* 'PIPE' */
1316 #define SMB_OPIPE_VALID(p) \
1317 ASSERT(((p) != NULL) && (p)->p_magic == SMB_OPIPE_MAGIC)
1318 #define SMB_OPIPE_MAXNAME 32
1321 * Data structure for SMB_FTYPE_MESG_PIPE ofiles, which is used
1322 * at the interface between SMB and NDR RPC.
1324 typedef struct smb_opipe
{
1328 struct smb_ofile
*p_ofile
;
1329 struct smb_server
*p_server
;
1332 /* This is the "flat" name, without path prefix */
1333 char p_name
[SMB_OPIPE_MAXNAME
];
1337 * The of_ftype of an open file should contain the SMB_FTYPE value
1338 * returned when the file/pipe was opened. The following
1339 * assumptions are currently made:
1341 * File Type Node PipeInfo
1342 * --------- -------- --------
1343 * SMB_FTYPE_DISK Valid Null
1344 * SMB_FTYPE_BYTE_PIPE Undefined Undefined
1345 * SMB_FTYPE_MESG_PIPE Null Valid
1346 * SMB_FTYPE_PRINTER Undefined Undefined
1347 * SMB_FTYPE_UNKNOWN Undefined Undefined
1351 * Some flags for ofile structure
1353 * SMB_OFLAGS_SET_DELETE_ON_CLOSE
1354 * Set this flag when the corresponding open operation whose
1355 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any
1356 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE
1357 * will be set for the file node upon close.
1360 /* SMB_OFLAGS_READONLY 0x0001 (obsolete) */
1361 #define SMB_OFLAGS_EXECONLY 0x0002
1362 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004
1363 #define SMB_OFLAGS_LLF_POS_VALID 0x0008
1365 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */
1366 #define SMB_OFILE_VALID(p) \
1367 ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC))
1370 * This is the size of the per-handle "Lock Sequence" array.
1371 * See LockSequenceIndex in [MS-SMB2] 2.2.26, and smb2_lock.c
1373 #define SMB_OFILE_LSEQ_MAX 64
1375 /* {arg_open,ofile}->dh_vers values */
1377 SMB2_NOT_DURABLE
= 0,
1384 * See the long "Ofile State Machine" comment in smb_ofile.c
1387 SMB_OFILE_STATE_ALLOC
= 0,
1388 SMB_OFILE_STATE_OPEN
,
1389 SMB_OFILE_STATE_SAVE_DH
,
1390 SMB_OFILE_STATE_SAVING
,
1391 SMB_OFILE_STATE_CLOSING
,
1392 SMB_OFILE_STATE_CLOSED
,
1393 SMB_OFILE_STATE_ORPHANED
,
1394 SMB_OFILE_STATE_RECONNECT
,
1395 SMB_OFILE_STATE_EXPIRED
,
1396 SMB_OFILE_STATE_SENTINEL
1397 } smb_ofile_state_t
;
1399 typedef struct smb_ofile
{
1400 uint16_t f_fid
; /* keep first */
1403 avl_node_t f_tree_lnd
; /* t_ofile_list */
1404 list_node_t f_node_lnd
; /* n_ofile_list */
1405 list_node_t f_dh_lnd
; /* sv_persistid_ht */
1407 smb_ofile_state_t f_state
;
1409 struct smb_server
*f_server
;
1410 smb_session_t
*f_session
;
1415 smb_opipe_t
*f_pipe
;
1419 * Note: f_persistid == 0 means this ofile has no persistid
1420 * (same interpretation at the protocol level). IFF non-zero,
1421 * this ofile is linked in the sv_persistid_ht hash table.
1423 uint64_t f_persistid
;
1426 uint64_t f_seek_pos
;
1428 uint32_t f_granted_access
;
1429 uint32_t f_share_access
;
1430 uint32_t f_create_options
;
1431 uint32_t f_opened_by_pid
;
1436 smb_attr_t f_pending_attr
;
1437 boolean_t f_written
;
1438 smb_oplock_grant_t f_oplock
;
1439 boolean_t f_oplock_closing
;
1440 uint8_t TargetOplockKey
[SMB_LEASE_KEY_SZ
];
1441 uint8_t ParentOplockKey
[SMB_LEASE_KEY_SZ
];
1442 struct smb_lease
*f_lease
;
1444 smb_notify_t f_notify
;
1446 smb_dh_vers_t dh_vers
;
1447 hrtime_t dh_timeout_offset
; /* time offset for timeout */
1448 hrtime_t dh_expire_time
; /* time the handle expires */
1449 boolean_t dh_persist
;
1451 struct nvlist
*dh_nvlist
;
1452 smb_node_t
*dh_nvfile
;
1454 uint8_t dh_create_guid
[16];
1455 char f_quota_resume
[SMB_SID_STRSZ
];
1456 uint8_t f_lock_seq
[SMB_OFILE_LSEQ_MAX
];
1459 typedef struct smb_fileinfo
{
1460 char fi_name
[MAXNAMELEN
];
1461 char fi_shortname
[SMB_SHORTNAMELEN
];
1462 uint32_t fi_cookie
; /* Dir offset (of next entry) */
1463 uint32_t fi_dosattr
; /* DOS attributes */
1464 uint64_t fi_nodeid
; /* file system node id */
1465 uint64_t fi_size
; /* file size in bytes */
1466 uint64_t fi_alloc_size
; /* allocation size in bytes */
1467 timestruc_t fi_atime
; /* last access */
1468 timestruc_t fi_mtime
; /* last modification */
1469 timestruc_t fi_ctime
; /* last status change */
1470 timestruc_t fi_crtime
; /* file creation */
1473 typedef struct smb_streaminfo
{
1475 uint64_t si_alloc_size
;
1476 char si_name
[MAXPATHLEN
];
1479 #define SMB_LOCK_MAGIC 0x4C4F434B /* 'LOCK' */
1481 typedef struct smb_lock
{
1487 smb_ofile_t
*l_file
;
1489 struct smb_lock
*l_blocked_by
; /* Debug info only */
1491 uint32_t l_conflicts
;
1500 #define SMB_LOCK_FLAG_INDEFINITE 0x0004
1501 #define SMB_LOCK_FLAG_CLOSED 0x0008
1502 #define SMB_LOCK_FLAG_CANCELLED 0x0010
1504 #define SMB_LOCK_TYPE_READWRITE 101
1505 #define SMB_LOCK_TYPE_READONLY 102
1507 typedef struct vardata_block
{
1511 struct iovec vdb_iovec
[MAX_IOVEC
];
1514 #define SMB_WRMODE_WRITE_THRU 0x0001
1515 #define SMB_WRMODE_IS_STABLE(M) ((M) & SMB_WRMODE_WRITE_THRU)
1517 #define SMB_RW_MAGIC 0x52445257 /* 'RDRW' */
1519 typedef struct smb_rw_param
{
1523 uint32_t rw_last_write
;
1525 uint32_t rw_count
; /* bytes in this request */
1527 uint32_t rw_total
; /* total bytes (write-raw) */
1528 uint16_t rw_dsoff
; /* SMB data offset */
1529 uint8_t rw_andx
; /* SMB secondary andx command */
1532 typedef struct smb_pathname
{
1543 typedef struct smb_fqi
{
1544 smb_pathname_t fq_path
;
1546 smb_node_t
*fq_dnode
;
1547 smb_node_t
*fq_fnode
;
1548 smb_attr_t fq_fattr
;
1549 char fq_last_comp
[MAXNAMELEN
];
1552 typedef struct dirop
{
1555 uint16_t info_level
;
1559 typedef struct smb_queryinfo
{
1560 smb_node_t
*qi_node
; /* NULL for pipes */
1561 uint8_t qi_InfoType
;
1562 uint8_t qi_InfoClass
;
1563 uint8_t qi_delete_on_close
;
1565 uint32_t qi_AddlInfo
;
1567 mbuf_chain_t in_data
;
1569 uint32_t qi_namelen
;
1570 char qi_shortname
[SMB_SHORTNAMELEN
];
1571 char qi_name
[MAXPATHLEN
];
1574 typedef struct smb_setinfo
{
1575 smb_node_t
*si_node
;
1576 mbuf_chain_t si_data
;
1582 * volume_units and volume avail are the total allocated and
1583 * available units on the volume.
1584 * caller_units and caller_avail are the allocated and available
1585 * units on the volume for the user associated with the calling
1588 typedef struct smb_fssize
{
1589 uint64_t fs_volume_units
;
1590 uint64_t fs_volume_avail
;
1591 uint64_t fs_caller_units
;
1592 uint64_t fs_caller_avail
;
1593 uint32_t fs_sectors_per_unit
;
1594 uint32_t fs_bytes_per_sector
;
1598 * SMB FsCtl operations (SMB2 Ioctl, and some SMB1 trans calls)
1602 uint32_t InputCount
;
1603 uint32_t OutputCount
;
1604 uint32_t MaxOutputResp
;
1605 mbuf_chain_t
*in_mbc
;
1606 mbuf_chain_t
*out_mbc
;
1610 uint64_t persistent
;
1620 typedef struct open_param
{
1629 timestruc_t timewarp
;
1631 * Careful: dsize is the desired (allocation) size before the
1632 * common open function, and the actual size afterwards.
1634 uint64_t dsize
; /* alloc size, actual size */
1635 uint32_t desired_access
;
1636 uint32_t maximum_access
;
1637 uint32_t share_access
;
1638 uint32_t create_options
;
1639 uint32_t create_disposition
;
1640 boolean_t create_timewarp
;
1641 boolean_t created_readonly
;
1644 uint32_t action_taken
;
1646 uint32_t rootdirfid
;
1649 smb_opipe_t
*pipe
; /* for smb_opipe_open */
1650 struct smb_sd
*sd
; /* for NTTransactCreate */
1653 uint8_t op_oplock_level
; /* requested/granted level */
1654 uint32_t op_oplock_state
; /* internal type+level */
1655 uint32_t lease_state
; /* SMB2_LEASE_... */
1656 uint32_t lease_flags
;
1657 uint16_t lease_epoch
;
1658 uint16_t lease_version
; /* 1 or 2 */
1659 uint8_t lease_key
[SMB_LEASE_KEY_SZ
]; /* from client */
1660 uint8_t parent_lease_key
[SMB_LEASE_KEY_SZ
]; /* for V2 */
1662 smb_dh_vers_t dh_vers
;
1663 smb2fid_t dh_fileid
; /* for durable reconnect */
1664 uint8_t create_guid
[16];
1665 uint32_t dh_v2_flags
;
1666 uint32_t dh_timeout
;
1669 typedef struct smb_arg_lock
{
1675 typedef struct smb_arg_olbrk
{
1678 boolean_t AckRequired
;
1679 uint8_t LeaseKey
[SMB_LEASE_KEY_SZ
];
1683 * SMB Request State Machine
1684 * -------------------------
1687 * +--------------------------->| FREE |---------------------------+
1693 * | T15 +-----------+ v
1694 * +------------+ T6 | | +--------------+
1695 * | CLEANED_UP |<-----------------| CANCELLED | | INITIALIZING |
1696 * +------------+ | | +--------------+
1697 * | ^ +-----------+ |
1699 * | | +-------------+ | | | |
1700 * | | T3 | | | | T13 | T1
1701 * | +-------------------------+ | | +----------------------+ |
1702 * +----------------------------+ | | | | |
1703 * T16 | | | | +-----------+ | |
1705 * +-----------------+ | T12 +--------+ | T2 +-----------+
1706 * | EVENT_OCCURRED |------------->| ACTIVE |<--------------------| SUBMITTED |
1707 * +-----------------+ | +--------+ | +-----------+
1710 * | T10 T9 | +----------+ | +-------+ | T11
1711 * | | | +-------+ | |
1714 * +----------------------+ +--------------+
1715 * | WAITING_EVENT | | WAITING_LOCK |
1716 * +----------------------+ +--------------+
1724 * This transition occurs when the request is allocated and is still under the
1725 * control of the session thread.
1729 * This transition occurs when the session thread dispatches a task to treat the
1738 * A request completes and smbsr_cleanup is called to release resources
1739 * associated with the request (but not the smb_request_t itself). This
1740 * includes references on smb_ofile_t, smb_node_t, and other structures.
1741 * CLEANED_UP state exists to detect if we attempt to cleanup a request
1742 * multiple times and to allow us to detect that we are accessing a
1743 * request that has already been cleaned up.
1791 * Request processing is completed (control returns from smb_dispatch)
1795 * Multipart (andx) request was cleaned up with smbsr_cleanup but more "andx"
1796 * sections remain to be processed.
1800 #define SMB_REQ_MAGIC 0x534D4252 /* 'SMBR' */
1801 #define SMB_REQ_VALID(p) ASSERT((p)->sr_magic == SMB_REQ_MAGIC)
1803 typedef enum smb_req_state
{
1804 SMB_REQ_STATE_FREE
= 0,
1805 SMB_REQ_STATE_INITIALIZING
,
1806 SMB_REQ_STATE_SUBMITTED
,
1807 SMB_REQ_STATE_ACTIVE
,
1808 SMB_REQ_STATE_WAITING_AUTH
,
1809 SMB_REQ_STATE_WAITING_FCN1
,
1810 SMB_REQ_STATE_WAITING_FCN2
,
1811 SMB_REQ_STATE_WAITING_LOCK
,
1812 SMB_REQ_STATE_WAITING_PIPE
,
1813 SMB_REQ_STATE_WAITING_OLBRK
,
1814 SMB_REQ_STATE_COMPLETED
,
1815 SMB_REQ_STATE_CANCEL_PENDING
,
1816 SMB_REQ_STATE_CANCELLED
,
1817 SMB_REQ_STATE_CLEANED_UP
,
1818 SMB_REQ_STATE_SENTINEL
1821 typedef struct smb_request
{
1822 list_node_t sr_session_lnd
;
1825 smb_req_state_t sr_state
;
1826 kcondvar_t sr_st_cv
;
1827 struct smb_server
*sr_server
;
1830 smb_session_t
*session
;
1831 smb_kmod_cfg_t
*sr_cfg
;
1832 void (*cancel_method
)(struct smb_request
*);
1835 /* Queue used by smb_request_append_postwork. */
1836 struct smb_request
*sr_postwork
;
1838 list_node_t sr_waiters
; /* smb_notify.c */
1840 struct mbuf_chain command
;
1841 struct mbuf_chain reply
;
1842 struct mbuf_chain raw_data
;
1844 struct smb_xa
*r_xa
;
1846 int cur_reply_offset
;
1847 int orig_request_hdr
;
1848 unsigned int reply_seqnum
; /* reply sequence number */
1849 unsigned char first_smb_com
; /* command code */
1850 unsigned char smb_com
; /* command code */
1852 uint8_t smb_rcls
; /* error code class */
1853 uint8_t smb_reh
; /* rsvd (AH DOS INT-24 ERR) */
1854 uint16_t smb_err
; /* error code */
1855 smb_error_t smb_error
;
1857 uint8_t smb_flg
; /* flags */
1858 uint16_t smb_flg2
; /* flags */
1859 unsigned char smb_sig
[8]; /* signiture */
1860 uint16_t smb_tid
; /* tree id # */
1861 uint32_t smb_pid
; /* caller's process id # */
1862 uint16_t smb_uid
; /* local (smb1) user id # */
1863 uint16_t smb_mid
; /* mutiplex id # */
1864 unsigned char smb_wct
; /* count of parameter words */
1865 uint16_t smb_bcc
; /* data byte count */
1868 * Beginning offsets (in the mbuf chain) for the
1869 * command and reply headers, and the next reply.
1871 uint32_t smb2_cmd_hdr
;
1872 uint32_t smb2_reply_hdr
;
1873 uint32_t smb2_next_reply
;
1876 * SMB2 header fields. [MS-SMB2 2.2.1.2]
1877 * XXX: Later do a union w smb1 members
1879 uint16_t smb2_credit_charge
;
1880 uint16_t smb2_chan_seq
; /* cmd only */
1881 uint32_t smb2_status
;
1882 uint16_t smb2_cmd_code
;
1883 uint16_t smb2_credit_request
;
1884 uint16_t smb2_credit_response
;
1885 uint16_t smb2_total_credits
; /* in compound */
1886 uint32_t smb2_hdr_flags
;
1887 uint32_t smb2_next_command
;
1888 uint64_t smb2_messageid
;
1889 uint64_t smb2_first_msgid
;
1890 /* uint32_t smb2_pid; use smb_pid */
1891 /* uint32_t smb2_tid; use smb_tid */
1892 uint64_t smb2_ssnid
; /* See u_ssnid */
1893 uint8_t smb2_sig
[16]; /* signature */
1896 * SMB3 transform header fields. [MS-SMB2 2.2.41]
1899 smb_user_t
*th_sid_user
;
1901 uint8_t th_nonce
[16];
1903 boolean_t encrypted
;
1904 boolean_t dh_nvl_dirty
;
1906 boolean_t smb2_async
;
1907 uint64_t smb2_async_id
;
1909 struct mbuf_chain smb_vwv
; /* variable width value */
1912 struct mbuf_chain smb_data
;
1914 uint16_t smb_fid
; /* not in hdr, but common */
1916 unsigned char andx_com
;
1919 struct smb_tree
*tid_tree
;
1920 struct smb_ofile
*fid_ofile
;
1921 smb_user_t
*uid_user
;
1924 kthread_t
*sr_worker
;
1925 hrtime_t sr_time_submitted
;
1926 hrtime_t sr_time_active
;
1927 hrtime_t sr_time_start
;
1932 smb_arg_negotiate_t
*negprot
;
1933 smb_arg_sessionsetup_t
*ssetup
;
1934 smb_arg_tcon_t tcon
;
1935 smb_arg_dirop_t dirop
;
1936 smb_arg_open_t open
;
1937 smb_arg_lock_t lock
;
1938 smb_arg_olbrk_t olbrk
; /* for async oplock break */
1945 #define sr_ssetup arg.ssetup
1946 #define sr_negprot arg.negprot
1947 #define sr_tcon arg.tcon
1948 #define sr_dirop arg.dirop
1949 #define sr_open arg.open
1950 #define sr_rw arg.rw
1951 #define sr_timestamp arg.timestamp
1953 #define SMB_READ_PROTOCOL(hdr) \
1954 LE_IN32(((smb_hdr_t *)(hdr))->protocol)
1956 #define SMB_PROTOCOL_MAGIC_INVALID(rd_sr) \
1957 (SMB_READ_PROTOCOL((rd_sr)->sr_request_buf) != SMB_PROTOCOL_MAGIC)
1959 #define SMB_READ_COMMAND(hdr) \
1960 (((smb_hdr_t *)(hdr))->command)
1962 #define SMB_IS_NT_CANCEL(rd_sr) \
1963 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NT_CANCEL)
1965 #define SMB_IS_SESSION_SETUP_ANDX(rd_sr) \
1966 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == \
1967 SMB_COM_SESSION_SETUP_ANDX)
1969 #define SMB_IS_NT_NEGOTIATE(rd_sr) \
1970 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NEGOTIATE)
1972 #define SMB_IS_TREE_CONNECT_ANDX(rd_sr) \
1973 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_TREE_CONNECT_ANDX)
1975 #define SMB_XA_FLAG_OPEN 0x0001
1976 #define SMB_XA_FLAG_CLOSE 0x0002
1977 #define SMB_XA_FLAG_COMPLETE 0x0004
1978 #define SMB_XA_CLOSED(xa) (!((xa)->xa_flags & SMB_XA_FLAG_OPEN))
1980 #define SMB_XA_MAGIC 0x534D4258 /* 'SMBX' */
1982 typedef struct smb_xa
{
1990 struct smb_session
*xa_session
;
1992 unsigned char smb_com
; /* which TRANS type */
1993 unsigned char smb_flg
; /* flags */
1994 uint16_t smb_flg2
; /* flags */
1995 uint16_t smb_tid
; /* tree id number */
1996 uint32_t smb_pid
; /* caller's process id */
1997 uint16_t smb_uid
; /* user id number */
1998 uint32_t smb_func
; /* NT_TRANS function */
2000 uint16_t xa_smb_mid
; /* mutiplex id number */
2001 uint16_t xa_smb_fid
; /* TRANS2 secondary */
2003 unsigned int reply_seqnum
; /* reply sequence number */
2005 uint32_t smb_tpscnt
; /* total parameter bytes being sent */
2006 uint32_t smb_tdscnt
; /* total data bytes being sent */
2007 uint32_t smb_mprcnt
; /* max parameter bytes to return */
2008 uint32_t smb_mdrcnt
; /* max data bytes to return */
2009 uint32_t smb_msrcnt
; /* max setup words to return */
2010 uint32_t smb_flags
; /* additional information: */
2011 /* bit 0 - if set, disconnect TID in smb_tid */
2012 /* bit 1 - if set, transaction is one way */
2013 /* (no final response) */
2014 int32_t smb_timeout
; /* number of milliseconds to await completion */
2015 uint32_t smb_suwcnt
; /* set up word count */
2020 * These are the param and data count received so far,
2021 * used to decide if the whole trans is here yet.
2026 struct mbuf_chain req_setup_mb
;
2027 struct mbuf_chain req_param_mb
;
2028 struct mbuf_chain req_data_mb
;
2030 struct mbuf_chain rep_setup_mb
;
2031 struct mbuf_chain rep_param_mb
;
2032 struct mbuf_chain rep_data_mb
;
2036 #define SDDF_NO_FLAGS 0
2037 #define SDDF_SUPPRESS_TID 0x0001
2038 #define SDDF_SUPPRESS_UID 0x0002
2041 * SMB dispatch return codes.
2049 SDRC_NOT_IMPLEMENTED
2052 #define VAR_BCC ((short)-1)
2054 #define SMB_SERVER_MAGIC 0x53534552 /* 'SSER' */
2055 #define SMB_SERVER_VALID(s) \
2056 ASSERT(((s) != NULL) && ((s)->sv_magic == SMB_SERVER_MAGIC))
2058 #define SMB_LISTENER_MAGIC 0x4C53544E /* 'LSTN' */
2059 #define SMB_LISTENER_VALID(ld) \
2060 ASSERT(((ld) != NULL) && ((ld)->ld_magic == SMB_LISTENER_MAGIC))
2064 struct smb_server
*ld_sv
;
2065 smb_thread_t ld_thread
;
2069 struct sockaddr_in ld_sin
;
2070 struct sockaddr_in6 ld_sin6
;
2072 } smb_listener_daemon_t
;
2074 #define SMB_SSETUP_CMD "authentication"
2075 #define SMB_TCON_CMD "share mapping"
2076 #define SMB_OPIPE_CMD "pipe open"
2077 #define SMB_LOGOFF_CMD "logoff"
2078 #define SMB_THRESHOLD_REPORT_THROTTLE 50
2079 typedef struct smb_cmd_threshold
{
2082 volatile uint32_t ct_active_cnt
;
2083 volatile uint32_t ct_blocked_cnt
;
2084 uint32_t ct_threshold
;
2085 uint32_t ct_timeout
; /* milliseconds */
2087 } smb_cmd_threshold_t
;
2090 kstat_named_t ls_files
;
2091 kstat_named_t ls_trees
;
2092 kstat_named_t ls_users
;
2093 } smb_server_legacy_kstat_t
;
2095 typedef enum smb_server_state
{
2096 SMB_SERVER_STATE_CREATED
= 0,
2097 SMB_SERVER_STATE_CONFIGURED
,
2098 SMB_SERVER_STATE_RUNNING
,
2099 SMB_SERVER_STATE_STOPPING
,
2100 SMB_SERVER_STATE_DELETING
,
2101 SMB_SERVER_STATE_SENTINEL
2102 } smb_server_state_t
;
2105 /* protected by sv_mutex */
2108 smb_llist_t sp_list
;
2109 smb_llist_t sp_fidlist
;
2112 #define SMB_SERVER_STATE_VALID(S) \
2113 ASSERT(((S) == SMB_SERVER_STATE_CREATED) || \
2114 ((S) == SMB_SERVER_STATE_CONFIGURED) || \
2115 ((S) == SMB_SERVER_STATE_RUNNING) || \
2116 ((S) == SMB_SERVER_STATE_STOPPING) || \
2117 ((S) == SMB_SERVER_STATE_DELETING))
2119 typedef struct smb_server
{
2124 smb_server_state_t sv_state
;
2129 smb_listener_daemon_t sv_nbt_daemon
;
2130 smb_listener_daemon_t sv_tcp_daemon
;
2131 krwlock_t sv_cfg_lock
;
2132 smb_kmod_cfg_t sv_cfg
;
2134 kmutex_t sv_proc_lock
;
2135 kcondvar_t sv_proc_cv
;
2136 smb_thread_state_t sv_proc_state
;
2137 uint64_t sv_proc_did
;
2138 struct proc
*sv_proc_p
;
2140 smb_session_t
*sv_session
;
2141 smb_user_t
*sv_rootuser
;
2142 smb_llist_t sv_session_list
;
2143 smb_hash_t
*sv_persistid_ht
;
2144 smb_hash_t
*sv_lease_ht
;
2146 smb_export_t sv_export
;
2147 struct __door_handle
*sv_lmshrd
;
2149 /* Internal door for up-calls to smbd */
2150 struct __door_handle
*sv_kdoor_hd
;
2151 int sv_kdoor_id
; /* init -1 */
2152 uint64_t sv_kdoor_ncall
;
2153 kmutex_t sv_kdoor_mutex
;
2154 kcondvar_t sv_kdoor_cv
;
2158 smb_thread_t si_thread_timers
;
2160 taskq_t
*sv_notify_pool
;
2161 taskq_t
*sv_worker_pool
;
2162 taskq_t
*sv_receiver_pool
;
2164 smb_node_t
*si_root_smb_node
;
2165 smb_llist_t sv_opipe_list
;
2166 smb_llist_t sv_event_list
;
2169 hrtime_t sv_start_time
;
2171 volatile uint32_t sv_nbt_sess
;
2172 volatile uint32_t sv_tcp_sess
;
2173 volatile uint32_t sv_users
;
2174 volatile uint32_t sv_trees
;
2175 volatile uint32_t sv_files
;
2176 volatile uint32_t sv_pipes
;
2177 volatile uint64_t sv_txb
;
2178 volatile uint64_t sv_rxb
;
2179 volatile uint64_t sv_nreq
;
2180 smb_srqueue_t sv_srqueue
;
2181 smb_spool_t sp_info
;
2182 smb_cmd_threshold_t sv_ssetup_ct
;
2183 smb_cmd_threshold_t sv_tcon_ct
;
2184 smb_cmd_threshold_t sv_opipe_ct
;
2185 smb_cmd_threshold_t sv_logoff_ct
;
2186 kstat_t
*sv_legacy_ksp
;
2187 kmutex_t sv_legacy_ksmtx
;
2188 smb_disp_stats_t
*sv_disp_stats1
;
2189 smb_disp_stats_t
*sv_disp_stats2
;
2192 #define SMB_EVENT_MAGIC 0x45564E54 /* EVNT */
2193 #define SMB_EVENT_TIMEOUT 45 /* seconds */
2194 #define SMB_EVENT_VALID(e) \
2195 ASSERT(((e) != NULL) && ((e)->se_magic == SMB_EVENT_MAGIC))
2196 typedef struct smb_event
{
2201 smb_server_t
*se_server
;
2203 boolean_t se_notified
;
2209 typedef struct smb_kspooldoc
{
2212 smb_inaddr_t sd_ipaddr
;
2213 uint32_t sd_spool_num
;
2215 char sd_username
[MAXNAMELEN
];
2216 char sd_path
[MAXPATHLEN
];
2219 typedef struct smb_spoolfid
{
2225 #define SMB_INFO_NETBIOS_SESSION_SVC_RUNNING 0x0001
2226 #define SMB_INFO_NETBIOS_SESSION_SVC_FAILED 0x0002
2227 #define SMB_INFO_USER_LEVEL_SECURITY 0x40000000
2228 #define SMB_INFO_ENCRYPT_PASSWORDS 0x80000000
2230 #define SMB_IS_STREAM(node) ((node)->n_unode)
2232 typedef struct smb_tsd
{
2238 typedef struct smb_disp_entry
{
2239 char sdt_name
[KSTAT_STRLEN
];
2240 smb_sdrc_t (*sdt_pre_op
)(smb_request_t
*);
2241 smb_sdrc_t (*sdt_function
)(smb_request_t
*);
2242 void (*sdt_post_op
)(smb_request_t
*);
2248 typedef struct smb_xlate
{
2254 * This structure is a helper for building RAP NetShareEnum response
2256 * es_posix_uid UID of the user requesting the shares list which
2257 * is used to detect if the user has any autohome
2258 * es_bufsize size of the response buffer
2259 * es_buf pointer to the response buffer
2260 * es_ntotal total number of shares exported by server which
2261 * their OEM names is less then 13 chars
2262 * es_nsent number of shares that can fit in the specified buffer
2263 * es_datasize actual data size (share's data) which was encoded
2264 * in the response buffer
2266 typedef struct smb_enumshare_info
{
2268 uint16_t es_bufsize
;
2272 uint16_t es_datasize
;
2273 } smb_enumshare_info_t
;
2276 * SMB 3.1.1 error id for error ctxs
2278 enum smb2_error_id
{
2279 SMB2_ERROR_ID_DEFAULT
= 0,
2280 SMB2_ERROR_ID_SHARE_REDIRECT
= 0x72645253 /* not used */
2287 #endif /* _SMBSRV_SMB_KTYPES_H */