Skip to content

Commit

Permalink
Better error message when missing grant privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jun 5, 2019
1 parent 06e0ec5 commit d3d0ce4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions htdocs/core/db/mysqli.class.php
Expand Up @@ -930,11 +930,17 @@ public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $d
dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
}
}

// Redo with localhost forced (sometimes user is created on %)
$sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost'";
$resql=$this->query($sql);

$sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
$resql=$this->query($sql);
if (! $resql)
{
$this->error = "Connected user not allowed to GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '*****'";
return -1;
}

Expand Down
3 changes: 2 additions & 1 deletion htdocs/install/step1.php
Expand Up @@ -573,6 +573,7 @@

// Create user
$result=$db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);

// Create user bis
if ($databasefortest == 'mysql')
{
Expand Down Expand Up @@ -611,7 +612,7 @@
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
print '</td>';
print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error()."</td></tr>";
print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error().($db->error ? '. '.$db->error : '')."</td></tr>";
}
}

Expand Down

0 comments on commit d3d0ce4

Please sign in to comment.