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 <?php echo phpversion(); ?>)
 	</td>
 	<?php
-		if (phpversion() == '4.0.6') {
+		if ( phpversion() == '4.0.6' ) {
 			print_test_result( GOOD );
 		} else {
 			if ( function_exists ( 'version_compare' ) ) {
@@ -163,10 +163,9 @@
 
 <!-- Check Safe Mode -->
 <?php print_test( 'Checking if safe mode is enabled for install script',
-		! ini_get ( 'SAFE_MODE' ),
+		!ini_get ( 'SAFE_MODE' ),
 		true,
 		'Disable safe_mode in php.ini before proceeding' ) ?>
-
 </table>
 <?php
 	if ( false == $g_failed ) {
@@ -265,6 +264,10 @@
 
 		if ( $t_result ) {
 			print_test_result( GOOD );
+
+			# due to a bug in ADODB, this call prompts warnings, hence the @
+			$t_version_info = @$g_db->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();
 	?>
 </tr>
 
@@ -281,8 +285,6 @@
 	<td bgcolor="#ffffff">
 		Checking Database Server Version
 		<?php
-			# due to a bug in ADODB, this call prompts warnings, hence the @
-			$t_version_info = @$g_db->ServerInfo();
 			echo '<br /> Running ' . $f_db_type . ' version ' . $t_version_info['description'];
 		?>
 	</td>
@@ -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 ' .
 							'<a href="http://dev.mysql.com/doc/mysql/en/password-hashing.html">http://dev.mysql.com/doc/mysql/en/password-hashing.html</a>.';
 					}
@@ -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();
 	?>
 </tr>
-
 <?php
 	}
 	if ( false == $g_failed ) {
@@ -473,16 +476,13 @@
 		<span class="title">Installing Database</span>
 	</td>
 </tr>
-<?php if ( ! $f_log_queries ) { ?>
+<?php if ( !$f_log_queries ) { ?>
 <tr>
 	<td bgcolor="#ffffff">
 		Create database if it does not exist
 	</td>
 	<?php
-		$t_result = @$g_db->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 @@
 		}
 	?>
 </tr>
+<?php
+}
+
+require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'schema.php' );
+
+if ( ($t_db_created || !$f_db_access) && ( $f_admin_username !== $f_db_username) ) {
+?>
+<tr>
+	<td bgcolor="#ffffff">
+		Create database user with privileges
+	</td>
+	<?php
+		$g_db = ADONewConnection($f_db_type);
+		$t_result = @$g_db->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<br />";
+				$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();
+	?>
+</tr>
+<?php
+}
+?>
 <tr>
 	<td bgcolor="#ffffff">
 		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 @@
 	?>
 </tr>
 <?php
-	}
 	# install the tables
 	if ( false == $g_failed ) {
 		$g_db_connected = false; # fake out database access routines used by config_get
 		$GLOBALS['g_db_type'] = $f_db_type; # database_api references this
-		require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'schema.php' );
 		$g_db = ADONewConnection( $f_db_type );
 		$t_result = @$g_db->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 '<tr><td bgcolor="#ffffff" col_span="2"> Database Creation Suppressed, SQL Queries follow <pre>';
 		}
 
-		while ( ( $i <= $lastid ) && ! $g_failed ) {
-			if ( ! $f_log_queries ) {
+		while ( ( $i <= $lastid ) && !$g_failed ) {
+			if ( !$f_log_queries ) {
 				echo '<tr><td bgcolor="#ffffff">Create Schema ( ' . $upgrade[$i][0] . ' on ' . $upgrade[$i][1][0] . ' )</td>';
 			}
 
@@ -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 '</pre></br /><p style="color:red">Your database has not been created yet. Please create the database, then install the tables and data using the information above before proceeding.</td></tr>';
 		}
-
+		$g_db->Close();
 	}
 	if ( false == $g_failed ) {
 		$t_install_state++;
 	} else {
 		$t_install_state--;
 	}
-
 ?>
 </table>
 <?php
@@ -595,6 +691,7 @@
 		<input name="admin_password" type="hidden" value="<?php echo $f_admin_password ?>"></input>
 		<input name="log_queries" type="hidden" value="<?php echo ( $f_log_queries ? 1 : 0 ) ?>"></input>
 		<input name="db_exists" type="hidden" value="<?php echo ( $f_db_exists ? 1 : 0 ) ?>"></input>
+		<input name="db_access" type="hidden" value="<?php echo ( $f_db_access ? 1 : 0 ) ?>"></input>
 <?php
 	# must post <input name="install" type="hidden" value="5"></input>
 	# 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 '<tr><td><pre>' . htmlentities( $t_config ) . '</pre></td></tr></table></tr>';
 	}
 ?>
-
 </table>
-
 <?php
 	if ( false == $g_failed ) {
 		$t_install_state++;
@@ -684,7 +779,7 @@
 <?php print_test( 'Checking for MD5 Crypt() support', 1 === CRYPT_MD5, false, 'password security may be lower than expected' ) ?>
 
 <!-- Checking register_globals are off -->
-<?php print_test( 'Checking for register_globals are off for mantis', ! ini_get_bool( 'register_globals' ), false, 'change php.ini to disable register_globals setting' ) ?>
+<?php print_test( 'Checking for register_globals are off for mantis', !ini_get_bool( 'register_globals' ), false, 'change php.ini to disable register_globals setting' ) ?>
 
 <tr>
 	<td bgcolor="#ffffff">
@@ -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();
 	?>
 </tr>
 </table>
@@ -786,7 +882,7 @@
 } # end install_state == 7
 
 
-if( $g_failed ) {
+if ( $g_failed ) {
 ?>
 <table width="100%" bgcolor="#222222" border="0" cellpadding="10" cellspacing="1">
 <tr>
@@ -808,6 +904,7 @@
 		<input name="log_queries" type="hidden" value="<?php echo ( $f_log_queries ? 1 : 0 ) ?>"></input>
 		<input name="retry" type="submit" value="Retry"></input>
 		<input name="db_exists" type="hidden" value="<?php echo ( $f_db_exists ? 1 : 0 ) ?>"></input>
+		<input name="db_access" type="hidden" value="<?php echo ( $f_db_access ? 1 : 0 ) ?>"></input>
 	</td>
 </tr>
 </table>
@@ -820,3 +917,4 @@
 
 </body>
 </html>
+<?php # vi: set ts=4: ?>
diff --unified --recursive /tmp/mantis-1.0.6/admin/schema.php mantis/admin/schema.php
--- /tmp/mantis-1.0.6/admin/schema.php	2006-02-19 09:42:24.000000000 -0500
+++ mantis/admin/schema.php	2006-12-01 20:36:47.000000000 -0500
@@ -26,7 +26,7 @@
 			  user_id I DEFAULT '0' PRIMARY,
 			  access_reqd I DEFAULT '0',
 			  type I DEFAULT '90',
-			  value XS NOTNULL",
+			  value X NOTNULL",
 Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_config',config_get('mantis_config_table'),'config_id'));
 
@@ -108,9 +108,9 @@
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_bug_text_table'),"
   id 			 I  PRIMARY UNSIGNED NOTNULL AUTOINCREMENT,
-  description 		XS NOTNULL,
-  steps_to_reproduce 	XS NOTNULL,
-  additional_information XS NOTNULL
+  description 		X NOTNULL,
+  steps_to_reproduce 	X NOTNULL,
+  additional_information X NOTNULL
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_bugnote_table'),"
@@ -129,7 +129,7 @@
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_bugnote_text_table'),"
   id 			 I  UNSIGNED NOTNULL PRIMARY AUTOINCREMENT,
-  note 			XS NOTNULL
+  note 			X NOTNULL
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_custom_field_project_table'),"
@@ -174,7 +174,7 @@
   project_id 		 I  NOTNULL DEFAULT '0',
   is_public 		L DEFAULT NULL,
   name 			C(64) NOTNULL DEFAULT \" '' \",
-  filter_string 	XS NOTNULL
+  filter_string 	X NOTNULL
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_news_table'),"
@@ -186,7 +186,7 @@
   view_state 		I2 NOTNULL DEFAULT '10',
   announcement 		L NOTNULL DEFAULT '0',
   headline 		C(64) NOTNULL DEFAULT \" '' \",
-  body 			XS NOTNULL
+  body 			X NOTNULL
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_project_category_table'),"
@@ -222,7 +222,7 @@
   view_state 		I2 NOTNULL DEFAULT '10',
   access_min 		I2 NOTNULL DEFAULT '10',
   file_path 		C(250) NOTNULL DEFAULT \" '' \",
-  description 		XS NOTNULL
+  description 		X NOTNULL
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_project_id',config_get('mantis_project_table'),'id'));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_project_name',config_get('mantis_project_table'),'name',Array('UNIQUE')));
@@ -240,7 +240,7 @@
   project_id 		 I  UNSIGNED NOTNULL DEFAULT '0',
   version 		C(64) NOTNULL DEFAULT \" '' \",
   date_order 		T NOTNULL DEFAULT '1970-01-01 00:00:01',
-  description 		XS NOTNULL,
+  description 		X NOTNULL,
   released 		L NOTNULL DEFAULT '1'
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_project_version',config_get('mantis_project_version_table'),'project_id,version',Array('UNIQUE')));
@@ -265,7 +265,7 @@
 			  type I NOTNULL,
 			  timestamp T NOTNULL,
 			  expiry T,
-			  value XS NOTNULL",
+			  value X NOTNULL",
 Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_user_pref_table'),"
@@ -313,7 +313,7 @@
   platform 		C(32) NOTNULL DEFAULT \" '' \",
   os 			C(32) NOTNULL DEFAULT \" '' \",
   os_build 		C(32) NOTNULL DEFAULT \" '' \",
-  description 		XS NOTNULL
+  description 		X NOTNULL
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_user_table'),"
