Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/libnfs-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ struct auth_context {
*/
bool_t needs_refresh;

/*
* Auth token cached for this context.
* Updated after a successful call to get_token_callback_t.
*/
char *azauth_data;

/*
* Expiry time of the current token.
* Updated after a successful call to get_token_callback_t.
Expand Down
1 change: 1 addition & 0 deletions lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ void rpc_destroy_context(struct rpc_context *rpc)
free(rpc->auth_context.auth_type);
free(rpc->auth_context.client_version);
free(rpc->auth_context.client_id);
free(rpc->auth_context.azauth_data);
rpc->auth_context.is_authorized = FALSE;
rpc->use_azauth = FALSE;

Expand Down
14 changes: 14 additions & 0 deletions lib/libnfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ set_auth_token_callback(get_token_callback_t get_cb)
static struct auth_token_cb_res *
get_azauth_token(struct auth_context *auth)
{
// Only access internals here, not in user code!
if (auth->azauth_data && auth->expiry_time > time(NULL)) {
fprintf(stderr, "Using cached auth token, expiry_time: %lu \n",
auth->expiry_time);
// Already cached and valid
struct auth_token_cb_res *cb_res = malloc(sizeof(struct auth_token_cb_res));
cb_res->azauth_data = strdup(auth->azauth_data);
cb_res->expiry_time = auth->expiry_time;
return cb_res;
}
return get_auth_token_cb(auth);
}

Expand Down Expand Up @@ -620,6 +630,7 @@ int nfs_set_auth_context(struct nfs_context *nfs,
nfs->rpc->auth_context.client_id = strdup(client_id);
nfs->rpc->auth_context.is_authorized = FALSE;
nfs->rpc->auth_context.expiry_time = 0;
nfs->rpc->auth_context.azauth_data = NULL;

return 0;
}
Expand Down Expand Up @@ -2862,10 +2873,12 @@ rpc_perform_azauth(struct rpc_context *rpc, rpc_cb cb, void *private_data)

rpc->auth_context.is_authorized = FALSE;
rpc->auth_context.expiry_time = res->expiry_time;
rpc->auth_context.azauth_data = strdup(res->azauth_data);

struct azauth_cb_data *data = calloc(1, sizeof(*data));
if (data == NULL) {
free_azauth_token(res, &azauthargs);
free(rpc->auth_context.azauth_data);
rpc_set_error(rpc, "Out of memory. Failed to allocate azauth_cb_data");
return NULL;
}
Expand All @@ -2881,6 +2894,7 @@ rpc_perform_azauth(struct rpc_context *rpc, rpc_cb cb, void *private_data)
if (pdu == NULL) {
rpc_set_error(rpc, "AZAUTH RPC failed to set pdu");
free_azauth_token(res, &azauthargs);
free(rpc->auth_context.azauth_data);
free_azauth_cb_data(data);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ int rpc_queue_pdu2(struct rpc_context *rpc, struct rpc_pdu *pdu, int prio)
if (sendto(rpc->fd, pdu->zdr.buf, size, MSG_DONTWAIT,
(struct sockaddr *)&rpc->udp_dest,
sizeof(rpc->udp_dest)) < 0) {
rpc_set_error(rpc, "Sendto failed with errno %s", strerror(errno));
rpc_set_error(rpc, "Send to failed with errno %s", strerror(errno));
rpc_free_pdu(rpc, pdu);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ rpc_read_from_socket(struct rpc_context *rpc)
case READ_RM:
/*
* Read record marker,
* And if this is a cleint context read the next 4 bytes
* And if this is a client context read the next 4 bytes
* i.e. the XID on a client
*/
rpc->pdu_size = 8;
Expand Down