smbtrans2client.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. static SmbTransactionMethod method = {
  11. .encodeprimary = smbtransactionencodeprimary2,
  12. .sendrequest = smbtransactionclientsend,
  13. .receiveresponse = smbtransactionclientreceive,
  14. .decoderesponse = smbtransactiondecoderesponse2,
  15. };
  16. int
  17. smbclienttrans2(SmbClient *c, uint8_t scount, uint16_t *setup,
  18. SmbBuffer *inparam, SmbBuffer *outparam, SmbBuffer *outdata,
  19. SmbHeader *rh, char **errmsgp)
  20. {
  21. SmbTransaction transaction;
  22. SmbHeader h;
  23. memset(&transaction, 0, sizeof(transaction));
  24. transaction.in.scount = scount;
  25. transaction.in.setup = setup;
  26. transaction.in.parameters = smbbufferreadpointer(inparam);
  27. transaction.in.tpcount = smbbufferreadspace(inparam);
  28. transaction.in.maxpcount = smbbufferwritespace(outparam);
  29. transaction.in.maxdcount = smbbufferwritespace(outdata);
  30. transaction.out.parameters = outparam;
  31. transaction.out.data = outdata;
  32. h = c->protoh;
  33. h.tid = c->sharetid;
  34. h.mid = 0;
  35. return smbtransactionexecute(&transaction, &h, &c->peerinfo, c->b, &method, c, rh, errmsgp);
  36. }
  37. int
  38. smbclienttrans2findfirst2(SmbClient *c, uint16_t searchcount,
  39. char *filename,
  40. uint16_t *sidp, uint16_t *searchcountp, uint16_t *endofsearchp,SmbFindFileBothDirectoryInfo *ip,
  41. char **errmsgp)
  42. {
  43. int rv;
  44. uint16_t setup;
  45. SmbBuffer *inparam;
  46. SmbBuffer *outparam;
  47. SmbBuffer *outdata;
  48. SmbHeader rh;
  49. setup = SMB_TRANS2_FIND_FIRST2;
  50. inparam = smbbuffernew(512);
  51. smbbufferputs(inparam, 0x16);
  52. smbbufferputs(inparam, searchcount);
  53. smbbufferputs(inparam, 7);
  54. smbbufferputs(inparam, SMB_FIND_FILE_BOTH_DIRECTORY_INFO);
  55. smbbufferputl(inparam, 0);
  56. smbbufferputstring(inparam, &c->peerinfo, 0, filename);
  57. outparam = smbbuffernew(10);
  58. outdata = smbbuffernew(65535);
  59. rv = smbclienttrans2(c, 1, &setup, inparam, outparam, outdata, &rh, errmsgp);
  60. smbbufferfree(&inparam);
  61. if (rv) {
  62. uint16_t eaerroroffset, lastnameoffset;
  63. uint32_t nextentry;
  64. int i;
  65. if (!smbbuffergets(outparam, sidp)
  66. || !smbbuffergets(outparam, searchcountp)
  67. || !smbbuffergets(outparam, endofsearchp)
  68. || !smbbuffergets(outparam, &eaerroroffset)
  69. || !smbbuffergets(outparam, &lastnameoffset)) {
  70. smbstringprint(errmsgp, "smbclienttrans2findfirst2: not enough parameters returned");
  71. rv = 0;
  72. goto done;
  73. }
  74. nextentry = 0;
  75. smblogprint(-1, "returned data:\n");
  76. smblogdata(-1, smblogprint, smbbufferreadpointer(outdata), smbbufferreadspace(outdata), 256);
  77. for (i = 0; i < *searchcountp; i++) {
  78. SmbFindFileBothDirectoryInfo *info = ip + i;
  79. uint32_t neo, filenamelength, easize;
  80. uint8_t shortnamelength;
  81. if (i && !smbbufferreadskipto(outdata, nextentry)) {
  82. underflow:
  83. smbstringprint(errmsgp, "smbclientrans2findfirst2: not enough data returned");
  84. rv = 0;
  85. goto done;
  86. }
  87. if (!smbbuffergetl(outdata, &neo))
  88. goto underflow;
  89. nextentry = smbbufferreadoffset(outdata) + neo - 4;
  90. print("neo 0x%.8lux\n", neo);
  91. if (!smbbuffergetl(outdata, &info->fileindex)
  92. || !smbbuffergetv(outdata, &info->creationtime)
  93. || !smbbuffergetv(outdata, &info->lastaccesstime)
  94. || !smbbuffergetv(outdata, &info->lastwritetime)
  95. || !smbbuffergetv(outdata, &info->changetime)
  96. || !smbbuffergetv(outdata, &info->endoffile)
  97. || !smbbuffergetv(outdata, &info->allocationsize))
  98. goto underflow;
  99. print("got here\n");
  100. if (!smbbuffergetl(outdata, &info->extfileattributes)
  101. || !smbbuffergetl(outdata, &filenamelength)
  102. || !smbbuffergetl(outdata, &easize)
  103. || !smbbuffergetb(outdata, &shortnamelength)
  104. || !smbbuffergetbytes(outdata, nil, 1)
  105. || !smbbuffergetbytes(outdata, nil, 24)
  106. || !smbbuffergetstring(outdata, &rh, SMB_STRING_REVPATH, &info->filename))
  107. goto underflow;
  108. print("got here as well\n");
  109. }
  110. }
  111. done:
  112. smbbufferfree(&outparam);
  113. smbbufferfree(&outdata);
  114. return rv;
  115. }