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

« back to all changes in this revision

Viewing changes to bug_form.pl

  • 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
 
# -*- Mode: perl; indent-tabs-mode: nil -*-
2
 
#
3
 
# The contents of this file are subject to the Mozilla Public
4
 
# License Version 1.1 (the "License"); you may not use this file
5
 
# except in compliance with the License. You may obtain a copy of
6
 
# the License at http://www.mozilla.org/MPL/
7
 
#
8
 
# Software distributed under the License is distributed on an "AS
9
 
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
 
# implied. See the License for the specific language governing
11
 
# rights and limitations under the License.
12
 
#
13
 
# The Original Code is the Bugzilla Bug Tracking System.
14
 
#
15
 
# The Initial Developer of the Original Code is Netscape Communications
16
 
# Corporation. Portions created by Netscape are
17
 
# Copyright (C) 1998 Netscape Communications Corporation. All
18
 
# Rights Reserved.
19
 
#
20
 
# Contributor(s): Terry Weissman <terry@mozilla.org>
21
 
#                 Dave Miller <justdave@syndicomm.com>
22
 
 
23
 
use diagnostics;
24
 
use strict;
25
 
 
26
 
use RelationSet;
27
 
 
28
 
# Use the Attachment module to display attachments for the bug.
29
 
use Attachment;
30
 
 
31
 
