]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix unbound-control local_data and local_datas to print detailed
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 16 Jul 2021 08:51:27 +0000 (10:51 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 16 Jul 2021 08:51:27 +0000 (10:51 +0200)
  syntax errors.

daemon/remote.c
doc/Changelog
doc/unbound-control.8.in

index 5836c0c7986177a81e4069e579d19a215be0922c..4cba37895a1fcff8bdf5097482b33ee60ec13e8c 100644 (file)
@@ -1304,10 +1304,35 @@ do_zones_remove(RES* ssl, struct local_zones* zones)
        (void)ssl_printf(ssl, "removed %d zones\n", num);
 }
 
+/** check syntax of newly added RR */
+static int
+check_RR_syntax(RES* ssl, char* str, int line)
+{
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       size_t len = sizeof(rr), dname_len = 0;
+       int s = sldns_str2wire_rr_buf(str, rr, &len, &dname_len, 3600,
+               NULL, 0, NULL, 0);
+       if(s != 0) {
+               char linestr[32];
+               if(line == 0)
+                       linestr[0]=0;
+               else    snprintf(linestr, sizeof(linestr), "line %d ", line);
+               if(!ssl_printf(ssl, "error parsing local-data at %sposition %d '%s': %s\n",
+                       linestr, LDNS_WIREPARSE_OFFSET(s), str,
+                       sldns_get_errorstr_parse(s)))
+                       return 0;
+               return 0;
+       }
+       return 1;
+}
+
 /** Add new RR data */
 static int
-perform_data_add(RES* ssl, struct local_zones* zones, char* arg)
+perform_data_add(RES* ssl, struct local_zones* zones, char* arg, int line)
 {
+       if(!check_RR_syntax(ssl, arg, line)) {
+               return 0;
+       }
        if(!local_zones_add_RR(zones, arg)) {
                ssl_printf(ssl,"error in syntax or out of memory, %s\n", arg);
                return 0;
@@ -1319,7 +1344,7 @@ perform_data_add(RES* ssl, struct local_zones* zones, char* arg)
 static void
 do_data_add(RES* ssl, struct local_zones* zones, char* arg)
 {
-       if(!perform_data_add(ssl, zones, arg))
+       if(!perform_data_add(ssl, zones, arg, 0))
                return;
        send_ok(ssl);
 }
@@ -1329,11 +1354,12 @@ static void
 do_datas_add(RES* ssl, struct local_zones* zones)
 {
        char buf[2048];
-       int num = 0;
+       int num = 0, line = 0;
        while(ssl_read_line(ssl, buf, sizeof(buf))) {
                if(buf[0] == 0x04 && buf[1] == 0)
                        break; /* end of transmission */
-               if(!perform_data_add(ssl, zones, buf)) {
+               line++;
+               if(!perform_data_add(ssl, zones, buf, line)) {
                        if(!ssl_printf(ssl, "error for input line: %s\n", buf))
                                return;
                }
index 6863c23c949fc48334bd61f3c6e492e792ac9152..f97944e3ea7e5bf529e7805fdcc66173cfc5034c 100644 (file)
@@ -4,6 +4,8 @@
        - Fix for #510: in depth, use ifdefs for windows api event calls.
        - Fix spelling in doc/unbound.doxygen comment.
        - Fix spelling in localzone.h comment.
+       - Fix unbound-control local_data and local_datas to print detailed
+         syntax errors.
 
 6 July 2021: Wouter
        - iana portlist update.
index dad840cf58f9d589e26eb6dee3b195d10203fc9c..1b5ef393c4d8903f138fa90152567da58a1fd5b1 100644 (file)
@@ -89,8 +89,7 @@ it.  If the zone does not exist, the command succeeds.
 Add new local data, the given resource record. Like \fBlocal\-data\fR
 config statement, except for when no covering zone exists.  In that case
 this remote control command creates a transparent zone with the same 
-name as this record.  This command is not good at returning detailed syntax 
-errors.
+name as this record.
 .TP
 .B local_data_remove \fIname
 Remove all RR data from local name.  If the name already has no items,