1 /* $NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $ */ 2 3 /* 4 * Copyright (c) 2010, Oracle America, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials 15 * provided with the distribution. 16 * * Neither the name of the "Oracle America, Inc." nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 #if defined(LIBC_SCCS) && !defined(lint) 36 #if 0 37 static char *sccsid = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro"; 38 static char *sccsid = "@(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC"; 39 #else 40 __RCSID("$NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $"); 41 #endif 42 #endif 43 44 /* 45 * pmap_clnt.c 46 * Client interface to pmap rpc service. 47 * 48 * Copyright (C) 1984, Sun Microsystems, Inc. 49 */ 50 51 #include "namespace.h" 52 53 #include <unistd.h> 54 55 #include <rpc/rpc.h> 56 #include <rpc/pmap_prot.h> 57 #include <rpc/pmap_clnt.h> 58 #include <rpc/nettype.h> 59 60 #include <stdio.h> 61 #include <stdlib.h> 62 63 #include "rpc_internal.h" 64 65 #ifdef __weak_alias 66 __weak_alias(pmap_set,_pmap_set) 67 __weak_alias(pmap_unset,_pmap_unset) 68 #endif 69 70 bool_t 71 pmap_set(u_long program, u_long version, int protocol, int port) 72 { 73 bool_t rslt; 74 struct netbuf *na; 75 struct netconfig *nconf; 76 char buf[32]; 77 78 if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) { 79 return (FALSE); 80 } 81 nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp"); 82 if (nconf == NULL) { 83 return (FALSE); 84 } 85 snprintf(buf, sizeof buf, "0.0.0.0.%d.%d", 86 (((u_int32_t)port) >> 8) & 0xff, port & 0xff); 87 na = uaddr2taddr(nconf, buf); 88 if (na == NULL) { 89 freenetconfigent(nconf); 90 return (FALSE); 91 } 92 rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na); 93 free(na); 94 freenetconfigent(nconf); 95 return (rslt); 96 } 97 98 /* 99 * Remove the mapping between program, version and port. 100 * Calls the pmap service remotely to do the un-mapping. 101 */ 102 bool_t 103 pmap_unset(u_long program, u_long version) 104 { 105 struct netconfig *nconf; 106 bool_t udp_rslt = FALSE; 107 bool_t tcp_rslt = FALSE; 108 109 nconf = __rpc_getconfip("udp"); 110 if (nconf != NULL) { 111 udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 112 nconf); 113 freenetconfigent(nconf); 114 } 115 nconf = __rpc_getconfip("tcp"); 116 if (nconf != NULL) { 117 tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version, 118 nconf); 119 freenetconfigent(nconf); 120 } 121 /* 122 * XXX: The call may still succeed even if only one of the 123 * calls succeeded. This was the best that could be 124 * done for backward compatibility. 125 */ 126 return (tcp_rslt || udp_rslt); 127 } 128