2005-04-17 06:20:36 +08: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>
|
2007-07-19 16:49:20 +08:00
|
|
|
#include <linux/nfsd/export.h>
|
2008-02-21 04:49:00 +08:00
|
|
|
#include "auth.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-19 16:49:20 +08:00
|
|
|
int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
|
2007-07-17 19:04:52 +08:00
|
|
|
{
|
|
|
|
struct exp_flavor_info *f;
|
|
|
|
struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
|
|
|
|
|
|
|
|
for (f = exp->ex_flavors; f < end; f++) {
|
|
|
|
if (f->pseudoflavor == rqstp->rq_flavor)
|
|
|
|
return f->flags;
|
|
|
|
}
|
|
|
|
return exp->ex_flags;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
|
|
|
|
{
|
2008-11-14 07:39:16 +08:00
|
|
|
struct cred *act_as = current->cred ;
|
2006-04-11 13:55:30 +08:00
|
|
|
struct svc_cred cred = rqstp->rq_cred;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2007-07-17 19:04:52 +08:00
|
|
|
int flags = nfsexp_flags(rqstp, exp);
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2007-07-17 19:04:52 +08:00
|
|
|
if (flags & NFSEXP_ALLSQUASH) {
|
2006-04-11 13:55:30 +08:00
|
|
|
cred.cr_uid = exp->ex_anon_uid;
|
|
|
|
cred.cr_gid = exp->ex_anon_gid;
|
|
|
|
cred.cr_group_info = groups_alloc(0);
|
2007-07-17 19:04:52 +08:00
|
|
|
} else if (flags & NFSEXP_ROOTSQUASH) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct group_info *gi;
|
2006-04-11 13:55:30 +08: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 06:20:36 +08:00
|
|
|
if (gi)
|
2006-04-11 13:55:30 +08:00
|
|
|
for (i = 0; i < cred.cr_group_info->ngroups; i++) {
|
|
|
|
if (!GROUP_AT(cred.cr_group_info, i))
|
2005-04-17 06:20:36 +08:00
|
|
|
GROUP_AT(gi, i) = exp->ex_anon_gid;
|
|
|
|
else
|
2006-04-11 13:55:30 +08:00
|
|
|
GROUP_AT(gi, i) = GROUP_AT(cred.cr_group_info, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-04-11 13:55:30 +08:00
|
|
|
cred.cr_group_info = gi;
|
|
|
|
} else
|
|
|
|
get_group_info(cred.cr_group_info);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-04-11 13:55:30 +08:00
|
|
|
if (cred.cr_uid != (uid_t) -1)
|
2008-11-14 07:39:16 +08:00
|
|
|
act_as->fsuid = cred.cr_uid;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-11-14 07:39:16 +08:00
|
|
|
act_as->fsuid = exp->ex_anon_uid;
|
2006-04-11 13:55:30 +08:00
|
|
|
if (cred.cr_gid != (gid_t) -1)
|
2008-11-14 07:39:16 +08:00
|
|
|
act_as->fsgid = cred.cr_gid;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-11-14 07:39:16 +08:00
|
|
|
act_as->fsgid = exp->ex_anon_gid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-04-11 13:55:30 +08:00
|
|
|
if (!cred.cr_group_info)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
2008-11-14 07:39:16 +08:00
|
|
|
ret = set_groups(act_as, cred.cr_group_info);
|
2006-04-11 13:55:30 +08:00
|
|
|
put_group_info(cred.cr_group_info);
|
|
|
|
if ((cred.cr_uid)) {
|
2008-11-14 07:39:16 +08:00
|
|
|
act_as->cap_effective =
|
|
|
|
cap_drop_nfsd_set(act_as->cap_effective);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2008-11-14 07:39:16 +08:00
|
|
|
act_as->cap_effective =
|
|
|
|
cap_raise_nfsd_set(act_as->cap_effective,
|
|
|
|
act_as->cap_permitted);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-14 07:39:16 +08:00
|
|
|
|