---
name: "krb5_get_default_realms"
section: "3"
platform: "linux"
package: "heimdal-dev"
version: "7.8.git20221117.28daf24+dfsg-9+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/krb5_get_default_realms"
---

# krb5\_get\_default\_realms(3)

default and host realm read and manipulation routines

## NAME

**krb5\_copy\_host\_realm**, **krb5\_free\_host\_realm**, **krb5\_get\_default\_realm**, **krb5\_get\_default\_realms**, **krb5\_get\_host\_realm**, **krb5\_set\_default\_realm** – default and host realm read and manipulation routines

## LIBRARY

Kerberos 5 Library (libkrb5, -lkrb5)

## SYNOPSIS

**#include \<krb5.h\>**

*krb5\_error\_code*\

**krb5\_copy\_host\_realm**(*krb5\_context context*, *const krb5\_realm \*from*, *krb5\_realm \*\*to*);

*krb5\_error\_code*\

**krb5\_free\_host\_realm**(*krb5\_context context*, *krb5\_realm \*realmlist*);

*krb5\_error\_code*\

**krb5\_get\_default\_realm**(*krb5\_context context*, *krb5\_realm \*realm*);

*krb5\_error\_code*\

**krb5\_get\_default\_realms**(*krb5\_context context*, *krb5\_realm \*\*realm*);

*krb5\_error\_code*\

**krb5\_get\_host\_realm**(*krb5\_context context*, *const char \*host*, *krb5\_realm \*\*realms*);

*krb5\_error\_code*\

**krb5\_set\_default\_realm**(*krb5\_context context*, *const char \*realm*);

## DESCRIPTION

**krb5\_copy\_host\_realm**() copies the list of realms from *from* to *to*. *to* should be freed by the caller using *krb5\_free\_host\_realm*.

**krb5\_free\_host\_realm**() frees all memory allocated by *realmlist*.

**krb5\_get\_default\_realm**() returns the first default realm for this host. The realm returned should be freed with **krb5\_xfree**().

**krb5\_get\_default\_realms**() returns a NULL terminated list of default realms for this context. Realms returned by **krb5\_get\_default\_realms**() should be freed with **krb5\_free\_host\_realm**().

**krb5\_get\_host\_realm**() returns a NULL terminated list of realms for *host* by looking up the information in the \[domain\_realm\] in *krb5.conf* or in DNS. If the mapping in \[domain\_realm\] results in the string dns\_locate, DNS is used to lookup the realm.

When using DNS to a resolve the domain for the host a.b.c, **krb5\_get\_host\_realm**() looks for a TXT resource record named \_kerberos.a.b.c, and if not found, it strips off the first component and tries a again (\_kerberos.b.c) until it reaches the root.

If there is no configuration or DNS information found, **krb5\_get\_host\_realm**() assumes it can use the domain part of the *host* to form a realm. Caller must free *realmlist* with **krb5\_free\_host\_realm**().

**krb5\_set\_default\_realm**() sets the default realm for the *context*. If NULL is used as a *realm*, the \[libdefaults\]default\_realm stanza in *krb5.conf* is used. If there is no such stanza in the configuration file, the **krb5\_get\_host\_realm**() function is used to form a default realm.

## SEE ALSO

[free(3)](/free/3.md), [krb5.conf(5)](/krb5.conf/5.md)
