Accepting request 127639 from home:vuntz:branches:GNOME:Factory
bnc#710231 & bnc#729796; would like to get this in 12.2 OBS-URL: https://build.opensuse.org/request/show/127639 OBS-URL: https://build.opensuse.org/package/show/GNOME:Factory/nss-mdns?expand=0&rev=8
This commit is contained in:
parent
45020ab90f
commit
4392fd0259
233
nss-mdns-config
Normal file
233
nss-mdns-config
Normal file
@ -0,0 +1,233 @@
|
||||
#!/bin/sh
|
||||
# vim: set ts=2 sw=2 et:
|
||||
|
||||
#
|
||||
# Copyright (c) 2012, Novell, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of the <ORGANIZATION> nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
#
|
||||
# (Licensed under the simplified BSD license)
|
||||
#
|
||||
# Authors: Vincent Untz <vuntz@opensuse.org>
|
||||
#
|
||||
|
||||
NSSWITCH=/etc/nsswitch.conf
|
||||
|
||||
function usage() {
|
||||
echo "nss-mdns-config [--enable|--disable] [-4|-6] [--no-backup]"
|
||||
}
|
||||
|
||||
ENABLE=0
|
||||
DISABLE=0
|
||||
IPv4=0
|
||||
IPv6=0
|
||||
IPvALL=0
|
||||
BACKUP=1
|
||||
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
--enable) ENABLE=1; shift;;
|
||||
--disable) DISABLE=1; shift;;
|
||||
-4) IPv4=1; shift;;
|
||||
-6) IPv6=1; shift;;
|
||||
--no-backup) BACKUP=0; shift;;
|
||||
*) usage; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if test "$ENABLE" -eq 1 -a "$DISABLE" -eq 1; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test "$IPv4" -eq 1 -a "$IPv6" -eq 1; then
|
||||
# Supporting -4 and -6 at the same time would make --enable more complex,
|
||||
# since we'd like it to add both mdns4_minimal and mdns6_minimal. So just
|
||||
# don't do it for now.
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test "$IPv4" -ne 1 -a "$IPv6" -ne 1; then
|
||||
IPv4=1
|
||||
IPv6=1
|
||||
IPvALL=1
|
||||
fi
|
||||
|
||||
if test ! -f "$NSSWITCH"; then
|
||||
if test "$ENABLE" -ne 1 -a "$DISABLE" -ne 1; then
|
||||
echo "No $NSSWITCH file."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
HOSTS=$(grep -m1 "^\s*hosts:" "$NSSWITCH")
|
||||
|
||||
if test $? -ne 0; then
|
||||
echo "No hosts configuration in $NSSWITCH."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
VALUE=$(echo $HOSTS | sed "s/^\s*hosts:\s*//g")
|
||||
|
||||
if test "$ENABLE" -ne 1 -a "$DISABLE" -ne 1; then
|
||||
|
||||
IPv4_ENABLED=0
|
||||
IPv6_ENABLED=0
|
||||
ENABLED=0
|
||||
|
||||
for ITEM in $VALUE; do
|
||||
if test "$ITEM" == "mdns4_minimal" -o "$ITEM" == "mdns4"; then
|
||||
IPv4_ENABLED=1
|
||||
elif test "$ITEM" == "mdns6_minimal" -o "$ITEM" == "mdns6"; then
|
||||
IPv6_ENABLED=1
|
||||
elif test "$ITEM" == "mdns_minimal" -o "$ITEM" == "mdns"; then
|
||||
ENABLED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if test "$ENABLED" -eq 1; then
|
||||
echo "Full support for nss-mdns is enabled."
|
||||
elif test "$IPv4_ENABLED" -eq 1 -a "$IPv6_ENABLED" -eq 1; then
|
||||
echo "Support for nss-mdns is enabled for IPv4 and IPv6."
|
||||
elif test "$IPv4_ENABLED" -eq 1; then
|
||||
echo "Support for nss-mdns is enabled for IPv4."
|
||||
elif test "$IPv6_ENABLED" -eq 1; then
|
||||
echo "Support for nss-mdns is enabled for IPv6."
|
||||
else
|
||||
echo "Support for nss-mdns is disabled."
|
||||
fi
|
||||
|
||||
elif test "$DISABLE" -eq 1; then
|
||||
|
||||
NEWVALUE=""
|
||||
DROPACTION=0
|
||||
|
||||
for ITEM in $VALUE; do
|
||||
if test \( "$ITEM" == "mdns4_minimal" -o "$ITEM" == "mdns4" \) -a "$IPv4" -eq 1; then
|
||||
DROPACTION=1
|
||||
elif test \( "$ITEM" == "mdns6_minimal" -o "$ITEM" == "mdns6" \) -a "$IPv6" -eq 1; then
|
||||
DROPACTION=1
|
||||
elif test "$ITEM" == "mdns_minimal" -o "$ITEM" == "mdns"; then
|
||||
if test "$IPvALL" -eq 1; then
|
||||
DROPACTION=1
|
||||
elif test "$IPv4" -eq 1; then
|
||||
NEWVALUE="$NEWVALUE `echo $ITEM | sed 's:mdns:mdns6:'`"
|
||||
DROPACTION=0
|
||||
elif test "$IPv6" -eq 1; then
|
||||
NEWVALUE="$NEWVALUE `echo $ITEM | sed 's:mdns:mdns4:'`"
|
||||
DROPACTION=0
|
||||
else
|
||||
echo "Internal error when disabling $ITEM."
|
||||
exit 1
|
||||
fi
|
||||
elif test "${ITEM::1}" == "[" -a "$DROPACTION" -eq 1; then
|
||||
DROPACTION=0
|
||||
else
|
||||
NEWVALUE="$NEWVALUE $ITEM"
|
||||
DROPACTION=0
|
||||
fi
|
||||
done
|
||||
|
||||
NEWVALUE=$(echo $NEWVALUE | sed "s/^\s*//;s/^\s*$//")
|
||||
|
||||
if test "$BACKUP" -eq 1; then
|
||||
cp -a "$NSSWITCH" "${NSSWITCH}bak"
|
||||
fi
|
||||
sed -i "s/\(^\s*hosts:\s*\).*/\1$NEWVALUE/" "$NSSWITCH"
|
||||
|
||||
elif test "$ENABLE" -eq 1; then
|
||||
|
||||
NEWVALUE=""
|
||||
FOUND=0
|
||||
FOUND_DNS=0
|
||||
DROPACTION=0
|
||||
|
||||
for ITEM in $VALUE; do
|
||||
if test \( "$ITEM" == "mdns_minimal" -o "$ITEM" == "mdns4_minimal" -o "$ITEM" == "mdns6_minimal" \); then
|
||||
if test "$FOUND_DNS" -eq 1; then
|
||||
# don't keep *_minimal after dns; it's not desired there
|
||||
DROPACTION=1
|
||||
else
|
||||
if test "$IPvALL" -eq 1 -a \( "$ITEM" == "mdns4_minimal" -o "$ITEM" == "mdns6_minimal" \); then
|
||||
# no need to keep mdns[46]_minimal since we'll add mdns_minimal
|
||||
DROPACTION=1
|
||||
else
|
||||
if test "$ITEM" == "mdns_minimal"; then
|
||||
FOUND=1
|
||||
elif test "$ITEM" == "mdns4_minimal" -a "$IPv4" -eq 1; then
|
||||
FOUND=1
|
||||
elif test "$ITEM" == "mdns6_minimal" -a "$IPv6" -eq 1; then
|
||||
FOUND=1
|
||||
fi
|
||||
# force the use of [NOTFOUND=return] after *_minimal
|
||||
NEWVALUE="$NEWVALUE $ITEM [NOTFOUND=return]"
|
||||
DROPACTION=1
|
||||
fi
|
||||
fi
|
||||
elif test \( "$ITEM" == "mdns" -o "$ITEM" == "mdns4" -o "$ITEM" == "mdns6" \); then
|
||||
# we simply don't use the non-minimal version in our setup, so drop it
|
||||
DROPACTION=1
|
||||
elif test "$ITEM" == "dns"; then
|
||||
FOUND_DNS=1
|
||||
DROPACTION=0
|
||||
if test "$FOUND" -ne 1; then
|
||||
FOUND=1
|
||||
if test "$IPvALL" -eq 1; then
|
||||
NEWVALUE="$NEWVALUE mdns_minimal [NOTFOUND=return] $ITEM"
|
||||
elif test "$IPv4" -eq 1; then
|
||||
NEWVALUE="$NEWVALUE mdns4_minimal [NOTFOUND=return] $ITEM"
|
||||
elif test "$IPv6" -eq 1; then
|
||||
NEWVALUE="$NEWVALUE mdns6_minimal [NOTFOUND=return] $ITEM"
|
||||
else
|
||||
echo "Internal error when enabling."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
NEWVALUE="$NEWVALUE $ITEM"
|
||||
fi
|
||||
elif test "${ITEM::1}" == "[" -a "$DROPACTION" -eq 1; then
|
||||
DROPACTION=0
|
||||
else
|
||||
NEWVALUE="$NEWVALUE $ITEM"
|
||||
DROPACTION=0
|
||||
fi
|
||||
done
|
||||
|
||||
if test "$FOUND_DNS" -ne 1; then
|
||||
echo "No dns service for hosts configuration in $NSSWITCH."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
NEWVALUE=$(echo $NEWVALUE | sed "s/^\s*//;s/^\s*$//")
|
||||
|
||||
if test "$BACKUP" -eq 1; then
|
||||
cp -a "$NSSWITCH" "${NSSWITCH}bak"
|
||||
fi
|
||||
sed -i "s/\(^\s*hosts:\s*\).*/\1$NEWVALUE/" "$NSSWITCH"
|
||||
|
||||
fi
|
@ -1,3 +1,21 @@
|
||||
-------------------------------------------------------------------
|
||||
Wed Jul 11 13:37:10 CEST 2012 - vuntz@opensuse.org
|
||||
|
||||
- Add nss-mdns-config script as a source, and install it in
|
||||
/usr/sbin: this script can be used to enable/disable mdns in
|
||||
/etc/nsswitch.conf (-4/-6 can be used to restrict
|
||||
enabling/disabling to IPv4/IPv6).
|
||||
- Change %post/%preun scriptlets to use new nss-mdns-config script
|
||||
instead of custom perl-fu.
|
||||
- Do not restrict mdns support in /etc/nsswitch.conf to IPv4: just
|
||||
pass --enable to nss-mdns-config in %post. Fix bnc#710231.
|
||||
- Only call nss-mdns-config in %post on first install, to avoid
|
||||
overwriting changes done by users. Fix nss-mdns side of
|
||||
bnc#729796.
|
||||
- Do not call sed to change /etc/nsswitch.conf to remove services
|
||||
not provided by nss-mdns anymore: when we need this, we'll be
|
||||
able to integrate this in nss-mdns-config.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Dec 15 22:28:46 CET 2009 - jengelh@medozas.de
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package nss-mdns (Version 0.10)
|
||||
# spec file for package nss-mdns
|
||||
#
|
||||
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
@ -15,21 +15,21 @@
|
||||
# Please submit bugfixes or comments via http://bugs.opensuse.org/
|
||||
#
|
||||
|
||||
# norootforbuild
|
||||
|
||||
|
||||
Name: nss-mdns
|
||||
# lynx is not needed, text version of README is already present
|
||||
#BuildRequires: lynx
|
||||
Version: 0.10
|
||||
Release: 41
|
||||
Group: Productivity/Networking/DNS/Utilities
|
||||
License: LGPL-2.1+
|
||||
Release: 0
|
||||
Url: http://0pointer.de/lennart/projects/nss-mdns/
|
||||
Summary: Host Name Resolution Via Multicast DNS (Zeroconf) for glibc
|
||||
License: LGPL-2.1+
|
||||
Group: Productivity/Networking/DNS/Utilities
|
||||
Source: %{name}-%{version}.tar.bz2
|
||||
Source1: nss-mdns-config
|
||||
Source2: baselibs.conf
|
||||
Patch: unaligned.diff
|
||||
# needed by nss-mdns-config
|
||||
PreReq: sed grep
|
||||
Requires: avahi
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
@ -48,12 +48,6 @@ register the local hostname via mDNS. I recommend Avahi.
|
||||
By default, nss-mdns tries to contact a running avahi-daemon to resolve
|
||||
hostnames and addresses and makes use of its superior record cacheing.
|
||||
|
||||
|
||||
|
||||
Authors:
|
||||
--------
|
||||
Lennart Poettering <mzaffzqaf@0pointer.de>
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
%patch
|
||||
@ -63,82 +57,34 @@ Authors:
|
||||
|
||||
%install
|
||||
%makeinstall
|
||||
install -D -m0755 %{SOURCE1} %{buildroot}%{_sbindir}/nss-mdns-config
|
||||
|
||||
%post
|
||||
/sbin/ldconfig
|
||||
# Perl-fu to add mdns4_minimal to the hosts line of /etc/nsswitch.conf
|
||||
if [ -f /etc/nsswitch.conf ] ; then
|
||||
perl -ibak -pe '
|
||||
sub insert {
|
||||
my @bits = split(" ", shift);
|
||||
if (grep { $_ eq "mdns4_minimal" || $_ eq "mdns4"
|
||||
|| $_ eq "mdns6_minimal" || $_ eq "mdns6"
|
||||
|| $_ eq "mdns_minimal" || $_ eq "mdns" } @bits) {
|
||||
return join " ", @bits;
|
||||
}
|
||||
return join " ", map {
|
||||
$_ eq "dns" ? ("mdns4_minimal", "[NOTFOUND=return]", $_) : $_
|
||||
} @bits;
|
||||
}
|
||||
s/^(hosts:\s+)(.*)$/$1.insert($2)/e;
|
||||
' /etc/nsswitch.conf
|
||||
if [ "$1" -eq 1 ] ; then
|
||||
# Only enable on first install, to not overwrite changes done by users
|
||||
nss-mdns-config --enable
|
||||
fi
|
||||
|
||||
%preun
|
||||
# Perl-fu to remove mdns4_minimal from the hosts line of /etc/nsswitch.conf
|
||||
if [ "$1" -eq 0 -a -f /etc/nsswitch.conf ] ; then
|
||||
perl -ibak -pe '
|
||||
my @remove = (
|
||||
"mdns4_minimal [NOTFOUND=return]",
|
||||
"mdns4_minimal",
|
||||
"mdns4",
|
||||
"mdns6_minimal [NOTFOUND=return]",
|
||||
"mdns6_minimal",
|
||||
"mdns6",
|
||||
"mdns_minimal [NOTFOUND=return]",
|
||||
"mdns_minimal",
|
||||
"mdns",
|
||||
);
|
||||
sub remove {
|
||||
my $s = shift;
|
||||
foreach my $bit (@remove) {
|
||||
$s =~ s/\s+\Q$bit\E//g;
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
s/^(hosts:\s+)(.*)$/$1.remove($2)/e;
|
||||
' /etc/nsswitch.conf
|
||||
if [ "$1" -eq 0 ] ; then
|
||||
# Completely disable when not upgrading (ie, fully uninstalling)
|
||||
nss-mdns-config --disable
|
||||
fi
|
||||
|
||||
%postun
|
||||
/sbin/ldconfig
|
||||
# Build a regexp removing all no more provided libraries.
|
||||
# If there are no known libraries installed, remove also related "[NOTFOUND=return]"
|
||||
REMOVE_REGEXP=
|
||||
REAL_REMOVE=true
|
||||
for NSS_NAME in mdns mdns4 mdns4_minimal mdns_minimal mdns6 mdns6_minimal ; do
|
||||
if test -f %{_lib}/libnss_$NSS_NAME.so.2 ; then
|
||||
REAL_REMOVE=false
|
||||
else
|
||||
REMOVE_REGEXP="${REMOVE_REGEXP}
|
||||
s/\\([[:space:]][[:space:]]*\\)$NSS_NAME\\([[:space:]][[:space:]]*\\)/\\1/g;
|
||||
s/\\([[:space:]][[:space:]]*\\)$NSS_NAME\$//g;"
|
||||
fi
|
||||
done
|
||||
if $REAL_REMOVE ; then
|
||||
REMOVE_REGEXP="s/\\(mdns[46]*_minimal\\)[[:space:]][[:space:]]*\\[NOTFOUND=return\\]/\\1/;$REMOVE_REGEXP"
|
||||
fi
|
||||
sed -i "/^hosts:/{$REMOVE_REGEXP}" etc/nsswitch.conf
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%doc LICENSE README doc/*.html doc/*.css
|
||||
%{_sbindir}/nss-mdns-config
|
||||
/%{_lib}/libnss_mdns.so.2
|
||||
/%{_lib}/libnss_mdns_minimal.so.2
|
||||
/%{_lib}/libnss_mdns4.so.2
|
||||
/%{_lib}/libnss_mdns4_minimal.so.2
|
||||
/%{_lib}/libnss_mdns6.so.2
|
||||
/%{_lib}/libnss_mdns6_minimal.so.2
|
||||
/%{_lib}/libnss_mdns_minimal.so.2
|
||||
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
Loading…
x
Reference in New Issue
Block a user