xref: /dflybsd-src/sys/netproto/smb/smb_usr.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*
286d7f5d3SJohn Marino  * Copyright (c) 2000-2001 Boris Popov
386d7f5d3SJohn Marino  * All rights reserved.
486d7f5d3SJohn Marino  *
586d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino  * are met:
886d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1086d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1186d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1286d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1386d7f5d3SJohn Marino  * 3. All advertising materials mentioning features or use of this software
1486d7f5d3SJohn Marino  *    must display the following acknowledgement:
1586d7f5d3SJohn Marino  *    This product includes software developed by Boris Popov.
1686d7f5d3SJohn Marino  * 4. Neither the name of the author nor the names of any co-contributors
1786d7f5d3SJohn Marino  *    may be used to endorse or promote products derived from this software
1886d7f5d3SJohn Marino  *    without specific prior written permission.
1986d7f5d3SJohn Marino  *
2086d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2186d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2286d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2386d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2486d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2586d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2686d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2786d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2886d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2986d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3086d7f5d3SJohn Marino  * SUCH DAMAGE.
3186d7f5d3SJohn Marino  *
3286d7f5d3SJohn Marino  * $FreeBSD: src/sys/netsmb/smb_usr.c,v 1.1.2.1 2001/05/22 08:32:34 bp Exp $
3386d7f5d3SJohn Marino  * $DragonFly: src/sys/netproto/smb/smb_usr.c,v 1.4 2006/11/26 19:12:25 pavalos Exp $
3486d7f5d3SJohn Marino  */
3586d7f5d3SJohn Marino #include <sys/param.h>
3686d7f5d3SJohn Marino #include <sys/malloc.h>
3786d7f5d3SJohn Marino #include <sys/kernel.h>
3886d7f5d3SJohn Marino #include <sys/systm.h>
3986d7f5d3SJohn Marino #include <sys/conf.h>
4086d7f5d3SJohn Marino #include <sys/proc.h>
4186d7f5d3SJohn Marino #include <sys/fcntl.h>
4286d7f5d3SJohn Marino #include <sys/socket.h>
4386d7f5d3SJohn Marino #include <sys/socketvar.h>
4486d7f5d3SJohn Marino #include <sys/sysctl.h>
4586d7f5d3SJohn Marino 
4686d7f5d3SJohn Marino #include <sys/iconv.h>
4786d7f5d3SJohn Marino 
4886d7f5d3SJohn Marino #include "smb.h"
4986d7f5d3SJohn Marino #include "smb_conn.h"
5086d7f5d3SJohn Marino #include "smb_rq.h"
5186d7f5d3SJohn Marino #include "smb_subr.h"
5286d7f5d3SJohn Marino #include "smb_dev.h"
5386d7f5d3SJohn Marino 
5486d7f5d3SJohn Marino /*
5586d7f5d3SJohn Marino  * helpers for nsmb device. Can be moved to the smb_dev.c file.
5686d7f5d3SJohn Marino  */
5786d7f5d3SJohn Marino static void smb_usr_vcspec_free(struct smb_vcspec *spec);
5886d7f5d3SJohn Marino 
5986d7f5d3SJohn Marino static int
smb_usr_vc2spec(struct smbioc_ossn * dp,struct smb_vcspec * spec)6086d7f5d3SJohn Marino smb_usr_vc2spec(struct smbioc_ossn *dp, struct smb_vcspec *spec)
6186d7f5d3SJohn Marino {
6286d7f5d3SJohn Marino 	int flags = 0;
6386d7f5d3SJohn Marino 
6486d7f5d3SJohn Marino 	bzero(spec, sizeof(*spec));
6586d7f5d3SJohn Marino 	if (dp->ioc_user[0] == 0)
6686d7f5d3SJohn Marino 		return EINVAL;
6786d7f5d3SJohn Marino 	if (dp->ioc_server == NULL)
6886d7f5d3SJohn Marino 		return EINVAL;
6986d7f5d3SJohn Marino 	if (dp->ioc_localcs[0] == 0) {
7086d7f5d3SJohn Marino 		SMBERROR("no local charset ?\n");
7186d7f5d3SJohn Marino 		return EINVAL;
7286d7f5d3SJohn Marino 	}
7386d7f5d3SJohn Marino 
7486d7f5d3SJohn Marino 	spec->sap = smb_memdupin(dp->ioc_server, dp->ioc_svlen);
7586d7f5d3SJohn Marino 	if (spec->sap == NULL)
7686d7f5d3SJohn Marino 		return ENOMEM;
7786d7f5d3SJohn Marino 	if (dp->ioc_local) {
7886d7f5d3SJohn Marino 		spec->lap = smb_memdupin(dp->ioc_local, dp->ioc_lolen);
7986d7f5d3SJohn Marino 		if (spec->lap == NULL) {
8086d7f5d3SJohn Marino 			smb_usr_vcspec_free(spec);
8186d7f5d3SJohn Marino 			return ENOMEM;
8286d7f5d3SJohn Marino 		}
8386d7f5d3SJohn Marino 	}
8486d7f5d3SJohn Marino 	spec->srvname = dp->ioc_srvname;
8586d7f5d3SJohn Marino 	spec->pass = dp->ioc_password;
8686d7f5d3SJohn Marino 	spec->domain = dp->ioc_workgroup;
8786d7f5d3SJohn Marino 	spec->username = dp->ioc_user;
8886d7f5d3SJohn Marino 	spec->mode = dp->ioc_mode;
8986d7f5d3SJohn Marino 	spec->rights = dp->ioc_rights;
9086d7f5d3SJohn Marino 	spec->owner = dp->ioc_owner;
9186d7f5d3SJohn Marino 	spec->group = dp->ioc_group;
9286d7f5d3SJohn Marino 	spec->localcs = dp->ioc_localcs;
9386d7f5d3SJohn Marino 	spec->servercs = dp->ioc_servercs;
9486d7f5d3SJohn Marino 	if (dp->ioc_opt & SMBVOPT_PRIVATE)
9586d7f5d3SJohn Marino 		flags |= SMBV_PRIVATE;
9686d7f5d3SJohn Marino 	if (dp->ioc_opt & SMBVOPT_SINGLESHARE)
9786d7f5d3SJohn Marino 		flags |= SMBV_PRIVATE | SMBV_SINGLESHARE;
9886d7f5d3SJohn Marino 	spec->flags = flags;
9986d7f5d3SJohn Marino 	return 0;
10086d7f5d3SJohn Marino }
10186d7f5d3SJohn Marino 
10286d7f5d3SJohn Marino static void
smb_usr_vcspec_free(struct smb_vcspec * spec)10386d7f5d3SJohn Marino smb_usr_vcspec_free(struct smb_vcspec *spec)
10486d7f5d3SJohn Marino {
10586d7f5d3SJohn Marino 	if (spec->sap)
10686d7f5d3SJohn Marino 		smb_memfree(spec->sap);
10786d7f5d3SJohn Marino 	if (spec->lap)
10886d7f5d3SJohn Marino 		smb_memfree(spec->lap);
10986d7f5d3SJohn Marino }
11086d7f5d3SJohn Marino 
11186d7f5d3SJohn Marino static int
smb_usr_share2spec(struct smbioc_oshare * dp,struct smb_sharespec * spec)11286d7f5d3SJohn Marino smb_usr_share2spec(struct smbioc_oshare *dp, struct smb_sharespec *spec)
11386d7f5d3SJohn Marino {
11486d7f5d3SJohn Marino 	bzero(spec, sizeof(*spec));
11586d7f5d3SJohn Marino 	spec->mode = dp->ioc_mode;
11686d7f5d3SJohn Marino 	spec->rights = dp->ioc_rights;
11786d7f5d3SJohn Marino 	spec->owner = dp->ioc_owner;
11886d7f5d3SJohn Marino 	spec->group = dp->ioc_group;
11986d7f5d3SJohn Marino 	spec->name = dp->ioc_share;
12086d7f5d3SJohn Marino 	spec->stype = dp->ioc_stype;
12186d7f5d3SJohn Marino 	spec->pass = dp->ioc_password;
12286d7f5d3SJohn Marino 	return 0;
12386d7f5d3SJohn Marino }
12486d7f5d3SJohn Marino 
12586d7f5d3SJohn Marino int
smb_usr_lookup(struct smbioc_lookup * dp,struct smb_cred * scred,struct smb_vc ** vcpp,struct smb_share ** sspp)12686d7f5d3SJohn Marino smb_usr_lookup(struct smbioc_lookup *dp, struct smb_cred *scred,
12786d7f5d3SJohn Marino 	struct smb_vc **vcpp, struct smb_share **sspp)
12886d7f5d3SJohn Marino {
12986d7f5d3SJohn Marino 	struct smb_vc *vcp = NULL;
13086d7f5d3SJohn Marino 	struct smb_vcspec vspec;
13186d7f5d3SJohn Marino 	struct smb_sharespec sspec, *sspecp = NULL;
13286d7f5d3SJohn Marino 	int error;
13386d7f5d3SJohn Marino 
13486d7f5d3SJohn Marino 	if (dp->ioc_level < SMBL_VC || dp->ioc_level > SMBL_SHARE)
13586d7f5d3SJohn Marino 		return EINVAL;
13686d7f5d3SJohn Marino 	error = smb_usr_vc2spec(&dp->ioc_ssn, &vspec);
13786d7f5d3SJohn Marino 	if (error)
13886d7f5d3SJohn Marino 		return error;
13986d7f5d3SJohn Marino 	if (dp->ioc_flags & SMBLK_CREATE)
14086d7f5d3SJohn Marino 		vspec.flags |= SMBV_CREATE;
14186d7f5d3SJohn Marino 
14286d7f5d3SJohn Marino 	if (dp->ioc_level >= SMBL_SHARE) {
14386d7f5d3SJohn Marino 		error = smb_usr_share2spec(&dp->ioc_sh, &sspec);
14486d7f5d3SJohn Marino 		if (error)
14586d7f5d3SJohn Marino 			goto out;
14686d7f5d3SJohn Marino 		sspecp = &sspec;
14786d7f5d3SJohn Marino 	}
14886d7f5d3SJohn Marino 	error = smb_sm_lookup(&vspec, sspecp, scred, &vcp);
14986d7f5d3SJohn Marino 	if (error == 0) {
15086d7f5d3SJohn Marino 		*vcpp = vcp;
15186d7f5d3SJohn Marino 		*sspp = vspec.ssp;
15286d7f5d3SJohn Marino 	}
15386d7f5d3SJohn Marino out:
15486d7f5d3SJohn Marino 	smb_usr_vcspec_free(&vspec);
15586d7f5d3SJohn Marino 	return error;
15686d7f5d3SJohn Marino }
15786d7f5d3SJohn Marino 
15886d7f5d3SJohn Marino /*
15986d7f5d3SJohn Marino  * Connect to the resource specified by smbioc_ossn structure.
16086d7f5d3SJohn Marino  * It may either find an existing connection or try to establish a new one.
16186d7f5d3SJohn Marino  * If no errors occured smb_vc returned locked and referenced.
16286d7f5d3SJohn Marino  */
16386d7f5d3SJohn Marino int
smb_usr_opensession(struct smbioc_ossn * dp,struct smb_cred * scred,struct smb_vc ** vcpp)16486d7f5d3SJohn Marino smb_usr_opensession(struct smbioc_ossn *dp, struct smb_cred *scred,
16586d7f5d3SJohn Marino 	struct smb_vc **vcpp)
16686d7f5d3SJohn Marino {
16786d7f5d3SJohn Marino 	struct smb_vc *vcp = NULL;
16886d7f5d3SJohn Marino 	struct smb_vcspec vspec;
16986d7f5d3SJohn Marino 	int error;
17086d7f5d3SJohn Marino 
17186d7f5d3SJohn Marino 	error = smb_usr_vc2spec(dp, &vspec);
17286d7f5d3SJohn Marino 	if (error)
17386d7f5d3SJohn Marino 		return error;
17486d7f5d3SJohn Marino 	if (dp->ioc_opt & SMBVOPT_CREATE)
17586d7f5d3SJohn Marino 		vspec.flags |= SMBV_CREATE;
17686d7f5d3SJohn Marino 
17786d7f5d3SJohn Marino 	error = smb_sm_lookup(&vspec, NULL, scred, &vcp);
17886d7f5d3SJohn Marino 	smb_usr_vcspec_free(&vspec);
17986d7f5d3SJohn Marino 	return error;
18086d7f5d3SJohn Marino }
18186d7f5d3SJohn Marino 
18286d7f5d3SJohn Marino int
smb_usr_openshare(struct smb_vc * vcp,struct smbioc_oshare * dp,struct smb_cred * scred,struct smb_share ** sspp)18386d7f5d3SJohn Marino smb_usr_openshare(struct smb_vc *vcp, struct smbioc_oshare *dp,
18486d7f5d3SJohn Marino 	struct smb_cred *scred, struct smb_share **sspp)
18586d7f5d3SJohn Marino {
18686d7f5d3SJohn Marino 	struct smb_share *ssp;
18786d7f5d3SJohn Marino 	struct smb_sharespec shspec;
18886d7f5d3SJohn Marino 	int error;
18986d7f5d3SJohn Marino 
19086d7f5d3SJohn Marino 	error = smb_usr_share2spec(dp, &shspec);
19186d7f5d3SJohn Marino 	if (error)
19286d7f5d3SJohn Marino 		return error;
19386d7f5d3SJohn Marino 	error = smb_vc_lookupshare(vcp, &shspec, scred, &ssp);
19486d7f5d3SJohn Marino 	if (error == 0) {
19586d7f5d3SJohn Marino 		*sspp = ssp;
19686d7f5d3SJohn Marino 		return 0;
19786d7f5d3SJohn Marino 	}
19886d7f5d3SJohn Marino 	if ((dp->ioc_opt & SMBSOPT_CREATE) == 0)
19986d7f5d3SJohn Marino 		return error;
20086d7f5d3SJohn Marino 	error = smb_share_create(vcp, &shspec, scred, &ssp);
20186d7f5d3SJohn Marino 	if (error)
20286d7f5d3SJohn Marino 		return error;
20386d7f5d3SJohn Marino 	error = smb_smb_treeconnect(ssp, scred);
20486d7f5d3SJohn Marino 	if (error) {
20586d7f5d3SJohn Marino 		smb_share_put(ssp, scred);
20686d7f5d3SJohn Marino 	} else
20786d7f5d3SJohn Marino 		*sspp = ssp;
20886d7f5d3SJohn Marino 	return error;
20986d7f5d3SJohn Marino }
21086d7f5d3SJohn Marino 
21186d7f5d3SJohn Marino int
smb_usr_simplerequest(struct smb_share * ssp,struct smbioc_rq * dp,struct smb_cred * scred)21286d7f5d3SJohn Marino smb_usr_simplerequest(struct smb_share *ssp, struct smbioc_rq *dp,
21386d7f5d3SJohn Marino 	struct smb_cred *scred)
21486d7f5d3SJohn Marino {
21586d7f5d3SJohn Marino 	struct smb_rq rq, *rqp = &rq;
21686d7f5d3SJohn Marino 	struct mbchain *mbp;
21786d7f5d3SJohn Marino 	struct mdchain *mdp;
21886d7f5d3SJohn Marino 	u_int8_t wc;
21986d7f5d3SJohn Marino 	u_int16_t bc;
22086d7f5d3SJohn Marino 	int error;
22186d7f5d3SJohn Marino 
22286d7f5d3SJohn Marino 	switch (dp->ioc_cmd) {
22386d7f5d3SJohn Marino 	    case SMB_COM_TRANSACTION2:
22486d7f5d3SJohn Marino 	    case SMB_COM_TRANSACTION2_SECONDARY:
22586d7f5d3SJohn Marino 	    case SMB_COM_CLOSE_AND_TREE_DISC:
22686d7f5d3SJohn Marino 	    case SMB_COM_TREE_CONNECT:
22786d7f5d3SJohn Marino 	    case SMB_COM_TREE_DISCONNECT:
22886d7f5d3SJohn Marino 	    case SMB_COM_NEGOTIATE:
22986d7f5d3SJohn Marino 	    case SMB_COM_SESSION_SETUP_ANDX:
23086d7f5d3SJohn Marino 	    case SMB_COM_LOGOFF_ANDX:
23186d7f5d3SJohn Marino 	    case SMB_COM_TREE_CONNECT_ANDX:
23286d7f5d3SJohn Marino 		return EPERM;
23386d7f5d3SJohn Marino 	}
23486d7f5d3SJohn Marino 	error = smb_rq_init(rqp, SSTOCP(ssp), dp->ioc_cmd, scred);
23586d7f5d3SJohn Marino 	if (error)
23686d7f5d3SJohn Marino 		return error;
23786d7f5d3SJohn Marino 	mbp = &rqp->sr_rq;
23886d7f5d3SJohn Marino 	smb_rq_wstart(rqp);
23986d7f5d3SJohn Marino 	error = mb_put_mem(mbp, dp->ioc_twords, dp->ioc_twc * 2, MB_MUSER);
24086d7f5d3SJohn Marino 	if (error)
24186d7f5d3SJohn Marino 		goto bad;
24286d7f5d3SJohn Marino 	smb_rq_wend(rqp);
24386d7f5d3SJohn Marino 	smb_rq_bstart(rqp);
24486d7f5d3SJohn Marino 	error = mb_put_mem(mbp, dp->ioc_tbytes, dp->ioc_tbc, MB_MUSER);
24586d7f5d3SJohn Marino 	if (error)
24686d7f5d3SJohn Marino 		goto bad;
24786d7f5d3SJohn Marino 	smb_rq_bend(rqp);
24886d7f5d3SJohn Marino 	error = smb_rq_simple(rqp);
24986d7f5d3SJohn Marino 	if (error)
25086d7f5d3SJohn Marino 		goto bad;
25186d7f5d3SJohn Marino 	mdp = &rqp->sr_rp;
25286d7f5d3SJohn Marino 	md_get_uint8(mdp, &wc);
25386d7f5d3SJohn Marino 	dp->ioc_rwc = wc;
25486d7f5d3SJohn Marino 	wc *= 2;
25586d7f5d3SJohn Marino 	if (wc > dp->ioc_rpbufsz) {
25686d7f5d3SJohn Marino 		error = EBADRPC;
25786d7f5d3SJohn Marino 		goto bad;
25886d7f5d3SJohn Marino 	}
25986d7f5d3SJohn Marino 	error = md_get_mem(mdp, dp->ioc_rpbuf, wc, MB_MUSER);
26086d7f5d3SJohn Marino 	if (error)
26186d7f5d3SJohn Marino 		goto bad;
26286d7f5d3SJohn Marino 	md_get_uint16le(mdp, &bc);
26386d7f5d3SJohn Marino 	if ((wc + bc) > dp->ioc_rpbufsz) {
26486d7f5d3SJohn Marino 		error = EBADRPC;
26586d7f5d3SJohn Marino 		goto bad;
26686d7f5d3SJohn Marino 	}
26786d7f5d3SJohn Marino 	dp->ioc_rbc = bc;
26886d7f5d3SJohn Marino 	error = md_get_mem(mdp, dp->ioc_rpbuf + wc, bc, MB_MUSER);
26986d7f5d3SJohn Marino bad:
27086d7f5d3SJohn Marino 	dp->ioc_errclass = rqp->sr_errclass;
27186d7f5d3SJohn Marino 	dp->ioc_serror = rqp->sr_serror;
27286d7f5d3SJohn Marino 	dp->ioc_error = rqp->sr_error;
27386d7f5d3SJohn Marino 	smb_rq_done(rqp);
27486d7f5d3SJohn Marino 	return error;
27586d7f5d3SJohn Marino 
27686d7f5d3SJohn Marino }
27786d7f5d3SJohn Marino 
27886d7f5d3SJohn Marino static int
smb_cpdatain(struct mbchain * mbp,int len,caddr_t data)27986d7f5d3SJohn Marino smb_cpdatain(struct mbchain *mbp, int len, caddr_t data)
28086d7f5d3SJohn Marino {
28186d7f5d3SJohn Marino 	int error;
28286d7f5d3SJohn Marino 
28386d7f5d3SJohn Marino 	if (len == 0)
28486d7f5d3SJohn Marino 		return 0;
28586d7f5d3SJohn Marino 	error = mb_init(mbp);
28686d7f5d3SJohn Marino 	if (error)
28786d7f5d3SJohn Marino 		return error;
28886d7f5d3SJohn Marino 	return mb_put_mem(mbp, data, len, MB_MUSER);
28986d7f5d3SJohn Marino }
29086d7f5d3SJohn Marino 
29186d7f5d3SJohn Marino int
smb_usr_t2request(struct smb_share * ssp,struct smbioc_t2rq * dp,struct smb_cred * scred)29286d7f5d3SJohn Marino smb_usr_t2request(struct smb_share *ssp, struct smbioc_t2rq *dp,
29386d7f5d3SJohn Marino 	struct smb_cred *scred)
29486d7f5d3SJohn Marino {
29586d7f5d3SJohn Marino 	struct smb_t2rq t2, *t2p = &t2;
29686d7f5d3SJohn Marino 	struct mdchain *mdp;
29786d7f5d3SJohn Marino 	int error, len;
29886d7f5d3SJohn Marino 
29986d7f5d3SJohn Marino 	if (dp->ioc_setupcnt > 3)
30086d7f5d3SJohn Marino 		return EINVAL;
30186d7f5d3SJohn Marino 	error = smb_t2_init(t2p, SSTOCP(ssp), dp->ioc_setup[0], scred);
30286d7f5d3SJohn Marino 	if (error)
30386d7f5d3SJohn Marino 		return error;
30486d7f5d3SJohn Marino 	len = t2p->t2_setupcount = dp->ioc_setupcnt;
30586d7f5d3SJohn Marino 	if (len > 1)
30686d7f5d3SJohn Marino 		t2p->t2_setupdata = dp->ioc_setup;
30786d7f5d3SJohn Marino 	if (dp->ioc_name) {
30886d7f5d3SJohn Marino 		t2p->t_name = smb_strdupin(dp->ioc_name, 128);
30986d7f5d3SJohn Marino 		if (t2p->t_name == NULL) {
31086d7f5d3SJohn Marino 			error = ENOMEM;
31186d7f5d3SJohn Marino 			goto bad;
31286d7f5d3SJohn Marino 		}
31386d7f5d3SJohn Marino 	}
31486d7f5d3SJohn Marino 	t2p->t2_maxscount = 0;
31586d7f5d3SJohn Marino 	t2p->t2_maxpcount = dp->ioc_rparamcnt;
31686d7f5d3SJohn Marino 	t2p->t2_maxdcount = dp->ioc_rdatacnt;
31786d7f5d3SJohn Marino 	error = smb_cpdatain(&t2p->t2_tparam, dp->ioc_tparamcnt, dp->ioc_tparam);
31886d7f5d3SJohn Marino 	if (error)
31986d7f5d3SJohn Marino 		goto bad;
32086d7f5d3SJohn Marino 	error = smb_cpdatain(&t2p->t2_tdata, dp->ioc_tdatacnt, dp->ioc_tdata);
32186d7f5d3SJohn Marino 	if (error)
32286d7f5d3SJohn Marino 		goto bad;
32386d7f5d3SJohn Marino 	error = smb_t2_request(t2p);
32486d7f5d3SJohn Marino 	if (error)
32586d7f5d3SJohn Marino 		goto bad;
32686d7f5d3SJohn Marino 	mdp = &t2p->t2_rparam;
32786d7f5d3SJohn Marino 	if (mdp->md_top) {
32886d7f5d3SJohn Marino 		len = m_fixhdr(mdp->md_top);
32986d7f5d3SJohn Marino 		if (len > dp->ioc_rparamcnt) {
33086d7f5d3SJohn Marino 			error = EMSGSIZE;
33186d7f5d3SJohn Marino 			goto bad;
33286d7f5d3SJohn Marino 		}
33386d7f5d3SJohn Marino 		dp->ioc_rparamcnt = len;
33486d7f5d3SJohn Marino 		error = md_get_mem(mdp, dp->ioc_rparam, len, MB_MUSER);
33586d7f5d3SJohn Marino 		if (error)
33686d7f5d3SJohn Marino 			goto bad;
33786d7f5d3SJohn Marino 	} else
33886d7f5d3SJohn Marino 		dp->ioc_rparamcnt = 0;
33986d7f5d3SJohn Marino 	mdp = &t2p->t2_rdata;
34086d7f5d3SJohn Marino 	if (mdp->md_top) {
34186d7f5d3SJohn Marino 		len = m_fixhdr(mdp->md_top);
34286d7f5d3SJohn Marino 		if (len > dp->ioc_rdatacnt) {
34386d7f5d3SJohn Marino 			error = EMSGSIZE;
34486d7f5d3SJohn Marino 			goto bad;
34586d7f5d3SJohn Marino 		}
34686d7f5d3SJohn Marino 		dp->ioc_rdatacnt = len;
34786d7f5d3SJohn Marino 		error = md_get_mem(mdp, dp->ioc_rdata, len, MB_MUSER);
34886d7f5d3SJohn Marino 	} else
34986d7f5d3SJohn Marino 		dp->ioc_rdatacnt = 0;
35086d7f5d3SJohn Marino bad:
35186d7f5d3SJohn Marino 	if (t2p->t_name)
35286d7f5d3SJohn Marino 		smb_strfree(t2p->t_name);
35386d7f5d3SJohn Marino 	smb_t2_done(t2p);
35486d7f5d3SJohn Marino 	return error;
35586d7f5d3SJohn Marino }
356