2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007 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 plus additions
11 that are listed in the file LICENSE.
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.
29 #include "mainwindow.h"
30 #include <QApplication>
33 #include "console_conf.h"
37 /* Imported functions */
38 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
40 /* Forward referenced functions */
41 void terminate_console(int sig);
43 static int check_resources();
45 #define CONFIG_FILE "./qt-console.conf" /* default configuration file */
47 /* Static variables */
48 static char *configfile = NULL;
52 int main(int argc, char *argv[])
56 bool no_signals = true;
57 bool test_config = false;
60 QApplication app(argc, argv);
61 app.setQuitOnLastWindowClosed(true);
63 mainWin = new MainWindow;
68 setlocale(LC_ALL, "");
69 bindtextdomain("bacula", LOCALEDIR);
74 my_name_is(argc, argv, "gnome-console");
76 working_directory = "/tmp";
78 struct sigaction sigignore;
79 sigignore.sa_flags = 0;
80 sigignore.sa_handler = SIG_IGN;
81 sigfillset(&sigignore.sa_mask);
82 sigaction(SIGPIPE, &sigignore, NULL);
84 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
86 case 'c': /* configuration file */
87 if (configfile != NULL) {
90 configfile = bstrdup(optarg);
94 debug_level = atoi(optarg);
99 case 's': /* turn off signals */
117 init_signals(terminate_console);
124 if (configfile == NULL) {
125 configfile = bstrdup(CONFIG_FILE);
128 parse_config(configfile);
129 set_text("Configuration read.\n");
131 if (init_crypto() != 0) {
132 Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
135 if (!check_resources()) {
136 Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
142 void terminate_console(int sig)
144 (void)sig; /* avoid compiler complaints */
152 "\nVersion: %s (%s) %s %s %s\n\n"
153 "Usage: qt-console [-s] [-c config_file] [-d debug_level] [config_file]\n"
154 " -c <file> set configuration file to file\n"
155 " -dnn set debug level to nn\n"
157 " -t test - read configuration and exit\n"
158 " -? print this message.\n"
159 "\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
165 * Call-back for reading a passphrase for an encrypted PEM file
166 * This function uses getpass(), which uses a static buffer and is NOT thread-safe.
168 static int tls_pem_callback(char *buf, int size, const void *userdata)
171 const char *prompt = (const char *) userdata;
174 passwd = getpass(prompt);
175 bstrncpy(buf, passwd, size);
176 return (strlen(buf));
185 * Make a quick check to see that we have all the
188 static int check_resources()
197 foreach_res(director, R_DIRECTOR) {
199 /* tls_require implies tls_enable */
200 if (director->tls_require) {
202 director->tls_enable = true;
204 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
210 if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && director->tls_enable) {
211 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
212 " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
213 " At least one CA certificate store is required.\n"),
214 director->hdr.name, configfile);
220 Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
221 "Without that I don't how to speak to the Director :-(\n"), configfile);
226 /* Loop over Consoles */
227 foreach_res(cons, R_CONSOLE) {
228 /* tls_require implies tls_enable */
229 if (cons->tls_require) {
231 cons->tls_enable = true;
233 Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
239 if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable) {
240 Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
241 " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
242 cons->hdr.name, configfile);