PORTMAP: Add v3 GETTIME support

libnfs-4.0.0-vitalif
Ronnie Sahlberg 2014-03-17 19:58:48 -07:00
parent 6c60e2822f
commit 5245608a65
6 changed files with 76 additions and 0 deletions

View File

@ -37,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "libnfs-zdr.h"
#include "libnfs.h"
#include "libnfs-raw.h"
@ -124,6 +125,26 @@ void pmap3_getaddr_cb(struct rpc_context *rpc, int status, void *data, void *pri
client->is_finished = 1;
}
void pmap3_gettime_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
time_t t = *(uint32_t *)data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/GETTIME call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/GETTIME call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/GETTIME:\n");
printf(" Time:%d %s\n", (int)t, ctime(&t));
client->is_finished = 1;
}
void pmap2_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
@ -224,6 +245,7 @@ int main(int argc _U_, char *argv[] _U_)
int null3 = 0;
int getaddr3 = 0;
int dump3 = 0;
int gettime3 = 0;
int command_found = 0;
int getaddr3prog, getaddr3vers;
@ -245,6 +267,9 @@ int main(int argc _U_, char *argv[] _U_)
} else if (!strcmp(argv[i], "dump3")) {
dump3 = 1;
command_found++;
} else if (!strcmp(argv[i], "gettime3")) {
gettime3 = 1;
command_found++;
} else if (!strcmp(argv[i], "getaddr3")) {
getaddr3 = 1;
getaddr3prog = atoi(argv[++i]);
@ -297,6 +322,13 @@ int main(int argc _U_, char *argv[] _U_)
}
wait_until_finished(rpc, &client);
}
if (gettime3) {
if (rpc_pmap3_gettime_async(rpc, pmap3_gettime_cb, &client) != 0) {
printf("Failed to send GETTIME3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (getaddr3) {
struct pmap3_mapping map;

View File

@ -304,6 +304,21 @@ EXTERN int rpc_pmap3_getaddr_async(struct rpc_context *rpc, struct pmap3_mapping
*/
EXTERN int rpc_pmap3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/GETTIME.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a uint32_t *.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_gettime_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* MOUNT v3 FUNCTIONS

View File

@ -105,6 +105,7 @@ rpc_pmap2_callit_async
rpc_pmap3_null_async
rpc_pmap3_getaddr_async
rpc_pmap3_dump_async
rpc_pmap3_gettime_async
rpc_mount_null_async
rpc_mount_mnt_async
rpc_mount_dump_async

View File

@ -142,6 +142,9 @@ extern pmap3_getaddr_result * pmap3_getaddr_3_svc(pmap3_mapping *, struct svc_r
#define PMAP3_DUMP 4
extern pmap3_dump_result * pmap3_dump_3(void *, CLIENT *);
extern pmap3_dump_result * pmap3_dump_3_svc(void *, struct svc_req *);
#define PMAP3_GETTIME 6
extern u_int * pmap3_gettime_3(void *, CLIENT *);
extern u_int * pmap3_gettime_3_svc(void *, struct svc_req *);
extern int pmap_program_3_freeresult (SVCXPRT *, zdrproc_t, caddr_t);
#else /* K&R C */
@ -160,6 +163,9 @@ extern pmap3_getaddr_result * pmap3_getaddr_3_svc();
#define PMAP3_DUMP 4
extern pmap3_dump_result * pmap3_dump_3();
extern pmap3_dump_result * pmap3_dump_3_svc();
#define PMAP3_GETTIME 6
extern u_int * pmap3_gettime_3();
extern u_int * pmap3_gettime_3_svc();
extern int pmap_program_3_freeresult ();
#endif /* K&R C */

View File

@ -302,3 +302,22 @@ int rpc_pmap3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
return 0;
}
int rpc_pmap3_gettime_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
{
struct rpc_pdu *pdu;
pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V3, PMAP3_GETTIME, cb, private_data, (zdrproc_t)zdr_int, sizeof(uint32_t));
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for PORTMAP3/GETTIME call");
return -1;
}
if (rpc_queue_pdu(rpc, pdu) != 0) {
rpc_set_error(rpc, "Failed to queue PORTMAP3/GETTIME pdu");
rpc_free_pdu(rpc, pdu);
return -1;
}
return 0;
}

View File

@ -88,6 +88,9 @@ program PMAP_PROGRAM {
pmap3_dump_result
PMAP3_DUMP(void) = 4;
unsigned int
PMAP3_GETTIME(void) = 6;
} = 3;
} = 100000;