Blame SOURCES/authconfig-6.2.8-norestart.patch

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