bareos: master 08bb7f15

Author Committer Branch Timestamp Parent
mvwieringen mvwieringen master 2016-09-01 19:40 master a2e9cfb4 Pending
Affected Issues  0000628: output of list command not restricted for own jobs/clients on restricted consoles with ACLs
Changeset bcommand: Filter resources on list/llist.

This patch expands the OUTPUT_FORMATTER with a filtering framework.
On instantiate of the class you specify a callback function which
does the filtering e.g. returns true or false to indicate that the
item should or should not be printed.

The following new methods are added to the OUTPUT_FORMATTER:

- add_limit_filter_tuple(limit)
   Sets a new filtering tuple that limits the number of output
   lines.
- add_acl_filter_tuple(column, acltype)
   Sets a new filtering tuple where column is the column number in
   the SQL ROW returned and acltype being the ACL type to check
   against using acl_access_ok().
- add_res_filter_tuple(column, restype)
   Sets a new filtering tuple where column is the column number in
   the SQL ROW returned and restype being the resource type to check
   against using GetResWithName().
- add_enabled_filter_tuple(column, restype)
   Sets a new filtering tuple where column is the column number in
   the SQL ROW returned and restype being the resource type to
   retrieve and check the enabled flag of that resource.
- add_disabled_filter_tuple(column, restype)
   Sets a new filtering tuple where column is the column number in
   the SQL ROW returned and restype being the resource type to
   retrieve and check the enabled flag of that resource.
- clear_filters()
   Remove all filters currently set e.g. all tuples are removed.
- has_filters()
   Returns if there are any filters defined.
   This allows you to shurtcut in the processing loop if no
   filtering needs to be done. Then there is no need to have the
   full overhead of calling the filter_data() methods that then
   finds out there is nothing to do.
- has_acl_filters()
   Returns if there are any ACL filters defined.
- filter_data(data)
   This function invokes the callback filter function with the
   data pointer you provide.
- add_hidden_column(column)
   Sets the given column to the hidden status and as such it will
   not be printed in the output. This allows you to add a column
   that is used for filtering but is not printed and thus invisible
   for the end-user.
- clear_hidden_columns()
   Remove all hidden columns currently set.
- is_hidden_column(column)
   Returns if the given column is hidden or not.

On instantiate of the OUTPUT_FORMATTER we set the so called context
to the current UA (UserAgent) for the filter function so that is
also passed to the filter callback function. This is analog to the
send() method which already existed. As acl_access_ok() needs the
UA we need to have it accessable in the filtering function.

When you specify current in the cmdline of a list or llist it will now
set the needed resource filters which will check if the resource is
still in the active config before displaying it.

When you specify enabled in the cmdline of a list or llist it will now
set the needed resource filters which will check if the resource is
enabled or not.

When you specify disabled in the cmdline of a list or llist it will now
set the needed resource filters which will check if the resource is
disabled or not.

We now always call get_jobid_from_cmdline() to get the jobid. This way
we can check in get_jobid_from_cmdline() if the jobid given is allowed
under the current ACL settings for the UA. For this we lookup the job
data and the client data and check against the JobAcl and ClientAcl.

As part of refactoring this code we created some new and moved some
functions to be methods in the UAContext. From now on there is a
GetResByName() method that should be used to get the pointer to a
resource instead of calling the GetResByName() function directly in
src/lib/res.c as this version checks directly if the named console has
access to the wanted resource so we no longer have to code a call to
acl_access_ok(). All the macros for GetXXXResByName now are also methods
of the UAContext and use the new method. We also removed quite some
redundant LockRes() and UnlockRes() calls as at the lowest level when
calling a GetXXXResByName() a GetResByName() is called and that already
does the right locking and unlocking. One of the nicer advantages of
the new approach to check for acl_acces_ok() in the resource lookup is
that the end-user gets back resource unknown instead of access denied
to resource (an audit event is logged however). This is also how things
work in most password authentication lookups in most UNIXes these days
as such you don't leak information about existing but not reachable
resources.

From now on messages will only be shown using the messages and .messages
functions to consoles with a non restrictive Command ACL setting. This
way no information can leak to any named console which doesn't have any
access to certain commands. Those named consoles can still do a list log
and see the data they are supposed to see under the restrictions of the
ACL that apply to those consoles.

Fixes 0000628: output of list command not restricted for own jobs/clients
            on restricted consoles with ACLs
mod - src/cats/protos.h Diff File
mod - src/cats/sql.c Diff File
mod - src/cats/sql_list.c Diff File
mod - src/dird/dird_conf.c Diff File
mod - src/dird/dird_conf.h Diff File
mod - src/dird/fd_cmds.c Diff File
mod - src/dird/migrate.c Diff File
mod - src/dird/protos.h Diff File
mod - src/dird/ua.h Diff File
mod - src/dird/ua_acl.c Diff File
mod - src/dird/ua_audit.c Diff File
mod - src/dird/ua_cmds.c Diff File
mod - src/dird/ua_configure.c Diff File
mod - src/dird/ua_db.c Diff File
mod - src/dird/ua_dotcmds.c Diff File
mod - src/dird/ua_label.c Diff File
mod - src/dird/ua_output.c Diff File
mod - src/dird/ua_prune.c Diff File
mod - src/dird/ua_restore.c Diff File
mod - src/dird/ua_run.c Diff File
mod - src/dird/ua_select.c Diff File
mod - src/dird/ua_server.c Diff File
mod - src/dird/ua_status.c Diff File
mod - src/dird/ua_update.c Diff File
mod - src/lib/output_formatter.c Diff File
mod - src/lib/output_formatter.h Diff File
mod - src/lib/parse_conf.h Diff File
mod - src/lib/res.c Diff File