~ubuntu-branches/ubuntu/edgy/bugzilla/edgy

« back to all changes in this revision

Viewing changes to query.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Alexis Sukrieh
  • Date: 2005-10-03 16:51:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051003165101-38n0y5qofd68vole
Tags: 2.18.4-1
* New upstream minor release
  + Fixed a security issue: It was possible to bypass the "user
    visibility groups" restrictions if user-matching was turned on
    in "substring" mode.
  + Fixed a security issue: config.cgi exposed information to users who
    weren't logged in, even when "requirelogin" was turned on in Bugzilla.
  (closes: #331206)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bonsaitools/bin/perl -wT
 
1
#!/usr/bin/perl -wT
2
2
# -*- Mode: perl; indent-tabs-mode: nil -*-
3
3
#
4
4
# The contents of this file are subject to the Mozilla Public
22
22
#                 David Gardiner <david.gardiner@unisa.edu.au>
23
23
#                 Matthias Radestock <matthias@sorted.org>
24
24
#                 Gervase Markham <gerv@gerv.net>
 
25
#                 Byron Jones <bugzilla@glob.com.au>
25
26
 
26
 
use diagnostics;
27
27
use strict;
28
 
use lib '/usr/share/bugzilla/lib';
 
28
use lib ".";
29
29
 
30
30
require "CGI.pl";
31
31
 
 
32
use Bugzilla::Constants;
 
33
use Bugzilla::Search;
 
34
 
32
35
use vars qw(
33
36
    @CheckOptionValues
34
37
    @legal_resolution
50
53
    $vars
51
54
);
52
55
 
53
 
ConnectToDatabase();
 
56
my $cgi = Bugzilla->cgi;
54
57
 
55
58
if (defined $::FORM{"GoAheadAndLogIn"}) {
56
59
    # We got here from a login page, probably from relogin.cgi.  We better
57
60
    # make sure the password is legit.
58
 
    confirm_login();
 
61
    Bugzilla->login(LOGIN_REQUIRED);
59
62
} else {
60
 
    quietly_check_login();
 
63
    Bugzilla->login();
61
64
}
62
65
 
 
66
my $user = Bugzilla->user;
 
67
my $userid = $user ? $user->id : 0;
 
68
 
63
69
# Backwards compatibility hack -- if there are any of the old QUERY_*
64
70
# cookies around, and we are logged in, then move them into the database
65
71
# and nuke the cookie. This is required for Bugzilla 2.8 and earlier.
66
 
if ($::userid) {
 
72
if ($user) {
67
73
    my @oldquerycookies;
68
74
    foreach my $i (keys %::COOKIE) {
69
75
        if ($i =~ /^QUERY_(.*)$/) {
79
85
            my ($name, $cookiename, $value) = (@$ref);
80
86
            if ($value) {
81
87
                my $qname = SqlQuote($name);
 
88
                SendSQL("LOCK TABLES namedqueries WRITE");
82
89
                SendSQL("SELECT query FROM namedqueries " .
83
 
                        "WHERE userid = $::userid AND name = $qname");
 
90
                        "WHERE userid = $userid AND name = $qname");
84
91
                my $query = FetchOneColumn();
85
92
                if (!$query) {
86
 
                    SendSQL("REPLACE INTO namedqueries " .
 
93
                    SendSQL("INSERT INTO namedqueries " .
87
94
                            "(userid, name, query) VALUES " .
88
 
                            "($::userid, $qname, " . SqlQuote($value) . ")");
 
95
                            "($userid, $qname, " . SqlQuote($value) . ")");
89
96
                }
 
97
                SendSQL("UNLOCK TABLES");
90
98
            }
91
 
            print "Set-Cookie: $cookiename= ; path=" . Param("cookiepath") . 
92
 
                  "; expires=Tue, 15-Sep-1998 21:49:00 GMT\n";
 
99
            $cgi->remove_cookie($cookiename);
93
100
        }
94
101
    }
95
102
}
96
103
 
97
104
if ($::FORM{'nukedefaultquery'}) {
98
 
    if ($::userid) {
 
105
    if ($user) {
99
106
        SendSQL("DELETE FROM namedqueries " .
100
 
                "WHERE userid = $::userid AND name = '$::defaultqueryname'");
 
107
                "WHERE userid = $userid AND name = '$::defaultqueryname'");
101
108
    }
102
109
    $::buffer = "";
103
110
}
104
111
 
105
112
my $userdefaultquery;
106
 
if ($::userid) {
 
113
if ($user) {
107
114
    SendSQL("SELECT query FROM namedqueries " .
108
 
            "WHERE userid = $::userid AND name = '$::defaultqueryname'");
 
115
            "WHERE userid = $userid AND name = '$::defaultqueryname'");
109
116
    $userdefaultquery = FetchOneColumn();
110
117
}
111
118
 
126
133
                      "chfieldto", "chfieldvalue", "target_milestone",
127
134
                      "email", "emailtype", "emailreporter",
128
135
                      "emailassigned_to", "emailcc", "emailqa_contact",
129
 
                      "emaillongdesc",
 
136
                      "emaillongdesc", "content",
130
137
                      "changedin", "votes", "short_desc", "short_desc_type",
131
138
                      "long_desc", "long_desc_type", "bug_file_loc",
132
139
                      "bug_file_loc_type", "status_whiteboard",
133
140
                      "status_whiteboard_type", "bug_id",
134
 
                      "bugidtype", "keywords", "keywords_type") {
 
141
                      "bugidtype", "keywords", "keywords_type",
 
142
                      "x_axis_field", "y_axis_field", "z_axis_field",
 
143
                      "chart_format", "cumulate", "x_labels_vertical",
 
144
                      "category", "subcategory", "name", "newcategory",
 
145
                      "newsubcategory", "public", "frequency") 
 
