Skip to content

Commit 3d5bed4

Browse files
committed
Merge branch 'maint-1.2' into maint-1.3
Conflicts: src/OVAL/probes/findfile.c src/OVAL/probes/fsdev.c tests/API/probes/Makefile.am tests/DS/Makefile.am
2 parents aa0b73b + 6363562 commit 3d5bed4

File tree

12 files changed

+318
-177
lines changed

12 files changed

+318
-177
lines changed

cpe/openscap-cpe-dict.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@
121121
<title xml:lang="en-us">Fedora 30</title>
122122
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="openscap-cpe-oval.xml">oval:org.open-scap.cpe.fedora:def:30</check>
123123
</cpe-item>
124+
<cpe-item name="cpe:/o:fedoraproject:fedora:31">
125+
<title xml:lang="en-us">Fedora 31</title>
126+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="openscap-cpe-oval.xml">oval:org.open-scap.cpe.fedora:def:31</check>
127+
</cpe-item>
124128
<cpe-item name="cpe:/o:suse:sle">
125129
<title xml:lang="en-us">SUSE Linux Enterprise all versions</title>
126130
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5" href="openscap-cpe-oval.xml">oval:org.open-scap.cpe.sle:def:1</check>

cpe/openscap-cpe-oval.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,20 @@
406406
<criterion comment="Fedora 30 is installed" test_ref="oval:org.open-scap.cpe.fedora:tst:30"/>
407407
</criteria>
408408
</definition>
409+
<definition class="inventory" id="oval:org.open-scap.cpe.fedora:def:31" version="1">
410+
<metadata>
411+
<title>Fedora 31</title>
412+
<affected family="unix">
413+
<platform>Fedora 31</platform>
414+
</affected>
415+
<reference ref_id="cpe:/o:fedoraproject:fedora:31" source="CPE"/>
416+
<description>The operating system installed on the system is Fedora 31</description>
417+
</metadata>
418+
<criteria>
419+
<criterion comment="Fedora 31 is installed" test_ref="oval:org.open-scap.cpe.fedora:tst:31"/>
420+
</criteria>
421+
</definition>
422+
409423

410424
<definition class="inventory" id="oval:org.open-scap.cpe.sle:def:1" version="1">
411425
<metadata>
@@ -880,6 +894,11 @@
880894
<object object_ref="oval:org.open-scap.cpe.fedora-release:obj:2"/>
881895
<state state_ref="oval:org.open-scap.cpe.fedora:ste:30"/>
882896
</rpminfo_test>
897+
<rpminfo_test check_existence="at_least_one_exists" id="oval:org.open-scap.cpe.fedora:tst:31" version="1" check="at least one" comment="fedora-release is version Fedora 31"
898+
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
899+
<object object_ref="oval:org.open-scap.cpe.fedora-release:obj:2"/>
900+
<state state_ref="oval:org.open-scap.cpe.fedora:ste:31"/>
901+
</rpminfo_test>
883902
<rpminfo_test check_existence="at_least_one_exists" id="oval:org.open-scap.cpe.sles:tst:1" version="1" check="at least one" comment="/etc/sles-release is provided by sles-release package"
884903
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
885904
<object object_ref="oval:org.open-scap.cpe.sles-release:obj:1"/>
@@ -1188,6 +1207,9 @@
11881207
<rpminfo_state id="oval:org.open-scap.cpe.fedora:ste:30" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
11891208
<version operation="pattern match">^30$</version>
11901209
</rpminfo_state>
1210+
<rpminfo_state id="oval:org.open-scap.cpe.fedora:ste:31" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
1211+
<version operation="pattern match">^31$</version>
1212+
</rpminfo_state>
11911213
<rpminfo_state id="oval:org.open-scap.cpe.sles:ste:1" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux">
11921214
<name operation="pattern match">^sles-release</name>
11931215
</rpminfo_state>

src/DS/sds.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ static int ds_sds_dump_component_by_href(struct ds_sds_session *session, char* x
420420
}
421421

