transnt.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <u.h>
  10. #include <libc.h>
  11. #include <fcall.h>
  12. #include <thread.h>
  13. #include <9p.h>
  14. #include "cifs.h"
  15. static Pkt *
  16. tnthdr(Session *s, Share *sp, int cmd)
  17. {
  18. Pkt *p;
  19. p = cifshdr(s, sp, SMB_COM_NT_TRANSACT);
  20. p->tbase = p8(p, 0); /* 0 Max setup count to return */
  21. pl16(p, 0); /* 1 reserved */
  22. pl32(p, 0); /* 3 Total parameter count */
  23. pl32(p, 0); /* 7 Total data count */
  24. pl32(p, 64); /* 11 Max parameter count to return */
  25. pl32(p, (MTU - T2HDRLEN)-64); /* 15 Max data count to return */
  26. pl32(p, 0); /* 19 Parameter count (in this buffer) */
  27. pl32(p, 0); /* 23 Offset to parameters (in this buffer) */
  28. pl32(p, 0); /* 27 Count of data in this buffer */
  29. pl32(p, 0); /* 31 Offset to data in this buffer */
  30. p8(p, 1); /* 35 Count of setup words */
  31. pl16(p, cmd); /* 37 setup[0] */
  32. pl16(p, 0); /* padding ??!?!? */
  33. pbytes(p);
  34. return p;
  35. }
  36. static void
  37. ptntparam(Pkt *p)
  38. {
  39. uint8_t *pos = p->pos;
  40. assert(p->tbase != 0);
  41. p->pos = p->tbase +23;
  42. pl32(p, (pos - p->buf) - NBHDRLEN); /* param offset */
  43. p->tparam = p->pos = pos;
  44. }
  45. static void
  46. ptntdata(Pkt *p)
  47. {
  48. uint8_t *pos = p->pos;
  49. assert(p->tbase != 0);
  50. assert(p->tparam != 0);
  51. p->pos = p->tbase +3;
  52. pl32(p, pos - p->tparam); /* total param count */
  53. p->pos = p->tbase +19;
  54. pl32(p, pos - p->tparam); /* param count */
  55. p->pos = p->tbase +31;
  56. pl32(p, (pos - p->buf) - NBHDRLEN); /* data offset */
  57. p->tdata = p->pos = pos;
  58. }
  59. static int
  60. tntrpc(Pkt *p)
  61. {
  62. int got;
  63. uint8_t *pos;
  64. assert(p->tbase != 0);
  65. assert(p->tdata != 0);
  66. pos = p->pos;
  67. p->pos = p->tbase +7;
  68. pl32(p, pos - p->tdata); /* total data count */
  69. p->pos = p->tbase +27;
  70. pl32(p, pos - p->tdata); /* data count */
  71. p->pos = pos;
  72. if((got = cifsrpc(p)) == -1)
  73. return -1;
  74. g8(p); /* Reserved */
  75. g8(p); /* Reserved */
  76. g8(p); /* Reserved */
  77. gl32(p); /* Total parameter count */
  78. gl32(p); /* Total data count */
  79. gl32(p); /* Parameter count in this buffer */
  80. p->tparam = p->buf +NBHDRLEN +gl32(p); /* Parameter offset */
  81. gl32(p); /* Parameter displacement */
  82. gl32(p); /* Data count (this buffer); */
  83. p->tdata = p->buf +NBHDRLEN +gl32(p); /* Data offset */
  84. gl32(p); /* Data displacement */
  85. g8(p); /* Setup count */
  86. gl16(p); /* padding ??? */
  87. return got;
  88. }
  89. static void
  90. gtntdata(Pkt *p)
  91. {
  92. p->pos = p->tdata;
  93. }
  94. int
  95. TNTquerysecurity(Session *s, Share *sp, int fh, char **usid, char **gsid)
  96. {
  97. Pkt *p;
  98. uint8_t *base;
  99. Fmt fmt, *f = &fmt;
  100. int n, i, off2owner, off2group;
  101. p = tnthdr(s, sp, NT_TRANSACT_QUERY_SECURITY_DESC);
  102. ptntparam(p);
  103. pl16(p, fh); /* File handle */
  104. pl16(p, 0); /* Reserved */
  105. pl32(p, QUERY_OWNER_SECURITY_INFORMATION |
  106. QUERY_GROUP_SECURITY_INFORMATION);
  107. ptntdata(p);
  108. if(tntrpc(p) == -1){
  109. free(p);
  110. return -1;
  111. }
  112. gtntdata(p);
  113. base = p->pos;
  114. gl16(p); /* revision */
  115. gl16(p); /* type */
  116. off2owner = gl32(p); /* offset to owner */
  117. off2group = gl32(p); /* offset to group */
  118. gl32(p);
  119. gl32(p);
  120. if(off2owner){
  121. p->pos = base + off2owner;
  122. fmtstrinit(f);
  123. fmtprint(f, "S-%u", g8(p)); /* revision */
  124. n = g8(p); /* num auth */
  125. fmtprint(f, "-%llu", gb48(p)); /* authority */
  126. for(i = 0; i < n; i++)
  127. fmtprint(f, "-%u", gl32(p)); /* sub-authorities */
  128. *usid = fmtstrflush(f);
  129. }
  130. if(off2group){
  131. p->pos = base + off2group;
  132. fmtstrinit(f);
  133. fmtprint(f, "S-%u", g8(p)); /* revision */
  134. n = g8(p); /* num auth */
  135. fmtprint(f, "-%llu", gb48(p)); /* authority */
  136. for(i = 0; i < n; i++)
  137. fmtprint(f, "-%u", gl32(p)); /* sub-authorities */
  138. *gsid = fmtstrflush(f);
  139. }
  140. free(p);
  141. return 0;
  142. }