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