iop-adma: cleanup iop_adma_run_tx_complete_actions
[linux/fpc-iii.git] / fs / nfsd / auth.c
blob5573508f707fa5cd652da4503049fa6e89c0f9f8
1 /*
2 * linux/fs/nfsd/auth.c
4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
5 */
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>
13 #include "auth.h"
15 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)
22 return f->flags;
24 return exp->ex_flags;
28 int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
30 struct group_info *rqgi;
31 struct group_info *gi;
32 struct cred *new;
33 int i;
34 int flags = nfsexp_flags(rqstp, exp);
35 int ret;
37 /* discard any old override before preparing the new set */
38 revert_creds(get_cred(current->real_cred));
39 new = prepare_creds();
40 if (!new)
41 return -ENOMEM;
43 new->fsuid = rqstp->rq_cred.cr_uid;
44 new->fsgid = rqstp->rq_cred.cr_gid;
46 rqgi = rqstp->rq_cred.cr_group_info;
48 if (flags & NFSEXP_ALLSQUASH) {
49 new->fsuid = exp->ex_anon_uid;
50 new->fsgid = exp->ex_anon_gid;
51 gi = groups_alloc(0);
52 if (!gi)
53 goto oom;
54 } else if (flags & NFSEXP_ROOTSQUASH) {
55 if (!new->fsuid)
56 new->fsuid = exp->ex_anon_uid;
57 if (!new->fsgid)
58 new->fsgid = exp->ex_anon_gid;
60 gi = groups_alloc(rqgi->ngroups);
61 if (!gi)
62 goto oom;
64 for (i = 0; i < rqgi->ngroups; i++) {
65 if (!GROUP_AT(rqgi, i))
66 GROUP_AT(gi, i) = exp->ex_anon_gid;
67 else
68 GROUP_AT(gi, i) = GROUP_AT(rqgi, i);
70 } else {
71 gi = get_group_info(rqgi);
74 if (new->fsuid == (uid_t) -1)
75 new->fsuid = exp->ex_anon_uid;
76 if (new->fsgid == (gid_t) -1)
77 new->fsgid = exp->ex_anon_gid;
79 ret = set_groups(new, gi);
80 put_group_info(gi);
81 if (ret < 0)
82 goto error;
84 if (new->fsuid)
85 new->cap_effective = cap_drop_nfsd_set(new->cap_effective);
86 else
87 new->cap_effective = cap_raise_nfsd_set(new->cap_effective,
88 new->cap_permitted);
89 put_cred(override_creds(new));
90 put_cred(new);
91 return 0;
93 oom:
94 ret = -ENOMEM;
95 error:
96 abort_creds(new);
97 return ret;