aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/auth.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfsd/auth.c')
-rw-r--r--fs/nfsd/auth.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c
new file mode 100644
index 000000000000..cfe9ce881613
--- /dev/null
+++ b/fs/nfsd/auth.c
@@ -0,0 +1,63 @@
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>
12
13#define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
14
15int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
16{
17 struct svc_cred *cred = &rqstp->rq_cred;
18 int i;
19 int ret;
20
21 if (exp->ex_flags & NFSEXP_ALLSQUASH) {
22 cred->cr_uid = exp->ex_anon_uid;
23 cred->cr_gid = exp->ex_anon_gid;
24 put_group_info(cred->cr_group_info);
25 cred->cr_group_info = groups_alloc(0);
26 } else if (exp->ex_flags & NFSEXP_ROOTSQUASH) {
27 struct group_info *gi;
28 if (!cred->cr_uid)
29 cred->cr_uid = exp->ex_anon_uid;
30 if (!cred->cr_gid)
31 cred->cr_gid = exp->ex_anon_gid;
32 gi = groups_alloc(cred->cr_group_info->ngroups);
33 if (gi)
34 for (i = 0; i < cred->cr_group_info->ngroups; i++) {
35 if (!GROUP_AT(cred->cr_group_info, i))
36 GROUP_AT(gi, i) = exp->ex_anon_gid;
37 else
38 GROUP_AT(gi, i) = GROUP_AT(cred->cr_group_info, i);
39 }
40 put_group_info(cred->cr_group_info);
41 cred->cr_group_info = gi;
42 }
43
44 if (cred->cr_uid != (uid_t) -1)
45 current->fsuid = cred->cr_uid;
46 else
47 current->fsuid = exp->ex_anon_uid;
48 if (cred->cr_gid != (gid_t) -1)
49 current->fsgid = cred->cr_gid;
50 else
51 current->fsgid = exp->ex_anon_gid;
52
53 if (!cred->cr_group_info)
54 return -ENOMEM;
55 ret = set_current_groups(cred->cr_group_info);
56 if ((cred->cr_uid)) {
57 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
58 } else {
59 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
60 current->cap_permitted);
61 }
62 return ret;
63}