simple code (DDNS)

Stefan Puiu stefan.puiu at gmail.com
Mon Mar 6 07:01:24 UTC 2006


I've only used res_nupdate(), and then switched to lower level
functions like res_nmkupdate() and res_nsendsigned(), but I think that
what res_update() does is call res_findzonecut() for each zone, which
finds the zone to update, the nameservers to update, and then performs
the update. You should check its return value btw, it returns the
number of zones updated.

Now, you can only imagine what will happen when res_findzonecut() is
passed an empty string as the owner name - what zone can it determine
from that? I wouldn't be surprised if it justs returns an error.

The second update will also be invalid, since you can't have a domain
name as the rdata in an A record.

You could try to watch the traffic with a sniffer - however, probably
the first call to dns_update() won't generate any, if it has any input
checking.

On 3/4/06, Roman Mashak <romez777 at gmail.com> wrote:
> Hello.
>
> I tried to implement simple function for DNS updates (to understand
> better internals of Bind and Co.). I used code from 'nsupdate.c' and
> simplified a bit. I thought I left the most important core, seems like
> I missed something cause it doesn't work as it's supposed to do:
>
> <skip headers>
>
> int dns_update(unsigned char *r_dname,int r_opcode,short int r_type,
>                 unsigned int r_ttl,int r_size,unsigned char *r_data) {
>
>
>         int r_section;
>         short int r_class;
>         ns_updrec *rrecp;
>
>         r_section=S_UPDATE;
>         r_class=C_IN;
>
>         if ( !(rrecp = res_mkupdrec(r_section, r_dname, r_class,
>              r_type, r_ttl)) || (r_size > 0 &&
>              !(rrecp->r_data = (u_char *)malloc(r_size))))
>
>                 return(0);
>
>         rrecp->r_opcode=r_opcode;
>         rrecp->r_size=r_size;
>         if(r_size>0) strcpy(rrecp->r_data,r_data);
>
> #if !defined(BIND821) && !defined(__FreeBSD__)
>         rrecp->r_link.prev=NULL;
>         rrecp->r_link.next=NULL;
> #else
>         rrecp->r_prev=NULL;
>         rrecp->r_next=NULL;
> #endif
>
>         res_update(rrecp);
>         if(rrecp->r_size) free(rrecp->r_data);
>         free(rrecp);
>         return(1);
> }
>
> int main(int argc, char *argv[])
> {
>         unsigned char str[128];
>
>         if (argc < 2)
>                 return -1;
>
>         sprintf(str, "%s", argv[1]);
>         dns_update(str,DELETE,T_A,0,0,"");
>         dns_update(str,ADD,T_A,DYN_TTL,strlen(str),str);
>
>         return 0;
> }
>
> #gcc -Wall -I/ext/mrv/my_local/usr/local/bind/include
> -L/ext/mrv/my_local/usr/local/bind/lib -g -o ddns ddns.c -lbind
>
> I tried to compile it with Bind8 and Bind9 libraries, succedded but I
> updates are not processed, and no records in llog file at all. Where
> has the problem hidden?
>
> Thanks in advance.
>
> --
> Roman
>
>
>



More information about the bind-users mailing list