add missing plural s
[heimdal.git] / kdc / config.c
blob61ef3f4e4eed73c284aab2c7305780e0e3c198dd
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("$Id$");
41 struct dbinfo {
42 char *realm;
43 char *dbname;
44 char *mkey_file;
45 struct dbinfo *next;
48 static char *config_file; /* location of kdc config file */
50 static int require_preauth = -1; /* 1 == require preauth for all principals */
51 static char *max_request_str; /* `max_request' as a string */
53 static int disable_des = -1;
54 static int enable_v4 = -1;
55 static int enable_kaserver = -1;
56 static int enable_524 = -1;
57 static int enable_v4_cross_realm = -1;
59 static int builtin_hdb_flag;
60 static int help_flag;
61 static int version_flag;
63 static struct getarg_strings addresses_str; /* addresses to listen on */
65 static char *v4_realm;
67 char *runas_string;
68 char *chroot_string;
71 static struct getargs args[] = {
73 "config-file", 'c', arg_string, &config_file,
74 "location of config file", "file"
77 "require-preauth", 'p', arg_negative_flag, &require_preauth,
78 "don't require pa-data in as-reqs"
81 "max-request", 0, arg_string, &max_request_str,
82 "max size for a kdc-request", "size"
84 { "enable-http", 'H', arg_flag, &enable_http, "turn on HTTP support" },
85 { "524", 0, arg_negative_flag, &enable_524,
86 "don't respond to 524 requests"
89 "kaserver", 'K', arg_flag, &enable_kaserver,
90 "enable kaserver support"
92 { "kerberos4", 0, arg_flag, &enable_v4,
93 "respond to kerberos 4 requests"
96 "v4-realm", 'r', arg_string, &v4_realm,
97 "realm to serve v4-requests for"
99 { "kerberos4-cross-realm", 0, arg_flag,
100 &enable_v4_cross_realm,
101 "respond to kerberos 4 requests from foreign realms"
103 { "ports", 'P', arg_string, &port_str,
104 "ports to listen to", "portspec"
106 #ifdef SUPPORT_DETACH
107 #if DETACH_IS_DEFAULT
109 "detach", 'D', arg_negative_flag, &detach_from_console,
110 "don't detach from console"
112 #else
114 "detach", 0 , arg_flag, &detach_from_console,
115 "detach from console"
117 #endif
118 #endif
119 { "addresses", 0, arg_strings, &addresses_str,
120 "addresses to listen on", "list of addresses" },
121 { "disable-des", 0, arg_flag, &disable_des,
122 "disable DES" },
123 { "builtin-hdb", 0, arg_flag, &builtin_hdb_flag,
124 "list builtin hdb backends"},
125 { "runas-user", 0, arg_string, &runas_string,
126 "run as this user when connected to network"
128 { "chroot", 0, arg_string, &chroot_string,
129 "chroot directory to run in"
131 { "help", 'h', arg_flag, &help_flag },
132 { "version", 'v', arg_flag, &version_flag }
135 static int num_args = sizeof(args) / sizeof(args[0]);
137 static void
138 usage(int ret)
140 arg_printusage (args, num_args, NULL, "");
141 exit (ret);
144 static void
145 add_one_address (krb5_context context, const char *str, int first)
147 krb5_error_code ret;
148 krb5_addresses tmp;
150 ret = krb5_parse_address (context, str, &tmp);
151 if (ret)
152 krb5_err (context, 1, ret, "parse_address `%s'", str);
153 if (first)
154 krb5_copy_addresses(context, &tmp, &explicit_addresses);
155 else
156 krb5_append_addresses(context, &explicit_addresses, &tmp);
157 krb5_free_addresses (context, &tmp);
160 krb5_kdc_configuration *
161 configure(krb5_context context, int argc, char **argv)
163 krb5_kdc_configuration *config;
164 krb5_error_code ret;
165 int optidx = 0;
166 const char *p;
168 while(getarg(args, num_args, argc, argv, &optidx))
169 warnx("error at argument `%s'", argv[optidx]);
171 if(help_flag)
172 usage (0);
174 if (version_flag) {
175 print_version(NULL);
176 exit(0);
179 if (builtin_hdb_flag) {
180 char *list;
181 ret = hdb_list_builtin(context, &list);
182 if (ret)
183 krb5_err(context, 1, ret, "listing builtin hdb backends");
184 printf("builtin hdb backends: %s\n", list);
185 free(list);
186 exit(0);
189 argc -= optidx;
190 argv += optidx;
192 if (argc != 0)
193 usage(1);
196 char **files;
198 if (config_file == NULL) {
199 asprintf(&config_file, "%s/kdc.conf", hdb_db_dir(context));
200 if (config_file == NULL)
201 errx(1, "out of memory");
204 ret = krb5_prepend_config_files_default(config_file, &files);
205 if (ret)
206 krb5_err(context, 1, ret, "getting configuration files");
208 ret = krb5_set_config_files(context, files);
209 krb5_free_config_files(files);
210 if(ret)
211 krb5_err(context, 1, ret, "reading configuration files");
214 ret = krb5_kdc_get_config(context, &config);
215 if (ret)
216 krb5_err(context, 1, ret, "krb5_kdc_default_config");
218 kdc_openlog(context, config);
220 ret = krb5_kdc_set_dbinfo(context, config);
221 if (ret)
222 krb5_err(context, 1, ret, "krb5_kdc_set_dbinfo");
224 if(max_request_str)
225 max_request_tcp = max_request_udp = parse_bytes(max_request_str, NULL);
227 if(max_request_tcp == 0){
228 p = krb5_config_get_string (context,
229 NULL,
230 "kdc",
231 "max-request",
232 NULL);
233 if(p)
234 max_request_tcp = max_request_udp = parse_bytes(p, NULL);
237 if(require_preauth != -1)
238 config->require_preauth = require_preauth;
240 if(port_str == NULL){
241 p = krb5_config_get_string(context, NULL, "kdc", "ports", NULL);
242 if (p != NULL)
243 port_str = strdup(p);
246 explicit_addresses.len = 0;
248 if (addresses_str.num_strings) {
249 int i;
251 for (i = 0; i < addresses_str.num_strings; ++i)
252 add_one_address (context, addresses_str.strings[i], i == 0);
253 free_getarg_strings (&addresses_str);
254 } else {
255 char **foo = krb5_config_get_strings (context, NULL,
256 "kdc", "addresses", NULL);
258 if (foo != NULL) {
259 add_one_address (context, *foo++, TRUE);
260 while (*foo)
261 add_one_address (context, *foo++, FALSE);
265 if(enable_v4 != -1)
266 config->enable_v4 = enable_v4;
268 if(enable_v4_cross_realm != -1)
269 config->enable_v4_cross_realm = enable_v4_cross_realm;
271 if(enable_524 != -1)
272 config->enable_524 = enable_524;
274 if(enable_http == -1)
275 enable_http = krb5_config_get_bool(context, NULL, "kdc",
276 "enable-http", NULL);
278 if(request_log == NULL)
279 request_log = krb5_config_get_string(context, NULL,
280 "kdc",
281 "kdc-request-log",
282 NULL);
284 if (krb5_config_get_string(context, NULL, "kdc",
285 "enforce-transited-policy", NULL))
286 krb5_errx(context, 1, "enforce-transited-policy deprecated, "
287 "use [kdc]transited-policy instead");
289 if (enable_kaserver != -1)
290 config->enable_kaserver = enable_kaserver;
292 #ifdef SUPPORT_DETACH
293 if(detach_from_console == -1)
294 detach_from_console = krb5_config_get_bool_default(context, NULL,
295 DETACH_IS_DEFAULT,
296 "kdc",
297 "detach", NULL);
298 #endif /* SUPPORT_DETACH */
300 if(max_request_tcp == 0)
301 max_request_tcp = 64 * 1024;
302 if(max_request_udp == 0)
303 max_request_udp = 64 * 1024;
305 if (port_str == NULL)
306 port_str = "+";
308 if (v4_realm)
309 config->v4_realm = v4_realm;
311 if(config->v4_realm == NULL && (config->enable_kaserver || config->enable_v4))
312 krb5_errx(context, 1, "Kerberos 4 enabled but no realm configured");
314 if(disable_des == -1)
315 disable_des = krb5_config_get_bool_default(context, NULL,
316 FALSE,
317 "kdc",
318 "disable-des", NULL);
319 if(disable_des) {
320 krb5_enctype_disable(context, ETYPE_DES_CBC_CRC);
321 krb5_enctype_disable(context, ETYPE_DES_CBC_MD4);
322 krb5_enctype_disable(context, ETYPE_DES_CBC_MD5);
323 krb5_enctype_disable(context, ETYPE_DES_CBC_NONE);
324 krb5_enctype_disable(context, ETYPE_DES_CFB64_NONE);
325 krb5_enctype_disable(context, ETYPE_DES_PCBC_NONE);
327 kdc_log(context, config,
328 0, "DES was disabled, turned off Kerberos V4, 524 "
329 "and kaserver");
330 config->enable_v4 = 0;
331 config->enable_524 = 0;
332 config->enable_kaserver = 0;
335 krb5_kdc_windc_init(context);
337 return config;