Print this page
4095 minor cleanup up libshare
*** 19,28 ****
--- 19,29 ----
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 RackTop Systems.
*/
/*
* Share control API
*/
*** 63,85 ****
extern struct sa_proto_plugin *sap_proto_list;
/* current SMF/SVC repository handle */
extern void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
! extern int gettransients(sa_handle_impl_t, xmlNodePtr *);
extern char *sa_fstype(char *);
! extern int sa_is_share(void *);
! extern int sa_is_resource(void *);
extern ssize_t scf_max_name_len; /* defined in scfutil during initialization */
! 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 sa_group_t sa_get_optionset_parent(sa_optionset_t);
static char *get_node_attr(void *, char *);
extern void sa_update_sharetab_ts(sa_handle_t);
--- 64,86 ----
extern struct sa_proto_plugin *sap_proto_list;
/* current SMF/SVC repository handle */
extern void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
! extern int gettransients(sa_handle_t, xmlNodePtr *);
extern char *sa_fstype(char *);
! extern boolean_t sa_is_share(void *);
! extern boolean_t sa_is_resource(void *);
extern ssize_t scf_max_name_len; /* defined in scfutil during initialization */
! extern boolean_t sa_group_is_zfs(sa_group_t);
! extern boolean_t 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_t);
! extern void sa_zfs_fini(sa_handle_t);
extern void sablocksigs(sigset_t *);
extern void saunblocksigs(sigset_t *);
static sa_group_t sa_get_optionset_parent(sa_optionset_t);
static char *get_node_attr(void *, char *);
extern void sa_update_sharetab_ts(sa_handle_t);
*** 93,103 ****
*/
mutex_t sa_global_lock;
struct doc2handle {
struct doc2handle *next;
xmlNodePtr root;
! sa_handle_impl_t handle;
};
mutex_t sa_dfstab_lock;
/* definitions used in a couple of property functions */
--- 94,104 ----
*/
mutex_t sa_global_lock;
struct doc2handle {
struct doc2handle *next;
xmlNodePtr root;
! sa_handle_t handle;
};
mutex_t sa_dfstab_lock;
/* definitions used in a couple of property functions */
*** 237,247 ****
* 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().
*/
! sa_handle_impl_t
get_handle_for_root(xmlNodePtr root)
{
struct doc2handle *item;
(void) mutex_lock(&sa_global_lock);
--- 238,248 ----
* 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().
*/
! sa_handle_t
get_handle_for_root(xmlNodePtr root)
{
struct doc2handle *item;
(void) mutex_lock(&sa_global_lock);
*** 254,264 ****
return (item->handle);
return (NULL);
}
static int
! add_handle_for_root(xmlNodePtr root, sa_handle_impl_t handle)
{
struct doc2handle *item;
int ret = SA_NO_MEMORY;
item = (struct doc2handle *)calloc(sizeof (struct doc2handle), 1);
--- 255,265 ----
return (item->handle);
return (NULL);
}
static int
! add_handle_for_root(xmlNodePtr root, sa_handle_t handle)
{
struct doc2handle *item;
int ret = SA_NO_MEMORY;
item = (struct doc2handle *)calloc(sizeof (struct doc2handle), 1);
*** 317,327 ****
sa_handle_t handle;
while (node != NULL) {
if (strcmp((char *)(node->name), "sharecfg") == 0) {
/* have the root so get the handle */
! handle = (sa_handle_t)get_handle_for_root(node);
return (handle);
}
node = node->parent;
}
return (NULL);
--- 318,328 ----
sa_handle_t handle;
while (node != NULL) {
if (strcmp((char *)(node->name), "sharecfg") == 0) {
/* have the root so get the handle */
! handle = get_handle_for_root(node);
return (handle);
}
node = node->parent;
}
return (NULL);
*** 338,348 ****
static void
set_legacy_timestamp(xmlNodePtr root, char *path, uint64_t tval)
{
xmlNodePtr node;
xmlChar *lpath = NULL;
! sa_handle_impl_t handle;
/* Have to have a handle or else we weren't initialized. */
handle = get_handle_for_root(root);
if (handle == NULL)
return;
--- 339,349 ----
static void
set_legacy_timestamp(xmlNodePtr root, char *path, uint64_t tval)
{
xmlNodePtr node;
xmlChar *lpath = NULL;
! sa_handle_t handle;
/* Have to have a handle or else we weren't initialized. */
handle = get_handle_for_root(root);
if (handle == NULL)
return;
*** 598,624 ****
*
* "group" can be either an sa_group_t or an sa_share_t. (void *)
* works since both thse types are also void *.
* If the share is a ZFS share, mark it as persistent.
*/
! int
sa_is_persistent(void *group)
{
char *type;
! int persist = 1;
sa_group_t grp;
type = sa_get_group_attr((sa_group_t)group, "type");
if (type != NULL) {
if (strcmp(type, "transient") == 0)
! persist = 0;
sa_free_attr_string(type);
}
grp = (sa_is_share(group)) ? sa_get_parent_group(group) : group;
if (sa_group_is_zfs(grp))
! persist = 1;
return (persist);
}
/*
--- 599,625 ----
*
* "group" can be either an sa_group_t or an sa_share_t. (void *)
* works since both thse types are also void *.
* If the share is a ZFS share, mark it as persistent.
*/
! boolean_t
sa_is_persistent(void *group)
{
char *type;
! boolean_t persist = B_TRUE;
sa_group_t grp;
type = sa_get_group_attr((sa_group_t)group, "type");
if (type != NULL) {
if (strcmp(type, "transient") == 0)
! persist = B_FALSE;
sa_free_attr_string(type);
}
grp = (sa_is_share(group)) ? sa_get_parent_group(group) : group;
if (sa_group_is_zfs(grp))
! persist = B_TRUE;
return (persist);
}
/*
*** 831,844 ****
uint64_t tval = 0;
int lockfd;
sigset_t old;
int updatelegacy = B_FALSE;
scf_simple_prop_t *prop;
! sa_handle_impl_t handle;
int err;
! handle = calloc(sizeof (struct sa_handle_impl), 1);
if (handle != NULL) {
/*
* Get protocol specific structures, but only if this
* is the only handle.
--- 832,845 ----
uint64_t tval = 0;
int lockfd;
sigset_t old;
int updatelegacy = B_FALSE;
scf_simple_prop_t *prop;
! sa_handle_t handle;
int err;
! handle = calloc(sizeof (struct sa_handle), 1);
if (handle != NULL) {
/*
* Get protocol specific structures, but only if this
* is the only handle.
*** 987,997 ****
verifydefgroupopts(handle);
}
if (updatelegacy == B_TRUE) {
sablocksigs(&old);
! getlegacyconfig((sa_handle_t)handle,
SA_LEGACY_DFSTAB, &handle->tree);
if (stat(SA_LEGACY_DFSTAB, &st) >= 0)
set_legacy_timestamp(
handle->tree,
SA_LEGACY_DFSTAB,
--- 988,998 ----
verifydefgroupopts(handle);
}
if (updatelegacy == B_TRUE) {
sablocksigs(&old);
! getlegacyconfig(handle,
SA_LEGACY_DFSTAB, &handle->tree);
if (stat(SA_LEGACY_DFSTAB, &st) >= 0)
set_legacy_timestamp(
handle->tree,
SA_LEGACY_DFSTAB,
*** 1004,1014 ****
(void) mutex_unlock(&sa_dfstab_lock);
(void) lockf(lockfd, F_ULOCK, 0);
(void) close(lockfd);
}
/* Get sharetab timestamp */
! sa_update_sharetab_ts((sa_handle_t)handle);
/* Get lastupdate (transaction) timestamp */
prop = scf_simple_prop_get(
handle->scfhandle->handle,
(const char *)SA_SVC_FMRI_BASE ":default",
--- 1005,1015 ----
(void) mutex_unlock(&sa_dfstab_lock);
(void) lockf(lockfd, F_ULOCK, 0);
(void) close(lockfd);
}
/* Get sharetab timestamp */
! sa_update_sharetab_ts(handle);
/* Get lastupdate (transaction) timestamp */
prop = scf_simple_prop_get(
handle->scfhandle->handle,
(const char *)SA_SVC_FMRI_BASE ":default",
*** 1027,1037 ****
legacy |= sa_get_zfs_shares(handle, "zfs");
legacy |= gettransients(handle, &handle->tree);
}
}
}
! return ((sa_handle_t)handle);
}
/*
* sa_fini(handle)
* Uninitialize the API structures including the configuration
--- 1028,1038 ----
legacy |= sa_get_zfs_shares(handle, "zfs");
legacy |= gettransients(handle, &handle->tree);
}
}
}
! return (handle);
}
/*
* sa_fini(handle)
* Uninitialize the API structures including the configuration
*** 1039,1060 ****
*/
void
sa_fini(sa_handle_t handle)
{
! sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
!
! if (impl_handle != NULL) {
/*
* Free the config trees and any other data structures
* used in the handle.
*/
! if (impl_handle->doc != NULL)
! xmlFreeDoc(impl_handle->doc);
/* Remove and free the entry in the global list. */
! remove_handle_for_root(impl_handle->tree);
/*
* If this was the last handle to release, unload the
* plugins that were loaded. Use a mutex in case
* another thread is reinitializing.
--- 1040,1059 ----
*/
void
sa_fini(sa_handle_t handle)
{
! if (handle != NULL) {
/*
* Free the config trees and any other data structures
* used in the handle.
*/
! if (handle->doc != NULL)
! xmlFreeDoc(handle->doc);
/* Remove and free the entry in the global list. */
! remove_handle_for_root(handle->tree);
/*
* If this was the last handle to release, unload the
* plugins that were loaded. Use a mutex in case
* another thread is reinitializing.
*** 1062,1076 ****
(void) mutex_lock(&sa_global_lock);
if (sa_global_handles == NULL)
(void) proto_plugin_fini();
(void) mutex_unlock(&sa_global_lock);
! sa_scf_fini(impl_handle->scfhandle);
! sa_zfs_fini(impl_handle);
/* Make sure we free the handle */
! free(impl_handle);
}
}
/*
--- 1061,1075 ----
(void) mutex_lock(&sa_global_lock);
if (sa_global_handles == NULL)
(void) proto_plugin_fini();
(void) mutex_unlock(&sa_global_lock);
! sa_scf_fini(handle->scfhandle);
! sa_zfs_fini(handle);
/* Make sure we free the handle */
! free(handle);
}
}
/*
*** 1153,1165 ****
sa_get_group(sa_handle_t handle, char *groupname)
{
xmlNodePtr node = NULL;
char *subgroup = NULL;
char *group = NULL;
- sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
! if (impl_handle != NULL && impl_handle->tree != NULL) {
if (groupname != NULL) {
group = strdup(groupname);
if (group != NULL) {
subgroup = strchr(group, '/');
if (subgroup != NULL)
--- 1152,1163 ----
sa_get_group(sa_handle_t handle, char *groupname)
{
xmlNodePtr node = NULL;
char *subgroup = NULL;
char *group = NULL;
! if (handle != NULL && handle->tree != NULL) {
if (groupname != NULL) {
group = strdup(groupname);
if (group != NULL) {
subgroup = strchr(group, '/');
if (subgroup != NULL)
*** 1172,1190 ****
* NULL, we only do the find if groupname is also
* NULL. This allows lookup of the "first" group in
* the internal list.
*/
if (group != NULL || groupname == NULL)
! node = find_group_by_name(impl_handle->tree,
(xmlChar *)group);
/* if a subgroup, find it before returning */
if (subgroup != NULL && node != NULL)
node = find_group_by_name(node, (xmlChar *)subgroup);
}
if (node != NULL && (char *)group != NULL)
! (void) sa_get_instance(impl_handle->scfhandle, (char *)group);
if (group != NULL)
free(group);
return ((sa_group_t)(node));
}
--- 1170,1188 ----
* NULL, we only do the find if groupname is also
* NULL. This allows lookup of the "first" group in
* the internal list.
*/
if (group != NULL || groupname == NULL)
! node = find_group_by_name(handle->tree,
(xmlChar *)group);
/* if a subgroup, find it before returning */
if (subgroup != NULL && node != NULL)
node = find_group_by_name(node, (xmlChar *)subgroup);
}
if (node != NULL && (char *)group != NULL)
! (void) sa_get_instance(handle->scfhandle, (char *)group);
if (group != NULL)
free(group);
return ((sa_group_t)(node));
}
*** 1500,1514 ****
if (sa_get_optionset(group, "nfs") != NULL)
err = sa_zfs_set_sharenfs(group, sharepath, 1);
else if (sa_get_optionset(group, "smb") != NULL)
err = sa_zfs_set_sharesmb(group, sharepath, 1);
} else {
! sa_handle_impl_t impl_handle;
! impl_handle =
! (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
! err = sa_commit_share(impl_handle->scfhandle,
group, (sa_share_t)node);
} else {
err = SA_SYSTEM_ERR;
}
}
--- 1498,1510 ----
if (sa_get_optionset(group, "nfs") != NULL)
err = sa_zfs_set_sharenfs(group, sharepath, 1);
else if (sa_get_optionset(group, "smb") != NULL)
err = sa_zfs_set_sharesmb(group, sharepath, 1);
} else {
! sa_handle_t handle = sa_find_group_handle(group);
! if (handle != NULL) {
! err = sa_commit_share(handle->scfhandle,
group, (sa_share_t)node);
} else {
err = SA_SYSTEM_ERR;
}
}
*** 1739,1754 ****
if (!transient || zfs != NULL) {
/* remove from legacy dfstab as well as possible SMF */
ret = sa_delete_legacy(share, NULL);
if (ret == SA_OK) {
if (!sa_group_is_zfs(group)) {
! sa_handle_impl_t impl_handle;
! impl_handle = (sa_handle_impl_t)
sa_find_group_handle(group);
! if (impl_handle != NULL) {
ret = sa_delete_share(
! impl_handle->scfhandle, group,
share);
} else {
ret = SA_SYSTEM_ERR;
}
} else {
--- 1735,1749 ----
if (!transient || zfs != NULL) {
/* remove from legacy dfstab as well as possible SMF */
ret = sa_delete_legacy(share, NULL);
if (ret == SA_OK) {
if (!sa_group_is_zfs(group)) {
! sa_handle_t handle =
sa_find_group_handle(group);
! if (handle != NULL) {
ret = sa_delete_share(
! handle->scfhandle, group,
share);
} else {
ret = SA_SYSTEM_ERR;
}
} else {
*** 1787,1816 ****
/* remove the node from its group then free the memory */
oldgroup = sa_get_parent_group(share);
if (oldgroup != group) {
! sa_handle_impl_t impl_handle;
xmlUnlinkNode((xmlNodePtr)share);
/*
* now that the share isn't in its old group, add to
* the new one
*/
(void) xmlAddChild((xmlNodePtr)group, (xmlNodePtr)share);
/* need to deal with SMF */
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! 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.
*/
! ret = sa_delete_share(impl_handle->scfhandle, oldgroup,
share);
if (ret == SA_OK)
! ret = sa_commit_share(impl_handle->scfhandle,
group, share);
} else {
ret = SA_SYSTEM_ERR;
}
}
--- 1782,1811 ----
/* remove the node from its group then free the memory */
oldgroup = sa_get_parent_group(share);
if (oldgroup != group) {
! sa_handle_t handle;
xmlUnlinkNode((xmlNodePtr)share);
/*
* now that the share isn't in its old group, add to
* the new one
*/
(void) xmlAddChild((xmlNodePtr)group, (xmlNodePtr)share);
/* need to deal with SMF */
! handle = sa_find_group_handle(group);
! if (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.
*/
! ret = sa_delete_share(handle->scfhandle, oldgroup,
share);
if (ret == SA_OK)
! ret = sa_commit_share(handle->scfhandle,
group, share);
} else {
ret = SA_SYSTEM_ERR;
}
}
*** 1841,1863 ****
}
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.
*/
sa_group_t
! _sa_create_group(sa_handle_impl_t impl_handle, char *groupname)
{
xmlNodePtr node = NULL;
if (sa_valid_group_name(groupname)) {
! node = xmlNewChild(impl_handle->tree, NULL, (xmlChar *)"group",
NULL);
if (node != NULL) {
(void) xmlSetProp(node, (xmlChar *)"name",
(xmlChar *)groupname);
(void) xmlSetProp(node, (xmlChar *)"state",
--- 1836,1858 ----
}
return ((sa_group_t)node);
}
/*
! * _sa_create_group(handle, groupname)
*
* Create a group in the document. The caller will need to deal with
* configuration store and activation.
*/
sa_group_t
! _sa_create_group(sa_handle_t handle, char *groupname)
{
xmlNodePtr node = NULL;
if (sa_valid_group_name(groupname)) {
! node = xmlNewChild(handle->tree, NULL, (xmlChar *)"group",
NULL);
if (node != NULL) {
(void) xmlSetProp(node, (xmlChar *)"name",
(xmlChar *)groupname);
(void) xmlSetProp(node, (xmlChar *)"state",
*** 1904,1985 ****
{
xmlNodePtr node = NULL;
sa_group_t group;
int ret;
char rbacstr[SA_STRSIZE];
- sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
ret = SA_OK;
! if (impl_handle == NULL || impl_handle->scfhandle == NULL) {
ret = SA_SYSTEM_ERR;
goto err;
}
group = sa_get_group(handle, groupname);
if (group != NULL) {
ret = SA_DUPLICATE_NAME;
} else {
if (sa_valid_group_name(groupname)) {
! node = xmlNewChild(impl_handle->tree, NULL,
(xmlChar *)"group", NULL);
if (node != NULL) {
(void) xmlSetProp(node, (xmlChar *)"name",
(xmlChar *)groupname);
/* default to the group being enabled */
(void) xmlSetProp(node, (xmlChar *)"state",
(xmlChar *)"enabled");
! ret = sa_create_instance(impl_handle->scfhandle,
groupname);
if (ret == SA_OK) {
ret = sa_start_transaction(
! impl_handle->scfhandle,
"operation");
}
if (ret == SA_OK) {
ret = sa_set_property(
! impl_handle->scfhandle,
"state", "enabled");
if (ret == SA_OK) {
ret = sa_end_transaction(
! impl_handle->scfhandle,
! impl_handle);
} else {
sa_abort_transaction(
! impl_handle->scfhandle);
}
}
if (ret == SA_OK) {
/* initialize the RBAC strings */
ret = sa_start_transaction(
! impl_handle->scfhandle,
"general");
if (ret == SA_OK) {
(void) snprintf(rbacstr,
sizeof (rbacstr), "%s.%s",
SA_RBAC_MANAGE, groupname);
ret = sa_set_property(
! impl_handle->scfhandle,
"action_authorization",
rbacstr);
}
if (ret == SA_OK) {
(void) snprintf(rbacstr,
sizeof (rbacstr), "%s.%s",
SA_RBAC_VALUE, groupname);
ret = sa_set_property(
! impl_handle->scfhandle,
"value_authorization",
rbacstr);
}
if (ret == SA_OK) {
ret = sa_end_transaction(
! impl_handle->scfhandle,
! impl_handle);
} else {
sa_abort_transaction(
! impl_handle->scfhandle);
}
}
if (ret != SA_OK) {
/*
* Couldn't commit the group
--- 1899,1979 ----
{
xmlNodePtr node = NULL;
sa_group_t group;
int ret;
char rbacstr[SA_STRSIZE];
ret = SA_OK;
! if (handle == NULL || handle->scfhandle == NULL) {
ret = SA_SYSTEM_ERR;
goto err;
}
group = sa_get_group(handle, groupname);
if (group != NULL) {
ret = SA_DUPLICATE_NAME;
} else {
if (sa_valid_group_name(groupname)) {
! node = xmlNewChild(handle->tree, NULL,
(xmlChar *)"group", NULL);
if (node != NULL) {
(void) xmlSetProp(node, (xmlChar *)"name",
(xmlChar *)groupname);
/* default to the group being enabled */
(void) xmlSetProp(node, (xmlChar *)"state",
(xmlChar *)"enabled");
! ret = sa_create_instance(handle->scfhandle,
groupname);
if (ret == SA_OK) {
ret = sa_start_transaction(
! handle->scfhandle,
"operation");
}
if (ret == SA_OK) {
ret = sa_set_property(
! handle->scfhandle,
"state", "enabled");
if (ret == SA_OK) {
ret = sa_end_transaction(
! handle->scfhandle,
! handle);
} else {
sa_abort_transaction(
! handle->scfhandle);
}
}
if (ret == SA_OK) {
/* initialize the RBAC strings */
ret = sa_start_transaction(
! handle->scfhandle,
"general");
if (ret == SA_OK) {
(void) snprintf(rbacstr,
sizeof (rbacstr), "%s.%s",
SA_RBAC_MANAGE, groupname);
ret = sa_set_property(
! handle->scfhandle,
"action_authorization",
rbacstr);
}
if (ret == SA_OK) {
(void) snprintf(rbacstr,
sizeof (rbacstr), "%s.%s",
SA_RBAC_VALUE, groupname);
ret = sa_set_property(
! handle->scfhandle,
"value_authorization",
rbacstr);
}
if (ret == SA_OK) {
ret = sa_end_transaction(
! handle->scfhandle,
! handle);
} else {
sa_abort_transaction(
! handle->scfhandle);
}
}
if (ret != SA_OK) {
/*
* Couldn't commit the group
*** 2013,2029 ****
int
sa_remove_group(sa_group_t group)
{
char *name;
int ret = SA_OK;
! sa_handle_impl_t impl_handle;
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
name = sa_get_group_attr(group, "name");
if (name != NULL) {
! ret = sa_delete_instance(impl_handle->scfhandle, name);
sa_free_attr_string(name);
}
xmlUnlinkNode((xmlNodePtr)group); /* make sure unlinked */
xmlFreeNode((xmlNodePtr)group); /* now it is gone */
} else {
--- 2007,2023 ----
int
sa_remove_group(sa_group_t group)
{
char *name;
int ret = SA_OK;
! sa_handle_t handle;
! handle = sa_find_group_handle(group);
! if (handle != NULL) {
name = sa_get_group_attr(group, "name");
if (name != NULL) {
! ret = sa_delete_instance(handle->scfhandle, name);
sa_free_attr_string(name);
}
xmlUnlinkNode((xmlNodePtr)group); /* make sure unlinked */
xmlFreeNode((xmlNodePtr)group); /* now it is gone */
} else {
*** 2116,2153 ****
int
sa_set_group_attr(sa_group_t group, char *tag, char *value)
{
int ret;
char *groupname;
! sa_handle_impl_t impl_handle;
/*
* ZFS group/subgroup doesn't need the handle so shortcut.
*/
if (sa_group_is_zfs(group)) {
set_node_attr((void *)group, tag, value);
return (SA_OK);
}
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
groupname = sa_get_group_attr(group, "name");
! ret = sa_get_instance(impl_handle->scfhandle, groupname);
if (ret == SA_OK) {
set_node_attr((void *)group, tag, value);
! ret = sa_start_transaction(impl_handle->scfhandle,
"operation");
if (ret == SA_OK) {
! ret = sa_set_property(impl_handle->scfhandle,
tag, value);
if (ret == SA_OK)
ret = sa_end_transaction(
! impl_handle->scfhandle,
! impl_handle);
else
sa_abort_transaction(
! impl_handle->scfhandle);
}
if (ret == SA_SYSTEM_ERR)
ret = SA_NO_PERMISSION;
}
if (groupname != NULL)
--- 2110,2147 ----
int
sa_set_group_attr(sa_group_t group, char *tag, char *value)
{
int ret;
char *groupname;
! sa_handle_t handle;
/*
* ZFS group/subgroup doesn't need the handle so shortcut.
*/
if (sa_group_is_zfs(group)) {
set_node_attr((void *)group, tag, value);
return (SA_OK);
}
! handle = sa_find_group_handle(group);
! if (handle != NULL) {
groupname = sa_get_group_attr(group, "name");
! ret = sa_get_instance(handle->scfhandle, groupname);
if (ret == SA_OK) {
set_node_attr((void *)group, tag, value);
! ret = sa_start_transaction(handle->scfhandle,
"operation");
if (ret == SA_OK) {
! ret = sa_set_property(handle->scfhandle,
tag, value);
if (ret == SA_OK)
ret = sa_end_transaction(
! handle->scfhandle,
! handle);
else
sa_abort_transaction(
! handle->scfhandle);
}
if (ret == SA_SYSTEM_ERR)
ret = SA_NO_PERMISSION;
}
if (groupname != NULL)
*** 2224,2240 ****
if (group != NULL) {
char *type;
/* we can probably optimize this some */
type = sa_get_share_attr(share, "type");
if (type == NULL || strcmp(type, "transient") != 0) {
! sa_handle_impl_t impl_handle;
! impl_handle =
! (sa_handle_impl_t)sa_find_group_handle(
group);
! if (impl_handle != NULL) {
ret = sa_commit_share(
! impl_handle->scfhandle, group,
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
--- 2218,2232 ----
if (group != NULL) {
char *type;
/* we can probably optimize this some */
type = sa_get_share_attr(share, "type");
if (type == NULL || strcmp(type, "transient") != 0) {
! sa_handle_t handle = sa_find_group_handle(
group);
! if (handle != NULL) {
ret = sa_commit_share(
! handle->scfhandle, group,
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
*** 2525,2538 ****
xmlFreeNode(node);
}
group = sa_get_parent_group(share);
if (group != NULL &&
sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
! sa_handle_impl_t impl_handle;
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
! ret = sa_commit_share(impl_handle->scfhandle, group,
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
--- 2517,2529 ----
xmlFreeNode(node);
}
group = sa_get_parent_group(share);
if (group != NULL &&
sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
! sa_handle_t handle = sa_find_group_handle(group);
! if (handle != NULL) {
! ret = sa_commit_share(handle->scfhandle, group,
share);
} else {
ret = SA_SYSTEM_ERR;
}
}
*** 2671,2690 ****
(void) sa_optionset_name(optionset, oname,
sizeof (oname), id);
groupname = sa_get_group_attr(parent, "name");
if (groupname != NULL && sa_is_persistent(group)) {
! sa_handle_impl_t impl_handle;
! impl_handle =
! (sa_handle_impl_t)sa_find_group_handle(
group);
! assert(impl_handle != NULL);
! if (impl_handle != NULL) {
(void) sa_get_instance(
! impl_handle->scfhandle, groupname);
(void) sa_create_pgroup(
! impl_handle->scfhandle, oname);
}
}
if (groupname != NULL)
sa_free_attr_string(groupname);
}
--- 2662,2679 ----
(void) sa_optionset_name(optionset, oname,
sizeof (oname), id);
groupname = sa_get_group_attr(parent, "name");
if (groupname != NULL && sa_is_persistent(group)) {
! sa_handle_t handle = sa_find_group_handle(
group);
! assert(handle != NULL);
! if (handle != NULL) {
(void) sa_get_instance(
! handle->scfhandle, groupname);
(void) sa_create_pgroup(
! handle->scfhandle, oname);
}
}
if (groupname != NULL)
sa_free_attr_string(groupname);
}
*** 2779,2789 ****
sa_group_t group;
sa_group_t parent;
int zfs = 0;
int needsupdate = 0;
int ret = SA_OK;
! sa_handle_impl_t impl_handle;
group = sa_get_optionset_parent(optionset);
if (group != NULL && (sa_is_share(group) || is_zfs_group(group))) {
/* only update ZFS if on a share */
parent = sa_get_parent_group(group);
--- 2768,2778 ----
sa_group_t group;
sa_group_t parent;
int zfs = 0;
int needsupdate = 0;
int ret = SA_OK;
! sa_handle_t handle;
group = sa_get_optionset_parent(optionset);
if (group != NULL && (sa_is_share(group) || is_zfs_group(group))) {
/* only update ZFS if on a share */
parent = sa_get_parent_group(group);
*** 2795,2812 ****
}
if (zfs) {
if (!clear && needsupdate)
ret = sa_zfs_update((sa_share_t)group);
} else {
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
if (clear) {
(void) sa_abort_transaction(
! impl_handle->scfhandle);
} else {
ret = sa_end_transaction(
! impl_handle->scfhandle, impl_handle);
}
} else {
ret = SA_SYSTEM_ERR;
}
}
--- 2784,2801 ----
}
if (zfs) {
if (!clear && needsupdate)
ret = sa_zfs_update((sa_share_t)group);
} else {
! handle = sa_find_group_handle(group);
! if (handle != NULL) {
if (clear) {
(void) sa_abort_transaction(
! handle->scfhandle);
} else {
ret = sa_end_transaction(
! handle->scfhandle, handle);
}
} else {
ret = SA_SYSTEM_ERR;
}
}
*** 2842,2857 ****
id = sa_get_share_attr((sa_share_t)group, "id");
}
ispersist = sa_is_persistent(group);
}
if (ispersist) {
! sa_handle_impl_t impl_handle;
len = sa_optionset_name(optionset, name, sizeof (name), id);
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
if (len > 0) {
! ret = sa_delete_pgroup(impl_handle->scfhandle,
name);
}
} else {
ret = SA_SYSTEM_ERR;
}
--- 2831,2845 ----
id = sa_get_share_attr((sa_share_t)group, "id");
}
ispersist = sa_is_persistent(group);
}
if (ispersist) {
! sa_handle_t handle = sa_find_group_handle(group);
len = sa_optionset_name(optionset, name, sizeof (name), id);
! if (handle != NULL) {
if (len > 0) {
! ret = sa_delete_pgroup(handle->scfhandle,
name);
}
} else {
ret = SA_SYSTEM_ERR;
}
*** 2911,2929 ****
sa_set_security_attr(security, "sectype", sectype);
(void) sa_security_name(security, oname,
sizeof (oname), id);
if (groupname != NULL && sa_is_persistent(group)) {
! sa_handle_impl_t impl_handle;
! impl_handle =
! (sa_handle_impl_t)sa_find_group_handle(
group);
! if (impl_handle != NULL) {
(void) sa_get_instance(
! impl_handle->scfhandle, groupname);
(void) sa_create_pgroup(
! impl_handle->scfhandle, oname);
}
}
}
}
if (id != NULL)
--- 2899,2915 ----
sa_set_security_attr(security, "sectype", sectype);
(void) sa_security_name(security, oname,
sizeof (oname), id);
if (groupname != NULL && sa_is_persistent(group)) {
! sa_handle_t handle = sa_find_group_handle(
group);
! if (handle != NULL) {
(void) sa_get_instance(
! handle->scfhandle, groupname);
(void) sa_create_pgroup(
! handle->scfhandle, oname);
}
}
}
}
if (id != NULL)
*** 2962,2976 ****
id = sa_get_share_attr((sa_share_t)group, "id");
}
if (ispersist) {
len = sa_security_name(security, name, sizeof (name), id);
if (!iszfs && len > 0) {
! sa_handle_impl_t impl_handle;
! impl_handle =
! (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL) {
! ret = sa_delete_pgroup(impl_handle->scfhandle,
name);
} else {
ret = SA_SYSTEM_ERR;
}
}
--- 2948,2960 ----
id = sa_get_share_attr((sa_share_t)group, "id");
}
if (ispersist) {
len = sa_security_name(security, name, sizeof (name), id);
if (!iszfs && len > 0) {
! sa_handle_t handle = sa_find_group_handle(group);
! if (handle != NULL) {
! ret = sa_delete_pgroup(handle->scfhandle,
name);
} else {
ret = SA_SYSTEM_ERR;
}
}
*** 3075,3098 ****
int opttype; /* 1 == optionset, 0 == security */
char *id = NULL;
int iszfs = 0;
sa_group_t parent = NULL;
sa_share_t share = NULL;
! sa_handle_impl_t impl_handle;
scfutilhandle_t *scf_handle;
if (!sa_is_persistent(group)) {
/*
* if the group/share is not persistent we don't need
* to do anything here
*/
return (SA_OK);
}
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle == NULL || impl_handle->scfhandle == NULL)
return (SA_SYSTEM_ERR);
! scf_handle = impl_handle->scfhandle;
name = sa_get_property_attr(prop, "type");
valstr = sa_get_property_attr(prop, "value");
entry = scf_entry_create(scf_handle->handle);
opttype = is_nodetype((void *)optionset, "optionset");
--- 3059,3082 ----
int opttype; /* 1 == optionset, 0 == security */
char *id = NULL;
int iszfs = 0;
sa_group_t parent = NULL;
sa_share_t share = NULL;
! sa_handle_t handle;
scfutilhandle_t *scf_handle;
if (!sa_is_persistent(group)) {
/*
* if the group/share is not persistent we don't need
* to do anything here
*/
return (SA_OK);
}
! handle = sa_find_group_handle(group);
! if (handle == NULL || handle->scfhandle == NULL)
return (SA_SYSTEM_ERR);
! scf_handle = handle->scfhandle;
name = sa_get_property_attr(prop, "type");
valstr = sa_get_property_attr(prop, "value");
entry = scf_entry_create(scf_handle->handle);
opttype = is_nodetype((void *)optionset, "optionset");
*** 3286,3305 ****
} else {
char oname[SA_STRSIZE];
if (!is_zfs_group(group)) {
char *id = NULL;
! sa_handle_impl_t impl_handle;
scfutilhandle_t *scf_handle;
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(
! group);
! if (impl_handle == NULL ||
! impl_handle->scfhandle == NULL)
ret = SA_SYSTEM_ERR;
if (ret == SA_OK) {
! scf_handle = impl_handle->scfhandle;
if (sa_is_share((sa_group_t)parent)) {
id = sa_get_share_attr(
(sa_share_t)parent, "id");
}
if (scf_handle->trans == NULL) {
--- 3270,3288 ----
} else {
char oname[SA_STRSIZE];
if (!is_zfs_group(group)) {
char *id = NULL;
! sa_handle_t handle;
scfutilhandle_t *scf_handle;
! handle = sa_find_group_handle(group);
! if (handle == NULL ||
! handle->scfhandle == NULL)
ret = SA_SYSTEM_ERR;
if (ret == SA_OK) {
! scf_handle = handle->scfhandle;
if (sa_is_share((sa_group_t)parent)) {
id = sa_get_share_attr(
(sa_share_t)parent, "id");
}
if (scf_handle->trans == NULL) {
*** 3794,3811 ****
if (!sa_is_persistent((sa_group_t)share))
goto done;
if (!sa_group_is_zfs(group)) {
/* ZFS doesn't use resource names */
! sa_handle_impl_t ihandle;
! ihandle = (sa_handle_impl_t)
! sa_find_group_handle(
group);
! if (ihandle != NULL)
err = sa_commit_share(
! ihandle->scfhandle, group,
share);
else
err = SA_SYSTEM_ERR;
} else {
err = sa_zfs_update((sa_share_t)group);
--- 3777,3793 ----
if (!sa_is_persistent((sa_group_t)share))
goto done;
if (!sa_group_is_zfs(group)) {
/* ZFS doesn't use resource names */
! sa_handle_t handle;
! handle = sa_find_group_handle(
group);
! if (handle != NULL)
err = sa_commit_share(
! handle->scfhandle, group,
share);
else
err = SA_SYSTEM_ERR;
} else {
err = sa_zfs_update((sa_share_t)group);
*** 3862,3875 ****
/* only do SMF action if permanent and not ZFS */
if (transient)
return (ret);
if (!sa_group_is_zfs(group)) {
! sa_handle_impl_t ihandle;
! ihandle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (ihandle != NULL)
! ret = sa_commit_share(ihandle->scfhandle, group, share);
else
ret = SA_SYSTEM_ERR;
} else {
ret = sa_zfs_update((sa_share_t)group);
}
--- 3844,3856 ----
/* only do SMF action if permanent and not ZFS */
if (transient)
return (ret);
if (!sa_group_is_zfs(group)) {
! sa_handle_t handle = sa_find_group_handle(group);
! if (handle != NULL)
! ret = sa_commit_share(handle->scfhandle, group, share);
else
ret = SA_SYSTEM_ERR;
} else {
ret = sa_zfs_update((sa_share_t)group);
}
*** 3928,3938 ****
group = sa_get_parent_group(share);
if (group == NULL)
return (ret);
! handle = (sa_handle_impl_t)sa_find_group_handle(group);
if (handle == NULL)
return (ret);
target = sa_find_resource(handle, newname);
if (target != NULL) {
--- 3909,3919 ----
group = sa_get_parent_group(share);
if (group == NULL)
return (ret);
! handle = sa_find_group_handle(group);
if (handle == NULL)
return (ret);
target = sa_find_resource(handle, newname);
if (target != NULL) {
*** 3948,3959 ****
if (!sa_is_persistent((sa_group_t)share))
return (ret);
if (!sa_group_is_zfs(group)) {
! sa_handle_impl_t ihandle = (sa_handle_impl_t)handle;
! ret = sa_commit_share(ihandle->scfhandle, group,
share);
} else {
ret = sa_zfs_update((sa_share_t)group);
}
}
--- 3929,3939 ----
if (!sa_is_persistent((sa_group_t)share))
return (ret);
if (!sa_group_is_zfs(group)) {
! ret = sa_commit_share(handle->scfhandle, group,
share);
} else {
ret = sa_zfs_update((sa_share_t)group);
}
}
*** 4362,4375 ****
share = sa_get_resource_parent(resource);
group = sa_get_parent_group(share);
if (group != NULL &&
sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
! sa_handle_impl_t impl_handle;
! impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
! if (impl_handle != NULL)
! ret = sa_commit_share(impl_handle->scfhandle,
group, share);
else
ret = SA_SYSTEM_ERR;
}
return (ret);
--- 4342,4354 ----
share = sa_get_resource_parent(resource);
group = sa_get_parent_group(share);
if (group != NULL &&
sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
! sa_handle_t handle = sa_find_group_handle(group);
! if (handle != NULL)
! ret = sa_commit_share(handle->scfhandle,
group, share);
else
ret = SA_SYSTEM_ERR;
}
return (ret);