blob: 1bfbfff92cce6c698d0f74377251d5b4f66f55e1 [file] [log] [blame]
rscbe8b3152004-06-17 03:27:35 +00001#include <u.h>
2#include <libc.h>
3#include <auth.h>
4
5/*
6 * become the authenticated user
7 */
8int
9auth_chuid(AuthInfo *ai, char *ns)
10{
11 int rv, fd;
12
13 if(ai == nil || ai->cap == nil){
14 werrstr("no capability");
15 return -1;
16 }
17
18 /* change uid */
19 fd = open("#¤/capuse", OWRITE);
20 if(fd < 0){
21 werrstr("opening #¤/capuse: %r");
22 return -1;
23 }
24 rv = write(fd, ai->cap, strlen(ai->cap));
25 close(fd);
26 if(rv < 0){
27 werrstr("writing %s to #¤/capuse: %r", ai->cap);
28 return -1;
29 }
30
31 /* get a link to factotum as new user */
32 fd = open("/srv/factotum", ORDWR);
33 if(fd >= 0)
34 mount(fd, -1, "/mnt", MREPL, "");
35
36 /* set up new namespace */
37 return newns(ai->cuid, ns);
38}