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>
40 #define MAX_REQUEST_MAX 67108864ll /* 64MB, the maximum accepted value of max_request */
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;
56 static int builtin_hdb_flag
;
59 static int version_flag
;
61 /* Should we enable the HTTP hack? */
64 /* Log over requests to the KDC */
65 const char *request_log
;
67 /* A string describing on what ports to listen */
70 krb5_addresses explicit_addresses
;
72 size_t max_request_udp
;
73 size_t max_request_tcp
;
76 static struct getarg_strings addresses_str
; /* addresses to listen on */
82 static struct getargs args
[] = {
84 "config-file", 'c', arg_string
, &config_file
,
85 "location of config file", "file"
88 "require-preauth", 'p', arg_negative_flag
, &require_preauth
,
89 "don't require pa-data in as-reqs", NULL
92 "max-request", 0, arg_string
, &max_request_str
,
93 "max size for a kdc-request", "size"
95 { "enable-http", 'H', arg_flag
, &enable_http
, "turn on HTTP support",
97 { "ports", 'P', arg_string
, rk_UNCONST(&port_str
),
98 "ports to listen to", "portspec"
101 "detach", 0 , arg_flag
, &detach_from_console
,
102 "detach from console", NULL
105 "daemon-child", 0 , arg_flag
, &daemon_child
,
106 "private argument, do not use", NULL
110 "bonjour", 0 , arg_flag
, &do_bonjour
,
111 "private argument, do not use", NULL
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", NULL
},
118 { "builtin-hdb", 0, arg_flag
, &builtin_hdb_flag
,
119 "list builtin hdb backends", NULL
},
120 { "runas-user", 0, arg_string
, &runas_string
,
121 "run as this user when connected to network", NULL
123 { "chroot", 0, arg_string
, &chroot_string
,
124 "chroot directory to run in", NULL
126 { "testing", 0, arg_flag
, &testing_flag
, NULL
, NULL
},
127 { "help", 'h', arg_flag
, &help_flag
, NULL
, NULL
},
128 { "version", 'v', arg_flag
, &version_flag
, NULL
, NULL
}
131 static int num_args
= sizeof(args
) / sizeof(args
[0]);
136 arg_printusage (args
, num_args
, NULL
, "");
141 add_one_address (krb5_context context
, const char *str
, int first
)
146 ret
= krb5_parse_address (context
, str
, &tmp
);
148 krb5_err (context
, 1, ret
, "parse_address `%s'", str
);
150 krb5_copy_addresses(context
, &tmp
, &explicit_addresses
);
152 krb5_append_addresses(context
, &explicit_addresses
, &tmp
);
153 krb5_free_addresses (context
, &tmp
);
156 krb5_kdc_configuration
*
157 configure(krb5_context context
, int argc
, char **argv
, int *optidx
)
159 krb5_kdc_configuration
*config
;
166 while (getarg(args
, num_args
, argc
, argv
, optidx
))
167 warnx("error at argument `%s'", argv
[*optidx
]);
177 if (builtin_hdb_flag
) {
179 ret
= hdb_list_builtin(context
, &list
);
181 krb5_err(context
, 1, ret
, "listing builtin hdb backends");
182 printf("builtin hdb backends: %s\n", list
);
187 if(detach_from_console
== -1)
188 detach_from_console
= krb5_config_get_bool_default(context
, NULL
,
193 if (detach_from_console
&& daemon_child
== -1)
194 daemon_child
= roken_detach_prep(argc
, argv
, "--daemon-child");
200 if (config_file
== NULL
) {
201 aret
= asprintf(&config_file
, "%s/kdc.conf", hdb_db_dir(context
));
202 if (aret
== -1 || config_file
== NULL
)
203 errx(1, "out of memory");
206 ret
= krb5_prepend_config_files_default(config_file
, &files
);
208 krb5_err(context
, 1, ret
, "getting configuration files");
210 ret
= krb5_set_config_files(context
, files
);
211 krb5_free_config_files(files
);
213 krb5_err(context
, 1, ret
, "reading configuration files");
216 ret
= krb5_kdc_get_config(context
, &config
);
218 krb5_err(context
, 1, ret
, "krb5_kdc_default_config");
220 kdc_openlog(context
, "kdc", config
);
222 ret
= krb5_kdc_set_dbinfo(context
, config
);
224 krb5_err(context
, 1, ret
, "krb5_kdc_set_dbinfo");
226 if (max_request_str
) {
229 if ((bytes
= parse_bytes(max_request_str
, NULL
)) < 0)
230 krb5_errx(context
, 1, "--max-request must be non-negative");
232 if (bytes
> MAX_REQUEST_MAX
)
233 krb5_errx(context
, 1, "--max-request size is too big "
234 "(must be smaller than %lld)", MAX_REQUEST_MAX
);
236 max_request_tcp
= max_request_udp
= bytes
;
239 if(max_request_tcp
== 0){
240 p
= krb5_config_get_string (context
,
248 if ((bytes
= parse_bytes(max_request_str
, NULL
)) < 0)
249 krb5_errx(context
, 1, "[kdc] max-request must be non-negative");
251 if (bytes
> MAX_REQUEST_MAX
)
252 krb5_errx(context
, 1, "[kdc] max-request size is too big "
253 "(must be smaller than %lld)", MAX_REQUEST_MAX
);
255 max_request_tcp
= max_request_udp
= bytes
;
259 if(require_preauth
!= -1)
260 config
->require_preauth
= require_preauth
;
262 if(port_str
== NULL
){
263 p
= krb5_config_get_string(context
, NULL
, "kdc", "ports", NULL
);
265 port_str
= strdup(p
);
268 explicit_addresses
.len
= 0;
270 if (addresses_str
.num_strings
) {
273 for (i
= 0; i
< addresses_str
.num_strings
; ++i
)
274 add_one_address (context
, addresses_str
.strings
[i
], i
== 0);
275 free_getarg_strings (&addresses_str
);
277 char **foo
= krb5_config_get_strings (context
, NULL
,
278 "kdc", "addresses", NULL
);
281 add_one_address (context
, *foo
++, TRUE
);
283 add_one_address (context
, *foo
++, FALSE
);
287 if(enable_http
== -1)
288 enable_http
= krb5_config_get_bool(context
, NULL
, "kdc",
289 "enable-http", NULL
);
291 if(request_log
== NULL
)
292 request_log
= krb5_config_get_string(context
, NULL
,
297 if (krb5_config_get_string(context
, NULL
, "kdc",
298 "enforce-transited-policy", NULL
))
299 krb5_errx(context
, 1, "enforce-transited-policy deprecated, "
300 "use [kdc]transited-policy instead");
302 if(max_request_tcp
== 0)
303 max_request_tcp
= 64 * 1024;
304 if(max_request_udp
== 0)
305 max_request_udp
= 64 * 1024;
307 if (port_str
== NULL
)
310 if(disable_des
== -1)
311 disable_des
= krb5_config_get_bool_default(context
, NULL
,
314 "disable-des", NULL
);
316 krb5_enctype_disable(context
, ETYPE_DES_CBC_CRC
);
317 krb5_enctype_disable(context
, ETYPE_DES_CBC_MD4
);
318 krb5_enctype_disable(context
, ETYPE_DES_CBC_MD5
);
319 krb5_enctype_disable(context
, ETYPE_DES_CBC_NONE
);
320 krb5_enctype_disable(context
, ETYPE_DES_CFB64_NONE
);
321 krb5_enctype_disable(context
, ETYPE_DES_PCBC_NONE
);
324 krb5_kdc_plugin_init(context
);
326 krb5_kdc_pkinit_config(context
, config
);