146
    {
135
147
        # This is a bit of a hack. The default, empty list has 
136
148
        # three entries to accommodate the needs of the email fields -
137
149
        # we use each position to denote the relevant field. Array
152
164
            $value = "";
153
165
        }
154
166
        
 
167
        # If the name begins with field, type, or value, then it is part of
 
168
        # the boolean charts. Because these are built different than the rest
 
169
        # of the form, we don't need to save a default value. We do, however,
 
170
        # need to indicate that we found something so the default query isn't
 
171
        # added in if all we have are boolean chart items.
 
172
        if ($name =~ m/^(?:field|type|value)/) {
 
173
            $foundone = 1;
 
174
        }
155
175
        # If the name ends in a number (which it does for the fields which
156
176
        # are part of the email searching), we use the array
157
177
        # positions to show the defaults for that number field.
158
 
        if ($name =~ m/^(.+)(\d)$/ && defined($default{$1})) {
 
178
        elsif ($name =~ m/^(.+)(\d)$/ && defined($default{$1})) {
159
179
            $foundone = 1;
160
180
            $default{$1}->[$2] = $value;
161
181
        }
189
209
 
190
210
GetVersionTable();
191
211
 
192
 
# if using usebuggroups, then we don't want people to see products they don't
193
 
# have access to. Remove them from the list.
 
212
# if using groups for entry, then we don't want people to see products they 
 
213
# don't have access to. Remove them from the list.
194
214
 
195
215
my @products = ();
196
216
my %component_set;
197
217
my %version_set;
198
218
my %milestone_set;
199
 
foreach my $p (@::legal_product) {
200
 
    # If we're using bug groups to restrict entry on products, and
201
 
    # this product has a bug group, and the user is not in that
202
 
    # group, we don't want to include that product in this list.
203
 
    next if (Param("usebuggroups") && GroupExists($p) && !UserInGroup($p));
204
 
 
 
219
foreach my $p (GetSelectableProducts()) {
205
220
    # We build up boolean hashes in the "-set" hashes for each of these things 
206
221
    # before making a list because there may be duplicates names across products.
207
222
    push @products, $p;
242
257
    }
243
258
}
244
259
 
245
 
# Sort the component list...
246
 
my $comps = \%::components;
247
 
foreach my $p (@products) {
248
 
    my @tmp = sort { lc($a) cmp lc($b) } @{$comps->{$p}};
249
 
    $comps->{$p} = \@tmp;
250
 
}    
251
 
 
252
 
# and the version list...
253
 
my $vers = \%::versions;
254
 
foreach my $p (@products) {
255
 
    my @tmp = sort { lc($a) cmp lc($b) } @{$vers->{$p}};
256
 
    $vers->{$p} = \@tmp;
257
 
}    
258
 
 
259
 
# and the milestone list.
260
 
my $mstones;
261
 
if (Param('usetargetmilestone')) {
262
 
    $mstones = \%::target_milestone;
263
 
    foreach my $p (@products) {
264
 
        my @tmp = sort { lc($a) cmp lc($b) } @{$mstones->{$p}};
265
 
        $mstones->{$p} = \@tmp;
266
 
    }    
 
260
# Create data structures representing each product.
 
261
for (my $i = 0; $i < @products; ++$i) {
 
262
    my $p = $products[$i];
 
263
    
 
264
    # Bug 190611: band-aid to avoid crashing with no versions defined
 
265
    if (!defined ($::components{$p})) {
 
266
        $::components{$p} = [];
 
267
    }
 
268
    
 
269
    # Create hash to hold attributes for each product.
 
270
    my %product = (
 
271
        'name'       => $p,
 
272
        'components' => [ sort { lc($a) cmp lc($b) } @{$::components{$p}} ],
 
273
        'versions'   => [ sort { lc($a) cmp lc($b) } @{$::versions{$p}}   ]
 
274
    );
 
275
    
 
276
    if (Param('usetargetmilestone')) {
 
277
        # Sorting here is required for ordering multiple selections 
 
278
        # correctly; see bug 97736 for discussion on how to fix this
 
279
        $product{'milestones'} =  
 
280
                      [ sort { lc($a) cmp lc($b) } @{$::target_milestone{$p}} ];
 
281
    }
 
282
    
 
283
    # Assign hash back to product array.
 
284
    $products[$i] = \%product;
267
285
}
268
286
 
269
 
# "foo" or "foos" is a list of all the possible (or legal) products, 
270
 
# components, versions or target milestones.
271
 
# "foobyproduct" is a hash, keyed by product, of sorted lists
272
 
# of the same data.
273
 
 
274
287
$vars->{'product'} = \@products;
275
288
 
276
289
# We use 'component_' because 'component' is a Template Toolkit reserved word.
277
 
$vars->{'componentsbyproduct'} = $comps;
278
290
$vars->{'component_'} = \@components;
279
291
 
280
 
$vars->{'versionsbyproduct'} = $vers;
281
292
$vars->{'version'} = \@versions;
282
293
 
283
294
if (Param('usetargetmilestone')) {
284
 
    $vars->{'milestonesbyproduct'} = $mstones;
285
295
    $vars->{'target_milestone'} = \@milestones;
286
296
}
287
297
 
292
302
      # Another hack - this array contains "" for some reason. See bug 106589.
293
303
$vars->{'resolution'} = \@::legal_resolution;
294
304
 
295
 
$vars->{'chfield'} = ["[Bug creation]", @::log_columns];
 
305
my @chfields;
 
306
 
 
307
push @chfields, "[Bug creation]";
 
308
 
 
309
# This is what happens when you have variables whose definition depends
 
310
# on the DB schema, and then the underlying schema changes...
 
311
foreach my $val (@::log_columns) {
 
312
    if ($val eq 'product_id') {
 
313
        $val = 'product';
 
314
    } elsif ($val eq 'component_id') {
 
315
        $val = 'component';
 
316
    }
 
317
    push @chfields, $val;
 
318
}
 
319
 
 
320
if (UserInGroup(Param('timetrackinggroup'))) {
 
321
    push @chfields, "work_time";
 
322
} else {
 
323
    @chfields = grep($_ ne "estimated_time", @chfields);
 
324
    @chfields = grep($_ ne "remaining_time", @chfields);
 
325
}
 
326
@chfields = (sort(@chfields));
 
327
$vars->{'chfield'} = \@chfields;
296
328
$vars->{'bug_status'} = \@::legal_bug_status;
297
329
$vars->{'rep_platform'} = \@::legal_platform;
298
330
$vars->{'op_sys'} = \@::legal_opsys;
299
331
$vars->{'priority'} = \@::legal_priority;
300
332
$vars->{'bug_severity'} = \@::legal_severity;
301
 
$vars->{'userid'} = $::userid;
302
333
 
303
334
# Boolean charts
304
335
my @fields;
305
336
push(@fields, { name => "noop", description => "---" });
306
 
SendSQL("SELECT name, description FROM fielddefs ORDER BY sortkey");
307
 
while (MoreSQLData()) {
308
 
    my ($name, $description) = FetchSQLData();
309
 
    push(@fields, { name => $name, description => $description });
310
 
}
311
 
 
 
337
push(@fields, GetFieldDefs());
312
338
$vars->{'fields'} = \@fields;
313
339
 
314
340
# Creating new charts - if the cmd-add value is there, we define the field
345
371
$default{'charts'} = \@charts;
346
372
 
347
373
# Named queries
348
 
if ($::userid) {
 
374
if ($user) {
349
375
    my @namedqueries;
350
376
    SendSQL("SELECT name FROM namedqueries " .
351
 
            "WHERE userid = $::userid AND name != '$::defaultqueryname' " .
 
377
            "WHERE userid = $userid AND name != '$::defaultqueryname' " .
352
378
            "ORDER BY name");
353
379
    while (MoreSQLData()) {
354
380
        push(@namedqueries, FetchOneColumn());
372
398
$vars->{'orders'} = \@orders;
373
399
$default{'querytype'} = $deforder || 'Importance';
374
400
 
 
401
if (($::FORM{'query_format'} || $::FORM{'format'} || "") eq "create-series") {
 
402
    require Bugzilla::Chart;
 
403
    $vars->{'category'} = Bugzilla::Chart::getVisibleSeries();
 
404
}
 
405
 
 
406
$vars->{'known_name'} = $cgi->param('known_name');
 
407
 
 
408
 
375
409
# Add in the defaults.
376
410
$vars->{'default'} = \%default;
377
411
 
 
412
$vars->{'format'} = $cgi->param('format');
 
413
$vars->{'query_format'} = $cgi->param('query_format');
 
414
 
 
415
# Set default page to "specific" if none proviced
 
416
if (!($cgi->param('query_format') || $cgi->param('format'))) {
 
417
    if (defined $cgi->cookie('DEFAULTFORMAT')) {
 
418
        $vars->{'format'} = $cgi->cookie('DEFAULTFORMAT');
 
419
    } else {
 
420
        $vars->{'format'} = 'specific';
 
421
    }
 
422
}
 
423
 
 
424
# Set cookie to current format as default, but only if the format
 
425
# one that we should remember.
 
426
if (IsValidQueryType($vars->{'format'})) {
 
427
    $cgi->send_cookie(-name => 'DEFAULTFORMAT',
 
428
                      -value => $vars->{'format'},
 
429
                      -expires => "Fri, 01-Jan-2038 00:00:00 GMT");
 
430
}
 
431
 
378
432
# Generate and return the UI (HTML page) from the appropriate template.
379
 
print "Content-type: text/html\n\n";
380
 
$template->process("search/search.html.tmpl", $vars)
 
433
# If we submit back to ourselves (for e.g. boolean charts), we need to
 
434
# preserve format information; hence query_format taking priority over
 
435
# format.
 
436
my $format = GetFormat("search/search", 
 
437
                       $vars->{'query_format'} || $vars->{'format'}, 
 
438
                       $cgi->param('ctype'));
 
439
 
 
440
print $cgi->header($format->{'ctype'});
 
441
 
 
442
$template->process($format->{'template'}, $vars)
381
443
  || ThrowTemplateError($template->error());