Print this page
12513 SMB 3.1.1 support for server
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/smbsrv/smb_ktypes.h
+++ new/usr/src/uts/common/smbsrv/smb_ktypes.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
24 + * Copyright 2020 RackTop Systems, Inc.
24 25 */
25 26
26 27 /*
27 28 * Structures and type definitions for the SMB module.
28 29 */
29 30
30 31 #ifndef _SMBSRV_SMB_KTYPES_H
31 32 #define _SMBSRV_SMB_KTYPES_H
32 33
33 34 #ifdef __cplusplus
34 35 extern "C" {
35 36 #endif
36 37
37 38 #include <sys/note.h>
38 39 #include <sys/systm.h>
39 40 #include <sys/param.h>
40 41 #include <sys/types.h>
41 42 #include <sys/synch.h>
42 43 #include <sys/taskq.h>
43 44 #include <sys/socket.h>
44 45 #include <sys/acl.h>
45 46 #include <sys/sdt.h>
46 47 #include <sys/stat.h>
47 48 #include <sys/vnode.h>
48 49 #include <sys/cred.h>
49 50 #include <netinet/in.h>
50 51 #include <sys/ksocket.h>
51 52 #include <sys/fem.h>
52 53 #include <smbsrv/smb.h>
53 54 #include <smbsrv/smb2.h>
54 55 #include <smbsrv/smbinfo.h>
55 56 #include <smbsrv/mbuf.h>
56 57 #include <smbsrv/smb_sid.h>
57 58 #include <smbsrv/smb_xdr.h>
58 59 #include <smbsrv/netbios.h>
59 60 #include <smbsrv/smb_vops.h>
60 61 #include <smbsrv/smb_kstat.h>
61 62
62 63 struct __door_handle; /* <sys/door.h> */
63 64 struct edirent; /* <sys/extdirent.h> */
64 65 struct nvlist;
65 66
66 67 struct smb_disp_entry;
67 68 struct smb_request;
68 69 struct smb_server;
69 70 struct smb_event;
70 71 struct smb_export;
71 72
72 73 /*
73 74 * Accumulated time and queue length statistics.
74 75 *
75 76 * Accumulated time statistics are kept as a running sum of "active" time.
76 77 * Queue length statistics are kept as a running sum of the product of queue
77 78 * length and elapsed time at that length -- i.e., a Riemann sum for queue
78 79 * length integrated against time. (You can also think of the active time as a
79 80 * Riemann sum, for the boolean function (queue_length > 0) integrated against
80 81 * time, or you can think of it as the Lebesgue measure of the set on which
81 82 * queue_length > 0.)
82 83 *
83 84 * ^
84 85 * | _________
85 86 * 8 | i4 |
86 87 * | | |
87 88 * Queue 6 | |
88 89 * Length | _________ | |
89 90 * 4 | i2 |_______| |
90 91 * | | i3 |
91 92 * 2_______| |
92 93 * | i1 |
93 94 * |_______________________________|
94 95 * Time-> t1 t2 t3 t4
95 96 *
96 97 * At each change of state (entry or exit from the queue), we add the elapsed
97 98 * time (since the previous state change) to the active time if the queue length
98 99 * was non-zero during that interval; and we add the product of the elapsed time
99 100 * times the queue length to the running length*time sum.
100 101 *
101 102 * This method is generalizable to measuring residency in any defined system:
102 103 * instead of queue lengths, think of "outstanding RPC calls to server X".
103 104 *
104 105 * A large number of I/O subsystems have at least two basic "lists" of
105 106 * transactions they manage: one for transactions that have been accepted for
106 107 * processing but for which processing has yet to begin, and one for
107 108 * transactions which are actively being processed (but not done). For this
108 109 * reason, two cumulative time statistics are defined here: wait (pre-service)
109 110 * time, and run (service) time.
110 111 *
111 112 * All times are 64-bit nanoseconds (hrtime_t), as returned by gethrtime().
112 113 *
113 114 * The units of cumulative busy time are accumulated nanoseconds. The units of
114 115 * cumulative length*time products are elapsed time times queue length.
115 116 *
116 117 * Updates to the fields below are performed implicitly by calls to
117 118 * these functions:
118 119 *
119 120 * smb_srqueue_init()
120 121 * smb_srqueue_destroy()
121 122 * smb_srqueue_waitq_enter()
122 123 * smb_srqueue_runq_exit()
123 124 * smb_srqueue_waitq_to_runq()
124 125 * smb_srqueue_update()
125 126 *
126 127 * These fields should never be updated by any other means.
127 128 */
128 129 typedef struct smb_srqueue {
129 130 kmutex_t srq_mutex;
130 131 hrtime_t srq_wlastupdate;
131 132 hrtime_t srq_wtime;
132 133 hrtime_t srq_wlentime;
133 134 hrtime_t srq_rlastupdate;
134 135 hrtime_t srq_rtime;
135 136 hrtime_t srq_rlentime;
136 137 uint32_t srq_wcnt;
137 138 uint32_t srq_rcnt;
138 139 } smb_srqueue_t;
139 140
140 141 /*
141 142 * The fields with the prefix 'ly_a' contain the statistics collected since the
142 143 * server was last started ('a' for 'aggregated'). The fields with the prefix
143 144 * 'ly_d' contain the statistics collected since the last snapshot ('d' for
144 145 * 'delta').
145 146 */
146 147 typedef struct smb_latency {
147 148 kmutex_t ly_mutex;
148 149 uint64_t ly_a_nreq;
149 150 hrtime_t ly_a_sum;
150 151 hrtime_t ly_a_mean;
151 152 hrtime_t ly_a_stddev;
152 153 uint64_t ly_d_nreq;
153 154 hrtime_t ly_d_sum;
154 155 hrtime_t ly_d_mean;
155 156 hrtime_t ly_d_stddev;
156 157 } smb_latency_t;
157 158
158 159 typedef struct smb_disp_stats {
159 160 volatile uint64_t sdt_txb;
160 161 volatile uint64_t sdt_rxb;
161 162 smb_latency_t sdt_lat;
162 163 } smb_disp_stats_t;
163 164
164 165 int smb_noop(void *, size_t, int);
165 166
166 167 #define SMB_AUDIT_STACK_DEPTH 16
167 168 #define SMB_AUDIT_BUF_MAX_REC 16
168 169 #define SMB_AUDIT_NODE 0x00000001
169 170
170 171 /*
171 172 * Maximum number of records returned in SMBsearch, SMBfind
172 173 * and SMBfindunique response. Value set to 10 for compatibility
173 174 * with Windows.
174 175 */
175 176 #define SMB_MAX_SEARCH 10
176 177
177 178 #define SMB_SEARCH_ATTRIBUTES \
178 179 (FILE_ATTRIBUTE_HIDDEN | \
179 180 FILE_ATTRIBUTE_SYSTEM | \
180 181 FILE_ATTRIBUTE_DIRECTORY)
181 182
182 183 #define SMB_SEARCH_HIDDEN(sattr) ((sattr) & FILE_ATTRIBUTE_HIDDEN)
183 184 #define SMB_SEARCH_SYSTEM(sattr) ((sattr) & FILE_ATTRIBUTE_SYSTEM)
184 185 #define SMB_SEARCH_DIRECTORY(sattr) ((sattr) & FILE_ATTRIBUTE_DIRECTORY)
185 186 #define SMB_SEARCH_ALL(sattr) ((sattr) & SMB_SEARCH_ATTRIBUTES)
186 187
187 188 typedef struct {
188 189 uint32_t anr_refcnt;
189 190 int anr_depth;
190 191 pc_t anr_stack[SMB_AUDIT_STACK_DEPTH];
191 192 } smb_audit_record_node_t;
192 193
193 194 typedef struct {
194 195 int anb_index;
195 196 int anb_max_index;
196 197 smb_audit_record_node_t anb_records[SMB_AUDIT_BUF_MAX_REC];
197 198 } smb_audit_buf_node_t;
198 199
199 200 /*
200 201 * Thread State Machine
201 202 * --------------------
202 203 *
203 204 * T5 T0
204 205 * smb_thread_destroy() <-------+ +------- smb_thread_init()
205 206 * | |
206 207 * | v
207 208 * +-----------------------------+
208 209 * | SMB_THREAD_STATE_EXITED |<---+
209 210 * +-----------------------------+ |
210 211 * | T1 |
211 212 * v |
212 213 * +-----------------------------+ |
213 214 * | SMB_THREAD_STATE_STARTING | |
214 215 * +-----------------------------+ |
215 216 * | T2 | T4
216 217 * v |
217 218 * +-----------------------------+ |
218 219 * | SMB_THREAD_STATE_RUNNING | |
219 220 * +-----------------------------+ |
220 221 * | T3 |
221 222 * v |
222 223 * +-----------------------------+ |
223 224 * | SMB_THREAD_STATE_EXITING |----+
224 225 * +-----------------------------+
225 226 *
226 227 * Transition T0
227 228 *
228 229 * This transition is executed in smb_thread_init().
229 230 *
230 231 * Transition T1
231 232 *
232 233 * This transition is executed in smb_thread_start().
233 234 *
234 235 * Transition T2
235 236 *
236 237 * This transition is executed by the thread itself when it starts running.
237 238 *
238 239 * Transition T3
239 240 *
240 241 * This transition is executed by the thread itself in
241 242 * smb_thread_entry_point() just before calling thread_exit().
242 243 *
243 244 *
244 245 * Transition T4
245 246 *
246 247 * This transition is executed in smb_thread_stop().
247 248 *
248 249 * Transition T5
249 250 *
250 251 * This transition is executed in smb_thread_destroy().
251 252 */
252 253 typedef enum smb_thread_state {
253 254 SMB_THREAD_STATE_STARTING = 0,
254 255 SMB_THREAD_STATE_RUNNING,
255 256 SMB_THREAD_STATE_EXITING,
256 257 SMB_THREAD_STATE_EXITED,
257 258 SMB_THREAD_STATE_FAILED
258 259 } smb_thread_state_t;
259 260
260 261 struct _smb_thread;
261 262
262 263 typedef void (*smb_thread_ep_t)(struct _smb_thread *, void *ep_arg);
263 264
264 265 #define SMB_THREAD_MAGIC 0x534D4254 /* SMBT */
265 266
266 267 typedef struct _smb_thread {
267 268 uint32_t sth_magic;
268 269 char sth_name[32];
269 270 smb_thread_state_t sth_state;
270 271 kthread_t *sth_th;
271 272 kt_did_t sth_did;
272 273 smb_thread_ep_t sth_ep;
273 274 void *sth_ep_arg;
274 275 pri_t sth_pri;
275 276 boolean_t sth_kill;
276 277 kmutex_t sth_mtx;
277 278 kcondvar_t sth_cv;
278 279 } smb_thread_t;
279 280
280 281 /*
281 282 * Pool of IDs
282 283 * -----------
283 284 *
284 285 * A pool of IDs is a pool of 16 bit numbers. It is implemented as a bitmap.
285 286 * A bit set to '1' indicates that that particular value has been allocated.
286 287 * The allocation process is done shifting a bit through the whole bitmap.
287 288 * The current position of that index bit is kept in the smb_idpool_t
288 289 * structure and represented by a byte index (0 to buffer size minus 1) and
289 290 * a bit index (0 to 7).
290 291 *
291 292 * The pools start with a size of 8 bytes or 64 IDs. Each time the pool runs
292 293 * out of IDs its current size is doubled until it reaches its maximum size
293 294 * (8192 bytes or 65536 IDs). The IDs 0 and 65535 are never given out which
294 295 * means that a pool can have a maximum number of 65534 IDs available.
295 296 */
296 297 #define SMB_IDPOOL_MAGIC 0x4944504C /* IDPL */
297 298 #define SMB_IDPOOL_MIN_SIZE 64 /* Number of IDs to begin with */
298 299 #define SMB_IDPOOL_MAX_SIZE 64 * 1024
299 300
300 301 typedef struct smb_idpool {
301 302 uint32_t id_magic;
302 303 kmutex_t id_mutex;
303 304 uint8_t *id_pool;
304 305 uint32_t id_size;
305 306 uint32_t id_maxsize;
306 307 uint8_t id_bit;
307 308 uint8_t id_bit_idx;
308 309 uint32_t id_idx;
309 310 uint32_t id_idx_msk;
310 311 uint32_t id_free_counter;
311 312 uint32_t id_max_free_counter;
312 313 } smb_idpool_t;
313 314
314 315 /*
315 316 * Maximum size of a Transport Data Unit when CAP_LARGE_READX and
316 317 * CAP_LARGE_WRITEX are not set. CAP_LARGE_READX/CAP_LARGE_WRITEX
317 318 * allow the payload to exceed the negotiated buffer size.
318 319 * 4 --> NBT/TCP Transport Header.
319 320 * 32 --> SMB Header
320 321 * 1 --> Word Count byte
321 322 * 510 --> Maximum Number of bytes of the Word Table (2 * 255)
322 323 * 2 --> Byte count of the data
323 324 * 65535 --> Maximum size of the data
324 325 * -----
325 326 * 66084
326 327 */
327 328 #define SMB_REQ_MAX_SIZE 66560 /* 65KB */
328 329 #define SMB_XPRT_MAX_SIZE (SMB_REQ_MAX_SIZE + NETBIOS_HDR_SZ)
329 330
330 331 #define SMB_TXREQ_MAGIC 0X54524251 /* 'TREQ' */
331 332 typedef struct {
332 333 list_node_t tr_lnd;
333 334 uint32_t tr_magic;
334 335 int tr_len;
335 336 uint8_t tr_buf[SMB_XPRT_MAX_SIZE];
336 337 } smb_txreq_t;
337 338
338 339 #define SMB_TXLST_MAGIC 0X544C5354 /* 'TLST' */
339 340 typedef struct {
340 341 uint32_t tl_magic;
341 342 kmutex_t tl_mutex;
342 343 kcondvar_t tl_wait_cv;
343 344 boolean_t tl_active;
344 345 } smb_txlst_t;
345 346
346 347 /*
347 348 * Maximum buffer size for NT is 37KB. If all clients are Windows 2000, this
348 349 * can be changed to 64KB. 37KB must be used with a mix of NT/Windows 2000
349 350 * clients because NT loses directory entries when values greater than 37KB are
350 351 * used.
351 352 *
352 353 * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to
353 354 * account for the NBT header.
354 355 */
355 356 #define NBT_MAXBUF 8
356 357 #define SMB_NT_MAXBUF (37 * 1024)
357 358
358 359 #define OUTBUFSIZE (65 * 1024)
359 360 #define SMBHEADERSIZE 32
360 361 #define SMBND_HASH_MASK (0xFF)
361 362 #define MAX_IOVEC 512
362 363 #define MAX_READREF (8 * 1024)
363 364
364 365 #define SMB_WORKER_MIN 4
365 366 #define SMB_WORKER_DEFAULT 64
366 367 #define SMB_WORKER_MAX 1024
367 368
368 369 /*
369 370 * Destructor object used in the locked-list delete queue.
370 371 */
371 372 #define SMB_DTOR_MAGIC 0x44544F52 /* DTOR */
372 373 #define SMB_DTOR_VALID(d) \
373 374 ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC))
374 375
375 376 typedef void (*smb_dtorproc_t)(void *);
376 377
377 378 typedef struct smb_dtor {
378 379 list_node_t dt_lnd;
379 380 uint32_t dt_magic;
380 381 void *dt_object;
381 382 smb_dtorproc_t dt_proc;
382 383 } smb_dtor_t;
383 384
384 385 typedef struct smb_llist {
385 386 krwlock_t ll_lock;
386 387 list_t ll_list;
387 388 uint32_t ll_count;
388 389 uint64_t ll_wrop;
389 390 kmutex_t ll_mutex;
390 391 list_t ll_deleteq;
391 392 uint32_t ll_deleteq_count;
392 393 boolean_t ll_flushing;
393 394 } smb_llist_t;
394 395
395 396 typedef struct smb_bucket {
396 397 smb_llist_t b_list;
397 398 uint32_t b_max_seen;
398 399 } smb_bucket_t;
399 400
400 401 typedef struct smb_hash {
401 402 uint32_t rshift;
402 403 uint32_t num_buckets;
403 404 smb_bucket_t *buckets;
404 405 } smb_hash_t;
405 406
406 407 typedef struct smb_slist {
407 408 kmutex_t sl_mutex;
408 409 kcondvar_t sl_cv;
409 410 list_t sl_list;
410 411 uint32_t sl_count;
411 412 boolean_t sl_waiting;
412 413 } smb_slist_t;
413 414
414 415 /*
415 416 * smb_avl_t State Machine
416 417 * --------------------
417 418 *
418 419 * +-----------------------------+
419 420 * | SMB_AVL_STATE_START |
420 421 * +-----------------------------+
421 422 * | T0
422 423 * v
423 424 * +-----------------------------+
424 425 * | SMB_AVL_STATE_READY |
425 426 * +-----------------------------+
426 427 * | T1
427 428 * v
428 429 * +-----------------------------+
429 430 * | SMB_AVL_STATE_DESTROYING |
430 431 * +-----------------------------+
431 432 *
432 433 * Transition T0
433 434 *
434 435 * This transition is executed in smb_avl_create().
435 436 *
436 437 * Transition T1
437 438 *
438 439 * This transition is executed in smb_avl_destroy().
439 440 *
440 441 */
441 442 typedef enum {
442 443 SMB_AVL_STATE_START = 0,
443 444 SMB_AVL_STATE_READY,
444 445 SMB_AVL_STATE_DESTROYING
445 446 } smb_avl_state_t;
446 447
447 448 typedef struct smb_avl_nops {
448 449 int (*avln_cmp) (const void *, const void *);
449 450 void (*avln_hold)(const void *);
450 451 boolean_t (*avln_rele)(const void *);
451 452 void (*avln_destroy)(void *);
452 453 } smb_avl_nops_t;
453 454
454 455 typedef struct smb_avl_cursor {
455 456 void *avlc_next;
456 457 uint32_t avlc_sequence;
457 458 } smb_avl_cursor_t;
458 459
459 460 typedef struct smb_avl {
460 461 krwlock_t avl_lock;
461 462 avl_tree_t avl_tree;
462 463 kmutex_t avl_mutex;
463 464 kcondvar_t avl_cv;
464 465 smb_avl_state_t avl_state;
465 466 uint32_t avl_refcnt;
466 467 uint32_t avl_sequence;
467 468 const smb_avl_nops_t *avl_nops;
468 469 } smb_avl_t;
469 470
470 471 typedef struct {
471 472 kcondvar_t rwx_cv;
472 473 kmutex_t rwx_mutex;
473 474 krwlock_t rwx_lock;
474 475 boolean_t rwx_waiting;
475 476 } smb_rwx_t;
476 477
477 478 typedef struct smb_export {
478 479 kmutex_t e_mutex;
479 480 boolean_t e_ready;
480 481 smb_avl_t e_share_avl;
481 482 smb_slist_t e_unexport_list;
482 483 smb_thread_t e_unexport_thread;
483 484 } smb_export_t;
484 485
485 486 /*
486 487 * NOTIFY CHANGE, a.k.a. File Change Notification (FCN)
487 488 */
488 489
489 490 /*
490 491 * These FCN filter mask values are not from MS-FSCC, but
491 492 * must not overlap with any FILE_NOTIFY_VALID_MASK values.
492 493 */
493 494 #define FILE_NOTIFY_CHANGE_EV_SUBDIR 0x00010000
494 495 #define FILE_NOTIFY_CHANGE_EV_DELETE 0x00020000
495 496 #define FILE_NOTIFY_CHANGE_EV_CLOSED 0x00040000
496 497 #define FILE_NOTIFY_CHANGE_EV_OVERFLOW 0x00080000
497 498
498 499 /*
499 500 * Note: These FCN action values are not from MS-FSCC, but must
500 501 * follow in sequence from FILE_ACTION_MODIFIED_STREAM.
501 502 *
502 503 * FILE_ACTION_SUBDIR_CHANGED is used internally for
503 504 * "watch tree" support, posted to all parents of a
504 505 * directory that had one of the changes above.
505 506 *
506 507 * FILE_ACTION_DELETE_PENDING is used internally to tell
507 508 * notify change requests when the "delete-on-close" flag
508 509 * has been set on the directory being watched.
509 510 *
510 511 * FILE_ACTION_HANDLE_CLOSED is used to wakeup notify change
511 512 * requests when the watched directory handle is closed.
512 513 */
513 514 #define FILE_ACTION_SUBDIR_CHANGED 0x00000009
514 515 #define FILE_ACTION_DELETE_PENDING 0x0000000a
515 516 #define FILE_ACTION_HANDLE_CLOSED 0x0000000b
516 517
517 518 /*
518 519 * Sub-struct within smb_ofile_t
519 520 */
520 521 typedef struct smb_notify {
521 522 list_t nc_waiters; /* Waiting SRs */
522 523 mbuf_chain_t nc_buffer;
523 524 uint32_t nc_filter;
524 525 uint32_t nc_events;
525 526 int nc_last_off;
526 527 boolean_t nc_subscribed;
527 528 } smb_notify_t;
528 529
529 530 /*
530 531 * SMB operates over a NetBIOS-over-TCP transport (NBT) or directly
531 532 * over TCP, which is also known as direct hosted NetBIOS-less SMB
532 533 * or SMB-over-TCP.
533 534 *
534 535 * NBT messages have a 4-byte header that defines the message type
535 536 * (8-bits), a 7-bit flags field and a 17-bit length.
536 537 *
537 538 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
538 539 * | TYPE | FLAGS |E| LENGTH |
539 540 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
540 541 *
541 542 * 8-bit type Defined in RFC 1002
542 543 * 7-bit flags Bits 0-6 reserved (must be 0)
543 544 * Bit 7: Length extension bit (E)
544 545 * 17-bit length Includes bit 7 of the flags byte
545 546 *
546 547 *
547 548 * SMB-over-TCP is defined to use a modified version of the NBT header
548 549 * containing an 8-bit message type and 24-bit message length.
549 550 *
550 551 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
551 552 * | TYPE | LENGTH |
552 553 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
553 554 *
554 555 * 8-bit type Must be 0
555 556 * 24-bit length
556 557 *
557 558 * The following structure is used to represent a generic, in-memory
558 559 * SMB transport header; it is not intended to map directly to either
559 560 * of the over-the-wire formats.
560 561 */
561 562 typedef struct {
562 563 uint8_t xh_type;
563 564 uint32_t xh_length;
564 565 } smb_xprt_t;
565 566
566 567 int MBC_LENGTH(struct mbuf_chain *);
567 568 int MBC_MAXBYTES(struct mbuf_chain *);
568 569 void MBC_SETUP(struct mbuf_chain *, uint32_t);
569 570 void MBC_INIT(struct mbuf_chain *, uint32_t);
570 571 void MBC_FLUSH(struct mbuf_chain *);
571 572 void MBC_ATTACH_MBUF(struct mbuf_chain *, struct mbuf *);
572 573 void MBC_APPEND_MBUF(struct mbuf_chain *, struct mbuf *);
573 574 void MBC_ATTACH_BUF(struct mbuf_chain *MBC, unsigned char *BUF, int LEN);
574 575 int MBC_SHADOW_CHAIN(struct mbuf_chain *SUBMBC, struct mbuf_chain *MBC,
575 576 int OFF, int LEN);
576 577
577 578 #define MBC_ROOM_FOR(b, n) (((b)->chain_offset + (n)) <= (b)->max_bytes)
578 579
579 580 /*
580 581 * Per smb_node oplock state
581 582 */
582 583 typedef struct smb_oplock {
583 584 kmutex_t ol_mutex;
584 585 boolean_t ol_fem; /* fem monitor installed? */
585 586 struct smb_ofile *excl_open;
586 587 uint32_t ol_state;
587 588 int32_t cnt_II;
588 589 int32_t cnt_R;
589 590 int32_t cnt_RH;
590 591 int32_t cnt_RHBQ;
591 592 int32_t waiters;
592 593 kcondvar_t WaitingOpenCV;
593 594 } smb_oplock_t;
594 595
595 596 /*
596 597 * Per smb_ofile oplock state
597 598 */
598 599 typedef struct smb_oplock_grant {
599 600 /* smb protocol-level state */
600 601 uint32_t og_state; /* latest sent to client */
601 602 uint32_t og_breaking; /* BREAK_TO... flags */
602 603 uint16_t og_dialect; /* how to send breaks */
603 604 /* File-system level state */
604 605 uint8_t onlist_II;
605 606 uint8_t onlist_R;
606 607 uint8_t onlist_RH;
607 608 uint8_t onlist_RHBQ;
608 609 uint8_t BreakingToRead;
609 610 } smb_oplock_grant_t;
610 611
611 612 #define SMB_LEASE_KEY_SZ 16
612 613
613 614 typedef struct smb_lease {
614 615 list_node_t ls_lnd; /* sv_lease_ht */
615 616 kmutex_t ls_mutex;
616 617 smb_llist_t *ls_bucket;
617 618 struct smb_node *ls_node;
618 619 /*
619 620 * With a lease, just one ofile has the oplock.
620 621 * This (used only for comparison) identifies which.
621 622 */
622 623 void *ls_oplock_ofile;
623 624 uint32_t ls_refcnt;
624 625 uint32_t ls_state;
625 626 uint32_t ls_breaking; /* BREAK_TO... flags */
626 627 uint16_t ls_epoch;
627 628 uint16_t ls_version;
628 629 uint8_t ls_key[SMB_LEASE_KEY_SZ];
629 630 uint8_t ls_clnt[SMB_LEASE_KEY_SZ];
630 631 } smb_lease_t;
631 632
632 633 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */
633 634 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC)
634 635
635 636 typedef enum {
636 637 SMB_NODE_STATE_AVAILABLE = 0,
637 638 SMB_NODE_STATE_DESTROYING
638 639 } smb_node_state_t;
639 640
640 641 /*
641 642 * waiting_event # of clients requesting FCN
642 643 * n_timestamps cached timestamps
643 644 * n_allocsz cached file allocation size
644 645 * n_dnode directory node
645 646 * n_unode unnamed stream node
646 647 * delete_on_close_cred credentials for delayed delete
647 648 */
648 649 typedef struct smb_node {
649 650 list_node_t n_lnd;
650 651 uint32_t n_magic;
651 652 krwlock_t n_lock;
652 653 kmutex_t n_mutex;
653 654 smb_node_state_t n_state;
654 655 uint32_t n_refcnt;
655 656 uint32_t n_hashkey;
656 657 smb_llist_t *n_hash_bucket;
657 658 uint32_t n_open_count;
658 659 uint32_t n_opening_count;
659 660 smb_llist_t n_ofile_list;
660 661 /* If entering both, go in order n_lock_list, n_wlock_list */
661 662 smb_llist_t n_lock_list; /* active locks */
662 663 smb_llist_t n_wlock_list; /* waiting locks */
663 664 volatile int flags;
664 665 u_offset_t n_allocsz;
665 666 uint32_t n_fcn_count;
666 667 smb_oplock_t n_oplock;
667 668 struct smb_node *n_dnode;
668 669 struct smb_node *n_unode;
669 670 cred_t *delete_on_close_cred;
670 671 uint32_t n_delete_on_close_flags;
671 672 char od_name[MAXNAMELEN];
672 673 vnode_t *vp;
673 674 smb_audit_buf_node_t *n_audit_buf;
674 675 } smb_node_t;
675 676
676 677 #define NODE_FLAGS_REPARSE 0x00001000
677 678 #define NODE_FLAGS_DFSLINK 0x00002000
678 679 #define NODE_FLAGS_VFSROOT 0x00004000
679 680 #define NODE_FLAGS_SYSTEM 0x00008000
680 681 #define NODE_FLAGS_WRITE_THROUGH 0x00100000
681 682 #define NODE_XATTR_DIR 0x01000000
682 683 #define NODE_FLAGS_DELETE_COMMITTED 0x20000000
683 684 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000
684 685 #define NODE_FLAGS_EXECUTABLE 0x80000000
685 686
686 687 #define SMB_NODE_VFS(node) ((node)->vp->v_vfsp)
687 688 #define SMB_NODE_FSID(node) ((node)->vp->v_vfsp->vfs_fsid)
688 689
689 690 /* Maximum buffer size for encryption key */
690 691 #define SMB_ENCRYPT_KEY_MAXLEN 32
691 692
692 693 #define SMB_SHARE_MAGIC 0x4B534852 /* KSHR */
693 694
694 695 typedef struct smb_kshare {
695 696 uint32_t shr_magic;
696 697 avl_node_t shr_link;
697 698 kmutex_t shr_mutex;
698 699 kcondvar_t shr_cv;
699 700 char *shr_name;
700 701 char *shr_path;
701 702 char *shr_cmnt;
702 703 char *shr_container;
703 704 char *shr_oemname;
704 705 uint32_t shr_flags;
705 706 uint32_t shr_type;
706 707 uint32_t shr_refcnt;
707 708 uint32_t shr_autocnt;
708 709 uid_t shr_uid;
709 710 gid_t shr_gid;
710 711 char *shr_access_none;
711 712 char *shr_access_ro;
712 713 char *shr_access_rw;
713 714 smb_node_t *shr_root_node;
714 715 smb_node_t *shr_ca_dir;
715 716 void *shr_import_busy;
716 717 smb_cfg_val_t shr_encrypt; /* Share.EncryptData */
717 718 } smb_kshare_t;
718 719
719 720
720 721 typedef struct smb_arg_negotiate {
721 722 char *ni_name;
722 723 int ni_dialect;
723 724 int ni_index;
724 725 uint32_t ni_capabilities;
725 726 uint16_t ni_maxmpxcount;
726 727 int16_t ni_tzcorrection;
727 728 uint8_t ni_keylen;
728 729 uint8_t ni_key[SMB_ENCRYPT_KEY_MAXLEN];
729 730 timestruc_t ni_servertime;
730 731 } smb_arg_negotiate_t;
731 732
732 733 typedef enum {
733 734 SMB_SSNSETUP_PRE_NTLM012 = 1,
734 735 SMB_SSNSETUP_NTLM012_NOEXT,
735 736 SMB_SSNSETUP_NTLM012_EXTSEC
736 737 } smb_ssnsetup_type_t;
737 738
738 739 typedef struct smb_arg_sessionsetup {
739 740 smb_ssnsetup_type_t ssi_type;
740 741 char *ssi_user;
741 742 char *ssi_domain;
742 743 /* LM password hash, f.k.a. case-insensitive p/w */
743 744 uint16_t ssi_lmpwlen;
744 745 uint8_t *ssi_lmpwd;
745 746 /* NT password hash, f.k.a. case-sensitive p/w */
746 747 uint16_t ssi_ntpwlen;
747 748 uint8_t *ssi_ntpwd;
748 749 /* Incoming security blob */
749 750 uint16_t ssi_iseclen;
750 751 uint8_t *ssi_isecblob;
751 752 /* Incoming security blob */
752 753 uint16_t ssi_oseclen;
753 754 uint8_t *ssi_osecblob;
754 755 /* parameters */
755 756 uint16_t ssi_maxbufsize;
756 757 uint16_t ssi_maxmpxcount;
757 758 uint32_t ssi_capabilities;
758 759 int ssi_native_os;
759 760 int ssi_native_lm;
760 761 } smb_arg_sessionsetup_t;
761 762
762 763 typedef struct tcon {
763 764 char *name;
764 765 char *path;
765 766 char *service;
766 767 int pwdlen;
767 768 char *password;
768 769 uint16_t flags;
769 770 uint16_t optional_support;
770 771 smb_kshare_t *si;
771 772 } smb_arg_tcon_t;
772 773
773 774 /*
774 775 * Based on section 2.6.1.2 (Connection Management) of the June 13,
775 776 * 1996 CIFS spec, a server may terminate the transport connection
776 777 * due to inactivity. The client software is expected to be able to
777 778 * automatically reconnect to the server if this happens. Like much
778 779 * of the useful background information, this section appears to
779 780 * have been dropped from later revisions of the document.
780 781 *
781 782 * Each session has an activity timestamp that's updated whenever a
782 783 * request is dispatched. If the session is idle, i.e. receives no
783 784 * requests, for SMB_SESSION_INACTIVITY_TIMEOUT minutes it will be
784 785 * closed.
785 786 *
786 787 * Each session has an I/O semaphore to serialize communication with
787 788 * the client. For example, after receiving a raw-read request, the
788 789 * server is not allowed to send an oplock break to the client until
789 790 * after it has sent the raw-read data.
790 791 */
791 792 #define SMB_SESSION_INACTIVITY_TIMEOUT (15 * 60)
792 793
793 794 /* SMB1 signing */
794 795 struct smb_sign {
795 796 unsigned int flags;
796 797 uint32_t seqnum;
797 798 uint_t mackey_len;
798 799 uint8_t *mackey;
799 800 };
800 801
801 802 /*
802 803 * SMB2 signing
803 804 */
804 805 struct smb_key {
805 806 uint_t len;
806 807 uint8_t key[SMB2_SESSION_KEY_LEN];
807 808 };
808 809
809 810 #define SMB_SIGNING_ENABLED 1
810 811 #define SMB_SIGNING_CHECK 2
811 812
812 813 /*
813 814 * Locking notes:
814 815 * If you hold the mutex/lock on an object, don't flush the deleteq
815 816 * of the objects directly below it in the logical hierarchy
816 817 * (i.e. via smb_llist_exit()). I.e. don't drop s_tree_list when
817 818 * you hold u_mutex, because deleted trees need u_mutex to
818 819 * lower the refcnt.
819 820 *
820 821 * Note that this also applies to u_mutex and t_ofile_list.
821 822 */
822 823
823 824 /*
824 825 * The "session" object.
825 826 *
826 827 * Note that the smb_session_t object here corresponds to what MS-SMB2
827 828 * calls a "connection". Adding to the confusion, what MS calls a
828 829 * "session" corresponds to our smb_user_t (below).
829 830 */
830 831
831 832 /*
832 833 * Session State Machine
833 834 * ---------------------
834 835 *
835 836 *
836 837 * +-----------------------------+ +----------------------------+
837 838 * | SMB_SESSION_STATE_CONNECTED | | SMB_SESSION_STATE_SHUTDOWN |
838 839 * +-----------------------------+ +----------------------------+
839 840 * | ^
840 841 * | |T6
841 842 * | +------------------------------+
842 843 * | | SMB_SESSION_STATE_TERMINATED |
843 844 * T0| +------------------------------+
844 845 * +--------------------+ ^
845 846 * v |T4 |T5
846 847 * +-------------------------------+ | +--------------------------------+
847 848 * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED |
848 849 * +-------------------------------+ +--------------------------------+
849 850 * T1| ^
850 851 * +----------+ |T3
851 852 * v |
852 853 * +------------------------------+
853 854 * | SMB_SESSION_STATE_NEGOTIATED |
854 855 * +------------------------------+
855 856 *
856 857 *
857 858 * Transition T0
858 859 *
859 860 *
860 861 *
861 862 * Transition T1
862 863 *
863 864 *
864 865 *
865 866 * Transition T2
866 867 *
867 868 *
868 869 *
869 870 * Transition T3
870 871 *
871 872 *
872 873 *
873 874 * Transition T4
874 875 *
875 876 *
876 877 *
877 878 * Transition T5
878 879 *
879 880 *
880 881 *
↓ open down ↓ |
847 lines elided |
↑ open up ↑ |
881 882 * Transition T6
882 883 *
883 884 *
884 885 *
885 886 */
886 887 #define SMB_SESSION_MAGIC 0x53455353 /* 'SESS' */
887 888 #define SMB_SESSION_VALID(p) \
888 889 ASSERT(((p) != NULL) && ((p)->s_magic == SMB_SESSION_MAGIC))
889 890
890 891 #define SMB_CHALLENGE_SZ 8
892 +#define SMB3_PREAUTH_HASHVAL_SZ 64
891 893
892 894 typedef enum {
893 895 SMB_SESSION_STATE_INITIALIZED = 0,
894 896 SMB_SESSION_STATE_DISCONNECTED,
895 897 SMB_SESSION_STATE_CONNECTED,
896 898 SMB_SESSION_STATE_ESTABLISHED,
897 899 SMB_SESSION_STATE_NEGOTIATED,
898 900 SMB_SESSION_STATE_TERMINATED,
899 901 SMB_SESSION_STATE_SHUTDOWN,
900 902 SMB_SESSION_STATE_SENTINEL
901 903 } smb_session_state_t;
902 904
903 905 /* Bits in s_flags below */
904 906 #define SMB_SSN_AAPL_CCEXT 1 /* Saw "AAPL" create ctx. ext. */
905 907 #define SMB_SSN_AAPL_READDIR 2 /* Wants MacOS ext. readdir */
906 908
907 909 typedef struct smb_session {
908 910 list_node_t s_lnd;
909 911 uint32_t s_magic;
910 912 smb_rwx_t s_lock;
911 913 uint64_t s_kid;
912 914 smb_session_state_t s_state;
913 915 uint32_t s_flags;
914 916 taskqid_t s_receiver_tqid;
915 917 kthread_t *s_thread;
916 918 kt_did_t s_ktdid;
917 919 int (*newrq_func)(struct smb_request *);
918 920 struct smb_server *s_server;
919 921 smb_kmod_cfg_t s_cfg;
920 922 int32_t s_gmtoff;
921 923 uint32_t keep_alive;
922 924 uint64_t opentime;
923 925 uint16_t s_local_port;
924 926 uint16_t s_remote_port;
925 927 smb_inaddr_t ipaddr;
926 928 smb_inaddr_t local_ipaddr;
927 929 int dialect;
928 930 int native_os;
929 931 int native_lm;
930 932
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
931 933 kmutex_t s_credits_mutex;
932 934 uint16_t s_cur_credits;
933 935 uint16_t s_max_credits;
934 936
935 937 uint32_t capabilities;
936 938 uint32_t srv_cap;
937 939
938 940 struct smb_sign signing; /* SMB1 */
939 941 void *sign_mech; /* mechanism info */
940 942 void *enc_mech;
943 + void *preauth_mech;
941 944
942 945 /* SMB2/SMB3 signing support */
943 946 int (*sign_calc)(struct smb_request *,
944 947 struct mbuf_chain *, uint8_t *);
945 948 void (*sign_fini)(struct smb_session *);
946 949
947 950 ksocket_t sock;
948 951
949 952 smb_slist_t s_req_list;
950 953 smb_llist_t s_xa_list;
951 954 smb_llist_t s_user_list;
952 955 smb_llist_t s_tree_list;
953 956 smb_idpool_t s_uid_pool;
954 957 smb_idpool_t s_tid_pool;
955 958 smb_txlst_t s_txlst;
956 959
957 960 volatile uint32_t s_tree_cnt;
958 961 volatile uint32_t s_file_cnt;
959 962 volatile uint32_t s_dir_cnt;
960 963
961 964 uint16_t cli_secmode;
962 965 uint16_t srv_secmode;
963 966 uint32_t sesskey;
964 967 uint32_t challenge_len;
965 968 unsigned char challenge_key[SMB_CHALLENGE_SZ];
966 969 int64_t activity_timestamp;
967 970 timeout_id_t s_auth_tmo;
968 971
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
969 972 /*
970 973 * Maximum negotiated buffer sizes between SMB client and server
971 974 * in SMB_SESSION_SETUP_ANDX
972 975 */
973 976 int cmd_max_bytes;
974 977 int reply_max_bytes;
975 978 uint16_t smb_msg_size;
976 979 uint16_t smb_max_mpx;
977 980 smb_srqueue_t *s_srqueue;
978 981 uint64_t start_time;
982 +
983 + uint16_t smb31_enc_cipherid;
984 + uint16_t smb31_preauth_hashid;
985 + uint8_t smb31_preauth_hashval[SMB3_PREAUTH_HASHVAL_SZ];
986 + uint8_t smb31_preauth_salt[32];
987 +
979 988 unsigned char MAC_key[44];
980 989 char ip_addr_str[INET6_ADDRSTRLEN];
981 990 uint8_t clnt_uuid[16];
982 991 char workstation[SMB_PI_MAX_HOST];
983 992 } smb_session_t;
984 993
985 994 /*
986 995 * The "user" object.
987 996 *
988 997 * Note that smb_user_t object here corresponds to what MS-SMB2 calls
989 998 * a "session". (Our smb_session_t is something else -- see above).
990 999 */
991 1000
992 1001 #define SMB_USER_MAGIC 0x55534552 /* 'USER' */
993 1002 #define SMB_USER_VALID(u) \
994 1003 ASSERT(((u) != NULL) && ((u)->u_magic == SMB_USER_MAGIC))
995 1004
996 1005 /* These flags are all <= 0x00000010 */
997 1006 #define SMB_USER_FLAG_GUEST SMB_ATF_GUEST
998 1007 #define SMB_USER_FLAG_ANON SMB_ATF_ANON
999 1008 #define SMB_USER_FLAG_ADMIN SMB_ATF_ADMIN
1000 1009 #define SMB_USER_FLAG_POWER_USER SMB_ATF_POWERUSER
1001 1010 #define SMB_USER_FLAG_BACKUP_OPERATOR SMB_ATF_BACKUPOP
1002 1011
1003 1012 #define SMB_USER_IS_ADMIN(U) (((U)->u_flags & SMB_USER_FLAG_ADMIN) != 0)
1004 1013 #define SMB_USER_IS_GUEST(U) (((U)->u_flags & SMB_USER_FLAG_GUEST) != 0)
1005 1014
1006 1015 /*
1007 1016 * Internal privilege flags derived from smb_privilege.h numbers
1008 1017 * Would rather not include that in this file.
1009 1018 */
1010 1019 #define SMB_USER_PRIV_SECURITY (1<<8) /* SE_SECURITY_LUID */
1011 1020 #define SMB_USER_PRIV_TAKE_OWNERSHIP (1<<9) /* SE_TAKE_OWNERSHIP_LUID */
1012 1021 #define SMB_USER_PRIV_BACKUP (1<<17) /* SE_BACKUP_LUID */
1013 1022 #define SMB_USER_PRIV_RESTORE (1<<18) /* SE_RESTORE_LUID */
1014 1023 #define SMB_USER_PRIV_CHANGE_NOTIFY (1<<23) /* SE_CHANGE_NOTIFY_LUID */
1015 1024 #define SMB_USER_PRIV_READ_FILE (1<<25) /* SE_READ_FILE_LUID */
1016 1025 #define SMB_USER_PRIV_WRITE_FILE (1<<26) /* SE_WRITE_FILE_LUID */
1017 1026
1018 1027 /*
1019 1028 * See the long "User State Machine" comment in smb_user.c
1020 1029 */
1021 1030 typedef enum {
1022 1031 SMB_USER_STATE_LOGGING_ON = 0,
1023 1032 SMB_USER_STATE_LOGGED_ON,
1024 1033 SMB_USER_STATE_LOGGING_OFF,
1025 1034 SMB_USER_STATE_LOGGED_OFF,
1026 1035 SMB_USER_STATE_SENTINEL
1027 1036 } smb_user_state_t;
1028 1037
1029 1038 typedef enum {
1030 1039 SMB2_DH_PRESERVE_NONE = 0,
1031 1040 SMB2_DH_PRESERVE_SOME,
1032 1041 SMB2_DH_PRESERVE_ALL
1033 1042 } smb_preserve_type_t;
1034 1043
1035 1044 typedef struct smb_user {
1036 1045 list_node_t u_lnd;
1037 1046 uint32_t u_magic;
1038 1047 kmutex_t u_mutex;
1039 1048 smb_user_state_t u_state;
1040 1049
1041 1050 struct smb_server *u_server;
1042 1051 smb_session_t *u_session;
1043 1052 ksocket_t u_authsock;
1044 1053 timeout_id_t u_auth_tmo;
1045 1054 uint16_t u_name_len;
1046 1055 char *u_name;
1047 1056 uint16_t u_domain_len;
1048 1057 char *u_domain;
1049 1058 time_t u_logon_time;
1050 1059 cred_t *u_cred;
1051 1060 cred_t *u_privcred;
1052 1061
1053 1062 uint64_t u_ssnid; /* unique server-wide */
1054 1063 uint32_t u_refcnt;
1055 1064 uint32_t u_flags;
1056 1065 smb_preserve_type_t preserve_opens;
1057 1066 uint32_t u_privileges;
1058 1067 uint16_t u_uid; /* unique per-session */
1059 1068 uint32_t u_audit_sid;
1060 1069
1061 1070 uint32_t u_sign_flags;
1062 1071 struct smb_key u_sign_key; /* SMB2 signing */
1063 1072
1064 1073 struct smb_key u_enc_key;
1065 1074 struct smb_key u_dec_key;
1066 1075 volatile uint64_t u_nonce_cnt;
1067 1076 uint8_t u_nonce_fixed[4];
1068 1077 uint64_t u_salt;
1069 1078 smb_cfg_val_t u_encrypt;
1070 1079 } smb_user_t;
1071 1080
1072 1081 #define SMB_TREE_MAGIC 0x54524545 /* 'TREE' */
1073 1082 #define SMB_TREE_VALID(p) \
1074 1083 ASSERT((p != NULL) && ((p)->t_magic == SMB_TREE_MAGIC))
1075 1084
1076 1085 #define SMB_TYPENAMELEN _ST_FSTYPSZ
1077 1086 #define SMB_VOLNAMELEN 32
1078 1087
1079 1088 #define SMB_TREE_READONLY 0x00000001
1080 1089 #define SMB_TREE_SUPPORTS_ACLS 0x00000002
1081 1090 #define SMB_TREE_STREAMS 0x00000004
1082 1091 #define SMB_TREE_CASEINSENSITIVE 0x00000008
1083 1092 #define SMB_TREE_NO_CASESENSITIVE 0x00000010
1084 1093 #define SMB_TREE_NO_EXPORT 0x00000020
1085 1094 #define SMB_TREE_OPLOCKS 0x00000040
1086 1095 #define SMB_TREE_SHORTNAMES 0x00000080
1087 1096 #define SMB_TREE_XVATTR 0x00000100
1088 1097 #define SMB_TREE_DIRENTFLAGS 0x00000200
1089 1098 #define SMB_TREE_ACLONCREATE 0x00000400
1090 1099 #define SMB_TREE_ACEMASKONACCESS 0x00000800
1091 1100 #define SMB_TREE_NFS_MOUNTED 0x00001000
1092 1101 #define SMB_TREE_UNICODE_ON_DISK 0x00002000
1093 1102 #define SMB_TREE_CATIA 0x00004000
1094 1103 #define SMB_TREE_ABE 0x00008000
1095 1104 #define SMB_TREE_QUOTA 0x00010000
1096 1105 #define SMB_TREE_DFSROOT 0x00020000
1097 1106 #define SMB_TREE_SPARSE 0x00040000
1098 1107 #define SMB_TREE_TRAVERSE_MOUNTS 0x00080000
1099 1108 #define SMB_TREE_FORCE_L2_OPLOCK 0x00100000
1100 1109 #define SMB_TREE_CA 0x00200000
1101 1110 /* Note: SMB_TREE_... in the mdb module too. */
1102 1111
1103 1112 /*
1104 1113 * See the long "Tree State Machine" comment in smb_tree.c
1105 1114 */
1106 1115 typedef enum {
1107 1116 SMB_TREE_STATE_CONNECTED = 0,
1108 1117 SMB_TREE_STATE_DISCONNECTING,
1109 1118 SMB_TREE_STATE_DISCONNECTED,
1110 1119 SMB_TREE_STATE_SENTINEL
1111 1120 } smb_tree_state_t;
1112 1121
1113 1122 typedef struct smb_tree {
1114 1123 list_node_t t_lnd;
1115 1124 uint32_t t_magic;
1116 1125 kmutex_t t_mutex;
1117 1126 smb_tree_state_t t_state;
1118 1127
1119 1128 struct smb_server *t_server;
1120 1129 smb_session_t *t_session;
1121 1130 /*
1122 1131 * user whose uid was in the tree connect message
1123 1132 * ("owner" in MS-CIFS parlance, see section 2.2.1.6 definition of FID)
1124 1133 */
1125 1134 smb_user_t *t_owner;
1126 1135 smb_node_t *t_snode;
1127 1136
1128 1137 smb_llist_t t_ofile_list;
1129 1138 smb_idpool_t t_fid_pool;
1130 1139
1131 1140 smb_llist_t t_odir_list;
1132 1141 smb_idpool_t t_odid_pool;
1133 1142
1134 1143 uint32_t t_refcnt;
1135 1144 uint32_t t_flags;
1136 1145 int32_t t_res_type;
1137 1146 uint16_t t_tid;
1138 1147 uint16_t t_umask;
1139 1148 char t_sharename[MAXNAMELEN];
1140 1149 char t_resource[MAXPATHLEN];
1141 1150 char t_typename[SMB_TYPENAMELEN];
1142 1151 char t_volume[SMB_VOLNAMELEN];
1143 1152 acl_type_t t_acltype;
1144 1153 uint32_t t_access;
1145 1154 uint32_t t_execflags;
1146 1155 time_t t_connect_time;
1147 1156 volatile uint32_t t_open_files;
1148 1157 smb_cfg_val_t t_encrypt; /* Share.EncryptData */
1149 1158 } smb_tree_t;
1150 1159
1151 1160 #define SMB_TREE_VFS(tree) ((tree)->t_snode->vp->v_vfsp)
1152 1161 #define SMB_TREE_FSID(tree) ((tree)->t_snode->vp->v_vfsp->vfs_fsid)
1153 1162
1154 1163 #define SMB_TREE_IS_READONLY(sr) \
1155 1164 ((sr) != NULL && (sr)->tid_tree != NULL && \
1156 1165 !((sr)->tid_tree->t_access & ACE_ALL_WRITE_PERMS))
1157 1166
1158 1167 #define SMB_TREE_IS_CASEINSENSITIVE(sr) \
1159 1168 (((sr) && (sr)->tid_tree) ? \
1160 1169 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CASEINSENSITIVE) : 0)
1161 1170
1162 1171 #define SMB_TREE_HAS_ACCESS(sr, acemask) \
1163 1172 ((sr) == NULL ? ACE_ALL_PERMS : ( \
1164 1173 (((sr) && (sr)->tid_tree) ? \
1165 1174 (((sr)->tid_tree->t_access) & (acemask)) : 0)))
1166 1175
1167 1176 #define SMB_TREE_SUPPORTS_CATIA(sr) \
1168 1177 (((sr) && (sr)->tid_tree) ? \
1169 1178 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CATIA) : 0)
1170 1179
1171 1180 #define SMB_TREE_SUPPORTS_ABE(sr) \
1172 1181 (((sr) && (sr)->tid_tree) ? \
1173 1182 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_ABE) : 0)
1174 1183
1175 1184 #define SMB_TREE_IS_DFSROOT(sr) \
1176 1185 (((sr) && (sr)->tid_tree) ? \
1177 1186 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_DFSROOT) : 0)
1178 1187
1179 1188 #define SMB_TREE_SUPPORTS_SHORTNAMES(sr) \
1180 1189 (((sr) && (sr)->tid_tree) ? \
1181 1190 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_SHORTNAMES) : 0)
1182 1191
1183 1192 /*
1184 1193 * SMB_TREE_CONTAINS_NODE is used to check if a node is on the same
1185 1194 * file system as the tree's root filesystem, or if mount point traversal
1186 1195 * should be allowed. Note that this is also called in some cases with
1187 1196 * sr=NULL, where it is expected to evaluate to TRUE.
1188 1197 */
1189 1198
1190 1199 #define SMB_TREE_CONTAINS_NODE(sr, node) \
1191 1200 ((sr) == NULL || (sr)->tid_tree == NULL || \
1192 1201 SMB_TREE_VFS((sr)->tid_tree) == SMB_NODE_VFS(node) || \
1193 1202 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_TRAVERSE_MOUNTS))
1194 1203
1195 1204 /*
1196 1205 * SMB_PATHFILE_IS_READONLY indicates whether or not a file is
1197 1206 * readonly when the caller has a path rather than an ofile.
1198 1207 */
1199 1208 #define SMB_PATHFILE_IS_READONLY(sr, node) \
1200 1209 (SMB_TREE_IS_READONLY((sr)) || \
1201 1210 smb_node_file_is_readonly((node)))
1202 1211
1203 1212 #define SMB_ODIR_MAGIC 0x4F444952 /* 'ODIR' */
1204 1213 #define SMB_ODIR_VALID(p) \
1205 1214 ASSERT((p != NULL) && ((p)->d_magic == SMB_ODIR_MAGIC))
1206 1215
1207 1216 #define SMB_ODIR_BUFSIZE (8 * 1024)
1208 1217
1209 1218 #define SMB_ODIR_FLAG_WILDCARDS 0x0001
1210 1219 #define SMB_ODIR_FLAG_IGNORE_CASE 0x0002
1211 1220 #define SMB_ODIR_FLAG_XATTR 0x0004
1212 1221 #define SMB_ODIR_FLAG_EDIRENT 0x0008
1213 1222 #define SMB_ODIR_FLAG_CATIA 0x0010
1214 1223 #define SMB_ODIR_FLAG_ABE 0x0020
1215 1224 #define SMB_ODIR_FLAG_SHORTNAMES 0x0040
1216 1225
1217 1226 typedef enum {
1218 1227 SMB_ODIR_STATE_OPEN = 0,
1219 1228 SMB_ODIR_STATE_IN_USE,
1220 1229 SMB_ODIR_STATE_CLOSING,
1221 1230 SMB_ODIR_STATE_CLOSED,
1222 1231 SMB_ODIR_STATE_SENTINEL
1223 1232 } smb_odir_state_t;
1224 1233
1225 1234 typedef enum {
1226 1235 SMB_ODIR_RESUME_CONT,
1227 1236 SMB_ODIR_RESUME_IDX,
1228 1237 SMB_ODIR_RESUME_COOKIE,
1229 1238 SMB_ODIR_RESUME_FNAME
1230 1239 } smb_odir_resume_type_t;
1231 1240
1232 1241 typedef struct smb_odir_resume {
1233 1242 smb_odir_resume_type_t or_type;
1234 1243 int or_idx;
1235 1244 uint32_t or_cookie;
1236 1245 char *or_fname;
1237 1246 } smb_odir_resume_t;
1238 1247
1239 1248 /*
1240 1249 * Flags used when opening an odir
1241 1250 */
1242 1251 #define SMB_ODIR_OPENF_BACKUP_INTENT 0x01
1243 1252
1244 1253 typedef struct smb_odir {
1245 1254 list_node_t d_lnd;
1246 1255 uint32_t d_magic;
1247 1256 kmutex_t d_mutex;
1248 1257 smb_odir_state_t d_state;
1249 1258 smb_session_t *d_session;
1250 1259 smb_user_t *d_user;
1251 1260 smb_tree_t *d_tree;
1252 1261 smb_node_t *d_dnode;
1253 1262 cred_t *d_cred;
1254 1263 uint32_t d_opened_by_pid;
1255 1264 uint16_t d_odid;
1256 1265 uint16_t d_sattr;
1257 1266 uint32_t d_refcnt;
1258 1267 uint32_t d_flags;
1259 1268 boolean_t d_eof;
1260 1269 int d_bufsize;
1261 1270 uint64_t d_offset;
1262 1271 union {
1263 1272 char *u_bufptr;
1264 1273 struct edirent *u_edp;
1265 1274 struct dirent64 *u_dp;
1266 1275 } d_u;
1267 1276 uint32_t d_last_cookie;
1268 1277 uint32_t d_cookies[SMB_MAX_SEARCH];
1269 1278 char d_pattern[MAXNAMELEN];
1270 1279 char d_buf[SMB_ODIR_BUFSIZE];
1271 1280 char d_last_name[MAXNAMELEN];
1272 1281 } smb_odir_t;
1273 1282 #define d_bufptr d_u.u_bufptr
1274 1283 #define d_edp d_u.u_edp
1275 1284 #define d_dp d_u.u_dp
1276 1285
1277 1286 typedef struct smb_odirent {
1278 1287 char od_name[MAXNAMELEN]; /* on disk name */
1279 1288 ino64_t od_ino;
1280 1289 uint32_t od_eflags;
1281 1290 } smb_odirent_t;
1282 1291
1283 1292 #define SMB_OPIPE_MAGIC 0x50495045 /* 'PIPE' */
1284 1293 #define SMB_OPIPE_VALID(p) \
1285 1294 ASSERT(((p) != NULL) && (p)->p_magic == SMB_OPIPE_MAGIC)
1286 1295 #define SMB_OPIPE_MAXNAME 32
1287 1296
1288 1297 /*
1289 1298 * Data structure for SMB_FTYPE_MESG_PIPE ofiles, which is used
1290 1299 * at the interface between SMB and NDR RPC.
1291 1300 */
1292 1301 typedef struct smb_opipe {
1293 1302 uint32_t p_magic;
1294 1303 kmutex_t p_mutex;
1295 1304 kcondvar_t p_cv;
1296 1305 struct smb_ofile *p_ofile;
1297 1306 struct smb_server *p_server;
1298 1307 uint32_t p_refcnt;
1299 1308 ksocket_t p_socket;
1300 1309 /* This is the "flat" name, without path prefix */
1301 1310 char p_name[SMB_OPIPE_MAXNAME];
1302 1311 } smb_opipe_t;
1303 1312
1304 1313 /*
1305 1314 * The of_ftype of an open file should contain the SMB_FTYPE value
1306 1315 * returned when the file/pipe was opened. The following
1307 1316 * assumptions are currently made:
1308 1317 *
1309 1318 * File Type Node PipeInfo
1310 1319 * --------- -------- --------
1311 1320 * SMB_FTYPE_DISK Valid Null
1312 1321 * SMB_FTYPE_BYTE_PIPE Undefined Undefined
1313 1322 * SMB_FTYPE_MESG_PIPE Null Valid
1314 1323 * SMB_FTYPE_PRINTER Undefined Undefined
1315 1324 * SMB_FTYPE_UNKNOWN Undefined Undefined
1316 1325 */
1317 1326
1318 1327 /*
1319 1328 * Some flags for ofile structure
1320 1329 *
1321 1330 * SMB_OFLAGS_SET_DELETE_ON_CLOSE
1322 1331 * Set this flag when the corresponding open operation whose
1323 1332 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any
1324 1333 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE
1325 1334 * will be set for the file node upon close.
1326 1335 */
1327 1336
1328 1337 /* SMB_OFLAGS_READONLY 0x0001 (obsolete) */
1329 1338 #define SMB_OFLAGS_EXECONLY 0x0002
1330 1339 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004
1331 1340 #define SMB_OFLAGS_LLF_POS_VALID 0x0008
1332 1341
1333 1342 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */
1334 1343 #define SMB_OFILE_VALID(p) \
1335 1344 ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC))
1336 1345
1337 1346 /*
1338 1347 * This is the size of the per-handle "Lock Sequence" array.
1339 1348 * See LockSequenceIndex in [MS-SMB2] 2.2.26, and smb2_lock.c
1340 1349 */
1341 1350 #define SMB_OFILE_LSEQ_MAX 64
1342 1351
1343 1352 /* {arg_open,ofile}->dh_vers values */
1344 1353 typedef enum {
1345 1354 SMB2_NOT_DURABLE = 0,
1346 1355 SMB2_DURABLE_V1,
1347 1356 SMB2_DURABLE_V2,
1348 1357 SMB2_RESILIENT,
1349 1358 } smb_dh_vers_t;
1350 1359
1351 1360 /*
1352 1361 * See the long "Ofile State Machine" comment in smb_ofile.c
1353 1362 */
1354 1363 typedef enum {
1355 1364 SMB_OFILE_STATE_ALLOC = 0,
1356 1365 SMB_OFILE_STATE_OPEN,
1357 1366 SMB_OFILE_STATE_SAVE_DH,
1358 1367 SMB_OFILE_STATE_SAVING,
1359 1368 SMB_OFILE_STATE_CLOSING,
1360 1369 SMB_OFILE_STATE_CLOSED,
1361 1370 SMB_OFILE_STATE_ORPHANED,
1362 1371 SMB_OFILE_STATE_RECONNECT,
1363 1372 SMB_OFILE_STATE_EXPIRED,
1364 1373 SMB_OFILE_STATE_SENTINEL
1365 1374 } smb_ofile_state_t;
1366 1375
1367 1376 typedef struct smb_ofile {
1368 1377 list_node_t f_tree_lnd; /* t_ofile_list */
1369 1378 list_node_t f_node_lnd; /* n_ofile_list */
1370 1379 list_node_t f_dh_lnd; /* sv_persistid_ht */
1371 1380 uint32_t f_magic;
1372 1381 kmutex_t f_mutex;
1373 1382 smb_ofile_state_t f_state;
1374 1383
1375 1384 struct smb_server *f_server;
1376 1385 smb_session_t *f_session;
1377 1386 smb_user_t *f_user;
1378 1387 smb_tree_t *f_tree;
1379 1388 smb_node_t *f_node;
1380 1389 smb_odir_t *f_odir;
1381 1390 smb_opipe_t *f_pipe;
1382 1391
1383 1392 kcondvar_t f_cv;
1384 1393 /*
1385 1394 * Note: f_persistid == 0 means this ofile has no persistid
1386 1395 * (same interpretation at the protocol level). IFF non-zero,
1387 1396 * this ofile is linked in the sv_persistid_ht hash table.
1388 1397 */
1389 1398 uint64_t f_persistid;
1390 1399 uint32_t f_uniqid;
1391 1400 uint32_t f_refcnt;
1392 1401 uint64_t f_seek_pos;
1393 1402 uint32_t f_flags;
1394 1403 uint32_t f_granted_access;
1395 1404 uint32_t f_share_access;
1396 1405 uint32_t f_create_options;
1397 1406 uint32_t f_opened_by_pid;
1398 1407 uint16_t f_fid;
1399 1408 uint16_t f_ftype;
1400 1409 uint64_t f_llf_pos;
1401 1410 int f_mode;
1402 1411 cred_t *f_cr;
1403 1412 pid_t f_pid;
1404 1413 smb_attr_t f_pending_attr;
1405 1414 boolean_t f_written;
1406 1415 smb_oplock_grant_t f_oplock;
1407 1416 uint8_t TargetOplockKey[SMB_LEASE_KEY_SZ];
1408 1417 uint8_t ParentOplockKey[SMB_LEASE_KEY_SZ];
1409 1418 struct smb_lease *f_lease;
1410 1419
1411 1420 smb_notify_t f_notify;
1412 1421
1413 1422 smb_dh_vers_t dh_vers;
1414 1423 hrtime_t dh_timeout_offset; /* time offset for timeout */
1415 1424 hrtime_t dh_expire_time; /* time the handle expires */
1416 1425 boolean_t dh_persist;
1417 1426 kmutex_t dh_nvlock;
1418 1427 struct nvlist *dh_nvlist;
1419 1428 smb_node_t *dh_nvfile;
1420 1429
1421 1430 uint8_t dh_create_guid[16];
1422 1431 char f_quota_resume[SMB_SID_STRSZ];
1423 1432 uint8_t f_lock_seq[SMB_OFILE_LSEQ_MAX];
1424 1433 } smb_ofile_t;
1425 1434
1426 1435 typedef struct smb_fileinfo {
1427 1436 char fi_name[MAXNAMELEN];
1428 1437 char fi_shortname[SMB_SHORTNAMELEN];
1429 1438 uint32_t fi_cookie; /* Dir offset (of next entry) */
1430 1439 uint32_t fi_dosattr; /* DOS attributes */
1431 1440 uint64_t fi_nodeid; /* file system node id */
1432 1441 uint64_t fi_size; /* file size in bytes */
1433 1442 uint64_t fi_alloc_size; /* allocation size in bytes */
1434 1443 timestruc_t fi_atime; /* last access */
1435 1444 timestruc_t fi_mtime; /* last modification */
1436 1445 timestruc_t fi_ctime; /* last status change */
1437 1446 timestruc_t fi_crtime; /* file creation */
1438 1447 } smb_fileinfo_t;
1439 1448
1440 1449 typedef struct smb_streaminfo {
1441 1450 uint64_t si_size;
1442 1451 uint64_t si_alloc_size;
1443 1452 char si_name[MAXPATHLEN];
1444 1453 } smb_streaminfo_t;
1445 1454
1446 1455 #define SMB_LOCK_MAGIC 0x4C4F434B /* 'LOCK' */
1447 1456
1448 1457 typedef struct smb_lock {
1449 1458 list_node_t l_lnd;
1450 1459 uint32_t l_magic;
1451 1460 kmutex_t l_mutex;
1452 1461 kcondvar_t l_cv;
1453 1462
1454 1463 smb_ofile_t *l_file;
1455 1464
1456 1465 struct smb_lock *l_blocked_by; /* Debug info only */
1457 1466
1458 1467 uint32_t l_conflicts;
1459 1468 uint32_t l_flags;
1460 1469 uint32_t l_pid;
1461 1470 uint32_t l_type;
1462 1471 uint64_t l_start;
1463 1472 uint64_t l_length;
1464 1473 clock_t l_end_time;
1465 1474 } smb_lock_t;
1466 1475
1467 1476 #define SMB_LOCK_FLAG_INDEFINITE 0x0004
1468 1477 #define SMB_LOCK_FLAG_CLOSED 0x0008
1469 1478 #define SMB_LOCK_FLAG_CANCELLED 0x0010
1470 1479
1471 1480 #define SMB_LOCK_TYPE_READWRITE 101
1472 1481 #define SMB_LOCK_TYPE_READONLY 102
1473 1482
1474 1483 typedef struct vardata_block {
1475 1484 uint8_t vdb_tag;
1476 1485 uint32_t vdb_len;
1477 1486 struct uio vdb_uio;
1478 1487 struct iovec vdb_iovec[MAX_IOVEC];
1479 1488 } smb_vdb_t;
1480 1489
1481 1490 #define SMB_WRMODE_WRITE_THRU 0x0001
1482 1491 #define SMB_WRMODE_IS_STABLE(M) ((M) & SMB_WRMODE_WRITE_THRU)
1483 1492
1484 1493 #define SMB_RW_MAGIC 0x52445257 /* 'RDRW' */
1485 1494
1486 1495 typedef struct smb_rw_param {
1487 1496 uint32_t rw_magic;
1488 1497 smb_vdb_t rw_vdb;
1489 1498 uint64_t rw_offset;
1490 1499 uint32_t rw_last_write;
1491 1500 uint16_t rw_mode;
1492 1501 uint32_t rw_count; /* bytes in this request */
1493 1502 uint16_t rw_mincnt;
1494 1503 uint32_t rw_total; /* total bytes (write-raw) */
1495 1504 uint16_t rw_dsoff; /* SMB data offset */
1496 1505 uint8_t rw_andx; /* SMB secondary andx command */
1497 1506 } smb_rw_param_t;
1498 1507
1499 1508 typedef struct smb_pathname {
1500 1509 char *pn_path;
1501 1510 char *pn_pname;
1502 1511 char *pn_fname;
1503 1512 char *pn_sname;
1504 1513 char *pn_stype;
1505 1514 } smb_pathname_t;
1506 1515
1507 1516 /*
1508 1517 * fs_query_info
1509 1518 */
1510 1519 typedef struct smb_fqi {
1511 1520 smb_pathname_t fq_path;
1512 1521 uint16_t fq_sattr;
1513 1522 smb_node_t *fq_dnode;
1514 1523 smb_node_t *fq_fnode;
1515 1524 smb_attr_t fq_fattr;
1516 1525 char fq_last_comp[MAXNAMELEN];
1517 1526 } smb_fqi_t;
1518 1527
1519 1528 typedef struct dirop {
1520 1529 smb_fqi_t fqi;
1521 1530 smb_fqi_t dst_fqi;
1522 1531 uint16_t info_level;
1523 1532 uint16_t flags;
1524 1533 } smb_arg_dirop_t;
1525 1534
1526 1535 typedef struct smb_queryinfo {
1527 1536 smb_node_t *qi_node; /* NULL for pipes */
1528 1537 uint8_t qi_InfoType;
1529 1538 uint8_t qi_InfoClass;
1530 1539 uint8_t qi_delete_on_close;
1531 1540 uint8_t qi_isdir;
1532 1541 uint32_t qi_AddlInfo;
1533 1542 uint32_t qi_Flags;
1534 1543 mbuf_chain_t in_data;
1535 1544 smb_attr_t qi_attr;
1536 1545 uint32_t qi_namelen;
1537 1546 char qi_shortname[SMB_SHORTNAMELEN];
1538 1547 char qi_name[MAXPATHLEN];
1539 1548 } smb_queryinfo_t;
1540 1549
1541 1550 typedef struct smb_setinfo {
1542 1551 smb_node_t *si_node;
1543 1552 mbuf_chain_t si_data;
1544 1553 smb_attr_t si_attr;
1545 1554 } smb_setinfo_t;
1546 1555
1547 1556 /*
1548 1557 * smb_fssize_t
1549 1558 * volume_units and volume avail are the total allocated and
1550 1559 * available units on the volume.
1551 1560 * caller_units and caller_avail are the allocated and available
1552 1561 * units on the volume for the user associated with the calling
1553 1562 * thread.
1554 1563 */
1555 1564 typedef struct smb_fssize {
1556 1565 uint64_t fs_volume_units;
1557 1566 uint64_t fs_volume_avail;
1558 1567 uint64_t fs_caller_units;
1559 1568 uint64_t fs_caller_avail;
1560 1569 uint32_t fs_sectors_per_unit;
1561 1570 uint32_t fs_bytes_per_sector;
1562 1571 } smb_fssize_t;
1563 1572
1564 1573 /*
1565 1574 * SMB FsCtl operations (SMB2 Ioctl, and some SMB1 trans calls)
1566 1575 */
1567 1576 typedef struct {
1568 1577 uint32_t CtlCode;
1569 1578 uint32_t InputCount;
1570 1579 uint32_t OutputCount;
1571 1580 uint32_t MaxOutputResp;
1572 1581 mbuf_chain_t *in_mbc;
1573 1582 mbuf_chain_t *out_mbc;
1574 1583 } smb_fsctl_t;
1575 1584
1576 1585 typedef struct {
1577 1586 uint64_t persistent;
1578 1587 uint64_t temporal;
1579 1588 } smb2fid_t;
1580 1589
1581 1590 typedef struct {
1582 1591 uint32_t status;
1583 1592 uint16_t errcls;
1584 1593 uint16_t errcode;
1585 1594 } smb_error_t;
1586 1595
1587 1596 typedef struct open_param {
1588 1597 smb_fqi_t fqi;
1589 1598 uint16_t omode;
1590 1599 uint16_t ofun;
1591 1600 uint32_t nt_flags;
1592 1601 uint32_t timeo;
1593 1602 uint32_t dattr;
1594 1603 timestruc_t crtime;
1595 1604 timestruc_t mtime;
1596 1605 timestruc_t timewarp;
1597 1606 /*
1598 1607 * Careful: dsize is the desired (allocation) size before the
1599 1608 * common open function, and the actual size afterwards.
1600 1609 */
1601 1610 uint64_t dsize; /* alloc size, actual size */
1602 1611 uint32_t desired_access;
1603 1612 uint32_t maximum_access;
1604 1613 uint32_t share_access;
1605 1614 uint32_t create_options;
1606 1615 uint32_t create_disposition;
1607 1616 boolean_t create_timewarp;
1608 1617 boolean_t created_readonly;
1609 1618 uint32_t ftype;
1610 1619 uint32_t devstate;
1611 1620 uint32_t action_taken;
1612 1621 uint64_t fileid;
1613 1622 uint32_t rootdirfid;
1614 1623 fsid_t op_fsid;
1615 1624 smb_ofile_t *dir;
1616 1625 smb_opipe_t *pipe; /* for smb_opipe_open */
1617 1626 struct smb_sd *sd; /* for NTTransactCreate */
1618 1627 void *create_ctx;
1619 1628
1620 1629 uint8_t op_oplock_level; /* requested/granted level */
1621 1630 uint32_t op_oplock_state; /* internal type+level */
1622 1631 uint32_t lease_state; /* SMB2_LEASE_... */
1623 1632 uint32_t lease_flags;
1624 1633 uint16_t lease_epoch;
1625 1634 uint16_t lease_version; /* 1 or 2 */
1626 1635 uint8_t lease_key[SMB_LEASE_KEY_SZ]; /* from client */
1627 1636 uint8_t parent_lease_key[SMB_LEASE_KEY_SZ]; /* for V2 */
1628 1637
1629 1638 smb_dh_vers_t dh_vers;
1630 1639 smb2fid_t dh_fileid; /* for durable reconnect */
1631 1640 uint8_t create_guid[16];
1632 1641 uint32_t dh_v2_flags;
1633 1642 uint32_t dh_timeout;
1634 1643 } smb_arg_open_t;
1635 1644
1636 1645 typedef struct smb_arg_lock {
1637 1646 void *lvec;
1638 1647 uint32_t lcnt;
1639 1648 uint32_t lseq;
1640 1649 } smb_arg_lock_t;
1641 1650
1642 1651 typedef struct smb_arg_olbrk {
1643 1652 uint32_t NewLevel;
1644 1653 boolean_t AckRequired;
1645 1654 } smb_arg_olbrk_t;
1646 1655
1647 1656 /*
1648 1657 * SMB Request State Machine
1649 1658 * -------------------------
1650 1659 *
1651 1660 * T4 +------+ T0
1652 1661 * +--------------------------->| FREE |---------------------------+
1653 1662 * | +------+ |
1654 1663 * +-----------+ |
1655 1664 * | COMPLETED | |
1656 1665 * +-----------+
1657 1666 * ^ |
1658 1667 * | T15 +-----------+ v
1659 1668 * +------------+ T6 | | +--------------+
1660 1669 * | CLEANED_UP |<-----------------| CANCELLED | | INITIALIZING |
1661 1670 * +------------+ | | +--------------+
1662 1671 * | ^ +-----------+ |
1663 1672 * | | ^ ^ ^ ^ |
1664 1673 * | | +-------------+ | | | |
1665 1674 * | | T3 | | | | T13 | T1
1666 1675 * | +-------------------------+ | | +----------------------+ |
1667 1676 * +----------------------------+ | | | | |
1668 1677 * T16 | | | | +-----------+ | |
1669 1678 * | \/ | | T5 | | v
1670 1679 * +-----------------+ | T12 +--------+ | T2 +-----------+
1671 1680 * | EVENT_OCCURRED |------------->| ACTIVE |<--------------------| SUBMITTED |
1672 1681 * +-----------------+ | +--------+ | +-----------+
1673 1682 * ^ | | ^ | |
1674 1683 * | | T8 | | | T7 |
1675 1684 * | T10 T9 | +----------+ | +-------+ | T11
1676 1685 * | | | +-------+ | |
1677 1686 * | | | T14 | | |
1678 1687 * | | v | v |
1679 1688 * +----------------------+ +--------------+
1680 1689 * | WAITING_EVENT | | WAITING_LOCK |
1681 1690 * +----------------------+ +--------------+
1682 1691 *
1683 1692 *
1684 1693 *
1685 1694 *
1686 1695 *
1687 1696 * Transition T0
1688 1697 *
1689 1698 * This transition occurs when the request is allocated and is still under the
1690 1699 * control of the session thread.
1691 1700 *
1692 1701 * Transition T1
1693 1702 *
1694 1703 * This transition occurs when the session thread dispatches a task to treat the
1695 1704 * request.
1696 1705 *
1697 1706 * Transition T2
1698 1707 *
1699 1708 *
1700 1709 *
1701 1710 * Transition T3
1702 1711 *
1703 1712 * A request completes and smbsr_cleanup is called to release resources
1704 1713 * associated with the request (but not the smb_request_t itself). This
1705 1714 * includes references on smb_ofile_t, smb_node_t, and other structures.
1706 1715 * CLEANED_UP state exists to detect if we attempt to cleanup a request
1707 1716 * multiple times and to allow us to detect that we are accessing a
1708 1717 * request that has already been cleaned up.
1709 1718 *
1710 1719 * Transition T4
1711 1720 *
1712 1721 *
1713 1722 *
1714 1723 * Transition T5
1715 1724 *
1716 1725 *
1717 1726 *
1718 1727 * Transition T6
1719 1728 *
1720 1729 *
1721 1730 *
1722 1731 * Transition T7
1723 1732 *
1724 1733 *
1725 1734 *
1726 1735 * Transition T8
1727 1736 *
1728 1737 *
1729 1738 *
1730 1739 * Transition T9
1731 1740 *
1732 1741 *
1733 1742 *
1734 1743 * Transition T10
1735 1744 *
1736 1745 *
1737 1746 *
1738 1747 * Transition T11
1739 1748 *
1740 1749 *
1741 1750 *
1742 1751 * Transition T12
1743 1752 *
1744 1753 *
1745 1754 *
1746 1755 * Transition T13
1747 1756 *
1748 1757 *
1749 1758 *
1750 1759 * Transition T14
1751 1760 *
1752 1761 *
1753 1762 *
1754 1763 * Transition T15
1755 1764 *
1756 1765 * Request processing is completed (control returns from smb_dispatch)
1757 1766 *
1758 1767 * Transition T16
1759 1768 *
1760 1769 * Multipart (andx) request was cleaned up with smbsr_cleanup but more "andx"
1761 1770 * sections remain to be processed.
1762 1771 *
1763 1772 */
1764 1773
1765 1774 #define SMB_REQ_MAGIC 0x534D4252 /* 'SMBR' */
1766 1775 #define SMB_REQ_VALID(p) ASSERT((p)->sr_magic == SMB_REQ_MAGIC)
1767 1776
1768 1777 typedef enum smb_req_state {
1769 1778 SMB_REQ_STATE_FREE = 0,
1770 1779 SMB_REQ_STATE_INITIALIZING,
1771 1780 SMB_REQ_STATE_SUBMITTED,
1772 1781 SMB_REQ_STATE_ACTIVE,
1773 1782 SMB_REQ_STATE_WAITING_AUTH,
1774 1783 SMB_REQ_STATE_WAITING_FCN1,
1775 1784 SMB_REQ_STATE_WAITING_FCN2,
1776 1785 SMB_REQ_STATE_WAITING_LOCK,
1777 1786 SMB_REQ_STATE_WAITING_PIPE,
1778 1787 SMB_REQ_STATE_COMPLETED,
1779 1788 SMB_REQ_STATE_CANCEL_PENDING,
1780 1789 SMB_REQ_STATE_CANCELLED,
1781 1790 SMB_REQ_STATE_CLEANED_UP,
1782 1791 SMB_REQ_STATE_SENTINEL
1783 1792 } smb_req_state_t;
1784 1793
1785 1794 typedef struct smb_request {
1786 1795 list_node_t sr_session_lnd;
1787 1796 uint32_t sr_magic;
1788 1797 kmutex_t sr_mutex;
1789 1798 smb_req_state_t sr_state;
1790 1799 struct smb_server *sr_server;
1791 1800 pid_t *sr_pid;
1792 1801 int32_t sr_gmtoff;
1793 1802 smb_session_t *session;
1794 1803 smb_kmod_cfg_t *sr_cfg;
1795 1804 void (*cancel_method)(struct smb_request *);
1796 1805 void *cancel_arg2;
1797 1806
1798 1807 /* Queue used by smb_request_append_postwork. */
1799 1808 struct smb_request *sr_postwork;
1800 1809
1801 1810 list_node_t sr_waiters; /* smb_notify.c */
1802 1811
1803 1812 /* Info from session service header */
1804 1813 uint32_t sr_req_length; /* Excluding NBT header */
1805 1814
1806 1815 /* Request buffer excluding NBT header */
1807 1816 void *sr_request_buf;
1808 1817
1809 1818 struct mbuf_chain command;
1810 1819 struct mbuf_chain reply;
1811 1820 struct mbuf_chain raw_data;
1812 1821 list_t sr_storage;
1813 1822 struct smb_xa *r_xa;
1814 1823 int andx_prev_wct;
1815 1824 int cur_reply_offset;
1816 1825 int orig_request_hdr;
1817 1826 unsigned int reply_seqnum; /* reply sequence number */
1818 1827 unsigned char first_smb_com; /* command code */
1819 1828 unsigned char smb_com; /* command code */
1820 1829
1821 1830 uint8_t smb_rcls; /* error code class */
1822 1831 uint8_t smb_reh; /* rsvd (AH DOS INT-24 ERR) */
1823 1832 uint16_t smb_err; /* error code */
1824 1833 smb_error_t smb_error;
1825 1834
1826 1835 uint8_t smb_flg; /* flags */
1827 1836 uint16_t smb_flg2; /* flags */
1828 1837 unsigned char smb_sig[8]; /* signiture */
1829 1838 uint16_t smb_tid; /* tree id # */
1830 1839 uint32_t smb_pid; /* caller's process id # */
1831 1840 uint16_t smb_uid; /* local (smb1) user id # */
1832 1841 uint16_t smb_mid; /* mutiplex id # */
1833 1842 unsigned char smb_wct; /* count of parameter words */
1834 1843 uint16_t smb_bcc; /* data byte count */
1835 1844
1836 1845 /*
1837 1846 * Beginning offsets (in the mbuf chain) for the
1838 1847 * command and reply headers, and the next reply.
1839 1848 */
1840 1849 uint32_t smb2_cmd_hdr;
1841 1850 uint32_t smb2_reply_hdr;
1842 1851 uint32_t smb2_next_reply;
1843 1852
1844 1853 /*
1845 1854 * SMB2 header fields. [MS-SMB2 2.2.1.2]
1846 1855 * XXX: Later do a union w smb1 members
1847 1856 */
1848 1857 uint16_t smb2_credit_charge;
1849 1858 uint16_t smb2_chan_seq; /* cmd only */
1850 1859 uint32_t smb2_status;
1851 1860 uint16_t smb2_cmd_code;
1852 1861 uint16_t smb2_credit_request;
1853 1862 uint16_t smb2_credit_response;
1854 1863 uint16_t smb2_total_credits; /* in compound */
1855 1864 uint32_t smb2_hdr_flags;
1856 1865 uint32_t smb2_next_command;
1857 1866 uint64_t smb2_messageid;
1858 1867 uint64_t smb2_first_msgid;
1859 1868 /* uint32_t smb2_pid; use smb_pid */
1860 1869 /* uint32_t smb2_tid; use smb_tid */
1861 1870 uint64_t smb2_ssnid; /* See u_ssnid */
1862 1871 uint8_t smb2_sig[16]; /* signature */
1863 1872
1864 1873 /*
1865 1874 * SMB3 transform header fields. [MS-SMB2 2.2.41]
1866 1875 */
1867 1876 uint64_t smb3_tform_ssnid;
1868 1877 smb_user_t *tform_ssn;
1869 1878 uint32_t msgsize;
1870 1879 uint8_t nonce[16];
1871 1880
1872 1881 boolean_t encrypted;
1873 1882 boolean_t dh_nvl_dirty;
1874 1883
1875 1884 boolean_t smb2_async;
1876 1885 uint64_t smb2_async_id;
1877 1886 /* Parameters */
1878 1887 struct mbuf_chain smb_vwv; /* variable width value */
1879 1888
1880 1889 /* Data */
1881 1890 struct mbuf_chain smb_data;
1882 1891
1883 1892 uint16_t smb_fid; /* not in hdr, but common */
1884 1893
1885 1894 unsigned char andx_com;
1886 1895 uint16_t andx_off;
1887 1896
1888 1897 struct smb_tree *tid_tree;
1889 1898 struct smb_ofile *fid_ofile;
1890 1899 smb_user_t *uid_user;
1891 1900
1892 1901 cred_t *user_cr;
1893 1902 kthread_t *sr_worker;
1894 1903 hrtime_t sr_time_submitted;
1895 1904 hrtime_t sr_time_active;
1896 1905 hrtime_t sr_time_start;
1897 1906 int32_t sr_txb;
1898 1907 uint32_t sr_seqnum;
1899 1908
1900 1909 union {
1901 1910 smb_arg_negotiate_t *negprot;
1902 1911 smb_arg_sessionsetup_t *ssetup;
1903 1912 smb_arg_tcon_t tcon;
1904 1913 smb_arg_dirop_t dirop;
1905 1914 smb_arg_open_t open;
1906 1915 smb_arg_lock_t lock;
1907 1916 smb_arg_olbrk_t olbrk; /* for async oplock break */
1908 1917 smb_rw_param_t *rw;
1909 1918 int32_t timestamp;
1910 1919 void *other;
1911 1920 } arg;
1912 1921 } smb_request_t;
1913 1922
1914 1923 #define sr_ssetup arg.ssetup
1915 1924 #define sr_negprot arg.negprot
1916 1925 #define sr_tcon arg.tcon
1917 1926 #define sr_dirop arg.dirop
1918 1927 #define sr_open arg.open
1919 1928 #define sr_rw arg.rw
1920 1929 #define sr_timestamp arg.timestamp
1921 1930
1922 1931 #define SMB_READ_PROTOCOL(hdr) \
1923 1932 LE_IN32(((smb_hdr_t *)(hdr))->protocol)
1924 1933
1925 1934 #define SMB_PROTOCOL_MAGIC_INVALID(rd_sr) \
1926 1935 (SMB_READ_PROTOCOL((rd_sr)->sr_request_buf) != SMB_PROTOCOL_MAGIC)
1927 1936
1928 1937 #define SMB_READ_COMMAND(hdr) \
1929 1938 (((smb_hdr_t *)(hdr))->command)
1930 1939
1931 1940 #define SMB_IS_NT_CANCEL(rd_sr) \
1932 1941 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NT_CANCEL)
1933 1942
1934 1943 #define SMB_IS_SESSION_SETUP_ANDX(rd_sr) \
1935 1944 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == \
1936 1945 SMB_COM_SESSION_SETUP_ANDX)
1937 1946
1938 1947 #define SMB_IS_NT_NEGOTIATE(rd_sr) \
1939 1948 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NEGOTIATE)
1940 1949
1941 1950 #define SMB_IS_TREE_CONNECT_ANDX(rd_sr) \
1942 1951 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_TREE_CONNECT_ANDX)
1943 1952
1944 1953 #define SMB_XA_FLAG_OPEN 0x0001
1945 1954 #define SMB_XA_FLAG_CLOSE 0x0002
1946 1955 #define SMB_XA_FLAG_COMPLETE 0x0004
1947 1956 #define SMB_XA_CLOSED(xa) (!((xa)->xa_flags & SMB_XA_FLAG_OPEN))
1948 1957
1949 1958 #define SMB_XA_MAGIC 0x534D4258 /* 'SMBX' */
1950 1959
1951 1960 typedef struct smb_xa {
1952 1961 list_node_t xa_lnd;
1953 1962 uint32_t xa_magic;
1954 1963 kmutex_t xa_mutex;
1955 1964
1956 1965 uint32_t xa_refcnt;
1957 1966 uint32_t xa_flags;
1958 1967
1959 1968 struct smb_session *xa_session;
1960 1969
1961 1970 unsigned char smb_com; /* which TRANS type */
1962 1971 unsigned char smb_flg; /* flags */
1963 1972 uint16_t smb_flg2; /* flags */
1964 1973 uint16_t smb_tid; /* tree id number */
1965 1974 uint32_t smb_pid; /* caller's process id */
1966 1975 uint16_t smb_uid; /* user id number */
1967 1976 uint32_t smb_func; /* NT_TRANS function */
1968 1977
1969 1978 uint16_t xa_smb_mid; /* mutiplex id number */
1970 1979 uint16_t xa_smb_fid; /* TRANS2 secondary */
1971 1980
1972 1981 unsigned int reply_seqnum; /* reply sequence number */
1973 1982
1974 1983 uint32_t smb_tpscnt; /* total parameter bytes being sent */
1975 1984 uint32_t smb_tdscnt; /* total data bytes being sent */
1976 1985 uint32_t smb_mprcnt; /* max parameter bytes to return */
1977 1986 uint32_t smb_mdrcnt; /* max data bytes to return */
1978 1987 uint32_t smb_msrcnt; /* max setup words to return */
1979 1988 uint32_t smb_flags; /* additional information: */
1980 1989 /* bit 0 - if set, disconnect TID in smb_tid */
1981 1990 /* bit 1 - if set, transaction is one way */
1982 1991 /* (no final response) */
1983 1992 int32_t smb_timeout; /* number of milliseconds to await completion */
1984 1993 uint32_t smb_suwcnt; /* set up word count */
1985 1994
1986 1995 char *xa_pipe_name;
1987 1996
1988 1997 /*
1989 1998 * These are the param and data count received so far,
1990 1999 * used to decide if the whole trans is here yet.
1991 2000 */
1992 2001 int req_disp_param;
1993 2002 int req_disp_data;
1994 2003
1995 2004 struct mbuf_chain req_setup_mb;
1996 2005 struct mbuf_chain req_param_mb;
1997 2006 struct mbuf_chain req_data_mb;
1998 2007
1999 2008 struct mbuf_chain rep_setup_mb;
2000 2009 struct mbuf_chain rep_param_mb;
2001 2010 struct mbuf_chain rep_data_mb;
2002 2011 } smb_xa_t;
2003 2012
2004 2013
2005 2014 #define SDDF_NO_FLAGS 0
2006 2015 #define SDDF_SUPPRESS_TID 0x0001
2007 2016 #define SDDF_SUPPRESS_UID 0x0002
2008 2017
2009 2018 /*
2010 2019 * SMB dispatch return codes.
2011 2020 */
2012 2021 typedef enum {
2013 2022 SDRC_SUCCESS = 0,
2014 2023 SDRC_ERROR,
2015 2024 SDRC_DROP_VC,
2016 2025 SDRC_NO_REPLY,
2017 2026 SDRC_SR_KEPT,
2018 2027 SDRC_NOT_IMPLEMENTED
2019 2028 } smb_sdrc_t;
2020 2029
2021 2030 #define VAR_BCC ((short)-1)
2022 2031
2023 2032 #define SMB_SERVER_MAGIC 0x53534552 /* 'SSER' */
2024 2033 #define SMB_SERVER_VALID(s) \
2025 2034 ASSERT(((s) != NULL) && ((s)->sv_magic == SMB_SERVER_MAGIC))
2026 2035
2027 2036 #define SMB_LISTENER_MAGIC 0x4C53544E /* 'LSTN' */
2028 2037 #define SMB_LISTENER_VALID(ld) \
2029 2038 ASSERT(((ld) != NULL) && ((ld)->ld_magic == SMB_LISTENER_MAGIC))
2030 2039
2031 2040 typedef struct {
2032 2041 uint32_t ld_magic;
2033 2042 struct smb_server *ld_sv;
2034 2043 smb_thread_t ld_thread;
2035 2044 ksocket_t ld_so;
2036 2045 in_port_t ld_port;
2037 2046 int ld_family;
2038 2047 struct sockaddr_in ld_sin;
2039 2048 struct sockaddr_in6 ld_sin6;
2040 2049 } smb_listener_daemon_t;
2041 2050
2042 2051 #define SMB_SSETUP_CMD "authentication"
2043 2052 #define SMB_TCON_CMD "share mapping"
2044 2053 #define SMB_OPIPE_CMD "pipe open"
2045 2054 #define SMB_THRESHOLD_REPORT_THROTTLE 50
2046 2055 typedef struct smb_cmd_threshold {
2047 2056 char *ct_cmd;
2048 2057 kmutex_t ct_mutex;
2049 2058 volatile uint32_t ct_active_cnt;
2050 2059 volatile uint32_t ct_blocked_cnt;
2051 2060 uint32_t ct_threshold;
2052 2061 uint32_t ct_timeout; /* milliseconds */
2053 2062 kcondvar_t ct_cond;
2054 2063 } smb_cmd_threshold_t;
2055 2064
2056 2065 typedef struct {
2057 2066 kstat_named_t ls_files;
2058 2067 kstat_named_t ls_trees;
2059 2068 kstat_named_t ls_users;
2060 2069 } smb_server_legacy_kstat_t;
2061 2070
2062 2071 typedef enum smb_server_state {
2063 2072 SMB_SERVER_STATE_CREATED = 0,
2064 2073 SMB_SERVER_STATE_CONFIGURED,
2065 2074 SMB_SERVER_STATE_RUNNING,
2066 2075 SMB_SERVER_STATE_STOPPING,
2067 2076 SMB_SERVER_STATE_DELETING,
2068 2077 SMB_SERVER_STATE_SENTINEL
2069 2078 } smb_server_state_t;
2070 2079
2071 2080 typedef struct {
2072 2081 /* protected by sv_mutex */
2073 2082 kcondvar_t sp_cv;
2074 2083 uint32_t sp_cnt;
2075 2084 smb_llist_t sp_list;
2076 2085 smb_llist_t sp_fidlist;
2077 2086 } smb_spool_t;
2078 2087
2079 2088 #define SMB_SERVER_STATE_VALID(S) \
2080 2089 ASSERT(((S) == SMB_SERVER_STATE_CREATED) || \
2081 2090 ((S) == SMB_SERVER_STATE_CONFIGURED) || \
2082 2091 ((S) == SMB_SERVER_STATE_RUNNING) || \
2083 2092 ((S) == SMB_SERVER_STATE_STOPPING) || \
2084 2093 ((S) == SMB_SERVER_STATE_DELETING))
2085 2094
2086 2095 typedef struct smb_server {
2087 2096 list_node_t sv_lnd;
2088 2097 uint32_t sv_magic;
2089 2098 kcondvar_t sv_cv;
2090 2099 kmutex_t sv_mutex;
2091 2100 smb_server_state_t sv_state;
2092 2101 uint32_t sv_refcnt;
2093 2102 pid_t sv_pid;
2094 2103 zoneid_t sv_zid;
2095 2104 smb_listener_daemon_t sv_nbt_daemon;
2096 2105 smb_listener_daemon_t sv_tcp_daemon;
2097 2106 krwlock_t sv_cfg_lock;
2098 2107 smb_kmod_cfg_t sv_cfg;
2099 2108 smb_session_t *sv_session;
2100 2109 smb_user_t *sv_rootuser;
2101 2110 smb_llist_t sv_session_list;
2102 2111 smb_hash_t *sv_persistid_ht;
2103 2112 smb_hash_t *sv_lease_ht;
2104 2113
2105 2114 smb_export_t sv_export;
2106 2115 struct __door_handle *sv_lmshrd;
2107 2116
2108 2117 /* Internal door for up-calls to smbd */
2109 2118 struct __door_handle *sv_kdoor_hd;
2110 2119 int sv_kdoor_id; /* init -1 */
2111 2120 uint64_t sv_kdoor_ncall;
2112 2121 kmutex_t sv_kdoor_mutex;
2113 2122 kcondvar_t sv_kdoor_cv;
2114 2123
2115 2124 int32_t si_gmtoff;
2116 2125
2117 2126 smb_thread_t si_thread_timers;
2118 2127
2119 2128 taskq_t *sv_worker_pool;
2120 2129 taskq_t *sv_receiver_pool;
2121 2130
2122 2131 smb_node_t *si_root_smb_node;
2123 2132 smb_llist_t sv_opipe_list;
2124 2133 smb_llist_t sv_event_list;
2125 2134
2126 2135 /* Statistics */
2127 2136 hrtime_t sv_start_time;
2128 2137 kstat_t *sv_ksp;
2129 2138 volatile uint32_t sv_nbt_sess;
2130 2139 volatile uint32_t sv_tcp_sess;
2131 2140 volatile uint32_t sv_users;
2132 2141 volatile uint32_t sv_trees;
2133 2142 volatile uint32_t sv_files;
2134 2143 volatile uint32_t sv_pipes;
2135 2144 volatile uint64_t sv_txb;
2136 2145 volatile uint64_t sv_rxb;
2137 2146 volatile uint64_t sv_nreq;
2138 2147 smb_srqueue_t sv_srqueue;
2139 2148 smb_spool_t sp_info;
2140 2149 smb_cmd_threshold_t sv_ssetup_ct;
2141 2150 smb_cmd_threshold_t sv_tcon_ct;
2142 2151 smb_cmd_threshold_t sv_opipe_ct;
2143 2152 kstat_t *sv_legacy_ksp;
2144 2153 kmutex_t sv_legacy_ksmtx;
2145 2154 smb_disp_stats_t *sv_disp_stats1;
2146 2155 smb_disp_stats_t *sv_disp_stats2;
2147 2156 } smb_server_t;
2148 2157
2149 2158 #define SMB_EVENT_MAGIC 0x45564E54 /* EVNT */
2150 2159 #define SMB_EVENT_TIMEOUT 45 /* seconds */
2151 2160 #define SMB_EVENT_VALID(e) \
2152 2161 ASSERT(((e) != NULL) && ((e)->se_magic == SMB_EVENT_MAGIC))
2153 2162 typedef struct smb_event {
2154 2163 list_node_t se_lnd;
2155 2164 uint32_t se_magic;
2156 2165 kmutex_t se_mutex;
2157 2166 kcondvar_t se_cv;
2158 2167 smb_server_t *se_server;
2159 2168 uint32_t se_txid;
2160 2169 boolean_t se_notified;
2161 2170 int se_waittime;
2162 2171 int se_timeout;
2163 2172 int se_errno;
2164 2173 } smb_event_t;
2165 2174
2166 2175 typedef struct smb_kspooldoc {
2167 2176 list_node_t sd_lnd;
2168 2177 uint32_t sd_magic;
2169 2178 smb_inaddr_t sd_ipaddr;
2170 2179 uint32_t sd_spool_num;
2171 2180 uint16_t sd_fid;
2172 2181 char sd_username[MAXNAMELEN];
2173 2182 char sd_path[MAXPATHLEN];
2174 2183 } smb_kspooldoc_t;
2175 2184
2176 2185 typedef struct smb_spoolfid {
2177 2186 list_node_t sf_lnd;
2178 2187 uint32_t sf_magic;
2179 2188 uint16_t sf_fid;
2180 2189 } smb_spoolfid_t;
2181 2190
2182 2191 #define SMB_INFO_NETBIOS_SESSION_SVC_RUNNING 0x0001
2183 2192 #define SMB_INFO_NETBIOS_SESSION_SVC_FAILED 0x0002
2184 2193 #define SMB_INFO_USER_LEVEL_SECURITY 0x40000000
2185 2194 #define SMB_INFO_ENCRYPT_PASSWORDS 0x80000000
2186 2195
2187 2196 #define SMB_IS_STREAM(node) ((node)->n_unode)
2188 2197
2189 2198 typedef struct smb_tsd {
2190 2199 void (*proc)();
2191 2200 void *arg;
2192 2201 char name[100];
2193 2202 } smb_tsd_t;
2194 2203
2195 2204 typedef struct smb_disp_entry {
2196 2205 char sdt_name[KSTAT_STRLEN];
2197 2206 smb_sdrc_t (*sdt_pre_op)(smb_request_t *);
2198 2207 smb_sdrc_t (*sdt_function)(smb_request_t *);
2199 2208 void (*sdt_post_op)(smb_request_t *);
2200 2209 uint8_t sdt_com;
2201 2210 char sdt_dialect;
2202 2211 uint8_t sdt_flags;
2203 2212 } smb_disp_entry_t;
2204 2213
2205 2214 typedef struct smb_xlate {
2206 2215 int code;
2207 2216 char *str;
2208 2217 } smb_xlate_t;
2209 2218
2210 2219 /*
2211 2220 * This structure is a helper for building RAP NetShareEnum response
2212 2221 *
2213 2222 * es_posix_uid UID of the user requesting the shares list which
2214 2223 * is used to detect if the user has any autohome
2215 2224 * es_bufsize size of the response buffer
2216 2225 * es_buf pointer to the response buffer
2217 2226 * es_ntotal total number of shares exported by server which
2218 2227 * their OEM names is less then 13 chars
2219 2228 * es_nsent number of shares that can fit in the specified buffer
2220 2229 * es_datasize actual data size (share's data) which was encoded
2221 2230 * in the response buffer
2222 2231 */
2223 2232 typedef struct smb_enumshare_info {
2224 2233 uid_t es_posix_uid;
2225 2234 uint16_t es_bufsize;
2226 2235 char *es_buf;
2227 2236 uint16_t es_ntotal;
2228 2237 uint16_t es_nsent;
2229 2238 uint16_t es_datasize;
2230 2239 } smb_enumshare_info_t;
2231 2240
2232 2241 #ifdef __cplusplus
2233 2242 }
2234 2243 #endif
2235 2244
2236 2245 #endif /* _SMBSRV_SMB_KTYPES_H */
↓ open down ↓ |
1248 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX