mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 18:33:16 +00:00
relocable hardcoded paths
This commit is contained in:
parent
174416b42e
commit
e46b546ce3
13 changed files with 129 additions and 29 deletions
|
@ -1,3 +1,7 @@
|
|||
Tue Oct 20 17:48:59 CEST 2009 (acab)
|
||||
------------------------------------
|
||||
* shared, win32: make hardcoded paths relocable in win32 builds
|
||||
|
||||
Mon Oct 19 14:13:27 CEST 2009 (acab)
|
||||
------------------------------------
|
||||
* win32: add clamconf
|
||||
|
|
|
@ -35,6 +35,12 @@
|
|||
#include "libclamav/clamav.h"
|
||||
#include "libclamav/others.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
extern const struct clam_option *clam_options;
|
||||
#else
|
||||
__declspec(dllimport) extern const struct clam_option *clam_options;
|
||||
#endif
|
||||
|
||||
static struct _cfgfile {
|
||||
const char *name;
|
||||
int tool;
|
||||
|
|
|
@ -33,3 +33,8 @@ typedef unsigned int in_addr_t;
|
|||
#else
|
||||
#define PATHSEP "/"
|
||||
#endif
|
||||
|
||||
#define CONFDIR_CLAMD CONFDIR"\\clamd.conf"
|
||||
#define CONFDIR_FRESHCLAM CONFDIR"\\freshclam.conf"
|
||||
#define CONFDIR_MILTER CONFDIR"\\clamav-milter.conf"
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ char *freshdbdir(void)
|
|||
|
||||
/* try to find the most up-to-date db directory */
|
||||
dbdir = cl_retdbdir();
|
||||
if((opts = optparse(CONFDIR PATHSEP "freshclam.conf", 0, NULL, 0, OPT_FRESHCLAM, 0, NULL))) {
|
||||
if((opts = optparse(CONFDIR_FRESHCLAM, 0, NULL, 0, OPT_FRESHCLAM, 0, NULL))) {
|
||||
if((opt = optget(opts, "DatabaseDirectory"))->enabled) {
|
||||
if(strcmp(dbdir, opt->strarg)) {
|
||||
char *daily = (char *) malloc(strlen(opt->strarg) + strlen(dbdir) + 30);
|
||||
|
|
|
@ -57,14 +57,14 @@
|
|||
#define FLAG_HIDDEN 4 /* don't print in clamconf --generate-config */
|
||||
#define FLAG_REG_CASE 8 /* case-sensitive regex matching */
|
||||
|
||||
const struct clam_option clam_options[] = {
|
||||
const struct clam_option __clam_options[] = {
|
||||
/* name, longopt, sopt, argtype, regex, num, str, flags, owner, description, suggested */
|
||||
|
||||
/* cmdline only */
|
||||
{ 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, "", "" },
|
||||
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR PATHSEP "clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" },
|
||||
{ NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR PATHSEP "freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
|
||||
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR PATHSEP "clamav-milter.conf", FLAG_REQUIRED, OPT_MILTER, "", "" },
|
||||
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_CLAMD, FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN | OPT_CLAMDTOP, "", "" },
|
||||
{ NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR_FRESHCLAM, FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
|
||||
{ NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR_MILTER, FLAG_REQUIRED, OPT_MILTER, "", "" },
|
||||
{ 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, "", "" },
|
||||
{ NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" },
|
||||
{ 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[] = {
|
|||
{ NULL, "daemon", 'd', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
|
||||
{ NULL, "no-dns", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
|
||||
{ NULL, "list-mirrors", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
|
||||
{ NULL, "submit-stats", 0, TYPE_STRING, NULL, 0, CONFDIR PATHSEP "clamd.conf", 0, OPT_FRESHCLAM, "", "" }, /* Don't merge this one with SubmitDetectionStats */
|
||||
{ NULL, "submit-stats", 0, TYPE_STRING, NULL, 0, CONFDIR_CLAMD, 0, OPT_FRESHCLAM, "", "" }, /* Don't merge this one with SubmitDetectionStats */
|
||||
{ NULL, "reload", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDSCAN, "", "" },
|
||||
{ NULL, "multiscan", 'm', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDSCAN, "", "" },
|
||||
{ NULL, "fdpass", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDSCAN, "", "" },
|
||||
|
@ -337,7 +337,7 @@ const struct clam_option clam_options[] = {
|
|||
|
||||
{ "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" },
|
||||
|
||||
{ "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" },
|
||||
{ "NotifyClamd", "daemon-notify", 0, TYPE_STRING, NULL, -1, CONFDIR_CLAMD, 0, OPT_FRESHCLAM, "Send the RELOAD command to clamd after a successful update.", "yes" },
|
||||
|
||||
{ "OnUpdateExecute", "on-update-execute", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command after a successful database update.", "command" },
|
||||
|
||||
|
@ -422,6 +422,7 @@ const struct clam_option clam_options[] = {
|
|||
|
||||
{ NULL, NULL, 0, 0, NULL, 0, NULL, 0, 0, NULL, NULL }
|
||||
};
|
||||
const struct clam_option *clam_options = __clam_options;
|
||||
|
||||
const struct optstruct *optget(const struct optstruct *opts, const char *name)
|
||||
{
|
||||
|
|
|
@ -67,8 +67,6 @@ struct clam_option {
|
|||
const char *suggested;
|
||||
};
|
||||
|
||||
extern const struct clam_option clam_options[];
|
||||
|
||||
const struct optstruct *optget(const struct optstruct *opts, const char *name);
|
||||
|
||||
void optfree(struct optstruct *opts);
|
||||
|
|
|
@ -191,10 +191,6 @@
|
|||
RelativePath="..\shared\misc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\optparser.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
|
|
|
@ -216,10 +216,6 @@
|
|||
RelativePath="..\shared\misc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\optparser.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\output.c"
|
||||
>
|
||||
|
|
|
@ -4,7 +4,12 @@
|
|||
#include "clamav-config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "pthread.h"
|
||||
#include "libgen.h"
|
||||
#include "shared/optparser.h"
|
||||
|
||||
void fix_paths(void);
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) {
|
||||
WSADATA wsa;
|
||||
|
@ -12,6 +17,7 @@ BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) {
|
|||
case DLL_PROCESS_ATTACH:
|
||||
if(WSAStartup(MAKEWORD(2,2), &wsa))
|
||||
return FALSE;
|
||||
fix_paths();
|
||||
return pthread_win32_process_attach_np();
|
||||
break;
|
||||
|
||||
|
@ -30,3 +36,79 @@ BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The trick is:
|
||||
1 - Reinclude clamav-config.h which is not guarded against multiple inclusions.
|
||||
In platform.h we do undef them and re-export as extern pointers, however, since
|
||||
platform.h is guarded, the undef won't trigger.
|
||||
This gives back to us the original CONFDIR and DATADIR macroes.
|
||||
2 - We define _static_ buffers to contain those strings.
|
||||
3 - We undef the macroes, which re-turns them back into extern pointers and we set them
|
||||
to point to the above defined buffer.
|
||||
4 - We now give the original macros the names of the above buffers and include optparser.c
|
||||
This result in clam_options struct in optparser be defined with proper pointers.
|
||||
*/
|
||||
|
||||
#include "clamav-config.h"
|
||||
char _DATADIR[MAX_PATH] = DATADIR;
|
||||
char _CONFDIR[MAX_PATH] = CONFDIR;
|
||||
char _CONFDIR_CLAMD[MAX_PATH] = CONFDIR"\\clamd.conf";
|
||||
char _CONFDIR_FRESHCLAM[MAX_PATH] = CONFDIR"\\freshclam.conf";
|
||||
char _CONFDIR_MILTER[MAX_PATH] = CONFDIR"\\clamav-milter.conf";
|
||||
|
||||
#undef DATADIR
|
||||
#undef CONFDIR
|
||||
const char *DATADIR = _DATADIR;
|
||||
const char *CONFDIR = _CONFDIR;
|
||||
const char *CONFDIR_CLAMD = _CONFDIR_CLAMD;
|
||||
const char *CONFDIR_FRESHCLAM = _CONFDIR_FRESHCLAM;
|
||||
const char *CONFDIR_MILTER = _CONFDIR_MILTER;
|
||||
|
||||
#define DATADIR _DATADIR
|
||||
#define CONFDIR _CONFDIR
|
||||
#define CONFDIR_CLAMD _CONFDIR_CLAMD
|
||||
#define CONFDIR_FRESHCLAM _CONFDIR_FRESHCLAM
|
||||
#define CONFDIR_MILTER _CONFDIR_MILTER
|
||||
|
||||
#include "shared/optparser.c"
|
||||
|
||||
#define CLAMKEY "Software\\ClamAV"
|
||||
void fix_paths(void) {
|
||||
int have_ddir = 0, have_cdir = 0;
|
||||
char path[MAX_PATH] = "";
|
||||
DWORD sizof;
|
||||
HKEY key;
|
||||
|
||||
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) {
|
||||
sizof = sizeof(path);
|
||||
if(RegQueryValueEx(key, "DataDir", 0, NULL, path, &sizof) == ERROR_SUCCESS) {
|
||||
have_ddir = 1;
|
||||
memcpy(_DATADIR, path, sizof);
|
||||
}
|
||||
sizof = sizeof(path);
|
||||
if(RegQueryValueEx(key, "ConfDir", 0, NULL, path, &sizof) == ERROR_SUCCESS) {
|
||||
have_cdir = 1;
|
||||
memcpy(_CONFDIR, path, sizof);
|
||||
}
|
||||
RegCloseKey(key);
|
||||
}
|
||||
if(!(have_ddir | have_cdir) && GetModuleFileName(NULL, path, sizeof(path))) {
|
||||
char *dir;
|
||||
path[sizeof(path)-1] = '\0';
|
||||
dir = dirname(path);
|
||||
if(!have_ddir)
|
||||
snprintf(_DATADIR, sizeof(_DATADIR), "%s\\database", dir);
|
||||
if(!have_cdir) {
|
||||
strncpy(_CONFDIR, dir, sizeof(_DATADIR));
|
||||
have_cdir = 1;
|
||||
}
|
||||
}
|
||||
_DATADIR[sizeof(_DATADIR) - 1] = '\0';
|
||||
_CONFDIR[sizeof(_CONFDIR) - 1] = '\0';
|
||||
if(have_cdir) {
|
||||
snprintf(_CONFDIR_CLAMD, sizeof(_CONFDIR_CLAMD), "%s\\%s", _CONFDIR, "clamd.conf");
|
||||
snprintf(_CONFDIR_FRESHCLAM, sizeof(_CONFDIR_FRESHCLAM), "%s\\%s", _CONFDIR, "freshclam.conf");
|
||||
snprintf(_CONFDIR_MILTER, sizeof(_CONFDIR_MILTER), "%s\\%s", _CONFDIR, "clamav-milter.conf");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,10 +222,6 @@
|
|||
RelativePath="..\shared\misc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\optparser.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\output.c"
|
||||
>
|
||||
|
|
|
@ -52,6 +52,17 @@ EXPORTS gzdopen
|
|||
EXPORTS gzclose
|
||||
EXPORTS gzwrite
|
||||
|
||||
EXPORTS optget
|
||||
EXPORTS optparse
|
||||
EXPORTS optfree
|
||||
EXPORTS clam_options DATA
|
||||
|
||||
EXPORTS DATADIR DATA
|
||||
EXPORTS CONFDIR DATA
|
||||
EXPORTS CONFDIR_CLAMD DATA
|
||||
EXPORTS CONFDIR_FRESHCLAM DATA
|
||||
EXPORTS CONFDIR_MILTER DATA
|
||||
|
||||
; winsock - bridging for now
|
||||
EXPORTS htonl
|
||||
EXPORTS htons
|
||||
|
|
|
@ -340,10 +340,6 @@
|
|||
RelativePath="..\libclamav\mew.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\misc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\libclamav\mpool.c"
|
||||
>
|
||||
|
@ -759,10 +755,6 @@
|
|||
RelativePath="..\shared\getopt.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\shared\optparser.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="compat"
|
||||
|
@ -779,6 +771,10 @@
|
|||
RelativePath=".\compat\libclamav_main.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\compat\libgen.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\compat\ltdl.c"
|
||||
>
|
||||
|
|
|
@ -65,4 +65,13 @@ typedef unsigned int in_addr_t;
|
|||
|
||||
#define PATHSEP "\\"
|
||||
|
||||
#undef DATADIR
|
||||
#undef CONFDIR
|
||||
__declspec(dllimport) extern const char *DATADIR;
|
||||
__declspec(dllimport) extern const char *CONFDIR;
|
||||
__declspec(dllimport) extern const char *CONFDIR_CLAMD;
|
||||
__declspec(dllimport) extern const char *CONFDIR_FRESHCLAM;
|
||||
__declspec(dllimport) extern const char *CONFDIR_MILTER;
|
||||
#undef HAVE_CONFIG_H
|
||||
|
||||
#endif /* __PLATFORM_H */
|
Loading…
Add table
Add a link
Reference in a new issue