Files
linux-apfs/fs/nfsd/auth.c
T

97 lines
2.1 KiB
C
Raw Normal View History

/* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
2005-04-16 15:20:36 -07:00
#include <linux/sched.h>
#include <linux/user_namespace.h>
#include "nfsd.h"
2008-02-20 12:49:00 -08:00
#include "auth.h"
2005-04-16 15:20:36 -07:00
2007-07-19 01:49:20 -07:00
int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
{
struct exp_flavor_info *f;
struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
for (f = exp->ex_flavors; f < end; f++) {
2012-05-14 22:06:49 -04:00
if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
return f->flags;
}
return exp->ex_flags;
}
2005-04-16 15:20:36 -07:00
int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
{
2008-11-14 10:39:23 +11:00
struct group_info *rqgi;
struct group_info *gi;
struct cred *new;
2005-04-16 15:20:36 -07:00
int i;
int flags = nfsexp_flags(rqstp, exp);
2005-04-16 15:20:36 -07:00
int ret;
validate_process_creds();
/* discard any old override before preparing the new set */
revert_creds(get_cred(current->real_cred));
2008-11-14 10:39:23 +11:00
new = prepare_creds();
if (!new)
2005-04-16 15:20:36 -07:00
return -ENOMEM;
2008-11-14 10:39:23 +11:00
new->fsuid = rqstp->rq_cred.cr_uid;
new->fsgid = rqstp->rq_cred.cr_gid;
rqgi = rqstp->rq_cred.cr_group_info;
if (flags & NFSEXP_ALLSQUASH) {
new->fsuid = exp->ex_anon_uid;
new->fsgid = exp->ex_anon_gid;
gi = groups_alloc(0);
2009-01-20 19:32:59 -05:00
if (!gi)
goto oom;
2008-11-14 10:39:23 +11:00
} else if (flags & NFSEXP_ROOTSQUASH) {
if (uid_eq(new->fsuid, GLOBAL_ROOT_UID))
2008-11-14 10:39:23 +11:00
new->fsuid = exp->ex_anon_uid;
if (gid_eq(new->fsgid, GLOBAL_ROOT_GID))
2008-11-14 10:39:23 +11:00
new->fsgid = exp->ex_anon_gid;
gi = groups_alloc(rqgi->ngroups);
if (!gi)
goto oom;
for (i = 0; i < rqgi->ngroups; i++) {
if (gid_eq(GLOBAL_ROOT_GID, GROUP_AT(rqgi, i)))
GROUP_AT(gi, i) = exp->ex_anon_gid;
2008-11-14 10:39:23 +11:00
else
GROUP_AT(gi, i) = GROUP_AT(rqgi, i);
}
2005-04-16 15:20:36 -07:00
} else {
2008-11-14 10:39:23 +11:00
gi = get_group_info(rqgi);
2005-04-16 15:20:36 -07:00
}
2008-11-14 10:39:23 +11:00
if (uid_eq(new->fsuid, INVALID_UID))
2008-11-14 10:39:23 +11:00
new->fsuid = exp->ex_anon_uid;
if (gid_eq(new->fsgid, INVALID_GID))
2008-11-14 10:39:23 +11:00
new->fsgid = exp->ex_anon_gid;
ret = set_groups(new, gi);
put_group_info(gi);
2009-01-05 17:19:37 +00:00
if (ret < 0)
2008-11-14 10:39:23 +11:00
goto error;
if (!uid_eq(new->fsuid, GLOBAL_ROOT_UID))
2008-11-14 10:39:23 +11:00
new->cap_effective = cap_drop_nfsd_set(new->cap_effective);
else
new->cap_effective = cap_raise_nfsd_set(new->cap_effective,
new->cap_permitted);
validate_process_creds();
put_cred(override_creds(new));
2009-01-20 19:34:22 -05:00
put_cred(new);
validate_process_creds();
return 0;
2008-11-14 10:39:23 +11:00
oom:
ret = -ENOMEM;
error:
abort_creds(new);
2005-04-16 15:20:36 -07:00
return ret;
}