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->setStyle(new QPlastiqueStyle());
67 app->setQuitOnLastWindowClosed(true);
68 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
70 QTranslator qtTranslator;
71 qtTranslator.load(QString("qt_") + QLocale::system().name(),QLibraryInfo::location(QLibraryInfo::TranslationsPath));
72 app->installTranslator(&qtTranslator);
74 QTranslator batTranslator;
75 batTranslator.load(QString("bat_") + QLocale::system().name(),QLibraryInfo::location(QLibraryInfo::TranslationsPath));
76 app->installTranslator(&batTranslator);
78 register_message_callback(message_callback);
81 setlocale(LC_ALL, "");
82 bindtextdomain("bacula", LOCALEDIR);
87 set_trace(true); /* output to trace file */
91 my_name_is(argc, argv, "bat");
94 working_directory = "/tmp";
97 struct sigaction sigignore;
98 sigignore.sa_flags = 0;
99 sigignore.sa_handler = SIG_IGN;
100 sigfillset(&sigignore.sa_mask);
101 sigaction(SIGPIPE, &sigignore, NULL);
102 sigaction(SIGUSR2, &sigignore, NULL);
105 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
107 case 'c': /* configuration file */
108 if (configfile != NULL) {
111 configfile = bstrdup(optarg);
115 debug_level = atoi(optarg);
116 if (debug_level <= 0)
120 case 's': /* turn off signals */
138 init_signals(terminate_console);
147 WSA_Init(); /* Initialize Windows sockets */
150 if (configfile == NULL) {
151 configfile = bstrdup(CONFIG_FILE);
154 config = New(CONFIG());
155 parse_bat_config(config, configfile, M_ERROR_TERM);
157 if (init_crypto() != 0) {
158 Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
161 if (!check_resources()) {
162 Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
168 mainWin = new MainWin;
174 void terminate_console(int /*sig*/)
177 WSACleanup(); /* TODO: check when we have to call it */
186 "\nVersion: %s (%s) %s %s %s\n\n"
187 "Usage: bat [-s] [-c config_file] [-d debug_level] [config_file]\n"
188 " -c <file> set configuration file to file\n"
189 " -dnn set debug level to nn\n"
191 " -t test - read configuration and exit\n"
192 " -? print this message.\n"
193 "\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
199 * Make a quick check to see that we have all the
202 static int check_resources()
212 foreach_res(director, R_DIRECTOR) {
214 /* tls_require implies tls_enable */
215 if (director->tls_require) {
217 director->tls_enable = true;
219 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
224 tls_needed = director->tls_enable || director->tls_authenticate;
226 if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && tls_needed) {
227 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
228 " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
229 " At least one CA certificate store is required.\n"),
230 director->hdr.name, configfile);
236 Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
237 "Without that I don't how to speak to the Director :-(\n"), configfile);
242 /* Loop over Consoles */
243 foreach_res(cons, R_CONSOLE) {
244 /* tls_require implies tls_enable */
245 if (cons->tls_require) {
247 cons->tls_enable = true;
249 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
254 tls_needed = cons->tls_enable || cons->tls_authenticate;
256 if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && tls_needed) {
257 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
258 " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
259 cons->hdr.name, configfile);