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#ifndef _NETSMB_SMB_RQ_2_H_ 25#define _NETSMB_SMB_RQ_2_H_ 26 27 28/* smb_rq sr_extflags values */ 29#define SMB2_REQUEST 0x0001 /* smb_rq is for SMB 2/3 request */ 30#define SMB2_RESPONSE 0x0002 /* smb_rq received SMB 2/3 response */ 31#define SMB2_REQ_SENT 0x0004 /* smb_rq is for SMB 2/3 request */ 32 33 34/* 35 * Note: Pad all structures to 8 byte boundaries 36 */ 37 38/* 39 * smb2_create_rq flags 40 * 41 * SMB2_CREATE_AAPL_RESOLVE_ID and SMB2_CREATE_DUR_HANDLE use the 42 * createp->create_contextp 43 */ 44typedef enum _SMB2_CREATE_RQ_FLAGS 45{ 46 SMB2_CREATE_DO_CREATE = 0x0001, 47 SMB2_CREATE_IS_NAMED_STREAM = 0x0002, 48 SMB2_CREATE_GET_MAX_ACCESS = 0x0004, 49 SMB2_CREATE_NAME_IS_PATH = 0x0008, 50 SMB2_CREATE_AAPL_QUERY = 0x0010, 51 SMB2_CREATE_AAPL_RESOLVE_ID = 0x0020, 52 SMB2_CREATE_DUR_HANDLE = 0x0040, 53 SMB2_CREATE_DUR_HANDLE_RECONNECT = 0x0080, 54 SMB2_CREATE_ASSUME_DELETE = 0x0100 55} _SMB2_CREATE_RQ_FLAGS; 56 57/* smb2_cmpd_position flags */ 58typedef enum _SMB2_CMPD_POSITION_FLAGS 59{ 60 SMB2_CMPD_FIRST = 0x0001, 61 SMB2_CMPD_MIDDLE = 0x0002, 62 SMB2_CMPD_LAST = 0x0004 63} _SMB2_CMPD_POSITION_FLAGS; 64 65struct smb2_change_notify_rq { 66 uint32_t flags; 67 uint32_t output_buffer_len; 68 SMBFID fid; 69 uint32_t filter; 70 uint32_t pad; 71 void *fn_callback; 72 void *fn_callback_args; 73 74 /* return values */ 75 uint32_t ret_ntstatus; 76 uint32_t ret_buffer_len; 77}; 78 79struct smb2_close_rq { 80 struct smb_share *share; 81 uint32_t flags; 82 uint32_t pad; 83 SMBFID fid; 84 85 /* return values */ 86 uint32_t ret_ntstatus; 87 uint32_t ret_attributes; 88 uint64_t ret_create_time; 89 uint64_t ret_access_time; 90 uint64_t ret_write_time; 91 uint64_t ret_change_time; 92 uint64_t ret_alloc_size; 93 uint64_t ret_eof; 94}; 95 96struct smb2_create_ctx_resolve_id { 97 uint64_t file_id; 98 uint32_t *ret_errorp; 99 char **ret_pathp; 100}; 101 102struct smb2_create_rq { 103 uint64_t flags; /* defined above */ 104 uint8_t oplock_level; 105 uint8_t pad[3]; 106 uint32_t impersonate_level; 107 uint32_t desired_access; 108 uint32_t file_attributes; 109 uint32_t share_access; 110 uint32_t disposition; 111 uint32_t create_options; 112 uint32_t name_len; 113 uint32_t strm_name_len; /* stream name len */ 114 uint32_t pad2; 115 struct smbnode *dnp; 116 char *namep; 117 char *strm_namep; /* stream name */ 118 void *create_contextp; /* used for various create contexts */ 119 120 /* return values */ 121 uint32_t ret_ntstatus; 122 uint32_t ret_attributes; 123 uint8_t ret_oplock_level; 124 uint8_t ret_pad[3]; 125 uint32_t ret_create_action; 126 uint64_t ret_create_time; 127 uint64_t ret_access_time; 128 uint64_t ret_write_time; 129 uint64_t ret_change_time; 130 uint64_t ret_alloc_size; 131 uint64_t ret_eof; 132 SMBFID ret_fid; 133 uint32_t ret_max_access; 134 uint32_t ret_pad2; 135}; 136 137struct smb2_get_dfs_referral { 138 uint16_t max_referral_level; 139 uint16_t pad; 140 uint32_t file_name_len; 141 char *file_namep; 142}; 143 144/* 145 * The SRV_COPYCHUNK_COPY packet is sent in an SMB 2/3 IOCTL Request 146 * by the client to initiate a server-side copy of data. It is 147 * set as the contents of the input data buffer. 148 */ 149#define SMB2_COPYCHUNK_ARR_SIZE 16 150#define SMB2_COPYCHUNK_MAX_CHUNK_LEN 1048576 // 1 MB 151#define SMB2_RESUME_KEY_LEN 24 152 153struct smb2_copychunk { 154 uint8_t source_key[SMB2_RESUME_KEY_LEN]; 155 uint32_t chunk_count; 156 uint32_t reserved; 157}__attribute__((__packed__)); 158 159/* 160 * SRV_COPYCHUNK_COPY: struct to describe 161 * an individual data range to copy. 162 */ 163struct smb2_copychunk_chunk { 164 uint64_t source_offset; 165 uint64_t target_offset; 166 uint32_t length; 167 uint32_t reserved; 168}__attribute__((__packed__)); 169 170/* 171 * SRV_COPYCHUNK_COPY: struct to describe the results of a SRC_COPYCHUNK_COPY 172 * request. 173 * 174 * chunks_written: number of chunks successfully written 175 * (only valid if status != STATUS_INVALID_PARAMETER). 176 * 177 * chunk_bytes_written (depends on status from server): 178 * status != STATUS_INVALID_PARAMETER: number of bytes written 179 * the last chunk that did not successfully process (if a partial 180 * write occurred). 181 * 182 * status == STATUS_INVALID_PARAMETER: indicates maximum number of 183 * bytes the server will allow to be written in a single chunk. 184 * 185 * total_bytes_written (depends on status from server): 186 * status != STATUS_INVALID_PARAMETER: the total number of bytes 187 * written in the server-side copy operation. 188 * 189 * status == STATUS_INVALID_PARAMATER: maximum number of bytes the 190 * server will accept to copy in a single request. 191 */ 192struct smb2_copychunk_result { 193 uint32_t chunks_written; 194 uint32_t chunk_bytes_written; 195 uint32_t total_bytes_written; 196}__attribute__((__packed__)); 197 198struct smb2_ioctl_rq { 199 struct smb_share *share; 200 uint32_t ctl_code; 201 uint32_t pad; 202 SMBFID fid; 203 uint32_t snd_input_len; 204 uint32_t snd_output_len; 205 uint32_t rcv_input_len; 206 uint32_t rcv_output_len; 207 208 /* uio buffers used for ioctls from user space */ 209 uio_t snd_input_uio; 210 uio_t snd_output_uio; 211 uio_t rcv_input_uio; 212 uio_t rcv_output_uio; 213 214 /* data ptrs used for ioctls from kernel space */ 215 uint8_t *snd_input_buffer; 216 uint8_t *rcv_output_buffer; 217 218 /* return values */ 219 uint32_t ret_ntstatus; 220 uint32_t ret_flags; 221 uint32_t ret_input_len; 222 uint32_t ret_output_len; 223}; 224 225struct smb2_query_dir_rq { 226 uint8_t file_info_class; 227 uint8_t flags; 228 uint8_t pad[6]; 229 uint32_t file_index; 230 uint32_t output_buffer_len; 231 SMBFID fid; 232 uint32_t name_len; 233 uint32_t name_flags; /* use UTF_SFM_CONVERSIONS or not */ 234 struct smbnode *dnp; 235 char *namep; 236 237 /* uio buffers used for ioctls from user space */ 238 uio_t rcv_output_uio; 239 240 /* return values */ 241 struct smb_rq *ret_rqp; 242 uint32_t ret_ntstatus; 243 uint32_t ret_buffer_len; 244}; 245 246struct smb2_query_info_rq { 247 uint8_t info_type; 248 uint8_t file_info_class; 249 uint8_t pad[6]; 250 uint32_t add_info; 251 uint32_t flags; 252 uint32_t output_buffer_len; 253 uint32_t input_buffer_len; 254 uint8_t *output_buffer; 255 uint8_t *input_buffer; 256 SMBFID fid; 257 258 /* return values */ 259 uint32_t ret_ntstatus; 260 uint32_t ret_buffer_len; 261}; 262 263/* smb2_rw_rq flags */ 264typedef enum _SMB2_RW_RQ_FLAGS 265{ 266 SMB2_SYNC_IO = 0x0001 267} _SMB2_RW_RQ_FLAGS; 268 269struct smb2_rw_rq { 270 uint64_t flags; 271 uint32_t remaining; 272 uint32_t write_flags; 273 SMBFID fid; 274 uio_t auio; 275 user_ssize_t io_len; 276 277 /* return values */ 278 uint32_t ret_ntstatus; 279 uint32_t ret_len; 280}; 281 282struct smb2_secure_neg_info { 283 uint32_t capabilities; 284 uint8_t guid[16]; 285 uint16_t security_mode; 286 uint16_t dialect_count; 287 uint16_t dialects[8]; 288}; 289 290struct smb2_set_info_file_basic_info { 291 uint64_t create_time; 292 uint64_t access_time; 293 uint64_t write_time; 294 uint64_t change_time; 295 uint32_t attributes; 296 uint32_t pad[4]; 297}; 298 299struct smb2_set_info_file_rename_info { 300 uint8_t replace_if_exists; 301 uint8_t pad[3]; 302 uint32_t tname_len; 303 struct smbnode *tdnp; 304 char *tnamep; 305}; 306 307struct smb2_set_info_security { 308 uint32_t security_attrs; 309 uint16_t control_flags; 310 uint16_t pad; 311 struct ntsid *owner; 312 struct ntsid *group; 313 struct ntacl *sacl; 314 struct ntacl *dacl; 315}; 316 317struct smb2_set_info_rq { 318 uint8_t info_type; 319 uint8_t file_info_class; 320 uint8_t pad[2]; 321 uint32_t add_info; 322 SMBFID fid; 323 uint8_t *input_buffer; 324 325 /* return values */ 326 uint32_t ret_ntstatus; 327 uint8_t ret_pad[4]; 328}; 329 330 331int smb2_rq_alloc(struct smb_connobj *obj, u_char cmd, uint32_t *rq_len, 332 vfs_context_t context, struct smb_rq **rqpp); 333void smb_rq_bend32(struct smb_rq *rqp); 334void smb2_rq_bstart(struct smb_rq *rqp, uint16_t *len_ptr); 335void smb2_rq_bstart32(struct smb_rq *rqp, uint32_t *len_ptr); 336void smb2_rq_align8(struct smb_rq *rqp); 337int smb2_rq_credit_increment(struct smb_rq *rqp); 338uint32_t smb2_rq_credit_check(struct smb_rq *rqp, uint32_t len); 339void smb2_rq_credit_start(struct smb_vc *vcp, uint16_t credits); 340int smb2_rq_message_id_increment(struct smb_rq *rqp); 341int smb2_rq_next_command(struct smb_rq *rqp, size_t *next_cmd_offset, 342 struct mdchain *mdp); 343uint32_t smb2_rq_length(struct smb_rq *rqp); 344uint32_t smb2_rq_parse_header(struct smb_rq *rqp, struct mdchain **mdp); 345int smb_rq_getenv(struct smb_connobj *obj, struct smb_vc **vcp, 346 struct smb_share **share); 347int smb2_rq_update_cmpd_hdr(struct smb_rq *rqp, uint32_t position_flag); 348 349 350#endif 351