]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /*- |
2 | * Copyright (c) 2008-2009 Apple Inc. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of | |
14 | * its contributors may be used to endorse or promote products derived | |
15 | * from this software without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND | |
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
20 | * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR | |
21 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | * | |
29 | */ | |
30 | ||
31 | #include <sys/param.h> | |
32 | #include <sys/socket.h> | |
33 | ||
34 | #include <security/audit/audit.h> | |
35 | ||
36 | #include <bsm/audit_domain.h> | |
37 | #include <bsm/audit_record.h> | |
38 | ||
39 | #if CONFIG_AUDIT | |
40 | struct bsm_domain { | |
0a7de745 A |
41 | u_short bd_bsm_domain; |
42 | int bd_local_domain; | |
b0d623f7 A |
43 | }; |
44 | ||
0a7de745 | 45 | #define PF_NO_LOCAL_MAPPING -600 |
b0d623f7 A |
46 | |
47 | static const struct bsm_domain bsm_domains[] = { | |
48 | { BSM_PF_UNSPEC, PF_UNSPEC }, | |
49 | { BSM_PF_LOCAL, PF_LOCAL }, | |
50 | { BSM_PF_INET, PF_INET }, | |
51 | { BSM_PF_IMPLINK, | |
52 | #ifdef PF_IMPLINK | |
0a7de745 | 53 | PF_IMPLINK |
b0d623f7 | 54 | #else |
0a7de745 | 55 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
56 | #endif |
57 | }, | |
58 | { BSM_PF_PUP, | |
59 | #ifdef PF_PUP | |
0a7de745 | 60 | PF_PUP |
b0d623f7 | 61 | #else |
0a7de745 | 62 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
63 | #endif |
64 | }, | |
65 | { BSM_PF_CHAOS, | |
66 | #ifdef PF_CHAOS | |
0a7de745 | 67 | PF_CHAOS |
b0d623f7 | 68 | #else |
0a7de745 | 69 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
70 | #endif |
71 | }, | |
72 | { BSM_PF_NS, | |
73 | #ifdef PF_NS | |
0a7de745 | 74 | PF_NS |
b0d623f7 | 75 | #else |
0a7de745 | 76 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
77 | #endif |
78 | }, | |
79 | { BSM_PF_NBS, | |
80 | #ifdef PF_NBS | |
0a7de745 | 81 | PF_NBS |
b0d623f7 | 82 | #else |
0a7de745 | 83 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
84 | #endif |
85 | }, | |
86 | { BSM_PF_ECMA, | |
87 | #ifdef PF_ECMA | |
0a7de745 | 88 | PF_ECMA |
b0d623f7 | 89 | #else |
0a7de745 | 90 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
91 | #endif |
92 | }, | |
93 | { BSM_PF_DATAKIT, | |
94 | #ifdef PF_DATAKIT | |
0a7de745 | 95 | PF_DATAKIT |
b0d623f7 | 96 | #else |
0a7de745 | 97 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
98 | #endif |
99 | }, | |
100 | { BSM_PF_CCITT, | |
101 | #ifdef PF_CCITT | |
0a7de745 | 102 | PF_CCITT |
b0d623f7 | 103 | #else |
0a7de745 | 104 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
105 | #endif |
106 | }, | |
107 | { BSM_PF_SNA, PF_SNA }, | |
108 | { BSM_PF_DECnet, PF_DECnet }, | |
109 | { BSM_PF_DLI, | |
110 | #ifdef PF_DLI | |
0a7de745 | 111 | PF_DLI |
b0d623f7 | 112 | #else |
0a7de745 | 113 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
114 | #endif |
115 | }, | |
116 | { BSM_PF_LAT, | |
117 | #ifdef PF_LAT | |
0a7de745 | 118 | PF_LAT |
b0d623f7 | 119 | #else |
0a7de745 | 120 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
121 | #endif |
122 | }, | |
123 | { BSM_PF_HYLINK, | |
124 | #ifdef PF_HYLINK | |
0a7de745 | 125 | PF_HYLINK |
b0d623f7 | 126 | #else |
0a7de745 | 127 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
128 | #endif |
129 | }, | |
130 | { BSM_PF_APPLETALK, PF_APPLETALK }, | |
131 | { BSM_PF_NIT, | |
132 | #ifdef PF_NIT | |
0a7de745 | 133 | PF_NIT |
b0d623f7 | 134 | #else |
0a7de745 | 135 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
136 | #endif |
137 | }, | |
138 | { BSM_PF_802, | |
139 | #ifdef PF_802 | |
0a7de745 | 140 | PF_802 |
b0d623f7 | 141 | #else |
0a7de745 | 142 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
143 | #endif |
144 | }, | |
145 | { BSM_PF_OSI, | |
146 | #ifdef PF_OSI | |
0a7de745 | 147 | PF_OSI |
b0d623f7 | 148 | #else |
0a7de745 | 149 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
150 | #endif |
151 | }, | |
152 | { BSM_PF_X25, | |
153 | #ifdef PF_X25 | |
0a7de745 | 154 | PF_X25 |
b0d623f7 | 155 | #else |
0a7de745 | 156 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
157 | #endif |
158 | }, | |
159 | { BSM_PF_OSINET, | |
160 | #ifdef PF_OSINET | |
0a7de745 | 161 | PF_OSINET |
b0d623f7 | 162 | #else |
0a7de745 | 163 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
164 | #endif |
165 | }, | |
166 | { BSM_PF_GOSIP, | |
167 | #ifdef PF_GOSIP | |
0a7de745 | 168 | PF_GOSIP |
b0d623f7 | 169 | #else |
0a7de745 | 170 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
171 | #endif |
172 | }, | |
173 | { BSM_PF_IPX, PF_IPX }, | |
174 | { BSM_PF_ROUTE, PF_ROUTE }, | |
175 | { BSM_PF_LINK, | |
176 | #ifdef PF_LINK | |
0a7de745 | 177 | PF_LINK |
b0d623f7 | 178 | #else |
0a7de745 | 179 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
180 | #endif |
181 | }, | |
182 | { BSM_PF_INET6, PF_INET6 }, | |
183 | { BSM_PF_KEY, PF_KEY }, | |
184 | { BSM_PF_NCA, | |
185 | #ifdef PF_NCA | |
0a7de745 | 186 | PF_NCA |
b0d623f7 | 187 | #else |
0a7de745 | 188 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
189 | #endif |
190 | }, | |
191 | { BSM_PF_POLICY, | |
192 | #ifdef PF_POLICY | |
0a7de745 | 193 | PF_POLICY |
b0d623f7 | 194 | #else |
0a7de745 | 195 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
196 | #endif |
197 | }, | |
198 | { BSM_PF_INET_OFFLOAD, | |
199 | #ifdef PF_INET_OFFLOAD | |
0a7de745 | 200 | PF_INET_OFFLOAD |
b0d623f7 | 201 | #else |
0a7de745 | 202 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
203 | #endif |
204 | }, | |
205 | { BSM_PF_NETBIOS, | |
206 | #ifdef PF_NETBIOS | |
0a7de745 | 207 | PF_NETBIOS |
b0d623f7 | 208 | #else |
0a7de745 | 209 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
210 | #endif |
211 | }, | |
212 | { BSM_PF_ISO, | |
213 | #ifdef PF_ISO | |
0a7de745 | 214 | PF_ISO |
b0d623f7 | 215 | #else |
0a7de745 | 216 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
217 | #endif |
218 | }, | |
219 | { BSM_PF_XTP, | |
220 | #ifdef PF_XTP | |
0a7de745 | 221 | PF_XTP |
b0d623f7 | 222 | #else |
0a7de745 | 223 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
224 | #endif |
225 | }, | |
226 | { BSM_PF_COIP, | |
227 | #ifdef PF_COIP | |
0a7de745 | 228 | PF_COIP |
b0d623f7 | 229 | #else |
0a7de745 | 230 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
231 | #endif |
232 | }, | |
233 | { BSM_PF_CNT, | |
234 | #ifdef PF_CNT | |
0a7de745 | 235 | PF_CNT |
b0d623f7 | 236 | #else |
0a7de745 | 237 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
238 | #endif |
239 | }, | |
240 | { BSM_PF_RTIP, | |
241 | #ifdef PF_RTIP | |
0a7de745 | 242 | PF_RTIP |
b0d623f7 | 243 | #else |
0a7de745 | 244 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
245 | #endif |
246 | }, | |
247 | { BSM_PF_SIP, | |
248 | #ifdef PF_SIP | |
0a7de745 | 249 | PF_SIP |
b0d623f7 | 250 | #else |
0a7de745 | 251 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
252 | #endif |
253 | }, | |
254 | { BSM_PF_PIP, | |
255 | #ifdef PF_PIP | |
0a7de745 | 256 | PF_PIP |
b0d623f7 | 257 | #else |
0a7de745 | 258 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
259 | #endif |
260 | }, | |
261 | { BSM_PF_ISDN, | |
262 | #ifdef PF_ISDN | |
0a7de745 | 263 | PF_ISDN |
b0d623f7 | 264 | #else |
0a7de745 | 265 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
266 | #endif |
267 | }, | |
268 | { BSM_PF_E164, | |
269 | #ifdef PF_E164 | |
0a7de745 | 270 | PF_E164 |
b0d623f7 | 271 | #else |
0a7de745 | 272 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
273 | #endif |
274 | }, | |
275 | { BSM_PF_NATM, | |
276 | #ifdef PF_NATM | |
0a7de745 | 277 | PF_NATM |
b0d623f7 | 278 | #else |
0a7de745 | 279 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
280 | #endif |
281 | }, | |
282 | { BSM_PF_ATM, | |
283 | #ifdef PF_ATM | |
0a7de745 | 284 | PF_ATM |
b0d623f7 | 285 | #else |
0a7de745 | 286 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
287 | #endif |
288 | }, | |
289 | { BSM_PF_NETGRAPH, | |
290 | #ifdef PF_NETGRAPH | |
0a7de745 | 291 | PF_NETGRAPH |
b0d623f7 | 292 | #else |
0a7de745 | 293 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
294 | #endif |
295 | }, | |
296 | { BSM_PF_SLOW, | |
297 | #ifdef PF_SLOW | |
0a7de745 | 298 | PF_SLOW |
b0d623f7 | 299 | #else |
0a7de745 | 300 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
301 | #endif |
302 | }, | |
303 | { BSM_PF_SCLUSTER, | |
304 | #ifdef PF_SCLUSTER | |
0a7de745 | 305 | PF_SCLUSTER |
b0d623f7 | 306 | #else |
0a7de745 | 307 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
308 | #endif |
309 | }, | |
310 | { BSM_PF_ARP, | |
311 | #ifdef PF_ARP | |
0a7de745 | 312 | PF_ARP |
b0d623f7 | 313 | #else |
0a7de745 | 314 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
315 | #endif |
316 | }, | |
317 | { BSM_PF_BLUETOOTH, | |
318 | #ifdef PF_BLUETOOTH | |
0a7de745 | 319 | PF_BLUETOOTH |
b0d623f7 | 320 | #else |
0a7de745 | 321 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
322 | #endif |
323 | }, | |
324 | { BSM_PF_IEEE80211, | |
325 | #ifdef PF_IEEE80211 | |
0a7de745 | 326 | PF_IEEE80211 |
b0d623f7 | 327 | #else |
0a7de745 | 328 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
329 | #endif |
330 | }, | |
331 | { BSM_PF_AX25, | |
332 | #ifdef PF_AX25 | |
0a7de745 | 333 | PF_AX25 |
b0d623f7 | 334 | #else |
0a7de745 | 335 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
336 | #endif |
337 | }, | |
338 | { BSM_PF_ROSE, | |
339 | #ifdef PF_ROSE | |
0a7de745 | 340 | PF_ROSE |
b0d623f7 | 341 | #else |
0a7de745 | 342 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
343 | #endif |
344 | }, | |
345 | { BSM_PF_NETBEUI, | |
346 | #ifdef PF_NETBEUI | |
0a7de745 | 347 | PF_NETBEUI |
b0d623f7 | 348 | #else |
0a7de745 | 349 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
350 | #endif |
351 | }, | |
352 | { BSM_PF_SECURITY, | |
353 | #ifdef PF_SECURITY | |
0a7de745 | 354 | PF_SECURITY |
b0d623f7 | 355 | #else |
0a7de745 | 356 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
357 | #endif |
358 | }, | |
359 | { BSM_PF_PACKET, | |
360 | #ifdef PF_PACKET | |
0a7de745 | 361 | PF_PACKET |
b0d623f7 | 362 | #else |
0a7de745 | 363 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
364 | #endif |
365 | }, | |
366 | { BSM_PF_ASH, | |
367 | #ifdef PF_ASH | |
0a7de745 | 368 | PF_ASH |
b0d623f7 | 369 | #else |
0a7de745 | 370 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
371 | #endif |
372 | }, | |
373 | { BSM_PF_ECONET, | |
374 | #ifdef PF_ECONET | |
0a7de745 | 375 | PF_ECONET |
b0d623f7 | 376 | #else |
0a7de745 | 377 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
378 | #endif |
379 | }, | |
380 | { BSM_PF_ATMSVC, | |
381 | #ifdef PF_ATMSVC | |
0a7de745 | 382 | PF_ATMSVC |
b0d623f7 | 383 | #else |
0a7de745 | 384 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
385 | #endif |
386 | }, | |
387 | { BSM_PF_IRDA, | |
388 | #ifdef PF_IRDA | |
0a7de745 | 389 | PF_IRDA |
b0d623f7 | 390 | #else |
0a7de745 | 391 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
392 | #endif |
393 | }, | |
394 | { BSM_PF_PPPOX, | |
395 | #ifdef PF_PPPOX | |
0a7de745 | 396 | PF_PPPOX |
b0d623f7 | 397 | #else |
0a7de745 | 398 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
399 | #endif |
400 | }, | |
401 | { BSM_PF_WANPIPE, | |
402 | #ifdef PF_WANPIPE | |
0a7de745 | 403 | PF_WANPIPE |
b0d623f7 | 404 | #else |
0a7de745 | 405 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
406 | #endif |
407 | }, | |
408 | { BSM_PF_LLC, | |
409 | #ifdef PF_LLC | |
0a7de745 | 410 | PF_LLC |
b0d623f7 | 411 | #else |
0a7de745 | 412 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
413 | #endif |
414 | }, | |
415 | { BSM_PF_CAN, | |
416 | #ifdef PF_CAN | |
0a7de745 | 417 | PF_CAN |
b0d623f7 | 418 | #else |
0a7de745 | 419 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
420 | #endif |
421 | }, | |
422 | { BSM_PF_TIPC, | |
423 | #ifdef PF_TIPC | |
0a7de745 | 424 | PF_TIPC |
b0d623f7 | 425 | #else |
0a7de745 | 426 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
427 | #endif |
428 | }, | |
429 | { BSM_PF_IUCV, | |
430 | #ifdef PF_IUCV | |
0a7de745 | 431 | PF_IUCV |
b0d623f7 | 432 | #else |
0a7de745 | 433 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
434 | #endif |
435 | }, | |
436 | { BSM_PF_RXRPC, | |
437 | #ifdef PF_RXRPC | |
0a7de745 | 438 | PF_RXRPC |
b0d623f7 | 439 | #else |
0a7de745 | 440 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
441 | #endif |
442 | }, | |
443 | { BSM_PF_PHONET, | |
444 | #ifdef PF_PHONET | |
0a7de745 | 445 | PF_PHONET |
b0d623f7 | 446 | #else |
0a7de745 | 447 | PF_NO_LOCAL_MAPPING |
b0d623f7 A |
448 | #endif |
449 | }, | |
450 | }; | |
451 | static const int bsm_domains_count = sizeof(bsm_domains) / | |
0a7de745 | 452 | sizeof(bsm_domains[0]); |
b0d623f7 A |
453 | |
454 | static const struct bsm_domain * | |
455 | bsm_lookup_local_domain(int local_domain) | |
456 | { | |
457 | int i; | |
458 | ||
459 | for (i = 0; i < bsm_domains_count; i++) { | |
0a7de745 A |
460 | if (bsm_domains[i].bd_local_domain == local_domain) { |
461 | return &bsm_domains[i]; | |
462 | } | |
b0d623f7 | 463 | } |
0a7de745 | 464 | return NULL; |
b0d623f7 A |
465 | } |
466 | ||
467 | u_short | |
468 | au_domain_to_bsm(int local_domain) | |
469 | { | |
470 | const struct bsm_domain *bstp; | |
471 | ||
472 | bstp = bsm_lookup_local_domain(local_domain); | |
0a7de745 A |
473 | if (bstp == NULL) { |
474 | return BSM_PF_UNKNOWN; | |
475 | } | |
476 | return bstp->bd_bsm_domain; | |
b0d623f7 A |
477 | } |
478 | ||
479 | static const struct bsm_domain * | |
480 | bsm_lookup_bsm_domain(u_short bsm_domain) | |
481 | { | |
482 | int i; | |
483 | ||
484 | for (i = 0; i < bsm_domains_count; i++) { | |
0a7de745 A |
485 | if (bsm_domains[i].bd_bsm_domain == bsm_domain) { |
486 | return &bsm_domains[i]; | |
487 | } | |
b0d623f7 | 488 | } |
0a7de745 | 489 | return NULL; |
b0d623f7 A |
490 | } |
491 | ||
492 | int | |
493 | au_bsm_to_domain(u_short bsm_domain, int *local_domainp) | |
494 | { | |
495 | const struct bsm_domain *bstp; | |
496 | ||
497 | bstp = bsm_lookup_bsm_domain(bsm_domain); | |
0a7de745 A |
498 | if (bstp == NULL || bstp->bd_local_domain) { |
499 | return -1; | |
500 | } | |
b0d623f7 | 501 | *local_domainp = bstp->bd_local_domain; |
0a7de745 | 502 | return 0; |
b0d623f7 A |
503 | } |
504 | #endif /* CONFIG_AUDIT */ |