Blame SOURCES/authconfig-6.2.8-sssd-smartcard-1.patch

977b74
diff -Naur old/authinfo.py new/authinfo.py
977b74
--- old/authinfo.py	2017-03-28 13:38:56.610467419 +0200
977b74
+++ new/authinfo.py	2017-03-28 13:55:43.626505569 +0200
977b74
@@ -334,6 +334,10 @@
977b74
 	"wait_for_card"
977b74
 ]
977b74
 
977b74
+argv_sssd_missing_name = [
977b74
+   "allow_missing_name"
977b74
+]
977b74
+
977b74
 argv_krb5_auth = [
977b74
 	"use_first_pass"
977b74
 ]
977b74
@@ -736,6 +740,8 @@
977b74
 pam_modules[SMARTCARD] = [
977b74
 	[True,  AUTH,		LOGIC_REQUIRED,
977b74
 	 "env",			[]],
977b74
+	[False,  AUTH,		LOGIC_SUFFICIENT,
977b74
+	 "sss",			argv_sssd_missing_name],
977b74
 	[False,  AUTH,		LOGIC_PKCS11,
977b74
 	 "pkcs11",		argv_force_pkcs11_auth],
977b74
 	[False, AUTH,		LOGIC_OPTIONAL,
977b74
@@ -1428,7 +1434,7 @@
977b74
 		("kerberosAdminServer", "i"), ("kerberosRealmviaDNS", "b"),
977b74
 		("kerberosKDCviaDNS", "b")]),
977b74
 	SaveGroup(self.writeSSSD, self.toggleSSSDService, [("ldapServer", "i"), ("ldapBaseDN", "c"), ("enableLDAPS", "b"),
977b74
-		("ldapSchema", "c"), ("ldapCacertDir", "c"), ("enableCacheCreds", "b"),
977b74
+		("ldapSchema", "c"), ("ldapCacertDir", "c"), ("enableCacheCreds", "b"), ("enableSmartcard", "b"),
977b74
 		("kerberosRealm", "c"), ("kerberosKDC", "i"), ("kerberosAdminServer", "i"),
977b74
 		("forceSSSDUpdate", "b"), ("enableLDAP", "b"), ("enableKerberos", "b"),
977b74
 		("enableLDAPAuth", "b"), ("enableIPAv2", "b")]),
977b74
@@ -3281,11 +3287,35 @@
977b74
 				domain.remove_provider(subtype)
977b74
 			domain.add_provider(newprovider, subtype)
977b74
 
977b74
+	def writeSSSDPAM(self):
977b74
+		if not self.sssdConfig:
977b74
+			return True
977b74
+
977b74
+		pam = self.sssdConfig.get_service('pam')
977b74
+
977b74
+		if self.enableSmartcard and self.enableSSSDAuth and self.smartcardModule == "sssd" :
977b74
+			pam.set_option('pam_cert_auth', 'True')
977b74
+		else:
977b74
+			try:
977b74
+				pam.remove_option('pam_cert_auth')
977b74
+			except SSSDConfig.NoOptionError:
977b74
+				pass
977b74
+
977b74
+		self.sssdConfig.save_service(pam)
977b74
+		try:
977b74
+			self.sssdConfig.write(all_configs[CFG_SSSD].origPath)
977b74
+		except IOError:
977b74
+			pass
977b74
+
977b74
+		return True
977b74
+
977b74
 	def writeSSSD(self):
977b74
 		if not self.sssdConfig:
977b74
 			return True
977b74
 
977b74
 		all_configs[CFG_SSSD].backup(self.backupDir)
977b74
+		
977b74
+		self.writeSSSDPAM()
977b74
 
977b74
 		if self.enableIPAv2:
977b74
 			# just save the backup
977b74
@@ -3855,7 +3885,7 @@
977b74
 				args = self.mkhomedirArgs
977b74
 			if name == "systemd":
977b74
 				args = self.systemdArgs
977b74
-			if name == "sss" and stack == "auth" and not self.enableNIS:
977b74
+			if name == "sss" and stack == "auth" and not self.enableNIS and not module[ARGV] == argv_sssd_missing_name:
977b74
 				args = "forward_pass"
977b74
 			if not args and module[ARGV]:
977b74
 				args = " ".join(module[ARGV])
977b74
@@ -3935,6 +3965,10 @@
977b74
 				enableSmartcard = True
