auth.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * linux/fs/nfsd/auth.c
  3. *
  4. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  5. */
  6. #include <linux/types.h>
  7. #include <linux/sched.h>
  8. #include <linux/sunrpc/svc.h>
  9. #include <linux/sunrpc/svcauth.h>
  10. #include <linux/nfsd/nfsd.h>
  11. #include <linux/nfsd/export.h>
  12. #include "auth.h"
  13. int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
  14. {
  15. struct exp_flavor_info *f;
  16. struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  17. for (f = exp->ex_flavors; f < end; f++) {
  18. if (f->pseudoflavor == rqstp->rq_flavor)
  19. return f->flags;
  20. }
  21. return exp->ex_flags;
  22. }
  23. int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
  24. {
  25. struct svc_cred cred = rqstp->rq_cred;
  26. int i;
  27. int flags = nfsexp_flags(rqstp, exp);
  28. int ret;
  29. if (flags & NFSEXP_ALLSQUASH) {
  30. cred.cr_uid = exp->ex_anon_uid;
  31. cred.cr_gid = exp->ex_anon_gid;
  32. cred.cr_group_info = groups_alloc(0);
  33. } else if (flags & NFSEXP_ROOTSQUASH) {
  34. struct group_info *gi;
  35. if (!cred.cr_uid)
  36. cred.cr_uid = exp->ex_anon_uid;
  37. if (!cred.cr_gid)
  38. cred.cr_gid = exp->ex_anon_gid;
  39. gi = groups_alloc(cred.cr_group_info->ngroups);
  40. if (gi)
  41. for (i = 0; i < cred.cr_group_info->ngroups; i++) {
  42. if (!GROUP_AT(cred.cr_group_info, i))
  43. GROUP_AT(gi, i) = exp->ex_anon_gid;
  44. else
  45. GROUP_AT(gi, i) = GROUP_AT(cred.cr_group_info, i);
  46. }
  47. cred.cr_group_info = gi;
  48. } else
  49. get_group_info(cred.cr_group_info);
  50. if (cred.cr_uid != (uid_t) -1)
  51. current->fsuid = cred.cr_uid;
  52. else
  53. current->fsuid = exp->ex_anon_uid;
  54. if (cred.cr_gid != (gid_t) -1)
  55. current->fsgid = cred.cr_gid;
  56. else
  57. current->fsgid = exp->ex_anon_gid;
  58. if (!cred.cr_group_info)
  59. return -ENOMEM;
  60. ret = set_current_groups(cred.cr_group_info);
  61. put_group_info(cred.cr_group_info);
  62. if ((cred.cr_uid)) {
  63. current->cap_effective =
  64. cap_drop_nfsd_set(current->cap_effective);
  65. } else {
  66. current->cap_effective =
  67. cap_raise_nfsd_set(current->cap_effective,
  68. current->cap_permitted);
  69. }
  70. return ret;
  71. }