16185db8dougm/*
26185db8dougm * CDDL HEADER START
36185db8dougm *
46185db8dougm * The contents of this file are subject to the terms of the
56185db8dougm * Common Development and Distribution License (the "License").
66185db8dougm * You may not use this file except in compliance with the License.
76185db8dougm *
86185db8dougm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96185db8dougm * or http://www.opensolaris.org/os/licensing.
106185db8dougm * See the License for the specific language governing permissions
116185db8dougm * and limitations under the License.
126185db8dougm *
136185db8dougm * When distributing Covered Code, include this CDDL HEADER in each
146185db8dougm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156185db8dougm * If applicable, add the following below this CDDL HEADER, with the
166185db8dougm * fields enclosed by brackets "[]" replaced with your own identifying
176185db8dougm * information: Portions Copyright [yyyy] [name of copyright owner]
186185db8dougm *
196185db8dougm * CDDL HEADER END
206185db8dougm */
216185db8dougm
226185db8dougm/*
23148c5f4Alan Wright * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24b8dc1b4Joyce McIntosh * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
258a981c3Daniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
266185db8dougm */
276185db8dougm
286185db8dougm/*
296185db8dougm * basic API declarations for share management
306185db8dougm */
316185db8dougm
326185db8dougm#ifndef _LIBSHARE_H
336185db8dougm#define	_LIBSHARE_H
346185db8dougm
356185db8dougm#ifdef	__cplusplus
366185db8dougmextern "C" {
376185db8dougm#endif
386185db8dougm
39da6c28aamw#include <sys/types.h>
40b819ceaGordon Ross#include <sys/nvpair.h>
418a981c3Daniel Hoffman#include <libzfs.h>
42da6c28aamw
436185db8dougm/*
446185db8dougm * Basic datatypes for most functions
456185db8dougm */
466185db8dougmtypedef void *sa_group_t;
476185db8dougmtypedef void *sa_share_t;
486185db8dougmtypedef void *sa_property_t;
496185db8dougmtypedef void *sa_optionset_t;
506185db8dougmtypedef void *sa_security_t;
516185db8dougmtypedef void *sa_protocol_properties_t;
52da6c28aamwtypedef void *sa_resource_t;
536185db8dougm
546185db8dougmtypedef void *sa_handle_t;	/* opaque handle to access core functions */
556185db8dougm
566185db8dougm/*
576185db8dougm * defined error values
586185db8dougm */
596185db8dougm
606185db8dougm#define	SA_OK			0
616185db8dougm#define	SA_NO_SUCH_PATH		1	/* provided path doesn't exist */
626185db8dougm#define	SA_NO_MEMORY		2	/* no memory for data structures */
636185db8dougm#define	SA_DUPLICATE_NAME	3	/* object name is already in use */
646185db8dougm#define	SA_BAD_PATH		4	/* not a full path */
656185db8dougm#define	SA_NO_SUCH_GROUP	5	/* group is not defined */
666185db8dougm#define	SA_CONFIG_ERR		6	/* system configuration error */
676185db8dougm#define	SA_SYSTEM_ERR		7	/* system error, use errno */
686185db8dougm#define	SA_SYNTAX_ERR		8	/* syntax error on command line */
696185db8dougm#define	SA_NO_PERMISSION	9	/* no permission for operation */
706185db8dougm#define	SA_BUSY			10	/* resource is busy */
716185db8dougm#define	SA_NO_SUCH_PROP		11	/* property doesn't exist */
726185db8dougm#define	SA_INVALID_NAME		12	/* name of object is invalid */
736185db8dougm#define	SA_INVALID_PROTOCOL	13	/* specified protocol not valid */
746185db8dougm#define	SA_NOT_ALLOWED		14	/* operation not allowed */
756185db8dougm#define	SA_BAD_VALUE		15	/* bad value for property */
766185db8dougm#define	SA_INVALID_SECURITY	16	/* invalid security type */
776185db8dougm#define	SA_NO_SUCH_SECURITY	17	/* security set not found */
786185db8dougm#define	SA_VALUE_CONFLICT	18	/* property value conflict */
796185db8dougm#define	SA_NOT_IMPLEMENTED	19	/* plugin interface not implemented */
806185db8dougm#define	SA_INVALID_PATH		20	/* path is sub-dir of existing share */
816185db8dougm#define	SA_NOT_SUPPORTED	21	/* operation not supported for proto */
826185db8dougm#define	SA_PROP_SHARE_ONLY	22	/* property valid on share only */
836185db8dougm#define	SA_NOT_SHARED		23	/* path is not shared */
84da6c28aamw#define	SA_NO_SUCH_RESOURCE	24	/* resource not found */
85da6c28aamw#define	SA_RESOURCE_REQUIRED	25	/* resource name is required  */
86da6c28aamw#define	SA_MULTIPLE_ERROR	26	/* multiple protocols reported error */
87da6c28aamw#define	SA_PATH_IS_SUBDIR	27	/* check_path found path is subdir */
88da6c28aamw#define	SA_PATH_IS_PARENTDIR	28	/* check_path found path is parent */
894bff34ethurlow#define	SA_NO_SECTION		29	/* protocol requires section info */
904bff34ethurlow#define	SA_NO_SUCH_SECTION	30	/* no section found */
914bff34ethurlow#define	SA_NO_PROPERTIES	31	/* no properties found */
924bff34ethurlow#define	SA_PASSWORD_ENC		32	/* passwords must be encrypted */
930616fd7Pavel Filipensky#define	SA_SHARE_EXISTS		33	/* path or file is already shared */
946185db8dougm
956185db8dougm/* API Initialization */
968a981c3Daniel Hoffman/* Both of these do not care about the value of arg in sa_init_arg */
976185db8dougm#define	SA_INIT_SHARE_API	0x0001	/* init share specific interface */
986185db8dougm#define	SA_INIT_CONTROL_API	0x0002	/* init control specific interface */
996185db8dougm
1008a981c3Daniel Hoffman/* expects an sa_init_selective_arg_t as an argument */
1018a981c3Daniel Hoffman#define	SA_INIT_SHARE_API_SELECTIVE	0x0004	/* only some shares */
1028a981c3Daniel Hoffmanstruct sa_init_selective_arg {
1038a981c3Daniel Hoffman	zfs_handle_t **zhandle_arr;
1048a981c3Daniel Hoffman	size_t zhandle_len;
1058a981c3Daniel Hoffman};
1068a981c3Daniel Hoffmantypedef struct sa_init_selective_arg sa_init_selective_arg_t;
1078a981c3Daniel Hoffman
1088a981c3Daniel Hoffman
1098a981c3Daniel Hoffman/*
1108a981c3Daniel Hoffman * The SA_INIT_ONE_SHARE* initialization options to sa_init* will cause
1118a981c3Daniel Hoffman * sa_needs_refrsh() to return true even if nothing else in the system has
1128a981c3Daniel Hoffman * changed. If writing code that could possibly need to share/unshare multiple
1138a981c3Daniel Hoffman * shares, it is recommended to use SA_INIT_SHARE_API_SELECTIVE.
1148a981c3Daniel Hoffman */
1158a981c3Daniel Hoffman/* Expects a single char * as input, the name of the share. */
1168a981c3Daniel Hoffman#define	SA_INIT_ONE_SHARE_FROM_NAME	0x0008
1178a981c3Daniel Hoffman
1188a981c3Daniel Hoffman/* Expects a single zfs_handle_t as input, the handle of the share. */
1198a981c3Daniel Hoffman#define	SA_INIT_ONE_SHARE_FROM_HANDLE	0x0010
1208a981c3Daniel Hoffman
1216185db8dougm/* not part of API returns */
1226185db8dougm#define	SA_LEGACY_ERR		32	/* share/unshare error return */
1236185db8dougm
1246185db8dougm/*
1256185db8dougm * other defined values
1266185db8dougm */
1276185db8dougm
1286185db8dougm#define	SA_MAX_NAME_LEN		100	/* must fit service instance name */
129da6c28aamw#define	SA_MAX_RESOURCE_NAME	255	/* Maximum length of resource name */
130f345c0bdougm
131da6c28aamw/* Used in calls to sa_add_share() and sa_add_resource() */
1326185db8dougm#define	SA_SHARE_TRANSIENT	0	/* shared but not across reboot */
133f345c0bdougm#define	SA_SHARE_LEGACY		1	/* share is in dfstab only */
134f345c0bdougm#define	SA_SHARE_PERMANENT	2	/* share goes to repository */
135f345c0bdougm
136f345c0bdougm/* sa_check_path() related */
137f345c0bdougm#define	SA_CHECK_NORMAL		0	/* only check against active shares */
138f345c0bdougm#define	SA_CHECK_STRICT		1	/* check against all shares */
1396185db8dougm
1406185db8dougm/* RBAC related */
1416185db8dougm#define	SA_RBAC_MANAGE	"solaris.smf.manage.shares"
1426185db8dougm#define	SA_RBAC_VALUE	"solaris.smf.value.shares"
1436185db8dougm
1446185db8dougm/*
145da6c28aamw * Feature set bit definitions
146da6c28aamw */
147da6c28aamw
148da6c28aamw#define	SA_FEATURE_NONE		0x0000	/* no feature flags set */
149da6c28aamw#define	SA_FEATURE_RESOURCE	0x0001	/* resource names are required */
150da6c28aamw#define	SA_FEATURE_DFSTAB	0x0002	/* need to manage in dfstab */
151da6c28aamw#define	SA_FEATURE_ALLOWSUBDIRS	0x0004	/* allow subdirs to be shared */
152da6c28aamw#define	SA_FEATURE_ALLOWPARDIRS	0x0008	/* allow parent dirs to be shared */
1534bff34ethurlow#define	SA_FEATURE_HAS_SECTIONS	0x0010	/* protocol supports sections */
1544bff34ethurlow#define	SA_FEATURE_ADD_PROPERTIES	0x0020	/* can add properties */
1559e5da85dougm#define	SA_FEATURE_SERVER	0x0040	/* protocol supports server mode */
156da6c28aamw
157da6c28aamw/*
1586185db8dougm * legacy files
1596185db8dougm */
1606185db8dougm
1616185db8dougm#define	SA_LEGACY_DFSTAB	"/etc/dfs/dfstab"
1626185db8dougm#define	SA_LEGACY_SHARETAB	"/etc/dfs/sharetab"
1636185db8dougm
1646185db8dougm/*
1656185db8dougm * SMF related
1666185db8dougm */
1676185db8dougm
1686185db8dougm#define	SA_SVC_FMRI_BASE	"svc:/network/shares/group"
1696185db8dougm
1706185db8dougm/* initialization */
171549ec3fdougmextern sa_handle_t sa_init(int);
1728a981c3Daniel Hoffmanextern sa_handle_t sa_init_arg(int, void *);
173549ec3fdougmextern void sa_fini(sa_handle_t);
174b8dc1b4Joyce McIntoshextern int sa_service(sa_handle_t);
175b8dc1b4Joyce McIntosh
176549ec3fdougmextern int sa_update_config(sa_handle_t);
177a851ffcGordon Rossextern boolean_t sa_needs_refresh(sa_handle_t);
1786185db8dougmextern char *sa_errorstr(int);
1796185db8dougm
1806185db8dougm/* protocol names */
1816185db8dougmextern int sa_get_protocols(char ***);
1826185db8dougmextern int sa_valid_protocol(char *);
1836185db8dougm
1846185db8dougm/* group control (create, remove, etc) */
185549ec3fdougmextern sa_group_t sa_create_group(sa_handle_t, char *, int *);
1866185db8dougmextern int sa_remove_group(sa_group_t);
187549ec3fdougmextern sa_group_t sa_get_group(sa_handle_t, char *);
1886185db8dougmextern sa_group_t sa_get_next_group(sa_group_t);
1896185db8dougmextern char *sa_get_group_attr(sa_group_t, char *);
1906185db8dougmextern int sa_set_group_attr(sa_group_t, char *, char *);
1916185db8dougmextern sa_group_t sa_get_sub_group(sa_group_t);
1926185db8dougmextern int sa_valid_group_name(char *);
1936185db8dougm
1946185db8dougm/* share control */
1956185db8dougmextern sa_share_t sa_add_share(sa_group_t, char *, int, int *);
196f345c0bdougmextern int sa_check_path(sa_group_t, char *, int);
1976185db8dougmextern int sa_move_share(sa_group_t, sa_share_t);
1986185db8dougmextern int sa_remove_share(sa_share_t);
1996185db8dougmextern sa_share_t sa_get_share(sa_group_t, char *);
200549ec3fdougmextern sa_share_t sa_find_share(sa_handle_t, char *);
2016185db8dougmextern sa_share_t sa_get_next_share(sa_share_t);
2026185db8dougmextern char *sa_get_share_attr(sa_share_t, char *);
2036185db8dougmextern char *sa_get_share_description(sa_share_t);
2046185db8dougmextern sa_group_t sa_get_parent_group(sa_share_t);
2056185db8dougmextern int sa_set_share_attr(sa_share_t, char *, char *);
2066185db8dougmextern int sa_set_share_description(sa_share_t, char *);
2076185db8dougmextern int sa_enable_share(sa_group_t, char *);
208da6c28aamwextern int sa_disable_share(sa_share_t, char *);
2096185db8dougmextern int sa_is_share(void *);
2106185db8dougm
211da6c28aamw/* resource name related */
212da6c28aamwextern sa_resource_t sa_find_resource(sa_handle_t, char *);
213da6c28aamwextern sa_resource_t sa_get_resource(sa_group_t, char *);
214da6c28aamwextern sa_resource_t sa_get_next_resource(sa_resource_t);
215da6c28aamwextern sa_share_t sa_get_resource_parent(sa_resource_t);
216da6c28aamwextern sa_resource_t sa_get_share_resource(sa_share_t, char *);
217da6c28aamwextern sa_resource_t sa_add_resource(sa_share_t, char *, int, int *);
218da6c28aamwextern int sa_remove_resource(sa_resource_t);
219da6c28aamwextern char *sa_get_resource_attr(sa_resource_t, char *);
220da6c28aamwextern int sa_set_resource_attr(sa_resource_t, char *, char *);
221da6c28aamwextern int sa_set_resource_description(sa_resource_t, char *);
222da6c28aamwextern char *sa_get_resource_description(sa_resource_t);
223da6c28aamwextern int sa_enable_resource(sa_resource_t, char *);
224da6c28aamwextern int sa_disable_resource(sa_resource_t, char *);
225da6c28aamwextern int sa_rename_resource(sa_resource_t, char *);
226da6c28aamwextern void sa_fix_resource_name(char *);
227da6c28aamw
2286185db8dougm/* data structure free calls */
2296185db8dougmextern void sa_free_attr_string(char *);
2306185db8dougmextern void sa_free_share_description(char *);
2316185db8dougm
2326185db8dougm/* optionset control */
2336185db8dougmextern sa_optionset_t sa_get_optionset(sa_group_t, char *);
2346185db8dougmextern sa_optionset_t sa_get_next_optionset(sa_group_t);
2356185db8dougmextern char *sa_get_optionset_attr(sa_optionset_t, char *);
2366185db8dougmextern void sa_set_optionset_attr(sa_optionset_t, char *, char *);
2376185db8dougmextern sa_optionset_t sa_create_optionset(sa_group_t, char *);
2386185db8dougmextern int sa_destroy_optionset(sa_optionset_t);
2396185db8dougmextern sa_optionset_t sa_get_derived_optionset(void *, char *, int);
2406185db8dougmextern void sa_free_derived_optionset(sa_optionset_t);
2416185db8dougm
2426185db8dougm/* property functions */
2436733190dougmextern sa_property_t sa_get_property(sa_optionset_t, char *);
2446733190dougmextern sa_property_t sa_get_next_property(sa_group_t);
2456185db8dougmextern char *sa_get_property_attr(sa_property_t, char *);
2464bff34ethurlowextern sa_property_t sa_create_section(char *, char *);
2474bff34ethurlowextern void sa_set_section_attr(sa_property_t, char *, char *);
2486185db8dougmextern sa_property_t sa_create_property(char *, char *);
2496185db8dougmextern int sa_add_property(void *, sa_property_t);
2506185db8dougmextern int sa_update_property(sa_property_t, char *);
2516185db8dougmextern int sa_remove_property(sa_property_t);
2526185db8dougmextern int sa_commit_properties(sa_optionset_t, int);
253687915edougmextern int sa_valid_property(sa_handle_t, void *, char *, sa_property_t);
254da6c28aamwextern int sa_is_persistent(void *);
2556185db8dougm
2566185db8dougm/* security control */
2576185db8dougmextern sa_security_t sa_get_security(sa_group_t, char *, char *);
2586185db8dougmextern sa_security_t sa_get_next_security(sa_security_t);
2596185db8dougmextern char *sa_get_security_attr(sa_optionset_t, char *);
2606185db8dougmextern sa_security_t sa_create_security(sa_group_t, char *, char *);
2616185db8dougmextern int sa_destroy_security(sa_security_t);
2626185db8dougmextern void sa_set_security_attr(sa_security_t, char *, char *);
2636185db8dougmextern sa_optionset_t sa_get_all_security_types(void *, char *, int);
2646185db8dougmextern sa_security_t sa_get_derived_security(void *, char *, char *, int);
2656185db8dougmextern void sa_free_derived_security(sa_security_t);
2666185db8dougm
2676185db8dougm/* protocol specific interfaces */
2686185db8dougmextern int sa_parse_legacy_options(sa_group_t, char *, char *);
2696185db8dougmextern char *sa_proto_legacy_format(char *, sa_group_t, int);
2706185db8dougmextern int sa_is_security(char *, char *);
2716185db8dougmextern sa_protocol_properties_t sa_proto_get_properties(char *);
272da6c28aamwextern uint64_t sa_proto_get_featureset(char *);
2734bff34ethurlowextern sa_property_t sa_get_protocol_section(sa_protocol_properties_t, char *);
2744bff34ethurlowextern sa_property_t sa_get_next_protocol_section(sa_property_t, char *);
2756185db8dougmextern sa_property_t sa_get_protocol_property(sa_protocol_properties_t, char *);
2764bff34ethurlowextern sa_property_t sa_get_next_protocol_property(sa_property_t, char *);
2774bff34ethurlowextern int sa_set_protocol_property(sa_property_t, char *, char *);
2786185db8dougmextern char *sa_get_protocol_status(char *);
2796185db8dougmextern void sa_format_free(char *);
2806185db8dougmextern sa_protocol_properties_t sa_create_protocol_properties(char *);
2816185db8dougmextern int sa_add_protocol_property(sa_protocol_properties_t, sa_property_t);
282687915edougmextern int sa_proto_valid_prop(sa_handle_t, char *, sa_property_t,
283687915edougm    sa_optionset_t);
2846185db8dougmextern int sa_proto_valid_space(char *, char *);
2856185db8dougmextern char *sa_proto_space_alias(char *, char *);
286da6c28aamwextern int sa_proto_get_transients(sa_handle_t, char *);
287da6c28aamwextern int sa_proto_notify_resource(sa_resource_t, char *);
288da6c28aamwextern int sa_proto_change_notify(sa_share_t, char *);
2894bff34ethurlowextern int sa_proto_delete_section(char *, char *);
2906185db8dougm
2916185db8dougm/* handle legacy (dfstab/sharetab) files */
292da6c28aamwextern int sa_delete_legacy(sa_share_t, char *);
2936185db8dougmextern int sa_update_legacy(sa_share_t, char *);
2946185db8dougmextern int sa_update_sharetab(sa_share_t, char *);
2955b6e0c4dougmextern int sa_delete_sharetab(sa_handle_t, char *, char *);
2966185db8dougm
2976185db8dougm/* ZFS functions */
298549ec3fdougmextern int sa_zfs_is_shared(sa_handle_t, char *);
2996185db8dougmextern int sa_group_is_zfs(sa_group_t);
300ecd6cf8marksextern int sa_path_is_zfs(char *);
301148c5f4Alan Wrightextern int sa_zfs_setprop(sa_handle_t, char *, nvlist_t *);
302549ec3fdougm
303549ec3fdougm/* SA Handle specific functions */
304549ec3fdougmextern sa_handle_t sa_find_group_handle(sa_group_t);
305549ec3fdougm
3066185db8dougm#ifdef	__cplusplus
3076185db8dougm}
3086185db8dougm#endif
3096185db8dougm
3106185db8dougm#endif /* _LIBSHARE_H */
311