]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/nfsd/auth.c | |
3 | * | |
4 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> | |
5 | */ | |
6 | ||
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> | |
c7d51402 | 12 | #include <linux/nfsd/export.h> |
a254b246 | 13 | #include "auth.h" |
1da177e4 | 14 | |
c7d51402 | 15 | int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp) |
1269bc69 BF |
16 | { |
17 | struct exp_flavor_info *f; | |
18 | struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors; | |
19 | ||
20 | for (f = exp->ex_flavors; f < end; f++) { | |
21 | if (f->pseudoflavor == rqstp->rq_flavor) | |
22 | return f->flags; | |
23 | } | |
24 | return exp->ex_flags; | |
25 | ||
26 | } | |
27 | ||
1da177e4 LT |
28 | int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp) |
29 | { | |
d84f4f99 DH |
30 | struct group_info *rqgi; |
31 | struct group_info *gi; | |
32 | struct cred *new; | |
1da177e4 | 33 | int i; |
1269bc69 | 34 | int flags = nfsexp_flags(rqstp, exp); |
1da177e4 LT |
35 | int ret; |
36 | ||
d84f4f99 DH |
37 | new = prepare_creds(); |
38 | if (!new) | |
39 | return -ENOMEM; | |
40 | ||
41 | new->fsuid = rqstp->rq_cred.cr_uid; | |
42 | new->fsgid = rqstp->rq_cred.cr_gid; | |
43 | ||
44 | rqgi = rqstp->rq_cred.cr_group_info; | |
45 | ||
1269bc69 | 46 | if (flags & NFSEXP_ALLSQUASH) { |
d84f4f99 DH |
47 | new->fsuid = exp->ex_anon_uid; |
48 | new->fsgid = exp->ex_anon_gid; | |
49 | gi = groups_alloc(0); | |
1269bc69 | 50 | } else if (flags & NFSEXP_ROOTSQUASH) { |
d84f4f99 DH |
51 | if (!new->fsuid) |
52 | new->fsuid = exp->ex_anon_uid; | |
53 | if (!new->fsgid) | |
54 | new->fsgid = exp->ex_anon_gid; | |
1da177e4 | 55 | |
d84f4f99 DH |
56 | gi = groups_alloc(rqgi->ngroups); |
57 | if (!gi) | |
58 | goto oom; | |
59 | ||
60 | for (i = 0; i < rqgi->ngroups; i++) { | |
61 | if (!GROUP_AT(rqgi, i)) | |
62 | GROUP_AT(gi, i) = exp->ex_anon_gid; | |
63 | else | |
64 | GROUP_AT(gi, i) = GROUP_AT(rqgi, i); | |
65 | } | |
1da177e4 | 66 | } else { |
d84f4f99 | 67 | gi = get_group_info(rqgi); |
1da177e4 | 68 | } |
d84f4f99 DH |
69 | |
70 | if (new->fsuid == (uid_t) -1) | |
71 | new->fsuid = exp->ex_anon_uid; | |
72 | if (new->fsgid == (gid_t) -1) | |
73 | new->fsgid = exp->ex_anon_gid; | |
74 | ||
75 | ret = set_groups(new, gi); | |
76 | put_group_info(gi); | |
77 | if (!ret) | |
78 | goto error; | |
79 | ||
80 | if (new->uid) | |
81 | new->cap_effective = cap_drop_nfsd_set(new->cap_effective); | |
82 | else | |
83 | new->cap_effective = cap_raise_nfsd_set(new->cap_effective, | |
84 | new->cap_permitted); | |
85 | return commit_creds(new); | |
86 | ||
87 | oom: | |
88 | ret = -ENOMEM; | |
89 | error: | |
90 | abort_creds(new); | |
1da177e4 LT |
91 | return ret; |
92 | } | |
b6dff3ec | 93 |