smbclientopen.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. int
  11. smbclientopen(SmbClient *c, uint16_t mode, char *name, uint8_t *errclassp,
  12. uint16_t *errorp,
  13. uint16_t *fidp, uint16_t *attrp, uint32_t *mtimep, uint32_t *sizep,
  14. uint16_t *accessallowedp, char **errmsgp)
  15. {
  16. SmbBuffer *b;
  17. SmbHeader h;
  18. uint32_t bytecountfixup;
  19. int32_t n;
  20. uint8_t *pdata;
  21. uint16_t bytecount;
  22. b = smbbuffernew(65535);
  23. h = c->protoh;
  24. h.tid = c->sharetid;
  25. h.command = SMB_COM_OPEN;
  26. h.wordcount = 2;
  27. smbbufferputheader(b, &h, &c->peerinfo);
  28. smbbufferputs(b, mode);
  29. smbbufferputs(b, 0);
  30. bytecountfixup = smbbufferwriteoffset(b);
  31. smbbufferputs(b, 0);
  32. smbbufferputb(b, 4);
  33. smbbufferputstring(b, &c->peerinfo, SMB_STRING_REVPATH, name);
  34. smbbufferfixuprelatives(b, bytecountfixup);
  35. nbsswrite(c->nbss, smbbufferreadpointer(b), smbbufferwriteoffset(b));
  36. smbbufferreset(b);
  37. n = nbssread(c->nbss, smbbufferwritepointer(b), smbbufferwritespace(b));
  38. if (n < 0) {
  39. smbstringprint(errmsgp, "read error: %r");
  40. smbbufferfree(&b);
  41. return 0;
  42. }
  43. smbbuffersetreadlen(b, n);
  44. if (!smbbuffergetandcheckheader(b, &h, h.command, 7, &pdata, &bytecount, errmsgp)) {
  45. smbbufferfree(&b);
  46. return 0;
  47. }
  48. if (h.errclass) {
  49. *errclassp = h.errclass;
  50. *errorp = h.error;
  51. smbbufferfree(&b);
  52. return 0;
  53. }
  54. *fidp = smbnhgets(pdata); pdata += 2;
  55. *attrp = smbnhgets(pdata); pdata += 2;
  56. *mtimep = smbnhgetl(pdata); pdata += 4;
  57. *sizep = smbnhgets(pdata); pdata += 4;
  58. *accessallowedp = smbnhgets(pdata);
  59. return 1;
  60. }