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
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
6185db853e024a486ff8837e6784dd290d866112dougm * Share control API
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * internal object type values returned by sa_get_object_type()
6185db853e024a486ff8837e6784dd290d866112dougm * internal data structures
6185db853e024a486ff8837e6784dd290d866112dougm/* current SMF/SVC repository handle */
549ec3fff108310966327d1dc9004551b63210b7dougmextern void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
549ec3fff108310966327d1dc9004551b63210b7dougmextern int gettransients(sa_handle_impl_t, xmlNodePtr *);
6185db853e024a486ff8837e6784dd290d866112dougmextern char *sa_fstype(char *);
6185db853e024a486ff8837e6784dd290d866112dougmextern int sa_is_share(void *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern int sa_is_resource(void *);
6185db853e024a486ff8837e6784dd290d866112dougmextern ssize_t scf_max_name_len; /* defined in scfutil during initialization */
6185db853e024a486ff8837e6784dd290d866112dougmextern int sa_path_is_zfs(char *);
6185db853e024a486ff8837e6784dd290d866112dougmextern int sa_zfs_set_sharenfs(sa_group_t, char *, int);
6185db853e024a486ff8837e6784dd290d866112dougmextern int issubdir(char *, char *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic sa_group_t sa_get_optionset_parent(sa_optionset_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *get_node_attr(void *, char *);
549ec3fff108310966327d1dc9004551b63210b7dougm * Data structures for finding/managing the document root to access
549ec3fff108310966327d1dc9004551b63210b7dougm * handle mapping. The list isn't expected to grow very large so a
549ec3fff108310966327d1dc9004551b63210b7dougm * simple list is acceptable. The purpose is to provide a way to start
549ec3fff108310966327d1dc9004551b63210b7dougm * with a group or share and find the library handle needed for
549ec3fff108310966327d1dc9004551b63210b7dougm * various operations.
57b448de658d89a2c88a001d58073c46ed2180f3dougm/* definitions used in a couple of property functions */
6185db853e024a486ff8837e6784dd290d866112dougm/* helper functions */
549ec3fff108310966327d1dc9004551b63210b7dougm * sa_errorstr(err)
549ec3fff108310966327d1dc9004551b63210b7dougm * convert an error value to an error string
6185db853e024a486ff8837e6784dd290d866112dougm switch (err) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = dgettext(TEXT_DOMAIN, "security type not found");
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = dgettext(TEXT_DOMAIN, "property value conflict");
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = dgettext(TEXT_DOMAIN, "operation not supported");
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = dgettext(TEXT_DOMAIN, "property not valid for group");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = dgettext(TEXT_DOMAIN, "errors from multiple protocols");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = dgettext(TEXT_DOMAIN, "path is a subpath of share");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = dgettext(TEXT_DOMAIN, "path is parent of a share");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = dgettext(TEXT_DOMAIN, "protocol requires a section");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = dgettext(TEXT_DOMAIN, "properties not found");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = dgettext(TEXT_DOMAIN, "passwords must be encrypted");
0616fd7f2fe52dfe4b6189a7f510069a5b2aed73Pavel Filipensky ret = dgettext(TEXT_DOMAIN, "path or file is already shared");
549ec3fff108310966327d1dc9004551b63210b7dougm * Document root to active handle mapping functions. These are only
549ec3fff108310966327d1dc9004551b63210b7dougm * used internally. A mutex is used to prevent access while the list
549ec3fff108310966327d1dc9004551b63210b7dougm * is changing. In general, the list will be relatively short - one
549ec3fff108310966327d1dc9004551b63210b7dougm * item per thread that has called sa_init().
549ec3fff108310966327d1dc9004551b63210b7dougm for (item = sa_global_handles; item != NULL; item = item->next) {
549ec3fff108310966327d1dc9004551b63210b7dougmadd_handle_for_root(xmlNodePtr root, sa_handle_impl_t handle)
549ec3fff108310966327d1dc9004551b63210b7dougm item = (struct doc2handle *)calloc(sizeof (struct doc2handle), 1);
549ec3fff108310966327d1dc9004551b63210b7dougm * remove_handle_for_root(root)
549ec3fff108310966327d1dc9004551b63210b7dougm * Walks the list of handles and removes the one for this "root" from
549ec3fff108310966327d1dc9004551b63210b7dougm * the list. It is up to the caller to free the data.
549ec3fff108310966327d1dc9004551b63210b7dougm for (prev = NULL, item = sa_global_handles; item != NULL;
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* first in the list */
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* Item is out of the list so free the list structure */
549ec3fff108310966327d1dc9004551b63210b7dougm * sa_find_group_handle(sa_group_t group)
549ec3fff108310966327d1dc9004551b63210b7dougm * Find the sa_handle_t for the configuration associated with this
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* have the root so get the handle */
6185db853e024a486ff8837e6784dd290d866112dougm * set_legacy_timestamp(root, path, timevalue)
6185db853e024a486ff8837e6784dd290d866112dougm * add the current timestamp value to the configuration for use in
6185db853e024a486ff8837e6784dd290d866112dougm * determining when to update the legacy files. For SMF, this
6185db853e024a486ff8837e6784dd290d866112dougm * property is kept in default/operation/legacy_timestamp
6185db853e024a486ff8837e6784dd290d866112dougmset_legacy_timestamp(xmlNodePtr root, char *path, uint64_t tval)
549ec3fff108310966327d1dc9004551b63210b7dougm /* Have to have a handle or else we weren't initialized. */
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (xmlStrcmp(node->name, (xmlChar *)"legacy") == 0) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* a possible legacy node for this path */
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* need to create the first legacy timestamp node */
57b448de658d89a2c88a001d58073c46ed2180f3dougm node = xmlNewChild(root, NULL, (xmlChar *)"legacy", NULL);
57b448de658d89a2c88a001d58073c46ed2180f3dougm (void) snprintf(tstring, sizeof (tstring), "%lld", tval);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(node, (xmlChar *)"path", (xmlChar *)path);
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* now commit to SMF */
57b448de658d89a2c88a001d58073c46ed2180f3dougm "operation");
6185db853e024a486ff8837e6784dd290d866112dougm * is_shared(share)
6185db853e024a486ff8837e6784dd290d866112dougm * determine if the specified share is currently shared or not.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * excluded_protocol(share, proto)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns B_TRUE if the specified protocol appears in the "exclude"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * property. This is used to prevent sharing special case shares
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (e.g. subdirs when SMB wants a subdir and NFS doesn't. B_FALSE is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * returned if the protocol isn't in the list.
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * checksubdirgroup(group, newpath, strictness)
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * check all the specified newpath against all the paths in the
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * group. This is a helper function for checksubdir to make it easier
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * to also check ZFS subgroups.
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * The strictness values mean:
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * SA_CHECK_NORMAL == only check newpath against shares that are active
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * SA_CHECK_STRICT == check newpath against both active shares and those
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * stored in the repository
a99982a76d4cc12b1e9021e88531cf425d1e7369dougmchecksubdirgroup(sa_group_t group, char *newpath, int strictness)
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm for (share = sa_get_share(group, NULL); share != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm * The original behavior of share never checked
6185db853e024a486ff8837e6784dd290d866112dougm * against the permanent configuration
6185db853e024a486ff8837e6784dd290d866112dougm * (/etc/dfs/dfstab). PIT has a number of cases where
6185db853e024a486ff8837e6784dd290d866112dougm * it depends on this older behavior even though it
6185db853e024a486ff8837e6784dd290d866112dougm * could be considered incorrect. We may tighten this
6185db853e024a486ff8837e6784dd290d866112dougm * up in the future.
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (strictness == SA_CHECK_NORMAL && !is_shared(share))
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * If path is NULL, then a share is in the process of
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * construction or someone has modified the property
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * group inappropriately. It should be
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * ignored. issubdir() comes from the original share
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * implementation and does the difficult part of
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * checking subdirectories.
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * checksubdir(newpath, strictness)
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * checksubdir determines if the specified path (newpath) is a
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * subdirectory of another share. It calls checksubdirgroup() to do
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * the complicated work. The strictness parameter determines how
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * strict a check to make against the path. The strictness values
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * mean: SA_CHECK_NORMAL == only check newpath against shares that are
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * active SA_CHECK_STRICT == check newpath against both active shares
a99982a76d4cc12b1e9021e88531cf425d1e7369dougm * and those * stored in the repository
549ec3fff108310966327d1dc9004551b63210b7dougmchecksubdir(sa_handle_t handle, char *newpath, int strictness)
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * validpath(path, strictness)
6185db853e024a486ff8837e6784dd290d866112dougm * determine if the provided path is valid for a share. It shouldn't
6185db853e024a486ff8837e6784dd290d866112dougm * be a sub-dir of an already shared path or the parent directory of a
6185db853e024a486ff8837e6784dd290d866112dougm * share path.
549ec3fff108310966327d1dc9004551b63210b7dougmvalidpath(sa_handle_t handle, char *path, int strictness)
57b448de658d89a2c88a001d58073c46ed2180f3dougm * check for special case with file system
57b448de658d89a2c88a001d58073c46ed2180f3dougm * that might have restrictions. For now, ZFS
57b448de658d89a2c88a001d58073c46ed2180f3dougm * is the only case since it has its own idea
57b448de658d89a2c88a001d58073c46ed2180f3dougm * of how to configure shares. We do this
57b448de658d89a2c88a001d58073c46ed2180f3dougm * before subdir checking since things like
57b448de658d89a2c88a001d58073c46ed2180f3dougm * ZFS will do that for us. This should also
57b448de658d89a2c88a001d58073c46ed2180f3dougm * be done via plugin interface.
6185db853e024a486ff8837e6784dd290d866112dougm * check to see if group/share is persistent.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "group" can be either an sa_group_t or an sa_share_t. (void *)
5cb0d67909d9970a3e7adbea9422ca3fc88000bfMarcel Telka * works since both these types are also void *.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * If the share is a ZFS share, mark it as persistent.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright grp = (sa_is_share(group)) ? sa_get_parent_group(group) : group;
6185db853e024a486ff8837e6784dd290d866112dougm * sa_valid_group_name(name)
6185db853e024a486ff8837e6784dd290d866112dougm * check that the "name" contains only valid characters and otherwise
6185db853e024a486ff8837e6784dd290d866112dougm * fits the required naming conventions. Valid names must start with
6185db853e024a486ff8837e6784dd290d866112dougm * an alphabetic and the remainder may consist of only alphanumeric
6185db853e024a486ff8837e6784dd290d866112dougm * plus the '-' and '_' characters. This name limitation comes from
6185db853e024a486ff8837e6784dd290d866112dougm * inherent limitations in SMF.
57b448de658d89a2c88a001d58073c46ed2180f3dougm for (c = *name++; c != '\0' && ret != 0; c = *name++) {
6185db853e024a486ff8837e6784dd290d866112dougm * is_zfs_group(group)
6185db853e024a486ff8837e6784dd290d866112dougm * Determine if the specified group is a ZFS sharenfs group
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (strcmp((char *)((xmlNodePtr)group)->name, "share") == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_object_type(object)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function returns a numeric value representing the object
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * type. This allows using simpler checks when doing type specific
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * operations.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (xmlStrcmp(node->name, (xmlChar *)"share") == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (xmlStrcmp(node->name, (xmlChar *)"resource") == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (xmlStrcmp(node->name, (xmlChar *)"optionset") == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else if (xmlStrcmp(node->name, (xmlChar *)"security") == 0)
6185db853e024a486ff8837e6784dd290d866112dougm * sa_optionset_name(optionset, oname, len, id)
6185db853e024a486ff8837e6784dd290d866112dougm * return the SMF name for the optionset. If id is not NULL, it
6185db853e024a486ff8837e6784dd290d866112dougm * will have the GUID value for a share and should be used
6185db853e024a486ff8837e6784dd290d866112dougm * instead of the keyword "optionset" which is used for
6185db853e024a486ff8837e6784dd290d866112dougm * groups. If the optionset doesn't have a protocol type
6185db853e024a486ff8837e6784dd290d866112dougm * associated with it, "default" is used. This shouldn't happen
6185db853e024a486ff8837e6784dd290d866112dougm * at this point but may be desirable in the future if there are
6185db853e024a486ff8837e6784dd290d866112dougm * protocol independent properties added. The name is returned in
6185db853e024a486ff8837e6784dd290d866112dougmsa_optionset_name(sa_optionset_t optionset, char *oname, size_t len, char *id)
6185db853e024a486ff8837e6784dd290d866112dougm * sa_security_name(optionset, oname, len, id)
6185db853e024a486ff8837e6784dd290d866112dougm * return the SMF name for the security. If id is not NULL, it will
6185db853e024a486ff8837e6784dd290d866112dougm * have the GUID value for a share and should be used instead of the
6185db853e024a486ff8837e6784dd290d866112dougm * keyword "optionset" which is used for groups. If the optionset
6185db853e024a486ff8837e6784dd290d866112dougm * doesn't have a protocol type associated with it, "default" is
6185db853e024a486ff8837e6784dd290d866112dougm * used. This shouldn't happen at this point but may be desirable in
6185db853e024a486ff8837e6784dd290d866112dougm * the future if there are protocol independent properties added. The
6185db853e024a486ff8837e6784dd290d866112dougm * name is returned in oname. The security type is also encoded into
6185db853e024a486ff8837e6784dd290d866112dougm * the name. In the future, this wil *be handled a bit differently.
6185db853e024a486ff8837e6784dd290d866112dougmsa_security_name(sa_security_t security, char *oname, size_t len, char *id)
57b448de658d89a2c88a001d58073c46ed2180f3dougm len = snprintf(oname, len, "%s_%s_%s", id, proto ? proto : "default",
57b448de658d89a2c88a001d58073c46ed2180f3dougm * verifydefgroupopts(handle)
57b448de658d89a2c88a001d58073c46ed2180f3dougm * Make sure a "default" group exists and has default protocols enabled.
57b448de658d89a2c88a001d58073c46ed2180f3dougm * NFS is the default for default group
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * sa_init(init_service)
6185db853e024a486ff8837e6784dd290d866112dougm * Initialize the API
6185db853e024a486ff8837e6784dd290d866112dougm * find all the shared objects
6185db853e024a486ff8837e6784dd290d866112dougm * init the tables with all objects
6185db853e024a486ff8837e6784dd290d866112dougm * read in the current configuration
57b448de658d89a2c88a001d58073c46ed2180f3dougm#define GETPROP(prop) scf_simple_prop_next_astring(prop)
57b448de658d89a2c88a001d58073c46ed2180f3dougm#define CHECKTSTAMP(st, tval) stat(SA_LEGACY_DFSTAB, &st) >= 0 && \
c5f58477f1b190d049c5f4fedeed36e5cc22a1c7dougm * Get protocol specific structures, but only if this
c5f58477f1b190d049c5f4fedeed36e5cc22a1c7dougm * is the only handle.
57b448de658d89a2c88a001d58073c46ed2180f3dougm * initialize access into libzfs. We use this
57b448de658d89a2c88a001d58073c46ed2180f3dougm * when collecting info about ZFS datasets and
57b448de658d89a2c88a001d58073c46ed2180f3dougm * since we want to use SMF, initialize an svc handle
57b448de658d89a2c88a001d58073c46ed2180f3dougm * and find out what is there.
57b448de658d89a2c88a001d58073c46ed2180f3dougm * Need to lock the extraction of the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * configuration if the dfstab file has
57b448de658d89a2c88a001d58073c46ed2180f3dougm * changed. Lock everything now and release if
57b448de658d89a2c88a001d58073c46ed2180f3dougm * not needed. Use a file that isn't being
57b448de658d89a2c88a001d58073c46ed2180f3dougm * manipulated by other parts of the system in
57b448de658d89a2c88a001d58073c46ed2180f3dougm * order to not interfere with locking. Using
57b448de658d89a2c88a001d58073c46ed2180f3dougm * dfstab doesn't work.
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (lockfd >= 0) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm extern int errno;
57b448de658d89a2c88a001d58073c46ed2180f3dougm * Check whether we are going to need
57b448de658d89a2c88a001d58073c46ed2180f3dougm * to merge any dfstab changes. This
57b448de658d89a2c88a001d58073c46ed2180f3dougm * is done by comparing the value of
57b448de658d89a2c88a001d58073c46ed2180f3dougm * legacy-timestamp with the current
57b448de658d89a2c88a001d58073c46ed2180f3dougm * st_ctim of the file. If they are
57b448de658d89a2c88a001d58073c46ed2180f3dougm * different, an update is needed and
57b448de658d89a2c88a001d58073c46ed2180f3dougm * the file must remain locked until
57b448de658d89a2c88a001d58073c46ed2180f3dougm * the merge is done in order to
57b448de658d89a2c88a001d58073c46ed2180f3dougm * prevent multiple startups from
57b448de658d89a2c88a001d58073c46ed2180f3dougm * changing the SMF repository at the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * same time. The first to get the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * lock will make any changes before
57b448de658d89a2c88a001d58073c46ed2180f3dougm * the others can read the repository.
57b448de658d89a2c88a001d58073c46ed2180f3dougm "legacy-timestamp");
57b448de658d89a2c88a001d58073c46ed2180f3dougm * We haven't set the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * timestamp before so do it.
57b448de658d89a2c88a001d58073c46ed2180f3dougm * It is essential that the document tree and
57b448de658d89a2c88a001d58073c46ed2180f3dougm * the internal list of roots to handles be
57b448de658d89a2c88a001d58073c46ed2180f3dougm * setup before anything that might try to
57b448de658d89a2c88a001d58073c46ed2180f3dougm * create a new object is called. The document
57b448de658d89a2c88a001d58073c46ed2180f3dougm * tree is the combination of handle->doc and
57b448de658d89a2c88a001d58073c46ed2180f3dougm * handle->tree. This allows searches,
57b448de658d89a2c88a001d58073c46ed2180f3dougm * etc. when all you have is an object in the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * If we couldn't add the tree handle
57b448de658d89a2c88a001d58073c46ed2180f3dougm * to the list, then things are going
57b448de658d89a2c88a001d58073c46ed2180f3dougm * to fail badly. Might as well undo
57b448de658d89a2c88a001d58073c46ed2180f3dougm * everything now and fail the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * sa_init().
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (tval == 0) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm * first time so make sure
57b448de658d89a2c88a001d58073c46ed2180f3dougm * default is setup
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm * Safe to unlock now to allow
546405c3c5a146c88705b0b02a469d1bd57f2b53dougm * others to run
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm /* Get sharetab timestamp */
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm /* Get lastupdate (transaction) timestamp */
549ec3fff108310966327d1dc9004551b63210b7dougm * sa_fini(handle)
6185db853e024a486ff8837e6784dd290d866112dougm * Uninitialize the API structures including the configuration
1cea05af420c1992d793dc442f4e30c7269fc107dougm * data structures and ZFS related data.
549ec3fff108310966327d1dc9004551b63210b7dougm sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
549ec3fff108310966327d1dc9004551b63210b7dougm * Free the config trees and any other data structures
549ec3fff108310966327d1dc9004551b63210b7dougm * used in the handle.
549ec3fff108310966327d1dc9004551b63210b7dougm /* Remove and free the entry in the global list. */
549ec3fff108310966327d1dc9004551b63210b7dougm * If this was the last handle to release, unload the
c5f58477f1b190d049c5f4fedeed36e5cc22a1c7dougm * plugins that were loaded. Use a mutex in case
c5f58477f1b190d049c5f4fedeed36e5cc22a1c7dougm * another thread is reinitializing.
0fd7766084e66e6e9fda9eb800b67bbf965d4bffgwr /* Make sure we free the handle */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_protocols(char **protocol)
6185db853e024a486ff8837e6784dd290d866112dougm * Get array of protocols that are supported
6185db853e024a486ff8837e6784dd290d866112dougm * Returns pointer to an allocated and NULL terminated
6185db853e024a486ff8837e6784dd290d866112dougm * array of strings. Caller must free.
6185db853e024a486ff8837e6784dd290d866112dougm * This really should be determined dynamically.
6185db853e024a486ff8837e6784dd290d866112dougm * If there aren't any defined, return -1.
6185db853e024a486ff8837e6784dd290d866112dougm * Use free() to return memory.
57b448de658d89a2c88a001d58073c46ed2180f3dougm for (numproto = 0, plug = sap_proto_list; plug != NULL;
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* faking for now */
6185db853e024a486ff8837e6784dd290d866112dougm * find_group_by_name(node, group)
6185db853e024a486ff8837e6784dd290d866112dougm * search the XML document subtree specified by node to find the group
6185db853e024a486ff8837e6784dd290d866112dougm * specified by group. Searching subtree allows subgroups to be
6185db853e024a486ff8837e6784dd290d866112dougm * searched for.
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* if no groupname, return the first found */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_group(groupname)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the "group" specified. If groupname is NULL,
6185db853e024a486ff8837e6784dd290d866112dougm * return the first group of the list of groups.
549ec3fff108310966327d1dc9004551b63210b7dougm sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
549ec3fff108310966327d1dc9004551b63210b7dougm if (impl_handle != NULL && impl_handle->tree != NULL) {
a335142544257a204dde1839676940d0e0432d06dougm * We want to find the, possibly, named group. If
a335142544257a204dde1839676940d0e0432d06dougm * group is not NULL, then lookup the name. If it is
a335142544257a204dde1839676940d0e0432d06dougm * NULL, we only do the find if groupname is also
a335142544257a204dde1839676940d0e0432d06dougm * NULL. This allows lookup of the "first" group in
a335142544257a204dde1839676940d0e0432d06dougm * the internal list.
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* if a subgroup, find it before returning */
57b448de658d89a2c88a001d58073c46ed2180f3dougm (void) sa_get_instance(impl_handle->scfhandle, (char *)group);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_next_group(group)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the "next" group after the specified group from
6185db853e024a486ff8837e6784dd290d866112dougm * the internal group list. NULL if there are no more.
57b448de658d89a2c88a001d58073c46ed2180f3dougm for (ngroup = ((xmlNodePtr)group)->next; ngroup != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_share(group, sharepath)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the share object for the share specified. The share
6185db853e024a486ff8837e6784dd290d866112dougm * must be in the specified group. Return NULL if not found.
6185db853e024a486ff8837e6784dd290d866112dougm * For future scalability, this should end up building a cache
6185db853e024a486ff8837e6784dd290d866112dougm * since it will get called regularly by the mountd and info
6185db853e024a486ff8837e6784dd290d866112dougm * services.
57b448de658d89a2c88a001d58073c46ed2180f3dougm for (node = ((xmlNodePtr)group)->children; node != NULL;
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* is it the correct share? */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_next_share(share)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the next share following the specified share
6185db853e024a486ff8837e6784dd290d866112dougm * from the internal list of shares. Returns NULL if there
6185db853e024a486ff8837e6784dd290d866112dougm * are no more shares. The list is relative to the same
6185db853e024a486ff8837e6784dd290d866112dougm * _sa_get_child_node(node, type)
6185db853e024a486ff8837e6784dd290d866112dougm * find the child node of the specified node that has "type". This is
6185db853e024a486ff8837e6784dd290d866112dougm * used to implement several internal functions.
6185db853e024a486ff8837e6784dd290d866112dougm * find_share(group, path)
6185db853e024a486ff8837e6784dd290d866112dougm * Search all the shares in the specified group for one that has the
6185db853e024a486ff8837e6784dd290d866112dougm * specified path.
6185db853e024a486ff8837e6784dd290d866112dougm for (share = sa_get_share(group, NULL); share != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_sub_group(group)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the first sub-group of group. The sa_get_next_group() function
6185db853e024a486ff8837e6784dd290d866112dougm * can be used to get the rest. This is currently only used for ZFS
6185db853e024a486ff8837e6784dd290d866112dougm * sub-groups but could be used to implement a more general mechanism.
6185db853e024a486ff8837e6784dd290d866112dougm return ((sa_group_t)_sa_get_child_node((xmlNodePtr)group,
6185db853e024a486ff8837e6784dd290d866112dougm * sa_find_share(sharepath)
6185db853e024a486ff8837e6784dd290d866112dougm * Finds a share regardless of group. In the future, this
6185db853e024a486ff8837e6784dd290d866112dougm * function should utilize a cache and hash table of some kind.
6185db853e024a486ff8837e6784dd290d866112dougm * The current assumption is that a path will only be shared
6185db853e024a486ff8837e6784dd290d866112dougm * once. In the future, this may change as implementation of
6185db853e024a486ff8837e6784dd290d866112dougm * resource names comes into being.
549ec3fff108310966327d1dc9004551b63210b7dougm for (group = sa_get_group(handle, NULL); group != NULL && !done;
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * sa_check_path(group, path, strictness)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check that path is a valid path relative to the group. Currently,
6185db853e024a486ff8837e6784dd290d866112dougm * we are ignoring the group and checking only the NFS rules. Later,
6185db853e024a486ff8837e6784dd290d866112dougm * we may want to use the group to then check against the protocols
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * enabled on the group. The strictness values mean:
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * SA_CHECK_NORMAL == only check newpath against shares that are active
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * SA_CHECK_STRICT == check newpath against both active shares and those
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * stored in the repository
f345c0beb4c8f75cb54c2e070498e56febd468acdougmsa_check_path(sa_group_t group, char *path, int strictness)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (handle == NULL)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (SA_BAD_PATH);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * mark_excluded_protos(group, share, flags)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Walk through all the protocols enabled for the group and check to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * see if the share has any of them should be in the exclude list
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * based on the featureset of the protocol. If there are any, add the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "exclude" property to the share.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwmark_excluded_protos(sa_group_t group, xmlNodePtr share, uint64_t flags)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * get_all_features(group)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Walk through all the protocols on the group and collect all
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * possible enabled features. This is the OR of all the featuresets.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * _sa_add_share(group, sharepath, persist, *error, flags)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common code for all types of add_share. sa_add_share() is the
6185db853e024a486ff8837e6784dd290d866112dougm * public API, we also need to be able to do this when parsing legacy
6185db853e024a486ff8837e6784dd290d866112dougm * files and construction of the internal configuration while
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * extracting config info from SMF. "flags" indicates if some
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * protocols need relaxed rules while other don't. These values are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the featureset values defined in libshare.h.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw_sa_add_share(sa_group_t group, char *sharepath, int persist, int *error,
57b448de658d89a2c88a001d58073c46ed2180f3dougm node = xmlNewChild((xmlNodePtr)group, NULL, (xmlChar *)"share", NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(node, (xmlChar *)"path", (xmlChar *)sharepath);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw persist ? (xmlChar *)"persist" : (xmlChar *)"transient");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * persistent shares come in two flavors: SMF and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ZFS. Sort this one out based on target group and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * path type. Both NFS and SMB are supported. First,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * check to see if the protocol is enabled on the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * subgroup and then setup the share appropriately.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (err == SA_NO_PERMISSION && persist & SA_SHARE_PARSER)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* called by the dfstab parser so could be a show */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * we couldn't commit to the repository so undo
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * our internal state to reflect reality.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_add_share(group, sharepath, persist, *error)
6185db853e024a486ff8837e6784dd290d866112dougm * Add a new share object to the specified group. The share will
6185db853e024a486ff8837e6784dd290d866112dougm * have the specified sharepath and will only be constructed if
6185db853e024a486ff8837e6784dd290d866112dougm * it is a valid path to be shared. NULL is returned on error
6185db853e024a486ff8837e6784dd290d866112dougm * and a detailed error value will be returned via the error
6185db853e024a486ff8837e6784dd290d866112dougmsa_add_share(sa_group_t group, char *sharepath, int persist, int *error)
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * If the share is to be permanent, use strict checking so a
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * bad config doesn't get created. Transient shares only need
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * to check against the currently active
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * shares. SA_SHARE_PARSER is a modifier used internally to
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * indicate that we are being called by the dfstab parser and
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * that we need strict checking in all cases. Normally persist
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * is in integer value but SA_SHARE_PARSER may be or'd into
f345c0beb4c8f75cb54c2e070498e56febd468acdougm * it as an override.
f345c0beb4c8f75cb54c2e070498e56febd468acdougm if (persist & SA_SHARE_PARSER || persist == SA_SHARE_PERMANENT)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * need to determine if the share is valid. The rules are:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - The path must not already exist
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - The path must not be a subdir or parent dir of an
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * existing path unless at least one protocol allows it.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The sub/parent check is done in sa_check_path().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (*error) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_enable_share(share, protocol)
6185db853e024a486ff8837e6784dd290d866112dougm * Enable the specified share to the specified protocol.
6185db853e024a486ff8837e6784dd290d866112dougm * If protocol is NULL, then all protocols.
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* tell the server about the share */
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* lookup protocol specific handler */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Tell all protocols about the share */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_disable_share(share, protocol)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Disable the specified share to the specified protocol. If
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * protocol is NULL, then all protocols that are enabled for the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * share should be disabled.
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* need to do all protocols */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Tell all protocols about the share */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_remove_share(share)
6185db853e024a486ff8837e6784dd290d866112dougm * remove the specified share from its containing group.
6185db853e024a486ff8837e6784dd290d866112dougm * Remove from the SMF or ZFS configuration space.
6185db853e024a486ff8837e6784dd290d866112dougm /* remove the node from its group then free the memory */
6185db853e024a486ff8837e6784dd290d866112dougm * need to test if "busy"
6185db853e024a486ff8837e6784dd290d866112dougm /* only do SMF action if permanent */
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* remove from legacy dfstab as well as possible SMF */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_move_share(group, share)
6185db853e024a486ff8837e6784dd290d866112dougm * move the specified share to the specified group. Update SMF
6185db853e024a486ff8837e6784dd290d866112dougm * appropriately.
6185db853e024a486ff8837e6784dd290d866112dougm /* remove the node from its group then free the memory */
57b448de658d89a2c88a001d58073c46ed2180f3dougm * now that the share isn't in its old group, add to
57b448de658d89a2c88a001d58073c46ed2180f3dougm * the new one
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlAddChild((xmlNodePtr)group, (xmlNodePtr)share);
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* need to deal with SMF */
57b448de658d89a2c88a001d58073c46ed2180f3dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
57b448de658d89a2c88a001d58073c46ed2180f3dougm * need to remove from old group first and then add to
57b448de658d89a2c88a001d58073c46ed2180f3dougm * new group. Ideally, we would do the other order but
57b448de658d89a2c88a001d58073c46ed2180f3dougm * need to avoid having the share in two groups at the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * same time.
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = sa_delete_share(impl_handle->scfhandle, oldgroup,
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_parent_group(share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Return the containing group for the share. If a group was actually
6185db853e024a486ff8837e6784dd290d866112dougm * passed in, we don't want a parent so return NULL.
6185db853e024a486ff8837e6784dd290d866112dougm * make sure parent is a group and not sharecfg since
6185db853e024a486ff8837e6784dd290d866112dougm * we may be cheating and passing in a group.
6185db853e024a486ff8837e6784dd290d866112dougm * Eventually, groups of groups might come into being.
549ec3fff108310966327d1dc9004551b63210b7dougm * _sa_create_group(impl_handle, groupname)
6185db853e024a486ff8837e6784dd290d866112dougm * Create a group in the document. The caller will need to deal with
6185db853e024a486ff8837e6784dd290d866112dougm * configuration store and activation.
549ec3fff108310966327d1dc9004551b63210b7dougm_sa_create_group(sa_handle_impl_t impl_handle, char *groupname)
57b448de658d89a2c88a001d58073c46ed2180f3dougm node = xmlNewChild(impl_handle->tree, NULL, (xmlChar *)"group",
6185db853e024a486ff8837e6784dd290d866112dougm * _sa_create_zfs_group(group, groupname)
6185db853e024a486ff8837e6784dd290d866112dougm * Create a ZFS subgroup under the specified group. This may
6185db853e024a486ff8837e6784dd290d866112dougm * eventually form the basis of general sub-groups, but is currently
6185db853e024a486ff8837e6784dd290d866112dougm * restricted to ZFS.
6185db853e024a486ff8837e6784dd290d866112dougm_sa_create_zfs_group(sa_group_t group, char *groupname)
57b448de658d89a2c88a001d58073c46ed2180f3dougm node = xmlNewChild((xmlNodePtr)group, NULL, (xmlChar *)"group", NULL);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_create_group(groupname, *error)
6185db853e024a486ff8837e6784dd290d866112dougm * Create a new group with groupname. Need to validate that it is a
6185db853e024a486ff8837e6784dd290d866112dougm * legal name for SMF and the construct the SMF service instance of
6185db853e024a486ff8837e6784dd290d866112dougm * svc:/network/shares/group to implement the group. All necessary
6185db853e024a486ff8837e6784dd290d866112dougm * operational properties must be added to the group at this point
6185db853e024a486ff8837e6784dd290d866112dougm * (via the SMF transaction model).
549ec3fff108310966327d1dc9004551b63210b7dougmsa_create_group(sa_handle_t handle, char *groupname, int *error)
549ec3fff108310966327d1dc9004551b63210b7dougm sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
549ec3fff108310966327d1dc9004551b63210b7dougm if (impl_handle == NULL || impl_handle->scfhandle == NULL) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* default to the group being enabled */
57b448de658d89a2c88a001d58073c46ed2180f3dougm "operation");
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* initialize the RBAC strings */
57b448de658d89a2c88a001d58073c46ed2180f3dougm "general");
6185db853e024a486ff8837e6784dd290d866112dougm "action_authorization",
6185db853e024a486ff8837e6784dd290d866112dougm "value_authorization",
57b448de658d89a2c88a001d58073c46ed2180f3dougm * Couldn't commit the group
57b448de658d89a2c88a001d58073c46ed2180f3dougm * so we need to undo
57b448de658d89a2c88a001d58073c46ed2180f3dougm * internally.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_remove_group(group)
6185db853e024a486ff8837e6784dd290d866112dougm * Remove the specified group. This deletes from the SMF repository.
6185db853e024a486ff8837e6784dd290d866112dougm * All property groups and properties are removed.
549ec3fff108310966327d1dc9004551b63210b7dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = sa_delete_instance(impl_handle->scfhandle, name);
57b448de658d89a2c88a001d58073c46ed2180f3dougm xmlUnlinkNode((xmlNodePtr)group); /* make sure unlinked */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_update_config()
6185db853e024a486ff8837e6784dd290d866112dougm * Used to update legacy files that need to be updated in bulk
6185db853e024a486ff8837e6784dd290d866112dougm * Currently, this is a placeholder and will go away in a future
6185db853e024a486ff8837e6784dd290d866112dougm * do legacy files first so we can tell when they change.
6185db853e024a486ff8837e6784dd290d866112dougm * This will go away when we start updating individual records
6185db853e024a486ff8837e6784dd290d866112dougm * rather than the whole file.
6185db853e024a486ff8837e6784dd290d866112dougm * get_node_attr(node, tag)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Get the specified tag(attribute) if it exists on the node. This is
6185db853e024a486ff8837e6784dd290d866112dougm * used internally by a number of attribute oriented functions.
6185db853e024a486ff8837e6784dd290d866112dougmstatic char *
6185db853e024a486ff8837e6784dd290d866112dougm return ((char *)name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * set_node_attr(node, tag)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set the specified tag(attribute) to the specified value This is
6185db853e024a486ff8837e6784dd290d866112dougm * used internally by a number of attribute oriented functions. It
6185db853e024a486ff8837e6784dd290d866112dougm * doesn't update the repository, only the internal document state.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_group_attr(group, tag)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the specied attribute, if defined, for the group.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_group_attr(group, tag, value)
6185db853e024a486ff8837e6784dd290d866112dougm * set the specified tag/attribute on the group using value as its
6185db853e024a486ff8837e6784dd290d866112dougm * This will result in setting the property in the SMF repository as
6185db853e024a486ff8837e6784dd290d866112dougm * well as in the internal document.
6185db853e024a486ff8837e6784dd290d866112dougmsa_set_group_attr(sa_group_t group, char *tag, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ZFS group/subgroup doesn't need the handle so shortcut.
549ec3fff108310966327d1dc9004551b63210b7dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = sa_get_instance(impl_handle->scfhandle, groupname);
57b448de658d89a2c88a001d58073c46ed2180f3dougm "operation");
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_share_attr(share, tag)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the value of the tag/attribute set on the specified
6185db853e024a486ff8837e6784dd290d866112dougm * share. Returns NULL if the tag doesn't exist.
6185db853e024a486ff8837e6784dd290d866112dougm * _sa_set_share_description(share, description)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Add a description tag with text contents to the specified share. A
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * separate XML tag is used rather than a property. This can also be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * used with resources.
57b448de658d89a2c88a001d58073c46ed2180f3dougm node = xmlNewChild((xmlNodePtr)share, NULL, (xmlChar *)"description",
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_share_attr(share, tag, value)
6185db853e024a486ff8837e6784dd290d866112dougm * Set the share attribute specified by tag to the specified value. In
6185db853e024a486ff8837e6784dd290d866112dougm * the case of "resource", enforce a no duplicates in a group rule. If
6185db853e024a486ff8837e6784dd290d866112dougm * the share is not transient, commit the changes to the repository
6185db853e024a486ff8837e6784dd290d866112dougm * else just update the share internally.
6185db853e024a486ff8837e6784dd290d866112dougmsa_set_share_attr(sa_share_t share, char *tag, char *value)
6185db853e024a486ff8837e6784dd290d866112dougm * There are some attributes that may have specific
6185db853e024a486ff8837e6784dd290d866112dougm * restrictions on them. Initially, only "resource" has
6185db853e024a486ff8837e6784dd290d866112dougm * special meaning that needs to be checked. Only one instance
6185db853e024a486ff8837e6784dd290d866112dougm * of a resource name may exist within a group.
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* we can probably optimize this some */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_property_attr(prop, tag)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the value of the specified property attribute. Standard
6185db853e024a486ff8837e6784dd290d866112dougm * attributes are "type" and "value".
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_optionset_attr(prop, tag)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the value of the specified property attribute. Standard
6185db853e024a486ff8837e6784dd290d866112dougm * attribute is "type".
6185db853e024a486ff8837e6784dd290d866112dougmsa_get_optionset_attr(sa_property_t optionset, char *tag)
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_optionset_attr(optionset, tag, value)
6185db853e024a486ff8837e6784dd290d866112dougm * Set the specified attribute(tag) to the specified value on the
6185db853e024a486ff8837e6784dd290d866112dougm * optionset.
6185db853e024a486ff8837e6784dd290d866112dougmsa_set_optionset_attr(sa_group_t optionset, char *tag, char *value)
6185db853e024a486ff8837e6784dd290d866112dougm * sa_free_attr_string(string)
6185db853e024a486ff8837e6784dd290d866112dougm * Free the string that was returned in one of the sa_get_*_attr()
6185db853e024a486ff8837e6784dd290d866112dougm * functions.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_optionset(group, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the optionset, if it exists, that is associated with the
6185db853e024a486ff8837e6784dd290d866112dougm * specified protocol.
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)group)->children; node != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm if (xmlStrcmp(node->name, (xmlChar *)"optionset") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_next_optionset(optionset)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the next optionset in the group. NULL if this was the last.
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)optionset)->next; node != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm if (xmlStrcmp(node->name, (xmlChar *)"optionset") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_security(group, sectype, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the security optionset. The internal name is a hold over
6185db853e024a486ff8837e6784dd290d866112dougm * from the implementation and will be changed before the API is
6185db853e024a486ff8837e6784dd290d866112dougm * finalized. This is really a named optionset that can be negotiated
6185db853e024a486ff8837e6784dd290d866112dougm * as a group of properties (like NFS security options).
6185db853e024a486ff8837e6784dd290d866112dougmsa_get_security(sa_group_t group, char *sectype, char *proto)
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)group)->children; node != NULL;
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (xmlStrcmp(node->name, (xmlChar *)"security") == 0) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* it doesn't match so continue */
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* potential match */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_next_security(security)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the next security optionset if one exists.
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)security)->next; node != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm if (xmlStrcmp(node->name, (xmlChar *)"security") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_property(optionset, prop)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the property object with the name specified in prop from the
6185db853e024a486ff8837e6784dd290d866112dougm * optionset.
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (xmlStrcmp(node->name, (xmlChar *)"option") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm if (node != NULL && xmlStrcmp(node->name, (xmlChar *)"option") != 0) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm * avoid a non option node -- it is possible to be a
57b448de658d89a2c88a001d58073c46ed2180f3dougm * text node
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_next_property(property)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the next property following the specified property. NULL if
6185db853e024a486ff8837e6784dd290d866112dougm * this was the last.
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)property)->next; node != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm if (xmlStrcmp(node->name, (xmlChar *)"option") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_share_description(share, content)
6185db853e024a486ff8837e6784dd290d866112dougm * Set the description of share to content.
6185db853e024a486ff8837e6784dd290d866112dougmsa_set_share_description(sa_share_t share, char *content)
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)share)->children; node != NULL;
6185db853e024a486ff8837e6784dd290d866112dougm if (xmlStrcmp(node->name, (xmlChar *)"description") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm /* no existing description but want to add */
6185db853e024a486ff8837e6784dd290d866112dougm /* add a description */
6185db853e024a486ff8837e6784dd290d866112dougm /* update a description */
6185db853e024a486ff8837e6784dd290d866112dougm /* remove an existing description */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
6185db853e024a486ff8837e6784dd290d866112dougm * fixproblemchars(string)
6185db853e024a486ff8837e6784dd290d866112dougm * don't want any newline or tab characters in the text since these
6185db853e024a486ff8837e6784dd290d866112dougm * could break display of data and legacy file formats.
57b448de658d89a2c88a001d58073c46ed2180f3dougm else if (c == '"')
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_share_description(share)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the description text for the specified share if it
6185db853e024a486ff8837e6784dd290d866112dougm * exists. NULL if no description exists.
6185db853e024a486ff8837e6784dd290d866112dougm for (node = ((xmlNodePtr)share)->children; node != NULL;
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (xmlStrcmp(node->name, (xmlChar *)"description") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm return ((char *)description);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_free(share_description(description)
6185db853e024a486ff8837e6784dd290d866112dougm * Free the description string.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_create_optionset(group, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Create an optionset for the specified protocol in the specied
6185db853e024a486ff8837e6784dd290d866112dougm * group. This is manifested as a property group within SMF.
6185db853e024a486ff8837e6784dd290d866112dougm /* can't have a duplicate protocol */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Account for resource names being slightly
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * different.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Transient shares do not have an "id" so not an
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * error to not find one.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* id can be NULL if the group is transient (ZFS) */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Couldn't get the id for the share or
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource. While this could be a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * configuration issue, it is most likely an
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * out of memory. In any case, fail the create.
57b448de658d89a2c88a001d58073c46ed2180f3dougm optionset = (sa_optionset_t)xmlNewChild((xmlNodePtr)group,
6185db853e024a486ff8837e6784dd290d866112dougm * only put to repository if on a group and we were
6185db853e024a486ff8837e6784dd290d866112dougm * able to create an optionset.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Need to get parent group in all cases, but also get
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the share if this is a resource.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_property_parent(property)
6185db853e024a486ff8837e6784dd290d866112dougm * Given a property, return the object it is a property of. This will
6185db853e024a486ff8837e6784dd290d866112dougm * be an optionset of some type.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_optionset_parent(optionset)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the parent of the specified optionset. This could be a group
6185db853e024a486ff8837e6784dd290d866112dougm * or a share.
6185db853e024a486ff8837e6784dd290d866112dougm * zfs_needs_update(share)
6185db853e024a486ff8837e6784dd290d866112dougm * In order to avoid making multiple updates to a ZFS share when
6185db853e024a486ff8837e6784dd290d866112dougm * setting properties, the share attribute "changed" will be set to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * true when a property is added or modified. When done adding
6185db853e024a486ff8837e6784dd290d866112dougm * properties, we can then detect that an update is needed. We then
6185db853e024a486ff8837e6784dd290d866112dougm * clear the state here to detect additional changes.
6185db853e024a486ff8837e6784dd290d866112dougm * zfs_set_update(share)
6185db853e024a486ff8837e6784dd290d866112dougm * Set the changed attribute of the share to true.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_commit_properties(optionset, clear)
6185db853e024a486ff8837e6784dd290d866112dougm * Check if SMF or ZFS config and either update or abort the pending
6185db853e024a486ff8837e6784dd290d866112dougmsa_commit_properties(sa_optionset_t optionset, int clear)
6185db853e024a486ff8837e6784dd290d866112dougm if (group != NULL && (sa_is_share(group) || is_zfs_group(group))) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm /* only update ZFS if on a share */
57b448de658d89a2c88a001d58073c46ed2180f3dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_destroy_optionset(optionset)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Remove the optionset from its group. Update the repository to
6185db853e024a486ff8837e6784dd290d866112dougm * reflect this change.
6185db853e024a486ff8837e6784dd290d866112dougm /* now delete the prop group */
57b448de658d89a2c88a001d58073c46ed2180f3dougm len = sa_optionset_name(optionset, name, sizeof (name), id);
57b448de658d89a2c88a001d58073c46ed2180f3dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (len > 0) {
6185db853e024a486ff8837e6784dd290d866112dougm/* private to the implementation */
6185db853e024a486ff8837e6784dd290d866112dougm * sa_create_security(group, sectype, proto)
6185db853e024a486ff8837e6784dd290d866112dougm * Create a security optionset (one that has a type name and a
6185db853e024a486ff8837e6784dd290d866112dougm * proto). Security is left over from a pure NFS implementation. The
6185db853e024a486ff8837e6784dd290d866112dougm * naming will change in the future when the API is released.
6185db853e024a486ff8837e6784dd290d866112dougmsa_create_security(sa_group_t group, char *sectype, char *proto)
6185db853e024a486ff8837e6784dd290d866112dougm /* can't have a duplicate security option */
6185db853e024a486ff8837e6784dd290d866112dougm security = (sa_security_t)xmlNewChild((xmlNodePtr)group,
6185db853e024a486ff8837e6784dd290d866112dougm * sa_destroy_security(security)
6185db853e024a486ff8837e6784dd290d866112dougm * Remove the specified optionset from the document and the
6185db853e024a486ff8837e6784dd290d866112dougm * configuration.
57b448de658d89a2c88a001d58073c46ed2180f3dougm len = sa_security_name(security, name, sizeof (name), id);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_security_attr(optionset, tag)
6185db853e024a486ff8837e6784dd290d866112dougm * Return the specified attribute value from the optionset.
6185db853e024a486ff8837e6784dd290d866112dougmsa_get_security_attr(sa_property_t optionset, char *tag)
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_security_attr(optionset, tag, value)
6185db853e024a486ff8837e6784dd290d866112dougm * Set the optioset attribute specied by tag to the specified value.
6185db853e024a486ff8837e6784dd290d866112dougmsa_set_security_attr(sa_group_t optionset, char *tag, char *value)
6185db853e024a486ff8837e6784dd290d866112dougm * is_nodetype(node, type)
6185db853e024a486ff8837e6784dd290d866112dougm * Check to see if node is of the type specified.
6185db853e024a486ff8837e6784dd290d866112dougm return (strcmp((char *)((xmlNodePtr)node)->name, type) == 0);
57b448de658d89a2c88a001d58073c46ed2180f3dougm * add_or_update()
57b448de658d89a2c88a001d58073c46ed2180f3dougm * Add or update a property. Pulled out of sa_set_prop_by_prop for
57b448de658d89a2c88a001d58073c46ed2180f3dougm * readability.
57b448de658d89a2c88a001d58073c46ed2180f3dougmadd_or_update(scfutilhandle_t *scf_handle, int type, scf_value_t *value,
57b448de658d89a2c88a001d58073c46ed2180f3dougm scf_transaction_entry_t *entry, char *name, char *valstr)
57b448de658d89a2c88a001d58073c46ed2180f3dougm ret = scf_transaction_property_change(scf_handle->trans,
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (ret == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_prop_by_prop(optionset, group, prop, type)
6185db853e024a486ff8837e6784dd290d866112dougm * Add/remove/update the specified property prop into the optionset or
6185db853e024a486ff8837e6784dd290d866112dougm * share. If a share, sort out which property group based on GUID. In
6185db853e024a486ff8837e6784dd290d866112dougm * all cases, the appropriate transaction is set (or ZFS share is
6185db853e024a486ff8837e6784dd290d866112dougm * marked as needing an update)
6185db853e024a486ff8837e6784dd290d866112dougmsa_set_prop_by_prop(sa_optionset_t optionset, sa_group_t group,
6185db853e024a486ff8837e6784dd290d866112dougm * if the group/share is not persistent we don't need
6185db853e024a486ff8837e6784dd290d866112dougm * to do anything here
549ec3fff108310966327d1dc9004551b63210b7dougm impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (impl_handle == NULL || impl_handle->scfhandle == NULL)
6185db853e024a486ff8837e6784dd290d866112dougm opttype = is_nodetype((void *)optionset, "optionset");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check for share vs. resource since they need slightly
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * different treatment given the hierarchy.
57b448de658d89a2c88a001d58073c46ed2180f3dougm * ZFS update. The calling function would have updated
57b448de658d89a2c88a001d58073c46ed2180f3dougm * the internal XML structure. Just need to flag it as
57b448de658d89a2c88a001d58073c46ed2180f3dougm * changed for ZFS.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * sa_create_section(name, value)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Create a new section with the specified name and extra data.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsa_set_section_attr(sa_property_t sect, char *name, char *value)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(sect, (xmlChar *)name, (xmlChar *)value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * sa_create_property(section, name, value)
6185db853e024a486ff8837e6784dd290d866112dougm * Create a new property with the specified name and value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(node, (xmlChar *)"type", (xmlChar *)name);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(node, (xmlChar *)"value", (xmlChar *)value);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_add_property(object, property)
6185db853e024a486ff8837e6784dd290d866112dougm * Add the specified property to the object. Issue the appropriate
6185db853e024a486ff8837e6784dd290d866112dougm * transaction or mark a ZFS object as needing an update.
3b61b335c37f67a23674820a1cf865f4e058d617dougm /* It is legitimate to not find a handle */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Resources are children of share. Need to go up two
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * levels to find the group but the parent needs to be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the share at this point in order to get the "id".
57b448de658d89a2c88a001d58073c46ed2180f3dougm * ZFS is a special case. We do want
57b448de658d89a2c88a001d58073c46ed2180f3dougm * to allow editing property/security
57b448de658d89a2c88a001d58073c46ed2180f3dougm * lists since we can have a better
57b448de658d89a2c88a001d58073c46ed2180f3dougm * syntax and we also want to keep
57b448de658d89a2c88a001d58073c46ed2180f3dougm * things consistent when possible.
57b448de658d89a2c88a001d58073c46ed2180f3dougm * Right now, we defer until the
57b448de658d89a2c88a001d58073c46ed2180f3dougm * sa_commit_properties so we can get
57b448de658d89a2c88a001d58073c46ed2180f3dougm * them all at once. We do need to
57b448de658d89a2c88a001d58073c46ed2180f3dougm * mark the share as "changed"
6185db853e024a486ff8837e6784dd290d866112dougm * sa_remove_property(property)
6185db853e024a486ff8837e6784dd290d866112dougm * Remove the specied property from its containing object. Update the
6185db853e024a486ff8837e6784dd290d866112dougm * repository as appropriate.
6185db853e024a486ff8837e6784dd290d866112dougm * sa_update_property(property, value)
6185db853e024a486ff8837e6784dd290d866112dougm * Update the specified property to the new value. If value is NULL,
6185db853e024a486ff8837e6784dd290d866112dougm * we currently treat this as a remove.
6185db853e024a486ff8837e6784dd290d866112dougmsa_update_property(sa_property_t property, char *value)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * sa_get_protocol_section(propset, prop)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get the specified protocol specific section. These are global to
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * the protocol and not specific to a group or share.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsa_get_protocol_section(sa_protocol_properties_t propset, char *section)
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross if ((sa_proto_get_featureset(proto) & SA_FEATURE_HAS_SECTIONS) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (xmlStrcmp(node->name, (xmlChar *)"section") == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (node != NULL && xmlStrcmp(node->name, (xmlChar *)"section") != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * avoid a non option node -- it is possible to be a
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * text node
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * sa_get_next_protocol_section(prop, find)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get the next protocol specific section in the list.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsa_get_next_protocol_section(sa_property_t prop, char *find)
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross if ((sa_proto_get_featureset(proto) & SA_FEATURE_HAS_SECTIONS) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (xmlStrcmp(node->name, (xmlChar *)"section") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_protocol_property(propset, prop)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the specified protocol specific property. These are global to
6185db853e024a486ff8837e6784dd290d866112dougm * the protocol and not specific to a group or share.
6185db853e024a486ff8837e6784dd290d866112dougmsa_get_protocol_property(sa_protocol_properties_t propset, char *prop)
57b448de658d89a2c88a001d58073c46ed2180f3dougm if (xmlStrcmp(node->name, (xmlChar *)"option") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm if (node != NULL && xmlStrcmp(node->name, (xmlChar *)"option") != 0) {
57b448de658d89a2c88a001d58073c46ed2180f3dougm * avoid a non option node -- it is possible to be a
57b448de658d89a2c88a001d58073c46ed2180f3dougm * text node
6185db853e024a486ff8837e6784dd290d866112dougm * sa_get_next_protocol_property(prop)
6185db853e024a486ff8837e6784dd290d866112dougm * Get the next protocol specific property in the list.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsa_get_next_protocol_property(sa_property_t prop, char *find)
6185db853e024a486ff8837e6784dd290d866112dougm if (xmlStrcmp(node->name, (xmlChar *)"option") == 0) {
6185db853e024a486ff8837e6784dd290d866112dougm * sa_set_protocol_property(prop, value)
6185db853e024a486ff8837e6784dd290d866112dougm * Set the specified property to have the new value. The protocol
6185db853e024a486ff8837e6784dd290d866112dougm * specific plugin will then be called to update the property.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsa_set_protocol_property(sa_property_t prop, char *section, char *value)
6185db853e024a486ff8837e6784dd290d866112dougm * sa_add_protocol_property(propset, prop)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Add a new property to the protocol specific property set.
6185db853e024a486ff8837e6784dd290d866112dougmsa_add_protocol_property(sa_protocol_properties_t propset, sa_property_t prop)
6185db853e024a486ff8837e6784dd290d866112dougm /* should check for legitimacy */
6185db853e024a486ff8837e6784dd290d866112dougm node = xmlAddChild((xmlNodePtr)propset, (xmlNodePtr)prop);
6185db853e024a486ff8837e6784dd290d866112dougm * sa_create_protocol_properties(proto)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Create a protocol specific property set.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(node, (xmlChar *)"type", (xmlChar *)proto);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_share_resource(share, resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Get the named resource from the share, if it exists. If resource is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NULL, get the first resource.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (node = ((xmlNodePtr)share)->children; node != NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (xmlStrcmp(node->name, (xmlChar *)"resource") == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We are looking for the first
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource node and not a names
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* is it the correct share? */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_next_resource(resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Return the next share following the specified share
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from the internal list of shares. Returns NULL if there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * are no more shares. The list is relative to the same
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * _sa_get_next_resource_index(share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * get the next resource index number (one greater then current largest)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_add_resource(share, resource, persist, &err)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Adds a new resource name associated with share. The resource name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * must be unique in the system and will be case insensitive (eventually).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsa_add_resource(sa_share_t share, char *resource, int persist, int *error)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char istring[8]; /* just big enough for an integer value */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) xmlSetProp(node, (xmlChar *)"type", persist ?
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* ZFS doesn't use resource names */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_remove_resource(resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Remove the resource name from the share (and the system)
55bf511df53aad0fdb7eb3fa349f0308cc05234cas /* Disable the resource for all protocols. */
55bf511df53aad0fdb7eb3fa349f0308cc05234cas /* Remove any optionsets from the resource. */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Remove from the share */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* only do SMF action if permanent and not ZFS */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ihandle = (sa_handle_impl_t)sa_find_group_handle(group);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = sa_commit_share(ihandle->scfhandle, group, share);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * proto_rename_resource(handle, group, resource, newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Helper function for sa_rename_resource that notifies the protocol
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of a resource name change prior to a config repository update.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwproto_rename_resource(sa_handle_t handle, sa_group_t group,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_rename_resource(resource, newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Rename the resource to the new name, if it is unique.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsa_rename_resource(sa_resource_t resource, char *newname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Everything appears to be valid at this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * point. Change the name of the active share and then
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * update the share in the appropriate repository.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ret = proto_rename_resource(handle, group, resource, newname);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_resource_attr(resource, tag)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Get the named attribute of the resource. "name" and "id" are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * currently defined. NULL if tag not defined.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_set_resource_attr(resource, tag, value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Get the named attribute of the resource. "name" and "id" are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * currently defined. NULL if tag not defined. Currently we don't do
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * much, but additional checking may be needed in the future.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsa_set_resource_attr(sa_resource_t resource, char *tag, char *value)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_resource_parent(resource_t)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns the share associated with the resource.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * find_resource(group, name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Find the resource within the group.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Iterate over all the shares and resources in the group. */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_find_resource(name)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Find the named resource in the system.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Iterate over all groups and zfs subgroups and check for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource name in them.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_resource(group, resource)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Search all the shares in the specified group for a share with a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource name matching the one specified.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * In the future, it may be advantageous to allow group to be NULL and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * search all groups but that isn't needed at present.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * get_protocol_list(optionset, object)
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * Get the protocol optionset list for the object and add them as
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * properties to optionset.
f85463f27ee24416b2ed04366664846e9b14ba9bdougmget_protocol_list(sa_optionset_t optionset, void *object)
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * It is possible to have a non-protocol optionset. We
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * skip any of those found.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm prop = (sa_property_t)xmlAddChild((xmlNodePtr)optionset,
f85463f27ee24416b2ed04366664846e9b14ba9bdougm /* If prop is NULL, don't bother continuing */
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * sa_free_protoset(optionset)
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * Free the protocol property optionset.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * sa_optionset_t sa_get_active_protocols(object)
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * Return a list of the protocols that are active for the object.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * This is currently an internal helper function, but could be
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * made visible if there is enough demand for it.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * The function finds the parent group and extracts the protocol
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * optionsets creating a new optionset with the protocols as properties.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * The caller must free the returned optionset.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm options = (sa_optionset_t)xmlNewNode(NULL, (xmlChar *)"optionset");
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * Find the objects up the tree that might have protocols
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * enabled on them.
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * If there was an error, we won't have a complete list so
f85463f27ee24416b2ed04366664846e9b14ba9bdougm * abandon everything. The caller will have to deal with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_enable_resource, protocol)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Disable the specified share to the specified protocol.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If protocol is NULL, then all protocols.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsa_enable_resource(sa_resource_t resource, char *protocol)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* need to do all protocols */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_disable_resource(resource, protocol)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Disable the specified share for the specified protocol. If
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * protocol is NULL, then all protocols. If the underlying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * protocol doesn't implement disable at the resource level, we
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * disable at the share level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsa_disable_resource(sa_resource_t resource, char *protocol)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The protocol doesn't implement unshare
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * resource. That implies that resource names are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * simple aliases for this protocol so we need to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unshare the share.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* need to do all protocols */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_set_resource_description(resource, content)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set the description of share to content.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsa_set_resource_description(sa_resource_t resource, char *content)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (xmlStrcmp(node->name, (xmlChar *)"description") == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* no existing description but want to add */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* add a description */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* update a description */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* remove an existing description */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sa_get_resource_description(share)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Return the description text for the specified share if it
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * exists. NULL if no description exists.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (node = ((xmlNodePtr)resource)->children; node != NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (xmlStrcmp(node->name, (xmlChar *)"description") == 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return ((char *)description);