1 /*
   2  * Copyright (c) 2011 - 2012 Apple Inc. All rights reserved.
   3  *
   4  * @APPLE_LICENSE_HEADER_START@
   5  *
   6  * This file contains Original Code and/or Modifications of Original Code
   7  * as defined in and that are subject to the Apple Public Source License
   8  * Version 2.0 (the 'License'). You may not use this file except in
   9  * compliance with the License. Please obtain a copy of the License at
  10  * http://www.opensource.apple.com/apsl/ and read it before using this
  11  * file.
  12  *
  13  * The Original Code and all software distributed under the License are
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18  * Please see the License for the specific language governing rights and
  19  * limitations under the License.
  20  *
  21  * @APPLE_LICENSE_HEADER_END@
  22  */
  23 
  24 /*
  25  * This file contains excerpts of content published under:
  26  * http://opensource.apple.com/source/smb/smb-759.40.1.1
  27  */
  28 
  29 #ifndef _SMB2AAPL_H
  30 #define _SMB2AAPL_H
  31 
  32 #include <sys/types.h>
  33 
  34 /*
  35  * Apple SMB 2/3 "AAPL" Create Context extensions
  36  */
  37 
  38 /* Define "AAPL" Context Command Codes */
  39 enum {
  40         kAAPL_SERVER_QUERY = 1,
  41         kAAPL_RESOLVE_ID = 2
  42 };
  43 
  44 /*
  45  * Server Query Request
  46  *
  47  *      uint32_t command_code = kAAPL_SERVER_QUERY;
  48  *      uint32_t reserved = 0;
  49  *      uint64_t request_bitmap;
  50  *      uint64_t client_capabilities;
  51  *
  52  * Server Query Response
  53  *
  54  *      uint32_t command_code = kAAPL_SERVER_QUERY;
  55  *      uint32_t reserved = 0;
  56  *      uint64_t reply_bitmap;
  57  *      <reply specific data>
  58  *
  59  *      The reply data is packed in the response block in the order specified
  60  *      by the reply_bitmap.
  61  *
  62  * Server Query request/reply bitmap
  63  *  Bit 0 - kAAPL_SERVER_CAPS returns uint64_t bitmap of server capabilities
  64  *  Bit 1 - kAAPL_VOLUME_CAPS returns uint64_t bitmap of volume capabilities
  65  *  Bit 2 - kAAPL_MODEL_INFO returns uint32_t Pad2 followed by uint32_t length
  66  *      followed by the Unicode model string. The Unicode string is padded with
  67  *      zeros to end on an 8 byte boundary.
  68  *
  69  * Example Server Query Context Response Buffer:
  70  *      uint32_t Next = 0;
  71  *      uint16_t NameOffset = 16;
  72  *      uint16_t NameLength = 4;
  73  *      uint16_t Reserved = 0;
  74  *      uint16_t DataOffset = 24;
  75  *      uint32_t DataLength = variable based on ModelString length;
  76  *      uint32_t ContextName = "AAPL";
  77  *      uint32_t Pad = 0;
  78  *      uint32_t CommandCode = kAAPL_SERVER_QUERY
  79  *      uint32_t Reserved = 0;
  80  *      uint64_t ReplyBitmap = kAAPL_SERVER_CAPS | kAAPL_VOLUME_CAPS |
  81  *                             kAAPL_MODEL_INFO;
  82  *      uint64_t ServerCaps = kAAPL_SUPPORTS_READ_DIR_ATTR |
  83  *                            kAAPL_SUPPORTS_OSX_COPYFILE;
  84  *      uint64_t VolumeCaps = kAAPL_SUPPORT_RESOLVE_ID | kAAPL_CASE_SENSITIVE;
  85  *      uint32_t Pad2 = 0;
  86  *      uint32_t ModelStringLen = variable;
  87  *      char *   ModelString;
  88  *      char     PadBytes = variable to end on 8 byte boundary;
  89  *
  90  * kAAPL_SUPPORTS_NFS_ACE - Uses to set Posix permission when ACLs are off
  91  *      on the server. The server must allow the client to get the current
  92  *      ACL and then the client will return it with the desired Posix
  93  *      permissions in the NFS ACE in the ACL.
  94  */
  95 
  96 /* Define Server Query request/response bitmap */
  97 enum {
  98         kAAPL_SERVER_CAPS = 0x01,
  99         kAAPL_VOLUME_CAPS = 0x02,
 100         kAAPL_MODEL_INFO = 0x04
 101 };
 102 
 103 /* Define Client/Server Capabilities bitmap */
 104 enum {
 105         kAAPL_SUPPORTS_READ_DIR_ATTR = 0x01,
 106         kAAPL_SUPPORTS_OSX_COPYFILE = 0x02,
 107         kAAPL_UNIX_BASED = 0x04,
 108         kAAPL_SUPPORTS_NFS_ACE = 0x08
 109 };
 110 
 111 /* Define Volume Capabilities bitmap */
 112 enum {
 113         kAAPL_SUPPORT_RESOLVE_ID = 0x01,
 114         kAAPL_CASE_SENSITIVE = 0x02,
 115         kAAPL_SUPPORTS_FULL_SYNC = 0x04
 116 };
 117 
 118 /*
 119  * kAAPL_SUPPORTS_FULL_SYNC - Full Sync Request
 120  * If the volume supports Full Sync, then when a F_FULLSYNC is done on the
 121  * client side, the client will flush its buffers and then a SMB Flush Request
 122  * with Reserved1 (uint16_t) set to 0xFFFF will be sent to the server. The
 123  * server should flush all its buffer for that file and then call the
 124  * filesystem to perform a F_FULLSYNC on that file.
 125  * Refer to "man fsync" and "man fcntl" in OS X for more information on
 126  * F_FULLSYNC
 127  */
 128 
 129 /*
 130  * Resolve ID Request
 131  *
 132  *      uint32_t command_code = kAAPL_RESOLVE_ID;
 133  *      uint32_t reserved = 0;
 134  *      uint64_t file_id;
 135  *
 136  * Resolve ID Response
 137  *
 138  *      uint32_t command_code = kAAPL_RESOLVE_ID;
 139  *      uint32_t reserved = 0;
 140  *      uint32_t resolve_id_ntstatus;
 141  *      uint32_t path_string_len = variable;
 142  *      char *   path_string;
 143  *
 144  * Example Resolve ID Context Response Buffer:
 145  *      uint32_t Next = 0;
 146  *      uint16_t NameOffset = 16;
 147  *      uint16_t NameLength = 4;
 148  *      uint16_t Reserved = 0;
 149  *      uint16_t DataOffset = 24;
 150  *      uint32_t DataLength = variable based on PathString length;
 151  *      uint32_t ContextName = "AAPL";
 152  *      uint32_t Pad = 0;
 153  *      uint32_t CommandCode = kAAPL_RESOLVE_ID;
 154  *      uint32_t Reserved = 0;
 155  *      uint32_t ResolveID_NTStatus = 0;
 156  *      uint32_t ServerPathLen = variable;
 157  *      char *   ServerPath;
 158  *      char     PadBytes = variable to end on 8 byte boundary;
 159  */
 160 
 161 /*
 162  * ReadDirAttr Support
 163  *
 164  * Server has to support AAPL Create Context and support the
 165  * command of kAAPL_SERVER_QUERY. In the ReplyBitMap, kAAPL_SERVER_CAPS
 166  * has to be set and in the ServerCaps field, kAAPL_SUPPORTS_READ_DIR_ATTR
 167  * must be set.
 168  *
 169  * Client uses FILE_ID_BOTH_DIR_INFORMATION for QueryDir
 170  *
 171  * In the Server reply for FILE_ID_BOTH_DIR_INFORMATION, fields are defined as:
 172  *      uint32_t ea_size;
 173  *      uint8_t short_name_len;
 174  *      uint8_t reserved;
 175  *      uint8_t short_name[24];
 176  *      uint16_t reserved2;
 177  *
 178  * If kAAPL_SUPPORTS_READ_DIR_ATTR is set, the fields will be filled in as:
 179  *      uint32_t max_access;
 180  *      uint8_t short_name_len = 0;
 181  *      uint8_t reserved = 0;
 182  *      uint64_t rsrc_fork_len;
 183  *      uint8_t compressed_finder_info[16];
 184  *      uint16_t unix_mode;  (only if kAAPL_UNIX_BASED is set)
 185  *
 186  * Notes:
 187  *      (1) ea_size is the max access if SMB_EFA_REPARSE_POINT is NOT set in
 188  *      the file attributes. For a reparse point, the SMB Client will assume
 189  *      full access.
 190  *      (2) short_name is now the Resource Fork logical length and minimal
 191  *      Finder Info.
 192  *      (3) SMB Cient will calculate the resource fork allocation size based on
 193  *      block size. This will be done in all places resource fork allocation
 194  *      size is returned by the SMB Client so we return consistent answers.
 195  *      (4) Compressed Finder Info will be only the fields actually still in
 196  *      use in the regular Finder Info and in the Ext Finder Info. SMB client
 197  *      will build a normal Finder Info and Ext Finder Info and fill in the
 198  *      other fields in with zeros.
 199  *      (5) If kAAPL_UNIX_BASED is set, then reserved2 is the entire Posix mode
 200  *
 201  *      struct smb_finder_file_info {
 202  *              uint32_t finder_type;
 203  *              uint32_t finder_creator;
 204  *              uint16_t finder_flags;
 205  *              uint16_t finder_ext_flags;
 206  *              uint32_t finder_date_added;
 207  *      }
 208  *
 209  *      struct smb_finder_folder_info {
 210  *              uint64_t reserved1;
 211  *              uint16_t finder_flags;
 212  *              uint16_t finder_ext_flags;
 213  *              uint32_t finder_date_added;
 214  *      }
 215  *
 216  *
 217  * Normal Finder Info and Extended Finder Info definitions
 218  *      struct finder_file_info {
 219  *              uint32_t finder_type;
 220  *              uint32_t finder_creator;
 221  *              uint16_t finder_flags;
 222  *              uint32_t finder_old_location = 0;
 223  *              uint16_t reserved = 0;
 224  *
 225  *              uint32_t reserved2 = 0;
 226  *              uint32_t finder_date_added;
 227  *              uint16_t finder_ext_flags;
 228  *              uint16_t reserved3 = 0;
 229  *              uint32_t reserved4 = 0;
 230  *      }
 231  *
 232  *      struct finder_folder_info {
 233  *              uint64_t reserved1;
 234  *              uint16_t finder_flags;
 235  *              uint32_t finder_old_location = 0;
 236  *              uint16_t finder_old_view_flags = 0;
 237  *
 238  *              uint32_t finder_old_scroll_position = 0;
 239  *              uint32_t finder_date_added;
 240  *              uint16_t finder_ext_flags;
 241  *              uint16_t reserved3 = 0;
 242  *              uint32_t reserved4 = 0;
 243  *      }
 244  */
 245 
 246 /*
 247  * Note: If you use these smb_finder_* structs, they must be "packed".
 248  * (no alignment padding).  On the server side, all of these can be
 249  * opaque, so for simplicity we use smb_macinfo_t below.
 250  */
 251 struct smb_finder_file_info {
 252         uint32_t finder_type;
 253         uint32_t finder_creator;
 254         uint16_t finder_flags;
 255         uint32_t finder_date_added;
 256         uint16_t finder_ext_flags;
 257 };
 258 
 259 struct smb_finder_folder_info {
 260         uint64_t reserved1;
 261         uint16_t finder_flags;
 262         uint32_t finder_date_added;
 263         uint16_t finder_ext_flags;
 264 };
 265 
 266 struct smb_finder_info {
 267         union {
 268                 struct smb_finder_file_info file_info;
 269                 struct smb_finder_folder_info folder_info;
 270         } u2;
 271 };
 272 
 273 /*
 274  * Implementation specific:
 275  */
 276 typedef struct smb_macinfo {
 277         uint64_t mi_rforksize;
 278         uint32_t mi_finderinfo[4];
 279         uint32_t mi_maxaccess;
 280         uint16_t mi_unixmode;
 281 } smb_macinfo_t;
 282 
 283 int smb2_aapl_get_macinfo(smb_request_t *, smb_odir_t *,
 284         smb_fileinfo_t *, smb_macinfo_t *, char *, size_t);
 285 
 286 #endif  /* _SMB2AAPL_H */