xref: /illumos-gate/usr/src/uts/common/smbsrv/smb_share.h (revision b89a8333f5e1f75ec0c269b22524bd2eccb972ba)
13db3f65cSamw /*
23db3f65cSamw  * CDDL HEADER START
33db3f65cSamw  *
43db3f65cSamw  * The contents of this file are subject to the terms of the
53db3f65cSamw  * Common Development and Distribution License (the "License").
63db3f65cSamw  * You may not use this file except in compliance with the License.
73db3f65cSamw  *
83db3f65cSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93db3f65cSamw  * or http://www.opensolaris.org/os/licensing.
103db3f65cSamw  * See the License for the specific language governing permissions
113db3f65cSamw  * and limitations under the License.
123db3f65cSamw  *
133db3f65cSamw  * When distributing Covered Code, include this CDDL HEADER in each
143db3f65cSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153db3f65cSamw  * If applicable, add the following below this CDDL HEADER, with the
163db3f65cSamw  * fields enclosed by brackets "[]" replaced with your own identifying
173db3f65cSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
183db3f65cSamw  *
193db3f65cSamw  * CDDL HEADER END
203db3f65cSamw  */
213db3f65cSamw /*
223db3f65cSamw  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233db3f65cSamw  * Use is subject to license terms.
243db3f65cSamw  */
253db3f65cSamw 
263db3f65cSamw #ifndef _SMB_SHARE_H
273db3f65cSamw #define	_SMB_SHARE_H
283db3f65cSamw 
293db3f65cSamw /*
303db3f65cSamw  * This file defines the LanMan (CIFS/SMB) resource share interface.
313db3f65cSamw  */
323db3f65cSamw 
333db3f65cSamw #include <sys/param.h>
343db3f65cSamw #include <smbsrv/string.h>
353db3f65cSamw #include <smbsrv/hash_table.h>
363db3f65cSamw #include <smbsrv/wintypes.h>
373db3f65cSamw #include <smbsrv/lmerr.h>
383db3f65cSamw #include <smbsrv/smb_common_door.h>
39*b89a8333Snatalie li - Sun Microsystems - Irvine United States #include <netinet/in.h>
403db3f65cSamw 
413db3f65cSamw #ifndef _KERNEL
423db3f65cSamw #include <libshare.h>
433db3f65cSamw #else
443db3f65cSamw #include <sys/door.h>
453db3f65cSamw #endif
463db3f65cSamw 
473db3f65cSamw #ifdef __cplusplus
483db3f65cSamw extern "C" {
493db3f65cSamw #endif
503db3f65cSamw 
513db3f65cSamw /*
523db3f65cSamw  * The following 4 macros are mainly for sharemgr use
533db3f65cSamw  */
543db3f65cSamw #define	SMB_SHROPT_AD_CONTAINER	"ad-container"
553db3f65cSamw #define	SMB_SHROPT_NAME		"name"	/* name is a pseudo property */
56*b89a8333Snatalie li - Sun Microsystems - Irvine United States /* next three properties use access-list a al NFS */
57*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SHOPT_RO		"ro"	/* share is read-only */
58*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SHOPT_RW		"rw"	/* share defaults to read-write */
59*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SHOPT_NONE		"none"	/* share doesn't allow access */
603db3f65cSamw 
613db3f65cSamw #define	SMB_DEFAULT_SHARE_GROUP	"smb"
623db3f65cSamw #define	SMB_PROTOCOL_NAME	"smb"
633db3f65cSamw 
643db3f65cSamw /*
653db3f65cSamw  * RAP protocol share related commands only understand
663db3f65cSamw  * share names in OEM format and there is a 13 char size
673db3f65cSamw  * limitation
683db3f65cSamw  */
693db3f65cSamw #define	SMB_SHARE_OEMNAME_MAX		13
703db3f65cSamw #define	SMB_SHARE_CMNT_MAX		(64 * MTS_MB_CHAR_MAX)
713db3f65cSamw 
723db3f65cSamw /*
733db3f65cSamw  *	struct SHARE_INFO_1 {
743db3f65cSamw  *		char		shi1_netname[13]
753db3f65cSamw  *		char		shi1_pad;
763db3f65cSamw  *		unsigned short	shi1_type
773db3f65cSamw  *		char		*shi1_remark;
783db3f65cSamw  *	}
793db3f65cSamw  */
803db3f65cSamw #define	SHARE_INFO_1_SIZE	(SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4)
813db3f65cSamw 
823db3f65cSamw /*
833db3f65cSamw  * Share flags:
843db3f65cSamw  *
853db3f65cSamw  * SMB_SHRF_TRANS	Transient share
863db3f65cSamw  * SMB_SHRF_PERM	Permanent share
873db3f65cSamw  * SMB_SHRF_AUTOHOME	Autohome share.
883db3f65cSamw  * SMB_SHRF_LONGNAME	Share name in OEM is longer than 13 chars
893db3f65cSamw  * SMB_SHRF_ADMIN	Admin share
90*b89a8333Snatalie li - Sun Microsystems - Irvine United States  * SMB_SHRF_ACC_OPEN	No restrictions set
91*b89a8333Snatalie li - Sun Microsystems - Irvine United States  * SMB_SHRF_ACC_NONE	"none" property set
92*b89a8333Snatalie li - Sun Microsystems - Irvine United States  * SMB_SHRF_ACC_RO	"ro" (readonly) property set
93*b89a8333Snatalie li - Sun Microsystems - Irvine United States  * SMB_SHRF_ACC_RW	"rw" (read/write) property set
94*b89a8333Snatalie li - Sun Microsystems - Irvine United States  * SMB_SHRF_ACC_ALL	All of the access bits
953db3f65cSamw  *
963db3f65cSamw  * All autohome shares are transient but not all transient shares are autohome.
973db3f65cSamw  * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but
983db3f65cSamw  * not autohome.
993db3f65cSamw  */
1003db3f65cSamw #define	SMB_SHRF_TRANS		0x0001
1013db3f65cSamw #define	SMB_SHRF_PERM		0x0002
1023db3f65cSamw #define	SMB_SHRF_AUTOHOME	0x0004
1033db3f65cSamw #define	SMB_SHRF_LONGNAME	0x0008
1043db3f65cSamw #define	SMB_SHRF_ADMIN		0x0010
1053db3f65cSamw 
106*b89a8333Snatalie li - Sun Microsystems - Irvine United States /* Access Flags */
107*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SMB_SHRF_ACC_OPEN	0x0000
108*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SMB_SHRF_ACC_NONE	0x0100
109*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SMB_SHRF_ACC_RO		0x0200
110*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SMB_SHRF_ACC_RW		0x0400
111*b89a8333Snatalie li - Sun Microsystems - Irvine United States #define	SMB_SHRF_ACC_ALL	0x0F00
112*b89a8333Snatalie li - Sun Microsystems - Irvine United States 
113*b89a8333Snatalie li - Sun Microsystems - Irvine United States 
1143db3f65cSamw /*
1153db3f65cSamw  * refcnt is currently only used for autohome.  autohome needs a refcnt
1163db3f65cSamw  * because a user can map his autohome share from more than one client
1173db3f65cSamw  * at the same time and the share should only be removed when the last
1183db3f65cSamw  * one is disconnected
1193db3f65cSamw  */
1203db3f65cSamw typedef struct smb_share {
1213db3f65cSamw 	char		shr_name[MAXNAMELEN];
1223db3f65cSamw 	char		shr_path[MAXPATHLEN];
1233db3f65cSamw 	char		shr_cmnt[SMB_SHARE_CMNT_MAX];
1243db3f65cSamw 	char		shr_container[MAXPATHLEN];
1253db3f65cSamw 	char		shr_oemname[SMB_SHARE_OEMNAME_MAX];
1263db3f65cSamw 	uint32_t	shr_flags;
1273db3f65cSamw 	uint32_t	shr_type;
1283db3f65cSamw 	uint32_t	shr_refcnt;
129*b89a8333Snatalie li - Sun Microsystems - Irvine United States 	uint32_t	shr_access_value;	/* host return access value */
130*b89a8333Snatalie li - Sun Microsystems - Irvine United States 	char		shr_access_none[MAXPATHLEN];
131*b89a8333Snatalie li - Sun Microsystems - Irvine United States 	char		shr_access_ro[MAXPATHLEN];
132*b89a8333Snatalie li - Sun Microsystems - Irvine United States 	char		shr_access_rw[MAXPATHLEN];
1333db3f65cSamw } smb_share_t;
1343db3f65cSamw 
1353db3f65cSamw typedef struct smb_shriter {
1363db3f65cSamw 	smb_share_t	si_share;
1373db3f65cSamw 	HT_ITERATOR	si_hashiter;
138c8ec8eeaSjose borrego 	boolean_t	si_first;
1393db3f65cSamw } smb_shriter_t;
1403db3f65cSamw 
1413db3f65cSamw #define	LMSHARES_PER_REQUEST  10
1423db3f65cSamw typedef struct smb_shrlist {
143c8ec8eeaSjose borrego 	int		sl_cnt;
144c8ec8eeaSjose borrego 	smb_share_t	sl_shares[LMSHARES_PER_REQUEST];
1453db3f65cSamw } smb_shrlist_t;
1463db3f65cSamw 
1473db3f65cSamw /*
1483db3f65cSamw  * This structure is a helper for building NetShareEnum response
1493db3f65cSamw  * in user space and send it back down to kernel.
1503db3f65cSamw  *
1513db3f65cSamw  * es_username	name of the user requesting the shares list which
1523db3f65cSamw  * 		is used to detect if the user has any autohome
1533db3f65cSamw  * es_bufsize	size of the response buffer
1543db3f65cSamw  * es_buf	pointer to the response buffer
1553db3f65cSamw  * es_ntotal	total number of shares exported by server which
1563db3f65cSamw  * 		their OEM names is less then 13 chars
1573db3f65cSamw  * es_nsent	number of shares that can fit in the specified buffer
1583db3f65cSamw  * es_datasize	actual data size (share's data) which was encoded
1593db3f65cSamw  * 		in the response buffer
1603db3f65cSamw  */
1613db3f65cSamw typedef struct smb_enumshare_info {
1623db3f65cSamw 	char		*es_username;
1633db3f65cSamw 	uint16_t	es_bufsize;
1643db3f65cSamw 	char		*es_buf;
1653db3f65cSamw 	uint16_t	es_ntotal;
1663db3f65cSamw 	uint16_t	es_nsent;
1673db3f65cSamw 	uint16_t	es_datasize;
1683db3f65cSamw } smb_enumshare_info_t;
1693db3f65cSamw 
1703db3f65cSamw /*
1713db3f65cSamw  * LanMan share API (for both SMB kernel module and GUI/CLI sub-system)
1723db3f65cSamw  *
1733db3f65cSamw  * NOTE: If any error is encounted by either the door server or client,
1743db3f65cSamw  * NERR_InternalError will be returned by most functions, smb_share_count
1753db3f65cSamw  * will return -1.
1763db3f65cSamw  */
1773db3f65cSamw 
1783db3f65cSamw #ifndef _KERNEL
1793db3f65cSamw 
1803db3f65cSamw /*
181c8ec8eeaSjose borrego  * CIFS share management functions exported by libmlsvc
1823db3f65cSamw  */
1833db3f65cSamw int smb_shr_start(void);
1843db3f65cSamw void smb_shr_stop(void);
185c8ec8eeaSjose borrego void smb_shr_iterinit(smb_shriter_t *);
186c8ec8eeaSjose borrego smb_share_t *smb_shr_iterate(smb_shriter_t *);
187c8ec8eeaSjose borrego void smb_shr_list(int, smb_shrlist_t *);
1883db3f65cSamw int smb_shr_count(void);
189*b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t smb_shr_add(smb_share_t *);
190*b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t smb_shr_remove(char *);
191c8ec8eeaSjose borrego uint32_t smb_shr_rename(char *, char *);
192c8ec8eeaSjose borrego uint32_t smb_shr_get(char *, smb_share_t *);
193*b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t smb_shr_modify(smb_share_t *);
194c8ec8eeaSjose borrego uint32_t smb_shr_get_realpath(const char *, char *, int);
195*b89a8333Snatalie li - Sun Microsystems - Irvine United States void smb_shr_hostaccess(smb_share_t *, ipaddr_t);
1963db3f65cSamw 
197c8ec8eeaSjose borrego boolean_t smb_shr_exists(char *);
198c8ec8eeaSjose borrego int smb_shr_is_special(char *);
199c8ec8eeaSjose borrego boolean_t smb_shr_is_restricted(char *);
200c8ec8eeaSjose borrego boolean_t smb_shr_is_admin(char *);
201c8ec8eeaSjose borrego boolean_t smb_shr_chkname(char *);
2023db3f65cSamw 
2033db3f65cSamw /*
2043db3f65cSamw  * CIFS share management API exported for other processes
2053db3f65cSamw  */
206c8ec8eeaSjose borrego uint32_t smb_share_list(int, smb_shrlist_t *);
2073db3f65cSamw int smb_share_count(void);
2083db3f65cSamw uint32_t smb_share_get(char *, smb_share_t *);
209c8ec8eeaSjose borrego uint32_t smb_share_delete(char *);
210c8ec8eeaSjose borrego uint32_t smb_share_rename(char *, char *);
211c8ec8eeaSjose borrego uint32_t smb_share_create(smb_share_t *);
212*b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t smb_share_modify(smb_share_t *);
2133db3f65cSamw 
2143db3f65cSamw #else
2153db3f65cSamw 
2163db3f65cSamw door_handle_t smb_kshare_init(int);
2173db3f65cSamw void smb_kshare_fini(door_handle_t);
218*b89a8333Snatalie li - Sun Microsystems - Irvine United States uint32_t smb_kshare_getinfo(door_handle_t, char *, smb_share_t *, ipaddr_t);
2193db3f65cSamw int smb_kshare_upcall(door_handle_t, void *, boolean_t);
2203db3f65cSamw uint32_t smb_kshare_enum(door_handle_t, smb_enumshare_info_t *);
2213db3f65cSamw 
2223db3f65cSamw #endif
2233db3f65cSamw 
224c8ec8eeaSjose borrego #define	SMB_SHARE_DNAME		"/var/run/smb_share_door"
2253db3f65cSamw #define	SMB_SHARE_DSIZE		(65 * 1024)
2263db3f65cSamw 
2273db3f65cSamw /*
2283db3f65cSamw  * Door interface
2293db3f65cSamw  *
2303db3f65cSamw  * Define door operations
2313db3f65cSamw  */
2323db3f65cSamw #define	SMB_SHROP_NUM_SHARES		1
2333db3f65cSamw #define	SMB_SHROP_DELETE		2
2343db3f65cSamw #define	SMB_SHROP_RENAME		3
2353db3f65cSamw #define	SMB_SHROP_GETINFO		4
2363db3f65cSamw #define	SMB_SHROP_ADD			5
237c8ec8eeaSjose borrego #define	SMB_SHROP_MODIFY		6
2383db3f65cSamw #define	SMB_SHROP_LIST			7
2393db3f65cSamw #define	SMB_SHROP_ENUM			8
2403db3f65cSamw 
2413db3f65cSamw /*
2423db3f65cSamw  * Door server status
2433db3f65cSamw  *
2443db3f65cSamw  * SMB_SHARE_DERROR is returned by the door server if there is problem
2453db3f65cSamw  * with marshalling/unmarshalling. Otherwise, SMB_SHARE_DSUCCESS is
2463db3f65cSamw  * returned.
2473db3f65cSamw  *
2483db3f65cSamw  */
2493db3f65cSamw #define	SMB_SHARE_DSUCCESS		0
2503db3f65cSamw #define	SMB_SHARE_DERROR		-1
2513db3f65cSamw 
2523db3f65cSamw void smb_dr_get_share(smb_dr_ctx_t *, smb_share_t *);
2533db3f65cSamw void smb_dr_put_share(smb_dr_ctx_t *, smb_share_t *);
2543db3f65cSamw 
2558d96b23eSAlan Wright void smb_share_door_clnt_init(void);
2568d96b23eSAlan Wright void smb_share_door_clnt_fini(void);
2573db3f65cSamw 
2583db3f65cSamw #ifdef __cplusplus
2593db3f65cSamw }
2603db3f65cSamw #endif
2613db3f65cSamw 
2623db3f65cSamw #endif /* _SMB_SHARE_H */
263