Thu Nov 29 00:04:37 2012 UTC ()
Pull up following revision(s) (requested by nakayama in ticket #725):
	sys/fs/smbfs/smbfs_smb.c: revision 1.43
	sys/netsmb/smb_smb.c: revision 1.33
- fix endian cofusion around FID, which is used as is, so no need
  to do byte swapping.
- put right value to ByteCount of SMB_COM_NT_CREATE_ANDX request.
The fix makes smbfs actually works on big-endian port.


(riz)
diff -r1.42 -r1.42.8.1 src/sys/fs/smbfs/smbfs_smb.c
diff -r1.32 -r1.32.18.1 src/sys/netsmb/smb_smb.c

cvs diff -r1.42 -r1.42.8.1 src/sys/fs/smbfs/Attic/smbfs_smb.c (expand / switch to unified diff)

--- src/sys/fs/smbfs/Attic/smbfs_smb.c 2011/09/27 02:05:10 1.42
+++ src/sys/fs/smbfs/Attic/smbfs_smb.c 2012/11/29 00:04:37 1.42.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: smbfs_smb.c,v 1.42 2011/09/27 02:05:10 christos Exp $ */ 1/* $NetBSD: smbfs_smb.c,v 1.42.8.1 2012/11/29 00:04:37 riz Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jaromir Dolecek. 8 * by Jaromir Dolecek.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -54,27 +54,27 @@ @@ -54,27 +54,27 @@
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE. 61 * SUCH DAMAGE.
62 * 62 *
63 * FreeBSD: src/sys/fs/smbfs/smbfs_smb.c,v 1.3 2001/12/10 08:09:46 obrien Exp 63 * FreeBSD: src/sys/fs/smbfs/smbfs_smb.c,v 1.3 2001/12/10 08:09:46 obrien Exp
64 */ 64 */
65 65
66#include <sys/cdefs.h> 66#include <sys/cdefs.h>
67__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.42 2011/09/27 02:05:10 christos Exp $"); 67__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.42.8.1 2012/11/29 00:04:37 riz Exp $");
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/systm.h> 70#include <sys/systm.h>
71#include <sys/kernel.h> 71#include <sys/kernel.h>
72#include <sys/malloc.h> 72#include <sys/malloc.h>
73#include <sys/proc.h> 73#include <sys/proc.h>
74#include <sys/lock.h> 74#include <sys/lock.h>
75#include <sys/vnode.h> 75#include <sys/vnode.h>
76#include <sys/mbuf.h> 76#include <sys/mbuf.h>
77#include <sys/mount.h> 77#include <sys/mount.h>
78 78
79#ifdef USE_MD5_HASH 79#ifdef USE_MD5_HASH
80#include <sys/md5.h> 80#include <sys/md5.h>
@@ -679,27 +679,27 @@ smbfs_smb_create(struct smbnode *dnp, co @@ -679,27 +679,27 @@ smbfs_smb_create(struct smbnode *dnp, co
679 mb_put_uint32le(mbp, tm); 679 mb_put_uint32le(mbp, tm);
680 smb_rq_wend(rqp); 680 smb_rq_wend(rqp);
681 681
682 smb_rq_bstart(rqp); 682 smb_rq_bstart(rqp);
683 mb_put_uint8(mbp, SMB_DT_ASCII); 683 mb_put_uint8(mbp, SMB_DT_ASCII);
684 error = smbfs_fullpath(mbp, SSTOVC(ssp), dnp, name, nmlen); 684 error = smbfs_fullpath(mbp, SSTOVC(ssp), dnp, name, nmlen);
685 if (!error) { 685 if (!error) {
686 smb_rq_bend(rqp); 686 smb_rq_bend(rqp);
687 error = smb_rq_simple(rqp); 687 error = smb_rq_simple(rqp);
688 if (!error) { 688 if (!error) {
689 smb_rq_getreply(rqp, &mdp); 689 smb_rq_getreply(rqp, &mdp);
690 md_get_uint8(mdp, &wc); 690 md_get_uint8(mdp, &wc);
691 if (wc == 1) 691 if (wc == 1)
692 md_get_uint16le(mdp, &fid); 692 md_get_uint16(mdp, &fid);
693 else 693 else
694 error = EBADRPC; 694 error = EBADRPC;
695 } 695 }
696 } 696 }
697 697
698 smb_rq_done(rqp); 698 smb_rq_done(rqp);
699 if (!error) 699 if (!error)
700 smbfs_smb_close(ssp, fid, &ctime, scred); 700 smbfs_smb_close(ssp, fid, &ctime, scred);
701 701
702 return (error); 702 return (error);
703} 703}
704 704
705int 705int
@@ -1412,39 +1412,38 @@ smbfs_smb_ntcreatex(struct smbnode *np,  @@ -1412,39 +1412,38 @@ smbfs_smb_ntcreatex(struct smbnode *np,
1412 mb_put_uint32le(mbp, 0); /* Hi 32bit */ 1412 mb_put_uint32le(mbp, 0); /* Hi 32bit */
1413 /* Initial allocation size */ 1413 /* Initial allocation size */
1414 mb_put_uint32le(mbp, 0); /* File attributes */ 1414 mb_put_uint32le(mbp, 0); /* File attributes */
1415 mb_put_uint32le(mbp, NT_FILE_SHARE_READ|NT_FILE_SHARE_WRITE); 1415 mb_put_uint32le(mbp, NT_FILE_SHARE_READ|NT_FILE_SHARE_WRITE);
1416 /* Type of share access */ 1416 /* Type of share access */
1417 mb_put_uint32le(mbp, NT_OPEN_EXISTING); 1417 mb_put_uint32le(mbp, NT_OPEN_EXISTING);
1418 /* Create disposition - just open */ 1418 /* Create disposition - just open */
1419 mb_put_uint32le(mbp, NT_FILE_DIRECTORY_FILE); 1419 mb_put_uint32le(mbp, NT_FILE_DIRECTORY_FILE);
1420 /* Options to use if creating a file */ 1420 /* Options to use if creating a file */
1421 mb_put_uint32le(mbp, 0); /* Security QOS information */ 1421 mb_put_uint32le(mbp, 0); /* Security QOS information */
1422 mb_put_uint8(mbp, 0); /* Security tracking mode flags */ 1422 mb_put_uint8(mbp, 0); /* Security tracking mode flags */
1423 smb_rq_wend(rqp); 1423 smb_rq_wend(rqp);
1424 smb_rq_bstart(rqp); 1424 smb_rq_bstart(rqp);
1425 smb_rq_bend(rqp); 
1426 mbp->mb_count = 0; 
1427 1425
1428 error = smbfs_fullpath(mbp, SSTOVC(ssp), np, NULL, 0); 1426 error = smbfs_fullpath(mbp, SSTOVC(ssp), np, NULL, 0);
1429 if (error) 1427 if (error)
1430 return error; 1428 return error;
1431 1429
1432 /* Windows XP seems to include the final zero. Better do that too. */ 1430 /* Windows XP seems to include the final zero. Better do that too. */
1433 mb_put_uint8(mbp, 0); 1431 mb_put_uint8(mbp, 0);
1434 1432
1435 flen = mbp->mb_count; 1433 flen = mbp->mb_count;
1436 SMBRQ_PUTLE16(nmlen, flen); 1434 SMBRQ_PUTLE16(nmlen, flen);
1437 1435
 1436 smb_rq_bend(rqp);
1438 error = smb_rq_simple(rqp); 1437 error = smb_rq_simple(rqp);
1439 if (error) 1438 if (error)
1440 goto bad; 1439 goto bad;
1441 1440
1442 smb_rq_getreply(rqp, &mdp); 1441 smb_rq_getreply(rqp, &mdp);
1443 md_get_uint8(mdp, &wc); /* WordCount - check? */ 1442 md_get_uint8(mdp, &wc); /* WordCount - check? */
1444 md_get_uint8(mdp, NULL); /* AndXCommand */ 1443 md_get_uint8(mdp, NULL); /* AndXCommand */
1445 md_get_uint8(mdp, NULL); /* Reserved - must be zero */ 1444 md_get_uint8(mdp, NULL); /* Reserved - must be zero */
1446 md_get_uint16(mdp, NULL); /* Offset to next cmd WordCount */ 1445 md_get_uint16(mdp, NULL); /* Offset to next cmd WordCount */
1447 md_get_uint8(mdp, NULL); /* Oplock level granted */ 1446 md_get_uint8(mdp, NULL); /* Oplock level granted */
1448 md_get_uint16(mdp, &np->n_fid); /* FID */ 1447 md_get_uint16(mdp, &np->n_fid); /* FID */
1449 /* ignore rest */ 1448 /* ignore rest */
1450 1449

cvs diff -r1.32 -r1.32.18.1 src/sys/netsmb/Attic/smb_smb.c (expand / switch to unified diff)

--- src/sys/netsmb/Attic/smb_smb.c 2009/10/18 23:20:31 1.32
+++ src/sys/netsmb/Attic/smb_smb.c 2012/11/29 00:04:37 1.32.18.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: smb_smb.c,v 1.32 2009/10/18 23:20:31 tron Exp $ */ 1/* $NetBSD: smb_smb.c,v 1.32.18.1 2012/11/29 00:04:37 riz Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000-2001 Boris Popov 4 * Copyright (c) 2000-2001 Boris Popov
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 * 33 *
34 * FreeBSD: src/sys/netsmb/smb_smb.c,v 1.10 2003/02/19 05:47:38 imp Exp 34 * FreeBSD: src/sys/netsmb/smb_smb.c,v 1.10 2003/02/19 05:47:38 imp Exp
35 */ 35 */
36/* 36/*
37 * various SMB requests. Most of the routines merely packs data into mbufs. 37 * various SMB requests. Most of the routines merely packs data into mbufs.
38 */ 38 */
39 39
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41__KERNEL_RCSID(0, "$NetBSD: smb_smb.c,v 1.32 2009/10/18 23:20:31 tron Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: smb_smb.c,v 1.32.18.1 2012/11/29 00:04:37 riz Exp $");
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/malloc.h> 46#include <sys/malloc.h>
47#include <sys/proc.h> 47#include <sys/proc.h>
48#include <sys/lock.h> 48#include <sys/lock.h>
49#include <sys/sysctl.h> 49#include <sys/sysctl.h>
50#include <sys/socket.h> 50#include <sys/socket.h>
51#include <sys/uio.h> 51#include <sys/uio.h>
52 52
53#include <netsmb/iconv.h> 53#include <netsmb/iconv.h>
54 54
@@ -165,27 +165,27 @@ smb_smb_negotiate(struct smb_vc *vcp, st @@ -165,27 +165,27 @@ smb_smb_negotiate(struct smb_vc *vcp, st
165 md_get_uint32le(mdp, &sp->sv_maxtx); 165 md_get_uint32le(mdp, &sp->sv_maxtx);
166 md_get_uint32le(mdp, &sp->sv_maxraw); 166 md_get_uint32le(mdp, &sp->sv_maxraw);
167 md_get_uint32le(mdp, &sp->sv_skey); 167 md_get_uint32le(mdp, &sp->sv_skey);
168 md_get_uint32le(mdp, &sp->sv_caps); 168 md_get_uint32le(mdp, &sp->sv_caps);
169 md_get_mem(mdp, stime, 8, MB_MSYSTEM); 169 md_get_mem(mdp, stime, 8, MB_MSYSTEM);
170 md_get_uint16le(mdp, &tw); 170 md_get_uint16le(mdp, &tw);
171 sp->sv_tz = tw; 171 sp->sv_tz = tw;
172 md_get_uint8(mdp, &sblen); 172 md_get_uint8(mdp, &sblen);
173 if (sblen && (sp->sv_sm & SMB_SM_ENCRYPT)) { 173 if (sblen && (sp->sv_sm & SMB_SM_ENCRYPT)) {
174 if (sblen != SMB_MAXCHALLENGELEN) { 174 if (sblen != SMB_MAXCHALLENGELEN) {
175 SMBERROR(("Unexpected length of security blob (%d)\n", sblen)); 175 SMBERROR(("Unexpected length of security blob (%d)\n", sblen));
176 break; 176 break;
177 } 177 }
178 error = md_get_uint16(mdp, &bc); 178 error = md_get_uint16le(mdp, &bc);
179 if (error) 179 if (error)
180 break; 180 break;
181 if (sp->sv_caps & SMB_CAP_EXT_SECURITY) 181 if (sp->sv_caps & SMB_CAP_EXT_SECURITY)
182 md_get_mem(mdp, NULL, 16, MB_MSYSTEM); 182 md_get_mem(mdp, NULL, 16, MB_MSYSTEM);
183 error = md_get_mem(mdp, vcp->vc_ch, sblen, MB_MSYSTEM); 183 error = md_get_mem(mdp, vcp->vc_ch, sblen, MB_MSYSTEM);
184 if (error) 184 if (error)
185 break; 185 break;
186 vcp->vc_chlen = sblen; 186 vcp->vc_chlen = sblen;
187 vcp->obj.co_flags |= SMBV_ENCRYPT; 187 vcp->obj.co_flags |= SMBV_ENCRYPT;
188 } 188 }
189 vcp->vc_hflags2 |= SMB_FLAGS2_KNOWS_LONG_NAMES; 189 vcp->vc_hflags2 |= SMB_FLAGS2_KNOWS_LONG_NAMES;
190 if (dp->d_id == SMB_DIALECT_NTLM0_12 && 190 if (dp->d_id == SMB_DIALECT_NTLM0_12 &&
191 sp->sv_maxtx < 4096 && 191 sp->sv_maxtx < 4096 &&
@@ -200,27 +200,27 @@ smb_smb_negotiate(struct smb_vc *vcp, st @@ -200,27 +200,27 @@ smb_smb_negotiate(struct smb_vc *vcp, st
200 md_get_uint16le(mdp, &sp->sv_maxmux); 200 md_get_uint16le(mdp, &sp->sv_maxmux);
201 md_get_uint16le(mdp, &sp->sv_maxvcs); 201 md_get_uint16le(mdp, &sp->sv_maxvcs);
202 md_get_uint16(mdp, NULL); /* rawmode */ 202 md_get_uint16(mdp, NULL); /* rawmode */
203 md_get_uint32le(mdp, &sp->sv_skey); 203 md_get_uint32le(mdp, &sp->sv_skey);
204 if (wc == 13) { /* >= LANMAN1 */ 204 if (wc == 13) { /* >= LANMAN1 */
205 md_get_uint16(mdp, NULL); /* time */ 205 md_get_uint16(mdp, NULL); /* time */
206 md_get_uint16(mdp, NULL); /* date */ 206 md_get_uint16(mdp, NULL); /* date */
207 md_get_uint16le(mdp, &tw); 207 md_get_uint16le(mdp, &tw);
208 sp->sv_tz = tw; 208 sp->sv_tz = tw;
209 md_get_uint16le(mdp, &swlen); 209 md_get_uint16le(mdp, &swlen);
210 if (swlen > SMB_MAXCHALLENGELEN) 210 if (swlen > SMB_MAXCHALLENGELEN)
211 break; 211 break;
212 md_get_uint16(mdp, NULL); /* mbz */ 212 md_get_uint16(mdp, NULL); /* mbz */
213 if (md_get_uint16(mdp, &bc) != 0) 213 if (md_get_uint16le(mdp, &bc) != 0)
214 break; 214 break;
215 if (bc < swlen) 215 if (bc < swlen)
216 break; 216 break;
217 if (swlen && (sp->sv_sm & SMB_SM_ENCRYPT)) { 217 if (swlen && (sp->sv_sm & SMB_SM_ENCRYPT)) {
218 error = md_get_mem(mdp, vcp->vc_ch, swlen, MB_MSYSTEM); 218 error = md_get_mem(mdp, vcp->vc_ch, swlen, MB_MSYSTEM);
219 if (error) 219 if (error)
220 break; 220 break;
221 vcp->vc_chlen = swlen; 221 vcp->vc_chlen = swlen;
222 vcp->obj.co_flags |= SMBV_ENCRYPT; 222 vcp->obj.co_flags |= SMBV_ENCRYPT;
223 } 223 }
224 } 224 }
225 vcp->vc_hflags2 |= SMB_FLAGS2_KNOWS_LONG_NAMES; 225 vcp->vc_hflags2 |= SMB_FLAGS2_KNOWS_LONG_NAMES;
226 } else { /* an old CORE protocol */ 226 } else { /* an old CORE protocol */