Populate creds in get_new_tickets before actually using it.
[heimdal.git] / kdc / config.c
blob485f20be2037c8542a32e543be8b169955bb06d6
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 struct dbinfo {
41 char *realm;
42 char *dbname;
43 char *mkey_file;
44 struct dbinfo *next;
47 static char *config_file; /* location of kdc config file */
49 static int require_preauth = -1; /* 1 == require preauth for all principals */
50 static char *max_request_str; /* `max_request' as a string */
52 static int disable_des = -1;
54 static int builtin_hdb_flag;
55 static int help_flag;
56 static int version_flag;
58 /* Should we enable the HTTP hack? */
59 int enable_http = -1;
61 /* Log over requests to the KDC */
62 const char *request_log;
64 /* A string describing on what ports to listen */
65 const char *port_str;
67 krb5_addresses explicit_addresses;
69 size_t max_request_udp;
70 size_t max_request_tcp;
73 static struct getarg_strings addresses_str; /* addresses to listen on */
75 char *runas_string;
76 char *chroot_string;
79 static struct getargs args[] = {
81 "config-file", 'c', arg_string, &config_file,
82 "location of config file", "file"
85 "require-preauth", 'p', arg_negative_flag, &require_preauth,
86 "don't require pa-data in as-reqs", NULL
89 "max-request", 0, arg_string, &max_request_str,
90 "max size for a kdc-request", "size"
92 { "enable-http", 'H', arg_flag, &enable_http, "turn on HTTP support",
93 NULL },
94 { "ports", 'P', arg_string, rk_UNCONST(&port_str),
95 "ports to listen to", "portspec"
97 #ifdef SUPPORT_DETACH
98 #if DETACH_IS_DEFAULT
100 "detach", 'D', arg_negative_flag, &detach_from_console,
101 "don't detach from console", NULL
103 #else
105 "detach", 0 , arg_flag, &detach_from_console,
106 "detach from console", NULL
108 #endif
109 #endif
110 { "addresses", 0, arg_strings, &addresses_str,
111 "addresses to listen on", "list of addresses" },
112 { "disable-des", 0, arg_flag, &disable_des,
113 "disable DES", NULL },
114 { "builtin-hdb", 0, arg_flag, &builtin_hdb_flag,
115 "list builtin hdb backends", NULL},
116 { "runas-user", 0, arg_string, &runas_string,
117 "run as this user when connected to network", NULL
119 { "chroot", 0, arg_string, &chroot_string,
120 "chroot directory to run in", NULL
122 { "help", 'h', arg_flag, &help_flag, NULL, NULL },
123 { "version", 'v', arg_flag, &version_flag, NULL, NULL }
126 static int num_args = sizeof(args) / sizeof(args[0]);
128 static void
129 usage(int ret)
131 arg_printusage (args, num_args, NULL, "");
132 exit (ret);
135 static void
136 add_one_address (krb5_context context, const char *str, int first)
138 krb5_error_code ret;
139 krb5_addresses tmp;
141 ret = krb5_parse_address (context, str, &tmp);
142 if (ret)
143 krb5_err (context, 1, ret, "parse_address `%s'", str);
144 if (first)
145 krb5_copy_addresses(context, &tmp, &explicit_addresses);
146 else
147 krb5_append_addresses(context, &explicit_addresses, &tmp);
148 krb5_free_addresses (context, &tmp);
151 krb5_kdc_configuration *
152 configure(krb5_context context, int argc, char **argv, int *optidx)
154 krb5_kdc_configuration *config;
155 krb5_error_code ret;
157 const char *p;
159 *optidx = 0;
161 while(getarg(args, num_args, argc, argv, optidx))
162 warnx("error at argument `%s'", argv[*optidx]);
164 if(help_flag)
165 usage (0);
167 if (version_flag) {
168 print_version(NULL);
169 exit(0);
172 if (builtin_hdb_flag) {
173 char *list;
174 ret = hdb_list_builtin(context, &list);
175 if (ret)
176 krb5_err(context, 1, ret, "listing builtin hdb backends");
177 printf("builtin hdb backends: %s\n", list);
178 free(list);
179 exit(0);
183 char **files;
185 if (config_file == NULL) {
186 asprintf(&config_file, "%s/kdc.conf", hdb_db_dir(context));
187 if (config_file == NULL)
188 errx(1, "out of memory");
191 ret = krb5_prepend_config_files_default(config_file, &files);
192 if (ret)
193 krb5_err(context, 1, ret, "getting configuration files");
195 ret = krb5_set_config_files(context, files);
196 krb5_free_config_files(files);
197 if(ret)
198 krb5_err(context, 1, ret, "reading configuration files");
201 ret = krb5_kdc_get_config(context, &config);
202 if (ret)
203 krb5_err(context, 1, ret, "krb5_kdc_default_config");
205 kdc_openlog(context, "kdc", config);
207 ret = krb5_kdc_set_dbinfo(context, config);
208 if (ret)
209 krb5_err(context, 1, ret, "krb5_kdc_set_dbinfo");
211 if(max_request_str)
212 max_request_tcp = max_request_udp = parse_bytes(max_request_str, NULL);
214 if(max_request_tcp == 0){
215 p = krb5_config_get_string (context,
216 NULL,
217 "kdc",
218 "max-request",
219 NULL);
220 if(p)
221 max_request_tcp = max_request_udp = parse_bytes(p, NULL);
224 if(require_preauth != -1)
225 config->require_preauth = require_preauth;
227 if(port_str == NULL){
228 p = krb5_config_get_string(context, NULL, "kdc", "ports", NULL);
229 if (p != NULL)
230 port_str = strdup(p);
233 explicit_addresses.len = 0;
235 if (addresses_str.num_strings) {
236 int i;
238 for (i = 0; i < addresses_str.num_strings; ++i)
239 add_one_address (context, addresses_str.strings[i], i == 0);
240 free_getarg_strings (&addresses_str);
241 } else {
242 char **foo = krb5_config_get_strings (context, NULL,
243 "kdc", "addresses", NULL);
245 if (foo != NULL) {
246 add_one_address (context, *foo++, TRUE);
247 while (*foo)
248 add_one_address (context, *foo++, FALSE);
252 if(enable_http == -1)
253 enable_http = krb5_config_get_bool(context, NULL, "kdc",
254 "enable-http", NULL);
256 if(request_log == NULL)
257 request_log = krb5_config_get_string(context, NULL,
258 "kdc",
259 "kdc-request-log",
260 NULL);
262 if (krb5_config_get_string(context, NULL, "kdc",
263 "enforce-transited-policy", NULL))
264 krb5_errx(context, 1, "enforce-transited-policy deprecated, "
265 "use [kdc]transited-policy instead");
267 #ifdef SUPPORT_DETACH
268 if(detach_from_console == -1)
269 detach_from_console = krb5_config_get_bool_default(context, NULL,
270 DETACH_IS_DEFAULT,
271 "kdc",
272 "detach", NULL);
273 #endif /* SUPPORT_DETACH */
275 if(max_request_tcp == 0)
276 max_request_tcp = 64 * 1024;
277 if(max_request_udp == 0)
278 max_request_udp = 64 * 1024;
280 if (port_str == NULL)
281 port_str = "+";
283 if(disable_des == -1)
284 disable_des = krb5_config_get_bool_default(context, NULL,
285 FALSE,
286 "kdc",
287 "disable-des", NULL);
288 if(disable_des) {
289 krb5_enctype_disable(context, ETYPE_DES_CBC_CRC);
290 krb5_enctype_disable(context, ETYPE_DES_CBC_MD4);
291 krb5_enctype_disable(context, ETYPE_DES_CBC_MD5);
292 krb5_enctype_disable(context, ETYPE_DES_CBC_NONE);
293 krb5_enctype_disable(context, ETYPE_DES_CFB64_NONE);
294 krb5_enctype_disable(context, ETYPE_DES_PCBC_NONE);
297 krb5_kdc_windc_init(context);
299 krb5_kdc_pkinit_config(context, config);
301 return config;