2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Main program for bat (qt-console)
22 * Written by Kern Sibbald, January MMVII
28 #include <QApplication>
29 #include <QTranslator>
32 * We need Qt version 4.8.4 or later to be able to comple correctly
34 #if QT_VERSION < 0x040804
35 #error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
36 #error "You need Qt version 4.8.4 or later to build Bat"
37 #error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
43 /* Forward referenced functions */
44 void terminate_console(int sig);
46 static int check_resources();
48 extern bool parse_bat_config(CONFIG *config, const char *configfile, int exit_code);
49 extern void message_callback(int /* type */, char *msg);
52 #define CONFIG_FILE "bat.conf" /* default configuration file */
54 /* Static variables */
55 static CONFIG *config;
56 static char *configfile = NULL;
58 int main(int argc, char *argv[])
61 bool no_signals = true;
62 bool test_config = false;
65 app = new QApplication(argc, argv);
66 app->setQuitOnLastWindowClosed(true);
67 #if QT_VERSION < 0x050000
68 app->setStyle(new QPlastiqueStyle());
69 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
72 QTranslator qtTranslator;
73 qtTranslator.load(QString("qt_") + QLocale::system().name(),QLibraryInfo::location(QLibraryInfo::TranslationsPath));
74 app->installTranslator(&qtTranslator);
76 QTranslator batTranslator;
77 batTranslator.load(QString("bat_") + QLocale::system().name(),QLibraryInfo::location(QLibraryInfo::TranslationsPath));
78 app->installTranslator(&batTranslator);
80 register_message_callback(message_callback);
83 setlocale(LC_ALL, "");
84 bindtextdomain("bacula", LOCALEDIR);
89 set_trace(true); /* output to trace file */
93 my_name_is(argc, argv, "bat");
96 working_directory = "/tmp";
99 struct sigaction sigignore;
100 sigignore.sa_flags = 0;
101 sigignore.sa_handler = SIG_IGN;
102 sigfillset(&sigignore.sa_mask);
103 sigaction(SIGPIPE, &sigignore, NULL);
104 sigaction(SIGUSR2, &sigignore, NULL);
107 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
109 case 'c': /* configuration file */
110 if (configfile != NULL) {
113 configfile = bstrdup(optarg);
117 debug_level = atoi(optarg);
118 if (debug_level <= 0)
122 case 's': /* turn off signals */
140 init_signals(terminate_console);
149 WSA_Init(); /* Initialize Windows sockets */
152 if (configfile == NULL) {
153 configfile = bstrdup(CONFIG_FILE);
156 config = New(CONFIG());
157 parse_bat_config(config, configfile, M_ERROR_TERM);
159 if (init_crypto() != 0) {
160 Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
163 if (!check_resources()) {
164 Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
170 mainWin = new MainWin;
176 void terminate_console(int /*sig*/)
179 WSACleanup(); /* TODO: check when we have to call it */
188 "\nVersion: %s (%s) %s %s %s\n\n"
189 "Usage: bat [-s] [-c config_file] [-d debug_level] [config_file]\n"
190 " -c <file> set configuration file to file\n"
191 " -dnn set debug level to nn\n"
193 " -t test - read configuration and exit\n"
194 " -? print this message.\n"
195 "\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
201 * Make a quick check to see that we have all the
204 static int check_resources()
214 foreach_res(director, R_DIRECTOR) {
216 /* tls_require implies tls_enable */
217 if (director->tls_require) {
219 director->tls_enable = true;
221 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
226 tls_needed = director->tls_enable || director->tls_authenticate;
228 if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && tls_needed) {
229 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
230 " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
231 " At least one CA certificate store is required.\n"),
232 director->hdr.name, configfile);
238 Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
239 "Without that I don't how to speak to the Director :-(\n"), configfile);
244 /* Loop over Consoles */
245 foreach_res(cons, R_CONSOLE) {
246 /* tls_require implies tls_enable */
247 if (cons->tls_require) {
249 cons->tls_enable = true;
251 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
256 tls_needed = cons->tls_enable || cons->tls_authenticate;
258 if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && tls_needed) {
259 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
260 " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
261 cons->hdr.name, configfile);