auth_chuid.c 669 B

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