From 29258a73c0d6b82caf23106b6c3d69cfc0e7f58b Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 17 Mar 2014 21:20:12 -0700 Subject: [PATCH] PORTMAP: Add support for v3 TADDR2UADDR --- include/nfsc/libnfs-raw.h | 17 +++++++++++++++++ lib/libnfs-win32.def | 1 + portmap/libnfs-raw-portmap.h | 6 ++++++ portmap/portmap.c | 24 ++++++++++++++++++++++++ portmap/portmap.x | 3 +++ 5 files changed, 51 insertions(+) diff --git a/include/nfsc/libnfs-raw.h b/include/nfsc/libnfs-raw.h index f3113a6..ce419ff 100644 --- a/include/nfsc/libnfs-raw.h +++ b/include/nfsc/libnfs-raw.h @@ -352,6 +352,23 @@ EXTERN int rpc_pmap3_gettime_async(struct rpc_context *rpc, rpc_cb cb, void *pri */ EXTERN int rpc_pmap3_uaddr2taddr_async(struct rpc_context *rpc, char *uaddr, rpc_cb cb, void *private_data); +/* + * Call PORTMAPPER3/TADDR2UADDR. + * 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 struct pmap3_getaddr_result *. + * 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. + */ +struct pmap3_netbuf; +EXTERN int rpc_pmap3_taddr2uaddr_async(struct rpc_context *rpc, struct pmap3_netbuf *netbuf, rpc_cb cb, void *private_data); + /* * MOUNT v3 FUNCTIONS */ diff --git a/lib/libnfs-win32.def b/lib/libnfs-win32.def index 81ec68e..72d6be6 100644 --- a/lib/libnfs-win32.def +++ b/lib/libnfs-win32.def @@ -110,6 +110,7 @@ rpc_pmap3_dump_async rpc_pmap3_callit_async rpc_pmap3_gettime_async rpc_pmap3_uaddr2taddr_async +rpc_pmap3_taddr2uaddr_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 1c5ec05..bc94871 100644 --- a/portmap/libnfs-raw-portmap.h +++ b/portmap/libnfs-raw-portmap.h @@ -180,6 +180,9 @@ extern u_int * pmap3_gettime_3_svc(void *, struct svc_req *); #define PMAP3_UADDR2TADDR 7 extern pmap3_netbuf * pmap3_uaddr2taddr_3(char **, CLIENT *); extern pmap3_netbuf * pmap3_uaddr2taddr_3_svc(char **, struct svc_req *); +#define PMAP3_TADDR2UADDR 8 +extern struct pmap3_getaddr_result * pmap3_taddr2uaddr_3(pmap3_netbuf *, CLIENT *); +extern struct pmap3_getaddr_result * pmap3_taddr2uaddr_3_svc(pmap3_netbuf *, struct svc_req *); extern int pmap_program_3_freeresult (SVCXPRT *, zdrproc_t, caddr_t); #else /* K&R C */ @@ -207,6 +210,9 @@ extern u_int * pmap3_gettime_3_svc(); #define PMAP3_UADDR2TADDR 7 extern pmap3_netbuf * pmap3_uaddr2taddr_3(); extern pmap3_netbuf * pmap3_uaddr2taddr_3_svc(); +#define PMAP3_TADDR2UADDR 8 +extern struct pmap3_getaddr_result * pmap3_taddr2uaddr_3(); +extern struct pmap3_getaddr_result * pmap3_taddr2uaddr_3_svc(); extern int pmap_program_3_freeresult (); #endif /* K&R C */ diff --git a/portmap/portmap.c b/portmap/portmap.c index e6aea82..2e9f653 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -376,3 +376,27 @@ int rpc_pmap3_uaddr2taddr_async(struct rpc_context *rpc, char *uaddr, rpc_cb cb, return 0; } + +int rpc_pmap3_taddr2uaddr_async(struct rpc_context *rpc, struct pmap3_netbuf *nb, rpc_cb cb, void *private_data) +{ + struct rpc_pdu *pdu; + + pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V3, PMAP3_TADDR2UADDR, cb, private_data, (zdrproc_t)zdr_pmap3_getaddr_result, sizeof(pmap3_getaddr_result)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for PORTMAP3/TADDR2UADDR call"); + return -1; + } + + if (zdr_pmap3_netbuf(&pdu->zdr, nb) == 0) { + rpc_set_error(rpc, "ZDR error: Failed to encode data for PORTMAP3/TADDR2UADDR call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Failed to queue PORTMAP3/TADDR2UADDR pdu: %s", rpc_get_error(rpc)); + return -1; + } + + return 0; +} diff --git a/portmap/portmap.x b/portmap/portmap.x index 45c87af..1572505 100644 --- a/portmap/portmap.x +++ b/portmap/portmap.x @@ -114,6 +114,9 @@ program PMAP_PROGRAM { pmap3_netbuf PMAP3_UADDR2TADDR(string) = 7; + + struct pmap3_getaddr_result + PMAP3_TADDR2UADDR(pmap3_netbuf) = 8; } = 3; } = 100000; -- 2.34.1