9 t2hdr(Session *s, Share *sp, int cmd)
13 p = cifshdr(s, sp, SMB_COM_TRANSACTION2);
15 p->tbase = pl16(p, 0); /* 0 Total parameter bytes to be sent, filled later */
16 pl16(p, 0); /* 2 Total data bytes to be sent, filled later */
17 pl16(p, 64); /* 4 Max parameter to return */
18 pl16(p, (MTU - T2HDRLEN)-64); /* 6 Max data to return */
19 p8(p, 0); /* 8 Max setup count to return */
20 p8(p, 0); /* 9 Reserved */
21 pl16(p, 0); /* 10 Flags */
22 pl32(p, 1000); /* 12 Timeout (ms) */
23 pl16(p, 0); /* 16 Reserved */
24 pl16(p, 0); /* 18 Parameter count, filled later */
25 pl16(p, 0); /* 20 Parameter offset, filled later */
26 pl16(p, 0); /* 22 Data count, filled later */
27 pl16(p, 0); /* 24 Data offset, filled later */
28 p8(p, 1); /* 26 Setup count (in words) */
29 p8(p, 0); /* 27 Reserved */
30 pl16(p, cmd); /* setup[0] */
32 p8(p, 0); /* padding ??!?!? */
42 assert(p->tbase != 0);
43 p->pos = p->tbase + 20;
44 pl16(p, (pos - p->buf) - NBHDRLEN); /* param offset */
46 p->tparam = p->pos = pos;
54 assert(p->tbase != 0);
55 assert(p->tparam != 0);
58 pl16(p, pos - p->tparam); /* total param count */
60 p->pos = p->tbase +18;
61 pl16(p, pos - p->tparam); /* param count */
63 p->pos = p->tbase +24;
64 pl16(p, (pos - p->buf) - NBHDRLEN); /* data offset */
66 p->tdata = p->pos = pos;
75 assert(p->tbase != 0);
76 assert(p->tdata != 0);
81 pl16(p, pos - p->tdata); /* total data count */
83 p->pos = p->tbase +22;
84 pl16(p, pos - p->tdata); /* data count */
87 if((got = cifsrpc(p)) == -1)
90 gl16(p); /* Total parameter count */
91 gl16(p); /* Total data count */
92 gl16(p); /* Reserved */
93 gl16(p); /* Parameter count in this buffer */
94 p->tparam = p->buf +NBHDRLEN +gl16(p); /* Parameter offset */
95 gl16(p); /* Parameter displacement */
96 gl16(p); /* Data count (this buffer); */
97 p->tdata = p->buf +NBHDRLEN +gl16(p); /* Data offset */
98 gl16(p); /* Data displacement */
99 g8(p); /* Setup count */
100 g8(p); /* Reserved */
119 T2findfirst(Session *s, Share *sp, int slots, char *path, int *got,
120 long *resume, FInfo *fip)
122 int pktlen, i, n, sh;
126 p = t2hdr(s, sp, TRANS2_FIND_FIRST2);
127 p8(p, 'D'); /* OS/2 */
128 p8(p, ' '); /* OS/2 */
131 pl16(p, ATTR_HIDDEN|ATTR_SYSTEM|ATTR_DIRECTORY); /* Search attributes */
132 pl16(p, slots); /* Search count */
133 pl16(p, CIFS_SEARCH_RETURN_RESUME); /* Flags */
134 pl16(p, SMB_FIND_FILE_FULL_DIRECTORY_INFO); /* Information level */
135 pl32(p, 0); /* SearchStorage type (?) */
136 ppath(p, path); /* path */
139 if((pktlen = t2rpc(p)) == -1){
144 s->lastfind = nsec();
147 sh = gl16(p); /* Sid (search handle) */
148 *got = gl16(p); /* number of slots received */
149 gl16(p); /* End of search flag */
150 gl16(p); /* Offset into EA list if EA error */
151 gl16(p); /* Offset into data to file name of last entry */
154 memset(fip, 0, slots * sizeof(FInfo));
155 for(i = 0; i < *got; i++){
157 next += gl32(p); /* offset to next entry */
159 * bug in Windows - somtimes it lies about how many
160 * directory entries it has put in the packet
162 if(next - p->buf > pktlen){
167 *resume = gl32(p); /* resume key for search */
168 fip[i].created = gvtime(p); /* creation time */
169 fip[i].accessed = gvtime(p); /* last access time */
170 fip[i].written = gvtime(p); /* last written time */
171 fip[i].changed = gvtime(p); /* change time */
172 fip[i].size = gl64(p); /* file size */
173 gl64(p); /* bytes allocated */
174 fip[i].attribs = gl32(p); /* extended attributes */
175 n = gl32(p); /* name length */
176 gl32(p); /* EA size */
177 gstr(p, fip[i].name, n); /* name */
187 T2findnext(Session *s, Share *sp, int slots, char *path, int *got,
188 long *resume, FInfo *fip, int sh)
195 * So I believe from comp.protocols.smb if you send
196 * TRANS2_FIND_NEXT2 requests too quickly to windows 95, it can
197 * get confused and fail to reply, so we slow up a bit in these
200 if(!(s->caps & CAP_NT_SMBS) && nsec() - s->lastfind < 200000000LL)
203 p = t2hdr(s, sp, TRANS2_FIND_NEXT2);
204 p8(p, 'D'); /* OS/2 */
205 p8(p, ' '); /* OS/2 */
208 pl16(p, sh); /* search handle */
209 pl16(p, slots); /* Search count */
210 pl16(p, SMB_FIND_FILE_FULL_DIRECTORY_INFO); /* Information level */
211 pl32(p, *resume); /* resume key */
212 pl16(p, CIFS_SEARCH_CONTINUE_FROM_LAST); /* Flags */
213 ppath(p, path); /* file+path to resume */
221 s->lastfind = nsec();
224 *got = gl16(p); /* number of slots received */
225 gl16(p); /* End of search flag */
226 gl16(p); /* Offset into EA list if EA error */
227 gl16(p); /* Offset into data to file name of last entry */
230 memset(fip, 0, slots * sizeof(FInfo));
231 for(i = 0; i < *got; i++){
233 next += gl32(p); /* offset to next entry */
234 *resume = gl32(p); /* resume key for search */
235 fip[i].created = gvtime(p); /* creation time */
236 fip[i].accessed = gvtime(p); /* last access time */
237 fip[i].written = gvtime(p); /* last written time */
238 fip[i].changed = gvtime(p); /* change time */
239 fip[i].size = gl64(p); /* file size */
240 gl64(p); /* bytes allocated */
241 fip[i].attribs = gl32(p); /* extended attributes */
242 n = gl32(p); /* name length */
243 gl32(p); /* EA size */
244 gstr(p, fip[i].name, n); /* name */
252 /* supported by 2k/XP/NT4 */
254 T2queryall(Session *s, Share *sp, char *path, FInfo *fip)
259 p = t2hdr(s, sp, TRANS2_QUERY_PATH_INFORMATION);
261 pl16(p, SMB_QUERY_FILE_ALL_INFO); /* Information level */
262 pl32(p, 0); /* reserved */
263 ppath(p, path); /* path */
273 * The layout of this struct is wrong in the SINA
274 * document, this layout gained by inspection.
276 memset(fip, 0, sizeof(FInfo));
277 fip->created = gvtime(p); /* creation time */
278 fip->accessed = gvtime(p); /* last access time */
279 fip->written = gvtime(p); /* last written time */
280 fip->changed = gvtime(p); /* change time */
281 fip->attribs = gl32(p); /* attributes */
282 gl32(p); /* reserved */
283 gl64(p); /* bytes allocated */
284 fip->size = gl64(p); /* file size */
285 gl32(p); /* number of hard links */
286 g8(p); /* delete pending */
287 g8(p); /* is a directory */
288 gl16(p); /* reserved */
289 gl32(p); /* EA size */
292 if(n >= sizeof fip->name)
293 n = sizeof fip->name - 1;
294 gstr(p, fip->name, n);
300 /* supported by 95/98/ME */
302 T2querystandard(Session *s, Share *sp, char *path, FInfo *fip)
306 p = t2hdr(s, sp, TRANS2_QUERY_PATH_INFORMATION);
308 pl16(p, SMB_INFO_STANDARD); /* Information level */
309 pl32(p, 0); /* reserved */
310 ppath(p, path); /* path */
318 memset(fip, 0, sizeof(FInfo));
319 fip->created = gdatetime(p); /* creation time */
320 fip->accessed = gdatetime(p); /* last access time */
321 fip->written = gdatetime(p); /* last written time */
322 fip->changed = fip->written; /* change time */
323 fip->size = gl32(p); /* file size */
324 gl32(p); /* bytes allocated */
325 fip->attribs = gl16(p); /* attributes */
326 gl32(p); /* EA size */
333 T2setpathinfo(Session *s, Share *sp, char *path, FInfo *fip)
338 p = t2hdr(s, sp, TRANS2_SET_PATH_INFORMATION);
340 pl16(p, SMB_INFO_STANDARD); /* Information level */
341 pl32(p, 0); /* reserved */
342 ppath(p, path); /* path */
345 pdatetime(p, fip->created); /* created */
346 pdatetime(p, fip->accessed); /* accessed */
347 pdatetime(p, fip->written); /* written */
348 pl32(p, fip->size); /* size */
349 pl32(p, 0); /* allocated */
350 pl16(p, fip->attribs); /* attributes */
351 pl32(p, 0); /* EA size */
352 pl16(p, 0); /* reserved */
361 T2setfilelength(Session *s, Share *sp, int fh, FInfo *fip) /* FIXME: maybe broken, needs testing */
366 p = t2hdr(s, sp, TRANS2_SET_FILE_INFORMATION);
368 pl16(p, fh); /* file handle */
369 pl16(p, SMB_SET_FILE_END_OF_FILE_INFO); /* Information level */
370 pl16(p, 0); /* reserved */
374 pl32(p, 0); /* padding ?! */
384 T2fsvolumeinfo(Session *s, Share *sp, long *created, long *serialno,
385 char *label, int labellen)
390 p = t2hdr(s, sp, TRANS2_QUERY_FS_INFORMATION);
392 pl16(p, SMB_QUERY_FS_VOLUME_INFO); /* Information level */
402 ct = gvtime(p); /* creation time */
403 sn = gl32(p); /* serial number */
404 n = gl32(p); /* label name length */
405 g8(p); /* reserved */
406 g8(p); /* reserved */
408 memset(label, 0, labellen);
409 if(n < labellen && n > 0)
410 gstr(p, label, n); /* file system label */
421 T2fssizeinfo(Session *s, Share *sp, uvlong *total, uvlong *unused)
426 p = t2hdr(s, sp, TRANS2_QUERY_FS_INFORMATION);
428 pl16(p, SMB_QUERY_FS_SIZE_INFO); /* Information level */
438 t = gl64(p); /* total blocks */
439 f = gl64(p); /* free blocks */
440 n = gl32(p); /* sectors per block */
441 b = gl32(p); /* bytes per sector */
453 T2getdfsreferral(Session *s, Share *sp, char *path, int *gflags, int *used,
456 int i, vers, nret, len;
461 p = t2hdr(s, sp, TRANS2_GET_DFS_REFERRAL);
463 pl16(p, 3); /* max info level we understand, must be >= 3 for domain requests */
473 memset(re, 0, sizeof *re * nent);
476 *used = gl16(p) / 2; /* length used (/2 as Windows counts in runes) */
477 nret = gl16(p); /* number of referrals returned */
478 *gflags = gl32(p); /* global flags */
480 for(i = 0; i < nret && i < nent && i < 16; i++){
482 vers = gl16(p); /* version of records */
483 len = gl16(p); /* length of records */
484 re[i].type = gl16(p); /* server type */
485 re[i].flags = gl16(p); /* referal flags */
488 re[i].prox = 0; /* nearby */
489 re[i].ttl = 5*60; /* 5 mins */
490 gstr(p, tmp, sizeof tmp);
491 re[i].addr = estrdup9p(tmp);
492 re[i].path = estrdup9p(tmp);
495 re[i].prox = gl32(p); /* not implemented in v2 */
497 goff(p, base, re[i].path, sizeof tmp);
498 re[i].path = estrdup9p(tmp);
499 goff(p, base, re[i].path, sizeof tmp);/* spurious 8.3 path */
500 goff(p, base, tmp, sizeof tmp);
501 re[i].addr = estrdup9p(tmp);
504 if(re[i].flags & DFS_REFERAL_LIST){
507 goff(p, base, tmp, sizeof tmp);
508 re[i].path = estrdup9p(tmp);
510 goff(p, base, tmp, sizeof tmp);
511 re[i].addr = estrdup9p(tmp);
516 goff(p, base, tmp, sizeof tmp);
517 re[i].path = estrdup9p(tmp);
518 gl16(p); /* spurious 8.3 path */
519 goff(p, base, tmp, sizeof tmp);
520 re[i].addr = estrdup9p(tmp);
521 gl16(p); /* GUID (historic) */
526 * this should never happen as we specify our maximum
527 * understood level in the request (above)
529 fprint(2, "%d - unsupported DFS infolevel\n", vers);
530 re[i].path = estrdup9p(tmp);
531 re[i].addr = estrdup9p(tmp);