1999-07-24 01:17:44 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2021-06-03 08:37:05 +02:00
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
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
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
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
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
#include <ctype.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2021-06-22 13:05:15 +02:00
|
|
|
#include <locale.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.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
|
|
|
|
2021-02-11 14:25:58 +01:00
|
|
|
#ifdef HAVE_DNSTAP
|
|
|
|
#include <protobuf-c/protobuf-c.h>
|
|
|
|
#endif
|
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#include <isc/attributes.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>
|
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>
|
2021-04-27 00:07:43 +02:00
|
|
|
#include <isc/managers.h>
|
2019-11-05 15:34:35 -08:00
|
|
|
#include <isc/netmgr.h>
|
2000-06-22 01:09:14 +00:00
|
|
|
#include <isc/os.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>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2022-07-26 13:03:45 +02:00
|
|
|
#include <isc/signal.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>
|
2022-04-27 17:41:47 +02:00
|
|
|
#include <isc/uv.h>
|
2022-09-23 14:36:54 +02:00
|
|
|
#include <isc/xml.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
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>
|
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
|
|
|
|
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>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */
|
2014-10-08 15:14:02 +02:00
|
|
|
|
2019-06-24 12:21:47 +02:00
|
|
|
#ifdef HAVE_JSON_C
|
|
|
|
#include <json_c_version.h>
|
|
|
|
#endif /* HAVE_JSON_C */
|
2014-03-12 20:52:01 -07:00
|
|
|
|
2019-11-18 21:51:36 +01:00
|
|
|
#ifdef HAVE_GEOIP2
|
|
|
|
#include <maxminddb.h>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_GEOIP2 */
|
2019-11-18 21:51:36 +01: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>
|
2019-11-05 12:56:58 +11:00
|
|
|
#include <named/config.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>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <named/globals.h> /* Explicit, though named/log.h includes it. */
|
1999-10-22 19:35:19 +00:00
|
|
|
#include <named/log.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <named/main.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>
|
2005-04-05 00:58:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <named/smf_globals.h>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LIBSCF */
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2015-01-22 09:44:24 -08:00
|
|
|
#include <openssl/crypto.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <openssl/opensslv.h>
|
2010-12-22 03:59:02 +00:00
|
|
|
#ifdef HAVE_LIBXML2
|
2019-06-24 14:25:55 +02:00
|
|
|
#include <libxml/parser.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <libxml/xmlversion.h>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LIBXML2 */
|
2016-03-13 07:48:11 +11:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
#include <zlib.h>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_ZLIB */
|
2021-08-24 13:24:56 +10:00
|
|
|
#ifdef HAVE_LIBNGHTTP2
|
2021-02-16 14:13:18 -08:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2021-08-24 13:24:56 +10:00
|
|
|
#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
|
|
|
|
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
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifndef BACKTRACE_MAXFRAME */
|
2009-09-01 18:40:25 +00:00
|
|
|
|
2021-06-10 08:06:48 +02:00
|
|
|
extern int isc_dscp_check_value;
|
|
|
|
extern unsigned int dns_zone_mkey_hour;
|
|
|
|
extern unsigned int dns_zone_mkey_day;
|
|
|
|
extern unsigned int dns_zone_mkey_month;
|
2013-03-22 12:27:54 -07:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
static bool want_stats = false;
|
|
|
|
static char program_name[NAME_MAX] = "named";
|
|
|
|
static char absolute_conffile[PATH_MAX];
|
|
|
|
static char saved_command_line[4096] = { 0 };
|
|
|
|
static char ellipsis[5] = { 0 };
|
|
|
|
static char version[512];
|
|
|
|
static int maxudp = 0;
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
/*
|
|
|
|
* -T options:
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool dropedns = false;
|
2018-07-26 17:53:15 +10:00
|
|
|
static bool ednsformerr = false;
|
|
|
|
static bool ednsnotimp = false;
|
|
|
|
static bool ednsrefused = false;
|
|
|
|
static bool fixedlocal = false;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool noaa = false;
|
2018-07-26 17:53:15 +10:00
|
|
|
static bool noedns = false;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool nonearest = false;
|
2018-07-26 17:53:15 +10:00
|
|
|
static bool nosoa = false;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool notcp = false;
|
|
|
|
static bool sigvalinsecs = false;
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* -4 and -6
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool disable6 = false;
|
|
|
|
static bool disable4 = false;
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2002-05-03 05:28:29 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08: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,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_WARNING, format,
|
|
|
|
args);
|
2001-09-14 12:34:03 +00:00
|
|
|
} 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
|
2020-02-13 14:44:37 -08: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,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL, format,
|
|
|
|
args);
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
|
|
|
"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);
|
|
|
|
}
|
|
|
|
|
2021-10-11 12:57:27 +02:00
|
|
|
noreturn static void
|
2009-09-29 15:06:07 +00:00
|
|
|
assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
2018-08-07 16:46:53 +02:00
|
|
|
const char *cond);
|
2009-09-29 15:06:07 +00:00
|
|
|
|
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,
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *cond) {
|
|
|
|
void *tracebuf[BACKTRACE_MAXFRAME];
|
2020-03-11 09:55:48 +01:00
|
|
|
int nframes;
|
2009-09-01 18:40:25 +00:00
|
|
|
|
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);
|
|
|
|
|
2021-04-27 16:20:03 +02:00
|
|
|
nframes = isc_backtrace(tracebuf, BACKTRACE_MAXFRAME);
|
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,
|
2021-04-27 16:20:03 +02:00
|
|
|
isc_assertion_typetotext(type), cond,
|
|
|
|
(nframes > 0) ? ", back trace" : "");
|
|
|
|
if (nframes > 0) {
|
|
|
|
char **strs = isc_backtrace_symbols(tracebuf, nframes);
|
|
|
|
if (strs != NULL) {
|
|
|
|
for (int i = 0; i < nframes; i++) {
|
|
|
|
isc_log_write(named_g_lctx,
|
|
|
|
NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN,
|
|
|
|
ISC_LOG_CRITICAL, "%s",
|
|
|
|
strs[i]);
|
|
|
|
}
|
2009-09-01 18:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
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 {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "%s:%d: %s(%s) failed\n", file, line,
|
|
|
|
isc_assertion_typetotext(type), cond);
|
1999-10-23 00:33:04 +00:00
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_coreok) {
|
1999-10-23 00:33:04 +00:00
|
|
|
abort();
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-23 00:33:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-10-11 12:57:27 +02:00
|
|
|
noreturn static void
|
2001-08-08 22:54:55 +00:00
|
|
|
library_fatal_error(const char *file, int line, const char *format,
|
2018-08-07 16:46:53 +02:00
|
|
|
va_list args) ISC_FORMAT_PRINTF(3, 0);
|
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,
|
2020-02-13 14:44:37 -08:00
|
|
|
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,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL, 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);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_coreok) {
|
1999-10-23 00:33:04 +00:00
|
|
|
abort();
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-23 00:33:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
library_unexpected_error(const char *file, int line, const char *format,
|
|
|
|
va_list args) ISC_FORMAT_PRINTF(3, 0);
|
2001-08-08 22:54:55 +00:00
|
|
|
|
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,
|
2020-02-13 14:44:37 -08:00
|
|
|
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,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_ERROR, format,
|
|
|
|
args);
|
2000-02-14 19:40:36 +00:00
|
|
|
} 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
|
2020-02-13 14:44:37 -08:00
|
|
|
usage(void) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "usage: named [-4|-6] [-c conffile] [-d debuglevel] "
|
2021-04-12 12:06:54 +10:00
|
|
|
"[-D comment] [-E engine]\n"
|
|
|
|
" [-f|-g] [-L logfile] [-n number_of_cpus] "
|
|
|
|
"[-p port] [-s]\n"
|
|
|
|
" [-S sockets] [-t chrootdir] [-u "
|
|
|
|
"username] [-U listeners]\n"
|
|
|
|
" [-X lockfile] [-m "
|
|
|
|
"{usage|trace|record|size|mctx}]\n"
|
|
|
|
" [-M fill|nofill]\n"
|
2022-03-23 12:52:33 +01:00
|
|
|
"usage: named [-v|-V|-C]\n");
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
save_command_line(int argc, char *argv[]) {
|
|
|
|
int i;
|
2018-12-21 12:39:51 +01:00
|
|
|
char *dst = saved_command_line;
|
|
|
|
char *eob = saved_command_line + sizeof(saved_command_line) - 1;
|
2019-05-21 12:05:44 +00:00
|
|
|
char *rollback = dst;
|
2000-08-09 03:44:42 +00:00
|
|
|
|
|
|
|
for (i = 1; i < argc && dst < eob; i++) {
|
2018-12-21 12:39:51 +01:00
|
|
|
char *src = argv[i];
|
2020-02-13 14:44:37 -08:00
|
|
|
bool quoted = false;
|
2018-12-21 12:39:51 +01:00
|
|
|
|
|
|
|
rollback = dst;
|
2000-08-09 03:44:42 +00:00
|
|
|
*dst++ = ' ';
|
|
|
|
|
|
|
|
while (*src != '\0' && dst < eob) {
|
2020-06-02 20:32:21 +02:00
|
|
|
if (isalnum(*(unsigned char *)src) || *src == ',' ||
|
|
|
|
*src == '-' || *src == '_' || *src == '.' ||
|
|
|
|
*src == '/')
|
2020-02-13 14:44:37 -08:00
|
|
|
{
|
2000-08-09 03:44:42 +00:00
|
|
|
*dst++ = *src++;
|
2020-06-02 20:32:21 +02:00
|
|
|
} else if (isprint(*(unsigned char *)src)) {
|
2018-12-21 12:39:51 +01:00
|
|
|
if (dst + 2 >= eob) {
|
|
|
|
goto add_ellipsis;
|
|
|
|
}
|
2000-08-09 03:44:42 +00:00
|
|
|
*dst++ = '\\';
|
2018-12-21 12:39:51 +01:00
|
|
|
*dst++ = *src++;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Control character found in the input,
|
|
|
|
* quote the whole arg and restart
|
|
|
|
*/
|
|
|
|
if (!quoted) {
|
|
|
|
dst = rollback;
|
|
|
|
src = argv[i];
|
|
|
|
|
|
|
|
if (dst + 3 >= eob) {
|
|
|
|
goto add_ellipsis;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = ' ';
|
|
|
|
*dst++ = '$';
|
|
|
|
*dst++ = '\'';
|
|
|
|
|
|
|
|
quoted = true;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
char tmp[5];
|
2020-02-13 14:44:37 -08:00
|
|
|
int c = snprintf(tmp, sizeof(tmp),
|
|
|
|
"\\%03o", *src++);
|
2018-12-21 12:39:51 +01:00
|
|
|
if (dst + c >= eob) {
|
|
|
|
goto add_ellipsis;
|
|
|
|
}
|
|
|
|
memmove(dst, tmp, c);
|
|
|
|
dst += c;
|
|
|
|
}
|
2000-08-09 03:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 12:39:51 +01:00
|
|
|
if (quoted) {
|
|
|
|
if (dst == eob) {
|
|
|
|
goto add_ellipsis;
|
|
|
|
}
|
|
|
|
*dst++ = '\'';
|
|
|
|
}
|
|
|
|
}
|
2000-08-09 03:44:42 +00:00
|
|
|
|
2018-12-21 12:39:51 +01:00
|
|
|
if (dst < eob) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_ellipsis:
|
|
|
|
dst = rollback;
|
|
|
|
*dst = '\0';
|
|
|
|
strlcpy(ellipsis, " ...", sizeof(ellipsis));
|
2000-08-09 03:44:42 +00:00
|
|
|
}
|
|
|
|
|
2000-09-28 21:09:51 +00:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
parse_int(char *arg, const char *desc) {
|
|
|
|
char *endp;
|
|
|
|
int tmp;
|
2000-09-28 21:09:51 +00:00
|
|
|
long int ltmp;
|
|
|
|
|
2000-09-28 21:21:31 +00:00
|
|
|
ltmp = strtol(arg, &endp, 10);
|
2020-02-12 13:59:18 +01:00
|
|
|
tmp = (int)ltmp;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (*endp != '\0') {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("%s '%s' must be numeric", desc, arg);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (tmp < 0 || tmp != ltmp) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("%s '%s' out of range", desc, arg);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-09-28 21:09:51 +00:00
|
|
|
return (tmp);
|
|
|
|
}
|
|
|
|
|
2001-09-07 00:17:25 +00:00
|
|
|
static struct flag_def {
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *name;
|
2001-09-07 00:17:25 +00:00
|
|
|
unsigned int value;
|
2020-02-13 14:44:37 -08:00
|
|
|
bool negate;
|
2020-02-12 13:59:18 +01:00
|
|
|
} mem_debug_flags[] = { { "none", 0, false },
|
|
|
|
{ "trace", ISC_MEM_DEBUGTRACE, false },
|
|
|
|
{ "record", ISC_MEM_DEBUGRECORD, false },
|
|
|
|
{ "usage", ISC_MEM_DEBUGUSAGE, false },
|
|
|
|
{ NULL, 0, false } },
|
2021-02-04 20:11:20 +01:00
|
|
|
mem_context_flags[] = { { "fill", ISC_MEMFLAG_FILL, false },
|
2020-02-12 13:59:18 +01:00
|
|
|
{ "nofill", ISC_MEMFLAG_FILL, true },
|
|
|
|
{ NULL, 0, false } };
|
2001-09-07 00:17:25 +00:00
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
set_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
|
2018-04-17 08:29:14 -07:00
|
|
|
bool clear = false;
|
2015-02-25 09:06:45 +05:30
|
|
|
|
2001-09-07 00:17:25 +00:00
|
|
|
for (;;) {
|
|
|
|
const struct flag_def *def;
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *end = strchr(arg, ',');
|
|
|
|
int arglen;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (end == NULL) {
|
2001-09-07 00:17:25 +00:00
|
|
|
end = arg + strlen(arg);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (def->value == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
clear = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (def->negate) {
|
2017-10-09 09:55:37 -07:00
|
|
|
*ret &= ~(def->value);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2017-10-09 09:55:37 -07:00
|
|
|
*ret |= def->value;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-09-07 00:17:25 +00:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
|
2020-02-12 13:59:18 +01:00
|
|
|
found:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (clear || (*end == '\0')) {
|
2001-09-07 00:17:25 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-09-07 00:17:25 +00:00
|
|
|
arg = end + 1;
|
|
|
|
}
|
2015-02-25 09:06:45 +05:30
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (clear) {
|
2015-02-25 09:06:45 +05:30
|
|
|
*ret = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-09-07 00:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 17:35:47 +10:00
|
|
|
static void
|
|
|
|
list_dnssec_algorithms(isc_buffer_t *b) {
|
|
|
|
for (dst_algorithm_t i = DST_ALG_UNKNOWN; i < DST_MAX_ALGS; i++) {
|
|
|
|
if (i == DST_ALG_DH || i == DST_ALG_GSSAPI ||
|
|
|
|
(i >= DST_ALG_HMAC_FIRST && i <= DST_ALG_HMAC_LAST))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (dst_algorithm_supported(i)) {
|
|
|
|
isc_buffer_putstr(b, " ");
|
|
|
|
(void)dns_secalg_totext(i, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_ds_algorithms(isc_buffer_t *b) {
|
|
|
|
for (size_t i = 0; i < 256; i++) {
|
|
|
|
if (dst_ds_digest_supported(i)) {
|
|
|
|
isc_buffer_putstr(b, " ");
|
|
|
|
(void)dns_dsdigest_totext(i, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_hmac_algorithms(isc_buffer_t *b) {
|
|
|
|
isc_buffer_t sb = *b;
|
|
|
|
for (dst_algorithm_t i = DST_ALG_HMAC_FIRST; i <= DST_ALG_HMAC_LAST;
|
|
|
|
i++) {
|
|
|
|
if (dst_algorithm_supported(i)) {
|
|
|
|
isc_buffer_putstr(b, " ");
|
|
|
|
isc_buffer_putstr(b, dst_hmac_algorithm_totext(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (unsigned char *s = isc_buffer_used(&sb); s != isc_buffer_used(b);
|
|
|
|
s++) {
|
|
|
|
*s = toupper(*s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 17:35:47 +10:00
|
|
|
static void
|
|
|
|
logit(isc_buffer_t *b) {
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_WARNING, "%.*s",
|
|
|
|
(int)isc_buffer_usedlength(b),
|
|
|
|
(char *)isc_buffer_base(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printit(isc_buffer_t *b) {
|
|
|
|
printf("%.*s\n", (int)isc_buffer_usedlength(b),
|
|
|
|
(char *)isc_buffer_base(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
format_supported_algorithms(void (*emit)(isc_buffer_t *b)) {
|
|
|
|
isc_buffer_t b;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
isc_buffer_putstr(&b, "DNSSEC algorithms:");
|
|
|
|
list_dnssec_algorithms(&b);
|
|
|
|
(*emit)(&b);
|
|
|
|
|
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
isc_buffer_putstr(&b, "DS algorithms:");
|
|
|
|
list_ds_algorithms(&b);
|
|
|
|
(*emit)(&b);
|
|
|
|
|
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
isc_buffer_putstr(&b, "HMAC algorithms:");
|
|
|
|
list_hmac_algorithms(&b);
|
|
|
|
(*emit)(&b);
|
|
|
|
|
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
isc_buffer_printf(&b, "TKEY mode 2 support (Diffie-Hellman): %s",
|
|
|
|
(dst_algorithm_supported(DST_ALG_DH) &&
|
|
|
|
dst_algorithm_supported(DST_ALG_HMACMD5))
|
|
|
|
? "yes"
|
|
|
|
: "non");
|
|
|
|
(*emit)(&b);
|
|
|
|
|
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
isc_buffer_printf(&b, "TKEY mode 3 support (GSS-API): %s",
|
|
|
|
dst_algorithm_supported(DST_ALG_GSSAPI) ? "yes"
|
|
|
|
: "no");
|
|
|
|
(*emit)(&b);
|
|
|
|
}
|
|
|
|
|
2019-02-05 14:27:03 -08:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
printversion(bool verbose) {
|
2019-02-05 16:08:26 -08:00
|
|
|
char rndcconf[PATH_MAX], *dot = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_mem_t *mctx = NULL;
|
2022-09-14 17:35:47 +10:00
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t b;
|
|
|
|
char buf[512];
|
|
|
|
#if defined(HAVE_GEOIP2)
|
2020-02-13 14:44:37 -08:00
|
|
|
cfg_parser_t *parser = NULL;
|
|
|
|
cfg_obj_t *config = NULL;
|
2019-11-05 12:56:58 +11:00
|
|
|
const cfg_obj_t *defaults = NULL, *obj = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_GEOIP2) */
|
2019-02-05 16:08:26 -08:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
printf("%s%s <id:%s>\n", PACKAGE_STRING, PACKAGE_DESCRIPTION,
|
|
|
|
PACKAGE_SRCID);
|
2019-02-05 14:27:03 -08:00
|
|
|
|
|
|
|
if (!verbose) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("running on %s\n", named_os_uname());
|
2018-08-07 16:46:53 +02:00
|
|
|
printf("built by %s with %s\n", PACKAGE_BUILDER, PACKAGE_CONFIGARGS);
|
2019-02-05 14:27:03 -08:00
|
|
|
#ifdef __clang__
|
|
|
|
printf("compiled by CLANG %s\n", __VERSION__);
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* ifdef __clang__ */
|
2019-02-05 14:27:03 -08:00
|
|
|
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
|
|
|
printf("compiled by ICC %s\n", __VERSION__);
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* if defined(__ICC) || defined(__INTEL_COMPILER) */
|
2019-02-05 14:27:03 -08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
printf("compiled by GCC %s\n", __VERSION__);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef __GNUC__ */
|
|
|
|
#endif /* if defined(__ICC) || defined(__INTEL_COMPILER) */
|
|
|
|
#endif /* ifdef __clang__ */
|
2019-02-05 14:27:03 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
printf("compiled by MSVC %d\n", _MSC_VER);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef _MSC_VER */
|
2019-02-05 14:27:03 -08:00
|
|
|
#ifdef __SUNPRO_C
|
|
|
|
printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef __SUNPRO_C */
|
2020-02-12 13:59:18 +01:00
|
|
|
printf("compiled with OpenSSL version: %s\n", OPENSSL_VERSION_TEXT);
|
2019-02-05 14:27:03 -08:00
|
|
|
#if !defined(LIBRESSL_VERSION_NUMBER) && \
|
2020-02-12 13:59:18 +01:00
|
|
|
OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 or higher */
|
2019-02-05 14:27:03 -08:00
|
|
|
printf("linked to OpenSSL version: %s\n",
|
|
|
|
OpenSSL_version(OPENSSL_VERSION));
|
|
|
|
|
2020-11-10 11:23:05 +01:00
|
|
|
#else /* if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= \
|
|
|
|
* 0x10100000L */
|
2019-02-05 14:27:03 -08:00
|
|
|
printf("linked to OpenSSL version: %s\n",
|
|
|
|
SSLeay_version(SSLEAY_VERSION));
|
|
|
|
#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
|
2020-07-24 17:04:02 -07:00
|
|
|
printf("compiled with libuv version: %d.%d.%d\n", UV_VERSION_MAJOR,
|
|
|
|
UV_VERSION_MINOR, UV_VERSION_PATCH);
|
|
|
|
printf("linked to libuv version: %s\n", uv_version_string());
|
2021-04-21 13:52:15 +02:00
|
|
|
#if HAVE_LIBNGHTTP2
|
|
|
|
nghttp2_info *nginfo = NULL;
|
2021-02-16 14:13:18 -08:00
|
|
|
printf("compiled with libnghttp2 version: %s\n", NGHTTP2_VERSION);
|
|
|
|
nginfo = nghttp2_version(1);
|
|
|
|
printf("linked to libnghttp2 version: %s\n", nginfo->version_str);
|
2021-04-21 13:52:15 +02:00
|
|
|
#endif
|
2019-02-05 14:27:03 -08:00
|
|
|
#ifdef HAVE_LIBXML2
|
2020-02-12 13:59:18 +01:00
|
|
|
printf("compiled with libxml2 version: %s\n", LIBXML_DOTTED_VERSION);
|
|
|
|
printf("linked to libxml2 version: %s\n", xmlParserVersion);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LIBXML2 */
|
2019-02-06 11:56:42 +01:00
|
|
|
#if defined(HAVE_JSON_C)
|
2020-02-12 13:59:18 +01:00
|
|
|
printf("compiled with json-c version: %s\n", JSON_C_VERSION);
|
|
|
|
printf("linked to json-c version: %s\n", json_c_version());
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_JSON_C) */
|
2019-02-05 14:27:03 -08:00
|
|
|
#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
|
2020-02-12 13:59:18 +01:00
|
|
|
printf("compiled with zlib version: %s\n", ZLIB_VERSION);
|
|
|
|
printf("linked to zlib version: %s\n", zlibVersion());
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_ZLIB) && defined(ZLIB_VERSION) */
|
2019-11-18 21:51:36 +01:00
|
|
|
#if defined(HAVE_GEOIP2)
|
|
|
|
/* Unfortunately, no version define on link time */
|
2020-02-12 13:59:18 +01:00
|
|
|
printf("linked to maxminddb version: %s\n", MMDB_lib_version());
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_GEOIP2) */
|
2019-11-18 22:14:20 +01:00
|
|
|
#if defined(HAVE_DNSTAP)
|
2020-02-12 13:59:18 +01:00
|
|
|
printf("compiled with protobuf-c version: %s\n", PROTOBUF_C_VERSION);
|
|
|
|
printf("linked to protobuf-c version: %s\n", protobuf_c_version());
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_DNSTAP) */
|
2022-09-14 17:35:47 +10:00
|
|
|
printf("threads support is enabled\n");
|
|
|
|
|
|
|
|
isc_mem_create(&mctx);
|
|
|
|
result = dst_lib_init(mctx, named_g_engine);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2022-09-14 17:35:47 +10:00
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
format_supported_algorithms(printit);
|
|
|
|
printf("\n");
|
|
|
|
} else {
|
|
|
|
printf("DST initialization failure: %s\n",
|
|
|
|
isc_result_totext(result));
|
2022-09-14 17:35:47 +10:00
|
|
|
}
|
2019-02-05 14:27:03 -08:00
|
|
|
|
2019-02-05 16:08:26 -08:00
|
|
|
/*
|
|
|
|
* The default rndc.conf and rndc.key paths are in the same
|
|
|
|
* directory, but named only has rndc.key defined internally.
|
2021-05-20 15:53:50 +02:00
|
|
|
* We construct the rndc.conf path from it.
|
2019-02-05 16:08:26 -08:00
|
|
|
*/
|
|
|
|
strlcpy(rndcconf, named_g_keyfile, sizeof(rndcconf));
|
|
|
|
dot = strrchr(rndcconf, '.');
|
|
|
|
if (dot != NULL) {
|
|
|
|
size_t len = dot - rndcconf + 1;
|
|
|
|
snprintf(dot + 1, PATH_MAX - len, "conf");
|
|
|
|
}
|
|
|
|
|
2019-02-05 14:27:03 -08:00
|
|
|
/*
|
|
|
|
* Print default configuration paths.
|
|
|
|
*/
|
|
|
|
printf("default paths:\n");
|
|
|
|
printf(" named configuration: %s\n", named_g_conffile);
|
2019-02-05 16:08:26 -08:00
|
|
|
printf(" rndc configuration: %s\n", rndcconf);
|
2019-02-05 14:27:03 -08:00
|
|
|
printf(" DNSSEC root key: %s\n", named_g_defaultbindkeys);
|
|
|
|
printf(" nsupdate session key: %s\n", named_g_defaultsessionkeyfile);
|
|
|
|
printf(" named PID file: %s\n", named_g_defaultpidfile);
|
|
|
|
printf(" named lock file: %s\n", named_g_defaultlockfile);
|
2019-11-05 12:56:58 +11:00
|
|
|
#if defined(HAVE_GEOIP2)
|
|
|
|
#define RTC(x) RUNTIME_CHECK((x) == ISC_R_SUCCESS)
|
|
|
|
RTC(cfg_parser_create(mctx, named_g_lctx, &parser));
|
|
|
|
RTC(named_config_parsedefaults(parser, &config));
|
|
|
|
RTC(cfg_map_get(config, "options", &defaults));
|
|
|
|
RTC(cfg_map_get(defaults, "geoip-directory", &obj));
|
|
|
|
if (cfg_obj_isstring(obj)) {
|
|
|
|
printf(" geoip-directory: %s\n", cfg_obj_asstring(obj));
|
|
|
|
}
|
|
|
|
cfg_obj_destroy(parser, &config);
|
|
|
|
cfg_parser_destroy(&parser);
|
|
|
|
isc_mem_detach(&mctx);
|
|
|
|
#endif /* HAVE_GEOIP2 */
|
2019-02-05 14:27:03 -08:00
|
|
|
}
|
|
|
|
|
2016-05-05 11:46:11 +02:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
parse_fuzz_arg(void) {
|
2016-05-05 11:46:11 +02:00
|
|
|
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'",
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_commandline_argument);
|
2016-05-05 11:46:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 13:26:59 +10:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
parse_T_opt(char *option) {
|
2018-06-06 13:26:59 +10:00
|
|
|
const char *p;
|
2020-02-13 14:44:37 -08:00
|
|
|
char *last = NULL;
|
2018-06-06 13:26:59 +10:00
|
|
|
/*
|
|
|
|
* force the server to behave (or misbehave) in
|
|
|
|
* specified ways for testing purposes.
|
|
|
|
* dscp=x: check that dscp values are as
|
|
|
|
* expected and assert otherwise.
|
|
|
|
*/
|
2020-01-21 10:58:42 +01:00
|
|
|
if (!strcmp(option, "dropedns")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
dropedns = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strncmp(option, "dscp=", 5)) {
|
|
|
|
isc_dscp_check_value = atoi(option + 5);
|
2018-07-26 17:53:15 +10:00
|
|
|
} else if (!strcmp(option, "ednsformerr")) {
|
|
|
|
ednsformerr = true;
|
|
|
|
} else if (!strcmp(option, "ednsnotimp")) {
|
|
|
|
ednsnotimp = true;
|
|
|
|
} else if (!strcmp(option, "ednsrefused")) {
|
|
|
|
ednsrefused = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "fixedlocal")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
fixedlocal = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "keepstderr")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
named_g_keepstderr = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "noaa")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
noaa = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "noedns")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
noedns = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "nonearest")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
nonearest = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "nosoa")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
nosoa = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "nosyslog")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
named_g_nosyslog = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "notcp")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
notcp = true;
|
2020-08-31 13:15:33 +02:00
|
|
|
} else if (!strncmp(option, "maxcachesize=", 13)) {
|
|
|
|
named_g_maxcachesize = atoi(option + 13);
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strcmp(option, "maxudp512")) {
|
|
|
|
maxudp = 512;
|
|
|
|
} else if (!strcmp(option, "maxudp1460")) {
|
|
|
|
maxudp = 1460;
|
|
|
|
} else if (!strncmp(option, "maxudp=", 7)) {
|
|
|
|
maxudp = atoi(option + 7);
|
2019-08-08 18:31:20 +10:00
|
|
|
if (maxudp <= 0) {
|
|
|
|
named_main_earlyfatal("bad maxudp");
|
|
|
|
}
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strncmp(option, "mkeytimers=", 11)) {
|
|
|
|
p = strtok_r(option + 11, "/", &last);
|
|
|
|
if (p == NULL) {
|
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_zone_mkey_hour = atoi(p);
|
|
|
|
if (dns_zone_mkey_hour == 0) {
|
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
|
|
|
}
|
|
|
|
|
|
|
|
p = strtok_r(NULL, "/", &last);
|
|
|
|
if (p == NULL) {
|
|
|
|
dns_zone_mkey_day = (24 * dns_zone_mkey_hour);
|
|
|
|
dns_zone_mkey_month = (30 * dns_zone_mkey_day);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_zone_mkey_day = atoi(p);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_zone_mkey_day < dns_zone_mkey_hour) {
|
2018-06-06 13:26:59 +10:00
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-06-06 13:26:59 +10:00
|
|
|
|
|
|
|
p = strtok_r(NULL, "/", &last);
|
|
|
|
if (p == NULL) {
|
|
|
|
dns_zone_mkey_month = (30 * dns_zone_mkey_day);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_zone_mkey_month = atoi(p);
|
|
|
|
if (dns_zone_mkey_month < dns_zone_mkey_day) {
|
|
|
|
named_main_earlyfatal("bad mkeytimer");
|
|
|
|
}
|
2018-05-03 16:43:15 +10:00
|
|
|
} else if (!strcmp(option, "sigvalinsecs")) {
|
2018-04-17 08:29:14 -07:00
|
|
|
sigvalinsecs = true;
|
2018-06-06 13:26:59 +10:00
|
|
|
} else if (!strncmp(option, "tat=", 4)) {
|
|
|
|
named_g_tat_interval = atoi(option + 4);
|
|
|
|
} else {
|
2018-07-26 17:53:15 +10:00
|
|
|
fprintf(stderr, "unknown -T flag '%s'\n", option);
|
2018-06-06 13:26:59 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 23:06:55 +02:00
|
|
|
static void
|
|
|
|
parse_port(char *arg) {
|
2020-09-16 12:21:32 -07:00
|
|
|
enum { DNSPORT, TLSPORT, HTTPSPORT, HTTPPORT } ptype = DNSPORT;
|
2020-10-12 23:06:55 +02:00
|
|
|
char *value = arg;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
if (strncmp(arg, "dns=", 4) == 0) {
|
|
|
|
value = arg + 4;
|
|
|
|
} else if (strncmp(arg, "tls=", 4) == 0) {
|
|
|
|
value = arg + 4;
|
|
|
|
ptype = TLSPORT;
|
2020-09-16 12:21:32 -07:00
|
|
|
} else if (strncmp(arg, "https=", 6) == 0) {
|
|
|
|
value = arg + 6;
|
|
|
|
ptype = HTTPSPORT;
|
|
|
|
} else if (strncmp(arg, "http=", 5) == 0) {
|
|
|
|
value = arg + 6;
|
|
|
|
ptype = HTTPPORT;
|
2020-10-12 23:06:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
port = parse_int(value, "port");
|
|
|
|
if (port < 1 || port > 65535) {
|
|
|
|
named_main_earlyfatal("port '%s' out of range", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ptype) {
|
|
|
|
case DNSPORT:
|
|
|
|
named_g_port = port;
|
|
|
|
break;
|
|
|
|
case TLSPORT:
|
|
|
|
named_g_tlsport = port;
|
|
|
|
break;
|
2020-09-16 12:21:32 -07:00
|
|
|
case HTTPSPORT:
|
|
|
|
named_g_httpsport = port;
|
|
|
|
break;
|
|
|
|
case HTTPPORT:
|
|
|
|
named_g_httpport = port;
|
|
|
|
break;
|
2020-10-12 23:06:55 +02:00
|
|
|
default:
|
2021-10-11 12:50:17 +02:00
|
|
|
UNREACHABLE();
|
2020-10-12 23:06:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
parse_command_line(int argc, char *argv[]) {
|
|
|
|
int ch;
|
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.
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
isc_commandline_errprint = false;
|
2020-02-13 14:44:37 -08: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':
|
2020-02-13 21:48:23 +01:00
|
|
|
if (disable4) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("cannot specify "
|
|
|
|
"-4 and -6");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (isc_net_probeipv4() != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("IPv4 not supported "
|
|
|
|
"by OS");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-01-16 03:59:28 +00:00
|
|
|
isc_net_disableipv6();
|
2018-04-17 08:29:14 -07:00
|
|
|
disable6 = true;
|
2003-01-16 03:59:28 +00:00
|
|
|
break;
|
|
|
|
case '6':
|
2020-02-13 21:48:23 +01:00
|
|
|
if (disable6) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("cannot specify "
|
|
|
|
"-4 and -6");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("IPv6 not supported "
|
|
|
|
"by OS");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-01-16 03:59:28 +00:00
|
|
|
isc_net_disableipv4();
|
2018-04-17 08:29:14 -07:00
|
|
|
disable4 = 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;
|
2018-04-17 08:29:14 -07:00
|
|
|
named_g_conffileset = true;
|
1999-07-24 01:17:44 +00:00
|
|
|
break;
|
2022-03-23 12:52:33 +01:00
|
|
|
case 'C':
|
|
|
|
printf("# Built-in default values. "
|
|
|
|
"This is NOT the run-time configuration!\n");
|
|
|
|
printf("%s", named_config_getdefault());
|
|
|
|
exit(0);
|
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,
|
2020-02-12 13:59:18 +01:00
|
|
|
"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':
|
2018-04-17 08:29:14 -07:00
|
|
|
named_g_foreground = true;
|
2000-01-26 17:35:16 +00:00
|
|
|
break;
|
2000-02-29 18:37:14 +00:00
|
|
|
case 'g':
|
2018-04-17 08:29:14 -07:00
|
|
|
named_g_foreground = true;
|
|
|
|
named_g_logstderr = 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':
|
2017-10-09 09:55:37 -07:00
|
|
|
set_flags(isc_commandline_argument, mem_context_flags,
|
|
|
|
&isc_mem_defaultflags);
|
2015-02-25 09:06:45 +05:30
|
|
|
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':
|
2020-02-17 12:05:39 -08:00
|
|
|
named_g_cpus = parse_int(isc_commandline_argument,
|
|
|
|
"number of cpus");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_cpus == 0) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_cpus = 1;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
break;
|
1999-09-09 02:19:11 +00:00
|
|
|
case 'p':
|
2020-10-12 23:06:55 +02:00
|
|
|
parse_port(isc_commandline_argument);
|
2000-10-04 23:19:01 +00:00
|
|
|
break;
|
1999-07-24 01:17:44 +00:00
|
|
|
case 's':
|
|
|
|
/* XXXRTH temporary syntax */
|
2018-04-17 08:29:14 -07:00
|
|
|
want_stats = true;
|
1999-07-24 01:17:44 +00:00
|
|
|
break;
|
2008-08-20 23:57:59 +00:00
|
|
|
case 'S':
|
2021-10-03 00:27:52 -07:00
|
|
|
/* Formerly maxsocks */
|
2008-08-20 23:57:59 +00:00
|
|
|
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;
|
2020-02-12 13:59:18 +01:00
|
|
|
case 'T': /* NOT DOCUMENTED */
|
2018-06-06 13:26:59 +10:00
|
|
|
parse_T_opt(isc_commandline_argument);
|
2008-01-02 05:03:07 +00:00
|
|
|
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':
|
2019-02-05 14:27:03 -08:00
|
|
|
printversion(false);
|
2000-08-30 20:40:04 +00:00
|
|
|
exit(0);
|
2008-09-23 17:25:47 +00:00
|
|
|
case 'V':
|
2019-02-05 14:27:03 -08:00
|
|
|
printversion(true);
|
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':
|
2018-04-17 08:29:14 -07:00
|
|
|
named_g_forcelock = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcasecmp(isc_commandline_argument, "none") != 0) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_defaultlockfile =
|
|
|
|
isc_commandline_argument;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_defaultlockfile = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-18 11:58:50 +05:30
|
|
|
break;
|
2009-05-07 09:33:52 +00:00
|
|
|
case 'F':
|
2021-10-11 12:09:16 +02:00
|
|
|
/* Reserved for FIPS mode */
|
|
|
|
FALLTHROUGH;
|
1999-10-25 18:58:43 +00:00
|
|
|
case '?':
|
2000-02-17 19:21:00 +00:00
|
|
|
usage();
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_commandline_option == '?') {
|
2007-05-21 02:47:25 +00:00
|
|
|
exit(0);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
p = strchr(NAMED_MAIN_ARGS, isc_commandline_option);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (p == NULL || *++p != ':') {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("unknown option '-%c'",
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_commandline_option);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("option '-%c' requires "
|
2020-02-12 13:59:18 +01:00
|
|
|
"an argument",
|
|
|
|
isc_commandline_option);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2021-10-11 12:09:16 +02: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
|
2020-02-13 14:44:37 -08:00
|
|
|
create_managers(void) {
|
2022-07-26 13:03:45 +02:00
|
|
|
/*
|
|
|
|
* Set the default named_g_cpus if it was not set from the command line
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
INSIST(named_g_cpus_detected > 0);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_cpus == 0) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_cpus = named_g_cpus_detected;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2022-07-26 13:03:45 +02:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
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");
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_udpdisp == 0) {
|
2018-08-22 15:41:28 +02:00
|
|
|
named_g_udpdisp = named_g_cpus_detected;
|
2014-02-19 21:54:43 -08:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_udpdisp > named_g_cpus) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_udpdisp = named_g_cpus;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
2020-02-12 13:59:18 +01:00
|
|
|
"using %u UDP listener%s per interface", named_g_udpdisp,
|
|
|
|
named_g_udpdisp == 1 ? "" : "s");
|
2011-11-09 18:44:04 +00:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_managers_create(&named_g_mctx, named_g_cpus, &named_g_loopmgr,
|
|
|
|
&named_g_netmgr, &named_g_taskmgr);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2021-04-27 00:07:43 +02:00
|
|
|
isc_nm_maxudp(named_g_netmgr, maxudp);
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
setup(void) {
|
|
|
|
isc_result_t result;
|
2008-10-24 01:24:54 +00:00
|
|
|
isc_resourcevalue_t old_openfiles;
|
2020-02-13 14:44:37 -08:00
|
|
|
ns_server_t *sctx;
|
2005-04-05 00:58:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
|
|
|
char *instance = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LIBSCF */
|
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. */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_smf_got_instance = 1;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_smf_got_instance = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (instance != NULL) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_free(named_g_mctx, instance);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2005-04-05 00:58:16 +00:00
|
|
|
#endif /* HAVE_LIBSCF */
|
|
|
|
|
2008-10-24 01:08:21 +00:00
|
|
|
/*
|
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();
|
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
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = named_log_init(named_g_username != NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("named_log_init() failed: %s",
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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().
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!named_g_foreground) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_os_daemonize();
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-01-26 21:13:19 +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,
|
2018-08-07 16:46:53 +02:00
|
|
|
"starting %s%s <id:%s>", PACKAGE_STRING,
|
|
|
|
PACKAGE_DESCRIPTION, PACKAGE_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,
|
2020-02-12 13:59:18 +01:00
|
|
|
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,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE, "built with %s",
|
2018-08-07 16:46:53 +02:00
|
|
|
PACKAGE_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,
|
2020-02-12 13:59:18 +01:00
|
|
|
"running as: %s%s%s", program_name, saved_command_line,
|
|
|
|
ellipsis);
|
2018-05-08 16:09:18 +10:00
|
|
|
#ifdef __clang__
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled by CLANG %s", __VERSION__);
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* ifdef __clang__ */
|
2018-05-08 16:09:18 +10:00
|
|
|
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled by ICC %s", __VERSION__);
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* if defined(__ICC) || defined(__INTEL_COMPILER) */
|
2018-05-08 16:09:18 +10:00
|
|
|
#ifdef __GNUC__
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled by GCC %s", __VERSION__);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef __GNUC__ */
|
|
|
|
#endif /* if defined(__ICC) || defined(__INTEL_COMPILER) */
|
|
|
|
#endif /* ifdef __clang__ */
|
2018-05-08 16:09:18 +10:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled by MSVC %d", _MSC_VER);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef _MSC_VER */
|
2018-05-08 16:09:18 +10:00
|
|
|
#ifdef __SUNPRO_C
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled by Solaris Studio %x", __SUNPRO_C);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef __SUNPRO_C */
|
2018-05-08 16:09:18 +10:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled with OpenSSL version: %s",
|
2018-06-12 11:26:04 +02:00
|
|
|
OPENSSL_VERSION_TEXT);
|
2018-05-08 16:09:18 +10:00
|
|
|
#if !defined(LIBRESSL_VERSION_NUMBER) && \
|
2020-02-12 13:59:18 +01:00
|
|
|
OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 or higher */
|
2018-05-08 16:09:18 +10:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"linked to OpenSSL version: %s",
|
|
|
|
OpenSSL_version(OPENSSL_VERSION));
|
2020-11-10 11:23:05 +01:00
|
|
|
#else /* if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= \
|
|
|
|
* 0x10100000L */
|
2018-05-08 16:09:18 +10:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"linked to OpenSSL version: %s",
|
|
|
|
SSLeay_version(SSLEAY_VERSION));
|
|
|
|
#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
|
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled with libxml2 version: %s",
|
|
|
|
LIBXML_DOTTED_VERSION);
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"linked to libxml2 version: %s", xmlParserVersion);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LIBXML2 */
|
2019-02-06 11:56:42 +01:00
|
|
|
#if defined(HAVE_JSON_C)
|
2018-05-08 16:09:18 +10:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2019-02-06 11:56:42 +01:00
|
|
|
"compiled with json-c version: %s", JSON_C_VERSION);
|
2018-05-08 16:09:18 +10:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
2019-02-06 11:56:42 +01:00
|
|
|
"linked to json-c version: %s", json_c_version());
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_JSON_C) */
|
2018-05-08 16:09:18 +10:00
|
|
|
#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"compiled with zlib version: %s", ZLIB_VERSION);
|
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
|
|
|
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
|
|
|
|
"linked to zlib version: %s", zlibVersion());
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(HAVE_ZLIB) && defined(ZLIB_VERSION) */
|
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
|
|
|
"----------------------------------------------------");
|
|
|
|
|
2000-11-14 23:59:21 +00:00
|
|
|
/*
|
|
|
|
* Get the initial resource limits.
|
|
|
|
*/
|
2018-10-13 12:10:43 +02:00
|
|
|
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_stacksize,
|
2020-02-12 13:59:18 +01:00
|
|
|
&named_g_initstacksize) ==
|
|
|
|
ISC_R_SUCCESS);
|
2018-10-13 12:10:43 +02:00
|
|
|
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_datasize,
|
2020-02-12 13:59:18 +01:00
|
|
|
&named_g_initdatasize) ==
|
|
|
|
ISC_R_SUCCESS);
|
2018-10-13 12:10:43 +02:00
|
|
|
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_coresize,
|
2020-02-12 13:59:18 +01:00
|
|
|
&named_g_initcoresize) ==
|
|
|
|
ISC_R_SUCCESS);
|
2018-10-13 12:10:43 +02:00
|
|
|
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_openfiles,
|
2020-02-12 13:59:18 +01:00
|
|
|
&named_g_initopenfiles) ==
|
|
|
|
ISC_R_SUCCESS);
|
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();
|
2018-10-13 12:10:43 +02:00
|
|
|
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_openfiles,
|
2020-02-12 13:59:18 +01:00
|
|
|
&named_g_initopenfiles) ==
|
|
|
|
ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
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 "
|
2018-03-28 14:56:40 +02:00
|
|
|
"%" PRIu64 " to "
|
|
|
|
"%" PRIu64,
|
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.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
if (!isc_file_isabsolute(named_g_conffile)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_file_absolutepath(named_g_conffile,
|
2001-07-16 17:32:49 +00:00
|
|
|
absolute_conffile,
|
|
|
|
sizeof(absolute_conffile));
|
2020-02-13 21:48:23 +01: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));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
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);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("isc_time_now() failed: %s",
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-21 06:03:37 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
result = create_managers();
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("create_managers() failed: %s",
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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
|
|
|
/*
|
|
|
|
* Register the DLZ "dlopen" driver.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
result = dlz_dlopen_init(named_g_mctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("dlz_dlopen_init() failed: %s",
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-03-10 04:36:16 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_server_create(named_g_mctx, &named_g_server);
|
2020-03-25 17:25:45 +01:00
|
|
|
ENSURE(named_g_server != NULL);
|
2017-09-08 13:39:09 -07:00
|
|
|
sctx = named_g_server->sctx;
|
|
|
|
|
2022-09-14 18:33:42 +10:00
|
|
|
/*
|
|
|
|
* Report supported algorithms now that dst_lib_init() has
|
|
|
|
* been called via named_server_create().
|
|
|
|
*/
|
2022-09-14 17:35:47 +10:00
|
|
|
format_supported_algorithms(logit);
|
2022-09-14 18:33:42 +10:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
/*
|
|
|
|
* Modify server context according to command line options
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (disable4) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_DISABLE4, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (disable6) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_DISABLE6, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (dropedns) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_DROPEDNS, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (ednsformerr) { /* STD13 server */
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_EDNSFORMERR, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (ednsnotimp) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_EDNSNOTIMP, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (ednsrefused) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_EDNSREFUSED, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (fixedlocal) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_FIXEDLOCAL, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (noaa) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOAA, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (noedns) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOEDNS, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (nonearest) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_NONEAREST, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (nosoa) {
|
2018-07-26 17:53:15 +10:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOSOA, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (notcp) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_NOTCP, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (sigvalinsecs) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ns_server_setoption(sctx, NS_SERVER_SIGVALINSECS, true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
cleanup(void) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_mapped != NULL) {
|
2017-09-08 13:39:09 -07:00
|
|
|
dns_acl_detach(&named_g_mapped);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2016-07-11 14:11:34 +10: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
|
|
|
/*
|
|
|
|
* Unregister "dlopen" DLZ driver.
|
|
|
|
*/
|
|
|
|
dlz_dlopen_clear();
|
2005-09-05 00:12:29 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
2020-02-12 13:59:18 +01:00
|
|
|
NAMED_LOGMODULE_MAIN, 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
|
2020-02-13 14:44:37 -08: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
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (filename == NULL) {
|
2001-09-07 00:37:02 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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
|
2020-02-13 14:44:37 -08: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;
|
2020-02-13 14:44:37 -08:00
|
|
|
int namelen;
|
|
|
|
char *instance;
|
2005-04-05 00:58:16 +00:00
|
|
|
|
|
|
|
REQUIRE(ins_name != NULL && *ins_name == NULL);
|
2004-09-01 07:25:51 +00:00
|
|
|
|
|
|
|
if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debug) {
|
2005-04-05 00:58:16 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_handle_create() failed: %s",
|
2008-01-18 23:46:58 +00:00
|
|
|
scf_strerror(scf_error()));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debug) {
|
2005-04-05 00:58:16 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_handle_bind() failed: %s",
|
|
|
|
scf_strerror(scf_error()));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debug) {
|
2005-04-05 00:58:16 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_myname() failed: %s",
|
|
|
|
scf_strerror(scf_error()));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debug) {
|
2005-04-05 00:58:16 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"scf_myname() failed: %s",
|
|
|
|
scf_strerror(scf_error()));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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
|
2020-02-13 14:44:37 -08:00
|
|
|
main(int argc, char *argv[]) {
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_t result;
|
2005-04-29 00:36:16 +00:00
|
|
|
#ifdef HAVE_LIBSCF
|
|
|
|
char *instance = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LIBSCF */
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2014-10-08 15:14:02 +02:00
|
|
|
#ifdef HAVE_GPERFTOOLS_PROFILER
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)ProfilerStart(NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */
|
2014-10-08 15:14:02 +02:00
|
|
|
|
2021-06-22 13:05:15 +02:00
|
|
|
/*
|
|
|
|
* Technically, this call is superfluous because on startup of the main
|
|
|
|
* program, the portable "C" locale is selected by default. This
|
|
|
|
* explicit call here is for a reference that the BIND 9 code base is
|
|
|
|
* not locale aware and the locale MUST be set to "C" (or "POSIX") when
|
|
|
|
* calling any BIND 9 library code. If you are calling external
|
|
|
|
* libraries that use locale, such calls must be wrapped into
|
|
|
|
* setlocale(LC_ALL, ""); before the call and setlocale(LC_ALL, "C");
|
|
|
|
* after the call, and no BIND 9 library calls must be made in between.
|
|
|
|
*/
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
|
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__)
|
2018-08-07 16:46:53 +02:00
|
|
|
"named version: BIND " PACKAGE_VERSION " <" PACKAGE_SRCID ">",
|
|
|
|
#else
|
|
|
|
"named version: BIND " PACKAGE_VERSION " <" PACKAGE_SRCID
|
|
|
|
"> (" __DATE__ ")",
|
|
|
|
#endif
|
2004-04-20 06:53:52 +00:00
|
|
|
sizeof(version));
|
2001-05-31 10:37:08 +00:00
|
|
|
result = isc_file_progname(*argv, program_name, sizeof(program_name));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlyfatal("program name too long");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-05-08 19:47:55 +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
|
|
|
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);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ENABLE_AFL */
|
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] == '/' ||
|
2020-02-13 14:44:37 -08:00
|
|
|
named_g_conffile[len] == '\\'))
|
|
|
|
{
|
2017-09-08 13:39:09 -07:00
|
|
|
named_main_earlywarning("config filename (-c %s) "
|
|
|
|
"contains chroot path (-t %s)",
|
|
|
|
named_g_conffile,
|
|
|
|
named_g_chrootdir);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-09-14 12:34:03 +00:00
|
|
|
}
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
setup();
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_mem_setname(named_g_mctx, "main");
|
2022-09-15 18:04:52 +10:00
|
|
|
INSIST(named_g_server != NULL);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
/*
|
2022-07-26 13:03:45 +02:00
|
|
|
* Start things running
|
1999-07-24 01:17:44 +00:00
|
|
|
*/
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_signal_start(named_g_server->sighup);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loopmgr_run(named_g_loopmgr);
|
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) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (smf_disable_instance(instance, 0) != 0) {
|
2005-04-29 00:36:16 +00:00
|
|
|
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()));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2005-04-29 00:36:16 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (instance != NULL) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_mem_free(named_g_mctx, instance);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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
|
|
|
}
|
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);
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)isc_stdio_close(fp);
|
2001-09-06 02:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-26 13:03:45 +02:00
|
|
|
|
|
|
|
isc_managers_destroy(&named_g_mctx, &named_g_loopmgr, &named_g_netmgr,
|
|
|
|
&named_g_taskmgr);
|
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
|
|
|
|
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();
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */
|
2014-10-08 15:14:02 +02:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|