auth_chuid.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. /*
  13. * become the authenticated user
  14. */
  15. int
  16. auth_chuid(AuthInfo *ai, char *ns)
  17. {
  18. int rv, fd;
  19. if(ai == nil || ai->cap == nil || *ai->cap == 0){
  20. werrstr("no capability");
  21. return -1;
  22. }
  23. /* change uid */
  24. fd = open("#¤/capuse", OWRITE);
  25. if(fd < 0){
  26. werrstr("opening #¤/capuse: %r");
  27. return -1;
  28. }
  29. rv = write(fd, ai->cap, strlen(ai->cap));
  30. close(fd);
  31. if(rv < 0){
  32. werrstr("writing %s to #¤/capuse: %r", ai->cap);
  33. return -1;
  34. }
  35. /* get a link to factotum as new user */
  36. fd = open("/srv/factotum", ORDWR);
  37. if(fd >= 0)
  38. mount(fd, -1, "/mnt", MREPL, "", 'M');
  39. /* set up new namespace */
  40. return newns(ai->cuid, ns);
  41. }