From d731e94cfa97651aa6a44dbff8855c924858696c Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 16 Mar 2014 16:37:33 -0700 Subject: [PATCH] PORTMAP: Add support for SET UNSET procedures --- include/nfsc/libnfs-raw.h | 34 +++++++++++++++++++++++- portmap/libnfs-raw-portmap.h | 12 +++++++++ portmap/portmap.c | 50 ++++++++++++++++++++++++++++++++++++ portmap/portmap.x | 6 +++++ 4 files changed, 101 insertions(+), 1 deletion(-) diff --git a/include/nfsc/libnfs-raw.h b/include/nfsc/libnfs-raw.h index b813e27..9ae5a07 100644 --- a/include/nfsc/libnfs-raw.h +++ b/include/nfsc/libnfs-raw.h @@ -239,6 +239,39 @@ EXTERN int rpc_pmap2_callit_async(struct rpc_context *rpc, int program, int vers */ EXTERN int rpc_pmap3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data); +/* + * Call PORTMAPPER3/SET. + * 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 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. + */ +struct pmap3_mapping; +EXTERN int rpc_pmap3_set_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data); + +/* + * Call PORTMAPPER3/UNSET. + * 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 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_unset_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data); + /* * Call PORTMAPPER3/GETADDR. * Function returns @@ -253,7 +286,6 @@ EXTERN int rpc_pmap3_null_async(struct rpc_context *rpc, rpc_cb cb, void *privat * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete. * data is NULL. */ -struct pmap3_mapping; EXTERN int rpc_pmap3_getaddr_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data); /* diff --git a/portmap/libnfs-raw-portmap.h b/portmap/libnfs-raw-portmap.h index f0aa174..df990b2 100644 --- a/portmap/libnfs-raw-portmap.h +++ b/portmap/libnfs-raw-portmap.h @@ -130,6 +130,12 @@ extern int pmap_program_2_freeresult (); #define PMAP3_NULL 0 extern void * pmap3_null_3(void *, CLIENT *); extern void * pmap3_null_3_svc(void *, struct svc_req *); +#define PMAP3_SET 1 +extern bool_t * pmap3_set_3(pmap3_mapping *, CLIENT *); +extern bool_t * pmap3_set_3_svc(pmap3_mapping *, struct svc_req *); +#define PMAP3_UNSET 2 +extern bool_t * pmap3_unset_3(pmap3_mapping *, CLIENT *); +extern bool_t * pmap3_unset_3_svc(pmap3_mapping *, struct svc_req *); #define PMAP3_GETADDR 3 extern pmap3_getaddr_result * pmap3_getaddr_3(pmap3_mapping *, CLIENT *); extern pmap3_getaddr_result * pmap3_getaddr_3_svc(pmap3_mapping *, struct svc_req *); @@ -142,6 +148,12 @@ extern int pmap_program_3_freeresult (SVCXPRT *, zdrproc_t, caddr_t); #define PMAP3_NULL 0 extern void * pmap3_null_3(); extern void * pmap3_null_3_svc(); +#define PMAP3_SET 1 +extern bool_t * pmap3_set_3(); +extern bool_t * pmap3_set_3_svc(); +#define PMAP3_UNSET 2 +extern bool_t * pmap3_unset_3(); +extern bool_t * pmap3_unset_3_svc(); #define PMAP3_GETADDR 3 extern pmap3_getaddr_result * pmap3_getaddr_3(); extern pmap3_getaddr_result * pmap3_getaddr_3_svc(); diff --git a/portmap/portmap.c b/portmap/portmap.c index 926ca60..16a43dc 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -209,6 +209,56 @@ int rpc_pmap3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) return 0; } +int rpc_pmap3_set_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data) +{ + struct rpc_pdu *pdu; + + pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V3, PMAP3_SET, 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/SET call"); + return -1; + } + + if (zdr_pmap3_mapping(&pdu->zdr, map) == 0) { + rpc_set_error(rpc, "ZDR error: Failed to encode data for PORTMAP3/SET call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Failed to queue PORTMAP3/SET pdu"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + return 0; +} + +int rpc_pmap3_unset_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data) +{ + struct rpc_pdu *pdu; + + pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V3, PMAP3_UNSET, 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/UNSET call"); + return -1; + } + + if (zdr_pmap3_mapping(&pdu->zdr, map) == 0) { + rpc_set_error(rpc, "ZDR error: Failed to encode data for PORTMAP3/UNSET call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Failed to queue PORTMAP3/UNSET pdu"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + return 0; +} + int rpc_pmap3_getaddr_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data) { struct rpc_pdu *pdu; diff --git a/portmap/portmap.x b/portmap/portmap.x index 61a9d5d..0f62858 100644 --- a/portmap/portmap.x +++ b/portmap/portmap.x @@ -77,6 +77,12 @@ program PMAP_PROGRAM { void PMAP3_NULL(void) = 0; + bool + PMAP3_SET(pmap3_mapping) = 1; + + bool + PMAP3_UNSET(pmap3_mapping) = 2; + pmap3_getaddr_result PMAP3_GETADDR(pmap3_mapping) = 3; -- 2.34.1