Skip to content

Commit

Permalink
show cmd: add verbose option
Browse files Browse the repository at this point in the history
When using the verbose option, also default and inherit directives are
show. These directives are prefixed by a "# " character.
  • Loading branch information
joergsteffens committed Aug 25, 2016
1 parent b2ed854 commit e5f67ab
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 170 deletions.
4 changes: 2 additions & 2 deletions src/console/console_conf.c
Expand Up @@ -110,7 +110,7 @@ static RES_TABLE resources[] = {
*/
void dump_resource(int type, RES *reshdr,
void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
void *sock, bool hide_sensitive_data, bool verbose)
{
POOL_MEM buf;
URES *res = (URES *)reshdr;
Expand All @@ -135,7 +135,7 @@ void dump_resource(int type, RES *reshdr,
sendit(sock, "%s", buf.c_str());

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

Expand Down
64 changes: 28 additions & 36 deletions src/dird/dird_conf.c
Expand Up @@ -1295,14 +1295,6 @@ char *CATRES::display(POOLMEM *dst)
return dst;
}

static void indent_config_item(POOL_MEM &cfg_str, int level, const char *config_item)
{
for (int i = 0; i < level; i++) {
pm_strcat(cfg_str, DEFAULT_INDENT_STRING);
}
pm_strcat(cfg_str, config_item);
}

static inline void print_config_runscript(RES_ITEM *item, POOL_MEM &cfg_str)
{
POOL_MEM temp;
Expand Down Expand Up @@ -1856,7 +1848,7 @@ static inline void print_config_run(RES_ITEM *item, POOL_MEM &cfg_str)
}
}

bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data, bool verbose)
{
POOL_MEM cfg_str;
POOL_MEM temp;
Expand Down Expand Up @@ -2277,7 +2269,7 @@ const char *level_to_str(int level)
*/
void dump_resource(int type, RES *ures,
void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
void *sock, bool hide_sensitive_data, bool verbose)
{
URES *res = (URES *)ures;
bool recurse = true;
Expand All @@ -2296,71 +2288,71 @@ void dump_resource(int type, RES *ures,

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

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

Expand Down Expand Up @@ -3981,7 +3973,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, bool hide_sensitive_data)
static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide_sensitive_data, bool inherited)
{
POOL_MEM temp;

Expand All @@ -3998,7 +3990,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
list = *(items[i].alistvalue);
if (list != NULL) {
Mmsg(temp, "%s = ", items[i].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);

pm_strcpy(res_names, "");
foreach_alist(res, list) {
Expand Down Expand Up @@ -4034,7 +4026,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
list = items[i].alistvalue[items[i].code];
if (list != NULL) {
Mmsg(temp, "%s = ", items[i].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
foreach_alist(value, list) {
if (cnt) {
Mmsg(temp, ",\"%s\"", value);
Expand All @@ -4060,7 +4052,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
for (int j = 0; jobtypes[j].type_name; j++) {
if (jobtypes[j].job_type == jobtype) {
Mmsg(temp, "%s = %s\n", items[i].name, jobtypes[j].type_name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4083,7 +4075,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
}

Mmsg(temp, "%s = %s\n", items[i].name, backupprotocols[j].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4097,7 +4089,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
for (int j = 0; migtypes[j].type_name; j++) {
if (migtypes[j].job_type == migtype) {
Mmsg(temp, "%s = %s\n", items[i].name, migtypes[j].type_name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4120,7 +4112,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
}

Mmsg(temp, "%s = %s\n", items[i].name, ReplaceOptions[j].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4134,7 +4126,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
for (int j = 0; joblevels[j].level_name; j++) {
if (joblevels[j].level == level) {
Mmsg(temp, "%s = %s\n", items[i].name, joblevels[j].level_name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4148,7 +4140,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
for (int j = 0; ActionOnPurgeOptions[j].name; j++) {
if (ActionOnPurgeOptions[j].token == action) {
Mmsg(temp, "%s = %s\n", items[i].name, ActionOnPurgeOptions[j].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4162,7 +4154,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
for (int j = 0; authprotocols[j].name; j++) {
if (authprotocols[j].token == authprotocol) {
Mmsg(temp, "%s = %s\n", items[i].name, authprotocols[j].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4176,7 +4168,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
for (int j = 0; authmethods[j].name; j++) {
if (authprotocols[j].token == authtype) {
Mmsg(temp, "%s = %s\n", items[i].name, authmethods[j].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);
break;
}
}
Expand All @@ -4195,7 +4187,7 @@ static void print_config_cb(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide
list = *(items[i].alistvalue);
if (list != NULL) {
Mmsg(temp, "%s = ", items[i].name);
indent_config_item(cfg_str, 1, temp.c_str());
indent_config_item(cfg_str, 1, temp.c_str(), inherited);

pm_strcpy(audit_events, "");
foreach_alist(audit_event, list) {
Expand Down
2 changes: 1 addition & 1 deletion src/dird/dird_conf.h
Expand Up @@ -498,7 +498,7 @@ class FILESETRES : public BRSRES {
bool enable_vss; /* Enable Volume Shadow Copy */

/* Methods */
bool print_config(POOL_MEM& buff, bool hide_sensitive_data);
bool print_config(POOL_MEM& buf, bool hide_sensitive_data = false, bool verbose = false);
};

/*
Expand Down
2 changes: 1 addition & 1 deletion src/dird/job.c
Expand Up @@ -1347,7 +1347,7 @@ bool get_or_create_fileset_record(JCR *jcr)
!db_get_fileset_record(jcr, jcr->db, &fsr)) {
POOL_MEM FileSetText(PM_MESSAGE);

jcr->res.fileset->print_config(FileSetText, false);
jcr->res.fileset->print_config(FileSetText, false, false);
fsr.FileSetText = FileSetText.c_str();

if (!db_create_fileset_record(jcr, jcr->db, &fsr)) {
Expand Down
6 changes: 3 additions & 3 deletions src/dird/ua_cmds.c
Expand Up @@ -373,9 +373,9 @@ static struct cmdstruct commands[] = {
NT_(""), false, true },
{ NT_("show"), show_cmd, _("Show resource records"),
NT_("jobdefs=<job-defaults> | job=<job-name> | pool=<pool-name> | fileset=<fileset-name> |\n"
"\tschedule=<schedule-name> | client=<client-name> | message=<message-resource-name> |\n"
"\tprofile=<profile-name> | jobdefs | jobs | pools | filesets | schedules | clients |\n"
"\tmessages | profiles | consoles | disabled | all"), true, true },
"schedule=<schedule-name> | client=<client-name> | message=<message-resource-name> |\n"
"profile=<profile-name> | jobdefs | jobs | pools | filesets | schedules | clients |\n"
"messages | profiles | consoles | disabled [ clients | jobs | schedules ] | all [verbose]"), true, true },
{ NT_("sqlquery"), sqlquery_cmd, _("Use SQL to query catalog"),
NT_(""), false, true },
{ NT_("time"), time_cmd, _("Print current time"),
Expand Down
16 changes: 14 additions & 2 deletions src/dird/ua_output.c
Expand Up @@ -223,6 +223,7 @@ bool show_cmd(UAContext *ua, const char *cmd)
int recurse;
char *res_name;
RES *res = NULL;
bool verbose = false;
bool hide_sensitive_data;

Dmsg1(20, "show: %s\n", ua->UA_sock->msg);
Expand All @@ -233,8 +234,19 @@ bool show_cmd(UAContext *ua, const char *cmd)
*/
hide_sensitive_data = !acl_access_ok(ua, Command_ACL, "configure", false);

if (find_arg(ua, NT_("verbose")) > 0) {
verbose = true;
}

LockRes();
for (i = 1; i < ua->argc; i++) {
/*
* skip verbose keyword, already handled earlier.
*/
if (bstrcasecmp(ua->argk[i], NT_("verbose"))) {
continue;
}

if (bstrcasecmp(ua->argk[i], _("disabled"))) {
if (((i + 1) < ua->argc) &&
bstrcasecmp(ua->argk[i + 1], NT_("jobs"))) {
Expand Down Expand Up @@ -303,7 +315,7 @@ bool show_cmd(UAContext *ua, const char *cmd)
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, hide_sensitive_data);
bsendmsg, ua, hide_sensitive_data, verbose);
}
break;
}
Expand All @@ -322,7 +334,7 @@ bool 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, hide_sensitive_data);
dump_resource(recurse ? type : -type, res, bsendmsg, ua, hide_sensitive_data, verbose);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/filed/filed_conf.c
Expand Up @@ -164,7 +164,7 @@ static RES_TABLE resources[] = {
*/
void dump_resource(int type, RES *reshdr,
void sendit(void *sock, const char *fmt, ...),
void *sock, bool hide_sensitive_data)
void *sock, bool hide_sensitive_data, bool verbose)
{
POOL_MEM buf;
URES *res = (URES *)reshdr;
Expand Down Expand Up @@ -195,7 +195,7 @@ void dump_resource(int type, RES *reshdr,
sendit(sock, "%s", buf.c_str());

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

Expand Down
13 changes: 10 additions & 3 deletions src/lib/parse_conf.h
Expand Up @@ -330,6 +330,11 @@ class BRSRES {
/* Methods */
char *name() const;
bool print_config(POOL_MEM &buf, bool hide_sensitive_data = false);
/*
* validate can be defined by inherited classes,
* when special rules for this resource type must be checked.
*/
bool validate();
};

inline char *BRSRES::name() const { return this->hdr.name; }
Expand Down Expand Up @@ -366,12 +371,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 hide_sensitive_data = false);
bool print_config(POOL_MEM &buff, bool hide_sensitive_data = false, bool verbose = 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, bool hide_sensitive_data);
typedef void (PRINT_RES_HANDLER)(RES_ITEM *items, int i, POOL_MEM &cfg_str, bool hide_sensitive_data, bool inherited);

/*
* New C++ configuration routines
Expand Down Expand Up @@ -473,13 +478,15 @@ 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, bool hide_sensitive_data = false);
void *sock, bool hide_sensitive_data = false, bool verbose = false);
void indent_config_item(POOL_MEM &cfg_str, int level, const char *config_item, bool inherited = false);
void free_resource(RES *res, int type);
void init_resource(int type, RES_ITEM *item);
bool save_resource(int type, RES_ITEM *item, int pass);
bool store_resource(int type, LEX *lc, RES_ITEM *item, int index, int pass);
const char *res_to_str(int rcode);


#ifdef HAVE_JANSSON
/*
* JSON output helper functions
Expand Down

0 comments on commit e5f67ab

Please sign in to comment.