sub show_bug {    
32
 
    # Shut up misguided -w warnings about "used only once".  For some reason,
33
 
    # "use vars" chokes on me when I try it here.
34
 
    sub bug_form_pl_sillyness {
35
 
        my $zz;
36
 
        $zz = %::FORM;
37
 
        $zz = %::proddesc;
38
 
        $zz = %::prodmaxvotes;
39
 
        $zz = @::enterable_products;                                            
40
 
        $zz = @::settable_resolution;
41
 
        $zz = $::unconfirmedstate;
42
 
        $zz = $::milestoneurl;
43
 
        $zz = $::template;
44
 
        $zz = $::vars;
45
 
        $zz = @::legal_priority;
46
 
        $zz = @::legal_platform;
47
 
        $zz = @::legal_severity;
48
 
        $zz = @::legal_bug_status;
49
 
        $zz = @::target_milestone;
50
 
        $zz = @::components;
51
 
        $zz = @::legal_keywords;
52
 
        $zz = @::versions;
53
 
        $zz = @::legal_opsys;
54
 
    }
55
 
 
56
 
    # Use templates
57
 
    my $template = $::template;
58
 
    my $vars = $::vars;
59
 
    
60
 
    $vars->{'GetBugLink'} = \&GetBugLink;
61
 
    $vars->{'quoteUrls'} = \&quoteUrls,
62
 
    $vars->{'lsearch'} = \&lsearch,
63
 
    $vars->{'header_done'} = (@_),
64
 
 
65
 
    quietly_check_login();
66
 
 
67
 
    my $id = $::FORM{'id'};
68
 
    
69
 
    if (!defined($id)) {
70
 
      $template->process("bug/choose.html.tmpl", $vars)
71
 
        || ThrowTemplateError($template->error());
72
 
      exit;
73
 
    }
74
 
    
75
 
    my %user = %{$vars->{'user'}};
76
 
    my %bug;
77
 
 
78
 
    # Populate the bug hash with the info we get directly from the DB.
79
 
    my $query = "
80
 
    SELECT bugs.bug_id, product, version, rep_platform, 
81
 
        op_sys, bug_status, resolution, priority, 
82
 
        bug_severity, component, assigned_to, reporter, 
83
 
        bug_file_loc, short_desc, target_milestone, 
84
 
        qa_contact, status_whiteboard, 
85
 
        date_format(creation_ts,'%Y-%m-%d %H:%i'),
86
 
        groupset, delta_ts, ifnull(sum(votes.count),0)
87
 
    FROM bugs LEFT JOIN votes USING(bug_id)
88
 
    WHERE bugs.bug_id = $id
89
 
    GROUP BY bugs.bug_id";
90
 
 
91
 
    SendSQL($query);
92
 
 
93
 
    my $value;
94
 
    my @row = FetchSQLData();
95
 
    foreach my $field ("bug_id", "product", "version", "rep_platform",
96
 
                       "op_sys", "bug_status", "resolution", "priority",
97
 
                       "bug_severity", "component", "assigned_to", "reporter",
98
 
                       "bug_file_loc", "short_desc", "target_milestone",
99
 
                       "qa_contact", "status_whiteboard", "creation_ts",
100
 
                       "groupset", "delta_ts", "votes") 
101
 
    {
102
 
        $value = shift(@row);
103
 
        $bug{$field} = defined($value) ? $value : "";
104
 
    }
105
 
 
106
 
    # General arrays of info about the database state
107
 
    GetVersionTable();
108
 
 
109
 
    # Fiddle the product list.
110
 
    my $seen_curr_prod;
111
 
    my @prodlist;
112
 
    
113
 
    foreach my $product (@::enterable_products) {
114
 
        if ($product eq $bug{'product'}) {
115
 
            # if it's the product the bug is already in, it's ALWAYS in
116
 
            # the popup, period, whether the user can see it or not, and
117
 
            # regardless of the disallownew setting.
118
 
            $seen_curr_prod = 1;
119
 
            push(@prodlist, $product);
120
 
            next;
121
 
        }
122
 
 
123
 
        if (Param("usebuggroupsentry")
124
 
          && GroupExists($product)
125
 
          && !UserInGroup($product))
126
 
        {
127
 
            # If we're using bug groups to restrict entry on products, and
128
 
            # this product has a bug group, and the user is not in that
129
 
            # group, we don't want to include that product in this list.
130
 
            next;
131
 
        }
132
 
 
133
 
        push(@prodlist, $product);
134
 
    }
135
 
 
136
 
    # The current product is part of the popup, even if new bugs are no longer
137
 
    # allowed for that product
138
 
    if (!$seen_curr_prod) {
139
 
        push (@prodlist, $bug{'product'});
140
 
        @prodlist = sort @prodlist;
141
 
    }
142
 
 
143
 
    $vars->{'product'} = \@prodlist;
144
 
    $vars->{'rep_platform'} = \@::legal_platform;
145
 
    $vars->{'priority'} = \@::legal_priority;
146
 
    $vars->{'bug_severity'} = \@::legal_severity;
147
 
    $vars->{'op_sys'} = \@::legal_opsys;
148
 
    $vars->{'bug_status'} = \@::legal_bug_status;
149
 
 
150
 
    # Hack - this array contains "" for some reason. See bug 106589.
151
 
    shift @::settable_resolution; 
152
 
    $vars->{'resolution'} = \@::settable_resolution;
153
 
 
154
 
    $vars->{'component_'} = $::components{$bug{'product'}};
155
 
    $vars->{'version'} = $::versions{$bug{'product'}};
156
 
    $vars->{'target_milestone'} = $::target_milestone{$bug{'product'}};
157
 
    $bug{'milestoneurl'} = $::milestoneurl{$bug{'product'}} || 
158
 
                           "notargetmilestone.html";
159
 
 
160
 
    $vars->{'use_votes'} = Param('usevotes')
161
 
                           && $::prodmaxvotes{$bug{'product'}} > 0;
162
 
 
163
 
    # Add additional, calculated fields to the bug hash
164
 
    if (@::legal_keywords) {
165
 
        $vars->{'use_keywords'} = 1;
166
 
 
167
 
        SendSQL("SELECT keyworddefs.name 
168
 
                 FROM keyworddefs, keywords
169
 
                 WHERE keywords.bug_id = $id 
170
 
                 AND keyworddefs.id = keywords.keywordid
171
 
                 ORDER BY keyworddefs.name");
172
 
        my @keywords;
173
 
        while (MoreSQLData()) {
174
 
            push(@keywords, FetchOneColumn());
175
 
        }
176
 
 
177
 
        $bug{'keywords'} = \@keywords;
178
 
    }    
179
 
 
180
 
    # Attachments
181
 
    $bug{'attachments'} = Attachment::query($id);
182
 
 
183
 
    # Dependencies
184
 
    my @list;
185
 
    SendSQL("SELECT dependson FROM dependencies WHERE  
186
 
             blocked = $id ORDER BY dependson");
187
 
    while (MoreSQLData()) {
188
 
        my ($i) = FetchSQLData();
189
 
        push(@list, $i);
190
 
    }
191
 
 
192
 
    $bug{'dependson'} = \@list;
193
 
 
194
 
    my @list2;
195
 
    SendSQL("SELECT blocked FROM dependencies WHERE  
196
 
             dependson = $id ORDER BY blocked");
197
 
    while (MoreSQLData()) {
198
 
        my ($i) = FetchSQLData();
199
 
        push(@list2, $i);
200
 
    }
201
 
 
202
 
    $bug{'blocked'} = \@list2;
203
 
 
204
 
    # Groups
205
 
    my @groups;
206
 
    if ($::usergroupset ne '0' || $bug{'groupset'} ne '0') {      
207
 
        my $bug_groupset = $bug{'groupset'};
208
 
 
209
 
        SendSQL("SELECT bit, name, description, (bit & $bug_groupset != 0),
210
 
                 (bit & $::usergroupset != 0) FROM groups 
211
 
                 WHERE isbuggroup != 0 " .
212
 
                 # Include active groups as well as inactive groups to which
213
 
                 # the bug already belongs.  This way the bug can be removed
214
 
                 # from an inactive group but can only be added to active ones.
215
 
                "AND ((isactive = 1 AND (bit & $::usergroupset != 0)) OR
216
 
                 (bit & $bug_groupset != 0))");
217
 
 
218
 
        $user{'inallgroups'} = 1;
219
 
 
220
 
        while (MoreSQLData()) {
221
 
            my ($bit, $name, $description, $ison, $ingroup) = FetchSQLData();
222
 
            # For product groups, we only want to display the checkbox if either
223
 
            # (1) The bit is already set, or
224
 
            # (2) The user is in the group, but either:
225
 
            #     (a) The group is a product group for the current product, or
226
 
            #     (b) The group name isn't a product name
227
 
            # This means that all product groups will be skipped, but 
228
 
            # non-product bug groups will still be displayed.
229
 
            if($ison || 
230
 
               ($ingroup && (($name eq $bug{'product'}) ||
231
 
                             (!defined $::proddesc{$name}))))
232
 
            {
233
 
                $user{'inallgroups'} &= $ingroup;
234
 
 
235
 
                push (@groups, { "bit" => $bit,
236
 
                                 "ison" => $ison,
237
 
                                 "ingroup" => $ingroup,
238
 
                                 "description" => $description });            
239
 
            }
240
 
        }
241
 
 
242
 
        # If the bug is restricted to a group, display checkboxes that allow
243
 
        # the user to set whether or not the reporter 
244
 
        # and cc list can see the bug even if they are not members of all 
245
 
        # groups to which the bug is restricted.
246
 
        if ($bug{'groupset'} != 0) {
247
 
            $bug{'inagroup'} = 1;
248
 
 
249
 
            # Determine whether or not the bug is always accessible by the
250
 
            # reporter, QA contact, and/or users on the cc: list.
251
 
            SendSQL("SELECT reporter_accessible, cclist_accessible
252
 
                     FROM   bugs
253
 
                     WHERE  bug_id = $id
254
 
                    ");
255
 
            ($bug{'reporter_accessible'}, 
256
 
             $bug{'cclist_accessible'}) = FetchSQLData();        
257
 
        }
258
 
    }
259
 
    $vars->{'groups'} = \@groups;
260
 
 
261
 
    my $movers = Param("movers");
262
 
    $user{'canmove'} = Param("move-enabled") 
263
 
                       && (defined $::COOKIE{"Bugzilla_login"}) 
264
 
                       && ($::COOKIE{"Bugzilla_login"} =~ /\Q$movers\E/);
265
 
 
266
 
    # User permissions
267
 
 
268
 
    # In the below, if the person hasn't logged in ($::userid == 0), then
269
 
    # we treat them as if they can do anything.  That's because we don't
270
 
    # know why they haven't logged in; it may just be because they don't
271
 
    # use cookies.  Display everything as if they have all the permissions
272
 
    # in the world; their permissions will get checked when they log in
273
 
    # and actually try to make the change.
274
 
    $user{'canedit'} = $::userid == 0
275
 
                       || $::userid == $bug{'reporter'}
276
 
                       || $::userid == $bug{'qa_contact'}
277
 
                       || $::userid == $bug{'assigned_to'}
278
 
                       || UserInGroup("editbugs");
279
 
    $user{'canconfirm'} = ($::userid == 0)
280
 
                          || UserInGroup("canconfirm")
281
 
                          || UserInGroup("editbugs");
282
 
 
283
 
    # Bug states
284
 
    $bug{'isunconfirmed'} = ($bug{'bug_status'} eq $::unconfirmedstate);
285
 
    $bug{'isopened'} = IsOpenedState($bug{'bug_status'});
286
 
 
287
 
    # People involved with the bug
288
 
    $bug{'assigned_to_email'} = DBID_to_name($bug{'assigned_to'});
289
 
    $bug{'assigned_to'} = DBID_to_real_or_loginname($bug{'assigned_to'});
290
 
    $bug{'reporter'} = DBID_to_real_or_loginname($bug{'reporter'});
291
 
    $bug{'qa_contact'} = $bug{'qa_contact'} > 0 ? 
292
 
                                          DBID_to_name($bug{'qa_contact'}) : "";
293
 
 
294
 
    my $ccset = new RelationSet;
295
 
    $ccset->mergeFromDB("SELECT who FROM cc WHERE bug_id=$id");
296
 
    
297
 
    my @cc = $ccset->toArrayOfStrings();
298
 
    $bug{'cc'} = \@cc if $cc[0];
299
 
 
300
 
    # Next bug in list (if there is one)
301
 
    my @bug_list;
302
 
    if ($::COOKIE{"BUGLIST"} && $id) 
303
 
    {
304
 
        @bug_list = split(/:/, $::COOKIE{"BUGLIST"});
305
 
    }
306
 
    $vars->{'bug_list'} = \@bug_list;
307
 
 
308
 
    $bug{'comments'} = GetComments($bug{'bug_id'});
309
 
 
310
 
    # This is length in number of comments
311
 
    $bug{'longdesclength'} = scalar(@{$bug{'comments'}});
312
 
 
313
 
    # Add the bug and user hashes to the variables
314
 
    $vars->{'bug'} = \%bug;
315
 
    $vars->{'user'} = \%user;
316
 
 
317
 
    # Create the <link> elements for browsing bug lists
318
 
    $vars->{'navigation_links'} = navigation_links(join(':',@bug_list));
319
 
 
320
 
    # Generate and return the UI (HTML page) from the appropriate template.
321
 
    $template->process("bug/edit.html.tmpl", $vars)
322
 
      || ThrowTemplateError($template->error());
323
 
}
324
 
 
325
 
1;
326