1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* plugins/kdb/ldap/libkdb_ldap/ldap_krbcontainer.c */
3 /*
4 * Copyright (c) 2004-2005, Novell, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * The copyright holder's name is not used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "ldap_main.h"
32 #include "kdb_ldap.h"
33 #include "ldap_err.h"
34
35 /*
36 * Read the kerberos container location from krb5.conf.
37 */
38
39 krb5_error_code
krb5_ldap_read_krbcontainer_dn(krb5_context context,char ** container_dn)40 krb5_ldap_read_krbcontainer_dn(krb5_context context, char **container_dn)
41 {
42 krb5_error_code st=0;
43 char *dn=NULL;
44 kdb5_dal_handle *dal_handle=NULL;
45 krb5_ldap_context *ldap_context=NULL;
46 krb5_ldap_server_handle *ldap_server_handle=NULL;
47
48 *container_dn = NULL;
49 SETUP_CONTEXT();
50
51 /* read kerberos container location from [dbmodules] section of krb5.conf file */
52 if (ldap_context->conf_section) {
53 if ((st=profile_get_string(context->profile, KDB_MODULE_SECTION, ldap_context->conf_section,
54 KRB5_CONF_LDAP_KERBEROS_CONTAINER_DN, NULL,
55 &dn)) != 0) {
56 k5_setmsg(context, st, _("Error reading kerberos container "
57 "location from krb5.conf"));
58 goto cleanup;
59 }
60 }
61
62 /* read kerberos container location from [dbdefaults] section of krb5.conf file */
63 if (dn == NULL) {
64 if ((st=profile_get_string(context->profile, KDB_MODULE_DEF_SECTION,
65 KRB5_CONF_LDAP_KERBEROS_CONTAINER_DN, NULL,
66 NULL, &dn)) != 0) {
67 k5_setmsg(context, st, _("Error reading kerberos container "
68 "location from krb5.conf"));
69 goto cleanup;
70 }
71 }
72
73 if (dn == NULL) {
74 st = KRB5_KDB_SERVER_INTERNAL_ERR;
75 k5_setmsg(context, st, _("Kerberos container location not specified"));
76 goto cleanup;
77 }
78
79 *container_dn = dn;
80
81 cleanup:
82 krb5_ldap_put_handle_to_pool(ldap_context, ldap_server_handle);
83 return st;
84 }
85