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 
42 static sa_fstype_t *smb_fstype;
43 
44 /*
45  * Enables SMB sharing for the specified share.
46  */
47 static int
48 smb_enable_share(sa_share_impl_t impl_share)
49 {
50 	(void) impl_share;
51 	fprintf(stderr, "No SMB support in FreeBSD yet.\n");
52 	return (SA_NOT_SUPPORTED);
53 }
54 /*
55  * Disables SMB sharing for the specified share.
56  */
57 static int
58 smb_disable_share(sa_share_impl_t impl_share)
59 {
60 	(void) impl_share;
61 	fprintf(stderr, "No SMB support in FreeBSD yet.\n");
62 	return (SA_NOT_SUPPORTED);
63 }
64 
65 /*
66  * Checks whether the specified SMB share options are syntactically correct.
67  */
68 static int
69 smb_validate_shareopts(const char *shareopts)
70 {
71 	(void) shareopts;
72 	fprintf(stderr, "No SMB support in FreeBSD yet.\n");
73 	return (SA_NOT_SUPPORTED);
74 }
75 
76 /*
77  * Checks whether a share is currently active.
78  */
79 static boolean_t
80 smb_is_share_active(sa_share_impl_t impl_share)
81 {
82 	(void) impl_share;
83 	return (B_FALSE);
84 }
85 
86 /*
87  * Called to update a share's options. A share's options might be out of
88  * date if the share was loaded from disk and the "sharesmb" dataset
89  * property has changed in the meantime. This function also takes care
90  * of re-enabling the share if necessary.
91  */
92 static int
93 smb_update_shareopts(sa_share_impl_t impl_share, const char *shareopts)
94 {
95 	(void) impl_share, (void) shareopts;
96 	return (SA_OK);
97 }
98 
99 static int
100 smb_update_shares(void)
101 {
102 	/* Not implemented */
103 	return (0);
104 }
105 /*
106  * Clears a share's SMB options. Used by libshare to
107  * clean up shares that are about to be free()'d.
108  */
109 static void
110 smb_clear_shareopts(sa_share_impl_t impl_share)
111 {
112 	FSINFO(impl_share, smb_fstype)->shareopts = NULL;
113 }
114 
115 static const sa_share_ops_t smb_shareops = {
116 	.enable_share = smb_enable_share,
117 	.disable_share = smb_disable_share,
118 	.is_shared = smb_is_share_active,
119 
120 	.validate_shareopts = smb_validate_shareopts,
121 	.update_shareopts = smb_update_shareopts,
122 	.clear_shareopts = smb_clear_shareopts,
123 	.commit_shares = smb_update_shares,
124 };
125 
126 /*
127  * Initializes the SMB functionality of libshare.
128  */
129 void
130 libshare_smb_init(void)
131 {
132 	smb_fstype = register_fstype("smb", &smb_shareops);
133 }
134