From 1bc49c70c67a05a9b30e96ae30c26311d87871ed Mon Sep 17 00:00:00 2001 From: Olaf Kirch Date: Tue, 16 Dec 2014 13:43:30 -0500 Subject: [PATCH] Introduce new helper function getpmaphandle This moves some code for creation of PMAP handles out of the getaddr code and into a function of its own. Signed-off-by: Olaf Kirch Signed-off-by: Steve Dickson --- INSTALL | 2 +- src/rpcb_clnt.c | 62 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/INSTALL b/INSTALL index 8b641e3..f812f5a 120000 --- a/INSTALL +++ b/INSTALL @@ -1 +1 @@ -/usr/share/automake-1.13/INSTALL \ No newline at end of file +/usr/share/automake-1.14/INSTALL \ No newline at end of file diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c index a796593..f1c71a2 100644 --- a/src/rpcb_clnt.c +++ b/src/rpcb_clnt.c @@ -401,6 +401,44 @@ out_err: return (client); } +/* + * Create a PMAP client handle. + */ +static CLIENT * +getpmaphandle(nconf, hostname, tgtaddr) + const struct netconfig *nconf; + const char *hostname; + char **tgtaddr; +{ + CLIENT *client = NULL; + rpcvers_t pmapvers = 2; + + /* + * Try UDP only - there are some portmappers out + * there that use UDP only. + */ + if (nconf == NULL || strcmp(nconf->nc_proto, NC_TCP) == 0) { + struct netconfig *newnconf; + + if ((newnconf = getnetconfigent("udp")) == NULL) { + rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; + return NULL; + } + client = getclnthandle(hostname, newnconf, tgtaddr); + freenetconfigent(newnconf); + } else if (strcmp(nconf->nc_proto, NC_UDP) == 0) { + if (strcmp(nconf->nc_protofmly, NC_INET) != 0) + return NULL; + client = getclnthandle(hostname, nconf, tgtaddr); + } + + /* Set version */ + if (client != NULL) + CLNT_CONTROL(client, CLSET_VERS, (char *)&pmapvers); + + return client; +} + /* XXX */ #define IN4_LOCALHOST_STRING "127.0.0.1" #define IN6_LOCALHOST_STRING "::1" @@ -733,34 +771,20 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp) if (strcmp(nconf->nc_protofmly, NC_INET) == 0) { u_short port = 0; struct netbuf remote; - rpcvers_t pmapvers = 2; struct pmap pmapparms; - /* - * Try UDP only - there are some portmappers out - * there that use UDP only. - */ - if (strcmp(nconf->nc_proto, NC_TCP) == 0) { - struct netconfig *newnconf; - - if ((newnconf = getnetconfigent("udp")) == NULL) { - rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; - return (NULL); - } - client = getclnthandle(host, newnconf, &parms.r_addr); - freenetconfigent(newnconf); - } else if (strcmp(nconf->nc_proto, NC_UDP) == 0) - client = getclnthandle(host, nconf, &parms.r_addr); - else + if (strcmp(nconf->nc_proto, NC_UDP) != 0 + && strcmp(nconf->nc_proto, NC_TCP) != 0) goto try_rpcbind; + + client = getpmaphandle(nconf, host, &parms.r_addr); if (client == NULL) return (NULL); /* - * Set version and retry timeout. + * Set retry timeout. */ CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)&rpcbrmttime); - CLNT_CONTROL(client, CLSET_VERS, (char *)&pmapvers); pmapparms.pm_prog = program; pmapparms.pm_vers = version; -- 2.50.1