2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2012 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Main program for bat (qt-console)
31 * Kern Sibbald, January MMVII
37 #include <QApplication>
38 #include <QTranslator>
41 * We need Qt version 4.7.4 or later to be able to comple correctly
43 #if QT_VERSION < 0x040602
44 #error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
45 #error "You need Qt version 4.7.4 or later to build Bat"
46 #error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
52 /* Forward referenced functions */
53 void terminate_console(int sig);
55 static int check_resources();
57 extern bool parse_bat_config(CONFIG *config, const char *configfile, int exit_code);
58 extern void message_callback(int /* type */, char *msg);
61 #define CONFIG_FILE "bat.conf" /* default configuration file */
63 /* Static variables */
64 static CONFIG *config;
65 static char *configfile = NULL;
67 int main(int argc, char *argv[])
70 bool no_signals = true;
71 bool test_config = false;
74 app = new QApplication(argc, argv);
75 app->setQuitOnLastWindowClosed(true);
76 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
78 QTranslator qtTranslator;
79 qtTranslator.load(QString("qt_") + QLocale::system().name());
80 app->installTranslator(&qtTranslator);
82 QTranslator batTranslator;
83 batTranslator.load(QString("bat_") + QLocale::system().name());
84 app->installTranslator(&batTranslator);
86 register_message_callback(message_callback);
89 setlocale(LC_ALL, "");
90 bindtextdomain("bacula", LOCALEDIR);
95 set_trace(true); /* output to trace file */
99 my_name_is(argc, argv, "bat");
101 init_msg(NULL, NULL);
102 working_directory = "/tmp";
104 struct sigaction sigignore;
105 sigignore.sa_flags = 0;
106 sigignore.sa_handler = SIG_IGN;
107 sigfillset(&sigignore.sa_mask);
108 sigaction(SIGPIPE, &sigignore, NULL);
109 sigaction(SIGUSR2, &sigignore, NULL);
112 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
114 case 'c': /* configuration file */
115 if (configfile != NULL) {
118 configfile = bstrdup(optarg);
122 debug_level = atoi(optarg);
123 if (debug_level <= 0)
127 case 's': /* turn off signals */
145 init_signals(terminate_console);
154 WSA_Init(); /* Initialize Windows sockets */
157 if (configfile == NULL) {
158 configfile = bstrdup(CONFIG_FILE);
161 config = new_config_parser();
162 parse_bat_config(config, configfile, M_ERROR_TERM);
164 if (init_crypto() != 0) {
165 Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
168 if (!check_resources()) {
169 Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
175 mainWin = new MainWin;
181 void terminate_console(int /*sig*/)
183 // WSA_Cleanup(); /* TODO: check when we have to call it */
191 "\nVersion: %s (%s) %s %s %s\n\n"
192 "Usage: bat [-s] [-c config_file] [-d debug_level] [config_file]\n"
193 " -c <file> set configuration file to file\n"
194 " -dnn set debug level to nn\n"
196 " -t test - read configuration and exit\n"
197 " -? print this message.\n"
198 "\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
204 * Make a quick check to see that we have all the
207 static int check_resources()
217 foreach_res(director, R_DIRECTOR) {
219 /* tls_require implies tls_enable */
220 if (director->tls_require) {
222 director->tls_enable = true;
224 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
229 tls_needed = director->tls_enable || director->tls_authenticate;
231 if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && tls_needed) {
232 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
233 " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
234 " At least one CA certificate store is required.\n"),
235 director->hdr.name, configfile);
241 Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
242 "Without that I don't how to speak to the Director :-(\n"), configfile);
247 /* Loop over Consoles */
248 foreach_res(cons, R_CONSOLE) {
249 /* tls_require implies tls_enable */
250 if (cons->tls_require) {
252 cons->tls_enable = true;
254 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
259 tls_needed = cons->tls_enable || cons->tls_authenticate;
261 if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && tls_needed) {
262 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
263 " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
264 cons->hdr.name, configfile);