Browse code

Support using a custom HostID (to support anonymous submissions)

Shawn Webb authored on 2014/01/08 01:42:06
Showing 1 changed files
... ...
@@ -10,12 +10,13 @@
10 10
 
11 11
 void usage(char *name)
12 12
 {
13
-    fprintf(stderr, "USAGE: %s -pnih?\n", name);
13
+    fprintf(stderr, "USAGE: %s -hHinp?\n", name);
14 14
     fprintf(stderr, "OPTIONS:\n");
15
-    fprintf(stderr, "    -p [FILE]\tSubmit a fase positive (FP)\n");
16
-    fprintf(stderr, "    -n [FILE]\tSubmit a false negative (FN)\n");
17
-    fprintf(stderr, "    -i [FILE]\tSubmit an \"interesting\" file\n");
18 15
     fprintf(stderr, "    -h or -?\tShow the help text\n");
16
+    fprintf(stderr, "    -H [HostID]\tAttach a custom HostID to the submission.\n");
17
+    fprintf(stderr, "    -i [FILE]\tSubmit an \"interesting\" file\n");
18
+    fprintf(stderr, "    -n [FILE]\tSubmit a false negative (FN)\n");
19
+    fprintf(stderr, "    -p [FILE]\tSubmit a fase positive (FP)\n");
19 20
     exit(0);
20 21
 }
21 22
 
... ...
@@ -27,18 +28,29 @@ int main(int argc, char *argv[])
27 27
     struct curl_httppost *post=NULL, *last=NULL;
28 28
     struct curl_slist *slist = NULL;
29 29
     char *type;
30
-    char *hostid;
30
+    char *hostid=NULL;
31 31
     struct cl_engine *engine;
32 32
 
33
-    cl_init(0);
34
-    engine = cl_engine_new();
35
-    if (!(engine)) {
36
-        fprintf(stderr, "Unable to create new ClamAV engine\n");
37
-        return 1;
33
+    while ((ch = my_getopt(argc, argv, "H:")) > 0) {
34
+        if (ch == 'H')
35
+            hostid = optarg;
38 36
     }
39 37
 
40
-    hostid = engine->cb_stats_get_hostid(engine->stats_data);
41
-    printf("HostID: %s\n", hostid);
38
+    /* Reset getopt */
39
+    optind = opterr = 1;
40
+    optopt = 0;
41
+    optarg = NULL;
42
+
43
+    if (!(hostid)) {
44
+        cl_init(0);
45
+        engine = cl_engine_new();
46
+        if (!(engine)) {
47
+            fprintf(stderr, "Unable to create new ClamAV engine\n");
48
+            return 1;
49
+        }
50
+
51
+        hostid = engine->cb_stats_get_hostid(engine->stats_data);
52
+    }
42 53
 
43 54
     curl_global_init(CURL_GLOBAL_ALL);
44 55