Open SCAP Library
oval_fts.h
1 /*
2  * Copyright 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Authors:
20  * "Daniel Kopecek" <dkopecek@redhat.com>
21  */
22 #ifndef OVAL_FTS_H
23 #define OVAL_FTS_H
24 
25 #include "oscap_platforms.h"
26 
27 #include <sexp.h>
28 #if defined(OS_SOLARIS) || defined(OS_AIX)
29 #include "fts_sun.h"
30 #else
31 #include <fts.h>
32 #endif
33 #include <pcre.h>
34 #include "fsdev.h"
35 
36 #define ENT_GET_AREF(ent, dst, attr_name, mandatory) \
37  do { \
38  if (((dst) = probe_ent_getattrval(ent, attr_name)) == NULL) { \
39  if (mandatory) { \
40  _F("Attribute `%s' is missing!\n", attr_name); \
41  return (NULL); \
42  } \
43  } \
44  } while(0)
45 
46 #define ENT_GET_STRVAL(ent, dst, dstlen, zerolen_exp) \
47  do { \
48  SEXP_t *___r; \
49  \
50  if ((___r = probe_ent_getval(ent)) == NULL) { \
51  dW("entity has no value!"); \
52  return (NULL); \
53  } else { \
54  if (!SEXP_stringp(___r)) { \
55  _F("invalid type\n"); \
56  SEXP_free(___r); \
57  return (NULL); \
58  } \
59  if (SEXP_string_length(___r) == 0) { \
60  SEXP_free(___r); \
61  zerolen_exp; \
62  } else { \
63  SEXP_string_cstr_r(___r, dst, dstlen); \
64  SEXP_free(___r); \
65  } \
66  } \
67  } while (0)
68 
69 typedef struct {
70  /* oval_fts_read_match_path() state */
71  FTS *ofts_match_path_fts;
72  FTSENT *ofts_match_path_fts_ent;
73  /* oval_fts_read_recurse_path() state */
74  FTS *ofts_recurse_path_fts;
75  int ofts_recurse_path_fts_opts;
76  int ofts_recurse_path_curdepth;
77  char *ofts_recurse_path_pthcpy;
78  char *ofts_recurse_path_curpth;
79  dev_t ofts_recurse_path_devid;
80 
81  pcre *ofts_path_regex;
82  pcre_extra *ofts_path_regex_extra;
83  uint32_t ofts_path_op;
84 
85  SEXP_t *ofts_spath;
86  SEXP_t *ofts_sfilename;
87  SEXP_t *ofts_sfilepath;
88  SEXP_t *result;
89 
90  int max_depth;
91  int direction;
92  int recurse;
93  int filesystem;
94  int following;
95 
96  fsdev_t *localdevs;
97  const char *prefix;
98 } OVAL_FTS;
99 
100 #define OVAL_RECURSE_DIRECTION_NONE 0 /* default */
101 #define OVAL_RECURSE_DIRECTION_DOWN 1
102 #define OVAL_RECURSE_DIRECTION_UP 2
103 
104 #define OVAL_RECURSE_FILES 0x01
105 #define OVAL_RECURSE_DIRS 0x02
106 #define OVAL_RECURSE_SYMLINKS 0x04
107 
108 #define OVAL_RECURSE_SYMLINKS_AND_DIRS (OVAL_RECURSE_SYMLINKS|OVAL_RECURSE_DIRS) /* default */
109 #define OVAL_RECURSE_FILES_AND_DIRS (OVAL_RECURSE_FILES|OVAL_RECURSE_SYMLINKS)
110 
111 #define OVAL_RECURSE_FS_LOCAL 0
112 #define OVAL_RECURSE_FS_DEFINED 1
113 #define OVAL_RECURSE_FS_ALL 2 /* default */
114 
115 typedef struct {
116  char *file;
117  size_t file_len;
118  char *path;
119  size_t path_len;
120  unsigned int fts_info;
121 } OVAL_FTSENT;
122 
123 /*
124  * OVAL FTS public API
125  */
126 OVAL_FTS *oval_fts_open_prefixed(const char *prefix, SEXP_t *path, SEXP_t *filename, SEXP_t *filepath, SEXP_t *behaviors, SEXP_t* result);
127 OVAL_FTS *oval_fts_open(SEXP_t *path, SEXP_t *filename, SEXP_t *filepath, SEXP_t *behaviors, SEXP_t* result);
128 OVAL_FTSENT *oval_fts_read(OVAL_FTS *ofts);
129 int oval_fts_close(OVAL_FTS *ofts);
130 
131 void oval_ftsent_free(OVAL_FTSENT *ofts_ent);
132 
133 #endif /* OVAL_FTS_H */
fsdev header file
Definition: fts_sun.h:84
Definition: oval_fts.h:115
Definition: oval_fts.h:69
Definition: sexp-types.h:82
Definition: fts_sun.h:132
Filesystem device structure.
Definition: fsdev.h:45