2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* linux/fs/nfsd/auth.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/sunrpc/svc.h>
|
|
|
|
#include <linux/sunrpc/svcauth.h>
|
|
|
|
#include <linux/nfsd/nfsd.h>
|
|
|
|
|
|
|
|
#define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
|
|
|
|
|
|
|
|
int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
|
|
|
|
{
|
2006-04-11 07:55:30 +02:00
|
|
|
struct svc_cred cred = rqstp->rq_cred;
|
2005-04-17 00:20:36 +02:00
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (exp->ex_flags & NFSEXP_ALLSQUASH) {
|
2006-04-11 07:55:30 +02:00
|
|
|
cred.cr_uid = exp->ex_anon_uid;
|
|
|
|
cred.cr_gid = exp->ex_anon_gid;
|
|
|
|
cred.cr_group_info = groups_alloc(0);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else if (exp->ex_flags & NFSEXP_ROOTSQUASH) {
|
|
|
|
struct group_info *gi;
|
2006-04-11 07:55:30 +02:00
|
|
|
if (!cred.cr_uid)
|
|
|
|
cred.cr_uid = exp->ex_anon_uid;
|
|
|
|
if (!cred.cr_gid)
|
|
|
|
cred.cr_gid = exp->ex_anon_gid;
|
|
|
|
gi = groups_alloc(cred.cr_group_info->ngroups);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (gi)
|
2006-04-11 07:55:30 +02:00
|
|
|
for (i = 0; i < cred.cr_group_info->ngroups; i++) {
|
|
|
|
if (!GROUP_AT(cred.cr_group_info, i))
|
2005-04-17 00:20:36 +02:00
|
|
|
GROUP_AT(gi, i) = exp->ex_anon_gid;
|
|
|
|
else
|
2006-04-11 07:55:30 +02:00
|
|
|
GROUP_AT(gi, i) = GROUP_AT(cred.cr_group_info, i);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-04-11 07:55:30 +02:00
|
|
|
cred.cr_group_info = gi;
|
|
|
|
} else
|
|
|
|
get_group_info(cred.cr_group_info);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-04-11 07:55:30 +02:00
|
|
|
if (cred.cr_uid != (uid_t) -1)
|
|
|
|
current->fsuid = cred.cr_uid;
|
2005-04-17 00:20:36 +02:00
|
|
|
else
|
|
|
|
current->fsuid = exp->ex_anon_uid;
|
2006-04-11 07:55:30 +02:00
|
|
|
if (cred.cr_gid != (gid_t) -1)
|
|
|
|
current->fsgid = cred.cr_gid;
|
2005-04-17 00:20:36 +02:00
|
|
|
else
|
|
|
|
current->fsgid = exp->ex_anon_gid;
|
|
|
|
|
2006-04-11 07:55:30 +02:00
|
|
|
if (!cred.cr_group_info)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENOMEM;
|
2006-04-11 07:55:30 +02:00
|
|
|
ret = set_current_groups(cred.cr_group_info);
|
|
|
|
put_group_info(cred.cr_group_info);
|
|
|
|
if ((cred.cr_uid)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
|
|
|
|
} else {
|
|
|
|
cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
|
|
|
|
current->cap_permitted);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|