none.c 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. char *namespace;
  5. void
  6. usage(void)
  7. {
  8. fprint(2, "usage: auth/none [-n namespace] [cmd ...]\n");
  9. exits("usage");
  10. }
  11. void
  12. main(int argc, char *argv[])
  13. {
  14. char cmd[256];
  15. int fd;
  16. ARGBEGIN{
  17. case 'n':
  18. namespace = EARGF(usage());
  19. break;
  20. default:
  21. usage();
  22. }ARGEND
  23. if (rfork(RFENVG|RFNAMEG) < 0)
  24. sysfatal("can't make new pgrp");
  25. fd = open("#c/user", OWRITE);
  26. if (fd < 0)
  27. sysfatal("can't open #c/user");
  28. if (write(fd, "none", strlen("none")) < 0)
  29. sysfatal("can't become none");
  30. close(fd);
  31. if (newns("none", namespace) < 0)
  32. sysfatal("can't build namespace");
  33. if (argc > 0) {
  34. strecpy(cmd, cmd+sizeof cmd, argv[0]);
  35. exec(cmd, &argv[0]);
  36. if (strncmp(cmd, "/", 1) != 0
  37. && strncmp(cmd, "./", 2) != 0
  38. && strncmp(cmd, "../", 3) != 0) {
  39. snprint(cmd, sizeof cmd, "/bin/%s", argv[0]);
  40. exec(cmd, &argv[0]);
  41. }
  42. } else {
  43. strcpy(cmd, "/bin/rc");
  44. execl(cmd, cmd, nil);
  45. }
  46. sysfatal(cmd);
  47. }