diff --unified --recursive /tmp/mantis-1.0.6/admin/install.php mantis/admin/install.php
--- /tmp/mantis-1.0.6/admin/install.php 2006-05-05 12:03:24.000000000 -0400
+++ mantis/admin/install.php 2006-12-02 08:25:47.000000000 -0500
@@ -145,7 +145,7 @@
Checking PHP version (your version is )
-
ServerInfo();
+
# check if db exists for the admin
$t_result = @$g_db->Connect($f_hostname, $f_admin_username, $f_admin_password, $f_database_name);
if ( $t_result ) {
@@ -273,6 +276,7 @@
} else {
print_test_result( BAD, true, 'Does administrative user have access to the database? ( ' . db_error_msg() . ' )' );
}
+ $g_db->Close();
?>
@@ -281,8 +285,6 @@
Checking Database Server Version
ServerInfo();
echo ' Running ' . $f_db_type . ' version ' . $t_version_info['description'];
?>
|
@@ -293,7 +295,7 @@
case 'mysql':
case 'mysqli':
if ( function_exists ( 'version_compare' ) ) {
- if ( version_compare ( $t_version_info['version'] , '4.1.0', '>' ) ) {
+ if ( $t_version_info['version'] && version_compare ( $t_version_info['version'] , '4.1.0', '>' ) ) {
$t_warning = 'Please ensure that your installation supports the new password scheme used in MySQL 4.1.0 and later. See ' .
'http://dev.mysql.com/doc/mysql/en/password-hashing.html.';
}
@@ -318,14 +320,15 @@
$g_db = ADONewConnection($f_db_type);
$t_result = @$g_db->Connect($f_hostname, $f_db_username, $f_db_password, $f_database_name);
- if ( $t_result == true ) {
+ if ( $t_result ) {
print_test_result( GOOD );
+ $f_db_access = true;
} else {
print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' . db_error_msg() . ' )' );
}
+ $g_db->Close();
?>
-
Installing Database
-
+
|
Create database if it does not exist
|
Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name );
- $g_db->Close();
-
- if ( $t_result == true ) {
+ if ( $f_db_exists ) {
print_test_result( GOOD );
} else {
// create db
@@ -491,8 +491,9 @@
$dict = NewDataDictionary( $g_db );
$sqlarray = $dict->CreateDatabase( $f_database_name );
$ret = $dict->ExecuteSQLArray( $sqlarray );
- if( $ret == 2) {
+ if ( $ret == 2 ) {
print_test_result( GOOD );
+ $t_db_created = true;
} else {
print_test_result( BAD, true, 'Does administrative user have access to create the database? ( ' . db_error_msg() . ' )' );
$t_install_state--; # db creation failed, allow user to re-enter user/password info
@@ -501,6 +502,102 @@
}
?>
+
+
+ |
+ Create database user with privileges
+ |
+ Connect($f_hostname, $f_admin_username, $f_admin_password);
+
+ if ( $t_result ) {
+ # build list of tables (objects)
+ for ($i = 0; $i < sizeof($upgrade); $i++) {
+ switch ( $upgrade[$i][0] ) {
+ case 'CreateTableSQL':
+ $t_tables[$upgrade[$i][1][0]] = 1;
+ break;
+ case 'DropTableSQL':
+ unset($t_tables[$upgrade[$i][1][0]]);
+ break;
+ case 'RenameTableSQL':
+ unset($t_tables[$upgrade[$i][1][0]]);
+ $t_tables[$upgrade[$i][1][1]] = 1;
+ default:
+ }
+ }
+
+ foreach ( $t_tables as $t_table => $t_ignore ) {
+ if ( $t_tablelist ) {
+ $t_tablelist .= ','.$t_table;
+ } else {
+ $t_tablelist = $t_table;
+ }
+ }
+
+ switch ( $f_db_type ) {
+ case 'mysql':
+ case 'mysqli':
+ $t_sqlarray = Array(
+ 'GRANT ALL PRIVILEGES ON '.$f_database_name.'.* TO '.$f_db_username.'@'.$f_hostname.' IDENTIFIED BY \''.$f_db_password.'\'',
+ 'FLUSH PRIVILEGES'
+ );
+ break;
+ case 'pgsql':
+ $t_sqlarray = Array(
+ 'CREATE USER '.$f_db_username.' WITH PASSWORD \''.$f_db_password.'\'',
+ 'USE '.$f_database_name,
+ 'GRANT ALL ON '.$t_tablelist.' TO '.$f_db_username
+ );
+ break;
+ case 'mssql':
+ $t_sqlarray = Array(
+ 'CREATE LOGIN '.$f_dbusername.' WITH PASSWORD \''.$f_db_password.'\'',
+ 'USE '.$f_database_name,
+ 'CREATE USER '.$f_dbusername.' FOR LOGIN '.$f_dbusername,
+ 'GRANT ALL PRIVILEGES ON '.$t_tablelist.' TO '.$f_dbusername
+ );
+ break;
+ case 'oci8':
+ $t_sqlarray = Array(
+ 'CREATE USER '.$f_dbusername.' IDENTIFIED BY '.$db_password,
+ 'GRANT ALL ON '.$t_tablelist.' TO '.$f_dbusername
+ );
+ break;
+ default:
+ $t_sqlarray = Array();
+ }
+
+ for ($i = 0; $i < sizeof( $t_sqlarray ); $i++) {
+ $t_query = $t_sqlarray[$i];
+echo "$t_query
";
+ $t_result = @$g_db->Execute( $t_query );
+ if ( !$t_result ) {
+ break;
+ } # continue until error
+ }
+
+ if ( $t_result ) {
+ print_test_result( GOOD );
+ } else {
+ print_test_result( BAD, false, 'Administrative user could not grant database access to user ( ' . db_error_msg() . ' )' );
+ }
+ } else {
+ print_test_result( BAD, true, 'Administrative user does not have access to the database ( ' . db_error_msg() . ' )' );
+ }
+ $g_db->Close();
+ ?>
+
+
|
Attempting to connect to database as user
@@ -509,8 +606,10 @@
$g_db = ADONewConnection($f_db_type);
$t_result = @$g_db->Connect($f_hostname, $f_db_username, $f_db_password, $f_database_name);
- if ( $t_result == true ) {
+ if ( $t_result ) {
print_test_result( GOOD );
+ $f_db_access = true;
+ $f_db_exists = true;
} else {
print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' . db_error_msg() . ' )' );
}
@@ -518,15 +617,13 @@
?>
|
Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name );
- if ( ! $f_log_queries ) {
+ if ( !$f_log_queries ) {
$g_db_connected = true; # fake out database access routines used by config_get
}
$t_last_update = config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS );
@@ -536,8 +633,8 @@
echo ' Database Creation Suppressed, SQL Queries follow ';
}
- while ( ( $i <= $lastid ) && ! $g_failed ) {
- if ( ! $f_log_queries ) {
+ while ( ( $i <= $lastid ) && !$g_failed ) {
+ if ( !$f_log_queries ) {
echo '| Create Schema ( ' . $upgrade[$i][0] . ' on ' . $upgrade[$i][1][0] . ' ) | ';
}
@@ -568,14 +665,13 @@
echo 'INSERT INTO mantis_config_table ( value, type, access_reqd, config_id, project_id, user_id ) VALUES (\'' . $lastid . '\', 1, 90, \'database_version\', 20, 0 );' . "\r\n";
echo 'Your database has not been created yet. Please create the database, then install the tables and data using the information above before proceeding. ';
}
-
+ $g_db->Close();
}
if ( false == $g_failed ) {
$t_install_state++;
} else {
$t_install_state--;
}
-
?>
">
+
# rather than the following line
@@ -628,7 +725,7 @@
$t_config_filename = $g_absolute_path . 'config_inc.php';
if ( !file_exists ( $t_config_filename ) ) {
- if ( $fd = @fopen( $t_config_filename, 'x' ) ) {
+ if ( $fd = @fopen( $t_config_filename, 'w' ) ) {
fwrite( $fd, $t_config );
fclose( $fd );
}
@@ -661,9 +758,7 @@
echo '' . htmlentities( $t_config ) . ' | |
';
}
?>
-
-
-
+
|
@@ -694,7 +789,7 @@
$g_db = ADONewConnection($f_db_type);
$t_result = @$g_db->Connect($f_hostname, $f_db_username, $f_db_password, $f_database_name);
- if ( $t_result == true ) {
+ if ( $t_result ) {
print_test_result( GOOD );
} else {
print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' . db_error_msg() . ' )' );
@@ -710,7 +805,7 @@
$t_query = "SELECT COUNT(*) FROM $t_mantis_config_table";
$t_result = @$g_db->Execute( $t_query );
- if ( $t_result != false ) {
+ if ( $t_result ) {
print_test_result( GOOD );
} else {
@@ -726,7 +821,7 @@
$t_query = "INSERT INTO $t_mantis_config_table ( value, type, access_reqd, config_id, project_id, user_id ) VALUES ('test', 1, 90, 'database_test', 20, 0 )";
$t_result = @$g_db->Execute( $t_query );
- if ( $t_result != false ) {
+ if ( $t_result ) {
print_test_result( GOOD );
} else {
@@ -742,7 +837,7 @@
$t_query = "UPDATE $t_mantis_config_table SET value='test_update' WHERE config_id='database_test'";
$t_result = @$g_db->Execute( $t_query );
- if ( $t_result != false ) {
+ if ( $t_result ) {
print_test_result( GOOD );
} else {
@@ -758,12 +853,13 @@
$t_query = "DELETE FROM $t_mantis_config_table WHERE config_id='database_test'";
$t_result = @$g_db->Execute( $t_query );
- if ( $t_result != false ) {
+ if ( $t_result ) {
print_test_result( GOOD );
} else {
print_test_result( BAD, true, 'Database user doesn\'t have DELETE access to the database ( ' . db_error_msg() . ' )' );
}
+ $g_db->Close();
?>
|
@@ -786,7 +882,7 @@
} # end install_state == 7
-if( $g_failed ) {
+if ( $g_failed ) {
?>
@@ -820,3 +917,4 @@