1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved. 24 */ 25 26 #ifndef _SMBSRV_SMB_XDR_H 27 #define _SMBSRV_SMB_XDR_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <rpc/xdr.h> 34 #include <sys/param.h> 35 #include <sys/avl.h> 36 #include <sys/list.h> 37 #include <smb/wintypes.h> 38 #include <smbsrv/smb_sid.h> 39 #include <smbsrv/smbinfo.h> 40 #include <smbsrv/smb_ioctl.h> 41 #include <smbsrv/smb_sid.h> 42 #include <smbsrv/smb_share.h> 43 #include <smbsrv/smb_dfs.h> 44 45 #if defined(_KERNEL) || defined(_FAKE_KERNEL) 46 #include <sys/sysmacros.h> 47 #define xdr_int8_t xdr_char 48 #define xdr_uint8_t xdr_u_char 49 #define xdr_int16_t xdr_short 50 #define xdr_uint16_t xdr_u_short 51 #else /* _KERNEL */ 52 #include <stddef.h> /* offsetof */ 53 #endif /* _KERNEL */ 54 55 /* 56 * null-terminated string 57 * See also: smb_string_xdr() 58 */ 59 typedef struct smb_string { 60 char *buf; 61 } smb_string_t; 62 63 struct smb_buf32; 64 65 /* 66 * Initial message on server named pipes. 67 * Followed by smb_netuserinfo 68 */ 69 typedef struct smb_pipehdr { 70 uint32_t ph_magic; 71 uint32_t ph_uilen; 72 } smb_pipehdr_t; 73 74 #define SMB_PIPE_HDR_MAGIC 0x50495045 /* PIPE */ 75 76 /* 77 * Maximum message size for SMB named pipes. 78 * Should be less than PIPE_BUF (5120). 79 * Use the same value Windows does. 80 */ 81 #define SMB_PIPE_MAX_MSGSIZE 4280 82 83 /* 84 * Door up-call stuff shared with smbd 85 */ 86 87 #define SMB_DOOR_HDR_MAGIC 0x444F4F52 /* DOOR */ 88 89 /* 90 * Door header flags. 91 */ 92 #define SMB_DF_ASYNC 0x00000001 /* Asynchronous call */ 93 #define SMB_DF_SYSSPACE 0x00000002 /* Called from the kernel */ 94 #define SMB_DF_USERSPACE 0x00000004 /* Called from user space */ 95 #define SMB_DF_FAKE_KERNEL 0x00000008 /* Called from fake kernel */ 96 97 /* 98 * Header for door calls. The op codes and return codes are defined 99 * in smb_door.h. The header is here to make it available to XDR. 100 * 101 * fid For opipe: the pipe identifier. 102 * op The door operation being invoked. 103 * txid Unique transaction id for the current door call. 104 * datalen Bytes of data following the header (excludes the header). 105 * resid For opipe: the number of bytes remaining in the server. 106 * door_rc Return code provided by the door server. 107 * status A pass-through status provided by the door operation. 108 * 109 * See also: smb_doorhdr_xdr() 110 */ 111 typedef struct smb_doorhdr { 112 uint32_t dh_magic; 113 uint32_t dh_flags; 114 uint32_t dh_fid; 115 uint32_t dh_op; 116 uint32_t dh_txid; 117 uint32_t dh_datalen; 118 uint32_t dh_resid; 119 uint32_t dh_door_rc; 120 uint32_t dh_status; 121 } smb_doorhdr_t; 122 123 /* 124 * Information about the client of a named pipe, provided by smbsrv 125 * to the server side of the named pipe (the RPC service). 126 * See also: smb_netuserinfo_xdr() 127 */ 128 typedef struct smb_netuserinfo { 129 uint64_t ui_session_id; 130 uint16_t ui_smb_uid; 131 uint16_t ui_domain_len; 132 char *ui_domain; 133 uint16_t ui_account_len; 134 char *ui_account; 135 uid_t ui_posix_uid; 136 uint16_t ui_workstation_len; 137 char *ui_workstation; 138 smb_inaddr_t ui_ipaddr; 139 int32_t ui_native_os; 140 int64_t ui_logon_time; 141 uint32_t ui_numopens; 142 uint32_t ui_flags; 143 } smb_netuserinfo_t; 144 145 typedef struct smb_opennum { 146 uint32_t open_users; 147 uint32_t open_trees; 148 uint32_t open_files; 149 uint32_t qualtype; 150 char qualifier[MAXNAMELEN]; 151 } smb_opennum_t; 152 153 /* 154 * SMB (internal) representation of a tree connection (etc.) 155 * See also: smb_netconnectinfo_xdr() 156 */ 157 typedef struct smb_netconnectinfo { 158 uint32_t ci_id; 159 uint32_t ci_type; 160 uint32_t ci_numopens; 161 uint32_t ci_numusers; 162 uint32_t ci_time; 163 uint32_t ci_namelen; 164 uint32_t ci_sharelen; 165 char *ci_username; 166 char *ci_share; 167 } smb_netconnectinfo_t; 168 169 /* 170 * SMB (internal) representation of an open file. 171 * See also: smb_netfileinfo_xdr() 172 */ 173 typedef struct smb_netfileinfo { 174 uint16_t fi_fid; 175 uint32_t fi_uniqid; 176 uint32_t fi_permissions; 177 uint32_t fi_numlocks; 178 uint32_t fi_pathlen; 179 uint32_t fi_namelen; 180 char *fi_path; 181 char *fi_username; 182 } smb_netfileinfo_t; 183 184 typedef struct smb_netsvcitem { 185 list_node_t nsi_lnd; 186 union { 187 smb_netuserinfo_t nsi_user; 188 smb_netconnectinfo_t nsi_tree; 189 smb_netfileinfo_t nsi_ofile; 190 } nsi_un; 191 } smb_netsvcitem_t; 192 193 typedef struct smb_netsvc { 194 list_t ns_list; 195 smb_netsvcitem_t *ns_items; 196 smb_ioc_svcenum_t *ns_ioc; 197 uint32_t ns_ioclen; 198 } smb_netsvc_t; 199 200 201 bool_t smb_buf32_xdr(XDR *, struct smb_buf32 *); 202 bool_t smb_string_xdr(XDR *, smb_string_t *); 203 bool_t smb_inaddr_xdr(XDR *, smb_inaddr_t *); 204 205 const char *smb_doorhdr_opname(uint32_t); 206 int smb_doorhdr_encode(smb_doorhdr_t *, uint8_t *, uint32_t); 207 int smb_doorhdr_decode(smb_doorhdr_t *, uint8_t *, uint32_t); 208 bool_t smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp); 209 int smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *); 210 int smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *); 211 bool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *); 212 int smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t, 213 uint_t *); 214 int smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t, 215 uint_t *); 216 bool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *); 217 int smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *); 218 int smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *); 219 bool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *); 220 221 typedef uint16_t sid_type_t; 222 223 typedef struct lsa_account { 224 ntstatus_t a_status; 225 sid_type_t a_sidtype; 226 char a_domain[MAXNAMELEN]; 227 char a_name[MAXNAMELEN]; 228 char a_sid[SMB_SID_STRSZ]; 229 } lsa_account_t; 230 231 int lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t); 232 int lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t); 233 bool_t lsa_account_xdr(XDR *, lsa_account_t *); 234 235 /* 236 * VSS Door Structures 237 */ 238 #define SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss") 239 240 /* 241 * Args for enumerating "previous versions". 242 * See also: smb_gmttoken_query_xdr() 243 */ 244 typedef struct smb_gmttoken_query { 245 uint32_t gtq_count; 246 char *gtq_path; 247 } smb_gmttoken_query_t; 248 249 /* 250 * Part of response for enumerating "previous versions". 251 * See also: smb_gmttoken_xdr() 252 */ 253 typedef char *smb_gmttoken_t; 254 255 /* 256 * Response for enumerating "previous versions". 257 * See also: smb_gmttoken_response_xdr() 258 */ 259 typedef struct smb_gmttoken_response { 260 uint32_t gtr_count; 261 struct { 262 uint_t gtr_gmttokens_len; 263 smb_gmttoken_t *gtr_gmttokens_val; 264 } gtr_gmttokens; 265 } smb_gmttoken_response_t; 266 267 /* 268 * Args to lookup "previous versions" during open. 269 * See also: smb_gmttoken_snapname_xdr() 270 */ 271 typedef struct smb_gmttoken_snapname { 272 char *gts_path; 273 char *gts_gmttoken; 274 uint64_t gts_toktime; /* seconds */ 275 } smb_gmttoken_snapname_t; 276 277 bool_t smb_gmttoken_query_xdr(XDR *, smb_gmttoken_query_t *); 278 bool_t smb_gmttoken_response_xdr(XDR *, smb_gmttoken_response_t *); 279 bool_t smb_gmttoken_snapname_xdr(XDR *, smb_gmttoken_snapname_t *); 280 281 /* 282 * User and Group Quotas 283 * 284 * SMB User and Group quota values of SMB_QUOTA_UNLIMITED mean 285 * No Limit. This maps to 0 (none) on ZFS. 286 */ 287 #define SMB_QUOTA_UNLIMITED 0xFFFFFFFFFFFFFFFF 288 289 /* 290 * SMB (internal) representation of a quota response 291 * See also: smb_quota_xdr() 292 */ 293 typedef struct smb_quota { 294 list_node_t q_list_node; 295 char q_sidstr[SMB_SID_STRSZ]; 296 uint32_t q_sidtype; 297 uint64_t q_used; 298 uint64_t q_thresh; 299 uint64_t q_limit; 300 avl_node_t q_avl_node; 301 } smb_quota_t; 302 303 /* 304 * Part of a quota response 305 * See also: smb_quota_sid_xdr() 306 */ 307 typedef struct smb_quota_sid { 308 list_node_t qs_list_node; 309 char qs_sidstr[SMB_SID_STRSZ]; 310 } smb_quota_sid_t; 311 312 typedef enum { 313 SMB_QUOTA_QUERY_INVALID_OP, 314 SMB_QUOTA_QUERY_SIDLIST, 315 SMB_QUOTA_QUERY_STARTSID, 316 SMB_QUOTA_QUERY_ALL 317 } smb_quota_query_op_t; 318 319 /* 320 * SMB (internal) form of a quota lookup 321 * See also: smb_quota_query_xdr() 322 */ 323 typedef struct smb_quota_query { 324 char *qq_root_path; 325 uint32_t qq_query_op; /* smb_quota_query_op_t */ 326 bool_t qq_single; 327 bool_t qq_restart; 328 uint32_t qq_max_quota; 329 list_t qq_sid_list; /* list of smb_quota_sid_t */ 330 } smb_quota_query_t; 331 332 /* 333 * The get quota response (list of quota records) 334 * See also: smb_quota_response_xdr() 335 */ 336 typedef struct smb_quota_response { 337 uint32_t qr_status; 338 list_t qr_quota_list; /* list of smb_quota_t */ 339 } smb_quota_response_t; 340 341 /* 342 * The set quota request (list of quota records) 343 * See also: smb_quota_set_xdr() 344 */ 345 typedef struct smb_quota_set { 346 char *qs_root_path; 347 list_t qs_quota_list; /* list of smb_quota_t */ 348 } smb_quota_set_t; 349 350 bool_t smb_quota_query_xdr(XDR *, smb_quota_query_t *); 351 bool_t smb_quota_response_xdr(XDR *, smb_quota_response_t *); 352 bool_t smb_quota_set_xdr(XDR *, smb_quota_set_t *); 353 354 typedef struct dfs_referral_query { 355 dfs_reftype_t rq_type; 356 char *rq_path; 357 } dfs_referral_query_t; 358 359 typedef struct dfs_referral_response { 360 dfs_info_t rp_referrals; 361 uint32_t rp_status; 362 } dfs_referral_response_t; 363 364 bool_t dfs_referral_query_xdr(XDR *, dfs_referral_query_t *); 365 bool_t dfs_referral_response_xdr(XDR *, dfs_referral_response_t *); 366 367 typedef struct smb_shr_hostaccess_query { 368 char *shq_none; 369 char *shq_ro; 370 char *shq_rw; 371 uint32_t shq_flag; 372 smb_inaddr_t shq_ipaddr; 373 } smb_shr_hostaccess_query_t; 374 375 bool_t smb_shr_hostaccess_query_xdr(XDR *, smb_shr_hostaccess_query_t *); 376 bool_t smb_shr_execinfo_xdr(XDR *, smb_shr_execinfo_t *); 377 378 #ifdef __cplusplus 379 } 380 #endif 381 382 #endif /* _SMBSRV_SMB_XDR_H */ 383