pmap_clnt.c revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef PORTMAP
/*
* interface to pmap rpc service.
*/
#include "mt.h"
#include "rpc_mt.h"
#include <netdir.h>
#include <rpc/pmap_prot.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_rmt.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
int use_portmapper = 0;
/*
* Solaris hasn't trully supported local portmappers since Solaris 2.4.
*
* In Solaris 2.0 the portmapper was replaced with rpcbind. Essentially
* rpcbind implements version 3 of the portmapper protocol. (The last
* version of the portmapper protocol while it was still called
* portmap was version 2.) The rpcbind protocol provides a lot
* of improvements over the portmap protocol. (Like the ability
* to bind to non AF_INET transports like TLI and to unregister
* individual transport providers instead of entire serivices.)
*
* So in Solaris 2.0 the portmapper was replace with rpcbind, but it
* wasn't until Solaris 2.5 that all the local portmapper code was
* modified to assume that the local processes managing rpc services
* always supported the rpcbind protocol. When this happened all the
* local portmap registration code was enhanced to translated any
* portmapper requests into rpcbind requests. This is a fine assumption
* for Solaris where we always have control over the local
* portmapper/rpcbind service and we can make sure that it always
* understands the rpcbind protocol.
*
* But this is a problem for BrandZ. In BrandZ we don't have contol over
* what local portmapper is running. (Unless we want to replace it.)
* In the Linux case, current Linux distributions don't support the
* rpcbind protocol, instead they support the old portmapper protocol
* (verison 2.) So to allow Solaris services to register with the
* Linux portmapper (which we need to support to allow us to run the
* native NFS daemons) there are two things that need to be done.
*
* - The classic interfaces for registering services with the version 2
* portmapper is via pmap_set() and pmap_unset(). In Solaris 2.5 these
* functions were changed to translate portmap requests into rpcbind
* requests. These interfaces need to be enhanced so that if we're
* trying to register with a portmapper instead of rpcbind, we don't
* translate the requests to rpcbind requests.
*
* - Libnsl provides lots of interfaces to simplify the creation of rpc
* services (see rpc_svc_*). Internally, the interfaces all assume
* that the local process that manages rpc services support the rpcbind
* protocol. To avoid having to update all rpc services that use these
* functions to be portmapper aware, we need to enhance these functions
* to support the portmapper protocol in addition to rpcbind.
*
* To address both these requirements we've introduced three key functions.
*
* __pmap_set() - Registers services using the portmapper version 2
* protocol. (Behaves like the Pre-Solaris 2.5 pmap_set())
*
* __pmap_unset() - Unregisters services using the portmapper version 2
* protocol. (Behaves like the Pre-Solaris 2.5 pmap_unset())
*
* __use_portmapper() - Tells libnsl if the local system expects
* the portmapper protocol versus the rpcbind protocol.
*
* If an rpc program uses this interface to tell libnsl
* that it want's to use portmap based services instead of
* rpcbind based services, then libnsl will internally
* replace attempts to register services via rpcbind
* with portmap.
*/
static CLIENT *
{
struct sockaddr_in sa_local;
/* we only support tcp and udp */
return (NULL);
/* try connecting to the portmapper via udp */
/* try connecting to the portmapper via tcp */
return (NULL);
}
return (client);
}
void
__use_portmapper(int p)
{
use_portmapper = p;
}
/*
* Set a mapping between program, version and address.
* Calls the portmapper service to do the mapping.
*/
{
struct sockaddr_in *sa;
int socket = RPC_ANYSOCK;
/* address better be a sockaddr_in struct */
return (FALSE);
return (FALSE);
/* get a connection to the portmapper */
return (FALSE);
return (FALSE);
/* LINTED pointer cast */
/* initialize the portmapper request */
/* make the call */
return (rslt);
}
/*
* Remove the mapping between program, version and port.
* Calls the portmapper service remotely to do the un-mapping.
*/
{
int socket = RPC_ANYSOCK;
/* get a connection to the portmapper */
return (FALSE);
/* initialize the portmapper request */
/* make the call */
return (rslt);
}
/*
* Set a mapping between program, version and port.
* Calls the pmap service remotely to do the mapping.
*/
{
char buf[32];
return (FALSE);
if (!nconf)
return (FALSE);
if (!na) {
return (FALSE);
}
if (!use_portmapper)
else
return (rslt);
}
/*
* Remove the mapping between program, version and port.
* Calls the pmap service remotely to do the un-mapping.
*/
{
if (use_portmapper)
if (nconf) {
}
if (nconf) {
}
/*
* XXX: The call may still succeed even if only one of the
* calls succeeded. This was the best that could be
* done for backward compatibility.
*/
}
/*
* Find the mapped port for program, version.
* Calls the pmap service remotely to do the lookup.
* Returns 0 if no map exists.
*
* XXX: It talks only to the portmapper and not to the rpcbind
* service. There may be implementations out there which do not
* run portmapper as a part of rpcbind.
*/
{
} else if (port == 0) {
}
}
return (port);
}
/*
* Get a copy of the current port maps.
* Calls the pmap service remotely to do get the maps.
*/
struct pmaplist *
{
struct timeval minutetimeout;
minutetimeout.tv_usec = 0;
}
}
}
/*
* pmapper remote-call-service interface.
* This routine is used to call the pmapper remote call service
* which will look up a service program in the port 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 p_rmtcallargs a;
struct p_rmtcallres r;
} else {
stat = RPC_FAILED;
}
return (stat);
}
#endif /* PORTMAP */