]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libcasper/services/cap_dns/cap_dns.3
MFCr340141:
[FreeBSD/FreeBSD.git] / lib / libcasper / services / cap_dns / cap_dns.3
1 .\" Copyright (c) 2018 Mariusz Zaborski <oshogbo@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd March 18, 2018
28 .Dt CAP_DNS 3
29 .Os
30 .Sh NAME
31 .Nm cap_gethostbyname ,
32 .Nm cap_gethostbyname2 ,
33 .Nm cap_gethostbyaddr ,
34 .Nm cap_getnameinfo ,
35 .Nm cap_dns_type_limit ,
36 .Nm cap_dns_family_limit
37 .Nd "library for getting network host entry in capability mode"
38 .Sh LIBRARY
39 .Lb libcap_dns
40 .Sh SYNOPSIS
41 .In sys/nv.h
42 .In libcasper.h
43 .In casper/cap_dns.h
44 .Ft "struct hostent *"
45 .Fn cap_gethostbyname "const cap_channel_t *chan" "const char *name"
46 .Ft "struct hostent *"
47 .Fn cap_gethostbyname2 "const cap_channel_t *chan" "const char *name" "int af"
48 .Ft "struct hostent *"
49 .Fn cap_gethostbyaddr "const cap_channel_t *chan" "const void *addr" "socklen_t len" "int af"
50 .Ft "int"
51 .Fn cap_getnameinfo "const cap_channel_t *chan" "const void *name" "int namelen"
52 .Ft "int"
53 .Fn cap_dns_type_limit "cap_channel_t *chan" "const char * const *types" "size_t ntypes"
54 .Ft "int"
55 .Fn cap_dns_family_limit "const cap_channel_t *chan" "const int *families" "size_t nfamilies"
56 .Sh DESCRIPTION
57 The functions
58 .Fn cap_gethostbyname ,
59 .Fn cap_gethostbyname2 ,
60 .Fn cep_gethostbyaddr
61 and
62 .Fn cap_getnameinfo
63 are respectively equivalent to
64 .Xr gethostbyname 2 ,
65 .Xr gethostbyname2 2 ,
66 .Xr gethostbyaddr 2
67 and
68 .Xr getnameinfo 2
69 except that the connection to the
70 .Nm system.dns
71 service needs to be provided.
72 .Pp
73 The
74 .Fn cap_dns_type_limit
75 function limits the functions allowed in the service.
76 The
77 .Fa types
78 variable can be set to
79 .Dv ADDR
80 or
81 .Dv NAME .
82 See the
83 .Sx LIMITS
84 section for more details.
85 The
86 .Fa ntpyes
87 variable contains the number of
88 .Fa types
89 provided.
90 .Pp
91 The
92 .Fn cap_dns_family_limit
93 functions allows to limit address families.
94 For details see
95 .Sx LIMITS .
96 The
97 .Fa nfamilies
98 variable contains the number of
99 .Fa families
100 provided.
101 .Sh LIMITS
102 The preferred way of setting limits is to use the
103 .Fn cap_dns_type_limit
104 and
105 .Fn cap_dns_family_limit
106 functions, but the limits of service can be set also using
107 .Xr cap_limit_set 3 .
108 The
109 .Xr nvlist 9
110 for that function can contain the following values and types:
111 .Bl -ohang -offset indent
112 .It type ( NV_TYPE_STRING )
113 The
114 .Va type
115 can have two values:
116 .Dv ADDR
117 or
118 .Dv NAME .
119 The
120 .Dv ADDR
121 means that reverse DNS lookups are allowed with
122 .Fn cap_getnameinfo
123 and
124 .Fn cap_gethostbyaddr
125 functions.
126 In case when
127 .Va type
128 is set to
129 .Dv NAME
130 the name resolution is allowed with
131 .Fn cap_getaddrinfo ,
132 .Fn cap_gethostbyname ,
133 and
134 .Fn cap_gethostbyname2
135 functions.
136 .It family ( NV_TYPE_NUMBER )
137 The
138 .Va family
139 limits service to one of the address families (e.g.
140 .Dv AF_INET , AF_INET6 ,
141 etc.).
142 .Sh EXAMPLES
143 The following example first opens a capability to casper and then uses this
144 capability to create the
145 .Nm system.dns
146 casper service and uses it to resolve an IP address.
147 .Bd -literal
148 cap_channel_t *capcas, *capdns;
149 const char *typelimit = "ADDR";
150 int familylimit;
151 const char *ipstr = "127.0.0.1";
152 struct in_addr ip;
153 struct hostent *hp;
154
155 /* Open capability to Casper. */
156 capcas = cap_init();
157 if (capcas == NULL)
158         err(1, "Unable to contact Casper");
159
160 /* Enter capability mode sandbox. */
161 if (cap_enter() < 0 && errno != ENOSYS)
162         err(1, "Unable to enter capability mode");
163
164 /* Use Casper capability to create capability to the system.dns service. */
165 capdns = cap_service_open(capcas, "system.dns");
166 if (capdns == NULL)
167         err(1, "Unable to open system.dns service");
168
169 /* Close Casper capability, we don't need it anymore. */
170 cap_close(capcas);
171
172 /* Limit system.dns to reverse DNS lookups. */
173 if (cap_dns_type_limit(capdns, &typelimit, 1) < 0)
174         err(1, "Unable to limit access to the system.dns service");
175
176 /* Limit system.dns to reserve IPv4 addresses */
177 familylimit = AF_INET;
178 if (cap_dns_family_limit(capdns, &familylimit, 1) < 0)
179         err(1, "Unable to limit access to the system.dns service");
180
181 /* Convert IP address in C-string to in_addr. */
182 if (!inet_aton(ipstr, &ip))
183         errx(1, "Unable to parse IP address %s.", ipstr);
184
185 /* Find hostname for the given IP address. */
186 hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET);
187 if (hp == NULL)
188         errx(1, "No name associated with %s.", ipstr);
189
190 printf("Name associated with %s is %s.\\n", ipstr, hp->h_name);
191 .Ed
192 .Sh SEE ALSO
193 .Xr cap_enter 2 ,
194 .Xr err 3 ,
195 .Xr gethostbyaddr 3 ,
196 .Xr gethostbyname 3 ,
197 .Xr gethostbyname2 3 ,
198 .Xr getnameinfo 3 ,
199 .Xr capsicum 4 ,
200 .Xr nv 9
201 .Sh AUTHORS
202 The
203 .Nm cap_dns
204 service was implemented by
205 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
206 under sponsorship from the FreeBSD Foundation.
207 .Pp
208 This manual page was written by
209 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org .