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.
Unified · Split
| @@ -343,7 +343,7 @@ void nfs_callback_down(int minorversion) · 342 unmodified lines | ||
| 343 | 343 | int |
| 344 | 344 | check_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 | 348 | if (rqstp->rq_authop->flavour != RPC_AUTH_GSS) |
| 349 | 349 | return 1; |
| @@ -650,9 +650,10 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c · 649 unmodified lines | ||
| 650 | 650 | struct rpc_clnt *client; |
| 651 | 651 | |
| 652 | 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 | 655 | return -EINVAL; |
| 655 | − args.client_name = clp->cl_principal; | |
| 656 | + args.client_name = clp->cl_cred.cr_principal; | |
| 656 | 657 | args.prognumber = conn->cb_prog, |
| 657 | 658 | args.protocol = XPRT_TRANSPORT_TCP; |
| 658 | 659 | args.authflavor = clp->cl_flavor; |
| @@ -1087,9 +1087,7 @@ free_client(struct nfs4_client *clp) · 1086 unmodified lines | ||
| 1087 | 1087 | list_del(&ses->se_perclnt); |
| 1088 | 1088 | nfsd4_put_session_locked(ses); |
| 1089 | 1089 | } |
| 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); | |
| 1093 | 1091 | kfree(clp->cl_name.data); |
| 1094 | 1092 | kfree(clp); |
| 1095 | 1093 | } |
| @@ -1170,12 +1168,20 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source) · 74 unmodified lines | ||
| 1170 | 1168 | target->cl_clientid.cl_id = source->cl_clientid.cl_id; |
| 1171 | 1169 | } |
| 1172 | 1170 | |
| 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) | |
| 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 | 1180 | target->cr_uid = source->cr_uid; |
| 1176 | 1181 | target->cr_gid = source->cr_gid; |
| 1177 | 1182 | target->cr_group_info = source->cr_group_info; |
| 1178 | 1183 | get_group_info(target->cr_group_info); |
| 1184 | + return 0; | |
| 1179 | 1185 | } |
| 1180 | 1186 | |
| 1181 | 1187 | 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 | ||
| 1242 | 1248 | { |
| 1243 | 1249 | struct nfs4_client *clp; |
| 1244 | 1250 | struct sockaddr *sa = svc_addr(rqstp); |
| 1245 | − char *princ; | |
| 1251 | + int ret; | |
| 1246 | 1252 | |
| 1247 | 1253 | clp = alloc_client(name); |
| 1248 | 1254 | if (clp == NULL) |
| 1249 | 1255 | return NULL; |
| 1250 | 1256 | |
| 1251 | 1257 | 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; | |
| 1262 | 1264 | } |
| 1263 | − | |
| 1264 | 1265 | idr_init(&clp->cl_stateids); |
| 1265 | 1266 | memcpy(clp->cl_recdir, recdir, HEXDIR_LEN); |
| 1266 | 1267 | 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 | ||
| 1279 | 1280 | copy_verf(clp, verf); |
| 1280 | 1281 | rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa); |
| 1281 | 1282 | clp->cl_flavor = rqstp->rq_flavor; |
| 1282 | − copy_cred(&clp->cl_cred, &rqstp->rq_cred); | |
| 1283 | 1283 | gen_confirm(clp); |
| 1284 | 1284 | clp->cl_cb_session = NULL; |
| 1285 | 1285 | return clp; |
| @@ -232,7 +232,6 @@ struct nfs4_client { · 231 unmodified lines | ||
| 232 | 232 | time_t cl_time; /* time of last lease renewal */ |
| 233 | 233 | struct sockaddr_storage cl_addr; /* client ipaddress */ |
| 234 | 234 | u32 cl_flavor; /* setclientid pseudoflavor */ |
| 235 | − char *cl_principal; /* setclientid principal name */ | |
| 236 | 235 | struct svc_cred cl_cred; /* setclientid principal */ |
| 237 | 236 | clientid_t cl_clientid; /* generated by server */ |
| 238 | 237 | nfs4_verifier cl_confirm; /* generated by server */ |
| @@ -15,13 +15,22 @@ · 14 unmodified lines | ||
| 15 | 15 | #include <linux/sunrpc/msg_prot.h> |
| 16 | 16 | #include <linux/sunrpc/cache.h> |
| 17 | 17 | #include <linux/hash.h> |
| 18 | +#include <linux/cred.h> | |
| 18 | 19 | |
| 19 | 20 | struct svc_cred { |
| 20 | 21 | uid_t cr_uid; |
| 21 | 22 | gid_t cr_gid; |
| 22 | 23 | struct group_info *cr_group_info; |
| 24 | + char *cr_principal; /* for gss */ | |
| 23 | 25 | }; |
| 24 | 26 | |
| 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 | + | |
| 25 | 34 | struct svc_rqst; /* forward decl */ |
| 26 | 35 | struct in6_addr; |
| 27 | 36 | |
| @@ -22,7 +22,6 @@ int gss_svc_init_net(struct net *net); · 21 unmodified lines | ||
| 22 | 22 | void gss_svc_shutdown_net(struct net *net); |
| 23 | 23 | int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name); |
| 24 | 24 | u32 svcauth_gss_flavor(struct auth_domain *dom); |
| 25 | −char *svc_gss_principal(struct svc_rqst *); | |
| 26 | 25 | |
| 27 | 26 | #endif /* __KERNEL__ */ |
| 28 | 27 | #endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */ |
| @@ -335,7 +335,6 @@ struct rsc { · 334 unmodified lines | ||
| 335 | 335 | struct svc_cred cred; |
| 336 | 336 | struct gss_svc_seq_data seqdata; |
| 337 | 337 | struct gss_ctx *mechctx; |
| 338 | − char *client_name; | |
| 339 | 338 | }; |
| 340 | 339 | |
| 341 | 340 | 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 | ||
| 346 | 345 | kfree(rsci->handle.data); |
| 347 | 346 | if (rsci->mechctx) |
| 348 | 347 | 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); | |
| 352 | 349 | } |
| 353 | 350 | |
| 354 | 351 | static void rsc_put(struct kref *ref) |
| @@ -386,7 +383,7 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp) · 31 unmodified lines | ||
| 386 | 383 | tmp->handle.data = NULL; |
| 387 | 384 | new->mechctx = NULL; |
| 388 | 385 | new->cred.cr_group_info = NULL; |
| 389 | − new->client_name = NULL; | |
| 386 | + new->cred.cr_principal = NULL; | |
| 390 | 387 | } |
| 391 | 388 | |
| 392 | 389 | static void |
| @@ -401,8 +398,8 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp) · 8 unmodified lines | ||
| 401 | 398 | spin_lock_init(&new->seqdata.sd_lock); |
| 402 | 399 | new->cred = tmp->cred; |
| 403 | 400 | 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; | |
| 406 | 403 | } |
| 407 | 404 | |
| 408 | 405 | static struct cache_head * |
| @@ -496,8 +493,8 @@ static int rsc_parse(struct cache_detail *cd, · 87 unmodified lines | ||
| 496 | 493 | /* get client name */ |
| 497 | 494 | len = qword_get(&mesg, buf, mlen); |
| 498 | 495 | 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) | |
| 501 | 498 | goto out; |
| 502 | 499 | } |
| 503 | 500 | |
| @@ -927,16 +924,6 @@ struct gss_svc_data { · 423 unmodified lines | ||
| 927 | 924 | struct rsc *rsci; |
| 928 | 925 | }; |
| 929 | 926 | |
| 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 | − | |
| 940 | 927 | static int |
| 941 | 928 | svcauth_gss_set_client(struct svc_rqst *rqstp) |
| 942 | 929 | { |
| @@ -740,6 +740,7 @@ svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp) · 739 unmodified lines | ||
| 740 | 740 | struct svc_cred *cred = &rqstp->rq_cred; |
| 741 | 741 | |
| 742 | 742 | cred->cr_group_info = NULL; |
| 743 | + cred->cr_principal = NULL; | |
| 743 | 744 | rqstp->rq_client = NULL; |
| 744 | 745 | |
| 745 | 746 | if (argv->iov_len < 3*4) |
| @@ -805,6 +806,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp) · 59 unmodified lines | ||
| 805 | 806 | int len = argv->iov_len; |
| 806 | 807 | |
| 807 | 808 | cred->cr_group_info = NULL; |
| 809 | + cred->cr_principal = NULL; | |
| 808 | 810 | rqstp->rq_client = NULL; |
| 809 | 811 | |
| 810 | 812 | if ((len -= 3*4) < 0) |