Path: blob/main/sys/contrib/openzfs/lib/libzfs/libzfs_share.h
178703 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* 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.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122/*23* Copyright 2008 Sun Microsystems, Inc. All rights reserved.24* Use is subject to license terms.25* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.26* Copyright (c) 2011 Gunnar Beutner27* Copyright (c) 2019, 2022 by Delphix. All rights reserved.28*/2930#ifndef _LIBZFS_SHARE_H31#define _LIBZFS_SHARE_H3233#include <sys/types.h>3435/*36* defined error values37*/38#define SA_OK 039#define SA_SYSTEM_ERR 7 /* system error, use errno */40#define SA_SYNTAX_ERR 8 /* syntax error on command line */41#define SA_NO_MEMORY 2 /* no memory for data structures */42#define SA_INVALID_PROTOCOL 13 /* specified protocol not valid */43#define SA_NOT_SUPPORTED 21 /* operation not supported for proto */4445/* The following errors are never returned by libshare */46#define SA_NO_SUCH_PATH 1 /* provided path doesn't exist */47#define SA_DUPLICATE_NAME 3 /* object name is already in use */48#define SA_BAD_PATH 4 /* not a full path */49#define SA_NO_SUCH_GROUP 5 /* group is not defined */50#define SA_CONFIG_ERR 6 /* system configuration error */51#define SA_NO_PERMISSION 9 /* no permission for operation */52#define SA_BUSY 10 /* resource is busy */53#define SA_NO_SUCH_PROP 11 /* property doesn't exist */54#define SA_INVALID_NAME 12 /* name of object is invalid */55#define SA_NOT_ALLOWED 14 /* operation not allowed */56#define SA_BAD_VALUE 15 /* bad value for property */57#define SA_INVALID_SECURITY 16 /* invalid security type */58#define SA_NO_SUCH_SECURITY 17 /* security set not found */59#define SA_VALUE_CONFLICT 18 /* property value conflict */60#define SA_NOT_IMPLEMENTED 19 /* plugin interface not implemented */61#define SA_INVALID_PATH 20 /* path is sub-dir of existing share */62#define SA_PROP_SHARE_ONLY 22 /* property valid on share only */63#define SA_NOT_SHARED 23 /* path is not shared */64#define SA_NO_SUCH_RESOURCE 24 /* resource not found */65#define SA_RESOURCE_REQUIRED 25 /* resource name is required */66#define SA_MULTIPLE_ERROR 26 /* multiple protocols reported error */67#define SA_PATH_IS_SUBDIR 27 /* check_path found path is subdir */68#define SA_PATH_IS_PARENTDIR 28 /* check_path found path is parent */69#define SA_NO_SECTION 29 /* protocol requires section info */70#define SA_NO_SUCH_SECTION 30 /* no section found */71#define SA_NO_PROPERTIES 31 /* no properties found */72#define SA_PASSWORD_ENC 32 /* passwords must be encrypted */73#define SA_SHARE_EXISTS 33 /* path or file is already shared */7475/* initialization */76extern const char *sa_errorstr(int);7778/* lower-case */79extern const char *const sa_protocol_names[SA_PROTOCOL_COUNT];8081/* share control */82extern int sa_enable_share(const char *, const char *, const char *,83enum sa_protocol);84extern int sa_disable_share(const char *, enum sa_protocol);85extern boolean_t sa_is_shared(const char *, enum sa_protocol);86extern void sa_commit_shares(enum sa_protocol);87extern void sa_truncate_shares(enum sa_protocol);8889/* protocol specific interfaces */90extern int sa_validate_shareopts(const char *, enum sa_protocol);919293/* internal definitions */94typedef const struct sa_share_impl {95const char *sa_zfsname;96const char *sa_mountpoint;97const char *sa_shareopts;98} *sa_share_impl_t;99100typedef struct {101int (*const enable_share)(sa_share_impl_t share);102int (*const disable_share)(sa_share_impl_t share);103boolean_t (*const is_shared)(sa_share_impl_t share);104int (*const validate_shareopts)(const char *shareopts);105int (*const commit_shares)(void);106void (*const truncate_shares)(void);107} sa_fstype_t;108109extern const sa_fstype_t libshare_nfs_type, libshare_smb_type;110111/* internal NFS definitions */112#define NFS_FILE_HEADER "# !!! DO NOT EDIT THIS FILE MANUALLY !!!\n\n"113114extern int nfs_escape_mountpoint(const char *mp, char **out,115boolean_t *need_free);116extern boolean_t nfs_is_shared_impl(const char *exports,117sa_share_impl_t impl_share);118extern int nfs_toggle_share(const char *lockfile, const char *exports,119const char *expdir, sa_share_impl_t impl_share,120int(*cbk)(sa_share_impl_t impl_share, FILE *tmpfile));121extern void nfs_reset_shares(const char *lockfile, const char *exports);122123/* internal SMB definitions */124#define SMB_NAME_MAX 255125#define SMB_COMMENT_MAX 255126127#define SMB_SHARE_DIR "/var/lib/samba/usershares"128#define SMB_NET_CMD_PATH "/usr/bin/net"129#define SMB_NET_CMD_ARG_HOST "127.0.0.1"130131typedef struct smb_share_s {132char name[SMB_NAME_MAX]; /* Share name */133char path[PATH_MAX]; /* Share path */134char comment[SMB_COMMENT_MAX]; /* Share's comment */135boolean_t guest_ok; /* 'y' or 'n' */136137struct smb_share_s *next;138} smb_share_t;139140#endif /* _LIBZFS_SHARE_H */141142143