Home | History | Annotate | Line # | Download | only in rpc
rpcb_clnt.c revision 1.3.2.2
      1  1.3.2.2     he /*	$NetBSD: rpcb_clnt.c,v 1.3.2.2 2001/11/25 20:33:13 he Exp $	*/
      2      1.1   fvdl 
      3      1.1   fvdl /*
      4      1.1   fvdl  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5      1.1   fvdl  * unrestricted use provided that this legend is included on all tape
      6      1.1   fvdl  * media and as a part of the software program in whole or part.  Users
      7      1.1   fvdl  * may copy or modify Sun RPC without charge, but are not authorized
      8      1.1   fvdl  * to license or distribute it to anyone else except as part of a product or
      9      1.1   fvdl  * program developed by the user.
     10      1.1   fvdl  *
     11      1.1   fvdl  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12      1.1   fvdl  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13      1.1   fvdl  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14      1.1   fvdl  *
     15      1.1   fvdl  * Sun RPC is provided with no support and without any obligation on the
     16      1.1   fvdl  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17      1.1   fvdl  * modification or enhancement.
     18      1.1   fvdl  *
     19      1.1   fvdl  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20      1.1   fvdl  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21      1.1   fvdl  * OR ANY PART THEREOF.
     22      1.1   fvdl  *
     23      1.1   fvdl  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24      1.1   fvdl  * or profits or other special, indirect and consequential damages, even if
     25      1.1   fvdl  * Sun has been advised of the possibility of such damages.
     26      1.1   fvdl  *
     27      1.1   fvdl  * Sun Microsystems, Inc.
     28      1.1   fvdl  * 2550 Garcia Avenue
     29      1.1   fvdl  * Mountain View, California  94043
     30      1.1   fvdl  */
     31      1.1   fvdl /*
     32      1.1   fvdl  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
     33      1.1   fvdl  */
     34      1.1   fvdl 
     35      1.1   fvdl /* #ident	"@(#)rpcb_clnt.c	1.27	94/04/24 SMI" */
     36      1.1   fvdl 
     37      1.1   fvdl 
     38      1.1   fvdl #if 0
     39      1.1   fvdl #if !defined(lint) && defined(SCCSIDS)
     40      1.1   fvdl static char sccsid[] = "@(#)rpcb_clnt.c 1.30 89/06/21 Copyr 1988 Sun Micro";
     41      1.1   fvdl #endif
     42      1.1   fvdl #endif
     43      1.1   fvdl 
     44      1.1   fvdl /*
     45      1.1   fvdl  * rpcb_clnt.c
     46      1.1   fvdl  * interface to rpcbind rpc service.
     47      1.1   fvdl  *
     48      1.1   fvdl  * Copyright (C) 1988, Sun Microsystems, Inc.
     49      1.1   fvdl  */
     50      1.1   fvdl 
     51      1.1   fvdl #include "namespace.h"
     52      1.1   fvdl #include "reentrant.h"
     53      1.1   fvdl #include <sys/types.h>
     54      1.1   fvdl #include <sys/socket.h>
     55      1.1   fvdl #include <sys/un.h>
     56      1.1   fvdl #include <sys/utsname.h>
     57      1.1   fvdl #include <rpc/rpc.h>
     58      1.1   fvdl #include <rpc/rpcb_prot.h>
     59      1.1   fvdl #include <netconfig.h>
     60      1.1   fvdl #ifdef PORTMAP
     61      1.1   fvdl #include <netinet/in.h>		/* FOR IPPROTO_TCP/UDP definitions */
     62      1.1   fvdl #include <rpc/pmap_prot.h>
     63      1.1   fvdl #endif
     64      1.1   fvdl #include <stdio.h>
     65      1.1   fvdl #include <errno.h>
     66      1.1   fvdl #include <stdlib.h>
     67      1.1   fvdl #include <string.h>
     68      1.1   fvdl #include <unistd.h>
     69      1.1   fvdl #include <netdb.h>
     70      1.3  assar #include <syslog.h>
     71      1.1   fvdl 
     72      1.1   fvdl #include "rpc_com.h"
     73      1.1   fvdl 
     74      1.1   fvdl #ifdef __weak_alias
     75      1.1   fvdl __weak_alias(rpcb_set,_rpcb_set)
     76      1.1   fvdl __weak_alias(rpcb_unset,_rpcb_unset)
     77      1.1   fvdl __weak_alias(rpcb_getmaps,_rpcb_getmaps)
     78      1.1   fvdl __weak_alias(rpcb_rmtcall,_rpcb_rmtcall)
     79      1.1   fvdl __weak_alias(rpcb_gettime,_rpcb_gettime)
     80      1.1   fvdl __weak_alias(rpcb_taddr2uaddr,_rpcb_taddr2uaddr)
     81      1.1   fvdl __weak_alias(rpcb_uaddr2taddr,_rpcb_uaddr2taddr)
     82      1.1   fvdl #endif
     83      1.1   fvdl 
     84      1.1   fvdl static struct timeval tottimeout = { 60, 0 };
     85      1.1   fvdl static const struct timeval rmttimeout = { 3, 0 };
     86      1.1   fvdl 
     87      1.1   fvdl extern bool_t xdr_wrapstring __P((XDR *, char **));
     88      1.1   fvdl 
     89      1.1   fvdl static const char nullstring[] = "\000";
     90      1.1   fvdl 
     91      1.1   fvdl #define	CACHESIZE 6
     92      1.1   fvdl 
     93      1.1   fvdl struct address_cache {
     94      1.1   fvdl 	char *ac_host;
     95      1.1   fvdl 	char *ac_netid;
     96      1.1   fvdl 	char *ac_uaddr;
     97      1.1   fvdl 	struct netbuf *ac_taddr;
     98      1.1   fvdl 	struct address_cache *ac_next;
     99      1.1   fvdl };
    100      1.1   fvdl 
    101      1.1   fvdl static struct address_cache *front;
    102      1.1   fvdl static int cachesize;
    103      1.1   fvdl 
    104      1.1   fvdl #define	CLCR_GET_RPCB_TIMEOUT	1
    105      1.1   fvdl #define	CLCR_SET_RPCB_TIMEOUT	2
    106      1.1   fvdl 
    107      1.1   fvdl 
    108      1.1   fvdl extern int __rpc_lowvers;
    109      1.1   fvdl 
    110      1.1   fvdl static struct address_cache *check_cache __P((const char *, const char *));
    111      1.1   fvdl static void delete_cache __P((struct netbuf *));
    112      1.1   fvdl static void add_cache __P((const char *, const char *, struct netbuf *,
    113      1.1   fvdl 			   char *));
    114      1.1   fvdl static CLIENT *getclnthandle __P((const char *, const struct netconfig *,
    115      1.1   fvdl 				  char **));
    116      1.1   fvdl static CLIENT *local_rpcb __P((void));
    117      1.1   fvdl static struct netbuf *got_entry __P((rpcb_entry_list_ptr,
    118      1.1   fvdl 				     const struct netconfig *));
    119      1.1   fvdl 
    120      1.1   fvdl /*
    121      1.1   fvdl  * This routine adjusts the timeout used for calls to the remote rpcbind.
    122      1.1   fvdl  * Also, this routine can be used to set the use of portmapper version 2
    123      1.1   fvdl  * only when doing rpc_broadcasts
    124      1.1   fvdl  * These are private routines that may not be provided in future releases.
    125      1.1   fvdl  */
    126      1.1   fvdl bool_t
    127      1.1   fvdl __rpc_control(request, info)
    128      1.1   fvdl 	int	request;
    129      1.1   fvdl 	void	*info;
    130      1.1   fvdl {
    131      1.1   fvdl 	switch (request) {
    132      1.1   fvdl 	case CLCR_GET_RPCB_TIMEOUT:
    133      1.1   fvdl 		*(struct timeval *)info = tottimeout;
    134      1.1   fvdl 		break;
    135      1.1   fvdl 	case CLCR_SET_RPCB_TIMEOUT:
    136      1.1   fvdl 		tottimeout = *(struct timeval *)info;
    137      1.1   fvdl 		break;
    138      1.1   fvdl 	case CLCR_SET_LOWVERS:
    139      1.1   fvdl 		__rpc_lowvers = *(int *)info;
    140      1.1   fvdl 		break;
    141      1.1   fvdl 	case CLCR_GET_LOWVERS:
    142      1.1   fvdl 		*(int *)info = __rpc_lowvers;
    143      1.1   fvdl 		break;
    144      1.1   fvdl 	default:
    145      1.1   fvdl 		return (FALSE);
    146      1.1   fvdl 	}
    147      1.1   fvdl 	return (TRUE);
    148      1.1   fvdl }
    149      1.1   fvdl 
    150      1.1   fvdl /*
    151      1.1   fvdl  *	It might seem that a reader/writer lock would be more reasonable here.
    152      1.1   fvdl  *	However because getclnthandle(), the only user of the cache functions,
    153      1.1   fvdl  *	may do a delete_cache() operation if a check_cache() fails to return an
    154      1.1   fvdl  *	address useful to clnt_tli_create(), we may as well use a mutex.
    155      1.1   fvdl  */
    156      1.1   fvdl /*
    157      1.1   fvdl  * As it turns out, if the cache lock is *not* a reader/writer lock, we will
    158      1.1   fvdl  * block all clnt_create's if we are trying to connect to a host that's down,
    159      1.1   fvdl  * since the lock will be held all during that time.
    160      1.1   fvdl  */
    161      1.1   fvdl #ifdef __REENT
    162      1.1   fvdl extern rwlock_t	rpcbaddr_cache_lock;
    163      1.1   fvdl #endif
    164      1.1   fvdl 
    165      1.1   fvdl /*
    166      1.1   fvdl  * The routines check_cache(), add_cache(), delete_cache() manage the
    167      1.1   fvdl  * cache of rpcbind addresses for (host, netid).
    168      1.1   fvdl  */
    169      1.1   fvdl 
    170      1.1   fvdl static struct address_cache *
    171      1.1   fvdl check_cache(host, netid)
    172      1.1   fvdl 	const char *host, *netid;
    173      1.1   fvdl {
    174      1.1   fvdl 	struct address_cache *cptr;
    175      1.1   fvdl 
    176      1.1   fvdl 	/* READ LOCK HELD ON ENTRY: rpcbaddr_cache_lock */
    177      1.1   fvdl 
    178      1.1   fvdl 	for (cptr = front; cptr != NULL; cptr = cptr->ac_next) {
    179      1.1   fvdl 		if (!strcmp(cptr->ac_host, host) &&
    180      1.1   fvdl 		    !strcmp(cptr->ac_netid, netid)) {
    181      1.1   fvdl #ifdef ND_DEBUG
    182      1.1   fvdl 			fprintf(stderr, "Found cache entry for %s: %s\n",
    183      1.1   fvdl 				host, netid);
    184      1.1   fvdl #endif
    185      1.1   fvdl 			return (cptr);
    186      1.1   fvdl 		}
    187      1.1   fvdl 	}
    188      1.1   fvdl 	return ((struct address_cache *) NULL);
    189      1.1   fvdl }
    190      1.1   fvdl 
    191      1.1   fvdl static void
    192      1.1   fvdl delete_cache(addr)
    193      1.1   fvdl 	struct netbuf *addr;
    194      1.1   fvdl {
    195      1.1   fvdl 	struct address_cache *cptr, *prevptr = NULL;
    196      1.1   fvdl 
    197      1.1   fvdl 	/* WRITE LOCK HELD ON ENTRY: rpcbaddr_cache_lock */
    198      1.1   fvdl 	for (cptr = front; cptr != NULL; cptr = cptr->ac_next) {
    199      1.1   fvdl 		if (!memcmp(cptr->ac_taddr->buf, addr->buf, addr->len)) {
    200      1.1   fvdl 			free(cptr->ac_host);
    201      1.1   fvdl 			free(cptr->ac_netid);
    202      1.1   fvdl 			free(cptr->ac_taddr->buf);
    203      1.1   fvdl 			free(cptr->ac_taddr);
    204      1.1   fvdl 			if (cptr->ac_uaddr)
    205      1.1   fvdl 				free(cptr->ac_uaddr);
    206      1.1   fvdl 			if (prevptr)
    207      1.1   fvdl 				prevptr->ac_next = cptr->ac_next;
    208      1.1   fvdl 			else
    209      1.1   fvdl 				front = cptr->ac_next;
    210      1.1   fvdl 			free(cptr);
    211      1.1   fvdl 			cachesize--;
    212      1.1   fvdl 			break;
    213      1.1   fvdl 		}
    214      1.1   fvdl 		prevptr = cptr;
    215      1.1   fvdl 	}
    216      1.1   fvdl }
    217      1.1   fvdl 
    218      1.1   fvdl static void
    219      1.1   fvdl add_cache(host, netid, taddr, uaddr)
    220      1.1   fvdl 	const char *host, *netid;
    221      1.1   fvdl 	char *uaddr;
    222      1.1   fvdl 	struct netbuf *taddr;
    223      1.1   fvdl {
    224      1.1   fvdl 	struct address_cache  *ad_cache, *cptr, *prevptr;
    225      1.1   fvdl 
    226      1.1   fvdl 	ad_cache = (struct address_cache *)
    227      1.1   fvdl 			malloc(sizeof (struct address_cache));
    228      1.1   fvdl 	if (!ad_cache) {
    229      1.1   fvdl 		return;
    230      1.1   fvdl 	}
    231      1.1   fvdl 	ad_cache->ac_host = strdup(host);
    232      1.1   fvdl 	ad_cache->ac_netid = strdup(netid);
    233      1.1   fvdl 	ad_cache->ac_uaddr = uaddr ? strdup(uaddr) : NULL;
    234      1.1   fvdl 	ad_cache->ac_taddr = (struct netbuf *)malloc(sizeof (struct netbuf));
    235      1.1   fvdl 	if (!ad_cache->ac_host || !ad_cache->ac_netid || !ad_cache->ac_taddr ||
    236      1.1   fvdl 		(uaddr && !ad_cache->ac_uaddr)) {
    237      1.1   fvdl 		return;
    238      1.1   fvdl 	}
    239      1.1   fvdl 	ad_cache->ac_taddr->len = ad_cache->ac_taddr->maxlen = taddr->len;
    240      1.1   fvdl 	ad_cache->ac_taddr->buf = (char *) malloc(taddr->len);
    241      1.1   fvdl 	if (ad_cache->ac_taddr->buf == NULL) {
    242      1.1   fvdl 		return;
    243      1.1   fvdl 	}
    244      1.1   fvdl 	memcpy(ad_cache->ac_taddr->buf, taddr->buf, taddr->len);
    245      1.1   fvdl #ifdef ND_DEBUG
    246      1.1   fvdl 	fprintf(stderr, "Added to cache: %s : %s\n", host, netid);
    247      1.1   fvdl #endif
    248      1.1   fvdl 
    249      1.1   fvdl /* VARIABLES PROTECTED BY rpcbaddr_cache_lock:  cptr */
    250      1.1   fvdl 
    251      1.1   fvdl 	rwlock_wrlock(&rpcbaddr_cache_lock);
    252      1.1   fvdl 	if (cachesize < CACHESIZE) {
    253      1.1   fvdl 		ad_cache->ac_next = front;
    254      1.1   fvdl 		front = ad_cache;
    255      1.1   fvdl 		cachesize++;
    256      1.1   fvdl 	} else {
    257      1.1   fvdl 		/* Free the last entry */
    258      1.1   fvdl 		cptr = front;
    259      1.1   fvdl 		prevptr = NULL;
    260      1.1   fvdl 		while (cptr->ac_next) {
    261      1.1   fvdl 			prevptr = cptr;
    262      1.1   fvdl 			cptr = cptr->ac_next;
    263      1.1   fvdl 		}
    264      1.1   fvdl 
    265      1.1   fvdl #ifdef ND_DEBUG
    266      1.1   fvdl 		fprintf(stderr, "Deleted from cache: %s : %s\n",
    267      1.1   fvdl 			cptr->ac_host, cptr->ac_netid);
    268      1.1   fvdl #endif
    269      1.1   fvdl 		free(cptr->ac_host);
    270      1.1   fvdl 		free(cptr->ac_netid);
    271      1.1   fvdl 		free(cptr->ac_taddr->buf);
    272      1.1   fvdl 		free(cptr->ac_taddr);
    273      1.1   fvdl 		if (cptr->ac_uaddr)
    274      1.1   fvdl 			free(cptr->ac_uaddr);
    275      1.1   fvdl 
    276      1.1   fvdl 		if (prevptr) {
    277      1.1   fvdl 			prevptr->ac_next = NULL;
    278      1.1   fvdl 			ad_cache->ac_next = front;
    279      1.1   fvdl 			front = ad_cache;
    280      1.1   fvdl 		} else {
    281      1.1   fvdl 			front = ad_cache;
    282      1.1   fvdl 			ad_cache->ac_next = NULL;
    283      1.1   fvdl 		}
    284      1.1   fvdl 		free(cptr);
    285      1.1   fvdl 	}
    286      1.1   fvdl 	rwlock_unlock(&rpcbaddr_cache_lock);
    287      1.1   fvdl }
    288      1.1   fvdl 
    289      1.1   fvdl /*
    290      1.1   fvdl  * This routine will return a client handle that is connected to the
    291      1.1   fvdl  * rpcbind. Returns NULL on error and free's everything.
    292      1.1   fvdl  */
    293      1.1   fvdl static CLIENT *
    294      1.1   fvdl getclnthandle(host, nconf, targaddr)
    295      1.1   fvdl 	const char *host;
    296      1.1   fvdl 	const struct netconfig *nconf;
    297      1.1   fvdl 	char **targaddr;
    298      1.1   fvdl {
    299      1.1   fvdl 	register CLIENT *client;
    300      1.1   fvdl 	struct netbuf *addr, taddr;
    301      1.1   fvdl 	struct netbuf addr_to_delete;
    302      1.1   fvdl 	struct __rpc_sockinfo si;
    303      1.1   fvdl 	struct addrinfo hints, *res, *tres;
    304      1.1   fvdl 	struct address_cache *ad_cache;
    305      1.1   fvdl 	char *tmpaddr;
    306      1.1   fvdl 
    307      1.1   fvdl /* VARIABLES PROTECTED BY rpcbaddr_cache_lock:  ad_cache */
    308      1.1   fvdl 
    309      1.1   fvdl 	/* Get the address of the rpcbind.  Check cache first */
    310      1.1   fvdl 	addr_to_delete.len = 0;
    311      1.1   fvdl 	rwlock_rdlock(&rpcbaddr_cache_lock);
    312      1.1   fvdl 	ad_cache = check_cache(host, nconf->nc_netid);
    313      1.1   fvdl 	if (ad_cache != NULL) {
    314      1.1   fvdl 		addr = ad_cache->ac_taddr;
    315      1.1   fvdl 		client = clnt_tli_create(RPC_ANYFD, nconf, addr, RPCBPROG,
    316      1.1   fvdl 					RPCBVERS4, 0, 0);
    317      1.1   fvdl 		if (client != NULL) {
    318      1.1   fvdl 			if (targaddr)
    319      1.1   fvdl 				*targaddr = ad_cache->ac_uaddr;
    320      1.1   fvdl 			rwlock_unlock(&rpcbaddr_cache_lock);
    321      1.1   fvdl 			return (client);
    322      1.1   fvdl 		}
    323      1.1   fvdl 		addr_to_delete.len = addr->len;
    324      1.1   fvdl 		addr_to_delete.buf = (char *)malloc(addr->len);
    325      1.1   fvdl 		if (addr_to_delete.buf == NULL) {
    326      1.1   fvdl 			addr_to_delete.len = 0;
    327      1.1   fvdl 		} else {
    328      1.1   fvdl 			memcpy(addr_to_delete.buf, addr->buf, addr->len);
    329      1.1   fvdl 		}
    330      1.1   fvdl 	}
    331      1.1   fvdl 	rwlock_unlock(&rpcbaddr_cache_lock);
    332      1.1   fvdl 	if (addr_to_delete.len != 0) {
    333      1.1   fvdl 		/*
    334      1.1   fvdl 		 * Assume this may be due to cache data being
    335      1.1   fvdl 		 *  outdated
    336      1.1   fvdl 		 */
    337      1.1   fvdl 		rwlock_wrlock(&rpcbaddr_cache_lock);
    338      1.1   fvdl 		delete_cache(&addr_to_delete);
    339      1.1   fvdl 		rwlock_unlock(&rpcbaddr_cache_lock);
    340      1.1   fvdl 		free(addr_to_delete.buf);
    341      1.1   fvdl 	}
    342      1.2   fvdl 	if (!__rpc_nconf2sockinfo(nconf, &si)) {
    343      1.2   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    344      1.1   fvdl 		return NULL;
    345      1.2   fvdl 	}
    346      1.1   fvdl 
    347      1.1   fvdl 	memset(&hints, 0, sizeof hints);
    348      1.1   fvdl 	hints.ai_family = si.si_af;
    349      1.1   fvdl 	hints.ai_socktype = si.si_socktype;
    350      1.1   fvdl 	hints.ai_protocol = si.si_proto;
    351      1.1   fvdl 
    352      1.1   fvdl #ifdef CLNT_DEBUG
    353      1.1   fvdl 	printf("trying netid %s family %d proto %d socktype %d\n",
    354      1.1   fvdl 	    nconf->nc_netid, si.si_af, si.si_proto, si.si_socktype);
    355      1.1   fvdl #endif
    356      1.1   fvdl 
    357      1.2   fvdl 	if (getaddrinfo(host, "sunrpc", &hints, &res) != 0) {
    358      1.2   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
    359      1.1   fvdl 		return NULL;
    360      1.2   fvdl 	}
    361      1.1   fvdl 
    362      1.1   fvdl 	for (tres = res; tres != NULL; tres = tres->ai_next) {
    363      1.1   fvdl 		taddr.buf = tres->ai_addr;
    364      1.1   fvdl 		taddr.len = taddr.maxlen = tres->ai_addrlen;
    365      1.1   fvdl 
    366      1.1   fvdl #ifdef ND_DEBUG
    367      1.1   fvdl 		{
    368      1.1   fvdl 			char *ua;
    369      1.1   fvdl 
    370      1.1   fvdl 			ua = taddr2uaddr(nconf, &taddr);
    371      1.1   fvdl 			fprintf(stderr, "Got it [%s]\n", ua);
    372      1.1   fvdl 			free(ua);
    373      1.1   fvdl 		}
    374      1.1   fvdl #endif
    375      1.1   fvdl 
    376      1.1   fvdl #ifdef ND_DEBUG
    377      1.1   fvdl 		{
    378      1.1   fvdl 			int i;
    379      1.1   fvdl 
    380      1.1   fvdl 			fprintf(stderr, "\tnetbuf len = %d, maxlen = %d\n",
    381      1.1   fvdl 				taddr.len, taddr.maxlen);
    382      1.1   fvdl 			fprintf(stderr, "\tAddress is ");
    383      1.1   fvdl 			for (i = 0; i < taddr.len; i++)
    384      1.2   fvdl 				fprintf(stderr, "%u.", ((char *)(taddr.buf))[i]);
    385      1.1   fvdl 			fprintf(stderr, "\n");
    386      1.1   fvdl 		}
    387      1.1   fvdl #endif
    388      1.1   fvdl 		client = clnt_tli_create(RPC_ANYFD, nconf, &taddr, RPCBPROG,
    389      1.1   fvdl 					RPCBVERS4, 0, 0);
    390      1.1   fvdl #ifdef ND_DEBUG
    391      1.1   fvdl 		if (! client) {
    392      1.1   fvdl 			clnt_pcreateerror("rpcbind clnt interface");
    393      1.1   fvdl 		}
    394      1.1   fvdl #endif
    395      1.1   fvdl 
    396      1.1   fvdl 		if (client) {
    397      1.1   fvdl 			tmpaddr = targaddr ? taddr2uaddr(nconf, &taddr) : NULL;
    398      1.1   fvdl 			add_cache(host, nconf->nc_netid, &taddr, tmpaddr);
    399      1.1   fvdl 			if (targaddr)
    400      1.1   fvdl 				*targaddr = tmpaddr;
    401      1.1   fvdl 			break;
    402      1.1   fvdl 		}
    403      1.1   fvdl 	}
    404      1.1   fvdl 	freeaddrinfo(res);
    405      1.1   fvdl 	return (client);
    406      1.1   fvdl }
    407      1.1   fvdl 
    408      1.1   fvdl /* XXX */
    409      1.1   fvdl #define IN4_LOCALHOST_STRING	"127.0.0.1"
    410      1.1   fvdl #define IN6_LOCALHOST_STRING	"::1"
    411      1.1   fvdl 
    412      1.1   fvdl /*
    413      1.1   fvdl  * This routine will return a client handle that is connected to the local
    414      1.1   fvdl  * rpcbind. Returns NULL on error and free's everything.
    415      1.1   fvdl  */
    416      1.1   fvdl static CLIENT *
    417      1.1   fvdl local_rpcb()
    418      1.1   fvdl {
    419      1.1   fvdl 	CLIENT *client;
    420      1.1   fvdl 	static struct netconfig *loopnconf;
    421      1.1   fvdl 	static char *hostname;
    422      1.1   fvdl #ifdef __REENT
    423      1.1   fvdl 	extern mutex_t loopnconf_lock;
    424      1.1   fvdl #endif
    425      1.1   fvdl 	int sock, tsize;
    426      1.1   fvdl 	struct netbuf nbuf;
    427      1.1   fvdl 	struct sockaddr_un sun;
    428      1.1   fvdl 
    429      1.1   fvdl 	/*
    430      1.1   fvdl 	 * Try connecting to the local rpcbind through a local socket
    431      1.1   fvdl 	 * first. If this doesn't work, try all transports defined in
    432      1.1   fvdl 	 * the netconfig file.
    433      1.1   fvdl 	 */
    434      1.1   fvdl 	memset(&sun, 0, sizeof sun);
    435      1.1   fvdl 	sock = socket(AF_LOCAL, SOCK_STREAM, 0);
    436      1.1   fvdl 	if (sock < 0)
    437      1.1   fvdl 		goto try_nconf;
    438      1.1   fvdl 	sun.sun_family = AF_LOCAL;
    439      1.1   fvdl 	strcpy(sun.sun_path, _PATH_RPCBINDSOCK);
    440      1.1   fvdl 	nbuf.len = sun.sun_len = SUN_LEN(&sun);
    441      1.1   fvdl 	nbuf.maxlen = sizeof (struct sockaddr_un);
    442      1.1   fvdl 	nbuf.buf = &sun;
    443      1.1   fvdl 
    444      1.1   fvdl 	tsize = __rpc_get_t_size(AF_LOCAL, 0, 0);
    445      1.1   fvdl 	client = clnt_vc_create(sock, &nbuf, RPCBPROG, RPCBVERS, tsize, tsize);
    446      1.1   fvdl 
    447  1.3.2.2     he 	if (client != NULL) {
    448  1.3.2.2     he 		/* XXX - mark the socket to be closed in destructor */
    449  1.3.2.2     he 		(void) CLNT_CONTROL(client, CLSET_FD_CLOSE, NULL);
    450      1.1   fvdl 		return client;
    451  1.3.2.2     he 	}
    452  1.3.2.2     he 
    453  1.3.2.2     he 	/* XXX - nobody needs this socket anymore, free the descriptor */
    454  1.3.2.2     he 	close(sock);
    455      1.1   fvdl 
    456      1.1   fvdl try_nconf:
    457      1.1   fvdl 
    458      1.1   fvdl /* VARIABLES PROTECTED BY loopnconf_lock: loopnconf */
    459      1.1   fvdl 	mutex_lock(&loopnconf_lock);
    460      1.1   fvdl 	if (loopnconf == NULL) {
    461      1.1   fvdl 		struct netconfig *nconf, *tmpnconf = NULL;
    462      1.1   fvdl 		void *nc_handle;
    463      1.1   fvdl 		int fd;
    464      1.1   fvdl 
    465      1.1   fvdl 		nc_handle = setnetconfig();
    466      1.1   fvdl 		if (nc_handle == NULL) {
    467      1.1   fvdl 			/* fails to open netconfig file */
    468      1.3  assar 			syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
    469      1.1   fvdl 			rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    470      1.1   fvdl 			mutex_unlock(&loopnconf_lock);
    471      1.1   fvdl 			return (NULL);
    472      1.1   fvdl 		}
    473      1.1   fvdl 		while ((nconf = getnetconfig(nc_handle))) {
    474      1.1   fvdl #ifdef INET6
    475      1.1   fvdl 			if ((strcmp(nconf->nc_protofmly, NC_INET6) == 0 ||
    476      1.1   fvdl #else
    477      1.1   fvdl 			if (
    478      1.1   fvdl #endif
    479      1.1   fvdl 			     strcmp(nconf->nc_protofmly, NC_INET) == 0) &&
    480      1.1   fvdl 			    (nconf->nc_semantics == NC_TPI_COTS ||
    481      1.1   fvdl 			     nconf->nc_semantics == NC_TPI_COTS_ORD)) {
    482      1.1   fvdl 				fd = __rpc_nconf2fd(nconf);
    483      1.1   fvdl 				/*
    484      1.1   fvdl 				 * Can't create a socket, assume that
    485      1.1   fvdl 				 * this family isn't configured in the kernel.
    486      1.1   fvdl 				 */
    487      1.1   fvdl 				if (fd < 0)
    488      1.1   fvdl 					continue;
    489      1.1   fvdl 				close(fd);
    490      1.1   fvdl 				tmpnconf = nconf;
    491      1.1   fvdl 				if (!strcmp(nconf->nc_protofmly, NC_INET))
    492      1.1   fvdl 					hostname = IN4_LOCALHOST_STRING;
    493      1.1   fvdl 				else
    494      1.1   fvdl 					hostname = IN6_LOCALHOST_STRING;
    495      1.1   fvdl 			}
    496      1.1   fvdl 		}
    497      1.1   fvdl 		if (tmpnconf == NULL) {
    498      1.1   fvdl 			rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    499      1.1   fvdl 			mutex_unlock(&loopnconf_lock);
    500      1.1   fvdl 			return (NULL);
    501      1.1   fvdl 		}
    502      1.1   fvdl 		loopnconf = getnetconfigent(tmpnconf->nc_netid);
    503      1.1   fvdl 		/* loopnconf is never freed */
    504      1.1   fvdl 		endnetconfig(nc_handle);
    505      1.1   fvdl 	}
    506      1.1   fvdl 	mutex_unlock(&loopnconf_lock);
    507      1.1   fvdl 	client = getclnthandle(hostname, loopnconf, (char **)NULL);
    508      1.1   fvdl 	return (client);
    509      1.1   fvdl }
    510      1.1   fvdl 
    511      1.1   fvdl /*
    512      1.1   fvdl  * Set a mapping between program, version and address.
    513      1.1   fvdl  * Calls the rpcbind service to do the mapping.
    514      1.1   fvdl  */
    515      1.1   fvdl bool_t
    516      1.1   fvdl rpcb_set(program, version, nconf, address)
    517      1.1   fvdl 	rpcprog_t program;
    518      1.1   fvdl 	rpcvers_t version;
    519      1.1   fvdl 	const struct netconfig *nconf;	/* Network structure of transport */
    520      1.1   fvdl 	const struct netbuf *address;		/* Services netconfig address */
    521      1.1   fvdl {
    522      1.1   fvdl 	register CLIENT *client;
    523      1.1   fvdl 	bool_t rslt = FALSE;
    524      1.1   fvdl 	RPCB parms;
    525      1.1   fvdl 	char uidbuf[32];
    526      1.1   fvdl 
    527      1.1   fvdl 	/* parameter checking */
    528      1.1   fvdl 	if (nconf == (struct netconfig *)NULL) {
    529      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    530      1.1   fvdl 		return (FALSE);
    531      1.1   fvdl 	}
    532      1.1   fvdl 	if (address == NULL) {
    533      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
    534      1.1   fvdl 		return (FALSE);
    535      1.1   fvdl 	}
    536      1.1   fvdl 	client = local_rpcb();
    537      1.1   fvdl 	if (! client) {
    538      1.1   fvdl 		return (FALSE);
    539      1.1   fvdl 	}
    540      1.1   fvdl 
    541      1.1   fvdl 	/* convert to universal */
    542      1.1   fvdl 	parms.r_addr = taddr2uaddr((struct netconfig *) nconf,
    543      1.1   fvdl 				   (struct netbuf *)address);
    544      1.1   fvdl 	if (!parms.r_addr) {
    545  1.3.2.2     he 		CLNT_DESTROY(client);
    546      1.1   fvdl 		rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE;
    547      1.1   fvdl 		return (FALSE); /* no universal address */
    548      1.1   fvdl 	}
    549      1.1   fvdl 	parms.r_prog = program;
    550      1.1   fvdl 	parms.r_vers = version;
    551      1.1   fvdl 	parms.r_netid = nconf->nc_netid;
    552      1.1   fvdl 	/*
    553      1.1   fvdl 	 * Though uid is not being used directly, we still send it for
    554      1.1   fvdl 	 * completeness.  For non-unix platforms, perhaps some other
    555      1.1   fvdl 	 * string or an empty string can be sent.
    556      1.1   fvdl 	 */
    557      1.1   fvdl 	(void) snprintf(uidbuf, sizeof uidbuf, "%d", geteuid());
    558      1.1   fvdl 	parms.r_owner = uidbuf;
    559      1.1   fvdl 
    560      1.1   fvdl 	CLNT_CALL(client, RPCBPROC_SET, (xdrproc_t) xdr_rpcb, (char *)&parms,
    561      1.1   fvdl 			(xdrproc_t) xdr_bool, (char *)&rslt, tottimeout);
    562      1.1   fvdl 
    563      1.1   fvdl 	CLNT_DESTROY(client);
    564      1.1   fvdl 	free(parms.r_addr);
    565      1.1   fvdl 	return (rslt);
    566      1.1   fvdl }
    567      1.1   fvdl 
    568      1.1   fvdl /*
    569      1.1   fvdl  * Remove the mapping between program, version and netbuf address.
    570      1.1   fvdl  * Calls the rpcbind service to do the un-mapping.
    571      1.1   fvdl  * If netbuf is NULL, unset for all the transports, otherwise unset
    572      1.1   fvdl  * only for the given transport.
    573      1.1   fvdl  */
    574      1.1   fvdl bool_t
    575      1.1   fvdl rpcb_unset(program, version, nconf)
    576      1.1   fvdl 	rpcprog_t program;
    577      1.1   fvdl 	rpcvers_t version;
    578      1.1   fvdl 	const struct netconfig *nconf;
    579      1.1   fvdl {
    580      1.1   fvdl 	register CLIENT *client;
    581      1.1   fvdl 	bool_t rslt = FALSE;
    582      1.1   fvdl 	RPCB parms;
    583      1.1   fvdl 	char uidbuf[32];
    584      1.1   fvdl 
    585      1.1   fvdl 	client = local_rpcb();
    586      1.1   fvdl 	if (! client) {
    587      1.1   fvdl 		return (FALSE);
    588      1.1   fvdl 	}
    589      1.1   fvdl 
    590      1.1   fvdl 	parms.r_prog = program;
    591      1.1   fvdl 	parms.r_vers = version;
    592      1.1   fvdl 	if (nconf)
    593      1.1   fvdl 		parms.r_netid = nconf->nc_netid;
    594      1.1   fvdl 	else
    595      1.1   fvdl 		parms.r_netid = (char *) &nullstring[0]; /* unsets  all */
    596      1.1   fvdl 	parms.r_addr = (char *) &nullstring[0];
    597      1.1   fvdl 	(void) snprintf(uidbuf, sizeof uidbuf, "%d", geteuid());
    598      1.1   fvdl 	parms.r_owner = uidbuf;
    599      1.1   fvdl 
    600      1.1   fvdl 	CLNT_CALL(client, RPCBPROC_UNSET, (xdrproc_t) xdr_rpcb, (char *)&parms,
    601      1.1   fvdl 			(xdrproc_t) xdr_bool, (char *)&rslt, tottimeout);
    602      1.1   fvdl 
    603      1.1   fvdl 	CLNT_DESTROY(client);
    604      1.1   fvdl 	return (rslt);
    605      1.1   fvdl }
    606      1.1   fvdl 
    607      1.1   fvdl /*
    608      1.1   fvdl  * From the merged list, find the appropriate entry
    609      1.1   fvdl  */
    610      1.1   fvdl static struct netbuf *
    611      1.1   fvdl got_entry(relp, nconf)
    612      1.1   fvdl 	rpcb_entry_list_ptr relp;
    613      1.1   fvdl 	const struct netconfig *nconf;
    614      1.1   fvdl {
    615      1.1   fvdl 	struct netbuf *na = NULL;
    616      1.1   fvdl 	rpcb_entry_list_ptr sp;
    617      1.1   fvdl 	rpcb_entry *rmap;
    618      1.1   fvdl 
    619      1.1   fvdl 	for (sp = relp; sp != NULL; sp = sp->rpcb_entry_next) {
    620      1.1   fvdl 		rmap = &sp->rpcb_entry_map;
    621      1.1   fvdl 		if ((strcmp(nconf->nc_proto, rmap->r_nc_proto) == 0) &&
    622      1.1   fvdl 		    (strcmp(nconf->nc_protofmly, rmap->r_nc_protofmly) == 0) &&
    623      1.1   fvdl 		    (nconf->nc_semantics == rmap->r_nc_semantics) &&
    624      1.1   fvdl 		    (rmap->r_maddr != NULL) && (rmap->r_maddr[0] != NULL)) {
    625      1.1   fvdl 			na = uaddr2taddr(nconf, rmap->r_maddr);
    626      1.1   fvdl #ifdef ND_DEBUG
    627      1.1   fvdl 			fprintf(stderr, "\tRemote address is [%s].\n",
    628      1.1   fvdl 				rmap->r_maddr);
    629      1.1   fvdl 			if (!na)
    630      1.1   fvdl 				fprintf(stderr,
    631      1.1   fvdl 				    "\tCouldn't resolve remote address!\n");
    632      1.1   fvdl #endif
    633      1.1   fvdl 			break;
    634      1.1   fvdl 		}
    635      1.1   fvdl 	}
    636      1.1   fvdl 	return (na);
    637      1.1   fvdl }
    638      1.1   fvdl 
    639      1.1   fvdl /*
    640      1.1   fvdl  * An internal function which optimizes rpcb_getaddr function.  It also
    641      1.1   fvdl  * returns the client handle that it uses to contact the remote rpcbind.
    642      1.1   fvdl  *
    643      1.1   fvdl  * The algorithm used: If the transports is TCP or UDP, it first tries
    644      1.1   fvdl  * version 2 (portmap), 4 and then 3 (svr4).  This order should be
    645      1.1   fvdl  * changed in the next OS release to 4, 2 and 3.  We are assuming that by
    646      1.1   fvdl  * that time, version 4 would be available on many machines on the network.
    647      1.1   fvdl  * With this algorithm, we get performance as well as a plan for
    648      1.1   fvdl  * obsoleting version 2.
    649      1.1   fvdl  *
    650      1.1   fvdl  * For all other transports, the algorithm remains as 4 and then 3.
    651      1.1   fvdl  *
    652      1.1   fvdl  * XXX: Due to some problems with t_connect(), we do not reuse the same client
    653      1.1   fvdl  * handle for COTS cases and hence in these cases we do not return the
    654      1.1   fvdl  * client handle.  This code will change if t_connect() ever
    655      1.1   fvdl  * starts working properly.  Also look under clnt_vc.c.
    656      1.1   fvdl  */
    657      1.1   fvdl struct netbuf *
    658      1.1   fvdl __rpcb_findaddr(program, version, nconf, host, clpp)
    659      1.1   fvdl 	rpcprog_t program;
    660      1.1   fvdl 	rpcvers_t version;
    661      1.1   fvdl 	const struct netconfig *nconf;
    662      1.1   fvdl 	const char *host;
    663      1.1   fvdl 	CLIENT **clpp;
    664      1.1   fvdl {
    665      1.1   fvdl 	register CLIENT *client = NULL;
    666      1.1   fvdl 	RPCB parms;
    667      1.1   fvdl 	enum clnt_stat clnt_st;
    668      1.1   fvdl 	char *ua = NULL;
    669      1.1   fvdl 	rpcvers_t vers;
    670      1.1   fvdl 	struct netbuf *address = NULL;
    671      1.1   fvdl 	rpcvers_t start_vers = RPCBVERS4;
    672      1.1   fvdl 	struct netbuf servaddr;
    673      1.1   fvdl 
    674      1.1   fvdl 	/* parameter checking */
    675      1.1   fvdl 	if (nconf == (struct netconfig *)NULL) {
    676      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    677      1.1   fvdl 		return (NULL);
    678      1.1   fvdl 	}
    679      1.1   fvdl 
    680      1.1   fvdl 	parms.r_addr = NULL;
    681      1.1   fvdl 
    682      1.1   fvdl #ifdef PORTMAP
    683      1.1   fvdl 	/* Try version 2 for TCP or UDP */
    684      1.1   fvdl 	if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
    685      1.1   fvdl 		u_short port = 0;
    686      1.1   fvdl 		struct netbuf remote;
    687  1.3.2.1   fvdl 		rpcvers_t pmapvers = 2;
    688      1.1   fvdl 		struct pmap pmapparms;
    689      1.1   fvdl 
    690      1.1   fvdl 		/*
    691      1.1   fvdl 		 * Try UDP only - there are some portmappers out
    692      1.1   fvdl 		 * there that use UDP only.
    693      1.1   fvdl 		 */
    694      1.1   fvdl 		if (strcmp(nconf->nc_proto, NC_TCP) == 0) {
    695      1.1   fvdl 			struct netconfig *newnconf;
    696      1.1   fvdl 
    697      1.2   fvdl 			if ((newnconf = getnetconfigent("udp")) == NULL) {
    698      1.1   fvdl 				rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
    699      1.1   fvdl 				return (NULL);
    700      1.1   fvdl 			}
    701      1.1   fvdl 			client = getclnthandle(host, newnconf, &parms.r_addr);
    702      1.2   fvdl 			freenetconfigent(newnconf);
    703      1.1   fvdl 		} else {
    704      1.1   fvdl 			client = getclnthandle(host, nconf, &parms.r_addr);
    705      1.1   fvdl 		}
    706      1.1   fvdl 		if (client == (CLIENT *)NULL) {
    707      1.1   fvdl 			return (NULL);
    708      1.1   fvdl 		}
    709      1.1   fvdl 
    710      1.1   fvdl 		/* Set the version */
    711      1.1   fvdl 		CLNT_CONTROL(client, CLSET_VERS, (char *)&pmapvers);
    712      1.1   fvdl 		pmapparms.pm_prog = program;
    713      1.1   fvdl 		pmapparms.pm_vers = version;
    714      1.1   fvdl 		pmapparms.pm_prot = strcmp(nconf->nc_proto, NC_TCP) ?
    715      1.1   fvdl 					IPPROTO_UDP : IPPROTO_TCP;
    716      1.1   fvdl 		pmapparms.pm_port = 0;	/* not needed */
    717      1.1   fvdl 		clnt_st = CLNT_CALL(client, PMAPPROC_GETPORT,
    718      1.1   fvdl 			(xdrproc_t) xdr_pmap, (caddr_t) &pmapparms,
    719      1.1   fvdl 			(xdrproc_t) xdr_u_short, (caddr_t) &port,
    720      1.1   fvdl 			tottimeout);
    721      1.1   fvdl 		if (clnt_st != RPC_SUCCESS) {
    722      1.1   fvdl 			if ((clnt_st == RPC_PROGVERSMISMATCH) ||
    723      1.1   fvdl 				(clnt_st == RPC_PROGUNAVAIL))
    724      1.1   fvdl 				goto try_rpcbind; /* Try different versions */
    725      1.1   fvdl 			rpc_createerr.cf_stat = RPC_PMAPFAILURE;
    726      1.1   fvdl 			clnt_geterr(client, &rpc_createerr.cf_error);
    727      1.1   fvdl 			goto error;
    728      1.1   fvdl 		} else if (port == 0) {
    729      1.1   fvdl 			address = NULL;
    730      1.1   fvdl 			rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
    731      1.1   fvdl 			goto error;
    732      1.1   fvdl 		}
    733      1.1   fvdl 		port = htons(port);
    734      1.1   fvdl 		CLNT_CONTROL(client, CLGET_SVC_ADDR, (char *)&remote);
    735      1.1   fvdl 		if (((address = (struct netbuf *)
    736      1.1   fvdl 			malloc(sizeof (struct netbuf))) == NULL) ||
    737      1.1   fvdl 		    ((address->buf = (char *)
    738      1.1   fvdl 			malloc(remote.len)) == NULL)) {
    739      1.1   fvdl 			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
    740      1.1   fvdl 			clnt_geterr(client, &rpc_createerr.cf_error);
    741      1.1   fvdl 			if (address) {
    742      1.1   fvdl 				free(address);
    743      1.1   fvdl 				address = NULL;
    744      1.1   fvdl 			}
    745      1.1   fvdl 			goto error;
    746      1.1   fvdl 		}
    747      1.1   fvdl 		memcpy(address->buf, remote.buf, remote.len);
    748      1.1   fvdl 		memcpy(&((char *)address->buf)[sizeof (short)],
    749      1.1   fvdl 				(char *)&port, sizeof (short));
    750      1.1   fvdl 		address->len = address->maxlen = remote.len;
    751      1.1   fvdl 		goto done;
    752      1.1   fvdl 	}
    753      1.1   fvdl #endif
    754      1.1   fvdl 
    755      1.1   fvdl try_rpcbind:
    756      1.1   fvdl 	/*
    757      1.1   fvdl 	 * Now we try version 4 and then 3.
    758      1.1   fvdl 	 * We also send the remote system the address we used to
    759      1.1   fvdl 	 * contact it in case it can help to connect back with us
    760      1.1   fvdl 	 */
    761      1.1   fvdl 	parms.r_prog = program;
    762      1.1   fvdl 	parms.r_vers = version;
    763      1.1   fvdl 	parms.r_owner = (char *) &nullstring[0];	/* not needed; */
    764      1.1   fvdl 							/* just for xdring */
    765      1.1   fvdl 	parms.r_netid = nconf->nc_netid; /* not really needed */
    766      1.1   fvdl 
    767      1.1   fvdl 	/*
    768      1.1   fvdl 	 * If a COTS transport is being used, try getting address via CLTS
    769      1.1   fvdl 	 * transport.  This works only with version 4.
    770      1.1   fvdl 	 * NOTE: This is being done for all transports EXCEPT LOOPBACK
    771      1.1   fvdl 	 * because with loopback the cost to go to a COTS is same as
    772      1.1   fvdl 	 * the cost to go through CLTS, plus you get the advantage of
    773      1.1   fvdl 	 * finding out immediately if the local rpcbind process is dead.
    774      1.1   fvdl 	 */
    775      1.1   fvdl #if 1
    776      1.1   fvdl 	if ((nconf->nc_semantics == NC_TPI_COTS_ORD ||
    777      1.1   fvdl 			nconf->nc_semantics == NC_TPI_COTS) &&
    778      1.1   fvdl 	    (strcmp(nconf->nc_protofmly, NC_LOOPBACK) != 0)) {
    779      1.1   fvdl #else
    780      1.1   fvdl 	if (client != NULL) {
    781      1.1   fvdl 		CLNT_DESTROY(client);
    782      1.1   fvdl 		client = NULL;
    783      1.1   fvdl 	}
    784      1.1   fvdl 	if (nconf->nc_semantics == NC_TPI_CLTS) {
    785      1.1   fvdl #endif
    786      1.1   fvdl 		void *handle;
    787      1.1   fvdl 		struct netconfig *nconf_clts;
    788      1.1   fvdl 		rpcb_entry_list_ptr relp = NULL;
    789      1.1   fvdl 
    790      1.1   fvdl 		if (client == NULL) {
    791      1.1   fvdl 			/* This did not go through the above PORTMAP/TCP code */
    792      1.1   fvdl #if 1
    793      1.1   fvdl 			if ((handle = __rpc_setconf("datagram_v")) != NULL) {
    794      1.1   fvdl #else
    795      1.1   fvdl 			if ((handle = __rpc_setconf("circuit_v")) != NULL) {
    796      1.1   fvdl #endif
    797      1.1   fvdl 				while ((nconf_clts = __rpc_getconf(handle))
    798      1.1   fvdl 					!= NULL) {
    799      1.1   fvdl 					if (strcmp(nconf_clts->nc_protofmly,
    800      1.1   fvdl 						nconf->nc_protofmly) != 0) {
    801      1.1   fvdl 						continue;
    802      1.1   fvdl 					}
    803      1.1   fvdl 					client = getclnthandle(host, nconf_clts,
    804      1.1   fvdl 							&parms.r_addr);
    805      1.1   fvdl 					break;
    806      1.1   fvdl 				}
    807      1.1   fvdl 				__rpc_endconf(handle);
    808      1.1   fvdl 			}
    809      1.1   fvdl 			if (client == (CLIENT *)NULL)
    810      1.1   fvdl 				goto regular_rpcbind;	/* Go the regular way */
    811      1.1   fvdl 		} else {
    812      1.1   fvdl 			/* This is a UDP PORTMAP handle.  Change to version 4 */
    813      1.1   fvdl 			vers = RPCBVERS4;
    814      1.1   fvdl 			CLNT_CONTROL(client, CLSET_VERS, (char *)&vers);
    815      1.1   fvdl 		}
    816      1.1   fvdl 		/*
    817      1.1   fvdl 		 * We also send the remote system the address we used to
    818      1.1   fvdl 		 * contact it in case it can help it connect back with us
    819      1.1   fvdl 		 */
    820      1.1   fvdl 		if (parms.r_addr == NULL)
    821      1.1   fvdl 			parms.r_addr = (char *) &nullstring[0]; /* for XDRing */
    822      1.1   fvdl 		clnt_st = CLNT_CALL(client, RPCBPROC_GETADDRLIST,
    823      1.1   fvdl 				    (xdrproc_t) xdr_rpcb, (char *) &parms,
    824      1.1   fvdl 				    (xdrproc_t) xdr_rpcb_entry_list_ptr,
    825      1.1   fvdl 				    (char *) &relp, tottimeout);
    826      1.1   fvdl 		if (clnt_st == RPC_SUCCESS) {
    827      1.1   fvdl 			if ((address = got_entry(relp, nconf))) {
    828      1.1   fvdl 				xdr_free((xdrproc_t) xdr_rpcb_entry_list_ptr,
    829      1.1   fvdl 					(char *)&relp);
    830      1.1   fvdl 				goto done;
    831      1.1   fvdl 			}
    832      1.1   fvdl 			/* Entry not found for this transport */
    833      1.1   fvdl 			xdr_free((xdrproc_t) xdr_rpcb_entry_list_ptr,
    834      1.1   fvdl 				(char *)&relp);
    835      1.1   fvdl 			/*
    836      1.1   fvdl 			 * XXX: should have perhaps returned with error but
    837      1.1   fvdl 			 * since the remote machine might not always be able
    838      1.1   fvdl 			 * to send the address on all transports, we try the
    839      1.1   fvdl 			 * regular way with regular_rpcbind
    840      1.1   fvdl 			 */
    841      1.1   fvdl 			goto regular_rpcbind;
    842      1.1   fvdl 		} else if ((clnt_st == RPC_PROGVERSMISMATCH) ||
    843      1.1   fvdl 			(clnt_st == RPC_PROGUNAVAIL)) {
    844      1.1   fvdl 			start_vers = RPCBVERS;	/* Try version 3 now */
    845      1.1   fvdl 			goto regular_rpcbind; /* Try different versions */
    846      1.1   fvdl 		} else {
    847      1.1   fvdl 			rpc_createerr.cf_stat = RPC_PMAPFAILURE;
    848      1.1   fvdl 			clnt_geterr(client, &rpc_createerr.cf_error);
    849      1.1   fvdl 			goto error;
    850      1.1   fvdl 		}
    851      1.1   fvdl 	}
    852      1.1   fvdl 
    853      1.1   fvdl regular_rpcbind:
    854      1.1   fvdl 
    855      1.1   fvdl 	/* Now the same transport is to be used to get the address */
    856      1.1   fvdl #if 1
    857      1.1   fvdl 	if (client && ((nconf->nc_semantics == NC_TPI_COTS_ORD) ||
    858      1.1   fvdl 			(nconf->nc_semantics == NC_TPI_COTS))) {
    859      1.1   fvdl #else
    860      1.1   fvdl 	if (client && nconf->nc_semantics == NC_TPI_CLTS) {
    861      1.1   fvdl #endif
    862      1.1   fvdl 		/* A CLTS type of client - destroy it */
    863      1.1   fvdl 		CLNT_DESTROY(client);
    864      1.1   fvdl 		client = NULL;
    865      1.1   fvdl 	}
    866      1.1   fvdl 
    867      1.1   fvdl 	if (client == NULL) {
    868      1.1   fvdl 		client = getclnthandle(host, nconf, &parms.r_addr);
    869      1.1   fvdl 		if (client == NULL) {
    870      1.1   fvdl 			goto error;
    871      1.1   fvdl 		}
    872      1.1   fvdl 	}
    873      1.1   fvdl 	if (parms.r_addr == NULL)
    874      1.1   fvdl 		parms.r_addr = (char *) &nullstring[0];
    875      1.1   fvdl 
    876      1.1   fvdl 	/* First try from start_vers and then version 3 (RPCBVERS) */
    877      1.1   fvdl 	for (vers = start_vers;  vers >= RPCBVERS; vers--) {
    878      1.1   fvdl 		/* Set the version */
    879      1.1   fvdl 		CLNT_CONTROL(client, CLSET_VERS, (char *)&vers);
    880      1.1   fvdl 		clnt_st = CLNT_CALL(client, RPCBPROC_GETADDR,
    881      1.1   fvdl 				    (xdrproc_t) xdr_rpcb, (char *) &parms,
    882      1.1   fvdl 				    (xdrproc_t) xdr_wrapstring,
    883      1.1   fvdl 				    (char *) &ua, tottimeout);
    884      1.1   fvdl 		if (clnt_st == RPC_SUCCESS) {
    885      1.1   fvdl 			if ((ua == NULL) || (ua[0] == NULL)) {
    886      1.1   fvdl 				/* address unknown */
    887      1.1   fvdl 				rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
    888      1.1   fvdl 				goto error;
    889      1.1   fvdl 			}
    890      1.1   fvdl 			address = uaddr2taddr(nconf, ua);
    891      1.1   fvdl #ifdef ND_DEBUG
    892      1.1   fvdl 			fprintf(stderr, "\tRemote address is [%s]\n", ua);
    893      1.1   fvdl 			if (!address)
    894      1.1   fvdl 				fprintf(stderr,
    895      1.1   fvdl 					"\tCouldn't resolve remote address!\n");
    896      1.1   fvdl #endif
    897      1.1   fvdl 			xdr_free((xdrproc_t)xdr_wrapstring, (char *)&ua);
    898      1.1   fvdl 
    899      1.1   fvdl 			if (! address) {
    900      1.1   fvdl 				/* We don't know about your universal address */
    901      1.1   fvdl 				rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE;
    902      1.1   fvdl 				goto error;
    903      1.1   fvdl 			}
    904      1.1   fvdl 			CLNT_CONTROL(client, CLGET_SVC_ADDR, (char *)&servaddr);
    905      1.1   fvdl 			__rpc_fixup_addr(address, &servaddr);
    906      1.1   fvdl 			goto done;
    907      1.1   fvdl 		} else if (clnt_st == RPC_PROGVERSMISMATCH) {
    908      1.1   fvdl 			struct rpc_err rpcerr;
    909      1.1   fvdl 
    910      1.1   fvdl 			clnt_geterr(client, &rpcerr);
    911      1.1   fvdl 			if (rpcerr.re_vers.low > RPCBVERS4)
    912      1.1   fvdl 				goto error;  /* a new version, can't handle */
    913      1.1   fvdl 		} else if (clnt_st != RPC_PROGUNAVAIL) {
    914      1.1   fvdl 			/* Cant handle this error */
    915      1.1   fvdl 			rpc_createerr.cf_stat = clnt_st;
    916      1.1   fvdl 			clnt_geterr(client, &rpc_createerr.cf_error);
    917      1.1   fvdl 			goto error;
    918      1.1   fvdl 		}
    919      1.1   fvdl 	}
    920      1.1   fvdl 
    921      1.1   fvdl 	if ((address == NULL) || (address->len == 0)) {
    922      1.1   fvdl 		rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
    923      1.1   fvdl 		clnt_geterr(client, &rpc_createerr.cf_error);
    924      1.1   fvdl 	}
    925      1.1   fvdl 
    926      1.1   fvdl error:
    927      1.1   fvdl 	if (client) {
    928      1.1   fvdl 		CLNT_DESTROY(client);
    929      1.1   fvdl 		client = NULL;
    930      1.1   fvdl 	}
    931      1.1   fvdl done:
    932      1.1   fvdl 	if (nconf->nc_semantics != NC_TPI_CLTS) {
    933      1.1   fvdl 		/* This client is the connectionless one */
    934      1.1   fvdl 		if (client) {
    935      1.1   fvdl 			CLNT_DESTROY(client);
    936      1.1   fvdl 			client = NULL;
    937      1.1   fvdl 		}
    938      1.1   fvdl 	}
    939      1.1   fvdl 	if (clpp) {
    940      1.1   fvdl 		*clpp = client;
    941      1.1   fvdl 	} else if (client) {
    942      1.1   fvdl 		CLNT_DESTROY(client);
    943      1.1   fvdl 	}
    944      1.1   fvdl 	return (address);
    945      1.1   fvdl }
    946      1.1   fvdl 
    947      1.1   fvdl 
    948      1.1   fvdl /*
    949      1.1   fvdl  * Find the mapped address for program, version.
    950      1.1   fvdl  * Calls the rpcbind service remotely to do the lookup.
    951      1.1   fvdl  * Uses the transport specified in nconf.
    952      1.1   fvdl  * Returns FALSE (0) if no map exists, else returns 1.
    953      1.1   fvdl  *
    954      1.1   fvdl  * Assuming that the address is all properly allocated
    955      1.1   fvdl  */
    956      1.1   fvdl int
    957      1.1   fvdl rpcb_getaddr(program, version, nconf, address, host)
    958      1.1   fvdl 	rpcprog_t program;
    959      1.1   fvdl 	rpcvers_t version;
    960      1.1   fvdl 	const struct netconfig *nconf;
    961      1.1   fvdl 	struct netbuf *address;
    962      1.1   fvdl 	const char *host;
    963      1.1   fvdl {
    964      1.1   fvdl 	struct netbuf *na;
    965      1.1   fvdl 
    966      1.1   fvdl 	if ((na = __rpcb_findaddr(program, version, nconf,
    967      1.1   fvdl 				host, (CLIENT **) NULL)) == NULL)
    968      1.1   fvdl 		return (FALSE);
    969      1.1   fvdl 
    970      1.1   fvdl 	if (na->len > address->maxlen) {
    971      1.1   fvdl 		/* Too long address */
    972      1.1   fvdl 		free(na->buf);
    973      1.1   fvdl 		free(na);
    974      1.1   fvdl 		rpc_createerr.cf_stat = RPC_FAILED;
    975      1.1   fvdl 		return (FALSE);
    976      1.1   fvdl 	}
    977      1.1   fvdl 	memcpy(address->buf, na->buf, (int)na->len);
    978      1.1   fvdl 	address->len = na->len;
    979      1.1   fvdl 	free(na->buf);
    980      1.1   fvdl 	free(na);
    981      1.1   fvdl 	return (TRUE);
    982      1.1   fvdl }
    983      1.1   fvdl 
    984      1.1   fvdl /*
    985      1.1   fvdl  * Get a copy of the current maps.
    986      1.1   fvdl  * Calls the rpcbind service remotely to get the maps.
    987      1.1   fvdl  *
    988      1.1   fvdl  * It returns only a list of the services
    989      1.1   fvdl  * It returns NULL on failure.
    990      1.1   fvdl  */
    991      1.1   fvdl rpcblist *
    992      1.1   fvdl rpcb_getmaps(nconf, host)
    993      1.1   fvdl 	const struct netconfig *nconf;
    994      1.1   fvdl 	const char *host;
    995      1.1   fvdl {
    996      1.1   fvdl 	rpcblist_ptr head = (rpcblist_ptr)NULL;
    997      1.1   fvdl 	register CLIENT *client;
    998      1.1   fvdl 	enum clnt_stat clnt_st;
    999  1.3.2.1   fvdl 	rpcvers_t vers = 0;
   1000      1.1   fvdl 
   1001      1.1   fvdl 	client = getclnthandle(host, nconf, (char **)NULL);
   1002      1.1   fvdl 	if (client == (CLIENT *)NULL) {
   1003      1.1   fvdl 		return (head);
   1004      1.1   fvdl 	}
   1005      1.1   fvdl 	clnt_st = CLNT_CALL(client, RPCBPROC_DUMP,
   1006      1.1   fvdl 			(xdrproc_t) xdr_void, NULL,
   1007      1.1   fvdl 			(xdrproc_t) xdr_rpcblist_ptr,
   1008      1.1   fvdl 			(char *)&head, tottimeout);
   1009      1.1   fvdl 	if (clnt_st == RPC_SUCCESS)
   1010      1.1   fvdl 		goto done;
   1011      1.1   fvdl 
   1012      1.1   fvdl 	if ((clnt_st != RPC_PROGVERSMISMATCH) &&
   1013      1.1   fvdl 		    (clnt_st != RPC_PROGUNAVAIL)) {
   1014      1.1   fvdl 		rpc_createerr.cf_stat = RPC_RPCBFAILURE;
   1015      1.1   fvdl 		clnt_geterr(client, &rpc_createerr.cf_error);
   1016      1.1   fvdl 		goto done;
   1017      1.1   fvdl 	}
   1018      1.1   fvdl 
   1019      1.1   fvdl 	/* fall back to earlier version */
   1020      1.1   fvdl 	CLNT_CONTROL(client, CLGET_VERS, (char *)&vers);
   1021      1.1   fvdl 	if (vers == RPCBVERS4) {
   1022      1.1   fvdl 		vers = RPCBVERS;
   1023      1.1   fvdl 		CLNT_CONTROL(client, CLSET_VERS, (char *)&vers);
   1024      1.1   fvdl 		if (CLNT_CALL(client, RPCBPROC_DUMP,
   1025      1.1   fvdl 			(xdrproc_t) xdr_void,
   1026      1.1   fvdl 			(char *) NULL, (xdrproc_t) xdr_rpcblist_ptr,
   1027      1.1   fvdl 			(char *)&head, tottimeout) == RPC_SUCCESS)
   1028      1.1   fvdl 				goto done;
   1029      1.1   fvdl 	}
   1030      1.1   fvdl 	rpc_createerr.cf_stat = RPC_RPCBFAILURE;
   1031      1.1   fvdl 	clnt_geterr(client, &rpc_createerr.cf_error);
   1032      1.1   fvdl 
   1033      1.1   fvdl done:
   1034      1.1   fvdl 	CLNT_DESTROY(client);
   1035      1.1   fvdl 	return (head);
   1036      1.1   fvdl }
   1037      1.1   fvdl 
   1038      1.1   fvdl /*
   1039      1.1   fvdl  * rpcbinder remote-call-service interface.
   1040      1.1   fvdl  * This routine is used to call the rpcbind remote call service
   1041      1.1   fvdl  * which will look up a service program in the address maps, and then
   1042      1.1   fvdl  * remotely call that routine with the given parameters. This allows
   1043      1.1   fvdl  * programs to do a lookup and call in one step.
   1044      1.1   fvdl */
   1045      1.1   fvdl enum clnt_stat
   1046      1.1   fvdl rpcb_rmtcall(nconf, host, prog, vers, proc, xdrargs, argsp,
   1047      1.1   fvdl 		xdrres, resp, tout, addr_ptr)
   1048      1.1   fvdl 	const struct netconfig *nconf;	/* Netconfig structure */
   1049      1.1   fvdl 	const char *host;			/* Remote host name */
   1050      1.1   fvdl 	rpcprog_t prog;
   1051      1.1   fvdl 	rpcvers_t vers;
   1052      1.1   fvdl 	rpcproc_t proc;			/* Remote proc identifiers */
   1053      1.1   fvdl 	xdrproc_t xdrargs, xdrres;	/* XDR routines */
   1054      1.1   fvdl 	caddr_t argsp, resp;		/* Argument and Result */
   1055      1.1   fvdl 	struct timeval tout;		/* Timeout value for this call */
   1056      1.1   fvdl 	const struct netbuf *addr_ptr;	/* Preallocated netbuf address */
   1057      1.1   fvdl {
   1058      1.1   fvdl 	register CLIENT *client;
   1059      1.1   fvdl 	enum clnt_stat stat;
   1060      1.1   fvdl 	struct r_rpcb_rmtcallargs a;
   1061      1.1   fvdl 	struct r_rpcb_rmtcallres r;
   1062  1.3.2.1   fvdl 	rpcvers_t rpcb_vers;
   1063      1.1   fvdl 
   1064      1.1   fvdl 
   1065      1.1   fvdl 	client = getclnthandle(host, nconf, (char **)NULL);
   1066      1.1   fvdl 	if (client == (CLIENT *)NULL) {
   1067      1.1   fvdl 		return (RPC_FAILED);
   1068      1.1   fvdl 	}
   1069      1.1   fvdl 	CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)&rmttimeout);
   1070      1.1   fvdl 	a.prog = prog;
   1071      1.1   fvdl 	a.vers = vers;
   1072      1.1   fvdl 	a.proc = proc;
   1073      1.1   fvdl 	a.args.args_val = argsp;
   1074      1.1   fvdl 	a.xdr_args = xdrargs;
   1075      1.1   fvdl 	r.addr = NULL;
   1076      1.1   fvdl 	r.results.results_val = resp;
   1077      1.1   fvdl 	r.xdr_res = xdrres;
   1078      1.1   fvdl 
   1079      1.1   fvdl 	for (rpcb_vers = RPCBVERS4; rpcb_vers >= RPCBVERS; rpcb_vers--) {
   1080      1.1   fvdl 		CLNT_CONTROL(client, CLSET_VERS, (char *)&rpcb_vers);
   1081      1.1   fvdl 		stat = CLNT_CALL(client, RPCBPROC_CALLIT,
   1082      1.1   fvdl 			(xdrproc_t) xdr_rpcb_rmtcallargs, (char *)&a,
   1083      1.1   fvdl 			(xdrproc_t) xdr_rpcb_rmtcallres, (char *)&r, tout);
   1084      1.1   fvdl 		if ((stat == RPC_SUCCESS) && (addr_ptr != NULL)) {
   1085      1.1   fvdl 			struct netbuf *na;
   1086      1.1   fvdl 
   1087      1.1   fvdl 			na = uaddr2taddr((struct netconfig *) nconf, r.addr);
   1088      1.1   fvdl 			if (! na) {
   1089      1.1   fvdl 				stat = RPC_N2AXLATEFAILURE;
   1090      1.1   fvdl 				((struct netbuf *) addr_ptr)->len = 0;
   1091      1.1   fvdl 				goto error;
   1092      1.1   fvdl 			}
   1093      1.1   fvdl 			if (na->len > addr_ptr->maxlen) {
   1094      1.1   fvdl 				/* Too long address */
   1095      1.1   fvdl 				stat = RPC_FAILED; /* XXX A better error no */
   1096      1.1   fvdl 				free(na->buf);
   1097      1.1   fvdl 				free(na);
   1098      1.1   fvdl 				((struct netbuf *) addr_ptr)->len = 0;
   1099      1.1   fvdl 				goto error;
   1100      1.1   fvdl 			}
   1101      1.1   fvdl 			memcpy(addr_ptr->buf, na->buf, (int)na->len);
   1102      1.1   fvdl 			((struct netbuf *)addr_ptr)->len = na->len;
   1103      1.1   fvdl 			free(na->buf);
   1104      1.1   fvdl 			free(na);
   1105      1.1   fvdl 			break;
   1106      1.1   fvdl 		} else if ((stat != RPC_PROGVERSMISMATCH) &&
   1107      1.1   fvdl 			    (stat != RPC_PROGUNAVAIL)) {
   1108      1.1   fvdl 			goto error;
   1109      1.1   fvdl 		}
   1110      1.1   fvdl 	}
   1111      1.1   fvdl error:
   1112      1.1   fvdl 	CLNT_DESTROY(client);
   1113      1.1   fvdl 	if (r.addr)
   1114      1.1   fvdl 		xdr_free((xdrproc_t) xdr_wrapstring, (char *)&r.addr);
   1115      1.1   fvdl 	return (stat);
   1116      1.1   fvdl }
   1117      1.1   fvdl 
   1118      1.1   fvdl /*
   1119      1.1   fvdl  * Gets the time on the remote host.
   1120      1.1   fvdl  * Returns 1 if succeeds else 0.
   1121      1.1   fvdl  */
   1122      1.1   fvdl bool_t
   1123      1.1   fvdl rpcb_gettime(host, timep)
   1124      1.1   fvdl 	const char *host;
   1125      1.1   fvdl 	time_t *timep;
   1126      1.1   fvdl {
   1127      1.1   fvdl 	CLIENT *client = NULL;
   1128      1.1   fvdl 	void *handle;
   1129      1.1   fvdl 	struct netconfig *nconf;
   1130  1.3.2.1   fvdl 	rpcvers_t vers;
   1131      1.1   fvdl 	enum clnt_stat st;
   1132      1.1   fvdl 
   1133      1.1   fvdl 
   1134      1.1   fvdl 	if ((host == NULL) || (host[0] == NULL)) {
   1135      1.1   fvdl 		time(timep);
   1136      1.1   fvdl 		return (TRUE);
   1137      1.1   fvdl 	}
   1138      1.1   fvdl 
   1139      1.1   fvdl 	if ((handle = __rpc_setconf("netpath")) == NULL) {
   1140      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
   1141      1.1   fvdl 		return (FALSE);
   1142      1.1   fvdl 	}
   1143      1.1   fvdl 	rpc_createerr.cf_stat = RPC_SUCCESS;
   1144      1.1   fvdl 	while (client == (CLIENT *)NULL) {
   1145      1.1   fvdl 		if ((nconf = __rpc_getconf(handle)) == NULL) {
   1146      1.1   fvdl 			if (rpc_createerr.cf_stat == RPC_SUCCESS)
   1147      1.1   fvdl 				rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
   1148      1.1   fvdl 			break;
   1149      1.1   fvdl 		}
   1150      1.1   fvdl 		client = getclnthandle(host, nconf, (char **)NULL);
   1151      1.1   fvdl 		if (client)
   1152      1.1   fvdl 			break;
   1153      1.1   fvdl 	}
   1154      1.1   fvdl 	__rpc_endconf(handle);
   1155      1.1   fvdl 	if (client == (CLIENT *) NULL) {
   1156      1.1   fvdl 		return (FALSE);
   1157      1.1   fvdl 	}
   1158      1.1   fvdl 
   1159      1.1   fvdl 	st = CLNT_CALL(client, RPCBPROC_GETTIME,
   1160      1.1   fvdl 		(xdrproc_t) xdr_void, (char *)NULL,
   1161      1.1   fvdl 		(xdrproc_t) xdr_int, (char *)timep, tottimeout);
   1162      1.1   fvdl 
   1163      1.1   fvdl 	if ((st == RPC_PROGVERSMISMATCH) || (st == RPC_PROGUNAVAIL)) {
   1164      1.1   fvdl 		CLNT_CONTROL(client, CLGET_VERS, (char *)&vers);
   1165      1.1   fvdl 		if (vers == RPCBVERS4) {
   1166      1.1   fvdl 			/* fall back to earlier version */
   1167      1.1   fvdl 			vers = RPCBVERS;
   1168      1.1   fvdl 			CLNT_CONTROL(client, CLSET_VERS, (char *)&vers);
   1169      1.1   fvdl 			st = CLNT_CALL(client, RPCBPROC_GETTIME,
   1170      1.1   fvdl 				(xdrproc_t) xdr_void, (char *)NULL,
   1171      1.1   fvdl 				(xdrproc_t) xdr_int, (char *) timep,
   1172      1.1   fvdl 				tottimeout);
   1173      1.1   fvdl 		}
   1174      1.1   fvdl 	}
   1175      1.1   fvdl 	CLNT_DESTROY(client);
   1176      1.1   fvdl 	return (st == RPC_SUCCESS? TRUE: FALSE);
   1177      1.1   fvdl }
   1178      1.1   fvdl 
   1179      1.1   fvdl /*
   1180      1.1   fvdl  * Converts taddr to universal address.  This routine should never
   1181      1.1   fvdl  * really be called because local n2a libraries are always provided.
   1182      1.1   fvdl  */
   1183      1.1   fvdl char *
   1184      1.1   fvdl rpcb_taddr2uaddr(nconf, taddr)
   1185      1.1   fvdl 	struct netconfig *nconf;
   1186      1.1   fvdl 	struct netbuf *taddr;
   1187      1.1   fvdl {
   1188      1.1   fvdl 	CLIENT *client;
   1189      1.1   fvdl 	char *uaddr = NULL;
   1190      1.1   fvdl 
   1191      1.1   fvdl 
   1192      1.1   fvdl 	/* parameter checking */
   1193      1.1   fvdl 	if (nconf == (struct netconfig *)NULL) {
   1194      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
   1195      1.1   fvdl 		return (NULL);
   1196      1.1   fvdl 	}
   1197      1.1   fvdl 	if (taddr == NULL) {
   1198      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
   1199      1.1   fvdl 		return (NULL);
   1200      1.1   fvdl 	}
   1201      1.1   fvdl 	client = local_rpcb();
   1202      1.1   fvdl 	if (! client) {
   1203      1.1   fvdl 		return (NULL);
   1204      1.1   fvdl 	}
   1205      1.1   fvdl 
   1206      1.1   fvdl 	CLNT_CALL(client, RPCBPROC_TADDR2UADDR, (xdrproc_t) xdr_netbuf,
   1207      1.1   fvdl 		(char *)taddr, (xdrproc_t) xdr_wrapstring, (char *)&uaddr,
   1208      1.1   fvdl 		tottimeout);
   1209      1.1   fvdl 	CLNT_DESTROY(client);
   1210      1.1   fvdl 	return (uaddr);
   1211      1.1   fvdl }
   1212      1.1   fvdl 
   1213      1.1   fvdl /*
   1214      1.1   fvdl  * Converts universal address to netbuf.  This routine should never
   1215      1.1   fvdl  * really be called because local n2a libraries are always provided.
   1216      1.1   fvdl  */
   1217      1.1   fvdl struct netbuf *
   1218      1.1   fvdl rpcb_uaddr2taddr(nconf, uaddr)
   1219      1.1   fvdl 	struct netconfig *nconf;
   1220      1.1   fvdl 	char *uaddr;
   1221      1.1   fvdl {
   1222      1.1   fvdl 	CLIENT *client;
   1223      1.1   fvdl 	struct netbuf *taddr;
   1224      1.1   fvdl 
   1225      1.1   fvdl 
   1226      1.1   fvdl 	/* parameter checking */
   1227      1.1   fvdl 	if (nconf == (struct netconfig *)NULL) {
   1228      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
   1229      1.1   fvdl 		return (NULL);
   1230      1.1   fvdl 	}
   1231      1.1   fvdl 	if (uaddr == NULL) {
   1232      1.1   fvdl 		rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
   1233      1.1   fvdl 		return (NULL);
   1234      1.1   fvdl 	}
   1235      1.1   fvdl 	client = local_rpcb();
   1236      1.1   fvdl 	if (! client) {
   1237      1.1   fvdl 		return (NULL);
   1238      1.1   fvdl 	}
   1239      1.1   fvdl 
   1240      1.1   fvdl 	taddr = (struct netbuf *)calloc(1, sizeof (struct netbuf));
   1241      1.1   fvdl 	if (taddr == NULL) {
   1242      1.1   fvdl 		CLNT_DESTROY(client);
   1243      1.1   fvdl 		return (NULL);
   1244      1.1   fvdl 	}
   1245      1.1   fvdl 	if (CLNT_CALL(client, RPCBPROC_UADDR2TADDR, (xdrproc_t) xdr_wrapstring,
   1246      1.1   fvdl 		(char *) &uaddr, (xdrproc_t) xdr_netbuf, (char *)taddr,
   1247      1.1   fvdl 		tottimeout) != RPC_SUCCESS) {
   1248      1.1   fvdl 		free(taddr);
   1249      1.1   fvdl 		taddr = NULL;
   1250      1.1   fvdl 	}
   1251      1.1   fvdl 	CLNT_DESTROY(client);
   1252      1.1   fvdl 	return (taddr);
   1253      1.1   fvdl }
   1254