2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
37 #include <parse_bytes.h>
48 static const 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
;
61 static int version_flag
;
63 static struct getarg_strings addresses_str
; /* addresses to listen on */
65 static char *v4_realm
;
67 static struct getargs args
[] = {
69 "config-file", 'c', arg_string
, &config_file
,
70 "location of config file", "file"
73 "require-preauth", 'p', arg_negative_flag
, &require_preauth
,
74 "don't require pa-data in as-reqs"
77 "max-request", 0, arg_string
, &max_request
,
78 "max size for a kdc-request", "size"
80 { "enable-http", 'H', arg_flag
, &enable_http
, "turn on HTTP support" },
81 { "524", 0, arg_negative_flag
, &enable_524
,
82 "don't respond to 524 requests"
85 "kaserver", 'K', arg_flag
, &enable_kaserver
,
86 "enable kaserver support"
88 { "kerberos4", 0, arg_flag
, &enable_v4
,
89 "respond to kerberos 4 requests"
92 "v4-realm", 'r', arg_string
, &v4_realm
,
93 "realm to serve v4-requests for"
95 { "kerberos4-cross-realm", 0, arg_flag
,
96 &enable_v4_cross_realm
,
97 "respond to kerberos 4 requests from foreign realms"
99 { "ports", 'P', arg_string
, &port_str
,
100 "ports to listen to", "portspec"
102 #if DETACH_IS_DEFAULT
104 "detach", 'D', arg_negative_flag
, &detach_from_console
,
105 "don't detach from console"
109 "detach", 0 , arg_flag
, &detach_from_console
,
110 "detach from console"
113 { "addresses", 0, arg_strings
, &addresses_str
,
114 "addresses to listen on", "list of addresses" },
115 { "disable-des", 0, arg_flag
, &disable_des
,
117 { "builtin-hdb", 0, arg_flag
, &builtin_hdb_flag
,
118 "list builtin hdb backends"},
119 { "help", 'h', arg_flag
, &help_flag
},
120 { "version", 'v', arg_flag
, &version_flag
}
123 static int num_args
= sizeof(args
) / sizeof(args
[0]);
128 arg_printusage (args
, num_args
, NULL
, "");
133 add_one_address (krb5_context context
, const char *str
, int first
)
138 ret
= krb5_parse_address (context
, str
, &tmp
);
140 krb5_err (context
, 1, ret
, "parse_address `%s'", str
);
142 krb5_copy_addresses(context
, &tmp
, &explicit_addresses
);
144 krb5_append_addresses(context
, &explicit_addresses
, &tmp
);
145 krb5_free_addresses (context
, &tmp
);
148 krb5_kdc_configuration
*
149 configure(krb5_context context
, int argc
, char **argv
)
151 krb5_kdc_configuration
*config
;
156 while(getarg(args
, num_args
, argc
, argv
, &optidx
))
157 warnx("error at argument `%s'", argv
[optidx
]);
167 if (builtin_hdb_flag
) {
169 ret
= hdb_list_builtin(context
, &list
);
171 krb5_err(context
, 1, ret
, "listing builtin hdb backends");
172 printf("builtin hdb backends: %s\n", list
);
186 if(config_file
== NULL
)
187 config_file
= _PATH_KDC_CONF
;
189 ret
= krb5_prepend_config_files_default(config_file
, &files
);
191 krb5_err(context
, 1, ret
, "getting configuration files");
193 ret
= krb5_set_config_files(context
, files
);
194 krb5_free_config_files(files
);
196 krb5_err(context
, 1, ret
, "reading configuration files");
199 ret
= krb5_kdc_get_config(context
, &config
);
201 krb5_err(context
, 1, ret
, "krb5_kdc_default_config");
203 kdc_openlog(context
, config
);
205 ret
= krb5_kdc_set_dbinfo(context
, config
);
207 krb5_err(context
, 1, ret
, "krb5_kdc_set_dbinfo");
210 max_request
= parse_bytes(max_request_str
, NULL
);
212 if(max_request
== 0){
213 p
= krb5_config_get_string (context
,
219 max_request
= parse_bytes(p
, NULL
);
222 if(require_preauth
!= -1)
223 config
->require_preauth
= require_preauth
;
225 if(port_str
== NULL
){
226 p
= krb5_config_get_string(context
, NULL
, "kdc", "ports", NULL
);
228 port_str
= strdup(p
);
231 explicit_addresses
.len
= 0;
233 if (addresses_str
.num_strings
) {
236 for (i
= 0; i
< addresses_str
.num_strings
; ++i
)
237 add_one_address (context
, addresses_str
.strings
[i
], i
== 0);
238 free_getarg_strings (&addresses_str
);
240 char **foo
= krb5_config_get_strings (context
, NULL
,
241 "kdc", "addresses", NULL
);
244 add_one_address (context
, *foo
++, TRUE
);
246 add_one_address (context
, *foo
++, FALSE
);
251 config
->enable_v4
= enable_v4
;
253 if(enable_v4_cross_realm
!= -1)
254 config
->enable_v4_cross_realm
= enable_v4_cross_realm
;
257 config
->enable_524
= enable_524
;
259 if(enable_http
== -1)
260 enable_http
= krb5_config_get_bool(context
, NULL
, "kdc",
261 "enable-http", NULL
);
263 if(request_log
== NULL
)
264 request_log
= krb5_config_get_string(context
, NULL
,
269 if (krb5_config_get_string(context
, NULL
, "kdc",
270 "enforce-transited-policy", NULL
))
271 krb5_errx(context
, 1, "enforce-transited-policy deprecated, "
272 "use [kdc]transited-policy instead");
274 if (enable_kaserver
!= -1)
275 config
->enable_kaserver
= enable_kaserver
;
277 if(detach_from_console
== -1)
278 detach_from_console
= krb5_config_get_bool_default(context
, NULL
,
284 max_request
= 64 * 1024;
286 if (port_str
== NULL
)
290 config
->v4_realm
= v4_realm
;
292 if(config
->v4_realm
== NULL
&& (config
->enable_kaserver
|| config
->enable_v4
))
293 krb5_errx(context
, 1, "Kerberos 4 enabled but no realm configured");
295 if(disable_des
== -1)
296 disable_des
= krb5_config_get_bool_default(context
, NULL
,
299 "disable-des", NULL
);
301 krb5_enctype_disable(context
, ETYPE_DES_CBC_CRC
);
302 krb5_enctype_disable(context
, ETYPE_DES_CBC_MD4
);
303 krb5_enctype_disable(context
, ETYPE_DES_CBC_MD5
);
304 krb5_enctype_disable(context
, ETYPE_DES_CBC_NONE
);
305 krb5_enctype_disable(context
, ETYPE_DES_CFB64_NONE
);
306 krb5_enctype_disable(context
, ETYPE_DES_PCBC_NONE
);
308 kdc_log(context
, config
,
309 0, "DES was disabled, turned off Kerberos V4, 524 "
311 config
->enable_v4
= 0;
312 config
->enable_524
= 0;
313 config
->enable_kaserver
= 0;
316 krb5_kdc_windc_init(context
);