smbcomrename.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. smbcomrename(SmbSession *s, SmbHeader *h, uint8_t *l, SmbBuffer *b)
  12. {
  13. int rv;
  14. char *old, *new;
  15. char *oldpath = nil;
  16. char *newpath = nil;
  17. char *olddir, *newdir;
  18. char *oldname, *newname;
  19. uint8_t oldfmt, newfmt;
  20. SmbTree *t;
  21. Dir d;
  22. SmbProcessResult pr;
  23. if (h->wordcount != 1)
  24. return SmbProcessResultFormat;
  25. if (!smbbuffergetb(b, &oldfmt) || oldfmt != 0x04 || !smbbuffergetstring(b, h, SMB_STRING_PATH, &old)
  26. || !smbbuffergetb(b, &newfmt) || newfmt != 0x04 || !smbbuffergetstring(b, h, SMB_STRING_PATH, &new))
  27. return SmbProcessResultFormat;
  28. t = smbidmapfind(s->tidmap, h->tid);
  29. if (t == nil) {
  30. smbseterror(s, ERRSRV, ERRinvtid);
  31. return SmbProcessResultError;
  32. }
  33. smbstringprint(&oldpath, "%s%s", t->serv->path, old);
  34. smbstringprint(&newpath, "%s%s", t->serv->path, new);
  35. smblogprint(h->command, "smbcomrename: %s to %s\n", oldpath, newpath);
  36. smbpathsplit(oldpath, &olddir, &oldname);
  37. smbpathsplit(newpath, &newdir, &newname);
  38. if (strcmp(olddir, newdir) != 0) {
  39. smblogprint(h->command, "smbcomrename: directories differ\n");
  40. goto noaccess;
  41. }
  42. memset(&d, 0xff, sizeof(d));
  43. d.uid = d.gid = d.muid = nil;
  44. d.name = newname;
  45. rv = dirwstat(oldpath, &d);
  46. if (rv < 0) {
  47. smblogprint(h->command, "smbcomrename failed: %r\n");
  48. noaccess:
  49. smbseterror(s, ERRDOS, ERRnoaccess);
  50. pr = SmbProcessResultError;
  51. }
  52. else
  53. pr = smbbufferputack(s->response, h, &s->peerinfo);
  54. free(oldpath);
  55. free(olddir);
  56. free(oldname);
  57. free(newpath);
  58. free(newdir);
  59. free(newname);
  60. return pr;
  61. }