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 2013 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 <smbsrv/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 #include <smbsrv/wintypes.h> 45 46 #if defined(_KERNEL) || defined(_FAKE_KERNEL) 47 #include <sys/sysmacros.h> 48 #define xdr_int8_t xdr_char 49 #define xdr_uint8_t xdr_u_char 50 #define xdr_int16_t xdr_short 51 #define xdr_uint16_t xdr_u_short 52 #else /* _KERNEL */ 53 #include <stddef.h> /* offsetof */ 54 #endif /* _KERNEL */ 55 56 /* null-terminated string */ 57 typedef struct smb_string { 58 char *buf; 59 } smb_string_t; 60 61 struct smb_buf32; 62 63 #define SMB_OPIPE_HDR_MAGIC 0x4F484452 /* OHDR */ 64 #define SMB_OPIPE_DOOR_BUFSIZE (30 * 1024) 65 66 /* 67 * Door operations for opipes. 68 */ 69 typedef enum { 70 SMB_OPIPE_NULL = 0, 71 SMB_OPIPE_LOOKUP, 72 SMB_OPIPE_OPEN, 73 SMB_OPIPE_CLOSE, 74 SMB_OPIPE_READ, 75 SMB_OPIPE_WRITE, 76 SMB_OPIPE_EXEC 77 } smb_opipe_op_t; 78 79 #define SMB_DOOR_HDR_MAGIC 0x444F4F52 /* DOOR */ 80 81 /* 82 * Door header flags. 83 */ 84 #define SMB_DF_ASYNC 0x00000001 /* Asynchronous call */ 85 #define SMB_DF_SYSSPACE 0x00000002 /* Called from the kernel */ 86 #define SMB_DF_USERSPACE 0x00000004 /* Called from user space */ 87 #define SMB_DF_FAKE_KERNEL 0x00000008 /* Called from fake kernel */ 88 89 /* 90 * Header for door calls. The op codes and return codes are defined 91 * in smb_door.h. The header is here to make it available to XDR. 92 * 93 * fid For opipe: the pipe identifier. 94 * op The door operation being invoked. 95 * txid Unique transaction id for the current door call. 96 * datalen Bytes of data following the header (excludes the header). 97 * resid For opipe: the number of bytes remaining in the server. 98 * door_rc Return code provided by the door server. 99 * status A pass-through status provided by the door operation. 100 */ 101 typedef struct smb_doorhdr { 102 uint32_t dh_magic; 103 uint32_t dh_flags; 104 uint32_t dh_fid; 105 uint32_t dh_op; 106 uint32_t dh_txid; 107 uint32_t dh_datalen; 108 uint32_t dh_resid; 109 uint32_t dh_door_rc; 110 uint32_t dh_status; 111 } smb_doorhdr_t; 112 113 typedef struct smb_netuserinfo { 114 uint64_t ui_session_id; 115 uint16_t ui_smb_uid; 116 uint16_t ui_domain_len; 117 char *ui_domain; 118 uint16_t ui_account_len; 119 char *ui_account; 120 uid_t ui_posix_uid; 121 uint16_t ui_workstation_len; 122 char *ui_workstation; 123 smb_inaddr_t ui_ipaddr; 124 int32_t ui_native_os; 125 int64_t ui_logon_time; 126 uint32_t ui_numopens; 127 uint32_t ui_flags; 128 } smb_netuserinfo_t; 129 130 typedef struct smb_opennum { 131 uint32_t open_users; 132 uint32_t open_trees; 133 uint32_t open_files; 134 uint32_t qualtype; 135 char qualifier[MAXNAMELEN]; 136 } smb_opennum_t; 137 138 typedef struct smb_netconnectinfo { 139 uint32_t ci_id; 140 uint32_t ci_type; 141 uint32_t ci_numopens; 142 uint32_t ci_numusers; 143 uint32_t ci_time; 144 uint32_t ci_namelen; 145 uint32_t ci_sharelen; 146 char *ci_username; 147 char *ci_share; 148 } smb_netconnectinfo_t; 149 150 typedef struct smb_netfileinfo { 151 uint16_t fi_fid; 152 uint32_t fi_uniqid; 153 uint32_t fi_permissions; 154 uint32_t fi_numlocks; 155 uint32_t fi_pathlen; 156 uint32_t fi_namelen; 157 char *fi_path; 158 char *fi_username; 159 } smb_netfileinfo_t; 160 161 typedef struct smb_netsvcitem { 162 list_node_t nsi_lnd; 163 union { 164 smb_netuserinfo_t nsi_user; 165 smb_netconnectinfo_t nsi_tree; 166 smb_netfileinfo_t nsi_ofile; 167 } nsi_un; 168 } smb_netsvcitem_t; 169 170 typedef struct smb_netsvc { 171 list_t ns_list; 172 smb_netsvcitem_t *ns_items; 173 smb_ioc_svcenum_t *ns_ioc; 174 uint32_t ns_ioclen; 175 } smb_netsvc_t; 176 177 178 bool_t smb_buf32_xdr(XDR *, struct smb_buf32 *); 179 bool_t smb_string_xdr(XDR *, smb_string_t *); 180 bool_t smb_inaddr_xdr(XDR *, smb_inaddr_t *); 181 182 const char *smb_doorhdr_opname(uint32_t); 183 int smb_doorhdr_encode(smb_doorhdr_t *, uint8_t *, uint32_t); 184 int smb_doorhdr_decode(smb_doorhdr_t *, uint8_t *, uint32_t); 185 bool_t smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp); 186 int smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *); 187 int smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *); 188 bool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *); 189 int smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t, 190 uint_t *); 191 int smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t, 192 uint_t *); 193 bool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *); 194 int smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *); 195 int smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *); 196 bool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *); 197 198 typedef uint16_t sid_type_t; 199 200 typedef struct lsa_account { 201 ntstatus_t a_status; 202 sid_type_t a_sidtype; 203 char a_domain[MAXNAMELEN]; 204 char a_name[MAXNAMELEN]; 205 char a_sid[SMB_SID_STRSZ]; 206 } lsa_account_t; 207 208 int lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t); 209 int lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t); 210 bool_t lsa_account_xdr(XDR *, lsa_account_t *); 211 212 /* 213 * VSS Door Structures 214 */ 215 #define SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss") 216 217 typedef struct smb_gmttoken_query { 218 uint32_t gtq_count; 219 char *gtq_path; 220 } smb_gmttoken_query_t; 221 222 typedef char *smb_gmttoken_t; 223 224 typedef struct smb_gmttoken_response { 225 uint32_t gtr_count; 226 struct { 227 uint_t gtr_gmttokens_len; 228 smb_gmttoken_t *gtr_gmttokens_val; 229 } gtr_gmttokens; 230 } smb_gmttoken_response_t; 231 232 typedef struct smb_gmttoken_snapname { 233 char *gts_path; 234 char *gts_gmttoken; 235 } smb_gmttoken_snapname_t; 236 237 bool_t smb_gmttoken_query_xdr(XDR *, smb_gmttoken_query_t *); 238 bool_t smb_gmttoken_response_xdr(XDR *, smb_gmttoken_response_t *); 239 bool_t smb_gmttoken_snapname_xdr(XDR *, smb_gmttoken_snapname_t *); 240 241 /* 242 * User and Group Quotas 243 * 244 * SMB User and Group quota values of SMB_QUOTA_UNLIMITED mean 245 * No Limit. This maps to 0 (none) on ZFS. 246 */ 247 #define SMB_QUOTA_UNLIMITED 0xFFFFFFFFFFFFFFFF 248 249 typedef struct smb_quota { 250 list_node_t q_list_node; 251 char q_sidstr[SMB_SID_STRSZ]; 252 uint32_t q_sidtype; 253 uint64_t q_used; 254 uint64_t q_thresh; 255 uint64_t q_limit; 256 avl_node_t q_avl_node; 257 } smb_quota_t; 258 259 typedef struct smb_quota_sid { 260 list_node_t qs_list_node; 261 char qs_sidstr[SMB_SID_STRSZ]; 262 } smb_quota_sid_t; 263 264 typedef enum { 265 SMB_QUOTA_QUERY_INVALID_OP, 266 SMB_QUOTA_QUERY_SIDLIST, 267 SMB_QUOTA_QUERY_STARTSID, 268 SMB_QUOTA_QUERY_ALL 269 } smb_quota_query_op_t; 270 271 typedef struct smb_quota_query { 272 char *qq_root_path; 273 uint32_t qq_query_op; /* smb_quota_query_op_t */ 274 bool_t qq_single; 275 bool_t qq_restart; 276 uint32_t qq_max_quota; 277 list_t qq_sid_list; /* list of smb_quota_sid_t */ 278 } smb_quota_query_t; 279 280 typedef struct smb_quota_response { 281 uint32_t qr_status; 282 list_t qr_quota_list; /* list of smb_quota_t */ 283 } smb_quota_response_t; 284 285 typedef struct smb_quota_set { 286 char *qs_root_path; 287 list_t qs_quota_list; /* list of smb_quota_t */ 288 } smb_quota_set_t; 289 290 bool_t smb_quota_query_xdr(XDR *, smb_quota_query_t *); 291 bool_t smb_quota_response_xdr(XDR *, smb_quota_response_t *); 292 bool_t smb_quota_set_xdr(XDR *, smb_quota_set_t *); 293 294 typedef struct dfs_referral_query { 295 dfs_reftype_t rq_type; 296 char *rq_path; 297 } dfs_referral_query_t; 298 299 typedef struct dfs_referral_response { 300 dfs_info_t rp_referrals; 301 uint32_t rp_status; 302 } dfs_referral_response_t; 303 304 bool_t dfs_referral_query_xdr(XDR *, dfs_referral_query_t *); 305 bool_t dfs_referral_response_xdr(XDR *, dfs_referral_response_t *); 306 307 typedef struct smb_shr_hostaccess_query { 308 char *shq_none; 309 char *shq_ro; 310 char *shq_rw; 311 uint32_t shq_flag; 312 smb_inaddr_t shq_ipaddr; 313 } smb_shr_hostaccess_query_t; 314 315 bool_t smb_shr_hostaccess_query_xdr(XDR *, smb_shr_hostaccess_query_t *); 316 bool_t smb_shr_execinfo_xdr(XDR *, smb_shr_execinfo_t *); 317 318 #ifdef __cplusplus 319 } 320 #endif 321 322 #endif /* _SMBSRV_SMB_XDR_H */ 323