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/fs/smbfs/smbfs_smb.c,v 1.1.2.2 2003/01/17 08:20:26 tjr Exp $
33*86d7f5d3SJohn Marino * $DragonFly: src/sys/vfs/smbfs/smbfs_smb.c,v 1.11 2008/01/06 16:55:53 swildner Exp $
34*86d7f5d3SJohn Marino */
35*86d7f5d3SJohn Marino #include <sys/param.h>
36*86d7f5d3SJohn Marino #include <sys/systm.h>
37*86d7f5d3SJohn Marino #include <sys/kernel.h>
38*86d7f5d3SJohn Marino #include <sys/malloc.h>
39*86d7f5d3SJohn Marino #include <sys/proc.h>
40*86d7f5d3SJohn Marino #include <sys/lock.h>
41*86d7f5d3SJohn Marino #include <sys/vnode.h>
42*86d7f5d3SJohn Marino #include <sys/mbuf.h>
43*86d7f5d3SJohn Marino #include <sys/mount.h>
44*86d7f5d3SJohn Marino
45*86d7f5d3SJohn Marino #ifdef USE_MD5_HASH
46*86d7f5d3SJohn Marino #include <sys/md5.h>
47*86d7f5d3SJohn Marino #endif
48*86d7f5d3SJohn Marino
49*86d7f5d3SJohn Marino #include <netproto/smb/smb.h>
50*86d7f5d3SJohn Marino #include <netproto/smb/smb_subr.h>
51*86d7f5d3SJohn Marino #include <netproto/smb/smb_rq.h>
52*86d7f5d3SJohn Marino #include <netproto/smb/smb_conn.h>
53*86d7f5d3SJohn Marino
54*86d7f5d3SJohn Marino #include "smbfs.h"
55*86d7f5d3SJohn Marino #include "smbfs_node.h"
56*86d7f5d3SJohn Marino #include "smbfs_subr.h"
57*86d7f5d3SJohn Marino
58*86d7f5d3SJohn Marino /*
59*86d7f5d3SJohn Marino * Lack of inode numbers leads us to the problem of generating them.
60*86d7f5d3SJohn Marino * Partially this problem can be solved by having a dir/file cache
61*86d7f5d3SJohn Marino * with inode numbers generated from the incremented by one counter.
62*86d7f5d3SJohn Marino * However this way will require too much kernel memory, gives all
63*86d7f5d3SJohn Marino * sorts of locking and consistency problems, not to mentinon counter overflows.
64*86d7f5d3SJohn Marino * So, I'm decided to use a hash function to generate pseudo random (and unique)
65*86d7f5d3SJohn Marino * inode numbers.
66*86d7f5d3SJohn Marino */
67*86d7f5d3SJohn Marino static long
smbfs_getino(struct smbnode * dnp,const char * name,int nmlen)68*86d7f5d3SJohn Marino smbfs_getino(struct smbnode *dnp, const char *name, int nmlen)
69*86d7f5d3SJohn Marino {
70*86d7f5d3SJohn Marino #ifdef USE_MD5_HASH
71*86d7f5d3SJohn Marino MD5_CTX md5;
72*86d7f5d3SJohn Marino u_int32_t state[4];
73*86d7f5d3SJohn Marino long ino;
74*86d7f5d3SJohn Marino int i;
75*86d7f5d3SJohn Marino
76*86d7f5d3SJohn Marino MD5Init(&md5);
77*86d7f5d3SJohn Marino MD5Update(&md5, name, nmlen);
78*86d7f5d3SJohn Marino MD5Final((u_char *)state, &md5);
79*86d7f5d3SJohn Marino for (i = 0, ino = 0; i < 4; i++)
80*86d7f5d3SJohn Marino ino += state[i];
81*86d7f5d3SJohn Marino return dnp->n_ino + ino;
82*86d7f5d3SJohn Marino #endif
83*86d7f5d3SJohn Marino u_int32_t ino;
84*86d7f5d3SJohn Marino
85*86d7f5d3SJohn Marino ino = dnp->n_ino + smbfs_hash(name, nmlen);
86*86d7f5d3SJohn Marino if (ino <= 2)
87*86d7f5d3SJohn Marino ino += 3;
88*86d7f5d3SJohn Marino return ino;
89*86d7f5d3SJohn Marino }
90*86d7f5d3SJohn Marino
91*86d7f5d3SJohn Marino static int
smbfs_smb_lockandx(struct smbnode * np,int op,u_int32_t pid,off_t start,off_t end,struct smb_cred * scred)92*86d7f5d3SJohn Marino smbfs_smb_lockandx(struct smbnode *np, int op, u_int32_t pid, off_t start, off_t end,
93*86d7f5d3SJohn Marino struct smb_cred *scred)
94*86d7f5d3SJohn Marino {
95*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
96*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
97*86d7f5d3SJohn Marino struct mbchain *mbp;
98*86d7f5d3SJohn Marino u_char ltype = 0;
99*86d7f5d3SJohn Marino int error;
100*86d7f5d3SJohn Marino
101*86d7f5d3SJohn Marino if (op == SMB_LOCK_SHARED)
102*86d7f5d3SJohn Marino ltype |= SMB_LOCKING_ANDX_SHARED_LOCK;
103*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_LOCKING_ANDX, scred);
104*86d7f5d3SJohn Marino if (error)
105*86d7f5d3SJohn Marino return error;
106*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
107*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
108*86d7f5d3SJohn Marino mb_put_uint8(mbp, 0xff); /* secondary command */
109*86d7f5d3SJohn Marino mb_put_uint8(mbp, 0); /* MBZ */
110*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0);
111*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&np->n_fid, 2, MB_MSYSTEM);
112*86d7f5d3SJohn Marino mb_put_uint8(mbp, ltype); /* locktype */
113*86d7f5d3SJohn Marino mb_put_uint8(mbp, 0); /* oplocklevel - 0 seems is NO_OPLOCK */
114*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* timeout - break immediately */
115*86d7f5d3SJohn Marino mb_put_uint16le(mbp, op == SMB_LOCK_RELEASE ? 1 : 0);
116*86d7f5d3SJohn Marino mb_put_uint16le(mbp, op == SMB_LOCK_RELEASE ? 0 : 1);
117*86d7f5d3SJohn Marino smb_rq_wend(rqp);
118*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
119*86d7f5d3SJohn Marino mb_put_uint16le(mbp, pid);
120*86d7f5d3SJohn Marino mb_put_uint32le(mbp, start);
121*86d7f5d3SJohn Marino mb_put_uint32le(mbp, end - start);
122*86d7f5d3SJohn Marino smb_rq_bend(rqp);
123*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
124*86d7f5d3SJohn Marino smb_rq_done(rqp);
125*86d7f5d3SJohn Marino return error;
126*86d7f5d3SJohn Marino }
127*86d7f5d3SJohn Marino
128*86d7f5d3SJohn Marino int
smbfs_smb_lock(struct smbnode * np,int op,caddr_t id,off_t start,off_t end,struct smb_cred * scred)129*86d7f5d3SJohn Marino smbfs_smb_lock(struct smbnode *np, int op, caddr_t id,
130*86d7f5d3SJohn Marino off_t start, off_t end, struct smb_cred *scred)
131*86d7f5d3SJohn Marino {
132*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
133*86d7f5d3SJohn Marino
134*86d7f5d3SJohn Marino if (SMB_DIALECT(SSTOVC(ssp)) < SMB_DIALECT_LANMAN1_0)
135*86d7f5d3SJohn Marino /*
136*86d7f5d3SJohn Marino * TODO: use LOCK_BYTE_RANGE here.
137*86d7f5d3SJohn Marino */
138*86d7f5d3SJohn Marino return EINVAL;
139*86d7f5d3SJohn Marino else
140*86d7f5d3SJohn Marino return smbfs_smb_lockandx(np, op, (u_int32_t)(uintptr_t)id,
141*86d7f5d3SJohn Marino start, end, scred);
142*86d7f5d3SJohn Marino }
143*86d7f5d3SJohn Marino
144*86d7f5d3SJohn Marino int
smbfs_smb_statfs2(struct smb_share * ssp,struct statfs * sbp,struct smb_cred * scred)145*86d7f5d3SJohn Marino smbfs_smb_statfs2(struct smb_share *ssp, struct statfs *sbp,
146*86d7f5d3SJohn Marino struct smb_cred *scred)
147*86d7f5d3SJohn Marino {
148*86d7f5d3SJohn Marino struct smb_t2rq *t2p;
149*86d7f5d3SJohn Marino struct mbchain *mbp;
150*86d7f5d3SJohn Marino struct mdchain *mdp;
151*86d7f5d3SJohn Marino u_int16_t bsize;
152*86d7f5d3SJohn Marino u_int32_t units, bpu, funits;
153*86d7f5d3SJohn Marino int error;
154*86d7f5d3SJohn Marino
155*86d7f5d3SJohn Marino error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_QUERY_FS_INFORMATION,
156*86d7f5d3SJohn Marino scred, &t2p);
157*86d7f5d3SJohn Marino if (error)
158*86d7f5d3SJohn Marino return error;
159*86d7f5d3SJohn Marino mbp = &t2p->t2_tparam;
160*86d7f5d3SJohn Marino mb_init(mbp);
161*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_INFO_ALLOCATION);
162*86d7f5d3SJohn Marino t2p->t2_maxpcount = 4;
163*86d7f5d3SJohn Marino t2p->t2_maxdcount = 4 * 4 + 2;
164*86d7f5d3SJohn Marino error = smb_t2_request(t2p);
165*86d7f5d3SJohn Marino if (error) {
166*86d7f5d3SJohn Marino smb_t2_done(t2p);
167*86d7f5d3SJohn Marino return error;
168*86d7f5d3SJohn Marino }
169*86d7f5d3SJohn Marino mdp = &t2p->t2_rdata;
170*86d7f5d3SJohn Marino md_get_uint32(mdp, NULL); /* fs id */
171*86d7f5d3SJohn Marino md_get_uint32le(mdp, &bpu);
172*86d7f5d3SJohn Marino md_get_uint32le(mdp, &units);
173*86d7f5d3SJohn Marino md_get_uint32le(mdp, &funits);
174*86d7f5d3SJohn Marino md_get_uint16le(mdp, &bsize);
175*86d7f5d3SJohn Marino sbp->f_bsize = bpu * bsize; /* fundamental file system block size */
176*86d7f5d3SJohn Marino sbp->f_blocks= units; /* total data blocks in file system */
177*86d7f5d3SJohn Marino sbp->f_bfree = funits; /* free blocks in fs */
178*86d7f5d3SJohn Marino sbp->f_bavail= funits; /* free blocks avail to non-superuser */
179*86d7f5d3SJohn Marino sbp->f_files = 0xffff; /* total file nodes in file system */
180*86d7f5d3SJohn Marino sbp->f_ffree = 0xffff; /* free file nodes in fs */
181*86d7f5d3SJohn Marino smb_t2_done(t2p);
182*86d7f5d3SJohn Marino return 0;
183*86d7f5d3SJohn Marino }
184*86d7f5d3SJohn Marino
185*86d7f5d3SJohn Marino int
smbfs_smb_statfs(struct smb_share * ssp,struct statfs * sbp,struct smb_cred * scred)186*86d7f5d3SJohn Marino smbfs_smb_statfs(struct smb_share *ssp, struct statfs *sbp,
187*86d7f5d3SJohn Marino struct smb_cred *scred)
188*86d7f5d3SJohn Marino {
189*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
190*86d7f5d3SJohn Marino struct mdchain *mdp;
191*86d7f5d3SJohn Marino u_int16_t units, bpu, bsize, funits;
192*86d7f5d3SJohn Marino int error;
193*86d7f5d3SJohn Marino
194*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_QUERY_INFORMATION_DISK, scred);
195*86d7f5d3SJohn Marino if (error)
196*86d7f5d3SJohn Marino return error;
197*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
198*86d7f5d3SJohn Marino smb_rq_wend(rqp);
199*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
200*86d7f5d3SJohn Marino smb_rq_bend(rqp);
201*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
202*86d7f5d3SJohn Marino if (error) {
203*86d7f5d3SJohn Marino smb_rq_done(rqp);
204*86d7f5d3SJohn Marino return error;
205*86d7f5d3SJohn Marino }
206*86d7f5d3SJohn Marino smb_rq_getreply(rqp, &mdp);
207*86d7f5d3SJohn Marino md_get_uint16le(mdp, &units);
208*86d7f5d3SJohn Marino md_get_uint16le(mdp, &bpu);
209*86d7f5d3SJohn Marino md_get_uint16le(mdp, &bsize);
210*86d7f5d3SJohn Marino md_get_uint16le(mdp, &funits);
211*86d7f5d3SJohn Marino sbp->f_bsize = bpu * bsize; /* fundamental file system block size */
212*86d7f5d3SJohn Marino sbp->f_blocks= units; /* total data blocks in file system */
213*86d7f5d3SJohn Marino sbp->f_bfree = funits; /* free blocks in fs */
214*86d7f5d3SJohn Marino sbp->f_bavail= funits; /* free blocks avail to non-superuser */
215*86d7f5d3SJohn Marino sbp->f_files = 0xffff; /* total file nodes in file system */
216*86d7f5d3SJohn Marino sbp->f_ffree = 0xffff; /* free file nodes in fs */
217*86d7f5d3SJohn Marino smb_rq_done(rqp);
218*86d7f5d3SJohn Marino return 0;
219*86d7f5d3SJohn Marino }
220*86d7f5d3SJohn Marino
221*86d7f5d3SJohn Marino int
smbfs_smb_setfsize(struct smbnode * np,int newsize,struct smb_cred * scred)222*86d7f5d3SJohn Marino smbfs_smb_setfsize(struct smbnode *np, int newsize, struct smb_cred *scred)
223*86d7f5d3SJohn Marino {
224*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
225*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
226*86d7f5d3SJohn Marino struct mbchain *mbp;
227*86d7f5d3SJohn Marino int error;
228*86d7f5d3SJohn Marino
229*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_WRITE, scred);
230*86d7f5d3SJohn Marino if (error)
231*86d7f5d3SJohn Marino return error;
232*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
233*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
234*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&np->n_fid, 2, MB_MSYSTEM);
235*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0);
236*86d7f5d3SJohn Marino mb_put_uint32le(mbp, newsize);
237*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0);
238*86d7f5d3SJohn Marino smb_rq_wend(rqp);
239*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
240*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_DATA);
241*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0);
242*86d7f5d3SJohn Marino smb_rq_bend(rqp);
243*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
244*86d7f5d3SJohn Marino smb_rq_done(rqp);
245*86d7f5d3SJohn Marino return error;
246*86d7f5d3SJohn Marino }
247*86d7f5d3SJohn Marino
248*86d7f5d3SJohn Marino
249*86d7f5d3SJohn Marino /*
250*86d7f5d3SJohn Marino * Set DOS file attributes. mtime should be NULL for dialects above lm10
251*86d7f5d3SJohn Marino */
252*86d7f5d3SJohn Marino int
smbfs_smb_setpattr(struct smbnode * np,u_int16_t attr,struct timespec * mtime,struct smb_cred * scred)253*86d7f5d3SJohn Marino smbfs_smb_setpattr(struct smbnode *np, u_int16_t attr, struct timespec *mtime,
254*86d7f5d3SJohn Marino struct smb_cred *scred)
255*86d7f5d3SJohn Marino {
256*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
257*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
258*86d7f5d3SJohn Marino struct mbchain *mbp;
259*86d7f5d3SJohn Marino u_long time;
260*86d7f5d3SJohn Marino int error, svtz;
261*86d7f5d3SJohn Marino
262*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_SET_INFORMATION, scred);
263*86d7f5d3SJohn Marino if (error)
264*86d7f5d3SJohn Marino return error;
265*86d7f5d3SJohn Marino svtz = SSTOVC(ssp)->vc_sopt.sv_tz;
266*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
267*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
268*86d7f5d3SJohn Marino mb_put_uint16le(mbp, attr);
269*86d7f5d3SJohn Marino if (mtime) {
270*86d7f5d3SJohn Marino smb_time_local2server(mtime, svtz, &time);
271*86d7f5d3SJohn Marino } else
272*86d7f5d3SJohn Marino time = 0;
273*86d7f5d3SJohn Marino mb_put_uint32le(mbp, time); /* mtime */
274*86d7f5d3SJohn Marino mb_put_mem(mbp, NULL, 5 * 2, MB_MZERO);
275*86d7f5d3SJohn Marino smb_rq_wend(rqp);
276*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
277*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
278*86d7f5d3SJohn Marino do {
279*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), np, NULL, 0);
280*86d7f5d3SJohn Marino if (error)
281*86d7f5d3SJohn Marino break;
282*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
283*86d7f5d3SJohn Marino mb_put_uint8(mbp, 0);
284*86d7f5d3SJohn Marino smb_rq_bend(rqp);
285*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
286*86d7f5d3SJohn Marino SMBERROR("%d\n", error);
287*86d7f5d3SJohn Marino if (error)
288*86d7f5d3SJohn Marino break;
289*86d7f5d3SJohn Marino } while(0);
290*86d7f5d3SJohn Marino smb_rq_done(rqp);
291*86d7f5d3SJohn Marino return error;
292*86d7f5d3SJohn Marino }
293*86d7f5d3SJohn Marino
294*86d7f5d3SJohn Marino /*
295*86d7f5d3SJohn Marino * Note, win95 doesn't support this call.
296*86d7f5d3SJohn Marino */
297*86d7f5d3SJohn Marino int
smbfs_smb_setptime2(struct smbnode * np,struct timespec * mtime,struct timespec * atime,int attr,struct smb_cred * scred)298*86d7f5d3SJohn Marino smbfs_smb_setptime2(struct smbnode *np, struct timespec *mtime,
299*86d7f5d3SJohn Marino struct timespec *atime, int attr, struct smb_cred *scred)
300*86d7f5d3SJohn Marino {
301*86d7f5d3SJohn Marino struct smb_t2rq *t2p;
302*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
303*86d7f5d3SJohn Marino struct smb_vc *vcp = SSTOVC(ssp);
304*86d7f5d3SJohn Marino struct mbchain *mbp;
305*86d7f5d3SJohn Marino u_int16_t date, time;
306*86d7f5d3SJohn Marino int error, tzoff;
307*86d7f5d3SJohn Marino
308*86d7f5d3SJohn Marino error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_PATH_INFORMATION,
309*86d7f5d3SJohn Marino scred, &t2p);
310*86d7f5d3SJohn Marino if (error)
311*86d7f5d3SJohn Marino return error;
312*86d7f5d3SJohn Marino mbp = &t2p->t2_tparam;
313*86d7f5d3SJohn Marino mb_init(mbp);
314*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_INFO_STANDARD);
315*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* MBZ */
316*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, vcp, np, NULL, 0);
317*86d7f5d3SJohn Marino if (error) {
318*86d7f5d3SJohn Marino smb_t2_done(t2p);
319*86d7f5d3SJohn Marino return error;
320*86d7f5d3SJohn Marino }
321*86d7f5d3SJohn Marino tzoff = vcp->vc_sopt.sv_tz;
322*86d7f5d3SJohn Marino mbp = &t2p->t2_tdata;
323*86d7f5d3SJohn Marino mb_init(mbp);
324*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* creation time */
325*86d7f5d3SJohn Marino if (atime)
326*86d7f5d3SJohn Marino smb_time_unix2dos(atime, tzoff, &date, &time, NULL);
327*86d7f5d3SJohn Marino else
328*86d7f5d3SJohn Marino time = date = 0;
329*86d7f5d3SJohn Marino mb_put_uint16le(mbp, date);
330*86d7f5d3SJohn Marino mb_put_uint16le(mbp, time);
331*86d7f5d3SJohn Marino if (mtime)
332*86d7f5d3SJohn Marino smb_time_unix2dos(mtime, tzoff, &date, &time, NULL);
333*86d7f5d3SJohn Marino else
334*86d7f5d3SJohn Marino time = date = 0;
335*86d7f5d3SJohn Marino mb_put_uint16le(mbp, date);
336*86d7f5d3SJohn Marino mb_put_uint16le(mbp, time);
337*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* file size */
338*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* allocation unit size */
339*86d7f5d3SJohn Marino mb_put_uint16le(mbp, attr); /* DOS attr */
340*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* EA size */
341*86d7f5d3SJohn Marino t2p->t2_maxpcount = 5 * 2;
342*86d7f5d3SJohn Marino t2p->t2_maxdcount = vcp->vc_txmax;
343*86d7f5d3SJohn Marino error = smb_t2_request(t2p);
344*86d7f5d3SJohn Marino smb_t2_done(t2p);
345*86d7f5d3SJohn Marino return error;
346*86d7f5d3SJohn Marino }
347*86d7f5d3SJohn Marino
348*86d7f5d3SJohn Marino /*
349*86d7f5d3SJohn Marino * NT level. Specially for win9x
350*86d7f5d3SJohn Marino */
351*86d7f5d3SJohn Marino int
smbfs_smb_setpattrNT(struct smbnode * np,u_short attr,struct timespec * mtime,struct timespec * atime,struct smb_cred * scred)352*86d7f5d3SJohn Marino smbfs_smb_setpattrNT(struct smbnode *np, u_short attr, struct timespec *mtime,
353*86d7f5d3SJohn Marino struct timespec *atime, struct smb_cred *scred)
354*86d7f5d3SJohn Marino {
355*86d7f5d3SJohn Marino struct smb_t2rq *t2p;
356*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
357*86d7f5d3SJohn Marino struct smb_vc *vcp = SSTOVC(ssp);
358*86d7f5d3SJohn Marino struct mbchain *mbp;
359*86d7f5d3SJohn Marino int64_t tm;
360*86d7f5d3SJohn Marino int error, tzoff;
361*86d7f5d3SJohn Marino
362*86d7f5d3SJohn Marino error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_PATH_INFORMATION,
363*86d7f5d3SJohn Marino scred, &t2p);
364*86d7f5d3SJohn Marino if (error)
365*86d7f5d3SJohn Marino return error;
366*86d7f5d3SJohn Marino mbp = &t2p->t2_tparam;
367*86d7f5d3SJohn Marino mb_init(mbp);
368*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_SET_FILE_BASIC_INFO);
369*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* MBZ */
370*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, vcp, np, NULL, 0);
371*86d7f5d3SJohn Marino if (error) {
372*86d7f5d3SJohn Marino smb_t2_done(t2p);
373*86d7f5d3SJohn Marino return error;
374*86d7f5d3SJohn Marino }
375*86d7f5d3SJohn Marino tzoff = vcp->vc_sopt.sv_tz;
376*86d7f5d3SJohn Marino mbp = &t2p->t2_tdata;
377*86d7f5d3SJohn Marino mb_init(mbp);
378*86d7f5d3SJohn Marino mb_put_int64le(mbp, 0); /* creation time */
379*86d7f5d3SJohn Marino if (atime) {
380*86d7f5d3SJohn Marino smb_time_local2NT(atime, tzoff, &tm);
381*86d7f5d3SJohn Marino } else
382*86d7f5d3SJohn Marino tm = 0;
383*86d7f5d3SJohn Marino mb_put_int64le(mbp, tm);
384*86d7f5d3SJohn Marino if (mtime) {
385*86d7f5d3SJohn Marino smb_time_local2NT(mtime, tzoff, &tm);
386*86d7f5d3SJohn Marino } else
387*86d7f5d3SJohn Marino tm = 0;
388*86d7f5d3SJohn Marino mb_put_int64le(mbp, tm);
389*86d7f5d3SJohn Marino mb_put_int64le(mbp, tm); /* change time */
390*86d7f5d3SJohn Marino mb_put_uint32le(mbp, attr); /* attr */
391*86d7f5d3SJohn Marino t2p->t2_maxpcount = 24;
392*86d7f5d3SJohn Marino t2p->t2_maxdcount = 56;
393*86d7f5d3SJohn Marino error = smb_t2_request(t2p);
394*86d7f5d3SJohn Marino smb_t2_done(t2p);
395*86d7f5d3SJohn Marino return error;
396*86d7f5d3SJohn Marino }
397*86d7f5d3SJohn Marino
398*86d7f5d3SJohn Marino /*
399*86d7f5d3SJohn Marino * Set file atime and mtime. Doesn't supported by core dialect.
400*86d7f5d3SJohn Marino */
401*86d7f5d3SJohn Marino int
smbfs_smb_setftime(struct smbnode * np,struct timespec * mtime,struct timespec * atime,struct smb_cred * scred)402*86d7f5d3SJohn Marino smbfs_smb_setftime(struct smbnode *np, struct timespec *mtime,
403*86d7f5d3SJohn Marino struct timespec *atime, struct smb_cred *scred)
404*86d7f5d3SJohn Marino {
405*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
406*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
407*86d7f5d3SJohn Marino struct mbchain *mbp;
408*86d7f5d3SJohn Marino u_int16_t date, time;
409*86d7f5d3SJohn Marino int error, tzoff;
410*86d7f5d3SJohn Marino
411*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_SET_INFORMATION2, scred);
412*86d7f5d3SJohn Marino if (error)
413*86d7f5d3SJohn Marino return error;
414*86d7f5d3SJohn Marino tzoff = SSTOVC(ssp)->vc_sopt.sv_tz;
415*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
416*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
417*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&np->n_fid, 2, MB_MSYSTEM);
418*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* creation time */
419*86d7f5d3SJohn Marino
420*86d7f5d3SJohn Marino if (atime)
421*86d7f5d3SJohn Marino smb_time_unix2dos(atime, tzoff, &date, &time, NULL);
422*86d7f5d3SJohn Marino else
423*86d7f5d3SJohn Marino time = date = 0;
424*86d7f5d3SJohn Marino mb_put_uint16le(mbp, date);
425*86d7f5d3SJohn Marino mb_put_uint16le(mbp, time);
426*86d7f5d3SJohn Marino if (mtime)
427*86d7f5d3SJohn Marino smb_time_unix2dos(mtime, tzoff, &date, &time, NULL);
428*86d7f5d3SJohn Marino else
429*86d7f5d3SJohn Marino time = date = 0;
430*86d7f5d3SJohn Marino mb_put_uint16le(mbp, date);
431*86d7f5d3SJohn Marino mb_put_uint16le(mbp, time);
432*86d7f5d3SJohn Marino smb_rq_wend(rqp);
433*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
434*86d7f5d3SJohn Marino smb_rq_bend(rqp);
435*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
436*86d7f5d3SJohn Marino SMBSDEBUG("%d\n", error);
437*86d7f5d3SJohn Marino smb_rq_done(rqp);
438*86d7f5d3SJohn Marino return error;
439*86d7f5d3SJohn Marino }
440*86d7f5d3SJohn Marino
441*86d7f5d3SJohn Marino /*
442*86d7f5d3SJohn Marino * Set DOS file attributes.
443*86d7f5d3SJohn Marino * Looks like this call can be used only if CAP_NT_SMBS bit is on.
444*86d7f5d3SJohn Marino */
445*86d7f5d3SJohn Marino int
smbfs_smb_setfattrNT(struct smbnode * np,u_int16_t attr,struct timespec * mtime,struct timespec * atime,struct smb_cred * scred)446*86d7f5d3SJohn Marino smbfs_smb_setfattrNT(struct smbnode *np, u_int16_t attr, struct timespec *mtime,
447*86d7f5d3SJohn Marino struct timespec *atime, struct smb_cred *scred)
448*86d7f5d3SJohn Marino {
449*86d7f5d3SJohn Marino struct smb_t2rq *t2p;
450*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
451*86d7f5d3SJohn Marino struct mbchain *mbp;
452*86d7f5d3SJohn Marino int64_t tm;
453*86d7f5d3SJohn Marino int error, svtz;
454*86d7f5d3SJohn Marino
455*86d7f5d3SJohn Marino error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_FILE_INFORMATION,
456*86d7f5d3SJohn Marino scred, &t2p);
457*86d7f5d3SJohn Marino if (error)
458*86d7f5d3SJohn Marino return error;
459*86d7f5d3SJohn Marino svtz = SSTOVC(ssp)->vc_sopt.sv_tz;
460*86d7f5d3SJohn Marino mbp = &t2p->t2_tparam;
461*86d7f5d3SJohn Marino mb_init(mbp);
462*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&np->n_fid, 2, MB_MSYSTEM);
463*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_SET_FILE_BASIC_INFO);
464*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0);
465*86d7f5d3SJohn Marino mbp = &t2p->t2_tdata;
466*86d7f5d3SJohn Marino mb_init(mbp);
467*86d7f5d3SJohn Marino mb_put_int64le(mbp, 0); /* creation time */
468*86d7f5d3SJohn Marino if (atime) {
469*86d7f5d3SJohn Marino smb_time_local2NT(atime, svtz, &tm);
470*86d7f5d3SJohn Marino } else
471*86d7f5d3SJohn Marino tm = 0;
472*86d7f5d3SJohn Marino mb_put_int64le(mbp, tm);
473*86d7f5d3SJohn Marino if (mtime) {
474*86d7f5d3SJohn Marino smb_time_local2NT(mtime, svtz, &tm);
475*86d7f5d3SJohn Marino } else
476*86d7f5d3SJohn Marino tm = 0;
477*86d7f5d3SJohn Marino mb_put_int64le(mbp, tm);
478*86d7f5d3SJohn Marino mb_put_int64le(mbp, tm); /* change time */
479*86d7f5d3SJohn Marino mb_put_uint16le(mbp, attr);
480*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* padding */
481*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0);
482*86d7f5d3SJohn Marino t2p->t2_maxpcount = 2;
483*86d7f5d3SJohn Marino t2p->t2_maxdcount = 0;
484*86d7f5d3SJohn Marino error = smb_t2_request(t2p);
485*86d7f5d3SJohn Marino smb_t2_done(t2p);
486*86d7f5d3SJohn Marino return error;
487*86d7f5d3SJohn Marino }
488*86d7f5d3SJohn Marino
489*86d7f5d3SJohn Marino
490*86d7f5d3SJohn Marino int
smbfs_smb_open(struct smbnode * np,int accmode,struct smb_cred * scred)491*86d7f5d3SJohn Marino smbfs_smb_open(struct smbnode *np, int accmode, struct smb_cred *scred)
492*86d7f5d3SJohn Marino {
493*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
494*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
495*86d7f5d3SJohn Marino struct mbchain *mbp;
496*86d7f5d3SJohn Marino struct mdchain *mdp;
497*86d7f5d3SJohn Marino u_int8_t wc;
498*86d7f5d3SJohn Marino u_int16_t fid, wattr, grantedmode;
499*86d7f5d3SJohn Marino int error;
500*86d7f5d3SJohn Marino
501*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_OPEN, scred);
502*86d7f5d3SJohn Marino if (error)
503*86d7f5d3SJohn Marino return error;
504*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
505*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
506*86d7f5d3SJohn Marino mb_put_uint16le(mbp, accmode);
507*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_FA_SYSTEM | SMB_FA_HIDDEN);
508*86d7f5d3SJohn Marino smb_rq_wend(rqp);
509*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
510*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
511*86d7f5d3SJohn Marino do {
512*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), np, NULL, 0);
513*86d7f5d3SJohn Marino if (error)
514*86d7f5d3SJohn Marino break;
515*86d7f5d3SJohn Marino smb_rq_bend(rqp);
516*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
517*86d7f5d3SJohn Marino if (error)
518*86d7f5d3SJohn Marino break;
519*86d7f5d3SJohn Marino smb_rq_getreply(rqp, &mdp);
520*86d7f5d3SJohn Marino if (md_get_uint8(mdp, &wc) != 0 || wc != 7) {
521*86d7f5d3SJohn Marino error = EBADRPC;
522*86d7f5d3SJohn Marino break;
523*86d7f5d3SJohn Marino }
524*86d7f5d3SJohn Marino md_get_uint16(mdp, &fid);
525*86d7f5d3SJohn Marino md_get_uint16le(mdp, &wattr);
526*86d7f5d3SJohn Marino md_get_uint32(mdp, NULL); /* mtime */
527*86d7f5d3SJohn Marino md_get_uint32(mdp, NULL); /* fsize */
528*86d7f5d3SJohn Marino md_get_uint16le(mdp, &grantedmode);
529*86d7f5d3SJohn Marino /*
530*86d7f5d3SJohn Marino * TODO: refresh attributes from this reply
531*86d7f5d3SJohn Marino */
532*86d7f5d3SJohn Marino } while(0);
533*86d7f5d3SJohn Marino smb_rq_done(rqp);
534*86d7f5d3SJohn Marino if (error)
535*86d7f5d3SJohn Marino return error;
536*86d7f5d3SJohn Marino np->n_fid = fid;
537*86d7f5d3SJohn Marino np->n_rwstate = grantedmode;
538*86d7f5d3SJohn Marino return 0;
539*86d7f5d3SJohn Marino }
540*86d7f5d3SJohn Marino
541*86d7f5d3SJohn Marino
542*86d7f5d3SJohn Marino int
smbfs_smb_close(struct smb_share * ssp,u_int16_t fid,struct timespec * mtime,struct smb_cred * scred)543*86d7f5d3SJohn Marino smbfs_smb_close(struct smb_share *ssp, u_int16_t fid, struct timespec *mtime,
544*86d7f5d3SJohn Marino struct smb_cred *scred)
545*86d7f5d3SJohn Marino {
546*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
547*86d7f5d3SJohn Marino struct mbchain *mbp;
548*86d7f5d3SJohn Marino u_long time;
549*86d7f5d3SJohn Marino int error;
550*86d7f5d3SJohn Marino
551*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_CLOSE, scred);
552*86d7f5d3SJohn Marino if (error)
553*86d7f5d3SJohn Marino return error;
554*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
555*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
556*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&fid, sizeof(fid), MB_MSYSTEM);
557*86d7f5d3SJohn Marino if (mtime) {
558*86d7f5d3SJohn Marino smb_time_local2server(mtime, SSTOVC(ssp)->vc_sopt.sv_tz, &time);
559*86d7f5d3SJohn Marino } else
560*86d7f5d3SJohn Marino time = 0;
561*86d7f5d3SJohn Marino mb_put_uint32le(mbp, time);
562*86d7f5d3SJohn Marino smb_rq_wend(rqp);
563*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
564*86d7f5d3SJohn Marino smb_rq_bend(rqp);
565*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
566*86d7f5d3SJohn Marino smb_rq_done(rqp);
567*86d7f5d3SJohn Marino return error;
568*86d7f5d3SJohn Marino }
569*86d7f5d3SJohn Marino
570*86d7f5d3SJohn Marino int
smbfs_smb_create(struct smbnode * dnp,const char * name,int nmlen,struct smb_cred * scred)571*86d7f5d3SJohn Marino smbfs_smb_create(struct smbnode *dnp, const char *name, int nmlen,
572*86d7f5d3SJohn Marino struct smb_cred *scred)
573*86d7f5d3SJohn Marino {
574*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
575*86d7f5d3SJohn Marino struct smb_share *ssp = dnp->n_mount->sm_share;
576*86d7f5d3SJohn Marino struct mbchain *mbp;
577*86d7f5d3SJohn Marino struct mdchain *mdp;
578*86d7f5d3SJohn Marino struct timespec ctime;
579*86d7f5d3SJohn Marino u_int8_t wc;
580*86d7f5d3SJohn Marino u_int16_t fid;
581*86d7f5d3SJohn Marino u_long tm;
582*86d7f5d3SJohn Marino int error;
583*86d7f5d3SJohn Marino
584*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_CREATE, scred);
585*86d7f5d3SJohn Marino if (error)
586*86d7f5d3SJohn Marino return error;
587*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
588*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
589*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_FA_ARCHIVE); /* attributes */
590*86d7f5d3SJohn Marino nanotime(&ctime);
591*86d7f5d3SJohn Marino smb_time_local2server(&ctime, SSTOVC(ssp)->vc_sopt.sv_tz, &tm);
592*86d7f5d3SJohn Marino mb_put_uint32le(mbp, tm);
593*86d7f5d3SJohn Marino smb_rq_wend(rqp);
594*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
595*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
596*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), dnp, name, nmlen);
597*86d7f5d3SJohn Marino if (!error) {
598*86d7f5d3SJohn Marino smb_rq_bend(rqp);
599*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
600*86d7f5d3SJohn Marino if (!error) {
601*86d7f5d3SJohn Marino smb_rq_getreply(rqp, &mdp);
602*86d7f5d3SJohn Marino md_get_uint8(mdp, &wc);
603*86d7f5d3SJohn Marino if (wc == 1)
604*86d7f5d3SJohn Marino md_get_uint16(mdp, &fid);
605*86d7f5d3SJohn Marino else
606*86d7f5d3SJohn Marino error = EBADRPC;
607*86d7f5d3SJohn Marino }
608*86d7f5d3SJohn Marino }
609*86d7f5d3SJohn Marino smb_rq_done(rqp);
610*86d7f5d3SJohn Marino if (error)
611*86d7f5d3SJohn Marino return error;
612*86d7f5d3SJohn Marino smbfs_smb_close(ssp, fid, &ctime, scred);
613*86d7f5d3SJohn Marino return error;
614*86d7f5d3SJohn Marino }
615*86d7f5d3SJohn Marino
616*86d7f5d3SJohn Marino int
smbfs_smb_delete(struct smbnode * np,struct smb_cred * scred)617*86d7f5d3SJohn Marino smbfs_smb_delete(struct smbnode *np, struct smb_cred *scred)
618*86d7f5d3SJohn Marino {
619*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
620*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
621*86d7f5d3SJohn Marino struct mbchain *mbp;
622*86d7f5d3SJohn Marino int error;
623*86d7f5d3SJohn Marino
624*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_DELETE, scred);
625*86d7f5d3SJohn Marino if (error)
626*86d7f5d3SJohn Marino return error;
627*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
628*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
629*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_FA_SYSTEM | SMB_FA_HIDDEN);
630*86d7f5d3SJohn Marino smb_rq_wend(rqp);
631*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
632*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
633*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), np, NULL, 0);
634*86d7f5d3SJohn Marino if (!error) {
635*86d7f5d3SJohn Marino smb_rq_bend(rqp);
636*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
637*86d7f5d3SJohn Marino }
638*86d7f5d3SJohn Marino smb_rq_done(rqp);
639*86d7f5d3SJohn Marino return error;
640*86d7f5d3SJohn Marino }
641*86d7f5d3SJohn Marino
642*86d7f5d3SJohn Marino int
smbfs_smb_rename(struct smbnode * src,struct smbnode * tdnp,const char * tname,int tnmlen,struct smb_cred * scred)643*86d7f5d3SJohn Marino smbfs_smb_rename(struct smbnode *src, struct smbnode *tdnp,
644*86d7f5d3SJohn Marino const char *tname, int tnmlen, struct smb_cred *scred)
645*86d7f5d3SJohn Marino {
646*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
647*86d7f5d3SJohn Marino struct smb_share *ssp = src->n_mount->sm_share;
648*86d7f5d3SJohn Marino struct mbchain *mbp;
649*86d7f5d3SJohn Marino int error;
650*86d7f5d3SJohn Marino
651*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_RENAME, scred);
652*86d7f5d3SJohn Marino if (error)
653*86d7f5d3SJohn Marino return error;
654*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
655*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
656*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_FA_SYSTEM | SMB_FA_HIDDEN);
657*86d7f5d3SJohn Marino smb_rq_wend(rqp);
658*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
659*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
660*86d7f5d3SJohn Marino do {
661*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), src, NULL, 0);
662*86d7f5d3SJohn Marino if (error)
663*86d7f5d3SJohn Marino break;
664*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
665*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), tdnp, tname, tnmlen);
666*86d7f5d3SJohn Marino if (error)
667*86d7f5d3SJohn Marino break;
668*86d7f5d3SJohn Marino smb_rq_bend(rqp);
669*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
670*86d7f5d3SJohn Marino } while(0);
671*86d7f5d3SJohn Marino smb_rq_done(rqp);
672*86d7f5d3SJohn Marino return error;
673*86d7f5d3SJohn Marino }
674*86d7f5d3SJohn Marino
675*86d7f5d3SJohn Marino int
smbfs_smb_move(struct smbnode * src,struct smbnode * tdnp,const char * tname,int tnmlen,u_int16_t flags,struct smb_cred * scred)676*86d7f5d3SJohn Marino smbfs_smb_move(struct smbnode *src, struct smbnode *tdnp,
677*86d7f5d3SJohn Marino const char *tname, int tnmlen, u_int16_t flags, struct smb_cred *scred)
678*86d7f5d3SJohn Marino {
679*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
680*86d7f5d3SJohn Marino struct smb_share *ssp = src->n_mount->sm_share;
681*86d7f5d3SJohn Marino struct mbchain *mbp;
682*86d7f5d3SJohn Marino int error;
683*86d7f5d3SJohn Marino
684*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_MOVE, scred);
685*86d7f5d3SJohn Marino if (error)
686*86d7f5d3SJohn Marino return error;
687*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
688*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
689*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_TID_UNKNOWN);
690*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0x20); /* delete target file */
691*86d7f5d3SJohn Marino mb_put_uint16le(mbp, flags);
692*86d7f5d3SJohn Marino smb_rq_wend(rqp);
693*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
694*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
695*86d7f5d3SJohn Marino do {
696*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), src, NULL, 0);
697*86d7f5d3SJohn Marino if (error)
698*86d7f5d3SJohn Marino break;
699*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
700*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), tdnp, tname, tnmlen);
701*86d7f5d3SJohn Marino if (error)
702*86d7f5d3SJohn Marino break;
703*86d7f5d3SJohn Marino smb_rq_bend(rqp);
704*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
705*86d7f5d3SJohn Marino } while(0);
706*86d7f5d3SJohn Marino smb_rq_done(rqp);
707*86d7f5d3SJohn Marino return error;
708*86d7f5d3SJohn Marino }
709*86d7f5d3SJohn Marino
710*86d7f5d3SJohn Marino int
smbfs_smb_mkdir(struct smbnode * dnp,const char * name,int len,struct smb_cred * scred)711*86d7f5d3SJohn Marino smbfs_smb_mkdir(struct smbnode *dnp, const char *name, int len,
712*86d7f5d3SJohn Marino struct smb_cred *scred)
713*86d7f5d3SJohn Marino {
714*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
715*86d7f5d3SJohn Marino struct smb_share *ssp = dnp->n_mount->sm_share;
716*86d7f5d3SJohn Marino struct mbchain *mbp;
717*86d7f5d3SJohn Marino int error;
718*86d7f5d3SJohn Marino
719*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_CREATE_DIRECTORY, scred);
720*86d7f5d3SJohn Marino if (error)
721*86d7f5d3SJohn Marino return error;
722*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
723*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
724*86d7f5d3SJohn Marino smb_rq_wend(rqp);
725*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
726*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
727*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), dnp, name, len);
728*86d7f5d3SJohn Marino if (!error) {
729*86d7f5d3SJohn Marino smb_rq_bend(rqp);
730*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
731*86d7f5d3SJohn Marino }
732*86d7f5d3SJohn Marino smb_rq_done(rqp);
733*86d7f5d3SJohn Marino return error;
734*86d7f5d3SJohn Marino }
735*86d7f5d3SJohn Marino
736*86d7f5d3SJohn Marino int
smbfs_smb_rmdir(struct smbnode * np,struct smb_cred * scred)737*86d7f5d3SJohn Marino smbfs_smb_rmdir(struct smbnode *np, struct smb_cred *scred)
738*86d7f5d3SJohn Marino {
739*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
740*86d7f5d3SJohn Marino struct smb_share *ssp = np->n_mount->sm_share;
741*86d7f5d3SJohn Marino struct mbchain *mbp;
742*86d7f5d3SJohn Marino int error;
743*86d7f5d3SJohn Marino
744*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ssp), SMB_COM_DELETE_DIRECTORY, scred);
745*86d7f5d3SJohn Marino if (error)
746*86d7f5d3SJohn Marino return error;
747*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
748*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
749*86d7f5d3SJohn Marino smb_rq_wend(rqp);
750*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
751*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII);
752*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, SSTOVC(ssp), np, NULL, 0);
753*86d7f5d3SJohn Marino if (!error) {
754*86d7f5d3SJohn Marino smb_rq_bend(rqp);
755*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
756*86d7f5d3SJohn Marino }
757*86d7f5d3SJohn Marino smb_rq_done(rqp);
758*86d7f5d3SJohn Marino return error;
759*86d7f5d3SJohn Marino }
760*86d7f5d3SJohn Marino
761*86d7f5d3SJohn Marino static int
smbfs_smb_search(struct smbfs_fctx * ctx)762*86d7f5d3SJohn Marino smbfs_smb_search(struct smbfs_fctx *ctx)
763*86d7f5d3SJohn Marino {
764*86d7f5d3SJohn Marino struct smb_vc *vcp = SSTOVC(ctx->f_ssp);
765*86d7f5d3SJohn Marino struct smb_rq *rqp;
766*86d7f5d3SJohn Marino struct mbchain *mbp;
767*86d7f5d3SJohn Marino struct mdchain *mdp;
768*86d7f5d3SJohn Marino u_int8_t wc, bt;
769*86d7f5d3SJohn Marino u_int16_t ec, dlen, bc;
770*86d7f5d3SJohn Marino int maxent, error, iseof = 0;
771*86d7f5d3SJohn Marino
772*86d7f5d3SJohn Marino maxent = min(ctx->f_left, (vcp->vc_txmax - SMB_HDRLEN - 3) / SMB_DENTRYLEN);
773*86d7f5d3SJohn Marino if (ctx->f_rq) {
774*86d7f5d3SJohn Marino smb_rq_done(ctx->f_rq);
775*86d7f5d3SJohn Marino ctx->f_rq = NULL;
776*86d7f5d3SJohn Marino }
777*86d7f5d3SJohn Marino error = smb_rq_alloc(SSTOCP(ctx->f_ssp), SMB_COM_SEARCH, ctx->f_scred, &rqp);
778*86d7f5d3SJohn Marino if (error)
779*86d7f5d3SJohn Marino return error;
780*86d7f5d3SJohn Marino ctx->f_rq = rqp;
781*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
782*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
783*86d7f5d3SJohn Marino mb_put_uint16le(mbp, maxent); /* max entries to return */
784*86d7f5d3SJohn Marino mb_put_uint16le(mbp, ctx->f_attrmask);
785*86d7f5d3SJohn Marino smb_rq_wend(rqp);
786*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
787*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_ASCII); /* buffer format */
788*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_FINDFIRST) {
789*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, vcp, ctx->f_dnp, ctx->f_wildcard, ctx->f_wclen);
790*86d7f5d3SJohn Marino if (error)
791*86d7f5d3SJohn Marino return error;
792*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_VARIABLE);
793*86d7f5d3SJohn Marino mb_put_uint16le(mbp, 0); /* context length */
794*86d7f5d3SJohn Marino ctx->f_flags &= ~SMBFS_RDD_FINDFIRST;
795*86d7f5d3SJohn Marino } else {
796*86d7f5d3SJohn Marino mb_put_uint8(mbp, 0); /* file name length */
797*86d7f5d3SJohn Marino mb_put_uint8(mbp, SMB_DT_VARIABLE);
798*86d7f5d3SJohn Marino mb_put_uint16le(mbp, SMB_SKEYLEN);
799*86d7f5d3SJohn Marino mb_put_mem(mbp, ctx->f_skey, SMB_SKEYLEN, MB_MSYSTEM);
800*86d7f5d3SJohn Marino }
801*86d7f5d3SJohn Marino smb_rq_bend(rqp);
802*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
803*86d7f5d3SJohn Marino if (error) {
804*86d7f5d3SJohn Marino if (rqp->sr_errclass == ERRDOS && rqp->sr_serror == ERRnofiles) {
805*86d7f5d3SJohn Marino error = 0;
806*86d7f5d3SJohn Marino iseof = 1;
807*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_EOF;
808*86d7f5d3SJohn Marino } else
809*86d7f5d3SJohn Marino return error;
810*86d7f5d3SJohn Marino }
811*86d7f5d3SJohn Marino smb_rq_getreply(rqp, &mdp);
812*86d7f5d3SJohn Marino md_get_uint8(mdp, &wc);
813*86d7f5d3SJohn Marino if (wc != 1)
814*86d7f5d3SJohn Marino return iseof ? ENOENT : EBADRPC;
815*86d7f5d3SJohn Marino md_get_uint16le(mdp, &ec);
816*86d7f5d3SJohn Marino if (ec == 0)
817*86d7f5d3SJohn Marino return ENOENT;
818*86d7f5d3SJohn Marino ctx->f_ecnt = ec;
819*86d7f5d3SJohn Marino md_get_uint16le(mdp, &bc);
820*86d7f5d3SJohn Marino if (bc < 3)
821*86d7f5d3SJohn Marino return EBADRPC;
822*86d7f5d3SJohn Marino bc -= 3;
823*86d7f5d3SJohn Marino md_get_uint8(mdp, &bt);
824*86d7f5d3SJohn Marino if (bt != SMB_DT_VARIABLE)
825*86d7f5d3SJohn Marino return EBADRPC;
826*86d7f5d3SJohn Marino md_get_uint16le(mdp, &dlen);
827*86d7f5d3SJohn Marino if (dlen != bc || dlen % SMB_DENTRYLEN != 0)
828*86d7f5d3SJohn Marino return EBADRPC;
829*86d7f5d3SJohn Marino return 0;
830*86d7f5d3SJohn Marino }
831*86d7f5d3SJohn Marino
832*86d7f5d3SJohn Marino static int
smbfs_findopenLM1(struct smbfs_fctx * ctx,struct smbnode * dnp,const char * wildcard,int wclen,int attr,struct smb_cred * scred)833*86d7f5d3SJohn Marino smbfs_findopenLM1(struct smbfs_fctx *ctx, struct smbnode *dnp,
834*86d7f5d3SJohn Marino const char *wildcard, int wclen, int attr, struct smb_cred *scred)
835*86d7f5d3SJohn Marino {
836*86d7f5d3SJohn Marino ctx->f_attrmask = attr;
837*86d7f5d3SJohn Marino if (wildcard) {
838*86d7f5d3SJohn Marino if (wclen == 1 && wildcard[0] == '*') {
839*86d7f5d3SJohn Marino ctx->f_wildcard = "*.*";
840*86d7f5d3SJohn Marino ctx->f_wclen = 3;
841*86d7f5d3SJohn Marino } else {
842*86d7f5d3SJohn Marino ctx->f_wildcard = wildcard;
843*86d7f5d3SJohn Marino ctx->f_wclen = wclen;
844*86d7f5d3SJohn Marino }
845*86d7f5d3SJohn Marino } else {
846*86d7f5d3SJohn Marino ctx->f_wildcard = NULL;
847*86d7f5d3SJohn Marino ctx->f_wclen = 0;
848*86d7f5d3SJohn Marino }
849*86d7f5d3SJohn Marino ctx->f_name = ctx->f_fname;
850*86d7f5d3SJohn Marino return 0;
851*86d7f5d3SJohn Marino }
852*86d7f5d3SJohn Marino
853*86d7f5d3SJohn Marino static int
smbfs_findnextLM1(struct smbfs_fctx * ctx,int limit)854*86d7f5d3SJohn Marino smbfs_findnextLM1(struct smbfs_fctx *ctx, int limit)
855*86d7f5d3SJohn Marino {
856*86d7f5d3SJohn Marino struct mdchain *mbp;
857*86d7f5d3SJohn Marino struct smb_rq *rqp;
858*86d7f5d3SJohn Marino char *cp;
859*86d7f5d3SJohn Marino u_int8_t battr;
860*86d7f5d3SJohn Marino u_int16_t date, time;
861*86d7f5d3SJohn Marino u_int32_t size;
862*86d7f5d3SJohn Marino int error;
863*86d7f5d3SJohn Marino
864*86d7f5d3SJohn Marino if (ctx->f_ecnt == 0) {
865*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_EOF)
866*86d7f5d3SJohn Marino return ENOENT;
867*86d7f5d3SJohn Marino ctx->f_left = ctx->f_limit = limit;
868*86d7f5d3SJohn Marino error = smbfs_smb_search(ctx);
869*86d7f5d3SJohn Marino if (error)
870*86d7f5d3SJohn Marino return error;
871*86d7f5d3SJohn Marino }
872*86d7f5d3SJohn Marino rqp = ctx->f_rq;
873*86d7f5d3SJohn Marino smb_rq_getreply(rqp, &mbp);
874*86d7f5d3SJohn Marino md_get_mem(mbp, ctx->f_skey, SMB_SKEYLEN, MB_MSYSTEM);
875*86d7f5d3SJohn Marino md_get_uint8(mbp, &battr);
876*86d7f5d3SJohn Marino md_get_uint16le(mbp, &time);
877*86d7f5d3SJohn Marino md_get_uint16le(mbp, &date);
878*86d7f5d3SJohn Marino md_get_uint32le(mbp, &size);
879*86d7f5d3SJohn Marino cp = ctx->f_name;
880*86d7f5d3SJohn Marino md_get_mem(mbp, cp, sizeof(ctx->f_fname), MB_MSYSTEM);
881*86d7f5d3SJohn Marino cp[sizeof(ctx->f_fname) - 1] = 0;
882*86d7f5d3SJohn Marino cp += strlen(cp) - 1;
883*86d7f5d3SJohn Marino while (*cp == ' ' && cp >= ctx->f_name)
884*86d7f5d3SJohn Marino *cp-- = 0;
885*86d7f5d3SJohn Marino ctx->f_attr.fa_attr = battr;
886*86d7f5d3SJohn Marino smb_dos2unixtime(date, time, 0, rqp->sr_vc->vc_sopt.sv_tz,
887*86d7f5d3SJohn Marino &ctx->f_attr.fa_mtime);
888*86d7f5d3SJohn Marino ctx->f_attr.fa_size = size;
889*86d7f5d3SJohn Marino ctx->f_nmlen = strlen(ctx->f_name);
890*86d7f5d3SJohn Marino ctx->f_ecnt--;
891*86d7f5d3SJohn Marino ctx->f_left--;
892*86d7f5d3SJohn Marino return 0;
893*86d7f5d3SJohn Marino }
894*86d7f5d3SJohn Marino
895*86d7f5d3SJohn Marino static int
smbfs_findcloseLM1(struct smbfs_fctx * ctx)896*86d7f5d3SJohn Marino smbfs_findcloseLM1(struct smbfs_fctx *ctx)
897*86d7f5d3SJohn Marino {
898*86d7f5d3SJohn Marino if (ctx->f_rq)
899*86d7f5d3SJohn Marino smb_rq_done(ctx->f_rq);
900*86d7f5d3SJohn Marino return 0;
901*86d7f5d3SJohn Marino }
902*86d7f5d3SJohn Marino
903*86d7f5d3SJohn Marino /*
904*86d7f5d3SJohn Marino * TRANS2_FIND_FIRST2/NEXT2, used for NT LM12 dialect
905*86d7f5d3SJohn Marino */
906*86d7f5d3SJohn Marino static int
smbfs_smb_trans2find2(struct smbfs_fctx * ctx)907*86d7f5d3SJohn Marino smbfs_smb_trans2find2(struct smbfs_fctx *ctx)
908*86d7f5d3SJohn Marino {
909*86d7f5d3SJohn Marino struct smb_t2rq *t2p;
910*86d7f5d3SJohn Marino struct smb_vc *vcp = SSTOVC(ctx->f_ssp);
911*86d7f5d3SJohn Marino struct mbchain *mbp;
912*86d7f5d3SJohn Marino struct mdchain *mdp;
913*86d7f5d3SJohn Marino u_int16_t tw, flags;
914*86d7f5d3SJohn Marino int error;
915*86d7f5d3SJohn Marino
916*86d7f5d3SJohn Marino if (ctx->f_t2) {
917*86d7f5d3SJohn Marino smb_t2_done(ctx->f_t2);
918*86d7f5d3SJohn Marino ctx->f_t2 = NULL;
919*86d7f5d3SJohn Marino }
920*86d7f5d3SJohn Marino ctx->f_flags &= ~SMBFS_RDD_GOTRNAME;
921*86d7f5d3SJohn Marino flags = 8 | 2; /* <resume> | <close if EOS> */
922*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_FINDSINGLE) {
923*86d7f5d3SJohn Marino flags |= 1; /* close search after this request */
924*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_NOCLOSE;
925*86d7f5d3SJohn Marino }
926*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_FINDFIRST) {
927*86d7f5d3SJohn Marino error = smb_t2_alloc(SSTOCP(ctx->f_ssp), SMB_TRANS2_FIND_FIRST2,
928*86d7f5d3SJohn Marino ctx->f_scred, &t2p);
929*86d7f5d3SJohn Marino if (error)
930*86d7f5d3SJohn Marino return error;
931*86d7f5d3SJohn Marino ctx->f_t2 = t2p;
932*86d7f5d3SJohn Marino mbp = &t2p->t2_tparam;
933*86d7f5d3SJohn Marino mb_init(mbp);
934*86d7f5d3SJohn Marino mb_put_uint16le(mbp, ctx->f_attrmask);
935*86d7f5d3SJohn Marino mb_put_uint16le(mbp, ctx->f_limit);
936*86d7f5d3SJohn Marino mb_put_uint16le(mbp, flags);
937*86d7f5d3SJohn Marino mb_put_uint16le(mbp, ctx->f_infolevel);
938*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0);
939*86d7f5d3SJohn Marino error = smbfs_fullpath(mbp, vcp, ctx->f_dnp, ctx->f_wildcard, ctx->f_wclen);
940*86d7f5d3SJohn Marino if (error)
941*86d7f5d3SJohn Marino return error;
942*86d7f5d3SJohn Marino } else {
943*86d7f5d3SJohn Marino error = smb_t2_alloc(SSTOCP(ctx->f_ssp), SMB_TRANS2_FIND_NEXT2,
944*86d7f5d3SJohn Marino ctx->f_scred, &t2p);
945*86d7f5d3SJohn Marino if (error)
946*86d7f5d3SJohn Marino return error;
947*86d7f5d3SJohn Marino ctx->f_t2 = t2p;
948*86d7f5d3SJohn Marino mbp = &t2p->t2_tparam;
949*86d7f5d3SJohn Marino mb_init(mbp);
950*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&ctx->f_Sid, 2, MB_MSYSTEM);
951*86d7f5d3SJohn Marino mb_put_uint16le(mbp, ctx->f_limit);
952*86d7f5d3SJohn Marino mb_put_uint16le(mbp, ctx->f_infolevel);
953*86d7f5d3SJohn Marino mb_put_uint32le(mbp, 0); /* resume key */
954*86d7f5d3SJohn Marino mb_put_uint16le(mbp, flags);
955*86d7f5d3SJohn Marino if (ctx->f_rname)
956*86d7f5d3SJohn Marino mb_put_mem(mbp, ctx->f_rname, strlen(ctx->f_rname) + 1, MB_MSYSTEM);
957*86d7f5d3SJohn Marino else
958*86d7f5d3SJohn Marino mb_put_uint8(mbp, 0); /* resume file name */
959*86d7f5d3SJohn Marino #if 0
960*86d7f5d3SJohn Marino struct timeval tv;
961*86d7f5d3SJohn Marino tv.tv_sec = 0;
962*86d7f5d3SJohn Marino tv.tv_usec = 200 * 1000; /* 200ms */
963*86d7f5d3SJohn Marino if (vcp->vc_flags & SMBC_WIN95) {
964*86d7f5d3SJohn Marino /*
965*86d7f5d3SJohn Marino * some implementations suggests to sleep here
966*86d7f5d3SJohn Marino * for 200ms, due to the bug in the Win95.
967*86d7f5d3SJohn Marino * I've didn't notice any problem, but put code
968*86d7f5d3SJohn Marino * for it.
969*86d7f5d3SJohn Marino */
970*86d7f5d3SJohn Marino tsleep(&flags, 0, "fix95", tvtohz_high(&tv));
971*86d7f5d3SJohn Marino }
972*86d7f5d3SJohn Marino #endif
973*86d7f5d3SJohn Marino }
974*86d7f5d3SJohn Marino t2p->t2_maxpcount = 5 * 2;
975*86d7f5d3SJohn Marino t2p->t2_maxdcount = vcp->vc_txmax;
976*86d7f5d3SJohn Marino error = smb_t2_request(t2p);
977*86d7f5d3SJohn Marino if (error)
978*86d7f5d3SJohn Marino return error;
979*86d7f5d3SJohn Marino mdp = &t2p->t2_rparam;
980*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_FINDFIRST) {
981*86d7f5d3SJohn Marino if ((error = md_get_uint16(mdp, &ctx->f_Sid)) != 0)
982*86d7f5d3SJohn Marino return error;
983*86d7f5d3SJohn Marino ctx->f_flags &= ~SMBFS_RDD_FINDFIRST;
984*86d7f5d3SJohn Marino }
985*86d7f5d3SJohn Marino if ((error = md_get_uint16le(mdp, &tw)) != 0)
986*86d7f5d3SJohn Marino return error;
987*86d7f5d3SJohn Marino ctx->f_ecnt = tw;
988*86d7f5d3SJohn Marino if ((error = md_get_uint16le(mdp, &tw)) != 0)
989*86d7f5d3SJohn Marino return error;
990*86d7f5d3SJohn Marino if (tw)
991*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_EOF | SMBFS_RDD_NOCLOSE;
992*86d7f5d3SJohn Marino if ((error = md_get_uint16le(mdp, &tw)) != 0)
993*86d7f5d3SJohn Marino return error;
994*86d7f5d3SJohn Marino if ((error = md_get_uint16le(mdp, &tw)) != 0)
995*86d7f5d3SJohn Marino return error;
996*86d7f5d3SJohn Marino if (ctx->f_ecnt == 0) {
997*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_EOF | SMBFS_RDD_NOCLOSE;
998*86d7f5d3SJohn Marino return ENOENT;
999*86d7f5d3SJohn Marino }
1000*86d7f5d3SJohn Marino ctx->f_rnameofs = tw;
1001*86d7f5d3SJohn Marino mdp = &t2p->t2_rdata;
1002*86d7f5d3SJohn Marino if (mdp->md_top == NULL) {
1003*86d7f5d3SJohn Marino kprintf("bug: ecnt = %d, but data is NULL (please report)\n", ctx->f_ecnt);
1004*86d7f5d3SJohn Marino return ENOENT;
1005*86d7f5d3SJohn Marino }
1006*86d7f5d3SJohn Marino if (mdp->md_top->m_len == 0) {
1007*86d7f5d3SJohn Marino kprintf("bug: ecnt = %d, but m_len = 0 and m_next = %p (please report)\n", ctx->f_ecnt,mbp->mb_top->m_next);
1008*86d7f5d3SJohn Marino return ENOENT;
1009*86d7f5d3SJohn Marino }
1010*86d7f5d3SJohn Marino ctx->f_eofs = 0;
1011*86d7f5d3SJohn Marino return 0;
1012*86d7f5d3SJohn Marino }
1013*86d7f5d3SJohn Marino
1014*86d7f5d3SJohn Marino static int
smbfs_smb_findclose2(struct smbfs_fctx * ctx)1015*86d7f5d3SJohn Marino smbfs_smb_findclose2(struct smbfs_fctx *ctx)
1016*86d7f5d3SJohn Marino {
1017*86d7f5d3SJohn Marino struct smb_rq rq, *rqp = &rq;
1018*86d7f5d3SJohn Marino struct mbchain *mbp;
1019*86d7f5d3SJohn Marino int error;
1020*86d7f5d3SJohn Marino
1021*86d7f5d3SJohn Marino error = smb_rq_init(rqp, SSTOCP(ctx->f_ssp), SMB_COM_FIND_CLOSE2, ctx->f_scred);
1022*86d7f5d3SJohn Marino if (error)
1023*86d7f5d3SJohn Marino return error;
1024*86d7f5d3SJohn Marino smb_rq_getrequest(rqp, &mbp);
1025*86d7f5d3SJohn Marino smb_rq_wstart(rqp);
1026*86d7f5d3SJohn Marino mb_put_mem(mbp, (caddr_t)&ctx->f_Sid, 2, MB_MSYSTEM);
1027*86d7f5d3SJohn Marino smb_rq_wend(rqp);
1028*86d7f5d3SJohn Marino smb_rq_bstart(rqp);
1029*86d7f5d3SJohn Marino smb_rq_bend(rqp);
1030*86d7f5d3SJohn Marino error = smb_rq_simple(rqp);
1031*86d7f5d3SJohn Marino smb_rq_done(rqp);
1032*86d7f5d3SJohn Marino return error;
1033*86d7f5d3SJohn Marino }
1034*86d7f5d3SJohn Marino
1035*86d7f5d3SJohn Marino static int
smbfs_findopenLM2(struct smbfs_fctx * ctx,struct smbnode * dnp,const char * wildcard,int wclen,int attr,struct smb_cred * scred)1036*86d7f5d3SJohn Marino smbfs_findopenLM2(struct smbfs_fctx *ctx, struct smbnode *dnp,
1037*86d7f5d3SJohn Marino const char *wildcard, int wclen, int attr, struct smb_cred *scred)
1038*86d7f5d3SJohn Marino {
1039*86d7f5d3SJohn Marino ctx->f_name = kmalloc(SMB_MAXFNAMELEN, M_SMBFSDATA, M_WAITOK);
1040*86d7f5d3SJohn Marino ctx->f_infolevel = SMB_DIALECT(SSTOVC(ctx->f_ssp)) < SMB_DIALECT_NTLM0_12 ?
1041*86d7f5d3SJohn Marino SMB_INFO_STANDARD : SMB_FIND_FILE_DIRECTORY_INFO;
1042*86d7f5d3SJohn Marino ctx->f_attrmask = attr;
1043*86d7f5d3SJohn Marino ctx->f_wildcard = wildcard;
1044*86d7f5d3SJohn Marino ctx->f_wclen = wclen;
1045*86d7f5d3SJohn Marino return 0;
1046*86d7f5d3SJohn Marino }
1047*86d7f5d3SJohn Marino
1048*86d7f5d3SJohn Marino static int
smbfs_findnextLM2(struct smbfs_fctx * ctx,int limit)1049*86d7f5d3SJohn Marino smbfs_findnextLM2(struct smbfs_fctx *ctx, int limit)
1050*86d7f5d3SJohn Marino {
1051*86d7f5d3SJohn Marino struct mdchain *mbp;
1052*86d7f5d3SJohn Marino struct smb_t2rq *t2p;
1053*86d7f5d3SJohn Marino char *cp;
1054*86d7f5d3SJohn Marino u_int8_t tb;
1055*86d7f5d3SJohn Marino u_int16_t date, time, wattr;
1056*86d7f5d3SJohn Marino u_int32_t size, next, dattr;
1057*86d7f5d3SJohn Marino int64_t lint;
1058*86d7f5d3SJohn Marino int error, svtz, cnt, fxsz, nmlen, recsz;
1059*86d7f5d3SJohn Marino
1060*86d7f5d3SJohn Marino if (ctx->f_ecnt == 0) {
1061*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_EOF)
1062*86d7f5d3SJohn Marino return ENOENT;
1063*86d7f5d3SJohn Marino ctx->f_left = ctx->f_limit = limit;
1064*86d7f5d3SJohn Marino error = smbfs_smb_trans2find2(ctx);
1065*86d7f5d3SJohn Marino if (error)
1066*86d7f5d3SJohn Marino return error;
1067*86d7f5d3SJohn Marino }
1068*86d7f5d3SJohn Marino t2p = ctx->f_t2;
1069*86d7f5d3SJohn Marino mbp = &t2p->t2_rdata;
1070*86d7f5d3SJohn Marino svtz = SSTOVC(ctx->f_ssp)->vc_sopt.sv_tz;
1071*86d7f5d3SJohn Marino switch (ctx->f_infolevel) {
1072*86d7f5d3SJohn Marino case SMB_INFO_STANDARD:
1073*86d7f5d3SJohn Marino next = 0;
1074*86d7f5d3SJohn Marino fxsz = 0;
1075*86d7f5d3SJohn Marino md_get_uint16le(mbp, &date);
1076*86d7f5d3SJohn Marino md_get_uint16le(mbp, &time); /* creation time */
1077*86d7f5d3SJohn Marino md_get_uint16le(mbp, &date);
1078*86d7f5d3SJohn Marino md_get_uint16le(mbp, &time); /* access time */
1079*86d7f5d3SJohn Marino smb_dos2unixtime(date, time, 0, svtz, &ctx->f_attr.fa_atime);
1080*86d7f5d3SJohn Marino md_get_uint16le(mbp, &date);
1081*86d7f5d3SJohn Marino md_get_uint16le(mbp, &time); /* access time */
1082*86d7f5d3SJohn Marino smb_dos2unixtime(date, time, 0, svtz, &ctx->f_attr.fa_mtime);
1083*86d7f5d3SJohn Marino md_get_uint32le(mbp, &size);
1084*86d7f5d3SJohn Marino ctx->f_attr.fa_size = size;
1085*86d7f5d3SJohn Marino md_get_uint32(mbp, NULL); /* allocation size */
1086*86d7f5d3SJohn Marino md_get_uint16le(mbp, &wattr);
1087*86d7f5d3SJohn Marino ctx->f_attr.fa_attr = wattr;
1088*86d7f5d3SJohn Marino md_get_uint8(mbp, &tb);
1089*86d7f5d3SJohn Marino size = nmlen = tb;
1090*86d7f5d3SJohn Marino fxsz = 23;
1091*86d7f5d3SJohn Marino recsz = next = 24 + nmlen; /* docs misses zero byte at end */
1092*86d7f5d3SJohn Marino break;
1093*86d7f5d3SJohn Marino case SMB_FIND_FILE_DIRECTORY_INFO:
1094*86d7f5d3SJohn Marino md_get_uint32le(mbp, &next);
1095*86d7f5d3SJohn Marino md_get_uint32(mbp, NULL); /* file index */
1096*86d7f5d3SJohn Marino md_get_int64(mbp, NULL); /* creation time */
1097*86d7f5d3SJohn Marino md_get_int64le(mbp, &lint);
1098*86d7f5d3SJohn Marino smb_time_NT2local(lint, svtz, &ctx->f_attr.fa_atime);
1099*86d7f5d3SJohn Marino md_get_int64le(mbp, &lint);
1100*86d7f5d3SJohn Marino smb_time_NT2local(lint, svtz, &ctx->f_attr.fa_mtime);
1101*86d7f5d3SJohn Marino md_get_int64le(mbp, &lint);
1102*86d7f5d3SJohn Marino smb_time_NT2local(lint, svtz, &ctx->f_attr.fa_ctime);
1103*86d7f5d3SJohn Marino md_get_int64le(mbp, &lint); /* file size */
1104*86d7f5d3SJohn Marino ctx->f_attr.fa_size = lint;
1105*86d7f5d3SJohn Marino md_get_int64(mbp, NULL); /* real size (should use) */
1106*86d7f5d3SJohn Marino md_get_uint32(mbp, &dattr); /* EA */
1107*86d7f5d3SJohn Marino ctx->f_attr.fa_attr = dattr;
1108*86d7f5d3SJohn Marino md_get_uint32le(mbp, &size); /* name len */
1109*86d7f5d3SJohn Marino fxsz = 64;
1110*86d7f5d3SJohn Marino recsz = next ? next : fxsz + size;
1111*86d7f5d3SJohn Marino break;
1112*86d7f5d3SJohn Marino default:
1113*86d7f5d3SJohn Marino SMBERROR("unexpected info level %d\n", ctx->f_infolevel);
1114*86d7f5d3SJohn Marino return EINVAL;
1115*86d7f5d3SJohn Marino }
1116*86d7f5d3SJohn Marino nmlen = min(size, SMB_MAXFNAMELEN);
1117*86d7f5d3SJohn Marino cp = ctx->f_name;
1118*86d7f5d3SJohn Marino error = md_get_mem(mbp, cp, nmlen, MB_MSYSTEM);
1119*86d7f5d3SJohn Marino if (error)
1120*86d7f5d3SJohn Marino return error;
1121*86d7f5d3SJohn Marino if (next) {
1122*86d7f5d3SJohn Marino cnt = next - nmlen - fxsz;
1123*86d7f5d3SJohn Marino if (cnt > 0)
1124*86d7f5d3SJohn Marino md_get_mem(mbp, NULL, cnt, MB_MSYSTEM);
1125*86d7f5d3SJohn Marino else if (cnt < 0) {
1126*86d7f5d3SJohn Marino SMBERROR("out of sync\n");
1127*86d7f5d3SJohn Marino return EBADRPC;
1128*86d7f5d3SJohn Marino }
1129*86d7f5d3SJohn Marino }
1130*86d7f5d3SJohn Marino if (nmlen && cp[nmlen - 1] == 0)
1131*86d7f5d3SJohn Marino nmlen--;
1132*86d7f5d3SJohn Marino if (nmlen == 0)
1133*86d7f5d3SJohn Marino return EBADRPC;
1134*86d7f5d3SJohn Marino
1135*86d7f5d3SJohn Marino next = ctx->f_eofs + recsz;
1136*86d7f5d3SJohn Marino if (ctx->f_rnameofs && (ctx->f_flags & SMBFS_RDD_GOTRNAME) == 0 &&
1137*86d7f5d3SJohn Marino (ctx->f_rnameofs >= ctx->f_eofs && ctx->f_rnameofs < next)) {
1138*86d7f5d3SJohn Marino /*
1139*86d7f5d3SJohn Marino * Server needs a resume filename.
1140*86d7f5d3SJohn Marino */
1141*86d7f5d3SJohn Marino if (ctx->f_rnamelen <= nmlen) {
1142*86d7f5d3SJohn Marino if (ctx->f_rname)
1143*86d7f5d3SJohn Marino kfree(ctx->f_rname, M_SMBFSDATA);
1144*86d7f5d3SJohn Marino ctx->f_rname = kmalloc(nmlen + 1, M_SMBFSDATA, M_WAITOK);
1145*86d7f5d3SJohn Marino ctx->f_rnamelen = nmlen;
1146*86d7f5d3SJohn Marino }
1147*86d7f5d3SJohn Marino bcopy(ctx->f_name, ctx->f_rname, nmlen);
1148*86d7f5d3SJohn Marino ctx->f_rname[nmlen] = 0;
1149*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_GOTRNAME;
1150*86d7f5d3SJohn Marino }
1151*86d7f5d3SJohn Marino ctx->f_nmlen = nmlen;
1152*86d7f5d3SJohn Marino ctx->f_eofs = next;
1153*86d7f5d3SJohn Marino ctx->f_ecnt--;
1154*86d7f5d3SJohn Marino ctx->f_left--;
1155*86d7f5d3SJohn Marino return 0;
1156*86d7f5d3SJohn Marino }
1157*86d7f5d3SJohn Marino
1158*86d7f5d3SJohn Marino static int
smbfs_findcloseLM2(struct smbfs_fctx * ctx)1159*86d7f5d3SJohn Marino smbfs_findcloseLM2(struct smbfs_fctx *ctx)
1160*86d7f5d3SJohn Marino {
1161*86d7f5d3SJohn Marino if (ctx->f_name)
1162*86d7f5d3SJohn Marino kfree(ctx->f_name, M_SMBFSDATA);
1163*86d7f5d3SJohn Marino if (ctx->f_t2)
1164*86d7f5d3SJohn Marino smb_t2_done(ctx->f_t2);
1165*86d7f5d3SJohn Marino if ((ctx->f_flags & SMBFS_RDD_NOCLOSE) == 0)
1166*86d7f5d3SJohn Marino smbfs_smb_findclose2(ctx);
1167*86d7f5d3SJohn Marino return 0;
1168*86d7f5d3SJohn Marino }
1169*86d7f5d3SJohn Marino
1170*86d7f5d3SJohn Marino int
smbfs_findopen(struct smbnode * dnp,const char * wildcard,int wclen,int attr,struct smb_cred * scred,struct smbfs_fctx ** ctxpp)1171*86d7f5d3SJohn Marino smbfs_findopen(struct smbnode *dnp, const char *wildcard, int wclen, int attr,
1172*86d7f5d3SJohn Marino struct smb_cred *scred, struct smbfs_fctx **ctxpp)
1173*86d7f5d3SJohn Marino {
1174*86d7f5d3SJohn Marino struct smbfs_fctx *ctx;
1175*86d7f5d3SJohn Marino int error;
1176*86d7f5d3SJohn Marino
1177*86d7f5d3SJohn Marino ctx = kmalloc(sizeof(*ctx), M_SMBFSDATA, M_WAITOK | M_ZERO);
1178*86d7f5d3SJohn Marino ctx->f_ssp = dnp->n_mount->sm_share;
1179*86d7f5d3SJohn Marino ctx->f_dnp = dnp;
1180*86d7f5d3SJohn Marino ctx->f_flags = SMBFS_RDD_FINDFIRST;
1181*86d7f5d3SJohn Marino ctx->f_scred = scred;
1182*86d7f5d3SJohn Marino if (SMB_DIALECT(SSTOVC(ctx->f_ssp)) < SMB_DIALECT_LANMAN2_0 ||
1183*86d7f5d3SJohn Marino (dnp->n_mount->sm_args.flags & SMBFS_MOUNT_NO_LONG)) {
1184*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_USESEARCH;
1185*86d7f5d3SJohn Marino error = smbfs_findopenLM1(ctx, dnp, wildcard, wclen, attr, scred);
1186*86d7f5d3SJohn Marino } else
1187*86d7f5d3SJohn Marino error = smbfs_findopenLM2(ctx, dnp, wildcard, wclen, attr, scred);
1188*86d7f5d3SJohn Marino if (error)
1189*86d7f5d3SJohn Marino smbfs_findclose(ctx, scred);
1190*86d7f5d3SJohn Marino else
1191*86d7f5d3SJohn Marino *ctxpp = ctx;
1192*86d7f5d3SJohn Marino return error;
1193*86d7f5d3SJohn Marino }
1194*86d7f5d3SJohn Marino
1195*86d7f5d3SJohn Marino int
smbfs_findnext(struct smbfs_fctx * ctx,int limit,struct smb_cred * scred)1196*86d7f5d3SJohn Marino smbfs_findnext(struct smbfs_fctx *ctx, int limit, struct smb_cred *scred)
1197*86d7f5d3SJohn Marino {
1198*86d7f5d3SJohn Marino int error;
1199*86d7f5d3SJohn Marino
1200*86d7f5d3SJohn Marino if (limit == 0)
1201*86d7f5d3SJohn Marino limit = 1000000;
1202*86d7f5d3SJohn Marino else if (limit > 1)
1203*86d7f5d3SJohn Marino limit *= 4; /* imperical */
1204*86d7f5d3SJohn Marino ctx->f_scred = scred;
1205*86d7f5d3SJohn Marino for (;;) {
1206*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_USESEARCH) {
1207*86d7f5d3SJohn Marino error = smbfs_findnextLM1(ctx, limit);
1208*86d7f5d3SJohn Marino } else
1209*86d7f5d3SJohn Marino error = smbfs_findnextLM2(ctx, limit);
1210*86d7f5d3SJohn Marino if (error)
1211*86d7f5d3SJohn Marino return error;
1212*86d7f5d3SJohn Marino if ((ctx->f_nmlen == 1 && ctx->f_name[0] == '.') ||
1213*86d7f5d3SJohn Marino (ctx->f_nmlen == 2 && ctx->f_name[0] == '.' &&
1214*86d7f5d3SJohn Marino ctx->f_name[1] == '.'))
1215*86d7f5d3SJohn Marino continue;
1216*86d7f5d3SJohn Marino break;
1217*86d7f5d3SJohn Marino }
1218*86d7f5d3SJohn Marino smbfs_fname_tolocal(SSTOVC(ctx->f_ssp), ctx->f_name, ctx->f_nmlen,
1219*86d7f5d3SJohn Marino ctx->f_dnp->n_mount->sm_caseopt);
1220*86d7f5d3SJohn Marino ctx->f_attr.fa_ino = smbfs_getino(ctx->f_dnp, ctx->f_name, ctx->f_nmlen);
1221*86d7f5d3SJohn Marino return 0;
1222*86d7f5d3SJohn Marino }
1223*86d7f5d3SJohn Marino
1224*86d7f5d3SJohn Marino int
smbfs_findclose(struct smbfs_fctx * ctx,struct smb_cred * scred)1225*86d7f5d3SJohn Marino smbfs_findclose(struct smbfs_fctx *ctx, struct smb_cred *scred)
1226*86d7f5d3SJohn Marino {
1227*86d7f5d3SJohn Marino ctx->f_scred = scred;
1228*86d7f5d3SJohn Marino if (ctx->f_flags & SMBFS_RDD_USESEARCH) {
1229*86d7f5d3SJohn Marino smbfs_findcloseLM1(ctx);
1230*86d7f5d3SJohn Marino } else
1231*86d7f5d3SJohn Marino smbfs_findcloseLM2(ctx);
1232*86d7f5d3SJohn Marino if (ctx->f_rname)
1233*86d7f5d3SJohn Marino kfree(ctx->f_rname, M_SMBFSDATA);
1234*86d7f5d3SJohn Marino kfree(ctx, M_SMBFSDATA);
1235*86d7f5d3SJohn Marino return 0;
1236*86d7f5d3SJohn Marino }
1237*86d7f5d3SJohn Marino
1238*86d7f5d3SJohn Marino int
smbfs_smb_lookup(struct smbnode * dnp,const char * name,int nmlen,struct smbfattr * fap,struct smb_cred * scred)1239*86d7f5d3SJohn Marino smbfs_smb_lookup(struct smbnode *dnp, const char *name, int nmlen,
1240*86d7f5d3SJohn Marino struct smbfattr *fap, struct smb_cred *scred)
1241*86d7f5d3SJohn Marino {
1242*86d7f5d3SJohn Marino struct smbfs_fctx *ctx;
1243*86d7f5d3SJohn Marino int error;
1244*86d7f5d3SJohn Marino
1245*86d7f5d3SJohn Marino if (dnp == NULL || (dnp->n_ino == 2 && name == NULL)) {
1246*86d7f5d3SJohn Marino bzero(fap, sizeof(*fap));
1247*86d7f5d3SJohn Marino fap->fa_attr = SMB_FA_DIR;
1248*86d7f5d3SJohn Marino fap->fa_ino = 2;
1249*86d7f5d3SJohn Marino return 0;
1250*86d7f5d3SJohn Marino }
1251*86d7f5d3SJohn Marino if (nmlen == 1 && name[0] == '.') {
1252*86d7f5d3SJohn Marino error = smbfs_smb_lookup(dnp, NULL, 0, fap, scred);
1253*86d7f5d3SJohn Marino return error;
1254*86d7f5d3SJohn Marino } else if (nmlen == 2 && name[0] == '.' && name[1] == '.') {
1255*86d7f5d3SJohn Marino error = smbfs_smb_lookup(VTOSMB(dnp->n_parent), NULL, 0, fap,
1256*86d7f5d3SJohn Marino scred);
1257*86d7f5d3SJohn Marino kprintf("%s: knows NOTHING about '..'\n", __func__);
1258*86d7f5d3SJohn Marino return error;
1259*86d7f5d3SJohn Marino }
1260*86d7f5d3SJohn Marino error = smbfs_findopen(dnp, name, nmlen,
1261*86d7f5d3SJohn Marino SMB_FA_SYSTEM | SMB_FA_HIDDEN | SMB_FA_DIR, scred, &ctx);
1262*86d7f5d3SJohn Marino if (error)
1263*86d7f5d3SJohn Marino return error;
1264*86d7f5d3SJohn Marino ctx->f_flags |= SMBFS_RDD_FINDSINGLE;
1265*86d7f5d3SJohn Marino error = smbfs_findnext(ctx, 1, scred);
1266*86d7f5d3SJohn Marino if (error == 0) {
1267*86d7f5d3SJohn Marino *fap = ctx->f_attr;
1268*86d7f5d3SJohn Marino if (name == NULL)
1269*86d7f5d3SJohn Marino fap->fa_ino = dnp->n_ino;
1270*86d7f5d3SJohn Marino }
1271*86d7f5d3SJohn Marino smbfs_findclose(ctx, scred);
1272*86d7f5d3SJohn Marino return error;
1273*86d7f5d3SJohn Marino }
1274