Author: locilka Date: Mon Jun 20 15:48:56 2011 New Revision: 64488 URL: http://svn.opensuse.org/viewcvs/yast?rev=64488&view=rev Log: - Automatically changing entered forwarder to a localhost IP if the server would forward to itself (non-local IP) (BNC #676676). - 2.21.2 Martin, let's move the functionality to some yast2/network module if appropriate ;) For 12.1 and later... Modified: trunk/dns-server/VERSION trunk/dns-server/package/yast2-dns-server.changes trunk/dns-server/src/dialog-main.ycp trunk/dns-server/testsuite/tests.ag/zoneag.ycp Modified: trunk/dns-server/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/dns-server/VERSION?rev=64488&r1=64487&r2=64488&view=diff ============================================================================== --- trunk/dns-server/VERSION (original) +++ trunk/dns-server/VERSION Mon Jun 20 15:48:56 2011 @@ -1 +1 @@ -2.21.1 +2.21.2 Modified: trunk/dns-server/package/yast2-dns-server.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/dns-server/package/yast2-dns-server.changes?rev=64488&r1=64487&r2=64488&view=diff ============================================================================== --- trunk/dns-server/package/yast2-dns-server.changes (original) +++ trunk/dns-server/package/yast2-dns-server.changes Mon Jun 20 15:48:56 2011 @@ -1,4 +1,11 @@ ------------------------------------------------------------------ +Mon Jun 20 15:35:29 CEST 2011 - locilka@suse.cz + +- Automatically changing entered forwarder to a localhost IP if + the server would forward to itself (non-local IP) (BNC #676676). +- 2.21.2 + +------------------------------------------------------------------ Wed Mar 16 15:51:40 CET 2011 - locilka@suse.cz - Handling unknown error in LDAP initialization (BNC #679960). Modified: trunk/dns-server/src/dialog-main.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/dns-server/src/dialog-main.ycp?rev=64488&r1=64487&r2=64488&view=diff ============================================================================== --- trunk/dns-server/src/dialog-main.ycp (original) +++ trunk/dns-server/src/dialog-main.ycp Mon Jun 20 15:48:56 2011 @@ -428,6 +428,66 @@ } /** + * Returns list of IPs currently used by the system. + * + * @param boolean whether local addresses should be returned as well (the default is false) + */ +list <string> CurrentlyUsedIPs (boolean including_local) { + string cmd = "ip addr show | grep 'inet\\(6\\)\\?' | sed 's/^[ \\t]\\+inet\\(6\\)\\?[ \\t]\\+\\([^\\/]\\+\\)\\/.*$/\\2/'"; + map cmd_ret = (map) SCR::Execute (.target.bash_output, cmd); + + if (cmd_ret == nil || cmd_ret["exit"]:-1 != 0) { + y2error ("Cannot get list of used IPs: %1", cmd_ret); + return nil; + } + + list <string> used_ips = splitstring (cmd_ret["stdout"]:"", "\n"); + used_ips = filter (string used_ip, used_ips, ``(used_ip != nil && used_ip != "")); + + // Filtering out all local IPs + if (including_local != true) { + used_ips = filter (string used_ip, used_ips, ``( + !regexpmatch(used_ip, "127\.0\.0\..*") && used_ip != "::1" + )); + } + + return used_ips; +} + +/** + * Gets an IP address and returns it's local equivalent: 127.0.0.1 for IPv4, ::1 for IPv6. + * If a given string is neither IPv4 nor IPv6, nil is returned. + * + * @param string IP to transform + * @returns string transformed IP + */ +string ChangeIPToLocalEquivalent (string ip_address) { + string ret = nil; + + if (IP::Check4 (ip_address)) { + ret = "127.0.0.1"; + } else if (IP::Check6 (ip_address)) { + ret = "::1"; + } else { + ret = nil; + } + + y2warning ("Transforming forwarder IP %1 to %2", ip_address, ret); + + if (ret == nil) { + // An error message, %1 is replaced with a variable IP + Report::Error (sformat(_("Cannot find local equivalent for IP %1"), ret)); + } else { + // TRANSLATORS: A warning message, %1 is replaced with the input IP, %2 with the output IP + Report::Warning (sformat(_("Forwarding DNS queries to itself would create an infinite loop. +IP address %1 is currently used by this server, so it has +been changed to its local equivalent %2."), ip_address, ret)); + } + + return ret; +} + +/** * Handle events in a tab of a dialog */ symbol HandleExpertForwardersPage (string key, map event) { @@ -449,6 +509,13 @@ ); return nil; } + + list <string> used_ips = CurrentlyUsedIPs (false); + if (contains (used_ips, new_addr)) { + new_addr = ChangeIPToLocalEquivalent (new_addr); + if (new_addr == nil) return nil; + } + if (contains (forwarders, new_addr)) { // error report Modified: trunk/dns-server/testsuite/tests.ag/zoneag.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/dns-server/testsuite/tests.ag/zoneag.ycp?rev=64488&r1=64487&r2=64488&view=diff ============================================================================== --- trunk/dns-server/testsuite/tests.ag/zoneag.ycp (original) +++ trunk/dns-server/testsuite/tests.ag/zoneag.ycp Mon Jun 20 15:48:56 2011 @@ -16,6 +16,7 @@ */ { + // testedfiles: zoneag.ycp integer old = (integer)WFM::SCRGetDefault (); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org