diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-07-19 07:55:27 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-07-19 07:56:21 +0200 |
commit | 640bbdf71c6f10ac26252ac67a22902e26657bd8 (patch) | |
tree | 227d6260dda188bdc22f2d9a6b52acd77c3d68b7 /resolv | |
parent | 13e1f86706e463de4429f7e88f47c6ff65cd845e (diff) | |
download | glibc-640bbdf71c6f10ac26252ac67a22902e26657bd8.tar glibc-640bbdf71c6f10ac26252ac67a22902e26657bd8.tar.gz glibc-640bbdf71c6f10ac26252ac67a22902e26657bd8.tar.bz2 glibc-640bbdf71c6f10ac26252ac67a22902e26657bd8.zip |
resolv: Move dn_expand to its own file and into libc
And reformat to GNU style.
This switches back to the dn_expand name for the ABI symbol and turns
__dn_expand into a compatibility symbol. With the improved namespace
management in current glibc, it is no longer necessary to use a
private namespace symbol. To avoid old code binding to a
GLIBC_PRIVATE symbol by accident, use __libc_dn_expand for the
internal symbol name.
The symbols dn_expand, __dnexpand were moved using
scripts/move-symbol-to-libc.py, followed by an adjustment to make
dn_expand the only GLIBC_2.34 symbol.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'resolv')
-rw-r--r-- | resolv/Makefile | 1 | ||||
-rw-r--r-- | resolv/Versions | 6 | ||||
-rw-r--r-- | resolv/compat-gethnamaddr.c | 13 | ||||
-rw-r--r-- | resolv/dn_expand.c | 112 | ||||
-rw-r--r-- | resolv/ns_parse.c | 4 | ||||
-rw-r--r-- | resolv/ns_print.c | 2 | ||||
-rw-r--r-- | resolv/nss_dns/dns-canon.c | 4 | ||||
-rw-r--r-- | resolv/res_comp.c | 27 | ||||
-rw-r--r-- | resolv/res_debug.c | 4 | ||||
-rw-r--r-- | resolv/res_send.c | 4 | ||||
-rw-r--r-- | resolv/resolv.h | 1 |
11 files changed, 134 insertions, 44 deletions
diff --git a/resolv/Makefile b/resolv/Makefile index 64600ab845..3e7de81fb5 100644 --- a/resolv/Makefile +++ b/resolv/Makefile @@ -28,6 +28,7 @@ headers := resolv.h bits/types/res_state.h \ sys/bitypes.h routines := \ + dn_expand \ herror \ inet_addr \ inet_ntop \ diff --git a/resolv/Versions b/resolv/Versions index a676be2e42..4a9203042f 100644 --- a/resolv/Versions +++ b/resolv/Versions @@ -3,6 +3,7 @@ libc { __h_errno_location; __res_randomid; _res; + dn_expand; h_errlist; h_nerr; herror; @@ -10,6 +11,7 @@ libc { res_init; } GLIBC_2.2 { + __dn_expand; __res_init; __res_nclose; __res_ninit; @@ -40,6 +42,7 @@ libc { gai_suspend; getaddrinfo_a; %endif + dn_expand; ns_name_compress; ns_name_ntop; ns_name_pack; @@ -55,6 +58,7 @@ libc { __h_errno; __inet_aton_exact; __inet_pton_length; + __libc_dn_expand; __ns_name_compress; __ns_name_ntop; __ns_name_pack; @@ -120,7 +124,6 @@ libresolv { _res_opcodes; _res_resultcodes; _sethtent; - dn_expand; inet_net_ntop; inet_net_pton; inet_neta; @@ -135,7 +138,6 @@ libresolv { res_send_setrhook; } GLIBC_2.2 { - __dn_expand; __res_hostalias; __res_mkquery; __res_nmkquery; diff --git a/resolv/compat-gethnamaddr.c b/resolv/compat-gethnamaddr.c index 0e24dcbbcc..1c630fcb3d 100644 --- a/resolv/compat-gethnamaddr.c +++ b/resolv/compat-gethnamaddr.c @@ -179,7 +179,7 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype) __set_h_errno (NO_RECOVERY); return (NULL); } - n = dn_expand(answer->buf, eom, cp, bp, buflen); + n = __libc_dn_expand (answer->buf, eom, cp, bp, buflen); if ((n < 0) || !(*name_ok)(bp)) { __set_h_errno (NO_RECOVERY); return (NULL); @@ -210,7 +210,7 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype) haveanswer = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, buflen); + n = __libc_dn_expand (answer->buf, eom, cp, bp, buflen); if ((n < 0) || !(*name_ok)(bp)) { had_error++; continue; @@ -233,7 +233,8 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype) if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { if (ap >= &host_aliases[MAXALIASES-1]) continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + n = __libc_dn_expand (answer->buf, eom, cp, + tbuf, sizeof tbuf); if ((n < 0) || !(*name_ok)(tbuf)) { had_error++; continue; @@ -265,7 +266,8 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype) continue; } if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + n = __libc_dn_expand (answer->buf, eom, cp, + tbuf, sizeof tbuf); if (n < 0 || !res_dnok(tbuf)) { had_error++; continue; @@ -302,7 +304,8 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype) cp += n; continue; /* XXX - had_error++ ? */ } - n = dn_expand(answer->buf, eom, cp, bp, buflen); + n = __libc_dn_expand (answer->buf, eom, cp, + bp, buflen); if ((n < 0) || !res_hnok(bp)) { had_error++; break; diff --git a/resolv/dn_expand.c b/resolv/dn_expand.c new file mode 100644 index 0000000000..0235b34eb4 --- /dev/null +++ b/resolv/dn_expand.c @@ -0,0 +1,112 @@ +/* Expanding a compressed DNS domain name to its presentation form. + Copyright (C) 1995-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +/* + * Copyright (c) 1985, 1993 + * The Regents of the University of California. 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 + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + */ + +/* + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * 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, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION 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) 1996-1999 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. + */ + +#include <arpa/nameser.h> +#include <resolv.h> +#include <shlib-compat.h> + +/* Expand compressed domain name COMP_DN to full domain name. MSG is + a pointer to the beginning of the message, EOMORIG points to the + first location after the message, EXP_DN is a pointer to a buffer + of size LENGTH for the result. Returns size of compressed name or + -1 if there was an error. */ +int +___dn_expand (const unsigned char *msg, const unsigned char *eom, + const unsigned char *src, char *dst, int dstsiz) +{ + int n = __ns_name_uncompress (msg, eom, src, dst, (size_t) dstsiz); + if (n > 0 && dst[0] == '.') + dst[0] = '\0'; + return n; +} +versioned_symbol (libc, ___dn_expand, dn_expand, GLIBC_2_34); +versioned_symbol (libc, ___dn_expand, __libc_dn_expand, GLIBC_PRIVATE); +libc_hidden_ver (___dn_expand, __libc_dn_expand); + +#if OTHER_SHLIB_COMPAT (libresolv, GLIBC_2_0, GLIBC_2_2) +compat_symbol (libresolv, ___dn_expand, dn_expand, GLIBC_2_0); +#endif +#if OTHER_SHLIB_COMPAT (libresolv, GLIBC_2_2, GLIBC_2_34) +compat_symbol (libresolv, ___dn_expand, __dn_expand, GLIBC_2_2); +#endif diff --git a/resolv/ns_parse.c b/resolv/ns_parse.c index 863b20a9f7..8ae72e7e1f 100644 --- a/resolv/ns_parse.c +++ b/resolv/ns_parse.c @@ -154,8 +154,8 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { } /* Do the parse. */ - b = dn_expand(handle->_msg, handle->_eom, - handle->_msg_ptr, rr->name, NS_MAXDNAME); + b = __libc_dn_expand (handle->_msg, handle->_eom, + handle->_msg_ptr, rr->name, NS_MAXDNAME); if (b < 0) return (-1); handle->_msg_ptr += b; diff --git a/resolv/ns_print.c b/resolv/ns_print.c index d61f5044b1..9a9602d74c 100644 --- a/resolv/ns_print.c +++ b/resolv/ns_print.c @@ -693,7 +693,7 @@ addname(const u_char *msg, size_t msglen, char *save_buf = *buf; int n; - n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen); + n = __libc_dn_expand (msg, msg + msglen, *pp, *buf, *buflen); if (n < 0) goto enospc; /*%< Guess. */ newlen = prune_origin(*buf, origin); diff --git a/resolv/nss_dns/dns-canon.c b/resolv/nss_dns/dns-canon.c index 1cdc9a86c9..b7340d7b9e 100644 --- a/resolv/nss_dns/dns-canon.c +++ b/resolv/nss_dns/dns-canon.c @@ -125,8 +125,8 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen, if (type == qtypes[i]) { /* We found the record. */ - s = __dn_expand (ansp.buf->buf, endptr, namestart, - buffer, buflen); + s = __libc_dn_expand (ansp.buf->buf, endptr, namestart, + buffer, buflen); if (s < 0) { if (errno != EMSGSIZE) diff --git a/resolv/res_comp.c b/resolv/res_comp.c index c53788643a..42e73a1f00 100644 --- a/resolv/res_comp.c +++ b/resolv/res_comp.c @@ -93,25 +93,6 @@ #include <unistd.h> /* - * Expand compressed domain name 'comp_dn' to full domain name. - * 'msg' is a pointer to the beginning of the message, - * 'eomorig' points to the first location after the message, - * 'exp_dn' is a pointer to a buffer of size 'length' for the result. - * Return size of compressed name or -1 if there was an error. - */ -int -dn_expand(const u_char *msg, const u_char *eom, const u_char *src, - char *dst, int dstsiz) -{ - int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz); - - if (n > 0 && dst[0] == '.') - dst[0] = '\0'; - return (n); -} -libresolv_hidden_def (dn_expand) - -/* * Pack domain name 'exp_dn' in presentation form into 'comp_dn'. * Return the size of the compressed name or -1. * 'length' is the size of the array pointed to by 'comp_dn'. @@ -268,11 +249,3 @@ void __putshort(uint16_t src, u_char *dst) { ns_put16(src, dst); } libresolv_hidden_def (__putshort) uint32_t _getlong(const u_char *src) { return (ns_get32(src)); } uint16_t _getshort(const u_char *src) { return (ns_get16(src)); } - - -#include <shlib-compat.h> - -#if SHLIB_COMPAT(libresolv, GLIBC_2_0, GLIBC_2_2) -# undef dn_expand -weak_alias (__dn_expand, dn_expand); -#endif diff --git a/resolv/res_debug.c b/resolv/res_debug.c index 844269cffa..030df0aa90 100644 --- a/resolv/res_debug.c +++ b/resolv/res_debug.c @@ -335,7 +335,7 @@ p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) { char name[MAXDNAME]; int n; - if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) + if ((n = __libc_dn_expand (msg, msg + len, cp, name, sizeof name)) < 0) return (NULL); if (name[0] == '\0') putc('.', file); @@ -359,7 +359,7 @@ p_fqnname (const u_char *cp, const u_char *msg, int msglen, char *name, { int n, newlen; - if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) + if ((n = __libc_dn_expand (msg, cp + msglen, cp, name, namelen)) < 0) return (NULL); newlen = strlen(name); if (newlen == 0 || name[newlen - 1] != '.') { diff --git a/resolv/res_send.c b/resolv/res_send.c index a70f3dec05..b6139c7d62 100644 --- a/resolv/res_send.c +++ b/resolv/res_send.c @@ -268,7 +268,7 @@ res_nameinquery(const char *name, int type, int class, char tname[MAXDNAME+1]; int n, ttype, tclass; - n = dn_expand(buf, eom, cp, tname, sizeof tname); + n = __libc_dn_expand (buf, eom, cp, tname, sizeof tname); if (n < 0) return (-1); cp += n; @@ -381,7 +381,7 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1, char tname[MAXDNAME+1]; int n, ttype, tclass; - n = dn_expand(buf1, eom1, cp, tname, sizeof tname); + n = __libc_dn_expand (buf1, eom1, cp, tname, sizeof tname); if (n < 0) return (-1); cp += n; diff --git a/resolv/resolv.h b/resolv/resolv.h index 02a35173e9..7232d81a3b 100644 --- a/resolv/resolv.h +++ b/resolv/resolv.h @@ -212,7 +212,6 @@ __END_DECLS #define b64_pton __b64_pton #define dn_comp __dn_comp #define dn_count_labels __dn_count_labels -#define dn_expand __dn_expand #define dn_skipname __dn_skipname #define fp_resstat __fp_resstat #define loc_aton __loc_aton |