Skip to contentSkip to conversation

genhomedircon

PATCH Russell Coker 1 participant 1 message Jun 16, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have made some minor changes to genhomedircon (attached a diff against the Fedora version and a copy of the modified script).

This improves the error handling code to make it clear when an error condition is caused by bad parameters and when it's by an internal error. It also fixes a bug so that now the following line in the "users" file will be accepted and not cause the program to abort:
user root roles user_r;

Previously it demanded the following instead:
user root roles { user_r };

Signature · 2 lines
http://apac.redhat.com/disclaimer
See above URL for disclaimer.
genhomedircon renamed from genhomedircon.orig +16 -8
@@ -51,7 +51,10 @@
 				if user[1] == "user_u" or user[1] == "system_u":
 					continue
 				# !!! chooses first role in the list to use in the file context !!!
-				role = user[4].split("_r")[0]
+				role = user[3]
+				if role == "{":
+					role = user[4]
+				role = role.split("_r")[0]
 				home = pwd.getpwnam(user[1])[5]
 				if home == "/":
 					continue
@@ -70,18 +73,24 @@
 	sys.stderr.flush()
 	sys.exit(1)
 	
+def errorExit(error):
+	sys.stderr.write("%s exiting for: " % sys.argv[0])
+	sys.stderr.write("%s\n" % error)
+	sys.stderr.flush()
+	sys.exit(1)
+	
 def update(filecontext, user, prefs):
 	rc=commands.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))
 	if rc[0] == 0:
 		print rc[1]
 	else:
-		usage(rc[1])
+		errorExit(join("grep/sed error ", rc[1]))
 	return rc
 
 try:
 	if len(sys.argv) != 3:
 		print len(sys.argv)
-		usage()
+		usage("Incorrect parameters")
 
 	FILECONTEXTDIR=sys.argv[1]
 	prefixes = getPrefixes()
@@ -91,8 +100,7 @@
 		homedir = rc[1].split("=")[1]
 	else:
 		sys.stderr.write("%s\n" % (rc[1],))
-		sys.stderr.write("You do not have access to /etc/default/useradd
-, default /home\n")
+		sys.stderr.write("You do not have access to /etc/default/useradd, default /home\n")
 		sys.stderr.flush()
 		homedir = "/home"
 		
@@ -109,7 +117,7 @@
 	if rc[0] == 0:
 		print rc[1]
 	else:
-		usage(rc[1])
+		errorExit(join("sed error ", rc[1]))
 
 	users = getUsers()
 	print "\n#\n# User-specific file contexts\n#\n"
@@ -118,6 +126,6 @@
 	for u in users.keys():
 		update(sys.argv[2], u, users[u]) 
 except ValueError, error:
-	usage(error)
+	errorExit(join("ValueError ", error))
 except IndexError, error:
-	usage()
+	errorExit("IndexError")