Annotation of embedaddon/strongswan/scripts/dnssec.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2011-2012 Reto Guadagnini
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include <stdio.h>
! 17:
! 18: #include <library.h>
! 19: #include <utils/debug.h>
! 20:
! 21: /**
! 22: * Define debug level
! 23: */
! 24: static level_t dbg_level = 1;
! 25:
! 26: static void dbg_dnssec(debug_t group, level_t level, char *fmt, ...)
! 27: {
! 28: if ((level <= dbg_level) || level <= 1)
! 29: {
! 30: va_list args;
! 31:
! 32: va_start(args, fmt);
! 33: vfprintf(stderr, fmt, args);
! 34: fprintf(stderr, "\n");
! 35: va_end(args);
! 36: }
! 37: }
! 38:
! 39: int main(int argc, char *argv[])
! 40: {
! 41: resolver_t *resolver;
! 42: resolver_response_t *response;
! 43: enumerator_t *enumerator;
! 44: chunk_t rdata;
! 45: rr_set_t *rrset;
! 46: rr_t *rr;
! 47:
! 48: library_init(NULL, "dnssec");
! 49: atexit(library_deinit);
! 50:
! 51: dbg = dbg_dnssec;
! 52:
! 53: if (!lib->plugins->load(lib->plugins, PLUGINS))
! 54: {
! 55: return 1;
! 56: }
! 57: if (argc != 2)
! 58: {
! 59: fprintf(stderr, "usage: dnssec <name>\n");
! 60: return 1;
! 61: }
! 62:
! 63: resolver = lib->resolver->create(lib->resolver);
! 64: if (!resolver)
! 65: {
! 66: printf("failed to create a resolver!\n");
! 67: return 1;
! 68: }
! 69:
! 70: response = resolver->query(resolver, argv[1], RR_CLASS_IN, RR_TYPE_A);
! 71: if (!response)
! 72: {
! 73: printf("no response received!\n");
! 74: resolver->destroy(resolver);
! 75: return 1;
! 76: }
! 77:
! 78: printf("DNS response:\n");
! 79: if (!response->has_data(response) || !response->query_name_exist(response))
! 80: {
! 81: if (!response->has_data(response))
! 82: {
! 83: printf(" no data in the response\n");
! 84: }
! 85: if (!response->query_name_exist(response))
! 86: {
! 87: printf(" query name does not exist\n");
! 88: }
! 89: response->destroy(response);
! 90: resolver->destroy(resolver);
! 91: return 1;
! 92: }
! 93:
! 94: printf(" RRs in the response:\n");
! 95: rrset = response->get_rr_set(response);
! 96: if (!rrset)
! 97: {
! 98: printf(" response contains no RRset!\n");
! 99: response->destroy(response);
! 100: resolver->destroy(resolver);
! 101: return 1;
! 102: }
! 103:
! 104: enumerator = rrset->create_rr_enumerator(rrset);
! 105: while (enumerator->enumerate(enumerator, &rr))
! 106: {
! 107: printf(" name: %s\n", rr->get_name(rr));
! 108: }
! 109:
! 110: enumerator = rrset->create_rrsig_enumerator(rrset);
! 111: if (enumerator)
! 112: {
! 113: printf(" RRSIGs for the RRset:\n");
! 114: while (enumerator->enumerate(enumerator, &rr))
! 115: {
! 116: rdata = rr->get_rdata(rr);
! 117:
! 118: printf(" name: %s\n", rr->get_name(rr));
! 119: printf(" RDATA: %#B\n", &rdata);
! 120: }
! 121: }
! 122:
! 123: printf(" security status of the response: ");
! 124: switch (response->get_security_state(response))
! 125: {
! 126: case SECURE:
! 127: printf("SECURE\n\n");
! 128: break;
! 129: case INSECURE:
! 130: printf("INSECURE\n\n");
! 131: break;
! 132: case BOGUS:
! 133: printf("BOGUS\n\n");
! 134: break;
! 135: case INDETERMINATE:
! 136: printf("INDETERMINATE\n\n");
! 137: break;
! 138: }
! 139: response->destroy(response);
! 140: resolver->destroy(resolver);
! 141: return 0;
! 142: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>