summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aquarela/smbcomquery.c
blob: daea6c78e784300c790af4220c676e69cf1248d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "headers.h"

SmbProcessResult
smbcomqueryinformation(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
{
	SmbTree *t;
	uchar fmt;
	char *path;
	Dir *d;
	char *fullpath;

	if (!smbcheckwordcount("comqueryinformation", h, 0)
		|| !smbbuffergetb(b, &fmt)
		|| fmt != 4
		|| !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
		return SmbProcessResultFormat;
	t = smbidmapfind(s->tidmap, h->tid);
	if (t == nil) {
		free(path);
		smbseterror(s, ERRSRV, ERRinvtid);
		return SmbProcessResultError;
	}
	smblogprint(h->command, "smbcomqueryinformation: %s\n", path);
	fullpath = nil;
	smbstringprint(&fullpath, "%s%s", t->serv->path, path);
	d = dirstat(fullpath);
	free(fullpath);
	free(path);
	if (d == nil) {
		smbseterror(s, ERRDOS, ERRbadpath);
		return SmbProcessResultError;
	}
	h->wordcount = 10;
	if (!smbbufferputheader(s->response, h, &s->peerinfo)
		|| !smbbufferputs(s->response, smbplan9mode2dosattr(d->mode))
		|| !smbbufferputl(s->response, smbplan9time2utime(d->mtime, s->tzoff))
		|| !smbbufferputl(s->response, smbplan9length2size32(d->length))
		|| !smbbufferfill(s->response, 0, 10)
		|| !smbbufferputs(s->response, 0)) {
		free(d);
		return SmbProcessResultMisc;
	}
	free(d);
	return SmbProcessResultReply;
}

SmbProcessResult
smbcomqueryinformation2(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *)
{
	SmbTree *t;
	Dir *d;
	ushort fid;
	ushort mtime, mdate;
	ushort atime, adate;
	SmbFile *f;

	if (!smbcheckwordcount("comqueryinformation2", h, 1))
		return SmbProcessResultFormat;
	fid = smbnhgets(pdata);
	t = smbidmapfind(s->tidmap, h->tid);
	if (t == nil) {
		smbseterror(s, ERRSRV, ERRinvtid);
		return SmbProcessResultError;
	}
	f = smbidmapfind(s->fidmap, fid);
	if (f == nil) {
		smbseterror(s, ERRDOS, ERRbadfid);
		return SmbProcessResultError;
	}
	d = dirfstat(f->fd);
	if (d == nil) {
		smbseterror(s, ERRDOS, ERRbadpath);
		return SmbProcessResultError;
	}
	h->wordcount = 11;
	smbplan9time2datetime(d->atime, s->tzoff, &adate, &atime);
	smbplan9time2datetime(d->mtime, s->tzoff, &mdate, &mtime);
	if (!smbbufferputheader(s->response, h, &s->peerinfo)
		|| !smbbufferputs(s->response, mdate)
		|| !smbbufferputs(s->response, mtime)
		|| !smbbufferputs(s->response, adate)
		|| !smbbufferputs(s->response, atime)
		|| !smbbufferputs(s->response, mdate)
		|| !smbbufferputs(s->response, mtime)
		|| !smbbufferputl(s->response, smbplan9length2size32(d->length))
		|| !smbbufferputl(s->response,
			smbplan9length2size32(smbl2roundupvlong(d->length, smbglobals.l2allocationsize)))
		|| !smbbufferputs(s->response, smbplan9mode2dosattr(d->mode))
		|| !smbbufferputs(s->response, 0)) {
		free(d);
		return SmbProcessResultMisc;
	}
	free(d);
	return SmbProcessResultReply;
}