From c0164685c7f693dd330074884185c83f95c3ee9a Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Thu, 27 Jul 2006 01:59:06 +0000 Subject: [PATCH] Complete port to Windows The one remaining piece is the final NSIS script update and automatic creation of the installation package. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3182 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/autoconf/configure.in | 8 - bacula/configure | 14 +- bacula/src/baconfig.h | 13 + bacula/src/bacula.h | 4 +- bacula/src/cats/bdb_list.c | 4 +- bacula/src/cats/make_sqlite3_tables.in | 2 +- bacula/src/cats/make_sqlite_tables.in | 2 +- bacula/src/cats/mysql.c | 2 +- bacula/src/cats/update_mysql_tables.in | 2 +- bacula/src/cats/update_postgresql_tables.in | 2 +- bacula/src/console/console.c | 4 - bacula/src/dird/dird.c | 17 +- bacula/src/dird/inc_conf.c | 2 +- bacula/src/dird/ua_update.c | 4 +- bacula/src/filed/Makefile.mingw | 231 ------ bacula/src/filed/job.c | 16 +- bacula/src/filed/status.c | 1 - bacula/src/filed/win32/.cvsignore | 1 - bacula/src/filed/win32/Makefile.in | 124 ---- bacula/src/filed/win32/Makefile.mingw | 125 ---- bacula/src/filed/win32/bacula.bmp | Bin 3126 -> 0 bytes bacula/src/filed/win32/bacula.ico | Bin 766 -> 0 bytes bacula/src/filed/win32/bacula.rc | 1 - bacula/src/filed/win32/error.ico | Bin 766 -> 0 bytes bacula/src/filed/win32/idle.ico | Bin 766 -> 0 bytes bacula/src/filed/win32/mymapi32.def | 151 ---- bacula/src/filed/win32/popup.c | 47 -- bacula/src/filed/win32/running.ico | Bin 766 -> 0 bytes bacula/src/filed/win32/saving.ico | Bin 766 -> 0 bytes bacula/src/filed/win32/warn.ico | Bin 766 -> 0 bytes bacula/src/filed/win32/winabout.cpp | 80 -- bacula/src/filed/win32/winabout.h | 48 -- bacula/src/filed/win32/winbacula.h | 71 -- bacula/src/filed/win32/winevents.cpp | 87 --- bacula/src/filed/win32/winevents.h | 44 -- bacula/src/filed/win32/winmain.cpp | 330 --------- bacula/src/filed/win32/winres.h | 46 -- bacula/src/filed/win32/winres.rc | 181 ----- bacula/src/filed/win32/winservice.cpp | 764 -------------------- bacula/src/filed/win32/winservice.h | 125 ---- bacula/src/filed/win32/winstat.cpp | 97 --- bacula/src/filed/win32/winstat.h | 45 -- bacula/src/filed/win32/wintray.cpp | 353 --------- bacula/src/filed/win32/wintray.h | 94 --- bacula/src/findlib/Makefile.in | 2 +- bacula/src/findlib/Makefile.mingw | 162 ----- bacula/src/findlib/attribs.c | 13 - bacula/src/lib/Makefile.in | 4 +- bacula/src/lib/Makefile.mingw | 232 ------ bacula/src/lib/bpipe.c | 96 +-- bacula/src/lib/bregex.h | 1 + bacula/src/lib/bsys.c | 15 - bacula/src/lib/message.h | 2 +- bacula/src/lib/var.c | 2 - bacula/src/lib/winapi.c | 259 ------- bacula/src/lib/winapi.h | 171 ----- bacula/src/stored/ansi_label.c | 8 +- bacula/src/stored/block.c | 12 +- bacula/src/stored/btape.c | 8 +- bacula/src/stored/dev.c | 116 ++- bacula/src/stored/protos.h | 6 +- bacula/src/stored/reserve.c | 20 +- bacula/src/stored/spool.c | 18 +- bacula/src/stored/status.c | 407 ++++++++--- bacula/src/stored/stored.c | 4 + bacula/src/stored/stored.h | 2 +- bacula/src/tools/Makefile.in | 11 +- bacula/src/tools/testfind.c | 398 ++++++++-- 68 files changed, 894 insertions(+), 4217 deletions(-) delete mode 100644 bacula/src/filed/Makefile.mingw delete mode 100644 bacula/src/filed/win32/.cvsignore delete mode 100755 bacula/src/filed/win32/Makefile.in delete mode 100644 bacula/src/filed/win32/Makefile.mingw delete mode 100644 bacula/src/filed/win32/bacula.bmp delete mode 100644 bacula/src/filed/win32/bacula.ico delete mode 100644 bacula/src/filed/win32/bacula.rc delete mode 100644 bacula/src/filed/win32/error.ico delete mode 100644 bacula/src/filed/win32/idle.ico delete mode 100644 bacula/src/filed/win32/mymapi32.def delete mode 100644 bacula/src/filed/win32/popup.c delete mode 100644 bacula/src/filed/win32/running.ico delete mode 100644 bacula/src/filed/win32/saving.ico delete mode 100644 bacula/src/filed/win32/warn.ico delete mode 100755 bacula/src/filed/win32/winabout.cpp delete mode 100755 bacula/src/filed/win32/winabout.h delete mode 100755 bacula/src/filed/win32/winbacula.h delete mode 100755 bacula/src/filed/win32/winevents.cpp delete mode 100755 bacula/src/filed/win32/winevents.h delete mode 100755 bacula/src/filed/win32/winmain.cpp delete mode 100755 bacula/src/filed/win32/winres.h delete mode 100644 bacula/src/filed/win32/winres.rc delete mode 100755 bacula/src/filed/win32/winservice.cpp delete mode 100755 bacula/src/filed/win32/winservice.h delete mode 100755 bacula/src/filed/win32/winstat.cpp delete mode 100755 bacula/src/filed/win32/winstat.h delete mode 100755 bacula/src/filed/win32/wintray.cpp delete mode 100755 bacula/src/filed/win32/wintray.h delete mode 100644 bacula/src/findlib/Makefile.mingw delete mode 100644 bacula/src/lib/Makefile.mingw delete mode 100644 bacula/src/lib/winapi.c delete mode 100644 bacula/src/lib/winapi.h diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 43d3fbc07e..bd853a3fa0 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -2004,7 +2004,6 @@ AC_OUTPUT([autoconf/Make.common \ src/stored/bacula-sd.conf \ src/filed/Makefile \ src/filed/bacula-fd.conf \ - src/filed/win32/Makefile \ src/cats/Makefile \ src/cats/make_catalog_backup \ src/cats/delete_catalog_backup \ @@ -2049,13 +2048,6 @@ AC_OUTPUT([autoconf/Make.common \ src/findlib/Makefile \ src/pygtk-console/Makefile \ src/tools/Makefile \ - src/win32/winbacula.nsi \ - src/win32/baculafd/bacula-fd.conf \ - src/win32/Makefile \ - src/win32/Makefile.vcpp \ - src/win32/console/bconsole.conf \ - src/win32/wx-console/wx-console.conf \ - src/win32/pebuilder/Makefile \ po/Makefile.in \ $PFILES ], [(echo "Doing make of dependencies"; ${MAKE:-make} depend;) ] diff --git a/bacula/configure b/bacula/configure index b7c8f95bd5..107e8d1a67 100755 --- a/bacula/configure +++ b/bacula/configure @@ -16631,9 +16631,9 @@ echo "$as_me: error: Unable to find libpq-fe.h in standard locations" >&2;} elif test -f $withval/include/postgresql/libpq-fe.h; then POSTGRESQL_INCDIR=$withval/include/postgresql if test -d $withval/lib64; then - POSTGRESQL_LIBDIR=$withval/lib64 + POSTGRESQL_LIBDIR=$withval/lib64 else - POSTGRESQL_LIBDIR=$withval/lib + POSTGRESQL_LIBDIR=$withval/lib fi POSTGRESQL_BINDIR=$withval/bin else @@ -29971,7 +29971,7 @@ if test "x${subsysdir}" = "x${sbindir}" ; then exit 1 fi - ac_config_files="$ac_config_files autoconf/Make.common Makefile manpages/Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/gnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf scripts/wxconsole.console_apps scripts/wxconsole.desktop.consolehelper scripts/wxconsole.desktop.xsu src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/gnome2-console/Makefile src/gnome2-console/gnome-console.conf src/wx-console/Makefile src/wx-console/wx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/filed/win32/Makefile src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite_database src/cats/update_sqlite_tables src/cats/make_sqlite_tables src/cats/grant_sqlite_privileges src/cats/drop_sqlite_tables src/cats/drop_sqlite_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/pygtk-console/Makefile src/tools/Makefile src/win32/winbacula.nsi src/win32/baculafd/bacula-fd.conf src/win32/Makefile src/win32/Makefile.vcpp src/win32/console/bconsole.conf src/win32/wx-console/wx-console.conf src/win32/pebuilder/Makefile po/Makefile.in $PFILES" + ac_config_files="$ac_config_files autoconf/Make.common Makefile manpages/Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/gnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf scripts/wxconsole.console_apps scripts/wxconsole.desktop.consolehelper scripts/wxconsole.desktop.xsu src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/gnome2-console/Makefile src/gnome2-console/gnome-console.conf src/wx-console/Makefile src/wx-console/wx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite_database src/cats/update_sqlite_tables src/cats/make_sqlite_tables src/cats/grant_sqlite_privileges src/cats/drop_sqlite_tables src/cats/drop_sqlite_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/pygtk-console/Makefile src/tools/Makefile po/Makefile.in $PFILES" ac_config_commands="$ac_config_commands default" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -30564,7 +30564,6 @@ do "src/stored/bacula-sd.conf" ) CONFIG_FILES="$CONFIG_FILES src/stored/bacula-sd.conf" ;; "src/filed/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/filed/Makefile" ;; "src/filed/bacula-fd.conf" ) CONFIG_FILES="$CONFIG_FILES src/filed/bacula-fd.conf" ;; - "src/filed/win32/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/filed/win32/Makefile" ;; "src/cats/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/cats/Makefile" ;; "src/cats/make_catalog_backup" ) CONFIG_FILES="$CONFIG_FILES src/cats/make_catalog_backup" ;; "src/cats/delete_catalog_backup" ) CONFIG_FILES="$CONFIG_FILES src/cats/delete_catalog_backup" ;; @@ -30609,13 +30608,6 @@ do "src/findlib/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/findlib/Makefile" ;; "src/pygtk-console/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/pygtk-console/Makefile" ;; "src/tools/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/tools/Makefile" ;; - "src/win32/winbacula.nsi" ) CONFIG_FILES="$CONFIG_FILES src/win32/winbacula.nsi" ;; - "src/win32/baculafd/bacula-fd.conf" ) CONFIG_FILES="$CONFIG_FILES src/win32/baculafd/bacula-fd.conf" ;; - "src/win32/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/win32/Makefile" ;; - "src/win32/Makefile.vcpp" ) CONFIG_FILES="$CONFIG_FILES src/win32/Makefile.vcpp" ;; - "src/win32/console/bconsole.conf" ) CONFIG_FILES="$CONFIG_FILES src/win32/console/bconsole.conf" ;; - "src/win32/wx-console/wx-console.conf" ) CONFIG_FILES="$CONFIG_FILES src/win32/wx-console/wx-console.conf" ;; - "src/win32/pebuilder/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/win32/pebuilder/Makefile" ;; "po/Makefile.in" ) CONFIG_FILES="$CONFIG_FILES po/Makefile.in" ;; "$PFILES" ) CONFIG_FILES="$CONFIG_FILES $PFILES" ;; "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index c6c6854e77..a4a839b6bb 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -71,14 +71,27 @@ void InitWinAPIWrapper(); #define OSDependentInit() InitWinAPIWrapper() #undef ENABLE_NLS +#if defined(BUILDING_DLL) +# define DLL_IMP_EXP _declspec(dllexport) +#elif defined(USING_DLL) +# define DLL_IMP_EXP _declspec(dllimport) +#else # define DLL_IMP_EXP +#endif + #else #define DLL_IMP_EXP #define OSDependentInit() +#define tape_open open +#define tape_ioctl ioctl +#define tape_read read +#define tape_write write +#define tape_close ::close #endif + #ifdef ENABLE_NLS #include #include diff --git a/bacula/src/bacula.h b/bacula/src/bacula.h index 69b43828af..60a219fee6 100644 --- a/bacula/src/bacula.h +++ b/bacula/src/bacula.h @@ -29,8 +29,6 @@ #if defined(HAVE_WIN32) #if defined(HAVE_MINGW) #include "mingwconfig.h" -#define _STAT_H /* don't pull in MinGW stat.h */ -#define _STAT_DEFINED /* don't pull in MinGW stat.h */ #else #include "winconfig.h" #endif @@ -149,7 +147,7 @@ #endif #if defined(HAVE_WIN32) -#include "lib/winapi.h" +#include "win32/winapi.h" #endif #ifndef HAVE_ZLIB_H diff --git a/bacula/src/cats/bdb_list.c b/bacula/src/cats/bdb_list.c index 902739c7a3..fbadb34ddc 100644 --- a/bacula/src/cats/bdb_list.c +++ b/bacula/src/cats/bdb_list.c @@ -52,7 +52,7 @@ /* * Submit general SQL query */ -int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, +int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose) { sendit(ctx, "SQL Queries not implemented with internal database.\n"); @@ -272,7 +272,7 @@ void db_list_files_for_job(JCR *jcr, B_DB *mdb, uint32_t jobid, DB_LIST_HANDLER void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx) { } -int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, +int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type) { return 0; diff --git a/bacula/src/cats/make_sqlite3_tables.in b/bacula/src/cats/make_sqlite3_tables.in index 4df3610ed2..fe44892255 100644 --- a/bacula/src/cats/make_sqlite3_tables.in +++ b/bacula/src/cats/make_sqlite3_tables.in @@ -276,7 +276,7 @@ CREATE TABLE NextId ( PRIMARY KEY (TableName) ); - + -- Initialize JobId to start at 1 INSERT INTO NextId (id, TableName) VALUES (1, "Job"); diff --git a/bacula/src/cats/make_sqlite_tables.in b/bacula/src/cats/make_sqlite_tables.in index 4df3610ed2..fe44892255 100644 --- a/bacula/src/cats/make_sqlite_tables.in +++ b/bacula/src/cats/make_sqlite_tables.in @@ -276,7 +276,7 @@ CREATE TABLE NextId ( PRIMARY KEY (TableName) ); - + -- Initialize JobId to start at 1 INSERT INTO NextId (id, TableName) VALUES (1, "Job"); diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index ad0be7a6ca..3c1a6e2fd6 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -191,7 +191,7 @@ db_close_database(JCR *jcr, B_DB *mdb) db_end_transaction(jcr, mdb); P(mutex); mdb->ref_count--; -#ifdef HAVE_TREAD_SAFE_MYSQL +#if defined(HAVE_THREAD_SAFE_MYSQL) my_thread_end(); #endif if (mdb->ref_count == 0) { diff --git a/bacula/src/cats/update_mysql_tables.in b/bacula/src/cats/update_mysql_tables.in index bdb5a213e1..1361514577 100755 --- a/bacula/src/cats/update_mysql_tables.in +++ b/bacula/src/cats/update_mysql_tables.in @@ -3,7 +3,7 @@ # Shell script to update MySQL tables from version 1.38 to 1.39 # echo " " -echo "This script will update a Bacula SQLite database from version 9 to 10" +echo "This script will update a Bacula MySQL database from version 9 to 10" echo " which is needed to convert from Bacula version 1.38.x to 1.39.x or higher" echo "Depending on the size of your database," echo "this script may take several minutes to run." diff --git a/bacula/src/cats/update_postgresql_tables.in b/bacula/src/cats/update_postgresql_tables.in index 87ea9128a5..a584543ee3 100755 --- a/bacula/src/cats/update_postgresql_tables.in +++ b/bacula/src/cats/update_postgresql_tables.in @@ -3,7 +3,7 @@ # Shell script to update PostgreSQL tables from version 1.38 to 1.39 # echo " " -echo "This script will update a Bacula SQLite database from version 9 to 10" +echo "This script will update a Bacula PostgreSQL database from version 9 to 10" echo " which is needed to convert from Bacula version 1.38.x to 1.39.x or higher" echo "Depending on the size of your database," echo "this script may take several minutes to run." diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index abdfc8f0f5..8e1d32e0e8 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -43,10 +43,6 @@ /* Exported variables */ extern int rl_catch_signals; -#ifdef HAVE_MINGW -/* Remove when we have real lib in src/lib */ -int enable_vss; -#endif /* Imported functions */ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 2d0afc38f7..db10ddb919 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -25,7 +25,7 @@ #include "dird.h" /* Forward referenced subroutines */ -static void terminate_dird(int sig); +void terminate_dird(int sig); static int check_resources(); static void dir_sql_query(JCR *jcr, const char *cmd); @@ -99,6 +99,10 @@ static void usage() * Main Bacula Server program * */ +#if defined(HAVE_WIN32) +#define main BaculaMain +#endif + int main (int argc, char *argv[]) { int ch; @@ -230,7 +234,9 @@ int main (int argc, char *argv[]) drop(uid, gid); /* reduce priveleges if requested */ +#if !defined(HAVE_WIN32) signal(SIGHUP, reload_config); +#endif init_console_msg(working_directory); @@ -273,7 +279,7 @@ static void dir_sql_query(JCR *jcr, const char *cmd) } /* Cleanup and then exit */ -static void terminate_dird(int sig) +void terminate_dird(int sig) { static bool already_here = false; @@ -394,7 +400,9 @@ extern "C" void reload_config(int sig) { static bool already_here = false; +#if !defined(HAVE_WIN32) sigset_t set; +#endif JCR *jcr; int njobs = 0; /* number of running jobs */ int table, rtable; @@ -404,9 +412,12 @@ void reload_config(int sig) abort(); /* Oops, recursion -> die */ } already_here = true; + +#if !defined(HAVE_WIN32) sigemptyset(&set); sigaddset(&set, SIGHUP); sigprocmask(SIG_BLOCK, &set, NULL); +#endif lock_jobs(); LockRes(); @@ -470,8 +481,10 @@ void reload_config(int sig) bail_out: UnlockRes(); unlock_jobs(); +#if !defined(HAVE_WIN32) sigprocmask(SIG_UNBLOCK, &set, NULL); signal(SIGHUP, reload_config); +#endif already_here = false; } diff --git a/bacula/src/dird/inc_conf.c b/bacula/src/dird/inc_conf.c index f0b9c144b1..ab0fc6e564 100644 --- a/bacula/src/dird/inc_conf.c +++ b/bacula/src/dird/inc_conf.c @@ -24,7 +24,7 @@ #include "bacula.h" #include "dird.h" #ifndef HAVE_REGEX_H -#include "lib/regex.h" +#include "lib/bregex.h" #else #include #endif diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index f8bf9c3f07..58788a8b9c 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -223,7 +223,7 @@ static void update_volrecycle(UAContext *ua, char *val, MEDIA_DBR *mr) POOL_MEM query(PM_MESSAGE); if (!is_yesno(val, &recycle)) { bsendmsg(ua, _("Invalid value. It must be yes or no.\n")); - return; + return; } Mmsg(query, "UPDATE Media SET Recycle=%d WHERE MediaId=%s", recycle, edit_int64(mr->MediaId, ed1)); @@ -243,7 +243,7 @@ static void update_volinchanger(UAContext *ua, char *val, MEDIA_DBR *mr) POOL_MEM query(PM_MESSAGE); if (!is_yesno(val, &InChanger)) { bsendmsg(ua, _("Invalid value. It must be yes or no.\n")); - return; + return; } Mmsg(query, "UPDATE Media SET InChanger=%d WHERE MediaId=%s", InChanger, edit_int64(mr->MediaId, ed1)); diff --git a/bacula/src/filed/Makefile.mingw b/bacula/src/filed/Makefile.mingw deleted file mode 100644 index 05ea039ff1..0000000000 --- a/bacula/src/filed/Makefile.mingw +++ /dev/null @@ -1,231 +0,0 @@ -# -# Bacula Makefile for the File daemon -# -# Version $Id$ -# - - -# autoconf/Make.common.in -*- Makefile -*- -# release date (man), LSM date, version number/name, current maintainer -DATE="15 Apr 2004" -LSMDATE=15Apr04 -VERSION=1.35.0 -VERNAME=bacula-$(VERSION)# -MAINT=Kern Sibbald# -MAINTEMAIL=# -WEBMAINT=# -WEBMAINTEMAIL=# -WEBPAGE=# -FTPSITENAME=# -FTPSITEDIR=# -#------------------------------------------------------------------------- - -SHELL = /bin/sh - -# Installation target directories & other installation stuff -prefix = -exec_prefix = -binprefix = -manprefix = -sbindir = /sbin -sysconfdir = /etc/bacula -scriptdir = /etc/bacula -mandir = ${prefix}/man/man1 -manext = 1 - -# Tools & program stuff -CC = gcc -CPP = gcc -E -CXX = g++ -MV = /usr/bin/mv -RM = /usr/bin/rm -RMF = /usr/bin/rm -f -CP = /usr/bin/cp -SED = /usr/bin/sed -AWK = /usr/bin/awk -ECHO = /usr/bin/echo -CMP = /usr/bin/cmp -TBL = /usr/bin/tbl -AR = /usr/bin/ar -RANLIB = /usr/bin/ranlib -INSTALL = /usr/bin/install -c -# add the -s to the following in PRODUCTION mode -INSTALL_PROGRAM = /usr/bin/install -c -m 754 -INSTALL_DATA = /usr/bin/install -c -m 644 -INSTALL_SCRIPT = /usr/bin/install -c -m 754 -INSTALL_CONFIG = /usr/bin/install -c -m 640 - -# Flags & libs -CFLAGS = -g -O2 -CPPFLAGS = -LDFLAGS = -O -TTOOL_LDFLAGS = -DEFS = -DHAVE_WIN32 -DHAVE_MINGW -LIBS = -lpthreadGC -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool \ - -lwinmm -lshell32 -lcomctl32 -lctl3d32 -ladvapi32 -lwsock32 \ - -lmsvcrt -DINCLUDE = -DLIB = -DB_LIBS = - -# Windows (cygwin) flags -WCFLAGS = -mwindows -WLDFLAGS = -mwindows -Wl,--subsystem,windows -mthreads - -# X Include directory -#XINC = @XPM_CFLAGS@ - -# extra libraries needed by X on some systems, X library location -#XLIB = @XPM_LIBS@ -lX11 - -# End of common section of the Makefile -#------------------------------------------------------------------------- - -srcdir = . -VPATH = . -.PATH: . - -# one up -basedir = .. -# top dir -topdir = ../.. -# this dir relative to top dir -thisdir = src/filed - -DEBUG= - -first_rule: all -dummy: - -# -SVRSRCS = filed.c authenticate.c backup.c chksum.c estimate.c \ - filed_conf.c heartbeat.c job.c \ - restore.c status.c verify.c verify_vol.c -SVROBJS = filed.o authenticate.o backup.o chksum.o estimate.o \ - filed_conf.o heartbeat.o job.o \ - restore.o status.o verify.o verify_vol.o - -# these are the objects that are changed by the .configure process -EXTRAOBJS = - -FDLIBS = -lz # extra libs for File daemon - -# extra items for linking on Win32 -WIN32OBJS = win32/winmain.o win32/winlib.a win32/winres.res -win32 = $(WIN32OBJS) - -WIN32LIBS = $(win32) - -.SUFFIXES: .c .o -.PHONY: -.DONTCARE: - -# inference rules -.c.o: - $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) -I../win32/compat $(DINCLUDE) $(CFLAGS) $< -#------------------------------------------------------------------------- -all: win32 bacula-fd - @echo "==== Make of filed is good ====" - @echo " " - -win32/winlib.a: - (cd win32; $(MAKE) -f Makefile.mingw DESTDIR=$(DESTDIR)) - @rm -f bacula-fd.exe - -win32/winmain.o: - (cd win32; $(MAKE) -f Makefile.mingw DESTDIR=$(DESTDIR)) - @rm -f bacula-fd.exe - -win32/winres.res: - (cd win32; $(MAKE) -f Makefile.mingw DESTDIR=$(DESTDIR)) - @rm -f bacula-fd.exe - -# win32 libraries if needed -win32: $(WIN32OBJS) - (cd win32; $(MAKE) -f Makefile.mingw DESTDIR=$(DESTDIR)) - @rm -f bacula-fd.exe - -bacula-fd: $(SVROBJS) ../findlib/libfind.a ../lib/libbac.a win32 - $(CXX) $(WLDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(SVROBJS) \ - $(WIN32LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) $(DLIB) - -static-bacula-fd: $(SVROBJS) ../findlib/libfind.a ../lib/libbac.a win32 - $(CXX) $(WLDFLAGS) $(LDFLAGS) -static -L../lib -L../findlib -o $@ $(SVROBJS) \ - $(WIN32LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) $(DLIB) - strip $@ - -../findlib/libfind.a: ../findlib/*.c - (cd ../findlib/; $(MAKE) -f Makefile.mingw DESTDIR=$(DESTDIR)) - @rm -f bacula-fd.exe - -../lib/libbac.a: ../lib/*.c* - (cd ../lib/; $(MAKE) -f Makefile.mingw DESTDIR=$(DESTDIR)) - @rm -f bacula-fd.exe - -clean: - @$(RMF) bacula-fd filed core core.* a.out *.o *.bak *~ *.intpro *.extpro 1 2 3 - @$(RMF) static-bacula-fd - if test -f win32/Makefile; then \ - (cd win32; $(MAKE) clean); \ - fi - -realclean: clean - @$(RMF) tags bacula-fd.conf - -distclean: realclean - if test $(srcdir) = .; then $(MAKE) realclean; fi - (cd $(srcdir); $(RMF) Makefile; $(RMF) -r CVS) - if test -f win32/Makefile; then \ - (cd win32; $(MAKE) distclean); \ - fi - -devclean: realclean - if test $(srcdir) = .; then $(MAKE) realclean; fi - (cd $(srcdir); $(RMF) Makefile) - if test -f win32/Makefile; then \ - (cd win32; $(MAKE) devclean); \ - fi - -install: all - $(INSTALL_PROGRAM) bacula-fd $(DESTDIR)$(sbindir)/bacula-fd - @srcconf=bacula-fd.conf; \ - if test -f ${DESTDIR}${sysconfdir}/$$srcconf; then \ - destconf=$$srcconf.new; \ - echo " ==> Found existing $$srcconf, installing new conf file as $$destconf"; \ - else \ - destconf=$$srcconf; \ - fi; \ - echo "${INSTALL_CONFIG} $$srcconf ${DESTDIR}${sysconfdir}/$$destconf"; \ - ${INSTALL_CONFIG} $$srcconf ${DESTDIR}${sysconfdir}/$$destconf - @if test -f static-bacula-fd; then \ - $(INSTALL_PROGRAM) static-bacula-fd $(DESTDIR)$(sbindir)/static-bacula-fd; \ - fi - - - -uninstall: - (cd $(DESTDIR)$(sbindir); $(RMF) bacula-fd) - (cd $(DESTDIR)$(sbindir); $(RMF) bacula-fd.conf) - (cd $(DESTDIR)$(sbindir); $(RMF) bacula-fd.conf.new) - - - -# Semi-automatic generation of dependencies: -# Use gcc -MM because X11 `makedepend' doesn't work on all systems -# and it also includes system headers. -# `semi'-automatic since dependencies are generated at distribution time. - -depend: - @$(MV) Makefile Makefile.bak - @$(SED) "/^# DO NOT DELETE:/,$$ d" Makefile.bak > Makefile - @$(ECHO) "# DO NOT DELETE: nice dependency list follows" >> Makefile - @$(CC) -S -M $(CPPFLAGS) $(XINC) -I$(srcdir) -I$(basedir) $(SQL_INC) *.c >> Makefile - @if test -f Makefile ; then \ - $(RMF) Makefile.bak; \ - else \ - $(MV) Makefile.bak Makefile; \ - echo -e "Something went wrong\n\a"; \ - fi - -# ----------------------------------------------------------------------- -# DO NOT DELETE: nice dependency list follows diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index ee00e1e31e..c8100a12bf 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -23,15 +23,16 @@ #include "bacula.h" #include "filed.h" -#ifdef WIN32_VSS + +#if defined(WIN32_VSS) #include "vss.h" + static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER; +static int enable_vss; #endif extern CLIENT *me; /* our client resource */ -int enable_vss = 0; /* set to use vss */ - /* Imported functions */ extern int status_cmd(JCR *jcr); extern int qstatus_cmd(JCR *jcr); @@ -991,10 +992,13 @@ static void set_options(findFOPTS *fo, const char *opts) static int fileset_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; + +#if defined(WIN32_VSS) int vss = 0; sscanf(dir->msg, "fileset vss=%d", &vss); enable_vss = vss; +#endif if (!init_fileset(jcr)) { return 0; @@ -1250,7 +1254,7 @@ static int backup_cmd(JCR *jcr) int SDJobStatus; char ed1[50], ed2[50]; -#ifdef WIN32_VSS +#if defined(WIN32_VSS) // capture state here, if client is backed up by multiple directors // and one enables vss and the other does not then enable_vss can change // between here and where its evaluated after the job completes. @@ -1310,7 +1314,7 @@ static int backup_cmd(JCR *jcr) generate_daemon_event(jcr, "JobStart"); -#ifdef WIN32_VSS +#if defined(WIN32_VSS) /* START VSS ON WIN 32 */ if (bDoVSS) { if (g_pVSSClient->InitializeForBackup()) { @@ -1408,7 +1412,7 @@ static int backup_cmd(JCR *jcr) } cleanup: -#ifdef WIN32_VSS +#if defined(WIN32_VSS) /* STOP VSS ON WIN 32 */ /* tell vss to close the backup session */ if (bDoVSS) { diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 7df988108c..302dd89567 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -83,7 +83,6 @@ static void do_status(void sendit(const char *msg, int len, void *sarg), void *a len = Mmsg(msg, " %sWUL,%sWMKD,%sWOP,%sGFAA,%sGFAW,%sGFAEA,%sGFAEW,%sSFAA,%sSFAW,%sBR,%sBW,%sSPSP,\n", p_wunlink?"":"!", p_wmkdir?"":"!", - p_wopen?"":"!", p_GetFileAttributesA?"":"!", p_GetFileAttributesW?"":"!", p_GetFileAttributesExA?"":"!", diff --git a/bacula/src/filed/win32/.cvsignore b/bacula/src/filed/win32/.cvsignore deleted file mode 100644 index f3c7a7c5da..0000000000 --- a/bacula/src/filed/win32/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/bacula/src/filed/win32/Makefile.in b/bacula/src/filed/win32/Makefile.in deleted file mode 100755 index 377227c4fc..0000000000 --- a/bacula/src/filed/win32/Makefile.in +++ /dev/null @@ -1,124 +0,0 @@ -# -# makefile to build Windows specific pieces of the Bacula File daemon -# -# Version $Id$ -# -CFLAGS=@CFLAGS@ -WCFLAGS=@WCFLAGS@ -CC = @CC@ -CXX = @CXX@ -RANLIB = @RANLIB@ -SHELL = /bin/sh - -# Program to install `make'. -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -# Program to install the man page. -INSTALL_DATA = @INSTALL_DATA@ -# Generic install program. -INSTALL = @INSTALL@ - -VERSION = @VERSION@ - - -# this dir -srcdir = . -# main dir -topdir = ../../.. -# this dir relative to top dir -thisdir = src/filed/win32 - -# Common prefix for machine-independent installed files. -prefix = @prefix@ -sysconfdir = @sysconfdir@ -sbindir = @sbindir@ -piddir = @piddir@ - -SRCS = shutdown.c - -OBJS = shutdown.o - -BACOBJS = winabout.o winevents.o winservice.o winstat.o wintray.o winmain.o - -all: winlib.a winres.res - -win32: winlib.a - -winlib.a: $(BACOBJS) winres.res - ar rcs $@ $(BACOBJS) - -winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico - windres $< -O coff -o $@ - -winmain.o: winmain.cpp winbacula.h - $(CC) -c $(WCFLAGS) $(CFLAGS) $< - -libmymapi32.a: mymapi32.def - dlltool --as=as -k --output-lib $@ --def $< - -Makefile: $(srcdir)/Makefile.in $(topdir)/config.status - cd $(topdir) \ - && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -clean: - rm -f *.exe *.o *.res *.a 1 2 3 - rm -f bin/smtp.exe bin/console.exe - rm -f bin/bacula-fd.exe bin/bsmtp.exe bin/testfind.exe - -distclean: clean - @rm -f Makefile - -devclean: clean - @rm -f Makefile - -install: - @mkdir -p $(DESTDIR)$(sbindir) $(DESTDIR)/tmp $(DESTDIR)$(sbindir)/../working - @echo "Installing system binary files ..." - @strip ../bacula-fd.exe - @strip ../../tools/bsmtp.exe - @strip ../../tools/testfind.exe - @strip ../../console/bconsole.exe - @cp -f ../bacula-fd.exe bin/ - @cp -f ../../tools/bsmtp.exe bin/ - @cp -f ../../tools/testfind.exe bin/ - @cp -f ../../console/bconsole.exe bin/ - @cp -f bin/* $(DESTDIR)$(sbindir) - @cp -f ../bacula-fd.conf $(DESTDIR)$(sysconfdir)/bacula-fd.conf.new - @cp -f ../../console/bconsole.conf $(DESTDIR)$(sysconfdir)/bconsole.conf.new - -# Make a Win32 binary release -binary-release: - @rm -rf wr - @mkdir -p wr - @mkdir -p wr/$(prefix) wr/$(sbindir) wr/$(sbindir)/../working wr/$(sysconfdir) wr/tmp - @echo "Copying system binary files ..." - @cp bin/* wr/$(sbindir) - @strip ../bacula-fd.exe - @strip ../../tools/bsmtp.exe - @strip ../../tools/testfind.exe - @strip ../../console/bconsole.exe - @echo "Copying executables ..." - @cp -f ../bacula-fd.exe wr/$(sbindir)/bacula-fd.exe - @cp -f ../../tools/bsmtp.exe wr/$(sbindir)/bsmtp.exe - @cp -f ../../tools/testfind.exe wr/$(sbindir)/testfind.exe - @cp -f ../../console/bconsole.exe wr/$(sbindir)/bconsole.exe - @echo "Copying bacula-fd.conf..." - @cp -f ../bacula-fd.conf wr/$(sysconfdir)/bacula-fd.conf.new - @cp -f ../../console/bconsole.conf wr/$(sysconfdir)/bconsole.conf.new -# the two dummy files are necessary to insure that WinZip -# actually creates the directories. - @echo "dummy" >wr/tmp/dummy.txt - @echo "dummy" >wr/$(sbindir)/../working/dummy.txt - @echo "Making tar file ..." - @tar cfz winbacula-${VERSION}.tar.gz -C wr bacula tmp - @mv -f winbacula-${VERSION}.tar.gz $(topdir)/.. - @rm -rf wr - @(cd $(topdir)/..; \ - echo "Tar file in: `pwd`/winbacula-${VERSION}.tar.gz") - -dummy: - -.c.o: - $(CC) -c $(WCFLAGS) $(CFLAGS) $< - -.cpp.o: - $(CXX) -c $(WCFLAGS) $(CFLAGS) $< diff --git a/bacula/src/filed/win32/Makefile.mingw b/bacula/src/filed/win32/Makefile.mingw deleted file mode 100644 index 4a3e36ff77..0000000000 --- a/bacula/src/filed/win32/Makefile.mingw +++ /dev/null @@ -1,125 +0,0 @@ -# -# makefile to build Windows specific pieces of the Bacula File daemon -# -# Version $Id$ -# -CFLAGS=-g -O2 -DHAVE_WIN32 -DHAVE_MINGW -WCFLAGS=-mwindows -I../../win32/compat -CC = gcc -CXX = g++ -RANLIB = /usr/bin/ranlib -SHELL = /bin/sh - -# Program to install `make'. -INSTALL_PROGRAM = ${INSTALL} -# Program to install the man page. -INSTALL_DATA = ${INSTALL} -m 644 -# Generic install program. -INSTALL = /usr/bin/install -c - -VERSION = 1.35.0 - - -# this dir -srcdir = . -# main dir -topdir = ../../.. -# this dir relative to top dir -thisdir = src/filed/win32 - -# Common prefix for machine-independent installed files. -prefix = -sysconfdir = /etc/bacula -sbindir = /sbin -piddir = /var/run - -SRCS = shutdown.c - -OBJS = shutdown.o - -BACOBJS = winabout.o winevents.o winservice.o winstat.o wintray.o winmain.o - -all: winlib.a winres.res - -win32: winlib.a - -winlib.a: $(BACOBJS) winres.res - ar rcs $@ $(BACOBJS) - -winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico - windres -DHAVE_MINGW $< -O coff -o $@ - -winmain.o: winmain.cpp winbacula.h - $(CC) -c $(WCFLAGS) $(CFLAGS) $< - -libmymapi32.a: mymapi32.def - dlltool --as=as -k --output-lib $@ --def $< - -Makefile: $(srcdir)/Makefile.in $(topdir)/config.status - cd $(topdir) \ - && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -clean: - rm -f *.exe *.o *.res *.a 1 2 3 - rm -f bin/smtp.exe bin/console.exe - rm -f bin/bacula-fd.exe bin/bsmtp.exe bin/testfind.exe - -distclean: clean - @rm -f Makefile - @rm -rf bin/CVS CVS - -devclean: clean - @rm -f Makefile - -install: - @mkdir -p $(DESTDIR)$(sbindir) $(DESTDIR)/tmp $(DESTDIR)$(sbindir)/../working - @echo "Installing system binary files ..." - @strip ../bacula-fd.exe - @strip ../../tools/bsmtp.exe - @strip ../../tools/testfind.exe - @strip ../../console/bconsole.exe - @cp -f ../bacula-fd.exe bin/ - @cp -f ../../tools/bsmtp.exe bin/ - @cp -f ../../tools/testfind.exe bin/ - @cp -f ../../console/bconsole.exe bin/ - @cp -f bin/* $(DESTDIR)$(sbindir) - @cp -f ../bacula-fd.conf $(DESTDIR)$(sysconfdir)/bacula-fd.conf.new - @cp -f ../../console/bconsole.conf $(DESTDIR)$(sysconfdir)/bconsole.conf.new - -# Make a Win32 binary release -binary-release: - @rm -rf wr - @mkdir -p wr - @mkdir -p wr/$(prefix) wr/$(sbindir) wr/$(sbindir)/../working wr/$(sysconfdir) wr/tmp - @echo "Copying system binary files ..." - @cp bin/* wr/$(sbindir) - @strip ../bacula-fd.exe - @strip ../../tools/bsmtp.exe - @strip ../../tools/testfind.exe - @strip ../../console/bconsole.exe - @echo "Copying executables ..." - @cp -f ../bacula-fd.exe wr/$(sbindir)/bacula-fd.exe - @cp -f ../../tools/bsmtp.exe wr/$(sbindir)/bsmtp.exe - @cp -f ../../tools/testfind.exe wr/$(sbindir)/testfind.exe - @cp -f ../../console/bconsole.exe wr/$(sbindir)/bconsole.exe - @echo "Copying bacula-fd.conf..." - @cp -f ../bacula-fd.conf wr/$(sysconfdir)/bacula-fd.conf.new - @cp -f ../../console/bconsole.conf wr/$(sysconfdir)/bconsole.conf.new -# the two dummy files are necessary to insure that WinZip -# actually creates the directories. - @echo "dummy" >wr/tmp/dummy.txt - @echo "dummy" >wr/$(sbindir)/../working/dummy.txt - @echo "Making tar file ..." - @tar cfz winbacula-${VERSION}.tar.gz -C wr bacula tmp - @mv -f winbacula-${VERSION}.tar.gz $(topdir)/.. - @rm -rf wr - @(cd $(topdir)/..; \ - echo "Tar file in: `pwd`/winbacula-${VERSION}.tar.gz") - -dummy: - -.c.o: - $(CC) -c $(WCFLAGS) $(CFLAGS) $< - -.cpp.o: - $(CXX) -c $(WCFLAGS) $(CFLAGS) $< diff --git a/bacula/src/filed/win32/bacula.bmp b/bacula/src/filed/win32/bacula.bmp deleted file mode 100644 index a31eb1636902fbe82492cf1bcc9424b196296912..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3126 zcmd6o!41MN3`NbI0XTAGf)2o)oiZAm!6(1^ib&KtPFvM#EjNvyznvnUujy*pCin;L z`+Q&Qh6pyl=L7xcSSw3+#U7a{C2WK5H7N1(-#tbpC*)g7x*!rg=@9{pUFI+a^jkg) zPL;HJ1tstbb|in{sG$Uc*|>%D1McMi+Ad6^&{{oz!WT*)SNfU0>RC?n7rfa;fX}|f zhdhxL@FRgIUysfJStVatHJ>Hea+epg44V9M!(hBCe^+?jI1Xq-`{Q>VrDrpxstQsN zul|%g8&n-7YQ9zi0jn?b^)?WA_yO5U@$dt(mEz%Z&xlvK=J^K5mW!e14=6nFeIt7e-mMG^>!P}Oo`Rqas4hADb?#lfFnd|d% diff --git a/bacula/src/filed/win32/bacula.ico b/bacula/src/filed/win32/bacula.ico deleted file mode 100644 index f6d50bf516caaa111e8598006ac9cac9ed166358..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmbtSJx;?g7=0#0jMx!kPBRonq~rhy^#Cln0$1qjjca*l;0hgCP&-tj5>)1WcI<{! zl`8S#=g%+SuPg(KUtMbmJ}!V;+IzAlA4!Ev?x$g`g>w#|_1-g(w9#vx2PWQS9d{|GMa9(zmM9Oifg9J{yF$_zg`k0-syWK-!{PKm;c%Cp!Q4?eoMXst}RfUL&g>>lC`cR F_ZNY8Y|;P# diff --git a/bacula/src/filed/win32/bacula.rc b/bacula/src/filed/win32/bacula.rc deleted file mode 100644 index 5849beb8e3..0000000000 --- a/bacula/src/filed/win32/bacula.rc +++ /dev/null @@ -1 +0,0 @@ -1 ICON "apcupsd.ico" diff --git a/bacula/src/filed/win32/error.ico b/bacula/src/filed/win32/error.ico deleted file mode 100644 index a8f85f120dbcc8483e9530af48554432945c2a91..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmc&yu?~VT5Pd}wMy-RZwJeSret?0`a%lXrPEI8Lf}!Bzr^i}8{7j(2xG zt_gskN2wJU_YBxj+!GbCCJN-F^DxH1S_@DF+_XHymJp<9}LB@7nDn`rxlQm{6{?* z^`}?Y;|VMuK+ypUOTS!8`@DJDqP-kVdsdO`Ip6nPo$Hu%7DU0k(JY!*4BwcFFV=Zv AHvj+t diff --git a/bacula/src/filed/win32/idle.ico b/bacula/src/filed/win32/idle.ico deleted file mode 100644 index ce5315f2507bed96c9f4a12d542d7189ef1a2471..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmc&yF%H5o47`*|9U%;?gmhs9^#dLHEQW}eWn!wt7Z@2kG9U#zX-TMBi3M@doqKlT zI#K{ZOQ{tY_YBxj+!GbCCJN-F^DxH1S_@Eg&dqQ9Nkt~$J0w<0PUr~96GW?nFRMyx zFTo#xwf5qDiKZ4_!u~RE8sX(jKRO>;$NqXJr4BMVAJ5#w*9Sv!>;>hL>uCjKBmYrP zTK(yh-iyZ*SU!NF0~VH^Tubx3dD^1A98G&xk?c9&@4GtJG3hLbf_bA})UO!+F%@4h CbY?XG diff --git a/bacula/src/filed/win32/mymapi32.def b/bacula/src/filed/win32/mymapi32.def deleted file mode 100644 index 42f0bfed84..0000000000 --- a/bacula/src/filed/win32/mymapi32.def +++ /dev/null @@ -1,151 +0,0 @@ -LIBRARY MAPI32.DLL -EXPORTS -MAPISendMail@20 -BuildDisplayTable@40 -CbOfEncoded@4 -CchOfEncoding@4 -ChangeIdleRoutine@28 -CloseIMsgSession@4 -CreateIProp@24 -CreateTable@36 -DeinitMapiUtil@0 -DeregisterIdleRoutine@4 -EnableIdleRoutine@8 -EncodeID@12 -FBadColumnSet@4 -FBadEntryList@4 -FBadProp@4 -FBadPropTag@4 -FBadRestriction@4 -FBadRglpNameID@8 -FBadRglpszA@8 -FBadRglpszW@8 -FBadRow@4 -FBadRowSet@4 -FBadSortOrderSet@4 -FBinFromHex@8 -FDecodeID@12 -FEqualNames@8 -FPropCompareProp@12 -FPropContainsProp@12 -FPropExists@8 -FreePadrlist@4 -FreeProws@4 -FtAdcFt@20 -FtAddFt@16 -FtDivFtBogus@20 -FtMulDw@12 -FtMulDwDw@8 -FtNegFt@8 -FtSubFt@16 -FtgRegisterIdleRoutine@20 -GetAttribIMsgOnIStg@12 -GetTnefStreamCodepage -GetTnefStreamCodepage@12 -HexFromBin@12 -HrAddColumns@16 -HrAddColumnsEx@20 -HrAllocAdviseSink@12 -HrComposeEID@28 -HrComposeMsgID@24 -HrDecomposeEID@28 -HrDecomposeMsgID@24 -HrDispatchNotifications@4 -HrEntryIDFromSz@12 -HrGetOneProp@12 -HrIStorageFromStream@16 -HrQueryAllRows@24 -HrSetOneProp@8 -HrSzFromEntryID@12 -HrThisThreadAdviseSink@8 -HrValidateIPMSubtree@20 -HrValidateParameters@8 -InstallFilterHook@4 -IsBadBoundedStringPtr@8 -LAUNCHWIZARD -LPropCompareProp@8 -LaunchWizard@20 -LpValFindProp@12 -MAPIAdminProfiles -MAPIAdminProfiles@8 -MAPIAllocateBuffer -MAPIAllocateBuffer@8 -MAPIAllocateMore -MAPIAllocateMore@12 -MAPIDeinitIdle@0 -MAPIFreeBuffer -MAPIFreeBuffer@4 -MAPIGetDefaultMalloc@0 -MAPIInitIdle@4 -MAPIInitialize -MAPIInitialize@4 -MAPILogonEx -MAPILogonEx@20 -MAPIOpenFormMgr -MAPIOpenFormMgr@8 -MAPIOpenLocalFormContainer -MAPIOpenLocalFormContainer@4 -MAPIUninitialize -MAPIUninitialize@0 -MNLS_CompareStringW@24 -MNLS_IsBadStringPtrW@8 -MNLS_MultiByteToWideChar@24 -MNLS_WideCharToMultiByte@32 -MNLS_lstrcmpW@8 -MNLS_lstrcpyW@8 -MNLS_lstrlenW@4 -MapStorageSCode@4 -OpenIMsgOnIStg@44 -OpenIMsgSession@12 -OpenStreamOnFile -OpenStreamOnFile@24 -OpenTnefStream -OpenTnefStream@28 -OpenTnefStreamEx -OpenTnefStreamEx@32 -PRProviderInit -PpropFindProp@12 -PropCopyMore@16 -RTFSync -RTFSync@12 -ScBinFromHexBounded@12 -ScCopyNotifications@16 -ScCopyProps@16 -ScCountNotifications@12 -ScCountProps@12 -ScCreateConversationIndex@16 -ScDupPropset@16 -ScGenerateMuid@4 -ScInitMapiUtil@4 -ScLocalPathFromUNC@12 -ScMAPIXFromCMC -ScMAPIXFromSMAPI -ScRelocNotifications@20 -ScRelocProps@20 -ScSplEntry -ScUNCFromLocalPath@12 -SetAttribIMsgOnIStg@16 -SwapPlong@8 -SwapPword@8 -SzFindCh@8 -SzFindLastCh@8 -SzFindSz@8 -UFromSz@4 -UNKOBJ_COFree@8 -UNKOBJ_Free@8 -UNKOBJ_FreeRows@8 -UNKOBJ_ScAllocate@12 -UNKOBJ_ScAllocateMore@16 -UNKOBJ_ScCOAllocate@12 -UNKOBJ_ScCOReallocate@12 -UNKOBJ_ScSzFromIdsAlloc@20 -UlAddRef@4 -UlFromSzHex@4 -UlPropSize@4 -UlRelease@4 -WrapCompressedRTFStream -WrapCompressedRTFStream@12 -WrapProgress@20 -WrapStoreEntryID@24 -__CPPValidateParameters@8 -__ValidateParameters@8 diff --git a/bacula/src/filed/win32/popup.c b/bacula/src/filed/win32/popup.c deleted file mode 100644 index e3e3420b73..0000000000 --- a/bacula/src/filed/win32/popup.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Dumb Windows program to put up a message box - * containing the command line. Any leading and - * trailing quotes are stripped. - * - * Kern E. Sibbald - * July MM - */ -#include "windows.h" - - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - PSTR szCmdLine, int iCmdShow) -{ - int len = strlen(szCmdLine); - char *msg, *wordPtr; - - // Funny things happen with the command line if the - // execution comes from c:/Program Files/apcupsd/apcupsd.exe - // We get a command line like: Files/apcupsd/apcupsd.exe" options - // I.e. someone stops scanning command line on a space, not - // realizing that the filename is quoted!!!!!!!!!! - // So if first character is not a double quote and - // the last character before first space is a double - // quote, we throw away the junk. - wordPtr = szCmdLine; - while (*wordPtr && *wordPtr != ' ') - wordPtr++; - if (wordPtr > szCmdLine) // backup to char before space - wordPtr--; - // if first character is not a quote and last is, junk it - if (*szCmdLine != '"' && *wordPtr == '"') { - wordPtr++; - while (*wordPtr && *wordPtr == ' ') - wordPtr++; /* strip leading spaces */ - szCmdLine = wordPtr; - len = strlen(szCmdLine); - } - - msg = szCmdLine; - if (*szCmdLine == '"' && len > 0 && szCmdLine[len-1] == '"') { - msg = szCmdLine + 1; - szCmdLine[len-1] = 0; - } - MessageBox(NULL, msg, "Apcupsd message", MB_OK); - return 0; -} diff --git a/bacula/src/filed/win32/running.ico b/bacula/src/filed/win32/running.ico deleted file mode 100644 index 32dc42cd3c159fea18072b3b5baba6999d87c692..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmc&yu?~VT5Pd}wMy-RZwJeSret?0`a%lXrPEI8Lf}!Bzr^i}8{7j(2xG zt_gskN2wJU_YBxj+!GbCCJN-F^DxH1S_@EwoA3KgMJC`oBvwjJ=m^OxM5}`@t4eDx z!5@IN_TqhsrWRg8f0;Lp@baY}oe!hqe7%!W2btWDckbcqgP}O~f^y0Av;wk`|EMRU z{`Bg4Jb~o{C^}$a>6dG1pEpliw3nl4&nl8V=li~^a~+e;f+(0bnnm-9;Tu!&1=o0F AHvj+t diff --git a/bacula/src/filed/win32/saving.ico b/bacula/src/filed/win32/saving.ico deleted file mode 100644 index f6d50bf516caaa111e8598006ac9cac9ed166358..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmbtSJx;?g7=0#0jMx!kPBRonq~rhy^#Cln0$1qjjca*l;0hgCP&-tj5>)1WcI<{! zl`8S#=g%+SuPg(KUtMbmJ}!V;+IzAlA4!Ev?x$g`g>w#|_1-g(w9#vx2PWQS9d{|GMa9(zmM9Oifg9J{yF$_zg`k0-syWK-!{PKm;c%Cp!Q4?eoMXst}RfUL&g>>lC`cR F_ZNY8Y|;P# diff --git a/bacula/src/filed/win32/warn.ico b/bacula/src/filed/win32/warn.ico deleted file mode 100644 index 26e1d398bb446fb55d02635a2afa4dc8489e0587..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 766 zcmc&yu?~VT5Pd}wMy-RZwJeSret?0`a%lXrPEI8Lf}!Bzr^i}8{7j(2xG zt_gskN2wJU_YBxj+!GbCCJN-F^DxH1S_@EwbMuWqsmKI;hr~+B2^}GMgJ^Z|WmReI zCHMod)?U0X(bU3A=r8l85njIZqw`^OoUeCM>L8Q*@yo9M@*nkN z)Sq5mk0-Ev07VBZEd6pV?epeoi}rFf?O8>#=X~FHb*^L5Sr7&DMzd&MF??exz5s&v BWi|i+ diff --git a/bacula/src/filed/win32/winabout.cpp b/bacula/src/filed/win32/winabout.cpp deleted file mode 100755 index 5fbccae3a9..0000000000 --- a/bacula/src/filed/win32/winabout.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (C) 2000-2004 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. - - This file is patterned after the VNC Win32 code by ATT - - Kern E. Sibbald, 2000 -*/ - -#include "bacula.h" -#include "winbacula.h" -#include "winabout.h" -#include "winres.h" - -bacAbout::bacAbout() -{ - visible = false; -} - -bacAbout::~bacAbout() { }; - -void bacAbout::Show(BOOL show) -{ - if (show && !visible) { - DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_ABOUT), NULL, - (DLGPROC)DialogProc, (LONG)this); - } -} - - -BOOL CALLBACK -bacAbout::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) -{ - /* Get the dialog class pointer from USERDATA */ - bacAbout *_this; - - switch (uMsg) { - case WM_INITDIALOG: - /* save the dialog class pointer */ - SetWindowLong(hwnd, GWL_USERDATA, lParam); - _this = (bacAbout *)lParam; - - /* Show the dialog */ - SetForegroundWindow(hwnd); - _this->visible = true; - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - case IDOK: - EndDialog(hwnd, TRUE); - _this = (bacAbout *)GetWindowLong(hwnd, GWL_USERDATA); - _this->visible = false; - return TRUE; - } - break; - - case WM_DESTROY: - EndDialog(hwnd, FALSE); - _this = (bacAbout *)GetWindowLong(hwnd, GWL_USERDATA); - _this->visible = false; - return TRUE; - } - return 0; -} diff --git a/bacula/src/filed/win32/winabout.h b/bacula/src/filed/win32/winabout.h deleted file mode 100755 index 46a6e94e3d..0000000000 --- a/bacula/src/filed/win32/winabout.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (C) 2000-2004 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. - - This file was inspired by the VNC Win32 code by ATT - - Kern E. Sibbald, 2000 -*/ - - -/* Object implementing the About dialog for Bacula */ - -class bacAbout; - -#ifndef _WINABOUT_H_ -#define _WINABOUT_H_ 1 - -/* Define the bacAbout class */ -class bacAbout -{ -public: - bacAbout(); - ~bacAbout(); - - /* The dialog box window proc */ - static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - - void Show(BOOL show); - - /* Object local storage */ - bool visible; -}; - -#endif diff --git a/bacula/src/filed/win32/winbacula.h b/bacula/src/filed/win32/winbacula.h deleted file mode 100755 index 088205be33..0000000000 --- a/bacula/src/filed/win32/winbacula.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. -// -// This file was part of the VNC system. -// -// The VNC system is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// If the source code for the VNC system is not available from the place -// whence you received this file, check http://www.uk.research.att.com/vnc or contact -// the authors on vnc@uk.research.att.com for information on obtaining it. -// -// This file has been adapted to the Win32 version of Bacula -// by Kern E. Sibbald. Many thanks to ATT and James Weatherall, -// the original author, for providing an excellent template. -// -// Copyright (2000) Kern E. Sibbald -// - - -// Application specific messages - -// Message used for system tray notifications -#define WM_TRAYNOTIFY WM_USER+1 - -// Messages used for the server object to notify windows of things -#define WM_SRV_CLIENT_CONNECT WM_USER+2 -#define WM_SRV_CLIENT_AUTHENTICATED WM_USER+3 -#define WM_SRV_CLIENT_DISCONNECT WM_USER+4 - -// Export the application details -extern HINSTANCE hAppInstance; -extern const char *szAppName; -extern DWORD mainthreadId; - -// Main Bacula server routine -extern int BaculaAppMain(); - -extern void LogErrorMsg(char *msg); - -// Standard command-line flag definitions -const char BaculaRunService[] = "/service"; -const char BaculaRunServiceHelper[] = "/servicehelper"; -const char BaculaRunAsUserApp[] = "/run"; - -const char BaculaInstallService[] = "/install"; -const char BaculaRemoveService[] = "/remove"; - -const char BaculaShowAbout[] = "/about"; -const char BaculaShowStatus[] = "/status"; -const char BaculaShowEvents[] = "/events"; -const char BaculaKillRunningCopy[] = "/kill"; - -const char BaculaShowHelp[] = "/help"; - -// Usage string -const char BaculaUsageText[] = "Bacula [/run] [/kill] [/install] [/remove] [/about] [/status] [/events]\n"; - -void LogErrorMsg(char *msg, char *fname, int lineno); -#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/filed/win32/winevents.cpp b/bacula/src/filed/win32/winevents.cpp deleted file mode 100755 index 50edd0a5f5..0000000000 --- a/bacula/src/filed/win32/winevents.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (C) 2000-2003 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. - - This file is patterned after the VNC Win32 code by ATT - - Copyright (2000) Kern E. Sibbald -*/ - - -/* Code for the Events dialogue */ - -#include "bacula.h" -#include "winbacula.h" -#include "winevents.h" -#include "winres.h" - -extern "C" void FillEventsBox(HWND hwnd, int id_list); - -bacEvents::bacEvents() -{ - visible = FALSE; -} - -bacEvents::~bacEvents() -{ -} - -/* Show the dialogue box */ -void -bacEvents::Show(BOOL show) -{ - if (show && !visible) { - DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_EVENTS), NULL, - (DLGPROC)DialogProc, (LONG)this); - } -} - - -BOOL CALLBACK -bacEvents::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - /* The dialog-box this pointer is in USERDATA */ - bacEvents *_this = (bacEvents *)GetWindowLong(hwnd, GWL_USERDATA); - - switch (uMsg) { - case WM_INITDIALOG: - /* Retrieve the Dialog box parameter */ - SetWindowLong(hwnd, GWL_USERDATA, lParam); - _this = (bacEvents *)lParam; - - /* Show the dialog */ - SetForegroundWindow(hwnd); - _this->visible = TRUE; - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - case IDOK: - EndDialog(hwnd, TRUE); - _this->visible = FALSE; - return TRUE; - } - break; - - case WM_DESTROY: - EndDialog(hwnd, FALSE); - _this->visible = FALSE; - return TRUE; - } - return 0; -} diff --git a/bacula/src/filed/win32/winevents.h b/bacula/src/filed/win32/winevents.h deleted file mode 100755 index a28d66e124..0000000000 --- a/bacula/src/filed/win32/winevents.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Object implementing the Events dialog for Bacula */ -/* - Copyright (C) 2000-2003 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. - - */ - - -class bacEvents; - -#ifndef _win_bacEVENTS -#define _win_bacEVENTS 1 - -/* Define the bacEvents class */ -class bacEvents -{ -public: - bacEvents(); - ~bacEvents(); - - /* The dialog box window proc */ - static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - - void Show(BOOL show); - - /* Object local storage */ - BOOL visible; -}; - -#endif diff --git a/bacula/src/filed/win32/winmain.cpp b/bacula/src/filed/win32/winmain.cpp deleted file mode 100755 index 4a662a56e7..0000000000 --- a/bacula/src/filed/win32/winmain.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* - Copyright (C) 2000-2006 Kern Sibbald - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as amended with additional clauses defined in the - file LICENSE in the main source directory. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. - - This file is patterned after the VNC Win32 code by ATT - -*/ - -#include -#include - -#include "bacula.h" -#include "winbacula.h" -#include "wintray.h" -#include "winservice.h" -#include -#include - -extern int BaculaMain(int argc, char *argv[]); -extern void terminate_filed(int sig); -extern DWORD g_error; -extern BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint); -extern void d_msg(const char *, int, int, const char *, ...); - -/* Globals */ -HINSTANCE hAppInstance; -const char *szAppName = "Bacula"; -DWORD mainthreadId; -bool silent = false; - -/* Imported variables */ -extern DWORD g_servicethread; -extern DWORD g_platform_id; - -#define MAX_COMMAND_ARGS 100 -static char *command_args[MAX_COMMAND_ARGS] = {"bacula-fd", NULL}; -static int num_command_args = 1; -static pid_t main_pid; -static pthread_t main_tid; - -/* - * WinMain parses the command line and either calls the main App - * routine or, under NT, the main service routine. - */ -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - PSTR CmdLine, int iCmdShow) -{ - char *szCmdLine = CmdLine; - char *wordPtr, *tempPtr; - int i, quote; - - /* Save the application instance and main thread id */ - hAppInstance = hInstance; - mainthreadId = GetCurrentThreadId(); - - main_pid = getpid(); - main_tid = pthread_self(); - - /* - * Funny things happen with the command line if the - * execution comes from c:/Program Files/bacula/bacula.exe - * We get a command line like: Files/bacula/bacula.exe" options - * I.e. someone stops scanning command line on a space, not - * realizing that the filename is quoted!!!!!!!!!! - * So if first character is not a double quote and - * the last character before first space is a double - * quote, we throw away the junk. - */ - - wordPtr = szCmdLine; - while (*wordPtr && *wordPtr != ' ') - wordPtr++; - if (wordPtr > szCmdLine) /* backup to char before space */ - wordPtr--; - /* if first character is not a quote and last is, junk it */ - if (*szCmdLine != '"' && *wordPtr == '"') { - szCmdLine = wordPtr + 1; - } -// MessageBox(NULL, szCmdLine, "Cmdline", MB_OK); - - /* Build Unix style argc *argv[] */ - - /* Don't NULL command_args[0] !!! */ - for (i=1;i -#include -#include "winres.h" -#include "../../version.h" - -/* NB: Internationalization of this file will require some work... */ -#define N_(s) s - -///////////////////////////////////////////////////////////////////////////// -// -// Icons -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_BACULA ICON DISCARDABLE "bacula.ico" -IDI_IDLE ICON DISCARDABLE "idle.ico" -IDI_RUNNING ICON DISCARDABLE "running.ico" -IDI_JOB_ERROR ICON DISCARDABLE "error.ico" -IDI_JOB_WARNING ICON DISCARDABLE "warn.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDR_TRAYMENU MENU DISCARDABLE -BEGIN - POPUP "tray" - BEGIN - MENUITEM N_("&Status"), ID_STATUS - MENUITEM N_("&Events"), ID_EVENTS -#ifdef properties_implemented - MENUITEM N_("&Properties"), ID_PROPERTIES -#endif - MENUITEM SEPARATOR - MENUITEM N_("&About Bacula"), ID_ABOUT - MENUITEM SEPARATOR - MENUITEM N_("&Close Bacula"), ID_CLOSE - END -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,0,0 - PRODUCTVERSION 1,1,0,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0 // -#endif - FILEOS VOS_NT_WINDOWS32 - FILETYPE VFT_APP - FILESUBTYPE 0 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E0" // Lang=US English, CharSet=Windows Multiligual - BEGIN - VALUE "Comments", "by Kern Sibbald\0" - VALUE "CompanyName", " \0" - VALUE "FileDescription", "Bacula File daemon for Win32\0" - VALUE "FileVersion", VERSION "\0" - VALUE "InternalName", "Bacula\0" - VALUE "LegalCopyright", "Copyright Kern Sibbald, 1999-2006\0" - VALUE "LegalTrademarks", "Licensed under GNU GPL 2.0\0" - VALUE "OriginalFilename", "filed.exe\0" - VALUE "PrivateBuild", "\0" - VALUE "ProductName", "Bacula - Win32 Version\0" - VALUE "ProductVersion", VERSION - VALUE "SpecialBuild", "\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 // US English, Multilingual - END -END - -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// - -IDB_BACULABMP BITMAP DISCARDABLE "bacula.bmp" - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE DISCARDABLE -BEGIN - IDI_BACULA "Bacula" -END - -///////////////////////////////////////////////////////////////////////////// -// -// Properties Dialog -// -#ifdef properties_implemented - -IDD_PROPERTIES DIALOG DISCARDABLE 0, 0, 221, 204 -STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | - WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Bacula Properties" -FONT 8, "MS Sans Serif" -BEGIN - PUSHBUTTON N_("&Cancel"),IDCANCEL,165,25,51,15 - DEFPUSHBUTTON N_("&OK"),IDOK,165,5,51,15 - LTEXT "No Properites yet",IDC_NONYET_LABEL,19,30,56,15, - SS_CENTERIMAGE -END -#endif - -///////////////////////////////////////////////////////////////////////////// -// -// About Dialog -// - -IDD_ABOUT DIALOG DISCARDABLE 0, 0, 250, 145 -STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "About Bacula" -FONT 8, "MS Sans Serif" -BEGIN - DEFPUSHBUTTON "OK",IDOK,190,120,50,15 -// CONTROL "\3", IDC_BACULABMP,"Static",SS_ICON | SS_CENTERIMAGE | -// SS_SUNKEN,7,5,73,65 -#ifndef HAVE_MINGW - CONTROL IDB_BACULABMP,IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,32,32 -#endif - - LTEXT N_(" by Kern Sibbald"),IDC_NAME,134,38,78,10 - LTEXT N_("For more information, see:"),-1,115,60,100,10 - LTEXT " www.bacula.org",IDC_WWW,115,70,100,10 -// LTEXT " ",-1,69,81,100,10 -// LTEXT " ",-1,90,70,100,10 - LTEXT "Copyright (C) 1999-2006, Kern Sibbald",IDC_COPYRIGHT,7,120,175,10 - LTEXT N_("Licensed under GNU GPL 2.0."),IDC_TRADEMARK,7,130,175,10 - RTEXT N_("Build Date:"),-1,108,24,42,8 - RTEXT N_("Bacula Version:"),-1,100,9,50,8 - LTEXT VERSION,IDC_VERSION,159,10,65,8 - LTEXT BDATE,-1,159,24,65,10 - -END - -///////////////////////////////////////////////////////////////////////////// -// -// Status Dialog -// - -IDD_STATUS DIALOG DISCARDABLE 0, 0, 411, 244 -STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | - WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION N_("Bacula Status") -FONT 8, "Courier New" -BEGIN - DEFPUSHBUTTON "&OK",IDOK,355,5,51,15 - LISTBOX IDC_LIST, 2, 2, 350, 240, WS_VSCROLL | WS_HSCROLL | WS_BORDER -END - -///////////////////////////////////////////////////////////////////////////// -// -// Events Dialog -// - -IDD_EVENTS DIALOG DISCARDABLE 0, 0, 411, 204 -STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | - WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION N_("Bacula Events") -FONT 8, "Courier New" -BEGIN - DEFPUSHBUTTON "&OK",IDOK,355,5,51,15 - LISTBOX IDC_LIST, 2, 2, 350, 200, WS_VSCROLL | WS_HSCROLL | WS_BORDER -END diff --git a/bacula/src/filed/win32/winservice.cpp b/bacula/src/filed/win32/winservice.cpp deleted file mode 100755 index 7fc85b2e7d..0000000000 --- a/bacula/src/filed/win32/winservice.cpp +++ /dev/null @@ -1,764 +0,0 @@ -// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. -// -// This file was part of the VNC system. -// -// The VNC system is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// If the source code for the VNC system is not available from the place -// whence you received this file, check http://www.uk.research.att.com/vnc or contact -// the authors on vnc@uk.research.att.com for information on obtaining it. -// -// This file has been adapted to the Win32 version of Bacula -// by Kern E. Sibbald. Many thanks to ATT and James Weatherall, -// the original author, for providing an excellent template. -// -// Copyright (C) 2000-2006 Kern E. Sibbald -// - - -// winService - -// Implementation of service-oriented functionality of Bacula -// I.e. command line options that contact a running version of -// Bacula and ask it to do something (show about, show status, -// show events, ...) - - -#include "bacula.h" -#include "winbacula.h" -#include "winservice.h" -#include "wintray.h" - -void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, - LPSTR lpDesc); - -// OS-SPECIFIC ROUTINES - -// Create an instance of the bacService class to cause the static fields to be -// initialised properly - -bacService init; - -extern DWORD g_platform_id; -extern bool silent; - -bacService::bacService() -{ - OSVERSIONINFO osversioninfo; - osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo); - - // Get the current OS version - if (!GetVersionEx(&osversioninfo)) { - g_platform_id = 0; - } else { - g_platform_id = osversioninfo.dwPlatformId; - } -} - - -// IsWin95 - returns a BOOL indicating whether the current OS is Win95 -BOOL -bacService::IsWin95() -{ - return (g_platform_id == VER_PLATFORM_WIN32_WINDOWS); -} - -// IsWinNT - returns a bool indicating whether the current OS is WinNT -BOOL -bacService::IsWinNT() -{ - return (g_platform_id == VER_PLATFORM_WIN32_NT); -} - -// Internal routine to find the Bacula menu class window and -// post a message to it! - -BOOL -PostToBacula(UINT message, WPARAM wParam, LPARAM lParam) -{ - // Locate the hidden Bacula menu window - HWND hservwnd = FindWindow(MENU_CLASS_NAME, NULL); - if (hservwnd == NULL) { - return FALSE; - } - - // Post the message to Bacula - PostMessage(hservwnd, message, wParam, lParam); - return TRUE; -} - - -// Static routine to show the Properties dialog for a currently-running -// copy of Bacula, (usually a servicified version.) - -BOOL -bacService::ShowProperties() -{ - return TRUE; -} - -// Static routine to show the Default Properties dialog for a currently-running -// copy of Bacula, (usually a servicified version.) - -BOOL -bacService::ShowDefaultProperties() -{ - return TRUE; -} - -// Static routine to show the About dialog for a currently-running -// copy of Bacula, (usually a servicified version.) - -BOOL -bacService::ShowAboutBox() -{ - // Post to the Bacula menu window - if (!PostToBacula(MENU_ABOUTBOX_SHOW, 0, 0)) { - MessageBox(NULL, _("No existing instance of Bacula could be contacted"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return FALSE; - } - return TRUE; -} - -// Static routine to show the Status dialog for a currently-running -// copy of Bacula, (usually a servicified version.) - -BOOL -bacService::ShowStatus() -{ - // Post to the Bacula menu window - if (!PostToBacula(MENU_STATUS_SHOW, 0, 0)) { - MessageBox(NULL, _("No existing instance of Bacula could be contacted"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return FALSE; - } - return TRUE; -} - -// SERVICE-MODE ROUTINES - -// Service-mode defines: - -// Executable name -#define BAC_APPNAME "bacula" - -// Internal service name -#define BAC_SERVICENAME "Bacula" - -// Displayed service name -#define BAC_SERVICEDISPLAYNAME "Bacula File Server" - -// List other required serves -#define BAC_DEPENDENCIES __TEXT("tcpip\0afd\0+File System\0") - - -// Internal service state -SERVICE_STATUS g_srvstatus; // current status of the service -SERVICE_STATUS_HANDLE g_hstatus; -DWORD g_error = 0; -DWORD g_servicethread = 0; -char* g_errortext[256]; - - -// Forward defines of internal service functions -void WINAPI ServiceMain(DWORD argc, char **argv); -DWORD WINAPI ServiceWorkThread(LPVOID lpwThreadParam); -void ServiceStop(); -void WINAPI ServiceCtrl(DWORD ctrlcode); -bool WINAPI CtrlHandler (DWORD ctrltype); -BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint); - -// ROUTINE TO QUERY WHETHER THIS PROCESS IS RUNNING AS A SERVICE OR NOT - -BOOL g_servicemode = FALSE; - -BOOL -bacService::RunningAsService() -{ - return g_servicemode; -} - -BOOL -bacService::KillRunningCopy() -{ - while (PostToBacula(WM_CLOSE, 0, 0)) - { } - return TRUE; -} - -// SERVICE MAIN ROUTINE -int -bacService::BaculaServiceMain() -{ - // Mark that we are a service - g_servicemode = TRUE; - - // How to run as a service depends upon the OS being used - switch (g_platform_id) { - - // Windows 95/98/Me - case VER_PLATFORM_WIN32_WINDOWS: - { - // Obtain a handle to the kernel library - HINSTANCE kerneldll = LoadLibrary("KERNEL32.DLL"); - if (kerneldll == NULL) { - MessageBox(NULL, _("KERNEL32.DLL not found: Bacula service not started"), - "Bacula Service", MB_OK); - break; - } - - // And find the RegisterServiceProcess function - DWORD (WINAPI *RegisterService)(DWORD, DWORD); - RegisterService = (DWORD (WINAPI *)(DWORD, DWORD)) - GetProcAddress(kerneldll, "RegisterServiceProcess"); - if (RegisterService == NULL) { - MessageBox(NULL, _("Registry service not found: Bacula service not started"), - "Bacula Service", MB_OK); - log_error_message(_("Registry service not found")); - break; - } - - // Register this process with the OS as a service! - RegisterService(0, 1); - - // Run the main program as a service - BaculaAppMain(); - - // Then remove the service from the system service table - RegisterService(0, 0); - - // Free the kernel library - FreeLibrary(kerneldll); - break; - } - - - // Windows NT, Win2K, WinXP - case VER_PLATFORM_WIN32_NT: - { - // Create a service entry table - SERVICE_TABLE_ENTRY dispatchTable[] = { - {BAC_SERVICENAME, (LPSERVICE_MAIN_FUNCTION)ServiceMain}, - {NULL, NULL} - }; - - // Call the service control dispatcher with our entry table - if (!StartServiceCtrlDispatcher(dispatchTable)) { - log_error_message(_("StartServiceCtrlDispatcher failed.")); - } - break; - } /* end case */ - } /* end switch */ - return 0; -} - -// SERVICE MAIN ROUTINE - NT ONLY !!! -// NT/Win2K/WinXP ONLY !!! -void WINAPI ServiceMain(DWORD argc, char **argv) -{ - DWORD dwThreadID; - - // Register the service control handler - g_hstatus = RegisterServiceCtrlHandler(BAC_SERVICENAME, ServiceCtrl); - - if (g_hstatus == 0) { - log_error_message(_("RegisterServiceCtlHandler failed")); - MessageBox(NULL, _("Contact Register Service Handler failure"), - "Bacula service", MB_OK); - return; - } - - // Set up some standard service state values - g_srvstatus.dwServiceType = SERVICE_WIN32 | SERVICE_INTERACTIVE_PROCESS; - g_srvstatus.dwServiceSpecificExitCode = 0; - - // Give this status to the SCM - if (!ReportStatus( - SERVICE_START_PENDING, // Service state - NO_ERROR, // Exit code type - 45000)) { // Hint as to how long Bacula should have hung before you assume error - - ReportStatus(SERVICE_STOPPED, g_error, 0); - log_error_message(_("ReportStatus STOPPED failed 1")); - return; - } - - // Now start the service for real - (void)CreateThread(NULL, 0, ServiceWorkThread, NULL, 0, &dwThreadID); - return; -} - -// SERVICE START ROUTINE - thread that calls BaculaAppMain -// NT ONLY !!!! -DWORD WINAPI ServiceWorkThread(LPVOID lpwThreadParam) -{ - - // Save the current thread identifier - g_servicethread = GetCurrentThreadId(); - - // report the status to the service control manager. - // - if (!ReportStatus( - SERVICE_RUNNING, // service state - NO_ERROR, // exit code - 0)) { // wait hint - MessageBox(NULL, _("Report Service failure"), "Bacula Service", MB_OK); - log_error_message("ReportStatus RUNNING failed"); - return 0; - } - - /* Call Bacula main code */ - BaculaAppMain(); - - /* Mark that we're no longer running */ - g_servicethread = 0; - - /* Tell the service manager that we've stopped */ - ReportStatus(SERVICE_STOPPED, g_error, 0); - return 0; -} - - -// SERVICE STOP ROUTINE - post a quit message to the relevant thread -void ServiceStop() -{ - // Post a quit message to the main service thread - if (g_servicethread != 0) { - PostThreadMessage(g_servicethread, WM_QUIT, 0, 0); - } -} - -// SERVICE INSTALL ROUTINE -int -bacService::InstallService() -{ - const int pathlength = 2048; - char path[pathlength]; - char servicecmd[pathlength]; - int len; - - // Get the filename of this executable - if (GetModuleFileName(NULL, path, pathlength-(strlen(BaculaRunService)+2)) == 0) { - MessageBox(NULL, _("Unable to install Bacula service"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - // Append the service-start flag to the end of the path: - if ((int)strlen(path) + 20 + (int)strlen(BaculaRunService) < pathlength) { - sprintf(servicecmd, "\"%s\" %s -c \"%s\"", path, BaculaRunService, path); - len = strlen(servicecmd) - 1; - for ( ; len > 0; len--) { - if (servicecmd[len] == '\\') { - servicecmd[len] = 0; - break; - } - servicecmd[len] = 0; - } - strcat(servicecmd, "\\bacula-fd.conf"); - - } else { - log_error_message(_("Service command length too long")); - MessageBox(NULL, _("Service command length too long. Service not registered."), - szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - // How to add the Bacula service depends upon the OS - switch (g_platform_id) { - - // Windows 95/98/Me - case VER_PLATFORM_WIN32_WINDOWS: - // Locate the RunService registry entry - HKEY runservices; - if (RegCreateKey(HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices", - &runservices) != ERROR_SUCCESS) { - log_error_message(_("Cannot write System Registry")); - MessageBox(NULL, _("The System Registry could not be updated - the Bacula service was not installed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - break; - } - - // Attempt to add a Bacula key - if (RegSetValueEx(runservices, szAppName, 0, REG_SZ, (unsigned char *)servicecmd, strlen(servicecmd)+1) != ERROR_SUCCESS) { - RegCloseKey(runservices); - log_error_message(_("Cannot add Bacula key to System Registry")); - MessageBox(NULL, _("The Bacula service could not be installed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - break; - } - - RegCloseKey(runservices); - - // We have successfully installed the service! - if (!silent) { - MessageBox(NULL, - _("The Bacula File service was successfully installed.\n" - "The service may be started by double clicking on the\n" - "Bacula \"Start\" icon and will be automatically\n" - "be run the next time this machine is rebooted. "), - szAppName, - MB_ICONINFORMATION | MB_OK); - } - break; - - // Windows NT, Win2K, WinXP - case VER_PLATFORM_WIN32_NT: - SC_HANDLE hservice; - SC_HANDLE hsrvmanager; - - // Open the default, local Service Control Manager database - hsrvmanager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if (hsrvmanager == NULL) { - log_error_message("OpenSCManager failed"); - MessageBox(NULL, - _("The Service Control Manager could not be contacted - the Bacula service was not installed"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - break; - } - - // Create an entry for the Bacula service - hservice = CreateService( - hsrvmanager, // SCManager database - BAC_SERVICENAME, // name of service - BAC_SERVICEDISPLAYNAME, // name to display - SERVICE_ALL_ACCESS, // desired access - SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, - // service type - SERVICE_AUTO_START, // start type - SERVICE_ERROR_NORMAL, // error control type - servicecmd, // service's binary - NULL, // no load ordering group - NULL, // no tag identifier - BAC_DEPENDENCIES, // dependencies - NULL, // LocalSystem account - NULL); // no password - if (hservice == NULL) { - CloseServiceHandle(hsrvmanager); - log_error_message("CreateService failed"); - MessageBox(NULL, - _("The Bacula service could not be installed"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - break; - } - - set_service_description(hsrvmanager,hservice, -_("Provides file backup and restore services. Bacula -- the network backup solution.")); - - CloseServiceHandle(hsrvmanager); - CloseServiceHandle(hservice); - - // Everything went fine - if (!silent) { - MessageBox(NULL, - _("The Bacula File service was successfully installed.\n" - "The service may be started from the Control Panel and will\n" - "automatically be run the next time this machine is rebooted."), - szAppName, - MB_ICONINFORMATION | MB_OK); - } - break; - default: - log_error_message("Unknown Windows System version"); - MessageBox(NULL, - _("Unknown Windows operating system.\n" - "Cannot install Bacula service.\n"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - break; - }; - - return 0; -} - - -// SERVICE REMOVE ROUTINE -int -bacService::RemoveService() -{ - // How to remove the Bacula service depends upon the OS - switch (g_platform_id) { - - // Windows 95/98/Me - case VER_PLATFORM_WIN32_WINDOWS: - // Locate the RunService registry entry - HKEY runservices; - if (RegOpenKey(HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices", - &runservices) != ERROR_SUCCESS) { - MessageBox(NULL, - _("Could not find registry entry.\nService probably not registerd - the Bacula service was not removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } else { - // Attempt to delete the Bacula key - if (RegDeleteValue(runservices, szAppName) != ERROR_SUCCESS) { - RegCloseKey(runservices); - MessageBox(NULL, _("Could not delete Registry key.\nThe Bacula service could not be removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - RegCloseKey(runservices); - break; - } - - // Try to kill any running copy of Bacula - if (!KillRunningCopy()) { - MessageBox(NULL, - _("Bacula could not be contacted, probably not running"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - break; - } - - // We have successfully removed the service! - if (!silent) { - MessageBox(NULL, _("The Bacula service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); - } - break; - - // Windows NT, Win2K, WinXP - case VER_PLATFORM_WIN32_NT: - SC_HANDLE hservice; - SC_HANDLE hsrvmanager; - - // Open the SCM - hsrvmanager = OpenSCManager( - NULL, // machine (NULL == local) - NULL, // database (NULL == default) - SC_MANAGER_ALL_ACCESS // access required - ); - if (hsrvmanager) { - hservice = OpenService(hsrvmanager, BAC_SERVICENAME, SERVICE_ALL_ACCESS); - if (hservice != NULL) { - SERVICE_STATUS status; - - // Try to stop the Bacula service - if (ControlService(hservice, SERVICE_CONTROL_STOP, &status)) { - while(QueryServiceStatus(hservice, &status)) { - if (status.dwCurrentState == SERVICE_STOP_PENDING) { - Sleep(1000); - } else { - break; - } - } - - if (status.dwCurrentState != SERVICE_STOPPED) { - MessageBox(NULL, _("The Bacula service could not be stopped"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - } - - // Now remove the service from the SCM - if (DeleteService(hservice)) { - if (!silent) { - MessageBox(NULL, _("The Bacula service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); - } - } else { - MessageBox(NULL, _("The Bacula service could not be removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hservice); - } else { - MessageBox(NULL, _("The Bacula service could not be found"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hsrvmanager); - } else { - MessageBox(NULL, _("The SCM could not be contacted - the Bacula service was not removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - break; - } - return 0; -} - -// USEFUL SERVICE SUPPORT ROUTINES - -// Service control routine -void WINAPI ServiceCtrl(DWORD ctrlcode) -{ - // What control code have we been sent? - switch(ctrlcode) { - case SERVICE_CONTROL_STOP: - // STOP : The service must stop - g_srvstatus.dwCurrentState = SERVICE_STOP_PENDING; - ServiceStop(); - break; - - case SERVICE_CONTROL_INTERROGATE: - // QUERY : Service control manager just wants to know our state - break; - - default: - // Control code not recognised - break; - } - - // Tell the control manager what we're up to. - ReportStatus(g_srvstatus.dwCurrentState, NO_ERROR, 0); -} - -// Service manager status reporting -BOOL ReportStatus(DWORD state, - DWORD exitcode, - DWORD waithint) -{ - static DWORD checkpoint = 1; - BOOL result = TRUE; - - // If we're in the start state then we don't want the control manager - // sending us control messages because they'll confuse us. - if (state == SERVICE_START_PENDING) { - g_srvstatus.dwControlsAccepted = 0; - } else { - g_srvstatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; - } - - // Save the new status we've been given - g_srvstatus.dwCurrentState = state; - g_srvstatus.dwWin32ExitCode = exitcode; - g_srvstatus.dwWaitHint = waithint; - - // Update the checkpoint variable to let the SCM know that we - // haven't died if requests take a long time - if ((state == SERVICE_RUNNING) || (state == SERVICE_STOPPED)) { - g_srvstatus.dwCheckPoint = 0; - } else { - g_srvstatus.dwCheckPoint = checkpoint++; - } - - // Tell the SCM our new status - if (!(result = SetServiceStatus(g_hstatus, &g_srvstatus))) { - log_error_message(_("SetServiceStatus failed")); - } - - return result; -} - -// Error reporting -void LogErrorMsg(char *message, char *fname, int lineno) -{ - char msgbuff[256]; - HANDLE heventsrc; - char * strings[32]; - LPTSTR msg; - - // Get the error code - g_error = GetLastError(); - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - g_error, - 0, - (LPTSTR)&msg, - 0, - NULL); - - // Use event logging to log the error - heventsrc = RegisterEventSource(NULL, BAC_SERVICENAME); - - sprintf(msgbuff, _("\n\n%s error: %ld at %s:%d"), - BAC_SERVICENAME, g_error, fname, lineno); - strings[0] = msgbuff; - strings[1] = message; - strings[2] = msg; - - if (heventsrc != NULL) { - MessageBeep(MB_OK); - - ReportEvent( - heventsrc, // handle of event source - EVENTLOG_ERROR_TYPE, // event type - 0, // event category - 0, // event ID - NULL, // current user's SID - 3, // strings in 'strings' - 0, // no bytes of raw data - (const char **)strings, // array of error strings - NULL); // no raw data - - DeregisterEventSource(heventsrc); - } - LocalFree(msg); -} -typedef BOOL (WINAPI * WinAPI)(SC_HANDLE, DWORD, LPVOID); - -void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, - LPSTR lpDesc) -{ - SC_LOCK sclLock; - LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf; - SERVICE_DESCRIPTION sdBuf; - DWORD dwBytesNeeded; - WinAPI ChangeServiceDescription; - - HINSTANCE hLib = LoadLibrary("ADVAPI32.DLL"); - if (!hLib) { - return; - } - ChangeServiceDescription = (WinAPI)GetProcAddress(hLib, - "ChangeServiceConfig2A"); - FreeLibrary(hLib); - if (!ChangeServiceDescription) { - return; - } - - // Need to acquire database lock before reconfiguring. - sclLock = LockServiceDatabase(hSCManager); - - // If the database cannot be locked, report the details. - if (sclLock == NULL) { - // Exit if the database is not locked by another process. - if (GetLastError() != ERROR_SERVICE_DATABASE_LOCKED) { - log_error_message("LockServiceDatabase"); - return; - } - - // Allocate a buffer to get details about the lock. - lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS)LocalAlloc( - LPTR, sizeof(QUERY_SERVICE_LOCK_STATUS)+256); - if (lpqslsBuf == NULL) { - log_error_message("LocalAlloc"); - return; - } - - // Get and print the lock status information. - if (!QueryServiceLockStatus( - hSCManager, - lpqslsBuf, - sizeof(QUERY_SERVICE_LOCK_STATUS)+256, - &dwBytesNeeded)) { - log_error_message("QueryServiceLockStatus"); - } - - if (lpqslsBuf->fIsLocked) { - printf(_("Locked by: %s, duration: %ld seconds\n"), - lpqslsBuf->lpLockOwner, - lpqslsBuf->dwLockDuration); - } else { - printf(_("No longer locked\n")); - } - - LocalFree(lpqslsBuf); - log_error_message(_("Could not lock database")); - return; - } - - // The database is locked, so it is safe to make changes. - - sdBuf.lpDescription = lpDesc; - - if (!ChangeServiceDescription( - hService, // handle to service - SERVICE_CONFIG_DESCRIPTION, // change: description - &sdBuf) ) { // value: new description - log_error_message("ChangeServiceConfig2"); - } - - // Release the database lock. - UnlockServiceDatabase(sclLock); -} diff --git a/bacula/src/filed/win32/winservice.h b/bacula/src/filed/win32/winservice.h deleted file mode 100755 index 157dea3b18..0000000000 --- a/bacula/src/filed/win32/winservice.h +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. -// -// This file was part of the ups system. -// -// The ups system is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// If the source code for the ups system is not available from the place -// whence you received this file, check http://www.uk.research.att.com/vnc or contact -// the authors on ups@uk.research.att.com for information on obtaining it. -// -// This file has been adapted to the Win32 version of Bacula -// by Kern E. Sibbald. Many thanks to ATT and James Weatherall, -// the original author, for providing an excellent template. -// -// Copyright (C) 2000-2006 Kern E. Sibbald -// - - -// winservice.cpp - -// SERVICE-MODE CODE - -// This class provides access to service-oriented routines, under both -// Windows NT and Windows 95. Some routines only operate under one -// OS, others operate under any OS. - -class bacService; - -#if (!defined(_win_bacService)) -#define _win_bacService - -// The NT-specific code wrapper class -class bacService -{ -public: - bacService(); - - // SERVICE INSTALL & START FUNCTIONS - - // Routine called by WinMain to cause Bacula to be installed - // as a service. - static int BaculaServiceMain(); - - // Routine to install the Apcupsd service on the local machine - static int InstallService(); - - // Routine to remove the Apcupsd service from the local machine - static int RemoveService(); - - // SERVICE SUPPORT FUNCTIONS - - // Routine to establish and return the currently logged in user name - static BOOL CurrentUser(char *buffer, UINT size); - - // Routine to post a message to the currently running Apcupsd server - // to pass it a handle to the current user - static BOOL PostUserHelperMessage(); - // Routine to process a user helper message - static BOOL ProcessUserHelperMessage(WPARAM wParam, LPARAM lParam); - - // Routines to establish which OS we're running on - static BOOL IsWin95(); - static BOOL IsWinNT(); - - // Routine to establish whether the current instance is running - // as a service or not - static BOOL RunningAsService(); - - // Routine to kill any other running copy of Apcupsd - static BOOL KillRunningCopy(); - - // Routine to set the current thread into the given desktop - static BOOL SelectHDESK(HDESK newdesktop); - - // Routine to set the current thread into the named desktop, - // or the input desktop if no name is given - static BOOL SelectDesktop(char *name); - - // Routine to establish whether the current thread desktop is the - // current user input one - static BOOL InputDesktopSelected(); - - // Routine to fake a CtrlAltDel to winlogon when required. - // *** This is a nasty little hack... - static BOOL SimulateCtrlAltDel(); - - // Routine to make any currently running version of Apcupsd show its - // Properties dialog, to allow the user to make changes to their settings - static BOOL ShowProperties(); - - // Routine to make any currently running version of Apcupsd show the - // Properties dialog for the default settings, so the user can make changes - static BOOL ShowDefaultProperties(); - - // Routine to make the an already running copy of Apcupsd bring up its - // About box so you can check the version! - static BOOL ShowAboutBox(); - - // Routine to make the an already running copy of Apcupsd bring up its - // Status dialog - static BOOL ShowStatus(); - - // Routine to make the an already running copy of Apcupsd bring up its - // Events dialog - static BOOL ShowEvents(); - - // Routine to make an already running copy of Apcupsd form an outgoing - // connection to a new ups client - static BOOL PostAddNewClient(unsigned long ipaddress); -}; - -#endif diff --git a/bacula/src/filed/win32/winstat.cpp b/bacula/src/filed/win32/winstat.cpp deleted file mode 100755 index 45e3c41ad1..0000000000 --- a/bacula/src/filed/win32/winstat.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Bacula File daemon Status Dialog box - * - * Inspired from the VNC code by ATT. - * - * Copyright (2000) Kern E. Sibbald - * - */ -/* - Copyright (C) 2000-2003 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "bacula.h" -#include "winbacula.h" -#include "winstat.h" -#include "winres.h" - -extern void FillStatusBox(HWND hwnd, int id_list); - -bacStatus::bacStatus() -{ - visible = FALSE; -} - -bacStatus::~bacStatus() -{ -} - - -/* Dialog box handling functions */ -void -bacStatus::Show(BOOL show) -{ - if (show && !visible) { - DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_STATUS), NULL, - (DLGPROC)DialogProc, (LONG)this); - } -} - -BOOL CALLBACK -bacStatus::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - /* Get class pointer from user data */ - bacStatus *_this = (bacStatus *)GetWindowLong(hwnd, GWL_USERDATA); - - switch (uMsg) { - case WM_INITDIALOG: - /* Set class pointer in user data */ - SetWindowLong(hwnd, GWL_USERDATA, lParam); - _this = (bacStatus *)lParam; - - /* show the dialog */ - SetForegroundWindow(hwnd); - - /* Update every 5 seconds */ - SetTimer(hwnd, 1, 5000, NULL); - _this->visible = TRUE; - FillStatusBox(hwnd, IDC_LIST); - return TRUE; - - case WM_TIMER: - FillStatusBox(hwnd, IDC_LIST); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - case IDOK: - KillTimer(hwnd, 1); - EndDialog(hwnd, TRUE); - _this->visible = FALSE; - return TRUE; - } - break; - - case WM_DESTROY: - KillTimer(hwnd, 1); - EndDialog(hwnd, FALSE); - _this->visible = FALSE; - return TRUE; - } - return 0; -} diff --git a/bacula/src/filed/win32/winstat.h b/bacula/src/filed/win32/winstat.h deleted file mode 100755 index 3486a00796..0000000000 --- a/bacula/src/filed/win32/winstat.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Bacula Status Dialog header file - * - */ -/* - Copyright (C) 2000-2003 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. - - */ - - -class bacStatus; - -#ifndef _WINSTAT_H_ -#define _WINSTAT_H_ - -class bacStatus -{ -public: - bacStatus(); - ~bacStatus(); - - /* The Windows callback routine */ - static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - - void Show(BOOL show); - - BOOL visible; -}; - -#endif diff --git a/bacula/src/filed/win32/wintray.cpp b/bacula/src/filed/win32/wintray.cpp deleted file mode 100755 index 044d34b7ce..0000000000 --- a/bacula/src/filed/win32/wintray.cpp +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. -// -// This file was part of the vnc system. -// -// The vnc system is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// If the source code for the vnc system is not available from the place -// whence you received this file, check http://www.uk.research.att.com/vnc or contact -// the authors on vnc@uk.research.att.com for information on obtaining it. -// -// This file has been adapted to the Win32 version of Bacula -// by Kern E. Sibbald. Many thanks to ATT and James Weatherall, -// the original author, for providing an excellent template. -// -// Copyright 2000-2004, Kern E. Sibbald -// - - - -// Tray - -// Implementation of a system tray icon & menu for Bacula - -#include "bacula.h" -#include "jcr.h" -#include "winbacula.h" -#include "winservice.h" -#include "winres.h" -#include "wintray.h" - -// Constants -#ifdef properties_implemented -const UINT MENU_PROPERTIES_SHOW = RegisterWindowMessage("Bacula.Properties.User.Show"); -const UINT MENU_DEFAULT_PROPERTIES_SHOW = RegisterWindowMessage("Bacula.Properties.Default.Show"); -#endif -const UINT MENU_ABOUTBOX_SHOW = RegisterWindowMessage("Bacula.AboutBox.Show"); -const UINT MENU_STATUS_SHOW = RegisterWindowMessage("Bacula.Status.Show"); -const UINT MENU_EVENTS_SHOW = RegisterWindowMessage("Bacula.Events.Show"); -const UINT MENU_SERVICEHELPER_MSG = RegisterWindowMessage("Bacula.ServiceHelper.Message"); -const UINT MENU_ADD_CLIENT_MSG = RegisterWindowMessage("Bacula.AddClient.Message"); -const char *MENU_CLASS_NAME = "Bacula Tray Icon"; - -extern void terminate_filed(int sig); -extern char *bac_status(char *buf, int buf_len); -extern int bacstat; - -// Implementation - -bacMenu::bacMenu() -{ - // Create a dummy window to handle tray icon messages - WNDCLASSEX wndclass; - - wndclass.cbSize = sizeof(wndclass); - wndclass.style = 0; - wndclass.lpfnWndProc = bacMenu::WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = hAppInstance; - wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); - wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); - wndclass.lpszMenuName = (const char *) NULL; - wndclass.lpszClassName = MENU_CLASS_NAME; - wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); - - RegisterClassEx(&wndclass); - - m_hwnd = CreateWindow(MENU_CLASS_NAME, - MENU_CLASS_NAME, - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, - CW_USEDEFAULT, - 200, 200, - NULL, - NULL, - hAppInstance, - NULL); - if (m_hwnd == NULL) { - PostQuitMessage(0); - return; - } - - // record which client created this window - SetWindowLong(m_hwnd, GWL_USERDATA, (LONG) this); - - // Timer to trigger icon updating - SetTimer(m_hwnd, 1, 5000, NULL); - - // Load the icons for the tray - m_idle_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE)); - m_running_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_RUNNING)); - m_error_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR)); - m_warn_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_WARNING)); - - // Load the popup menu - m_hmenu = LoadMenu(hAppInstance, MAKEINTRESOURCE(IDR_TRAYMENU)); - - // Install the tray icon! - AddTrayIcon(); -} - -bacMenu::~bacMenu() -{ - // Remove the tray icon - SendTrayMsg(NIM_DELETE, 0); - - // Destroy the loaded menu - if (m_hmenu != NULL) - DestroyMenu(m_hmenu); -} - -void -bacMenu::AddTrayIcon() -{ - SendTrayMsg(NIM_ADD, bacstat); -} - -void -bacMenu::DelTrayIcon() -{ - SendTrayMsg(NIM_DELETE, 0); -} - - -void -bacMenu::UpdateTrayIcon(int bacstat) -{ - (void *)bac_status(NULL, 0); - SendTrayMsg(NIM_MODIFY, bacstat); -} - -void -bacMenu::SendTrayMsg(DWORD msg, int bacstat) -{ - struct s_last_job *job; - - // Create the tray icon message - m_nid.hWnd = m_hwnd; - m_nid.cbSize = sizeof(m_nid); - m_nid.uID = IDI_BACULA; // never changes after construction - switch (bacstat) { - case 0: - m_nid.hIcon = m_idle_icon; - break; - case JS_Running: - m_nid.hIcon = m_running_icon; - break; - case JS_ErrorTerminated: - m_nid.hIcon = m_error_icon; - break; - default: - if (last_jobs->size() > 0) { - job = (struct s_last_job *)last_jobs->last(); - if (job->Errors) { - m_nid.hIcon = m_warn_icon; - } else { - m_nid.hIcon = m_idle_icon; - } - } else { - m_nid.hIcon = m_idle_icon; - } - break; - } - - m_nid.uFlags = NIF_ICON | NIF_MESSAGE; - m_nid.uCallbackMessage = WM_TRAYNOTIFY; - - - // Use resource string as tip if there is one - if (LoadString(hAppInstance, IDI_BACULA, m_nid.szTip, sizeof(m_nid.szTip))) { - m_nid.uFlags |= NIF_TIP; - } - - // Try to add the Bacula status to the tip string, if possible - if (m_nid.uFlags & NIF_TIP) { - bac_status(m_nid.szTip, sizeof(m_nid.szTip)); - } - - // Send the message - if (Shell_NotifyIcon(msg, &m_nid)) { - EnableMenuItem(m_hmenu, ID_CLOSE, MF_ENABLED); - } else { - if (!bacService::RunningAsService()) { - if (msg == NIM_ADD) { - // The tray icon couldn't be created, so use the Properties dialog - // as the main program window - // removed because it causes quit when not running as a - // service in use with BartPe. - // PostQuitMessage(0); - } - } - } -} - -// Process window messages -LRESULT CALLBACK bacMenu::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) -{ - // This is a static method, so we don't know which instantiation we're - // dealing with. We use Allen Hadden's (ahadden@taratec.com) suggestion - // from a newsgroup to get the pseudo-this. - bacMenu *_this = (bacMenu *) GetWindowLong(hwnd, GWL_USERDATA); - - switch (iMsg) { - - // Every five seconds, a timer message causes the icon to update - case WM_TIMER: - // *** HACK for running servicified - if (bacService::RunningAsService()) { - // Attempt to add the icon if it's not already there - _this->AddTrayIcon(); - } - - // Update the icon - _this->UpdateTrayIcon(bacstat); - break; - - // STANDARD MESSAGE HANDLING - case WM_CREATE: - return 0; - - case WM_COMMAND: - // User has clicked an item on the tray menu - switch (LOWORD(wParam)) { - case ID_STATUS: - // Show the status dialog - _this->m_status.Show(TRUE); - _this->UpdateTrayIcon(bacstat); - break; - - case ID_EVENTS: - // Show the Events dialog - _this->m_events.Show(TRUE); - _this->UpdateTrayIcon(bacstat); - break; - - - case ID_KILLCLIENTS: - // Disconnect all currently connected clients - break; - - case ID_ABOUT: - // Show the About box - _this->m_about.Show(TRUE); - break; - - case ID_CLOSE: - // User selected Close from the tray menu - PostMessage(hwnd, WM_CLOSE, 0, 0); - break; - - } - return 0; - - case WM_TRAYNOTIFY: - // User has clicked on the tray icon or the menu - { - // Get the submenu to use as a pop-up menu - HMENU submenu = GetSubMenu(_this->m_hmenu, 0); - - // What event are we responding to, RMB click? - if (lParam==WM_RBUTTONUP) { - if (submenu == NULL) { - return 0; - } - - // Make the first menu item the default (bold font) - SetMenuDefaultItem(submenu, 0, TRUE); - - // Get the current cursor position, to display the menu at - POINT mouse; - GetCursorPos(&mouse); - - // There's a "bug" - // (Microsoft calls it a feature) in Windows 95 that requires calling - // SetForegroundWindow. To find out more, search for Q135788 in MSDN. - // - SetForegroundWindow(_this->m_nid.hWnd); - - // Display the menu at the desired position - TrackPopupMenu(submenu, - 0, mouse.x, mouse.y, 0, - _this->m_nid.hWnd, NULL); - - return 0; - } - - // Or was there a LMB double click? - if (lParam==WM_LBUTTONDBLCLK) { - // double click: execute first menu item - SendMessage(_this->m_nid.hWnd, - WM_COMMAND, - GetMenuItemID(submenu, 0), - 0); - } - - return 0; - } - - case WM_CLOSE: - terminate_filed(0); - break; - - case WM_DESTROY: - // The user wants Bacula to quit cleanly... - PostQuitMessage(0); - return 0; - - case WM_QUERYENDSESSION: - // Are we running as a system service? - // Or is the system shutting down (in which case we should check anyway!) - if ((!bacService::RunningAsService()) || (lParam == 0)) { - // No, so we are about to be killed - - // If there are remote connections then we should verify - // that the user is happy about killing them. - - // Finally, post a quit message, just in case - PostQuitMessage(0); - return TRUE; - } - return TRUE; - - - default: - if (iMsg == MENU_ABOUTBOX_SHOW) { - // External request to show our About dialog - PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0); - return 0; - } - if (iMsg == MENU_STATUS_SHOW) { - // External request to show our status - PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0); - return 0; - } - } - - // Message not recognised - return DefWindowProc(hwnd, iMsg, wParam, lParam); -} diff --git a/bacula/src/filed/win32/wintray.h b/bacula/src/filed/win32/wintray.h deleted file mode 100755 index 2f40492df9..0000000000 --- a/bacula/src/filed/win32/wintray.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. -// -// This file was part of the VNC system. -// -// The VNC system is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. -// -// If the source code for the VNC system is not available from the place -// whence you received this file, check http://www.uk.research.att.com/vnc or contact -// the authors on vnc@uk.research.att.com for information on obtaining it. -// -// This file has been adapted to the Win32 version of Bacula -// by Kern E. Sibbald. Many thanks to ATT and James Weatherall, -// the original author, for providing an excellent template. -// -// Copyright (2000) Kern E. Sibbald -// - - - -// winMenu - -// This class handles creation of a system-tray icon & menu - -class bacMenu; - -#if (!defined(_win_bacMENU)) -#define _win_bacMENU - -#include -#include "winabout.h" -#include "winstat.h" -#include "winevents.h" - -// Constants -extern const UINT MENU_ABOUTBOX_SHOW; -extern const UINT MENU_STATUS_SHOW; -extern const UINT MENU_EVENTS_SHOW; -extern const UINT MENU_SERVICEHELPER_MSG; -extern const UINT MENU_ADD_CLIENT_MSG; -extern const char *MENU_CLASS_NAME; - -// The tray menu class itself -class bacMenu -{ -public: - bacMenu(); - ~bacMenu(); -protected: - // Tray icon handling - void AddTrayIcon(); - void DelTrayIcon(); - void UpdateTrayIcon(int battstat); - void SendTrayMsg(DWORD msg, int battstat); - - // Message handler for the tray window - static LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); - - // Fields -protected: - - // About dialog for this server - bacAbout m_about; - - // Status dialog for this server - bacStatus m_status; - - bacEvents m_events; - - HWND m_hwnd; - HMENU m_hmenu; - NOTIFYICONDATA m_nid; - - // The icon handles - HICON m_idle_icon; - HICON m_running_icon; - HICON m_error_icon; - HICON m_warn_icon; -}; - - -#endif diff --git a/bacula/src/findlib/Makefile.in b/bacula/src/findlib/Makefile.in index 2a84fc9253..d1e2950faa 100644 --- a/bacula/src/findlib/Makefile.in +++ b/bacula/src/findlib/Makefile.in @@ -22,7 +22,7 @@ first_rule: all dummy: # -LIBSRCS = find.c match.c find_one.c attibs.c create_file.c \ +LIBSRCS = find.c match.c find_one.c attribs.c create_file.c \ bfile.c drivetype.c enable_priv.c fstype.c makepath.c save-cwd.c LIBOBJS = find.o match.o find_one.o attribs.o create_file.o \ bfile.o drivetype.o enable_priv.o fstype.o makepath.o save-cwd.o diff --git a/bacula/src/findlib/Makefile.mingw b/bacula/src/findlib/Makefile.mingw deleted file mode 100644 index 46fdb6d3c9..0000000000 --- a/bacula/src/findlib/Makefile.mingw +++ /dev/null @@ -1,162 +0,0 @@ -# -# Find files library Makefile -# - -# autoconf/Make.common.in -*- Makefile -*- -# release date (man), LSM date, version number/name, current maintainer -DATE="15 Apr 2004" -LSMDATE=15Apr04 -VERSION=1.35.0 -VERNAME=bacula-$(VERSION)# -MAINT=Kern Sibbald# -MAINTEMAIL=# -WEBMAINT=# -WEBMAINTEMAIL=# -WEBPAGE=# -FTPSITENAME=# -FTPSITEDIR=# -#------------------------------------------------------------------------- - -SHELL = /bin/sh - -# Installation target directories & other installation stuff -prefix = -exec_prefix = -binprefix = -manprefix = -sbindir = /sbin -sysconfdir = /etc/bacula -scriptdir = /etc/bacula -mandir = ${prefix}/man/man1 -manext = 1 - -# Tools & program stuff -CC = gcc -CPP = gcc -E -CXX = g++ -MV = /usr/bin/mv -RM = /usr/bin/rm -RMF = /usr/bin/rm -f -CP = /usr/bin/cp -SED = /usr/bin/sed -AWK = /usr/bin/awk -ECHO = /usr/bin/echo -CMP = /usr/bin/cmp -TBL = /usr/bin/tbl -AR = ar -RANLIB = ranlib -INSTALL = /usr/bin/install -c -# add the -s to the following in PRODUCTION mode -INSTALL_PROGRAM = /usr/bin/install -c -m 754 -INSTALL_DATA = /usr/bin/install -c -m 644 -INSTALL_SCRIPT = /usr/bin/install -c -m 754 -INSTALL_CONFIG = /usr/bin/install -c -m 640 - -# Flags & libs -CFLAGS = -g -O2 -CPPFLAGS = -LDFLAGS = -O -TTOOL_LDFLAGS = -DEFS = -DHAVE_WIN32 -DHAVE_MINGW -LIBS = -lpthread -DINCLUDE = -DLIB = -DB_LIBS = - -# Windows (cygwin) flags -WCFLAGS = -mwindows -WLDFLAGS = -mwindows - -# X Include directory -#XINC = @XPM_CFLAGS@ - -# extra libraries needed by X on some systems, X library location -#XLIB = @XPM_LIBS@ -lX11 - -# End of common section of the Makefile -#------------------------------------------------------------------------- - -srcdir = . -VPATH = . -.PATH: . - -# one up -basedir = .. -# top dir -topdir = ../.. -# this dir relative to top dir -thisdir = src/findlib - -DEBUG= - -first_rule: all -dummy: - -# -LIBSRCS = find.c match.c find_one.c attibs.c create_file.c \ - bfile.c enable_priv.c fstype.c makepath.c save-cwd.c winapi.c -LIBOBJS = find.o match.o find_one.o attribs.o create_file.o \ - bfile.o enable_priv.o fstype.o makepath.o save-cwd.o winapi.o - -.SUFFIXES: .c .o -.PHONY: -.DONTCARE: - -# inference rules -.c.o: - $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) -I../win32/compat $(DINCLUDE) $(CFLAGS) $< -#------------------------------------------------------------------------- -all: libfind.a - @echo "==== Make of findlib is good ====" - @echo " " - -libfind.a: $(LIBOBJS) - $(RMF) $@ - $(AR) cr $@ $(LIBOBJS) - $(RANLIB) $@ - -install: - -uninstall: - - -clean: - $(RMF) find core a.out *.a *.o *.bak *~ *.intpro *.extpro 1 2 3 - -realclean: clean - $(RMF) tags - -distclean: realclean - if test $(srcdir) = .; then $(MAKE) realclean; fi - (cd $(srcdir); $(RMF) Makefile; $(RMF) -r CVS) - -devclean: realclean - if test $(srcdir) = .; then $(MAKE) realclean; fi - (cd $(srcdir); $(RMF) Makefile) - -install: - - -uninstall: - - - -# Semi-automatic generation of dependencies: -# Use gcc -M because X11 `makedepend' doesn't work on all systems -# and it also includes system headers. -# `semi'-automatic since dependencies are generated at distribution time. - -depend: - @$(MV) Makefile Makefile.bak - @$(SED) "/^# DO NOT DELETE:/,$$ d" Makefile.bak > Makefile - @$(ECHO) "# DO NOT DELETE: nice dependency list follows" >> Makefile - @$(CC) -S -M $(CPPFLAGS) $(XINC) -I$(srcdir) -I$(basedir) $(SQL_INC) *.c >> Makefile - @if test -f Makefile ; then \ - $(RMF) Makefile.bak; \ - else \ - $(MV) Makefile.bak Makefile; \ - echo -e "Something went wrong\n\a"; \ - fi - -# ----------------------------------------------------------------------- -# DO NOT DELETE: nice dependency list follows diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index 6a81ac5dac..ab9a87f51d 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -710,17 +710,4 @@ void win_error(JCR *jcr, char *prefix, DWORD lerror) } LocalFree(msg); } - - -/* Conversion of a Unix filename to a Win32 filename */ -extern void conv_unix_to_win32_path(const char *path, char *win32_path, DWORD dwSize); -void unix_name_to_win32(POOLMEM **win32_name, char *name) -{ - /* One extra byte should suffice, but we double it */ - /* add MAX_PATH bytes for VSS shadow copy name */ - DWORD dwSize = 2*strlen(name)+MAX_PATH; - *win32_name = check_pool_memory_size(*win32_name, dwSize); - conv_unix_to_win32_path(name, *win32_name, dwSize); -} - #endif /* HAVE_WIN32 */ diff --git a/bacula/src/lib/Makefile.in b/bacula/src/lib/Makefile.in index 827d52f539..ad6c837fe0 100644 --- a/bacula/src/lib/Makefile.in +++ b/bacula/src/lib/Makefile.in @@ -32,7 +32,7 @@ LIBSRCS = alloc.c attr.c base64.c berrno.c bsys.c bget_msg.c \ res.c rwlock.c scan.c serial.c sha1.c \ semlock.c signal.c smartall.c tls.c tree.c \ util.c var.c watchdog.c workq.c btimers.c \ - address_conf.c pythonlib.c winapi.c + address_conf.c pythonlib.c LIBOBJS = alloc.o attr.o base64.o berrno.o bsys.o bget_msg.o \ @@ -45,7 +45,7 @@ LIBOBJS = alloc.o attr.o base64.o berrno.o bsys.o bget_msg.o \ res.o rwlock.o scan.o serial.o sha1.o \ semlock.o signal.o smartall.o tls.o tree.o \ util.o var.o watchdog.o workq.o btimers.o \ - address_conf.o pythonlib.o winapi.o + address_conf.o pythonlib.o EXTRAOBJS = @OBJLIST@ diff --git a/bacula/src/lib/Makefile.mingw b/bacula/src/lib/Makefile.mingw deleted file mode 100644 index dab73ebe0b..0000000000 --- a/bacula/src/lib/Makefile.mingw +++ /dev/null @@ -1,232 +0,0 @@ -# $Id$ - -# autoconf/Make.common.in -*- Makefile -*- -# release date (man), LSM date, version number/name, current maintainer -DATE="15 Apr 2004" -LSMDATE=15Apr04 -VERSION=1.35.0 -VERNAME=bacula-$(VERSION)# -MAINT=Kern Sibbald# -MAINTEMAIL=# -WEBMAINT=# -WEBMAINTEMAIL=# -WEBPAGE=# -FTPSITENAME=# -FTPSITEDIR=# -#------------------------------------------------------------------------- - -SHELL = /bin/sh - -# Installation target directories & other installation stuff -prefix = -exec_prefix = -binprefix = -manprefix = -sbindir = /sbin -sysconfdir = /etc/bacula -scriptdir = /etc/bacula -mandir = ${prefix}/man/man1 -manext = 1 - -# Tools & program stuff -CC = gcc -CPP = gcc -E -CXX = g++ -MV = /usr/bin/mv -RM = /usr/bin/rm -RMF = /usr/bin/rm -f -CP = /usr/bin/cp -SED = /usr/bin/sed -AWK = /usr/bin/awk -ECHO = /usr/bin/echo -CMP = /usr/bin/cmp -TBL = /usr/bin/tbl -AR = ar -RANLIB = ranlib -INSTALL = /usr/bin/install -c -# add the -s to the following in PRODUCTION mode -INSTALL_PROGRAM = /usr/bin/install -c -m 754 -INSTALL_DATA = /usr/bin/install -c -m 644 -INSTALL_SCRIPT = /usr/bin/install -c -m 754 -INSTALL_CONFIG = /usr/bin/install -c -m 640 - -# Flags & libs -CFLAGS = -g -O2 -Wall -CPPFLAGS = -LDFLAGS = -O -TTOOL_LDFLAGS = -DEFS = -DHAVE_WIN32 -DHAVE_MINGW -LIBS = -lpthread -DINCLUDE = -DLIB = -DB_LIBS = - -# Windows (cygwin) flags -WCFLAGS = -mwindows -WLDFLAGS = -mwindows - -# X Include directory -#XINC = @XPM_CFLAGS@ - -# extra libraries needed by X on some systems, X library location -#XLIB = @XPM_LIBS@ -lX11 - -# End of common section of the Makefile -#------------------------------------------------------------------------- - -CWEB = @CWEB@ -CTANGLE = $(CWEB)/ctangle -CWEAVE = $(CWEB)/cweave -TEXINPUTS = TEXINPUTS=.:$(CWEB): - -# FIXME -- These should be found by autoconf -TEX = tex -PDFTEX = pdftex -XDVI = xdvi -DVIPS = dvips - -srcdir = . -VPATH = . -.PATH: . - -# one up -basedir = .. -# top dir -topdir = ../.. -# this dir relative to top dir -thisdir = src/lib - - -DEBUG= - -GMP_INC=@GMP_INC@ - -first_rule: all -dummy: - -LIBSRCS = alloc.c attr.c base64.c bsys.c bget_msg.c \ - bnet.c bnet_server.c \ - bpipe.c bshm.c btime.c \ - cram-md5.c crc32.c daemon.c edit.c fnmatch.c \ - hmac.c idcache.c jcr.c lex.c alist.c dlist.c \ - md5.c message.c mem_pool.c parse_conf.c \ - queue.c rwlock.c scan.c serial.c sha1.c \ - semlock.c signal.c smartall.c tree.c \ - util.c var.c watchdog.c workq.c timers.c - - -LIBOBJS = alloc.o attr.o base64.o bsys.o bget_msg.o \ - bnet.o bnet_server.o \ - bpipe.o bshm.o btime.o \ - cram-md5.o crc32.o daemon.o edit.o fnmatch.o \ - hmac.o idcache.o jcr.o lex.o alist.o dlist.o \ - md5.o message.o mem_pool.o parse_conf.o \ - queue.o rwlock.o scan.o serial.o sha1.o \ - semlock.o signal.o smartall.o tree.o \ - util.o var.o watchdog.o workq.o timers.o - - - -EXTRAOBJS = - - -.SUFFIXES: .c .o .ch .dvi .pdf .tex .view .w .1 -.PHONY: -.DONTCARE: - -# inference rules -compat.o: ../win32/compat/compat.cpp - $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat \ - -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -o compat.o ../win32/compat/compat.cpp - -.c.o: - $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< - -.cc.o: - $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< - -.w.c: - $(CTANGLE) $< - -.w.tex: - $(CWEAVE) $< - -.tex.dvi: - ( $(TEXINPUTS) ; export TEXINPUTS; $(TEX) $< ) - -.tex.pdf: - ( $(TEXINPUTS) ; export TEXINPUTS; $(PDFTEX) $< ) - -.dvi.view: - $(XDVI) -s 0 $< - -#------------------------------------------------------------------------- -all: Makefile libbac.a - @echo "==== Make of lib is good ====" - @echo " " - -libbac.a: $(LIBOBJS) compat.o - $(AR) rc $@ $(LIBOBJS) compat.o - $(RANLIB) $@ - - -Makefile: $(srcdir)/Makefile.in $(topdir)/config.status - cd $(topdir) \ - && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - -rwlock_test: - rm -f rwlock.o - $(CXX) -DTEST_RWLOCK $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c - $(CXX) $(LDFLAGS) -L. -o $@ rwlock.o $(LIBS) $(DLIB) -lbac -lm - rm -f rwlock.o - $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c - -md5sum: - rm -f md5.o - $(CXX) -DMD5_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c - $(CXX) $(LDFLAGS) -L. -o $@ md5.o $(LIBS) $(DLIB) -lbac -lm - rm -f md5.o - $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c - - -sha1sum: - rm -f sha1.o - $(CXX) -DSHA1_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c - $(CXX) $(LDFLAGS) -L. -o $@ sha1.o $(LIBS) $(DLIB) -lbac -lm - rm -f sha1.o - $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c - -install: - -uninstall: - -clean: - $(RMF) *.a core a.out *.o *.bak *.tex *.pdf *~ *.intpro *.extpro 1 2 3 - $(RMF) rwlock_test md5sum sha1sum - -realclean: clean - $(RMF) tags - -distclean: realclean - if test $(srcdir) = .; then $(MAKE) realclean; fi - (cd $(srcdir); $(RMF) Makefile; $(RMF) -r CVS) - -# Semi-automatic generation of dependencies: -# Use gcc -MM because X11 `makedepend' doesn't work on all systems -# and it also includes system headers. -# `semi'-automatic since dependencies are generated at distribution time. - -depend: - @$(MV) Makefile Makefile.bak - @$(SED) "/^# DO NOT DELETE:/,$$ d" Makefile.bak > Makefile - @$(ECHO) "# DO NOT DELETE: nice dependency list follows" >> Makefile - @$(CXX) -S -M $(CPPFLAGS) $(XINC) -I$(srcdir) -I$(basedir) $(SQL_INC) *.c >> Makefile - @if test -f Makefile ; then \ - $(RMF) Makefile.bak; \ - else \ - $(MV) Makefile.bak Makefile; \ - echo -e "Something went wrong\n\a"; \ - fi - -# ----------------------------------------------------------------------- -# DO NOT DELETE: nice dependency list follows \ No newline at end of file diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index 12a5d8b925..d0fa3aaa79 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -41,6 +41,8 @@ int num_execvp_errors = (int)(sizeof(execvp_errors)/sizeof(int)); #define MAX_ARGV 100 + +#if !defined(HAVE_WIN32) static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_arg); /* @@ -249,6 +251,53 @@ int close_bpipe(BPIPE *bpipe) return stat; } +/* + * Build argc and argv from a string + */ +static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv) +{ + int i; + char *p, *q, quote; + int argc = 0; + + argc = 0; + for (i=0; i @@ -2718,4 +2717,3 @@ const char *var_strerror(var_t *var, var_rc_t rc) } return str; } -#endif /* !defined(HAVE_WIN32) */ diff --git a/bacula/src/lib/winapi.c b/bacula/src/lib/winapi.c deleted file mode 100644 index 58a20fd715..0000000000 --- a/bacula/src/lib/winapi.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Windows APIs that are different for each system. - * We use pointers to the entry points so that a - * single binary will run on all Windows systems. - * - * Kern Sibbald MMIII - */ -/* - Copyright (C) 2003-2006 Kern Sibbald - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as amended with additional clauses defined in the - file LICENSE in the main source directory. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. - - */ - -#ifdef __APCUPSD__ -#include "apc.h" -#else -#include "bacula.h" -#endif - -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) - -#include "winapi.h" - -int win32_client = 1; - -#ifdef WIN32_VSS -#include "vss.h" -#endif - -// init with win9x, but maybe set to NT in InitWinAPI -DWORD g_platform_id = VER_PLATFORM_WIN32_WINDOWS; -#ifdef WIN32_VSS -/* preset VSSClient to NULL */ -VSSClient *g_pVSSClient = NULL; -#endif - - -/* API Pointers */ - -t_OpenProcessToken p_OpenProcessToken = NULL; -t_AdjustTokenPrivileges p_AdjustTokenPrivileges = NULL; -t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL; - -t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL; - -t_CreateFileA p_CreateFileA = NULL; -t_CreateFileW p_CreateFileW = NULL; -t_CreateDirectoryA p_CreateDirectoryA; -t_CreateDirectoryW p_CreateDirectoryW; - -t_wunlink p_wunlink = NULL; -t_wmkdir p_wmkdir = NULL; -t_wopen p_wopen = NULL; - -t_GetFileAttributesA p_GetFileAttributesA = NULL; -t_GetFileAttributesW p_GetFileAttributesW = NULL; - -t_GetFileAttributesExA p_GetFileAttributesExA = NULL; -t_GetFileAttributesExW p_GetFileAttributesExW = NULL; - -t_SetFileAttributesA p_SetFileAttributesA = NULL; -t_SetFileAttributesW p_SetFileAttributesW = NULL; -t_BackupRead p_BackupRead = NULL; -t_BackupWrite p_BackupWrite = NULL; -t_WideCharToMultiByte p_WideCharToMultiByte = NULL; -t_MultiByteToWideChar p_MultiByteToWideChar = NULL; - -t_FindFirstFileA p_FindFirstFileA = NULL; -t_FindFirstFileW p_FindFirstFileW = NULL; - -t_FindNextFileA p_FindNextFileA = NULL; -t_FindNextFileW p_FindNextFileW = NULL; - -t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL; -t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL; - -t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL; -t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL; - -t_GetVolumePathNameW p_GetVolumePathNameW = NULL; -t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL; - -#ifdef WIN32_VSS -void -VSSCleanup() -{ - if (g_pVSSClient) - delete (g_pVSSClient); -} -#endif - -void -InitWinAPIWrapper() -{ - HMODULE hLib = LoadLibraryA("KERNEL32.DLL"); - if (hLib) { - /* create file calls */ - p_CreateFileA = (t_CreateFileA) - GetProcAddress(hLib, "CreateFileA"); - p_CreateFileW = (t_CreateFileW) - GetProcAddress(hLib, "CreateFileW"); - - p_CreateDirectoryA = (t_CreateDirectoryA) - GetProcAddress(hLib, "CreateDirectoryA"); - p_CreateDirectoryW = (t_CreateDirectoryW) - GetProcAddress(hLib, "CreateDirectoryW"); - - /* attribute calls */ - p_GetFileAttributesA = (t_GetFileAttributesA) - GetProcAddress(hLib, "GetFileAttributesA"); - p_GetFileAttributesW = (t_GetFileAttributesW) - GetProcAddress(hLib, "GetFileAttributesW"); - p_GetFileAttributesExA = (t_GetFileAttributesExA) - GetProcAddress(hLib, "GetFileAttributesExA"); - p_GetFileAttributesExW = (t_GetFileAttributesExW) - GetProcAddress(hLib, "GetFileAttributesExW"); - p_SetFileAttributesA = (t_SetFileAttributesA) - GetProcAddress(hLib, "SetFileAttributesA"); - p_SetFileAttributesW = (t_SetFileAttributesW) - GetProcAddress(hLib, "SetFileAttributesW"); - /* process calls */ - p_SetProcessShutdownParameters = (t_SetProcessShutdownParameters) - GetProcAddress(hLib, "SetProcessShutdownParameters"); - /* backup calls */ - p_BackupRead = (t_BackupRead) - GetProcAddress(hLib, "BackupRead"); - p_BackupWrite = (t_BackupWrite) - GetProcAddress(hLib, "BackupWrite"); - /* char conversion calls */ - p_WideCharToMultiByte = (t_WideCharToMultiByte) - GetProcAddress(hLib, "WideCharToMultiByte"); - p_MultiByteToWideChar = (t_MultiByteToWideChar) - GetProcAddress(hLib, "MultiByteToWideChar"); - - /* find files */ - p_FindFirstFileA = (t_FindFirstFileA) - GetProcAddress(hLib, "FindFirstFileA"); - p_FindFirstFileW = (t_FindFirstFileW) - GetProcAddress(hLib, "FindFirstFileW"); - p_FindNextFileA = (t_FindNextFileA) - GetProcAddress(hLib, "FindNextFileA"); - p_FindNextFileW = (t_FindNextFileW) - GetProcAddress(hLib, "FindNextFileW"); - /* set and get directory */ - p_SetCurrentDirectoryA = (t_SetCurrentDirectoryA) - GetProcAddress(hLib, "SetCurrentDirectoryA"); - p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW) - GetProcAddress(hLib, "SetCurrentDirectoryW"); - p_GetCurrentDirectoryA = (t_GetCurrentDirectoryA) - GetProcAddress(hLib, "GetCurrentDirectoryA"); - p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW) - GetProcAddress(hLib, "GetCurrentDirectoryW"); - - /* some special stuff we need for VSS - but statically linkage doesn't work on Win 9x */ - p_GetVolumePathNameW = (t_GetVolumePathNameW) - GetProcAddress(hLib, "GetVolumePathNameW"); - p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW) - GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW"); - - FreeLibrary(hLib); - } - - hLib = LoadLibraryA("MSVCRT.DLL"); - if (hLib) { - /* unlink */ - p_wunlink = (t_wunlink) - GetProcAddress(hLib, "_wunlink"); - /* wmkdir */ - p_wmkdir = (t_wmkdir) - GetProcAddress(hLib, "_wmkdir"); - /* wopen */ - p_wopen = (t_wopen) - GetProcAddress(hLib, "_wopen"); - - FreeLibrary(hLib); - } - - hLib = LoadLibraryA("ADVAPI32.DLL"); - if (hLib) { - p_OpenProcessToken = (t_OpenProcessToken) - GetProcAddress(hLib, "OpenProcessToken"); - p_AdjustTokenPrivileges = (t_AdjustTokenPrivileges) - GetProcAddress(hLib, "AdjustTokenPrivileges"); - p_LookupPrivilegeValue = (t_LookupPrivilegeValue) - GetProcAddress(hLib, "LookupPrivilegeValueA"); - FreeLibrary(hLib); - } - - // do we run on win 9x ??? - OSVERSIONINFO osversioninfo; - osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo); - - DWORD dwMinorVersion; - - // Get the current OS version - if (!GetVersionEx(&osversioninfo)) { - g_platform_id = 0; - dwMinorVersion = 0; - } else { - g_platform_id = osversioninfo.dwPlatformId; - dwMinorVersion = osversioninfo.dwMinorVersion; - } - - /* deinitialize some routines on win95 - they're not implemented well */ - if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS) { - p_BackupRead = NULL; - p_BackupWrite = NULL; - - p_CreateFileW = NULL; - p_GetFileAttributesW = NULL; - p_GetFileAttributesExW = NULL; - - p_SetFileAttributesW = NULL; - - p_FindFirstFileW = NULL; - p_FindNextFileW = NULL; - p_SetCurrentDirectoryW = NULL; - p_GetCurrentDirectoryW = NULL; - - p_wunlink = NULL; - p_wmkdir = NULL; - p_wopen = NULL; - - p_GetVolumePathNameW = NULL; - p_GetVolumeNameForVolumeMountPointW = NULL; - } - - /* decide which vss class to initialize */ -#ifdef WIN32_VSS - switch (dwMinorVersion) { - case 1: - g_pVSSClient = new VSSClientXP(); - atexit(VSSCleanup); - break; - case 2: - g_pVSSClient = new VSSClient2003(); - atexit(VSSCleanup); - break; - } -#endif /* WIN32_VSS */ - atexit(Win32ConvCleanupCache); -} - -#else - -/* Not Windows */ -int win32_client = 0; - -#endif diff --git a/bacula/src/lib/winapi.h b/bacula/src/lib/winapi.h deleted file mode 100644 index 78b108adec..0000000000 --- a/bacula/src/lib/winapi.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Windows APIs that are different for each system. - * We use pointers to the entry points so that a - * single binary will run on all Windows systems. - * - * Kern Sibbald MMIII - */ -/* - Copyright (C) 2003-2006 Kern Sibbald - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as amended with additional clauses defined in the - file LICENSE in the main source directory. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. - - */ - -#ifndef __WINAPI_H -#define __WINAPI_H - -#if defined(HAVE_WIN32) -/* - * Commented out native.h include statement, which is not distributed with the - * free version of VC++, and which is not used in bacula. - * - * #if !defined(HAVE_MINGW) // native.h not present on mingw - * #include - * #endif - */ -#include -#endif - -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) - -#ifndef POOLMEM -typedef char POOLMEM; -#endif - -// unicode enabling of win 32 needs some defines and functions - -// using an average of 3 bytes per character is probably fine in -// practice but I believe that Windows actually uses UTF-16 encoding -// as opposed to UCS2 which means characters 0x10000-0x10ffff are -// valid and result in 4 byte UTF-8 encodings. -#define MAX_PATH_UTF8 MAX_PATH*4 // strict upper bound on UTF-16 to UTF-8 conversion -// from -// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileattributesex.asp -// In the ANSI version of this function, the name is limited to -// MAX_PATH characters. To extend this limit to 32,767 wide -// characters, call the Unicode version of the function and prepend -// "\\?\" to the path. For more information, see Naming a File. -#define MAX_PATH_W 32767 - -int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8); -int UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF); -int make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRawPath = NULL); - - -/* In ADVAPI32.DLL */ - -typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE); -typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL, - PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); -typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID); - -extern t_OpenProcessToken p_OpenProcessToken; -extern t_AdjustTokenPrivileges p_AdjustTokenPrivileges; -extern t_LookupPrivilegeValue p_LookupPrivilegeValue; - -/* In MSVCRT.DLL */ -typedef int (__cdecl * t_wunlink) (const wchar_t *); -typedef int (__cdecl * t_wmkdir) (const wchar_t *); -typedef int (__cdecl * t_wopen) (const wchar_t *, int, ...); - -extern t_wunlink p_wunlink; -extern t_wmkdir p_wmkdir; -extern t_wopen p_wopen; - -/* In KERNEL32.DLL */ -typedef BOOL (WINAPI * t_GetFileAttributesExA)(LPCSTR, GET_FILEEX_INFO_LEVELS, - LPVOID); -typedef BOOL (WINAPI * t_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS, - LPVOID); - -typedef DWORD (WINAPI * t_GetFileAttributesA)(LPCSTR); -typedef DWORD (WINAPI * t_GetFileAttributesW)(LPCWSTR); -typedef BOOL (WINAPI * t_SetFileAttributesA)(LPCSTR, DWORD); -typedef BOOL (WINAPI * t_SetFileAttributesW)(LPCWSTR, DWORD); - -typedef HANDLE (WINAPI * t_CreateFileA) (LPCSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES, - DWORD , DWORD, HANDLE); -typedef HANDLE (WINAPI * t_CreateFileW) (LPCWSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES, - DWORD , DWORD, HANDLE); - -typedef BOOL (WINAPI * t_CreateDirectoryA) (LPCSTR, LPSECURITY_ATTRIBUTES); -typedef BOOL (WINAPI * t_CreateDirectoryW) (LPCWSTR, LPSECURITY_ATTRIBUTES); - -typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD); -typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); -typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); - -typedef int (WINAPI * t_WideCharToMultiByte) (UINT CodePage, DWORD , LPCWSTR, int, - LPSTR, int, LPCSTR, LPBOOL); - -typedef int (WINAPI * t_MultiByteToWideChar) (UINT, DWORD, LPCSTR, int, LPWSTR, int); -typedef HANDLE (WINAPI * t_FindFirstFileA) (LPCSTR, LPWIN32_FIND_DATAA); -typedef HANDLE (WINAPI * t_FindFirstFileW) (LPCWSTR, LPWIN32_FIND_DATAW); - -typedef BOOL (WINAPI * t_FindNextFileA) (HANDLE, LPWIN32_FIND_DATAA); -typedef BOOL (WINAPI * t_FindNextFileW) (HANDLE, LPWIN32_FIND_DATAW); - -typedef BOOL (WINAPI * t_SetCurrentDirectoryA) (LPCSTR); -typedef BOOL (WINAPI * t_SetCurrentDirectoryW) (LPCWSTR); - -typedef DWORD (WINAPI * t_GetCurrentDirectoryA) (DWORD, LPSTR); -typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR); - -typedef BOOL (WINAPI * t_GetVolumePathNameW) (LPCWSTR, LPWSTR, DWORD); -typedef BOOL (WINAPI * t_GetVolumeNameForVolumeMountPointW) (LPCWSTR, LPWSTR, DWORD); - -extern t_GetFileAttributesA p_GetFileAttributesA; -extern t_GetFileAttributesW p_GetFileAttributesW; - -extern t_GetFileAttributesExA p_GetFileAttributesExA; -extern t_GetFileAttributesExW p_GetFileAttributesExW; - -extern t_SetFileAttributesA p_SetFileAttributesA; -extern t_SetFileAttributesW p_SetFileAttributesW; - -extern t_CreateFileA p_CreateFileA; -extern t_CreateFileW p_CreateFileW; - -extern t_CreateDirectoryA p_CreateDirectoryA; -extern t_CreateDirectoryW p_CreateDirectoryW; - -extern t_SetProcessShutdownParameters p_SetProcessShutdownParameters; -extern t_BackupRead p_BackupRead; -extern t_BackupWrite p_BackupWrite; - -extern t_WideCharToMultiByte p_WideCharToMultiByte; -extern t_MultiByteToWideChar p_MultiByteToWideChar; - -extern t_FindFirstFileA p_FindFirstFileA; -extern t_FindFirstFileW p_FindFirstFileW; - -extern t_FindNextFileA p_FindNextFileA; -extern t_FindNextFileW p_FindNextFileW; - -extern t_SetCurrentDirectoryA p_SetCurrentDirectoryA; -extern t_SetCurrentDirectoryW p_SetCurrentDirectoryW; - -extern t_GetCurrentDirectoryA p_GetCurrentDirectoryA; -extern t_GetCurrentDirectoryW p_GetCurrentDirectoryW; - -extern t_GetVolumePathNameW p_GetVolumePathNameW; -extern t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW; - -#ifdef WIN32_VSS -class VSSClient; -extern VSSClient* g_pVSSClient; -#endif - -void InitWinAPIWrapper(); -#endif - -#endif /* __WINAPI_H */ diff --git a/bacula/src/stored/ansi_label.c b/bacula/src/stored/ansi_label.c index 28fba900f7..02b70cadfd 100644 --- a/bacula/src/stored/ansi_label.c +++ b/bacula/src/stored/ansi_label.c @@ -74,7 +74,7 @@ int read_ansi_ibm_label(DCR *dcr) /* Read a maximum of 5 records VOL1, HDR1, ... HDR4 */ for (i=0; i < 6; i++) { do { - stat = read(dev->fd, label, sizeof(label)); + stat = tape_read(dev->fd, label, sizeof(label)); } while (stat == -1 && errno == EINTR); if (stat < 0) { berrno be; @@ -296,7 +296,7 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) } else { label[79] = '3'; /* ANSI label flag */ } - stat = write(dev->fd, label, sizeof(label)); + stat = tape_write(dev->fd, label, sizeof(label)); if (stat != sizeof(label)) { berrno be; Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI VOL1 label. ERR=%s\n"), @@ -328,7 +328,7 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) * This could come at the end of a tape, ignore * EOT errors. */ - stat = write(dev->fd, label, sizeof(label)); + stat = tape_write(dev->fd, label, sizeof(label)); if (stat != sizeof(label)) { berrno be; if (stat == -1) { @@ -357,7 +357,7 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) label[4] = 'V'; ascii_to_ebcdic(label, label, sizeof(label)); } - stat = write(dev->fd, label, sizeof(label)); + stat = tape_write(dev->fd, label, sizeof(label)); if (stat != sizeof(label)) { berrno be; if (stat == -1) { diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 6ac2bfdc2c..e0907d54da 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -511,7 +511,11 @@ bool write_block_to_dev(DCR *dcr) /* * Do write here */ - stat = write(dev->fd, block->buf, (size_t)wlen); + if (dev->is_tape()) { + stat = tape_write(dev->fd, block->buf, (size_t)wlen); + } else { + stat = write(dev->fd, block->buf, (size_t)wlen); + } #ifdef DEBUG_BLOCK_ZEROING if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) { @@ -925,7 +929,11 @@ reread: // uint32_t *bp = (uint32_t *)block->buf; // Pmsg3(000, "Read %p %u at %llu\n", block->buf, block->buf_len, lseek(dev->fd, 0, SEEK_CUR)); - stat = read(dev->fd, block->buf, (size_t)block->buf_len); + if (dev->is_tape()) { + stat = tape_read(dev->fd, block->buf, (size_t)block->buf_len); + } else { + stat = read(dev->fd, block->buf, (size_t)block->buf_len); + } // Pmsg8(000, "stat=%d Csum=%u blen=%u bnum=%u %c%c%c%c\n",stat, bp[0],bp[1],bp[2], // block->buf[12],block->buf[13],block->buf[14],block->buf[15]); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index a69a3d2e3a..21ea77ede6 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -309,6 +309,8 @@ static void terminate_btape(int stat) dev->term(); } + free_volume_list(); + if (debug_level > 10) print_memory_pool_stats(); @@ -2455,7 +2457,11 @@ static void rawfill_cmd() Pmsg1(0, _("Begin writing raw blocks of %u bytes.\n"), block->buf_len); for ( ;; ) { *p = block_num; - stat = write(dev->fd, block->buf, block->buf_len); + if (dev->is_tape()) { + stat = tape_write(dev->fd, block->buf, block->buf_len); + } else { + stat = write(dev->fd, block->buf, block->buf_len); + } if (stat == (int)block->buf_len) { if ((block_num++ % 100) == 0) { printf("+"); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index ffda26336a..3ccde2b2c3 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -264,10 +264,14 @@ DEVICE::open(DCR *dcr, int omode) if (openmode == omode) { return fd; } else { - ::close(fd); /* use system close so correct mode will be used on open */ - clear_opened(); - Dmsg0(100, "Close fd for mode change.\n"); - preserve = state & (ST_LABEL|ST_APPEND|ST_READ); + if (is_tape()) { + tape_close(fd); + } else { + ::close(fd); + } + clear_opened(); + Dmsg0(100, "Close fd for mode change.\n"); + preserve = state & (ST_LABEL|ST_APPEND|ST_READ); } } if (dcr) { @@ -336,6 +340,17 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) Dmsg3(100, "Try open %s mode=%s nonblocking=%d\n", print_name(), mode_to_str(omode), nonblocking); /* Use system open() */ + +#ifdef HAVE_WIN32 + if ((fd = tape_open(dev_name, mode)) < 0) { + berrno be; + dev_errno = errno; + + Mmsg2(errmsg, _("Unable to open device %s: ERR=%s\n"), + print_name(), be.strerror(dev_errno)); + Jmsg0(dcr->jcr, M_FATAL, 0, errmsg); + } +#else while ((fd = ::open(dev_name, mode+nonblocking)) < 0) { berrno be; dev_errno = errno; @@ -361,6 +376,7 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) Jmsg0(dcr->jcr, M_FATAL, 0, errmsg); break; } +#endif if (fd >= 0) { openmode = omode; /* save open mode */ @@ -645,7 +661,7 @@ bool DEVICE::rewind(DCR *dcr) * retrying every 5 seconds. */ for (i=max_rewind_wait; ; i -= 5) { - if (ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; clrerror(MTREW); if (i == max_rewind_wait) { @@ -659,7 +675,7 @@ bool DEVICE::rewind(DCR *dcr) */ if (first && dcr) { int open_mode = openmode; - ::close(fd); + tape_close(fd); clear_opened(); open(dcr, open_mode); if (fd < 0) { @@ -827,7 +843,7 @@ bool DEVICE::eod() mt_com.mt_count = 1; } - if (ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; clrerror(mt_com.mt_op); Dmsg1(50, "ioctl error: %s\n", be.strerror()); @@ -971,7 +987,7 @@ uint32_t status_dev(DEVICE *dev) stat |= BMT_TAPE; Pmsg0(-20,_(" Bacula status:")); Pmsg2(-20,_(" file=%d block=%d\n"), dev->file, dev->block_num); - if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { + if (tape_ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { berrno be; dev->dev_errno = errno; Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), @@ -1017,6 +1033,40 @@ uint32_t status_dev(DEVICE *dev) stat |= BMT_IM_REP_EN; Pmsg0(-20, " IM_REP_EN"); } +#elif defined(HAVE_WIN32) + if (GMT_EOF(mt_stat.mt_gstat)) { + stat |= BMT_EOF; + Pmsg0(-20, " EOF"); + } + if (GMT_BOT(mt_stat.mt_gstat)) { + stat |= BMT_BOT; + Pmsg0(-20, " BOT"); + } + if (GMT_EOT(mt_stat.mt_gstat)) { + stat |= BMT_EOT; + Pmsg0(-20, " EOT"); + } + if (GMT_EOD(mt_stat.mt_gstat)) { + stat |= BMT_EOD; + Pmsg0(-20, " EOD"); + } + if (GMT_WR_PROT(mt_stat.mt_gstat)) { + stat |= BMT_WR_PROT; + Pmsg0(-20, " WR_PROT"); + } + if (GMT_ONLINE(mt_stat.mt_gstat)) { + stat |= BMT_ONLINE; + Pmsg0(-20, " ONLINE"); + } + if (GMT_DR_OPEN(mt_stat.mt_gstat)) { + stat |= BMT_DR_OPEN; + Pmsg0(-20, " DR_OPEN"); + } + if (GMT_IM_REP_EN(mt_stat.mt_gstat)) { + stat |= BMT_IM_REP_EN; + Pmsg0(-20, " IM_REP_EN"); + } + #endif /* !SunOS && !OSF */ if (dev->has_cap(CAP_MTIOCGET)) { Pmsg2(-20, _(" file=%d block=%d\n"), mt_stat.mt_fileno, mt_stat.mt_blkno); @@ -1064,7 +1114,7 @@ bool load_dev(DEVICE *dev) dev->file_addr = 0; mt_com.mt_op = MTLOAD; mt_com.mt_count = 1; - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev->dev_errno = errno; Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), @@ -1096,11 +1146,11 @@ bool DEVICE::offline() #ifdef MTUNLOCK mt_com.mt_op = MTUNLOCK; mt_com.mt_count = 1; - ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); #endif mt_com.mt_op = MTOFFL; mt_com.mt_count = 1; - if (ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev_errno = errno; Mmsg2(errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"), @@ -1173,7 +1223,7 @@ bool DEVICE::fsf(int num) if (has_cap(CAP_FSF) && has_cap(CAP_MTIOCGET) && has_cap(CAP_FASTFSF)) { mt_com.mt_op = MTFSF; mt_com.mt_count = num; - stat = ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); if (stat < 0 || !dev_get_os_pos(this, &mt_stat)) { berrno be; set_eot(); @@ -1210,7 +1260,7 @@ bool DEVICE::fsf(int num) mt_com.mt_count = 1; while (num-- && !at_eot()) { Dmsg0(100, "Doing read before fsf\n"); - if ((stat = read(fd, (char *)rbuf, rbuf_len)) < 0) { + if ((stat = tape_read(fd, (char *)rbuf, rbuf_len)) < 0) { if (errno == ENOMEM) { /* tape record exceeds buf len */ stat = rbuf_len; /* This is OK */ /* @@ -1249,7 +1299,7 @@ bool DEVICE::fsf(int num) } Dmsg0(100, "Doing MTFSF\n"); - stat = ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { /* error => EOT */ berrno be; set_eot(); @@ -1323,7 +1373,7 @@ bool DEVICE::bsf(int num) file_size = 0; mt_com.mt_op = MTBSF; mt_com.mt_count = num; - stat = ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { berrno be; clrerror(MTBSF); @@ -1363,7 +1413,7 @@ bool DEVICE::fsr(int num) Dmsg1(29, "fsr %d\n", num); mt_com.mt_op = MTFSR; mt_com.mt_count = num; - stat = ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); if (stat == 0) { clear_eof(); block_num += num; @@ -1423,7 +1473,7 @@ bool DEVICE::bsr(int num) clear_eot(); mt_com.mt_op = MTBSR; mt_com.mt_count = num; - stat = ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { berrno be; clrerror(MTBSR); @@ -1529,7 +1579,7 @@ bool DEVICE::weof(int num) clear_eot(); mt_com.mt_op = MTWEOF; mt_com.mt_count = num; - stat = ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); if (stat == 0) { block_num = 0; file += num; @@ -1645,7 +1695,7 @@ void DEVICE::clrerror(int func) */ /* On some systems such as NetBSD, this clears all errors */ - ioctl(fd, MTIOCGET, (char *)&mt_stat); + tape_ioctl(fd, MTIOCGET, (char *)&mt_stat); /* Found on Linux */ #ifdef MTIOCLRERR @@ -1654,7 +1704,7 @@ void DEVICE::clrerror(int func) mt_com.mt_op = MTIOCLRERR; mt_com.mt_count = 1; /* Clear any error condition on the tape */ - ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); Dmsg0(200, "Did MTIOCLRERR\n"); } #endif @@ -1666,7 +1716,7 @@ void DEVICE::clrerror(int func) union mterrstat mt_errstat; Dmsg2(200, "Doing MTIOCERRSTAT errno=%d ERR=%s\n", dev_errno, strerror(dev_errno)); - ioctl(fd, MTIOCERRSTAT, (char *)&mt_errstat); + tape_ioctl(fd, MTIOCERRSTAT, (char *)&mt_errstat); } #endif @@ -1677,7 +1727,7 @@ void DEVICE::clrerror(int func) mt_com.mt_op = MTCSE; mt_com.mt_count = 1; /* Clear any error condition on the tape */ - ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); Dmsg0(200, "Did MTCSE\n"); } #endif @@ -1693,7 +1743,11 @@ void DEVICE::close() offline(); } if (fd >= 0) { - ::close(fd); + if (is_tape()) { + tape_close(fd); + } else { + ::close(fd); + } } else { Dmsg2(100, "device %s already closed vol=%s\n", print_name(), VolHdr.VolumeName); @@ -2096,13 +2150,13 @@ bool double_dev_wait_time(DEVICE *dev) void set_os_device_parameters(DEVICE *dev) { -#ifdef HAVE_LINUX_OS +#if defined(HAVE_LINUX_OS) || defined(HAVE_WIN32) struct mtop mt_com; if (dev->min_block_size == dev->max_block_size && dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSETBLK; mt_com.mt_count = 0; - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBLK); } mt_com.mt_op = MTSETDRVBUFFER; @@ -2113,7 +2167,7 @@ void set_os_device_parameters(DEVICE *dev) if (dev->has_cap(CAP_EOM)) { mt_com.mt_count |= MT_ST_FAST_MTEOM; } - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBLK); } } @@ -2126,13 +2180,13 @@ void set_os_device_parameters(DEVICE *dev) dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSETBSIZ; mt_com.mt_count = 0; - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBSIZ); } /* Get notified at logical end of tape */ mt_com.mt_op = MTEWARN; mt_com.mt_count = 1; - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTEWARN); } } @@ -2145,7 +2199,7 @@ void set_os_device_parameters(DEVICE *dev) dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSETBSIZ; mt_com.mt_count = 0; - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBSIZ); } } @@ -2158,7 +2212,7 @@ void set_os_device_parameters(DEVICE *dev) dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSRSZ; mt_com.mt_count = 0; - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSRSZ); } } @@ -2169,7 +2223,7 @@ void set_os_device_parameters(DEVICE *dev) static bool dev_get_os_pos(DEVICE *dev, struct mtget *mt_stat) { return dev->has_cap(CAP_MTIOCGET) && - ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 && + tape_ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 && mt_stat->mt_fileno >= 0; } diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 421afd0871..1b92dc0e94 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -217,9 +217,9 @@ bool free_volume(DEVICE *dev); void free_unused_volume(DCR *dcr); void create_volume_list(); void free_volume_list(); -void list_volumes(BSOCK *user); +void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg); bool is_volume_in_use(DCR *dcr); -void send_drive_reserve_messages(JCR *jcr, BSOCK *user); +void send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg); bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx); int search_res_for_device(RCTX &rctx); void release_msgs(JCR *jcr); @@ -234,7 +234,7 @@ bool begin_attribute_spool (JCR *jcr); bool discard_attribute_spool (JCR *jcr); bool commit_attribute_spool (JCR *jcr); bool write_block_to_spool_file (DCR *dcr); -void list_spool_stats (BSOCK *bs); +void list_spool_stats (void sendit(const char *msg, int len, void *sarg), void *arg); /* From wait.c */ int wait_for_sysop(DCR *dcr); diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index d10c0c0427..dad24e65de 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -254,18 +254,27 @@ void free_unused_volume(DCR *dcr) /* * List Volumes -- this should be moved to status.c */ -void list_volumes(BSOCK *user) +void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg) { VOLRES *vol; + char *msg; + int len; + + msg = (char *)get_pool_memory(PM_MESSAGE); + P(vol_list_lock); for (vol=(VOLRES *)vol_list->first(); vol; vol=(VOLRES *)vol_list->next(vol)) { if (vol->dev) { - bnet_fsend(user, "%s on device %s\n", vol->vol_name, vol->dev->print_name()); + len = Mmsg(msg, "%s on device %s\n", vol->vol_name, vol->dev->print_name()); + sendit(msg, len, arg); } else { - bnet_fsend(user, "%s\n", vol->vol_name); + len = Mmsg(msg, "%s\n", vol->vol_name); + sendit(msg, len, arg); } } V(vol_list_lock); + + free_pool_memory(msg); } /* Create the Volume list */ @@ -1046,7 +1055,7 @@ static void queue_reserve_message(JCR *jcr) /* * Send any reservation messages queued for this jcr */ -void send_drive_reserve_messages(JCR *jcr, BSOCK *user) +void send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg) { int i; alist *msgs; @@ -1061,7 +1070,8 @@ void send_drive_reserve_messages(JCR *jcr, BSOCK *user) for (i=msgs->size()-1; i >= 0; i--) { msg = (char *)msgs->get(i); if (msg) { - bnet_fsend(user, " %s", msg); + sendit(" ", 3, arg); + sendit(msg, strlen(msg), arg); } else { break; } diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index 5923279c02..e69fec331f 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -62,21 +62,31 @@ enum { RB_OK }; -void list_spool_stats(BSOCK *bs) +void list_spool_stats(void sendit(const char *msg, int len, void *sarg), void *arg) { - char ed1[30], ed2[30]; + char *msg, ed1[30], ed2[30]; + int len; + + msg = (char *)get_pool_memory(PM_MESSAGE); + if (spool_stats.data_jobs || spool_stats.max_data_size) { - bnet_fsend(bs, _("Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n"), + len = Mmsg(msg, _("Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n"), spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1), spool_stats.total_data_jobs, edit_uint64_with_commas(spool_stats.max_data_size, ed2)); + + sendit(msg, len, arg); } if (spool_stats.attr_jobs || spool_stats.max_attr_size) { - bnet_fsend(bs, _("Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n"), + len = Mmsg(msg, _("Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n"), spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1), spool_stats.total_attr_jobs, edit_uint64_with_commas(spool_stats.max_attr_size, ed2)); + + sendit(msg, len, arg); } + + free_pool_memory(msg); } bool begin_data_spool(DCR *dcr) diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index 404f47ae02..d483d41f45 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -39,69 +39,82 @@ static char DotStatusJob[] = "JobId=%d JobStatus=%c JobErrors=%d\n"; /* Forward referenced functions */ -static void send_blocked_status(JCR *jcr, DEVICE *dev); -static void list_terminated_jobs(void *arg); -static void list_running_jobs(BSOCK *user); -static void list_jobs_waiting_on_reservation(BSOCK *user); -static void sendit(const char *msg, int len, void *arg); -static const char *level_to_str(int level); +static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int len, void *sarg), void *arg); +static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg); +static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg); +static void list_jobs_waiting_on_reservation(void sendit(const char *msg, int len, void *sarg), void *arg); +#if defined(HAVE_WIN32) +static void win32_sendit(const char *msg, int len, void *arg); +#endif +static const char *level_to_str(int level); /* * Status command from Director */ -bool status_cmd(JCR *jcr) +bool do_status(void sendit(const char *msg, int len, void *sarg), void *arg) { DEVRES *device; AUTOCHANGER *changer; DEVICE *dev; - BSOCK *user = jcr->dir_bsock; char dt[MAX_TIME_LENGTH]; - char b1[35], b2[35], b3[35], b4[35]; + char *msg, b1[35], b2[35], b3[35], b4[35]; int bpb; + int len; + + msg = (char *)get_pool_memory(PM_MESSAGE); + + len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s\n"), + my_name, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER); + sendit(msg, len, arg); - bnet_fsend(user, _("\n%s Version: %s (%s) %s %s %s\n"), my_name, - VERSION, BDATE, HOST_OS, DISTNAME, DISTVER); bstrftime_nc(dt, sizeof(dt), daemon_start_time); - if (num_jobs_run == 1) { - bnet_fsend(user, _("Daemon started %s, 1 Job run since started.\n"), dt); - } - else { - bnet_fsend(user, _("Daemon started %s, %d Jobs run since started.\n"), dt, num_jobs_run); - } - bnet_fsend(user, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"), + + + len = Mmsg(msg, _("Daemon started %s, %d Job%s run since started.\n"), + dt, num_jobs_run, num_jobs_run == 1 ? "" : "s"); + sendit(msg, len, arg); + + len = Mmsg(msg, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"), edit_uint64_with_commas(sm_bytes, b1), edit_uint64_with_commas(sm_max_bytes, b2), edit_uint64_with_commas(sm_buffers, b3), edit_uint64_with_commas(sm_max_buffers, b4)); + sendit(msg, len, arg); /* * List running jobs */ - list_running_jobs(user); + list_running_jobs(sendit, arg); /* * List jobs stuck in reservation system */ - list_jobs_waiting_on_reservation(user); + list_jobs_waiting_on_reservation(sendit, arg); /* * List terminated jobs */ - list_terminated_jobs(user); + list_terminated_jobs(sendit, arg); /* * List devices */ - bnet_fsend(user, _("\nDevice status:\n")); + len = Mmsg(msg, _("\nDevice status:\n")); + sendit(msg, len, arg); + foreach_res(changer, R_AUTOCHANGER) { - bnet_fsend(user, _("Autochanger \"%s\" with devices:\n"), + len = Mmsg(msg, _("Autochanger \"%s\" with devices:\n"), changer->hdr.name); + sendit(msg, len, arg); + foreach_alist(device, changer->device) { if (device->dev) { - bnet_fsend(user, " %s\n", device->dev->print_name()); + len = Mmsg(msg, " %s\n", device->dev->print_name()); + sendit(msg, len, arg); } else { - bnet_fsend(user, " %s\n", device->hdr.name); + len = Mmsg(msg, " %s\n", device->hdr.name); + sendit(msg, len, arg); } } } @@ -109,24 +122,27 @@ bool status_cmd(JCR *jcr) dev = device->dev; if (dev && dev->is_open()) { if (dev->is_labeled()) { - bnet_fsend(user, _("Device %s is mounted with Volume=\"%s\" Pool=\"%s\"\n"), + len = Mmsg(msg, _("Device %s is mounted with Volume=\"%s\" Pool=\"%s\"\n"), dev->print_name(), dev->VolHdr.VolumeName, dev->pool_name[0]?dev->pool_name:"*unknown*"); + sendit(msg, len, arg); } else { - bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), + len = Mmsg(msg, _("Device %s open but no Bacula volume is mounted.\n"), dev->print_name()); + sendit(msg, len, arg); } - send_blocked_status(jcr, dev); + send_blocked_status(dev, sendit, arg); if (dev->can_append()) { bpb = dev->VolCatInfo.VolCatBlocks; if (bpb <= 0) { bpb = 1; } bpb = dev->VolCatInfo.VolCatBytes / bpb; - bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"), + len = Mmsg(msg, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"), edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1), edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), edit_uint64_with_commas(bpb, b3)); + sendit(msg, len, arg); } else { /* reading */ bpb = dev->VolCatInfo.VolCatReads; if (bpb <= 0) { @@ -137,28 +153,35 @@ bool status_cmd(JCR *jcr) } else { bpb = 0; } - bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"), + len = Mmsg(msg, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"), edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1), edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2), edit_uint64_with_commas(bpb, b3)); + sendit(msg, len, arg); } - bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"), + len = Mmsg(msg, _(" Positioned at File=%s Block=%s\n"), edit_uint64_with_commas(dev->file, b1), edit_uint64_with_commas(dev->block_num, b2)); + sendit(msg, len, arg); } else { if (dev) { - bnet_fsend(user, _("Device %s is not open.\n"), dev->print_name()); - } else { - bnet_fsend(user, _("Device \"%s\" is not open or does not exist.\n"), device->hdr.name); + len = Mmsg(msg, _("Device %s is not open.\n"), dev->print_name()); + sendit(msg, len, arg); + } else { + len = Mmsg(msg, _("Device \"%s\" is not open or does not exist.\n"), device->hdr.name); + sendit(msg, len, arg); } - send_blocked_status(jcr, dev); + send_blocked_status(dev, sendit, arg); } } - bnet_fsend(user, _("====\n\n")); - bnet_fsend(user, _("In Use Volume status:\n")); - list_volumes(user); - bnet_fsend(user, _("====\n\n")); + len = Mmsg(msg, _("====\n\n")); + sendit(msg, len, arg); + len = Mmsg(msg, _("In Use Volume status:\n")); + sendit(msg, len, arg); + list_volumes(sendit, arg); + len = Mmsg(msg, _("====\n\n")); + sendit(msg, len, arg); #ifdef xxx if (debug_level > 10) { @@ -168,41 +191,64 @@ bool status_cmd(JCR *jcr) } #endif - list_spool_stats(user); + list_spool_stats(sendit, arg); - bnet_sig(user, BNET_EOD); + free_pool_memory(msg); return true; } -static void send_blocked_status(JCR *jcr, DEVICE *dev) +static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int len, void *sarg), void *arg) { - BSOCK *user = jcr->dir_bsock; - DCR *dcr = jcr->dcr; + char *msg; + int len; + + msg = (char *)get_pool_memory(PM_MESSAGE); if (!dev) { - bnet_fsend(user, _("No DEVICE structure.\n\n")); + len = Mmsg(msg, _("No DEVICE structure.\n\n")); + sendit(msg, len, arg); return; } switch (dev->dev_blocked) { case BST_UNMOUNTED: - bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n")); + len = Mmsg(msg, _(" Device is BLOCKED. User unmounted.\n")); + sendit(msg, len, arg); break; case BST_UNMOUNTED_WAITING_FOR_SYSOP: - bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n")); + len = Mmsg(msg, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n")); + sendit(msg, len, arg); break; case BST_WAITING_FOR_SYSOP: - if (jcr->JobStatus == JS_WaitMount) { - bnet_fsend(user, _(" Device is BLOCKED waiting for mount of volume \"%s\".\n"), - dcr->VolumeName); - } else { - bnet_fsend(user, _(" Device is BLOCKED waiting for media.\n")); + { + dlist *dcrs = dev->attached_dcrs; + bool found_jcr = false; + + if (dcrs != NULL) { + DCR *dcr; + + for (dcr = (DCR *)dcrs->first(); dcr != NULL; dcr = (DCR *)dcrs->next(dcr)) { + if (dcr->jcr->JobStatus == JS_WaitMount) { + len = Mmsg(msg, _(" Device is BLOCKED waiting for mount of volume \"%s\".\n"), + dcr->VolumeName); + sendit(msg, len, arg); + found_jcr = true; + } + } + } + + if (!found_jcr) { + len = Mmsg(msg, _(" Device is BLOCKED waiting for media.\n")); + sendit(msg, len, arg); + } } break; case BST_DOING_ACQUIRE: - bnet_fsend(user, _(" Device is being initialized.\n")); + len = Mmsg(msg, _(" Device is being initialized.\n")); + sendit(msg, len, arg); break; case BST_WRITING_LABEL: - bnet_fsend(user, _(" Device is blocked labeling a Volume.\n")); + len = Mmsg(msg, _(" Device is blocked labeling a Volume.\n")); + sendit(msg, len, arg); break; default: break; @@ -210,68 +256,91 @@ static void send_blocked_status(JCR *jcr, DEVICE *dev) /* Send autochanger slot status */ if (dev->is_autochanger()) { if (dev->Slot) { - bnet_fsend(user, _(" Slot %d is loaded in drive %d.\n"), + len = Mmsg(msg, _(" Slot %d is loaded in drive %d.\n"), dev->Slot, dev->drive_index); + sendit(msg, len, arg); } else { - bnet_fsend(user, _(" Drive %d is not loaded.\n"), dev->drive_index); + len = Mmsg(msg, _(" Drive %d is not loaded.\n"), dev->drive_index); + sendit(msg, len, arg); } } if (debug_level > 1) { - bnet_fsend(user, _("Configured device capabilities:\n")); - bnet_fsend(user, "%sEOF ", dev->capabilities & CAP_EOF ? "" : "!"); - bnet_fsend(user, "%sBSR ", dev->capabilities & CAP_BSR ? "" : "!"); - bnet_fsend(user, "%sBSF ", dev->capabilities & CAP_BSF ? "" : "!"); - bnet_fsend(user, "%sFSR ", dev->capabilities & CAP_FSR ? "" : "!"); - bnet_fsend(user, "%sFSF ", dev->capabilities & CAP_FSF ? "" : "!"); - bnet_fsend(user, "%sEOM ", dev->capabilities & CAP_EOM ? "" : "!"); - bnet_fsend(user, "%sREM ", dev->capabilities & CAP_REM ? "" : "!"); - bnet_fsend(user, "%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!"); - bnet_fsend(user, "%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!"); - bnet_fsend(user, "%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!"); - bnet_fsend(user, "%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!"); - bnet_fsend(user, "%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!"); - bnet_fsend(user, "\n"); - - bnet_fsend(user, _("Device state:\n")); - bnet_fsend(user, "%sOPENED ", dev->is_open() ? "" : "!"); - bnet_fsend(user, "%sTAPE ", dev->is_tape() ? "" : "!"); - bnet_fsend(user, "%sLABEL ", dev->is_labeled() ? "" : "!"); - bnet_fsend(user, "%sMALLOC ", dev->state & ST_MALLOC ? "" : "!"); - bnet_fsend(user, "%sAPPEND ", dev->can_append() ? "" : "!"); - bnet_fsend(user, "%sREAD ", dev->can_read() ? "" : "!"); - bnet_fsend(user, "%sEOT ", dev->at_eot() ? "" : "!"); - bnet_fsend(user, "%sWEOT ", dev->state & ST_WEOT ? "" : "!"); - bnet_fsend(user, "%sEOF ", dev->at_eof() ? "" : "!"); - bnet_fsend(user, "%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!"); - bnet_fsend(user, "%sSHORT ", dev->state & ST_SHORT ? "" : "!"); - bnet_fsend(user, "%sMOUNTED ", dev->state & ST_MOUNTED ? "" : "!"); - bnet_fsend(user, "\n"); - bnet_fsend(user, _("num_writers=%d JobStatus=%c block=%d\n\n"), dev->num_writers, - jcr->JobStatus, dev->dev_blocked); - - bnet_fsend(user, _("Device parameters:\n")); - bnet_fsend(user, _("Archive name: %s Device name: %s\n"), dev->archive_name(), + len = Mmsg(msg, _("Configured device capabilities:\n")); + sendit(msg, len, arg); + + len = Mmsg(msg, "%sEOF %sBSR %sBSF %sFSR %sFSF %sEOM %sREM %sRACCESS %sAUTOMOUNT %sLABEL %sANONVOLS %sALWAYSOPEN\n", + dev->capabilities & CAP_EOF ? "" : "!", + dev->capabilities & CAP_BSR ? "" : "!", + dev->capabilities & CAP_BSF ? "" : "!", + dev->capabilities & CAP_FSR ? "" : "!", + dev->capabilities & CAP_FSF ? "" : "!", + dev->capabilities & CAP_EOM ? "" : "!", + dev->capabilities & CAP_REM ? "" : "!", + dev->capabilities & CAP_RACCESS ? "" : "!", + dev->capabilities & CAP_AUTOMOUNT ? "" : "!", + dev->capabilities & CAP_LABEL ? "" : "!", + dev->capabilities & CAP_ANONVOLS ? "" : "!", + dev->capabilities & CAP_ALWAYSOPEN ? "" : "!"); + sendit(msg, len, arg); + + len = Mmsg(msg, _("Device state:\n")); + sendit(msg, len, arg); + + len = Mmsg(msg, "%sOPENED %sTAPE %sLABEL %sMALLOC %sAPPEND %sREAD %sEOT %sWEOT %sEOF %sNEXTVOL %sSHORT %sMOUNTED\n", + dev->is_open() ? "" : "!", + dev->is_tape() ? "" : "!", + dev->is_labeled() ? "" : "!", + dev->state & ST_MALLOC ? "" : "!", + dev->can_append() ? "" : "!", + dev->can_read() ? "" : "!", + dev->at_eot() ? "" : "!", + dev->state & ST_WEOT ? "" : "!", + dev->at_eof() ? "" : "!", + dev->state & ST_NEXTVOL ? "" : "!", + dev->state & ST_SHORT ? "" : "!", + dev->state & ST_MOUNTED ? "" : "!"); + sendit(msg, len, arg); + + len = Mmsg(msg, _("num_writers=%d block=%d\n\n"), dev->num_writers, dev->dev_blocked); + sendit(msg, len, arg); + + len = Mmsg(msg, _("Device parameters:\n")); + sendit(msg, len, arg); + + len = Mmsg(msg, _("Archive name: %s Device name: %s\n"), dev->archive_name(), dev->name()); - bnet_fsend(user, _("File=%u block=%u\n"), dev->file, dev->block_num); - bnet_fsend(user, _("Min block=%u Max block=%u\n"), dev->min_block_size, dev->max_block_size); + sendit(msg, len, arg); + + len = Mmsg(msg, _("File=%u block=%u\n"), dev->file, dev->block_num); + sendit(msg, len, arg); + + len = Mmsg(msg, _("Min block=%u Max block=%u\n"), dev->min_block_size, dev->max_block_size); + sendit(msg, len, arg); } + free_pool_memory(msg); } -static void list_running_jobs(BSOCK *user) +static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg) { bool found = false; int bps, sec; JCR *jcr; DCR *dcr, *rdcr; char JobName[MAX_NAME_LENGTH]; - char b1[30], b2[30], b3[30]; + char *msg, b1[30], b2[30], b3[30]; + int len; + + msg = (char *)get_pool_memory(PM_MESSAGE); + + len = Mmsg(msg, _("\nRunning Jobs:\n")); + sendit(msg, len, arg); - bnet_fsend(user, _("\nRunning Jobs:\n")); foreach_jcr(jcr) { if (jcr->JobStatus == JS_WaitFD) { - bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"), + len = Mmsg(msg, _("%s Job %s waiting for Client connection.\n"), job_type_to_str(jcr->JobType), jcr->Job); + sendit(msg, len, arg); } dcr = jcr->dcr; rdcr = jcr->read_dcr; @@ -285,7 +354,7 @@ static void list_running_jobs(BSOCK *user) } } if (rdcr && rdcr->device) { - bnet_fsend(user, _("Reading: %s %s job %s JobId=%d Volume=\"%s\"\n" + len = Mmsg(msg, _("Reading: %s %s job %s JobId=%d Volume=\"%s\"\n" " pool=\"%s\" device=\"%s\"\n"), job_level_to_str(jcr->JobLevel), job_type_to_str(jcr->JobType), @@ -295,9 +364,10 @@ static void list_running_jobs(BSOCK *user) rdcr->pool_name, rdcr->dev?rdcr->dev->print_name(): rdcr->device->device_name); + sendit(msg, len, arg); } if (dcr && dcr->device) { - bnet_fsend(user, _("Writing: %s %s job %s JobId=%d Volume=\"%s\"\n" + len = Mmsg(msg, _("Writing: %s %s job %s JobId=%d Volume=\"%s\"\n" " pool=\"%s\" device=\"%s\"\n"), job_level_to_str(jcr->JobLevel), job_type_to_str(jcr->JobType), @@ -307,27 +377,29 @@ static void list_running_jobs(BSOCK *user) dcr->pool_name, dcr->dev?dcr->dev->print_name(): dcr->device->device_name); - bnet_fsend(user, _(" spooling=%d despooling=%d despool_wait=%d\n"), - dcr->spooling, dcr->despooling, dcr->despool_wait); + sendit(msg, len, arg); } sec = time(NULL) - jcr->run_time; if (sec <= 0) { sec = 1; } bps = jcr->JobBytes / sec; - bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"), + len = Mmsg(msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"), edit_uint64_with_commas(jcr->JobFiles, b1), edit_uint64_with_commas(jcr->JobBytes, b2), edit_uint64_with_commas(bps, b3)); + sendit(msg, len, arg); found = true; #ifdef DEBUG if (jcr->file_bsock) { - bnet_fsend(user, _(" FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n"), + len = Mmsg(msg, _(" FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n"), edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1), jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no, jcr->file_bsock->fd); + sendit(msg, len, arg); } else { - bnet_fsend(user, _(" FDSocket closed\n")); + len = Mmsg(msg, _(" FDSocket closed\n")); + sendit(msg, len, arg); } #endif } @@ -335,29 +407,37 @@ static void list_running_jobs(BSOCK *user) endeach_jcr(jcr); if (!found) { - bnet_fsend(user, _("No Jobs running.\n")); + len = Mmsg(msg, _("No Jobs running.\n")); + sendit(msg, len, arg); } - bnet_fsend(user, _("====\n")); + len = Mmsg(msg, _("====\n")); + sendit(msg, len, arg); + + free_pool_memory(msg); } -static void list_jobs_waiting_on_reservation(BSOCK *user) +static void list_jobs_waiting_on_reservation(void sendit(const char *msg, int len, void *sarg), void *arg) { JCR *jcr; + char *msg; + + msg = _("\nJobs waiting to reserve a drive:\n"); + sendit(msg, strlen(msg), arg); - bnet_fsend(user, _("\nJobs waiting to reserve a drive:\n")); foreach_jcr(jcr) { if (!jcr->reserve_msgs) { continue; } - send_drive_reserve_messages(jcr, user); + send_drive_reserve_messages(jcr, sendit, arg); } endeach_jcr(jcr); - bnet_fsend(user, _("====\n")); + msg = _("====\n"); + sendit(msg, strlen(msg), arg); } -static void list_terminated_jobs(void *arg) +static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg) { char dt[MAX_TIME_LENGTH], b1[30], b2[30]; char level[10]; @@ -484,7 +564,7 @@ static const char *level_to_str(int level) /* * Send to Director */ -static void sendit(const char *msg, int len, void *arg) +static void bsock_sendit(const char *msg, int len, void *arg) { BSOCK *user = (BSOCK *)arg; @@ -493,6 +573,20 @@ static void sendit(const char *msg, int len, void *arg) bnet_send(user); } +/* + * Status command from Director + */ +bool status_cmd(JCR *jcr) +{ + BSOCK *user = jcr->dir_bsock; + + bnet_fsend(user, "\n"); + do_status(bsock_sendit, (void *)user); + + bnet_sig(user, BNET_EOD); + return 1; +} + /* * .status command from Director */ @@ -536,3 +630,94 @@ bool qstatus_cmd(JCR *jcr) bnet_sig(dir, BNET_EOD); return true; } + +#if defined(HAVE_WIN32) +int bacstat = 0; + +struct s_win32_arg { + HWND hwnd; + int idlist; +}; + +/* + * Put message in Window List Box + */ +static void win32_sendit(const char *msg, int len, void *marg) +{ + struct s_win32_arg *arg = (struct s_win32_arg *)marg; + + if (len > 0 && msg[len-1] == '\n') { + // when compiling with visual studio some strings are read-only + // and cause access violations. So we creat a tmp copy. + char *_msg = (char *)alloca(len); + bstrncpy(_msg, msg, len); + msg = _msg; + } + SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg); + +} + +void FillStatusBox(HWND hwnd, int idlist) +{ + struct s_win32_arg arg; + + arg.hwnd = hwnd; + arg.idlist = idlist; + + /* Empty box */ + for ( ; SendDlgItemMessage(hwnd, idlist, LB_DELETESTRING, 0, (LONG)0) > 0; ) + { } + do_status(win32_sendit, (void *)&arg); +} + +char *bac_status(char *buf, int buf_len) +{ + JCR *njcr; + const char *termstat = _("Bacula Idle"); + struct s_last_job *job; + int stat = 0; /* Idle */ + + if (!last_jobs) { + goto done; + } + Dmsg0(1000, "Begin bac_status jcr loop.\n"); + foreach_jcr(njcr) { + if (njcr->JobId != 0) { + stat = JS_Running; + termstat = _("Bacula Running"); + break; + } + } + endeach_jcr(njcr); + + if (stat != 0) { + goto done; + } + if (last_jobs->size() > 0) { + job = (struct s_last_job *)last_jobs->last(); + stat = job->JobStatus; + switch (job->JobStatus) { + case JS_Canceled: + termstat = _("Last Job Canceled"); + break; + case JS_ErrorTerminated: + case JS_FatalError: + termstat = _("Last Job Failed"); + break; + default: + if (job->Errors) { + termstat = _("Last Job had Warnings"); + } + break; + } + } + Dmsg0(1000, "End bac_status jcr loop.\n"); +done: + bacstat = stat; + if (buf) { + bstrncpy(buf, termstat, buf_len); + } + return buf; +} + +#endif /* HAVE_WIN32 */ diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 0889a761f7..b72b9208fa 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -84,6 +84,10 @@ static void usage() * Main Bacula Unix Storage Daemon * */ +#if defined(HAVE_WIN32) +#define main BaculaMain +#endif + int main (int argc, char *argv[]) { int ch; diff --git a/bacula/src/stored/stored.h b/bacula/src/stored/stored.h index 7ae3dffe94..34569fff88 100644 --- a/bacula/src/stored/stored.h +++ b/bacula/src/stored/stored.h @@ -29,7 +29,7 @@ # ifdef HAVE_SYS_MTIO_H # include # else -# ifdef HAVE_SYS_TAPE +# ifdef HAVE_SYS_TAPE_H # include # endif # endif diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index e1677fcc7a..50b7f9612b 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -30,7 +30,7 @@ GETTEXT_LIBS = @LIBINTL@ OPENSSL_INC = @OPENSSL_INC@ OPENSSL_LIBS = @OPENSSL_LIBS@ -FINDOBJS = testfind.o +FINDOBJS = testfind.o dird_conf.o inc_conf.o run_conf.o # these are the objects that are changed by the .configure process EXTRAOBJS = @OBJLIST@ @@ -71,6 +71,15 @@ fstype: fstype.o ../lib/libbac.a ../findlib/libfind.a drivetype: drivetype.o ../lib/libbac.a ../findlib/libfind.a $(CXX) $(LDFLAGS) -L../lib -L../findlib -o $@ drivetype.o -lfind -lbac -lm $(DLIB) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) +dird_conf.o: ../dird/dird_conf.c + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< + +run_conf.o: ../dird/run_conf.c + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< + +inc_conf.o: ../dird/inc_conf.c + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< + testfind: ../findlib/libfind.a ../lib/libbac.a $(FINDOBJS) $(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ $(FINDOBJS) \ $(DLIB) -lfind -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index fe4c21a2e6..3b7876912f 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -17,13 +17,12 @@ */ #include "bacula.h" +#include "dird/dird.h" #include "findlib/find.h" #if defined(HAVE_WIN32) -int win32_client = 1; -#else -int win32_client = 0; +#define isatty(fd) (fd==0) #endif /* Dummy functions */ @@ -42,6 +41,8 @@ static JCR *jcr; static int print_file(FF_PKT *ff, void *pkt, bool); static void count_files(FF_PKT *ff); +static bool copy_fileset(FF_PKT *ff, JCR *jcr); +static void set_options(findFOPTS *fo, const char *opts); static void usage() { @@ -50,9 +51,8 @@ static void usage() "Usage: testfind [-d debug_level] [-] [pattern1 ...]\n" " -a print extended attributes (Win32 debug)\n" " -dnn set debug level to nn\n" -" -e specify file of exclude patterns\n" -" -i specify file of include patterns\n" -" - read pattern(s) from stdin\n" +" -c specify config file containing FileSet resources\n" +" -f specify which FileSet to use\n" " -? print this message.\n" "\n" "Patterns are used for file inclusion -- normally directories.\n" @@ -71,22 +71,26 @@ int main (int argc, char *const *argv) { FF_PKT *ff; - char name[1000]; - int i, ch, hard_links; - char *inc = NULL; - char *exc = NULL; - FILE *fd; + char *configfile = "bacula-dir.conf"; + char *fileset_name = "Windows-Full-Set"; + int ch, hard_links; + + OSDependentInit(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); - while ((ch = getopt(argc, argv, "ad:e:i:?")) != -1) { + while ((ch = getopt(argc, argv, "ac:d:f:?")) != -1) { switch (ch) { case 'a': /* print extended attributes *debug* */ attrs = 1; break; + case 'c': /* set debug level */ + configfile = optarg; + break; + case 'd': /* set debug level */ debug_level = atoi(optarg); if (debug_level <= 0) { @@ -94,12 +98,8 @@ main (int argc, char *const *argv) } break; - case 'e': /* exclude patterns */ - exc = optarg; - break; - - case 'i': /* include patterns */ - inc = optarg; + case 'f': /* exclude patterns */ + fileset_name = optarg; break; case '?': @@ -108,56 +108,105 @@ main (int argc, char *const *argv) } } + argc -= optind; argv += optind; - jcr = new_jcr(sizeof(JCR), NULL); + parse_config(configfile); - ff = init_find_files(); - if (argc == 0 && !inc) { - add_fname_to_include_list(ff, 0, "/"); /* default to / */ - } else { - for (i=0; i < argc; i++) { - if (strcmp(argv[i], "-") == 0) { - while (fgets(name, sizeof(name)-1, stdin)) { - strip_trailing_junk(name); - add_fname_to_include_list(ff, 0, name); - } - continue; - } - add_fname_to_include_list(ff, 0, argv[i]); - } + MSGS *msg; + + foreach_res(msg, R_MSGS) + { + init_msg(NULL, msg); } - if (inc) { - fd = fopen(inc, "r"); - if (!fd) { - printf(_("Could not open include file: %s\n"), inc); - exit(1); - } - while (fgets(name, sizeof(name)-1, fd)) { - strip_trailing_junk(name); - add_fname_to_include_list(ff, 0, name); + + jcr = new_jcr(sizeof(JCR), NULL); + jcr->fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name); + + if (jcr->fileset == NULL) { + fprintf(stderr, "%s: Fileset not found\n", fileset_name); + + FILESET *var; + + fprintf(stderr, "Valid FileSets:\n"); + + foreach_res(var, R_FILESET) { + fprintf(stderr, " %s\n", var->hdr.name); } - fclose(fd); + + exit(1); } - if (exc) { - fd = fopen(exc, "r"); - if (!fd) { - printf(_("Could not open exclude file: %s\n"), exc); - exit(1); + ff = init_find_files(); + + copy_fileset(ff, jcr); + + find_files(jcr, ff, print_file, NULL); + + free_jcr(jcr); + free_config_resources(); + term_last_jobs_list(); + + /* Clean up fileset */ + findFILESET *fileset = ff->fileset; + + if (fileset) { + int i, j, k; + /* Delete FileSet Include lists */ + for (i=0; iinclude_list.size(); i++) { + findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i); + for (j=0; jopts_list.size(); j++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + for (k=0; kregex.size(); k++) { + regfree((regex_t *)fo->regex.get(k)); + } + fo->regex.destroy(); + fo->regexdir.destroy(); + fo->regexfile.destroy(); + fo->wild.destroy(); + fo->wilddir.destroy(); + fo->wildfile.destroy(); + fo->wildbase.destroy(); + fo->fstype.destroy(); + fo->drivetype.destroy(); + if (fo->reader) { + free(fo->reader); + } + if (fo->writer) { + free(fo->writer); + } + } + incexe->opts_list.destroy(); + incexe->name_list.destroy(); } - while (fgets(name, sizeof(name)-1, fd)) { - strip_trailing_junk(name); - add_fname_to_exclude_list(ff, name); + fileset->include_list.destroy(); + + /* Delete FileSet Exclude lists */ + for (i=0; iexclude_list.size(); i++) { + findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); + for (j=0; jopts_list.size(); j++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + fo->regex.destroy(); + fo->regexdir.destroy(); + fo->regexfile.destroy(); + fo->wild.destroy(); + fo->wilddir.destroy(); + fo->wildfile.destroy(); + fo->wildbase.destroy(); + fo->fstype.destroy(); + fo->drivetype.destroy(); + } + incexe->opts_list.destroy(); + incexe->name_list.destroy(); } - fclose(fd); + fileset->exclude_list.destroy(); + free(fileset); } - match_files(jcr, ff, print_file, NULL); - term_include_exclude_files(ff); + ff->fileset = NULL; hard_links = term_find_files(ff); - printf(_("" + printf(_("\n" "Total files : %d\n" "Max file length: %d\n" "Max path length: %d\n" @@ -167,10 +216,11 @@ main (int argc, char *const *argv) num_files, max_file_len, max_path_len, trunc_fname, trunc_path, hard_links); - free_jcr(jcr); - close_memory_pool(); - sm_dump(false); - exit(0); + term_msg(); + + close_memory_pool(); + sm_dump(false); + exit(0); } static int print_file(FF_PKT *ff, void *pkt, bool top_level) @@ -213,6 +263,7 @@ static int print_file(FF_PKT *ff, void *pkt, bool top_level) case FT_NORECURSE: case FT_NOFSCHG: case FT_INVALIDFS: + case FT_INVALIDDT: case FT_DIREND: if (debug_level) { char errmsg[100] = ""; @@ -222,6 +273,8 @@ static int print_file(FF_PKT *ff, void *pkt, bool top_level) bstrncpy(errmsg, _("\t[will not descend: file system change not allowed]"), sizeof(errmsg)); } else if (ff->type == FT_INVALIDFS) { bstrncpy(errmsg, _("\t[will not descend: disallowed file system]"), sizeof(errmsg)); + } else if (ff->type == FT_INVALIDDT) { + bstrncpy(errmsg, _("\t[will not descend: disallowed drive type]"), sizeof(errmsg)); } printf("%s%s%s\n", (debug_level > 1 ? "Dir: " : ""), ff->fname, errmsg); } @@ -341,3 +394,230 @@ static void count_files(FF_PKT *ar) } bool python_set_prog(JCR*, char const*) { return false; } + +static bool copy_fileset(FF_PKT *ff, JCR *jcr) +{ + FILESET *jcr_fileset = jcr->fileset; + int num; + bool include = true; + + findFILESET *fileset; + findFOPTS *current_opts; + + fileset = (findFILESET *)malloc(sizeof(findFILESET)); + memset(fileset, 0, sizeof(findFILESET)); + ff->fileset = fileset; + + fileset->state = state_none; + fileset->include_list.init(1, true); + fileset->exclude_list.init(1, true); + + for ( ;; ) { + if (include) { + num = jcr_fileset->num_includes; + } else { + num = jcr_fileset->num_excludes; + } + for (int i=0; iinclude_items[i]; + + /* New include */ + fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE)); + memset(fileset->incexe, 0, sizeof(findINCEXE)); + fileset->incexe->opts_list.init(1, true); + fileset->incexe->name_list.init(1, true); + fileset->include_list.append(fileset->incexe); + } else { + ie = jcr_fileset->exclude_items[i]; + + /* New exclude */ + fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE)); + memset(fileset->incexe, 0, sizeof(findINCEXE)); + fileset->incexe->opts_list.init(1, true); + fileset->incexe->name_list.init(1, true); + fileset->exclude_list.append(fileset->incexe); + } + + for (j=0; jnum_opts; j++) { + FOPTS *fo = ie->opts_list[j]; + + current_opts = (findFOPTS *)malloc(sizeof(findFOPTS)); + memset(current_opts, 0, sizeof(findFOPTS)); + fileset->incexe->current_opts = current_opts; + fileset->incexe->opts_list.append(current_opts); + + current_opts->regex.init(1, true); + current_opts->regexdir.init(1, true); + current_opts->regexfile.init(1, true); + current_opts->wild.init(1, true); + current_opts->wilddir.init(1, true); + current_opts->wildfile.init(1, true); + current_opts->wildbase.init(1, true); + current_opts->fstype.init(1, true); + current_opts->drivetype.init(1, true); + + set_options(current_opts, fo->opts); + + for (k=0; kregex.size(); k++) { + // bnet_fsend(fd, "R %s\n", fo->regex.get(k)); + current_opts->regex.append(bstrdup((const char *)fo->regex.get(k))); + } + for (k=0; kregexdir.size(); k++) { + // bnet_fsend(fd, "RD %s\n", fo->regexdir.get(k)); + current_opts->regexdir.append(bstrdup((const char *)fo->regexdir.get(k))); + } + for (k=0; kregexfile.size(); k++) { + // bnet_fsend(fd, "RF %s\n", fo->regexfile.get(k)); + current_opts->regexfile.append(bstrdup((const char *)fo->regexfile.get(k))); + } + for (k=0; kwild.size(); k++) { + current_opts->wild.append(bstrdup((const char *)fo->wild.get(k))); + } + for (k=0; kwilddir.size(); k++) { + current_opts->wilddir.append(bstrdup((const char *)fo->wilddir.get(k))); + } + for (k=0; kwildfile.size(); k++) { + current_opts->wildfile.append(bstrdup((const char *)fo->wildfile.get(k))); + } + for (k=0; kwildbase.size(); k++) { + current_opts->wildbase.append(bstrdup((const char *)fo->wildbase.get(k))); + } + for (k=0; kfstype.size(); k++) { + current_opts->fstype.append(bstrdup((const char *)fo->fstype.get(k))); + } + for (k=0; kdrivetype.size(); k++) { + current_opts->drivetype.append(bstrdup((const char *)fo->drivetype.get(k))); + } + if (fo->reader) { + current_opts->reader = bstrdup(fo->reader); + } + if (fo->writer) { + current_opts->writer = bstrdup(fo->writer); + } + } + + for (j=0; jname_list.size(); j++) { + fileset->incexe->name_list.append(bstrdup((const char *)ie->name_list.get(j))); + } + } + + if (!include) { /* If we just did excludes */ + break; /* all done */ + } + + include = false; /* Now do excludes */ + } + + return true; +} + +static void set_options(findFOPTS *fo, const char *opts) +{ + int j; + const char *p; + + for (p=opts; *p; p++) { + switch (*p) { + case 'a': /* alway replace */ + case '0': /* no option */ + break; + case 'e': + fo->flags |= FO_EXCLUDE; + break; + case 'f': + fo->flags |= FO_MULTIFS; + break; + case 'h': /* no recursion */ + fo->flags |= FO_NO_RECURSION; + break; + case 'H': /* no hard link handling */ + fo->flags |= FO_NO_HARDLINK; + break; + case 'i': + fo->flags |= FO_IGNORECASE; + break; + case 'M': /* MD5 */ + fo->flags |= FO_MD5; + break; + case 'n': + fo->flags |= FO_NOREPLACE; + break; + case 'p': /* use portable data format */ + fo->flags |= FO_PORTABLE; + break; + case 'R': /* Resource forks and Finder Info */ + fo->flags |= FO_HFSPLUS; + case 'r': /* read fifo */ + fo->flags |= FO_READFIFO; + break; + case 'S': + switch(*(p + 1)) { + case ' ': + /* Old director did not specify SHA variant */ + fo->flags |= FO_SHA1; + break; + case '1': + fo->flags |= FO_SHA1; + p++; + break; +#ifdef HAVE_SHA2 + case '2': + fo->flags |= FO_SHA256; + p++; + break; + case '3': + fo->flags |= FO_SHA512; + p++; + break; +#endif + default: + /* Automatically downgrade to SHA-1 if an unsupported + * SHA variant is specified */ + fo->flags |= FO_SHA1; + p++; + break; + } + break; + case 's': + fo->flags |= FO_SPARSE; + break; + case 'm': + fo->flags |= FO_MTIMEONLY; + break; + case 'k': + fo->flags |= FO_KEEPATIME; + break; + case 'A': + fo->flags |= FO_ACL; + break; + case 'V': /* verify options */ + /* Copy Verify Options */ + for (j=0; *p && *p != ':'; p++) { + fo->VerifyOpts[j] = *p; + if (j < (int)sizeof(fo->VerifyOpts) - 1) { + j++; + } + } + fo->VerifyOpts[j] = 0; + break; + case 'w': + fo->flags |= FO_IF_NEWER; + break; + case 'W': + fo->flags |= FO_ENHANCEDWILD; + break; + case 'Z': /* gzip compression */ + fo->flags |= FO_GZIP; + fo->GZIP_level = *++p - '0'; + Dmsg1(200, "Compression level=%d\n", fo->GZIP_level); + break; + default: + Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p); + break; + } + } +} -- 2.39.2