1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 /* 26 * Structures and type definitions for the SMB module. 27 */ 28 29 #ifndef _SMBSRV_SMB_KTYPES_H 30 #define _SMBSRV_SMB_KTYPES_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <sys/note.h> 37 #include <sys/systm.h> 38 #include <sys/param.h> 39 #include <sys/types.h> 40 #include <sys/synch.h> 41 #include <sys/taskq.h> 42 #include <sys/socket.h> 43 #include <sys/acl.h> 44 #include <sys/sdt.h> 45 #include <sys/stat.h> 46 #include <sys/vnode.h> 47 #include <sys/cred.h> 48 #include <netinet/in.h> 49 #include <sys/ksocket.h> 50 #include <sys/fem.h> 51 #include <sys/door.h> 52 #include <sys/extdirent.h> 53 #include <smbsrv/smb.h> 54 #include <smbsrv/smbinfo.h> 55 #include <smbsrv/mbuf.h> 56 #include <smbsrv/smb_sid.h> 57 #include <smbsrv/smb_xdr.h> 58 #include <smbsrv/netbios.h> 59 #include <smbsrv/smb_vops.h> 60 #include <smbsrv/smb_kstat.h> 61 62 struct smb_disp_entry; 63 struct smb_request; 64 struct smb_server; 65 struct smb_event; 66 67 /* 68 * Accumulated time and queue length statistics. 69 * 70 * Accumulated time statistics are kept as a running sum of "active" time. 71 * Queue length statistics are kept as a running sum of the product of queue 72 * length and elapsed time at that length -- i.e., a Riemann sum for queue 73 * length integrated against time. (You can also think of the active time as a 74 * Riemann sum, for the boolean function (queue_length > 0) integrated against 75 * time, or you can think of it as the Lebesgue measure of the set on which 76 * queue_length > 0.) 77 * 78 * ^ 79 * | _________ 80 * 8 | i4 | 81 * | | | 82 * Queue 6 | | 83 * Length | _________ | | 84 * 4 | i2 |_______| | 85 * | | i3 | 86 * 2_______| | 87 * | i1 | 88 * |_______________________________| 89 * Time-> t1 t2 t3 t4 90 * 91 * At each change of state (entry or exit from the queue), we add the elapsed 92 * time (since the previous state change) to the active time if the queue length 93 * was non-zero during that interval; and we add the product of the elapsed time 94 * times the queue length to the running length*time sum. 95 * 96 * This method is generalizable to measuring residency in any defined system: 97 * instead of queue lengths, think of "outstanding RPC calls to server X". 98 * 99 * A large number of I/O subsystems have at least two basic "lists" of 100 * transactions they manage: one for transactions that have been accepted for 101 * processing but for which processing has yet to begin, and one for 102 * transactions which are actively being processed (but not done). For this 103 * reason, two cumulative time statistics are defined here: wait (pre-service) 104 * time, and run (service) time. 105 * 106 * All times are 64-bit nanoseconds (hrtime_t), as returned by gethrtime(). 107 * 108 * The units of cumulative busy time are accumulated nanoseconds. The units of 109 * cumulative length*time products are elapsed time times queue length. 110 * 111 * Updates to the fields below are performed implicitly by calls to 112 * these functions: 113 * 114 * smb_srqueue_init() 115 * smb_srqueue_destroy() 116 * smb_srqueue_waitq_enter() 117 * smb_srqueue_runq_exit() 118 * smb_srqueue_waitq_to_runq() 119 * smb_srqueue_update() 120 * 121 * These fields should never be updated by any other means. 122 */ 123 typedef struct smb_srqueue { 124 kmutex_t srq_mutex; 125 hrtime_t srq_wlastupdate; 126 hrtime_t srq_wtime; 127 hrtime_t srq_wlentime; 128 hrtime_t srq_rlastupdate; 129 hrtime_t srq_rtime; 130 hrtime_t srq_rlentime; 131 uint32_t srq_wcnt; 132 uint32_t srq_rcnt; 133 } smb_srqueue_t; 134 135 /* 136 * The fields with the prefix 'ly_a' contain the statistics collected since the 137 * server was last started ('a' for 'aggregated'). The fields with the prefix 138 * 'ly_d' contain the statistics collected since the last snapshot ('d' for 139 * 'delta'). 140 */ 141 typedef struct smb_latency { 142 kmutex_t ly_mutex; 143 uint64_t ly_a_nreq; 144 hrtime_t ly_a_sum; 145 hrtime_t ly_a_mean; 146 hrtime_t ly_a_stddev; 147 uint64_t ly_d_nreq; 148 hrtime_t ly_d_sum; 149 hrtime_t ly_d_mean; 150 hrtime_t ly_d_stddev; 151 } smb_latency_t; 152 153 int smb_noop(void *, size_t, int); 154 155 #define SMB_AUDIT_STACK_DEPTH 16 156 #define SMB_AUDIT_BUF_MAX_REC 16 157 #define SMB_AUDIT_NODE 0x00000001 158 159 /* 160 * Maximum number of records returned in SMBsearch, SMBfind 161 * and SMBfindunique response. Value set to 10 for compatibility 162 * with Windows. 163 */ 164 #define SMB_MAX_SEARCH 10 165 166 #define SMB_SEARCH_ATTRIBUTES \ 167 (FILE_ATTRIBUTE_HIDDEN | \ 168 FILE_ATTRIBUTE_SYSTEM | \ 169 FILE_ATTRIBUTE_DIRECTORY) 170 171 #define SMB_SEARCH_HIDDEN(sattr) ((sattr) & FILE_ATTRIBUTE_HIDDEN) 172 #define SMB_SEARCH_SYSTEM(sattr) ((sattr) & FILE_ATTRIBUTE_SYSTEM) 173 #define SMB_SEARCH_DIRECTORY(sattr) ((sattr) & FILE_ATTRIBUTE_DIRECTORY) 174 #define SMB_SEARCH_ALL(sattr) ((sattr) & SMB_SEARCH_ATTRIBUTES) 175 176 typedef struct { 177 uint32_t anr_refcnt; 178 int anr_depth; 179 pc_t anr_stack[SMB_AUDIT_STACK_DEPTH]; 180 } smb_audit_record_node_t; 181 182 typedef struct { 183 int anb_index; 184 int anb_max_index; 185 smb_audit_record_node_t anb_records[SMB_AUDIT_BUF_MAX_REC]; 186 } smb_audit_buf_node_t; 187 188 #define SMB_WORKER_PRIORITY 99 189 /* 190 * Thread State Machine 191 * -------------------- 192 * 193 * T5 T0 194 * smb_thread_destroy() <-------+ +------- smb_thread_init() 195 * | | 196 * | v 197 * +-----------------------------+ 198 * | SMB_THREAD_STATE_EXITED |<---+ 199 * +-----------------------------+ | 200 * | T1 | 201 * v | 202 * +-----------------------------+ | 203 * | SMB_THREAD_STATE_STARTING | | 204 * +-----------------------------+ | 205 * | T2 | T4 206 * v | 207 * +-----------------------------+ | 208 * | SMB_THREAD_STATE_RUNNING | | 209 * +-----------------------------+ | 210 * | T3 | 211 * v | 212 * +-----------------------------+ | 213 * | SMB_THREAD_STATE_EXITING |----+ 214 * +-----------------------------+ 215 * 216 * Transition T0 217 * 218 * This transition is executed in smb_thread_init(). 219 * 220 * Transition T1 221 * 222 * This transition is executed in smb_thread_start(). 223 * 224 * Transition T2 225 * 226 * This transition is executed by the thread itself when it starts running. 227 * 228 * Transition T3 229 * 230 * This transition is executed by the thread itself in 231 * smb_thread_entry_point() just before calling thread_exit(). 232 * 233 * 234 * Transition T4 235 * 236 * This transition is executed in smb_thread_stop(). 237 * 238 * Transition T5 239 * 240 * This transition is executed in smb_thread_destroy(). 241 */ 242 typedef enum smb_thread_state { 243 SMB_THREAD_STATE_STARTING = 0, 244 SMB_THREAD_STATE_RUNNING, 245 SMB_THREAD_STATE_EXITING, 246 SMB_THREAD_STATE_EXITED 247 } smb_thread_state_t; 248 249 struct _smb_thread; 250 251 typedef void (*smb_thread_ep_t)(struct _smb_thread *, void *ep_arg); 252 253 #define SMB_THREAD_MAGIC 0x534D4254 /* SMBT */ 254 255 typedef struct _smb_thread { 256 uint32_t sth_magic; 257 char sth_name[16]; 258 smb_thread_state_t sth_state; 259 kthread_t *sth_th; 260 kt_did_t sth_did; 261 smb_thread_ep_t sth_ep; 262 void *sth_ep_arg; 263 boolean_t sth_kill; 264 kmutex_t sth_mtx; 265 kcondvar_t sth_cv; 266 } smb_thread_t; 267 268 /* 269 * Pool of IDs 270 * ----------- 271 * 272 * A pool of IDs is a pool of 16 bit numbers. It is implemented as a bitmap. 273 * A bit set to '1' indicates that that particular value has been allocated. 274 * The allocation process is done shifting a bit through the whole bitmap. 275 * The current position of that index bit is kept in the smb_idpool_t 276 * structure and represented by a byte index (0 to buffer size minus 1) and 277 * a bit index (0 to 7). 278 * 279 * The pools start with a size of 8 bytes or 64 IDs. Each time the pool runs 280 * out of IDs its current size is doubled until it reaches its maximum size 281 * (8192 bytes or 65536 IDs). The IDs 0 and 65535 are never given out which 282 * means that a pool can have a maximum number of 65534 IDs available. 283 */ 284 #define SMB_IDPOOL_MAGIC 0x4944504C /* IDPL */ 285 #define SMB_IDPOOL_MIN_SIZE 64 /* Number of IDs to begin with */ 286 #define SMB_IDPOOL_MAX_SIZE 64 * 1024 287 288 typedef struct smb_idpool { 289 uint32_t id_magic; 290 kmutex_t id_mutex; 291 uint8_t *id_pool; 292 uint32_t id_size; 293 uint8_t id_bit; 294 uint8_t id_bit_idx; 295 uint32_t id_idx; 296 uint32_t id_idx_msk; 297 uint32_t id_free_counter; 298 uint32_t id_max_free_counter; 299 } smb_idpool_t; 300 301 /* 302 * Maximum size of a Transport Data Unit when CAP_LARGE_READX and 303 * CAP_LARGE_WRITEX are not set. CAP_LARGE_READX/CAP_LARGE_WRITEX 304 * allow the payload to exceed the negotiated buffer size. 305 * 4 --> NBT/TCP Transport Header. 306 * 32 --> SMB Header 307 * 1 --> Word Count byte 308 * 510 --> Maximum Number of bytes of the Word Table (2 * 255) 309 * 2 --> Byte count of the data 310 * 65535 --> Maximum size of the data 311 * ----- 312 * 66084 313 */ 314 #define SMB_REQ_MAX_SIZE 66560 /* 65KB */ 315 #define SMB_XPRT_MAX_SIZE (SMB_REQ_MAX_SIZE + NETBIOS_HDR_SZ) 316 317 #define SMB_TXREQ_MAGIC 0X54524251 /* 'TREQ' */ 318 typedef struct { 319 uint32_t tr_magic; 320 list_node_t tr_lnd; 321 int tr_len; 322 uint8_t tr_buf[SMB_XPRT_MAX_SIZE]; 323 } smb_txreq_t; 324 325 #define SMB_TXLST_MAGIC 0X544C5354 /* 'TLST' */ 326 typedef struct { 327 uint32_t tl_magic; 328 kmutex_t tl_mutex; 329 boolean_t tl_active; 330 list_t tl_list; 331 } smb_txlst_t; 332 333 /* 334 * Maximum buffer size for NT is 37KB. If all clients are Windows 2000, this 335 * can be changed to 64KB. 37KB must be used with a mix of NT/Windows 2000 336 * clients because NT loses directory entries when values greater than 37KB are 337 * used. 338 * 339 * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to 340 * account for the NBT header. 341 */ 342 #define NBT_MAXBUF 8 343 #define SMB_NT_MAXBUF (37 * 1024) 344 345 #define OUTBUFSIZE (65 * 1024) 346 #define SMBHEADERSIZE 32 347 #define SMBND_HASH_MASK (0xFF) 348 #define MAX_IOVEC 512 349 #define MAX_READREF (8 * 1024) 350 351 #define SMB_WORKER_MIN 4 352 #define SMB_WORKER_DEFAULT 64 353 #define SMB_WORKER_MAX 1024 354 355 /* 356 * Destructor object used in the locked-list delete queue. 357 */ 358 #define SMB_DTOR_MAGIC 0x44544F52 /* DTOR */ 359 #define SMB_DTOR_VALID(d) \ 360 ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC)) 361 362 typedef void (*smb_dtorproc_t)(void *); 363 364 typedef struct smb_dtor { 365 uint32_t dt_magic; 366 list_node_t dt_lnd; 367 void *dt_object; 368 smb_dtorproc_t dt_proc; 369 } smb_dtor_t; 370 371 typedef struct smb_llist { 372 krwlock_t ll_lock; 373 list_t ll_list; 374 uint32_t ll_count; 375 uint64_t ll_wrop; 376 kmutex_t ll_mutex; 377 list_t ll_deleteq; 378 uint32_t ll_deleteq_count; 379 boolean_t ll_flushing; 380 } smb_llist_t; 381 382 typedef struct smb_slist { 383 kmutex_t sl_mutex; 384 kcondvar_t sl_cv; 385 list_t sl_list; 386 uint32_t sl_count; 387 boolean_t sl_waiting; 388 } smb_slist_t; 389 390 /* 391 * smb_avl_t State Machine 392 * -------------------- 393 * 394 * +-----------------------------+ 395 * | SMB_AVL_STATE_START | 396 * +-----------------------------+ 397 * | T0 398 * v 399 * +-----------------------------+ 400 * | SMB_AVL_STATE_READY | 401 * +-----------------------------+ 402 * | T1 403 * v 404 * +-----------------------------+ 405 * | SMB_AVL_STATE_DESTROYING | 406 * +-----------------------------+ 407 * 408 * Transition T0 409 * 410 * This transition is executed in smb_avl_create(). 411 * 412 * Transition T1 413 * 414 * This transition is executed in smb_avl_destroy(). 415 * 416 */ 417 typedef enum { 418 SMB_AVL_STATE_START = 0, 419 SMB_AVL_STATE_READY, 420 SMB_AVL_STATE_DESTROYING 421 } smb_avl_state_t; 422 423 typedef struct smb_avl_nops { 424 int (*avln_cmp) (const void *, const void *); 425 void (*avln_hold)(const void *); 426 boolean_t (*avln_rele)(const void *); 427 void (*avln_destroy)(void *); 428 } smb_avl_nops_t; 429 430 typedef struct smb_avl_cursor { 431 void *avlc_next; 432 uint32_t avlc_sequence; 433 } smb_avl_cursor_t; 434 435 typedef struct smb_avl { 436 krwlock_t avl_lock; 437 avl_tree_t avl_tree; 438 kmutex_t avl_mutex; 439 kcondvar_t avl_cv; 440 smb_avl_state_t avl_state; 441 uint32_t avl_refcnt; 442 uint32_t avl_sequence; 443 smb_avl_nops_t *avl_nops; 444 } smb_avl_t; 445 446 typedef struct { 447 kcondvar_t rwx_cv; 448 kmutex_t rwx_mutex; 449 krwlock_t rwx_lock; 450 boolean_t rwx_waiting; 451 } smb_rwx_t; 452 453 /* NOTIFY CHANGE */ 454 455 typedef struct smb_notify_change_req { 456 list_node_t nc_lnd; 457 struct smb_node *nc_node; 458 uint32_t nc_reply_type; 459 uint32_t nc_flags; 460 } smb_notify_change_req_t; 461 462 /* 463 * SMB operates over a NetBIOS-over-TCP transport (NBT) or directly 464 * over TCP, which is also known as direct hosted NetBIOS-less SMB 465 * or SMB-over-TCP. 466 * 467 * NBT messages have a 4-byte header that defines the message type 468 * (8-bits), a 7-bit flags field and a 17-bit length. 469 * 470 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 471 * | TYPE | FLAGS |E| LENGTH | 472 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 473 * 474 * 8-bit type Defined in RFC 1002 475 * 7-bit flags Bits 0-6 reserved (must be 0) 476 * Bit 7: Length extension bit (E) 477 * 17-bit length Includes bit 7 of the flags byte 478 * 479 * 480 * SMB-over-TCP is defined to use a modified version of the NBT header 481 * containing an 8-bit message type and 24-bit message length. 482 * 483 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 484 * | TYPE | LENGTH | 485 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 486 * 487 * 8-bit type Must be 0 488 * 24-bit length 489 * 490 * The following structure is used to represent a generic, in-memory 491 * SMB transport header; it is not intended to map directly to either 492 * of the over-the-wire formats. 493 */ 494 typedef struct { 495 uint8_t xh_type; 496 uint32_t xh_length; 497 } smb_xprt_t; 498 499 int MBC_LENGTH(struct mbuf_chain *); 500 int MBC_MAXBYTES(struct mbuf_chain *); 501 void MBC_SETUP(struct mbuf_chain *, uint32_t); 502 void MBC_INIT(struct mbuf_chain *, uint32_t); 503 void MBC_FLUSH(struct mbuf_chain *); 504 void MBC_ATTACH_MBUF(struct mbuf_chain *, struct mbuf *); 505 void MBC_APPEND_MBUF(struct mbuf_chain *, struct mbuf *); 506 void MBC_ATTACH_BUF(struct mbuf_chain *MBC, unsigned char *BUF, int LEN); 507 int MBC_SHADOW_CHAIN(struct mbuf_chain *SUBMBC, struct mbuf_chain *MBC, 508 int OFF, int LEN); 509 510 #define MBC_ROOM_FOR(b, n) (((b)->chain_offset + (n)) <= (b)->max_bytes) 511 512 #define OPLOCK_MIN_TIMEOUT (5 * 1000) 513 #define OPLOCK_STD_TIMEOUT (30 * 1000) 514 515 /* 516 * Oplock break flags: 517 * SMB_OPLOCK_BREAK_EXCLUSIVE - only break exclusive oplock 518 * (type SMB_OPLOCK_EXCLUSIVE or SMB_OPLOCK_BATCH) 519 * SMB_OPLOCK_BREAK_BATCH - only break exclusive BATCH oplock 520 * SMB_OPLOCK_BREAK_NOWAIT - do not wait for oplock break ack 521 */ 522 #define SMB_OPLOCK_NO_BREAK 0x00 523 #define SMB_OPLOCK_BREAK_TO_NONE 0x01 524 #define SMB_OPLOCK_BREAK_TO_LEVEL_II 0x02 525 #define SMB_OPLOCK_BREAK_EXCLUSIVE 0x04 526 #define SMB_OPLOCK_BREAK_BATCH 0x08 527 #define SMB_OPLOCK_BREAK_NOWAIT 0x10 528 529 /* 530 * Oplocks levels are defined to match the levels in the SMB 531 * protocol (nt_create_andx / nt_transact_create) and should 532 * not be changed 533 */ 534 #define SMB_OPLOCK_NONE 0 535 #define SMB_OPLOCK_EXCLUSIVE 1 536 #define SMB_OPLOCK_BATCH 2 537 #define SMB_OPLOCK_LEVEL_II 3 538 539 typedef struct smb_oplock { 540 kmutex_t ol_mutex; 541 kcondvar_t ol_cv; 542 kthread_t *ol_xthread; 543 boolean_t ol_fem; /* fem monitor installed? */ 544 uint8_t ol_break; 545 uint32_t ol_count; /* number of grants */ 546 list_t ol_grants; /* list of smb_oplock_grant_t */ 547 } smb_oplock_t; 548 549 #define SMB_OPLOCK_GRANT_MAGIC 0x4F4C4B47 /* OLKG */ 550 #define SMB_OPLOCK_GRANT_VALID(p) \ 551 ASSERT((p)->og_magic == SMB_OPLOCK_GRANT_MAGIC) 552 #define SMB_OFILE_OPLOCK_GRANTED(p) \ 553 ((p)->f_oplock_grant.og_magic == SMB_OPLOCK_GRANT_MAGIC) 554 typedef struct smb_oplock_grant { 555 uint32_t og_magic; 556 list_node_t og_lnd; 557 uint8_t og_level; 558 uint16_t og_fid; 559 uint16_t og_tid; 560 uint16_t og_uid; 561 struct smb_session *og_session; 562 struct smb_ofile *og_ofile; 563 } smb_oplock_grant_t; 564 565 #define SMB_OPLOCK_BREAK_MAGIC 0x4F4C4B42 /* OLKB */ 566 #define SMB_OPLOCK_BREAK_VALID(p) \ 567 ASSERT((p)->ob_magic == SMB_OPLOCK_BREAK_MAGIC) 568 typedef struct smb_oplock_break { 569 uint32_t ob_magic; 570 list_node_t ob_lnd; 571 struct smb_node *ob_node; 572 } smb_oplock_break_t; 573 574 575 #define SMB_VFS_MAGIC 0x534D4256 /* 'SMBV' */ 576 577 typedef struct smb_vfs { 578 uint32_t sv_magic; 579 list_node_t sv_lnd; 580 uint32_t sv_refcnt; 581 vfs_t *sv_vfsp; 582 vnode_t *sv_rootvp; 583 } smb_vfs_t; 584 585 /* 586 * Solaris file systems handle timestamps differently from NTFS. 587 * In order to provide a more similar view of an open file's 588 * timestamps, we cache the timestamps in the node and manipulate 589 * them in a manner more consistent with windows. 590 * t_cached is B_TRUE when timestamps are cached. 591 * Timestamps remain cached while there are open ofiles for the node. 592 * This includes open ofiles for named streams. t_open_ofiles is a 593 * count of open ofiles on the node, including named streams' ofiles, 594 * n_open_count cannot be used as it doesn't include ofiles opened 595 * for the node's named streams. 596 */ 597 typedef struct smb_times { 598 uint32_t t_open_ofiles; 599 boolean_t t_cached; 600 timestruc_t t_atime; 601 timestruc_t t_mtime; 602 timestruc_t t_ctime; 603 timestruc_t t_crtime; 604 } smb_times_t; 605 606 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */ 607 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC) 608 609 typedef enum { 610 SMB_NODE_STATE_AVAILABLE = 0, 611 SMB_NODE_STATE_DESTROYING 612 } smb_node_state_t; 613 614 /* 615 * waiting_event # of clients requesting FCN 616 * n_timestamps cached timestamps 617 * n_allocsz cached file allocation size 618 * n_dnode directory node 619 * n_unode unnamed stream node 620 * delete_on_close_cred credentials for delayed delete 621 */ 622 typedef struct smb_node { 623 uint32_t n_magic; 624 krwlock_t n_lock; 625 kmutex_t n_mutex; 626 list_node_t n_lnd; 627 smb_node_state_t n_state; 628 uint32_t n_refcnt; 629 uint32_t n_hashkey; 630 smb_llist_t *n_hash_bucket; 631 uint32_t n_open_count; 632 uint32_t n_opening_count; 633 smb_llist_t n_ofile_list; 634 smb_llist_t n_lock_list; 635 struct smb_ofile *readonly_creator; 636 volatile int flags; 637 volatile int waiting_event; 638 smb_times_t n_timestamps; 639 u_offset_t n_allocsz; 640 smb_oplock_t n_oplock; 641 struct smb_node *n_dnode; 642 struct smb_node *n_unode; 643 cred_t *delete_on_close_cred; 644 uint32_t n_delete_on_close_flags; 645 char od_name[MAXNAMELEN]; 646 vnode_t *vp; 647 smb_audit_buf_node_t *n_audit_buf; 648 } smb_node_t; 649 650 #define NODE_FLAGS_REPARSE 0x00001000 651 #define NODE_FLAGS_DFSLINK 0x00002000 652 #define NODE_FLAGS_VFSROOT 0x00004000 653 #define NODE_FLAGS_SYSTEM 0x00008000 654 #define NODE_FLAGS_WATCH_TREE 0x10000000 655 #define NODE_FLAGS_NOTIFY_CHANGE \ 656 (NODE_FLAGS_WATCH_TREE | FILE_NOTIFY_VALID_MASK) 657 #define NODE_FLAGS_CHANGED 0x08000000 658 #define NODE_FLAGS_WRITE_THROUGH 0x00100000 659 #define NODE_XATTR_DIR 0x01000000 660 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000 661 #define NODE_FLAGS_EXECUTABLE 0x80000000 662 663 #define SMB_NODE_VFS(node) ((node)->vp->v_vfsp) 664 #define SMB_NODE_FSID(node) ((node)->vp->v_vfsp->vfs_fsid) 665 666 /* Maximum buffer size for encryption key */ 667 #define SMB_ENCRYPT_KEY_MAXLEN 32 668 669 #define SMB_SHARE_MAGIC 0x4B534852 /* KSHR */ 670 671 typedef struct smb_kshare { 672 uint32_t shr_magic; 673 char *shr_name; 674 char *shr_path; 675 char *shr_cmnt; 676 char *shr_container; 677 char *shr_oemname; 678 uint32_t shr_flags; 679 uint32_t shr_type; 680 uint32_t shr_refcnt; 681 uint32_t shr_autocnt; 682 uid_t shr_uid; 683 gid_t shr_gid; 684 char *shr_access_none; 685 char *shr_access_ro; 686 char *shr_access_rw; 687 avl_node_t shr_link; 688 kmem_cache_t *shr_cache; 689 kmutex_t shr_mutex; 690 } smb_kshare_t; 691 692 693 typedef struct smb_arg_negotiate { 694 char *ni_name; 695 int ni_dialect; 696 int ni_index; 697 uint32_t ni_capabilities; 698 uint16_t ni_maxmpxcount; 699 int16_t ni_tzcorrection; 700 uint8_t ni_keylen; 701 uint8_t ni_key[SMB_ENCRYPT_KEY_MAXLEN]; 702 timestruc_t ni_servertime; 703 } smb_arg_negotiate_t; 704 705 typedef struct smb_arg_sessionsetup { 706 char *ssi_user; 707 char *ssi_domain; 708 uint16_t ssi_cipwlen; 709 uint8_t *ssi_cipwd; 710 uint16_t ssi_cspwlen; 711 uint8_t *ssi_cspwd; 712 uint16_t ssi_maxmpxcount; 713 uint32_t ssi_capabilities; 714 uint32_t ssi_sesskey; 715 boolean_t ssi_guest; 716 } smb_arg_sessionsetup_t; 717 718 typedef struct tcon { 719 char *path; 720 char *service; 721 int pwdlen; 722 char *password; 723 uint16_t flags; 724 uint16_t optional_support; 725 smb_kshare_t *si; 726 } smb_arg_tcon_t; 727 728 /* 729 * Based on section 2.6.1.2 (Connection Management) of the June 13, 730 * 1996 CIFS spec, a server may terminate the transport connection 731 * due to inactivity. The client software is expected to be able to 732 * automatically reconnect to the server if this happens. Like much 733 * of the useful background information, this section appears to 734 * have been dropped from later revisions of the document. 735 * 736 * Each session has an activity timestamp that's updated whenever a 737 * request is dispatched. If the session is idle, i.e. receives no 738 * requests, for SMB_SESSION_INACTIVITY_TIMEOUT minutes it will be 739 * closed. 740 * 741 * Each session has an I/O semaphore to serialize communication with 742 * the client. For example, after receiving a raw-read request, the 743 * server is not allowed to send an oplock break to the client until 744 * after it has sent the raw-read data. 745 */ 746 #define SMB_SESSION_INACTIVITY_TIMEOUT (15 * 60) 747 748 #define SMB_SESSION_OFILE_MAX (16 * 1024) 749 750 /* 751 * When a connection is set up we need to remember both the client 752 * (peer) IP address and the local IP address used to establish the 753 * connection. When a client connects with a vc number of zero, we 754 * are supposed to abort any existing connections with that client 755 * (see notes in smb_negotiate.c and smb_session_setup_andx.c). For 756 * servers with multiple network interfaces or IP aliases, however, 757 * each interface has to be managed independently since the client 758 * is not aware of the server configuration. We have to allow the 759 * client to establish a connection on each interface with a vc 760 * number of zero without aborting the other connections. 761 * 762 * ipaddr: the client (peer) IP address for the session. 763 * local_ipaddr: the local IP address used to connect to the server. 764 */ 765 766 #define SMB_MAC_KEYSZ 512 767 768 struct smb_sign { 769 unsigned int seqnum; 770 unsigned int mackey_len; 771 unsigned int flags; 772 unsigned char mackey[SMB_MAC_KEYSZ]; 773 }; 774 775 #define SMB_SIGNING_ENABLED 1 776 #define SMB_SIGNING_CHECK 2 777 778 /* 779 * Session State Machine 780 * --------------------- 781 * 782 * +-----------------------------+ +------------------------------+ 783 * | SMB_SESSION_STATE_CONNECTED | | SMB_SESSION_STATE_TERMINATED | 784 * +-----------------------------+ +------------------------------+ 785 * T0| ^ 786 * +--------------------+ |T13 787 * v |T14 | 788 * +-------------------------------+ | +--------------------------------+ 789 * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED | 790 * +-------------------------------+ +--------------------------------+ 791 * T1| ^ ^ ^ ^ 792 * +----------+ |T9 | | | 793 * v | | | | 794 * +------------------------------+ | | | 795 * | SMB_SESSION_STATE_NEGOTIATED | | | | 796 * +------------------------------+ | | | 797 * ^| ^| | ^ | | | 798 * +----------------+| || | | | | | 799 * |+----------------+ || T7| |T8 | | | 800 * || || | | | | | 801 * || +----------------+| | | | | | 802 * || |+----------------+ | | | | | 803 * || || v | | | | 804 * || || +-----------------------------------+ T10| | | 805 * || || | SMB_SESSION_STATE_OPLOCK_BREAKING |----+ | | 806 * || || +-----------------------------------+ | | 807 * || ||T5 | | 808 * || |+-->+-----------------------------------+ T11| | 809 * || |T6 | SMB_SESSION_STATE_READ_RAW_ACTIVE |------+ | 810 * || +----+-----------------------------------+ | 811 * ||T3 | 812 * |+------->+------------------------------------+ T12| 813 * |T4 | SMB_SESSION_STATE_WRITE_RAW_ACTIVE |-------+ 814 * +---------+------------------------------------+ 815 * 816 * Transition T0 817 * 818 * 819 * 820 * Transition T1 821 * 822 * 823 * 824 * Transition T2 825 * 826 * 827 * 828 * Transition T3 829 * 830 * 831 * 832 * Transition T4 833 * 834 * 835 * 836 * Transition T5 837 * 838 * 839 * 840 * Transition T6 841 * 842 * 843 * 844 * Transition T7 845 * 846 * 847 * 848 * Transition T8 849 * 850 * 851 * 852 * Transition T9 853 * 854 * 855 * 856 * Transition T10 857 * 858 * 859 * 860 * Transition T11 861 * 862 * 863 * 864 * Transition T12 865 * 866 * 867 * 868 * Transition T13 869 * 870 * 871 * 872 * Transition T14 873 * 874 * 875 * 876 */ 877 #define SMB_SESSION_MAGIC 0x53455353 /* 'SESS' */ 878 #define SMB_SESSION_VALID(p) \ 879 ASSERT(((p) != NULL) && ((p)->s_magic == SMB_SESSION_MAGIC)) 880 881 typedef enum { 882 SMB_SESSION_STATE_INITIALIZED = 0, 883 SMB_SESSION_STATE_DISCONNECTED, 884 SMB_SESSION_STATE_CONNECTED, 885 SMB_SESSION_STATE_ESTABLISHED, 886 SMB_SESSION_STATE_NEGOTIATED, 887 SMB_SESSION_STATE_OPLOCK_BREAKING, 888 SMB_SESSION_STATE_WRITE_RAW_ACTIVE, 889 SMB_SESSION_STATE_READ_RAW_ACTIVE, 890 SMB_SESSION_STATE_TERMINATED, 891 SMB_SESSION_STATE_SENTINEL 892 } smb_session_state_t; 893 894 typedef struct smb_session { 895 uint32_t s_magic; 896 smb_rwx_t s_lock; 897 list_node_t s_lnd; 898 uint64_t s_kid; 899 smb_session_state_t s_state; 900 uint32_t s_flags; 901 int s_write_raw_status; 902 kthread_t *s_thread; 903 kt_did_t s_ktdid; 904 smb_kmod_cfg_t s_cfg; 905 kmem_cache_t *s_cache; 906 kmem_cache_t *s_cache_request; 907 struct smb_server *s_server; 908 int32_t s_gmtoff; 909 uint32_t keep_alive; 910 uint64_t opentime; 911 uint16_t vcnumber; 912 uint16_t s_local_port; 913 smb_inaddr_t ipaddr; 914 smb_inaddr_t local_ipaddr; 915 char workstation[SMB_PI_MAX_HOST]; 916 int dialect; 917 int native_os; 918 int native_lm; 919 920 uint32_t capabilities; 921 struct smb_sign signing; 922 923 ksocket_t sock; 924 925 smb_slist_t s_req_list; 926 smb_llist_t s_xa_list; 927 smb_llist_t s_user_list; 928 smb_idpool_t s_uid_pool; 929 smb_txlst_t s_txlst; 930 931 volatile uint32_t s_tree_cnt; 932 volatile uint32_t s_file_cnt; 933 volatile uint32_t s_dir_cnt; 934 935 uint16_t secmode; 936 uint32_t sesskey; 937 uint32_t challenge_len; 938 unsigned char challenge_key[8]; 939 unsigned char MAC_key[44]; 940 int64_t activity_timestamp; 941 /* 942 * Maximum negotiated buffer size between SMB client and server 943 * in SMB_SESSION_SETUP_ANDX 944 */ 945 uint16_t smb_msg_size; 946 uchar_t *outpipe_data; 947 int outpipe_datalen; 948 int outpipe_cookie; 949 list_t s_oplock_brkreqs; 950 smb_srqueue_t *s_srqueue; 951 } smb_session_t; 952 953 #define SMB_USER_MAGIC 0x55534552 /* 'USER' */ 954 #define SMB_USER_VALID(u) \ 955 ASSERT(((u) != NULL) && ((u)->u_magic == SMB_USER_MAGIC)) 956 957 #define SMB_USER_FLAG_GUEST SMB_ATF_GUEST 958 #define SMB_USER_FLAG_IPC SMB_ATF_ANON 959 #define SMB_USER_FLAG_ADMIN SMB_ATF_ADMIN 960 #define SMB_USER_FLAG_POWER_USER SMB_ATF_POWERUSER 961 #define SMB_USER_FLAG_BACKUP_OPERATOR SMB_ATF_BACKUPOP 962 963 #define SMB_USER_IS_ADMIN(U) (((U)->u_flags & SMB_USER_FLAG_ADMIN) != 0) 964 #define SMB_USER_IS_GUEST(U) (((U)->u_flags & SMB_USER_FLAG_GUEST) != 0) 965 966 #define SMB_USER_PRIV_TAKE_OWNERSHIP 0x00000001 967 #define SMB_USER_PRIV_BACKUP 0x00000002 968 #define SMB_USER_PRIV_RESTORE 0x00000004 969 #define SMB_USER_PRIV_SECURITY 0x00000008 970 971 972 typedef enum { 973 SMB_USER_STATE_LOGGED_IN = 0, 974 SMB_USER_STATE_LOGGING_OFF, 975 SMB_USER_STATE_LOGGED_OFF, 976 SMB_USER_STATE_SENTINEL 977 } smb_user_state_t; 978 979 typedef struct smb_user { 980 uint32_t u_magic; 981 list_node_t u_lnd; 982 kmutex_t u_mutex; 983 smb_user_state_t u_state; 984 985 struct smb_server *u_server; 986 smb_session_t *u_session; 987 uint16_t u_name_len; 988 char *u_name; 989 uint16_t u_domain_len; 990 char *u_domain; 991 time_t u_logon_time; 992 cred_t *u_cred; 993 cred_t *u_privcred; 994 995 smb_llist_t u_tree_list; 996 smb_idpool_t u_tid_pool; 997 998 uint32_t u_refcnt; 999 uint32_t u_flags; 1000 uint32_t u_privileges; 1001 uint16_t u_uid; 1002 uint32_t u_audit_sid; 1003 } smb_user_t; 1004 1005 #define SMB_TREE_MAGIC 0x54524545 /* 'TREE' */ 1006 #define SMB_TREE_VALID(p) \ 1007 ASSERT((p != NULL) && ((p)->t_magic == SMB_TREE_MAGIC)) 1008 1009 #define SMB_TYPENAMELEN _ST_FSTYPSZ 1010 #define SMB_VOLNAMELEN 32 1011 1012 #define SMB_TREE_READONLY 0x00000001 1013 #define SMB_TREE_SUPPORTS_ACLS 0x00000002 1014 #define SMB_TREE_STREAMS 0x00000004 1015 #define SMB_TREE_CASEINSENSITIVE 0x00000008 1016 #define SMB_TREE_NO_CASESENSITIVE 0x00000010 1017 #define SMB_TREE_NO_EXPORT 0x00000020 1018 #define SMB_TREE_OPLOCKS 0x00000040 1019 #define SMB_TREE_SHORTNAMES 0x00000080 1020 #define SMB_TREE_XVATTR 0x00000100 1021 #define SMB_TREE_DIRENTFLAGS 0x00000200 1022 #define SMB_TREE_ACLONCREATE 0x00000400 1023 #define SMB_TREE_ACEMASKONACCESS 0x00000800 1024 #define SMB_TREE_NFS_MOUNTED 0x00001000 1025 #define SMB_TREE_UNICODE_ON_DISK 0x00002000 1026 #define SMB_TREE_CATIA 0x00004000 1027 #define SMB_TREE_ABE 0x00008000 1028 #define SMB_TREE_QUOTA 0x00010000 1029 #define SMB_TREE_DFSROOT 0x00020000 1030 #define SMB_TREE_SPARSE 0x00040000 1031 1032 typedef enum { 1033 SMB_TREE_STATE_CONNECTED = 0, 1034 SMB_TREE_STATE_DISCONNECTING, 1035 SMB_TREE_STATE_DISCONNECTED, 1036 SMB_TREE_STATE_SENTINEL 1037 } smb_tree_state_t; 1038 1039 typedef struct smb_tree { 1040 uint32_t t_magic; 1041 kmutex_t t_mutex; 1042 list_node_t t_lnd; 1043 smb_tree_state_t t_state; 1044 1045 struct smb_server *t_server; 1046 smb_session_t *t_session; 1047 smb_user_t *t_user; 1048 smb_node_t *t_snode; 1049 1050 smb_llist_t t_ofile_list; 1051 smb_idpool_t t_fid_pool; 1052 1053 smb_llist_t t_odir_list; 1054 smb_idpool_t t_odid_pool; 1055 1056 uint32_t t_refcnt; 1057 uint32_t t_flags; 1058 int32_t t_res_type; 1059 uint16_t t_tid; 1060 uint16_t t_umask; 1061 char t_sharename[MAXNAMELEN]; 1062 char t_resource[MAXPATHLEN]; 1063 char t_typename[SMB_TYPENAMELEN]; 1064 char t_volume[SMB_VOLNAMELEN]; 1065 acl_type_t t_acltype; 1066 uint32_t t_access; 1067 uint32_t t_execflags; 1068 time_t t_connect_time; 1069 volatile uint32_t t_open_files; 1070 } smb_tree_t; 1071 1072 #define SMB_TREE_VFS(tree) ((tree)->t_snode->vp->v_vfsp) 1073 #define SMB_TREE_FSID(tree) ((tree)->t_snode->vp->v_vfsp->vfs_fsid) 1074 1075 #define SMB_TREE_IS_READONLY(sr) \ 1076 ((sr) != NULL && (sr)->tid_tree != NULL && \ 1077 !((sr)->tid_tree->t_access & ACE_ALL_WRITE_PERMS)) 1078 1079 #define SMB_TREE_IS_CASEINSENSITIVE(sr) \ 1080 (((sr) && (sr)->tid_tree) ? \ 1081 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CASEINSENSITIVE) : 0) 1082 1083 #define SMB_TREE_HAS_ACCESS(sr, acemask) \ 1084 ((sr) == NULL ? ACE_ALL_PERMS : ( \ 1085 (((sr) && (sr)->tid_tree) ? \ 1086 (((sr)->tid_tree->t_access) & (acemask)) : 0))) 1087 1088 #define SMB_TREE_SUPPORTS_CATIA(sr) \ 1089 (((sr) && (sr)->tid_tree) ? \ 1090 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CATIA) : 0) 1091 1092 #define SMB_TREE_SUPPORTS_ABE(sr) \ 1093 (((sr) && (sr)->tid_tree) ? \ 1094 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_ABE) : 0) 1095 1096 #define SMB_TREE_IS_DFSROOT(sr) \ 1097 (((sr) && (sr)->tid_tree) ? \ 1098 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_DFSROOT) : 0) 1099 1100 #define SMB_TREE_SUPPORTS_SHORTNAMES(sr) \ 1101 (((sr) && (sr)->tid_tree) ? \ 1102 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_SHORTNAMES) : 0) 1103 1104 /* 1105 * SMB_TREE_CONTAINS_NODE is used to check that a node is in the same 1106 * file system as the tree. 1107 */ 1108 #define SMB_TREE_CONTAINS_NODE(sr, node) \ 1109 (((sr) && (sr)->tid_tree) ? \ 1110 (SMB_TREE_VFS((sr)->tid_tree) == SMB_NODE_VFS(node)) : 1) 1111 1112 /* 1113 * SMB_OFILE_IS_READONLY reflects whether an ofile is readonly or not. 1114 * The macro takes into account 1115 * - the tree readonly state 1116 * - the node readonly state 1117 * - whether the specified ofile is the readonly creator 1118 * The readonly creator has write permission until the ofile is closed. 1119 */ 1120 1121 #define SMB_OFILE_IS_READONLY(of) \ 1122 (((of)->f_flags & SMB_OFLAGS_READONLY) || \ 1123 smb_node_file_is_readonly((of)->f_node) || \ 1124 (((of)->f_node->readonly_creator) && \ 1125 ((of)->f_node->readonly_creator != (of)))) 1126 1127 /* 1128 * SMB_PATHFILE_IS_READONLY indicates whether or not a file is 1129 * readonly when the caller has a path rather than an ofile. Unlike 1130 * SMB_OFILE_IS_READONLY, the caller cannot be the readonly creator, 1131 * since that requires an ofile. 1132 */ 1133 1134 #define SMB_PATHFILE_IS_READONLY(sr, node) \ 1135 (SMB_TREE_IS_READONLY((sr)) || \ 1136 smb_node_file_is_readonly((node)) || \ 1137 ((node)->readonly_creator)) 1138 1139 #define SMB_OPIPE_MAGIC 0x50495045 /* 'PIPE' */ 1140 #define SMB_OPIPE_VALID(p) \ 1141 ASSERT(((p) != NULL) && (p)->p_magic == SMB_OPIPE_MAGIC) 1142 1143 /* 1144 * Data structure for SMB_FTYPE_MESG_PIPE ofiles, which is used 1145 * at the interface between SMB and NDR RPC. 1146 */ 1147 typedef struct smb_opipe { 1148 uint32_t p_magic; 1149 list_node_t p_lnd; 1150 kmutex_t p_mutex; 1151 kcondvar_t p_cv; 1152 struct smb_server *p_server; 1153 struct smb_event *p_event; 1154 char *p_name; 1155 uint32_t p_busy; 1156 smb_doorhdr_t p_hdr; 1157 smb_netuserinfo_t p_user; 1158 uint8_t *p_doorbuf; 1159 uint8_t *p_data; 1160 } smb_opipe_t; 1161 1162 /* 1163 * The of_ftype of an open file should contain the SMB_FTYPE value 1164 * returned when the file/pipe was opened. The following 1165 * assumptions are currently made: 1166 * 1167 * File Type Node PipeInfo 1168 * --------- -------- -------- 1169 * SMB_FTYPE_DISK Valid Null 1170 * SMB_FTYPE_BYTE_PIPE Undefined Undefined 1171 * SMB_FTYPE_MESG_PIPE Null Valid 1172 * SMB_FTYPE_PRINTER Undefined Undefined 1173 * SMB_FTYPE_UNKNOWN Undefined Undefined 1174 */ 1175 1176 /* 1177 * Some flags for ofile structure 1178 * 1179 * SMB_OFLAGS_SET_DELETE_ON_CLOSE 1180 * Set this flag when the corresponding open operation whose 1181 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any 1182 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE 1183 * will be set for the file node upon close. 1184 * 1185 * SMB_OFLAGS_TIMESTAMPS_PENDING 1186 * This flag gets set when a write operation is performed on the 1187 * ofile. The timestamps will be updated, and the flags cleared, 1188 * when the ofile gets closed or a setattr is performed on the ofile. 1189 */ 1190 1191 #define SMB_OFLAGS_READONLY 0x0001 1192 #define SMB_OFLAGS_EXECONLY 0x0002 1193 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004 1194 #define SMB_OFLAGS_LLF_POS_VALID 0x0008 1195 #define SMB_OFLAGS_TIMESTAMPS_PENDING 0x0010 1196 1197 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */ 1198 #define SMB_OFILE_VALID(p) \ 1199 ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC)) 1200 1201 typedef enum { 1202 SMB_OFILE_STATE_OPEN = 0, 1203 SMB_OFILE_STATE_CLOSING, 1204 SMB_OFILE_STATE_CLOSED, 1205 SMB_OFILE_STATE_SENTINEL 1206 } smb_ofile_state_t; 1207 1208 typedef struct smb_ofile { 1209 uint32_t f_magic; 1210 kmutex_t f_mutex; 1211 list_node_t f_lnd; 1212 list_node_t f_nnd; 1213 smb_ofile_state_t f_state; 1214 1215 struct smb_server *f_server; 1216 smb_session_t *f_session; 1217 smb_user_t *f_user; 1218 smb_tree_t *f_tree; 1219 smb_node_t *f_node; 1220 smb_opipe_t *f_pipe; 1221 1222 uint32_t f_uniqid; 1223 uint32_t f_refcnt; 1224 uint64_t f_seek_pos; 1225 uint32_t f_flags; 1226 uint32_t f_granted_access; 1227 uint32_t f_share_access; 1228 uint32_t f_create_options; 1229 uint16_t f_fid; 1230 uint16_t f_opened_by_pid; 1231 uint16_t f_ftype; 1232 uint64_t f_llf_pos; 1233 int f_mode; 1234 cred_t *f_cr; 1235 pid_t f_pid; 1236 uint32_t f_explicit_times; 1237 char f_quota_resume[SMB_SID_STRSZ]; 1238 smb_oplock_grant_t f_oplock_grant; 1239 } smb_ofile_t; 1240 1241 #define SMB_ODIR_MAGIC 0x4F444952 /* 'ODIR' */ 1242 #define SMB_ODIR_VALID(p) \ 1243 ASSERT((p != NULL) && ((p)->d_magic == SMB_ODIR_MAGIC)) 1244 1245 #define SMB_ODIR_BUFSIZE (8 * 1024) 1246 1247 #define SMB_ODIR_FLAG_WILDCARDS 0x0001 1248 #define SMB_ODIR_FLAG_IGNORE_CASE 0x0002 1249 #define SMB_ODIR_FLAG_XATTR 0x0004 1250 #define SMB_ODIR_FLAG_EDIRENT 0x0008 1251 #define SMB_ODIR_FLAG_CATIA 0x0010 1252 #define SMB_ODIR_FLAG_ABE 0x0020 1253 #define SMB_ODIR_FLAG_SHORTNAMES 0x0040 1254 1255 typedef enum { 1256 SMB_ODIR_STATE_OPEN = 0, 1257 SMB_ODIR_STATE_IN_USE, 1258 SMB_ODIR_STATE_CLOSING, 1259 SMB_ODIR_STATE_CLOSED, 1260 SMB_ODIR_STATE_SENTINEL 1261 } smb_odir_state_t; 1262 1263 typedef enum { 1264 SMB_ODIR_RESUME_IDX, 1265 SMB_ODIR_RESUME_COOKIE, 1266 SMB_ODIR_RESUME_FNAME 1267 } smb_odir_resume_type_t; 1268 1269 typedef struct smb_odir_resume { 1270 smb_odir_resume_type_t or_type; 1271 int or_idx; 1272 uint32_t or_cookie; 1273 char *or_fname; 1274 } smb_odir_resume_t; 1275 1276 /* 1277 * Flags used when opening an odir 1278 */ 1279 #define SMB_ODIR_OPENF_BACKUP_INTENT 0x01 1280 1281 typedef struct smb_odir { 1282 uint32_t d_magic; 1283 kmutex_t d_mutex; 1284 list_node_t d_lnd; 1285 smb_odir_state_t d_state; 1286 smb_session_t *d_session; 1287 smb_tree_t *d_tree; 1288 smb_node_t *d_dnode; 1289 cred_t *d_cred; 1290 uint16_t d_odid; 1291 uint16_t d_opened_by_pid; 1292 uint16_t d_sattr; 1293 uint32_t d_refcnt; 1294 uint32_t d_flags; 1295 boolean_t d_eof; 1296 int d_bufsize; 1297 uint64_t d_offset; 1298 union { 1299 char *u_bufptr; 1300 edirent_t *u_edp; 1301 dirent64_t *u_dp; 1302 } d_u; 1303 uint32_t d_cookies[SMB_MAX_SEARCH]; 1304 char d_pattern[MAXNAMELEN]; 1305 char d_buf[SMB_ODIR_BUFSIZE]; 1306 } smb_odir_t; 1307 #define d_bufptr d_u.u_bufptr 1308 #define d_edp d_u.u_edp 1309 #define d_dp d_u.u_dp 1310 1311 typedef struct smb_odirent { 1312 char od_name[MAXNAMELEN]; /* on disk name */ 1313 ino64_t od_ino; 1314 uint32_t od_eflags; 1315 } smb_odirent_t; 1316 1317 typedef struct smb_fileinfo { 1318 char fi_name[MAXNAMELEN]; 1319 char fi_shortname[SMB_SHORTNAMELEN]; 1320 uint32_t fi_cookie; 1321 uint32_t fi_dosattr; /* DOS attributes */ 1322 uint64_t fi_nodeid; /* file system node id */ 1323 uint64_t fi_size; /* file size in bytes */ 1324 uint64_t fi_alloc_size; /* allocation size in bytes */ 1325 timestruc_t fi_atime; /* last access */ 1326 timestruc_t fi_mtime; /* last modification */ 1327 timestruc_t fi_ctime; /* last status change */ 1328 timestruc_t fi_crtime; /* file creation */ 1329 } smb_fileinfo_t; 1330 1331 typedef struct smb_streaminfo { 1332 uint64_t si_size; 1333 uint64_t si_alloc_size; 1334 char si_name[MAXPATHLEN]; 1335 } smb_streaminfo_t; 1336 1337 #define SMB_LOCK_MAGIC 0x4C4F434B /* 'LOCK' */ 1338 1339 typedef struct smb_lock { 1340 uint32_t l_magic; 1341 kmutex_t l_mutex; 1342 list_node_t l_lnd; 1343 kcondvar_t l_cv; 1344 1345 list_node_t l_conflict_lnd; 1346 smb_slist_t l_conflict_list; 1347 1348 smb_session_t *l_session; 1349 smb_ofile_t *l_file; 1350 struct smb_request *l_sr; 1351 1352 uint32_t l_flags; 1353 uint64_t l_session_kid; 1354 struct smb_lock *l_blocked_by; /* Debug info only */ 1355 1356 uint16_t l_pid; 1357 uint16_t l_uid; 1358 uint32_t l_type; 1359 uint64_t l_start; 1360 uint64_t l_length; 1361 clock_t l_end_time; 1362 } smb_lock_t; 1363 1364 #define SMB_LOCK_FLAG_INDEFINITE 0x0004 1365 #define SMB_LOCK_INDEFINITE_WAIT(lock) \ 1366 ((lock)->l_flags & SMB_LOCK_FLAG_INDEFINITE) 1367 1368 #define SMB_LOCK_TYPE_READWRITE 101 1369 #define SMB_LOCK_TYPE_READONLY 102 1370 1371 typedef struct vardata_block { 1372 uint8_t vdb_tag; 1373 uint32_t vdb_len; 1374 struct uio vdb_uio; 1375 struct iovec vdb_iovec[MAX_IOVEC]; 1376 } smb_vdb_t; 1377 1378 #define SMB_WRMODE_WRITE_THRU 0x0001 1379 #define SMB_WRMODE_IS_STABLE(M) ((M) & SMB_WRMODE_WRITE_THRU) 1380 1381 #define SMB_RW_MAGIC 0x52445257 /* 'RDRW' */ 1382 1383 typedef struct smb_rw_param { 1384 uint32_t rw_magic; 1385 smb_vdb_t rw_vdb; 1386 uint64_t rw_offset; 1387 uint32_t rw_last_write; 1388 uint16_t rw_mode; 1389 uint32_t rw_count; /* bytes in this request */ 1390 uint16_t rw_mincnt; 1391 uint32_t rw_total; /* total bytes (write-raw) */ 1392 uint16_t rw_dsoff; /* SMB data offset */ 1393 uint8_t rw_andx; /* SMB secondary andx command */ 1394 } smb_rw_param_t; 1395 1396 typedef struct smb_pathname { 1397 char *pn_path; 1398 char *pn_pname; 1399 char *pn_fname; 1400 char *pn_sname; 1401 char *pn_stype; 1402 } smb_pathname_t; 1403 1404 /* 1405 * fs_query_info 1406 */ 1407 typedef struct smb_fqi { 1408 smb_pathname_t fq_path; 1409 uint16_t fq_sattr; 1410 smb_node_t *fq_dnode; 1411 smb_node_t *fq_fnode; 1412 smb_attr_t fq_fattr; 1413 char fq_last_comp[MAXNAMELEN]; 1414 } smb_fqi_t; 1415 1416 typedef struct dirop { 1417 smb_fqi_t fqi; 1418 smb_fqi_t dst_fqi; 1419 uint16_t info_level; 1420 uint16_t flags; 1421 } smb_arg_dirop_t; 1422 1423 typedef struct { 1424 uint32_t status; 1425 uint16_t errcls; 1426 uint16_t errcode; 1427 } smb_error_t; 1428 1429 typedef struct open_param { 1430 smb_fqi_t fqi; 1431 uint16_t omode; 1432 uint16_t ofun; 1433 uint32_t nt_flags; 1434 uint32_t timeo; 1435 uint32_t dattr; 1436 timestruc_t crtime; 1437 timestruc_t mtime; 1438 uint64_t dsize; 1439 uint32_t desired_access; 1440 uint32_t share_access; 1441 uint32_t create_options; 1442 uint32_t create_disposition; 1443 boolean_t created_readonly; 1444 uint32_t ftype; 1445 uint32_t devstate; 1446 uint32_t action_taken; 1447 uint64_t fileid; 1448 uint32_t rootdirfid; 1449 smb_ofile_t *dir; 1450 /* This is only set by NTTransactCreate */ 1451 struct smb_sd *sd; 1452 uint8_t op_oplock_level; /* requested/granted level */ 1453 boolean_t op_oplock_levelII; /* TRUE if levelII supported */ 1454 } smb_arg_open_t; 1455 1456 /* 1457 * SMB Request State Machine 1458 * ------------------------- 1459 * 1460 * T4 +------+ T0 1461 * +--------------------------->| FREE |---------------------------+ 1462 * | +------+ | 1463 * +-----------+ | 1464 * | COMPLETED | | 1465 * +-----------+ 1466 * ^ | 1467 * | T15 +----------+ v 1468 * +------------+ T6 | | +--------------+ 1469 * | CLEANED_UP |<-----------------| CANCELED | | INITIALIZING | 1470 * +------------+ | | +--------------+ 1471 * | ^ +----------+ | 1472 * | | ^ ^ ^ ^ | 1473 * | | +-------------+ | | | | 1474 * | | T3 | | | | T13 | T1 1475 * | +-------------------------+ | | +----------------------+ | 1476 * +----------------------------+ | | | | | 1477 * T16 | | | | +-----------+ | | 1478 * | \/ | | T5 | | v 1479 * +-----------------+ | T12 +--------+ | T2 +-----------+ 1480 * | EVENT_OCCURRED |------------->| ACTIVE |<--------------------| SUBMITTED | 1481 * +-----------------+ | +--------+ | +-----------+ 1482 * ^ | | ^ | | 1483 * | | T8 | | | T7 | 1484 * | T10 T9 | +----------+ | +-------+ | T11 1485 * | | | +-------+ | | 1486 * | | | T14 | | | 1487 * | | v | v | 1488 * +----------------------+ +--------------+ 1489 * | WAITING_EVENT | | WAITING_LOCK | 1490 * +----------------------+ +--------------+ 1491 * 1492 * 1493 * 1494 * 1495 * 1496 * Transition T0 1497 * 1498 * This transition occurs when the request is allocated and is still under the 1499 * control of the session thread. 1500 * 1501 * Transition T1 1502 * 1503 * This transition occurs when the session thread dispatches a task to treat the 1504 * request. 1505 * 1506 * Transition T2 1507 * 1508 * 1509 * 1510 * Transition T3 1511 * 1512 * A request completes and smbsr_cleanup is called to release resources 1513 * associated with the request (but not the smb_request_t itself). This 1514 * includes references on smb_ofile_t, smb_node_t, and other structures. 1515 * CLEANED_UP state exists to detect if we attempt to cleanup a request 1516 * multiple times and to allow us to detect that we are accessing a 1517 * request that has already been cleaned up. 1518 * 1519 * Transition T4 1520 * 1521 * 1522 * 1523 * Transition T5 1524 * 1525 * 1526 * 1527 * Transition T6 1528 * 1529 * 1530 * 1531 * Transition T7 1532 * 1533 * 1534 * 1535 * Transition T8 1536 * 1537 * 1538 * 1539 * Transition T9 1540 * 1541 * 1542 * 1543 * Transition T10 1544 * 1545 * 1546 * 1547 * Transition T11 1548 * 1549 * 1550 * 1551 * Transition T12 1552 * 1553 * 1554 * 1555 * Transition T13 1556 * 1557 * 1558 * 1559 * Transition T14 1560 * 1561 * 1562 * 1563 * Transition T15 1564 * 1565 * Request processing is completed (control returns from smb_dispatch) 1566 * 1567 * Transition T16 1568 * 1569 * Multipart (andx) request was cleaned up with smbsr_cleanup but more "andx" 1570 * sections remain to be processed. 1571 * 1572 */ 1573 1574 #define SMB_REQ_MAGIC 0x534D4252 /* 'SMBR' */ 1575 #define SMB_REQ_VALID(p) ASSERT((p)->sr_magic == SMB_REQ_MAGIC) 1576 1577 typedef enum smb_req_state { 1578 SMB_REQ_STATE_FREE = 0, 1579 SMB_REQ_STATE_INITIALIZING, 1580 SMB_REQ_STATE_SUBMITTED, 1581 SMB_REQ_STATE_ACTIVE, 1582 SMB_REQ_STATE_WAITING_EVENT, 1583 SMB_REQ_STATE_EVENT_OCCURRED, 1584 SMB_REQ_STATE_WAITING_LOCK, 1585 SMB_REQ_STATE_COMPLETED, 1586 SMB_REQ_STATE_CANCELED, 1587 SMB_REQ_STATE_CLEANED_UP, 1588 SMB_REQ_STATE_SENTINEL 1589 } smb_req_state_t; 1590 1591 typedef struct smb_request { 1592 uint32_t sr_magic; 1593 kmutex_t sr_mutex; 1594 list_node_t sr_session_lnd; 1595 smb_req_state_t sr_state; 1596 boolean_t sr_keep; 1597 kmem_cache_t *sr_cache; 1598 struct smb_server *sr_server; 1599 pid_t *sr_pid; 1600 int32_t sr_gmtoff; 1601 smb_session_t *session; 1602 smb_kmod_cfg_t *sr_cfg; 1603 smb_notify_change_req_t sr_ncr; 1604 1605 /* Info from session service header */ 1606 uint32_t sr_req_length; /* Excluding NBT header */ 1607 1608 /* Request buffer excluding NBT header */ 1609 void *sr_request_buf; 1610 1611 smb_lock_t *sr_awaiting; 1612 struct mbuf_chain command; 1613 struct mbuf_chain reply; 1614 struct mbuf_chain raw_data; 1615 list_t sr_storage; 1616 struct smb_xa *r_xa; 1617 int andx_prev_wct; 1618 int cur_reply_offset; 1619 int orig_request_hdr; 1620 unsigned int reply_seqnum; /* reply sequence number */ 1621 unsigned char first_smb_com; /* command code */ 1622 unsigned char smb_com; /* command code */ 1623 1624 uint8_t smb_rcls; /* error code class */ 1625 uint8_t smb_reh; /* rsvd (AH DOS INT-24 ERR) */ 1626 uint16_t smb_err; /* error code */ 1627 smb_error_t smb_error; 1628 1629 uint8_t smb_flg; /* flags */ 1630 uint16_t smb_flg2; /* flags */ 1631 uint16_t smb_pid_high; /* high part of pid */ 1632 unsigned char smb_sig[8]; /* signiture */ 1633 uint16_t smb_tid; /* tree id # */ 1634 uint16_t smb_pid; /* caller's process id # */ 1635 uint16_t smb_uid; /* user id # */ 1636 uint16_t smb_mid; /* mutiplex id # */ 1637 unsigned char smb_wct; /* count of parameter words */ 1638 uint16_t smb_bcc; /* data byte count */ 1639 1640 /* Parameters */ 1641 struct mbuf_chain smb_vwv; /* variable width value */ 1642 1643 /* Data */ 1644 struct mbuf_chain smb_data; 1645 1646 uint16_t smb_fid; /* not in hdr, but common */ 1647 1648 unsigned char andx_com; 1649 uint16_t andx_off; 1650 1651 struct smb_tree *tid_tree; 1652 struct smb_ofile *fid_ofile; 1653 smb_user_t *uid_user; 1654 1655 union { 1656 smb_arg_negotiate_t *negprot; 1657 smb_arg_sessionsetup_t *ssetup; 1658 smb_arg_tcon_t tcon; 1659 smb_arg_dirop_t dirop; 1660 smb_arg_open_t open; 1661 smb_rw_param_t *rw; 1662 uint32_t timestamp; 1663 } arg; 1664 1665 cred_t *user_cr; 1666 kthread_t *sr_worker; 1667 hrtime_t sr_time_submitted; 1668 hrtime_t sr_time_active; 1669 hrtime_t sr_time_start; 1670 int32_t sr_txb; 1671 uint32_t sr_seqnum; 1672 } smb_request_t; 1673 1674 #define sr_ssetup arg.ssetup 1675 #define sr_negprot arg.negprot 1676 #define sr_tcon arg.tcon 1677 #define sr_dirop arg.dirop 1678 #define sr_open arg.open 1679 #define sr_rw arg.rw 1680 #define sr_timestamp arg.timestamp 1681 1682 #define SMB_READ_PROTOCOL(hdr) \ 1683 LE_IN32(((smb_hdr_t *)(hdr))->protocol) 1684 1685 #define SMB_PROTOCOL_MAGIC_INVALID(rd_sr) \ 1686 (SMB_READ_PROTOCOL((rd_sr)->sr_request_buf) != SMB_PROTOCOL_MAGIC) 1687 1688 #define SMB_READ_COMMAND(hdr) \ 1689 (((smb_hdr_t *)(hdr))->command) 1690 1691 #define SMB_IS_WRITERAW(rd_sr) \ 1692 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_WRITE_RAW) 1693 1694 #define SMB_IS_NT_CANCEL(rd_sr) \ 1695 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NT_CANCEL) 1696 1697 #define SMB_IS_SESSION_SETUP_ANDX(rd_sr) \ 1698 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == \ 1699 SMB_COM_SESSION_SETUP_ANDX) 1700 1701 #define SMB_IS_NT_NEGOTIATE(rd_sr) \ 1702 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_NEGOTIATE) 1703 1704 #define SMB_IS_TREE_CONNECT_ANDX(rd_sr) \ 1705 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_TREE_CONNECT_ANDX) 1706 1707 #define SMB_XA_FLAG_OPEN 0x0001 1708 #define SMB_XA_FLAG_CLOSE 0x0002 1709 #define SMB_XA_FLAG_COMPLETE 0x0004 1710 #define SMB_XA_CLOSED(xa) (!((xa)->xa_flags & SMB_XA_FLAG_OPEN)) 1711 1712 #define SMB_XA_MAGIC 0x534D4258 /* 'SMBX' */ 1713 1714 typedef struct smb_xa { 1715 uint32_t xa_magic; 1716 kmutex_t xa_mutex; 1717 list_node_t xa_lnd; 1718 1719 uint32_t xa_refcnt; 1720 uint32_t xa_flags; 1721 1722 struct smb_session *xa_session; 1723 1724 unsigned char smb_com; /* which TRANS type */ 1725 unsigned char smb_flg; /* flags */ 1726 uint16_t smb_flg2; /* flags */ 1727 uint16_t smb_tid; /* tree id number */ 1728 uint16_t smb_pid; /* caller's process id number */ 1729 uint16_t smb_uid; /* user id number */ 1730 uint32_t smb_func; /* NT_TRANS function */ 1731 1732 uint16_t xa_smb_mid; /* mutiplex id number */ 1733 uint16_t xa_smb_fid; /* TRANS2 secondary */ 1734 1735 unsigned int reply_seqnum; /* reply sequence number */ 1736 1737 uint32_t smb_tpscnt; /* total parameter bytes being sent */ 1738 uint32_t smb_tdscnt; /* total data bytes being sent */ 1739 uint32_t smb_mprcnt; /* max parameter bytes to return */ 1740 uint32_t smb_mdrcnt; /* max data bytes to return */ 1741 uint32_t smb_msrcnt; /* max setup words to return */ 1742 uint32_t smb_flags; /* additional information: */ 1743 /* bit 0 - if set, disconnect TID in smb_tid */ 1744 /* bit 1 - if set, transaction is one way */ 1745 /* (no final response) */ 1746 int32_t smb_timeout; /* number of milliseconds to await completion */ 1747 uint32_t smb_suwcnt; /* set up word count */ 1748 1749 char *xa_pipe_name; 1750 1751 int req_disp_param; 1752 int req_disp_data; 1753 1754 struct mbuf_chain req_setup_mb; 1755 struct mbuf_chain req_param_mb; 1756 struct mbuf_chain req_data_mb; 1757 1758 struct mbuf_chain rep_setup_mb; 1759 struct mbuf_chain rep_param_mb; 1760 struct mbuf_chain rep_data_mb; 1761 } smb_xa_t; 1762 1763 1764 #define SDDF_NO_FLAGS 0 1765 #define SDDF_SUPPRESS_TID 0x0001 1766 #define SDDF_SUPPRESS_UID 0x0002 1767 1768 /* 1769 * SMB dispatch return codes. 1770 */ 1771 typedef enum { 1772 SDRC_SUCCESS = 0, 1773 SDRC_ERROR, 1774 SDRC_DROP_VC, 1775 SDRC_NO_REPLY, 1776 SDRC_SR_KEPT, 1777 SDRC_NOT_IMPLEMENTED 1778 } smb_sdrc_t; 1779 1780 #define VAR_BCC ((short)-1) 1781 1782 #define SMB_SERVER_MAGIC 0x53534552 /* 'SSER' */ 1783 #define SMB_SERVER_VALID(s) \ 1784 ASSERT(((s) != NULL) && ((s)->sv_magic == SMB_SERVER_MAGIC)) 1785 1786 #define SMB_LISTENER_MAGIC 0x4C53544E /* 'LSTN' */ 1787 #define SMB_LISTENER_VALID(ld) \ 1788 ASSERT(((ld) != NULL) && ((ld)->ld_magic == SMB_LISTENER_MAGIC)) 1789 1790 typedef struct { 1791 uint32_t ld_magic; 1792 struct smb_server *ld_sv; 1793 smb_thread_t ld_thread; 1794 ksocket_t ld_so; 1795 in_port_t ld_port; 1796 int ld_family; 1797 struct sockaddr_in ld_sin; 1798 struct sockaddr_in6 ld_sin6; 1799 smb_llist_t ld_session_list; 1800 } smb_listener_daemon_t; 1801 1802 #define SMB_SSETUP_CMD "authentication" 1803 #define SMB_TCON_CMD "share mapping" 1804 #define SMB_OPIPE_CMD "pipe open" 1805 #define SMB_THRESHOLD_REPORT_THROTTLE 50 1806 typedef struct smb_cmd_threshold { 1807 char *ct_cmd; 1808 kmutex_t ct_mutex; 1809 volatile uint32_t ct_active_cnt; 1810 volatile uint32_t ct_blocked_cnt; 1811 volatile uint32_t ct_error_cnt; 1812 uint32_t ct_threshold; 1813 struct smb_event *ct_event; 1814 uint32_t ct_event_id; 1815 } smb_cmd_threshold_t; 1816 1817 typedef struct { 1818 kstat_named_t ls_files; 1819 kstat_named_t ls_trees; 1820 kstat_named_t ls_users; 1821 } smb_server_legacy_kstat_t; 1822 1823 typedef enum smb_server_state { 1824 SMB_SERVER_STATE_CREATED = 0, 1825 SMB_SERVER_STATE_CONFIGURED, 1826 SMB_SERVER_STATE_RUNNING, 1827 SMB_SERVER_STATE_STOPPING, 1828 SMB_SERVER_STATE_DELETING, 1829 SMB_SERVER_STATE_SENTINEL 1830 } smb_server_state_t; 1831 1832 typedef struct { 1833 kcondvar_t sp_cv; 1834 kmutex_t sp_mutex; 1835 uint32_t sp_cnt; 1836 smb_llist_t sp_list; 1837 smb_llist_t sp_fidlist; 1838 } smb_spool_t; 1839 1840 #define SMB_SERVER_STATE_VALID(S) \ 1841 ASSERT(((S) == SMB_SERVER_STATE_CREATED) || \ 1842 ((S) == SMB_SERVER_STATE_CONFIGURED) || \ 1843 ((S) == SMB_SERVER_STATE_RUNNING) || \ 1844 ((S) == SMB_SERVER_STATE_STOPPING) || \ 1845 ((S) == SMB_SERVER_STATE_DELETING)) 1846 1847 typedef struct smb_server { 1848 uint32_t sv_magic; 1849 kcondvar_t sv_cv; 1850 kmutex_t sv_mutex; 1851 list_node_t sv_lnd; 1852 smb_server_state_t sv_state; 1853 uint32_t sv_refcnt; 1854 pid_t sv_pid; 1855 zoneid_t sv_zid; 1856 smb_listener_daemon_t sv_nbt_daemon; 1857 smb_listener_daemon_t sv_tcp_daemon; 1858 krwlock_t sv_cfg_lock; 1859 smb_kmod_cfg_t sv_cfg; 1860 smb_session_t *sv_session; 1861 1862 door_handle_t sv_lmshrd; 1863 1864 int32_t si_gmtoff; 1865 1866 smb_thread_t si_thread_timers; 1867 1868 taskq_t *sv_worker_pool; 1869 taskq_t *sv_receiver_pool; 1870 1871 kmem_cache_t *si_cache_request; 1872 kmem_cache_t *si_cache_session; 1873 kmem_cache_t *si_cache_user; 1874 kmem_cache_t *si_cache_tree; 1875 kmem_cache_t *si_cache_ofile; 1876 kmem_cache_t *si_cache_odir; 1877 kmem_cache_t *si_cache_opipe; 1878 kmem_cache_t *si_cache_event; 1879 1880 smb_node_t *si_root_smb_node; 1881 smb_llist_t sv_opipe_list; 1882 smb_llist_t sv_event_list; 1883 1884 /* Statistics */ 1885 hrtime_t sv_start_time; 1886 kstat_t *sv_ksp; 1887 volatile uint32_t sv_nbt_sess; 1888 volatile uint32_t sv_tcp_sess; 1889 volatile uint32_t sv_users; 1890 volatile uint32_t sv_trees; 1891 volatile uint32_t sv_files; 1892 volatile uint32_t sv_pipes; 1893 volatile uint64_t sv_txb; 1894 volatile uint64_t sv_rxb; 1895 volatile uint64_t sv_nreq; 1896 smb_srqueue_t sv_srqueue; 1897 smb_spool_t sp_info; 1898 smb_cmd_threshold_t sv_ssetup_ct; 1899 smb_cmd_threshold_t sv_tcon_ct; 1900 smb_cmd_threshold_t sv_opipe_ct; 1901 kstat_t *sv_legacy_ksp; 1902 kmutex_t sv_legacy_ksmtx; 1903 } smb_server_t; 1904 1905 #define SMB_EVENT_MAGIC 0x45564E54 /* EVNT */ 1906 #define SMB_EVENT_TIMEOUT 45 /* seconds */ 1907 #define SMB_EVENT_VALID(e) \ 1908 ASSERT(((e) != NULL) && ((e)->se_magic == SMB_EVENT_MAGIC)) 1909 typedef struct smb_event { 1910 uint32_t se_magic; 1911 list_node_t se_lnd; 1912 kmutex_t se_mutex; 1913 kcondvar_t se_cv; 1914 smb_server_t *se_server; 1915 uint32_t se_txid; 1916 boolean_t se_notified; 1917 int se_waittime; 1918 int se_timeout; 1919 int se_errno; 1920 } smb_event_t; 1921 1922 typedef struct smb_kspooldoc { 1923 uint32_t sd_magic; 1924 list_node_t sd_lnd; 1925 smb_inaddr_t sd_ipaddr; 1926 uint32_t sd_spool_num; 1927 uint16_t sd_fid; 1928 char sd_username[MAXNAMELEN]; 1929 char sd_path[MAXPATHLEN]; 1930 } smb_kspooldoc_t; 1931 1932 typedef struct smb_spoolfid { 1933 uint32_t sf_magic; 1934 list_node_t sf_lnd; 1935 uint16_t sf_fid; 1936 } smb_spoolfid_t; 1937 1938 #define SMB_INFO_NETBIOS_SESSION_SVC_RUNNING 0x0001 1939 #define SMB_INFO_NETBIOS_SESSION_SVC_FAILED 0x0002 1940 #define SMB_INFO_USER_LEVEL_SECURITY 0x40000000 1941 #define SMB_INFO_ENCRYPT_PASSWORDS 0x80000000 1942 1943 #define SMB_NEW_KID() atomic_inc_64_nv(&smb_kids) 1944 #define SMB_UNIQ_FID() atomic_inc_32_nv(&smb_fids) 1945 1946 #define SMB_IS_STREAM(node) ((node)->n_unode) 1947 1948 typedef struct smb_tsd { 1949 void (*proc)(); 1950 void *arg; 1951 char name[100]; 1952 } smb_tsd_t; 1953 1954 typedef struct smb_disp_entry { 1955 char sdt_name[KSTAT_STRLEN]; 1956 smb_sdrc_t (*sdt_pre_op)(smb_request_t *); 1957 smb_sdrc_t (*sdt_function)(smb_request_t *); 1958 void (*sdt_post_op)(smb_request_t *); 1959 uint8_t sdt_com; 1960 char sdt_dialect; 1961 uint8_t sdt_flags; 1962 volatile uint64_t sdt_txb; 1963 volatile uint64_t sdt_rxb; 1964 smb_latency_t sdt_lat; 1965 } smb_disp_entry_t; 1966 1967 typedef struct smb_xlate { 1968 int code; 1969 char *str; 1970 } smb_xlate_t; 1971 1972 typedef struct smb_export { 1973 kmutex_t e_mutex; 1974 boolean_t e_ready; 1975 smb_llist_t e_vfs_list; 1976 smb_avl_t e_share_avl; 1977 smb_slist_t e_unexport_list; 1978 1979 kmem_cache_t *e_cache_share; 1980 kmem_cache_t *e_cache_vfs; 1981 kmem_cache_t *e_cache_unexport; 1982 1983 smb_thread_t e_unexport_thread; 1984 } smb_export_t; 1985 1986 /* 1987 * This structure is a helper for building RAP NetShareEnum response 1988 * 1989 * es_posix_uid UID of the user requesting the shares list which 1990 * is used to detect if the user has any autohome 1991 * es_bufsize size of the response buffer 1992 * es_buf pointer to the response buffer 1993 * es_ntotal total number of shares exported by server which 1994 * their OEM names is less then 13 chars 1995 * es_nsent number of shares that can fit in the specified buffer 1996 * es_datasize actual data size (share's data) which was encoded 1997 * in the response buffer 1998 */ 1999 typedef struct smb_enumshare_info { 2000 uid_t es_posix_uid; 2001 uint16_t es_bufsize; 2002 char *es_buf; 2003 uint16_t es_ntotal; 2004 uint16_t es_nsent; 2005 uint16_t es_datasize; 2006 } smb_enumshare_info_t; 2007 2008 #ifdef __cplusplus 2009 } 2010 #endif 2011 2012 #endif /* _SMBSRV_SMB_KTYPES_H */ 2013