libshare.c revision 573b0c00a1ee520c3f6938dda8d693236f37ae60
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Share control API
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include "libshare.h"
#include "libshare_impl.h"
#include <libscf.h>
#include "scfutil.h"
#include <ctype.h>
#include <libintl.h>
#include <thread.h>
#include <synch.h>
#if _NOT_SMF
#define CONFIG_FILE "/var/tmp/share.cfg"
#define CONFIG_FILE_TMP "/var/tmp/share.cfg.tmp"
#endif
#define DFS_LOCK_FILE "/etc/dfs/fstypes"
/*
* internal object type values returned by sa_get_object_type()
*/
#define SA_TYPE_UNKNOWN 0
#define SA_TYPE_GROUP 1
#define SA_TYPE_SHARE 2
#define SA_TYPE_RESOURCE 3
#define SA_TYPE_OPTIONSET 4
#define SA_TYPE_ALTSPACE 5
/*
* internal data structures
*/
extern struct sa_proto_plugin *sap_proto_list;
extern int sa_valid_property(void *, char *, sa_property_t);
extern char *sa_fstype(char *);
extern int sa_is_share(void *);
extern int sa_is_resource(void *);
extern int sa_group_is_zfs(sa_group_t);
extern int sa_path_is_zfs(char *);
extern int sa_zfs_set_sharenfs(sa_group_t, char *, int);
extern int sa_zfs_set_sharesmb(sa_group_t, char *, int);
extern void update_legacy_config(sa_handle_t);
extern int issubdir(char *, char *);
extern int sa_zfs_init(sa_handle_impl_t);
extern void sa_zfs_fini(sa_handle_impl_t);
extern void sablocksigs(sigset_t *);
extern void saunblocksigs(sigset_t *);
static char *get_node_attr(void *, char *);
/*
* handle mapping. The list isn't expected to grow very large so a
* simple list is acceptable. The purpose is to provide a way to start
* with a group or share and find the library handle needed for
* various operations.
*/
struct doc2handle {
struct doc2handle *next;
};
/* definitions used in a couple of property functions */
#define SA_PROP_OP_REMOVE 1
#define SA_PROP_OP_ADD 2
#define SA_PROP_OP_UPDATE 3
/* helper functions */
/*
* sa_errorstr(err)
*
* convert an error value to an error string
*/
char *
sa_errorstr(int err)
{
static char errstr[32];
switch (err) {
case SA_OK:
break;
case SA_NO_SUCH_PATH:
break;
case SA_NO_MEMORY:
break;
case SA_DUPLICATE_NAME:
break;
case SA_BAD_PATH:
break;
case SA_NO_SUCH_GROUP:
break;
case SA_CONFIG_ERR:
break;
case SA_SYSTEM_ERR:
break;
case SA_SYNTAX_ERR:
break;
case SA_NO_PERMISSION:
break;
case SA_BUSY:
break;
case SA_NO_SUCH_PROP:
break;
case SA_INVALID_NAME:
break;
case SA_INVALID_PROTOCOL:
break;
case SA_NOT_ALLOWED:
break;
case SA_BAD_VALUE:
break;
case SA_INVALID_SECURITY:
break;
case SA_NO_SUCH_SECURITY:
break;
case SA_VALUE_CONFLICT:
break;
case SA_NOT_IMPLEMENTED:
break;
case SA_INVALID_PATH:
break;
case SA_NOT_SUPPORTED:
break;
case SA_PROP_SHARE_ONLY:
break;
case SA_NOT_SHARED:
break;
case SA_NO_SUCH_RESOURCE:
break;
case SA_RESOURCE_REQUIRED:
break;
case SA_MULTIPLE_ERROR:
break;
case SA_PATH_IS_SUBDIR:
break;
case SA_PATH_IS_PARENTDIR:
break;
default:
}
return (ret);
}
/*
* Document root to active handle mapping functions. These are only
* used internally. A mutex is used to prevent access while the list
* is changing. In general, the list will be relatively short - one
* item per thread that has called sa_init().
*/
{
struct doc2handle *item;
(void) mutex_lock(&sa_global_lock);
break;
}
(void) mutex_unlock(&sa_global_lock);
return (NULL);
}
static int
{
struct doc2handle *item;
int ret = SA_NO_MEMORY;
(void) mutex_lock(&sa_global_lock);
(void) mutex_unlock(&sa_global_lock);
}
return (ret);
}
/*
* remove_handle_for_root(root)
*
* Walks the list of handles and removes the one for this "root" from
* the list. It is up to the caller to free the data.
*/
static void
{
(void) mutex_lock(&sa_global_lock);
/* first in the list */
else
/* Item is out of the list so free the list structure */
break;
}
}
(void) mutex_unlock(&sa_global_lock);
}
/*
* sa_find_group_handle(sa_group_t group)
*
* Find the sa_handle_t for the configuration associated with this
* group.
*/
{
/* have the root so get the handle */
return (handle);
}
}
return (NULL);
}
/*
* set_legacy_timestamp(root, path, timevalue)
*
* add the current timestamp value to the configuration for use in
* determining when to update the legacy files. For SMF, this
* property is kept in default/operation/legacy_timestamp
*/
static void
{
/* Have to have a handle or else we weren't initialized. */
return;
/* a possible legacy node for this path */
break;
}
}
}
/* need to create the first legacy timestamp node */
}
char tstring[32];
int ret;
/* now commit to SMF */
"operation");
"legacy-timestamp", tstring);
(void) sa_end_transaction(
} else {
}
}
}
}
}
/*
* is_shared(share)
*
* determine if the specified share is currently shared or not.
*/
static int
{
char *shared;
int result = 0; /* assume not */
result = 1;
}
return (result);
}
/*
* excluded_protocol(share, proto)
*
* Returns B_TRUE if the specified protocol appears in the "exclude"
* property. This is used to prevent sharing special case shares
* (e.g. subdirs when SMB wants a subdir and NFS doesn't. B_FALSE is
* returned if the protocol isn't in the list.
*/
static boolean_t
{
char *protolist;
char *str;
char *token;
return (B_TRUE);
}
}
}
return (B_FALSE);
}
/*
* checksubdirgroup(group, newpath, strictness)
*
* check all the specified newpath against all the paths in the
* group. This is a helper function for checksubdir to make it easier
* to also check ZFS subgroups.
* The strictness values mean:
* SA_CHECK_NORMAL == only check newpath against shares that are active
* SA_CHECK_STRICT == check newpath against both active shares and those
* stored in the repository
*/
static int
{
char *path;
int subdir;
int parent;
return (SA_INVALID_PATH);
/*
* The original behavior of share never checked
* against the permanent configuration
* it depends on this older behavior even though it
* could be considered incorrect. We may tighten this
* up in the future.
*/
continue;
/*
* If path is NULL, then a share is in the process of
* construction or someone has modified the property
* group inappropriately. It should be
* ignored. issubdir() comes from the original share
* implementation and does the difficult part of
* checking subdirectories.
*/
continue;
} else {
return (subdir ?
}
}
}
return (issub);
}
/*
* checksubdir(newpath, strictness)
*
* checksubdir determines if the specified path (newpath) is a
* subdirectory of another share. It calls checksubdirgroup() to do
* the complicated work. The strictness parameter determines how
* strict a check to make against the path. The strictness values
* mean: SA_CHECK_NORMAL == only check newpath against shares that are
* active SA_CHECK_STRICT == check newpath against both active shares
* and those * stored in the repository
*/
static int
{
if (sa_group_is_zfs(group)) {
} else {
}
}
return (issub);
}
/*
* validpath(path, strictness)
* determine if the provided path is valid for a share. It shouldn't
* be a sub-dir of an already shared path or the parent directory of a
* share path.
*/
static int
{
char *fstype;
if (*path != '/')
return (SA_BAD_PATH);
} else {
/*
* check for special case with file system
* that might have restrictions. For now, ZFS
* is the only case since it has its own idea
* of how to configure shares. We do this
* before subdir checking since things like
* ZFS will do that for us. This should also
* be done via plugin interface.
*/
}
}
}
return (error);
}
/*
*
* "group" can be either an sa_group_t or an sa_share_t. (void *)
* works since both thse types are also void *.
*/
int
sa_is_persistent(void *group)
{
char *type;
int persist = 1;
persist = 0;
return (persist);
}
/*
* sa_valid_group_name(name)
*
* check that the "name" contains only valid characters and otherwise
* fits the required naming conventions. Valid names must start with
* an alphabetic and the remainder may consist of only alphanumeric
* plus the '-' and '_' characters. This name limitation comes from
* inherent limitations in SMF.
*/
int
sa_valid_group_name(char *name)
{
int ret = 1;
char c;
ret = 0;
}
} else {
ret = 0;
}
} else {
ret = 0;
}
return (ret);
}
/*
* is_zfs_group(group)
* Determine if the specified group is a ZFS sharenfs group
*/
static int
{
int ret = 0;
else
ret = 1;
}
return (ret);
}
/*
* sa_get_object_type(object)
*
* This function returns a numeric value representing the object
* type. This allows using simpler checks when doing type specific
* operations.
*/
static int
sa_get_object_type(void *object)
{
int type;
else
assert(0);
return (type);
}
/*
* sa_optionset_name(optionset, oname, len, id)
* return the SMF name for the optionset. If id is not NULL, it
* will have the GUID value for a share and should be used
* instead of the keyword "optionset" which is used for
* groups. If the optionset doesn't have a protocol type
* associated with it, "default" is used. This shouldn't happen
* at this point but may be desirable in the future if there are
* protocol independent properties added. The name is returned in
* oname.
*/
static int
{
char *proto;
void *parent;
int ptype;
id = "optionset";
if (ptype != SA_TYPE_RESOURCE) {
} else {
char *index;
else
len = 0;
}
} else {
len = 0;
}
return (len);
}
/*
* sa_security_name(optionset, oname, len, id)
*
* return the SMF name for the security. If id is not NULL, it will
* have the GUID value for a share and should be used instead of the
* keyword "optionset" which is used for groups. If the optionset
* doesn't have a protocol type associated with it, "default" is
* used. This shouldn't happen at this point but may be desirable in
* the future if there are protocol independent properties added. The
* name is returned in oname. The security type is also encoded into
* the name. In the future, this wil *be handled a bit differently.
*/
static int
{
char *proto;
char *sectype;
id = "optionset";
return (len);
}
/*
* verifydefgroupopts(handle)
*
* Make sure a "default" group exists and has default protocols enabled.
*/
static void
{
/*
* NFS is the default for default group
*/
}
}
/*
* sa_init(init_service)
* Initialize the API
* find all the shared objects
* init the tables with all objects
* read in the current configuration
*/
sa_init(int init_service)
{
int legacy = 0;
int lockfd;
int updatelegacy = B_FALSE;
int err;
/* get protocol specific structures */
(void) proto_plugin_init();
if (init_service & SA_INIT_SHARE_API) {
/*
* initialize access into libzfs. We use this
* when collecting info about ZFS datasets and
* shares.
*/
(void) proto_plugin_fini();
return (NULL);
}
/*
* since we want to use SMF, initialize an svc handle
* and find out what is there.
*/
/*
* Need to lock the extraction of the
* configuration if the dfstab file has
* changed. Lock everything now and release if
* not needed. Use a file that isn't being
* manipulated by other parts of the system in
* order to not interfere with locking. Using
* dfstab doesn't work.
*/
sablocksigs(&old);
if (lockfd >= 0) {
extern int errno;
errno = 0;
/*
* Check whether we are going to need
* to merge any dfstab changes. This
* is done by comparing the value of
* legacy-timestamp with the current
* st_ctim of the file. If they are
* different, an update is needed and
* the file must remain locked until
* the merge is done in order to
* prevent multiple startups from
* changing the SMF repository at the
* same time. The first to get the
* lock will make any changes before
* the others can read the repository.
*/
(const char *)SA_SVC_FMRI_BASE
":default", "operation",
"legacy-timestamp");
char *i64;
NULL, 0);
} else {
/*
* We haven't set the
* timestamp before so do it.
*/
}
}
if (updatelegacy == B_FALSE) {
/* Don't need the lock anymore */
}
/*
* It is essential that the document tree and
* the internal list of roots to handles be
* setup before anything that might try to
* create a new object is called. The document
* tree is the combination of handle->doc and
* handle->tree. This allows searches,
* etc. when all you have is an object in the
* tree.
*/
(xmlChar *)"sharecfg");
handle);
err = sa_get_config(
} else {
err = SA_NO_MEMORY;
}
saunblocksigs(&old);
/*
* If we couldn't add the tree handle
* to the list, then things are going
* to fail badly. Might as well undo
* everything now and fail the
* sa_init().
*/
return (NULL);
}
if (tval == 0) {
/*
* first time so make sure
* default is setup
*/
}
if (updatelegacy == B_TRUE) {
sablocksigs(&old);
saunblocksigs(&old);
/*
* Safe to unlock now to allow
* others to run
*/
}
}
}
}
return ((sa_handle_t)handle);
}
/*
* sa_fini(handle)
* Uninitialize the API structures including the configuration
* data structures and ZFS related data.
*/
void
{
if (impl_handle != NULL) {
/*
* Free the config trees and any other data structures
* used in the handle.
*/
/* Remove and free the entry in the global list. */
/* Make sure we free the handle */
/*
* If this was the last handle to release, unload the
* plugins that were loaded.
*/
if (sa_global_handles == NULL)
(void) proto_plugin_fini();
}
}
/*
* sa_get_protocols(char **protocol)
* Get array of protocols that are supported
* Returns pointer to an allocated and NULL terminated
* array of strings. Caller must free.
* This really should be determined dynamically.
* If there aren't any defined, return -1.
* Use free() to return memory.
*/
int
sa_get_protocols(char ***protocols)
{
int numproto = -1;
struct sa_proto_plugin *plug;
numproto++;
}
int ret = 0;
/* faking for now */
}
} else {
numproto = -1;
}
}
return (numproto);
}
/*
* find_group_by_name(node, group)
*
* search the XML document subtree specified by node to find the group
* specified by group. Searching subtree allows subgroups to be
* searched for.
*/
static xmlNodePtr
{
/* if no groupname, return the first found */
break;
break;
}
}
}
return (node);
}
/*
* sa_get_group(groupname)
* Return the "group" specified. If groupname is NULL,
* return the first group of the list of groups.
*/
{
*subgroup++ = '\0';
}
}
/*
* We want to find the, possibly, named group. If
* group is not NULL, then lookup the name. If it is
* NULL, we only do the find if groupname is also
* NULL. This allows lookup of the "first" group in
* the internal list.
*/
/* if a subgroup, find it before returning */
}
return ((sa_group_t)(node));
}
/*
* sa_get_next_group(group)
* Return the "next" group after the specified group from
* the internal group list. NULL if there are no more.
*/
{
break;
}
}
return ((sa_group_t)ngroup);
}
/*
* sa_get_share(group, sharepath)
* Return the share object for the share specified. The share
* must be in the specified group. Return NULL if not found.
*/
{
/*
* For future scalability, this should end up building a cache
* since it will get called regularly by the mountd and info
* services.
*/
break;
} else {
/* is it the correct share? */
(xmlChar *)"path");
break;
}
}
}
}
}
return ((sa_share_t)node);
}
/*
* sa_get_next_share(share)
* Return the next share following the specified share
* from the internal list of shares. Returns NULL if there
* are no more shares. The list is relative to the same
* group.
*/
{
break;
}
}
}
return ((sa_share_t)node);
}
/*
* _sa_get_child_node(node, type)
*
* find the child node of the specified node that has "type". This is
* used to implement several internal functions.
*/
static xmlNodePtr
{
return (child);
return ((xmlNodePtr)NULL);
}
/*
* find_share(group, path)
*
* Search all the shares in the specified group for one that has the
* specified path.
*/
static sa_share_t
{
char *path;
break;
}
}
return (share);
}
/*
* sa_get_sub_group(group)
*
* Get the first sub-group of group. The sa_get_next_group() function
* can be used to get the rest. This is currently only used for ZFS
* sub-groups but could be used to implement a more general mechanism.
*/
{
(xmlChar *)"group"));
}
/*
* sa_find_share(sharepath)
* Finds a share regardless of group. In the future, this
* function should utilize a cache and hash table of some kind.
* The current assumption is that a path will only be shared
* once. In the future, this may change as implementation of
* resource names comes into being.
*/
{
int done = 0;
if (is_zfs_group(group)) {
for (zgroup =
(xmlChar *)"group");
break;
}
} else {
}
break;
}
return (share);
}
/*
* sa_check_path(group, path, strictness)
*
* Check that path is a valid path relative to the group. Currently,
* we are ignoring the group and checking only the NFS rules. Later,
* we may want to use the group to then check against the protocols
* enabled on the group. The strictness values mean:
* SA_CHECK_NORMAL == only check newpath against shares that are active
* SA_CHECK_STRICT == check newpath against both active shares and those
* stored in the repository
*/
int
{
}
/*
* mark_excluded_protos(group, share, flags)
*
* Walk through all the protocols enabled for the group and check to
* see if the share has any of them should be in the exclude list
* based on the featureset of the protocol. If there are any, add the
* "exclude" property to the share.
*/
static void
{
char exclude_list[SA_STRSIZE];
char *sep = "";
exclude_list[0] = '\0';
char *value;
continue;
sizeof (exclude_list));
sizeof (exclude_list));
sep = ",";
}
}
if (exclude_list[0] != '\0')
(xmlChar *)exclude_list);
}
/*
* get_all_features(group)
*
* Walk through all the protocols on the group and collect all
* possible enabled features. This is the OR of all the featuresets.
*/
static uint64_t
{
char *value;
continue;
}
return (features);
}
/*
* _sa_add_share(group, sharepath, persist, *error, flags)
*
* Common code for all types of add_share. sa_add_share() is the
* public API, we also need to be able to do this when parsing legacy
* files and construction of the internal configuration while
* extracting config info from SMF. "flags" indicates if some
* protocols need relaxed rules while other don't. These values are
* the featureset values defined in libshare.h.
*/
{
int err;
*error = SA_NO_MEMORY;
return (node);
}
if (flags != 0)
if (persist != SA_SHARE_TRANSIENT) {
/*
* persistent shares come in two flavors: SMF and
* ZFS. Sort this one out based on target group and
* path type. Both NFS and SMB are supported. First,
* check to see if the protocol is enabled on the
* subgroup and then setup the share appropriately.
*/
if (sa_group_is_zfs(group) &&
} else {
if (impl_handle != NULL) {
} else {
err = SA_SYSTEM_ERR;
}
}
}
/* called by the dfstab parser so could be a show */
/*
* we couldn't commit to the repository so undo
* our internal state to reflect reality.
*/
}
return (node);
}
/*
* sa_add_share(group, sharepath, persist, *error)
*
* Add a new share object to the specified group. The share will
* have the specified sharepath and will only be constructed if
* it is a valid path to be shared. NULL is returned on error
* and a detailed error value will be returned via the error
* pointer.
*/
{
int strictness = SA_CHECK_NORMAL;
/*
* If the share is to be permanent, use strict checking so a
* bad config doesn't get created. Transient shares only need
* to check against the currently active
* shares. SA_SHARE_PARSER is a modifier used internally to
* indicate that we are being called by the dfstab parser and
* that we need strict checking in all cases. Normally persist
* is in integer value but SA_SHARE_PARSER may be or'd into
* it as an override.
*/
/*
* need to determine if the share is valid. The rules are:
* - The path must not already exist
* - The path must not be a subdir or parent dir of an
* existing path unless at least one protocol allows it.
*/
switch (*error) {
case SA_PATH_IS_SUBDIR:
if (features & SA_FEATURE_ALLOWSUBDIRS)
break;
case SA_PATH_IS_PARENTDIR:
if (features & SA_FEATURE_ALLOWPARDIRS)
break;
}
} else {
}
return ((sa_share_t)node);
}
/*
* sa_enable_share(share, protocol)
* Enable the specified share to the specified protocol.
* If protocol is NULL, then all protocols.
*/
int
{
char *sharepath;
int ret;
return (SA_NO_MEMORY);
} else {
/* tell the server about the share */
goto done;
/* lookup protocol specific handler */
(void) sa_set_share_attr(share,
"shared", "true");
} else {
/* Tell all protocols about the share */
char *proto;
"type");
share);
}
}
}
}
}
done:
return (err);
}
/*
* sa_disable_share(share, protocol)
* Disable the specified share to the specified protocol. If
* protocol is NULL, then all protocols that are enabled for the
* share should be disabled.
*/
int
{
char *path;
} else {
/* need to do all protocols */
/* Tell all protocols about the share */
char *proto;
}
}
}
return (ret);
}
/*
* sa_remove_share(share)
*
* remove the specified share from its containing group.
* Remove from the SMF or ZFS configuration space.
*/
int
{
char *type;
int transient = 0;
char *groupname;
char *zfs;
transient = 1;
/* remove the node from its group then free the memory */
/*
* need to test if "busy"
*/
/* only do SMF action if permanent */
/* remove from legacy dfstab as well as possible SMF */
if (!sa_group_is_zfs(group)) {
if (impl_handle != NULL) {
share);
} else {
ret = SA_SYSTEM_ERR;
}
} else {
"path");
sharepath, 0);
}
}
}
}
return (ret);
}
/*
* sa_move_share(group, share)
*
* move the specified share to the specified group. Update SMF
* appropriately.
*/
int
{
/* remove the node from its group then free the memory */
/*
* now that the share isn't in its old group, add to
* the new one
*/
/* need to deal with SMF */
if (impl_handle != NULL) {
/*
* need to remove from old group first and then add to
* new group. Ideally, we would do the other order but
* need to avoid having the share in two groups at the
* same time.
*/
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
return (ret);
}
/*
* sa_get_parent_group(share)
*
* Return the containing group for the share. If a group was actually
* passed in, we don't want a parent so return NULL.
*/
{
/*
* make sure parent is a group and not sharecfg since
* we may be cheating and passing in a group.
* Eventually, groups of groups might come into being.
*/
}
return ((sa_group_t)node);
}
/*
* _sa_create_group(impl_handle, groupname)
*
* Create a group in the document. The caller will need to deal with
* configuration store and activation.
*/
{
if (sa_valid_group_name(groupname)) {
NULL);
(xmlChar *)"enabled");
}
}
return ((sa_group_t)node);
}
/*
* _sa_create_zfs_group(group, groupname)
*
* Create a ZFS subgroup under the specified group. This may
* eventually form the basis of general sub-groups, but is currently
* restricted to ZFS.
*/
{
}
return ((sa_group_t)node);
}
/*
* sa_create_group(groupname, *error)
*
* Create a new group with groupname. Need to validate that it is a
* legal name for SMF and the construct the SMF service instance of
* operational properties must be added to the group at this point
* (via the SMF transaction model).
*/
{
int ret;
char rbacstr[SA_STRSIZE];
ret = SA_SYSTEM_ERR;
goto err;
}
} else {
if (sa_valid_group_name(groupname)) {
/* default to the group being enabled */
(xmlChar *)"enabled");
"operation");
}
"state", "enabled");
} else {
}
}
/* initialize the RBAC strings */
"general");
sizeof (rbacstr), "%s.%s",
"action_authorization",
rbacstr);
}
sizeof (rbacstr), "%s.%s",
"value_authorization",
rbacstr);
}
} else {
}
}
/*
* Couldn't commit the group
* so we need to undo
* internally.
*/
}
} else {
ret = SA_NO_MEMORY;
}
} else {
}
}
err:
return ((sa_group_t)node);
}
/*
* sa_remove_group(group)
*
* Remove the specified group. This deletes from the SMF repository.
* All property groups and properties are removed.
*/
int
{
char *name;
if (impl_handle != NULL) {
}
} else {
ret = SA_SYSTEM_ERR;
}
return (ret);
}
/*
* sa_update_config()
*
* Used to update legacy files that need to be updated in bulk
* Currently, this is a placeholder and will go away in a future
* release.
*/
int
{
/*
* do legacy files first so we can tell when they change.
* This will go away when we start updating individual records
* rather than the whole file.
*/
return (SA_OK);
}
/*
* get_node_attr(node, tag)
*
* Get the specified tag(attribute) if it exists on the node. This is
* used internally by a number of attribute oriented functions.
*/
static char *
{
return ((char *)name);
}
/*
* get_node_attr(node, tag)
*
* Set the specified tag(attribute) to the specified value This is
* used internally by a number of attribute oriented functions. It
* doesn't update the repository, only the internal document state.
*/
void
{
else
}
}
/*
* sa_get_group_attr(group, tag)
*
* Get the specied attribute, if defined, for the group.
*/
char *
{
}
/*
* sa_set_group_attr(group, tag, value)
*
* value.
*
* This will result in setting the property in the SMF repository as
* well as in the internal document.
*/
int
{
int ret;
char *groupname;
/*
*/
if (sa_group_is_zfs(group)) {
return (SA_OK);
}
if (impl_handle != NULL) {
"operation");
else
}
if (ret == SA_SYSTEM_ERR)
}
} else {
ret = SA_SYSTEM_ERR;
}
return (ret);
}
/*
* sa_get_share_attr(share, tag)
*
* share. Returns NULL if the tag doesn't exist.
*/
char *
{
}
/*
* _sa_set_share_description(share, description)
*
* Add a description tag with text contents to the specified share. A
* separate XML tag is used rather than a property. This can also be
* used with resources.
*/
{
NULL);
return (node);
}
/*
* sa_set_share_attr(share, tag, value)
*
* Set the share attribute specified by tag to the specified value. In
* the case of "resource", enforce a no duplicates in a group rule. If
* the share is not transient, commit the changes to the repository
* else just update the share internally.
*/
int
{
/*
* There are some attributes that may have specific
* restrictions on them. Initially, only "resource" has
* special meaning that needs to be checked. Only one instance
* of a resource name may exist within a group.
*/
}
char *type;
/* we can probably optimize this some */
group);
if (impl_handle != NULL) {
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
}
}
return (ret);
}
/*
* sa_get_property_attr(prop, tag)
*
* Get the value of the specified property attribute. Standard
* attributes are "type" and "value".
*/
char *
{
}
/*
* sa_get_optionset_attr(prop, tag)
*
* Get the value of the specified property attribute. Standard
* attribute is "type".
*/
char *
{
}
/*
* sa_set_optionset_attr(optionset, tag, value)
*
* Set the specified attribute(tag) to the specified value on the
* optionset.
*/
void
{
}
/*
* sa_free_attr_string(string)
*
* Free the string that was returned in one of the sa_get_*_attr()
* functions.
*/
void
sa_free_attr_string(char *string)
{
}
/*
* sa_get_optionset(group, proto)
*
* Return the optionset, if it exists, that is associated with the
* specified protocol.
*/
{
break;
}
}
} else {
break;
}
}
}
return ((sa_optionset_t)node);
}
/*
* sa_get_next_optionset(optionset)
*
* Return the next optionset in the group. NULL if this was the last.
*/
{
break;
}
}
return ((sa_optionset_t)node);
}
/*
* sa_get_security(group, sectype, proto)
*
* Return the security optionset. The internal name is a hold over
* from the implementation and will be changed before the API is
* finalized. This is really a named optionset that can be negotiated
* as a group of properties (like NFS security options).
*/
{
/* it doesn't match so continue */
continue;
}
}
}
/* potential match */
break;
}
} else {
break;
}
}
}
}
return ((sa_security_t)node);
}
/*
* sa_get_next_security(security)
*
* Get the next security optionset if one exists.
*/
{
break;
}
}
return ((sa_security_t)node);
}
/*
* sa_get_property(optionset, prop)
*
* Get the property object with the name specified in prop from the
* optionset.
*/
{
return (NULL);
break;
break;
}
}
}
}
/*
* avoid a non option node -- it is possible to be a
* text node
*/
}
return ((sa_property_t)node);
}
/*
* sa_get_next_property(property)
*
* Get the next property following the specified property. NULL if
* this was the last.
*/
{
break;
}
}
return ((sa_property_t)node);
}
/*
* sa_set_share_description(share, content)
*
* Set the description of share to content.
*/
int
{
break;
}
}
/* no existing description but want to add */
/* add a description */
/* update a description */
/* remove an existing description */
}
if (impl_handle != NULL) {
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
return (ret);
}
/*
* fixproblemchars(string)
*
* don't want any newline or tab characters in the text since these
* could break display of data and legacy file formats.
*/
static void
fixproblemchars(char *str)
{
int c;
if (c == '\t' || c == '\n')
*str = ' ';
else if (c == '"')
*str = '\'';
}
}
/*
* sa_get_share_description(share)
*
* Return the description text for the specified share if it
* exists. NULL if no description exists.
*/
char *
{
break;
}
}
fixproblemchars((char *)description);
}
return ((char *)description);
}
/*
* sa_free(share_description(description)
*
* Free the description string.
*/
void
{
}
/*
* sa_create_optionset(group, proto)
*
* Create an optionset for the specified protocol in the specied
* group. This is manifested as a property group within SMF.
*/
{
/* can't have a duplicate protocol */
} else {
/*
* Account for resource names being slightly
* different.
*/
if (sa_is_share(group)) {
/*
* Transient shares do not have an "id" so not an
* error to not find one.
*/
} else if (sa_is_resource(group)) {
/* id can be NULL if the group is transient (ZFS) */
err = SA_NO_MEMORY;
}
if (err == SA_NO_MEMORY) {
/*
* Couldn't get the id for the share or
* resource. While this could be a
* configuration issue, it is most likely an
* out of memory. In any case, fail the create.
*/
return (NULL);
}
/*
* only put to repository if on a group and we were
* able to create an optionset.
*/
char oname[SA_STRSIZE];
char *groupname;
/*
* Need to get parent group in all cases, but also get
* the share if this is a resource.
*/
if (sa_is_share(group)) {
} else if (sa_is_resource(group)) {
}
group);
if (impl_handle != NULL) {
(void) sa_get_instance(
(void) sa_create_pgroup(
}
}
}
}
return (optionset);
}
/*
* sa_get_property_parent(property)
*
* Given a property, return the object it is a property of. This will
* be an optionset of some type.
*/
static sa_optionset_t
{
return ((sa_optionset_t)node);
}
/*
* sa_get_optionset_parent(optionset)
*
* Return the parent of the specified optionset. This could be a group
* or a share.
*/
static sa_group_t
{
return ((sa_group_t)node);
}
/*
* zfs_needs_update(share)
*
* In order to avoid making multiple updates to a ZFS share when
* setting properties, the share attribute "changed" will be set to
* true when a property is added or modified. When done adding
* properties, we can then detect that an update is needed. We then
* clear the state here to detect additional changes.
*/
static int
{
char *attr;
int result = 0;
result = 1;
}
return (result);
}
/*
* zfs_set_update(share)
*
* Set the changed attribute of the share to true.
*/
static void
{
}
/*
* sa_commit_properties(optionset, clear)
*
* Check if SMF or ZFS config and either update or abort the pending
* changes.
*/
int
{
int zfs = 0;
int needsupdate = 0;
/* only update ZFS if on a share */
zfs++;
else
zfs = 0;
}
if (zfs) {
if (!clear && needsupdate)
} else {
if (impl_handle != NULL) {
if (clear) {
(void) sa_abort_transaction(
} else {
}
} else {
ret = SA_SYSTEM_ERR;
}
}
return (ret);
}
/*
* sa_destroy_optionset(optionset)
*
* Remove the optionset from its group. Update the repository to
* reflect this change.
*/
int
{
char name[SA_STRSIZE];
int len;
int ret;
int ispersist = 1;
/* now delete the prop group */
if (sa_is_resource(group)) {
} else if (sa_is_share(group)) {
}
}
if (ispersist) {
if (impl_handle != NULL) {
if (len > 0) {
name);
}
} else {
ret = SA_SYSTEM_ERR;
}
}
return (ret);
}
/* private to the implementation */
int
{
return (ret);
}
/*
* sa_create_security(group, sectype, proto)
*
* Create a security optionset (one that has a type name and a
* proto). Security is left over from a pure NFS implementation. The
* naming will change in the future when the API is released.
*/
{
}
/* can't have a duplicate security option */
} else {
char oname[SA_STRSIZE];
group);
if (impl_handle != NULL) {
(void) sa_get_instance(
(void) sa_create_pgroup(
}
}
}
}
return (security);
}
/*
* sa_destroy_security(security)
*
* Remove the specified optionset from the document and the
* configuration.
*/
int
{
char name[SA_STRSIZE];
int len;
int iszfs = 0;
int ispersist = 1;
if (sa_is_share(group))
}
if (ispersist) {
if (impl_handle != NULL) {
name);
} else {
ret = SA_SYSTEM_ERR;
}
}
}
if (iszfs)
return (ret);
}
/*
* sa_get_security_attr(optionset, tag)
*
* Return the specified attribute value from the optionset.
*/
char *
{
}
/*
* sa_set_security_attr(optionset, tag, value)
*
* Set the optioset attribute specied by tag to the specified value.
*/
void
{
}
/*
* is_nodetype(node, type)
*
* Check to see if node is of the type specified.
*/
static int
{
}
/*
* add_or_update()
*
* Add or update a property. Pulled out of sa_set_prop_by_prop for
* readability.
*/
static int
{
int ret = SA_SYSTEM_ERR;
if (type == SA_PROP_OP_ADD)
else
if (ret == 0) {
if (ret == 0)
if (ret == 0)
return (ret);
} else {
}
}
return (SA_SYSTEM_ERR);
}
/*
* sa_set_prop_by_prop(optionset, group, prop, type)
*
* share. If a share, sort out which property group based on GUID. In
* all cases, the appropriate transaction is set (or ZFS share is
* marked as needing an update)
*/
static int
{
char *name;
char *valstr;
int opttype; /* 1 == optionset, 0 == security */
int iszfs = 0;
if (!sa_is_persistent(group)) {
/*
* to do anything here
*/
return (SA_OK);
}
return (SA_SYSTEM_ERR);
/*
* Check for share vs. resource since they need slightly
* different treatment given the hierarchy.
*/
if (sa_is_share(group)) {
} else if (sa_is_resource(group)) {
} else {
}
if (!iszfs) {
char oname[SA_STRSIZE];
"name");
} else {
"name");
}
}
if (opttype)
(void) sa_optionset_name(optionset,
else
(void) sa_security_name(optionset,
}
switch (type) {
case SA_PROP_OP_REMOVE:
break;
case SA_PROP_OP_ADD:
case SA_PROP_OP_UPDATE:
scf_handle->handle);
break;
}
}
} else {
/*
* ZFS update. The calling function would have updated
* the internal XML structure. Just need to flag it as
* changed for ZFS.
*/
}
}
if (ret == -1)
ret = SA_SYSTEM_ERR;
return (ret);
}
/*
* sa_create_property(name, value)
*
* Create a new property with the specified name and value.
*/
{
}
return ((sa_property_t)node);
}
/*
* sa_add_property(object, property)
*
* Add the specified property to the object. Issue the appropriate
* transaction or mark a ZFS object as needing an update.
*/
int
{
char *proto;
SA_OK) {
} else {
return (ret);
}
}
if (!sa_is_persistent(parent))
return (ret);
if (sa_is_resource(parent)) {
/*
* Resources are children of share. Need to go up two
* levels to find the group but the parent needs to be
* the share at this point in order to get the "id".
*/
} else if (sa_is_share(parent)) {
} else {
}
ret = SA_NO_MEMORY;
} else {
char oname[SA_STRSIZE];
if (!is_zfs_group(group)) {
group);
if (impl_handle == NULL ||
ret = SA_SYSTEM_ERR;
}
(void) sa_optionset_name(
} else {
(void) sa_security_name(
}
oname);
}
char *name;
char *value;
"type");
"value");
if (scf_handle->scf_state ==
value);
}
} else {
ret = SA_CONFIG_ERR;
}
name);
}
}
} else {
/*
* ZFS is a special case. We do want
* lists since we can have a better
* syntax and we also want to keep
* things consistent when possible.
*
* Right now, we defer until the
* sa_commit_properties so we can get
* them all at once. We do need to
* mark the share as "changed"
*/
}
}
return (ret);
}
/*
* sa_remove_property(property)
*
* Remove the specied property from its containing object. Update the
* repository as appropriate.
*/
int
{
}
}
} else {
}
return (ret);
}
/*
* sa_update_property(property, value)
*
* Update the specified property to the new value. If value is NULL,
* we currently treat this as a remove.
*/
int
{
return (sa_remove_property(property));
} else {
}
} else {
}
}
return (ret);
}
/*
* sa_get_protocol_property(propset, prop)
*
* Get the specified protocol specific property. These are global to
* the protocol and not specific to a group or share.
*/
{
break;
break;
}
}
}
}
/*
* avoid a non option node -- it is possible to be a
* text node
*/
}
return ((sa_property_t)node);
}
/*
* sa_get_next_protocol_property(prop)
*
* Get the next protocol specific property in the list.
*/
{
break;
}
}
return ((sa_property_t)node);
}
/*
* sa_set_protocol_property(prop, value)
*
* Set the specified property to have the new value. The protocol
* specific plugin will then be called to update the property.
*/
int
{
char *proto;
int ret = SA_INVALID_PROTOCOL;
}
}
return (ret);
}
/*
* sa_add_protocol_property(propset, prop)
*
* Add a new property to the protocol specific property set.
*/
int
{
/* should check for legitimacy */
return (SA_OK);
return (SA_NO_MEMORY);
}
/*
* sa_create_protocol_properties(proto)
*
* Create a protocol specific property set.
*/
{
return (node);
}
/*
* sa_get_share_resource(share, resource)
*
* Get the named resource from the share, if it exists. If resource is
* NULL, get the first resource.
*/
{
/*
* We are looking for the first
* resource node and not a names
* resource.
*/
break;
} else {
/* is it the correct share? */
(xmlChar *)"name");
break;
}
}
}
}
}
return ((sa_resource_t)node);
}
/*
* sa_get_next_resource(resource)
* Return the next share following the specified share
* from the internal list of shares. Returns NULL if there
* are no more shares. The list is relative to the same
* group.
*/
{
break;
}
}
return ((sa_share_t)node);
}
/*
* _sa_get_next_resource_index(share)
*
* get the next resource index number (one greater then current largest)
*/
static int
{
int index = 0;
char *id;
int val;
}
}
return (index + 1);
}
/*
* sa_add_resource(share, resource, persist, &err)
*
* Adds a new resource name associated with share. The resource name
* must be unique in the system and will be case insensitive (eventually).
*/
{
int index;
} else {
if (persist != SA_SHARE_TRANSIENT) {
index);
if (!sa_group_is_zfs(group) &&
/* ZFS doesn't use resource names */
group);
share);
else
err = SA_SYSTEM_ERR;
}
}
}
}
return ((sa_resource_t)node);
}
/*
* sa_remove_resource(resource)
*
* Remove the resource name from the share (and the system)
*/
int
{
char *type;
int transient = 0;
transient = 1;
}
/* Disable the resource for all protocols. */
/* Remove any optionsets from the resource. */
(void) sa_destroy_optionset(opt);
/* Remove from the share */
/* only do SMF action if permanent and not ZFS */
else
ret = SA_SYSTEM_ERR;
}
return (ret);
}
/*
* proto_resource_rename(handle, group, resource, newname)
*
* Helper function for sa_rename_resource that notifies the protocol
* of a resource name change prior to a config repository update.
*/
static int
{
int err;
char *type;
newname);
}
}
return (ret);
}
/*
* sa_rename_resource(resource, newname)
*
* Rename the resource to the new name, if it is unique.
*/
int
{
int ret = SA_CONFIG_ERR;
return (ret);
return (ret);
return (ret);
} else {
/*
* Everything appears to be valid at this
* point. Change the name of the active share and then
* update the share in the appropriate repository.
*/
if (!sa_group_is_zfs(group) &&
share);
}
}
return (ret);
}
/*
* sa_get_resource_attr(resource, tag)
*
* Get the named attribute of the resource. "name" and "id" are
* currently defined. NULL if tag not defined.
*/
char *
{
}
/*
* sa_set_resource_attr(resource, tag, value)
*
* Get the named attribute of the resource. "name" and "id" are
* currently defined. NULL if tag not defined. Currently we don't do
* much, but additional checking may be needed in the future.
*/
int
{
return (SA_OK);
}
/*
* sa_get_resource_parent(resource_t)
*
* Returns the share associated with the resource.
*/
{
return (share);
}
/*
* find_resource(group, name)
*
* Find the resource within the group.
*/
static sa_resource_t
{
char *name;
/* Iterate over all the shares and resources in the group. */
break;
}
}
}
}
return (resource);
}
/*
* sa_find_resource(name)
*
* Find the named resource in the system.
*/
{
/*
* Iterate over all groups and zfs subgroups and check for
* resource name in them.
*/
if (is_zfs_group(group)) {
for (zgroup =
(xmlChar *)"group");
}
} else {
}
break;
}
return (resource);
}
/*
* sa_get_resource(group, resource)
*
* Search all the shares in the specified group for a share with a
* resource name matching the one specified.
*
* In the future, it may be advantageous to allow group to be NULL and
* search all groups but that isn't needed at present.
*/
{
}
}
return (res);
}
/*
* sa_enable_resource, protocol)
* Disable the specified share to the specified protocol.
* If protocol is NULL, then all protocols.
*/
int
{
char **protocols;
int numproto;
} else {
/* need to do all protocols */
int i, err;
for (i = 0; i < numproto; i++) {
}
}
}
return (ret);
}
/*
* sa_disable_resource(resource, protocol)
*
* Disable the specified share for the specified protocol. If
* protocol is NULL, then all protocols. If the underlying
* protocol doesn't implement disable at the resource level, we
* disable at the share level.
*/
int
{
char **protocols;
int numproto;
if (ret == SA_NOT_IMPLEMENTED) {
/*
* The protocol doesn't implement unshare
* resource. That implies that resource names are
* simple aliases for this protocol so we need to
* unshare the share.
*/
else
ret = SA_CONFIG_ERR;
}
} else {
/* need to do all protocols */
int i, err;
for (i = 0; i < numproto; i++) {
resource);
if (err == SA_NOT_SUPPORTED) {
resource);
protocols[i]);
else
err = SA_CONFIG_ERR;
}
}
}
}
return (ret);
}
/*
* sa_set_resource_description(resource, content)
*
* Set the description of share to content.
*/
int
{
break;
}
}
/* no existing description but want to add */
/* add a description */
/* update a description */
/* remove an existing description */
}
if (impl_handle != NULL)
else
ret = SA_SYSTEM_ERR;
}
return (ret);
}
/*
* sa_get_resource_description(share)
*
* Return the description text for the specified share if it
* exists. NULL if no description exists.
*/
char *
{
break;
}
fixproblemchars((char *)description);
}
return ((char *)description);
}