KRB5_VERIFY_USER(3)
π KRB5_VERIFY_USER π
okay so bestie, welcome to krb5_verify_user(3) β yeah it lives in the Library Functions Manual (section 3, we love a 3) and it's the whole Heimdal password verifying function family. buckle up, this is lowkey a lot of functions but they all slay together π
π LIBRARY
Kerberos 5 Library (libkrb5, -lkrb5) π«Ά
β¨ SYNOPSIS β¨
#include <krb5.h>
krb5_error_code
krb5_verify_user(krb5_context context, krb5_principal principal,
krb5_ccache ccache, const char *password, krb5_boolean secure,
const char *service);
krb5_error_code
krb5_verify_user_lrealm(krb5_context context, krb5_principal principal,
krb5_ccache ccache, const char *password, krb5_boolean secure,
const char *service);
void
krb5_verify_opt_init(krb5_verify_opt *opt);
void
krb5_verify_opt_alloc(krb5_verify_opt **opt);
void
krb5_verify_opt_free(krb5_verify_opt *opt);
void
krb5_verify_opt_set_ccache(krb5_verify_opt *opt, krb5_ccache ccache);
void
krb5_verify_opt_set_keytab(krb5_verify_opt *opt, krb5_keytab keytab);
void
krb5_verify_opt_set_secure(krb5_verify_opt *opt, krb5_boolean secure);
void
krb5_verify_opt_set_service(krb5_verify_opt *opt, const char *service);
void
krb5_verify_opt_set_flags(krb5_verify_opt *opt, unsigned int flags);
krb5_error_code
krb5_verify_user_opt(krb5_context context, krb5_principal principal,
const char *password, krb5_verify_opt *opt);
π DESCRIPTION π
krb5_verify_user does exactly what it says on the tin: it verifies the password a user gave you. the principal whose password is getting checked goes in principal. here's the tea though β new tickets get obtained as a side-effect and stored in ccache (and if that's NULL, the default ccache gets used instead π«Ά). also krb5_verify_user() will call krb5_cc_initialize() on the ccache you hand it, so heads up: that ccache must only be initialized with krb5_cc_resolve() or krb5_cc_gen_new(). if you don't pass a password in password (like, you gave it as NULL), the user gets prompted for it. and if secure is set, the ticket gets verified against the locally stored service key service β and if you pass that as NULL, it defaults to 'host' π (yes, just literally the string host).
krb5_verify_user_lrealm() is the same vibe, except it ignores the realm inside principal and tries all the local realms (peep krb5.conf(5)). after a successful return, principal gets set to the authenticated realm, slay. but if the call fails? then principal isn't meaningful anymore and you should only free it with krb5_free_principal(3). no reading it, no trusting it, just free it, periodt.
krb5_verify_opt_alloc() and krb5_verify_opt_free() allocate and free a krb5_verify_opt. bestie, you should use the alloc and free functions instead of allocating the structure yourself β because in a future release the structure won't be exported. so like, don't get attached to it π.
krb5_verify_opt_init() resets all of opt back to default values. fresh start energy β¨.
none of the krb5_verify_opt_set functions make a copy of the data structure they're called with π so it's up to the caller to free them after krb5_verify_user_opt() has been called. your memory, your problem, no cap.
π the setters, one by one π
krb5_verify_opt_set_ccache()β sets the ccache that the user ofoptwill use. if you don't set it, the default credential cache is used.krb5_verify_opt_set_keytab()β sets the keytab that the user ofoptwill use. if you don't set it, the default keytab is used.krb5_verify_opt_set_secure()β ifsecureis true, the password verification will require that the ticket gets verified against the locally stored service key. if you don't set it, the default value istrue.krb5_verify_opt_set_service()β sets the service principal that the user ofoptwill use. if you don't set it, the'host'service is used.krb5_verify_opt_set_flags()β sets the flags that the user ofoptwill use. if the flagKRB5_VERIFY_LREALMSis used, thenprincipalgets modified exactly the waykrb5_verify_user_lrealm()modifies it π
π and finally, the main event π
krb5_verify_user_opt() verifies the password supplied by a user. the principal whose password will be verified is specified in principal, and the options for the verification process get passed in through opt. that's it, that's the function, she's simple and she ate π
π¦ EXAMPLES π¦
here's an example program that verifies a password. it uses the 'host/hostname' service principal in krb5.keytab. so cute, so useful:
#include <krb5.h>
int
main(int argc, char **argv)
{
char *user;
krb5_error_code error;
krb5_principal princ;
krb5_context context;
if (argc != 2)
errx(1, "usage: verify_passwd <principal-name>");
user = argv[1];
if (krb5_init_context(&context) < 0)
errx(1, "krb5_init_context");
if ((error = krb5_parse_name(context, user, &princ)) != 0)
krb5_err(context, 1, error, "krb5_parse_name");
error = krb5_verify_user(context, princ, NULL, NULL, TRUE, NULL);
if (error)
krb5_err(context, 1, error, "krb5_verify_user");
return 0;
}
π₯ SEE ALSO π₯
krb5_cc_gen_new(3)krb5_cc_initialize(3)krb5_cc_resolve(3)krb5_err(3)krb5_free_principal(3)krb5_init_context(3)krb5_kt_default(3)krb5.conf(5)
and that's the whole page bestie, go verify some passwords, stay secure, and remember: free your principals π«Ά
this has been HEIMDAL, dated May 1, 2006 β yes it's giving vintage but she still eats πβ¨π
π¦ 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
- 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 - 2006 Kungliga Tekniska HΓΆgskolan
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms