2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Main program for bat (qt-console)
23 * Written by Kern Sibbald, January MMVII
29 #include <QApplication>
30 #include <QTranslator>
33 * We need Qt version 4.8.4 or later to be able to comple correctly
35 #if QT_VERSION < 0x040804
36 #error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
37 #error "You need Qt version 4.8.4 or later to build Bat"
38 #error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
44 /* Forward referenced functions */
45 void terminate_console(int sig);
47 static int check_resources();
49 extern bool parse_bat_config(CONFIG *config, const char *configfile, int exit_code);
50 extern void message_callback(int /* type */, char *msg);
53 #define CONFIG_FILE "bat.conf" /* default configuration file */
55 /* Static variables */
56 static CONFIG *config;
57 static char *configfile = NULL;
59 int main(int argc, char *argv[])
62 bool no_signals = true;
63 bool test_config = false;
66 app = new QApplication(argc, argv);
67 app->setStyle(new QPlastiqueStyle());
68 app->setQuitOnLastWindowClosed(true);
69 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
71 QTranslator qtTranslator;
72 qtTranslator.load(QString("qt_") + QLocale::system().name(),QLibraryInfo::location(QLibraryInfo::TranslationsPath));
73 app->installTranslator(&qtTranslator);
75 QTranslator batTranslator;
76 batTranslator.load(QString("bat_") + QLocale::system().name(),QLibraryInfo::location(QLibraryInfo::TranslationsPath));
77 app->installTranslator(&batTranslator);
79 register_message_callback(message_callback);
82 setlocale(LC_ALL, "");
83 bindtextdomain("bacula", LOCALEDIR);
88 set_trace(true); /* output to trace file */
92 my_name_is(argc, argv, "bat");
95 working_directory = "/tmp";
98 struct sigaction sigignore;
99 sigignore.sa_flags = 0;
100 sigignore.sa_handler = SIG_IGN;
101 sigfillset(&sigignore.sa_mask);
102 sigaction(SIGPIPE, &sigignore, NULL);
103 sigaction(SIGUSR2, &sigignore, NULL);
106 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
108 case 'c': /* configuration file */
109 if (configfile != NULL) {
112 configfile = bstrdup(optarg);
116 debug_level = atoi(optarg);
117 if (debug_level <= 0)
121 case 's': /* turn off signals */
139 init_signals(terminate_console);
148 WSA_Init(); /* Initialize Windows sockets */
151 if (configfile == NULL) {
152 configfile = bstrdup(CONFIG_FILE);
155 config = new_config_parser();
156 parse_bat_config(config, configfile, M_ERROR_TERM);
158 if (init_crypto() != 0) {
159 Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
162 if (!check_resources()) {
163 Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
169 mainWin = new MainWin;
175 void terminate_console(int /*sig*/)
178 WSACleanup(); /* TODO: check when we have to call it */
187 "\nVersion: %s (%s) %s %s %s\n\n"
188 "Usage: bat [-s] [-c config_file] [-d debug_level] [config_file]\n"
189 " -c <file> set configuration file to file\n"
190 " -dnn set debug level to nn\n"
192 " -t test - read configuration and exit\n"
193 " -? print this message.\n"
194 "\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
200 * Make a quick check to see that we have all the
203 static int check_resources()
213 foreach_res(director, R_DIRECTOR) {
215 /* tls_require implies tls_enable */
216 if (director->tls_require) {
218 director->tls_enable = true;
220 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
225 tls_needed = director->tls_enable || director->tls_authenticate;
227 if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && tls_needed) {
228 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
229 " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
230 " At least one CA certificate store is required.\n"),
231 director->hdr.name, configfile);
237 Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
238 "Without that I don't how to speak to the Director :-(\n"), configfile);
243 /* Loop over Consoles */
244 foreach_res(cons, R_CONSOLE) {
245 /* tls_require implies tls_enable */
246 if (cons->tls_require) {
248 cons->tls_enable = true;
250 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
255 tls_needed = cons->tls_enable || cons->tls_authenticate;
257 if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && tls_needed) {
258 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
259 " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
260 cons->hdr.name, configfile);