2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 two of the GNU 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 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 John Walker.
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.
31 * Main program for bat (qt-console)
33 * Kern Sibbald, January MMVII
38 #include <QApplication>
39 #include <QTranslator>
45 /* Forward referenced functions */
46 void terminate_console(int sig);
48 static int check_resources();
50 extern bool parse_bat_config(CONFIG *config, const char *configfile, int exit_code);
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 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
69 QTranslator qtTranslator;
70 qtTranslator.load(QString("qt_") + QLocale::system().name());
71 app->installTranslator(&qtTranslator);
73 QTranslator batTranslator;
74 batTranslator.load(QString("bat_") + QLocale::system().name());
75 app->installTranslator(&batTranslator);
80 setlocale(LC_ALL, "");
81 bindtextdomain("bacula", LOCALEDIR);
86 my_name_is(argc, argv, "bat");
88 working_directory = "/tmp";
90 struct sigaction sigignore;
91 sigignore.sa_flags = 0;
92 sigignore.sa_handler = SIG_IGN;
93 sigfillset(&sigignore.sa_mask);
94 sigaction(SIGPIPE, &sigignore, NULL);
95 sigaction(SIGUSR2, &sigignore, NULL);
98 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
100 case 'c': /* configuration file */
101 if (configfile != NULL) {
104 configfile = bstrdup(optarg);
108 debug_level = atoi(optarg);
109 if (debug_level <= 0)
113 case 's': /* turn off signals */
131 init_signals(terminate_console);
138 if (configfile == NULL) {
139 configfile = bstrdup(CONFIG_FILE);
142 config = new_config_parser();
143 parse_bat_config(config, configfile, M_ERROR_TERM);
145 if (init_crypto() != 0) {
146 Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
149 if (!check_resources()) {
150 Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
153 mainWin = new MainWin;
159 void terminate_console(int /*sig*/)
168 "\nVersion: %s (%s) %s %s %s\n\n"
169 "Usage: bat [-s] [-c config_file] [-d debug_level] [config_file]\n"
170 " -c <file> set configuration file to file\n"
171 " -dnn set debug level to nn\n"
173 " -t test - read configuration and exit\n"
174 " -? print this message.\n"
175 "\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
182 * Call-back for reading a passphrase for an encrypted PEM file
183 * This function uses getpass(), which uses a static buffer and is NOT thread-safe.
185 static int tls_pem_callback(char *buf, int size, const void *userdata)
188 const char *prompt = (const char *) userdata;
191 passwd = getpass(prompt);
192 bstrncpy(buf, passwd, size);
193 return (strlen(buf));
203 * Make a quick check to see that we have all the
206 static int check_resources()
216 foreach_res(director, R_DIRECTOR) {
218 /* tls_require implies tls_enable */
219 if (director->tls_require) {
221 director->tls_enable = true;
223 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
228 tls_needed = director->tls_enable || director->tls_authenticate;
230 if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && tls_needed) {
231 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
232 " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
233 " At least one CA certificate store is required.\n"),
234 director->hdr.name, configfile);
240 Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
241 "Without that I don't how to speak to the Director :-(\n"), configfile);
246 /* Loop over Consoles */
247 foreach_res(cons, R_CONSOLE) {
248 /* tls_require implies tls_enable */
249 if (cons->tls_require) {
251 cons->tls_enable = true;
253 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
258 tls_needed = cons->tls_enable || cons->tls_authenticate;
260 if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && tls_needed) {
261 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
262 " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
263 cons->hdr.name, configfile);