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