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

« back to all changes in this revision

Viewing changes to debian/patches/02_checksetup.dpatch

  • 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
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 02_checksetup.dpatch by  <sukria@sukria.net>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: Change checksetup.pl to fit our needs
 
6
 
 
7
@DPATCH@
 
8
diff -urNad bugzilla-2.18.2/checksetup.pl /tmp/dpep.PEzGnE/bugzilla-2.18.2/checksetup.pl
 
9
--- bugzilla-2.18.2/checksetup.pl       2005-07-10 20:34:58.000000000 +0200
 
10
+++ /tmp/dpep.PEzGnE/bugzilla-2.18.2/checksetup.pl      2005-07-10 20:38:32.000000000 +0200
 
11
@@ -1,4 +1,5 @@
 
12
 #!/usr/bin/perl -w
 
13
+$|=1;
 
14
 # -*- Mode: perl; indent-tabs-mode: nil -*-
 
15
 #
 
16
 # The contents of this file are subject to the Mozilla Public
 
17
@@ -114,10 +115,11 @@
 
18
 #
 
19
 
 
20
 use strict;
 
21
-use lib ".";
 
22
+use lib "/usr/share/bugzilla";
 
23
 
 
24
 use vars qw( $db_name %answer );
 
25
 use Bugzilla::Constants;
 
26
+use constant MAX_PROMPT_CYCLE => 10;
 
27
 
 
28
 my $silent;
 
29
 
 
30
@@ -155,6 +157,26 @@
 
31
     exit 1;
 
32
 }
 
33
 
 
34
+# the Debian way of fixing permissions
 
35
+# Comes from bugzilla.postinst.
 
36
+sub fix_www_data_perm {
 
37
+       my $path = shift;
 
38
+       my $chown_cmd = "chown -R www-data:www-data $path";
 
39
+       my $chmod_file_cmd = "find $path -type f -exec chmod 644 {} \\;";
 
40
+       my $chmod_dir_cmd = "find $path -type d -exec chmod 755 {} \\; ";
 
41
+               
 
42
+       foreach my $cmd ($chown_cmd, $chmod_file_cmd, $chmod_dir_cmd) { 
 
43
+               system($cmd) == 0
 
44
+                       or die "Command `$cmd` failed ($!)";
 
45
+       }
 
46
+}
 
47
+sub fix_pl_scripts_perm
 
48
+{
 
49
+       my $path = shift;
 
50
+       system(qq{find $path -type f -name '*.pl' -print0 | xargs -0 chmod 755}) == 0
 
51
+               or die "Can't fix $path/* .pl perm : $!";
 
52
+}
 
53
+
 
54
 ###########################################################################
 
55
 # Non-interactive override. Pass a filename on the command line which is
 
56
 # a Perl script. This script defines a %answer hash whose names are tags
 
57
@@ -891,7 +913,8 @@
 
58
 unless (-d 'graphs') {
 
59
     print "Creating graphs directory...\n";
 
60
     # permissions for non-webservergroup are fixed later on
 
61
-    mkdir 'graphs', 0770;
 
62
+    mkdir 'graphs', 0775;
 
63
+    `chmod a+r graphs`;
 
64
     # Upgrade data format
 
65
     foreach my $in_file (glob("$datadir/mining/*"))
 
66
     {
 
67
@@ -1017,17 +1040,21 @@
 
68
     }
 
69
 
 
70
   }
 
71
-  if (!-e "Bugzilla/.htaccess") {
 
72
-    print "Creating Bugzilla/.htaccess...\n";
 
73
-    open HTACCESS, '>', 'Bugzilla/.htaccess';
 
74
-    print HTACCESS <<'END';
 
75
-# nothing in this directory is retrievable unless overriden by an .htaccess
 
76
-# in a subdirectory
 
77
-deny from all
 
78
-END
 
79
-    close HTACCESS;
 
80
-    chmod $fileperm, "Bugzilla/.htaccess";
 
81
-  }
 
82
+  
 
83
+  # This has nothing to do with Debian in fact, as Bugzilla Perl modules are 
 
84
+  # in /usr/share/perl5/Bugzilla.
 
85
+  # I then comment out that block.
 
86
+#  if (!-e "Bugzilla/.htaccess") {
 
87
+#    print "Creating Bugzilla/.htaccess...\n";
 
88
+#    open HTACCESS, '>', 'Bugzilla/.htaccess';
 
89
+#    print HTACCESS <<'END';
 
90
+## nothing in this directory is retrievable unless overriden by an .htaccess
 
91
+## in a subdirectory
 
92
+#deny from all
 
93
+#END
 
94
+#    close HTACCESS;
 
