xref: /dflybsd-src/sys/netproto/smb/smb_usr.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  * Copyright (c) 2000-2001 Boris Popov
3*86d7f5d3SJohn Marino  * All rights reserved.
4*86d7f5d3SJohn Marino  *
5*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino  * are met:
8*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
11*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
12*86d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
13*86d7f5d3SJohn Marino  * 3. All advertising materials mentioning features or use of this software
14*86d7f5d3SJohn Marino  *    must display the following acknowledgement:
15*86d7f5d3SJohn Marino  *    This product includes software developed by Boris Popov.
16*86d7f5d3SJohn Marino  * 4. Neither the name of the author nor the names of any co-contributors
17*86d7f5d3SJohn Marino  *    may be used to endorse or promote products derived from this software
18*86d7f5d3SJohn Marino  *    without specific prior written permission.
19*86d7f5d3SJohn Marino  *
20*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21*86d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*86d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*86d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24*86d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*86d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*86d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*86d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*86d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*86d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*86d7f5d3SJohn Marino  * SUCH DAMAGE.
31*86d7f5d3SJohn Marino  *
32*86d7f5d3SJohn Marino  * $FreeBSD: src/sys/netsmb/smb_usr.c,v 1.1.2.1 2001/05/22 08:32:34 bp Exp $
33*86d7f5d3SJohn Marino  * $DragonFly: src/sys/netproto/smb/smb_usr.c,v 1.4 2006/11/26 19:12:25 pavalos Exp $
34*86d7f5d3SJohn Marino  */
35*86d7f5d3SJohn Marino #include <sys/param.h>
36*86d7f5d3SJohn Marino #include <sys/malloc.h>
37*86d7f5d3SJohn Marino #include <sys/kernel.h>
38*86d7f5d3SJohn Marino #include <sys/systm.h>
39*86d7f5d3SJohn Marino #include <sys/conf.h>
40*86d7f5d3SJohn Marino #include <sys/proc.h>
41*86d7f5d3SJohn Marino #include <sys/fcntl.h>
42*86d7f5d3SJohn Marino #include <sys/socket.h>
43*86d7f5d3SJohn Marino #include <sys/socketvar.h>
44*86d7f5d3SJohn Marino #include <sys/sysctl.h>
45*86d7f5d3SJohn Marino 
46*86d7f5d3SJohn Marino #include <sys/iconv.h>
47*86d7f5d3SJohn Marino 
48*86d7f5d3SJohn Marino #include "smb.h"
49*86d7f5d3SJohn Marino #include "smb_conn.h"
50*86d7f5d3SJohn Marino #include "smb_rq.h"
51*86d7f5d3SJohn Marino #include "smb_subr.h"
52*86d7f5d3SJohn Marino #include "smb_dev.h"
53*86d7f5d3SJohn Marino 
54*86d7f5d3SJohn Marino /*
55*86d7f5d3SJohn Marino  * helpers for nsmb device. Can be moved to the smb_dev.c file.
56*86d7f5d3SJohn Marino  */
57*86d7f5d3SJohn Marino static void smb_usr_vcspec_free(struct smb_vcspec *spec);
58*86d7f5d3SJohn Marino 
59*86d7f5d3SJohn Marino static int
smb_usr_vc2spec(struct smbioc_ossn * dp,struct smb_vcspec * spec)60*86d7f5d3SJohn Marino smb_usr_vc2spec(struct smbioc_ossn *dp, struct smb_vcspec *spec)
61*86d7f5d3SJohn Marino {
62*86d7f5d3SJohn Marino 	int flags = 0;
63*86d7f5d3SJohn Marino 
64*86d7f5d3SJohn Marino 	bzero(spec, sizeof(*spec));
65*86d7f5d3SJohn Marino 	if (dp->ioc_user[0] == 0)
66*86d7f5d3SJohn Marino 		return EINVAL;
67*86d7f5d3SJohn Marino 	if (dp->ioc_server == NULL)
68*86d7f5d3SJohn Marino 		return EINVAL;
69*86d7f5d3SJohn Marino 	if (dp->ioc_localcs[0] == 0) {
70*86d7f5d3SJohn Marino 		SMBERROR("no local charset ?\n");
71*86d7f5d3SJohn Marino 		return EINVAL;
72*86d7f5d3SJohn Marino 	}
73*86d7f5d3SJohn Marino 
74*86d7f5d3SJohn Marino 	spec->sap = smb_memdupin(dp->ioc_server, dp->ioc_svlen);
75*86d7f5d3SJohn Marino 	if (spec->sap == NULL)
76*86d7f5d3SJohn Marino 		return ENOMEM;
77*86d7f5d3SJohn Marino 	if (dp->ioc_local) {
78*86d7f5d3SJohn Marino 		spec->lap = smb_memdupin(dp->ioc_local, dp->ioc_lolen);
79*86d7f5d3SJohn Marino 		if (spec->lap == NULL) {
80*86d7f5d3SJohn Marino 			smb_usr_vcspec_free(spec);
81*86d7f5d3SJohn Marino 			return ENOMEM;
82*86d7f5d3SJohn Marino 		}
83*86d7f5d3SJohn Marino 	}
84*86d7f5d3SJohn Marino 	spec->srvname = dp->ioc_srvname;
85*86d7f5d3SJohn Marino 	spec->pass = dp->ioc_password;
86*86d7f5d3SJohn Marino 	spec->domain = dp->ioc_workgroup;
87*86d7f5d3SJohn Marino 	spec->username = dp->ioc_user;
88*86d7f5d3SJohn Marino 	spec->mode = dp->ioc_mode;
89*86d7f5d3SJohn Marino 	spec->rights = dp->ioc_rights;
90*86d7f5d3SJohn Marino 	spec->owner = dp->ioc_owner;
91*86d7f5d3SJohn Marino 	spec->group = dp->ioc_group;
92*86d7f5d3SJohn Marino 	spec->localcs = dp->ioc_localcs;
93*86d7f5d3SJohn Marino 	spec->servercs = dp->ioc_servercs;
94*86d7f5d3SJohn Marino 	if (dp->ioc_opt & SMBVOPT_PRIVATE)
95*86d7f5d3SJohn Marino 		flags |= SMBV_PRIVATE;
96*86d7f5d3SJohn Marino 	if (dp->ioc_opt & SMBVOPT_SINGLESHARE)
97*86d7f5d3SJohn Marino 		flags |= SMBV_PRIVATE | SMBV_SINGLESHARE;
98*86d7f5d3SJohn Marino 	spec->flags = flags;
99*86d7f5d3SJohn Marino 	return 0;
100*86d7f5d3SJohn Marino }
101*86d7f5d3SJohn Marino 
102*86d7f5d3SJohn Marino static void
smb_usr_vcspec_free(struct smb_vcspec * spec)103*86d7f5d3SJohn Marino smb_usr_vcspec_free(struct smb_vcspec *spec)
104*86d7f5d3SJohn Marino {
105*86d7f5d3SJohn Marino 	if (spec->sap)
106*86d7f5d3SJohn Marino 		smb_memfree(spec->sap);
107*86d7f5d3SJohn Marino 	if (spec->lap)
108*86d7f5d3SJohn Marino 		smb_memfree(spec->lap);
109*86d7f5d3SJohn Marino }
110*86d7f5d3SJohn Marino 
111*86d7f5d3SJohn Marino static int
smb_usr_share2spec(struct smbioc_oshare * dp,struct smb_sharespec * spec)112*86d7f5d3SJohn Marino smb_usr_share2spec(struct smbioc_oshare *dp, struct smb_sharespec *spec)
113*86d7f5d3SJohn Marino {
114*86d7f5d3SJohn Marino 	bzero(spec, sizeof(*spec));
115*86d7f5d3SJohn Marino 	spec->mode = dp->ioc_mode;
116*86d7f5d3SJohn Marino 	spec->rights = dp->ioc_rights;
117*86d7f5d3SJohn Marino 	spec->owner = dp->ioc_owner;
118*86d7f5d3SJohn Marino 	spec->group = dp->ioc_group;
119*86d7f5d3SJohn Marino 	spec->name = dp->ioc_share;
120*86d7f5d3SJohn Marino 	spec->stype = dp->ioc_stype;
121*86d7f5d3SJohn Marino 	spec->pass = dp->ioc_password;
122*86d7f5d3SJohn Marino 	return 0;
123*86d7f5d3SJohn Marino }
124*86d7f5d3SJohn Marino 
125*86d7f5d3SJohn Marino int
smb_usr_lookup(struct smbioc_lookup * dp,struct smb_cred * scred,struct smb_vc ** vcpp,struct smb_share ** sspp)126*86d7f5d3SJohn Marino smb_usr_lookup(struct smbioc_lookup *dp, struct smb_cred *scred,
127*86d7f5d3SJohn Marino 	struct smb_vc **vcpp, struct smb_share **sspp)
128*86d7f5d3SJohn Marino {
129*86d7f5d3SJohn Marino 	struct smb_vc *vcp = NULL;
130*86d7f5d3SJohn Marino 	struct smb_vcspec vspec;
131*86d7f5d3SJohn Marino 	struct smb_sharespec sspec, *sspecp = NULL;
132*86d7f5d3SJohn Marino 	int error;
133*86d7f5d3SJohn Marino 
134*86d7f5d3SJohn Marino 	if (dp->ioc_level < SMBL_VC || dp->ioc_level > SMBL_SHARE)
135*86d7f5d3SJohn Marino 		return EINVAL;
136*86d7f5d3SJohn Marino 	error = smb_usr_vc2spec(&dp->ioc_ssn, &vspec);
137*86d7f5d3SJohn Marino 	if (error)
138*86d7f5d3SJohn Marino 		return error;
139*86d7f5d3SJohn Marino 	if (dp->ioc_flags & SMBLK_CREATE)
140*86d7f5d3SJohn Marino 		vspec.flags |= SMBV_CREATE;
141*86d7f5d3SJohn Marino 
142*86d7f5d3SJohn Marino 	if (dp->ioc_level >= SMBL_SHARE) {
143*86d7f5d3SJohn Marino 		error = smb_usr_share2spec(&dp->ioc_sh, &sspec);
144*86d7f5d3SJohn Marino 		if (error)
145*86d7f5d3SJohn Marino 			goto out;
146*86d7f5d3SJohn Marino 		sspecp = &sspec;
147*86d7f5d3SJohn Marino 	}
148*86d7f5d3SJohn Marino 	error = smb_sm_lookup(&vspec, sspecp, scred, &vcp);
149*86d7f5d3SJohn Marino 	if (error == 0) {
150*86d7f5d3SJohn Marino 		*vcpp = vcp;
151*86d7f5d3SJohn Marino 		*sspp = vspec.ssp;
152*86d7f5d3SJohn Marino 	}
153*86d7f5d3SJohn Marino out:
154*86d7f5d3SJohn Marino 	smb_usr_vcspec_free(&vspec);
155*86d7f5d3SJohn Marino 	return error;
156*86d7f5d3SJohn Marino }
157*86d7f5d3SJohn Marino 
158*86d7f5d3SJohn Marino /*
159*86d7f5d3SJohn Marino  * Connect to the resource specified by smbioc_ossn structure.
160*86d7f5d3SJohn Marino  * It may either find an existing connection or try to establish a new one.
161*86d7f5d3SJohn Marino  * If no errors occured smb_vc returned locked and referenced.
162*86d7f5d3SJohn Marino  */
163*86d7f5d3SJohn Marino int
smb_usr_opensession(struct smbioc_ossn * dp,struct smb_cred * scred,struct smb_vc ** vcpp)164*86d7f5d3SJohn Marino smb_usr_opensession(struct smbioc_ossn *dp, struct smb_cred *scred,
165*86d7f5d3SJohn Marino 	struct smb_vc **vcpp)
166*86d7f5d3SJohn Marino {
167*86d7f5d3SJohn Marino 	struct smb_vc *vcp = NULL;
168*86d7f5d3SJohn Marino 	struct smb_vcspec vspec;
169*86d7f5d3SJohn Marino 	int error;
170*86d7f5d3SJohn Marino 
171*86d7f5d3SJohn Marino 	error = smb_usr_vc2spec(dp, &vspec);
172*86d7f5d3SJohn Marino 	if (error)
173*86d7f5d3SJohn Marino 		return error;
174*86d7f5d3SJohn Marino 	if (dp->ioc_opt & SMBVOPT_CREATE)
175*86d7f5d3SJohn Marino 		vspec.flags |= SMBV_CREATE;
176*86d7f5d3SJohn Marino 
177*86d7f5d3SJohn Marino 	error = smb_sm_lookup(&vspec, NULL, scred, &vcp);
178*86d7f5d3SJohn Marino 	smb_usr_vcspec_free(&vspec);
179*86d7f5d3SJohn Marino 	return error;
180*86d7f5d3SJohn Marino }
181*86d7f5d3SJohn Marino 
182*86d7f5d3SJohn Marino int
smb_usr_openshare(struct smb_vc * vcp,struct smbioc_oshare * dp,struct smb_cred * scred,struct smb_share ** sspp)183*86d7f5d3SJohn Marino smb_usr_openshare(struct smb_vc *vcp, struct smbioc_oshare *dp,
184*86d7f5d3SJohn Marino 	struct smb_cred *scred, struct smb_share **sspp)
185*86d7f5d3SJohn Marino {
186*86d7f5d3SJohn Marino 	struct smb_share *ssp;
187*86d7f5d3SJohn Marino 	struct smb_sharespec shspec;
188*86d7f5d3SJohn Marino 	int error;
189*86d7f5d3SJohn Marino 
190*86d7f5d3SJohn Marino 	error = smb_usr_share2spec(dp, &shspec);
191*86d7f5d3SJohn Marino 	if (error)
192*86d7f5d3SJohn Marino 		return error;
193*86d7f5d3SJohn Marino 	error = smb_vc_lookupshare(vcp, &shspec, scred, &ssp);
194*86d7f5d3SJohn Marino 	if (error == 0) {
195*86d7f5d3SJohn Marino 		*sspp = ssp;
196*86d7f5d3SJohn Marino 		return 0;
197*86d7f5d3SJohn Marino 	}
198*86d7f5d3SJohn Marino 	if ((dp->ioc_opt & SMBSOPT_CREATE) == 0)
199*86d7f5d3SJohn Marino 		return error;
200*86d7f5d3SJohn Marino 	error = smb_share_create(vcp, &shspec, scred, &ssp);
201*86d7f5d3SJohn Marino 	if (error)
202*86d7f5d3SJohn Marino 		return error;
203*86d7f5d3SJohn Marino 	error = smb_smb_treeconnect(ssp, scred);
204*86d7f5d3SJohn Marino 	if (error) {
205*86d7f5d3SJohn Marino 		smb_share_put(ssp, scred);
206*86d7f5d3SJohn Marino 	} else
207*86d7f5d3SJohn Marino 		*sspp = ssp;
208*86d7f5d3SJohn Marino 	return error;
209*86d7f5d3SJohn Marino }
210*86d7f5d3SJohn Marino 
211*86d7f5d3SJohn Marino int
smb_usr_simplerequest(struct smb_share * ssp,struct smbioc_rq * dp,struct smb_cred * scred)212*86d7f5d3SJohn Marino smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *dp,
213*86d7f5d3SJohn Marino 	struct smb_cred *scred)
214*86d7f5d3SJohn Marino {
215*86d7f5d3SJohn Marino 	struct smb_rq rq, *rqp = &rq;
216*86d7f5d3SJohn Marino 	struct mbchain *mbp;
217*86d7f5d3SJohn Marino 	struct mdchain *mdp;
218*86d7f5d3SJohn Marino 	u_int8_t wc;
219*86d7f5d3SJohn Marino 	u_int16_t bc;
220*86d7f5d3SJohn Marino 	int error;
221*86d7f5d3SJohn Marino 
222*86d7f5d3SJohn Marino 	switch (dp->ioc_cmd) {
223*86d7f5d3SJohn Marino 	    case SMB_COM_TRANSACTION2:
224*86d7f5d3SJohn Marino 	    case SMB_COM_TRANSACTION2_SECONDARY:
225*86d7f5d3SJohn Marino 	    case SMB_COM_CLOSE_AND_TREE_DISC:
226*86d7f5d3SJohn Marino 	    case SMB_COM_TREE_CONNECT:
227*86d7f5d3SJohn Marino 	    case SMB_COM_TREE_DISCONNECT:
228*86d7f5d3SJohn Marino 	    case SMB_COM_NEGOTIATE:
229*86d7f5d3SJohn Marino 	    case SMB_COM_SESSION_SETUP_ANDX:
230*86d7f5d3SJohn Marino 	    case SMB_COM_LOGOFF_ANDX:
231*86d7f5d3SJohn Marino 	    case SMB_COM_TREE_CONNECT_ANDX:
232*86d7f5d3SJohn Marino 		return EPERM;
233*86d7f5d3SJohn Marino 	}
234*86d7f5d3SJohn Marino 	error = smb_rq_init(rqp, SSTOCP(ssp), dp->ioc_cmd, scred);
235*86d7f5d3SJohn Marino 	if (error)
236*86d7f5d3SJohn Marino 		return error;
237*86d7f5d3SJohn Marino 	mbp = &rqp->sr_rq;
238*86d7f5d3SJohn Marino 	smb_rq_wstart(rqp);
239*86d7f5d3SJohn Marino 	error = mb_put_mem(mbp, dp->ioc_twords, dp->ioc_twc * 2, MB_MUSER);
240*86d7f5d3SJohn Marino 	if (error)
241*86d7f5d3SJohn Marino 		goto bad;
242*86d7f5d3SJohn Marino 	smb_rq_wend(rqp);
243*86d7f5d3SJohn Marino 	smb_rq_bstart(rqp);
244*86d7f5d3SJohn Marino 	error = mb_put_mem(mbp, dp->ioc_tbytes, dp->ioc_tbc, MB_MUSER);
245*86d7f5d3SJohn Marino 	if (error)
246*86d7f5d3SJohn Marino 		goto bad;
247*86d7f5d3SJohn Marino 	smb_rq_bend(rqp);
248*86d7f5d3SJohn Marino 	error = smb_rq_simple(rqp);
249*86d7f5d3SJohn Marino 	if (error)
250*86d7f5d3SJohn Marino 		goto bad;
251*86d7f5d3SJohn Marino 	mdp = &rqp->sr_rp;
252*86d7f5d3SJohn Marino 	md_get_uint8(mdp, &wc);
253*86d7f5d3SJohn Marino 	dp->ioc_rwc = wc;
254*86d7f5d3SJohn Marino 	wc *= 2;
255*86d7f5d3SJohn Marino 	if (wc > dp->ioc_rpbufsz) {
256*86d7f5d3SJohn Marino 		error = EBADRPC;
257*86d7f5d3SJohn Marino 		goto bad;
258*86d7f5d3SJohn Marino 	}
259*86d7f5d3SJohn Marino 	error = md_get_mem(mdp, dp->ioc_rpbuf, wc, MB_MUSER);
260*86d7f5d3SJohn Marino 	if (error)
261*86d7f5d3SJohn Marino 		goto bad;
262*86d7f5d3SJohn Marino 	md_get_uint16le(mdp, &bc);
263*86d7f5d3SJohn Marino 	if ((wc + bc) > dp->ioc_rpbufsz) {
264*86d7f5d3SJohn Marino 		error = EBADRPC;
265*86d7f5d3SJohn Marino 		goto bad;
266*86d7f5d3SJohn Marino 	}
267*86d7f5d3SJohn Marino 	dp->ioc_rbc = bc;
268*86d7f5d3SJohn Marino 	error = md_get_mem(mdp, dp->ioc_rpbuf + wc, bc, MB_MUSER);
269*86d7f5d3SJohn Marino bad:
270*86d7f5d3SJohn Marino 	dp->ioc_errclass = rqp->sr_errclass;
271*86d7f5d3SJohn Marino 	dp->ioc_serror = rqp->sr_serror;
272*86d7f5d3SJohn Marino 	dp->ioc_error = rqp->sr_error;
273*86d7f5d3SJohn Marino 	smb_rq_done(rqp);
274*86d7f5d3SJohn Marino 	return error;
275*86d7f5d3SJohn Marino 
276*86d7f5d3SJohn Marino }
277*86d7f5d3SJohn Marino 
278*86d7f5d3SJohn Marino static int
smb_cpdatain(struct mbchain * mbp,int len,caddr_t data)279*86d7f5d3SJohn Marino smb_cpdatain(struct mbchain *mbp, int len, caddr_t data)
280*86d7f5d3SJohn Marino {
281*86d7f5d3SJohn Marino 	int error;
282*86d7f5d3SJohn Marino 
283*86d7f5d3SJohn Marino 	if (len == 0)
284*86d7f5d3SJohn Marino 		return 0;
285*86d7f5d3SJohn Marino 	error = mb_init(mbp);
286*86d7f5d3SJohn Marino 	if (error)
287*86d7f5d3SJohn Marino 		return error;
288*86d7f5d3SJohn Marino 	return mb_put_mem(mbp, data, len, MB_MUSER);
289*86d7f5d3SJohn Marino }
290*86d7f5d3SJohn Marino 
291*86d7f5d3SJohn Marino int
smb_usr_t2request(struct smb_share * ssp,struct smbioc_t2rq * dp,struct smb_cred * scred)292*86d7f5d3SJohn Marino smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *dp,
293*86d7f5d3SJohn Marino 	struct smb_cred *scred)
294*86d7f5d3SJohn Marino {
295*86d7f5d3SJohn Marino 	struct smb_t2rq t2, *t2p = &t2;
296*86d7f5d3SJohn Marino 	struct mdchain *mdp;
297*86d7f5d3SJohn Marino 	int error, len;
298*86d7f5d3SJohn Marino 
299*86d7f5d3SJohn Marino 	if (dp->ioc_setupcnt > 3)
300*86d7f5d3SJohn Marino 		return EINVAL;
301*86d7f5d3SJohn Marino 	error = smb_t2_init(t2p, SSTOCP(ssp), dp->ioc_setup[0], scred);
302*86d7f5d3SJohn Marino 	if (error)
303*86d7f5d3SJohn Marino 		return error;
304*86d7f5d3SJohn Marino 	len = t2p->t2_setupcount = dp->ioc_setupcnt;
305*86d7f5d3SJohn Marino 	if (len > 1)
306*86d7f5d3SJohn Marino 		t2p->t2_setupdata = dp->ioc_setup;
307*86d7f5d3SJohn Marino 	if (dp->ioc_name) {
308*86d7f5d3SJohn Marino 		t2p->t_name = smb_strdupin(dp->ioc_name, 128);
309*86d7f5d3SJohn Marino 		if (t2p->t_name == NULL) {
310*86d7f5d3SJohn Marino 			error = ENOMEM;
311*86d7f5d3SJohn Marino 			goto bad;
312*86d7f5d3SJohn Marino 		}
313*86d7f5d3SJohn Marino 	}
314*86d7f5d3SJohn Marino 	t2p->t2_maxscount = 0;
315*86d7f5d3SJohn Marino 	t2p->t2_maxpcount = dp->ioc_rparamcnt;
316*86d7f5d3SJohn Marino 	t2p->t2_maxdcount = dp->ioc_rdatacnt;
317*86d7f5d3SJohn Marino 	error = smb_cpdatain(&t2p->t2_tparam, dp->ioc_tparamcnt, dp->ioc_tparam);
318*86d7f5d3SJohn Marino 	if (error)
319*86d7f5d3SJohn Marino 		goto bad;
320*86d7f5d3SJohn Marino 	error = smb_cpdatain(&t2p->t2_tdata, dp->ioc_tdatacnt, dp->ioc_tdata);
321*86d7f5d3SJohn Marino 	if (error)
322*86d7f5d3SJohn Marino 		goto bad;
323*86d7f5d3SJohn Marino 	error = smb_t2_request(t2p);
324*86d7f5d3SJohn Marino 	if (error)
325*86d7f5d3SJohn Marino 		goto bad;
326*86d7f5d3SJohn Marino 	mdp = &t2p->t2_rparam;
327*86d7f5d3SJohn Marino 	if (mdp->md_top) {
328*86d7f5d3SJohn Marino 		len = m_fixhdr(mdp->md_top);
329*86d7f5d3SJohn Marino 		if (len > dp->ioc_rparamcnt) {
330*86d7f5d3SJohn Marino 			error = EMSGSIZE;
331*86d7f5d3SJohn Marino 			goto bad;
332*86d7f5d3SJohn Marino 		}
333*86d7f5d3SJohn Marino 		dp->ioc_rparamcnt = len;
334*86d7f5d3SJohn Marino 		error = md_get_mem(mdp, dp->ioc_rparam, len, MB_MUSER);
335*86d7f5d3SJohn Marino 		if (error)
336*86d7f5d3SJohn Marino 			goto bad;
337*86d7f5d3SJohn Marino 	} else
338*86d7f5d3SJohn Marino 		dp->ioc_rparamcnt = 0;
339*86d7f5d3SJohn Marino 	mdp = &t2p->t2_rdata;
340*86d7f5d3SJohn Marino 	if (mdp->md_top) {
341*86d7f5d3SJohn Marino 		len = m_fixhdr(mdp->md_top);
342*86d7f5d3SJohn Marino 		if (len > dp->ioc_rdatacnt) {
343*86d7f5d3SJohn Marino 			error = EMSGSIZE;
344*86d7f5d3SJohn Marino 			goto bad;
345*86d7f5d3SJohn Marino 		}
346*86d7f5d3SJohn Marino 		dp->ioc_rdatacnt = len;
347*86d7f5d3SJohn Marino 		error = md_get_mem(mdp, dp->ioc_rdata, len, MB_MUSER);
348*86d7f5d3SJohn Marino 	} else
349*86d7f5d3SJohn Marino 		dp->ioc_rdatacnt = 0;
350*86d7f5d3SJohn Marino bad:
351*86d7f5d3SJohn Marino 	if (t2p->t_name)
352*86d7f5d3SJohn Marino 		smb_strfree(t2p->t_name);
353*86d7f5d3SJohn Marino 	smb_t2_done(t2p);
354*86d7f5d3SJohn Marino 	return error;
355*86d7f5d3SJohn Marino }
356