#include <config.h>
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/event.h>
#include <isc/file.h>
#include <isc/mem.h>
#include <isc/net.h>
#include <isc/netaddr.h>
#include <isc/random.h>
#include <isc/result.h>
#include <isc/stdtime.h>
#include <isc/string.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <isccfg/namedconf.h>
#include <bind9/check.h>
#include <isccc/alist.h>
#include <isccc/cc.h>
#include <isccc/ccmsg.h>
#include <isccc/events.h>
#include <isccc/result.h>
#include <isccc/sexpr.h>
#include <isccc/symtab.h>
#include <isccc/util.h>
#include <dns/result.h>
#include <named/control.h>
#include <named/log.h>
#include <named/server.h>
Go to the source code of this file.
Data Structures | |
struct | controlconnection |
struct | controllistener |
struct | ns_controls |
Defines | |
#define | CLOCKSKEW 300 |
#define | CHECK(x) |
Typedefs | |
typedef struct controlkey | controlkey_t |
Functions | |
typedef | ISC_LIST (controlkey_t) |
static void | control_newconn (isc_task_t *task, isc_event_t *event) |
static void | control_recvmessage (isc_task_t *task, isc_event_t *event) |
static void | free_controlkey (controlkey_t *key, isc_mem_t *mctx) |
static void | free_controlkeylist (controlkeylist_t *keylist, isc_mem_t *mctx) |
static void | free_listener (controllistener_t *listener) |
static void | maybe_free_listener (controllistener_t *listener) |
static void | maybe_free_connection (controlconnection_t *conn) |
static void | shutdown_listener (controllistener_t *listener) |
static isc_boolean_t | address_ok (isc_sockaddr_t *sockaddr, dns_acl_t *acl) |
static isc_result_t | control_accept (controllistener_t *listener) |
static isc_result_t | control_listen (controllistener_t *listener) |
static void | control_next (controllistener_t *listener) |
static void | control_senddone (isc_task_t *task, isc_event_t *event) |
static void | log_invalid (isccc_ccmsg_t *ccmsg, isc_result_t result) |
static void | control_timeout (isc_task_t *task, isc_event_t *event) |
static isc_result_t | newconnection (controllistener_t *listener, isc_socket_t *sock) |
static void | controls_shutdown (ns_controls_t *controls) |
void | ns_controls_shutdown (ns_controls_t *controls) |
Initiate shutdown of all the command channels in 'controls'. | |
static isc_result_t | cfgkeylist_find (const cfg_obj_t *keylist, const char *keyname, const cfg_obj_t **objp) |
static isc_result_t | controlkeylist_fromcfg (const cfg_obj_t *keylist, isc_mem_t *mctx, controlkeylist_t *keyids) |
static void | register_keys (const cfg_obj_t *control, const cfg_obj_t *keylist, controlkeylist_t *keyids, isc_mem_t *mctx, const char *socktext) |
static isc_result_t | get_rndckey (isc_mem_t *mctx, controlkeylist_t *keyids) |
static void | get_key_info (const cfg_obj_t *config, const cfg_obj_t *control, const cfg_obj_t **global_keylistp, const cfg_obj_t **control_keylistp) |
static void | update_listener (ns_controls_t *cp, controllistener_t **listenerp, const cfg_obj_t *control, const cfg_obj_t *config, isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx, const char *socktext, isc_sockettype_t type) |
static void | add_listener (ns_controls_t *cp, controllistener_t **listenerp, const cfg_obj_t *control, const cfg_obj_t *config, isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx, const char *socktext, isc_sockettype_t type) |
isc_result_t | ns_controls_configure (ns_controls_t *cp, const cfg_obj_t *config, cfg_aclconfctx_t *aclconfctx) |
Configure zero or more command channels into 'controls' as defined in the configuration parse tree 'config'. The channels will evaluate ACLs in the context of 'aclconfctx'. | |
isc_result_t | ns_controls_create (ns_server_t *server, ns_controls_t **ctrlsp) |
Create an initial, empty set of command channels for 'server'. | |
void | ns_controls_destroy (ns_controls_t **ctrlsp) |
Destroy a set of command channels. |
Definition in file controlconf.c.
#define CLOCKSKEW 300 |
#define CHECK | ( | x | ) |
Value:
do { \ result = (x); \ if (result != ISC_R_SUCCESS) \ goto cleanup; \ } while (0)
Definition at line 825 of file controlconf.c.
typedef struct controlkey controlkey_t |
Definition at line 64 of file controlconf.c.
typedef ISC_LIST | ( | controlkey_t | ) |
static void control_newconn | ( | isc_task_t * | task, | |
isc_event_t * | event | |||
) | [static] |
Definition at line 602 of file controlconf.c.
References address_ok(), cleanup(), control_next(), isc_event_free(), ISC_FALSE, ISC_LOG_WARNING, isc_log_write(), ISC_R_CANCELED, ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, isc_socket_detach(), isc_socket_getpeername(), isc_socket_setname(), isc_sockettype_tcp, controlconnection::listener, newconnection(), isc_socket_newconnev::newsocket, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, isc_socket_newconnev::result, shutdown_listener(), and UNUSED.
Referenced by control_accept().
static void control_recvmessage | ( | isc_task_t * | task, | |
isc_event_t * | event | |||
) | [static] |
Definition at line 326 of file controlconf.c.
References algorithm, isc_region::base, isc_buffer::base, cleanup(), CLOCKSKEW, control_senddone(), DST_ALG_UNKNOWN, isc_buffer_add, isc_buffer_allocate(), isc_buffer_base, isc_buffer_clear, isc_buffer_free(), isc_buffer_init, isc_buffer_putuint32, isc_buffer_used, isc_buffer_usedlength, ISC_FALSE, ISC_LIST_HEAD, ISC_LIST_NEXT, isc_mem_get, isc_mem_put, ISC_R_CANCELED, ISC_R_EOF, ISC_R_EXISTS, ISC_R_FAILURE, ISC_R_SUCCESS, isc_random_get(), isc_result_totext(), isc_socket_detach(), isc_socket_send(), isc_stdtime_get(), ISC_TRUE, isccc_alist_lookup(), isccc_cc_checkdup(), isccc_cc_cleansymtab(), isccc_cc_createresponse(), isccc_cc_definestring(), isccc_cc_defineuint32(), isccc_cc_fromwire(), isccc_cc_isreply(), isccc_cc_lookupuint32(), isccc_cc_towire(), isccc_ccmsg_invalidate(), ISCCC_EVENT_CCMSG, ISCCC_R_BADAUTH, ISCCC_R_CLOCKSKEW, ISCCC_R_DUPLICATE, ISCCC_R_EXPIRED, isccc_sexpr_free(), key, isc_region::length, controlconnection::listener, log_invalid(), maybe_free_connection(), maybe_free_listener(), controlconnection::nonce, now, ns_control_docommand(), r, REGION_SIZE, isccc_region::rend, REQUIRE, isccc_region::rstart, secret, str, text, and isc_buffer::used.
Referenced by control_senddone(), and newconnection().
static void free_controlkey | ( | controlkey_t * | key, | |
isc_mem_t * | mctx | |||
) | [static] |
Definition at line 123 of file controlconf.c.
References isc_mem_free, and isc_mem_put.
Referenced by free_controlkeylist(), get_rndckey(), and register_keys().
static void free_controlkeylist | ( | controlkeylist_t * | keylist, | |
isc_mem_t * | mctx | |||
) | [static] |
Definition at line 132 of file controlconf.c.
References free_controlkey(), ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_UNLINK, and key.
Referenced by controlkeylist_fromcfg(), free_listener(), and update_listener().
static void free_listener | ( | controllistener_t * | listener | ) | [static] |
Definition at line 141 of file controlconf.c.
References dns_acl_detach(), free_controlkeylist(), INSIST, ISC_LIST_EMPTY, isc_mem_putanddetach, and isc_socket_detach().
Referenced by add_listener(), and maybe_free_listener().
static void maybe_free_listener | ( | controllistener_t * | listener | ) | [static] |
Definition at line 158 of file controlconf.c.
References free_listener(), and ISC_LIST_EMPTY.
Referenced by control_recvmessage(), control_senddone(), and shutdown_listener().
static void maybe_free_connection | ( | controlconnection_t * | conn | ) | [static] |
Definition at line 166 of file controlconf.c.
References isc_buffer_free(), ISC_LIST_UNLINK, isc_mem_put, ISC_SOCKCANCEL_SEND, isc_socket_cancel(), isc_timer_detach(), isccc_ccmsg_cancelread(), and controlconnection::listener.
Referenced by control_recvmessage(), control_senddone(), control_timeout(), and shutdown_listener().
static void shutdown_listener | ( | controllistener_t * | listener | ) | [static] |
Definition at line 191 of file controlconf.c.
References ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_LIST_UNLINK, ISC_LOG_NOTICE, isc_log_write(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, ISC_SOCKCANCEL_ACCEPT, isc_socket_cancel(), isc_socket_cleanunix(), isc_sockettype_unix, ISC_TRUE, maybe_free_connection(), maybe_free_listener(), NS_LOGCATEGORY_GENERAL, and NS_LOGMODULE_CONTROL.
Referenced by control_newconn(), controls_shutdown(), ns_statschannels_configure(), and ns_statschannels_shutdown().
static isc_boolean_t address_ok | ( | isc_sockaddr_t * | sockaddr, | |
dns_acl_t * | acl | |||
) | [static] |
Definition at line 226 of file controlconf.c.
References dns_acl_match(), ISC_FALSE, isc_netaddr_fromsockaddr(), ISC_R_SUCCESS, ISC_TRUE, and match().
Referenced by control_newconn().
static isc_result_t control_accept | ( | controllistener_t * | listener | ) | [static] |
Definition at line 243 of file controlconf.c.
References control_newconn(), ISC_R_SUCCESS, isc_result_totext(), isc_socket_accept(), ISC_TRUE, and UNEXPECTED_ERROR.
Referenced by add_listener(), and control_next().
static isc_result_t control_listen | ( | controllistener_t * | listener | ) | [static] |
Definition at line 258 of file controlconf.c.
References ISC_R_SUCCESS, isc_result_totext(), isc_socket_listen(), and UNEXPECTED_ERROR.
Referenced by add_listener().
static void control_next | ( | controllistener_t * | listener | ) | [static] |
Definition at line 270 of file controlconf.c.
References control_accept().
Referenced by control_newconn().
static void control_senddone | ( | isc_task_t * | task, | |
isc_event_t * | event | |||
) | [static] |
Definition at line 275 of file controlconf.c.
References control_recvmessage(), isc_event_free(), ISC_FALSE, ISC_LOG_WARNING, isc_log_write(), ISC_R_CANCELED, ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, isc_socket_detach(), isc_socket_getpeername(), isccc_ccmsg_readmessage(), controlconnection::listener, maybe_free_connection(), maybe_free_listener(), NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, REQUIRE, isc_socketevent::result, and UNUSED.
Referenced by control_recvmessage().
static void log_invalid | ( | isccc_ccmsg_t * | ccmsg, | |
isc_result_t | result | |||
) | [inline, static] |
Definition at line 313 of file controlconf.c.
References ISC_LOG_ERROR, isc_log_write(), isc_result_totext(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, isc_socket_getpeername(), NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, and isccc_ccmsg::sock.
Referenced by control_recvmessage().
static void control_timeout | ( | isc_task_t * | task, | |
isc_event_t * | event | |||
) | [static] |
Definition at line 545 of file controlconf.c.
References isc_event_free(), isc_timer_detach(), maybe_free_connection(), and UNUSED.
Referenced by newconnection().
static isc_result_t newconnection | ( | controllistener_t * | listener, | |
isc_socket_t * | sock | |||
) | [static] |
Definition at line 557 of file controlconf.c.
References cleanup(), control_recvmessage(), control_timeout(), isc_buffer_free(), ISC_FALSE, isc_interval_set(), ISC_LINK_INIT, ISC_LIST_APPEND, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_timer_create(), isc_timer_detach(), isc_timertype_once, ISC_TRUE, isccc_ccmsg_init(), isccc_ccmsg_invalidate(), and isccc_ccmsg_readmessage().
Referenced by control_newconn().
static void controls_shutdown | ( | ns_controls_t * | controls | ) | [static] |
Definition at line 655 of file controlconf.c.
References ISC_LIST_HEAD, ISC_LIST_NEXT, controlconnection::listener, ns_controls::listeners, and shutdown_listener().
Referenced by ns_controls_configure(), and ns_controls_shutdown().
void ns_controls_shutdown | ( | ns_controls_t * | controls | ) |
Initiate shutdown of all the command channels in 'controls'.
Definition at line 673 of file controlconf.c.
References controls_shutdown(), ISC_TRUE, and ns_controls::shuttingdown.
Referenced by shutdown_server().
static isc_result_t cfgkeylist_find | ( | const cfg_obj_t * | keylist, | |
const char * | keyname, | |||
const cfg_obj_t ** | objp | |||
) | [static] |
Definition at line 679 of file controlconf.c.
References cfg_list_first(), cfg_list_next(), cfg_listelt_value(), cfg_map_getname(), cfg_obj_asstring(), ISC_R_NOTFOUND, ISC_R_SUCCESS, and str.
Referenced by register_keys().
static isc_result_t controlkeylist_fromcfg | ( | const cfg_obj_t * | keylist, | |
isc_mem_t * | mctx, | |||
controlkeylist_t * | keyids | |||
) | [static] |
Definition at line 703 of file controlconf.c.
References cfg_list_first(), cfg_list_next(), cfg_listelt_value(), cfg_obj_asstring(), cleanup(), DST_ALG_UNKNOWN, free_controlkeylist(), ISC_LINK_INIT, ISC_LIST_APPEND, isc_mem_free, isc_mem_get, isc_mem_strdup, ISC_R_NOMEMORY, ISC_R_SUCCESS, key, and str.
Referenced by add_listener(), and update_listener().
static void register_keys | ( | const cfg_obj_t * | control, | |
const cfg_obj_t * | keylist, | |||
controlkeylist_t * | keyids, | |||
isc_mem_t * | mctx, | |||
const char * | socktext | |||
) | [static] |
Definition at line 742 of file controlconf.c.
References cfg_map_get(), cfg_obj_asstring(), cfg_obj_log(), cfgkeylist_find(), free_controlkey(), INSIST, isc_base64_decodestring(), isc_buffer_base, isc_buffer_init, isc_buffer_usedlength, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_LIST_UNLINK, ISC_LOG_WARNING, isc_mem_get, ISC_R_SUCCESS, isc_result_totext(), ns_config_getkeyalgorithm2(), and secret.
Referenced by add_listener(), and update_listener().
static isc_result_t get_rndckey | ( | isc_mem_t * | mctx, | |
controlkeylist_t * | keyids | |||
) | [static] |
Definition at line 833 of file controlconf.c.
References bind9_check_key(), cfg_map_get(), cfg_map_getname(), cfg_obj_asstring(), cfg_obj_destroy(), cfg_obj_log(), cfg_parse_file(), cfg_parser_create(), cfg_parser_destroy(), cfg_type_rndckey, CHECK, cleanup(), DST_ALG_UNKNOWN, free_controlkey(), INSIST, isc_base64_decodestring(), isc_buffer_base, isc_buffer_init, isc_buffer_usedlength, isc_file_exists(), ISC_LINK_INIT, ISC_LIST_APPEND, ISC_LOG_INFO, ISC_LOG_WARNING, isc_log_write(), isc_mem_get, isc_mem_strdup, ISC_R_FILENOTFOUND, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_result_totext(), key, ns_config_getkeyalgorithm2(), NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, and secret.
Referenced by add_listener(), and update_listener().
static void get_key_info | ( | const cfg_obj_t * | config, | |
const cfg_obj_t * | control, | |||
const cfg_obj_t ** | global_keylistp, | |||
const cfg_obj_t ** | control_keylistp | |||
) | [static] |
Definition at line 931 of file controlconf.c.
References cfg_list_first(), cfg_map_get(), cfg_obj_isvoid(), cfg_tuple_get(), ISC_R_SUCCESS, and REQUIRE.
Referenced by add_listener(), and update_listener().
static void update_listener | ( | ns_controls_t * | cp, | |
controllistener_t ** | listenerp, | |||
const cfg_obj_t * | control, | |||
const cfg_obj_t * | config, | |||
isc_sockaddr_t * | addr, | |||
cfg_aclconfctx_t * | aclconfctx, | |||
const char * | socktext, | |||
isc_sockettype_t | type | |||
) | [static] |
Definition at line 956 of file controlconf.c.
References cfg_acl_fromconfig(), cfg_obj_asuint32(), cfg_obj_log(), cfg_tuple_get(), controlkeylist_fromcfg(), dns_acl_any(), dns_acl_attach(), dns_acl_detach(), free_controlkeylist(), get_key_info(), get_rndckey(), INSIST, ISC_LIST_HEAD, ISC_LIST_INIT, ISC_LIST_NEXT, ISC_LOG_WARNING, isc_log_write(), ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_equal(), isc_socket_permunix(), isc_sockettype_tcp, isc_sockettype_unix, controlconnection::listener, ns_controls::listeners, cfg_aclconfctx::mctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, and register_keys().
Referenced by ns_controls_configure(), and ns_statschannels_configure().
static void add_listener | ( | ns_controls_t * | cp, | |
controllistener_t ** | listenerp, | |||
const cfg_obj_t * | control, | |||
const cfg_obj_t * | config, | |||
isc_sockaddr_t * | addr, | |||
cfg_aclconfctx_t * | aclconfctx, | |||
const char * | socktext, | |||
isc_sockettype_t | type | |||
) | [static] |
Definition at line 1094 of file controlconf.c.
References AF_INET6, cfg_acl_fromconfig(), cfg_obj_asuint32(), cfg_obj_log(), cfg_tuple_get(), control_accept(), control_listen(), controlkeylist_fromcfg(), dns_acl_any(), dns_acl_attach(), dns_acl_detach(), free_listener(), get_key_info(), get_rndckey(), ISC_FALSE, ISC_LINK_INIT, ISC_LIST_INIT, ISC_LOG_NOTICE, ISC_LOG_WARNING, isc_log_write(), isc_mem_attach(), isc_mem_get, isc_net_probeipv4(), isc_net_probeipv6(), isc_net_probeunix(), ISC_PLATFORM_HAVESYSUNH, ISC_R_FAMILYNOSUPPORT, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_pf(), isc_socket_bind(), isc_socket_cleanunix(), isc_socket_create(), isc_socket_ipv6only(), isc_socket_permunix(), ISC_SOCKET_REUSEADDRESS, isc_socket_setname(), isc_sockettype_tcp, isc_sockettype_unix, ISC_TRUE, controlconnection::listener, ns_server::mctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, register_keys(), ns_controls::server, and ns_server::task.
Referenced by ns_controls_configure(), and ns_statschannels_configure().
isc_result_t ns_controls_configure | ( | ns_controls_t * | cp, | |
const cfg_obj_t * | config, | |||
cfg_aclconfctx_t * | aclconfctx | |||
) |
Configure zero or more command channels into 'controls' as defined in the configuration parse tree 'config'. The channels will evaluate ACLs in the context of 'aclconfctx'.
Definition at line 1242 of file controlconf.c.
References add_listener(), cfg_list_first(), cfg_list_next(), cfg_listelt_value(), cfg_map_get(), cfg_obj_assockaddr(), cfg_obj_asstring(), cfg_tuple_get(), controls_shutdown(), in6addr_loopback, INADDR_LOOPBACK, ISC_LIST_APPEND, ISC_LIST_APPENDLIST, ISC_LIST_INIT, ISC_LIST_UNLINK, ISC_LOG_DEBUG, isc_log_write(), isc_net_probeipv4(), isc_net_probeipv6(), ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, isc_sockaddr_fromin(), isc_sockaddr_fromin6(), isc_sockaddr_frompath(), isc_sockaddr_getport(), isc_sockaddr_setport(), isc_sockettype_tcp, isc_sockettype_unix, controlconnection::listener, ns_controls::listeners, NS_CONTROL_PORT, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_CONTROL, and update_listener().
Referenced by load_configuration().
isc_result_t ns_controls_create | ( | ns_server_t * | server, | |
ns_controls_t ** | ctrlsp | |||
) |
Create an initial, empty set of command channels for 'server'.
Definition at line 1472 of file controlconf.c.
References ISC_FALSE, ISC_LIST_INIT, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, isccc_cc_createsymtab(), ns_controls::listeners, ns_server::mctx, ns_controls::server, ns_controls::shuttingdown, and ns_controls::symtab.
Referenced by ns_server_create().
void ns_controls_destroy | ( | ns_controls_t ** | ctrlsp | ) |
Destroy a set of command channels.
Requires: Shutdown of the channels has completed.
Definition at line 1493 of file controlconf.c.
References ISC_LIST_EMPTY, isc_mem_put, isccc_symtab_destroy(), ns_controls::listeners, ns_server::mctx, REQUIRE, ns_controls::server, and ns_controls::symtab.
Referenced by ns_server_destroy().