4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 #include <linux/types.h>
8 #include <linux/sched.h>
9 #include <linux/sunrpc/svc.h>
10 #include <linux/sunrpc/svcauth.h>
11 #include <linux/nfsd/nfsd.h>
13 #define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
15 static int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
17 struct exp_flavor_info *f;
18 struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
20 for (f = exp->ex_flavors; f < end; f++) {
21 if (f->pseudoflavor == rqstp->rq_flavor)
28 int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
30 struct svc_cred cred = rqstp->rq_cred;
32 int flags = nfsexp_flags(rqstp, exp);
35 if (flags & NFSEXP_ALLSQUASH) {
36 cred.cr_uid = exp->ex_anon_uid;
37 cred.cr_gid = exp->ex_anon_gid;
38 cred.cr_group_info = groups_alloc(0);
39 } else if (flags & NFSEXP_ROOTSQUASH) {
40 struct group_info *gi;
42 cred.cr_uid = exp->ex_anon_uid;
44 cred.cr_gid = exp->ex_anon_gid;
45 gi = groups_alloc(cred.cr_group_info->ngroups);
47 for (i = 0; i < cred.cr_group_info->ngroups; i++) {
48 if (!GROUP_AT(cred.cr_group_info, i))
49 GROUP_AT(gi, i) = exp->ex_anon_gid;
51 GROUP_AT(gi, i) = GROUP_AT(cred.cr_group_info, i);
53 cred.cr_group_info = gi;
55 get_group_info(cred.cr_group_info);
57 if (cred.cr_uid != (uid_t) -1)
58 current->fsuid = cred.cr_uid;
60 current->fsuid = exp->ex_anon_uid;
61 if (cred.cr_gid != (gid_t) -1)
62 current->fsgid = cred.cr_gid;
64 current->fsgid = exp->ex_anon_gid;
66 if (!cred.cr_group_info)
68 ret = set_current_groups(cred.cr_group_info);
69 put_group_info(cred.cr_group_info);
71 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
73 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
74 current->cap_permitted);