From: Ronnie Sahlberg Date: Tue, 18 Mar 2014 02:58:48 +0000 (-0700) Subject: PORTMAP: Add v3 GETTIME support X-Git-Tag: upstream/1.9.6^2~65 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5245608a6587cf6b5279ffc4fde701d8dce23bf3;p=deb_libnfs.git PORTMAP: Add v3 GETTIME support --- diff --git a/examples/portmap-client.c b/examples/portmap-client.c index b479888..73c7ab2 100644 --- a/examples/portmap-client.c +++ b/examples/portmap-client.c @@ -37,6 +37,7 @@ #include #include #include +#include #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; diff --git a/include/nfsc/libnfs-raw.h b/include/nfsc/libnfs-raw.h index 9ae5a07..74dd439 100644 --- a/include/nfsc/libnfs-raw.h +++ b/include/nfsc/libnfs-raw.h @@ -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 diff --git a/lib/libnfs-win32.def b/lib/libnfs-win32.def index 1c3e1ad..7b908e7 100644 --- a/lib/libnfs-win32.def +++ b/lib/libnfs-win32.def @@ -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 diff --git a/portmap/libnfs-raw-portmap.h b/portmap/libnfs-raw-portmap.h index df990b2..2a41831 100644 --- a/portmap/libnfs-raw-portmap.h +++ b/portmap/libnfs-raw-portmap.h @@ -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 */ diff --git a/portmap/portmap.c b/portmap/portmap.c index 16a43dc..fcfb4cd 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -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; +} diff --git a/portmap/portmap.x b/portmap/portmap.x index 0f62858..0f8a5dd 100644 --- a/portmap/portmap.x +++ b/portmap/portmap.x @@ -88,6 +88,9 @@ program PMAP_PROGRAM { pmap3_dump_result PMAP3_DUMP(void) = 4; + + unsigned int + PMAP3_GETTIME(void) = 6; } = 3; } = 100000;