Remove building with NOCRYPTO option
[minix3.git] / lib / libc / rpc / pmap_clnt.c
blob4d0438b88d8dc691fe5adc2b5ae39132a9a341c2
1 /* $NetBSD: pmap_clnt.c,v 1.19 2013/03/11 20:19:29 tron Exp $ */
3 /*
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
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.
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.
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
45 * pmap_clnt.c
46 * Client interface to pmap rpc service.
48 * Copyright (C) 1984, Sun Microsystems, Inc.
51 #include "namespace.h"
53 #include <unistd.h>
55 #include <rpc/rpc.h>
56 #include <rpc/pmap_prot.h>
57 #include <rpc/pmap_clnt.h>
58 #include <rpc/nettype.h>
60 #include <stdio.h>
61 #include <stdlib.h>
63 #include "rpc_internal.h"
65 #ifdef __weak_alias
66 __weak_alias(pmap_set,_pmap_set)
67 __weak_alias(pmap_unset,_pmap_unset)
68 #endif
70 bool_t
71 pmap_set(u_long program, u_long version, int protocol, int port)
73 bool_t rslt;
74 struct netbuf *na;
75 struct netconfig *nconf;
76 char buf[32];
78 if ((protocol != IPPROTO_UDP) && (protocol != IPPROTO_TCP)) {
79 return (FALSE);
81 nconf = __rpc_getconfip(protocol == IPPROTO_UDP ? "udp" : "tcp");
82 if (nconf == NULL) {
83 return (FALSE);
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);
92 rslt = rpcb_set((rpcprog_t)program, (rpcvers_t)version, nconf, na);
93 free(na);
94 freenetconfigent(nconf);
95 return (rslt);
99 * Remove the mapping between program, version and port.
100 * Calls the pmap service remotely to do the un-mapping.
102 bool_t
103 pmap_unset(u_long program, u_long version)
105 struct netconfig *nconf;
106 bool_t udp_rslt = FALSE;
107 bool_t tcp_rslt = FALSE;
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);
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);
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.
126 return (tcp_rslt || udp_rslt);