Debian Codegraph @

src/OVAL/probes/unix/solaris/isainfo_probe.c

raw symbols SCIP
1 /**
2 * @file isainfo_probe.c
3 * @brief isainfo probe
4 * @author "Ryan E Haggerty" <[email protected]
5 *
6 * 2011/05/06 [email protected]
7 *
8 * This probe relates to the instruction set architecture of a system and
9 * returns the following:
10 * *isainfo_object
11 * Due to its very nature, a system has exactly one item that can be returned,
12 * therefore there are no attributes to define in the object declaration.
13 */
14
15 /*
16 * Copyright (c) 2011 Tresys Technology LLC, Columbia, Maryland, USA
17 *
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
22 *
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with this library; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 */
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36
37 #include "probe-api.h"
38 #include <stdlib.h>
39 #include <string.h>
40 #include <stdio.h>
41 #include <stdio_ext.h>
42 #include <errno.h>
43 #include <dirent.h>
44 #include <fcntl.h>
45 #include <netdb.h>
46 #include <arpa/inet.h>
47 #include <regex.h>
48 #include <sys/systeminfo.h>
49 #include "../../../../common/debug_priv.h"
50 #include "isainfo_probe.h"
51
52 /* man sysinfo (2) recommends using 257 for this size */
53 #define MAX_STR_RESULT 257
54
55 struct result_info {
56 unsigned int bits;
57 char kernel_isa[MAX_STR_RESULT];
58 char application_isa[MAX_STR_RESULT];
59 };
60
61
62 static void report_finding(struct result_info *res, probe_ctx *ctx)
63 {
64 SEXP_t *item;
65
66 item = probe_item_create(OVAL_SOLARIS_ISAINFO, NULL,
67 "bits", OVAL_DATATYPE_INTEGER, (int64_t)res->bits,
68 "kernel_isa", OVAL_DATATYPE_STRING, res->kernel_isa,
69 "application_isa", OVAL_DATATYPE_STRING, res->application_isa,
70 NULL);
71 probe_item_collect(ctx, item);
72 }
73
74 int read_sysinfo(probe_ctx *ctx) {
75 dD("In read_sysinfo for isainfo probe");
76
77 int err = 1;
78 int ret = 0;
79 char tmp_buf[MAX_STR_RESULT];
80 struct result_info result;
81
82 /* sysinfo returns -1 on failure according to man sysinfo (2) */
83
84 ret = sysinfo(SI_ARCHITECTURE_64, tmp_buf, MAX_STR_RESULT);
85
86 if (ret != -1) {
87 result.bits = 64;
88 }
89 else {
90 result.bits = 32;
91 }
92
93 if (sysinfo(SI_ARCHITECTURE_K, result.kernel_isa, MAX_STR_RESULT) == -1) {
94 return err;
95 }
96 #if defined(OS_SOLARIS)
97 if ((sysinfo(SI_ARCHITECTURE_32, result.application_isa, MAX_STR_RESULT) == -1) &&
98 (sysinfo(SI_ARCHITECTURE_64, result.application_isa, MAX_STR_RESULT) == -1)) {
99 #else
100 if (sysinfo(SI_ARCHITECTURE_NATIVE, result.application_isa, MAX_STR_RESULT) == -1) {
101 #endif
102 return err;
103 }
104
105 /* if we made it this far, there were no errors in the sysinfo calls */
106 err = 0;
107 report_finding(&result, ctx);
108 return err;
109 }
110
111 int isainfo_probe_main(probe_ctx *ctx, void *probe_arg)
112 {
113 if (read_sysinfo(ctx)) {
114 return PROBE_EACCESS;
115 }
116
117 return 0;
118 }