Commit Graph

19 Commits

Author SHA1 Message Date
Todd C. Miller
a38b714667 sudoers plugin: silence most -Wconversion warnings. 2023-07-07 15:07:04 -06:00
Todd C. Miller
f066ff9e01 Eliminate a few harmless dead stores.
Quiets warnings from Infer.
2022-11-22 11:18:24 -07:00
Todd C. Miller
a2b0a8330c Fix a few whitespace issues. 2022-07-09 11:21:17 -06:00
kernelmethod
c20859d55b Add an APPARMOR_PROFILE user spec option to sudoers
sudoers now supports an APPARMOR_PROFILE option, which can be specified
as e.g.

    alice       ALL=(ALL:ALL)   APPARMOR_PROFILE=foo    ALL

The line above says "user alice can run any command as any user/group,
under confinement by the AppArmor profile 'foo'." Profiles can be
specified in any way that complies with the rules of
aa_change_profile(2). For instance, the sudoers configuration

    alice       ALL=(ALL:ALL)   APPARMOR_PROFILE=unconfined     ALL

allows alice to run any command unconfined (i.e., without an AppArmor
profile), while

    alice       ALL=(ALL:ALL)   APPARMOR_PROFILE=foo//&bar      ALL

tells sudoers that alice can run any command under the stacked AppArmor
profiles 'foo' and 'bar'.

The intention of this option is to give sysadmins on Linux distros
supporting AppArmor better options for fine-grained access control.
Among other things, this option can enforce mandatory access control
(MAC) over the operations that a privileged user is able to perform to
ensure that they cannot privesc past the boundaries of a specified
profile. It can also be used to limit which users are able to get
unconfined system access, by enforcing a default AppArmor profile on all
users and then specifying 'APPARMOR_PROFILE=unconfined' for a privileged
subset of users.
2022-05-23 13:41:56 -06:00
Todd C. Miller
960bf99656 defaults_check_conflict: it is only really a conflict if the binding match
If the Defaults name matched but the binding does not, we can simply
leave it be.  Fixes a problem where given two sudoers sources that
have a host specified, if they contain conflicting Defaults entries
we would drop one of the Defaults instead of keeping both after
making them host-specific.
2022-01-31 19:18:04 -07:00
Todd C. Miller
8f4351a897 Make it possible to merge a host-based Defaults with a global one.
We convert the global Defaults to a host-based one with a single
"ALL" member.  Later, when we simplify the host list, we'll convert
this back to a global Defaults.
2022-01-31 19:18:03 -07:00
Todd C. Miller
d6ff97d837 defaults_var_matches() should return bool, not enum match_result.
Remove enum match_result as it is no longer used.
2022-01-05 11:12:07 -07:00
Todd C. Miller
296d876b76 userspec_overridden: fix checks when there is more than one userspec 2022-01-03 16:40:32 -07:00
Todd C. Miller
835079fa3f Fix merging of global/ALL entries when each input file has a host.
If a host is specified for the input file, cvtsudoers will bind
global Defaults to that host and change host "ALL" in a userspec
to the host name.  However, if all the input files have matching
hosts we can simplify the merged file by converting back to ALL
after resolving conflicts.
2022-01-03 13:23:22 -07:00
Todd C. Miller
149e8208b5 cvtsudoers: fix a regression when merging matching Defaults.
If a host is specified with a sudoers file, we have to treat Defaults
as Defaults@host checking for duplicates.
2021-12-20 12:57:02 -07:00
Todd C. Miller
dfc11d7483 When merging Defaults, allow a subsequent global Defaults (no
binding) to override a prior Defaults setting with a binding.
2021-12-17 18:59:29 -07:00
Todd C. Miller
546d4f6246 Plug memory leak when making a default host-specific.
We don't need to allocate new space for the binding list,
just the members of the list.
2021-12-17 16:01:11 -07:00
Todd C. Miller
0608a4ea6f cvtsudoers: better merging of lists that are not exact duplicates
When merging rules, if one list would be overridden by another,
remove the overridden rule and continue merging.
2021-11-29 11:50:40 -07:00
Todd C. Miller
003f9550f1 cvtsudoers: add -l option to log merge actions
The "-l logfile" option can be used to store a log of what
actions cvtsudoers took when merging multiple files.
For example, which aliases were renamed, which entries were overriden
or removed as duplicated.
2021-11-24 06:52:51 -07:00
Todd C. Miller
e64a089aea Add reference counting to Defaults bindings.
Previously, we checked that the previous entry's binding pointer
was not the same while freeing.  However, to be able to merge
Defaults records we cannot rely on Defaults entries with the same
binding being immediately adjacent.  This removes the prev_binding
checks in favor of a reference count which allows us to plug the
memory leak in cvtsudoers when merging Defaults.
2021-11-20 08:01:37 -07:00
Todd C. Miller
aed51033e1 cvtsudoers: use init_parse_tree() to initialize a parse tree.
Also free the parse tree before exit.
2021-11-19 12:29:21 -07:00
Todd C. Miller
f5c6e2df7b cvtsudoers: merge userspecs when multiple sudoers files are specified
If a hostname is specified with the sudoers file, it will be used to
make the userspec host-specific, if possible.  Duplicate userspecs
are removed but conflicting entries are not currently pruned.
2021-11-19 12:29:21 -07:00
Todd C. Miller
d31109ded2 cvtsudoers: merge Defaults when multiple sudoers files are specified
If a hostname is specified with the sudoers file, it will be used to
make the Defaults setting host-specific, if possible.
Duplicate Defaults settings are removed and conflicts are warned about.
It is not possible to resolve all conflicts automatically.
2021-11-19 12:29:21 -07:00
Todd C. Miller
ab9e44a6ca cvtsudoers: merge aliases when multiple sudoers files are specified
Duplicate aliases are remove.  If there are conflicting alias names,
the conflicts are renamed by appending a numerical suffix.
For example, if there are two SERVERS Host_Aliases, the second one
will be renamed to SERVERS_1.
2021-11-19 12:29:21 -07:00