]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
-s (strip DNSSEC) option in read-zone
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Wed, 20 Jun 2007 09:11:10 +0000 (09:11 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Wed, 20 Jun 2007 09:11:10 +0000 (09:11 +0000)
examples/ldns-read-zone.c

index b9db5aa1166357363ba4cb7057197d6cddc86f26..6483314368c0cc124b216c6476fa44c4cf9020ee 100644 (file)
@@ -22,10 +22,13 @@ main(int argc, char **argv)
        int c;
        bool canonicalize = false;
        bool sort = false;
+       bool strip = false;
        ldns_status s;
        size_t i;
+       ldns_rr_list *stripped_list;
+       ldns_rr *cur_rr;
 
-        while ((c = getopt(argc, argv, "chvz")) != -1) {
+        while ((c = getopt(argc, argv, "chsvz")) != -1) {
                 switch(c) {
                        case 'c':
                                canonicalize = true;
@@ -36,11 +39,15 @@ main(int argc, char **argv)
                                printf("\tThe RR count of the zone is printed to stderr.\n");
                                printf("\t-c canonicalize all rrs in the zone.\n");
                                printf("\t-h show this text\n");
+                               printf("\t-s strip DNSSEC data from the zone\n");
                                printf("\t-v shows the version and exits\n");
                                printf("\t-z sort the zone (implies -c).\n");
                                printf("\nif no file is given standard input is read\n");
                                exit(EXIT_SUCCESS);
                                break;
+                        case 's':
+                               strip = true;
+                               break;
                        case 'v':
                                printf("read zone version %s (ldns version %s)\n", LDNS_VERSION, ldns_version());
                                exit(EXIT_SUCCESS);
@@ -68,6 +75,26 @@ main(int argc, char **argv)
        }
        
        s = ldns_zone_new_frm_fp_l(&z, fp, NULL, 0, LDNS_RR_CLASS_IN, &line_nr);
+
+       if (strip) {
+               stripped_list = ldns_rr_list_new();
+               while ((cur_rr = ldns_rr_list_pop_rr(ldns_zone_rrs(z)))) {
+                       if (ldns_rr_get_type(cur_rr) == LDNS_RR_TYPE_RRSIG ||
+                           ldns_rr_get_type(cur_rr) == LDNS_RR_TYPE_NSEC
+                          ) {
+                               
+                               printf("remove:\n");
+                               ldns_rr_print(stdout, cur_rr);
+                               
+                               ldns_rr_free(cur_rr);
+                       } else {
+                               ldns_rr_list_push_rr(stripped_list, cur_rr);
+                       }
+               }
+               ldns_rr_list_free(ldns_zone_rrs(z));
+               ldns_zone_set_rrs(z, stripped_list);
+       }
+
        if (s == LDNS_STATUS_OK) {
                if (canonicalize) {
                        ldns_rr2canonical(ldns_zone_soa(z));