]>
git.proxmox.com Git - mirror_zfs.git/blob - lib/libshare/libshare.c
d6257aa1ef30ffee804f141ea9a4717062e8277a
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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011 Gunnar Beutner
25 * Copyright (c) 2018, 2020 by Delphix. All rights reserved.
35 #include <sys/types.h>
40 #include "libshare_impl.h"
42 #define init_share(zfsname, path, shareopts) \
44 .sa_zfsname = zfsname, \
45 .sa_mountpoint = path, \
46 .sa_shareopts = shareopts, \
49 #define VALIDATE_PROTOCOL(proto, ...) \
50 if ((proto) < 0 || (proto) >= SA_PROTOCOL_COUNT) \
53 const char *const sa_protocol_names
[SA_PROTOCOL_COUNT
] = {
54 [SA_PROTOCOL_NFS
] = "nfs",
55 [SA_PROTOCOL_SMB
] = "smb",
58 static const sa_fstype_t
*fstypes
[SA_PROTOCOL_COUNT
] =
59 {&libshare_nfs_type
, &libshare_smb_type
};
62 sa_enable_share(const char *zfsname
, const char *mountpoint
,
63 const char *shareopts
, enum sa_protocol protocol
)
65 VALIDATE_PROTOCOL(protocol
, SA_INVALID_PROTOCOL
);
67 const struct sa_share_impl args
=
68 init_share(zfsname
, mountpoint
, shareopts
);
69 return (fstypes
[protocol
]->enable_share(&args
));
73 sa_disable_share(const char *mountpoint
, enum sa_protocol protocol
)
75 VALIDATE_PROTOCOL(protocol
, SA_INVALID_PROTOCOL
);
77 const struct sa_share_impl args
= init_share(NULL
, mountpoint
, NULL
);
78 return (fstypes
[protocol
]->disable_share(&args
));
82 sa_is_shared(const char *mountpoint
, enum sa_protocol protocol
)
84 VALIDATE_PROTOCOL(protocol
, B_FALSE
);
86 const struct sa_share_impl args
= init_share(NULL
, mountpoint
, NULL
);
87 return (fstypes
[protocol
]->is_shared(&args
));
91 sa_commit_shares(enum sa_protocol protocol
)
94 VALIDATE_PROTOCOL(protocol
, );
96 fstypes
[protocol
]->commit_shares();
100 sa_validate_shareopts(const char *options
, enum sa_protocol protocol
)
102 VALIDATE_PROTOCOL(protocol
, SA_INVALID_PROTOCOL
);
104 return (fstypes
[protocol
]->validate_shareopts(options
));
110 * convert an error value to an error string
115 static char errstr
[32];
119 return (dgettext(TEXT_DOMAIN
, "ok"));
120 case SA_NO_SUCH_PATH
:
121 return (dgettext(TEXT_DOMAIN
, "path doesn't exist"));
123 return (dgettext(TEXT_DOMAIN
, "no memory"));
124 case SA_DUPLICATE_NAME
:
125 return (dgettext(TEXT_DOMAIN
, "name in use"));
127 return (dgettext(TEXT_DOMAIN
, "bad path"));
128 case SA_NO_SUCH_GROUP
:
129 return (dgettext(TEXT_DOMAIN
, "no such group"));
131 return (dgettext(TEXT_DOMAIN
, "configuration error"));
133 return (dgettext(TEXT_DOMAIN
, "system error"));
135 return (dgettext(TEXT_DOMAIN
, "syntax error"));
136 case SA_NO_PERMISSION
:
137 return (dgettext(TEXT_DOMAIN
, "no permission"));
139 return (dgettext(TEXT_DOMAIN
, "busy"));
140 case SA_NO_SUCH_PROP
:
141 return (dgettext(TEXT_DOMAIN
, "no such property"));
142 case SA_INVALID_NAME
:
143 return (dgettext(TEXT_DOMAIN
, "invalid name"));
144 case SA_INVALID_PROTOCOL
:
145 return (dgettext(TEXT_DOMAIN
, "invalid protocol"));
147 return (dgettext(TEXT_DOMAIN
, "operation not allowed"));
149 return (dgettext(TEXT_DOMAIN
, "bad property value"));
150 case SA_INVALID_SECURITY
:
151 return (dgettext(TEXT_DOMAIN
, "invalid security type"));
152 case SA_NO_SUCH_SECURITY
:
153 return (dgettext(TEXT_DOMAIN
, "security type not found"));
154 case SA_VALUE_CONFLICT
:
155 return (dgettext(TEXT_DOMAIN
, "property value conflict"));
156 case SA_NOT_IMPLEMENTED
:
157 return (dgettext(TEXT_DOMAIN
, "not implemented"));
158 case SA_INVALID_PATH
:
159 return (dgettext(TEXT_DOMAIN
, "invalid path"));
160 case SA_NOT_SUPPORTED
:
161 return (dgettext(TEXT_DOMAIN
, "operation not supported"));
162 case SA_PROP_SHARE_ONLY
:
163 return (dgettext(TEXT_DOMAIN
, "property not valid for group"));
165 return (dgettext(TEXT_DOMAIN
, "not shared"));
166 case SA_NO_SUCH_RESOURCE
:
167 return (dgettext(TEXT_DOMAIN
, "no such resource"));
168 case SA_RESOURCE_REQUIRED
:
169 return (dgettext(TEXT_DOMAIN
, "resource name required"));
170 case SA_MULTIPLE_ERROR
:
171 return (dgettext(TEXT_DOMAIN
,
172 "errors from multiple protocols"));
173 case SA_PATH_IS_SUBDIR
:
174 return (dgettext(TEXT_DOMAIN
, "path is a subpath of share"));
175 case SA_PATH_IS_PARENTDIR
:
176 return (dgettext(TEXT_DOMAIN
, "path is parent of a share"));
178 return (dgettext(TEXT_DOMAIN
, "protocol requires a section"));
179 case SA_NO_PROPERTIES
:
180 return (dgettext(TEXT_DOMAIN
, "properties not found"));
181 case SA_NO_SUCH_SECTION
:
182 return (dgettext(TEXT_DOMAIN
, "section not found"));
183 case SA_PASSWORD_ENC
:
184 return (dgettext(TEXT_DOMAIN
, "passwords must be encrypted"));
185 case SA_SHARE_EXISTS
:
186 return (dgettext(TEXT_DOMAIN
,
187 "path or file is already shared"));
189 (void) snprintf(errstr
, sizeof (errstr
),
190 dgettext(TEXT_DOMAIN
, "unknown %d"), err
);