smbcomdir.c 1.1 KB

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