PORTMAP: Add support for V3 DUMP command
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sun, 16 Mar 2014 21:15:34 +0000 (14:15 -0700)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Sun, 16 Mar 2014 21:17:06 +0000 (14:17 -0700)
This implements the missing procedure from Issue #65

examples/Makefile.am
examples/nfsclient-raw.c
include/nfsc/libnfs-raw.h
lib/libnfs-win32.def
portmap/libnfs-raw-portmap.c
portmap/libnfs-raw-portmap.h
portmap/portmap.c
portmap/portmap.x

index 39f5a17eea57d402499c5de6951ad3f22078a2cc..10fd9ea737635c83ae3b0d490127378330af2bf3 100644 (file)
@@ -5,8 +5,8 @@ AM_CPPFLAGS = \
        -I$(abs_top_srcdir)/include/nfsc \
        -I$(abs_top_srcdir)/mount \
        -I$(abs_top_srcdir)/nfs \
-       -I$(abs_top_srcdir)/rquota \
        -I$(abs_top_srcdir)/portmap \
+       -I$(abs_top_srcdir)/rquota \
        "-D_U_=__attribute__((unused))"
 
 AM_LDFLAGS = ../lib/.libs/libnfs.la -lpopt
index 28dd45ceccf77bc469a9d32cd420a8ae27e2d360..fd6575f21fac787d3e0330d9216073bf126861a9 100644 (file)
@@ -44,6 +44,7 @@
 #include "libnfs-raw.h"
 #include "libnfs-raw-mount.h"
 #include "libnfs-raw-nfs.h"
+#include "libnfs-raw-portmap.h"
 #include "libnfs-raw-rquota.h"
 
 struct client {
@@ -345,9 +346,11 @@ void pmap_getport1_cb(struct rpc_context *rpc, int status, void *data, void *pri
        }
 }
 
-void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+void pmap_dump_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
 {
        struct client *client = private_data;
+       struct pmap_dump_result *dr = data;
+       struct pmap_mapping_list *list = dr->list;
 
        if (status == RPC_STATUS_ERROR) {
                printf("portmapper null call failed with \"%s\"\n", (char *)data);
@@ -358,7 +361,16 @@ void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private
                exit(10);
        }
 
-       printf("Got reply from server for PORTMAP/NULL procedure.\n");
+       printf("Got reply from server for PORTMAP/DUMP procedure.\n");
+       while (list) {
+               printf("Prog:%d Vers:%d Protocol:%d Port:%d\n",
+                       list->map.prog,
+                       list->map.vers,
+                       list->map.prot,
+                       list->map.port);
+               list = list->next;
+       }
+
        printf("Send getport request asking for MOUNT port\n");
        if (rpc_pmap_getport_async(rpc, RQUOTA_PROGRAM, RQUOTA_V1, IPPROTO_TCP, pmap_getport1_cb, client) != 0) {
                printf("Failed to send getport request\n");
@@ -366,6 +378,27 @@ void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private
        }
 }
 
