From 8b2d89d707496feea71c66635599aa4bd5fdcac9 Mon Sep 17 00:00:00 2001 From: wimpunk Date: Wed, 19 Nov 2008 21:09:07 +0000 Subject: [PATCH] Added better password handling sended by Ingo Schwarze git-svn-id: svn+ssh://svn.code.sf.net/p/ddclient/code/trunk@105 3873ddee-7413-0410-b6c4-c2c57c1ab35a --- ddclient | 18 +++++++--- patches/password.patch | 77 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 patches/password.patch diff --git a/ddclient b/ddclient index 354cc86..804ae91 100755 --- a/ddclient +++ b/ddclient @@ -937,6 +937,7 @@ sub _read_config { local $lineno = 0; my $continuation = ''; + my %passwords = (); while () { s/[\r\n]//g; @@ -952,10 +953,17 @@ sub _read_config { } $content .= "$_\n" unless /^#/; - # lines contain passwords are a special case, we don't want to - # arbitrarily strip out '#' - if (/^(\S*password\S*)\s*=\s*(\S+)/i) { $_ = "$1=$2"; } - if (/^#/ || !(/password/i) || /#.*password/i) { s/#.*//; } # remove comments + + ## parsing passwords is special + if (/^([^#]*\s)?([^#]*?password\S*?)\s*=\s*('.*'|[^']\S*)(.*)/) { + my ($head, $key, $value, $tail) = ($1 || '', $2, $3, $4); + $value = $1 if $value =~ /^'(.*)'$/; + $passwords{$key} = $value; + $_ = "${head}${key}=dummy${tail}"; + } + + ## remove comments + s/#.*//; ## handle continuation lines $_ = "$continuation$_"; @@ -980,6 +988,7 @@ sub _read_config { ## verify that keywords are valid...and check the value foreach my $k (keys %locals) { + $locals{$k} = $passwords{$k} if defined $passwords{$k}; if (!exists $variables{'merged'}{$k}) { warning("unrecognized keyword '%s' (ignored)", $k); delete $locals{$k}; @@ -1018,6 +1027,7 @@ sub _read_config { $config{$h}{'host'} = $h; } } + %passwords = (); } close(FD); diff --git a/patches/password.patch b/patches/password.patch new file mode 100644 index 0000000..e0d763d --- /dev/null +++ b/patches/password.patch @@ -0,0 +1,77 @@ +# +# Patch to improve password handling in ddclient-3.7.3 +# Copyright (C) 2008 Astaro AG www.astaro.com +# Author: Ingo Schwarze 30.09.2008 +# +# Originally posted on the ddclient-user mailing list +# see http://permalink.gmane.org/gmane.network.dns.ddclient.user/18 +# +# This patch is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This patch is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with the ddclient program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA, +# or look up http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt . +# +Index: ddclient +=================================================================== +RCS file: /home/cvs/sources/d/ddclient/ddclient,v +retrieving revision 1.1.1.2 +diff -u -p -r1.1.1.2 ddclient +--- ddclient 15 Sep 2008 11:13:55 -0000 1.1.1.2 ++++ ddclient 30 Sep 2008 18:55:52 -0000 +@@ -888,6 +888,7 @@ sub _read_config { + + local $lineno = 0; + my $continuation = ''; ++ my %passwords = (); + while () { + s/[\r\n]//g; + +@@ -903,10 +904,17 @@ sub _read_config { + } + + $content .= "$_\n" unless /^#/; +- # lines contain passwords are a special case, we don't want to +- # arbitrarily strip out '#' +- if (/^(\S*password\S*)\s*=\s*(\S+)/i) { $_ = "$1=$2"; } +- if (/^#/ || !(/password/i) || /#.*password/i) { s/#.*//; } # remove comments ++ ++ ## parsing passwords is special ++ if (/^([^#]*\s)?([^#]*?password\S*?)\s*=\s*('.*'|[^']\S*)(.*)/) { ++ my ($head, $key, $value, $tail) = ($1 || '', $2, $3, $4); ++ $value = $1 if $value =~ /^'(.*)'$/; ++ $passwords{$key} = $value; ++ $_ = "${head}${key}=dummy${tail}"; ++ } ++ ++ ## remove comments ++ s/#.*//; + + ## handle continuation lines + $_ = "$continuation$_"; +@@ -931,6 +939,7 @@ sub _read_config { + + ## verify that keywords are valid...and check the value + foreach my $k (keys %locals) { ++ $locals{$k} = $passwords{$k} if defined $passwords{$k}; + if (!exists $variables{'merged'}{$k}) { + warning("unrecognized keyword '%s' (ignored)", $k); + delete $locals{$k}; +@@ -969,6 +978,7 @@ sub _read_config { + $config{$h}{'host'} = $h; + } + } ++ %passwords = (); + } + close(FD); + +