Browse code

clamdscan: print warnings when ignoring options

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@718 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/08/04 02:02:45
Showing 4 changed files
... ...
@@ -1,3 +1,8 @@
1
+Tue Aug  3 18:50:57 CEST 2004 (tk)
2
+----------------------------------
3
+  * clamdscan: print warnings when ignoring options (requested by Tomasz
4
+	       Papszun <tomek*clamav.net>)
5
+
1 6
 Tue Aug  3 02:20:03 CEST 2004 (tk)
2 7
 ----------------------------------
3 8
   * libclamav: scanhtml: fix memory leak (reported by Mike Lambert
... ...
@@ -127,7 +127,6 @@ void help(void)
127 127
     mprintf("    --stdout                           Write to stdout instead of stderr\n");
128 128
     mprintf("                                       (this help is always written to stdout)\n");
129 129
     mprintf("    --log=FILE          -l FILE        Save scan report in FILE\n");
130
-    mprintf("    --log-verbose                      Log additional messages\n");
131 130
     mprintf("    --config-file=FILE                 Read configuration from FILE.\n");
132 131
     mprintf("    --no-summary                       Disable summary at end of scanning\n");
133 132
     mprintf("\n");
... ...
@@ -38,6 +38,14 @@
38 38
 
39 39
 extern int clamscan(struct optstruct *opt);
40 40
 
41
+static char *clamdscan_long[] = { "help", "version", "verbose", "quiet",
42
+				  "stdout", "log", "config-file", "no-summary",
43
+				  NULL };
44
+
45
+static char clamdscan_short[] = { 'h', 'V', 'v', 'l', 0 };
46
+
47
+int clamdscan_mode = 0;
48
+
41 49
 int main(int argc, char **argv)
42 50
 {
43 51
 	int ret, opt_index, i, len;
... ...
@@ -50,11 +58,12 @@ int main(int argc, char **argv)
50 50
 	     * WARNING: For compatibility reasons options marked as "not used"
51 51
 	     *		must still be accepted !
52 52
 	     */
53
-	    {"help", 0, 0, 'h'},
54
-	    {"quiet", 0, 0, 0},
55
-	    {"verbose", 0, 0, 'v'},
53
+	    {"help", 0, 0, 'h'},	    /* clamscan + clamdscan */
54
+	    {"quiet", 0, 0, 0},		    /* clamscan + clamdscan */
55
+	    {"stdout", 0, 0, 0},	    /* clamscan + clamdscan */
56
+	    {"verbose", 0, 0, 'v'},	    /* clamscan + clamdscan */
56 57
 	    {"debug", 0, 0, 0},
57
-	    {"version", 0, 0, 'V'},
58
+	    {"version", 0, 0, 'V'},	    /* clamscan + clamdscan */
58 59
 	    {"tempdir", 1, 0, 0},
59 60
 	    {"leave-temps", 0, 0, 0},
60 61
 	    {"config-file", 1, 0, 0}, /* clamdscan */
... ...
@@ -85,7 +94,6 @@ int main(int argc, char **argv)
85 85
 	    {"no-ole2", 0, 0, 0},
86 86
 	    {"no-html", 0, 0, 0},
87 87
 	    {"mbox", 0, 0, 'm'},
88
-	    {"stdout", 0, 0, 0},
89 88
 	    {"unzip", 2, 0, 0},
90 89
 	    {"unrar", 2, 0, 0},
91 90
 	    {"unace", 2, 0, 0}, /* not used */
... ...
@@ -105,6 +113,9 @@ int main(int argc, char **argv)
105 105
     opt=(struct optstruct*) mcalloc(1, sizeof(struct optstruct));
106 106
     opt->optlist = NULL;
107 107
 
108
+    if(strstr(argv[0], "clamdscan"))
109
+	clamdscan_mode = 1;
110
+
108 111
     while(1) {
109 112
 
110 113
 	opt_index=0;
... ...
@@ -119,9 +130,13 @@ int main(int argc, char **argv)
119 119
 		break;
120 120
 
121 121
     	    default:
122
-		if(strchr(getopt_parameters, ret))
123
-		    register_char_option(opt, ret);
124
-		else {
122
+		if(strchr(getopt_parameters, ret)) {
123
+		    if(opt_index)
124
+			register_char_option(opt, ret, long_options[opt_index].name);
125
+		    else
126
+			register_char_option(opt, ret, NULL);
127
+
128
+		} else {
125 129
 		    mprintf("!Unknown option passed.\n");
126 130
 		    free_opt(opt);
127 131
 		    exit(40);
... ...
@@ -155,9 +170,26 @@ int main(int argc, char **argv)
155 155
     return  ret;
156 156
 }
157 157
 
158
-void register_char_option(struct optstruct *opt, char ch)
158
+void register_char_option(struct optstruct *opt, char ch, const char *longname)
159 159
 {
160 160
 	struct optnode *newnode;
161
+	int i, found = 0;
162
+
163
+
164
+    if(clamdscan_mode) {
165
+	for(i = 0; clamdscan_short[i]; i++)
166
+	    if(clamdscan_short[i] == ch)
167
+		found = 1;
168
+
169
+	if(!found) {
170
+	    if(longname)
171
+		mprintf("WARNING: Ignoring option -%c (--%s): please edit clamav.conf instead.\n", ch, longname);
172
+	    else
173
+		mprintf("WARNING: Ignoring option -%c: please edit clamav.conf instead.\n", ch);
174
+
175
+	    return;
176
+	}
177
+    }
161 178
 
162 179
     newnode = (struct optnode *) mmalloc(sizeof(struct optnode));
163 180
     newnode->optchar = ch;
... ...
@@ -174,6 +206,19 @@ void register_char_option(struct optstruct *opt, char ch)
174 174
 void register_long_option(struct optstruct *opt, const char *optname)
175 175
 {
176 176
 	struct optnode *newnode;
177
+	int i, found;
178
+
179
+
180
+    if(clamdscan_mode) {
181
+	for(i = 0; clamdscan_long[i]; i++)
182
+	    if(!strcmp(clamdscan_long[i], optname))
183
+		found = 1;
184
+
185
+	if(!found) {
186
+	    mprintf("WARNING: Ignoring option --%s: please edit clamav.conf instead.\n", optname);
187
+	    return;
188
+	}
189
+    }
177 190
 
178 191
     newnode = (struct optnode *) mmalloc(sizeof(struct optnode));
179 192
     newnode->optchar = 0;
... ...
@@ -33,7 +33,7 @@ struct optstruct {
33 33
 
34 34
 int optc(const struct optstruct *opt, char ch);
35 35
 int optl(const struct optstruct *opt, const char *optname);
36
-void register_char_option(struct optstruct *opt, char ch);
36
+void register_char_option(struct optstruct *opt, char ch, const char *longname);
37 37
 void register_long_option(struct optstruct *opt, const char *optname);
38 38
 char *getargc(const struct optstruct *opt, char ch);
39 39
 char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode);