From: Ronnie Sahlberg Date: Tue, 18 Mar 2014 03:19:03 +0000 (-0700) Subject: PORTMAP: Add support for PORTMAP v3 CALLIT X-Git-Tag: upstream/1.9.6^2~64 X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=commitdiff_plain;h=b71f7e8291c4b9bb7e2569174644e80c341ea4e2 PORTMAP: Add support for PORTMAP v3 CALLIT --- diff --git a/include/nfsc/libnfs-raw.h b/include/nfsc/libnfs-raw.h index 74dd439..b8330a6 100644 --- a/include/nfsc/libnfs-raw.h +++ b/include/nfsc/libnfs-raw.h @@ -211,7 +211,7 @@ EXTERN int rpc_pmap2_dump_async(struct rpc_context *rpc, rpc_cb cb, void *privat * * When the callback is invoked, status indicates the result: * RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon - * data is a 'pmap_call_result' pointer. + * data is a 'pmap2_call_result' pointer. * 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. @@ -304,6 +304,22 @@ 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/CALLIT. + * 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 'pmap3_call_result' pointer. + * 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_callit_async(struct rpc_context *rpc, int program, int version, int procedure, char *data, int datalen, rpc_cb cb, void *private_data); + /* * Call PORTMAPPER3/GETTIME. * Function returns diff --git a/lib/libnfs-win32.def b/lib/libnfs-win32.def index 7b908e7..d6bc077 100644 --- a/lib/libnfs-win32.def +++ b/lib/libnfs-win32.def @@ -103,8 +103,11 @@ rpc_pmap2_unset_async rpc_pmap2_dump_async rpc_pmap2_callit_async rpc_pmap3_null_async +rpc_pmap3_set_async +rpc_pmap3_unset_async rpc_pmap3_getaddr_async rpc_pmap3_dump_async +rpc_pmap3_callit_async rpc_pmap3_gettime_async rpc_mount_null_async rpc_mount_mnt_async diff --git a/portmap/libnfs-raw-portmap.c b/portmap/libnfs-raw-portmap.c index 76c1cdf..30ff664 100644 --- a/portmap/libnfs-raw-portmap.c +++ b/portmap/libnfs-raw-portmap.c @@ -208,3 +208,72 @@ zdr_pmap3_dump_result (ZDR *zdrs, pmap3_dump_result *objp) return FALSE; return TRUE; } + +bool_t +zdr_pmap3_call_args (ZDR *zdrs, pmap3_call_args *objp) +{ + register int32_t *buf; + buf = NULL; + + + if (zdrs->x_op == ZDR_ENCODE) { + buf = ZDR_INLINE (zdrs, 3 * BYTES_PER_ZDR_UNIT); + if (buf == NULL) { + if (!zdr_u_int (zdrs, &objp->prog)) + return FALSE; + if (!zdr_u_int (zdrs, &objp->vers)) + return FALSE; + if (!zdr_u_int (zdrs, &objp->proc)) + return FALSE; + + } else { + IZDR_PUT_U_LONG(buf, objp->prog); + IZDR_PUT_U_LONG(buf, objp->vers); + IZDR_PUT_U_LONG(buf, objp->proc); + } + if (!zdr_bytes (zdrs, (char **)&objp->args.args_val, (u_int *) &objp->args.args_len, ~0)) + return FALSE; + return TRUE; + } else if (zdrs->x_op == ZDR_DECODE) { + buf = ZDR_INLINE (zdrs, 3 * BYTES_PER_ZDR_UNIT); + if (buf == NULL) { + if (!zdr_u_int (zdrs, &objp->prog)) + return FALSE; + if (!zdr_u_int (zdrs, &objp->vers)) + return FALSE; + if (!zdr_u_int (zdrs, &objp->proc)) + return FALSE; + + } else { + objp->prog = IZDR_GET_U_LONG(buf); + objp->vers = IZDR_GET_U_LONG(buf); + objp->proc = IZDR_GET_U_LONG(buf); + } + if (!zdr_bytes (zdrs, (char **)&objp->args.args_val, (u_int *) &objp->args.args_len, ~0)) + return FALSE; + return TRUE; + } + + if (!zdr_u_int (zdrs, &objp->prog)) + return FALSE; + if (!zdr_u_int (zdrs, &objp->vers)) + return FALSE; + if (!zdr_u_int (zdrs, &objp->proc)) + return FALSE; + if (!zdr_bytes (zdrs, (char **)&objp->args.args_val, (u_int *) &objp->args.args_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +zdr_pmap3_call_result (ZDR *zdrs, pmap3_call_result *objp) +{ + register int32_t *buf; + buf = NULL; + + if (!zdr_u_int (zdrs, &objp->port)) + return FALSE; + if (!zdr_bytes (zdrs, (char **)&objp->res.res_val, (u_int *) &objp->res.res_len, ~0)) + return FALSE; + return TRUE; +} diff --git a/portmap/libnfs-raw-portmap.h b/portmap/libnfs-raw-portmap.h index 2a41831..c888263 100644 --- a/portmap/libnfs-raw-portmap.h +++ b/portmap/libnfs-raw-portmap.h @@ -79,6 +79,26 @@ struct pmap3_dump_result { }; typedef struct pmap3_dump_result pmap3_dump_result; +struct pmap3_call_args { + u_int prog; + u_int vers; + u_int proc; + struct { + u_int args_len; + char *args_val; + } args; +}; +typedef struct pmap3_call_args pmap3_call_args; + +struct pmap3_call_result { + u_int port; + struct { + u_int res_len; + char *res_val; + } res; +}; +typedef struct pmap3_call_result pmap3_call_result; + #define PMAP_PROGRAM 100000 #define PMAP_V2 2 @@ -142,6 +162,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_CALLIT 5 +extern pmap3_call_result * pmap3_callit_3(pmap3_call_args *, CLIENT *); +extern pmap3_call_result * pmap3_callit_3_svc(pmap3_call_args *, 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 *); @@ -163,6 +186,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_CALLIT 5 +extern pmap3_call_result * pmap3_callit_3(); +extern pmap3_call_result * pmap3_callit_3_svc(); #define PMAP3_GETTIME 6 extern u_int * pmap3_gettime_3(); extern u_int * pmap3_gettime_3_svc(); @@ -181,6 +207,8 @@ extern bool_t zdr_pmap3_getaddr_result (ZDR *, pmap3_getaddr_result*); extern bool_t zdr_pmap3_mapping (ZDR *, pmap3_mapping*); extern bool_t zdr_pmap3_mapping_list (ZDR *, pmap3_mapping_list*); extern bool_t zdr_pmap3_dump_result (ZDR *, pmap3_dump_result*); +extern bool_t zdr_pmap3_call_args (ZDR *, pmap3_call_args*); +extern bool_t zdr_pmap3_call_result (ZDR *, pmap3_call_result*); #else /* K&R C */ extern bool_t zdr_pmap2_mapping (); @@ -192,6 +220,8 @@ extern bool_t zdr_pmap3_getaddr_result (); extern bool_t zdr_pmap3_mapping (); extern bool_t zdr_pmap3_mapping_list (); extern bool_t zdr_pmap3_dump_result (); +extern bool_t zdr_pmap3_call_args (); +extern bool_t zdr_pmap3_call_result (); #endif /* K&R C */ diff --git a/portmap/portmap.c b/portmap/portmap.c index fcfb4cd..5c0633b 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -321,3 +321,34 @@ int rpc_pmap3_gettime_async(struct rpc_context *rpc, rpc_cb cb, void *private_da return 0; } + +int rpc_pmap3_callit_async(struct rpc_context *rpc, int program, int version, int procedure, char *data, int datalen, rpc_cb cb, void *private_data) +{ + struct rpc_pdu *pdu; + struct pmap3_call_args ca; + + pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V3, PMAP3_CALLIT, cb, private_data, (zdrproc_t)zdr_pmap3_call_result, sizeof(pmap3_call_result)); + if (pdu == NULL) { + rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for PORTMAP3/CALLIT call"); + return -1; + } + + ca.prog = program; + ca.vers = version; + ca.proc = procedure; + ca.args.args_len = datalen; + ca.args.args_val = data; + + if (zdr_pmap3_call_args(&pdu->zdr, &ca) == 0) { + rpc_set_error(rpc, "ZDR error: Failed to encode data for PORTMAP3/CALLIT call"); + rpc_free_pdu(rpc, pdu); + return -1; + } + + if (rpc_queue_pdu(rpc, pdu) != 0) { + rpc_set_error(rpc, "Failed to queue PORTMAP3/CALLIT pdu: %s", rpc_get_error(rpc)); + return -1; + } + + return 0; +} diff --git a/portmap/portmap.x b/portmap/portmap.x index 0f8a5dd..238656f 100644 --- a/portmap/portmap.x +++ b/portmap/portmap.x @@ -53,6 +53,18 @@ struct pmap3_dump_result { struct pmap3_mapping_list *list; }; +struct pmap3_call_args { + unsigned int prog; + unsigned int vers; + unsigned int proc; + opaque args<>; +}; + +struct pmap3_call_result { + unsigned int port; + opaque res<>; +}; + program PMAP_PROGRAM { version PMAP_V2 { void @@ -89,6 +101,9 @@ program PMAP_PROGRAM { pmap3_dump_result PMAP3_DUMP(void) = 4; + pmap3_call_result + PMAP3_CALLIT(pmap3_call_args) = 5; + unsigned int PMAP3_GETTIME(void) = 6; } = 3;