History

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.

J. Bruce Fields committed 14 years ago

Commit 03a4e1f1 parent 631fc9e8 files · +38 −41Browse files

Unified · Split

8 files
  1. fs/nfs/callback.c +1 −1
  2. fs/nfsd/nfs4callback.c +3 −2
  3. fs/nfsd/nfs4state.c +17 −17
  4. fs/nfsd/state.h +0 −1
  5. include/linux/sunrpc/svcauth.h +9 −0
  6. include/linux/sunrpc/svcauth_gss.h +0 −1
  7. net/sunrpc/auth_gss/svcauth_gss.c +6 −19
  8. net/sunrpc/svcauth_unix.c +2 −0
fs/nfs/callback.c+1−1
@@ -343,7 +343,7 @@ void nfs_callback_down(int minorversion) · 342 unmodified lines
343343 int
344344 check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
345345 {
346− char *p = svc_gss_principal(rqstp);
346+ char *p = rqstp->rq_cred.cr_principal;
347347
348348 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
349349 return 1;
fs/nfsd/nfs4callback.c+3−2
@@ -650,9 +650,10 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c · 649 unmodified lines
650650 struct rpc_clnt *client;
651651
652652 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))
654655 return -EINVAL;
655− args.client_name = clp->cl_principal;
656+ args.client_name = clp->cl_cred.cr_principal;
656657 args.prognumber = conn->cb_prog,
657658 args.protocol = XPRT_TRANSPORT_TCP;
658659 args.authflavor = clp->cl_flavor;
fs/nfsd/nfs4state.c+17−17
@@ -1087,9 +1087,7 @@ free_client(struct nfs4_client *clp) · 1086 unmodified lines
10871087 list_del(&ses->se_perclnt);
10881088 nfsd4_put_session_locked(ses);
10891089 }
1090− if (clp->cl_cred.cr_group_info)
1091− put_group_info(clp->cl_cred.cr_group_info);
1092− kfree(clp->cl_principal);
1090+ free_svc_cred(&clp->cl_cred);
10931091 kfree(clp->cl_name.data);
10941092 kfree(clp);
10951093 }
@@ -1170,12 +1168,20 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source) · 74 unmodified lines
11701168 target->cl_clientid.cl_id = source->cl_clientid.cl_id;
11711169 }
11721170
1173−static void copy_cred(struct svc_cred *target, struct svc_cred *source)
1171+static int copy_cred(struct svc_cred *target, struct svc_cred *source)
11741172 {
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;
11751180 target->cr_uid = source->cr_uid;
11761181 target->cr_gid = source->cr_gid;
11771182 target->cr_group_info = source->cr_group_info;
11781183 get_group_info(target->cr_group_info);
1184+ return 0;
11791185 }
11801186
11811187 static 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, · 60 unmodified lines
12421248 {
12431249 struct nfs4_client *clp;
12441250 struct sockaddr *sa = svc_addr(rqstp);
1245− char *princ;
1251+ int ret;
12461252
12471253 clp = alloc_client(name);
12481254 if (clp == NULL)
12491255 return NULL;
12501256
12511257 INIT_LIST_HEAD(&clp->cl_sessions);
1252−
1253− princ = svc_gss_principal(rqstp);
1254− if (princ) {
1255− clp->cl_principal = kstrdup(princ, GFP_KERNEL);
1256− if (clp->cl_principal == NULL) {
1257− spin_lock(&client_lock);
1258− free_client(clp);
1259− spin_unlock(&client_lock);
1260− return NULL;
1261− }
1258+ ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred);
1259+ if (ret) {
1260+ spin_lock(&client_lock);
1261+ free_client(clp);
1262+ spin_unlock(&client_lock);
1263+ return NULL;
12621264 }
1263−
12641265 idr_init(&clp->cl_stateids);
12651266 memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
12661267 atomic_set(&clp->cl_refcount, 0);
@@ -1279,7 +1280,6 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir, · 12 unmodified lines
12791280 copy_verf(clp, verf);
12801281 rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
12811282 clp->cl_flavor = rqstp->rq_flavor;
1282− copy_cred(&clp->cl_cred, &rqstp->rq_cred);
12831283 gen_confirm(clp);
12841284 clp->cl_cb_session = NULL;
12851285 return clp;
fs/nfsd/state.h+0−1
@@ -232,7 +232,6 @@ struct nfs4_client { · 231 unmodified lines
232232 time_t cl_time; /* time of last lease renewal */
233233 struct sockaddr_storage cl_addr; /* client ipaddress */
234234 u32 cl_flavor; /* setclientid pseudoflavor */
235− char *cl_principal; /* setclientid principal name */
236235 struct svc_cred cl_cred; /* setclientid principal */
237236 clientid_t cl_clientid; /* generated by server */
238237 nfs4_verifier cl_confirm; /* generated by server */
include/linux/sunrpc/svcauth.h+9−0
@@ -15,13 +15,22 @@ · 14 unmodified lines
1515 #include <linux/sunrpc/msg_prot.h>
1616 #include <linux/sunrpc/cache.h>
1717 #include <linux/hash.h>
18+#include <linux/cred.h>
1819
1920 struct svc_cred {
2021 uid_t cr_uid;
2122 gid_t cr_gid;
2223 struct group_info *cr_group_info;
24+ char *cr_principal; /* for gss */
2325 };
2426
27+static 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+
2534 struct svc_rqst; /* forward decl */
2635 struct in6_addr;
2736
include/linux/sunrpc/svcauth_gss.h+0−1
@@ -22,7 +22,6 @@ int gss_svc_init_net(struct net *net); · 21 unmodified lines
2222 void gss_svc_shutdown_net(struct net *net);
2323 int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name);
2424 u32 svcauth_gss_flavor(struct auth_domain *dom);
25−char *svc_gss_principal(struct svc_rqst *);
2625
2726 #endif /* __KERNEL__ */
2827 #endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */
net/sunrpc/auth_gss/svcauth_gss.c+6−19
@@ -335,7 +335,6 @@ struct rsc { · 334 unmodified lines
335335 struct svc_cred cred;
336336 struct gss_svc_seq_data seqdata;
337337 struct gss_ctx *mechctx;
338− char *client_name;
339338 };
340339
341340 static 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) · 4 unmodified lines
346345 kfree(rsci->handle.data);
347346 if (rsci->mechctx)
348347 gss_delete_sec_context(&rsci->mechctx);
349− if (rsci->cred.cr_group_info)
350− put_group_info(rsci->cred.cr_group_info);
351− kfree(rsci->client_name);
348+ free_svc_cred(&rsci->cred);
352349 }
353350
354351 static void rsc_put(struct kref *ref)
@@ -386,7 +383,7 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp) · 31 unmodified lines
386383 tmp->handle.data = NULL;
387384 new->mechctx = NULL;
388385 new->cred.cr_group_info = NULL;
389− new->client_name = NULL;
386+ new->cred.cr_principal = NULL;
390387 }
391388
392389 static void
@@ -401,8 +398,8 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp) · 8 unmodified lines
401398 spin_lock_init(&new->seqdata.sd_lock);
402399 new->cred = tmp->cred;
403400 tmp->cred.cr_group_info = NULL;
404− new->client_name = tmp->client_name;
405− tmp->client_name = NULL;
401+ new->cred.cr_principal = tmp->cred.cr_principal;
402+ tmp->cred.cr_principal = NULL;
406403 }
407404
408405 static struct cache_head *
@@ -496,8 +493,8 @@ static int rsc_parse(struct cache_detail *cd, · 87 unmodified lines
496493 /* get client name */
497494 len = qword_get(&mesg, buf, mlen);
498495 if (len > 0) {
499− rsci.client_name = kstrdup(buf, GFP_KERNEL);
500− if (!rsci.client_name)
496+ rsci.cred.cr_principal = kstrdup(buf, GFP_KERNEL);
497+ if (!rsci.cred.cr_principal)
501498 goto out;
502499 }
503500
@@ -927,16 +924,6 @@ struct gss_svc_data { · 423 unmodified lines
927924 struct rsc *rsci;
928925 };
929926
930−char *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−}
938−EXPORT_SYMBOL_GPL(svc_gss_principal);
939−
940927 static int
941928 svcauth_gss_set_client(struct svc_rqst *rqstp)
942929 {
net/sunrpc/svcauth_unix.c+2−0
@@ -740,6 +740,7 @@ svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp) · 739 unmodified lines
740740 struct svc_cred *cred = &rqstp->rq_cred;
741741
742742 cred->cr_group_info = NULL;
743+ cred->cr_principal = NULL;
743744 rqstp->rq_client = NULL;
744745
745746 if (argv->iov_len < 3*4)
@@ -805,6 +806,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp) · 59 unmodified lines
805806 int len = argv->iov_len;
806807
807808 cred->cr_group_info = NULL;
809+ cred->cr_principal = NULL;
808810 rqstp->rq_client = NULL;
809811
810812 if ((len -= 3*4) < 0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t