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

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