Removed build system from master branch, will relocate to linux-zfs-branch
[zfs.git] / zfs / lib / libport / include / libshare.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26
27 /*
28  * basic API declarations for share management
29  */
30
31 #include "zfs_config.h"
32
33 #ifdef HAVE_LIBSHARE
34 #include_next <libshare.h>
35 #else
36
37 #ifndef _LIBSHARE_H
38 #define _LIBSHARE_H
39
40
41
42 #ifdef  __cplusplus
43 extern "C" {
44 #endif
45
46 #include <sys/types.h>
47
48 /*
49  * Basic datatypes for most functions
50  */
51 typedef void *sa_group_t;
52 typedef void *sa_share_t;
53 typedef void *sa_property_t;
54 typedef void *sa_optionset_t;
55 typedef void *sa_security_t;
56 typedef void *sa_protocol_properties_t;
57 typedef void *sa_resource_t;
58
59 typedef void *sa_handle_t;      /* opaque handle to access core functions */
60
61 /*
62  * defined error values
63  */
64
65 #define SA_OK                   0
66 #define SA_NO_SUCH_PATH         1       /* provided path doesn't exist */
67 #define SA_NO_MEMORY            2       /* no memory for data structures */
68 #define SA_DUPLICATE_NAME       3       /* object name is already in use */
69 #define SA_BAD_PATH             4       /* not a full path */
70 #define SA_NO_SUCH_GROUP        5       /* group is not defined */
71 #define SA_CONFIG_ERR           6       /* system configuration error */
72 #define SA_SYSTEM_ERR           7       /* system error, use errno */
73 #define SA_SYNTAX_ERR           8       /* syntax error on command line */
74 #define SA_NO_PERMISSION        9       /* no permission for operation */
75 #define SA_BUSY                 10      /* resource is busy */
76 #define SA_NO_SUCH_PROP         11      /* property doesn't exist */
77 #define SA_INVALID_NAME         12      /* name of object is invalid */
78 #define SA_INVALID_PROTOCOL     13      /* specified protocol not valid */
79 #define SA_NOT_ALLOWED          14      /* operation not allowed */
80 #define SA_BAD_VALUE            15      /* bad value for property */
81 #define SA_INVALID_SECURITY     16      /* invalid security type */
82 #define SA_NO_SUCH_SECURITY     17      /* security set not found */
83 #define SA_VALUE_CONFLICT       18      /* property value conflict */
84 #define SA_NOT_IMPLEMENTED      19      /* plugin interface not implemented */
85 #define SA_INVALID_PATH         20      /* path is sub-dir of existing share */
86 #define SA_NOT_SUPPORTED        21      /* operation not supported for proto */
87 #define SA_PROP_SHARE_ONLY      22      /* property valid on share only */
88 #define SA_NOT_SHARED           23      /* path is not shared */
89 #define SA_NO_SUCH_RESOURCE     24      /* resource not found */
90 #define SA_RESOURCE_REQUIRED    25      /* resource name is required  */
91 #define SA_MULTIPLE_ERROR       26      /* multiple protocols reported error */
92 #define SA_PATH_IS_SUBDIR       27      /* check_path found path is subdir */
93 #define SA_PATH_IS_PARENTDIR    28      /* check_path found path is parent */
94 #define SA_NO_SECTION           29      /* protocol requires section info */
95 #define SA_NO_SUCH_SECTION      30      /* no section found */
96 #define SA_NO_PROPERTIES        31      /* no properties found */
97 #define SA_PASSWORD_ENC         32      /* passwords must be encrypted */
98
99 /* API Initialization */
100 #define SA_INIT_SHARE_API       0x0001  /* init share specific interface */
101 #define SA_INIT_CONTROL_API     0x0002  /* init control specific interface */
102
103 /* not part of API returns */
104 #define SA_LEGACY_ERR           32      /* share/unshare error return */
105
106 /*
107  * other defined values
108  */
109
110 #define SA_MAX_NAME_LEN         100     /* must fit service instance name */
111 #define SA_MAX_RESOURCE_NAME    255     /* Maximum length of resource name */
112
113 /* Used in calls to sa_add_share() and sa_add_resource() */
114 #define SA_SHARE_TRANSIENT      0       /* shared but not across reboot */
115 #define SA_SHARE_LEGACY         1       /* share is in dfstab only */
116 #define SA_SHARE_PERMANENT      2       /* share goes to repository */
117
118 /* sa_check_path() related */
119 #define SA_CHECK_NORMAL         0       /* only check against active shares */
120 #define SA_CHECK_STRICT         1       /* check against all shares */
121
122 /* RBAC related */
123 #define SA_RBAC_MANAGE  "solaris.smf.manage.shares"
124 #define SA_RBAC_VALUE   "solaris.smf.value.shares"
125
126 /*
127  * Feature set bit definitions
128  */
129
130 #define SA_FEATURE_NONE         0x0000  /* no feature flags set */
131 #define SA_FEATURE_RESOURCE     0x0001  /* resource names are required */
132 #define SA_FEATURE_DFSTAB       0x0002  /* need to manage in dfstab */
133 #define SA_FEATURE_ALLOWSUBDIRS 0x0004  /* allow subdirs to be shared */
134 #define SA_FEATURE_ALLOWPARDIRS 0x0008  /* allow parent dirs to be shared */
135 #define SA_FEATURE_HAS_SECTIONS 0x0010  /* protocol supports sections */
136 #define SA_FEATURE_ADD_PROPERTIES       0x0020  /* can add properties */
137 #define SA_FEATURE_SERVER       0x0040  /* protocol supports server mode */
138
139 /*
140  * legacy files
141  */
142
143 #define SA_LEGACY_DFSTAB        "/etc/dfs/dfstab"
144 #define SA_LEGACY_SHARETAB      "/etc/dfs/sharetab"
145
146 /*
147  * SMF related
148  */
149
150 #define SA_SVC_FMRI_BASE        "svc:/network/shares/group"
151
152 /* initialization */
153 extern sa_handle_t sa_init(int);
154 extern void sa_fini(sa_handle_t);
155 extern int sa_update_config(sa_handle_t);
156 extern char *sa_errorstr(int);
157
158 /* protocol names */
159 extern int sa_get_protocols(char ***);
160 extern int sa_valid_protocol(char *);
161
162 /* group control (create, remove, etc) */
163 extern sa_group_t sa_create_group(sa_handle_t, char *, int *);
164 extern int sa_remove_group(sa_group_t);
165 extern sa_group_t sa_get_group(sa_handle_t, char *);
166 extern sa_group_t sa_get_next_group(sa_group_t);
167 extern char *sa_get_group_attr(sa_group_t, char *);
168 extern int sa_set_group_attr(sa_group_t, char *, char *);
169 extern sa_group_t sa_get_sub_group(sa_group_t);
170 extern int sa_valid_group_name(char *);
171
172 /* share control */
173 extern sa_share_t sa_add_share(sa_group_t, char *, int, int *);
174 extern int sa_check_path(sa_group_t, char *, int);
175 extern int sa_move_share(sa_group_t, sa_share_t);
176 extern int sa_remove_share(sa_share_t);
177 extern sa_share_t sa_get_share(sa_group_t, char *);
178 extern sa_share_t sa_find_share(sa_handle_t, char *);
179 extern sa_share_t sa_get_next_share(sa_share_t);
180 extern char *sa_get_share_attr(sa_share_t, char *);
181 extern char *sa_get_share_description(sa_share_t);
182 extern sa_group_t sa_get_parent_group(sa_share_t);
183 extern int sa_set_share_attr(sa_share_t, char *, char *);
184 extern int sa_set_share_description(sa_share_t, char *);
185 extern int sa_enable_share(sa_group_t, char *);
186 extern int sa_disable_share(sa_share_t, char *);
187 extern int sa_is_share(void *);
188
189 /* resource name related */
190 extern sa_resource_t sa_find_resource(sa_handle_t, char *);
191 extern sa_resource_t sa_get_resource(sa_group_t, char *);
192 extern sa_resource_t sa_get_next_resource(sa_resource_t);
193 extern sa_share_t sa_get_resource_parent(sa_resource_t);
194 extern sa_resource_t sa_get_share_resource(sa_share_t, char *);
195 extern sa_resource_t sa_add_resource(sa_share_t, char *, int, int *);
196 extern int sa_remove_resource(sa_resource_t);
197 extern char *sa_get_resource_attr(sa_resource_t, char *);
198 extern int sa_set_resource_attr(sa_resource_t, char *, char *);
199 extern int sa_set_resource_description(sa_resource_t, char *);
200 extern char *sa_get_resource_description(sa_resource_t);
201 extern int sa_enable_resource(sa_resource_t, char *);
202 extern int sa_disable_resource(sa_resource_t, char *);
203 extern int sa_rename_resource(sa_resource_t, char *);
204 extern void sa_fix_resource_name(char *);
205
206 /* data structure free calls */
207 extern void sa_free_attr_string(char *);
208 extern void sa_free_share_description(char *);
209
210 /* optionset control */
211 extern sa_optionset_t sa_get_optionset(sa_group_t, char *);
212 extern sa_optionset_t sa_get_next_optionset(sa_group_t);
213 extern char *sa_get_optionset_attr(sa_optionset_t, char *);
214 extern void sa_set_optionset_attr(sa_optionset_t, char *, char *);
215 extern sa_optionset_t sa_create_optionset(sa_group_t, char *);
216 extern int sa_destroy_optionset(sa_optionset_t);
217 extern sa_optionset_t sa_get_derived_optionset(void *, char *, int);
218 extern void sa_free_derived_optionset(sa_optionset_t);
219
220 /* property functions */
221 extern sa_property_t sa_get_property(sa_optionset_t, char *);
222 extern sa_property_t sa_get_next_property(sa_group_t);
223 extern char *sa_get_property_attr(sa_property_t, char *);
224 extern sa_property_t sa_create_section(char *, char *);
225 extern void sa_set_section_attr(sa_property_t, char *, char *);
226 extern sa_property_t sa_create_property(char *, char *);
227 extern int sa_add_property(void *, sa_property_t);
228 extern int sa_update_property(sa_property_t, char *);
229 extern int sa_remove_property(sa_property_t);
230 extern int sa_commit_properties(sa_optionset_t, int);
231 extern int sa_valid_property(void *, char *, sa_property_t);
232 extern int sa_is_persistent(void *);
233
234 /* security control */
235 extern sa_security_t sa_get_security(sa_group_t, char *, char *);
236 extern sa_security_t sa_get_next_security(sa_security_t);
237 extern char *sa_get_security_attr(sa_optionset_t, char *);
238 extern sa_security_t sa_create_security(sa_group_t, char *, char *);
239 extern int sa_destroy_security(sa_security_t);
240 extern void sa_set_security_attr(sa_security_t, char *, char *);
241 extern sa_optionset_t sa_get_all_security_types(void *, char *, int);
242 extern sa_security_t sa_get_derived_security(void *, char *, char *, int);
243 extern void sa_free_derived_security(sa_security_t);
244
245 /* protocol specific interfaces */
246 extern int sa_parse_legacy_options(sa_group_t, char *, char *);
247 extern char *sa_proto_legacy_format(char *, sa_group_t, int);
248 extern int sa_is_security(char *, char *);
249 extern sa_protocol_properties_t sa_proto_get_properties(char *);
250 extern uint64_t sa_proto_get_featureset(char *);
251 extern sa_property_t sa_get_protocol_section(sa_protocol_properties_t, char *);
252 extern sa_property_t sa_get_next_protocol_section(sa_property_t, char *);
253 extern sa_property_t sa_get_protocol_property(sa_protocol_properties_t, char *);
254 extern sa_property_t sa_get_next_protocol_property(sa_property_t, char *);
255 extern int sa_set_protocol_property(sa_property_t, char *, char *);
256 extern char *sa_get_protocol_status(char *);
257 extern void sa_format_free(char *);
258 extern sa_protocol_properties_t sa_create_protocol_properties(char *);
259 extern int sa_add_protocol_property(sa_protocol_properties_t, sa_property_t);
260 extern int sa_proto_valid_prop(char *, sa_property_t, sa_optionset_t);
261 extern int sa_proto_valid_space(char *, char *);
262 extern char *sa_proto_space_alias(char *, char *);
263 extern int sa_proto_get_transients(sa_handle_t, char *);
264 extern int sa_proto_notify_resource(sa_resource_t, char *);
265 extern int sa_proto_change_notify(sa_share_t, char *);
266 extern int sa_proto_delete_section(char *, char *);
267
268 /* handle legacy (dfstab/sharetab) files */
269 extern int sa_delete_legacy(sa_share_t, char *);
270 extern int sa_update_legacy(sa_share_t, char *);
271 extern int sa_update_sharetab(sa_share_t, char *);
272 extern int sa_delete_sharetab(sa_handle_t, char *, char *);
273
274 /* ZFS functions */
275 extern int sa_zfs_is_shared(sa_handle_t, char *);
276 extern int sa_group_is_zfs(sa_group_t);
277 extern int sa_path_is_zfs(char *);
278
279 /* SA Handle specific functions */
280 extern sa_handle_t sa_find_group_handle(sa_group_t);
281
282 #ifdef  __cplusplus
283 }
284 #endif
285
286 #endif /* _LIBSHARE_H */
287 #endif /* HAVE_LIBSHARE */