1/*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2020 by Delphix. All rights reserved.
24 */
25
26#include <time.h>
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30#include <strings.h>
31#include <fcntl.h>
32#include <sys/wait.h>
33#include <unistd.h>
34#include <dirent.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <libzfs.h>
38#include <libshare.h>
39#include "libshare_impl.h"
40#include "smb.h"
41
42static sa_fstype_t *smb_fstype;
43
44/*
45 * Enables SMB sharing for the specified share.
46 */
47static int
48smb_enable_share(sa_share_impl_t impl_share)
49{
50	fprintf(stderr, "No SMB support in FreeBSD yet.\n");
51	return (SA_NOT_SUPPORTED);
52}
53/*
54 * Disables SMB sharing for the specified share.
55 */
56static int
57smb_disable_share(sa_share_impl_t impl_share)
58{
59	fprintf(stderr, "No SMB support in FreeBSD yet.\n");
60	return (SA_NOT_SUPPORTED);
61}
62
63/*
64 * Checks whether the specified SMB share options are syntactically correct.
65 */
66static int
67smb_validate_shareopts(const char *shareopts)
68{
69	fprintf(stderr, "No SMB support in FreeBSD yet.\n");
70	return (SA_NOT_SUPPORTED);
71}
72
73/*
74 * Checks whether a share is currently active.
75 */
76static boolean_t
77smb_is_share_active(sa_share_impl_t impl_share)
78{
79	return (B_FALSE);
80}
81
82/*
83 * Called to update a share's options. A share's options might be out of
84 * date if the share was loaded from disk and the "sharesmb" dataset
85 * property has changed in the meantime. This function also takes care
86 * of re-enabling the share if necessary.
87 */
88static int
89smb_update_shareopts(sa_share_impl_t impl_share, const char *shareopts)
90{
91	return (SA_OK);
92}
93
94static int
95smb_update_shares(void)
96{
97	/* Not implemented */
98	return (0);
99}
100/*
101 * Clears a share's SMB options. Used by libshare to
102 * clean up shares that are about to be free()'d.
103 */
104static void
105smb_clear_shareopts(sa_share_impl_t impl_share)
106{
107	FSINFO(impl_share, smb_fstype)->shareopts = NULL;
108}
109
110static const sa_share_ops_t smb_shareops = {
111	.enable_share = smb_enable_share,
112	.disable_share = smb_disable_share,
113	.is_shared = smb_is_share_active,
114
115	.validate_shareopts = smb_validate_shareopts,
116	.update_shareopts = smb_update_shareopts,
117	.clear_shareopts = smb_clear_shareopts,
118	.commit_shares = smb_update_shares,
119};
120
121/*
122 * Initializes the SMB functionality of libshare.
123 */
124void
125libshare_smb_init(void)
126{
127	smb_fstype = register_fstype("smb", &smb_shareops);
128}
129