rpcb_clnt.c revision 2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley
* 4.3 BSD under license from the Regents of the University of
* California.
*/
/*
* interface to rpcbind rpc service.
*/
#include "mt.h"
#include "rpc_mt.h"
#include <assert.h>
#include <rpc/rpcb_prot.h>
#include <netconfig.h>
#include <netdir.h>
#include <syslog.h>
#ifdef PORTMAP
#include <rpc/pmap_prot.h>
#endif
#ifdef ND_DEBUG
#include <stdio.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static const char nullstring[] = "\000";
const struct timeval *);
struct timeval *);
/*
* The life time of a cached entry should not exceed 5 minutes
* since automountd attempts an unmount every 5 minutes.
* It is arbitrarily set a little lower (3 min = 180 sec)
* to reduce the time during which an entry is stale.
*/
#define CACHE_TTL 180
#define CACHESIZE 6
struct address_cache {
char *ac_host;
char *ac_netid;
char *ac_uaddr;
struct address_cache *ac_next;
};
static struct address_cache *front;
static int cachesize;
extern int lowvers;
extern int authdes_cachesz;
/*
* This routine adjusts the timeout used for calls to the remote rpcbind.
* Also, this routine can be used to set the use of portmapper version 2
* only when doing rpc_broadcasts
* These are private routines that may not be provided in future releases.
*/
{
switch (request) {
case CLCR_GET_RPCB_TIMEOUT:
break;
case CLCR_SET_RPCB_TIMEOUT:
break;
case CLCR_GET_LOWVERS:
break;
case CLCR_SET_LOWVERS:
break;
case CLCR_GET_RPCB_RMTTIME:
break;
case CLCR_SET_RPCB_RMTTIME:
break;
case CLCR_GET_CRED_CACHE_SZ:
*(int *)info = authdes_cachesz;
break;
case CLCR_SET_CRED_CACHE_SZ:
authdes_cachesz = *(int *)info;
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* However because getclnthandle(), the only user of the cache functions,
* may do a delete_cache() operation if a check_cache() fails to return an
* address useful to clnt_tli_create(), we may as well use a mutex.
*/
/*
* block all clnt_create's if we are trying to connect to a host that's down,
* since the lock will be held all during that time.
*/
extern rwlock_t rpcbaddr_cache_lock;
/*
* The routines check_cache(), add_cache(), delete_cache() manage the
* cache of rpcbind addresses for (host, netid).
*/
static struct address_cache *
{
struct address_cache *cptr;
/* READ LOCK HELD ON ENTRY: rpcbaddr_cache_lock */
#ifdef ND_DEBUG
#endif
return (cptr);
}
}
return (NULL);
}
static void
{
/* WRITE LOCK HELD ON ENTRY: rpcbaddr_cache_lock */
if (prevptr)
else
cachesize--;
break;
}
}
}
static void
{
if (!ad_cache) {
goto memerr;
}
goto memerr1;
}
goto memerr1;
}
#ifdef ND_DEBUG
#endif
/* VARIABLES PROTECTED BY rpcbaddr_cache_lock: cptr */
(void) rw_wrlock(&rpcbaddr_cache_lock);
cachesize++;
} else {
/* Free the last entry */
}
#ifdef ND_DEBUG
#endif
if (prevptr) {
} else {
}
}
(void) rw_unlock(&rpcbaddr_cache_lock);
return;
}
/*
* This routine will return a client handle that is connected to the
* rpcbind. Returns NULL on error and free's everything.
*/
static CLIENT *
{
}
/*
* Same as getclnthandle() except it takes an extra timeout argument.
* This is for bug 4049792: clnt_create_timed does not timeout.
*
* If tp is NULL, use default timeout to get a client handle.
*/
static CLIENT *
{
struct netbuf addr_to_delete;
struct nd_addrlist *nas;
struct nd_hostserv rpcbind_hs;
struct address_cache *ad_cache;
char *tmpaddr;
int neterr;
int j;
/* VARIABLES PROTECTED BY rpcbaddr_cache_lock: ad_cache */
/* Get the address of the rpcbind. Check cache first */
addr_to_delete.len = 0;
(void) rw_rdlock(&rpcbaddr_cache_lock);
if (targaddr) {
/*
* case where a client handle is created
* without a targaddr and the handle is
* requested with a targaddr
*/
"_getclnthandle_timed: strdup "
"failed.");
(void) rw_unlock(
return (NULL);
}
} else {
}
}
(void) rw_unlock(&rpcbaddr_cache_lock);
return (client);
}
(void) rw_unlock(&rpcbaddr_cache_lock);
return (NULL);
}
addr_to_delete.len = 0;
} else {
}
}
(void) rw_unlock(&rpcbaddr_cache_lock);
if (addr_to_delete.len != 0) {
/*
* Assume this may be due to cache data being
* outdated
*/
(void) rw_wrlock(&rpcbaddr_cache_lock);
(void) rw_unlock(&rpcbaddr_cache_lock);
}
#ifdef ND_DEBUG
#endif
else
return (NULL);
}
/* XXX nas should perhaps be cached for better performance */
#ifdef ND_DEBUG
{
int i;
char *ua;
}
#endif
if (client)
break;
}
#ifdef ND_DEBUG
if (!client) {
clnt_pcreateerror("rpcbind clnt interface");
}
#endif
if (client) {
if (targaddr) {
}
}
return (client);
}
/*
* This routine will return a client handle that is connected to the local
* rpcbind. Returns NULL on error and free's everything.
*/
static CLIENT *
local_rpcb(void)
{
static char *hostname;
extern mutex_t loopnconf_lock;
/* VARIABLES PROTECTED BY loopnconf_lock: loopnconf */
(void) mutex_lock(&loopnconf_lock);
void *nc_handle;
#else
#endif
(void) mutex_unlock(&loopnconf_lock);
return (NULL);
}
}
nc_handle = setnetconfig();
/* fails to open netconfig file */
(void) mutex_unlock(&loopnconf_lock);
return (NULL);
}
break;
}
}
(void) mutex_unlock(&loopnconf_lock);
return (NULL);
}
/* loopnconf is never freed */
(void) endnetconfig(nc_handle);
}
(void) mutex_unlock(&loopnconf_lock);
}
/*
* Set a mapping between program, version and address.
* Calls the rpcbind service to do the mapping.
*/
{
char uidbuf[32];
/* parameter checking */
return (FALSE);
}
return (FALSE);
}
client = local_rpcb();
if (!client)
return (FALSE);
return (FALSE); /* no universal address */
}
/*
* Though uid is not being used directly, we still send it for
* completeness. For non-unix platforms, perhaps some other
* string or an empty string can be sent.
*/
return (rslt);
}
/*
* Remove the mapping between program, version and netbuf address.
* Calls the rpcbind service to do the un-mapping.
* If netbuf is NULL, unset for all the transports, otherwise unset
* only for the given transport.
*/
{
char uidbuf[32];
client = local_rpcb();
if (!client)
return (FALSE);
if (nconf)
else
return (rslt);
}
/*
* From the merged list, find the appropriate entry
*/
static struct netbuf *
{
#ifdef ND_DEBUG
if (!na)
"\tCouldn't resolve remote address!\n");
#endif
break;
}
}
return (na);
}
/*
* Quick check to see if rpcbind is up. Tries to connect over
* local transport.
*/
__rpcbind_is_up(void)
{
int fd;
#else
#endif
return (TRUE);
return (TRUE);
return (TRUE);
}
return (TRUE);
}
uaddr[0] = '\0';
return (FALSE);
}
if (addr)
return (FALSE);
}
else
return (res);
}
/*
* An internal function which optimizes rpcb_getaddr function. It also
* returns the client handle that it uses to contact the remote rpcbind.
*
* The algorithm used: If the transports is TCP or UDP, it first tries
* version 2 (portmap), 4 and then 3 (svr4). This order should be
* changed in the next OS release to 4, 2 and 3. We are assuming that by
* that time, version 4 would be available on many machines on the network.
* With this algorithm, we get performance as well as a plan for
* obsoleting version 2.
*
* For all other transports, the algorithm remains as 4 and then 3.
*
* XXX: Due to some problems with t_connect(), we do not reuse the same client
* handle for COTS cases and hence in these cases we do not return the
* client handle. This code will change if t_connect() ever
* starts working properly. Also look under clnt_vc.c.
*/
struct netbuf *
{
/* parameter checking */
return (NULL);
}
/*
* Use default total timeout if no timeout is specified.
*/
tp = &tottimeout;
#ifdef PORTMAP
/* Try version 2 for TCP or UDP */
/*
* Try UDP only - there are some portmappers out
* there that use UDP only.
*/
void *handle;
return (NULL);
}
/*
* The following to reinforce that you can
* only request for remote address through
* the same transport you are requesting.
* ie. requesting unversial address
* of IPv4 has to be carried through IPv4.
* Can't use IPv6 to send out the request.
* The mergeaddr in rpcbind can't handle
* this.
*/
for (;;) {
== NULL) {
return (NULL);
}
/*
* here check the protocol family to
* be consistent with the request one
*/
break;
}
} else {
}
return (NULL);
/*
* Set version and retry timeout.
*/
*tp);
if (clnt_st != RPC_SUCCESS) {
if ((clnt_st == RPC_PROGVERSMISMATCH) ||
(clnt_st == RPC_PROGUNAVAIL))
goto try_rpcbind; /* Try different versions */
goto error;
} else if (port == 0) {
goto error;
}
if (address) {
}
goto error;
}
sizeof (short));
goto done;
}
#endif
/*
* Check if rpcbind is up. This prevents needless delays when
* accessing applications such as the keyserver while booting
* disklessly.
*/
if (!__rpcbind_is_up()) {
goto error;
}
}
/*
* Now we try version 4 and then 3.
* We also send the remote system the address we used to
* contact it in case it can help to connect back with us
*/
/* just for xdring */
/*
* If a COTS transport is being used, try getting address via CLTS
* transport. This works only with version 4.
*/
void *handle;
struct netconfig *nconf_clts;
!= NULL) {
nconf->nc_protofmly) != 0) {
continue;
}
tp);
break;
}
}
goto regular_rpcbind; /* Go the regular way */
} else {
/* This is a UDP PORTMAP handle. Change to version 4 */
}
/*
* We also send the remote system the address we used to
* contact it in case it can help it connect back with us
*/
"strdup failed.");
goto error;
}
}
if (clnt_st == RPC_SUCCESS) {
(char *)&relp);
goto done;
}
/* Entry not found for this transport */
(char *)&relp);
/*
* XXX: should have perhaps returned with error but
* since the remote machine might not always be able
* to send the address on all transports, we try the
* regular way with regular_rpcbind
*/
goto regular_rpcbind;
} else if ((clnt_st == RPC_PROGVERSMISMATCH) ||
(clnt_st == RPC_PROGUNAVAIL)) {
goto regular_rpcbind; /* Try different versions */
} else {
goto error;
}
}
/* Now the same transport is to be used to get the address */
/* A CLTS type of client - destroy it */
}
goto error;
}
}
"strdup failed.");
goto error;
}
}
/* First try from start_vers and then version 3 (RPCBVERS) */
/* Set the version */
if (clnt_st == RPC_SUCCESS) {
/* address unknown */
goto error;
}
#ifdef ND_DEBUG
if (!address)
"\tCouldn't resolve remote address!\n");
#endif
if (!address) {
/* We don't know about your universal address */
goto error;
}
goto done;
}
if (clnt_st == RPC_PROGVERSMISMATCH) {
goto error; /* a new version, can't handle */
} else if (clnt_st != RPC_PROGUNAVAIL) {
/* Cant handle this error */
goto error;
}
}
}
if (client) {
}
done:
/* This client is the connectionless one */
if (client) {
}
}
if (clpp) {
} else if (client) {
}
return (address);
}
/*
* Find the mapped address for program, version.
* Calls the rpcbind service remotely to do the lookup.
* Uses the transport specified in nconf.
* Returns FALSE (0) if no map exists, else returns 1.
*
* Assuming that the address is all properly allocated
*/
int
{
return (FALSE);
/* Too long address */
return (FALSE);
}
return (TRUE);
}
/*
* Get a copy of the current maps.
* Calls the rpcbind service remotely to get the maps.
*
* It returns only a list of the services
* It returns NULL on failure.
*/
rpcblist *
{
int vers = 0;
return (NULL);
(char *)&head, tottimeout);
if (clnt_st == RPC_SUCCESS)
goto done;
if ((clnt_st != RPC_PROGVERSMISMATCH) &&
(clnt_st != RPC_PROGUNAVAIL)) {
goto done;
}
/* fall back to earlier version */
goto done;
}
done:
return (head);
}
/*
* rpcbinder remote-call-service interface.
* This routine is used to call the rpcbind remote call service
* which will look up a service program in the address maps, and then
* remotely call that routine with the given parameters. This allows
* programs to do a lookup and call in one step.
*/
enum clnt_stat
{
struct r_rpcb_rmtcallargs a;
struct r_rpcb_rmtcallres r;
int rpcb_vers;
return (RPC_FAILED);
(xdrproc_t)xdr_rpcb_rmtcallargs, (char *)&a,
if (!na) {
goto error;
}
/* Too long address */
goto error;
}
break;
}
if ((stat != RPC_PROGVERSMISMATCH) &&
(stat != RPC_PROGUNAVAIL))
goto error;
}
if (r.addr)
return (stat);
}
/*
* Gets the time on the remote host.
* Returns 1 if succeeds else 0.
*/
{
void *handle;
int vers;
return (TRUE);
}
return (FALSE);
}
break;
}
if (client)
break;
}
return (FALSE);
/* fall back to earlier version */
}
}
}
/*
* Converts taddr to universal address. This routine should never
* really be called because local n2a libraries are always provided.
*/
char *
{
/* parameter checking */
return (NULL);
}
return (NULL);
}
client = local_rpcb();
if (!client)
return (NULL);
return (uaddr);
}
/*
* Converts universal address to netbuf. This routine should never
* really be called because local n2a libraries are always provided.
*/
struct netbuf *
{
/* parameter checking */
return (NULL);
}
return (NULL);
}
client = local_rpcb();
if (!client)
return (NULL);
return (NULL);
}
tottimeout) != RPC_SUCCESS) {
}
return (taddr);
}