xref: /titanic_44/usr/src/lib/smbsrv/libsmbrp/common/smbrp_plugin.c (revision 8928217521dcb14b8099cc9d7f6f2fe2a30f518a)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * SMB plugin for reparse point operations.
29  * For more details refer to section 5.4 of PSARC/2009/387
30  */
31 
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <strings.h>
35 #include <string.h>
36 #include <sys/types.h>
37 #include <sys/errno.h>
38 #include <syslog.h>
39 #include "rp_plugin.h"
40 
41 #include <smbsrv/smb_dfs.h>
42 
43 static char *smb_rpo_service_type(void);
44 static boolean_t smb_rpo_supports_svc(const char *);
45 static int smb_rpo_deref(const char *, const char *, char *, size_t *);
46 static int smb_rpo_form(const char *, const char *, char *, size_t *);
47 
48 struct rp_plugin_ops rp_plugin_ops = {
49 	RP_PLUGIN_V1,
50 	NULL,			/* rpo_init */
51 	NULL,			/* rpo_fini */
52 	smb_rpo_service_type,
53 	smb_rpo_supports_svc,
54 	smb_rpo_form,
55 	smb_rpo_deref
56 };
57 
58 /*
59  * Reports supported service type
60  */
61 static char *
62 smb_rpo_service_type(void)
63 {
64 	return (DFS_REPARSE_SVCTYPE);
65 }
66 
67 /*
68  * Determines whether this plugin supports the given service type
69  */
70 static boolean_t
71 smb_rpo_supports_svc(const char *svc_type)
72 {
73 	if (svc_type == NULL)
74 		return (B_FALSE);
75 
76 	if (strncasecmp(svc_type, DFS_REPARSE_SVCTYPE,
77 	    strlen(DFS_REPARSE_SVCTYPE)) == 0)
78 		return (B_TRUE);
79 
80 	return (B_FALSE);
81 }
82 
83 /*
84  * Accepts the service-specific item from the reparse point and returns the
85  * service-specific data requested.  The caller specifies the size of the
86  * buffer provided via *bufsz; the routine will fail with EOVERFLOW if
87  * the results will not fit in the buffer, in which case, *bufsz will
88  * contain the number of bytes needed to hold the results.
89  *
90  * Currently, there is no transformation is needed to data stored in
91  * a reparse point for DFS, so 'buf' will contain the same data as
92  * 'svc_data'.
93  */
94 static int
95 smb_rpo_deref(const char *svc_type, const char *svc_data, char *buf,
96     size_t *bufsz)
97 {
98 	int slen;
99 
100 	if ((!svc_type) || (!svc_data) || (!buf) || (!bufsz))
101 		return (EINVAL);
102 
103 	if (strcasecmp(svc_type, DFS_REPARSE_SVCTYPE) != 0)
104 		return (ENOTSUP);
105 
106 	slen = strlen(svc_data) + 1;
107 
108 	if (slen > *bufsz) {
109 		*bufsz = slen;
110 		return (EOVERFLOW);
111 	}
112 
113 	(void) strlcpy(buf, svc_data, *bufsz);
114 
115 	return (0);
116 }
117 
118 /*
119  * Returns a string with the appropriate service-specific syntax to create
120  * a reparse point of the given svc_type, using the string from the
121  * reparse_add() call as part of the string.
122  */
123 static int
124 smb_rpo_form(const char *svc_type, const char *svc_data, char *buf,
125     size_t *bufsz)
126 {
127 	int slen;
128 
129 	if ((!svc_type) || (!svc_data) || (!buf) || (!bufsz))
130 		return (EINVAL);
131 
132 	slen = strlen(svc_data) + 1;
133 
134 	if (slen > *bufsz) {
135 		*bufsz = slen;
136 		return (EOVERFLOW);
137 	}
138 
139 	(void) strlcpy(buf, svc_data, *bufsz);
140 
141 	return (0);
142 }
143