Skip to content

Commit

Permalink
Merge pull request #493 from bareos/dev/fbergkemper/master/s3975
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Apr 28, 2020
2 parents 1b06287 + e9cb830 commit 544b82b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 38 deletions.
4 changes: 2 additions & 2 deletions core/src/dird/jcr_private.h
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 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
Expand Down Expand Up @@ -136,7 +136,7 @@ struct JobControlRecordPrivate {
int64_t spool_size{}; /**< Spool size for this job */
volatile bool sd_msg_thread_done{}; /**< Set when Storage message thread done */
bool IgnoreDuplicateJobChecking{}; /**< Set in migration jobs */
bool IgnoreLevelPoolOverides{}; /**< Set if a cmdline pool was specified */
bool IgnoreLevelPoolOverrides{}; /**< Set if a cmdline pool was specified */
bool IgnoreClientConcurrency{}; /**< Set in migration jobs */
bool IgnoreStorageConcurrency{}; /**< Set in migration jobs */
bool spool_data{}; /**< Spool data in SD */
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/job.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 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
Expand Down Expand Up @@ -1258,7 +1258,7 @@ void ApplyPoolOverrides(JobControlRecord* jcr, bool force)
* If a cmdline pool override is given ignore any level pool overrides.
* Unless a force is given then we always apply any overrides.
*/
if (!force && jcr->impl->IgnoreLevelPoolOverides) { return; }
if (!force && jcr->impl->IgnoreLevelPoolOverrides) { return; }

/*
* If only a pool override and no level overrides are given in run entry
Expand Down
3 changes: 2 additions & 1 deletion core/src/dird/ua.h
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2001-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 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
Expand Down Expand Up @@ -152,6 +152,7 @@ class UaContext {
*/
bool AuditEventWanted(bool audit_event_enabled);
void LogAuditEventCmdline();
void LogAuditEventInfoMsg(const char* fmt, ...);

/*
* The below are in ua_output.c
Expand Down
24 changes: 23 additions & 1 deletion core/src/dird/ua_audit.cc
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2014-2016 Bareos GmbH & Co. KG
Copyright (C) 2014-2020 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
Expand Down Expand Up @@ -142,4 +142,26 @@ void UaContext::LogAuditEventCmdline()
Emsg3(M_AUDIT, 0, _("Console [%s] from [%s] cmdline %s\n"), user_name, host,
cmd);
}

void UaContext::LogAuditEventInfoMsg(const char* fmt, ...)
{
va_list arg_ptr;
const char* user_name;
const char* host;
PoolMem message(PM_MESSAGE);

if (!me->auditing) { return; }

va_start(arg_ptr, fmt);
message.Bvsprintf(fmt, arg_ptr);
va_end(arg_ptr);

user_name =
user_acl ? user_acl->corresponding_resource->resource_name_ : "default";
host = UA_sock ? UA_sock->host() : "unknown";

Emsg3(M_AUDIT, 0, _("Console [%s] from [%s] info message %s\n"),
user_name, host, message.c_str());
}

} /* namespace directordaemon */
8 changes: 6 additions & 2 deletions core/src/dird/ua_restore.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2002-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 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
Expand Down Expand Up @@ -1134,7 +1134,11 @@ static bool BuildDirectoryTree(UaContext* ua, RestoreContext* rx)
}
}

ua->InfoMsg(_("\nBuilding directory tree for JobId(s) %s ... "), rx->JobIds);
ua->InfoMsg(
_("\nBuilding directory tree for JobId(s) %s ... "), rx->JobIds);

ua->LogAuditEventInfoMsg(
_("Building directory tree for JobId(s) %s"), rx->JobIds);

