smbcomcreatedir.c 933 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "headers.h"
  2. SmbProcessResult
  3. smbcomcreatedirectory(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
  4. {
  5. int fd;
  6. char *path;
  7. char *fullpath = nil;
  8. SmbTree *t;
  9. uchar fmt;
  10. if (h->wordcount != 0)
  11. return SmbProcessResultFormat;
  12. if (!smbbuffergetb(b, &fmt) || fmt != 0x04 || !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
  13. return SmbProcessResultFormat;
  14. smblogprint(h->command, "smbcomcreatedirectory: %s\n", path);
  15. t = smbidmapfind(s->tidmap, h->tid);
  16. if (t == nil) {
  17. smbseterror(s, ERRSRV, ERRinvtid);
  18. return SmbProcessResultError;
  19. }
  20. smbstringprint(&fullpath, "%s%s", t->serv->path, path);
  21. fd = create(fullpath, OREAD, DMDIR | 0775);
  22. if (fd < 0) {
  23. smblogprint(h->command, "smbcomcreatedirectory failed: %r\n");
  24. smbseterror(s, ERRDOS, ERRnoaccess);
  25. free(path);
  26. return SmbProcessResultError;
  27. }
  28. close(fd);
  29. free(fullpath);
  30. free(path);
  31. return smbbufferputack(s->response, h, &s->peerinfo);
  32. }