KRB5_KRBHST_INIT(3)
π KRB5_KRBHST_INIT π
okay bestie, so this is a page from the Library Functions Manual (yeah, the KRB5_KRBHST_INIT(3) one) and it's literally all about looking up Kerberos KDC hosts. group chat rules apply, let's get into it π
β¨ NAME β¨
krb5_krbhst_init, krb5_krbhst_init_flags, krb5_krbhst_next, krb5_krbhst_next_as_string, krb5_krbhst_reset, krb5_krbhst_free, krb5_krbhst_format_string, krb5_krbhst_get_addrinfo β lookup Kerberos KDC hosts ππ
π LIBRARY π
Kerberos 5 Library (libkrb5, -lkrb5) β yeah you gotta link it, no cap.
πΈ SYNOPSIS πΈ
#include <krb5.h>
krb5_error_code
krb5_krbhst_init(krb5_context context, const char *realm,
unsigned int type, krb5_krbhst_handle *handle);
krb5_error_code
krb5_krbhst_init_flags(krb5_context context, const char *realm,
unsigned int type, int flags, krb5_krbhst_handle *handle);
krb5_error_code
krb5_krbhst_next(krb5_context context, krb5_krbhst_handle handle,
krb5_krbhst_info **host);
krb5_error_code
krb5_krbhst_next_as_string(krb5_context context,
krb5_krbhst_handle handle, char *hostname, size_t hostlen);
void
krb5_krbhst_reset(krb5_context context, krb5_krbhst_handle handle);
void
krb5_krbhst_free(krb5_context context, krb5_krbhst_handle handle);
krb5_error_code
krb5_krbhst_format_string(krb5_context context,
const krb5_krbhst_info *host, char *hostname, size_t hostlen);
krb5_error_code
krb5_krbhst_get_addrinfo(krb5_context context, krb5_krbhst_info *host,
struct addrinfo **ai);
π DESCRIPTION π
So these functions are your little tour guides through every single Kerberos host of one specific realm and one specific service. And the service type can be: the KDCs, the administrative servers, the password changing servers, or the servers that do Kerberos 4 ticket conversion. it's giving β¨optionsβ¨
First things first, you grab a handle to a particular service by calling krb5_krbhst_init() (or krb5_krbhst_init_flags()) and you pass it the realm you care about plus the type of service you're looking up. That type can be one of these:
KRB5_KRBHST_KDCKRB5_KRBHST_ADMINKRB5_KRBHST_CHANGEPWKRB5_KRBHST_KRB524
The handle gets handed back to you, and bestie, you're gonna pass it to all the other functions. it's the main character of this whole operation π«Ά
The flag argument to krb5_krbhst_init_flags is literally the same flags that krb5_send_to_kdc_flags() uses. Possible values are:
KRB5_KRBHST_FLAGS_MASTERβ only talk to master (readwrite) KDC πKRB5_KRBHST_FLAGS_LARGE_MSGβ this is a large message, so use transport that can handle that. big vibes need big pipes π¦
Every single time you call krb5_krbhst_next() you get info on a brand new host. That function returns in host a pointer to a struct holding all the deets about the host β protocol, hostname, port, the whole thing:
typedef struct krb5_krbhst_info {
enum { KRB5_KRBHST_UDP,
KRB5_KRBHST_TCP,
KRB5_KRBHST_HTTP } proto;
unsigned short port;
struct addrinfo *ai;
struct krb5_krbhst_info *next;
char hostname[1];
} krb5_krbhst_info;
And the related function, krb5_krbhst_next_as_string(), gives you that same info but as a URL-like string. cute, right? π
When there are no more hosts, these functions return KRB5_KDC_UNREACH. that's it, that's the end of the list, no more crumbs π
Wanna loop through everything again from the top? Call krb5_krbhst_reset() and the next call to krb5_krbhst_next() will hand you the first host again. rewind, bestie βͺ
When you're done with the handle, you should call krb5_krbhst_free(). don't leave it hanging, that's rude π
So you've got a krb5_krbhst_info and you wanna actually use it? There are two functions for that:
krb5_krbhst_format_string()β returns a printable representation of that struct π¨οΈkrb5_krbhst_get_addrinfo()β returns astruct addrinfothat you can then use to communicate with the server mentioned. say hi to the server for me π«‘
π EXAMPLES π
This code right here prints the KDCs of the realm βMY.REALMβ. slay:
krb5_krbhst_handle handle;
char host[MAXHOSTNAMELEN];
krb5_krbhst_init(context, "MY.REALM", KRB5_KRBHST_KDC, &handle);
while(krb5_krbhst_next_as_string(context, handle,
host, sizeof(host)) == 0)
printf("%s\n", host);
krb5_krbhst_free(context, handle);
π SEE ALSO π
getaddrinfo(3), krb5_get_krbhst(3), krb5_send_to_kdc_flags(3) β go read these too, iykyk πβ¨
π¦ HISTORY π¦
These functions first appeared in Heimdal 0.3g. iconic behavior, honestly.
okay that's the whole page bestie!! π this was the Heimdal manual, dated May 10, 2005 β so like, vintage but make it β¨timelessβ¨. go forth and find your KDCs, no cap, periodt π π
π¦ where this page comes from
- alpine 3.22: heimdal-doc 7.8.0-r4 Β· BSD-3-Clause
- alpine 3.23: heimdal-doc 7.8.0-r5 Β· BSD-3-Clause
- alpine 3.24: heimdal-doc 7.8.0-r5 Β· BSD-3-Clause
- debian bookworm: heimdal-dev 7.8.git20221117.28daf24+dfsg-2 Β· BSD-3-Clause
- debian trixie: heimdal-dev 7.8.git20221117.28daf24+dfsg-9+deb13u1 Β· BSD-3-Clause
- epel 10: heimdal-devel 7.8.0-26.el10_2 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- epel 9: heimdal-devel 7.8.0-5.el9 Β· BSD and MIT
- fedora 43: heimdal-devel 7.8.0-26.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 43: heimdal-devel 7.8.0-26.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-26.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-26.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-28.fc44 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-28.fc44 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- freebsd 14.5: base 14.5
- nixpkgs unstable: heimdal 7.8.0-unstable-2024-09-10
- ubuntu jammy: heimdal-dev 7.7.0+dfsg-3ubuntu1 Β· BSD-3-Clause
- ubuntu noble: heimdal-dev 7.8.git20221117.28daf24+dfsg-5ubuntu3 Β· BSD-3-Clause
- ubuntu questing: heimdal-dev 7.8.git20221117.28daf24+dfsg-9ubuntu1
- ubuntu resolute: heimdal-dev 7.8.git20221117.28daf24+dfsg-11ubuntu1 Β· BSD-3-Clause
- ubuntu stonking: heimdal-dev 7.8.git20240113.1b4565a+dfsg-2ubuntu1 Β· BSD-3-Clause
- Copyright (c) 2001-2005 Kungliga Tekniska HΓΆgskolan
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms