smbcomquery.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "headers.h"
  2. SmbProcessResult
  3. smbcomqueryinformation(SmbSession *s, SmbHeader *h, uchar *, SmbBuffer *b)
  4. {
  5. SmbTree *t;
  6. uchar fmt;
  7. char *path;
  8. Dir *d;
  9. char *fullpath;
  10. if (!smbcheckwordcount("comqueryinformation", h, 0)
  11. || !smbbuffergetb(b, &fmt)
  12. || fmt != 4
  13. || !smbbuffergetstring(b, h, SMB_STRING_PATH, &path))
  14. return SmbProcessResultFormat;
  15. t = smbidmapfind(s->tidmap, h->tid);
  16. if (t == nil) {
  17. free(path);
  18. smbseterror(s, ERRSRV, ERRinvtid);
  19. return SmbProcessResultError;
  20. }
  21. smblogprint(h->command, "smbcomqueryinformation: %s\n", path);
  22. fullpath = nil;
  23. smbstringprint(&fullpath, "%s%s", t->serv->path, path);
  24. d = dirstat(fullpath);
  25. free(fullpath);
  26. free(path);
  27. if (d == nil) {
  28. smbseterror(s, ERRDOS, ERRbadpath);
  29. return SmbProcessResultError;
  30. }
  31. h->wordcount = 10;
  32. if (!smbbufferputheader(s->response, h, &s->peerinfo)
  33. || !smbbufferputs(s->response, smbplan9mode2dosattr(d->mode))
  34. || !smbbufferputl(s->response, smbplan9time2utime(d->mtime, s->tzoff))
  35. || !smbbufferputl(s->response, smbplan9length2size32(d->length))
  36. || !smbbufferfill(s->response, 0, 10)
  37. || !smbbufferputs(s->response, 0)) {
  38. free(d);
  39. return SmbProcessResultMisc;
  40. }
  41. free(d);
  42. return SmbProcessResultReply;
  43. }
  44. SmbProcessResult
  45. smbcomqueryinformation2(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *)
  46. {
  47. SmbTree *t;
  48. Dir *d;
  49. ushort fid;
  50. ushort mtime, mdate;
  51. ushort atime, adate;
  52. SmbFile *f;
  53. if (!smbcheckwordcount("comqueryinformation2", h, 1))
  54. return SmbProcessResultFormat;
  55. fid = smbnhgets(pdata);
  56. t = smbidmapfind(s->tidmap, h->tid);
  57. if (t == nil) {
  58. smbseterror(s, ERRSRV, ERRinvtid);
  59. return SmbProcessResultError;
  60. }
  61. f = smbidmapfind(s->fidmap, fid);
  62. if (f == nil) {
  63. smbseterror(s, ERRDOS, ERRbadfid);
  64. return SmbProcessResultError;
  65. }
  66. d = dirfstat(f->fd);
  67. if (d == nil) {
  68. smbseterror(s, ERRDOS, ERRbadpath);
  69. return SmbProcessResultError;
  70. }
  71. h->wordcount = 11;
  72. smbplan9time2datetime(d->atime, s->tzoff, &adate, &atime);
  73. smbplan9time2datetime(d->mtime, s->tzoff, &mdate, &mtime);
  74. if (!smbbufferputheader(s->response, h, &s->peerinfo)
  75. || !smbbufferputs(s->response, mdate)
  76. || !smbbufferputs(s->response, mtime)
  77. || !smbbufferputs(s->response, adate)
  78. || !smbbufferputs(s->response, atime)
  79. || !smbbufferputs(s->response, mdate)
  80. || !smbbufferputs(s->response, mtime)
  81. || !smbbufferputl(s->response, smbplan9length2size32(d->length))
  82. || !smbbufferputl(s->response,
  83. smbplan9length2size32(smbl2roundupvlong(d->length, smbglobals.l2allocationsize)))
  84. || !smbbufferputs(s->response, smbplan9mode2dosattr(d->mode))
  85. || !smbbufferputs(s->response, 0)) {
  86. free(d);
  87. return SmbProcessResultMisc;
  88. }
  89. free(d);
  90. return SmbProcessResultReply;
  91. }