commands.c revision 25a68471b9ababbc21cfdbbb2866014f34f419ec
6185db853e024a486ff8837e6784dd290d866112dougm * CDDL HEADER START
6185db853e024a486ff8837e6784dd290d866112dougm * The contents of this file are subject to the terms of the
6185db853e024a486ff8837e6784dd290d866112dougm * Common Development and Distribution License (the "License").
6185db853e024a486ff8837e6784dd290d866112dougm * You may not use this file except in compliance with the License.
6185db853e024a486ff8837e6784dd290d866112dougm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
6185db853e024a486ff8837e6784dd290d866112dougm * See the License for the specific language governing permissions
6185db853e024a486ff8837e6784dd290d866112dougm * and limitations under the License.
6185db853e024a486ff8837e6784dd290d866112dougm * When distributing Covered Code, include this CDDL HEADER in each
6185db853e024a486ff8837e6784dd290d866112dougm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
6185db853e024a486ff8837e6784dd290d866112dougm * If applicable, add the following below this CDDL HEADER, with the
6185db853e024a486ff8837e6784dd290d866112dougm * fields enclosed by brackets "[]" replaced with your own identifying
6185db853e024a486ff8837e6784dd290d866112dougm * information: Portions Copyright [yyyy] [name of copyright owner]
6185db853e024a486ff8837e6784dd290d866112dougm * CDDL HEADER END
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
6185db853e024a486ff8837e6784dd290d866112dougm * Use is subject to license terms.
6185db853e024a486ff8837e6784dd290d866112dougm#pragma ident "%Z%%M% %I% %E% SMI"
6185db853e024a486ff8837e6784dd290d866112dougm * Implementation of the common sub-commands supported by sharemgr.
6185db853e024a486ff8837e6784dd290d866112dougm * A number of helper functions are also included.
6185db853e024a486ff8837e6784dd290d866112dougm * has_protocol(group, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * If the group has an optionset with the specified protocol,
6185db853e024a486ff8837e6784dd290d866112dougm * return true (1) otherwise false (0).
6185db853e024a486ff8837e6784dd290d866112dougm * add_list(list, item)
6185db853e024a486ff8837e6784dd290d866112dougm * Adds a new list member that points to item to the list.
6185db853e024a486ff8837e6784dd290d866112dougm * If list is NULL, it starts a new list. The function returns
6185db853e024a486ff8837e6784dd290d866112dougm * the first member of the list.
6185db853e024a486ff8837e6784dd290d866112dougm for (tmp = listp; tmp->next != NULL; tmp = tmp->next) {
6185db853e024a486ff8837e6784dd290d866112dougm /* get to end of list */
6185db853e024a486ff8837e6784dd290d866112dougm * free_list(list)
6185db853e024a486ff8837e6784dd290d866112dougm * Given a list, free all the members of the list;
6185db853e024a486ff8837e6784dd290d866112dougm * check_authorization(instname, which)
6185db853e024a486ff8837e6784dd290d866112dougm * Checks to see if the specific type of authorization in which is
6185db853e024a486ff8837e6784dd290d866112dougm * enabled for the user in this SMF service instance.
6185db853e024a486ff8837e6784dd290d866112dougm char svcstring[SA_MAX_NAME_LEN + sizeof (SA_SVC_FMRI_BASE) + 1];
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Since names are restricted to SA_MAX_NAME_LEN won't
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * overflow.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) snprintf(svcstring, sizeof (svcstring), "%s:%s",
6185db853e024a486ff8837e6784dd290d866112dougm /* make sure we have an authorization string property */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* check if this user has one of the strings */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* no authorization string defined */
6185db853e024a486ff8837e6784dd290d866112dougm * check_authorizations(instname, flags)
6185db853e024a486ff8837e6784dd290d866112dougm * check all the needed authorizations for the user in this service
6185db853e024a486ff8837e6784dd290d866112dougm * instance. Return value of 1(true) or 0(false) indicates whether
6185db853e024a486ff8837e6784dd290d866112dougm * there are authorizations for the user or not.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* if not flags set, we assume we don't need authorizations */
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * enable_group(group, updateproto)
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * enable all the shares in the specified group. This is a helper for
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * enable_all_groups in order to simplify regular and subgroup (zfs)
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * disabling. Group has already been checked for non-NULL.
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * isenabled(group)
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * Returns B_TRUE if the group is enabled or B_FALSE if it isn't.
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * Moved to separate function to reduce clutter in the code.
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * enable_all_groups(list, setstate, online, updateproto)
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * Given a list of groups, enable each one found. If updateproto
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * is not NULL, then update all the shares for the protocol that
7d968cb8b4b6274092771b93e94bf88d1ee31c6cdougm * was passed in.
549ec3fff108310966327d1dc9004551b63210b7dougmenable_all_groups(sa_handle_t handle, struct list *work, int setstate,
6185db853e024a486ff8837e6784dd290d866112dougm char instance[SA_MAX_NAME_LEN + sizeof (SA_SVC_FMRI_BASE) + 1];
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * If setstate == TRUE, then make sure to set
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * enabled. This needs to be done here in order for
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * the isenabled check to succeed on a newly enabled
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * Check to see if group is enabled. If it isn't, skip
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * the rest. We don't want shares starting if the
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * group is disabled. The properties may have been
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * updated, but there won't be a change until the
330ef417fbd2286149a25e8033587edf7ae52ae5dougm * group is enabled.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* if itemdata != NULL then a single share */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = sa_enable_share((sa_share_t)work->itemdata, NULL);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* if itemdata == NULL then the whole group */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * if the share is managed by ZFS, don't
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * update any of the protocols since ZFS is
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * handling this. updateproto will contain
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * the name of the protocol that we want to
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * update legacy files for.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm enable_group(group, zfs == NULL ? updateproto : NULL);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* never update legacy for ZFS subgroups */
6185db853e024a486ff8837e6784dd290d866112dougm * chk_opt(optlistp, security, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Do a sanity check on the optlist provided for the protocol. This
6185db853e024a486ff8837e6784dd290d866112dougm * is a syntax check and verification that the property is either a
6185db853e024a486ff8837e6784dd290d866112dougm * general or specific to a names optionset.
6185db853e024a486ff8837e6784dd290d866112dougmchk_opt(struct options *optlistp, int security, char *proto)
6185db853e024a486ff8837e6784dd290d866112dougm for (optlist = optlistp; optlist != NULL; optlist = optlist->next) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* extract property/value pair */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (ret) {
6185db853e024a486ff8837e6784dd290d866112dougm * free_opt(optlist)
6185db853e024a486ff8837e6784dd290d866112dougm * Free the specified option list.
6185db853e024a486ff8837e6784dd290d866112dougm * check property list for valid properties
6185db853e024a486ff8837e6784dd290d866112dougm * A null value is a remove which is always valid.
6185db853e024a486ff8837e6784dd290d866112dougmvalid_options(struct options *optlist, char *proto, void *object, char *sec)
6185db853e024a486ff8837e6784dd290d866112dougm prop = sa_create_property(cur->optname, cur->optvalue);
6185db853e024a486ff8837e6784dd290d866112dougm (ret = sa_valid_property(parent, proto, prop)) != SA_OK) {
6185db853e024a486ff8837e6784dd290d866112dougm * add_optionset(group, optlist, protocol, *err)
6185db853e024a486ff8837e6784dd290d866112dougm * Add the options in optlist to an optionset and then add the optionset
6185db853e024a486ff8837e6784dd290d866112dougm * to the group.
6185db853e024a486ff8837e6784dd290d866112dougm * The return value indicates if there was a "change" while errors are
6185db853e024a486ff8837e6784dd290d866112dougm * returned via the *err parameters.
6185db853e024a486ff8837e6784dd290d866112dougmadd_optionset(sa_group_t group, struct options *optlist, char *proto, int *err)
6185db853e024a486ff8837e6784dd290d866112dougm * add the property, but only if it is
6185db853e024a486ff8837e6784dd290d866112dougm * a non-NULL or non-zero length value
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "not add property "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "%s: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not add property "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "%s: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* there was a change */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* should check to see if value changed */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_create(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * create a new group
6185db853e024a486ff8837e6784dd290d866112dougm * this may or may not have a protocol associated with it.
6185db853e024a486ff8837e6784dd290d866112dougm * No protocol means "all" protocols in this case.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_create(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (ret) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Property syntax error for property: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Security properties need "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "to be set with set-security: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\tgroup must be specified.\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\textraneous group(s) at end\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* lookup default protocol */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "with properties\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "supported with create\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * If a group already exists, we can only add a new protocol
6185db853e024a486ff8837e6784dd290d866112dougm * to it and not create a new one or add the same protocol
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* group exists so must be a protocol add */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Group \"%s\" already exists"
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* must add new protocol */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Group already exists and no protocol "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "specified.\n"));
6185db853e024a486ff8837e6784dd290d866112dougm * is it a valid name? Must comply with SMF instance
6185db853e024a486ff8837e6784dd290d866112dougm * name restrictions.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* check protocol vs optlist */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* check options, if any, for validity */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm for (i = 0; i < numprotos; i++) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We have a group and legal additions
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Commit to configuration for protocols that
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * need to do block updates. For NFS, this
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * doesn't do anything but it will be run for
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * all protocols that implement the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * appropriate plugin.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Could not create group: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * group_status(group)
6185db853e024a486ff8837e6784dd290d866112dougm * return the current status (enabled/disabled) of the group.
6185db853e024a486ff8837e6784dd290d866112dougmstatic char *
6185db853e024a486ff8837e6784dd290d866112dougm * sa_delete(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Delete a group.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_delete(sa_handle_t handle, int flags, int argc, char *argv[])
6185db853e024a486ff8837e6784dd290d866112dougm while ((c = getopt(argc, argv, "?hvnP:fS:")) != EOF) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\tgroup must be specified.\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\textraneous group(s) at end\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\tsecurity requires protocol to be "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "specified.\n"));
6185db853e024a486ff8837e6784dd290d866112dougm * Determine if the group already exists since it must in
6185db853e024a486ff8837e6784dd290d866112dougm * order to be removed.
6185db853e024a486ff8837e6784dd290d866112dougm * We can delete when:
6185db853e024a486ff8837e6784dd290d866112dougm * - group is empty
6185db853e024a486ff8837e6784dd290d866112dougm * - force flag is set
6185db853e024a486ff8837e6784dd290d866112dougm * - if protocol specified, only delete the protocol
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * need to do the disable of
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * each share, but don't
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * actually do anything on a
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Commit to configuration if not a dryrun */
6185db853e024a486ff8837e6784dd290d866112dougm /* a protocol delete */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* only delete specified security */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * have an optionset with
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * protocol to delete
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Now find all security sets
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * for the protocol and remove
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * them. Don't remove other
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * protocols.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Could not delete group: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * strndupr(*buff, str, buffsize)
6185db853e024a486ff8837e6784dd290d866112dougm * used with small strings to duplicate and possibly increase the
6185db853e024a486ff8837e6784dd290d866112dougm * buffer size of a string.
6185db853e024a486ff8837e6784dd290d866112dougmstatic char *
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* if it fails, fail it hard */
6185db853e024a486ff8837e6784dd290d866112dougm * group_proto(group)
6185db853e024a486ff8837e6784dd290d866112dougm * return a string of all the protocols (space separated) associated
6185db853e024a486ff8837e6784dd290d866112dougm * with this group.
6185db853e024a486ff8837e6784dd290d866112dougmstatic char *
6185db853e024a486ff8837e6784dd290d866112dougm * get the protocol list by finding the optionsets on this
6185db853e024a486ff8837e6784dd290d866112dougm * group and extracting the type value. The initial call to
6185db853e024a486ff8837e6784dd290d866112dougm * strndupr() initailizes buff.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * extract out the protocol type from this optionset
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * and append it to the buffer "buff". strndupr() will
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * reallocate space as necessay.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_list(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * implements the "list" subcommand to list groups and optionally
6185db853e024a486ff8837e6784dd290d866112dougm * their state and protocols.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
549ec3fff108310966327d1dc9004551b63210b7dougmsa_list(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (protocol == NULL || has_protocol(group, protocol)) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (name != NULL && (verbose > 1 || name[0] != '#')) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Need the list of protocols
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * and current status once
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * available. We do want to
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * translate the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * enabled/disabled text here.
6185db853e024a486ff8837e6784dd290d866112dougm return (0);
6185db853e024a486ff8837e6784dd290d866112dougm * out_properties(optionset, proto, sec)
6185db853e024a486ff8837e6784dd290d866112dougm * Format the properties and encode the protocol and optional named
6185db853e024a486ff8837e6784dd290d866112dougm * optionset into the string.
6185db853e024a486ff8837e6784dd290d866112dougm * format is protocol[:name]=(property-list)
6185db853e024a486ff8837e6784dd290d866112dougmout_properties(sa_optionset_t optionset, char *proto, char *sec)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(" %s=(", proto ? proto : gettext("all"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(" %s:%s=(", proto ? proto : gettext("all"), sec);
6185db853e024a486ff8837e6784dd290d866112dougm for (spacer = 0, prop = sa_get_property(optionset, NULL);
6185db853e024a486ff8837e6784dd290d866112dougm * extract the property name/value and output with
6185db853e024a486ff8837e6784dd290d866112dougm * appropriate spacing. I.e. no prefixed space the
6185db853e024a486ff8837e6784dd290d866112dougm * first time through but a space on subsequent
6185db853e024a486ff8837e6784dd290d866112dougm * properties.
6185db853e024a486ff8837e6784dd290d866112dougm * show_properties(group, protocol, prefix)
6185db853e024a486ff8837e6784dd290d866112dougm * print the properties for a group. If protocol is NULL, do all
6185db853e024a486ff8837e6784dd290d866112dougm * protocols otherwise only the specified protocol. All security
6185db853e024a486ff8837e6784dd290d866112dougm * (named groups specific to the protocol) are included.
6185db853e024a486ff8837e6784dd290d866112dougm * The "prefix" is always applied. The caller knows whether it wants
6185db853e024a486ff8837e6784dd290d866112dougm * some type of prefix string (white space) or not. Once the prefix
6185db853e024a486ff8837e6784dd290d866112dougm * has been output, it is reduced to the zero length string for the
6185db853e024a486ff8837e6784dd290d866112dougm * remainder of the property output.
6185db853e024a486ff8837e6784dd290d866112dougmshow_properties(sa_group_t group, char *protocol, char *prefix)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm for (security = sa_get_security(group, NULL, protocol);
6185db853e024a486ff8837e6784dd290d866112dougm * show_group(group, verbose, properties, proto, subgroup)
6185db853e024a486ff8837e6784dd290d866112dougm * helper function to show the contents of a group.
6185db853e024a486ff8837e6784dd290d866112dougmshow_group(sa_group_t group, int verbose, int properties, char *proto,
6185db853e024a486ff8837e6784dd290d866112dougm * check to see if the group is managed by ZFS. If
6185db853e024a486ff8837e6784dd290d866112dougm * there is an attribute, then it is. A non-NULL zfs
6185db853e024a486ff8837e6784dd290d866112dougm * variable will trigger the different way to display
6185db853e024a486ff8837e6784dd290d866112dougm * and will remove the transient property indicator
6185db853e024a486ff8837e6784dd290d866112dougm * from the output.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Have a group, so list the contents. Resource and
6185db853e024a486ff8837e6784dd290d866112dougm * description are only listed if verbose is set.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "resource");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\t\"%s\"",
6185db853e024a486ff8837e6784dd290d866112dougm * show_group_xml_init()
6185db853e024a486ff8837e6784dd290d866112dougm * Create an XML document that will be used to display config info via
6185db853e024a486ff8837e6784dd290d866112dougm * XML format.
6185db853e024a486ff8837e6784dd290d866112dougm * show_group_xml(doc, group)
6185db853e024a486ff8837e6784dd290d866112dougm * Copy the group info into the XML doc.
6185db853e024a486ff8837e6784dd290d866112dougm * In the future, we may have interally used tags that
6185db853e024a486ff8837e6784dd290d866112dougm * should not appear in the XML output. Remove
6185db853e024a486ff8837e6784dd290d866112dougm * anything we don't want to show here.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_show(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the show subcommand.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
549ec3fff108310966327d1dc9004551b63210b7dougmsa_show(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* No group specified so go through them all */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Have a group so check if one we want and then list
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * contents with appropriate options.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Have a specified list of groups */
6185db853e024a486ff8837e6784dd290d866112dougm * enable_share(group, share, update_legacy)
6185db853e024a486ff8837e6784dd290d866112dougm * helper function to enable a share if the group is enabled.
549ec3fff108310966327d1dc9004551b63210b7dougmenable_share(sa_handle_t handle, sa_group_t group, sa_share_t share,
6185db853e024a486ff8837e6784dd290d866112dougm * need to enable this share if the group is enabled but not
6185db853e024a486ff8837e6784dd290d866112dougm * otherwise. The enable is also done on each protocol
6185db853e024a486ff8837e6784dd290d866112dougm * represented in the group.
6185db853e024a486ff8837e6784dd290d866112dougm enabled = value != NULL && strcmp(value, "enabled") == 0;
6185db853e024a486ff8837e6784dd290d866112dougm /* remove legacy config if necessary */
6185db853e024a486ff8837e6784dd290d866112dougm * Step through each optionset at the group level and
6185db853e024a486ff8837e6784dd290d866112dougm * enable the share based on the protocol type. This
6185db853e024a486ff8837e6784dd290d866112dougm * works because protocols must be set on the group
6185db853e024a486ff8837e6784dd290d866112dougm * for the protocol to be enabled.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_addshare(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * implements add-share subcommand.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_addshare(sa_handle_t handle, int flags, int argc, char *argv[])
6185db853e024a486ff8837e6784dd290d866112dougm int persist = SA_SHARE_PERMANENT; /* default to persist */
6185db853e024a486ff8837e6784dd290d866112dougm while ((c = getopt(argc, argv, "?hvns:d:r:t")) != EOF) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Save share path into group. Currently limit
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * to one share per command.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Adding multiple shares not supported\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (1);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (dryrun || sharepath != NULL || description != NULL ||
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\tgroup must be specified\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\t-s sharepath must be specified\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Check for valid syntax */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (resource != NULL && strpbrk(resource, " \t/") != NULL) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\tresource must not contain white"
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "space or '/' characters\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share path already "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "shared in group "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\"%s\": %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share path already"
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "shared: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share path %s already shared\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Need to check that resource name is
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * unique at some point. Path checking
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * should use the "normal" rules which
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * don't check the repository.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not add share: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Now enable the share(s) */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (ret) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Resource name in"
6185db853e024a486ff8837e6784dd290d866112dougm "attribute: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Command would fail: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * sa_moveshare(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * implements move-share subcommand.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_moveshare(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Remove share path from group. Currently limit
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * to one share per command.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "not supported\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\tgroup must be specified\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\tsharepath must be specified\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "sharepath must be specified with the -s "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "option\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Note that the share may need to be
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * "unshared" if the new group is
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * disabled and the old was enabled or
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * it may need to be share to update
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * if the new group is enabled.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* enable_share determines what to do */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_removeshare(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * implements remove-share subcommand.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_removeshare(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Remove share path from group. Currently limit
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * to one share per command.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Removing multiple shares not "
6185db853e024a486ff8837e6784dd290d866112dougm "supported\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "\t-s sharepath must be specified\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Extraneous group(s) at end of "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "command\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Lookup the path in the internal configuration. Care
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * must be taken to handle the case where the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * underlying path has been removed since we need to
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * be able to deal with that as well.
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * If we didn't find the share with the provided path,
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * it may be a symlink so attempt to resolve it using
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * realpath and try again. Realpath will resolve any
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * symlinks and place them in "dir". Note that
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * sharepath is only used for the lookup the first
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * time and later for error messages. dir will be used
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * on the second attempt. Once a share is found, all
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * operations are based off of the share variable.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * If there hasn't been an error, there was likely a
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * path found. If not, give the appropriate error
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * message and set the return error. If it was found,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * then disable the share and then remove it from the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * configuration.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We don't care if it fails since it
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * could be disabled already. Some
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * unexpected errors could occur that
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * prevent removal, so also check for
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * force being set.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not remove share: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Command would fail: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_share(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * implements set-share subcommand.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_set_share(sa_handle_t handle, int flags, int argc, char *argv[])
6185db853e024a486ff8837e6784dd290d866112dougm while ((c = getopt(argc, argv, "?hnd:r:s:")) != EOF) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Save share path into group. Currently limit
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * to one share per command.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Updating multiple shares not "
6185db853e024a486ff8837e6784dd290d866112dougm "supported\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\tgroup must be specified\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("\tExtraneous group(s) at end\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Share path \"%s\" not found\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Group \"%s\" does not contain "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "contain white space or '/'\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (ret) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Resource name in use: %s\n"), resource);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Could not set attribute: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * add_security(group, sectype, optlist, proto, *err)
6185db853e024a486ff8837e6784dd290d866112dougm * Helper function to add a security option (named optionset) to the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Add the property, but only if it is
6185db853e024a486ff8837e6784dd290d866112dougm * a non-NULL or non-zero length value
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not add "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "property %s: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not add "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "property (%s=%s): "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * When done, properties may have all been removed but
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * we need to keep the security type itself until
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * explicitly removed.
6185db853e024a486ff8837e6784dd290d866112dougm * basic_set(groupname, optlist, protocol, sharepath, dryrun)
6185db853e024a486ff8837e6784dd290d866112dougm * This function implements "set" when a name space (-S) is not
6185db853e024a486ff8837e6784dd290d866112dougm * specified. It is a basic set. Options and other CLI parsing has
6185db853e024a486ff8837e6784dd290d866112dougm * already been done.
549ec3fff108310966327d1dc9004551b63210b7dougmbasic_set(sa_handle_t handle, char *groupname, struct options *optlist,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share does not exist in group %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* group must exist */
6185db853e024a486ff8837e6784dd290d866112dougm (void) printf(gettext("Group \"%s\" not found\n"), groupname);
6185db853e024a486ff8837e6784dd290d866112dougm * we have a group and potentially legal additions
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Commit to configuration if not a dryrunp and properties
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * have changed.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (!dryrun && ret == SA_OK && change && worklist != NULL)
6185db853e024a486ff8837e6784dd290d866112dougm /* properties changed, so update all shares */
549ec3fff108310966327d1dc9004551b63210b7dougm (void) enable_all_groups(handle, worklist, 0, 0, protocol);
6185db853e024a486ff8837e6784dd290d866112dougm * space_set(groupname, optlist, protocol, sharepath, dryrun)
6185db853e024a486ff8837e6784dd290d866112dougm * This function implements "set" when a name space (-S) is
6185db853e024a486ff8837e6784dd290d866112dougm * specified. It is a namespace set. Options and other CLI parsing has
6185db853e024a486ff8837e6784dd290d866112dougm * already been done.
549ec3fff108310966327d1dc9004551b63210b7dougmspace_set(sa_handle_t handle, char *groupname, struct options *optlist,
549ec3fff108310966327d1dc9004551b63210b7dougm char *protocol, char *sharepath, int dryrun, char *sectype)
6185db853e024a486ff8837e6784dd290d866112dougm * make sure protcol and sectype are valid
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Option space \"%s\" not valid "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share does not exist in group %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* group must exist */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not set property: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm (void) printf(gettext("Group \"%s\" not found\n"), groupname);
6185db853e024a486ff8837e6784dd290d866112dougm * we have a group and potentially legal additions
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Commit to configuration if not a dryrun */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* properties changed, so update all shares */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the set subcommand. It keys off of -S to determine which
6185db853e024a486ff8837e6784dd290d866112dougm * set of operations to actually do.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_set(sa_handle_t handle, int flags, int argc, char *argv[])
6185db853e024a486ff8837e6784dd290d866112dougm while ((c = getopt(argc, argv, "?hvnP:p:s:S:")) != EOF) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (ret) {
6185db853e024a486ff8837e6784dd290d866112dougm if (optind >= argc || (optlist == NULL && optset == NULL) ||
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("usage: %s\n"), sa_get_usage(USAGE_SET));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("%sat least one property must be"
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("%sprotocol must be specified"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * If a group already exists, we can only add a new
6185db853e024a486ff8837e6784dd290d866112dougm * protocol to it and not create a new one or add the
6185db853e024a486ff8837e6784dd290d866112dougm * same protocol again.
6185db853e024a486ff8837e6784dd290d866112dougm * remove_options(group, optlist, proto, *err)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Helper function to actually remove options from a group after all
6185db853e024a486ff8837e6784dd290d866112dougm * preprocessing is done.
6185db853e024a486ff8837e6784dd290d866112dougmremove_options(sa_group_t group, struct options *optlist,
6185db853e024a486ff8837e6784dd290d866112dougm * valid_unset(group, optlist, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Sanity check the optlist to make sure they can be removed. Issue an
6185db853e024a486ff8837e6784dd290d866112dougm * error if a property doesn't exist.
6185db853e024a486ff8837e6784dd290d866112dougmvalid_unset(sa_group_t group, struct options *optlist, char *proto)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not unset property %s: not set\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * valid_unset_security(group, optlist, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Sanity check the optlist to make sure they can be removed. Issue an
6185db853e024a486ff8837e6784dd290d866112dougm * error if a property doesn't exist.
6185db853e024a486ff8837e6784dd290d866112dougmvalid_unset_security(sa_group_t group, struct options *optlist, char *proto,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not unset property %s: not set\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * remove_security(group, optlist, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Remove the properties since they were checked as valid.
6185db853e024a486ff8837e6784dd290d866112dougm * when done, properties may have all been removed but
6185db853e024a486ff8837e6784dd290d866112dougm * we need to keep the security type itself until
6185db853e024a486ff8837e6784dd290d866112dougm * explicitly removed.
6185db853e024a486ff8837e6784dd290d866112dougm * basic_unset(groupname, optlist, protocol, sharepath, dryrun)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Unset non-named optionset properties.
549ec3fff108310966327d1dc9004551b63210b7dougmbasic_unset(sa_handle_t handle, char *groupname, struct options *optlist,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share does not exist in group %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm /* group must exist */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * If a share optionset is
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * empty, remove it.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Could not remove properties: "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We have a group and potentially legal additions
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Commit to configuration if not a dryrun
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* properties changed, so update all shares */
6185db853e024a486ff8837e6784dd290d866112dougm * space_unset(groupname, optlist, protocol, sharepath, dryrun)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Unset named optionset properties.
549ec3fff108310966327d1dc9004551b63210b7dougmspace_unset(sa_handle_t handle, char *groupname, struct options *optlist,
549ec3fff108310966327d1dc9004551b63210b7dougm char *protocol, char *sharepath, int dryrun, char *sectype)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Group \"%s\" not found\n"), groupname);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Share does not exist in group %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = valid_unset_security(share != NULL ? share : group, optlist,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* If a share security is empty, remove it */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Could not unset property: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We have a group and potentially legal additions
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Commit to configuration if not a dryrun */
6185db853e024a486ff8837e6784dd290d866112dougm /* properties changed, so update all shares */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_unset(flags, argc, argv)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Implements the unset subcommand. Parsing done here and then basic
6185db853e024a486ff8837e6784dd290d866112dougm * or space versions of the real code are called.
549ec3fff108310966327d1dc9004551b63210b7dougmsa_unset(sa_handle_t handle, int flags, int argc, char *argv[])
6185db853e024a486ff8837e6784dd290d866112dougm while ((c = getopt(argc, argv, "?hvnP:p:s:S:")) != EOF) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (ret) {
6185db853e024a486ff8837e6784dd290d866112dougm if (optind >= argc || (optlist == NULL && optset == NULL) ||
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("%sprotocol must be specified"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * If a group already exists, we can only add a new
6185db853e024a486ff8837e6784dd290d866112dougm * protocol to it and not create a new one or add the
6185db853e024a486ff8837e6784dd290d866112dougm * same protocol again.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = basic_unset(handle, groupname, optlist, protocol,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = space_unset(handle, groupname, optlist, protocol,
6185db853e024a486ff8837e6784dd290d866112dougm * sa_enable_group(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the enable subcommand
549ec3fff108310966327d1dc9004551b63210b7dougmsa_enable_group(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* already enabled */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Group \"%s\" is already "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "enabled\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Enabling group \"%s\"\n"),
549ec3fff108310966327d1dc9004551b63210b7dougm ret = enable_all_groups(handle, worklist, 1, 0, NULL);
6185db853e024a486ff8837e6784dd290d866112dougm (void) printf(gettext("Could not enable group: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * disable_group(group, setstate)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Disable all the shares in the specified group honoring the setstate
6185db853e024a486ff8837e6784dd290d866112dougm * argument. This is a helper for disable_all_groups in order to
6185db853e024a486ff8837e6784dd290d866112dougm * simplify regular and subgroup (zfs) disabling. Group has already
6185db853e024a486ff8837e6784dd290d866112dougm * been checked for non-NULL.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * this is OK since the path is gone. we can't
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * re-share it anyway so no error.
6185db853e024a486ff8837e6784dd290d866112dougm * disable_all_groups(work, setstate)
6185db853e024a486ff8837e6784dd290d866112dougm * helper function that disables the shares in the list of groups
6185db853e024a486ff8837e6784dd290d866112dougm * provided. It optionally marks the group as disabled. Used by both
6185db853e024a486ff8837e6784dd290d866112dougm * enable and start subcommands.
549ec3fff108310966327d1dc9004551b63210b7dougmdisable_all_groups(sa_handle_t handle, struct list *work, int setstate)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* need to get the sub-groups for stopping */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We don't want to "disable" since it won't come
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * up after a reboot. The SMF framework should do
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * the right thing. On enable we do want to do
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * something.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_disable_group(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the disable subcommand
549ec3fff108310966327d1dc9004551b63210b7dougmsa_disable_group(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* already disabled */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Group \"%s\" is "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "already disabled\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Disabling group "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf(gettext("Could not disable group: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * sa_start_group(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the start command.
6185db853e024a486ff8837e6784dd290d866112dougm * This is similar to enable except it doesn't change the state
6185db853e024a486ff8837e6784dd290d866112dougm * of the group(s) and only enables shares if the group is already
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
549ec3fff108310966327d1dc9004551b63210b7dougmsa_start_group(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Starting group \"%s\"\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Determine if there are any
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * protocols. if there aren't any,
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * then there isn't anything to do in
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * any case so no error.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm for (group = sa_get_group(handle, NULL); group != NULL;
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) enable_all_groups(handle, worklist, 0, 1, NULL);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_stop_group(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the stop command.
6185db853e024a486ff8837e6784dd290d866112dougm * This is similar to disable except it doesn't change the state
6185db853e024a486ff8837e6784dd290d866112dougm * of the group(s) and only disables shares if the group is already
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
549ec3fff108310966327d1dc9004551b63210b7dougmsa_stop_group(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: %s\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (0);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm } else if (!all) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Stopping group \"%s\"\n"),
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm for (group = sa_get_group(handle, NULL); group != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm * remove_all_options(share, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Removes all options on a share.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We walk through the list. prevsec keeps the
6185db853e024a486ff8837e6784dd290d866112dougm * previous security so we can delete it without
6185db853e024a486ff8837e6784dd290d866112dougm * destroying the list.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* remove the previously seen security */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* set to NULL so we don't try multiple times */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * if the security matches the specified protocol, we
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * want to remove it. prevsec holds it until either
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * the next pass or we fall out of the loop.
6185db853e024a486ff8837e6784dd290d866112dougm /* in case there is one left */
6185db853e024a486ff8837e6784dd290d866112dougm * for legacy support, we need to handle the old syntax. This is what
6185db853e024a486ff8837e6784dd290d866112dougm * we get if sharemgr is called with the name "share" rather than
6185db853e024a486ff8837e6784dd290d866112dougm * sharemgr.
6185db853e024a486ff8837e6784dd290d866112dougmformat_legacy_path(char *buff, int buffsize, char *proto, char *cmd)
6185db853e024a486ff8837e6784dd290d866112dougm err = snprintf(buff, buffsize, "/usr/lib/fs/%s/%s", proto, cmd);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (-1);
6185db853e024a486ff8837e6784dd290d866112dougm return (0);
6185db853e024a486ff8837e6784dd290d866112dougm * check_legacy_cmd(proto, cmd)
6185db853e024a486ff8837e6784dd290d866112dougm * Check to see if the cmd exists in /usr/lib/fs/<proto>/<cmd> and is
6185db853e024a486ff8837e6784dd290d866112dougm * executable.
6185db853e024a486ff8837e6784dd290d866112dougm * run_legacy_command(proto, cmd, argv)
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * We know the command exists, so attempt to execute it with all the
6185db853e024a486ff8837e6784dd290d866112dougm * arguments. This implements full legacy share support for those
6185db853e024a486ff8837e6784dd290d866112dougm * protocols that don't have plugin providers.
6185db853e024a486ff8837e6784dd290d866112dougm if (ret < 0) {
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * out_share(out, group, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Display the share information in the format that the "share"
6185db853e024a486ff8837e6784dd290d866112dougm * command has traditionally used.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (groupname != NULL && strcmp(groupname, "default") == 0) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Want the sharetab version if it exists */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* only active shares go here */
6185db853e024a486ff8837e6784dd290d866112dougm * output_legacy_file(out, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Walk all of the groups for the specified protocol and call
6185db853e024a486ff8837e6784dd290d866112dougm * out_share() to format and write in the format displayed by the
6185db853e024a486ff8837e6784dd290d866112dougm * "share" command with no arguments.
549ec3fff108310966327d1dc9004551b63210b7dougmoutput_legacy_file(FILE *out, char *proto, sa_handle_t handle)
549ec3fff108310966327d1dc9004551b63210b7dougm for (group = sa_get_group(handle, NULL); group != NULL;
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Get default options preformated, being careful to
6185db853e024a486ff8837e6784dd290d866112dougm * handle legacy shares differently from new style
6185db853e024a486ff8837e6784dd290d866112dougm * shares. Legacy share have options on the share.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* got a group, so display it */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
549ec3fff108310966327d1dc9004551b63210b7dougmsa_legacy_share(sa_handle_t handle, int flags, int argc, char *argv[])
6185db853e024a486ff8837e6784dd290d866112dougm while ((c = getopt(argc, argv, "?hF:d:o:p")) != EOF) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid protocol specified: "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Have the info so construct what is needed */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* display current info in share format */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* We are modifying the configuration */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* If still using legacy share/unshare, exec it */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * The legacy group is always present and zfs groups
6185db853e024a486ff8837e6784dd290d866112dougm * come and go. zfs shares may be in sub-groups and
6185db853e024a486ff8837e6784dd290d866112dougm * the zfs share will already be in that group so it
6185db853e024a486ff8837e6784dd290d866112dougm * isn't an error.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * If the share exists (not NULL), then make sure it
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * is one we want to handle by getting the parent
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Could be a ZFS path being started
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * This shouldn't
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * May want to change persist state, but the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * important thing is to change options. We
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * need to change them regardless of the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Have a group to hold this share path */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * ZFS shares never have resource or
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * description and we can't store the values
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * so don't try.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) fprintf(stderr, gettext("Could not share: %s: %s\n"),
6185db853e024a486ff8837e6784dd290d866112dougm * sa_legacy_unshare(flags, argc, argv)
6185db853e024a486ff8837e6784dd290d866112dougm * Implements the original unshare command.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
549ec3fff108310966327d1dc9004551b63210b7dougmsa_legacy_unshare(sa_handle_t handle, int flags, int argc, char *argv[])
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm switch (c) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "Invalid file system name\n"));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* Have the info so construct what is needed */
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm if (optind == argc || (optind + 1) < argc || options != NULL) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm /* if still using legacy share/unshare, exec it */
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * Find the path in the internal configuration. If it
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * isn't found, attempt to resolve the path via
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * realpath() and try again.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Errors are ok and removal should still occur. The
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * legacy unshare is more forgiving of errors than the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * remove-share subcommand which may need the force
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * flag set for some error conditions. That is, the
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * "unshare" command will always unshare if it can
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * while "remove-share" might require the force option.
6185db853e024a486ff8837e6784dd290d866112dougm switch (ret) {
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm (void) printf("%s: %s\n", sharepath, sa_errorstr(ret));
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm * Common commands that implement the sub-commands used by all
6185db853e024a486ff8837e6784dd290d866112dougm * protcols. The entries are found via the lookup command
6185db853e024a486ff8837e6784dd290d866112dougm {"add-share", 0, sa_addshare, USAGE_ADD_SHARE, SVC_SET},
6185db853e024a486ff8837e6784dd290d866112dougm {"create", 0, sa_create, USAGE_CREATE, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougm {"delete", 0, sa_delete, USAGE_DELETE, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougm {"disable", 0, sa_disable_group, USAGE_DISABLE, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougm {"enable", 0, sa_enable_group, USAGE_ENABLE, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougm {"move-share", 0, sa_moveshare, USAGE_MOVE_SHARE, SVC_SET},
6185db853e024a486ff8837e6784dd290d866112dougm {"remove-share", 0, sa_removeshare, USAGE_REMOVE_SHARE, SVC_SET},
6185db853e024a486ff8837e6784dd290d866112dougm {"set-share", 0, sa_set_share, USAGE_SET_SHARE, SVC_SET},
6185db853e024a486ff8837e6784dd290d866112dougm {"share", 0, sa_legacy_share, USAGE_SHARE, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougm {"stop", CMD_NODISPLAY, sa_stop_group, USAGE_STOP, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougm {"unshare", 0, sa_legacy_unshare, USAGE_UNSHARE, SVC_SET|SVC_ACTION},
6185db853e024a486ff8837e6784dd290d866112dougmstatic char *
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "[-d \"description text\"] -s sharepath group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "create [-nvh] [-P proto [-p property=value]] group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "move-share [-nvh] -s sharepath destination-group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = gettext("remove-share [-fnvh] -s sharepath group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "[-p property=value]* [-s sharepath] group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = gettext("set-security [-nvh] -P proto -S security-type "
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "[-p property=value]* group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "[-d \"description text\"] -s sharepath group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = gettext("share [-F fstype] [-p] [-o optionlist]"
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "[-d description] [pathname [resourcename]]");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = gettext("start [-vh] [-P proto] {-a | group ...}");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = gettext("stop [-vh] [-P proto] {-a | group ...}");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "[-p property]* group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm ret = gettext("unset-security [-nvh] -P proto -S security-type"
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm " [-p property]* group");
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm "unshare [-F fstype] [-p] sharepath");
6185db853e024a486ff8837e6784dd290d866112dougm * sa_lookup(cmd, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Lookup the sub-command. proto isn't currently used, but it may
6185db853e024a486ff8837e6784dd290d866112dougm * eventually provide a way to provide protocol specific sub-commands.
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm return (&commands[i]);
25a68471b9ababbc21cfdbbb2866014f34f419ecdougm/*ARGSUSED*/