Skip to content

Commit a0337d1

Browse files
jtlaytontrondmypd
authored andcommitted
sunrpc: add a new "stringify_acceptor" rpc_credop
...and add an new rpc_auth function to call it when it exists. This is only applicable for AUTH_GSS mechanisms, so we only specify this for those sorts of credentials. Signed-off-by: Jeff Layton <jlayton@poochiereds.net> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 2004c72 commit a0337d1

3 files changed

Lines changed: 53 additions & 20 deletions

File tree

‎include/linux/sunrpc/auth.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct rpc_credops {
140140
void *, __be32 *, void *);
141141
int (*crkey_timeout)(struct rpc_cred *);
142142
bool (*crkey_to_expire)(struct rpc_cred *);
143+
char * (*crstringify_acceptor)(struct rpc_cred *);
143144
};
144145

145146
extern const struct rpc_authops authunix_ops;
@@ -182,6 +183,7 @@ void rpcauth_clear_credcache(struct rpc_cred_cache *);
182183
int rpcauth_key_timeout_notify(struct rpc_auth *,
183184
struct rpc_cred *);
184185
bool rpcauth_cred_key_to_expire(struct rpc_cred *);
186+
char * rpcauth_stringify_acceptor(struct rpc_cred *);
185187

186188
static inline
187189
struct rpc_cred * get_rpccred(struct rpc_cred *cred)

‎net/sunrpc/auth.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ rpcauth_cred_key_to_expire(struct rpc_cred *cred)
363363
}
364364
EXPORT_SYMBOL_GPL(rpcauth_cred_key_to_expire);
365365

366+
char *
367+
rpcauth_stringify_acceptor(struct rpc_cred *cred)
368+
{
369+
if (!cred->cr_ops->crstringify_acceptor)
370+
return NULL;
371+
return cred->cr_ops->crstringify_acceptor(cred);
372+
}
373+
EXPORT_SYMBOL_GPL(rpcauth_stringify_acceptor);
374+
366375
/*
367376
* Destroy a list of credentials
368377
*/

‎net/sunrpc/auth_gss/auth_gss.c‎

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,26 @@ gss_cred_init(struct rpc_auth *auth, struct rpc_cred *cred)
13461346
return err;
13471347
}
13481348

1349+
static char *
1350+
gss_stringify_acceptor(struct rpc_cred *cred)
1351+
{
1352+
char *string;
1353+
struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
1354+
struct xdr_netobj *acceptor = &gss_cred->gc_ctx->gc_acceptor;
1355+
1356+
/* no point if there's no string */
1357+
if (!acceptor->len)
1358+
return NULL;
1359+
1360+
string = kmalloc(acceptor->len + 1, GFP_KERNEL);
1361+
if (!string)
1362+
return string;
1363+
1364+
memcpy(string, acceptor->data, acceptor->len);
1365+
string[acceptor->len] = '\0';
1366+
return string;
1367+
}
1368+
13491369
/*
13501370
* Returns -EACCES if GSS context is NULL or will expire within the
13511371
* timeout (miliseconds)
@@ -1923,29 +1943,31 @@ static const struct rpc_authops authgss_ops = {
19231943
};
19241944

19251945
static const struct rpc_credops gss_credops = {
1926-
.cr_name = "AUTH_GSS",
1927-
.crdestroy = gss_destroy_cred,
1928-
.cr_init = gss_cred_init,
1929-
.crbind = rpcauth_generic_bind_cred,
1930-
.crmatch = gss_match,
1931-
.crmarshal = gss_marshal,
1932-
.crrefresh = gss_refresh,
1933-
.crvalidate = gss_validate,
1934-
.crwrap_req = gss_wrap_req,
1935-
.crunwrap_resp = gss_unwrap_resp,
1936-
.crkey_timeout = gss_key_timeout,
1946+
.cr_name = "AUTH_GSS",
1947+
.crdestroy = gss_destroy_cred,
1948+
.cr_init = gss_cred_init,
1949+
.crbind = rpcauth_generic_bind_cred,
1950+
.crmatch = gss_match,
1951+
.crmarshal = gss_marshal,
1952+
.crrefresh = gss_refresh,
1953+
.crvalidate = gss_validate,
1954+
.crwrap_req = gss_wrap_req,
1955+
.crunwrap_resp = gss_unwrap_resp,
1956+
.crkey_timeout = gss_key_timeout,
1957+
.crstringify_acceptor = gss_stringify_acceptor,
19371958
};
19381959

19391960
static const struct rpc_credops gss_nullops = {
1940-
.cr_name = "AUTH_GSS",
1941-
.crdestroy = gss_destroy_nullcred,
1942-
.crbind = rpcauth_generic_bind_cred,
1943-
.crmatch = gss_match,
1944-
.crmarshal = gss_marshal,
1945-
.crrefresh = gss_refresh_null,
1946-
.crvalidate = gss_validate,
1947-
.crwrap_req = gss_wrap_req,
1948-
.crunwrap_resp = gss_unwrap_resp,
1961+
.cr_name = "AUTH_GSS",
1962+
.crdestroy = gss_destroy_nullcred,
1963+
.crbind = rpcauth_generic_bind_cred,
1964+
.crmatch = gss_match,
1965+
.crmarshal = gss_marshal,
1966+
.crrefresh = gss_refresh_null,
1967+
.crvalidate = gss_validate,
1968+
.crwrap_req = gss_wrap_req,
1969+
.crunwrap_resp = gss_unwrap_resp,
1970+
.crstringify_acceptor = gss_stringify_acceptor,
19491971
};
19501972

19511973
static const struct rpc_pipe_ops gss_upcall_ops_v0 = {

0 commit comments

Comments
 (0)