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 2008 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 #pragma ident "@(#)smb_share.h 1.7 08/08/07 SMI" 30 31 /* 32 * This file defines the LanMan (CIFS/SMB) resource share interface. 33 */ 34 35 #include <sys/param.h> 36 #include <smbsrv/string.h> 37 #include <smbsrv/hash_table.h> 38 #include <smbsrv/wintypes.h> 39 #include <smbsrv/lmerr.h> 40 #include <smbsrv/smb_common_door.h> 41 42 #ifndef _KERNEL 43 #include <libshare.h> 44 #else 45 #include <sys/door.h> 46 #endif 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 /* 53 * The following 4 macros are mainly for sharemgr use 54 */ 55 #define SMB_SHROPT_AD_CONTAINER "ad-container" 56 #define SMB_SHROPT_NAME "name" /* name is a pseudo property */ 57 58 #define SMB_DEFAULT_SHARE_GROUP "smb" 59 #define SMB_PROTOCOL_NAME "smb" 60 61 /* 62 * RAP protocol share related commands only understand 63 * share names in OEM format and there is a 13 char size 64 * limitation 65 */ 66 #define SMB_SHARE_OEMNAME_MAX 13 67 #define SMB_SHARE_CMNT_MAX (64 * MTS_MB_CHAR_MAX) 68 69 /* 70 * struct SHARE_INFO_1 { 71 * char shi1_netname[13] 72 * char shi1_pad; 73 * unsigned short shi1_type 74 * char *shi1_remark; 75 * } 76 */ 77 #define SHARE_INFO_1_SIZE (SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4) 78 79 /* 80 * Share flags: 81 * 82 * SMB_SHRF_TRANS Transient share 83 * SMB_SHRF_PERM Permanent share 84 * SMB_SHRF_AUTOHOME Autohome share. 85 * SMB_SHRF_LONGNAME Share name in OEM is longer than 13 chars 86 * SMB_SHRF_ADMIN Admin share 87 * 88 * All autohome shares are transient but not all transient shares are autohome. 89 * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but 90 * not autohome. 91 */ 92 #define SMB_SHRF_TRANS 0x0001 93 #define SMB_SHRF_PERM 0x0002 94 #define SMB_SHRF_AUTOHOME 0x0004 95 #define SMB_SHRF_LONGNAME 0x0008 96 #define SMB_SHRF_ADMIN 0x0010 97 98 /* 99 * refcnt is currently only used for autohome. autohome needs a refcnt 100 * because a user can map his autohome share from more than one client 101 * at the same time and the share should only be removed when the last 102 * one is disconnected 103 */ 104 typedef struct smb_share { 105 char shr_name[MAXNAMELEN]; 106 char shr_path[MAXPATHLEN]; 107 char shr_cmnt[SMB_SHARE_CMNT_MAX]; 108 char shr_container[MAXPATHLEN]; 109 char shr_oemname[SMB_SHARE_OEMNAME_MAX]; 110 uint32_t shr_flags; 111 uint32_t shr_type; 112 uint32_t shr_refcnt; 113 } smb_share_t; 114 115 typedef struct smb_shriter { 116 smb_share_t si_share; 117 HT_ITERATOR si_hashiter; 118 boolean_t si_first; 119 } smb_shriter_t; 120 121 #define LMSHARES_PER_REQUEST 10 122 typedef struct smb_shrlist { 123 int sl_cnt; 124 smb_share_t sl_shares[LMSHARES_PER_REQUEST]; 125 } smb_shrlist_t; 126 127 /* 128 * This structure is a helper for building NetShareEnum response 129 * in user space and send it back down to kernel. 130 * 131 * es_username name of the user requesting the shares list which 132 * is used to detect if the user has any autohome 133 * es_bufsize size of the response buffer 134 * es_buf pointer to the response buffer 135 * es_ntotal total number of shares exported by server which 136 * their OEM names is less then 13 chars 137 * es_nsent number of shares that can fit in the specified buffer 138 * es_datasize actual data size (share's data) which was encoded 139 * in the response buffer 140 */ 141 typedef struct smb_enumshare_info { 142 char *es_username; 143 uint16_t es_bufsize; 144 char *es_buf; 145 uint16_t es_ntotal; 146 uint16_t es_nsent; 147 uint16_t es_datasize; 148 } smb_enumshare_info_t; 149 150 /* 151 * LanMan share API (for both SMB kernel module and GUI/CLI sub-system) 152 * 153 * NOTE: If any error is encounted by either the door server or client, 154 * NERR_InternalError will be returned by most functions, smb_share_count 155 * will return -1. 156 */ 157 158 #ifndef _KERNEL 159 160 /* 161 * CIFS share management functions exported by libmlsvc 162 */ 163 int smb_shr_start(void); 164 void smb_shr_stop(void); 165 void smb_shr_iterinit(smb_shriter_t *); 166 smb_share_t *smb_shr_iterate(smb_shriter_t *); 167 void smb_shr_list(int, smb_shrlist_t *); 168 int smb_shr_count(void); 169 uint32_t smb_shr_create(smb_share_t *, boolean_t); 170 uint32_t smb_shr_delete(char *, boolean_t); 171 uint32_t smb_shr_rename(char *, char *); 172 uint32_t smb_shr_get(char *, smb_share_t *); 173 uint32_t smb_shr_modify(char *, const char *, const char *, boolean_t); 174 uint32_t smb_shr_get_realpath(const char *, char *, int); 175 176 boolean_t smb_shr_exists(char *); 177 int smb_shr_is_special(char *); 178 boolean_t smb_shr_is_restricted(char *); 179 boolean_t smb_shr_is_admin(char *); 180 boolean_t smb_shr_chkname(char *); 181 182 /* 183 * CIFS share management API exported for other processes 184 */ 185 uint32_t smb_share_list(int, smb_shrlist_t *); 186 int smb_share_count(void); 187 uint32_t smb_share_get(char *, smb_share_t *); 188 uint32_t smb_share_delete(char *); 189 uint32_t smb_share_rename(char *, char *); 190 uint32_t smb_share_create(smb_share_t *); 191 uint32_t smb_share_modify(char *, char *, char *); 192 193 #else 194 195 door_handle_t smb_kshare_init(int); 196 void smb_kshare_fini(door_handle_t); 197 uint32_t smb_kshare_getinfo(door_handle_t, const char *, smb_share_t *); 198 int smb_kshare_upcall(door_handle_t, void *, boolean_t); 199 uint32_t smb_kshare_enum(door_handle_t, smb_enumshare_info_t *); 200 201 #endif 202 203 #define SMB_SHARE_DNAME "/var/run/smb_share_door" 204 #define SMB_SHARE_DSIZE (65 * 1024) 205 206 /* 207 * Door interface 208 * 209 * Define door operations 210 */ 211 #define SMB_SHROP_NUM_SHARES 1 212 #define SMB_SHROP_DELETE 2 213 #define SMB_SHROP_RENAME 3 214 #define SMB_SHROP_GETINFO 4 215 #define SMB_SHROP_ADD 5 216 #define SMB_SHROP_MODIFY 6 217 #define SMB_SHROP_LIST 7 218 #define SMB_SHROP_ENUM 8 219 220 /* 221 * Door server status 222 * 223 * SMB_SHARE_DERROR is returned by the door server if there is problem 224 * with marshalling/unmarshalling. Otherwise, SMB_SHARE_DSUCCESS is 225 * returned. 226 * 227 */ 228 #define SMB_SHARE_DSUCCESS 0 229 #define SMB_SHARE_DERROR -1 230 231 void smb_dr_get_share(smb_dr_ctx_t *, smb_share_t *); 232 void smb_dr_put_share(smb_dr_ctx_t *, smb_share_t *); 233 234 void smb_share_dclose(void); 235 236 #ifdef __cplusplus 237 } 238 #endif 239 240 #endif /* _SMB_SHARE_H */ 241