smbcomrename.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "headers.h"
  2. SmbProcessResult
  3. smbcomrename(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
  4. {
  5. int rv;
  6. char *old, *new;
  7. char *oldpath = nil;
  8. char *newpath = nil;
  9. char *olddir, *newdir;
  10. char *oldname, *newname;
  11. uchar oldfmt, newfmt;
  12. Dir d;
  13. SmbProcessResult pr;
  14. if (h->wordcount != 1)
  15. return SmbProcessResultFormat;
  16. if (!smbbuffergetb(b, &oldfmt) || oldfmt != 0x04 || !smbbuffergetstring(b, h, SMB_STRING_PATH, &old)
  17. || !smbbuffergetb(b, &newfmt) || newfmt != 0x04 || !smbbuffergetstring(b, h, SMB_STRING_PATH, &new))
  18. return SmbProcessResultFormat;
  19. smbstringprint(&oldpath, "%s%s", s->serv->path, old);
  20. smbstringprint(&newpath, "%s%s", s->serv->path, new);
  21. smblogprint(h->command, "smbcomrename: %s to %s\n", oldpath, newpath);
  22. smbpathsplit(oldpath, &olddir, &oldname);
  23. smbpathsplit(newpath, &newdir, &newname);
  24. if (strcmp(olddir, newdir) != 0) {
  25. smblogprint(h->command, "smbcomrename: directories differ\n");
  26. goto noaccess;
  27. }
  28. memset(&d, 0xff, sizeof(d));
  29. d.uid = d.gid = d.muid = nil;
  30. d.name = newname;
  31. rv = dirwstat(oldpath, &d);
  32. if (rv < 0) {
  33. smblogprint(h->command, "smbcomrename failed: %r\n");
  34. noaccess:
  35. smbseterror(s, ERRDOS, ERRnoaccess);
  36. pr = SmbProcessResultError;
  37. }
  38. else
  39. pr = smbbufferputack(s->response, h, &s->peerinfo);
  40. free(oldpath);
  41. free(olddir);
  42. free(oldname);
  43. free(newpath);
  44. free(newdir);
  45. free(newname);
  46. return pr;
  47. }