Project

General

Profile

Bug #4095 ยป libshare-cleanup.patch

Andrew Stormont, 2013-09-01 12:06 PM

View differences:

usr/src/lib/libshare/common/libshare.c
21 21

  
22 22
/*
23 23
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24
 * Copyright (c) 2013 RackTop Systems.
24 25
 */
25 26

  
26 27
/*
......
65 66

  
66 67
/* current SMF/SVC repository handle */
67 68
extern void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
68
extern int gettransients(sa_handle_impl_t, xmlNodePtr *);
69
extern int gettransients(sa_handle_t, xmlNodePtr *);
69 70
extern char *sa_fstype(char *);
70
extern int sa_is_share(void *);
71
extern int sa_is_resource(void *);
71
extern boolean_t sa_is_share(void *);
72
extern boolean_t sa_is_resource(void *);
72 73
extern ssize_t scf_max_name_len; /* defined in scfutil during initialization */
73
extern int sa_group_is_zfs(sa_group_t);
74
extern int sa_path_is_zfs(char *);
74
extern boolean_t sa_group_is_zfs(sa_group_t);
75
extern boolean_t sa_path_is_zfs(char *);
75 76
extern int sa_zfs_set_sharenfs(sa_group_t, char *, int);
76 77
extern int sa_zfs_set_sharesmb(sa_group_t, char *, int);
77 78
extern void update_legacy_config(sa_handle_t);
78 79
extern int issubdir(char *, char *);
79
extern int sa_zfs_init(sa_handle_impl_t);
80
extern void sa_zfs_fini(sa_handle_impl_t);
80
extern int sa_zfs_init(sa_handle_t);
81
extern void sa_zfs_fini(sa_handle_t);
81 82
extern void sablocksigs(sigset_t *);
82 83
extern void saunblocksigs(sigset_t *);
83 84
static sa_group_t sa_get_optionset_parent(sa_optionset_t);
......
95 96
struct doc2handle {
96 97
	struct doc2handle	*next;
97 98
	xmlNodePtr		root;
98
	sa_handle_impl_t	handle;
99
	sa_handle_t		handle;
99 100
};
100 101

  
101 102
mutex_t sa_dfstab_lock;
......
239 240
 * item per thread that has called sa_init().
240 241
 */