if (!ua->db->GetFileList(ua->jcr, rx->JobIds, false /* do not use md5 */,
true /* get delta */, InsertTreeHandler,
Expand Down
17 changes: 13 additions & 4 deletions core/src/dird/ua_run.cc
Expand Up @@ -2,7 +2,7 @@
Copyright (C) 2001-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 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
Expand Down Expand Up @@ -505,7 +505,7 @@ int DoRunCmd(UaContext* ua, const char* cmd)
* For interactive runs we set IgnoreLevelPoolOverrides as we already
* performed the actual overrrides.
*/
jcr->impl->IgnoreLevelPoolOverides = true;
jcr->impl->IgnoreLevelPoolOverrides = true;

if (ua->cmd[0] == 0 || bstrncasecmp(ua->cmd, NT_("yes"), strlen(ua->cmd)) ||
bstrncasecmp(ua->cmd, _("yes"), strlen(ua->cmd))) {
Expand All @@ -525,6 +525,15 @@ int DoRunCmd(UaContext* ua, const char* cmd)

FreeJcr(jcr); /* release jcr */

/*
* For interactive runs we send a message to the audit log
*/
if (jcr->impl->IgnoreLevelPoolOverrides) {
char buf[50];
ua->LogAuditEventInfoMsg(
_("Job queued. JobId=%s"), edit_int64(jcr->JobId, buf));
}

if (JobId == 0) {
ua->ErrorMsg(_("Job failed.\n"));
} else {
Expand Down Expand Up @@ -850,12 +859,12 @@ static bool ResetRestoreContext(UaContext* ua,
/*
* See if an explicit pool override was performed.
* If so set the pool_source to command line and
* set the IgnoreLevelPoolOverides so any level Pool
* set the IgnoreLevelPoolOverrides so any level Pool
* overrides are ignored.
*/
if (rc.pool_name) {
PmStrcpy(jcr->impl->res.pool_source, _("command line"));
jcr->impl->IgnoreLevelPoolOverides = true;
jcr->impl->IgnoreLevelPoolOverrides = true;
} else if (!rc.level_override &&
jcr->impl->res.pool != jcr->impl->res.job->pool) {
PmStrcpy(jcr->impl->res.pool_source, _("user input"));
Expand Down
76 changes: 50 additions & 26 deletions core/src/dird/ua_tree.cc
Expand Up @@ -75,42 +75,62 @@ struct cmdstruct {
const char* key;
int (*func)(UaContext* ua, TreeContext* tree);
const char* help;
const bool audit_event;
};

static struct cmdstruct commands[] = {
{NT_("abort"), QuitCmd, _("abort and do not do restore")},
{NT_("abort"), QuitCmd,
_("abort and do not do restore"), true},
{NT_("add"), markcmd,
_("add dir/file to be restored recursively, wildcards allowed")},
{NT_("cd"), cdcmd, _("change current directory")},
{NT_("count"), countcmd, _("count marked files in and below the cd")},
_("add dir/file to be restored recursively, wildcards allowed"), true},
{NT_("cd"), cdcmd,
_("change current directory"), true},
{NT_("count"), countcmd,
_("count marked files in and below the cd"), false},
{NT_("delete"), Unmarkcmd,
_("delete dir/file to be restored recursively in dir")},
{NT_("dir"), dircmd, _("long list current directory, wildcards allowed")},
_("delete dir/file to be restored recursively in dir"), true},
{NT_("dir"), dircmd,
_("long list current directory, wildcards allowed"), false},
{NT_(".dir"), DotDircmd,
_("long list current directory, wildcards allowed")},
{NT_("done"), donecmd, _("leave file selection mode")},
{NT_("estimate"), Estimatecmd, _("estimate restore size")},
{NT_("exit"), donecmd, _("same as done command")},
{NT_("find"), findcmd, _("find files, wildcards allowed")},
{NT_("help"), HelpCmd, _("print help")},
{NT_("ls"), lscmd, _("list current directory, wildcards allowed")},
{NT_(".ls"), DotLscmd, _("list current directory, wildcards allowed")},
_("long list current directory, wildcards allowed"), false},
{NT_("done"), donecmd,
_("leave file selection mode"), true},
{NT_("estimate"), Estimatecmd,
_("estimate restore size"), false},
{NT_("exit"), donecmd,
_("same as done command"), true},
{NT_("find"), findcmd,
_("find files, wildcards allowed"), false},
{NT_("help"), HelpCmd,
_("print help"), false},
{NT_("ls"), lscmd,
_("list current directory, wildcards allowed"), false},
{NT_(".ls"), DotLscmd,
_("list current directory, wildcards allowed"), false},
{NT_(".lsdir"), DotLsdircmd,
_("list subdir in current directory, wildcards allowed")},
{NT_("lsmark"), Lsmarkcmd, _("list the marked files in and below the cd")},
{NT_(".lsmark"), DotLsmarkcmd, _("list the marked files in")},
_("list subdir in current directory, wildcards allowed"), false},
{NT_("lsmark"), Lsmarkcmd,
_("list the marked files in and below the cd"), false},
{NT_(".lsmark"), DotLsmarkcmd,
_("list the marked files in"), false},
{NT_("mark"), markcmd,
_("mark dir/file to be restored recursively, wildcards allowed")},
_("mark dir/file to be restored recursively, wildcards allowed"), true},
{NT_("markdir"), Markdircmd,
_("mark directory name to be restored (no files)")},
{NT_("pwd"), pwdcmd, _("print current working directory")},
{NT_(".pwd"), DotPwdcmd, _("print current working directory")},
_("mark directory name to be restored (no files)"), true},
{NT_("pwd"), pwdcmd,
_("print current working directory"), false},
{NT_(".pwd"), DotPwdcmd,
_("print current working directory"), false},
{NT_("unmark"), Unmarkcmd,
_("unmark dir/file to be restored recursively in dir")},
_("unmark dir/file to be restored recursively in dir"), true},
{NT_("unmarkdir"), UnMarkdircmd,
_("unmark directory name only no recursion")},
{NT_("quit"), QuitCmd, _("quit and do not do restore")},
{NT_(".help"), DotHelpcmd, _("print help")},
{NT_("?"), HelpCmd, _("print help")},
_("unmark directory name only no recursion"), true},
{NT_("quit"), QuitCmd,
_("quit and do not do restore"), true},
{NT_(".help"), DotHelpcmd,
_("print help"), false},
{NT_("?"), HelpCmd,
_("print help"), false},
};
#define comsize ((int)(sizeof(commands) / sizeof(struct cmdstruct)))

Expand Down Expand Up @@ -172,6 +192,10 @@ bool UserSelectFilesFromTree(TreeContext* tree)
len = strlen(ua->argk[0]);
for (i = 0; i < comsize; i++) { /* search for command */
if (bstrncasecmp(ua->argk[0], commands[i].key, len)) {
// If we need to audit this event do it now.
if (ua->AuditEventWanted(commands[i].audit_event)) {
ua->LogAuditEventCmdline();
}
status = (*commands[i].func)(ua, tree); /* go execute command */
found = 1;
break;
Expand Down

0 comments on commit 544b82b

Please sign in to comment.