]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 340104: Move Bugzilla::Auth::get_netaddr() in Util.pm - Patch by Frédéric Buclin...
authorlpsolit%gmail.com <>
Sat, 3 Jun 2006 19:23:12 +0000 (19:23 +0000)
committerlpsolit%gmail.com <>
Sat, 3 Jun 2006 19:23:12 +0000 (19:23 +0000)
Bugzilla/Auth.pm
Bugzilla/Auth/Login/Cookie.pm
Bugzilla/Auth/Persist/Cookie.pm
Bugzilla/Util.pm

index 0e57371a283cdd8a7ed3cb661c84be8a58b1f416..daacc677a0a9b51a4735bed321e211f117ac25b4 100644 (file)
@@ -199,28 +199,6 @@ sub _handle_login_result {
     return $user;
 }
 
-# Returns the network address for a given IP
-sub get_netaddr {
-    my $ipaddr = shift;
-
-    # Check for a valid IPv4 addr which we know how to parse
-    if (!$ipaddr || $ipaddr !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
-        return undef;
-    }
-
-    my $addr = unpack("N", pack("CCCC", split(/\./, $ipaddr)));
-
-    my $maskbits = Param('loginnetmask');
-
-    # Make Bugzilla ignore the IP address if loginnetmask is set to 0
-    return "0.0.0.0" if ($maskbits == 0);
-
-    $addr >>= (32-$maskbits);
-
-    $addr <<= (32-$maskbits);
-    return join(".", unpack("CCCC", pack("N", $addr)));
-}
-
 1;
 
 __END__
@@ -383,22 +361,6 @@ Returns:     C<true> if users can change their own email address,
 
 =back
 
-=head1 CLASS FUNCTIONS
-
-C<Bugzilla::Auth> contains several helper methods to be used by
-authentication or login modules.
-
-=over 4
-
-=item C<Bugzilla::Auth::get_netaddr($ipaddr)>
-
-Given an ip address, this returns the associated network address, using
-C<Param('loginnetmask')> as the netmask. This can be used to obtain data
-in order to restrict weak authentication methods (such as cookies) to
-only some addresses.
-
-=back
-
 =head1 STRUCTURE
 
 This section is mostly interesting to developers who want to implement
index 2ca4aca72ccd807031cff01c2e11f4c61a272f41..f2a93e94e3ea7282adecfde066f11c7098a2812e 100644 (file)
@@ -19,7 +19,6 @@ package Bugzilla::Auth::Login::Cookie;
 use strict;
 use base qw(Bugzilla::Auth::Login);
 
-use Bugzilla::Auth;
 use Bugzilla::Constants;
 use Bugzilla::Util;
 
@@ -35,7 +34,7 @@ sub get_login_info {
     my $dbh = Bugzilla->dbh;
 
     my $ip_addr      = $cgi->remote_addr();
-    my $net_addr     = Bugzilla::Auth::get_netaddr($ip_addr);
+    my $net_addr     = get_netaddr($ip_addr);
     my $login_cookie = $cgi->cookie("Bugzilla_logincookie");
     my $user_id      = $cgi->cookie("Bugzilla_login");
 
index c41948e72aedefa97b08aac6325ade64211459fc..7d1209a0e03cda9c481633219dced0fd7c546ffe 100644 (file)
@@ -32,7 +32,6 @@ package Bugzilla::Auth::Persist::Cookie;
 use strict;
 use fields qw();
 
-use Bugzilla::Auth;
 use Bugzilla::Config;
 use Bugzilla::Constants;
 use Bugzilla::Util;
@@ -55,8 +54,7 @@ sub persist_login {
     unless ($cgi->param('Bugzilla_restrictlogin') ||
             Param('loginnetmask') == 32) 
     {
-        # XXX I don't like this subclass being dependent upon its parent.
-        $ip_addr = Bugzilla::Auth::get_netaddr($ip_addr);
+        $ip_addr = get_netaddr($ip_addr);
     }
 
     # The IP address is valid, at least for comparing with itself in a
index 28f5e71bc324e33f40394d237fe6daf4baadef5d..98a3065cf24937a937183e299f1a9ef524e77f2a 100644 (file)
@@ -34,7 +34,7 @@ use base qw(Exporter);
                              detaint_signed
                              html_quote url_quote value_quote xml_quote
                              css_class_quote
-                             i_am_cgi
+                             i_am_cgi get_netaddr
                              lsearch max min
                              diff_arrays diff_strings
                              trim wrap_comment find_wrap_point
@@ -396,6 +396,27 @@ sub clean_text {
     return trim($dtext);
 }
 
+sub get_netaddr {
+    my $ipaddr = shift;
+
+    # Check for a valid IPv4 addr which we know how to parse
+    if (!$ipaddr || $ipaddr !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+        return undef;
+    }
+
+    my $addr = unpack("N", pack("CCCC", split(/\./, $ipaddr)));
+
+    my $maskbits = Param('loginnetmask');
+
+    # Make Bugzilla ignore the IP address if loginnetmask is set to 0
+    return "0.0.0.0" if ($maskbits == 0);
+
+    $addr >>= (32-$maskbits);
+
+    $addr <<= (32-$maskbits);
+    return join(".", unpack("CCCC", pack("N", $addr)));
+}
+
 1;
 
 __END__
@@ -425,6 +446,7 @@ Bugzilla::Util - Generic utility functions for bugzilla
 
   # Functions that tell you about your environment
   my $is_cgi = i_am_cgi();
+  $net_addr = get_netaddr($ip_addr);
 
   # Functions for searching
   $loc = lsearch(\@arr, $val);
@@ -540,12 +562,27 @@ is kept separate from html_quote partly for compatibility with previous code
 
 Converts the %xx encoding from the given URL back to its original form.
 
+=back
+
+=head2 Environment and Location
+
+Functions returning information about your environment or location.
+
+=over 4
+
 =item C<i_am_cgi()>
 
 Tells you whether or not you are being run as a CGI script in a web
 server. For example, it would return false if the caller is running
 in a command-line script.
 
+=item C<get_netaddr($ipaddr)>
+
+Given an IP address, this returns the associated network address, using
+C<Param('loginnetmask')> as the netmask. This can be used to obtain data
+in order to restrict weak authentication methods (such as cookies) to
+only some addresses.
+
 =back
 
 =head2 Searching