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>
12 #include <linux/nfsd/export.h>
14 int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
16 struct exp_flavor_info *f;
17 struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
19 for (f = exp->ex_flavors; f < end; f++) {
20 if (f->pseudoflavor == rqstp->rq_flavor)
27 int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
29 struct svc_cred cred = rqstp->rq_cred;
31 int flags = nfsexp_flags(rqstp, exp);
34 if (flags & NFSEXP_ALLSQUASH) {
35 cred.cr_uid = exp->ex_anon_uid;
36 cred.cr_gid = exp->ex_anon_gid;
37 cred.cr_group_info = groups_alloc(0);
38 } else if (flags & NFSEXP_ROOTSQUASH) {
39 struct group_info *gi;
41 cred.cr_uid = exp->ex_anon_uid;
43 cred.cr_gid = exp->ex_anon_gid;
44 gi = groups_alloc(cred.cr_group_info->ngroups);
46 for (i = 0; i < cred.cr_group_info->ngroups; i++) {
47 if (!GROUP_AT(cred.cr_group_info, i))
48 GROUP_AT(gi, i) = exp->ex_anon_gid;
50 GROUP_AT(gi, i) = GROUP_AT(cred.cr_group_info, i);
52 cred.cr_group_info = gi;
54 get_group_info(cred.cr_group_info);
56 if (cred.cr_uid != (uid_t) -1)
57 current->fsuid = cred.cr_uid;
59 current->fsuid = exp->ex_anon_uid;
60 if (cred.cr_gid != (gid_t) -1)
61 current->fsgid = cred.cr_gid;
63 current->fsgid = exp->ex_anon_gid;
65 if (!cred.cr_group_info)
67 ret = set_current_groups(cred.cr_group_info);
68 put_group_info(cred.cr_group_info);
70 current->cap_effective =
71 cap_drop_nfsd_set(current->cap_effective);
73 current->cap_effective =
74 cap_raise_nfsd_set(current->cap_effective,
75 current->cap_permitted);