]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add DNS_NAME_QUOTED flag for dns_name_totext()
authorMark Andrews <marka@isc.org>
Mon, 6 Jul 2026 02:59:50 +0000 (12:59 +1000)
committerMark Andrews <marka@isc.org>
Mon, 13 Jul 2026 22:31:59 +0000 (08:31 +1000)
Names that are to be printed within a pair of double quotes,
(for example, in named.conf), don't need spaces and special
characters to be fully escaped.

lib/dns/include/dns/name.h
lib/dns/name.c

index d0c336fe0b52616d8e1117f9ef47646503de91ca..db9752fc827eab908ee09a74cbc3ce4565575baa 100644 (file)
@@ -882,6 +882,7 @@ dns_name_wirefromtext(isc_buffer_t *source, const dns_name_t *origin,
 
 #define DNS_NAME_OMITFINALDOT 0x01U
 #define DNS_NAME_PRINCIPAL    0x02U /* do not escape $ and @ */
+#define DNS_NAME_QUOTED              0x04U /* minimal escaping within double quotes */
 
 isc_result_t
 dns_name_totext(const dns_name_t *name, unsigned int options,
@@ -1283,7 +1284,7 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest);
 bool
 dns_name_ishostname(const dns_name_t *name, bool wildcard);
 /*%<
- * Return if 'name' is a valid hostname.  RFC 952 / RFC 1123.
+ * Return true if 'name' is a valid hostname.  RFC 952 / RFC 1123.
  * If 'wildcard' is true then allow the first label of name to
  * be a wildcard.
  * The root is also accepted.
@@ -1295,7 +1296,7 @@ dns_name_ishostname(const dns_name_t *name, bool wildcard);
 bool
 dns_name_ismailbox(const dns_name_t *name);
 /*%<
- * Return if 'name' is a valid mailbox.  RFC 821.
+ * Return true if 'name' is a valid mailbox.  RFC 821.
  *
  * Requires:
  * \li 'name' to be valid.
@@ -1304,7 +1305,7 @@ dns_name_ismailbox(const dns_name_t *name);
 bool
 dns_name_internalwildcard(const dns_name_t *name);
 /*%<
- * Return if 'name' contains a internal wildcard name.
+ * Return true if 'name' contains a internal wildcard name.
  *
  * Requires:
  * \li 'name' to be valid.
index 1bb3f40f6540a70e0beb66be3103a1afba16cbce..a1a5e17e3ef1ef65834817f7fc4ee9f72e37f1f1 100644 (file)
@@ -981,6 +981,8 @@ dns_name_totext(const dns_name_t *name, unsigned int options,
        bool saw_root = false;
        unsigned int oused;
        bool omit_final_dot = ((options & DNS_NAME_OMITFINALDOT) != 0);
+       bool minimal = ((options & DNS_NAME_QUOTED) != 0);
+       bool principal = ((options & DNS_NAME_PRINCIPAL) != 0);
        bool first = true;
 
        /*
@@ -1047,16 +1049,19 @@ dns_name_totext(const dns_name_t *name, unsigned int options,
                                /* Special modifiers in zone files. */
                                case 0x40: /* '@' */
                                case 0x24: /* '$' */
-                                       if ((options & DNS_NAME_PRINCIPAL) != 0)
-                                       {
+                                       if (principal) {
                                                goto no_escape;
                                        }
                                        FALLTHROUGH;
-                               case 0x22: /* '"' */
                                case 0x28: /* '(' */
                                case 0x29: /* ')' */
-                               case 0x2E: /* '.' */
                                case 0x3B: /* ';' */
+                                       if (minimal) {
+                                               goto no_escape;
+                                       }
+                                       FALLTHROUGH;
+                               case 0x22: /* '"' */
+                               case 0x2E: /* '.' */
                                case 0x5C: /* '\\' */
                                        value = '\\' << 8 | c;
                                        CHECK(isc_buffer_reserve(target, 2));
@@ -1066,7 +1071,9 @@ dns_name_totext(const dns_name_t *name, unsigned int options,
                                        break;
                                no_escape:
                                default:
-                                       if (c > 0x20 && c < 0x7f) {
+                                       if ((c > 0x20 && c < 0x7f) ||
+                                           (c == 0x20 && minimal))
+                                       {
                                                CHECK(isc_buffer_reserve(target,
                                                                         1));
                                                isc_buffer_putuint8(target, c);