1 This patch provides the system info probe functionality for solaris. It |
|
2 detects the ethernet network interfaces and MAC and IP addresses associated |
|
3 with them. |
|
4 This patch has not been contributed upstream, but is planned to be done by |
|
5 2013-Jul-12. |
|
6 |
|
7 --- openscap-0.9.5/src/OVAL/probes/independent/system_info.c.~1~ 2012-11-06 05:51:30.048128639 -0800 |
|
8 +++ openscap-0.9.5/src/OVAL/probes/independent/system_info.c 2013-04-03 15:04:36.221945232 -0700 |
|
9 @@ -92,7 +92,73 @@ |
|
10 |
|
11 return mac_buf; |
|
12 } |
|
13 +#else if defined(__SVR4) && defined(__sun) |
|
14 +#include <sys/socket.h> |
|
15 +#include <ifaddrs.h> |
|
16 +#include <netdb.h> |
|
17 +#include <sys/ioctl.h> |
|
18 +#include <string.h> |
|
19 +#include <net/if.h> |
|
20 +#include <arpa/inet.h> |
|
21 +#include <sys/sockio.h> |
|
22 +#include <net/if_types.h> |
|
23 +#include <libdlpi.h> |
|
24 |
|
25 +static int fd=-1; |
|
26 + |
|
27 +static char *get_mac(const struct ifaddrs *ifa) |
|
28 +{ |
|
29 + struct lifreq lifr; |
|
30 + uint_t physaddrlen = DLPI_PHYSADDR_MAX; |
|
31 + uchar_t physaddr[DLPI_PHYSADDR_MAX]; |
|
32 + static char mac_buf[DLPI_PHYSADDR_MAX]; |
|
33 + char *str; |
|
34 + int retv; |
|
35 + dlpi_handle_t dh; |
|
36 + dlpi_info_t dlinfo; |
|
37 + |
|
38 + memset(mac_buf, 0, sizeof(mac_buf)); |
|
39 + memset(&lifr, 0, sizeof(struct lifreq)); |
|
40 + strlcpy(lifr.lifr_name, ifa->ifa_name, sizeof (lifr.lifr_name)); |
|
41 + if (ioctl(fd, SIOCGLIFFLAGS, &lifr) >= 0) { |
|
42 + |
|
43 + if (lifr.lifr_flags & (IFF_VIRTUAL| IFF_IPMP)) |
|
44 + return (mac_buf); |
|
45 + |
|
46 + if (dlpi_open(lifr.lifr_name, &dh, 0) != DLPI_SUCCESS) |
|
47 + return (NULL); |
|
48 + |
|
49 + retv = dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR, physaddr, |
|
50 + &physaddrlen); |
|
51 + if (retv != DLPI_SUCCESS) { |
|
52 + dlpi_close(dh); |
|
53 + return (NULL); |
|
54 + } |
|
55 + |
|
56 + retv = dlpi_info(dh, &dlinfo, DLPI_INFO_VERSION); |
|
57 + if (retv != DLPI_SUCCESS) { |
|
58 + dlpi_close(dh); |
|
59 + return (NULL); |
|
60 + } |
|
61 + dlpi_close(dh); |
|
62 + str = _link_ntoa(physaddr, NULL, physaddrlen, IFT_OTHER); |
|
63 + |
|
64 + if (str != NULL && physaddrlen != 0) { |
|
65 + switch(dlinfo.di_mactype) { |
|
66 + case DL_IB: |
|
67 + break; |
|
68 + default: |
|
69 + strlcpy(mac_buf, str, sizeof(mac_buf)); |
|
70 + break; |
|
71 + } |
|
72 + free(str); |
|
73 + } |
|
74 + } |
|
75 + return mac_buf; |
|
76 +} |
|
77 +#endif |
|
78 + |
|
79 +#if defined(__linux__) || (defined(__SVR4) && defined(__sun)) |
|
80 static int get_ifs(SEXP_t *item) |
|
81 { |
|
82 struct ifaddrs *ifaddr, *ifa; |
|
83 @@ -119,6 +185,14 @@ |
|
84 continue; |
|
85 |
|
86 mac = get_mac(ifa); |
|
87 +#if defined(__SVR4) && defined(__sun) |
|
88 + if (mac == NULL) { |
|
89 + rc = 1; |
|
90 + goto leave2; |
|
91 + } |
|
92 + if (mac[0] == '\0') |
|
93 + continue; |
|
94 +#endif |
|
95 if (family == AF_INET) { |
|
96 rc = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), |
|
97 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); |
|