2 |
- |
1 |
#include "headers.h"
|
|
|
2 |
|
|
|
3 |
static SmbTransactionMethod method = {
|
|
|
4 |
.encodeprimary = smbtransactionencodeprimary2,
|
|
|
5 |
.sendrequest = smbtransactionclientsend,
|
|
|
6 |
.receiveresponse = smbtransactionclientreceive,
|
|
|
7 |
.decoderesponse = smbtransactiondecoderesponse2,
|
|
|
8 |
};
|
|
|
9 |
|
|
|
10 |
int
|
|
|
11 |
smbclienttrans2(SmbClient *c, uchar scount, ushort *setup, SmbBuffer *inparam, SmbBuffer *outparam, SmbBuffer *outdata, SmbHeader *rh, char **errmsgp)
|
|
|
12 |
{
|
|
|
13 |
SmbTransaction transaction;
|
|
|
14 |
SmbHeader h;
|
|
|
15 |
memset(&transaction, 0, sizeof(transaction));
|
|
|
16 |
transaction.in.scount = scount;
|
|
|
17 |
transaction.in.setup = setup;
|
|
|
18 |
transaction.in.parameters = smbbufferreadpointer(inparam);
|
|
|
19 |
transaction.in.tpcount = smbbufferreadspace(inparam);
|
|
|
20 |
transaction.in.maxpcount = smbbufferwritespace(outparam);
|
|
|
21 |
transaction.in.maxdcount = smbbufferwritespace(outdata);
|
|
|
22 |
transaction.out.parameters = outparam;
|
|
|
23 |
transaction.out.data = outdata;
|
|
|
24 |
h = c->protoh;
|
|
|
25 |
h.tid = c->sharetid;
|
|
|
26 |
h.mid = 0;
|
|
|
27 |
return smbtransactionexecute(&transaction, &h, &c->peerinfo, c->b, &method, c, rh, errmsgp);
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
int
|
|
|
31 |
smbclienttrans2findfirst2(SmbClient *c, ushort searchcount, char *filename,
|
|
|
32 |
ushort *sidp, ushort *searchcountp, ushort *endofsearchp,SmbFindFileBothDirectoryInfo *ip, char **errmsgp)
|
|
|
33 |
{
|
|
|
34 |
int rv;
|
|
|
35 |
ushort setup;
|
|
|
36 |
SmbBuffer *inparam;
|
|
|
37 |
SmbBuffer *outparam;
|
|
|
38 |
SmbBuffer *outdata;
|
|
|
39 |
SmbHeader rh;
|
|
|
40 |
setup = SMB_TRANS2_FIND_FIRST2;
|
|
|
41 |
inparam = smbbuffernew(512);
|
|
|
42 |
smbbufferputs(inparam, 0x16);
|
|
|
43 |
smbbufferputs(inparam, searchcount);
|
|
|
44 |
smbbufferputs(inparam, 7);
|
|
|
45 |
smbbufferputs(inparam, SMB_FIND_FILE_BOTH_DIRECTORY_INFO);
|
|
|
46 |
smbbufferputl(inparam, 0);
|
|
|
47 |
smbbufferputstring(inparam, &c->peerinfo, 0, filename);
|
|
|
48 |
outparam = smbbuffernew(10);
|
|
|
49 |
outdata = smbbuffernew(65535);
|
|
|
50 |
rv = smbclienttrans2(c, 1, &setup, inparam, outparam, outdata, &rh, errmsgp);
|
|
|
51 |
smbbufferfree(&inparam);
|
|
|
52 |
if (rv) {
|
|
|
53 |
ushort eaerroroffset, lastnameoffset;
|
|
|
54 |
ulong nextentry;
|
|
|
55 |
int i;
|
|
|
56 |
|
|
|
57 |
if (!smbbuffergets(outparam, sidp)
|
|
|
58 |
|| !smbbuffergets(outparam, searchcountp)
|
|
|
59 |
|| !smbbuffergets(outparam, endofsearchp)
|
|
|
60 |
|| !smbbuffergets(outparam, &eaerroroffset)
|
|
|
61 |
|| !smbbuffergets(outparam, &lastnameoffset)) {
|
|
|
62 |
smbstringprint(errmsgp, "smbclienttrans2findfirst2: not enough parameters returned");
|
|
|
63 |
rv = 0;
|
|
|
64 |
goto done;
|
|
|
65 |
}
|
|
|
66 |
nextentry = 0;
|
|
|
67 |
smblogprint(-1, "returned data:\n");
|
|
|
68 |
smblogdata(-1, smblogprint, smbbufferreadpointer(outdata), smbbufferreadspace(outdata), 256);
|
|
|
69 |
for (i = 0; i < *searchcountp; i++) {
|
|
|
70 |
SmbFindFileBothDirectoryInfo *info = ip + i;
|
|
|
71 |
ulong neo, filenamelength, easize;
|
|
|
72 |
uchar shortnamelength;
|
|
|
73 |
if (i && !smbbufferreadskipto(outdata, nextentry)) {
|
|
|
74 |
underflow:
|
|
|
75 |
smbstringprint(errmsgp, "smbclientrans2findfirst2: not enough data returned");
|
|
|
76 |
rv = 0;
|
|
|
77 |
goto done;
|
|
|
78 |
}
|
|
|
79 |
if (!smbbuffergetl(outdata, &neo))
|
|
|
80 |
goto underflow;
|
|
|
81 |
nextentry = smbbufferreadoffset(outdata) + neo - 4;
|
|
|
82 |
print("neo 0x%.8lux\n", neo);
|
|
|
83 |
if (!smbbuffergetl(outdata, &info->fileindex)
|
|
|
84 |
|| !smbbuffergetv(outdata, &info->creationtime)
|
|
|
85 |
|| !smbbuffergetv(outdata, &info->lastaccesstime)
|
|
|
86 |
|| !smbbuffergetv(outdata, &info->lastwritetime)
|
|
|
87 |
|| !smbbuffergetv(outdata, &info->changetime)
|
|
|
88 |
|| !smbbuffergetv(outdata, &info->endoffile)
|
|
|
89 |
|| !smbbuffergetv(outdata, &info->allocationsize))
|
|
|
90 |
goto underflow;
|
|
|
91 |
print("got here\n");
|
|
|
92 |
if (!smbbuffergetl(outdata, &info->extfileattributes)
|
|
|
93 |
|| !smbbuffergetl(outdata, &filenamelength)
|
|
|
94 |
|| !smbbuffergetl(outdata, &easize)
|
|
|
95 |
|| !smbbuffergetb(outdata, &shortnamelength)
|
|
|
96 |
|| !smbbuffergetbytes(outdata, nil, 1)
|
|
|
97 |
|| !smbbuffergetbytes(outdata, nil, 24)
|
|
|
98 |
|| !smbbuffergetstring(outdata, &rh, SMB_STRING_REVPATH, &info->filename))
|
|
|
99 |
goto underflow;
|
|
|
100 |
print("got here as well\n");
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
done:
|
|
|
104 |
smbbufferfree(&outparam);
|
|
|
105 |
smbbufferfree(&outdata);
|
|
|
106 |
return rv;
|
|
|
107 |
}
|
|
|
108 |
|