1 /*        $NetBSD: rpcbind.h,v 1.6 2017/08/16 08:44:40 christos Exp $ */
2 /*        $FreeBSD: head/usr.sbin/rpcbind/rpcbind.h 293229 2016-01-06 00:00:11Z asomers $ */
3 /*-
4  * Copyright (c) 2009, Sun Microsystems, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * - Redistributions of source code must retain the above copyright notice,
10  *   this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * - Neither the name of Sun Microsystems, Inc. nor the names of its
15  *   contributors may be used to endorse or promote products derived
16  *   from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*
32  * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
33  */
34 
35 /* #ident "@(#)rpcbind.h 1.4 90/04/12 SMI" */
36 
37 /*
38  * rpcbind.h
39  * The common header declarations
40  */
41 
42 #ifndef rpcbind_h
43 #define   rpcbind_h
44 
45 #ifdef PORTMAP
46 #include <rpc/pmap_prot.h>
47 #endif
48 #include <rpc/rpcb_prot.h>
49 
50 /*
51  * Stuff for the rmtcall service
52  */
53 struct encap_parms {
54           u_int32_t arglen;
55           char *args;
56 };
57 
58 struct r_rmtcall_args {
59           u_int32_t  rmt_prog;
60           u_int32_t  rmt_vers;
61           u_int32_t  rmt_proc;
62           int     rmt_localvers;  /* whether to send port # or uaddr */
63           char    *rmt_uaddr;
64           struct encap_parms rmt_args;
65 };
66 
67 extern int debugging;
68 extern int doabort;
69 #ifdef LIBWRAP
70 extern int libwrap;
71 #endif
72 extern int verboselog;
73 extern int insecure;
74 extern int oldstyle_local;
75 extern rpcblist_ptr list_rbl; /* A list of version 3 & 4 rpcbind services */
76 
77 #ifdef PORTMAP
78 extern struct pmaplist *list_pml; /* A list of version 2 rpcbind services */
79 extern const char *udptrans;  /* Name of UDP transport */
80 extern const char *tcptrans;  /* Name of TCP transport */
81 extern const char *udp_uaddr; /* Universal UDP address */
82 extern const char *tcp_uaddr; /* Universal TCP address */
83 #endif
84 
85 extern const char rpcbind_superuser[];
86 extern const char rpcbind_unknown[];
87 
88 int add_bndlist(struct netconfig *, struct netbuf *);
89 bool_t is_bound(const char *, const char *);
90 char *mergeaddr(SVCXPRT *, char *, char *, char *);
91 struct netconfig *rpcbind_get_conf(const char *);
92 
93 void rpcbs_init(void);
94 void rpcbs_procinfo(rpcvers_t, rpcproc_t);
95 void rpcbs_set(rpcvers_t, bool_t);
96 void rpcbs_unset(rpcvers_t, bool_t);
97 void rpcbs_getaddr(rpcvers_t, rpcprog_t, rpcvers_t, const char *, const char *);
98 void rpcbs_rmtcall(rpcvers_t, rpcproc_t, rpcprog_t, rpcvers_t, rpcproc_t,
99                               char *, rpcblist_ptr);
100 void *rpcbproc_getstat(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
101 
102 void rpcb_service_3(struct svc_req *, SVCXPRT *);
103 void rpcb_service_4(struct svc_req *, SVCXPRT *);
104 
105 /* Common functions shared between versions */
106 void *rpcbproc_set_com(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
107 void *rpcbproc_unset_com(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
108 bool_t map_set(RPCB *, char *);
109 bool_t map_unset(RPCB *, const char *);
110 void delete_prog(rpcprog_t);
111 void *rpcbproc_getaddr_com(RPCB *, struct svc_req *, SVCXPRT *, rpcvers_t,
112                                          rpcvers_t);
113 void *rpcbproc_gettime_com(void *, struct svc_req *, SVCXPRT *,
114                                         rpcvers_t);
115 void *rpcbproc_uaddr2taddr_com(void *, struct svc_req *,
116                                                        SVCXPRT *, rpcvers_t);
117 void *rpcbproc_taddr2uaddr_com(void *, struct svc_req *, SVCXPRT *,
118                                             rpcvers_t);
119 int create_rmtcall_fd(struct netconfig *);
120 void rpcbproc_callit_com(struct svc_req *, SVCXPRT *, rpcvers_t,
121                                     rpcvers_t);
122 __dead void my_svc_run(void);
123 
124 __dead void rpcbind_abort(void);
125 void reap(int);
126 void toggle_verboselog(int);
127 
128 int check_access(SVCXPRT *, rpcproc_t, void *, unsigned int);
129 int check_callit(SVCXPRT *, struct r_rmtcall_args *, int);
130 void logit(int, struct sockaddr *, rpcproc_t, rpcprog_t, const char *);
131 int is_loopback(struct netbuf *);
132 
133 #ifdef PORTMAP
134 extern void pmap_service(struct svc_req *, SVCXPRT *);
135 #endif
136 
137 void write_warmstart(void);
138 void read_warmstart(void);
139 
140 char *addrmerge(struct netbuf *caller, char *serv_uaddr, char *clnt_uaddr,
141     const char *netid);
142 int listen_addr(const struct sockaddr *sa);
143 void network_init(void);
144 struct sockaddr *local_sa(int);
145 
146 /* For different getaddr semantics */
147 #define   RPCB_ALLVERS 0
148 #define   RPCB_ONEVERS 1
149 /* To convert a struct sockaddr to IPv4 or IPv6 address */
150 #define   SA2SIN(sa)          ((const struct sockaddr_in *)(sa))
151 #define   SA2SINADDR(sa)      (SA2SIN(sa)->sin_addr)
152 #ifdef INET6
153 #define   SA2SIN6(sa)         ((const struct sockaddr_in6 *)(sa))
154 #define   SA2SIN6ADDR(sa)     (SA2SIN6(sa)->sin6_addr)
155 #endif
156 
157 #endif /* rpcbind_h */
158