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

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