summaryrefslogtreecommitdiff
path: root/net-dns/pdnsd
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
committerV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
commit4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch)
treeba5f07bf3f9d22d82e54a462313f5d244036c768 /net-dns/pdnsd
reinit the tree, so we can have metadata
Diffstat (limited to 'net-dns/pdnsd')
-rw-r--r--net-dns/pdnsd/Manifest11
-rw-r--r--net-dns/pdnsd/files/pdnsd.conf.test27
-rw-r--r--net-dns/pdnsd/files/pdnsd.online.233
-rw-r--r--net-dns/pdnsd/files/pdnsd.rc827
-rw-r--r--net-dns/pdnsd/files/pdnsd.resolvconf-r1631
-rw-r--r--net-dns/pdnsd/files/pdnsd.service11
-rw-r--r--net-dns/pdnsd/files/pdnsd.tmpfiles1
-rw-r--r--net-dns/pdnsd/metadata.xml24
-rw-r--r--net-dns/pdnsd/pdnsd-1.2.9a-r1.ebuild131
9 files changed, 896 insertions, 0 deletions
diff --git a/net-dns/pdnsd/Manifest b/net-dns/pdnsd/Manifest
new file mode 100644
index 000000000000..80289638fa30
--- /dev/null
+++ b/net-dns/pdnsd/Manifest
@@ -0,0 +1,11 @@
+AUX pdnsd.conf.test 370 SHA256 b37d79771d6be11ec9bedbbd582d905fbe7b0372212de6de9cf242509a34f8d1 SHA512 1882df76c4f3280041b9045b8ae06b929c8c418206270c25b09e604e591a5fb287328af340ec9164fb36c5af8bd2c9216a6a0fdf6eefad3986cc3221880d8138 WHIRLPOOL 00bd58f8cc7be55f1305f31363bf14b4c7f186e25d0f316ef076ef6936c1cb8db1f794c66cae889b7093c9d105bce3fd6fe699adfcd6edfa15b2a3172deb9997
+AUX pdnsd.online.2 568 SHA256 77c3585500a7ccc8f4535300ce5fe1871423cbb2242cc2d22a6ecb0b6c958628 SHA512 d1844e7e21a0f2fb44779604883f21117b8aefa900e842ed079ada0769288416bf288f424a6980f0744b92b0e502af3e578bfcdadc59187f4c4693e306241efb WHIRLPOOL faad847bc08cf856840d1a341b084bb81d466dc2e21c4a3939805c6c793d676fe8cc1906183845d0363a4aa931e38eec72e5d24a60b74d0d3abedbf7093f0452
+AUX pdnsd.rc8 573 SHA256 27b7bd5c0ec3bb026ccd2e47e7ac6f87869a9820bf4ba85a99d7cd4b1a3b826a SHA512 be012cc164301bada209dfa26087eac85735fae2dd82d76e3f1154ba21df122be2be05bc029e9219c69514de4835495aed51dcbb99e19daf3fec75110b5d941c WHIRLPOOL 6b685bfb0fd756ab989cceddb2dfc8aa24bb8c306d73a88e17e0e3a622fdb4873eda4513a8956f9bd44b1655a1415e9f4e28445323e0e92e662ba6df0acedadc
+AUX pdnsd.resolvconf-r1 17538 SHA256 40bdcc876ba8bb86069d52f8023fed468974004f47c235c202ca7eac88aa0fe3 SHA512 22a92df825d560ec03860c1a9a6000f32e19b33ccda0f6412830ebca13499e6d45161267bb30658aa9ed4b5862bae04e304e25358c30ee6d80a9deea90ba989f WHIRLPOOL c6c08c105be3986d1d0c8b86d2cf9f0a36e2608b207ec3db084f46f55dd6f0764d999179133783ac055c75c14542d049f3240cb11036c162eeb5d820811ca3cb
+AUX pdnsd.service 269 SHA256 c0db5c9844b3d882f8c6f22db839006f6616a0690b6bbd6bb4668207590f0e82 SHA512 c1504f52fb30ba197bd3c3450f200f2f274bf73f7a6436bc317ad9affc18e9c5edcb8555913a4aa9c6bf44b935e0c9cd005b4f5b0fd56eed6e11914f63db9ef2 WHIRLPOOL ed8fcdbe4acef862a3faff7322ff8fa4c2ed3923fe3931dfed6887425c52061132022c465f01082b4d76a2f15624ddb9b39886b766817897603853aed93abe1a
+AUX pdnsd.tmpfiles 37 SHA256 db6537c715c0acfd47a4ca64fce3cbb29913705462a0abbb32fdabef38cdab52 SHA512 7beacc66e8504ca0f8e613dfc8ed2479362f1ebc98ffab902622b36c795fe75e176d9f0a330ad74e10a7f7b1597cce068d94eea6511a75b941e42b2458b76df5 WHIRLPOOL f785b6980c7e1748384a4f56f6744263ab28944e42b1741f7ebe1e3e6a5638b8fbcae5f0b4e9295127258908174bfb2ffdf9b01cd89e28d80017f2e156e25e5f
+DIST pdnsd-1.2.9a-par.tar.gz 516061 SHA256 bb5835d0caa8c4b31679d6fd6a1a090b71bdf70950db3b1d0cea9cf9cb7e2a7b SHA512 4fde296642306aa986ddb7cad0b5991bcd397656d93ef4962706276848c7fa62c664a40198e807d029637f116e8000c237d98b91cbbfec5c08b134d8bb3adf81 WHIRLPOOL 9f1f94d6aece1d5cdffe4799e532b1f88217e8d0fef83d097fd03a24a958ad551154efa1f1b719a31315be5e225f33cc7da5c40e3f13a0acba6686e0f6376573
+EBUILD pdnsd-1.2.9a-r1.ebuild 4074 SHA256 7d995cb65f4457e41e0877e80def7e60d4b1e11a014cb450feeba0cc3b429612 SHA512 2378463b4df77ed3cca083e4434ccbec9b1bfebe65a2fbd42acb10a90f1ae22e43e875302fcf5a47c35702b57186a4303234f29b2618d502ee06e75d13d6c554 WHIRLPOOL bd7ea83af46499a82f7ba50ae739f8b9d203b48a75e9ede4bf1abefaff39137bc30b0e324fe862c8fb56ed25c00fbed529fead9388678b552b5dfb85e80e273e
+MISC ChangeLog 3293 SHA256 9cbe441c6561dc27cd5d0beaff85096b9c5d40ce7806c773afb986cd4320b0a1 SHA512 a91c16966a5db04e90335cf481781c58ec86273a4ecce322a13650f72e3ba09685b363fa787693fea6fa43daaa1c9846cf34c6a2822b45b2988bb4c15f0c408f WHIRLPOOL 78a9e341f825ed939da0af2aef396e18169b3658dd67d64b1490c66ea6a9803108e94d0ece625a87cd8d298d98b2837d54befb3eae77aaa09be11b75532d861d
+MISC ChangeLog-2015 19527 SHA256 132d3d9bf183812494f576f7df9ae1e063c5460254cbcf58176608cfd6857f71 SHA512 8740c224e7fc24e363f1606f81416a6db7732c771377dd6f86f72663c8a8890f011ec7c37aeed705e5e28c8c5d5030b08ca3dbe0dc2ea2df1397624801f8f7f6 WHIRLPOOL 410e7635d1824d370a9e128aa5c2e620aacb13ddb85ec139d9f87b5a36fa1b8e2d082fe701086c7c9ee7f39db5d78092e5084264c6e680b60b1a5fce8c5deaac
+MISC metadata.xml 814 SHA256 226bc1a2e634ec4238314651b2243f4222e6c78d5cb00bf6a9737964f8fafc0e SHA512 b5bca37d42c4c50031a968297332e824e2830481903ae4036347ffbf554a0a37efb582d8a52b6bba48a0566db81942b1052aca5ed16bbe248fcec46ea99090a8 WHIRLPOOL 7e7aafc09bfcebb42159cea26f58cc62f9cc6389aee87257fa336bcf9b73efb9e3291e94f00b6966ad3785a12db9a1ce0e9383f67793e580e030cdb320cd4507
diff --git a/net-dns/pdnsd/files/pdnsd.conf.test b/net-dns/pdnsd/files/pdnsd.conf.test
new file mode 100644
index 000000000000..10a5d7abb912
--- /dev/null
+++ b/net-dns/pdnsd/files/pdnsd.conf.test
@@ -0,0 +1,27 @@
+// $Id: pdnsd.conf.in,v 1.4 2000/11/11 20:32:58 thomas Exp $
+
+global {
+ perm_cache=512;
+ cache_dir=;
+ max_ttl=604800;
+ paranoid=on;
+ server_port=33455;
+ server_ip=127.0.0.1;
+ status_ctl=on;
+}
+
+server {
+ ip=
+ timeout=30;
+ interval=30;
+ uptest=ping;
+ ping_timeout=50;
+ purge_cache=off;
+}
+
+source {
+ ttl=86400;
+ owner="localhost.";
+ serve_aliases=on;
+ file="/etc/hosts";
+}
diff --git a/net-dns/pdnsd/files/pdnsd.online.2 b/net-dns/pdnsd/files/pdnsd.online.2
new file mode 100644
index 000000000000..089f4e76e9cc
--- /dev/null
+++ b/net-dns/pdnsd/files/pdnsd.online.2
@@ -0,0 +1,33 @@
+#!/sbin/openrc-run
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+command="/usr/sbin/pdnsd-ctl"
+
+depend() {
+ need pdnsd
+}
+
+wait_for_socket() {
+ local i=0 pdnsd_socket="/var/cache/pdnsd/pdnsd.status"
+ while [ $i -lt 10 ]; do
+ [ -S "${pdnsd_socket}" ] && return 0
+ i=$(($i+1))
+ sleep 1s
+ done
+
+ return 1
+}
+
+start() {
+ wait_for_socket || return 1
+ ebegin "Starting pdnsd-online"
+ ${command} -q server all up
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping pdnsd-online"
+ ${command} -q server all down
+ eend $?
+}
diff --git a/net-dns/pdnsd/files/pdnsd.rc8 b/net-dns/pdnsd/files/pdnsd.rc8
new file mode 100644
index 000000000000..1f216fbc2d01
--- /dev/null
+++ b/net-dns/pdnsd/files/pdnsd.rc8
@@ -0,0 +1,27 @@
+#!/sbin/openrc-run
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+pidfile="/run/pdnsd.pid"
+command="/usr/sbin/pdnsd"
+command_args="-s -t -d -p ${pidfile} ${PDNSDCONFIG}"
+extra_started_commands="reload"
+
+depend() {
+ use net
+ provide dns
+}
+
+start_pre() {
+ if [ ! -e /etc/pdnsd/pdnsd.conf ] ; then
+ eerror "You need an /etc/pdnsd/pdnsd.conf file first."
+ eerror "There is a sample in /etc/pdnsd/pdnsd.conf.sample"
+ return 1
+ fi
+}
+
+reload() {
+ ebegin "Reloading pdnsd.conf"
+ /usr/sbin/pdnsd-ctl config
+ eend $?
+}
diff --git a/net-dns/pdnsd/files/pdnsd.resolvconf-r1 b/net-dns/pdnsd/files/pdnsd.resolvconf-r1
new file mode 100644
index 000000000000..edc1c9994f0a
--- /dev/null
+++ b/net-dns/pdnsd/files/pdnsd.resolvconf-r1
@@ -0,0 +1,631 @@
+#!/bin/bash
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# /etc/pdnsd/pdnsd.conf updater
+# Written by Oldrich Jedlicka (oldium.pro@seznam.cz)
+
+# Implementation notes:
+# * The assumptions are same as for other scripts like bind and dnsmasq:
+# - We assume that we are a local dns cache - after all, why would a server
+# use resolvconf?
+# - Now that we have assumed this, we also assume that generic DHCP clients
+# will enter their domains and search domains ONLY in the "search" field
+# in their resolv.confs and VPN clients will put the domain they are for
+# into the domain field only.
+# - This allows pdnsd to forward domains for a specific VPN domain to the
+# VPN nameserver and everything else to the standard name servers.
+#
+# HOW-TO CONFIGURE:
+#
+# To get this working, you need to do only two steps
+#
+# 1. Create a basic configuration of /etc/pdnsd/pdnsd.conf, you can use
+# /etc/pdnsd/pdnsd.conf.example to start.
+#
+# Additional configuration will be created automatically be resolvconf.
+# The generated server sections has labels starting with "resolvconf", so
+#
+# DO NOT USE "resolvconf" IN YOUR LABELS!
+#
+# Check if the status_ctl is set to "on", otherwise the configuration
+# will not be automatically reloaded - see sample config file.
+#
+# You are free to edit automatically created server sections, but always
+# write one option per line. There are few options that are always recreated
+# and your changes in them will be lost. Here is the list (with example
+# values):
+#
+# preset=on;
+# ip="192.168.0.1","192.168.0.2";
+# include=".net",".com";'
+#
+# The exclude directive in "resolvconf" server section is partly recreated.
+# Known (configured) domains in the form ".<domain>" or ".<domain>." are
+# added and removed automatically, unknown domains (also those not in
+# the format above) found in this directive are kept.
+#
+# The sample configuration file /etc/pdnsd/pdnsd.conf prepared to work
+# with resolvconf would look like this:
+#
+#global {
+# perm_cache=2048;
+# run_as="pdnsd";
+# status_ctl = on; # Important to enable status control
+# run_ipv4=on;
+# par_queries=2; # How many servers are probed in parallel
+# interface = "lo"; # Interface on which the pdnsd listens
+#}
+#
+# 2. The last step is to configure dns configuration for /etc/resolv.conf
+# for the lo interface. In Gentoo we set it up like so in /etc/conf.d/net
+#
+# dns_servers_lo=( "127.0.0.1" )
+
+# pdnsd config file
+PDNSDCONFIG="/etc/pdnsd/pdnsd.conf"
+
+# Backup suffix
+BACKUPSUFFIX=".backup"
+
+# Load our variables from resolvconf
+VARS="$(resolvconf -v)"
+eval "${VARS}"
+
+COMMENT='
+# Automatically generated by resolvconf.
+#
+# Following server sections are automatically enabled and disabled.
+#
+# !!! WARNING !!!
+# DO NOT RENAME LABELS!
+#
+# No section will be deleted and only some options are automatically changed.
+# Feel free to add your own options, but do not use pair comments /* */ as they
+# are not recognised.
+#
+# DO NOT USE resolvconf ANYWHERE IN YOUR LABELS!
+#
+# Automatically changed options are (with examples):
+# preset=on;
+# ip="192.168.0.1","192.168.0.2";
+# include=".net",".com";
+# exclude=".domain.net",".domain.com";
+# policy=excluded;
+#
+# The exclude directive is changed automatically only in "resolvconf" server
+# section. Not handled servers are kept in the directive.
+#'
+BASIC_SETTINGS='server {
+ label="resolvconf";
+ preset=off;
+}'
+
+INSTALLATION_CHECK='^[[:space:]]*label[[:space:]]*=[[:space:]]*"resolvconf"'
+
+###
+# Sed script configuration
+#
+# Composed sequence of lines:
+#
+# (1) SED_LOOP with @MATCH_LABELS@ substituted by several SED_MATCH_ONE_LABEL
+# (2) SED_EDIT_ONE_SERVER several times
+# (3) SED_ADDING with new servers
+#
+# Notes:
+#
+# * @LABEL@ is a string "resolvconf-<domain>" or "resolvconf" for global
+# section
+# * @RULE@ is @LABEL@ with translated characters '-' and '.' into '_'.
+###
+
+###
+# Main loop with label match - it will redirect the processing to
+# SED_EDIT_ONE_SERVER, when the label match is found. Special match is
+# for "resolvconf" label - the control flow is redirected to SED_ADDING to
+# allow adding new sections.
+#
+# To summarize: Old sections are edited as they appear in the file and new
+# sections are added before the "resolvconf" section.
+SED_LOOP=\
+'/^[[:space:]]*server[[:space:]]*[\{]/ b server;
+p; d;
+:server; h;
+:server_loop; n;
+/^[[:space:]]*server[[:space:]]*[\{]/ { x; p; b server_loop; };
+@MATCH_LABELS@
+/^[[:space:]]*label[[:space:]]*=[[:space:]]*"resolvconf"/ { H; b adding; };
+/^[[:space:]]*[\}]/ { H; x; p; d; };
+H;
+b server_loop;
+'
+
+###
+# Match for one label with a jump to SED_EDIT_ONE_SERVER
+SED_MATCH_ONE_LABEL=\
+'/^[[:space:]]*label[[:space:]]*=[[:space:]]*"@LABEL@"/ { H; x; b main_@RULE@; };
+'
+
+###
+# Editing one server. New lines are put into @SETUP@, lines are composed
+# in function compose_lines(). After the new lines are added, all "preset",
+# "ip" and "include" options are removed (not printed).
+#
+# Sanity checks: Check if there is a second label or another server directive.
+# In both cases, there is some error in the file, so go to the beginning by
+# jumping to SED_LOOP's :server.
+SED_EDIT_ONE_SERVER=\
+':main_@RULE@;
+p; @SETUP@
+:loop_@RULE@;
+n;
+/^[[:space:]]*server[[:space:]]*[\{]/ b server;
+/^[[:space:]]*label[[:space:]]*=/ b server;
+/^[[:space:]]*preset[[:space:]]*=/ b loop_@RULE@;
+/^[[:space:]]*ip[[:space:]]*=/ b loop_@RULE@;
+/^[[:space:]]*include[[:space:]]*=/ b loop_@RULE@;
+/^[[:space:]]*policy[[:space:]]*=/ b loop_@RULE@;
+/^[[:space:]]*exclude[[:space:]]*=/ b exclude_logic_@RULE;
+p;
+/^[[:space:]]*[\}]/ d;
+b loop_@RULE@;
+
+:exclude_logic_@RULE;
+@EXCLUDE_LOGIC@
+b loop_@RULE@;
+'
+
+###
+# Add new servers. All lines composed by function compose_lines() are put into
+# @SETUP@. Then the control flow is returned to one special SED_EDIT_ONE_SERVER
+# section with label "resolvconf".
+SED_ADDING=\
+':adding;
+@SETUP@
+x; b main_resolvconf;
+'
+
+
+###
+# Edit the domain list (include/exclude). All empty fields and matching domains
+# are removed. Unmaintained domains (not in resolvconf-<domain>) are kept. All
+# domains should be in a pipe (|) separated list and should begin, but not end
+# with a dot. The list is put into @DOMAINS@. The control flow continues, where
+# it ended in SED_EDIT_ONE_SERVER.
+#
+SED_DOMAIN_LIST_LOGIC=\
+'h;
+s/^([[:space:]]*@DIRECTIVE@[[:space:]]*=[[:space:]]*).*/\\1/;
+x;
+s/^[[:space:]]*@DIRECTIVE@[[:space:]]*=[[:space:]]*//;
+
+:@DIRECTIVE@_loop_@RULE@;
+/([[:space:]]*("[^"]"*|[^,;]*)[[:space:]]*,)*[[:space:]]*("(@DOMAINS@|)\.?"|(@DOMAINS@)\.?|,)[[:space:]]*[,;]/ {
+ s/(([[:space:]]*("[^"]"*|[^,;]*)[[:space:]]*,)*[[:space:]]*)("(@DOMAINS@|)\.?"|(@DOMAINS@)\.?|,)[[:space:]]*([,;])/\\1\\7/;
+ b @DIRECTIVE@_loop_@RULE@;
+};
+
+s/^[,;]//g;
+/^[[:space:]]*$/ b @DIRECTIVE@_end_@RULE@;
+H; x; s/\\n//; p;
+:@DIRECTIVE@_end_@RULE@;
+'
+
+################################################################################
+# Functions
+
+###
+# char* [] uniqify(char* list[])
+#
+# Uniqify the items in the list
+uniqify() {
+ local result=
+ while [ -n "$1" ] ; do
+ case " ${result} " in
+ *" $1 "*) ;;
+ *) result="${result} $1" ;;
+ esac
+ shift
+ done
+ echo "${result# *}"
+}
+
+###
+# char *make_pdnsd_label(char *domain)
+#
+# Translate domain name into pdnsd's label
+make_pdnsd_label() {
+ local domain=$1
+ if [[ -n ${domain} ]] ; then
+ echo -n "resolvconf-${domain}"
+ else
+ echo -n "resolvconf"
+ fi
+}
+
+###
+# char *make_sed_label(char *pdnsd_label)
+#
+# Translate pdnsd's label into sed's label
+make_sed_label() {
+ local label="$1"
+ label="${label//-/_}"
+ label="${label//./_}"
+ echo -n "${label}"
+}
+
+# char *compose_lines(...)
+#
+# Compose a sed command that prints lines
+compose_lines() {
+ local line result
+ for line in "$@" ; do
+ result="${result}i\\\\\\n${line// /\\t}\\n"
+ done
+ echo "${result}"
+}
+
+###
+# char *build_settings(char *nameservers, char *domains, char *directive)
+#
+# Builds configuration part @SETUP@ of sed script. The directive parameter denotes
+# if the domains are to be included ("include") or excluded ("exclude"). This
+# involves options like
+#
+# (1) # [nameserver list is empty]
+# preset=off;
+#
+# (2) # [domain list is empty]
+# preset=on;
+# ip="address","address"...;
+#
+# (3) # [directive=="include"]
+# preset=on;
+# ip="address","address"...;
+# include=".domain.",".domain."...;
+# policy=excluded;
+#
+# (4) # [directive=="exclude"]
+# preset=on;
+# ip="address","address"...;
+# exclude=".domain.",".domain."...;
+# policy=included;
+#
+# Note: Currently there will always be only one domain in "include" directive.
+#
+build_settings() {
+ local ns="$1" domains="$2" directive="$3"
+ if [[ -n ${ns} ]] ; then
+ local x list_ns list_domains
+ for x in ${ns} ; do
+ list_ns="${list_ns},\"${x}\""
+ done
+ list_ns="${list_ns#,}"
+ if [[ -n ${domains} ]] ; then
+ for x in ${domains} ; do
+ list_domains="${list_domains},\".${x}.\""
+ done
+ list_domains="${list_domains#,}"
+ if [[ $directive == "include" ]]; then
+ compose_lines \
+ " preset=on;" \
+ " ip=${list_ns};" \
+ " include=${list_domains};" \
+ " policy=excluded;"
+ else
+ compose_lines \
+ " preset=on;" \
+ " ip=${list_ns};" \
+ " exclude=${list_domains};" \
+ " policy=included;"
+ fi
+ else
+ compose_lines \
+ " preset=on;" \
+ " ip=${list_ns};"
+ fi
+ else
+ compose_lines \
+ " preset=off;"
+ fi
+}
+
+###
+# char *build_match_labels(char *domains...)
+#
+# Build the label match part of the sed script
+#
+build_match_labels() {
+ local domain result label destination new_match
+ for domain in "$@" ; do
+ label="$(make_pdnsd_label "${domain}")"
+ rule="$(make_sed_label "${label}")"
+ new_match="${SED_MATCH_ONE_LABEL//@LABEL@/${label}}"
+ new_match="${new_match//@RULE@/${rule}}"
+ result="${result}${new_match}"
+ done
+ echo "${result}"
+}
+
+###
+# char *build_domain_list_logic(char *domains, char *directive)
+#
+# Build a logic for changing (removing) domains from a directive.
+#
+build_domain_list_logic() {
+ local domains="$1" directive="$2"
+ local x domain_list logic
+
+ # Domains should be pipe separated list
+ for x in ${domains}; do
+ x=".${x%.}"
+ x="${x//./\.}"
+ domain_list="${domain_list}|${x}"
+ done
+ domain_list="${domain_list#|}"
+
+ if [[ -z ${domain_list} ]]; then
+ logic="p;"
+ else
+ logic="${SED_DOMAIN_LIST_LOGIC//@DOMAINS@/${domain_list}}"
+ logic="${logic//@DIRECTIVE@/${directive}}"
+ fi
+ echo "${logic}"
+}
+
+###
+# char *build_edit_part(char *domain, char *nameservers, \
+# char *add_domains, char *remove_domains,
+# char *directive)
+#
+# Build edit part of the sed script for a particular domain. Domain can be
+# empty in the case it is the "resolvconf" server part.
+#
+build_edit_part() {
+ local domain="$1" nameservers="$2" add_domains="$3" remove_domains="$4"
+ local directive="$5"
+ local setup label rule logic result
+
+ setup="$(build_settings "${nameservers}" "${add_domains}" "${directive}")"
+ label="$(make_pdnsd_label "${domain}")"
+ rule="$(make_sed_label "${label}")"
+ logic="$(build_domain_list_logic "${remove_domains}" "${directive}")"
+ result="${SED_EDIT_ONE_SERVER//@SETUP@/${setup}}"
+ result="${result//@EXCLUDE_LOGIC@/${logic}}"
+ result="${result//@RULE@/${rule}}"
+ echo "${result}"
+}
+
+###
+# char *get_domain_nameservers(char *domain, char *domain_config...)
+#
+# Get the list of nameservers belonging to one particular domain.
+#
+# Domain configuration is a space separated list of pair <domain>,<ip>.
+#
+get_domain_nameservers() {
+ local domain="$1" ns
+ shift
+ for x in "$@" ; do
+ if [[ ${x%,*} == ${domain} ]] ; then
+ ns="${ns} ${x#*,}"
+ fi
+ done
+ ns="$(uniqify ${ns})"
+ echo -n "${ns}"
+}
+
+###
+# char *build_domain_edit_part(char *domain, char *domain_config...)
+#
+# Parse the list of domain configurations and build settings for one particular
+# domain for the sed script.
+#
+# Domain configuration is a space separated list of pair <domain>,<ip>.
+#
+build_domain_edit_part() {
+ local domain="$1" ns
+ shift
+ ns="$(get_domain_nameservers "${domain}" "$@")"
+ build_edit_part "${domain}" "${ns}" "${domain}" "" "include"
+}
+
+###
+# char *build_add_part(char *add, char *domains...)
+#
+# Build add part of the sed script for all domains that needs to be added
+#
+build_add_part() {
+ local add="$1" x label rule add_part new_part result
+ shift
+ for x in ${add} ; do
+ local domain="${x}" ns
+ ns="$(get_domain_nameservers "${domain}" "$@")"
+ label="$(make_pdnsd_label "${domain}")"
+ rule="$(make_sed_label ${label})"
+ new_part="$(compose_lines "server {" " label=\"${label}\";")"
+ new_part="${new_part}$(build_settings "${ns}" "${domain}" "include")"
+ new_part="${new_part}$(compose_lines "}" "")"
+ add_part="${add_part}${new_part}"
+ done
+ result="${SED_ADDING//@SETUP@/${add_part}}"
+ echo "${result}"
+}
+
+###
+# char *build_sed_script(char *nameservers, char *domain_config,
+# char *change, char *add,
+# char *active_domains, char *known_domains)
+#
+# Build the full sed script from the list of nameservers, list of domains
+# (in format <domain>,<ip>), list of changed domains, list of added domains,
+# list of activly used domains and a list of all known domains.
+#
+build_sed_script() {
+ local ns="$1" domain_config="$2" change="$3" add="$4"
+ local active_domains="$5" known_domains="$6"
+
+ local match_labels="$(build_match_labels ${change})"
+
+ local edit_changed x
+ for x in ${change} ; do
+ edit_changed="${edit_changed}$( \
+ build_domain_edit_part "${x}" ${domain_config})"
+ done
+ edit_changed="${edit_changed}$( \
+ build_edit_part "" "${ns}" "${active_domains}" "${known_domains}" "exclude")"
+
+ local added
+ added="$(build_add_part "${add}" ${domain_config})"
+
+ local full
+ full="${SED_LOOP//@MATCH_LABELS@/${match_labels}}"
+ echo -ne "${full}"
+ echo -ne "${edit_changed}"
+ echo -ne "${added}"
+}
+
+###
+# char *read_configured_domains(char *config_file)
+#
+# Reads labels of servers starting with resolvconf* from the configuration file.
+#
+read_configured_domains() {
+ local config_file="$1" result
+ result="\
+ $(sed -nre 's/^[[:space:]]+label=\"?resolvconf-([^;\"]*)\";.*/\1/p' \
+ ${config_file})"
+ echo -n "${result}"
+}
+
+###
+# void installation_check(char *config_file)
+#
+# Check if the pdnsd is installed and can be configured. Prepare also the file
+# for resolvconf.
+#
+installation_check() {
+ local config_file="$1"
+ if [[ -e ${config_file} ]] ; then
+ if ! grep ${INSTALLATION_CHECK} ${config_file} &>/dev/null ; then
+ echo -e "${COMMENT}" >> ${config_file}
+ echo -e "\n${BASIC_SETTINGS}" >> ${config_file}
+ fi
+ return 0
+ else
+ return 1
+ fi
+}
+
+###
+# void initialization(char *config_file)
+#
+# Setup basic variables NAMESERVERS, DOMAINS an CONFIGURED_DOMAINS
+#
+initialization() {
+ local config_file="$1"
+
+ for N in ${NEWNS} ; do
+ NAMESERVERS="${NAMESERVERS} ${N}"
+ done
+
+ for N in ${NEWSEARCH} ; do
+ NAMESERVERS="${NAMESERVERS} ${N#*,}"
+ done
+
+ for DN in ${NEWDOMAIN} ; do
+ DOMAINS="${DOMAINS} ${DN%,*}"
+ done
+
+ CONFIGURED_DOMAINS=$(read_configured_domains ${config_file})
+
+ NAMESERVERS=$(uniqify ${NAMESERVERS})
+ DOMAINS=$(uniqify ${DOMAINS})
+ CONFIGURED_DOMAINS=$(uniqify ${CONFIGURED_DOMAINS})
+}
+
+###
+# void find_changed_and_added(char *configured, char *domains)
+#
+# Find already configured and newly added domains. Sets variables
+# CHANGE_DOMAINS, ADD_DOMAINS and KNOWN_DOMAINS.
+#
+find_changed_and_added() {
+ local configured="$1" domains="$2" x
+
+ KNOWN_DOMAINS="${CONFIGURED_DOMAINS} ${DOMAINS}"
+
+ # Find what has to be disabled
+ for x in ${configured} ; do
+ if [[ " ${domains} " != *" ${x} "* ]] ; then
+ CHANGE_DOMAINS="${CHANGE_DOMAINS} ${x}"
+ fi
+ done
+
+ # Find what has to be added
+ for x in ${domains} ; do
+ if [[ " ${configured} " != *" ${x} "* ]] ; then
+ ADD_DOMAINS="${ADD_DOMAINS} ${x}"
+ else
+ CHANGE_DOMAINS="${CHANGE_DOMAINS} ${x}"
+ fi
+ done
+
+ ADD_DOMAINS=$(uniqify ${ADD_DOMAINS})
+ CHANGE_DOMAINS=$(uniqify ${CHANGE_DOMAINS})
+ KNOWN_DOMAINS=$(uniqify ${KNOWN_DOMAINS})
+}
+
+###
+# bool make_configuration_change(char *config_file, char *backup_suffix,
+# char *sed_script)
+#
+# Applies any configuration change. Returns true, if there was a change.
+#
+make_configuration_change() {
+ local config_file="$1" backup_suffix="$2" sed_script="$3"
+ local old_config new_config
+
+ old_config=$(< ${config_file})
+
+ # Sanity check: add '}' at the end of the file
+ new_config=$( (echo -n "${old_config}" && echo -ne "\n}" ) | \
+ sed -nre "${sed_script}")
+ # Now remove what we added
+ new_config=${new_config%?\}}
+
+ if [[ "${old_config}" != "${new_config}" ]] ; then
+ cp ${config_file} ${config_file}${backup_suffix}
+ echo "${new_config}" > "${config_file}"
+ return 0
+ else
+ return 1
+ fi
+}
+
+################################################################################
+# Main part
+
+# Check, if pdnsd configuration file is installed and possibly prepare it
+installation_check "${PDNSDCONFIG}" || exit 0
+
+# Basic initialization of NAMESERVERS, DOMAINS and CONFIGURED_DOMAINS
+initialization "${PDNSDCONFIG}"
+
+find_changed_and_added "${CONFIGURED_DOMAINS}" "${DOMAINS}"
+
+sed_script="$(build_sed_script "${NAMESERVERS}" "${NEWDOMAIN}" \
+ "${CHANGE_DOMAINS}" "${ADD_DOMAINS}" \
+ "${DOMAINS}" "${KNOWN_DOMAINS}")"
+
+# Check if the config changed
+if make_configuration_change "${PDNSDCONFIG}" "${BACKUPSUFFIX}" "${sed_script}" ; then
+ # Checks for running pdnsd
+ [ -x /usr/sbin/pdnsd-ctl ] || exit 0
+ [ -e /var/cache/pdnsd/pdnsd.status ] || exit 0
+
+ # Reload config files
+ /usr/sbin/pdnsd-ctl config &>/dev/null
+fi
+
+exit 0
diff --git a/net-dns/pdnsd/files/pdnsd.service b/net-dns/pdnsd/files/pdnsd.service
new file mode 100644
index 000000000000..d1812a53b384
--- /dev/null
+++ b/net-dns/pdnsd/files/pdnsd.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=pdnsd private name-server cache daemon
+After=syslog.target network.target auditd.service
+ConditionPathExists=/etc/pdnsd/pdnsd.conf
+
+[Service]
+ExecStart=/usr/sbin/pdnsd -s -t
+ExecReload=/usr/sbin/pdnsd-ctl config
+
+[Install]
+WantedBy=multi-user.target
diff --git a/net-dns/pdnsd/files/pdnsd.tmpfiles b/net-dns/pdnsd/files/pdnsd.tmpfiles
new file mode 100644
index 000000000000..dc538151fe32
--- /dev/null
+++ b/net-dns/pdnsd/files/pdnsd.tmpfiles
@@ -0,0 +1 @@
+d /var/cache/pdnsd 750 pdnsd pdnsd -
diff --git a/net-dns/pdnsd/metadata.xml b/net-dns/pdnsd/metadata.xml
new file mode 100644
index 000000000000..1198baddd17c
--- /dev/null
+++ b/net-dns/pdnsd/metadata.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="person">
+ <email>polynomial-c@gentoo.org</email>
+ <name>Lars Wendler</name>
+ </maintainer>
+ <longdescription>
+ 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 (for example in dial-in
+ networking).
+ </longdescription>
+ <use>
+ <flag name="isdn">
+ Linux-only: check status of ippp interfaces with ISDN-specific
+ system calls.
+ </flag>
+ <flag name="urandom">
+ Linux-only: use /dev/urandom (pseudo-random number generation)
+ instead of the default use of random() PRNG.
+ </flag>
+ </use>
+</pkgmetadata>
diff --git a/net-dns/pdnsd/pdnsd-1.2.9a-r1.ebuild b/net-dns/pdnsd/pdnsd-1.2.9a-r1.ebuild
new file mode 100644
index 000000000000..67ce6e471960
--- /dev/null
+++ b/net-dns/pdnsd/pdnsd-1.2.9a-r1.ebuild
@@ -0,0 +1,131 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit systemd user
+
+DESCRIPTION="Proxy DNS server with permanent caching"
+HOMEPAGE="http://members.home.nl/p.a.rombouts/pdnsd/"
+SRC_URI="http://members.home.nl/p.a.rombouts/pdnsd/releases/${P}-par.tar.gz"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="alpha amd64 arm ia64 ppc ~s390 sparc x86"
+IUSE="debug ipv6 isdn +urandom test"
+
+RDEPEND=""
+DEPEND="test? ( net-dns/bind-tools )"
+
+pkg_setup() {
+ enewgroup pdnsd
+ enewuser pdnsd -1 -1 /var/lib/pdnsd pdnsd
+}
+
+src_configure() {
+ local myconf=""
+ use debug && myconf="${myconf} --with-debug=3"
+ use urandom && myconf="${myconf} --with-random-device=/dev/urandom"
+
+ econf \
+ --disable-dependency-tracking \
+ --sysconfdir=/etc/pdnsd \
+ --with-cachedir=/var/cache/pdnsd \
+ --with-default-id=pdnsd \
+ $(use_enable ipv6) $(use_enable ipv6 ipv6-startup) \
+ $(use_enable isdn) \
+ ${myconf}
+}
+
+src_install() {
+ emake DESTDIR="${D}" install
+
+ dodoc AUTHORS ChangeLog* NEWS README THANKS TODO README.par
+ docinto contrib ; dodoc contrib/{README,dhcp2pdnsd,pdnsd_dhcp.pl}
+ docinto html ; dohtml doc/html/*
+ docinto txt ; dodoc doc/txt/*
+ newdoc doc/pdnsd.conf pdnsd.conf.sample
+
+ newinitd "${FILESDIR}/pdnsd.rc8" pdnsd
+ newinitd "${FILESDIR}/pdnsd.online.2" pdnsd-online
+ systemd_newtmpfilesd "${FILESDIR}/pdnsd.tmpfiles" pdnsd.conf
+ systemd_dounit "${FILESDIR}/pdnsd.service"
+
+ mkdir "${T}"/confd || die
+
+ cat - > "${T}"/confd/pdnsd-online <<EOF
+# Make sure to change the rc_need variable to the service for the
+# interface that connects you to the dns servers.
+#
+# For instance if you use a PPP connection on ppp0 to connect, set
+# rc_need="net.ppp0"
+
+rc_need="net.lo"
+EOF
+
+ # Don't try to do the smart thing and add the --help output here:
+ # it will cause the file to be etc-updated if the help text
+ # changes and fails when cross-compiling.
+ cat - > "${T}"/confd/pdnsd <<EOF
+# Command line options, check pdnsd --help for a list of valid
+# parameters. Note that most of the options that can be given at
+# command-line are also available as configuration parameters in
+# /etc/pdnsd/pdnsd.conf
+PDNSDCONFIG=""
+EOF
+
+ doconfd "${T}"/confd/*
+
+ # gentoo resolvconf support
+ exeinto /etc/resolvconf/update.d
+ newexe "${FILESDIR}/pdnsd.resolvconf-r1" pdnsd
+}
+
+src_test() {
+ fail_kill() {
+ kill -9 $(<"${T}"/pid)
+ die "$1"
+ }
+
+ mkdir "${T}/pdnsd" || die
+ echo -n -e "pd12\0\0\0\0" > "${T}/pdnsd/pdnsd.cache"
+ IPS=$(grep ^nameserver /etc/resolv.conf | sed -e 's/nameserver \(.*\)/\tip=\1;/g' | xargs)
+ sed -e "s/\tip=/${IPS}/" -e "s:cache_dir=:cache_dir=${T}/pdnsd:" "${FILESDIR}/pdnsd.conf.test" \
+ > "${T}/pdnsd.conf.test"
+ src/pdnsd -c "${T}/pdnsd.conf.test" -g -s -d -p "${T}/pid" || die "couldn't start daemon"
+ sleep 3
+
+ find "${T}" -ls
+ [ -s "${T}/pid" ] || die "empty or no pid file created"
+ [ -S "${T}/pdnsd/pdnsd.status" ] || fail_kill "no socket created"
+ src/pdnsd-ctl/pdnsd-ctl -c "${T}/pdnsd" server all up || fail_kill "failed to start the daemon"
+ src/pdnsd-ctl/pdnsd-ctl -c "${T}/pdnsd" status || fail_kill "failed to communicate with the daemon"
+ sleep 3
+
+ dig @127.0.0.1 -p 33455 localhost > "${T}"/dig.output 2>&1
+ cat "${T}"/dig.output || die
+ fgrep -q "status: NOERROR" "${T}"/dig.output || fail_kill "www.gentoo.org lookup failed"
+
+ kill $(<"${T}/pid") || fail_kill "failed to terminate daemon"
+}
+
+pkg_postinst() {
+ elog
+ elog "Add pdnsd to your default runlevel - rc-update add pdnsd default"
+ elog ""
+ elog "Add pdnsd-online to your online runlevel."
+ elog "The online interface will be listed in /etc/conf.d/pdnsd-online"
+ elog ""
+ elog "Sample config file in /etc/pdnsd/pdnsd.conf.sample"
+
+ # The tmpfiles.d configuration does not come into effect before the
+ # next reboot so create the cachedir now.
+ local cachedir="/var/cache/pdnsd"
+ if [[ ! -d ${cachedir} ]] ; then
+ mkdir ${cachedir} || eerror "Failed to create cache"
+ fi
+ chown pdnsd:pdnsd ${cachedir} \
+ || eerror "Failed to set ownership for cachedir"
+ chmod 0750 ${cachedir} \
+ || eerror "Failed to set permissions for cachedir"
+}