1 #include "headers.h"
2
3 SmbProcessResult
smbcomcheckdirectory(SmbSession * s,SmbHeader * h,uchar *,SmbBuffer * b)4 smbcomcheckdirectory(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
5 {
6 char *path;
7 Dir *d;
8 uchar fmt;
9 SmbProcessResult pr;
10 SmbTree *t;
11 char *fullpath = nil;
12
13 if (!smbcheckwordcount("comcheckdirectory", h, 0))
14 return SmbProcessResultFormat;
15
16 if (!smbbuffergetb(b, &fmt)
17 || fmt != 4
18 || !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
19 return SmbProcessResultFormat;
20
21 t = smbidmapfind(s->tidmap, h->tid);
22 if (t == nil) {
23 smbseterror(s, ERRSRV, ERRinvtid);
24 return SmbProcessResultError;
25 }
26
27 smbstringprint(&fullpath, "%s%s", t->serv->path, path);
28 smblogprintif(1, "smbcomcheckdirectory: statting %s\n", fullpath);
29 d = dirstat(fullpath);
30
31 if (d == nil || (d->mode & DMDIR) == 0) {
32 smbseterror(s, ERRDOS, ERRbadpath);
33 pr = SmbProcessResultError;
34 goto done;
35 }
36
37 if (access(fullpath, AREAD) < 0) {
38 smbseterror(s, ERRDOS, ERRbadpath);
39 pr = SmbProcessResultError;
40 goto done;
41 }
42
43 pr = smbbufferputack(s->response, h, &s->peerinfo) ? SmbProcessResultReply : SmbProcessResultMisc;
44 done:
45 free(fullpath);
46 free(path);
47 free(d);
48 return pr;
49 }
50