Blame SOURCES/nfs-utils-1.3.0-rpcgssd-maccout-nocase.patch

0c6d0c
diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
0c6d0c
index 5fde091..990111d 100644
0c6d0c
--- a/utils/gssd/krb5_util.c
0c6d0c
+++ b/utils/gssd/krb5_util.c
0c6d0c
@@ -801,8 +801,10 @@ find_keytab_entry(krb5_context context, krb5_keytab kt, const char *tgtname,
0c6d0c
 	char *default_realm = NULL;
0c6d0c
 	char *realm;
0c6d0c
 	char *k5err = NULL;
0c6d0c
-	int tried_all = 0, tried_default = 0;
0c6d0c
+	int tried_all = 0, tried_default = 0, tried_upper = 0;
0c6d0c
 	krb5_principal princ;
0c6d0c
+	const char *notsetstr = "not set";
0c6d0c
+	char *adhostoverride;
0c6d0c
 
0c6d0c
 
0c6d0c
 	/* Get full target hostname */
0c6d0c
@@ -820,13 +822,23 @@ find_keytab_entry(krb5_context context, krb5_keytab kt, const char *tgtname,
0c6d0c
 	}
0c6d0c
 
0c6d0c
 	/* Compute the active directory machine name HOST$ */
0c6d0c
-	strcpy(myhostad, myhostname);
0c6d0c
-	for (i = 0; myhostad[i] != 0; ++i) {
0c6d0c
-		if (myhostad[i] == '.') break;
0c6d0c
-		myhostad[i] = toupper(myhostad[i]);
0c6d0c
+	krb5_appdefault_string(context, "nfs", NULL, "ad_principal_name", 
0c6d0c
+		notsetstr, &adhostoverride);
0c6d0c
+	if (strcmp(adhostoverride, notsetstr) != 0) {
0c6d0c
+	        printerr (1, 
0c6d0c
+				"AD host string overridden with \"%s\" from appdefaults\n", 
0c6d0c
+				adhostoverride);
0c6d0c
+	        /* No overflow: Windows cannot handle strings longer than 19 chars */
0c6d0c
+	        strcpy(myhostad, adhostoverride);
0c6d0c
+		free(adhostoverride);
0c6d0c
+	} else {
0c6d0c
+	        strcpy(myhostad, myhostname);
0c6d0c
+	        for (i = 0; myhostad[i] != 0; ++i) {
0c6d0c
+	          if (myhostad[i] == '.') break;
0c6d0c
+	        }
0c6d0c
+	        myhostad[i] = '$';
0c6d0c
+	        myhostad[i+1] = 0;
0c6d0c
 	}
0c6d0c
-	myhostad[i] = '$';
0c6d0c
-	myhostad[i+1] = 0;
0c6d0c
 
0c6d0c
 	retval = get_full_hostname(myhostname, myhostname, sizeof(myhostname));
0c6d0c
 	if (retval) {
0c6d0c
@@ -923,6 +935,19 @@ find_keytab_entry(krb5_context context, krb5_keytab kt, const char *tgtname,
0c6d0c
 				k5err = gssd_k5_err_msg(context, code);
0c6d0c
 				printerr(3, "%s while getting keytab entry for '%s'\n",
0c6d0c
 					 k5err, spn);
0c6d0c
+				/*
0c6d0c
+				 * We tried the active directory machine account
0c6d0c
+				 * with the hostname part as-is and failed...
0c6d0c
+				 * convert it to uppercase and try again before
0c6d0c
+				 * moving on to the svcname
0c6d0c
+				 */
0c6d0c
+				if (strcmp(svcnames[j],"$") == 0 && !tried_upper) {
0c6d0c
+					for (i = 0; myhostad[i] != '$'; ++i) {
0c6d0c
+						myhostad[i] = toupper(myhostad[i]);
0c6d0c
+					}
0c6d0c
+					j--;
0c6d0c
+					tried_upper = 1;
0c6d0c
+				}
0c6d0c
 			} else {
0c6d0c
 				printerr(3, "Success getting keytab entry for '%s'\n",spn);
0c6d0c
 				retval = 0;