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