977b74
 				forceSmartcard = True
977b74
 
977b74
+			# configure SSSD Smartcard support instead of
977b74
+			# pam_pkcs11 if SSSD is used for authentication and no
977b74
+			# Smartcard module is set, e.g. if pam_pkcs11 is not installed.
977b74
+			use_sssd_smartcard_support = self.enableSSSDAuth and self.smartcardModule == "sssd"
977b74
 			prevmodule = []
977b74
 			for module in pam_modules[service]:
977b74
 				if prevmodule and module[STACK] != prevmodule[STACK]:
977b74
@@ -3952,15 +3986,17 @@
977b74
 					    ((module[NAME] == "krb5" and module[ARGV] == argv_krb5_sc_auth) or
977b74
 					    (module[NAME] == "permit" and module[STACK] == AUTH))) or
977b74
 					((self.enableLDAPAuth and not self.implicitSSSDAuth) and module[NAME] == "ldap") or
977b74
-					(enableSmartcard and module[STACK] == AUTH and
977b74
+					(enableSmartcard and use_sssd_smartcard_support and module[NAME] == "sss" and module[ARGV] == argv_sssd_missing_name) or
977b74
+					(enableSmartcard and not use_sssd_smartcard_support and module[STACK] == AUTH and
977b74
 						module[NAME] == "succeed_if" and module[LOGIC] == LOGIC_SKIPNEXT) or
977b74
-					(enableSmartcard and module[NAME] == "pkcs11") or 
977b74
+					(enableSmartcard and not use_sssd_smartcard_support and module[NAME] == "pkcs11") or
977b74
+					(enableSmartcard and not use_sssd_smartcard_support and forceSmartcard and module[NAME] == "deny") or
977b74
 					(enableSmartcard and forceSmartcard and module[NAME] == "deny") or 
977b74
 					(enableFprintd and module[NAME] == "fprintd") or
977b74
 					(self.enableOTP and module[NAME] == "otp") or
977b74
 					(self.enablePasswdQC and module[NAME] == "passwdqc") or
977b74
 					(self.enableWinbindAuth and module[NAME] == "winbind") or
977b74
-					((self.enableSSSDAuth or self.implicitSSSDAuth or self.enableIPAv2) and module[NAME] == "sss") or
977b74
+					((self.enableSSSDAuth or self.implicitSSSDAuth or self.enableIPAv2) and module[NAME] == "sss" and module[ARGV] != argv_sssd_missing_name) or
977b74
 					((self.enableSSSDAuth or self.implicitSSSDAuth or self.enableIPAv2) and
977b74
 						(not self.enableNIS) and module[NAME] == "localuser" and module[STACK] == AUTH) or
977b74
 					(self.enableLocAuthorize and module[NAME] == "localuser" and module[STACK] == ACCOUNT) or
977b74
@@ -4093,6 +4129,8 @@
977b74
 				ret = ret and self.writeWinbind()
977b74
 			if self.implicitSSSD or self.implicitSSSDAuth:
977b74
 				ret = ret and self.writeSSSD()
977b74
+			elif self.enableSSSDAuth:
977b74
+				ret = ret and self.writeSSSDPAM()
977b74
 			ret = ret and self.writeNSS()
977b74
 			ret = ret and self.writePAM()
977b74
 			ret = ret and self.writeSysconfig()
977b74
@@ -4250,7 +4288,8 @@
977b74
 		print " LDAP server = \"%s\"" % self.ldapServer
977b74
 		print " LDAP base DN = \"%s\"" % self.ldapBaseDN
977b74
 		print " LDAP schema = \"%s\"" % (self.ldapSchema or "rfc2307")
977b74
-		print "pam_pkcs11 is %s" % formatBool(self.enableSmartcard)
977b74
+		print "pam_pkcs11 is %s" % formatBool(self.enableSmartcard and not (self.enableSSSDAuth and self.smartcardModule == "sssd"))
977b74
+		print "SSSD smartcard support is %s" % formatBool(self.enableSmartcard and (self.enableSSSDAuth and self.smartcardModule == "sssd"))
977b74
 		print " use only smartcard for login is %s" % formatBool(self.forceSmartcard)
977b74
 		print " smartcard module = \"%s\"" % self.smartcardModule
977b74
 		print " smartcard removal action = \"%s\"" % self.smartcardAction