2 |
- |
1 |
#include "headers.h"
|
|
|
2 |
|
|
|
3 |
SmbProcessResult
|
|
|
4 |
smbcomqueryinformation(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
|
|
|
5 |
{
|
|
|
6 |
SmbTree *t;
|
|
|
7 |
uchar fmt;
|
|
|
8 |
char *path;
|
|
|
9 |
Dir *d;
|
|
|
10 |
char *fullpath;
|
|
|
11 |
|
|
|
12 |
if (!smbcheckwordcount("comqueryinformation", h, 0)
|
|
|
13 |
|| !smbbuffergetb(b, &fmt)
|
|
|
14 |
|| fmt != 4
|
|
|
15 |
|| !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
|
|
|
16 |
return SmbProcessResultFormat;
|
|
|
17 |
t = smbidmapfind(s->tidmap, h->tid);
|
|
|
18 |
if (t == nil) {
|
|
|
19 |
free(path);
|
|
|
20 |
smbseterror(s, ERRSRV, ERRinvtid);
|
|
|
21 |
return SmbProcessResultError;
|
|
|
22 |
}
|
|
|
23 |
smblogprint(h->command, "smbcomqueryinformation: %s\n", path);
|
|
|
24 |
fullpath = nil;
|
|
|
25 |
smbstringprint(&fullpath, "%s%s", t->serv->path, path);
|
|
|
26 |
d = dirstat(fullpath);
|
|
|
27 |
free(fullpath);
|
|
|
28 |
free(path);
|
|
|
29 |
if (d == nil) {
|
|
|
30 |
smbseterror(s, ERRDOS, ERRbadpath);
|
|
|
31 |
return SmbProcessResultError;
|
|
|
32 |
}
|
|
|
33 |
h->wordcount = 10;
|
|
|
34 |
if (!smbbufferputheader(s->response, h, &s->peerinfo)
|
|
|
35 |
|| !smbbufferputs(s->response, smbplan9mode2dosattr(d->mode))
|
|
|
36 |
|| !smbbufferputl(s->response, smbplan9time2utime(d->mtime, s->tzoff))
|
|
|
37 |
|| !smbbufferputl(s->response, smbplan9length2size32(d->length))
|
|
|
38 |
|| !smbbufferfill(s->response, 0, 10)
|
|
|
39 |
|| !smbbufferputs(s->response, 0)) {
|
|
|
40 |
free(d);
|
|
|
41 |
return SmbProcessResultMisc;
|
|
|
42 |
}
|
|
|
43 |
free(d);
|
|
|
44 |
return SmbProcessResultReply;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
SmbProcessResult
|
|
|
48 |
smbcomqueryinformation2(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *)
|
|
|
49 |
{
|
|
|
50 |
SmbTree *t;
|
|
|
51 |
Dir *d;
|
|
|
52 |
ushort fid;
|
|
|
53 |
ushort mtime, mdate;
|
|
|
54 |
ushort atime, adate;
|
|
|
55 |
SmbFile *f;
|
|
|
56 |
|
|
|
57 |
if (!smbcheckwordcount("comqueryinformation2", h, 1))
|
|
|
58 |
return SmbProcessResultFormat;
|
|
|
59 |
fid = smbnhgets(pdata);
|
|
|
60 |
t = smbidmapfind(s->tidmap, h->tid);
|
|
|
61 |
if (t == nil) {
|
|
|
62 |
smbseterror(s, ERRSRV, ERRinvtid);
|
|
|
63 |
return SmbProcessResultError;
|
|
|
64 |
}
|
|
|
65 |
f = smbidmapfind(s->fidmap, fid);
|
|
|
66 |
if (f == nil) {
|
|
|
67 |
smbseterror(s, ERRDOS, ERRbadfid);
|
|
|
68 |
return SmbProcessResultError;
|
|
|
69 |
}
|
|
|
70 |
d = dirfstat(f->fd);
|
|
|
71 |
if (d == nil) {
|
|
|
72 |
smbseterror(s, ERRDOS, ERRbadpath);
|
|
|
73 |
return SmbProcessResultError;
|
|
|
74 |
}
|
|
|
75 |
h->wordcount = 11;
|
|
|
76 |
smbplan9time2datetime(d->atime, s->tzoff, &adate, &atime);
|
|
|
77 |
smbplan9time2datetime(d->mtime, s->tzoff, &mdate, &mtime);
|
|
|
78 |
if (!smbbufferputheader(s->response, h, &s->peerinfo)
|
|
|
79 |
|| !smbbufferputs(s->response, mdate)
|
|
|
80 |
|| !smbbufferputs(s->response, mtime)
|
|
|
81 |
|| !smbbufferputs(s->response, adate)
|
|
|
82 |
|| !smbbufferputs(s->response, atime)
|
|
|
83 |
|| !smbbufferputs(s->response, mdate)
|
|
|
84 |
|| !smbbufferputs(s->response, mtime)
|
|
|
85 |
|| !smbbufferputl(s->response, smbplan9length2size32(d->length))
|
|
|
86 |
|| !smbbufferputl(s->response,
|
|
|
87 |
smbplan9length2size32(smbl2roundupvlong(d->length, smbglobals.l2allocationsize)))
|
|
|
88 |
|| !smbbufferputs(s->response, smbplan9mode2dosattr(d->mode))
|
|
|
89 |
|| !smbbufferputs(s->response, 0)) {
|
|
|
90 |
free(d);
|
|
|
91 |
return SmbProcessResultMisc;
|
|
|
92 |
}
|
|
|
93 |
free(d);
|
|
|
94 |
return SmbProcessResultReply;
|
|
|
95 |
}
|