PORTMAP: Add support for PORTMAP v3 GETADDR
parent
4edd78302d
commit
7fbedfdefd
|
@ -104,6 +104,26 @@ void pmap3_dump_cb(struct rpc_context *rpc, int status, void *data, void *privat
|
|||
client->is_finished = 1;
|
||||
}
|
||||
|
||||
void pmap3_getaddr_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
|
||||
{
|
||||
struct client *client = private_data;
|
||||
struct pmap3_getaddr_result *gar = data;
|
||||
|
||||
if (status == RPC_STATUS_ERROR) {
|
||||
printf("PORTMAP3/GETADDR call failed with \"%s\"\n", (char *)data);
|
||||
exit(10);
|
||||
}
|
||||
if (status != RPC_STATUS_SUCCESS) {
|
||||
printf("PORTMAP3/GETADDR call failed, status:%d\n", status);
|
||||
exit(10);
|
||||
}
|
||||
|
||||
printf("PORTMAP3/GETADDR:\n");
|
||||
printf(" Addr:%s\n", gar->addr);
|
||||
|
||||
client->is_finished = 1;
|
||||
}
|
||||
|
||||
void pmap2_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
|
||||
{
|
||||
struct client *client = private_data;
|
||||
|
@ -202,9 +222,13 @@ int main(int argc _U_, char *argv[] _U_)
|
|||
int null2 = 0;
|
||||
int dump2 = 0;
|
||||
int null3 = 0;
|
||||
int getaddr3 = 0;
|
||||
int dump3 = 0;
|
||||
int command_found = 0;
|
||||
|
||||
int getaddr3prog, getaddr3vers;
|
||||
char *getaddr3netid;
|
||||
|
||||
rpc = rpc_init_context();
|
||||
if (rpc == NULL) {
|
||||
printf("failed to init context\n");
|
||||
|
@ -221,6 +245,12 @@ int main(int argc _U_, char *argv[] _U_)
|
|||
} else if (!strcmp(argv[i], "dump3")) {
|
||||
dump3 = 1;
|
||||
command_found++;
|
||||
} else if (!strcmp(argv[i], "getaddr3")) {
|
||||
getaddr3 = 1;
|
||||
getaddr3prog = atoi(argv[++i]);
|
||||
getaddr3vers = atoi(argv[++i]);
|
||||
getaddr3netid = argv[++i];
|
||||
command_found++;
|
||||
} else if (!strcmp(argv[i], "null3")) {
|
||||
null3 = 1;
|
||||
command_found++;
|
||||
|
@ -267,6 +297,20 @@ int main(int argc _U_, char *argv[] _U_)
|
|||
}
|
||||
wait_until_finished(rpc, &client);
|
||||
}
|
||||
if (getaddr3) {
|
||||
struct pmap3_mapping map;
|
||||
|
||||
map.prog=getaddr3prog;
|
||||
map.vers=getaddr3vers;
|
||||
map.netid=getaddr3netid;
|
||||
map.addr="";
|
||||
map.owner="";
|
||||
if (rpc_pmap3_getaddr_async(rpc, &map, pmap3_getaddr_cb, &client) != 0) {
|
||||
printf("Failed to send GETADDR3 request\n");
|
||||
exit(10);
|
||||
}
|
||||
wait_until_finished(rpc, &client);
|
||||
}
|
||||
|
||||
|
||||
rpc_destroy_context(rpc);
|
||||
|
|
|
@ -239,6 +239,23 @@ 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/GETADDR.
|
||||
* 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 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_mapping;
|
||||
EXTERN int rpc_pmap3_getaddr_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data);
|
||||
|
||||
/*
|
||||
* Call PORTMAPPER3/DUMP.
|
||||
* Function returns
|
||||
|
|
|
@ -102,6 +102,9 @@ rpc_pmap2_set_async
|
|||
rpc_pmap2_unset_async
|
||||
rpc_pmap2_dump_async
|
||||
rpc_pmap2_callit_async
|
||||
rpc_pmap3_null_async
|
||||
rpc_pmap3_getaddr_async
|
||||
rpc_pmap3_dump_async
|
||||
rpc_mount_null_async
|
||||
rpc_mount_mnt_async
|
||||
rpc_mount_dump_async
|
||||
|
|
|
@ -155,6 +155,17 @@ zdr_pmap2_dump_result (ZDR *zdrs, pmap2_dump_result *objp)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
zdr_pmap3_getaddr_result (ZDR *zdrs, pmap3_getaddr_result *objp)
|
||||
{
|
||||
register int32_t *buf;
|
||||
buf = NULL;
|
||||
|
||||
if (!zdr_string (zdrs, &objp->addr, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
zdr_pmap3_mapping (ZDR *zdrs, pmap3_mapping *objp)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,11 @@ struct pmap2_dump_result {
|
|||
};
|
||||
typedef struct pmap2_dump_result pmap2_dump_result;
|
||||
|
||||
struct pmap3_getaddr_result {
|
||||
char *addr;
|
||||
};
|
||||
typedef struct pmap3_getaddr_result pmap3_getaddr_result;
|
||||
|
||||
struct pmap3_mapping {
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
|
@ -125,6 +130,9 @@ 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_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 *);
|
||||
#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 *);
|
||||
|
@ -134,6 +142,9 @@ 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_GETADDR 3
|
||||
extern pmap3_getaddr_result * pmap3_getaddr_3();
|
||||
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();
|
||||
|
@ -148,6 +159,7 @@ extern bool_t zdr_pmap2_call_args (ZDR *, pmap2_call_args*);
|
|||
extern bool_t zdr_pmap2_call_result (ZDR *, pmap2_call_result*);
|
||||
extern bool_t zdr_pmap2_mapping_list (ZDR *, pmap2_mapping_list*);
|
||||
extern bool_t zdr_pmap2_dump_result (ZDR *, pmap2_dump_result*);
|
||||
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*);
|
||||
|
@ -158,6 +170,7 @@ extern bool_t zdr_pmap2_call_args ();
|
|||
extern bool_t zdr_pmap2_call_result ();
|
||||
extern bool_t zdr_pmap2_mapping_list ();
|
||||
extern bool_t zdr_pmap2_dump_result ();
|
||||
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 ();
|
||||
|
|
|
@ -209,6 +209,31 @@ int rpc_pmap3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
|
|||
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;
|
||||
|
||||
pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V3, PMAP3_GETADDR, 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/GETADDR call");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (zdr_pmap3_mapping(&pdu->zdr, map) == 0) {
|
||||
rpc_set_error(rpc, "ZDR error: Failed to encode data for PORTMAP3/GETADDR call");
|
||||
rpc_free_pdu(rpc, pdu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rpc_queue_pdu(rpc, pdu) != 0) {
|
||||
rpc_set_error(rpc, "Failed to queue PORTMAP3/GETADDR pdu");
|
||||
rpc_free_pdu(rpc, pdu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rpc_pmap3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
|
||||
{
|
||||
struct rpc_pdu *pdu;
|
||||
|
|
|
@ -32,6 +32,10 @@ struct pmap2_dump_result {
|
|||
struct pmap2_mapping_list *list;
|
||||
};
|
||||
|
||||
struct pmap3_getaddr_result {
|
||||
string addr<>;
|
||||
};
|
||||
|
||||
struct pmap3_mapping {
|
||||
unsigned int prog;
|
||||
unsigned int vers;
|
||||
|
@ -64,7 +68,7 @@ program PMAP_PROGRAM {
|
|||
PMAP2_GETPORT(pmap2_mapping) = 3;
|
||||
|
||||
pmap2_dump_result
|
||||
PMAP2_DUMP(void) = 4;
|
||||
PMAP2_DUMP(void) = 4;
|
||||
|
||||
pmap2_call_result
|
||||
PMAP2_CALLIT(pmap2_call_args) = 5;
|
||||
|
@ -73,9 +77,11 @@ program PMAP_PROGRAM {
|
|||
void
|
||||
PMAP3_NULL(void) = 0;
|
||||
|
||||
pmap3_getaddr_result
|
||||
PMAP3_GETADDR(pmap3_mapping) = 3;
|
||||
|
||||
pmap3_dump_result
|
||||
PMAP3_DUMP(void) = 4;
|
||||
|
||||
} = 3;
|
||||
} = 100000;
|
||||
|
||||
|
|
Loading…
Reference in New Issue