Blame SOURCES/authconfig-6.2.8-norestart.patch

aec187
diff -up authconfig-6.2.8/authinfo.py.norestart authconfig-6.2.8/authinfo.py
aec187
--- authconfig-6.2.8/authinfo.py.norestart	2014-01-17 15:42:31.512947910 +0100
aec187
+++ authconfig-6.2.8/authinfo.py	2014-01-29 14:58:17.010078820 +0100
aec187
@@ -80,11 +80,6 @@ PATH_PWCONV = "/usr/sbin/pwconv"
aec187
 PATH_RPCBIND = "/sbin/rpcbind"
aec187
 PATH_NSCD = "/usr/sbin/nscd"
aec187
 PATH_NSLCD = "/usr/sbin/nslcd"
aec187
-PATH_DBBIND = "/usr/sbin/dbbind"
aec187
-PATH_DBIBIND = "/usr/sbin/dbibind"
aec187
-PATH_HESIODBIND = "/usr/sbin/hesiodbind"
aec187
-PATH_LDAPBIND = "/usr/sbin/ldapbind"
aec187
-PATH_ODBCBIND = "/usr/sbin/odbcbind"
aec187
 PATH_WINBIND = "/usr/sbin/winbindd"
aec187
 PATH_SSSD = "/usr/sbin/sssd"
aec187
 PATH_YPBIND = "/usr/sbin/ypbind"
aec187
@@ -848,77 +843,13 @@ try:
aec187
 except OSError:
aec187
 	Service = SysVInitService()
aec187
 
aec187
-def toggleCachingService(enableCaching, nostart, onlystart):
aec187
-	if not nostart:
aec187
-		if enableCaching:
aec187
-			if not onlystart:
aec187
-				Service.stop("nscd")
aec187
-			Service.start("nscd")
aec187
-		else:
aec187
-			try:
aec187
-				Service.stop("nscd")
aec187
-			except OSError:
aec187
-				pass
aec187
-	return True
aec187
-
aec187
-def toggleNisService(enableNis, nisDomain, nostart, onlystart):
aec187
-	if enableNis and nisDomain:
aec187
-		if not nostart:
aec187
-			os.system("/bin/domainname " + nisDomain)
aec187
-		try:
aec187
-			os.system("[[ $(getsebool allow_ypbind) == *off* ]] && setsebool -P allow_ypbind 1")
aec187
-			os.stat(PATH_RPCBIND)
aec187
-			Service.enable("rpcbind")
aec187
-			if not nostart:
aec187
-				Service.start("rpcbind")
aec187
-		except OSError:
aec187
-			pass
aec187
-		try:
aec187
-			os.stat(PATH_YPBIND)
aec187
-			Service.enable("ypbind")
aec187
-			if not nostart:
aec187
-				if not onlystart:
aec187
-					Service.stop("ypbind")
aec187
-				Service.start("ypbind")
aec187
-		except OSError:
aec187
-			pass
aec187
-	else:
aec187
-		if not nostart:
aec187
-			os.system("/bin/domainname \"(none)\"")
aec187
-		try:
aec187
-			os.system("[[ $(getsebool allow_ypbind) == *on* ]] && setsebool -P allow_ypbind 0")
aec187
-			os.stat(PATH_YPBIND)
aec187
-			if not nostart:
aec187
-				try:
aec187
-					Service.stop("ypbind")
aec187
-				except OSError:
aec187
-					pass
aec187
-			Service.disable("ypbind")
aec187
-		except OSError:
aec187
-			pass
aec187
-	return True
aec187
-
aec187
-def toggleLDAPService(enableLDAP):
aec187
-	if enableLDAP:
aec187
-		try:
aec187
-			os.system("[[ $(getsebool authlogin_nsswitch_use_ldap) == *off* ]] && setsebool -P authlogin_nsswitch_use_ldap 1")
aec187
-		except OSError:
aec187
-			pass
aec187
-	else:
aec187
-		try:
aec187
-			os.system("[[ $(getsebool authlogin_nsswitch_use_ldap) == *on* ]] && setsebool -P authlogin_nsswitch_use_ldap 0")
aec187
-		except OSError:
aec187
-			pass
aec187
-	return True
aec187
-
aec187
-def toggleSplatbindService(enable, path, name, nostart, onlystart):
aec187
+def toggleSplatbindService(enable, path, name, nostart):
aec187
 	if enable:
aec187
 		try:
aec187
 			os.stat(path)
aec187
 			Service.enable(name)
aec187
 			if not nostart:
aec187
-				if not onlystart:
aec187
-					Service.stop(name)
aec187
+				Service.stop(name)
aec187
 				Service.start(name)
