Blame SOURCES/0003-library-_adcli_krb5_build_principal-allow-principals.patch

341f9a
From 10a4dbb5978b6f05cf75f820d97da908e735ace8 Mon Sep 17 00:00:00 2001
341f9a
From: Sumit Bose <sbose@redhat.com>
341f9a
Date: Fri, 22 Mar 2019 10:37:11 +0100
341f9a
Subject: [PATCH 3/4] library: _adcli_krb5_build_principal allow principals as
341f9a
 names
341f9a
341f9a
Make _adcli_krb5_build_principal a bit more robust by checking if the
341f9a
given name already contains a realm suffix.
341f9a
341f9a
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1630187
341f9a
---
341f9a
 library/adkrb5.c | 12 ++++++++----
341f9a
 1 file changed, 8 insertions(+), 4 deletions(-)
341f9a
341f9a
diff --git a/library/adkrb5.c b/library/adkrb5.c
341f9a
index 7f77373..da835d7 100644
341f9a
--- a/library/adkrb5.c
341f9a
+++ b/library/adkrb5.c
341f9a
@@ -41,12 +41,16 @@ _adcli_krb5_build_principal (krb5_context k5,
341f9a
                              krb5_principal *principal)
341f9a
 {
341f9a
 	krb5_error_code code;
341f9a
-	char *name;
341f9a
+	char *name = NULL;
341f9a
 
341f9a
-	if (asprintf (&name, "%s@%s", user, realm) < 0)
341f9a
-		return_val_if_reached (ENOMEM);
341f9a
+	/* Use user if user contains a @-character and add @realm otherwise */
341f9a
+	if (strchr (user, '@') == NULL) {
341f9a
+		if (asprintf (&name, "%s@%s", user, realm) < 0) {
341f9a
+			return_val_if_reached (ENOMEM);
341f9a
+		}
341f9a
+	}
341f9a
 
341f9a
-	code = krb5_parse_name (k5, name, principal);
341f9a
+	code = krb5_parse_name (k5, name != NULL ? name : user, principal);
341f9a
 	return_val_if_fail (code == 0, code);
341f9a
 
341f9a
 	free (name);
341f9a
-- 
341f9a
2.20.1
341f9a