xref: /freebsd/lib/libc/rpc/pmap_clnt.c (revision 2e322d379631c3bd6107e295f3e5d814c7845fc7)
18360efbdSAlfred Perlstein /*	$NetBSD: pmap_clnt.c,v 1.16 2000/07/06 03:10:34 christos Exp $	*/
28360efbdSAlfred Perlstein 
3*2e322d37SHiroki Sato /*-
4*2e322d37SHiroki Sato  * Copyright (c) 2009, Sun Microsystems, Inc.
5*2e322d37SHiroki Sato  * All rights reserved.
699064799SGarrett Wollman  *
7*2e322d37SHiroki Sato  * Redistribution and use in source and binary forms, with or without
8*2e322d37SHiroki Sato  * modification, are permitted provided that the following conditions are met:
9*2e322d37SHiroki Sato  * - Redistributions of source code must retain the above copyright notice,
10*2e322d37SHiroki Sato  *   this list of conditions and the following disclaimer.
11*2e322d37SHiroki Sato  * - Redistributions in binary form must reproduce the above copyright notice,
12*2e322d37SHiroki Sato  *   this list of conditions and the following disclaimer in the documentation
13*2e322d37SHiroki Sato  *   and/or other materials provided with the distribution.
14*2e322d37SHiroki Sato  * - Neither the name of Sun Microsystems, Inc. nor the names of its
15*2e322d37SHiroki Sato  *   contributors may be used to endorse or promote products derived
16*2e322d37SHiroki Sato  *   from this software without specific prior written permission.
1799064799SGarrett Wollman  *
18*2e322d37SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*2e322d37SHiroki Sato  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*2e322d37SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*2e322d37SHiroki Sato  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*2e322d37SHiroki Sato  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*2e322d37SHiroki Sato  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*2e322d37SHiroki Sato  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*2e322d37SHiroki Sato  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*2e322d37SHiroki Sato  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*2e322d37SHiroki Sato  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*2e322d37SHiroki Sato  * POSSIBILITY OF SUCH DAMAGE.
2999064799SGarrett Wollman  */
3099064799SGarrett Wollman 
3199064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint)
32a986ef57SDavid E. O'Brien static char *sccsid2 = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
33d3d20c82SDavid E. O'Brien static char *sccsid = "@(#)pmap_clnt.c	2.2 88/08/01 4.0 RPCSRC";
3499064799SGarrett Wollman #endif
35d3d20c82SDavid E. O'Brien #include <sys/cdefs.h>
36d3d20c82SDavid E. O'Brien __FBSDID("$FreeBSD$");
3799064799SGarrett Wollman 
3899064799SGarrett Wollman /*
3999064799SGarrett Wollman  * pmap_clnt.c
4099064799SGarrett Wollman  * Client interface to pmap rpc service.
4199064799SGarrett Wollman  *
4299064799SGarrett Wollman  * Copyright (C) 1984, Sun Microsystems, Inc.
4399064799SGarrett Wollman  */
4499064799SGarrett Wollman 
45d201fe46SDaniel Eischen #include "namespace.h"
46ad133ed6SBill Paul #include <sys/types.h>
47ad133ed6SBill Paul #include <sys/stat.h>
484c3af266SPoul-Henning Kamp #include <unistd.h>
498360efbdSAlfred Perlstein 
5099064799SGarrett Wollman #include <rpc/rpc.h>
5199064799SGarrett Wollman #include <rpc/pmap_prot.h>
5299064799SGarrett Wollman #include <rpc/pmap_clnt.h>
538360efbdSAlfred Perlstein #include <rpc/nettype.h>
54ec53c6faSPeter Wemm #include <netinet/in.h>
55d201fe46SDaniel Eischen #include "un-namespace.h"
56c124f3bdSJames Raynard 
578360efbdSAlfred Perlstein #include <stdio.h>
588360efbdSAlfred Perlstein #include <stdlib.h>
5999064799SGarrett Wollman 
608360efbdSAlfred Perlstein #include "rpc_com.h"
6199064799SGarrett Wollman 
6299064799SGarrett Wollman bool_t
638360efbdSAlfred Perlstein pmap_set(u_long program, u_long version, int protocol, int port)
6499064799SGarrett Wollman {
6599064799SGarrett Wollman 	bool_t rslt;
668360efbdSAlfred Perlstein 	struct netbuf *na;
678360efbdSAlfred Perlstein 	struct netconfig *nconf;
688360efbdSAlfred Perlstein 	char buf[32];
6999064799SGarrett Wollman 
708360efbdSAlfred Perlstein 	if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {
7199064799SGarrett Wollman 		return (FALSE);
7299064799SGarrett Wollman 	}
738360efbdSAlfred Perlstein 	nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");
748360efbdSAlfred Perlstein 	if (nconf == NULL) {
758360efbdSAlfred Perlstein 		return (FALSE);
768360efbdSAlfred Perlstein 	}
778360efbdSAlfred Perlstein 	snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",
788360efbdSAlfred Perlstein 	    (((u_int32_t)port) >> 8) & 0xff, port & 0xff);
798360efbdSAlfred Perlstein 	na = uaddr2taddr(nconf, buf);
808360efbdSAlfred Perlstein 	if (na == NULL) {
818360efbdSAlfred Perlstein 		freenetconfigent(nconf);
828360efbdSAlfred Perlstein 		return (FALSE);
838360efbdSAlfred Perlstein 	}
848360efbdSAlfred Perlstein 	rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);
858360efbdSAlfred Perlstein 	free(na);
868360efbdSAlfred Perlstein 	freenetconfigent(nconf);
8799064799SGarrett Wollman 	return (rslt);
8899064799SGarrett Wollman }
8999064799SGarrett Wollman 
9099064799SGarrett Wollman /*
9199064799SGarrett Wollman  * Remove the mapping between program, version and port.
9299064799SGarrett Wollman  * Calls the pmap service remotely to do the un-mapping.
9399064799SGarrett Wollman  */
9499064799SGarrett Wollman bool_t
958360efbdSAlfred Perlstein pmap_unset(u_long program, u_long version)
9699064799SGarrett Wollman {
978360efbdSAlfred Perlstein 	struct netconfig *nconf;
988360efbdSAlfred Perlstein 	bool_t udp_rslt = FALSE;
998360efbdSAlfred Perlstein 	bool_t tcp_rslt = FALSE;
10099064799SGarrett Wollman 
1018360efbdSAlfred Perlstein 	nconf = __rpc_getconfip("udp");
1028360efbdSAlfred Perlstein 	if (nconf != NULL) {
1038360efbdSAlfred Perlstein 		udp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
1048360efbdSAlfred Perlstein 		    nconf);
1058360efbdSAlfred Perlstein 		freenetconfigent(nconf);
106ad133ed6SBill Paul 	}
1078360efbdSAlfred Perlstein 	nconf = __rpc_getconfip("tcp");
1088360efbdSAlfred Perlstein 	if (nconf != NULL) {
1098360efbdSAlfred Perlstein 		tcp_rslt = rpcb_unset((rpcprog_t)program, (rpcvers_t)version,
1108360efbdSAlfred Perlstein 		    nconf);
1118360efbdSAlfred Perlstein 		freenetconfigent(nconf);
1128360efbdSAlfred Perlstein 	}
1138360efbdSAlfred Perlstein 	/*
1148360efbdSAlfred Perlstein 	 * XXX: The call may still succeed even if only one of the
1158360efbdSAlfred Perlstein 	 * calls succeeded.  This was the best that could be
1168360efbdSAlfred Perlstein 	 * done for backward compatibility.
1178360efbdSAlfred Perlstein 	 */
1188360efbdSAlfred Perlstein 	return (tcp_rslt || udp_rslt);
11999064799SGarrett Wollman }
120