none.c 1.3 KB

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