fix travis and genhomedircon
This commit is contained in:
parent
3b3e6f75d3
commit
33fd9ae139
|
@ -109,5 +109,5 @@ after_success:
|
|||
- make DESTDIR=${HOME}/tmp install
|
||||
- make DESTDIR=${HOME}/tmp install-headers
|
||||
- make DESTDIR=${HOME}/tmp install-src
|
||||
- make DESTDIR=${HOME}/tmp install-doc
|
||||
- make DESTDIR=${HOME}/tmp install-docs
|
||||
- make DESTDIR=${HOME}/tmp install-appconfig
|
||||
|
|
|
@ -40,13 +40,26 @@
|
|||
# are always "real" (including root, in the default configuration).
|
||||
#
|
||||
|
||||
import subprocess, sys, os, pwd, getopt, re
|
||||
import sys, os, pwd, getopt, re
|
||||
|
||||
EXCLUDE_LOGINS=["/sbin/nologin", "/bin/false"]
|
||||
|
||||
# Python 2/3 wrapper
|
||||
def getstatusoutput_wrapper(cmd):
|
||||
if sys.version_info.major is 2:
|
||||
import commands
|
||||
return commands.getstatusoutput(cmd)
|
||||
elif sys.version_info.major is 3:
|
||||
import subprocess
|
||||
return subprocess.getstatusoutput(cmd)
|
||||
else:
|
||||
print("Unsupported Python major version: " + sys.version_info.major)
|
||||
exit(1)
|
||||
|
||||
|
||||
def getStartingUID():
|
||||
starting_uid = 99999
|
||||
rc=subprocess.getstatusoutput("grep -h '^UID_MIN' /etc/login.defs")
|
||||
rc=getstatusoutput_wrapper("grep -h '^UID_MIN' /etc/login.defs")
|
||||
if rc[0] == 0:
|
||||
uid_min = re.sub("^UID_MIN[^0-9]*", "", rc[1])
|
||||
#stip any comment from the end of the line
|
||||
|
@ -54,7 +67,7 @@ def getStartingUID():
|
|||
uid_min = uid_min.strip()
|
||||
if int(uid_min) < starting_uid:
|
||||
starting_uid = int(uid_min)
|
||||
rc=subprocess.getstatusoutput("grep -h '^LU_UIDNUMBER' /etc/libuser.conf")
|
||||
rc=getstatusoutput_wrapper("grep -h '^LU_UIDNUMBER' /etc/libuser.conf")
|
||||
if rc[0] == 0:
|
||||
lu_uidnumber = re.sub("^LU_UIDNUMBER[^0-9]*", "", rc[1])
|
||||
#stip any comment from the end of the line
|
||||
|
@ -87,7 +100,7 @@ def getPrefixes():
|
|||
return prefixes
|
||||
|
||||
def getUsers(filecontextdir):
|
||||
rc = subprocess.getstatusoutput("grep ^user %s/users" % filecontextdir)
|
||||
rc = getstatusoutput_wrapper("grep ^user %s/users" % filecontextdir)
|
||||
udict = {}
|
||||
if rc[0] == 0:
|
||||
ulist = rc[1].strip().split("\n")
|
||||
|
@ -113,7 +126,7 @@ def getUsers(filecontextdir):
|
|||
return udict
|
||||
|
||||
def update(filecontext, user, prefs):
|
||||
rc=subprocess.getstatusoutput("grep -h '^HOME_DIR' %s | grep -v vmware | sed -e 's|HOME_DIR|%s|' -e 's/ROLE/%s/' -e 's/system_u/%s/'" % (filecontext, prefs["home"], prefs["role"], user))
|
||||
rc=getstatusoutput_wrapper("grep -h '^HOME_DIR' %s | grep -v vmware | sed -e 's|HOME_DIR|%s|' -e 's/ROLE/%s/' -e 's/system_u/%s/'" % (filecontext, prefs["home"], prefs["role"], user))
|
||||
if rc[0] == 0:
|
||||
print(rc[1])
|
||||
else:
|
||||
|
@ -128,7 +141,7 @@ def oldgenhomedircon(filecontextdir, filecontext):
|
|||
usage()
|
||||
#We are going to define home directory used by libuser and show-utils as a home directory root
|
||||
prefixes = {}
|
||||
rc=subprocess.getstatusoutput("grep -h '^HOME' /etc/default/useradd")
|
||||
rc=getstatusoutput_wrapper("grep -h '^HOME' /etc/default/useradd")
|
||||
if rc[0] == 0:
|
||||
homedir = rc[1].split("=")[1]
|
||||
homedir = homedir.split("#")[0]
|
||||
|
@ -143,7 +156,7 @@ def oldgenhomedircon(filecontextdir, filecontext):
|
|||
sys.stderr.flush()
|
||||
|
||||
|
||||
rc=subprocess.getstatusoutput("grep -h '^LU_HOMEDIRECTORY' /etc/libuser.conf")
|
||||
rc=getstatusoutput_wrapper("grep -h '^LU_HOMEDIRECTORY' /etc/libuser.conf")
|
||||
if rc[0] == 0:
|
||||
homedir = rc[1].split("=")[1]
|
||||
homedir = homedir.split("#")[0]
|
||||
|
@ -165,7 +178,7 @@ def oldgenhomedircon(filecontextdir, filecontext):
|
|||
#this works by grepping the file_contexts for
|
||||
# 1. ^/ makes sure this is not a comment
|
||||
# 2. prints only the regex in the first column first cut on \t then on space
|
||||
rc=subprocess.getstatusoutput("grep \"^/\" %s | cut -f 1 | cut -f 1 -d \" \" " % (sys.argv[2]) )
|
||||
rc=getstatusoutput_wrapper("grep \"^/\" %s | cut -f 1 | cut -f 1 -d \" \" " % (sys.argv[2]) )
|
||||
if rc[0] == 0:
|
||||
prefix_regex = rc[1].split("\n")
|
||||
else:
|
||||
|
@ -204,7 +217,7 @@ def oldgenhomedircon(filecontextdir, filecontext):
|
|||
sed_dir = "h; s|^HOME_DIR|%s/[^/]+|; s|ROLE_|user_|" % (prefixes.keys() + "/[^/]+|; s|ROLE_|user_|; p; g; s|^HOME_DIR|")
|
||||
|
||||
# Fill in HOME_ROOT, HOME_DIR, and ROLE for users not explicitly defined in /etc/security/selinux/src/policy/users
|
||||
rc=subprocess.getstatusoutput("sed -e \"/^HOME_ROOT/{%s}\" -e \"/^HOME_DIR/{%s}\" %s" % (sed_root, sed_dir, filecontext))
|
||||
rc=getstatusoutput_wrapper("sed -e \"/^HOME_ROOT/{%s}\" -e \"/^HOME_DIR/{%s}\" %s" % (sed_root, sed_dir, filecontext))
|
||||
if rc[0] == 0:
|
||||
print(rc[1])
|
||||
else:
|
||||
|
@ -225,7 +238,7 @@ def oldgenhomedircon(filecontextdir, filecontext):
|
|||
|
||||
def getDefaultHomeDir():
|
||||
ret = []
|
||||
rc=subprocess.getstatusoutput("grep -h '^HOME' /etc/default/useradd")
|
||||
rc=getstatusoutput_wrapper("grep -h '^HOME' /etc/default/useradd")
|
||||
if rc[0] == 0:
|
||||
homedir = rc[1].split("=")[1]
|
||||
homedir = homedir.split("#")[0]
|
||||
|
@ -238,7 +251,7 @@ def getDefaultHomeDir():
|
|||
sys.stderr.write("%s\n" % rc[1])
|
||||
sys.stderr.write("You do not have access to /etc/default/useradd HOME=\n")
|
||||
sys.stderr.flush()
|
||||
rc=subprocess.getstatusoutput("grep -h '^LU_HOMEDIRECTORY' /etc/libuser.conf")
|
||||
rc=getstatusoutput_wrapper("grep -h '^LU_HOMEDIRECTORY' /etc/libuser.conf")
|
||||
if rc[0] == 0:
|
||||
homedir = rc[1].split("=")[1]
|
||||
homedir = homedir.split("#")[0]
|
||||
|
@ -256,7 +269,7 @@ def getDefaultHomeDir():
|
|||
return ret
|
||||
|
||||
def getSELinuxType(directory):
|
||||
rc=subprocess.getstatusoutput("grep ^SELINUXTYPE= %s/config" % directory)
|
||||
rc=getstatusoutput_wrapper("grep ^SELINUXTYPE= %s/config" % directory)
|
||||
if rc[0]==0:
|
||||
return rc[1].split("=")[-1].strip()
|
||||
return "targeted"
|
||||
|
@ -299,7 +312,7 @@ class selinuxConfig:
|
|||
return self.getFileContextDir()+"/homedir_template"
|
||||
|
||||
def getHomeRootContext(self, homedir):
|
||||
rc=subprocess.getstatusoutput("grep HOME_ROOT %s | sed -e \"s|^HOME_ROOT|%s|\"" % ( self.getHomeDirTemplate(), homedir))
|
||||
rc=getstatusoutput_wrapper("grep HOME_ROOT %s | sed -e \"s|^HOME_ROOT|%s|\"" % ( self.getHomeDirTemplate(), homedir))
|
||||
if rc[0] == 0:
|
||||
return rc[1]+"\n"
|
||||
else:
|
||||
|
@ -318,10 +331,10 @@ class selinuxConfig:
|
|||
|
||||
def getUsers(self):
|
||||
users=""
|
||||
rc = subprocess.getstatusoutput('grep "^user" %s' % self.getSystemUsersFile())
|
||||
rc = getstatusoutput_wrapper('grep "^user" %s' % self.getSystemUsersFile())
|
||||
if rc[0] == 0:
|
||||
users+=rc[1]+"\n"
|
||||
rc = subprocess.getstatusoutput("grep ^user %s" % self.getUsersFile())
|
||||
rc = getstatusoutput_wrapper("grep ^user %s" % self.getUsersFile())
|
||||
if rc[0] == 0:
|
||||
users+=rc[1]
|
||||
udict = {}
|
||||
|
@ -351,7 +364,7 @@ class selinuxConfig:
|
|||
|
||||
def getHomeDirContext(self, user, home, role):
|
||||
ret="\n\n#\n# Context for user %s\n#\n\n" % user
|
||||
rc=subprocess.getstatusoutput("grep '^HOME_DIR' %s | sed -e 's|HOME_DIR|%s|' -e 's/ROLE/%s/' -e 's/system_u/%s/'" % (self.getHomeDirTemplate(), home, role, user))
|
||||
rc=getstatusoutput_wrapper("grep '^HOME_DIR' %s | sed -e 's|HOME_DIR|%s|' -e 's/ROLE/%s/' -e 's/system_u/%s/'" % (self.getHomeDirTemplate(), home, role, user))
|
||||
return ret + rc[1] + "\n"
|
||||
|
||||
def genHomeDirContext(self):
|
||||
|
@ -363,12 +376,12 @@ class selinuxConfig:
|
|||
return ret+"\n"
|
||||
|
||||
def checkExists(self, home):
|
||||
if subprocess.getstatusoutput("grep -E '^%s[^[:alnum:]_-]' %s" % (home, self.getFileContextFile()))[0] == 0:
|
||||
if getstatusoutput_wrapper("grep -E '^%s[^[:alnum:]_-]' %s" % (home, self.getFileContextFile()))[0] == 0:
|
||||
return 0
|
||||
#this works by grepping the file_contexts for
|
||||
# 1. ^/ makes sure this is not a comment
|
||||
# 2. prints only the regex in the first column first cut on \t then on space
|
||||
rc=subprocess.getstatusoutput("grep \"^/\" %s | cut -f 1 | cut -f 1 -d \" \" " % self.getFileContextFile() )
|
||||
rc=getstatusoutput_wrapper("grep \"^/\" %s | cut -f 1 | cut -f 1 -d \" \" " % self.getFileContextFile() )
|
||||
if rc[0] == 0:
|
||||
prefix_regex = rc[1].split("\n")
|
||||
else:
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
try:
|
||||
import selinux
|
||||
import warnings
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
|
||||
import selinux
|
||||
|
||||
if selinux.is_selinux_enabled():
|
||||
print(selinux.security_policyvers())
|
||||
|
|
Loading…
Reference in New Issue