From 4d1a8aa7fa34bcfa92e9c24ea119ee58f53202c0 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Fri, 1 Sep 2006 00:49:21 +0000 Subject: [PATCH] Update the Microsoft Visual Studio build to match the MinGW32 build. Fix precedence problem in an ASSERT. Put DLL_IMP_EXP macros in the right place so they work with both gcc and msvc. Change make_session_key on WIN32 to use WIN32 APIs to produce a better seed. Add sed to external dependencies, it is used only during installation. Remove unused code from winmain.cpp and winservice.cpp for the three daemons. Fix /kill for file and storage daemons. Add bfree to the exports for bacula.dll. Add new tool scsilist.exe which displays the changer, tape and CD/DVD (1394, SCSI, SATA, ATAPI) devices and the information required to add them to bacula-sd.conf. Added full configuration generation to the installer. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3392 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/Makefile.in | 2 +- bacula/src/bacula.h | 17 +++++- bacula/src/console/console.c | 3 +- bacula/src/filed/job.c | 2 +- bacula/src/findlib/attribs.c | 2 +- bacula/src/jcr.h | 2 +- bacula/src/lib/message.h | 18 +++--- bacula/src/lib/res.c | 2 - bacula/src/lib/util.c | 115 +++++++++++++++++++++-------------- bacula/src/stored/dircmd.c | 2 - 10 files changed, 97 insertions(+), 68 deletions(-) diff --git a/bacula/Makefile.in b/bacula/Makefile.in index 19c2d93c4a..e4a0562cdd 100755 --- a/bacula/Makefile.in +++ b/bacula/Makefile.in @@ -23,7 +23,7 @@ fd_subdirs = src scripts src/lib src/findlib src/filed \ @GNOME_DIR@ @TRAY_MONITOR_DIR@ @WX_DIR@ # Non-client-only directores -subdirs = src/cats @DIRD_DIR@ @STORED_DIR@ src/tools +subdirs = src/cats @DIRD_DIR@ @STORED_DIR@ src/tools all_subdirs = ${fd_subdirs} ${@ALL_DIRS@} manpages diff --git a/bacula/src/bacula.h b/bacula/src/bacula.h index 5619c0d7f2..09291ab3ca 100644 --- a/bacula/src/bacula.h +++ b/bacula/src/bacula.h @@ -32,10 +32,8 @@ #else #include "winconfig.h" #endif -#include "winhost.h" #else #include "config.h" -#include "host.h" #endif @@ -64,7 +62,11 @@ #if HAVE_ALLOCA_H #include #endif - +#if defined(_MSC_VER) +#include +#include +#include +#endif #include #include @@ -73,6 +75,12 @@ #define O_NOATIME 0 #endif +#if defined(_MSC_VER) +extern "C" { +#include "getopt.h" +} +#endif + #ifdef xxxxx #ifdef HAVE_GETOPT_LONG #include @@ -158,6 +166,9 @@ #if defined(HAVE_WIN32) #include "win32/winapi.h" +#include "winhost.h" +#else +#include "host.h" #endif #ifndef HAVE_ZLIB_H diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index bcaf07a9fc..b7064e0bd2 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -292,8 +292,8 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock) static int tls_pem_callback(char *buf, int size, const void *userdata) { #ifdef HAVE_TLS -# ifdef HAVE_MINGW const char *prompt = (const char *)userdata; +# if defined(HAVE_WIN32) sendit(prompt); if (win32_cgets(buf, size) == NULL) { buf[0] = 0; @@ -302,7 +302,6 @@ static int tls_pem_callback(char *buf, int size, const void *userdata) return strlen(buf); } # else - const char *prompt = (const char *)userdata; char *passwd; passwd = getpass(prompt); diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 5d7ec87caf..0c81adc143 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -25,7 +25,7 @@ #include "filed.h" #if defined(WIN32_VSS) -#include "vss.h" +#include "vss.h" static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER; static int enable_vss; diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index ab9a87f51d..4c71cc679e 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -123,7 +123,7 @@ int select_data_stream(FF_PKT *ff_pkt) default: /* All stream types that do not support encryption should clear out * FO_ENCRYPT above, and this code block should be unreachable. */ - ASSERT(!ff_pkt->flags & FO_ENCRYPT); + ASSERT(!(ff_pkt->flags & FO_ENCRYPT)); return STREAM_NONE; } } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index f37b6f6865..6a2dad36e4 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -353,7 +353,7 @@ struct s_last_job { }; extern struct s_last_job last_job; -extern dlist * DLL_IMP_EXP last_jobs; +extern DLL_IMP_EXP dlist * last_jobs; /* The following routines are found in lib/jcr.c */ diff --git a/bacula/src/lib/message.h b/bacula/src/lib/message.h index 1d144bb74a..66b0f82dd8 100644 --- a/bacula/src/lib/message.h +++ b/bacula/src/lib/message.h @@ -133,14 +133,14 @@ void Qmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...); bool get_trace(void); typedef void (*sql_query)(JCR *jcr, const char *cmd); -extern sql_query DLL_IMP_EXP p_sql_query; +extern DLL_IMP_EXP sql_query p_sql_query; -extern int DLL_IMP_EXP debug_level; -extern int DLL_IMP_EXP verbose; -extern char DLL_IMP_EXP my_name[]; -extern const char * DLL_IMP_EXP working_directory; -extern time_t DLL_IMP_EXP daemon_start_time; +extern DLL_IMP_EXP int debug_level; +extern DLL_IMP_EXP int verbose; +extern DLL_IMP_EXP char my_name[]; +extern DLL_IMP_EXP const char * working_directory; +extern DLL_IMP_EXP time_t daemon_start_time; -extern int DLL_IMP_EXP console_msg_pending; -extern FILE * DLL_IMP_EXP con_fd; /* Console file descriptor */ -extern brwlock_t DLL_IMP_EXP con_lock; /* Console lock structure */ +extern DLL_IMP_EXP int console_msg_pending; +extern DLL_IMP_EXP FILE * con_fd; /* Console file descriptor */ +extern DLL_IMP_EXP brwlock_t con_lock; /* Console lock structure */ diff --git a/bacula/src/lib/res.c b/bacula/src/lib/res.c index c35fb68ee5..670b61fe59 100644 --- a/bacula/src/lib/res.c +++ b/bacula/src/lib/res.c @@ -23,8 +23,6 @@ #include "bacula.h" -extern int debug_level; - /* Each daemon has a slightly different set of * resources, so it will define the following * global values. diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 505851583f..f991483202 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -428,63 +428,86 @@ int do_shell_expansion(char *name, int name_len) void make_session_key(char *key, char *seed, int mode) { - int j, k; - struct MD5Context md5c; - unsigned char md5key[16], md5key1[16]; - char s[1024]; - - s[0] = 0; - if (seed != NULL) { - bstrncat(s, seed, sizeof(s)); - } + int j, k; + struct MD5Context md5c; + unsigned char md5key[16], md5key1[16]; + char s[1024]; + + s[0] = 0; + if (seed != NULL) { + bstrncat(s, seed, sizeof(s)); + } + + /* The following creates a seed for the session key generator + based on a collection of volatile and environment-specific + information unlikely to be vulnerable (as a whole) to an + exhaustive search attack. If one of these items isn't + available on your machine, replace it with something + equivalent or, if you like, just delete it. */ - /* The following creates a seed for the session key generator - based on a collection of volatile and environment-specific - information unlikely to be vulnerable (as a whole) to an - exhaustive search attack. If one of these items isn't - available on your machine, replace it with something - equivalent or, if you like, just delete it. */ - - sprintf(s + strlen(s), "%lu", (unsigned long)getpid()); - sprintf(s + strlen(s), "%lu", (unsigned long)getppid()); - (void)getcwd(s + strlen(s), 256); - sprintf(s + strlen(s), "%lu", (unsigned long)clock()); - sprintf(s + strlen(s), "%lu", (unsigned long)time(NULL)); +#if defined(HAVE_WIN32) + { + LARGE_INTEGER li; + DWORD length; + FILETIME ft; + char *p; + + p = s; + sprintf(s + strlen(s), "%lu", (unsigned long)GetCurrentProcessId()); + (void)getcwd(s + strlen(s), 256); + sprintf(s + strlen(s), "%lu", (unsigned long)GetTickCount()); + QueryPerformanceCounter(&li); + sprintf(s + strlen(s), "%lu", (unsigned long)li.LowPart); + GetSystemTimeAsFileTime(&ft); + sprintf(s + strlen(s), "%lu", (unsigned long)ft.dwLowDateTime); + sprintf(s + strlen(s), "%lu", (unsigned long)ft.dwHighDateTime); + length = 256; + GetComputerName(s + strlen(s), &length); + length = 256; + GetUserName(s + strlen(s), &length); + } +#else + sprintf(s + strlen(s), "%lu", (unsigned long)getpid()); + sprintf(s + strlen(s), "%lu", (unsigned long)getppid()); + (void)getcwd(s + strlen(s), 256); + sprintf(s + strlen(s), "%lu", (unsigned long)clock()); + sprintf(s + strlen(s), "%lu", (unsigned long)time(NULL)); #if defined(Solaris) - sysinfo(SI_HW_SERIAL,s + strlen(s), 12); + sysinfo(SI_HW_SERIAL,s + strlen(s), 12); #endif #if defined(HAVE_GETHOSTID) - sprintf(s + strlen(s), "%lu", (unsigned long) gethostid()); + sprintf(s + strlen(s), "%lu", (unsigned long) gethostid()); #endif - gethostname(s + strlen(s), 256); - sprintf(s + strlen(s), "%u", (unsigned)getuid()); - sprintf(s + strlen(s), "%u", (unsigned)getgid()); - MD5Init(&md5c); - MD5Update(&md5c, (unsigned char *)s, strlen(s)); - MD5Final(md5key, &md5c); - sprintf(s + strlen(s), "%lu", (unsigned long)((time(NULL) + 65121) ^ 0x375F)); - MD5Init(&md5c); - MD5Update(&md5c, (unsigned char *)s, strlen(s)); - MD5Final(md5key1, &md5c); + gethostname(s + strlen(s), 256); + sprintf(s + strlen(s), "%u", (unsigned)getuid()); + sprintf(s + strlen(s), "%u", (unsigned)getgid()); +#endif + MD5Init(&md5c); + MD5Update(&md5c, (unsigned char *)s, strlen(s)); + MD5Final(md5key, &md5c); + sprintf(s + strlen(s), "%lu", (unsigned long)((time(NULL) + 65121) ^ 0x375F)); + MD5Init(&md5c); + MD5Update(&md5c, (unsigned char *)s, strlen(s)); + MD5Final(md5key1, &md5c); #define nextrand (md5key[j] ^ md5key1[j]) - if (mode) { - for (j = k = 0; j < 16; j++) { - unsigned char rb = nextrand; + if (mode) { + for (j = k = 0; j < 16; j++) { + unsigned char rb = nextrand; #define Rad16(x) ((x) + 'A') - key[k++] = Rad16((rb >> 4) & 0xF); - key[k++] = Rad16(rb & 0xF); + key[k++] = Rad16((rb >> 4) & 0xF); + key[k++] = Rad16(rb & 0xF); #undef Rad16 - if (j & 1) { - key[k++] = '-'; - } - } - key[--k] = 0; - } else { - for (j = 0; j < 16; j++) { - key[j] = nextrand; + if (j & 1) { + key[k++] = '-'; } } + key[--k] = 0; + } else { + for (j = 0; j < 16; j++) { + key[j] = nextrand; + } + } } #undef nextrand diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index d1134f140e..877b4b01b2 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -43,8 +43,6 @@ extern BSOCK *filed_chan; extern int r_first, r_last; extern struct s_res resources[]; -extern char my_name[]; -extern time_t daemon_start_time; extern struct s_last_job last_job; extern bool init_done; -- 2.39.5