95
+#    chmod $fileperm, "Bugzilla/.htaccess";
 
96
+#  }
 
97
   # Even though $datadir may not (and should not) be in the webtree,
 
98
   # we can't know for sure, so create the .htaccess anyeay. Its harmless
 
99
   # if its not accessible...
 
100
@@ -1308,6 +1335,11 @@
 
101
 
 
102
 # fix file (or files - wildcards ok) permissions 
 
103
 sub fixPerms {
 
104
+       
 
105
+    # In Debian, we already have good permissions thanks to postinst
 
106
+    # and we use a simpliest method for that, see fix_www_data_perm()
 
107
+    return;
 
108
+    
 
109
     my ($file_pattern, $owner, $group, $umask, $do_dirs) = @_;
 
110
     my @files = glob($file_pattern);
 
111
     my $execperm = 0777 & ~ $umask;
 
112
@@ -1317,6 +1349,7 @@
 
113
         # do not change permissions on directories here unless $do_dirs is set
 
114
         if (!(-d $file)) {
 
115
             chown $owner, $group, $file;
 
116
+           print "chown $owner, $group, $file;\n";
 
117
             # check if the file is executable.
 
118
             if (isExecutableFile($file)) {
 
119
                 #printf ("Changing $file to %o\n", $execperm);
 
120
@@ -1328,6 +1361,7 @@
 
121
         }
 
122
         elsif ($do_dirs) {
 
123
             chown $owner, $group, $file;
 
124
+           print "chown $owner, $group, $file;\n";
 
125
             if ($file =~ /CVS$/) {
 
126
                 chmod 0700, $file;
 
127
             }
 
128
@@ -1362,14 +1396,14 @@
 
129
         fixPerms($templatedir, $<, $webservergid, 027, 1);
 
130
         fixPerms('css', $<, $webservergid, 027, 1);
 
131
         fixPerms('js', $<, $webservergid, 027, 1);
 
132
-        chmod 0644, 'globals.pl';
 
133
+#        chmod 0644, 'globals.pl';
 
134
         
 
135
         # Don't use fixPerms here, because it won't change perms on the directory
 
136
         # unless its using recursion
 
137
-        chown $<, $webservergid, $datadir;
 
138
-        chmod 0771, $datadir;
 
139
-        chown $<, $webservergid, 'graphs';
 
140
-        chmod 0770, 'graphs';
 
141
+#        chown $<, $webservergid, $datadir;
 
142
+#        chmod 0771, $datadir;
 
143
+#        chown $<, $webservergid, 'graphs';
 
144
+#        chmod 0770, 'graphs';
 
145
     } else {
 
146
         # get current gid from $( list
 
147
         my $gid = (split " ", $()[0];
 
148
@@ -1390,10 +1424,10 @@
 
149
         
 
150
         # Don't use fixPerms here, because it won't change perms on the directory
 
151
         # unless its using recursion
 
152
-        chown $<, $gid, $datadir;
 
153
-        chmod 0777, $datadir;
 
154
-        chown $<, $gid, 'graphs';
 
155
-        chmod 01777, 'graphs';
 
156
+#        chown $<, $gid, $datadir;
 
157
+#        chmod 0777, $datadir;
 
158
+#        chown $<, $gid, 'graphs';
 
159
+#        chmod 01777, 'graphs';
 
160
     }
 
161
 }
 
162
 
 
163
@@ -4238,7 +4272,9 @@
 
164
                     " WHERE name = 'admin' AND id = group_id");
 
165
 $sth->execute;
 
166
 # when we have no admin users, prompt for admin email address and password ...
 
167
-if ($sth->rows == 0) {
 
168
+# if we are in non-interactive mode, process anyway.
 
169
+if ($sth->rows == 0 or defined $answer{'ADMIN_EMAIL'}) {
 
170
+  my $update_only = 1 if $sth->rows > 0;
 
171
   my $login = "";
 
172
   my $realname = "";
 
173
   my $pass1 = "";
 
174
@@ -4263,16 +4299,24 @@
 
175
       and at least one \'.\' after the @.';
 
176
   }
 
177
 
 
178
-  print "\nLooks like we don't have an administrator set up yet.  Either this is your\n";
 
179
-  print "first time using Bugzilla, or your administrator's privileges might have accidently\n";
 
180
-  print "been deleted.\n";
 
181
-  while(! $admin_ok ) {
 
182
-    while( $login eq "" ) {
 
183
-      print "Enter the e-mail address of the administrator: ";
 
184
+  unless ($update_only) {
 
185
+      print "\nLooks like we don't have an administrator set up yet.  Either this is your\n";
 
186
+      print "first time using Bugzilla, or your administrator's privileges might have accidently\n";
 
187
+      print "been deleted.\n";
 
188
+  }
 
189
+
 
190
+  #this is useful when using this script in non-interactive mode.
 
191
+  my $cycle_count = 0;
 
192
+  
 
193
+  while(! $admin_ok  ) {
 
194
+    while( $login eq "") {
 
195
+      print "Enter the e-mail address of the administrator: " 
 
196
+       unless defined $answer{'ADMIN_EMAIL'};
 
197
       $login = $answer{'ADMIN_EMAIL'} 
 
198
           || ($silent && die("cant preload ADMIN_EMAIL")) 
 
199
           || <STDIN>;
 
200
       chomp $login;
 
201
+
 
202
       if(! $login ) {
 
203
         print "\nYou DO want an administrator, don't you?\n";
 
204
       }
 
205
@@ -4284,18 +4328,24 @@
 
206
         # Go round, and ask them again
 
207
         $login = "";
 
208
       }
 
209
+      
 
210
+      die "Failed to get a valid email address: $login\n" if
 
211
+             ($cycle_count++ > MAX_PROMPT_CYCLE);
 
212
     }
 
213
     $login = $dbh->quote($login);
 
214
     $sth = $dbh->prepare("SELECT login_name FROM profiles" .
 
215
                         " WHERE login_name=$login");
 
216
     $sth->execute;
 
217
     if ($sth->rows > 0) {
 
218
-      print "$login already has an account.\n";
 
219
-      print "Make this user the administrator? [Y/n] ";
 
220
+      if (not $answer{'ADMIN_OK'}) {
 
221
+          print "$login already has an account.\n";
 
222
+          print "Make this user the administrator? [Y/n] ";
 
223
+      }
 
224
       my $ok = $answer{'ADMIN_OK'} 
 
225
           || ($silent && die("cant preload ADMIN_OK")) 
 
226
           || <STDIN>;
 
227
       chomp $ok;
 
228
+
 
229
       if ($ok !~ /^n/i) {
 
230
         $admin_ok = 1;
 
231
         $admin_create = 0;
 
232
@@ -4318,17 +4368,21 @@
 
233
     }
 
234
   }
 
235
 
 
236
-  if ($admin_create) {
 
237
 
 
238
+    $cycle_count = 0;
 
239
     while( $realname eq "" ) {
 
240
-      print "Enter the real name of the administrator: ";
 
241
+      print "Enter the real name of the administrator: " 
 
242
+       unless defined $answer{'ADMIN_REALNAME'};
 
243
       $realname = $answer{'ADMIN_REALNAME'} 
 
244
           || ($silent && die("cant preload ADMIN_REALNAME")) 
 
245
           || <STDIN>;
 
246
       chomp $realname;
 
247
+      
 
248
       if(! $realname ) {
 
249
         print "\nReally.  We need a full name.\n";
 
250
       }
 
251
+      die "Failed to get a valid realname: $realname\n" if
 
252
+             ($cycle_count++ > MAX_PROMPT_CYCLE);
 
253
     }
 
254
 
 
255
     # trap a few interrupts so we can fix the echo if we get aborted.
 
256
@@ -4337,17 +4391,23 @@
 
257
     $SIG{QUIT} = \&bailout;
 
258
     $SIG{TERM} = \&bailout;
 
259
 
 
260
-    if ($^O !~ /MSWin32/i) {
 
261
+    # only on interactive mode !
 
262
+    if ((not $answer{'ADMIN_PASSWORD'}) and $^O !~ /MSWin32/i) {
 
263
         system("stty","-echo");  # disable input echoing
 
264
     }
 
265
-
 
266
+    my $interactive = 1;
 
267
+    $interactive = 0 if defined $answer{'ADMIN_PASSWORD'};
 
268
+    
 
269
     while( $pass1 ne $pass2 ) {
 
270
+      $cycle_count = 0;
 
271
       while( $pass1 eq "" || $pass1 !~ /^[[:print:]]{3,16}$/ ) {
 
272
-        print "Enter a password for the administrator account: ";
 
273
+        print "Enter a password for the administrator account: "
 
274
+               unless defined $answer{'ADMIN_PASSWORD'};
 
275
         $pass1 = $answer{'ADMIN_PASSWORD'} 
 
276
             || ($silent && die("cant preload ADMIN_PASSWORD")) 
 
277
             || <STDIN>;
 
278
         chomp $pass1;
 
279
+       
 
280
         if(! $pass1 ) {
 
281
           print "\n\nAn empty password is a security risk. Try again!\n";
 
282
         } elsif ( $pass1 !~ /^.{3,16}$/ ) {
 
283
@@ -4355,8 +4415,13 @@
 
284
         } elsif ( $pass1 !~ /^[[:print:]]{3,16}$/ ) {
 
285
           print "\n\nThe password contains non-printable characters.\n";
 
286
         }
 
287
+        
 
288
+       die "Failed to get a valid password: $pass1\n" if
 
289
+             ($cycle_count++ > MAX_PROMPT_CYCLE);
 
290
       }
 
291
-      print "\nPlease retype the password to verify: ";
 
292
+      print "\nPlease retype the password to verify: " 
 
293
+       if $interactive;
 
294
+       
 
295
       $pass2 = $answer{'ADMIN_PASSWORD'} 
 
296
           || ($silent && die("cant preload ADMIN_PASSWORD")) 
 
297
           || <STDIN>;
 
298
@@ -4371,7 +4436,8 @@
 
299
     # Crypt the administrator's password
 
300
     my $cryptedpassword = Crypt($pass1);
 
301
 
 
302
-    if ($^O !~ /MSWin32/i) {
 
303
+    # Only on interactive mode
 
304
+    if ($interactive and $^O !~ /MSWin32/i) {
 
305
         system("stty","echo"); # re-enable input echoing
 
306
     }
 
307
 
 
308
@@ -4386,9 +4452,26 @@
 
309
     # Set default email flags for the Admin, same as for users
 
310
     my $defaultflagstring = $dbh->quote(Bugzilla::Constants::DEFAULT_EMAIL_SETTINGS);
 
311
 
 
312
-    $dbh->do("INSERT INTO profiles (login_name, realname, cryptpassword, emailflags) " .
 
313
-             "VALUES ($login, $realname, $cryptedpassword, $defaultflagstring)");
 
314
+  if ($admin_create) {
 
315
+    warn "Creating the administrator $login...\n"
 
316
+       if ($answer{'ADMIN_REALNAME'});
 
317
+
 
318
+    unless($dbh->do("INSERT INTO profiles (login_name, realname, cryptpassword, emailflags) " .
 
319
+             "VALUES ($login, $realname, $cryptedpassword, $defaultflagstring)")) {
 
320
+       die "Unable to create the $login profile.";
 
321
+    }
 
322
+  }
 
323
+
 
324
+  # The ADMIN_REALNAME exists already, but we have to update his profile.
 
325
+  else {
 
326
+       warn "Updating the $login account...\n";
 
327
+       unless ($dbh->do("UPDATE profiles SET realname=$realname, cryptpassword=$cryptedpassword ".
 
328
+                "WHERE login_name=$login")) {
 
329
+               die "Unable to update the $login profile.";
 
330
+       }
 
331
   }
 
332
+
 
333
+  unless ($update_only) {
 
334
     # Put the admin in each group if not already    
 
335
     my $query = "select userid from profiles where login_name = $login";    
 
336
     $sth = $dbh->prepare($query); 
 
337
@@ -4405,6 +4488,7 @@
 
338
         (user_id, group_id, isbless, grant_type) 
 
339
         VALUES ($userid, $admingroupid, 1, " . GRANT_DIRECT . ")");
 
340
 
 
341
+
 
342
     # Admins get inherited membership and bless capability for all groups
 
343
     foreach my $group ( @groups ) {
 
344
         $dbh->do("INSERT INTO group_group_map
 
345
@@ -4414,6 +4498,7 @@
 
346
             (member_id, grantor_id, isbless)
 
347
             VALUES ($admingroupid, $group, 1)");
 
348
     }
 
349
+  }
 
350
 
 
351
   print "\n$login is now set up as an administrator account.\n";
 
352
 }
 
353
@@ -4550,5 +4635,17 @@
 
354
 # when test product was created, admin was unknown
 
355
 $dbh->do("UPDATE components SET initialowner = $adminuid WHERE initialowner = 0");
 
356
 
 
357
+# That's deprecated...
 
358
+#
 
359
+# Now fixing the right permissions ala bugzilla.postinst.
 
360
+# Doing this here is better : it will allow user to run 
 
361
+# checksetup.pl by hand without breaking bugzilla.
 
362
+# (closes #200707)
 
363
+# print "Fixing permissions for www-data...\n";
 
364
+fix_www_data_perm('/usr/share/bugzilla');  
 
365
+fix_www_data_perm('/var/cache/bugzilla');
 
366
+fix_www_data_perm('/var/lib/bugzilla');
 
367
+fix_pl_scripts_perm('/usr/share/bugzilla/lib');
 
368
+
 
369
 unlink "$datadir/versioncache";
 
370