xref: /minix3/crypto/external/bsd/heimdal/dist/kcm/config.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: config.c,v 1.1.1.2 2014/04/24 12:45:27 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc  * Copyright (c) 2005, PADL Software Pty Ltd.
5ebfedea0SLionel Sambuc  * All rights reserved.
6ebfedea0SLionel Sambuc  *
7ebfedea0SLionel Sambuc  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8ebfedea0SLionel Sambuc  *
9ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
10ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
11ebfedea0SLionel Sambuc  * are met:
12ebfedea0SLionel Sambuc  *
13ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
14ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
15ebfedea0SLionel Sambuc  *
16ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
17ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
18ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
19ebfedea0SLionel Sambuc  *
20ebfedea0SLionel Sambuc  * 3. Neither the name of PADL Software nor the names of its contributors
21ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
22ebfedea0SLionel Sambuc  *    without specific prior written permission.
23ebfedea0SLionel Sambuc  *
24ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
25ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
28ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34ebfedea0SLionel Sambuc  * SUCH DAMAGE.
35ebfedea0SLionel Sambuc  */
36ebfedea0SLionel Sambuc 
37ebfedea0SLionel Sambuc #include "kcm_locl.h"
38ebfedea0SLionel Sambuc #include <krb5/getarg.h>
39ebfedea0SLionel Sambuc #include <krb5/parse_bytes.h>
40ebfedea0SLionel Sambuc 
41ebfedea0SLionel Sambuc static const char *config_file;	/* location of kcm config file */
42ebfedea0SLionel Sambuc 
43ebfedea0SLionel Sambuc size_t max_request = 0;		/* maximal size of a request */
44ebfedea0SLionel Sambuc char *socket_path = NULL;
45ebfedea0SLionel Sambuc char *door_path = NULL;
46ebfedea0SLionel Sambuc 
47ebfedea0SLionel Sambuc static char *max_request_str;	/* `max_request' as a string */
48ebfedea0SLionel Sambuc 
49ebfedea0SLionel Sambuc #ifdef SUPPORT_DETACH
50ebfedea0SLionel Sambuc int detach_from_console = -1;
51ebfedea0SLionel Sambuc #define DETACH_IS_DEFAULT FALSE
52ebfedea0SLionel Sambuc #endif
53ebfedea0SLionel Sambuc 
54ebfedea0SLionel Sambuc static const char *system_cache_name = NULL;
55ebfedea0SLionel Sambuc static const char *system_keytab = NULL;
56ebfedea0SLionel Sambuc static const char *system_principal = NULL;
57ebfedea0SLionel Sambuc static const char *system_server = NULL;
58ebfedea0SLionel Sambuc static const char *system_perms = NULL;
59ebfedea0SLionel Sambuc static const char *system_user = NULL;
60ebfedea0SLionel Sambuc static const char *system_group = NULL;
61ebfedea0SLionel Sambuc 
62ebfedea0SLionel Sambuc static const char *renew_life = NULL;
63ebfedea0SLionel Sambuc static const char *ticket_life = NULL;
64ebfedea0SLionel Sambuc 
65ebfedea0SLionel Sambuc int launchd_flag = 0;
66ebfedea0SLionel Sambuc int disallow_getting_krbtgt = 0;
67ebfedea0SLionel Sambuc int name_constraints = -1;
68ebfedea0SLionel Sambuc 
69ebfedea0SLionel Sambuc static int help_flag;
70ebfedea0SLionel Sambuc static int version_flag;
71ebfedea0SLionel Sambuc 
72ebfedea0SLionel Sambuc static struct getargs args[] = {
73ebfedea0SLionel Sambuc     {
74ebfedea0SLionel Sambuc 	"cache-name",	0,	arg_string,	&system_cache_name,
75ebfedea0SLionel Sambuc 	"system cache name", "cachename"
76ebfedea0SLionel Sambuc     },
77ebfedea0SLionel Sambuc     {
78ebfedea0SLionel Sambuc 	"config-file",	'c',	arg_string,	&config_file,
79ebfedea0SLionel Sambuc 	"location of config file",	"file"
80ebfedea0SLionel Sambuc     },
81ebfedea0SLionel Sambuc     {
82ebfedea0SLionel Sambuc 	"group",	'g',	arg_string,	&system_group,
83ebfedea0SLionel Sambuc 	"system cache group",	"group"
84ebfedea0SLionel Sambuc     },
85ebfedea0SLionel Sambuc     {
86ebfedea0SLionel Sambuc 	"max-request",	0,	arg_string, &max_request,
87ebfedea0SLionel Sambuc 	"max size for a kcm-request", "size"
88ebfedea0SLionel Sambuc     },
89ebfedea0SLionel Sambuc     {
90ebfedea0SLionel Sambuc 	"launchd",	0,	arg_flag, &launchd_flag,
91ebfedea0SLionel Sambuc 	"when in use by launchd"
92ebfedea0SLionel Sambuc     },
93ebfedea0SLionel Sambuc #ifdef SUPPORT_DETACH
94ebfedea0SLionel Sambuc #if DETACH_IS_DEFAULT
95ebfedea0SLionel Sambuc     {
96ebfedea0SLionel Sambuc 	"detach",       'D',      arg_negative_flag, &detach_from_console,
97ebfedea0SLionel Sambuc 	"don't detach from console"
98ebfedea0SLionel Sambuc     },
99ebfedea0SLionel Sambuc #else
100ebfedea0SLionel Sambuc     {
101ebfedea0SLionel Sambuc 	"detach",       0 ,      arg_flag, &detach_from_console,
102ebfedea0SLionel Sambuc 	"detach from console"
103ebfedea0SLionel Sambuc     },
104ebfedea0SLionel Sambuc #endif
105ebfedea0SLionel Sambuc #endif
106ebfedea0SLionel Sambuc     {	"help",		'h',	arg_flag,   &help_flag },
107ebfedea0SLionel Sambuc     {
108ebfedea0SLionel Sambuc 	"system-principal",	'k',	arg_string,	&system_principal,
109ebfedea0SLionel Sambuc 	"system principal name",	"principal"
110ebfedea0SLionel Sambuc     },
111ebfedea0SLionel Sambuc     {
112ebfedea0SLionel Sambuc 	"lifetime",	'l', arg_string, &ticket_life,
113ebfedea0SLionel Sambuc 	"lifetime of system tickets", "time"
114ebfedea0SLionel Sambuc     },
115ebfedea0SLionel Sambuc     {
116ebfedea0SLionel Sambuc 	"mode",		'm', arg_string, &system_perms,
117ebfedea0SLionel Sambuc 	"octal mode of system cache", "mode"
118ebfedea0SLionel Sambuc     },
119ebfedea0SLionel Sambuc     {
120ebfedea0SLionel Sambuc 	"name-constraints",	'n', arg_negative_flag, &name_constraints,
121ebfedea0SLionel Sambuc 	"disable credentials cache name constraints"
122ebfedea0SLionel Sambuc     },
123ebfedea0SLionel Sambuc     {
124ebfedea0SLionel Sambuc 	"disallow-getting-krbtgt", 0, arg_flag, &disallow_getting_krbtgt,
125ebfedea0SLionel Sambuc 	"disable fetching krbtgt from the cache"
126ebfedea0SLionel Sambuc     },
127ebfedea0SLionel Sambuc     {
128ebfedea0SLionel Sambuc 	"renewable-life",	'r', arg_string, &renew_life,
129ebfedea0SLionel Sambuc     	"renewable lifetime of system tickets", "time"
130ebfedea0SLionel Sambuc     },
131ebfedea0SLionel Sambuc     {
132ebfedea0SLionel Sambuc 	"socket-path",		's', arg_string, &socket_path,
133ebfedea0SLionel Sambuc     	"path to kcm domain socket", "path"
134ebfedea0SLionel Sambuc     },
135ebfedea0SLionel Sambuc #ifdef HAVE_DOOR_CREATE
136ebfedea0SLionel Sambuc     {
137ebfedea0SLionel Sambuc 	"door-path",		's', arg_string, &door_path,
138ebfedea0SLionel Sambuc     	"path to kcm door", "path"
139ebfedea0SLionel Sambuc     },
140ebfedea0SLionel Sambuc #endif
141ebfedea0SLionel Sambuc     {
142ebfedea0SLionel Sambuc 	"server",		'S', arg_string, &system_server,
143ebfedea0SLionel Sambuc     	"server to get system ticket for", "principal"
144ebfedea0SLionel Sambuc     },
145ebfedea0SLionel Sambuc     {
146ebfedea0SLionel Sambuc 	"keytab",	't',	arg_string,	&system_keytab,
147ebfedea0SLionel Sambuc 	"system keytab name",	"keytab"
148ebfedea0SLionel Sambuc     },
149ebfedea0SLionel Sambuc     {
150ebfedea0SLionel Sambuc 	"user",		'u',	arg_string,	&system_user,
151ebfedea0SLionel Sambuc 	"system cache owner",	"user"
152ebfedea0SLionel Sambuc     },
153ebfedea0SLionel Sambuc     {	"version",	'v',	arg_flag,   &version_flag }
154ebfedea0SLionel Sambuc };
155ebfedea0SLionel Sambuc 
156ebfedea0SLionel Sambuc static int num_args = sizeof(args) / sizeof(args[0]);
157ebfedea0SLionel Sambuc 
158ebfedea0SLionel Sambuc static void
usage(int ret)159ebfedea0SLionel Sambuc usage(int ret)
160ebfedea0SLionel Sambuc {
161ebfedea0SLionel Sambuc     arg_printusage (args, num_args, NULL, "");
162ebfedea0SLionel Sambuc     exit (ret);
163ebfedea0SLionel Sambuc }
164ebfedea0SLionel Sambuc 
parse_owners(kcm_ccache ccache)165ebfedea0SLionel Sambuc static int parse_owners(kcm_ccache ccache)
166ebfedea0SLionel Sambuc {
167ebfedea0SLionel Sambuc     uid_t uid = 0;
168ebfedea0SLionel Sambuc     gid_t gid = 0;
169ebfedea0SLionel Sambuc     struct passwd *pw;
170ebfedea0SLionel Sambuc     struct group *gr;
171ebfedea0SLionel Sambuc     int uid_p = 0;
172ebfedea0SLionel Sambuc     int gid_p = 0;
173ebfedea0SLionel Sambuc 
174ebfedea0SLionel Sambuc     if (system_user != NULL) {
175ebfedea0SLionel Sambuc 	if (isdigit((unsigned char)system_user[0])) {
176ebfedea0SLionel Sambuc 	    pw = getpwuid(atoi(system_user));
177ebfedea0SLionel Sambuc 	} else {
178ebfedea0SLionel Sambuc 	    pw = getpwnam(system_user);
179ebfedea0SLionel Sambuc 	}
180ebfedea0SLionel Sambuc 	if (pw == NULL) {
181ebfedea0SLionel Sambuc 	    return errno;
182ebfedea0SLionel Sambuc 	}
183ebfedea0SLionel Sambuc 
184ebfedea0SLionel Sambuc 	system_user = strdup(pw->pw_name);
185ebfedea0SLionel Sambuc 	if (system_user == NULL) {
186ebfedea0SLionel Sambuc 	    return ENOMEM;
187ebfedea0SLionel Sambuc 	}
188ebfedea0SLionel Sambuc 
189ebfedea0SLionel Sambuc 	uid = pw->pw_uid; uid_p = 1;
190ebfedea0SLionel Sambuc 	gid = pw->pw_gid; gid_p = 1;
191ebfedea0SLionel Sambuc     }
192ebfedea0SLionel Sambuc 
193ebfedea0SLionel Sambuc     if (system_group != NULL) {
194ebfedea0SLionel Sambuc 	if (isdigit((unsigned char)system_group[0])) {
195ebfedea0SLionel Sambuc 	    gr = getgrgid(atoi(system_group));
196ebfedea0SLionel Sambuc 	} else {
197ebfedea0SLionel Sambuc 	    gr = getgrnam(system_group);
198ebfedea0SLionel Sambuc 	}
199ebfedea0SLionel Sambuc 	if (gr == NULL) {
200ebfedea0SLionel Sambuc 	    return errno;
201ebfedea0SLionel Sambuc 	}
202ebfedea0SLionel Sambuc 
203ebfedea0SLionel Sambuc 	gid = gr->gr_gid; gid_p = 1;
204ebfedea0SLionel Sambuc     }
205ebfedea0SLionel Sambuc 
206ebfedea0SLionel Sambuc     if (uid_p)
207ebfedea0SLionel Sambuc 	ccache->uid = uid;
208ebfedea0SLionel Sambuc     else
209ebfedea0SLionel Sambuc 	ccache->uid = 0; /* geteuid() XXX */
210ebfedea0SLionel Sambuc 
211ebfedea0SLionel Sambuc     if (gid_p)
212ebfedea0SLionel Sambuc 	ccache->gid = gid;
213ebfedea0SLionel Sambuc     else
214ebfedea0SLionel Sambuc 	ccache->gid = 0; /* getegid() XXX */
215ebfedea0SLionel Sambuc 
216ebfedea0SLionel Sambuc     return 0;
217ebfedea0SLionel Sambuc }
218ebfedea0SLionel Sambuc 
219ebfedea0SLionel Sambuc static const char *
kcm_system_config_get_string(const char * string)220ebfedea0SLionel Sambuc kcm_system_config_get_string(const char *string)
221ebfedea0SLionel Sambuc {
222ebfedea0SLionel Sambuc     return krb5_config_get_string(kcm_context, NULL, "kcm",
223ebfedea0SLionel Sambuc 				  "system_ccache", string, NULL);
224ebfedea0SLionel Sambuc }
225ebfedea0SLionel Sambuc 
226ebfedea0SLionel Sambuc static krb5_error_code
ccache_init_system(void)227ebfedea0SLionel Sambuc ccache_init_system(void)
228ebfedea0SLionel Sambuc {
229ebfedea0SLionel Sambuc     kcm_ccache ccache;
230ebfedea0SLionel Sambuc     krb5_error_code ret;
231ebfedea0SLionel Sambuc 
232ebfedea0SLionel Sambuc     if (system_cache_name == NULL)
233ebfedea0SLionel Sambuc 	system_cache_name = kcm_system_config_get_string("cc_name");
234ebfedea0SLionel Sambuc 
235ebfedea0SLionel Sambuc     ret = kcm_ccache_new(kcm_context,
236ebfedea0SLionel Sambuc 			 system_cache_name ? system_cache_name : "SYSTEM",
237ebfedea0SLionel Sambuc 			 &ccache);
238ebfedea0SLionel Sambuc     if (ret)
239ebfedea0SLionel Sambuc 	return ret;
240ebfedea0SLionel Sambuc 
241ebfedea0SLionel Sambuc     ccache->flags |= KCM_FLAGS_OWNER_IS_SYSTEM;
242ebfedea0SLionel Sambuc     ccache->flags |= KCM_FLAGS_USE_KEYTAB;
243ebfedea0SLionel Sambuc 
244ebfedea0SLionel Sambuc     ret = parse_owners(ccache);
245ebfedea0SLionel Sambuc     if (ret)
246ebfedea0SLionel Sambuc 	return ret;
247ebfedea0SLionel Sambuc 
248ebfedea0SLionel Sambuc     ret = krb5_parse_name(kcm_context, system_principal, &ccache->client);
249ebfedea0SLionel Sambuc     if (ret) {
250ebfedea0SLionel Sambuc 	kcm_release_ccache(kcm_context, ccache);
251ebfedea0SLionel Sambuc 	return ret;
252ebfedea0SLionel Sambuc     }
253ebfedea0SLionel Sambuc 
254ebfedea0SLionel Sambuc     if (system_server == NULL)
255ebfedea0SLionel Sambuc 	system_server = kcm_system_config_get_string("server");
256ebfedea0SLionel Sambuc 
257ebfedea0SLionel Sambuc     if (system_server != NULL) {
258ebfedea0SLionel Sambuc 	ret = krb5_parse_name(kcm_context, system_server, &ccache->server);
259ebfedea0SLionel Sambuc 	if (ret) {
260ebfedea0SLionel Sambuc 	    kcm_release_ccache(kcm_context, ccache);
261ebfedea0SLionel Sambuc 	    return ret;
262ebfedea0SLionel Sambuc 	}
263ebfedea0SLionel Sambuc     }
264ebfedea0SLionel Sambuc 
265ebfedea0SLionel Sambuc     if (system_keytab == NULL)
266ebfedea0SLionel Sambuc 	system_keytab = kcm_system_config_get_string("keytab_name");
267ebfedea0SLionel Sambuc 
268ebfedea0SLionel Sambuc     if (system_keytab != NULL) {
269ebfedea0SLionel Sambuc 	ret = krb5_kt_resolve(kcm_context, system_keytab, &ccache->key.keytab);
270ebfedea0SLionel Sambuc     } else {
271ebfedea0SLionel Sambuc 	ret = krb5_kt_default(kcm_context, &ccache->key.keytab);
272ebfedea0SLionel Sambuc     }
273ebfedea0SLionel Sambuc     if (ret) {
274ebfedea0SLionel Sambuc 	kcm_release_ccache(kcm_context, ccache);
275ebfedea0SLionel Sambuc 	return ret;
276ebfedea0SLionel Sambuc     }
277ebfedea0SLionel Sambuc 
278ebfedea0SLionel Sambuc     if (renew_life == NULL)
279ebfedea0SLionel Sambuc 	renew_life = kcm_system_config_get_string("renew_life");
280ebfedea0SLionel Sambuc 
281ebfedea0SLionel Sambuc     if (renew_life == NULL)
282ebfedea0SLionel Sambuc 	renew_life = "1 month";
283ebfedea0SLionel Sambuc 
284ebfedea0SLionel Sambuc     if (renew_life != NULL) {
285ebfedea0SLionel Sambuc 	ccache->renew_life = parse_time(renew_life, "s");
286ebfedea0SLionel Sambuc 	if (ccache->renew_life < 0) {
287ebfedea0SLionel Sambuc 	    kcm_release_ccache(kcm_context, ccache);
288ebfedea0SLionel Sambuc 	    return EINVAL;
289ebfedea0SLionel Sambuc 	}
290ebfedea0SLionel Sambuc     }
291ebfedea0SLionel Sambuc 
292ebfedea0SLionel Sambuc     if (ticket_life == NULL)
293ebfedea0SLionel Sambuc 	ticket_life = kcm_system_config_get_string("ticket_life");
294ebfedea0SLionel Sambuc 
295ebfedea0SLionel Sambuc     if (ticket_life != NULL) {
296ebfedea0SLionel Sambuc 	ccache->tkt_life = parse_time(ticket_life, "s");
297ebfedea0SLionel Sambuc 	if (ccache->tkt_life < 0) {
298ebfedea0SLionel Sambuc 	    kcm_release_ccache(kcm_context, ccache);
299ebfedea0SLionel Sambuc 	    return EINVAL;
300ebfedea0SLionel Sambuc 	}
301ebfedea0SLionel Sambuc     }
302ebfedea0SLionel Sambuc 
303ebfedea0SLionel Sambuc     if (system_perms == NULL)
304ebfedea0SLionel Sambuc 	system_perms = kcm_system_config_get_string("mode");
305ebfedea0SLionel Sambuc 
306ebfedea0SLionel Sambuc     if (system_perms != NULL) {
307ebfedea0SLionel Sambuc 	int mode;
308ebfedea0SLionel Sambuc 
309ebfedea0SLionel Sambuc 	if (sscanf(system_perms, "%o", &mode) != 1)
310ebfedea0SLionel Sambuc 	    return EINVAL;
311ebfedea0SLionel Sambuc 
312ebfedea0SLionel Sambuc 	ccache->mode = mode;
313ebfedea0SLionel Sambuc     }
314ebfedea0SLionel Sambuc 
315ebfedea0SLionel Sambuc     if (disallow_getting_krbtgt == -1) {
316ebfedea0SLionel Sambuc 	disallow_getting_krbtgt =
317ebfedea0SLionel Sambuc 	    krb5_config_get_bool_default(kcm_context, NULL, FALSE, "kcm",
318ebfedea0SLionel Sambuc 					 "disallow-getting-krbtgt", NULL);
319ebfedea0SLionel Sambuc     }
320ebfedea0SLionel Sambuc 
321ebfedea0SLionel Sambuc     /* enqueue default actions for credentials cache */
322ebfedea0SLionel Sambuc     ret = kcm_ccache_enqueue_default(kcm_context, ccache, NULL);
323ebfedea0SLionel Sambuc 
324ebfedea0SLionel Sambuc     kcm_release_ccache(kcm_context, ccache); /* retained by event queue */
325ebfedea0SLionel Sambuc 
326ebfedea0SLionel Sambuc     return ret;
327ebfedea0SLionel Sambuc }
328ebfedea0SLionel Sambuc 
329ebfedea0SLionel Sambuc void
kcm_configure(int argc,char ** argv)330ebfedea0SLionel Sambuc kcm_configure(int argc, char **argv)
331ebfedea0SLionel Sambuc {
332ebfedea0SLionel Sambuc     krb5_error_code ret;
333ebfedea0SLionel Sambuc     int optind = 0;
334ebfedea0SLionel Sambuc     const char *p;
335ebfedea0SLionel Sambuc 
336ebfedea0SLionel Sambuc     while(getarg(args, num_args, argc, argv, &optind))
337ebfedea0SLionel Sambuc 	warnx("error at argument `%s'", argv[optind]);
338ebfedea0SLionel Sambuc 
339ebfedea0SLionel Sambuc     if(help_flag)
340ebfedea0SLionel Sambuc 	usage (0);
341ebfedea0SLionel Sambuc 
342ebfedea0SLionel Sambuc     if (version_flag) {
343ebfedea0SLionel Sambuc 	print_version(NULL);
344ebfedea0SLionel Sambuc 	exit(0);
345ebfedea0SLionel Sambuc     }
346ebfedea0SLionel Sambuc 
347ebfedea0SLionel Sambuc     argc -= optind;
348ebfedea0SLionel Sambuc     argv += optind;
349ebfedea0SLionel Sambuc 
350ebfedea0SLionel Sambuc     if (argc != 0)
351ebfedea0SLionel Sambuc 	usage(1);
352ebfedea0SLionel Sambuc 
353ebfedea0SLionel Sambuc     {
354ebfedea0SLionel Sambuc 	char **files;
355ebfedea0SLionel Sambuc 
356ebfedea0SLionel Sambuc 	if(config_file == NULL)
357ebfedea0SLionel Sambuc 	    config_file = _PATH_KCM_CONF;
358ebfedea0SLionel Sambuc 
359ebfedea0SLionel Sambuc 	ret = krb5_prepend_config_files_default(config_file, &files);
360ebfedea0SLionel Sambuc 	if (ret)
361ebfedea0SLionel Sambuc 	    krb5_err(kcm_context, 1, ret, "getting configuration files");
362ebfedea0SLionel Sambuc 
363ebfedea0SLionel Sambuc 	ret = krb5_set_config_files(kcm_context, files);
364ebfedea0SLionel Sambuc 	krb5_free_config_files(files);
365ebfedea0SLionel Sambuc 	if(ret)
366ebfedea0SLionel Sambuc 	    krb5_err(kcm_context, 1, ret, "reading configuration files");
367ebfedea0SLionel Sambuc     }
368ebfedea0SLionel Sambuc 
369ebfedea0SLionel Sambuc     if(max_request_str)
370ebfedea0SLionel Sambuc 	max_request = parse_bytes(max_request_str, NULL);
371ebfedea0SLionel Sambuc 
372ebfedea0SLionel Sambuc     if(max_request == 0){
373ebfedea0SLionel Sambuc 	p = krb5_config_get_string (kcm_context,
374ebfedea0SLionel Sambuc 				    NULL,
375ebfedea0SLionel Sambuc 				    "kcm",
376ebfedea0SLionel Sambuc 				    "max-request",
377ebfedea0SLionel Sambuc 				    NULL);
378ebfedea0SLionel Sambuc 	if(p)
379ebfedea0SLionel Sambuc 	    max_request = parse_bytes(p, NULL);
380ebfedea0SLionel Sambuc     }
381ebfedea0SLionel Sambuc 
382ebfedea0SLionel Sambuc     if (system_principal == NULL) {
383ebfedea0SLionel Sambuc 	system_principal = kcm_system_config_get_string("principal");
384ebfedea0SLionel Sambuc     }
385ebfedea0SLionel Sambuc 
386ebfedea0SLionel Sambuc     if (system_principal != NULL) {
387ebfedea0SLionel Sambuc 	ret = ccache_init_system();
388ebfedea0SLionel Sambuc 	if (ret)
389ebfedea0SLionel Sambuc 	    krb5_err(kcm_context, 1, ret, "initializing system ccache");
390ebfedea0SLionel Sambuc     }
391ebfedea0SLionel Sambuc 
392ebfedea0SLionel Sambuc #ifdef SUPPORT_DETACH
393ebfedea0SLionel Sambuc     if(detach_from_console == -1)
394ebfedea0SLionel Sambuc 	detach_from_console = krb5_config_get_bool_default(kcm_context, NULL,
395ebfedea0SLionel Sambuc 							   DETACH_IS_DEFAULT,
396ebfedea0SLionel Sambuc 							   "kcm",
397ebfedea0SLionel Sambuc 							   "detach", NULL);
398ebfedea0SLionel Sambuc #endif
399ebfedea0SLionel Sambuc     kcm_openlog();
400ebfedea0SLionel Sambuc     if(max_request == 0)
401ebfedea0SLionel Sambuc 	max_request = 64 * 1024;
402ebfedea0SLionel Sambuc }
403ebfedea0SLionel Sambuc 
404