diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2008-05-22 21:30:28 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2008-05-22 21:30:28 +0000 |
commit | 3c77dcff9ebf51910b01ca770f7a8ffef52b617c (patch) | |
tree | 8424a3ed0b00dfcb1d31428f57817fadf658ba80 /newlib/libc/sys/linux/net/hesiod.c | |
parent | 8a179967e670032fb2decf0ebcdd0059f9d139d8 (diff) | |
download | cygnal-3c77dcff9ebf51910b01ca770f7a8ffef52b617c.tar.gz cygnal-3c77dcff9ebf51910b01ca770f7a8ffef52b617c.tar.bz2 cygnal-3c77dcff9ebf51910b01ca770f7a8ffef52b617c.zip |
2008-05-22 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/reent.h: Add _h_errno field.
* libc/sys/linux/libc-symbols.h: Add default stubs for new libc macros
now used in net directory.
* libc/sys/linux/bits/libc-lock.h: Always define _IO_MTSAFE_IO.
* libc/sys/linux/include/hesiod.h: Add needed macros for new code
in net directory.
* libc/sys/linux/include/netdb.h: Ditto.
* libc/sys/linux/include/resolv.h: Ditto.
* libc/sys/linux/include/stdint.h: Ditto.
* libc/sys/linux/include/arpa/nameser.h: Ditto.
* libc/sys/linux/include/net/ethernet.h: Ditto.
* libc/sys/linux/include/net/if_ppp.h: Ditto.
* libc/sys/linux/include/netinet/if_ether.h: Ditto.
* libc/sys/linux/machine/i386/get_clockfreq.c: Remove static memmem.
* libc/sys/linux/machine/i386/include/endian.h: Protect macros with
flags to avoid duplicate definition.
* libc/sys/linux/machine/i386/include/param.h: Ditto.
* libc/sys/linux/net/Makefile.am: Modified to account for removed and
added files.
* libc/sys/linux/net/Makefile.in: Regenerated.
* libc/sys/linux/net/base64.c: Replaced with glibc version of code.
* libc/sys/linux/net/getaddrinfo.c: Ditto.
* libc/sys/linux/net/getnameinfo.c: Ditto.
* libc/sys/linux/net/getproto.c: Ditto.
* libc/sys/linux/net/getservent.c: Ditto.
* libc/sys/linux/net/inet_netof.c: Ditto.
* libc/sys/linux/net/inet_lnaof.c: Ditto.
* libc/sys/linux/net/ns_name.c: Ditto.
* libc/sys/linux/net/ns_netint.c: Ditto.
* libc/sys/linux/net/inet_ntoa.c: Ditto.
* libc/sys/linux/net/ns_parse.c: Ditto.
* libc/sys/linux/net/ns_print.c: Ditto.
* libc/sys/linux/net/ns_ttl.c: Ditto.
* libc/sys/linux/net/nsap_addr.c: Ditto.
* libc/sys/linux/net/rcmd.c: Ditto.
* libc/sys/linux/net/res_comp.c: Ditto.
* libc/sys/linux/net/res_data.c: Ditto.
* libc/sys/linux/net/res_debug.c: Ditto.
* libc/sys/linux/net/res_init.c: Ditto.
* libc/sys/linux/net/res_mkquery.c: Ditto.
* libc/sys/linux/net/res_query.c: Ditto.
* libc/sys/linux/net/res_send.c: Ditto.
* libc/sys/linux/net/send.c: Ditto.
* libc/sys/linux/stdlib/collate.c: Ditto.
* libc/sys/linux/sys/ioctl.h: Ditto.
* libc/sys/linux/sys/socket.h: Ditto.
* libc/sys/linux/sys/unistd.h: Ditto.
* libc/sys/linux/iconv/iconvconfig.c: Removed either because no longer
used or because licensing includes advertising clause that cannot be
ignored.
* libc/sys/linux/iconv/strtab.c: Ditto.
* libc/sys/linux/include/libc_private.h: Ditto.
* libc/sys/linux/include/nsswitch.h: Ditto.
* libc/sys/linux/include/net/if_atm.h: Ditto.
* libc/sys/linux/include/net/if_media.h: Ditto.
* libc/sys/linux/include/net/if_pppvar.h: Ditto.
* libc/sys/linux/include/netinet/if_atm.h: Ditto.
* libc/sys/linux/include/netinet/ip_flow.h: Ditto.
* libc/sys/linux/intl/locale.alias: Ditto.
* libc/sys/linux/net/addr2ascii.3: Ditto.
* libc/sys/linux/net/bindresvport.c: Ditto.
* libc/sys/linux/net/byteorder.3: Ditto.
* libc/sys/linux/net/res_config.h: Ditto.
* libc/sys/linux/net/ether_addr.c: Ditto.
* libc/sys/linux/net/ethers.3: Ditto.
* libc/sys/linux/net/getaddrinfo.3: Ditto.
* libc/sys/linux/net/gethostbydns.c: Ditto.
* libc/sys/linux/net/gethostbyht.c: Ditto.
* libc/sys/linux/net/gethostbyname.3: Ditto.
* libc/sys/linux/net/gethostbynis.c: Ditto.
* libc/sys/linux/net/gethostnamadr.c: Ditto.
* libc/sys/linux/net/getifaddrs.3: Ditto.
* libc/sys/linux/net/getifaddrs.c: Ditto.
* libc/sys/linux/net/getipnodebyname.3: Ditto.
* libc/sys/linux/net/getnameinfo.3: Ditto.
* libc/sys/linux/net/getnetbydns.c: Ditto.
* libc/sys/linux/net/getnetbyht.c: Ditto.
* libc/sys/linux/net/getnetbynis.c: Ditto.
* libc/sys/linux/net/getnetent.3: Ditto.
* libc/sys/linux/net/getnetnamadr.c: Ditto.
* libc/sys/linux/net/getprotoent.3: Ditto.
* libc/sys/linux/net/getprotoent.c: Ditto.
* libc/sys/linux/net/getprotoname.c: Ditto.
* libc/sys/linux/net/getservbyname.c: Ditto.
* libc/sys/linux/net/getservbyport.c: Ditto.
* libc/sys/linux/net/getservent.3: Ditto.
* libc/sys/linux/net/herror.c: Ditto.
* libc/sys/linux/net/hesiod.3: Ditto.
* libc/sys/linux/net/hesiod.c: Ditto.
* libc/sys/linux/net/if_indextoname.3: Ditto.
* libc/sys/linux/net/inet.3: Ditto.
* libc/sys/linux/net/inet6_option_space.3: Ditto.
* libc/sys/linux/net/inet6_rthdr_space.3: Ditto.
* libc/sys/linux/net/inet_makeaddr.c: Ditto.
* libc/sys/linux/net/inet_net.3: Ditto.
* libc/sys/linux/net/inet_network.c: Ditto.
* libc/sys/linux/net/innetgr-stub.c: Ditto.
* libc/sys/linux/net/ip6opt.c: Ditto.
* libc/sys/linux/net/iso_addr.3: Ditto.
* libc/sys/linux/net/iso_addr.c: Ditto.
* libc/sys/linux/net/linkaddr.3: Ditto.
* libc/sys/linux/net/linkaddr.c: Ditto.
* libc/sys/linux/net/map_v4v6.c: Ditto.
* libc/sys/linux/net/name6.c: Ditto.
* libc/sys/linux/net/namespace.h: Ditto.
* libc/sys/linux/net/ns.3: Ditto.
* libc/sys/linux/net/ns_addr.c: Ditto.
* libc/sys/linux/net/ns_ntoa.c: Ditto.
* libc/sys/linux/net/nsdispatch.3: Ditto.
* libc/sys/linux/net/nsdispatch.c: Ditto.
* libc/sys/linux/net/nslexer.c: Ditto.
* libc/sys/linux/net/nslexer.l: Ditto.
* libc/sys/linux/net/nsparser.c: Ditto.
* libc/sys/linux/net/nsparser.h: Ditto.
* libc/sys/linux/net/nsparser.y: Ditto.
* libc/sys/linux/net/rcmd.3: Ditto.
* libc/sys/linux/net/rcmdsh.3: Ditto.
* libc/sys/linux/net/res_mkupdate.c: Ditto.
* libc/sys/linux/net/res_update.c: Ditto.
* libc/sys/linux/net/resolver.3: Ditto.
* libc/sys/linux/net/rthdr.c: Ditto.
* libc/sys/linux/net/vars.c: Ditto.
* libc/sys/linux/shlib-compat.h: New file.
* libc/sys/linux/machine/i386/atomic.h: Ditto.
* libc/sys/linux/net/XXX-lookup.c: Ditto.
* libc/sys/linux/net/alias-lookup.c: Ditto.
* libc/sys/linux/net/res_libc.c: Ditto.
* libc/sys/linux/net/aliases.h: Ditto.
* libc/sys/linux/net/check_pf.c: Ditto.
* libc/sys/linux/net/databases.def: Ditto.
* libc/sys/linux/net/digits_dots.c: Ditto.
* libc/sys/linux/net/ether_aton.c: Ditto.
* libc/sys/linux/net/ether_aton_r.c: Ditto.
* libc/sys/linux/net/ether_hton.c: Ditto.
* libc/sys/linux/net/ether_line.c: Ditto.
* libc/sys/linux/net/ether_ntoa.c: Ditto.
* libc/sys/linux/net/ether_ntoa_r.c: Ditto.
* libc/sys/linux/net/ether_ntoh.c: Ditto.
* libc/sys/linux/net/etherent.h: Ditto.
* libc/sys/linux/net/ethers-lookup.c: Ditto.
* libc/sys/linux/net/function.def: Ditto.
* libc/sys/linux/net/getXXbyYY.c: Ditto.
* libc/sys/linux/net/getXXbyYY_r.c: Ditto.
* libc/sys/linux/net/getXXent.c: Ditto.
* libc/sys/linux/net/getXXent_r.c: Ditto.
* libc/sys/linux/net/getaliasent.c: Ditto.
* libc/sys/linux/net/getaliasent_r.c: Ditto.
* libc/sys/linux/net/getaliasname.c: Ditto.
* libc/sys/linux/net/getaliasname_r.c: Ditto.
* libc/sys/linux/net/gethstbyad.c: Ditto.
* libc/sys/linux/net/gethstbyad_r.c: Ditto.
* libc/sys/linux/net/gethstbynm.c: Ditto.
* libc/sys/linux/net/gethstbynm2.c: Ditto.
* libc/sys/linux/net/gethstbynm2_r.c: Ditto.
* libc/sys/linux/net/gethstbynm_r.c: Ditto.
* libc/sys/linux/net/gethstent.c: Ditto.
* libc/sys/linux/net/gethstent_r.c: Ditto.
* libc/sys/linux/net/getnetbyad.c: Ditto.
* libc/sys/linux/net/getnetbyad_r.c: Ditto.
* libc/sys/linux/net/getnetbynm.c: Ditto.
* libc/sys/linux/net/getnetbynm_r.c: Ditto.
* libc/sys/linux/net/getnetent.c: Ditto.
* libc/sys/linux/net/getnetent_r.c: Ditto.
* libc/sys/linux/net/getnetgrent.c: Ditto.
* libc/sys/linux/net/getnetgrent_r.c: Ditto.
* libc/sys/linux/net/getnssent.c: Ditto.
* libc/sys/linux/net/getnssent_r.c: Ditto.
* libc/sys/linux/net/getproto_r.c: Ditto.
* libc/sys/linux/net/getprtent.c: Ditto.
* libc/sys/linux/net/getprtent_r.c: Ditto.
* libc/sys/linux/net/getprtname.c: Ditto.
* libc/sys/linux/net/getprtname_r.c: Ditto.
* libc/sys/linux/net/getrpcbyname.c: Ditto.
* libc/sys/linux/net/getrpcbyname_r.c: Ditto.
* libc/sys/linux/net/getrpcbynumber.c: Ditto.
* libc/sys/linux/net/getrpcbynumber_r.c: Ditto.
* libc/sys/linux/net/getrpcent.c: Ditto.
* libc/sys/linux/net/getrpcent_r.c: Ditto.
* libc/sys/linux/net/getservent_r.c: Ditto.
* libc/sys/linux/net/getsrvbynm.c: Ditto.
* libc/sys/linux/net/getsrvbynm_r.c: Ditto.
* libc/sys/linux/net/getsrvbypt.c: Ditto.
* libc/sys/linux/net/getsrvbypt_r.c: Ditto.
* libc/sys/linux/net/grp-lookup.c: Ditto.
* libc/sys/linux/net/herrno.c: Ditto.
* libc/sys/linux/net/hosts-lookup.c: Ditto.
* libc/sys/linux/net/ifaddrs.h: Ditto.
* libc/sys/linux/net/ifreq.c: Ditto.
* libc/sys/linux/net/ifreq.h: Ditto.
* libc/sys/linux/net/in6_addr.c: Ditto.
* libc/sys/linux/net/inet6_option.c: Ditto.
* libc/sys/linux/net/inet_mkadr.c: Ditto.
* libc/sys/linux/net/inet_net.c: Ditto.
* libc/sys/linux/net/key-lookup.c: Ditto.
* libc/sys/linux/net/local.h: Ditto.
* libc/sys/linux/net/netgroup.h: Ditto.
* libc/sys/linux/net/netgrp-lookup.c: Ditto.
* libc/sys/linux/net/network-lookup.c: Ditto.
* libc/sys/linux/net/not-cancel.h: Ditto.
* libc/sys/linux/net/ns_samedomain.c: Ditto.
* libc/sys/linux/net/nscd-types.h: Ditto.
* libc/sys/linux/net/nss.h: Ditto.
* libc/sys/linux/net/nsswitch.c: Ditto.
* libc/sys/linux/net/nsswitch.h: Ditto.
* libc/sys/linux/net/opensock.c: Ditto.
* libc/sys/linux/net/proto-lookup.c: Ditto.
* libc/sys/linux/net/pwd-lookup.c: Ditto.
* libc/sys/linux/net/res_debug.h: Ditto.
* libc/sys/linux/net/res_hconf.c: Ditto.
* libc/sys/linux/net/res_hconf.h: Ditto.
* libc/sys/linux/net/rexec.c: Ditto.
* libc/sys/linux/net/rpc-lookup.c: Ditto.
* libc/sys/linux/net/ruserpass.c: Ditto.
* libc/sys/linux/net/service-lookup.c: Ditto.
* libc/sys/linux/net/spwd-lookup.c: Ditto.
* libc/sys/linux/net/nscd/nscd-client.h: Ditto.
* libc/sys/linux/net/nscd/nscd_proto.h: Ditto.
Diffstat (limited to 'newlib/libc/sys/linux/net/hesiod.c')
-rw-r--r-- | newlib/libc/sys/linux/net/hesiod.c | 600 |
1 files changed, 0 insertions, 600 deletions
diff --git a/newlib/libc/sys/linux/net/hesiod.c b/newlib/libc/sys/linux/net/hesiod.c deleted file mode 100644 index 909c09440..000000000 --- a/newlib/libc/sys/linux/net/hesiod.c +++ /dev/null @@ -1,600 +0,0 @@ -/* $NetBSD: hesiod.c,v 1.9 1999/02/11 06:16:38 simonb Exp $ */ - -/* 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. - */ - -/* Copyright 1996 by the Massachusetts Institute of Technology. - * - * Permission to use, copy, modify, and distribute this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting - * documentation, and that the name of M.I.T. not be used in - * advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. - * M.I.T. makes no representations about the suitability of - * this software for any purpose. It is provided "as is" - * without express or implied warranty. - */ - -/* This file is part of the hesiod library. It implements the core - * portion of the hesiod resolver. - * - * This file is loosely based on an interim version of hesiod.c from - * the BIND IRS library, which was in turn based on an earlier version - * of this file. Extensive changes have been made on each step of the - * path. - * - * This implementation is not truly thread-safe at the moment because - * it uses res_send() and accesses _res. - */ - -#include <sys/cdefs.h> - -#if 0 -static char *orig_rcsid = "$NetBSD: hesiod.c,v 1.9 1999/02/11 06:16:38 simonb Exp $"; -#endif -#include <sys/cdefs.h> -#include <sys/types.h> -#include <machine/endian.h> - -#include <sys/types.h> -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/nameser.h> - -#include <ctype.h> -#include <errno.h> -#include <hesiod.h> -#include <resolv.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -struct hesiod_p { - char *lhs; /* normally ".ns" */ - char *rhs; /* AKA the default hesiod domain */ - int classes[2]; /* The class search order. */ -}; - -#define MAX_HESRESP 1024 - -static int read_config_file(struct hesiod_p *, const char *); -static char **get_txt_records(int, const char *); -static int init_context(void); -static void translate_errors(void); - - -/* - * hesiod_init -- - * initialize a hesiod_p. - */ -int -hesiod_init(context) - void **context; -{ - struct hesiod_p *ctx; - const char *p, *configname; - - ctx = malloc(sizeof(struct hesiod_p)); - if (ctx) { - *context = ctx; - if (!issetugid()) - configname = getenv("HESIOD_CONFIG"); - else - configname = NULL; - if (!configname) - configname = _PATH_HESIOD_CONF; - if (read_config_file(ctx, configname) >= 0) { - /* - * The default rhs can be overridden by an - * environment variable. - */ - if (!issetugid()) - p = getenv("HES_DOMAIN"); - else - p = NULL; - if (p) { - if (ctx->rhs) - free(ctx->rhs); - ctx->rhs = malloc(strlen(p) + 2); - if (ctx->rhs) { - *ctx->rhs = '.'; - strcpy(ctx->rhs + 1, - (*p == '.') ? p + 1 : p); - return 0; - } else - errno = ENOMEM; - } else - return 0; - } - } else - errno = ENOMEM; - - if (ctx->lhs) - free(ctx->lhs); - if (ctx->rhs) - free(ctx->rhs); - if (ctx) - free(ctx); - return -1; -} - -/* - * hesiod_end -- - * Deallocates the hesiod_p. - */ -void -hesiod_end(context) - void *context; -{ - struct hesiod_p *ctx = (struct hesiod_p *) context; - - free(ctx->rhs); - if (ctx->lhs) - free(ctx->lhs); - free(ctx); -} - -/* - * hesiod_to_bind -- - * takes a hesiod (name, type) and returns a DNS - * name which is to be resolved. - */ -char * -hesiod_to_bind(void *context, const char *name, const char *type) -{ - struct hesiod_p *ctx = (struct hesiod_p *) context; - char bindname[MAXDNAME], *p, *ret, **rhs_list = NULL; - const char *rhs; - int len; - size_t bindnamelen; - - if (strlcpy(bindname, name, sizeof(bindname)) >= sizeof(bindname)) { - errno = EMSGSIZE; - return NULL; - } - - /* - * Find the right right hand side to use, possibly - * truncating bindname. - */ - p = strchr(bindname, '@'); - if (p) { - *p++ = 0; - if (strchr(p, '.')) - rhs = name + (p - bindname); - else { - rhs_list = hesiod_resolve(context, p, "rhs-extension"); - if (rhs_list) - rhs = *rhs_list; - else { - errno = ENOENT; - return NULL; - } - } - } else - rhs = ctx->rhs; - - /* See if we have enough room. */ - len = strlen(bindname) + 1 + strlen(type); - if (ctx->lhs) - len += strlen(ctx->lhs) + ((ctx->lhs[0] != '.') ? 1 : 0); - len += strlen(rhs) + ((rhs[0] != '.') ? 1 : 0); - if (len > sizeof(bindname) - 1) { - if (rhs_list) - hesiod_free_list(context, rhs_list); - errno = EMSGSIZE; - return NULL; - } - /* Put together the rest of the domain. */ - strcat(bindname, "."); - strcat(bindname, type); - /* Only append lhs if it isn't empty. */ - if (ctx->lhs && ctx->lhs[0] != '\0' ) { - if (ctx->lhs[0] != '.') - strcat(bindname, "."); - strcat(bindname, ctx->lhs); - } - if (rhs[0] != '.') - strcat(bindname, "."); - strcat(bindname, rhs); - - /* rhs_list is no longer needed, since we're done with rhs. */ - if (rhs_list) - hesiod_free_list(context, rhs_list); - - /* Make a copy of the result and return it to the caller. */ - bindnamelen = strlen (bindname) + 1; - ret = malloc (bindnamelen); - if (!ret) - errno = ENOMEM; - else - memcpy (ret, bindname, bindnamelen); - return ret; -} - -/* - * hesiod_resolve -- - * Given a hesiod name and type, return an array of strings returned - * by the resolver. - */ -char ** -hesiod_resolve(context, name, type) - void *context; - const char *name; - const char *type; -{ - struct hesiod_p *ctx = (struct hesiod_p *) context; - char *bindname, **retvec; - - bindname = hesiod_to_bind(context, name, type); - if (!bindname) - return NULL; - - retvec = get_txt_records(ctx->classes[0], bindname); - if (retvec == NULL && errno == ENOENT && ctx->classes[1]) - retvec = get_txt_records(ctx->classes[1], bindname); - - free(bindname); - return retvec; -} - -/*ARGSUSED*/ -void -hesiod_free_list(context, list) - void *context; - char **list; -{ - char **p; - - if (list == NULL) - return; - for (p = list; *p; p++) - free(*p); - free(list); -} - - -/* read_config_file -- - * Parse the /etc/hesiod.conf file. Returns 0 on success, - * -1 on failure. On failure, it might leave values in ctx->lhs - * or ctx->rhs which need to be freed by the caller. - */ -static int -read_config_file(ctx, filename) - struct hesiod_p *ctx; - const char *filename; -{ - char *key, *data, *p, **which; - char buf[MAXDNAME + 7]; - int n; - FILE *fp; - - /* Set default query classes. */ - ctx->classes[0] = C_IN; - ctx->classes[1] = C_HS; - - /* Try to open the configuration file. */ - fp = fopen(filename, "r"); - if (!fp) { - size_t len; - /* Use compiled in default domain names. */ - len = strlen (DEF_LHS) + 1; - ctx->lhs = malloc (len); - if (ctx->lhs) { - memcpy (ctx->lhs, DEF_LHS, len); - len = strlen (DEF_RHS) + 1; - ctx->rhs = malloc (len); - if (ctx->rhs) - memcpy (ctx->rhs, DEF_RHS, len); - } - if (ctx->lhs && ctx->rhs) - return 0; - else { - errno = ENOMEM; - return -1; - } - } - ctx->lhs = NULL; - ctx->rhs = NULL; - while (fgets(buf, sizeof(buf), fp) != NULL) { - p = buf; - if (*p == '#' || *p == '\n' || *p == '\r') - continue; - while (*p == ' ' || *p == '\t') - p++; - key = p; - while (*p != ' ' && *p != '\t' && *p != '=') - p++; - *p++ = 0; - - while (isspace(*p) || *p == '=') - p++; - data = p; - while (!isspace(*p)) - p++; - *p = 0; - - if (strcasecmp(key, "lhs") == 0 || - strcasecmp(key, "rhs") == 0) { - size_t len; - which = (strcasecmp(key, "lhs") == 0) - ? &ctx->lhs : &ctx->rhs; - len = strlen (data) + 1; - *which = malloc (len); - if (!*which) { - errno = ENOMEM; - return -1; - } - else - memcpy (*which, data, len); - } else { - if (strcasecmp(key, "classes") == 0) { - n = 0; - while (*data && n < 2) { - p = data; - while (*p && *p != ',') - p++; - if (*p) - *p++ = 0; - if (strcasecmp(data, "IN") == 0) - ctx->classes[n++] = C_IN; - else - if (strcasecmp(data, "HS") == 0) - ctx->classes[n++] = - C_HS; - data = p; - } - while (n < 2) - ctx->classes[n++] = 0; - } - } - } - fclose(fp); - - if (!ctx->rhs || ctx->classes[0] == 0 || - ctx->classes[0] == ctx->classes[1]) { - errno = ENOEXEC; - return -1; - } - return 0; -} - -/* - * get_txt_records -- - * Given a DNS class and a DNS name, do a lookup for TXT records, and - * return a list of them. - */ -static char ** -get_txt_records(qclass, name) - int qclass; - const char *name; -{ - HEADER *hp; - unsigned char qbuf[PACKETSZ], abuf[MAX_HESRESP], *p, *eom, *eor; - char *dst, **list; - int ancount, qdcount, i, j, n, skip, type, class, len; - - /* Make sure the resolver is initialized. */ - if ((_res.options & RES_INIT) == 0 && res_init() == -1) - return NULL; - - /* Construct the query. */ - n = res_mkquery(QUERY, name, qclass, T_TXT, NULL, 0, - NULL, qbuf, PACKETSZ); - if (n < 0) - return NULL; - - /* Send the query. */ - n = res_send(qbuf, n, abuf, MAX_HESRESP); - if (n < 0) { - errno = ECONNREFUSED; - return NULL; - } - /* Parse the header of the result. */ - hp = (HEADER *) (void *) abuf; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - p = abuf + sizeof(HEADER); - eom = abuf + n; - - /* - * Skip questions, trying to get to the answer section - * which follows. - */ - for (i = 0; i < qdcount; i++) { - skip = dn_skipname(p, eom); - if (skip < 0 || p + skip + QFIXEDSZ > eom) { - errno = EMSGSIZE; - return NULL; - } - p += skip + QFIXEDSZ; - } - - /* Allocate space for the text record answers. */ - list = malloc((ancount + 1) * sizeof(char *)); - if (!list) { - errno = ENOMEM; - return NULL; - } - /* Parse the answers. */ - j = 0; - for (i = 0; i < ancount; i++) { - /* Parse the header of this answer. */ - skip = dn_skipname(p, eom); - if (skip < 0 || p + skip + 10 > eom) - break; - type = p[skip + 0] << 8 | p[skip + 1]; - class = p[skip + 2] << 8 | p[skip + 3]; - len = p[skip + 8] << 8 | p[skip + 9]; - p += skip + 10; - if (p + len > eom) { - errno = EMSGSIZE; - break; - } - /* Skip entries of the wrong class and type. */ - if (class != qclass || type != T_TXT) { - p += len; - continue; - } - /* Allocate space for this answer. */ - list[j] = malloc((size_t)len); - if (!list[j]) { - errno = ENOMEM; - break; - } - dst = list[j++]; - - /* Copy answer data into the allocated area. */ - eor = p + len; - while (p < eor) { - n = (unsigned char) *p++; - if (p + n > eor) { - errno = EMSGSIZE; - break; - } - memcpy(dst, p, (size_t)n); - p += n; - dst += n; - } - if (p < eor) { - errno = EMSGSIZE; - break; - } - *dst = 0; - } - - /* - * If we didn't terminate the loop normally, something - * went wrong. - */ - if (i < ancount) { - for (i = 0; i < j; i++) - free(list[i]); - free(list); - return NULL; - } - if (j == 0) { - errno = ENOENT; - free(list); - return NULL; - } - list[j] = NULL; - return list; -} - - /* - * COMPATIBILITY FUNCTIONS - */ - -static int inited = 0; -static void *context; -static int errval = HES_ER_UNINIT; - -int -hes_init() -{ - init_context(); - return errval; -} - -char * -hes_to_bind(name, type) - const char *name; - const char *type; -{ - static char *bindname; - if (init_context() < 0) - return NULL; - if (bindname) - free(bindname); - bindname = hesiod_to_bind(context, name, type); - if (!bindname) - translate_errors(); - return bindname; -} - -char ** -hes_resolve(name, type) - const char *name; - const char *type; -{ - static char **list; - - if (init_context() < 0) - return NULL; - - /* - * In the old Hesiod interface, the caller was responsible for - * freeing the returned strings but not the vector of strings itself. - */ - if (list) - free(list); - - list = hesiod_resolve(context, name, type); - if (!list) - translate_errors(); - return list; -} - -int -hes_error() -{ - return errval; -} - -void -hes_free(hp) - char **hp; -{ - hesiod_free_list(context, hp); -} - -static int -init_context() -{ - if (!inited) { - inited = 1; - if (hesiod_init(&context) < 0) { - errval = HES_ER_CONFIG; - return -1; - } - errval = HES_ER_OK; - } - return 0; -} - -static void -translate_errors() -{ - switch (errno) { - case ENOENT: - errval = HES_ER_NOTFOUND; - break; - case ECONNREFUSED: - case EMSGSIZE: - errval = HES_ER_NET; - break; - case ENOMEM: - default: - /* Not a good match, but the best we can do. */ - errval = HES_ER_CONFIG; - break; - } -} |