mount.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. void usage(void);
  13. void catch(void *c, char*);
  14. char *keyspec = "";
  15. int
  16. amount0(int fd, char *mntpt, int flags, char *aname, char *keyspec)
  17. {
  18. int rv, afd;
  19. AuthInfo *ai;
  20. afd = fauth(fd, aname);
  21. if(afd >= 0){
  22. ai = auth_proxy(afd, amount_getkey, "proto=p9any role=client %s", keyspec);
  23. if(ai != nil)
  24. auth_freeAI(ai);
  25. else
  26. fprint(2, "%s: auth_proxy: %r\n", argv0);
  27. }
  28. rv = mount(fd, afd, mntpt, flags, aname, 'M');
  29. if(afd >= 0)
  30. close(afd);
  31. return rv;
  32. }
  33. void
  34. main(int argc, char *argv[])
  35. {
  36. char *spec;
  37. uint32_t flag = 0;
  38. int qflag = 0;
  39. int noauth = 0;
  40. int fd, rv;
  41. ARGBEGIN{
  42. case 'a':
  43. flag |= MAFTER;
  44. break;
  45. case 'b':
  46. flag |= MBEFORE;
  47. break;
  48. case 'c':
  49. flag |= MCREATE;
  50. break;
  51. case 'C':
  52. flag |= MCACHE;
  53. break;
  54. case 'k':
  55. keyspec = EARGF(usage());
  56. break;
  57. case 'n':
  58. noauth = 1;
  59. break;
  60. case 'q':
  61. qflag = 1;
  62. break;
  63. default:
  64. usage();
  65. }ARGEND
  66. spec = 0;
  67. if(argc == 2)
  68. spec = "";
  69. else if(argc == 3)
  70. spec = argv[2];
  71. else
  72. usage();
  73. if((flag&MAFTER)&&(flag&MBEFORE))
  74. usage();
  75. fd = open(argv[0], ORDWR);
  76. if(fd < 0){
  77. if(qflag)
  78. exits(0);
  79. fprint(2, "%s: can't open %s: %r\n", argv0, argv[0]);
  80. exits("open");
  81. }
  82. notify(catch);
  83. if(noauth)
  84. rv = mount(fd, -1, argv[1], flag, spec, 'M');
  85. else
  86. rv = amount0(fd, argv[1], flag, spec, keyspec);
  87. if(rv < 0){
  88. if(qflag)
  89. exits(0);
  90. fprint(2, "%s: mount %s: %r\n", argv0, argv[1]);
  91. exits("mount");
  92. }
  93. exits(0);
  94. }
  95. void
  96. catch(void *x, char *m)
  97. {
  98. USED(x);
  99. fprint(2, "mount: %s\n", m);
  100. exits(m);
  101. }
  102. void
  103. usage(void)
  104. {
  105. fprint(2, "usage: mount [-a|-b] [-cnq] [-k keypattern] /srv/service dir [spec]\n");
  106. exits("usage");
  107. }