* Mon Nov 14 2005 Dan Walsh <dwalsh@redhat.com> 1.27.27-5

- Fix genhomedircon to work with non libsemanage systems
This commit is contained in:
Daniel J Walsh 2005-11-14 20:26:05 +00:00
parent e27699418d
commit a95038d775

View File

@ -1,6 +1,6 @@
diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon policycoreutils-1.27.27/scripts/genhomedircon diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon policycoreutils-1.27.27/scripts/genhomedircon
--- nsapolicycoreutils/scripts/genhomedircon 2005-09-12 16:33:30.000000000 -0400 --- nsapolicycoreutils/scripts/genhomedircon 2005-09-12 16:33:30.000000000 -0400
+++ policycoreutils-1.27.27/scripts/genhomedircon 2005-11-14 13:56:01.000000000 -0500 +++ policycoreutils-1.27.27/scripts/genhomedircon 2005-11-14 15:25:45.000000000 -0500
@@ -15,32 +15,19 @@ @@ -15,32 +15,19 @@
# The file CONTEXTDIR/files/homedir_template exists. This file is used to # The file CONTEXTDIR/files/homedir_template exists. This file is used to
# set up the home directory context for each real user. # set up the home directory context for each real user.
@ -220,7 +220,7 @@ diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon po
self.type=type self.type=type
self.selinuxdir=selinuxdir +"/" self.selinuxdir=selinuxdir +"/"
self.contextdir="/contexts" self.contextdir="/contexts"
@@ -312,48 +141,68 @@ @@ -312,48 +141,75 @@
else: else:
errorExit(string.join("sed error ", rc[1])) errorExit(string.join("sed error ", rc[1]))
@ -236,10 +236,15 @@ diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon po
+ if self.semanaged: + if self.semanaged:
+ ret += "# use seusers command to manage system users in order to change the file_context\n#\n#\n" + ret += "# use seusers command to manage system users in order to change the file_context\n#\n#\n"
+ else: + else:
+ ret += "# edit %s to change file_context\n#\n#\n" % self.selinuxdir+self.type+"/seusers" + ret += "# edit %s to change file_context\n#\n#\n" % (self.selinuxdir+self.type+"/seusers")
return ret return ret
+ - def getUsers(self):
- users=""
- rc = commands.getstatusoutput('grep "^user" %s' % self.getSystemUsersFile())
- if rc[0] == 0:
- users+=rc[1]+"\n"
- rc = commands.getstatusoutput("grep ^user %s" % self.getUsersFile())
+ def defaultrole(self, name): + def defaultrole(self, name):
+ for idx in range(self.usize): + for idx in range(self.usize):
+ user = semanage_user_by_idx(self.ulist, idx) + user = semanage_user_by_idx(self.ulist, idx)
@ -251,6 +256,18 @@ diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon po
+ else: + else:
+ return role + return role
+ return name + return name
+ def getOldRole(self, role):
+ rc = commands.getstatusoutput('grep "^user %s" %s' % (role, self.selinuxdir+self.type+"/users/system.users"))
+ if rc[0] != 0:
+ rc = commands.getstatusoutput('grep "^user %s" %s' % (role, self.selinuxdir+self.type+"/users/local.users"))
if rc[0] == 0:
- users+=rc[1]
+ user=rc[1].split()
+ role = user[3]
+ if role == "{":
+ role = user[4]
+ return role
+
+ def adduser(self, udict, user, seuser, role): + def adduser(self, udict, user, seuser, role):
+ try: + try:
+ if seuser == "user_u" or user == "__default__": + if seuser == "user_u" or user == "__default__":
@ -268,14 +285,7 @@ diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon po
+ except KeyError: + except KeyError:
+ sys.stderr.write("The user \"%s\" is not present in the passwd file, skipping...\n" % user) + sys.stderr.write("The user \"%s\" is not present in the passwd file, skipping...\n" % user)
+ +
def getUsers(self): + def getUsers(self):
- users=""
- rc = commands.getstatusoutput('grep "^user" %s' % self.getSystemUsersFile())
- if rc[0] == 0:
- users+=rc[1]+"\n"
- rc = commands.getstatusoutput("grep ^user %s" % self.getUsersFile())
- if rc[0] == 0:
- users+=rc[1]
udict = {} udict = {}
- prefs = {} - prefs = {}
- if users != "": - if users != "":
@ -315,15 +325,12 @@ diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon po
- udict[user[1]] = prefs - udict[user[1]] = prefs
- except KeyError: - except KeyError:
- sys.stderr.write("The user \"%s\" is not present in the passwd file, skipping...\n" % user[1]) - sys.stderr.write("The user \"%s\" is not present in the passwd file, skipping...\n" % user[1])
+ if user[0] == "root": + role=self.getOldRole(user[1])
+ role="user"
+ else:
+ role=user[1]
+ self.adduser(udict, user[0], user[1], role) + self.adduser(udict, user[0], user[1], role)
return udict return udict
def getHomeDirContext(self, user, home, role): def getHomeDirContext(self, user, home, role):
@@ -362,9 +211,8 @@ @@ -362,9 +218,8 @@
return ret + rc[1] + "\n" return ret + rc[1] + "\n"
def getUserContext(self, user, sel_user, role): def getUserContext(self, user, sel_user, role):
@ -334,7 +341,7 @@ diff --exclude-from=exclude -N -u -r nsapolicycoreutils/scripts/genhomedircon po
def genHomeDirContext(self): def genHomeDirContext(self):
users = self.getUsers() users = self.getUsers()
@@ -478,10 +326,6 @@ @@ -478,10 +333,6 @@
if type==None: if type==None:
type=getSELinuxType(directory) type=getSELinuxType(directory)