1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw 
22da6c28aaSamw /*
23c5866007SKeyur Desai  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
241160dcf7SMatt Barden  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
25da6c28aaSamw  */
26da6c28aaSamw 
27da6c28aaSamw /*
28da6c28aaSamw  * SMB specific functions
29da6c28aaSamw  */
30da6c28aaSamw #include <stdio.h>
31da6c28aaSamw #include <string.h>
32da6c28aaSamw #include <ctype.h>
33da6c28aaSamw #include <stdlib.h>
34da6c28aaSamw #include <unistd.h>
35da6c28aaSamw #include <zone.h>
36da6c28aaSamw #include <errno.h>
37da6c28aaSamw #include <locale.h>
38da6c28aaSamw #include <fcntl.h>
39da6c28aaSamw #include <sys/types.h>
40da6c28aaSamw #include <sys/stat.h>
41da6c28aaSamw #include <syslog.h>
42da6c28aaSamw #include "libshare.h"
43da6c28aaSamw #include "libshare_impl.h"
44da6c28aaSamw #include <pwd.h>
45da6c28aaSamw #include <limits.h>
46da6c28aaSamw #include <libscf.h>
47b56bf881SAntonello Cruz #include <libscf_priv.h>
48da6c28aaSamw #include <strings.h>
49da6c28aaSamw #include "libshare_smb.h"
50da6c28aaSamw #include <rpcsvc/daemon_utils.h>
513db3f65cSamw #include <smbsrv/smb_share.h>
52da6c28aaSamw #include <smbsrv/smbinfo.h>
53da6c28aaSamw #include <smbsrv/libsmb.h>
548d7e4166Sjose borrego #include <libdlpi.h>
558d7e4166Sjose borrego 
568d7e4166Sjose borrego #define	SMB_CSC_BUFSZ		64
57da6c28aaSamw 
5829bd2886SAlan Wright #define	SMB_VALID_SUB_CHRS	"UDhMLmIiSPu"	/* substitution characters */
5929bd2886SAlan Wright 
60da6c28aaSamw /* internal functions */
61da6c28aaSamw static int smb_share_init(void);
62da6c28aaSamw static void smb_share_fini(void);
63da6c28aaSamw static int smb_enable_share(sa_share_t);
64da6c28aaSamw static int smb_share_changed(sa_share_t);
65da6c28aaSamw static int smb_resource_changed(sa_resource_t);
66da6c28aaSamw static int smb_rename_resource(sa_handle_t, sa_resource_t, char *);
67da6c28aaSamw static int smb_disable_share(sa_share_t share, char *);
68687915e9Sdougm static int smb_validate_property(sa_handle_t, sa_property_t, sa_optionset_t);
69da6c28aaSamw static int smb_set_proto_prop(sa_property_t);
70da6c28aaSamw static sa_protocol_properties_t smb_get_proto_set(void);
71da6c28aaSamw static char *smb_get_status(void);
72da6c28aaSamw static int smb_parse_optstring(sa_group_t, char *);
73da6c28aaSamw static char *smb_format_options(sa_group_t, int);
74da6c28aaSamw 
75da6c28aaSamw static int smb_enable_service(void);
76da6c28aaSamw 
77da6c28aaSamw static int range_check_validator(int, char *);
78da6c28aaSamw static int range_check_validator_zero_ok(int, char *);
79da6c28aaSamw static int string_length_check_validator(int, char *);
8086d7016bSGordon Ross static int print_enable_validator(int, char *);
81da6c28aaSamw static int true_false_validator(int, char *);
8229bd2886SAlan Wright static int ipv4_validator(int, char *);
8396a62adaSjoyce mcintosh static int hostname_validator(int, char *);
84da6c28aaSamw static int path_validator(int, char *);
8529bd2886SAlan Wright static int cmd_validator(int, char *);
8629bd2886SAlan Wright static int disposition_validator(int, char *);
873e2c0c09SMatt Barden static int protocol_validator(int, char *);
881160dcf7SMatt Barden static int require_validator(int, char *);
89da6c28aaSamw 
90da6c28aaSamw static int smb_enable_resource(sa_resource_t);
91da6c28aaSamw static int smb_disable_resource(sa_resource_t);
92da6c28aaSamw static uint64_t smb_share_features(void);
93da6c28aaSamw static int smb_list_transient(sa_handle_t);
94dc20a302Sas 
95c8ec8eeaSjose borrego static int smb_build_shareinfo(sa_share_t, sa_resource_t, smb_share_t *);
968d7e4166Sjose borrego static void smb_csc_option(const char *, smb_share_t *);
9789dc44ceSjose borrego static char *smb_csc_name(const smb_share_t *);
98c8ec8eeaSjose borrego static sa_group_t smb_get_defaultgrp(sa_handle_t);
998d7e4166Sjose borrego static int interface_validator(int, char *);
10096a62adaSjoyce mcintosh static int smb_update_optionset_props(sa_handle_t, sa_resource_t, nvlist_t *);
101c8ec8eeaSjose borrego 
102ca5fb90aSGordon Ross static boolean_t smb_saprop_getbool(sa_optionset_t, char *, boolean_t);
1039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_saprop_getstr(sa_optionset_t, char *, char *, size_t);
1049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
10589dc44ceSjose borrego static struct {
10689dc44ceSjose borrego 	char *value;
10789dc44ceSjose borrego 	uint32_t flag;
10889dc44ceSjose borrego } cscopt[] = {
10989dc44ceSjose borrego 	{ "disabled",	SMB_SHRF_CSC_DISABLED },
11089dc44ceSjose borrego 	{ "manual",	SMB_SHRF_CSC_MANUAL },
11189dc44ceSjose borrego 	{ "auto",	SMB_SHRF_CSC_AUTO },
11289dc44ceSjose borrego 	{ "vdo",	SMB_SHRF_CSC_VDO }
11389dc44ceSjose borrego };
11489dc44ceSjose borrego 
115da6c28aaSamw /* size of basic format allocation */
116da6c28aaSamw #define	OPT_CHUNK	1024
117da6c28aaSamw 
118dc20a302Sas /* size of string for types - big enough to hold "dependency" */
119dc20a302Sas #define	SCFTYPE_LEN	32
120dc20a302Sas 
121da6c28aaSamw /*
122da6c28aaSamw  * Indexes of entries in smb_proto_options table.
123da6c28aaSamw  * Changes to smb_proto_options table may require
124da6c28aaSamw  * an update to these values.
125da6c28aaSamw  */
126da6c28aaSamw #define	PROTO_OPT_WINS1			6
127da6c28aaSamw #define	PROTO_OPT_WINS_EXCLUDE		8
128da6c28aaSamw 
1298d7e4166Sjose borrego typedef struct smb_hostifs_walker {
1308d7e4166Sjose borrego 	const char	*hiw_ifname;
1318d7e4166Sjose borrego 	boolean_t	hiw_matchfound;
1328d7e4166Sjose borrego } smb_hostifs_walker_t;
1338d7e4166Sjose borrego 
134da6c28aaSamw 
135da6c28aaSamw /*
136da6c28aaSamw  * ops vector that provides the protocol specific info and operations
137da6c28aaSamw  * for share management.
138da6c28aaSamw  */
139da6c28aaSamw 
140da6c28aaSamw struct sa_plugin_ops sa_plugin_ops = {
141da6c28aaSamw 	SA_PLUGIN_VERSION,
142da6c28aaSamw 	SMB_PROTOCOL_NAME,
143da6c28aaSamw 	smb_share_init,
144da6c28aaSamw 	smb_share_fini,
145da6c28aaSamw 	smb_enable_share,
146da6c28aaSamw 	smb_disable_share,
147da6c28aaSamw 	smb_validate_property,
1484bff34e3Sthurlow 	NULL,	/* valid_space */
1494bff34e3Sthurlow 	NULL,	/* security_prop */
150da6c28aaSamw 	smb_parse_optstring,
151da6c28aaSamw 	smb_format_options,
152da6c28aaSamw 	smb_set_proto_prop,
153da6c28aaSamw 	smb_get_proto_set,
154da6c28aaSamw 	smb_get_status,
1554bff34e3Sthurlow 	NULL,	/* space_alias */
1564bff34e3Sthurlow 	NULL,	/* update_legacy */
1574bff34e3Sthurlow 	NULL,	/* delete_legacy */
158da6c28aaSamw 	smb_share_changed,
159da6c28aaSamw 	smb_enable_resource,
160da6c28aaSamw 	smb_disable_resource,
161da6c28aaSamw 	smb_share_features,
162da6c28aaSamw 	smb_list_transient,
163da6c28aaSamw 	smb_resource_changed,
164da6c28aaSamw 	smb_rename_resource,
1654bff34e3Sthurlow 	NULL,	/* run_command */
1664bff34e3Sthurlow 	NULL,	/* command_help */
1674bff34e3Sthurlow 	NULL	/* delete_proto_section */
168da6c28aaSamw };
169da6c28aaSamw 
170da6c28aaSamw struct option_defs optdefs[] = {
1718d7e4166Sjose borrego 	{ SHOPT_AD_CONTAINER,	OPT_TYPE_STRING },
172e3f2c991SKeyur Desai 	{ SHOPT_ABE,		OPT_TYPE_BOOLEAN },
1738d7e4166Sjose borrego 	{ SHOPT_NAME,		OPT_TYPE_NAME },
1748d7e4166Sjose borrego 	{ SHOPT_RO,		OPT_TYPE_ACCLIST },
1758d7e4166Sjose borrego 	{ SHOPT_RW,		OPT_TYPE_ACCLIST },
1768d7e4166Sjose borrego 	{ SHOPT_NONE,		OPT_TYPE_ACCLIST },
1778b2cc8acSafshin salek ardakani - Sun Microsystems - Irvine United States 	{ SHOPT_CATIA,		OPT_TYPE_BOOLEAN },
1788d7e4166Sjose borrego 	{ SHOPT_CSC,		OPT_TYPE_CSC },
17929bd2886SAlan Wright 	{ SHOPT_GUEST,		OPT_TYPE_BOOLEAN },
1809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	{ SHOPT_DFSROOT,	OPT_TYPE_BOOLEAN },
181148c5f43SAlan Wright 	{ SHOPT_DESCRIPTION,	OPT_TYPE_STRING },
1828d94f651SGordon Ross 	{ SHOPT_CA,		OPT_TYPE_BOOLEAN },
18394047d49SGordon Ross 	{ SHOPT_FSO,		OPT_TYPE_BOOLEAN },
184ca5fb90aSGordon Ross 	{ SHOPT_QUOTAS,		OPT_TYPE_BOOLEAN },
1851160dcf7SMatt Barden 	{ SHOPT_ENCRYPT,	OPT_TYPE_STRING },
186ff168298SToomas Soome 	{ NULL, 0 }
187da6c28aaSamw };
188da6c28aaSamw 
189