2011-07-02 19:34:05 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* Copyright (c) 2011 Gunnar Beutner
|
2020-07-13 16:19:18 +00:00
|
|
|
* Copyright (c) 2018, 2020 by Delphix. All rights reserved.
|
2011-07-02 19:34:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2022-02-28 13:50:28 +00:00
|
|
|
#include <stddef.h>
|
2022-01-22 00:56:46 +00:00
|
|
|
#include <string.h>
|
2011-07-02 19:34:05 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <libintl.h>
|
2020-07-13 16:19:18 +00:00
|
|
|
#include <sys/file.h>
|
2011-07-02 19:34:05 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libzfs.h>
|
|
|
|
#include <libshare.h>
|
|
|
|
#include "libshare_impl.h"
|
|
|
|
|
2022-02-28 13:50:28 +00:00
|
|
|
#define init_share(zfsname, path, shareopts) \
|
|
|
|
{ \
|
|
|
|
.sa_zfsname = zfsname, \
|
|
|
|
.sa_mountpoint = path, \
|
|
|
|
.sa_shareopts = shareopts, \
|
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2022-02-28 14:46:25 +00:00
|
|
|
#define VALIDATE_PROTOCOL(proto, ...) \
|
|
|
|
if ((proto) < 0 || (proto) >= SA_PROTOCOL_COUNT) \
|
|
|
|
return __VA_ARGS__
|
|
|
|
|
|
|
|
const char *const sa_protocol_names[SA_PROTOCOL_COUNT] = {
|
|
|
|
[SA_PROTOCOL_NFS] = "nfs",
|
|
|
|
[SA_PROTOCOL_SMB] = "smb",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const sa_fstype_t *fstypes[SA_PROTOCOL_COUNT] =
|
|
|
|
{&libshare_nfs_type, &libshare_smb_type};
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
int
|
|
|
|
sa_enable_share(const char *zfsname, const char *mountpoint,
|
2022-02-28 14:46:25 +00:00
|
|
|
const char *shareopts, enum sa_protocol protocol)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2022-02-28 14:46:25 +00:00
|
|
|
VALIDATE_PROTOCOL(protocol, SA_INVALID_PROTOCOL);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2022-02-28 13:50:28 +00:00
|
|
|
const struct sa_share_impl args =
|
|
|
|
init_share(zfsname, mountpoint, shareopts);
|
2022-02-28 14:46:25 +00:00
|
|
|
return (fstypes[protocol]->enable_share(&args));
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-02-28 14:46:25 +00:00
|
|
|
sa_disable_share(const char *mountpoint, enum sa_protocol protocol)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2022-02-28 14:46:25 +00:00
|
|
|
VALIDATE_PROTOCOL(protocol, SA_INVALID_PROTOCOL);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2022-02-28 13:50:28 +00:00
|
|
|
const struct sa_share_impl args = init_share(NULL, mountpoint, NULL);
|
2022-02-28 14:46:25 +00:00
|
|
|
return (fstypes[protocol]->disable_share(&args));
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
boolean_t
|
2022-02-28 14:46:25 +00:00
|
|
|
sa_is_shared(const char *mountpoint, enum sa_protocol protocol)
|
2011-07-02 19:34:05 +00:00
|
|
|
{
|
2022-02-28 14:46:25 +00:00
|
|
|
VALIDATE_PROTOCOL(protocol, B_FALSE);
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2022-02-28 13:50:28 +00:00
|
|
|
const struct sa_share_impl args = init_share(NULL, mountpoint, NULL);
|
2022-02-28 14:46:25 +00:00
|
|
|
return (fstypes[protocol]->is_shared(&args));
|
2020-07-13 16:19:18 +00:00
|
|
|
}
|
2011-07-02 19:34:05 +00:00
|
|
|
|
2020-07-13 16:19:18 +00:00
|
|
|
void
|
2022-02-28 14:46:25 +00:00
|
|
|
sa_commit_shares(enum sa_protocol protocol)
|
|
|
|
{
|
|
|
|
/* CSTYLED */
|
|
|
|
VALIDATE_PROTOCOL(protocol, );
|
|
|
|
|
|
|
|
fstypes[protocol]->commit_shares();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sa_validate_shareopts(const char *options, enum sa_protocol protocol)
|
2020-07-13 16:19:18 +00:00
|
|
|
{
|
2022-02-28 14:46:25 +00:00
|
|
|
VALIDATE_PROTOCOL(protocol, SA_INVALID_PROTOCOL);
|
2022-02-28 13:50:28 +00:00
|
|
|
|
2022-02-28 14:46:25 +00:00
|
|
|
return (fstypes[protocol]->validate_shareopts(options));
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sa_errorstr(err)
|
|
|
|
*
|
|
|
|
* convert an error value to an error string
|
|
|
|
*/
|
2022-02-28 12:37:06 +00:00
|
|
|
const char *
|
2011-07-02 19:34:05 +00:00
|
|
|
sa_errorstr(int err)
|
|
|
|
{
|
|
|
|
static char errstr[32];
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case SA_OK:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "ok"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SUCH_PATH:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "path doesn't exist"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_MEMORY:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "no memory"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_DUPLICATE_NAME:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "name in use"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_BAD_PATH:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "bad path"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SUCH_GROUP:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "no such group"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_CONFIG_ERR:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "configuration error"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_SYSTEM_ERR:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "system error"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_SYNTAX_ERR:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "syntax error"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_PERMISSION:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "no permission"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_BUSY:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "busy"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SUCH_PROP:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "no such property"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_INVALID_NAME:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "invalid name"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_INVALID_PROTOCOL:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "invalid protocol"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NOT_ALLOWED:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "operation not allowed"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_BAD_VALUE:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "bad property value"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_INVALID_SECURITY:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "invalid security type"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SUCH_SECURITY:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "security type not found"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_VALUE_CONFLICT:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "property value conflict"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NOT_IMPLEMENTED:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "not implemented"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_INVALID_PATH:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "invalid path"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NOT_SUPPORTED:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "operation not supported"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_PROP_SHARE_ONLY:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "property not valid for group"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NOT_SHARED:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "not shared"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SUCH_RESOURCE:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "no such resource"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_RESOURCE_REQUIRED:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "resource name required"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_MULTIPLE_ERROR:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN,
|
|
|
|
"errors from multiple protocols"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_PATH_IS_SUBDIR:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "path is a subpath of share"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_PATH_IS_PARENTDIR:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "path is parent of a share"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SECTION:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "protocol requires a section"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_PROPERTIES:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "properties not found"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_NO_SUCH_SECTION:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "section not found"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_PASSWORD_ENC:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN, "passwords must be encrypted"));
|
2011-07-02 19:34:05 +00:00
|
|
|
case SA_SHARE_EXISTS:
|
2022-02-28 13:50:28 +00:00
|
|
|
return (dgettext(TEXT_DOMAIN,
|
|
|
|
"path or file is already shared"));
|
2011-07-02 19:34:05 +00:00
|
|
|
default:
|
|
|
|
(void) snprintf(errstr, sizeof (errstr),
|
|
|
|
dgettext(TEXT_DOMAIN, "unknown %d"), err);
|
2022-02-28 13:50:28 +00:00
|
|
|
return (errstr);
|
2011-07-02 19:34:05 +00:00
|
|
|
}
|
|
|
|
}
|