summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aquarela/smbcomdir.c
blob: 72bf827add34fe2cb993e48c6a05968ab0625305 (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
#include "headers.h"

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

	if (!smbcheckwordcount("comcheckdirectory", h, 0))
		return SmbProcessResultFormat;

	if (!smbbuffergetb(b, &fmt)
		|| fmt != 4
		|| !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
		return SmbProcessResultFormat;

	t = smbidmapfind(s->tidmap, h->tid);
	if (t == nil) {
		smbseterror(s, ERRSRV, ERRinvtid);
		return SmbProcessResultError;
	}
	
	smbstringprint(&fullpath, "%s%s", t->serv->path, path);
smblogprintif(1, "smbcomcheckdirectory: statting %s\n", fullpath);
	d = dirstat(fullpath);

	if (d == nil || (d->mode & DMDIR) == 0) {
		smbseterror(s, ERRDOS, ERRbadpath);
		pr = SmbProcessResultError;
		goto done;
	}

	if (access(fullpath, AREAD) < 0) {
		smbseterror(s, ERRDOS, ERRbadpath);
		pr = SmbProcessResultError;
		goto done;
	}

	pr = smbbufferputack(s->response, h, &s->peerinfo) ? SmbProcessResultReply : SmbProcessResultMisc;
done:
	free(fullpath);
	free(path);
	free(d);
	return pr;
}