xref: /minix3/lib/libc/rpc/pmap_clnt.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*
4*84d9c625SLionel Sambuc  * Copyright (c) 2010, Oracle America, Inc.
52fe8fb19SBen Gras  *
6*84d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*84d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions are
8*84d9c625SLionel Sambuc  * met:
92fe8fb19SBen Gras  *
10*84d9c625SLionel Sambuc  *     * Redistributions of source code must retain the above copyright
11*84d9c625SLionel Sambuc  *       notice, this list of conditions and the following disclaimer.
12*84d9c625SLionel Sambuc  *     * Redistributions in binary form must reproduce the above
13*84d9c625SLionel Sambuc  *       copyright notice, this list of conditions and the following
14*84d9c625SLionel Sambuc  *       disclaimer in the documentation and/or other materials
15*84d9c625SLionel Sambuc  *       provided with the distribution.
16*84d9c625SLionel Sambuc  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17*84d9c625SLionel Sambuc  *       contributors may be used to endorse or promote products derived
18*84d9c625SLionel Sambuc  *       from this software without specific prior written permission.
192fe8fb19SBen Gras  *
20*84d9c625SLionel Sambuc  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*84d9c625SLionel Sambuc  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*84d9c625SLionel Sambuc  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*84d9c625SLionel Sambuc  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24*84d9c625SLionel Sambuc  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25*84d9c625SLionel Sambuc  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*84d9c625SLionel Sambuc  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27*84d9c625SLionel Sambuc  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*84d9c625SLionel Sambuc  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29*84d9c625SLionel Sambuc  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30*84d9c625SLionel Sambuc  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*84d9c625SLionel Sambuc  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322fe8fb19SBen Gras  */
332fe8fb19SBen Gras 
342fe8fb19SBen Gras #include <sys/cdefs.h>
352fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
362fe8fb19SBen Gras #if 0
372fe8fb19SBen Gras static char *sccsid = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
382fe8fb19SBen Gras static char *sccsid = "@(#)pmap_clnt.c	2.2 88/08/01 4.0 RPCSRC";
392fe8fb19SBen Gras #else
40*84d9c625SLionel Sambuc __RCSID("$NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $");
412fe8fb19SBen Gras #endif
422fe8fb19SBen Gras #endif
432fe8fb19SBen Gras 
442fe8fb19SBen Gras /*
452fe8fb19SBen Gras  * pmap_clnt.c
462fe8fb19SBen Gras  * Client interface to pmap rpc service.
472fe8fb19SBen Gras  *
482fe8fb19SBen Gras  * Copyright (C) 1984, Sun Microsystems, Inc.
492fe8fb19SBen Gras  */
502fe8fb19SBen Gras 
512fe8fb19SBen Gras #include "namespace.h"
522fe8fb19SBen Gras 
532fe8fb19SBen Gras #include <unistd.h>
542fe8fb19SBen Gras 
552fe8fb19SBen Gras #include <rpc/rpc.h>
562fe8fb19SBen Gras #include <rpc/pmap_prot.h>
572fe8fb19SBen Gras #include <rpc/pmap_clnt.h>
582fe8fb19SBen Gras #include <rpc/nettype.h>
592fe8fb19SBen Gras 
602fe8fb19SBen Gras #include <stdio.h>
612fe8fb19SBen Gras #include <stdlib.h>
622fe8fb19SBen Gras 
632fe8fb19SBen Gras #include "rpc_internal.h"
642fe8fb19SBen Gras 
652fe8fb19SBen Gras #ifdef __weak_alias
__weak_alias(pmap_set,_pmap_set)662fe8fb19SBen Gras __weak_alias(pmap_set,_pmap_set)
672fe8fb19SBen Gras __weak_alias(pmap_unset,_pmap_unset)
682fe8fb19SBen Gras #endif
692fe8fb19SBen Gras 
702fe8fb19SBen Gras bool_t
712fe8fb19SBen Gras pmap_set(u_long program, u_long version, int protocol, int port)
722fe8fb19SBen Gras {
732fe8fb19SBen Gras 	bool_t rslt;
742fe8fb19SBen Gras 	struct netbuf *na;
752fe8fb19SBen Gras 	struct netconfig *nconf;
762fe8fb19SBen Gras 	char buf[32];
772fe8fb19SBen Gras 
782fe8fb19SBen Gras 	if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {
792fe8fb19SBen Gras 		return (FALSE);
802fe8fb19SBen Gras 	}
812fe8fb19SBen Gras 	nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");
822fe8fb19SBen Gras 	if (nconf == NULL) {
832fe8fb19SBen Gras 		return (FALSE);
842fe8fb19SBen Gras 	}
852fe8fb19SBen Gras 	snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",
862fe8fb19SBen Gras 	    (((u_int32_t)port) >> 8) & 0xff, port & 0xff);
872fe8fb19SBen Gras 	na = uaddr2taddr(nconf, buf);
882fe8fb19SBen Gras 	if (na == NULL) {
892fe8fb19SBen Gras 		freenetconfigent(nconf);
902fe8fb19SBen Gras 		return (FALSE);
912fe8fb19SBen Gras 	}
922fe8fb19SBen Gras 	rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);
932fe8fb19SBen Gras 	free(na);
942fe8fb19SBen Gras 	freenetconfigent(nconf);
952fe8fb19SBen Gras 	return (rslt);
962fe8fb19SBen Gras }
972fe8fb19SBen Gras 
982fe8fb19SBen Gras /*
992fe8fb19SBen Gras  * Remove the mapping between program, version and port.
1002fe8fb19SBen Gras  * Calls the pmap service remotely to do the un-mapping.
1012fe8fb19SBen Gras  */
1022fe8fb19SBen Gras bool_t
pmap_unset(u_long program,u_long version)1032fe8fb19SBen Gras pmap_unset(u_long program, u_long version)
1042fe8fb19SBen Gras {
1052fe8fb19SBen Gras 	struct netconfig *nconf;
1062fe8fb19SBen Gras 	bool_t udp_rslt = FALSE;
1072fe8fb19SBen Gras 	bool_t tcp_rslt = FALSE;
1082fe8fb19SBen Gras 
1092fe8fb19SBen Gras 	nconf = __rpc_getconfip("udp");
1102fe8fb19SBen Gras 	if (nconf != NULL) {
1112fe8fb19SBen Gras 		udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
1122fe8fb19SBen Gras 		    nconf);
1132fe8fb19SBen Gras 		freenetconfigent(nconf);
1142fe8fb19SBen Gras 	}
1152fe8fb19SBen Gras 	nconf = __rpc_getconfip("tcp");
1162fe8fb19SBen Gras 	if (nconf != NULL) {
1172fe8fb19SBen Gras 		tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
1182fe8fb19SBen Gras 		    nconf);
1192fe8fb19SBen Gras 		freenetconfigent(nconf);
1202fe8fb19SBen Gras 	}
1212fe8fb19SBen Gras 	/*
1222fe8fb19SBen Gras 	 * XXX: The call may still succeed even if only one of the
1232fe8fb19SBen Gras 	 * calls succeeded.  This was the best that could be
1242fe8fb19SBen Gras 	 * done for backward compatibility.
1252fe8fb19SBen Gras 	 */
1262fe8fb19SBen Gras 	return (tcp_rslt || udp_rslt);
1272fe8fb19SBen Gras }
128