/*
* Copyright (c) 2000-2004, 2010 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska H�gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 THE INSTITUTE 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.
*/
#include <sendmail.h>
#if DNSMAP
# if NAMED_BIND
# if NETINET
# include <netinet/in_systm.h>
# endif /* NETINET */
# include "sm_resolve.h"
SM_RCSID("$Id: sm_resolve.c,v 8.40 2013-11-22 20:51:56 ca Exp $")
static struct stot
{
const char *st_name;
int st_type;
} stot[] =
{
# if NETINET
{ "A", T_A },
# endif /* NETINET */
# if NETINET6
{ "AAAA", T_AAAA },
# endif /* NETINET6 */
{ "NS", T_NS },
{ "CNAME", T_CNAME },
{ "PTR", T_PTR },
{ "MX", T_MX },
{ "TXT", T_TXT },
{ "AFSDB", T_AFSDB },
{ "SRV", T_SRV },
{ NULL, 0 }
};
/*
** DNS_STRING_TO_TYPE -- convert resource record name into type
**
** Parameters:
** name -- name of resource record type
**
** Returns:
** type if succeeded.
** -1 otherwise.
*/
int
const char *name;
{
return p->st_type;
return -1;
}
/*
** DNS_TYPE_TO_STRING -- convert resource record type into name
**
** Parameters:
** type -- resource record type
**
** Returns:
** name if succeeded.
** NULL otherwise.
*/
const char *
int type;
{
return p->st_name;
return NULL;
}
/*
** DNS_FREE_DATA -- free all components of a DNS_REPLY_T
**
** Parameters:
** r -- pointer to DNS_REPLY_T
**
** Returns:
** none.
*/
void
DNS_REPLY_T *r;
{
{
}
sm_free(r);
}
/*
** PARSE_DNS_REPLY -- parse DNS reply data.
**
** Parameters:
** data -- pointer to dns data
** len -- len of data
**
** Returns:
** pointer to DNS_REPLY_T if succeeded.
** NULL otherwise.
*/
static DNS_REPLY_T *
unsigned char *data;
int len;
{
unsigned char *p;
int status;
size_t l;
DNS_REPLY_T *r;
r = (DNS_REPLY_T *) sm_malloc(sizeof(*r));
if (r == NULL)
return NULL;
memset(r, 0, sizeof(*r));
p = data;
/* doesn't work on Crays? */
p += sizeof(r->dns_r_h);
if (status < 0)
{
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
p += status;
rr = &r->dns_r_head;
ui = 0;
{
if (status < 0)
{
dns_free_data(r);
return NULL;
}
++ui;
p += status;
{
/*
** announced size of data exceeds length of
** data paket: someone is cheating.
*/
if (LogLevel > 5)
"ERROR: DNS RDLENGTH=%d > data len=%d",
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
switch (type)
{
case T_NS:
case T_CNAME:
case T_PTR:
sizeof(host));
if (status < 0)
{
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
break;
case T_MX:
case T_AFSDB:
sizeof(host));
if (status < 0)
{
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
host, l);
break;
case T_SRV:
sizeof(host));
if (status < 0)
{
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
host, l);
break;
case T_TXT:
/*
** The TXT record contains the length as
** leading byte, hence the value is restricted
** to 255, which is less than the maximum value
** of RDLENGTH (size). Nevertheless, txtlen
** must be less than size because the latter
** specifies the length of the entire TXT
** record.
*/
txtlen = *p;
{
if (LogLevel > 5)
"ERROR: DNS TXT record size=%d <= text len=%d",
dns_free_data(r);
return NULL;
}
{
dns_free_data(r);
return NULL;
}
txtlen + 1);
break;
default:
{
dns_free_data(r);
return NULL;
}
break;
}
p += size;
}
return r;
}
/*
** DNS_LOOKUP_INT -- perform dns map lookup (internal helper routine)
**
** Parameters:
** domain -- name to lookup
** rr_class -- resource record class
** rr_type -- resource record type
** retrans -- retransmission timeout
** retry -- number of retries
**
** Returns:
** result of lookup if succeeded.
** NULL otherwise.
*/
const char *domain;
int rr_class;
int rr_type;
int retry;
{
int len;
unsigned long old_options = 0;
int save_retry = 0;
DNS_REPLY_T *r = NULL;
unsigned char *reply;
#ifndef IP_MAXPACKET
#endif
{
}
if (retrans > 0)
{
}
if (retry > 0)
{
}
errno = 0;
SM_SET_H_ERRNO(0);
{
if (len >= IP_MAXPACKET)
{
sm_dprintf("dns_lookup: domain=%s, length=%d, default_size=%d, max=%d, status=response too long\n",
}
else
{
sm_dprintf("dns_lookup: domain=%s, length=%d, default_size=%d, max=%d, status=response longer than default size, resizing\n",
else
}
}
{
sm_dprintf("dns_lookup(%s, %d, %s) --> %d\n",
}
{
}
if (retrans > 0)
if (retry > 0)
return r;
}
# if 0
const char *domain;
const char *type_name;
int retry;
{
int type;
if (type == -1)
{
sm_dprintf("dns_lookup: unknown resource type: `%s'\n",
return NULL;
}
}
# endif /* 0 */
# endif /* NAMED_BIND */
#endif /* DNSMAP */