aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2012-05-14 19:55:22 -0400
committerJ. Bruce Fields <bfields@redhat.com>2012-05-31 20:29:55 -0400
commit03a4e1f6ddf25f48848e1bddcffc0ad489648331 (patch)
treef140e3deb767d092eca997037ebb7b098d8afce9
parent631fc9ea05c97e5d1d14ea58a7347be4857d09da (diff)
nfsd4: move principal name into svc_cred
Instead of keeping the principal name associated with a request in a structure that's private to auth_gss and using an accessor function, move it to svc_cred. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--fs/nfs/callback.c2
-rw-r--r--fs/nfsd/nfs4callback.c5
-rw-r--r--fs/nfsd/nfs4state.c34
-rw-r--r--fs/nfsd/state.h1
-rw-r--r--include/linux/sunrpc/svcauth.h9
-rw-r--r--include/linux/sunrpc/svcauth_gss.h1
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c25
-rw-r--r--net/sunrpc/svcauth_unix.c2
8 files changed, 38 insertions, 41 deletions
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index cff39406f965..970659daa323 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -343,7 +343,7 @@ void nfs_callback_down(int minorversion)
343int 343int
344check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp) 344check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
345{ 345{
346 char *p = svc_gss_principal(rqstp); 346 char *p = rqstp->rq_cred.cr_principal;
347 347
348 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS) 348 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
349 return 1; 349 return 1;
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index c8e9f637153a..a5fd6b982f27 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -650,9 +650,10 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c
650 struct rpc_clnt *client; 650 struct rpc_clnt *client;
651 651
652 if (clp->cl_minorversion == 0) { 652 if (clp->cl_minorversion == 0) {
653 if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) 653 if (!clp->cl_cred.cr_principal &&
654 (clp->cl_flavor >= RPC_AUTH_GSS_KRB5))
654 return -EINVAL; 655 return -EINVAL;
655 args.client_name = clp->cl_principal; 656 args.client_name = clp->cl_cred.cr_principal;
656 args.prognumber = conn->cb_prog, 657 args.prognumber = conn->cb_prog,
657 args.protocol = XPRT_TRANSPORT_TCP; 658 args.protocol = XPRT_TRANSPORT_TCP;
658 args.authflavor = clp->cl_flavor; 659 args.authflavor = clp->cl_flavor;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 5415550a63a9..37bafb290c11 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1087,9 +1087,7 @@ free_client(struct nfs4_client *clp)
1087 list_del(&ses->se_perclnt); 1087 list_del(&ses->se_perclnt);
1088 nfsd4_put_session_locked(ses); 1088 nfsd4_put_session_locked(ses);
1089 } 1089 }
1090 if (clp->cl_cred.cr_group_info) 1090 free_svc_cred(&clp->cl_cred);
1091 put_group_info(clp->cl_cred.cr_group_info);
1092 kfree(clp->cl_principal);
1093 kfree(clp->cl_name.data); 1091 kfree(clp->cl_name.data);
1094 kfree(clp); 1092 kfree(clp);
1095} 1093}
@@ -1170,12 +1168,20 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source)
1170 target->cl_clientid.cl_id = source->cl_clientid.cl_id; 1168 target->cl_clientid.cl_id = source->cl_clientid.cl_id;
1171} 1169}
1172 1170
1173static void copy_cred(struct svc_cred *target, struct svc_cred *source) 1171static int copy_cred(struct svc_cred *target, struct svc_cred *source)
1174{ 1172{
1173 if (source->cr_principal) {
1174 target->cr_principal =
1175 kstrdup(source->cr_principal, GFP_KERNEL);
1176 if (target->cr_principal == NULL)
1177 return -ENOMEM;
1178 } else
1179 target->cr_principal = NULL;
1175 target->cr_uid = source->cr_uid; 1180 target->cr_uid = source->cr_uid;
1176 target->cr_gid = source->cr_gid; 1181 target->cr_gid = source->cr_gid;
1177 target->cr_group_info = source->cr_group_info; 1182 target->cr_group_info = source->cr_group_info;
1178 get_group_info(target->cr_group_info); 1183 get_group_info(target->cr_group_info);
1184 return 0;
1179} 1185}
1180 1186
1181static int same_name(const char *n1, const char *n2) 1187static int same_name(const char *n1, const char *n2)
@@ -1242,25 +1248,20 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
1242{ 1248{
1243 struct nfs4_client *clp; 1249 struct nfs4_client *clp;
1244 struct sockaddr *sa = svc_addr(rqstp); 1250 struct sockaddr *sa = svc_addr(rqstp);
1245 char *princ; 1251 int ret;
1246 1252
1247 clp = alloc_client(name); 1253 clp = alloc_client(name);
1248 if (clp == NULL) 1254 if (clp == NULL)
1249 return NULL; 1255 return NULL;
1250 1256
1251 INIT_LIST_HEAD(&clp->cl_sessions); 1257 INIT_LIST_HEAD(&clp->cl_sessions);
1252 1258 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred);
1253 princ = svc_gss_principal(rqstp); 1259 if (ret) {
1254 if (princ) { 1260 spin_lock(&client_lock);
1255 clp->cl_principal = kstrdup(princ, GFP_KERNEL); 1261 free_client(clp);
1256 if (clp->cl_principal == NULL) { 1262 spin_unlock(&client_lock);
1257 spin_lock(&client_lock); 1263 return NULL;
1258 free_client(clp);
1259 spin_unlock(&client_lock);
1260 return NULL;
1261 }
1262 } 1264 }
1263
1264 idr_init(&clp->cl_stateids); 1265 idr_init(&clp->cl_stateids);
1265 memcpy(clp->cl_recdir, recdir, HEXDIR_LEN); 1266 memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
1266 atomic_set(&clp->cl_refcount, 0); 1267 atomic_set(&clp->cl_refcount, 0);
@@ -1279,7 +1280,6 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
1279 copy_verf(clp, verf); 1280 copy_verf(clp, verf);
1280 rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa); 1281 rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
1281 clp->cl_flavor = rqstp->rq_flavor; 1282 clp->cl_flavor = rqstp->rq_flavor;
1282 copy_cred(&clp->cl_cred, &rqstp->rq_cred);
1283 gen_confirm(clp); 1283 gen_confirm(clp);
1284 clp->cl_cb_session = NULL; 1284 clp->cl_cb_session = NULL;
1285 return clp; 1285 return clp;
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 89ab137d379a..849091e16ea6 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -232,7 +232,6 @@ struct nfs4_client {
232 time_t cl_time; /* time of last lease renewal */ 232 time_t cl_time; /* time of last lease renewal */
233 struct sockaddr_storage cl_addr; /* client ipaddress */ 233 struct sockaddr_storage cl_addr; /* client ipaddress */
234 u32 cl_flavor; /* setclientid pseudoflavor */ 234 u32 cl_flavor; /* setclientid pseudoflavor */
235 char *cl_principal; /* setclientid principal name */
236 struct svc_cred cl_cred; /* setclientid principal */ 235 struct svc_cred cl_cred; /* setclientid principal */
237 clientid_t cl_clientid; /* generated by server */ 236 clientid_t cl_clientid; /* generated by server */
238 nfs4_verifier cl_confirm; /* generated by server */ 237 nfs4_verifier cl_confirm; /* generated by server */
diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
index 2c54683b91de..16fe477a96e0 100644
--- a/include/linux/sunrpc/svcauth.h
+++ b/include/linux/sunrpc/svcauth.h
@@ -15,13 +15,22 @@
15#include <linux/sunrpc/msg_prot.h> 15#include <linux/sunrpc/msg_prot.h>
16#include <linux/sunrpc/cache.h> 16#include <linux/sunrpc/cache.h>
17#include <linux/hash.h> 17#include <linux/hash.h>
18#include <linux/cred.h>
18 19
19struct svc_cred { 20struct svc_cred {
20 uid_t cr_uid; 21 uid_t cr_uid;
21 gid_t cr_gid; 22 gid_t cr_gid;
22 struct group_info *cr_group_info; 23 struct group_info *cr_group_info;
24 char *cr_principal; /* for gss */
23}; 25};
24 26
27static inline void free_svc_cred(struct svc_cred *cred)
28{
29 if (cred->cr_group_info)
30 put_group_info(cred->cr_group_info);
31 kfree(cred->cr_principal);
32}
33
25struct svc_rqst; /* forward decl */ 34struct svc_rqst; /* forward decl */
26struct in6_addr; 35struct in6_addr;
27 36
diff --git a/include/linux/sunrpc/svcauth_gss.h b/include/linux/sunrpc/svcauth_gss.h
index 7c32daa025eb..726aff1a5201 100644
--- a/include/linux/sunrpc/svcauth_gss.h
+++ b/include/linux/sunrpc/svcauth_gss.h
@@ -22,7 +22,6 @@ int gss_svc_init_net(struct net *net);
22void gss_svc_shutdown_net(struct net *net); 22void gss_svc_shutdown_net(struct net *net);
23int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name); 23int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name);
24u32 svcauth_gss_flavor(struct auth_domain *dom); 24u32 svcauth_gss_flavor(struct auth_domain *dom);
25char *svc_gss_principal(struct svc_rqst *);
26 25
27#endif /* __KERNEL__ */ 26#endif /* __KERNEL__ */
28#endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */ 27#endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index f0a0cd4470b7..d091d7d09bea 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -335,7 +335,6 @@ struct rsc {
335 struct svc_cred cred; 335 struct svc_cred cred;
336 struct gss_svc_seq_data seqdata; 336 struct gss_svc_seq_data seqdata;
337 struct gss_ctx *mechctx; 337 struct gss_ctx *mechctx;
338 char *client_name;
339}; 338};
340 339
341static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old); 340static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old);
@@ -346,9 +345,7 @@ static void rsc_free(struct rsc *rsci)
346 kfree(rsci->handle.data); 345 kfree(rsci->handle.data);
347 if (rsci->mechctx) 346 if (rsci->mechctx)
348 gss_delete_sec_context(&rsci->mechctx); 347 gss_delete_sec_context(&rsci->mechctx);
349 if (rsci->cred.cr_group_info) 348 free_svc_cred(&rsci->cred);
350 put_group_info(rsci->cred.cr_group_info);
351 kfree(rsci->client_name);
352} 349}
353 350
354static void rsc_put(struct kref *ref) 351static void rsc_put(struct kref *ref)
@@ -386,7 +383,7 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp)
386 tmp->handle.data = NULL; 383 tmp->handle.data = NULL;
387 new->mechctx = NULL; 384 new->mechctx = NULL;
388 new->cred.cr_group_info = NULL; 385 new->cred.cr_group_info = NULL;
389 new->client_name = NULL; 386 new->cred.cr_principal = NULL;
390} 387}
391 388
392static void 389static void
@@ -401,8 +398,8 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp)
401 spin_lock_init(&new->seqdata.sd_lock); 398 spin_lock_init(&new->seqdata.sd_lock);
402 new->cred = tmp->cred; 399 new->cred = tmp->cred;
403 tmp->cred.cr_group_info = NULL; 400 tmp->cred.cr_group_info = NULL;
404 new->client_name = tmp->client_name; 401 new->cred.cr_principal = tmp->cred.cr_principal;
405 tmp->client_name = NULL; 402 tmp->cred.cr_principal = NULL;
406} 403}
407 404
408static struct cache_head * 405static struct cache_head *
@@ -496,8 +493,8 @@ static int rsc_parse(struct cache_detail *cd,
496 /* get client name */ 493 /* get client name */
497 len = qword_get(&mesg, buf, mlen); 494 len = qword_get(&mesg, buf, mlen);
498 if (len > 0) { 495 if (len > 0) {
499 rsci.client_name = kstrdup(buf, GFP_KERNEL); 496 rsci.cred.cr_principal = kstrdup(buf, GFP_KERNEL);
500 if (!rsci.client_name) 497 if (!rsci.cred.cr_principal)
501 goto out; 498 goto out;
502 } 499 }
503 500
@@ -927,16 +924,6 @@ struct gss_svc_data {
927 struct rsc *rsci; 924 struct rsc *rsci;
928}; 925};
929 926
930char *svc_gss_principal(struct svc_rqst *rqstp)
931{
932 struct gss_svc_data *gd = (struct gss_svc_data *)rqstp->rq_auth_data;
933
934 if (gd && gd->rsci)
935 return gd->rsci->client_name;
936 return NULL;
937}
938EXPORT_SYMBOL_GPL(svc_gss_principal);
939
940static int 927static int
941svcauth_gss_set_client(struct svc_rqst *rqstp) 928svcauth_gss_set_client(struct svc_rqst *rqstp)
942{ 929{
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 9c3b9f014468..12e4897d0bf3 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -740,6 +740,7 @@ svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp)
740 struct svc_cred *cred = &rqstp->rq_cred; 740 struct svc_cred *cred = &rqstp->rq_cred;
741 741
742 cred->cr_group_info = NULL; 742 cred->cr_group_info = NULL;
743 cred->cr_principal = NULL;
743 rqstp->rq_client = NULL; 744 rqstp->rq_client = NULL;
744 745
745 if (argv->iov_len < 3*4) 746 if (argv->iov_len < 3*4)
@@ -805,6 +806,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
805 int len = argv->iov_len; 806 int len = argv->iov_len;
806 807
807 cred->cr_group_info = NULL; 808 cred->cr_group_info = NULL;
809 cred->cr_principal = NULL;
808 rqstp->rq_client = NULL; 810 rqstp->rq_client = NULL;
809 811
810 if ((len -= 3*4) < 0) 812 if ((len -= 3*4) < 0)