PORTMAP: Add support for V3 DUMP command

This implements the missing procedure from Issue #65
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2014-03-16 14:15:34 -07:00
parent 2aec85d132
commit 8ae943f608
8 changed files with 131 additions and 4 deletions

View 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

View 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,6 +346,38 @@ void pmap_getport1_cb(struct rpc_context *rpc, int status, void *data, void *pri
}
}
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);
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/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");
exit(10);
}
}
void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
@ -359,8 +392,8 @@ void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private
}
printf("Got reply from server for PORTMAP/NULL procedure.\n");
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("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);
}

View 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

View 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

View 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;
}

View 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 */

View 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;

View 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;