diff options
author | Alin Năstac <mrness@gentoo.org> | 2006-06-11 11:24:58 +0000 |
---|---|---|
committer | Alin Năstac <mrness@gentoo.org> | 2006-06-11 11:24:58 +0000 |
commit | 7bd5fbddaef9fe44368400e4d1f6be269e0bd35b (patch) | |
tree | 2d5b644613c7c883965126e841d729c3616fc520 /net-dns/pdnsd | |
parent | Add freebsd-lib as option for libedit. (diff) | |
download | historical-7bd5fbddaef9fe44368400e4d1f6be269e0bd35b.tar.gz historical-7bd5fbddaef9fe44368400e4d1f6be269e0bd35b.tar.bz2 historical-7bd5fbddaef9fe44368400e4d1f6be269e0bd35b.zip |
Add support for resolvconf-gentoo (#134254).
Package-Manager: portage-2.1
Diffstat (limited to 'net-dns/pdnsd')
-rw-r--r-- | net-dns/pdnsd/ChangeLog | 9 | ||||
-rw-r--r-- | net-dns/pdnsd/files/digest-pdnsd-1.2.4-r2 | 3 | ||||
-rw-r--r-- | net-dns/pdnsd/files/pdnsd.resolvconf | 499 | ||||
-rw-r--r-- | net-dns/pdnsd/pdnsd-1.2.4-r2.ebuild | 126 |
4 files changed, 636 insertions, 1 deletions
diff --git a/net-dns/pdnsd/ChangeLog b/net-dns/pdnsd/ChangeLog index 5bd51bf65e8d..f3f387bb5760 100644 --- a/net-dns/pdnsd/ChangeLog +++ b/net-dns/pdnsd/ChangeLog @@ -1,6 +1,13 @@ # ChangeLog for net-dns/pdnsd # Copyright 2002-2006 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/net-dns/pdnsd/ChangeLog,v 1.59 2006/04/29 09:01:12 dertobi123 Exp $ +# $Header: /var/cvsroot/gentoo-x86/net-dns/pdnsd/ChangeLog,v 1.60 2006/06/11 11:24:58 mrness Exp $ + +*pdnsd-1.2.4-r2 (11 Jun 2006) + + 11 Jun 2006; Alin Nastac <mrness@gentoo.org> +files/pdnsd.resolvconf, + -pdnsd-1.2.3.ebuild, +pdnsd-1.2.4-r2.ebuild: + Add support for resolvconf-gentoo, thanks to Oldrich Jedlicka + <oldium.pro@seznam.cz> (#134254). 29 Apr 2006; Tobias Scherbaum <dertobi123@gentoo.org> pdnsd-1.2.4-r1.ebuild: diff --git a/net-dns/pdnsd/files/digest-pdnsd-1.2.4-r2 b/net-dns/pdnsd/files/digest-pdnsd-1.2.4-r2 new file mode 100644 index 000000000000..a46253777836 --- /dev/null +++ b/net-dns/pdnsd/files/digest-pdnsd-1.2.4-r2 @@ -0,0 +1,3 @@ +MD5 aafb9d65d713b4bc2c6c4ba822e0bd3c pdnsd-1.2.4-par.tar.gz 537362 +RMD160 19cbb5d03eacdd8153ac3b9675cdbe07b1edfbd4 pdnsd-1.2.4-par.tar.gz 537362 +SHA256 b9172094feee0ebe6b2aec3c1358419cc928469e16c96718d7d0fc639fc17e55 pdnsd-1.2.4-par.tar.gz 537362 diff --git a/net-dns/pdnsd/files/pdnsd.resolvconf b/net-dns/pdnsd/files/pdnsd.resolvconf new file mode 100644 index 000000000000..6c88656ba9d5 --- /dev/null +++ b/net-dns/pdnsd/files/pdnsd.resolvconf @@ -0,0 +1,499 @@ +#!/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 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" ) + +# Load generic Gentoo functions +source /etc/init.d/functions.sh + +# 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"; +# policy=excluded; +#' +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@; +p; +/^[[:space:]]*[\}]/ d; +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; +' + +################################################################################ +# Functions + +### +# 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 *domain) +# +# Builds configuration part @SETUP@ of sed script. This involves options like +# +# (1) preset=off; +# +# (2) preset=on; +# ip="address","address"...; +# +# (3) preset=on; +# ip="address","address"...; +# include=".domain.",".domain."...; +# +# Note: Currently the will always be only one domain in "include" option. +# +build_settings() { + local ns="$1" domain="$2" + if [[ -n ${ns} ]] ; then + local x list_ns list_domain + for x in ${ns} ; do + list_ns="${list_ns},\"${x}\"" + done + if [[ -n ${domain} ]] ; then + for x in ${domain} ; do + list_domain="${list_domain},\".${x}.\"" + done + compose_lines \ + " preset=on;" \ + " ip=${list_ns#,};" \ + " include=${list_domain#,};" \ + " policy=excluded;" + 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_one_domain(char *domain, char *domains...) +# +# Parse the list of domains and build settings for one particular domain for +# the sed script. +# +build_one_domain() { + local domain="$1" ip_list + shift + for x in "$@" ; do + if [[ ${x} == *","* ]] ; then + if [[ ${x%,*} == ${domain} ]] ; then + ip_list="${ip_list} ${x#*,}" + fi + else + ip_list="${ip_list} ${x}" + fi + done + ip_list="$(uniqify ${ip_list})" + build_settings "${ip_list}" "${domain}" +} + +### +# char *build_edit_part(char *domain, char *domains...) +# +# Build edit part of the sed script for one particular domain. +# +build_edit_part() { + local domain="$1" x setup result label rule + shift + setup="$(build_one_domain "${domain}" "$@")" + label="$(make_pdnsd_label "${domain}")" + rule="$(make_sed_label "${label}")" + result="${SED_EDIT_ONE_SERVER//@SETUP@/${setup}}" + result="${result//@RULE@/${rule}}" + echo -n "${result}" +} + + +### +# 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 + label="$(make_pdnsd_label "${x}")" + rule="$(make_sed_label ${label})" + new_part="$(compose_lines "server {" " label=\"${label}\";")" + new_part="${new_part}$(build_one_domain "${x}" "$@")" + new_part="${new_part}$(compose_lines "}" "")" + add_part="${add_part}${new_part}" + done + result="${SED_ADDING//@SETUP@/${add_part}}" + echo -n "${result}" +} + +### +# char *build_sed_script(char *nameservers, char *domains, +# char *change, char *add) +# +# Build the full sed script. +# +build_sed_script() { + local ns="$1" domains="$2" change="$3" add="$4" + + local match_labels="$(build_match_labels ${change})" + + local edit_changed x + for x in ${change} ; do + edit_changed="${edit_changed}$(build_edit_part ${x} ${domains})" + done + edit_changed="${edit_changed}$(build_edit_part '' ${ns})" + + local added + added="$(build_add_part "${add}" ${domains})" + + 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 and ADD_DOMAINS +# +find_changed_and_added() { + local configured="$1" domains="$2" x + # 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}) +} + +### +# 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}")" + +# 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/pdnsd-1.2.4-r2.ebuild b/net-dns/pdnsd/pdnsd-1.2.4-r2.ebuild new file mode 100644 index 000000000000..b8fdb35dc644 --- /dev/null +++ b/net-dns/pdnsd/pdnsd-1.2.4-r2.ebuild @@ -0,0 +1,126 @@ +# Copyright 1999-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/net-dns/pdnsd/pdnsd-1.2.4-r2.ebuild,v 1.1 2006/06/11 11:24:58 mrness Exp $ + +inherit eutils + +DESCRIPTION="Proxy DNS server with permanent caching" +HOMEPAGE="http://www.phys.uu.nl/%7Erombouts/pdnsd.html http://www.phys.uu.nl/~rombouts/pdnsd.html" +SRC_URI="http://www.phys.uu.nl/%7Erombouts/pdnsd/releases/${P}-par.tar.gz" + +LICENSE="|| ( BSD GPL-2 )" +SLOT="0" +KEYWORDS="~alpha ~amd64 ~arm ~ppc ~s390 ~sparc ~x86" +IUSE="ipv6 debug isdn nptl" + +pkg_setup() { + enewgroup pdnsd + enewuser pdnsd -1 -1 /var/lib/pdnsd pdnsd +} + +src_unpack() { + unpack ${A} + + epatch "${FILESDIR}/${P}-dbg_file.patch" +} + +src_compile() { + local myconf="" + + if use debug; then + myconf="${myconf} --with-debug=3" + CFLAGS="${CFLAGS} -g" + fi + use nptl && myconf="${myconf} --with-thread-lib=NPTL" + + [ -c /dev/urandom ] && myconf="${myconf} --with-random-device=/dev/urandom" + + econf \ + --sysconfdir=/etc/pdnsd \ + --with-cachedir=/var/cache/pdnsd \ + --infodir=/usr/share/info --mandir=/usr/share/man \ + --with-default-id=pdnsd \ + `use_enable ipv6` `use_enable isdn` \ + ${myconf} \ + || die "bad configure" + + emake all || die "compile problem" +} + +pkg_preinst() { + # Duplicated so that binary packages work + enewgroup pdnsd + enewuser pdnsd -1 -1 /var/lib/pdnsd pdnsd +} + +src_test() { + if [ -x /usr/bin/dig ]; then + mkdir "${T}/pdnsd" + echo -n -e "pd12\0\0\0\0" > "${T}/pdnsd/pdnsd.cache" + IPS=$(grep ^nameserver "${ROOT}/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" ] || die "no socket created" + src/pdnsd-ctl/pdnsd-ctl -c "${T}/pdnsd" server all up || die "failed to start the daemon" + src/pdnsd-ctl/pdnsd-ctl -c "${T}/pdnsd" status || die "failed to communicate with the daemon" + sleep 3 + + dig @127.0.0.1 -p 33455 www.gentoo.org | fgrep "status: NOERROR" || die "www.gentoo.org lookup failed" + kill $(<"${T}/pid") || die "failed to terminate daemon" + fi +} + +src_install() { + emake DESTDIR="${D}" install || die + + # Copy cache from prev older versions + [ -f "${ROOT}/var/lib/pdnsd/pdnsd.cache" ] && \ + cp "${ROOT}/var/lib/pdnsd/pdnsd.cache" "${D}/var/cache/pdnsd/pdnsd.cache" + + # Don't clobber existing cache - copy prev cache so unmerging prev version + # doesn't remove the cache. + [ -f "${ROOT}/var/cache/pdnsd/pdnsd.cache" ] && \ + rm "${D}/var/cache/pdnsd/pdnsd.cache" + + 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.rc6" pdnsd + newinitd "${FILESDIR}/pdnsd.online" pdnsd-online + + keepdir /etc/conf.d + local config="${D}/etc/conf.d/pdnsd-online" + + echo -e "# Enter the interface that connects you to the dns servers" >> "${config}" + echo "# This will correspond to /etc/init.d/net.${IFACE}" >> "${config}" + echo -e "\n# IMPORTANT: Be sure to run depscan.sh after modifiying IFACE" >> "${config}" + echo "IFACE=ppp0" >> "${config}" + + config="${D}/etc/conf.d/pdnsd" + "${D}/usr/sbin/pdnsd" --help | sed "s/^/# /g" > "${config}" + echo "# Command line options" >> "${config}" + use ipv6 && echo PDNSDCONFIG="-a" >> "${config}" \ + || echo PDNSDCONFIG="" >> "${config}" + + #resolvconf-gentoo support + exeinto /etc/resolvconf/update.d + newexe "${FILESDIR}/pdnsd.resolvconf" pdnsd +} + +pkg_postinst() { + einfo + einfo "Add pdnsd to your default runlevel - rc-update add pdnsd default" + einfo "" + einfo "Add pdnsd-online to your online runlevel." + einfo "The online interface will be listed in /etc/conf.d/pdnsd-online" + einfo "" + einfo "Sample config file in /etc/pdnsd/pdnsd.conf.sample" +} |