Open SCAP Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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)) || defined(_AIX)
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!"); \
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  pcre *ofts_path_regex;
80  pcre_extra *ofts_path_regex_extra;
81  uint32_t ofts_path_op;
82 
83  SEXP_t *ofts_spath;
84  SEXP_t *ofts_sfilename;
85  SEXP_t *ofts_sfilepath;
86  SEXP_t *result;
87 
88  int max_depth;
89  int direction;
90  int recurse;
91  int filesystem;
92 
93  fsdev_t *localdevs;
94  const char *prefix;
95 } OVAL_FTS;
96 
97 #define OVAL_RECURSE_DIRECTION_NONE 0 /* default */
98 #define OVAL_RECURSE_DIRECTION_DOWN 1
99 #define OVAL_RECURSE_DIRECTION_UP 2
100 
101 #define OVAL_RECURSE_FILES 0x01
102 #define OVAL_RECURSE_DIRS 0x02
103 #define OVAL_RECURSE_SYMLINKS 0x04
104 
105 #define OVAL_RECURSE_SYMLINKS_AND_DIRS (OVAL_RECURSE_SYMLINKS|OVAL_RECURSE_DIRS) /* default */
106 #define OVAL_RECURSE_FILES_AND_DIRS (OVAL_RECURSE_FILES|OVAL_RECURSE_SYMLINKS)
107 
108 #define OVAL_RECURSE_FS_LOCAL 0
109 #define OVAL_RECURSE_FS_DEFINED 1
110 #define OVAL_RECURSE_FS_ALL 2 /* default */
111 
112 typedef struct {
113  char *file;
114  size_t file_len;
115  char *path;
116  size_t path_len;
117  unsigned int fts_info;
118 } OVAL_FTSENT;
119 
120 /*
121  * OVAL FTS public API
122  */
123 OVAL_FTS *oval_fts_open_prefixed(const char *prefix, SEXP_t *path, SEXP_t *filename, SEXP_t *filepath, SEXP_t *behaviors, SEXP_t* result);
124 OVAL_FTS *oval_fts_open(SEXP_t *path, SEXP_t *filename, SEXP_t *filepath, SEXP_t *behaviors, SEXP_t* result);
125 OVAL_FTSENT *oval_fts_read(OVAL_FTS *ofts);
126 int oval_fts_close(OVAL_FTS *ofts);
127 
128 void oval_ftsent_free(OVAL_FTSENT *ofts_ent);
129 
130 #endif /* OVAL_FTS_H */
Definition: oval_fts.h:112
fsdev API public header file
Definition: oval_fts.h:67
Definition: fts_sun.h:84
Definition: fts_sun.h:132
Filesystem device structure.
Definition: fsdev.h:42
Definition: sexp-types.h:82