/* $NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */12/*-3* SPDX-License-Identifier: BSD-3-Clause4*5* Copyright (c) 2009, Sun Microsystems, Inc.6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions are met:10* - Redistributions of source code must retain the above copyright notice,11* this list of conditions and the following disclaimer.12* - Redistributions in binary form must reproduce the above copyright notice,13* this list of conditions and the following disclaimer in the documentation14* and/or other materials provided with the distribution.15* - Neither the name of Sun Microsystems, Inc. nor the names of its16* contributors may be used to endorse or promote products derived17* from this software without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"20* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE23* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR24* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF25* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS26* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN27* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE29* POSSIBILITY OF SUCH DAMAGE.30*/3132/*33* pmap_clnt.c34* Client interface to pmap rpc service.35*36* Copyright (C) 1984, Sun Microsystems, Inc.37*/3839#include "namespace.h"40#include <sys/types.h>41#include <sys/stat.h>42#include <unistd.h>4344#include <rpc/rpc.h>45#include <rpc/pmap_prot.h>46#include <rpc/pmap_clnt.h>47#include <rpc/nettype.h>48#include <netinet/in.h>49#include "un-namespace.h"5051#include <stdio.h>52#include <stdlib.h>5354#include "rpc_com.h"5556bool_t57pmap_set(u_long program, u_long version, int protocol, int port)58{59bool_t rslt;60struct netbuf *na;61struct netconfig *nconf;62char buf[32];6364if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {65return (FALSE);66}67nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");68if (nconf == NULL) {69return (FALSE);70}71snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",72(((u_int32_t)port) >> 8) & 0xff, port & 0xff);73na = uaddr2taddr(nconf, buf);74if (na == NULL) {75freenetconfigent(nconf);76return (FALSE);77}78rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);79free(na);80freenetconfigent(nconf);81return (rslt);82}8384/*85* Remove the mapping between program, version and port.86* Calls the pmap service remotely to do the un-mapping.87*/88bool_t89pmap_unset(u_long program, u_long version)90{91struct netconfig *nconf;92bool_t udp_rslt = FALSE;93bool_t tcp_rslt = FALSE;9495nconf = __rpc_getconfip("udp");96if (nconf != NULL) {97udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,98nconf);99freenetconfigent(nconf);100}101nconf = __rpc_getconfip("tcp");102if (nconf != NULL) {103tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,104nconf);105freenetconfigent(nconf);106}107/*108* XXX: The call may still succeed even if only one of the109* calls succeeded. This was the best that could be110* done for backward compatibility.111*/112return (tcp_rslt || udp_rslt);113}114115116