Пример #1
0
static isc_result_t
ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
	  isc_taskmgr_t **taskmgrp, isc_socketmgr_t **socketmgrp,
	  isc_timermgr_t **timermgrp)
{
	isc_result_t result;

	result = isc_mem_create(0, 0, mctxp);
	if (result != ISC_R_SUCCESS)
		goto fail;

	result = isc_appctx_create(*mctxp, actxp);
	if (result != ISC_R_SUCCESS)
		goto fail;

	result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp);
	if (result != ISC_R_SUCCESS)
		goto fail;

	result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp);
	if (result != ISC_R_SUCCESS)
		goto fail;

	result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp);
	if (result != ISC_R_SUCCESS)
		goto fail;

	return (ISC_R_SUCCESS);

 fail:
	ctxs_destroy(mctxp, actxp, taskmgrp, socketmgrp, timermgrp);

	return (result);
}
Пример #2
0
isc_result_t
dhcp_context_create(void) {
	isc_result_t result;

	/*
	 * Set up the error messages, this isn't the right place
	 * for this call but it is convienent for now.
	 */
	result = dhcp_result_register();
	if (result != ISC_R_SUCCESS) {
		log_fatal("register_table() %s: %u", "failed", result);
	}

	memset(&dhcp_gbl_ctx, 0, sizeof (dhcp_gbl_ctx));
	
	isc_lib_register();

	/* get the current time for use as the random seed */
	gettimeofday(&cur_tv, (struct timezone *)0);
	isc_random_seed(cur_tv.tv_sec);

#if defined (NSUPDATE)
	result = dns_lib_init();
	if (result != ISC_R_SUCCESS)
		goto cleanup;
#endif

	result = isc_mem_create(0, 0, &dhcp_gbl_ctx.mctx);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	result = isc_appctx_create(dhcp_gbl_ctx.mctx, &dhcp_gbl_ctx.actx);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	result = isc_app_ctxstart(dhcp_gbl_ctx.actx);
	if (result != ISC_R_SUCCESS)
		return (result);
	dhcp_gbl_ctx.actx_started = ISC_TRUE;

	result = isc_taskmgr_createinctx(dhcp_gbl_ctx.mctx,
					 dhcp_gbl_ctx.actx,
					 1, 0,
					 &dhcp_gbl_ctx.taskmgr);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	result = isc_socketmgr_createinctx(dhcp_gbl_ctx.mctx,
					   dhcp_gbl_ctx.actx,
					   &dhcp_gbl_ctx.socketmgr);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	result = isc_timermgr_createinctx(dhcp_gbl_ctx.mctx,
					  dhcp_gbl_ctx.actx,
					  &dhcp_gbl_ctx.timermgr);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0, &dhcp_gbl_ctx.task);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

#if defined (NSUPDATE)
	result = dns_client_createx(dhcp_gbl_ctx.mctx,
				    dhcp_gbl_ctx.actx,
				    dhcp_gbl_ctx.taskmgr,
				    dhcp_gbl_ctx.socketmgr,
				    dhcp_gbl_ctx.timermgr,
				    0,
				    &dhcp_gbl_ctx.dnsclient);
	if (result != ISC_R_SUCCESS)
		goto cleanup;
#else
	/* The dst library is inited as part of dns_lib_init, we don't
	 * need it if NSUPDATE is enabled */
	result = dst_lib_init(dhcp_gbl_ctx.mctx, NULL, 0);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

