mult-inheritance
print-func
qrc_main.cpp
-
+moc_*.cpp
#############################################################################
# Makefile for building: qt-console
-# Generated by qmake (2.01a) (Qt 4.2.1) on: Fri Jan 26 15:30:33 2007
+# Generated by qmake (2.01a) (Qt 4.2.1) on: Fri Jan 26 20:53:56 2007
# Project: qt-console.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile qt-console.pro
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
LEXFLAGS =
YACCFLAGS = -d
-INCPATH = -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I.
+INCPATH = -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I.. -I. -I.
LINK = g++
LFLAGS =
-LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -L/usr/lib -L/usr/X11R6/lib -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -ldl -lpthread
+LIBS = $(SUBLIBS) -L/usr/lib -L../lib -lbac -lssl -lcrypto -lQtGui -L/usr/lib -L/usr/X11R6/lib -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -ldl -lpthread
AR = ar cqs
RANLIB =
QMAKE = /usr/bin/qmake
####### Files
SOURCES = main.cpp \
+ authenticate.cpp \
+ console_conf.cpp \
mainwindow.cpp moc_mainwindow.cpp \
qrc_main.cpp
OBJECTS = main.o \
+ authenticate.o \
+ console_conf.o \
mainwindow.o \
moc_mainwindow.o \
qrc_main.o
dist:
@$(CHK_DIR_EXISTS) .tmp/qt-console1.0.0 || $(MKDIR) .tmp/qt-console1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents mainwindow.h .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents main.ui .tmp/qt-console1.0.0/ && (cd `dirname .tmp/qt-console1.0.0` && $(TAR) qt-console1.0.0.tar qt-console1.0.0 && $(COMPRESS) qt-console1.0.0.tar) && $(MOVE) `dirname .tmp/qt-console1.0.0`/qt-console1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/qt-console1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents mainwindow.h console_conf.h .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents main.cpp authenticate.cpp console_conf.cpp mainwindow.cpp .tmp/qt-console1.0.0/ && $(COPY_FILE) --parents main.ui .tmp/qt-console1.0.0/ && (cd `dirname .tmp/qt-console1.0.0` && $(TAR) qt-console1.0.0.tar qt-console1.0.0 && $(COMPRESS) qt-console1.0.0.tar) && $(MOVE) `dirname .tmp/qt-console1.0.0`/qt-console1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/qt-console1.0.0
yaccclean:
qrc_main.cpp: main.qrc \
/usr/bin/rcc \
images/new.png \
+ images/bat-natural-fullsize.png \
images/copy.png \
images/cut.png \
images/save.png \
####### Compile
main.o: main.cpp mainwindow.h \
- ui_main.h
+ ui_main.h \
+ console_conf.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
+authenticate.o: authenticate.cpp console_conf.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o authenticate.o authenticate.cpp
+
+console_conf.o: console_conf.cpp console_conf.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o console_conf.o console_conf.cpp
+
mainwindow.o: mainwindow.cpp mainwindow.h \
ui_main.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
--- /dev/null
+/*
+ *
+ * Bacula UA authentication. Provides authentication with
+ * the Director.
+ *
+ * Kern Sibbald, June MMI
+ *
+ * Version $Id$
+ *
+ * This routine runs as a thread and must be thread reentrant.
+ *
+ * Basic tasks done here:
+ *
+ */
+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
+
+#include "mainwindow.h"
+#include "bacula.h"
+#include "console_conf.h"
+#include "jcr.h"
+
+
+/* Commands sent to Director */
+static char hello[] = "Hello %s calling\n";
+
+/* Response from Director */
+static char OKhello[] = "1000 OK:";
+
+/* Forward referenced functions */
+
+/*
+ * Authenticate Director
+ */
+int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
+{
+ BSOCK *dir = jcr->dir_bsock;
+ int tls_local_need = BNET_TLS_NONE;
+ int tls_remote_need = BNET_TLS_NONE;
+ int compatible = true;
+ char bashed_name[MAX_NAME_LENGTH];
+ char *password;
+
+ /*
+ * Send my name to the Director then do authentication
+ */
+ if (cons) {
+ bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
+ bash_spaces(bashed_name);
+ password = cons->password;
+ } else {
+ bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
+ password = director->password;
+ }
+ /* Timeout Hello after 5 mins */
+ btimer_t *tid = start_bsock_timer(dir, 60 * 5);
+ bnet_fsend(dir, hello, bashed_name);
+
+ /* respond to Dir challenge */
+ if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
+ /* Now challenge dir */
+ !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
+ stop_bsock_timer(tid);
+ printf(_("%s: Director authorization problem.\n"), my_name);
+ set_text(_("Director authorization problem.\n"));
+ set_text(_(
+ "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));
+ return 0;
+ }
+
+ Dmsg1(6, ">dird: %s", dir->msg);
+ if (bnet_recv(dir) <= 0) {
+ stop_bsock_timer(tid);
+ set_textf(_("Bad response to Hello command: ERR=%s\n"),
+ bnet_strerror(dir));
+ printf(_("%s: Bad response to Hello command: ERR=%s\n"),
+ my_name, bnet_strerror(dir));
+ set_text(_("The Director is probably not running.\n"));
+ return 0;
+ }
+ stop_bsock_timer(tid);
+ Dmsg1(10, "<dird: %s", dir->msg);
+ if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
+ set_text(_("Director rejected Hello command\n"));
+ return 0;
+ } else {
+ set_text(dir->msg);
+ }
+ return 1;
+}
--- /dev/null
+/*
+ * Main configuration file parser for Bacula User Agent
+ * some parts may be split into separate files such as
+ * the schedule configuration (sch_config.c).
+ *
+ * Note, the configuration file parser consists of three parts
+ *
+ * 1. The generic lexical scanner in lib/lex.c and lib/lex.h
+ *
+ * 2. The generic config scanner in lib/parse_config.c and
+ * lib/parse_config.h.
+ * These files contain the parser code, some utility
+ * routines, and the common store routines (name, int,
+ * string).
+ *
+ * 3. The daemon specific file, which contains the Resource
+ * definitions as well as any specific store routines
+ * for the resource records.
+ *
+ * Kern Sibbald, January MM, September MM
+ *
+ * Version $Id$
+ */
+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
+
+#include "bacula.h"
+#include "console_conf.h"
+
+/* Define the first and last resource ID record
+ * types. Note, these should be unique for each
+ * daemon though not a requirement.
+ */
+int r_first = R_FIRST;
+int r_last = R_LAST;
+static RES *sres_head[R_LAST - R_FIRST + 1];
+RES **res_head = sres_head;
+
+/* Forward referenced subroutines */
+
+
+/* We build the current resource here as we are
+ * scanning the resource configuration definition,
+ * then move it to allocated memory when the resource
+ * scan is complete.
+ */
+URES res_all;
+int res_all_size = sizeof(res_all);
+
+/* Definition of records permitted within each
+ * resource with the routine to process the record
+ * information.
+ */
+static RES_ITEM dir_items[] = {
+ {"name", store_name, ITEM(dir_res.hdr.name), 0, ITEM_REQUIRED, 0},
+ {"description", store_str, ITEM(dir_res.hdr.desc), 0, 0, 0},
+ {"dirport", store_int, ITEM(dir_res.DIRport), 0, ITEM_DEFAULT, 9101},
+ {"address", store_str, ITEM(dir_res.address), 0, ITEM_REQUIRED, 0},
+ {"password", store_password, ITEM(dir_res.password), 0, 0, 0},
+ {"tlsenable", store_bit, ITEM(dir_res.tls_enable), 1, 0, 0},
+ {"tlsrequire", store_bit, ITEM(dir_res.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(dir_res.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(dir_res.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(dir_res.tls_certfile), 0, 0, 0},
+ {"tlskey", store_dir, ITEM(dir_res.tls_keyfile), 0, 0, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+};
+
+static RES_ITEM con_items[] = {
+ {"name", store_name, ITEM(con_res.hdr.name), 0, ITEM_REQUIRED, 0},
+ {"description", store_str, ITEM(con_res.hdr.desc), 0, 0, 0},
+ {"password", store_password, ITEM(con_res.password), 0, ITEM_REQUIRED, 0},
+ {"tlsenable", store_bit, ITEM(con_res.tls_enable), 1, 0, 0},
+ {"tlsrequire", store_bit, ITEM(con_res.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(con_res.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(con_res.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(con_res.tls_certfile), 0, 0, 0},
+ {"tlskey", store_dir, ITEM(con_res.tls_keyfile), 0, 0, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+};
+
+static RES_ITEM con_font_items[] = {
+ {"name", store_name, ITEM(con_font.hdr.name), 0, ITEM_REQUIRED, 0},
+ {"description", store_str, ITEM(con_font.hdr.desc), 0, 0, 0},
+ {"font", store_str, ITEM(con_font.fontface), 0, 0, 0},
+ {"requiressl", store_bit, ITEM(con_font.require_ssl), 1, ITEM_DEFAULT, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+};
+
+
+/*
+ * This is the master resource definition.
+ * It must have one item for each of the resources.
+ */
+RES_TABLE resources[] = {
+ {"director", dir_items, R_DIRECTOR},
+ {"console", con_items, R_CONSOLE},
+ {"consolefont", con_font_items, R_CONSOLE_FONT},
+ {NULL, NULL, 0}
+};
+
+
+/* Dump contents of resource */
+void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
+{
+ URES *res = (URES *)reshdr;
+ bool recurse = true;
+
+ if (res == NULL) {
+ printf(_("No record for %d %s\n"), type, res_to_str(type));
+ return;
+ }
+ if (type < 0) { /* no recursion */
+ type = - type;
+ recurse = false;
+ }
+ switch (type) {
+ case R_DIRECTOR:
+ printf(_("Director: name=%s address=%s DIRport=%d\n"), reshdr->name,
+ res->dir_res.address, res->dir_res.DIRport);
+ break;
+ case R_CONSOLE:
+ printf(_("Console: name=%s\n"), reshdr->name);
+ break;
+ case R_CONSOLE_FONT:
+ printf(_("ConsoleFont: name=%s font face=%s\n"),
+ reshdr->name, NPRT(res->con_font.fontface));
+ break;
+ default:
+ printf(_("Unknown resource type %d\n"), type);
+ }
+ if (recurse && res->dir_res.hdr.next) {
+ dump_resource(type, res->dir_res.hdr.next, sendit, sock);
+ }
+}
+
+/*
+ * Free memory of resource.
+ * NB, we don't need to worry about freeing any references
+ * to other resources as they will be freed when that
+ * resource chain is traversed. Mainly we worry about freeing
+ * allocated strings (names).
+ */
+void free_resource(RES *sres, int type)
+{
+ RES *nres;
+ URES *res = (URES *)sres;
+
+ if (res == NULL)
+ return;
+
+ /* common stuff -- free the resource name */
+ nres = (RES *)res->dir_res.hdr.next;
+ if (res->dir_res.hdr.name) {
+ free(res->dir_res.hdr.name);
+ }
+ if (res->dir_res.hdr.desc) {
+ free(res->dir_res.hdr.desc);
+ }
+
+ switch (type) {
+ case R_DIRECTOR:
+ if (res->dir_res.address) {
+ free(res->dir_res.address);
+ }
+ if (res->dir_res.tls_ctx) {
+ free_tls_context(res->dir_res.tls_ctx);
+ }
+ if (res->dir_res.tls_ca_certfile) {
+ free(res->dir_res.tls_ca_certfile);
+ }
+ if (res->dir_res.tls_ca_certdir) {
+ free(res->dir_res.tls_ca_certdir);
+ }
+ if (res->dir_res.tls_certfile) {
+ free(res->dir_res.tls_certfile);
+ }
+ if (res->dir_res.tls_keyfile) {
+ free(res->dir_res.tls_keyfile);
+ }
+ break;
+ case R_CONSOLE:
+ if (res->con_res.password) {
+ free(res->con_res.password);
+ }
+ if (res->con_res.tls_ctx) {
+ free_tls_context(res->con_res.tls_ctx);
+ }
+ if (res->con_res.tls_ca_certfile) {
+ free(res->con_res.tls_ca_certfile);
+ }
+ if (res->con_res.tls_ca_certdir) {
+ free(res->con_res.tls_ca_certdir);
+ }
+ if (res->con_res.tls_certfile) {
+ free(res->con_res.tls_certfile);
+ }
+ if (res->con_res.tls_keyfile) {
+ free(res->con_res.tls_keyfile);
+ }
+ break;
+ case R_CONSOLE_FONT:
+ if (res->con_font.fontface) {
+ free(res->con_font.fontface);
+ }
+ break;
+ default:
+ printf(_("Unknown resource type %d\n"), type);
+ }
+ /* Common stuff again -- free the resource, recurse to next one */
+ free(res);
+ if (nres) {
+ free_resource(nres, type);
+ }
+}
+
+/* Save the new resource by chaining it into the head list for
+ * the resource. If this is pass 2, we update any resource
+ * pointers (currently only in the Job resource).
+ */
+void save_resource(int type, RES_ITEM *items, int pass)
+{
+ URES *res;
+ int rindex = type - r_first;
+ int i, size = 0;
+ int error = 0;
+
+ /*
+ * Ensure that all required items are present
+ */
+ for (i=0; items[i].name; i++) {
+ if (items[i].flags & ITEM_REQUIRED) {
+ if (!bit_is_set(i, res_all.dir_res.hdr.item_present)) {
+ Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
+ items[i].name, resources[rindex]);
+ }
+ }
+ }
+
+ /* During pass 2, we looked up pointers to all the resources
+ * referrenced in the current resource, , now we
+ * must copy their address from the static record to the allocated
+ * record.
+ */
+ if (pass == 2) {
+ switch (type) {
+ /* Resources not containing a resource */
+ case R_DIRECTOR:
+ break;
+
+ case R_CONSOLE:
+ case R_CONSOLE_FONT:
+ break;
+
+ default:
+ Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
+ error = 1;
+ break;
+ }
+ /* Note, the resoure name was already saved during pass 1,
+ * so here, we can just release it.
+ */
+ if (res_all.dir_res.hdr.name) {
+ free(res_all.dir_res.hdr.name);
+ res_all.dir_res.hdr.name = NULL;
+ }
+ if (res_all.dir_res.hdr.desc) {
+ free(res_all.dir_res.hdr.desc);
+ res_all.dir_res.hdr.desc = NULL;
+ }
+ return;
+ }
+
+ /* The following code is only executed during pass 1 */
+ switch (type) {
+ case R_DIRECTOR:
+ size = sizeof(DIRRES);
+ break;
+ case R_CONSOLE_FONT:
+ size = sizeof(CONFONTRES);
+ break;
+ case R_CONSOLE:
+ size = sizeof(CONRES);
+ break;
+ default:
+ printf(_("Unknown resource type %d\n"), type);
+ error = 1;
+ break;
+ }
+ /* Common */
+ if (!error) {
+ res = (URES *)malloc(size);
+ memcpy(res, &res_all, size);
+ if (!res_head[rindex]) {
+ res_head[rindex] = (RES *)res; /* store first entry */
+ } else {
+ RES *next, *last;
+ /* Add new res to end of chain */
+ for (last=next=res_head[rindex]; next; next=next->next) {
+ last = next;
+ if (strcmp(next->name, res->dir_res.hdr.name) == 0) {
+ Emsg2(M_ERROR_TERM, 0,
+ _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
+ resources[rindex].name, res->dir_res.hdr.name);
+ }
+ }
+ last->next = (RES *)res;
+ Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
+ res->dir_res.hdr.name);
+ }
+ }
+}
--- /dev/null
+/*
+ * Bacula GNOME User Agent specific configuration and defines
+ *
+ * Kern Sibbald, March 2002
+ *
+ * Version $Id$
+ */
+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
+
+#ifndef __CONSOLE_CONF_H_
+#define __CONSOLE_CONF_H_
+
+/*
+ * Resource codes -- they must be sequential for indexing
+ */
+
+enum {
+ R_DIRECTOR = 1001,
+ R_CONSOLE,
+ R_CONSOLE_FONT,
+ R_FIRST = R_DIRECTOR,
+ R_LAST = R_CONSOLE_FONT /* Keep this updated */
+};
+
+/*
+ * Some resource attributes
+ */
+enum {
+ R_NAME = 1020,
+ R_ADDRESS,
+ R_PASSWORD,
+ R_TYPE,
+ R_BACKUP
+};
+
+
+/* Definition of the contents of each Resource */
+struct DIRRES {
+ RES hdr;
+ int DIRport; /* UA server port */
+ char *address; /* UA server address */
+ char *password; /* UA server password */
+ int tls_enable; /* Enable TLS */
+ int tls_require; /* Require TLS */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+ char *tls_keyfile; /* TLS Client Key File */
+
+ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
+};
+
+struct CONFONTRES {
+ RES hdr;
+ char *fontface; /* Console Font specification */
+ int require_ssl; /* Require SSL on all connections */
+};
+
+struct CONRES {
+ RES hdr;
+ char *password; /* UA server password */
+ int tls_enable; /* Enable TLS on all connections */
+ int tls_require; /* Require TLS on all connections */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+ char *tls_keyfile; /* TLS Client Key File */
+
+ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
+};
+
+
+/* Define the Union of all the above
+ * resource structure definitions.
+ */
+union u_res {
+ DIRRES dir_res;
+ CONRES con_res;
+ CONFONTRES con_font;
+ RES hdr;
+};
+
+typedef union u_res URES;
+
+#endif
Switzerland, email:ftf@fsfeurope.org.
*/
-
#include "mainwindow.h"
#include <QApplication>
+#include "config.h"
+#include "bacula.h"
+#include "console_conf.h"
+#include "jcr.h"
+
+
+/* Imported functions */
+int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
+
+/* Forward referenced functions */
+void terminate_console(int sig);
+static void usage();
+static int check_resources();
+
+#define CONFIG_FILE "./qt-console.conf" /* default configuration file */
+
+/* Static variables */
+static char *configfile = NULL;
+
+MainWindow *mainWin;
int main(int argc, char *argv[])
{
+
+ int ch;
+ bool no_signals = true;
+ bool test_config = false;
+
+
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(true);
-
- MainWindow *main = new MainWindow;
- main->show();
+ mainWin = new MainWindow;
+
+ mainWin->show();
+
+#ifdef ENABLE_NLS
+ setlocale(LC_ALL, "");
+ bindtextdomain("bacula", LOCALEDIR);
+ textdomain("bacula");
+#endif
+
+ init_stack_dump();
+ my_name_is(argc, argv, "gnome-console");
+ init_msg(NULL, NULL);
+ working_directory = "/tmp";
+
+ struct sigaction sigignore;
+ sigignore.sa_flags = 0;
+ sigignore.sa_handler = SIG_IGN;
+ sigfillset(&sigignore.sa_mask);
+ sigaction(SIGPIPE, &sigignore, NULL);
+
+ while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
+ switch (ch) {
+ case 'c': /* configuration file */
+ if (configfile != NULL) {
+ free(configfile);
+ }
+ configfile = bstrdup(optarg);
+ break;
+
+ case 'd':
+ debug_level = atoi(optarg);
+ if (debug_level <= 0)
+ debug_level = 1;
+ break;
+
+ case 's': /* turn off signals */
+ no_signals = true;
+ break;
+
+ case 't':
+ test_config = true;
+ break;
+
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+
+ if (!no_signals) {
+ init_signals(terminate_console);
+ }
+
+ if (argc) {
+ usage();
+ }
+
+ if (configfile == NULL) {
+ configfile = bstrdup(CONFIG_FILE);
+ }
+
+ parse_config(configfile);
+ set_text("Configuration read.\n");
+
+ if (init_crypto() != 0) {
+ Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
+ }
+
+ if (!check_resources()) {
+ Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
+ }
+
return app.exec();
}
+
+void terminate_console(int sig)
+{
+ (void)sig; /* avoid compiler complaints */
+ exit(0);
+}
+
+static void usage()
+{
+ fprintf(stderr, _(
+PROG_COPYRIGHT
+"\nVersion: %s (%s) %s %s %s\n\n"
+"Usage: qt-console [-s] [-c config_file] [-d debug_level] [config_file]\n"
+" -c <file> set configuration file to file\n"
+" -dnn set debug level to nn\n"
+" -s no signals\n"
+" -t test - read configuration and exit\n"
+" -? print this message.\n"
+"\n"), 2007, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
+
+ exit(1);
+}
+
+/*
+ * Call-back for reading a passphrase for an encrypted PEM file
+ * This function uses getpass(), which uses a static buffer and is NOT thread-safe.
+ */
+static int tls_pem_callback(char *buf, int size, const void *userdata)
+{
+#ifdef HAVE_TLS
+ const char *prompt = (const char *) userdata;
+ char *passwd;
+
+ passwd = getpass(prompt);
+ bstrncpy(buf, passwd, size);
+ return (strlen(buf));
+#else
+ buf[0] = 0;
+ return 0;
+#endif
+}
+
+
+/*
+ * Make a quick check to see that we have all the
+ * resources needed.
+ */
+static int check_resources()
+{
+ bool ok = true;
+ DIRRES *director;
+ int numdir;
+
+ LockRes();
+
+ numdir = 0;
+ foreach_res(director, R_DIRECTOR) {
+ numdir++;
+ /* tls_require implies tls_enable */
+ if (director->tls_require) {
+ if (have_tls) {
+ director->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ ok = false;
+ continue;
+ }
+ }
+
+ if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && director->tls_enable) {
+ Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
+ " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
+ " At least one CA certificate store is required.\n"),
+ director->hdr.name, configfile);
+ ok = false;
+ }
+ }
+
+ if (numdir == 0) {
+ Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
+ "Without that I don't how to speak to the Director :-(\n"), configfile);
+ ok = false;
+ }
+
+ CONRES *cons;
+ /* Loop over Consoles */
+ foreach_res(cons, R_CONSOLE) {
+ /* tls_require implies tls_enable */
+ if (cons->tls_require) {
+ if (have_tls) {
+ cons->tls_enable = true;
+ } else {
+ Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+ ok = false;
+ continue;
+ }
+ }
+
+ if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable) {
+ Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
+ " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
+ cons->hdr.name, configfile);
+ ok = false;
+ }
+ }
+
+ UnlockRes();
+
+ return ok;
+}
<string>qt-console</string>
</property>
<property name="windowIcon" >
- <iconset>images/bat_icon.png</iconset>
+ <iconset>images/bat-natural-fullsize.png</iconset>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QGridLayout" >
lineEdit->clear(); /* clear the lineEdit box */
textEdit->append(cmdStr); /* append text on screen */
}
+
+void set_textf(const char *fmt, ...)
+{
+ va_list arg_ptr;
+ char buf[1000];
+ int len;
+ va_start(arg_ptr, fmt);
+ len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
+ va_end(arg_ptr);
+ mainWin->textEdit->append(buf);
+}
+
+void set_text(const char *buf)
+{
+ mainWin->textEdit->append(buf);
+}
+
+void set_statusf(const char *fmt, ...)
+{
+ va_list arg_ptr;
+ char buf[1000];
+ int len;
+ va_start(arg_ptr, fmt);
+ len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
+ va_end(arg_ptr);
+// gtk_label_set_text(GTK_LABEL(status1), buf);
+// set_scroll_bar_to_end();
+// ready = false;
+}
+
+void set_status_ready()
+{
+ mainWin->statusBar()->showMessage("Ready");
+// ready = true;
+// set_scroll_bar_to_end();
+}
+
+void set_status(const char *buf)
+{
+ mainWin->statusBar()->showMessage(buf);
+// ready = false;
+}
private:
QString m_UserInput;
};
+
+extern MainWindow *mainWin;
+
+void set_textf(const char *fmt, ...);
+void set_text(const char *buf);
+
+int bvsnprintf(char *str, int32_t size, const char *format, va_list ap);
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
+INCLUDEPATH += ..
+LIBS += -L../lib
+LIBS += -lbac
+LIBS += -lssl -lcrypto
RESOURCES = main.qrc
# Input
FORMS += main.ui
-HEADERS += mainwindow.h
-SOURCES += main.cpp
+HEADERS += mainwindow.h console_conf.h
+SOURCES += main.cpp authenticate.cpp console_conf.cpp
SOURCES += mainwindow.cpp