authunix.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include <sunrpc.h>
  5. uint
  6. sunAuthUnixSize(SunAuthUnix *x)
  7. {
  8. return 4 + sunStringSize(x->sysname) + 4 + 4 + 4 + 4*x->ng;
  9. }
  10. int
  11. sunAuthUnixUnpack(uchar *a, uchar *ea, uchar **pa, SunAuthUnix *x)
  12. {
  13. int i;
  14. if(sunUint32Unpack(a, ea, &a, &x->stamp) < 0) goto Err;
  15. if(sunStringUnpack(a, ea, &a, &x->sysname, 256) < 0) goto Err;
  16. if(sunUint32Unpack(a, ea, &a, &x->uid) < 0) goto Err;
  17. if(sunUint32Unpack(a, ea, &a, &x->gid) < 0) goto Err;
  18. if(sunUint32Unpack(a, ea, &a, &x->ng) < 0 || x->ng > nelem(x->g)) goto Err;
  19. for(i=0; i<x->ng; i++)
  20. if(sunUint32Unpack(a, ea, &a, &x->g[i]) < 0) goto Err;
  21. *pa = a;
  22. return 0;
  23. Err:
  24. *pa = ea;
  25. return -1;
  26. }
  27. int
  28. sunAuthUnixPack(uchar *a, uchar *ea, uchar **pa, SunAuthUnix *x)
  29. {
  30. int i;
  31. if(sunUint32Pack(a, ea, &a, &x->stamp) < 0) goto Err;
  32. if(sunStringPack(a, ea, &a, &x->sysname, 256) < 0) goto Err;
  33. if(sunUint32Pack(a, ea, &a, &x->uid) < 0) goto Err;
  34. if(sunUint32Pack(a, ea, &a, &x->gid) < 0) goto Err;
  35. if(sunUint32Pack(a, ea, &a, &x->ng) < 0 || x->ng > nelem(x->g)) goto Err;
  36. for(i=0; i<x->ng; i++)
  37. if(sunUint32Pack(a, ea, &a, &x->g[i]) < 0) goto Err;
  38. *pa = a;
  39. return 0;
  40. Err:
  41. *pa = ea;
  42. return -1;
  43. }
  44. void
  45. sunAuthUnixPrint(Fmt *fmt, SunAuthUnix *x)
  46. {
  47. int i;
  48. fmtprint(fmt, "unix %.8lux %s %lud %lud (", (ulong)x->stamp,
  49. x->sysname, (ulong)x->uid, (ulong)x->gid);
  50. for(i=0; i<x->ng; i++)
  51. fmtprint(fmt, "%s%lud", i ? " ":"", (ulong)x->g[i]);
  52. fmtprint(fmt, ")");
  53. }