Back to index

system-config-printer  1.3.9+20120706
CheckSELinux.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2010 Red Hat, Inc.
00006 ## Copyright (C) 2010 Jiri Popelka <jpopelka@redhat.com>
00007 
00008 ## This program is free software; you can redistribute it and/or modify
00009 ## it under the terms of the GNU General Public License as published by
00010 ## the Free Software Foundation; either version 2 of the License, or
00011 ## (at your option) any later version.
00012 
00013 ## This program is distributed in the hope that it will be useful,
00014 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 ## GNU General Public License for more details.
00017 
00018 ## You should have received a copy of the GNU General Public License
00019 ## along with this program; if not, write to the Free Software
00020 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 
00022 import subprocess
00023 from base import *
00024 import os
00025 import shlex
00026 from timedops import TimedSubprocess
00027 
00028 class CheckSELinux(Question):
00029     def __init__ (self, troubleshooter):
00030         Question.__init__ (self, troubleshooter, "Check SELinux contexts")
00031         troubleshooter.new_page (gtk.Label (), self)
00032 
00033     def display (self):
00034         self.answers = {}
00035         #answers = self.troubleshooter.answers
00036 
00037         RESTORECON = "/sbin/restorecon"
00038         if not os.access (RESTORECON, os.X_OK):
00039             return False
00040 
00041         try:
00042             import selinux
00043         except ImportError:
00044             return False
00045         if not selinux.is_selinux_enabled():
00046             return False
00047 
00048         paths = ["/etc/cups/", "/usr/lib/cups/", "/usr/share/cups/"]
00049         null = file ("/dev/null", "r+")
00050         parent = self.troubleshooter.get_window ()
00051         contexts = {}
00052         new_environ = os.environ.copy()
00053         new_environ['LC_ALL'] = "C"
00054         restorecon_args = [RESTORECON, "-nvR"].extend(paths)
00055         try:
00056             # Run restorecon -nvR
00057             self.op = TimedSubprocess (parent=parent,
00058                                        args=restorecon_args,
00059                                        close_fds=True,
00060                                        env=new_environ,
00061                                        stdin=null,
00062                                        stdout=subprocess.PIPE,
00063                                        stderr=null)
00064             (restorecon_stdout, restorecon_stderr, result) = self.op.run ()
00065         except:
00066             # Problem executing command.
00067             return False
00068         for line in restorecon_stdout:
00069             l = shlex.split (line)
00070             if (len (l) < 1):
00071                 continue
00072             contexts[l[2]] = l[4]
00073         self.answers['selinux_contexts'] = contexts
00074         return False
00075 
00076     def collect_answer (self):
00077         return self.answers
00078 
00079     def cancel_operation (self):
00080         self.op.cancel ()