xref: /freebsd/sys/netsmb/smb_smb.c (revision daa35ded10a879bc638c1f9f4b46dd660fcc7870)
1681a5bbeSBoris Popov /*
2681a5bbeSBoris Popov  * Copyright (c) 2000-2001 Boris Popov
3681a5bbeSBoris Popov  * All rights reserved.
4681a5bbeSBoris Popov  *
5681a5bbeSBoris Popov  * Redistribution and use in source and binary forms, with or without
6681a5bbeSBoris Popov  * modification, are permitted provided that the following conditions
7681a5bbeSBoris Popov  * are met:
8681a5bbeSBoris Popov  * 1. Redistributions of source code must retain the above copyright
9681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer.
10681a5bbeSBoris Popov  * 2. Redistributions in binary form must reproduce the above copyright
11681a5bbeSBoris Popov  *    notice, this list of conditions and the following disclaimer in the
12681a5bbeSBoris Popov  *    documentation and/or other materials provided with the distribution.
13681a5bbeSBoris Popov  * 3. All advertising materials mentioning features or use of this software
14681a5bbeSBoris Popov  *    must display the following acknowledgement:
15681a5bbeSBoris Popov  *    This product includes software developed by Boris Popov.
16681a5bbeSBoris Popov  * 4. Neither the name of the author nor the names of any co-contributors
17681a5bbeSBoris Popov  *    may be used to endorse or promote products derived from this software
18681a5bbeSBoris Popov  *    without specific prior written permission.
19681a5bbeSBoris Popov  *
20681a5bbeSBoris Popov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21681a5bbeSBoris Popov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22681a5bbeSBoris Popov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23681a5bbeSBoris Popov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24681a5bbeSBoris Popov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25681a5bbeSBoris Popov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26681a5bbeSBoris Popov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27681a5bbeSBoris Popov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28681a5bbeSBoris Popov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29681a5bbeSBoris Popov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30681a5bbeSBoris Popov  * SUCH DAMAGE.
31681a5bbeSBoris Popov  *
32681a5bbeSBoris Popov  * $FreeBSD$
33681a5bbeSBoris Popov  */
34681a5bbeSBoris Popov /*
35681a5bbeSBoris Popov  * various SMB requests. Most of the routines merely packs data into mbufs.
36681a5bbeSBoris Popov  */
37681a5bbeSBoris Popov #include <sys/param.h>
38681a5bbeSBoris Popov #include <sys/systm.h>
39681a5bbeSBoris Popov #include <sys/kernel.h>
40681a5bbeSBoris Popov #include <sys/malloc.h>
41681a5bbeSBoris Popov #include <sys/proc.h>
42681a5bbeSBoris Popov #include <sys/lock.h>
43681a5bbeSBoris Popov #include <sys/sysctl.h>
44681a5bbeSBoris Popov #include <sys/socket.h>
45681a5bbeSBoris Popov #include <sys/uio.h>
46681a5bbeSBoris Popov 
47681a5bbeSBoris Popov #include <sys/iconv.h>
48681a5bbeSBoris Popov 
49681a5bbeSBoris Popov #include <netsmb/smb.h>
50681a5bbeSBoris Popov #include <netsmb/smb_subr.h>
51681a5bbeSBoris Popov #include <netsmb/smb_rq.h>
52681a5bbeSBoris Popov #include <netsmb/smb_conn.h>
53681a5bbeSBoris Popov #include <netsmb/smb_tran.h>
54681a5bbeSBoris Popov 
55681a5bbeSBoris Popov struct smb_dialect {
56681a5bbeSBoris Popov 	int		d_id;
57681a5bbeSBoris Popov 	const char *	d_name;
58681a5bbeSBoris Popov };
59681a5bbeSBoris Popov 
60681a5bbeSBoris Popov static struct smb_dialect smb_dialects[] = {
61681a5bbeSBoris Popov 	{SMB_DIALECT_CORE,	"PC NETWORK PROGRAM 1.0"},
62681a5bbeSBoris Popov 	{SMB_DIALECT_COREPLUS,	"MICROSOFT NETWORKS 1.03"},
63681a5bbeSBoris Popov 	{SMB_DIALECT_LANMAN1_0,	"MICROSOFT NETWORKS 3.0"},
64681a5bbeSBoris Popov 	{SMB_DIALECT_LANMAN1_0,	"LANMAN1.0"},
65681a5bbeSBoris Popov 	{SMB_DIALECT_LANMAN2_0,	"LM1.2X002"},
66681a5bbeSBoris Popov 	{SMB_DIALECT_LANMAN2_0,	"Samba"},
67681a5bbeSBoris Popov 	{SMB_DIALECT_NTLM0_12,	"NT LANMAN 1.0"},
68681a5bbeSBoris Popov 	{SMB_DIALECT_NTLM0_12,	"NT LM 0.12"},
69681a5bbeSBoris Popov 	{-1,			NULL}
70681a5bbeSBoris Popov };
71681a5bbeSBoris Popov 
72681a5bbeSBoris Popov #define	SMB_DIALECT_MAX	(sizeof(smb_dialects) / sizeof(struct smb_dialect) - 2)
73681a5bbeSBoris Popov 
74681a5bbeSBoris Popov static int
75681a5bbeSBoris Popov smb_smb_nomux(struct smb_vc *vcp, struct smb_cred *scred, const char *name)
76681a5bbeSBoris Popov {
77fce6fbfaSBoris Popov 	if (scred->scr_td->td_proc == vcp->vc_iod->iod_p)
78681a5bbeSBoris Popov 		return 0;
79681a5bbeSBoris Popov 	SMBERROR("wrong function called(%s)\n", name);
80681a5bbeSBoris Popov 	return EINVAL;
81681a5bbeSBoris Popov }
82681a5bbeSBoris Popov 
83681a5bbeSBoris Popov int
84681a5bbeSBoris Popov smb_smb_negotiate(struct smb_vc *vcp, struct smb_cred *scred)
85681a5bbeSBoris Popov {
86681a5bbeSBoris Popov 	struct smb_dialect *dp;
87681a5bbeSBoris Popov 	struct smb_sopt *sp = NULL;
88681a5bbeSBoris Popov 	struct smb_rq *rqp;
89681a5bbeSBoris Popov 	struct mbchain *mbp;
90681a5bbeSBoris Popov 	struct mdchain *mdp;
91681a5bbeSBoris Popov 	u_int8_t wc, stime[8], sblen;
92681a5bbeSBoris Popov 	u_int16_t dindex, tw, tw1, swlen, bc;
93681a5bbeSBoris Popov 	int error, maxqsz;
94681a5bbeSBoris Popov 
956e551fb6SDavid E. O'Brien 	if (smb_smb_nomux(vcp, scred, __func__) != 0)
96681a5bbeSBoris Popov 		return EINVAL;
97681a5bbeSBoris Popov 	vcp->vc_hflags = 0;
98681a5bbeSBoris Popov 	vcp->vc_hflags2 = 0;
99681a5bbeSBoris Popov 	vcp->obj.co_flags &= ~(SMBV_ENCRYPT);
100681a5bbeSBoris Popov 	sp = &vcp->vc_sopt;
101681a5bbeSBoris Popov 	bzero(sp, sizeof(struct smb_sopt));
102681a5bbeSBoris Popov 	error = smb_rq_alloc(VCTOCP(vcp), SMB_COM_NEGOTIATE, scred, &rqp);
103681a5bbeSBoris Popov 	if (error)
104681a5bbeSBoris Popov 		return error;
105681a5bbeSBoris Popov 	smb_rq_getrequest(rqp, &mbp);
106681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
107681a5bbeSBoris Popov 	smb_rq_wend(rqp);
108681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
109681a5bbeSBoris Popov 	for(dp = smb_dialects; dp->d_id != -1; dp++) {
110681a5bbeSBoris Popov 		mb_put_uint8(mbp, SMB_DT_DIALECT);
111681a5bbeSBoris Popov 		smb_put_dstring(mbp, vcp, dp->d_name, SMB_CS_NONE);
112681a5bbeSBoris Popov 	}
113681a5bbeSBoris Popov 	smb_rq_bend(rqp);
114681a5bbeSBoris Popov 	error = smb_rq_simple(rqp);
115681a5bbeSBoris Popov 	SMBSDEBUG("%d\n", error);
116681a5bbeSBoris Popov 	if (error)
117681a5bbeSBoris Popov 		goto bad;
118681a5bbeSBoris Popov 	smb_rq_getreply(rqp, &mdp);
119681a5bbeSBoris Popov 	do {
120681a5bbeSBoris Popov 		error = md_get_uint8(mdp, &wc);
121681a5bbeSBoris Popov 		if (error)
122681a5bbeSBoris Popov 			break;
123681a5bbeSBoris Popov 		error = md_get_uint16le(mdp, &dindex);
124681a5bbeSBoris Popov 		if (error)
125681a5bbeSBoris Popov 			break;
126681a5bbeSBoris Popov 		if (dindex > 7) {
127681a5bbeSBoris Popov 			SMBERROR("Don't know how to talk with server %s (%d)\n", "xxx", dindex);
128681a5bbeSBoris Popov 			error = EBADRPC;
129681a5bbeSBoris Popov 			break;
130681a5bbeSBoris Popov 		}
131681a5bbeSBoris Popov 		dp = smb_dialects + dindex;
132681a5bbeSBoris Popov 		sp->sv_proto = dp->d_id;
133681a5bbeSBoris Popov 		SMBSDEBUG("Dialect %s (%d, %d)\n", dp->d_name, dindex, wc);
134681a5bbeSBoris Popov 		error = EBADRPC;
135681a5bbeSBoris Popov 		if (dp->d_id >= SMB_DIALECT_NTLM0_12) {
136681a5bbeSBoris Popov 			if (wc != 17)
137681a5bbeSBoris Popov 				break;
138681a5bbeSBoris Popov 			md_get_uint8(mdp, &sp->sv_sm);
139681a5bbeSBoris Popov 			md_get_uint16le(mdp, &sp->sv_maxmux);
140681a5bbeSBoris Popov 			md_get_uint16le(mdp, &sp->sv_maxvcs);
141681a5bbeSBoris Popov 			md_get_uint32le(mdp, &sp->sv_maxtx);
142681a5bbeSBoris Popov 			md_get_uint32le(mdp, &sp->sv_maxraw);
143681a5bbeSBoris Popov 			md_get_uint32le(mdp, &sp->sv_skey);
144681a5bbeSBoris Popov 			md_get_uint32le(mdp, &sp->sv_caps);
145681a5bbeSBoris Popov 			md_get_mem(mdp, stime, 8, MB_MSYSTEM);
146681a5bbeSBoris Popov 			md_get_uint16le(mdp, (u_int16_t*)&sp->sv_tz);
147681a5bbeSBoris Popov 			md_get_uint8(mdp, &sblen);
148681a5bbeSBoris Popov 			if (sblen && (sp->sv_sm & SMB_SM_ENCRYPT)) {
149681a5bbeSBoris Popov 				if (sblen != SMB_MAXCHALLENGELEN) {
150681a5bbeSBoris Popov 					SMBERROR("Unexpected length of security blob (%d)\n", sblen);
151681a5bbeSBoris Popov 					break;
152681a5bbeSBoris Popov 				}
153681a5bbeSBoris Popov 				error = md_get_uint16(mdp, &bc);
154681a5bbeSBoris Popov 				if (error)
155681a5bbeSBoris Popov 					break;
156681a5bbeSBoris Popov 				if (sp->sv_caps & SMB_CAP_EXT_SECURITY)
157681a5bbeSBoris Popov 					md_get_mem(mdp, NULL, 16, MB_MSYSTEM);
158681a5bbeSBoris Popov 				error = md_get_mem(mdp, vcp->vc_ch, sblen, MB_MSYSTEM);
159681a5bbeSBoris Popov 				if (error)
160681a5bbeSBoris Popov 					break;
161681a5bbeSBoris Popov 				vcp->vc_chlen = sblen;
162681a5bbeSBoris Popov 				vcp->obj.co_flags |= SMBV_ENCRYPT;
163681a5bbeSBoris Popov 			}
164681a5bbeSBoris Popov 			vcp->vc_hflags2 |= SMB_FLAGS2_KNOWS_LONG_NAMES;
165681a5bbeSBoris Popov 			if (dp->d_id == SMB_DIALECT_NTLM0_12 &&
166681a5bbeSBoris Popov 			    sp->sv_maxtx < 4096 &&
167681a5bbeSBoris Popov 			    (sp->sv_caps & SMB_CAP_NT_SMBS) == 0) {
168681a5bbeSBoris Popov 				vcp->obj.co_flags |= SMBV_WIN95;
169681a5bbeSBoris Popov 				SMBSDEBUG("Win95 detected\n");
170681a5bbeSBoris Popov 			}
171681a5bbeSBoris Popov 		} else if (dp->d_id > SMB_DIALECT_CORE) {
172681a5bbeSBoris Popov 			md_get_uint16le(mdp, &tw);
173681a5bbeSBoris Popov 			sp->sv_sm = tw;
174681a5bbeSBoris Popov 			md_get_uint16le(mdp, &tw);
175681a5bbeSBoris Popov 			sp->sv_maxtx = tw;
176681a5bbeSBoris Popov 			md_get_uint16le(mdp, &sp->sv_maxmux);
177681a5bbeSBoris Popov 			md_get_uint16le(mdp, &sp->sv_maxvcs);
178681a5bbeSBoris Popov 			md_get_uint16le(mdp, &tw);	/* rawmode */
179681a5bbeSBoris Popov 			md_get_uint32le(mdp, &sp->sv_skey);
180681a5bbeSBoris Popov 			if (wc == 13) {		/* >= LANMAN1 */
181681a5bbeSBoris Popov 				md_get_uint16(mdp, &tw);		/* time */
182681a5bbeSBoris Popov 				md_get_uint16(mdp, &tw1);		/* date */
183681a5bbeSBoris Popov 				md_get_uint16le(mdp, (u_int16_t*)&sp->sv_tz);
184681a5bbeSBoris Popov 				md_get_uint16le(mdp, &swlen);
185681a5bbeSBoris Popov 				if (swlen > SMB_MAXCHALLENGELEN)
186681a5bbeSBoris Popov 					break;
187681a5bbeSBoris Popov 				md_get_uint16(mdp, NULL);	/* mbz */
188681a5bbeSBoris Popov 				if (md_get_uint16(mdp, &bc) != 0)
189681a5bbeSBoris Popov 					break;
190681a5bbeSBoris Popov 				if (bc < swlen)
191681a5bbeSBoris Popov 					break;
192681a5bbeSBoris Popov 				if (swlen && (sp->sv_sm & SMB_SM_ENCRYPT)) {
193681a5bbeSBoris Popov 					error = md_get_mem(mdp, vcp->vc_ch, swlen, MB_MSYSTEM);
194681a5bbeSBoris Popov 					if (error)
195681a5bbeSBoris Popov 						break;
196681a5bbeSBoris Popov 					vcp->vc_chlen = swlen;
197681a5bbeSBoris Popov 					vcp->obj.co_flags |= SMBV_ENCRYPT;
198681a5bbeSBoris Popov 				}
199681a5bbeSBoris Popov 			}
200681a5bbeSBoris Popov 			vcp->vc_hflags2 |= SMB_FLAGS2_KNOWS_LONG_NAMES;
201681a5bbeSBoris Popov 		} else {	/* an old CORE protocol */
202681a5bbeSBoris Popov 			sp->sv_maxmux = 1;
203681a5bbeSBoris Popov 		}
204681a5bbeSBoris Popov 		error = 0;
205681a5bbeSBoris Popov 	} while (0);
206681a5bbeSBoris Popov 	if (error == 0) {
207681a5bbeSBoris Popov 		vcp->vc_maxvcs = sp->sv_maxvcs;
208681a5bbeSBoris Popov 		if (vcp->vc_maxvcs <= 1) {
209681a5bbeSBoris Popov 			if (vcp->vc_maxvcs == 0)
210681a5bbeSBoris Popov 				vcp->vc_maxvcs = 1;
211681a5bbeSBoris Popov 		}
212681a5bbeSBoris Popov 		if (sp->sv_maxtx <= 0 || sp->sv_maxtx > 0xffff)
213681a5bbeSBoris Popov 			sp->sv_maxtx = 1024;
214681a5bbeSBoris Popov 		SMB_TRAN_GETPARAM(vcp, SMBTP_SNDSZ, &maxqsz);
215681a5bbeSBoris Popov 		vcp->vc_txmax = min(sp->sv_maxtx, maxqsz);
216681a5bbeSBoris Popov 		SMBSDEBUG("TZ = %d\n", sp->sv_tz);
217681a5bbeSBoris Popov 		SMBSDEBUG("CAPS = %x\n", sp->sv_caps);
218681a5bbeSBoris Popov 		SMBSDEBUG("MAXMUX = %d\n", sp->sv_maxmux);
219681a5bbeSBoris Popov 		SMBSDEBUG("MAXVCS = %d\n", sp->sv_maxvcs);
220681a5bbeSBoris Popov 		SMBSDEBUG("MAXRAW = %d\n", sp->sv_maxraw);
221681a5bbeSBoris Popov 		SMBSDEBUG("MAXTX = %d\n", sp->sv_maxtx);
222681a5bbeSBoris Popov 	}
223681a5bbeSBoris Popov bad:
224681a5bbeSBoris Popov 	smb_rq_done(rqp);
225681a5bbeSBoris Popov 	return error;
226681a5bbeSBoris Popov }
227681a5bbeSBoris Popov 
228681a5bbeSBoris Popov int
229681a5bbeSBoris Popov smb_smb_ssnsetup(struct smb_vc *vcp, struct smb_cred *scred)
230681a5bbeSBoris Popov {
231681a5bbeSBoris Popov 	struct smb_rq *rqp;
232681a5bbeSBoris Popov 	struct mbchain *mbp;
233681a5bbeSBoris Popov /*	u_int8_t wc;
234681a5bbeSBoris Popov 	u_int16_t tw, tw1;*/
235681a5bbeSBoris Popov 	smb_uniptr unipp, ntencpass = NULL;
236681a5bbeSBoris Popov 	char *pp, *up, *pbuf, *encpass;
237681a5bbeSBoris Popov 	int error, plen, uniplen, ulen;
238681a5bbeSBoris Popov 
239681a5bbeSBoris Popov 	vcp->vc_smbuid = SMB_UID_UNKNOWN;
240681a5bbeSBoris Popov 
2416e551fb6SDavid E. O'Brien 	if (smb_smb_nomux(vcp, scred, __func__) != 0)
242681a5bbeSBoris Popov 		return EINVAL;
243681a5bbeSBoris Popov 
244681a5bbeSBoris Popov 	error = smb_rq_alloc(VCTOCP(vcp), SMB_COM_SESSION_SETUP_ANDX, scred, &rqp);
245681a5bbeSBoris Popov 	if (error)
246681a5bbeSBoris Popov 		return error;
247681a5bbeSBoris Popov 	pbuf = malloc(SMB_MAXPASSWORDLEN + 1, M_SMBTEMP, M_WAITOK);
248681a5bbeSBoris Popov 	encpass = malloc(24, M_SMBTEMP, M_WAITOK);
249681a5bbeSBoris Popov 	if (vcp->vc_sopt.sv_sm & SMB_SM_USER) {
250681a5bbeSBoris Popov 		iconv_convstr(vcp->vc_toupper, pbuf, smb_vc_getpass(vcp));
251681a5bbeSBoris Popov 		iconv_convstr(vcp->vc_toserver, pbuf, pbuf);
252681a5bbeSBoris Popov 		if (vcp->vc_sopt.sv_sm & SMB_SM_ENCRYPT) {
253681a5bbeSBoris Popov 			uniplen = plen = 24;
254681a5bbeSBoris Popov 			smb_encrypt(pbuf, vcp->vc_ch, encpass);
255681a5bbeSBoris Popov 			ntencpass = malloc(uniplen, M_SMBTEMP, M_WAITOK);
256681a5bbeSBoris Popov 			iconv_convstr(vcp->vc_toserver, pbuf, smb_vc_getpass(vcp));
257681a5bbeSBoris Popov 			smb_ntencrypt(pbuf, vcp->vc_ch, (u_char*)ntencpass);
258681a5bbeSBoris Popov 			pp = encpass;
259681a5bbeSBoris Popov 			unipp = ntencpass;
260681a5bbeSBoris Popov 		} else {
261681a5bbeSBoris Popov 			plen = strlen(pbuf) + 1;
262681a5bbeSBoris Popov 			pp = pbuf;
263681a5bbeSBoris Popov 			uniplen = plen * 2;
264681a5bbeSBoris Popov 			ntencpass = malloc(uniplen, M_SMBTEMP, M_WAITOK);
265681a5bbeSBoris Popov 			smb_strtouni(ntencpass, smb_vc_getpass(vcp));
266681a5bbeSBoris Popov 			plen--;
267daa35dedSBoris Popov 
268daa35dedSBoris Popov 			/*
269daa35dedSBoris Popov 			 * The uniplen is zeroed because Samba cannot deal
270daa35dedSBoris Popov 			 * with this 2nd cleartext password.  This Samba
271daa35dedSBoris Popov 			 * "bug" is actually a workaround for problems in
272daa35dedSBoris Popov 			 * Microsoft clients.
273daa35dedSBoris Popov 			 */
274681a5bbeSBoris Popov 			uniplen = 0/*-= 2*/;
275681a5bbeSBoris Popov 			unipp = ntencpass;
276681a5bbeSBoris Popov 		}
277681a5bbeSBoris Popov 	} else {
278681a5bbeSBoris Popov 		/*
279681a5bbeSBoris Popov 		 * In the share security mode password will be used
280681a5bbeSBoris Popov 		 * only in the tree authentication
281681a5bbeSBoris Popov 		 */
282681a5bbeSBoris Popov 		 pp = "";
283681a5bbeSBoris Popov 		 plen = 1;
284681a5bbeSBoris Popov 		 unipp = &smb_unieol;
285681a5bbeSBoris Popov 		 uniplen = sizeof(smb_unieol);
286681a5bbeSBoris Popov 	}
287681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
288681a5bbeSBoris Popov 	mbp = &rqp->sr_rq;
289681a5bbeSBoris Popov 	up = vcp->vc_username;
290681a5bbeSBoris Popov 	ulen = strlen(up) + 1;
291681a5bbeSBoris Popov 	mb_put_uint8(mbp, 0xff);
292681a5bbeSBoris Popov 	mb_put_uint8(mbp, 0);
293681a5bbeSBoris Popov 	mb_put_uint16le(mbp, 0);
294681a5bbeSBoris Popov 	mb_put_uint16le(mbp, vcp->vc_sopt.sv_maxtx);
295681a5bbeSBoris Popov 	mb_put_uint16le(mbp, vcp->vc_sopt.sv_maxmux);
296681a5bbeSBoris Popov 	mb_put_uint16le(mbp, vcp->vc_number);
297681a5bbeSBoris Popov 	mb_put_uint32le(mbp, vcp->vc_sopt.sv_skey);
298681a5bbeSBoris Popov 	mb_put_uint16le(mbp, plen);
299681a5bbeSBoris Popov 	if (SMB_DIALECT(vcp) < SMB_DIALECT_NTLM0_12) {
300681a5bbeSBoris Popov 		mb_put_uint32le(mbp, 0);
301681a5bbeSBoris Popov 		smb_rq_wend(rqp);
302681a5bbeSBoris Popov 		smb_rq_bstart(rqp);
303681a5bbeSBoris Popov 		mb_put_mem(mbp, pp, plen, MB_MSYSTEM);
304681a5bbeSBoris Popov 		smb_put_dstring(mbp, vcp, up, SMB_CS_NONE);
305681a5bbeSBoris Popov 	} else {
306681a5bbeSBoris Popov 		mb_put_uint16le(mbp, uniplen);
307681a5bbeSBoris Popov 		mb_put_uint32le(mbp, 0);		/* reserved */
308daa35dedSBoris Popov 		mb_put_uint32le(mbp, vcp->obj.co_flags & SMBV_UNICODE ?
309daa35dedSBoris Popov 				     SMB_CAP_UNICODE : 0);
310681a5bbeSBoris Popov 		smb_rq_wend(rqp);
311681a5bbeSBoris Popov 		smb_rq_bstart(rqp);
312681a5bbeSBoris Popov 		mb_put_mem(mbp, pp, plen, MB_MSYSTEM);
313681a5bbeSBoris Popov 		mb_put_mem(mbp, (caddr_t)unipp, uniplen, MB_MSYSTEM);
314681a5bbeSBoris Popov 		smb_put_dstring(mbp, vcp, up, SMB_CS_NONE);		/* AccountName */
315681a5bbeSBoris Popov 		smb_put_dstring(mbp, vcp, vcp->vc_domain, SMB_CS_NONE);	/* PrimaryDomain */
316681a5bbeSBoris Popov 		smb_put_dstring(mbp, vcp, "FreeBSD", SMB_CS_NONE);	/* Client's OS */
317681a5bbeSBoris Popov 		smb_put_dstring(mbp, vcp, "NETSMB", SMB_CS_NONE);		/* Client name */
318681a5bbeSBoris Popov 	}
319681a5bbeSBoris Popov 	smb_rq_bend(rqp);
320681a5bbeSBoris Popov 	if (ntencpass)
321681a5bbeSBoris Popov 		free(ntencpass, M_SMBTEMP);
322681a5bbeSBoris Popov 	error = smb_rq_simple(rqp);
323681a5bbeSBoris Popov 	SMBSDEBUG("%d\n", error);
324681a5bbeSBoris Popov 	if (error) {
325681a5bbeSBoris Popov 		if (rqp->sr_errclass == ERRDOS && rqp->sr_serror == ERRnoaccess)
326681a5bbeSBoris Popov 			error = EAUTH;
327681a5bbeSBoris Popov 		goto bad;
328681a5bbeSBoris Popov 	}
329681a5bbeSBoris Popov 	vcp->vc_smbuid = rqp->sr_rpuid;
330681a5bbeSBoris Popov bad:
331681a5bbeSBoris Popov 	free(encpass, M_SMBTEMP);
332681a5bbeSBoris Popov 	free(pbuf, M_SMBTEMP);
333681a5bbeSBoris Popov 	smb_rq_done(rqp);
334681a5bbeSBoris Popov 	return error;
335681a5bbeSBoris Popov }
336681a5bbeSBoris Popov 
337681a5bbeSBoris Popov int
338681a5bbeSBoris Popov smb_smb_ssnclose(struct smb_vc *vcp, struct smb_cred *scred)
339681a5bbeSBoris Popov {
340681a5bbeSBoris Popov 	struct smb_rq *rqp;
341681a5bbeSBoris Popov 	struct mbchain *mbp;
342681a5bbeSBoris Popov 	int error;
343681a5bbeSBoris Popov 
344681a5bbeSBoris Popov 	if (vcp->vc_smbuid == SMB_UID_UNKNOWN)
345681a5bbeSBoris Popov 		return 0;
346681a5bbeSBoris Popov 
3476e551fb6SDavid E. O'Brien 	if (smb_smb_nomux(vcp, scred, __func__) != 0)
348681a5bbeSBoris Popov 		return EINVAL;
349681a5bbeSBoris Popov 
350681a5bbeSBoris Popov 	error = smb_rq_alloc(VCTOCP(vcp), SMB_COM_LOGOFF_ANDX, scred, &rqp);
351681a5bbeSBoris Popov 	if (error)
352681a5bbeSBoris Popov 		return error;
353681a5bbeSBoris Popov 	mbp = &rqp->sr_rq;
354681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
355681a5bbeSBoris Popov 	mb_put_uint8(mbp, 0xff);
356681a5bbeSBoris Popov 	mb_put_uint8(mbp, 0);
357681a5bbeSBoris Popov 	mb_put_uint16le(mbp, 0);
358681a5bbeSBoris Popov 	smb_rq_wend(rqp);
359681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
360681a5bbeSBoris Popov 	smb_rq_bend(rqp);
361681a5bbeSBoris Popov 	error = smb_rq_simple(rqp);
362681a5bbeSBoris Popov 	SMBSDEBUG("%d\n", error);
363681a5bbeSBoris Popov 	smb_rq_done(rqp);
364681a5bbeSBoris Popov 	return error;
365681a5bbeSBoris Popov }
366681a5bbeSBoris Popov 
367681a5bbeSBoris Popov static char smb_any_share[] = "?????";
368681a5bbeSBoris Popov 
369681a5bbeSBoris Popov static char *
370681a5bbeSBoris Popov smb_share_typename(int stype)
371681a5bbeSBoris Popov {
372681a5bbeSBoris Popov 	char *pp;
373681a5bbeSBoris Popov 
374681a5bbeSBoris Popov 	switch (stype) {
375681a5bbeSBoris Popov 	    case SMB_ST_DISK:
376681a5bbeSBoris Popov 		pp = "A:";
377681a5bbeSBoris Popov 		break;
378681a5bbeSBoris Popov 	    case SMB_ST_PRINTER:
379681a5bbeSBoris Popov 		pp = smb_any_share;		/* can't use LPT: here... */
380681a5bbeSBoris Popov 		break;
381681a5bbeSBoris Popov 	    case SMB_ST_PIPE:
382681a5bbeSBoris Popov 		pp = "IPC";
383681a5bbeSBoris Popov 		break;
384681a5bbeSBoris Popov 	    case SMB_ST_COMM:
385681a5bbeSBoris Popov 		pp = "COMM";
386681a5bbeSBoris Popov 		break;
387681a5bbeSBoris Popov 	    case SMB_ST_ANY:
388681a5bbeSBoris Popov 	    default:
389681a5bbeSBoris Popov 		pp = smb_any_share;
390681a5bbeSBoris Popov 		break;
391681a5bbeSBoris Popov 	}
392681a5bbeSBoris Popov 	return pp;
393681a5bbeSBoris Popov }
394681a5bbeSBoris Popov 
395681a5bbeSBoris Popov int
396681a5bbeSBoris Popov smb_smb_treeconnect(struct smb_share *ssp, struct smb_cred *scred)
397681a5bbeSBoris Popov {
398681a5bbeSBoris Popov 	struct smb_vc *vcp;
399681a5bbeSBoris Popov 	struct smb_rq rq, *rqp = &rq;
400681a5bbeSBoris Popov 	struct mbchain *mbp;
401681a5bbeSBoris Popov 	char *pp, *pbuf, *encpass;
402681a5bbeSBoris Popov 	int error, plen, caseopt;
403681a5bbeSBoris Popov 
404681a5bbeSBoris Popov 	ssp->ss_tid = SMB_TID_UNKNOWN;
405681a5bbeSBoris Popov 	error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_TREE_CONNECT_ANDX, scred, &rqp);
406681a5bbeSBoris Popov 	if (error)
407681a5bbeSBoris Popov 		return error;
408681a5bbeSBoris Popov 	vcp = rqp->sr_vc;
409681a5bbeSBoris Popov 	caseopt = SMB_CS_NONE;
410681a5bbeSBoris Popov 	if (vcp->vc_sopt.sv_sm & SMB_SM_USER) {
411681a5bbeSBoris Popov 		plen = 1;
412681a5bbeSBoris Popov 		pp = "";
413681a5bbeSBoris Popov 		pbuf = NULL;
414681a5bbeSBoris Popov 		encpass = NULL;
415681a5bbeSBoris Popov 	} else {
416681a5bbeSBoris Popov 		pbuf = malloc(SMB_MAXPASSWORDLEN + 1, M_SMBTEMP, M_WAITOK);
417681a5bbeSBoris Popov 		encpass = malloc(24, M_SMBTEMP, M_WAITOK);
418681a5bbeSBoris Popov 		iconv_convstr(vcp->vc_toupper, pbuf, smb_share_getpass(ssp));
419681a5bbeSBoris Popov 		iconv_convstr(vcp->vc_toserver, pbuf, pbuf);
420681a5bbeSBoris Popov 		if (vcp->vc_sopt.sv_sm & SMB_SM_ENCRYPT) {
421681a5bbeSBoris Popov 			plen = 24;
422681a5bbeSBoris Popov 			smb_encrypt(pbuf, vcp->vc_ch, encpass);
423681a5bbeSBoris Popov 			pp = encpass;
424681a5bbeSBoris Popov 		} else {
425681a5bbeSBoris Popov 			plen = strlen(pbuf) + 1;
426681a5bbeSBoris Popov 			pp = pbuf;
427681a5bbeSBoris Popov 		}
428681a5bbeSBoris Popov 	}
429681a5bbeSBoris Popov 	mbp = &rqp->sr_rq;
430681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
431681a5bbeSBoris Popov 	mb_put_uint8(mbp, 0xff);
432681a5bbeSBoris Popov 	mb_put_uint8(mbp, 0);
433681a5bbeSBoris Popov 	mb_put_uint16le(mbp, 0);
434681a5bbeSBoris Popov 	mb_put_uint16le(mbp, 0);		/* Flags */
435681a5bbeSBoris Popov 	mb_put_uint16le(mbp, plen);
436681a5bbeSBoris Popov 	smb_rq_wend(rqp);
437681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
438681a5bbeSBoris Popov 	mb_put_mem(mbp, pp, plen, MB_MSYSTEM);
439681a5bbeSBoris Popov 	smb_put_dmem(mbp, vcp, "\\\\", 2, caseopt);
440681a5bbeSBoris Popov 	pp = vcp->vc_srvname;
441681a5bbeSBoris Popov 	smb_put_dmem(mbp, vcp, pp, strlen(pp), caseopt);
442681a5bbeSBoris Popov 	smb_put_dmem(mbp, vcp, "\\", 1, caseopt);
443681a5bbeSBoris Popov 	pp = ssp->ss_name;
444681a5bbeSBoris Popov 	smb_put_dstring(mbp, vcp, pp, caseopt);
445681a5bbeSBoris Popov 	pp = smb_share_typename(ssp->ss_type);
446681a5bbeSBoris Popov 	smb_put_dstring(mbp, vcp, pp, caseopt);
447681a5bbeSBoris Popov 	smb_rq_bend(rqp);
448681a5bbeSBoris Popov 	error = smb_rq_simple(rqp);
449681a5bbeSBoris Popov 	SMBSDEBUG("%d\n", error);
450681a5bbeSBoris Popov 	if (error)
451681a5bbeSBoris Popov 		goto bad;
452681a5bbeSBoris Popov 	ssp->ss_tid = rqp->sr_rptid;
453681a5bbeSBoris Popov 	ssp->ss_vcgenid = vcp->vc_genid;
454681a5bbeSBoris Popov 	ssp->ss_flags |= SMBS_CONNECTED;
455681a5bbeSBoris Popov bad:
456681a5bbeSBoris Popov 	if (encpass)
457681a5bbeSBoris Popov 		free(encpass, M_SMBTEMP);
458681a5bbeSBoris Popov 	if (pbuf)
459681a5bbeSBoris Popov 		free(pbuf, M_SMBTEMP);
460681a5bbeSBoris Popov 	smb_rq_done(rqp);
461681a5bbeSBoris Popov 	return error;
462681a5bbeSBoris Popov }
463681a5bbeSBoris Popov 
464681a5bbeSBoris Popov int
465681a5bbeSBoris Popov smb_smb_treedisconnect(struct smb_share *ssp, struct smb_cred *scred)
466681a5bbeSBoris Popov {
467681a5bbeSBoris Popov 	struct smb_rq *rqp;
468681a5bbeSBoris Popov 	struct mbchain *mbp;
469681a5bbeSBoris Popov 	int error;
470681a5bbeSBoris Popov 
471681a5bbeSBoris Popov 	if (ssp->ss_tid == SMB_TID_UNKNOWN)
472681a5bbeSBoris Popov 		return 0;
473681a5bbeSBoris Popov 	error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_TREE_DISCONNECT, scred, &rqp);
474681a5bbeSBoris Popov 	if (error)
475681a5bbeSBoris Popov 		return error;
476681a5bbeSBoris Popov 	mbp = &rqp->sr_rq;
477681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
478681a5bbeSBoris Popov 	smb_rq_wend(rqp);
479681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
480681a5bbeSBoris Popov 	smb_rq_bend(rqp);
481681a5bbeSBoris Popov 	error = smb_rq_simple(rqp);
482681a5bbeSBoris Popov 	SMBSDEBUG("%d\n", error);
483681a5bbeSBoris Popov 	smb_rq_done(rqp);
484681a5bbeSBoris Popov 	ssp->ss_tid = SMB_TID_UNKNOWN;
485681a5bbeSBoris Popov 	return error;
486681a5bbeSBoris Popov }
487681a5bbeSBoris Popov 
488681a5bbeSBoris Popov static __inline int
489681a5bbeSBoris Popov smb_smb_read(struct smb_share *ssp, u_int16_t fid,
490681a5bbeSBoris Popov 	int *len, int *rresid, struct uio *uio, struct smb_cred *scred)
491681a5bbeSBoris Popov {
492681a5bbeSBoris Popov 	struct smb_rq *rqp;
493681a5bbeSBoris Popov 	struct mbchain *mbp;
494681a5bbeSBoris Popov 	struct mdchain *mdp;
495681a5bbeSBoris Popov 	u_int16_t resid, bc;
496681a5bbeSBoris Popov 	u_int8_t wc;
497681a5bbeSBoris Popov 	int error, rlen, blksz;
498681a5bbeSBoris Popov 
499681a5bbeSBoris Popov 	error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_READ, scred, &rqp);
500681a5bbeSBoris Popov 	if (error)
501681a5bbeSBoris Popov 		return error;
502681a5bbeSBoris Popov 
503681a5bbeSBoris Popov 	blksz = SSTOVC(ssp)->vc_txmax - SMB_HDRLEN - 16;
504681a5bbeSBoris Popov 	rlen = *len = min(blksz, *len);
505681a5bbeSBoris Popov 
506681a5bbeSBoris Popov 	smb_rq_getrequest(rqp, &mbp);
507681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
508681a5bbeSBoris Popov 	mb_put_mem(mbp, (caddr_t)&fid, sizeof(fid), MB_MSYSTEM);
509681a5bbeSBoris Popov 	mb_put_uint16le(mbp, rlen);
510681a5bbeSBoris Popov 	mb_put_uint32le(mbp, uio->uio_offset);
511681a5bbeSBoris Popov 	mb_put_uint16le(mbp, min(uio->uio_resid, 0xffff));
512681a5bbeSBoris Popov 	smb_rq_wend(rqp);
513681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
514681a5bbeSBoris Popov 	smb_rq_bend(rqp);
515681a5bbeSBoris Popov 	do {
516681a5bbeSBoris Popov 		error = smb_rq_simple(rqp);
517681a5bbeSBoris Popov 		if (error)
518681a5bbeSBoris Popov 			break;
519681a5bbeSBoris Popov 		smb_rq_getreply(rqp, &mdp);
520681a5bbeSBoris Popov 		md_get_uint8(mdp, &wc);
521681a5bbeSBoris Popov 		if (wc != 5) {
522681a5bbeSBoris Popov 			error = EBADRPC;
523681a5bbeSBoris Popov 			break;
524681a5bbeSBoris Popov 		}
525681a5bbeSBoris Popov 		md_get_uint16le(mdp, &resid);
526681a5bbeSBoris Popov 		md_get_mem(mdp, NULL, 4 * 2, MB_MSYSTEM);
527681a5bbeSBoris Popov 		md_get_uint16le(mdp, &bc);
528681a5bbeSBoris Popov 		md_get_uint8(mdp, NULL);		/* ignore buffer type */
529681a5bbeSBoris Popov 		md_get_uint16le(mdp, &resid);
530681a5bbeSBoris Popov 		if (resid == 0) {
531681a5bbeSBoris Popov 			*rresid = resid;
532681a5bbeSBoris Popov 			break;
533681a5bbeSBoris Popov 		}
534681a5bbeSBoris Popov 		error = md_get_uio(mdp, uio, resid);
535681a5bbeSBoris Popov 		if (error)
536681a5bbeSBoris Popov 			break;
537681a5bbeSBoris Popov 		*rresid = resid;
538681a5bbeSBoris Popov 	} while(0);
539681a5bbeSBoris Popov 	smb_rq_done(rqp);
540681a5bbeSBoris Popov 	return error;
541681a5bbeSBoris Popov }
542681a5bbeSBoris Popov 
543681a5bbeSBoris Popov int
544681a5bbeSBoris Popov smb_read(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
545681a5bbeSBoris Popov 	struct smb_cred *scred)
546681a5bbeSBoris Popov {
547681a5bbeSBoris Popov 	int tsize, len, resid;
548681a5bbeSBoris Popov 	int error = 0;
549681a5bbeSBoris Popov 
550681a5bbeSBoris Popov 	tsize = uio->uio_resid;
551681a5bbeSBoris Popov 	while (tsize > 0) {
552681a5bbeSBoris Popov 		len = tsize;
553681a5bbeSBoris Popov 		error = smb_smb_read(ssp, fid, &len, &resid, uio, scred);
554681a5bbeSBoris Popov 		if (error)
555681a5bbeSBoris Popov 			break;
556681a5bbeSBoris Popov 		tsize -= resid;
557681a5bbeSBoris Popov 		if (resid < len)
558681a5bbeSBoris Popov 			break;
559681a5bbeSBoris Popov 	}
560681a5bbeSBoris Popov 	return error;
561681a5bbeSBoris Popov }
562681a5bbeSBoris Popov 
563681a5bbeSBoris Popov static __inline int
564681a5bbeSBoris Popov smb_smb_write(struct smb_share *ssp, u_int16_t fid, int *len, int *rresid,
565681a5bbeSBoris Popov 	struct uio *uio, struct smb_cred *scred)
566681a5bbeSBoris Popov {
567681a5bbeSBoris Popov 	struct smb_rq *rqp;
568681a5bbeSBoris Popov 	struct mbchain *mbp;
569681a5bbeSBoris Popov 	struct mdchain *mdp;
570681a5bbeSBoris Popov 	u_int16_t resid;
571681a5bbeSBoris Popov 	u_int8_t wc;
572681a5bbeSBoris Popov 	int error, blksz;
573681a5bbeSBoris Popov 
574681a5bbeSBoris Popov 	blksz = SSTOVC(ssp)->vc_txmax - SMB_HDRLEN - 16;
575681a5bbeSBoris Popov 	if (blksz > 0xffff)
576681a5bbeSBoris Popov 		blksz = 0xffff;
577681a5bbeSBoris Popov 
578681a5bbeSBoris Popov 	resid = *len = min(blksz, *len);
579681a5bbeSBoris Popov 
580681a5bbeSBoris Popov 	error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_WRITE, scred, &rqp);
581681a5bbeSBoris Popov 	if (error)
582681a5bbeSBoris Popov 		return error;
583681a5bbeSBoris Popov 	smb_rq_getrequest(rqp, &mbp);
584681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
585681a5bbeSBoris Popov 	mb_put_mem(mbp, (caddr_t)&fid, sizeof(fid), MB_MSYSTEM);
586681a5bbeSBoris Popov 	mb_put_uint16le(mbp, resid);
587681a5bbeSBoris Popov 	mb_put_uint32le(mbp, uio->uio_offset);
588681a5bbeSBoris Popov 	mb_put_uint16le(mbp, min(uio->uio_resid, 0xffff));
589681a5bbeSBoris Popov 	smb_rq_wend(rqp);
590681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
591681a5bbeSBoris Popov 	mb_put_uint8(mbp, SMB_DT_DATA);
592681a5bbeSBoris Popov 	mb_put_uint16le(mbp, resid);
593681a5bbeSBoris Popov 	do {
594681a5bbeSBoris Popov 		error = mb_put_uio(mbp, uio, resid);
595681a5bbeSBoris Popov 		if (error)
596681a5bbeSBoris Popov 			break;
597681a5bbeSBoris Popov 		smb_rq_bend(rqp);
598681a5bbeSBoris Popov 		error = smb_rq_simple(rqp);
599681a5bbeSBoris Popov 		if (error)
600681a5bbeSBoris Popov 			break;
601681a5bbeSBoris Popov 		smb_rq_getreply(rqp, &mdp);
602681a5bbeSBoris Popov 		md_get_uint8(mdp, &wc);
603681a5bbeSBoris Popov 		if (wc != 1) {
604681a5bbeSBoris Popov 			error = EBADRPC;
605681a5bbeSBoris Popov 			break;
606681a5bbeSBoris Popov 		}
607681a5bbeSBoris Popov 		md_get_uint16le(mdp, &resid);
608681a5bbeSBoris Popov 		*rresid = resid;
609681a5bbeSBoris Popov 	} while(0);
610681a5bbeSBoris Popov 	smb_rq_done(rqp);
611681a5bbeSBoris Popov 	return error;
612681a5bbeSBoris Popov }
613681a5bbeSBoris Popov 
614681a5bbeSBoris Popov int
615681a5bbeSBoris Popov smb_write(struct smb_share *ssp, u_int16_t fid, struct uio *uio,
616681a5bbeSBoris Popov 	struct smb_cred *scred)
617681a5bbeSBoris Popov {
618681a5bbeSBoris Popov 	int error = 0, len, tsize, resid;
619681a5bbeSBoris Popov 	struct uio olduio;
620681a5bbeSBoris Popov 
621681a5bbeSBoris Popov 	/*
622681a5bbeSBoris Popov 	 * review: manage iov more precisely
623681a5bbeSBoris Popov 	 */
624681a5bbeSBoris Popov 	if (uio->uio_iovcnt != 1) {
625681a5bbeSBoris Popov 		SMBERROR("can't handle iovcnt > 1\n");
626681a5bbeSBoris Popov 		return EIO;
627681a5bbeSBoris Popov 	}
628681a5bbeSBoris Popov 	tsize = uio->uio_resid;
629681a5bbeSBoris Popov 	olduio = *uio;
630681a5bbeSBoris Popov 	while (tsize > 0) {
631681a5bbeSBoris Popov 		len = tsize;
632681a5bbeSBoris Popov 		error = smb_smb_write(ssp, fid, &len, &resid, uio, scred);
633681a5bbeSBoris Popov 		if (error)
634681a5bbeSBoris Popov 			break;
635681a5bbeSBoris Popov 		if (resid < len) {
636681a5bbeSBoris Popov 			error = EIO;
637681a5bbeSBoris Popov 			break;
638681a5bbeSBoris Popov 		}
639681a5bbeSBoris Popov 		tsize -= resid;
640681a5bbeSBoris Popov 	}
641681a5bbeSBoris Popov 	if (error) {
642681a5bbeSBoris Popov 		*uio = olduio;
643681a5bbeSBoris Popov 	}
644681a5bbeSBoris Popov 	return error;
645681a5bbeSBoris Popov }
646681a5bbeSBoris Popov 
647681a5bbeSBoris Popov int
648681a5bbeSBoris Popov smb_smb_echo(struct smb_vc *vcp, struct smb_cred *scred)
649681a5bbeSBoris Popov {
650681a5bbeSBoris Popov 	struct smb_rq *rqp;
651681a5bbeSBoris Popov 	struct mbchain *mbp;
652681a5bbeSBoris Popov 	int error;
653681a5bbeSBoris Popov 
654681a5bbeSBoris Popov 	error = smb_rq_alloc(VCTOCP(vcp), SMB_COM_ECHO, scred, &rqp);
655681a5bbeSBoris Popov 	if (error)
656681a5bbeSBoris Popov 		return error;
657681a5bbeSBoris Popov 	mbp = &rqp->sr_rq;
658681a5bbeSBoris Popov 	smb_rq_wstart(rqp);
659681a5bbeSBoris Popov 	mb_put_uint16le(mbp, 1);
660681a5bbeSBoris Popov 	smb_rq_wend(rqp);
661681a5bbeSBoris Popov 	smb_rq_bstart(rqp);
662681a5bbeSBoris Popov 	mb_put_uint32le(mbp, 0);
663681a5bbeSBoris Popov 	smb_rq_bend(rqp);
664681a5bbeSBoris Popov 	error = smb_rq_simple(rqp);
665681a5bbeSBoris Popov 	SMBSDEBUG("%d\n", error);
666681a5bbeSBoris Popov 	smb_rq_done(rqp);
667681a5bbeSBoris Popov 	return error;
668681a5bbeSBoris Popov }
669