5
$mysql_host $mysql_port
6
$mysql_name $mysql_user $mysql_user_pwd
7
$mysql_root_name $mysql_root_pwd );
9
use Debconf::Client::ConfModule ':all';
13
if ( get('bugzilla/mysql_available') ne 'true' ) {
14
print STDERR "You answer that there is no MySQL server "
15
."suitable to support the bugzilla database. "
16
."This makes bugzilla installation to failed\n";
20
$mysql_host = get('bugzilla/mysql_host');
21
$mysql_port = get('bugzilla/mysql_port');
22
$mysql_name = get('bugzilla/mysql_name');
23
$mysql_user = get('bugzilla/mysql_user');
24
$mysql_user_pwd = get('bugzilla/mysql_user_pwd');
26
my $mysql_need_root = get('bugzilla/mysql_need_root');
28
if ($mysql_need_root eq 'true') {
29
$mysql_root_name = get('bugzilla/mysql_root_name');
30
$mysql_root_pwd = get('bugzilla/mysql_root_pwd');
31
$dsn = "DBI:mysql:;$mysql_host;$mysql_port";
32
$dbh = DBI->connect($dsn, $mysql_root_name, $mysql_root_pwd)
33
or die "Can't connect as admin to the database";
37
$dbh = DBI->connect($dsn, $mysql_root_name, $mysql_root_pwd)
38
or die "Can't connect as admin to the database";
44
reset('bugzilla/mysql_root_pwd');
45
set('bugzilla/mysql_need_root','false');
48
$dsn = "DBI:mysql:$mysql_name;$mysql_host;$mysql_port";
49
$dbh = DBI->connect($dsn, $mysql_user, $mysql_user_pwd)
50
or die "Can't connect to $mysql_name database as $mysql_user";
52
create_profiles_tables();
59
system('/usr/share/bugzilla/lib/checksetup.pl 1>&2') == 0
60
or die "checksetup.pl failed";
62
my $temp="set -e\nset -- @ARGV\n" . << 'EOF';
66
system ($temp) / 256 == 0
67
or die "Problem with debhelper scripts: $!";
69
fix_www_data_perm('/var/lib/bugzilla'); #this should be done by checksetup.pl
70
fix_www_data_perm('/var/cache/bugzilla'); #but I dislike the way this is done.
75
sub alter_localconfig {
76
# TODO: have localconfig rotate
77
# TODO: don't change localconfig if there is no change on it
78
umask 0027; #there is password in localconfig
79
rename ('/etc/bugzilla/localconfig','/etc/bugzilla/localconfig.dpkg.old')
80
or die "Can't rename /etc/bugzilla/localconfig : $!";
81
open (CONFIG_OLD,"</etc/bugzilla/localconfig.dpkg.old")
82
or die "Can't open /etc/bugzilla/localconfig.dpkg.old : $!";
83
open (CONFIG_NEW,">/etc/bugzilla/localconfig")
84
or die "Cant't open /etc/bugzilla/localconfig : $!";
85
while (<CONFIG_OLD>) {
86
s/(\$db_host\s*=\s*)"[^"]*"/$1"$mysql_host"/;
87
s/(\$db_port\s*=\s*)\d+/$1$mysql_port/;
88
s/(\$db_name\s*=\s*)"[^"]*"/$1"$mysql_name"/;
89
s/(\$db_user\s*=\s*)"[^"]*"/$1"$mysql_user"/;
90
s/(\$db_pass\s*=\s*)"[^"]*"/$1"\Q$mysql_user_pwd\E"/;
91
print CONFIG_NEW $_ or die "Can't write in /etc/bugzilla/localconfig : $!" ;
96
my @www_pwent = getpwnam("www-data")
97
or die "Can't find numeric uid/gid of www-data";
98
chown ($www_pwent[2], $www_pwent[3], '/etc/bugzilla/localconfig')
99
or die "Can't change the owner of /etc/bugzilla/localconfig";
102
sub fix_www_data_perm {
104
system(qq{chown -R www-data.www-data $path}) == 0
105
or die "Can't fix owner of files under $path : $!";
106
system(qq{find $path -type f -print0 | xargs -0 chmod 644}) == 0
107
or die "Can't fix $path/* files perm : $!";
108
system(qq{find $path -type d -print0 | xargs -0 chmod 755}) == 0
109
or die "Can't fix $path/* dirs perm : $!";
112
sub create_database {
113
my @databases = $dbh->func('_ListDBs');
114
unless (grep /^$mysql_name$/, @databases) {
115
$dbh->func('createdb', $mysql_name, "$mysql_host:$mysql_port",
116
$mysql_root_name, $mysql_root_pwd, 'admin')
117
or die "Can't create the $mysql_name";
124
if ( $mysql_host eq "localhost" ) {
129
$dbh->do("grant all on $mysql_name.* to $mysql_user\@$fqdn identified by '$mysql_user_pwd'")
130
or die "Can't grant or create $mysql_user user";
133
sub create_profiles_tables {
134
my $sth = $dbh->table_info(undef, undef, undef, "TABLE");
135
my @tables = @{$dbh->selectcol_arrayref($sth, { Columns => [3] })};
136
unless (grep /^profiles$/, @tables) {
137
$dbh->do('create table profiles(
138
userid mediumint not null auto_increment primary key,
139
login_name varchar(255) not null,
140
cryptpassword varchar(64),
141
realname varchar(255),
142
groupset bigint not null,
143
disabledtext mediumtext,
144
mybugslink tinyint not null default 1,
145
blessgroupset bigint not null default 0,
146
emailflags mediumtext,
147
unique(login_name))')
148
or die "Can't create profiles table";
152
sub populate_profiles {
153
my $bugzilla_admin_name = get('bugzilla/bugzilla_admin_name');
154
my $bugzilla_admin_real_name = get('bugzilla/bugzilla_admin_real_name');
155
my $bugzilla_admin_pwd = get('bugzilla/bugzilla_admin_pwd');
158
my $sth = $dbh->prepare(q{select userid
161
or die "Can't prepare login selection";
162
$sth->execute($bugzilla_admin_name)
163
or die "Can't execute login selection";
165
(my $userid) = $sth->fetchrow_array;
169
if ( defined $userid ) {
170
$dbh->do(q{update profiles
173
groupset=0x7fffffffffffffff
176
$bugzilla_admin_real_name,Crypt($bugzilla_admin_pwd),$userid )
177
or die "Can't update bugzilla admin profile";
179
$dbh->do(q{insert into profiles
187
0x7fffffffffffffff)},
189
$bugzilla_admin_name,
190
$bugzilla_admin_real_name,
191
Crypt($bugzilla_admin_pwd))
192
or die "Can't create the bugzilla admin profile";
198
my @saltchars = (0..9, 'A'..'Z', 'a'..'z', '.', '/');
200
for ( my $i=0 ; $i < 8 ; ++$i ) {
201
$salt .= $saltchars[rand(64)];
204
my $cryptedpassword = crypt($password, $salt);
206
return $cryptedpassword;