void KRB5_CALLCONV
krb5_free_default_realm(krb5_context context, char *lrealm);
+/**
+ * Canonicalize a hostname, possibly using name service.
+ *
+ * @param [in] context Library context
+ * @param [in] host Input hostname
+ * @param [out] canonhost_out Canonicalized hostname
+ *
+ * This function canonicalizes orig_hostname, possibly using name service
+ * lookups if configuration permits. Use krb5_free_string() to free @a
+ * canonhost_out when it is no longer needed.
+ *
+ * @version New in 1.15
+ */
+krb5_error_code KRB5_CALLCONV
+krb5_expand_hostname(krb5_context context, const char *host,
+ char **canonhost_out);
+
/**
* Generate a full principal name from a service name.
*
return value;
}
-/* Set *name_out to the canonicalized form of name, obeying relevant
- * configuration settings. The caller must free the result. */
-static krb5_error_code
-canon_hostname(krb5_context context, krb5_int32 type, const char *host,
- char **canonhost_out)
+krb5_error_code KRB5_CALLCONV
+krb5_expand_hostname(krb5_context context, const char *host,
+ char **canonhost_out)
{
struct addrinfo *ai = NULL, hint;
char namebuf[NI_MAXHOST], *copy, *p;
*canonhost_out = NULL;
canonhost = host;
- if (type == KRB5_NT_SRV_HST && context->dns_canonicalize_hostname) {
+ if (context->dns_canonicalize_hostname) {
/* Try a forward lookup of the hostname. */
memset(&hint, 0, sizeof(hint));
hint.ai_flags = AI_CANONNAME;
if (copy == NULL)
goto cleanup;
- if (type == KRB5_NT_SRV_HST) {
- /* Convert the hostname to lower case. */
- for (p = copy; *p != '\0'; p++) {
- if (isupper((unsigned char)*p))
- *p = tolower((unsigned char)*p);
- }
+ /* Convert the hostname to lower case. */
+ for (p = copy; *p != '\0'; p++) {
+ if (isupper((unsigned char)*p))
+ *p = tolower((unsigned char)*p);
}
/* Remove any trailing dot. */
}
/* Canonicalize the hostname if appropriate. */
- ret = canon_hostname(context, type, hostname, &canonhost);
- if (ret)
- goto cleanup;
- hostname = canonhost;
+ if (type == KRB5_NT_SRV_HST) {
+ ret = krb5_expand_hostname(context, hostname, &canonhost);
+ if (ret)
+ goto cleanup;
+ hostname = canonhost;
+ }
/* Find the realm of the host. */
ret = krb5_get_host_realm(context, hostname, &hrealms);
testu('Example.COM', 'Example.COM', 'R2')
testu('abcde', 'abcde', '')
-# A ':port' or ':instance' trailer should be ignored for hostname
-# adjustment and realm lookup. If there is more than one colon in the
-# name, we assume it's an IPv6 address and don't treat it as having a
-# trailer.
-testu('example.com.:123', 'example.com:123', 'R2')
+# A ':port' or ':instance' trailer should be ignored for realm lookup.
+# If there is more than one colon in the name, we assume it's an IPv6
+# address and don't treat it as having a trailer.
+testu('example.com.:123', 'example.com.:123', 'R2')
testu('Example.COM:xyZ', 'Example.COM:xyZ', 'R2')
testu('example.com.::123', 'example.com.::123', '')