res_update.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
static char rcsid[] = "$Id: res_update.c,v 1.1.1.1 2003/11/19 01:51:39 kyu3 Exp $";
#endif /* not lint */
/*
* Copyright (c) 1996 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Portions copyright (c) 1999, 2000
* Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
*
* This product includes software developed by Intel Corporation and
* its contributors.
*
* 4. Neither the name of Intel Corporation or its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* Based on the Dynamic DNS reference implementation by Viraj Bais
* <viraj_bais@ccm.fm.intel.com>
*/
#include <errno.h>
#include <limits.h>
#include <netdb.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Separate a linked list of records into groups so that all records
* in a group will belong to a single zone on the nameserver.
* Create a dynamic update packet for each zone and send it to the
* nameservers for that zone, and await answer.
* Abort if error occurs in updating any zone.
* Return the number of zones updated on success, < 0 on error.
*
* On error, caller must deal with the unsynchronized zones
* eg. an A record might have been successfully added to the forward
* zone but the corresponding PTR record would be missing if error
* was encountered while updating the reverse zone.
*/
#define NSMAX 16
struct ns1 {
};
struct zonegrp {
int z_nscount;
};
int
return (-1);
}
done = 0;
seen_before = 0;
for (tmpzptr = zgrp_start;
tmpzptr && !seen_before;
if (strcasecmp(dname,
seen_before++;
tmprrecp && !seen_before;
seen_before++;
break;
}
if (seen_before) {
/*
* Append to the end of
* current group.
*/
(void)NULL;
done = 1;
break;
}
}
for (tmpzptr = zgrp_start;
dname) == 0 &&
done = 1;
break;
}
}
if (done)
break;
if (n <= 0) {
return (n);
}
if (n < 0) {
return (n);
}
if (n < HFIXEDSZ)
return (-1);
/* skip the question section */
return (-1);
/*
* if (rcode == NOERROR) then the dname exists but
* has no soa record associated with it.
* if (rcode == NXDOMAIN) then the dname does not
* exist and the server is replying out of NCACHE.
* in either case, proceed with the next try
*/
dname++;
continue;
ancount == 0 &&
/*
* authority section
*/
/* authority section must contain the soa record */
sizeof zname)) < 0)
return (n);
cp += n;
return (-1);
return (-1);
}
myzone = 0;
while (dname)
myzone = 1;
break;
dname++;
if (!myzone) {
dname++;
continue;
}
nscount = 0;
/* fallthrough */
/*
* found the zone name
* new servers will supply NS records for the zone
* in authority section and A records for those
* nameservers in the additional section
* older servers have to be explicitly queried for
* NS records for the zone
*/
/* answer section must contain the soa record */
sizeof zname)) < 0)
return (n);
else
cp += n;
return (-1);
dname++;
continue;
}
return (-1);
}
/* FALLTHROUGH */
} else {
"unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
return (-1);
}
return (-1);
/* continue processing the soa record */
return (-1);
newgroup = 1;
zptr = zgrp_start;
while (zptr) {
newgroup = 0;
break;
}
}
if (!newgroup) {
;
done = 1;
break;
} else {
sizeof primary)) < 0)
return (n);
cp += n;
/*
* We don't have to bounds check here because the
* next use of 'cp' is in dn_expand().
*/
sizeof mailaddr)) < 0)
return (n);
cp += n;
return (-1);
return (-1);
if (zgrp_start == NULL)
zgrp_start = zptr;
else
/* fallthrough to process NS and A records */
}
break;
}
/* should not happen */
return (-1);
if (nscount > 0) {
/*
* answer and authority sections contain
* the same information, skip answer section
*/
for (j = 0; j < ancount; j++) {
if (n < 0)
return (-1);
return (-1);
cp += n;
}
} else
/* fallthrough to process NS and A records */
} else {
ans=%d, auth=%d, add=%d, rcode=%d\n",
return (-1);
}
/* fallthrough to process A records */
} else {
ans=%d, auth=%d, add=%d, rcode=%d\n",
return (-1);
}
}
/* process NS records for the zone */
j = 0;
for (i = 0; i < nscount; i++) {
sizeof name)) < 0)
return (n);
cp += n;
return (-1);
return (-1);
return (n);
}
}
/* get addresses for the nameservers */
for (i = 0; i < arcount; i++) {
sizeof name)) < 0)
return (n);
cp += n;
return (-1);
return (-1);
INT32SZ);
break;
}
}
}
continue;
}
done = 1;
done = 0;
}
} /* while */
}
/* append zone section */
return (-1);
}
if (n < 0) {
return (-1);
} else
/*
* Override the list of NS records from res_init() with
* the authoritative nameservers for the zone being updated.
* Sort primary to be the first in the list of nameservers.
*/
zptr->z_soardata) == 0) {
if (i != 0) {
zptr->z_soardata);
}
break;
}
}
for (i = 0; i < MAXNS; i++) {
}
if (n < 0) {
break;
} else
numzones++;
}
/* free malloc'ed memory */
while(zgrp_start) {
zptr = zgrp_start;
}
return (numzones);
}