smbcomtransaction.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 int
  11. sendresponse(void *magic, SmbBuffer *sb, char **errmsgp)
  12. {
  13. int rv;
  14. SmbSession *s = magic;
  15. rv = smbresponsesend(s);
  16. if (rv < 0) {
  17. smbstringprint(errmsgp, "sendresponse failed");
  18. return 0;
  19. }
  20. return 1;
  21. }
  22. SmbTransactionMethod smbtransactionmethod = {
  23. .encoderesponse = smbtransactionencoderesponse,
  24. .sendresponse = sendresponse,
  25. };
  26. SmbTransactionMethod smbtransactionmethod2 = {
  27. .encoderesponse = smbtransactionencoderesponse2,
  28. .sendresponse = sendresponse,
  29. };
  30. SmbProcessResult
  31. smbcomtransaction(SmbSession *s, SmbHeader *h, uint8_t *pdata, SmbBuffer *b)
  32. {
  33. int rv;
  34. char *errmsg;
  35. SmbProcessResult pr = SmbProcessResultDie;
  36. errmsg = nil;
  37. rv = smbtransactiondecodeprimary(&s->transaction, h, pdata, b, &errmsg);
  38. if (rv < 0) {
  39. pr = SmbProcessResultFormat;
  40. goto done;
  41. }
  42. if (rv == 0) {
  43. h->wordcount = 0;
  44. if (smbbufferputack(s->response, h, &s->peerinfo)) {
  45. pr = SmbProcessResultReply;
  46. s->nextcommand = SMB_COM_TRANSACTION_SECONDARY;
  47. }
  48. goto done;
  49. }
  50. smblogprint(h->command, "smbcomtransaction: %s scount %u tpcount %lu tdcount %lu maxscount %lu maxpcount %lu maxdcount %lu\n",
  51. s->transaction.in.name, s->transaction.in.scount, s->transaction.in.tpcount, s->transaction.in.tdcount,
  52. s->transaction.in.maxscount, s->transaction.in.maxpcount, s->transaction.in.maxdcount);
  53. smbbufferfree(&s->transaction.out.parameters);
  54. smbbufferfree(&s->transaction.out.data);
  55. s->transaction.out.parameters = smbbuffernew(s->transaction.in.maxpcount);
  56. s->transaction.out.data = smbbuffernew(s->transaction.in.maxdcount);
  57. if (strcmp(s->transaction.in.name, smbglobals.pipelanman) == 0)
  58. pr = smbrap2(s);
  59. else {
  60. smbseterror(s, ERRDOS, ERRbadpath);
  61. pr = SmbProcessResultError;
  62. goto done;
  63. }
  64. if (pr == SmbProcessResultReply) {
  65. char *errmsg;
  66. errmsg = nil;
  67. rv = smbtransactionrespond(&s->transaction, h, &s->peerinfo, s->response, &smbtransactionmethod, s, &errmsg);
  68. if (!rv) {
  69. smblogprint(h->command, "smbcomtransaction: failed: %s\n", errmsg);
  70. pr = SmbProcessResultMisc;
  71. }
  72. else
  73. pr = SmbProcessResultOk;
  74. }
  75. done:
  76. free(errmsg);
  77. return pr;
  78. }
  79. SmbProcessResult
  80. smbcomtransaction2(SmbSession *s, SmbHeader *h, uint8_t *pdata, SmbBuffer *b)
  81. {
  82. int rv;
  83. char *errmsg;
  84. SmbProcessResult pr = SmbProcessResultDie;
  85. uint16_t op;
  86. errmsg = nil;
  87. rv = smbtransactiondecodeprimary2(&s->transaction, h, pdata, b, &errmsg);
  88. if (rv < 0) {
  89. fmtfail:
  90. pr = SmbProcessResultFormat;
  91. goto done;
  92. }
  93. if (rv == 0) {
  94. h->wordcount = 0;
  95. if (smbbufferputack(s->response, h, &s->peerinfo)) {
  96. pr = SmbProcessResultReply;
  97. s->nextcommand = SMB_COM_TRANSACTION2_SECONDARY;
  98. }
  99. goto done;
  100. }
  101. smblogprint(h->command, "smbcomtransaction2: scount %u tpcount %lu tdcount %lu maxscount %lu maxpcount %lu maxdcount %lu\n",
  102. s->transaction.in.scount, s->transaction.in.tpcount, s->transaction.in.tdcount,
  103. s->transaction.in.maxscount, s->transaction.in.maxpcount, s->transaction.in.maxdcount);
  104. smbbufferfree(&s->transaction.out.parameters);
  105. smbbufferfree(&s->transaction.out.data);
  106. s->transaction.out.parameters = smbbuffernew(s->transaction.in.maxpcount);
  107. s->transaction.out.data = smbbuffernew(s->transaction.in.maxdcount);
  108. if (s->transaction.in.scount != 1)
  109. goto fmtfail;
  110. op = s->transaction.in.setup[0];
  111. if (op >= smbtrans2optablesize || smbtrans2optable[op].name == nil) {
  112. smblogprint(-1, "smbcomtransaction2: function %d unknown\n", op);
  113. pr = SmbProcessResultUnimp;
  114. goto done;
  115. }
  116. if (smbtrans2optable[op].process == nil) {
  117. smblogprint(-1, "smbcomtransaction2: %s unimplemented\n", smbtrans2optable[op].name);
  118. pr = SmbProcessResultUnimp;
  119. goto done;
  120. }
  121. pr = (*smbtrans2optable[op].process)(s, h);
  122. if (pr == SmbProcessResultReply) {
  123. char *errmsg;
  124. errmsg = nil;
  125. rv = smbtransactionrespond(&s->transaction, h, &s->peerinfo, s->response, &smbtransactionmethod2, s, &errmsg);
  126. if (!rv) {
  127. smblogprint(h->command, "smbcomtransaction2: failed: %s\n", errmsg);
  128. pr = SmbProcessResultMisc;
  129. }
  130. else
  131. pr = SmbProcessResultOk;
  132. }
  133. done:
  134. free(errmsg);
  135. return pr;
  136. }