├── COPYING ├── src ├── tls │ ├── validator │ │ ├── val_nsec3.h │ │ └── val_secalgo.h │ └── pubkey-pinning-internal.h ├── util │ ├── auxiliary │ │ ├── util │ │ │ ├── data │ │ │ │ └── packed_rrset.h │ │ │ ├── storage │ │ │ │ ├── lookup3.h │ │ │ │ └── lruhash.h │ │ │ ├── fptr_wlist.h │ │ │ └── log.h │ │ ├── log.h │ │ ├── sldns │ │ │ ├── keyraw.h │ │ │ ├── rrdef.h │ │ │ └── sbuffer.h │ │ └── fptr_wlist.h │ ├── lookup3.h │ ├── val_secalgo.h │ ├── rbtree.h │ ├── locks.h │ ├── orig-headers │ │ └── lookup3.h │ └── lruhash.h ├── extension │ ├── libev.symbols │ ├── libuv.symbols │ ├── libevent.symbols │ ├── default_eventloop.h │ ├── select_eventloop.h │ └── poll_eventloop.h ├── gnutls │ ├── keyraw-internal.c │ ├── keyraw-internal.h │ ├── pubkey-pinning-internal.c │ └── tls-internal.h ├── compat │ ├── explicit_bzero.c │ ├── getentropy_win.c │ ├── strlcpy.c │ ├── mkstemp.c │ ├── arc4random_uniform.c │ ├── gettimeofday.c │ └── arc4_lock.c ├── test │ ├── scratchpad.template.c │ ├── check_getdns_libevent.h │ ├── check_getdns_transport.h │ ├── check_getdns_context_set_timeout.h │ ├── check_getdns_eventloop.h │ ├── check_getdns_selectloop.c │ ├── testmessages.h │ ├── check_getdns_libuv.c │ ├── check_getdns_libevent.c │ ├── check_getdns_libev.c │ ├── testmessages.c │ └── testscript.sh ├── gldns │ ├── import.sh │ ├── compare.sh │ ├── keyraw.h │ └── keyraw.c ├── server.h ├── stub.h ├── version.c.in ├── pubkey-pinning.h ├── const-info.h ├── convert.h ├── openssl │ ├── tls-internal.h │ └── pubkey-pinning-internal.c ├── getdns │ ├── getdns_ext_libev.h │ ├── getdns_ext_libuv.h │ └── getdns_ext_libevent.h ├── dict.h ├── ub_loop.h ├── list.h ├── anchor.h ├── dnssec.h ├── general.h └── mdns.h ├── NEWS ├── cmake ├── tests │ ├── test___func__.c │ ├── test_uv_cb.c │ └── test_poll.c ├── include │ └── getdns_shared_version.rc.in └── modules │ ├── TargetSharedLibraryExports.cmake │ ├── TargetSharedLibraryVersion.cmake │ ├── FindLibev.cmake │ ├── FindLibidn2.cmake │ ├── FindLibuv.cmake │ ├── FindLibevent2.cmake │ ├── FindGnuTLS.cmake │ ├── FindCheck.cmake │ ├── FindLibunbound.cmake │ └── FindNettle.cmake ├── AUTHORS ├── getdns.pc.in ├── getdns_ext_event.pc.in ├── LICENSE ├── spec └── example │ ├── getdns_core_only.h │ ├── getdns_libevent.h │ ├── example-synchronous.c │ └── example-simple-answers.c └── doc ├── manpgaltnames ├── getdns_pretty_print_dict.3.in ├── getdns_display_ip_address.3.in ├── getdns_root_trust_anchor.3.in ├── getdns_context_set_context_update_callback.3.in ├── getdns_cancel_callback.3.in ├── getdns_validate_dnssec.3.in ├── getdns_dict_set.3.in ├── getdns_convert.3.in └── getdns_list.3.in /COPYING: -------------------------------------------------------------------------------- 1 | LICENSE -------------------------------------------------------------------------------- /src/tls/validator/val_nsec3.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | this page intentionally left blank 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/util/data/packed_rrset.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/log.h: -------------------------------------------------------------------------------- 1 | #include "util/log.h" 2 | -------------------------------------------------------------------------------- /src/extension/libev.symbols: -------------------------------------------------------------------------------- 1 | getdns_extension_set_libev_loop 2 | -------------------------------------------------------------------------------- /src/extension/libuv.symbols: -------------------------------------------------------------------------------- 1 | getdns_extension_set_libuv_loop 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/sldns/keyraw.h: -------------------------------------------------------------------------------- 1 | #include "gldns/keyraw.h" 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/sldns/rrdef.h: -------------------------------------------------------------------------------- 1 | #include "gldns/rrdef.h" 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/fptr_wlist.h: -------------------------------------------------------------------------------- 1 | #include "util/fptr_wlist.h" 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/sldns/sbuffer.h: -------------------------------------------------------------------------------- 1 | #include "gldns/gbuffer.h" 2 | -------------------------------------------------------------------------------- /src/extension/libevent.symbols: -------------------------------------------------------------------------------- 1 | getdns_extension_set_libevent_base 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/util/storage/lookup3.h: -------------------------------------------------------------------------------- 1 | #include "util/lookup3.h" 2 | -------------------------------------------------------------------------------- /src/util/auxiliary/util/storage/lruhash.h: -------------------------------------------------------------------------------- 1 | #include "util/lruhash.h" 2 | -------------------------------------------------------------------------------- /cmake/tests/test___func__.c: -------------------------------------------------------------------------------- 1 | int main (int ac, char *av[]) 2 | { 3 | char *s = __func__; 4 | } 5 | -------------------------------------------------------------------------------- /cmake/tests/test_uv_cb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void test_cb(uv_timer_t *handle) 4 | { 5 | (void) handle; 6 | } 7 | 8 | int main(int ac, char *av[]) 9 | { 10 | uv_timer_cb cb = test_cb; 11 | (*cb)(0); 12 | } 13 | -------------------------------------------------------------------------------- /cmake/tests/test_poll.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_SYS_POLL_H 2 | #include 3 | #else 4 | #include 5 | #endif 6 | 7 | int main (int ac, char *av[]) 8 | { 9 | int rc; 10 | rc = poll((struct pollfd *)(0), 0, 0); 11 | } 12 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Craig Despeaux 2 | Neel Goyal 3 | Allison Mankin 4 | Melinda Shore 5 | Willem Toorop 6 | W.C.A. Wijngaards 7 | Glen Wiley 8 | -------------------------------------------------------------------------------- /getdns.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=${prefix} 3 | libdir=@libdir_for_pc_file@ 4 | includedir=@includedir_for_pc_file@ 5 | 6 | Name: getdns 7 | Version: @GETDNS_VERSION@ 8 | Description: A modern asynchronous DNS library 9 | 10 | Libs: -L${libdir} -lgetdns 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /getdns_ext_event.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: getdns_ext_event 7 | Version: @GETDNS_VERSION@ 8 | Description: A modern asynchronous DNS library 9 | 10 | Libs: -L${libdir} -lgetdns_ext_event 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /src/gnutls/keyraw-internal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * keyraw.c - raw key operations and conversions - OpenSSL version 3 | * 4 | * (c) NLnet Labs, 2004-2008 5 | * 6 | * See the file LICENSE for the license 7 | */ 8 | /** 9 | * \file 10 | * Implementation of raw DNSKEY functions (work on wire rdata). 11 | */ 12 | 13 | #include "config.h" 14 | #include "gldns/keyraw.h" 15 | #include "gldns/rrdef.h" 16 | -------------------------------------------------------------------------------- /src/compat/explicit_bzero.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: explicit_bzero.c,v 1.3 2014/06/21 02:34:26 matthew Exp $ */ 2 | /* 3 | * Public domain. 4 | * Written by Matthew Dempsky. 5 | */ 6 | #include "config.h" 7 | #include 8 | 9 | void 10 | explicit_bzero(void *buf, size_t len) 11 | { 12 | #ifdef GETDNS_ON_WINDOWS 13 | SecureZeroMemory(buf, len); 14 | #else 15 | memset(buf, 0, len); 16 | #endif 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scratchpad.template.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | getdns_return_t r; 8 | getdns_context *ctx = NULL; 9 | 10 | if ((r = getdns_context_create(&ctx, 1))) 11 | fprintf(stderr, "Could not create context"); 12 | 13 | if (ctx) 14 | getdns_context_destroy(ctx); 15 | 16 | if (r) { 17 | fprintf(stderr, ": %s\n", getdns_get_errorstr_by_id(r)); 18 | exit(EXIT_FAILURE); 19 | } 20 | exit(EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /src/gldns/import.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Meant to be run from this directory 4 | 5 | if [ -d gldns ] 6 | then 7 | # Import synchronised files from comparison directory 8 | for f in gldns/*.[ch] 9 | do 10 | sed -e 's/sldns_/gldns_/g' \ 11 | -e 's/LDNS_/GLDNS_/g' \ 12 | -e 's/include "sldns/include "gldns/g' \ 13 | -e 's///g' \ 14 | -e 's/sbuffer\.h/gbuffer.h/g' $f > ${f#gldns/} 15 | done 16 | mv sbuffer.h gbuffer.h 17 | mv sbuffer.c gbuffer.c 18 | else 19 | echo Run compare first 20 | fi 21 | -------------------------------------------------------------------------------- /src/gnutls/keyraw-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * keyraw.h -- raw key and signature access and conversion - OpenSSL 3 | * 4 | * Copyright (c) 2005-2008, NLnet Labs. All rights reserved. 5 | * 6 | * See LICENSE for the license. 7 | * 8 | */ 9 | 10 | /** 11 | * \file 12 | * 13 | * raw key and signature access and conversion 14 | * 15 | * Since those functions heavily rely op cryptographic operations, 16 | * this module is dependent on openssl. 17 | * 18 | */ 19 | 20 | #ifndef GLDNS_KEYRAW_INTERNAL_H 21 | #define GLDNS_KEYRAW_INTERNAL_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* GLDNS_KEYRAW_INTERNAL_H */ 32 | -------------------------------------------------------------------------------- /cmake/include/getdns_shared_version.rc.in: -------------------------------------------------------------------------------- 1 | 1 VERSIONINFO 2 | FILEVERSION @version_current@,@version_revision@,@version_age@,0 3 | PRODUCTVERSION @version_current@,@version_revision@,0,0 4 | FILEOS 4 5 | FILETYPE 2 6 | FILESUBTYPE 0 7 | BEGIN 8 | BLOCK "StringFileInfo" 9 | BEGIN 10 | BLOCK "040904e4" 11 | BEGIN 12 | VALUE "CompanyName", "getdns project\0" 13 | VALUE "ProductName", "getdns\0" 14 | VALUE "FileVersion", "@version_current@.@version_revision@\0" 15 | VALUE "ProductVersion", "@version_current@.@version_revision@\0" 16 | VALUE "LegalCopyright", "NLnet Labs, Sinodun, No Mountain Software. New BSD licence.\0" 17 | END 18 | END 19 | END 20 | -------------------------------------------------------------------------------- /src/gldns/compare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Meant to be run from this directory 4 | rm -fr gldns 5 | mkdir gldns 6 | svn co https://github.com/NLnetLabs/unbound/trunk/sldns/ 7 | mv gbuffer.h sbuffer.h 8 | mv gbuffer.c sbuffer.c 9 | for f in sldns/*.[ch] 10 | do 11 | #sed -e 's/sldns_/gldns_/g' -e 's/LDNS_/GLDNS_/g' -e 's/include "ldns/include "gldns/g' -e 's//"gldns\/rrdef.h"/g' -e 's/sbuffer\.h/gbuffer.h/g' ${f#sldns/} > gldns/${f#sldns/} 12 | sed -e 's/gldns_/sldns_/g' \ 13 | -e 's/GLDNS_/LDNS_/g' \ 14 | -e 's///g' \ 15 | -e 's/include "gldns/include "sldns/g' \ 16 | -e 's/gbuffer\.h/sbuffer.h/g' \ 17 | ${f#sldns/} > gldns/${f#sldns/} 18 | done 19 | mv sbuffer.h gbuffer.h 20 | mv sbuffer.c gbuffer.c 21 | 22 | -------------------------------------------------------------------------------- /src/gldns/keyraw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * keyraw.h -- raw key and signature access and conversion 3 | * 4 | * Copyright (c) 2005-2008, NLnet Labs. All rights reserved. 5 | * 6 | * See LICENSE for the license. 7 | * 8 | */ 9 | 10 | /** 11 | * \file 12 | * 13 | * raw key and signature access and conversion 14 | * 15 | * Since those functions heavily rely op cryptographic operations, 16 | * this module is dependent on openssl. 17 | * 18 | */ 19 | 20 | #ifndef GLDNS_KEYRAW_H 21 | #define GLDNS_KEYRAW_H 22 | 23 | #include "keyraw-internal.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * get the length of the keydata in bits 31 | * \param[in] keydata the raw key data 32 | * \param[in] len the length of the keydata 33 | * \param[in] alg the cryptographic algorithm this is a key for 34 | * \return the keysize in bits, or 0 on error 35 | */ 36 | size_t gldns_rr_dnskey_key_size_raw(const unsigned char *keydata, 37 | const size_t len, int alg); 38 | 39 | /** 40 | * Calculates keytag of DNSSEC key, operates on wireformat rdata. 41 | * \param[in] key the key as uncompressed wireformat rdata. 42 | * \param[in] keysize length of key data. 43 | * \return the keytag 44 | */ 45 | uint16_t gldns_calc_keytag_raw(const uint8_t* key, size_t keysize); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* GLDNS_KEYRAW_H */ 52 | -------------------------------------------------------------------------------- /cmake/modules/TargetSharedLibraryExports.cmake: -------------------------------------------------------------------------------- 1 | # Export only named entry points from shared library. 2 | function(target_shared_library_exports lib libname symbols) 3 | if (WIN32) 4 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${libname}.def" "LIBRARY ${libname}\n EXPORTS\n") 5 | foreach (symbol IN LISTS symbols) 6 | file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${libname}.def" " ${symbol}\n") 7 | endforeach () 8 | target_sources(${lib} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${libname}.def") 9 | elseif (APPLE) 10 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${libname}.syms" "") 11 | foreach (symbol IN LISTS symbols) 12 | file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${libname}.syms" "_${symbol}\n") 13 | endforeach () 14 | target_sources(${lib} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${libname}.syms") 15 | target_link_libraries(${lib} PRIVATE "-exported_symbols_list ${libname}.syms") 16 | elseif (UNIX) 17 | # Assume GNU ld. 18 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${libname}.ver" "{ global:\n") 19 | foreach (symbol IN LISTS symbols) 20 | file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${libname}.ver" " ${symbol};\n") 21 | endforeach () 22 | file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${libname}.ver" "local:\n *;\n};\n") 23 | target_link_libraries(${lib} PRIVATE "-Wl,--version-script=${libname}.ver") 24 | else () 25 | message(WARNING "Unknown platform, ${lib} exports not set.") 26 | endif () 27 | endfunction () 28 | -------------------------------------------------------------------------------- /cmake/modules/TargetSharedLibraryVersion.cmake: -------------------------------------------------------------------------------- 1 | # Add version to given shared library linkage. 2 | function(target_shared_library_version lib version_current version_revision version_age) 3 | if (APPLE) 4 | # Follow libtool. Add one to major version, as version 0 doesn't work. 5 | # But tag dynlib name with current-age. 6 | math(EXPR major_version "${version_current}+1") 7 | math(EXPR dynlib_version "${version_current}-${version_age}") 8 | set_target_properties(${lib} PROPERTIES VERSION "${dynlib_version}") 9 | target_link_libraries(${lib} PRIVATE "-compatibility_version ${major_version}") 10 | target_link_libraries(${lib} PRIVATE "-current_version ${major_version}.${version_revision}") 11 | elseif (UNIX OR MINGW OR MSYS OR CYGWIN) 12 | # Assume GNU ld, and again follow libtool. Major version is current-age. 13 | math(EXPR compat_version "${version_current}-${version_age}") 14 | set_target_properties(${lib} PROPERTIES VERSION "${compat_version}.${version_age}.${version_revision}" SOVERSION "${compat_version}") 15 | elseif (WIN32) 16 | set(rc_template "${CMAKE_CURRENT_SOURCE_DIR}/cmake/include/${lib}_version.rc.in") 17 | if (EXISTS ${rc_template}) 18 | configure_file(${rc_template} ${lib}.rc @ONLY) 19 | target_sources(${lib} PRIVATE ${lib}.rc) 20 | endif () 21 | target_link_libraries(${lib} PRIVATE "-VERSION:${version_current}.${version_revision}") 22 | else () 23 | message(WARNING "Unknown platform, ${lib} will not be versioned.") 24 | endif () 25 | endfunction () 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Verisign, Inc., NLnet Labs 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the names of the copyright holders nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /spec/example/getdns_core_only.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the names of the copyright holders nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include 28 | -------------------------------------------------------------------------------- /cmake/modules/FindLibev.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindLibev 3 | --------- 4 | 5 | Find the Libev library. 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Libev::Libev`` 13 | The Libev library, if found. 14 | 15 | Result variables 16 | ^^^^^^^^^^^^^^^^ 17 | 18 | This module will set the following variables in your project: 19 | 20 | ``Libev_FOUND`` 21 | If false, do not try to use Libev. 22 | ``LIBEV_INCLUDE_DIR`` 23 | where to find libev headers. 24 | ``LIBEV_LIBRARIES`` 25 | the libraries needed to use Libev. 26 | ``LIBEV_VERSION`` 27 | the version of the Libev library found 28 | 29 | #]=======================================================================] 30 | 31 | find_path(LIBEV_INCLUDE_DIR ev.h 32 | HINTS 33 | "${LIBEV_DIR}" 34 | "${LIBEV_DIR}/include" 35 | ) 36 | 37 | find_library(LIBEV_LIBRARY NAMES ev libev 38 | HINTS 39 | "${LIBEV_DIR}" 40 | "${LIBEV_DIR}/lib" 41 | ) 42 | 43 | set(LIBEV_LIBRARIES "") 44 | 45 | if (LIBEV_INCLUDE_DIR AND LIBEV_LIBRARY) 46 | if (NOT TARGET Libev::Libev) 47 | add_library(Libev::Libev UNKNOWN IMPORTED) 48 | set_target_properties(Libev::Libev PROPERTIES 49 | INTERFACE_INCLUDE_DIRECTORIES "${LIBEV_INCLUDE_DIR}" 50 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 51 | IMPORTED_LOCATION "${LIBEV_LIBRARY}" 52 | ) 53 | endif () 54 | endif() 55 | 56 | list(APPEND LIBEV_LIBRARIES "${LIBEV_LIBRARY}") 57 | 58 | include(FindPackageHandleStandardArgs) 59 | find_package_handle_standard_args(Libev 60 | REQUIRED_VARS LIBEV_LIBRARIES LIBEV_INCLUDE_DIR 61 | ) 62 | 63 | mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARIES LIBEV_LIBRARY) 64 | -------------------------------------------------------------------------------- /src/compat/getentropy_win.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD$ */ 2 | 3 | /* 4 | * Copyright (c) 2014, Theo de Raadt 5 | * Copyright (c) 2014, Bob Beck 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | int getentropy(void *buf, size_t len); 28 | 29 | /* 30 | * On Windows, CryptGenRandom is supposed to be a well-seeded 31 | * cryptographically strong random number generator. 32 | */ 33 | int 34 | getentropy(void *buf, size_t len) 35 | { 36 | HCRYPTPROV provider; 37 | 38 | if (len > 256) { 39 | errno = EIO; 40 | return -1; 41 | } 42 | 43 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, 44 | CRYPT_VERIFYCONTEXT) == 0) 45 | goto fail; 46 | if (CryptGenRandom(provider, len, buf) == 0) { 47 | CryptReleaseContext(provider, 0); 48 | goto fail; 49 | } 50 | CryptReleaseContext(provider, 0); 51 | return (0); 52 | 53 | fail: 54 | errno = EIO; 55 | return (-1); 56 | } 57 | -------------------------------------------------------------------------------- /src/test/check_getdns_libevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the names of the copyright holders nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifdef HAVE_EVENT2_EVENT_H 28 | #include 29 | #else 30 | # ifndef u_char 31 | # define u_char unsigned char 32 | # endif 33 | #include 34 | #endif 35 | -------------------------------------------------------------------------------- /src/compat/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* from openssh 4.3p2 compat/strlcpy.c */ 2 | /* 3 | * Copyright (c) 1998 Todd C. Miller 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* OPENBSD ORIGINAL: lib/libc/string/strlcpy.c */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | /* 26 | * Copy src to string dst of size siz. At most siz-1 characters 27 | * will be copied. Always NUL terminates (unless siz == 0). 28 | * Returns strlen(src); if retval >= siz, truncation occurred. 29 | */ 30 | size_t 31 | strlcpy(char *dst, const char *src, size_t siz) 32 | { 33 | char *d = dst; 34 | const char *s = src; 35 | size_t n = siz; 36 | 37 | /* Copy as many bytes as will fit */ 38 | if (n != 0 && --n != 0) { 39 | do { 40 | if ((*d++ = *s++) == 0) 41 | break; 42 | } while (--n != 0); 43 | } 44 | 45 | /* Not enough room in dst, add NUL and traverse rest of src */ 46 | if (n == 0) { 47 | if (siz != 0) 48 | *d = '\0'; /* NUL-terminate dst */ 49 | while (*s++) 50 | ; 51 | } 52 | 53 | return(s - src - 1); /* count does not include NUL */ 54 | } 55 | -------------------------------------------------------------------------------- /doc/manpgaltnames: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # generate list of alternate names for the specified man page 3 | # used to generate alternative man pages 4 | # 5 | # Copyright (c) 2013, Verisign, Inc., NLnet Labs 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions are met: 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # * Neither the names of the copyright holders nor the 16 | # names of its contributors may be used to endorse or promote products 17 | # derived from this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | # DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 23 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | [ ! -f $1 ] && exit 0 30 | 31 | main=${1%.[0-9]} 32 | sect=${1#*.} 33 | sed -n '/.SH NAME/,/.SH LIBRARY/p' $1 |grep "^.B " | sed 's/.B //g' | sed 's/ *$//g' | sed 's/,//g' | grep -v "^$main\$" | sed "s/\$/.$sect/" 34 | -------------------------------------------------------------------------------- /src/server.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file server.h 3 | * @brief Functions for serving requests 4 | * 5 | * getdns_context_set_listen_addresses() and getdns_reply() are implemented 6 | * here. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | #ifndef _GETDNS_SERVER_H_ 36 | #define _GETDNS_SERVER_H_ 37 | 38 | struct listen_set; 39 | 40 | #endif /* _GETDNS_SERVER_H_ */ 41 | -------------------------------------------------------------------------------- /src/util/auxiliary/util/fptr_wlist.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief dummy prototypes for function pointer whitelisting 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef UTIL_FPTR_WLIST_H 35 | #define UTIL_FPTR_WLIST_H 36 | 37 | #define fptr_ok(x) 38 | #define fptr_whitelist_event(x) 39 | #define fptr_whitelist_rbtree_cmp(x) 40 | 41 | #endif /* UTIL_FPTR_WLIST_H */ 42 | 43 | -------------------------------------------------------------------------------- /src/tls/pubkey-pinning-internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief internal functions for dealing with pubkey pinsets 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2015 ACLU 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef PUBKEY_PINNING_INTERNAL_H_ 35 | #define PUBKEY_PINNING_INTERNAL_H_ 36 | 37 | #include 38 | 39 | getdns_return_t _getdns_decode_base64(const char* str, uint8_t* res, size_t res_size); 40 | 41 | #endif 42 | /* pubkey-pinning-internal.h */ 43 | -------------------------------------------------------------------------------- /src/util/lookup3.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file lookup3.h 4 | * /brief Alternative symbol names for unbound's lookup3.h 5 | * 6 | */ 7 | /* 8 | * Copyright (c) 2017, NLnet Labs, the getdns team 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #ifndef LOOKUP3_H_SYMBOLS 34 | #define LOOKUP3_H_SYMBOLS 35 | 36 | #define hashword _getdns_hashword 37 | #define hashlittle _getdns_hashlittle 38 | #define hash_set_raninit _getdns_hash_set_raninit 39 | 40 | #include "util/orig-headers/lookup3.h" 41 | #endif 42 | -------------------------------------------------------------------------------- /src/compat/mkstemp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mkstemp.c 3 | * @brief Implementation of mkstemp for Windows. 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2019 Sinodun 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the names of the copyright holders nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | int mkstemp(char *template) 39 | { 40 | if (_mktemp_s(template, strlen(template) + 1) != 0) 41 | return -1; 42 | return open(template, _O_CREAT | _O_EXCL | _O_RDWR, _S_IWRITE | _S_IREAD); 43 | } 44 | -------------------------------------------------------------------------------- /src/test/check_getdns_transport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the names of the copyright holders nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef _check_getdns_transport_h_ 28 | #define _check_getdns_transport_h_ 29 | 30 | #ifdef __clang__ 31 | #pragma clang diagnostic push 32 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 33 | #endif 34 | #include 35 | #ifdef __clang__ 36 | #pragma clang diagnostic pop 37 | #endif 38 | 39 | Suite * 40 | getdns_transport_suite (void); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/stub.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief functions for stub resolving 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef STUB_H_ 35 | #define STUB_H_ 36 | 37 | #include "getdns/getdns.h" 38 | #include "types-internal.h" 39 | 40 | getdns_return_t _getdns_submit_stub_request( 41 | getdns_network_req *netreq, uint64_t *now_ms); 42 | 43 | void _getdns_cancel_stub_request(getdns_network_req *netreq); 44 | 45 | #endif 46 | 47 | /* stub.h */ 48 | -------------------------------------------------------------------------------- /src/compat/arc4random_uniform.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: arc4random_uniform.c,v 1.1 2014/07/12 13:24:54 deraadt Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2008, Damien Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "config.h" 20 | #include 21 | #include 22 | 23 | /* 24 | * Calculate a uniformly distributed random number less than upper_bound 25 | * avoiding "modulo bias". 26 | * 27 | * Uniformity is achieved by generating new random numbers until the one 28 | * returned is outside the range [0, 2**32 % upper_bound). This 29 | * guarantees the selected random number will be inside 30 | * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) 31 | * after reduction modulo upper_bound. 32 | */ 33 | uint32_t 34 | arc4random_uniform(uint32_t upper_bound) 35 | { 36 | uint32_t r, min; 37 | 38 | if (upper_bound < 2) 39 | return 0; 40 | 41 | /* 2**32 % x == (2**32 - x) % x */ 42 | min = -upper_bound % upper_bound; 43 | 44 | /* 45 | * This could theoretically loop forever but each retry has 46 | * p > 0.5 (worst case, usually far better) of selecting a 47 | * number inside the range we need, so it should rarely need 48 | * to re-roll. 49 | */ 50 | for (;;) { 51 | r = arc4random(); 52 | if (r >= min) 53 | break; 54 | } 55 | 56 | return r % upper_bound; 57 | } 58 | -------------------------------------------------------------------------------- /src/test/check_getdns_context_set_timeout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the names of the copyright holders nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef _check_getdns_context_set_timeout_h_ 28 | #define _check_getdns_context_set_timeout_h_ 29 | 30 | #ifdef __clang__ 31 | #pragma clang diagnostic push 32 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 33 | #endif 34 | #include 35 | #ifdef __clang__ 36 | #pragma clang diagnostic pop 37 | #endif 38 | 39 | Suite * 40 | getdns_context_set_timeout_suite (void); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /spec/example/getdns_libevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the names of the copyright holders nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "config.h" 28 | #include 29 | #include 30 | #ifdef HAVE_EVENT2_EVENT_H 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | #ifndef HAVE_EVENT_BASE_FREE 37 | #define event_base_free(x) /* nop */ 38 | #endif 39 | #ifndef HAVE_EVENT_BASE_NEW 40 | #define event_base_new event_init 41 | #endif 42 | 43 | #ifndef HAVE_U_CHAR 44 | typedef unsigned char u_char; 45 | #endif 46 | -------------------------------------------------------------------------------- /src/version.c.in: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief function for returning version info about the library and the API 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | 36 | const char *getdns_get_version(void) 37 | { 38 | return "@GETDNS_VERSION@"; 39 | } 40 | 41 | uint32_t getdns_get_version_number(void) 42 | { 43 | return @GETDNS_NUMERIC_VERSION@; 44 | } 45 | 46 | const char *getdns_get_api_version(void) 47 | { 48 | return "@API_VERSION@"; 49 | } 50 | 51 | uint32_t getdns_get_api_version_number(void) 52 | { 53 | return @API_NUMERIC_VERSION@; 54 | } 55 | 56 | /* version.c */ 57 | -------------------------------------------------------------------------------- /src/test/check_getdns_eventloop.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Testing interfaces to getdns 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | /* this is used to prevent header conflicts with libevent and libev */ 37 | #ifndef _check_getdns_eventloop_h_ 38 | #define _check_getdns_eventloop_h_ 39 | 40 | #include "config.h" 41 | #include "getdns/getdns.h" 42 | 43 | void run_event_loop_impl(struct getdns_context* context, void* eventloop); 44 | void* create_eventloop_impl(struct getdns_context* context); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/test/check_getdns_selectloop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Testing interfaces to getdns 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "check_getdns_eventloop.h" 37 | #include "getdns/getdns_extra.h" 38 | 39 | void run_event_loop_impl(struct getdns_context* context, void* eventloop) { 40 | (void)eventloop; /* unused parameter */ 41 | getdns_context_run(context); 42 | } 43 | 44 | void* create_eventloop_impl(struct getdns_context* context) { 45 | (void)context; /* unused parameter */ 46 | return NULL; 47 | } 48 | -------------------------------------------------------------------------------- /spec/example/example-synchronous.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | getdns_return_t r; /* Holder for all function returns */ 8 | getdns_context *context = NULL; 9 | getdns_dict *response = NULL; 10 | getdns_dict *extensions = NULL; 11 | getdns_bindata *address_data; 12 | char *first = NULL, *second = NULL; 13 | 14 | /* Create the DNS context for this call */ 15 | if ((r = getdns_context_create(&context, 1))) 16 | fprintf(stderr, "Trying to create the context failed"); 17 | 18 | else if (!(extensions = getdns_dict_create())) 19 | fprintf(stderr, "Could not create extensions dict.\n"); 20 | 21 | else if ((r = getdns_dict_set_int(extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE))) 22 | fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed"); 23 | 24 | else if ((r = getdns_general_sync(context, "example.com", GETDNS_RRTYPE_A, extensions, &response))) 25 | fprintf(stderr, "Error scheduling synchronous request"); 26 | 27 | else if ((r = getdns_dict_get_bindata(response, "/just_address_answers/0/address_data", &address_data))) 28 | fprintf(stderr, "Could not get first address"); 29 | 30 | else if (!(first = getdns_display_ip_address(address_data))) 31 | fprintf(stderr, "Could not convert first address to string\n"); 32 | 33 | else if ((r = getdns_dict_get_bindata(response, "/just_address_answers/1/address_data", &address_data))) 34 | fprintf(stderr, "Could not get second address"); 35 | 36 | else if (!(second = getdns_display_ip_address(address_data))) 37 | fprintf(stderr, "Could not convert second address to string\n"); 38 | 39 | if (first) { 40 | printf("The address is %s\n", first); 41 | free(first); 42 | } 43 | if (second) { 44 | printf("The address is %s\n", second); 45 | free(second); 46 | } 47 | /* Clean up */ 48 | if (response) 49 | getdns_dict_destroy(response); 50 | 51 | if (extensions) 52 | getdns_dict_destroy(extensions); 53 | 54 | if (context) 55 | getdns_context_destroy(context); 56 | 57 | if (r) { 58 | assert( r != GETDNS_RETURN_GOOD ); 59 | 60 | fprintf(stderr, ": %d\n", r); 61 | exit(EXIT_FAILURE); 62 | } 63 | /* Assuming we get here, leave gracefully */ 64 | exit(EXIT_SUCCESS); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/extension/default_eventloop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * \file default_eventloop.h 3 | * @brief Build in default eventloop extension that uses either poll or select. 4 | * 5 | */ 6 | /* 7 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the names of the copyright holders nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef DEFAULT_EVENTLOOP_H_ 33 | #define DEFAULT_EVENTLOOP_H_ 34 | #include "config.h" 35 | #ifdef USE_POLL_DEFAULT_EVENTLOOP 36 | #include "extension/poll_eventloop.h" 37 | #define _getdns_default_eventloop _getdns_poll_eventloop 38 | #define _getdns_default_eventloop_init _getdns_poll_eventloop_init 39 | #else 40 | #include "extension/select_eventloop.h" 41 | #define _getdns_default_eventloop _getdns_select_eventloop 42 | #define _getdns_default_eventloop_init _getdns_select_eventloop_init 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /src/compat/gettimeofday.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Christian Huitema 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * Numerous places in the code make reference to the Unix/Linux 19 | * "gettimeofday()" function, which is not available in the standard 20 | * windows libraries. This code provides a compatible implementation. 21 | */ 22 | #include "config.h" 23 | 24 | #ifndef HAVE_GETTIMEOFDAY 25 | 26 | int gettimeofday(struct timeval* tv, void* tz) 27 | { 28 | FILETIME ft; 29 | uint64_t now = 0; 30 | 31 | /* 32 | * The GetSystemTimeAsFileTime API returns the number 33 | * of 100-nanosecond intervals since January 1, 1601 (UTC), 34 | * in FILETIME format. 35 | */ 36 | GetSystemTimeAsFileTime(&ft); 37 | 38 | /* 39 | * Convert to plain 64 bit format, without making 40 | * assumptions about the FILETIME structure alignment. 41 | */ 42 | now |= ft.dwHighDateTime; 43 | now <<= 32; 44 | now |= ft.dwLowDateTime; 45 | /* 46 | * Convert units from 100ns to 1us 47 | */ 48 | now /= 10; 49 | /* 50 | * Account for microseconds elapsed between 1601 and 1970. 51 | */ 52 | now -= 11644473600000000ULL; 53 | 54 | if (tv != NULL) 55 | { 56 | uint64_t sec = now / 1000000; 57 | uint64_t usec = now % 1000000; 58 | 59 | tv->tv_sec = (long)sec; 60 | tv->tv_usec = (long)usec; 61 | } 62 | 63 | if (tz != NULL) 64 | { 65 | /* 66 | * TODO: implement a timezone retrieval function. 67 | * Not urgent, since the GetDNS code always set this parameter to NULL. 68 | */ 69 | return -1; 70 | } 71 | 72 | return 0; 73 | } 74 | #endif /* HAVE_GETTIMEOFDAY */ 75 | -------------------------------------------------------------------------------- /src/gnutls/pubkey-pinning-internal.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief functions for dealing with pubkey pinsets 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2015 ACLU 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "context.h" 35 | #include 36 | 37 | #include "types-internal.h" 38 | 39 | #include "pubkey-pinning.h" 40 | 41 | /** 42 | ** Interfaces from pubkey-pinning.h 43 | **/ 44 | 45 | getdns_return_t _getdns_decode_base64(const char* str, uint8_t* res, size_t res_size) 46 | { 47 | struct base64_decode_ctx ctx; 48 | uint8_t* lim = res + res_size; 49 | 50 | base64_decode_init(&ctx); 51 | 52 | for(; *str != '\0' && res < lim; ++str) { 53 | int r = base64_decode_single(&ctx, res, *str); 54 | if (r == -1 ) 55 | return GETDNS_RETURN_GENERIC_ERROR; 56 | res += r; 57 | } 58 | return (res == lim) ? GETDNS_RETURN_GOOD : GETDNS_RETURN_GENERIC_ERROR; 59 | } 60 | -------------------------------------------------------------------------------- /src/pubkey-pinning.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief functions for dealing with pubkey pinsets 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2015 ACLU 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef PUBKEY_PINNING_H_ 35 | #define PUBKEY_PINNING_H_ 36 | 37 | /* getdns_pubkey_pin_create_from_string() is implemented in pubkey-pinning.c */ 38 | #include "getdns/getdns_extra.h" 39 | 40 | #include "tls.h" 41 | 42 | /* create and populate a pinset linked list from a getdns_list pinset */ 43 | getdns_return_t 44 | _getdns_get_pubkey_pinset_from_list(const getdns_list *pinset_list, 45 | struct mem_funcs *mf, 46 | sha256_pin_t **pinset_out); 47 | 48 | 49 | /* create a getdns_list version of the pinset */ 50 | getdns_return_t 51 | _getdns_get_pubkey_pinset_list(const getdns_context *ctx, 52 | const sha256_pin_t *pinset_in, 53 | getdns_list **pinset_list); 54 | 55 | #endif 56 | /* pubkey-pinning.h */ 57 | -------------------------------------------------------------------------------- /src/util/val_secalgo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file val_secalgo.h 4 | * /brief secalgo interface. 5 | * 6 | */ 7 | /* 8 | * Copyright (c) 2017, NLnet Labs, the getdns team 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #ifndef VAL_SECALGO_H_SYMBOLS 34 | #define VAL_SECALGO_H_SYMBOLS 35 | 36 | #include "gldns/gbuffer.h" 37 | 38 | enum sec_status { sec_status_bogus = 0 39 | , sec_status_unchecked = 0 40 | , sec_status_insecure = 0 41 | , sec_status_secure = 1 }; 42 | 43 | size_t _getdns_ds_digest_size_supported(int algo); 44 | 45 | int _getdns_secalgo_ds_digest(int algo, unsigned char* buf, size_t len, 46 | unsigned char* res); 47 | 48 | int _getdns_dnskey_algo_id_is_supported(int id); 49 | 50 | enum sec_status _getdns_verify_canonrrset(struct gldns_buffer* buf, int algo, 51 | unsigned char* sigblock, unsigned int sigblock_len, 52 | unsigned char* key, unsigned int keylen, char** reason); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/gldns/keyraw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * keyraw.c - raw key operations and conversions 3 | * 4 | * (c) NLnet Labs, 2004-2008 5 | * 6 | * See the file LICENSE for the license 7 | */ 8 | /** 9 | * \file 10 | * Implementation of raw DNSKEY functions (work on wire rdata). 11 | */ 12 | 13 | #include "config.h" 14 | #include "gldns/keyraw.h" 15 | #include "gldns/rrdef.h" 16 | 17 | size_t 18 | gldns_rr_dnskey_key_size_raw(const unsigned char* keydata, 19 | const size_t len, int alg) 20 | { 21 | /* for DSA keys */ 22 | uint8_t t; 23 | 24 | /* for RSA keys */ 25 | uint16_t exp; 26 | uint16_t int16; 27 | 28 | switch ((gldns_algorithm)alg) { 29 | case GLDNS_DSA: 30 | case GLDNS_DSA_NSEC3: 31 | if (len > 0) { 32 | t = keydata[0]; 33 | return (64 + t*8)*8; 34 | } else { 35 | return 0; 36 | } 37 | break; 38 | case GLDNS_RSAMD5: 39 | case GLDNS_RSASHA1: 40 | case GLDNS_RSASHA1_NSEC3: 41 | #ifdef USE_SHA2 42 | case GLDNS_RSASHA256: 43 | case GLDNS_RSASHA512: 44 | #endif 45 | if (len > 0) { 46 | if (keydata[0] == 0) { 47 | /* big exponent */ 48 | if (len > 3) { 49 | memmove(&int16, keydata + 1, 2); 50 | exp = ntohs(int16); 51 | return (len - exp - 3)*8; 52 | } else { 53 | return 0; 54 | } 55 | } else { 56 | exp = keydata[0]; 57 | return (len-exp-1)*8; 58 | } 59 | } else { 60 | return 0; 61 | } 62 | break; 63 | #ifdef USE_GOST 64 | case GLDNS_ECC_GOST: 65 | return 512; 66 | #endif 67 | #ifdef USE_ECDSA 68 | case GLDNS_ECDSAP256SHA256: 69 | return 256; 70 | case GLDNS_ECDSAP384SHA384: 71 | return 384; 72 | #endif 73 | #ifdef USE_ED25519 74 | case GLDNS_ED25519: 75 | return 256; 76 | #endif 77 | #ifdef USE_ED448 78 | case GLDNS_ED448: 79 | return 456; 80 | #endif 81 | default: 82 | return 0; 83 | } 84 | } 85 | 86 | uint16_t gldns_calc_keytag_raw(const uint8_t* key, size_t keysize) 87 | { 88 | if(keysize < 4) { 89 | return 0; 90 | } 91 | /* look at the algorithm field, copied from 2535bis */ 92 | if (key[3] == GLDNS_RSAMD5) { 93 | uint16_t ac16 = 0; 94 | if (keysize > 4) { 95 | memmove(&ac16, key + keysize - 3, 2); 96 | } 97 | ac16 = ntohs(ac16); 98 | return (uint16_t) ac16; 99 | } else { 100 | size_t i; 101 | uint32_t ac32 = 0; 102 | for (i = 0; i < keysize; ++i) { 103 | ac32 += (i & 1) ? key[i] : key[i] << 8; 104 | } 105 | ac32 += (ac32 >> 16) & 0xFFFF; 106 | return (uint16_t) (ac32 & 0xFFFF); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/util/rbtree.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file rbtree.h 4 | * /brief Alternative symbol names for unbound's rbtree.h 5 | * 6 | */ 7 | /* 8 | * Copyright (c) 2017, NLnet Labs, the getdns team 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #ifndef RBTREE_H_SYMBOLS 34 | #define RBTREE_H_SYMBOLS 35 | #define rbnode_type _getdns_rbnode_t 36 | #define rbtree_null_node _getdns_rbtree_null_node 37 | #define rbtree_type _getdns_rbtree_t 38 | #define rbtree_create _getdns_rbtree_create 39 | #define rbtree_init _getdns_rbtree_init 40 | #define rbtree_insert _getdns_rbtree_insert 41 | #define rbtree_delete _getdns_rbtree_delete 42 | #define rbtree_search _getdns_rbtree_search 43 | #define rbtree_find_less_equal _getdns_rbtree_find_less_equal 44 | #define rbtree_first _getdns_rbtree_first 45 | #define rbtree_last _getdns_rbtree_last 46 | #define rbtree_next _getdns_rbtree_next 47 | #define rbtree_previous _getdns_rbtree_previous 48 | #define traverse_postorder _getdns_traverse_postorder 49 | #include "util/orig-headers/rbtree.h" 50 | #endif 51 | -------------------------------------------------------------------------------- /src/util/auxiliary/util/log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief dummy prototypes for logging a la unbound 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef UTIL_LOG_H 35 | #define UTIL_LOG_H 36 | 37 | #include 38 | 39 | #include "config.h" 40 | #include "debug.h" 41 | 42 | #ifdef DEBUGGING 43 | #define verbose(x, ...) DEBUG_NL(__VA_ARGS__) 44 | #define log_err(...) DEBUG_NL(__VA_ARGS__) 45 | #define log_info(...) DEBUG_NL(__VA_ARGS__) 46 | #define fatal_exit(...) do { DEBUG_NL(__VA_ARGS__); exit(EXIT_FAILURE); } while(0) 47 | #define log_assert(x) do { if(!(x)) fatal_exit("%s:%d: %s: assertion %s failed", \ 48 | __FILE__, __LINE__, __FUNC__, #x); \ 49 | } while(0) 50 | #else 51 | #define verbose(...) ((void)0) 52 | #define log_err(...) ((void)0) 53 | #define log_info(...) ((void)0) 54 | #define fatal_exit(...) ((void)0) 55 | #define log_assert(x) ((void)0) 56 | #endif 57 | 58 | 59 | #endif /* UTIL_LOG_H */ 60 | 61 | -------------------------------------------------------------------------------- /src/test/testmessages.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief display messages to support unit testing 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the names of the copyright holders nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef TESTMESSAGES_H 34 | #define TESTMESSAGES_H 1 35 | 36 | /** 37 | * call at the start of a test program to display start message 38 | */ 39 | void tstmsg_prog_begin(char *prognm); 40 | /** 41 | * call at the end of a test program to display end message 42 | */ 43 | void tstmsg_prog_end(); 44 | 45 | /** 46 | * call at the start of a test case (after test_prog_begin) 47 | * to display case start message 48 | */ 49 | void tstmsg_case_begin(char *casenm); 50 | /** 51 | * call at the end of a test case (after test_prog_begin/test_case_begin) 52 | * to display case end message 53 | */ 54 | void tstmsg_case_end(); 55 | 56 | /** 57 | * call to display message regarding the current test case 58 | * to display case end message 59 | * TODO: add macro to automatically output source file line 60 | */ 61 | void tstmsg_case_msg(char *msg); 62 | 63 | #endif 64 | 65 | /* testmessages.h */ 66 | -------------------------------------------------------------------------------- /cmake/modules/FindLibidn2.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindLibidn2 3 | ----------- 4 | 5 | Find the Libidn2 library 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Libidn2::Libidn2`` 13 | The Libidn2 library, if found. 14 | 15 | Result variables 16 | ^^^^^^^^^^^^^^^^ 17 | 18 | This module will set the following variables in your project: 19 | 20 | ``Libidn2_FOUND`` 21 | If false, do not try to use Libidn2. 22 | ``LIBIDN2_INCLUDE_DIR`` 23 | where to find libidn2 headers. 24 | ``LIBIDN2_LIBRARIES`` 25 | the libraries needed to use Libidn2. 26 | ``LIBIDN2_VERSION`` 27 | the version of the Libidn2 library found 28 | 29 | #]=======================================================================] 30 | 31 | find_package(PkgConfig QUIET) 32 | if (PKG_CONFIG_FOUND) 33 | pkg_check_modules(PkgLibIdn2 IMPORTED_TARGET GLOBAL libidn2) 34 | endif () 35 | 36 | if (PkgLibIdn2_FOUND) 37 | set(LIBIDN2_INCLUDE_DIR ${PkgLibIdn2_INCLUDE_DIRS} CACHE FILEPATH "libidn2 include path") 38 | set(LIBIDN2_LIBRARIES ${PkgLibIdn2_LIBRARIES} CACHE STRING "libidn2 libraries") 39 | set(LIBIDN2_VERSION ${PkgLibIdn2_VERSION}) 40 | add_library(Libidn2::Libidn2 ALIAS PkgConfig::PkgLibIdn2) 41 | set(Libidn2_FOUND ON) 42 | else () 43 | find_path(LIBIDN2_INCLUDE_DIR idn2.h 44 | HINTS 45 | "${LIBIDN2_DIR}" 46 | "${LIBIDN2_DIR}/include" 47 | ) 48 | 49 | find_library(LIBIDN2_LIBRARIES NAMES idn2 libidn2 50 | HINTS 51 | "${LIBIDN2_DIR}" 52 | "${LIBIDN2_DIR}/lib" 53 | ) 54 | 55 | if (LIBIDN2_INCLUDE_DIR AND LIBIDN2_LIBRARIES) 56 | if (NOT TARGET Libidn2::Libidn2) 57 | add_library(Libidn2::Libidn2 UNKNOWN IMPORTED) 58 | set_target_properties(Libidn2::Libidn2 PROPERTIES 59 | INTERFACE_INCLUDE_DIRECTORIES "${LIBIDN2_INCLUDE_DIR}" 60 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 61 | IMPORTED_LOCATION "${LIBIDN2_LIBRARIES}" 62 | ) 63 | endif () 64 | 65 | if (NOT LIBIDN2_VERSION AND LIBIDN2_INCLUDE_DIR AND EXISTS "${LIBIDN2_INCLUDE_DIR}/idn2.h") 66 | file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" LIBIDN2_H REGEX "^[ \t]*#[ \t]*define[ \t]+IDN2_VERSION[ \t]") 67 | string(REGEX REPLACE "^.*IDN2_VERSION[ \t]+\"([0-9.]+)\".*$" "\\1" LIBIDN2_VERSION "${LIBIDN2_H}") 68 | endif () 69 | endif () 70 | include(FindPackageHandleStandardArgs) 71 | find_package_handle_standard_args(Libidn2 72 | REQUIRED_VARS LIBIDN2_LIBRARIES LIBIDN2_INCLUDE_DIR 73 | VERSION_VAR LIBIDN2_VERSION 74 | ) 75 | endif () 76 | 77 | mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARIES) 78 | -------------------------------------------------------------------------------- /doc/getdns_pretty_print_dict.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_pretty_print_dict 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_pretty_print_dict 32 | -- return a string representation of a getdns dict 33 | 34 | .SH LIBRARY 35 | DNS Resolver library (libgetdns, \-lgetdns) 36 | 37 | .SH SYNOPSIS 38 | #include 39 | 40 | char * 41 | .br 42 | .B getdns_pretty_print_dict 43 | (const getdns_dict *this_dict) 44 | 45 | .SH DESCRIPTION 46 | 47 | .LP 48 | Helper function that returns a string of nicely formatted data including all of the 49 | elements in the dict. 50 | 51 | .HP 3 52 | .I this_dict 53 | the dictionary to render as a string 54 | 55 | .HP 56 | .SH "RETURN VALUES" 57 | 58 | Returns a string that the calling function must free (it is allocated using the 59 | system allocator not the user defined allocator). Returns NULL if there is an error. 60 | 61 | .SH EXAMPLES 62 | 63 | TBD 64 | 65 | .SH SEE ALSO 66 | .BR getdns_dict (3) 67 | .BR libgetdns (3) 68 | 69 | -------------------------------------------------------------------------------- /doc/getdns_display_ip_address.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_display_ip_address 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_display_ip_address 32 | -- convert an getdns ip address to string 33 | 34 | .SH LIBRARY 35 | DNS Resolver library (libgetdns, \-lgetdns) 36 | 37 | .SH SYNOPSIS 38 | #include 39 | 40 | char * 41 | .br 42 | .B getdns_display_ip_address 43 | (const getdns_bindata *ipv4_or_ipv6_addr) 44 | 45 | .SH DESCRIPTION 46 | 47 | .LP 48 | This helper function returns a nicely formatted string representation of the IPv4 or 49 | IPv6 address. The length of the bindata is used to determine whether the address 50 | is IPv4 or IPv6. 51 | 52 | .HP 3 53 | .I ipv4_or_ipv6_addr 54 | bindata of the address to print 55 | 56 | .HP 57 | .SH "RETURN VALUES" 58 | 59 | Returns a string representation of the IP address (allocated using the system 60 | allocator - malloc), the caller is responsible for freeing the storage using free(). 61 | 62 | .SH EXAMPLES 63 | 64 | TBD 65 | 66 | .SH SEE ALSO 67 | .BR libgetdns (3) 68 | 69 | -------------------------------------------------------------------------------- /src/extension/select_eventloop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * \file select_eventloop.h 3 | * @brief Build in default eventloop extension that uses select. 4 | * 5 | */ 6 | /* 7 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the names of the copyright holders nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef SELECT_EVENTLOOP_H_ 33 | #define SELECT_EVENTLOOP_H_ 34 | #include "config.h" 35 | #include "getdns/getdns.h" 36 | #include "getdns/getdns_extra.h" 37 | #include "types-internal.h" 38 | 39 | /* No more than select's capability queries can be outstanding, 40 | * The number of outstanding timeouts should be less or equal then 41 | * the number of outstanding queries, so MAX_TIMEOUTS equal to 42 | * FD_SETSIZE should be safe. 43 | */ 44 | #define MAX_TIMEOUTS FD_SETSIZE 45 | 46 | /* Eventloop based on select */ 47 | typedef struct _getdns_select_eventloop { 48 | getdns_eventloop loop; 49 | getdns_eventloop_event *fd_events[FD_SETSIZE]; 50 | uint64_t fd_timeout_times[FD_SETSIZE]; 51 | getdns_eventloop_event *timeout_events[MAX_TIMEOUTS]; 52 | uint64_t timeout_times[MAX_TIMEOUTS]; 53 | } _getdns_select_eventloop; 54 | 55 | 56 | void 57 | _getdns_select_eventloop_init(struct mem_funcs *mf, _getdns_select_eventloop *loop); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/const-info.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief _getdns_consts table with values, names and descriptions of the 4 | * constants in getdns 5 | * 6 | * The _getdns_get_validation_chain function is called after an answer 7 | * has been fetched when the dnssec_return_validation_chain extension is set. 8 | * It fetches DNSKEYs, DSes and their signatures for all RRSIGs found in the 9 | * answer. 10 | */ 11 | 12 | /* 13 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions are met: 18 | * * Redistributions of source code must retain the above copyright 19 | * notice, this list of conditions and the following disclaimer. 20 | * * Redistributions in binary form must reproduce the above copyright 21 | * notice, this list of conditions and the following disclaimer in the 22 | * documentation and/or other materials provided with the distribution. 23 | * * Neither the names of the copyright holders nor the 24 | * names of its contributors may be used to endorse or promote products 25 | * derived from this software without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 31 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 32 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef CONST_INFO_H_ 40 | #define CONST_INFO_H_ 41 | 42 | #include "getdns/getdns.h" 43 | #include "getdns/getdns_extra.h" 44 | 45 | #ifndef GETDNS_CONTEXT_CODE_MAX_BACKOFF_VALUE 46 | #define GETDNS_CONTEXT_CODE_MAX_BACKOFF_VALUE 699 47 | #define GETDNS_CONTEXT_CODE_MAX_BACKOFF_VALUE_TEXT "Change related to getdns_context_set_max_backoff_value" 48 | #endif 49 | 50 | struct const_info { 51 | int code; 52 | const char *name; 53 | const char *text; 54 | }; 55 | 56 | struct const_info *_getdns_get_const_info(int value); 57 | 58 | struct const_name_info { 59 | const char *name; 60 | uint32_t code; 61 | }; 62 | 63 | int _getdns_get_const_name_info(const char *name, uint32_t *code); 64 | 65 | #endif 66 | 67 | /* const-info.h */ 68 | -------------------------------------------------------------------------------- /src/extension/poll_eventloop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * \file poll_eventloop.h 3 | * @brief Build in default eventloop extension that uses select. 4 | * 5 | */ 6 | /* 7 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the names of the copyright holders nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef POLL_EVENTLOOP_H_ 33 | #define POLL_EVENTLOOP_H_ 34 | #include "config.h" 35 | #include "getdns/getdns.h" 36 | #include "getdns/getdns_extra.h" 37 | #include "types-internal.h" 38 | 39 | /* Eventloop based on poll */ 40 | 41 | typedef struct _getdns_poll_event { 42 | getdns_eventloop_event *event; 43 | uint64_t timeout_time; 44 | } _getdns_poll_event; 45 | 46 | typedef struct _getdns_poll_eventloop { 47 | getdns_eventloop loop; 48 | struct mem_funcs mf; 49 | 50 | struct pollfd *pfds; 51 | size_t fd_events_capacity; 52 | _getdns_poll_event *fd_events; 53 | size_t fd_events_free; 54 | size_t fd_events_n_used; 55 | 56 | size_t to_events_capacity; 57 | _getdns_poll_event *to_events; 58 | size_t to_events_free; 59 | size_t to_events_n_used; 60 | } _getdns_poll_eventloop; 61 | 62 | void 63 | _getdns_poll_eventloop_init(struct mem_funcs *mf, _getdns_poll_eventloop *loop); 64 | 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /cmake/modules/FindLibuv.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindLibuv 3 | --------- 4 | 5 | Find the Libuv library. 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Libuv::Libuv`` 13 | The Libuv library, if found. 14 | 15 | Result variables 16 | ^^^^^^^^^^^^^^^^ 17 | 18 | This module will set the following variables in your project: 19 | 20 | ``Libuv_FOUND`` 21 | If false, do not try to use Libuv. 22 | ``LIBUV_INCLUDE_DIR`` 23 | where to find libuv headers. 24 | ``LIBUV_LIBRARIES`` 25 | the libraries needed to use Libuv. 26 | ``LIBUV_VERSION`` 27 | the version of the Libuv library found 28 | 29 | #]=======================================================================] 30 | 31 | find_package(PkgConfig QUIET) 32 | if (PKG_CONFIG_FOUND) 33 | pkg_check_modules(PkgLibuv IMPORTED_TARGET GLOBAL libuv) 34 | endif () 35 | 36 | if (PkgLibuv_FOUND) 37 | set(LIBUV_INCLUDE_DIR ${PkgLibuv_INCLUDE_DIRS} CACHE FILEPATH "libuv include path") 38 | set(LIBUV_LIBRARIES ${PkgLibuv_LIBRARIES} CACHE STRING "libuv libraries") 39 | set(LIBUV_VERSION ${PkgLibuv_VERSION}) 40 | add_library(Libuv::Libuv ALIAS PkgConfig::PkgLibuv) 41 | set(Libuv_FOUND ON) 42 | else () 43 | find_path(LIBUV_INCLUDE_DIR uv.h 44 | HINTS 45 | "${LIBUV_DIR}" 46 | "${LIBUV_DIR}/include" 47 | ) 48 | 49 | find_library(LIBUV_LIBRARIES NAMES uv libuv 50 | HINTS 51 | "${LIBUV_DIR}" 52 | "${LIBUV_DIR}/lib" 53 | ) 54 | 55 | if (LIBUV_INCLUDE_DIR AND LIBUV_LIBRARIES) 56 | if (NOT TARGET Libuv::Libuv) 57 | add_library(Libuv::Libuv UNKNOWN IMPORTED) 58 | set_target_properties(Libuv::Libuv PROPERTIES 59 | INTERFACE_INCLUDE_DIRECTORIES "${LIBUV_INCLUDE_DIR}" 60 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 61 | IMPORTED_LOCATION "${LIBUV_LIBRARIES}" 62 | ) 63 | endif () 64 | 65 | if (NOT LIBUV_VERSION AND LIBUV_INCLUDE_DIR) 66 | if (EXISTS "${LIBUV_INCLUDE_DIR}/uv-version.h") 67 | file(STRINGS "${LIBUV_INCLUDE_DIR}/uv-version.h" LIBUV_VER_H REGEX "^#define UV_VERSION_(MAJOR|MINOR|PATCH) ") 68 | elseif (EXISTS "${LIBUV_INCLUDE_DIR}/uv/version.h") 69 | file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" LIBUV_VER_H REGEX "^#define UV_VERSION_(MAJOR|MINOR|PATCH) ") 70 | endif () 71 | string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3" LIBUV_VERSION "${LIBUV_VER_H}") 72 | endif () 73 | endif () 74 | 75 | include(FindPackageHandleStandardArgs) 76 | find_package_handle_standard_args(Libuv 77 | REQUIRED_VARS LIBUV_LIBRARIES LIBUV_INCLUDE_DIR 78 | VERSION_VAR LIBUV_VERSION 79 | ) 80 | endif () 81 | 82 | mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARIES) 83 | -------------------------------------------------------------------------------- /src/test/check_getdns_libuv.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Testing interfaces to getdns 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "check_getdns_eventloop.h" 37 | 38 | #include "getdns/getdns_ext_libuv.h" 39 | #include 40 | #ifdef __clang__ 41 | #pragma clang diagnostic push 42 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 43 | #endif 44 | #include 45 | #ifdef __clang__ 46 | #pragma clang diagnostic pop 47 | #endif 48 | #include "check_getdns_common.h" 49 | 50 | void run_event_loop_impl(struct getdns_context* context, void* eventloop) { 51 | uv_loop_t* loop = (uv_loop_t*) eventloop; 52 | (void)context; /* unused parameter */ 53 | uv_run(loop, UV_RUN_DEFAULT); 54 | } 55 | 56 | 57 | void* create_eventloop_impl(struct getdns_context* context) { 58 | uv_loop_t* result = uv_default_loop(); 59 | ck_assert_msg(result != NULL, "UV loop creation failed"); 60 | ASSERT_RC(getdns_extension_set_libuv_loop(context, result), 61 | GETDNS_RETURN_GOOD, 62 | "Return code from getdns_extension_set_libuv_loop()"); 63 | return result; 64 | } 65 | -------------------------------------------------------------------------------- /cmake/modules/FindLibevent2.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindLibevent2 3 | ------------- 4 | 5 | Find the Libevent2 library. For now this finds the core library only. 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Libevent2::Libevent_core`` 13 | The Libevent2 library, if found. 14 | 15 | Result variables 16 | ^^^^^^^^^^^^^^^^ 17 | 18 | This module will set the following variables in your project: 19 | 20 | ``Libevent2_FOUND`` 21 | If false, do not try to use Libevent2. 22 | ``LIBEVENT2_INCLUDE_DIR`` 23 | where to find libevent headers. 24 | ``LIBEVENT2_LIBRARIES`` 25 | the libraries needed to use Libevent2. 26 | ``LIBEVENT2_VERSION`` 27 | the version of the Libevent2 library found 28 | 29 | #]=======================================================================] 30 | 31 | find_package(PkgConfig QUIET) 32 | if (PKG_CONFIG_FOUND) 33 | pkg_check_modules(PkgLibevent IMPORTED_TARGET GLOBAL QUIET libevent>=2) 34 | endif () 35 | 36 | if (PkgLibevent_FOUND) 37 | set(LIBEVENT2_INCLUDE_DIR ${PkgLibevent_INCLUDE_DIRS} CACHE FILEPATH "libevent2 include path") 38 | set(LIBEVENT2_LIBRARIES ${PkgLibevent_LIBRARIES} CACHE STRING "libevent2 libraries") 39 | set(LIBEVENT2_VERSION ${PkgLibevent_VERSION}) 40 | add_library(Libevent2::Libevent_core ALIAS PkgConfig::PkgLibevent) 41 | set(Libevent2_FOUND ON) 42 | else () 43 | find_path(LIBEVENT2_INCLUDE_DIR event2/event.h 44 | HINTS 45 | "${LIBEVENT2_DIR}" 46 | "${LIBEVENT2_DIR}/include" 47 | ) 48 | 49 | find_library(LIBEVENT2_LIBRARIES NAMES event_core libevent_core 50 | HINTS 51 | "${LIBEVENT2_DIR}" 52 | "${LIBEVENT2_DIR}/lib" 53 | ) 54 | 55 | if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARIES) 56 | if (NOT TARGET Libevent2::Libevent_core) 57 | add_library(Libevent2::Libevent_core UNKNOWN IMPORTED) 58 | set_target_properties(Libevent2::Libevent_core PROPERTIES 59 | INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT2_INCLUDE_DIR}" 60 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 61 | IMPORTED_LOCATION "${LIBEVENT2_LIBRARIES}" 62 | ) 63 | endif () 64 | 65 | if (NOT LIBEVENT2_VERSION AND LIBEVENT2_INCLUDE_DIR AND EXISTS "${LIBEVENT2_INCLUDE_DIR}/event2/event.h") 66 | file(STRINGS "${LIBEVENT2_INCLUDE_DIR}/event2/event-config.h" LIBEVENT2_H REGEX "^#define _?EVENT_+VERSION ") 67 | string(REGEX REPLACE "^.*EVENT_+VERSION \"([^\"]+)\".*$" "\\1" LIBEVENT2_VERSION "${LIBEVENT2_H}") 68 | endif () 69 | endif () 70 | 71 | include(FindPackageHandleStandardArgs) 72 | find_package_handle_standard_args(Libevent2 73 | REQUIRED_VARS LIBEVENT2_LIBRARIES LIBEVENT2_INCLUDE_DIR 74 | VERSION_VAR LIBEVENT2_VERSION 75 | ) 76 | endif () 77 | 78 | mark_as_advanced(LIBEVENT2_INCLUDE_DIR LIBEVENT2_LIBRARIES) 79 | -------------------------------------------------------------------------------- /src/test/check_getdns_libevent.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Testing interfaces to getdns 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "check_getdns_eventloop.h" 37 | 38 | #include "getdns/getdns_ext_libevent.h" 39 | #include "check_getdns_libevent.h" 40 | #ifdef __clang__ 41 | #pragma clang diagnostic push 42 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 43 | #endif 44 | #include 45 | #ifdef __clang__ 46 | #pragma clang diagnostic pop 47 | #endif 48 | #include "check_getdns_common.h" 49 | 50 | void run_event_loop_impl(struct getdns_context* context, void* eventloop) { 51 | struct event_base* base = (struct event_base*) eventloop; 52 | (void)context; /* unused parameter */ 53 | event_base_dispatch(base); 54 | } 55 | 56 | void* create_eventloop_impl(struct getdns_context* context) { 57 | struct event_base* result = event_base_new(); 58 | ck_assert_msg(result != NULL, "Event base creation failed"); 59 | ASSERT_RC(getdns_extension_set_libevent_base(context, result), 60 | GETDNS_RETURN_GOOD, 61 | "Return code from getdns_extension_set_libevent_base()"); 62 | return result; 63 | } 64 | -------------------------------------------------------------------------------- /src/test/check_getdns_libev.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Testing interfaces to getdns 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "check_getdns_eventloop.h" 37 | 38 | #include "getdns/getdns_ext_libev.h" 39 | #ifdef HAVE_LIBEV_EV_H 40 | #include 41 | #else 42 | #include 43 | #endif 44 | #ifdef __clang__ 45 | #pragma clang diagnostic push 46 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 47 | #endif 48 | #include 49 | #ifdef __clang__ 50 | #pragma clang diagnostic pop 51 | #endif 52 | #include "check_getdns_common.h" 53 | 54 | void run_event_loop_impl(struct getdns_context* context, void* eventloop) { 55 | struct ev_loop* loop = (struct ev_loop*) eventloop; 56 | (void)context; /* unused parameter */ 57 | ev_run(loop, 0); 58 | } 59 | 60 | void* create_eventloop_impl(struct getdns_context* context) { 61 | struct ev_loop* result = ev_default_loop(0); 62 | ck_assert_msg(result != NULL, "EV loop creation failed"); 63 | ASSERT_RC(getdns_extension_set_libev_loop(context, result), 64 | GETDNS_RETURN_GOOD, 65 | "Return code from getdns_extension_set_libev_loop()"); 66 | return result; 67 | } 68 | -------------------------------------------------------------------------------- /src/convert.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file convert.h 4 | * @brief getdns label conversion functions 5 | * 6 | */ 7 | 8 | /* 9 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * * Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the names of the copyright holders nor the 20 | * names of its contributors may be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _GETDNS_CONVERT_H_ 36 | #define _GETDNS_CONVERT_H_ 37 | 38 | #include "types-internal.h" 39 | #include 40 | 41 | getdns_return_t 42 | _getdns_wire2msg_dict_scan(struct mem_funcs *mf, 43 | const uint8_t **wire, size_t *wire_len, getdns_dict **msg_dict); 44 | 45 | getdns_return_t _getdns_wire2rr_dict(struct mem_funcs *mf, 46 | const uint8_t *wire, size_t wire_len, getdns_dict **rr_dict); 47 | 48 | getdns_return_t _getdns_wire2rr_dict_buf(struct mem_funcs *mf, 49 | const uint8_t *wire, size_t *wire_len, getdns_dict **rr_dict); 50 | 51 | getdns_return_t _getdns_wire2rr_dict_scan(struct mem_funcs *mf, 52 | const uint8_t **wire, size_t *wire_len, getdns_dict **rr_dict); 53 | 54 | getdns_return_t _getdns_str2rr_dict(struct mem_funcs *mf, const char *str, 55 | getdns_dict **rr_dict, const char *origin, uint32_t default_ttl); 56 | 57 | getdns_return_t _getdns_fp2rr_list(struct mem_funcs *mf, FILE *in, 58 | getdns_list **rr_list, const char *origin, uint32_t default_ttl); 59 | 60 | getdns_return_t _getdns_reply_dict2wire( 61 | const getdns_dict *reply, gldns_buffer *buf, int reuse_header); 62 | 63 | #endif 64 | /* convert.h */ 65 | -------------------------------------------------------------------------------- /src/util/locks.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file locks.h 4 | * /brief Alternative symbol names for unbound's locks.h 5 | * 6 | */ 7 | /* 8 | * Copyright (c) 2017, NLnet Labs, the getdns team 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #ifndef LOCKS_H_SYMBOLS 34 | #define LOCKS_H_SYMBOLS 35 | 36 | #include "config.h" 37 | 38 | #define ub_thread_blocksigs _getdns_ub_thread_blocksigs 39 | #define ub_thread_sig_unblock _getdns_ub_thread_sig_unblock 40 | 41 | #define ub_thread_type _getdns_ub_thread_type 42 | #define ub_thr_fork_create _getdns_ub_thr_fork_create 43 | #define ub_thr_fork_wait _getdns_ub_thr_fork_wait 44 | 45 | #if defined(HAVE_SOLARIS_THREADS) || defined(HAVE_WINDOWS_THREADS) 46 | #define ub_thread_key_type _getdns_ub_thread_key_type 47 | #define ub_thread_key_create _getdns_ub_thread_key_create 48 | #define ub_thread_key_set _getdns_ub_thread_key_set 49 | #define ub_thread_key_get _getdns_ub_thread_key_get 50 | #endif 51 | 52 | #ifdef HAVE_WINDOWS_THREADS 53 | #define lock_basic_type _getdns_lock_basic_type 54 | #define lock_basic_init _getdns_lock_basic_init 55 | #define lock_basic_destroy _getdns_lock_basic_destroy 56 | #define lock_basic_lock _getdns_lock_basic_lock_ 57 | #define lock_basic_unlock _getdns_lock_basic_unlock 58 | 59 | #define ub_thread_create _getdns_ub_thread_create 60 | #define ub_thread_self _getdns_ub_thread_self 61 | #endif 62 | 63 | #include "util/orig-headers/locks.h" 64 | #endif 65 | -------------------------------------------------------------------------------- /src/tls/validator/val_secalgo.h: -------------------------------------------------------------------------------- 1 | #ifndef VAL_SECALGO_H_VALIDATOR 2 | #define VAL_SECALGO_H_VALIDATOR 3 | 4 | #define sldns_buffer gldns_buffer 5 | 6 | #define nsec3_hash_algo_size_supported _getdns_nsec3_hash_algo_size_supported 7 | #define secalgo_nsec3_hash _getdns_secalgo_nsec3_hash 8 | #define secalgo_hash_sha256 _getdns_secalgo_hash_sha256 9 | #define ds_digest_size_supported _getdns_ds_digest_size_supported 10 | #define secalgo_ds_digest _getdns_secalgo_ds_digest 11 | #define dnskey_algo_id_is_supported _getdns_dnskey_algo_id_is_supported 12 | #define verify_canonrrset _getdns_verify_canonrrset 13 | #define sec_status _getdns_sec_status 14 | #define sec_status_secure _getdns_sec_status_secure 15 | #define sec_status_insecure _getdns_sec_status_insecure 16 | #define sec_status_unchecked _getdns_sec_status_unchecked 17 | #define sec_status_bogus _getdns_sec_status_bogus 18 | #define fake_sha1 _getdns_fake_sha1 19 | #define fake_dsa _getdns_fake_dsa 20 | 21 | 22 | #define NSEC3_HASH_SHA1 0x01 23 | 24 | #define LDNS_SHA1 GLDNS_SHA1 25 | #define LDNS_SHA256 GLDNS_SHA256 26 | #define LDNS_SHA384 GLDNS_SHA384 27 | #define LDNS_HASH_GOST GLDNS_HASH_GOST 28 | #define LDNS_RSAMD5 GLDNS_RSAMD5 29 | #define LDNS_DSA GLDNS_DSA 30 | #define LDNS_DSA_NSEC3 GLDNS_DSA_NSEC3 31 | #define LDNS_RSASHA1 GLDNS_RSASHA1 32 | #define LDNS_RSASHA1_NSEC3 GLDNS_RSASHA1_NSEC3 33 | #define LDNS_RSASHA256 GLDNS_RSASHA256 34 | #define LDNS_RSASHA512 GLDNS_RSASHA512 35 | #define LDNS_ECDSAP256SHA256 GLDNS_ECDSAP256SHA256 36 | #define LDNS_ECDSAP384SHA384 GLDNS_ECDSAP384SHA384 37 | #define LDNS_ECC_GOST GLDNS_ECC_GOST 38 | #define LDNS_ED25519 GLDNS_ED25519 39 | #define LDNS_ED448 GLDNS_ED448 40 | #define sldns_ed255192pkey_raw gldns_ed255192pkey_raw 41 | #define sldns_ed4482pkey_raw gldns_ed4482pkey_raw 42 | #define sldns_key_EVP_load_gost_id gldns_key_EVP_load_gost_id 43 | #define sldns_digest_evp gldns_digest_evp 44 | #define sldns_key_buf2dsa_raw gldns_key_buf2dsa_raw 45 | #define sldns_key_buf2rsa_raw gldns_key_buf2rsa_raw 46 | #define sldns_gost2pkey_raw gldns_gost2pkey_raw 47 | #define sldns_ecdsa2pkey_raw gldns_ecdsa2pkey_raw 48 | #define sldns_buffer_begin gldns_buffer_begin 49 | #define sldns_buffer_limit gldns_buffer_limit 50 | #define sldns_key_dsa2pkey_raw gldns_key_dsa2pkey_raw 51 | #define sldns_key_rsa2pkey_raw gldns_key_rsa2pkey_raw 52 | 53 | #include "util/val_secalgo.h" 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/util/orig-headers/lookup3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util/storage/lookup3.h - header file for hashing functions. 3 | * 4 | * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 | * 6 | * This software is open source. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * Neither the name of the NLNET LABS nor the names of its contributors may 20 | * be used to endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | /** 37 | * \file 38 | * 39 | * This file contains header definitions for the hash functions we use. 40 | * The hash functions are public domain (see lookup3.c). 41 | */ 42 | 43 | #ifndef UTIL_STORAGE_LOOKUP3_H 44 | #define UTIL_STORAGE_LOOKUP3_H 45 | 46 | /** 47 | * Hash key made of 4byte chunks. 48 | * @param k: the key, an array of uint32_t values 49 | * @param length: the length of the key, in uint32_ts 50 | * @param initval: the previous hash, or an arbitrary value 51 | * @return: hash value. 52 | */ 53 | uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval); 54 | 55 | /** 56 | * Hash key data. 57 | * @param k: the key, array of uint8_t 58 | * @param length: the length of the key, in uint8_ts 59 | * @param initval: the previous hash, or an arbitrary value 60 | * @return: hash value. 61 | */ 62 | uint32_t hashlittle(const void *k, size_t length, uint32_t initval); 63 | 64 | /** 65 | * Set the randomisation initial value, set this before threads start, 66 | * and before hashing stuff (because it changes subsequent results). 67 | * @param v: value 68 | */ 69 | void hash_set_raninit(uint32_t v); 70 | 71 | #endif /* UTIL_STORAGE_LOOKUP3_H */ 72 | -------------------------------------------------------------------------------- /doc/getdns_root_trust_anchor.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_root_trust_anchor 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_root_trust_anchor 32 | -- return the getdns list of default root trust anchors 33 | 34 | .SH LIBRARY 35 | DNS Resolver library (libgetdns, \-lgetdns) 36 | 37 | .SH SYNOPSIS 38 | #include 39 | 40 | getdns_list * 41 | .br 42 | .B getdns_root_trust_anchor 43 | (time_t *utc_date_of_anchor) 44 | 45 | .SH DESCRIPTION 46 | 47 | .LP 48 | If an application wants the API to perform DNSSEC validation without using the 49 | extensions, it can use the getdns_validate_dnssec() helper function. The API 50 | will use the resource records in bundle_of_support_records to construct the 51 | validation chain and the DNSKEY or DS records in trust_anchor_records as trust 52 | anchors. The default list of trust anchor records that is used by the library 53 | to validate DNSSEC can be retrieved by using the getdns_root_trust_anchor 54 | helper function. 55 | 56 | .HP 3 57 | .I utc_date_of_anchor 58 | time the trust anchors were obtained in epoch seconds (on success) 59 | 60 | .HP 61 | .SH "RETURN VALUES" 62 | 63 | Returns the default list of trust anchor records used by the library to validate DNSSEC or NULL if no default trust anchors are available. 64 | 65 | .SH EXAMPLES 66 | 67 | TBD 68 | 69 | .SH SEE ALSO 70 | .BR getdns_validate_dnssec (3) 71 | .BR libgetdns (3) 72 | 73 | -------------------------------------------------------------------------------- /src/openssl/tls-internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file tls-internal.h 4 | * @brief getdns TLS implementation-specific items 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2018-2019, NLnet Labs 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _GETDNS_TLS_INTERNAL_H 35 | #define _GETDNS_TLS_INTERNAL_H 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "getdns/getdns.h" 43 | 44 | #ifndef HAVE_DECL_SSL_CTX_SET1_CURVES_LIST 45 | #define HAVE_TLS_CTX_CURVES_LIST 0 46 | #else 47 | #define HAVE_TLS_CTX_CURVES_LIST (HAVE_DECL_SSL_CTX_SET1_CURVES_LIST) 48 | #endif 49 | #ifndef HAVE_DECL_SSL_SET1_CURVES_LIST 50 | #define HAVE_TLS_CONN_CURVES_LIST 0 51 | #else 52 | #define HAVE_TLS_CONN_CURVES_LIST (HAVE_DECL_SSL_SET1_CURVES_LIST) 53 | #endif 54 | 55 | #define GETDNS_TLS_MAX_DIGEST_LENGTH (EVP_MAX_MD_SIZE) 56 | 57 | /* Forward declare type. */ 58 | struct sha256_pin; 59 | struct getdns_log_config; 60 | 61 | typedef struct _getdns_tls_context { 62 | SSL_CTX* ssl; 63 | const struct getdns_log_config* log; 64 | } _getdns_tls_context; 65 | 66 | typedef struct _getdns_tls_connection { 67 | SSL* ssl; 68 | const struct getdns_log_config* log; 69 | #if defined(USE_DANESSL) 70 | const char* auth_name; 71 | const struct sha256_pin* pinset; 72 | #endif 73 | } _getdns_tls_connection; 74 | 75 | typedef struct _getdns_tls_session { 76 | SSL_SESSION* ssl; 77 | } _getdns_tls_session; 78 | 79 | typedef struct _getdns_tls_x509 80 | { 81 | X509* ssl; 82 | } _getdns_tls_x509; 83 | 84 | #endif /* _GETDNS_TLS_INTERNAL_H */ 85 | -------------------------------------------------------------------------------- /src/test/testmessages.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * @brief display messages to support unit testing 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * * Neither the names of the copyright holders nor the 18 | * names of its contributors may be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "testmessages.h" 38 | 39 | static char *testprog = NULL; 40 | static char **cases = NULL; 41 | static int ncases = 0; 42 | 43 | void 44 | tstmsg_prog_begin(char *prognm) 45 | { 46 | if (testprog != NULL) { 47 | tstmsg_prog_end(); 48 | } 49 | testprog = strdup(prognm); 50 | printf("TESTPROG %s START\n", testprog); 51 | } /* tstmsg_prog_begin */ 52 | 53 | void 54 | tstmsg_prog_end() 55 | { 56 | printf("TESTPROG %s END\n", testprog); 57 | free(testprog); 58 | } /* tstmsg_prog_end */ 59 | 60 | void 61 | tstmsg_case_begin(char *casenm) 62 | { 63 | ncases++; 64 | cases = (char **) realloc(cases, sizeof(char *) * ncases); 65 | cases[ncases - 1] = strdup(casenm); 66 | 67 | printf("TESTCASE %s:%s BEGIN\n", testprog, cases[ncases - 1]); 68 | } /* tstmsg_case_begin */ 69 | 70 | void 71 | tstmsg_case_end(void) 72 | { 73 | if (ncases > 0) { 74 | printf("TESTCASE %s:%s END\n", testprog, cases[ncases - 1]); 75 | ncases--; 76 | free(cases[ncases]); 77 | if (ncases) { 78 | cases = 79 | (char **) realloc(cases, sizeof(char *) * ncases); 80 | } else { 81 | cases = NULL; 82 | } 83 | } 84 | } /* tstmsg_case_end */ 85 | 86 | void 87 | tstmsg_case_msg(char *msg) 88 | { 89 | printf(" %s:%s: %s\n", testprog, cases[ncases - 1], msg); 90 | } /* tstmsg_case_msg */ 91 | 92 | /* testmessages.c */ 93 | -------------------------------------------------------------------------------- /src/getdns/getdns_ext_libev.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Public interfaces to getdns, include in your application to use getdns API. 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef GETDNS_EXT_LIBEV_H 37 | #define GETDNS_EXT_LIBEV_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include 44 | #include 45 | struct ev_loop; 46 | 47 | 48 | /** 49 | * \ingroup eventloops 50 | */ 51 | /** 52 | * Associate the libev ev_loop with the context, so that all 53 | * asynchronous requests will schedule Input/Output with it. 54 | * Synchronous requests will still use a default eventloop based on `poll()`. 55 | * Applications need to @code #include @endcode 56 | * and link with libgetdns_ext_ev to use this function. 57 | * getdns needs to have been configured with --with-libev for this 58 | * extension to be available. 59 | * @param context The context to configure 60 | * @param ev_loop The libev event loop to associate with this context. 61 | * @return GETDNS_RETURN_GOOD when successful 62 | * @return GETDNS_RETURN_BAD_CONTEXT when context is NULL 63 | * @return GETDNS_RETURN_INVALID_PARAMETER when ev_loop is NULL 64 | * @return GETDNS_RETURN_MEMORY_ERROR when memory could not be allocated 65 | */ 66 | getdns_return_t 67 | getdns_extension_set_libev_loop(struct getdns_context *context, 68 | struct ev_loop *ev_loop); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | #endif 74 | -------------------------------------------------------------------------------- /src/getdns/getdns_ext_libuv.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Public interfaces to getdns, include in your application to use getdns API. 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef GETDNS_EXT_LIBUV_H 37 | #define GETDNS_EXT_LIBUV_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include 44 | #include 45 | struct uv_loop_s; 46 | 47 | /** 48 | * \ingroup eventloops 49 | */ 50 | /** 51 | * Associate the libuv uv_loop with the context, so that all 52 | * asynchronous requests will schedule Input/Output with it. 53 | * Synchronous requests will still use a default eventloop based on `poll()`. 54 | * Applications need to @code #include @endcode 55 | * and link with libgetdns_ext_uv to use this function. 56 | * getdns needs to have been configured with --with-libuv for this 57 | * extension to be available. 58 | * @param context The context to configure 59 | * @param uv_loop The libuv event loop to associate with this context. 60 | * @return GETDNS_RETURN_GOOD when successful 61 | * @return GETDNS_RETURN_BAD_CONTEXT when context is NULL 62 | * @return GETDNS_RETURN_INVALID_PARAMETER when uv_loop is NULL 63 | * @return GETDNS_RETURN_MEMORY_ERROR when memory could not be allocated 64 | */ 65 | getdns_return_t 66 | getdns_extension_set_libuv_loop(struct getdns_context *context, 67 | struct uv_loop_s *uv_loop); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #endif 73 | -------------------------------------------------------------------------------- /src/dict.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief getdns dict data type management functions 4 | * 5 | * 6 | */ 7 | 8 | /* 9 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * * Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the names of the copyright holders nor the 20 | * names of its contributors may be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _GETDNS_DICT_H_ 36 | #define _GETDNS_DICT_H_ 37 | 38 | #include "getdns/getdns.h" 39 | #include "util/rbtree.h" 40 | #include "types-internal.h" 41 | 42 | /** 43 | * this structure represents a single item in a dictionary type 44 | */ 45 | struct getdns_dict_item 46 | { 47 | _getdns_rbnode_t node; 48 | getdns_item i; 49 | }; 50 | 51 | /** 52 | * getdns dictionary data type 53 | * Use helper functions getdns_dict_* to manipulate and iterate dictionaries 54 | * dict is implemented using the t*() functions for manipulating binary search 55 | * trees in the std library. The internal implementation may change so the 56 | * application should stick to the helper functions. 57 | */ 58 | struct getdns_dict 59 | { 60 | _getdns_rbtree_t root; 61 | struct mem_funcs mf; 62 | }; 63 | 64 | static inline getdns_dict *_getdns_dict_create_with_mf(struct mem_funcs *mf) 65 | { return getdns_dict_create_with_extended_memory_functions( 66 | mf->mf_arg, mf->mf.ext.malloc, mf->mf.ext.realloc, mf->mf.ext.free); } 67 | 68 | getdns_return_t _getdns_dict_find( 69 | const getdns_dict *dict, const char *key, getdns_item **item); 70 | 71 | getdns_return_t _getdns_dict_find_and_add( 72 | getdns_dict *dict, const char *key, getdns_item **item); 73 | 74 | /* Return 1 (true) if bindata can be interpreted as an 75 | * uncompressed dname. 76 | */ 77 | int _getdns_bindata_is_dname(getdns_bindata *bindata); 78 | 79 | #endif 80 | 81 | /* dict.h */ 82 | -------------------------------------------------------------------------------- /src/ub_loop.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file ub_loop.h 4 | * /brief Interface for the pluggable unbound event API 5 | * 6 | */ 7 | 8 | /* 9 | * Copyright (c) 2015, NLnet Labs, Verisign, Inc. 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * * Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the names of the copyright holders nor the 20 | * names of its contributors may be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef UB_LOOP_H 36 | #define UB_LOOP_H 37 | 38 | #include "config.h" 39 | #ifdef HAVE_UNBOUND_EVENT_API 40 | #include "getdns/getdns.h" 41 | #include "getdns/getdns_extra.h" 42 | #include "types-internal.h" 43 | #include "debug.h" 44 | 45 | #ifdef HAVE_UNBOUND_EVENT_H 46 | # include 47 | #else 48 | struct ub_event_base_vmt; 49 | struct ub_event_base { 50 | unsigned long magic; 51 | struct ub_event_base_vmt* vmt; 52 | }; 53 | # ifndef _UB_EVENT_PRIMITIVES 54 | # define _UB_EVENT_PRIMITIVES 55 | struct ub_ctx* ub_ctx_create_ub_event(struct ub_event_base* base); 56 | typedef void (*ub_event_callback_t)(void*, int, void*, int, int, char*); 57 | int ub_resolve_event(struct ub_ctx* ctx, const char* name, int rrtype, 58 | int rrclass, void* mydata, ub_event_callback_t callback, int* async_id); 59 | # endif 60 | #endif 61 | 62 | typedef struct _getdns_ub_loop { 63 | struct ub_event_base super; 64 | struct mem_funcs mf; 65 | getdns_eventloop *extension; 66 | int running; 67 | #if defined(SCHED_DEBUG) && SCHED_DEBUG 68 | int n_events; 69 | #endif 70 | } _getdns_ub_loop; 71 | 72 | void _getdns_ub_loop_init(_getdns_ub_loop *loop, struct mem_funcs *mf, getdns_eventloop *extension); 73 | 74 | static inline int _getdns_ub_loop_enabled(_getdns_ub_loop *loop) 75 | { return loop->super.vmt ? 1 : 0; } 76 | 77 | #endif /* HAVE_UNBOUND_EVENT_API */ 78 | #endif 79 | /* ub_loop.h */ 80 | -------------------------------------------------------------------------------- /src/list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file list.h 4 | * @brief getdns list management functions 5 | * 6 | * Originally taken from the getdns API description pseudo implementation. 7 | * 8 | */ 9 | 10 | /* 11 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 12 | * All rights reserved. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions are met: 16 | * * Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * * Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * * Neither the names of the copyright holders nor the 22 | * names of its contributors may be used to endorse or promote products 23 | * derived from this software without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef _GETDNS_LIST_H_ 38 | #define _GETDNS_LIST_H_ 39 | 40 | #include "getdns/getdns.h" 41 | #include "types-internal.h" 42 | 43 | #define GETDNS_LIST_BLOCKSZ 10 44 | 45 | /** 46 | * getdns list data type 47 | * Use helper functions getdns_list_* to manipulate and iterate lists 48 | * lists are implemented as arrays internally since the helper functions 49 | * like to reference indexes in the list. Elements are allocated in blocks 50 | * and then marked valid as they are used and invalid as they are not used 51 | * The use cases do not justify working too hard at shrinking the structures. 52 | * Indexes are 0 based. 53 | */ 54 | struct getdns_list 55 | { 56 | size_t numalloc; 57 | size_t numinuse; 58 | struct getdns_item *items; 59 | struct mem_funcs mf; 60 | }; 61 | 62 | static inline getdns_list *_getdns_list_create_with_mf(struct mem_funcs *mf) 63 | { return getdns_list_create_with_extended_memory_functions( 64 | mf->mf_arg, mf->mf.ext.malloc, mf->mf.ext.realloc, mf->mf.ext.free); } 65 | 66 | getdns_return_t _getdns_list_find( 67 | const getdns_list *dict, const char *key, getdns_item **item); 68 | 69 | getdns_return_t _getdns_list_find_and_add( 70 | getdns_list *list, const char *key, getdns_item **item); 71 | 72 | getdns_return_t _getdns_list_remove_name( 73 | getdns_list *list, const char *name); 74 | 75 | #endif 76 | 77 | /* list.h */ 78 | -------------------------------------------------------------------------------- /src/getdns/getdns_ext_libevent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \brief Public interfaces to getdns, include in your application to use getdns API. 4 | * 5 | * This source was taken from the original pseudo-implementation by 6 | * Paul Hoffman. 7 | */ 8 | 9 | /* 10 | * Copyright (c) 2013, NLNet Labs, Verisign, Inc. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * * Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * * Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * * Neither the names of the copyright holders nor the 21 | * names of its contributors may be used to endorse or promote products 22 | * derived from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 28 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef GETDNS_EXT_LIBEVENT_H 37 | #define GETDNS_EXT_LIBEVENT_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include 44 | #include 45 | struct event_base; 46 | 47 | /** 48 | * \ingroup eventloops 49 | */ 50 | /** 51 | * Associate the libevent event_base with the context, so that all 52 | * asynchronous requests will schedule Input/Output with it. 53 | * Synchronous requests will still use a default eventloop based on `poll()`. 54 | * Applications need to @code #include @endcode 55 | * and link with libgetdns_ext_event to use this function. 56 | * getdns needs to have been configured with --with-libevent for this 57 | * extension to be available. 58 | * @param context The context to configure 59 | * @param this_event_base The libevent event base to associate with this context. 60 | * @return GETDNS_RETURN_GOOD when successful 61 | * @return GETDNS_RETURN_BAD_CONTEXT when context is NULL 62 | * @return GETDNS_RETURN_INVALID_PARAMETER when this_event_base is NULL 63 | * @return GETDNS_RETURN_MEMORY_ERROR when memory could not be allocated 64 | */ 65 | getdns_return_t 66 | getdns_extension_set_libevent_base(struct getdns_context *context, 67 | struct event_base *this_event_base); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #endif 73 | -------------------------------------------------------------------------------- /src/anchor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief functions for DNSSEC trust anchor management 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2017, NLnet Labs 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef ANCHOR_H_ 35 | #define ANCHOR_H_ 36 | 37 | #include "getdns/getdns.h" 38 | #include "getdns/getdns_extra.h" 39 | #include 40 | #include "rr-iter.h" 41 | 42 | #include "types-internal.h" 43 | 44 | /** 45 | ** Internal functions, implemented in anchor-internal.c. 46 | **/ 47 | void _getdns_context_equip_with_anchor(getdns_context *context, uint64_t *now_ms); 48 | 49 | uint8_t *_getdns_tas_validate(struct mem_funcs *mf, 50 | const getdns_bindata *xml_bd, const getdns_bindata *p7s_bd, 51 | const getdns_bindata *crt_bd, const char *p7signer, 52 | uint64_t *now_ms, uint8_t *tas, size_t *tas_len); 53 | 54 | 55 | /** 56 | ** anchor.c functions used by anchor-internal.c. 57 | **/ 58 | time_t _getdns_xml_convertdate(const char* str); 59 | 60 | uint16_t _getdns_parse_xml_trust_anchors_buf(gldns_buffer *gbuf, uint64_t *now_ms, char *xml_data, size_t xml_len); 61 | 62 | /** 63 | ** Public interface. 64 | **/ 65 | void _getdns_context_equip_with_anchor(getdns_context *context, uint64_t *now_ms); 66 | 67 | void _getdns_start_fetching_ta( 68 | getdns_context *context, getdns_eventloop *loop, uint64_t *now_ms); 69 | 70 | #define MAX_KSKS 16 71 | #define RRSIG_RDATA_LEN 16 72 | typedef struct _getdns_ksks { 73 | size_t n; 74 | uint16_t ids[MAX_KSKS]; 75 | size_t n_rrsigs; 76 | uint8_t rrsigs[MAX_KSKS][RRSIG_RDATA_LEN]; 77 | } _getdns_ksks; 78 | 79 | void _getdns_context_update_root_ksk( 80 | getdns_context *context, _getdns_rrset *dnskey_set); 81 | 82 | #endif 83 | /* anchor.h */ 84 | -------------------------------------------------------------------------------- /doc/getdns_context_set_context_update_callback.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_context_set_context_update_callback 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_context_set_context_update_callback 32 | -- get informed on getdns context updates 33 | 34 | .SH LIBRARY 35 | DNS Resolver library (libgetdns, \-lgetdns) 36 | 37 | .SH SYNOPSIS 38 | #include 39 | 40 | getdns_return_t 41 | .br 42 | .B getdns_context_set_context_update_callback 43 | (getdns_context ** context, 44 | .RS 3 45 | .br 46 | void (*cbfun)(getdns_context *context, getdns_context_code_t changed_item) 47 | .RE 48 | 49 | .SH DESCRIPTION 50 | 51 | .LP 52 | Changes to the context such as in response to system files that affect the contet (/etc/resolv.conf etc.) trigger a call to the callback function specified as 53 | .B 54 | cbfun 55 | 56 | .HP 3 57 | .I context 58 | a previously initialized context 59 | 60 | .HP 3 61 | .I cbfun 62 | callback function to invoked when the specified context changes. If this 63 | argument is NULL then updates to the context will not invoke a callback. 64 | 65 | .HP 66 | .SH "RETURN VALUES" 67 | 68 | Upon successful completion each of these functions return 69 | .B GETDNS_RETURN_GOOD 70 | , otherwise the following error values are returned: 71 | 72 | .LP 73 | .B GETDNS_RETURN_GENERIC_ERROR 74 | memory allocation failed or some other untoward thing happened 75 | 76 | .LP 77 | .B GETDNS_RETURN_BAD_CONTEXT 78 | if the context pointer is invalid 79 | 80 | .SH EXAMPLES 81 | 82 | TBD 83 | 84 | .SH SEE ALSO 85 | .BR libgetdns (3), 86 | .BR getdns_context_create (3), 87 | .BR getdns_context_set (3), 88 | .BR getdns_context_set_context_update_callback (3), 89 | 90 | -------------------------------------------------------------------------------- /src/test/testscript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2013, Verisign, Inc., NLNet Labs 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # * Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # * Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # * Neither the names of the copyright holders nor the 13 | # names of its contributors may be used to endorse or promote products 14 | # derived from this software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | # DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 20 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | # run $1 > $2 and exit on failure to execute 28 | runit () { 29 | echo -n "Test $1:" 30 | ./$1 > $2 31 | if test $? -ne 0; then 32 | echo " failed (execution failed)" 33 | exit 1 34 | fi 35 | } 36 | 37 | # check output files $1 and $2, exit on failure 38 | diffit () { 39 | if diff $1 $2; then 40 | echo " OK" 41 | else 42 | echo " failed (differences above)" 43 | exit 1 44 | fi 45 | } 46 | 47 | # check output of program $1, known_good must be in $1.good 48 | checkoutput () { 49 | runit $1 output 50 | diffit output $1.good 51 | } 52 | 53 | # filter out TTL and bindata stuff from $1 to $2 54 | filterout () { 55 | sed -e '/"ttl"/d' -e '/"ipv4_address"/d' -e '/"ipv6_address"/d' -e '/"rdata_raw"/d' -e '/$2 56 | } 57 | 58 | # like checkoutput but removes addresses and TTLs and bindata 59 | # this makes the test almost useless, but it tests runtime lookup 60 | # and the structure of the answer format, against the live internet. 61 | checkpacket () { 62 | runit $1 output 63 | cp $1.good output.good 64 | filterout output output2 65 | filterout output.good output2.good 66 | diffit output2 output2.good 67 | } 68 | 69 | echo "./check_getdns" 70 | ./check_getdns 71 | if test $? -ne 0; then 72 | echo " failed (unit test execution failed)" 73 | exit 1 74 | fi 75 | checkoutput tests_dict 76 | checkoutput tests_list 77 | 78 | # the packets are too different to compare for people 79 | #checkpacket tests_stub_async 80 | #checkpacket tests_stub_sync 81 | 82 | runit tests_stub_async output 83 | echo " exitcode-OK" 84 | runit tests_stub_sync output 85 | echo " exitcode-OK" 86 | runit tests_dnssec output 87 | echo " exitcode-OK" 88 | 89 | rm -f output output.good output2 output2.good 90 | exit 0 91 | -------------------------------------------------------------------------------- /src/gnutls/tls-internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file tls-internal.h 4 | * @brief getdns TLS implementation-specific items 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2018-2019, NLnet Labs 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _GETDNS_TLS_INTERNAL_H 35 | #define _GETDNS_TLS_INTERNAL_H 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include "getdns/getdns.h" 44 | 45 | #define SHA_DIGEST_LENGTH 20 46 | #define SHA224_DIGEST_LENGTH 28 47 | #define SHA256_DIGEST_LENGTH 32 48 | #define SHA384_DIGEST_LENGTH 48 49 | #define SHA512_DIGEST_LENGTH 64 50 | 51 | #define GETDNS_TLS_MAX_DIGEST_LENGTH (SHA512_DIGEST_LENGTH) 52 | 53 | #define HAVE_TLS_CTX_CURVES_LIST 0 54 | #define HAVE_TLS_CONN_CURVES_LIST 0 55 | 56 | /* Forward declare type. */ 57 | struct getdns_log_config; 58 | 59 | typedef struct _getdns_tls_context { 60 | struct mem_funcs* mfs; 61 | char* cipher_list; 62 | char* cipher_suites; 63 | char* curve_list; 64 | gnutls_protocol_t min_tls; 65 | gnutls_protocol_t max_tls; 66 | char* ca_trust_file; 67 | char* ca_trust_path; 68 | const struct getdns_log_config* log; 69 | } _getdns_tls_context; 70 | 71 | typedef struct _getdns_tls_connection { 72 | gnutls_session_t tls; 73 | gnutls_certificate_credentials_t cred; 74 | int shutdown; 75 | _getdns_tls_context* ctx; 76 | struct mem_funcs* mfs; 77 | char* cipher_list; 78 | char* cipher_suites; 79 | char* curve_list; 80 | gnutls_protocol_t min_tls; 81 | gnutls_protocol_t max_tls; 82 | dane_query_t dane_query; 83 | dane_state_t dane_state; 84 | char* tlsa; 85 | const struct getdns_log_config* log; 86 | } _getdns_tls_connection; 87 | 88 | typedef struct _getdns_tls_session { 89 | gnutls_datum_t tls; 90 | } _getdns_tls_session; 91 | 92 | typedef struct _getdns_tls_x509 93 | { 94 | gnutls_datum_t tls; 95 | } _getdns_tls_x509; 96 | 97 | #endif /* _GETDNS_TLS_INTERNAL_H */ 98 | -------------------------------------------------------------------------------- /src/util/lruhash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file lruhash.h 4 | * /brief Alternative symbol names for unbound's lruhash.h 5 | * 6 | */ 7 | /* 8 | * Copyright (c) 2017, NLnet Labs, the getdns team 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #ifndef LRUHASH_H_SYMBOLS 34 | #define LRUHASH_H_SYMBOLS 35 | 36 | #define lruhash _getdns_lruhash 37 | #define lruhash_bin _getdns_lruhash_bin 38 | #define lruhash_entry _getdns_lruhash_entry 39 | #define hashvalue_type _getdns_hashvalue_type 40 | #define lruhash_sizefunc_type _getdns_lruhash_sizefunc_type 41 | #define lruhash_compfunc_type _getdns_lruhash_compfunc_type 42 | #define lruhash_delkeyfunc_type _getdns_lruhash_delkeyfunc_type 43 | #define lruhash_deldatafunc_type _getdns_lruhash_deldatafunc_type 44 | #define lruhash_markdelfunc_type _getdns_lruhash_markdelfunc_type 45 | #define lruhash_create _getdns_lruhash_create 46 | #define lruhash_delete _getdns_lruhash_delete 47 | #define lruhash_clear _getdns_lruhash_clear 48 | #define lruhash_insert _getdns_lruhash_insert 49 | #define lruhash_lookup _getdns_lruhash_lookup 50 | #define lru_touch _getdns_lru_touch 51 | #define lruhash_setmarkdel _getdns_lruhash_setmarkdel 52 | 53 | #define lru_demote _getdns_lru_demote 54 | #define lruhash_insert_or_retrieve _getdns_lruhash_insert_or_retrieve 55 | 56 | #define lruhash_remove _getdns_lruhash_remove 57 | #define bin_init _getdns_bin_init 58 | #define bin_delete _getdns_bin_delete 59 | #define bin_find_entry _getdns_bin_find_entry 60 | #define bin_overflow_remove _getdns_bin_overflow_remove 61 | #define bin_split _getdns_bin_split 62 | #define reclaim_space _getdns_reclaim_space 63 | #define table_grow _getdns_table_grow 64 | #define lru_front _getdns_lru_front 65 | #define lru_remove _getdns_lru_remove 66 | #define lruhash_status _getdns_lruhash_status 67 | #define lruhash_get_mem _getdns_lruhash_get_mem 68 | #define lruhash_traverse _getdns_lruhash_traverse 69 | 70 | #include "util/orig-headers/lruhash.h" 71 | #endif 72 | -------------------------------------------------------------------------------- /src/dnssec.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief functions for DNSSEC 4 | * 5 | * The _getdns_get_validation_chain function is called after an answer 6 | * has been fetched when the dnssec_return_validation_chain extension is set. 7 | * It fetches DNSKEYs, DSes and their signatures for all RRSIGs found in the 8 | * answer. 9 | */ 10 | 11 | /* 12 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 13 | * All rights reserved. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions are met: 17 | * * Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * * Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * * Neither the names of the copyright holders nor the 23 | * names of its contributors may be used to endorse or promote products 24 | * derived from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #ifndef DNSSEC_H_ 39 | #define DNSSEC_H_ 40 | 41 | #include "getdns/getdns.h" 42 | #include "config.h" 43 | #include "gldns/gbuffer.h" 44 | #include "gldns/rrdef.h" 45 | #include "types-internal.h" 46 | 47 | /* Do some additional requests to fetch the complete validation chain */ 48 | void _getdns_get_validation_chain(getdns_dns_req *dns_req); 49 | void _getdns_cancel_validation_chain(getdns_dns_req *dns_req); 50 | void _getdns_validation_chain_timeout(getdns_dns_req *dns_req); 51 | void _getdns_ta_notify_dnsreqs(getdns_context *context); 52 | 53 | uint16_t _getdns_parse_ta_file(time_t *ta_mtime, gldns_buffer *gbuf); 54 | 55 | static inline int _dnssec_rdata_to_canonicalize(uint16_t rr_type) 56 | { 57 | return rr_type == GLDNS_RR_TYPE_NS || rr_type == GLDNS_RR_TYPE_MD 58 | || rr_type == GLDNS_RR_TYPE_MF || rr_type == GLDNS_RR_TYPE_CNAME 59 | || rr_type == GLDNS_RR_TYPE_SOA || rr_type == GLDNS_RR_TYPE_MB 60 | || rr_type == GLDNS_RR_TYPE_MG || rr_type == GLDNS_RR_TYPE_MR 61 | || rr_type == GLDNS_RR_TYPE_PTR || rr_type == GLDNS_RR_TYPE_MINFO 62 | || rr_type == GLDNS_RR_TYPE_MX || rr_type == GLDNS_RR_TYPE_RP 63 | || rr_type == GLDNS_RR_TYPE_AFSDB || rr_type == GLDNS_RR_TYPE_RT 64 | || rr_type == GLDNS_RR_TYPE_SIG || rr_type == GLDNS_RR_TYPE_PX 65 | || rr_type == GLDNS_RR_TYPE_NXT || rr_type == GLDNS_RR_TYPE_NAPTR 66 | || rr_type == GLDNS_RR_TYPE_KX || rr_type == GLDNS_RR_TYPE_SRV 67 | || rr_type == GLDNS_RR_TYPE_DNAME || rr_type == GLDNS_RR_TYPE_RRSIG; 68 | } 69 | 70 | int _getdns_bogus(getdns_dns_req *dns_req); 71 | 72 | #endif 73 | 74 | /* dnssec.h */ 75 | -------------------------------------------------------------------------------- /doc/getdns_cancel_callback.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_cancel_callback 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_cancel_callback 32 | -- cancel an outstanding asyn getdns request 33 | 34 | .SH LIBRARY 35 | DNS Resolver library (libgetdns, \-lgetdns) 36 | 37 | .SH SYNOPSIS 38 | #include 39 | 40 | getdns_return_t 41 | .br 42 | .B getdns_cancel_callback 43 | (getdns_context_t context, 44 | .RS 3 45 | .br 46 | getdns_transaction_t *transaction_id) 47 | .RE 48 | 49 | .SH DESCRIPTION 50 | 51 | .LP 52 | To cancel an outstanding callback, use getdns_cancel_callback. This causes the 53 | API to call the callback with a callback_type of GETDNS_CALLBACK_CANCEL if the 54 | callback for this transaction_id has not already been called. The callback code 55 | for cancellation should clean up any memory related to the identified call, 56 | such as to deallocate the memory for the userarg. getdns_cancel_callback() may 57 | return immediately, even before the callback finishes its work and returns. 58 | 59 | .HP 3 60 | .I context 61 | see getdns_context (3) 62 | 63 | .HP 3 64 | .I transaction_id 65 | populated by the API and used to identify the callback (for example to getdns_cancel_callback), can be NULL, set to 0 if the function fails 66 | 67 | .HP 68 | .SH "RETURN VALUES" 69 | 70 | Upon successful completion the functions return 71 | .B GETDNS_RETURN_GOOD 72 | , otherwise the following error values are returned: 73 | 74 | .LP 75 | .B GETDNS_RETURN_INVALID_PARAMETER 76 | if context == NULL 77 | .LP 78 | .B GETDNS_RETURN_UNKNOWN_TRANSACTION 79 | if the transaction_id that is unknown or belongs to a callback that has already been called 80 | 81 | .SH EXAMPLES 82 | 83 | TBD 84 | 85 | .SH FILES 86 | .br 87 | /etc/hosts 88 | .br 89 | /etc/resolv.conf 90 | 91 | .SH SEE ALSO 92 | .BR libgetdns (3), 93 | .BR getdns_context (3), 94 | .BR getdns_general (3), 95 | .BR getdns_hostname (3), 96 | .BR getdns_service (3), 97 | 98 | -------------------------------------------------------------------------------- /doc/getdns_validate_dnssec.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_validate_dnssec 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_validate_dnssec 32 | -- DNSSEC validate a given getdns record 33 | 34 | .SH LIBRARY 35 | DNS Resolver library (libgetdns, \-lgetdns) 36 | 37 | .SH SYNOPSIS 38 | #include 39 | 40 | getdns_return_t 41 | .br 42 | .B getdns_validate_dnssec 43 | (getdns_list *record_to_validate, 44 | .br 45 | .RS 3 46 | getdns_list *bundle_of_support_records, 47 | .br 48 | getdns_list *trust_anchor_records) 49 | .RE 50 | 51 | .SH DESCRIPTION 52 | 53 | .LP 54 | If an application wants the API to perform DNSSEC validation without using the 55 | extensions, it can use the getdns_validate_dnssec() helper function. The API 56 | will use the resource records in bundle_of_support_records to construct the 57 | validation chain and the DNSKEY or DS records in trust_anchor_records as trust 58 | anchors. The default list of trust anchor records that is used by the library 59 | to validate DNSSEC can be retrieved by using the getdns_root_trust_anchor 60 | helper function. 61 | 62 | .HP 3 63 | .I record_to_validate 64 | the resource record being validated 65 | 66 | .HP 3 67 | .I bundle_of_support_records 68 | records used to construct the validation chain 69 | 70 | .HP 3 71 | .I trust_anchor_records 72 | trust anchor records to use for the validation 73 | 74 | .HP 75 | .SH "RETURN VALUES" 76 | 77 | .LP 78 | .B GETDNS_DNSSEC_BOGUS 79 | the DNSSEC signature is bogus 80 | .LP 81 | .B GETDNS_DNSSEC_INDETERMINATE 82 | validation could not be completed 83 | .LP 84 | .B GETDNS_DNSSEC_INSECURE 85 | one or more pieces of the validation chain are demonstrably incorrect 86 | .LP 87 | .B GETDNS_DNSSEC_SECURE 88 | validation succeeded 89 | .LP 90 | .B GETDNS_RETURN_MEMORY_ERROR 91 | an attempt to allocate memory failed 92 | 93 | .SH EXAMPLES 94 | 95 | TBD 96 | 97 | .SH SEE ALSO 98 | .BR getdns_root_trust_anchor (3) 99 | .BR libgetdns (3) 100 | 101 | -------------------------------------------------------------------------------- /cmake/modules/FindGnuTLS.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindGnuTLS 3 | ---------- 4 | 5 | Find the GnuTLS library. 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``GnuTLS::GnuTLS`` 13 | The GnuTLS library, if found. 14 | ``GnuTLS::Dane`` 15 | The GnuTLS DANE library, if found. 16 | 17 | Result variables 18 | ^^^^^^^^^^^^^^^^ 19 | 20 | This module will set the following variables in your project: 21 | 22 | ``GnuTLS_FOUND`` 23 | If false, do not try to use GnuTLS. 24 | ``GNUTLS_INCLUDE_DIR`` 25 | where to find GnuTLS headers. 26 | ``GNUTLS_LIBRARIES`` 27 | the libraries needed to use GnuTLS. 28 | ``GNUTLS_VERSION`` 29 | the version of the GnuTLS library found 30 | 31 | #]=======================================================================] 32 | 33 | find_package(PkgConfig QUIET) 34 | if (PKG_CONFIG_FOUND) 35 | pkg_check_modules(PkgGnuTLS IMPORTED_TARGET GLOBAL QUIET gnutls) 36 | pkg_check_modules(PkgGnuTLSDane IMPORTED_TARGET GLOBAL QUIET gnutls-dane) 37 | endif () 38 | 39 | if (PkgGnuTLS_FOUND AND PkgGnuTLSDane_FOUND) 40 | set(GNUTLS_INCLUDE_DIR ${PkgGnuTLS_INCLUDE_DIRS} $PkgGnuTLSDane_INCLUDE_DIRS} CACHE FILEPATH "GnuTLS include path") 41 | set(NETTLE_LIBRARIES ${PkgGnuTLS_LIBRARIES} ${PkgGnuTLSDane_LIBRARIES} CACHE STRING "GnuTLS libraries") 42 | set(NETTLE_VERSION ${PkgGnuTLS_VERSION}) 43 | add_library(GnuTLS::GnuTLS ALIAS PkgConfig::PkgGnuTLS) 44 | add_library(GnuTLS::Dane ALIAS PkgConfig::PkgGnuTLSDane) 45 | set(GnuTLS_FOUND ON) 46 | else () 47 | find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h 48 | HINTS 49 | "${GNUTLS_DIR}" 50 | "${GNUTLS_DIR}/include" 51 | ) 52 | 53 | find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls 54 | HINTS 55 | "${GNUTLS_DIR}" 56 | "${GNUTLS_DIR}/lib" 57 | ) 58 | 59 | find_library(GNUTLS_DANE_LIBRARY NAMES gnutls-dane libgnutls-dane 60 | HINTS 61 | "${GNUTLS_DIR}" 62 | "${GNUTLS_DIR}/lib" 63 | ) 64 | 65 | set(_GNUTLS_LIBRARIES "") 66 | 67 | if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY AND GNUTLS_DANE_LIBRARY) 68 | if (NOT TARGET GnuTLS::GnuTLS) 69 | add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED) 70 | set_target_properties(GnuTLS::GnuTLS PROPERTIES 71 | INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIR}" 72 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 73 | IMPORTED_LOCATION "${GNUTLS_LIBRARY}" 74 | ) 75 | endif () 76 | if (NOT TARGET GnuTLS::Dane) 77 | add_library(GnuTLS::Dane UNKNOWN IMPORTED) 78 | set_target_properties(GnuTLS::Dane PROPERTIES 79 | INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIR}" 80 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 81 | IMPORTED_LOCATION "${GNUTLS_DANE_LIBRARY}" 82 | ) 83 | endif () 84 | 85 | if (NOT GNUTLS_VERSION AND GNUTLS_INCLUDE_DIR) 86 | file(STRINGS "${GNUTLS_INCLUDE_DIR}/gnutls/gnutls.h" GNUTLS_VER_H REGEX "^#define GNUTLS_VERSION_(MAJOR|MINOR|PATCH) ") 87 | string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3c" GNUTLS_VERSION "${GNUTLS_VER_H}") 88 | endif () 89 | endif () 90 | 91 | list(APPEND _GNUTLS_LIBRARIES "${GNUTLS_LIBRARY}" "${GNUTLS_DANE_LIBRARY}") 92 | set(GNUTLS_LIBRARIES ${_GNUTLS_LIBRARIES} CACHE STRING "GnuTLS libraries") 93 | 94 | include(FindPackageHandleStandardArgs) 95 | find_package_handle_standard_args(GnuTLS 96 | REQUIRED_VARS GNUTLS_LIBRARIES GNUTLS_INCLUDE_DIR 97 | VERSION_VAR GNUTLS_VERSION 98 | ) 99 | endif () 100 | 101 | mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARIES GNUTLS_LIBRARY GNUTLS_DANE_LIBRARY) 102 | -------------------------------------------------------------------------------- /src/openssl/pubkey-pinning-internal.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * /brief functions for Public Key Pinning 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2015, Daniel Kahn Gillmor 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * * Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the names of the copyright holders nor the 19 | * names of its contributors may be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /** 35 | * getdns Public Key Pinning 36 | * 37 | * a public key pinset is a list of dicts. each dict should have a 38 | * "digest" and a "value". 39 | * 40 | * "digest": a string indicating the type of digest. at the moment, we 41 | * only support a "digest" of "sha256". 42 | * 43 | * "value": a binary representation of the digest provided. 44 | * 45 | * given a such a pinset, we should be able to validate a chain 46 | * properly according to section 2.6 of RFC 7469. 47 | */ 48 | #include "config.h" 49 | #include "debug.h" 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include "context.h" 57 | #include "util-internal.h" 58 | 59 | #include "pubkey-pinning-internal.h" 60 | 61 | /* we only support sha256 at the moment. adding support for another 62 | digest is more complex than just adding another entry here. in 63 | particular, you'll probably need a match for a particular cert 64 | against all supported algorithms. better to wait on doing that 65 | until it is a better-understood problem (i.e. wait until hpkp is 66 | updated and follow the guidance in rfc7469bis) 67 | */ 68 | 69 | /* b64 turns every 3 octets (or fraction thereof) into 4 octets */ 70 | #define B64_ENCODED_SHA256_LENGTH (((SHA256_DIGEST_LENGTH + 2)/3) * 4) 71 | getdns_return_t _getdns_decode_base64(const char* str, uint8_t* res, size_t res_size) 72 | { 73 | BIO *bio = NULL; 74 | char inbuf[B64_ENCODED_SHA256_LENGTH + 1]; 75 | getdns_return_t ret = GETDNS_RETURN_GOOD; 76 | 77 | /* openssl needs a trailing newline to base64 decode */ 78 | memcpy(inbuf, str, B64_ENCODED_SHA256_LENGTH); 79 | inbuf[B64_ENCODED_SHA256_LENGTH] = '\n'; 80 | 81 | bio = BIO_push(BIO_new(BIO_f_base64()), 82 | BIO_new_mem_buf(inbuf, sizeof(inbuf))); 83 | if (BIO_read(bio, res, res_size) != (int) res_size) 84 | ret = GETDNS_RETURN_GENERIC_ERROR; 85 | 86 | BIO_free_all(bio); 87 | return ret; 88 | } 89 | 90 | /* pubkey-pinning.c */ 91 | -------------------------------------------------------------------------------- /cmake/modules/FindCheck.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindCheck 3 | -------- 4 | 5 | Find the Check (Unit Testing Framework for C) library 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Check::Check`` 13 | The Check library, if found. 14 | 15 | Result variables 16 | ^^^^^^^^^^^^^^^^ 17 | 18 | This module will set the following variables in your project: 19 | 20 | ``Check_FOUND`` 21 | If false, do not try to use Check. 22 | ``CHECK_INCLUDE_DIR`` 23 | where to find check.h, etc. 24 | ``CHECK_LIBRARIES`` 25 | the libraries needed to use Check. 26 | ``CHECK_VERSION`` 27 | the version of the Check library found 28 | 29 | #]=======================================================================] 30 | 31 | find_package(PkgConfig QUIET) 32 | if (PKG_CONFIG_FOUND) 33 | pkg_check_modules(PkgCheck IMPORTED_TARGET GLOBAL check) 34 | endif () 35 | 36 | if (PkgCheck_FOUND) 37 | set(CHECK_INCLUDE_DIR ${PkgCheck_INCLUDE_DIRS} CACHE FILEPATH "check include path") 38 | set(CHECK_LIBRARIES ${PkgCheck_LIBRARIES} CACHE STRING "check libraries") 39 | set(CHECK_VERSION ${PkgCheck_VERSION}) 40 | add_library(Check::Check ALIAS PkgConfig::PkgCheck) 41 | set(Check_FOUND ON) 42 | else () 43 | find_path(CHECK_INCLUDE_DIR check.h 44 | HINTS 45 | "${CHECK_DIR}" 46 | "${CHECK_DIR}/include" 47 | ) 48 | 49 | # Check for PIC and non-PIC libraries. If PIC present, use that 50 | # in preference (as per Debian check.pc). 51 | find_library(CHECK_LIBRARY NAMES check_pic libcheck_pic 52 | HINTS 53 | "${CHECK_DIR}" 54 | "${CHECK_DIR}/lib" 55 | ) 56 | 57 | if (NOT CHECK_LIBRARY) 58 | find_library(CHECK_LIBRARY NAMES check libcheck 59 | HINTS 60 | "${CHECK_DIR}" 61 | "${CHECK_DIR}/lib" 62 | ) 63 | endif () 64 | 65 | set(_CHECK_LIBARIES "") 66 | 67 | # Check may need the math, subunit and rt libraries on Unix 68 | if (UNIX) 69 | find_library(CHECK_MATH_LIBRARY m) 70 | find_library(CHECK_RT_LIBRARY rt) 71 | find_library(CHECK_SUBUNIT_LIBRARY subunit) 72 | 73 | if (CHECK_MATH_LIBRARY) 74 | list(APPEND _CHECK_LIBARIES "${CHECK_MATH_LIBRARY}") 75 | endif () 76 | if (CHECK_RT_LIBRARY) 77 | list(APPEND _CHECK_LIBARIES "${CHECK_RT_LIBRARY}") 78 | endif () 79 | if (CHECK_SUBUNIT_LIBRARY) 80 | list(APPEND _CHECK_LIBARIES "${CHECK_SUBUNIT_LIBRARY}") 81 | endif () 82 | endif() 83 | 84 | set(CHECK_LIBRARIES ${_CHECK_LIBARIES} ${CHECK_LIBRARY} CACHE STRING "check libraries") 85 | 86 | if (CHECK_INCLUDE_DIR AND CHECK_LIBRARY) 87 | if (NOT TARGET Check::Check) 88 | add_library(Check::Check UNKNOWN IMPORTED) 89 | set_target_properties(Check::Check PROPERTIES 90 | INTERFACE_INCLUDE_DIRECTORIES "${CHECK_INCLUDE_DIR}" 91 | INTERFACE_LINK_LIBRARIES "${CHECK_LIBRARIES}" 92 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 93 | IMPORTED_LOCATION "${CHECK_LIBRARY}" 94 | ) 95 | endif () 96 | 97 | if (NOT CHECK_VERSION AND CHECK_INCLUDE_DIR AND EXISTS "${CHECK_INCLUDE_DIR}/check.h") 98 | file(STRINGS "${CHECK_INCLUDE_DIR}/check.h" CHECK_H REGEX "^#define CHECK_M[A-Z]+_VERSION") 99 | string(REGEX REPLACE "^.*\(([0-9]+)\).*\(([0-9]+)\).*\(([0-9]+)\).*$" "\\1.\\2.\\3" CHECK_VERSION "${CHECK_H}") 100 | endif () 101 | endif() 102 | 103 | list(APPEND CHECK_LIBRARIES "${CHECK_LIBRARY}") 104 | 105 | include(FindPackageHandleStandardArgs) 106 | find_package_handle_standard_args(Check 107 | REQUIRED_VARS CHECK_LIBRARIES CHECK_INCLUDE_DIR 108 | VERSION_VAR CHECK_VERSION 109 | ) 110 | 111 | endif() 112 | 113 | mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARIES CHECK_LIBRARY 114 | CHECK_MATH_LIBRARY CHECK_RT_LIBRARY CHECK_SUBUNIT_LIBRARY) 115 | -------------------------------------------------------------------------------- /src/general.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file general.h 4 | * @brief getdns_general and related support functions 5 | * 6 | * This is the meat of the API 7 | * Originally taken from the getdns API description pseudo implementation. 8 | * 9 | */ 10 | /* 11 | * Copyright (c) 2013, NLnet Labs, Verisign, Inc. 12 | * All rights reserved. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions are met: 16 | * * Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * * Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * * Neither the names of the copyright holders nor the 22 | * names of its contributors may be used to endorse or promote products 23 | * derived from this software without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef _GETDNS_GENERAL_H_ 38 | #define _GETDNS_GENERAL_H_ 39 | 40 | #include "getdns/getdns.h" 41 | #include "types-internal.h" 42 | 43 | /* private inner helper used by sync and async */ 44 | 45 | #define DNS_REQ_FINISHED -1 46 | 47 | void _getdns_call_user_callback(getdns_dns_req *, getdns_dict *); 48 | 49 | /* Change state of the netreq req. 50 | * - Increments context->netreqs_in_flight 51 | * when state changes from NOT_SENT to IN_FLIGHT 52 | * - Decrements context->netreqs_in_flight 53 | * when state changes from IN_FLIGHT to FINISHED, TIMED_OUT or ERRORED 54 | * - Resubmits NOT_SENT netreqs from context->pending_netreqs, 55 | * when # pending_netreqs < limit_outstanding_queries 56 | */ 57 | void _getdns_netreq_change_state( 58 | getdns_network_req *netreq, network_req_state new_state); 59 | 60 | void _getdns_check_dns_req_complete(getdns_dns_req *dns_req); 61 | int _getdns_submit_netreq(getdns_network_req *netreq, uint64_t *now_ms); 62 | 63 | 64 | getdns_return_t 65 | _getdns_general_loop(getdns_context *context, getdns_eventloop *loop, 66 | const char *name, uint16_t request_type, const getdns_dict *extensions, 67 | void *userarg, getdns_network_req **netreq_p, 68 | getdns_callback_t callbackfn, internal_cb_t internal_cb); 69 | 70 | getdns_return_t 71 | _getdns_address_loop(getdns_context *context, getdns_eventloop *loop, 72 | const char *name, const getdns_dict *extensions, 73 | void *userarg, getdns_transaction_t *transaction_id, 74 | getdns_callback_t callbackfn); 75 | 76 | getdns_return_t 77 | _getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, 78 | const getdns_dict *address, const getdns_dict *extensions, 79 | void *userarg, getdns_transaction_t *transaction_id, 80 | getdns_callback_t callbackfn); 81 | 82 | getdns_return_t 83 | _getdns_service_loop(getdns_context *context, getdns_eventloop *loop, 84 | const char *name, const getdns_dict *extensions, 85 | void *userarg, getdns_transaction_t *transaction_id, 86 | getdns_callback_t callbackfn); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /cmake/modules/FindLibunbound.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindLibunbound 3 | -------------- 4 | 5 | Find the Libunbound library 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Libunbound::Libunbound`` 13 | The Libunbound library, if found. 14 | 15 | Result variables 16 | ^^^^^^^^^^^^^^^^ 17 | 18 | This module will set the following variables in your project: 19 | 20 | ``Libunbound_FOUND`` 21 | If false, do not try to use Libunbound. 22 | ``LIBUNBOUND_INCLUDE_DIR`` 23 | where to find libunbound headers. 24 | ``LIBUNBOUND_LIBRARIES`` 25 | the libraries needed to use Libunbound. 26 | ``LIBUNBOUND_VERSION`` 27 | the version of the Libunbound library found 28 | 29 | #]=======================================================================] 30 | 31 | find_package(PkgConfig QUIET) 32 | if (PKG_CONFIG_FOUND) 33 | pkg_check_modules(PkgLibunbound IMPORTED_TARGET GLOBAL QUIET libunbound) 34 | endif () 35 | 36 | if (PkgLibunbound_FOUND) 37 | set(LIBUNBOUND_INCLUDE_DIR ${PkgLibunbound_INCLUDE_DIRS} CACHE FILEPATH "libunbound include path") 38 | set(LIBUNBOUND_LIBRARIES ${PkgLibunbound_LIBRARIES} CACHE STRING "libunbound libraries") 39 | set(LIBUNBOUND_VERSION ${PkgLibunbound_VERSION}) 40 | add_library(Libunbound::Libunbound ALIAS PkgConfig::PkgLibunbound) 41 | set(Libunbound_FOUND ON) 42 | else () 43 | find_path(LIBUNBOUND_INCLUDE_DIR unbound.h 44 | HINTS 45 | "${LIBUNBOUND_DIR}" 46 | "${LIBUNBOUND_DIR}/include" 47 | ) 48 | 49 | find_library(LIBUNBOUND_LIBRARY NAMES unbound 50 | HINTS 51 | "${LIBUNBOUND_DIR}" 52 | "${LIBUNBOUND_DIR}/lib" 53 | ) 54 | 55 | set(_LIBUNBOUND_LIBRARIES "") 56 | 57 | if (UNIX) 58 | find_package(Threads REQUIRED) 59 | find_package(OpenSSL REQUIRED) 60 | 61 | list(APPEND _LIBUNBOUND_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") 62 | list(APPEND _LIBUNBOUND_LIBRARIES "${OPENSSL_LIBRARIES}") 63 | endif() 64 | 65 | if (LIBUNBOUND_INCLUDE_DIR AND LIBUNBOUND_LIBRARY) 66 | if (NOT TARGET Libunbound::Libunbound) 67 | add_library(Libunbound::Libunbound UNKNOWN IMPORTED) 68 | set_target_properties(Libunbound::Libunbound PROPERTIES 69 | INTERFACE_INCLUDE_DIRECTORIES "${LIBUNBOUND_INCLUDE_DIR}" 70 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 71 | IMPORTED_LOCATION "${LIBUNBOUND_LIBRARY}" 72 | ) 73 | 74 | if(UNIX AND TARGET Threads::Threads) 75 | set_property(TARGET Libunbound::Libunbound APPEND PROPERTY 76 | INTERFACE_LINK_LIBRARIES Threads::Threads) 77 | endif () 78 | if(UNIX AND TARGET OpenSSL::SSL) 79 | set_property(TARGET Libunbound::Libunbound APPEND PROPERTY 80 | INTERFACE_LINK_LIBRARIES OpenSSL::SSL) 81 | endif () 82 | if(UNIX AND TARGET OpenSSL::Crypto) 83 | set_property(TARGET Libunbound::Libunbound APPEND PROPERTY 84 | INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) 85 | endif () 86 | endif () 87 | 88 | if (NOT LIBUNBOUND_VERSION AND LIBUNBOUND_INCLUDE_DIR AND EXISTS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h") 89 | file(STRINGS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h" LIBUNBOUND_H REGEX "^#define UNBOUND_VERSION_M[A-Z]+") 90 | string(REGEX REPLACE "^.*MAJOR ([0-9]+).*MINOR ([0-9]+).*MICRO ([0-9]+).*$" "\\1.\\2.\\3" LIBUNBOUND_VERSION "${LIBUNBOUND_H}") 91 | endif () 92 | endif () 93 | 94 | list(APPEND _LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}") 95 | set(LIBUNBOUND_LIBRARIES ${_LIBUNBOUND_LIBRARIES} CACHE STRING "libunbound libraries") 96 | 97 | include(FindPackageHandleStandardArgs) 98 | find_package_handle_standard_args(Libunbound 99 | REQUIRED_VARS LIBUNBOUND_LIBRARIES LIBUNBOUND_INCLUDE_DIR 100 | VERSION_VAR LIBUNBOUND_VERSION 101 | ) 102 | endif () 103 | 104 | mark_as_advanced(LIBUNBOUND_INCLUDE_DIR LIBUNBOUND_LIBRARIES LIBUNBOUND_LIBRARY) 105 | -------------------------------------------------------------------------------- /cmake/modules/FindNettle.cmake: -------------------------------------------------------------------------------- 1 | #[=======================================================================[.rst: 2 | FindNettle 3 | ---------- 4 | 5 | Find the Nettle library. 6 | 7 | Imported targets 8 | ^^^^^^^^^^^^^^^^ 9 | 10 | This module defines the following :prop_tgt:`IMPORTED` targets: 11 | 12 | ``Nettle::Nettle`` 13 | The Nettle library, if found. 14 | ``Nettle::Hogweed`` 15 | The Hogweed library, if found. 16 | 17 | Result variables 18 | ^^^^^^^^^^^^^^^^ 19 | 20 | This module will set the following variables in your project: 21 | 22 | ``Nettle_FOUND`` 23 | If false, do not try to use Nettle. 24 | ``NETTLE_INCLUDE_DIR`` 25 | where to find Nettle headers. 26 | ``NETTLE_LIBRARIES`` 27 | the libraries needed to use Nettle. 28 | ``NETTLE_VERSION`` 29 | the version of the Nettle library found 30 | 31 | #]=======================================================================] 32 | 33 | find_package(PkgConfig QUIET) 34 | if(PKG_CONFIG_FOUND) 35 | pkg_check_modules(PkgNettle IMPORTED_TARGET GLOBAL nettle) 36 | pkg_check_modules(PkgHogweed IMPORTED_TARGET GLOBAL QUIET hogweed) 37 | endif() 38 | 39 | if(PkgNettle_FOUND AND PkHogweed_FOUND) 40 | set(NETTLE_INCLUDE_DIR ${PkgNettle_INCLUDE_DIRS} ${PkgHogweed_INCLUDE_DIRS} CACHE FILEPATH "Nettle include path") 41 | set(NETTLE_LIBRARIES ${PkgNettle_LIBRARIES} ${PkgHogweed_LIBRARIES} CACHE STRING "Nettle libraries") 42 | set(NETTLE_VERSION ${PkgNettle_VERSION}) 43 | add_library(Nettle::Nettle ALIAS PkgConfig::PkgNettle) 44 | add_library(Nettle::Hogweed ALIAS PkgConfig::PkgHogweed) 45 | set(Nettle_FOUND ON) 46 | else() 47 | find_path(NETTLE_INCLUDE_DIR nettle/version.h 48 | HINTS 49 | "${NETTLE_DIR}" 50 | "${NETTLE_DIR}/include" 51 | ) 52 | 53 | find_library(NETTLE_LIBRARY NAMES nettle libnettle 54 | HINTS 55 | "${NETTLE_DIR}" 56 | "${NETTLE_DIR}/lib" 57 | ) 58 | 59 | find_library(HOGWEED_LIBRARY NAMES hogweed libhogweed 60 | HINTS 61 | "${NETTLE_DIR}" 62 | "${NETTLE_DIR}/lib" 63 | ) 64 | 65 | set(_NETTLE_LIBRARIES ${NETTLE_LIBRARY} ${HOGWEED_LIBRARY}) 66 | 67 | # May need gmp library on Unix. 68 | if (UNIX) 69 | find_library(NETTLE_GMP_LIBRARY gmp) 70 | endif () 71 | if (NETTLE_GMP_LIBRARY) 72 | list(APPEND _NETTLE_LIBRARIES "${NETTLE_GMP_LIBRARY}") 73 | endif () 74 | set(NETTLE_LIBRARIES ${_NETTLE_LIBRARIES} CACHE STRING "nettle libraries") 75 | 76 | 77 | if (NETTLE_INCLUDE_DIR AND NETTLE_LIBRARY AND HOGWEED_LIBRARY) 78 | if (NOT TARGET Nettle::Nettle) 79 | add_library(Nettle::Nettle UNKNOWN IMPORTED) 80 | set_target_properties(Nettle::Nettle PROPERTIES 81 | INTERFACE_INCLUDE_DIRECTORIES "${NETTLE_INCLUDE_DIR}" 82 | INTERFACE_LINK_LIBRARIES "${NETTLE_LIBRARIES}" 83 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 84 | IMPORTED_LOCATION "${NETTLE_LIBRARY}" 85 | ) 86 | endif () 87 | if (NOT TARGET Nettle::Hogweed) 88 | add_library(Nettle::Hogweed UNKNOWN IMPORTED) 89 | set_target_properties(Nettle::Hogweed PROPERTIES 90 | INTERFACE_INCLUDE_DIRECTORIES "${NETTLE_INCLUDE_DIR}" 91 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 92 | IMPORTED_LOCATION "${HOGWEED_LIBRARY}" 93 | ) 94 | endif () 95 | 96 | if (NOT NETTLE_VERSION AND NETTLE_INCLUDE_DIR) 97 | file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" NETTLE_VER_H REGEX "^#define NETTLE_VERSION_(MAJOR|MINOR) ") 98 | string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*$" "\\1.\\2" NETTLE_VERSION "${NETTLE_VER_H}") 99 | endif () 100 | endif() 101 | 102 | list(APPEND NETTLE_LIBRARIES "${NETTLE_LIBRARY}" "${HOGWEED_LIBRARY}") 103 | 104 | include(FindPackageHandleStandardArgs) 105 | find_package_handle_standard_args(Nettle 106 | REQUIRED_VARS NETTLE_LIBRARIES NETTLE_INCLUDE_DIR 107 | VERSION_VAR NETTLE_VERSION 108 | ) 109 | endif() 110 | 111 | mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARIES NETTLE_LIBRARY HOGWEED_LIBRARY NETTLE_GMP_LIBRARY) 112 | -------------------------------------------------------------------------------- /src/compat/arc4_lock.c: -------------------------------------------------------------------------------- 1 | /* arc4_lock.c - global lock for arc4random 2 | * 3 | * Copyright (c) 2014, NLnet Labs. All rights reserved. 4 | * 5 | * This software is open source. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 14 | * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 18 | * Neither the name of the NLNET LABS nor the names of its contributors may 19 | * be used to endorse or promote products derived from this software without 20 | * specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | #include "config.h" 35 | #define LOCKRET(func) func 36 | 37 | #ifdef HAVE_PTHREAD 38 | #include "pthread.h" 39 | 40 | static pthread_mutex_t arc_lock = PTHREAD_MUTEX_INITIALIZER; 41 | 42 | void _ARC4_LOCK(void) 43 | { 44 | pthread_mutex_lock(&arc_lock); 45 | } 46 | 47 | void _ARC4_UNLOCK(void) 48 | { 49 | pthread_mutex_unlock(&arc_lock); 50 | } 51 | #elif defined(GETDNS_ON_WINDOWS) 52 | /* 53 | * There is no explicit arc4random_init call, and thus 54 | * the critical section must be allocated on the first call to 55 | * ARC4_LOCK(). The interlocked test is used to verify that 56 | * the critical section will be allocated only once. 57 | * 58 | * The work around is for the main program to call arc4random() 59 | * at the beginning of execution, before spinning new threads. 60 | * 61 | * There is also no explicit arc4random_close call, and thus 62 | * the critical section is never deleted. It will remain allocated 63 | * as long as the program runs. 64 | */ 65 | static CRITICAL_SECTION arc_critical_section; 66 | static volatile long arc_critical_section_initialized = 0; 67 | 68 | void _ARC4_LOCK(void) 69 | { 70 | long r = InterlockedCompareExchange(&arc_critical_section_initialized, 1, 0); 71 | 72 | if (r != 2) 73 | { 74 | if (r == 0) 75 | { 76 | InitializeCriticalSection(&arc_critical_section); 77 | arc_critical_section_initialized = 2; 78 | } 79 | else if (r == 1) 80 | { 81 | /* 82 | * If the critical section is initialized, the first test 83 | * will return the value 2. 84 | * 85 | * If several threads try to initialize the arc4random 86 | * state "at the same time", the first one will find 87 | * the "initialized" variable at 0, the other ones at 1. 88 | * 89 | * Since this is a fairly rare event, we resolve it with a 90 | * simple active wait loop. 91 | */ 92 | 93 | while (arc_critical_section_initialized != 2) 94 | { 95 | Sleep(1); 96 | } 97 | } 98 | } 99 | 100 | EnterCriticalSection(&arc_critical_section); 101 | } 102 | 103 | void _ARC4_UNLOCK(void) 104 | { 105 | LeaveCriticalSection(&arc_critical_section); 106 | } 107 | 108 | #else 109 | /* XXX - add non pthread specific lock routines here */ 110 | void _ARC4_LOCK(void) 111 | { 112 | } 113 | 114 | void _ARC4_UNLOCK(void) 115 | { 116 | } 117 | #endif 118 | -------------------------------------------------------------------------------- /spec/example/example-simple-answers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* Set up the callback function, which will also do the processing of the results */ 7 | void callback(getdns_context *context, 8 | getdns_callback_type_t callback_type, 9 | getdns_dict *response, 10 | void *userarg, 11 | getdns_transaction_t transaction_id) 12 | { 13 | getdns_return_t r; /* Holder for all function returns */ 14 | uint32_t status; 15 | getdns_bindata *address_data; 16 | char *first = NULL, *second = NULL; 17 | 18 | (void) context; /* unused parameter */ 19 | 20 | printf( "Callback for query \"%s\" with request ID %"PRIu64".\n" 21 | , (char *)userarg, transaction_id ); 22 | 23 | switch(callback_type) { 24 | case GETDNS_CALLBACK_CANCEL: 25 | printf("Transaction with ID %"PRIu64" was cancelled.\n", transaction_id); 26 | return; 27 | case GETDNS_CALLBACK_TIMEOUT: 28 | printf("Transaction with ID %"PRIu64" timed out.\n", transaction_id); 29 | return; 30 | case GETDNS_CALLBACK_ERROR: 31 | printf("An error occurred for transaction ID %"PRIu64".\n", transaction_id); 32 | return; 33 | default: break; 34 | } 35 | assert( callback_type == GETDNS_CALLBACK_COMPLETE ); 36 | 37 | if ((r = getdns_dict_get_int(response, "status", &status))) 38 | fprintf(stderr, "Could not get \"status\" from response"); 39 | 40 | else if (status != GETDNS_RESPSTATUS_GOOD) 41 | fprintf(stderr, "The search had no results, and a return value of %"PRIu32".\n", status); 42 | 43 | else if ((r = getdns_dict_get_bindata(response, "/just_address_answers/0/address_data", &address_data))) 44 | fprintf(stderr, "Could not get first address"); 45 | 46 | else if (!(first = getdns_display_ip_address(address_data))) 47 | fprintf(stderr, "Could not convert first address to string\n"); 48 | 49 | else if ((r = getdns_dict_get_bindata(response, "/just_address_answers/1/address_data", &address_data))) 50 | fprintf(stderr, "Could not get second address"); 51 | 52 | else if (!(second = getdns_display_ip_address(address_data))) 53 | fprintf(stderr, "Could not convert second address to string\n"); 54 | 55 | if (first) { 56 | printf("The address is %s\n", first); 57 | free(first); 58 | } 59 | if (second) { 60 | printf("The address is %s\n", second); 61 | free(second); 62 | } 63 | if (r) { 64 | assert( r != GETDNS_RETURN_GOOD ); 65 | fprintf(stderr, ": %d\n", r); 66 | } 67 | getdns_dict_destroy(response); 68 | } 69 | 70 | int main() 71 | { 72 | getdns_return_t r; /* Holder for all function returns */ 73 | getdns_context *context = NULL; 74 | struct event_base *event_base = NULL; 75 | getdns_dict *extensions = NULL; 76 | char *query_name = "www.example.com"; 77 | /* Could add things here to help identify this call */ 78 | char *userarg = query_name; 79 | getdns_transaction_t transaction_id; 80 | 81 | if ((r = getdns_context_create(&context, 1))) 82 | fprintf(stderr, "Trying to create the context failed"); 83 | 84 | else if (!(event_base = event_base_new())) 85 | fprintf(stderr, "Trying to create the event base failed.\n"); 86 | 87 | else if ((r = getdns_extension_set_libevent_base(context, event_base))) 88 | fprintf(stderr, "Setting the event base failed"); 89 | 90 | else if ((r = getdns_address( context, query_name, extensions 91 | , userarg, &transaction_id, callback))) 92 | fprintf(stderr, "Error scheduling asynchronous request"); 93 | 94 | else { 95 | printf("Request with transaction ID %"PRIu64" scheduled.\n", transaction_id); 96 | if (event_base_dispatch(event_base) < 0) 97 | fprintf(stderr, "Error dispatching events\n"); 98 | } 99 | 100 | /* Clean up */ 101 | if (event_base) 102 | event_base_free(event_base); 103 | 104 | if (context) 105 | getdns_context_destroy(context); 106 | 107 | /* Assuming we get here, leave gracefully */ 108 | exit(EXIT_SUCCESS); 109 | } 110 | -------------------------------------------------------------------------------- /src/mdns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Functions for MDNS resolving. 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2016 Christian Huitema 7 | * 8 | * Permission to use, copy, modify, and distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice appear in all copies. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | 21 | #ifndef MDNS_H 22 | #define MDNS_H 23 | 24 | #ifdef HAVE_MDNS_SUPPORT 25 | #include "getdns/getdns.h" 26 | #include "types-internal.h" 27 | #include "util-internal.h" 28 | #include "platform.h" 29 | #include "util/lruhash.h" 30 | #include "config.h" 31 | 32 | getdns_return_t 33 | _getdns_submit_mdns_request(getdns_network_req *netreq); 34 | 35 | getdns_return_t 36 | _getdns_mdns_namespace_check(getdns_dns_req *dnsreq); 37 | 38 | /* 39 | * data structure for continuous queries 40 | */ 41 | 42 | typedef struct getdns_mdns_known_record 43 | { 44 | /* For storage in context->mdns_known_records_by_value */ 45 | _getdns_rbnode_t node; 46 | uint64_t insertion_microsec; 47 | uint16_t record_type; 48 | uint16_t record_class; 49 | uint32_t ttl; 50 | int name_len; 51 | int record_data_len; 52 | uint8_t* name; 53 | uint8_t * record_data; 54 | } getdns_mdns_known_record; 55 | 56 | /* 57 | * Each entry in the hash table is keyed by type, class and name. 58 | * The key structure also contains the LRU hash entry structure. 59 | * The data part contains: 60 | * - 64 bit time stamp 61 | * - 32 bit word describing the record size 62 | * - 32 bit word describing the allocated memory size 63 | * - valid DNS response, including 1 query and N answers, 0 AUTH, 0 AD. 64 | * For economy, the names of all answers are encoded using header compression, pointing 65 | * to the name in the query, i.e. offset 12 from beginning of message. 66 | * For stability, the names included in the data part of records are not compressed. 67 | */ 68 | 69 | typedef struct getdns_mdns_cached_key_header 70 | { 71 | /* embedded entry, for LRU hash */ 72 | struct lruhash_entry entry; 73 | /* identification */ 74 | uint16_t record_type; 75 | uint16_t record_class; 76 | int name_len; 77 | /* the octets following this structure contain the name */ 78 | } getdns_mdns_cached_key_header; 79 | 80 | typedef struct getdns_mdns_cached_record_header 81 | { 82 | uint64_t insertion_microsec; 83 | uint32_t content_len; 84 | uint32_t allocated_length; 85 | /* list of user queries */ 86 | getdns_network_req *netreq_first; 87 | } getdns_mdns_cached_record_header; 88 | 89 | typedef struct getdns_mdns_continuous_query 90 | { 91 | /* For storage in context->mdns_continuous_queries_by_name_rrtype */ 92 | _getdns_rbnode_t node; 93 | uint8_t name[256]; /* binary representation of name being queried */ 94 | int name_len; 95 | uint16_t request_class; 96 | uint16_t request_type; 97 | /* list of user queries */ 98 | getdns_network_req *netreq_first; 99 | /* todo: do we need an expiration date, or a timer? */ 100 | /* todo: do we need an update mark for showing last results? */ 101 | } getdns_mdns_continuous_query; 102 | 103 | typedef struct mdns_network_connection 104 | { 105 | struct getdns_context* context; 106 | int fd; 107 | int addr_mcast_len; 108 | SOCKADDR_STORAGE addr_mcast; 109 | getdns_eventloop_event event; 110 | uint8_t response[1500]; 111 | } mdns_network_connection; 112 | 113 | 114 | void _getdns_mdns_context_init(struct getdns_context *context); 115 | void _getdns_mdns_context_destroy(struct getdns_context *context); 116 | 117 | #endif /* HAVE_MDNS_SUPPORT */ 118 | 119 | #endif /* MDNS_H */ 120 | -------------------------------------------------------------------------------- /doc/getdns_dict_set.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLNet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_dict_set 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_dict_set, 32 | .B getdns_dict_set_bindata, 33 | .B getdns_dict_set_dict, 34 | .B getdns_dict_set_int, 35 | .B getdns_dict_set_list, 36 | -- set a value by name in a getdns dict 37 | 38 | .SH LIBRARY 39 | DNS Resolver library (libgetdns, \-lgetdns) 40 | 41 | .SH SYNOPSIS 42 | #include 43 | 44 | getdns_return_t 45 | .br 46 | .B getdns_dict_set_bindata 47 | (getdns_dict *this_dict, 48 | .RS 3 49 | char *name, 50 | .br 51 | getdns_bindata *child_bindata) 52 | .RE 53 | 54 | getdns_return_t 55 | .br 56 | .B getdns_dict_set_dict 57 | (getdns_dict *this_dict, 58 | .RS 3 59 | char *name, 60 | .br 61 | getdns_dict *child_dict) 62 | .RE 63 | 64 | getdns_return_t 65 | .br 66 | .B getdns_dict_set_int 67 | (getdns_dict *this_dict, 68 | .RS 3 69 | char *name, 70 | .br 71 | uint32_t child_uint32_t) 72 | .RE 73 | 74 | getdns_return_t 75 | .br 76 | .B getdns_dict_set_list 77 | (getdns_dict *this_dict, 78 | .RS 3 79 | char *name, 80 | .br 81 | getdns_list *child_list) 82 | .RE 83 | 84 | .SH DESCRIPTION 85 | 86 | .LP 87 | The getdns_dict type is used to manage name/value pairs in which the names are strings and the data types of the values are heterogeneous and include 88 | .RS 3 89 | .br 90 | getdns_bindata 91 | .br 92 | getdns_dict 93 | .br 94 | getdns_list 95 | .br 96 | uint32_t 97 | .RE 98 | 99 | .LP 100 | .I this_dict 101 | the dictionary in which to add/update the name/value pair 102 | .LP 103 | .I name 104 | the name whose associated value is to be set. If the name exists in the dictionary 105 | the value associated with that name is replaced, if the name does not exist in the 106 | dictionary a new item is added to the dictionary. 107 | .LP 108 | .I child_bindata 109 | .I child_dict 110 | .I child_list 111 | .I child_uint32 112 | value to assign the name 113 | 114 | .SH "RETURN VALUES" 115 | 116 | Upon successful completion the functions return 117 | .B GETDNS_RETURN_GOOD 118 | , otherwise the following error values are returned: 119 | .LP 120 | .B GETDNS_RETURN_GENERIC_ERROR 121 | if this_dict is not a valid dictionary 122 | 123 | .SH EXAMPLES 124 | 125 | TBD 126 | 127 | .SH SEE ALSO 128 | .BR libgetdns (3), 129 | .BR getdns_address (3), 130 | .BR getdns_dict (3), 131 | .BR getdns_dict_get (3), 132 | .BR getdns_general (3), 133 | .BR getdns_hostname (3), 134 | .BR getdns_service (3) 135 | 136 | -------------------------------------------------------------------------------- /doc/getdns_convert.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_convert 3 "@date@" "getdns @version@" getdns 30 | .SH NAME 31 | .B getdns_convert, 32 | .B getdns_convert_dns_name_to_fqdn, 33 | .B getdns_convert_fqdn_to_dns_name 34 | -- convert dname between presentation- and wire-format 35 | 36 | .SH LIBRARY 37 | DNS Resolver library (libgetdns, \-lgetdns) 38 | 39 | .SH SYNOPSIS 40 | #include 41 | 42 | getdns_return_t 43 | .br 44 | .B getdns_convert_dns_name_to_fqdn 45 | (const getdns_bindata *dns_name_wire_fmt, 46 | .br 47 | .RS 3 48 | char **fqdn_as_string) 49 | .RE 50 | 51 | getdns_return_t 52 | .br 53 | .B getdns_convert_fqdn_to_dns_name 54 | (char *fqdn_as_string, 55 | .br 56 | .RS 3 57 | const getdns_bindata **dns_name_wire_fmt) 58 | .RE 59 | 60 | .SH DESCRIPTION 61 | 62 | .LP 63 | Names in DNS fields are stored in a fashion very different from the normal 64 | presentation format normally used in applications. The DNS format is described 65 | in the first paragraph in Section 3.1 of RFC 1035; the presentation format here 66 | is a null-terminated string with interior dots. These helper functions only 67 | work with names in the DNS format that are not compressed. They are useful for 68 | converting domain names in the replies_tree to and from the FQDN presentation 69 | format. 70 | 71 | getdns_convert_dns_name_to_fqdn() converts a domain name in DNS format to the 72 | presentation format. For example, the hex sequence 03 77 77 77 07 65 78 61 6d 73 | 70 6c 65 03 63 6f 6d 00 would be converted to "www.example.com". 74 | getdns_convert_fqdn_to_dns_name() does the reverse: it converts a 75 | null-terminated string in FQDN format to bytes in DNS format. 76 | 77 | .HP 3 78 | .I dns_name_wire_fmt 79 | The non-compressed DNS wire format name (per RFC 1035) in a bindata structure that 80 | will be converted to/from an fqdn. In getdns_convert_fqdn_to_dns_name storage is 81 | allocated using the system allocator (malloc) and must be freed by the caller. 82 | 83 | .HP 3 84 | .I fqdn_as_string 85 | a null terminated string to be converted to/from non-compressed DNS wire format name (per RFC 1035). 86 | In getdns_convert_dns_name_to_fqdn storage is 87 | allocated using the system allocator (malloc) and must be freed by the caller. 88 | 89 | .HP 90 | .SH "RETURN VALUES" 91 | 92 | Upon successful completion the function returns 93 | .B GETDNS_RETURN_GOOD 94 | 95 | .SH EXAMPLES 96 | 97 | TBD 98 | 99 | .SH SEE ALSO 100 | .BR libgetdns (3) 101 | 102 | -------------------------------------------------------------------------------- /doc/getdns_list.3.in: -------------------------------------------------------------------------------- 1 | .\" The "BSD-New" License 2 | .\" 3 | .\" Copyright (c) 2013, NLnet Labs, Verisign, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions are met: 8 | .\" * Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" * Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" * Neither the names of the copyright holders nor the 14 | .\" names of its contributors may be used to endorse or promote products 15 | .\" derived from this software without specific prior written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | .\" DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY 21 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | .\" 28 | 29 | .TH getdns_list 3 "@date@" "getdns @version@" getdns 30 | .ad l 31 | .SH NAME 32 | .B getdns_list, 33 | .B getdns_list_create, 34 | .B getdns_list_create_with_extended_memory_functions, 35 | .B getdns_list_create_with_memory_functions, 36 | .B getdns_list_destroy 37 | -- getdns list create and destroy routines 38 | .ad n 39 | 40 | .SH LIBRARY 41 | DNS Resolver library (libgetdns, \-lgetdns) 42 | 43 | .SH SYNOPSIS 44 | #include 45 | 46 | getdns_list * 47 | .br 48 | .B getdns_list_create 49 | () 50 | 51 | getdns_list * 52 | .br 53 | .B getdns_list_create_with_extended_memory_functions 54 | .RS 3 55 | (void *userarg, 56 | .br 57 | void *(*malloc)(void *userarg, size_t sz), 58 | .br 59 | void *(*realloc)(void *userarg, void *buf, size_t sz), 60 | .br 61 | void (*free)(void *userarg, void *buf) 62 | .RE 3 63 | 64 | getdns_list * 65 | .br 66 | .B getdns_list_create_with_memory_functions 67 | .RS 3 68 | (void *userarg, 69 | .br 70 | void *(*malloc)(size_t sz), 71 | .br 72 | void *(*realloc)(void *buf, size_t sz), 73 | .br 74 | void (*free)(void *buf) 75 | .RE 3 76 | 77 | void 78 | .br 79 | .B getdns_list_destroy 80 | (getdns_list *this_dict) 81 | 82 | .SH DESCRIPTION 83 | 84 | .LP 85 | The getdns_list type is used to manage heterogeneous indexed lists name/value pairs in which the data types of the values include 86 | .RS 3 87 | .br 88 | getdns_bindata 89 | .br 90 | getdns_dict 91 | .br 92 | getdns_list 93 | .br 94 | uint32_t 95 | .RE 96 | 97 | .LP 98 | The destroy function performs a "deep" destroy, freeing storage for all of the members 99 | of the list before destroying the list. There are a number of helper 100 | functions that provide access to the list object, see their respective man pages. 101 | 102 | .LP 103 | .I userarg 104 | pass this argument to the user specified memory management functions for operations on lists created using extended memory functions 105 | 106 | .LP 107 | .I this_list 108 | the list to destroy 109 | 110 | .SH "RETURN VALUES" 111 | 112 | Upon successful completion the getdns_list_create function returns a valid (empty) 113 | list structure that should be freed via a call to getdns_list_destroy. If a parameter in invalid or in the event of some error getdns_list_create returns NULL. 114 | 115 | .SH EXAMPLES 116 | 117 | TBD 118 | 119 | .SH SEE ALSO 120 | .BR libgetdns (3), 121 | .BR getdns_dict (3), 122 | .BR getdns_list_get (3), 123 | .BR getdns_list_set (3) 124 | 125 | --------------------------------------------------------------------------------