1999-07-24 01:17:44 +00:00
|
|
|
/*
|
2017-09-08 13:39:09 -07:00
|
|
|
* Copyright (C) 1999-2017 Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
1999-07-24 01:17:44 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
#include <ctype.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <stdlib.h>
|
2000-06-19 18:55:46 +00:00
|
|
|
#include <string.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
#include <isc/app.h>
|
2009-09-01 18:40:25 +00:00
|
|
|
#include <isc/backtrace.h>
|
1999-10-06 19:59:29 +00:00
|
|
|
#include <isc/commandline.h>
|
2001-06-08 23:52:21 +00:00
|
|
|
#include <isc/dir.h>
|
2000-06-21 22:12:02 +00:00
|
|
|
#include <isc/entropy.h>
|
2001-05-08 19:47:55 +00:00
|
|
|
#include <isc/file.h>
|
2003-07-25 02:22:26 +00:00
|
|
|
#include <isc/hash.h>
|
2016-05-05 11:46:11 +02:00
|
|
|
#include <isc/httpd.h>
|
2000-06-22 01:09:14 +00:00
|
|
|
#include <isc/os.h>
|
2000-12-29 22:31:04 +00:00
|
|
|
#include <isc/platform.h>
|
2008-10-24 01:24:54 +00:00
|
|
|
#include <isc/print.h>
|
2000-11-14 23:59:21 +00:00
|
|
|
#include <isc/resource.h>
|
2001-09-06 02:13:55 +00:00
|
|
|
#include <isc/stdio.h>
|
2004-04-20 06:53:52 +00:00
|
|
|
#include <isc/string.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2001-03-27 00:44:59 +00:00
|
|
|
#include <isccc/result.h>
|
|
|
|
|
2000-05-10 21:34:50 +00:00
|
|
|
#include <dns/dispatch.h>
|
2015-09-28 23:12:35 -07:00
|
|
|
#include <dns/dyndb.h>
|
2003-07-25 02:22:26 +00:00
|
|
|
#include <dns/name.h>
|
2001-03-27 00:44:59 +00:00
|
|
|
#include <dns/result.h>
|
2016-05-05 11:46:11 +02:00
|
|
|
#include <dns/resolver.h>
|
2000-06-16 03:26:55 +00:00
|
|
|
#include <dns/view.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2001-03-27 00:44:59 +00:00
|
|
|
#include <dst/result.h>
|
2014-03-12 20:52:01 -07:00
|
|
|
#ifdef PKCS11CRYPTO
|
|
|
|
#include <pk11/result.h>
|
|
|
|
#endif
|
2001-03-27 00:44:59 +00:00
|
|
|
|
2011-03-10 04:36:16 +00:00
|
|
|
#include <dlz/dlz_dlopen_driver.h>
|
|
|
|
|
2014-10-08 15:14:02 +02:00
|
|
|
#ifdef HAVE_GPERFTOOLS_PROFILER
|
|
|
|
#include <gperftools/profiler.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-12 20:52:01 -07:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
2017-09-08 13:39:09 -07:00
|
|
|
* Defining NAMED_MAIN provides storage declarations (rather than extern)
|
2000-05-08 14:38:29 +00:00
|
|
|
* for variables in named/globals.h.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
#define NAMED_MAIN 1
|
|
|
|
|
|
|
|
#include <ns/interfacemgr.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2001-11-20 01:18:15 +00:00
|
|
|
#include <named/builtin.h>
|
2001-03-27 00:44:59 +00:00
|
|
|
#include <named/control.h>
|
2016-05-05 11:46:11 +02:00
|
|
|
#include <named/fuzz.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <named/globals.h> /* Explicit, though named/log.h includes it. */
|
1999-10-22 19:35:19 +00:00
|
|
|
#include <named/log.h>
|
1999-10-23 01:07:22 +00:00
|
|
|
#include <named/os.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <named/server.h>
|
1999-10-23 01:07:22 +00:00
|
|
|
#include <named/main.h>
|
2014-05-15 20:29:30 -07:00
|
|
|
#include <named/seccomp.h>
|
2005-04-05 00:58:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <named/smf_globals.h>
|
2005-04-05 00:58:16 +00:00
|
|
|
#endif
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2010-12-22 03:59:02 +00:00
|
|
|
#ifdef OPENSSL
|
|
|
|
#include <openssl/opensslv.h>
|
2015-01-22 09:44:24 -08:00
|
|
|
#include <openssl/crypto.h>
|
2010-12-22 03:59:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
#include <libxml/xmlversion.h>
|
|
|
|
#endif
|
2016-03-13 07:48:11 +11:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
#include <zlib.h>
|
|
|
|
#endif
|
2000-11-27 19:12:23 +00:00
|
|
|
/*
|
|
|
|
* Include header files for database drivers here.
|
|
|
|
*/
|
2000-12-06 01:04:45 +00:00
|
|
|
/* #include "xxdb.h" */
|
2000-11-27 19:12:23 +00:00
|
|
|
|
2011-03-10 04:36:16 +00:00
|
|
|
#ifdef CONTRIB_DLZ
|
2005-09-05 00:12:29 +00:00
|
|
|
/*
|
2011-03-10 04:36:16 +00:00
|
|
|
* Include contributed DLZ drivers if appropriate.
|
2005-09-05 00:12:29 +00:00
|
|
|
*/
|
|
|
|
#include <dlz/dlz_drivers.h>
|
|
|
|
#endif
|
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
/*
|
|
|
|
* The maximum number of stack frames to dump on assertion failure.
|
|
|
|
*/
|
|
|
|
#ifndef BACKTRACE_MAXFRAME
|
|
|
|
#define BACKTRACE_MAXFRAME 128
|
|
|
|
#endif
|
|
|
|
|
2016-09-07 14:12:11 +10:00
|
|
|
LIBISC_EXTERNAL_DATA extern int isc_dscp_check_value;
|
|
|
|
LIBDNS_EXTERNAL_DATA extern unsigned int dns_zone_mkey_hour;
|
|
|
|
LIBDNS_EXTERNAL_DATA extern unsigned int dns_zone_mkey_day;
|
|
|
|
LIBDNS_EXTERNAL_DATA extern unsigned int dns_zone_mkey_month;
|
2013-03-22 12:27:54 -07:00
|
|
|
|
2000-06-01 18:49:22 +00:00
|
|
|
static isc_boolean_t want_stats = ISC_FALSE;
|
2001-06-08 23:52:21 +00:00
|
|
|
static char program_name[ISC_DIR_NAMEMAX] = "named";
|
|
|
|
static char absolute_conffile[ISC_DIR_PATHMAX];
|
2004-04-20 06:53:52 +00:00
|
|
|
static char saved_command_line[512];
|
|
|
|
static char version[512];
|
2008-08-20 23:57:59 +00:00
|
|
|
static unsigned int maxsocks = 0;
|
2009-03-05 03:13:55 +00:00
|
|
|
static int maxudp = 0;
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
/*
|
|
|
|
* -T options:
|
|
|
|
*/
|
|
|
|
static isc_boolean_t clienttest = ISC_FALSE;
|
|
|
|
static isc_boolean_t dropedns = ISC_FALSE;
|
|
|
|
static isc_boolean_t noedns = ISC_FALSE;
|
|
|
|
static isc_boolean_t nosoa = ISC_FALSE;
|
|
|
|
static isc_boolean_t noaa = ISC_FALSE;
|
|
|
|
static unsigned int delay = 0;
|
|
|
|
static isc_boolean_t nonearest = ISC_FALSE;
|
|
|
|
static isc_boolean_t notcp = ISC_FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -4 and -6
|
|
|
|
*/
|
|
|
|
static isc_boolean_t disable6 = ISC_FALSE;
|
|
|
|
static isc_boolean_t disable4 = ISC_FALSE;
|
|
|
|
|
2002-05-03 05:28:29 +00:00
|
|
|
void
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlywarning(const char *format, ...) {
|
2001-09-14 12:34:03 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_lctx != NULL) {
|
|
|
|
isc_log_vwrite(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_WARNING,
|
2001-09-14 12:34:03 +00:00
|
|
|
format, args);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s: ", program_name);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
1999-10-23 01:07:22 +00:00
|
|
|
void
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal(const char *format, ...) {
|
1999-07-24 01:17:44 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_lctx != NULL) {
|
|
|
|
isc_log_vwrite(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
1999-10-22 19:35:19 +00:00
|
|
|
format, args);
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
1999-10-23 00:02:23 +00:00
|
|
|
"exiting (due to early fatal error)");
|
1999-10-22 19:35:19 +00:00
|
|
|
} else {
|
1999-10-25 18:58:43 +00:00
|
|
|
fprintf(stderr, "%s: ", program_name);
|
1999-10-22 19:35:19 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
1999-10-23 00:33:04 +00:00
|
|
|
fflush(stderr);
|
1999-10-22 19:35:19 +00:00
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-09-29 15:06:07 +00:00
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
|
|
|
assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
|
|
|
const char *cond) ISC_PLATFORM_NORETURN_POST;
|
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
static void
|
2000-06-01 18:49:22 +00:00
|
|
|
assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
|
|
|
const char *cond)
|
|
|
|
{
|
2009-09-01 18:40:25 +00:00
|
|
|
void *tracebuf[BACKTRACE_MAXFRAME];
|
|
|
|
int i, nframes;
|
|
|
|
isc_result_t result;
|
|
|
|
const char *logsuffix = "";
|
|
|
|
const char *fname;
|
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
/*
|
|
|
|
* Handle assertion failures.
|
|
|
|
*/
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_lctx != NULL) {
|
2000-01-31 15:23:10 +00:00
|
|
|
/*
|
2009-01-17 11:12:10 +00:00
|
|
|
* Reset the assertion callback in case it is the log
|
2000-01-31 15:23:10 +00:00
|
|
|
* routines causing the assertion.
|
|
|
|
*/
|
|
|
|
isc_assertion_setcallback(NULL);
|
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
|
|
|
|
&nframes);
|
|
|
|
if (result == ISC_R_SUCCESS && nframes > 0)
|
|
|
|
logsuffix = ", back trace";
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
2009-09-01 18:40:25 +00:00
|
|
|
"%s:%d: %s(%s) failed%s", file, line,
|
|
|
|
isc_assertion_typetotext(type), cond, logsuffix);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
for (i = 0; i < nframes; i++) {
|
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
fname = NULL;
|
|
|
|
result = isc_backtrace_getsymbol(tracebuf[i],
|
|
|
|
&fname,
|
|
|
|
&offset);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx,
|
|
|
|
NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN,
|
2009-09-01 18:40:25 +00:00
|
|
|
ISC_LOG_CRITICAL,
|
|
|
|
"#%d %p in %s()+0x%lx", i,
|
|
|
|
tracebuf[i], fname,
|
|
|
|
offset);
|
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx,
|
|
|
|
NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN,
|
2009-09-01 18:40:25 +00:00
|
|
|
ISC_LOG_CRITICAL,
|
|
|
|
"#%d %p in ??", i,
|
|
|
|
tracebuf[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
2000-08-17 01:30:31 +00:00
|
|
|
"exiting (due to assertion failure)");
|
1999-10-23 00:33:04 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s:%d: %s(%s) failed\n",
|
|
|
|
file, line, isc_assertion_typetotext(type), cond);
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_coreok)
|
1999-10-23 00:33:04 +00:00
|
|
|
abort();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-09-29 15:06:07 +00:00
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
2001-08-08 22:54:55 +00:00
|
|
|
library_fatal_error(const char *file, int line, const char *format,
|
2009-09-29 15:06:07 +00:00
|
|
|
va_list args)
|
|
|
|
ISC_FORMAT_PRINTF(3, 0) ISC_PLATFORM_NORETURN_POST;
|
2001-08-08 22:54:55 +00:00
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
static void
|
2000-06-01 18:49:22 +00:00
|
|
|
library_fatal_error(const char *file, int line, const char *format,
|
|
|
|
va_list args)
|
|
|
|
{
|
1999-10-23 00:33:04 +00:00
|
|
|
/*
|
|
|
|
* Handle isc_error_fatal() calls from our libraries.
|
|
|
|
*/
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_lctx != NULL) {
|
2000-01-31 15:23:10 +00:00
|
|
|
/*
|
|
|
|
* Reset the error callback in case it is the log
|
|
|
|
* routines causing the assertion.
|
|
|
|
*/
|
|
|
|
isc_error_setfatal(NULL);
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
2000-02-14 19:40:36 +00:00
|
|
|
"%s:%d: fatal error:", file, line);
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_vwrite(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
1999-10-23 00:33:04 +00:00
|
|
|
format, args);
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
1999-10-23 00:33:04 +00:00
|
|
|
"exiting (due to fatal error in library)");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s:%d: fatal error: ", file, line);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_coreok)
|
1999-10-23 00:33:04 +00:00
|
|
|
abort();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-08-08 22:54:55 +00:00
|
|
|
static void
|
|
|
|
library_unexpected_error(const char *file, int line, const char *format,
|
|
|
|
va_list args) ISC_FORMAT_PRINTF(3, 0);
|
|
|
|
|
2000-02-14 19:40:36 +00:00
|
|
|
static void
|
2000-06-01 18:49:22 +00:00
|
|
|
library_unexpected_error(const char *file, int line, const char *format,
|
|
|
|
va_list args)
|
|
|
|
{
|
2000-02-14 19:40:36 +00:00
|
|
|
/*
|
|
|
|
* Handle isc_error_unexpected() calls from our libraries.
|
|
|
|
*/
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_lctx != NULL) {
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_ERROR,
|
2000-02-14 19:40:36 +00:00
|
|
|
"%s:%d: unexpected error:", file, line);
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_vwrite(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_ERROR,
|
2000-02-14 19:40:36 +00:00
|
|
|
format, args);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s:%d: fatal error: ", file, line);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
static void
|
|
|
|
usage(void) {
|
|
|
|
fprintf(stderr,
|
2004-03-16 05:52:24 +00:00
|
|
|
"usage: named [-4|-6] [-c conffile] [-d debuglevel] "
|
2009-10-05 17:30:49 +00:00
|
|
|
"[-E engine] [-f|-g]\n"
|
|
|
|
" [-n number_of_cpus] [-p port] [-s] "
|
2016-02-23 16:57:02 +11:00
|
|
|
"[-S sockets] [-t chrootdir]\n"
|
|
|
|
" [-u username] [-U listeners] "
|
|
|
|
"[-m {usage|trace|record|size|mctx}]\n"
|
|
|
|
"usage: named [-v|-V]\n");
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
static void
|
|
|
|
save_command_line(int argc, char *argv[]) {
|
|
|
|
int i;
|
|
|
|
char *src;
|
|
|
|
char *dst;
|
|
|
|
char *eob;
|
|
|
|
const char truncated[] = "...";
|
|
|
|
isc_boolean_t quoted = ISC_FALSE;
|
|
|
|
|
|
|
|
dst = saved_command_line;
|
|
|
|
eob = saved_command_line + sizeof(saved_command_line);
|
|
|
|
|
|
|
|
for (i = 1; i < argc && dst < eob; i++) {
|
|
|
|
*dst++ = ' ';
|
|
|
|
|
|
|
|
src = argv[i];
|
|
|
|
while (*src != '\0' && dst < eob) {
|
|
|
|
/*
|
|
|
|
* This won't perfectly produce a shell-independent
|
|
|
|
* pastable command line in all circumstances, but
|
|
|
|
* comes close, and for practical purposes will
|
|
|
|
* nearly always be fine.
|
|
|
|
*/
|
|
|
|
if (quoted || isalnum(*src & 0xff) ||
|
|
|
|
*src == '-' || *src == '_' ||
|
|
|
|
*src == '.' || *src == '/') {
|
|
|
|
*dst++ = *src++;
|
|
|
|
quoted = ISC_FALSE;
|
|
|
|
} else {
|
|
|
|
*dst++ = '\\';
|
|
|
|
quoted = ISC_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSIST(sizeof(saved_command_line) >= sizeof(truncated));
|
|
|
|
|
|
|
|
if (dst == eob)
|
|
|
|
strcpy(eob - sizeof(truncated), truncated);
|
|
|
|
else
|
|
|
|
*dst = '\0';
|
|
|
|
}
|
|
|
|
|
2000-09-28 21:09:51 +00:00
|
|
|
static int
|
|
|
|
parse_int(char *arg, const char *desc) {
|
|
|
|
char *endp;
|
|
|
|
int tmp;
|
|
|
|
long int ltmp;
|
|
|
|
|
2000-09-28 21:21:31 +00:00
|
|
|
ltmp = strtol(arg, &endp, 10);
|
2000-09-28 21:09:51 +00:00
|
|
|
tmp = (int) ltmp;
|
|
|
|
if (*endp != '\0')
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("%s '%s' must be numeric", desc, arg);
|
2000-09-28 21:09:51 +00:00
|
|
|
if (tmp < 0 || tmp != ltmp)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("%s '%s' out of range", desc, arg);
|
2000-09-28 21:09:51 +00:00
|
|
|
return (tmp);
|
|
|
|
}
|
|
|
|
|
2001-09-07 00:17:25 +00:00
|
|
|
static struct flag_def {
|
|
|
|
const char *name;
|
|
|
|
unsigned int value;
|
|
|
|
} mem_debug_flags[] = {
|
2015-02-25 09:06:45 +05:30
|
|
|
{ "none", 0},
|
2001-09-07 00:17:25 +00:00
|
|
|
{ "trace", ISC_MEM_DEBUGTRACE },
|
|
|
|
{ "record", ISC_MEM_DEBUGRECORD },
|
2001-10-25 01:07:45 +00:00
|
|
|
{ "usage", ISC_MEM_DEBUGUSAGE },
|
2005-06-10 07:00:20 +00:00
|
|
|
{ "size", ISC_MEM_DEBUGSIZE },
|
|
|
|
{ "mctx", ISC_MEM_DEBUGCTX },
|
2001-09-07 00:17:25 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
|
2015-02-25 09:06:45 +05:30
|
|
|
isc_boolean_t clear = ISC_FALSE;
|
|
|
|
|
2001-09-07 00:17:25 +00:00
|
|
|
for (;;) {
|
|
|
|
const struct flag_def *def;
|
|
|
|
const char *end = strchr(arg, ',');
|
2004-07-01 02:03:54 +00:00
|
|
|
int arglen;
|
2001-09-07 00:17:25 +00:00
|
|
|
if (end == NULL)
|
|
|
|
end = arg + strlen(arg);
|
2013-12-04 12:47:23 +11:00
|
|
|
arglen = (int)(end - arg);
|
2001-09-07 00:17:25 +00:00
|
|
|
for (def = defs; def->name != NULL; def++) {
|
2004-07-01 02:03:54 +00:00
|
|
|
if (arglen == (int)strlen(def->name) &&
|
|
|
|
memcmp(arg, def->name, arglen) == 0) {
|
2015-02-25 09:06:45 +05:30
|
|
|
if (def->value == 0)
|
|
|
|
clear = ISC_TRUE;
|
2001-09-07 00:17:25 +00:00
|
|
|
*ret |= def->value;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
|
2001-09-07 00:17:25 +00:00
|
|
|
found:
|
2015-02-25 09:06:45 +05:30
|
|
|
if (clear || (*end == '\0'))
|
2001-09-07 00:17:25 +00:00
|
|
|
break;
|
|
|
|
arg = end + 1;
|
|
|
|
}
|
2015-02-25 09:06:45 +05:30
|
|
|
|
|
|
|
if (clear)
|
|
|
|
*ret = 0;
|
2001-09-07 00:17:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 11:46:11 +02:00
|
|
|
static void
|
|
|
|
parse_fuzz_arg(void) {
|
|
|
|
if (!strncmp(isc_commandline_argument, "client:", 7)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_fuzz_addr = isc_commandline_argument + 7;
|
|
|
|
named_g_fuzz_type = isc_fuzz_client;
|
2016-05-05 11:46:11 +02:00
|
|
|
} else if (!strncmp(isc_commandline_argument, "tcp:", 4)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_fuzz_addr = isc_commandline_argument + 4;
|
|
|
|
named_g_fuzz_type = isc_fuzz_tcpclient;
|
2016-05-05 11:46:11 +02:00
|
|
|
} else if (!strncmp(isc_commandline_argument, "resolver:", 9)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_fuzz_addr = isc_commandline_argument + 9;
|
|
|
|
named_g_fuzz_type = isc_fuzz_resolver;
|
2016-05-05 11:46:11 +02:00
|
|
|
} else if (!strncmp(isc_commandline_argument, "http:", 5)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_fuzz_addr = isc_commandline_argument + 5;
|
|
|
|
named_g_fuzz_type = isc_fuzz_http;
|
2016-05-05 11:46:11 +02:00
|
|
|
} else if (!strncmp(isc_commandline_argument, "rndc:", 5)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_fuzz_addr = isc_commandline_argument + 5;
|
|
|
|
named_g_fuzz_type = isc_fuzz_rndc;
|
2016-05-05 11:46:11 +02:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("unknown fuzzing type '%s'",
|
2016-05-05 11:46:11 +02:00
|
|
|
isc_commandline_argument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
static void
|
1999-07-24 01:17:44 +00:00
|
|
|
parse_command_line(int argc, char *argv[]) {
|
|
|
|
int ch;
|
2000-09-28 21:09:51 +00:00
|
|
|
int port;
|
2014-04-03 19:34:48 -07:00
|
|
|
const char *p;
|
2000-06-19 18:55:46 +00:00
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
save_command_line(argc, argv);
|
|
|
|
|
2015-02-25 09:06:45 +05:30
|
|
|
/*
|
2017-09-08 13:39:09 -07:00
|
|
|
* NAMED_MAIN_ARGS is defined in main.h, so that it can be used
|
2015-02-25 09:06:45 +05:30
|
|
|
* both by named and by ntservice hooks.
|
|
|
|
*/
|
1999-10-25 18:58:43 +00:00
|
|
|
isc_commandline_errprint = ISC_FALSE;
|
2017-09-08 13:39:09 -07:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv,
|
|
|
|
NAMED_MAIN_ARGS)) != -1)
|
|
|
|
{
|
1999-07-24 01:17:44 +00:00
|
|
|
switch (ch) {
|
2003-01-16 03:59:28 +00:00
|
|
|
case '4':
|
2017-09-08 13:39:09 -07:00
|
|
|
if (disable4)
|
|
|
|
named_main_earlyfatal("cannot specify "
|
|
|
|
"-4 and -6");
|
2003-01-16 03:59:28 +00:00
|
|
|
if (isc_net_probeipv4() != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("IPv4 not supported "
|
|
|
|
"by OS");
|
2003-01-16 03:59:28 +00:00
|
|
|
isc_net_disableipv6();
|
2017-09-08 13:39:09 -07:00
|
|
|
disable6 = ISC_TRUE;
|
2003-01-16 03:59:28 +00:00
|
|
|
break;
|
|
|
|
case '6':
|
2017-09-08 13:39:09 -07:00
|
|
|
if (disable6)
|
|
|
|
named_main_earlyfatal("cannot specify "
|
|
|
|
"-4 and -6");
|
2003-01-16 03:59:28 +00:00
|
|
|
if (isc_net_probeipv6() != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("IPv6 not supported "
|
|
|
|
"by OS");
|
2003-01-16 03:59:28 +00:00
|
|
|
isc_net_disableipv4();
|
2017-09-08 13:39:09 -07:00
|
|
|
disable4 = ISC_TRUE;
|
2003-01-16 03:59:28 +00:00
|
|
|
break;
|
2016-05-05 11:46:11 +02:00
|
|
|
case 'A':
|
|
|
|
parse_fuzz_arg();
|
|
|
|
break;
|
1999-07-24 01:17:44 +00:00
|
|
|
case 'c':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_conffile = isc_commandline_argument;
|
|
|
|
named_g_conffileset = ISC_TRUE;
|
1999-07-24 01:17:44 +00:00
|
|
|
break;
|
1999-10-23 00:02:23 +00:00
|
|
|
case 'd':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_debuglevel = parse_int(isc_commandline_argument,
|
|
|
|
"debug level");
|
1999-10-23 00:02:23 +00:00
|
|
|
break;
|
2013-06-12 11:31:30 +10:00
|
|
|
case 'D':
|
|
|
|
/* Descriptive comment for 'ps'. */
|
|
|
|
break;
|
2009-10-05 17:30:49 +00:00
|
|
|
case 'E':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_engine = isc_commandline_argument;
|
2009-10-05 17:30:49 +00:00
|
|
|
break;
|
2000-01-26 17:35:16 +00:00
|
|
|
case 'f':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_foreground = ISC_TRUE;
|
2000-01-26 17:35:16 +00:00
|
|
|
break;
|
2000-02-29 18:37:14 +00:00
|
|
|
case 'g':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_foreground = ISC_TRUE;
|
|
|
|
named_g_logstderr = ISC_TRUE;
|
2000-10-04 23:19:01 +00:00
|
|
|
break;
|
2014-04-29 17:17:03 -07:00
|
|
|
case 'L':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_logfile = isc_commandline_argument;
|
2014-04-29 17:17:03 -07:00
|
|
|
break;
|
2015-02-25 09:06:45 +05:30
|
|
|
case 'M':
|
|
|
|
if (strcmp(isc_commandline_argument, "external") == 0)
|
|
|
|
isc_mem_defaultflags = 0;
|
|
|
|
break;
|
2001-09-07 00:17:25 +00:00
|
|
|
case 'm':
|
|
|
|
set_flags(isc_commandline_argument, mem_debug_flags,
|
|
|
|
&isc_mem_debugging);
|
|
|
|
break;
|
2000-02-28 22:19:47 +00:00
|
|
|
case 'N': /* Deprecated. */
|
|
|
|
case 'n':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_cpus = parse_int(isc_commandline_argument,
|
2000-09-28 21:09:51 +00:00
|
|
|
"number of cpus");
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_cpus == 0)
|
|
|
|
named_g_cpus = 1;
|
1999-07-24 01:17:44 +00:00
|
|
|
break;
|
1999-09-09 02:19:11 +00:00
|
|
|
case 'p':
|
2000-09-28 21:09:51 +00:00
|
|
|
port = parse_int(isc_commandline_argument, "port");
|
2000-01-31 15:23:10 +00:00
|
|
|
if (port < 1 || port > 65535)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("port '%s' out of range",
|
2000-01-31 15:23:10 +00:00
|
|
|
isc_commandline_argument);
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_port = port;
|
2000-10-04 23:19:01 +00:00
|
|
|
break;
|
1999-07-24 01:17:44 +00:00
|
|
|
case 's':
|
|
|
|
/* XXXRTH temporary syntax */
|
|
|
|
want_stats = ISC_TRUE;
|
|
|
|
break;
|
2008-08-20 23:57:59 +00:00
|
|
|
case 'S':
|
|
|
|
maxsocks = parse_int(isc_commandline_argument,
|
|
|
|
"max number of sockets");
|
|
|
|
break;
|
2000-01-26 17:35:16 +00:00
|
|
|
case 't':
|
2000-01-28 20:10:26 +00:00
|
|
|
/* XXXJAB should we make a copy? */
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_chrootdir = isc_commandline_argument;
|
2000-01-26 17:35:16 +00:00
|
|
|
break;
|
2010-06-26 00:20:33 +00:00
|
|
|
case 'T': /* NOT DOCUMENTED */
|
2008-01-02 05:03:07 +00:00
|
|
|
/*
|
2013-03-22 12:27:54 -07:00
|
|
|
* force the server to behave (or misbehave) in
|
|
|
|
* specified ways for testing purposes.
|
|
|
|
*
|
2008-01-02 05:03:07 +00:00
|
|
|
* clienttest: make clients single shot with their
|
|
|
|
* own memory context.
|
2012-09-29 13:07:09 +10:00
|
|
|
* delay=xxxx: delay client responses by xxxx ms to
|
|
|
|
* simulate remote servers.
|
2013-03-22 12:27:54 -07:00
|
|
|
* dscp=x: check that dscp values are as
|
|
|
|
* expected and assert otherwise.
|
2008-01-02 05:03:07 +00:00
|
|
|
*/
|
2009-03-05 03:13:55 +00:00
|
|
|
if (!strcmp(isc_commandline_argument, "clienttest"))
|
2017-09-08 13:39:09 -07:00
|
|
|
clienttest = ISC_TRUE;
|
2010-06-25 23:50:13 +00:00
|
|
|
else if (!strcmp(isc_commandline_argument, "nosoa"))
|
2017-09-08 13:39:09 -07:00
|
|
|
nosoa = ISC_TRUE;
|
2010-09-15 12:07:56 +00:00
|
|
|
else if (!strcmp(isc_commandline_argument, "noaa"))
|
2017-09-08 13:39:09 -07:00
|
|
|
noaa = ISC_TRUE;
|
|
|
|
else if (!strcmp(isc_commandline_argument,
|
|
|
|
"maxudp512"))
|
2009-03-05 03:13:55 +00:00
|
|
|
maxudp = 512;
|
2017-09-08 13:39:09 -07:00
|
|
|
else if (!strcmp(isc_commandline_argument,
|
|
|
|
"maxudp1460"))
|
2009-03-05 03:13:55 +00:00
|
|
|
maxudp = 1460;
|
2012-10-16 10:23:08 +11:00
|
|
|
else if (!strcmp(isc_commandline_argument, "dropedns"))
|
2017-09-08 13:39:09 -07:00
|
|
|
dropedns = ISC_TRUE;
|
2012-10-16 10:23:08 +11:00
|
|
|
else if (!strcmp(isc_commandline_argument, "noedns"))
|
2017-09-08 13:39:09 -07:00
|
|
|
noedns = ISC_TRUE;
|
2012-10-16 10:23:08 +11:00
|
|
|
else if (!strncmp(isc_commandline_argument,
|
|
|
|
"maxudp=", 7))
|
|
|
|
maxudp = atoi(isc_commandline_argument + 7);
|
2012-09-29 13:07:09 +10:00
|
|
|
else if (!strncmp(isc_commandline_argument,
|
|
|
|
"delay=", 6))
|
2017-09-08 13:39:09 -07:00
|
|
|
delay = atoi(isc_commandline_argument + 6);
|
2013-01-06 07:56:10 +11:00
|
|
|
else if (!strcmp(isc_commandline_argument, "nosyslog"))
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_nosyslog = ISC_TRUE;
|
2013-01-10 23:09:08 +11:00
|
|
|
else if (!strcmp(isc_commandline_argument, "nonearest"))
|
2017-09-08 13:39:09 -07:00
|
|
|
nonearest = ISC_TRUE;
|
2013-03-22 12:27:54 -07:00
|
|
|
else if (!strncmp(isc_commandline_argument, "dscp=", 5))
|
|
|
|
isc_dscp_check_value =
|
|
|
|
atoi(isc_commandline_argument + 5);
|
2015-02-05 17:18:15 -08:00
|
|
|
else if (!strncmp(isc_commandline_argument,
|
|
|
|
"mkeytimers=", 11))
|
|
|
|
{
|
|
|
|
p = strtok(isc_commandline_argument + 11, "/");
|
|
|
|
if (p == NULL)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
2015-02-05 17:18:15 -08:00
|
|
|
dns_zone_mkey_hour = atoi(p);
|
|
|
|
if (dns_zone_mkey_hour == 0)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
2015-02-05 17:18:15 -08:00
|
|
|
|
|
|
|
p = strtok(NULL, "/");
|
|
|
|
if (p == NULL) {
|
|
|
|
dns_zone_mkey_day =
|
|
|
|
(24 * dns_zone_mkey_hour);
|
|
|
|
dns_zone_mkey_month =
|
|
|
|
(30 * dns_zone_mkey_day);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dns_zone_mkey_day = atoi(p);
|
|
|
|
if (dns_zone_mkey_day < dns_zone_mkey_hour)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
2015-02-05 17:18:15 -08:00
|
|
|
|
|
|
|
p = strtok(NULL, "/");
|
|
|
|
if (p == NULL) {
|
|
|
|
dns_zone_mkey_month =
|
|
|
|
(30 * dns_zone_mkey_day);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dns_zone_mkey_month = atoi(p);
|
|
|
|
if (dns_zone_mkey_month < dns_zone_mkey_day)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
2015-02-05 17:18:15 -08:00
|
|
|
} else if (!strcmp(isc_commandline_argument, "notcp"))
|
2017-09-08 13:39:09 -07:00
|
|
|
notcp = ISC_TRUE;
|
2016-07-22 20:02:17 +10:00
|
|
|
else if (!strncmp(isc_commandline_argument, "tat=", 4))
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_tat_interval =
|
2016-07-22 20:02:17 +10:00
|
|
|
atoi(isc_commandline_argument + 4);
|
2016-12-05 10:38:16 +11:00
|
|
|
else if (!strcmp(isc_commandline_argument,
|
|
|
|
"keepstderr"))
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_keepstderr = ISC_TRUE;
|
2008-01-02 05:03:07 +00:00
|
|
|
else
|
|
|
|
fprintf(stderr, "unknown -T flag '%s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
break;
|
2011-11-09 18:44:04 +00:00
|
|
|
case 'U':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_udpdisp = parse_int(isc_commandline_argument,
|
|
|
|
"number of UDP listeners "
|
|
|
|
"per interface");
|
2011-11-09 18:44:04 +00:00
|
|
|
break;
|
2000-01-28 20:10:26 +00:00
|
|
|
case 'u':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_username = isc_commandline_argument;
|
2000-01-28 20:10:26 +00:00
|
|
|
break;
|
2000-08-30 20:40:04 +00:00
|
|
|
case 'v':
|
2015-02-26 11:53:11 -08:00
|
|
|
printf("%s %s%s%s <id:%s>\n",
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_product, named_g_version,
|
|
|
|
(*named_g_description != '\0') ? " " : "",
|
|
|
|
named_g_description, named_g_srcid);
|
2000-08-30 20:40:04 +00:00
|
|
|
exit(0);
|
2008-09-23 17:25:47 +00:00
|
|
|
case 'V':
|
2017-09-08 13:39:09 -07:00
|
|
|
printf("%s %s%s%s <id:%s>\n",
|
|
|
|
named_g_product, named_g_version,
|
|
|
|
(*named_g_description != '\0') ? " " : "",
|
|
|
|
named_g_description, named_g_srcid);
|
|
|
|
printf("running on %s\n", named_os_uname());
|
2015-02-26 11:53:11 -08:00
|
|
|
printf("built by %s with %s\n",
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_builder, named_g_configargs);
|
2013-12-04 12:47:23 +11:00
|
|
|
#ifdef __clang__
|
|
|
|
printf("compiled by CLANG %s\n", __VERSION__);
|
|
|
|
#else
|
|
|
|
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
|
|
|
printf("compiled by ICC %s\n", __VERSION__);
|
|
|
|
#else
|
|
|
|
#ifdef __GNUC__
|
|
|
|
printf("compiled by GCC %s\n", __VERSION__);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
printf("compiled by MSVC %d\n", _MSC_VER);
|
|
|
|
#endif
|
|
|
|
#ifdef __SUNPRO_C
|
|
|
|
printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
|
|
|
|
#endif
|
2010-12-22 03:59:02 +00:00
|
|
|
#ifdef OPENSSL
|
2015-01-22 09:44:24 -08:00
|
|
|
printf("compiled with OpenSSL version: %s\n",
|
2010-12-22 03:59:02 +00:00
|
|
|
OPENSSL_VERSION_TEXT);
|
2016-11-01 12:48:53 +11:00
|
|
|
#if !defined(LIBRESSL_VERSION_NUMBER) && \
|
|
|
|
OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 or higher */
|
2016-10-31 10:04:37 +11:00
|
|
|
printf("linked to OpenSSL version: %s\n",
|
|
|
|
OpenSSL_version(OPENSSL_VERSION));
|
|
|
|
|
|
|
|
#else
|
2015-01-22 09:44:24 -08:00
|
|
|
printf("linked to OpenSSL version: %s\n",
|
|
|
|
SSLeay_version(SSLEAY_VERSION));
|
2016-10-31 10:04:37 +11:00
|
|
|
#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
|
2010-12-22 03:59:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBXML2
|
2015-01-22 09:44:24 -08:00
|
|
|
printf("compiled with libxml2 version: %s\n",
|
2010-12-22 03:59:02 +00:00
|
|
|
LIBXML_DOTTED_VERSION);
|
2015-01-22 09:44:24 -08:00
|
|
|
printf("linked to libxml2 version: %s\n",
|
|
|
|
xmlParserVersion);
|
2015-02-26 11:53:11 -08:00
|
|
|
#endif
|
2015-10-29 15:22:41 +11:00
|
|
|
#if defined(HAVE_JSON) && defined(JSON_C_VERSION)
|
2015-02-26 11:53:11 -08:00
|
|
|
printf("compiled with libjson-c version: %s\n",
|
|
|
|
JSON_C_VERSION);
|
|
|
|
printf("linked to libjson-c version: %s\n",
|
|
|
|
json_c_version());
|
2015-03-04 15:56:33 -08:00
|
|
|
#endif
|
2016-03-13 07:48:11 +11:00
|
|
|
#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
|
|
|
|
printf("compiled with zlib version: %s\n",
|
|
|
|
ZLIB_VERSION);
|
|
|
|
printf("linked to zlib version: %s\n",
|
|
|
|
zlibVersion());
|
|
|
|
#endif
|
2015-03-04 15:56:33 -08:00
|
|
|
#ifdef ISC_PLATFORM_USETHREADS
|
|
|
|
printf("threads support is enabled\n");
|
|
|
|
#else
|
|
|
|
printf("threads support is disabled\n");
|
2010-12-22 03:59:02 +00:00
|
|
|
#endif
|
2008-09-23 17:25:47 +00:00
|
|
|
exit(0);
|
2014-12-18 11:58:50 +05:30
|
|
|
case 'x':
|
|
|
|
/* Obsolete. No longer in use. Ignore. */
|
|
|
|
break;
|
|
|
|
case 'X':
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_forcelock = ISC_TRUE;
|
2015-03-02 19:27:54 -08:00
|
|
|
if (strcasecmp(isc_commandline_argument, "none") != 0)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_defaultlockfile =
|
|
|
|
isc_commandline_argument;
|
2015-03-02 19:27:54 -08:00
|
|
|
else
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_defaultlockfile = NULL;
|
2014-12-18 11:58:50 +05:30
|
|
|
break;
|
2009-05-07 09:33:52 +00:00
|
|
|
case 'F':
|
|
|
|
/* Reserved for FIPS mode */
|
|
|
|
/* FALLTHROUGH */
|
1999-10-25 18:58:43 +00:00
|
|
|
case '?':
|
2000-02-17 19:21:00 +00:00
|
|
|
usage();
|
2007-05-21 02:47:25 +00:00
|
|
|
if (isc_commandline_option == '?')
|
|
|
|
exit(0);
|
2017-09-08 13:39:09 -07:00
|
|
|
p = strchr(NAMED_MAIN_ARGS, isc_commandline_option);
|
2014-04-03 19:34:48 -07:00
|
|
|
if (p == NULL || *++p != ':')
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("unknown option '-%c'",
|
2014-04-03 19:34:48 -07:00
|
|
|
isc_commandline_option);
|
|
|
|
else
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("option '-%c' requires "
|
2014-04-03 19:34:48 -07:00
|
|
|
"an argument",
|
|
|
|
isc_commandline_option);
|
2009-05-07 09:33:52 +00:00
|
|
|
/* FALLTHROUGH */
|
1999-07-24 01:17:44 +00:00
|
|
|
default:
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("parsing options returned %d",
|
|
|
|
ch);
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-06 19:59:29 +00:00
|
|
|
argc -= isc_commandline_index;
|
|
|
|
argv += isc_commandline_index;
|
2011-03-11 06:11:27 +00:00
|
|
|
POST(argv);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-02-17 19:21:00 +00:00
|
|
|
if (argc > 0) {
|
1999-07-24 01:17:44 +00:00
|
|
|
usage();
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("extra command line arguments");
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2000-05-14 13:47:17 +00:00
|
|
|
create_managers(void) {
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_t result;
|
2008-08-20 23:57:59 +00:00
|
|
|
unsigned int socks;
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
INSIST(named_g_cpus_detected > 0);
|
2015-10-03 07:06:49 +05:30
|
|
|
|
2000-12-29 22:31:04 +00:00
|
|
|
#ifdef ISC_PLATFORM_USETHREADS
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_cpus == 0)
|
|
|
|
named_g_cpus = named_g_cpus_detected;
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
|
|
|
"found %u CPU%s, using %u worker thread%s",
|
|
|
|
named_g_cpus_detected,
|
|
|
|
named_g_cpus_detected == 1 ? "" : "s",
|
|
|
|
named_g_cpus, named_g_cpus == 1 ? "" : "s");
|
2000-12-29 22:31:04 +00:00
|
|
|
#else
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_cpus = 1;
|
2000-12-29 22:31:04 +00:00
|
|
|
#endif
|
2012-02-06 04:19:33 +00:00
|
|
|
#ifdef WIN32
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_udpdisp = 1;
|
2012-02-06 04:19:33 +00:00
|
|
|
#else
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_udpdisp == 0) {
|
|
|
|
if (named_g_cpus_detected == 1)
|
|
|
|
named_g_udpdisp = 1;
|
2014-02-19 21:54:43 -08:00
|
|
|
else
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_udpdisp = named_g_cpus_detected - 1;
|
2014-02-19 21:54:43 -08:00
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_udpdisp > named_g_cpus)
|
|
|
|
named_g_udpdisp = named_g_cpus;
|
2012-02-06 04:19:33 +00:00
|
|
|
#endif
|
2015-03-04 15:56:33 -08:00
|
|
|
#ifdef ISC_PLATFORM_USETHREADS
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
|
|
|
"using %u UDP listener%s per interface",
|
|
|
|
named_g_udpdisp, named_g_udpdisp == 1 ? "" : "s");
|
2015-03-04 15:56:33 -08:00
|
|
|
#endif
|
2011-11-09 18:44:04 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_taskmgr_create(named_g_mctx, named_g_cpus, 0,
|
|
|
|
&named_g_taskmgr);
|
1999-07-24 01:17:44 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2006-01-05 01:37:19 +00:00
|
|
|
"isc_taskmgr_create() failed: %s",
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_timermgr_create(named_g_mctx, &named_g_timermgr);
|
1999-07-24 01:17:44 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2006-01-05 01:37:19 +00:00
|
|
|
"isc_timermgr_create() failed: %s",
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_socketmgr_create2(named_g_mctx, &named_g_socketmgr,
|
|
|
|
maxsocks);
|
1999-07-24 01:17:44 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-02-17 19:58:59 +00:00
|
|
|
"isc_socketmgr_create() failed: %s",
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
isc__socketmgr_maxudp(named_g_socketmgr, maxudp);
|
|
|
|
result = isc_socketmgr_getmaxsockets(named_g_socketmgr, &socks);
|
2008-08-20 23:57:59 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_SERVER,
|
2008-08-20 23:57:59 +00:00
|
|
|
ISC_LOG_INFO, "using up to %u sockets", socks);
|
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_entropy_create(named_g_mctx, &named_g_entropy);
|
2000-06-16 01:39:02 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-06-21 22:12:02 +00:00
|
|
|
"isc_entropy_create() failed: %s",
|
2000-06-16 01:39:02 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_hash_create(named_g_mctx, named_g_entropy,
|
|
|
|
DNS_NAME_MAXWIRE);
|
2003-07-25 02:22:26 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_hash_create() failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_managers(void) {
|
|
|
|
/*
|
2001-03-29 04:23:51 +00:00
|
|
|
* isc_taskmgr_destroy() will block until all tasks have exited,
|
1999-07-24 01:17:44 +00:00
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_taskmgr_destroy(&named_g_taskmgr);
|
|
|
|
isc_timermgr_destroy(&named_g_timermgr);
|
|
|
|
isc_socketmgr_destroy(&named_g_socketmgr);
|
2003-09-24 23:20:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* isc_hash_destroy() cannot be called as long as a resolver may be
|
|
|
|
* running. Calling this after isc_taskmgr_destroy() ensures the
|
|
|
|
* call is safe.
|
|
|
|
*/
|
|
|
|
isc_hash_destroy();
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
static void
|
2014-03-04 10:42:25 -08:00
|
|
|
dump_symboltable(void) {
|
2009-09-01 18:40:25 +00:00
|
|
|
int i;
|
|
|
|
isc_result_t result;
|
|
|
|
const char *fname;
|
|
|
|
const void *addr;
|
|
|
|
|
|
|
|
if (isc__backtrace_nsymbols == 0)
|
|
|
|
return;
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (!isc_log_wouldlog(named_g_lctx, ISC_LOG_DEBUG(99)))
|
2009-09-01 18:40:25 +00:00
|
|
|
return;
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_DEBUG(99),
|
|
|
|
"Symbol table:");
|
2009-09-01 18:40:25 +00:00
|
|
|
|
|
|
|
for (i = 0, result = ISC_R_SUCCESS; result == ISC_R_SUCCESS; i++) {
|
|
|
|
addr = NULL;
|
|
|
|
fname = NULL;
|
|
|
|
result = isc_backtrace_getsymbolfromindex(i, &addr, &fname);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_DEBUG(99),
|
2009-09-01 18:40:25 +00:00
|
|
|
"[%d] %p %s", i, addr, fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 20:29:30 -07:00
|
|
|
#ifdef HAVE_LIBSECCOMP
|
|
|
|
static void
|
|
|
|
setup_seccomp() {
|
|
|
|
scmp_filter_ctx ctx;
|
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Make sure the lists are in sync */
|
|
|
|
INSIST((sizeof(scmp_syscalls) / sizeof(int)) ==
|
|
|
|
(sizeof(scmp_syscall_names) / sizeof(const char *)));
|
|
|
|
|
|
|
|
ctx = seccomp_init(SCMP_ACT_KILL);
|
|
|
|
if (ctx == NULL) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_WARNING,
|
2014-05-15 20:29:30 -07:00
|
|
|
"libseccomp activation failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < sizeof(scmp_syscalls)/sizeof(*(scmp_syscalls)); i++) {
|
|
|
|
ret = seccomp_rule_add(ctx, SCMP_ACT_ALLOW,
|
|
|
|
scmp_syscalls[i], 0);
|
|
|
|
if (ret < 0)
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_WARNING,
|
2014-05-15 20:29:30 -07:00
|
|
|
"libseccomp rule failed: %s",
|
|
|
|
scmp_syscall_names[i]);
|
|
|
|
|
|
|
|
else
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_DEBUG(9),
|
2014-05-15 20:29:30 -07:00
|
|
|
"added libseccomp rule: %s",
|
|
|
|
scmp_syscall_names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = seccomp_load(ctx);
|
|
|
|
if (ret < 0) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_WARNING,
|
2014-05-15 20:29:30 -07:00
|
|
|
"libseccomp unable to load filter");
|
2014-06-16 11:19:40 -07:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2014-06-16 11:19:40 -07:00
|
|
|
"libseccomp sandboxing active");
|
2014-05-15 20:29:30 -07:00
|
|
|
}
|
|
|
|
|
2014-06-16 11:19:40 -07:00
|
|
|
/*
|
|
|
|
* Release filter in ctx. Filters already loaded are not
|
|
|
|
* affected.
|
|
|
|
*/
|
|
|
|
seccomp_release(ctx);
|
2014-05-15 20:29:30 -07:00
|
|
|
}
|
|
|
|
#endif /* HAVE_LIBSECCOMP */
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
static void
|
2000-05-14 13:47:17 +00:00
|
|
|
setup(void) {
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_t result;
|
2008-10-24 01:24:54 +00:00
|
|
|
isc_resourcevalue_t old_openfiles;
|
2017-09-08 13:39:09 -07:00
|
|
|
ns_server_t *sctx;
|
2005-04-05 00:58:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
|
|
|
char *instance = NULL;
|
|
|
|
#endif
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-07-01 00:48:06 +00:00
|
|
|
/*
|
|
|
|
* Get the user and group information before changing the root
|
|
|
|
* directory, so the administrator does not need to keep a copy
|
|
|
|
* of the user and group databases in the chroot'ed environment.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_inituserinfo(named_g_username);
|
2000-07-01 00:48:06 +00:00
|
|
|
|
2004-01-07 05:48:15 +00:00
|
|
|
/*
|
|
|
|
* Initialize time conversion information
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_tzset();
|
2004-01-07 05:48:15 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_opendevnull();
|
2004-01-07 06:17:04 +00:00
|
|
|
|
2005-04-05 00:58:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
|
|
|
/* Check if named is under smf control, before chroot. */
|
2017-09-08 13:39:09 -07:00
|
|
|
result = named_smf_get_instance(&instance, 0, named_g_mctx);
|
2005-04-05 00:58:16 +00:00
|
|
|
/* We don't care about instance, just check if we got one. */
|
|
|
|
if (result == ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_smf_got_instance = 1;
|
2005-04-05 00:58:16 +00:00
|
|
|
else
|
2017-09-08 13:39:09 -07:00
|
|
|
named_smf_got_instance = 0;
|
2005-04-05 00:58:16 +00:00
|
|
|
if (instance != NULL)
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_free(named_g_mctx, instance);
|
2005-04-05 00:58:16 +00:00
|
|
|
#endif /* HAVE_LIBSCF */
|
|
|
|
|
2004-01-27 02:13:22 +00:00
|
|
|
#ifdef PATH_RANDOMDEV
|
|
|
|
/*
|
|
|
|
* Initialize system's random device as fallback entropy source
|
|
|
|
* if running chroot'ed.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_chrootdir != NULL) {
|
|
|
|
result = isc_entropy_create(named_g_mctx,
|
|
|
|
&named_g_fallbackentropy);
|
2004-01-27 02:13:22 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("isc_entropy_create() failed: %s",
|
2004-01-27 02:13:22 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_entropy_createfilesource(named_g_fallbackentropy,
|
2004-01-27 02:13:22 +00:00
|
|
|
PATH_RANDOMDEV);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlywarning("could not open pre-chroot "
|
2004-01-27 02:13:22 +00:00
|
|
|
"entropy source %s: %s",
|
|
|
|
PATH_RANDOMDEV,
|
|
|
|
isc_result_totext(result));
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_entropy_detach(&named_g_fallbackentropy);
|
2004-01-27 02:13:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-24 01:08:21 +00:00
|
|
|
|
|
|
|
#ifdef ISC_PLATFORM_USETHREADS
|
|
|
|
/*
|
2017-09-08 13:39:09 -07:00
|
|
|
* Check for the number of cpu's before named_os_chroot().
|
2008-10-24 01:08:21 +00:00
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_cpus_detected = isc_os_ncpus();
|
2008-10-24 01:08:21 +00:00
|
|
|
#endif
|
2004-01-27 02:13:22 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_chroot(named_g_chrootdir);
|
2000-01-28 20:10:26 +00:00
|
|
|
|
2000-04-11 18:51:19 +00:00
|
|
|
/*
|
|
|
|
* For operating systems which have a capability mechanism, now
|
|
|
|
* is the time to switch to minimal privs and change our user id.
|
|
|
|
* On traditional UNIX systems, this call will be a no-op, and we
|
|
|
|
* will change the user ID after reading the config file the first
|
|
|
|
* time. (We need to read the config file to know which possibly
|
|
|
|
* privileged ports to bind() to.)
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_minprivs();
|
2000-04-11 18:51:19 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = named_log_init(ISC_TF(named_g_username != NULL));
|
1999-10-22 19:35:19 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("named_log_init() failed: %s",
|
1999-10-23 01:07:22 +00:00
|
|
|
isc_result_totext(result));
|
1999-10-22 19:35:19 +00:00
|
|
|
|
2000-01-26 21:13:19 +00:00
|
|
|
/*
|
|
|
|
* Now is the time to daemonize (if we're not running in the
|
|
|
|
* foreground). We waited until now because we wanted to get
|
|
|
|
* a valid logging context setup. We cannot daemonize any later,
|
|
|
|
* because calling create_managers() will create threads, which
|
|
|
|
* would be lost after fork().
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
if (!named_g_foreground)
|
|
|
|
named_os_daemonize();
|
2000-01-26 21:13:19 +00:00
|
|
|
|
2004-10-25 00:33:28 +00:00
|
|
|
/*
|
|
|
|
* We call isc_app_start() here as some versions of FreeBSD's fork()
|
|
|
|
* destroys all the signal handling it sets up.
|
|
|
|
*/
|
|
|
|
result = isc_app_start();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("isc_app_start() failed: %s",
|
2004-10-25 00:33:28 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"starting %s %s%s%s <id:%s>",
|
|
|
|
named_g_product, named_g_version,
|
|
|
|
*named_g_description ? " " : "", named_g_description,
|
|
|
|
named_g_srcid);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"running on %s", named_os_uname());
|
2016-01-30 11:03:10 -08:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"built with %s", named_g_configargs);
|
2008-09-23 17:25:47 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"running as: %s%s",
|
2015-02-26 11:53:11 -08:00
|
|
|
program_name, saved_command_line);
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2011-11-05 00:45:31 +00:00
|
|
|
"----------------------------------------------------");
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2011-11-05 00:45:31 +00:00
|
|
|
"BIND 9 is maintained by Internet Systems Consortium,");
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2011-11-05 00:45:31 +00:00
|
|
|
"Inc. (ISC), a non-profit 501(c)(3) public-benefit ");
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2011-11-05 00:45:31 +00:00
|
|
|
"corporation. Support and training for BIND 9 are ");
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2011-11-05 00:45:31 +00:00
|
|
|
"available at https://www.isc.org/support");
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2011-11-05 00:45:31 +00:00
|
|
|
"----------------------------------------------------");
|
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
dump_symboltable();
|
|
|
|
|
2000-11-14 23:59:21 +00:00
|
|
|
/*
|
|
|
|
* Get the initial resource limits.
|
|
|
|
*/
|
2000-11-15 02:11:50 +00:00
|
|
|
(void)isc_resource_getlimit(isc_resource_stacksize,
|
2017-09-08 13:39:09 -07:00
|
|
|
&named_g_initstacksize);
|
2000-11-15 02:11:50 +00:00
|
|
|
(void)isc_resource_getlimit(isc_resource_datasize,
|
2017-09-08 13:39:09 -07:00
|
|
|
&named_g_initdatasize);
|
2000-11-15 02:11:50 +00:00
|
|
|
(void)isc_resource_getlimit(isc_resource_coresize,
|
2017-09-08 13:39:09 -07:00
|
|
|
&named_g_initcoresize);
|
2000-11-15 02:11:50 +00:00
|
|
|
(void)isc_resource_getlimit(isc_resource_openfiles,
|
2017-09-08 13:39:09 -07:00
|
|
|
&named_g_initopenfiles);
|
2000-11-14 23:59:21 +00:00
|
|
|
|
2008-10-24 01:24:54 +00:00
|
|
|
/*
|
|
|
|
* System resources cannot effectively be tuned on some systems.
|
|
|
|
* Raise the limit in such cases for safety.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
old_openfiles = named_g_initopenfiles;
|
|
|
|
named_os_adjustnofile();
|
2008-10-24 01:24:54 +00:00
|
|
|
(void)isc_resource_getlimit(isc_resource_openfiles,
|
2017-09-08 13:39:09 -07:00
|
|
|
&named_g_initopenfiles);
|
|
|
|
if (old_openfiles != named_g_initopenfiles) {
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2008-10-24 01:24:54 +00:00
|
|
|
"adjusted limit on open files from "
|
|
|
|
"%" ISC_PRINT_QUADFORMAT "u to "
|
|
|
|
"%" ISC_PRINT_QUADFORMAT "u",
|
2017-09-08 13:39:09 -07:00
|
|
|
old_openfiles, named_g_initopenfiles);
|
2008-10-24 01:24:54 +00:00
|
|
|
}
|
|
|
|
|
2001-06-08 23:52:21 +00:00
|
|
|
/*
|
|
|
|
* If the named configuration filename is relative, prepend the current
|
|
|
|
* directory's name before possibly changing to another directory.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
if (! isc_file_isabsolute(named_g_conffile)) {
|
|
|
|
result = isc_file_absolutepath(named_g_conffile,
|
2001-07-16 17:32:49 +00:00
|
|
|
absolute_conffile,
|
|
|
|
sizeof(absolute_conffile));
|
2001-06-08 23:52:21 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("could not construct "
|
|
|
|
"absolute path "
|
|
|
|
"of configuration file: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
named_g_conffile = absolute_conffile;
|
2001-06-08 23:52:21 +00:00
|
|
|
}
|
|
|
|
|
2006-12-21 06:03:37 +00:00
|
|
|
/*
|
|
|
|
* Record the server's startup time.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_time_now(&named_g_boottime);
|
2006-12-21 06:03:37 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("isc_time_now() failed: %s",
|
2006-12-21 06:03:37 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
result = create_managers();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("create_managers() failed: %s",
|
1999-10-23 01:07:22 +00:00
|
|
|
isc_result_totext(result));
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_builtin_init();
|
2001-11-20 01:18:15 +00:00
|
|
|
|
2000-11-17 22:09:19 +00:00
|
|
|
/*
|
|
|
|
* Add calls to register sdb drivers here.
|
|
|
|
*/
|
2000-11-27 19:12:23 +00:00
|
|
|
/* xxdb_init(); */
|
2000-11-17 22:09:19 +00:00
|
|
|
|
2011-03-10 04:36:16 +00:00
|
|
|
#ifdef ISC_DLZ_DLOPEN
|
|
|
|
/*
|
|
|
|
* Register the DLZ "dlopen" driver.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
result = dlz_dlopen_init(named_g_mctx);
|
2011-03-10 04:36:16 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("dlz_dlopen_init() failed: %s",
|
2011-03-10 04:36:16 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONTRIB_DLZ
|
2005-09-05 00:12:29 +00:00
|
|
|
/*
|
2011-03-10 04:36:16 +00:00
|
|
|
* Register any other contributed DLZ drivers.
|
2005-09-05 00:12:29 +00:00
|
|
|
*/
|
|
|
|
result = dlz_drivers_init();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("dlz_drivers_init() failed: %s",
|
2005-09-05 00:12:29 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_server_create(named_g_mctx, &named_g_server);
|
|
|
|
sctx = named_g_server->sctx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modify server context according to command line options
|
|
|
|
*/
|
|
|
|
if (clienttest)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_CLIENTTEST, ISC_TRUE);
|
|
|
|
if (dropedns)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_DROPEDNS, ISC_TRUE);
|
|
|
|
if (noedns)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOEDNS, ISC_TRUE);
|
|
|
|
if (nosoa)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOSOA, ISC_TRUE);
|
|
|
|
if (noaa)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOAA, ISC_TRUE);
|
|
|
|
if (nonearest)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_NONEAREST, ISC_TRUE);
|
|
|
|
if (notcp)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOTCP, ISC_TRUE);
|
|
|
|
if (disable4)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_DISABLE4, ISC_TRUE);
|
|
|
|
if (disable6)
|
|
|
|
ns_server_setoption(sctx, NS_SERVER_DISABLE6, ISC_TRUE);
|
|
|
|
|
|
|
|
named_g_server->sctx->delay = delay;
|
2014-05-15 20:29:30 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBSECCOMP
|
|
|
|
setup_seccomp();
|
|
|
|
#endif /* HAVE_LIBSECCOMP */
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-14 13:47:17 +00:00
|
|
|
cleanup(void) {
|
1999-07-24 01:17:44 +00:00
|
|
|
destroy_managers();
|
2000-07-10 11:35:02 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_mapped != NULL)
|
|
|
|
dns_acl_detach(&named_g_mapped);
|
2016-07-11 14:11:34 +10:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_entropy_detach(&named_g_entropy);
|
|
|
|
if (named_g_fallbackentropy != NULL)
|
|
|
|
isc_entropy_detach(&named_g_fallbackentropy);
|
2000-07-10 11:35:02 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_server_destroy(&named_g_server);
|
2015-02-27 12:34:43 +11:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_builtin_deinit();
|
2001-11-20 01:18:15 +00:00
|
|
|
|
2000-11-17 22:09:19 +00:00
|
|
|
/*
|
|
|
|
* Add calls to unregister sdb drivers here.
|
|
|
|
*/
|
2000-11-27 19:12:23 +00:00
|
|
|
/* xxdb_clear(); */
|
2000-11-17 22:09:19 +00:00
|
|
|
|
2011-03-10 04:36:16 +00:00
|
|
|
#ifdef CONTRIB_DLZ
|
2005-09-05 00:12:29 +00:00
|
|
|
/*
|
2011-03-10 04:36:16 +00:00
|
|
|
* Unregister contributed DLZ drivers.
|
2005-09-05 00:12:29 +00:00
|
|
|
*/
|
|
|
|
dlz_drivers_clear();
|
|
|
|
#endif
|
2011-03-10 04:36:16 +00:00
|
|
|
#ifdef ISC_DLZ_DLOPEN
|
|
|
|
/*
|
|
|
|
* Unregister "dlopen" DLZ driver.
|
|
|
|
*/
|
|
|
|
dlz_dlopen_clear();
|
|
|
|
#endif
|
2005-09-05 00:12:29 +00:00
|
|
|
|
2005-09-18 07:16:24 +00:00
|
|
|
dns_name_destroy();
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_NOTICE, "exiting");
|
2017-09-08 13:39:09 -07:00
|
|
|
named_log_shutdown();
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
2001-09-07 00:37:02 +00:00
|
|
|
static char *memstats = NULL;
|
|
|
|
|
|
|
|
void
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_setmemstats(const char *filename) {
|
2001-09-07 00:37:02 +00:00
|
|
|
/*
|
|
|
|
* Caller has to ensure locking.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (memstats != NULL) {
|
|
|
|
free(memstats);
|
|
|
|
memstats = NULL;
|
|
|
|
}
|
2017-09-13 00:14:37 -07:00
|
|
|
|
2001-09-07 00:37:02 +00:00
|
|
|
if (filename == NULL)
|
|
|
|
return;
|
2017-09-13 00:14:37 -07:00
|
|
|
|
|
|
|
memstats = strdup(filename);
|
2001-09-07 00:37:02 +00:00
|
|
|
}
|
|
|
|
|
2004-09-01 07:25:51 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
|
|
|
/*
|
2005-04-05 00:58:16 +00:00
|
|
|
* Get FMRI for the named process.
|
2004-09-01 07:25:51 +00:00
|
|
|
*/
|
2005-04-05 00:58:16 +00:00
|
|
|
isc_result_t
|
2017-09-08 13:39:09 -07:00
|
|
|
named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) {
|
2004-09-01 07:25:51 +00:00
|
|
|
scf_handle_t *h = NULL;
|
|
|
|
int namelen;
|
2005-04-05 00:58:16 +00:00
|
|
|
char *instance;
|
|
|
|
|
|
|
|
REQUIRE(ins_name != NULL && *ins_name == NULL);
|
2004-09-01 07:25:51 +00:00
|
|
|
|
|
|
|
if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
|
2005-04-05 00:58:16 +00:00
|
|
|
if (debug)
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_handle_create() failed: %s",
|
2008-01-18 23:46:58 +00:00
|
|
|
scf_strerror(scf_error()));
|
2005-04-05 00:58:16 +00:00
|
|
|
return (ISC_R_FAILURE);
|
2004-09-01 07:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scf_handle_bind(h) == -1) {
|
2005-04-05 00:58:16 +00:00
|
|
|
if (debug)
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_handle_bind() failed: %s",
|
|
|
|
scf_strerror(scf_error()));
|
2004-09-01 07:25:51 +00:00
|
|
|
scf_handle_destroy(h);
|
2005-04-05 00:58:16 +00:00
|
|
|
return (ISC_R_FAILURE);
|
2004-09-01 07:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((namelen = scf_myname(h, NULL, 0)) == -1) {
|
2005-04-05 00:58:16 +00:00
|
|
|
if (debug)
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_myname() failed: %s",
|
|
|
|
scf_strerror(scf_error()));
|
2004-09-01 07:25:51 +00:00
|
|
|
scf_handle_destroy(h);
|
2005-04-05 00:58:16 +00:00
|
|
|
return (ISC_R_FAILURE);
|
2004-09-01 07:25:51 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 00:58:16 +00:00
|
|
|
if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) {
|
2004-09-01 07:25:51 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2017-09-08 13:39:09 -07:00
|
|
|
"named_smf_get_instance memory "
|
2004-09-01 07:25:51 +00:00
|
|
|
"allocation failed: %s",
|
|
|
|
isc_result_totext(ISC_R_NOMEMORY));
|
|
|
|
scf_handle_destroy(h);
|
2005-04-05 00:58:16 +00:00
|
|
|
return (ISC_R_FAILURE);
|
2004-09-01 07:25:51 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 00:58:16 +00:00
|
|
|
if (scf_myname(h, instance, namelen + 1) == -1) {
|
|
|
|
if (debug)
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_myname() failed: %s",
|
|
|
|
scf_strerror(scf_error()));
|
2004-09-01 07:25:51 +00:00
|
|
|
scf_handle_destroy(h);
|
2005-04-05 00:58:16 +00:00
|
|
|
isc_mem_free(mctx, instance);
|
|
|
|
return (ISC_R_FAILURE);
|
2004-09-01 07:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scf_handle_destroy(h);
|
2005-04-05 00:58:16 +00:00
|
|
|
*ins_name = instance;
|
|
|
|
return (ISC_R_SUCCESS);
|
2004-09-01 07:25:51 +00:00
|
|
|
}
|
2005-04-05 00:58:16 +00:00
|
|
|
#endif /* HAVE_LIBSCF */
|
2004-09-01 07:25:51 +00:00
|
|
|
|
2013-12-04 12:47:23 +11:00
|
|
|
/* main entry point, possibly hooked */
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
isc_result_t result;
|
2005-04-29 00:36:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
|
|
|
char *instance = NULL;
|
|
|
|
#endif
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2014-10-08 15:14:02 +02:00
|
|
|
#ifdef HAVE_GPERFTOOLS_PROFILER
|
|
|
|
(void) ProfilerStart(NULL);
|
|
|
|
#endif
|
|
|
|
|
2004-04-20 06:53:52 +00:00
|
|
|
/*
|
|
|
|
* Record version in core image.
|
|
|
|
* strings named.core | grep "named version:"
|
|
|
|
*/
|
|
|
|
strlcat(version,
|
2009-04-03 19:55:59 +00:00
|
|
|
#if defined(NO_VERSION_DATE) || !defined(__DATE__)
|
2012-10-22 12:56:47 -07:00
|
|
|
"named version: BIND " VERSION " <" SRCID ">",
|
2009-04-03 19:55:59 +00:00
|
|
|
#else
|
2012-10-22 12:56:47 -07:00
|
|
|
"named version: BIND " VERSION " <" SRCID "> (" __DATE__ ")",
|
2004-04-20 06:53:52 +00:00
|
|
|
#endif
|
|
|
|
sizeof(version));
|
2001-05-31 10:37:08 +00:00
|
|
|
result = isc_file_progname(*argv, program_name, sizeof(program_name));
|
2001-05-08 19:47:55 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("program name too long");
|
2001-05-08 19:47:55 +00:00
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("failed to build internal symbol table");
|
2009-09-01 18:40:25 +00:00
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
isc_assertion_setcallback(assertion_failed);
|
|
|
|
isc_error_setfatal(library_fatal_error);
|
2000-02-14 19:40:36 +00:00
|
|
|
isc_error_setunexpected(library_unexpected_error);
|
1999-10-23 00:33:04 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_init(program_name);
|
1999-10-23 01:07:22 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
dns_result_register();
|
|
|
|
dst_result_register();
|
2001-03-27 00:44:59 +00:00
|
|
|
isccc_result_register();
|
2014-03-12 20:52:01 -07:00
|
|
|
#ifdef PKCS11CRYPTO
|
|
|
|
pk11_result_register();
|
|
|
|
#endif
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
parse_command_line(argc, argv);
|
|
|
|
|
2016-05-05 11:46:11 +02:00
|
|
|
#ifdef ENABLE_AFL
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_fuzz_type != isc_fuzz_none) {
|
2016-05-05 11:46:11 +02:00
|
|
|
named_fuzz_setup();
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_fuzz_type == isc_fuzz_resolver) {
|
2016-05-05 11:46:11 +02:00
|
|
|
dns_resolver_setfuzzing();
|
2017-09-08 13:39:09 -07:00
|
|
|
} else if (named_g_fuzz_type == isc_fuzz_http) {
|
2016-05-05 11:46:11 +02:00
|
|
|
isc_httpd_setfinishhook(named_fuzz_notify);
|
|
|
|
}
|
|
|
|
#endif
|
2001-09-14 12:34:03 +00:00
|
|
|
/*
|
|
|
|
* Warn about common configuration error.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_chrootdir != NULL) {
|
|
|
|
int len = strlen(named_g_chrootdir);
|
|
|
|
if (strncmp(named_g_chrootdir, named_g_conffile, len) == 0 &&
|
|
|
|
(named_g_conffile[len] == '/' ||
|
|
|
|
named_g_conffile[len] == '\\'))
|
|
|
|
named_main_earlywarning("config filename (-c %s) "
|
|
|
|
"contains chroot path (-t %s)",
|
|
|
|
named_g_conffile,
|
|
|
|
named_g_chrootdir);
|
2001-09-14 12:34:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_mem_create(0, 0, &named_g_mctx);
|
2001-09-07 00:17:25 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("isc_mem_create() failed: %s",
|
2001-09-07 00:17:25 +00:00
|
|
|
isc_result_totext(result));
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_setname(named_g_mctx, "main", NULL);
|
2001-09-07 00:17:25 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
setup();
|
|
|
|
|
|
|
|
/*
|
2000-01-22 01:40:10 +00:00
|
|
|
* Start things running and then wait for a shutdown request
|
|
|
|
* or reload.
|
1999-07-24 01:17:44 +00:00
|
|
|
*/
|
2000-01-22 01:40:10 +00:00
|
|
|
do {
|
|
|
|
result = isc_app_run();
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-01-22 01:40:10 +00:00
|
|
|
if (result == ISC_R_RELOAD) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_server_reloadwanted(named_g_server);
|
2000-01-22 01:40:10 +00:00
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_app_run(): %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
/*
|
|
|
|
* Force exit.
|
|
|
|
*/
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
} while (result != ISC_R_SUCCESS);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2005-04-29 00:36:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_smf_want_disable == 1) {
|
|
|
|
result = named_smf_get_instance(&instance, 1, named_g_mctx);
|
2005-04-29 00:36:16 +00:00
|
|
|
if (result == ISC_R_SUCCESS && instance != NULL) {
|
|
|
|
if (smf_disable_instance(instance, 0) != 0)
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2006-11-10 18:44:46 +00:00
|
|
|
"smf_disable_instance() "
|
2005-04-29 00:36:16 +00:00
|
|
|
"failed for %s : %s",
|
|
|
|
instance,
|
|
|
|
scf_strerror(scf_error()));
|
|
|
|
}
|
|
|
|
if (instance != NULL)
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_free(named_g_mctx, instance);
|
2005-04-29 00:36:16 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_LIBSCF */
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
cleanup();
|
|
|
|
|
2000-12-29 01:29:56 +00:00
|
|
|
if (want_stats) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_stats(named_g_mctx, stdout);
|
2000-12-29 01:29:56 +00:00
|
|
|
isc_mutex_stats(stdout);
|
|
|
|
}
|
2007-09-26 03:22:45 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_memstatistics && memstats != NULL) {
|
2001-09-06 02:13:55 +00:00
|
|
|
FILE *fp = NULL;
|
|
|
|
result = isc_stdio_open(memstats, "w", &fp);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_stats(named_g_mctx, fp);
|
2001-09-06 02:13:55 +00:00
|
|
|
isc_mutex_stats(fp);
|
2016-08-08 09:50:34 +10:00
|
|
|
(void) isc_stdio_close(fp);
|
2001-09-06 02:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_destroy(&named_g_mctx);
|
2006-01-04 03:16:47 +00:00
|
|
|
isc_mem_checkdestroyed(stderr);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_setmemstats(NULL);
|
2001-09-07 00:37:02 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_app_finish();
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_closedevnull();
|
2004-01-07 06:17:04 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_shutdown();
|
1999-10-23 01:07:22 +00:00
|
|
|
|
2014-10-08 15:14:02 +02:00
|
|
|
#ifdef HAVE_GPERFTOOLS_PROFILER
|
|
|
|
ProfilerStop();
|
|
|
|
#endif
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|