Open SCAP Library
/home/pvrabec/project/openscap/openscap-0.8.0/src/OVAL/probes/oval_fts.h
00001 /*
00002  * Copyright 2010 Red Hat Inc., Durham, North Carolina.
00003  * All Rights Reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  * Authors:
00020  *      "Daniel Kopecek" <dkopecek@redhat.com>
00021  */
00022 #ifndef OVAL_FTS_H
00023 #define OVAL_FTS_H
00024 
00025 #include <sexp.h>
00026 #if defined(__SVR4) && defined(__sun)
00027 #include "fts_sun.h"
00028 #else
00029 #include <fts.h>
00030 #endif
00031 #include <pcre.h>
00032 #include "fsdev.h"
00033 
00034 #define ENT_GET_AREF(ent, dst, attr_name, mandatory)                    \
00035         do {                                                            \
00036                 if (((dst) = probe_ent_getattrval(ent, attr_name)) == NULL) { \
00037                         if (mandatory) {                                \
00038                                 _F("Attribute `%s' is missing!\n", attr_name); \
00039                                 return (NULL);                          \
00040                         }                                               \
00041                 }                                                       \
00042         } while(0)
00043 
00044 #define ENT_GET_STRVAL(ent, dst, dstlen, zerolen_exp)                   \
00045         do {                                                    \
00046                 SEXP_t *___r;                                   \
00047                                                                 \
00048                 if ((___r = probe_ent_getval(ent)) == NULL) {   \
00049                         _W("entity has no value!\n");           \
00050                         return (NULL);                          \
00051                 } else {                                        \
00052                         if (!SEXP_stringp(___r)) {              \
00053                                 _F("invalid type\n");           \
00054                                 SEXP_free(___r);                \
00055                                 return (NULL);                  \
00056                         }                                       \
00057                         if (SEXP_string_length(___r) == 0) {    \
00058                                 SEXP_free(___r);                \
00059                                 zerolen_exp;                    \
00060                         } else {                                \
00061                                 SEXP_string_cstr_r(___r, dst, dstlen); \
00062                                 SEXP_free(___r);                \
00063                         }                                       \
00064                 }                                               \
00065         } while (0)
00066 
00067 typedef struct {
00068         /* oval_fts_read_match_path() state */
00069         FTS *ofts_match_path_fts;
00070         FTSENT *ofts_match_path_fts_ent;
00071         /* oval_fts_read_recurse_path() state */
00072         FTS *ofts_recurse_path_fts;
00073         int ofts_recurse_path_fts_opts;
00074         int ofts_recurse_path_curdepth;
00075         char *ofts_recurse_path_pthcpy;
00076         char *ofts_recurse_path_curpth;
00077         dev_t ofts_recurse_path_devid;
00078 
00079         char   **ofts_st_path;       
00080         uint16_t ofts_st_path_count; 
00081         uint16_t ofts_st_path_index; 
00083         pcre       *ofts_path_regex;
00084         pcre_extra *ofts_path_regex_extra;
00085         uint32_t ofts_path_op;
00086 
00087         SEXP_t *ofts_spath;
00088         SEXP_t *ofts_sfilename;
00089         SEXP_t *ofts_sfilepath;
00090 
00091         int max_depth;
00092         int direction;
00093         int recurse;
00094         int filesystem;
00095 
00096         fsdev_t *localdevs;
00097 } OVAL_FTS;
00098 
00099 #define OVAL_RECURSE_DIRECTION_NONE 0 /* default */
00100 #define OVAL_RECURSE_DIRECTION_DOWN 1
00101 #define OVAL_RECURSE_DIRECTION_UP   2
00102 
00103 #define OVAL_RECURSE_FILES    0x01
00104 #define OVAL_RECURSE_DIRS     0x02
00105 #define OVAL_RECURSE_SYMLINKS 0x04
00106 
00107 #define OVAL_RECURSE_SYMLINKS_AND_DIRS (OVAL_RECURSE_SYMLINKS|OVAL_RECURSE_DIRS) /* default */
00108 #define OVAL_RECURSE_FILES_AND_DIRS    (OVAL_RECURSE_FILES|OVAL_RECURSE_SYMLINKS)
00109 
00110 #define OVAL_RECURSE_FS_LOCAL   0
00111 #define OVAL_RECURSE_FS_DEFINED 1
00112 #define OVAL_RECURSE_FS_ALL     2 /* default */
00113 
00114 typedef struct {
00115         char *file;
00116         size_t file_len;
00117         char *path;
00118         size_t path_len;
00119 } OVAL_FTSENT;
00120 
00121 /*
00122  * OVAL FTS public API
00123  */
00124 OVAL_FTS    *oval_fts_open(SEXP_t *path, SEXP_t *filename, SEXP_t *filepath, SEXP_t *behaviors);
00125 OVAL_FTSENT *oval_fts_read(OVAL_FTS *ofts);
00126 int          oval_fts_close(OVAL_FTS *ofts);
00127 
00128 void oval_ftsent_free(OVAL_FTSENT *ofts_ent);
00129 
00130 #endif /* OVAL_FTS_H */