├── .gitignore ├── AUTHORS ├── COPYING ├── COPYING.BSD ├── ChangeLog ├── ChangeLog.old ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── PKGBUILD.in ├── README ├── README.par ├── README.par.old ├── THANKS ├── TODO ├── acconfig.h ├── aclocal.m4 ├── compile ├── config.h.in ├── configure ├── configure.in ├── contrib ├── Makefile.am ├── Makefile.in ├── README ├── change_pdnsd_server_ip.pl ├── dhcp2pdnsd └── pdnsd_dhcp.pl ├── depcomp ├── doc ├── Makefile.am ├── Makefile.in ├── doc_makefile ├── html │ ├── dl.html │ ├── dl.html.in │ ├── doc.html │ ├── doc_makefile │ ├── faq.html │ ├── htmlsubst.pl │ └── index.html ├── html2confman.pl ├── pdnsd-ctl.8 ├── pdnsd.8.in ├── pdnsd.conf.5.in ├── pdnsd.conf.in └── txt │ ├── doc_makefile │ ├── faq.txt │ ├── intro.txt │ └── manual.txt ├── file-list.base.in ├── install-sh ├── missing ├── pdnsd.spec.in ├── src ├── Makefile.am ├── Makefile.in ├── cache.c ├── cache.h ├── conf-keywords.h ├── conf-parser.c ├── conf-parser.h ├── conff.c ├── conff.h ├── consts.c ├── consts.h ├── debug.c ├── debug.h ├── dns.c ├── dns.h ├── dns_answer.c ├── dns_answer.h ├── dns_query.c ├── dns_query.h ├── error.c ├── error.h ├── freebsd_netinet_ip_icmp.h ├── hash.c ├── hash.h ├── helpers.c ├── helpers.h ├── icmp.c ├── icmp.h ├── ipvers.h ├── list.c ├── list.h ├── main.c ├── make_rr_types_h.pl ├── netdev.c ├── netdev.h ├── pdnsd-ctl │ ├── Makefile.am │ ├── Makefile.in │ └── pdnsd-ctl.c ├── pdnsd_assert.h ├── rc │ ├── ArchLinux │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ └── pdnsd.in │ ├── Debian │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ └── pdnsd.in │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ ├── RedHat │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ └── pdnsd.in │ ├── Slackware │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ └── rc.pdnsd.in │ └── SuSE │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ └── pdnsd.in ├── rr_types.c ├── rr_types.h ├── rr_types.in ├── servers.c ├── servers.h ├── sort_namevalues.pl ├── status.c ├── status.h ├── test │ ├── Makefile.am │ ├── Makefile.in │ ├── if_up.c │ ├── is_local_addr.c │ ├── random.c │ └── tping.c ├── thread.c └── thread.h └── version /.gitignore: -------------------------------------------------------------------------------- 1 | # gitignore patterns for pdnsd 2 | *~ 3 | *.[oa] 4 | autom4te.cache/ 5 | .deps 6 | Makefile 7 | *.makesave 8 | /config.h 9 | /config.log 10 | /config.status 11 | /doc/pdnsd.8 12 | /doc/pdnsd.conf 13 | /doc/pdnsd.conf.5 14 | /file-list.base 15 | /pdnsd.spec 16 | /pdnsd-*.tar.gz 17 | /PKGBUILD 18 | /src/rc/*/pdnsd 19 | /src/rc/Slackware/rc.pdnsd 20 | /stamp-h1 21 | /src/pdnsd 22 | /src/pdnsd-ctl/pdnsd-ctl 23 | /src/test/if_up 24 | /src/test/is_local_addr 25 | /src/test/random 26 | /src/test/tping 27 | TAGS 28 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Most of pdnsd was written by Thomas Moestl (tmoestl@gmx.net). 2 | In the "par" versions large parts of the code have been revised 3 | and several features have been added by Paul Rombouts. 4 | 5 | Small parts of this program are based on code that was taken from nmap (IP 6 | checksumming), the isdn4k-utils (ippp interface uptest), glibc 2.1.2 (some 7 | definitions for kernel 2.2.x missing in 2.0 glibcs) and FreeBSD 8 | (SIZEOF_ADDR_IFREQ in netdev.c). 9 | nmap was written by Fyodor. The insd4k-utils were written by Fritz Elfert and 10 | others. The GNU C library (glibc) is copyright by the Free Software 11 | Foundation. 12 | 13 | The following people have contributed code: 14 | Andrew M. Bishop contributed support for server labels 15 | Carsten Block contributed 'configure'-able rc scripts 16 | Stephan Boettcher contributed the SCHEME= option. 17 | P.J. Bostley contributed patches to get pdnsd working on 18 | alpha 19 | Frank Elsner contributed rc script fixes 20 | Christian Engstler contributed patches for SuSE compatability 21 | Bjoern Fischer contributed code to make pdnsd leave the case of names 22 | in the cache unchanged 23 | Torben Janssen contributed RedHat rc scripts 24 | Olaf Kirch contributed a security fix for the run_as() 25 | function 26 | Bernd Leibing contributed fixes to the spec file. 27 | Sourav K. Mandal contributed the autoconf/automake code, gdbm 28 | caching facility and many suggestions 29 | Markus Mohr contributed Debian rc scripts 30 | Alexandre Nunes contributed autoconf fixes 31 | Wolfgang Ocker contributed the server_ip option 32 | Soenke J. Peters contributed patches and suggestions for RedHat 33 | compatability 34 | Roman Shterenzon contributed many helpful hints and patches for 35 | FreeBSD compatability. 36 | Andreas Steinmetz contributed the code for the query_port_start and 37 | query_port_end options (which I changed slightly, 38 | so blame any breakage on me ;) 39 | Marko Stolle contributed the contrib/pdnsd_update.pl script that 40 | makes pdnsd usable in a DHCP setup. 41 | Lyonel Vincent extended the serve_aliases option to support an 42 | arbitrary number of aliases 43 | Paul Wagland contributed a patches for bind9-compatability 44 | and for some memory leaks on error paths. 45 | Sverker Wiberg contributed IPv6 build fixes 46 | Michael Wiedmann contributed the pdnsd-ctl.8 man page. 47 | Ron Yorston contributed the dev-uptest for Linux ppp dial- 48 | on-demand devices 49 | Nikita V. Youshchenko contributed extensions to the "if" uptest 50 | Mahesh T. Pai contributed the pdnsd.8 man page. 51 | Nikola Kotur contributed the Slackware start-up script. 52 | Kiyo Kelvin Lee contributed a patch for Cygwin support. 53 | Rodney Brown contributed a patch for Darwin (Apple Mac OS X) support. 54 | Jan-Marek Glogowski contributed a patch implementing the "use_nss" option. 55 | 56 | Please look into the THANKS file for people who helped me in various ways on 57 | this project. 58 | If this list is incomplete, pease drop me a mail! 59 | -------------------------------------------------------------------------------- /COPYING.BSD: -------------------------------------------------------------------------------- 1 | A small part of the pdnsd source is licensed under the following BSD-style 2 | license: 3 | 4 | Copyright (C) 2001 Thomas Moestl 5 | 6 | This file is part of the pdnsd package. 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 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 26 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocks/pdnsd/a8e46ccba7b0fa2230d6c42ab6dcd92926f6c21d/ChangeLog -------------------------------------------------------------------------------- /ChangeLog.old: -------------------------------------------------------------------------------- 1 | 2000-02-15 2 | Version 0.2. First working alpha with the extended feature set. 3 | 4 | 2000-02-16 5 | Version 0.3 with many bugfixes, better standard conformity and 6 | some new features. 7 | 8 | 2000-02-17 9 | Did a lint on the code, implemented soft timeouts, again bugfixes, 10 | drastically reduced cache memory requirements, implemented local 11 | records. 12 | Version 0.4 released. 13 | 14 | 2000-02-19 15 | Recursive query finally implemented. Version 0.5 out. 16 | 17 | 2000-02-20 18 | Various bugfixes. The server now always tries to get an AA answer 19 | if possible; this implies recursion. This is to deal better with 20 | caching servers that may return incomplete results on * queries. 21 | This may be a little sub-optimal since it may not take the full 22 | effect of caching, but it is the only real possibility of getting 23 | complete records. 24 | Redid the deps in the makefile for now. 25 | Version is now 0.6. 26 | 27 | 2000-02-21 28 | Another set of bugfixes. Version is 0.6.1. 29 | 30 | 2000-02-22 31 | Another set of bugfixes. It should stabilize by now. Answer compression 32 | is there finally. Version is therefore up again, 0.7 by now. 33 | 34 | 2000-02-23 35 | Minor bugfixes, isdn interface uptest added. The new record types as of 36 | rfc1700 are implemented, but as a compile-time option, since normally 37 | there is no need to waste space for them. 38 | Version is 0.7.1. 39 | 40 | 2000-02-24 41 | Version 0.7.2 with all rrs up to KX (36). #define DNS_NEW_RRS in 42 | config.h and (re)compile if you want to use them. Delete the cache 43 | file before using a version with this option changed! 44 | NSAP-PTR does NOT WORK (any incoming answer containing it may cause 45 | a format error) because it is ill-designed (see TODO). Never mind, it 46 | is officially deprecated anyway. 47 | The secure DNS extension record types defined in RFC 2065 (KEY, SIG, 48 | NXT) are cached only and therefore useless. 49 | 50 | 2000-02-26 51 | Version 0.8 with parallel query (and probably new bugs) introduced. 52 | 53 | 2000-02-27 54 | Version 0.8.1 with minor bugfixes on the new features. 55 | 56 | 2000-02-27 57 | Version 0.8.5 with authority support and the usual bugifxes. Some issues 58 | with standard conformity were also fixed (wow, two versions a day). 59 | 60 | 2000-02-28 61 | Implemented caching of non-authoritative records. This allows better 62 | usage of other caching name servers. This may return non-authoritative 63 | records to any non-wildcard query. If a wildcard query arrives, we 64 | always look for authoritative records, so we do if the non-authoritative 65 | answer does not contain at least one answering record to the query. 66 | This fixes the sub-optimal behaviour since 0.6. 67 | Version is therefore up to 0.8.7 (0.8.6 was also released today 68 | containing bugfixes) 69 | 70 | 2000-02-29 71 | Better thread support, avoiding deadlocks in signal handling. The cost 72 | is unfortunately one more thread. 73 | New option server_port in config file. 74 | Version is 0.8.8. 75 | 76 | 2000-03-01 77 | Nailed a renitent memory leak bug to the wall (shame, what a trivial 78 | mistake). Also improved handling of error conditions slightly. 79 | Version is 0.8.9. 80 | 81 | 2000-03-01 82 | Cache code cleanup. The development of the non-parallel query code 83 | is discontinued, although it still works. If you want serial query, 84 | just set PAR_QUERIES to 1. 85 | Additional information finally implemented. 86 | We are up to 0.9. 87 | 88 | 2000-03-02 89 | Fixed a DoS possibility. 90 | More rfc compatability fixups and a smarter resolver logic. 91 | Version 0.9.1 92 | 93 | 2000-03-02 94 | Added the source section to the config file handling. This allows to 95 | source your /etc/hosts file. Version 0.9.2. 96 | 97 | 2000-03-02 98 | Avoiding double additional records now. Version 0.9.3. 99 | 100 | 2000-03-09 101 | Fixed some REALLY STUPID bugs. Uuummph, thought it was finished. 102 | However, the number of bugs remaining is always n+1... 103 | Anyway, we are up to 0.9.4. Hope that there are no mean bugs left. 104 | 105 | 2000-03-14 106 | Added another uptest, exec. See README for details. Also grained the 107 | cache size finer (it's now specified in kB). Version 0.9.5 108 | 109 | 2000-04-07 110 | Fixed some really stupid bugs, what else? Version is 0.9.6 111 | To be more exact: fixed misc bugs, cleaned up hash.c and cache.c 112 | 113 | 2000-04-20 114 | Again fixed some bugs, version is now 0.9.7. 115 | 116 | 2000-04-29 117 | Fixed a build problem caused by some missing #defines in glibc2.0 and a 118 | minor bug. 119 | Version is up to 0.9.8 120 | 121 | 2000-04-30 122 | Fixed some unclean C code and did a general C lint. Thanks to Byrial 123 | Jensen for pointing out some issues. Now using stricter compiler flags. 124 | Also replaced the daemon() call in main.c for improved portability. 125 | Pre-Released 0.9.9p1 126 | 127 | 2000-05-03 128 | Released 0.9.9p2 with the changes of 0.9.9p1, Documentation updates, 129 | bugfixes, and the Red Hat rc scripts contributed by Torben Janssen. 130 | Also, the meaning of the command line option -v has changed. 131 | There is a new config file option "lean_query" that is on by 132 | default. It is an optimization, so please look in the docs when 133 | updating whether you want it switched on or not. 134 | Removed the long-dead serial query code from the distribution tree. 135 | Some resolvers seem to be broken somehow in a respect that it cares 136 | about order in which the records appear. In particular, it wants 137 | cname to appear before other records. Ok, so it be... 138 | 139 | 140 | 2000-05-04 141 | Save all names in lower case in the rrs. 142 | Tidying up the source tree. 143 | The long-awaited cache structure changes have been started. Please 144 | delete you cache files before using this new release. 145 | 146 | 2000-05-05 147 | Fixed several bugs in the old and in the new source tree. 148 | Use time_t instead of long for internal time storage for compatibility. 149 | 150 | 151 | 2000-05-06 152 | Version 0.9.10. 153 | This fixes a bug in uptest=if. Red Hat and configuration fixes 154 | suggested by Soeren J. Peters were included. 155 | 156 | 2000-05-08 157 | Version 0.9.11 158 | This fixes a locally exploitable security problem (pdnsd.cache was 159 | world-writeable). This is actually a one-line fix; for a description of 160 | possible dangers, please refer to the html documentation. 161 | Thanks to Alan Swanson for reporting. 162 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | The installation instructions are in doc/html/doc.html and doc/txt/manual.txt. 2 | The system requirements are listed in doc/html/index.html and doc/txt/intro.txt. 3 | I recommend using the html version. 4 | Following are generic installation instructions for autoconf programs. 5 | I strongly recommend to read the Installation section in the docs! 6 | 7 | 8 | Basic Installation 9 | ================== 10 | 11 | These are generic installation instructions. 12 | 13 | The `configure' shell script attempts to guess correct values for 14 | various system-dependent variables used during compilation. It uses 15 | those values to create a `Makefile' in each directory of the package. 16 | It may also create one or more `.h' files containing system-dependent 17 | definitions. Finally, it creates a shell script `config.status' that 18 | you can run in the future to recreate the current configuration, a file 19 | `config.cache' that saves the results of its tests to speed up 20 | reconfiguring, and a file `config.log' containing compiler output 21 | (useful mainly for debugging `configure'). 22 | 23 | If you need to do unusual things to compile the package, please try 24 | to figure out how `configure' could check whether to do them, and mail 25 | diffs or instructions to the address given in the `README' so they can 26 | be considered for the next release. If at some point `config.cache' 27 | contains results you don't want to keep, you may remove or edit it. 28 | 29 | The file `configure.in' is used to create `configure' by a program 30 | called `autoconf'. You only need `configure.in' if you want to change 31 | it or regenerate `configure' using a newer version of `autoconf'. 32 | 33 | The simplest way to compile this package is: 34 | 35 | 1. `cd' to the directory containing the package's source code and type 36 | `./configure' to configure the package for your system. If you're 37 | using `csh' on an old version of System V, you might need to type 38 | `sh ./configure' instead to prevent `csh' from trying to execute 39 | `configure' itself. 40 | 41 | Running `configure' takes awhile. While running, it prints some 42 | messages telling which features it is checking for. 43 | 44 | 2. Type `make' to compile the package. 45 | 46 | 3. Optionally, type `make check' to run any self-tests that come with 47 | the package. 48 | 49 | 4. Type `make install' to install the programs and any data files and 50 | documentation. 51 | 52 | 5. You can remove the program binaries and object files from the 53 | source code directory by typing `make clean'. To also remove the 54 | files that `configure' created (so you can compile the package for 55 | a different kind of computer), type `make distclean'. There is 56 | also a `make maintainer-clean' target, but that is intended mainly 57 | for the package's developers. If you use it, you may have to get 58 | all sorts of other programs in order to regenerate files that came 59 | with the distribution. 60 | 61 | Compilers and Options 62 | ===================== 63 | 64 | Some systems require unusual options for compilation or linking that 65 | the `configure' script does not know about. You can give `configure' 66 | initial values for variables by setting them in the environment. Using 67 | a Bourne-compatible shell, you can do that on the command line like 68 | this: 69 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 70 | 71 | Or on systems that have the `env' program, you can do it like this: 72 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 73 | 74 | Compiling For Multiple Architectures 75 | ==================================== 76 | 77 | You can compile the package for more than one kind of computer at the 78 | same time, by placing the object files for each architecture in their 79 | own directory. To do this, you must use a version of `make' that 80 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 81 | directory where you want the object files and executables to go and run 82 | the `configure' script. `configure' automatically checks for the 83 | source code in the directory that `configure' is in and in `..'. 84 | 85 | If you have to use a `make' that does not supports the `VPATH' 86 | variable, you have to compile the package for one architecture at a time 87 | in the source code directory. After you have installed the package for 88 | one architecture, use `make distclean' before reconfiguring for another 89 | architecture. 90 | 91 | Installation Names 92 | ================== 93 | 94 | By default, `make install' will install the package's files in 95 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 96 | installation prefix other than `/usr/local' by giving `configure' the 97 | option `--prefix=PATH'. 98 | 99 | You can specify separate installation prefixes for 100 | architecture-specific files and architecture-independent files. If you 101 | give `configure' the option `--exec-prefix=PATH', the package will use 102 | PATH as the prefix for installing programs and libraries. 103 | Documentation and other data files will still use the regular prefix. 104 | 105 | In addition, if you use an unusual directory layout you can give 106 | options like `--bindir=PATH' to specify different values for particular 107 | kinds of files. Run `configure --help' for a list of the directories 108 | you can set and what kinds of files go in them. 109 | 110 | If the package supports it, you can cause programs to be installed 111 | with an extra prefix or suffix on their names by giving `configure' the 112 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 113 | 114 | Optional Features 115 | ================= 116 | 117 | Some packages pay attention to `--enable-FEATURE' options to 118 | `configure', where FEATURE indicates an optional part of the package. 119 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 120 | is something like `gnu-as' or `x' (for the X Window System). The 121 | `README' should mention any `--enable-' and `--with-' options that the 122 | package recognizes. 123 | 124 | For packages that use the X Window System, `configure' can usually 125 | find the X include and library files automatically, but if it doesn't, 126 | you can use the `configure' options `--x-includes=DIR' and 127 | `--x-libraries=DIR' to specify their locations. 128 | 129 | Specifying the System Type 130 | ========================== 131 | 132 | There may be some features `configure' can not figure out 133 | automatically, but needs to determine by the type of host the package 134 | will run on. Usually `configure' can figure that out, but if it prints 135 | a message saying it can not guess the host type, give it the 136 | `--host=TYPE' option. TYPE can either be a short name for the system 137 | type, such as `sun4', or a canonical name with three fields: 138 | CPU-COMPANY-SYSTEM 139 | 140 | See the file `config.sub' for the possible values of each field. If 141 | `config.sub' isn't included in this package, then this package doesn't 142 | need to know the host type. 143 | 144 | If you are building compiler tools for cross-compiling, you can also 145 | use the `--target=TYPE' option to select the type of system they will 146 | produce code for and the `--build=TYPE' option to select the type of 147 | system on which you are compiling the package. 148 | 149 | Sharing Defaults 150 | ================ 151 | 152 | If you want to set default values for `configure' scripts to share, 153 | you can create a site shell script called `config.site' that gives 154 | default values for variables like `CC', `cache_file', and `prefix'. 155 | `configure' looks for `PREFIX/share/config.site' if it exists, then 156 | `PREFIX/etc/config.site' if it exists. Or, you can set the 157 | `CONFIG_SITE' environment variable to the location of the site script. 158 | A warning: not all `configure' scripts look for a site script. 159 | 160 | Operation Controls 161 | ================== 162 | 163 | `configure' recognizes the following options to control how it 164 | operates. 165 | 166 | `--cache-file=FILE' 167 | Use and save the results of the tests in FILE instead of 168 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 169 | debugging `configure'. 170 | 171 | `--help' 172 | Print a summary of the options to `configure', and exit. 173 | 174 | `--quiet' 175 | `--silent' 176 | `-q' 177 | Do not print messages saying which checks are being made. To 178 | suppress all normal output, redirect it to `/dev/null' (any error 179 | messages will still be shown). 180 | 181 | `--srcdir=DIR' 182 | Look for the package's source code in directory DIR. Usually 183 | `configure' can determine that directory automatically. 184 | 185 | `--version' 186 | Print the version of Autoconf used to generate the `configure' 187 | script, and exit. 188 | 189 | `configure' also accepts some other, not widely useful, options. 190 | 191 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = src doc contrib 3 | 4 | EXTRA_DIST = version ChangeLog.old COPYING.BSD README.par README.par.old PKGBUILD 5 | 6 | # The sample configuration is handled in doc/Makefile.am 7 | install-data-hook: 8 | $(mkinstalldirs) "$(DESTDIR)$(cachedir)" 9 | test -f "$(DESTDIR)$(cachedir)/pdnsd.cache" || \ 10 | touch "$(DESTDIR)$(cachedir)/pdnsd.cache" 11 | if test `whoami` = "root"; then \ 12 | chown $(def_id) "$(DESTDIR)$(cachedir)/pdnsd.cache"; \ 13 | chown $(def_id) "$(DESTDIR)$(cachedir)"; \ 14 | fi 15 | chmod 0640 "$(DESTDIR)$(cachedir)/pdnsd.cache" 16 | chmod 0750 "$(DESTDIR)$(cachedir)" 17 | 18 | dist-hook: $(PACKAGE).spec.in 19 | sed -e '/^%{!?distro: %define distro /c\ 20 | %if 0%{!?distro:1}\ 21 | %if "%{_vendor}" == "redhat"\ 22 | %define distro RedHat\ 23 | %else\ 24 | %if "%{_vendor}" == "suse"\ 25 | %define distro SuSE\ 26 | %else\ 27 | %if "%{_vendor}" == "SuSE"\ 28 | %define distro SuSE\ 29 | %endif\ 30 | %endif\ 31 | %endif\ 32 | %endif' \ 33 | -e 's:[@]PACKAGE[@]:$(PACKAGE):g' \ 34 | -e 's:[@]VERSION[@]:$(VERSION):g' \ 35 | -e 's:[@]fullversion[@]:$(fullversion):g' \ 36 | -e 's:[@]packagerelease[@]:$(packagerelease):g' \ 37 | -e 's:[@]cachedir[@]:/var/cache/$(PACKAGE):g' \ 38 | -e 's:[@]def_id[@]:$(PACKAGE):g' \ 39 | $(PACKAGE).spec.in > $(distdir)/$(PACKAGE).spec 40 | 41 | -------------------------------------------------------------------------------- /PKGBUILD.in: -------------------------------------------------------------------------------- 1 | # Package build script for Arch Linux, 2 | # contributed by Alexander Drozdov. 3 | 4 | pkgname=@PACKAGE@ 5 | pkgver=@VERSION@ 6 | pkgrel=@packagerelease@ 7 | pkgdesc="pdnsd is a proxy DNS server with permanent caching (the cache contents are written to hard disk on exit) that is designed to cope with unreachable or down DNS servers." 8 | url="http://members.home.nl/p.a.rombouts/pdnsd.html" 9 | license="GPLv3" 10 | depends=() 11 | makedepends=(glibc) 12 | conflicts=() 13 | replaces=() 14 | backup=() 15 | install= 16 | source=(http://members.home.nl/p.a.rombouts/pdnsd/releases/$pkgname-$pkgver-$pkgrel.tar.gz) 17 | md5sums=() 18 | 19 | build() { 20 | cd $startdir/src/$pkgname-$pkgver 21 | ./configure --prefix=/usr --enable-ipv6 --sysconfdir=/etc --with-distribution=ArchLinux 22 | make || return 1 23 | make DESTDIR=$startdir/pkg install 24 | } 25 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | You can find the documentation for pdnsd in the doc/ directory. The html 2 | documentation (which I recommend) is in the doc/html/ subdirectory. 3 | The pure text documentation (which is generated automatically from the 4 | html documentation) is in doc/txt/. 5 | The following documents are available: 6 | 7 | index.html / intro.txt Overview, system requirements 8 | doc.html / manual.txt Building, installation and usage instructions 9 | faq.html / faq.txt The FAQ 10 | 11 | Share and enjoy! 12 | Thomas 13 | 14 | 15 | For news about recent changes in pdnsd the following files may be of 16 | interest to you: 17 | 18 | README.par 19 | ChangeLog 20 | NEWS 21 | 22 | Last revised: 08 July 2007 by Paul Rombouts 23 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocks/pdnsd/a8e46ccba7b0fa2230d6c42ab6dcd92926f6c21d/THANKS -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Implement a reference counter to ensure that newly entered records are not 2 | purged immediately (really needed?) 3 | - Perhaps do a two-step form of recursive query: first query those servers we 4 | have got cached, then (if unsuccessful) look the others up and query again. 5 | The impact of this optimisation may not be very big, because all sane servers 6 | give A records for NS records if possible. 7 | - Test for compatibility on other Unix-like Systems other than the BSDs and 8 | Linux; rewrite the functions in netdev.c and icmp.c for those OSs if 9 | necessary. Also try to get compatibility for other compilers than gcc. 10 | - Write an install rule for the Slackware start-up script. 11 | - Update the FAQ. 12 | - Implement DNSSEC support. Since version 1.2.9, pdnsd is able to cache the RR 13 | types necessary for DNSSEC, but the resolver is not yet security aware. 14 | - Implement a lookup table (hash table) for queries in progress. This would 15 | enable a thread that is resolving a query that is already being handled by 16 | another thread to wait for that other thread to finish and copy its result 17 | rather than independently query remote servers. It is very common for 18 | resolvers to resend UDP queries if they don't get a reply within a timeout 19 | period and if the answer is not yet cached, this will result in multiple 20 | threads duplicating each others work in the current implementation. 21 | -------------------------------------------------------------------------------- /acconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | /* ONLY EDIT acconfig.h, NEVER config.h or config.h.in! 5 | * config.h MAY BE OVERWRITTEN BY make, config.h.in by autoheader! */ 6 | 7 | /* Define your Target here. Currently defined are TARGET_LINUX (any 8 | * architecture), TARGET_BSD (experimental; tested on FreeBSD, hopefully 9 | * works for other BSD variants) and TARGET_CYGWIN. */ 10 | #define TARGET TARGET_LINUX 11 | 12 | /* change the #undef to #define if you do not want to compile with special 13 | * ISDN support for Linux. Note that the ISDN support will not compile ok on 14 | * unpatched kernerls earlier than 2.2.12 (if you did apply newer isdn patches, 15 | * it may work fine). This is not on by default because it will cause compile 16 | * problems on some systems */ 17 | #undef ISDN_SUPPORT 18 | 19 | /* The following regulates the IP Protocol support. Supported types are IPv4 20 | * and IPv6 (aka IPng). You may enable either or both of these protocols. 21 | * Enabling in this context means that support for the respective protocol 22 | * will be in the binary. When running the binary, one of the protocols may 23 | * be activated via command line switches. Note that activating both IPv4 and 24 | * IPv6 is pointless (and will not work because two UDP and two TCP threads 25 | * will be started that concur for ports). Because of that, it is not allowed. 26 | * When pdnsd runs with IPv6 activated it should be able to service queries 27 | * from IPv6 as well as from IPv4 hosts, provided that you host is configured 28 | * properly. 29 | * For each of the protocols there are two options: ENABLE_IPV4 and ENABLE_IPV6 30 | * control whether support for the respective protocol is available in the 31 | * binary. DEFAULT_IPV4 selects which protocol is enabled on pdnsd 32 | * startup by default. 1 means IPv4, while 0 means IPv6. If support for 33 | * a protocol was included in the executable, you can specify command line 34 | * parameters to activate or deactivate that protocol (the options are -4 and 35 | * -6), but it makes more sense to use the run_ipv4=on/off option in the 36 | * configuration file. 37 | * Make your choice. Note that IPv6 support is experimental in pdnsd. 38 | * In normal operation, you will currently only need IPv4. */ 39 | #undef ENABLE_IPV4 40 | #define DEFAULT_IPV4 1 41 | #undef ENABLE_IPV6 42 | 43 | /* In all pdnsd versions before 1.0.6, DNS queries were always done over 44 | * TCP. Now, you have the choice. You can control that behaviour using 45 | * the -m command line switch, and you can give a preset here. There 46 | * are 3 different modes: 47 | * UDP_ONLY: This is undoubtedly the fastest query method, because 48 | * no TCP negotiation needs to be done. 49 | * TCP_ONLY: This is slower than uo, but generally more secure 50 | * against DNS spoofing. Note that some name servers on the 51 | * internet do not support TCP queries, notably dnscache. 52 | * TCP_UDP: TCP, then UDP. If the TCP query fails with a "connection refused"- 53 | * error or times out, the query is retried using UDP. 54 | * UDP_TCP: UDP, then TCP. If the UDP reply is truncated (i.e. the tc flag is set), 55 | * the query is retried using TCP. */ 56 | #define M_PRESET UDP_ONLY 57 | 58 | /* In addition to choosing the presets, you may also completely disable 59 | * one of the protocols (TCP for preset UDP_ONLY and UDP for preset TCP_ONLY). 60 | * This saves some executable space. */ 61 | #undef NO_UDP_QUERIES 62 | #undef NO_TCP_QUERIES 63 | 64 | /* With the following option, you can disable the TCP server functionality 65 | * of pdnsd. Nearly no program does TCP queries, so you probably can do 66 | * this safely and save some executable space and one thread. 67 | * You also can turn off the TCP server at runtime with the --notcp option. */ 68 | #undef NO_TCP_SERVER 69 | 70 | /* By undefining the following, you can disable the UDP source address 71 | * discovery code. This is not recommended, but you may need it when 72 | * running into compilation problems. */ 73 | #undef SRC_ADDR_DISC 74 | 75 | /* NO_POLL specifies not to use poll(2), but select(2) instead. If you are 76 | * unsure about what this means, just leave this as it is.*/ 77 | #undef NO_POLL 78 | 79 | /* Define this for "hard" RFC 2181 compliance: this RFC states that 80 | * implementations should discard answers whose RR sets have multiple 81 | * different time stamps. While correct answers are generated, incorrect 82 | * ones are normally tolerated and corrected. Full RFC compliance is 83 | * however only achieved by deactivating this behaviour and thus being 84 | * intolerant. */ 85 | #undef RFC2181_ME_HARDER 86 | 87 | /* Define this to the device you want to use for getting random numbers. 88 | * Leave this undefined if you wand to use the standard C library random 89 | * function, which basically should be sufficient. 90 | * Linux and FreeBSD have two random number devices: /dev/random and 91 | * /dev/urandom. /dev/urandom might be less secure in some cases, but 92 | * should still be more than sufficient. The use of /dev/random is 93 | * discouraged, as reading from this device blocks when new random bits 94 | * need to be gathered. */ 95 | #undef RANDOM_DEVICE 96 | #undef R_DEFAULT 97 | #undef R_RANDOM 98 | #undef R_ARC4RANDOM 99 | /*#define RANDOM_DEVICE "/dev/urandom"*/ 100 | 101 | /* Designate which database manager to use for cacheing. 102 | * default: native; others: gdbm */ 103 | #define CACHE_DBM DBM_NATIVE 104 | 105 | #define CACHEDIR "/var/cache/pdnsd" 106 | 107 | #define TEMPDIR "/tmp"; 108 | 109 | /* This is for various debugging facilities that produce debug output and 110 | * double-check some values. You can enable debug messages with the -g option. 111 | * Normally, you can switch this off safely by setting the number after DEBUG 112 | * to 0. This will increase speed (although only marginally), save space 113 | * in the executable (only about 12kB) and some stack space per thread 114 | * (which may be significant if you have many threads running simultaneously). 115 | * However, it may be an aid when debugging config files. 116 | * The only defined debug levels by now are in the range 0 - 9. 117 | * Define this to 9 if you want hex dumps of all the queries and replies pdnsd 118 | * receives (you must also call pdnsd with -v9 to actually see the hex dumps). 119 | * When in doubt, leave it defined to 1. */ 120 | #define DEBUG 1 121 | 122 | /* This defines the default verbosity of informational messages you will get. 123 | This has nothing to to with the debug option (-g), but may be set with -v 124 | option. 0 is for normal operation, up to 3 for debugging. 125 | Unlike the debug messages, these messages will also be written to the syslog.*/ 126 | #define VERBOSITY 0 127 | 128 | /* Redefine this if you want another hash size. 129 | * The number of hash buckets is computed as power of two (1<. 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | case $1 in 33 | '') 34 | echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35 | exit 1; 36 | ;; 37 | -h | --h*) 38 | cat <<\EOF 39 | Usage: compile [--help] [--version] PROGRAM [ARGS] 40 | 41 | Wrapper for compilers which do not understand `-c -o'. 42 | Remove `-o dest.o' from ARGS, run PROGRAM with the remaining 43 | arguments, and rename the output as expected. 44 | 45 | If you are trying to build a whole package this is not the 46 | right script to run: please start by reading the file `INSTALL'. 47 | 48 | Report bugs to . 49 | EOF 50 | exit $? 51 | ;; 52 | -v | --v*) 53 | echo "compile $scriptversion" 54 | exit $? 55 | ;; 56 | esac 57 | 58 | ofile= 59 | cfile= 60 | eat= 61 | 62 | for arg 63 | do 64 | if test -n "$eat"; then 65 | eat= 66 | else 67 | case $1 in 68 | -o) 69 | # configure might choose to run compile as `compile cc -o foo foo.c'. 70 | # So we strip `-o arg' only if arg is an object. 71 | eat=1 72 | case $2 in 73 | *.o | *.obj) 74 | ofile=$2 75 | ;; 76 | *) 77 | set x "$@" -o "$2" 78 | shift 79 | ;; 80 | esac 81 | ;; 82 | *.c) 83 | cfile=$1 84 | set x "$@" "$1" 85 | shift 86 | ;; 87 | *) 88 | set x "$@" "$1" 89 | shift 90 | ;; 91 | esac 92 | fi 93 | shift 94 | done 95 | 96 | if test -z "$ofile" || test -z "$cfile"; then 97 | # If no `-o' option was seen then we might have been invoked from a 98 | # pattern rule where we don't need one. That is ok -- this is a 99 | # normal compilation that the losing compiler can handle. If no 100 | # `.c' file was seen then we are probably linking. That is also 101 | # ok. 102 | exec "$@" 103 | fi 104 | 105 | # Name of file we expect compiler to create. 106 | cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 107 | 108 | # Create the lock directory. 109 | # Note: use `[/.-]' here to ensure that we don't use the same name 110 | # that we are using for the .o file. Also, base the name on the expected 111 | # object file name, since that is what matters with a parallel build. 112 | lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d 113 | while true; do 114 | if mkdir "$lockdir" >/dev/null 2>&1; then 115 | break 116 | fi 117 | sleep 1 118 | done 119 | # FIXME: race condition here if user kills between mkdir and trap. 120 | trap "rmdir '$lockdir'; exit 1" 1 2 15 121 | 122 | # Run the compile. 123 | "$@" 124 | ret=$? 125 | 126 | if test -f "$cofile"; then 127 | mv "$cofile" "$ofile" 128 | elif test -f "${cofile}bj"; then 129 | mv "${cofile}bj" "$ofile" 130 | fi 131 | 132 | rmdir "$lockdir" 133 | exit $ret 134 | 135 | # Local Variables: 136 | # mode: shell-script 137 | # sh-indentation: 2 138 | # eval: (add-hook 'write-file-hooks 'time-stamp) 139 | # time-stamp-start: "scriptversion=" 140 | # time-stamp-format: "%:y-%02m-%02d.%02H" 141 | # time-stamp-end: "$" 142 | # End: 143 | -------------------------------------------------------------------------------- /contrib/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = pdnsd_dhcp.pl dhcp2pdnsd change_pdnsd_server_ip.pl README 3 | -------------------------------------------------------------------------------- /contrib/README: -------------------------------------------------------------------------------- 1 | Last revised: 27 July 2003 by Paul Rombouts 2 | 3 | This directory contains user-contributed scripts for use with pdnsd. 4 | So far there are: 5 | 6 | pdnsd_dhcp.pl, save_ram.pl 7 | A perl script contributed by Marko Stolle (derived from a script by 8 | Mike Stella) to watch a ISC DHCPD leases file and add local records for 9 | the hosts listed there. This makes pdnsd useable in a DHCP setup. 10 | Please look into the script for usage instructions (you will probably 11 | also need to customize some settings there). 12 | For details about save_ram.pl, please look into pdnsd_dhcp.pl 13 | 14 | dhcp2pdnsd 15 | A rc script for pdnsd, also by Marko Stolle. You might need to change 16 | it slightly to make it run with your distro. 17 | 18 | change_pdnsd_server_ip.pl 19 | A perl script contributed by Paul Rombouts for automatically updating 20 | the configuration file if the DNS server configuration has changed. 21 | For instance, you could place the following line in the script 22 | /sbin/ifup-local 23 | 24 | /usr/local/sbin/change_pdnsd_server_ip.pl isplabel "$DNS" /etc/pdnsd.conf 25 | 26 | where $DNS contains the IP addresses (in comma separated format) of the 27 | DNS servers obtained by DHCP negotiation. The perl script only 28 | overwrites /etc/pdnsd.conf if the DNS configuration has actually 29 | changed, in which case the previous configuration file is saved as 30 | /etc/pdnsd.conf.save 31 | -------------------------------------------------------------------------------- /contrib/change_pdnsd_server_ip.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # A Perl script to change the ip addresses of dns servers 4 | # in the pdnsd configuration file. 5 | # 6 | # Written by Paul A. Rombouts 7 | # 8 | # This file Copyright 2002, 2004 Paul A. Rombouts 9 | # It may be distributed under the GNU Public License, version 2, or 10 | # any higher version. See section COPYING of the GNU Public license 11 | # for conditions under which this file may be redistributed. 12 | # 13 | 14 | use strict; 15 | 16 | unless(@ARGV) {die "Error: no label specified.\n"} 17 | my $label=shift; 18 | unless(@ARGV) {die "Error: no DNS addresses specified.\n"} 19 | my $dns_str=shift; 20 | my $pdnsd_conf='/etc/pdnsd.conf'; 21 | if(@ARGV) { 22 | $pdnsd_conf=shift; 23 | if(@ARGV) {warn "Warning: spurious arguments ignored: @ARGV\n"} 24 | } 25 | 26 | #unless($label =~ /^\".*\"$/) {$label="\"$label\""} 27 | #unless($dns_str =~ /^\".*\"$/) {$dns_str =~ s/^[\s,]*/\"/; $dns_str =~ s/[\s,]*$/\"/} 28 | #unless($dns_str =~ /\"\s*\,\s*\"/) {$dns_str =~ s/[\s,]+/","/g} 29 | 30 | my @lines=(); 31 | my $found_section=0; 32 | my $changed=0; 33 | my $ip_patt = qr/^((?:[^#]*?(?:\{|;))*?)(\s*ip\s*=\s*)("?[\w.:]+"?(?:\s*,\s*"?[\w.:]+"?)*)\s*;/; 34 | 35 | open(CONFFILE,$pdnsd_conf) or die "Can't open $pdnsd_conf: $!\n"; 36 | 37 | while() { 38 | if(/^\s*server\s*\{/) { 39 | my $sect_beg=$#lines+1; 40 | my $sect_end; 41 | my $found_label=0; 42 | LOOP: { 43 | do { 44 | push @lines,$_; 45 | if(/^(?:.*(?:\{|;))?\s*label\s*=\s*"?\Q$label\E"?\s*;/) { 46 | if($found_label++) { 47 | warn "Server section with multiple labels found.\n"; 48 | close(CONFFILE); 49 | exit 2; 50 | } 51 | } 52 | if(/\}\s*$/) { 53 | $sect_end=$#lines; 54 | last LOOP; 55 | } 56 | } while(); 57 | } 58 | unless(defined($sect_end)) { 59 | warn "Server section without proper ending found.\n"; 60 | close(CONFFILE); 61 | exit 2; 62 | } 63 | if(!$found_label) {next} 64 | if(!($found_section++)) { 65 | my $found_ip=0; 66 | for(my $i=$sect_beg; $i<=$sect_end;++$i) { 67 | if($lines[$i] =~ $ip_patt) { 68 | my $matched=''; my $rest; 69 | do { 70 | $rest=$'; 71 | if(!($found_ip++)) { 72 | if($3 eq $dns_str) { 73 | $matched.=$&; 74 | } 75 | else { 76 | $matched.="$1$2$dns_str;"; 77 | $changed=1; 78 | } 79 | } 80 | else { 81 | $matched.=$1; 82 | $changed=1; 83 | } 84 | } while($rest =~ $ip_patt); 85 | $lines[$i] = $matched.$rest; 86 | } 87 | } 88 | if(!$found_ip) { 89 | unless($lines[$sect_end] =~ s/\}\s*$/ ip=$dns_str;\n$&/) { 90 | warn "Can't add ip specification to server section labeled $label.\n"; 91 | close(CONFFILE); 92 | exit 2; 93 | } 94 | $changed=1; 95 | } 96 | } 97 | else { 98 | splice @lines,$sect_beg; 99 | $changed=1; 100 | } 101 | } 102 | else {push @lines,$_} 103 | } 104 | 105 | close(CONFFILE) or die "Can't close $pdnsd_conf: $!\n"; 106 | 107 | if(!$found_section) { 108 | warn "No server sections labeled $label found.\n"; 109 | exit 2; 110 | } 111 | elsif(!$changed) { 112 | exit 0; 113 | } 114 | 115 | rename($pdnsd_conf,"$pdnsd_conf.save") or die "Can't rename $pdnsd_conf: $!\n"; 116 | 117 | unless((open(CONFFILE,">$pdnsd_conf") or (warn("Can't open $pdnsd_conf for writing: $!\n"),0)) and 118 | (print CONFFILE (@lines) or (warn("Can't write to $pdnsd_conf: $!\n"),0)) and 119 | (close(CONFFILE) or (warn("Can't close $pdnsd_conf after writing: $!\n"),0))) { 120 | rename("$pdnsd_conf.save",$pdnsd_conf) or die "Can't rename $pdnsd_conf.save: $!\n"; 121 | exit 3; 122 | } 123 | 124 | exit 1; 125 | -------------------------------------------------------------------------------- /contrib/dhcp2pdnsd: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # dhcp2pdnsd Start/Stop DHCP to DNS update script 4 | # 5 | # chkconfig: 345 96 99 6 | # description: DHCP to DNS update script 7 | # processname: dhcp2pdnsd.pl 8 | # 9 | # $Id: dhcp2pdnsd,v 1.1 2001/03/25 20:01:34 tmm Exp $ 10 | 11 | where="/usr/local/bin/" 12 | name="pdnsd_dhcp.pl" 13 | 14 | # Source function library. 15 | . /etc/rc.d/init.d/functions 16 | 17 | # Get config. 18 | . /etc/sysconfig/network 19 | 20 | # See how we were called. 21 | case "$1" in 22 | start) 23 | $where$name > /dev/null 2> /dev/null & 24 | action "Starting DHCP to DNS update script: " /bin/true 25 | ;; 26 | stop) 27 | p=`ps h -C $name | awk '{print $1}'` 28 | [ $p -gt 0 ] 2> /dev/null && kill $p && action "Stopping DHCP to DNS update script: " /bin/true 29 | [ $p -gt 0 ] 2> /dev/null || action "Stopping DHCP to DNS update script: " /bin/false 30 | ;; 31 | status) 32 | p=`ps h -C $name | awk '{print $1}'` 33 | [ $p -gt 0 ] 2> /dev/null && echo 'running as '$p 34 | [ $p -gt 0 ] 2> /dev/null || echo 'not running' 35 | ;; 36 | restart|reload) 37 | $0 stop 38 | $0 start 39 | ;; 40 | *) 41 | echo "Usage: dhcp2pdnsd {start|stop|status|restart|reload}" 42 | exit 1 43 | esac 44 | 45 | exit 0 46 | -------------------------------------------------------------------------------- /contrib/pdnsd_dhcp.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # $Id: pdnsd_dhcp.pl,v 1.2 2001/03/25 20:01:34 tmm Exp $ 3 | ########################################################################## 4 | # 5 | # Filename: pdnsd_dhcp.pl 6 | # Description: Dynamic DNS-DHCP update script for pdnsd 7 | # Author: Mike Stella 8 | # Modified by: Marko Stolle 9 | # Created: November 19, 2001 10 | # Last Updated: February 28, 2001 11 | # Email: fwd2m@gmx.de 12 | # 13 | ########################################################################### 14 | # 15 | # This code is Copyright (c) 1998-2001 by Mike Stella and Marko Stolle 16 | # 17 | # NO WARRANTY is given for this program. If it doesn't 18 | # work on your system, sorry. If it eats your hard drive, 19 | # again, sorry. It works fine on mine. Good luck! 20 | # 21 | # This program is free software; you can redistribute it and/or modify 22 | # it under the terms of the GNU General Public License as published by 23 | # the Free Software Foundation; either version 2 of the License, or 24 | # (at your option) any later version. 25 | # 26 | # This program is distributed in the hope that it will be useful, 27 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | # GNU General Public License for more details. 30 | # 31 | # You should have received a copy of the GNU General Public License 32 | # along with this program; if not, write to the Free Software 33 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 34 | # 35 | ########################################################################### 36 | # 37 | # This script reads a dhcpd.leases file and dynamically updates pdnsd with 38 | # hostname and ip information. 39 | # 40 | # It assumes that your DHCP server recieves hostnames from the 41 | # clients, and that your clients offer their hostnames to the server. 42 | # Some versions of Linux DHCP clients don't do that. I use ISC's 43 | # DHCPD, found at http://www.isc.org - though others may work just 44 | # fine. 45 | # 46 | # This version of the script updates the pdnsd database. The status 47 | # control socket of pdnsd has to be enabled (psnsd -d -s). 48 | # 49 | ########################################################################### 50 | # 51 | # 02/20/2001 - first working version 52 | # 02/21/2001 - security patches by Thomas Moestl 53 | # 02/22/2001 - re-read dhcpd.leases if ttl has expireds since last update 54 | # 02/24/2001 - try to get domainname if not specified 55 | # 02/28/2001 - randomized temporary filename 56 | # added possibility to save some RAM (read below) 57 | # 58 | ########################################################################### 59 | 60 | 61 | # You may save some memory if you use absolute values with sysopen 62 | # in sub update_dns and don't use tmpnam().. 63 | # Just switch the '#' in front of the 'until sysopen' in the sub 64 | # update_dns, check the necessary modes on your system using save_ram.pl 65 | # and add a '#' in front of the following three lines. 66 | # Not using the tmpnam() function may open a security breach on systems 67 | # with not absolute trustworthy local users (Risk: a user may write a 68 | # script which creates files with the same names as this script and block 69 | # it that way. Unlikely because the filenames are now even without tmpnam() 70 | # randomized and an attacker has to create a very large number of files.) 71 | 72 | use Fcntl; 73 | use strict; 74 | use POSIX qw(tmpnam); 75 | 76 | $|=1; 77 | 78 | ########################################################################### 79 | ### Globals - you can change these as needed 80 | 81 | # Domain name 82 | # if not changed script will try to get it from the system 83 | my $domain_name = "domain"; 84 | 85 | # DHCPD lease file 86 | my $lease_file = "/var/lib/dhcp/dhcpd.leases"; 87 | 88 | # path to pdnsd-ctl 89 | my $pdnsd_ctl = "/usr/local/sbin/pdnsd-ctl"; 90 | 91 | # owning name server for the newly added records 92 | my $nameserver = "localhost."; 93 | 94 | # TTL (Time To Live) for the new records 95 | my $ttl = "86400"; 96 | 97 | # number of seconds to check the lease file for updates 98 | my $update_freq = 30; 99 | 100 | my $debug = 0; 101 | 102 | ########################################################################### 103 | ### Don't mess with anything below unless you REALLY need to modify the 104 | ### code. And if you do, please let me know, I'm always interested in 105 | ### in improving this program. 106 | 107 | # Make a pid file 108 | `echo $$ > /var/run/pdnsd_update.pid`; 109 | 110 | my $logstr; 111 | my $modtime = 0; 112 | my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP}; 113 | 114 | use vars qw (%db); 115 | 116 | my $version = "1.03"; 117 | 118 | 119 | ########################################################################### 120 | # Main Loop 121 | 122 | # try to find domainname if necessary 123 | if ($domain_name eq "domain") { 124 | $domain_name = `dnsdomainname`; 125 | } 126 | else { 127 | $domain_name = "$domain_name\n"; 128 | } 129 | 130 | while (1) { 131 | 132 | # check the file's last updated time, if it's been changed, update 133 | # the DNS and save the time. Update DNS even if there a no changes on 134 | # the leases file if ttl since last DNS update has expired. 135 | # This will ALWAYS run once - on startup, since $modtime starts at zero. 136 | 137 | 138 | my @stats = stat ($lease_file); 139 | 140 | 141 | if (($stats[9] > $modtime) or (time >= $modtime+$ttl)){ 142 | 143 | # clear the old hash 144 | undef %db; 145 | 146 | printf STDERR "updating DNS with dhcpd.leases\n"; 147 | $modtime = time; 148 | &read_lease_file; 149 | &update_dns; 150 | } 151 | 152 | # wait till next check time 153 | sleep $update_freq; 154 | 155 | } # end main 156 | ########################################################################### 157 | 158 | 159 | ### write out the import file 160 | sub update_dns { 161 | my ($ip, $hostname, $fname); 162 | 163 | do { $fname = tmpnam() } 164 | until sysopen(DNSFILE, $fname, O_WRONLY|O_CREAT|O_EXCL, 0600); 165 | # do { $fname = "$temp_dir/d2d".int(rand(time())) } 166 | # until sysopen(DNSFILE, $fname, 1|64|128, 0600); 167 | 168 | while (($hostname,$ip) = each (%db)) { 169 | print DNSFILE "$ip $hostname.$domain_name"; 170 | } 171 | close DNSFILE; 172 | 173 | system ("$pdnsd_ctl source $fname $nameserver $ttl"); 174 | unlink($fname); 175 | } 176 | 177 | 178 | ### reads the lease file & makes a hash of what's in there. 179 | sub read_lease_file { 180 | 181 | unless (open(LEASEFILE,$lease_file)) { 182 | #`logger -t dns_update.pl error opening dhcpd lease file`; 183 | print STDERR "Can't open lease file\n"; 184 | return; 185 | } 186 | 187 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); 188 | my $curdate = sprintf "%02d%02d%02d%02d%02d%20d%20d", 189 | ($year+1900),($mon+1),$mday,$hour,$min,$sec; 190 | 191 | ## Loop here, reading from LEASEFILE 192 | while () { 193 | my ($ip, $hostname, $mac, $enddate,$endtime); 194 | 195 | if (/^\s*lease/i) { 196 | 197 | # find ip address 198 | $_ =~ /^\s*lease\s+(\S+)/; 199 | $ip = $1; 200 | 201 | # do the rest of the block - we're interested in hostname, 202 | # mac address, and the lease time 203 | while ($_ !~ /^}/) { 204 | $_ = ; 205 | # find hostname 206 | if ($_ =~ /^\s*client/i) { 207 | #chomp $_; 208 | #chop $_; 209 | $_ =~ /\"(.*)\"/; 210 | $hostname = $1; 211 | 212 | # change spaces to dash, remove dots - microsoft 213 | # really needs to not do this crap 214 | $hostname =~ s/\s+/-/g; 215 | $hostname =~ s/\.//g; 216 | } 217 | # get the lease end date 218 | elsif ($_ =~ /^\s*ends/i) { 219 | $_ =~ m/^\s*ends\s+\d\s+([^;]+);/; 220 | $enddate = $1; 221 | $enddate =~ s|[/: ]||g; 222 | } 223 | } 224 | # lowercase it - stupid dhcp clients 225 | $hostname =~ tr/[A-Z]/[a-z]/; 226 | 227 | ($debug < 1 ) || print STDERR "$hostname $ip $enddate $curdate\n"; 228 | 229 | # Store hostname/ip in hash - this way we can do easy dupe checking 230 | if (($hostname ne "") and ($enddate > $curdate)) { 231 | $db{$hostname} = $ip; 232 | } 233 | } 234 | } 235 | close LEASEFILE; 236 | } 237 | 238 | ### left around for testing 239 | sub print_db { 240 | my ($key,$value); 241 | 242 | while (($key,$value) = each (%db)) { 243 | print "$key - $value\n"; 244 | } 245 | } 246 | 247 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | man_MANS = pdnsd.8 pdnsd-ctl.8 pdnsd.conf.5 3 | 4 | # Note: pdnsd-ctl.8, pdnsd.conf.5.in, dl.html and the txt docs are handled by dist-hook rule. 5 | EXTRA_DIST = pdnsd.conf.in pdnsd.8.in \ 6 | html/dl.html.in html/doc.html html/faq.html html/index.html \ 7 | doc_makefile html/doc_makefile txt/doc_makefile \ 8 | html2confman.pl html/htmlsubst.pl 9 | 10 | # XXX: Do not insist to set the config file owner to root to avoid breaking RPM 11 | # builds 12 | install-data-hook: 13 | $(mkinstalldirs) "$(DESTDIR)$(sysconfdir)" 14 | if test `whoami` = "root"; then \ 15 | $(INSTALL) -o 0 -g 0 -m 644 pdnsd.conf "$(DESTDIR)$(sysconfdir)/pdnsd.conf.sample" ; \ 16 | else \ 17 | $(INSTALL) -m 644 pdnsd.conf "$(DESTDIR)$(sysconfdir)/pdnsd.conf.sample" ; \ 18 | fi 19 | 20 | dist-hook: doc_makefile 21 | @$(MAKE) -f doc_makefile doc 22 | cp -p --parents pdnsd-ctl.8 pdnsd.conf.5.in \ 23 | html/dl.html txt/faq.txt txt/intro.txt txt/manual.txt \ 24 | $(distdir) 25 | 26 | distclean-local: doc_makefile 27 | @$(MAKE) -f doc_makefile clean 28 | 29 | -------------------------------------------------------------------------------- /doc/doc_makefile: -------------------------------------------------------------------------------- 1 | # This file was written by Paul Rombouts. 2 | # Because pdnsd currently has a very idiosyncratic method of building documentation 3 | # I prefer to keep the actual build rules outside of the Makefiles an ordinary user 4 | # would use to compile pdnsd and therefore I have put them into separate 'doc_makefile's. 5 | # 6 | # To rebuild pdnsd docs after you have modified something that other files depend on, 7 | # run 'make -f doc_makefile doc' in the doc/ directory. 8 | # This makefile is also invoked when you build a pdnsd distribution tarball 9 | # using 'make dist' in the toplevel pdnsd source directory. 10 | # 11 | # If anyone thinks there is a much more elegant method for building the pdnsd docs 12 | # using a conventional autoconf/automake process, please let me know. 13 | 14 | versionfile = ../version 15 | 16 | doc: pdnsd-ctl.8 pdnsd.conf.5.in html txt 17 | .PHONY: pdnsd-ctl.8 doc html txt clean 18 | 19 | pdnsd-ctl.8: 20 | @pver=`cat $(versionfile)` && \ 21 | mver=`perl -e 'while(<>) {if(/^\s*\.TH(?:\s+(?:"[^"]*"|[^"\s]+)){3}\s+"pdnsd\s+([^"]*)"/) {print "$$1\n";exit 0}} \ 22 | die "Cannot find version in $$ARGV\n"' $@` && { \ 23 | test "$$mver" = "$$pver" || { \ 24 | perl -p -i.makesave -e 's/^(\s*\.TH(?:\s+(?:"[^"]*"|[^"\s]+)){3}\s+"pdnsd\s+)[^"]*(")/$${1}'"$$pver"'$${2}/' $@ && \ 25 | echo "Updated version in $@: $$mver -> $$pver"; \ 26 | }; \ 27 | } 28 | 29 | pdnsd.conf.5.in: html/doc.html html2confman.pl 30 | perl html2confman.pl $< > $@ 31 | 32 | html txt: 33 | @cd $@ && $(MAKE) -f doc_makefile 34 | 35 | clean: 36 | @rm -fv pdnsd.conf.5.in 37 | @cd html && $(MAKE) -f doc_makefile clean 38 | @cd txt && $(MAKE) -f doc_makefile clean 39 | -------------------------------------------------------------------------------- /doc/html/dl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | pdnsd Download Page 5 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 22 | 25 | 28 | 31 | 32 |
17 | pdnsd Homepage 18 | 20 | pdnsd FAQ 21 | 23 | Documentation 24 | 26 | GNU GPL (pdnsd's License) 27 | 29 | Download Section 30 |
33 | 34 |

pdnsd Download Page

35 | 36 |

The original author of pdnsd is Thomas Moestl, 37 | but since 2003, he no longer maintains pdnsd. 38 | However, Paul A. Rombouts has extensively revised the code and maintains 39 | a version with many fixes and improvements at 40 | http://members.home.nl/p.a.rombouts/pdnsd.html.
41 | He has pre-patched tarballs and RPM packages available for download at this site.
42 |

43 |

44 | If you are interested in the very latest code or if you want to participate in 45 | pdnsd development, checkout the pdnsd git repository 46 | at gitorious.org. 47 |

48 | 49 | The most recent tarball is pdnsd-1.2.9b-par.tar.gz 50 | (GPG signature).
51 | The most recent RPM packages are: 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 75 | 76 |
Package NameSizeDescription
pdnsd-1.2.9b-par.src.rpm514kBSource RPM (binary packages can also be built directly from the tarball). 62 |
pdnsd-1.2.9b-par_sl6.i686.rpm???i686 binary built on a Scientific Linux 6.2 system. 68 |
pdnsd-1.2.9b-par_sl6.x86_64.rpm282kBx86_64 binary built on a Scientific Linux 6.2 system. 74 |
77 | If you want to check the signatures on these packages you will need a copy of my GPG key 78 | which you can get here 79 | or from a public key server. 80 |

81 | There are also Debian, 82 | Ubuntu, 83 | Gentoo, 84 | Mandriva 85 | and FreeBSD 86 | packages, but these may not include the latest version.
87 | If you are looking for other versions released by Paul Rombouts, visit this 88 | download directory. 89 |

90 |
91 |
92 |

93 | Last revised: 24 Apr 2012 by Paul A. Rombouts 94 |

95 | 96 | 97 | -------------------------------------------------------------------------------- /doc/html/dl.html.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | pdnsd Download Page 5 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 22 | 25 | 28 | 31 | 32 |
17 | pdnsd Homepage 18 | 20 | pdnsd FAQ 21 | 23 | Documentation 24 | 26 | GNU GPL (pdnsd's License) 27 | 29 | Download Section 30 |
33 | 34 |

pdnsd Download Page

35 | 36 |

The original author of pdnsd is Thomas Moestl, 37 | but since 2003, he no longer maintains pdnsd. 38 | However, Paul A. Rombouts has extensively revised the code and maintains 39 | a version with many fixes and improvements at 40 | http://members.home.nl/p.a.rombouts/pdnsd.html.
41 | He has pre-patched tarballs and RPM packages available for download at this site.
42 |

43 |

44 | If you are interested in the very latest code or if you want to participate in 45 | pdnsd development, checkout the pdnsd git repository 46 | at gitorious.org. 47 |

48 | 49 | The most recent tarball is pdnsd-$version.tar.gz 50 | (GPG signature).
51 | The most recent RPM packages are: 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 75 | 76 |
Package NameSizeDescription
pdnsd-$version.src.rpm$sizeof("$HOME/rpmbuild/SRPMS/pdnsd-$version.src.rpm")Source RPM (binary packages can also be built directly from the tarball). 62 |
pdnsd-${version}${extver}.${arch}.rpm$sizeof("$HOME/rpmbuild/RPMS/pdnsd-${version}${extver}.${arch}.rpm")${arch} binary built on a $system. 68 |
pdnsd-${version}${extver}.${arch2}.rpm$sizeof("$HOME/rpmbuild/RPMS/pdnsd-${version}${extver}.${arch2}.rpm")${arch2} binary built on a $system. 74 |
77 | If you want to check the signatures on these packages you will need a copy of my GPG key 78 | which you can get here 79 | or from a public key server. 80 |

81 | There are also Debian, 82 | Ubuntu, 83 | Gentoo, 84 | Mandriva 85 | and FreeBSD 86 | packages, but these may not include the latest version.
87 | If you are looking for other versions released by Paul Rombouts, visit this 88 | download directory. 89 |

90 |
91 |
92 |

93 | Last revised: $date by Paul A. Rombouts 94 |

95 | 96 | 97 | -------------------------------------------------------------------------------- /doc/html/doc_makefile: -------------------------------------------------------------------------------- 1 | 2 | versionfile = ../../version 3 | arch = i686 4 | arch2 = x86_64 5 | extver = _sl6 6 | system = Scientific Linux 6.2 system 7 | 8 | doc: dl.html 9 | .PHONY: doc clean 10 | 11 | # If the existing dl.html contains '???', then certain packages were missing 12 | # during the previous build and dl.html needs to be built again. 13 | ifneq ($(shell grep -F -l -e '???' dl.html),) 14 | .PHONY: dl.html 15 | endif 16 | 17 | dl.html: %.html: %.html.in htmlsubst.pl $(versionfile) 18 | perl htmlsubst.pl version=`cat $(versionfile)` \ 19 | baseurl='http://members.home.nl/p.a.rombouts/pdnsd/' \ 20 | arch=$(arch) arch2=$(arch2) extver=$(extver) system="$(system)" $< > $@ 21 | 22 | clean: 23 | @rm -fv dl.html 24 | -------------------------------------------------------------------------------- /doc/html/htmlsubst.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # Primitive ad-hoc script for updating pdnsd html doc files. 4 | # Written by Paul Rombouts. 5 | 6 | use strict; 7 | use integer; 8 | use POSIX qw(strftime); 9 | 10 | my %paramvals=(); 11 | 12 | while(@ARGV && $ARGV[0]=~/^([^=]*)=(.*)$/) { 13 | my $param=$1; my $val=$2; 14 | if($param =~ /^[[:alpha:]]\w*$/) { 15 | $paramvals{$param}=$val; 16 | } 17 | else {warn "Warning: invalid parameter '$param' ignored.\n"} 18 | shift @ARGV; 19 | } 20 | 21 | sub sizeof { 22 | my($arg)=@_; 23 | (my $str= $arg) =~ s/\$(?:([[:alpha:]]\w*)\b|\{([[:alpha:]]\w*)\})/ 24 | defined($paramvals{$+})?$paramvals{$+}:defined($ENV{$+})?$ENV{$+}:''/eg; 25 | my $filename=eval($str); 26 | (-f $filename) or return '???'; 27 | (((-s $filename)+1023)/1024).'kB'; 28 | } 29 | 30 | while(<>) { 31 | s/\$(?:date\b|\{date\})/strftime("%d %b %Y",localtime)/eg; 32 | s/\$sizeof\(([^()]*)\)/sizeof($1)/eg; 33 | s/\$(?:([[:alpha:]]\w*)\b|\{([[:alpha:]]\w*)\})/ 34 | defined($paramvals{$+})?$paramvals{$+}:defined($ENV{$+})?$ENV{$+}:''/eg; 35 | print; 36 | } 37 | -------------------------------------------------------------------------------- /doc/html/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocks/pdnsd/a8e46ccba7b0fa2230d6c42ab6dcd92926f6c21d/doc/html/index.html -------------------------------------------------------------------------------- /doc/html2confman.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # A Perl script for converting pdnsd html documentation to a man page. 4 | # 5 | # Written by Paul A. Rombouts 6 | # 7 | # This file Copyright 2004 Paul A. Rombouts 8 | # It may be distributed under the GNU Public License, version 2, or 9 | # any higher version. See section COPYING of the GNU Public license 10 | # for conditions under which this file may be redistributed. 11 | # 12 | 13 | use strict; 14 | use POSIX qw(strftime); 15 | 16 | 17 | while(<>) { 18 | if(/[^<]*configuration file/i) { 19 | last; 20 | } 21 | } 22 | 23 | exit unless defined($_); 24 | 25 | while(<>) { 26 | if(/[^<]*layout/i) { 27 | last; 28 | } 29 | } 30 | 31 | exit unless defined($_); 32 | 33 | (my $myname=$0) =~ s{.*/}{}; 34 | 35 | print <) { 75 | if(/.*\bpdnsd-ctl\b/) { 76 | last; 77 | } 78 | s{^\s*((?:<[^<>]+>)*?)[\d.]*\s*(.*)((?:<[^<>]+>)*?)(?:
)?\s*$}{.SS $1$2$3\n}i; 79 | if(s{^\s*\s*}{.TP\n}i) {$taggedparagraph=1} 80 | if(m{^\s*}i) {$taggedparagraph=0} 81 | s{^\s*((?:<[^<>]+>)*?)(.*)((?:<[^<>]+>)*?)(?:
)?\s*$}{.B $1$2$3\n}i if $taggedparagraph; 82 | s{^\s*((?:<[^<>]+>)*?or(?:<[^<>]+>)*?)(?:
)?\s*$}{$1\n.PD 0\n.TP\n.PD\n}i if $taggedparagraph; 83 | if(s{^\s*
}{.DS L\n}i) {$displayed=1}
 84 |     s{^\t}{        } if $displayed;
 85 |     if(s{
\s*$}{\n.DE\n\n}i) {$displayed=0} 86 | elsif(!$displayed) {s{^\s*}{}} 87 | s{^\s*
  • }{.IP\n\\(bu }i; 88 | s{
  • }{\n.IP\n\\(bu }i; 89 | s{
      }{\n}i; 90 | s{
    }{\n}i; 91 | s{}{\\fB}ig; 92 | s{}{\\fP}ig; 93 | s{<(i|em)>}{\\fI}ig; 94 | s{}{\\fP}ig; 95 | unless(s{^\s*(<[^<>]+>)*(
    |

    )(<[^<>]+>)*\s*$}{\n}i) { 96 | s{]*>(.*)

    }{\n$1\n}i; 97 | s{^\s*
    }{.br\n}i; 98 | s{
    \s*
    \s*$}{\n\n}i; 99 | s{
    \s*$}{\n.br\n}i; 100 | s{
    }{\n.br\n}i; 101 | s{^\s*(<[^<>]+>)*\s*$}{}; 102 | } 103 | s{<[^<>]+>}{}g; 104 | s{<}{<}ig; 105 | s{>}{>}ig; 106 | s{"}{"}ig; 107 | s{ }{\\ }ig; 108 | s{/var/cache/pdnsd\b}{\@cachedir\@}g; 109 | s{(? 132 | .UE 133 | and was extensively revised by Paul A. Rombouts 134 | .UR 135 | 136 | .UE 137 | (for versions 1.1.8b1\\-par and later). 138 | .PP 139 | Several others have contributed to \\fBpdnsd\\fP; see files in the source or 140 | \\fB/usr/share/doc/pdnsd/\\fP directory. 141 | .PP 142 | This man page was automatically generated from the html documentation for \\fBpdnsd\\fP, 143 | using a customized Perl script written by Paul A. Rombouts. 144 | ENDOFTRAILER 145 | 146 | if(defined($_)) { 147 | while(<>) { 148 | if(/last\s+revised/i) { 149 | s{^\s*}{}; 150 | s{<[^<>]+>}{}g; 151 | s{<}{<}ig; 152 | s{>}{>}ig; 153 | s{"}{"}ig; 154 | s{ }{\\ }ig; 155 | print ".PP\n"; 156 | print; 157 | last; 158 | } 159 | } 160 | } 161 | exit; 162 | -------------------------------------------------------------------------------- /doc/pdnsd-ctl.8: -------------------------------------------------------------------------------- 1 | .\" This manpage has been automatically generated by docbook2man-spec 2 | .\" from a DocBook document. docbook2man-spec can be found at: 3 | .\" 4 | .\" Please send any bug reports, improvements, comments, patches, 5 | .\" etc. to Steve Cheng . 6 | .\" This manpage has been edited manually by Paul A. Rombouts. 7 | .TH "PDNSD\-CTL" "8" "Sep 2008" "pdnsd 1.2.9b-par" "" 8 | .SH NAME 9 | \fBpdnsd\-ctl\fP \- controls pdnsd 10 | .SH SYNOPSIS 11 | .sp 12 | \fBpdnsd\-ctl\fP [\fB\-c\fP \fIcachedir\fP] [\fB\-q\fP] \fIcommand\fP [\fIarguments\fP] 13 | .SH "DESCRIPTION" 14 | .PP 15 | \fBpdnsd\-ctl\fP controls \fBpdnsd\fP, a proxy dns server with permanent caching. 16 | Note that the status control socket must be enabled (by specifying an option on 17 | the pdnsd command line or in the configuration file) before you can use 18 | \fBpdnsd\-ctl\fP. 19 | .PP 20 | .TP 21 | \fB\-c\fP \fIcachedir\fP 22 | Set the cache directory to \fIcachedir\fP (must match pdnsd setting). 23 | This is only necessary if the directory differs from the default specified 24 | at compile time. 25 | .TP 26 | \fB\-q\fP 27 | Be quiet unless output is specified by the command or something goes wrong. 28 | .SH "COMMANDS" 29 | .TP 30 | \fBhelp\fP\ \ \ [no arguments] 31 | 32 | Print a command summary. 33 | .TP 34 | \fBversion\fP\ [no arguments] 35 | 36 | Print version and license info. 37 | .TP 38 | \fBstatus\fP\ [no arguments] 39 | 40 | Print a description of pdnsd's cache status, thread status and configuration. 41 | Also shows which remote name servers are assumed to be available. 42 | .TP 43 | \fBserver\fP\ (\fIindex\fP|\fIlabel\fP) (\fBup\fP|\fBdown\fP|\fBretest\fP) [\fIdns1\fP[,\fIdns2\fP[,...]]] 44 | 45 | Set the status of the servers with the given index or label to up or down, or 46 | force a retest. The index is assigned in the order of definition in pdnsd.conf 47 | starting with 0. Use the status command to view the indexes. You can specify all 48 | instead of an index to perform the action for all servers registered with pdnsd. 49 | .IP 50 | An optional third argument can be given consisting of a list of IP addresses 51 | separated by commas or white-space characters. This list will replace the 52 | addresses of name servers used by pdnsd for the given server section. This 53 | feature is useful for run-time configuration of pdnsd with dynamic DNS data in 54 | scripts called by ppp or DHCP clients. The last argument may also be an empty 55 | string, which causes existing IP addresses to be removed and the corresponding 56 | server section to become inactive. 57 | .TP 58 | \fBrecord\fP\ \fIname\fP (\fBdelete\fP|\fBinvalidate\fP) 59 | 60 | Delete or invalidate the records of the given domain name if it is in the cache. 61 | Invalidation means that the records are marked as timed out, and will be 62 | reloaded if possible. For local records (i.e., records that were given in the 63 | config file using a rr section, records read from a hosts-style file and records 64 | added using pdnsd-ctl), invalidation has no effect. Deletion will work, though. 65 | .TP 66 | \fBsource\fP\ \fIfn\fP \fIowner\fP [\fIttl\fP] [(\fBon\fP|\fBoff\fP)] [\fBnoauth\fP] 67 | 68 | Load a hosts-style file. Works like using the pdnsd source configuration section. 69 | Owner and ttl are used as in the source section. ttl has a default 70 | of 900 (it does not need to be specified). The next to last argument corresponds 71 | to the serve_aliases option, and is off by default. 72 | \fBnoauth\fP is used to make the domains non-authoritative 73 | (this is similar to setting authrec=off in the config file, 74 | please consult the 75 | .BR pdnsd.conf (5) 76 | man page for what that means). 77 | fn is the name of the file, which must be readable by pdnsd. 78 | .TP 79 | \fBadd\fP\ \ \ \ \fBa\fP \fIaddr\fP \fIname\fP [\fIttl\fP] [\fBnoauth\fP] 80 | .TP 81 | \fBadd\fP\ \ \ \ \fBaaaa\fP \fIaddr\fP \fIname\fP [\fIttl\fP] [\fBnoauth\fP] 82 | .TP 83 | \fBadd\fP\ \ \ \ \fBptr\fP \fIhost\fP \fIname\fP [\fIttl\fP] [\fBnoauth\fP] 84 | .TP 85 | \fBadd\fP\ \ \ \ \fBcname\fP \fIhost\fP \fIname\fP [\fIttl\fP] [\fBnoauth\fP] 86 | .TP 87 | \fBadd\fP\ \ \ \ \fBmx\fP \fIhost\fP \fIname\fP \fIpref\fP [\fIttl\fP] [\fBnoauth\fP] 88 | 89 | Add a record of the given type to the pdnsd cache, replacing existing 90 | records for the same name and type. The 2nd argument corresponds 91 | to the value of the option in the rr section that is named like 92 | the first argument. The addr argument may be a list of IP addresses, 93 | separated by commas or white space. 94 | The ttl is optional, the default is 900 seconds. 95 | \fBnoauth\fP is used to make the domains non-authoritative 96 | (this is similar to setting authrec=off in the config file, 97 | please consult the 98 | .BR pdnsd.conf (5) 99 | man page for what that means). 100 | If you want no other record than the newly added in the cache, do 101 | \fBpdnsd\-ctl\fP\ \fBrecord\fP\ \fIname\fP\ \fBdelete\fP 102 | before adding records. 103 | .TP 104 | \fBneg\fP\ \ \ \ \fIname\fP [\fItype\fP] [\fIttl\fP] 105 | 106 | Add a negatively cached record to pdnsd's cache, replacing existing 107 | records for the same name and type. If no type is given, the whole 108 | domain is cached negatively. For negatively cached records, errors are 109 | immediately returned on a query, without querying other servers first. 110 | The ttl is optional, the default is 900 seconds. 111 | .TP 112 | \fBconfig\fP\ \fIfilename\fP 113 | 114 | Reload pdnsd's configuration file. 115 | .br 116 | The config file must be owned by the uid that pdnsd had when it was started, 117 | and be readable by pdnsd's run_as uid. 118 | If no file name is specified, the config file used at start-up is reloaded. 119 | Note that some configuration changes, like the port or IP address pdnsd listens on, 120 | cannot be made this way and you will receive an error message. 121 | In these cases, you will have to restart pdnsd instead. 122 | .TP 123 | \fBinclude\fP\ \fIfilename\fP 124 | 125 | Parse an include file. 126 | .br 127 | The include file may contain the same 128 | type of sections as a config file, expect for global and server 129 | sections, which are not allowed. This command can be used to add data 130 | to the cache without reconfiguring pdnsd. 131 | .TP 132 | \fBeval\fP\ \ \ \fIstring\fP 133 | 134 | Parse a string as if part of an include file. 135 | .br 136 | The string should hold one or more complete configuration sections, 137 | but no global and server sections, which are not allowed. 138 | If multiple strings are given, they will be joined using newline chars 139 | and parsed together. 140 | .TP 141 | \fBempty\-cache\fP\ [[+|-]\fIname\fP ...] 142 | 143 | Delete all entries in the cache matching include/exclude rules. 144 | .br 145 | If no arguments are provided, the cache is completely emptied, 146 | freeing all existing entries. 147 | Note that this also removes local records, as defined by the config file. 148 | To restore local records, run "pdnsd-ctl\ config" immediately afterwards. 149 | .br 150 | If one or more arguments are provided, these are interpreted as 151 | include/exclude names. If an argument starts with a '+' the name is to 152 | be included. If an argument starts with a '-' it is to be excluded. 153 | If an argument does not begin with '+' or '-', a '+' is assumed. 154 | If the domain name of a cache entry ends in one of the names in the 155 | list, the first match will determine what happens. If the matching name 156 | is to be included, the cache entry is deleted, otherwise it remains. 157 | If there are no matches, the default action is not to delete. 158 | .TP 159 | \fBdump\fP\ \ \ [\fIname\fP] 160 | 161 | Print information stored in the cache about \fIname\fP. 162 | If \fIname\fP begins with a dot and is not the root domain, information 163 | about the names in the cache ending in \fIname\fP (including \fIname\fP without 164 | the leading dot) will be printed. 165 | If \fIname\fP is not specified, information about all the names in the cache 166 | will be printed. 167 | .TP 168 | \fBlist\-rrtypes\fP [no arguments] 169 | 170 | List available rr types for the neg command. Note that those are only 171 | used for the neg command, not for add! 172 | .SH "BUGS" 173 | .PP 174 | If you pipe the output of \fBdump\fP command through an application that 175 | reads only part of the output and then blocks (such as more or less), 176 | pdnsd threads trying to add new entries to the cache will be suspended 177 | until the pipe is closed. 178 | It is preferable to capture the output in a file in such a case. 179 | .br 180 | Report any remaining bugs to the authors. 181 | .SH "AUTHORS" 182 | .PP 183 | Thomas Moestl 184 | .UR 185 | 186 | .UE 187 | .br 188 | Paul A. Rombouts 189 | .UR 190 | 191 | .UE 192 | (for versions 1.1.8b1\-par and later) 193 | .PP 194 | Last revised: 04 Sep 2008 by Paul A. Rombouts. 195 | .SH "SEE ALSO" 196 | .PP 197 | .BR pdnsd (8), 198 | .BR pdnsd.conf (5) 199 | -------------------------------------------------------------------------------- /doc/pdnsd.conf.in: -------------------------------------------------------------------------------- 1 | // Sample pdnsd configuration file. Must be customized to obtain a working pdnsd setup! 2 | // Read the pdnsd.conf(5) manpage for an explanation of the options. 3 | // Add or remove '#' in front of options you want to disable or enable, respectively. 4 | // Remove '/*' and '*/' to enable complete sections. 5 | 6 | global { 7 | perm_cache=1024; 8 | cache_dir="@cachedir@"; 9 | # pid_file = /var/run/pdnsd.pid; 10 | run_as="@def_id@"; 11 | server_ip = 127.0.0.1; # Use eth0 here if you want to allow other 12 | # machines on your network to query pdnsd. 13 | status_ctl = on; 14 | # paranoid=on; # This option reduces the chance of cache poisoning 15 | # but may make pdnsd less efficient, unfortunately. 16 | query_method=udp_tcp; 17 | min_ttl=15m; # Retain cached entries at least 15 minutes. 18 | max_ttl=1w; # One week. 19 | timeout=10; # Global timeout option (10 seconds). 20 | neg_domain_pol=on; 21 | udpbufsize=1024; # Upper limit on the size of UDP messages. 22 | } 23 | 24 | # The following section is most appropriate if you have a fixed connection to 25 | # the Internet and an ISP which provides good DNS servers. 26 | server { 27 | label= "myisp"; 28 | ip = 192.168.0.1; # Put your ISP's DNS-server address(es) here. 29 | # proxy_only=on; # Do not query any name servers beside your ISP's. 30 | # This may be necessary if you are behind some 31 | # kind of firewall and cannot receive replies 32 | # from outside name servers. 33 | timeout=4; # Server timeout; this may be much shorter 34 | # that the global timeout option. 35 | uptest=if; # Test if the network interface is active. 36 | interface=eth0; # The name of the interface to check. 37 | interval=10m; # Check every 10 minutes. 38 | purge_cache=off; # Keep stale cache entries in case the ISP's 39 | # DNS servers go offline. 40 | edns_query=yes; # Use EDNS for outgoing queries to allow UDP messages 41 | # larger than 512 bytes. May cause trouble with some 42 | # legacy systems. 43 | # exclude=.thepiratebay.org, # If your ISP censors certain names, you may 44 | # .thepiratebay.se, # want to exclude them here, and provide an 45 | # .piratebay.org, # alternative server section below that will 46 | # .piratebay.se; # successfully resolve the names. 47 | } 48 | 49 | /* 50 | # The following section is more appropriate for dial-up connections. 51 | # Read about how to use pdnsd-ctl for dynamic configuration in the documentation. 52 | server { 53 | label= "dialup"; 54 | file = "/etc/ppp/resolv.conf"; # Preferably do not use /etc/resolv.conf 55 | proxy_only=on; 56 | timeout=4; 57 | uptest=if; 58 | interface = ppp0; 59 | interval=10; # Check the interface every 10 seconds. 60 | purge_cache=off; 61 | preset=off; 62 | } 63 | */ 64 | 65 | /* 66 | # The servers provided by OpenDNS are fast, but they do not reply with 67 | # NXDOMAIN for non-existant domains, instead they supply you with an 68 | # address of one of their search engines. They also lie about the addresses of 69 | # of the search engines of google, microsoft and yahoo. 70 | # If you do not like this behaviour the "reject" option may be useful. 71 | server { 72 | label = "opendns"; 73 | ip = 208.67.222.222, 208.67.220.220; 74 | reject = 208.69.32.0/24, # You may need to add additional address ranges 75 | 208.69.34.0/24, # here if the addresses of their search engines 76 | 208.67.219.0/24; # change. 77 | reject_policy = fail; # If you do not provide any alternative server 78 | # sections, like the following root-server 79 | # example, "negate" may be more appropriate here. 80 | timeout = 4; 81 | uptest = ping; # Test availability using ICMP echo requests. 82 | ping_timeout = 100; # ping test will time out after 10 seconds. 83 | interval = 15m; # Test every 15 minutes. 84 | preset = off; 85 | } 86 | */ 87 | 88 | /* 89 | # This section is meant for resolving from root servers. 90 | server { 91 | label = "root-servers"; 92 | root_server = discover; # Query the name servers listed below 93 | # to obtain a full list of root servers. 94 | randomize_servers = on; # Give every root server an equal chance 95 | # of being queried. 96 | ip = 198.41.0.4, # This list will be expanded to the full 97 | 192.228.79.201; # list on start up. 98 | timeout = 5; 99 | uptest = query; # Test availability using empty DNS queries. 100 | # query_test_name = .; # To be used if remote servers ignore empty queries. 101 | interval = 30m; # Test every half hour. 102 | ping_timeout = 300; # Test should time out after 30 seconds. 103 | purge_cache = off; 104 | # edns_query = yes; # Use EDNS for outgoing queries to allow UDP messages 105 | # larger than 512 bytes. May cause trouble with some 106 | # legacy systems. 107 | exclude = .localdomain; 108 | policy = included; 109 | preset = off; 110 | } 111 | */ 112 | 113 | source { 114 | owner=localhost; 115 | # serve_aliases=on; 116 | file="/etc/hosts"; 117 | } 118 | 119 | /* 120 | include {file="/etc/pdnsd.include";} # Read additional definitions from /etc/pdnsd.include. 121 | */ 122 | 123 | rr { 124 | name=localhost; 125 | reverse=on; 126 | a=127.0.0.1; 127 | owner=localhost; 128 | soa=localhost,root.localhost,42,86400,900,86400,86400; 129 | } 130 | 131 | /* 132 | neg { 133 | name=doubleclick.net; 134 | types=domain; # This will also block xxx.doubleclick.net, etc. 135 | } 136 | */ 137 | 138 | /* 139 | neg { 140 | name=bad.server.com; # Badly behaved server you don't want to connect to. 141 | types=A,AAAA; 142 | } 143 | */ 144 | -------------------------------------------------------------------------------- /doc/txt/doc_makefile: -------------------------------------------------------------------------------- 1 | # Makefile for converting pdnsd html documentation to text files. 2 | # This file was based on a Makefile originally written by Thomas Moestl 3 | # and adapted by Paul Rombouts. 4 | 5 | 6 | HTML2TXT=w3m -dump -cols 80 -T text/html 7 | 8 | doc: intro.txt manual.txt faq.txt 9 | .PHONY: doc clean 10 | 11 | intro.txt: ../html/index.html 12 | sed -e 's///-->/g' ../html/index.html | $(HTML2TXT) | sed -e 's/[[:blank:]]\+$$//' > intro.txt 13 | 14 | manual.txt: ../html/doc.html 15 | sed -e 's///-->/g' ../html/doc.html | $(HTML2TXT) | sed -e 's/[[:blank:]]\+$$//' > manual.txt 16 | 17 | faq.txt: ../html/faq.html 18 | sed -e 's///-->/g' ../html/faq.html | $(HTML2TXT) | sed -e 's/[[:blank:]]\+$$//' > faq.txt 19 | 20 | clean: 21 | @rm -fv intro.txt manual.txt faq.txt 22 | -------------------------------------------------------------------------------- /file-list.base.in: -------------------------------------------------------------------------------- 1 | %defattr(-,root,root) 2 | %doc AUTHORS THANKS COPYING COPYING.BSD ChangeLog ChangeLog.old INSTALL NEWS README README.par README.par.old TODO 3 | %config /etc/pdnsd.conf.sample 4 | %attr(750, @def_id@, @def_id@) %dir @cachedir@ 5 | %attr(640, @def_id@, @def_id@) %config @cachedir@/pdnsd.cache 6 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | sbin_PROGRAMS = pdnsd 3 | 4 | pdnsd_CFLAGS = -DCONFDIR='"$(sysconfdir)"' $(thread_CFLAGS) 5 | 6 | pdnsd_SOURCES = conf-parser.c conff.c consts.c debug.c dns.c dns_answer.c \ 7 | dns_query.c error.c helpers.c icmp.c list.c main.c netdev.c rr_types.c \ 8 | status.c servers.c thread.c cache.c hash.c conf-parser.h \ 9 | conf-keywords.h conff.h consts.h debug.h dns.h dns_answer.h \ 10 | dns_query.h error.h helpers.h icmp.h ipvers.h list.h netdev.h \ 11 | rr_types.h servers.h status.h thread.h cache.h hash.h pdnsd_assert.h \ 12 | freebsd_netinet_ip_icmp.h 13 | 14 | EXTRA_DIST = make_rr_types_h.pl rr_types.in 15 | 16 | ## Try to do this last 17 | 18 | SUBDIRS = . pdnsd-ctl rc test 19 | 20 | $(pdnsd_OBJECTS): rr_types.h 21 | 22 | rr_types.h: make_rr_types_h.pl rr_types.in 23 | perl make_rr_types_h.pl rr_types.in > rr_types.h 24 | 25 | -------------------------------------------------------------------------------- /src/conf-keywords.h: -------------------------------------------------------------------------------- 1 | /* conf-keywords.h - Tables used by parser of configuration file. 2 | Based on information previously contained in conf-lex.y and conf-parse.y 3 | 4 | Copyright (C) 2004,2005,2006,2007,2008,2009,2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | enum { 24 | ERROR, 25 | 26 | GLOBAL, 27 | SERVER, 28 | RR, 29 | NEG, 30 | SOURCE, 31 | INCLUDE_F, 32 | 33 | PERM_CACHE, 34 | CACHE_DIR, 35 | SERVER_PORT, 36 | SERVER_IP, 37 | OUTGOING_IP, 38 | SCHEME_FILE, 39 | LINKDOWN_KLUGE, 40 | MAX_TTL, 41 | MIN_TTL, 42 | RUN_AS, 43 | STRICT_SETUID, 44 | USE_NSS, 45 | PARANOID, 46 | IGNORE_CD, 47 | STATUS_CTL, 48 | DAEMON, 49 | C_TCP_SERVER, 50 | PID_FILE, 51 | C_VERBOSITY, 52 | C_QUERY_METHOD, 53 | RUN_IPV4, 54 | IPV4_6_PREFIX, 55 | C_DEBUG, 56 | C_CTL_PERMS, 57 | C_PROC_LIMIT, 58 | C_PROCQ_LIMIT, 59 | TCP_QTIMEOUT, 60 | C_PAR_QUERIES, 61 | C_RAND_RECS, 62 | NEG_TTL, 63 | NEG_RRS_POL, 64 | NEG_DOMAIN_POL, 65 | QUERY_PORT_START, 66 | QUERY_PORT_END, 67 | UDP_BUFSIZE, 68 | DELEGATION_ONLY, 69 | 70 | IP, 71 | PORT, 72 | SCHEME, 73 | UPTEST, 74 | TIMEOUT, 75 | PING_TIMEOUT, 76 | PING_IP, 77 | UPTEST_CMD, 78 | QUERY_TEST_NAME, 79 | INTERVAL, 80 | INTERFACE, 81 | DEVICE, 82 | PURGE_CACHE, 83 | CACHING, 84 | LEAN_QUERY, 85 | EDNS_QUERY, 86 | PRESET, 87 | PROXY_ONLY, 88 | ROOT_SERVER, 89 | RANDOMIZE_SERVERS, 90 | INCLUDE, 91 | EXCLUDE, 92 | POLICY, 93 | REJECTLIST, 94 | REJECTPOLICY, 95 | REJECTRECURSIVELY, 96 | LABEL, 97 | 98 | A, 99 | PTR, 100 | MX, 101 | SOA, 102 | CNAME, 103 | TXT, 104 | SPF, 105 | NAME, 106 | OWNER, 107 | TTL, 108 | TYPES, 109 | FILET, 110 | SERVE_ALIASES, 111 | AUTHREC, 112 | REVERSE 113 | }; 114 | 115 | 116 | /* Table for looking up section headers. Order alphabetically! */ 117 | static const namevalue_t section_headers[]= { 118 | {"global", GLOBAL}, 119 | {"include", INCLUDE_F}, 120 | {"neg", NEG}, 121 | {"rr", RR}, 122 | {"server", SERVER}, 123 | {"source", SOURCE} 124 | }; 125 | 126 | /* Table for looking up global options. Order alphabetically! */ 127 | static const namevalue_t global_options[]= { 128 | {"cache_dir", CACHE_DIR}, 129 | {"ctl_perms", C_CTL_PERMS}, 130 | {"daemon", DAEMON}, 131 | {"debug", C_DEBUG}, 132 | {"delegation_only", DELEGATION_ONLY}, 133 | {"ignore_cd", IGNORE_CD}, 134 | {"interface", SERVER_IP}, 135 | {"ipv4_6_prefix", IPV4_6_PREFIX}, 136 | {"linkdown_kluge", LINKDOWN_KLUGE}, 137 | {"max_ttl", MAX_TTL}, 138 | {"min_ttl", MIN_TTL}, 139 | {"neg_domain_pol", NEG_DOMAIN_POL}, 140 | {"neg_rrs_pol", NEG_RRS_POL}, 141 | {"neg_ttl", NEG_TTL}, 142 | {"outgoing_ip", OUTGOING_IP}, 143 | {"outside_interface", OUTGOING_IP}, 144 | {"par_queries", C_PAR_QUERIES}, 145 | {"paranoid", PARANOID}, 146 | {"perm_cache", PERM_CACHE}, 147 | {"pid_file", PID_FILE}, 148 | {"proc_limit", C_PROC_LIMIT}, 149 | {"procq_limit", C_PROCQ_LIMIT}, 150 | {"query_method", C_QUERY_METHOD}, 151 | {"query_port_end", QUERY_PORT_END}, 152 | {"query_port_start", QUERY_PORT_START}, 153 | {"randomize_recs", C_RAND_RECS}, 154 | {"run_as", RUN_AS}, 155 | {"run_ipv4", RUN_IPV4}, 156 | {"scheme_file", SCHEME_FILE}, 157 | {"server_ip", SERVER_IP}, 158 | {"server_port", SERVER_PORT}, 159 | {"status_ctl", STATUS_CTL}, 160 | {"strict_setuid", STRICT_SETUID}, 161 | {"tcp_qtimeout", TCP_QTIMEOUT}, 162 | {"tcp_server", C_TCP_SERVER}, 163 | {"timeout", TIMEOUT}, 164 | {"udpbufsize", UDP_BUFSIZE}, 165 | {"use_nss", USE_NSS}, 166 | {"verbosity", C_VERBOSITY} 167 | }; 168 | 169 | /* Table for looking up server options. Order alphabetically! */ 170 | static const namevalue_t server_options[]= { 171 | {"caching", CACHING}, 172 | {"device", DEVICE}, 173 | {"edns_query", EDNS_QUERY}, 174 | {"exclude", EXCLUDE}, 175 | {"file", FILET}, 176 | {"include", INCLUDE}, 177 | {"interface", INTERFACE}, 178 | {"interval", INTERVAL}, 179 | {"ip", IP}, 180 | {"label", LABEL}, 181 | {"lean_query", LEAN_QUERY}, 182 | {"ping_ip", PING_IP}, 183 | {"ping_timeout", PING_TIMEOUT}, 184 | {"policy", POLICY}, 185 | {"port", PORT}, 186 | {"preset", PRESET}, 187 | {"proxy_only", PROXY_ONLY}, 188 | {"purge_cache", PURGE_CACHE}, 189 | {"query_test_name", QUERY_TEST_NAME}, 190 | {"randomize_servers", RANDOMIZE_SERVERS}, 191 | {"reject", REJECTLIST}, 192 | {"reject_policy", REJECTPOLICY}, 193 | {"reject_recursively", REJECTRECURSIVELY}, 194 | {"root_server", ROOT_SERVER}, 195 | {"scheme", SCHEME}, 196 | {"timeout", TIMEOUT}, 197 | {"uptest", UPTEST}, 198 | {"uptest_cmd", UPTEST_CMD} 199 | }; 200 | 201 | /* Table for looking up rr options. Order alphabetically! */ 202 | static const namevalue_t rr_options[]= { 203 | {"a", A}, 204 | {"authrec", AUTHREC}, 205 | {"cname", CNAME}, 206 | {"mx", MX}, 207 | {"name", NAME}, 208 | {"ns", OWNER}, 209 | {"owner", OWNER}, 210 | {"ptr", PTR}, 211 | {"reverse", REVERSE}, 212 | {"soa", SOA}, 213 | {"spf", SPF}, 214 | {"ttl", TTL}, 215 | {"txt", TXT} 216 | }; 217 | 218 | /* Table for looking up source options. Order alphabetically! */ 219 | static const namevalue_t source_options[]= { 220 | {"authrec", AUTHREC}, 221 | {"file", FILET}, 222 | {"ns", OWNER}, 223 | {"owner", OWNER}, 224 | {"serve_aliases", SERVE_ALIASES}, 225 | {"ttl", TTL} 226 | }; 227 | 228 | /* Table for looking up include options. Order alphabetically! */ 229 | static const namevalue_t include_options[]= { 230 | {"file", FILET} 231 | }; 232 | 233 | /* Table for looking up neg options. Order alphabetically! */ 234 | static const namevalue_t neg_options[]= { 235 | {"name", NAME}, 236 | {"ttl", TTL}, 237 | {"types", TYPES} 238 | }; 239 | -------------------------------------------------------------------------------- /src/conf-parser.h: -------------------------------------------------------------------------------- 1 | /* conf-parser.h - definitions for parser of pdnsd config files. 2 | The parser was rewritten in C from scratch and doesn't require (f)lex 3 | or yacc/bison. 4 | 5 | Copyright (C) 2004,2008 Paul A. Rombouts. 6 | 7 | This file is part of the pdnsd package. 8 | 9 | pdnsd is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | pdnsd is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with pdnsd; see the file COPYING. If not, see 21 | . 22 | */ 23 | 24 | #ifndef CONF_PARSER_H 25 | #define CONF_PARSER_H 26 | 27 | int confparse(FILE* in, char *prestr, globparm_t *global, servparm_array *servers, int includedepth, char **errstr); 28 | 29 | #endif /* CONF_PARSER_H */ 30 | -------------------------------------------------------------------------------- /src/conff.h: -------------------------------------------------------------------------------- 1 | /* conff.h - Definitions for configuration management. 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef CONFF_H 25 | #define CONFF_H 26 | 27 | /* XXX should use the system defined ones. */ 28 | /* #define MAXPATH 1024 */ 29 | /* #define MAXIFNAME 31 */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "ipvers.h" 37 | #include "list.h" 38 | 39 | /* From main.c */ 40 | #if DEBUG>0 41 | extern short int debug_p; 42 | #else 43 | #define debug_p 0 44 | #endif 45 | extern short int stat_pipe; 46 | extern pthread_t main_thrid; 47 | extern uid_t init_uid; 48 | extern char *conf_file; 49 | 50 | /* ----------- */ 51 | 52 | typedef DYNAMIC_ARRAY(pdnsd_a) *addr_array; 53 | typedef DYNAMIC_ARRAY(pdnsd_a2) *addr2_array; 54 | 55 | typedef struct { 56 | time_t i_ts; 57 | char is_up; 58 | pdnsd_a2 a; 59 | } atup_t; 60 | typedef DYNAMIC_ARRAY(atup_t) *atup_array; 61 | 62 | typedef struct { 63 | unsigned char *domain; 64 | short exact; 65 | short rule; 66 | } slist_t; 67 | typedef DYNAMIC_ARRAY(slist_t) *slist_array; 68 | 69 | typedef struct { 70 | struct in_addr a,mask; 71 | } addr4maskpair_t; 72 | 73 | typedef DYNAMIC_ARRAY(addr4maskpair_t) *a4_array; 74 | 75 | #if ALLOW_LOCAL_AAAA 76 | typedef struct { 77 | struct in6_addr a,mask; 78 | } addr6maskpair_t; 79 | 80 | typedef DYNAMIC_ARRAY(addr6maskpair_t) *a6_array; 81 | #endif 82 | 83 | typedef struct { 84 | unsigned short port; 85 | short uptest; 86 | time_t timeout; 87 | time_t interval; 88 | time_t ping_timeout; 89 | char scheme[32]; 90 | char *uptest_cmd; 91 | char uptest_usr[21]; 92 | char interface[IFNAMSIZ]; 93 | char device[IFNAMSIZ]; 94 | unsigned char *query_test_name; 95 | char *label; 96 | char purge_cache; 97 | char nocache; 98 | char lean_query; 99 | char edns_query; 100 | char is_proxy; 101 | char rootserver; 102 | char rand_servers; 103 | char preset; 104 | char rejectrecursively; 105 | short rejectpolicy; 106 | short policy; 107 | slist_array alist; 108 | atup_array atup_a; 109 | a4_array reject_a4; 110 | #if ALLOW_LOCAL_AAAA 111 | a6_array reject_a6; 112 | #endif 113 | pdnsd_a ping_a; 114 | } servparm_t; 115 | typedef DYNAMIC_ARRAY(servparm_t) *servparm_array; 116 | 117 | typedef unsigned char *zone_t; 118 | typedef DYNAMIC_ARRAY(zone_t) *zone_array; 119 | 120 | typedef struct { 121 | long perm_cache; 122 | char *cache_dir; 123 | char *pidfile; 124 | int port; 125 | pdnsd_a a; 126 | pdnsd_a out_a; 127 | #ifdef ENABLE_IPV6 128 | struct in6_addr ipv4_6_prefix; 129 | #endif 130 | time_t max_ttl; 131 | time_t min_ttl; 132 | time_t neg_ttl; 133 | short neg_rrs_pol; 134 | short neg_domain_pol; 135 | short verbosity; 136 | char run_as[21]; 137 | char daemon; 138 | char debug; 139 | char stat_pipe; 140 | char notcp; 141 | char strict_suid; 142 | char use_nss; 143 | char paranoid; 144 | char lndown_kluge; 145 | char onquery; 146 | char rnd_recs; 147 | int ctl_perms; 148 | char *scheme_file; 149 | int proc_limit; 150 | int procq_limit; 151 | time_t tcp_qtimeout; 152 | time_t timeout; 153 | int par_queries; 154 | int query_method; 155 | int query_port_start; 156 | int query_port_end; 157 | int udpbufsize; 158 | zone_array deleg_only_zones; 159 | } globparm_t; 160 | 161 | typedef struct { 162 | char 163 | #ifdef ENABLE_IPV6 164 | prefix, 165 | #endif 166 | pidfile, 167 | verbosity, 168 | pdnsduser, 169 | daemon, 170 | debug, 171 | stat_pipe, 172 | notcp, 173 | query_method; 174 | } cmdlineflags_t; 175 | 176 | extern globparm_t global; 177 | extern cmdlineflags_t cmdline; 178 | extern servparm_t serv_presets; 179 | 180 | extern servparm_array servers; 181 | 182 | int read_config_file(const char *nm, globparm_t *global, servparm_array *servers, int includedepth, char **errstr); 183 | int reload_config_file(const char *nm, char **errstr); 184 | void free_zone(void *ptr); 185 | void free_slist_domain(void *ptr); 186 | void free_slist_array(slist_array sla); 187 | void free_servparm(servparm_t *serv); 188 | 189 | int report_conf_stat(int f); 190 | #endif 191 | -------------------------------------------------------------------------------- /src/consts.c: -------------------------------------------------------------------------------- 1 | /* consts.c - Common config constants & handling 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2005, 2006, 2007, 2009 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "consts.h" 27 | #include "rr_types.h" 28 | 29 | 30 | /* Order alphabetically!! */ 31 | static const namevalue_t const_dic[]={ 32 | {"auth", C_AUTH}, 33 | {"default", C_DEFAULT}, 34 | {"dev", C_DEV}, 35 | {"diald", C_DIALD}, 36 | {"discover", C_DISCOVER}, 37 | {"domain", C_DOMAIN}, 38 | {"excluded", C_EXCLUDED}, 39 | {"exec", C_EXEC}, 40 | {"fail", C_FAIL}, 41 | {"false", C_OFF}, 42 | {"fqdn_only", C_FQDN_ONLY}, 43 | {"if", C_IF}, 44 | {"included", C_INCLUDED}, 45 | {"negate", C_NEGATE}, 46 | {"no", C_OFF}, 47 | {"none", C_NONE}, 48 | {"off", C_OFF}, 49 | {"on", C_ON}, 50 | {"onquery", C_ONQUERY}, 51 | {"ontimeout", C_ONTIMEOUT}, 52 | {"ping", C_PING}, 53 | {"query", C_QUERY}, 54 | {"simple_only", C_SIMPLE_ONLY}, 55 | {"tcp_only", TCP_ONLY}, 56 | {"tcp_udp", TCP_UDP}, 57 | {"true", C_ON}, 58 | {"udp_only", UDP_ONLY}, 59 | {"udp_tcp", UDP_TCP}, 60 | {"yes", C_ON} 61 | }; 62 | 63 | /* Added by Paul Rombouts */ 64 | static const char *const const_names[]={ 65 | "error", 66 | "on", 67 | "off", 68 | "default", 69 | "discover", 70 | "none", 71 | "if", 72 | "exec", 73 | "ping", 74 | "query", 75 | "onquery", 76 | "ontimeout", 77 | "udp_only", 78 | "tcp_only", 79 | "tcp_udp", 80 | "udp_tcp", 81 | "dev", 82 | "diald", 83 | "included", 84 | "excluded", 85 | "simple_only", 86 | "fqdn_only", 87 | "auth", 88 | "domain", 89 | "fail", 90 | "negate" 91 | }; 92 | 93 | /* compare two strings. 94 | The first one is given as pointer to a char array of length len (which 95 | should not contain any null chars), 96 | the second one as a pointer to a null terminated char array. 97 | */ 98 | inline static int keyncmp(const char *key1, int len, const char *key2) 99 | { 100 | int cmp=strncmp(key1,key2,len); 101 | if(cmp) return cmp; 102 | return -(int)((unsigned char)(key2[len])); 103 | } 104 | 105 | int binsearch_keyword(const char *name, int len, const namevalue_t dic[], int range) 106 | { 107 | int i=0,j=range; 108 | 109 | while(i0) 115 | i=k+1; 116 | else 117 | return dic[k].val; 118 | } 119 | 120 | return 0; 121 | } 122 | 123 | 124 | int lookup_const(const char *name, int len) 125 | { 126 | return binsearch_keyword(name,len,const_dic,sizeof(const_dic)/sizeof(namevalue_t)); 127 | } 128 | 129 | /* Added by Paul Rombouts */ 130 | const char *const_name(int c) 131 | { 132 | return (c>=0 && c. 21 | */ 22 | 23 | 24 | #ifndef CONSTS_H 25 | #define CONSTS_H 26 | 27 | #include 28 | 29 | #define C_RRTOFFS 64 30 | 31 | enum { 32 | C_ERR, 33 | C_ON, 34 | C_OFF, 35 | C_DEFAULT, 36 | C_DISCOVER, 37 | C_NONE, 38 | C_IF, 39 | C_EXEC, 40 | C_PING, 41 | C_QUERY, 42 | C_ONQUERY, 43 | C_ONTIMEOUT, 44 | UDP_ONLY, 45 | TCP_ONLY, 46 | TCP_UDP, 47 | UDP_TCP, 48 | C_DEV, 49 | C_DIALD, 50 | C_INCLUDED, 51 | C_EXCLUDED, 52 | C_SIMPLE_ONLY, 53 | C_FQDN_ONLY, 54 | C_AUTH, 55 | C_DOMAIN, 56 | C_FAIL, 57 | C_NEGATE 58 | }; 59 | 60 | typedef struct { 61 | const char *name; 62 | int val; 63 | } namevalue_t; 64 | 65 | int binsearch_keyword(const char *name, int len, const namevalue_t dic[], int range); 66 | int lookup_const(const char *name, int len); 67 | const char *const_name(int c); /* Added by Paul Rombouts */ 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | /* debug.c - Various debugging facilities 2 | * Copyright (C) 2001 Thomas Moestl 3 | * 4 | * This file is part of the pdnsd package. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include "helpers.h" 31 | #include "error.h" 32 | 33 | 34 | /* 35 | * This is indeed very primitive (it does not track allocation failures 36 | * and so on). It should be expanded some time. 37 | */ 38 | #ifdef ALLOC_DEBUG 39 | void *DBGcalloc(size_t n, size_t sz, char *file, int line) 40 | { 41 | DEBUG_MSG("+ calloc, %s:%d\n", file, line); 42 | return calloc(n, sz); 43 | } 44 | 45 | void *DBGmalloc(size_t sz, char *file, int line) 46 | { 47 | DEBUG_MSG("+ malloc, %s:%d\n", file, line); 48 | return malloc(sz); 49 | } 50 | 51 | void *DBGrealloc(void *ptr, size_t sz, char *file, int line) 52 | { 53 | if (ptr == NULL && sz != 0) 54 | DEBUG_MSG("+ realloc, %s:%d\n", file, line); 55 | if (ptr != NULL && sz == 0) 56 | DEBUG_MSG("- realloc(0), %s:%d\n", file, line); 57 | return realloc(ptr, sz); 58 | } 59 | void DBGfree(void *ptr, char *file, int line) 60 | { 61 | DEBUG_MSG("- free, %s:%d\n", file, line); 62 | free(ptr); 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /* debug.h - Various debugging facilities 2 | * Copyright (C) 2001 Thomas Moestl 3 | * 4 | * This file is part of the pdnsd package. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | 28 | #ifndef DEBUG_H 29 | #define DEBUG_H 30 | 31 | /* 32 | * A hand-rolled alloc debug factility, because most available libraries have 33 | * problems with at least one thread implementation. 34 | */ 35 | #ifdef ALLOC_DEBUG 36 | void *DBGcalloc(size_t n, size_t sz, char *file, int line); 37 | void *DBGmalloc(size_t sz, char *file, int line); 38 | void *DBGrealloc(void *ptr, size_t sz, char *file, int line); 39 | void DBGfree(void *ptr, char *file, int line); 40 | 41 | #define pdnsd_calloc(n,sz) DBGcalloc(n,sz,__FILE__,__LINE__) 42 | #define pdnsd_malloc(sz) DBGmalloc(sz,__FILE__,__LINE__) 43 | #define pdnsd_realloc(ptr,sz) DBGrealloc(ptr,sz,__FILE__,__LINE__) 44 | #define pdnsd_free(ptr) DBGfree(ptr,__FILE__,__LINE__) 45 | #else 46 | #define pdnsd_calloc calloc 47 | #define pdnsd_malloc malloc 48 | #define pdnsd_realloc realloc 49 | #define pdnsd_free free 50 | #endif 51 | 52 | #endif /* def DEBUG_H */ 53 | -------------------------------------------------------------------------------- /src/dns.h: -------------------------------------------------------------------------------- 1 | /* dns.h - Declarations for dns handling and generic dns functions 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2004, 2005, 2009, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef DNS_H 25 | #define DNS_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "rr_types.h" 34 | #include "list.h" 35 | #include "ipvers.h" 36 | 37 | #if (TARGET==TARGET_BSD) 38 | # if !defined(__BIG_ENDIAN) 39 | # if defined(BIG_ENDIAN) 40 | # define __BIG_ENDIAN BIG_ENDIAN 41 | # elif defined(_BIG_ENDIAN) 42 | # define __BIG_ENDIAN _BIG_ENDIAN 43 | # endif 44 | # endif 45 | # if !defined(__LITTLE_ENDIAN) 46 | # if defined(LITTLE_ENDIAN) 47 | # define __LITTLE_ENDIAN LITTLE_ENDIAN 48 | # elif defined(_LITTLE_ENDIAN) 49 | # define __LITTLE_ENDIAN _LITTLE_ENDIAN 50 | # endif 51 | # endif 52 | # if !defined(__BYTE_ORDER) 53 | # if defined(BYTE_ORDER) 54 | # define __BYTE_ORDER BYTE_ORDER 55 | # elif defined(_BYTE_ORDER) 56 | # define __BYTE_ORDER _BYTE_ORDER 57 | # endif 58 | # endif 59 | #endif 60 | 61 | /* Deal with byte orders */ 62 | #ifndef __BYTE_ORDER 63 | # if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) 64 | # error Fuzzy endianness system! Both __LITTLE_ENDIAN and __BIG_ENDIAN have been defined! 65 | # endif 66 | # if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) 67 | # error Strange Endianness-less system! Neither __LITTLE_ENDIAN nor __BIG_ENDIAN has been defined! 68 | # endif 69 | # if defined(__LITTLE_ENDIAN) 70 | # define __BYTE_ORDER __LITTLE_ENDIAN 71 | # elif defined(__BIG_ENDIAN) 72 | # define __BYTE_ORDER __BIG_ENDIAN 73 | # endif 74 | #endif 75 | 76 | /* special rr type codes for queries */ 77 | #define QT_MIN 251 78 | #define QT_IXFR 251 79 | #define QT_AXFR 252 80 | #define QT_MAILB 253 81 | #define QT_MAILA 254 82 | #define QT_ALL 255 83 | #define QT_MAX 255 84 | #define QT_NUM 5 85 | 86 | /* rr classes */ 87 | #define C_MIN 1 88 | #define C_IN 1 89 | #define C_CS 2 90 | #define C_CH 3 91 | #define C_HS 4 92 | #define C_MAX 4 93 | #define C_NUM 4 94 | 95 | /* special classes for queries */ 96 | #define QC_ALL 255 97 | 98 | /* status codes */ 99 | #define RC_OK 0 100 | #define RC_FORMAT 1 101 | #define RC_SERVFAIL 2 102 | #define RC_NAMEERR 3 103 | #define RC_NOTSUPP 4 104 | #define RC_REFUSED 5 105 | #define RC_BADVERS 16 106 | 107 | /* 108 | * special internal retvals 109 | */ 110 | #define RC_NOTCACHED 0xfffa 111 | #define RC_CACHED 0xfffb 112 | #define RC_STALE 0xfffc 113 | #define RC_TCPREFUSED 0xfffd 114 | #define RC_TRUNC 0xfffe 115 | #define RC_FATALERR 0xffff 116 | 117 | /* query/response */ 118 | #define QR_QUERY 0 119 | #define QR_RESP 1 120 | 121 | /*opcodes */ 122 | #define OP_QUERY 0 123 | #define OP_IQUERY 1 124 | #define OP_STATUS 2 125 | 126 | #if 0 127 | typedef struct { 128 | /* the name is the first field. It has variable length, so it can't be put in the struct */ 129 | uint16_t type; 130 | uint16_t class; 131 | uint32_t ttl; 132 | uint16_t rdlength; 133 | /* rdata follows */ 134 | } __attribute__((packed)) rr_hdr_t; 135 | 136 | #define sizeof_rr_hdr_t (sizeof rr_hdr_t) 137 | #else 138 | 139 | /* We will not actually use the rr_hdr_t type, only its size: 140 | sizeof(rr_hdr_t) = 2 + 2 + 4 + 2 */ 141 | #define sizeof_rr_hdr_t 10 142 | #endif 143 | 144 | #define sizeof_opt_pseudo_rr (1+sizeof_rr_hdr_t) 145 | 146 | #if 0 147 | typedef struct { 148 | /* The server name and maintainer mailbox are the first two fields. It has variable length, */ 149 | /* so they can't be put in the struct */ 150 | uint32_t serial; 151 | uint32_t refresh; 152 | uint32_t retry; 153 | uint32_t expire; 154 | uint32_t minimum; 155 | } __attribute__((packed)) soa_r_t; 156 | 157 | 158 | typedef struct { 159 | /* char qname[];*/ 160 | uint16_t qtype; 161 | uint16_t qclass; 162 | } __attribute__((packed)) std_query_t; 163 | #endif 164 | 165 | 166 | typedef struct { 167 | uint16_t id; 168 | #if __BYTE_ORDER == __LITTLE_ENDIAN 169 | unsigned int rd:1; 170 | unsigned int tc:1; 171 | unsigned int aa:1; 172 | unsigned int opcode:4; 173 | unsigned int qr:1; 174 | unsigned int rcode:4; 175 | unsigned int cd:1; 176 | unsigned int ad:1; 177 | unsigned int z :1; 178 | unsigned int ra:1; 179 | #elif __BYTE_ORDER == __BIG_ENDIAN 180 | unsigned int qr:1; 181 | unsigned int opcode:4; 182 | unsigned int aa:1; 183 | unsigned int tc:1; 184 | unsigned int rd:1; 185 | unsigned int ra:1; 186 | unsigned int z :1; 187 | unsigned int ad:1; 188 | unsigned int cd:1; 189 | unsigned int rcode:4; 190 | #else 191 | # error "Please define __BYTE_ORDER to be __LITTLE_ENDIAN or __BIG_ENDIAN" 192 | #endif 193 | uint16_t qdcount; 194 | uint16_t ancount; 195 | uint16_t nscount; 196 | uint16_t arcount; 197 | } __attribute__((packed)) dns_hdr_t; 198 | 199 | 200 | /* A structure that can also be used for DNS messages over TCP. */ 201 | typedef struct { 202 | #ifndef NO_TCP_QUERIES 203 | uint16_t len; 204 | #endif 205 | dns_hdr_t hdr; 206 | } __attribute__((packed)) dns_msg_t; 207 | 208 | #ifdef NO_TCP_QUERIES 209 | # define dnsmsghdroffset 0 210 | #else 211 | # define dnsmsghdroffset 2 212 | #endif 213 | 214 | 215 | /* Structure for storing EDNS (Extension mechanisms for DNS) information. */ 216 | typedef struct { 217 | unsigned short udpsize; 218 | unsigned short rcode; 219 | unsigned short version; 220 | unsigned char do_flg; 221 | } edns_info_t; 222 | 223 | 224 | /* Macros to retrieve or store integer data that is not necessarily aligned. 225 | Also takes care of network to host byte order. 226 | The pointer cp is advanced and should be of type void* or char*. 227 | These are actually adapted versions of the NS_GET16 and NS_GET32 228 | macros in the arpa/nameser.h include file in the BIND 9 source. 229 | */ 230 | 231 | #define GETINT16(s,cp) do { \ 232 | register uint16_t t_s; \ 233 | register const unsigned char *t_cp = (const unsigned char *)(cp); \ 234 | t_s = (uint16_t)*t_cp++ << 8; \ 235 | t_s |= (uint16_t)*t_cp++; \ 236 | (s) = t_s; \ 237 | (cp) = (void *)t_cp; \ 238 | } while (0) 239 | 240 | #define GETINT32(l,cp) do { \ 241 | register uint32_t t_l; \ 242 | register const unsigned char *t_cp = (const unsigned char *)(cp); \ 243 | t_l = (uint32_t)*t_cp++ << 24; \ 244 | t_l |= (uint32_t)*t_cp++ << 16; \ 245 | t_l |= (uint32_t)*t_cp++ << 8; \ 246 | t_l |= (uint32_t)*t_cp++; \ 247 | (l) = t_l; \ 248 | (cp) = (void *)t_cp; \ 249 | } while (0) 250 | 251 | #define PUTINT16(s,cp) do { \ 252 | register uint16_t t_s = (uint16_t)(s); \ 253 | register unsigned char *t_cp = (unsigned char *)(cp); \ 254 | *t_cp++ = t_s >> 8; \ 255 | *t_cp++ = t_s; \ 256 | (cp) = (void *)t_cp; \ 257 | } while (0) 258 | 259 | #define PUTINT32(l,cp) do { \ 260 | register uint32_t t_l = (uint32_t)(l); \ 261 | register unsigned char *t_cp = (unsigned char *)(cp); \ 262 | *t_cp++ = t_l >> 24; \ 263 | *t_cp++ = t_l >> 16; \ 264 | *t_cp++ = t_l >> 8; \ 265 | *t_cp++ = t_l; \ 266 | (cp) = (void *)t_cp; \ 267 | } while (0) 268 | 269 | 270 | /* Size (number of bytes) of buffers used to hold domain names. */ 271 | #define DNSNAMEBUFSIZE 256 272 | 273 | /* Recursion depth. */ 274 | #define MAX_HOPS 20 275 | 276 | /* 277 | * Types for compression buffers. 278 | */ 279 | typedef struct { 280 | unsigned int index; 281 | unsigned char s[0]; 282 | } compel_t; 283 | 284 | 285 | 286 | int decompress_name(unsigned char *msg, size_t msgsz, unsigned char **src, size_t *sz, unsigned char *tgt, unsigned int *len); 287 | /* int domain_name_match(const unsigned char *ms, const unsigned char *md, int *os, int *od); */ 288 | unsigned int domain_match(const unsigned char *ms, const unsigned char *md, unsigned int *os, unsigned int *od); 289 | unsigned int compress_name(unsigned char *in, unsigned char *out, unsigned int offs, dlist *cb); 290 | int a2ptrstr(pdnsd_ca *a, int tp, unsigned char *buf); 291 | int read_hosts(const char *fn, unsigned char *rns, time_t ttl, unsigned flags, int aliases, char **errstr); 292 | 293 | const char *getrrtpname(int tp); 294 | #if DEBUG>0 295 | const char *get_cname(int id); 296 | const char *get_tname(int id); 297 | const char *get_ename(int id); 298 | #define DNSFLAGSMAXSTRSIZE (7*3+1) 299 | char *dnsflags2str(dns_hdr_t *hdr, char *buf); 300 | #endif 301 | 302 | #if DEBUG>=9 303 | void debug_dump_dns_msg(void *data, size_t len); 304 | #define DEBUG_DUMP_DNS_MSG(d,l) {if(debug_p && global.verbosity>=9) debug_dump_dns_msg(d,l);} 305 | #else 306 | #define DEBUG_DUMP_DNS_MSG(d,l) 307 | #endif 308 | 309 | #endif 310 | -------------------------------------------------------------------------------- /src/dns_answer.h: -------------------------------------------------------------------------------- 1 | /* dns_answer.h - Receive and process icoming dns queries. 2 | 3 | Copyright (C) 2000 Thomas Moestl 4 | Copyright (C) 2005 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef DNS_ANSWER_H 25 | #define DNS_ANSWER_H 26 | 27 | #include 28 | 29 | /* --- from main.c */ 30 | extern pthread_t main_thrid,servstat_thrid,statsock_thrid,tcps_thrid,udps_thrid; 31 | extern volatile int tcp_socket; 32 | extern volatile int udp_socket; 33 | /* --- */ 34 | 35 | int init_udp_socket(void); 36 | int init_tcp_socket(void); 37 | void start_dns_servers(void); 38 | int report_thread_stat(int f); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/dns_query.h: -------------------------------------------------------------------------------- 1 | /* dns_query.h - Execute outgoing dns queries and write entries to cache 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2004, 2006, 2009, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef DNS_QUERY_H 25 | #define DNS_QUERY_H 26 | 27 | #include "cache.h" 28 | 29 | /* Default UDP buffer size (when EDNS is not used). */ 30 | #define UDP_BUFSIZE 512 31 | 32 | 33 | typedef struct qhintnode_s qhintnode_t; 34 | 35 | /* --- parallel query */ 36 | int r_dns_cached_resolve(unsigned char *name, int thint, dns_cent_t **cachedp, 37 | int hops, qhintnode_t *qhlist, time_t queryts, 38 | unsigned char *c_soa); 39 | #define dns_cached_resolve(name,thint,cachedp,hops,queryts,c_soa) \ 40 | r_dns_cached_resolve(name,thint,cachedp,hops,NULL,queryts,c_soa) 41 | 42 | addr2_array dns_rootserver_resolv(atup_array atup_a, int port, char edns_query, time_t timeout); 43 | int query_uptest(pdnsd_a *addr, int port, const unsigned char *name, time_t timeout, int rep); 44 | 45 | /* --- from dns_answer.c */ 46 | int add_opt_pseudo_rr(dns_msg_t **ans, size_t *sz, size_t *allocsz, 47 | unsigned short udpsize, unsigned short rcode, 48 | unsigned short ednsver, unsigned short Zflags); 49 | size_t remove_opt_pseudo_rr(dns_msg_t *ans, size_t sz); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/error.c: -------------------------------------------------------------------------------- 1 | /* error.c - Error handling 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2003, 2004, 2005, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "error.h" 32 | #include "helpers.h" 33 | #include "conff.h" 34 | 35 | 36 | pthread_mutex_t loglock = PTHREAD_MUTEX_INITIALIZER; 37 | volatile short int use_log_lock=0; 38 | 39 | /* 40 | * Initialize a mutex for io-locking in order not to produce gibberish on 41 | * multiple simultaneous errors. 42 | */ 43 | /* This is now defined as an inline function in error.h */ 44 | #if 0 45 | void init_log_lock(void) 46 | { 47 | use_log_lock=1; 48 | } 49 | #endif 50 | 51 | /* We crashed? Ooops... */ 52 | void crash_msg(char *msg) 53 | { 54 | log_error("%s", msg); 55 | log_error("pdnsd probably crashed due to a bug. Please consider sending a bug"); 56 | log_error("report to p.a.rombouts@home.nl or tmoestl@gmx.net"); 57 | } 58 | 59 | /* Log a warning, error or info message. 60 | * If we are a daemon, use the syslog. s is a format string like in printf, 61 | * the optional following arguments are the arguments like in printf */ 62 | void log_message(int prior, const char *s, ...) 63 | { 64 | int gotlock=0; 65 | va_list va; 66 | FILE *f; 67 | 68 | if (use_log_lock) { 69 | gotlock=softlock_mutex(&loglock); 70 | /* If we failed to get the lock and the type of the 71 | message is "info" or less important, then don't bother. */ 72 | if(!gotlock && prior>=LOG_INFO) 73 | return; 74 | } 75 | if (global.daemon) { 76 | openlog("pdnsd",LOG_PID,LOG_DAEMON); 77 | va_start(va,s); 78 | vsyslog(prior,s,va); 79 | va_end(va); 80 | closelog(); 81 | } 82 | else { 83 | f=stderr; 84 | #if DEBUG > 0 85 | goto printtofile; 86 | } 87 | if(debug_p) { 88 | f=dbg_file; 89 | printtofile: 90 | #endif 91 | { 92 | char ts[sizeof "* 12/31 23:59:59| "]; 93 | time_t tt = time(NULL); 94 | struct tm tm; 95 | 96 | if(!localtime_r(&tt, &tm) || strftime(ts, sizeof(ts), "* %m/%d %T| ", &tm) <=0) 97 | ts[0]=0; 98 | fprintf(f,"%spdnsd: %s: ", ts, 99 | prior<=LOG_CRIT?"critical": 100 | prior==LOG_ERR?"error": 101 | prior==LOG_WARNING?"warning": 102 | "info"); 103 | } 104 | va_start(va,s); 105 | vfprintf(f,s,va); 106 | va_end(va); 107 | { 108 | const char *p=strchr(s,0); 109 | if(!p || p==s || *(p-1)!='\n') 110 | fputc('\n',f); 111 | } 112 | } 113 | if (gotlock) 114 | pthread_mutex_unlock(&loglock); 115 | } 116 | 117 | 118 | #if DEBUG > 0 119 | /* XXX: The timestamp generation makes this a little heavy-weight */ 120 | void debug_msg(int c, const char *fmt, ...) 121 | { 122 | va_list va; 123 | 124 | if (!c) { 125 | char ts[sizeof "12/31 23:59:59"]; 126 | time_t tt = time(NULL); 127 | struct tm tm; 128 | unsigned *id; 129 | 130 | if(localtime_r(&tt, &tm) && strftime(ts, sizeof(ts), "%m/%d %T", &tm) > 0) { 131 | if((id = (unsigned *)pthread_getspecific(thrid_key))) 132 | fprintf(dbg_file,"%u %s| ", *id, ts); 133 | else 134 | fprintf(dbg_file,"- %s| ", ts); 135 | } 136 | } 137 | va_start(va,fmt); 138 | vfprintf(dbg_file,fmt,va); 139 | va_end(va); 140 | fflush(dbg_file); 141 | } 142 | #endif /* DEBUG */ 143 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | /* error.h - Error handling 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2003, 2004, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef ERROR_H 25 | #define ERROR_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "thread.h" 35 | #include "helpers.h" 36 | #include "pdnsd_assert.h" 37 | 38 | /* --- from error.c */ 39 | extern volatile short int use_log_lock; 40 | /* --- */ 41 | 42 | void crash_msg(char *msg); 43 | 44 | inline static void init_log_lock(void) __attribute__((always_inline)); 45 | inline static void init_log_lock(void) 46 | { 47 | use_log_lock=1; 48 | } 49 | 50 | void log_message(int prior,const char *s, ...) printfunc(2, 3); 51 | #if !defined(CPP_C99_VARIADIC_MACROS) 52 | /* GNU C Macro Varargs style. */ 53 | #define log_error(args...) log_message(LOG_ERR,args) 54 | #define log_warn(args...) log_message(LOG_WARNING,args) 55 | #define log_info(level,args...) {if((level)<=global.verbosity) log_message(LOG_INFO,args);} 56 | #else 57 | /* ANSI C99 style. */ 58 | #define log_error(...) log_message(LOG_ERR,__VA_ARGS__) 59 | #define log_warn(...) log_message(LOG_WARNING,__VA_ARGS__) 60 | #define log_info(level,...) {if((level)<=global.verbosity) log_message(LOG_INFO,__VA_ARGS__);} 61 | #endif 62 | 63 | /* Following are some ugly macros for debug messages that 64 | * should inhibit any code generation when DEBUG is not defined. 65 | * Of course, those messages could be done in a function, but I 66 | * want to save the overhead when DEBUG is not defined. 67 | * debug_p needs to be defined (by including conff.h), or you 68 | * will get strange errors. 69 | * A macro call expands to a complete statement, so a semicolon after 70 | * the macro call is redundant. 71 | * The arguments are normal printfs, so you know how to use the args 72 | */ 73 | #if DEBUG>0 74 | void debug_msg(int c, const char *fmt, ...) printfunc(2, 3); 75 | /* from main.c */ 76 | extern FILE *dbg_file; 77 | #endif 78 | 79 | #if !defined(CPP_C99_VARIADIC_MACROS) 80 | /* GNU C Macro Varargs style. */ 81 | # if DEBUG > 0 82 | # define DEBUG_MSG(args...) {if (debug_p) debug_msg(0,args);} 83 | # define DEBUG_MSGC(args...) {if (debug_p) debug_msg(1,args);} 84 | # define DEBUG_PDNSDA_MSG(args...) {char _debugsockabuf[ADDRSTR_MAXLEN]; DEBUG_MSG(args);} 85 | # define PDNSDA2STR(a) pdnsd_a2str(a,_debugsockabuf,sizeof(_debugsockabuf)) 86 | # define DEBUG_RHN_MSG(args...) {unsigned char _debugstrbuf[DNSNAMEBUFSIZE]; DEBUG_MSG(args);} 87 | # define RHN2STR(a) rhn2str(a,_debugstrbuf,sizeof(_debugstrbuf)) 88 | # else 89 | # define DEBUG_MSG(args...) 90 | # define DEBUG_MSGC(args...) 91 | # define DEBUG_PDNSDA_MSG(args...) 92 | # define DEBUG_RHN_MSG(args...) 93 | # endif /* DEBUG > 0 */ 94 | #else 95 | /* ANSI C99 style. */ 96 | # if DEBUG > 0 97 | /* 98 | * XXX: The ANSI and GCC variadic macros should be merged as far as possible, but that 99 | * might make things even more messy... 100 | */ 101 | # define DEBUG_MSG(...) {if (debug_p) debug_msg(0,__VA_ARGS__);} 102 | # define DEBUG_MSGC(...) {if (debug_p) debug_msg(1,__VA_ARGS__);} 103 | # define DEBUG_PDNSDA_MSG(...) {char _debugsockabuf[ADDRSTR_MAXLEN]; DEBUG_MSG(__VA_ARGS__);} 104 | # define PDNSDA2STR(a) pdnsd_a2str(a,_debugsockabuf,ADDRSTR_MAXLEN) 105 | # define DEBUG_RHN_MSG(...) {unsigned char _debugstrbuf[DNSNAMEBUFSIZE]; DEBUG_MSG(__VA_ARGS__);} 106 | # define RHN2STR(a) rhn2str(a,_debugstrbuf,sizeof(_debugstrbuf)) 107 | # else 108 | # define DEBUG_MSG(...) 109 | # define DEBUG_MSGC(...) 110 | # define DEBUG_PDNSDA_MSG(...) 111 | # define DEBUG_RHN_MSG(...) 112 | # endif /* DEBUG > 0 */ 113 | #endif 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /src/freebsd_netinet_ip_icmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1982, 1986, 1993 3 | * The Regents of the University of California. 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 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. 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 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 34 | * $FreeBSD: src/sys/netinet/ip_icmp.h,v 1.20 2003/03/21 15:28:10 mdodd Exp $ 35 | */ 36 | 37 | #ifndef _NETINET_IP_ICMP_H_ 38 | #define _NETINET_IP_ICMP_H_ 39 | 40 | /* 41 | * Interface Control Message Protocol Definitions. 42 | * Per RFC 792, September 1981. 43 | */ 44 | 45 | /* 46 | * Internal of an ICMP Router Advertisement 47 | */ 48 | struct icmp_ra_addr { 49 | u_int32_t ira_addr; 50 | u_int32_t ira_preference; 51 | }; 52 | 53 | /* 54 | * Structure of an icmp header. 55 | */ 56 | struct icmp { 57 | u_char icmp_type; /* type of message, see below */ 58 | u_char icmp_code; /* type sub code */ 59 | u_short icmp_cksum; /* ones complement cksum of struct */ 60 | union { 61 | u_char ih_pptr; /* ICMP_PARAMPROB */ 62 | struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 63 | struct ih_idseq { 64 | n_short icd_id; 65 | n_short icd_seq; 66 | } ih_idseq; 67 | int ih_void; 68 | 69 | /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ 70 | struct ih_pmtu { 71 | n_short ipm_void; 72 | n_short ipm_nextmtu; 73 | } ih_pmtu; 74 | 75 | struct ih_rtradv { 76 | u_char irt_num_addrs; 77 | u_char irt_wpa; 78 | u_int16_t irt_lifetime; 79 | } ih_rtradv; 80 | } icmp_hun; 81 | #define icmp_pptr icmp_hun.ih_pptr 82 | #define icmp_gwaddr icmp_hun.ih_gwaddr 83 | #define icmp_id icmp_hun.ih_idseq.icd_id 84 | #define icmp_seq icmp_hun.ih_idseq.icd_seq 85 | #define icmp_void icmp_hun.ih_void 86 | #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void 87 | #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu 88 | #define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs 89 | #define icmp_wpa icmp_hun.ih_rtradv.irt_wpa 90 | #define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime 91 | union { 92 | struct id_ts { /* ICMP Timestamp */ 93 | n_time its_otime; /* Originate */ 94 | n_time its_rtime; /* Receive */ 95 | n_time its_ttime; /* Transmit */ 96 | } id_ts; 97 | struct id_ip { 98 | struct ip idi_ip; 99 | /* options and then 64 bits of data */ 100 | } id_ip; 101 | struct icmp_ra_addr id_radv; 102 | u_int32_t id_mask; 103 | char id_data[1]; 104 | } icmp_dun; 105 | #define icmp_otime icmp_dun.id_ts.its_otime 106 | #define icmp_rtime icmp_dun.id_ts.its_rtime 107 | #define icmp_ttime icmp_dun.id_ts.its_ttime 108 | #define icmp_ip icmp_dun.id_ip.idi_ip 109 | #define icmp_radv icmp_dun.id_radv 110 | #define icmp_mask icmp_dun.id_mask 111 | #define icmp_data icmp_dun.id_data 112 | }; 113 | 114 | /* 115 | * Lower bounds on packet lengths for various types. 116 | * For the error advice packets must first insure that the 117 | * packet is large enough to contain the returned ip header. 118 | * Only then can we do the check to see if 64 bits of packet 119 | * data have been returned, since we need to check the returned 120 | * ip header length. 121 | */ 122 | #define ICMP_MINLEN 8 /* abs minimum */ 123 | #define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */ 124 | #define ICMP_MASKLEN 12 /* address mask */ 125 | #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ 126 | #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) 127 | /* N.B.: must separately check that ip_hl >= 5 */ 128 | 129 | /* 130 | * Definition of type and code field values. 131 | */ 132 | #define ICMP_ECHOREPLY 0 /* echo reply */ 133 | #define ICMP_UNREACH 3 /* dest unreachable, codes: */ 134 | #define ICMP_UNREACH_NET 0 /* bad net */ 135 | #define ICMP_UNREACH_HOST 1 /* bad host */ 136 | #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ 137 | #define ICMP_UNREACH_PORT 3 /* bad port */ 138 | #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ 139 | #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ 140 | #define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ 141 | #define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ 142 | #define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ 143 | #define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ 144 | #define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ 145 | #define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ 146 | #define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ 147 | #define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */ 148 | #define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */ 149 | #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */ 150 | #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ 151 | #define ICMP_REDIRECT 5 /* shorter route, codes: */ 152 | #define ICMP_REDIRECT_NET 0 /* for network */ 153 | #define ICMP_REDIRECT_HOST 1 /* for host */ 154 | #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ 155 | #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ 156 | #define ICMP_ECHO 8 /* echo service */ 157 | #define ICMP_ROUTERADVERT 9 /* router advertisement */ 158 | #define ICMP_ROUTERSOLICIT 10 /* router solicitation */ 159 | #define ICMP_TIMXCEED 11 /* time exceeded, code: */ 160 | #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ 161 | #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ 162 | #define ICMP_PARAMPROB 12 /* ip header bad */ 163 | #define ICMP_PARAMPROB_ERRATPTR 0 /* error at param ptr */ 164 | #define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ 165 | #define ICMP_PARAMPROB_LENGTH 2 /* bad length */ 166 | #define ICMP_TSTAMP 13 /* timestamp request */ 167 | #define ICMP_TSTAMPREPLY 14 /* timestamp reply */ 168 | #define ICMP_IREQ 15 /* information request */ 169 | #define ICMP_IREQREPLY 16 /* information reply */ 170 | #define ICMP_MASKREQ 17 /* address mask request */ 171 | #define ICMP_MASKREPLY 18 /* address mask reply */ 172 | 173 | #define ICMP_MAXTYPE 18 174 | 175 | #define ICMP_INFOTYPE(type) \ 176 | ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ 177 | (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ 178 | (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ 179 | (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ 180 | (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) 181 | 182 | #ifdef _KERNEL 183 | void icmp_error(struct mbuf *, int, int, n_long, struct ifnet *); 184 | void icmp_input(struct mbuf *, int); 185 | #endif 186 | 187 | #endif 188 | -------------------------------------------------------------------------------- /src/hash.c: -------------------------------------------------------------------------------- 1 | /* hash.c - Manage hashes for cached dns records 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2003, 2005 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "hash.h" 29 | #include "cache.h" 30 | #include "error.h" 31 | #include "helpers.h" 32 | #include "consts.h" 33 | 34 | 35 | /* This is not a perfect hash, but I hope it holds. It is designed for 1024 hash 36 | * buckets, and hashes strings with case-insensitivity. 37 | * It is position-aware in a limited way. 38 | * It is exactly seen a two-way hash: because I do not want to exaggerate 39 | * the hash buckets (i do have 1024), but I hash strings and string-comparisons 40 | * are expensive, I save another 32 bit hash in each hash element that is checked 41 | * before the string. The 32 bit hash is also used to order the entries in a hash chain. 42 | * I hope not to have all too much collision concentration. 43 | * 44 | * The ip hash was removed. I don't think it concentrated the collisions too much. 45 | * If it does, the hash algorithm needs to be changed, rather than using another 46 | * hash. 47 | * Some measurements seem to indicate that the hash algorithm is doing reasonable well. 48 | */ 49 | 50 | dns_hash_ent_t *hash_buckets[HASH_NUM_BUCKETS]; 51 | 52 | 53 | /* 54 | * Hash a dns name (length-byte string format) to HASH_SZ bit. 55 | * *rhash is set to a long int hash. 56 | */ 57 | static unsigned dns_hash(const unsigned char *str, unsigned long *rhash) 58 | { 59 | unsigned s,i,lb,c; 60 | unsigned long r; 61 | s=0; r=0; 62 | i=0; 63 | while((lb=str[i])) { 64 | s+=lb<<(i%(HASH_SZ-5)); 65 | r+=((unsigned long)lb)<<(i%(8*sizeof(unsigned long)-7)); 66 | ++i; 67 | do { 68 | c=toupper(str[i]); 69 | s+=c<<(i%(HASH_SZ-5)); 70 | r+=((unsigned long)c)<<(i%(8*sizeof(unsigned long)-7)); 71 | ++i; 72 | } while(--lb); 73 | } 74 | s=(s&HASH_BITMASK)+((s&(~HASH_BITMASK))>>HASH_SZ); 75 | s=(s&HASH_BITMASK)+((s&(~HASH_BITMASK))>>HASH_SZ); 76 | s &= HASH_BITMASK; 77 | #ifdef DEBUG_HASH 78 | { 79 | unsigned char buf[DNSNAMEBUFSIZE]; 80 | printf("Diagnostic: hashes for %s: %03x,%04lx\n",rhn2str(str,buf,sizeof(buf)),s,r); 81 | } 82 | #endif 83 | if(rhash) *rhash=r; 84 | return s; 85 | } 86 | 87 | /* 88 | * Initialize hash to hold a dns hash table 89 | */ 90 | /* This is now defined as an inline function in hash.h */ 91 | #if 0 92 | void mk_dns_hash() 93 | { 94 | int i; 95 | for(i=0;irhash<=rh) { 116 | if (he->rhash==rh && rhnicmp(key,he->data->qname)) { 117 | retval = he->data; 118 | break; 119 | } 120 | hep = &he->next; 121 | } 122 | if(loc) { 123 | loc->pos = hep; 124 | loc->rhash = rh; 125 | } 126 | return retval; 127 | } 128 | 129 | /* 130 | Add a cache entry to the hash table. 131 | 132 | loc must contain the location where the the new entry should be inserted 133 | (this location can be obtained with dns_lookup). 134 | 135 | add_dns_hash returns 1 on success, or 0 if out of memory. 136 | */ 137 | int add_dns_hash(dns_cent_t *data, dns_hash_loc_t *loc) 138 | { 139 | dns_hash_ent_t *he = malloc(sizeof(dns_hash_ent_t)); 140 | 141 | if(!he) 142 | return 0; 143 | 144 | he->next = *(loc->pos); 145 | he->rhash = loc->rhash; 146 | he->data = data; 147 | *(loc->pos) = he; 148 | 149 | return 1; 150 | } 151 | 152 | /* 153 | Delete the hash entry indentified by the location returned by dns_lookup(). 154 | */ 155 | dns_cent_t *del_dns_hash_ent(dns_hash_loc_t *loc) 156 | { 157 | dns_hash_ent_t *he = *(loc->pos); 158 | dns_cent_t *data; 159 | 160 | *(loc->pos) = he->next; 161 | data = he->data; 162 | free(he); 163 | return data; 164 | } 165 | 166 | /* 167 | * Delete the first entry indexed by key from the hash. Returns the data field or NULL. 168 | * Since two cents are not allowed to be for the same host name, there will be only one. 169 | */ 170 | dns_cent_t *del_dns_hash(const unsigned char *key) 171 | { 172 | unsigned idx; 173 | unsigned long rh; 174 | dns_hash_ent_t **hep,*he; 175 | dns_cent_t *data; 176 | 177 | idx = dns_hash(key,&rh); 178 | hep = &hash_buckets[idx]; 179 | while ((he= *hep) && he->rhash<=rh) { 180 | if (he->rhash==rh && rhnicmp(key,he->data->qname)) { 181 | *hep = he->next; 182 | data = he->data; 183 | free(he); 184 | return data; 185 | } 186 | hep = &he->next; 187 | } 188 | return NULL; /* not found */ 189 | } 190 | 191 | 192 | /* 193 | * Delete all entries in a hash bucket. 194 | */ 195 | void free_dns_hash_bucket(int i) 196 | { 197 | dns_hash_ent_t *he,*hen; 198 | 199 | he=hash_buckets[i]; 200 | hash_buckets[i]=NULL; 201 | while (he) { 202 | hen=he->next; 203 | del_cent(he->data); 204 | free(he); 205 | he=hen; 206 | } 207 | } 208 | 209 | /* 210 | * Delete all entries in a hash bucket whose names match those in 211 | * an include/exclude list. 212 | */ 213 | void free_dns_hash_selected(int i, slist_array sla) 214 | { 215 | dns_hash_ent_t **hep,*he,*hen; 216 | int j,m=DA_NEL(sla); 217 | 218 | hep= &hash_buckets[i]; 219 | he= *hep; 220 | 221 | while (he) { 222 | unsigned char *name=he->data->qname; 223 | for(j=0;jdomain,&nrem,&lrem); 227 | if(!lrem && (!sl->exact || !nrem)) { 228 | if(sl->rule==C_INCLUDED) 229 | goto delete_entry; 230 | else 231 | break; 232 | } 233 | } 234 | /* default policy is not to delete */ 235 | hep= &he->next; 236 | he= *hep; 237 | continue; 238 | 239 | delete_entry: 240 | *hep=hen=he->next;; 241 | del_cent(he->data); 242 | free(he); 243 | he=hen; 244 | } 245 | } 246 | 247 | /* 248 | * Delete the whole hash table, freeing all memory 249 | */ 250 | void free_dns_hash() 251 | { 252 | int i; 253 | dns_hash_ent_t *he,*hen; 254 | for (i=0;inext; 259 | del_cent(he->data); 260 | free(he); 261 | he=hen; 262 | } 263 | } 264 | } 265 | 266 | /* 267 | * The following functions are for iterating over the hash. 268 | * fetch_first returns the data field of the first element (or NULL if there is none), and fills pos 269 | * for subsequent calls of fetch_next. 270 | * fetch_next returns the data field of the element after the element that was returned by the last 271 | * call with the same position argument (or NULL if there is none) 272 | * 273 | * Note that these are designed so that you may actually delete the elements you retrieved from the hash. 274 | */ 275 | dns_cent_t *fetch_first(dns_hash_pos_t *pos) 276 | { 277 | int i; 278 | for (i=0;ibucket=i; 282 | pos->ent=he->next; 283 | return he->data; 284 | } 285 | } 286 | return NULL; 287 | } 288 | 289 | dns_cent_t *fetch_next(dns_hash_pos_t *pos) 290 | { 291 | dns_hash_ent_t *he=pos->ent; 292 | int i; 293 | if (he) { 294 | pos->ent=he->next; 295 | return he->data; 296 | } 297 | 298 | for (i=pos->bucket+1;ibucket=i; 302 | pos->ent=he->next; 303 | return he->data; 304 | } 305 | } 306 | return NULL; 307 | } 308 | 309 | #ifdef DEBUG_HASH 310 | void dumphash() 311 | { 312 | if(debug_p) { 313 | int i, j; 314 | dns_hash_ent_t *he; 315 | 316 | for (i=0; inext, j++) ; 318 | DEBUG_MSG("bucket %d: %d entries\n", i, j); 319 | } 320 | } 321 | } 322 | #endif 323 | -------------------------------------------------------------------------------- /src/hash.h: -------------------------------------------------------------------------------- 1 | /* hash.h - Manage hashes for cached dns records 2 | 3 | Copyright (C) 2000 Thomas Moestl 4 | Copyright (C) 2003, 2005 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef _HASH_H_ 25 | #define _HASH_H_ 26 | #include 27 | #include "cache.h" 28 | 29 | typedef struct dns_hash_ent_s { 30 | struct dns_hash_ent_s *next; 31 | unsigned long rhash; /* this is a better hash */ 32 | dns_cent_t *data; 33 | } dns_hash_ent_t; 34 | 35 | /* Redefine this if you want another hash size. Should work ;-). 36 | * The number of hash buckets is computed as power of two; 37 | * so, e.g. HASH_SZ set to 10 yields 1024 hash rows (2^10 or 1<<10). 38 | * Only powers of two are possible conveniently. 39 | * HASH_SZ may not be bigger than 32 (if you set it even close to that value, 40 | * you are nuts.) */ 41 | /* #define HASH_SZ 10 */ /* Now defined in config.h */ 42 | #define HASH_NUM_BUCKETS (1<. 21 | */ 22 | 23 | 24 | #ifndef HELPERS_H 25 | #define HELPERS_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "cache.h" 33 | #include "pdnsd_assert.h" 34 | 35 | #define SOFTLOCK_MAXTRIES 1000 36 | 37 | int run_as(const char *user); 38 | void pdnsd_exit(void); 39 | int softlock_mutex(pthread_mutex_t *mutex); 40 | 41 | #if 0 42 | inline static int isdchar (unsigned char c) 43 | { 44 | return ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='-' 45 | #ifdef UNDERSCORE 46 | || c=='_' 47 | #endif 48 | ); 49 | } 50 | #endif 51 | 52 | const unsigned char *rhn2str(const unsigned char *rhn, unsigned char *str, unsigned int size); 53 | int str2rhn(const unsigned char *str, unsigned char *rhn); 54 | const char *parsestr2rhn(const unsigned char *str, unsigned int len, unsigned char *rhn); 55 | 56 | /* Note added by Paul Rombouts: 57 | Compared to the definition used by Thomas Moestl (strlen(rhn)+1), the following definition of rhnlen 58 | may yield a different result in certain error situations (when a domain name segment contains a null byte). 59 | */ 60 | inline static unsigned int rhnlen(const unsigned char *rhn) 61 | __attribute__((always_inline)); 62 | inline static unsigned int rhnlen(const unsigned char *rhn) 63 | { 64 | unsigned int i=0,lb; 65 | 66 | while((lb=rhn[i++])) 67 | i+=lb; 68 | return i; 69 | } 70 | 71 | /* Skip k segments in a name in length-byte string notation. */ 72 | inline static const unsigned char *skipsegs(const unsigned char *nm, unsigned k) 73 | __attribute__((always_inline)); 74 | inline static const unsigned char *skipsegs(const unsigned char *nm, unsigned k) 75 | { 76 | unsigned lb; 77 | for(;k && (lb= *nm); --k) { 78 | nm += lb+1; 79 | } 80 | return nm; 81 | } 82 | 83 | /* Skip a name in length-byte string notation and return a pointer to the 84 | position right after the terminating null byte. 85 | */ 86 | inline static unsigned char *skiprhn(unsigned char *rhn) 87 | __attribute__((always_inline)); 88 | inline static unsigned char *skiprhn(unsigned char *rhn) 89 | { 90 | unsigned lb; 91 | 92 | while((lb= *rhn++)) 93 | rhn += lb; 94 | return rhn; 95 | } 96 | 97 | /* count the number of name segments of a name in length-byte string notation. */ 98 | inline static unsigned int rhnsegcnt(const unsigned char *rhn) 99 | __attribute__((always_inline)); 100 | inline static unsigned int rhnsegcnt(const unsigned char *rhn) 101 | { 102 | unsigned int res=0,lb; 103 | 104 | while((lb= *rhn)) { 105 | ++res; 106 | rhn += lb+1; 107 | } 108 | return res; 109 | } 110 | 111 | unsigned int rhncpy(unsigned char *dst, const unsigned char *src); 112 | int isnormalencdomname(const unsigned char *rhn, unsigned maxlen); 113 | 114 | inline static int is_inaddr_any(pdnsd_a *a) __attribute__((always_inline)); 115 | inline static int is_inaddr_any(pdnsd_a *a) 116 | { 117 | return SEL_IPVER( a->ipv4.s_addr==INADDR_ANY, 118 | IN6_IS_ADDR_UNSPECIFIED(&a->ipv6) ); 119 | } 120 | 121 | 122 | inline static int same_inaddr(pdnsd_a *a, pdnsd_a *b) 123 | __attribute__((always_inline)); 124 | inline static int same_inaddr(pdnsd_a *a, pdnsd_a *b) 125 | { 126 | return SEL_IPVER( a->ipv4.s_addr==b->ipv4.s_addr, 127 | IN6_ARE_ADDR_EQUAL(&a->ipv6,&b->ipv6) ); 128 | } 129 | 130 | /* Compare a pdnsd_a* with a pdnsd_a2*. */ 131 | inline static int same_inaddr2(pdnsd_a *a, pdnsd_a2 *b) 132 | __attribute__((always_inline)); 133 | inline static int same_inaddr2(pdnsd_a *a, pdnsd_a2 *b) 134 | { 135 | return SEL_IPVER( a->ipv4.s_addr==b->ipv4.s_addr, 136 | IN6_ARE_ADDR_EQUAL(&a->ipv6,&b->ipv6) && b->ipv4.s_addr==INADDR_ANY ); 137 | } 138 | 139 | inline static int equiv_inaddr2(pdnsd_a *a, pdnsd_a2 *b) 140 | __attribute__((always_inline)); 141 | inline static int equiv_inaddr2(pdnsd_a *a, pdnsd_a2 *b) 142 | { 143 | return SEL_IPVER( a->ipv4.s_addr==b->ipv4.s_addr, 144 | IN6_ARE_ADDR_EQUAL(&a->ipv6,&b->ipv6) || 145 | (b->ipv4.s_addr!=INADDR_ANY && ADDR_EQUIV6_4(&a->ipv6,&b->ipv4)) ); 146 | } 147 | 148 | int str2pdnsd_a(const char *addr, pdnsd_a *a); 149 | const char *pdnsd_a2str(pdnsd_a *a, char *buf, int maxlen); 150 | 151 | int init_rng(void); 152 | #ifdef RANDOM_DEVICE 153 | extern FILE *rand_file; 154 | /* Because this is usually empty, it is now defined as a macro to save overhead.*/ 155 | #define free_rng() {if (rand_file) fclose(rand_file);} 156 | #else 157 | #define free_rng() 158 | #endif 159 | 160 | unsigned short get_rand16(void); 161 | 162 | int fsprintf(int fd, const char *format, ...) printfunc(2, 3); 163 | #if !defined(CPP_C99_VARIADIC_MACROS) 164 | /* GNU C Macro Varargs style. */ 165 | # define fsprintf_or_return(args...) {int _retval; if((_retval=fsprintf(args))<0) return _retval;} 166 | #else 167 | /* ANSI C99 style variadic macro. */ 168 | # define fsprintf_or_return(...) {int _retval; if((_retval=fsprintf(__VA_ARGS__))<0) return _retval;} 169 | #endif 170 | 171 | /* Added by Paul Rombouts */ 172 | inline static ssize_t write_all(int fd,const void *data,size_t n) 173 | __attribute__((always_inline)); 174 | inline static ssize_t write_all(int fd,const void *data,size_t n) 175 | { 176 | ssize_t written=0; 177 | 178 | while(written 310 | int vasprintf (char **lineptr, const char *format, va_list va); 311 | #endif 312 | 313 | #ifndef HAVE_INET_NTOP 314 | const char *inet_ntop(int af, const void *src, char *dst, size_t size); 315 | #endif 316 | 317 | #define strlitlen(strlit) (sizeof(strlit)-1) 318 | 319 | #endif /* HELPERS_H */ 320 | -------------------------------------------------------------------------------- /src/icmp.h: -------------------------------------------------------------------------------- 1 | /* icmp.h - Server response tests using ICMP echo requests 2 | Copyright (C) 2000 Thomas Moestl 3 | Copyright (C) 2007 Paul A. Rombouts 4 | 5 | This file is part of the pdnsd package. 6 | 7 | pdnsd is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | pdnsd is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with pdnsd; see the file COPYING. If not, see 19 | . 20 | */ 21 | 22 | 23 | #ifndef ICMP_H 24 | #define ICMP_H 25 | 26 | 27 | #include 28 | #include "ipvers.h" 29 | 30 | volatile extern int ping_isocket; 31 | volatile extern int ping6_isocket; 32 | 33 | /* initialize a socket for pinging */ 34 | void init_ping_socket(void); 35 | 36 | /* 37 | * This is a classical ping routine. 38 | * timeout in 10ths of seconds, rep is the repetition count. 39 | */ 40 | 41 | int ping(pdnsd_a *addr, int timeout, int rep); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/list.c: -------------------------------------------------------------------------------- 1 | /* list.c - Dynamic array and list handling 2 | 3 | Copyright (C) 2001 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2007, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "helpers.h" 27 | #include "error.h" 28 | #include "list.h" 29 | 30 | 31 | /* Grow a dynamic array to hold one extra element. 32 | This could be done using da_resize(), but this is such a common operation 33 | it is has been given its own optimized implementation. 34 | da_grow1() returns a pointer to the new (possibly reallocated) array if 35 | successful, otherwise it frees the old array (after freeing all the array 36 | elements if a clean-up routine is supplied) and returns NULL. 37 | */ 38 | darray da_grow1(darray a, size_t headsz, size_t elemsz, void (*cleanuproutine) (void *)) 39 | { 40 | size_t k = (a?a->nel:0); 41 | if(!a || (k!=0 && (k&7)==0)) { 42 | darray tmp=(darray)realloc(a, headsz+elemsz*(k+8)); 43 | if (!tmp && a) { 44 | if(cleanuproutine) { 45 | size_t i; 46 | for(i=0;inel=k+1; 54 | return a; 55 | } 56 | 57 | inline static size_t alloc_nel(size_t n) 58 | { 59 | return n==0 ? 8 : (n+7)&(~7); 60 | } 61 | 62 | /* da_resize() allows you to grow (or shrink) a dynamic array to an arbitrary length n, 63 | but is otherwise similar to da_grow1(). 64 | */ 65 | darray da_resize(darray a, size_t headsz, size_t elemsz, size_t n, void (*cleanuproutine) (void *)) 66 | { 67 | size_t ael = (a?alloc_nel(a->nel):0); 68 | size_t new_ael = alloc_nel(n); 69 | if(new_ael != ael) { 70 | /* adjust alloced space. */ 71 | darray tmp=(darray)realloc(a, headsz+elemsz*new_ael); 72 | if (!tmp && a) { 73 | if(cleanuproutine) { 74 | size_t i,k=a->nel; 75 | for(i=0;inel=n; 83 | return a; 84 | } 85 | 86 | #ifdef ALLOC_DEBUG 87 | void DBGda_free(darray a, size_t headsz, size_t elemsz, char *file, int line) 88 | { 89 | if (a==NULL) 90 | {DEBUG_MSG("- da_free, %s:%d, not initialized\n", file, line);} 91 | else 92 | {DEBUG_MSG("- da_free, %s:%d, %lu bytes\n", file, line, 93 | (unsigned long)(headsz+elemsz*alloc_nel(a->nel)));} 94 | free(a); 95 | } 96 | #endif 97 | 98 | 99 | #define DLISTALIGN(len) (((len) + (sizeof(size_t)-1)) & ~(sizeof(size_t)-1)) 100 | /* This mask corresponds to a chunk size of 1024. */ 101 | #define DLISTCHUNKSIZEMASK ((size_t)0x3ff) 102 | 103 | /* Add space for a new item of size len to the list a. 104 | dlist_grow() returns a pointer to the new (possibly reallocated) list structure if 105 | successful, otherwise it frees the old list and returns NULL. 106 | */ 107 | dlist dlist_grow(dlist a, size_t len) 108 | { 109 | size_t sz=0, allocsz=0, szincr, newsz; 110 | if(a) { 111 | sz=a->last+a->lastsz; 112 | allocsz = (sz+DLISTCHUNKSIZEMASK)&(~DLISTCHUNKSIZEMASK); 113 | *((size_t *)&a->data[a->last])=a->lastsz; 114 | } 115 | szincr=DLISTALIGN(len+sizeof(size_t)); 116 | newsz=sz+szincr; 117 | if(newsz>allocsz) { 118 | dlist tmp; 119 | allocsz = (newsz+DLISTCHUNKSIZEMASK)&(~DLISTCHUNKSIZEMASK); 120 | tmp=realloc(a, sizeof(struct _dynamic_list_head)+allocsz); 121 | if (!tmp) 122 | free(a); 123 | a=tmp; 124 | } 125 | if(a) { 126 | a->last=sz; 127 | a->lastsz=szincr; 128 | *((size_t *)&a->data[sz])=0; 129 | } 130 | return a; 131 | } 132 | 133 | 134 | /* Add a new node, capable of holding data of size len, at the end of a linked list. 135 | llist_grow() returns 1 if successful, otherwise it frees the entire linked list 136 | and returns 0. 137 | */ 138 | int llist_grow(llist *a, size_t len) 139 | { 140 | struct llistnode_s *new= (struct llistnode_s *)malloc(sizeof(struct llistnode_s)+len); 141 | 142 | if(!new) { 143 | llist_free(a); 144 | return 0; 145 | } 146 | 147 | new->next=NULL; 148 | 149 | if(!a->first) 150 | a->first=new; 151 | else 152 | a->last->next=new; 153 | 154 | a->last=new; 155 | 156 | return 1; 157 | } 158 | 159 | void llist_free(llist *a) 160 | { 161 | struct llistnode_s *p= a->first; 162 | 163 | while(p) { 164 | struct llistnode_s *next= p->next; 165 | free(p); 166 | p=next; 167 | } 168 | 169 | a->first=NULL; 170 | a->last= NULL; 171 | } 172 | -------------------------------------------------------------------------------- /src/list.h: -------------------------------------------------------------------------------- 1 | /* list.h - Dynamic array and list handling 2 | 3 | Copyright (C) 2001 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2007, 2009, 2011 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef LIST_H 25 | #define LIST_H 26 | 27 | #include 28 | #include 29 | #include "pdnsd_assert.h" 30 | 31 | 32 | typedef struct {size_t nel;} *darray; 33 | 34 | /* used in type declarations */ 35 | #define DYNAMIC_ARRAY(typ) struct {size_t nel; typ elem[0];} 36 | #define DA_TYP_OFFSET(atyp) ((size_t)((atyp)0)->elem) 37 | #define DA_OFFSET(a) DA_TYP_OFFSET(typeof (a)) 38 | 39 | #define DA_CREATE(atyp,n) ((atyp)da_resize(NULL,DA_TYP_OFFSET(atyp),sizeof(((atyp)0)->elem[0]),n,NULL)) 40 | #define DA_INDEX(a,i) ((a)->elem[i]) 41 | /* Used often, so make special-case macro here */ 42 | #define DA_LAST(a) ((a)->elem[(a)->nel-1]) 43 | 44 | #define DA_GROW1(a) ((typeof (a))da_grow1((darray)(a),DA_OFFSET(a),sizeof((a)->elem[0]),NULL)) 45 | #define DA_GROW1_F(a,cleanup) ((typeof (a))da_grow1((darray)(a),DA_OFFSET(a),sizeof((a)->elem[0]),cleanup)) 46 | #define DA_RESIZE(a,n) ((typeof (a))da_resize((darray)(a),DA_OFFSET(a),sizeof((a)->elem[0]),n,NULL)) 47 | #define DA_NEL(a) da_nel((darray)(a)) 48 | 49 | /* 50 | * Some or all of these should be inline. 51 | * They aren't macros for type safety. 52 | */ 53 | 54 | darray da_grow1(darray a, size_t headsz, size_t elemsz, void (*cleanuproutine) (void *)); 55 | darray da_resize(darray a, size_t headsz, size_t elemsz, size_t n, void (*cleanuproutine) (void *)); 56 | 57 | inline static unsigned int da_nel(darray a) 58 | __attribute__((always_inline)); 59 | inline static unsigned int da_nel(darray a) 60 | { 61 | if (a==NULL) 62 | return 0; 63 | return a->nel; 64 | } 65 | 66 | /* alloc/free debug code.*/ 67 | #ifdef ALLOC_DEBUG 68 | void DBGda_free(darray a, size_t headsz, size_t elemsz, char *file, int line); 69 | #define da_free(a) DBGda_free((darray)(a),DA_OFFSET(a),sizeof((a)->elem[0]), __FILE__, __LINE__) 70 | #else 71 | #define da_free free 72 | #endif 73 | 74 | 75 | /* This dynamic "list" structure is useful if the items are not all the same size. 76 | The elements can only be read back in sequential order, not indexed as with the dynamic arrays. 77 | */ 78 | struct _dynamic_list_head { 79 | size_t last,lastsz; 80 | char data[0]; 81 | }; 82 | 83 | typedef struct _dynamic_list_head *dlist; 84 | 85 | inline static void *dlist_first(dlist a) 86 | __attribute__((always_inline)); 87 | inline static void *dlist_first(dlist a) 88 | { 89 | return a?&a->data[sizeof(size_t)]:NULL; 90 | } 91 | 92 | /* dlist_next() returns a reference to the next item in the list, or NULL is there is no next item. 93 | ref should be properly aligned. 94 | If the dlist was grown with dlist_grow(), this should be OK. 95 | */ 96 | inline static void *dlist_next(void *ref) 97 | __attribute__((always_inline)); 98 | inline static void *dlist_next(void *ref) 99 | { 100 | size_t incr= *(((size_t *)ref)-1); 101 | return incr?((char *)ref)+incr:NULL; 102 | } 103 | 104 | /* dlist_last() returns a reference to the last item. */ 105 | inline static void *dlist_last(dlist a) 106 | __attribute__((always_inline)); 107 | inline static void *dlist_last(dlist a) 108 | { 109 | return a?&a->data[a->last+sizeof(size_t)]:NULL; 110 | } 111 | 112 | dlist dlist_grow(dlist a, size_t len); 113 | 114 | #define dlist_free free 115 | 116 | 117 | /* linked list data type. */ 118 | struct llistnode_s { 119 | struct llistnode_s *next; 120 | char *data[0]; 121 | }; 122 | 123 | typedef struct { 124 | struct llistnode_s *first, *last; 125 | } 126 | llist; 127 | 128 | inline static void llist_init(llist *a) 129 | __attribute__((always_inline)); 130 | inline static void llist_init(llist *a) 131 | { 132 | a->first=NULL; 133 | a->last= NULL; 134 | } 135 | 136 | inline static int llist_isempty(llist *a) 137 | __attribute__((always_inline)); 138 | inline static int llist_isempty(llist *a) 139 | { 140 | return a->first==NULL; 141 | } 142 | 143 | inline static void *llist_first(llist *a) 144 | __attribute__((always_inline)); 145 | inline static void *llist_first(llist *a) 146 | { 147 | struct llistnode_s *p= a->first; 148 | return p?p->data:NULL; 149 | } 150 | 151 | inline static void *llist_next(void *ref) 152 | __attribute__((always_inline)); 153 | inline static void *llist_next(void *ref) 154 | { 155 | struct llistnode_s *next= *(((struct llistnode_s **)ref)-1); 156 | return next?next->data:NULL; 157 | } 158 | 159 | inline static void *llist_last(llist *a) 160 | __attribute__((always_inline)); 161 | inline static void *llist_last(llist *a) 162 | { 163 | struct llistnode_s *p= a->last; 164 | return p?p->data:NULL; 165 | } 166 | 167 | int llist_grow(llist *a, size_t len); 168 | void llist_free(llist *a); 169 | 170 | #endif /* def LIST_H */ 171 | -------------------------------------------------------------------------------- /src/netdev.h: -------------------------------------------------------------------------------- 1 | /* netdev.h - Test network devices for existence and status 2 | Copyright (C) 2000 Thomas Moestl 3 | 4 | This file is part of the pdnsd package. 5 | 6 | pdnsd is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | pdnsd is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with pdnsd; see the file COPYING. If not, see 18 | . 19 | */ 20 | 21 | 22 | #ifndef _NETDEV_H_ 23 | #define _NETDEV_H_ 24 | 25 | #include 26 | #include "ipvers.h" 27 | 28 | int if_up(char *devname); 29 | int dev_up(char *ifname, char *devname); 30 | int is_local_addr(pdnsd_a *a); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/pdnsd-ctl/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | sbin_PROGRAMS = pdnsd-ctl 3 | 4 | pdnsd_ctl_SOURCES = pdnsd-ctl.c 5 | pdnsd_ctl_LDADD = rr_types.o 6 | pdnsd_ctl_DEPENDENCIES = rr_types.o 7 | 8 | # These are Symlinks we want to have in the package 9 | #EXTRA_DIST = rr_types.h 10 | 11 | pdnsd-ctl.o rr_types.o: ../rr_types.h 12 | 13 | ../rr_types.h: ../make_rr_types_h.pl ../rr_types.in 14 | perl ../make_rr_types_h.pl ../rr_types.in > ../rr_types.h 15 | 16 | rr_types.o: %.o: ../%.c 17 | $(COMPILE) -DCLIENT_ONLY -c $< 18 | 19 | -------------------------------------------------------------------------------- /src/pdnsd_assert.h: -------------------------------------------------------------------------------- 1 | /* This include file was added by Paul A. Rombouts. 2 | I had terrible difficulties with cyclic dependencies of the include files 3 | written by Thomas Moestl. The only way I knew how to break the cycle was to 4 | put some declarations in a seperate file. 5 | 6 | Copyright (C) 2000, 2001 Thomas Moestl 7 | Copyright (C) 2002 Paul A. Rombouts 8 | 9 | This file is part of the pdnsd package. 10 | 11 | pdnsd is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | pdnsd is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with pdnsd; see the file COPYING. If not, see 23 | . 24 | */ 25 | 26 | #ifndef PDNSD_ASSERT_H 27 | #define PDNSD_ASSERT_H 28 | 29 | /* Originally in helpers.h */ 30 | 31 | /* format string checking for printf-like functions */ 32 | #ifdef __GNUC__ 33 | #define printfunc(fmt, firstva) __attribute__((__format__(__printf__, fmt, firstva))) 34 | #else 35 | #define printfunc(fmt, firstva) 36 | #endif 37 | 38 | void pdnsd_exit(void); 39 | 40 | 41 | /* 42 | * Assert macro, used in some places. For now, it should be always defined, not 43 | * only in the DEBUG case, to be on the safe side security-wise. 44 | */ 45 | #define PDNSD_ASSERT(cond, msg) \ 46 | { if (!(cond)) { \ 47 | log_error("%s:%d: %s", __FILE__, __LINE__, msg); \ 48 | pdnsd_exit(); \ 49 | } } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/rc/ArchLinux/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | install-exec-local: 3 | if [ "$(distribution)" = "ArchLinux" ] ; then \ 4 | $(mkinstalldirs) "$(DESTDIR)/etc/rc.d"; \ 5 | $(INSTALL_SCRIPT) $(srcdir)/pdnsd "$(DESTDIR)/etc/rc.d/pdnsd";\ 6 | fi 7 | 8 | -------------------------------------------------------------------------------- /src/rc/ArchLinux/pdnsd.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . /etc/rc.conf 4 | . /etc/rc.d/functions 5 | 6 | PID=`pidof -o %PPID @prefix@/sbin/pdnsd` 7 | 8 | start() { 9 | stat_busy "Starting PDNSD" 10 | [ -z "$PID" ] && @prefix@/sbin/pdnsd -d -c /etc/pdnsd.conf 11 | if [ $? -gt 0 ]; then 12 | stat_fail 13 | else 14 | add_daemon pdnsd 15 | stat_done 16 | fi 17 | } 18 | 19 | stop() { 20 | stat_busy "Stopping PDNSD" 21 | [ ! -z "$PID" ] && kill $PID &> /dev/null 22 | if [ $? -gt 0 ]; then 23 | stat_fail 24 | else 25 | rm_daemon pdnsd 26 | stat_done 27 | fi 28 | } 29 | 30 | case "$1" in 31 | start) 32 | start 33 | ;; 34 | stop) 35 | stop 36 | ;; 37 | restart) 38 | $0 stop 39 | sleep 2 40 | $0 start 41 | ;; 42 | *) 43 | echo "usage: $0 {start|stop|restart}" 44 | esac 45 | exit 0 46 | -------------------------------------------------------------------------------- /src/rc/Debian/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | install-exec-local: 3 | if [ "$(distribution)" = "Debian" ] ; then \ 4 | CURDIR=`pwd`; \ 5 | $(mkinstalldirs) "$(DESTDIR)/etc/init.d"; \ 6 | $(INSTALL_SCRIPT) $(srcdir)/pdnsd "$(DESTDIR)/etc/init.d"; \ 7 | update-rc.d pdnsd defaults 19 ;\ 8 | fi 9 | -------------------------------------------------------------------------------- /src/rc/Debian/pdnsd.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # This script was written and contributed by Markus Mohr, and 5 | # slightly modified by me for version 1.0.6 (which obviously 6 | # broke it some way). I then applied a set of corrections 7 | # by Markus Mohr. 8 | # 9 | # Carsten Block has patched this with some magic so that 10 | # the actual script is generated by configure, and that 11 | # the pdnsd user is determined from pdnsd.conf 12 | # I changed this a little to use the --pdnsd-user option 13 | # of pdnsd to determine the run_as user. 14 | # 15 | 16 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 17 | 18 | test -x @prefix@/sbin/pdnsd || exit 0 19 | 20 | case "$1" in 21 | start) 22 | # Check if cache dir exists and recreate if neccessary 23 | test -d @cachedir@ || mkdir @cachedir@ 24 | RUNAS=`@prefix@/sbin/pdnsd --pdnsd-user` || echo -n " failed" 25 | [ -z "$RUNAS" ] && RUNAS=nobody 26 | chown $RUNAS @cachedir@ 27 | echo -n "Starting domain name service: pdnsd" 28 | start-stop-daemon --start --quiet --pidfile /var/run/pdnsd.pid --name pdnsd \ 29 | --exec @prefix@/sbin/pdnsd -- --daemon -p /var/run/pdnsd.pid \ 30 | || echo -n " failed" 31 | echo "." 32 | ;; 33 | 34 | stop) 35 | echo -n "Stopping domain name service: pdnsd" 36 | start-stop-daemon --stop --quiet --pidfile /var/run/pdnsd.pid --name pdnsd --exec @prefix@/sbin/pdnsd \ 37 | || echo -n " failed" 38 | echo "." 39 | ;; 40 | 41 | restart) 42 | $0 stop 43 | $0 start 44 | ;; 45 | 46 | *) 47 | echo "Usage: /etc/init.d/pdnsd {start|stop|restart}" >&2 48 | exit 1 49 | ;; 50 | esac 51 | 52 | exit 0 53 | -------------------------------------------------------------------------------- /src/rc/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = RedHat SuSE Debian Slackware ArchLinux 3 | 4 | EXTRA_DIST = README 5 | 6 | -------------------------------------------------------------------------------- /src/rc/README: -------------------------------------------------------------------------------- 1 | rc/ 2 | === 3 | 4 | These are start scripts for different Linux distros and other things that 5 | do not directly belong to pdnsd. 6 | If you do start scripts for the distro you use, please GPL them and send 7 | them in, so that they can be included in this package for other users. 8 | Note that there is NO WARRANTY OF ANY KIND on anything in this directory; 9 | read the COPYING that comes with pdnsd for details. 10 | So far there are files in the following directories: 11 | 12 | SuSE 13 | ---- 14 | pdnsd - Start script for SuSE Linux. Tested for 6.? but should run on some 15 | versions below. You can do 'make install' as root in the SuSE 16 | directory to install it, or you can install manually: 17 | --manual installation------------------------------------------------- 18 | For manual installation, copy it into /sbin/init.d/, go to 19 | /sbin/init.d/rc2.d/ and create there the following two symlinks: 20 | S11pdnsd -> ../pdnsd (do "ln -s ../pdnsd S11pdnsd" in that dir) 21 | K34pdnsd -> ../pdnsd (do "ln -s ../pdnsd K34pdnsd" in that dir) 22 | The numbers dictate the order different services are started and 23 | might need to be modified. Then edit your /etc/rc.config file and 24 | add the line "START_PDNSD=yes" to start pdnsd at boot time. 25 | ---------------------------------------------------------------------- 26 | If you used the 'make install' command, "START_PDNSD=yes" has been 27 | appended to your /etc/rc.config file, causing pdnsd to be started 28 | at boot time. If you don't want that, change the "yes" into "no". 29 | This start script was created from /sbin/init.d/skeleton by me, so the 30 | most is copyrighted by SuSE. They put it under the GPL, however, so 31 | the licence stated in COPYING also applies to this script. 32 | This is no official SuSE script, and SuSE naturally does NO support 33 | for it. 34 | 35 | Redhat 36 | ------ 37 | The contents of the Redhat directory and the following documentation were 38 | contributed by Torben Janssen. Thanks a lot! 39 | 40 | pdnsd - Start script for Redhat Linux. Tested for 6.1 but should run on 5.0+. 41 | You can do 'make install' as root in the Redhat directory to 42 | install it, or you can install manually: 43 | 44 | --manual installation------------------------------------------------- 45 | For manual installation, copy pdnsd into /etc/rc.d/init.d/ 46 | 47 | Then go to /etc/rc.d/rc3.d and create there the following symlink: 48 | S78pdnsd -> ../init.d/pdnsd 49 | (do "ln -f -s ../init.d/pdnsd S78pdnsd" in that dir) 50 | 51 | Then go to /etc/rc.d/rc0.d and create there the following symlink: 52 | K78pdnsd -> ../init.d/pdnsd 53 | (do "ln -f -s ../init.d/pdnsd K78pdnsd" in that dir) 54 | 55 | Then go to /etc/rc.d/rc6.d and create there the following symlink: 56 | K78pdnsd -> ../init.d/pdnsd 57 | (do "ln -f -s ../init.d/pdnsd K78pdnsd" in that dir) 58 | 59 | WHY 60 | --- 61 | the rc[0-6].d dirs includes the scripts which starts/stops the 62 | services on entering runlevel [0-6] 63 | the interesting runlevels on Redhat are: 64 | 0 - halt 65 | 3 - multi user system 66 | 6 - reboot 67 | The links have an 'S' or 'K' and a number at the beginnig. All links 68 | with 'S' starts the script on entering the runlevel and 'K' stops 69 | them. 70 | So, there's an 'S' link in rc3 and 'K' links in rc0 and rc6. 71 | I choose 78 as number, because there was no script with this number on 72 | my system. You can choose every number you want, AFAIK . 73 | 74 | This is no offical Redhat script, and Redhat naturally does NO support 75 | for it. 76 | 77 | Debian 78 | ------ 79 | The contents of the Debian directory were contributed by Markus Mohr. 80 | His installation instructions are (translated): 81 | Install the pdnsd script to /etc/init and run 82 | update-rc.d pdnsd defaults 19 83 | as root. 84 | 85 | Slackware 86 | --------- 87 | A Slackware start-up script rc.pdnsd was contributed by Nikola Kotur . 88 | His comments were: 89 | 90 | Slackware uses traditional BSD style init script layout instead of SystemV 91 | style startup scripts. So I adjusted the start-up script for pdnsd, and 92 | now it can be used with Slackware 9.1 distribution, and probably with all the 93 | others. 94 | 95 | Additional info: 96 | 1) put these lines in the /etc/rc.d/rc.M: 97 | if [ -x /etc/rc.d/rc.pdnsd ]; then 98 | /etc/rc.d/rc.pdnsd start 99 | fi 100 | 101 | 2) put these lines in the /etc/rc.d/rc.6 and /etc/rc.d/rc.K: 102 | if [ -x /etc/rc.d/rc.pdnsd ]; then 103 | /etc/rc.d/rc.pdnsd stop 104 | fi 105 | -------------------------------------------------------------------------------- /src/rc/RedHat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | # no need to create links. 'chkconfig' will take care of this. 3 | # In the spec case, chkconfig is called during rpm install 4 | install-exec-local: 5 | if [ "$(distribution)" = "RedHat" ] ; then \ 6 | $(mkinstalldirs) "$(DESTDIR)/etc/rc.d/init.d"; \ 7 | $(INSTALL_SCRIPT) $(srcdir)/pdnsd "$(DESTDIR)/etc/rc.d/init.d/pdnsd"; \ 8 | if [ "$(specbuild)" = "no" ] ; then \ 9 | /sbin/chkconfig --add pdnsd; \ 10 | fi \ 11 | fi 12 | 13 | -------------------------------------------------------------------------------- /src/rc/RedHat/pdnsd.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # /etc/rc.d/init.d/pdnsd 4 | # 5 | # Script for starting the Proxy DNS Daemon 6 | # Modified by Paul Rombouts, 2003 7 | # 8 | # chkconfig: 2345 11 89 9 | # description: Proxy DNS Daemon 10 | # processname: pdnsd 11 | # config: /etc/pdnsd.conf 12 | 13 | PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin 14 | 15 | # Source function library. 16 | . /etc/rc.d/init.d/functions 17 | 18 | # Source networking configuration. 19 | . /etc/sysconfig/network 20 | 21 | # Check that networking is up. 22 | if [[ $NETWORKING == [Nn][Oo] ]]; then exit 0; fi 23 | 24 | # Source sysconfig settings, if any. 25 | if [ -f /etc/sysconfig/pdnsd ]; then . /etc/sysconfig/pdnsd; fi 26 | 27 | start() { 28 | echo -n 'Starting pdnsd: ' 29 | daemon @prefix@/sbin/pdnsd -d -s -p /var/run/pdnsd.pid "$EXTRAOPTIONS" 30 | local RETVAL=$? 31 | echo 32 | if [ $RETVAL -eq 0 ]; then touch /var/lock/subsys/pdnsd; fi 33 | return $RETVAL 34 | } 35 | 36 | stop() { 37 | echo -n 'Shutting down pdnsd: ' 38 | killproc pdnsd 39 | local RETVAL=$? 40 | case @threadlib@ in 41 | [Ll]inux[Tt]hreads*|lt*) 42 | # Wait until all threads have terminated. 43 | local -i count=20 44 | while [[ count -gt 0 ]] && pidof pdnsd > /dev/null 45 | do 46 | usleep 200000 47 | let --count 48 | done 49 | ;; 50 | esac 51 | echo 52 | if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/pdnsd; fi 53 | return $RETVAL 54 | } 55 | 56 | restart() { 57 | stop 58 | start 59 | } 60 | 61 | # 62 | # See how we were called. 63 | # 64 | case "$1" in 65 | start) 66 | start 67 | ;; 68 | stop) 69 | stop 70 | ;; 71 | status) 72 | status pdnsd 73 | ;; 74 | reload) 75 | @prefix@/sbin/pdnsd-ctl config 76 | ;; 77 | restart) 78 | restart 79 | ;; 80 | condrestart) 81 | if [ -f /var/lock/subsys/pdnsd ]; then restart; fi 82 | ;; 83 | *) 84 | echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}" 85 | exit 1 86 | esac 87 | 88 | exit 89 | -------------------------------------------------------------------------------- /src/rc/Slackware/Makefile.am: -------------------------------------------------------------------------------- 1 | # TODO: write an install rule for the Slackware start-up script. 2 | 3 | install-exec-local: 4 | -------------------------------------------------------------------------------- /src/rc/Slackware/rc.pdnsd.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # /etc/rc.d/rc.pdnsd 4 | # 5 | # Starts the Proxy DNS Daemon 6 | # 7 | # description: Proxy DNS Daemon 8 | # processname: pdnsd 9 | # config: /etc/pdnsd.conf 10 | # distribution: Slackware 11 | # author: Nikola Kotur 12 | # 13 | # Additional info: 14 | # 1) put these lines in the /etc/rc.d/rc.M: 15 | # if [ -x /etc/rc.d/rc.pdnsd ]; then 16 | # /etc/rc.d/rc.pdnsd start 17 | # fi 18 | # 19 | # 2) put these lines in the /etc/rc.d/rc.6 and /etc/rc.d/rc.K: 20 | # if [ -x /etc/rc.d/rc.pdnsd ]; then 21 | # /etc/rc.d/rc.pdnsd stop 22 | # fi 23 | 24 | 25 | test -x @prefix@/sbin/pdnsd || exit 0 26 | [ -f @sysconfdir@/pdnsd.conf ] || exit 1 27 | 28 | RETVAL=0 29 | 30 | start() { 31 | echo -n "Starting pdnsd... " 32 | RETVAL=$? 33 | @prefix@/sbin/pdnsd -d 34 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pdnsd 35 | echo ' OK' 36 | } 37 | 38 | stop() { 39 | echo -n "Shutting down pdnsd... " 40 | killall pdnsd 41 | RETVAL=$? 42 | [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/pdnsd 43 | echo ' OK' 44 | } 45 | 46 | restart() { 47 | stop 48 | start 49 | } 50 | 51 | condrestart() { 52 | [ -e /var/lock/subsys/pdnsd ] && restart 53 | return 0 54 | } 55 | 56 | case "$1" in 57 | start) 58 | start 59 | ;; 60 | stop) 61 | stop 62 | ;; 63 | reload|restart) 64 | restart 65 | ;; 66 | condrestart) 67 | condrestart 68 | ;; 69 | *) 70 | echo $"Usage: $0 {start|stop|restart|condrestart|reload}" 71 | RETVAL=1 72 | esac 73 | 74 | exit $RETVAL 75 | -------------------------------------------------------------------------------- /src/rc/SuSE/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | install-exec-local: 3 | if [ "$(distribution)" = "SuSE" ] ; then \ 4 | CURDIR=`pwd`; \ 5 | $(mkinstalldirs) "$(DESTDIR)/sbin/init.d"; \ 6 | $(INSTALL_SCRIPT) $(srcdir)/pdnsd "$(DESTDIR)/sbin/init.d/pdnsd"; \ 7 | $(mkinstalldirs) "$(DESTDIR)/sbin/init.d/rc2.d"; \ 8 | cd "$(DESTDIR)/sbin/init.d/rc2.d"; \ 9 | ln -fs ../pdnsd K34pdnsd; ln -s ../pdnsd S11pdnsd; \ 10 | cd $$CURDIR ; \ 11 | $(mkinstalldirs) "$(DESTDIR)/sbin/init.d/rc3.d"; \ 12 | cd "$(DESTDIR)/sbin/init.d/rc3.d"; \ 13 | ln -fs ../pdnsd K34pdnsd; ln -s ../pdnsd S11pdnsd; \ 14 | cd $$CURDIR ; \ 15 | grep "START_PDNSD" "$(DESTDIR)/etc/rc.config" > /dev/null ; \ 16 | if [ $$? -eq 1 ] ; then \ 17 | echo -e "\n\n#\n# Set to yes to start pdnsd at boot time\n#\nSTART_PDNSD=yes" >> /etc/rc.config ; \ 18 | fi \ 19 | fi 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/rc/SuSE/pdnsd.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Copyright (c) 1995-1998 SuSE GmbH Nuernberg, Germany. 3 | # 4 | # Modified 2000 from SuSE Linux 6.3 /sbin/init.d/skeleton by Thomas Moestl 5 | # 6 | # /sbin/init.d/pdnsd 7 | # 8 | # and symbolic its link 9 | # 10 | # /sbin/rc?/pdnsd 11 | # 12 | 13 | . /etc/rc.config 14 | 15 | # Determine the base and follow a runlevel link name. 16 | base=${0##*/} 17 | link=${base#*[SK][0-9][0-9]} 18 | 19 | # Force execution if not called by a runlevel directory. 20 | test $link = $base && START_PDNSD=yes 21 | test "$START_PDNSD" = yes || exit 0 22 | 23 | # The echo return value for success (defined in /etc/rc.config). 24 | return=$rc_done 25 | case "$1" in 26 | start) 27 | echo -n "Starting pdnsd" 28 | ## Start daemon with startproc(8). If this fails 29 | ## the echo return value is set appropriate. 30 | 31 | startproc @prefix@/sbin/pdnsd -d || return=$rc_failed 32 | 33 | echo -e "$return" 34 | ;; 35 | stop) 36 | echo -n "Shutting down pdnsd" 37 | ## Stop daemon with killproc(8) and if this fails 38 | ## set echo the echo return value. 39 | 40 | killproc -TERM @prefix@/sbin/pdnsd || return=$rc_failed 41 | 42 | echo -e "$return" 43 | ;; 44 | restart) 45 | ## If first returns OK call the second, if first or 46 | ## second command fails, set echo return value. 47 | $0 stop && $0 start || return=$rc_failed 48 | ;; 49 | reload) 50 | $0 stop && $0 start || return=$rc_failed 51 | ;; 52 | status) 53 | echo -n "Checking for pdnsd: " 54 | ## Check status with checkproc(8), if process is running 55 | ## checkproc will return with exit status 0. 56 | 57 | checkproc @prefix@/sbin/pdnsd && echo OK || echo No process 58 | ;; 59 | *) 60 | echo "Usage: $0 {start|stop|status|restart|reload}" 61 | exit 1 62 | ;; 63 | esac 64 | 65 | # Inform the caller not only verbosely and set an exit status. 66 | test "$return" = "$rc_done" || exit 1 67 | exit 0 68 | 69 | -------------------------------------------------------------------------------- /src/rr_types.c: -------------------------------------------------------------------------------- 1 | /* rr_types.c - Tables with information for handling 2 | all rr types known to pdnsd, plus 3 | some helper functions useful for turning 4 | binary RR data into text or vice versa. 5 | 6 | Copyright (C) 2000, 2001 Thomas Moestl 7 | Copyright (C) 2003, 2004, 2007, 2010, 2011 Paul A. Rombouts 8 | 9 | This file is part of the pdnsd package. 10 | 11 | pdnsd is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | pdnsd is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with pdnsd; see the file COPYING. If not, see 23 | . 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #define DEFINE_RR_TYPE_ARRAYS 1 30 | #include "helpers.h" 31 | #include "dns.h" 32 | #include "rr_types.h" 33 | 34 | 35 | /* 36 | * OK, this is inefficient. But it is used _really_ seldom (only in some cases while parsing the 37 | * config file or by pdnsd-ctl), so it is much more effective to sort by id. 38 | */ 39 | int rr_tp_byname(char *name) 40 | { 41 | int i; 42 | 43 | for (i=0;i> 4); 65 | exponent = (prec & 0x0f); 66 | 67 | if(mantissa>=10 || exponent>=10) 68 | return NULL; 69 | if (exponent>= 2) 70 | sprintf(retbuf, "%u", mantissa * poweroften[exponent-2]); 71 | else 72 | sprintf(retbuf, "0.%.2u", mantissa * poweroften[exponent]); 73 | return (retbuf); 74 | } 75 | 76 | /* takes an on-the-wire LOC RR and formats it in a human readable format. 77 | This is an adapted version of the loc_ntoa function that 78 | can be found in the BIND 9 source. 79 | */ 80 | const char *loc2str(const void *binary, char *ascii, size_t asclen) 81 | { 82 | const unsigned char *cp = binary; 83 | 84 | int latdeg, latmin, latsec, latsecfrac; 85 | int longdeg, longmin, longsec, longsecfrac; 86 | char northsouth, eastwest; 87 | const char *altsign; 88 | int altmeters, altfrac; 89 | 90 | const uint32_t referencealt = 100000 * 100; 91 | 92 | int32_t latval, longval, altval; 93 | uint32_t templ; 94 | uint8_t sizeval, hpval, vpval, versionval; 95 | 96 | char sizestr[NPRECSIZE],hpstr[NPRECSIZE],vpstr[NPRECSIZE]; 97 | 98 | versionval = *cp++; 99 | 100 | if (versionval) { 101 | /* unknown LOC RR version */ 102 | return NULL; 103 | } 104 | 105 | sizeval = *cp++; 106 | 107 | hpval = *cp++; 108 | vpval = *cp++; 109 | 110 | GETINT32(templ, cp); 111 | latval = (templ - ((unsigned)1<<31)); 112 | 113 | GETINT32(templ, cp); 114 | longval = (templ - ((unsigned)1<<31)); 115 | 116 | GETINT32(templ, cp); 117 | if (templ < referencealt) { /* below WGS 84 spheroid */ 118 | altval = referencealt - templ; 119 | altsign = "-"; 120 | } else { 121 | altval = templ - referencealt; 122 | altsign = ""; 123 | } 124 | 125 | if (latval < 0) { 126 | northsouth = 'S'; 127 | latval = -latval; 128 | } else 129 | northsouth = 'N'; 130 | 131 | latsecfrac = latval % 1000; 132 | latval /= 1000; 133 | latsec = latval % 60; 134 | latval /= 60; 135 | latmin = latval % 60; 136 | latval /= 60; 137 | latdeg = latval; 138 | 139 | if (longval < 0) { 140 | eastwest = 'W'; 141 | longval = -longval; 142 | } else 143 | eastwest = 'E'; 144 | 145 | longsecfrac = longval % 1000; 146 | longval /= 1000; 147 | longsec = longval % 60; 148 | longval /= 60; 149 | longmin = longval % 60; 150 | longval /= 60; 151 | longdeg = longval; 152 | 153 | altfrac = altval % 100; 154 | altmeters = (altval / 100); 155 | 156 | if(!precsize_ntoa(sizeval,sizestr) || !precsize_ntoa(hpval,hpstr) || !precsize_ntoa(vpval,vpstr)) 157 | return NULL; 158 | { 159 | int n=snprintf(ascii,asclen, 160 | "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm", 161 | latdeg, latmin, latsec, latsecfrac, northsouth, 162 | longdeg, longmin, longsec, longsecfrac, eastwest, 163 | altsign, altmeters, altfrac, 164 | sizestr, hpstr, vpstr); 165 | if(n<0 || n>=asclen) 166 | return NULL; 167 | } 168 | 169 | return (ascii); 170 | } 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /src/rr_types.in: -------------------------------------------------------------------------------- 1 | # This file is part of the pdnsd package. 2 | 3 | # This file contains information about the RR types implemented in pdnsd 4 | # and is used for generating rr_types.h. 5 | # It was derived from the following source: http://www.bind9.net/dns-parameters 6 | # 7 | # After making modifications to this file the file rr_types.h should be regenerated! 8 | # 9 | # Info about the format of this file: 10 | # Blank lines and lines starting with '#' are ignored, all other lines 11 | # are assumed to define an RR type. Lines starting with '+' define most 12 | # frequently used types. An RR type preceded by a '-' will not be cached 13 | # by pdnsd. The next two fields are interpreted as the name and the value 14 | # of the RR type, resp. A subsequent word in parenthesis will be interpreted a 15 | # class name (used for conflict resolution). Remaining fields are ignored. 16 | # 17 | # Adding or removing an initial '+' can be done safely without requiring 18 | # changes to the source code (other than regenerating rr_types.h). 19 | # 20 | # If you are sure that you will never use certain RR types you can disable 21 | # caching for them and make pdnsd slightly more efficient by placing a 22 | # '-' sign in front of the lines that define those types. 23 | # For a list of obsolete RR types see e.g. 24 | # http://en.wikipedia.org/wiki/List_of_DNS_record_types . 25 | # Note that some RR types are essential for pdnsd; these are currently: 26 | # A, NS, CNAME, SOA, PTR, MX and (if you want IPv6 support) AAAA. 27 | # Disabling caching for these types will cause pdnsd to fail to compile 28 | # or cause a fatal run-time error. 29 | # 30 | # Removing a '-' sign to enable caching can be risky if the support in 31 | # the pdnsd code is missing or inadequate, so only do this if you really know 32 | # what you are doing. SPF records are supported, however, so it should be safe 33 | # to enable caching for them. 34 | 35 | # RR TYPE Value (class) and meaning Reference 36 | # ----------- --------------------------------------------- --------- 37 | + A 1 (RECORD) a host address [RFC 1035] 38 | + NS 2 an authoritative name server [RFC 1035] 39 | MD 3 a mail destination (Obsolete - use MX) [RFC 1035] 40 | MF 4 a mail forwarder (Obsolete - use MX) [RFC 1035] 41 | + CNAME 5 (ALIAS) the canonical name for an alias [RFC 1035] 42 | + SOA 6 marks the start of a zone of authority [RFC 1035] 43 | MB 7 a mailbox domain name (EXPERIMENTAL) [RFC 1035] 44 | MG 8 a mail group member (EXPERIMENTAL) [RFC 1035] 45 | MR 9 a mail rename domain name (EXPERIMENTAL) [RFC 1035] 46 | NULL 10 a null RR (EXPERIMENTAL) [RFC 1035] 47 | WKS 11 (RECORD) a well known service description [RFC 1035] 48 | + PTR 12 (PTR) a domain name pointer [RFC 1035] 49 | HINFO 13 (RECORD) host information [RFC 1035] 50 | MINFO 14 mailbox or mail list information [RFC 1035] 51 | + MX 15 mail exchange [RFC 1035] 52 | + TXT 16 text strings [RFC 1035] 53 | RP 17 (RECORD) for Responsible Person [RFC 1183] 54 | AFSDB 18 (RECORD) for AFS Data Base location [RFC 1183][RFC 5864] 55 | X25 19 (RECORD) for X.25 PSDN address [RFC 1183] 56 | ISDN 20 (RECORD) for ISDN address [RFC 1183] 57 | RT 21 (RECORD) for Route Through [RFC 1183] 58 | NSAP 22 (RECORD) for NSAP address, NSAP style A record [RFC 1706] 59 | NSAP-PTR 23 (PTR) for domain name pointer, NSAP style [RFC 1348] 60 | SIG 24 for security signature [RFC 4034][RFC 3755][RFC 2535] 61 | KEY 25 for security key [RFC 4034][RFC 3755][RFC 2535] 62 | PX 26 X.400 mail mapping information [RFC 2163] 63 | GPOS 27 (RECORD) Geographical Position [RFC 1712] 64 | + AAAA 28 (RECORD) IP6 Address [RFC 3596] 65 | LOC 29 (RECORD) Location Information [RFC 1876] 66 | NXT 30 Next Domain - OBSOLETE [RFC 3755][RFC 2535] 67 | EID 31 (RECORD) Endpoint Identifier [Patton] 68 | NIMLOC 32 (RECORD) Nimrod Locator [Patton] 69 | SRV 33 (RECORD) Server Selection [RFC 2782] 70 | ATMA 34 (RECORD) ATM Address [ATMDOC] 71 | NAPTR 35 (RECORD) Naming Authority Pointer [RFC 2915][RFC 2168][RFC 3403] 72 | KX 36 (RECORD) Key Exchanger [RFC 2230] 73 | CERT 37 (RECORD) CERT [RFC 4398] 74 | - A6 38 A6 (Experimental) [RFC 3226][RFC 2874] 75 | - DNAME 39 (ALIAS) DNAME [RFC 2672] 76 | - SINK 40 SINK [Eastlake] 77 | - OPT 41 OPT [RFC 2671] 78 | APL 42 APL [RFC 3123] 79 | DS 43 Delegation Signer [RFC 4034][RFC 3658] 80 | SSHFP 44 SSH Key Fingerprint [RFC 4255] 81 | IPSECKEY 45 IPSECKEY [RFC 4025] 82 | RRSIG 46 RRSIG [RFC 4034][RFC 3755] 83 | NSEC 47 NSEC [RFC 4034][RFC 3755] 84 | DNSKEY 48 DNSKEY [RFC 4034][RFC 3755] 85 | DHCID 49 DHCID [RFC 4701] 86 | NSEC3 50 NSEC3 [RFC 5155] 87 | NSEC3PARAM 51 NSEC3PARAM [RFC 5155] 88 | # Unassigned 52-54 89 | - HIP 55 Host Identity Protocol [RFC 5205] 90 | - NINFO 56 NINFO [Reid] 91 | - RKEY 57 RKEY [Reid] 92 | - TALINK 58 Trust Anchor LINK [Wijngaards] 93 | # Unassigned 59-98 94 | - SPF 99 Sender Policy Framework [RFC 4408] 95 | - UINFO 100 [IANA-Reserved] 96 | - UID 101 [IANA-Reserved] 97 | - GID 102 [IANA-Reserved] 98 | - UNSPEC 103 [IANA-Reserved] 99 | # Unassigned 104-248 100 | -------------------------------------------------------------------------------- /src/servers.h: -------------------------------------------------------------------------------- 1 | /* servers.h - manage a set of dns servers 2 | 3 | Copyright (C) 2000 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2004, 2005 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef _SERVERS_H_ 25 | #define _SERVERS_H_ 26 | 27 | #include 28 | #include "consts.h" 29 | 30 | /* Number of ping timeouts before we take a server offline. */ 31 | #define PINGREPEAT 2 32 | 33 | extern pthread_t servstat_thrid; 34 | extern volatile int signal_interrupt; 35 | 36 | 37 | int start_servstat_thread(void); 38 | void sched_server_test(pdnsd_a *sa, int nadr, int up); 39 | int mark_servers(int i, char* label, int up); 40 | void test_onquery(void); 41 | void lock_server_data(); 42 | void unlock_server_data(); 43 | int exclusive_lock_server_data(int tm); 44 | void exclusive_unlock_server_data(int retest); 45 | int change_servers(int i, addr_array ar, int up); 46 | 47 | inline static int needs_testing(servparm_t *sp) 48 | __attribute__((always_inline)); 49 | inline static int needs_testing(servparm_t *sp) 50 | { 51 | return ((sp->interval>0 || sp->interval==-2) && (sp->uptest!=C_NONE || sp->scheme[0])); 52 | } 53 | 54 | inline static int needs_intermittent_testing(servparm_t *sp) 55 | __attribute__((always_inline)); 56 | inline static int needs_intermittent_testing(servparm_t *sp) 57 | { 58 | return (sp->interval>0 && (sp->uptest!=C_NONE || sp->scheme[0])); 59 | } 60 | 61 | inline static int is_interrupted_servstat_thread() 62 | __attribute__((always_inline)); 63 | inline static int is_interrupted_servstat_thread() 64 | { 65 | return (signal_interrupt && pthread_equal(pthread_self(),servstat_thrid)); 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/sort_namevalues.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | my %dic; 6 | my $maxkeylen=0; 7 | 8 | while(<>) { 9 | if(/"(\w+)".*?(\w+)/) { 10 | my $key=$1; my $val=$2; 11 | if($dic{$key}) {die "The key \"$key\" does not have a unique value.\n"} 12 | $dic{$key}=$val; 13 | if(length($key)>$maxkeylen) {$maxkeylen=length($key)} 14 | } 15 | else {die "Can't find key-value pair in following line:\n$_\n"} 16 | } 17 | 18 | my $linenr=0; 19 | foreach my $key (sort(keys %dic)) { 20 | if($linenr++) {print ",\n"} 21 | printf("\t{%-*s%s}",$maxkeylen+4,"\"$key\",",$dic{$key}); 22 | } 23 | print "\n"; 24 | 25 | exit 26 | -------------------------------------------------------------------------------- /src/status.h: -------------------------------------------------------------------------------- 1 | /* status.h - Make server status information accessible through a named pipe 2 | 3 | Copyright (C) 2000, 2001 Thomas Moestl 4 | Copyright (C) 2002, 2004, 2008, 2009 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef _STATUS_H_ 25 | #define _STATUS_H_ 26 | 27 | #include 28 | #include "conff.h" 29 | 30 | extern char *sock_path; 31 | extern int stat_sock; 32 | 33 | /* The commands for pdnsd-ctl */ 34 | #define CTL_CMDVERNR 0x6800 /* pdnsd-ctl command version (magic number used to check compatibility) */ 35 | 36 | #define CTL_MIN 1 37 | #define CTL_STATS 1 /* Give out stats (like the "traditional" status pipe) */ 38 | #define CTL_SERVER 2 /* Enable or disable a server */ 39 | #define CTL_RECORD 3 /* Delete or invalidate records */ 40 | #define CTL_SOURCE 4 /* Read a hosts-style file */ 41 | #define CTL_ADD 5 /* Add a record of the given type */ 42 | #define CTL_NEG 6 /* Add a negative cached record */ 43 | #define CTL_CONFIG 7 /* Re-read config file */ 44 | #define CTL_INCLUDE 8 /* Read file as config file, disregarding global and server sections */ 45 | #define CTL_EVAL 9 /* Parse string as if part of config file */ 46 | #define CTL_EMPTY 10 /* Empty the cache */ 47 | #define CTL_DUMP 11 /* Dump cache contents */ 48 | #define CTL_MAX 11 49 | 50 | #define CTL_S_UP 1 51 | #define CTL_S_DOWN 2 52 | #define CTL_S_RETEST 3 53 | #define CTL_R_DELETE 1 54 | #define CTL_R_INVAL 2 55 | 56 | void init_stat_sock(void); 57 | int start_stat_sock(void); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/test/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: all clean distclean 3 | 4 | noinst_PROGRAMS = if_up is_local_addr tping random 5 | 6 | ## Dirty trick: I demand that these objects be built; then, with the knowledge 7 | ## that the object files will end up here, I redefine the link chain. 8 | 9 | TESTADDSRC= 10 | #TESTADDSRC= netdev.c error.c thread.c helpers.c icmp.c 11 | TESTDEPS = netdev.o error.o thread.o helpers.o icmp.o 12 | 13 | TESTOBJS = netdev.o error.o thread.o helpers.o icmp.o 14 | 15 | if_up_SOURCES = if_up.c $(TESTADDSRC) 16 | if_up_LDADD = $(TESTOBJS) @thread_CFLAGS@ 17 | if_up_DEPENDENCIES = $(TESTDEPS) 18 | 19 | is_local_addr_SOURCES = is_local_addr.c $(TESTADDSRC) 20 | is_local_addr_LDADD = $(TESTOBJS) @thread_CFLAGS@ 21 | is_local_addr_DEPENDENCIES = $(TESTDEPS) 22 | 23 | tping_SOURCES = tping.c $(TESTADDSRC) 24 | tping_LDADD = $(TESTOBJS) @thread_CFLAGS@ 25 | tping_DEPENDENCIES = $(TESTDEPS) 26 | 27 | random_SOURCES = random.c $(TESTADDSRC) 28 | random_LDADD = $(TESTOBJS) @thread_CFLAGS@ 29 | random_DEPENDENCIES = $(TESTDEPS) 30 | 31 | # These are Symlinks we want to have in the package 32 | #EXTRA_DIST = conff.h error.h helpers.h icmp.h ipvers.h netdev.h thread.h cacheing 33 | 34 | $(TESTOBJS): %.o: ../%.c 35 | $(COMPILE) @thread_CFLAGS@ -c $< 36 | -------------------------------------------------------------------------------- /src/test/if_up.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../helpers.h" 6 | #include "../conff.h" 7 | #include "../netdev.h" 8 | 9 | short int daemon_p=0; 10 | #if DEBUG>0 11 | short int debug_p=0; 12 | #endif 13 | short int verbosity=VERBOSITY; 14 | #if defined(ENABLE_IPV4) && defined(ENABLE_IPV6) 15 | short int run_ipv4=DEFAULT_IPV4; 16 | #endif 17 | #ifdef ENABLE_IPV6 18 | struct in6_addr ipv4_6_prefix; 19 | #endif 20 | pthread_t main_thrid,servstat_thrid; 21 | volatile int signal_interrupt; 22 | #if DEBUG>0 23 | FILE *dbg_file; 24 | #endif 25 | globparm_t global; 26 | 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | if (argc!=2) { 31 | printf("Usage: %s \n",argv[0]); 32 | exit(1); 33 | } 34 | printf("if_up: %s - %s\n",argv[1],if_up(argv[1])?"up":"down"); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/test/is_local_addr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../helpers.h" 6 | #include "../conff.h" 7 | #include "../netdev.h" 8 | #include "../ipvers.h" 9 | 10 | short int daemon_p=0; 11 | #if DEBUG>0 12 | short int debug_p=0; 13 | #endif 14 | short int verbosity=VERBOSITY; 15 | #if defined(ENABLE_IPV4) && defined(ENABLE_IPV6) 16 | short int run_ipv4=DEFAULT_IPV4; 17 | #endif 18 | #ifdef ENABLE_IPV6 19 | struct in6_addr ipv4_6_prefix; 20 | #endif 21 | pthread_t main_thrid,servstat_thrid; 22 | volatile int signal_interrupt; 23 | #if DEBUG>0 24 | FILE *dbg_file; 25 | #endif 26 | globparm_t global; 27 | 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | pdnsd_a a; 32 | 33 | if (argc!=2) { 34 | printf("Usage: %s
    \n",argv[0]); 35 | exit(1); 36 | } 37 | #ifdef ENABLE_IPV4 38 | if (inet_aton(argv[1],&a.ipv4)) { 39 | # ifdef ENABLE_IPV6 40 | run_ipv4=1; 41 | # endif 42 | printf("is %s a local addr: %s\n",argv[1],is_local_addr(&a)?"yes":"no"); 43 | return 0; 44 | } 45 | #endif 46 | #ifdef ENABLE_IPV6 47 | if (inet_pton(AF_INET6,argv[1],&a.ipv6)) { 48 | # ifdef ENABLE_IPV4 49 | run_ipv4=0; 50 | # endif 51 | printf("is %s a local addr: %s\n",argv[1],is_local_addr(&a)?"yes":"no"); 52 | return 0; 53 | } 54 | #endif 55 | printf("Adress invalid.\n"); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /src/test/random.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../helpers.h" 6 | #include "../conff.h" 7 | 8 | short int daemon_p=0; 9 | #if DEBUG>0 10 | short int debug_p=0; 11 | #endif 12 | short int verbosity=VERBOSITY; 13 | #if defined(ENABLE_IPV4) && defined(ENABLE_IPV6) 14 | short int run_ipv4=DEFAULT_IPV4; 15 | #endif 16 | #ifdef ENABLE_IPV6 17 | struct in6_addr ipv4_6_prefix; 18 | #endif 19 | pthread_t main_thrid,servstat_thrid; 20 | volatile int signal_interrupt; 21 | #if DEBUG>0 22 | FILE *dbg_file; 23 | #endif 24 | globparm_t global; 25 | 26 | 27 | int main(void) 28 | { 29 | init_rng(); 30 | printf("%i\n",(int)get_rand16()); 31 | free_rng(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/test/tping.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../helpers.h" 6 | #include "../conff.h" 7 | #include "../icmp.h" 8 | #include "../ipvers.h" 9 | 10 | short int daemon_p=0; 11 | #if DEBUG>0 12 | short int debug_p=0; 13 | #endif 14 | short int verbosity=VERBOSITY; 15 | #if defined(ENABLE_IPV4) && defined(ENABLE_IPV6) 16 | short int run_ipv4=DEFAULT_IPV4; 17 | #endif 18 | #ifdef ENABLE_IPV6 19 | struct in6_addr ipv4_6_prefix; 20 | #endif 21 | pthread_t main_thrid,servstat_thrid; 22 | volatile int signal_interrupt; 23 | #if DEBUG>0 24 | FILE *dbg_file; 25 | #endif 26 | globparm_t global; 27 | 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | pdnsd_a a; 32 | 33 | if (argc!=2) { 34 | printf("Usage: %s
    \n",argv[0]); 35 | exit(1); 36 | } 37 | #ifdef ENABLE_IPV4 38 | if (inet_aton(argv[1],&a.ipv4)) { 39 | # ifdef ENABLE_IPV6 40 | run_ipv4=1; 41 | # endif 42 | init_ping_socket(); 43 | printf("ping (v4) echo from %s: %i\n",argv[1],ping(&a,100,2)); 44 | return 0; 45 | } 46 | #endif 47 | #ifdef ENABLE_IPV6 48 | if (inet_pton(AF_INET6,argv[1],&a.ipv6)) { 49 | # ifdef ENABLE_IPV4 50 | run_ipv4=0; 51 | # endif 52 | init_ping_socket(); 53 | printf("ping (v6) echo from %s: %i\n",argv[1],ping(&a,100,2)); 54 | return 0; 55 | } 56 | #endif 57 | printf("Adress invalid.\n"); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /src/thread.c: -------------------------------------------------------------------------------- 1 | /* thread.c - Threading helpers 2 | 3 | Copyright (C) 2000 Thomas Moestl 4 | Copyright (C) 2002, 2003 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "thread.h" 33 | #include "error.h" 34 | #include "helpers.h" 35 | #include "conff.h" 36 | 37 | 38 | #if (TARGET==TARGET_LINUX) && !defined(THREADLIB_NPTL) 39 | volatile short int waiting=0; /* Has the main thread already done sigwait() ? */ 40 | #endif 41 | pthread_attr_t attr_detached; 42 | #if DEBUG>0 43 | pthread_key_t thrid_key; 44 | #endif 45 | 46 | /* This is a handler for signals to the threads. We just hand the sigs on to the main thread. 47 | * Note that this may result in blocked locks. We have no means to open the locks here, because in LinuxThreads 48 | * the mutex functions are not async-signal safe. So, locks may still be active. We account for this by using 49 | * softlocks (see below) in any functions called after sigwait from main(). */ 50 | #if (TARGET==TARGET_LINUX) && !defined(THREADLIB_NPTL) 51 | void thread_sig(int sig) 52 | { 53 | if (sig==SIGTSTP || sig==SIGTTOU || sig==SIGTTIN) { 54 | /* nonfatal signal. Ignore, because proper handling is very difficult. */ 55 | return; 56 | } 57 | if (waiting) { 58 | log_warn("Caught signal %i.",sig); 59 | if (sig==SIGSEGV || sig==SIGILL || sig==SIGBUS) 60 | crash_msg("A fatal signal occured."); 61 | pthread_kill(main_thrid,SIGTERM); 62 | pthread_exit(NULL); 63 | } else { 64 | crash_msg("An error occured at startup."); 65 | _exit(1); 66 | } 67 | } 68 | #endif 69 | 70 | /* This is now defined as an inline function in thread.h */ 71 | #if 0 72 | void usleep_r(unsigned long usec) 73 | { 74 | #if ((TARGET==TARGET_LINUX) || (TARGET==TARGET_BSD) || (TARGET==TARGET_CYGWIN)) && defined(HAVE_USLEEP) 75 | usleep(usec); 76 | #else 77 | struct timeval tv; 78 | 79 | tv.tv_sec=usec/1000000; 80 | tv.tv_usec=usec%1000000; 81 | select(0, NULL, NULL, NULL, tv); 82 | #endif 83 | } 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /src/thread.h: -------------------------------------------------------------------------------- 1 | /* thread.h - Threading helpers 2 | 3 | Copyright (C) 2000 Thomas Moestl 4 | Copyright (C) 2002, 2003, 2005 Paul A. Rombouts 5 | 6 | This file is part of the pdnsd package. 7 | 8 | pdnsd is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | pdnsd is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with pdnsd; see the file COPYING. If not, see 20 | . 21 | */ 22 | 23 | 24 | #ifndef _THREAD_H_ 25 | #define _THREAD_H_ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | /* --- from main.c */ 32 | extern sigset_t sigs_msk; 33 | /* --- */ 34 | 35 | #if (TARGET==TARGET_LINUX) && !defined(THREADLIB_NPTL) 36 | extern volatile short int waiting; 37 | void thread_sig(int sig); 38 | #endif 39 | 40 | /* These are macros for setting up the signal handling of a new thread. They 41 | * are needed because the LinuxThreads implementation obviously has some 42 | * problems in signal handling, which makes the recommended solution (doing 43 | * sigwait() in one thread and blocking the signals in all threads) impossible. 44 | * So, for Linux, we have to install the fatal_sig handler. 45 | * It seems to me that signal handlers in fact aren't shared between threads 46 | * under Linux. Also, sigwait() does not seem to work as indicated in the docs */ 47 | 48 | /* Note added by Paul Rombouts: In the new Native POSIX Thread Library for Linux (NPTL) 49 | signal handling has changed from per-thread signal handling to POSIX process signal handling, 50 | which makes the recommended solution mentioned by Thomas Moestl possible. 51 | In this case I can simply define THREAD_SIGINIT to be empty. 52 | The signals are blocked in main() before any threads are created, 53 | and we simply never unblock them except by calling sigwait() in main(). */ 54 | 55 | #if (TARGET==TARGET_LINUX) 56 | # ifdef THREADLIB_NPTL 57 | # define THREAD_SIGINIT 58 | # else 59 | # ifdef THREADLIB_LINUXTHREADS2 60 | # define THREAD_SIGINIT { \ 61 | struct sigaction action; \ 62 | pthread_sigmask(SIG_UNBLOCK,&sigs_msk,NULL); \ 63 | action.sa_handler = thread_sig; \ 64 | action.sa_mask = sigs_msk; \ 65 | action.sa_flags = 0; \ 66 | sigaction(SIGINT,&action,NULL); \ 67 | sigaction(SIGILL,&action,NULL); \ 68 | sigaction(SIGABRT,&action,NULL); \ 69 | sigaction(SIGFPE,&action,NULL); \ 70 | sigaction(SIGSEGV,&action,NULL); \ 71 | sigaction(SIGTSTP,&action,NULL); \ 72 | sigaction(SIGTTOU,&action,NULL); \ 73 | sigaction(SIGTTIN,&action,NULL); \ 74 | sigaction(SIGTERM,&action,NULL); \ 75 | action.sa_handler = SIG_IGN; \ 76 | sigemptyset(&action.sa_mask); \ 77 | action.sa_flags = 0; \ 78 | sigaction(SIGPIPE,&action,NULL); \ 79 | } 80 | # else 81 | # define THREAD_SIGINIT { \ 82 | struct sigaction action; \ 83 | pthread_sigmask(SIG_UNBLOCK,&sigs_msk,NULL); \ 84 | action.sa_handler = thread_sig; \ 85 | action.sa_mask = sigs_msk; \ 86 | action.sa_flags = 0; \ 87 | sigaction(SIGILL,&action,NULL); \ 88 | sigaction(SIGABRT,&action,NULL); \ 89 | sigaction(SIGFPE,&action,NULL); \ 90 | sigaction(SIGSEGV,&action,NULL); \ 91 | sigaction(SIGTSTP,&action,NULL); \ 92 | sigaction(SIGTTOU,&action,NULL); \ 93 | sigaction(SIGTTIN,&action,NULL); \ 94 | action.sa_handler = SIG_IGN; \ 95 | sigemptyset(&action.sa_mask); \ 96 | action.sa_flags = 0; \ 97 | sigaction(SIGPIPE,&action,NULL); \ 98 | } 99 | # endif 100 | # endif 101 | #elif (TARGET==TARGET_BSD) || (TARGET==TARGET_CYGWIN) 102 | #define THREAD_SIGINIT pthread_sigmask(SIG_BLOCK,&sigs_msk,NULL) 103 | #else 104 | # error Unsupported platform! 105 | #endif 106 | 107 | 108 | /* This is a thread-safe usleep(). 109 | Implementation of the BSD usleep function using nanosleep. 110 | */ 111 | inline static int usleep_r(unsigned long useconds) 112 | __attribute__((always_inline)); 113 | inline static int usleep_r(unsigned long useconds) 114 | { 115 | struct timespec ts = { tv_sec: (useconds / 1000000), 116 | tv_nsec: (useconds % 1000000) * 1000ul }; 117 | 118 | return nanosleep(&ts, NULL); 119 | } 120 | 121 | /* This is a thread-safe sleep(). 122 | The semantics are somewhat different from the POSIX sleep function, 123 | but it suits our purposes. 124 | */ 125 | inline static int sleep_r (unsigned int seconds) 126 | __attribute__((always_inline)); 127 | inline static int sleep_r (unsigned int seconds) 128 | { 129 | struct timespec ts = { tv_sec: seconds, tv_nsec: 0 }; 130 | 131 | return nanosleep(&ts, NULL); 132 | } 133 | 134 | 135 | /* Used for creating detached threads */ 136 | extern pthread_attr_t attr_detached; 137 | 138 | #if DEBUG>0 139 | /* Key for storing private thread ID's */ 140 | extern pthread_key_t thrid_key; 141 | #endif 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | 1.2.9b-par 2 | --------------------------------------------------------------------------------