- if (qu->cnameoff<0 &&
- (qu->typei->type & adns__rrt_typemask) != adns_r_cname &&
- rrtype == adns_r_cname) { /* Ignore second and subsequent CNAMEs */
- st= adns__get_domain_perm(ads,qu,serv, dgram,dglen,
- &rdstart,rdstart+rdlength,&qu->cnameoff);
- if (st) { adns__query_fail(ads,qu,st); return; }
- if (qu->cnameoff==-1) goto x_truncated;
- /* If we find the answer section truncated after this point we restart
- * the query at the CNAME; if beforehand then we obviously have to use
- * TCP. If there is no truncation we can use the whole answer if
- * it contains the relevant info.
- */
+ if (rrtype == adns_r_cname &&
+ (qu->typei->type & adns__rrt_typemask) != adns_r_cname) {
+ if (qu->flags & adns_qf_cname_forbid) {
+ adns__query_fail(qu,adns_s_prohibitedcname);
+ return;
+ } else if (qu->cname_dgram) { /* Ignore second and subsequent CNAME(s) */
+ adns__debug(ads,serv,qu,"allegedly canonical name %s"
+ " is actually alias for %s", qu->answer->cname,
+ adns__diag_domain(ads,serv,qu, &qu->vb,
+ dgram,dglen,rdstart));
+ adns__query_fail(qu,adns_s_prohibitedcname);
+ return;
+ } else if (wantedrrs) { /* Ignore CNAME(s) after RR(s). */
+ adns__debug(ads,serv,qu,"ignoring CNAME (to %s) coexisting with RR",
+ adns__diag_domain(ads,serv,qu, &qu->vb,
+ dgram,dglen,rdstart));
+ } else {
+ qu->cname_begin= rdstart;
+ qu->cname_dglen= dglen;
+ st= adns__parse_domain(ads,serv,qu, &qu->vb,
+ qu->flags & adns_qf_quotefail_cname
+ ? 0 : pdf_quoteok,
+ dgram,dglen, &rdstart,rdstart+rdlength);
+ if (!qu->vb.used) goto x_truncated;
+ if (st) { adns__query_fail(qu,st); return; }
+ l= strlen(qu->vb.buf)+1;
+ qu->answer->cname= adns__alloc_preserved(qu,l);
+ if (!qu->answer->cname) {
+ adns__query_fail(qu,adns_s_nomemory);
+ return;
+ }
+
+ qu->cname_dgram= adns__alloc_mine(qu,dglen);
+ memcpy(qu->cname_dgram,dgram,dglen);
+
+ memcpy(qu->answer->cname,qu->vb.buf,l);
+ cname_here= 1;
+ adns__update_expires(qu,ttl,now);
+ /* If we find the answer section truncated after this point we restart
+ * the query at the CNAME; if beforehand then we obviously have to use
+ * TCP. If there is no truncation we can use the whole answer if
+ * it contains the relevant info.
+ */
+ }