---
name: "krb_realmofhost"
section: "3"
platform: "linux"
package: "kerberos4kth-dev"
version: "1.2.2-11.2"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/krb_realmofhost"
---

# krb\_realmofhost(3)

additional Kerberos utility routines

## NAME

krb\_realmofhost, krb\_get\_phost, krb\_get\_krbhst, krb\_get\_admhst, krb\_get\_lrealm - additional Kerberos utility routines

## SYNOPSIS

```
#include <krb.h>
#include <des.h>
#include <netinet/in.h>
```

**char \*krb\_realmofhost(host)** **char \*host;**

**char \*krb\_get\_phost(alias)** **char \*alias;**

**krb\_get\_krbhst(host,realm,n)** **char \*host;** **char \*realm;** **int n;**

**krb\_get\_admhst(host,realm,n)** **char \*host;** **char \*realm;** **int n;**

**krb\_get\_lrealm(realm,n)** **char \*realm;** **int n;**

## DESCRIPTION

*krb\_realmofhost* returns the Kerberos realm of the host *host*, as determined by the translation table */etc/krb.realms*. *host* should be the fully-qualified domain-style primary host name of the host in question.  In order to prevent certain security attacks, this routine must either have  *a priori* knowledge of a host's realm, or obtain such information securely.

The format of the translation file is described by  *krb.realms*(5). If *host* exactly matches a host\_name line, the corresponding realm is returned. Otherwise, if the domain portion of *host* matches a domain\_name line, the corresponding realm is returned. If *host* contains a domain, but no translation is found, *host*'s domain is converted to upper-case and returned. If  *host* contains no discernable domain, or an error occurs, the local realm name, as supplied by  *krb\_get\_lrealm*(3), is returned.

*krb\_get\_phost* converts the hostname *alias* (which can be either an official name or an alias) into the instance name to be used in obtaining Kerberos tickets for most services, including the Berkeley rcmd suite (rlogin, rcp, rsh).\
 The current convention is to return the first segment of the official domain-style name after conversion to lower case.

*krb\_get\_krbhst* fills in *host* with the hostname of the *n*th host running a Kerberos key distribution center (KDC) for realm *realm*, as specified in the configuration file (*/etc/krb.conf*). The configuration file is described by  [*krb.conf*(5)](/krb.conf/5.md). If the host is successfully filled in, the routine returns KSUCCESS. If the file cannot be opened, and *n* equals 1, then the value of KRB\_HOST as defined in *\<krb.h\>* is filled in, and KSUCCESS is returned.  If there are fewer than *n* hosts running a Kerberos KDC for the requested realm, or the configuration file is malformed, the routine returns KFAILURE.

*krb\_get\_admhst* fills in *host* with the hostname of the *n*th host running a Kerberos KDC database administration server for realm *realm*, as specified in the configuration file (*/etc/krb.conf*). If the file cannot be opened or is malformed, or there are fewer than *n* hosts running a Kerberos KDC database administration server, the routine returns KFAILURE.

The character arrays used as return values for *krb\_get\_krbhst*, *krb\_get\_admhst*, should be large enough to hold any hostname (MAXHOSTNAMELEN from \<sys/param.h\>).

*krb\_get\_lrealm* fills in *realm* with the *n*th realm of the local host, as specified in the configuration file. *realm* should be at least REALM\_SZ (from *\<krb.h\>)*characters*long.*

## SEE ALSO

[kerberos(3)](/kerberos/3.md), [krb.conf(5)](/krb.conf/5.md), krb.realms(5)

## FILES

- /etc/krb.realms

  translation file for host-to-realm mapping.

- /etc/krb.conf

  local realm-name and realm/server configuration file.

## BUGS

The current convention for instance names is too limited; the full domain name should be used.

*krb\_get\_lrealm* currently only supports  *n* = 1.  It should really consult the user's ticket cache to determine the user's current realm, rather than consulting a file on the host.
