2 * Copyright (c) 1997-2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <parse_bytes.h>
40 static char *config_file
; /* location of kdc config file */
42 int require_preauth
= -1; /* 1 == require preauth for all principals */
44 size_t max_request
; /* maximal size of a request */
46 static char *max_request_str
; /* `max_request' as a string */
48 time_t kdc_warn_pwexpire
; /* time before expiration to print a warning */
50 struct dbinfo
*databases
;
57 krb5_boolean encode_as_rep_as_tgs_rep
; /* bug compatibility */
59 krb5_boolean check_ticket_addresses
;
60 krb5_boolean allow_null_ticket_addresses
;
62 static struct getarg_strings addresses_str
; /* addresses to listen on */
63 krb5_addresses explicit_addresses
;
69 krb5_boolean enable_kaserver
= -1;
73 static int version_flag
;
75 static struct getargs args
[] = {
77 "config-file", 'c', arg_string
, &config_file
,
78 "location of config file", "file"
81 "require-preauth", 'p', arg_negative_flag
, &require_preauth
,
82 "don't require pa-data in as-reqs"
85 "max-request", 0, arg_string
, &max_request
,
86 "max size for a kdc-request", "size"
90 "database", 'd', arg_string
, &databases
,
91 "location of database", "database"
94 { "enable-http", 'H', arg_flag
, &enable_http
, "turn on HTTP support" },
97 "v4-realm", 'r', arg_string
, &v4_realm
,
98 "realm to serve v4-requests for"
103 "kaserver", 'K', arg_negative_flag
, &enable_kaserver
,
104 "turn off kaserver support"
107 { "ports", 'P', arg_string
, &port_str
,
110 { "addresses", 0, arg_strings
, &addresses_str
,
111 "addresses to listen on", "list of addresses" },
112 { "help", 'h', arg_flag
, &help_flag
},
113 { "version", 'v', arg_flag
, &version_flag
}
116 static int num_args
= sizeof(args
) / sizeof(args
[0]);
121 arg_printusage (args
, num_args
, NULL
, "");
126 get_dbinfo(krb5_config_section
*cf
)
128 krb5_config_binding
*top_binding
= NULL
;
129 krb5_config_binding
*db_binding
;
130 krb5_config_binding
*default_binding
= NULL
;
131 struct dbinfo
*di
, **dt
;
132 const char *default_dbname
= HDB_DEFAULT_DB
;
133 const char *default_mkey
= HDB_DB_DIR
"/m-key";
138 while((db_binding
= (krb5_config_binding
*)
139 krb5_config_get_next(context
, cf
, &top_binding
,
144 p
= krb5_config_get_string(context
, db_binding
, "realm", NULL
);
146 if(default_binding
) {
147 krb5_warnx(context
, "WARNING: more than one realm-less "
148 "database specification");
149 krb5_warnx(context
, "WARNING: using the first encountered");
151 default_binding
= db_binding
;
154 di
= calloc(1, sizeof(*di
));
155 di
->realm
= strdup(p
);
156 p
= krb5_config_get_string(context
, db_binding
, "dbname", NULL
);
158 di
->dbname
= strdup(p
);
159 p
= krb5_config_get_string(context
, db_binding
, "mkey_file", NULL
);
161 di
->mkey_file
= strdup(p
);
165 if(default_binding
) {
166 di
= calloc(1, sizeof(*di
));
167 p
= krb5_config_get_string(context
, default_binding
, "dbname", NULL
);
169 di
->dbname
= strdup(p
);
172 p
= krb5_config_get_string(context
, default_binding
, "mkey_file", NULL
);
174 di
->mkey_file
= strdup(p
);
180 di
= calloc(1, sizeof(*di
));
181 di
->dbname
= strdup(default_dbname
);
182 di
->mkey_file
= strdup(default_mkey
);
186 for(di
= databases
; di
; di
= di
->next
) {
187 if(di
->dbname
== NULL
)
188 di
->dbname
= strdup(default_dbname
);
189 if(di
->mkey_file
== NULL
) {
190 p
= strrchr(di
->dbname
, '.');
191 if(p
== NULL
|| strchr(p
, '/') != NULL
)
192 asprintf(&di
->mkey_file
, "%s.mkey", di
->dbname
);
194 asprintf(&di
->mkey_file
, "%.*s.mkey",
195 (int)(p
- di
->dbname
), di
->dbname
);
201 add_one_address (const char *str
, int first
)
206 ret
= krb5_parse_address (context
, str
, &tmp
);
208 krb5_err (context
, 1, ret
, "parse_address `%s'", str
);
210 krb5_copy_addresses(context
, &tmp
, &explicit_addresses
);
212 krb5_append_addresses(context
, &explicit_addresses
, &tmp
);
213 krb5_free_addresses (context
, &tmp
);
217 configure(int argc
, char **argv
)
219 krb5_config_section
*cf
= NULL
;
224 while((e
= getarg(args
, num_args
, argc
, argv
, &optind
)))
225 warnx("error at argument `%s'", argv
[optind
]);
241 if(config_file
== NULL
)
242 config_file
= HDB_DB_DIR
"/kdc.conf";
244 if(krb5_config_parse_file(config_file
, &cf
))
250 max_request
= parse_bytes(max_request_str
, NULL
);
253 if(max_request
== 0){
254 p
= krb5_config_get_string (context
,
260 max_request
= parse_bytes(p
, NULL
);
263 if(require_preauth
== -1)
264 require_preauth
= krb5_config_get_bool(context
, cf
, "kdc",
265 "require-preauth", NULL
);
267 if(port_str
== NULL
){
268 p
= krb5_config_get_string(context
, cf
, "kdc", "ports", NULL
);
270 port_str
= strdup(p
);
273 explicit_addresses
.len
= 0;
275 if (addresses_str
.num_strings
) {
278 for (i
= 0; i
< addresses_str
.num_strings
; ++i
)
279 add_one_address (addresses_str
.strings
[i
], i
== 0);
281 char **foo
= krb5_config_get_strings (context
, cf
,
282 "kdc", "addresses", NULL
);
285 add_one_address (*foo
++, TRUE
);
287 add_one_address (*foo
++, FALSE
);
291 if(enable_http
== -1)
292 enable_http
= krb5_config_get_bool(context
, cf
, "kdc",
293 "enable-http", NULL
);
294 check_ticket_addresses
=
295 krb5_config_get_bool(context
, cf
, "kdc",
296 "check-ticket-addresses", NULL
);
297 allow_null_ticket_addresses
=
298 krb5_config_get_bool(context
, cf
, "kdc",
299 "allow-null-ticket-addresses", NULL
);
301 if(v4_realm
== NULL
){
302 p
= krb5_config_get_string (context
, cf
,
307 v4_realm
= strdup(p
);
311 if (enable_kaserver
== -1)
312 enable_kaserver
= krb5_config_get_bool_default(context
, cf
, TRUE
,
318 encode_as_rep_as_tgs_rep
= krb5_config_get_bool(context
, cf
, "kdc",
319 "encode_as_rep_as_tgs_rep",
322 kdc_warn_pwexpire
= krb5_config_get_time (context
, cf
,
328 krb5_config_file_free (context
, cf
);
330 max_request
= 64 * 1024;
331 if(require_preauth
== -1)
333 if (port_str
== NULL
)
336 if(v4_realm
== NULL
){
337 v4_realm
= malloc(40); /* REALM_SZ */
338 krb_get_lrealm(v4_realm
, 1);