adns_status adns__parse_domain_more(findlabel_state *flstate, adns_state ads,
				    adns_query qu, vbuf *vb, parsedomain_flags flags,
				    const byte *dgram) {
  int lablen, labstart, i, ch, first;
  adns_status st;

  first= 1;
  for (;;) {
    st= adns__findlabel_next(flstate,&lablen,&labstart);
    if (st) return st;
    if (lablen<0) { vb->used=0; return adns_s_ok; }
    if (!lablen) break;
    if (first) {
      first= 0;
    } else {
      if (!adns__vbuf_append(vb,".",1)) return adns_s_nomemory;
    }
    if (flags & pdf_quoteok) {
      if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
	return adns_s_nomemory;
    } else {
      ch= dgram[labstart];
      if (!ctype_alpha(ch) && !ctype_digit(ch)) return adns_s_answerdomaininvalid;
      for (i= labstart+1; i<labstart+lablen; i++) {
	ch= dgram[i];
	if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
	  return adns_s_answerdomaininvalid;
      }
      if (!adns__vbuf_append(vb, (const char *) dgram+labstart,lablen))
	return adns_s_nomemory;
    }
  }
  if (!adns__vbuf_append(vb,"",1)) return adns_s_nomemory;
  return adns_s_ok;
}
Exemple #2
0
adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
			  const char *owner, int ol,
			  const typeinfo *typei, adns_queryflags flags) {
  int ll, c, nbytes;
  byte label[255], *rqp;
  const char *p, *pe;
  adns_status st;

  st= mkquery_header(ads,vb,id_r,ol+2); if (st) return st;
  
  MKQUERY_START(vb);

  p= owner; pe= owner+ol;
  nbytes= 0;
  while (p!=pe) {
    ll= 0;
    while (p!=pe && (c= *p++)!='.') {
      if (c=='\\') {
	if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
	if (ctype_digit(p[0])) {
	  if (ctype_digit(p[1]) && ctype_digit(p[2])) {
            c = (*p++ - '0')*100;
            c += (*p++ - '0')*10;
            c += (*p++ - '0');
	    if (c >= 256) return adns_s_querydomaininvalid;
	  } else {
	    return adns_s_querydomaininvalid;
	  }
	} else if (!(c= *p++)) {
	  return adns_s_querydomaininvalid;
	}
      }
      if (!(flags & adns_qf_quoteok_query)) {
	if (c == '-') {
	  if (!ll) return adns_s_querydomaininvalid;
	} else if (!ctype_alpha(c) && !ctype_digit(c)) {
	  return adns_s_querydomaininvalid;
	}
      }
      if (ll == sizeof(label)) return adns_s_querydomaininvalid;
      label[ll++]= c;
    }
    if (!ll) return adns_s_querydomaininvalid;
    if (ll > DNS_MAXLABEL) return adns_s_querydomaintoolong;
    nbytes+= ll+1;
    if (nbytes >= DNS_MAXDOMAIN) return adns_s_querydomaintoolong;
    MKQUERY_ADDB(ll);
    memcpy(rqp,label,ll); rqp+= ll;
  }
  MKQUERY_ADDB(0);

  MKQUERY_STOP(vb);
  
  st= mkquery_footer(vb,typei->type);
  
  return adns_s_ok;
}
Exemple #3
0
adns_status adns__findrr_anychk(adns_query qu, int serv,
                                const byte *dgram, int dglen, int *cbyte_io,
                                int *type_r, int *class_r, unsigned long *ttl_r,
                                int *rdlen_r, int *rdstart_r,
                                const byte *eo_dgram, int eo_dglen, int eo_cbyte,
                                int *eo_matched_r)
{
    findlabel_state fls, eo_fls;
    int cbyte;

    int tmp, rdlen, mismatch;
    unsigned long ttl;
    int lablen, labstart, ch;
    int eo_lablen, eo_labstart, eo_ch;
    adns_status st;

    cbyte= *cbyte_io;

    adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
    if (eo_dgram)
    {
        adns__findlabel_start(&eo_fls,qu->ads, -1,0, eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
        mismatch= 0;
    }
    else
    {
        mismatch= 1;
    }

    for (;;)
    {
        st= adns__findlabel_next(&fls,&lablen,&labstart);
        if (st) return st;
        if (lablen<0) goto x_truncated;

        if (!mismatch)
        {
            st= adns__findlabel_next(&eo_fls,&eo_lablen,&eo_labstart);
            assert(!st);
            assert(eo_lablen>=0);
            if (lablen != eo_lablen) mismatch= 1;
            while (!mismatch && eo_lablen-- > 0)
            {
                ch= dgram[labstart++];
                if (ctype_alpha(ch)) ch &= ~32;
                eo_ch= eo_dgram[eo_labstart++];
                if (ctype_alpha(eo_ch)) eo_ch &= ~32;
                if (ch != eo_ch) mismatch= 1;
            }
        }
        if (!lablen) break;
    }
    if (eo_matched_r) *eo_matched_r= !mismatch;

    if (cbyte+10>dglen) goto x_truncated;
    GET_W(cbyte,tmp);
    *type_r= tmp;
    GET_W(cbyte,tmp);
    *class_r= tmp;

    GET_L(cbyte,ttl);
    if (ttl > MAXTTLBELIEVE) ttl= MAXTTLBELIEVE;
    *ttl_r= ttl;

    GET_W(cbyte,rdlen);
    if (rdlen_r) *rdlen_r= rdlen;
    if (rdstart_r) *rdstart_r= cbyte;
    cbyte+= rdlen;
    if (cbyte>dglen) goto x_truncated;
    *cbyte_io= cbyte;
    return adns_s_ok;

x_truncated:
    *type_r= -1;
    return 0;
}