smbcomdir.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "headers.h"
  10. SmbProcessResult
  11. smbcomcheckdirectory(SmbSession *s, SmbHeader *h, uint8_t *l, SmbBuffer *b)
  12. {
  13. char *path;
  14. Dir *d;
  15. uint8_t fmt;
  16. SmbProcessResult pr;
  17. SmbTree *t;
  18. char *fullpath = nil;
  19. if (!smbcheckwordcount("comcheckdirectory", h, 0))
  20. return SmbProcessResultFormat;
  21. if (!smbbuffergetb(b, &fmt)
  22. || fmt != 4
  23. || !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
  24. return SmbProcessResultFormat;
  25. t = smbidmapfind(s->tidmap, h->tid);
  26. if (t == nil) {
  27. smbseterror(s, ERRSRV, ERRinvtid);
  28. return SmbProcessResultError;
  29. }
  30. smbstringprint(&fullpath, "%s%s", t->serv->path, path);
  31. smblogprintif(1, "smbcomcheckdirectory: statting %s\n", fullpath);
  32. d = dirstat(fullpath);
  33. if (d == nil || (d->mode & DMDIR) == 0) {
  34. smbseterror(s, ERRDOS, ERRbadpath);
  35. pr = SmbProcessResultError;
  36. goto done;
  37. }
  38. if (access(fullpath, AREAD) < 0) {
  39. smbseterror(s, ERRDOS, ERRbadpath);
  40. pr = SmbProcessResultError;
  41. goto done;
  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. }