|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Copyright (c) 2010, Oracle America, Inc.
|
|
Packit |
00408a |
* All rights reserved.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
00408a |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
00408a |
* - Redistributions of source code must retain the above copyright notice,
|
|
Packit |
00408a |
* this list of conditions and the following disclaimer.
|
|
Packit |
00408a |
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
00408a |
* this list of conditions and the following disclaimer in the documentation
|
|
Packit |
00408a |
* and/or other materials provided with the distribution.
|
|
Packit |
00408a |
* - Neither the name of the "Oracle America, Inc." nor the names of its
|
|
Packit |
00408a |
* contributors may be used to endorse or promote products derived
|
|
Packit |
00408a |
* from this software without specific prior written permission.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
00408a |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
00408a |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
00408a |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
Packit |
00408a |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
00408a |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
00408a |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
00408a |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
00408a |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
00408a |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
00408a |
* POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* rpcb_clnt.c
|
|
Packit |
00408a |
* interface to rpcbind rpc service.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
#include <pthread.h>
|
|
Packit |
00408a |
#include <reentrant.h>
|
|
Packit |
00408a |
#include <sys/types.h>
|
|
Packit |
00408a |
#include <sys/socket.h>
|
|
Packit |
00408a |
#include <sys/un.h>
|
|
Packit |
00408a |
#include <sys/utsname.h>
|
|
Packit |
00408a |
#include <rpc/rpc.h>
|
|
Packit |
00408a |
#include <rpc/rpcb_prot.h>
|
|
Packit |
00408a |
#include <rpc/nettype.h>
|
|
Packit |
00408a |
#include <netconfig.h>
|
|
Packit |
00408a |
#ifdef PORTMAP
|
|
Packit |
00408a |
#include <netinet/in.h> /* FOR IPPROTO_TCP/UDP definitions */
|
|
Packit |
00408a |
#include <rpc/pmap_prot.h>
|
|
Packit |
00408a |
#endif /* PORTMAP */
|
|
Packit |
00408a |
#include <stdio.h>
|
|
Packit |
00408a |
#include <errno.h>
|
|
Packit |
00408a |
#include <stdlib.h>
|
|
Packit |
00408a |
#include <string.h>
|
|
Packit |
00408a |
#include <unistd.h>
|
|
Packit |
00408a |
#include <netdb.h>
|
|
Packit |
00408a |
#include <syslog.h>
|
|
Packit |
00408a |
#include <assert.h>
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#include "rpc_com.h"
|
|
Packit |
00408a |
#include "debug.h"
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static struct timeval tottimeout = { 60, 0 };
|
|
Packit |
00408a |
static const struct timeval rmttimeout = { 3, 0 };
|
|
Packit |
00408a |
static struct timeval rpcbrmttime = { 15, 0 };
|
|
Packit |
00408a |
|
|
Packit |
00408a |
extern bool_t xdr_wrapstring(XDR *, char **);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static const char nullstring[] = "\000";
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#define RPCB_OWNER_STRING "libtirpc"
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#define CACHESIZE 6
|
|
Packit |
00408a |
|
|
Packit |
00408a |
struct address_cache {
|
|
Packit |
00408a |
char *ac_host;
|
|
Packit |
00408a |
char *ac_netid;
|
|
Packit |
00408a |
char *ac_uaddr;
|
|
Packit |
00408a |
struct netbuf *ac_taddr;
|
|
Packit |
00408a |
struct address_cache *ac_next;
|
|
Packit |
00408a |
};
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static struct address_cache *front;
|
|
Packit |
00408a |
static int cachesize;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#define CLCR_GET_RPCB_TIMEOUT 1
|
|
Packit |
00408a |
#define CLCR_SET_RPCB_TIMEOUT 2
|
|
Packit |
00408a |
|
|
Packit |
00408a |
|
|
Packit |
00408a |
extern int __rpc_lowvers;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static struct address_cache *check_cache(const char *, const char *);
|
|
Packit |
00408a |
static void delete_cache(struct netbuf *);
|
|
Packit |
00408a |
static void add_cache(const char *, const char *, struct netbuf *, char *);
|
|
Packit |
00408a |
static CLIENT *getclnthandle(const char *, const struct netconfig *, char **);
|
|
Packit |
00408a |
static CLIENT *local_rpcb(void);
|
|
Packit |
00408a |
#ifdef NOTUSED
|
|
Packit |
00408a |
static struct netbuf *got_entry(rpcb_entry_list_ptr, const struct netconfig *);
|
|
Packit |
00408a |
#endif
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* This routine adjusts the timeout used for calls to the remote rpcbind.
|
|
Packit |
00408a |
* Also, this routine can be used to set the use of portmapper version 2
|
|
Packit |
00408a |
* only when doing rpc_broadcasts
|
|
Packit |
00408a |
* These are private routines that may not be provided in future releases.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
bool_t
|
|
Packit |
00408a |
__rpc_control(request, info)
|
|
Packit |
00408a |
int request;
|
|
Packit |
00408a |
void *info;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
switch (request) {
|
|
Packit |
00408a |
case CLCR_GET_RPCB_TIMEOUT:
|
|
Packit |
00408a |
*(struct timeval *)info = tottimeout;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
case CLCR_SET_RPCB_TIMEOUT:
|
|
Packit |
00408a |
tottimeout = *(struct timeval *)info;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
case CLCR_SET_LOWVERS:
|
|
Packit |
00408a |
__rpc_lowvers = *(int *)info;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
case CLCR_GET_LOWVERS:
|
|
Packit |
00408a |
*(int *)info = __rpc_lowvers;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
default:
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
return (TRUE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* It might seem that a reader/writer lock would be more reasonable here.
|
|
Packit |
00408a |
* However because getclnthandle(), the only user of the cache functions,
|
|
Packit |
00408a |
* may do a delete_cache() operation if a check_cache() fails to return an
|
|
Packit |
00408a |
* address useful to clnt_tli_create(), we may as well use a mutex.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* As it turns out, if the cache lock is *not* a reader/writer lock, we will
|
|
Packit |
00408a |
* block all clnt_create's if we are trying to connect to a host that's down,
|
|
Packit |
00408a |
* since the lock will be held all during that time.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
extern rwlock_t rpcbaddr_cache_lock;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* The routines check_cache(), add_cache(), delete_cache() manage the
|
|
Packit |
00408a |
* cache of rpcbind addresses for (host, netid).
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static struct address_cache *
|
|
Packit |
00408a |
check_cache(host, netid)
|
|
Packit |
00408a |
const char *host, *netid;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
struct address_cache *cptr;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* READ LOCK HELD ON ENTRY: rpcbaddr_cache_lock */
|
|
Packit |
00408a |
|
|
Packit |
00408a |
for (cptr = front; cptr != NULL; cptr = cptr->ac_next) {
|
|
Packit |
00408a |
if (!strcmp(cptr->ac_host, host) &&
|
|
Packit |
00408a |
!strcmp(cptr->ac_netid, netid)) {
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(3, ("check_cache: Found cache entry for %s: %s\n",
|
|
Packit |
00408a |
host, netid));
|
|
Packit |
00408a |
return (cptr);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
return ((struct address_cache *) NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static void
|
|
Packit |
00408a |
delete_cache(addr)
|
|
Packit |
00408a |
struct netbuf *addr;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
struct address_cache *cptr, *prevptr = NULL;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* WRITE LOCK HELD ON ENTRY: rpcbaddr_cache_lock */
|
|
Packit |
00408a |
for (cptr = front; cptr != NULL; cptr = cptr->ac_next) {
|
|
Packit |
00408a |
if (!memcmp(cptr->ac_taddr->buf, addr->buf, addr->len)) {
|
|
Packit |
00408a |
free(cptr->ac_host);
|
|
Packit |
00408a |
free(cptr->ac_netid);
|
|
Packit |
00408a |
free(cptr->ac_taddr->buf);
|
|
Packit |
00408a |
free(cptr->ac_taddr);
|
|
Packit |
00408a |
if (cptr->ac_uaddr)
|
|
Packit |
00408a |
free(cptr->ac_uaddr);
|
|
Packit |
00408a |
if (prevptr)
|
|
Packit |
00408a |
prevptr->ac_next = cptr->ac_next;
|
|
Packit |
00408a |
else
|
|
Packit |
00408a |
front = cptr->ac_next;
|
|
Packit |
00408a |
free(cptr);
|
|
Packit |
00408a |
cachesize--;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
prevptr = cptr;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
static void
|
|
Packit |
00408a |
add_cache(host, netid, taddr, uaddr)
|
|
Packit |
00408a |
const char *host, *netid;
|
|
Packit |
00408a |
char *uaddr;
|
|
Packit |
00408a |
struct netbuf *taddr;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
struct address_cache *ad_cache, *cptr, *prevptr;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
ad_cache = (struct address_cache *)
|
|
Packit |
00408a |
malloc(sizeof (struct address_cache));
|
|
Packit |
00408a |
if (!ad_cache) {
|
|
Packit |
00408a |
return;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
ad_cache->ac_host = strdup(host);
|
|
Packit |
00408a |
ad_cache->ac_netid = strdup(netid);
|
|
Packit |
00408a |
ad_cache->ac_uaddr = uaddr ? strdup(uaddr) : NULL;
|
|
Packit |
00408a |
ad_cache->ac_taddr = (struct netbuf *)malloc(sizeof (struct netbuf));
|
|
Packit |
00408a |
if (!ad_cache->ac_host || !ad_cache->ac_netid || !ad_cache->ac_taddr ||
|
|
Packit |
00408a |
(uaddr && !ad_cache->ac_uaddr))
|
|
Packit |
00408a |
goto out_free;
|
|
Packit |
00408a |
ad_cache->ac_taddr->len = ad_cache->ac_taddr->maxlen = taddr->len;
|
|
Packit |
00408a |
ad_cache->ac_taddr->buf = (char *) malloc(taddr->len);
|
|
Packit |
00408a |
if (ad_cache->ac_taddr->buf == NULL)
|
|
Packit |
00408a |
goto out_free;
|
|
Packit |
00408a |
memcpy(ad_cache->ac_taddr->buf, taddr->buf, taddr->len);
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(3, ("add_cache: Added to cache: %s : %s\n", host, netid));
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* VARIABLES PROTECTED BY rpcbaddr_cache_lock: cptr */
|
|
Packit |
00408a |
|
|
Packit |
00408a |
rwlock_wrlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
if (cachesize < CACHESIZE) {
|
|
Packit |
00408a |
ad_cache->ac_next = front;
|
|
Packit |
00408a |
front = ad_cache;
|
|
Packit |
00408a |
cachesize++;
|
|
Packit |
00408a |
} else {
|
|
Packit |
00408a |
/* Free the last entry */
|
|
Packit |
00408a |
cptr = front;
|
|
Packit |
00408a |
prevptr = NULL;
|
|
Packit |
00408a |
while (cptr->ac_next) {
|
|
Packit |
00408a |
prevptr = cptr;
|
|
Packit |
00408a |
cptr = cptr->ac_next;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(3, ("add_cache: Deleted from cache: %s : %s\n",
|
|
Packit |
00408a |
cptr->ac_host, cptr->ac_netid));
|
|
Packit |
00408a |
free(cptr->ac_host);
|
|
Packit |
00408a |
free(cptr->ac_netid);
|
|
Packit |
00408a |
free(cptr->ac_taddr->buf);
|
|
Packit |
00408a |
free(cptr->ac_taddr);
|
|
Packit |
00408a |
if (cptr->ac_uaddr)
|
|
Packit |
00408a |
free(cptr->ac_uaddr);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (prevptr) {
|
|
Packit |
00408a |
prevptr->ac_next = NULL;
|
|
Packit |
00408a |
ad_cache->ac_next = front;
|
|
Packit |
00408a |
front = ad_cache;
|
|
Packit |
00408a |
} else {
|
|
Packit |
00408a |
front = ad_cache;
|
|
Packit |
00408a |
ad_cache->ac_next = NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
free(cptr);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
rwlock_unlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
return;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
out_free:
|
|
Packit |
00408a |
free(ad_cache->ac_host);
|
|
Packit |
00408a |
free(ad_cache->ac_netid);
|
|
Packit |
00408a |
free(ad_cache->ac_uaddr);
|
|
Packit |
00408a |
free(ad_cache->ac_taddr);
|
|
Packit |
00408a |
free(ad_cache);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* This routine will return a client handle that is connected to the
|
|
Packit |
00408a |
* rpcbind. If targaddr is non-NULL, the "universal address" of the
|
|
Packit |
00408a |
* host will be stored in *targaddr; the caller is responsible for
|
|
Packit |
00408a |
* freeing this string.
|
|
Packit |
00408a |
* On error, returns NULL and free's everything.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
static CLIENT *
|
|
Packit |
00408a |
getclnthandle(host, nconf, targaddr)
|
|
Packit |
00408a |
const char *host;
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
char **targaddr;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
struct netbuf *addr, taddr;
|
|
Packit |
00408a |
struct netbuf addr_to_delete;
|
|
Packit |
00408a |
struct __rpc_sockinfo si;
|
|
Packit |
00408a |
struct addrinfo hints, *res, *tres;
|
|
Packit |
00408a |
struct address_cache *ad_cache;
|
|
Packit |
00408a |
char *tmpaddr;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (nconf == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (nconf->nc_protofmly != NULL &&
|
|
Packit |
00408a |
strcmp(nconf->nc_protofmly, NC_LOOPBACK) != 0 &&
|
|
Packit |
00408a |
host == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
|
|
Packit |
00408a |
return NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* VARIABLES PROTECTED BY rpcbaddr_cache_lock: ad_cache */
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* Get the address of the rpcbind. Check cache first */
|
|
Packit |
00408a |
client = NULL;
|
|
Packit |
00408a |
if (targaddr)
|
|
Packit |
00408a |
*targaddr = NULL;
|
|
Packit |
00408a |
addr_to_delete.len = 0;
|
|
Packit |
00408a |
rwlock_rdlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
ad_cache = NULL;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (host != NULL)
|
|
Packit |
00408a |
ad_cache = check_cache(host, nconf->nc_netid);
|
|
Packit |
00408a |
if (ad_cache != NULL) {
|
|
Packit |
00408a |
addr = ad_cache->ac_taddr;
|
|
Packit |
00408a |
client = clnt_tli_create(RPC_ANYFD, nconf, addr,
|
|
Packit |
00408a |
(rpcprog_t)RPCBPROG, (rpcvers_t)RPCBVERS4, 0, 0);
|
|
Packit |
00408a |
if (client != NULL) {
|
|
Packit |
00408a |
if (targaddr && ad_cache->ac_uaddr)
|
|
Packit |
00408a |
*targaddr = strdup(ad_cache->ac_uaddr);
|
|
Packit |
00408a |
rwlock_unlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
return (client);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
addr_to_delete.len = addr->len;
|
|
Packit |
00408a |
addr_to_delete.buf = (char *)malloc(addr->len);
|
|
Packit |
00408a |
if (addr_to_delete.buf == NULL) {
|
|
Packit |
00408a |
addr_to_delete.len = 0;
|
|
Packit |
00408a |
} else {
|
|
Packit |
00408a |
memcpy(addr_to_delete.buf, addr->buf, addr->len);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
rwlock_unlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
if (addr_to_delete.len != 0) {
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Assume this may be due to cache data being
|
|
Packit |
00408a |
* outdated
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
rwlock_wrlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
delete_cache(&addr_to_delete);
|
|
Packit |
00408a |
rwlock_unlock(&rpcbaddr_cache_lock);
|
|
Packit |
00408a |
free(addr_to_delete.buf);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (!__rpc_nconf2sockinfo(nconf, &si)) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
assert(client == NULL);
|
|
Packit |
00408a |
goto out_err;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
memset(&hints, 0, sizeof hints);
|
|
Packit |
00408a |
hints.ai_family = si.si_af;
|
|
Packit |
00408a |
hints.ai_socktype = si.si_socktype;
|
|
Packit |
00408a |
hints.ai_protocol = si.si_proto;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(3, ("getclnthandle: trying netid %s family %d proto %d socktype %d\n",
|
|
Packit |
00408a |
nconf->nc_netid, si.si_af, si.si_proto, si.si_socktype));
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (nconf->nc_protofmly != NULL && strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) {
|
|
Packit |
00408a |
client = local_rpcb();
|
|
Packit |
00408a |
if (! client) {
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(1, ("getclnthandle: %s",
|
|
Packit |
00408a |
clnt_spcreateerror("local_rpcb failed")));
|
|
Packit |
00408a |
goto out_err;
|
|
Packit |
00408a |
} else {
|
|
Packit |
00408a |
struct sockaddr_un sun;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (targaddr) {
|
|
Packit |
00408a |
*targaddr = malloc(sizeof(sun.sun_path));
|
|
Packit |
00408a |
strncpy(*targaddr, _PATH_RPCBINDSOCK,
|
|
Packit |
00408a |
sizeof(sun.sun_path));
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
return (client);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
} else {
|
|
Packit |
00408a |
if (getaddrinfo(host, "sunrpc", &hints, &res) != 0) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
|
|
Packit |
00408a |
assert(client == NULL);
|
|
Packit |
00408a |
goto out_err;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
for (tres = res; tres != NULL; tres = tres->ai_next) {
|
|
Packit |
00408a |
taddr.buf = tres->ai_addr;
|
|
Packit |
00408a |
taddr.len = taddr.maxlen = tres->ai_addrlen;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (libtirpc_debug_level > 3 && log_stderr) {
|
|
Packit |
00408a |
char *ua;
|
|
Packit |
00408a |
int i;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
ua = taddr2uaddr(nconf, &taddr);
|
|
Packit |
00408a |
fprintf(stderr, "Got it [%s]\n", ua);
|
|
Packit |
00408a |
free(ua);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
fprintf(stderr, "\tnetbuf len = %d, maxlen = %d\n",
|
|
Packit |
00408a |
taddr.len, taddr.maxlen);
|
|
Packit |
00408a |
fprintf(stderr, "\tAddress is ");
|
|
Packit |
00408a |
for (i = 0; i < taddr.len; i++)
|
|
Packit |
00408a |
fprintf(stderr, "%u.", ((char *)(taddr.buf))[i]);
|
|
Packit |
00408a |
fprintf(stderr, "\n");
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
client = clnt_tli_create(RPC_ANYFD, nconf, &taddr,
|
|
Packit |
00408a |
(rpcprog_t)RPCBPROG, (rpcvers_t)RPCBVERS4, 0, 0);
|
|
Packit |
00408a |
if (! client) {
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(1, ("getclnthandle: %s",
|
|
Packit |
00408a |
clnt_spcreateerror("clnt_tli_create failed")));
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (client) {
|
|
Packit |
00408a |
tmpaddr = targaddr ? taddr2uaddr(nconf, &taddr) : NULL;
|
|
Packit |
00408a |
if (host)
|
|
Packit |
00408a |
add_cache(host, nconf->nc_netid, &taddr, tmpaddr);
|
|
Packit |
00408a |
if (targaddr)
|
|
Packit |
00408a |
*targaddr = tmpaddr;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (res)
|
|
Packit |
00408a |
freeaddrinfo(res);
|
|
Packit |
00408a |
out_err:
|
|
Packit |
00408a |
if (!client && targaddr)
|
|
Packit |
00408a |
free(*targaddr);
|
|
Packit |
00408a |
return (client);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Create a PMAP client handle.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
static CLIENT *
|
|
Packit |
00408a |
getpmaphandle(nconf, hostname, tgtaddr)
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
const char *hostname;
|
|
Packit |
00408a |
char **tgtaddr;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client = NULL;
|
|
Packit |
00408a |
rpcvers_t pmapvers = 2;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Try UDP only - there are some portmappers out
|
|
Packit |
00408a |
* there that use UDP only.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
if (nconf == NULL || strcmp(nconf->nc_proto, NC_TCP) == 0) {
|
|
Packit |
00408a |
struct netconfig *newnconf;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((newnconf = getnetconfigent("udp")) == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
client = getclnthandle(hostname, newnconf, tgtaddr);
|
|
Packit |
00408a |
freenetconfigent(newnconf);
|
|
Packit |
00408a |
} else if (strcmp(nconf->nc_proto, NC_UDP) == 0) {
|
|
Packit |
00408a |
if (strcmp(nconf->nc_protofmly, NC_INET) != 0)
|
|
Packit |
00408a |
return NULL;
|
|
Packit |
00408a |
client = getclnthandle(hostname, nconf, tgtaddr);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* Set version */
|
|
Packit |
00408a |
if (client != NULL)
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_VERS, (char *)&pmapvers);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
return client;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* XXX */
|
|
Packit |
00408a |
#define IN4_LOCALHOST_STRING "127.0.0.1"
|
|
Packit |
00408a |
#define IN6_LOCALHOST_STRING "::1"
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* This routine will return a client handle that is connected to the local
|
|
Packit |
00408a |
* rpcbind. Returns NULL on error and free's everything.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
static CLIENT *
|
|
Packit |
00408a |
local_rpcb()
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
static struct netconfig *loopnconf;
|
|
Packit |
00408a |
static char *hostname;
|
|
Packit |
00408a |
extern mutex_t loopnconf_lock;
|
|
Packit |
00408a |
int sock;
|
|
Packit |
00408a |
size_t tsize;
|
|
Packit |
00408a |
struct netbuf nbuf;
|
|
Packit |
00408a |
struct sockaddr_un sun;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Try connecting to the local rpcbind through a local socket
|
|
Packit |
00408a |
* first. If this doesn't work, try all transports defined in
|
|
Packit |
00408a |
* the netconfig file.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
memset(&sun, 0, sizeof sun);
|
|
Packit |
00408a |
sock = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
Packit |
00408a |
if (sock < 0)
|
|
Packit |
00408a |
goto try_nconf;
|
|
Packit |
00408a |
sun.sun_family = AF_LOCAL;
|
|
Packit |
00408a |
strcpy(sun.sun_path, _PATH_RPCBINDSOCK);
|
|
Packit |
00408a |
nbuf.len = SUN_LEN(&sun);
|
|
Packit |
00408a |
nbuf.maxlen = sizeof (struct sockaddr_un);
|
|
Packit |
00408a |
nbuf.buf = &sun;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
tsize = __rpc_get_t_size(AF_LOCAL, 0, 0);
|
|
Packit |
00408a |
client = clnt_vc_create(sock, &nbuf, (rpcprog_t)RPCBPROG,
|
|
Packit |
00408a |
(rpcvers_t)RPCBVERS, tsize, tsize);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (client != NULL) {
|
|
Packit |
00408a |
/* Mark the socket to be closed in destructor */
|
|
Packit |
00408a |
(void) CLNT_CONTROL(client, CLSET_FD_CLOSE, NULL);
|
|
Packit |
00408a |
return client;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* Nobody needs this socket anymore; free the descriptor. */
|
|
Packit |
00408a |
close(sock);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
try_nconf:
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* VARIABLES PROTECTED BY loopnconf_lock: loopnconf */
|
|
Packit |
00408a |
mutex_lock(&loopnconf_lock);
|
|
Packit |
00408a |
if (loopnconf == NULL) {
|
|
Packit |
00408a |
struct netconfig *nconf, *tmpnconf = NULL;
|
|
Packit |
00408a |
void *nc_handle;
|
|
Packit |
00408a |
int fd;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
nc_handle = setnetconfig();
|
|
Packit |
00408a |
if (nc_handle == NULL) {
|
|
Packit |
00408a |
/* fails to open netconfig file */
|
|
Packit |
00408a |
syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
mutex_unlock(&loopnconf_lock);
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
while ((nconf = getnetconfig(nc_handle)) != NULL) {
|
|
Packit |
00408a |
#ifdef INET6
|
|
Packit |
00408a |
if ((strcmp(nconf->nc_protofmly, NC_INET6) == 0 ||
|
|
Packit |
00408a |
#else
|
|
Packit |
00408a |
if ((
|
|
Packit |
00408a |
#endif
|
|
Packit |
00408a |
strcmp(nconf->nc_protofmly, NC_INET) == 0) &&
|
|
Packit |
00408a |
(nconf->nc_semantics == NC_TPI_COTS ||
|
|
Packit |
00408a |
nconf->nc_semantics == NC_TPI_COTS_ORD)) {
|
|
Packit |
00408a |
fd = __rpc_nconf2fd(nconf);
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Can't create a socket, assume that
|
|
Packit |
00408a |
* this family isn't configured in the kernel.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
if (fd < 0)
|
|
Packit |
00408a |
continue;
|
|
Packit |
00408a |
close(fd);
|
|
Packit |
00408a |
tmpnconf = nconf;
|
|
Packit |
00408a |
if (!strcmp(nconf->nc_protofmly, NC_INET))
|
|
Packit |
00408a |
hostname = IN4_LOCALHOST_STRING;
|
|
Packit |
00408a |
else
|
|
Packit |
00408a |
hostname = IN6_LOCALHOST_STRING;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (tmpnconf == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
mutex_unlock(&loopnconf_lock);
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
loopnconf = getnetconfigent(tmpnconf->nc_netid);
|
|
Packit |
00408a |
/* loopnconf is never freed */
|
|
Packit |
00408a |
endnetconfig(nc_handle);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
mutex_unlock(&loopnconf_lock);
|
|
Packit |
00408a |
client = getclnthandle(hostname, loopnconf, NULL);
|
|
Packit |
00408a |
return (client);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Set a mapping between program, version and address.
|
|
Packit |
00408a |
* Calls the rpcbind service to do the mapping.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
bool_t
|
|
Packit |
00408a |
rpcb_set(program, version, nconf, address)
|
|
Packit |
00408a |
rpcprog_t program;
|
|
Packit |
00408a |
rpcvers_t version;
|
|
Packit |
00408a |
const struct netconfig *nconf; /* Network structure of transport */
|
|
Packit |
00408a |
const struct netbuf *address; /* Services netconfig address */
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
bool_t rslt = FALSE;
|
|
Packit |
00408a |
RPCB parms;
|
|
Packit |
00408a |
char uidbuf[32];
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* parameter checking */
|
|
Packit |
00408a |
if (nconf == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (address == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
client = local_rpcb();
|
|
Packit |
00408a |
if (! client) {
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* convert to universal */
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
parms.r_addr = taddr2uaddr((struct netconfig *) nconf,
|
|
Packit |
00408a |
(struct netbuf *)address);
|
|
Packit |
00408a |
if (!parms.r_addr) {
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE;
|
|
Packit |
00408a |
return (FALSE); /* no universal address */
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
parms.r_prog = program;
|
|
Packit |
00408a |
parms.r_vers = version;
|
|
Packit |
00408a |
parms.r_netid = nconf->nc_netid;
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Though uid is not being used directly, we still send it for
|
|
Packit |
00408a |
* completeness. For non-unix platforms, perhaps some other
|
|
Packit |
00408a |
* string or an empty string can be sent.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
(void) snprintf(uidbuf, sizeof uidbuf, "%d", geteuid());
|
|
Packit |
00408a |
parms.r_owner = uidbuf;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_CALL(client, (rpcproc_t)RPCBPROC_SET, (xdrproc_t) xdr_rpcb,
|
|
Packit |
00408a |
(char *)&parms, (xdrproc_t) xdr_bool,
|
|
Packit |
00408a |
(char *)&rslt, tottimeout);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
free(parms.r_addr);
|
|
Packit |
00408a |
return (rslt);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Remove the mapping between program, version and netbuf address.
|
|
Packit |
00408a |
* Calls the rpcbind service to do the un-mapping.
|
|
Packit |
00408a |
* If netbuf is NULL, unset for all the transports, otherwise unset
|
|
Packit |
00408a |
* only for the given transport.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
bool_t
|
|
Packit |
00408a |
rpcb_unset(program, version, nconf)
|
|
Packit |
00408a |
rpcprog_t program;
|
|
Packit |
00408a |
rpcvers_t version;
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
bool_t rslt = FALSE;
|
|
Packit |
00408a |
RPCB parms;
|
|
Packit |
00408a |
char uidbuf[32];
|
|
Packit |
00408a |
|
|
Packit |
00408a |
client = local_rpcb();
|
|
Packit |
00408a |
if (! client) {
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
parms.r_prog = program;
|
|
Packit |
00408a |
parms.r_vers = version;
|
|
Packit |
00408a |
if (nconf)
|
|
Packit |
00408a |
parms.r_netid = nconf->nc_netid;
|
|
Packit |
00408a |
else {
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
parms.r_netid = (char *) &nullstring[0]; /* unsets all */
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
parms.r_addr = (char *) &nullstring[0];
|
|
Packit |
00408a |
(void) snprintf(uidbuf, sizeof uidbuf, "%d", geteuid());
|
|
Packit |
00408a |
parms.r_owner = uidbuf;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_CALL(client, (rpcproc_t)RPCBPROC_UNSET, (xdrproc_t) xdr_rpcb,
|
|
Packit |
00408a |
(char *)(void *)&parms, (xdrproc_t) xdr_bool,
|
|
Packit |
00408a |
(char *)(void *)&rslt, tottimeout);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return (rslt);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#ifdef NOTUSED
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* From the merged list, find the appropriate entry
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
static struct netbuf *
|
|
Packit |
00408a |
got_entry(relp, nconf)
|
|
Packit |
00408a |
rpcb_entry_list_ptr relp;
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
struct netbuf *na = NULL;
|
|
Packit |
00408a |
rpcb_entry_list_ptr sp;
|
|
Packit |
00408a |
rpcb_entry *rmap;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
for (sp = relp; sp != NULL; sp = sp->rpcb_entry_next) {
|
|
Packit |
00408a |
rmap = &sp->rpcb_entry_map;
|
|
Packit |
00408a |
if ((strcmp(nconf->nc_proto, rmap->r_nc_proto) == 0) &&
|
|
Packit |
00408a |
(strcmp(nconf->nc_protofmly, rmap->r_nc_protofmly) == 0) &&
|
|
Packit |
00408a |
(nconf->nc_semantics == rmap->r_nc_semantics) &&
|
|
Packit |
00408a |
(rmap->r_maddr != NULL) && (rmap->r_maddr[0] != 0)) {
|
|
Packit |
00408a |
na = uaddr2taddr(nconf, rmap->r_maddr);
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(3, ("got_entry: Remote address is [%s] %s",
|
|
Packit |
00408a |
rmap->r_maddr, (na ? "Resolvable" : "Not Resolvable")));
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
return (na);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Quick check to see if rpcbind is up. Tries to connect over
|
|
Packit |
00408a |
* local transport.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
bool_t
|
|
Packit |
00408a |
__rpcbind_is_up()
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
struct netconfig *nconf;
|
|
Packit |
00408a |
struct sockaddr_un sun;
|
|
Packit |
00408a |
void *localhandle;
|
|
Packit |
00408a |
int sock;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
nconf = NULL;
|
|
Packit |
00408a |
localhandle = setnetconfig();
|
|
Packit |
00408a |
while ((nconf = getnetconfig(localhandle)) != NULL) {
|
|
Packit |
00408a |
if (nconf->nc_protofmly != NULL &&
|
|
Packit |
00408a |
strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0)
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (nconf == NULL)
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
endnetconfig(localhandle);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
memset(&sun, 0, sizeof sun);
|
|
Packit |
00408a |
sock = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
Packit |
00408a |
if (sock < 0)
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
sun.sun_family = AF_LOCAL;
|
|
Packit |
00408a |
strncpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
|
|
Packit |
00408a |
close(sock);
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
close(sock);
|
|
Packit |
00408a |
return (TRUE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
#endif
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#ifdef PORTMAP
|
|
Packit |
00408a |
static struct netbuf *
|
|
Packit |
00408a |
__try_protocol_version_2(program, version, nconf, host, tp)
|
|
Packit |
00408a |
rpcprog_t program;
|
|
Packit |
00408a |
rpcvers_t version;
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
const char *host;
|
|
Packit |
00408a |
struct timeval *tp;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
u_short port = 0;
|
|
Packit |
00408a |
struct netbuf remote;
|
|
Packit |
00408a |
struct pmap pmapparms;
|
|
Packit |
00408a |
CLIENT *client = NULL;
|
|
Packit |
00408a |
enum clnt_stat clnt_st;
|
|
Packit |
00408a |
struct netbuf *pmapaddress;
|
|
Packit |
00408a |
RPCB parms;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (strcmp(nconf->nc_proto, NC_UDP) != 0
|
|
Packit |
00408a |
&& strcmp(nconf->nc_proto, NC_TCP) != 0)
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
client = getpmaphandle(nconf, host, &parms.r_addr);
|
|
Packit |
00408a |
if (client == NULL)
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Set retry timeout.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)&rpcbrmttime);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
pmapparms.pm_prog = program;
|
|
Packit |
00408a |
pmapparms.pm_vers = version;
|
|
Packit |
00408a |
pmapparms.pm_prot = strcmp(nconf->nc_proto, NC_TCP) ?
|
|
Packit |
00408a |
IPPROTO_UDP : IPPROTO_TCP;
|
|
Packit |
00408a |
pmapparms.pm_port = 0; /* not needed */
|
|
Packit |
00408a |
clnt_st = CLNT_CALL(client, (rpcproc_t)PMAPPROC_GETPORT,
|
|
Packit |
00408a |
(xdrproc_t) xdr_pmap, (caddr_t)(void *)&pmapparms,
|
|
Packit |
00408a |
(xdrproc_t) xdr_u_short, (caddr_t)(void *)&port,
|
|
Packit |
00408a |
*tp);
|
|
Packit |
00408a |
if (clnt_st != RPC_SUCCESS) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_PMAPFAILURE;
|
|
Packit |
00408a |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
} else if (port == 0) {
|
|
Packit |
00408a |
pmapaddress = NULL;
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
port = htons(port);
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLGET_SVC_ADDR, (char *)&remote);
|
|
Packit |
00408a |
if (((pmapaddress = (struct netbuf *)
|
|
Packit |
00408a |
malloc(sizeof (struct netbuf))) == NULL) ||
|
|
Packit |
00408a |
((pmapaddress->buf = (char *)
|
|
Packit |
00408a |
malloc(remote.len)) == NULL)) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
|
Packit |
00408a |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
00408a |
if (pmapaddress) {
|
|
Packit |
00408a |
free(pmapaddress);
|
|
Packit |
00408a |
pmapaddress = NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
memcpy(pmapaddress->buf, remote.buf, remote.len);
|
|
Packit |
00408a |
memcpy(&((char *)pmapaddress->buf)[sizeof (short)],
|
|
Packit |
00408a |
(char *)(void *)&port, sizeof (short));
|
|
Packit |
00408a |
pmapaddress->len = pmapaddress->maxlen = remote.len;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return pmapaddress;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
error:
|
|
Packit |
00408a |
if (client) {
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
client = NULL;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
#endif
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* An internal function which optimizes rpcb_getaddr function. It also
|
|
Packit |
00408a |
* returns the client handle that it uses to contact the remote rpcbind.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* The algorithm used: If the transports is TCP or UDP, it first tries
|
|
Packit |
00408a |
* version 4 (srv4), then 3 and then fall back to version 2 (portmap).
|
|
Packit |
00408a |
* With this algorithm, we get performance as well as a plan for
|
|
Packit |
00408a |
* obsoleting version 2.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* For all other transports, the algorithm remains as 4 and then 3.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* XXX: Due to some problems with t_connect(), we do not reuse the same client
|
|
Packit |
00408a |
* handle for COTS cases and hence in these cases we do not return the
|
|
Packit |
00408a |
* client handle. This code will change if t_connect() ever
|
|
Packit |
00408a |
* starts working properly. Also look under clnt_vc.c.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
struct netbuf *
|
|
Packit |
00408a |
__rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
|
|
Packit |
00408a |
rpcprog_t program;
|
|
Packit |
00408a |
rpcvers_t version;
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
const char *host;
|
|
Packit |
00408a |
CLIENT **clpp;
|
|
Packit |
00408a |
struct timeval *tp;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
#ifdef NOTUSED
|
|
Packit |
00408a |
static bool_t check_rpcbind = TRUE;
|
|
Packit |
00408a |
#endif
|
|
Packit |
00408a |
CLIENT *client = NULL;
|
|
Packit |
00408a |
RPCB parms;
|
|
Packit |
00408a |
enum clnt_stat clnt_st;
|
|
Packit |
00408a |
char *ua = NULL;
|
|
Packit |
00408a |
rpcvers_t vers;
|
|
Packit |
00408a |
struct netbuf *address = NULL;
|
|
Packit |
00408a |
rpcvers_t start_vers = RPCBVERS4;
|
|
Packit |
00408a |
struct netbuf servaddr;
|
|
Packit |
00408a |
struct rpc_err rpcerr;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* parameter checking */
|
|
Packit |
00408a |
if (nconf == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
parms.r_addr = NULL;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Use default total timeout if no timeout is specified.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
if (tp == NULL)
|
|
Packit |
00408a |
tp = &tottimeout;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
parms.r_prog = program;
|
|
Packit |
00408a |
parms.r_vers = version;
|
|
Packit |
00408a |
parms.r_netid = nconf->nc_netid;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* rpcbind ignores the r_owner field in GETADDR requests, but we
|
|
Packit |
00408a |
* need to give xdr_rpcb something to gnaw on. Might as well make
|
|
Packit |
00408a |
* it something human readable for when we see these in captures.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
parms.r_owner = RPCB_OWNER_STRING;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* Now the same transport is to be used to get the address */
|
|
Packit |
00408a |
if (client && ((nconf->nc_semantics == NC_TPI_COTS_ORD) ||
|
|
Packit |
00408a |
(nconf->nc_semantics == NC_TPI_COTS))) {
|
|
Packit |
00408a |
/* A CLTS type of client - destroy it */
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
client = NULL;
|
|
Packit |
00408a |
free(parms.r_addr);
|
|
Packit |
00408a |
parms.r_addr = NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (client == NULL) {
|
|
Packit |
00408a |
client = getclnthandle(host, nconf, &parms.r_addr);
|
|
Packit |
00408a |
if (client == NULL) {
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (parms.r_addr == NULL) {
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
parms.r_addr = (char *) &nullstring[0];
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* First try from start_vers(4) and then version 3 (RPCBVERS) */
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *) &rpcbrmttime);
|
|
Packit |
00408a |
for (vers = start_vers; vers >= RPCBVERS; vers--) {
|
|
Packit |
00408a |
/* Set the version */
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_VERS, (char *)(void *)&vers;;
|
|
Packit |
00408a |
clnt_st = CLNT_CALL(client, (rpcproc_t)RPCBPROC_GETADDR,
|
|
Packit |
00408a |
(xdrproc_t) xdr_rpcb, (char *)(void *)&parms,
|
|
Packit |
00408a |
(xdrproc_t) xdr_wrapstring, (char *)(void *) &ua, *tp);
|
|
Packit |
00408a |
switch (clnt_st) {
|
|
Packit |
00408a |
case RPC_SUCCESS:
|
|
Packit |
00408a |
if ((ua == NULL) || (ua[0] == 0)) {
|
|
Packit |
00408a |
/* address unknown */
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
address = uaddr2taddr(nconf, ua);
|
|
Packit |
00408a |
LIBTIRPC_DEBUG(3, ("__rpcb_findaddr_timed: Remote address is [%s] %s",
|
|
Packit |
00408a |
ua, (address ? "Resolvable" : "Not Resolvable")));
|
|
Packit |
00408a |
|
|
Packit |
00408a |
xdr_free((xdrproc_t)xdr_wrapstring,
|
|
Packit |
00408a |
(char *)(void *)&ua);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (! address) {
|
|
Packit |
00408a |
/* We don't know about your universal address */
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE;
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLGET_SVC_ADDR,
|
|
Packit |
00408a |
(char *)(void *)&servaddr);
|
|
Packit |
00408a |
__rpc_fixup_addr(address, &servaddr);
|
|
Packit |
00408a |
goto done;
|
|
Packit |
00408a |
case RPC_PROGVERSMISMATCH:
|
|
Packit |
00408a |
clnt_geterr(client, &rpcerr);
|
|
Packit |
00408a |
if (rpcerr.re_vers.low > RPCBVERS4)
|
|
Packit |
00408a |
goto error; /* a new version, can't handle */
|
|
Packit |
00408a |
/* Try the next lower version */
|
|
Packit |
00408a |
case RPC_PROGUNAVAIL:
|
|
Packit |
00408a |
case RPC_CANTDECODEARGS:
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
default:
|
|
Packit |
00408a |
/* Cant handle this error */
|
|
Packit |
00408a |
rpc_createerr.cf_stat = clnt_st;
|
|
Packit |
00408a |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
#ifdef PORTMAP /* Try version 2 for TCP or UDP */
|
|
Packit |
00408a |
if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
|
|
Packit |
00408a |
address = __try_protocol_version_2(program, version, nconf, host, tp);
|
|
Packit |
00408a |
if (address == NULL)
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
#endif /* PORTMAP */
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((address == NULL) || (address->len == 0)) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
|
|
Packit |
00408a |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
error:
|
|
Packit |
00408a |
if (client) {
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
client = NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
done:
|
|
Packit |
00408a |
if (nconf->nc_semantics != NC_TPI_CLTS) {
|
|
Packit |
00408a |
/* This client is the connectionless one */
|
|
Packit |
00408a |
if (client) {
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
client = NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (clpp) {
|
|
Packit |
00408a |
*clpp = client;
|
|
Packit |
00408a |
} else if (client) {
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (parms.r_addr != NULL && parms.r_addr != nullstring)
|
|
Packit |
00408a |
free(parms.r_addr);
|
|
Packit |
00408a |
return (address);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Find the mapped address for program, version.
|
|
Packit |
00408a |
* Calls the rpcbind service remotely to do the lookup.
|
|
Packit |
00408a |
* Uses the transport specified in nconf.
|
|
Packit |
00408a |
* Returns FALSE (0) if no map exists, else returns 1.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* Assuming that the address is all properly allocated
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
int
|
|
Packit |
00408a |
rpcb_getaddr(program, version, nconf, address, host)
|
|
Packit |
00408a |
rpcprog_t program;
|
|
Packit |
00408a |
rpcvers_t version;
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
struct netbuf *address;
|
|
Packit |
00408a |
const char *host;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
struct netbuf *na;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((na = __rpcb_findaddr_timed(program, version,
|
|
Packit |
00408a |
(struct netconfig *) nconf, (char *) host,
|
|
Packit |
00408a |
(CLIENT **) NULL, (struct timeval *) NULL)) == NULL)
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if (na->len > address->maxlen) {
|
|
Packit |
00408a |
/* Too long address */
|
|
Packit |
00408a |
free(na->buf);
|
|
Packit |
00408a |
free(na);
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_FAILED;
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
memcpy(address->buf, na->buf, (size_t)na->len);
|
|
Packit |
00408a |
address->len = na->len;
|
|
Packit |
00408a |
free(na->buf);
|
|
Packit |
00408a |
free(na);
|
|
Packit |
00408a |
return (TRUE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Get a copy of the current maps.
|
|
Packit |
00408a |
* Calls the rpcbind service remotely to get the maps.
|
|
Packit |
00408a |
*
|
|
Packit |
00408a |
* It returns only a list of the services
|
|
Packit |
00408a |
* It returns NULL on failure.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
rpcblist *
|
|
Packit |
00408a |
rpcb_getmaps(nconf, host)
|
|
Packit |
00408a |
const struct netconfig *nconf;
|
|
Packit |
00408a |
const char *host;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
rpcblist_ptr head = NULL;
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
enum clnt_stat clnt_st;
|
|
Packit |
00408a |
rpcvers_t vers = 0;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
client = getclnthandle(host, nconf, NULL);
|
|
Packit |
00408a |
if (client == NULL) {
|
|
Packit |
00408a |
return (head);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
clnt_st = CLNT_CALL(client, (rpcproc_t)RPCBPROC_DUMP,
|
|
Packit |
00408a |
(xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_rpcblist_ptr,
|
|
Packit |
00408a |
(char *)(void *)&head, tottimeout);
|
|
Packit |
00408a |
if (clnt_st == RPC_SUCCESS)
|
|
Packit |
00408a |
goto done;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((clnt_st != RPC_PROGVERSMISMATCH) &&
|
|
Packit |
00408a |
(clnt_st != RPC_PROGUNAVAIL)) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_RPCBFAILURE;
|
|
Packit |
00408a |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
00408a |
goto done;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* fall back to earlier version */
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLGET_VERS, (char *)(void *)&vers;;
|
|
Packit |
00408a |
if (vers == RPCBVERS4) {
|
|
Packit |
00408a |
vers = RPCBVERS;
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_VERS, (char *)(void *)&vers;;
|
|
Packit |
00408a |
if (CLNT_CALL(client, (rpcproc_t)RPCBPROC_DUMP,
|
|
Packit |
00408a |
(xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_rpcblist_ptr,
|
|
Packit |
00408a |
(char *)(void *)&head, tottimeout) == RPC_SUCCESS)
|
|
Packit |
00408a |
goto done;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_RPCBFAILURE;
|
|
Packit |
00408a |
clnt_geterr(client, &rpc_createerr.cf_error);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
done:
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return (head);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* rpcbinder remote-call-service interface.
|
|
Packit |
00408a |
* This routine is used to call the rpcbind remote call service
|
|
Packit |
00408a |
* which will look up a service program in the address maps, and then
|
|
Packit |
00408a |
* remotely call that routine with the given parameters. This allows
|
|
Packit |
00408a |
* programs to do a lookup and call in one step.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
enum clnt_stat
|
|
Packit |
00408a |
rpcb_rmtcall(nconf, host, prog, vers, proc, xdrargs, argsp,
|
|
Packit |
00408a |
xdrres, resp, tout, addr_ptr)
|
|
Packit |
00408a |
const struct netconfig *nconf; /* Netconfig structure */
|
|
Packit |
00408a |
const char *host; /* Remote host name */
|
|
Packit |
00408a |
rpcprog_t prog;
|
|
Packit |
00408a |
rpcvers_t vers;
|
|
Packit |
00408a |
rpcproc_t proc; /* Remote proc identifiers */
|
|
Packit |
00408a |
xdrproc_t xdrargs, xdrres; /* XDR routines */
|
|
Packit |
00408a |
caddr_t argsp, resp; /* Argument and Result */
|
|
Packit |
00408a |
struct timeval tout; /* Timeout value for this call */
|
|
Packit |
00408a |
const struct netbuf *addr_ptr; /* Preallocated netbuf address */
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
enum clnt_stat stat;
|
|
Packit |
00408a |
struct r_rpcb_rmtcallargs a;
|
|
Packit |
00408a |
struct r_rpcb_rmtcallres r;
|
|
Packit |
00408a |
rpcvers_t rpcb_vers;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
stat = 0;
|
|
Packit |
00408a |
client = getclnthandle(host, nconf, NULL);
|
|
Packit |
00408a |
if (client == NULL) {
|
|
Packit |
00408a |
return (RPC_FAILED);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)(void *)&rmttimeout);
|
|
Packit |
00408a |
a.prog = prog;
|
|
Packit |
00408a |
a.vers = vers;
|
|
Packit |
00408a |
a.proc = proc;
|
|
Packit |
00408a |
a.args.args_val = argsp;
|
|
Packit |
00408a |
a.xdr_args = xdrargs;
|
|
Packit |
00408a |
r.addr = NULL;
|
|
Packit |
00408a |
r.results.results_val = resp;
|
|
Packit |
00408a |
r.xdr_res = xdrres;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
for (rpcb_vers = RPCBVERS4; rpcb_vers >= RPCBVERS; rpcb_vers--) {
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_VERS, (char *)(void *)&rpcb_vers);
|
|
Packit |
00408a |
stat = CLNT_CALL(client, (rpcproc_t)RPCBPROC_CALLIT,
|
|
Packit |
00408a |
(xdrproc_t) xdr_rpcb_rmtcallargs, (char *)(void *)&a,
|
|
Packit |
00408a |
(xdrproc_t) xdr_rpcb_rmtcallres, (char *)(void *)&r, tout);
|
|
Packit |
00408a |
if ((stat == RPC_SUCCESS) && (addr_ptr != NULL)) {
|
|
Packit |
00408a |
struct netbuf *na;
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
na = uaddr2taddr((struct netconfig *) nconf, r.addr);
|
|
Packit |
00408a |
if (!na) {
|
|
Packit |
00408a |
stat = RPC_N2AXLATEFAILURE;
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
((struct netbuf *) addr_ptr)->len = 0;
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (na->len > addr_ptr->maxlen) {
|
|
Packit |
00408a |
/* Too long address */
|
|
Packit |
00408a |
stat = RPC_FAILED; /* XXX A better error no */
|
|
Packit |
00408a |
free(na->buf);
|
|
Packit |
00408a |
free(na);
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
((struct netbuf *) addr_ptr)->len = 0;
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
memcpy(addr_ptr->buf, na->buf, (size_t)na->len);
|
|
Packit |
00408a |
/*LINTED const castaway*/
|
|
Packit |
00408a |
((struct netbuf *)addr_ptr)->len = na->len;
|
|
Packit |
00408a |
free(na->buf);
|
|
Packit |
00408a |
free(na);
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
} else if ((stat != RPC_PROGVERSMISMATCH) &&
|
|
Packit |
00408a |
(stat != RPC_PROGUNAVAIL)) {
|
|
Packit |
00408a |
goto error;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
error:
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
if (r.addr)
|
|
Packit |
00408a |
xdr_free((xdrproc_t) xdr_wrapstring, (char *)(void *)&r.addr);
|
|
Packit |
00408a |
return (stat);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Gets the time on the remote host.
|
|
Packit |
00408a |
* Returns 1 if succeeds else 0.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
bool_t
|
|
Packit |
00408a |
rpcb_gettime(host, timep)
|
|
Packit |
00408a |
const char *host;
|
|
Packit |
00408a |
time_t *timep;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client = NULL;
|
|
Packit |
00408a |
void *handle;
|
|
Packit |
00408a |
struct netconfig *nconf;
|
|
Packit |
00408a |
rpcvers_t vers;
|
|
Packit |
00408a |
enum clnt_stat st;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((host == NULL) || (host[0] == 0)) {
|
|
Packit |
00408a |
time(timep);
|
|
Packit |
00408a |
return (TRUE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((handle = __rpc_setconf("netpath")) == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_SUCCESS;
|
|
Packit |
00408a |
while (client == NULL) {
|
|
Packit |
00408a |
if ((nconf = __rpc_getconf(handle)) == NULL) {
|
|
Packit |
00408a |
if (rpc_createerr.cf_stat == RPC_SUCCESS)
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
client = getclnthandle(host, nconf, NULL);
|
|
Packit |
00408a |
if (client)
|
|
Packit |
00408a |
break;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
__rpc_endconf(handle);
|
|
Packit |
00408a |
if (client == (CLIENT *) NULL) {
|
|
Packit |
00408a |
return (FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
st = CLNT_CALL(client, (rpcproc_t)RPCBPROC_GETTIME,
|
|
Packit |
00408a |
(xdrproc_t) xdr_void, NULL,
|
|
Packit |
00408a |
(xdrproc_t) xdr_int, (char *)(void *)timep, tottimeout);
|
|
Packit |
00408a |
|
|
Packit |
00408a |
if ((st == RPC_PROGVERSMISMATCH) || (st == RPC_PROGUNAVAIL)) {
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLGET_VERS, (char *)(void *)&vers;;
|
|
Packit |
00408a |
if (vers == RPCBVERS4) {
|
|
Packit |
00408a |
/* fall back to earlier version */
|
|
Packit |
00408a |
vers = RPCBVERS;
|
|
Packit |
00408a |
CLNT_CONTROL(client, CLSET_VERS, (char *)(void *)&vers;;
|
|
Packit |
00408a |
st = CLNT_CALL(client, (rpcproc_t)RPCBPROC_GETTIME,
|
|
Packit |
00408a |
(xdrproc_t) xdr_void, NULL,
|
|
Packit |
00408a |
(xdrproc_t) xdr_int, (char *)(void *)timep,
|
|
Packit |
00408a |
tottimeout);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return (st == RPC_SUCCESS? TRUE: FALSE);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Converts taddr to universal address. This routine should never
|
|
Packit |
00408a |
* really be called because local n2a libraries are always provided.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
char *
|
|
Packit |
00408a |
rpcb_taddr2uaddr(nconf, taddr)
|
|
Packit |
00408a |
struct netconfig *nconf;
|
|
Packit |
00408a |
struct netbuf *taddr;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
char *uaddr = NULL;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* parameter checking */
|
|
Packit |
00408a |
if (nconf == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (taddr == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
client = local_rpcb();
|
|
Packit |
00408a |
if (! client) {
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
CLNT_CALL(client, (rpcproc_t)RPCBPROC_TADDR2UADDR,
|
|
Packit |
00408a |
(xdrproc_t) xdr_netbuf, (char *)(void *)taddr,
|
|
Packit |
00408a |
(xdrproc_t) xdr_wrapstring, (char *)(void *)&uaddr, tottimeout);
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return (uaddr);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/*
|
|
Packit |
00408a |
* Converts universal address to netbuf. This routine should never
|
|
Packit |
00408a |
* really be called because local n2a libraries are always provided.
|
|
Packit |
00408a |
*/
|
|
Packit |
00408a |
struct netbuf *
|
|
Packit |
00408a |
rpcb_uaddr2taddr(nconf, uaddr)
|
|
Packit |
00408a |
struct netconfig *nconf;
|
|
Packit |
00408a |
char *uaddr;
|
|
Packit |
00408a |
{
|
|
Packit |
00408a |
CLIENT *client;
|
|
Packit |
00408a |
struct netbuf *taddr;
|
|
Packit |
00408a |
|
|
Packit |
00408a |
|
|
Packit |
00408a |
/* parameter checking */
|
|
Packit |
00408a |
if (nconf == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (uaddr == NULL) {
|
|
Packit |
00408a |
rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
client = local_rpcb();
|
|
Packit |
00408a |
if (! client) {
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
|
|
Packit |
00408a |
taddr = (struct netbuf *)calloc(1, sizeof (struct netbuf));
|
|
Packit |
00408a |
if (taddr == NULL) {
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return (NULL);
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
if (CLNT_CALL(client, (rpcproc_t)RPCBPROC_UADDR2TADDR,
|
|
Packit |
00408a |
(xdrproc_t) xdr_wrapstring, (char *)(void *)&uaddr,
|
|
Packit |
00408a |
(xdrproc_t) xdr_netbuf, (char *)(void *)taddr,
|
|
Packit |
00408a |
tottimeout) != RPC_SUCCESS) {
|
|
Packit |
00408a |
free(taddr);
|
|
Packit |
00408a |
taddr = NULL;
|
|
Packit |
00408a |
}
|
|
Packit |
00408a |
CLNT_DESTROY(client);
|
|
Packit |
00408a |
return (taddr);
|
|
Packit |
00408a |
}
|