smbcomquery.c 3.1 KB

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