1 #include <u.h> 2 #include <libc.h> 3 #include <auth.h> 4 5 char *namespace; 6 7 void 8 usage(void) 9 { 10 fprint(2, "usage: auth/none [-n namespace] [cmd ...]\n"); 11 exits("usage"); 12 } 13 14 void 15 main(int argc, char *argv[]) 16 { 17 char cmd[256]; 18 int fd; 19 20 ARGBEGIN{ 21 case 'n': 22 namespace = EARGF(usage()); 23 break; 24 default: 25 usage(); 26 }ARGEND 27 28 if (rfork(RFENVG|RFNAMEG) < 0) 29 sysfatal("can't make new pgrp"); 30 31 fd = open("#c/user", OWRITE); 32 if (fd < 0) 33 sysfatal("can't open #c/user"); 34 if (write(fd, "none", strlen("none")) < 0) 35 sysfatal("can't become none"); 36 close(fd); 37 38 if (newns("none", namespace) < 0) 39 sysfatal("can't build namespace"); 40 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 } 56