From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <0c1a28eaa3675826962acdf5f048a410@plan9.bell-labs.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] as.c -- invoke things as another user. From: "Russ Cox" In-Reply-To: <200301202115.h0KLFhw19151@augusta.math.psu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Jan 2003 16:20:58 -0500 Topicbox-Message-UUID: 44634d3c-eacb-11e9-9e20-41e7f4b1d025 The only user name you can write to #c is none, so a few of us use a short C program called none: #include #include #include void main(int argc, char *argv[]) { char cmd[8192]; int fd; argv0 = argv[0]; if (rfork(RFENVG|RFNAMEG) < 0) sysfatal("can't make new pgrp"); fd = open("#c/user", OWRITE); if (fd < 0) sysfatal("can't open #c/user"); if (write(fd, "none", strlen("none")) < 0) sysfatal("can't become none"); close(fd); if (newns("none", nil) < 0) sysfatal("can't build namespace"); if (argc > 1) { strcpy(cmd, argv[1]); exec(cmd, &argv[1]); if (strncmp(cmd, "/", 1) != 0 && strncmp(cmd, "./", 2) != 0 && strncmp(cmd, "../", 3) != 0) { sprint(cmd, "/bin/%s", argv[1]); exec(cmd, &argv[1]); } } else { strcpy(cmd, "/bin/rc"); execl(cmd, cmd, nil); } sysfatal(cmd); }