/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2009 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.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Bacula® is a registered trademark of John Walker.
+ Bacula® is a registered trademark of Kern Sibbald.
The licensor of Bacula is the Free Software Foundation Europe
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
/* Imported functions */
int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
+extern bool parse_cons_config(CONFIG *config, const char *configfile, int exit_code);
/* Forward referenced functions */
static void terminate_console(int sig);
static POOLMEM *args;
static char *argk[MAX_CMD_ARGS];
static char *argv[MAX_CMD_ARGS];
+static CONFIG *config;
/* Command prototypes */
static int outputcmd(FILE *input, BSOCK *UA_sock);
static int teecmd(FILE *input, BSOCK *UA_sock);
static int quitcmd(FILE *input, BSOCK *UA_sock);
+static int helpcmd(FILE *input, BSOCK *UA_sock);
static int echocmd(FILE *input, BSOCK *UA_sock);
static int timecmd(FILE *input, BSOCK *UA_sock);
static int sleepcmd(FILE *input, BSOCK *UA_sock);
static int execcmd(FILE *input, BSOCK *UA_sock);
+#ifdef HAVE_READLINE
+static int eolcmd(FILE *input, BSOCK *UA_sock);
+#endif
#define CONFIG_FILE "bconsole.conf" /* default configuration file */
{ N_("exec"), execcmd, _("execute an external command")},
{ N_("exit"), quitcmd, _("exit = quit")},
{ N_("zed_keys"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")},
+ { N_("help"), helpcmd, _("help listing")},
+#ifdef HAVE_READLINE
+ { N_("separator"), eolcmd, _("set command separator")},
+#endif
};
-#define comsize (sizeof(commands)/sizeof(struct cmdstruct))
+#define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct)))
static int do_a_command(FILE *input, BSOCK *UA_sock)
{
#ifdef HAVE_READLINE
#define READLINE_LIBRARY 1
-#undef free
#include "readline.h"
#include "history.h"
+static char eol = '\0';
+static int eolcmd(FILE *input, BSOCK *UA_sock)
+{
+ if ((argc > 1) && (strchr("!$%&'()*+,-/:;<>?[]^`{|}~", argk[1][0]) != NULL)) {
+ eol = argk[1][0];
+ } else if (argc == 1) {
+ eol = '\0';
+ } else {
+ sendit(_("Illegal separator character.\n"));
+ }
+ return 1;
+}
+
int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
- char *line;
-
- rl_catch_signals = 0; /* do it ourselves */
- line = readline((char *)prompt); /* cast needed for old readlines */
+ static char *line = NULL;
+ static char *next = NULL;
+ static int do_history = 0;
+ char *command;
+
+ if (line == NULL) {
+ do_history = 0;
+ rl_catch_signals = 0; /* do it ourselves */
+ /* Here, readline does ***real*** malloc
+ * so, be we have to use the real free
+ */
+ line = readline((char *)prompt); /* cast needed for old readlines */
+ if (!line) {
+ exit(1);
+ }
+ strip_trailing_junk(line);
+ command = line;
+ } else if (next) {
+ command = next + 1;
+ } else {
+ sendit(_("Command logic problem\n"));
+ sock->msglen = 0;
+ sock->msg[0] = 0;
+ return 0;
+ }
- if (!line) {
- exit(1);
+ /*
+ * Split "line" into multiple commands separated by the eol character.
+ * Each part is pointed to by "next" until finally it becomes null.
+ */
+ if (eol == '\0') {
+ next = NULL;
+ } else {
+ next = strchr(command, eol);
+ if (next) {
+ *next = '\0';
+ }
+ }
+ if (command != line && isatty(fileno(input))) {
+ senditf("%s%s\n", prompt, command);
}
- strip_trailing_junk(line);
- sock->msglen = pm_strcpy(&sock->msg, line);
+
+ sock->msglen = pm_strcpy(&sock->msg, command);
if (sock->msglen) {
- add_history(sock->msg);
+ do_history++;
+ }
+
+ if (!next) {
+ if (do_history) {
+ add_history(line);
+ }
+ actuallyfree(line); /* allocated by readline() malloc */
+ line = NULL;
}
- free(line);
return 1;
}
#else /* no readline, do it ourselves */
-#if !defined(HAVE_WIN32)
+#ifdef HAVE_CONIO
static bool bisatty(int fd)
{
if (no_conio) {
configfile = bstrdup(CONFIG_FILE);
}
- parse_config(configfile);
+ config = new_config_parser();
+ parse_cons_config(config, configfile, M_ERROR_TERM);
if (init_crypto() != 0) {
Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
exit(1);
}
already_here = true;
+ config->free_resources();
+ free(config);
+ config = NULL;
cleanup_crypto();
free_pool_memory(args);
if (!no_conio) {
con_term();
}
(void)WSACleanup(); /* Cleanup Windows sockets */
+ lmgr_cleanup_main();
+
if (sig != 0) {
exit(1);
}
static int echocmd(FILE *input, BSOCK *UA_sock)
{
for (int i=1; i < argc; i++) {
- senditf("%s", argk[i]);
- sendit(" ");
+ senditf("%s ", argk[i]);
}
sendit("\n");
return 1;
return 0;
}
+static int helpcmd(FILE *input, BSOCK *UA_sock)
+{
+ int i;
+ for (i=0; i<comsize; i++) {
+ senditf(" %-10s %s\n", commands[i].key, commands[i].help);
+ }
+ return 1;
+}
+
+
static int sleepcmd(FILE *input, BSOCK *UA_sock)
{
if (argc > 1) {