rexexec.c 742 B

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