/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012 Milan Jurik. All rights reserved.
*/
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
#include <utmpx.h>
#include <pwd.h>
#include <auth_attr.h>
#include <secdb.h>
#include <errno.h>
#include <libshare.h>
#include "sharemgr.h"
#include <libscf.h>
#include <libintl.h>
#include <assert.h>
#include <iconv.h>
#include <langinfo.h>
#include <dirent.h>
static char *sa_get_usage(sa_usage_t);
/*
* Implementation of the common sub-commands supported by sharemgr.
* A number of helper functions are also included.
*/
/*
* has_protocol(group, proto)
* If the group has an optionset with the specified protocol,
* return true (1) otherwise false (0).
*/
static int
{
int result = 0;
result++;
}
return (result);
}
/*
* 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 int
{
const char *cp;
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
}
return (B_FALSE);
return (B_TRUE);
}
/*
* conv_to_utf8(input)
*
* Convert the input string to utf8 from the current locale. If the
* conversion fails, use the current locale, it is likely close
* enough. For example, the "C" locale is a subset of utf-8. The
* return value may be a new string or the original input string.
*/
static char *
{
char *outleft;
char *curlocale;
static int warned = 0;
curlocale = "C";
/* Assume worst case of characters expanding to 4 bytes. */
/* inval can be modified on return */
}
} else {
/* Need to return something. */
}
(void) iconv_close(cd);
} else {
if (!warned)
gettext("Cannot convert to UTF-8 from %s\n"),
warned = 1;
}
return (output);
}
/*
* conv_from(input)
*
* Convert the input string from utf8 to current locale. If the
* conversion isn't supported, just use as is. The return value may be
* a new string or the original input string.
*/
static char *
{
char *outleft;
char *curlocale;
static int warned = 0;
curlocale = "C";
/* Assume worst case of characters expanding to 4 bytes. */
} else {
/* Need to return something. */
}
(void) iconv_close(cd);
} else {
if (!warned)
gettext("Cannot convert to %s from UTF-8\n"),
warned = 1;
}
return (output);
}
/*
* print_rsrc_desc(resource, sharedesc)
*
* Print the resource description string after converting from UTF8 to
* the current locale. If sharedesc is not NULL and there is no
* description on the resource, use sharedesc. sharedesc will already
* be converted to UTF8.
*/
static void
{
char *description;
char *desc;
return;
if (description != NULL) {
if (desc != description) {
description = desc;
}
}
if (description != NULL) {
}
}
/*
* set_resource_desc(share, description)
*
* Set the share description value after converting the description
* string to UTF8 from the current locale.
*/
static int
{
char *desc;
int ret;
if (description != desc)
return (ret);
}
/*
* set_share_desc(share, description)
*
* Set the resource description value after converting the description
* string to UTF8 from the current locale.
*/
static int
{
char *desc;
int ret;
if (description != desc)
return (ret);
}
/*
* add_list(list, item, data, proto)
* Adds a new list member that points holds item in the list.
* If list is NULL, it starts a new list. The function returns
* the first member of the list.
*/
struct list *
{
} else {
return (listp);
}
return (new);
/* get to end of list */
}
return (listp);
}
/*
* free_list(list)
* Given a list, free all the members of the list;
*/
static void
{
}
}
/*
* check_authorization(instname, which)
*
* Checks to see if the specific type of authorization in which is
* enabled for the user in this SMF service instance.
*/
static int
{
} else {
/*
* Since names are restricted to SA_MAX_NAME_LEN won't
* overflow.
*/
if (scf_handle_bind(handle) == 0) {
switch (which) {
case SVC_SET:
svcstring, "general",
break;
case SVC_ACTION:
svcstring, "general",
break;
}
}
}
}
/* make sure we have an authorization string property */
int i;
/* check if this user has one of the strings */
ret = 1;
break;
}
}
}
endauthattr();
} else {
/* no authorization string defined */
ret = 0;
}
return (ret);
}
/*
* check_authorizations(instname, flags)
*
* check all the needed authorizations for the user in this service
* instance. Return value of 1(true) or 0(false) indicates whether
* there are authorizations for the user or not.
*/
static int
{
int ret1 = 0;
int ret2 = 0;
int ret;
if (flags & SVC_ACTION)
switch (flags) {
case SVC_ACTION:
break;
case SVC_SET:
break;
case SVC_ACTION|SVC_SET:
break;
default:
/* if not flags set, we assume we don't need authorizations */
ret = 1;
}
return (ret);
}
/*
* notify_or_enable_share(share, protocol)
*
* Since some protocols don't want an "enable" when properties change,
* this function will use the protocol specific notify function
* first. If that fails, it will then attempt to use the
* sa_enable_share(). "protocol" is the protocol that was specified
* on the command line.
*/
static void
{
char *path;
char *groupproto;
/* If really a resource, get parent share */
if (!sa_is_share(share)) {
}
/*
* Now that we've got a share in "parent", make sure it has a path.
*/
return;
return;
}
if (groupproto == NULL ||
if (groupproto != NULL)
continue;
}
if (sa_is_share(share)) {
groupproto)) != SA_OK) {
(void) printf(
gettext("Could not reenable"
" share %s: %s\n"),
}
}
} else {
/* Must be a resource */
groupproto)) != SA_OK) {
(void) printf(
gettext("Could not "
"reenable resource %s: "
"%s\n"), path,
sa_errorstr(ret));
}
}
}
}
}
/*
* enable_group(group, updateproto, notify, proto)
*
* enable all the shares in the specified group. This is a helper for
* enable_all_groups in order to simplify regular and subgroup (zfs)
* enabling. Group has already been checked for non-NULL. If notify
* is non-zero, attempt to use the notify interface rather than
* enable.
*/
static void
{
/* If the protocol isn't enabled for this group skip it */
return;
if (updateproto != NULL)
if (notify)
else
}
}
/*
* isenabled(group)
*
* Returns B_TRUE if the group is enabled or B_FALSE if it isn't.
* Moved to separate function to reduce clutter in the code.
*/
static int
{
char *state;
}
}
return (ret);
}
/*
* enable_all_groups(list, setstate, online, updateproto)
*
* Given a list of groups, enable each one found. If updateproto is
* not NULL, then update all the shares for the protocol that was
* passed in. If enable is non-zero, tell enable_group to try the
* notify interface since this is a property change.
*/
static int
{
int ret;
char *state;
char *name;
/*
* If setstate == TRUE, then make sure to set
* enabled. This needs to be done here in order for
* the isenabled check to succeed on a newly enabled
* group.
*/
break;
}
/*
* Check to see if group is enabled. If it isn't, skip
* the rest. We don't want shares starting if the
* group is disabled. The properties may have been
* updated, but there won't be a change until the
* group is enabled.
*/
continue;
/* if itemdata != NULL then a single share */
if (enable) {
else
ret = SA_CONFIG_ERR;
} else {
} else {
}
}
}
break;
/* if itemdata == NULL then the whole group */
/*
* If the share is managed by ZFS, don't
* update any of the protocols since ZFS is
* handling this. Updateproto will contain
* the name of the protocol that we want to
* update legacy files for.
*/
/* never update legacy for ZFS subgroups */
}
}
if (online) {
sizeof (instance), "%s:%s",
(void) smf_enable_instance(
instance, 0);
}
} else {
}
}
}
}
}
return (ret);
}
/*
* chk_opt(optlistp, security, proto)
*
* Do a sanity check on the optlist provided for the protocol. This
* is a syntax check and verification that the property is either a
* general or specific to a names optionset.
*/
static int
{
int notfirst = 0;
int ret;
char *optname;
ret = OPT_ADD_OK;
if (!security)
} else {
if (security)
}
if (ret != OPT_ADD_OK) {
if (notfirst == 0)
(void) printf(
gettext("Property syntax error: "));
switch (ret) {
case OPT_ADD_SYNTAX:
sep = ", ";
break;
case OPT_ADD_SECURITY:
sep = ", ";
break;
case OPT_ADD_PROPERTY:
(void) printf(
gettext("%s%s not supported with -S"),
sep = ", ";
break;
}
notfirst++;
}
}
if (notfirst) {
(void) printf("\n");
ret = SA_SYNTAX_ERR;
}
return (ret);
}
/*
* free_opt(optlist)
* Free the specified option list.
*/
static void
{
}
}
/*
* check property list for valid properties
* A null value is a remove which is always valid.
*/
static int
{
else
}
continue;
ret = SA_NO_MEMORY;
SA_OK) {
(void) printf(
gettext("Could not add property %s: %s\n"),
}
(void) sa_remove_property(prop);
}
return (ret);
}
/*
* add_optionset(group, optlist, protocol, *err)
* Add the options in optlist to an optionset and then add the optionset
* to the group.
*
* The return value indicates if there was a "change" while errors are
* returned via the *err parameters.
*/
static int
{
ret = SA_NO_MEMORY;
}
ret = SA_NO_MEMORY;
goto out;
}
ret = SA_CONFIG_ERR;
goto out;
}
/*
* add the property, but only if it is
* a non-NULL or non-zero length value
*/
(void) sa_remove_property(prop);
"not add property "
"%s: %s\n"),
sa_errorstr(ret));
}
}
"Could not add property "
"%s: %s\n"),
sa_errorstr(ret));
} else {
/* there was a change */
}
}
}
} else {
/* should check to see if value changed */
sa_errorstr(ret));
} else {
}
}
}
out:
return (result);
}
/*
* resource_compliant(group)
*
* Go through all the shares in the group. Assume compliant, but if
* any share doesn't have at least one resource name, it isn't
* compliant.
*/
static int
{
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* fix_path(path)
*
* change all illegal characters to something else. For now, all get
* converted to '_' and the leading '/' is stripped off. This is used
* to construct an resource name (SMB share name) that is valid.
* Caller must pass a valid path.
*/
static void
{
char *cp;
/* make sure we are appropriate length */
cp++;
}
/* two cases - cp == NULL and cp is substring of path */
/* just take last SA_MAX_RESOURCE_NAME chars */
} else {
}
/*
* Don't want any of the characters that are not allowed
* in and SMB share name. Replace them with '_'.
*/
while (*path) {
switch (*path) {
case '/':
case '"':
case '\\':
case '[':
case ']':
case ':':
case '|':
case '<':
case '>':
case '+':
case ';':
case ',':
case '?':
case '*':
case '=':
case '\t':
*path = '_';
break;
}
path++;
}
}
/*
* name_adjust(path, count)
*
* Add a ~<count> in place of last few characters. The total number of
* characters is dependent on count.
*/
static int
{
if (count > 10)
len--;
if (count > 100)
len--;
if (count > 1000)
len--;
if (len > 0)
else
return (SA_BAD_VALUE);
return (SA_OK);
}
/*
* make_resources(group)
*
* Go through all the shares in the group and make them have resource
* names.
*/
static void
{
int count;
/* Skip those with resources */
char *path;
continue;
count = 0; /* reset for next resource */
err == SA_DUPLICATE_NAME) {
int ret;
count++;
count >= MAX_MANGLE_NUMBER) {
"Cannot create resource name for"
" path: %s\n"), path);
break;
}
}
}
}
}
/*
* check_valid_group(group, protocol)
*
* Check to see that the group should have the protocol added (if
* there is one specified).
*/
static int
{
"Group \"%s\" already exists"
" with protocol %s\n"), groupname,
protocol);
return (SA_DUPLICATE_NAME);
"Group \"%s\" only allows protocol "
return (SA_INVALID_PROTOCOL);
}
} else {
/* must add new protocol */
"Group already exists and no protocol "
"specified.\n"));
return (SA_DUPLICATE_NAME);
}
return (SA_OK);
}
/*
* enforce_featureset(group, protocol, dryrun, force)
*
* Check the protocol featureset against the group and enforce any
* rules that might be imposed.
*/
static int
{
return (SA_OK);
/*
* First check to see if specified protocol is one we want to
* allow on a group. Only server protocols are allowed here.
*/
if (!(features & SA_FEATURE_SERVER)) {
(void) printf(
return (SA_INVALID_PROTOCOL);
}
/*
* Check to see if the new protocol is one that requires
* resource names and make sure we are compliant before
* proceeding.
*/
if ((features & SA_FEATURE_RESOURCE) &&
!resource_compliant(group)) {
} else {
(void) printf(
gettext("Protocol requires resource names to be "
"set: %s\n"), protocol);
return (SA_RESOURCE_REQUIRED);
}
}
return (SA_OK);
}
/*
* set_all_protocols(group)
*
* Get the list of all protocols and add all server protocols to the
* group.
*/
static int
{
char **protolist;
int numprotos, i;
/*
* Now make sure we really want to put this protocol on a
* group. Only server protocols can go here.
*/
for (i = 0; i < numprotos; i++) {
if (features & SA_FEATURE_SERVER) {
ret = SA_NO_MEMORY;
break;
}
}
}
return (ret);
}
/*
* sa_create(flags, argc, argv)
* create a new group
* this may or may not have a protocol associated with it.
* No protocol means "all" protocols in this case.
*/
static int
{
char *groupname;
int c;
int auth;
switch (c) {
case 'f':
break;
case 'v':
break;
case 'n':
break;
case 'P':
"multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (sa_valid_protocol(protocol))
break;
"Invalid protocol specified: %s\n"), protocol);
return (SA_INVALID_PROTOCOL);
case 'p':
switch (ret) {
case OPT_ADD_SYNTAX:
"Property syntax error for property: %s\n"),
optarg);
return (SA_SYNTAX_ERR);
case OPT_ADD_SECURITY:
"Security properties need "
"to be set with set-security: %s\n"),
optarg);
return (SA_SYNTAX_ERR);
default:
break;
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
err = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (err);
}
}
return (SA_BAD_PATH);
}
return (SA_SYNTAX_ERR);
}
/* lookup default protocol */
"with properties\n"));
return (SA_INVALID_PROTOCOL);
}
if (ret == OPT_ADD_SECURITY) {
"supported with create\n"));
return (SA_SYNTAX_ERR);
}
/*
* If a group already exists, we can only add a new protocol
* to it and not create a new one or add the same protocol
* again.
*/
/* group exists so must be a protocol add */
} else {
/*
* is it a valid name? Must comply with SMF instance
* name restrictions.
*/
if (!sa_valid_group_name(groupname)) {
}
}
/* check protocol vs optlist */
/* check options, if any, for validity */
}
}
&err);
}
/*
* Check group and protocol against featureset
* requirements.
*/
goto err;
/*
* So far so good. Now add the required
* optionset(s) to the group.
*/
&ret);
protocol);
ret = SA_NO_MEMORY;
/* default group create so add all protocols */
}
/*
* We have a group and legal additions
*/
/*
* Commit to configuration for protocols that
* need to do block updates. For NFS, this
* doesn't do anything but it will be run for
* all protocols that implement the
* appropriate plugin.
*/
} else {
(void) sa_remove_group(group);
}
} else {
sa_errorstr(ret));
}
}
}
err:
return (ret);
}
/*
* group_status(group)
*
*/
static char *
{
char *state;
int enabled = 0;
enabled = 1;
}
}
}
/*
* sa_delete(flags, argc, argv)
*
* Delete a group.
*/
static int
{
char *groupname;
int verbose = 0;
int dryrun = 0;
int force = 0;
int c;
int auth;
switch (c) {
case 'v':
verbose++;
break;
case 'n':
dryrun++;
break;
case 'P':
"multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"specified: %s\n"), protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'S':
"multiple property "
"spaces not supported: %s\n"), sectype);
return (SA_SYNTAX_ERR);
}
break;
case 'f':
force++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
return (SA_SYNTAX_ERR);
}
return (SA_SYNTAX_ERR);
}
"specified.\n"));
return (SA_SYNTAX_ERR);
}
/*
* Determine if the group already exists since it must in
* order to be removed.
*
* We can delete when:
*
* - group is empty
* - force flag is set
* - if protocol specified, only delete the protocol
*/
goto done;
}
if (!dryrun) {
/*
* need to do the disable of
* each share, but don't
* actually do anything on a
* dryrun.
*/
share = next_share;
}
}
}
/* Commit to configuration if not a dryrun */
}
} else {
/* a protocol delete */
/* only delete specified security */
else
} else {
/*
* have an optionset with
* protocol to delete
*/
/*
* Now find all security sets
* for the protocol and remove
* them. Don't remove other
* protocols.
*/
for (security =
char *secprot;
"type");
security);
}
} else {
if (!dryrun)
}
}
/*
* With the protocol items removed, make sure that all
* the shares are updated in the legacy files, if
* necessary.
*/
}
}
done:
sa_errorstr(ret));
}
return (ret);
}
/*
* strndupr(*buff, str, buffsize)
*
* used with small strings to duplicate and possibly increase the
* buffer size of a string.
*/
static char *
{
int limit;
return (NULL);
*buffsize = 64;
buff[0] = '\0';
}
}
} else {
/* if it fails, fail it hard */
}
return (buff);
}
/*
* group_proto(group)
*
* return a string of all the protocols (space separated) associated
* with this group.
*/
static char *
{
char *proto;
int buffsize = 0;
int addspace = 0;
/*
* get the protocol list by finding the optionsets on this
* group and extracting the type value. The initial call to
* strndupr() initailizes buff.
*/
/*
* extract out the protocol type from this optionset
* and append it to the buffer "buff". strndupr() will
* reallocate space as necessay.
*/
if (addspace++)
}
}
}
return (buff);
}
/*
* sa_list(flags, argc, argv)
*
* implements the "list" subcommand to list groups and optionally
* their state and protocols.
*/
static int
{
int verbose = 0;
int c;
#ifdef lint
#endif
switch (c) {
case 'v':
verbose++;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"),
protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
return (SA_SYNTAX_ERR);
}
char *name;
char *proto;
if (verbose) {
/*
* Need the list of protocols
* and current status once
* available. We do want to
* translate the
*/
gettext("enabled") :
gettext("disabled"));
(void) printf("\t%s",
(char *)proto);
}
}
(void) printf("\n");
}
}
}
return (0);
}
/*
* out_properties(optionset, proto, sec)
*
* Format the properties and encode the protocol and optional named
* optionset into the string.
*
* format is protocol[:name]=(property-list)
*/
static void
{
char *type;
char *value;
int spacer;
else
/*
* appropriate spacing. I.e. no prefixed space the
* first time through but a space on subsequent
* properties.
*/
spacer = 1;
else
(void) printf("\"\"");
}
}
(void) printf(")");
}
/*
* show_properties(group, protocol, prefix)
*
* print the properties for a group. If protocol is NULL, do all
* protocols otherwise only the specified protocol. All security
* (named groups specific to the protocol) are included.
*
* The "prefix" is always applied. The caller knows whether it wants
* some type of prefix string (white space) or not. Once the prefix
* has been output, it is reduced to the zero length string for the
* remainder of the property output.
*/
static void
{
char *value;
char *secvalue;
prefix = "";
}
prefix = "";
}
} else {
prefix = "";
}
prefix = "";
}
}
}
/*
* get_resource(share)
*
* Get the first resource name, if any, and fix string to be in
* current locale and have quotes if it has embedded spaces. Return
* an attr string that must be freed.
*/
static char *
{
char *retstring;
char *cp;
int len;
}
/* account for quotes */
"\"%s\"", resstring);
} else {
}
}
}
}
return (resstring);
}
/*
* has_resource_with_opt(share)
*
* Check to see if the share has any resource names with optionsets
* set. Also indicate if multiple resource names since the syntax
* would be about the same.
*/
static int
{
break;
}
}
return (ret);
}
/*
* has_multiple_resource(share)
*
* Check to see if the share has multiple resource names since
* the syntax would be about the same.
*/
static boolean_t
{
int num;
num++;
if (num > 1)
return (B_TRUE);
}
return (B_FALSE);
}
/*
* show_share(share, verbose, properties, proto, iszfs, sharepath)
*
* print out the share information. With the addition of resource as a
* full object that can have multiple instances below the share, we
* need to display that as well.
*/
static void
{
char *drive;
char *exclude;
char *description;
char *rsrcname;
int rsrcwithopt;
char *type;
/* First, indicate if transient */
(void) printf("\t* ");
else
(void) printf("\t ");
/*
* If we came in with verbose, we want to handle the case of
* multiple resources as though they had properties set.
*/
/*
* if there is a description on the share and there
* are resources, treat as multiple resources in order
* to get all descriptions displayed.
*/
/* Next, if not multiple follow old model */
if (!multiple && !rsrcwithopt) {
} else {
}
/* Print the description string if there is one. */
} else {
/* Treat as simple and then resources come later */
}
drive);
}
if (properties)
exclude);
}
if (description != NULL) {
}
/*
* If there are resource names with options, show them
* here, with one line per resource. Resource specific
* options are at the end of the line followed by
* description, if any.
*/
if (rsrcwithopt || multiple) {
int has_space;
char *rsrc;
(void) printf("\n\t\t ");
"name");
continue;
if (has_space)
else
if (properties || rsrcwithopt)
/* Get description string if any */
}
}
if (description != NULL)
} else {
if (properties)
}
(void) printf("\n");
}
/*
* show_group(group, verbose, properties, proto, subgroup)
*
* helper function to show the contents of a group.
*/
static void
char *subgroup)
{
char *groupname;
int iszfs = 0;
char *sharepath;
return;
}
/*
* check to see if the group is managed by ZFS. If
* there is an attribute, then it is. A non-NULL zfs
* variable will trigger the different way to display
* and will remove the transient property indicator
* from the output.
*/
iszfs = 1;
}
else
if (properties)
(void) printf("\n");
"zfs");
}
return;
}
/*
* Have a group, so list the contents. Resource and
* description are only listed if verbose is set.
*/
}
}
}
}
}
/*
* show_group_xml_init()
*
* Create an XML document that will be used to display config info via
* XML format.
*/
{
}
return (doc);
}
/*
* show_group_xml(doc, group)
*
* Copy the group info into the XML doc.
*/
static void
{
/*
* In the future, we may have interally used tags that
* should not appear in the XML output. Remove
* anything we don't want to show here.
*/
}
}
/*
* sa_show(flags, argc, argv)
*
* Implements the show subcommand.
*/
int
{
int verbose = 0;
int properties = 0;
int c;
int xml = 0;
#ifdef lint
#endif
switch (c) {
case 'v':
verbose++;
break;
case 'p':
properties++;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"),
protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'x':
xml++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
if (xml) {
doc = show_group_xml_init();
ret = SA_NO_MEMORY;
}
/* No group specified so go through them all */
/*
* Have a group so check if one we want and then list
* contents with appropriate options.
*/
if (xml)
else
NULL);
}
} else {
/* Have a specified list of groups */
if (xml)
else
} else {
}
}
}
}
return (ret);
}
/*
* enable_share(group, share, update_legacy)
*
* helper function to enable a share if the group is enabled.
*/
static int
int update_legacy)
{
char *value;
int enabled;
int err;
int iszfs = 0;
int isshare;
/*
* need to enable this share if the group is enabled but not
* otherwise. The enable is also done on each protocol
* represented in the group.
*/
/* remove legacy config if necessary */
if (update_legacy)
iszfs++;
}
/*
* Step through each optionset at the group level and
* enable the share based on the protocol type. This
* works because protocols must be set on the group
* for the protocol to be enabled.
*/
if (enabled) {
if (isshare) {
} else {
if (err == SA_NOT_SUPPORTED) {
share);
}
}
"Failed to enable share for "
"\"%s\": %s\n"),
}
}
/*
* If we want to update the legacy, use a copy of
* share so we can avoid breaking the loop we are in
* since we might also need to go up the tree to the
* parent.
*/
if (update_legacy && !iszfs) {
if (!sa_is_share(share)) {
}
}
}
}
(void) sa_update_config(handle);
return (ret);
}
/*
* sa_require_resource(group)
*
* if any of the defined protocols on the group require resource
* names, then all shares must have them.
*/
static int
{
char *proto;
if (features & SA_FEATURE_RESOURCE) {
return (B_TRUE);
}
}
}
return (B_FALSE);
}
/*
* sa_addshare(flags, argc, argv)
*
* implements add-share subcommand.
*/
static int
{
int verbose = 0;
int dryrun = 0;
int c;
int auth;
switch (c) {
case 'n':
dryrun++;
break;
case 'v':
verbose++;
break;
case 'd':
break;
case 'r':
"resource names not"
" supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 's':
/*
* Save share path into group. Currently limit
* to one share per command.
*/
"Adding multiple shares not supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 't':
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
} else {
}
} else {
"\t-s sharepath must be specified\n"));
ret = SA_BAD_PATH;
}
ret = SA_BAD_PATH;
"is not valid: %s\n"),
} else {
}
}
/* check for valid syntax */
if (validresource(rsrcname)) {
/*
* Resource names must be
* unique in the system
*/
"\tresource names must be unique "
"in the system\n"));
}
} else {
"\tresource names use restricted "
"character set\n"));
}
}
return (ret);
}
/*
* Can only have a duplicate share if a new
* resource name is being added.
*/
"shared: %s\n"), sharepath);
}
}
return (ret);
"Resource name is required "
"by at least one enabled protocol "
"in group\n"));
return (SA_RESOURCE_REQUIRED);
}
if (dryrun)
else
}
/*
* Make sure this isn't an attempt to put a resourced
* share into a different group than it already is in.
*/
"Share path already "
"shared: %s\n"), sharepath);
}
}
"Could not add share: %s\n"),
sa_errorstr(ret));
} else {
flags);
rsrc,
&ret);
}
description != NULL) {
ret =
else
ret =
}
/* now enable the share(s) */
ret = enable_share(
1);
} else {
ret = enable_share(
1);
}
}
switch (ret) {
case SA_DUPLICATE_NAME:
"Resource name in"
"use: %s\n"),
rsrcname);
break;
default:
"Could not set "
"attribute: %s\n"),
sa_errorstr(ret));
break;
case SA_OK:
break;
}
"Command would fail: %s\n"),
}
}
} else {
switch (ret) {
default:
break;
case SA_BAD_PATH:
case SA_DUPLICATE_NAME:
break;
}
}
}
return (ret);
}
/*
* sa_moveshare(flags, argc, argv)
*
* implements move-share subcommand.
*/
int
{
int verbose = 0;
int dryrun = 0;
int c;
switch (c) {
case 'n':
dryrun++;
break;
case 'v':
verbose++;
break;
case 'r':
"Moving multiple resource names not"
" supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 's':
/*
* Remove share path from group. Currently limit
* to one share per command.
*/
" not supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
} else {
ret = SA_SYNTAX_ERR;
"\tsharepath must be specified\n"));
} else {
}
}
} else {
char *zfsold;
char *zfsnew;
"sharepath must be specified with the -s "
"option\n"));
return (SA_BAD_PATH);
}
return (SA_NO_SUCH_GROUP);
}
/*
* If a share wasn't found, it may have been a symlink
* or has a trailing '/'. Try again after resolving
* with realpath().
*/
"is not valid: %s\n"),
return (SA_BAD_PATH);
}
}
return (SA_NO_SUCH_PATH);
}
char *pname;
}
}
}
char *oldstate;
/*
* Note that the share may need to be
* "unshared" if the new group is disabled and
* the old was enabled or it may need to be
* share to update if the new group is
* enabled. We disable before the move and
* will have to enable after the move in order
* to cleanup entries for protocols that
* aren't in the new group.
*/
/* enable_share determines what to do */
}
}
/*
* Reenable and update any config information.
*/
}
sa_errorstr(ret));
verbose) {
}
}
return (ret);
}
/*
* sa_removeshare(flags, argc, argv)
*
* implements remove-share subcommand.
*/
int
{
int verbose = 0;
int dryrun = 0;
int force = 0;
int c;
int auth;
switch (c) {
case 'n':
dryrun++;
break;
case 'v':
verbose++;
break;
case 'f':
force++;
break;
case 's':
/*
* Remove share path from group. Currently limit
* to one share per command.
*/
"Removing multiple shares not "
"supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 'r':
/*
* Remove share from group if last resource or remove
* resource from share if multiple resources.
*/
"Removing multiple resource names not "
"supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
" must be specified\n"));
ret = SA_BAD_PATH;
} else {
}
}
return (ret);
}
"command\n"));
ret = SA_SYNTAX_ERR;
} else {
}
}
} else {
}
"Resource name not found for share: %s\n"),
rsrcname);
}
}
/*
* Lookup the path in the internal configuration. Care
* must be taken to handle the case where the
* underlying path has been removed since we need to
* be able to deal with that as well.
*/
else
}
"Bad resource name for share: %s\n"),
rsrcname);
}
}
/*
* If we didn't find the share with the provided path,
* it may be a symlink so attempt to resolve it using
* realpath and try again. Realpath will resolve any
* symlinks and place them in "dir". Note that
* sharepath is only used for the lookup the first
* time and later for error messages. dir will be used
* on the second attempt. Once a share is found, all
* operations are based off of the share variable.
*/
ret = SA_BAD_PATH;
"Path is not valid: %s\n"), sharepath);
} else {
else
}
}
}
/*
* If there hasn't been an error, there was likely a
* path found. If not, give the appropriate error
* message and set the return error. If it was found,
* then disable the share and then remove it from the
* configuration.
*/
return (ret);
}
else
} else {
if (!dryrun) {
NULL);
else
/*
* We don't care if it fails since it
* could be disabled already. Some
* unexpected errors could occur that
* prevent removal, so also check for
* force being set.
*/
ret == SA_NOT_SUPPORTED ||
ret == SA_NOT_SUPPORTED ||
/*
* If this was the
* last one, remove
* the share as well.
*/
resource =
share);
}
}
}
char *pname;
}
"Command would fail: %s\n"),
}
}
}
return (ret);
}
/*
* sa_set_share(flags, argc, argv)
*
* implements set-share subcommand.
*/
int
{
int dryrun = 0;
int c;
char *newrsrc;
int auth;
int verbose = 0;
switch (c) {
case 'n':
dryrun++;
break;
case 'd':
break;
case 'v':
verbose++;
break;
case 'r':
/*
* Update share by resource name
*/
"Updating multiple resource names not "
"supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 's':
/*
* Save share path into group. Currently limit
* to one share per command.
*/
"Updating multiple shares not "
"supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
ret = SA_BAD_PATH;
} else {
}
}
ret = SA_SYNTAX_ERR;
}
/*
* Must have at least one of sharepath and rsrcrname.
* It is a syntax error to be missing both.
*/
ret = SA_SYNTAX_ERR;
}
return (ret);
} else {
}
/*
* If rsrcname exists, split rename syntax and then
* convert to utf 8 if no errors.
*/
*newname++ = '\0';
}
if (!validresource(rsrcname)) {
"\"%s\"\n"), rsrcname);
} else {
}
if (!validresource(newname)) {
"%s\n"), newname);
} else {
}
}
}
return (ret);
}
else
}
"share %s\n"),
ret = SA_BAD_PATH;
} else {
int delgroupname = 0;
"name");
delgroupname = 1;
}
if (delgroupname) {
}
} else {
ret = SA_NO_MEMORY;
}
if (!dryrun) {
}
}
/*
* If the user has set a description, it will be
* on the resource if -r was used otherwise it
* must be on the share.
*/
char *desc;
else
desc);
if (desc != description)
}
}
}
switch (ret) {
case SA_DUPLICATE_NAME:
rsrcname);
break;
default:
sa_errorstr(ret));
break;
case SA_OK:
"Command would fail: %s\n"),
}
break;
}
} else {
switch (ret) {
case SA_NO_SUCH_RESOURCE:
rsrcname);
break;
default:
(void) printf(
gettext("Share path \"%s\" not found\n"),
} else {
sa_errorstr(ret));
}
}
}
return (ret);
}
/*
* add_security(group, sectype, optlist, proto, *err)
*
* Helper function to add a security option (named optionset) to the
* group.
*/
static int
{
int result = 0;
goto done;
ret = SA_CONFIG_ERR;
goto done;
}
/*
* Add the property, but only if it is
* a non-NULL or non-zero length value
*/
(void) sa_remove_property(prop);
"Could not add "
"property %s: %s\n"),
sa_errorstr(ret));
}
prop);
"Could not add "
"property (%s=%s):"
" %s\n"),
sa_errorstr(ret));
} else {
result = 1;
}
}
}
}
} else {
}
}
/*
* When done, properties may have all been removed but
* we need to keep the security type itself until
* explicitly removed.
*/
if (result)
done:
return (result);
}
/*
* zfscheck(group, share)
*
* For the special case where a share was provided, make sure it is a
* compatible path for a ZFS property change. The only path
* acceptable is the path that defines the zfs sub-group (dataset with
* the sharenfs property set) and not one of the paths that inherited
* the NFS properties. Returns SA_OK if it is usable and
* SA_NOT_ALLOWED if it isn't.
*
* on return will catch errors for those cases. What we are looking
* for here is that the group is ZFS and the share is not the defining
* share. All else is SA_OK.
*/
static int
{
char *attr;
if (sa_group_is_zfs(group)) {
/*
* The group is a ZFS group. Does the share represent
* the dataset that defined the group? It is only OK
* if the attribute "subgroup" exists on the share and
* has a value of "true".
*/
}
}
return (ret);
}
/*
* basic_set(groupname, optlist, protocol, sharepath, rsrcname, dryrun)
*
* This function implements "set" when a name space (-S) is not
* specified. It is a basic set. Options and other CLI parsing has
* already been done.
*
* "rsrcname" is a "resource name". If it is non-NULL, it must match
* the sharepath if present or group if present, otherwise it is used
* to set options.
*
* Resource names may take options if the protocol supports it. If the
* protocol doesn't support resource level options, rsrcname is just
* an alias for the share.
*/
static int
{
int change = 0;
/*
* If there is a sharepath, make sure it belongs to
* the group.
*/
"Share does not exist in group %s\n"),
} else {
/* if ZFS and OK, then only group */
if (ret == SA_NOT_ALLOWED)
"Properties on ZFS group shares "
"not supported: %s\n"), sharepath);
}
}
/*
* If a resource name exists, make sure it belongs to
* the share if present else it belongs to the
* group. Also check the protocol to see if it
* supports resource level properties or not. If not,
* use share only.
*/
rsrcname);
} else {
resource);
else
}
/*
* Check to see if the resource can take
* properties. If so, stick the resource into
* "share" so it will all just work.
*/
if (features & SA_FEATURE_RESOURCE)
}
}
/* group must exist */
else
}
}
} else {
}
/*
* we have a group and potentially legal additions
*/
/*
* Commit to configuration if not a dryrunp and properties
* have changed.
*/
/* properties changed, so update all shares */
B_TRUE);
return (ret);
}
/*
* space_set(groupname, optlist, protocol, sharepath, dryrun)
*
* This function implements "set" when a name space (-S) is
* specified. It is a namespace set. Options and other CLI parsing has
* already been done.
*/
static int
{
int change = 0;
/*
* make sure protcol and sectype are valid
*/
"for protocol.\n"), sectype);
return (SA_INVALID_SECURITY);
}
"Share does not exist in group %s\n"),
} else {
/* if ZFS and OK, then only group */
if (ret == SA_NOT_ALLOWED)
"Properties on ZFS group shares "
"not supported: %s\n"), sharepath);
}
}
/* group must exist */
else
"Could not set property: %s\n"),
sa_errorstr(ret));
}
protocol);
}
} else {
}
/*
* We have a group and potentially legal additions.
*/
/* Commit to configuration if not a dryrun */
/* properties changed, so update all shares */
}
}
return (ret);
}
/*
* sa_set(flags, argc, argv)
*
* Implements the set subcommand. It keys off of -S to determine which
* set of operations to actually do.
*/
int
{
char *groupname;
int verbose = 0;
int dryrun = 0;
int c;
int auth;
switch (c) {
case 'v':
verbose++;
break;
case 'n':
dryrun++;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'p':
switch (ret) {
case OPT_ADD_SYNTAX:
" %s\n"), optarg);
return (SA_SYNTAX_ERR);
case OPT_ADD_MEMORY:
"property: %s\n"), optarg);
return (SA_NO_MEMORY);
default:
break;
}
break;
case 'r':
"Setting multiple resource names not"
" supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 's':
"Setting multiple shares not supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 'S':
"Specifying multiple property "
"spaces not supported: %s\n"), optset);
return (SA_SYNTAX_ERR);
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
sep);
sep = ", ";
}
" specified"), sep);
sep = ", ";
}
sep);
sep = ", ";
}
(void) printf("\n");
ret = SA_SYNTAX_ERR;
} else {
/*
* Group already exists so we can proceed after a few
* additional checks related to ZFS handling.
*/
"\"zfs\" not allowed\n"));
return (SA_NOT_ALLOWED);
}
else
}
}
return (ret);
}
/*
* remove_options(group, optlist, proto, *err)
*
* Helper function to actually remove options from a group after all
* preprocessing is done.
*/
static int
{
int change = 0;
break;
change = 1;
}
}
}
return (change);
}
/*
* valid_unset(group, optlist, proto)
*
* Sanity check the optlist to make sure they can be removed. Issue an
* error if a property doesn't exist.
*/
static int
{
"Could not unset property %s: not set\n"),
}
}
}
return (ret);
}
/*
* valid_unset_security(group, optlist, proto)
*
* Sanity check the optlist to make sure they can be removed. Issue an
* error if a property doesn't exist.
*/
static int
char *sectype)
{
char *sec;
"Could not unset property %s: not set\n"),
}
}
} else {
"Could not unset %s: space not defined\n"), sectype);
}
return (ret);
}
/*
* remove_security(group, optlist, proto)
*
* Remove the properties since they were checked as valid.
*/
static int
{
int change = 0;
break;
change = 1;
}
}
/*
* when done, properties may have all been removed but
* we need to keep the security type itself until
* explicitly removed.
*/
} else {
}
return (change);
}
/*
* basic_unset(groupname, optlist, protocol, sharepath, rsrcname, dryrun)
*
* Unset non-named optionset properties.
*/
static int
{
int change = 0;
return (ret);
/*
* If there is a sharepath, make sure it belongs to
* the group.
*/
"Share does not exist in group %s\n"),
}
}
/*
* If a resource name exists, make sure it belongs to
* the share if present else it belongs to the
* group. Also check the protocol to see if it
* supports resource level properties or not. If not,
* use share only.
*/
} else {
} else {
}
}
/*
* Check to see if the resource can take
* properties. If so, stick the resource into
* "share" so it will all just work.
*/
if (features & SA_FEATURE_RESOURCE)
}
}
/* group must exist */
/*
* If a share optionset is
* empty, remove it.
*/
protocol);
(void) sa_destroy_optionset(
}
} else {
}
protocol);
"Could not remove properties: "
}
} else {
}
/*
* We have a group and potentially legal additions
*
* Commit to configuration if not a dryrun
*/
/* properties changed, so update all shares */
}
}
return (ret);
}
/*
* space_unset(groupname, optlist, protocol, sharepath, dryrun)
*
* Unset named optionset properties.
*/
static int
{
int change = 0;
return (SA_NO_SUCH_GROUP);
}
"Share does not exist in group %s\n"),
return (SA_NO_SUCH_PATH);
}
}
/* If a share security is empty, remove it */
NULL);
}
} else {
}
} else {
char *sec;
change = 1;
} else {
}
}
sa_errorstr(ret));
}
/*
* We have a group and potentially legal additions
*/
/* Commit to configuration if not a dryrun */
/* properties changed, so update all shares */
}
return (ret);
}
/*
* sa_unset(flags, argc, argv)
*
* Implements the unset subcommand. Parsing done here and then basic
* or space versions of the real code are called.
*/
int
{
char *groupname;
int verbose = 0;
int dryrun = 0;
int c;
int auth;
switch (c) {
case 'v':
verbose++;
break;
case 'n':
dryrun++;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'p':
switch (ret) {
case OPT_ADD_SYNTAX:
"for property %s\n"), optarg);
return (SA_SYNTAX_ERR);
case OPT_ADD_PROPERTY:
"set with set command: %s\n"), optarg);
return (SA_SYNTAX_ERR);
default:
break;
}
break;
case 'r':
/*
* Unset properties on resource if applicable or on
* share if resource for this protocol doesn't use
* resources.
*/
"Unsetting multiple resource "
"names not supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 's':
"Adding multiple shares not supported\n"));
return (SA_SYNTAX_ERR);
}
break;
case 'S':
"Specifying multiple property "
"spaces not supported: %s\n"), optset);
return (SA_SYNTAX_ERR);
}
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
sep);
sep = ", ";
}
"be specified"), sep);
sep = ", ";
}
sep);
sep = ", ";
}
(void) printf("\n");
ret = SA_SYNTAX_ERR;
} else {
/*
* If a group already exists, we can only add a new
* protocol to it and not create a new one or add the
* same protocol again.
*/
else
}
return (ret);
}
/*
* sa_enable_group(flags, argc, argv)
*
* Implements the enable subcommand
*/
int
{
int verbose = 0;
int dryrun = 0;
int all = 0;
int c;
char *state;
switch (c) {
case 'a':
all = 1;
break;
case 'n':
dryrun++;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'v':
verbose++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
return (ret);
}
}
}
return (SA_NO_SUCH_PATH);
}
if (!all) {
flags);
/* already enabled */
if (verbose)
"Group \"%s\" is already "
"enabled\n"),
} else {
0, protocol);
if (verbose)
"Enabling group \"%s\"\n"),
}
} else {
}
optind++;
}
} else {
}
}
sa_errorstr(ret));
}
return (ret);
}
/*
* disable_group(group, proto)
*
* Disable all the shares in the specified group.. This is a helper
* for disable_all_groups in order to simplify regular and subgroup
* (zfs) disabling. Group has already been checked for non-NULL.
*/
static int
{
/*
* If the protocol isn't enabled, skip it and treat as
* successful.
*/
return (ret);
if (ret == SA_NO_SUCH_PATH) {
/*
* this is OK since the path is gone. we can't
* re-share it anyway so no error.
*/
}
}
return (ret);
}
/*
* disable_all_groups(work, setstate)
*
* helper function that disables the shares in the list of groups
* provided. It optionally marks the group as disabled. Used by both
* enable and start subcommands.
*/
static int
{
if (setstate)
char *name;
/* need to get the sub-groups for stopping */
}
} else {
}
/*
* We don't want to "disable" since it won't come
* up after a reboot. The SMF framework should do
* the right thing. On enable we do want to do
* something.
*/
}
}
return (ret);
}
/*
* sa_disable_group(flags, argc, argv)
*
* Implements the disable subcommand
*/
int
{
int verbose = 0;
int dryrun = 0;
int all = 0;
int c;
char *state;
switch (c) {
case 'a':
all = 1;
break;
case 'n':
dryrun++;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'v':
verbose++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
return (SA_NO_SUCH_PATH);
}
if (!all) {
flags);
/* already disabled */
if (verbose)
"Group \"%s\" is "
"already disabled\n"),
} else {
protocol);
if (verbose)
"Disabling group "
}
} else {
}
optind++;
}
} else {
}
sa_errorstr(ret));
return (ret);
}
/*
* sa_start_group(flags, argc, argv)
*
* Implements the start command.
* This is similar to enable except it doesn't change the state
* of the group(s) and only enables shares if the group is already
* enabled.
*/
int
{
int verbose = 0;
int all = 0;
int c;
char *state;
#ifdef lint
#endif
switch (c) {
case 'a':
all = 1;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'v':
verbose++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
return (SMF_EXIT_ERR_FATAL);
}
if (!all) {
protocol);
if (verbose)
"Starting group \"%s\"\n"),
} else {
/*
* Determine if there are any
* protocols. If there aren't any,
* then there isn't anything to do in
* any case so no error.
*/
if (sa_get_optionset(group,
ret = SMF_EXIT_OK;
}
}
}
optind++;
}
} else {
protocol);
}
}
return (ret);
}
/*
* sa_stop_group(flags, argc, argv)
*
* Implements the stop command.
* This is similar to disable except it doesn't change the state
* of the group(s) and only disables shares if the group is already
* enabled.
*/
int
{
int verbose = 0;
int all = 0;
int c;
char *state;
#ifdef lint
#endif
switch (c) {
case 'a':
all = 1;
break;
case 'P':
"Specifying multiple protocols "
"not supported: %s\n"), protocol);
return (SA_SYNTAX_ERR);
}
if (!sa_valid_protocol(protocol)) {
"Invalid protocol specified: %s\n"),
protocol);
return (SA_INVALID_PROTOCOL);
}
break;
case 'v':
verbose++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_SYNTAX_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
return (SMF_EXIT_ERR_FATAL);
} else if (!all) {
protocol);
if (verbose)
"Stopping group \"%s\"\n"),
} else {
ret = SMF_EXIT_OK;
}
}
optind++;
}
} else {
protocol);
}
}
return (ret);
}
/*
* remove_all_options(share, proto)
*
* Removes all options on a share.
*/
static void
{
(void) sa_destroy_optionset(optionset);
char *type;
/*
* We walk through the list. prevsec keeps the
* previous security so we can delete it without
* destroying the list.
*/
/* remove the previously seen security */
(void) sa_destroy_security(prevsec);
/* set to NULL so we don't try multiple times */
}
/*
* if the security matches the specified protocol, we
* want to remove it. prevsec holds it until either
* the next pass or we fall out of the loop.
*/
}
}
/* in case there is one left */
(void) sa_destroy_security(prevsec);
}
/*
* for legacy support, we need to handle the old syntax. This is what
* we get if sharemgr is called with the name "share" rather than
* sharemgr.
*/
static int
{
int err;
return (-1);
return (0);
}
/*
* check_legacy_cmd(proto, cmd)
*
* executable.
*/
static int
{
int ret = 0;
ret = 1;
}
return (ret);
}
/*
* run_legacy_command(proto, cmd, argv)
*
* We know the command exists, so attempt to execute it with all the
* arguments. This implements full legacy share support for those
* protocols that don't have plugin providers.
*/
static int
{
int ret;
if (ret < 0) {
switch (errno) {
case EACCES:
break;
default:
ret = SA_SYSTEM_ERR;
break;
}
}
return (ret);
}
/*
* out_share(out, group, proto)
*
* Display the share information in the format that the "share"
* command has traditionally used.
*/
static void
{
char *defprop;
/*
* The original share command defaulted to displaying NFS
* shares or allowed a protocol to be specified. We want to
* skip those shares that are not the specified protocol.
*/
return;
proto = "nfs";
/*
* get the default property string. NFS uses "rw" but
* everything else will use "".
*/
defprop = "\"\"";
else
defprop = "rw";
char *path;
char *type;
char *resource;
char *description;
char *groupname;
char *sharedstate;
char *soptions;
}
/*
* Want the sharetab version if it exists, defaulting
* to NFS if no protocol specified.
*/
if (sharedstate == NULL)
shared = 0;
if (shared) {
/* only active shares go here */
}
if (description != NULL)
if (sharedstate != NULL)
}
}
/*
* output_legacy_file(out, proto)
*
* Walk all of the groups for the specified protocol and call
* out_share() to format and write in the format displayed by the
* "share" command with no arguments.
*/
static void
{
char *zfs;
/*
* Go through all the groups and ZFS
* sub-groups. out_share() will format the shares in
* the group appropriately.
*/
/* got a group, so display it */
}
} else {
}
}
}
int
{
int argsused = 0;
int c;
int zfs = 0;
int true_legacy = 0;
#ifdef lint
#endif
switch (c) {
case 'd':
argsused++;
break;
case 'F':
if (!sa_valid_protocol(protocol)) {
protocol, "share") == 0 &&
check_legacy_cmd(cmd)) {
true_legacy++;
} else {
"Invalid protocol specified: "
"%s\n"), protocol);
return (SA_INVALID_PROTOCOL);
}
}
break;
case 'o':
argsused++;
break;
case 'p':
argsused++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_LEGACY_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
/* Have the info so construct what is needed */
/* display current info in share format */
return (ret);
}
/* We are modifying the configuration */
return (SA_LEGACY_ERR);
}
if (true_legacy) {
return (ret);
}
*groupname++ = '\0';
}
ret = SA_BAD_PATH;
else
else
char *legacygroup;
/*
* The legacy group is always present and zfs groups
* come and go. zfs shares may be in sub-groups and
* the zfs share will already be in that group so it
* isn't an error. If the protocol is "smb", the group
* "smb" is used when "default" would otherwise be
* used. "default" is NFS only and "smb" is SMB only.
*/
legacygroup = "smb";
else
legacygroup = "default";
/*
* If the share exists (not NULL), then make sure it
* is one we want to handle by getting the parent
* group.
*/
} else {
/*
* This group may not exist, so create
* as necessary. It only contains the
* "smb" protocol.
*/
&ret);
(void) sa_create_optionset(group,
protocol);
}
}
ret = SA_SYSTEM_ERR;
goto err;
}
ret == SA_DUPLICATE_NAME) {
/*
* Could be a ZFS path being started
*/
if (sa_zfs_is_shared(handle,
sharepath)) {
"zfs");
/*
* This shouldn't
* happen.
*/
ret = SA_CONFIG_ERR;
} else {
}
}
}
} else {
char *type;
/*
* May want to change persist state, but the
* important thing is to change options. We
* need to change them regardless of the
* source.
*/
zfs = 1;
}
}
"persist" : "transient");
}
}
/*
* If there is a resource name, we may
* actually care about it if this is share for
* a protocol that uses resource level sharing
* (SMB). We need to find the resource and, if
* it exists, make sure it belongs to the
* current share. If it doesn't exist, attempt
* to create it.
*/
} else {
}
if (features & SA_FEATURE_RESOURCE)
}
/* Have a group to hold this share path */
protocol);
}
if (!zfs) {
/*
* ZFS shares never have a description
* and we can't store the values so
* don't try.
*/
}
else
protocol);
persist == SA_SHARE_PERMANENT) {
(void) sa_update_legacy(share,
protocol);
}
}
}
err:
ret = SA_LEGACY_ERR;
}
return (ret);
}
/*
* sa_legacy_unshare(flags, argc, argv)
*
* Implements the original unshare command.
*/
int
{
int argsused = 0;
int c;
int true_legacy = 0;
#ifdef lint
#endif
switch (c) {
case 'F':
if (!sa_valid_protocol(protocol)) {
protocol, "unshare") == 0 &&
check_legacy_cmd(cmd)) {
true_legacy++;
} else {
"Invalid file system name\n"));
return (SA_INVALID_PROTOCOL);
}
}
break;
case 'o':
argsused++;
break;
case 'p':
argsused++;
break;
case 'h':
/* optopt on valid arg isn't defined */
optopt = c;
/*FALLTHROUGH*/
case '?':
default:
/*
* Since a bad option gets to here, sort it
* out and return a syntax error return value
* if necessary.
*/
switch (optopt) {
default:
ret = SA_LEGACY_ERR;
break;
case 'h':
case '?':
break;
}
return (ret);
}
}
/* Have the info so construct what is needed */
ret = SA_SYNTAX_ERR;
} else {
if (true_legacy) {
return (ret);
}
/*
* Find the path in the internal configuration. If it
* isn't found, attempt to resolve the path via
* realpath() and try again.
*/
} else {
}
}
/* Could be a resource name so check that next */
if (features & SA_FEATURE_RESOURCE)
(void) sa_disable_resource(resource,
protocol);
if (persist == SA_SHARE_PERMANENT) {
}
/*
* If we still have a resource on the
* share, we don't disable the share
* itself. IF there aren't anymore, we
* need to remove the share. The
* removal will be done in the next
* section if appropriate.
*/
/* Didn't find path and no resource */
ret = SA_BAD_PATH;
}
}
/*
* Errors are ok and removal should still occur. The
* legacy unshare is more forgiving of errors than the
* remove-share subcommand which may need the force
* flag set for some error conditions. That is, the
* "unshare" command will always unshare if it can
* while "remove-share" might require the force option.
*/
if (persist == SA_SHARE_PERMANENT) {
}
/*
* If both share and resource are NULL, then
* share not found. If one or the other was
* found or there was an earlier error, we
* assume it was handled earlier.
*/
ret = SA_NOT_SHARED;
}
}
switch (ret) {
default:
ret = SA_LEGACY_ERR;
break;
case SA_SYNTAX_ERR:
break;
case SA_OK:
break;
}
return (ret);
}
/*
* Common commands that implement the sub-commands used by all
* protocols. The entries are found via the lookup command
*/
};
static char *
{
switch (index) {
case USAGE_ADD_SHARE:
"[-d \"description text\"] -s sharepath group");
break;
case USAGE_CREATE:
"create [-nvh] [-P proto [-p property=value]] group");
break;
case USAGE_DELETE:
break;
case USAGE_DISABLE:
break;
case USAGE_ENABLE:
break;
case USAGE_LIST:
break;
case USAGE_MOVE_SHARE:
"move-share [-nvh] -s sharepath destination-group");
break;
case USAGE_REMOVE_SHARE:
"remove-share [-fnvh] {-s sharepath | -r resource} "
"group");
break;
case USAGE_SET:
"[-p property=value]* [-s sharepath] [-r resource]] "
"group");
break;
case USAGE_SET_SECURITY:
"[-p property=value]* group");
break;
case USAGE_SET_SHARE:
"[-d \"description text\"] -s sharepath group");
break;
case USAGE_SHOW:
break;
case USAGE_SHARE:
"[-d description] [pathname [resourcename]]");
break;
case USAGE_START:
break;
case USAGE_STOP:
break;
case USAGE_UNSET:
"[-p property]* group");
break;
case USAGE_UNSET_SECURITY:
"-S security-type [-p property]* group");
break;
case USAGE_UNSHARE:
"unshare [-F fstype] [-p] [-o optionlist] sharepath");
break;
}
return (ret);
}
/*
* sa_lookup(cmd, proto)
*
* Lookup the sub-command. proto isn't currently used, but it may
* eventually provide a way to provide protocol specific sub-commands.
*/
{
int i;
#ifdef lint
#endif
return (&commands[i]);
}
return (NULL);
}
void
{
int i;
#ifdef lint
#endif
(void) printf("\t%s\n",
}
}