1 /* $NetBSD: main.c,v 1.11 2009/01/23 11:28:27 tteras Exp $ */
3 /* Id: main.c,v 1.25 2006/06/20 20:31:34 manubsd Exp */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * 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.
17 * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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 <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
41 #include <netinet/in.h>
55 * If we're using a debugging malloc library, this may define our
58 #define RACOON_MAIN_PROGRAM
67 #include "cfparse_proto.h"
68 #include "isakmp_var.h"
69 #include "remoteconf.h"
70 #include "localconf.h"
75 #include "crypto_openssl.h"
79 #include "package_version.h"
81 int dump_config
= 0; /* dump parsed config file. */
82 int f_local
= 0; /* local test mode. behave like a wall. */
83 int vflag
= 1; /* for print-isakmp.c */
84 static int loading_sa
= 0; /* install sa when racoon boots up. */
87 static char version
[] = "@(#)" TOP_PACKAGE_STRING
" (" TOP_PACKAGE_URL
")";
88 #else /* TOP_PACKAGE */
89 static char version
[] = "@(#) racoon / IPsec-tools";
90 #endif /* TOP_PACKAGE */
98 "- %s (http://www.openssl.org/)\n"
103 "- Dead Peer Detection\n"
106 "- IKE fragmentation\n"
109 "- Hybrid authentication\n"
112 "- GSS-API authentication\n"
118 "- Timing statistics\n"
120 #ifdef ENABLE_ADMINPORT
123 #ifdef HAVE_CLOCK_MONOTONIC
124 "- Monotonic clock\n"
127 "- Security context\n"
138 printf("usage: racoon [-BdFv"
142 "] [-f (file)] [-l (file)] [-p (port)] [-P (natt port)]\n"
143 " -B: install SA to the kernel from the file "
144 "specified by the configuration file.\n"
145 " -d: debug level, more -d will generate more debug message.\n"
146 " -C: dump parsed config file.\n"
147 " -L: include location in debug messages\n"
148 " -F: run in foreground, do not become daemon.\n"
149 " -v: be more verbose\n"
150 " -V: print version and exit\n"
155 " -f: pathname for configuration file.\n"
156 " -l: pathname for log file.\n"
157 " -p: port number for isakmp (default: %d).\n"
158 " -P: port number for NAT-T (default: %d).\n"
160 PORT_ISAKMP
, PORT_ISAKMP_NATT
);
176 pname
= strrchr(*av
, '/');
182 while ((c
= getopt(ac
, av
, "dLFp:P:f:l:vVZBC"
198 printf("Foreground mode.\n");
202 lcconf
->port_isakmp
= atoi(optarg
);
205 lcconf
->port_isakmp_natt
= atoi(optarg
);
208 lcconf
->racoon_conf
= optarg
;
222 * To specify -Z option and to choice a appropriate
223 * port number for ISAKMP, you can launch some racoons
224 * on the local host for debug.
225 * pk_sendadd() on initiator side is always failed
226 * even if this flag is used. Because there is same
227 * spi in the SAD which is inserted by pk_sendgetspi()
230 printf("Local test mode.\n");
240 lcconf
->default_af
= AF_INET
;
243 lcconf
->default_af
= AF_INET6
;
276 if (geteuid() != 0) {
277 errx(1, "must be root to invoke this program.");
282 * Don't let anyone read files I write. Although some files (such as
283 * the PID file) can be other readable, we dare to use the global mask,
284 * because racoon uses fopen(3), which can't specify the permission
285 * at the creation time.
288 if (umask(077) != 077) {
289 errx(1, "could not set umask");
293 #ifdef DEBUG_RECORD_MALLOCATION
307 plog(LLV_INFO
, LOCATION
, NULL
, "%s\n", version
);
308 plog(LLV_INFO
, LOCATION
, NULL
, "@(#)"
309 "This product linked %s (http://www.openssl.org/)"
310 "\n", eay_version());
311 plog(LLV_INFO
, LOCATION
, NULL
, "Reading configuration from \"%s\"\n",
312 lcconf
->racoon_conf
);
315 * install SAs from the specified file. If the file is not specified
316 * by the configuration file, racoon will exit.
318 if (loading_sa
&& !f_local
) {
319 if (backupsa_from_file() != 0)
320 errx(1, "something error happened "
327 if (daemon(0, 0) < 0) {
328 errx(1, "failed to be daemon. (%s)",
333 * In case somebody has started inetd manually, we need to
334 * clear the logname, so that old servers run as root do not
335 * get the user's logname..
337 if (setlogin("") < 0) {
338 plog(LLV_ERROR
, LOCATION
, NULL
,
339 "cannot clear logname: %s\n", strerror(errno
));
340 /* no big deal if it fails.. */