2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Portions of this source code were derived from Berkeley 2N/A * 4.3 BSD under license from the Regents of the University of 2N/A * interface to rpcbind rpc service. 2N/A * The life time of a cached entry should not exceed 5 minutes 2N/A * since automountd attempts an unmount every 5 minutes. 2N/A * It is arbitrarily set a little lower (3 min = 180 sec) 2N/A * to reduce the time during which an entry is stale. 2N/A * This routine adjusts the timeout used for calls to the remote rpcbind. 2N/A * Also, this routine can be used to set the use of portmapper version 2 2N/A * only when doing rpc_broadcasts 2N/A * These are private routines that may not be provided in future releases. 2N/A * However because getclnthandle(), the only user of the cache functions, 2N/A * may do a delete_cache() operation if a check_cache() fails to return an 2N/A * address useful to clnt_tli_create(), we may as well use a mutex. 2N/A * As it turns out, if the cache lock is *not* a reader/writer lock, we will 2N/A * block all clnt_create's if we are trying to connect to a host that's down, 2N/A * since the lock will be held all during that time. 2N/A * The routines check_cache(), add_cache(), delete_cache() manage the 2N/A * cache of rpcbind addresses for (host, netid). 2N/A /* READ LOCK HELD ON ENTRY: rpcbaddr_cache_lock */ 2N/A /* WRITE LOCK HELD ON ENTRY: rpcbaddr_cache_lock */ 2N/A/* VARIABLES PROTECTED BY rpcbaddr_cache_lock: cptr */ 2N/A /* Free the last entry */ 2N/A * This routine will return a client handle that is connected to the 2N/A * rpcbind. Returns NULL on error and free's everything. 2N/A * Same as getclnthandle() except it takes an extra timeout argument. 2N/A * This is for bug 4049792: clnt_create_timed does not timeout. 2N/A * If tp is NULL, use default timeout to get a client handle. 2N/A/* VARIABLES PROTECTED BY rpcbaddr_cache_lock: ad_cache */ 2N/A /* Get the address of the rpcbind. Check cache first */ 2N/A * case where a client handle is created 2N/A * without a targaddr and the handle is 2N/A * requested with a targaddr 2N/A "_getclnthandle_timed: strdup " 2N/A * Assume this may be due to cache data being 2N/A /* XXX nas should perhaps be cached for better performance */ 2N/A * This routine will return a client handle that is connected to the local 2N/A * rpcbind. Returns NULL on error and free's everything. 2N/A/* VARIABLES PROTECTED BY loopnconf_lock: loopnconf */ 2N/A /* fails to open netconfig file */ 2N/A /* loopnconf is never freed */ 2N/A * Set a mapping between program, version and address. 2N/A * Calls the rpcbind service to do the mapping. 2N/A /* parameter checking */ 2N/A return (
FALSE);
/* no universal address */ 2N/A * Though uid is not being used directly, we still send it for 2N/A * completeness. For non-unix platforms, perhaps some other 2N/A * string or an empty string can be sent. 2N/A * Remove the mapping between program, version and netbuf address. 2N/A * Calls the rpcbind service to do the un-mapping. 2N/A * If netbuf is NULL, unset for all the transports, otherwise unset 2N/A * only for the given transport. 2N/A * From the merged list, find the appropriate entry 2N/A "\tCouldn't resolve remote address!\n");
2N/A * Quick check to see if rpcbind is up. Tries to connect over 2N/A * An internal function which optimizes rpcb_getaddr function. It also 2N/A * returns the client handle that it uses to contact the remote rpcbind. 2N/A * The algorithm used: If the transports is TCP or UDP, it first tries 2N/A * version 2 (portmap), 4 and then 3 (svr4). This order should be 2N/A * changed in the next OS release to 4, 2 and 3. We are assuming that by 2N/A * that time, version 4 would be available on many machines on the network. 2N/A * With this algorithm, we get performance as well as a plan for 2N/A * obsoleting version 2. 2N/A * For all other transports, the algorithm remains as 4 and then 3. 2N/A * XXX: Due to some problems with t_connect(), we do not reuse the same client 2N/A * handle for COTS cases and hence in these cases we do not return the 2N/A * client handle. This code will change if t_connect() ever 2N/A /* parameter checking */ 2N/A * Use default total timeout if no timeout is specified. 2N/A /* Try version 2 for TCP or UDP */ 2N/A * Try UDP only - there are some portmappers out 2N/A * there that use UDP only. 2N/A * The following to reinforce that you can 2N/A * only request for remote address through 2N/A * the same transport you are requesting. 2N/A * ie. requesting unversial address 2N/A * of IPv4 has to be carried through IPv4. 2N/A * Can't use IPv6 to send out the request. 2N/A * The mergeaddr in rpcbind can't handle 2N/A * here check the protocol family to 2N/A * be consistent with the request one 2N/A * Set version and retry timeout. 2N/A * Check if rpcbind is up. This prevents needless delays when 2N/A * accessing applications such as the keyserver while booting 2N/A * Now we try version 4 and then 3. 2N/A * We also send the remote system the address we used to 2N/A * contact it in case it can help to connect back with us 2N/A /* just for xdring */ 2N/A * If a COTS transport is being used, try getting address via CLTS 2N/A * transport. This works only with version 4. 2N/A /* This is a UDP PORTMAP handle. Change to version 4 */ 2N/A * We also send the remote system the address we used to 2N/A * contact it in case it can help it connect back with us 2N/A /* Entry not found for this transport */ 2N/A * XXX: should have perhaps returned with error but 2N/A * since the remote machine might not always be able 2N/A * to send the address on all transports, we try the 2N/A * regular way with regular_rpcbind 2N/A /* Now the same transport is to be used to get the address */ 2N/A /* A CLTS type of client - destroy it */ 2N/A /* First try from start_vers and then version 3 (RPCBVERS) */ 2N/A /* Set the version */ 2N/A /* address unknown */ 2N/A "\tCouldn't resolve remote address!\n");
2N/A /* We don't know about your universal address */ 2N/A goto error;
/* a new version, can't handle */ 2N/A /* Cant handle this error */ 2N/A /* This client is the connectionless one */ 2N/A * Find the mapped address for program, version. 2N/A * Calls the rpcbind service remotely to do the lookup. 2N/A * Uses the transport specified in nconf. 2N/A * Returns FALSE (0) if no map exists, else returns 1. 2N/A * Assuming that the address is all properly allocated 2N/A /* Too long address */ 2N/A * Get a copy of the current maps. 2N/A * Calls the rpcbind service remotely to get the maps. 2N/A * It returns only a list of the services 2N/A * It returns NULL on failure. 2N/A /* fall back to earlier version */ 2N/A * rpcbinder remote-call-service interface. 2N/A * This routine is used to call the rpcbind remote call service 2N/A * which will look up a service program in the address maps, and then 2N/A * remotely call that routine with the given parameters. This allows 2N/A * programs to do a lookup and call in one step. 2N/A /* Too long address */ 2N/A * Gets the time on the remote host. 2N/A * Returns 1 if succeeds else 0. 2N/A /* fall back to earlier version */ 2N/A * Converts taddr to universal address. This routine should never 2N/A * really be called because local n2a libraries are always provided. 2N/A /* parameter checking */ 2N/A * Converts universal address to netbuf. This routine should never 2N/A * really be called because local n2a libraries are always provided. 2N/A /* parameter checking */