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 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright (c) 2016 by Delphix. All rights reserved.
  26  */
  27 
  28 #ifndef _SMBSRV_NTIFS_H
  29 #define _SMBSRV_NTIFS_H
  30 
  31 /*
  32  * This file provides definitions compatible with the NT Installable
  33  * File System (IFS) interface. This header file also defines the Security
  34  * Descriptor module from Windows.
  35  */
  36 
  37 #ifdef __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 #include <sys/acl.h>
  42 #include <sys/list.h>
  43 #include <smbsrv/smb_sid.h>
  44 
  45 /*
  46  * The Volume and Directory bits are for SMB rather than NT.
  47  * NT has an explicit Normal bit; this bit is implied in SMB
  48  * when the Hidden, System and Directory bits are not set.
  49  *
  50  * File attributes and creation flags share the same 32-bit
  51  * space.
  52  */
  53 #define FILE_ATTRIBUTE_READONLY                 0x00000001
  54 #define FILE_ATTRIBUTE_HIDDEN                   0x00000002
  55 #define FILE_ATTRIBUTE_SYSTEM                   0x00000004
  56 #define FILE_ATTRIBUTE_VOLUME                   0x00000008
  57 #define FILE_ATTRIBUTE_DIRECTORY                0x00000010
  58 #define FILE_ATTRIBUTE_ARCHIVE                  0x00000020
  59 #define FILE_ATTRIBUTE_DEVICE                   0x00000040
  60 #define FILE_ATTRIBUTE_NORMAL                   0x00000080
  61 #define FILE_ATTRIBUTE_TEMPORARY                0x00000100
  62 #define FILE_ATTRIBUTE_SPARSE_FILE              0x00000200
  63 #define FILE_ATTRIBUTE_REPARSE_POINT            0x00000400
  64 #define FILE_ATTRIBUTE_COMPRESSED               0x00000800
  65 #define FILE_ATTRIBUTE_OFFLINE                  0x00001000
  66 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED      0x00002000
  67 #define FILE_ATTRIBUTE_ENCRYPTED                0x00004000
  68 #define FILE_ATTRIBUTE_VIRTUAL                  0x00010000
  69 #define FILE_FLAG_OPEN_NO_RECALL                0x00100000
  70 #define FILE_FLAG_OPEN_REPARSE_POINT            0x00200000
  71 #define FILE_FLAG_POSIX_SEMANTICS               0x01000000
  72 #define FILE_FLAG_BACKUP_SEMANTICS              0x02000000
  73 #define FILE_FLAG_DELETE_ON_CLOSE               0x04000000
  74 #define FILE_FLAG_SEQUENTIAL_SCAN               0x08000000
  75 #define FILE_FLAG_RANDOM_ACCESS                 0x10000000
  76 #define FILE_FLAG_NO_BUFFERING                  0x20000000
  77 #define FILE_FLAG_OVERLAPPED                    0x40000000
  78 #define FILE_FLAG_WRITE_THROUGH                 0x80000000
  79 
  80 #define FILE_ATTRIBUTE_VALID_FLAGS              0x00001fb7
  81 #define FILE_ATTRIBUTE_VALID_SET_FLAGS          0x00001fa7
  82 #define FILE_ATTRIBUTE_MASK                     0x00003FFF
  83 
  84 /*
  85  * The create/open option flags: used in NtCreateAndx and NtTransactCreate
  86  * SMB requests.
  87  *
  88  * The CreateOptions specify the options to be applied when creating or
  89  * opening the file, as a compatible combination of the following flags:
  90  *
  91  * FILE_DIRECTORY_FILE
  92  *      The file being created or opened is a directory file. With this
  93  *      flag, the Disposition parameter must be set to one of FILE_CREATE,
  94  *      FILE_OPEN, or FILE_OPEN_IF. With this flag, other compatible
  95  *      CreateOptions flags include only the following:
  96  *                      FILE_SYNCHRONOUS_IO_ALERT
  97  *                      FILE_SYNCHRONOUS_IO_NONALERT
  98  *                      FILE_WRITE_THROUGH
  99  *                      FILE_OPEN_FOR_BACKUP_INTENT
 100  *                      FILE_OPEN_BY_FILE_ID
 101  *
 102  * FILE_NON_DIRECTORY_FILE
 103  *      The file being opened must not be a directory file or this call
 104  *      will fail. The file object being opened can represent a data file,
 105  *      a logical, virtual, or physical device, or a volume.
 106  *
 107  * FILE_WRITE_THROUGH
 108  *      System services, FSDs, and drivers that write data to the file must
 109  *      actually transfer the data into the file before any requested write
 110  *      operation is considered complete. This flag is automatically set if
 111  *      the CreateOptions flag FILE_NO_INTERMEDIATE _BUFFERING is set.
 112  *
 113  * FILE_SEQUENTIAL_ONLY
 114  *      All accesses to the file will be sequential.
 115  *
 116  * FILE_RANDOM_ACCESS
 117  *      Accesses to the file can be random, so no sequential read-ahead
 118  *      operations should be performed on the file by FSDs or the system.
 119  *      FILE_NO_INTERMEDIATE _BUFFERING The file cannot be cached or
 120  *      buffered in a driver's internal buffers. This flag is incompatible
 121  *      with the DesiredAccess FILE_APPEND_DATA flag.
 122  *
 123  * FILE_SYNCHRONOUS_IO_ALERT
 124  *      All operations on the file are performed synchronously. Any wait
 125  *      on behalf of the caller is subject to premature termination from
 126  *      alerts. This flag also causes the I/O system to maintain the file
 127  *      position context. If this flag is set, the DesiredAccess
 128  *      SYNCHRONIZE flag also must be set.
 129  *
 130  * FILE_SYNCHRONOUS_IO _NONALERT
 131  *      All operations on the file are performed synchronously. Waits in
 132  *      the system to synchronize I/O queuing and completion are not subject
 133  *      to alerts. This flag also causes the I/O system to maintain the file
 134  *      position context. If this flag is set, the DesiredAccess SYNCHRONIZE
 135  *      flag also must be set.
 136  *
 137  * FILE_CREATE_TREE _CONNECTION
 138  *      Create a tree connection for this file in order to open it over the
 139  *      network. This flag is irrelevant to device and intermediate drivers.
 140  *
 141  * FILE_COMPLETE_IF_OPLOCKED
 142  *      Complete this operation immediately with an alternate success code
 143  *      if the target file is oplocked, rather than blocking the caller's
 144  *      thread. If the file is oplocked, another caller already has access
 145  *      to the file over the network. This flag is irrelevant to device and
 146  *      intermediate drivers.
 147  *
 148  * FILE_NO_EA_KNOWLEDGE
 149  *      If the extended attributes on an existing file being opened indicate
 150  *      that the caller must understand EAs to properly interpret the file,
 151  *      fail this request because the caller does not understand how to deal
 152  *      with EAs. Device and intermediate drivers can ignore this flag.
 153  *
 154  * FILE_DELETE_ON_CLOSE
 155  *      Delete the file when the last reference to it is passed to close.
 156  *
 157  * FILE_OPEN_BY_FILE_ID
 158  *      The file name contains the name of a device and a 64-bit ID to
 159  *      be used to open the file. This flag is irrelevant to device and
 160  *      intermediate drivers.
 161  *
 162  * FILE_OPEN_FOR_BACKUP _INTENT
 163  *      The file is being opened for backup intent, hence, the system should
 164  *      check for certain access rights and grant the caller the appropriate
 165  *      accesses to the file before checking the input DesiredAccess against
 166  *      the file's security descriptor. This flag is irrelevant to device
 167  *      and intermediate drivers.
 168  */
 169 #define FILE_DIRECTORY_FILE                     0x00000001
 170 #define FILE_WRITE_THROUGH                      0x00000002
 171 #define FILE_SEQUENTIAL_ONLY                    0x00000004
 172 #define FILE_NO_INTERMEDIATE_BUFFERING          0x00000008
 173 
 174 #define FILE_SYNCHRONOUS_IO_ALERT               0x00000010
 175 #define FILE_SYNCHRONOUS_IO_NONALERT            0x00000020
 176 #define FILE_NON_DIRECTORY_FILE                 0x00000040
 177 #define FILE_CREATE_TREE_CONNECTION             0x00000080
 178 
 179 #define FILE_COMPLETE_IF_OPLOCKED               0x00000100
 180 #define FILE_NO_EA_KNOWLEDGE                    0x00000200
 181 /* UNUSED                                       0x00000400 */
 182 #define FILE_RANDOM_ACCESS                      0x00000800
 183 
 184 #define FILE_DELETE_ON_CLOSE                    0x00001000
 185 #define FILE_OPEN_BY_FILE_ID                    0x00002000
 186 #define FILE_OPEN_FOR_BACKUP_INTENT             0x00004000
 187 #define FILE_NO_COMPRESSION                     0x00008000
 188 
 189 #define FILE_RESERVE_OPFILTER                   0x00100000
 190 #define FILE_RESERVED0                          0x00200000
 191 #define FILE_RESERVED1                          0x00400000
 192 #define FILE_RESERVED2                          0x00800000
 193 
 194 #define FILE_VALID_OPTION_FLAGS                 0x00ffffff
 195 #define FILE_VALID_PIPE_OPTION_FLAGS            0x00000032
 196 #define FILE_VALID_MAILSLOT_OPTION_FLAGS        0x00000032
 197 #define FILE_VALID_SET_FLAGS                    0x00000036
 198 
 199 /*
 200  * "Granular" oplock flags; [MS-FSA], WinDDK/ntifs.h
 201  * Same as smb2.h SMB2_LEASE_...
 202  */
 203 #define OPLOCK_LEVEL_CACHE_READ                 0x01
 204 #define OPLOCK_LEVEL_CACHE_HANDLE               0x02
 205 #define OPLOCK_LEVEL_CACHE_WRITE                0x04
 206 #define OPLOCK_LEVEL_CACHE_MASK                 0x07
 207 
 208 /*
 209  * [MS-FSA] oplock types (also "levels")
 210  */
 211 #define OPLOCK_LEVEL_NONE                       0
 212 #define OPLOCK_LEVEL_TWO                        0x100
 213 #define OPLOCK_LEVEL_ONE                        0x200
 214 #define OPLOCK_LEVEL_BATCH                      0x400
 215 #define OPLOCK_LEVEL_GRANULAR                   0x800
 216 #define OPLOCK_LEVEL_TYPE_MASK                  0xf00
 217 
 218 /*
 219  * Define the file information class values used by the NT DDK and HAL.
 220  */
 221 typedef enum _FILE_INFORMATION_CLASS {
 222         FileDirectoryInformation                = 1,
 223         FileFullDirectoryInformation,           /* 2 */
 224         FileBothDirectoryInformation,           /* 3 */
 225         FileBasicInformation,                   /* 4 */
 226         FileStandardInformation,                /* 5 */
 227         FileInternalInformation,                /* 6 */
 228         FileEaInformation,                      /* 7 */
 229         FileAccessInformation,                  /* 8 */
 230         FileNameInformation,                    /* 9 */
 231         FileRenameInformation,                  /* 10 */
 232         FileLinkInformation,                    /* 11 */
 233         FileNamesInformation,                   /* 12 */
 234         FileDispositionInformation,             /* 13 */
 235         FilePositionInformation,                /* 14 */
 236         FileFullEaInformation,                  /* 15 */
 237         FileModeInformation,                    /* 16 */
 238         FileAlignmentInformation,               /* 17 */
 239         FileAllInformation,                     /* 18 */
 240         FileAllocationInformation,              /* 19 */
 241         FileEndOfFileInformation,               /* 20 */
 242         FileAlternateNameInformation,           /* 21 */
 243         FileStreamInformation,                  /* 22 */
 244         FilePipeInformation,                    /* 23 */
 245         FilePipeLocalInformation,               /* 24 */
 246         FilePipeRemoteInformation,              /* 25 */
 247         FileMailslotQueryInformation,           /* 26 */
 248         FileMailslotSetInformation,             /* 27 */
 249         FileCompressionInformation,             /* 28 */
 250         FileObjectIdInformation,                /* 29 */
 251         FileCompletionInformation,              /* 30 */
 252         FileMoveClusterInformation,             /* 31 */
 253         FileQuotaInformation,                   /* 32 */
 254         FileReparsePointInformation,            /* 33 */
 255         FileNetworkOpenInformation,             /* 34 */
 256         FileAttributeTagInformation,            /* 35 */
 257         FileTrackingInformation,                /* 36 */
 258         FileIdBothDirectoryInformation,         /* 37 */
 259         FileIdFullDirectoryInformation,         /* 38 */
 260         FileValidDataLengthInformation,         /* 39 */
 261         FileShortNameInformation,               /* 40 */
 262         FileInformationReserved41,              /* 41 */
 263         FileInformationReserved42,              /* 42 */
 264         FileInformationReserved43,              /* 43 */
 265         FileSfioReserveInformation,             /* 44 */
 266         FileSfioVolumeInformation,              /* 45 */
 267         FileHardLinkInformation,                /* 46 */
 268         FileInformationReserved47,              /* 47 */
 269         FileNormalizedNameInformation,          /* 48 */
 270         FileInformationReserved49,              /* 49 */
 271         FileIdGlobalTxDirectoryInformation,     /* 50 */
 272         FileInformationReserved51,              /* 51 */
 273         FileInformationReserved52,              /* 52 */
 274         FileInformationReserved53,              /* 53 */
 275         FileStandardLinkInformation,            /* 54 */
 276         FileMaximumInformation
 277 } FILE_INFORMATION_CLASS;
 278 
 279 /*
 280  * Define the file system information class values.
 281  */
 282 typedef enum _FILE_FS_INFORMATION_CLASS {
 283         FileFsVolumeInformation         = 1,
 284         FileFsLabelInformation,         /* 2 */
 285         FileFsSizeInformation,          /* 3 */
 286         FileFsDeviceInformation,        /* 4 */
 287         FileFsAttributeInformation,     /* 5 */
 288         FileFsControlInformation,       /* 6 */
 289         FileFsFullSizeInformation,      /* 7 */
 290         FileFsObjectIdInformation,      /* 8 */
 291         FileFsDriverPathInformation,    /* 9 */
 292         FileFsVolumeFlagsInformation,   /* A */
 293         FileFsSectorSizeInformation     /* B */
 294 } FILE_FS_INFORMATION_CLASS;
 295 
 296 /*
 297  * Discretionary Access Control List (DACL)
 298  *
 299  * A Discretionary Access Control List (DACL), often abbreviated to
 300  * ACL, is a list of access controls which either allow or deny access
 301  * for users or groups to a resource. There is a list header followed
 302  * by a list of access control entries (ACE). Each ACE specifies the
 303  * access allowed or denied to a single user or group (identified by
 304  * a SID).
 305  *
 306  * There is another access control list object called a System Access
 307  * Control List (SACL), which is used to control auditing, but no
 308  * support is provideed for SACLs at this time.
 309  *
 310  * ACL header format:
 311  *
 312  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
 313  *    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
 314  *   +-------------------------------+---------------+---------------+
 315  *   |            AclSize            |      Sbz1     |  AclRevision  |
 316  *   +-------------------------------+---------------+---------------+
 317  *   |              Sbz2             |           AceCount            |
 318  *   +-------------------------------+-------------------------------+
 319  *
 320  * AclRevision specifies the revision level of the ACL. This value should
 321  * be ACL_REVISION, unless the ACL contains an object-specific ACE, in which
 322  * case this value must be ACL_REVISION_DS. All ACEs in an ACL must be at the
 323  * same revision level.
 324  *
 325  * ACE header format:
 326  *
 327  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
 328  *    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
 329  *   +---------------+-------+-------+---------------+---------------+
 330  *   |            AceSize            |    AceFlags   |     AceType   |
 331  *   +---------------+-------+-------+---------------+---------------+
 332  *
 333  * Access mask format:
 334  *
 335  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
 336  *    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
 337  *   +---------------+---------------+-------------------------------+
 338  *   |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
 339  *   |R|W|E|A|     |S|               |                               |
 340  *   +-+-------------+---------------+-------------------------------+
 341  *
 342  *   typedef struct ACCESS_MASK {
 343  *       WORD SpecificRights;
 344  *       BYTE StandardRights;
 345  *       BYTE AccessSystemAcl : 1;
 346  *       BYTE Reserved : 3;
 347  *       BYTE GenericAll : 1;
 348  *       BYTE GenericExecute : 1;
 349  *       BYTE GenericWrite : 1;
 350  *       BYTE GenericRead : 1;
 351  *   } ACCESS_MASK;
 352  *
 353  */
 354 
 355 #define ACL_REVISION1                   1
 356 #define ACL_REVISION2                   2
 357 #define MIN_ACL_REVISION2               ACL_REVISION2
 358 #define ACL_REVISION3                   3
 359 #define ACL_REVISION4                   4
 360 #define MAX_ACL_REVISION                ACL_REVISION4
 361 
 362 /*
 363  * Current ACE and ACL revision Levels
 364  */
 365 #define ACE_REVISION                    1
 366 #define ACL_REVISION                    ACL_REVISION2
 367 #define ACL_REVISION_DS                 ACL_REVISION4
 368 
 369 
 370 #define ACCESS_ALLOWED_ACE_TYPE         0
 371 #define ACCESS_DENIED_ACE_TYPE          1
 372 #define SYSTEM_AUDIT_ACE_TYPE           2
 373 #define SYSTEM_ALARM_ACE_TYPE           3
 374 
 375 /*
 376  *  se_flags
 377  * ----------
 378  * Specifies a set of ACE type-specific control flags. This member can be a
 379  * combination of the following values.
 380  *
 381  * CONTAINER_INHERIT_ACE: Child objects that are containers, such as
 382  *              directories, inherit the ACE as an effective ACE. The inherited
 383  *              ACE is inheritable unless the NO_PROPAGATE_INHERIT_ACE bit flag
 384  *              is also set.
 385  *
 386  * INHERIT_ONLY_ACE: Indicates an inherit-only ACE which does not control
 387  *              access to the object to which it is attached.
 388  *              If this flag is not set,
 389  *              the ACE is an effective ACE which controls access to the object
 390  *              to which it is attached.
 391  *              Both effective and inherit-only ACEs can be inherited
 392  *              depending on the state of the other inheritance flags.
 393  *
 394  * INHERITED_ACE: Windows 2000/XP: Indicates that the ACE was inherited.
 395  *              The system sets this bit when it propagates an
 396  *              inherited ACE to a child object.
 397  *
 398  * NO_PROPAGATE_INHERIT_ACE: If the ACE is inherited by a child object, the
 399  *              system clears the OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE
 400  *              flags in the inherited ACE.
 401  *              This prevents the ACE from being inherited by
 402  *              subsequent generations of objects.
 403  *
 404  * OBJECT_INHERIT_ACE: Noncontainer child objects inherit the ACE as an
 405  *              effective ACE.  For child objects that are containers,
 406  *              the ACE is inherited as an inherit-only ACE unless the
 407  *              NO_PROPAGATE_INHERIT_ACE bit flag is also set.
 408  */
 409 #define OBJECT_INHERIT_ACE              0x01
 410 #define CONTAINER_INHERIT_ACE           0x02
 411 #define NO_PROPOGATE_INHERIT_ACE        0x04
 412 #define INHERIT_ONLY_ACE                0x08
 413 #define INHERITED_ACE                   0x10
 414 #define INHERIT_MASK_ACE                0x1F
 415 
 416 
 417 /*
 418  * These flags are only used in system audit or alarm ACEs to
 419  * indicate when an audit message should be generated, i.e.
 420  * on successful access or on unsuccessful access.
 421  */
 422 #define SUCCESSFUL_ACCESS_ACE_FLAG      0x40
 423 #define FAILED_ACCESS_ACE_FLAG          0x80
 424 
 425 /*
 426  * se_bsize is the size, in bytes, of ACE as it appears on the wire.
 427  * se_sln is used to sort the ACL when it's required.
 428  */
 429 typedef struct smb_acehdr {
 430         uint8_t         se_type;
 431         uint8_t         se_flags;
 432         uint16_t        se_bsize;
 433 } smb_acehdr_t;
 434 
 435 typedef struct smb_ace {
 436         smb_acehdr_t    se_hdr;
 437         uint32_t        se_mask;
 438         list_node_t     se_sln;
 439         smb_sid_t       *se_sid;
 440 } smb_ace_t;
 441 
 442 /*
 443  * sl_bsize is the size of ACL in bytes as it appears on the wire.
 444  */
 445 typedef struct smb_acl {
 446         uint8_t         sl_revision;
 447         uint16_t        sl_bsize;
 448         uint16_t        sl_acecnt;
 449         smb_ace_t       *sl_aces;
 450         list_t          sl_sorted;
 451 } smb_acl_t;
 452 
 453 /*
 454  * ACE/ACL header size, in byte, as it appears on the wire
 455  */
 456 #define SMB_ACE_HDRSIZE         4
 457 #define SMB_ACL_HDRSIZE         8
 458 
 459 /*
 460  * Security Descriptor (SD)
 461  *
 462  * Security descriptors provide protection for objects, for example
 463  * files and directories. It identifies the owner and primary group
 464  * (SIDs) and contains an access control list. When a user tries to
 465  * access an object their SID is compared to the permissions in the
 466  * DACL to determine if access should be allowed or denied. Note that
 467  * this is a simplification because there are other factors, such as
 468  * default behavior and privileges to be taken into account (see also
 469  * access tokens).
 470  *
 471  * The boolean flags have the following meanings when set:
 472  *
 473  * SE_OWNER_DEFAULTED indicates that the SID pointed to by the Owner
 474  * field was provided by a defaulting mechanism rather than explicitly
 475  * provided by the original provider of the security descriptor. This
 476  * may affect the treatment of the SID with respect to inheritance of
 477  * an owner.
 478  *
 479  * SE_GROUP_DEFAULTED indicates that the SID in the Group field was
 480  * provided by a defaulting mechanism rather than explicitly provided
 481  * by the original provider of the security descriptor.  This may
 482  * affect the treatment of the SID with respect to inheritance of a
 483  * primary group.
 484  *
 485  * SE_DACL_PRESENT indicates that the security descriptor contains a
 486  * discretionary ACL. If this flag is set and the Dacl field of the
 487  * SECURITY_DESCRIPTOR is null, then a null ACL is explicitly being
 488  * specified.
 489  *
 490  * SE_DACL_DEFAULTED indicates that the ACL pointed to by the Dacl
 491  * field was provided by a defaulting mechanism rather than explicitly
 492  * provided by the original provider of the security descriptor. This
 493  * may affect the treatment of the ACL with respect to inheritance of
 494  * an ACL. This flag is ignored if the DaclPresent flag is not set.
 495  *
 496  * SE_SACL_PRESENT indicates that the security descriptor contains a
 497  * system ACL pointed to by the Sacl field. If this flag is set and
 498  * the Sacl field of the SECURITY_DESCRIPTOR is null, then an empty
 499  * (but present) ACL is being specified.
 500  *
 501  * SE_SACL_DEFAULTED indicates that the ACL pointed to by the Sacl
 502  * field was provided by a defaulting mechanism rather than explicitly
 503  * provided by the original provider of the security descriptor. This
 504  * may affect the treatment of the ACL with respect to inheritance of
 505  * an ACL. This flag is ignored if the SaclPresent flag is not set.
 506  *
 507  * SE_DACL_PROTECTED Prevents ACEs set on the DACL of the parent container
 508  * (and any objects above the parent container in the directory hierarchy)
 509  * from being applied to the object's DACL.
 510  *
 511  * SE_SACL_PROTECTED Prevents ACEs set on the SACL of the parent container
 512  * (and any objects above the parent container in the directory hierarchy)
 513  * from being applied to the object's SACL.
 514  *
 515  * Note that the SE_DACL_PRESENT flag needs to be present to set
 516  * SE_DACL_PROTECTED and SE_SACL_PRESENT needs to be present to set
 517  * SE_SACL_PROTECTED.
 518  *
 519  * SE_SELF_RELATIVE indicates that the security descriptor is in self-
 520  * relative form. In this form, all fields of the security descriptor
 521  * are contiguous in memory and all pointer fields are expressed as
 522  * offsets from the beginning of the security descriptor.
 523  *
 524  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
 525  *    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
 526  *   +---------------------------------------------------------------+
 527  *   |            Control            |Reserved1 (SBZ)|   Revision    |
 528  *   +---------------------------------------------------------------+
 529  *   |                            Owner                              |
 530  *   +---------------------------------------------------------------+
 531  *   |                            Group                              |
 532  *   +---------------------------------------------------------------+
 533  *   |                            Sacl                               |
 534  *   +---------------------------------------------------------------+
 535  *   |                            Dacl                               |
 536  *   +---------------------------------------------------------------+
 537  *
 538  */
 539 
 540 #define SMB_OWNER_SECINFO       0x0001
 541 #define SMB_GROUP_SECINFO       0x0002
 542 #define SMB_DACL_SECINFO        0x0004
 543 #define SMB_SACL_SECINFO        0x0008
 544 #define SMB_ALL_SECINFO         0x000F
 545 #define SMB_ACL_SECINFO         (SMB_DACL_SECINFO | SMB_SACL_SECINFO)
 546 
 547 #define SECURITY_DESCRIPTOR_REVISION    1
 548 
 549 
 550 #define SE_OWNER_DEFAULTED              0x0001
 551 #define SE_GROUP_DEFAULTED              0x0002
 552 #define SE_DACL_PRESENT                 0x0004
 553 #define SE_DACL_DEFAULTED               0x0008
 554 #define SE_SACL_PRESENT                 0x0010
 555 #define SE_SACL_DEFAULTED               0x0020
 556 #define SE_DACL_AUTO_INHERIT_REQ        0x0100
 557 #define SE_SACL_AUTO_INHERIT_REQ        0x0200
 558 #define SE_DACL_AUTO_INHERITED          0x0400
 559 #define SE_SACL_AUTO_INHERITED          0x0800
 560 #define SE_DACL_PROTECTED               0x1000
 561 #define SE_SACL_PROTECTED               0x2000
 562 #define SE_SELF_RELATIVE                0x8000
 563 
 564 #define SE_DACL_INHERITANCE_MASK        0x1500
 565 #define SE_SACL_INHERITANCE_MASK        0x2A00
 566 
 567 /*
 568  * Security descriptor structures:
 569  *
 570  * smb_sd_t     SD in SMB pointer form
 571  * smb_fssd_t   SD in filesystem form
 572  *
 573  * Filesystems (e.g. ZFS/UFS) don't have something equivalent
 574  * to SD. The items comprising a SMB SD are kept separately in
 575  * filesystem. smb_fssd_t is introduced as a helper to provide
 576  * the required abstraction for CIFS code.
 577  */
 578 
 579 typedef struct smb_sd {
 580         uint8_t         sd_revision;
 581         uint16_t        sd_control;
 582         smb_sid_t       *sd_owner;      /* SID file owner */
 583         smb_sid_t       *sd_group;      /* SID group (for POSIX) */
 584         smb_acl_t       *sd_sacl;       /* ACL System (audits) */
 585         smb_acl_t       *sd_dacl;       /* ACL Discretionary (perm) */
 586 } smb_sd_t;
 587 
 588 /*
 589  * SD header size as it appears on the wire
 590  */
 591 #define SMB_SD_HDRSIZE  20
 592 
 593 /*
 594  * values for smb_fssd.sd_flags
 595  */
 596 #define SMB_FSSD_FLAGS_DIR      0x01
 597 
 598 typedef struct smb_fssd {
 599         uint32_t        sd_secinfo;
 600         uint32_t        sd_flags;
 601         uid_t           sd_uid;
 602         gid_t           sd_gid;
 603         acl_t           *sd_zdacl;
 604         acl_t           *sd_zsacl;
 605 } smb_fssd_t;
 606 
 607 void smb_sd_init(smb_sd_t *, uint8_t);
 608 void smb_sd_term(smb_sd_t *);
 609 uint32_t smb_sd_get_secinfo(smb_sd_t *);
 610 uint32_t smb_sd_len(smb_sd_t *, uint32_t);
 611 uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *);
 612 
 613 void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t);
 614 void smb_fssd_term(smb_fssd_t *);
 615 
 616 void smb_acl_sort(smb_acl_t *);
 617 void smb_acl_free(smb_acl_t *);
 618 smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t);
 619 smb_acl_t *smb_acl_from_zfs(acl_t *);
 620 uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **);
 621 uint16_t smb_acl_len(smb_acl_t *);
 622 boolean_t smb_acl_isvalid(smb_acl_t *, int);
 623 
 624 void smb_fsacl_free(acl_t *);
 625 acl_t *smb_fsacl_alloc(int, int);
 626 
 627 #ifdef __cplusplus
 628 }
 629 #endif
 630 
 631 #endif /* _SMBSRV_NTIFS_H */