Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / crypto / dist / heimdal / kdc / config.c
blob6c79e5f32db7283eb49db8da832e6f5be9490cad
1 /*
2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include "kdc_locl.h"
36 #include <getarg.h>
37 #include <parse_bytes.h>
39 __RCSID("$Heimdal: config.c 22248 2007-12-08 23:52:12Z lha $"
40 "$NetBSD$");
42 struct dbinfo {
43 char *realm;
44 char *dbname;
45 char *mkey_file;
46 struct dbinfo *next;
49 static char *config_file; /* location of kdc config file */
51 static int require_preauth = -1; /* 1 == require preauth for all principals */
52 static char *max_request_str; /* `max_request' as a string */
54 static int disable_des = -1;
55 static int enable_v4 = -1;
56 static int enable_kaserver = -1;
57 static int enable_524 = -1;
58 static int enable_v4_cross_realm = -1;
60 static int builtin_hdb_flag;
61 static int help_flag;
62 static int version_flag;
64 static struct getarg_strings addresses_str; /* addresses to listen on */
66 static char *v4_realm;
68 static struct getargs args[] = {
70 "config-file", 'c', arg_string, &config_file,
71 "location of config file", "file"
74 "require-preauth", 'p', arg_negative_flag, &require_preauth,
75 "don't require pa-data in as-reqs"
78 "max-request", 0, arg_string, &max_request,
79 "max size for a kdc-request", "size"
81 { "enable-http", 'H', arg_flag, &enable_http, "turn on HTTP support" },
82 { "524", 0, arg_negative_flag, &enable_524,
83 "don't respond to 524 requests"
86 "kaserver", 'K', arg_flag, &enable_kaserver,
87 "enable kaserver support"
89 { "kerberos4", 0, arg_flag, &enable_v4,
90 "respond to kerberos 4 requests"
93 "v4-realm", 'r', arg_string, &v4_realm,
94 "realm to serve v4-requests for"
96 { "kerberos4-cross-realm", 0, arg_flag,
97 &enable_v4_cross_realm,
98 "respond to kerberos 4 requests from foreign realms"
100 { "ports", 'P', arg_string, &port_str,
101 "ports to listen to", "portspec"
103 #if DETACH_IS_DEFAULT
105 "detach", 'D', arg_negative_flag, &detach_from_console,
106 "don't detach from console"
108 #else
110 "detach", 0 , arg_flag, &detach_from_console,
111 "detach from console"
113 #endif
114 { "addresses", 0, arg_strings, &addresses_str,
115 "addresses to listen on", "list of addresses" },
116 { "disable-des", 0, arg_flag, &disable_des,
117 "disable DES" },
118 { "builtin-hdb", 0, arg_flag, &builtin_hdb_flag,
119 "list builtin hdb backends"},
120 { "help", 'h', arg_flag, &help_flag },
121 { "version", 'v', arg_flag, &version_flag }
124 static int num_args = sizeof(args) / sizeof(args[0]);
126 static void
127 usage(int ret)
129 arg_printusage (args, num_args, NULL, "");
130 exit (ret);
133 static void
134 add_one_address (krb5_context context, const char *str, int first)
136 krb5_error_code ret;
137 krb5_addresses tmp;
139 ret = krb5_parse_address (context, str, &tmp);
140 if (ret)
141 krb5_err (context, 1, ret, "parse_address `%s'", str);
142 if (first)
143 krb5_copy_addresses(context, &tmp, &explicit_addresses);
144 else
145 krb5_append_addresses(context, &explicit_addresses, &tmp);
146 krb5_free_addresses (context, &tmp);
149 krb5_kdc_configuration *
150 configure(krb5_context context, int argc, char **argv)
152 krb5_kdc_configuration *config;
153 krb5_error_code ret;
154 int optidx = 0;
155 const char *p;
157 while(getarg(args, num_args, argc, argv, &optidx))
158 warnx("error at argument `%s'", argv[optidx]);
160 if(help_flag)
161 usage (0);
163 if (version_flag) {
164 print_version(NULL);
165 exit(0);
168 if (builtin_hdb_flag) {
169 char *list;
170 ret = hdb_list_builtin(context, &list);
171 if (ret)
172 krb5_err(context, 1, ret, "listing builtin hdb backends");
173 printf("builtin hdb backends: %s\n", list);
174 free(list);
175 exit(0);
178 argc -= optidx;
179 argv += optidx;
181 if (argc != 0)
182 usage(1);
185 char **files;
187 if (config_file == NULL) {
188 asprintf(&config_file, "%s/kdc.conf", hdb_db_dir(context));
189 if (config_file == NULL)
190 errx(1, "out of memory");
193 ret = krb5_prepend_config_files_default(config_file, &files);
194 if (ret)
195 krb5_err(context, 1, ret, "getting configuration files");
197 ret = krb5_set_config_files(context, files);
198 krb5_free_config_files(files);
199 if(ret)
200 krb5_err(context, 1, ret, "reading configuration files");
203 ret = krb5_kdc_get_config(context, &config);
204 if (ret)
205 krb5_err(context, 1, ret, "krb5_kdc_default_config");
207 kdc_openlog(context, config);
209 ret = krb5_kdc_set_dbinfo(context, config);
210 if (ret)
211 krb5_err(context, 1, ret, "krb5_kdc_set_dbinfo");
213 if(max_request_str)
214 max_request = parse_bytes(max_request_str, NULL);
216 if(max_request == 0){
217 p = krb5_config_get_string (context,
218 NULL,
219 "kdc",
220 "max-request",
221 NULL);
222 if(p)
223 max_request = parse_bytes(p, NULL);
226 if(require_preauth != -1)
227 config->require_preauth = require_preauth;
229 if(port_str == NULL){
230 p = krb5_config_get_string(context, NULL, "kdc", "ports", NULL);
231 if (p != NULL)
232 port_str = strdup(p);
235 explicit_addresses.len = 0;
237 if (addresses_str.num_strings) {
238 int i;
240 for (i = 0; i < addresses_str.num_strings; ++i)
241 add_one_address (context, addresses_str.strings[i], i == 0);
242 free_getarg_strings (&addresses_str);
243 } else {
244 char **foo = krb5_config_get_strings (context, NULL,
245 "kdc", "addresses", NULL);
247 if (foo != NULL) {
248 add_one_address (context, *foo++, TRUE);
249 while (*foo)
250 add_one_address (context, *foo++, FALSE);
254 if(enable_v4 != -1)
255 config->enable_v4 = enable_v4;
257 if(enable_v4_cross_realm != -1)
258 config->enable_v4_cross_realm = enable_v4_cross_realm;
260 if(enable_524 != -1)
261 config->enable_524 = enable_524;
263 if(enable_http == -1)
264 enable_http = krb5_config_get_bool(context, NULL, "kdc",
265 "enable-http", NULL);
267 if(request_log == NULL)
268 request_log = krb5_config_get_string(context, NULL,
269 "kdc",
270 "kdc-request-log",
271 NULL);
273 if (krb5_config_get_string(context, NULL, "kdc",
274 "enforce-transited-policy", NULL))
275 krb5_errx(context, 1, "enforce-transited-policy deprecated, "
276 "use [kdc]transited-policy instead");
278 if (enable_kaserver != -1)
279 config->enable_kaserver = enable_kaserver;
281 if(detach_from_console == -1)
282 detach_from_console = krb5_config_get_bool_default(context, NULL,
283 DETACH_IS_DEFAULT,
284 "kdc",
285 "detach", NULL);
287 if(max_request == 0)
288 max_request = 64 * 1024;
290 if (port_str == NULL)
291 port_str = "+";
293 if (v4_realm)
294 config->v4_realm = v4_realm;
296 if(config->v4_realm == NULL && (config->enable_kaserver || config->enable_v4))
297 krb5_errx(context, 1, "Kerberos 4 enabled but no realm configured");
299 if(disable_des == -1)
300 disable_des = krb5_config_get_bool_default(context, NULL,
301 FALSE,
302 "kdc",
303 "disable-des", NULL);
304 if(disable_des) {
305 krb5_enctype_disable(context, ETYPE_DES_CBC_CRC);
306 krb5_enctype_disable(context, ETYPE_DES_CBC_MD4);
307 krb5_enctype_disable(context, ETYPE_DES_CBC_MD5);
308 krb5_enctype_disable(context, ETYPE_DES_CBC_NONE);
309 krb5_enctype_disable(context, ETYPE_DES_CFB64_NONE);
310 krb5_enctype_disable(context, ETYPE_DES_PCBC_NONE);
312 kdc_log(context, config,
313 0, "DES was disabled, turned off Kerberos V4, 524 "
314 "and kaserver");
315 config->enable_v4 = 0;
316 config->enable_524 = 0;
317 config->enable_kaserver = 0;
320 krb5_kdc_windc_init(context);
322 return config;