18360efbdSAlfred Perlstein /* $NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */ 28360efbdSAlfred Perlstein 32e322d37SHiroki Sato /*- 4*8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 5*8a16b7a1SPedro F. Giffuni * 62e322d37SHiroki Sato * Copyright (c) 2009, Sun Microsystems, Inc. 72e322d37SHiroki Sato * All rights reserved. 899064799SGarrett Wollman * 92e322d37SHiroki Sato * Redistribution and use in source and binary forms, with or without 102e322d37SHiroki Sato * modification, are permitted provided that the following conditions are met: 112e322d37SHiroki Sato * - Redistributions of source code must retain the above copyright notice, 122e322d37SHiroki Sato * this list of conditions and the following disclaimer. 132e322d37SHiroki Sato * - Redistributions in binary form must reproduce the above copyright notice, 142e322d37SHiroki Sato * this list of conditions and the following disclaimer in the documentation 152e322d37SHiroki Sato * and/or other materials provided with the distribution. 162e322d37SHiroki Sato * - Neither the name of Sun Microsystems, Inc. nor the names of its 172e322d37SHiroki Sato * contributors may be used to endorse or promote products derived 182e322d37SHiroki Sato * from this software without specific prior written permission. 1999064799SGarrett Wollman * 202e322d37SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 212e322d37SHiroki Sato * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 222e322d37SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 232e322d37SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 242e322d37SHiroki Sato * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 252e322d37SHiroki Sato * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 262e322d37SHiroki Sato * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 272e322d37SHiroki Sato * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 282e322d37SHiroki Sato * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 292e322d37SHiroki Sato * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 302e322d37SHiroki Sato * POSSIBILITY OF SUCH DAMAGE. 3199064799SGarrett Wollman */ 3299064799SGarrett Wollman 3399064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 34a986ef57SDavid E. O'Brien static char *sccsid2 = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro"; 35d3d20c82SDavid E. O'Brien static char *sccsid = "@(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC"; 3699064799SGarrett Wollman #endif 37d3d20c82SDavid E. O'Brien #include <sys/cdefs.h> 38d3d20c82SDavid E. O'Brien __FBSDID("$FreeBSD$"); 3999064799SGarrett Wollman 4099064799SGarrett Wollman /* 4199064799SGarrett Wollman * pmap_clnt.c 4299064799SGarrett Wollman * Client interface to pmap rpc service. 4399064799SGarrett Wollman * 4499064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 4599064799SGarrett Wollman */ 4699064799SGarrett Wollman 47d201fe46SDaniel Eischen #include "namespace.h" 48ad133ed6SBill Paul #include <sys/types.h> 49ad133ed6SBill Paul #include <sys/stat.h> 504c3af266SPoul-Henning Kamp #include <unistd.h> 518360efbdSAlfred Perlstein 5299064799SGarrett Wollman #include <rpc/rpc.h> 5399064799SGarrett Wollman #include <rpc/pmap_prot.h> 5499064799SGarrett Wollman #include <rpc/pmap_clnt.h> 558360efbdSAlfred Perlstein #include <rpc/nettype.h> 56ec53c6faSPeter Wemm #include <netinet/in.h> 57d201fe46SDaniel Eischen #include "un-namespace.h" 58c124f3bdSJames Raynard 598360efbdSAlfred Perlstein #include <stdio.h> 608360efbdSAlfred Perlstein #include <stdlib.h> 6199064799SGarrett Wollman 628360efbdSAlfred Perlstein #include "rpc_com.h" 6399064799SGarrett Wollman 6499064799SGarrett Wollman bool_t 658360efbdSAlfred Perlstein pmap_set(u_long program, u_long version, int protocol, int port) 6699064799SGarrett Wollman { 6799064799SGarrett Wollman bool_t rslt; 688360efbdSAlfred Perlstein struct netbuf *na; 698360efbdSAlfred Perlstein struct netconfig *nconf; 708360efbdSAlfred Perlstein char buf[32]; 7199064799SGarrett Wollman 728360efbdSAlfred Perlstein if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) { 7399064799SGarrett Wollman return (FALSE); 7499064799SGarrett Wollman } 758360efbdSAlfred Perlstein nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp"); 768360efbdSAlfred Perlstein if (nconf == NULL) { 778360efbdSAlfred Perlstein return (FALSE); 788360efbdSAlfred Perlstein } 798360efbdSAlfred Perlstein snprintf(buf, sizeof buf, "0.0.0.0.%d.%d", 808360efbdSAlfred Perlstein (((u_int32_t)port) >> 8) & 0xff, port & 0xff); 818360efbdSAlfred Perlstein na = uaddr2taddr(nconf, buf); 828360efbdSAlfred Perlstein if (na == NULL) { 838360efbdSAlfred Perlstein freenetconfigent(nconf); 848360efbdSAlfred Perlstein return (FALSE); 858360efbdSAlfred Perlstein } 868360efbdSAlfred Perlstein rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na); 878360efbdSAlfred Perlstein free(na); 888360efbdSAlfred Perlstein freenetconfigent(nconf); 8999064799SGarrett Wollman return (rslt); 9099064799SGarrett Wollman } 9199064799SGarrett Wollman 9299064799SGarrett Wollman /* 9399064799SGarrett Wollman * Remove the mapping between program, version and port. 9499064799SGarrett Wollman * Calls the pmap service remotely to do the un-mapping. 9599064799SGarrett Wollman */ 9699064799SGarrett Wollman bool_t 978360efbdSAlfred Perlstein pmap_unset(u_long program, u_long version) 9899064799SGarrett Wollman { 998360efbdSAlfred Perlstein struct netconfig *nconf; 1008360efbdSAlfred Perlstein bool_t udp_rslt = FALSE; 1018360efbdSAlfred Perlstein bool_t tcp_rslt = FALSE; 10299064799SGarrett Wollman 1038360efbdSAlfred Perlstein nconf = __rpc_getconfip("udp"); 1048360efbdSAlfred Perlstein if (nconf != NULL) { 1058360efbdSAlfred Perlstein udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 1068360efbdSAlfred Perlstein nconf); 1078360efbdSAlfred Perlstein freenetconfigent(nconf); 108ad133ed6SBill Paul } 1098360efbdSAlfred Perlstein nconf = __rpc_getconfip("tcp"); 1108360efbdSAlfred Perlstein if (nconf != NULL) { 1118360efbdSAlfred Perlstein tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 1128360efbdSAlfred Perlstein nconf); 1138360efbdSAlfred Perlstein freenetconfigent(nconf); 1148360efbdSAlfred Perlstein } 1158360efbdSAlfred Perlstein /* 1168360efbdSAlfred Perlstein * XXX: The call may still succeed even if only one of the 1178360efbdSAlfred Perlstein * calls succeeded. This was the best that could be 1188360efbdSAlfred Perlstein * done for backward compatibility. 1198360efbdSAlfred Perlstein */ 1208360efbdSAlfred Perlstein return (tcp_rslt || udp_rslt); 12199064799SGarrett Wollman } 122