1
0
mirror of https://github.com/ElvishArtisan/rivendell.git synced 2025-05-09 08:12:43 +02:00

Fixed problems with MySQL user management

This commit is contained in:
Patrick Linstruth 2018-10-08 18:09:45 -07:00
parent a62d13b14b
commit 2e8819dfa8
2 changed files with 47 additions and 5 deletions

@ -35,7 +35,7 @@ CreateDb::CreateDb(QString host,QString database,QString username,QString passwo
db_pass=password; db_pass=password;
} }
bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config) bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *rd_config)
{ {
QString sql; QString sql;
@ -43,7 +43,7 @@ bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
// Open Database // Open Database
// //
if (!db.isOpen()){ if (!db.isOpen()){
db=QSqlDatabase::addDatabase(config->mysqlDriver(),"createDb"); db=QSqlDatabase::addDatabase(rd_config->mysqlDriver(),"createDb");
if(!db.isValid()) { if(!db.isValid()) {
*err_str+= QString(QObject::tr("Couldn't initialize MySql driver!")); *err_str+= QString(QObject::tr("Couldn't initialize MySql driver!"));
return true; return true;
@ -78,8 +78,41 @@ bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
} }
delete q; delete q;
sql=QString().sprintf("grant all on * to %s identified by \"%s\"", //
(const char *)db_user,(const char *)db_pass); // Drop any existing 'rduser'@'%' and 'rduser'@'localhost' users
//
sql=QString().sprintf("drop user '%s'@'%%'",(const char *)rd_config->mysqlUsername());
q=new QSqlQuery(sql,db);
delete q;
sql=QString().sprintf("drop user '%s'@'localhost'",(const char *)rd_config->mysqlUsername());
q=new QSqlQuery(sql,db);
delete q;
sql=QString("flush privileges");
q=new QSqlQuery(sql,db);
delete q;
sql=QString().sprintf("create user '%s'@'%%' identified by \"%s\"",
(const char *)rd_config->mysqlUsername(),(const char *)rd_config->mysqlPassword());
q=new QSqlQuery(sql,db);
if (!q->isActive()) {
*err_str+=QString().sprintf("Could not create user: '%s'@'%%'",(const char *)sql);
return true;
}
delete q;
sql=QString().sprintf("create user '%s'@'localhost' identified by \"%s\"",
(const char *)rd_config->mysqlUsername(),(const char *)rd_config->mysqlPassword());
q=new QSqlQuery(sql,db);
if (!q->isActive()) {
*err_str+=QString().sprintf("Could not create user: '%s'@'localhost'",(const char *)sql);
return true;
}
delete q;
sql=QString().sprintf("grant SELECT, INSERT, UPDATE, DELETE, CREATE, DROP,\
INDEX, ALTER, LOCK TABLES on %s.* to %s",
(const char *)db_name, (const char *)rd_config->mysqlUsername());
q=new QSqlQuery(sql,db); q=new QSqlQuery(sql,db);
if (!q->isActive()) { if (!q->isActive()) {
*err_str+=QString().sprintf("Could not set permissions: %s",(const char *)sql); *err_str+=QString().sprintf("Could not set permissions: %s",(const char *)sql);
@ -87,6 +120,10 @@ bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
} }
delete q; delete q;
sql=QString("flush privileges");
q=new QSqlQuery(sql,db);
delete q;
QProcess rddbmgrProcess(parent); QProcess rddbmgrProcess(parent);
QStringList args; QStringList args;
args << QString("--create"); args << QString("--create");

@ -176,7 +176,6 @@ void MainWidget::updateLabels()
db = new Db(&err_msg,rd_config); db = new Db(&err_msg,rd_config);
if (!db->isOpen()) { if (!db->isOpen()) {
QMessageBox::information(this,tr("Cannot Open Database"),tr("Unable to open database. The connection parameters of the [Mysql] section of rd.conf may be incorrect or you may need to create a new database."));
label_schema->setVisible(false); label_schema->setVisible(false);
db_backup_button->setEnabled(false); db_backup_button->setEnabled(false);
db_restore_button->setEnabled(false); db_restore_button->setEnabled(false);
@ -234,6 +233,8 @@ void MainWidget::createData()
delete db_create; delete db_create;
updateLabels();
startDaemons(); startDaemons();
} }
@ -348,7 +349,9 @@ void MainWidget::resizeEvent(QResizeEvent *e)
void MainWidget::stopDaemons() void MainWidget::stopDaemons()
{ {
if(system("/usr/bin/systemctl status rivendell")==0) { if(system("/usr/bin/systemctl status rivendell")==0) {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
system("/usr/bin/systemctl stop rivendell"); system("/usr/bin/systemctl stop rivendell");
QApplication::restoreOverrideCursor();
db_daemon_start_needed=true; db_daemon_start_needed=true;
} }
} }
@ -357,7 +360,9 @@ void MainWidget::stopDaemons()
void MainWidget::startDaemons() void MainWidget::startDaemons()
{ {
if(db_daemon_start_needed) { if(db_daemon_start_needed) {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
system("/usr/bin/systemctl start rivendell"); system("/usr/bin/systemctl start rivendell");
QApplication::restoreOverrideCursor();
} }
} }