+void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("portmapper null call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("portmapper null call to server %s failed, status:%d\n", client->server, status);
+               exit(10);
+       }
+
+       printf("Got reply from server for PORTMAP/NULL procedure.\n");
+       printf("Send PMAP/DUMP command\n");
+       if (rpc_pmap_dump_async(rpc, pmap_dump_cb, client) != 0) {
+               printf("Failed to send getport request\n");
+               exit(10);
+       }
+}
+
 void pmap_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
 {
        struct client *client = private_data;
index c5eeb90d1bbc701ab192325cc8932a19a32cbb6b..9d6b0ec099e2245fb3c3fcd215a306f91b925eda 100644 (file)
@@ -187,6 +187,22 @@ EXTERN int rpc_pmap_set_async(struct rpc_context *rpc, int program, int version,
  */
 EXTERN int rpc_pmap_unset_async(struct rpc_context *rpc, int program, int version, int protocol, int port, rpc_cb cb, void *private_data);
 
+/*
+ * Call PORTMAPPER/DUMP.
+ * 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 struct *pmap_mapping_list.
+ * 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_pmap_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
+
 /*
  * Call PORTMAPPER/CALLIT.
  * Function returns
index 100f0cb492c40ed5407f3ede6f88a5ae543ca0dd..7eae9520c9a85d4b47d8267b3300364e4bf0acaa 100644 (file)
@@ -100,6 +100,7 @@ rpc_pmap_null_async
 rpc_pmap_getport_async
 rpc_pmap_set_async
 rpc_pmap_unset_async
+rpc_pmap_dump_async
 rpc_pmap_callit_async
 rpc_mount_null_async
 rpc_mount_mnt_async
index 347756444bf827a3ee23f52337224f3d7582d917..a07a1e62e025374b5d70b8d07a19d00853332ac1 100644 (file)
@@ -130,3 +130,27 @@ zdr_pmap_call_result (ZDR *zdrs, pmap_call_result *objp)
                 return FALSE;
        return TRUE;
 }
+
+bool_t
+zdr_pmap_mapping_list (ZDR *zdrs, pmap_mapping_list *objp)
+{
+       register int32_t *buf;
+       buf = NULL;
+
+        if (!zdr_pmap_mapping (zdrs, &objp->map))
+                return FALSE;
+        if (!zdr_pointer (zdrs, (char **)&objp->next, sizeof (pmap_mapping_list), (zdrproc_t) zdr_pmap_mapping_list))
+                return FALSE;
+       return TRUE;
+}
+
+bool_t
+zdr_pmap_dump_result (ZDR *zdrs, pmap_dump_result *objp)
+{
+       register int32_t *buf;
+       buf = NULL;
+
+        if (!zdr_pointer (zdrs, (char **)&objp->list, sizeof (pmap_mapping_list), (zdrproc_t) zdr_pmap_mapping_list))
+                return FALSE;
+       return TRUE;
+}
index df88b6786b58f9bac1ea7019a8e65a0e6e19c298..f8d9a45b613fdcf0cc22a71c37614b1ac9b6791a 100644 (file)
@@ -6,7 +6,8 @@
 #ifndef _PORTMAP_H_RPCGEN
 #define _PORTMAP_H_RPCGEN
 
-#include <nfsc/libnfs-zdr.h>
+
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,6 +43,17 @@ struct pmap_call_result {
 };
 typedef struct pmap_call_result pmap_call_result;
 
+struct pmap_mapping_list {
+       pmap_mapping map;
+       struct pmap_mapping_list *next;
+};
+typedef struct pmap_mapping_list pmap_mapping_list;
+
+struct pmap_dump_result {
+       struct pmap_mapping_list *list;
+};
+typedef struct pmap_dump_result pmap_dump_result;
+
 #define PMAP_PROGRAM 100000
 #define PMAP_V2 2
 
@@ -58,6 +70,9 @@ extern  bool_t * pmap_unset_2_svc(pmap_mapping *, struct svc_req *);
 #define PMAP_GETPORT 3
 extern  u_int * pmap_getport_2(pmap_mapping *, CLIENT *);
 extern  u_int * pmap_getport_2_svc(pmap_mapping *, struct svc_req *);
+#define PMAP_DUMP 4
+extern  pmap_mapping_list * pmap_dump_2(void *, CLIENT *);
+extern  pmap_mapping_list * pmap_dump_2_svc(void *, struct svc_req *);
 #define PMAP_CALLIT 5
 extern  pmap_call_result * pmap_callit_2(pmap_call_args *, CLIENT *);
 extern  pmap_call_result * pmap_callit_2_svc(pmap_call_args *, struct svc_req *);
@@ -76,6 +91,9 @@ extern  bool_t * pmap_unset_2_svc();
 #define PMAP_GETPORT 3
 extern  u_int * pmap_getport_2();
 extern  u_int * pmap_getport_2_svc();
+#define PMAP_DUMP 4
+extern  pmap_mapping_list * pmap_dump_2();
+extern  pmap_mapping_list * pmap_dump_2_svc();
 #define PMAP_CALLIT 5
 extern  pmap_call_result * pmap_callit_2();
 extern  pmap_call_result * pmap_callit_2_svc();
@@ -88,11 +106,15 @@ extern int pmap_program_2_freeresult ();
 extern  bool_t zdr_pmap_mapping (ZDR *, pmap_mapping*);
 extern  bool_t zdr_pmap_call_args (ZDR *, pmap_call_args*);
 extern  bool_t zdr_pmap_call_result (ZDR *, pmap_call_result*);
+extern  bool_t zdr_pmap_mapping_list (ZDR *, pmap_mapping_list*);
+extern  bool_t zdr_pmap_dump_result (ZDR *, pmap_dump_result*);
 
 #else /* K&R C */
 extern bool_t zdr_pmap_mapping ();
 extern bool_t zdr_pmap_call_args ();
 extern bool_t zdr_pmap_call_result ();
+extern bool_t zdr_pmap_mapping_list ();
+extern bool_t zdr_pmap_dump_result ();
 
 #endif /* K&R C */
 
index d1c1488ba616384337387d406e8032f479475882..5042e8c19b0eb6bc7fb724953ee28c87d8a53b87 100644 (file)
@@ -135,6 +135,25 @@ int rpc_pmap_unset_async(struct rpc_context *rpc, int program, int version, int
        return 0;
 }
 
+int rpc_pmap_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
+{
+       struct rpc_pdu *pdu;
+
+       pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_DUMP, cb, private_data, (zdrproc_t)zdr_pmap_dump_result, sizeof(pmap_dump_result));
+       if (pdu == NULL) {
+               rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/dump call");
+               return -1;
+       }
+
+       if (rpc_queue_pdu(rpc, pdu) != 0) {
+               rpc_set_error(rpc, "Failed to queue portmap/dump pdu");
+               rpc_free_pdu(rpc, pdu);
+               return -1;
+       }
+
+       return 0;
+}
+
 int rpc_pmap_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;
index ef9f08e699b9465f56303039990702ddeedb992c..17fd980455449cff57bde695be42296d1b28ff4e 100644 (file)
@@ -23,6 +23,15 @@ struct pmap_call_result {
        opaque res<>;
 };
 
+struct pmap_mapping_list {
+       pmap_mapping map;
+       pmap_mapping_list *next;
+};
+
+struct pmap_dump_result {
+       struct pmap_mapping_list *list;
+};
+
 program PMAP_PROGRAM {
        version PMAP_V2 {
                void
@@ -37,6 +46,9 @@ program PMAP_PROGRAM {
                unsigned int
                PMAP_GETPORT(pmap_mapping)   = 3;
 
+               pmap_mapping_list
+               PMAP_DUMP(void)              = 4;
+
                pmap_call_result
                PMAP_CALLIT(pmap_call_args)  = 5;
        } = 2;