From 1e9fdca8c26b783b67ab46862d87cafe2336c000 Mon Sep 17 00:00:00 2001 From: pragyagandhi Date: Tue, 9 Sep 2025 04:52:49 +0000 Subject: [PATCH 1/2] Update --- include/libnfs-private.h | 6 ++++++ lib/init.c | 1 + lib/libnfs.c | 14 ++++++++++++++ lib/pdu.c | 2 +- lib/socket.c | 12 +++++++++++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/libnfs-private.h b/include/libnfs-private.h index 5e7272c4..60b26d35 100644 --- a/include/libnfs-private.h +++ b/include/libnfs-private.h @@ -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. diff --git a/lib/init.c b/lib/init.c index b4d10f05..fe099433 100644 --- a/lib/init.c +++ b/lib/init.c @@ -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; diff --git a/lib/libnfs.c b/lib/libnfs.c index f3c26249..40716be1 100755 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -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); } @@ -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; } @@ -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; } @@ -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; } diff --git a/lib/pdu.c b/lib/pdu.c index 94fd5829..b7a2cf62 100644 --- a/lib/pdu.c +++ b/lib/pdu.c @@ -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; } diff --git a/lib/socket.c b/lib/socket.c index e48c2226..14aa1c07 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -706,11 +706,12 @@ rpc_read_from_socket(struct rpc_context *rpc) while (1){ if (rpc->inpos == 0) { + //RPC_LOG(rpc, 2, "printing state %d" rpc->state); switch (rpc->state) { 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; @@ -772,7 +773,9 @@ rpc_read_from_socket(struct rpc_context *rpc) } } + RPC_LOG(rpc, 2, "%d %d", rpc->inpos, rpc->pdu_size); count = rpc->pdu_size - rpc->inpos; + RPC_LOG(rpc, 2, "1st %d", count); /* * When reading padding, clamp this so we do not overwrite * rpc->inbuf/rpc->inbuf_size which we use as the garbage buffer @@ -784,14 +787,21 @@ rpc_read_from_socket(struct rpc_context *rpc) } } + RPC_LOG(rpc, 2, "2nd %d", count); + if (rpc->buf) { + RPC_LOG(rpc, 2, "2nd to %d %d", count, rpc->fd); count = recv(rpc->fd, rpc->buf, count, MSG_DONTWAIT); + perror("recv"); } else { assert(rpc->pdu->in.iovcnt > 0); assert(count <= rpc->pdu->in.remaining_size); count = readv(rpc->fd, rpc->pdu->in.iov, rpc->pdu->in.iovcnt); } + RPC_LOG(rpc, 2, "3rd %d", count); + //RPC_LOG(rpc, 2,"%d %d", rpc->inpos, count); + if (count < 0) { /* * No more data to read so we can break out of From 44328cf554f890b2ed69a6c449817901fc77c81e Mon Sep 17 00:00:00 2001 From: pragyagandhi Date: Tue, 9 Sep 2025 04:57:31 +0000 Subject: [PATCH 2/2] Remove extra echo lines --- lib/socket.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/socket.c b/lib/socket.c index 14aa1c07..3cbdddda 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -706,7 +706,6 @@ rpc_read_from_socket(struct rpc_context *rpc) while (1){ if (rpc->inpos == 0) { - //RPC_LOG(rpc, 2, "printing state %d" rpc->state); switch (rpc->state) { case READ_RM: /* @@ -773,9 +772,7 @@ rpc_read_from_socket(struct rpc_context *rpc) } } - RPC_LOG(rpc, 2, "%d %d", rpc->inpos, rpc->pdu_size); count = rpc->pdu_size - rpc->inpos; - RPC_LOG(rpc, 2, "1st %d", count); /* * When reading padding, clamp this so we do not overwrite * rpc->inbuf/rpc->inbuf_size which we use as the garbage buffer @@ -787,21 +784,14 @@ rpc_read_from_socket(struct rpc_context *rpc) } } - RPC_LOG(rpc, 2, "2nd %d", count); - if (rpc->buf) { - RPC_LOG(rpc, 2, "2nd to %d %d", count, rpc->fd); count = recv(rpc->fd, rpc->buf, count, MSG_DONTWAIT); - perror("recv"); } else { assert(rpc->pdu->in.iovcnt > 0); assert(count <= rpc->pdu->in.remaining_size); count = readv(rpc->fd, rpc->pdu->in.iov, rpc->pdu->in.iovcnt); } - RPC_LOG(rpc, 2, "3rd %d", count); - //RPC_LOG(rpc, 2,"%d %d", rpc->inpos, count); - if (count < 0) { /* * No more data to read so we can break out of