getrrset.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2000-2005, 2007, 2012, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: getrrset.c,v 1.18 2007/06/19 23:47:22 tbox Exp $ */
/*! \file */
/**
* DESCRIPTION
*
* lwres_getrrsetbyname() gets a set of resource records associated with
* a hostname, class, and type. hostname is a pointer a to
* null-terminated string. The flags field is currently unused and must
* be zero.
*
* After a successful call to lwres_getrrsetbyname(), *res is a pointer
* to an #rrsetinfo structure, containing a list of one or more #rdatainfo
* structures containing resource records and potentially another list of
* rdatainfo structures containing SIG resource records associated with
* those records. The members #rri_rdclass and #rri_rdtype are copied from
* the parameters. #rri_ttl and #rri_name are properties of the obtained
* rrset. The resource records contained in #rri_rdatas and #rri_sigs are
* in uncompressed DNS wire format. Properties of the rdataset are
* represented in the #rri_flags bitfield. If the #RRSET_VALIDATED bit is
* set, the data has been DNSSEC validated and the signatures verified.
*
* All of the information returned by lwres_getrrsetbyname() is
* dynamically allocated: the rrsetinfo and rdatainfo structures, and the
* canonical host name strings pointed to by the rrsetinfostructure.
* Memory allocated for the dynamically allocated structures created by a
* successful call to lwres_getrrsetbyname() is released by
* lwres_freerrset(). rrset is a pointer to a struct rrset created by a
* call to lwres_getrrsetbyname().
*
* The following structures are used:
*
* \code
* struct rdatainfo {
* unsigned int rdi_length; // length of data
* unsigned char *rdi_data; // record data
* };
*
* struct rrsetinfo {
* unsigned int rri_flags; // RRSET_VALIDATED...
* unsigned int rri_rdclass; // class number
* unsigned int rri_rdtype; // RR type number
* unsigned int rri_ttl; // time to live
* unsigned int rri_nrdatas; // size of rdatas array
* unsigned int rri_nsigs; // size of sigs array
* char *rri_name; // canonical name
* struct rdatainfo *rri_rdatas; // individual records
* struct rdatainfo *rri_sigs; // individual signatures
* };
* \endcode
*
* \section getrrset_return Return Values
*
* lwres_getrrsetbyname() returns zero on success, and one of the
* following error codes if an error occurred:
*
* \li #ERRSET_NONAME: the name does not exist
*
* \li #ERRSET_NODATA:
* the name exists, but does not have data of the desired type
*
* \li #ERRSET_NOMEMORY:
* memory could not be allocated
*
* \li #ERRSET_INVAL:
* a parameter is invalid
*
* \li #ERRSET_FAIL:
* other failure
*/
#include <config.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include "assert_p.h"
/*!
* Structure to map results
*/
static unsigned int
switch (lwresult) {
case LWRES_R_SUCCESS: return (ERRSET_SUCCESS);
case LWRES_R_NOMEMORY: return (ERRSET_NOMEMORY);
case LWRES_R_NOTFOUND: return (ERRSET_NONAME);
case LWRES_R_TYPENOTFOUND: return (ERRSET_NODATA);
default: return (ERRSET_FAIL);
}
}
/*@{*/
/*!
* malloc / calloc functions that guarantee to only
* return NULL if there is an error, like they used
* to before the ANSI C committee broke them.
*/
static void *
if (size == 0U)
size = 1;
}
static void *
return (mem);
}
/*@}*/
/*% Returns a set of resource records associated with a hostname, class, and type. hostname is a pointer a to null-terminated string. */
int
{
unsigned int i;
unsigned int lwflags;
unsigned int result;
goto fail;
}
/*
* Don't allow queries of class or type ANY
*/
goto fail;
}
if (lwresult != LWRES_R_SUCCESS) {
goto fail;
}
/*
* If any input flags were defined, lwflags would be set here
* based on them
*/
lwflags = 0;
if (lwresult != LWRES_R_SUCCESS) {
goto fail;
}
goto fail;
}
rrset->rri_nrdatas = 0;
goto fail;
}
sizeof(struct rdatainfo));
goto fail;
}
for (i = 0; i < rrset->rri_nrdatas; i++) {
goto fail;
}
}
sizeof(struct rdatainfo));
goto fail;
}
goto fail;
}
}
return (ERRSET_SUCCESS);
fail:
}
return (result);
}
/*% Releases memory allocated for the dynamically allocated structures created by a successful call to lwres_getrrsetbyname(). */
void
unsigned int i;
for (i = 0; i < rrset->rri_nrdatas; i++) {
break;
}
}
break;
}
}
}