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