aec187
 		except OSError:
aec187
 			pass
aec187
@@ -1055,8 +986,9 @@ def read(msgcb):
aec187
 	return info
aec187
 
aec187
 class SaveGroup:
aec187
-	def __init__(self, savefunc, attrlist):
aec187
+	def __init__(self, savefunc, togglefunc, attrlist):
aec187
 		self.saveFunction = savefunc
aec187
+		self.toggleFunction = togglefunc
aec187
 		self.attrlist = attrlist
aec187
 
aec187
 	def attrsDiffer(self, a, b):
aec187
@@ -1429,49 +1361,49 @@ class AuthInfo:
aec187
 		self.sssdConfig = None
aec187
 		self.sssdDomain = None
aec187
 		self.forceSSSDUpdate = None
aec187
-		self.confChanged = False
aec187
 		if SSSDConfig:
aec187
 			try:
aec187
 				self.sssdConfig = SSSDConfig.SSSDConfig()
aec187
 				self.sssdConfig.new_config()
aec187
 			except IOError:
aec187
 				pass
aec187
+		self.toggleFunctions = set()
aec187
 		self.save_groups = [
aec187
-	SaveGroup(self.writeCache, [("enableCache", "b"), ("implicitSSSD", "b")]),
aec187
-	SaveGroup(self.writeHesiod, [("hesiodLHS", "i"), ("hesiodRHS", "i")]),
aec187
-	SaveGroup(self.writeNIS, [("nisDomain", "c"), ("nisLocalDomain", "c"), ("nisServer", "c")]),
aec187
-	SaveGroup(self.writeLDAP, [("ldapServer", "i"), ("ldapBaseDN", "c"), ("enableLDAPS", "b"),
aec187
+	SaveGroup(self.writeCache, self.toggleCachingService, [("enableCache", "b"), ("implicitSSSD", "b")]),
aec187
+	SaveGroup(self.writeHesiod, None, [("hesiodLHS", "i"), ("hesiodRHS", "i")]),
aec187
+	SaveGroup(self.writeNIS, self.toggleNisService, [("nisDomain", "c"), ("nisLocalDomain", "c"), ("nisServer", "c")]),
aec187
+	SaveGroup(self.writeLDAP, None, [("ldapServer", "i"), ("ldapBaseDN", "c"), ("enableLDAPS", "b"),
aec187
 		("ldapSchema", "c"), ("ldapCacertDir", "c"), ("passwordAlgorithm", "i")]),
aec187
-	SaveGroup(self.writeLibuser, [("passwordAlgorithm", "i")]),
aec187
-	SaveGroup(self.writeLogindefs, [("passwordAlgorithm", "i")]), # for now we do not rewrite uidMin
aec187
-        SaveGroup(self.writePWQuality, [("passMinLen", "c"), ("passMinClass", "c"),
aec187
+	SaveGroup(self.writeLibuser, None, [("passwordAlgorithm", "i")]),
aec187
+	SaveGroup(self.writeLogindefs, None, [("passwordAlgorithm", "i")]), # for now we do not rewrite uidMin
aec187
+        SaveGroup(self.writePWQuality, None,  [("passMinLen", "c"), ("passMinClass", "c"),
aec187
                 ("passMaxRepeat", "c"), ("passMaxClassRepeat", "c"), ("passReqLower", "b"),
aec187
                 ("passReqUpper", "b"), ("passReqDigit", "b"), ("passReqOther", "b")]),
aec187
-	SaveGroup(self.writeKerberos, [("kerberosRealm", "c"), ("kerberosKDC", "i"),
aec187
+	SaveGroup(self.writeKerberos, None, [("kerberosRealm", "c"), ("kerberosKDC", "i"),
aec187
 		("smbSecurity", "i"), ("smbRealm", "c"), ("smbServers", "i"),
aec187
 		("kerberosAdminServer", "i"), ("kerberosRealmviaDNS", "b"),
aec187
 		("kerberosKDCviaDNS", "b")]),
aec187
-	SaveGroup(self.writeSSSD, [("ldapServer", "i"), ("ldapBaseDN", "c"), ("enableLDAPS", "b"),
aec187
+	SaveGroup(self.writeSSSD, self.toggleSSSDService, [("ldapServer", "i"), ("ldapBaseDN", "c"), ("enableLDAPS", "b"),
aec187
 		("ldapSchema", "c"), ("ldapCacertDir", "c"), ("enableCacheCreds", "b"),
aec187
 		("kerberosRealm", "c"), ("kerberosKDC", "i"), ("kerberosAdminServer", "i"),
aec187
 		("forceSSSDUpdate", "b"), ("enableLDAP", "b"), ("enableKerberos", "b"),
aec187
 		("enableLDAPAuth", "b"), ("enableIPAv2", "b")]),
aec187
-	SaveGroup(self.writeSmartcard, [("smartcardAction", "i"), ("smartcardModule", "c")]),
aec187
-	SaveGroup(self.writeDConf, [("smartcardAction", "i"), ("smartcardModule", "c"),
aec187
+	SaveGroup(self.writeSmartcard, None, [("smartcardAction", "i"), ("smartcardModule", "c")]),
aec187
+	SaveGroup(self.writeDConf, None, [("smartcardAction", "i"), ("smartcardModule", "c"),
aec187
 		("enableFprintd", "b"), ("enableSmartcard", "b"), ("forceSmartcard", "b")]),
aec187
-	SaveGroup(self.writeWinbind, [("smbWorkgroup", "i"), ("smbServers", "i"),
aec187
+	SaveGroup(self.writeWinbind, self.toggleWinbindService, [("smbWorkgroup", "i"), ("smbServers", "i"),
aec187
 		("smbRealm", "c"), ("smbSecurity", "i"), ("smbIdmapRange", "i"),
aec187
 		("winbindSeparator", "c"), ("winbindTemplateHomedir", "c"),
aec187
 		("winbindTemplatePrimaryGroup", "c"), ("winbindTemplateShell", "c"),
aec187
 		("winbindUseDefaultDomain", "b"), ("winbindOffline", "b"), ("winbindKrb5", "b")]),
aec187
-	SaveGroup(self.writeNSS, [("enableDB", "b"), ("enableDirectories", "b"), ("enableWinbind", "b"),
aec187
+	SaveGroup(self.writeNSS, None, [("enableDB", "b"), ("enableDirectories", "b"), ("enableWinbind", "b"),
aec187
 		("enableOdbcbind", "b"), ("enableNIS3", "b"), ("enableNIS", "b"),
aec187
 		("enableLDAPbind", "b"), ("enableLDAP", "b"), ("enableHesiodbind", "b"),
aec187
 		("enableHesiod", "b"), ("enableDBIbind", "b"), ("enableDBbind", "b"),
aec187
 		("enableCompat", "b"), ("enableWINS", "b"), ("enableMDNS", "b"),
aec187
 		("enableNIS3", "b"), ("enableNIS", "b"), ("enableIPAv2", "b"),
aec187
 		("enableSSSD", "b"), ("preferDNSinHosts", "b"), ("implicitSSSD", "b")]),
aec187
-	SaveGroup(self.writePAM, [("pwqualityArgs", "c"), ("passwdqcArgs", "c"),
aec187
+	SaveGroup(self.writePAM, None, [("pwqualityArgs", "c"), ("passwdqcArgs", "c"),
aec187
 		("localuserArgs", "c"), ("pamAccessArgs", "c"), ("enablePAMAccess", "b"),
aec187
 		("mkhomedirArgs", "c"), ("enableMkHomeDir", "b"), ("algoRounds", "c"),
aec187
 		("passwordAlgorithm", "i"), ("enableShadow", "b"), ("enableNIS", "b"),
aec187
@@ -1484,7 +1416,7 @@ class AuthInfo:
aec187
 		("winbindOffline", "b"), ("winbindKrb5", "b"),
aec187
 		("enableSSSDAuth", "b"), ("enableFprintd", "b"), ("pamLinked", "b"),
aec187
 		("implicitSSSDAuth", "b"), ("systemdArgs", "c"), ("uidMin", "i"), ("enableIPAv2", "b")]),
aec187
-	SaveGroup(self.writeSysconfig, [("passwordAlgorithm", "i"), ("enableShadow", "b"), ("enableNIS", "b"),
aec187
+	SaveGroup(self.writeSysconfig, None, [("passwordAlgorithm", "i"), ("enableShadow", "b"), ("enableNIS", "b"),
aec187
 		("enableLDAP", "b"), ("enableLDAPAuth", "b"), ("enableKerberos", "b"),
aec187
 		("enableEcryptfs", "b"), ("enableSmartcard", "b"), ("forceSmartcard", "b"),
aec187
 		("enableWinbindAuth", "b"), ("enableWinbind", "b"), ("winbindKrb5", "b"), ("enableDB", "b"),
aec187
@@ -1494,8 +1426,15 @@ class AuthInfo:
aec187
 		("enableSSSD", "b"), ("enableSSSDAuth", "b"), ("enableForceLegacy", "b"),
aec187
 		("ipav2Server", "i"), ("ipav2Domain", "i"), ("ipav2Realm", "c"),
aec187
 		("enableIPAv2", "b"), ("ipaDomainJoined", "b"), ("ipav2NoNTP", "b")]),
aec187
-	SaveGroup(self.writeNetwork, [("nisDomain", "c")]),
aec187
-	SaveGroup(self.toggleShadow, [("enableShadow", "b")])]
aec187
+	SaveGroup(self.writeNetwork, None, [("nisDomain", "c")]),
aec187
+	SaveGroup(self.toggleShadow, None, [("enableShadow", "b")]),
aec187
+	SaveGroup(None, self.toggleNisService, [("enableNIS", "b")]),
aec187
+	SaveGroup(None, self.toggleOddjobService, [("enableMkHomeDir", "b")]),
aec187
+	SaveGroup(None, self.toggleLDAPService, [("enableLDAP", "b"), ("enableLDAPAuth", "b"),
aec187
+		("implicitSSSD", "b"), ("implicitSSSDAuth", "b"), ("enableForceLegacy", "b")]),
aec187
+	SaveGroup(None, self.toggleSSSDService, [("implicitSSSD", "b"), ("implicitSSSDAuth", "b"),
aec187
+		("enableIPAv2", "b"), ("enableSSSD", "b"), ("enableSSSDAuth", "b"), ("enableForceLegacy", "b")]),
aec187
+	SaveGroup(None, self.toggleWinbindService, [("enableWinbind", "b"), ("enableWinbindAuth", "b")])]
aec187
 
aec187
 	def setParam(self, attr, value, ref):
aec187
 		oldval = getattr(self, attr)
aec187
@@ -4049,7 +3988,6 @@ class AuthInfo:
aec187
 		self.update()
aec187
 		self.prewriteUpdate()
aec187
 		self.setupBackup(PATH_CONFIG_BACKUPS + "/last")
aec187
-		self.confChanged = True
aec187
 		try:
aec187
 			ret = self.writeLibuser()
aec187
 			ret = ret and self.writeLogindefs()
aec187
@@ -4080,6 +4018,9 @@ class AuthInfo:
aec187
 		except (OSError, IOError):
aec187
 			sys.stderr.write(str(sys.exc_info()[1]) + "\n")
aec187
 			return False
aec187
+		for group in self.save_groups:
aec187
+			if group.toggleFunction:
aec187
+				self.toggleFunctions.add(group.toggleFunction)
aec187
 		return ret
aec187
 
aec187
 	def writeChanged(self, ref):
aec187
@@ -4091,8 +4032,10 @@ class AuthInfo:
aec187
 		try:
aec187
 			for group in self.save_groups:
aec187
 				if group.attrsDiffer(self, ref):
aec187
-					self.confChanged = True
aec187
-					ret = ret and group.saveFunction()
aec187
+					if group.saveFunction:
aec187
+						ret = ret and group.saveFunction()
aec187
+					if group.toggleFunction:
aec187
+						self.toggleFunctions.add(group.toggleFunction)
aec187
 		except (OSError, IOError):
aec187
 			sys.stderr.write(str(sys.exc_info()[1]) + "\n")
aec187
 			return False
aec187
@@ -4326,44 +4269,93 @@ class AuthInfo:
aec187
 		cmd = PATH_IPA_CLIENT_INSTALL + " --uninstall --noac"
aec187
 		os.system(cmd)
aec187
 
aec187
-	def post(self, nostart):
aec187
-		onlystart = not self.confChanged
aec187
-		toggleNisService(self.enableNIS, self.nisDomain, nostart, onlystart)
aec187
-		toggleLDAPService(self.enableLDAP or self.enableLDAPAuth)
aec187
+	def toggleCachingService(self, nostart):
aec187
+		if not nostart:
aec187
+			if self.enableCache:
aec187
+				Service.stop("nscd")
aec187
+				Service.start("nscd")
aec187
+			else:
aec187
+				try:
aec187
+					Service.stop("nscd")
aec187
+				except OSError:
aec187
+					pass
aec187
+		return True
aec187
+	def toggleNisService(self, nostart):
aec187
+		if self.enableNIS and self.nisDomain:
aec187
+			if not nostart:
aec187
+				os.system("/bin/domainname " + self.nisDomain)
aec187
+			try:
aec187
+				os.system("[[ $(getsebool allow_ypbind) == *off* ]] && setsebool -P allow_ypbind 1")
aec187
+				os.stat(PATH_RPCBIND)
aec187
+				Service.enable("rpcbind")
aec187
+				if not nostart:
aec187
+					Service.start("rpcbind")
aec187
+			except OSError:
aec187
+				pass
aec187
+			try:
aec187
+				os.stat(PATH_YPBIND)
aec187
+				Service.enable("ypbind")
aec187
+				if not nostart:
aec187
+					Service.stop("ypbind")
aec187
+					Service.start("ypbind")
aec187
+			except OSError:
aec187
+				pass
aec187
+		else:
aec187
+			if not nostart:
aec187
+				os.system("/bin/domainname \"(none)\"")
aec187
+			try:
aec187
+				os.system("[[ $(getsebool allow_ypbind) == *on* ]] && setsebool -P allow_ypbind 0")
aec187
+				os.stat(PATH_YPBIND)
aec187
+				if not nostart:
aec187
+					try:
aec187
+						Service.stop("ypbind")
aec187
+					except OSError:
aec187
+						pass
aec187
+				Service.disable("ypbind")
aec187
+			except OSError:
aec187
+				pass
aec187
+		return True
aec187
+
aec187
+	def toggleLDAPService(self, nostart):
aec187
+		toggleSplatbindService((self.enableLDAP or self.enableLDAPAuth) and
aec187
+			not self.implicitSSSD,
aec187
+			PATH_NSLCD,
aec187
+			"nslcd", nostart)
aec187
+		if self.enableLDAP:
aec187
+			try:
aec187
+				os.system("[[ $(getsebool authlogin_nsswitch_use_ldap) == *off* ]] && setsebool -P authlogin_nsswitch_use_ldap 1")
aec187
+			except OSError:
aec187
+				pass
aec187
+		else:
aec187
+			try:
aec187
+				os.system("[[ $(getsebool authlogin_nsswitch_use_ldap) == *on* ]] && setsebool -P authlogin_nsswitch_use_ldap 0")
aec187
+			except OSError:
aec187
+				pass
aec187
+		return True
aec187
+
aec187
+	def toggleWinbindService(self, nostart):
aec187
 		toggleSplatbindService(self.enableWinbind or self.enableWinbindAuth,
aec187
 			PATH_WINBIND,
aec187
-			"winbind", nostart, onlystart)
aec187
+			"winbind", nostart)
aec187
+
aec187
+	def toggleSSSDService(self, nostart):
aec187
 		toggleSplatbindService(self.implicitSSSD or self.implicitSSSDAuth or
aec187
 			self.enableIPAv2 or self.enableSSSD or self.enableSSSDAuth,
aec187
 			PATH_SSSD,
aec187
 			"sssd", nostart or not (self.implicitSSSD or self.implicitSSSDAuth
aec187
-			or self.enableIPAv2), onlystart)
aec187
-		toggleSplatbindService((self.enableLDAP or self.enableLDAPAuth) and
aec187
-			not self.implicitSSSD,
aec187
-			PATH_NSLCD,
aec187
-			"nslcd", nostart, onlystart)
aec187
-		toggleSplatbindService(self.enableDBbind,
aec187
-			PATH_DBBIND,
aec187
-			"dbbind", nostart, onlystart)
aec187
-		toggleSplatbindService(self.enableDBIbind,
aec187
-			PATH_DBIBIND,
aec187
-			"dbibind", nostart, onlystart)
aec187
-		toggleSplatbindService(self.enableHesiodbind,
aec187
-			PATH_HESIODBIND,
aec187
-			"hesiodbind", nostart, onlystart)
aec187
-		toggleSplatbindService(self.enableLDAPbind,
aec187
-			PATH_LDAPBIND,
aec187
-			"ldapbind", nostart, onlystart)
aec187
-		toggleSplatbindService(self.enableOdbcbind,
aec187
-			PATH_ODBCBIND,
aec187
-			"odbcbind", nostart, onlystart)
aec187
+			or self.enableIPAv2))
aec187
+
aec187
+	def toggleOddjobService(self, nostart):
aec187
 		if self.enableMkHomeDir and os.access("%s/pam_%s.so"
aec187
 				% (AUTH_MODULE_DIR, "oddjob_mkhomedir"), os.X_OK):
aec187
 			# only switch on and only if pam_oddjob_mkhomedir exists
aec187
 			toggleSplatbindService(True,
aec187
 				PATH_ODDJOBD,
aec187
-				"oddjobd", nostart, onlystart)
aec187
-		toggleCachingService(self.enableCache, nostart, onlystart)
aec187
+				"oddjobd", nostart)
aec187
+
aec187
+	def post(self, nostart):
aec187
+		for togglefunc in self.toggleFunctions:
aec187
+			togglefunc(nostart)
aec187
 		if self.ipaUninstall:
aec187
 			self.uninstallIPA()
aec187