xref: /freebsd/crypto/heimdal/kdc/main.c (revision c19800e8cd5640693f36f2040db4ab5e8d738146)
1b528cefcSMark Murray /*
2c19800e8SDoug Rabson  * Copyright (c) 1997-2005 Kungliga Tekniska H�gskolan
3b528cefcSMark Murray  * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray  * All rights reserved.
5b528cefcSMark Murray  *
6b528cefcSMark Murray  * Redistribution and use in source and binary forms, with or without
7b528cefcSMark Murray  * modification, are permitted provided that the following conditions
8b528cefcSMark Murray  * are met:
9b528cefcSMark Murray  *
10b528cefcSMark Murray  * 1. Redistributions of source code must retain the above copyright
11b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer.
12b528cefcSMark Murray  *
13b528cefcSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
14b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer in the
15b528cefcSMark Murray  *    documentation and/or other materials provided with the distribution.
16b528cefcSMark Murray  *
17b528cefcSMark Murray  * 3. Neither the name of the Institute nor the names of its contributors
18b528cefcSMark Murray  *    may be used to endorse or promote products derived from this software
19b528cefcSMark Murray  *    without specific prior written permission.
20b528cefcSMark Murray  *
21b528cefcSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22b528cefcSMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23b528cefcSMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24b528cefcSMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25b528cefcSMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26b528cefcSMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27b528cefcSMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28b528cefcSMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29b528cefcSMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30b528cefcSMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b528cefcSMark Murray  * SUCH DAMAGE.
32b528cefcSMark Murray  */
33b528cefcSMark Murray 
34b528cefcSMark Murray #include "kdc_locl.h"
358373020dSJacques Vidrine #ifdef HAVE_UTIL_H
368373020dSJacques Vidrine #include <util.h>
378373020dSJacques Vidrine #endif
38b528cefcSMark Murray 
39c19800e8SDoug Rabson RCSID("$Id: main.c 20454 2007-04-19 20:21:51Z lha $");
40b528cefcSMark Murray 
41b528cefcSMark Murray sig_atomic_t exit_flag = 0;
42b528cefcSMark Murray 
43c19800e8SDoug Rabson int detach_from_console = -1;
448373020dSJacques Vidrine 
45b528cefcSMark Murray static RETSIGTYPE
46b528cefcSMark Murray sigterm(int sig)
47b528cefcSMark Murray {
48c19800e8SDoug Rabson     exit_flag = sig;
49b528cefcSMark Murray }
50b528cefcSMark Murray 
51b528cefcSMark Murray int
52b528cefcSMark Murray main(int argc, char **argv)
53b528cefcSMark Murray {
54b528cefcSMark Murray     krb5_error_code ret;
55c19800e8SDoug Rabson     krb5_context context;
56c19800e8SDoug Rabson     krb5_kdc_configuration *config;
57c19800e8SDoug Rabson 
58adb0ddaeSAssar Westerlund     setprogname(argv[0]);
59b528cefcSMark Murray 
605e9cd1aeSAssar Westerlund     ret = krb5_init_context(&context);
61c19800e8SDoug Rabson     if (ret == KRB5_CONFIG_BADFORMAT)
62c19800e8SDoug Rabson 	errx (1, "krb5_init_context failed to parse configuration file");
63c19800e8SDoug Rabson     else if (ret)
645e9cd1aeSAssar Westerlund 	errx (1, "krb5_init_context failed: %d", ret);
65b528cefcSMark Murray 
66c19800e8SDoug Rabson     ret = krb5_kt_register(context, &hdb_kt_ops);
67c19800e8SDoug Rabson     if (ret)
68c19800e8SDoug Rabson 	errx (1, "krb5_kt_register(HDB) failed: %d", ret);
69b528cefcSMark Murray 
70c19800e8SDoug Rabson     config = configure(context, argc, argv);
71b528cefcSMark Murray 
72b528cefcSMark Murray #ifdef HAVE_SIGACTION
73b528cefcSMark Murray     {
74b528cefcSMark Murray 	struct sigaction sa;
75b528cefcSMark Murray 
76b528cefcSMark Murray 	sa.sa_flags = 0;
77b528cefcSMark Murray 	sa.sa_handler = sigterm;
78b528cefcSMark Murray 	sigemptyset(&sa.sa_mask);
79b528cefcSMark Murray 
80b528cefcSMark Murray 	sigaction(SIGINT, &sa, NULL);
815e9cd1aeSAssar Westerlund 	sigaction(SIGTERM, &sa, NULL);
82c19800e8SDoug Rabson 	sigaction(SIGXCPU, &sa, NULL);
83c19800e8SDoug Rabson 
84c19800e8SDoug Rabson 	sa.sa_handler = SIG_IGN;
85c19800e8SDoug Rabson 	sigaction(SIGPIPE, &sa, NULL);
86b528cefcSMark Murray     }
87b528cefcSMark Murray #else
88b528cefcSMark Murray     signal(SIGINT, sigterm);
895e9cd1aeSAssar Westerlund     signal(SIGTERM, sigterm);
90c19800e8SDoug Rabson     signal(SIGXCPU, sigterm);
91c19800e8SDoug Rabson     signal(SIGPIPE, SIG_IGN);
92b528cefcSMark Murray #endif
938373020dSJacques Vidrine     if (detach_from_console)
948373020dSJacques Vidrine 	daemon(0, 0);
955e9cd1aeSAssar Westerlund     pidfile(NULL);
96c19800e8SDoug Rabson     loop(context, config);
97b528cefcSMark Murray     krb5_free_context(context);
98b528cefcSMark Murray     return 0;
99b528cefcSMark Murray }
100