diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index ab8d979..33e10e3 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -62,6 +62,7 @@ static int delete_cmd(UAContext *ua, const char *cmd); static int disable_cmd(UAContext *ua, const char *cmd); static int enable_cmd(UAContext *ua, const char *cmd); static int estimate_cmd(UAContext *ua, const char *cmd); +static bool is_valid_cmd(UAContext *ua, int cmd_index); static int help_cmd(UAContext *ua, const char *cmd); static int memory_cmd(UAContext *ua, const char *cmd); static int mount_cmd(UAContext *ua, const char *cmd); @@ -1985,37 +1986,90 @@ int wait_cmd(UAContext *ua, const char *cmd) return 1; } +/* return true if the command at index cmd_index in commands is validly able + to be used by this user agent */ +static bool is_valid_cmd(UAContext *ua, int cmd_index) +{ + int len; + + len = strlen(commands[cmd_index].key); + + return + /* quit and .quit should always be valid */ + (strcmp(commands[cmd_index].key, "quit") == 0) || + (strcmp(commands[cmd_index].key, ".quit") == 0) || + acl_access_ok(ua, Command_ACL, commands[cmd_index].key, len) || + (ua->runscript && commands[cmd_index].use_in_rs); +} static int help_cmd(UAContext *ua, const char *cmd) { int i; + char validity = ' '; + int is_restricted_console = false; + ua->send_msg(_(" Command Description\n ======= ===========\n")); for (i=0; iargc == 2) { if (!strcasecmp(ua->argk[1], commands[i].key)) { - ua->send_msg(_(" %-13s %s\n\nArguments:\n\t%s\n"), commands[i].key, - commands[i].help, commands[i].usage); + ua->send_msg(_("%c %-13s %s\n\nArguments:\n\t%s\n"), + validity, commands[i].key, + commands[i].help, commands[i].usage); + if (!is_valid_cmd(ua, i)) { + /* if we asked for help on an invalid command, ensure we + inform the user that this is a restricted console */ + is_restricted_console = true; + } break; } } else { - ua->send_msg(_(" %-13s %s\n"), commands[i].key, commands[i].help); + if (!is_valid_cmd(ua, i)) { + /* saturate this boolean if any commands we're emitting + happened to be invalid */ + is_restricted_console = true; + } + ua->send_msg(_("%c %-13s %s\n"), + validity, commands[i].key, commands[i].help); } } if (i == comsize && ua->argc == 2) { ua->send_msg(_("\nCan't find %s command.\n\n"), ua->argk[1]); } - ua->send_msg(_("\nWhen at a prompt, entering a period cancels the command.\n\n")); + + if (is_restricted_console) { + /* Emit a message if we told the user about any kind of invalid command */ + ua->send_msg(_("\nThis is a restricted console. Commands marked with ! are invalid.\n")); + } + + ua->send_msg(_("\nWhen at a prompt, entering a period cancels the command.\n")); + return 1; } int qhelp_cmd(UAContext *ua, const char *cmd) { int i,j; + const char *cmd_is_valid_fmt = "%s\n"; + const char *cmd_is_invalid_fmt = "!%s\n"; + const char *everything_is_valid_fmt = "%s %s -- %s\n"; + const char *everything_is_invalid_fmt = "!%s %s -- %s\n"; + const char *fmt; + /* Want to display only commands */ j = find_arg(ua, NT_("all")); if (j >= 0) { for (i=0; isend_msg("%s\n", commands[i].key); + fmt = is_valid_cmd(ua, i)? + cmd_is_valid_fmt: + cmd_is_invalid_fmt; + + ua->send_msg(fmt, commands[i].key); } return 1; } @@ -2024,7 +2078,15 @@ int qhelp_cmd(UAContext *ua, const char *cmd) if (j >= 0 && ua->argk[j]) { for (i=0; iargv[j])) { + /* send the usage */ ua->send_msg("%s\n", commands[i].usage); + + /* However, inform the user the command isn't actually available + if that is the case. */ + if (is_valid_cmd(ua, i) == false) { + ua->send_msg("The command '%s' is invalid in this restricted console.\n", commands[i].key); + } + break; } } @@ -2032,7 +2094,11 @@ int qhelp_cmd(UAContext *ua, const char *cmd) } /* Want to display everything */ for (i=0; isend_msg("%s %s -- %s\n", commands[i].key, commands[i].help, commands[i].usage); + fmt = is_valid_cmd(ua, i)? + everything_is_valid_fmt: + everything_is_invalid_fmt; + + ua->send_msg(fmt, commands[i].key, commands[i].help, commands[i].usage); } return 1; }