isc_result_t named_log_setsafechannels(isc_logconfig_t *lcfg) { isc_result_t result; isc_logdestination_t destination; if (! named_g_logstderr) { result = isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TONULL, ISC_LOG_DYNAMIC, NULL, 0); if (result != ISC_R_SUCCESS) goto cleanup; /* * Setting the debug level to zero should get the output * discarded a bit faster. */ isc_log_setdebuglevel(named_g_lctx, 0); } else { isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); } if (named_g_logfile != NULL) { destination.file.stream = NULL; destination.file.name = named_g_logfile; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTCATEGORY| ISC_LOG_PRINTLEVEL); if (result != ISC_R_SUCCESS) goto cleanup; } #if ISC_FACILITY != LOG_DAEMON destination.facility = ISC_FACILITY; result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, ISC_LOG_INFO, &destination, 0); if (result != ISC_R_SUCCESS) goto cleanup; #endif result = ISC_R_SUCCESS; cleanup: return (result); }
isc_result_t named_log_setdefaultchannels(isc_logconfig_t *lcfg) { isc_result_t result; isc_logdestination_t destination; /* * By default, the logging library makes "default_debug" log to * stderr. In BIND, we want to override this and log to named.run * instead, unless the -g option was given. */ if (! named_g_logstderr) { destination.file.stream = NULL; destination.file.name = "named.run"; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_DEBUGONLY); if (result != ISC_R_SUCCESS) goto cleanup; } if (named_g_logfile != NULL) { destination.file.stream = NULL; destination.file.name = named_g_logfile; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTCATEGORY| ISC_LOG_PRINTLEVEL); if (result != ISC_R_SUCCESS) goto cleanup; } #if ISC_FACILITY != LOG_DAEMON destination.facility = ISC_FACILITY; result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, ISC_LOG_INFO, &destination, 0); if (result != ISC_R_SUCCESS) goto cleanup; #endif /* * Set the initial debug level. */ isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); result = ISC_R_SUCCESS; cleanup: return (result); }
static void log_init(void) { isc_logdestination_t destination; unsigned int flags; /* * Setup a logging context. */ RUNTIME_CHECK(isc_log_create(mctx, &lctx, &lcfg) == ISC_R_SUCCESS); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; flags = ISC_LOG_PRINTTIME; RUNTIME_CHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, flags) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) == ISC_R_SUCCESS); isc_log_setdebuglevel(lctx, level); }
isc_result_t ns_log_setsafechannels(isc_logconfig_t *lcfg) { isc_result_t result; #if ISC_FACILITY != LOG_DAEMON isc_logdestination_t destination; #endif if (! ns_g_logstderr) { result = isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TONULL, ISC_LOG_DYNAMIC, NULL, 0); if (result != ISC_R_SUCCESS) goto cleanup; /* * Setting the debug level to zero should get the output * discarded a bit faster. */ isc_log_setdebuglevel(ns_g_lctx, 0); } else { isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel); } #if ISC_FACILITY != LOG_DAEMON destination.facility = ISC_FACILITY; result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, ISC_LOG_INFO, &destination, 0); if (result != ISC_R_SUCCESS) goto cleanup; #endif result = ISC_R_SUCCESS; cleanup: return (result); }
int main(int argc, char **argv) { isc_result_t result; isc_logdestination_t destination; UNUSED(argc); UNUSED(argv); dns_result_register(); result = isc_app_start(); check_result(result, "isc_app_start()"); isc_stdtime_get(&now); result = isc_mutex_init(&client_lock); check_result(result, "isc_mutex_init(&client_lock)"); ISC_LIST_INIT(clients); /* * EVERYTHING needs a memory context. */ RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); cmp = NULL; RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp) == ISC_R_SUCCESS); isc_mempool_setname(cmp, "adb test clients"); result = isc_entropy_create(mctx, &ectx); check_result(result, "isc_entropy_create()"); result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE); check_result(result, "isc_hash_create()"); result = isc_log_create(mctx, &lctx, &lcfg); check_result(result, "isc_log_create()"); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME); check_result(result, "isc_log_createchannel()"); result = isc_log_usechannel(lcfg, "_default", NULL, NULL); check_result(result, "isc_log_usechannel()"); /* * Set the initial debug level. */ isc_log_setdebuglevel(lctx, 2); create_managers(); t1 = NULL; result = isc_task_create(taskmgr, 0, &t1); check_result(result, "isc_task_create t1"); t2 = NULL; result = isc_task_create(taskmgr, 0, &t2); check_result(result, "isc_task_create t2"); printf("task 1 = %p\n", t1); printf("task 2 = %p\n", t2); create_view(); adb = view->adb; /* * Lock the entire client list here. This will cause all events * for found names to block as well. */ CLOCK(); lookup("f.root-servers.net."); /* Should be in hints */ lookup("www.iengines.com"); /* should fetch */ lookup("www.isc.org"); /* should fetch */ lookup("www.flame.org"); /* should fetch */ lookup("kechara.flame.org."); /* should fetch */ lookup("moghedien.flame.org."); /* should fetch */ lookup("mailrelay.flame.org."); /* should fetch */ lookup("ipv4v6.flame.org."); /* should fetch */ lookup("nonexistant.flame.org."); /* should fail to be found */ lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */ lookup("i.root-servers.net."); /* Should be in hints */ lookup("www.firstcard.com."); lookup("dns04.flame.org."); CUNLOCK(); sleep(10); dns_adb_dump(adb, stderr); sleep(10); CLOCK(); lookup("f.root-servers.net."); /* Should be in hints */ lookup("www.iengines.com"); /* should fetch */ lookup("www.isc.org"); /* should fetch */ lookup("www.flame.org"); /* should fetch */ lookup("kechara.flame.org."); /* should fetch */ lookup("moghedien.flame.org."); /* should fetch */ lookup("mailrelay.flame.org."); /* should fetch */ lookup("ipv4v6.flame.org."); /* should fetch */ lookup("nonexistant.flame.org."); /* should fail to be found */ lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */ lookup("i.root-servers.net."); /* Should be in hints */ CUNLOCK(); sleep(20); dns_adb_dump(adb, stderr); isc_task_detach(&t1); isc_task_detach(&t2); isc_mem_stats(mctx, stdout); dns_adb_dump(adb, stderr); isc_app_run(); dns_adb_dump(adb, stderr); dns_view_detach(&view); adb = NULL; fprintf(stderr, "Destroying socket manager\n"); isc_socketmgr_destroy(&socketmgr); fprintf(stderr, "Destroying timer manager\n"); isc_timermgr_destroy(&timermgr); fprintf(stderr, "Destroying task manager\n"); isc_taskmgr_destroy(&taskmgr); isc_log_destroy(&lctx); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mempool_destroy(&cmp); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
/*% * This function is called to process the incoming command * when a control channel message is received. */ isc_result_t ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { isccc_sexpr_t *data; char *command = NULL; isc_result_t result; int log_level; #ifdef HAVE_LIBSCF ns_smf_want_disable = 0; #endif data = isccc_alist_lookup(message, "_data"); if (data == NULL) { /* * No data section. */ return (ISC_R_FAILURE); } result = isccc_cc_lookupstring(data, "type", &command); if (result != ISC_R_SUCCESS) { /* * We have no idea what this is. */ return (result); } /* * Compare the 'command' parameter against all known control commands. */ if (command_compare(command, NS_COMMAND_NULL) || command_compare(command, NS_COMMAND_STATUS)) { log_level = ISC_LOG_DEBUG(1); } else { log_level = ISC_LOG_INFO; } isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, log_level, "received control channel command '%s'", command); if (command_compare(command, NS_COMMAND_RELOAD)) { result = ns_server_reloadcommand(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_RECONFIG)) { result = ns_server_reconfigcommand(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_REFRESH)) { result = ns_server_refreshcommand(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_RETRANSFER)) { result = ns_server_retransfercommand(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_HALT)) { #ifdef HAVE_LIBSCF /* * If we are managed by smf(5), AND in chroot, then * we cannot connect to the smf repository, so just * return with an appropriate message back to rndc. */ if (ns_smf_got_instance == 1 && ns_smf_chroot == 1) { result = ns_smf_add_message(text); return (result); } /* * If we are managed by smf(5) but not in chroot, * try to disable ourselves the smf way. */ if (ns_smf_got_instance == 1 && ns_smf_chroot == 0) ns_smf_want_disable = 1; /* * If ns_smf_got_instance = 0, ns_smf_chroot * is not relevant and we fall through to * isc_app_shutdown below. */ #endif /* Do not flush master files */ ns_server_flushonshutdown(ns_g_server, ISC_FALSE); ns_os_shutdownmsg(command, text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_STOP)) { /* * "stop" is the same as "halt" except it does * flush master files. */ #ifdef HAVE_LIBSCF if (ns_smf_got_instance == 1 && ns_smf_chroot == 1) { result = ns_smf_add_message(text); return (result); } if (ns_smf_got_instance == 1 && ns_smf_chroot == 0) ns_smf_want_disable = 1; #endif ns_server_flushonshutdown(ns_g_server, ISC_TRUE); ns_os_shutdownmsg(command, text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) { result = ns_server_dumpstats(ns_g_server); } else if (command_compare(command, NS_COMMAND_QUERYLOG)) { result = ns_server_togglequerylog(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_DUMPDB)) { ns_server_dumpdb(ns_g_server, command); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_SECROOTS)) { result = ns_server_dumpsecroots(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_TRACE)) { result = ns_server_setdebuglevel(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_NOTRACE)) { ns_g_debuglevel = 0; isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_FLUSH)) { result = ns_server_flushcache(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_FLUSHNAME)) { result = ns_server_flushnode(ns_g_server, command, ISC_FALSE); } else if (command_compare(command, NS_COMMAND_FLUSHTREE)) { result = ns_server_flushnode(ns_g_server, command, ISC_TRUE); } else if (command_compare(command, NS_COMMAND_STATUS)) { result = ns_server_status(ns_g_server, text); } else if (command_compare(command, NS_COMMAND_TSIGLIST)) { result = ns_server_tsiglist(ns_g_server, text); } else if (command_compare(command, NS_COMMAND_TSIGDELETE)) { result = ns_server_tsigdelete(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_FREEZE)) { result = ns_server_freeze(ns_g_server, ISC_TRUE, command, text); } else if (command_compare(command, NS_COMMAND_UNFREEZE) || command_compare(command, NS_COMMAND_THAW)) { result = ns_server_freeze(ns_g_server, ISC_FALSE, command, text); } else if (command_compare(command, NS_COMMAND_SCAN)) { result = ISC_R_SUCCESS; ns_server_scan_interfaces(ns_g_server); } else if (command_compare(command, NS_COMMAND_SYNC)) { result = ns_server_sync(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_RECURSING)) { result = ns_server_dumprecursing(ns_g_server); } else if (command_compare(command, NS_COMMAND_TIMERPOKE)) { result = ISC_R_SUCCESS; isc_timermgr_poke(ns_g_timermgr); } else if (command_compare(command, NS_COMMAND_NULL)) { result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_NOTIFY)) { result = ns_server_notifycommand(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_VALIDATION)) { result = ns_server_validation(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_SIGN) || command_compare(command, NS_COMMAND_LOADKEYS)) { result = ns_server_rekey(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_ADDZONE)) { result = ns_server_add_zone(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_DELZONE)) { result = ns_server_del_zone(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_SIGNING)) { result = ns_server_signing(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_ZONESTATUS)) { result = ns_server_zonestatus(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_NTA)) { result = ns_server_nta(ns_g_server, command, text); } else { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, ISC_LOG_WARNING, "unknown control channel command '%s'", command); result = DNS_R_UNKNOWNCOMMAND; } return (result); }
int main(int argc, char **argv) { const char *progname, *syslog_file, *message; int ch, i, file_versions, stderr_line; isc_boolean_t show_final_mem = ISC_FALSE; isc_log_t *lctx; isc_logconfig_t *lcfg; isc_mem_t *mctx; isc_result_t result; isc_logdestination_t destination; const isc_logcategory_t *category; const isc_logmodule_t *module; progname = strrchr(*argv, '/'); if (progname != NULL) progname++; else progname = *argv; syslog_file = SYSLOG_FILE; file_versions = FILE_VERSIONS; while ((ch = isc_commandline_parse(argc, argv, "ms:r:")) != -1) { switch (ch) { case 'm': show_final_mem = ISC_TRUE; break; case 's': syslog_file = isc_commandline_argument; break; case 'r': file_versions = atoi(isc_commandline_argument); if (file_versions < 0 && file_versions != ISC_LOG_ROLLNEVER && file_versions != ISC_LOG_ROLLINFINITE) { fprintf(stderr, "%s: file rotations must be " "%d (ISC_LOG_ROLLNEVER),\n\t" "%d (ISC_LOG_ROLLINFINITE) " "or > 0\n", progname, ISC_LOG_ROLLNEVER, ISC_LOG_ROLLINFINITE); exit(1); } break; case '?': fprintf(stderr, usage, progname); exit(1); } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc > 0) { fprintf(stderr, usage, progname); exit(1); } fprintf(stderr, "EXPECT:\n%s%d%s%s%s", "8 lines to stderr (first 4 numbered, #3 repeated)\n", file_versions == 0 || file_versions == ISC_LOG_ROLLNEVER ? 1 : file_versions > 0 ? file_versions + 1 : FILE_VERSIONS + 1, " " TEST_FILE " files, and\n", "2 lines to syslog\n", "lines ending with exclamation marks are errors\n\n"); isc_log_opensyslog(progname, LOG_PID, LOG_DAEMON); mctx = NULL; lctx = NULL; lcfg = NULL; CHECK(isc_mem_create(0, 0, &mctx)); CHECK(isc_log_create(mctx, &lctx, &lcfg)); CHECK(isc_log_settag(lcfg, progname)); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Test isc_log_categorybyname and isc_log_modulebyname. */ category = isc_log_categorybyname(lctx, "notify"); if (category != NULL) fprintf(stderr, "%s category found. (expected)\n", category->name); else fprintf(stderr, "notify category not found!\n"); module = isc_log_modulebyname(lctx, "xyzzy"); if (module != NULL) fprintf(stderr, "%s module found!\n", module->name); else fprintf(stderr, "xyzzy module not found. (expected)\n"); /* * Create a file channel to test file opening, size limiting and * version rolling. */ destination.file.name = TEST_FILE; destination.file.maximum_size = 1; destination.file.versions = file_versions; CHECK(isc_log_createchannel(lcfg, "file_test", ISC_LOG_TOFILE, ISC_LOG_INFO, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTTAG| ISC_LOG_PRINTLEVEL| ISC_LOG_PRINTCATEGORY| ISC_LOG_PRINTMODULE)); /* * Create a dynamic debugging channel to a file descriptor. */ destination.file.stream = stderr; CHECK(isc_log_createchannel(lcfg, "debug_test", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTLEVEL| ISC_LOG_DEBUGONLY)); /* * Test the usability of the four predefined logging channels. */ CHECK(isc_log_usechannel(lcfg, "default_syslog", DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE)); CHECK(isc_log_usechannel(lcfg, "default_stderr", DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE)); CHECK(isc_log_usechannel(lcfg, "default_debug", DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE)); CHECK(isc_log_usechannel(lcfg, "null", DNS_LOGCATEGORY_DATABASE, NULL)); /* * Use the custom channels. */ CHECK(isc_log_usechannel(lcfg, "file_test", DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB)); CHECK(isc_log_usechannel(lcfg, "debug_test", DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB)); fprintf(stderr, "\n==> stderr begin\n"); /* * Write to the internal default by testing both a category for which * no channel has been specified and a category which was specified * but not with the named module. */ stderr_line = 1; isc_log_write(lctx, DNS_LOGCATEGORY_SECURITY, DNS_LOGMODULE_RBT, ISC_LOG_CRITICAL, "%s (%d)", "Unspecified category and unspecified module to stderr", stderr_line++); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBT, ISC_LOG_CRITICAL, "%s (%d)", "Specified category and unspecified module to stderr", stderr_line++); /* * Write to default_syslog, default_stderr and default_debug. */ isc_log_write(lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_WARNING, "%s (%d twice)", "Using the predefined channels to syslog+stderr", stderr_line++); /* * Write to predefined null channel. */ isc_log_write(lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_RBTDB, ISC_LOG_INFO, "This is to null and should not appear!"); /* * Reset the internal default to use syslog instead of stderr, * and test it. */ CHECK(isc_log_usechannel(lcfg, "default_syslog", ISC_LOGCATEGORY_DEFAULT, NULL)); isc_log_write(lctx, DNS_LOGCATEGORY_SECURITY, DNS_LOGMODULE_RBT, ISC_LOG_ERROR, "%s%s", "This message to the redefined default category should ", "be second in syslog"); /* * Write to the file channel. */ if (file_versions >= 0 || file_versions == ISC_LOG_ROLLINFINITE) { /* * If file_versions is 0 or ISC_LOG_ROLLINFINITE, write * the "should not appear" and "should be in file" messages * to ensure they get rolled. */ if (file_versions <= 0) file_versions = FILE_VERSIONS; else isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "This should be rolled over " "and not appear!"); for (i = file_versions - 1; i >= 0; i--) isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "should be in file %d/%d", i, file_versions - 1); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "should be in base file"); } else { file_versions = FILE_VERSIONS; for (i = 1; i <= file_versions; i++) isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "This is message %d in the log file", i); } /* * Write a debugging message to a category that has no * debugging channels for the named module. */ isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_DEBUG(1), "This debug message should not appear!"); /* * Write debugging messages to a dynamic debugging channel. */ isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, "This critical message should " "not appear because the debug level is 0!"); isc_log_setdebuglevel(lctx, 3); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_DEBUG(1), "%s (%d)", "Dynamic debugging to stderr", stderr_line++); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_DEBUG(5), "This debug level is too high and should not appear!"); /* * Test out the duplicate filtering using the debug_test channel. */ isc_log_setduplicateinterval(lcfg, 10); message = "This message should appear only once on stderr"; isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, "%s", message); isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, message); isc_log_setduplicateinterval(lcfg, 1); message = "This message should appear twice on stderr"; isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, message); sleep(2); isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, message); /* * Review where everything went. * XXXDCL NT */ fputc('\n', stderr); system("head " TEST_FILE "*; rm -f " TEST_FILE "*"); freopen(syslog_file, "r", stdin); fprintf(stderr, "\n==> %s <==\n", syslog_file); system("tail -2"); fputc('\n', stderr); isc_log_destroy(&lctx); if (show_final_mem) isc_mem_stats(mctx, stderr); return (0); }
int main(int argc, char **argv) { isc_result_t result; isc_mem_t *mctx = NULL; isc_log_t *lctx = NULL; isc_logconfig_t *lcfg = NULL; isc_logdestination_t destination; cfg_parser_t *pctx = NULL; cfg_obj_t *cfg = NULL; cfg_type_t *type = NULL; isc_boolean_t grammar = ISC_FALSE; isc_boolean_t memstats = ISC_FALSE; char *filename = NULL; RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); result = isc_log_create(mctx, &lctx, &lcfg); check_result(result, "isc_log_create()"); isc_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME); check_result(result, "isc_log_createchannel()"); result = isc_log_usechannel(lcfg, "_default", NULL, NULL); check_result(result, "isc_log_usechannel()"); /* * Set the initial debug level. */ isc_log_setdebuglevel(lctx, 2); if (argc < 3) usage(); while (argc > 1) { if (strcmp(argv[1], "--grammar") == 0) { grammar = ISC_TRUE; } else if (strcmp(argv[1], "--memstats") == 0) { memstats = ISC_TRUE; } else if (strcmp(argv[1], "--named") == 0) { type = &cfg_type_namedconf; } else if (strcmp(argv[1], "--rndc") == 0) { type = &cfg_type_rndcconf; } else if (argv[1][0] == '-') { usage(); } else { filename = argv[1]; } argv++, argc--; } if (grammar) { if (type == NULL) usage(); cfg_print_grammar(type, output, NULL); } else { if (type == NULL || filename == NULL) usage(); RUNTIME_CHECK(cfg_parser_create(mctx, lctx, &pctx) == ISC_R_SUCCESS); result = cfg_parse_file(pctx, filename, type, &cfg); fprintf(stderr, "read config: %s\n", isc_result_totext(result)); if (result != ISC_R_SUCCESS) exit(1); cfg_print(cfg, output, NULL); cfg_obj_destroy(pctx, &cfg); cfg_parser_destroy(&pctx); } isc_log_destroy(&lctx); if (memstats) isc_mem_stats(mctx, stderr); isc_mem_destroy(&mctx); fflush(stdout); if (ferror(stdout)) { fprintf(stderr, "write error\n"); return (1); } else return (0); }
int main(int argc, char *argv[]) { isc_taskmgr_t *taskmgr; isc_timermgr_t *timermgr; isc_socketmgr_t *socketmgr; isc_socket_t *sock; unsigned int attrs, attrmask; isc_sockaddr_t bind_any; dns_dispatchmgr_t *dispatchmgr; dns_dispatch_t *dispatchv4; dns_view_t *view; isc_entropy_t *ectx; isc_task_t *task; isc_log_t *lctx = NULL; isc_logconfig_t *lcfg = NULL; isc_logdestination_t destination; UNUSED(argv); UNUSED(argc); RUNCHECK(isc_app_start()); dns_result_register(); mctx = NULL; RUNCHECK(isc_mem_create(0, 0, &mctx)); RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; RUNCHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME)); RUNCHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL)); isc_log_setdebuglevel(lctx, 9); ectx = NULL; RUNCHECK(isc_entropy_create(mctx, &ectx)); RUNCHECK(isc_entropy_createfilesource(ectx, "/dev/urandom")); RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY)); taskmgr = NULL; RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr)); task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); timermgr = NULL; RUNCHECK(isc_timermgr_create(mctx, &timermgr)); socketmgr = NULL; RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, ectx, &dispatchmgr)); isc_sockaddr_any(&bind_any); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | DNS_DISPATCHATTR_IPV4; attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6; dispatchv4 = NULL; RUNCHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &bind_any, 4096, 4, 2, 3, 5, attrs, attrmask, &dispatchv4)); requestmgr = NULL; RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr, dispatchmgr, dispatchv4, NULL, &requestmgr)); ring = NULL; RUNCHECK(dns_tsigkeyring_create(mctx, &ring)); view = NULL; RUNCHECK(dns_view_create(mctx, 0, "_test", &view)); dns_view_setkeyring(view, ring); sock = NULL; RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp, &sock)); setup(); RUNCHECK(isc_app_onrun(mctx, task, console, NULL)); (void)isc_app_run(); if (tsigkey) dns_tsigkey_detach(&tsigkey); dns_requestmgr_shutdown(requestmgr); dns_requestmgr_detach(&requestmgr); dns_dispatch_detach(&dispatchv4); dns_dispatchmgr_destroy(&dispatchmgr); isc_timermgr_destroy(&timermgr); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); isc_socket_detach(&sock); isc_socketmgr_destroy(&socketmgr); isc_mem_stats(mctx, stdout); dns_view_detach(&view); dst_lib_destroy(); isc_entropy_detach(&ectx); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
/*% * This function is called to process the incoming command * when a control channel message is received. */ isc_result_t named_control_docommand(isccc_sexpr_t *message, isc_boolean_t readonly, isc_buffer_t **text) { isccc_sexpr_t *data; char *cmdline = NULL; char *command = NULL; isc_result_t result; int log_level; isc_buffer_t src; isc_lex_t *lex = NULL; #ifdef HAVE_LIBSCF named_smf_want_disable = 0; #endif data = isccc_alist_lookup(message, "_data"); if (!isccc_alist_alistp(data)) { /* * No data section. */ return (ISC_R_FAILURE); } result = isccc_cc_lookupstring(data, "type", &cmdline); if (result != ISC_R_SUCCESS) { /* * We have no idea what this is. */ return (result); } result = isc_lex_create(named_g_mctx, strlen(cmdline), &lex); if (result != ISC_R_SUCCESS) return (result); isc_buffer_init(&src, cmdline, strlen(cmdline)); isc_buffer_add(&src, strlen(cmdline)); result = isc_lex_openbuffer(lex, &src); if (result != ISC_R_SUCCESS) goto cleanup; result = getcommand(lex, &command); if (result != ISC_R_SUCCESS) goto cleanup; /* * Compare the 'command' parameter against all known control commands. */ if (command_compare(command, NAMED_COMMAND_NULL) || command_compare(command, NAMED_COMMAND_STATUS)) { log_level = ISC_LOG_DEBUG(1); } else { log_level = ISC_LOG_INFO; } /* * If this listener should have read-only access, reject * restricted commands here. rndc nta is handled specially * below. */ if (readonly && !command_compare(command, NAMED_COMMAND_NTA) && !command_compare(command, NAMED_COMMAND_NULL) && !command_compare(command, NAMED_COMMAND_STATUS) && !command_compare(command, NAMED_COMMAND_SHOWZONE) && !command_compare(command, NAMED_COMMAND_TESTGEN) && !command_compare(command, NAMED_COMMAND_ZONESTATUS)) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_CONTROL, log_level, "rejecting restricted control channel " "command '%s'", cmdline); result = ISC_R_FAILURE; goto cleanup; } isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_CONTROL, log_level, "received control channel command '%s'", cmdline); if (command_compare(command, NAMED_COMMAND_RELOAD)) { result = named_server_reloadcommand(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_RECONFIG)) { result = named_server_reconfigcommand(named_g_server); } else if (command_compare(command, NAMED_COMMAND_REFRESH)) { result = named_server_refreshcommand(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_RETRANSFER)) { result = named_server_retransfercommand(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_HALT)) { #ifdef HAVE_LIBSCF /* * If we are managed by smf(5), AND in chroot, then * we cannot connect to the smf repository, so just * return with an appropriate message back to rndc. */ if (named_smf_got_instance == 1 && named_smf_chroot == 1) { result = named_smf_add_message(text); goto cleanup; } /* * If we are managed by smf(5) but not in chroot, * try to disable ourselves the smf way. */ if (named_smf_got_instance == 1 && named_smf_chroot == 0) named_smf_want_disable = 1; /* * If named_smf_got_instance = 0, named_smf_chroot * is not relevant and we fall through to * isc_app_shutdown below. */ #endif /* Do not flush master files */ named_server_flushonshutdown(named_g_server, ISC_FALSE); named_os_shutdownmsg(cmdline, *text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NAMED_COMMAND_STOP)) { /* * "stop" is the same as "halt" except it does * flush master files. */ #ifdef HAVE_LIBSCF if (named_smf_got_instance == 1 && named_smf_chroot == 1) { result = named_smf_add_message(text); goto cleanup; } if (named_smf_got_instance == 1 && named_smf_chroot == 0) named_smf_want_disable = 1; #endif named_server_flushonshutdown(named_g_server, ISC_TRUE); named_os_shutdownmsg(cmdline, *text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NAMED_COMMAND_DUMPSTATS)) { result = named_server_dumpstats(named_g_server); } else if (command_compare(command, NAMED_COMMAND_QUERYLOG)) { result = named_server_togglequerylog(named_g_server, lex); } else if (command_compare(command, NAMED_COMMAND_DUMPDB)) { named_server_dumpdb(named_g_server, lex, text); result = ISC_R_SUCCESS; } else if (command_compare(command, NAMED_COMMAND_SECROOTS)) { result = named_server_dumpsecroots(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_TRACE)) { result = named_server_setdebuglevel(named_g_server, lex); } else if (command_compare(command, NAMED_COMMAND_NOTRACE)) { named_g_debuglevel = 0; isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); result = ISC_R_SUCCESS; } else if (command_compare(command, NAMED_COMMAND_FLUSH)) { result = named_server_flushcache(named_g_server, lex); } else if (command_compare(command, NAMED_COMMAND_FLUSHNAME)) { result = named_server_flushnode(named_g_server, lex, ISC_FALSE); } else if (command_compare(command, NAMED_COMMAND_FLUSHTREE)) { result = named_server_flushnode(named_g_server, lex, ISC_TRUE); } else if (command_compare(command, NAMED_COMMAND_STATUS)) { result = named_server_status(named_g_server, text); } else if (command_compare(command, NAMED_COMMAND_TSIGLIST)) { result = named_server_tsiglist(named_g_server, text); } else if (command_compare(command, NAMED_COMMAND_TSIGDELETE)) { result = named_server_tsigdelete(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_FREEZE)) { result = named_server_freeze(named_g_server, ISC_TRUE, lex, text); } else if (command_compare(command, NAMED_COMMAND_UNFREEZE) || command_compare(command, NAMED_COMMAND_THAW)) { result = named_server_freeze(named_g_server, ISC_FALSE, lex, text); } else if (command_compare(command, NAMED_COMMAND_SCAN)) { result = ISC_R_SUCCESS; named_server_scan_interfaces(named_g_server); } else if (command_compare(command, NAMED_COMMAND_SYNC)) { result = named_server_sync(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_RECURSING)) { result = named_server_dumprecursing(named_g_server); } else if (command_compare(command, NAMED_COMMAND_TIMERPOKE)) { result = ISC_R_SUCCESS; isc_timermgr_poke(named_g_timermgr); } else if (command_compare(command, NAMED_COMMAND_NULL)) { result = ISC_R_SUCCESS; } else if (command_compare(command, NAMED_COMMAND_NOTIFY)) { result = named_server_notifycommand(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_VALIDATION)) { result = named_server_validation(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_SIGN) || command_compare(command, NAMED_COMMAND_LOADKEYS)) { result = named_server_rekey(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_ADDZONE) || command_compare(command, NAMED_COMMAND_MODZONE)) { result = named_server_changezone(named_g_server, cmdline, text); } else if (command_compare(command, NAMED_COMMAND_DELZONE)) { result = named_server_delzone(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_SHOWZONE)) { result = named_server_showzone(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_SIGNING)) { result = named_server_signing(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_ZONESTATUS)) { result = named_server_zonestatus(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_NTA)) { result = named_server_nta(named_g_server, lex, readonly, text); } else if (command_compare(command, NAMED_COMMAND_TESTGEN)) { result = named_server_testgen(lex, text); } else if (command_compare(command, NAMED_COMMAND_MKEYS)) { result = named_server_mkeys(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_DNSTAP) || command_compare(command, NAMED_COMMAND_DNSTAPREOPEN)) { result = named_server_dnstap(named_g_server, lex, text); } else if (command_compare(command, NAMED_COMMAND_TCPTIMEOUTS)) { result = named_server_tcptimeouts(lex, text); } else if (command_compare(command, NAMED_COMMAND_SERVESTALE)) { result = named_server_servestale(named_g_server, lex, text); } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_CONTROL, ISC_LOG_WARNING, "unknown control channel command '%s'", command); result = DNS_R_UNKNOWNCOMMAND; } cleanup: if (lex != NULL) isc_lex_destroy(&lex); return (result); }
/* * This function is called to process the incoming command * when a control channel message is received. */ isc_result_t ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { isccc_sexpr_t *data; char *command; isc_result_t result; data = isccc_alist_lookup(message, "_data"); if (data == NULL) { /* * No data section. */ return (ISC_R_FAILURE); } result = isccc_cc_lookupstring(data, "type", &command); if (result != ISC_R_SUCCESS) { /* * We have no idea what this is. */ return (result); } isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, ISC_LOG_DEBUG(1), "received control channel command '%s'", command); /* * Compare the 'command' parameter against all known control commands. */ if (command_compare(command, NS_COMMAND_RELOAD)) { result = ns_server_reloadcommand(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_RECONFIG)) { result = ns_server_reconfigcommand(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_REFRESH)) { result = ns_server_refreshcommand(ns_g_server, command, text); } else if (command_compare(command, NS_COMMAND_RETRANSFER)) { result = ns_server_retransfercommand(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_HALT)) { ns_server_flushonshutdown(ns_g_server, ISC_FALSE); ns_os_shutdownmsg(command, text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_STOP)) { ns_server_flushonshutdown(ns_g_server, ISC_TRUE); ns_os_shutdownmsg(command, text); isc_app_shutdown(); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) { result = ns_server_dumpstats(ns_g_server); } else if (command_compare(command, NS_COMMAND_QUERYLOG)) { result = ns_server_togglequerylog(ns_g_server); } else if (command_compare(command, NS_COMMAND_DUMPDB)) { ns_server_dumpdb(ns_g_server, command); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_TRACE)) { result = ns_server_setdebuglevel(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_NOTRACE)) { ns_g_debuglevel = 0; isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_FLUSH)) { result = ns_server_flushcache(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_FLUSHNAME)) { result = ns_server_flushname(ns_g_server, command); } else if (command_compare(command, NS_COMMAND_STATUS)) { result = ns_server_status(ns_g_server, text); } else if (command_compare(command, NS_COMMAND_FREEZE)) { result = ns_server_freeze(ns_g_server, ISC_TRUE, command); } else if (command_compare(command, NS_COMMAND_UNFREEZE) || command_compare(command, NS_COMMAND_THAW)) { result = ns_server_freeze(ns_g_server, ISC_FALSE, command); } else if (command_compare(command, NS_COMMAND_RECURSING)) { result = ns_server_dumprecursing(ns_g_server); } else if (command_compare(command, NS_COMMAND_NULL)) { result = ISC_R_SUCCESS; } else { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, ISC_LOG_WARNING, "unknown control channel command '%s'", command); result = DNS_R_UNKNOWNCOMMAND; } return (result); }
static void setup_logging(FILE *errout) { isc_result_t result; isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; result = isc_log_create(mctx, &lctx, &logconfig); if (result != ISC_R_SUCCESS) fatal("Couldn't set up logging"); isc_log_registercategories(lctx, categories); isc_log_registermodules(lctx, modules); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); cfg_log_init(lctx); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'stderr'"); isc_log_setdebuglevel(lctx, loglevel); result = isc_log_settag(logconfig, ";; "); if (result != ISC_R_SUCCESS) fatal("Couldn't set log tag"); result = isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_DEFAULT, NULL); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'stderr'"); if (resolve_trace && loglevel < 1) { result = isc_log_createchannel(logconfig, "resolver", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(1), &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'resolver'"); result = isc_log_usechannel(logconfig, "resolver", DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_RESOLVER); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'resolver'"); } if (validator_trace && loglevel < 3) { result = isc_log_createchannel(logconfig, "validator", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(3), &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'validator'"); result = isc_log_usechannel(logconfig, "validator", DNS_LOGCATEGORY_DNSSEC, DNS_LOGMODULE_VALIDATOR); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'validator'"); } if (message_trace && loglevel < 10) { result = isc_log_createchannel(logconfig, "messages", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(10), &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'messages'"); result = isc_log_usechannel(logconfig, "messages", DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'messagse'"); } }