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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 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 62 struct smb_disp_entry; 63 struct smb_request; 64 struct smb_server; 65 struct smb_sd; 66 67 int smb_noop(void *, size_t, int); 68 69 #define SMB_AUDIT_STACK_DEPTH 16 70 #define SMB_AUDIT_BUF_MAX_REC 16 71 #define SMB_AUDIT_NODE 0x00000001 72 73 /* 74 * Maximum number of records returned in SMBsearch, SMBfind 75 * and SMBfindunique response. Value set to 10 for compatibility 76 * with Windows. 77 */ 78 #define SMB_MAX_SEARCH 10 79 80 #define SMB_SEARCH_ATTRIBUTES \ 81 (FILE_ATTRIBUTE_HIDDEN | \ 82 FILE_ATTRIBUTE_SYSTEM | \ 83 FILE_ATTRIBUTE_DIRECTORY) 84 85 #define SMB_SEARCH_HIDDEN(sattr) ((sattr) & FILE_ATTRIBUTE_HIDDEN) 86 #define SMB_SEARCH_SYSTEM(sattr) ((sattr) & FILE_ATTRIBUTE_SYSTEM) 87 #define SMB_SEARCH_DIRECTORY(sattr) ((sattr) & FILE_ATTRIBUTE_DIRECTORY) 88 #define SMB_SEARCH_ALL(sattr) ((sattr) & SMB_SEARCH_ATTRIBUTES) 89 90 typedef struct { 91 uint32_t anr_refcnt; 92 int anr_depth; 93 pc_t anr_stack[SMB_AUDIT_STACK_DEPTH]; 94 } smb_audit_record_node_t; 95 96 typedef struct { 97 int anb_index; 98 int anb_max_index; 99 smb_audit_record_node_t anb_records[SMB_AUDIT_BUF_MAX_REC]; 100 } smb_audit_buf_node_t; 101 102 #define SMB_WORKER_PRIORITY 99 103 /* 104 * Thread State Machine 105 * -------------------- 106 * 107 * T5 T0 108 * smb_thread_destroy() <-------+ +------- smb_thread_init() 109 * | | 110 * | v 111 * +-----------------------------+ 112 * | SMB_THREAD_STATE_EXITED |<---+ 113 * +-----------------------------+ | 114 * | T1 | 115 * v | 116 * +-----------------------------+ | 117 * | SMB_THREAD_STATE_STARTING | | 118 * +-----------------------------+ | 119 * | T2 | T4 120 * v | 121 * +-----------------------------+ | 122 * | SMB_THREAD_STATE_RUNNING | | 123 * +-----------------------------+ | 124 * | T3 | 125 * v | 126 * +-----------------------------+ | 127 * | SMB_THREAD_STATE_EXITING |----+ 128 * +-----------------------------+ 129 * 130 * Transition T0 131 * 132 * This transition is executed in smb_thread_init(). 133 * 134 * Transition T1 135 * 136 * This transition is executed in smb_thread_start(). 137 * 138 * Transition T2 139 * 140 * This transition is executed by the thread itself when it starts running. 141 * 142 * Transition T3 143 * 144 * This transition is executed by the thread itself in 145 * smb_thread_entry_point() just before calling thread_exit(). 146 * 147 * 148 * Transition T4 149 * 150 * This transition is executed in smb_thread_stop(). 151 * 152 * Transition T5 153 * 154 * This transition is executed in smb_thread_destroy(). 155 * 156 * Comments 157 * -------- 158 * 159 * The field smb_thread_aw_t contains a function pointer that knows how to 160 * awake the thread. It is a temporary solution to work around the fact that 161 * kernel threads (not part of a userspace process) cannot be signaled. 162 */ 163 typedef enum smb_thread_state { 164 SMB_THREAD_STATE_STARTING = 0, 165 SMB_THREAD_STATE_RUNNING, 166 SMB_THREAD_STATE_EXITING, 167 SMB_THREAD_STATE_EXITED 168 } smb_thread_state_t; 169 170 struct _smb_thread; 171 172 typedef void (*smb_thread_ep_t)(struct _smb_thread *, void *ep_arg); 173 typedef void (*smb_thread_aw_t)(struct _smb_thread *, void *aw_arg); 174 175 #define SMB_THREAD_MAGIC 0x534D4254 /* SMBT */ 176 177 typedef struct _smb_thread { 178 uint32_t sth_magic; 179 char sth_name[16]; 180 smb_thread_state_t sth_state; 181 kthread_t *sth_th; 182 kt_did_t sth_did; 183 smb_thread_ep_t sth_ep; 184 void *sth_ep_arg; 185 smb_thread_aw_t sth_aw; 186 void *sth_aw_arg; 187 boolean_t sth_kill; 188 kmutex_t sth_mtx; 189 kcondvar_t sth_cv; 190 } smb_thread_t; 191 192 /* 193 * Pool of IDs 194 * ----------- 195 * 196 * A pool of IDs is a pool of 16 bit numbers. It is implemented as a bitmap. 197 * A bit set to '1' indicates that that particular value has been allocated. 198 * The allocation process is done shifting a bit through the whole bitmap. 199 * The current position of that index bit is kept in the smb_idpool_t 200 * structure and represented by a byte index (0 to buffer size minus 1) and 201 * a bit index (0 to 7). 202 * 203 * The pools start with a size of 8 bytes or 64 IDs. Each time the pool runs 204 * out of IDs its current size is doubled until it reaches its maximum size 205 * (8192 bytes or 65536 IDs). The IDs 0 and 65535 are never given out which 206 * means that a pool can have a maximum number of 65534 IDs available. 207 */ 208 #define SMB_IDPOOL_MAGIC 0x4944504C /* IDPL */ 209 #define SMB_IDPOOL_MIN_SIZE 64 /* Number of IDs to begin with */ 210 #define SMB_IDPOOL_MAX_SIZE 64 * 1024 211 212 typedef struct smb_idpool { 213 uint32_t id_magic; 214 kmutex_t id_mutex; 215 uint8_t *id_pool; 216 uint32_t id_size; 217 uint8_t id_bit; 218 uint8_t id_bit_idx; 219 uint32_t id_idx; 220 uint32_t id_idx_msk; 221 uint32_t id_free_counter; 222 uint32_t id_max_free_counter; 223 } smb_idpool_t; 224 225 /* 226 * Maximum size of a Transport Data Unit when CAP_LARGE_READX and 227 * CAP_LARGE_WRITEX are not set. CAP_LARGE_READX/CAP_LARGE_WRITEX 228 * allow the payload to exceed the negotiated buffer size. 229 * 4 --> NBT/TCP Transport Header. 230 * 32 --> SMB Header 231 * 1 --> Word Count byte 232 * 510 --> Maximum Number of bytes of the Word Table (2 * 255) 233 * 2 --> Byte count of the data 234 * 65535 --> Maximum size of the data 235 * ----- 236 * 66084 237 */ 238 #define SMB_REQ_MAX_SIZE 66560 /* 65KB */ 239 #define SMB_XPRT_MAX_SIZE (SMB_REQ_MAX_SIZE + NETBIOS_HDR_SZ) 240 241 #define SMB_TXREQ_MAGIC 0X54524251 /* 'TREQ' */ 242 typedef struct { 243 uint32_t tr_magic; 244 list_node_t tr_lnd; 245 int tr_len; 246 uint8_t tr_buf[SMB_XPRT_MAX_SIZE]; 247 } smb_txreq_t; 248 249 #define SMB_TXLST_MAGIC 0X544C5354 /* 'TLST' */ 250 typedef struct { 251 uint32_t tl_magic; 252 kmutex_t tl_mutex; 253 boolean_t tl_active; 254 list_t tl_list; 255 } smb_txlst_t; 256 257 /* 258 * Maximum buffer size for NT is 37KB. If all clients are Windows 2000, this 259 * can be changed to 64KB. 37KB must be used with a mix of NT/Windows 2000 260 * clients because NT loses directory entries when values greater than 37KB are 261 * used. 262 * 263 * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to 264 * account for the NBT header. 265 */ 266 #define NBT_MAXBUF 8 267 #define SMB_NT_MAXBUF (37 * 1024) 268 269 #define OUTBUFSIZE (65 * 1024) 270 #define SMBHEADERSIZE 32 271 #define SMBND_HASH_MASK (0xFF) 272 #define MAX_IOVEC 512 273 #define MAX_READREF (8 * 1024) 274 275 #define SMB_WORKER_MIN 4 276 #define SMB_WORKER_DEFAULT 64 277 #define SMB_WORKER_MAX 1024 278 279 /* 280 * Fix align a pointer or offset appropriately so that fields will not 281 * cross word boundaries. 282 */ 283 #define PTRALIGN(x) \ 284 (((uintptr_t)(x) + (uintptr_t)(_POINTER_ALIGNMENT) - 1l) & \ 285 ~((uintptr_t)(_POINTER_ALIGNMENT) - 1l)) 286 287 /* 288 * native os types are defined in win32/smbinfo.h 289 */ 290 291 /* 292 * All 4 different time / date formats that will bee seen in SMB 293 */ 294 typedef struct { 295 uint16_t Day : 5; 296 uint16_t Month : 4; 297 uint16_t Year : 7; 298 } SMB_DATE; 299 300 typedef struct { 301 uint16_t TwoSeconds : 5; 302 uint16_t Minutes : 6; 303 uint16_t Hours : 5; 304 } SMB_TIME; 305 306 307 typedef uint32_t UTIME; /* seconds since Jan 1 1970 */ 308 309 typedef struct smb_malloc_list { 310 struct smb_malloc_list *forw; 311 struct smb_malloc_list *back; 312 } smb_malloc_list; 313 314 typedef struct smb_llist { 315 krwlock_t ll_lock; 316 list_t ll_list; 317 uint32_t ll_count; 318 uint64_t ll_wrop; 319 } smb_llist_t; 320 321 typedef struct smb_slist { 322 kmutex_t sl_mutex; 323 kcondvar_t sl_cv; 324 list_t sl_list; 325 uint32_t sl_count; 326 boolean_t sl_waiting; 327 } smb_slist_t; 328 329 typedef struct smb_session_list { 330 krwlock_t se_lock; 331 uint64_t se_wrop; 332 struct { 333 list_t lst; 334 uint32_t count; 335 } se_rdy; 336 struct { 337 list_t lst; 338 uint32_t count; 339 } se_act; 340 } smb_session_list_t; 341 342 typedef struct { 343 kcondvar_t rwx_cv; 344 kmutex_t rwx_mutex; 345 krwlock_t rwx_lock; 346 boolean_t rwx_waiting; 347 } smb_rwx_t; 348 349 /* NOTIFY CHANGE */ 350 351 typedef struct smb_notify_change_req { 352 list_node_t nc_lnd; 353 struct smb_node *nc_node; 354 uint32_t nc_reply_type; 355 uint32_t nc_flags; 356 } smb_notify_change_req_t; 357 358 /* 359 * SMB operates over a NetBIOS-over-TCP transport (NBT) or directly 360 * over TCP, which is also known as direct hosted NetBIOS-less SMB 361 * or SMB-over-TCP. 362 * 363 * NBT messages have a 4-byte header that defines the message type 364 * (8-bits), a 7-bit flags field and a 17-bit length. 365 * 366 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 367 * | TYPE | FLAGS |E| LENGTH | 368 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 369 * 370 * 8-bit type Defined in RFC 1002 371 * 7-bit flags Bits 0-6 reserved (must be 0) 372 * Bit 7: Length extension bit (E) 373 * 17-bit length Includes bit 7 of the flags byte 374 * 375 * 376 * SMB-over-TCP is defined to use a modified version of the NBT header 377 * containing an 8-bit message type and 24-bit message length. 378 * 379 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 380 * | TYPE | LENGTH | 381 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 382 * 383 * 8-bit type Must be 0 384 * 24-bit length 385 * 386 * The following structure is used to represent a generic, in-memory 387 * SMB transport header; it is not intended to map directly to either 388 * of the over-the-wire formats. 389 */ 390 typedef struct { 391 uint8_t xh_type; 392 uint32_t xh_length; 393 } smb_xprt_t; 394 395 int MBC_LENGTH(struct mbuf_chain *); 396 int MBC_MAXBYTES(struct mbuf_chain *); 397 void MBC_SETUP(struct mbuf_chain *, uint32_t); 398 void MBC_INIT(struct mbuf_chain *, uint32_t); 399 void MBC_FLUSH(struct mbuf_chain *); 400 void MBC_ATTACH_MBUF(struct mbuf_chain *, struct mbuf *); 401 void MBC_APPEND_MBUF(struct mbuf_chain *, struct mbuf *); 402 void MBC_ATTACH_BUF(struct mbuf_chain *MBC, unsigned char *BUF, int LEN); 403 int MBC_SHADOW_CHAIN(struct mbuf_chain *SUBMBC, struct mbuf_chain *MBC, 404 int OFF, int LEN); 405 406 #define MBC_ROOM_FOR(b, n) (((b)->chain_offset + (n)) <= (b)->max_bytes) 407 408 typedef struct smb_oplock { 409 uint64_t ol_sess_id; 410 kcondvar_t ol_cv; 411 kthread_t *ol_xthread; 412 struct smb_ofile *ol_ofile; 413 uint32_t ol_waiters_count; 414 uint8_t ol_level; 415 } smb_oplock_t; 416 417 #define DOS_ATTR_VALID 0x80000000 418 419 #define SMB_VFS_MAGIC 0x534D4256 /* 'SMBV' */ 420 421 typedef struct smb_vfs { 422 uint32_t sv_magic; 423 list_node_t sv_lnd; 424 uint32_t sv_refcnt; 425 vfs_t *sv_vfsp; 426 vnode_t *sv_rootvp; 427 } smb_vfs_t; 428 429 typedef struct smb_unexport { 430 list_node_t ux_lnd; 431 char ux_sharename[MAXNAMELEN]; 432 } smb_unexport_t; 433 434 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */ 435 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC) 436 437 typedef enum { 438 SMB_NODE_STATE_AVAILABLE = 0, 439 SMB_NODE_STATE_OPLOCK_GRANTED, 440 SMB_NODE_STATE_OPLOCK_BREAKING, 441 SMB_NODE_STATE_DESTROYING 442 } smb_node_state_t; 443 444 typedef struct smb_node { 445 uint32_t n_magic; 446 krwlock_t n_lock; 447 kmutex_t n_mutex; 448 list_node_t n_lnd; 449 smb_node_state_t n_state; 450 uint32_t n_refcnt; 451 uint32_t n_hashkey; 452 smb_llist_t *n_hash_bucket; 453 uint32_t n_orig_uid; 454 uint32_t n_open_count; 455 smb_llist_t n_ofile_list; 456 smb_llist_t n_lock_list; 457 struct smb_ofile *readonly_creator; 458 volatile int flags; /* FILE_NOTIFY_CHANGE_* */ 459 volatile int waiting_event; /* # of clients requesting FCN */ 460 smb_attr_t attr; 461 unsigned int what; 462 u_offset_t n_size; 463 smb_oplock_t n_oplock; 464 struct smb_node *dir_snode; /* Directory of node */ 465 struct smb_node *unnamed_stream_node; /* set in stream nodes */ 466 /* Credentials for delayed delete */ 467 cred_t *delete_on_close_cred; 468 char od_name[MAXNAMELEN]; 469 vnode_t *vp; 470 smb_audit_buf_node_t *n_audit_buf; 471 } smb_node_t; 472 473 #define NODE_FLAGS_NOTIFY_CHANGE 0x10000fff 474 #define NODE_OPLOCKS_IN_FORCE 0x0000f000 475 #define NODE_OPLOCK_NONE 0x00000000 476 #define NODE_EXCLUSIVE_OPLOCK 0x00001000 477 #define NODE_BATCH_OPLOCK 0x00002000 478 #define NODE_LEVEL_II_OPLOCK 0x00003000 479 #define NODE_CAP_LEVEL_II 0x00010000 480 #define NODE_PROTOCOL_LOCK 0x00020000 481 #define NODE_FLAGS_WRITE_THROUGH 0x00100000 482 #define NODE_FLAGS_SYNCATIME 0x00200000 483 #define NODE_FLAGS_LOCKED 0x00400000 484 #define NODE_FLAGS_ATTR_VALID 0x00800000 485 #define NODE_XATTR_DIR 0x01000000 486 #define NODE_FLAGS_CREATED 0x04000000 487 #define NODE_FLAGS_CHANGED 0x08000000 488 #define NODE_FLAGS_WATCH_TREE 0x10000000 489 #define NODE_FLAGS_SET_SIZE 0x20000000 490 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000 491 #define NODE_FLAGS_EXECUTABLE 0x80000000 492 493 #define OPLOCK_TYPE(n) ((n)->flags & NODE_OPLOCKS_IN_FORCE) 494 #define OPLOCKS_IN_FORCE(n) (OPLOCK_TYPE(n) != NODE_OPLOCK_NONE) 495 #define EXCLUSIVE_OPLOCK_IN_FORCE(n) \ 496 (OPLOCK_TYPE(n) == NODE_EXCLUSIVE_OPLOCK) 497 #define BATCH_OPLOCK_IN_FORCE(n) (OPLOCK_TYPE(n) == NODE_BATCH_OPLOCK) 498 #define LEVEL_II_OPLOCK_IN_FORCE(n) (OPLOCK_TYPE(n) == NODE_LEVEL_II_OPLOCK) 499 500 #define SMB_NODE_VFS(node) ((node)->vp->v_vfsp) 501 #define SMB_NODE_FSID(node) ((node)->vp->v_vfsp->vfs_fsid) 502 503 /* 504 * Based on section 2.6.1.2 (Connection Management) of the June 13, 505 * 1996 CIFS spec, a server may terminate the transport connection 506 * due to inactivity. The client software is expected to be able to 507 * automatically reconnect to the server if this happens. Like much 508 * of the useful background information, this section appears to 509 * have been dropped from later revisions of the document. 510 * 511 * Each session has an activity timestamp that's updated whenever a 512 * request is dispatched. If the session is idle, i.e. receives no 513 * requests, for SMB_SESSION_INACTIVITY_TIMEOUT minutes it will be 514 * closed. 515 * 516 * Each session has an I/O semaphore to serialize communication with 517 * the client. For example, after receiving a raw-read request, the 518 * server is not allowed to send an oplock break to the client until 519 * after it has sent the raw-read data. 520 */ 521 #define SMB_SESSION_INACTIVITY_TIMEOUT (15 * 60) 522 523 #define SMB_SESSION_OFILE_MAX (16 * 1024) 524 525 /* 526 * When a connection is set up we need to remember both the client 527 * (peer) IP address and the local IP address used to establish the 528 * connection. When a client connects with a vc number of zero, we 529 * are supposed to abort any existing connections with that client 530 * (see notes in smb_negotiate.c and smb_session_setup_andx.c). For 531 * servers with multiple network interfaces or IP aliases, however, 532 * each interface has to be managed independently since the client 533 * is not aware of the server configuration. We have to allow the 534 * client to establish a connection on each interface with a vc 535 * number of zero without aborting the other connections. 536 * 537 * ipaddr: the client (peer) IP address for the session. 538 * local_ipaddr: the local IP address used to connect to the server. 539 */ 540 541 #define SMB_MAC_KEYSZ 512 542 543 struct smb_sign { 544 unsigned int seqnum; 545 unsigned int mackey_len; 546 unsigned int flags; 547 unsigned char mackey[SMB_MAC_KEYSZ]; 548 }; 549 550 #define SMB_SIGNING_ENABLED 1 551 #define SMB_SIGNING_CHECK 2 552 553 /* 554 * Session State Machine 555 * --------------------- 556 * 557 * +-----------------------------+ +------------------------------+ 558 * | SMB_SESSION_STATE_CONNECTED | | SMB_SESSION_STATE_TERMINATED | 559 * +-----------------------------+ +------------------------------+ 560 * T0| ^ 561 * +--------------------+ |T13 562 * v |T14 | 563 * +-------------------------------+ | +--------------------------------+ 564 * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED | 565 * +-------------------------------+ +--------------------------------+ 566 * T1| ^ ^ ^ ^ 567 * +----------+ |T9 | | | 568 * v | | | | 569 * +------------------------------+ | | | 570 * | SMB_SESSION_STATE_NEGOTIATED | | | | 571 * +------------------------------+ | | | 572 * ^| ^| | ^ | | | 573 * +----------------+| || | | | | | 574 * |+----------------+ || T7| |T8 | | | 575 * || || | | | | | 576 * || +----------------+| | | | | | 577 * || |+----------------+ | | | | | 578 * || || v | | | | 579 * || || +-----------------------------------+ T10| | | 580 * || || | SMB_SESSION_STATE_OPLOCK_BREAKING |----+ | | 581 * || || +-----------------------------------+ | | 582 * || ||T5 | | 583 * || |+-->+-----------------------------------+ T11| | 584 * || |T6 | SMB_SESSION_STATE_READ_RAW_ACTIVE |------+ | 585 * || +----+-----------------------------------+ | 586 * ||T3 | 587 * |+------->+------------------------------------+ T12| 588 * |T4 | SMB_SESSION_STATE_WRITE_RAW_ACTIVE |-------+ 589 * +---------+------------------------------------+ 590 * 591 * Transition T0 592 * 593 * 594 * 595 * Transition T1 596 * 597 * 598 * 599 * Transition T2 600 * 601 * 602 * 603 * Transition T3 604 * 605 * 606 * 607 * Transition T4 608 * 609 * 610 * 611 * Transition T5 612 * 613 * 614 * 615 * Transition T6 616 * 617 * 618 * 619 * Transition T7 620 * 621 * 622 * 623 * Transition T8 624 * 625 * 626 * 627 * Transition T9 628 * 629 * 630 * 631 * Transition T10 632 * 633 * 634 * 635 * Transition T11 636 * 637 * 638 * 639 * Transition T12 640 * 641 * 642 * 643 * Transition T13 644 * 645 * 646 * 647 * Transition T14 648 * 649 * 650 * 651 */ 652 #define SMB_SESSION_MAGIC 0x53455353 /* 'SESS' */ 653 #define SMB_SESSION_VALID(p) ASSERT((p)->s_magic == SMB_SESSION_MAGIC) 654 655 typedef enum { 656 SMB_SESSION_STATE_INITIALIZED = 0, 657 SMB_SESSION_STATE_DISCONNECTED, 658 SMB_SESSION_STATE_CONNECTED, 659 SMB_SESSION_STATE_ESTABLISHED, 660 SMB_SESSION_STATE_NEGOTIATED, 661 SMB_SESSION_STATE_OPLOCK_BREAKING, 662 SMB_SESSION_STATE_WRITE_RAW_ACTIVE, 663 SMB_SESSION_STATE_READ_RAW_ACTIVE, 664 SMB_SESSION_STATE_TERMINATED, 665 SMB_SESSION_STATE_SENTINEL 666 } smb_session_state_t; 667 668 typedef struct smb_session { 669 uint32_t s_magic; 670 smb_rwx_t s_lock; 671 list_node_t s_lnd; 672 uint64_t s_kid; 673 smb_session_state_t s_state; 674 uint32_t s_flags; 675 int s_write_raw_status; 676 kthread_t *s_thread; 677 kt_did_t s_ktdid; 678 smb_kmod_cfg_t s_cfg; 679 kmem_cache_t *s_cache; 680 kmem_cache_t *s_cache_request; 681 struct smb_server *s_server; 682 int32_t s_gmtoff; 683 uint32_t keep_alive; 684 uint64_t opentime; 685 uint16_t vcnumber; 686 uint16_t s_local_port; 687 smb_inaddr_t ipaddr; 688 smb_inaddr_t local_ipaddr; 689 char workstation[SMB_PI_MAX_HOST]; 690 int dialect; 691 int native_os; 692 uint32_t capabilities; 693 struct smb_sign signing; 694 695 ksocket_t sock; 696 697 smb_slist_t s_req_list; 698 smb_llist_t s_xa_list; 699 smb_llist_t s_user_list; 700 smb_idpool_t s_uid_pool; 701 smb_txlst_t s_txlst; 702 703 volatile uint32_t s_tree_cnt; 704 volatile uint32_t s_file_cnt; 705 volatile uint32_t s_dir_cnt; 706 707 uint16_t secmode; 708 uint32_t sesskey; 709 uint32_t challenge_len; 710 unsigned char challenge_key[8]; 711 unsigned char MAC_key[44]; 712 int64_t activity_timestamp; 713 /* 714 * Maximum negotiated buffer size between SMB client and server 715 * in SMB_SESSION_SETUP_ANDX 716 */ 717 uint16_t smb_msg_size; 718 uchar_t *outpipe_data; 719 int outpipe_datalen; 720 int outpipe_cookie; 721 uint32_t s_oplock_brkcntr; 722 list_t s_oplock_brkreqs; 723 } smb_session_t; 724 725 #define SMB_USER_MAGIC 0x55534552 /* 'USER' */ 726 727 #define SMB_USER_FLAG_GUEST SMB_ATF_GUEST 728 #define SMB_USER_FLAG_IPC SMB_ATF_ANON 729 #define SMB_USER_FLAG_ADMIN SMB_ATF_ADMIN 730 #define SMB_USER_FLAG_POWER_USER SMB_ATF_POWERUSER 731 #define SMB_USER_FLAG_BACKUP_OPERATOR SMB_ATF_BACKUPOP 732 733 #define SMB_USER_PRIV_TAKE_OWNERSHIP 0x00000001 734 #define SMB_USER_PRIV_BACKUP 0x00000002 735 #define SMB_USER_PRIV_RESTORE 0x00000004 736 #define SMB_USER_PRIV_SECURITY 0x00000008 737 738 739 typedef enum { 740 SMB_USER_STATE_LOGGED_IN = 0, 741 SMB_USER_STATE_LOGGING_OFF, 742 SMB_USER_STATE_LOGGED_OFF, 743 SMB_USER_STATE_SENTINEL 744 } smb_user_state_t; 745 746 typedef struct smb_user { 747 uint32_t u_magic; 748 list_node_t u_lnd; 749 kmutex_t u_mutex; 750 smb_user_state_t u_state; 751 752 struct smb_server *u_server; 753 smb_session_t *u_session; 754 uint16_t u_name_len; 755 char *u_name; 756 uint16_t u_domain_len; 757 char *u_domain; 758 time_t u_logon_time; 759 cred_t *u_cred; 760 cred_t *u_privcred; 761 762 smb_llist_t u_tree_list; 763 smb_idpool_t u_tid_pool; 764 765 uint32_t u_refcnt; 766 uint32_t u_flags; 767 uint32_t u_privileges; 768 uint16_t u_uid; 769 uint32_t u_audit_sid; 770 } smb_user_t; 771 772 #define SMB_TREE_MAGIC 0x54524545 /* 'TREE' */ 773 774 #define SMB_TYPENAMELEN _ST_FSTYPSZ 775 #define SMB_VOLNAMELEN 32 776 777 #define SMB_TREE_READONLY 0x00000001 778 #define SMB_TREE_SUPPORTS_ACLS 0x00000002 779 #define SMB_TREE_STREAMS 0x00000004 780 #define SMB_TREE_CASEINSENSITIVE 0x00000008 781 #define SMB_TREE_NO_CASESENSITIVE 0x00000010 782 #define SMB_TREE_NO_EXPORT 0x00000020 783 #define SMB_TREE_NO_OPLOCKS 0x00000040 784 #define SMB_TREE_NO_ATIME 0x00000080 785 #define SMB_TREE_XVATTR 0x00000100 786 #define SMB_TREE_DIRENTFLAGS 0x00000200 787 #define SMB_TREE_ACLONCREATE 0x00000400 788 #define SMB_TREE_ACEMASKONACCESS 0x00000800 789 #define SMB_TREE_NFS_MOUNTED 0x00001000 790 791 typedef enum { 792 SMB_TREE_STATE_CONNECTED = 0, 793 SMB_TREE_STATE_DISCONNECTING, 794 SMB_TREE_STATE_DISCONNECTED, 795 SMB_TREE_STATE_SENTINEL 796 } smb_tree_state_t; 797 798 typedef struct smb_tree { 799 uint32_t t_magic; 800 kmutex_t t_mutex; 801 list_node_t t_lnd; 802 smb_tree_state_t t_state; 803 804 struct smb_server *t_server; 805 smb_session_t *t_session; 806 smb_user_t *t_user; 807 smb_node_t *t_snode; 808 809 smb_llist_t t_ofile_list; 810 smb_idpool_t t_fid_pool; 811 812 smb_llist_t t_odir_list; 813 smb_idpool_t t_odid_pool; 814 815 uint32_t t_refcnt; 816 uint32_t t_flags; 817 int32_t t_res_type; 818 uint16_t t_tid; 819 uint16_t t_umask; 820 char t_sharename[MAXNAMELEN]; 821 char t_resource[MAXPATHLEN]; 822 char t_typename[SMB_TYPENAMELEN]; 823 char t_volume[SMB_VOLNAMELEN]; 824 acl_type_t t_acltype; 825 uint32_t t_access; 826 } smb_tree_t; 827 828 #define SMB_TREE_VFS(tree) ((tree)->t_snode->vp->v_vfsp) 829 #define SMB_TREE_FSID(tree) ((tree)->t_snode->vp->v_vfsp->vfs_fsid) 830 831 #define SMB_TREE_IS_READONLY(sr) \ 832 ((sr) != NULL && (sr)->tid_tree != NULL && \ 833 !((sr)->tid_tree->t_access & ACE_ALL_WRITE_PERMS)) 834 835 #define SMB_TREE_IS_CASEINSENSITIVE(sr) \ 836 (((sr) && (sr)->tid_tree) ? \ 837 smb_tree_has_feature((sr)->tid_tree, SMB_TREE_CASEINSENSITIVE) : 0) 838 839 #define SMB_TREE_HAS_ACCESS(sr, acemask) \ 840 ((sr) == NULL ? ACE_ALL_PERMS : ( \ 841 (((sr) && (sr)->tid_tree) ? \ 842 (((sr)->tid_tree->t_access) & (acemask)) : 0))) 843 844 /* 845 * SMB_TREE_CONTAINS_NODE is used to check that a node is in the same 846 * file system as the tree. 847 */ 848 #define SMB_TREE_CONTAINS_NODE(sr, node) \ 849 (((sr) && (sr)->tid_tree) ? \ 850 (SMB_TREE_VFS((sr)->tid_tree) == SMB_NODE_VFS(node)) : 1) 851 852 /* 853 * SMB_NODE_IS_READONLY(node) 854 * 855 * This macro indicates whether the DOS readonly bit is set in the node's 856 * attribute cache. The cache reflects what is on-disk. 857 */ 858 859 #define SMB_NODE_IS_READONLY(node) \ 860 ((node) && (node)->attr.sa_dosattr & FILE_ATTRIBUTE_READONLY) 861 862 /* 863 * SMB_OFILE_IS_READONLY reflects whether an ofile is readonly or not. 864 * The macro takes into account 865 * - the tree readonly state 866 * - the node readonly state 867 * - whether the specified ofile is the readonly creator 868 * The readonly creator has write permission until the ofile is closed. 869 */ 870 871 #define SMB_OFILE_IS_READONLY(of) \ 872 (((of)->f_flags & SMB_OFLAGS_READONLY) || \ 873 SMB_NODE_IS_READONLY((of)->f_node) || \ 874 (((of)->f_node->readonly_creator) && \ 875 ((of)->f_node->readonly_creator != (of)))) 876 877 /* 878 * SMB_PATHFILE_IS_READONLY indicates whether or not a file is 879 * readonly when the caller has a path rather than an ofile. Unlike 880 * SMB_OFILE_IS_READONLY, the caller cannot be the readonly creator, 881 * since that requires an ofile. 882 */ 883 884 #define SMB_PATHFILE_IS_READONLY(sr, node) \ 885 (SMB_TREE_IS_READONLY((sr)) || \ 886 SMB_NODE_IS_READONLY((node)) || \ 887 ((node)->readonly_creator)) 888 889 #define PIPE_STATE_AUTH_VERIFY 0x00000001 890 891 /* 892 * Data structure for SMB_FTYPE_MESG_PIPE ofiles, which is used 893 * at the interface between SMB and NDR RPC. 894 */ 895 typedef struct smb_opipe { 896 kmutex_t p_mutex; 897 kcondvar_t p_cv; 898 char *p_name; 899 uint32_t p_busy; 900 smb_opipe_hdr_t p_hdr; 901 smb_opipe_context_t p_context; 902 uint8_t *p_doorbuf; 903 uint8_t *p_data; 904 } smb_opipe_t; 905 906 /* 907 * The of_ftype of an open file should contain the SMB_FTYPE value 908 * (cifs.h) returned when the file/pipe was opened. The following 909 * assumptions are currently made: 910 * 911 * File Type Node PipeInfo 912 * --------- -------- -------- 913 * SMB_FTYPE_DISK Valid Null 914 * SMB_FTYPE_BYTE_PIPE Undefined Undefined 915 * SMB_FTYPE_MESG_PIPE Null Valid 916 * SMB_FTYPE_PRINTER Undefined Undefined 917 * SMB_FTYPE_UNKNOWN Undefined Undefined 918 */ 919 920 /* 921 * Some flags for ofile structure 922 * 923 * SMB_OFLAGS_SET_DELETE_ON_CLOSE 924 * Set this flag when the corresponding open operation whose 925 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any 926 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE 927 * will be set for the file node upon close. 928 */ 929 930 #define SMB_OFLAGS_READONLY 0x0001 931 #define SMB_OFLAGS_EXECONLY 0x0002 932 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004 933 #define SMB_OFLAGS_LLF_POS_VALID 0x0008 934 935 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */ 936 #define SMB_OFILE_VALID(p) ASSERT((p)->f_magic == SMB_OFILE_MAGIC) 937 938 typedef enum { 939 SMB_OFILE_STATE_OPEN = 0, 940 SMB_OFILE_STATE_CLOSING, 941 SMB_OFILE_STATE_CLOSED, 942 SMB_OFILE_STATE_SENTINEL 943 } smb_ofile_state_t; 944 945 typedef struct smb_ofile { 946 uint32_t f_magic; 947 kmutex_t f_mutex; 948 list_node_t f_lnd; 949 list_node_t f_nnd; 950 smb_ofile_state_t f_state; 951 952 struct smb_server *f_server; 953 smb_session_t *f_session; 954 smb_user_t *f_user; 955 smb_tree_t *f_tree; 956 smb_node_t *f_node; 957 smb_opipe_t *f_pipe; 958 959 uint32_t f_uniqid; 960 uint32_t f_refcnt; 961 uint64_t f_seek_pos; 962 uint32_t f_flags; 963 uint32_t f_granted_access; 964 uint32_t f_share_access; 965 uint32_t f_create_options; 966 uint16_t f_fid; 967 uint16_t f_opened_by_pid; 968 uint16_t f_ftype; 969 uint64_t f_llf_pos; 970 int f_mode; 971 cred_t *f_cr; 972 pid_t f_pid; 973 boolean_t f_oplock_granted; 974 boolean_t f_oplock_exit; 975 } smb_ofile_t; 976 977 #define SMB_ODIR_MAGIC 0x4F444952 /* 'ODIR' */ 978 #define SMB_ODIR_BUFSIZE (8 * 1024) 979 980 typedef enum { 981 SMB_ODIR_STATE_OPEN = 0, 982 SMB_ODIR_STATE_CLOSING, 983 SMB_ODIR_STATE_CLOSED, 984 SMB_ODIR_STATE_SENTINEL 985 } smb_odir_state_t; 986 987 typedef enum { 988 SMB_ODIR_RESUME_IDX, 989 SMB_ODIR_RESUME_COOKIE, 990 SMB_ODIR_RESUME_FNAME 991 } smb_odir_resume_type_t; 992 993 typedef struct smb_odir_resume { 994 smb_odir_resume_type_t or_type; 995 int or_idx; 996 uint32_t or_cookie; 997 char *or_fname; 998 } smb_odir_resume_t; 999 1000 typedef struct smb_odir { 1001 uint32_t d_magic; 1002 kmutex_t d_mutex; 1003 list_node_t d_lnd; 1004 smb_odir_state_t d_state; 1005 smb_session_t *d_session; 1006 smb_user_t *d_user; 1007 smb_tree_t *d_tree; 1008 smb_node_t *d_dnode; 1009 uint16_t d_odid; 1010 uint16_t d_opened_by_pid; 1011 uint16_t d_sattr; 1012 uint32_t d_refcnt; 1013 1014 boolean_t d_wildcards; 1015 boolean_t d_ignore_case; 1016 boolean_t d_xat; 1017 boolean_t d_eof; 1018 boolean_t d_is_edp; 1019 int d_bufsize; 1020 uint64_t d_offset; 1021 union { 1022 char *u_bufptr; 1023 edirent_t *u_edp; 1024 dirent64_t *u_dp; 1025 } d_u; 1026 uint32_t d_cookies[SMB_MAX_SEARCH]; 1027 char d_pattern[MAXNAMELEN]; 1028 char d_buf[SMB_ODIR_BUFSIZE]; 1029 } smb_odir_t; 1030 #define d_bufptr d_u.u_bufptr 1031 #define d_edp d_u.u_edp 1032 #define d_dp d_u.u_dp 1033 1034 typedef struct smb_odirent { 1035 char od_name[MAXNAMELEN]; /* on disk name */ 1036 ino64_t od_ino; 1037 uint32_t od_eflags; 1038 } smb_odirent_t; 1039 1040 typedef struct smb_fileinfo { 1041 char fi_name[MAXNAMELEN]; 1042 char fi_name83[SMB_SHORTNAMELEN]; 1043 char fi_shortname[SMB_SHORTNAMELEN]; 1044 uint32_t fi_cookie; 1045 uint32_t fi_dosattr; /* DOS attributes */ 1046 uint64_t fi_nodeid; /* file system node id */ 1047 uint64_t fi_size; /* file size in bytes */ 1048 uint64_t fi_alloc_size; /* allocation size in bytes */ 1049 timestruc_t fi_atime; /* last access */ 1050 timestruc_t fi_mtime; /* last modification */ 1051 timestruc_t fi_ctime; /* last status change */ 1052 timestruc_t fi_crtime; /* file creation */ 1053 } smb_fileinfo_t; 1054 1055 typedef struct smb_streaminfo { 1056 uint64_t si_size; 1057 char si_name[MAXPATHLEN]; 1058 } smb_streaminfo_t; 1059 1060 #define SMB_LOCK_MAGIC 0x4C4F434B /* 'LOCK' */ 1061 1062 typedef struct smb_lock { 1063 uint32_t l_magic; 1064 kmutex_t l_mutex; 1065 list_node_t l_lnd; 1066 kcondvar_t l_cv; 1067 1068 list_node_t l_conflict_lnd; 1069 smb_slist_t l_conflict_list; 1070 1071 smb_session_t *l_session; 1072 smb_ofile_t *l_file; 1073 struct smb_request *l_sr; 1074 1075 uint32_t l_flags; 1076 uint64_t l_session_kid; 1077 struct smb_lock *l_blocked_by; /* Debug info only */ 1078 1079 uint16_t l_pid; 1080 uint16_t l_uid; 1081 uint32_t l_type; 1082 uint64_t l_start; 1083 uint64_t l_length; 1084 clock_t l_end_time; 1085 } smb_lock_t; 1086 1087 #define SMB_LOCK_FLAG_INDEFINITE 0x0004 1088 #define SMB_LOCK_INDEFINITE_WAIT(lock) \ 1089 ((lock)->l_flags & SMB_LOCK_FLAG_INDEFINITE) 1090 1091 #define SMB_LOCK_TYPE_READWRITE 101 1092 #define SMB_LOCK_TYPE_READONLY 102 1093 1094 typedef struct vardata_block { 1095 uint8_t vdb_tag; 1096 uint32_t vdb_len; 1097 struct uio vdb_uio; 1098 struct iovec vdb_iovec[MAX_IOVEC]; 1099 } smb_vdb_t; 1100 1101 #define SMB_RW_MAGIC 0x52445257 /* 'RDRW' */ 1102 1103 typedef struct smb_rw_param { 1104 uint32_t rw_magic; 1105 smb_vdb_t rw_vdb; 1106 uint64_t rw_offset; 1107 uint32_t rw_last_write; 1108 uint16_t rw_mode; 1109 uint32_t rw_count; 1110 uint16_t rw_mincnt; 1111 uint16_t rw_dsoff; /* SMB data offset */ 1112 uint8_t rw_andx; /* SMB secondary andx command */ 1113 } smb_rw_param_t; 1114 1115 /* 1116 * fs_query_info 1117 */ 1118 typedef struct smb_fqi { 1119 char *path; 1120 uint16_t srch_attr; 1121 smb_node_t *dir_snode; 1122 smb_attr_t dir_attr; 1123 char last_comp[MAXNAMELEN]; 1124 int last_comp_was_found; 1125 char last_comp_od[MAXNAMELEN]; 1126 smb_node_t *last_snode; 1127 smb_attr_t last_attr; 1128 } smb_fqi_t; 1129 1130 #define SMB_NULL_FQI_NODES(fqi) \ 1131 (fqi).last_snode = NULL; \ 1132 (fqi).dir_snode = NULL; 1133 1134 #define FQM_DIR_MUST_EXIST 1 1135 #define FQM_PATH_MUST_EXIST 2 1136 #define FQM_PATH_MUST_NOT_EXIST 3 1137 1138 #define OPLOCK_MIN_TIMEOUT (5 * 1000) 1139 #define OPLOCK_STD_TIMEOUT (15 * 1000) 1140 #define OPLOCK_RETRIES 2 1141 1142 typedef struct { 1143 uint32_t severity; 1144 uint32_t status; 1145 uint16_t errcls; 1146 uint16_t errcode; 1147 } smb_error_t; 1148 1149 typedef struct open_param { 1150 smb_fqi_t fqi; 1151 uint16_t omode; 1152 uint16_t ofun; 1153 uint32_t nt_flags; 1154 uint32_t timeo; 1155 uint32_t dattr; 1156 timestruc_t crtime; 1157 timestruc_t mtime; 1158 uint64_t dsize; 1159 uint32_t desired_access; 1160 uint32_t share_access; 1161 uint32_t create_options; 1162 uint32_t create_disposition; 1163 boolean_t created_readonly; 1164 uint32_t ftype; 1165 uint32_t devstate; 1166 uint32_t action_taken; 1167 uint64_t fileid; 1168 uint32_t rootdirfid; 1169 /* This is only set by NTTransactCreate */ 1170 struct smb_sd *sd; 1171 uint8_t op_oplock_level; 1172 } open_param_t; 1173 1174 #define SMB_OPLOCK_NONE 0 1175 #define SMB_OPLOCK_EXCLUSIVE 1 1176 #define SMB_OPLOCK_BATCH 2 1177 #define SMB_OPLOCK_LEVEL_II 3 1178 1179 /* 1180 * SMB Request State Machine 1181 * ------------------------- 1182 * 1183 * T4 +------+ T0 1184 * +--------------------------->| FREE |---------------------------+ 1185 * | +------+ | 1186 * +-----------+ | 1187 * | COMPLETED | | 1188 * +-----------+ 1189 * ^ | 1190 * | T15 +----------+ v 1191 * +------------+ T6 | | +--------------+ 1192 * | CLEANED_UP |<-----------------| CANCELED | | INITIALIZING | 1193 * +------------+ | | +--------------+ 1194 * | ^ +----------+ | 1195 * | | ^ ^ ^ ^ | 1196 * | | +-------------+ | | | | 1197 * | | T3 | | | | T13 | T1 1198 * | +-------------------------+ | | +----------------------+ | 1199 * +----------------------------+ | | | | | 1200 * T16 | | | | +-----------+ | | 1201 * | \/ | | T5 | | v 1202 * +-----------------+ | T12 +--------+ | T2 +-----------+ 1203 * | EVENT_OCCURRED |------------->| ACTIVE |<--------------------| SUBMITTED | 1204 * +-----------------+ | +--------+ | +-----------+ 1205 * ^ | | ^ | | 1206 * | | T8 | | | T7 | 1207 * | T10 T9 | +----------+ | +-------+ | T11 1208 * | | | +-------+ | | 1209 * | | | T14 | | | 1210 * | | v | v | 1211 * +----------------------+ +--------------+ 1212 * | WAITING_EVENT | | WAITING_LOCK | 1213 * +----------------------+ +--------------+ 1214 * 1215 * 1216 * 1217 * 1218 * 1219 * Transition T0 1220 * 1221 * This transition occurs when the request is allocated and is still under the 1222 * control of the session thread. 1223 * 1224 * Transition T1 1225 * 1226 * This transition occurs when the session thread dispatches a task to treat the 1227 * request. 1228 * 1229 * Transition T2 1230 * 1231 * 1232 * 1233 * Transition T3 1234 * 1235 * A request completes and smbsr_cleanup is called to release resources 1236 * associated with the request (but not the smb_request_t itself). This 1237 * includes references on smb_ofile_t, smb_node_t, and other structures. 1238 * CLEANED_UP state exists to detect if we attempt to cleanup a request 1239 * multiple times and to allow us to detect that we are accessing a 1240 * request that has already been cleaned up. 1241 * 1242 * Transition T4 1243 * 1244 * 1245 * 1246 * Transition T5 1247 * 1248 * 1249 * 1250 * Transition T6 1251 * 1252 * 1253 * 1254 * Transition T7 1255 * 1256 * 1257 * 1258 * Transition T8 1259 * 1260 * 1261 * 1262 * Transition T9 1263 * 1264 * 1265 * 1266 * Transition T10 1267 * 1268 * 1269 * 1270 * Transition T11 1271 * 1272 * 1273 * 1274 * Transition T12 1275 * 1276 * 1277 * 1278 * Transition T13 1279 * 1280 * 1281 * 1282 * Transition T14 1283 * 1284 * 1285 * 1286 * Transition T15 1287 * 1288 * Request processing is completed (control returns from smb_dispatch) 1289 * 1290 * Transition T16 1291 * 1292 * Multipart (andx) request was cleaned up with smbsr_cleanup but more "andx" 1293 * sections remain to be processed. 1294 * 1295 */ 1296 1297 #define SMB_REQ_MAGIC 0x534D4252 /* 'SMBR' */ 1298 #define SMB_REQ_VALID(p) ASSERT((p)->sr_magic == SMB_REQ_MAGIC) 1299 1300 typedef enum smb_req_state { 1301 SMB_REQ_STATE_FREE = 0, 1302 SMB_REQ_STATE_INITIALIZING, 1303 SMB_REQ_STATE_SUBMITTED, 1304 SMB_REQ_STATE_ACTIVE, 1305 SMB_REQ_STATE_WAITING_EVENT, 1306 SMB_REQ_STATE_EVENT_OCCURRED, 1307 SMB_REQ_STATE_WAITING_LOCK, 1308 SMB_REQ_STATE_COMPLETED, 1309 SMB_REQ_STATE_CANCELED, 1310 SMB_REQ_STATE_CLEANED_UP, 1311 SMB_REQ_STATE_SENTINEL 1312 } smb_req_state_t; 1313 1314 typedef struct smb_request { 1315 uint32_t sr_magic; 1316 kmutex_t sr_mutex; 1317 list_node_t sr_session_lnd; 1318 smb_req_state_t sr_state; 1319 boolean_t sr_keep; 1320 kmem_cache_t *sr_cache; 1321 struct smb_server *sr_server; 1322 pid_t *sr_pid; 1323 int32_t sr_gmtoff; 1324 smb_session_t *session; 1325 smb_kmod_cfg_t *sr_cfg; 1326 smb_notify_change_req_t sr_ncr; 1327 1328 /* Info from session service header */ 1329 uint32_t sr_req_length; /* Excluding NBT header */ 1330 1331 /* Request buffer excluding NBT header */ 1332 void *sr_request_buf; 1333 1334 /* Fields for raw writes */ 1335 uint32_t sr_raw_data_length; 1336 void *sr_raw_data_buf; 1337 1338 smb_lock_t *sr_awaiting; 1339 struct mbuf_chain command; 1340 struct mbuf_chain reply; 1341 struct mbuf_chain raw_data; 1342 smb_malloc_list request_storage; 1343 struct smb_xa *r_xa; 1344 int andx_prev_wct; 1345 int cur_reply_offset; 1346 int orig_request_hdr; 1347 unsigned int reply_seqnum; /* reply sequence number */ 1348 unsigned char first_smb_com; /* command code */ 1349 unsigned char smb_com; /* command code */ 1350 1351 uint8_t smb_rcls; /* error code class */ 1352 uint8_t smb_reh; /* rsvd (AH DOS INT-24 ERR) */ 1353 uint16_t smb_err; /* error code */ 1354 smb_error_t smb_error; 1355 1356 uint8_t smb_flg; /* flags */ 1357 uint16_t smb_flg2; /* flags */ 1358 uint16_t smb_pid_high; /* high part of pid */ 1359 unsigned char smb_sig[8]; /* signiture */ 1360 uint16_t smb_tid; /* tree id # */ 1361 uint16_t smb_pid; /* caller's process id # */ 1362 uint16_t smb_uid; /* user id # */ 1363 uint16_t smb_mid; /* mutiplex id # */ 1364 unsigned char smb_wct; /* count of parameter words */ 1365 uint16_t smb_bcc; /* data byte count */ 1366 1367 /* Parameters */ 1368 struct mbuf_chain smb_vwv; /* variable width value */ 1369 1370 /* Data */ 1371 struct mbuf_chain smb_data; 1372 1373 uint16_t smb_fid; /* not in hdr, but common */ 1374 1375 unsigned char andx_com; 1376 uint16_t andx_off; 1377 1378 struct smb_tree *tid_tree; 1379 struct smb_ofile *fid_ofile; 1380 smb_user_t *uid_user; 1381 1382 union { 1383 struct tcon { 1384 char *path; 1385 char *service; 1386 int pwdlen; 1387 char *password; 1388 uint16_t flags; 1389 uint16_t optional_support; 1390 } tcon; 1391 1392 struct dirop { 1393 smb_fqi_t fqi; 1394 smb_fqi_t dst_fqi; 1395 } dirop; 1396 1397 open_param_t open; 1398 smb_rw_param_t *rw; 1399 uint32_t timestamp; 1400 } arg; 1401 1402 cred_t *user_cr; 1403 kthread_t *sr_worker; 1404 } smb_request_t; 1405 1406 #define SMB_READ_PROTOCOL(smb_nh_ptr) \ 1407 LE_IN32(((smb_nethdr_t *)(smb_nh_ptr))->sh_protocol) 1408 1409 #define SMB_PROTOCOL_MAGIC_INVALID(rd_sr) \ 1410 (SMB_READ_PROTOCOL((rd_sr)->sr_request_buf) != SMB_PROTOCOL_MAGIC) 1411 1412 #define SMB_READ_COMMAND(smb_nh_ptr) \ 1413 (((smb_nethdr_t *)(smb_nh_ptr))->sh_command) 1414 1415 #define SMB_IS_WRITERAW(rd_sr) \ 1416 (SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_WRITE_RAW) 1417 1418 1419 #define SR_FLG_OFFSET 9 1420 1421 #define MAX_TRANS_NAME 64 1422 1423 #define SMB_XA_FLAG_OPEN 0x0001 1424 #define SMB_XA_FLAG_CLOSE 0x0002 1425 #define SMB_XA_FLAG_COMPLETE 0x0004 1426 #define SMB_XA_CLOSED(xa) (!((xa)->xa_flags & SMB_XA_FLAG_OPEN)) 1427 1428 #define SMB_XA_MAGIC 0x534D4258 /* 'SMBX' */ 1429 1430 typedef struct smb_xa { 1431 uint32_t xa_magic; 1432 kmutex_t xa_mutex; 1433 list_node_t xa_lnd; 1434 1435 uint32_t xa_refcnt; 1436 uint32_t xa_flags; 1437 1438 struct smb_session *xa_session; 1439 1440 unsigned char smb_com; /* which TRANS type */ 1441 unsigned char smb_flg; /* flags */ 1442 uint16_t smb_flg2; /* flags */ 1443 uint16_t smb_tid; /* tree id number */ 1444 uint16_t smb_pid; /* caller's process id number */ 1445 uint16_t smb_uid; /* user id number */ 1446 uint32_t smb_func; /* NT_TRANS function */ 1447 1448 uint16_t xa_smb_mid; /* mutiplex id number */ 1449 uint16_t xa_smb_fid; /* TRANS2 secondary */ 1450 1451 unsigned int reply_seqnum; /* reply sequence number */ 1452 1453 uint32_t smb_tpscnt; /* total parameter bytes being sent */ 1454 uint32_t smb_tdscnt; /* total data bytes being sent */ 1455 uint32_t smb_mprcnt; /* max parameter bytes to return */ 1456 uint32_t smb_mdrcnt; /* max data bytes to return */ 1457 uint32_t smb_msrcnt; /* max setup words to return */ 1458 uint32_t smb_flags; /* additional information: */ 1459 /* bit 0 - if set, disconnect TID in smb_tid */ 1460 /* bit 1 - if set, transaction is one way */ 1461 /* (no final response) */ 1462 int32_t smb_timeout; /* number of milliseconds to await completion */ 1463 uint32_t smb_suwcnt; /* set up word count */ 1464 1465 1466 char *xa_smb_trans_name; 1467 1468 int req_disp_param; 1469 int req_disp_data; 1470 1471 struct mbuf_chain req_setup_mb; 1472 struct mbuf_chain req_param_mb; 1473 struct mbuf_chain req_data_mb; 1474 1475 struct mbuf_chain rep_setup_mb; 1476 struct mbuf_chain rep_param_mb; 1477 struct mbuf_chain rep_data_mb; 1478 } smb_xa_t; 1479 1480 1481 #define SDDF_NO_FLAGS 0 1482 #define SDDF_SUPPRESS_TID 0x0001 1483 #define SDDF_SUPPRESS_UID 0x0002 1484 1485 /* 1486 * SMB dispatch return codes. 1487 */ 1488 typedef enum { 1489 SDRC_SUCCESS = 0, 1490 SDRC_ERROR, 1491 SDRC_DROP_VC, 1492 SDRC_NO_REPLY, 1493 SDRC_SR_KEPT, 1494 SDRC_NOT_IMPLEMENTED 1495 } smb_sdrc_t; 1496 1497 #define VAR_BCC ((short)-1) 1498 1499 #define SMB_SERVER_MAGIC 0x53534552 /* 'SSER' */ 1500 1501 typedef struct { 1502 kstat_named_t open_files; 1503 kstat_named_t open_trees; 1504 kstat_named_t open_users; 1505 } smb_server_stats_t; 1506 1507 typedef struct { 1508 kthread_t *ld_kth; 1509 kt_did_t ld_ktdid; 1510 ksocket_t ld_so; 1511 struct sockaddr_in ld_sin; 1512 struct sockaddr_in6 ld_sin6; 1513 smb_session_list_t ld_session_list; 1514 } smb_listener_daemon_t; 1515 1516 typedef enum smb_server_state { 1517 SMB_SERVER_STATE_CREATED = 0, 1518 SMB_SERVER_STATE_CONFIGURED, 1519 SMB_SERVER_STATE_RUNNING, 1520 SMB_SERVER_STATE_DELETING, 1521 SMB_SERVER_STATE_SENTINEL 1522 } smb_server_state_t; 1523 1524 typedef struct smb_server { 1525 uint32_t sv_magic; 1526 kcondvar_t sv_cv; 1527 kmutex_t sv_mutex; 1528 list_node_t sv_lnd; 1529 smb_server_state_t sv_state; 1530 uint32_t sv_refcnt; 1531 pid_t sv_pid; 1532 zoneid_t sv_zid; 1533 smb_listener_daemon_t sv_nbt_daemon; 1534 smb_listener_daemon_t sv_tcp_daemon; 1535 krwlock_t sv_cfg_lock; 1536 smb_kmod_cfg_t sv_cfg; 1537 smb_session_t *sv_session; 1538 1539 kstat_t *sv_ksp; 1540 kmutex_t sv_ksp_mutex; 1541 char sv_ksp_name[KSTAT_STRLEN]; 1542 smb_server_stats_t sv_ks_data; 1543 1544 door_handle_t sv_lmshrd; 1545 1546 int32_t si_gmtoff; 1547 1548 smb_thread_t si_thread_timers; 1549 smb_thread_t si_thread_unexport; 1550 1551 taskq_t *sv_thread_pool; 1552 1553 kmem_cache_t *si_cache_unexport; 1554 kmem_cache_t *si_cache_vfs; 1555 kmem_cache_t *si_cache_request; 1556 kmem_cache_t *si_cache_session; 1557 kmem_cache_t *si_cache_user; 1558 kmem_cache_t *si_cache_tree; 1559 kmem_cache_t *si_cache_ofile; 1560 kmem_cache_t *si_cache_odir; 1561 1562 volatile uint32_t sv_open_trees; 1563 volatile uint32_t sv_open_files; 1564 volatile uint32_t sv_open_users; 1565 1566 smb_node_t *si_root_smb_node; 1567 smb_llist_t sv_vfs_list; 1568 smb_slist_t sv_unexport_list; 1569 } smb_server_t; 1570 1571 #define SMB_INFO_NETBIOS_SESSION_SVC_RUNNING 0x0001 1572 #define SMB_INFO_NETBIOS_SESSION_SVC_FAILED 0x0002 1573 #define SMB_INFO_USER_LEVEL_SECURITY 0x40000000 1574 #define SMB_INFO_ENCRYPT_PASSWORDS 0x80000000 1575 1576 #define SMB_NEW_KID() atomic_inc_64_nv(&smb_kids) 1577 #define SMB_UNIQ_FID() atomic_inc_32_nv(&smb_fids) 1578 1579 /* 1580 * This is to be used by Trans2SetFileInfo 1581 * and Trans2SetPathInfo 1582 */ 1583 typedef struct smb_trans2_setinfo { 1584 uint16_t level; 1585 struct smb_xa *ts_xa; 1586 struct smb_node *node; 1587 char *path; 1588 char name[MAXNAMELEN]; 1589 } smb_trans2_setinfo_t; 1590 1591 #define SMB_IS_STREAM(node) ((node)->unnamed_stream_node) 1592 1593 typedef struct smb_tsd { 1594 void (*proc)(); 1595 void *arg; 1596 char name[100]; 1597 } smb_tsd_t; 1598 1599 typedef struct smb_disp_entry { 1600 smb_sdrc_t (*sdt_pre_op)(smb_request_t *); 1601 smb_sdrc_t (*sdt_function)(smb_request_t *); 1602 void (*sdt_post_op)(smb_request_t *); 1603 char sdt_dialect; 1604 unsigned char sdt_flags; 1605 krw_t sdt_slock_mode; 1606 kstat_named_t sdt_dispatch_stats; /* invocations */ 1607 } smb_disp_entry_t; 1608 1609 /* 1610 * Discretionary Access Control List (DACL) 1611 * 1612 * A Discretionary Access Control List (DACL), often abbreviated to 1613 * ACL, is a list of access controls which either allow or deny access 1614 * for users or groups to a resource. There is a list header followed 1615 * by a list of access control entries (ACE). Each ACE specifies the 1616 * access allowed or denied to a single user or group (identified by 1617 * a SID). 1618 * 1619 * There is another access control list object called a System Access 1620 * Control List (SACL), which is used to control auditing, but no 1621 * support is provideed for SACLs at this time. 1622 * 1623 * ACL header format: 1624 * 1625 * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1626 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1627 * +-------------------------------+---------------+---------------+ 1628 * | AclSize | Sbz1 | AclRevision | 1629 * +-------------------------------+---------------+---------------+ 1630 * | Sbz2 | AceCount | 1631 * +-------------------------------+-------------------------------+ 1632 * 1633 * AclRevision specifies the revision level of the ACL. This value should 1634 * be ACL_REVISION, unless the ACL contains an object-specific ACE, in which 1635 * case this value must be ACL_REVISION_DS. All ACEs in an ACL must be at the 1636 * same revision level. 1637 * 1638 * ACE header format: 1639 * 1640 * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1641 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1642 * +---------------+-------+-------+---------------+---------------+ 1643 * | AceSize | AceFlags | AceType | 1644 * +---------------+-------+-------+---------------+---------------+ 1645 * 1646 * Access mask format: 1647 * 1648 * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1649 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1650 * +---------------+---------------+-------------------------------+ 1651 * |G|G|G|G|Res'd|A| StandardRights| SpecificRights | 1652 * |R|W|E|A| |S| | | 1653 * +-+-------------+---------------+-------------------------------+ 1654 * 1655 * typedef struct ACCESS_MASK { 1656 * WORD SpecificRights; 1657 * BYTE StandardRights; 1658 * BYTE AccessSystemAcl : 1; 1659 * BYTE Reserved : 3; 1660 * BYTE GenericAll : 1; 1661 * BYTE GenericExecute : 1; 1662 * BYTE GenericWrite : 1; 1663 * BYTE GenericRead : 1; 1664 * } ACCESS_MASK; 1665 * 1666 */ 1667 1668 #define ACL_REVISION1 1 1669 #define ACL_REVISION2 2 1670 #define MIN_ACL_REVISION2 ACL_REVISION2 1671 #define ACL_REVISION3 3 1672 #define ACL_REVISION4 4 1673 #define MAX_ACL_REVISION ACL_REVISION4 1674 1675 /* 1676 * Current ACE and ACL revision Levels 1677 */ 1678 #define ACE_REVISION 1 1679 #define ACL_REVISION ACL_REVISION2 1680 #define ACL_REVISION_DS ACL_REVISION4 1681 1682 1683 #define ACCESS_ALLOWED_ACE_TYPE 0 1684 #define ACCESS_DENIED_ACE_TYPE 1 1685 #define SYSTEM_AUDIT_ACE_TYPE 2 1686 #define SYSTEM_ALARM_ACE_TYPE 3 1687 1688 /* 1689 * se_flags 1690 * ---------- 1691 * Specifies a set of ACE type-specific control flags. This member can be a 1692 * combination of the following values. 1693 * 1694 * CONTAINER_INHERIT_ACE: Child objects that are containers, such as 1695 * directories, inherit the ACE as an effective ACE. The inherited 1696 * ACE is inheritable unless the NO_PROPAGATE_INHERIT_ACE bit flag 1697 * is also set. 1698 * 1699 * INHERIT_ONLY_ACE: Indicates an inherit-only ACE which does not control 1700 * access to the object to which it is attached. 1701 * If this flag is not set, 1702 * the ACE is an effective ACE which controls access to the object 1703 * to which it is attached. 1704 * Both effective and inherit-only ACEs can be inherited 1705 * depending on the state of the other inheritance flags. 1706 * 1707 * INHERITED_ACE: Windows 2000/XP: Indicates that the ACE was inherited. 1708 * The system sets this bit when it propagates an 1709 * inherited ACE to a child object. 1710 * 1711 * NO_PROPAGATE_INHERIT_ACE: If the ACE is inherited by a child object, the 1712 * system clears the OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE 1713 * flags in the inherited ACE. 1714 * This prevents the ACE from being inherited by 1715 * subsequent generations of objects. 1716 * 1717 * OBJECT_INHERIT_ACE: Noncontainer child objects inherit the ACE as an 1718 * effective ACE. For child objects that are containers, 1719 * the ACE is inherited as an inherit-only ACE unless the 1720 * NO_PROPAGATE_INHERIT_ACE bit flag is also set. 1721 */ 1722 #define OBJECT_INHERIT_ACE 0x01 1723 #define CONTAINER_INHERIT_ACE 0x02 1724 #define NO_PROPOGATE_INHERIT_ACE 0x04 1725 #define INHERIT_ONLY_ACE 0x08 1726 #define INHERITED_ACE 0x10 1727 #define INHERIT_MASK_ACE 0x1F 1728 1729 1730 /* 1731 * These flags are only used in system audit or alarm ACEs to 1732 * indicate when an audit message should be generated, i.e. 1733 * on successful access or on unsuccessful access. 1734 */ 1735 #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40 1736 #define FAILED_ACCESS_ACE_FLAG 0x80 1737 1738 /* 1739 * se_bsize is the size, in bytes, of ACE as it appears on the wire. 1740 * se_sln is used to sort the ACL when it's required. 1741 */ 1742 typedef struct smb_acehdr { 1743 uint8_t se_type; 1744 uint8_t se_flags; 1745 uint16_t se_bsize; 1746 } smb_acehdr_t; 1747 1748 typedef struct smb_ace { 1749 smb_acehdr_t se_hdr; 1750 uint32_t se_mask; 1751 list_node_t se_sln; 1752 smb_sid_t *se_sid; 1753 } smb_ace_t; 1754 1755 /* 1756 * sl_bsize is the size of ACL in bytes as it appears on the wire. 1757 */ 1758 typedef struct smb_acl { 1759 uint8_t sl_revision; 1760 uint16_t sl_bsize; 1761 uint16_t sl_acecnt; 1762 smb_ace_t *sl_aces; 1763 list_t sl_sorted; 1764 } smb_acl_t; 1765 1766 /* 1767 * ACE/ACL header size, in byte, as it appears on the wire 1768 */ 1769 #define SMB_ACE_HDRSIZE 4 1770 #define SMB_ACL_HDRSIZE 8 1771 1772 /* 1773 * Security Descriptor (SD) 1774 * 1775 * Security descriptors provide protection for objects, for example 1776 * files and directories. It identifies the owner and primary group 1777 * (SIDs) and contains an access control list. When a user tries to 1778 * access an object his SID is compared to the permissions in the 1779 * DACL to determine if access should be allowed or denied. Note that 1780 * this is a simplification because there are other factors, such as 1781 * default behavior and privileges to be taken into account (see also 1782 * access tokens). 1783 * 1784 * The boolean flags have the following meanings when set: 1785 * 1786 * SE_OWNER_DEFAULTED indicates that the SID pointed to by the Owner 1787 * field was provided by a defaulting mechanism rather than explicitly 1788 * provided by the original provider of the security descriptor. This 1789 * may affect the treatment of the SID with respect to inheritance of 1790 * an owner. 1791 * 1792 * SE_GROUP_DEFAULTED indicates that the SID in the Group field was 1793 * provided by a defaulting mechanism rather than explicitly provided 1794 * by the original provider of the security descriptor. This may 1795 * affect the treatment of the SID with respect to inheritance of a 1796 * primary group. 1797 * 1798 * SE_DACL_PRESENT indicates that the security descriptor contains a 1799 * discretionary ACL. If this flag is set and the Dacl field of the 1800 * SECURITY_DESCRIPTOR is null, then a null ACL is explicitly being 1801 * specified. 1802 * 1803 * SE_DACL_DEFAULTED indicates that the ACL pointed to by the Dacl 1804 * field was provided by a defaulting mechanism rather than explicitly 1805 * provided by the original provider of the security descriptor. This 1806 * may affect the treatment of the ACL with respect to inheritance of 1807 * an ACL. This flag is ignored if the DaclPresent flag is not set. 1808 * 1809 * SE_SACL_PRESENT indicates that the security descriptor contains a 1810 * system ACL pointed to by the Sacl field. If this flag is set and 1811 * the Sacl field of the SECURITY_DESCRIPTOR is null, then an empty 1812 * (but present) ACL is being specified. 1813 * 1814 * SE_SACL_DEFAULTED indicates that the ACL pointed to by the Sacl 1815 * field was provided by a defaulting mechanism rather than explicitly 1816 * provided by the original provider of the security descriptor. This 1817 * may affect the treatment of the ACL with respect to inheritance of 1818 * an ACL. This flag is ignored if the SaclPresent flag is not set. 1819 * 1820 * SE_DACL_PROTECTED Prevents ACEs set on the DACL of the parent container 1821 * (and any objects above the parent container in the directory hierarchy) 1822 * from being applied to the object's DACL. 1823 * 1824 * SE_SACL_PROTECTED Prevents ACEs set on the SACL of the parent container 1825 * (and any objects above the parent container in the directory hierarchy) 1826 * from being applied to the object's SACL. 1827 * 1828 * Note that the SE_DACL_PRESENT flag needs to be present to set 1829 * SE_DACL_PROTECTED and SE_SACL_PRESENT needs to be present to set 1830 * SE_SACL_PROTECTED. 1831 * 1832 * SE_SELF_RELATIVE indicates that the security descriptor is in self- 1833 * relative form. In this form, all fields of the security descriptor 1834 * are contiguous in memory and all pointer fields are expressed as 1835 * offsets from the beginning of the security descriptor. 1836 * 1837 * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1838 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1839 * +---------------------------------------------------------------+ 1840 * | Control |Reserved1 (SBZ)| Revision | 1841 * +---------------------------------------------------------------+ 1842 * | Owner | 1843 * +---------------------------------------------------------------+ 1844 * | Group | 1845 * +---------------------------------------------------------------+ 1846 * | Sacl | 1847 * +---------------------------------------------------------------+ 1848 * | Dacl | 1849 * +---------------------------------------------------------------+ 1850 * 1851 */ 1852 1853 #define SMB_OWNER_SECINFO 0x0001 1854 #define SMB_GROUP_SECINFO 0x0002 1855 #define SMB_DACL_SECINFO 0x0004 1856 #define SMB_SACL_SECINFO 0x0008 1857 #define SMB_ALL_SECINFO 0x000F 1858 #define SMB_ACL_SECINFO (SMB_DACL_SECINFO | SMB_SACL_SECINFO) 1859 1860 #define SECURITY_DESCRIPTOR_REVISION 1 1861 1862 1863 #define SE_OWNER_DEFAULTED 0x0001 1864 #define SE_GROUP_DEFAULTED 0x0002 1865 #define SE_DACL_PRESENT 0x0004 1866 #define SE_DACL_DEFAULTED 0x0008 1867 #define SE_SACL_PRESENT 0x0010 1868 #define SE_SACL_DEFAULTED 0x0020 1869 #define SE_DACL_AUTO_INHERIT_REQ 0x0100 1870 #define SE_SACL_AUTO_INHERIT_REQ 0x0200 1871 #define SE_DACL_AUTO_INHERITED 0x0400 1872 #define SE_SACL_AUTO_INHERITED 0x0800 1873 #define SE_DACL_PROTECTED 0x1000 1874 #define SE_SACL_PROTECTED 0x2000 1875 #define SE_SELF_RELATIVE 0x8000 1876 1877 #define SE_DACL_INHERITANCE_MASK 0x1500 1878 #define SE_SACL_INHERITANCE_MASK 0x2A00 1879 1880 /* 1881 * Security descriptor structures: 1882 * 1883 * smb_sd_t SD in SMB pointer form 1884 * smb_fssd_t SD in filesystem form 1885 * 1886 * Filesystems (e.g. ZFS/UFS) don't have something equivalent 1887 * to SD. The items comprising a SMB SD are kept separately in 1888 * filesystem. smb_fssd_t is introduced as a helper to provide 1889 * the required abstraction for CIFS code. 1890 */ 1891 1892 typedef struct smb_sd { 1893 uint8_t sd_revision; 1894 uint16_t sd_control; 1895 smb_sid_t *sd_owner; /* SID file owner */ 1896 smb_sid_t *sd_group; /* SID group (for POSIX) */ 1897 smb_acl_t *sd_sacl; /* ACL System (audits) */ 1898 smb_acl_t *sd_dacl; /* ACL Discretionary (perm) */ 1899 } smb_sd_t; 1900 1901 /* 1902 * SD header size as it appears on the wire 1903 */ 1904 #define SMB_SD_HDRSIZE 20 1905 1906 /* 1907 * values for smb_fssd.sd_flags 1908 */ 1909 #define SMB_FSSD_FLAGS_DIR 0x01 1910 1911 typedef struct smb_fssd { 1912 uint32_t sd_secinfo; 1913 uint32_t sd_flags; 1914 uid_t sd_uid; 1915 gid_t sd_gid; 1916 acl_t *sd_zdacl; 1917 acl_t *sd_zsacl; 1918 } smb_fssd_t; 1919 1920 #ifdef __cplusplus 1921 } 1922 #endif 1923 1924 #endif /* _SMBSRV_SMB_KTYPES_H */ 1925