xref: /titanic_51/usr/src/lib/smbsrv/libsmbrp/common/smbrp_plugin.c (revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497)
1*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
2*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * CDDL HEADER START
3*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  *
4*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * The contents of this file are subject to the terms of the
5*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Common Development and Distribution License (the "License").
6*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * You may not use this file except in compliance with the License.
7*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  *
8*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * or http://www.opensolaris.org/os/licensing.
10*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * See the License for the specific language governing permissions
11*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * and limitations under the License.
12*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  *
13*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * When distributing Covered Code, include this CDDL HEADER in each
14*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * If applicable, add the following below this CDDL HEADER, with the
16*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * fields enclosed by brackets "[]" replaced with your own identifying
17*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  *
19*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * CDDL HEADER END
20*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
21*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
22*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
23*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Use is subject to license terms.
25*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
26*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
27*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
28*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * SMB plugin for reparse point operations.
29*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * For more details refer to section 5.4 of PSARC/2009/387
30*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
31*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
32*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <stdio.h>
33*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <unistd.h>
34*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <strings.h>
35*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <string.h>
36*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <sys/types.h>
37*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <sys/errno.h>
38*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <syslog.h>
39*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include "rp_plugin.h"
40*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
41*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_dfs.h>
42*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
43*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static char *smb_rpo_service_type(void);
44*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_rpo_supports_svc(const char *);
45*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_rpo_deref(const char *, const char *, char *, size_t *);
46*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_rpo_form(const char *, const char *, char *, size_t *);
47*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
48*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States struct rp_plugin_ops rp_plugin_ops = {
49*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	RP_PLUGIN_V1,
50*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	NULL,			/* rpo_init */
51*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	NULL,			/* rpo_fini */
52*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_rpo_service_type,
53*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_rpo_supports_svc,
54*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_rpo_form,
55*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_rpo_deref
56*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States };
57*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
58*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
59*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Reports supported service type
60*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
61*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static char *
62*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_rpo_service_type(void)
63*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
64*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (DFS_REPARSE_SVCTYPE);
65*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
66*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
67*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
68*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Determines whether this plugin supports the given service type
69*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
70*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t
71*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_rpo_supports_svc(const char *svc_type)
72*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
73*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (svc_type == NULL)
74*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (B_FALSE);
75*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
76*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (strncasecmp(svc_type, DFS_REPARSE_SVCTYPE,
77*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    strlen(DFS_REPARSE_SVCTYPE)) == 0)
78*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (B_TRUE);
79*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
80*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (B_FALSE);
81*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
82*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
83*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
84*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Accepts the service-specific item from the reparse point and returns the
85*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * service-specific data requested.  The caller specifies the size of the
86*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * buffer provided via *bufsz; the routine will fail with EOVERFLOW if
87*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * the results will not fit in the buffer, in which case, *bufsz will
88*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * contain the number of bytes needed to hold the results.
89*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  *
90*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Currently, there is no transformation is needed to data stored in
91*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * a reparse point for DFS, so 'buf' will contain the same data as
92*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * 'svc_data'.
93*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
94*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int
95*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_rpo_deref(const char *svc_type, const char *svc_data, char *buf,
96*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States     size_t *bufsz)
97*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
98*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	int slen;
99*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
100*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((!svc_type) || (!svc_data) || (!buf) || (!bufsz))
101*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (EINVAL);
102*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
103*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (strcasecmp(svc_type, DFS_REPARSE_SVCTYPE) != 0)
104*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (ENOTSUP);
105*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
106*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	slen = strlen(svc_data) + 1;
107*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
108*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (slen > *bufsz) {
109*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		*bufsz = slen;
110*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (EOVERFLOW);
111*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	}
112*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
113*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) strlcpy(buf, svc_data, *bufsz);
114*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
115*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (0);
116*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
117*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
118*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
119*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Returns a string with the appropriate service-specific syntax to create
120*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * a reparse point of the given svc_type, using the string from the
121*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * reparse_add() call as part of the string.
122*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
123*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int
124*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_rpo_form(const char *svc_type, const char *svc_data, char *buf,
125*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States     size_t *bufsz)
126*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
127*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	int slen;
128*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
129*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((!svc_type) || (!svc_data) || (!buf) || (!bufsz))
130*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (EINVAL);
131*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
132*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	slen = strlen(svc_data) + 1;
133*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
134*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if (slen > *bufsz) {
135*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		*bufsz = slen;
136*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (EOVERFLOW);
137*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	}
138*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
139*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) strlcpy(buf, svc_data, *bufsz);
140*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
141*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (0);
142*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
143