#endif
	return(ISC_R_SUCCESS);

 cleanup:
	/*
	 * Currently we don't try and cleanup, just return an error
	 * expecting that our caller will log the error and exit.
	 */

	return(result);
}
Пример #3
0
int
main(int argc, char *argv[]) {
	dns_client_t *client = NULL;
	isc_result_t result;
	dns_fixedname_t qfn;
	dns_name_t *query_name, *response_name;
	dns_rdataset_t *rdataset;
	dns_namelist_t namelist;
	unsigned int resopt, clopt;
	isc_appctx_t *actx = NULL;
	isc_taskmgr_t *taskmgr = NULL;
	isc_socketmgr_t *socketmgr = NULL;
	isc_timermgr_t *timermgr = NULL;
	dns_master_style_t *style = NULL;
#ifndef WIN32
	struct sigaction sa;
#endif

	progname = argv[0];
	preparse_args(argc, argv);

	argc--;
	argv++;

	isc_lib_register();
	result = dns_lib_init();
	if (result != ISC_R_SUCCESS)
		fatal("dns_lib_init failed: %d", result);

	result = isc_mem_create(0, 0, &mctx);
	if (result != ISC_R_SUCCESS)
		fatal("failed to create mctx");

	CHECK(isc_appctx_create(mctx, &actx));
	CHECK(isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr));
	CHECK(isc_socketmgr_createinctx(mctx, actx, &socketmgr));
	CHECK(isc_timermgr_createinctx(mctx, actx, &timermgr));

	parse_args(argc, argv);

	CHECK(setup_style(&style));

	setup_logging(stderr);

	CHECK(isc_app_ctxstart(actx));

#ifndef WIN32
	/* Unblock SIGINT if it's been blocked by isc_app_ctxstart() */
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = SIG_DFL;
	if (sigfillset(&sa.sa_mask) != 0 || sigaction(SIGINT, &sa, NULL) < 0)
		fatal("Couldn't set up signal handler");
#endif

	/* Create client */
	clopt = DNS_CLIENTCREATEOPT_USECACHE;
	result = dns_client_createx2(mctx, actx, taskmgr, socketmgr, timermgr,
				     clopt, &client, srcaddr4, srcaddr6);
	if (result != ISC_R_SUCCESS) {
		delv_log(ISC_LOG_ERROR, "dns_client_create: %s",
			  isc_result_totext(result));
		goto cleanup;
	}

	/* Set the nameserver */
	if (server != NULL)
		addserver(client);
	else
		findserver(client);

	CHECK(setup_dnsseckeys(client));

	/* Construct QNAME */
	CHECK(convert_name(&qfn, &query_name, qname));

	/* Set up resolution options */
	resopt = DNS_CLIENTRESOPT_ALLOWRUN | DNS_CLIENTRESOPT_NOCDFLAG;
	if (no_sigs)
		resopt |= DNS_CLIENTRESOPT_NODNSSEC;
	if (!root_validation && !dlv_validation)
		resopt |= DNS_CLIENTRESOPT_NOVALIDATE;
	if (cdflag)
		resopt &= ~DNS_CLIENTRESOPT_NOCDFLAG;

	/* Perform resolution */
	ISC_LIST_INIT(namelist);
	result = dns_client_resolve(client, query_name, dns_rdataclass_in,
				    qtype, resopt, &namelist);
	if (result != ISC_R_SUCCESS)
		delv_log(ISC_LOG_ERROR, "resolution failed: %s",
			  isc_result_totext(result));

	for (response_name = ISC_LIST_HEAD(namelist);
	     response_name != NULL;
	     response_name = ISC_LIST_NEXT(response_name, link)) {
		for (rdataset = ISC_LIST_HEAD(response_name->list);
		     rdataset != NULL;
		     rdataset = ISC_LIST_NEXT(rdataset, link)) {
			result = printdata(rdataset, response_name, style);
			if (result != ISC_R_SUCCESS)
				delv_log(ISC_LOG_ERROR, "print data failed");
		}
	}

	dns_client_freeresanswer(client, &namelist);

cleanup:
	if (dlv_anchor != NULL)
		isc_mem_free(mctx, dlv_anchor);
	if (trust_anchor != NULL)
		isc_mem_free(mctx, trust_anchor);
	if (anchorfile != NULL)
		isc_mem_free(mctx, anchorfile);
	if (qname != NULL)
		isc_mem_free(mctx, qname);
	if (style != NULL)
		dns_master_styledestroy(&style, mctx);
	if (client != NULL)
		dns_client_destroy(&client);
	if (taskmgr != NULL)
		isc_taskmgr_destroy(&taskmgr);
	if (timermgr != NULL)
		isc_timermgr_destroy(&timermgr);
	if (socketmgr != NULL)
		isc_socketmgr_destroy(&socketmgr);
	if (actx != NULL)
		isc_appctx_destroy(&actx);
	if (lctx != NULL)
		isc_log_destroy(&lctx);
	isc_mem_detach(&mctx);

	dns_lib_shutdown();

	return (0);
}