Skip to content

Commit

Permalink
Add configure console command.
Browse files Browse the repository at this point in the history
For now this is a dummy command but eventually this will implement
the interactive configuration of the director. For now we only use
this command to determine if we should print the sensitive data
when dumping resources in the show command. If you have a console
that allows either the configure or any command you will see the
sensitive data (passwords) otherwise not.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent ae7f8ab commit f0f7fb6
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 61 deletions.
10 changes: 7 additions & 3 deletions src/console/console_conf.c
Expand Up @@ -120,8 +120,12 @@ static RES_TABLE resources[] = {
{ NULL, NULL, 0 }
};

/* Dump contents of resource */
void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
/*
* Dump contents of resource
*/
void dump_resource(int type, RES *reshdr,
void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
{
POOL_MEM buf;
URES *res = (URES *)reshdr;
Expand All @@ -146,7 +150,7 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm
sendit(sock, "%s", buf.c_str());

if (recurse && res->res_dir.hdr.next) {
dump_resource(type, res->res_dir.hdr.next, sendit, sock);
dump_resource(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/dird/Makefile.in
Expand Up @@ -33,9 +33,10 @@ SVRSRCS = admin.c authenticate.c autoprune.c backup.c bsr.c catreq.c \
inc_conf.c job.c jobq.c migrate.c mountreq.c msgchan.c ndmp_dma.c \
newvol.c next_vol.c quota.c socket_server.c recycle.c restore.c \
run_conf.c sd_cmds.c scheduler.c stats.c ua_acl.c ua_audit.c \
ua_cmds.c ua_dotcmds.c ua_input.c ua_impexp.c ua_label.c ua_output.c \
ua_prune.c ua_purge.c ua_query.c ua_restore.c ua_run.c ua_select.c \
ua_server.c ua_status.c ua_tree.c ua_update.c vbackup.c verify.c
ua_cmds.c ua_configure.c ua_dotcmds.c ua_input.c ua_impexp.c \
ua_label.c ua_output.c ua_prune.c ua_purge.c ua_query.c ua_restore.c \
ua_run.c ua_select.c ua_server.c ua_status.c ua_tree.c ua_update.c \
vbackup.c verify.c
SVROBJS = $(SVRSRCS:.c=.o)

DBCHKSRCS = dbcheck.c dird_conf.c ua_acl.c ua_audit.c run_conf.c inc_conf.c
Expand Down
36 changes: 19 additions & 17 deletions src/dird/dird_conf.c
Expand Up @@ -1375,7 +1375,7 @@ static inline void print_config_run(RES_ITEM *item, POOL_MEM &cfg_str)
}
}

bool FILESETRES::print_config(POOL_MEM &buff)
bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
{
POOL_MEM cfg_str;
POOL_MEM temp;
Expand Down Expand Up @@ -1779,7 +1779,9 @@ const char *level_to_str(int level)
/*
* Dump contents of resource
*/
void dump_resource(int type, RES *ures, void sendit(void *sock, const char *fmt, ...), void *sock)
void dump_resource(int type, RES *ures,
void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
{
URES *res = (URES *)ures;
bool recurse = true;
Expand All @@ -1798,71 +1800,71 @@ void dump_resource(int type, RES *ures, void sendit(void *sock, const char *fmt,

switch (type) {
case R_DIRECTOR:
res->res_dir.print_config(buf);
res->res_dir.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
break;
case R_PROFILE:
res->res_profile.print_config(buf);
res->res_profile.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
break;
case R_CONSOLE:
res->res_con.print_config(buf);
res->res_con.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
break;
case R_COUNTER:
res->res_counter.print_config(buf);
res->res_counter.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
break;
case R_CLIENT:
if (!ua || acl_access_ok(ua, Client_ACL, res->res_client.hdr.name)) {
res->res_client.print_config(buf);
res->res_client.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_DEVICE:
res->res_dev.print_config(buf);
res->res_dev.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
break;
case R_STORAGE:
if (!ua || acl_access_ok(ua, Storage_ACL, res->res_store.hdr.name)) {
res->res_store.print_config(buf);
res->res_store.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_CATALOG:
if (!ua || acl_access_ok(ua, Catalog_ACL, res->res_cat.hdr.name)) {
res->res_cat.print_config(buf);
res->res_cat.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_JOBDEFS:
case R_JOB:
if (!ua || acl_access_ok(ua, Job_ACL, res->res_job.hdr.name)) {
res->res_job.print_config(buf);
res->res_job.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_FILESET: {
if (!ua || acl_access_ok(ua, FileSet_ACL, res->res_fs.hdr.name)) {
res->res_fs.print_config(buf);
res->res_fs.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
}
case R_SCHEDULE:
if (!ua || acl_access_ok(ua, Schedule_ACL, res->res_sch.hdr.name)) {
res->res_sch.print_config(buf);
res->res_sch.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_POOL:
if (!ua || acl_access_ok(ua, Pool_ACL, res->res_pool.hdr.name)) {
res->res_pool.print_config(buf);
res->res_pool.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_MSGS:
res->res_msgs.print_config(buf);
res->res_msgs.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
break;
default:
Expand All @@ -1871,7 +1873,7 @@ void dump_resource(int type, RES *ures, void sendit(void *sock, const char *fmt,
}

if (recurse && res->res_dir.hdr.next) {
dump_resource(type, res->res_dir.hdr.next, sendit, sock);
dump_resource(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data);
}
}

Expand Down Expand Up @@ -3592,7 +3594,7 @@ static void parse_config_cb(LEX *lc, RES_ITEM *item, int index, int pass)
* callback function for print_config
* See ../lib/res.c, function BRSRES::print_config, for more generic handling.
*/
static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str)
static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide_sensitive_data)
{
POOL_MEM temp;

Expand Down
3 changes: 1 addition & 2 deletions src/dird/dird_conf.h
Expand Up @@ -97,7 +97,6 @@ bool print_config_schema_json(POOL_MEM &buff);

/*
* Director Resource
*
*/
class DIRRES: public BRSRES {
public:
Expand Down Expand Up @@ -518,7 +517,7 @@ class FILESETRES : public BRSRES {
bool enable_vss; /* Enable Volume Shadow Copy */

/* Methods */
bool print_config(POOL_MEM& buff);
bool print_config(POOL_MEM& buff, bool hide_sensitive_data);
};

/*
Expand Down
3 changes: 3 additions & 0 deletions src/dird/ua_cmds.c
Expand Up @@ -36,6 +36,7 @@ extern jobq_t job_queue; /* job queue */

/* Imported functions */
extern int autodisplay_cmd(UAContext *ua, const char *cmd);
extern int configure_cmd(UAContext *ua, const char *cmd);
extern int gui_cmd(UAContext *ua, const char *cmd);
extern int label_cmd(UAContext *ua, const char *cmd);
extern int list_cmd(UAContext *ua, const char *cmd);
Expand Down Expand Up @@ -108,6 +109,8 @@ static struct cmdstruct commands[] = {
NT_("on | off"), false, true },
{ NT_("cancel"), cancel_cmd, _("Cancel a job"),
NT_("storage=<storage-name> | jobid=<jobid> | job=<job-name> | ujobid=<unique-jobid> | state=<job_state> | all yes"), false, true },
{ NT_("configure"), configure_cmd, _("Configure director"),
NT_("terminal"), false, true },
{ NT_("create"), create_cmd, _("Create DB Pool from resource"),
NT_("pool=<pool-name>"), false, true },
{ NT_("delete"), delete_cmd, _("Delete volume, pool or job"),
Expand Down
36 changes: 36 additions & 0 deletions src/dird/ua_configure.c
@@ -0,0 +1,36 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2015-2015 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
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
Affero General Public License for more details.
You should have received a copy of the GNU Affero 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.
*/
/*
* BAREOS Director -- Interactive configuration engine for director.
*
* Written by Marco van Wieringen, January 2015
*/

#include "bareos.h"
#include "dird.h"

/* Forward referenced functions */

int configure_cmd(UAContext *ua, const char *cmd)
{
ua->send_msg("Interactive configuration not implemented\n");
return 1;
}
13 changes: 10 additions & 3 deletions src/dird/ua_output.c
Expand Up @@ -215,9 +215,16 @@ int show_cmd(UAContext *ua, const char *cmd)
int recurse;
char *res_name;
RES *res = NULL;
bool hide_sensitive_data;

Dmsg1(20, "show: %s\n", ua->UA_sock->msg);

/*
* When the console has no access to the configure cmd then any show cmd
* will suppress all sensitive information like for instance passwords.
*/
hide_sensitive_data = !acl_access_ok(ua, Command_ACL, "configure", false);

LockRes();
for (i = 1; i < ua->argc; i++) {
if (bstrcasecmp(ua->argk[i], _("disabled"))) {
Expand Down Expand Up @@ -284,15 +291,15 @@ int show_cmd(UAContext *ua, const char *cmd)
continue;
default:
if (my_config->m_res_head[j - my_config->m_r_first]) {
dump_resource(j, my_config->m_res_head[j - my_config->m_r_first], bsendmsg, ua);
dump_resource(j, my_config->m_res_head[j - my_config->m_r_first], bsendmsg, ua, hide_sensitive_data);
}
break;
}
}
break;
case -2:
ua->send_msg(_("Keywords for the show command are:\n"));
for (j=0; avail_resources[j].res_name; j++) {
for (j = 0; avail_resources[j].res_name; j++) {
ua->error_msg("%s\n", _(avail_resources[j].res_name));
}
goto bail_out;
Expand All @@ -303,7 +310,7 @@ int show_cmd(UAContext *ua, const char *cmd)
ua->error_msg(_("Resource %s not found\n"), res_name);
goto bail_out;
default:
dump_resource(recurse ? type : -type, res, bsendmsg, ua);
dump_resource(recurse ? type : -type, res, bsendmsg, ua, hide_sensitive_data);
break;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/filed/filed_conf.c
Expand Up @@ -167,7 +167,9 @@ static RES_TABLE resources[] = {
/*
* Dump contents of resource
*/
void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock)
void dump_resource(int type, RES *reshdr,
void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
{
POOL_MEM buf;
URES *res = (URES *)reshdr;
Expand Down Expand Up @@ -198,7 +200,7 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm
sendit(sock, "%s", buf.c_str());

if (recurse && res->res_dir.hdr.next) {
dump_resource(type, res->res_dir.hdr.next, sendit, sock);
dump_resource(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/lib/parse_conf.c
Expand Up @@ -58,8 +58,6 @@
#define MAX_PATH 1024
#endif

extern void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock);

/*
* Define the Union of all the common resource structure definitions.
*/
Expand Down Expand Up @@ -316,7 +314,7 @@ bool CONFIG::parse_config()
if (debug_level >= 900 && pass == 2) {
int i;
for (i = m_r_first; i <= m_r_last; i++) {
dump_resource(i, m_res_head[i-m_r_first], prtmsg, NULL);
dump_resource(i, m_res_head[i-m_r_first], prtmsg, NULL, false);
}
}
lc = lex_close_file(lc);
Expand Down Expand Up @@ -654,11 +652,12 @@ void CONFIG::init_resource(int type, RES_ITEM *items, int pass)
}
}

void CONFIG::dump_resources(void sendit(void *sock, const char *fmt, ...), void *sock)
void CONFIG::dump_resources(void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
{
for (int i = m_r_first; i <= m_r_last; i++) {
if (m_res_head[i - m_r_first]) {
::dump_resource(i,m_res_head[i - m_r_first],sendit,sock);
dump_resource(i,m_res_head[i - m_r_first],sendit, sock, hide_sensitive_data);
}
}
}
12 changes: 7 additions & 5 deletions src/lib/parse_conf.h
Expand Up @@ -264,7 +264,7 @@ class BRSRES {

/* Methods */
char *name() const;
bool print_config(POOL_MEM &buf);
bool print_config(POOL_MEM &buf, bool hide_sensitive_data = false);
};

inline char *BRSRES::name() const { return this->hdr.name; }
Expand Down Expand Up @@ -300,12 +300,12 @@ class MSGSRES : public BRSRES {
void wait_not_in_use(); /* in message.c */
void lock(); /* in message.c */
void unlock(); /* in message.c */
bool print_config(POOL_MEM& buff);
bool print_config(POOL_MEM &buff, bool hide_sensitive_data = false);
};

typedef void (INIT_RES_HANDLER)(RES_ITEM *item, int pass);
typedef void (STORE_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
typedef void (PRINT_RES_HANDLER)(RES_ITEM *items, int i, POOL_MEM &cfg_str);
typedef void (PRINT_RES_HANDLER)(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide_sensitive_data);

/*
* New C++ configuration routines
Expand Down Expand Up @@ -356,7 +356,8 @@ class CONFIG {
RES **save_resources();
RES **new_res_head();
void init_resource(int type, RES_ITEM *items, int pass);
void dump_resources(void sendit(void *sock, const char *fmt, ...), void *sock);
void dump_resources(void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data = false);
};

CONFIG *new_config_parser();
Expand All @@ -377,7 +378,8 @@ RES *GetResWithName(int rcode, const char *name);
RES *GetNextRes(int rcode, RES *res);
void b_LockRes(const char *file, int line);
void b_UnlockRes(const char *file, int line);
void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...), void *sock);
void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data = false);
void free_resource(RES *res, int type);
void init_resource(int type, RES_ITEM *item);
void save_resource(int type, RES_ITEM *item, int pass);
Expand Down

0 comments on commit f0f7fb6

Please sign in to comment.