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