18360efbdSAlfred Perlstein /* $NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */ 28360efbdSAlfred Perlstein 399064799SGarrett Wollman /* 499064799SGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 599064799SGarrett Wollman * unrestricted use provided that this legend is included on all tape 699064799SGarrett Wollman * media and as a part of the software program in whole or part. Users 799064799SGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 899064799SGarrett Wollman * to license or distribute it to anyone else except as part of a product or 999064799SGarrett Wollman * program developed by the user. 1099064799SGarrett Wollman * 1199064799SGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1299064799SGarrett Wollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1399064799SGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1499064799SGarrett Wollman * 1599064799SGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 1699064799SGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 1799064799SGarrett Wollman * modification or enhancement. 1899064799SGarrett Wollman * 1999064799SGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 2099064799SGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 2199064799SGarrett Wollman * OR ANY PART THEREOF. 2299064799SGarrett Wollman * 2399064799SGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 2499064799SGarrett Wollman * or profits or other special, indirect and consequential damages, even if 2599064799SGarrett Wollman * Sun has been advised of the possibility of such damages. 2699064799SGarrett Wollman * 2799064799SGarrett Wollman * Sun Microsystems, Inc. 2899064799SGarrett Wollman * 2550 Garcia Avenue 2999064799SGarrett Wollman * Mountain View, California 94043 3099064799SGarrett Wollman */ 3199064799SGarrett Wollman 328360efbdSAlfred Perlstein #include <sys/cdefs.h> 3399064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 3499064799SGarrett Wollman /*static char *sccsid = "from: @(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";*/ 3599064799SGarrett Wollman /*static char *sccsid = "from: @(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";*/ 367f3dea24SPeter Wemm static char *rcsid = "$FreeBSD$"; 3799064799SGarrett Wollman #endif 3899064799SGarrett Wollman 3999064799SGarrett Wollman /* 4099064799SGarrett Wollman * pmap_clnt.c 4199064799SGarrett Wollman * Client interface to pmap rpc service. 4299064799SGarrett Wollman * 4399064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 4499064799SGarrett Wollman */ 4599064799SGarrett Wollman 46d201fe46SDaniel Eischen #include "namespace.h" 47ad133ed6SBill Paul #include <sys/types.h> 48ad133ed6SBill Paul #include <sys/stat.h> 494c3af266SPoul-Henning Kamp #include <unistd.h> 508360efbdSAlfred Perlstein 5199064799SGarrett Wollman #include <rpc/rpc.h> 5299064799SGarrett Wollman #include <rpc/pmap_prot.h> 5399064799SGarrett Wollman #include <rpc/pmap_clnt.h> 548360efbdSAlfred Perlstein #include <rpc/nettype.h> 55ec53c6faSPeter Wemm #include <netinet/in.h> 56d201fe46SDaniel Eischen #include "un-namespace.h" 57c124f3bdSJames Raynard 588360efbdSAlfred Perlstein #include <stdio.h> 598360efbdSAlfred Perlstein #include <stdlib.h> 6099064799SGarrett Wollman 618360efbdSAlfred Perlstein #include "rpc_com.h" 6299064799SGarrett Wollman 6399064799SGarrett Wollman bool_t 648360efbdSAlfred Perlstein pmap_set(u_long program, u_long version, int protocol, int port) 6599064799SGarrett Wollman { 6699064799SGarrett Wollman bool_t rslt; 678360efbdSAlfred Perlstein struct netbuf *na; 688360efbdSAlfred Perlstein struct netconfig *nconf; 698360efbdSAlfred Perlstein char buf[32]; 7099064799SGarrett Wollman 718360efbdSAlfred Perlstein if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) { 7299064799SGarrett Wollman return (FALSE); 7399064799SGarrett Wollman } 748360efbdSAlfred Perlstein nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp"); 758360efbdSAlfred Perlstein if (nconf == NULL) { 768360efbdSAlfred Perlstein return (FALSE); 778360efbdSAlfred Perlstein } 788360efbdSAlfred Perlstein snprintf(buf, sizeof buf, "0.0.0.0.%d.%d", 798360efbdSAlfred Perlstein (((u_int32_t)port) >> 8) & 0xff, port & 0xff); 808360efbdSAlfred Perlstein na = uaddr2taddr(nconf, buf); 818360efbdSAlfred Perlstein if (na == NULL) { 828360efbdSAlfred Perlstein freenetconfigent(nconf); 838360efbdSAlfred Perlstein return (FALSE); 848360efbdSAlfred Perlstein } 858360efbdSAlfred Perlstein rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na); 868360efbdSAlfred Perlstein free(na); 878360efbdSAlfred Perlstein freenetconfigent(nconf); 8899064799SGarrett Wollman return (rslt); 8999064799SGarrett Wollman } 9099064799SGarrett Wollman 9199064799SGarrett Wollman /* 9299064799SGarrett Wollman * Remove the mapping between program, version and port. 9399064799SGarrett Wollman * Calls the pmap service remotely to do the un-mapping. 9499064799SGarrett Wollman */ 9599064799SGarrett Wollman bool_t 968360efbdSAlfred Perlstein pmap_unset(u_long program, u_long version) 9799064799SGarrett Wollman { 988360efbdSAlfred Perlstein struct netconfig *nconf; 998360efbdSAlfred Perlstein bool_t udp_rslt = FALSE; 1008360efbdSAlfred Perlstein bool_t tcp_rslt = FALSE; 10199064799SGarrett Wollman 1028360efbdSAlfred Perlstein nconf = __rpc_getconfip("udp"); 1038360efbdSAlfred Perlstein if (nconf != NULL) { 1048360efbdSAlfred Perlstein udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 1058360efbdSAlfred Perlstein nconf); 1068360efbdSAlfred Perlstein freenetconfigent(nconf); 107ad133ed6SBill Paul } 1088360efbdSAlfred Perlstein nconf = __rpc_getconfip("tcp"); 1098360efbdSAlfred Perlstein if (nconf != NULL) { 1108360efbdSAlfred Perlstein tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 1118360efbdSAlfred Perlstein nconf); 1128360efbdSAlfred Perlstein freenetconfigent(nconf); 1138360efbdSAlfred Perlstein } 1148360efbdSAlfred Perlstein /* 1158360efbdSAlfred Perlstein * XXX: The call may still succeed even if only one of the 1168360efbdSAlfred Perlstein * calls succeeded. This was the best that could be 1178360efbdSAlfred Perlstein * done for backward compatibility. 1188360efbdSAlfred Perlstein */ 1198360efbdSAlfred Perlstein return (tcp_rslt || udp_rslt); 12099064799SGarrett Wollman } 121