Commit | Line | Data |
---|---|---|
7663dacd | 1 | /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */ |
1da177e4 | 2 | |
1da177e4 | 3 | #include <linux/sched.h> |
9a74af21 | 4 | #include "nfsd.h" |
a254b246 | 5 | #include "auth.h" |
1da177e4 | 6 | |
c7d51402 | 7 | int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp) |
1269bc69 BF |
8 | { |
9 | struct exp_flavor_info *f; | |
10 | struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors; | |
11 | ||
12 | for (f = exp->ex_flavors; f < end; f++) { | |
d5497fc6 | 13 | if (f->pseudoflavor == rqstp->rq_cred.cr_flavor) |
1269bc69 BF |
14 | return f->flags; |
15 | } | |
16 | return exp->ex_flags; | |
17 | ||
18 | } | |
19 | ||
1da177e4 LT |
20 | int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp) |
21 | { | |
d84f4f99 DH |
22 | struct group_info *rqgi; |
23 | struct group_info *gi; | |
24 | struct cred *new; | |
1da177e4 | 25 | int i; |
1269bc69 | 26 | int flags = nfsexp_flags(rqstp, exp); |
1da177e4 | 27 | |
e0e81739 DH |
28 | validate_process_creds(); |
29 | ||
3b11a1de | 30 | /* discard any old override before preparing the new set */ |
ae4b884f | 31 | revert_creds(get_cred(current_real_cred())); |
d84f4f99 DH |
32 | new = prepare_creds(); |
33 | if (!new) | |
34 | return -ENOMEM; | |
35 | ||
36 | new->fsuid = rqstp->rq_cred.cr_uid; | |
37 | new->fsgid = rqstp->rq_cred.cr_gid; | |
38 | ||
39 | rqgi = rqstp->rq_cred.cr_group_info; | |
40 | ||
1269bc69 | 41 | if (flags & NFSEXP_ALLSQUASH) { |
d84f4f99 DH |
42 | new->fsuid = exp->ex_anon_uid; |
43 | new->fsgid = exp->ex_anon_gid; | |
44 | gi = groups_alloc(0); | |
bf935a78 BF |
45 | if (!gi) |
46 | goto oom; | |
1269bc69 | 47 | } else if (flags & NFSEXP_ROOTSQUASH) { |
6fab8779 | 48 | if (uid_eq(new->fsuid, GLOBAL_ROOT_UID)) |
d84f4f99 | 49 | new->fsuid = exp->ex_anon_uid; |
6fab8779 | 50 | if (gid_eq(new->fsgid, GLOBAL_ROOT_GID)) |
d84f4f99 | 51 | new->fsgid = exp->ex_anon_gid; |
1da177e4 | 52 | |
d84f4f99 DH |
53 | gi = groups_alloc(rqgi->ngroups); |
54 | if (!gi) | |
55 | goto oom; | |
56 | ||
57 | for (i = 0; i < rqgi->ngroups; i++) { | |
81243eac AD |
58 | if (gid_eq(GLOBAL_ROOT_GID, rqgi->gid[i])) |
59 | gi->gid[i] = exp->ex_anon_gid; | |
d84f4f99 | 60 | else |
81243eac | 61 | gi->gid[i] = rqgi->gid[i]; |
d84f4f99 | 62 | } |
1da177e4 | 63 | } else { |
d84f4f99 | 64 | gi = get_group_info(rqgi); |
1da177e4 | 65 | } |
d84f4f99 | 66 | |
6fab8779 | 67 | if (uid_eq(new->fsuid, INVALID_UID)) |
d84f4f99 | 68 | new->fsuid = exp->ex_anon_uid; |
6fab8779 | 69 | if (gid_eq(new->fsgid, INVALID_GID)) |
d84f4f99 DH |
70 | new->fsgid = exp->ex_anon_gid; |
71 | ||
8f6c5ffc | 72 | set_groups(new, gi); |
d84f4f99 | 73 | put_group_info(gi); |
d84f4f99 | 74 | |
6fab8779 | 75 | if (!uid_eq(new->fsuid, GLOBAL_ROOT_UID)) |
d84f4f99 DH |
76 | new->cap_effective = cap_drop_nfsd_set(new->cap_effective); |
77 | else | |
78 | new->cap_effective = cap_raise_nfsd_set(new->cap_effective, | |
79 | new->cap_permitted); | |
e0e81739 | 80 | validate_process_creds(); |
3b11a1de | 81 | put_cred(override_creds(new)); |
b914152a | 82 | put_cred(new); |
e0e81739 | 83 | validate_process_creds(); |
3b11a1de | 84 | return 0; |
d84f4f99 DH |
85 | |
86 | oom: | |
d84f4f99 | 87 | abort_creds(new); |
61a27f08 | 88 | return -ENOMEM; |
1da177e4 | 89 | } |
b6dff3ec | 90 |