| 1 |
|
| 2 |
#ifdef HAVE_CONFIG_H |
| 3 |
#include <config.h> |
| 4 |
#endif |
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <string.h> |
| 9 |
#include "sexp.h" |
| 10 |
#include "oval_fts.h" |
| 11 |
#include "probe-api.h" |
| 12 |
#include <stddef.h> |
| 13 |
#include <assert.h> |
| 14 |
#include "util.h" |
| 15 |
#include "public/oscap_debug.h" |
| 16 |
|
| 17 |
static int create_path_sexpr(char *arg_operation, char *arg_argument, SEXP_t **result) |
| 18 |
{ |
| 19 |
*result = NULL; |
| 20 |
|
| 21 |
|
| 22 |
if (strlen(arg_operation) == 0 && strlen(arg_argument) == 0) { |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
int operation_number = oval_operation_from_text(arg_operation); |
| 27 |
if (operation_number <= 0 || operation_number > 255) { |
| 28 |
fprintf(stderr, "Error parsing path->operation number -- not a valid OVAL_OPERATION enum string: %s\n", arg_operation); |
| 29 |
return 1; |
| 30 |
} |
| 31 |
|
| 32 |
uint8_t operation_value = (uint8_t)(operation_number & 0xFF); |
| 33 |
|
| 34 |
SEXP_t *s_path_str = SEXP_string_new("path", 4); |
| 35 |
SEXP_t *s_operation_str = SEXP_string_new(":operation", 10); |
| 36 |
SEXP_t *s_operation_number = SEXP_number_new(SEXP_NUM_UINT8, &operation_value); |
| 37 |
SEXP_t *s_path_argument = SEXP_string_new(arg_argument, strlen(arg_argument)); |
| 38 |
SEXP_t *s_inner_list = SEXP_list_new(NULL); |
| 39 |
|
| 40 |
SEXP_list_add(s_inner_list, s_path_str); |
| 41 |
SEXP_list_add(s_inner_list, s_operation_str); |
| 42 |
SEXP_list_add(s_inner_list, s_operation_number); |
| 43 |
|
| 44 |
*result = SEXP_list_new(NULL); |
| 45 |
SEXP_list_add(*result, s_inner_list); |
| 46 |
SEXP_list_add(*result, s_path_argument); |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
static int create_filename_sexpr(char *arg_operation, char *arg_argument, SEXP_t **result) |
| 52 |
{ |
| 53 |
*result = NULL; |
| 54 |
|
| 55 |
|
| 56 |
if (strlen(arg_operation) == 0 && strlen(arg_argument) == 0) { |
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
int operation_number = oval_operation_from_text(arg_operation); |
| 61 |
if (operation_number <= 0 || operation_number > 255) { |
| 62 |
fprintf(stderr, "Error parsing path->operation number -- not a valid OVAL_OPERATION enum string: %s\n", arg_operation); |
| 63 |
return 1; |
| 64 |
} |
| 65 |
|
| 66 |
uint8_t operation_value = (uint8_t)(operation_number & 0xFF); |
| 67 |
|
| 68 |
SEXP_t *s_filename_str = SEXP_string_new("filename", 8); |
| 69 |
SEXP_t *s_operation_str = SEXP_string_new(":operation", 10); |
| 70 |
SEXP_t *s_operation_number = SEXP_number_new(SEXP_NUM_UINT8, &operation_value); |
| 71 |
SEXP_t *s_filename_argument = NULL; |
| 72 |
if (strcmp(arg_argument, "EMPTY_STRING") == 0) { |
| 73 |
s_filename_argument = SEXP_string_new("", 0); |
| 74 |
} else { |
| 75 |
s_filename_argument = SEXP_string_new(arg_argument, strlen(arg_argument)); |
| 76 |
} |
| 77 |
|
| 78 |
SEXP_t *s_inner_list = SEXP_list_new(NULL); |
| 79 |
SEXP_list_add(s_inner_list, s_filename_str); |
| 80 |
SEXP_list_add(s_inner_list, s_operation_str); |
| 81 |
SEXP_list_add(s_inner_list, s_operation_number); |
| 82 |
|
| 83 |
*result = SEXP_list_new(NULL); |
| 84 |
SEXP_list_add(*result, s_inner_list); |
| 85 |
|
| 86 |
if (strlen(arg_argument) != 0) { |
| 87 |
SEXP_list_add(*result, s_filename_argument); |
| 88 |
} |
| 89 |
|
| 90 |
SEXP_free(s_filename_str); |
| 91 |
SEXP_free(s_operation_str); |
| 92 |
SEXP_free(s_operation_number); |
| 93 |
SEXP_free(s_filename_argument); |
| 94 |
SEXP_free(s_inner_list); |
| 95 |
|
| 96 |
return 0; |
| 97 |
} |
| 98 |
|
| 99 |
static int create_filepath_sexpr(char *arg_operation, char *arg_argument, SEXP_t **result) |
| 100 |
{ |
| 101 |
*result = NULL; |
| 102 |
|
| 103 |
|
| 104 |
if (strlen(arg_operation) == 0 && strlen(arg_argument) == 0) { |
| 105 |
return 0; |
| 106 |
} |
| 107 |
|
| 108 |
int operation_number = oval_operation_from_text(arg_operation); |
| 109 |
if (operation_number <= 0 || operation_number > 255) { |
| 110 |
fprintf(stderr, "Error parsing path->operation number -- not a valid OVAL_OPERATION enum string: %s\n", arg_operation); |
| 111 |
return 1; |
| 112 |
} |
| 113 |
|
| 114 |
uint8_t operation_value = (uint8_t)(operation_number & 0xFF); |
| 115 |
|
| 116 |
SEXP_t *s_filepath_str = SEXP_string_new("filepath", 8); |
| 117 |
SEXP_t *s_operation_str = SEXP_string_new(":operation", 10); |
| 118 |
SEXP_t *s_operation_number = SEXP_number_new(SEXP_NUM_UINT8, &operation_value); |
| 119 |
SEXP_t *s_filepath_argument = SEXP_string_new(arg_argument, strlen(arg_argument)); |
| 120 |
SEXP_t *s_inner_list = SEXP_list_new(NULL); |
| 121 |
|
| 122 |
SEXP_list_add(s_inner_list, s_filepath_str); |
| 123 |
SEXP_list_add(s_inner_list, s_operation_str); |
| 124 |
SEXP_list_add(s_inner_list, s_operation_number); |
| 125 |
|
| 126 |
*result = SEXP_list_new(NULL); |
| 127 |
SEXP_list_add(*result, s_inner_list); |
| 128 |
SEXP_list_add(*result, s_filepath_argument); |
| 129 |
|
| 130 |
return 0; |
| 131 |
} |
| 132 |
|
| 133 |
static int create_behaviors_sexpr(char *arg_max_depth, char *arg_recurse, char *arg_recurse_direction, char *arg_recurse_file_system, SEXP_t **result) |
| 134 |
{ |
| 135 |
*result = NULL; |
| 136 |
|
| 137 |
|
| 138 |
if (strlen(arg_max_depth) == 0 && strlen(arg_recurse) == 0 && strlen(arg_recurse_direction) == 0 && strlen(arg_recurse_file_system) == 0) { |
| 139 |
return 0; |
| 140 |
} |
| 141 |
|
| 142 |
SEXP_t *s_behaviors_str = SEXP_string_new("behaviors", 9); |
| 143 |
SEXP_t *s_max_depth_str = SEXP_string_new(":max_depth", 10); |
| 144 |
SEXP_t *s_max_depth_argument = SEXP_string_new(arg_max_depth, strlen(arg_max_depth)); |
| 145 |
SEXP_t *s_recurse_str = SEXP_string_new(":recurse", 8); |
| 146 |
SEXP_t *s_recurse_argument = SEXP_string_new(arg_recurse, strlen(arg_recurse)); |
| 147 |
SEXP_t *s_recurse_direction_str = SEXP_string_new(":recurse_direction", 18); |
| 148 |
SEXP_t *s_recurse_direction_argument = SEXP_string_new(arg_recurse_direction, strlen(arg_recurse_direction)); |
| 149 |
SEXP_t *s_recurse_file_system_str = SEXP_string_new(":recurse_file_system", 20); |
| 150 |
SEXP_t *s_recurse_file_system_argument = SEXP_string_new(arg_recurse_file_system, strlen(arg_recurse_file_system)); |
| 151 |
|
| 152 |
SEXP_t *s_inner_list = SEXP_list_new(NULL); |
| 153 |
|
| 154 |
SEXP_list_add(s_inner_list, s_behaviors_str); |
| 155 |
SEXP_list_add(s_inner_list, s_max_depth_str); |
| 156 |
SEXP_list_add(s_inner_list, s_max_depth_argument); |
| 157 |
SEXP_list_add(s_inner_list, s_recurse_str); |
| 158 |
SEXP_list_add(s_inner_list, s_recurse_argument); |
| 159 |
SEXP_list_add(s_inner_list, s_recurse_direction_str); |
| 160 |
SEXP_list_add(s_inner_list, s_recurse_direction_argument); |
| 161 |
SEXP_list_add(s_inner_list, s_recurse_file_system_str); |
| 162 |
SEXP_list_add(s_inner_list, s_recurse_file_system_argument); |
| 163 |
|
| 164 |
*result = SEXP_list_new(NULL); |
| 165 |
SEXP_list_add(*result, s_inner_list); |
| 166 |
|
| 167 |
return 0; |
| 168 |
} |
| 169 |
|
| 170 |
int main(int argc, char *argv[]) |
| 171 |
{ |
| 172 |
OVAL_FTS *ofts; |
| 173 |
OVAL_FTSENT *ofts_ent; |
| 174 |
|
| 175 |
SEXP_t *path, *filename, *behaviors, *filepath, *result; |
| 176 |
|
| 177 |
int ret = 0; |
| 178 |
|
| 179 |
oscap_set_verbose(NULL, NULL); |
| 180 |
|
| 181 |
if (argc < 11) { |
| 182 |
fprintf(stderr, "Invalid usage -- too few arguments supplied.\n"); |
| 183 |
fprintf(stderr, "The following arguments are required, but may be empty:\n\n"); |
| 184 |
fprintf(stderr, " argv[1] - path operation\n"); |
| 185 |
fprintf(stderr, " argv[2] - path argument (regex or paths)\n"); |
| 186 |
fprintf(stderr, " argv[3] - filename operation\n"); |
| 187 |
fprintf(stderr, " argv[4] - filename argument (regex or paths)\n"); |
| 188 |
fprintf(stderr, " argv[5] - filepath operation\n"); |
| 189 |
fprintf(stderr, " argv[6] - filepath argument (regex or paths)\n"); |
| 190 |
fprintf(stderr, " argv[7] - behaviors max_depth\n"); |
| 191 |
fprintf(stderr, " argv[8] - behaviors recurse\n"); |
| 192 |
fprintf(stderr, " argv[9] - behaviors recurse_direction\n"); |
| 193 |
fprintf(stderr, " argv[10] - behaviors recurse_file_system\n"); |
| 194 |
return 1; |
| 195 |
} |
| 196 |
|
| 197 |
ret = create_path_sexpr(argv[1], argv[2], &path); |
| 198 |
if (ret) |
| 199 |
return ret; |
| 200 |
|
| 201 |
ret = create_filename_sexpr(argv[3], argv[4], &filename); |
| 202 |
if (ret) |
| 203 |
return ret; |
| 204 |
|
| 205 |
ret = create_filepath_sexpr(argv[5], argv[6], &filepath); |
| 206 |
if (ret) |
| 207 |
return ret; |
| 208 |
|
| 209 |
ret = create_behaviors_sexpr(argv[7], argv[8], argv[9], argv[10], &behaviors); |
| 210 |
if (ret) |
| 211 |
return ret; |
| 212 |
|
| 213 |
|
| 214 |
result = probe_cobj_new(SYSCHAR_FLAG_UNKNOWN, NULL, NULL, NULL); |
| 215 |
|
| 216 |
fprintf(stderr, |
| 217 |
"path=%p\n" |
| 218 |
"filename=%p\n" |
| 219 |
"filepath=%p\n" |
| 220 |
"behaviors=%p\n", path, filename, filepath, behaviors); |
| 221 |
|
| 222 |
ofts = oval_fts_open_prefixed(NULL, path, filename, filepath, behaviors, result); |
| 223 |
|
| 224 |
if (ofts != NULL) { |
| 225 |
while ((ofts_ent = oval_fts_read(ofts)) != NULL) { |
| 226 |
printf("%s/%s\n", ofts_ent->path, ofts_ent->file ? ofts_ent->file : ""); |
| 227 |
oval_ftsent_free(ofts_ent); |
| 228 |
} |
| 229 |
|
| 230 |
oval_fts_close(ofts); |
| 231 |
} |
| 232 |
|
| 233 |
SEXP_free(path); |
| 234 |
SEXP_free(filename); |
| 235 |
SEXP_free(filepath); |
| 236 |
SEXP_free(behaviors); |
| 237 |
|
| 238 |
return 0; |
| 239 |
} |