1 /* $NetBSD: main.c,v 1.2 2017/01/28 21:31:44 christos Exp $ */
2
3 /*
4 * Copyright (c) 1997-2002 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
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.
18 *
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.
22 *
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
33 * SUCH DAMAGE.
34 */
35
36 #include "kcm_locl.h"
37
38 __RCSID("$NetBSD: main.c,v 1.2 2017/01/28 21:31:44 christos Exp $");
39
40 krb5_context kcm_context = NULL;
41
42 const char *service_name = "org.h5l.kcm";
43
44 static RETSIGTYPE
sigusr1(int sig)45 sigusr1(int sig)
46 {
47 kcm_debug_ccache(kcm_context);
48 }
49
50 static RETSIGTYPE
sigusr2(int sig)51 sigusr2(int sig)
52 {
53 kcm_debug_events(kcm_context);
54 }
55
56 int
main(int argc,char ** argv)57 main(int argc, char **argv)
58 {
59 krb5_error_code ret;
60 setprogname(argv[0]);
61
62 ret = krb5_init_context(&kcm_context);
63 if (ret) {
64 errx (1, "krb5_init_context failed: %d", ret);
65 return ret;
66 }
67
68 kcm_configure(argc, argv);
69
70 #ifdef HAVE_SIGACTION
71 {
72 struct sigaction sa;
73
74 sa.sa_flags = 0;
75 sa.sa_handler = sigusr1;
76 sigemptyset(&sa.sa_mask);
77
78 sigaction(SIGUSR1, &sa, NULL);
79
80 sa.sa_handler = sigusr2;
81 sigaction(SIGUSR2, &sa, NULL);
82
83 sa.sa_handler = SIG_IGN;
84 sigaction(SIGPIPE, &sa, NULL);
85 }
86 #else
87 signal(SIGUSR1, sigusr1);
88 signal(SIGUSR2, sigusr2);
89 signal(SIGPIPE, SIG_IGN);
90 #endif
91 if (detach_from_console && !launchd_flag && daemon_child == -1)
92 roken_detach_prep(argc, argv, "--daemon-child");
93 rk_pidfile(NULL);
94
95 if (launchd_flag) {
96 heim_sipc mach;
97 heim_sipc_launchd_mach_init(service_name, kcm_service, NULL, &mach);
98 } else {
99 heim_sipc un;
100 heim_sipc_service_unix(service_name, kcm_service, NULL, &un);
101 }
102
103 roken_detach_finish(NULL, daemon_child);
104
105 heim_ipc_main();
106
107 krb5_free_context(kcm_context);
108 return 0;
109 }
110