241 242

  
242
sa_handle_impl_t
243
sa_handle_t
243 244
get_handle_for_root(xmlNodePtr root)
244 245
{
245 246
	struct doc2handle *item;
......
256 257
}
257 258

  
258 259
static int
259
add_handle_for_root(xmlNodePtr root, sa_handle_impl_t handle)
260
add_handle_for_root(xmlNodePtr root, sa_handle_t handle)
260 261
{
261 262
	struct doc2handle *item;
262 263
	int ret = SA_NO_MEMORY;
......
319 320
	while (node != NULL) {
320 321
		if (strcmp((char *)(node->name), "sharecfg") == 0) {
321 322
			/* have the root so get the handle */
322
			handle = (sa_handle_t)get_handle_for_root(node);
323
			handle = get_handle_for_root(node);
323 324
			return (handle);
324 325
		}
325 326
		node = node->parent;
......
340 341
{
341 342
	xmlNodePtr node;
342 343
	xmlChar *lpath = NULL;
343
	sa_handle_impl_t handle;
344
	sa_handle_t handle;
344 345

  
345 346
	/* Have to have a handle or else we weren't initialized. */
346 347
	handle = get_handle_for_root(root);
......
600 601
 * works since both thse types are also void *.
601 602
 * If the share is a ZFS share, mark it as persistent.
602 603
 */
603
int
604
boolean_t
604 605
sa_is_persistent(void *group)
605 606
{
606 607
	char *type;
607
	int persist = 1;
608
	boolean_t persist = B_TRUE;
608 609
	sa_group_t grp;
609 610

  
610 611
	type = sa_get_group_attr((sa_group_t)group, "type");
611 612
	if (type != NULL) {
612 613
		if (strcmp(type, "transient") == 0)
613
			persist = 0;
614
			persist = B_FALSE;
614 615
		sa_free_attr_string(type);
615 616
	}
616 617

  
617 618
	grp = (sa_is_share(group)) ? sa_get_parent_group(group) : group;
618 619
	if (sa_group_is_zfs(grp))
619
		persist = 1;
620
		persist = B_TRUE;
620 621

  
621 622
	return (persist);
622 623
}
......
833 834
	sigset_t old;
834 835
	int updatelegacy = B_FALSE;
835 836
	scf_simple_prop_t *prop;
836
	sa_handle_impl_t handle;
837
	sa_handle_t handle;
837 838
	int err;
838 839

  
839
	handle = calloc(sizeof (struct sa_handle_impl), 1);
840
	handle = calloc(sizeof (struct sa_handle), 1);
840 841

  
841 842
	if (handle != NULL) {
842 843
		/*
......
1029 1030
			}
1030 1031
		}
1031 1032
	}
1032
	return ((sa_handle_t)handle);
1033
	return (handle);
1033 1034
}
1034 1035

  
1035 1036
/*
......
1041 1042
void
1042 1043
sa_fini(sa_handle_t handle)
1043 1044
{
1044
	sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
1045

  
1046
	if (impl_handle != NULL) {
1045
	if (handle != NULL) {
1047 1046
		/*
1048 1047
		 * Free the config trees and any other data structures
1049 1048
		 * used in the handle.
1050 1049
		 */
1051
		if (impl_handle->doc != NULL)
1052
			xmlFreeDoc(impl_handle->doc);
1050
		if (handle->doc != NULL)
1051
			xmlFreeDoc(handle->doc);
1053 1052

  
1054 1053
		/* Remove and free the entry in the global list. */
1055
		remove_handle_for_root(impl_handle->tree);
1054
		remove_handle_for_root(handle->tree);
1056 1055

  
1057 1056
		/*
1058 1057
		 * If this was the last handle to release, unload the
......
1064 1063
			(void) proto_plugin_fini();
1065 1064
		(void) mutex_unlock(&sa_global_lock);
1066 1065

  
1067
		sa_scf_fini(impl_handle->scfhandle);
1068
		sa_zfs_fini(impl_handle);
1066
		sa_scf_fini(handle->scfhandle);
1067
		sa_zfs_fini(handle);
1069 1068

  
1070 1069
		/* Make sure we free the handle */
1071
		free(impl_handle);
1070
		free(handle);
1072 1071

  
1073 1072
	}
1074 1073
}
......
1155 1154
	xmlNodePtr node = NULL;
1156 1155
	char *subgroup = NULL;
1157 1156
	char *group = NULL;
1158
	sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
1159 1157

  
1160
	if (impl_handle != NULL && impl_handle->tree != NULL) {
1158
	if (handle != NULL && handle->tree != NULL) {
1161 1159
		if (groupname != NULL) {
1162 1160
			group = strdup(groupname);
1163 1161
			if (group != NULL) {
......
1174 1172
		 * the internal list.
1175 1173
		 */
1176 1174
		if (group != NULL || groupname == NULL)
1177
			node = find_group_by_name(impl_handle->tree,
1175
			node = find_group_by_name(handle->tree,
1178 1176
			    (xmlChar *)group);
1179 1177

  
1180 1178
		/* if a subgroup, find it before returning */
......
1182 1180
			node = find_group_by_name(node, (xmlChar *)subgroup);
1183 1181
	}
1184 1182
	if (node != NULL && (char *)group != NULL)
1185
		(void) sa_get_instance(impl_handle->scfhandle, (char *)group);
1183
		(void) sa_get_instance(handle->scfhandle, (char *)group);
1186 1184
	if (group != NULL)
1187 1185
		free(group);
1188 1186
	return ((sa_group_t)(node));
......
1502 1500
			else if (sa_get_optionset(group, "smb") != NULL)
1503 1501
				err = sa_zfs_set_sharesmb(group, sharepath, 1);
1504 1502
		} else {
1505
			sa_handle_impl_t impl_handle;
1506
			impl_handle =
1507
			    (sa_handle_impl_t)sa_find_group_handle(group);
1508
			if (impl_handle != NULL) {
1509
				err = sa_commit_share(impl_handle->scfhandle,
1503
			sa_handle_t handle = sa_find_group_handle(group);
1504
			if (handle != NULL) {
1505
				err = sa_commit_share(handle->scfhandle,
1510 1506
				    group, (sa_share_t)node);
1511 1507
			} else {
1512 1508
				err = SA_SYSTEM_ERR;
......
1741 1737
		ret = sa_delete_legacy(share, NULL);
1742 1738
		if (ret == SA_OK) {
1743 1739
			if (!sa_group_is_zfs(group)) {
1744
				sa_handle_impl_t impl_handle;
1745
				impl_handle = (sa_handle_impl_t)
1740
				sa_handle_t handle =
1746 1741
				    sa_find_group_handle(group);
1747
				if (impl_handle != NULL) {
1742
				if (handle != NULL) {
1748 1743
					ret = sa_delete_share(
1749
					    impl_handle->scfhandle, group,
1744
					    handle->scfhandle, group,
1750 1745
					    share);
1751 1746
				} else {
1752 1747
					ret = SA_SYSTEM_ERR;
......
1789 1784

  
1790 1785
	oldgroup = sa_get_parent_group(share);
1791 1786
	if (oldgroup != group) {
1792
		sa_handle_impl_t impl_handle;
1787
		sa_handle_t handle;
1793 1788
		xmlUnlinkNode((xmlNodePtr)share);
1794 1789
		/*
1795 1790
		 * now that the share isn't in its old group, add to
......
1797 1792
		 */
1798 1793
		(void) xmlAddChild((xmlNodePtr)group, (xmlNodePtr)share);
1799 1794
		/* need to deal with SMF */
1800
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
1801
		if (impl_handle != NULL) {
1795
		handle = sa_find_group_handle(group);
1796
		if (handle != NULL) {
1802 1797
			/*
1803 1798
			 * need to remove from old group first and then add to
1804 1799
			 * new group. Ideally, we would do the other order but
1805 1800
			 * need to avoid having the share in two groups at the
1806 1801
			 * same time.
1807 1802
			 */
1808
			ret = sa_delete_share(impl_handle->scfhandle, oldgroup,
1803
			ret = sa_delete_share(handle->scfhandle, oldgroup,
1809 1804
			    share);
1810 1805
			if (ret == SA_OK)
1811
				ret = sa_commit_share(impl_handle->scfhandle,
1806
				ret = sa_commit_share(handle->scfhandle,
1812 1807
				    group, share);
1813 1808
		} else {
1814 1809
			ret = SA_SYSTEM_ERR;
......
1843 1838
}
1844 1839

  
1845 1840
/*
1846
 * _sa_create_group(impl_handle, groupname)
1841
 * _sa_create_group(handle, groupname)
1847 1842
 *
1848 1843
 * Create a group in the document. The caller will need to deal with
1849 1844
 * configuration store and activation.
1850 1845
 */
1851 1846

  
1852 1847
sa_group_t
1853
_sa_create_group(sa_handle_impl_t impl_handle, char *groupname)
1848
_sa_create_group(sa_handle_t handle, char *groupname)
1854 1849
{
1855 1850
	xmlNodePtr node = NULL;
1856 1851

  
1857 1852
	if (sa_valid_group_name(groupname)) {
1858
		node = xmlNewChild(impl_handle->tree, NULL, (xmlChar *)"group",
1853
		node = xmlNewChild(handle->tree, NULL, (xmlChar *)"group",
1859 1854
		    NULL);
1860 1855
		if (node != NULL) {
1861 1856
			(void) xmlSetProp(node, (xmlChar *)"name",
......
1906 1901
	sa_group_t group;
1907 1902
	int ret;
1908 1903
	char rbacstr[SA_STRSIZE];
1909
	sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
1910 1904

  
1911 1905
	ret = SA_OK;
1912 1906

  
1913
	if (impl_handle == NULL || impl_handle->scfhandle == NULL) {
1907
	if (handle == NULL || handle->scfhandle == NULL) {
1914 1908
		ret = SA_SYSTEM_ERR;
1915 1909
		goto err;
1916 1910
	}
......
1920 1914
		ret = SA_DUPLICATE_NAME;
1921 1915
	} else {
1922 1916
		if (sa_valid_group_name(groupname)) {
1923
			node = xmlNewChild(impl_handle->tree, NULL,
1917
			node = xmlNewChild(handle->tree, NULL,
1924 1918
			    (xmlChar *)"group", NULL);
1925 1919
			if (node != NULL) {
1926 1920
				(void) xmlSetProp(node, (xmlChar *)"name",
......
1928 1922
				/* default to the group being enabled */
1929 1923
				(void) xmlSetProp(node, (xmlChar *)"state",
1930 1924
				    (xmlChar *)"enabled");
1931
				ret = sa_create_instance(impl_handle->scfhandle,
1925
				ret = sa_create_instance(handle->scfhandle,
1932 1926
				    groupname);
1933 1927
				if (ret == SA_OK) {
1934 1928
					ret = sa_start_transaction(
1935
					    impl_handle->scfhandle,
1929
					    handle->scfhandle,
1936 1930
					    "operation");
1937 1931
				}
1938 1932
				if (ret == SA_OK) {
1939 1933
					ret = sa_set_property(
1940
					    impl_handle->scfhandle,
1934
					    handle->scfhandle,
1941 1935
					    "state", "enabled");
1942 1936
					if (ret == SA_OK) {
1943 1937
						ret = sa_end_transaction(
1944
						    impl_handle->scfhandle,
1945
						    impl_handle);
1938
						    handle->scfhandle,
1939
						    handle);
1946 1940
					} else {
1947 1941
						sa_abort_transaction(
1948
						    impl_handle->scfhandle);
1942
						    handle->scfhandle);
1949 1943
					}
1950 1944
				}
1951 1945
				if (ret == SA_OK) {
1952 1946
					/* initialize the RBAC strings */
1953 1947
					ret = sa_start_transaction(
1954
					    impl_handle->scfhandle,
1948
					    handle->scfhandle,
1955 1949
					    "general");
1956 1950
					if (ret == SA_OK) {
1957 1951
						(void) snprintf(rbacstr,
1958 1952
						    sizeof (rbacstr), "%s.%s",
1959 1953
						    SA_RBAC_MANAGE, groupname);
1960 1954
						ret = sa_set_property(
1961
						    impl_handle->scfhandle,
1955
						    handle->scfhandle,
1962 1956
						    "action_authorization",
1963 1957
						    rbacstr);
1964 1958
					}
......
1967 1961
						    sizeof (rbacstr), "%s.%s",
1968 1962
						    SA_RBAC_VALUE, groupname);
1969 1963
						ret = sa_set_property(
1970
						    impl_handle->scfhandle,
1964
						    handle->scfhandle,
1971 1965
						    "value_authorization",
1972 1966
						    rbacstr);
1973 1967
					}
1974 1968
					if (ret == SA_OK) {
1975 1969
						ret = sa_end_transaction(
1976
						    impl_handle->scfhandle,
1977
						    impl_handle);
1970
						    handle->scfhandle,
1971
						    handle);
1978 1972
					} else {
1979 1973
						sa_abort_transaction(
1980
						    impl_handle->scfhandle);
1974
						    handle->scfhandle);
1981 1975
					}
1982 1976
				}
1983 1977
				if (ret != SA_OK) {
......
2015 2009
{
2016 2010
	char *name;
2017 2011
	int ret = SA_OK;
2018
	sa_handle_impl_t impl_handle;
2012
	sa_handle_t handle;
2019 2013

  
2020
	impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2021
	if (impl_handle != NULL) {
2014
	handle = sa_find_group_handle(group);
2015
	if (handle != NULL) {
2022 2016
		name = sa_get_group_attr(group, "name");
2023 2017
		if (name != NULL) {
2024
			ret = sa_delete_instance(impl_handle->scfhandle, name);
2018
			ret = sa_delete_instance(handle->scfhandle, name);
2025 2019
			sa_free_attr_string(name);
2026 2020
		}
2027 2021
		xmlUnlinkNode((xmlNodePtr)group); /* make sure unlinked */
......
2118 2112
{
2119 2113
	int ret;
2120 2114
	char *groupname;
2121
	sa_handle_impl_t impl_handle;
2115
	sa_handle_t handle;
2122 2116

  
2123 2117
	/*
2124 2118
	 * ZFS group/subgroup doesn't need the handle so shortcut.
......
2128 2122
		return (SA_OK);
2129 2123
	}
2130 2124

  
2131
	impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2132
	if (impl_handle != NULL) {
2125
	handle = sa_find_group_handle(group);
2126
	if (handle != NULL) {
2133 2127
		groupname = sa_get_group_attr(group, "name");
2134
		ret = sa_get_instance(impl_handle->scfhandle, groupname);
2128
		ret = sa_get_instance(handle->scfhandle, groupname);
2135 2129
		if (ret == SA_OK) {
2136 2130
			set_node_attr((void *)group, tag, value);
2137
			ret = sa_start_transaction(impl_handle->scfhandle,
2131
			ret = sa_start_transaction(handle->scfhandle,
2138 2132
			    "operation");
2139 2133
			if (ret == SA_OK) {
2140
				ret = sa_set_property(impl_handle->scfhandle,
2134
				ret = sa_set_property(handle->scfhandle,
2141 2135
				    tag, value);
2142 2136
				if (ret == SA_OK)
2143 2137
					ret = sa_end_transaction(
2144
					    impl_handle->scfhandle,
2145
					    impl_handle);
2138
					    handle->scfhandle,
2139
					    handle);
2146 2140
				else
2147 2141
					sa_abort_transaction(
2148
					    impl_handle->scfhandle);
2142
					    handle->scfhandle);
2149 2143
			}
2150 2144
			if (ret == SA_SYSTEM_ERR)
2151 2145
				ret = SA_NO_PERMISSION;
......
2226 2220
			/* we can probably optimize this some */
2227 2221
			type = sa_get_share_attr(share, "type");
2228 2222
			if (type == NULL || strcmp(type, "transient") != 0) {
2229
				sa_handle_impl_t impl_handle;
2230
				impl_handle =
2231
				    (sa_handle_impl_t)sa_find_group_handle(
2223
				sa_handle_t handle = sa_find_group_handle(
2232 2224
				    group);
2233
				if (impl_handle != NULL) {
2225
				if (handle != NULL) {
2234 2226
					ret = sa_commit_share(
2235
					    impl_handle->scfhandle, group,
2227
					    handle->scfhandle, group,
2236 2228
					    share);
2237 2229
				} else {
2238 2230
					ret = SA_SYSTEM_ERR;
......
2527 2519
	group = sa_get_parent_group(share);
2528 2520
	if (group != NULL &&
2529 2521
	    sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
2530
		sa_handle_impl_t impl_handle;
2531
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2532
		if (impl_handle != NULL) {
2533
			ret = sa_commit_share(impl_handle->scfhandle, group,
2522
		sa_handle_t handle = sa_find_group_handle(group);
2523
		if (handle != NULL) {
2524
			ret = sa_commit_share(handle->scfhandle, group,
2534 2525
			    share);
2535 2526
		} else {
2536 2527
			ret = SA_SYSTEM_ERR;
......
2673 2664
			    sizeof (oname), id);
2674 2665
			groupname = sa_get_group_attr(parent, "name");
2675 2666
			if (groupname != NULL && sa_is_persistent(group)) {
2676
				sa_handle_impl_t impl_handle;
2677
				impl_handle =
2678
				    (sa_handle_impl_t)sa_find_group_handle(
2667
				sa_handle_t handle = sa_find_group_handle(
2679 2668
				    group);
2680
				assert(impl_handle != NULL);
2681
				if (impl_handle != NULL) {
2669
				assert(handle != NULL);
2670
				if (handle != NULL) {
2682 2671
					(void) sa_get_instance(
2683
					    impl_handle->scfhandle, groupname);
2672
					    handle->scfhandle, groupname);
2684 2673
					(void) sa_create_pgroup(
2685
					    impl_handle->scfhandle, oname);
2674
					    handle->scfhandle, oname);
2686 2675
				}
2687 2676
			}
2688 2677
			if (groupname != NULL)
......
2781 2770
	int zfs = 0;
2782 2771
	int needsupdate = 0;
2783 2772
	int ret = SA_OK;
2784
	sa_handle_impl_t impl_handle;
2773
	sa_handle_t handle;
2785 2774

  
2786 2775
	group = sa_get_optionset_parent(optionset);
2787 2776
	if (group != NULL && (sa_is_share(group) || is_zfs_group(group))) {
......
2797 2786
		if (!clear && needsupdate)
2798 2787
			ret = sa_zfs_update((sa_share_t)group);
2799 2788
	} else {
2800
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2801
		if (impl_handle != NULL) {
2789
		handle = sa_find_group_handle(group);
2790
		if (handle != NULL) {
2802 2791
			if (clear) {
2803 2792
				(void) sa_abort_transaction(
2804
				    impl_handle->scfhandle);
2793
				    handle->scfhandle);
2805 2794
			} else {
2806 2795
				ret = sa_end_transaction(
2807
				    impl_handle->scfhandle, impl_handle);
2796
				    handle->scfhandle, handle);
2808 2797
			}
2809 2798
		} else {
2810 2799
			ret = SA_SYSTEM_ERR;
......
2844 2833
		ispersist = sa_is_persistent(group);
2845 2834
	}
2846 2835
	if (ispersist) {
2847
		sa_handle_impl_t impl_handle;
2836
		sa_handle_t handle = sa_find_group_handle(group);
2848 2837
		len = sa_optionset_name(optionset, name, sizeof (name), id);
2849
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2850
		if (impl_handle != NULL) {
2838
		if (handle != NULL) {
2851 2839
			if (len > 0) {
2852
				ret = sa_delete_pgroup(impl_handle->scfhandle,
2840
				ret = sa_delete_pgroup(handle->scfhandle,
2853 2841
				    name);
2854 2842
			}
2855 2843
		} else {
......
2913 2901
			(void) sa_security_name(security, oname,
2914 2902
			    sizeof (oname), id);
2915 2903
			if (groupname != NULL && sa_is_persistent(group)) {
2916
				sa_handle_impl_t impl_handle;
2917
				impl_handle =
2918
				    (sa_handle_impl_t)sa_find_group_handle(
2904
				sa_handle_t handle = sa_find_group_handle(
2919 2905
				    group);
2920
				if (impl_handle != NULL) {
2906
				if (handle != NULL) {
2921 2907
					(void) sa_get_instance(
2922
					    impl_handle->scfhandle, groupname);
2908
					    handle->scfhandle, groupname);
2923 2909
					(void) sa_create_pgroup(
2924
					    impl_handle->scfhandle, oname);
2910
					    handle->scfhandle, oname);
2925 2911
				}
2926 2912
			}
2927 2913
		}
......
2964 2950
	if (ispersist) {
2965 2951
		len = sa_security_name(security, name, sizeof (name), id);
2966 2952
		if (!iszfs && len > 0) {
2967
			sa_handle_impl_t impl_handle;
2968
			impl_handle =
2969
			    (sa_handle_impl_t)sa_find_group_handle(group);
2970
			if (impl_handle != NULL) {
2971
				ret = sa_delete_pgroup(impl_handle->scfhandle,
2953
			sa_handle_t handle = sa_find_group_handle(group);
2954
			if (handle != NULL) {
2955
				ret = sa_delete_pgroup(handle->scfhandle,
2972 2956
				    name);
2973 2957
			} else {
2974 2958
				ret = SA_SYSTEM_ERR;
......
3077 3061
	int iszfs = 0;
3078 3062
	sa_group_t parent = NULL;
3079 3063
	sa_share_t share = NULL;
3080
	sa_handle_impl_t impl_handle;
3064
	sa_handle_t handle;
3081 3065
	scfutilhandle_t  *scf_handle;
3082 3066

  
3083 3067
	if (!sa_is_persistent(group)) {
......
3087 3071
		 */
3088 3072
		return (SA_OK);
3089 3073
	}
3090
	impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
3091
	if (impl_handle == NULL || impl_handle->scfhandle == NULL)
3074
	handle = sa_find_group_handle(group);
3075
	if (handle == NULL || handle->scfhandle == NULL)
3092 3076
		return (SA_SYSTEM_ERR);
3093
	scf_handle = impl_handle->scfhandle;
3077
	scf_handle = handle->scfhandle;
3094 3078
	name = sa_get_property_attr(prop, "type");
3095 3079
	valstr = sa_get_property_attr(prop, "value");
3096 3080
	entry = scf_entry_create(scf_handle->handle);
......
3288 3272

  
3289 3273
		if (!is_zfs_group(group)) {
3290 3274
			char *id = NULL;
3291
			sa_handle_impl_t impl_handle;
3275
			sa_handle_t handle;
3292 3276
			scfutilhandle_t  *scf_handle;
3293 3277

  
3294
			impl_handle = (sa_handle_impl_t)sa_find_group_handle(
3295
			    group);
3296
			if (impl_handle == NULL ||
3297
			    impl_handle->scfhandle == NULL)
3278
			handle = sa_find_group_handle(group);
3279
			if (handle == NULL ||
3280
			    handle->scfhandle == NULL)
3298 3281
				ret = SA_SYSTEM_ERR;
3299 3282
			if (ret == SA_OK) {
3300
				scf_handle = impl_handle->scfhandle;
3283
				scf_handle = handle->scfhandle;
3301 3284
				if (sa_is_share((sa_group_t)parent)) {
3302 3285
					id = sa_get_share_attr(
3303 3286
					    (sa_share_t)parent, "id");
......
3796 3779

  
3797 3780
				if (!sa_group_is_zfs(group)) {
3798 3781
					/* ZFS doesn't use resource names */
3799
					sa_handle_impl_t ihandle;
3782
					sa_handle_t handle;
3800 3783

  
3801
					ihandle = (sa_handle_impl_t)
3802
					    sa_find_group_handle(
3784
					handle = sa_find_group_handle(
3803 3785
					    group);
3804
					if (ihandle != NULL)
3786
					if (handle != NULL)
3805 3787
						err = sa_commit_share(
3806
						    ihandle->scfhandle, group,
3788
						    handle->scfhandle, group,
3807 3789
						    share);
3808 3790
					else
3809 3791
						err = SA_SYSTEM_ERR;
......
3864 3846
		return (ret);
3865 3847

  
3866 3848
	if (!sa_group_is_zfs(group)) {
3867
		sa_handle_impl_t ihandle;
3868
		ihandle = (sa_handle_impl_t)sa_find_group_handle(group);
3869
		if (ihandle != NULL)
3870
			ret = sa_commit_share(ihandle->scfhandle, group, share);
3849
		sa_handle_t handle = sa_find_group_handle(group);
3850
		if (handle != NULL)
3851
			ret = sa_commit_share(handle->scfhandle, group, share);
3871 3852
		else
3872 3853
			ret = SA_SYSTEM_ERR;
3873 3854
	} else {
......
3930 3911
	if (group == NULL)
3931 3912
		return (ret);
3932 3913

  
3933
	handle = (sa_handle_impl_t)sa_find_group_handle(group);
3914
	handle = sa_find_group_handle(group);
3934 3915
	if (handle == NULL)
3935 3916
		return (ret);
3936 3917

  
......
3950 3931
			return (ret);
3951 3932

  
3952 3933
		if (!sa_group_is_zfs(group)) {
3953
			sa_handle_impl_t ihandle = (sa_handle_impl_t)handle;
3954
			ret = sa_commit_share(ihandle->scfhandle, group,
3934
			ret = sa_commit_share(handle->scfhandle, group,
3955 3935
			    share);
3956 3936
		} else {
3957 3937
			ret = sa_zfs_update((sa_share_t)group);
......
4364 4344
	group = sa_get_parent_group(share);
4365 4345
	if (group != NULL &&
4366 4346
	    sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
4367
		sa_handle_impl_t impl_handle;
4368
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
4369
		if (impl_handle != NULL)
4370
			ret = sa_commit_share(impl_handle->scfhandle,
4347
		sa_handle_t handle = sa_find_group_handle(group);
4348
		if (handle != NULL)
4349
			ret = sa_commit_share(handle->scfhandle,
4371 4350
			    group, share);
4372 4351
		else
4373 4352
			ret = SA_SYSTEM_ERR;
usr/src/lib/libshare/common/libshare.h
21 21

  
22 22
/*
23 23
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24
 * Copyright (c) 2013 RackTop Systems.
24 25
 */
25 26

  
26 27
/*
......
48 49
typedef void *sa_protocol_properties_t;
49 50
typedef void *sa_resource_t;
50 51

  
51
typedef void *sa_handle_t;	/* opaque handle to access core functions */
52
typedef struct sa_handle *sa_handle_t;	/* opaque handle to access core functions */
52 53

  
53 54
/*
54 55
 * defined error values
......
177 178
extern int sa_set_share_description(sa_share_t, char *);
178 179
extern int sa_enable_share(sa_group_t, char *);
179 180
extern int sa_disable_share(sa_share_t, char *);
180
extern int sa_is_share(void *);
181
extern boolean_t sa_is_share(void *);
181 182

  
182 183
/* resource name related */
183 184
extern sa_resource_t sa_find_resource(sa_handle_t, char *);
......
222 223
extern int sa_remove_property(sa_property_t);
223 224
extern int sa_commit_properties(sa_optionset_t, int);
224 225
extern int sa_valid_property(sa_handle_t, void *, char *, sa_property_t);
225
extern int sa_is_persistent(void *);
226
extern boolean_t sa_is_persistent(void *);
226 227

  
227 228
/* security control */
228 229
extern sa_security_t sa_get_security(sa_group_t, char *, char *);
......
238 239
/* protocol specific interfaces */
239 240
extern int sa_parse_legacy_options(sa_group_t, char *, char *);
240 241
extern char *sa_proto_legacy_format(char *, sa_group_t, int);
241
extern int sa_is_security(char *, char *);
242
extern boolean_t sa_is_security(char *, char *);
242 243
extern sa_protocol_properties_t sa_proto_get_properties(char *);
243 244
extern uint64_t sa_proto_get_featureset(char *);
244 245
extern sa_property_t sa_get_protocol_section(sa_protocol_properties_t, char *);
......
266 267
extern int sa_delete_sharetab(sa_handle_t, char *, char *);
267 268

  
268 269
/* ZFS functions */
269
extern int sa_zfs_is_shared(sa_handle_t, char *);
270
extern int sa_group_is_zfs(sa_group_t);
271
extern int sa_path_is_zfs(char *);
270
extern boolean_t sa_zfs_is_shared(sa_handle_t, char *);
271
extern boolean_t sa_group_is_zfs(sa_group_t);
272
extern boolean_t sa_path_is_zfs(char *);
272 273
extern int sa_zfs_setprop(sa_handle_t, char *, nvlist_t *);
273 274

  
274 275
/* SA Handle specific functions */
usr/src/lib/libshare/common/libshare_impl.h
25 25
 */
26 26

  
27 27
/*
28
 * Copyright (c) 2013 RackTop Systems.
29
 */
30

  
31
/*
28 32
 * basic declarations for implementation of the share management
29 33
 * libraries.
30 34
 */
......
100 104
} property_list_t;
101 105

  
102 106
/* internal version of sa_handle_t */
103
typedef struct sa_handle_impl {
107
struct sa_handle {
104 108
	uint64_t	flags;
105 109
	scfutilhandle_t	*scfhandle;
106 110
	libzfs_handle_t *zfs_libhandle;
......
110 114
	xmlDocPtr	doc;
111 115
	uint64_t	tssharetab;
112 116
	uint64_t	tstrans;
113
} *sa_handle_impl_t;
117
};
114 118

  
115 119
extern int sa_proto_share(char *, sa_share_t);
116 120
extern int sa_proto_unshare(sa_share_t, char *, char *);
......
129 133
extern void sa_free_derived_security(sa_security_t);
130 134
extern sa_protocol_properties_t sa_create_protocol_properties(char *);
131 135
extern int sa_start_transaction(scfutilhandle_t *, char *);
132
extern int sa_end_transaction(scfutilhandle_t *, sa_handle_impl_t);
136
extern int sa_end_transaction(scfutilhandle_t *, sa_handle_t);
133 137
extern void sa_abort_transaction(scfutilhandle_t *);
134 138
extern int sa_commit_share(scfutilhandle_t *, sa_group_t, sa_share_t);
135 139
extern int sa_set_property(scfutilhandle_t *, char *, char *);
usr/src/lib/libshare/common/libshare_zfs.c
21 21

  
22 22
/*
23 23
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24
 */
25
/*
26 24
 * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
25
 * Copyright (c) 2013 RackTop Systems.
27 26
 */
28 27

  
29 28
#include <stdio.h>
......
41 40
extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
42 41
extern char *sa_fstype(char *);
43 42
extern void set_node_attr(void *, char *, char *);
44
extern int sa_is_share(void *);
43
extern boolean_t sa_is_share(void *);
45 44
extern void sa_update_sharetab_ts(sa_handle_t);
46 45

  
47 46
/*
......
58 57
} get_all_cbdata_t;
59 58

  
60 59
/*
61
 * sa_zfs_init(impl_handle)
60
 * sa_zfs_init(handle)
62 61
 *
63 62
 * Initialize an access handle into libzfs.  The handle needs to stay
64 63
 * around until sa_zfs_fini() in order to maintain the cache of
......
66 65
 */
67 66

  
68 67
int
69
sa_zfs_init(sa_handle_impl_t impl_handle)
68
sa_zfs_init(sa_handle_t handle)
70 69
{
71
	impl_handle->zfs_libhandle = libzfs_init();
72
	if (impl_handle->zfs_libhandle != NULL) {
73
		libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE);
70
	handle->zfs_libhandle = libzfs_init();
71
	if (handle->zfs_libhandle != NULL) {
72
		libzfs_print_on_error(handle->zfs_libhandle, B_TRUE);
74 73
		return (B_TRUE);
75 74
	}
76 75
	return (B_FALSE);
77 76
}
78 77

  
79 78
/*
80
 * sa_zfs_fini(impl_handle)
79
 * sa_zfs_fini(handle)
81 80
 *
82 81
 * cleanup data structures and the libzfs handle used for accessing
83 82
 * zfs file share info.
84 83
 */
85 84

  
86 85
void
87
sa_zfs_fini(sa_handle_impl_t impl_handle)
86
sa_zfs_fini(sa_handle_t handle)
88 87
{
89
	if (impl_handle->zfs_libhandle != NULL) {
90
		if (impl_handle->zfs_list != NULL) {
91
			zfs_handle_t **zhp = impl_handle->zfs_list;
88
	if (handle->zfs_libhandle != NULL) {
89
		if (handle->zfs_list != NULL) {
90
			zfs_handle_t **zhp = handle->zfs_list;
92 91
			size_t i;
93 92

  
94 93
			/*
95 94
			 * Contents of zfs_list need to be freed so we
96 95
			 * don't lose ZFS handles.
97 96
			 */
98
			for (i = 0; i < impl_handle->zfs_list_count; i++) {
97
			for (i = 0; i < handle->zfs_list_count; i++) {
99 98
				zfs_close(zhp[i]);
100 99
			}
101
			free(impl_handle->zfs_list);
102
			impl_handle->zfs_list = NULL;
103
			impl_handle->zfs_list_count = 0;
100
			free(handle->zfs_list);
101
			handle->zfs_list = NULL;
102
			handle->zfs_list_count = 0;
104 103
		}
105 104

  
106
		libzfs_fini(impl_handle->zfs_libhandle);
107
		impl_handle->zfs_libhandle = NULL;
105
		libzfs_fini(handle->zfs_libhandle);
106
		handle->zfs_libhandle = NULL;
108 107
	}
109 108
}
110 109

  
......
183 182
 */
184 183

  
185 184
static void
186
get_all_filesystems(sa_handle_impl_t impl_handle,
185
get_all_filesystems(sa_handle_t handle,
187 186
			zfs_handle_t ***fslist, size_t *count)
188 187
{
189 188
	get_all_cbdata_t cb = { 0 };
190 189
	cb.cb_types = ZFS_TYPE_FILESYSTEM;
191 190

  
192
	if (impl_handle->zfs_list != NULL) {
193
		*fslist = impl_handle->zfs_list;
194
		*count = impl_handle->zfs_list_count;
191
	if (handle->zfs_list != NULL) {
192
		*fslist = handle->zfs_list;
193
		*count = handle->zfs_list_count;
195 194
		return;
196 195
	}
197 196

  
198
	(void) zfs_iter_root(impl_handle->zfs_libhandle,
197
	(void) zfs_iter_root(handle->zfs_libhandle,
199 198
	    get_one_filesystem, &cb);
200 199

  
201
	impl_handle->zfs_list = *fslist = cb.cb_handles;
202
	impl_handle->zfs_list_count = *count = cb.cb_used;
200
	handle->zfs_list = *fslist = cb.cb_handles;
201
	handle->zfs_list_count = *count = cb.cb_used;
203 202
}
204 203

  
205 204
/*
......
261 260
}
262 261

  
263 262
/*
264
 * get_zfs_dataset(impl_handle, path)
263
 * get_zfs_dataset(handle, path)
265 264
 *
266 265
 * get the name of the ZFS dataset the path is equivalent to.  The
267 266
 * dataset name is used for get/set of ZFS properties since libzfs
......
269 268
 */
270 269

  
271 270
static char *
272
get_zfs_dataset(sa_handle_impl_t impl_handle, char *path,
271
get_zfs_dataset(sa_handle_t handle, char *path,
273 272
    boolean_t search_mnttab)
274 273
{
275 274
	size_t i, count = 0;
......
278 277
	char mountpoint[ZFS_MAXPROPLEN];
279 278
	char canmount[ZFS_MAXPROPLEN];
280 279

  
281
	get_all_filesystems(impl_handle, &zlist, &count);
280
	get_all_filesystems(handle, &zlist, &count);
282 281
	qsort(zlist, count, sizeof (void *), mountpoint_compare);
283 282
	for (i = 0; i < count; i++) {
284 283
		/* must have a mountpoint */
......
335 334
 */
336 335

  
337 336
static char *
338
get_zfs_property(char *dataset, zfs_prop_t property)
337
get_zfs_property(sa_handle_t handle, char *dataset, zfs_prop_t property)
339 338
{
340
	zfs_handle_t *handle = NULL;
339
	zfs_handle_t *z_fs;
341 340
	char shareopts[ZFS_MAXPROPLEN];
342
	libzfs_handle_t *libhandle;
343

  
344
	libhandle = libzfs_init();
345
	if (libhandle != NULL) {
346
		handle = zfs_open(libhandle, dataset, ZFS_TYPE_FILESYSTEM);
347
		if (handle != NULL) {
348
			if (zfs_prop_get(handle, property, shareopts,
349
			    sizeof (shareopts), NULL, NULL, 0,
350
			    B_FALSE) == 0) {
351
				zfs_close(handle);
352
				libzfs_fini(libhandle);
353
				return (strdup(shareopts));
354
			}
355
			zfs_close(handle);
341

  
342
	z_fs = zfs_open(handle->zfs_libhandle, dataset, ZFS_TYPE_FILESYSTEM);
343
	if (z_fs != NULL) {
344
		if (zfs_prop_get(z_fs, property, shareopts,
345
		    sizeof (shareopts), NULL, NULL, 0,
346
		    B_FALSE) == 0) {
347
			zfs_close(z_fs);
348
			return (strdup(shareopts));
356 349
		}
357
		libzfs_fini(libhandle);
350
		zfs_close(z_fs);
358 351
	}
359 352
	return (NULL);
360 353
}
......
366 359
 * or not.
367 360
 */
368 361

  
369
int
370
sa_zfs_is_shared(sa_handle_t sahandle, char *path)
362
boolean_t
363
sa_zfs_is_shared(sa_handle_t handle, char *path)
371 364
{
372
	int ret = 0;
365
	int ret = B_FALSE;
373 366
	char *dataset;
374
	zfs_handle_t *handle = NULL;
367
	zfs_handle_t *z_fs = NULL;
375 368
	char shareopts[ZFS_MAXPROPLEN];
376
	libzfs_handle_t *libhandle;
377 369

  
378
	dataset = get_zfs_dataset((sa_handle_t)sahandle, path, B_FALSE);
370
	dataset = get_zfs_dataset(handle, path, B_FALSE);
379 371
	if (dataset != NULL) {
380
		libhandle = libzfs_init();
381
		if (libhandle != NULL) {
382
			handle = zfs_open(libhandle, dataset,
383
			    ZFS_TYPE_FILESYSTEM);
384
			if (handle != NULL) {
385
				if (zfs_prop_get(handle, ZFS_PROP_SHARENFS,
386
				    shareopts, sizeof (shareopts), NULL, NULL,
387
				    0, B_FALSE) == 0 &&
388
				    strcmp(shareopts, "off") != 0) {
389
					ret = 1; /* it is shared */
390
				}
391
				zfs_close(handle);
372
		z_fs = zfs_open(handle->zfs_libhandle, dataset,
373
		    ZFS_TYPE_FILESYSTEM);
374
		if (z_fs != NULL) {
375
			if (zfs_prop_get(z_fs, ZFS_PROP_SHARENFS,
376
			    shareopts, sizeof (shareopts), NULL, NULL,
377
			    0, B_FALSE) == 0 &&
378
			    strcmp(shareopts, "off") != 0) {
379
				ret = B_TRUE; /* it is shared */
392 380
			}
393
			libzfs_fini(libhandle);
381
			zfs_close(z_fs);
394 382
		}
395 383
		free(dataset);
396 384
	}
......
763 751
	/*
764 752
	 * If we can't access libzfs, don't bother doing anything.
765 753
	 */
766
	zfs_libhandle = ((sa_handle_impl_t)handle)->zfs_libhandle;
754
	zfs_libhandle = handle->zfs_libhandle;
767 755
	if (zfs_libhandle == NULL)
768 756
		return (SA_SYSTEM_ERR);
769 757

  
......
776 764
	 * need to walk the mounted ZFS pools and datasets to
777 765
	 * find shares that are possible.
778 766
	 */
779
	get_all_filesystems((sa_handle_impl_t)handle, &zlist, &count);
767
	get_all_filesystems(handle, &zlist, &count);
780 768
	qsort(zlist, count, sizeof (void *), mountpoint_compare);
781 769

  
782 770
	for (i = 0; i < count; i++) {
......
932 920
		char *opts = NULL;
933 921
		char *dataset = NULL;
934 922
		FILE *pfile;
935
		sa_handle_impl_t impl_handle;
923
		sa_handle_t handle;
936 924
		/* for now, NFS is always available for "zfs" */
937 925
		if (on) {
938 926
			opts = sa_proto_legacy_format("nfs", group, 1);
......
942 930
			}
943 931
		}
944 932

  
945
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
946
		assert(impl_handle != NULL);
947
		if (impl_handle != NULL)
948
			dataset = get_zfs_dataset(impl_handle, path, B_FALSE);
933
		handle = sa_find_group_handle(group);
934
		assert(handle != NULL);
935
		if (handle != NULL)
936
			dataset = get_zfs_dataset(handle, path, B_FALSE);
949 937
		else
950 938
			ret = SA_SYSTEM_ERR;
951 939

  
......
1043 1031
		char *opts = NULL;
1044 1032
		char *dataset = NULL;
1045 1033
		FILE *pfile;
1046
		sa_handle_impl_t impl_handle;
1034
		sa_handle_t handle;
1047 1035

  
1048 1036
		if (on) {
1049 1037
			char *newopt;
......
1059 1047
			opts = newopt;
1060 1048
		}
1061 1049

  
1062
		impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
1063
		assert(impl_handle != NULL);
1064
		if (impl_handle != NULL)
1065
			dataset = get_zfs_dataset(impl_handle, path, B_FALSE);
1050
		handle = sa_find_group_handle(group);
1051
		assert(handle != NULL);
1052
		if (handle != NULL)
1053
			dataset = get_zfs_dataset(handle, path, B_FALSE);
1066 1054
		else
1067 1055
			ret = SA_SYSTEM_ERR;
1068 1056

  
......
1126 1114
				path = sa_get_share_attr((sa_share_t)group,
1127 1115
				    "path");
1128 1116
				if (path != NULL) {
1129
					sa_handle_impl_t impl_handle;
1117
					sa_handle_t handle;
1130 1118

  
1131
					impl_handle = sa_find_group_handle(
1119
					handle = sa_find_group_handle(
1132 1120
					    group);
1133
					if (impl_handle != NULL)
1121
					if (handle != NULL)
1134 1122
						dataset = get_zfs_dataset(
1135
						    impl_handle, path, B_FALSE);
1123
						    handle, path, B_FALSE);
1136 1124
					else
1137 1125
						ret = SA_SYSTEM_ERR;
1138 1126

  
......
1144 1132
			/* update only when there is an optstring found */
1145 1133
			doupdate = 0;
1146 1134
			if (proto != NULL && dataset != NULL) {
1135
				sa_handle_t handle;
1136

  
1147 1137
				optstring = sa_proto_legacy_format(proto,
1148 1138
				    group, 1);
1149
				zfsopts = get_zfs_property(dataset,
1139
				handle = sa_find_group_handle(group);
1140
				zfsopts = get_zfs_property(handle, dataset,
1150 1141
				    ZFS_PROP_SHARENFS);
1151 1142

  
1152 1143
				if (optstring != NULL && zfsopts != NULL) {
......
1204 1195
 * Given the group, determine if the zfs attribute is set.
1205 1196
 */
1206 1197

  
1207
int
1198
boolean_t
1208 1199
sa_group_is_zfs(sa_group_t group)
1209 1200
{
1210 1201
	char *zfs;
1211
	int ret = 0;
1202
	int ret = B_FALSE;
1212 1203

  
1213 1204
	zfs = sa_get_group_attr(group, "zfs");
1214 1205
	if (zfs != NULL) {
1215
		ret = 1;
1206
		ret = B_TRUE;
1216 1207
		sa_free_attr_string(zfs);
1217 1208
	}
1218 1209
	return (ret);
......
1224 1215
 * Check to see if the file system path represents is of type "zfs".
1225 1216
 */
1226 1217

  
1227
int
1218
boolean_t
1228 1219
sa_path_is_zfs(char *path)
1229 1220
{
1230 1221
	char *fstype;
1231
	int ret = 0;
1222
	int ret = B_FALSE;
1232 1223

  
1233 1224
	fstype = sa_fstype(path);
1234 1225
	if (fstype != NULL && strcmp(fstype, "zfs") == 0)
1235
		ret = 1;
1226
		ret = B_TRUE;
1236 1227
	if (fstype != NULL)
1237 1228
		sa_free_fstype(fstype);
1238 1229
	return (ret);
......
1264 1255
sa_share_zfs(sa_share_t share, sa_resource_t resource, char *path, share_t *sh,
1265 1256
    void *exportdata, zfs_share_op_t operation)
1266 1257
{
1267
	libzfs_handle_t *libhandle;
1268 1258
	sa_group_t group;
1269
	sa_handle_t sahandle;
1259
	sa_handle_t handle;
1270 1260
	char *dataset;
1271 1261
	int err = EINVAL;
1272 1262
	int i, j;
1273 1263
	char newpath[MAXPATHLEN];
1274 1264
	char *pathp;
1265
	char *resource_name;
1275 1266

  
1276 1267
	/*
1277 1268
	 * First find the dataset name
......
1279 1270
	if ((group = sa_get_parent_group(share)) == NULL)  {
1280 1271
		return (EINVAL);
1281 1272
	}
1282
	if ((sahandle = sa_find_group_handle(group)) == NULL) {
1273
	if ((handle = sa_find_group_handle(group)) == NULL) {
1283 1274
		return (EINVAL);
1284 1275
	}
1285 1276

  
......
1288 1279
	 */
1289 1280

  
1290 1281
	pathp = path;
1291
	while ((dataset = get_zfs_dataset(sahandle, pathp, B_TRUE)) == NULL) {
1282
	while ((dataset = get_zfs_dataset(handle, pathp, B_TRUE)) == NULL) {
1292 1283
		char *p;
1293 1284

  
1294 1285
		if (pathp == path) {
......
1322 1313
		}
1323 1314
	}
1324 1315

  
1325
	libhandle = libzfs_init();
1326
	if (libhandle != NULL) {
1327
		char *resource_name;
1328

  
1329
		i = (sh->sh_path ? strlen(sh->sh_path) : 0);
1330
		sh->sh_size = i;
1316
	i = (sh->sh_path ? strlen(sh->sh_path) : 0);
1317
	sh->sh_size = i;
1331 1318

  
1332
		j = (sh->sh_res ? strlen(sh->sh_res) : 0);
1333
		sh->sh_size += j;
1334
		SMAX(i, j);
1319
	j = (sh->sh_res ? strlen(sh->sh_res) : 0);
1320
	sh->sh_size += j;
1321
	SMAX(i, j);
1335 1322

  
1336
		j = (sh->sh_fstype ? strlen(sh->sh_fstype) : 0);
1337
		sh->sh_size += j;
1338
		SMAX(i, j);
1323
	j = (sh->sh_fstype ? strlen(sh->sh_fstype) : 0);
1324
	sh->sh_size += j;
1325
	SMAX(i, j);
1339 1326

  
1340
		j = (sh->sh_opts ? strlen(sh->sh_opts) : 0);
1341
		sh->sh_size += j;
1342
		SMAX(i, j);
1327
	j = (sh->sh_opts ? strlen(sh->sh_opts) : 0);
1328
	sh->sh_size += j;
1329
	SMAX(i, j);
1343 1330

  
1344
		j = (sh->sh_descr ? strlen(sh->sh_descr) : 0);
1345
		sh->sh_size += j;
1346
		SMAX(i, j);
1331
	j = (sh->sh_descr ? strlen(sh->sh_descr) : 0);
1332
	sh->sh_size += j;
1333
	SMAX(i, j);
1347 1334

  
1348
		resource_name = sa_get_resource_attr(resource, "name");
1335
	resource_name = sa_get_resource_attr(resource, "name");
1349 1336

  
1350
		err = zfs_deleg_share_nfs(libhandle, dataset, path,
1351
		    resource_name, exportdata, sh, i, operation);
1352
		if (err == SA_OK)
1353
			sa_update_sharetab_ts(sahandle);
1354
		else
1355
			err = errno;
1356
		if (resource_name)
1357
			sa_free_attr_string(resource_name);
1337
	err = zfs_deleg_share_nfs(handle->zfs_libhandle, dataset, path,
1338
	    resource_name, exportdata, sh, i, operation);
1339
	if (err == SA_OK)
1340
		sa_update_sharetab_ts(handle);
1341
	else
1342
		err = errno;
1343
	if (resource_name != NULL)
1344
		sa_free_attr_string(resource_name);
1358 1345

  
1359
		libzfs_fini(libhandle);
1360
	}
1361 1346
	free(dataset);
1362 1347
	return (err);
1363 1348
}
......
1373 1358
libzfs_handle_t *
1374 1359
sa_get_zfs_handle(sa_handle_t handle)
1375 1360
{
1376
	sa_handle_impl_t implhandle = (sa_handle_impl_t)handle;
1377

  
1378
	return (implhandle->zfs_libhandle);
1379
}
1380

  
1381
/*
1382
 * sa_get_zfs_info(libzfs, path, mountpoint, dataset)
1383
 *
1384
 * Find the ZFS dataset and mountpoint for a given path
1385
 */
1386
int
1387
sa_zfs_get_info(libzfs_handle_t *libzfs, char *path, char *mountpointp,
1388
    char *datasetp)
1389
{
1390
	get_all_cbdata_t cb = { 0 };
1391
	int i;
1392
	char mountpoint[ZFS_MAXPROPLEN];
1393
	char dataset[ZFS_MAXPROPLEN];
1394
	char canmount[ZFS_MAXPROPLEN];
1395
	char *dp;
1396
	int count;
1397
	int ret = 0;
1398

  
1399
	cb.cb_types = ZFS_TYPE_FILESYSTEM;
1400

  
1401
	if (libzfs == NULL)
1402
		return (0);
1403

  
1404
	(void) zfs_iter_root(libzfs, get_one_filesystem, &cb);
1405
	count = cb.cb_used;
1406

  
1407
	qsort(cb.cb_handles, count, sizeof (void *), mountpoint_compare);
1408
	for (i = 0; i < count; i++) {
1409
		/* must have a mountpoint */
1410
		if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_MOUNTPOINT,
1411
		    mountpoint, sizeof (mountpoint),
1412
		    NULL, NULL, 0, B_FALSE) != 0) {
1413
			/* no mountpoint */
1414
			continue;
1415
		}
1416

  
1417
		/* mountpoint must be a path */
1418
		if (strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) == 0 ||
1419
		    strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) {
1420
			/*
1421
			 * Search mmttab for mountpoint
1422
			 */
1423

  
1424
			if (get_legacy_mountpoint(path, dataset,
1425
			    ZFS_MAXPROPLEN, mountpoint,
1426
			    ZFS_MAXPROPLEN) == 0) {
1427
				ret = 1;
1428
				break;
1429
			}
1430
			continue;
1431
		}
1432

  
1433
		/* canmount must be set */
1434
		canmount[0] = '\0';
1435
		if (zfs_prop_get(cb.cb_handles[i], ZFS_PROP_CANMOUNT, canmount,
1436
		    sizeof (canmount), NULL, NULL, 0, B_FALSE) != 0 ||
1437
		    strcmp(canmount, "off") == 0)
1438
			continue;
1439

  
1440
		/*
1441
		 * have a mountable handle but want to skip those marked none
1442
		 * and legacy
1443
		 */
1444
		if (strcmp(mountpoint, path) == 0) {
1445
			dp = (char *)zfs_get_name(cb.cb_handles[i]);
1446
			if (dp != NULL) {
1447
				if (datasetp != NULL)
1448
					(void) strcpy(datasetp, dp);
1449
				if (mountpointp != NULL)
1450
					(void) strcpy(mountpointp, mountpoint);
1451
				ret = 1;
1452
			}
1453
			break;
1454
		}
1455

  
1456
	}
1457

  
1458
	return (ret);
1361
	return (handle->zfs_libhandle);
1459 1362
}
1460 1363

  
1461 1364
/*
......
1465 1368
static int
1466 1369
sa_zfs_sprintf_new_prop(nvlist_t *nvl, char *sharesmb_val)
1467 1370
{
1468
	char cur_val[MAXPATHLEN];
1371
	char cur_val[ZFS_MAXPROPLEN];
1469 1372
	char *name, *val;
1470 1373
	nvpair_t *cur;
1471 1374
	int err = 0;
......
1477 1380
		if ((err != 0) || (name == NULL) || (val == NULL))
1478 1381
			return (-1);
1479 1382

  
1480
		(void) snprintf(cur_val, MAXPATHLEN, "%s=%s,", name, val);
1481
		(void) strlcat(sharesmb_val, cur_val, MAXPATHLEN);
1383
		(void) snprintf(cur_val, ZFS_MAXPROPLEN, "%s=%s,", name, val);
1384
		(void) strlcat(sharesmb_val, cur_val, ZFS_MAXPROPLEN);
1482 1385

  
1483 1386
		cur = nvlist_next_nvpair(nvl, cur);
1484 1387
	}
......
1497 1400
static int
1498 1401
sa_zfs_sprintf_existing_prop(zfs_handle_t *handle, char *sharesmb_val)
1499 1402
{
1500
	char shareopts[ZFS_MAXPROPLEN], cur_val[MAXPATHLEN];
1403
	char shareopts[ZFS_MAXPROPLEN], cur_val[ZFS_MAXPROPLEN];
1501 1404
	char *token, *last, *value;
1502 1405

  
1503 1406
	if (zfs_prop_get(handle, ZFS_PROP_SHARESMB, shareopts,
......
1514 1417
			return (-1);
1515 1418
		*value++ = '\0';
1516 1419

  
1517
		(void) snprintf(cur_val, MAXPATHLEN, "%s=", token);
1420
		(void) snprintf(cur_val, ZFS_MAXPROPLEN, "%s=", token);
1518 1421
		if (strstr(sharesmb_val, cur_val) == NULL) {
1519
			(void) strlcat(cur_val, value, MAXPATHLEN);
1520
			(void) strlcat(cur_val, ",", MAXPATHLEN);
1521
			(void) strlcat(sharesmb_val, cur_val, MAXPATHLEN);
1422
			(void) strlcat(cur_val, value, ZFS_MAXPROPLEN);
1423
			(void) strlcat(cur_val, ",", ZFS_MAXPROPLEN);
1424
			(void) strlcat(sharesmb_val, cur_val, ZFS_MAXPROPLEN);
1522 1425
		}
1523 1426
	}
1524 1427

  
......
1540 1443
sa_zfs_setprop(sa_handle_t handle, char *path, nvlist_t *nvl)
1541 1444
{
1542 1445
	zfs_handle_t *z_fs;
1543
	libzfs_handle_t *z_lib;
1544
	char sharesmb_val[MAXPATHLEN];
1446
	char sharesmb_val[ZFS_MAXPROPLEN];
1545 1447
	char *dataset, *lastcomma;
1546 1448

  
1547 1449
	if (nvlist_empty(nvl))
......
1553 1455
	if ((dataset = get_zfs_dataset(handle, path, B_FALSE)) == NULL)
1554 1456
		return (-1);
1555 1457

  
1556
	if ((z_lib = libzfs_init()) == NULL) {
1557
		free(dataset);
1558
		return (-1);
1559
	}
1560

  
1561
	z_fs = zfs_open(z_lib, dataset, ZFS_TYPE_DATASET);
1458
	z_fs = zfs_open(handle->zfs_libhandle, dataset, ZFS_TYPE_DATASET);
1562 1459
	if (z_fs == NULL) {
1563 1460
		free(dataset);
1564
		libzfs_fini(z_lib);
1565 1461
		return (-1);
1566 1462
	}
1567 1463

  
1568
	bzero(sharesmb_val, MAXPATHLEN);
1464
	bzero(sharesmb_val, ZFS_MAXPROPLEN);
1569 1465
	if (sa_zfs_sprintf_new_prop(nvl, sharesmb_val) != 0) {
1570 1466
		free(dataset);
1571 1467
		zfs_close(z_fs);
1572
		libzfs_fini(z_lib);
1573 1468
		return (-1);
1574 1469
	}
1575 1470

  
1576 1471
	if (sa_zfs_sprintf_existing_prop(z_fs, sharesmb_val) != 0) {
1577 1472
		free(dataset);
1578 1473
		zfs_close(z_fs);
1579
		libzfs_fini(z_lib);
1580 1474
		return (-1);
1581 1475
	}
1582 1476

  
......
1588 1482
	    sharesmb_val);
1589 1483
	free(dataset);
1590 1484
	zfs_close(z_fs);
1591
	libzfs_fini(z_lib);
1592 1485

  
1593 1486
	return (0);
1594 1487
}
usr/src/lib/libshare/common/libsharecore.c
21 21

  
22 22
/*
23 23
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24
 * Copyright (c) 2013 RackTop Systems.
24 25
 */
25 26

  
26 27
/*
......
90 91
/* prototypes */
91 92
void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
92 93
extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
93
extern sa_group_t _sa_create_group(sa_handle_impl_t, char *);
94
extern sa_group_t _sa_create_group(sa_handle_t, char *);
94 95
static void outdfstab(FILE *, xfs_sharelist_t *);
95 96
extern int _sa_remove_optionset(sa_optionset_t);
96 97
extern int set_node_share(void *, char *, char *);
......
741 742
 * property for the specified protocol.
742 743
 */
743 744

  
744
int
745
boolean_t
745 746
sa_is_security(char *optname, char *proto)
746 747
{
747
	int ret = 0;
748
	int ret = B_FALSE;
748 749
	if (proto != NULL)
749 750
		ret = sa_proto_security_prop(proto, optname);
750 751
	return (ret);
......
775 776
 * returns true of the object is of type "share".
776 777
 */
777 778

  
778
int
779
boolean_t
779 780
sa_is_share(void *object)
780 781
{
781 782
	if (object != NULL) {
782 783
		if (strcmp((char *)((xmlNodePtr)object)->name, "share") == 0)
783
		return (1);
784
		return (B_TRUE);
784 785
	}
785
	return (0);
786
	return (B_FALSE);
786 787
}
787 788
/*
788 789
 * sa_is_resource(object)
......
790 791
 * returns true of the object is of type "share".
791 792
 */
792 793

  
793
int
794
boolean_t
... This diff was truncated because it exceeds the maximum size that can be displayed.
    (1-1/1)