rexexec.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <bio.h>
  12. #include <auth.h>
  13. /*
  14. * called by listen as rexexec rexexec net dir ...
  15. */
  16. void
  17. main(int argc, char **argv)
  18. {
  19. char buf[8192];
  20. int n, nn;
  21. AuthInfo *ai;
  22. ARGBEGIN{
  23. }ARGEND;
  24. ai = auth_proxy(0, auth_getkey, "proto=p9any role=server");
  25. if(ai == nil)
  26. sysfatal("auth_proxy: %r");
  27. if(strcmp(ai->cuid, "none") == 0)
  28. sysfatal("rexexec by none disallowed");
  29. if(auth_chuid(ai, nil) < 0)
  30. sysfatal("auth_chuid: %r");
  31. n = 0;
  32. do {
  33. nn = read(0, buf+n, 1);
  34. if(nn <= 0)
  35. sysfatal("can't read command");
  36. n += nn;
  37. if(n == sizeof buf)
  38. buf[n-1] = '\0';
  39. } while (buf[n-1] != '\0');
  40. putenv("service", "rx");
  41. execl("/bin/rc", "rc", "-lc", buf, nil);
  42. sysfatal("can't exec rc");
  43. }