Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/openzfs/lib/libzfs/libzfs_share.h
178703 views
1
// SPDX-License-Identifier: CDDL-1.0
2
/*
3
* CDDL HEADER START
4
*
5
* The contents of this file are subject to the terms of the
6
* Common Development and Distribution License (the "License").
7
* You may not use this file except in compliance with the License.
8
*
9
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10
* or https://opensource.org/licenses/CDDL-1.0.
11
* See the License for the specific language governing permissions
12
* and limitations under the License.
13
*
14
* When distributing Covered Code, include this CDDL HEADER in each
15
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16
* If applicable, add the following below this CDDL HEADER, with the
17
* fields enclosed by brackets "[]" replaced with your own identifying
18
* information: Portions Copyright [yyyy] [name of copyright owner]
19
*
20
* CDDL HEADER END
21
*/
22
23
/*
24
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25
* Use is subject to license terms.
26
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
27
* Copyright (c) 2011 Gunnar Beutner
28
* Copyright (c) 2019, 2022 by Delphix. All rights reserved.
29
*/
30
31
#ifndef _LIBZFS_SHARE_H
32
#define _LIBZFS_SHARE_H
33
34
#include <sys/types.h>
35
36
/*
37
* defined error values
38
*/
39
#define SA_OK 0
40
#define SA_SYSTEM_ERR 7 /* system error, use errno */
41
#define SA_SYNTAX_ERR 8 /* syntax error on command line */
42
#define SA_NO_MEMORY 2 /* no memory for data structures */
43
#define SA_INVALID_PROTOCOL 13 /* specified protocol not valid */
44
#define SA_NOT_SUPPORTED 21 /* operation not supported for proto */
45
46
/* The following errors are never returned by libshare */
47
#define SA_NO_SUCH_PATH 1 /* provided path doesn't exist */
48
#define SA_DUPLICATE_NAME 3 /* object name is already in use */
49
#define SA_BAD_PATH 4 /* not a full path */
50
#define SA_NO_SUCH_GROUP 5 /* group is not defined */
51
#define SA_CONFIG_ERR 6 /* system configuration error */
52
#define SA_NO_PERMISSION 9 /* no permission for operation */
53
#define SA_BUSY 10 /* resource is busy */
54
#define SA_NO_SUCH_PROP 11 /* property doesn't exist */
55
#define SA_INVALID_NAME 12 /* name of object is invalid */
56
#define SA_NOT_ALLOWED 14 /* operation not allowed */
57
#define SA_BAD_VALUE 15 /* bad value for property */
58
#define SA_INVALID_SECURITY 16 /* invalid security type */
59
#define SA_NO_SUCH_SECURITY 17 /* security set not found */
60
#define SA_VALUE_CONFLICT 18 /* property value conflict */
61
#define SA_NOT_IMPLEMENTED 19 /* plugin interface not implemented */
62
#define SA_INVALID_PATH 20 /* path is sub-dir of existing share */
63
#define SA_PROP_SHARE_ONLY 22 /* property valid on share only */
64
#define SA_NOT_SHARED 23 /* path is not shared */
65
#define SA_NO_SUCH_RESOURCE 24 /* resource not found */
66
#define SA_RESOURCE_REQUIRED 25 /* resource name is required */
67
#define SA_MULTIPLE_ERROR 26 /* multiple protocols reported error */
68
#define SA_PATH_IS_SUBDIR 27 /* check_path found path is subdir */
69
#define SA_PATH_IS_PARENTDIR 28 /* check_path found path is parent */
70
#define SA_NO_SECTION 29 /* protocol requires section info */
71
#define SA_NO_SUCH_SECTION 30 /* no section found */
72
#define SA_NO_PROPERTIES 31 /* no properties found */
73
#define SA_PASSWORD_ENC 32 /* passwords must be encrypted */
74
#define SA_SHARE_EXISTS 33 /* path or file is already shared */
75
76
/* initialization */
77
extern const char *sa_errorstr(int);
78
79
/* lower-case */
80
extern const char *const sa_protocol_names[SA_PROTOCOL_COUNT];
81
82
/* share control */
83
extern int sa_enable_share(const char *, const char *, const char *,
84
enum sa_protocol);
85
extern int sa_disable_share(const char *, enum sa_protocol);
86
extern boolean_t sa_is_shared(const char *, enum sa_protocol);
87
extern void sa_commit_shares(enum sa_protocol);
88
extern void sa_truncate_shares(enum sa_protocol);
89
90
/* protocol specific interfaces */
91
extern int sa_validate_shareopts(const char *, enum sa_protocol);
92
93
94
/* internal definitions */
95
typedef const struct sa_share_impl {
96
const char *sa_zfsname;
97
const char *sa_mountpoint;
98
const char *sa_shareopts;
99
} *sa_share_impl_t;
100
101
typedef struct {
102
int (*const enable_share)(sa_share_impl_t share);
103
int (*const disable_share)(sa_share_impl_t share);
104
boolean_t (*const is_shared)(sa_share_impl_t share);
105
int (*const validate_shareopts)(const char *shareopts);
106
int (*const commit_shares)(void);
107
void (*const truncate_shares)(void);
108
} sa_fstype_t;
109
110
extern const sa_fstype_t libshare_nfs_type, libshare_smb_type;
111
112
/* internal NFS definitions */
113
#define NFS_FILE_HEADER "# !!! DO NOT EDIT THIS FILE MANUALLY !!!\n\n"
114
115
extern int nfs_escape_mountpoint(const char *mp, char **out,
116
boolean_t *need_free);
117
extern boolean_t nfs_is_shared_impl(const char *exports,
118
sa_share_impl_t impl_share);
119
extern int nfs_toggle_share(const char *lockfile, const char *exports,
120
const char *expdir, sa_share_impl_t impl_share,
121
int(*cbk)(sa_share_impl_t impl_share, FILE *tmpfile));
122
extern void nfs_reset_shares(const char *lockfile, const char *exports);
123
124
/* internal SMB definitions */
125
#define SMB_NAME_MAX 255
126
#define SMB_COMMENT_MAX 255
127
128
#define SMB_SHARE_DIR "/var/lib/samba/usershares"
129
#define SMB_NET_CMD_PATH "/usr/bin/net"
130
#define SMB_NET_CMD_ARG_HOST "127.0.0.1"
131
132
typedef struct smb_share_s {
133
char name[SMB_NAME_MAX]; /* Share name */
134
char path[PATH_MAX]; /* Share path */
135
char comment[SMB_COMMENT_MAX]; /* Share's comment */
136
boolean_t guest_ok; /* 'y' or 'n' */
137
138
struct smb_share_s *next;
139
} smb_share_t;
140
141
#endif /* _LIBZFS_SHARE_H */
142
143