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, 2022 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_truncate_shares(enum sa_protocol protocol
)
103 VALIDATE_PROTOCOL(protocol
, );
105 if (fstypes
[protocol
]->truncate_shares
!= NULL
)
106 fstypes
[protocol
]->truncate_shares();
110 sa_validate_shareopts(const char *options
, enum sa_protocol protocol
)
112 VALIDATE_PROTOCOL(protocol
, SA_INVALID_PROTOCOL
);
114 return (fstypes
[protocol
]->validate_shareopts(options
));
120 * convert an error value to an error string
125 static char errstr
[32];
129 return (dgettext(TEXT_DOMAIN
, "ok"));
130 case SA_NO_SUCH_PATH
:
131 return (dgettext(TEXT_DOMAIN
, "path doesn't exist"));
133 return (dgettext(TEXT_DOMAIN
, "no memory"));
134 case SA_DUPLICATE_NAME
:
135 return (dgettext(TEXT_DOMAIN
, "name in use"));
137 return (dgettext(TEXT_DOMAIN
, "bad path"));
138 case SA_NO_SUCH_GROUP
:
139 return (dgettext(TEXT_DOMAIN
, "no such group"));
141 return (dgettext(TEXT_DOMAIN
, "configuration error"));
143 return (dgettext(TEXT_DOMAIN
, "system error"));
145 return (dgettext(TEXT_DOMAIN
, "syntax error"));
146 case SA_NO_PERMISSION
:
147 return (dgettext(TEXT_DOMAIN
, "no permission"));
149 return (dgettext(TEXT_DOMAIN
, "busy"));
150 case SA_NO_SUCH_PROP
:
151 return (dgettext(TEXT_DOMAIN
, "no such property"));
152 case SA_INVALID_NAME
:
153 return (dgettext(TEXT_DOMAIN
, "invalid name"));
154 case SA_INVALID_PROTOCOL
:
155 return (dgettext(TEXT_DOMAIN
, "invalid protocol"));
157 return (dgettext(TEXT_DOMAIN
, "operation not allowed"));
159 return (dgettext(TEXT_DOMAIN
, "bad property value"));
160 case SA_INVALID_SECURITY
:
161 return (dgettext(TEXT_DOMAIN
, "invalid security type"));
162 case SA_NO_SUCH_SECURITY
:
163 return (dgettext(TEXT_DOMAIN
, "security type not found"));
164 case SA_VALUE_CONFLICT
:
165 return (dgettext(TEXT_DOMAIN
, "property value conflict"));
166 case SA_NOT_IMPLEMENTED
:
167 return (dgettext(TEXT_DOMAIN
, "not implemented"));
168 case SA_INVALID_PATH
:
169 return (dgettext(TEXT_DOMAIN
, "invalid path"));
170 case SA_NOT_SUPPORTED
:
171 return (dgettext(TEXT_DOMAIN
, "operation not supported"));
172 case SA_PROP_SHARE_ONLY
:
173 return (dgettext(TEXT_DOMAIN
, "property not valid for group"));
175 return (dgettext(TEXT_DOMAIN
, "not shared"));
176 case SA_NO_SUCH_RESOURCE
:
177 return (dgettext(TEXT_DOMAIN
, "no such resource"));
178 case SA_RESOURCE_REQUIRED
:
179 return (dgettext(TEXT_DOMAIN
, "resource name required"));
180 case SA_MULTIPLE_ERROR
:
181 return (dgettext(TEXT_DOMAIN
,
182 "errors from multiple protocols"));
183 case SA_PATH_IS_SUBDIR
:
184 return (dgettext(TEXT_DOMAIN
, "path is a subpath of share"));
185 case SA_PATH_IS_PARENTDIR
:
186 return (dgettext(TEXT_DOMAIN
, "path is parent of a share"));
188 return (dgettext(TEXT_DOMAIN
, "protocol requires a section"));
189 case SA_NO_PROPERTIES
:
190 return (dgettext(TEXT_DOMAIN
, "properties not found"));
191 case SA_NO_SUCH_SECTION
:
192 return (dgettext(TEXT_DOMAIN
, "section not found"));
193 case SA_PASSWORD_ENC
:
194 return (dgettext(TEXT_DOMAIN
, "passwords must be encrypted"));
195 case SA_SHARE_EXISTS
:
196 return (dgettext(TEXT_DOMAIN
,
197 "path or file is already shared"));
199 (void) snprintf(errstr
, sizeof (errstr
),
200 dgettext(TEXT_DOMAIN
, "unknown %d"), err
);