422422
ds_sds_session_remote_resources_progress(session)(true, "WARNING: Skipping '%s' file which is referenced from datastream\n", url);
423+
// -2 means that remote resources were not downloaded
423424
return -2;
424425
}
425426

@@ -452,8 +453,12 @@ int ds_sds_dump_component_ref_as(const xmlNodePtr component_ref, struct ds_sds_s
452453
xmlFree(xlink_href);
453454
xmlFree(cref_id);
454455

455-
if (ret != 0) {
456-
456+
if (ret == -2) {
457+
// A remote component was not dumped
458+
// It should be ok to continue without it
459+
free(target_filename_dirname);
460+
return 0;
461+
} else if (ret != 0) {
457462
free(target_filename_dirname);
458463
return -1;
459464
}

src/OVAL/probes/fsdev.c

Lines changed: 34 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -71,58 +71,32 @@ static int fsdev_cmp(const void *a, const void *b)
7171
return memcmp(a, b, sizeof(dev_t));
7272
}
7373

74-
/**
75-
* Compare two strings.
76-
*/
77-
static int fsname_cmp(const void *a, const void *b)
78-
{
79-
return strcmp(a, b);
80-
}
81-
82-
/**
83-
* Search for a filesystem name in a sorted array using binary search.
84-
* @param fsname name
85-
* @param fs_arr sorted array of filesystem names
86-
* @param fs_cnt number of names in the array
87-
* @retval 1 if found
88-
* @retval 0 otherwise
89-
*/
90-
static int match_fs(const char *fsname, const char **fs_arr, size_t fs_cnt)
91-
{
92-
size_t w, s;
93-
int cmp;
94-
95-
w = fs_cnt;
96-
s = 0;
97-
98-
while (w > 0) {
99-
cmp = fsname_cmp(fsname, fs_arr[s + w / 2]);
100-
if (cmp > 0) {
101-
s += w / 2 + 1;
102-
w = w - w / 2 - 1;
103-
} else if (cmp < 0) {
104-
w = w / 2;
105-
} else {
106-
return (1);
107-
}
108-
}
109-
110-
return (0);
111-
}
112-
11374
#if defined(OS_LINUX) || defined(OS_AIX)
11475

11576
#define DEVID_ARRAY_SIZE 16
11677
#define DEVID_ARRAY_ADD 8
11778

11879
#if defined(OS_LINUX)
119-
static int
120-
is_local_fs(struct mntent *ment)
80+
int is_local_fs(struct mntent *ment)
12181
{
12282
// todo: would it be usefull to provide the choice during build-time?
12383
#if 1
12484
char *s;
12585

86+
/*
87+
* When type of the filesystem is autofs, it means the mtab entry
88+
* describes the autofs configuration, which means ment->mnt_fsname
89+
* is a path to the relevant autofs map, eg. /etc/auto.misc. In this
90+
* situation, the following code which analyses ment->mnt_type would
91+
* not work. When the filesystem handled by autofs is mounted, there
92+
* is another different entry in mtab which contains the real block
93+
* special device or remote filesystem in ment->mnt_fsname, and that
94+
* will be parsed in a different call of this function.
95+
*/
96+
if (!strcmp(ment->mnt_type, "autofs")) {
97+
return 0;
98+
}
99+
126100
s = ment->mnt_fsname;
127101
/* If the fsname begins with "//", it is probably CIFS. */
128102
if (s[0] == '/' && s[1] == '/')
@@ -153,8 +127,7 @@ is_local_fs(struct mntent *ment)
153127
}
154128

155129
#elif defined(OS_AIX)
156-
static int
157-
is_local_fs(struct mntent *ment)
130+
int is_local_fs(struct mntent *ment)
158131
{
159132
int i;
160133
struct vfs_ent *e;
@@ -183,7 +156,7 @@ is_local_fs(struct mntent *ment)
183156

184157
#endif /* OS_AIX */
185158

186-
static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
159+
static fsdev_t *__fsdev_init(fsdev_t *lfs)
187160
{
188161
int e;
189162
FILE *fp;
@@ -214,12 +187,8 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
214187
i = 0;
215188

216189
while ((ment = getmntent(fp)) != NULL) {
217-
if (fs == NULL) {
218-
if (!is_local_fs(ment))
219-
continue;
220-
} else if (!match_fs(ment->mnt_type, fs, fs_cnt)) {
221-
continue;
222-
}
190+
if (!is_local_fs(ment))
191+
continue;
223192
if (stat(ment->mnt_dir, &st) != 0)
224193
continue;
225194
if (i >= lfs->cnt) {
@@ -237,7 +206,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
237206
return (lfs);
238207
}
239208
#elif defined(OS_FREEBSD) || defined(OS_APPLE)
240-
static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
209+
static fsdev_t *__fsdev_init(fsdev_t *lfs)
241210
{
242211
struct statfs *mntbuf = NULL;
243212
struct stat st;
@@ -246,20 +215,11 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
246215
lfs->cnt = getmntinfo(&mntbuf, (fs == NULL ? MNT_LOCAL : 0) | MNT_NOWAIT);
247216
lfs->ids = malloc(sizeof(dev_t) * lfs->cnt);
248217

249-
if (fs == NULL) {
250-
for (i = 0; i < lfs->cnt; ++i) {
251-
if (stat(mntbuf[i].f_mntonname, &st) != 0)
252-
continue;
253-
254-
memcpy(&(lfs->ids[i]), &st.st_dev, sizeof(dev_t));
255-
}
256-
} else {
257-
for (i = 0; i < lfs->cnt; ++i) {
258-
if (!match_fs(mntbuf[i].f_fstypename, fs, fs_cnt))
259-
continue;
218+
for (i = 0; i < lfs->cnt; ++i) {
219+
if (stat(mntbuf[i].f_mntonname, &st) != 0)
220+
continue;
260221

261-
memcpy(&(lfs->ids[i]), &st.st_dev, sizeof(dev_t));
262-
}
222+
memcpy(&(lfs->ids[i]), &st.st_dev, sizeof(dev_t));
263223
}
264224

265225
if (i != lfs->cnt) {
@@ -274,7 +234,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
274234
#define DEVID_ARRAY_SIZE 16
275235
#define DEVID_ARRAY_ADD 8
276236

277-
static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
237+
static fsdev_t *__fsdev_init(fsdev_t *lfs)
278238
{
279239
int e;
280240
FILE *fp;
@@ -304,31 +264,16 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
304264
lfs->cnt = DEVID_ARRAY_SIZE;
305265
i = 0;
306266

307-
if (fs == NULL) {
308-
while ((getmntent(fp, &mentbuf)) == 0) {
309-
/* TODO: Is this check reliable? */
310-
if (stat (mentbuf.mnt_special, &st) == 0 && (st.st_mode & S_IFCHR)) {
311-
312-
if (i >= lfs->cnt) {
313-
lfs->cnt += DEVID_ARRAY_ADD;
314-
lfs->ids = realloc(lfs->ids, sizeof(dev_t) * lfs->cnt);
315-
}
267+
while ((getmntent(fp, &mentbuf)) == 0) {
268+
/* TODO: Is this check reliable? */
269+
if (stat(mentbuf.mnt_special, &st) == 0 && (st.st_mode & S_IFCHR)) {
316270

317-
memcpy(&(lfs->ids[i++]), &st.st_dev, sizeof(dev_t));
271+
if (i >= lfs->cnt) {
272+
lfs->cnt += DEVID_ARRAY_ADD;
273+
lfs->ids = realloc(lfs->ids, sizeof(dev_t) * lfs->cnt);
318274
}
319-
}
320-
} else {
321-
while ((getmntent(fp, &mentbuf)) == 0) {
322-
323-
if (match_fs(mentbuf.mnt_fstype, fs, fs_cnt)) {
324275

325-
if (i >= lfs->cnt) {
326-
lfs->cnt += DEVID_ARRAY_ADD;
327-
lfs->ids = realloc(lfs->ids, sizeof(dev_t) * lfs->cnt);
328-
}
329-
330-
memcpy(&(lfs->ids[i++]), &st.st_dev, sizeof(dev_t));
331-
}
276+
memcpy(&(lfs->ids[i++]), &st.st_dev, sizeof(dev_t));
332277
}
333278
}
334279

@@ -341,7 +286,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
341286
}
342287
#endif
343288

344-
fsdev_t *fsdev_init(const char **fs, size_t fs_cnt)
289+
fsdev_t *fsdev_init()
345290
{
346291
fsdev_t *lfs;
347292

@@ -350,7 +295,7 @@ fsdev_t *fsdev_init(const char **fs, size_t fs_cnt)
350295
if (lfs == NULL)
351296
return (NULL);
352297

353-
if (__fsdev_init(lfs, fs, fs_cnt) == NULL)
298+
if (__fsdev_init(lfs) == NULL)
354299
return (NULL);
355300

356301
if (lfs->ids != NULL && lfs->cnt > 1)
@@ -364,53 +309,6 @@ static inline int isfschar(int c)
364309
return (isalpha(c) || isdigit(c) || c == '-' || c == '_');
365310
}
366311

367-
fsdev_t *fsdev_strinit(const char *fs_names)
368-
{
369-
fsdev_t *lfs;
370-
char *pstr, **fs_arr;
371-
size_t fs_cnt;
372-
int state, e;
373-
374-
pstr = strdup(fs_names);
375-
state = 0;
376-
fs_arr = NULL;
377-
fs_cnt = 0;
378-
379-
while (*pstr != '\0') {
380-
switch (state) {
381-
case 0:
382-
if (isfschar(*pstr)) {
383-
state = 1;
384-
++fs_cnt;
385-
fs_arr = realloc(fs_arr, sizeof(char *) * fs_cnt);
386-
fs_arr[fs_cnt - 1] = pstr;
387-
}
388-
389-
++pstr;
390-
391-
break;
392-
case 1:
393-
if (!isfschar(*pstr) && *pstr != '\0') {
394-
state = 0;
395-
*pstr = '\0';
396-
++pstr;
397-
}
398-
break;
399-
}
400-
}
401-
402-
if (fs_arr != NULL && fs_cnt > 0)
403-
qsort(fs_arr, fs_cnt, sizeof(char *), fsname_cmp);
404-
405-
lfs = fsdev_init((const char **)fs_arr, fs_cnt);
406-
e = errno;
407-
free(fs_arr);
408-
errno = e;
409-
free(pstr);
410-
411-
return (lfs);
412-
}
413-
414312
void fsdev_free(fsdev_t * lfs)
415313
{
416314
if (lfs != NULL) {

src/OVAL/probes/fsdev.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include <sys/stat.h>
3636
#include "oscap_export.h"
3737

38+
#if defined(__linux__) || defined(_AIX)
39+
#include <mntent.h>
40+
#endif
41+
3842
/**
3943
* Filesystem device structure.
4044
*/
@@ -47,13 +51,7 @@ typedef struct {
4751
* Initialize the fsdev_t structure from an array of filesystem
4852
* names.
4953
*/
50-
fsdev_t *fsdev_init(const char **fs, size_t fs_cnt);
51-
52-
/**
53-
* Initialize the fsdev_t structure from a string containing filesystem
54-
* names.
55-
*/
56-
fsdev_t *fsdev_strinit(const char *fs_names);
54+
fsdev_t *fsdev_init(void);
5755

5856
/**
5957
* Free the fsdev_t structure.
@@ -87,4 +85,14 @@ int fsdev_path(fsdev_t *lfs, const char *path);
8785
*/
8886
int fsdev_fd(fsdev_t *lfs, int fd);
8987

88+
#if defined(__linux__) || defined(_AIX)
89+
/**
90+
* Detemines whether a given mtab entry is a local file system.
91+
* @param ment Structure returned by getmntent (see `man 3 getmntent`).
92+
* @retval 1 if local
93+
* @retval 0 otherwise
94+
*/
95+
int is_local_fs(struct mntent *ment);
96+
#endif
97+
9098
#endif /* FSDEV_H */

0 commit comments

Comments
 (0)