... | ... |
@@ -35,6 +35,12 @@ |
35 | 35 |
#include "libclamav/clamav.h" |
36 | 36 |
#include "libclamav/others.h" |
37 | 37 |
|
38 |
+#ifndef _WIN32 |
|
39 |
+extern const struct clam_option *clam_options; |
|
40 |
+#else |
|
41 |
+__declspec(dllimport) extern const struct clam_option *clam_options; |
|
42 |
+#endif |
|
43 |
+ |
|
38 | 44 |
static struct _cfgfile { |
39 | 45 |
const char *name; |
40 | 46 |
int tool; |
... | ... |
@@ -74,7 +74,7 @@ char *freshdbdir(void) |
74 | 74 |
|
75 | 75 |
/* try to find the most up-to-date db directory */ |
76 | 76 |
dbdir = cl_retdbdir(); |
77 |
- if((opts = optparse(CONFDIR PATHSEP "freshclam.conf", 0, NULL, 0, OPT_FRESHCLAM, 0, NULL))) { |
|
77 |
+ if((opts = optparse(CONFDIR_FRESHCLAM, 0, NULL, 0, OPT_FRESHCLAM, 0, NULL))) { |
|
78 | 78 |
if((opt = optget(opts, "DatabaseDirectory"))->enabled) { |
79 | 79 |
if(strcmp(dbdir, opt->strarg)) { |
80 | 80 |
char *daily = (char *) malloc(strlen(opt->strarg) + strlen(dbdir) + 30); |
... | ... |
@@ -57,14 +57,14 @@ |
57 | 57 |
#define FLAG_HIDDEN 4 /* don't print in clamconf --generate-config */ |
58 | 58 |
#define FLAG_REG_CASE 8 /* case-sensitive regex matching */ |
59 | 59 |
|
60 |
-const struct clam_option clam_options[] = { |
|
60 |
+const struct clam_option __clam_options[] = { |
|
61 | 61 |
/* name, longopt, sopt, argtype, regex, num, str, flags, owner, description, suggested */ |
62 | 62 |
|
63 | 63 |
/* cmdline only */ |
64 | 64 |
{ NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP | OPT_CLAMBC, "", "" }, |
65 |
- { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR PATHSEP "clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" }, |
|
66 |
- { NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR PATHSEP "freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" }, |
|
67 |
- { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR PATHSEP "clamav-milter.conf", FLAG_REQUIRED, OPT_MILTER, "", "" }, |
|
65 |
+ { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_CLAMD, FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" }, |
|
66 |
+ { NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR_FRESHCLAM, FLAG_REQUIRED, OPT_FRESHCLAM, "", "" }, |
|
67 |
+ { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_MILTER, FLAG_REQUIRED, OPT_MILTER, "", "" }, |
|
68 | 68 |
{ NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL | OPT_MILTER | OPT_CLAMCONF | OPT_CLAMDTOP | OPT_CLAMBC, "", "" }, |
69 | 69 |
{ NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" }, |
70 | 70 |
{ NULL, "verbose", 'v', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" }, |
... | ... |
@@ -75,7 +75,7 @@ const struct clam_option clam_options[] = { |
75 | 75 |
{ NULL, "daemon", 'd', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" }, |
76 | 76 |
{ NULL, "no-dns", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" }, |
77 | 77 |
{ NULL, "list-mirrors", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" }, |
78 |
- { NULL, "submit-stats", 0, TYPE_STRING, NULL, 0, CONFDIR PATHSEP "clamd.conf", 0, OPT_FRESHCLAM, "", "" }, /* Don't merge this one with SubmitDetectionStats */ |
|
78 |
+ { NULL, "submit-stats", 0, TYPE_STRING, NULL, 0, CONFDIR_CLAMD, 0, OPT_FRESHCLAM, "", "" }, /* Don't merge this one with SubmitDetectionStats */ |
|
79 | 79 |
{ NULL, "reload", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDSCAN, "", "" }, |
80 | 80 |
{ NULL, "multiscan", 'm', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDSCAN, "", "" }, |
81 | 81 |
{ NULL, "fdpass", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDSCAN, "", "" }, |
... | ... |
@@ -337,7 +337,7 @@ const struct clam_option clam_options[] = { |
337 | 337 |
|
338 | 338 |
{ "HTTPUserAgent", NULL, 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "If your servers are behind a firewall/proxy which does a User-Agent\nfiltering you can use this option to force the use of a different\nUser-Agent header.", "default" }, |
339 | 339 |
|
340 |
- { "NotifyClamd", "daemon-notify", 0, TYPE_STRING, NULL, -1, CONFDIR PATHSEP "clamd.conf", 0, OPT_FRESHCLAM, "Send the RELOAD command to clamd after a successful update.", "yes" }, |
|
340 |
+ { "NotifyClamd", "daemon-notify", 0, TYPE_STRING, NULL, -1, CONFDIR_CLAMD, 0, OPT_FRESHCLAM, "Send the RELOAD command to clamd after a successful update.", "yes" }, |
|
341 | 341 |
|
342 | 342 |
{ "OnUpdateExecute", "on-update-execute", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command after a successful database update.", "command" }, |
343 | 343 |
|
... | ... |
@@ -422,6 +422,7 @@ const struct clam_option clam_options[] = { |
422 | 422 |
|
423 | 423 |
{ NULL, NULL, 0, 0, NULL, 0, NULL, 0, 0, NULL, NULL } |
424 | 424 |
}; |
425 |
+const struct clam_option *clam_options = __clam_options; |
|
425 | 426 |
|
426 | 427 |
const struct optstruct *optget(const struct optstruct *opts, const char *name) |
427 | 428 |
{ |
... | ... |
@@ -4,7 +4,12 @@ |
4 | 4 |
#include "clamav-config.h" |
5 | 5 |
#endif |
6 | 6 |
|
7 |
+#include <string.h> |
|
7 | 8 |
#include "pthread.h" |
9 |
+#include "libgen.h" |
|
10 |
+#include "shared/optparser.h" |
|
11 |
+ |
|
12 |
+void fix_paths(void); |
|
8 | 13 |
|
9 | 14 |
BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) { |
10 | 15 |
WSADATA wsa; |
... | ... |
@@ -12,6 +17,7 @@ BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) { |
12 | 12 |
case DLL_PROCESS_ATTACH: |
13 | 13 |
if(WSAStartup(MAKEWORD(2,2), &wsa)) |
14 | 14 |
return FALSE; |
15 |
+ fix_paths(); |
|
15 | 16 |
return pthread_win32_process_attach_np(); |
16 | 17 |
break; |
17 | 18 |
|
... | ... |
@@ -30,3 +36,79 @@ BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) { |
30 | 30 |
break; |
31 | 31 |
} |
32 | 32 |
} |
33 |
+ |
|
34 |
+/* |
|
35 |
+ The trick is: |
|
36 |
+ 1 - Reinclude clamav-config.h which is not guarded against multiple inclusions. |
|
37 |
+ In platform.h we do undef them and re-export as extern pointers, however, since |
|
38 |
+ platform.h is guarded, the undef won't trigger. |
|
39 |
+ This gives back to us the original CONFDIR and DATADIR macroes. |
|
40 |
+ 2 - We define _static_ buffers to contain those strings. |
|
41 |
+ 3 - We undef the macroes, which re-turns them back into extern pointers and we set them |
|
42 |
+ to point to the above defined buffer. |
|
43 |
+ 4 - We now give the original macros the names of the above buffers and include optparser.c |
|
44 |
+ This result in clam_options struct in optparser be defined with proper pointers. |
|
45 |
+*/ |
|
46 |
+ |
|
47 |
+#include "clamav-config.h" |
|
48 |
+char _DATADIR[MAX_PATH] = DATADIR; |
|
49 |
+char _CONFDIR[MAX_PATH] = CONFDIR; |
|
50 |
+char _CONFDIR_CLAMD[MAX_PATH] = CONFDIR"\\clamd.conf"; |
|
51 |
+char _CONFDIR_FRESHCLAM[MAX_PATH] = CONFDIR"\\freshclam.conf"; |
|
52 |
+char _CONFDIR_MILTER[MAX_PATH] = CONFDIR"\\clamav-milter.conf"; |
|
53 |
+ |
|
54 |
+#undef DATADIR |
|
55 |
+#undef CONFDIR |
|
56 |
+const char *DATADIR = _DATADIR; |
|
57 |
+const char *CONFDIR = _CONFDIR; |
|
58 |
+const char *CONFDIR_CLAMD = _CONFDIR_CLAMD; |
|
59 |
+const char *CONFDIR_FRESHCLAM = _CONFDIR_FRESHCLAM; |
|
60 |
+const char *CONFDIR_MILTER = _CONFDIR_MILTER; |
|
61 |
+ |
|
62 |
+#define DATADIR _DATADIR |
|
63 |
+#define CONFDIR _CONFDIR |
|
64 |
+#define CONFDIR_CLAMD _CONFDIR_CLAMD |
|
65 |
+#define CONFDIR_FRESHCLAM _CONFDIR_FRESHCLAM |
|
66 |
+#define CONFDIR_MILTER _CONFDIR_MILTER |
|
67 |
+ |
|
68 |
+#include "shared/optparser.c" |
|
69 |
+ |
|
70 |
+#define CLAMKEY "Software\\ClamAV" |
|
71 |
+void fix_paths(void) { |
|
72 |
+ int have_ddir = 0, have_cdir = 0; |
|
73 |
+ char path[MAX_PATH] = ""; |
|
74 |
+ DWORD sizof; |
|
75 |
+ HKEY key; |
|
76 |
+ |
|
77 |
+ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, CLAMKEY, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS || RegOpenKeyEx(HKEY_CURRENT_USER, CLAMKEY, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { |
|
78 |
+ sizof = sizeof(path); |
|
79 |
+ if(RegQueryValueEx(key, "DataDir", 0, NULL, path, &sizof) == ERROR_SUCCESS) { |
|
80 |
+ have_ddir = 1; |
|
81 |
+ memcpy(_DATADIR, path, sizof); |
|
82 |
+ } |
|
83 |
+ sizof = sizeof(path); |
|
84 |
+ if(RegQueryValueEx(key, "ConfDir", 0, NULL, path, &sizof) == ERROR_SUCCESS) { |
|
85 |
+ have_cdir = 1; |
|
86 |
+ memcpy(_CONFDIR, path, sizof); |
|
87 |
+ } |
|
88 |
+ RegCloseKey(key); |
|
89 |
+ } |
|
90 |
+ if(!(have_ddir | have_cdir) && GetModuleFileName(NULL, path, sizeof(path))) { |
|
91 |
+ char *dir; |
|
92 |
+ path[sizeof(path)-1] = '\0'; |
|
93 |
+ dir = dirname(path); |
|
94 |
+ if(!have_ddir) |
|
95 |
+ snprintf(_DATADIR, sizeof(_DATADIR), "%s\\database", dir); |
|
96 |
+ if(!have_cdir) { |
|
97 |
+ strncpy(_CONFDIR, dir, sizeof(_DATADIR)); |
|
98 |
+ have_cdir = 1; |
|
99 |
+ } |
|
100 |
+ } |
|
101 |
+ _DATADIR[sizeof(_DATADIR) - 1] = '\0'; |
|
102 |
+ _CONFDIR[sizeof(_CONFDIR) - 1] = '\0'; |
|
103 |
+ if(have_cdir) { |
|
104 |
+ snprintf(_CONFDIR_CLAMD, sizeof(_CONFDIR_CLAMD), "%s\\%s", _CONFDIR, "clamd.conf"); |
|
105 |
+ snprintf(_CONFDIR_FRESHCLAM, sizeof(_CONFDIR_FRESHCLAM), "%s\\%s", _CONFDIR, "freshclam.conf"); |
|
106 |
+ snprintf(_CONFDIR_MILTER, sizeof(_CONFDIR_MILTER), "%s\\%s", _CONFDIR, "clamav-milter.conf"); |
|
107 |
+ } |
|
108 |
+} |
... | ... |
@@ -52,6 +52,17 @@ EXPORTS gzdopen |
52 | 52 |
EXPORTS gzclose |
53 | 53 |
EXPORTS gzwrite |
54 | 54 |
|
55 |
+EXPORTS optget |
|
56 |
+EXPORTS optparse |
|
57 |
+EXPORTS optfree |
|
58 |
+EXPORTS clam_options DATA |
|
59 |
+ |
|
60 |
+EXPORTS DATADIR DATA |
|
61 |
+EXPORTS CONFDIR DATA |
|
62 |
+EXPORTS CONFDIR_CLAMD DATA |
|
63 |
+EXPORTS CONFDIR_FRESHCLAM DATA |
|
64 |
+EXPORTS CONFDIR_MILTER DATA |
|
65 |
+ |
|
55 | 66 |
; winsock - bridging for now |
56 | 67 |
EXPORTS htonl |
57 | 68 |
EXPORTS htons |
... | ... |
@@ -341,10 +341,6 @@ |
341 | 341 |
> |
342 | 342 |
</File> |
343 | 343 |
<File |
344 |
- RelativePath="..\shared\misc.c" |
|
345 |
- > |
|
346 |
- </File> |
|
347 |
- <File |
|
348 | 344 |
RelativePath="..\libclamav\mpool.c" |
349 | 345 |
> |
350 | 346 |
</File> |
... | ... |
@@ -759,10 +755,6 @@ |
759 | 759 |
RelativePath="..\shared\getopt.c" |
760 | 760 |
> |
761 | 761 |
</File> |
762 |
- <File |
|
763 |
- RelativePath="..\shared\optparser.c" |
|
764 |
- > |
|
765 |
- </File> |
|
766 | 762 |
</Filter> |
767 | 763 |
<Filter |
768 | 764 |
Name="compat" |
... | ... |
@@ -780,6 +772,10 @@ |
780 | 780 |
> |
781 | 781 |
</File> |
782 | 782 |
<File |
783 |
+ RelativePath=".\compat\libgen.c" |
|
784 |
+ > |
|
785 |
+ </File> |
|
786 |
+ <File |
|
783 | 787 |
RelativePath=".\compat\ltdl.c" |
784 | 788 |
> |
785 | 789 |
</File> |
... | ... |
@@ -65,4 +65,13 @@ typedef unsigned int in_addr_t; |
65 | 65 |
|
66 | 66 |
#define PATHSEP "\\" |
67 | 67 |
|
68 |
+#undef DATADIR |
|
69 |
+#undef CONFDIR |
|
70 |
+__declspec(dllimport) extern const char *DATADIR; |
|
71 |
+__declspec(dllimport) extern const char *CONFDIR; |
|
72 |
+__declspec(dllimport) extern const char *CONFDIR_CLAMD; |
|
73 |
+__declspec(dllimport) extern const char *CONFDIR_FRESHCLAM; |
|
74 |
+__declspec(dllimport) extern const char *CONFDIR_MILTER; |
|
75 |
+#undef HAVE_CONFIG_H |
|
76 |
+ |
|
68 | 77 |
#endif /* __PLATFORM_H */ |
69 | 78 |
\ No newline at end of file |