/***************************************************************************
- * Copyright (C) 2005-2015 by the Quassel Project *
+ * Copyright (C) 2005-2018 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
}
if (Quassel::isOptionSet("add-user")) {
- createUser();
- exit(0);
+ exit(createUser() ? EXIT_SUCCESS : EXIT_FAILURE);
+
}
if (Quassel::isOptionSet("change-userpass")) {
- changeUserPass(Quassel::optionValue("change-userpass"));
- exit(0);
+ exit(changeUserPass(Quassel::optionValue("change-userpass")) ?
+ EXIT_SUCCESS : EXIT_FAILURE);
}
connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
return false; // trigger setup process
if (storage->setup(settings))
return initStorage(backend, settings, false);
+ return false;
+
// if initialization wasn't successful, we quit to keep from coming up unconfigured
case Storage::NotAvailable:
qCritical() << "FATAL: Selected storage backend is not available:" << backend;
- exit(EXIT_FAILURE);
+ if (!setup)
+ exit(EXIT_FAILURE);
+ return false;
+
case Storage::IsReady:
// delete all other backends
_storageBackends.remove(backend);
}
+bool Core::reloadCerts()
+{
+#ifdef HAVE_SSL
+ SslServer *sslServerv4 = qobject_cast<SslServer *>(&instance()->_server);
+ bool retv4 = sslServerv4->reloadCerts();
+
+ SslServer *sslServerv6 = qobject_cast<SslServer *>(&instance()->_v6server);
+ bool retv6 = sslServerv6->reloadCerts();
+
+ return retv4 && retv6;
+#else
+ // SSL not supported, don't mark configuration reload as failed
+ return true;
+#endif
+}
+
+
bool Core::startListening()
{
// in mono mode we only start a local port if a port is specified in the cli call
SessionThread *session = new SessionThread(uid, restore, this);
_sessions[uid] = session;
session->start();
- connect(session, SIGNAL(passwordChangeRequested(UserId, QString)), _storage, SLOT(updateUser(UserId, QString)));
return session;
}
}
-void Core::createUser()
+bool Core::createUser()
{
QTextStream out(stdout);
QTextStream in(stdin);
if (password != password2) {
qWarning() << "Passwords don't match!";
- return;
+ return false;
}
if (password.isEmpty()) {
qWarning() << "Password is empty!";
- return;
+ return false;
}
if (_configured && _storage->addUser(username, password).isValid()) {
out << "Added user " << username << " successfully!" << endl;
+ return true;
}
else {
qWarning() << "Unable to add user:" << qPrintable(username);
+ return false;
}
}
-void Core::changeUserPass(const QString &username)
+bool Core::changeUserPass(const QString &username)
{
QTextStream out(stdout);
QTextStream in(stdin);
UserId userId = _storage->getUserId(username);
if (!userId.isValid()) {
out << "User " << username << " does not exist." << endl;
- return;
+ return false;
}
out << "Change password for user: " << username << endl;
if (password != password2) {
qWarning() << "Passwords don't match!";
- return;
+ return false;
}
if (password.isEmpty()) {
qWarning() << "Password is empty!";
- return;
+ return false;
}
if (_configured && _storage->updateUser(userId, password)) {
out << "Password changed successfully!" << endl;
+ return true;
}
else {
qWarning() << "Failed to change password!";
+ return false;
}
}
+bool Core::changeUserPassword(UserId userId, const QString &password)
+{
+ if (!isConfigured() || !userId.isValid())
+ return false;
+
+ return instance()->_storage->updateUser(userId, password);
+}
+
+
AbstractSqlMigrationReader *Core::getMigrationReader(Storage *storage)
{
if (!storage)