]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libauth/auth_chuid.c
libauth: add sanity check for auth_proxy write size
[plan9front.git] / sys / src / libauth / auth_chuid.c
1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4
5 /*
6  *  become the authenticated user
7  */
8 int
9 auth_chuid(AuthInfo *ai, char *ns)
10 {
11         int rv, fd;
12
13         if(ai == nil || ai->cap == nil || ai->cap[0] == 0){
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 }