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