Skip to content

Commit fff5819

Browse files
committed
Test is_local_fs
Adds a simple unit test that checks whether autofs entries in /etc/mtab are not considered local.
1 parent 309f823 commit fff5819

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

src/OVAL/probes/fsdev.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ static int match_fs(const char *fsname, const char **fs_arr, size_t fs_cnt)
118118
#define DEVID_ARRAY_ADD 8
119119

120120
#if defined(__linux__)
121-
static int
122-
is_local_fs(struct mntent *ment)
121+
int is_local_fs(struct mntent *ment)
123122
{
124123
// todo: would it be usefull to provide the choice during build-time?
125124
#if 1
@@ -169,8 +168,7 @@ is_local_fs(struct mntent *ment)
169168
}
170169

171170
#elif defined(_AIX)
172-
static int
173-
is_local_fs(struct mntent *ment)
171+
int is_local_fs(struct mntent *ment)
174172
{
175173
int i;
176174
struct vfs_ent *e;

src/OVAL/probes/public/fsdev.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include <stdint.h>
3737
#include <sys/stat.h>
3838

39+
#if defined(__linux__) || defined(_AIX)
40+
#include <mntent.h>
41+
#endif
42+
3943
/**
4044
* Filesystem device structure.
4145
*/
@@ -88,5 +92,15 @@ int fsdev_path(fsdev_t * lfs, const char *path);
8892
*/
8993
int fsdev_fd(fsdev_t * lfs, int fd);
9094

95+
#if defined(__linux__) || defined(_AIX)
96+
/**
97+
* Detemines whether a given mtab entry is a local file system.
98+
* @param ment Structure returned by getmntent (see `man 3 getmntent`).
99+
* @retval 1 if local
100+
* @retval 0 otherwise
101+
*/
102+
int is_local_fs(struct mntent *ment);
103+
#endif
104+
91105
#endif /* FSDEV_H */
92106
/// @}

tests/API/probes/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ TESTS_ENVIRONMENT = \
2626
$(top_builddir)/run
2727

2828
TESTS = all.sh
29-
check_PROGRAMS = test_api_probes_smoke oval_fts_list
29+
check_PROGRAMS = test_api_probes_smoke oval_fts_list test_fsdev_is_local_fs
3030

3131
test_api_probes_smoke_SOURCES = test_api_probes_smoke.c
3232
oval_fts_list_CFLAGS= -I$(top_srcdir)/src/OVAL/probes
3333
oval_fts_list_SOURCES= oval_fts_list.c
34+
test_fsdev_is_local_fs_SOURCES = test_fsdev_is_local_fs.c
3435

3536
EXTRA_DIST += \
3637
all.sh \
3738
fts.sh \
3839
gentree.sh \
39-
test_api_probes_smoke.c
40+
test_api_probes_smoke.c \
41+
test_fsdev_is_local_fs.c

tests/API/probes/all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_init "test_api_probes.log"
77
if [ -z ${CUSTOM_OSCAP+x} ] ; then
88
test_run "fts test" $srcdir/fts.sh
99
test_run "probe api smoke test" ./test_api_probes_smoke
10+
test_run "fsdev is_local_fs unit test" ./test_fsdev_is_local_fs
1011
fi
1112

1213
test_exit
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2019 Red Hat Inc., Durham, North Carolina.
3+
* All Rights Reserved.
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
*
19+
* Authors:
20+
* "Jan Černý" <[email protected]>
21+
*/
22+
23+
#ifdef HAVE_CONFIG_H
24+
#include <config.h>
25+
#endif
26+
27+
#include <stdio.h>
28+
#include <string.h>
29+
#include <mntent.h>
30+
#include "fsdev.h"
31+
32+
int main(int argc, char *argv[])
33+
{
34+
struct mntent ment;
35+
ment.mnt_type = "autofs";
36+
int ret = is_local_fs(&ment);
37+
if (ret != 0) {
38+
return 1;
39+
}
40+
return 0;
41+
}

0 commit comments

Comments
 (0)