rpcb_clnt.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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) 1986-1991,1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* interface to rpcbind rpc service.
*/
#include <rpc/rpcb_prot.h>
#include <netconfig.h>
#include <netdir.h>
#ifdef PORTMAP
#include <rpc/pmap_prot.h>
#endif
#ifdef ND_DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <tiuser.h>
static char nullstring[] = "\000";
#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;
/*
* This routine adjusts the timeout used for calls to the remote rpcbind.
* This is a private routine that may not be provided in future releases.
*/
{
switch (request) {
case CLCR_GET_RPCB_TIMEOUT:
break;
case CLCR_SET_RPCB_TIMEOUT:
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* 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;
trace1(TR_check_cache, 0);
#ifdef ND_DEBUG
#endif
return (cptr);
}
}
return ((struct address_cache *)NULL);
}
static void
{
trace1(TR_delete_cache, 0);
if (prevptr)
else
cachesize--;
break;
}
}
}
static void
{
trace1(TR_add_cache, 0);
ad_cache = (struct address_cache *)
malloc(sizeof (struct address_cache));
if (!ad_cache) {
return;
}
return;
}
return;
}
#ifdef ND_DEBUG
#endif
cachesize++;
} else {
/* Free the last entry */
}
#ifdef ND_DEBUG
#endif
if (prevptr) {
} else {
}
}
}
/*
* This routine will return a client handle that is connected to the
* rpcbind. Returns NULL on error and free's everything.
*/
static CLIENT *
{
struct nd_addrlist *nas;
struct nd_hostserv rpcbind_hs;
struct address_cache *ad_cache;
char *tmpaddr;
trace1(TR_getclnthandle, 0);
/* Get the address of the rpcbind. Check cache first */
RPCBVERS4, 0, 0);
if (targaddr)
return (client);
}
/*
* Assume this may be due to cache data being
* outdated
*/
}
#ifdef ND_DEBUG
#endif
}
/* XXX nas should perhaps be cached for better performance */
#ifdef ND_DEBUG
{
char *ua;
}
#endif
#ifdef ND_DEBUG
{
int i;
}
#endif
RPCBVERS4, 0, 0);
#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 *
{
static char *hostname;
trace1(TR_local_rpcb, 0);
void *nc_handle;
}
}
nc_handle = setnetconfig();
/* fails to open netconfig file */
return (NULL);
}
break;
}
}
return (NULL);
}
/* loopnconf is never freed */
(void) endnetconfig(nc_handle);
}
return (client);
}
/*
* 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);
}
*) address); /* convert to universal */
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 *
{
trace1(TR_got_entry, 0);
#ifdef ND_DEBUG
if (!na)
"\tCouldn't resolve remote address!\n");
#endif
break;
}
}
return (na);
}
/*
* 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);
}
#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);
}
return (NULL);
}
} else {
}
return (NULL);
}
/* Set the version */
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;
}
(char *)&port, sizeof (short));
goto done;
}
#endif
/*
* 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
*/
/*
* 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;
}
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
*/
(char *)&relp, tottimeout);
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;
}
/* First try from start_vers and then version 3 (RPCBVERS) */
/* Set the version */
(char *)&ua, tottimeout);
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;
} else 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;
trace1(TR_rpcb_getmaps, 0);
(char **)NULL);
return (head);
}
(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;
(char **)NULL);
return (RPC_FAILED);
}
(xdrproc_t)xdr_rpcb_rmtcallargs, (char *)&a,
if (! na) {
goto error;
}
/* Too long address */
goto error;
}
break;
} else 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;
trace1(TR_rpcb_gettime, 0);
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);
}