⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rndc.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2000-2003  Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. *//* $Id: rndc.c,v 1.77.2.5.2.12.6.1 2004/09/20 01:00:01 marka Exp $ *//* * Principal Author: DCL */#include <config.h>#include <stdlib.h>#include <isc/app.h>#include <isc/buffer.h>#include <isc/commandline.h>#include <isc/file.h>#include <isc/log.h>#include <isc/mem.h>#include <isc/random.h>#include <isc/socket.h>#include <isc/stdtime.h>#include <isc/string.h>#include <isc/task.h>#include <isc/thread.h>#include <isc/util.h>#include <isccfg/namedconf.h>#include <isccc/alist.h>#include <isccc/base64.h>#include <isccc/cc.h>#include <isccc/ccmsg.h>#include <isccc/result.h>#include <isccc/sexpr.h>#include <isccc/types.h>#include <isccc/util.h>#include <bind9/getaddresses.h>#include "util.h"#define SERVERADDRS 10char *progname;isc_boolean_t verbose;static const char *admin_conffile;static const char *admin_keyfile;static const char *version = VERSION;static const char *servername = NULL;static isc_sockaddr_t serveraddrs[SERVERADDRS];static int nserveraddrs;static int currentaddr = 0;static unsigned int remoteport = 0;static isc_socketmgr_t *socketmgr = NULL;static unsigned char databuf[2048];static isccc_ccmsg_t ccmsg;static isccc_region_t secret;static isc_boolean_t failed = ISC_FALSE;static isc_mem_t *mctx;static int sends, recvs, connects;static char *command;static char *args;static char program[256];static isc_socket_t *sock = NULL;static isc_uint32_t serial;static void rndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task);static voidusage(int status) {	fprintf(stderr, "\Usage: %s [-c config] [-s server] [-p port]\n\        [-k key-file ] [-y key] [-V] command\n\\n\command is one of the following:\n\\n\  reload	Reload configuration file and zones.\n\  reload zone [class [view]]\n\		Reload a single zone.\n\  refresh zone [class [view]]\n\		Schedule immediate maintenance for a zone.\n\  retransfer zone [class [view]]\n\		Retransfer a single zone without checking serial number.\n\  freeze zone [class [view]]\n\  		Suspend updates to a dynamic zone.\n\  thaw zone [class [view]]\n\  		Enable updates to a frozen dynamic zone and reload it.\n\  reconfig	Reload configuration file and new zones only.\n\  stats		Write server statistics to the statistics file.\n\  querylog	Toggle query logging.\n\  dumpdb	Dump cache(s) to the dump file (named_dump.db).\n\  stop		Save pending updates to master files and stop the server.\n\  stop -p	Save pending updates to master files and stop the server\n\		reporting process id.\n\  halt		Stop the server without saving pending updates.\n\  halt -p	Stop the server without saving pending updates reporting\n\		process id.\n\  trace		Increment debugging level by one.\n\  trace level	Change the debugging level.\n\  notrace	Set debugging level to 0.\n\  flush 	Flushes all of the server's caches.\n\  flush [view]	Flushes the server's cache for a view.\n\  flushname name [view]\n\		Flush the given name from the server's cache(s)\n\  status	Display status of the server.\n\  recursing	Dump the queries that are currently recursing (named.recursing)\n\  *restart	Restart the server.\n\\n\* == not yet implemented\n\Version: %s\n",		progname, version);	exit(status);}static voidget_addresses(const char *host, in_port_t port) {	isc_result_t result;	isc_app_block();	result = bind9_getaddresses(servername, port,				    serveraddrs, SERVERADDRS, &nserveraddrs);	isc_app_unblock();	if (result != ISC_R_SUCCESS)		fatal("couldn't get address for '%s': %s",		      host, isc_result_totext(result));	INSIST(nserveraddrs > 0);}static voidrndc_senddone(isc_task_t *task, isc_event_t *event) {	isc_socketevent_t *sevent = (isc_socketevent_t *)event;	UNUSED(task);	sends--;	if (sevent->result != ISC_R_SUCCESS)		fatal("send failed: %s", isc_result_totext(sevent->result));	isc_event_free(&event);}static voidrndc_recvdone(isc_task_t *task, isc_event_t *event) {	isccc_sexpr_t *response = NULL;	isccc_sexpr_t *data;	isccc_region_t source;	char *errormsg = NULL;	char *textmsg = NULL;	isc_result_t result;	recvs--;	if (ccmsg.result == ISC_R_EOF)		fatal("connection to remote host closed\n"		      "This may indicate that the remote server is using "		      "an older version of \n"		      "the command protocol, this host is not authorized "		      "to connect,\nor the key is invalid.");	if (ccmsg.result != ISC_R_SUCCESS)		fatal("recv failed: %s", isc_result_totext(ccmsg.result));	source.rstart = isc_buffer_base(&ccmsg.buffer);	source.rend = isc_buffer_used(&ccmsg.buffer);	DO("parse message", isccc_cc_fromwire(&source, &response, &secret));	data = isccc_alist_lookup(response, "_data");	if (data == NULL)		fatal("no data section in response");	result = isccc_cc_lookupstring(data, "err", &errormsg);	if (result == ISC_R_SUCCESS) {		failed = ISC_TRUE;		fprintf(stderr, "%s: '%s' failed: %s\n",			progname, command, errormsg);	}	else if (result != ISC_R_NOTFOUND)		fprintf(stderr, "%s: parsing response failed: %s\n",			progname, isc_result_totext(result));	result = isccc_cc_lookupstring(data, "text", &textmsg);	if (result == ISC_R_SUCCESS)		printf("%s\n", textmsg);	else if (result != ISC_R_NOTFOUND)		fprintf(stderr, "%s: parsing response failed: %s\n",			progname, isc_result_totext(result));	isc_event_free(&event);	isccc_sexpr_free(&response);	isc_socket_detach(&sock);	isc_task_shutdown(task);	RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);}static voidrndc_recvnonce(isc_task_t *task, isc_event_t *event) {	isccc_sexpr_t *response = NULL;	isccc_sexpr_t *_ctrl;	isccc_region_t source;	isc_result_t result;	isc_uint32_t nonce;	isccc_sexpr_t *request = NULL;	isccc_time_t now;	isc_region_t r;	isccc_sexpr_t *data;	isccc_region_t message;	isc_uint32_t len;	isc_buffer_t b;	recvs--;	if (ccmsg.result == ISC_R_EOF)		fatal("connection to remote host closed\n"		      "This may indicate that the remote server is using "		      "an older version of \n"		      "the command protocol, this host is not authorized "		      "to connect,\nor the key is invalid.");	if (ccmsg.result != ISC_R_SUCCESS)		fatal("recv failed: %s", isc_result_totext(ccmsg.result));	source.rstart = isc_buffer_base(&ccmsg.buffer);	source.rend = isc_buffer_used(&ccmsg.buffer);	DO("parse message", isccc_cc_fromwire(&source, &response, &secret));	_ctrl = isccc_alist_lookup(response, "_ctrl");	if (_ctrl == NULL)		fatal("_ctrl section missing");	nonce = 0;	if (isccc_cc_lookupuint32(_ctrl, "_nonce", &nonce) != ISC_R_SUCCESS)		nonce = 0;	isc_stdtime_get(&now);	DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,						    now, now + 60, &request));	data = isccc_alist_lookup(request, "_data");	if (data == NULL)		fatal("_data section missing");	if (isccc_cc_definestring(data, "type", args) == NULL)		fatal("out of memory");	if (nonce != 0) {		_ctrl = isccc_alist_lookup(request, "_ctrl");		if (_ctrl == NULL)			fatal("_ctrl section missing");		if (isccc_cc_defineuint32(_ctrl, "_nonce", nonce) == NULL)			fatal("out of memory");	}	message.rstart = databuf + 4;	message.rend = databuf + sizeof(databuf);	DO("render message", isccc_cc_towire(request, &message, &secret));	len = sizeof(databuf) - REGION_SIZE(message);	isc_buffer_init(&b, databuf, 4);	isc_buffer_putuint32(&b, len - 4);	r.length = len;	r.base = databuf;	isccc_ccmsg_cancelread(&ccmsg);	DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,						    rndc_recvdone, NULL));	recvs++;	DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,					   NULL));	sends++;	isc_event_free(&event);	isccc_sexpr_free(&response);	return;}static voidrndc_connected(isc_task_t *task, isc_event_t *event) {	isc_socketevent_t *sevent = (isc_socketevent_t *)event;	isccc_sexpr_t *request = NULL;	isccc_sexpr_t *data;	isccc_time_t now;	isccc_region_t message;	isc_region_t r;	isc_uint32_t len;	isc_buffer_t b;	isc_result_t result;	connects--;	if (sevent->result != ISC_R_SUCCESS) {		if (sevent->result != ISC_R_CANCELED &&		    currentaddr < nserveraddrs)		{			notify("connection failed: %s",			       isc_result_totext(sevent->result));			isc_socket_detach(&sock);			isc_event_free(&event);			rndc_startconnect(&serveraddrs[currentaddr++], task);			return;		} else			fatal("connect failed: %s",			      isc_result_totext(sevent->result));	}	isc_stdtime_get(&now);	DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,						    now, now + 60, &request));	data = isccc_alist_lookup(request, "_data");	if (data == NULL)		fatal("_data section missing");	if (isccc_cc_definestring(data, "type", "null") == NULL)		fatal("out of memory");	message.rstart = databuf + 4;	message.rend = databuf + sizeof(databuf);	DO("render message", isccc_cc_towire(request, &message, &secret));	len = sizeof(databuf) - REGION_SIZE(message);	isc_buffer_init(&b, databuf, 4);	isc_buffer_putuint32(&b, len - 4);	r.length = len;	r.base = databuf;	isccc_ccmsg_init(mctx, sock, &ccmsg);	isccc_ccmsg_setmaxsize(&ccmsg, 1024);	DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,						    rndc_recvnonce, NULL));	recvs++;	DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,					   NULL));	sends++;	isc_event_free(&event);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -