getrrset.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000-2005, 2007, 2012, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington */
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: getrrset.c,v 1.18 2007/06/19 23:47:22 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/**
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * DESCRIPTION
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * lwres_getrrsetbyname() gets a set of resource records associated with
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * a hostname, class, and type. hostname is a pointer a to
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * null-terminated string. The flags field is currently unused and must
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * be zero.
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * After a successful call to lwres_getrrsetbyname(), *res is a pointer
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * to an #rrsetinfo structure, containing a list of one or more #rdatainfo
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * structures containing resource records and potentially another list of
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * rdatainfo structures containing SIG resource records associated with
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * those records. The members #rri_rdclass and #rri_rdtype are copied from
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * the parameters. #rri_ttl and #rri_name are properties of the obtained
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * rrset. The resource records contained in #rri_rdatas and #rri_sigs are
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * in uncompressed DNS wire format. Properties of the rdataset are
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * represented in the #rri_flags bitfield. If the #RRSET_VALIDATED bit is
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * set, the data has been DNSSEC validated and the signatures verified.
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * All of the information returned by lwres_getrrsetbyname() is
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * dynamically allocated: the rrsetinfo and rdatainfo structures, and the
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * canonical host name strings pointed to by the rrsetinfostructure.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Memory allocated for the dynamically allocated structures created by a
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * successful call to lwres_getrrsetbyname() is released by
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * lwres_freerrset(). rrset is a pointer to a struct rrset created by a
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * call to lwres_getrrsetbyname().
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * The following structures are used:
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \code
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * struct rdatainfo {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rdi_length; // length of data
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned char *rdi_data; // record data
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * };
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * struct rrsetinfo {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rri_flags; // RRSET_VALIDATED...
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rri_rdclass; // class number
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rri_rdtype; // RR type number
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rri_ttl; // time to live
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rri_nrdatas; // size of rdatas array
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * unsigned int rri_nsigs; // size of sigs array
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * char *rri_name; // canonical name
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * struct rdatainfo *rri_rdatas; // individual records
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * struct rdatainfo *rri_sigs; // individual signatures
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * };
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \endcode
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \section getrrset_return Return Values
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * lwres_getrrsetbyname() returns zero on success, and one of the
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * following error codes if an error occurred:
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ERRSET_NONAME: the name does not exist
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ERRSET_NODATA:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * the name exists, but does not have data of the desired type
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ERRSET_NOMEMORY:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * memory could not be allocated
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ERRSET_INVAL:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * a parameter is invalid
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ERRSET_FAIL:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * other failure
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <config.h>
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <string.h>
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <errno.h>
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <stdlib.h>
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <lwres/lwres.h>
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <lwres/net.h>
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include <lwres/netdb.h> /* XXX #include <netdb.h> */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington#include "assert_p.h"
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Structure to map results
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonstatic unsigned int
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwresult_to_result(lwres_result_t lwresult) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington switch (lwresult) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington case LWRES_R_SUCCESS: return (ERRSET_SUCCESS);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington case LWRES_R_NOMEMORY: return (ERRSET_NOMEMORY);
47ad4fad771b9c570bcf57793d6a931e0ca9856cAndreas Gustafsson case LWRES_R_NOTFOUND: return (ERRSET_NONAME);
47ad4fad771b9c570bcf57793d6a931e0ca9856cAndreas Gustafsson case LWRES_R_TYPENOTFOUND: return (ERRSET_NODATA);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington default: return (ERRSET_FAIL);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington}
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson * malloc / calloc functions that guarantee to only
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson * return NULL if there is an error, like they used
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson * to before the ANSI C committee broke them.
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson */
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafssonstatic void *
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafssonsane_malloc(size_t size) {
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews if (size == 0U)
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson size = 1;
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson return (malloc(size));
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson}
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafssonstatic void *
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafssonsane_calloc(size_t number, size_t size) {
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson size_t len = number * size;
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson void *mem = sane_malloc(len);
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson if (mem != NULL)
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson memset(mem, 0, len);
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson return (mem);
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson}
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Returns a set of resource records associated with a hostname, class, and type. hostname is a pointer a to null-terminated string. */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonint
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_getrrsetbyname(const char *hostname, unsigned int rdclass,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington unsigned int rdtype, unsigned int flags,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington struct rrsetinfo **res)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington{
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_context_t *lwrctx = NULL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_result_t lwresult;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_grbnresponse_t *response = NULL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington struct rrsetinfo *rrset = NULL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington unsigned int i;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington unsigned int lwflags;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington unsigned int result;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rdclass > 0xffff || rdtype > 0xffff) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_INVAL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington /*
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington * Don't allow queries of class or type ANY
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington */
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington if (rdclass == 0xff || rdtype == 0xff) {
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington result = ERRSET_INVAL;
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington goto fail;
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington }
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwresult = lwres_context_create(&lwrctx, NULL, NULL, NULL, 0);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (lwresult != LWRES_R_SUCCESS) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = lwresult_to_result(lwresult);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington (void) lwres_conf_parse(lwrctx, lwres_resolv_conf);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington /*
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * If any input flags were defined, lwflags would be set here
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington * based on them
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington UNUSED(flags);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwflags = 0;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
5e2f4725611cf90870268a798409ce3ebe684474Brian Wellington lwresult = lwres_getrdatabyname(lwrctx, hostname,
15c7a1bf207173deb2bff1d610d5f784b6629875Tinderbox User (lwres_uint16_t)rdclass,
5e2f4725611cf90870268a798409ce3ebe684474Brian Wellington (lwres_uint16_t)rdtype,
5e2f4725611cf90870268a798409ce3ebe684474Brian Wellington lwflags, &response);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (lwresult != LWRES_R_SUCCESS) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = lwresult_to_result(lwresult);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson rrset = sane_malloc(sizeof(struct rrsetinfo));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset == NULL) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_NOMEMORY;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_name = NULL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_rdclass = response->rdclass;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_rdtype = response->rdtype;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_ttl = response->ttl;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_flags = 0;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_nrdatas = 0;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_rdatas = NULL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_nsigs = 0;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_sigs = NULL;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson rrset->rri_name = sane_malloc(response->realnamelen + 1);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset->rri_name == NULL) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_NOMEMORY;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington strncpy(rrset->rri_name, response->realname, response->realnamelen);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_name[response->realnamelen] = 0;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if ((response->flags & LWRDATA_VALIDATED) != 0)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_flags |= RRSET_VALIDATED;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_nrdatas = response->nrdatas;
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson rrset->rri_rdatas = sane_calloc(rrset->rri_nrdatas,
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington sizeof(struct rdatainfo));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset->rri_rdatas == NULL) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_NOMEMORY;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington for (i = 0; i < rrset->rri_nrdatas; i++) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_rdatas[i].rdi_length = response->rdatalen[i];
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_rdatas[i].rdi_data =
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson sane_malloc(rrset->rri_rdatas[i].rdi_length);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset->rri_rdatas[i].rdi_data == NULL) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_NOMEMORY;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(rrset->rri_rdatas[i].rdi_data, response->rdatas[i],
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt rrset->rri_rdatas[i].rdi_length);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_nsigs = response->nsigs;
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson rrset->rri_sigs = sane_calloc(rrset->rri_nsigs,
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson sizeof(struct rdatainfo));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset->rri_sigs == NULL) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_NOMEMORY;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington for (i = 0; i < rrset->rri_nsigs; i++) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_sigs[i].rdi_length = response->siglen[i];
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington rrset->rri_sigs[i].rdi_data =
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson sane_malloc(rrset->rri_sigs[i].rdi_length);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset->rri_sigs[i].rdi_data == NULL) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington result = ERRSET_NOMEMORY;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington goto fail;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(rrset->rri_sigs[i].rdi_data, response->sigs[i],
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt rrset->rri_sigs[i].rdi_length);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_grbnresponse_free(lwrctx, &response);
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews lwres_conf_clear(lwrctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_context_destroy(&lwrctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington *res = rrset;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington return (ERRSET_SUCCESS);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington fail:
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (rrset != NULL)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_freerrset(rrset);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington if (response != NULL)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_grbnresponse_free(lwrctx, &response);
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews if (lwrctx != NULL) {
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews lwres_conf_clear(lwrctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington lwres_context_destroy(&lwrctx);
d9e0458a890c49f977fdcf9d995681f546f7c427Mark Andrews }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington return (result);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington}
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Releases memory allocated for the dynamically allocated structures created by a successful call to lwres_getrrsetbyname(). */
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonvoid
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellingtonlwres_freerrset(struct rrsetinfo *rrset) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington unsigned int i;
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews if (rrset->rri_rdatas != NULL) {
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews for (i = 0; i < rrset->rri_nrdatas; i++) {
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews if (rrset->rri_rdatas[i].rdi_data == NULL)
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews break;
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews free(rrset->rri_rdatas[i].rdi_data);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews }
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews free(rrset->rri_rdatas);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews if (rrset->rri_sigs != NULL) {
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews for (i = 0; i < rrset->rri_nsigs; i++) {
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews if (rrset->rri_sigs[i].rdi_data == NULL)
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews break;
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews free(rrset->rri_sigs[i].rdi_data);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews }
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews free(rrset->rri_sigs);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington }
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington free(rrset->rri_name);
fd091cb3cd17e4e3a7b8c49454db0863a31a7e7dBrian Wellington free(rrset);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington}