plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

auth_chuid.c (669B)


      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){
     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 }