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 */ 24 25 #ifndef _SMB_SHARE_H 26 #define _SMB_SHARE_H 27 28 #include <sys/param.h> 29 #include <smbsrv/string.h> 30 #include <smbsrv/smb_inet.h> 31 #include <smbsrv/hash_table.h> 32 #include <smbsrv/wintypes.h> 33 #include <smbsrv/lmerr.h> 34 #include <smbsrv/smb_door.h> 35 36 #ifndef _KERNEL 37 #include <libshare.h> 38 #else 39 #include <sys/door.h> 40 #endif 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /* 47 * Share Properties: 48 * 49 * name Advertised name of the share 50 * 51 * ad-container Active directory container in which the share 52 * will be published 53 * 54 * abe Determines whether Access Based Enumeration is applied 55 * to a share 56 * 57 * csc Client-side caching (CSC) options applied to this share 58 * disabled The client MUST NOT cache any files 59 * manual The client should not automatically cache every file 60 * that it opens 61 * auto The client may cache every file that it opens 62 * vdo The client may cache every file that it opens 63 * and satisfy file requests from its local cache. 64 * 65 * catia CATIA character substitution 66 * 67 * guestok Determines whether guest access is allowed 68 * 69 * next three properties use access-list a al NFS 70 * 71 * ro list of hosts that will have read-only access 72 * rw list of hosts that will have read/write access 73 * none list of hosts that won't be allowed access 74 */ 75 #define SHOPT_AD_CONTAINER "ad-container" 76 #define SHOPT_ABE "abe" 77 #define SHOPT_NAME "name" 78 #define SHOPT_CSC "csc" 79 #define SHOPT_CATIA "catia" 80 #define SHOPT_GUEST "guestok" 81 #define SHOPT_RO "ro" 82 #define SHOPT_RW "rw" 83 #define SHOPT_NONE "none" 84 #define SHOPT_DFSROOT "dfsroot" 85 86 #define SMB_DEFAULT_SHARE_GROUP "smb" 87 #define SMB_PROTOCOL_NAME "smb" 88 89 #define SMB_SHR_MAP 0 90 #define SMB_SHR_UNMAP 1 91 #define SMB_SHR_DISP_CONT_STR "continue" 92 #define SMB_SHR_DISP_TERM_STR "terminate" 93 94 /* 95 * RAP protocol share related commands only understand 96 * share names in OEM format and there is a 13 char size 97 * limitation 98 */ 99 #define SMB_SHARE_OEMNAME_MAX 13 100 #define SMB_SHARE_NTNAME_MAX 81 101 #define SMB_SHARE_CMNT_MAX (64 * MTS_MB_CHAR_MAX) 102 103 /* 104 * struct SHARE_INFO_1 { 105 * char shi1_netname[13] 106 * char shi1_pad; 107 * unsigned short shi1_type 108 * char *shi1_remark; 109 * } 110 */ 111 #define SHARE_INFO_1_SIZE (SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4) 112 113 /* 114 * Share flags: 115 * 116 * There are two types of flags: 117 * 118 * - flags that represent a share property 119 * - other flags set at runtime 120 * 121 * Property flags: 122 * 123 * SMB_SHRF_CSC_DISABLED Client-side caching is disabled for this share 124 * SMB_SHRF_CSC_MANUAL Manual client-side caching is allowed 125 * SMB_SHRF_CSC_AUTO Automatic client-side caching (CSC) is allowed 126 * SMB_SHRF_CSC_VDO Automatic CSC and local cache lookup is allowed 127 * SMB_SHRF_ACC_OPEN No restrictions set 128 * SMB_SHRF_ACC_NONE "none" property set 129 * SMB_SHRF_ACC_RO "ro" (readonly) property set 130 * SMB_SHRF_ACC_RW "rw" (read/write) property set 131 * SMB_SHRF_ACC_ALL All of the access bits 132 * SMB_SHRF_CATIA CATIA character translation on/off 133 * SMB_SHRF_GUEST_OK Guest access on/off 134 * SMB_SHRF_ABE Access Based Enumeration on/off 135 * SMB_SHRF_DFSROOT Share is a standalone DFS root 136 * 137 * Runtime flags: 138 * 139 * SMB_SHRF_TRANS Transient share 140 * SMB_SHRF_PERM Permanent share 141 * SMB_SHRF_AUTOHOME Autohome share. 142 * SMB_SHRF_LONGNAME Share name in OEM is longer than 13 chars 143 * SMB_SHRF_ADMIN Admin share 144 * SMB_SHRF_MAP Map command is specified 145 * SMB_SHRF_UNMAP Unmap command is specified 146 * SMB_SHRF_DISP_TERM Disposition is set to terminate 147 * SMB_SHRF_EXEC_MASK All of the exec bits 148 * 149 * All autohome shares are transient but not all transient shares are autohome. 150 * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but 151 * not autohome. 152 */ 153 154 /* 155 * Property flags 156 */ 157 #define SMB_SHRF_DFSROOT 0x0001 158 #define SMB_SHRF_CATIA 0x0002 159 #define SMB_SHRF_GUEST_OK 0x0004 160 #define SMB_SHRF_ABE 0x0008 161 162 #define SMB_SHRF_CSC_DISABLED 0x0010 163 #define SMB_SHRF_CSC_MANUAL 0x0020 164 #define SMB_SHRF_CSC_AUTO 0x0040 165 #define SMB_SHRF_CSC_VDO 0x0080 166 #define SMB_SHRF_CSC_MASK 0x00F0 167 168 #define SMB_SHRF_ACC_OPEN 0x0000 169 #define SMB_SHRF_ACC_NONE 0x0100 170 #define SMB_SHRF_ACC_RO 0x0200 171 #define SMB_SHRF_ACC_RW 0x0400 172 #define SMB_SHRF_ACC_ALL 0x0F00 173 174 /* 175 * Runtime flags 176 */ 177 #define SMB_SHRF_MAP 0x00010000 178 #define SMB_SHRF_UNMAP 0x00020000 179 #define SMB_SHRF_DISP_TERM 0x00040000 180 #define SMB_SHRF_EXEC_MASK 0x00070000 181 182 #define SMB_SHRF_ADMIN 0x01000000 183 #define SMB_SHRF_TRANS 0x10000000 184 #define SMB_SHRF_PERM 0x20000000 185 #define SMB_SHRF_AUTOHOME 0x40000000 186 #define SMB_SHRF_LONGNAME 0x80000000 187 188 /* 189 * refcnt is currently only used for autohome. autohome needs a refcnt 190 * because a user can map his autohome share from more than one client 191 * at the same time and the share should only be removed when the last 192 * one is disconnected 193 */ 194 typedef struct smb_share { 195 char shr_name[MAXNAMELEN]; 196 char shr_path[MAXPATHLEN]; 197 char shr_cmnt[SMB_SHARE_CMNT_MAX]; 198 char shr_container[MAXPATHLEN]; 199 char shr_oemname[SMB_SHARE_OEMNAME_MAX]; 200 uint32_t shr_flags; 201 uint32_t shr_type; 202 uint32_t shr_refcnt; 203 uint32_t shr_access_value; /* host return access value */ 204 uid_t shr_uid; /* autohome only */ 205 gid_t shr_gid; /* autohome only */ 206 char shr_access_none[MAXPATHLEN]; 207 char shr_access_ro[MAXPATHLEN]; 208 char shr_access_rw[MAXPATHLEN]; 209 } smb_share_t; 210 211 typedef struct smb_shriter { 212 smb_share_t si_share; 213 HT_ITERATOR si_hashiter; 214 boolean_t si_first; 215 } smb_shriter_t; 216 217 #define LMSHARES_PER_REQUEST 10 218 typedef struct smb_shrlist { 219 int sl_cnt; 220 smb_share_t sl_shares[LMSHARES_PER_REQUEST]; 221 } smb_shrlist_t; 222 223 /* 224 * This structure is a helper for building NetShareEnum response 225 * in user space and send it back down to kernel. 226 * 227 * es_posix_uid UID of the user requesting the shares list which 228 * is used to detect if the user has any autohome 229 * es_bufsize size of the response buffer 230 * es_buf pointer to the response buffer 231 * es_ntotal total number of shares exported by server which 232 * their OEM names is less then 13 chars 233 * es_nsent number of shares that can fit in the specified buffer 234 * es_datasize actual data size (share's data) which was encoded 235 * in the response buffer 236 */ 237 typedef struct smb_enumshare_info { 238 uid_t es_posix_uid; 239 uint16_t es_bufsize; 240 char *es_buf; 241 uint16_t es_ntotal; 242 uint16_t es_nsent; 243 uint16_t es_datasize; 244 } smb_enumshare_info_t; 245 246 typedef struct smb_execsub_info { 247 char *e_winname; 248 char *e_userdom; 249 smb_inaddr_t e_srv_ipaddr; 250 smb_inaddr_t e_cli_ipaddr; 251 char *e_cli_netbiosname; 252 uid_t e_uid; 253 } smb_execsub_info_t; 254 255 /* 256 * LanMan share API (for both SMB kernel module and GUI/CLI sub-system) 257 * 258 * NOTE: If any error is encounted by either the door server or client, 259 * NERR_InternalError will be returned by most functions, smb_share_count 260 * will return -1. 261 */ 262 263 #ifndef _KERNEL 264 265 /* 266 * CIFS share management functions exported by libmlsvc 267 */ 268 int smb_shr_start(void); 269 void smb_shr_stop(void); 270 int smb_shr_load(void); 271 void smb_shr_iterinit(smb_shriter_t *); 272 smb_share_t *smb_shr_iterate(smb_shriter_t *); 273 void smb_shr_list(int, smb_shrlist_t *); 274 int smb_shr_count(void); 275 uint32_t smb_shr_add(smb_share_t *); 276 uint32_t smb_shr_remove(char *); 277 uint32_t smb_shr_rename(char *, char *); 278 uint32_t smb_shr_get(char *, smb_share_t *); 279 uint32_t smb_shr_modify(smb_share_t *); 280 uint32_t smb_shr_get_realpath(const char *, char *, int); 281 void smb_shr_hostaccess(smb_share_t *, smb_inaddr_t *); 282 int smb_shr_exec(char *, smb_execsub_info_t *, int); 283 284 boolean_t smb_shr_exists(char *); 285 int smb_shr_is_special(char *); 286 boolean_t smb_shr_is_restricted(char *); 287 boolean_t smb_shr_is_admin(char *); 288 char smb_shr_drive_letter(const char *); 289 290 sa_handle_t smb_shr_sa_enter(void); 291 void smb_shr_sa_exit(void); 292 void smb_shr_sa_csc_option(const char *, smb_share_t *); 293 char *smb_shr_sa_csc_name(const smb_share_t *); 294 void smb_shr_sa_setflag(const char *, smb_share_t *, uint32_t); 295 296 /* 297 * CIFS share management API exported for other processes 298 */ 299 uint32_t smb_share_list(int, smb_shrlist_t *); 300 int smb_share_count(void); 301 uint32_t smb_share_delete(char *); 302 uint32_t smb_share_rename(char *, char *); 303 uint32_t smb_share_create(smb_share_t *); 304 uint32_t smb_share_modify(smb_share_t *); 305 306 #else 307 308 door_handle_t smb_kshare_init(int); 309 void smb_kshare_fini(door_handle_t); 310 uint32_t smb_kshare_getinfo(door_handle_t, char *, smb_share_t *, 311 smb_inaddr_t *); 312 int smb_kshare_upcall(door_handle_t, void *, boolean_t); 313 uint32_t smb_kshare_enum(door_handle_t, smb_enumshare_info_t *); 314 uint32_t smb_kshare_exec(door_handle_t, char *, smb_execsub_info_t *, int); 315 316 #endif 317 318 #define SMB_SHARE_DNAME "/var/run/smb_share_door" 319 #define SMB_SHARE_DSIZE (65 * 1024) 320 321 /* 322 * Door interface 323 * 324 * Define door operations 325 */ 326 #define SMB_SHROP_NUM_SHARES 1 327 #define SMB_SHROP_DELETE 2 328 #define SMB_SHROP_RENAME 3 329 #define SMB_SHROP_GETINFO 4 330 #define SMB_SHROP_ADD 5 331 #define SMB_SHROP_MODIFY 6 332 #define SMB_SHROP_LIST 7 333 #define SMB_SHROP_ENUM 8 334 #define SMB_SHROP_EXEC 9 335 336 /* 337 * Door server status 338 * 339 * SMB_SHARE_DERROR is returned by the door server if there is problem 340 * with marshalling/unmarshalling. Otherwise, SMB_SHARE_DSUCCESS is 341 * returned. 342 * 343 */ 344 #define SMB_SHARE_DSUCCESS 0 345 #define SMB_SHARE_DERROR -1 346 347 void smb_dr_get_share(smb_dr_ctx_t *, smb_share_t *); 348 void smb_dr_put_share(smb_dr_ctx_t *, smb_share_t *); 349 350 void smb_share_door_clnt_init(void); 351 void smb_share_door_clnt_fini(void); 352 353 #ifdef __cplusplus 354 } 355 #endif 356 357 #endif /* _SMB_SHARE_H */ 358