1169689Skan/* $NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */ 2169689Skan 3169689Skan/*- 4169689Skan * Copyright (c) 2009, Sun Microsystems, Inc. 5169689Skan * All rights reserved. 6169689Skan * 7169689Skan * Redistribution and use in source and binary forms, with or without 8169689Skan * modification, are permitted provided that the following conditions are met: 9169689Skan * - Redistributions of source code must retain the above copyright notice, 10169689Skan * this list of conditions and the following disclaimer. 11169689Skan * - Redistributions in binary form must reproduce the above copyright notice, 12169689Skan * this list of conditions and the following disclaimer in the documentation 13169689Skan * and/or other materials provided with the distribution. 14169689Skan * - Neither the name of Sun Microsystems, Inc. nor the names of its 15169689Skan * contributors may be used to endorse or promote products derived 16169689Skan * from this software without specific prior written permission. 17169689Skan * 18169689Skan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19169689Skan * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20169689Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21169689Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22169689Skan * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23169689Skan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24169689Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25169689Skan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26169689Skan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27169689Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28169689Skan * POSSIBILITY OF SUCH DAMAGE. 29169689Skan */ 30169689Skan 31169689Skan#if defined(LIBC_SCCS) && !defined(lint) 32169689Skanstatic char *sccsid2 = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro"; 33169689Skanstatic char *sccsid = "@(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC"; 34169689Skan#endif 35169689Skan#include <sys/cdefs.h> 36169689Skan__FBSDID("$FreeBSD$"); 37169689Skan 38169689Skan/* 39169689Skan * pmap_clnt.c 40169689Skan * Client interface to pmap rpc service. 41169689Skan * 42169689Skan * Copyright (C) 1984, Sun Microsystems, Inc. 43169689Skan */ 44169689Skan 45169689Skan#include "namespace.h" 46169689Skan#include <sys/types.h> 47169689Skan#include <sys/stat.h> 48169689Skan#include <unistd.h> 49169689Skan 50169689Skan#include <rpc/rpc.h> 51169689Skan#include <rpc/pmap_prot.h> 52169689Skan#include <rpc/pmap_clnt.h> 53169689Skan#include <rpc/nettype.h> 54169689Skan#include <netinet/in.h> 55169689Skan#include "un-namespace.h" 56169689Skan 57169689Skan#include <stdio.h> 58169689Skan#include <stdlib.h> 59169689Skan 60169689Skan#include "rpc_com.h" 61169689Skan 62169689Skanbool_t 63169689Skanpmap_set(u_long program, u_long version, int protocol, int port) 64169689Skan{ 65169689Skan bool_t rslt; 66169689Skan struct netbuf *na; 67169689Skan struct netconfig *nconf; 68169689Skan char buf[32]; 69169689Skan 70169689Skan if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) { 71169689Skan return (FALSE); 72169689Skan } 73169689Skan nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp"); 74169689Skan if (nconf == NULL) { 75169689Skan return (FALSE); 76169689Skan } 77169689Skan snprintf(buf, sizeof buf, "0.0.0.0.%d.%d", 78169689Skan (((u_int32_t)port) >> 8) & 0xff, port & 0xff); 79169689Skan na = uaddr2taddr(nconf, buf); 80169689Skan if (na == NULL) { 81169689Skan freenetconfigent(nconf); 82169689Skan return (FALSE); 83169689Skan } 84169689Skan rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na); 85169689Skan free(na); 86169689Skan freenetconfigent(nconf); 87169689Skan return (rslt); 88169689Skan} 89169689Skan 90169689Skan/* 91169689Skan * Remove the mapping between program, version and port. 92169689Skan * Calls the pmap service remotely to do the un-mapping. 93169689Skan */ 94169689Skanbool_t 95169689Skanpmap_unset(u_long program, u_long version) 96169689Skan{ 97169689Skan struct netconfig *nconf; 98169689Skan bool_t udp_rslt = FALSE; 99169689Skan bool_t tcp_rslt = FALSE; 100169689Skan 101169689Skan nconf = __rpc_getconfip("udp"); 102169689Skan if (nconf != NULL) { 103169689Skan udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 104169689Skan nconf); 105169689Skan freenetconfigent(nconf); 106169689Skan } 107169689Skan nconf = __rpc_getconfip("tcp"); 108169689Skan if (nconf != NULL) { 109169689Skan tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 110169689Skan nconf); 111169689Skan freenetconfigent(nconf); 112169689Skan } 113169689Skan /* 114169689Skan * XXX: The call may still succeed even if only one of the 115169689Skan * calls succeeded. This was the best that could be 116169689Skan * done for backward compatibility. 117169689Skan */ 118252176Spfg return (tcp_rslt || udp_rslt); 119252176Spfg} 120252176Spfg