2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <parse_bytes.h>
41 krb5_kdc_get_config(krb5_context context
, krb5_kdc_configuration
**config
)
43 krb5_kdc_configuration
*c
;
45 c
= calloc(1, sizeof(*c
));
47 krb5_set_error_message(context
, ENOMEM
, "malloc: out of memory");
51 c
->require_preauth
= TRUE
;
52 c
->kdc_warn_pwexpire
= 0;
53 c
->encode_as_rep_as_tgs_rep
= FALSE
;
54 c
->check_ticket_addresses
= TRUE
;
55 c
->allow_null_ticket_addresses
= TRUE
;
56 c
->allow_anonymous
= FALSE
;
57 c
->trpolicy
= TRPOLICY_ALWAYS_CHECK
;
58 c
->enable_pkinit
= FALSE
;
59 c
->pkinit_princ_in_cert
= TRUE
;
60 c
->pkinit_require_binding
= TRUE
;
66 krb5_config_get_bool_default(context
, NULL
,
68 "kdc", "require-preauth", NULL
);
71 krb5_config_get_bool_default(context
, NULL
,
73 "kdc", "enable-digest", NULL
);
78 digests
= krb5_config_get_string(context
, NULL
,
80 "digests_allowed", NULL
);
83 c
->digests_allowed
= parse_flags(digests
,_kdc_digestunits
, 0);
84 if (c
->digests_allowed
== -1) {
85 kdc_log(context
, c
, 0,
86 "unparsable digest units (%s), turning off digest",
89 } else if (c
->digests_allowed
== 0) {
90 kdc_log(context
, c
, 0,
91 "no digest enable, turning digest off",
100 krb5_config_get_bool_default(context
, NULL
,
102 "kdc", "enable-kx509", NULL
);
104 if (c
->enable_kx509
) {
106 krb5_config_get_string(context
, NULL
,
107 "kdc", "kx509_template", NULL
);
109 krb5_config_get_string(context
, NULL
,
110 "kdc", "kx509_ca", NULL
);
111 if (c
->kx509_ca
== NULL
|| c
->kx509_template
== NULL
) {
112 kdc_log(context
, c
, 0,
113 "missing kx509 configuration, turning off");
114 c
->enable_kx509
= FALSE
;
119 c
->check_ticket_addresses
=
120 krb5_config_get_bool_default(context
, NULL
,
121 c
->check_ticket_addresses
,
123 "check-ticket-addresses", NULL
);
124 c
->allow_null_ticket_addresses
=
125 krb5_config_get_bool_default(context
, NULL
,
126 c
->allow_null_ticket_addresses
,
128 "allow-null-ticket-addresses", NULL
);
131 krb5_config_get_bool_default(context
, NULL
,
134 "allow-anonymous", NULL
);
136 c
->max_datagram_reply_length
=
137 krb5_config_get_int_default(context
,
141 "max-kdc-datagram-reply-length",
145 const char *trpolicy_str
;
148 krb5_config_get_string_default(context
, NULL
, "DEFAULT", "kdc",
149 "transited-policy", NULL
);
150 if(strcasecmp(trpolicy_str
, "always-check") == 0) {
151 c
->trpolicy
= TRPOLICY_ALWAYS_CHECK
;
152 } else if(strcasecmp(trpolicy_str
, "allow-per-principal") == 0) {
153 c
->trpolicy
= TRPOLICY_ALLOW_PER_PRINCIPAL
;
154 } else if(strcasecmp(trpolicy_str
, "always-honour-request") == 0) {
155 c
->trpolicy
= TRPOLICY_ALWAYS_HONOUR_REQUEST
;
156 } else if(strcasecmp(trpolicy_str
, "DEFAULT") == 0) {
159 kdc_log(context
, c
, 0,
160 "unknown transited-policy: %s, "
161 "reverting to default (always-check)",
166 c
->encode_as_rep_as_tgs_rep
=
167 krb5_config_get_bool_default(context
, NULL
,
168 c
->encode_as_rep_as_tgs_rep
,
170 "encode_as_rep_as_tgs_rep", NULL
);
172 c
->kdc_warn_pwexpire
=
173 krb5_config_get_time_default (context
, NULL
,
174 c
->kdc_warn_pwexpire
,
175 "kdc", "kdc_warn_pwexpire", NULL
);
179 krb5_config_get_bool_default(context
,
187 c
->pkinit_kdc_identity
=
188 krb5_config_get_string(context
, NULL
,
189 "kdc", "pkinit_identity", NULL
);
190 c
->pkinit_kdc_anchors
=
191 krb5_config_get_string(context
, NULL
,
192 "kdc", "pkinit_anchors", NULL
);
193 c
->pkinit_kdc_cert_pool
=
194 krb5_config_get_strings(context
, NULL
,
195 "kdc", "pkinit_pool", NULL
);
196 c
->pkinit_kdc_revoke
=
197 krb5_config_get_strings(context
, NULL
,
198 "kdc", "pkinit_revoke", NULL
);
199 c
->pkinit_kdc_ocsp_file
=
200 krb5_config_get_string(context
, NULL
,
201 "kdc", "pkinit_kdc_ocsp", NULL
);
202 c
->pkinit_kdc_friendly_name
=
203 krb5_config_get_string(context
, NULL
,
204 "kdc", "pkinit_kdc_friendly_name", NULL
);
205 c
->pkinit_princ_in_cert
=
206 krb5_config_get_bool_default(context
, NULL
,
207 c
->pkinit_princ_in_cert
,
209 "pkinit_principal_in_certificate",
211 c
->pkinit_require_binding
=
212 krb5_config_get_bool_default(context
, NULL
,
213 c
->pkinit_require_binding
,
215 "pkinit_win2k_require_binding",
217 c
->pkinit_dh_min_bits
=
218 krb5_config_get_int_default(context
, NULL
,
220 "kdc", "pkinit_dh_min_bits", NULL
);
228 krb5_kdc_pkinit_config(krb5_context context
, krb5_kdc_configuration
*config
)
232 config
->enable_pkinit
= 1;
234 if (config
->pkinit_kdc_identity
== NULL
) {
235 if (config
->pkinit_kdc_friendly_name
== NULL
)
236 config
->pkinit_kdc_friendly_name
=
237 strdup("O=System Identity,CN=com.apple.kerberos.kdc");
238 config
->pkinit_kdc_identity
= strdup("KEYCHAIN:");
240 if (config
->pkinit_kdc_anchors
== NULL
)
241 config
->pkinit_kdc_anchors
= strdup("KEYCHAIN:");
243 #endif /* __APPLE__ */
245 if (config
->enable_pkinit
) {
246 if (config
->pkinit_kdc_identity
== NULL
)
247 krb5_errx(context
, 1, "pkinit enabled but no identity");
249 if (config
->pkinit_kdc_anchors
== NULL
)
250 krb5_errx(context
, 1, "pkinit enabled but no X509 anchors");
252 krb5_kdc_pk_initialize(context
, config
,
253 config
->pkinit_kdc_identity
,
254 config
->pkinit_kdc_anchors
,
255 config
->pkinit_kdc_cert_pool
,
256 config
->pkinit_kdc_revoke
);