diff options
author | lpsolit%gmail.com <> | 2006-06-03 19:23:12 +0000 |
---|---|---|
committer | lpsolit%gmail.com <> | 2006-06-03 19:23:12 +0000 |
commit | 1a18e5fc2c3678e9a4a3049b9289e417ce174c7e (patch) | |
tree | e63669d54a68eb921c69c9b78d79b1dd5f7563c3 /Bugzilla/Util.pm | |
parent | Bug 340116: Flag::FormToNewFlags() uses incorrect data - Patch by Frédéric ... (diff) | |
download | bugzilla-1a18e5fc2c3678e9a4a3049b9289e417ce174c7e.tar.gz bugzilla-1a18e5fc2c3678e9a4a3049b9289e417ce174c7e.tar.bz2 bugzilla-1a18e5fc2c3678e9a4a3049b9289e417ce174c7e.zip |
Bug 340104: Move Bugzilla::Auth::get_netaddr() in Util.pm - Patch by Frédéric Buclin <LpSolit@gmail.com> r/a=justdave
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r-- | Bugzilla/Util.pm | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 28f5e71bc..98a3065cf 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -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 |