libshare_smb.c revision f4427914317470f516ca69daaed90f7efb3d76dc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
*/
/*
* SMB specific functions
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <zone.h>
#include <errno.h>
#include <locale.h>
#include <fcntl.h>
#include <syslog.h>
#include "libshare.h"
#include "libshare_impl.h"
#include <pwd.h>
#include <limits.h>
#include <libscf.h>
#include <libscf_priv.h>
#include <strings.h>
#include "libshare_smb.h"
#include <rpcsvc/daemon_utils.h>
#include <smbsrv/smb_share.h>
#include <libdlpi.h>
#define SMB_CSC_BUFSZ 64
/* internal functions */
static int smb_share_init(void);
static void smb_share_fini(void);
static int smb_enable_share(sa_share_t);
static int smb_share_changed(sa_share_t);
static int smb_resource_changed(sa_resource_t);
static int smb_set_proto_prop(sa_property_t);
static sa_protocol_properties_t smb_get_proto_set(void);
static char *smb_get_status(void);
static int smb_parse_optstring(sa_group_t, char *);
static char *smb_format_options(sa_group_t, int);
static int smb_enable_service(void);
static int range_check_validator(int, char *);
static int range_check_validator_zero_ok(int, char *);
static int string_length_check_validator(int, char *);
static int print_enable_validator(int, char *);
static int true_false_validator(int, char *);
static int ipv4_validator(int, char *);
static int hostname_validator(int, char *);
static int path_validator(int, char *);
static int cmd_validator(int, char *);
static int disposition_validator(int, char *);
static int smb_enable_resource(sa_resource_t);
static int smb_disable_resource(sa_resource_t);
static uint64_t smb_share_features(void);
static int smb_list_transient(sa_handle_t);
static void smb_csc_option(const char *, smb_share_t *);
static char *smb_csc_name(const smb_share_t *);
static int interface_validator(int, char *);
static struct {
char *value;
} cscopt[] = {
{ "disabled", SMB_SHRF_CSC_DISABLED },
{ "manual", SMB_SHRF_CSC_MANUAL },
{ "auto", SMB_SHRF_CSC_AUTO },
{ "vdo", SMB_SHRF_CSC_VDO }
};
/* size of basic format allocation */
#define OPT_CHUNK 1024
/* size of string for types - big enough to hold "dependency" */
#define SCFTYPE_LEN 32
/*
* Indexes of entries in smb_proto_options table.
* Changes to smb_proto_options table may require
* an update to these values.
*/
#define PROTO_OPT_WINS1 6
#define PROTO_OPT_WINS_EXCLUDE 8
typedef struct smb_hostifs_walker {
const char *hiw_ifname;
/*
* ops vector that provides the protocol specific info and operations
* for share management.
*/
struct sa_plugin_ops sa_plugin_ops = {
NULL, /* valid_space */
NULL, /* security_prop */
NULL, /* space_alias */
NULL, /* update_legacy */
NULL, /* delete_legacy */
NULL, /* run_command */
NULL, /* command_help */
NULL /* delete_proto_section */
};
struct option_defs optdefs[] = {
{ SHOPT_ABE, OPT_TYPE_BOOLEAN },
{ SHOPT_NAME, OPT_TYPE_NAME },
{ SHOPT_RO, OPT_TYPE_ACCLIST },
{ SHOPT_RW, OPT_TYPE_ACCLIST },
{ SHOPT_NONE, OPT_TYPE_ACCLIST },
{ SHOPT_CATIA, OPT_TYPE_BOOLEAN },
{ SHOPT_CSC, OPT_TYPE_CSC },
{ SHOPT_GUEST, OPT_TYPE_BOOLEAN },
};
/*
* findopt(name)
*
* Lookup option "name" in the option table and return the table
* index.
*/
static int
{
int i;
return (i);
}
}
return (-1);
}
/*
* is_a_number(number)
*
* is the string a number in one of the forms we want to use?
*/
static boolean_t
is_a_number(char *number)
{
return (B_FALSE);
number += 2;
} else if (*number == '-') {
number++;
}
number++;
}
return (isnum);
}
/*
* check ro vs rw values. Over time this may get beefed up.
* for now it just does simple checks.
*/
static int
{
return (ret);
}
/*
* validresource(name)
*
* Check that name only has valid characters in it. The current valid
* set are the printable characters but not including:
* " / \ [ ] : | < > + ; , ? * = \t
* Note that space is included and there is a maximum length.
*/
static boolean_t
validresource(const char *name)
{
const char *cp;
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
}
return (B_FALSE);
return (B_TRUE);
}
/*
* Check that the client-side caching (CSC) option value is valid.
*/
static boolean_t
{
int i;
return (B_TRUE);
}
return (B_FALSE);
}
/*
* smb_isonline()
*
* Determine if the SMF service instance is in the online state or
* not. A number of operations depend on this state.
*/
static boolean_t
smb_isonline(void)
{
char *str;
}
return (ret);
}
/*
* smb_isdisabled()
*
* Determine if the SMF service instance is in the disabled state or
* not. A number of operations depend on this state.
*/
static boolean_t
smb_isdisabled(void)
{
char *str;
}
return (ret);
}
/*
* smb_isautoenable()
*
* Determine if the SMF service instance auto_enabled set or not. A
* number of operations depend on this state. The property not being
* set or being set to true means autoenable. Only being set to false
* is not autoenabled.
*/
static boolean_t
smb_isautoenable(void)
{
"application", "auto_enable");
}
return (ret);
}
/*
* smb_ismaint()
*
* Determine if the SMF service instance is in the disabled state or
* not. A number of operations depend on this state.
*/
static boolean_t
smb_ismaint(void)
{
char *str;
}
return (ret);
}
/*
* smb_enable_share tells the implementation that it is to enable the share.
* This entails converting the path and options into the appropriate ioctl
* calls. It is assumed that all error checking of paths, etc. were
* done earlier.
*/
static int
{
char *path;
/*
* We only start in the global zone and only run if we aren't
* running Trusted Extensions.
*/
if (getzoneid() != GLOBAL_ZONEID) {
"SMB: service not supported in local zone\n"));
return (SA_NOT_SUPPORTED);
}
if (is_system_labeled()) {
"SMB: service not supported with Trusted Extensions\n"));
return (SA_NOT_SUPPORTED);
}
/* get the path since it is important in several places */
return (SA_NO_SUCH_PATH);
/*
* If administratively disabled, don't try to start anything.
*/
online = smb_isonline();
goto done;
if (iszfs) {
if (!online) {
"SMB: Cannot share remove "
"file system: %s\n"), path);
"SMB: Service needs to be enabled "
"by a privileged user\n"));
}
if (err) {
return (err);
}
}
}
err = smb_enable_service();
"SMB: Unable to enable service\n"));
} else {
}
}
/*
* Don't bother trying to start shares if the service isn't
* running.
*/
if (!online)
goto done;
/* Each share can have multiple resources */
return (err);
}
if (!iszfs) {
} else {
&si, ZFS_SHARE_SMB);
err = -1;
}
sa_emptyshare(&sh);
}
}
if (!iszfs)
done:
}
/*
* This is the share for CIFS all shares have resource names.
* Enable tells the smb server to update its hash. If it fails
* because smb server is down, we just ignore as smb server loads
* the resources from sharemanager at startup.
*/
static int
{
int err;
return (SA_NO_SUCH_PATH);
/*
* If administratively disabled, don't try to start anything.
*/
isonline = smb_isonline();
return (SA_OK);
if (!isonline) {
(void) smb_enable_service();
if (!smb_isonline())
return (SA_OK);
}
return (ret);
/*
* Attempt to add the share. Any error that occurs if it was
* online is an error but don't count NERR_DuplicateName if
* service up will enable the share that was just added prior
* to the attempt to enable.
*/
else
return (SA_NOT_SHARED);
return (SA_OK);
}
/*
* Remove it from smb server hash.
*/
static int
{
char *rname;
return (SA_NO_SUCH_RESOURCE);
if (smb_isonline()) {
if (res != NERR_Success &&
res != NERR_NetNameNotFound) {
return (SA_CONFIG_ERR);
}
}
}
}
/*
* Shares will be picked up when loaded.
*/
return (SA_OK);
}
/*
* smb_share_changed(sa_share_t share)
*
* The specified share has changed.
*/
static int
{
char *path;
if (!smb_isonline())
return (SA_OK);
/* get the path since it is important in several places */
return (SA_NO_SUCH_PATH);
(void) smb_resource_changed(resource);
return (SA_OK);
}
/*
* smb_resource_changed(sa_resource_t resource)
*
* The specified resource has changed.
*/
static int
{
if (!smb_isonline())
return (SA_OK);
return (SA_CONFIG_ERR);
return (res);
if (res != NERR_Success)
return (SA_CONFIG_ERR);
return (smb_enable_service());
}
/*
* smb_disable_share(sa_share_t share, char *path)
*
* Unshare the specified share. Note that "path" is the same
* path as what is in the "share" object. It is passed in to avoid an
* additional lookup. A missing "path" value makes this a no-op
* function.
*/
static int
{
char *rname;
return (ret);
/*
* If the share is in a ZFS group we need to handle it
* differently. Just being on a ZFS file system isn't
* enough since we may be in a legacy share case.
*/
if (!smb_isonline())
goto done;
continue;
}
if (!iszfs) {
switch (err) {
case NERR_NetNameNotFound:
case NERR_Success:
break;
default:
err = SA_CONFIG_ERR;
break;
}
} else {
switch (err) {
case EINVAL:
case ENOENT:
break;
default:
/*
* If we are no longer the first case,
* we don't care about the sa_share_zfs
* err if it is -1. This works around
* a problem in sharefs and should be
* removed when sharefs supports
* multiple entries per path.
*/
if (!first)
else
err = SA_SYSTEM_ERR;
break;
}
}
sa_emptyshare(&sh);
}
}
done:
if (!iszfs) {
else
ret = SA_SYSTEM_ERR;
}
return (ret);
}
/*
* smb_validate_property(handle, property, parent)
*
* Check that the property has a legitimate value for its type.
* Handle isn't currently used but may need to be in the future.
*/
/*ARGSUSED*/
static int
{
char *propname;
int optindex;
char *value;
char *other;
/* need to validate value range here as well */
}
return (ret);
}
/* first basic type checking */
case OPT_TYPE_NUMBER:
/* check that the value is all digits */
if (!is_a_number(value))
ret = SA_BAD_VALUE;
break;
case OPT_TYPE_BOOLEAN:
break;
case OPT_TYPE_NAME:
/*
* Make sure no invalid characters
*/
if (!validresource(value))
ret = SA_BAD_VALUE;
break;
case OPT_TYPE_STRING:
/* whatever is here should be ok */
break;
case OPT_TYPE_CSC:
ret = SA_BAD_VALUE;
break;
case OPT_TYPE_ACCLIST: {
char *ovalue;
/*
* access list handling. Should eventually
* validate that all the values make sense.
* Also, ro and rw may have cross value
* conflicts.
*/
break;
else
break;
/* compare rw(ro) with ro(rw) */
break;
/*
* only potential
* confusion if other
* exists
*/
}
break;
}
default:
break;
}
}
/* do the property specific check */
return (ret);
}
/*
* Protocol management functions
*
* properties defined in the default files are defined in
* proto_option_defs for parsing and validation.
*/
struct smb_proto_option_defs {
int smb_index;
int (*validator)(int, char *);
} smb_proto_options[] = {
{ SMB_CI_SYS_CMNT, 0, MAX_VALUE_BUFLEN,
{ SMB_CI_NBSCOPE, 0, MAX_VALUE_BUFLEN,
{ SMB_CI_WINS_SRV1, 0, MAX_VALUE_BUFLEN,
{ SMB_CI_WINS_SRV2, 0, MAX_VALUE_BUFLEN,
{ SMB_CI_WINS_EXCL, 0, MAX_VALUE_BUFLEN,
{ SMB_CI_SIGNING_ENABLE, 0, 0, true_false_validator,
{ SMB_CI_SIGNING_REQD, 0, 0, true_false_validator,
{ SMB_CI_RESTRICT_ANON, 0, 0, true_false_validator,
{ SMB_CI_ADS_SITE, 0, MAX_VALUE_BUFLEN,
{ SMB_CI_DYNDNS_ENABLE, 0, 0, true_false_validator, 0 },
{ SMB_CI_IPV6_ENABLE, 0, 0, true_false_validator,
{ SMB_CI_PRINT_ENABLE, 0, 0, print_enable_validator,
{ SMB_CI_TRAVERSE_MOUNTS, 0, 0, true_false_validator,
};
#define SMB_OPT_NUM \
(sizeof (smb_proto_options) / sizeof (smb_proto_options[0]))
/*
* Check the range of value as int range.
*/
static int
{
if (!is_a_number(value)) {
ret = SA_BAD_VALUE;
} else {
int val;
ret = SA_BAD_VALUE;
}
return (ret);
}
/*
* Check the range of value as int range.
*/
static int
{
if (!is_a_number(value)) {
ret = SA_BAD_VALUE;
} else {
int val;
if (val == 0)
else {
ret = SA_BAD_VALUE;
}
}
return (ret);
}
/*
* Check the length of the string
*/
static int
{
return (SA_BAD_VALUE);
ret = SA_BAD_VALUE;
return (ret);
}
/*
*/
/*ARGSUSED*/
static int
{
return (SA_BAD_VALUE);
return (SA_OK);
return (SA_BAD_VALUE);
}
/*
* If printing support is compiled in, this is the same as:
* true_false_validator. Otherwise, only allow false.
*/
/*ARGSUSED*/
static int
{
return (SA_BAD_VALUE);
#ifdef HAVE_CUPS
return (SA_OK);
#endif
return (SA_OK);
return (SA_BAD_VALUE);
}
/*
* Check IP v4 address.
*/
/*ARGSUSED*/
static int
{
char sbytes[16];
return (SA_OK);
return (SA_OK);
return (SA_BAD_VALUE);
return (SA_OK);
}
/*
* Check that the specified name is an IP address (v4 or v6) or a hostname.
* Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
* and dots. The first and last character of a label must be alphanumeric.
* Interior characters may be alphanumeric or hypens.
*
* Domain names should not contain underscores but we allow them because
* Windows names are often in non-compliance with this rule.
*/
/*ARGSUSED*/
static int
{
char sbytes[INET6_ADDRSTRLEN];
char *p;
char label_terminator;
int len;
return (SA_OK);
return (SA_OK);
return (SA_OK);
return (SA_OK);
if (len >= MAXHOSTNAMELEN)
return (SA_BAD_VALUE);
return (SA_BAD_VALUE);
for (p = value; *p != '\0'; ++p) {
if (new_label) {
if (!isalnum(*p))
return (SA_BAD_VALUE);
label_terminator = *p;
continue;
}
if (*p == '.') {
if (!isalnum(label_terminator))
return (SA_BAD_VALUE);
label_terminator = *p;
continue;
}
label_terminator = *p;
continue;
return (SA_BAD_VALUE);
}
if (!isalnum(label_terminator))
return (SA_BAD_VALUE);
return (SA_OK);
}
/*
* Call back function for dlpi_walk.
* Returns TRUE if interface name exists on the host.
*/
static boolean_t
{
return (iterp->hiw_matchfound);
}
/*
* Checks to see if the input interface exists on the host.
* Returns B_TRUE if the match is found, B_FALSE otherwise.
*/
static boolean_t
smb_validate_interface(const char *ifname)
{
return (B_FALSE);
return (iter.hiw_matchfound);
}
/*
* Check valid interfaces. Interface names value can be NULL or empty.
* Returns SA_BAD_VALUE if interface cannot be found on the host.
*/
/*ARGSUSED*/
static int
{
char buf[16];
return (ret);
return (SA_BAD_VALUE);
return (SA_NO_MEMORY);
tmp = p;
if (*ifname == '\0') {
ret = SA_BAD_VALUE;
break;
}
if (!smb_validate_interface(ifname)) {
ret = SA_BAD_VALUE;
break;
}
}
}
free(p);
return (ret);
}
/*
* Check path
*/
/*ARGSUSED*/
static int
{
return (SA_BAD_VALUE);
if (fd < 0)
return (SA_BAD_VALUE);
if (status < 0)
return (SA_BAD_VALUE);
return (SA_OK);
return (SA_BAD_VALUE);
}
/*
* the protoset holds the defined options so we don't have to read
* them multiple times
*/
static sa_protocol_properties_t protoset;
static int
findprotoopt(char *name)
{
int i;
char *sc_name;
for (i = 0; i < SMB_OPT_NUM; i++) {
return (i);
}
return (-1);
}
/*
* smb_load_proto_properties()
*
* read the smb config values from SMF.
*/
static int
{
char value[MAX_VALUE_BUFLEN];
char *name;
int index;
int rc;
return (SA_NO_MEMORY);
if (rc != SMBD_SMF_OK)
continue;
else
ret = SA_NO_MEMORY;
}
return (ret);
}
/*
* smb_share_init()
*
* Initialize the smb plugin.
*/
static int
smb_share_init(void)
{
return (SA_SYSTEM_ERR);
return (smb_load_proto_properties());
}
/*
* smb_share_fini()
*
*/
static void
smb_share_fini(void)
{
}
/*
* smb_get_proto_set()
*
* Return an optionset with all the protocol specific properties in
* it.
*/
static sa_protocol_properties_t
smb_get_proto_set(void)
{
return (protoset);
}
/*
* smb_enable_dependencies()
*
* SMBD_DEFAULT_INSTANCE_FMRI may have some dependencies that aren't
* enabled. This will attempt to enable all of them.
*/
static void
smb_enable_dependencies(const char *fmri)
{
char type[SCFTYPE_LEN];
char *dependency;
char *servname;
int maxlen;
/*
* Get all required handles and storage.
*/
return;
if (scf_handle_bind(handle) != 0) {
return;
}
maxlen = MAXPATHLEN;
goto done;
/*
* We passed in the FMRI for the default instance but for
* some things we need the simple form so construct it. Since
* we reuse the storage that dependency points to, we need to
* use the servname early.
*/
goto done;
*servname = '\0';
/*
* Setup to iterate over the service property groups, only
* looking at those that are "dependency" types. The "entity"
* property will have the FMRI of the service we are dependent
* on.
*/
goto done;
goto done;
goto done;
char *services[2];
/*
* Have a property group for the service. See if it is
* a dependency pg and only do operations on those.
*/
continue;
continue;
/*
* Have a dependency. Attempt to enable it.
*/
continue;
continue;
services[0] = dependency;
}
}
done:
if (dependency != NULL)
(void) scf_handle_unbind(handle);
}
/*
* How long to wait for service to come online
*/
#define WAIT_FOR_SERVICE 15
/*
* smb_enable_service()
*
*/
static int
smb_enable_service(void)
{
int i;
if (!smb_isonline()) {
/*
* Attempt to start the idmap, and other dependent
* services, first. If it fails, the SMB service will
* ultimately fail so we use that as the error. If we
* don't try to enable idmap, smb won't start the
* first time unless the admin has done it
* manually. The service could be administratively
* disabled so we won't always get started.
*/
/* Wait for service to come online */
for (i = 0; i < WAIT_FOR_SERVICE; i++) {
if (smb_isonline()) {
break;
} else if (smb_ismaint()) {
/* maintenance requires help */
ret = SA_SYSTEM_ERR;
break;
} else {
/* try another time */
(void) sleep(1);
}
}
}
return (ret);
}
/*
* smb_validate_proto_prop(index, name, value)
*
* Verify that the property specified by name can take the new
* value. This is a sanity check to prevent bad values getting into
* the default files.
*/
static int
{
return (SA_BAD_VALUE);
return (SA_OK);
return (SA_OK);
return (SA_BAD_VALUE);
}
/*
* smb_set_proto_prop(prop)
*
* check that prop is valid.
*/
/*ARGSUSED*/
static int
{
char *name;
char *value;
int index = -1;
struct smb_proto_option_defs *opt;
if (index >= 0) {
/* should test for valid value */
/* Save to SMF */
/*
* Specialized refresh mechanisms can
* be flagged in the proto_options and
* processed here.
*/
(void) smf_refresh_instance(
(void) smf_restart_instance(
}
}
}
return (ret);
}
/*
* smb_get_status()
*
* What is the current status of the smbd? We use the SMF state here.
* Caller must free the returned value.
*/
static char *
smb_get_status(void)
{
return (smf_get_state(SMBD_DEFAULT_INSTANCE_FMRI));
}
/*
* This protocol plugin require resource names
*/
static uint64_t
smb_share_features(void)
{
return (SA_FEATURE_RESOURCE | SA_FEATURE_ALLOWSUBDIRS |
}
/*
* This should be used to convert smb_share_t to sa_resource_t
* supplied to sharemgr to display.
*/
static int
{
int err;
char *opt;
return (SA_INVALID_NAME);
return (SA_NO_SUCH_GROUP);
return (SA_NO_SUCH_PATH);
}
}
/*
* Now handle the resource. Make sure that the resource is
* transient and added to the share.
*/
return (SA_NO_SUCH_RESOURCE);
}
si->shr_container);
return (SA_NO_MEMORY);
}
if (err) {
return (SA_CONFIG_ERR);
}
return (err);
}
/*
* Return smb transient shares.
*/
static int
{
int i, offset;
int res;
if (smb_share_count() <= 0)
return (SA_OK);
offset = 0;
break;
return (res);
}
}
return (SA_OK);
}
/*
* fix_resource_name(share, name, prefix)
*
* Construct a name where the ZFS dataset has the prefix replaced with "name".
*/
static char *
{
char *dataset;
}
/*
* smb_parse_optstring(group, options)
*
* parse a compact option string into individual options. This allows
* ZFS sharesmb and sharemgr "share" command to work. group can be a
* group, a share or a resource.
*/
static int
{
char *dup;
char *base;
char *lasts;
char *token;
int iszfs = 0;
int persist = 0;
int need_optionset = 0;
/*
* In order to not attempt to change ZFS properties unless
* absolutely necessary, we never do it in the legacy parsing
* so we need to keep track of this.
*/
if (sa_is_share(group)) {
char *zfs;
iszfs = 1;
}
}
} else {
/*
* If a ZFS group, then we need to see if a resource
* name is being set. If so, bail with
* SA_PROP_SHARE_ONLY, so we come back in with a share
* instead of a group.
*/
if (iszfs ||
return (SA_PROP_SHARE_ONLY);
}
}
/* do we have an existing optionset? */
/* didn't find existing optionset so create one */
return (SA_NO_MEMORY);
} else {
/*
* If an optionset already exists, we've come through
* twice so ignore the second time.
*/
return (ret);
}
/* We need a copy of options for the next part. */
return (SA_NO_MEMORY);
/*
* SMB properties are straightforward and are strings,
* integers or booleans. Properties are separated by
* commas. It will be necessary to parse quotes due to some
* strings not having a restricted characters set.
*
* Note that names will create a resource. For now, if there
* is a set of properties "before" the first name="", those
* properties will be placed on the group.
*/
char *value;
/*
* All SMB properties have values so there
* MUST be an '=' character. If it doesn't,
* it is a syntax error.
*/
*value++ = '\0';
} else {
ret = SA_SYNTAX_ERR;
break;
}
/*
* We may need to handle a "name" property
* that is a ZFS imposed resource name. Each
* name would trigger getting a new "resource"
* to put properties on. For now, assume no
* "name" property for special handling.
*/
char *prefix;
/*
* We have a name, so now work on the
* resource level. We have a "share"
* in "group" due to the caller having
* added it. If we are called with a
* at the beginning of this function
* will bail out the parse if there is a
* "name" but no share.
*/
if (!iszfs) {
ret = SA_SYNTAX_ERR;
break;
}
/*
* Make sure the parent group has the
* "prefix" property since we will
* need to use this for constructing
* inherited name= values.
*/
"name");
(void) sa_set_group_attr(parent,
"prefix", prefix);
}
}
} else {
ret = SA_NO_MEMORY;
}
/* A resource level optionset is needed */
need_optionset = 1;
ret = SA_NO_MEMORY;
break;
}
continue;
}
(void) sa_set_share_description(
else
(void) sa_set_resource_description(
continue;
}
if (need_optionset) {
"smb");
need_optionset = 0;
}
ret = SA_NO_MEMORY;
else
break;
if (!iszfs)
}
}
return (ret);
}
/*
* smb_sprint_option(rbuff, rbuffsize, incr, prop, sep)
*
* provides a mechanism to format SMB properties into legacy output
* format. If the buffer would overflow, it is reallocated and grown
* as appropriate. Special cases of converting internal form of values
* to those used by "share" are done. this function does one property
* at a time.
*/
static void
{
char *name;
char *value;
int curlen;
else
curlen = 0;
int len;
/*
* A future RFE would be to replace this with more
* generic code and to possibly handle more types.
*
* For now, everything else is treated as a string. If
* we get any properties that aren't exactly
*/
/* need more room */
/* realloc failed so free everything */
goto err;
}
}
goto err;
}
err:
}
/*
* smb_format_resource_options(resource, hier)
*
* format all the options on the group into a flattened option
* string. If hier is non-zero, walk up the tree to get inherited
* options.
*/
static char *
{
int sep = 0;
char *buff;
return (NULL);
buff[0] = '\0';
/*
* We may have a an optionset relative to this item. format
* these if we find them and then add any security definitions.
*/
/*
* do the default set first but skip any option that is also
* in the protocol specific optionset.
*/
/*
* use this one since we skipped any
* of these that were also in
* optdefault
*/
/*
* buff could become NULL if there
* isn't enough memory for
* smb_sprint_option to realloc()
* as necessary. We can't really
* do anything about it at this
* point so we return NULL. The
* caller should handle the
* failure.
*/
options);
return (buff);
}
sep = 1;
}
}
return (buff);
}
/*
* smb_rename_resource(resource, newname)
*
* Change the current exported name of the resource to newname.
*/
/*ARGSUSED*/
int
{
int err;
char *oldname;
if (!smb_isonline())
return (SA_OK);
return (SA_NO_SUCH_RESOURCE);
/* improve error values somewhat */
switch (err) {
case NERR_Success:
break;
case NERR_InternalError:
ret = SA_SYSTEM_ERR;
break;
case NERR_DuplicateShare:
break;
default:
ret = SA_CONFIG_ERR;
break;
}
return (ret);
}
static int
{
char *path;
char *rname;
char csc_value[SMB_CSC_BUFSZ];
return (SA_NO_SUCH_PATH);
return (SA_NO_SUCH_RESOURCE);
}
}
return (SA_OK);
sizeof (si->shr_container));
sizeof (si->shr_access_ro)))
sizeof (si->shr_access_rw)))
sizeof (si->shr_access_none)))
return (SA_OK);
}
/*
* Map a client-side caching (CSC) option to the appropriate share
* flag. Only one option is allowed; an error will be logged if
* multiple options have been specified. We don't need to do anything
* about multiple values here because the SRVSVC will not recognize
* a value containing multiple flags and will return the default value.
*
* If the option value is not recognized, it will be ignored: invalid
* values will typically be caught and rejected by sharemgr.
*/
static void
{
char buf[SMB_CSC_BUFSZ];
int i;
break;
}
}
case 0:
case SMB_SHRF_CSC_DISABLED:
case SMB_SHRF_CSC_MANUAL:
case SMB_SHRF_CSC_AUTO:
case SMB_SHRF_CSC_VDO:
break;
default:
buf[0] = '\0';
}
}
break;
}
}
/*
* Return the option name for the first CSC flag (there should be only
* one) encountered in the share flags.
*/
static char *
{
int i;
}
return (NULL);
}
/*
* smb_get_defaultgrp
*
* If default group for CIFS shares (i.e. "smb") exists
* then it will return the group handle, otherwise it will
* create the group and return the handle.
*
* All the shares created by CIFS clients (this is only possible
* via RPC) will be added to "smb" groups.
*/
static sa_group_t
{
int err;
return (group);
return (NULL);
(void) sa_remove_group(group);
}
return (group);
}
/*
* Checks to see if the command args are the supported substitution specifier.
* i.e. <cmd> %U %S
*/
static int
{
char cmd[MAXPATHLEN];
char *ptr, *v;
return (SA_BAD_VALUE);
if (*value == '\0')
return (SA_OK);
do {
break;
if (*v != '\0') {
if (skip_cmdname) {
continue;
}
return (SA_BAD_VALUE);
return (SA_BAD_VALUE);
}
} while (v != NULL);
/*
* If skip_cmdname is still true then the string contains
* only spaces. Don't allow such a string.
*/
if (skip_cmdname)
return (SA_BAD_VALUE);
return (SA_OK);
}
/*ARGSUSED*/
static int
{
return (SA_BAD_VALUE);
if (*value == '\0')
return (SA_OK);
return (SA_OK);
return (SA_BAD_VALUE);
}
/*
* Updates the optionset properties of the share resource.
* The properties are given as a list of name-value pair.
* The name argument should be the optionset property name and the value
* should be a valid value for the specified property.
*
* When calling this function for permanent shares, the caller must also
* call sa_commit_properties() to commit the changes to SMF.
*/
static int
{
return (SA_CONFIG_ERR);
}
err = SA_CONFIG_ERR;
break;
}
(void) sa_remove_property(prop);
break;
}
}
break;
} else {
break;
}
}
return (err);
}
static boolean_t
{
char *val;
}
return (propval);
}
static boolean_t
{
char *val;
return (B_TRUE);
}
return (B_FALSE);
}