Maybe include <sys/types.h> and <sys/select.h>
[heimdal.git] / kdc / default_config.c
blob449cf47ad062ace61c918e21f71df437f6650aee
1 /*
2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
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
10 * are met:
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
33 * SUCH DAMAGE.
36 #include "kdc_locl.h"
37 #include <getarg.h>
38 #include <parse_bytes.h>
40 krb5_error_code
41 krb5_kdc_get_config(krb5_context context, krb5_kdc_configuration **config)
43 krb5_kdc_configuration *c;
45 c = calloc(1, sizeof(*c));
46 if (c == NULL) {
47 krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
48 return ENOMEM;
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;
61 c->db = NULL;
62 c->num_db = 0;
63 c->logf = NULL;
65 c->require_preauth =
66 krb5_config_get_bool_default(context, NULL,
67 c->require_preauth,
68 "kdc", "require-preauth", NULL);
69 #ifdef DIGEST
70 c->enable_digest =
71 krb5_config_get_bool_default(context, NULL,
72 FALSE,
73 "kdc", "enable-digest", NULL);
76 const char *digests;
78 digests = krb5_config_get_string(context, NULL,
79 "kdc",
80 "digests_allowed", NULL);
81 if (digests == NULL)
82 digests = "ntlm-v2";
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",
87 digests);
88 c->enable_digest = 0;
89 } else if (c->digests_allowed == 0) {
90 kdc_log(context, c, 0,
91 "no digest enable, turning digest off",
92 digests);
93 c->enable_digest = 0;
96 #endif
98 #ifdef KX509
99 c->enable_kx509 =
100 krb5_config_get_bool_default(context, NULL,
101 FALSE,
102 "kdc", "enable-kx509", NULL);
104 if (c->enable_kx509) {
105 c->kx509_template =
106 krb5_config_get_string(context, NULL,
107 "kdc", "kx509_template", NULL);
108 c->kx509_ca =
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;
117 #endif
119 c->check_ticket_addresses =
120 krb5_config_get_bool_default(context, NULL,
121 c->check_ticket_addresses,
122 "kdc",
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,
127 "kdc",
128 "allow-null-ticket-addresses", NULL);
130 c->allow_anonymous =
131 krb5_config_get_bool_default(context, NULL,
132 c->allow_anonymous,
133 "kdc",
134 "allow-anonymous", NULL);
136 c->max_datagram_reply_length =
137 krb5_config_get_int_default(context,
138 NULL,
139 1400,
140 "kdc",
141 "max-kdc-datagram-reply-length",
142 NULL);
145 const char *trpolicy_str;
147 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) {
157 /* default */
158 } else {
159 kdc_log(context, c, 0,
160 "unknown transited-policy: %s, "
161 "reverting to default (always-check)",
162 trpolicy_str);
166 c->encode_as_rep_as_tgs_rep =
167 krb5_config_get_bool_default(context, NULL,
168 c->encode_as_rep_as_tgs_rep,
169 "kdc",
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);
178 c->enable_pkinit =
179 krb5_config_get_bool_default(context,
180 NULL,
181 c->enable_pkinit,
182 "kdc",
183 "enable-pkinit",
184 NULL);
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,
208 "kdc",
209 "pkinit_principal_in_certificate",
210 NULL);
211 c->pkinit_require_binding =
212 krb5_config_get_bool_default(context, NULL,
213 c->pkinit_require_binding,
214 "kdc",
215 "pkinit_win2k_require_binding",
216 NULL);
217 c->pkinit_dh_min_bits =
218 krb5_config_get_int_default(context, NULL,
220 "kdc", "pkinit_dh_min_bits", NULL);
222 *config = c;
224 return 0;
227 krb5_error_code
228 krb5_kdc_pkinit_config(krb5_context context, krb5_kdc_configuration *config)
230 #ifdef PKINIT
231 #ifdef __APPLE__
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);
260 return 0;
261 #endif /* PKINIT */