Skip to content

Commit ea04516

Browse files
committed
Add offline mode in yamlfilecontent probe
1 parent 72c8512 commit ea04516

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/OVAL/probes/independent/yamlfilecontent_probe.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
#include "debug_priv.h"
3434
#include "oval_fts.h"
3535
#include "list.h"
36+
#include "probe/probe.h"
3637

38+
int yamlfilecontent_probe_offline_mode_supported()
39+
{
40+
return PROBE_OFFLINE_OWN;
41+
}
3742

3843
static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, struct oscap_list *values, probe_ctx *ctx)
3944
{
@@ -125,13 +130,14 @@ static int yaml_path_query(const char *filepath, const char *yaml_path_cstr, str
125130
return ret;
126131
}
127132

128-
static int process_yaml_file(const char *path, const char *filename, const char *yamlpath, probe_ctx *ctx)
133+
static int process_yaml_file(const char *prefix, const char *path, const char *filename, const char *yamlpath, probe_ctx *ctx)
129134
{
130135
int ret = 0;
131136
char *filepath = oscap_path_join(path, filename);
132137
struct oscap_list *values = oscap_list_new();
138+
char *filepath_with_prefix = oscap_path_join(prefix, filepath);
133139

134-
if (yaml_path_query(filepath, yamlpath, values, ctx)) {
140+
if (yaml_path_query(filepath_with_prefix, yamlpath, values, ctx)) {
135141
ret = -1;
136142
goto cleanup;
137143
}
@@ -160,6 +166,7 @@ static int process_yaml_file(const char *path, const char *filename, const char
160166

161167
cleanup:
162168
oscap_list_free(values, free);
169+
free(filepath_with_prefix);
163170
free(filepath);
164171
return ret;
165172
}
@@ -176,16 +183,17 @@ int yamlfilecontent_probe_main(probe_ctx *ctx, void *arg)
176183
char *yamlpath_str = SEXP_string_cstr(yamlpath_val);
177184

178185
probe_filebehaviors_canonicalize(&behaviors_ent);
186+
const char *prefix = getenv("OSCAP_PROBE_ROOT");
179187
OVAL_FTS *ofts = oval_fts_open_prefixed(
180-
NULL, path_ent, filename_ent, filepath_ent, behaviors_ent,
188+
prefix, path_ent, filename_ent, filepath_ent, behaviors_ent,
181189
probe_ctx_getresult(ctx));
182190
if (ofts != NULL) {
183191
OVAL_FTSENT *ofts_ent;
184192
while ((ofts_ent = oval_fts_read(ofts)) != NULL) {
185193
if (ofts_ent->fts_info == FTS_F
186194
|| ofts_ent->fts_info == FTS_SL) {
187-
process_yaml_file(
188-
ofts_ent->path, ofts_ent->file, yamlpath_str, ctx);
195+
process_yaml_file(prefix, ofts_ent->path, ofts_ent->file,
196+
yamlpath_str, ctx);
189197
}
190198
oval_ftsent_free(ofts_ent);
191199
}

src/OVAL/probes/independent/yamlfilecontent_probe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "probe-api.h"
2727

28+
int yamlfilecontent_probe_offline_mode_supported(void);
2829
int yamlfilecontent_probe_main(probe_ctx *ctx, void *arg);
2930

3031
#endif /* OPENSCAP_YAMLFILECONTENT_PROBE_H */

src/OVAL/probes/probe-table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static const probe_table_entry_t probe_table[] = {
250250
{OVAL_INDEPENDENT_XML_FILE_CONTENT, xmlfilecontent_probe_init, xmlfilecontent_probe_main, xmlfilecontent_probe_fini, xmlfilecontent_probe_offline_mode_supported},
251251
#endif
252252
#ifdef OPENSCAP_PROBE_INDEPENDENT_YAMLFILECONTENT
253-
{OVAL_INDEPENDENT_YAML_FILE_CONTENT, NULL, yamlfilecontent_probe_main, NULL, NULL},
253+
{OVAL_INDEPENDENT_YAML_FILE_CONTENT, NULL, yamlfilecontent_probe_main, NULL, yamlfilecontent_probe_offline_mode_supported},
254254
#endif
255255
#ifdef OPENSCAP_PROBE_LINUX_DPKGINFO
256256
{OVAL_LINUX_DPKG_INFO, dpkginfo_probe_init, dpkginfo_probe_main, dpkginfo_probe_fini, dpkginfo_probe_offline_mode_supported},

0 commit comments

Comments
 (0)