1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/os/hostream_profile.c - profile hostrealm module */
4 * Copyright (C) 1990,1991,2002,2008,2009,2013 by the Massachusetts Institute
5 * of Technology. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
34 * This file implements the built-in profile module for the hostrealm
35 * interface, which uses profile configuration to determine the local default
36 * realm or the authoritative realm of a host.
41 #include <krb5/hostrealm_plugin.h>
44 * Search progressively shorter suffixes of host in the [domain_realms] section
45 * of the profile to find the realm. For example, given a host a.b.c, try to
46 * match a.b.c, then .b.c, then b.c, then .c, then c. If we don't find a
47 * match, return success but set *realm_out to NULL.
49 static krb5_error_code
50 profile_host_realm(krb5_context context, krb5_hostrealm_moddata data,
51 const char *host, char ***realms_out)
59 /* Don't look up IP addresses in [domain_realms]. */
60 if (k5_is_numeric_address(host))
61 return KRB5_PLUGIN_NO_HANDLE;
63 /* Look for the host and each suffix in the [domain_realms] section. */
64 for (p = host; p != NULL; p = (*p == '.') ? p + 1 : strchr(p, '.')) {
65 ret = profile_get_string(context->profile, KRB5_CONF_DOMAIN_REALM, p,
66 NULL, NULL, &prof_realm);
69 if (prof_realm != NULL) {
70 ret = k5_make_realmlist(prof_realm, realms_out);
71 profile_release_string(prof_realm);
75 return KRB5_PLUGIN_NO_HANDLE;
78 /* Look up the default_realm variable in the [libdefaults] section of the
80 static krb5_error_code
81 profile_default_realm(krb5_context context, krb5_hostrealm_moddata data,
88 ret = profile_get_string(context->profile, KRB5_CONF_LIBDEFAULTS,
89 KRB5_CONF_DEFAULT_REALM, NULL, NULL, &prof_realm);
92 if (prof_realm == NULL)
93 return KRB5_PLUGIN_NO_HANDLE;
94 ret = k5_make_realmlist(prof_realm, realms_out);
95 profile_release_string(prof_realm);
100 profile_free_realmlist(krb5_context context, krb5_hostrealm_moddata data,
103 krb5_free_host_realm(context, list);
107 hostrealm_profile_initvt(krb5_context context, int maj_ver, int min_ver,
108 krb5_plugin_vtable vtable)
110 krb5_hostrealm_vtable vt = (krb5_hostrealm_vtable)vtable;
112 vt->name = "profile";
113 vt->host_realm = profile_host_realm;
114 vt->default_realm = profile_default_realm;
115 vt->free_list = profile_free_realmlist;