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

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