CVE-2016-2115: s3:winbindd: use lp_client_ipc_{min,max}_protocol()
[samba.git] / source4 / dns_server / dns_utils.c
index c757c1576266929335892c54666244ba008f12e0..ce450b56c645ba5489f9ac8fa1dc715e32aad5e0 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_DNS
 
-bool dns_name_match(const char *zone, const char *name, size_t *host_part_len)
-{
-       size_t zl = strlen(zone);
-       size_t nl = strlen(name);
-       ssize_t zi, ni;
-       static const size_t fixup = 'a' - 'A';
-
-       if (zl > nl) {
-               return false;
-       }
-
-       for (zi = zl, ni = nl; zi >= 0; zi--, ni--) {
-               char zc = zone[zi];
-               char nc = name[ni];
-
-               /* convert to lower case */
-               if (zc >= 'A' && zc <= 'Z') {
-                       zc += fixup;
-               }
-               if (nc >= 'A' && nc <= 'Z') {
-                       nc += fixup;
-               }
-
-               if (zc != nc) {
-                       return false;
-               }
-       }
-
-       if (ni >= 0) {
-               if (name[ni] != '.') {
-                       return false;
-               }
-
-               ni--;
-       }
-
-       *host_part_len = ni+1;
-
-       return true;
-}
-
 /* Names are equal if they match and there's nothing left over */
 bool dns_name_equal(const char *name1, const char *name2)
 {
@@ -199,54 +158,29 @@ bool dns_authorative_for_zone(struct dns_server *dns,
        return true;
 }
 
-WERROR dns_name2dn(struct dns_server *dns,
-                  TALLOC_CTX *mem_ctx,
-                  const char *name,
-                  struct ldb_dn **_dn)
+const char *dns_get_authoritative_zone(struct dns_server *dns,
+                                      const char *name)
 {
-       struct ldb_dn *base;
-       struct ldb_dn *dn;
        const struct dns_server_zone *z;
        size_t host_part_len = 0;
 
-       if (name == NULL) {
-               return DNS_ERR(FORMAT_ERROR);
-       }
-
-       /*TODO: Check if 'name' is a valid DNS name */
-
-       if (strcmp(name, "") == 0) {
-               base = ldb_get_default_basedn(dns->samdb);
-               dn = ldb_dn_copy(mem_ctx, base);
-               ldb_dn_add_child_fmt(dn, "DC=@,DC=RootDNSServers,CN=MicrosoftDNS,CN=System");
-               *_dn = dn;
-               return WERR_OK;
-       }
-
        for (z = dns->zones; z != NULL; z = z->next) {
                bool match;
-
                match = dns_name_match(z->name, name, &host_part_len);
                if (match) {
-                       break;
+                       return z->name;
                }
        }
+       return NULL;
+}
 
-       if (z == NULL) {
-               return DNS_ERR(NAME_ERROR);
-       }
-
-       if (host_part_len == 0) {
-               dn = ldb_dn_copy(mem_ctx, z->dn);
-               ldb_dn_add_child_fmt(dn, "DC=@");
-               *_dn = dn;
-               return WERR_OK;
-       }
-
-       dn = ldb_dn_copy(mem_ctx, z->dn);
-       ldb_dn_add_child_fmt(dn, "DC=%*.*s", (int)host_part_len, (int)host_part_len, name);
-       *_dn = dn;
-       return WERR_OK;
+WERROR dns_name2dn(struct dns_server *dns,
+                  TALLOC_CTX *mem_ctx,
+                  const char *name,
+                  struct ldb_dn **dn)
+{
+       return dns_common_name2dn(dns->samdb, dns->zones,
+                                 mem_ctx, name, dn);
 }
 
 WERROR dns_generate_options(struct dns_server *dns,
@@ -259,7 +193,7 @@ WERROR dns_generate_options(struct dns_server *dns,
        if (o == NULL) {
                return WERR_NOMEM;
        }
-       o->name = '\0';
+       o->name = NULL;
        o->rr_type = DNS_QTYPE_OPT;
        /* This is ugly, but RFC2671 wants the payload size in this field */
        o->rr_class = (enum dns_qclass) dns->max_payload;