174462Salfred/*	$NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $	*/
274462Salfred
3261046Smav/*-
4261046Smav * Copyright (c) 2009, Sun Microsystems, Inc.
5261046Smav * All rights reserved.
68870Srgrimes *
7261046Smav * Redistribution and use in source and binary forms, with or without
8261046Smav * modification, are permitted provided that the following conditions are met:
9261046Smav * - Redistributions of source code must retain the above copyright notice,
10261046Smav *   this list of conditions and the following disclaimer.
11261046Smav * - Redistributions in binary form must reproduce the above copyright notice,
12261046Smav *   this list of conditions and the following disclaimer in the documentation
13261046Smav *   and/or other materials provided with the distribution.
14261046Smav * - Neither the name of Sun Microsystems, Inc. nor the names of its
15261046Smav *   contributors may be used to endorse or promote products derived
16261046Smav *   from this software without specific prior written permission.
17261046Smav *
18261046Smav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19261046Smav * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20261046Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21261046Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22261046Smav * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23261046Smav * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24261046Smav * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25261046Smav * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26261046Smav * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27261046Smav * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28261046Smav * POSSIBILITY OF SUCH DAMAGE.
291901Swollman */
301901Swollman
311901Swollman#if defined(LIBC_SCCS) && !defined(lint)
32136581Sobrienstatic char *sccsid2 = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
3392990Sobrienstatic char *sccsid = "@(#)pmap_clnt.c	2.2 88/08/01 4.0 RPCSRC";
341901Swollman#endif
3592990Sobrien#include <sys/cdefs.h>
3692990Sobrien__FBSDID("$FreeBSD$");
371901Swollman
381901Swollman/*
391901Swollman * pmap_clnt.c
401901Swollman * Client interface to pmap rpc service.
411901Swollman *
421901Swollman * Copyright (C) 1984, Sun Microsystems, Inc.
431901Swollman */
441901Swollman
4571579Sdeischen#include "namespace.h"
4626221Swpaul#include <sys/types.h>
4726221Swpaul#include <sys/stat.h>
4811666Sphk#include <unistd.h>
4974462Salfred
501901Swollman#include <rpc/rpc.h>
511901Swollman#include <rpc/pmap_prot.h>
521901Swollman#include <rpc/pmap_clnt.h>
5374462Salfred#include <rpc/nettype.h>
5421078Speter#include <netinet/in.h>
5571579Sdeischen#include "un-namespace.h"
561901Swollman
5774462Salfred#include <stdio.h>
5874462Salfred#include <stdlib.h>
591901Swollman
6074462Salfred#include "rpc_com.h"
611901Swollman
621901Swollmanbool_t
6374462Salfredpmap_set(u_long program, u_long version, int protocol, int port)
641901Swollman{
651901Swollman	bool_t rslt;
6674462Salfred	struct netbuf *na;
6774462Salfred	struct netconfig *nconf;
6874462Salfred	char buf[32];
691901Swollman
7074462Salfred	if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {
7174462Salfred		return (FALSE);
7226221Swpaul	}
7374462Salfred	nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");
7474462Salfred	if (nconf == NULL) {
751901Swollman		return (FALSE);
7674462Salfred	}
7774462Salfred	snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",
7874462Salfred	    (((u_int32_t)port) >> 8) & 0xff, port & 0xff);
7974462Salfred	na = uaddr2taddr(nconf, buf);
8074462Salfred	if (na == NULL) {
8174462Salfred		freenetconfigent(nconf);
821901Swollman		return (FALSE);
831901Swollman	}
8474462Salfred	rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);
8574462Salfred	free(na);
8674462Salfred	freenetconfigent(nconf);
871901Swollman	return (rslt);
881901Swollman}
891901Swollman
901901Swollman/*
9174462Salfred * Remove the mapping between program, version and port.
921901Swollman * Calls the pmap service remotely to do the un-mapping.
931901Swollman */
941901Swollmanbool_t
9574462Salfredpmap_unset(u_long program, u_long version)
961901Swollman{
9774462Salfred	struct netconfig *nconf;
9874462Salfred	bool_t udp_rslt = FALSE;
9974462Salfred	bool_t tcp_rslt = FALSE;
1001901Swollman
10174462Salfred	nconf = __rpc_getconfip("udp");
10274462Salfred	if (nconf != NULL) {
10374462Salfred		udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
10474462Salfred		    nconf);
10574462Salfred		freenetconfigent(nconf);
10674462Salfred	}
10774462Salfred	nconf = __rpc_getconfip("tcp");
10874462Salfred	if (nconf != NULL) {
10974462Salfred		tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
11074462Salfred		    nconf);
11174462Salfred		freenetconfigent(nconf);
11274462Salfred	}
11326221Swpaul	/*
11474462Salfred	 * XXX: The call may still succeed even if only one of the
11574462Salfred	 * calls succeeded.  This was the best that could be
11674462Salfred	 * done for backward compatibility.
11726221Swpaul	 */
11874462Salfred	return (tcp_rslt || udp_rslt);
1191901Swollman}
120