Open SCAP Library
/home/pvrabec/project/openscap/openscap-0.7.4/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 
00068 typedef struct {
00069         FTS    *ofts_fts;
00070 
00071         char   **ofts_st_path;       
00072         uint16_t ofts_st_path_count; 
00073         uint16_t ofts_st_path_index; 
00075         pcre       *ofts_path_regex;
00076         pcre_extra *ofts_path_regex_extra;
00077         uint32_t ofts_path_op;
00078 
00079         SEXP_t *ofts_spath;
00080         SEXP_t *ofts_sfilename;
00081         SEXP_t *ofts_sfilepath;
00082 
00083         int max_depth;
00084         int direction;
00085         int recurse;
00086         int filesystem;
00087 
00088         fsdev_t *localdevs;
00089 } OVAL_FTS;
00090 
00091 #define OVAL_RECURSE_DIRECTION_NONE 0 /* default */
00092 #define OVAL_RECURSE_DIRECTION_DOWN 1
00093 #define OVAL_RECURSE_DIRECTION_UP   2
00094 
00095 #define OVAL_RECURSE_FILES    0x01
00096 #define OVAL_RECURSE_DIRS     0x02
00097 #define OVAL_RECURSE_SYMLINKS 0x04
00098 
00099 #define OVAL_RECURSE_SYMLINKS_AND_DIRS (OVAL_RECURSE_SYMLINKS|OVAL_RECURSE_DIRS) /* default */
00100 #define OVAL_RECURSE_FILES_AND_DIRS    (OVAL_RECURSE_FILES|OVAL_RECURSE_SYMLINKS)
00101 
00102 #define OVAL_RECURSE_FS_LOCAL   0
00103 #define OVAL_RECURSE_FS_DEFINED 1
00104 #define OVAL_RECURSE_FS_ALL     2 /* default */
00105 
00106 typedef struct {
00107         char *file;
00108         size_t file_len;
00109         char *path;
00110         size_t path_len;
00111 } OVAL_FTSENT;
00112 
00113 /*
00114  * OVAL FTS public API
00115  */
00116 OVAL_FTS    *oval_fts_open(SEXP_t *path, SEXP_t *filename, SEXP_t *filepath, SEXP_t *behaviors);
00117 OVAL_FTSENT *oval_fts_read(OVAL_FTS *ofts);
00118 int          oval_fts_close(OVAL_FTS *ofts);
00119 
00120 void oval_ftsent_free(OVAL_FTSENT *ofts_ent);
00121 
00122 #endif /* OVAL_FTS_H */