Commit 9fd45c16 authored by NeilBrown's avatar NeilBrown Committed by Chuck Lever
Browse files

nfsd: Pass 'cred' instead of 'rqstp' to some functions.



nfsd_permission(), exp_rdonly(), nfsd_setuser(), and nfsexp_flags()
only ever need the cred out of rqstp, so pass it explicitly instead of
the whole rqstp.

This makes the interfaces cleaner.

Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent c55aeef7
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -5,26 +5,26 @@
#include "nfsd.h"
#include "auth.h"

int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
int nfsexp_flags(struct svc_cred *cred, 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++) {
		if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
		if (f->pseudoflavor == cred->cr_flavor)
			return f->flags;
	}
	return exp->ex_flags;

}

int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)
{
	struct group_info *rqgi;
	struct group_info *gi;
	struct cred *new;
	int i;
	int flags = nfsexp_flags(rqstp, exp);
	int flags = nfsexp_flags(cred, exp);

	/* discard any old override before preparing the new set */
	revert_creds(get_cred(current_real_cred()));
@@ -32,10 +32,10 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
	if (!new)
		return -ENOMEM;

	new->fsuid = rqstp->rq_cred.cr_uid;
	new->fsgid = rqstp->rq_cred.cr_gid;
	new->fsuid = cred->cr_uid;
	new->fsgid = cred->cr_gid;

	rqgi = rqstp->rq_cred.cr_group_info;
	rqgi = cred->cr_group_info;

	if (flags & NFSEXP_ALLSQUASH) {
		new->fsuid = exp->ex_anon_uid;
+1 −1
Original line number Diff line number Diff line
@@ -12,6 +12,6 @@
 * Set the current process's fsuid/fsgid etc to those of the NFS
 * client user
 */
int nfsd_setuser(struct svc_rqst *, struct svc_export *);
int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp);

#endif /* LINUX_NFSD_AUTH_H */
+2 −1
Original line number Diff line number Diff line
@@ -99,7 +99,8 @@ struct svc_expkey {
#define EX_NOHIDE(exp)		((exp)->ex_flags & NFSEXP_NOHIDE)
#define EX_WGATHER(exp)		((exp)->ex_flags & NFSEXP_GATHERED_WRITES)

int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
struct svc_cred;
int nfsexp_flags(struct svc_cred *cred, struct svc_export *exp);
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);

/*
+2 −1
Original line number Diff line number Diff line
@@ -6891,7 +6891,8 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,

	nf = nfs4_find_file(s, flags);
	if (nf) {
		status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
		status = nfsd_permission(&rqstp->rq_cred,
					 fhp->fh_export, fhp->fh_dentry,
				acc | NFSD_MAY_OWNER_OVERRIDE);
		if (status) {
			nfsd_file_put(nf);
+3 −3
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
					  struct svc_export *exp)
{
	int flags = nfsexp_flags(rqstp, exp);
	int flags = nfsexp_flags(&rqstp->rq_cred, exp);

	/* Check if the request originated from a secure port. */
	if (!nfsd_originating_port_ok(rqstp, flags)) {
@@ -113,7 +113,7 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
	}

	/* Set user creds for this exportpoint */
	return nfserrno(nfsd_setuser(rqstp, exp));
	return nfserrno(nfsd_setuser(&rqstp->rq_cred, exp));
}

static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
@@ -394,7 +394,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)

skip_pseudoflavor_check:
	/* Finally, check access permissions. */
	error = nfsd_permission(rqstp, exp, dentry, access);
	error = nfsd_permission(&rqstp->rq_cred, exp, dentry, access);
out:
	trace_nfsd_fh_verify_err(rqstp, fhp, type, access, error);
	if (error == nfserr_stale)
Loading