Andrew Ford
Arno Lehmann
Bernd Frick
+Bill Moran
Carlos A. Molina G
Carsten Paeth
Chris Lee
Nic Bellamy
Nicolas Boichat
Olivier Lehmann
+Peter Buschmann
Peter Eriksson
Philippe Chauvat
Phil Stracchino
{"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},
{"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},
*/
#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 */
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 > $@
ECHO_CMD = @
+BUILDDIR := @BUILDDIR@
TOPDIR := @TOPDIR@
DEPKGS := $(TOPDIR)/depkgs-mingw32
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
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
#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;
include ../Makefile.inc
INCLUDES = \
+ -I. \
$(INCLUDE_PTHREADS) \
$(INCLUDE_BACULA) \
$(INCLUDE_ZLIB) \
-DWINVER=0x500 \
$(HAVES)
-vpath %.c ../../dird
-vpath %.cpp ../../dird
+vpath %.c ../../dird ../libwin32
+vpath %.cpp ../../dird ../libwin32
##########################################################################
$(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
######################################################################
--- /dev/null
+#include "../libwin32/bacula.rc"
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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-dir"
+#define LC_APP_NAME "bacula-dir"
+#define APP_DESC "Bacula Director Service"
+
+#define terminate_app(x) terminate_dird(x)
+extern void terminate_dird(int sig);
+
+#define VSSInit()
+++ /dev/null
-// 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__)
+++ /dev/null
-/*
- 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 <unistd.h>
-#include <ctype.h>
-
-#include "bacula.h"
-#include "winbacula.h"
-#include "winservice.h"
-#include <signal.h>
-#include <pthread.h>
-
-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<MAX_COMMAND_ARGS;i++)
- command_args[i] = NULL;
-
- char *pszArgs = bstrdup(szCmdLine);
- wordPtr = pszArgs;
- quote = 0;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- if (*wordPtr == '\"') {
- quote = 1;
- wordPtr++;
- } else if (*wordPtr == '/') {
- /* Skip Windows options */
- while (*wordPtr && (*wordPtr != ' ' && *wordPtr != '\t'))
- wordPtr++;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- }
- if (*wordPtr) {
- while (*wordPtr && num_command_args < MAX_COMMAND_ARGS) {
- tempPtr = wordPtr;
- if (quote) {
- while (*tempPtr && *tempPtr != '\"')
- tempPtr++;
- quote = 0;
- } else {
- while (*tempPtr && *tempPtr != ' ')
- tempPtr++;
- }
- if (*tempPtr)
- *(tempPtr++) = '\0';
- command_args[num_command_args++] = wordPtr;
- wordPtr = tempPtr;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- if (*wordPtr == '\"') {
- quote = 1;
- wordPtr++;
- }
- }
- }
-
- /*
- * Now process Windows command line options
- */
- for (i = 0; i < (int)strlen(szCmdLine); i++) {
- if (szCmdLine[i] <= ' ') {
- continue;
- }
-
- if (szCmdLine[i] != '/') {
- break;
- }
-
- /* Now check for command-line arguments */
-
- /* /debug install quietly -- no prompts */
- if (strnicmp(&szCmdLine[i], BaculaOptDebug, sizeof(BaculaOptDebug) - 1) == 0) {
- opt_debug = true;
- i += sizeof(BaculaOptDebug) - 1;
- continue;
- }
-
- /* /service start service */
- if (strnicmp(&szCmdLine[i], BaculaRunService, sizeof(BaculaRunService) - 1) == 0) {
- /* Run Bacula as a service */
- return bacService::BaculaServiceMain();
- }
- /* /run (this is the default if no command line arguments) */
- if (strnicmp(&szCmdLine[i], BaculaRunAsUserApp, sizeof(BaculaRunAsUserApp) - 1) == 0) {
- /* Bacula is being run as a user-level program */
- return BaculaAppMain();
- }
- /* /install */
- if (strnicmp(&szCmdLine[i], BaculaInstallService, sizeof(BaculaInstallService) - 1) == 0) {
- /* Install Bacula as a service */
- return bacService::InstallService(&szCmdLine[i + sizeof(BaculaInstallService) - 1]);
- }
- /* /remove */
- if (strnicmp(&szCmdLine[i], BaculaRemoveService, sizeof(BaculaRemoveService) - 1) == 0) {
- /* Remove the Bacula service */
- return bacService::RemoveService();
- }
-
- /* /kill */
- if (strnicmp(&szCmdLine[i], BaculaKillRunningCopy, sizeof(BaculaKillRunningCopy) - 1) == 0) {
- /* Kill running copy of Bacula */
- return bacService::KillRunningCopy() ? 0 : 1;
- }
-
- /* /help */
- if (strnicmp(&szCmdLine[i], BaculaShowHelp, sizeof(BaculaShowHelp) - 1) == 0) {
- MessageBox(NULL, BaculaUsageText, _("Bacula Usage"), MB_OK|MB_ICONINFORMATION);
- return 0;
- }
-
- MessageBox(NULL, szCmdLine, _("Bad Command Line Options"), MB_OK);
-
- /* Show the usage dialog */
- MessageBox(NULL, BaculaUsageText, _("Bacula Usage"), MB_OK | MB_ICONINFORMATION);
- return 1;
- }
-
- return BaculaAppMain();
-}
-
-
-/*
- * Called as a thread from BaculaAppMain()
- * Here we handle the Windows messages
- */
-//DWORD WINAPI Main_Msg_Loop(LPVOID lpwThreadParam)
-void *Main_Msg_Loop(LPVOID lpwThreadParam)
-{
- DWORD old_servicethread = g_servicethread;
-
- pthread_detach(pthread_self());
-
- /* Since we are the only thread with a message loop
- * mark ourselves as the service thread so that
- * we can receive all the window events.
- */
- g_servicethread = GetCurrentThreadId();
-
- /* Now enter the Windows message handling loop until told to quit! */
- MSG msg;
- while (GetMessage(&msg, NULL, 0,0) ) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- if (old_servicethread != 0) { /* started as NT service */
- /* Mark that we're no longer running */
- g_servicethread = 0;
-
- /* Tell the service manager that we've stopped. */
- ReportStatus(SERVICE_STOPPED, g_error, 0);
- }
- /* Tell main program to go away */
- terminate_dird(0);
-
- /* Should not get here */
- pthread_kill(main_tid, SIGTERM); /* ask main thread to terminate */
- sleep(1);
- kill(main_pid, SIGTERM); /* ask main thread to terminate */
- _exit(0);
-}
-
-
-/*
- * This is the main routine for Bacula when running as an application
- * (under Windows 95 or Windows NT)
- * Under NT, Bacula can also run as a service. The BaculaServerMain routine,
- * defined in the bacService header, is used instead when running as a service.
- */
-int BaculaAppMain()
-{
- /* DWORD dwThreadID; */
- pthread_t tid;
- DWORD dwCharsWritten;
-
- InitWinAPIWrapper();
-
- WSA_Init();
-
- /* If no arguments were given then just run */
- if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) {
- if (opt_debug) {
- AllocConsole();
- }
- }
- WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL);
-
- /* Set this process to be the last application to be shut down. */
- if (p_SetProcessShutdownParameters) {
- p_SetProcessShutdownParameters(0x100, 0);
- }
-
- /* Create a thread to handle the Windows messages */
- pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0);
-
- /* Call the "real" Bacula */
- BaculaMain(num_command_args, command_args);
- PostQuitMessage(0);
- WSACleanup();
- _exit(0);
-}
+++ /dev/null
-#include <winuser.h>
-#include <winver.h>
-#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
+++ /dev/null
-// 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);
-}
+++ /dev/null
-// 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
$(INCLUDE_ICONS)
DEFINES = \
+ -DHAVE_TRAY_MONITOR \
-DUSING_DLL \
-DWIN32_VSS \
-DWINVER=0x500 \
$(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)
--- /dev/null
+#include "../libwin32/bacula.rc"
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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();
+++ /dev/null
-/*
- 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 <unistd.h>
-#include <ctype.h>
-
-#include "bacula.h"
-#include "winbacula.h"
-#include "wintray.h"
-#include "winservice.h"
-#include <signal.h>
-#include <pthread.h>
-
-#undef _WIN32_IE
-#define _WIN32_IE 0x0401
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
-#include <commctrl.h>
-
-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;
-
-/* Imported variables */
-extern DWORD g_servicethread;
-
-#define MAX_COMMAND_ARGS 100
-static char *command_args[MAX_COMMAND_ARGS] = {"bacula-fd", NULL};
-static int num_command_args = 1;
-static pid_t main_pid;
-static pthread_t main_tid;
-
-/*
- * WinMain parses the command line and either calls the main App
- * routine or, under NT, the main service routine.
- */
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- PSTR CmdLine, int iCmdShow)
-{
- char *szCmdLine = CmdLine;
- char *wordPtr, *tempPtr;
- int i, quote;
-
- /* Save the application instance and main thread id */
- hAppInstance = hInstance;
- mainthreadId = GetCurrentThreadId();
-
- main_pid = getpid();
- main_tid = pthread_self();
-
- 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<MAX_COMMAND_ARGS;i++) {
- command_args[i] = NULL;
- }
-
- char *pszArgs = bstrdup(szCmdLine);
- wordPtr = pszArgs;
- quote = 0;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- if (*wordPtr == '\"') {
- quote = 1;
- wordPtr++;
- } else if (*wordPtr == '/') {
- /* Skip Windows options */
- while (*wordPtr && (*wordPtr != ' ' && *wordPtr != '\t'))
- wordPtr++;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- }
- if (*wordPtr) {
- while (*wordPtr && num_command_args < MAX_COMMAND_ARGS) {
- tempPtr = wordPtr;
- if (quote) {
- while (*tempPtr && *tempPtr != '\"')
- tempPtr++;
- quote = 0;
- } else {
- while (*tempPtr && *tempPtr != ' ')
- tempPtr++;
- }
- if (*tempPtr)
- *(tempPtr++) = '\0';
- command_args[num_command_args++] = wordPtr;
- wordPtr = tempPtr;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- if (*wordPtr == '\"') {
- quote = 1;
- wordPtr++;
- }
- }
- }
-
- /*
- * Now process Windows command line options
- */
- for (i = 0; i < (int)strlen(szCmdLine); i++) {
- if (szCmdLine[i] <= ' ') {
- continue;
- }
-
- if (szCmdLine[i] != '/') {
- break;
- }
-
- /* Now check for command-line arguments */
-
- /* /debug - enable debugging facilities such as console message window */
- if (strnicmp(&szCmdLine[i], BaculaOptDebug, sizeof(BaculaOptDebug) - 1) == 0) {
- opt_debug = true;
- i += sizeof(BaculaOptDebug) - 1;
- continue;
- }
-
- /* /service start service */
- if (strnicmp(&szCmdLine[i], BaculaRunService, sizeof(BaculaRunService) - 1) == 0) {
- /* Run Bacula as a service */
- return bacService::BaculaServiceMain();
- }
- /* /run (this is the default if no command line arguments) */
- if (strnicmp(&szCmdLine[i], BaculaRunAsUserApp, sizeof(BaculaRunAsUserApp) - 1) == 0) {
- /* Bacula is being run as a user-level program */
- return BaculaAppMain();
- }
- /* /install */
- if (strnicmp(&szCmdLine[i], BaculaInstallService, sizeof(BaculaInstallService) - 1) == 0) {
- /* Install Bacula as a service */
- return bacService::InstallService(&szCmdLine[i + sizeof(BaculaInstallService) - 1]);
- }
- /* /remove */
- if (strnicmp(&szCmdLine[i], BaculaRemoveService, sizeof(BaculaRemoveService) - 1) == 0) {
- /* Remove the Bacula service */
- return bacService::RemoveService();
- }
-
- /* /about */
- if (strnicmp(&szCmdLine[i], BaculaShowAbout, sizeof(BaculaShowAbout) - 1) == 0) {
- /* Show Bacula's about box */
- return bacService::ShowAboutBox();
- }
-
- /* /status */
- if (strnicmp(&szCmdLine[i], BaculaShowStatus, sizeof(BaculaShowStatus) - 1) == 0) {
- /* Show Bacula's status box */
- return bacService::ShowStatus();
- }
-
- /* /kill */
- if (strnicmp(&szCmdLine[i], BaculaKillRunningCopy, sizeof(BaculaKillRunningCopy) - 1) == 0) {
- /* Kill running copy of Bacula */
- return bacService::KillRunningCopy();
- }
-
- /* /help */
- if (strnicmp(&szCmdLine[i], BaculaShowHelp, sizeof(BaculaShowHelp) - 1) == 0) {
- MessageBox(NULL, BaculaUsageText, _("Bacula Usage"), MB_OK|MB_ICONINFORMATION);
- return 0;
- }
-
- MessageBox(NULL, szCmdLine, _("Bad Command Line Options"), MB_OK);
-
- /* Show the usage dialog */
- MessageBox(NULL, BaculaUsageText, _("Bacula Usage"), MB_OK | MB_ICONINFORMATION);
-
- return 1;
- }
- return BaculaAppMain();
-}
-
-
-/*
- * Called as a thread from BaculaAppMain()
- * Here we handle the Windows messages
- */
-//DWORD WINAPI Main_Msg_Loop(LPVOID lpwThreadParam)
-void *Main_Msg_Loop(LPVOID lpwThreadParam)
-{
- DWORD old_servicethread = g_servicethread;
-
- pthread_detach(pthread_self());
-
- /* Since we are the only thread with a message loop
- * mark ourselves as the service thread so that
- * we can receive all the window events.
- */
- g_servicethread = GetCurrentThreadId();
-
- /* Create tray icon & menu if we're running as an app */
- bacMenu *menu = new bacMenu();
- if (menu == NULL) {
-// log_error_message("Could not create sys tray menu");
- PostQuitMessage(0);
- }
-
- /* Now enter the Windows message handling loop until told to quit! */
- MSG msg;
- while (GetMessage(&msg, NULL, 0,0) ) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- if (menu != NULL) {
- delete menu;
- }
-
- if (old_servicethread != 0) { /* started as NT service */
- /* Mark that we're no longer running */
- g_servicethread = 0;
-
- /* Tell the service manager that we've stopped. */
- ReportStatus(SERVICE_STOPPED, g_error, 0);
- }
- /* Tell main program to go away */
- terminate_filed(0);
-
- /* Should not get here */
- pthread_kill(main_tid, SIGTERM); /* ask main thread to terminate */
- sleep(1);
- kill(main_pid, SIGTERM); /* ask main thread to terminate */
- _exit(0);
-}
-
-
-/*
- * This is the main routine for Bacula when running as an application
- * (under Windows 95 or Windows NT)
- * Under NT, Bacula can also run as a service. The BaculaServerMain routine,
- * defined in the bacService header, is used instead when running as a service.
- */
-int BaculaAppMain()
-{
- /* DWORD dwThreadID; */
- pthread_t tid;
- DWORD dwCharsWritten;
-
- OSDependentInit();
-
- /* If no arguments were given then just run */
- if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) {
- if (opt_debug) {
- AllocConsole();
- }
- }
- WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL);
-
- VSSInit();
-
- WSA_Init();
-
- /* Set this process to be the last application to be shut down. */
- if (p_SetProcessShutdownParameters) {
- p_SetProcessShutdownParameters(0x100, 0);
- }
-
- HWND hservwnd = FindWindow(MENU_CLASS_NAME, NULL);
- if (hservwnd != NULL) {
- /* We don't allow multiple instances! */
- MessageBox(NULL, _("Another instance of Bacula is already running"), szAppName, MB_OK);
- _exit(0);
- }
-
- /* Create a thread to handle the Windows messages */
- pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0);
-
- /* Call the "real" Bacula */
- BaculaMain(num_command_args, command_args);
- PostQuitMessage(0);
- WSACleanup();
- _exit(0);
-}
+++ /dev/null
-// 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);
-}
# Using MinGW cross-compiler on GNU/Linux
#
# Written for Bacula by Howard Thomson, April 2006
+# for building using cross-complilation.
#
include ../Makefile.inc
--- /dev/null
+/*
+ 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$
+ *
+*/
+
+#include "bacula.h"
+#include "win32.h"
+
+static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ /* Get the dialog class pointer from USERDATA */
+ aboutDialog *about;
+
+ switch (uMsg) {
+ case WM_INITDIALOG:
+ /* save the dialog class pointer */
+ SetWindowLong(hwnd, GWL_USERDATA, lParam);
+ about = (aboutDialog *)lParam;
+
+ /* Show the dialog */
+ SetForegroundWindow(hwnd);
+ about->m_visible = true;
+ return true;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ case IDOK:
+ EndDialog(hwnd, true);
+ about = (aboutDialog *)GetWindowLong(hwnd, GWL_USERDATA);
+ about->m_visible = false;
+ return true;
+ }
+ break;
+
+ case WM_DESTROY:
+ 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);
+ }
+}
--- /dev/null
+/*
+ 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 __ABOUT_DIALOG_H_
+#define __ABOUT_DIALOG_H_ 1
+
+/* Define the aboutDialog class */
+class aboutDialog
+{
+public:
+ aboutDialog() { m_visible =false; };
+ ~aboutDialog() { };
+
+ void show(bool show);
+
+ bool m_visible;
+};
+
+#endif /* __ABOUT_H_ */
+++ /dev/null
-1 ICON "apcupsd.ico"\r
--- /dev/null
+/*
+ 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$
+ *
+ * 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 "win32.h"
+#include <signal.h>
+#include <pthread.h>
+
+#undef _WIN32_IE
+#define _WIN32_IE 0x0401
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#include <commctrl.h>
+
+/* Globals */
+HINSTANCE appInstance;
+DWORD mainthreadId;
+bool opt_debug = false;
+bool have_service_api;
+DWORD service_thread_id = 0;
+
+
+#define MAX_COMMAND_ARGS 100
+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";
+
+/*
+ *
+ * Main Windows entry point.
+ *
+ * We parse the command line and either calls the main App
+ * or starts up the service.
+ */
+int WINAPI WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, PSTR CmdLine,
+ int /*show*/)
+{
+ char *cmdLine = CmdLine;
+ char *wordPtr, *tempPtr;
+ int i, quote;
+ OSVERSIONINFO osversioninfo;
+ osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
+
+
+ /* Save the application instance and main thread id */
+ 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 = {
+ 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 = cmdLine;
+ while (*wordPtr && *wordPtr != ' ')
+ wordPtr++;
+ if (wordPtr > cmdLine) /* backup to char before space */
+ wordPtr--;
+ /* if first character is not a quote and last is, junk it */
+ if (*cmdLine != '"' && *wordPtr == '"') {
+ cmdLine = wordPtr + 1;
+ }
+
+ /*
+ * Build Unix style argc *argv[] for the main "Unix" code
+ * stripping out any Windows options
+ */
+
+ /* Don't NULL command_args[0] !!! */
+ for (i=1;i<MAX_COMMAND_ARGS;i++) {
+ command_args[i] = NULL;
+ }
+
+ char *pszArgs = bstrdup(cmdLine);
+ wordPtr = pszArgs;
+ quote = 0;
+ while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
+ wordPtr++;
+ if (*wordPtr == '\"') {
+ quote = 1;
+ wordPtr++;
+ } else if (*wordPtr == '/') {
+ /* Skip Windows options */
+ while (*wordPtr && (*wordPtr != ' ' && *wordPtr != '\t'))
+ wordPtr++;
+ while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
+ wordPtr++;
+ }
+ if (*wordPtr) {
+ while (*wordPtr && num_command_args < MAX_COMMAND_ARGS) {
+ tempPtr = wordPtr;
+ if (quote) {
+ while (*tempPtr && *tempPtr != '\"')
+ tempPtr++;
+ quote = 0;
+ } else {
+ while (*tempPtr && *tempPtr != ' ')
+ tempPtr++;
+ }
+ if (*tempPtr)
+ *(tempPtr++) = '\0';
+ command_args[num_command_args++] = wordPtr;
+ wordPtr = tempPtr;
+ while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
+ wordPtr++;
+ if (*wordPtr == '\"') {
+ quote = 1;
+ wordPtr++;
+ }
+ }
+ }
+
+ /*
+ * Now process Windows command line options. Most of these options
+ * are single shot -- i.e. we accept one option, do something and
+ * terminate.
+ */
+ for (i = 0; i < (int)strlen(cmdLine); i++) {
+ char *p = &cmdLine[i];
+
+ if (*p <= ' ') {
+ continue; /* toss junk */
+ }
+
+ if (*p != '/') {
+ break; /* syntax error */
+ }
+
+ /* Start as a service? */
+ if (strncasecmp(p, "/service", 8) == 0) {
+ return baculaServiceMain(); /* yes, run as a service */
+ }
+
+ /* Stop any running copy? */
+ if (strncasecmp(p, "/kill", 5) == 0) {
+ return stopRunningBacula();
+ }
+
+ /* Run app as user program? */
+ if (strncasecmp(p, "/run", 4) == 0) {
+ return BaculaAppMain(); /* yes, run as a user program */
+ }
+
+ /* Install Bacula in registry? */
+ if (strncasecmp(p, "/install", 8) == 0) {
+ return installService(p+8); /* Pass command options */
+ }
+
+ /* Remove Bacula registry entry? */
+ if (strncasecmp(p, "/remove", 7) == 0) {
+ return removeService();
+ }
+
+ /* Set debug mode? -- causes more dialogs to be displayed */
+ if (strncasecmp(p, "/debug", 6) == 0) {
+ opt_debug = true;
+ i += 6; /* skip /debug */
+ continue;
+ }
+
+ /* Display help? -- displays usage */
+ if (strncasecmp(p, "/help", 5) == 0) {
+ MessageBox(NULL, usage, APP_DESC, MB_OK|MB_ICONINFORMATION);
+ return 0;
+ }
+
+ MessageBox(NULL, cmdLine, _("Bad Command Line Option"), MB_OK);
+
+ /* Show the usage dialog */
+ MessageBox(NULL, usage, APP_DESC, MB_OK | MB_ICONINFORMATION);
+
+ return 1;
+ }
+ return BaculaAppMain();
+}
+
+
+/*
+ * Called as a thread from BaculaAppMain()
+ * Here we handle the Windows messages
+ */
+void *Main_Msg_Loop(LPVOID lpwThreadParam)
+{
+ MSG msg;
+
+ pthread_detach(pthread_self());
+
+ /*
+ * Since we are the only thread with a message loop
+ * mark ourselves as the service thread so that
+ * we can receive all the window events.
+ */
+ service_thread_id = GetCurrentThreadId();
+
+#ifdef HAVE_TRAY_MONITOR
+ /* Create tray icon & menu if we're running as an app */
+ trayMonitor *monitor = new trayMonitor();
+ if (monitor == NULL) {
+ PostQuitMessage(0);
+ }
+#endif
+
+ /* Now enter the Windows message handling loop until told to quit! */
+ while (GetMessage(&msg, NULL, 0,0) ) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ /* If we get here, we are shutting down */
+
+#ifdef HAVE_TRAY_MONITOR
+ if (monitor != NULL) {
+ delete monitor;
+ }
+#endif
+
+ if (have_service_api) {
+ /* Mark that we're no longer running */
+ service_thread_id = 0;
+ /* Tell the service manager that we've stopped. */
+ ReportStatus(SERVICE_STOPPED, service_error, 0);
+ }
+ /* Tell main "Unix" program to go away */
+ terminate_app(0);
+
+ /* Should not get here */
+ pthread_kill(main_tid, SIGTERM); /* ask main thread to terminate */
+ sleep(1);
+ kill(main_pid, SIGTERM); /* kill main thread */
+ _exit(0);
+}
+
+
+/*
+ * This is the main routine for Bacula when running as an application,
+ * or after the service has started up.
+ */
+int BaculaAppMain()
+{
+ pthread_t tid;
+ DWORD dwCharsWritten;
+
+ OSDependentInit();
+
+ /* If no arguments were given then just run */
+ if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) {
+ if (opt_debug) {
+ AllocConsole();
+ }
+ }
+ WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL);
+
+ /* Start up Volume Shadow Copy (only on FD) */
+ VSSInit();
+
+ /* Startup networking */
+ WSA_Init();
+
+ /* Set this process to be the last application to be shut down. */
+ if (p_SetProcessShutdownParameters) {
+ p_SetProcessShutdownParameters(0x100, 0);
+ }
+
+ /* Create a thread to handle the Windows messages */
+ pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0);
+
+ /* Call the Unix Bacula daemon */
+ BaculaMain(num_command_args, command_args);
+ PostQuitMessage(0); /* terminate our main message loop */
+
+ WSACleanup();
+ _exit(0);
+}
--- /dev/null
+/*
+ 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$
+ */
+
+#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__)
+
+extern int BaculaAppMain();
+extern void LogErrorMsg(char *msg, char *fname, int lineno);
+
+extern void output_status(void sendit(const char *msg, int len, void *sarg), void *arg);
+
+extern int BaculaMain(int argc, char *argv[]);
+extern BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint);
+extern void d_msg(const char *, int, int, const char *, ...);
+extern char *bac_status(char *buf, int buf_len);
+
+
+/* service.cpp */
+bool postToBacula(UINT message, WPARAM wParam, LPARAM lParam);
+bool isAService();
+int installService(const char *svc);
+int removeService();
+int stopRunningBacula();
+int baculaServiceMain();
+
+
+/* Globals */
+extern DWORD service_thread_id;
+extern DWORD service_error;
+extern bool opt_debug;
+extern bool have_service_api;
+extern HINSTANCE appInstance;
+extern int bacstat;
--- /dev/null
+/*
+ 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$
+ */
+
+/* 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_ABOUT 40000
+#define ID_STATUS 40001
+#define ID_CLOSE 40002
+
+/* Dialog definitions */
+#define IDD_ABOUT 201
+#define IDD_STATUS 202
--- /dev/null
+/*
+ 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 service routine, which is used by all three
+ * of the daemons. Each one compiles it with slightly different
+ * #defines.
+ *
+ */
+
+#include "bacula.h"
+#include "win32.h"
+
+/* Forward reference */
+static void set_service_description(SC_HANDLE hSCManager,
+ SC_HANDLE hService, LPSTR lpDesc);
+
+/* Other Window component dependencies */
+#define BAC_DEPENDENCIES __TEXT("tcpip\0afd\0")
+
+/* Service globals */
+SERVICE_STATUS_HANDLE service_handle;
+SERVICE_STATUS service_status;
+DWORD service_error = 0;
+static bool is_service = false;
+
+/* Forward references */
+void WINAPI serviceControlCallback(DWORD ctrlcode);
+BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint);
+DWORD WINAPI baculaWorkerThread(LPVOID lpwThreadParam);
+
+
+/*
+ * Post a message to a running instance of the app
+ */
+bool postToBacula(UINT message, WPARAM wParam, LPARAM lParam)
+{
+ /* Locate the Bacula menu window */
+ HWND hservwnd = FindWindow(APP_NAME, NULL);
+ if (hservwnd == NULL) {
+ return false;
+ }
+
+ /* Post the message to Bacula */
+ PostMessage(hservwnd, message, wParam, lParam);
+ return true;
+}
+
+
+/*
+ * Running as a service?
+ */
+bool isAService()
+{
+ return is_service;
+}
+
+/*
+ * terminate any running Bacula
+ */
+int stopRunningBacula()
+{
+ postToBacula(WM_CLOSE, 0, 0);
+ sleep(5);
+ return 0;
+}
+
+/*
+ * New style service start callback handler for the OS.
+ * the OS returns control here immediately after starting
+ * the service.
+ */
+void WINAPI serviceStartCallback(DWORD argc, char **argv)
+{
+ DWORD dwThreadID;
+
+ /* Register our service */
+ service_handle = RegisterServiceCtrlHandler(APP_NAME, serviceControlCallback);
+ if (!service_handle) {
+ log_error_message(_("RegisterServiceCtlHandler failed"));
+ MessageBox(NULL, _("Failure contacting the Service Handler"),
+ APP_DESC, MB_OK);
+ return;
+ }
+
+ service_status.dwServiceType = SERVICE_WIN32|SERVICE_INTERACTIVE_PROCESS;
+ service_status.dwServiceSpecificExitCode = 0;
+
+ /* Report status */
+ if (!ReportStatus(SERVICE_START_PENDING, NO_ERROR, 45000)) {
+ ReportStatus(SERVICE_STOPPED, service_error, 0);
+ log_error_message(_("Service start report failed"));
+ return;
+ }
+
+ /* Now create the Bacula worker thread */
+ (void)CreateThread(NULL, 0, baculaWorkerThread, NULL, 0, &dwThreadID);
+ return;
+}
+
+/*
+ * Stop our service
+ */
+static void serviceStop()
+{
+ /* Post a quit message our service thread */
+ if (service_thread_id != 0) {
+ PostThreadMessage(service_thread_id, WM_QUIT, 0, 0);
+ }
+}
+
+/*
+ * Service Control callback handler. The OS can call us here
+ * at any time, most often to stop the service.
+ */
+void WINAPI serviceControlCallback(DWORD ctrlcode)
+{
+ switch(ctrlcode) {
+ case SERVICE_CONTROL_STOP:
+ service_status.dwCurrentState = SERVICE_STOP_PENDING;
+ serviceStop(); /* our stop service routine */
+ break;
+ }
+
+ /* Report our status */
+ ReportStatus(service_status.dwCurrentState, NO_ERROR, 0);
+}
+
+
+/*
+ * Run Bacula as a service
+ */
+int baculaServiceMain()
+{
+ is_service = true; /* indicate we are running as a service */
+
+ if (have_service_api) { /* New style service API */
+ /* Tell OS where to dispatch service calls to us */
+ SERVICE_TABLE_ENTRY dispatchTable[] = {
+ {APP_NAME, (LPSERVICE_MAIN_FUNCTION)serviceStartCallback},
+ {NULL, NULL}};
+
+ /* Start the service control dispatcher */
+ if (!StartServiceCtrlDispatcher(dispatchTable)) {
+ log_error_message(_("StartServiceCtrlDispatcher failed."));
+ }
+ /* Note, this thread continues in the ServiceCallback routine */
+
+ } else { /* old style Win95/98/Me */
+ HINSTANCE kerneldll = LoadLibrary("KERNEL32.DLL");
+ if (kerneldll == NULL) {
+ MessageBox(NULL, _("KERNEL32.DLL not found: Bacula service not started"),
+ APP_DESC, MB_OK);
+ return 1;
+ }
+
+ /* Get entry point for 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"),
+ APP_DESC, MB_OK);
+ log_error_message(_("Registry service entry point not found"));
+ return 1;
+ }
+
+ RegisterService(0, 1); /* register us as a service */
+ BaculaAppMain(); /* call the main Bacula code */
+ RegisterService(0, 0); /* terminate the service */
+ FreeLibrary(kerneldll); /* free up kernel dll */
+ }
+ return 0;
+}
+
+
+/*
+ * New style service bacula worker thread
+ */
+DWORD WINAPI baculaWorkerThread(LPVOID lpwThreadParam)
+{
+ service_thread_id = GetCurrentThreadId();
+
+ if (!ReportStatus(SERVICE_RUNNING, NO_ERROR, 0)) {
+ MessageBox(NULL, _("Report Service failure"), APP_DESC, MB_OK);
+ log_error_message("ReportStatus RUNNING failed");
+ return 0;
+ }
+
+ /* Call Bacula main code */
+ BaculaAppMain();
+
+ /* Mark that we're no longer running */
+ service_thread_id = 0;
+
+ /* Tell the service manager that we've stopped */
+ ReportStatus(SERVICE_STOPPED, service_error, 0);
+ return 0;
+}
+
+
+
+/*
+ * Install the Bacula service on the OS -- very complicated
+ */
+int installService(const char *cmdOpts)
+{
+ const int maxlen = 2048;
+ char path[maxlen];
+ char svcmd[maxlen];
+
+ bsnprintf(svcmd, sizeof(svcmd), "service: install: %s", cmdOpts, APP_DESC, MB_OK);
+
+ /* Get our filename */
+ if (GetModuleFileName(NULL, path, maxlen-11) == 0) {
+ MessageBox(NULL, _("Unable to install the service"), APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ /* Create a valid command for starting the service */
+ if ((int)strlen(path) + (int)strlen(cmdOpts) + 30 < maxlen) {
+ bsnprintf(svcmd, sizeof(svcmd), "\"%s\" /service %s", path, cmdOpts);
+ } else {
+ log_error_message(_("Service command length too long"));
+ MessageBox(NULL, _("Service command length too long. Service not registered."),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ if (have_service_api) {
+ SC_HANDLE baculaService, serviceManager;
+
+ /* Open the service control manager */
+ serviceManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (!serviceManager) {
+ log_error_message("Open Service Manager failed");
+ MessageBox(NULL,
+ _("The Service Control Manager could not be contacted - the service was not installed"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ /* Now actually create the Bacula service entry */
+ baculaService = CreateService(
+ serviceManager,
+ APP_NAME, /* Our service name */
+ APP_DESC, /* Display name */
+ SERVICE_ALL_ACCESS,
+ SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
+ SERVICE_AUTO_START,
+ SERVICE_ERROR_NORMAL,
+ svcmd, /* Command string to start the service */
+ NULL,
+ NULL,
+ BAC_DEPENDENCIES, /* Services to start before us */
+ NULL, /* Use default SYSTEM account */
+ NULL);
+ if (!baculaService) {
+ CloseServiceHandle(serviceManager);
+ log_error_message("CreateService failed for " APP_DESC);
+ MessageBox(NULL, _("The Bacula service: " APP_NAME " could not be installed"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ /* Set a text description in the service manager's control panel */
+ set_service_description(serviceManager, baculaService,
+_("Provides file backup and restore services. Bacula -- the network backup solution."));
+
+ CloseServiceHandle(serviceManager);
+ CloseServiceHandle(baculaService);
+
+ } else {
+ /* Old style service -- create appropriate registry key path */
+ HKEY runservices;
+ if (RegCreateKey(HKEY_LOCAL_MACHINE,
+ "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices",
+ &runservices) != ERROR_SUCCESS) {
+ log_error_message(_("Cannot write System Registry for " APP_DESC));
+ MessageBox(NULL, _("The System Registry could not be updated - the Bacula service was not installed"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ /* Add the Bacula values */
+ if (RegSetValueEx(runservices, APP_NAME, 0, REG_SZ,
+ (unsigned char *)svcmd, strlen(svcmd)+1) != ERROR_SUCCESS) {
+ RegCloseKey(runservices);
+ log_error_message(_("Cannot add Bacula key to System Registry"));
+ MessageBox(NULL, _("The Bacula service: " APP_NAME " could not be installed"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+ RegCloseKey(runservices);
+ }
+
+ /* At this point the service is installed */
+ if (opt_debug) {
+ MessageBox(NULL,
+ _("The " APP_DESC "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. "),
+ APP_DESC, MB_ICONINFORMATION | MB_OK);
+ }
+ return 0;
+}
+
+
+/*
+ * Remove a service from the OS (normally done when we are installing
+ * a new version).
+ */
+int removeService()
+{
+ if (have_service_api) { /* Newer Windows platform (NT, Win2K, ...) */
+ SC_HANDLE serviceManager, baculaService;
+ int stat = 0;
+
+ serviceManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (serviceManager) {
+ /* Now get the Bacula service entry */
+ baculaService = OpenService(serviceManager, APP_NAME, SERVICE_ALL_ACCESS);
+ if (baculaService) {
+ SERVICE_STATUS status;
+
+ /* If the service is running, stop it */
+ if (ControlService(baculaService, SERVICE_CONTROL_STOP, &status)) {
+ while(QueryServiceStatus(baculaService, &status)) {
+ if (status.dwCurrentState == SERVICE_STOP_PENDING) {
+ sleep(1);
+ } else {
+ return 0;
+ }
+ }
+ if (status.dwCurrentState != SERVICE_STOPPED) {
+ MessageBox(NULL, _("The Bacula service: " APP_NAME " could not be stopped"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ }
+ }
+
+ if (DeleteService(baculaService)) {
+ if (opt_debug) {
+ MessageBox(NULL, _("The Bacula service: " APP_NAME " has been removed"),
+ APP_DESC, MB_ICONINFORMATION | MB_OK);
+ }
+ } else {
+ MessageBox(NULL, _("The Bacula service: " APP_NAME " could not be removed"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ stat = 1; /* error */
+ }
+ CloseServiceHandle(baculaService);
+
+ } else {
+ MessageBox(NULL, _("A existing Bacula service: " APP_NAME " could not be found for "
+ "removal. This is not normally an error."),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ }
+ CloseServiceHandle(serviceManager);
+ return stat;
+
+ } else {
+ MessageBox(NULL, _("The service Manager could not be contacted - the Bacula service was not removed"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 1; /* error */
+ }
+
+ } else { /* Old Win95/98/Me OS */
+ /* Open the registry path key */
+ 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"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ } else {
+ /* Now delete the Bacula entry */
+ if (RegDeleteValue(runservices, APP_NAME) != ERROR_SUCCESS) {
+ RegCloseKey(runservices);
+ MessageBox(NULL, _("Could not delete Registry key for " APP_NAME ".\n"
+ "The Bacula service could not be removed"), APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ }
+ RegCloseKey(runservices);
+ return 1;
+ }
+
+ /* Stop any running Bacula */
+ if (!stopRunningBacula()) {
+ MessageBox(NULL,
+ _("Bacula could not be contacted, probably not running"),
+ APP_DESC, MB_ICONEXCLAMATION | MB_OK);
+ return 0; /* not really an error */
+ }
+
+ /* At this point, the service has been removed */
+ if (opt_debug) {
+ MessageBox(NULL, _("The Bacula service has been removed"), APP_DESC, MB_ICONINFORMATION | MB_OK);
+ }
+ }
+ return 0;
+}
+
+
+/*
+ * This subroutine is called to report our current status to the
+ * new style service manager
+ */
+BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint)
+{
+ static DWORD checkpoint = 1;
+ BOOL result = TRUE;
+
+ /* No callbacks until we are started */
+ if (state == SERVICE_START_PENDING) {
+ service_status.dwControlsAccepted = 0;
+ } else {
+ service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+ }
+
+ /* Save global service_status state */
+ service_status.dwCurrentState = state;
+ service_status.dwWin32ExitCode = exitcode;
+ service_status.dwWaitHint = waithint;
+
+ /*
+ * Update the checkpoint variable so the service manager knows
+ * we are alive.
+ */
+ if (state == SERVICE_RUNNING || state == SERVICE_STOPPED) {
+ service_status.dwCheckPoint = 0;
+ } else {
+ service_status.dwCheckPoint = checkpoint++;
+ }
+
+ /* Send our new status */
+ result = SetServiceStatus(service_handle, &service_status);
+ if (!result) {
+ log_error_message(_("SetServiceStatus failed"));
+ }
+ return result;
+}
+
+/* Log an error message */
+void LogErrorMsg(char *message, char *fname, int lineno)
+{
+ char msgbuf[500];
+ HANDLE eventHandler;
+ char *strings[3];
+ LPTSTR msg;
+
+ service_error = GetLastError();
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ service_error,
+ 0,
+ (LPTSTR)&msg,
+ 0,
+ NULL);
+
+ /* Use the OS event logging to log the error */
+ eventHandler = RegisterEventSource(NULL, APP_NAME);
+
+ bsnprintf(msgbuf, sizeof(msgbuf), _("\n\n%s error: %ld at %s:%d"),
+ APP_NAME, service_error, fname, lineno);
+
+ strings[0] = msgbuf;
+ strings[1] = message;
+ strings[2] = msg;
+
+ if (eventHandler) {
+ ReportEvent(eventHandler, EVENTLOG_ERROR_TYPE,
+ 0, /* category */
+ 0, /* ID */
+ NULL, /* SID */
+ 3, /* Number of strings */
+ 0, /* raw data size */
+ (const char **)strings, /* error strings */
+ NULL); /* raw data */
+ DeregisterEventSource(eventHandler);
+ }
+ LocalFree(msg);
+}
+
+typedef BOOL (WINAPI * WinAPI)(SC_HANDLE, DWORD, LPVOID);
+
+/*
+ * This is amazingly complicated just to get a bit of English explanation
+ * in the service manager's dialog box.
+ */
+static 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);
+}
--- /dev/null
+/*
+ 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);
+ }
+}
--- /dev/null
+/*
+ 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 Status Dialog header file
+ *
+ * Kern Sibbald, August 2007
+ *
+ * Version $Id$
+ *
+ */
+
+#ifndef __STATUS_DIALOG_H_
+#define __STATUS_DIALOG_H_
+
+class statusDialog
+{
+public:
+ statusDialog() { m_visible = false; m_textWin = NULL; };
+ ~statusDialog() { };
+
+ void display();
+
+ void show(bool show);
+
+ void resize(HWND win, int width, int height);
+
+ bool m_visible;
+ HWND m_textWin;
+};
+
+#endif
--- /dev/null
+/*
+ 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);
+}
--- /dev/null
+/*
+ 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_ */
--- /dev/null
+/*
+ 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 "protos.h"
+#include "res.h"
+
+#ifdef HAVE_TRAY_MONITOR
+#include "aboutDialog.h"
+#include "statusDialog.h"
+#include "trayMonitor.h"
+#endif
+++ /dev/null
-/*
- 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.
-
- 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 "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;
-}
+++ /dev/null
-/*
- Bacula® - The Network Backup Solution
-
- Copyright (C) 2000-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.
-*/
-/*
- This file was inspired by the VNC Win32 code by ATT
-
- Kern E. Sibbald, 2000
-*/
-
-
-/* Header for 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);
-
- bool visible;
-};
-
-#endif
+++ /dev/null
-// 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__)
+++ /dev/null
-/*
- * 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
-
-
+++ /dev/null
-#include <winuser.h>\r
-#include <winver.h>\r
-#include "winres.h"\r
-#include "../../version.h"\r
-\r
-/* NB: Internationalization of this file will require some work... */\r
-#define N_(s) s\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Icons\r
-//\r
-\r
-// Icon with lowest ID value placed first to ensure application icon\r
-// remains consistent on all systems.\r
-IDI_BACULA ICON "bacula.ico"\r
-IDI_IDLE ICON "idle.ico"\r
-IDI_RUNNING ICON "running.ico"\r
-IDI_JOB_ERROR ICON "error.ico"\r
-IDI_JOB_WARNING ICON "warn.ico"\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Menu\r
-//\r
-\r
-IDR_TRAYMENU MENU\r
-BEGIN\r
- POPUP "tray"\r
- BEGIN\r
- MENUITEM N_("&Status"), ID_STATUS\r
- MENUITEM SEPARATOR\r
- MENUITEM N_("&About Bacula"), ID_ABOUT\r
-// MENUITEM SEPARATOR\r
-// MENUITEM N_("&Close Bacula"), ID_CLOSE\r
- END\r
-END\r
-\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Version\r
-//\r
-\r
-VS_VERSION_INFO VERSIONINFO\r
- FILEVERSION 1,1,0,0\r
- PRODUCTVERSION 1,1,0,0\r
- FILEFLAGSMASK VS_FFI_FILEFLAGSMASK\r
-#ifdef _DEBUG\r
- FILEFLAGS 0x1L\r
-#else\r
- FILEFLAGS 0 //\r
-#endif\r
- FILEOS VOS_NT_WINDOWS32\r
- FILETYPE VFT_APP\r
- FILESUBTYPE 0\r
-BEGIN\r
- BLOCK "StringFileInfo"\r
- BEGIN\r
- BLOCK "040904E0" // Lang=US English, CharSet=Windows Multiligual\r
- BEGIN\r
- VALUE "Comments", "by Kern Sibbald\0"\r
- VALUE "CompanyName", " \0"\r
- VALUE "FileDescription", "Bacula File daemon for Win32\0"\r
- VALUE "FileVersion", VERSION "\0"\r
- VALUE "InternalName", "Bacula\0"\r
- VALUE "LegalCopyright", "Copyright Free Software Foundation Europe e.V., 1999-2007\0"\r
- VALUE "LegalTrademarks", "Licensed under GNU GPL 2.0\0"\r
- VALUE "OriginalFilename", "bacula-fd.exe\0"\r
- VALUE "PrivateBuild", "\0"\r
- VALUE "ProductName", "Bacula - Win32 Version\0"\r
- VALUE "ProductVersion", VERSION\r
- VALUE "SpecialBuild", "\0"\r
- END\r
- END\r
- BLOCK "VarFileInfo"\r
- BEGIN\r
- VALUE "Translation", 0x409, 1252 // US English, Multilingual\r
- END\r
-END\r
-\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// RT_MANIFEST\r
-//\r
-CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "bacula-fd.manifest"\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Bitmap\r
-//\r
-\r
-IDB_BACULABMP BITMAP DISCARDABLE "bacula.bmp"\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// String Table\r
-//\r
-\r
-STRINGTABLE \r
-BEGIN\r
- IDI_BACULA "Bacula"\r
-END\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// About Dialog\r
-//\r
-\r
-IDD_ABOUT DIALOG 0, 0, 250, 145\r
-STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU\r
-CAPTION "About Bacula"\r
-FONT 8, "MS Sans Serif"\r
-BEGIN\r
- DEFPUSHBUTTON "OK",IDOK,190,120,50,15\r
-// CONTROL "\3", IDC_BACULABMP,"Static",SS_ICON | SS_CENTERIMAGE |\r
-// SS_SUNKEN,7,5,73,65\r
-#ifndef HAVE_MINGW\r
- CONTROL IDB_BACULABMP,IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,32,32\r
-#endif\r
-\r
- LTEXT N_(" by Kern Sibbald"),-1,134,38,78,10\r
- LTEXT N_("For more information, see:"),-1,115,60,100,10\r
- LTEXT " www.bacula.org",-1,115,70,100,10\r
-// LTEXT " ",-1,69,81,100,10\r
-// LTEXT " ",-1,90,70,100,10\r
- LTEXT "Copyright (C) 1999-2007, Free Software Foundation Europe e.V.",-1,7,120,175,10\r
- LTEXT N_("Licensed under GNU GPL 2.0."),-1,7,130,175,10\r
- RTEXT N_("Build Date:"),-1,108,24,42,8\r
- RTEXT N_("Bacula Version:"),-1,100,9,50,8\r
- LTEXT VERSION,-1,159,10,65,8\r
- LTEXT BDATE,-1,159,24,65,10\r
-\r
-END\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Status Dialog\r
-//\r
-\r
-IDD_STATUS DIALOGEX 0, 0, 411, 244\r
-STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME\r
-CAPTION N_("Bacula Status")\r
-FONT 8, "Courier New"\r
-BEGIN\r
- DEFPUSHBUTTON "&OK",IDOK,355,5,51,15\r
- EDITTEXT IDC_TEXTDISPLAY, 2, 2, 350, 240, WS_VSCROLL | WS_HSCROLL | WS_BORDER | ES_READONLY | ES_MULTILINE\r
-END\r
+++ /dev/null
-// 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
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- Bacula® - The Network Backup Solution
-
- Copyright (C) 2000-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 Status Dialog header file
- *
- */
-
-#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;
-};
-
-#endif
+++ /dev/null
-// 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);
-}
// 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;
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;
include ../Makefile.inc
INCLUDES = \
+ -I. \
-I../../stored \
$(INCLUDE_DDK) \
$(INCLUDE_PTHREADS) \
$(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
##########################################################################
$(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) \
LIBS_STORED = \
$(LIBS_PTHREADS) \
+ -lole32 \
+ -loleaut32 \
-lwsock32 \
+ -luuid \
-lcomctl32
######################################################################
--- /dev/null
+#include "../libwin32/bacula.rc"
--- /dev/null
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+ ProjectType="Visual C++"\r
+ Version="8.00"\r
+ Name="baculasd"\r
+ ProjectGUID="{F5F063F8-11A1-475A-82E2-19759BB40B25}"\r
+ RootNamespace="baculasd"\r
+ >\r
+ <Platforms>\r
+ <Platform\r
+ Name="Win32"\r
+ />\r
+ </Platforms>\r
+ <ToolFiles>\r
+ </ToolFiles>\r
+ <Configurations>\r
+ <Configuration\r
+ Name="Debug|Win32"\r
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+ IntermediateDirectory="$(ConfigurationName)"\r
+ ConfigurationType="1"\r
+ UseOfMFC="0"\r
+ ATLMinimizesCRunTimeLibraryUsage="false"\r
+ CharacterSet="2"\r
+ >\r
+ <Tool\r
+ Name="VCPreBuildEventTool"\r
+ />\r
+ <Tool\r
+ Name="VCCustomBuildTool"\r
+ />\r
+ <Tool\r
+ Name="VCXMLDataGeneratorTool"\r
+ />\r
+ <Tool\r
+ Name="VCWebServiceProxyGeneratorTool"\r
+ />\r
+ <Tool\r
+ Name="VCMIDLTool"\r
+ TypeLibraryName=".\Debug/baculasd.tlb"\r
+ HeaderFileName=""\r
+ />\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ Optimization="0"\r
+ AdditionalIncludeDirectories="../../..;../../compat;../../../stored;../../../../../depkgs-msvc/include"\r
+ PreprocessorDefinitions="_DEBUG;WIN32;_CONSOLE;HAVE_WIN32;USING_DLL;_USE_32BIT_TIME_T;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"\r
+ MinimalRebuild="true"\r
+ BasicRuntimeChecks="3"\r
+ RuntimeLibrary="3"\r
+ UsePrecompiledHeader="0"\r
+ BrowseInformation="1"\r
+ WarningLevel="3"\r
+ SuppressStartupBanner="true"\r
+ DebugInformationFormat="4"\r
+ />\r
+ <Tool\r
+ Name="VCManagedResourceCompilerTool"\r
+ />\r
+ <Tool\r
+ Name="VCResourceCompilerTool"\r
+ PreprocessorDefinitions="_DEBUG"\r
+ Culture="1033"\r
+ />\r
+ <Tool\r
+ Name="VCPreLinkEventTool"\r
+ />\r
+ <Tool\r
+ Name="VCLinkerTool"\r
+ AdditionalDependencies="pthreadVCE.lib zlib.lib wsock32.lib comctl32.lib atlsd.lib"\r
+ OutputFile="$(OutDir)/bacula-sd.exe"\r
+ LinkIncremental="0"\r
+ SuppressStartupBanner="true"\r
+ AdditionalLibraryDirectories="../../../../../depkgs-msvc/lib"\r
+ IgnoreDefaultLibraryNames="msvcrt"\r
+ GenerateDebugInformation="true"\r
+ SubSystem="2"\r
+ TargetMachine="1"\r
+ />\r
+ <Tool\r
+ Name="VCALinkTool"\r
+ />\r
+ <Tool\r
+ Name="VCManifestTool"\r
+ />\r
+ <Tool\r
+ Name="VCXDCMakeTool"\r
+ />\r
+ <Tool\r
+ Name="VCBscMakeTool"\r
+ SuppressStartupBanner="true"\r
+ OutputFile=".\Debug/baculasd.bsc"\r
+ />\r
+ <Tool\r
+ Name="VCFxCopTool"\r
+ />\r
+ <Tool\r
+ Name="VCAppVerifierTool"\r
+ />\r
+ <Tool\r
+ Name="VCWebDeploymentTool"\r
+ />\r
+ <Tool\r
+ Name="VCPostBuildEventTool"\r
+ />\r
+ </Configuration>\r
+ <Configuration\r
+ Name="Release|Win32"\r
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+ IntermediateDirectory="$(ConfigurationName)"\r
+ ConfigurationType="1"\r
+ UseOfMFC="0"\r
+ UseOfATL="1"\r
+ ATLMinimizesCRunTimeLibraryUsage="false"\r
+ CharacterSet="2"\r
+ WholeProgramOptimization="1"\r
+ >\r
+ <Tool\r
+ Name="VCPreBuildEventTool"\r
+ />\r
+ <Tool\r
+ Name="VCCustomBuildTool"\r
+ />\r
+ <Tool\r
+ Name="VCXMLDataGeneratorTool"\r
+ />\r
+ <Tool\r
+ Name="VCWebServiceProxyGeneratorTool"\r
+ />\r
+ <Tool\r
+ Name="VCMIDLTool"\r
+ TypeLibraryName=".\Release/baculasd.tlb"\r
+ HeaderFileName=""\r
+ />\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ Optimization="4"\r
+ InlineFunctionExpansion="2"\r
+ EnableIntrinsicFunctions="true"\r
+ AdditionalIncludeDirectories="../../..;../../compat;../../../stored;../../../../../depkgs-msvc/include"\r
+ PreprocessorDefinitions="NDEBUG;_CONSOLE;HAVE_WIN32;USING_DLL;_USE_32BIT_TIME_T;_WIN32_WINNT=0x0501;_CRT_SECURE_NO_DEPRECATE"\r
+ StringPooling="true"\r
+ RuntimeLibrary="2"\r
+ EnableFunctionLevelLinking="true"\r
+ UsePrecompiledHeader="0"\r
+ BrowseInformation="1"\r
+ WarningLevel="3"\r
+ SuppressStartupBanner="true"\r
+ Detect64BitPortabilityProblems="false"\r
+ DebugInformationFormat="3"\r
+ />\r
+ <Tool\r
+ Name="VCManagedResourceCompilerTool"\r
+ />\r
+ <Tool\r
+ Name="VCResourceCompilerTool"\r
+ PreprocessorDefinitions="NDEBUG"\r
+ Culture="1033"\r
+ AdditionalIncludeDirectories=""\r
+ />\r
+ <Tool\r
+ Name="VCPreLinkEventTool"\r
+ />\r
+ <Tool\r
+ Name="VCLinkerTool"\r
+ AdditionalDependencies="pthreadVCE.lib zlib.lib wsock32.lib comctl32.lib atls.lib"\r
+ OutputFile="$(OutDir)\bacula-sd.exe"\r
+ LinkIncremental="0"\r
+ SuppressStartupBanner="true"\r
+ AdditionalLibraryDirectories="../../../../../depkgs-msvc/lib"\r
+ DelayLoadDLLs="$(NOINHERIT)"\r
+ GenerateDebugInformation="true"\r
+ SubSystem="2"\r
+ TargetMachine="1"\r
+ />\r
+ <Tool\r
+ Name="VCALinkTool"\r
+ />\r
+ <Tool\r
+ Name="VCManifestTool"\r
+ />\r
+ <Tool\r
+ Name="VCXDCMakeTool"\r
+ />\r
+ <Tool\r
+ Name="VCBscMakeTool"\r
+ SuppressStartupBanner="true"\r
+ OutputFile=".\Release/baculasd.bsc"\r
+ />\r
+ <Tool\r
+ Name="VCFxCopTool"\r
+ />\r
+ <Tool\r
+ Name="VCAppVerifierTool"\r
+ />\r
+ <Tool\r
+ Name="VCWebDeploymentTool"\r
+ />\r
+ <Tool\r
+ Name="VCPostBuildEventTool"\r
+ />\r
+ </Configuration>\r
+ </Configurations>\r
+ <References>\r
+ </References>\r
+ <Files>\r
+ <Filter\r
+ Name="Source Files"\r
+ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+ >\r
+ <File\r
+ RelativePath="..\mtops.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\status.c"\r
+ >\r
+ <FileConfiguration\r
+ Name="Debug|Win32"\r
+ >\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ CompileAs="2"\r
+ />\r
+ </FileConfiguration>\r
+ <FileConfiguration\r
+ Name="Release|Win32"\r
+ >\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ CompileAs="2"\r
+ />\r
+ </FileConfiguration>\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\stored.c"\r
+ >\r
+ <FileConfiguration\r
+ Name="Debug|Win32"\r
+ >\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ CompileAs="2"\r
+ />\r
+ </FileConfiguration>\r
+ <FileConfiguration\r
+ Name="Release|Win32"\r
+ >\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ CompileAs="2"\r
+ />\r
+ </FileConfiguration>\r
+ </File>\r
+ <File\r
+ RelativePath=".\winabout.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winmain.cpp"\r
+ >\r
+ <FileConfiguration\r
+ Name="Debug|Win32"\r
+ >\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ CompileAs="2"\r
+ />\r
+ </FileConfiguration>\r
+ </File>\r
+ <File\r
+ RelativePath=".\winservice.cpp"\r
+ >\r
+ <FileConfiguration\r
+ Name="Debug|Win32"\r
+ >\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ CompileAs="2"\r
+ />\r
+ </FileConfiguration>\r
+ </File>\r
+ <File\r
+ RelativePath=".\winstat.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\wintray.cpp"\r
+ >\r
+ </File>\r
+ </Filter>\r
+ <Filter\r
+ Name="Header Files"\r
+ Filter="h;hpp;hxx;hm;inl"\r
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+ >\r
+ <File\r
+ RelativePath="..\..\..\stored\block.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\bsr.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\dev.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\protos.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\record.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\reserve.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\stored.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\stored\stored_conf.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winabout.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winbacula.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winres.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winservice.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winstat.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\wintray.h"\r
+ >\r
+ </File>\r
+ </Filter>\r
+ <Filter\r
+ Name="Resource Files"\r
+ Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+ >\r
+ <File\r
+ RelativePath=".\bacula-sd.manifest"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\bacula.bmp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\bacula.ico"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\error.ico"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\idle.ico"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\running.ico"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\warn.ico"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\winres.rc"\r
+ >\r
+ </File>\r
+ </Filter>\r
+ </Files>\r
+ <Globals>\r
+ </Globals>\r
+</VisualStudioProject>\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?> \r
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> \r
- <assemblyIdentity \r
- version="1.0.0.0" \r
- processorArchitecture="X86" \r
- name="Bacula.Bacula-sd" \r
- type="win32" /> \r
- <description>Bacula Storage daemon for Win32</description> \r
- <dependency> \r
- <dependentAssembly> \r
- <assemblyIdentity \r
- type="win32" \r
- name="Microsoft.Windows.Common-Controls" \r
- version="6.0.0.0" \r
- processorArchitecture="X86" \r
- publicKeyToken="6595b64144ccf1df" \r
- language="*" /> \r
- </dependentAssembly> \r
- </dependency> \r
-</assembly> \r
-\r
+++ /dev/null
-1 ICON "apcupsd.ico"\r
+++ /dev/null
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioProject\r
- ProjectType="Visual C++"\r
- Version="8.00"\r
- Name="baculasd"\r
- ProjectGUID="{F5F063F8-11A1-475A-82E2-19759BB40B25}"\r
- RootNamespace="baculasd"\r
- >\r
- <Platforms>\r
- <Platform\r
- Name="Win32"\r
- />\r
- </Platforms>\r
- <ToolFiles>\r
- </ToolFiles>\r
- <Configurations>\r
- <Configuration\r
- Name="Debug|Win32"\r
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
- IntermediateDirectory="$(ConfigurationName)"\r
- ConfigurationType="1"\r
- UseOfMFC="0"\r
- ATLMinimizesCRunTimeLibraryUsage="false"\r
- CharacterSet="2"\r
- >\r
- <Tool\r
- Name="VCPreBuildEventTool"\r
- />\r
- <Tool\r
- Name="VCCustomBuildTool"\r
- />\r
- <Tool\r
- Name="VCXMLDataGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCWebServiceProxyGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCMIDLTool"\r
- TypeLibraryName=".\Debug/baculasd.tlb"\r
- HeaderFileName=""\r
- />\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- Optimization="0"\r
- AdditionalIncludeDirectories="../../..;../../compat;../../../stored;../../../../../depkgs-msvc/include"\r
- PreprocessorDefinitions="_DEBUG;WIN32;_CONSOLE;HAVE_WIN32;USING_DLL;_USE_32BIT_TIME_T;_WIN32_WINNT=0x0500;_CRT_SECURE_NO_DEPRECATE"\r
- MinimalRebuild="true"\r
- BasicRuntimeChecks="3"\r
- RuntimeLibrary="3"\r
- UsePrecompiledHeader="0"\r
- BrowseInformation="1"\r
- WarningLevel="3"\r
- SuppressStartupBanner="true"\r
- DebugInformationFormat="4"\r
- />\r
- <Tool\r
- Name="VCManagedResourceCompilerTool"\r
- />\r
- <Tool\r
- Name="VCResourceCompilerTool"\r
- PreprocessorDefinitions="_DEBUG"\r
- Culture="1033"\r
- />\r
- <Tool\r
- Name="VCPreLinkEventTool"\r
- />\r
- <Tool\r
- Name="VCLinkerTool"\r
- AdditionalDependencies="pthreadVCE.lib zlib.lib wsock32.lib comctl32.lib atlsd.lib"\r
- OutputFile="$(OutDir)/bacula-sd.exe"\r
- LinkIncremental="0"\r
- SuppressStartupBanner="true"\r
- AdditionalLibraryDirectories="../../../../../depkgs-msvc/lib"\r
- IgnoreDefaultLibraryNames="msvcrt"\r
- GenerateDebugInformation="true"\r
- SubSystem="2"\r
- TargetMachine="1"\r
- />\r
- <Tool\r
- Name="VCALinkTool"\r
- />\r
- <Tool\r
- Name="VCManifestTool"\r
- />\r
- <Tool\r
- Name="VCXDCMakeTool"\r
- />\r
- <Tool\r
- Name="VCBscMakeTool"\r
- SuppressStartupBanner="true"\r
- OutputFile=".\Debug/baculasd.bsc"\r
- />\r
- <Tool\r
- Name="VCFxCopTool"\r
- />\r
- <Tool\r
- Name="VCAppVerifierTool"\r
- />\r
- <Tool\r
- Name="VCWebDeploymentTool"\r
- />\r
- <Tool\r
- Name="VCPostBuildEventTool"\r
- />\r
- </Configuration>\r
- <Configuration\r
- Name="Release|Win32"\r
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
- IntermediateDirectory="$(ConfigurationName)"\r
- ConfigurationType="1"\r
- UseOfMFC="0"\r
- UseOfATL="1"\r
- ATLMinimizesCRunTimeLibraryUsage="false"\r
- CharacterSet="2"\r
- WholeProgramOptimization="1"\r
- >\r
- <Tool\r
- Name="VCPreBuildEventTool"\r
- />\r
- <Tool\r
- Name="VCCustomBuildTool"\r
- />\r
- <Tool\r
- Name="VCXMLDataGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCWebServiceProxyGeneratorTool"\r
- />\r
- <Tool\r
- Name="VCMIDLTool"\r
- TypeLibraryName=".\Release/baculasd.tlb"\r
- HeaderFileName=""\r
- />\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- Optimization="4"\r
- InlineFunctionExpansion="2"\r
- EnableIntrinsicFunctions="true"\r
- AdditionalIncludeDirectories="../../..;../../compat;../../../stored;../../../../../depkgs-msvc/include"\r
- PreprocessorDefinitions="NDEBUG;_CONSOLE;HAVE_WIN32;USING_DLL;_USE_32BIT_TIME_T;_WIN32_WINNT=0x0501;_CRT_SECURE_NO_DEPRECATE"\r
- StringPooling="true"\r
- RuntimeLibrary="2"\r
- EnableFunctionLevelLinking="true"\r
- UsePrecompiledHeader="0"\r
- BrowseInformation="1"\r
- WarningLevel="3"\r
- SuppressStartupBanner="true"\r
- Detect64BitPortabilityProblems="false"\r
- DebugInformationFormat="3"\r
- />\r
- <Tool\r
- Name="VCManagedResourceCompilerTool"\r
- />\r
- <Tool\r
- Name="VCResourceCompilerTool"\r
- PreprocessorDefinitions="NDEBUG"\r
- Culture="1033"\r
- AdditionalIncludeDirectories=""\r
- />\r
- <Tool\r
- Name="VCPreLinkEventTool"\r
- />\r
- <Tool\r
- Name="VCLinkerTool"\r
- AdditionalDependencies="pthreadVCE.lib zlib.lib wsock32.lib comctl32.lib atls.lib"\r
- OutputFile="$(OutDir)\bacula-sd.exe"\r
- LinkIncremental="0"\r
- SuppressStartupBanner="true"\r
- AdditionalLibraryDirectories="../../../../../depkgs-msvc/lib"\r
- DelayLoadDLLs="$(NOINHERIT)"\r
- GenerateDebugInformation="true"\r
- SubSystem="2"\r
- TargetMachine="1"\r
- />\r
- <Tool\r
- Name="VCALinkTool"\r
- />\r
- <Tool\r
- Name="VCManifestTool"\r
- />\r
- <Tool\r
- Name="VCXDCMakeTool"\r
- />\r
- <Tool\r
- Name="VCBscMakeTool"\r
- SuppressStartupBanner="true"\r
- OutputFile=".\Release/baculasd.bsc"\r
- />\r
- <Tool\r
- Name="VCFxCopTool"\r
- />\r
- <Tool\r
- Name="VCAppVerifierTool"\r
- />\r
- <Tool\r
- Name="VCWebDeploymentTool"\r
- />\r
- <Tool\r
- Name="VCPostBuildEventTool"\r
- />\r
- </Configuration>\r
- </Configurations>\r
- <References>\r
- </References>\r
- <Files>\r
- <Filter\r
- Name="Source Files"\r
- Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
- >\r
- <File\r
- RelativePath="..\mtops.cpp"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\status.c"\r
- >\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
- <FileConfiguration\r
- Name="Release|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\stored.c"\r
- >\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
- <FileConfiguration\r
- Name="Release|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
- </File>\r
- <File\r
- RelativePath=".\winabout.cpp"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winmain.cpp"\r
- >\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
- </File>\r
- <File\r
- RelativePath=".\winservice.cpp"\r
- >\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
- </File>\r
- <File\r
- RelativePath=".\winstat.cpp"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\wintray.cpp"\r
- >\r
- </File>\r
- </Filter>\r
- <Filter\r
- Name="Header Files"\r
- Filter="h;hpp;hxx;hm;inl"\r
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
- >\r
- <File\r
- RelativePath="..\..\..\stored\block.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\bsr.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\dev.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\protos.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\record.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\reserve.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\stored.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath="..\..\..\stored\stored_conf.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winabout.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winbacula.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winres.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winservice.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winstat.h"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\wintray.h"\r
- >\r
- </File>\r
- </Filter>\r
- <Filter\r
- Name="Resource Files"\r
- Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
- >\r
- <File\r
- RelativePath=".\bacula-sd.manifest"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\bacula.bmp"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\bacula.ico"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\error.ico"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\idle.ico"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\running.ico"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\warn.ico"\r
- >\r
- </File>\r
- <File\r
- RelativePath=".\winres.rc"\r
- >\r
- </File>\r
- </Filter>\r
- </Files>\r
- <Globals>\r
- </Globals>\r
-</VisualStudioProject>\r
+++ /dev/null
-/*
- 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;
-}
+++ /dev/null
-/*
- 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.
-
- 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.
-*/
-
-
-/* Object implementing the About dialog for Bacula */
-
-class bacAbout;
-
-#ifndef _WINABOUT_H_
-#define _WINABOUT_H_ 1
-
-/* Define the bacAbout class */
-class bacAbout
-{
-public:
- bacAbout();
- ~bacAbout();
-
- /* The dialog box window proc */
- static BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-
- void Show(BOOL show);
-
- /* Object local storage */
- bool visible;
-};
-
-#endif
+++ /dev/null
-// 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__)
+++ /dev/null
-/*
- 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 <unistd.h>
-#include <ctype.h>
-
-#include "bacula.h"
-#include "winbacula.h"
-#include "wintray.h"
-#include "winservice.h"
-#include <signal.h>
-#include <pthread.h>
-
-#undef _WIN32_IE
-#define _WIN32_IE 0x0501
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
-#include <commctrl.h>
-
-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<MAX_COMMAND_ARGS;i++)
- command_args[i] = NULL;
-
- char *pszArgs = bstrdup(szCmdLine);
- wordPtr = pszArgs;
- quote = 0;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- if (*wordPtr == '\"') {
- quote = 1;
- wordPtr++;
- } else if (*wordPtr == '/') {
- /* Skip Windows options */
- while (*wordPtr && (*wordPtr != ' ' && *wordPtr != '\t'))
- wordPtr++;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- }
- if (*wordPtr) {
- while (*wordPtr && num_command_args < MAX_COMMAND_ARGS) {
- tempPtr = wordPtr;
- if (quote) {
- while (*tempPtr && *tempPtr != '\"')
- tempPtr++;
- quote = 0;
- } else {
- while (*tempPtr && *tempPtr != ' ')
- tempPtr++;
- }
- if (*tempPtr)
- *(tempPtr++) = '\0';
- command_args[num_command_args++] = wordPtr;
- wordPtr = tempPtr;
- while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
- wordPtr++;
- if (*wordPtr == '\"') {
- quote = 1;
- wordPtr++;
- }
- }
- }
-
- /*
- * Now process Windows command line options
- */
- for (i = 0; i < (int)strlen(szCmdLine); i++) {
- if (szCmdLine[i] <= ' ') {
- continue;
- }
-
- if (szCmdLine[i] != '/') {
- break;
- }
-
- /* Now check for command-line arguments */
-
- /* /debug install quietly -- no prompts */
- if (strnicmp(&szCmdLine[i], BaculaOptDebug, sizeof(BaculaOptDebug) - 1) == 0) {
- opt_debug = true;
- i += sizeof(BaculaOptDebug) - 1;
- continue;
- }
-
- /* /service start service */
- if (strnicmp(&szCmdLine[i], BaculaRunService, sizeof(BaculaRunService) - 1) == 0) {
- /* Run Bacula as a service */
- return bacService::BaculaServiceMain();
- }
- /* /run (this is the default if no command line arguments) */
- if (strnicmp(&szCmdLine[i], BaculaRunAsUserApp, sizeof(BaculaRunAsUserApp) - 1) == 0) {
- /* Bacula is being run as a user-level program */
- return BaculaAppMain();
- }
- /* /install */
- if (strnicmp(&szCmdLine[i], BaculaInstallService, sizeof(BaculaInstallService) - 1) == 0) {
- /* Install Bacula as a service */
- return bacService::InstallService(&szCmdLine[i + sizeof(BaculaInstallService) - 1]);
- }
- /* /remove */
- if (strnicmp(&szCmdLine[i], BaculaRemoveService, sizeof(BaculaRemoveService) - 1) == 0) {
- /* Remove the Bacula service */
- return bacService::RemoveService();
- }
-
- /* /about */
- if (strnicmp(&szCmdLine[i], BaculaShowAbout, sizeof(BaculaShowAbout) - 1) == 0) {
- /* Show Bacula's about box */
- return bacService::ShowAboutBox();
- }
-
- /* /status */
- if (strnicmp(&szCmdLine[i], BaculaShowStatus, sizeof(BaculaShowStatus) - 1) == 0) {
- /* Show Bacula's status box */
- return bacService::ShowStatus();
- }
-
- /* /kill */
- if (strnicmp(&szCmdLine[i], BaculaKillRunningCopy, sizeof(BaculaKillRunningCopy) - 1) == 0) {
- /* Kill running copy of Bacula */
- return bacService::KillRunningCopy();
- }
-
- /* /help */
- if (strnicmp(&szCmdLine[i], BaculaShowHelp, sizeof(BaculaShowHelp) - 1) == 0) {
- MessageBox(NULL, BaculaUsageText, _("Bacula Usage"), MB_OK|MB_ICONINFORMATION);
- return 0;
- }
-
- MessageBox(NULL, szCmdLine, _("Bad Command Line Options"), MB_OK);
-
- /* Show the usage dialog */
- MessageBox(NULL, BaculaUsageText, _("Bacula Usage"), MB_OK | MB_ICONINFORMATION);
- return 1;
- }
-
- return BaculaAppMain();
-}
-
-
-/*
- * Called as a thread from BaculaAppMain()
- * Here we handle the Windows messages
- */
-//DWORD WINAPI Main_Msg_Loop(LPVOID lpwThreadParam)
-void *Main_Msg_Loop(LPVOID lpwThreadParam)
-{
- DWORD old_servicethread = g_servicethread;
-
-
- pthread_detach(pthread_self());
-
- /* Since we are the only thread with a message loop
- * mark ourselves as the service thread so that
- * we can receive all the window events.
- */
- g_servicethread = GetCurrentThreadId();
-
- /* Create tray icon & menu if we're running as an app */
- bacMenu *menu = new bacMenu();
- if (menu == NULL) {
-// log_error_message("Could not create sys tray menu");
- PostQuitMessage(0);
- }
-
- /* Now enter the Windows message handling loop until told to quit! */
- MSG msg;
- while (GetMessage(&msg, NULL, 0,0) ) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- if (menu != NULL) {
- delete menu;
- }
-
- if (old_servicethread != 0) { /* started as NT service */
- /* Mark that we're no longer running */
- g_servicethread = 0;
-
- /* Tell the service manager that we've stopped. */
- ReportStatus(SERVICE_STOPPED, g_error, 0);
- }
- /* Tell main program to go away */
- terminate_stored(0);
-
- /* Should not get here */
- pthread_kill(main_tid, SIGTERM); /* ask main thread to terminate */
- sleep(1);
- kill(main_pid, SIGTERM); /* ask main thread to terminate */
- _exit(0);
-}
-
-
-/*
- * This is the main routine for Bacula when running as an application
- * (under Windows 95 or Windows NT)
- * Under NT, Bacula can also run as a service. The BaculaServerMain routine,
- * defined in the bacService header, is used instead when running as a service.
- */
-int BaculaAppMain()
-{
- /* DWORD dwThreadID; */
- pthread_t tid;
- DWORD dwCharsWritten;
-
- InitWinAPIWrapper();
-
- WSA_Init();
-
- /* If no arguments were given then just run */
- if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) {
- if (opt_debug) {
- AllocConsole();
- }
- }
- WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL);
-
- /* Set this process to be the last application to be shut down. */
- if (p_SetProcessShutdownParameters) {
- p_SetProcessShutdownParameters(0x100, 0);
- }
-
- HWND hservwnd = FindWindow(MENU_CLASS_NAME, NULL);
- if (hservwnd != NULL) {
- /* We don't allow multiple instances! */
- MessageBox(NULL, _("Another instance of Bacula is already running"), szAppName, MB_OK);
- _exit(0);
- }
-
- /* Create a thread to handle the Windows messages */
- pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0);
-
- /* Call the "real" Bacula */
- BaculaMain(num_command_args, command_args);
- PostQuitMessage(0);
- WSACleanup();
- _exit(0);
-}
+++ /dev/null
-/*
- * 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
-
-
+++ /dev/null
-#include <winuser.h>\r
-#include <winver.h>\r
-#include "winres.h"\r
-#include "../../../version.h"\r
-\r
-/* NB: Internationalization of this file will require some work... */\r
-#define N_(s) s\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Icons\r
-//\r
-\r
-// Icon with lowest ID value placed first to ensure application icon\r
-// remains consistent on all systems.\r
-IDI_BACULA ICON "bacula.ico"\r
-IDI_IDLE ICON "idle.ico"\r
-IDI_RUNNING ICON "running.ico"\r
-IDI_JOB_ERROR ICON "error.ico"\r
-IDI_JOB_WARNING ICON "warn.ico"\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Menu\r
-//\r
-\r
-IDR_TRAYMENU MENU\r
-BEGIN\r
- POPUP "tray"\r
- BEGIN\r
- MENUITEM N_("&Status"), ID_STATUS\r
- MENUITEM SEPARATOR\r
- MENUITEM N_("&About Bacula"), ID_ABOUT\r
- MENUITEM SEPARATOR\r
- MENUITEM N_("&Close Bacula"), ID_CLOSE\r
- END\r
-END\r
-\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Version\r
-//\r
-\r
-VS_VERSION_INFO VERSIONINFO\r
- FILEVERSION 1,1,0,0\r
- PRODUCTVERSION 1,1,0,0\r
- FILEFLAGSMASK VS_FFI_FILEFLAGSMASK\r
-#ifdef _DEBUG\r
- FILEFLAGS 0x1L\r
-#else\r
- FILEFLAGS 0 //\r
-#endif\r
- FILEOS VOS_NT_WINDOWS32\r
- FILETYPE VFT_APP\r
- FILESUBTYPE 0\r
-BEGIN\r
- BLOCK "StringFileInfo"\r
- BEGIN\r
- BLOCK "040904E0" // Lang=US English, CharSet=Windows Multiligual\r
- BEGIN\r
- VALUE "Comments", "by Kern Sibbald\0"\r
- VALUE "CompanyName", " \0"\r
- VALUE "FileDescription", "Bacula Storage daemon for Win32\0"\r
- VALUE "FileVersion", VERSION "\0"\r
- VALUE "InternalName", "Bacula\0"\r
- VALUE "LegalCopyright", "Copyright Free Software Foundation Europe e.V., 1999-2006\0"\r
- VALUE "LegalTrademarks", "Licensed under GNU GPL 2.0\0"\r
- VALUE "OriginalFilename", "bacula-sd.exe\0"\r
- VALUE "PrivateBuild", "\0"\r
- VALUE "ProductName", "Bacula - Win32 Version\0"\r
- VALUE "ProductVersion", VERSION\r
- VALUE "SpecialBuild", "\0"\r
- END\r
- END\r
- BLOCK "VarFileInfo"\r
- BEGIN\r
- VALUE "Translation", 0x409, 1252 // US English, Multilingual\r
- END\r
-END\r
-\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// RT_MANIFEST\r
-//\r
-CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "bacula-sd.manifest"\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Bitmap\r
-//\r
-\r
-IDB_BACULABMP BITMAP "bacula.bmp"\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// String Table\r
-//\r
-\r
-STRINGTABLE \r
-BEGIN\r
- IDI_BACULA "Bacula"\r
-END\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// About Dialog\r
-//\r
-\r
-IDD_ABOUT DIALOG 0, 0, 250, 145\r
-STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU\r
-CAPTION "About Bacula"\r
-FONT 8, "MS Sans Serif"\r
-BEGIN\r
- DEFPUSHBUTTON "OK",IDOK,190,120,50,15\r
-// CONTROL "\3", IDC_BACULABMP,"Static",SS_ICON | SS_CENTERIMAGE |\r
-// SS_SUNKEN,7,5,73,65\r
-#ifndef HAVE_MINGW\r
- CONTROL IDB_BACULABMP,IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,32,32\r
-#endif\r
-\r
- LTEXT N_(" by Kern Sibbald"),-1,134,38,78,10\r
- LTEXT N_("For more information, see:"),-1,115,60,100,10\r
- LTEXT " www.bacula.org",-1,115,70,100,10\r
-// LTEXT " ",-1,69,81,100,10\r
-// LTEXT " ",-1,90,70,100,10\r
- LTEXT "Copyright (C) 1999-2006, Kern Sibbald",-1,7,120,175,10\r
- LTEXT N_("Licensed under GNU GPL 2.0."),-1,7,130,175,10\r
- RTEXT N_("Build Date:"),-1,108,24,42,8\r
- RTEXT N_("Bacula Version:"),-1,100,9,50,8\r
- LTEXT VERSION,-1,159,10,65,8\r
- LTEXT BDATE,-1,159,24,65,10\r
-\r
-END\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-//\r
-// Status Dialog\r
-//\r
-\r
-IDD_STATUS DIALOGEX 0, 0, 411, 244\r
-STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME\r
-CAPTION N_("Bacula Status")\r
-FONT 8, "Courier New"\r
-BEGIN\r
- DEFPUSHBUTTON "&OK",IDOK,355,5,51,15\r
- EDITTEXT IDC_TEXTDISPLAY, 2, 2, 350, 240, WS_VSCROLL | WS_HSCROLL | WS_BORDER | ES_READONLY | ES_MULTILINE\r
-END\r
+++ /dev/null
-// 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);
-}
+++ /dev/null
-// 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
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * Bacula Status Dialog header file
- *
- */
-/*
- 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.
-*/
-
-
-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;
-};
-
-#endif
+++ /dev/null
-// 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);
-}
+++ /dev/null
-// 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
--- /dev/null
+/*
+ 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"
-/*
- * mtops.cpp - Emulate the Linux st (scsi tape) driver on Microsoft Windows.
- *
- * Author: Robert Nelson, May, 2006 <robertn@the-nelsons.org>
- *
- * 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 <robertn@the-nelsons.org>.
- */
/*
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.
(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 <robertn@the-nelsons.org>
+ *
+ * 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 <robertn@the-nelsons.org>.
+ */
#include <stdarg.h>
#include <stddef.h>
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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"
--- /dev/null
+/*
+ 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()
-/*
- * 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
(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
// 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
- 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 <marc@schiffbauer.net> that