Skip to content

Commit 616abda

Browse files
committed
OVAL/probes/sysctl: Add offline capabilities
The probe will support the so-called hybrid offline mode, when the system is online (/proc contents are available) but the root filesystem is mounted elsewhere (/guest/proc/...). Support is only for Linux builds.
1 parent 6230fe5 commit 616abda

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

src/OVAL/probes/probe-table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static const probe_table_entry_t probe_table[] = {
335335
{OVAL_UNIX_SYMLINK, NULL, symlink_probe_main, NULL, symlink_probe_offline_mode_supported},
336336
#endif
337337
#ifdef OPENSCAP_PROBE_UNIX_SYSCTL
338-
{OVAL_UNIX_SYSCTL, NULL, sysctl_probe_main, NULL, NULL},
338+
{OVAL_UNIX_SYSCTL, NULL, sysctl_probe_main, NULL, sysctl_probe_offline_mode_supported},
339339
#endif
340340
#ifdef OPENSCAP_PROBE_UNIX_UNAME
341341
{OVAL_UNIX_UNAME, NULL, uname_probe_main, NULL, NULL},

src/OVAL/probes/unix/sysctl_probe.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#include <config.h>
3131
#endif
3232

33-
#include <probe-api.h>
33+
#include <probe/probe.h>
34+
#include "probe-api.h"
3435
#include "probe/entcmp.h"
3536
#include "sysctl_probe.h"
3637

@@ -40,7 +41,6 @@
4041
#include <limits.h>
4142
#include <string.h>
4243

43-
#include "oval_fts.h"
4444
#include "common/debug_priv.h"
4545

4646
#define SYSCTL_CMD "/sbin/sysctl -ae"
@@ -59,6 +59,11 @@
5959
#define PROC_SYS_DIR "/proc/sys"
6060
#define PROC_SYS_MAXDEPTH 7
6161

62+
int sysctl_probe_offline_mode_supported(void)
63+
{
64+
return PROBE_OFFLINE_OWN;
65+
}
66+
6267
int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
6368
{
6469
OVAL_FTS *ofts;
@@ -119,10 +124,11 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
119124
* collect sysctls
120125
* XXX: use direct access for the "equals" op
121126
*/
122-
ofts = oval_fts_open_prefixed(NULL, path_entity, filename_entity, NULL, bh_entity, probe_ctx_getresult(ctx));
127+
const char *prefix = getenv("OSCAP_PROBE_ROOT");
128+
ofts = oval_fts_open_prefixed(prefix, path_entity, filename_entity, NULL, bh_entity, probe_ctx_getresult(ctx));
123129

124130
if (ofts == NULL) {
125-
dE("oval_fts_open_prefixed(%s, %s) failed", PROC_SYS_DIR, ".\\+");
131+
dE("oval_fts_open_prefixed(%s, %s) (prefix: %s) failed", PROC_SYS_DIR, ".\\+", prefix);
126132
SEXP_free(path_entity);
127133
SEXP_free(filename_entity);
128134
SEXP_free(bh_entity);
@@ -283,6 +289,12 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
283289
}
284290

285291
#elif defined(OS_FREEBSD)
292+
293+
int sysctl_probe_offline_mode_supported(void)
294+
{
295+
return PROBE_OFFLINE_NONE;
296+
}
297+
286298
int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
287299
{
288300
FILE *fp;
@@ -360,9 +372,17 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
360372
pclose(fp);
361373
return (0);
362374
}
375+
363376
#else
377+
378+
int sysctl_probe_offline_mode_supported(void)
379+
{
380+
return PROBE_OFFLINE_NONE;
381+
}
382+
364383
int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
365384
{
366385
return(PROBE_EOPNOTSUPP);
367386
}
387+
368388
#endif

src/OVAL/probes/unix/sysctl_probe.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "probe-api.h"
2727

28+
int sysctl_probe_offline_mode_supported(void);
29+
2830
int sysctl_probe_main(probe_ctx *ctx, void *arg);
2931

3032
#endif /* OPENSCAP_SYSCTL_PROBE_H */

tests/probes/sysctl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
if(ENABLE_PROBES_UNIX)
22
add_oscap_test("test_sysctl_probe.sh")
33
add_oscap_test("test_sysctl_probe_all.sh")
4+
add_oscap_test("test_sysctl_probe_offline_mode.sh")
45
endif()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
. $builddir/tests/test_common.sh
4+
5+
set -e -o pipefail
6+
7+
function perform_test {
8+
probecheck "sysctl" || return 255
9+
[ $(uname) == "Linux" ] || return 255
10+
11+
result=`mktemp`
12+
stderr=`mktemp`
13+
hostname=`hostname`
14+
15+
tmpdir=$(make_temp_dir /tmp "test_offline_mode_sysctl")
16+
ln -s -t "${tmpdir}" "/proc"
17+
set_chroot_offline_test_mode "${tmpdir}"
18+
19+
$OSCAP oval eval --results $result $srcdir/test_sysctl_probe.oval.xml 2>$stderr
20+
21+
unset_chroot_offline_test_mode
22+
rm -rf "${tmpdir}"
23+
24+
[ ! -s $stderr ]
25+
assert_exists 1 "/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:sysctl_item/unix-sys:name[text()='kernel.hostname']"
26+
assert_exists 1 "/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:sysctl_item/unix-sys:value[text()='$hostname']"
27+
28+
rm $result
29+
rm $stderr
30+
}
31+
32+
perform_test

0 commit comments

Comments
 (0)