summaryrefslogtreecommitdiff
path: root/src/rost.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rost.c')
-rw-r--r--src/rost.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/rost.c b/src/rost.c
index 928aa12..efe18e5 100644
--- a/src/rost.c
+++ b/src/rost.c
@@ -22,6 +22,7 @@
*/
+#include <assert.h>
#include <getopt.h>
#include <libgen.h>
#include <locale.h>
@@ -91,6 +92,7 @@ static void show_rost_help(const char *name)
printf("\n");
printf("\t-A --algorithm=name\tSelect one of the available algorithms for data: bitmap, acism (default: acsim).\n");
+ printf("\t-C --check-only\t\tValidate the rule syntax without performing a scan (discard the file/dir argument).\n");
printf("\t-j --print-json\t\tPrint matching strings in JSON format.\n");
printf("\t-s --print-strings\tPrint matching strings.\n");
printf("\t-S --print-stats\tPrint rules' statistics.\n");
@@ -215,6 +217,7 @@ int main(int argc, char **argv)
int result; /* Bilan de l'exécution */
bool show_help; /* Affichage de l'aide ? */
bool show_version; /* Affichage de la version ? */
+ bool check_only; /* Validation uniquement */
LogMessageType verbosity; /* Niveau de filtre de message */
GScanOptions *options; /* Options d'analyses */
int index; /* Indice d'argument */
@@ -233,6 +236,7 @@ int main(int argc, char **argv)
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' },
{ "algorithm", required_argument, NULL, 'A' },
+ { "check-only", no_argument, NULL, 'C' },
{ "print-json", no_argument, NULL, 'j' },
{ "print-strings", no_argument, NULL, 's' },
{ "print-stats", no_argument, NULL, 'S' },
@@ -247,6 +251,7 @@ int main(int argc, char **argv)
show_help = false;
show_version = false;
+ check_only = false;
verbosity = LMT_INFO;
options = g_scan_options_new();
@@ -255,7 +260,7 @@ int main(int argc, char **argv)
while (true)
{
- ret = getopt_long(argc, argv, "hvA:jsSV:", long_options, &index);
+ ret = getopt_long(argc, argv, "hvA:CjsSV:", long_options, &index);
if (ret == -1) break;
switch (ret)
@@ -277,6 +282,11 @@ int main(int argc, char **argv)
g_scan_options_set_backend_for_data(options, G_TYPE_INVALID);
break;
+ case 'C':
+ check_only = true;
+ g_scan_options_set_check_only(options, true);
+ break;
+
case 'j':
g_scan_options_set_print_json(options, true);
break;
@@ -297,10 +307,11 @@ int main(int argc, char **argv)
}
- if ((optind + 1) != argc && (optind + 2) != argc)
+ if ((check_only && (optind + 0) != argc && (optind + 1) != argc)
+ || (!check_only && (optind + 1) != argc && (optind + 2) != argc))
{
+ printf("failed: check=%d optind=%d argc=%d\n", check_only, optind, argc);
show_rost_help(argv[0]);
- result = EXIT_FAILURE;
goto done;
}
@@ -323,7 +334,6 @@ int main(int argc, char **argv)
if (g_scan_options_get_backend_for_data(options) == G_TYPE_INVALID)
{
show_rost_help(argv[0]);
- result = EXIT_FAILURE;
goto done;
}
@@ -350,10 +360,26 @@ int main(int argc, char **argv)
/* Traitement des recherches */
- if ((optind + 1) == argc)
+ if ((optind + 0) == argc)
{
+ assert(check_only);
+
rules = NULL;
- target = argv[optind];
+ target = NULL;
+
+ }
+ else if ((optind + 1) == argc)
+ {
+ if (check_only)
+ {
+ rules = argv[optind];
+ target = NULL;
+ }
+ else
+ {
+ rules = NULL;
+ target = argv[optind];
+ }
}
else
{
@@ -382,8 +408,12 @@ int main(int argc, char **argv)
scanner = g_content_scanner_new_from_file(rules);
if (scanner != NULL)
+ result = EXIT_SUCCESS;
+
+ if (scanner != NULL && !check_only)
{
content = g_file_content_new(target);
+ if (content == NULL) goto bad_file_content;
context = g_content_scanner_analyze(scanner, options, content);
@@ -406,6 +436,8 @@ int main(int argc, char **argv)
g_object_unref(G_OBJECT(context));
g_object_unref(G_OBJECT(content));
+ bad_file_content:
+
g_object_unref(G_OBJECT(scanner));
}