From b75828273c5c05a28b8443be909c892275dd6857 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 15 Aug 2007 16:54:21 +0000 Subject: [PATCH] kes Update AUTHORs file kes Increase the default max concurrent jobs to 20 in FD and SD to correspond with the default .conf files. kes Rewrite the Win32 service routines. This eliminates the 3 copies some different, of the same file created by RN when porting the Win32 SD and Dir. kes Rearrange some of the Win32 directories and the placement of the files in them. kes Set DEVELOPER flag in version.h git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5358 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/AUTHORS | 2 + bacula/src/filed/filed_conf.c | 2 +- bacula/src/stored/stored_conf.c | 2 +- bacula/src/version.h | 6 +- bacula/src/win32/Makefile | 5 +- bacula/src/win32/Makefile.inc.in | 37 +- bacula/src/win32/Makefile.rules | 1 + bacula/src/win32/compat/getopt.c | 2 +- bacula/src/win32/dird/Makefile | 17 +- bacula/src/win32/dird/bacula.rc | 1 + bacula/src/win32/dird/main.cpp | 36 + bacula/src/win32/dird/service.cpp | 36 + .../{stored/baculasd/winstat.h => dird/who.h} | 50 +- bacula/src/win32/dird/winbacula.h | 67 -- bacula/src/win32/dird/winmain.cpp | 287 ------- bacula/src/win32/dird/winres.rc | 76 -- bacula/src/win32/dird/winservice.cpp | 521 ------------- bacula/src/win32/dird/winservice.h | 69 -- bacula/src/win32/filed/Makefile | 13 +- bacula/src/win32/filed/bacula.rc | 1 + bacula/src/win32/filed/main.cpp | 36 + bacula/src/win32/filed/service.cpp | 36 + bacula/src/win32/filed/trayMonitor.cpp | 36 + bacula/src/win32/filed/who.h | 43 ++ bacula/src/win32/filed/winservice.cpp | 731 ------------------ bacula/src/win32/libbac/Makefile | 1 + .../{winabout.cpp => aboutDialog.cpp} | 71 +- .../libwin32/{winabout.h => aboutDialog.h} | 36 +- bacula/src/win32/libwin32/bacula.rc | 1 - .../{filed/winmain.cpp => libwin32/main.cpp} | 237 +++--- bacula/src/win32/libwin32/protos.h | 62 ++ bacula/src/win32/libwin32/res.h | 51 ++ bacula/src/win32/libwin32/service.cpp | 595 ++++++++++++++ bacula/src/win32/libwin32/statusDialog.cpp | 170 ++++ .../libwin32/{winstat.h => statusDialog.h} | 31 +- bacula/src/win32/libwin32/trayMonitor.cpp | 261 +++++++ bacula/src/win32/libwin32/trayMonitor.h | 68 ++ .../baculasd/winabout.h => libwin32/win32.h} | 49 +- bacula/src/win32/libwin32/winbacula.h | 70 -- bacula/src/win32/libwin32/winres.h | 24 - bacula/src/win32/libwin32/winres.rc | 149 ---- bacula/src/win32/libwin32/winservice.h | 83 -- bacula/src/win32/libwin32/winstat.cpp | 183 ----- bacula/src/win32/libwin32/wintray.cpp | 341 -------- bacula/src/win32/libwin32/wintray.h | 13 +- bacula/src/win32/stored/Makefile | 21 +- bacula/src/win32/stored/bacula.rc | 1 + .../stored/{baculasd => }/baculasd.vcproj | 0 .../win32/stored/baculasd/bacula-sd.manifest | 21 - bacula/src/win32/stored/baculasd/bacula.bmp | Bin 3126 -> 0 bytes bacula/src/win32/stored/baculasd/bacula.ico | Bin 766 -> 0 bytes bacula/src/win32/stored/baculasd/bacula.rc | 1 - bacula/src/win32/stored/baculasd/error.ico | Bin 766 -> 0 bytes bacula/src/win32/stored/baculasd/idle.ico | Bin 766 -> 0 bytes bacula/src/win32/stored/baculasd/running.ico | Bin 766 -> 0 bytes bacula/src/win32/stored/baculasd/saving.ico | Bin 766 -> 0 bytes bacula/src/win32/stored/baculasd/warn.ico | Bin 766 -> 0 bytes bacula/src/win32/stored/baculasd/winabout.cpp | 80 -- bacula/src/win32/stored/baculasd/winbacula.h | 70 -- bacula/src/win32/stored/baculasd/winmain.cpp | 338 -------- bacula/src/win32/stored/baculasd/winres.h | 24 - bacula/src/win32/stored/baculasd/winres.rc | 149 ---- .../src/win32/stored/baculasd/winservice.cpp | 571 -------------- bacula/src/win32/stored/baculasd/winservice.h | 79 -- bacula/src/win32/stored/baculasd/winstat.cpp | 182 ----- bacula/src/win32/stored/baculasd/wintray.cpp | 341 -------- bacula/src/win32/stored/baculasd/wintray.h | 87 --- bacula/src/win32/stored/main.cpp | 36 + bacula/src/win32/stored/mtops.cpp | 42 +- bacula/src/win32/stored/service.cpp | 36 + bacula/src/win32/stored/trayMonitor.cpp | 36 + bacula/src/win32/stored/who.h | 44 ++ bacula/src/win32/winapi.h | 15 +- bacula/technotes-2.1 | 15 +- 74 files changed, 1915 insertions(+), 4883 deletions(-) create mode 100644 bacula/src/win32/dird/bacula.rc create mode 100644 bacula/src/win32/dird/main.cpp create mode 100644 bacula/src/win32/dird/service.cpp rename bacula/src/win32/{stored/baculasd/winstat.h => dird/who.h} (59%) delete mode 100644 bacula/src/win32/dird/winbacula.h delete mode 100644 bacula/src/win32/dird/winmain.cpp delete mode 100644 bacula/src/win32/dird/winres.rc delete mode 100644 bacula/src/win32/dird/winservice.cpp delete mode 100644 bacula/src/win32/dird/winservice.h create mode 100644 bacula/src/win32/filed/bacula.rc create mode 100644 bacula/src/win32/filed/main.cpp create mode 100644 bacula/src/win32/filed/service.cpp create mode 100644 bacula/src/win32/filed/trayMonitor.cpp create mode 100644 bacula/src/win32/filed/who.h delete mode 100644 bacula/src/win32/filed/winservice.cpp rename bacula/src/win32/libwin32/{winabout.cpp => aboutDialog.cpp} (63%) rename bacula/src/win32/libwin32/{winabout.h => aboutDialog.h} (68%) delete mode 100644 bacula/src/win32/libwin32/bacula.rc rename bacula/src/win32/{filed/winmain.cpp => libwin32/main.cpp} (52%) create mode 100644 bacula/src/win32/libwin32/protos.h create mode 100644 bacula/src/win32/libwin32/res.h create mode 100644 bacula/src/win32/libwin32/service.cpp create mode 100644 bacula/src/win32/libwin32/statusDialog.cpp rename bacula/src/win32/libwin32/{winstat.h => statusDialog.h} (69%) create mode 100644 bacula/src/win32/libwin32/trayMonitor.cpp create mode 100644 bacula/src/win32/libwin32/trayMonitor.h rename bacula/src/win32/{stored/baculasd/winabout.h => libwin32/win32.h} (61%) delete mode 100644 bacula/src/win32/libwin32/winbacula.h delete mode 100644 bacula/src/win32/libwin32/winres.h delete mode 100644 bacula/src/win32/libwin32/winres.rc delete mode 100644 bacula/src/win32/libwin32/winservice.h delete mode 100644 bacula/src/win32/libwin32/winstat.cpp delete mode 100644 bacula/src/win32/libwin32/wintray.cpp create mode 100644 bacula/src/win32/stored/bacula.rc rename bacula/src/win32/stored/{baculasd => }/baculasd.vcproj (100%) delete mode 100644 bacula/src/win32/stored/baculasd/bacula-sd.manifest delete mode 100644 bacula/src/win32/stored/baculasd/bacula.bmp delete mode 100644 bacula/src/win32/stored/baculasd/bacula.ico delete mode 100644 bacula/src/win32/stored/baculasd/bacula.rc delete mode 100644 bacula/src/win32/stored/baculasd/error.ico delete mode 100644 bacula/src/win32/stored/baculasd/idle.ico delete mode 100644 bacula/src/win32/stored/baculasd/running.ico delete mode 100644 bacula/src/win32/stored/baculasd/saving.ico delete mode 100644 bacula/src/win32/stored/baculasd/warn.ico delete mode 100644 bacula/src/win32/stored/baculasd/winabout.cpp delete mode 100644 bacula/src/win32/stored/baculasd/winbacula.h delete mode 100644 bacula/src/win32/stored/baculasd/winmain.cpp delete mode 100644 bacula/src/win32/stored/baculasd/winres.h delete mode 100644 bacula/src/win32/stored/baculasd/winres.rc delete mode 100644 bacula/src/win32/stored/baculasd/winservice.cpp delete mode 100644 bacula/src/win32/stored/baculasd/winservice.h delete mode 100644 bacula/src/win32/stored/baculasd/winstat.cpp delete mode 100644 bacula/src/win32/stored/baculasd/wintray.cpp delete mode 100644 bacula/src/win32/stored/baculasd/wintray.h create mode 100644 bacula/src/win32/stored/main.cpp create mode 100644 bacula/src/win32/stored/service.cpp create mode 100644 bacula/src/win32/stored/trayMonitor.cpp create mode 100644 bacula/src/win32/stored/who.h diff --git a/bacula/AUTHORS b/bacula/AUTHORS index 9764f56489..93575d2d9e 100644 --- a/bacula/AUTHORS +++ b/bacula/AUTHORS @@ -18,6 +18,7 @@ Andreas Piesk Andrew Ford Arno Lehmann Bernd Frick +Bill Moran Carlos A. Molina G Carsten Paeth Chris Lee @@ -64,6 +65,7 @@ Morgan Nic Bellamy Nicolas Boichat Olivier Lehmann +Peter Buschmann Peter Eriksson Philippe Chauvat Phil Stracchino diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index 3018ac1efd..427bc4bcfb 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -96,7 +96,7 @@ static RES_ITEM cli_items[] = { {"piddirectory", store_dir, ITEM(res_client.pid_directory), 0, ITEM_REQUIRED, 0}, {"subsysdirectory", store_dir, ITEM(res_client.subsys_directory), 0, 0, 0}, {"scriptsdirectory", store_dir, ITEM(res_client.scripts_directory), 0, 0, 0}, - {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 10}, + {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 20}, {"messages", store_res, ITEM(res_client.messages), R_MSGS, 0, 0}, {"sdconnecttimeout", store_time,ITEM(res_client.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30}, {"heartbeatinterval", store_time, ITEM(res_client.heartbeat_interval), 0, ITEM_DEFAULT, 0}, diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index d40e212e0c..caace4c970 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -75,7 +75,7 @@ static RES_ITEM store_items[] = { {"piddirectory", store_dir, ITEM(res_store.pid_directory), 0, ITEM_REQUIRED, 0}, {"subsysdirectory", store_dir, ITEM(res_store.subsys_directory), 0, 0, 0}, {"scriptsdirectory", store_dir, ITEM(res_store.scripts_directory), 0, 0, 0}, - {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 10}, + {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 20}, {"heartbeatinterval", store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0}, {"tlsenable", store_bit, ITEM(res_store.tls_enable), 1, 0, 0}, {"tlsrequire", store_bit, ITEM(res_store.tls_require), 1, 0, 0}, diff --git a/bacula/src/version.h b/bacula/src/version.h index 06413385b7..c3ba21d46b 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "2.2.0" -#define BDATE "08 August 2007" -#define LSMDATE "08Aug07" +#define VERSION "2.3.0" +#define BDATE "15 August 2007" +#define LSMDATE "15Aug07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/src/win32/Makefile b/bacula/src/win32/Makefile index 56e8d3198d..2797503ee3 100644 --- a/bacula/src/win32/Makefile +++ b/bacula/src/win32/Makefile @@ -43,7 +43,10 @@ Makefile.inc: Makefile.inc.in echo -e "You must run build-win32-cross-tools and build-dependencies first.\n"; \ exit 1; \ fi ; \ - sed -e "s^@TOPDIR@^$${TOPDIR}^" \ + $(ECHO_CMD)BUILDDIR=`(pwd)`; \ + sed \ + -e "s^@BUILDDIR@^$${BUILDDIR}^" \ + -e "s^@TOPDIR@^$${TOPDIR}^" \ -e "s^@BINDIR@^$${BINDIR}^" \ -e "s^@INCDIR@^$${INCDIR}^" \ -e "s^@DLLDIR@^$${DLLDIR}^" < Makefile.inc.in > $@ diff --git a/bacula/src/win32/Makefile.inc.in b/bacula/src/win32/Makefile.inc.in index 052a6ed9db..c5b651b0c0 100644 --- a/bacula/src/win32/Makefile.inc.in +++ b/bacula/src/win32/Makefile.inc.in @@ -9,6 +9,7 @@ ECHO_CMD = @ +BUILDDIR := @BUILDDIR@ TOPDIR := @TOPDIR@ DEPKGS := $(TOPDIR)/depkgs-mingw32 @@ -45,41 +46,41 @@ INCLUDE_WX := -I$(DEPKGS)/lib/wx_dll/msw -I$(DEPKGS)/include INCLUDE_MYSQL := -I$(DEPKGS)/include/mysql LIBS_PTHREADS := \ - $(DEPKGS)/lib/libpthreadGCE.a + $(DEPKGS)/lib/libpthreadGCE.a LIBS_ZLIB := \ - $(DEPKGS)/lib/libz.a + $(DEPKGS)/lib/libz.a LIBS_MYSQL := \ - $(DEPKGS)/lib/libmysql.a + $(DEPKGS)/lib/libmysql.a LIBS_POSTGRESQL := \ - $(DEPKGS)/lib/libpq.a + $(DEPKGS)/lib/libpq.a LIBS_SQLITE := \ - $(DEPKGS)/lib/libsqlite3.a + $(DEPKGS)/lib/libsqlite3.a LIBS_SSL := \ - $(DEPKGS)/lib/libssl.dll.a + $(DEPKGS)/lib/libssl.dll.a LIBS_CRYPTO := \ - $(DEPKGS)/lib/libcrypto.dll.a + $(DEPKGS)/lib/libcrypto.dll.a LIBS_WX := \ - $(DEPKGS)/lib/wx_dll/libwxmsw27_core.a \ - $(DEPKGS)/lib/wx_dll/libwxbase27.a + $(DEPKGS)/lib/wx_dll/libwxmsw27_core.a \ + $(DEPKGS)/lib/wx_dll/libwxbase27.a LIBS_CATS := \ - $(LIBDIR)/libcats.a + $(LIBDIR)/libcats.a LIBS_BACULA := \ - $(LIBDIR)/libbacula.a + $(LIBDIR)/libbacula.a HAVES := \ - -DHAVE_WIN32 \ - -DHAVE_MINGW \ - -DHAVE_ZLIB_H \ - -DHAVE_LIBZ \ - -DHAVE_CRYPTO \ - -DHAVE_OPENSSL \ - -DHAVE_TLS + -DHAVE_WIN32 \ + -DHAVE_MINGW \ + -DHAVE_ZLIB_H \ + -DHAVE_LIBZ \ + -DHAVE_CRYPTO \ + -DHAVE_OPENSSL \ + -DHAVE_TLS diff --git a/bacula/src/win32/Makefile.rules b/bacula/src/win32/Makefile.rules index 8535f46ce8..72c93c86ba 100644 --- a/bacula/src/win32/Makefile.rules +++ b/bacula/src/win32/Makefile.rules @@ -7,6 +7,7 @@ define clean_obj $(ECHO_CMD)rm -f $(1) $(patsubst %.o,%.d,$(filter-out %.res,$(1))) + $(ECHO_CMD)rm -f $(1) $(addsuffix .d.*,$(basename $(1))) endef define clean_exe diff --git a/bacula/src/win32/compat/getopt.c b/bacula/src/win32/compat/getopt.c index 695c98248d..597ee42a8c 100644 --- a/bacula/src/win32/compat/getopt.c +++ b/bacula/src/win32/compat/getopt.c @@ -40,7 +40,7 @@ #include "getopt.h" -static const char* ID = "$Id$"; +static const char* ID = "$Id: getopt.c 5170 2007-07-13 13:33:34Z kerns $"; char* optarg = NULL; diff --git a/bacula/src/win32/dird/Makefile b/bacula/src/win32/dird/Makefile index de5b657b70..387a6b2828 100644 --- a/bacula/src/win32/dird/Makefile +++ b/bacula/src/win32/dird/Makefile @@ -8,6 +8,7 @@ include ../Makefile.inc INCLUDES = \ + -I. \ $(INCLUDE_PTHREADS) \ $(INCLUDE_BACULA) \ $(INCLUDE_ZLIB) \ @@ -20,8 +21,8 @@ DEFINES = \ -DWINVER=0x500 \ $(HAVES) -vpath %.c ../../dird -vpath %.cpp ../../dird +vpath %.c ../../dird ../libwin32 +vpath %.cpp ../../dird ../libwin32 ########################################################################## @@ -67,16 +68,20 @@ DIRD_OBJS = \ $(OBJDIR)/ua_tree.o \ $(OBJDIR)/ua_update.o \ $(OBJDIR)/verify.o \ - $(OBJDIR)/winservice.o \ - $(OBJDIR)/winmain.o \ - $(OBJDIR)/winres.res + $(OBJDIR)/service.o \ + $(OBJDIR)/main.o \ + $(OBJDIR)/bacula.res ALL_OBJS = $(DIRD_OBJS) DIRD_LIBS = \ $(LIBS_PTHREADS) \ - -lwsock32 + -lole32 \ + -loleaut32 \ + -lwsock32 \ + -luuid \ + -lcomctl32 ###################################################################### diff --git a/bacula/src/win32/dird/bacula.rc b/bacula/src/win32/dird/bacula.rc new file mode 100644 index 0000000000..92b889cb41 --- /dev/null +++ b/bacula/src/win32/dird/bacula.rc @@ -0,0 +1 @@ +#include "../libwin32/bacula.rc" diff --git a/bacula/src/win32/dird/main.cpp b/bacula/src/win32/dird/main.cpp new file mode 100644 index 0000000000..a0cc118b6c --- /dev/null +++ b/bacula/src/win32/dird/main.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/main.cpp" diff --git a/bacula/src/win32/dird/service.cpp b/bacula/src/win32/dird/service.cpp new file mode 100644 index 0000000000..0be0918bb2 --- /dev/null +++ b/bacula/src/win32/dird/service.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/service.cpp" diff --git a/bacula/src/win32/stored/baculasd/winstat.h b/bacula/src/win32/dird/who.h similarity index 59% rename from bacula/src/win32/stored/baculasd/winstat.h rename to bacula/src/win32/dird/who.h index a4a11c2e76..cee1572492 100644 --- a/bacula/src/win32/stored/baculasd/winstat.h +++ b/bacula/src/win32/dird/who.h @@ -1,18 +1,14 @@ -/* - * Bacula Status Dialog header file - * - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. This program is Free Software; you can redistribute it and/or modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation and included - in the file LICENSE. + License as published by the Free Software Foundation, which is + listed in the file LICENSE. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -29,32 +25,20 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + * This file is pulled in by certain generic routines in libwin32 + * to define the names of the daemon that is being built. + */ +#define APP_NAME "Bacula-dir" +#define LC_APP_NAME "bacula-dir" +#define APP_DESC "Bacula Director Service" -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); - static void DisplayString(const char *msg, int len, void *context); - - void UpdateDisplay(); - - void Show(BOOL show); - - void ResizeChildren(HWND hDlg, WORD wWidth, WORD wHeight); - -private: - BOOL m_bVisible; - HWND m_hTextDisplay; -}; +#define terminate_app(x) terminate_dird(x) +extern void terminate_dird(int sig); -#endif +#define VSSInit() diff --git a/bacula/src/win32/dird/winbacula.h b/bacula/src/win32/dird/winbacula.h deleted file mode 100644 index 6a0a4e9a57..0000000000 --- a/bacula/src/win32/dird/winbacula.h +++ /dev/null @@ -1,67 +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; - -extern int BaculaAppMain(); - -extern void LogErrorMsg(char *msg); - -// Standard command-line flag definitions -const char BaculaOptDebug[] = "/debug"; - -const char BaculaRunService[] = "/service"; -const char BaculaRunAsUserApp[] = "/run"; -const char BaculaKillRunningCopy[] = "/kill"; - -const char BaculaInstallService[] = "/install"; -const char BaculaRemoveService[] = "/remove"; - -const char BaculaShowHelp[] = "/help"; - -// Usage string -const char BaculaUsageText[] = "Bacula [/debug] [/service] [/run] [/kill] [/install] [/remove] [/help]\n"; - -void LogErrorMsg(char *msg, char *fname, int lineno); -#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/win32/dird/winmain.cpp b/bacula/src/win32/dird/winmain.cpp deleted file mode 100644 index 281127683f..0000000000 --- a/bacula/src/win32/dird/winmain.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ - -#include -#include - -#include "bacula.h" -#include "winbacula.h" -#include "winservice.h" -#include -#include - -extern int BaculaMain(int argc, char *argv[]); -extern void terminate_dird(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-dir"; -DWORD mainthreadId; -bool opt_debug = false; - -/* Imported variables */ -extern DWORD g_servicethread; - -#define MAX_COMMAND_ARGS 100 -static char *command_args[MAX_COMMAND_ARGS] = {"bacula-dir", 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; - } - - /* 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 "bacula.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// 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 Director for Win32\0" - VALUE "FileVersion", VERSION "\0" - VALUE "InternalName", "Bacula\0" - VALUE "LegalCopyright", "Copyright Free Software Foundation Europe e.V., 1999-2007\0" - VALUE "LegalTrademarks", "Licensed under GNU GPL 2.0\0" - VALUE "OriginalFilename", "bacula-fd.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 -BEGIN - IDI_BACULA "Bacula" -END diff --git a/bacula/src/win32/dird/winservice.cpp b/bacula/src/win32/dird/winservice.cpp deleted file mode 100644 index 1b71b617b5..0000000000 --- a/bacula/src/win32/dird/winservice.cpp +++ /dev/null @@ -1,521 +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" - -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 bool opt_debug; - -// SERVICE-MODE ROUTINES - -// Service-mode defines: - -// Internal service name -#define BAC_SERVICENAME "Bacula-dir" - -// Displayed service name -#define BAC_SERVICEDISPLAYNAME "Bacula Director" - -// List other required services -#define BAC_DEPENDENCIES __TEXT("tcpip\0afd\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; - - // 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.")); - } - - 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 char *pszCmdLine) -{ - const int pathlength = 2048; - char path[pathlength]; - char servicecmd[pathlength]; - - // Get the filename of this executable - if (GetModuleFileName(NULL, path, pathlength-(strlen(BaculaRunService)+2)) == 0) { - MessageBox(NULL, _("Unable to install Bacula Director service"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - // Append the service-start flag to the end of the path: - if ((int)strlen(path) + 5 + (int)strlen(BaculaRunService) + (int)strlen(pszCmdLine) < pathlength) { - sprintf(servicecmd, "\"%s\" %s %s", path, BaculaRunService, pszCmdLine); - } 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; - } - - 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 Director service was not installed"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - // 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 Director service could not be installed"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - set_service_description(hsrvmanager,hservice, -_("Provides director services. Bacula -- the network backup solution.")); - - CloseServiceHandle(hsrvmanager); - CloseServiceHandle(hservice); - - // Everything went fine - if (opt_debug) { - MessageBox(NULL, - _("The Bacula Director 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); - } - return 0; -} - - -// SERVICE REMOVE ROUTINE -int -bacService::RemoveService() -{ - 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 Director service could not be stopped"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - } - - // Now remove the service from the SCM - if(DeleteService(hservice)) { - if (opt_debug) { - MessageBox(NULL, _("The Bacula Director service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); - } - } else { - MessageBox(NULL, _("The Bacula Director service could not be removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hservice); - } else { - MessageBox(NULL, _("The Bacula Director service could not be found"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hsrvmanager); - } else { - MessageBox(NULL, _("The SCM could not be contacted - the Bacula Director service was not removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - 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/win32/dird/winservice.h b/bacula/src/win32/dird/winservice.h deleted file mode 100644 index 841d85c6e6..0000000000 --- a/bacula/src/win32/dird/winservice.h +++ /dev/null @@ -1,69 +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 (2000) 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. - -#if (!defined(_win_bacService)) -#define _win_bacService - -// The NT-specific code wrapper class -class bacService -{ -public: - // 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(const char *pszCmdLine); - - // Routine to remove the Apcupsd service from the local machine - static int RemoveService(); - - // SERVICE SUPPORT FUNCTIONS - - // 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(); -}; - -#endif diff --git a/bacula/src/win32/filed/Makefile b/bacula/src/win32/filed/Makefile index 72f778f549..e1327b4f70 100644 --- a/bacula/src/win32/filed/Makefile +++ b/bacula/src/win32/filed/Makefile @@ -17,6 +17,7 @@ INCLUDES = \ $(INCLUDE_ICONS) DEFINES = \ + -DHAVE_TRAY_MONITOR \ -DUSING_DLL \ -DWIN32_VSS \ -DWINVER=0x500 \ @@ -43,12 +44,12 @@ FILED_OBJS = \ $(OBJDIR)/vss_XP.o \ $(OBJDIR)/vss_W2K3.o \ $(OBJDIR)/vss_Vista.o \ - $(OBJDIR)/winabout.o \ - $(OBJDIR)/winservice.o \ - $(OBJDIR)/winstat.o \ - $(OBJDIR)/wintray.o \ - $(OBJDIR)/winmain.o \ - $(OBJDIR)/winres.res + $(OBJDIR)/aboutDialog.o \ + $(OBJDIR)/service.o \ + $(OBJDIR)/statusDialog.o \ + $(OBJDIR)/trayMonitor.o \ + $(OBJDIR)/main.o \ + $(OBJDIR)/bacula.res ALL_OBJS = $(FILED_OBJS) diff --git a/bacula/src/win32/filed/bacula.rc b/bacula/src/win32/filed/bacula.rc new file mode 100644 index 0000000000..92b889cb41 --- /dev/null +++ b/bacula/src/win32/filed/bacula.rc @@ -0,0 +1 @@ +#include "../libwin32/bacula.rc" diff --git a/bacula/src/win32/filed/main.cpp b/bacula/src/win32/filed/main.cpp new file mode 100644 index 0000000000..a0cc118b6c --- /dev/null +++ b/bacula/src/win32/filed/main.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/main.cpp" diff --git a/bacula/src/win32/filed/service.cpp b/bacula/src/win32/filed/service.cpp new file mode 100644 index 0000000000..0be0918bb2 --- /dev/null +++ b/bacula/src/win32/filed/service.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/service.cpp" diff --git a/bacula/src/win32/filed/trayMonitor.cpp b/bacula/src/win32/filed/trayMonitor.cpp new file mode 100644 index 0000000000..71be7ac251 --- /dev/null +++ b/bacula/src/win32/filed/trayMonitor.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/trayMonitor.cpp" diff --git a/bacula/src/win32/filed/who.h b/bacula/src/win32/filed/who.h new file mode 100644 index 0000000000..e5430a6cdf --- /dev/null +++ b/bacula/src/win32/filed/who.h @@ -0,0 +1,43 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + * This file is pulled in by certain generic routines in libwin32 + * to define the names of the daemon that is being built. + */ + +#define APP_NAME "Bacula-fd" +#define LC_APP_NAME "bacula-fd" +#define APP_DESC "Bacula File Service" + +#define terminate_app(x) terminate_filed(x) +extern void terminate_filed(int sig); +extern void VSSInit(); diff --git a/bacula/src/win32/filed/winservice.cpp b/bacula/src/win32/filed/winservice.cpp deleted file mode 100644 index ca840fc298..0000000000 --- a/bacula/src/win32/filed/winservice.cpp +++ /dev/null @@ -1,731 +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 bool opt_debug; - -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 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 File service 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 File service could be contacted"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return FALSE; - } - return TRUE; -} - -// SERVICE-MODE ROUTINES - -// Service-mode defines: - -// Internal service name -#define BAC_SERVICENAME "Bacula-fd" - -// Displayed service name -#define BAC_SERVICEDISPLAYNAME "Bacula File Server" - -// List other required serves -#define BAC_DEPENDENCIES __TEXT("tcpip\0afd\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)) { -// Sleep(500); -//} - 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 char *pszCmdLine) -{ - const int pathlength = 2048; - char path[pathlength]; - char servicecmd[pathlength]; - - // Get the filename of this executable - if (GetModuleFileName(NULL, path, pathlength-(strlen(BaculaRunService)+2)) == 0) { - MessageBox(NULL, _("Unable to install Bacula File 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) + (int)strlen(pszCmdLine) < pathlength) { - sprintf(servicecmd, "\"%s\" %s %s", path, BaculaRunService, pszCmdLine); - } 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 (opt_debug) { - 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 (opt_debug) { - 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 (opt_debug) { - 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 file service could not be stopped"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - } - - // Now remove the service from the SCM - if (DeleteService(hservice)) { - if (opt_debug) { - MessageBox(NULL, _("The Bacula file service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); - } - } else { - MessageBox(NULL, _("The Bacula file service could not be removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hservice); - } else { - MessageBox(NULL, _("The Bacula file service could not be found"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hsrvmanager); - } else { - MessageBox(NULL, _("The SCM could not be contacted - the Bacula file 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) { - 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/win32/libbac/Makefile b/bacula/src/win32/libbac/Makefile index 5a4b87d6b1..55c260be9f 100644 --- a/bacula/src/win32/libbac/Makefile +++ b/bacula/src/win32/libbac/Makefile @@ -3,6 +3,7 @@ # Using MinGW cross-compiler on GNU/Linux # # Written for Bacula by Howard Thomson, April 2006 +# for building using cross-complilation. # include ../Makefile.inc diff --git a/bacula/src/win32/libwin32/winabout.cpp b/bacula/src/win32/libwin32/aboutDialog.cpp similarity index 63% rename from bacula/src/win32/libwin32/winabout.cpp rename to bacula/src/win32/libwin32/aboutDialog.cpp index 2cccd1414b..e09b2f2e14 100644 --- a/bacula/src/win32/libwin32/winabout.cpp +++ b/bacula/src/win32/libwin32/aboutDialog.cpp @@ -1,12 +1,7 @@ -/* - This file is patterned after the VNC Win32 code by ATT - - Kern E. Sibbald, 2000 -*/ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -30,61 +25,57 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Kern Sibbald, August 2007 + * + * Version $Id$ + * +*/ #include "bacula.h" -#include "winbacula.h" -#include "winabout.h" -#include "winres.h" - -bacAbout::bacAbout() -{ - visible = false; -} - -bacAbout::~bacAbout() { }; +#include "win32.h" -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 ) +static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { /* Get the dialog class pointer from USERDATA */ - bacAbout *_this; + aboutDialog *about; switch (uMsg) { case WM_INITDIALOG: /* save the dialog class pointer */ SetWindowLong(hwnd, GWL_USERDATA, lParam); - _this = (bacAbout *)lParam; + about = (aboutDialog *)lParam; /* Show the dialog */ SetForegroundWindow(hwnd); - _this->visible = true; - return TRUE; + about->m_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; + EndDialog(hwnd, true); + about = (aboutDialog *)GetWindowLong(hwnd, GWL_USERDATA); + about->m_visible = false; + return true; } break; case WM_DESTROY: - EndDialog(hwnd, FALSE); - _this = (bacAbout *)GetWindowLong(hwnd, GWL_USERDATA); - _this->visible = false; - return TRUE; + EndDialog(hwnd, false); + about = (aboutDialog *)GetWindowLong(hwnd, GWL_USERDATA); + about->m_visible = false; + return true; + } + return false; +} + +void aboutDialog::show(bool show) +{ + if (show && !m_visible) { + DialogBoxParam(appInstance, MAKEINTRESOURCE(IDD_ABOUT), NULL, + (DLGPROC)DialogProc, (LONG)this); } - return 0; } diff --git a/bacula/src/win32/libwin32/winabout.h b/bacula/src/win32/libwin32/aboutDialog.h similarity index 68% rename from bacula/src/win32/libwin32/winabout.h rename to bacula/src/win32/libwin32/aboutDialog.h index 39fa2e4fc1..80f5ea47ad 100644 --- a/bacula/src/win32/libwin32/winabout.h +++ b/bacula/src/win32/libwin32/aboutDialog.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -26,32 +26,24 @@ Switzerland, email:ftf@fsfeurope.org. */ /* - This file was inspired by the VNC Win32 code by ATT + * Kern Sibbald, August 2007 + * + * Version $Id$ + */ - Kern E. Sibbald, 2000 -*/ - - -/* Header for the About dialog for Bacula */ +#ifndef __ABOUT_DIALOG_H_ +#define __ABOUT_DIALOG_H_ 1 -class bacAbout; - -#ifndef _WINABOUT_H_ -#define _WINABOUT_H_ 1 - -/* Define the bacAbout class */ -class bacAbout +/* Define the aboutDialog class */ +class aboutDialog { public: - bacAbout(); - ~bacAbout(); - - /* The dialog box window proc */ - static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + aboutDialog() { m_visible =false; }; + ~aboutDialog() { }; - void Show(BOOL show); + void show(bool show); - bool visible; + bool m_visible; }; -#endif +#endif /* __ABOUT_H_ */ diff --git a/bacula/src/win32/libwin32/bacula.rc b/bacula/src/win32/libwin32/bacula.rc deleted file mode 100644 index c3371e7de1..0000000000 --- a/bacula/src/win32/libwin32/bacula.rc +++ /dev/null @@ -1 +0,0 @@ -1 ICON "apcupsd.ico" diff --git a/bacula/src/win32/filed/winmain.cpp b/bacula/src/win32/libwin32/main.cpp similarity index 52% rename from bacula/src/win32/filed/winmain.cpp rename to bacula/src/win32/libwin32/main.cpp index 9ce6b74fc0..8f309c078a 100644 --- a/bacula/src/win32/filed/winmain.cpp +++ b/bacula/src/win32/libwin32/main.cpp @@ -1,10 +1,7 @@ -/* - This file is patterned after the VNC Win32 code by ATT -*/ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -27,15 +24,31 @@ The licensor of Bacula is the Free Software Foundation Europe (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. -*/ + */ -#include -#include +/* + * + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + * Note, some of the original Bacula Windows startup and service handling code + * was derived from VNC code that was used in apcupsd then ported to + * Bacula. However, since then the code has been significantly enhanced + * and largely rewritten. + * + * Evidently due to the nature of Windows startup code and service + * handling code, certain similarities remain. Thanks to the original + * VNC authors. + * + * This is a generic main routine, which is used by all three + * of the daemons. Each one compiles it with slightly different + * #defines. + * + */ #include "bacula.h" -#include "winbacula.h" -#include "wintray.h" -#include "winservice.h" +#include "win32.h" #include #include @@ -45,47 +58,52 @@ #define _WIN32_WINNT 0x0501 #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 *, ...); -extern void VSSInit(); - /* Globals */ -HINSTANCE hAppInstance; -const char *szAppName = "Bacula-fd"; -DWORD mainthreadId; -bool opt_debug = false; +HINSTANCE appInstance; +DWORD mainthreadId; +bool opt_debug = false; +bool have_service_api; +DWORD service_thread_id = 0; -/* Imported variables */ -extern DWORD g_servicethread; #define MAX_COMMAND_ARGS 100 -static char *command_args[MAX_COMMAND_ARGS] = {"bacula-fd", NULL}; +static char *command_args[MAX_COMMAND_ARGS] = {LC_APP_NAME, NULL}; static int num_command_args = 1; static pid_t main_pid; static pthread_t main_tid; +const char usage[] = APP_NAME "[/debug] [/service] [/run] [/kill] [/install] [/remove] [/help]\n"; + /* - * WinMain parses the command line and either calls the main App - * routine or, under NT, the main service routine. + * + * Main Windows entry point. + * + * We parse the command line and either calls the main App + * or starts up the service. */ -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - PSTR CmdLine, int iCmdShow) +int WINAPI WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, PSTR CmdLine, + int /*show*/) { - char *szCmdLine = CmdLine; + char *cmdLine = CmdLine; char *wordPtr, *tempPtr; int i, quote; + OSVERSIONINFO osversioninfo; + osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo); + /* Save the application instance and main thread id */ - hAppInstance = hInstance; + appInstance = Instance; mainthreadId = GetCurrentThreadId(); + if (GetVersionEx(&osversioninfo) && + osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { + have_service_api = true; + } + main_pid = getpid(); main_tid = pthread_self(); - INITCOMMONCONTROLSEX initCC = { + INITCOMMONCONTROLSEX initCC = { sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES }; @@ -103,24 +121,27 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, * quote, we throw away the junk. */ - wordPtr = szCmdLine; + wordPtr = cmdLine; while (*wordPtr && *wordPtr != ' ') wordPtr++; - if (wordPtr > szCmdLine) /* backup to char before space */ + if (wordPtr > cmdLine) /* backup to char before space */ wordPtr--; /* if first character is not a quote and last is, junk it */ - if (*szCmdLine != '"' && *wordPtr == '"') { - szCmdLine = wordPtr + 1; + if (*cmdLine != '"' && *wordPtr == '"') { + cmdLine = wordPtr + 1; } - /* Build Unix style argc *argv[] */ + /* + * Build Unix style argc *argv[] for the main "Unix" code + * stripping out any Windows options + */ /* Don't NULL command_args[0] !!! */ for (i=1;ifIsLocked) { + 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/win32/libwin32/statusDialog.cpp b/bacula/src/win32/libwin32/statusDialog.cpp new file mode 100644 index 0000000000..0735262e8b --- /dev/null +++ b/bacula/src/win32/libwin32/statusDialog.cpp @@ -0,0 +1,170 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Bacula File daemon Status Dialog box + * + * Kern Sibbald, August 2007 + * + * Version $Id$ + */ + +#include "bacula.h" +#include "win32.h" +#include "statusDialog.h" + +static BOOL CALLBACK dialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + /* Get class pointer from user data */ + statusDialog *statDlg = (statusDialog *)GetWindowLong(hDlg, GWL_USERDATA); + + switch (uMsg) { + case WM_INITDIALOG: + /* Set class pointer in user data */ + SetWindowLong(hDlg, GWL_USERDATA, lParam); + statDlg = (statusDialog *)lParam; + statDlg->m_textWin = GetDlgItem(hDlg, IDC_TEXTDISPLAY); + + /* show the dialog */ + SetForegroundWindow(hDlg); + + /* Update every 5 seconds */ + SetTimer(hDlg, 1, 5000, NULL); + statDlg->m_visible = true; + statDlg->display(); + return true; + + case WM_TIMER: + statDlg->display(); + return true; + + case WM_SIZE: + statDlg->resize(hDlg, LOWORD(lParam), HIWORD(lParam)); + return true; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: + case IDOK: + statDlg->m_visible = false; + KillTimer(hDlg, 1); + EndDialog(hDlg, true); + return true; + } + break; + + case WM_DESTROY: + statDlg->m_textWin = NULL; + statDlg->m_visible = false; + KillTimer(hDlg, 1); + EndDialog(hDlg, false); + return true; + } + return false; +} + + +static void displayString(const char *msg, int len, void *context) +{ + /* Get class pointer from user data */ + statusDialog *statDlg = (statusDialog *)context; + const char *start = msg; + const char *p; + char *str; + + for (p=start; *p; p++) { + if (*p == '\n') { + int len = p - start; + if (len > 0) { + str = (char *)alloca(len + 1); + bstrncpy(str, start, len + 1); + + SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); + SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)str); + } + + if (*p == '\n') { + SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); + SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LONG)"\r\n"); + } + + if (*p == '\0'){ + break; + } + start = p + 1; + } + } +} + +void statusDialog::display() +{ + if (m_textWin != NULL) { + long hPos = GetScrollPos(m_textWin, SB_HORZ); + long vPos = GetScrollPos(m_textWin, SB_VERT); + long selStart; + long selEnd; + + SendMessage(m_textWin, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd); + + SetWindowText(m_textWin, ""); + output_status(displayString, this); + + SendMessage(m_textWin, EM_SETSEL, selStart, selEnd); + SendMessage(m_textWin, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, hPos), 0); + SendMessage(m_textWin, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, vPos), 0); + } +} + +/* Dialog box handling functions */ +void statusDialog::show(bool show) +{ + if (show && !m_visible) { + DialogBoxParam(appInstance, MAKEINTRESOURCE(IDD_STATUS), NULL, + (DLGPROC)dialogProc, (LONG)this); + } +} + +/* + * Make sure OK button is positioned in the right place + */ +void statusDialog::resize(HWND dWin, int dWidth, int dHeight) +{ + int bWidth, bHeight; + RECT bRect; + HWND bWin; + + if (m_textWin != NULL) { + bWin = GetDlgItem(dWin, IDOK); /* get size of OK button */ + + GetWindowRect(bWin, &bRect); + bWidth = bRect.right - bRect.left; + bHeight = bRect.bottom - bRect.top; + + MoveWindow(m_textWin, 8, 8, dWidth-bWidth-24, dHeight-16, true); + MoveWindow(bWin, dWidth - bWidth-8, 8, bWidth, bHeight, true); + } +} diff --git a/bacula/src/win32/libwin32/winstat.h b/bacula/src/win32/libwin32/statusDialog.h similarity index 69% rename from bacula/src/win32/libwin32/winstat.h rename to bacula/src/win32/libwin32/statusDialog.h index 77c115463f..c99d5172c7 100644 --- a/bacula/src/win32/libwin32/winstat.h +++ b/bacula/src/win32/libwin32/statusDialog.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -28,30 +28,29 @@ /* * Bacula Status Dialog header file * + * Kern Sibbald, August 2007 + * + * Version $Id$ + * */ -#ifndef _WINSTAT_H_ -#define _WINSTAT_H_ +#ifndef __STATUS_DIALOG_H_ +#define __STATUS_DIALOG_H_ -class bacStatus +class statusDialog { public: - bacStatus(); - ~bacStatus(); - - /* The Windows callback routine */ - static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - static void DisplayString(const char *msg, int len, void *context); + statusDialog() { m_visible = false; m_textWin = NULL; }; + ~statusDialog() { }; - void UpdateDisplay(); + void display(); - void Show(BOOL show); + void show(bool show); - void ResizeChildren(HWND hDlg, WORD wWidth, WORD wHeight); + void resize(HWND win, int width, int height); -private: - BOOL m_bVisible; - HWND m_hTextDisplay; + bool m_visible; + HWND m_textWin; }; #endif diff --git a/bacula/src/win32/libwin32/trayMonitor.cpp b/bacula/src/win32/libwin32/trayMonitor.cpp new file mode 100644 index 0000000000..d6e4ce2386 --- /dev/null +++ b/bacula/src/win32/libwin32/trayMonitor.cpp @@ -0,0 +1,261 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. + */ +/* + * + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + * This is a generic tray monitor routine, which is used by all three + * of the daemons. Each one compiles it with slightly different + * #defines. + * + */ + +#include "bacula.h" +#include "jcr.h" +#include "win32.h" + +trayMonitor::trayMonitor() +{ + /* Create a window to handle tray icon messages */ + WNDCLASSEX trayclass; + + trayclass.cbSize = sizeof(trayclass); + trayclass.style = 0; + trayclass.lpfnWndProc = trayMonitor::trayWinProc; + trayclass.cbClsExtra = 0; + trayclass.cbWndExtra = 0; + trayclass.hInstance = appInstance; + trayclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + trayclass.hCursor = LoadCursor(NULL, IDC_ARROW); + trayclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + trayclass.lpszMenuName = NULL; + trayclass.lpszClassName = APP_NAME; + trayclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + RegisterClassEx(&trayclass); + + m_hwnd = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, + NULL, NULL, appInstance, NULL); + if (!m_hwnd) { + PostQuitMessage(0); + return; + } + + /* Save our class pointer */ + 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(appInstance, MAKEINTRESOURCE(IDI_IDLE)); + m_running_icon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_RUNNING)); + m_error_icon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_JOB_ERROR)); + m_warn_icon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_JOB_WARNING)); + + /* Load the menu */ + m_hmenu = LoadMenu(appInstance, MAKEINTRESOURCE(IDR_TRAYMENU)); + m_visible = false; + + /* Install the icon in the tray */ + install(); +} + +trayMonitor::~trayMonitor() +{ + /* Remove the icon from the tray */ + sendMessage(NIM_DELETE, 0); + + if (m_hmenu) { + DestroyMenu(m_hmenu); + m_hmenu = NULL; + } +} + +void trayMonitor::install() +{ + sendMessage(NIM_ADD, bacstat); + m_installed = true; +} + +void trayMonitor::update(int bacstat) +{ + if (!m_installed) { + install(); + } + (void)bac_status(NULL, 0); + sendMessage(NIM_MODIFY, bacstat); +} + +void trayMonitor::sendMessage(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 the resource string as tip */ + if (LoadString(appInstance, IDI_BACULA, m_nid.szTip, sizeof(m_nid.szTip))) { + m_nid.uFlags |= NIF_TIP; + } + + /* Add the Bacula status to the tip string */ + if (m_nid.uFlags & NIF_TIP) { + bac_status(m_nid.szTip, sizeof(m_nid.szTip)); + } + + if (Shell_NotifyIcon(msg, &m_nid)) { + EnableMenuItem(m_hmenu, ID_CLOSE, MF_ENABLED); + } +} + +/* + * This is the windows call back for our tray window + */ +LRESULT CALLBACK trayMonitor::trayWinProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) +{ + HMENU menu; + trayMonitor *mon = (trayMonitor *)GetWindowLong(hwnd, GWL_USERDATA); + + switch (iMsg) { + + /* Every five seconds, a timer message causes the icon to update */ + case WM_TIMER: + if (isAService()) { + mon->update(bacstat); + } + break; + + case WM_CREATE: + return 0; + + case WM_COMMAND: + /* User has clicked an item on the tray monitor menu */ + switch (LOWORD(wParam)) { + case ID_STATUS: + /* show the dialog box */ + mon->m_status.show(true); + mon->update(bacstat); + break; + + case ID_ABOUT: + /* Show the About box */ + mon->m_about.show(true); + break; + + /* This is turned off now */ +#ifdef xxx + case ID_CLOSE: + /* User selected Close from the tray menu */ + PostMessage(hwnd, WM_CLOSE, 0, 0); + break; +#endif + + } + return 0; + + /* Our special command to check for mouse events */ + case WM_TRAYNOTIFY: + /* Right button click pops up the menu */ + if (lParam == WM_RBUTTONUP) { + POINT mouse; + /* Get the menu and pop it up */ + menu = GetSubMenu(mon->m_hmenu, 0); + if (!menu) { + return 0; + } + + /* The first menu item (Status) is the default */ + SetMenuDefaultItem(menu, 0, TRUE); + GetCursorPos(&mouse); + SetForegroundWindow(mon->m_nid.hWnd); /* display the menu */ + + /* Open the menu at the mouse position */ + TrackPopupMenu(menu, 0, mouse.x, mouse.y, 0, mon->m_nid.hWnd, NULL); + + /* Left double click brings up status dialog directly */ + } else if (lParam == WM_LBUTTONDBLCLK) { + mon->m_status.show(true); + mon->update(bacstat); + } + return 0; + + case WM_CLOSE: + if (isAService()) { + mon->sendMessage(NIM_DELETE, 0); + } + terminate_app(0); + break; + + case WM_DESTROY: + /* zap everything */ + PostQuitMessage(0); + return 0; + + case WM_QUERYENDSESSION: + if (!isAService() || lParam == 0) { + PostQuitMessage(0); + return TRUE; + } + return TRUE; + } + + return DefWindowProc(hwnd, iMsg, wParam, lParam); +} diff --git a/bacula/src/win32/libwin32/trayMonitor.h b/bacula/src/win32/libwin32/trayMonitor.h new file mode 100644 index 0000000000..77bc2031ae --- /dev/null +++ b/bacula/src/win32/libwin32/trayMonitor.h @@ -0,0 +1,68 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + */ + +#ifndef __TRAY_MONITOR_H_ +#define __TRAY_MONITOR_H_ 1 + +#define WM_TRAYNOTIFY WM_USER+1 + +/* Define the trayMonitor class */ +class trayMonitor +{ +public: + trayMonitor(); + ~trayMonitor(); + + void show(bool show); + void install(); + void update(int bacstat); + void sendMessage(DWORD msg, int bacstat); + + static LRESULT CALLBACK trayWinProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); + + bool m_visible; + bool m_installed; + + aboutDialog m_about; + statusDialog m_status; + + HWND m_hwnd; + HMENU m_hmenu; + NOTIFYICONDATA m_nid; + HICON m_idle_icon; + HICON m_running_icon; + HICON m_error_icon; + HICON m_warn_icon; +}; + +#endif /* __TRAY_MONITOR_H_ */ diff --git a/bacula/src/win32/stored/baculasd/winabout.h b/bacula/src/win32/libwin32/win32.h similarity index 61% rename from bacula/src/win32/stored/baculasd/winabout.h rename to bacula/src/win32/libwin32/win32.h index ea5badd621..0a67f04907 100644 --- a/bacula/src/win32/stored/baculasd/winabout.h +++ b/bacula/src/win32/libwin32/win32.h @@ -1,19 +1,14 @@ -/* - This file was inspired by the VNC Win32 code by ATT - - Kern E. Sibbald, 2000 -*/ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. This program is Free Software; you can redistribute it and/or modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation and included - in the file LICENSE. + License as published by the Free Software Foundation, which is + listed in the file LICENSE. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -30,29 +25,17 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ - - -/* 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; -}; - +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + */ + +#include "protos.h" +#include "res.h" + +#ifdef HAVE_TRAY_MONITOR +#include "aboutDialog.h" +#include "statusDialog.h" +#include "trayMonitor.h" #endif diff --git a/bacula/src/win32/libwin32/winbacula.h b/bacula/src/win32/libwin32/winbacula.h deleted file mode 100644 index b1674cc662..0000000000 --- a/bacula/src/win32/libwin32/winbacula.h +++ /dev/null @@ -1,70 +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; - -extern int BaculaAppMain(); - -extern void LogErrorMsg(char *msg); - -// Standard command-line flag definitions -const char BaculaOptDebug[] = "/debug"; - -const char BaculaRunService[] = "/service"; -const char BaculaRunAsUserApp[] = "/run"; -const char BaculaKillRunningCopy[] = "/kill"; - -const char BaculaInstallService[] = "/install"; -const char BaculaRemoveService[] = "/remove"; - -const char BaculaShowAbout[] = "/about"; -const char BaculaShowStatus[] = "/status"; - -const char BaculaShowHelp[] = "/help"; - -// Usage string -const char BaculaUsageText[] = "Bacula [/debug] [/service] [/run] [/kill] [/install] [/remove] [/about] [/status] [/help]\n"; - -void LogErrorMsg(char *msg, char *fname, int lineno); -#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/win32/libwin32/winres.h b/bacula/src/win32/libwin32/winres.h deleted file mode 100644 index 53c85209bd..0000000000 --- a/bacula/src/win32/libwin32/winres.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Included by bacula.rc - */ - -/* Icon definitions */ -#define IDI_BACULA 100 -#define IDI_IDLE 101 -#define IDI_RUNNING 102 -#define IDI_JOB_ERROR 103 -#define IDI_JOB_WARNING 104 -#define IDR_TRAYMENU 105 -#define IDB_BACULABMP 106 - -#define IDC_TEXTDISPLAY 1000 - -#define ID_CLOSE 40002 -#define ID_ABOUT 40004 -#define ID_STATUS 40005 - -/* Dialog definitions */ -#define IDD_ABOUT 201 -#define IDD_STATUS 202 - - diff --git a/bacula/src/win32/libwin32/winres.rc b/bacula/src/win32/libwin32/winres.rc deleted file mode 100644 index c5e7f7cbe5..0000000000 --- a/bacula/src/win32/libwin32/winres.rc +++ /dev/null @@ -1,149 +0,0 @@ -#include -#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 "bacula.ico" -IDI_IDLE ICON "idle.ico" -IDI_RUNNING ICON "running.ico" -IDI_JOB_ERROR ICON "error.ico" -IDI_JOB_WARNING ICON "warn.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDR_TRAYMENU MENU -BEGIN - POPUP "tray" - BEGIN - MENUITEM N_("&Status"), ID_STATUS - 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 Free Software Foundation Europe e.V., 1999-2007\0" - VALUE "LegalTrademarks", "Licensed under GNU GPL 2.0\0" - VALUE "OriginalFilename", "bacula-fd.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 - - -///////////////////////////////////////////////////////////////////////////// -// -// RT_MANIFEST -// -CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "bacula-fd.manifest" - -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// - -IDB_BACULABMP BITMAP DISCARDABLE "bacula.bmp" - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE -BEGIN - IDI_BACULA "Bacula" -END - -///////////////////////////////////////////////////////////////////////////// -// -// About Dialog -// - -IDD_ABOUT DIALOG 0, 0, 250, 145 -STYLE DS_SETFONT | 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"),-1,134,38,78,10 - LTEXT N_("For more information, see:"),-1,115,60,100,10 - LTEXT " www.bacula.org",-1,115,70,100,10 -// LTEXT " ",-1,69,81,100,10 -// LTEXT " ",-1,90,70,100,10 - LTEXT "Copyright (C) 1999-2007, Free Software Foundation Europe e.V.",-1,7,120,175,10 - LTEXT N_("Licensed under GNU GPL 2.0."),-1,7,130,175,10 - RTEXT N_("Build Date:"),-1,108,24,42,8 - RTEXT N_("Bacula Version:"),-1,100,9,50,8 - LTEXT VERSION,-1,159,10,65,8 - LTEXT BDATE,-1,159,24,65,10 - -END - -///////////////////////////////////////////////////////////////////////////// -// -// Status Dialog -// - -IDD_STATUS DIALOGEX 0, 0, 411, 244 -STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -CAPTION N_("Bacula Status") -FONT 8, "Courier New" -BEGIN - DEFPUSHBUTTON "&OK",IDOK,355,5,51,15 - EDITTEXT IDC_TEXTDISPLAY, 2, 2, 350, 240, WS_VSCROLL | WS_HSCROLL | WS_BORDER | ES_READONLY | ES_MULTILINE -END diff --git a/bacula/src/win32/libwin32/winservice.h b/bacula/src/win32/libwin32/winservice.h deleted file mode 100644 index d622cf6deb..0000000000 --- a/bacula/src/win32/libwin32/winservice.h +++ /dev/null @@ -1,83 +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. - -#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(const char *pszCmdLine); - - // Routine to remove the Apcupsd service from the local machine - static int RemoveService(); - - // SERVICE SUPPORT FUNCTIONS - - // 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 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(); -}; - -#endif diff --git a/bacula/src/win32/libwin32/winstat.cpp b/bacula/src/win32/libwin32/winstat.cpp deleted file mode 100644 index e1d6c7a058..0000000000 --- a/bacula/src/win32/libwin32/winstat.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Bacula File daemon Status Dialog box - * - * Inspired from the VNC code by ATT. - * - * Copyright (2000) Kern E. Sibbald - * - */ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ - -#include "bacula.h" -#include "winbacula.h" -#include "winstat.h" -#include "winres.h" - -extern void output_status(void sendit(const char *msg, int len, void *sarg), void *arg); - -bacStatus::bacStatus() -{ - m_bVisible = FALSE; - m_hTextDisplay = NULL; -} - -bacStatus::~bacStatus() -{ -} - -void -bacStatus::DisplayString(const char *msg, int len, void *context) -{ - /* Get class pointer from user data */ - bacStatus *_this = (bacStatus *)context; - const char *pStart; - const char *pCurrent; - - for (pStart = msg, pCurrent = msg; ; pCurrent++) { - if (*pCurrent == '\n' || *pCurrent == '\0') { - int lenSubstring = pCurrent - pStart; - if (lenSubstring > 0) { - char *pSubString = (char *)alloca(lenSubstring + 1); - bstrncpy(pSubString, pStart, lenSubstring + 1); - - SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LPARAM)pSubString); - } - - if (*pCurrent == '\n') { - SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LONG)"\r\n"); - } - - if (*pCurrent == '\0'){ - break; - } - pStart = pCurrent + 1; - } - } -} - -void -bacStatus::UpdateDisplay() -{ - if (m_hTextDisplay != NULL) { - long lHorizontalPos = GetScrollPos(m_hTextDisplay, SB_HORZ); - long lVerticalPos = GetScrollPos(m_hTextDisplay, SB_VERT); - long selStart, selEnd; - - SendMessage(m_hTextDisplay, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd); - - SetWindowText(m_hTextDisplay, ""); - - output_status(DisplayString, this); - - SendMessage(m_hTextDisplay, EM_SETSEL, (WPARAM)selStart, (LPARAM)selEnd); - SendMessage(m_hTextDisplay, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lHorizontalPos), 0); - SendMessage(m_hTextDisplay, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lVerticalPos), 0); - } -} - -/* Dialog box handling functions */ -void -bacStatus::Show(BOOL show) -{ - if (show && !m_bVisible) { - DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_STATUS), NULL, - (DLGPROC)DialogProc, (LONG)this); - } -} - -void -bacStatus::ResizeChildren(HWND hDlg, WORD wWidth, WORD wHeight) -{ - if (m_hTextDisplay != NULL) { - HWND hwndButton = GetDlgItem(hDlg, IDOK); - RECT rcWindow; - - GetWindowRect(hwndButton, &rcWindow); - - LONG lButtonWidth = rcWindow.right - rcWindow.left; - LONG lButtonHeight = rcWindow.bottom - rcWindow.top; - - MoveWindow(m_hTextDisplay, 8, 8, wWidth - lButtonWidth - 24, wHeight - 16, TRUE); - MoveWindow(hwndButton, wWidth - lButtonWidth - 8, 8, lButtonWidth, lButtonHeight, TRUE); - } -} - - -BOOL CALLBACK -bacStatus::DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - /* Get class pointer from user data */ - bacStatus *_this = (bacStatus *)GetWindowLong(hDlg, GWL_USERDATA); - - switch (uMsg) { - case WM_INITDIALOG: - /* Set class pointer in user data */ - SetWindowLong(hDlg, GWL_USERDATA, lParam); - _this = (bacStatus *)lParam; - _this->m_hTextDisplay = GetDlgItem(hDlg, IDC_TEXTDISPLAY); - - /* show the dialog */ - SetForegroundWindow(hDlg); - - /* Update every 5 seconds */ - SetTimer(hDlg, 1, 5000, NULL); - _this->m_bVisible = TRUE; - _this->UpdateDisplay(); - return TRUE; - - case WM_TIMER: - _this->UpdateDisplay(); - return TRUE; - - case WM_SIZE: - _this->ResizeChildren(hDlg, LOWORD(lParam), HIWORD(lParam)); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - case IDOK: - KillTimer(hDlg, 1); - EndDialog(hDlg, TRUE); - _this->m_bVisible = FALSE; - return TRUE; - } - break; - - case WM_DESTROY: - _this->m_hTextDisplay = NULL; - KillTimer(hDlg, 1); - EndDialog(hDlg, FALSE); - _this->m_bVisible = FALSE; - return TRUE; - } - return 0; -} diff --git a/bacula/src/win32/libwin32/wintray.cpp b/bacula/src/win32/libwin32/wintray.cpp deleted file mode 100644 index ca70e5164f..0000000000 --- a/bacula/src/win32/libwin32/wintray.cpp +++ /dev/null @@ -1,341 +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 char *MENU_CLASS_NAME = "BaculaFD 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 - DelTrayIcon(); - - // 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: - 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_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: - if (bacService::RunningAsService()) { - _this->DelTrayIcon(); - } - 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/win32/libwin32/wintray.h b/bacula/src/win32/libwin32/wintray.h index 44ad83c570..59b5568033 100644 --- a/bacula/src/win32/libwin32/wintray.h +++ b/bacula/src/win32/libwin32/wintray.h @@ -34,13 +34,18 @@ // This class handles creation of a system-tray icon & menu + + class bacMenu; #if (!defined(_win_bacMENU)) #define _win_bacMENU -#include "winabout.h" -#include "winstat.h" +#include "aboutDialog.h" +#include "statusDialog.h" + +// Message used for system tray notifications +#define WM_TRAYNOTIFY WM_USER+1 // Constants extern const UINT MENU_ABOUTBOX_SHOW; @@ -67,10 +72,10 @@ protected: protected: // About dialog for this server - bacAbout m_about; + aboutDialog m_about; // Status dialog for this server - bacStatus m_status; + statusDialog m_status; HWND m_hwnd; HMENU m_hmenu; diff --git a/bacula/src/win32/stored/Makefile b/bacula/src/win32/stored/Makefile index de04715d51..183171ebfd 100644 --- a/bacula/src/win32/stored/Makefile +++ b/bacula/src/win32/stored/Makefile @@ -10,6 +10,7 @@ include ../Makefile.inc INCLUDES = \ + -I. \ -I../../stored \ $(INCLUDE_DDK) \ $(INCLUDE_PTHREADS) \ @@ -19,12 +20,13 @@ INCLUDES = \ $(INCLUDE_ICONS) DEFINES = \ + -DHAVE_TRAY_MONITOR \ -DUSING_DLL \ -DWINVER=0x500 \ $(HAVES) -vpath %.c ../../stored baculasd -vpath %.cpp ../../stored baculasd +vpath %.c ../../stored ../libwin32 +vpath %.cpp ../../stored ../libwin32 ########################################################################## @@ -72,12 +74,12 @@ BEXTRACT_OBJS = \ $(OBJDIR)/pythonsd.o OBJS_WIN = \ - $(OBJDIR)/winabout.o \ - $(OBJDIR)/winservice.o \ - $(OBJDIR)/winstat.o \ - $(OBJDIR)/wintray.o \ - $(OBJDIR)/winmain.o \ - $(OBJDIR)/winres.res + $(OBJDIR)/aboutDialog.o \ + $(OBJDIR)/service.o \ + $(OBJDIR)/statusDialog.o \ + $(OBJDIR)/trayMonitor.o \ + $(OBJDIR)/main.o \ + $(OBJDIR)/bacula.res ALL_OBJS = \ $(COMMON_OBJS) \ @@ -91,7 +93,10 @@ ALL_OBJS = \ LIBS_STORED = \ $(LIBS_PTHREADS) \ + -lole32 \ + -loleaut32 \ -lwsock32 \ + -luuid \ -lcomctl32 ###################################################################### diff --git a/bacula/src/win32/stored/bacula.rc b/bacula/src/win32/stored/bacula.rc new file mode 100644 index 0000000000..92b889cb41 --- /dev/null +++ b/bacula/src/win32/stored/bacula.rc @@ -0,0 +1 @@ +#include "../libwin32/bacula.rc" diff --git a/bacula/src/win32/stored/baculasd/baculasd.vcproj b/bacula/src/win32/stored/baculasd.vcproj similarity index 100% rename from bacula/src/win32/stored/baculasd/baculasd.vcproj rename to bacula/src/win32/stored/baculasd.vcproj diff --git a/bacula/src/win32/stored/baculasd/bacula-sd.manifest b/bacula/src/win32/stored/baculasd/bacula-sd.manifest deleted file mode 100644 index 8296f138ed..0000000000 --- a/bacula/src/win32/stored/baculasd/bacula-sd.manifest +++ /dev/null @@ -1,21 +0,0 @@ - - - - Bacula Storage daemon for Win32 - - - - - - - diff --git a/bacula/src/win32/stored/baculasd/bacula.bmp b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/bacula.ico b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/bacula.rc b/bacula/src/win32/stored/baculasd/bacula.rc deleted file mode 100644 index c3371e7de1..0000000000 --- a/bacula/src/win32/stored/baculasd/bacula.rc +++ /dev/null @@ -1 +0,0 @@ -1 ICON "apcupsd.ico" diff --git a/bacula/src/win32/stored/baculasd/error.ico b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/idle.ico b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/running.ico b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/saving.ico b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/warn.ico b/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/winabout.cpp b/bacula/src/win32/stored/baculasd/winabout.cpp deleted file mode 100644 index 5fbccae3a9..0000000000 --- a/bacula/src/win32/stored/baculasd/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/win32/stored/baculasd/winbacula.h b/bacula/src/win32/stored/baculasd/winbacula.h deleted file mode 100644 index 04572de8fc..0000000000 --- a/bacula/src/win32/stored/baculasd/winbacula.h +++ /dev/null @@ -1,70 +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 Free Software Foundation Europe e.V. -// - - -// 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; - -extern int BaculaAppMain(); - -extern void LogErrorMsg(char *msg); - -// Standard command-line flag definitions -const char BaculaOptDebug[] = "/debug"; - -const char BaculaRunService[] = "/service"; -const char BaculaRunAsUserApp[] = "/run"; -const char BaculaKillRunningCopy[] = "/kill"; - -const char BaculaInstallService[] = "/install"; -const char BaculaRemoveService[] = "/remove"; - -const char BaculaShowAbout[] = "/about"; -const char BaculaShowStatus[] = "/status"; - -const char BaculaShowHelp[] = "/help"; - -// Usage string -const char BaculaUsageText[] = "Bacula [/debug] [/service] [/run] [/kill] [/install] [/remove] [/about] [/status] [/help]\n"; - -void LogErrorMsg(char *msg, char *fname, int lineno); -#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/win32/stored/baculasd/winmain.cpp b/bacula/src/win32/stored/baculasd/winmain.cpp deleted file mode 100644 index 332b4b03d0..0000000000 --- a/bacula/src/win32/stored/baculasd/winmain.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/* - Kern Sibbald - - This file is patterned after the VNC Win32 code by ATT -*/ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ - - -#include -#include - -#include "bacula.h" -#include "winbacula.h" -#include "wintray.h" -#include "winservice.h" -#include -#include - -#undef _WIN32_IE -#define _WIN32_IE 0x0501 -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 -#include - -extern int BaculaMain(int argc, char *argv[]); -extern void terminate_stored(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-sd"; -DWORD mainthreadId; -bool opt_debug = false; - -/* Imported variables */ -extern DWORD g_servicethread; - -#define MAX_COMMAND_ARGS 100 -static char *command_args[MAX_COMMAND_ARGS] = {"bacula-sd", 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(); - - INITCOMMONCONTROLSEX initCC = { - sizeof(INITCOMMONCONTROLSEX), - ICC_STANDARD_CLASSES - }; - - InitCommonControlsEx(&initCC); - - /* - * 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; - } - - /* 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 "bacula.ico" -IDI_IDLE ICON "idle.ico" -IDI_RUNNING ICON "running.ico" -IDI_JOB_ERROR ICON "error.ico" -IDI_JOB_WARNING ICON "warn.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDR_TRAYMENU MENU -BEGIN - POPUP "tray" - BEGIN - MENUITEM N_("&Status"), ID_STATUS - 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 Storage daemon for Win32\0" - VALUE "FileVersion", VERSION "\0" - VALUE "InternalName", "Bacula\0" - VALUE "LegalCopyright", "Copyright Free Software Foundation Europe e.V., 1999-2006\0" - VALUE "LegalTrademarks", "Licensed under GNU GPL 2.0\0" - VALUE "OriginalFilename", "bacula-sd.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 - - -///////////////////////////////////////////////////////////////////////////// -// -// RT_MANIFEST -// -CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "bacula-sd.manifest" - -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// - -IDB_BACULABMP BITMAP "bacula.bmp" - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE -BEGIN - IDI_BACULA "Bacula" -END - -///////////////////////////////////////////////////////////////////////////// -// -// About Dialog -// - -IDD_ABOUT DIALOG 0, 0, 250, 145 -STYLE DS_SETFONT | 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"),-1,134,38,78,10 - LTEXT N_("For more information, see:"),-1,115,60,100,10 - LTEXT " www.bacula.org",-1,115,70,100,10 -// LTEXT " ",-1,69,81,100,10 -// LTEXT " ",-1,90,70,100,10 - LTEXT "Copyright (C) 1999-2006, Kern Sibbald",-1,7,120,175,10 - LTEXT N_("Licensed under GNU GPL 2.0."),-1,7,130,175,10 - RTEXT N_("Build Date:"),-1,108,24,42,8 - RTEXT N_("Bacula Version:"),-1,100,9,50,8 - LTEXT VERSION,-1,159,10,65,8 - LTEXT BDATE,-1,159,24,65,10 - -END - -///////////////////////////////////////////////////////////////////////////// -// -// Status Dialog -// - -IDD_STATUS DIALOGEX 0, 0, 411, 244 -STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -CAPTION N_("Bacula Status") -FONT 8, "Courier New" -BEGIN - DEFPUSHBUTTON "&OK",IDOK,355,5,51,15 - EDITTEXT IDC_TEXTDISPLAY, 2, 2, 350, 240, WS_VSCROLL | WS_HSCROLL | WS_BORDER | ES_READONLY | ES_MULTILINE -END diff --git a/bacula/src/win32/stored/baculasd/winservice.cpp b/bacula/src/win32/stored/baculasd/winservice.cpp deleted file mode 100644 index 535d9bd9d5..0000000000 --- a/bacula/src/win32/stored/baculasd/winservice.cpp +++ /dev/null @@ -1,571 +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 Free Software Foundataion Europe e.V. -// - - -// 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 bool opt_debug; - -bacService::bacService() -{ -} - - -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 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 storage service 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 storage service could be contacted"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return FALSE; - } - return TRUE; -} - -// SERVICE-MODE ROUTINES - -// Service-mode defines: - -// Internal service name -#define BAC_SERVICENAME "Bacula-sd" - -// Displayed service name -#define BAC_SERVICEDISPLAYNAME "Bacula Storage Server" - -// List other required services -#define BAC_DEPENDENCIES __TEXT("tcpip\0afd\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)) { - Sleep(500); - } - return TRUE; -} - -// SERVICE MAIN ROUTINE -int -bacService::BaculaServiceMain() -{ - // Mark that we are a service - g_servicemode = TRUE; - - // 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.")); - } - - 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 char *pszCmdLine) -{ - const int pathlength = 2048; - char path[pathlength]; - char servicecmd[pathlength]; - - // Get the filename of this executable - if (GetModuleFileName(NULL, path, pathlength-(strlen(BaculaRunService)+2)) == 0) { - MessageBox(NULL, _("Unable to install Bacula Storage service"), szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - // Append the service-start flag to the end of the path: - if ((int)strlen(path) + 5 + (int)strlen(BaculaRunService) + (int)strlen(pszCmdLine) < pathlength) { - sprintf(servicecmd, "\"%s\" %s %s", path, BaculaRunService, pszCmdLine); - } 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; - } - - 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 Storage service was not installed"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - // 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 Storage service could not be installed"), - szAppName, MB_ICONEXCLAMATION | MB_OK); - return 0; - } - - set_service_description(hsrvmanager,hservice, -_("Provides storage services. Bacula -- the network backup solution.")); - - CloseServiceHandle(hsrvmanager); - CloseServiceHandle(hservice); - - // Everything went fine - if (opt_debug) { - MessageBox(NULL, - _("The Bacula Storage 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); - } - return 0; -} - - -// SERVICE REMOVE ROUTINE -int -bacService::RemoveService() -{ - 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 Storage service could not be stopped"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - } - - // Now remove the service from the SCM - if(DeleteService(hservice)) { - if (opt_debug) { - MessageBox(NULL, _("The Bacula Storage service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); - } - } else { - MessageBox(NULL, _("The Bacula Storage service could not be removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hservice); - } else { - MessageBox(NULL, _("The Bacula Storage service could not be found"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - - CloseServiceHandle(hsrvmanager); - } else { - MessageBox(NULL, _("The SCM could not be contacted - the Bacula Storage service was not removed"), szAppName, MB_ICONEXCLAMATION | MB_OK); - } - 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/win32/stored/baculasd/winservice.h b/bacula/src/win32/stored/baculasd/winservice.h deleted file mode 100644 index 36b31830db..0000000000 --- a/bacula/src/win32/stored/baculasd/winservice.h +++ /dev/null @@ -1,79 +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 Free Software Foundation Europe e.V. -// - - -// 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. - -#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(const char *pszCmdLine); - - // Routine to remove the Apcupsd service from the local machine - static int RemoveService(); - - // SERVICE SUPPORT FUNCTIONS - - // 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 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(); -}; - -#endif diff --git a/bacula/src/win32/stored/baculasd/winstat.cpp b/bacula/src/win32/stored/baculasd/winstat.cpp deleted file mode 100644 index b213223903..0000000000 --- a/bacula/src/win32/stored/baculasd/winstat.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Bacula File daemon Status Dialog box - * - * Inspired from the VNC code by ATT. - * - * - */ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ - -#include "bacula.h" -#include "winbacula.h" -#include "winstat.h" -#include "winres.h" - -extern void output_status(void sendit(const char *msg, int len, void *sarg), void *arg); - -bacStatus::bacStatus() -{ - m_bVisible = FALSE; - m_hTextDisplay = NULL; -} - -bacStatus::~bacStatus() -{ -} - -void -bacStatus::DisplayString(const char *msg, int len, void *context) -{ - /* Get class pointer from user data */ - bacStatus *_this = (bacStatus *)context; - const char *pStart; - const char *pCurrent; - - for (pStart = msg, pCurrent = msg; ; pCurrent++) { - if (*pCurrent == '\n' || *pCurrent == '\0') { - int lenSubstring = pCurrent - pStart; - if (lenSubstring > 0) { - char *pSubString = (char *)alloca(lenSubstring + 1); - bstrncpy(pSubString, pStart, lenSubstring + 1); - - SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LPARAM)pSubString); - } - - if (*pCurrent == '\n') { - SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); - SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LONG)"\r\n"); - } - - if (*pCurrent == '\0'){ - break; - } - pStart = pCurrent + 1; - } - } -} - -void -bacStatus::UpdateDisplay() -{ - if (m_hTextDisplay != NULL) { - long lHorizontalPos = GetScrollPos(m_hTextDisplay, SB_HORZ); - long lVerticalPos = GetScrollPos(m_hTextDisplay, SB_VERT); - long selStart, selEnd; - - SendMessage(m_hTextDisplay, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd); - - SetWindowText(m_hTextDisplay, ""); - - output_status(DisplayString, this); - - SendMessage(m_hTextDisplay, EM_SETSEL, (WPARAM)selStart, (LPARAM)selEnd); - SendMessage(m_hTextDisplay, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lHorizontalPos), 0); - SendMessage(m_hTextDisplay, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lVerticalPos), 0); - } -} - -/* Dialog box handling functions */ -void -bacStatus::Show(BOOL show) -{ - if (show && !m_bVisible) { - DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_STATUS), NULL, - (DLGPROC)DialogProc, (LONG)this); - } -} - -void -bacStatus::ResizeChildren(HWND hDlg, WORD wWidth, WORD wHeight) -{ - if (m_hTextDisplay != NULL) { - HWND hwndButton = GetDlgItem(hDlg, IDOK); - RECT rcWindow; - - GetWindowRect(hwndButton, &rcWindow); - - LONG lButtonWidth = rcWindow.right - rcWindow.left; - LONG lButtonHeight = rcWindow.bottom - rcWindow.top; - - MoveWindow(m_hTextDisplay, 8, 8, wWidth - lButtonWidth - 24, wHeight - 16, TRUE); - MoveWindow(hwndButton, wWidth - lButtonWidth - 8, 8, lButtonWidth, lButtonHeight, TRUE); - } -} - - -BOOL CALLBACK -bacStatus::DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - /* Get class pointer from user data */ - bacStatus *_this = (bacStatus *)GetWindowLong(hDlg, GWL_USERDATA); - - switch (uMsg) { - case WM_INITDIALOG: - /* Set class pointer in user data */ - SetWindowLong(hDlg, GWL_USERDATA, lParam); - _this = (bacStatus *)lParam; - _this->m_hTextDisplay = GetDlgItem(hDlg, IDC_TEXTDISPLAY); - - /* show the dialog */ - SetForegroundWindow(hDlg); - - /* Update every 5 seconds */ - SetTimer(hDlg, 1, 5000, NULL); - _this->m_bVisible = TRUE; - _this->UpdateDisplay(); - return TRUE; - - case WM_TIMER: - _this->UpdateDisplay(); - return TRUE; - - case WM_SIZE: - _this->ResizeChildren(hDlg, LOWORD(lParam), HIWORD(lParam)); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - case IDOK: - KillTimer(hDlg, 1); - EndDialog(hDlg, TRUE); - _this->m_bVisible = FALSE; - return TRUE; - } - break; - - case WM_DESTROY: - _this->m_hTextDisplay = NULL; - KillTimer(hDlg, 1); - EndDialog(hDlg, FALSE); - _this->m_bVisible = FALSE; - return TRUE; - } - return 0; -} diff --git a/bacula/src/win32/stored/baculasd/wintray.cpp b/bacula/src/win32/stored/baculasd/wintray.cpp deleted file mode 100644 index b9612cd442..0000000000 --- a/bacula/src/win32/stored/baculasd/wintray.cpp +++ /dev/null @@ -1,341 +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, Free Software Foundation Europe e.V. -// - - - -// 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 char *MENU_CLASS_NAME = "BaculaSD Tray Icon"; - -extern void terminate_stored(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 - DelTrayIcon(); - - // 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: - 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_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: - if (bacService::RunningAsService()) { - _this->DelTrayIcon(); - } - terminate_stored(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/win32/stored/baculasd/wintray.h b/bacula/src/win32/stored/baculasd/wintray.h deleted file mode 100644 index 2853a83224..0000000000 --- a/bacula/src/win32/stored/baculasd/wintray.h +++ /dev/null @@ -1,87 +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 Free Software Foundation Europe e.V. -// - - - -// winMenu - -// This class handles creation of a system-tray icon & menu - -class bacMenu; - -#if (!defined(_win_bacMENU)) -#define _win_bacMENU - -#include "winabout.h" -#include "winstat.h" - -// Constants -extern const UINT MENU_ABOUTBOX_SHOW; -extern const UINT MENU_STATUS_SHOW; -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; - - 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/win32/stored/main.cpp b/bacula/src/win32/stored/main.cpp new file mode 100644 index 0000000000..a0cc118b6c --- /dev/null +++ b/bacula/src/win32/stored/main.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/main.cpp" diff --git a/bacula/src/win32/stored/mtops.cpp b/bacula/src/win32/stored/mtops.cpp index 7b8a4c70ff..5b36846b56 100644 --- a/bacula/src/win32/stored/mtops.cpp +++ b/bacula/src/win32/stored/mtops.cpp @@ -1,27 +1,7 @@ -/* - * mtops.cpp - Emulate the Linux st (scsi tape) driver on Microsoft Windows. - * - * Author: Robert Nelson, May, 2006 - * - * Version $Id$ - * - * This file was contributed to the Bacula project by Robert Nelson. - * - * Robert Nelson has been granted a perpetual, worldwide, - * non-exclusive, no-charge, royalty-free, irrevocable copyright - * license to reproduce, prepare derivative works of, publicly - * display, publicly perform, sublicense, and distribute the original - * work contributed by Robert Nelson to the Bacula project in source - * or object form. - * - * If you wish to license contributions from Robert Nelson - * under an alternate open source license please contact - * Robert Nelson . - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2006-2006 Free Software Foundation Europe e.V. + Copyright (C) 2006-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -45,6 +25,26 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * mtops.cpp - Emulate the Linux st (scsi tape) driver on Microsoft Windows. + * + * Author: Robert Nelson, May, 2006 + * + * Version $Id$ + * + * This file was contributed to the Bacula project by Robert Nelson. + * + * Robert Nelson has been granted a perpetual, worldwide, + * non-exclusive, no-charge, royalty-free, irrevocable copyright + * license to reproduce, prepare derivative works of, publicly + * display, publicly perform, sublicense, and distribute the original + * work contributed by Robert Nelson to the Bacula project in source + * or object form. + * + * If you wish to license contributions from Robert Nelson + * under an alternate open source license please contact + * Robert Nelson . + */ #include #include diff --git a/bacula/src/win32/stored/service.cpp b/bacula/src/win32/stored/service.cpp new file mode 100644 index 0000000000..0be0918bb2 --- /dev/null +++ b/bacula/src/win32/stored/service.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/service.cpp" diff --git a/bacula/src/win32/stored/trayMonitor.cpp b/bacula/src/win32/stored/trayMonitor.cpp new file mode 100644 index 0000000000..71be7ac251 --- /dev/null +++ b/bacula/src/win32/stored/trayMonitor.cpp @@ -0,0 +1,36 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + */ + +#include "who.h" +#include "../libwin32/trayMonitor.cpp" diff --git a/bacula/src/win32/stored/who.h b/bacula/src/win32/stored/who.h new file mode 100644 index 0000000000..910d00d5fc --- /dev/null +++ b/bacula/src/win32/stored/who.h @@ -0,0 +1,44 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, August 2007 + * + * Version $Id$ + * + * This file is pulled in by certain generic routines in libwin32 + * to define the names of the daemon that is being built. + */ + +#define APP_NAME "Bacula-sd" +#define LC_APP_NAME "bacula-sd" +#define APP_DESC "Bacula Storagee Service" + +#define terminate_app(x) terminate_stored(x) +extern void terminate_stored(int sig); + +#define VSSInit() diff --git a/bacula/src/win32/winapi.h b/bacula/src/win32/winapi.h index 72039378c6..07b46e738b 100644 --- a/bacula/src/win32/winapi.h +++ b/bacula/src/win32/winapi.h @@ -1,10 +1,3 @@ -/* - * 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 - */ /* Bacula® - The Network Backup Solution @@ -32,6 +25,13 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * 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 + */ #ifndef __WINAPI_H #define __WINAPI_H @@ -58,6 +58,7 @@ typedef char POOLMEM; // 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 diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 0183f968ff..a0a5ba0a0e 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,19 @@ - Technical notes on version 2.1 + Technical notes on version 2.3 General: +15Aug07 +kes Update AUTHORs file +kes Increase the default max concurrent jobs to 20 in FD and SD to + correspond with the default .conf files. +kes Rewrite the Win32 service routines. This eliminates the 3 copies + some different, of the same file created by RN when porting the + Win32 SD and Dir. +kes Rearrange some of the Win32 directories and the placement of the files + in them. +kes Set DEVELOPER flag in version.h + +======================================================================== +Release Version 2.2.0 09Aug07 kes Apply a second doc patch from Marc. kes Apply a doc patch from Marc Schiffbauer that -- 2.39.5