| 1 |
# Authors: Petr Viktorin <[email protected]> |
| 2 |
# |
| 3 |
# Copyright (C) 2014 Red Hat |
| 4 |
# see file 'COPYING' for use and warranty information |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
|
| 21 |
class SetseboolError(Exception): |
| 22 |
"""Raised when setting a SELinux boolean fails |
| 23 |
|
| 24 |
:param failed: Dictionary mapping boolean names to intended values |
| 25 |
to their intended values, for booleans that cound not be set |
| 26 |
:param command: Command the user can run to set the booleans |
| 27 |
|
| 28 |
The initializer arguments are copied to attributes of the same name. |
| 29 |
""" |
| 30 |
def __init__(self, failed, command): |
| 31 |
message = "Could not set SELinux booleans: %s" % ' '.join( |
| 32 |
'%s=%s' % (name, value) for name, value in failed.items()) |
| 33 |
super(SetseboolError, self).__init__(message) |
| 34 |
self.failed = failed |
| 35 |
self.command = command |
| 36 |
|
| 37 |
def format_service_warning(self, service_name): |
| 38 |
"""Format warning for display when this is raised from service install |
| 39 |
""" |
| 40 |
return '\n'.join([ |
| 41 |
'WARNING: %(err)s', |
| 42 |
'', |
| 43 |
'The %(service)s may not function correctly until ', |
| 44 |
'the booleans are successfully changed with the command:', |
| 45 |
' %(cmd)s', |
| 46 |
'Try updating the policycoreutils and selinux-policy packages.' |
| 47 |
]) % {'err': self, 'service': service_name, 'cmd': self.command} |