Small update to my bundling script for Mac OS X.
[quassel.git] / src / core / core.cpp
index 542d425..18f022b 100644 (file)
@@ -151,11 +151,6 @@ void Core::init() {
     exit(0);
   }
 
-  if(Quassel::isOptionSet("add-user")) {
-    createUser();
-    exit(0);
-  }
-
   if(!_configured) {
     if(!_storageBackends.count()) {
       qWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
@@ -167,6 +162,16 @@ void Core::init() {
     qWarning() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
   }
 
+  if(Quassel::isOptionSet("add-user")) {
+    createUser();
+    exit(0);
+  }
+
+  if(Quassel::isOptionSet("change-userpass")) {
+    changeUserPass(Quassel::optionValue("change-userpass"));
+    exit(0);
+  }
+
   connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
   connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
   if(!startListening()) exit(1); // TODO make this less brutal
@@ -542,6 +547,7 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) {
     clientInfo[socket] = msg; // store for future reference
     reply["MsgType"] = "ClientInitAck";
     SignalProxy::writeDataToDevice(socket, reply);
+    socket->flush(); // ensure that the write cache is flushed before we switch to ssl
 
 #ifdef HAVE_SSL
     // after we told the client that we are ssl capable we switch to ssl mode
@@ -648,6 +654,7 @@ void Core::setupClientSession(QTcpSocket *socket, UserId uid) {
   else sess = createSession(uid);
   // Hand over socket, session then sends state itself
   disconnect(socket, 0, this, 0);
+  socket->flush(); // ensure that the write cache is flushed before we hand over the connection to another thread.
   blocksizes.remove(socket);
   clientInfo.remove(socket);
   if(!sess) {
@@ -663,7 +670,13 @@ void Core::setupInternalClientSession(SignalProxy *proxy) {
     setupCoreForInternalUsage();
   }
 
-  UserId uid = _storage->internalUser();
+  UserId uid;
+  if(_storage) {
+    uid = _storage->internalUser();
+  } else {
+    qWarning() << "Core::setupInternalClientSession(): You're trying to run monolithic Quassel with an unusable Backend! Go fix it!";
+    return;
+  }
 
   // Find or create session for validated user
   SessionThread *sess;
@@ -808,6 +821,44 @@ void Core::createUser() {
   }
 }
 
+void 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;
+  }
+
+  out << "Change password for user: " << username << endl;
+
+  disableStdInEcho();
+  out << "New Password: ";
+  out.flush();
+  QString password = in.readLine().trimmed();
+  out << endl;
+  out << "Repeat Password: ";
+  out.flush();
+  QString password2 = in.readLine().trimmed();
+  out << endl;
+  enableStdInEcho();
+
+  if(password != password2) {
+    qWarning() << "Passwords don't match!";
+    return;
+  }
+  if(password.isEmpty()) {
+    qWarning() << "Password is empty!";
+    return;
+  }
+
+  if(_storage->updateUser(userId, password)) {
+    out << "Password changed successfuly!" << endl;
+  } else {
+    qWarning() << "Failed to change password!";
+  }
+}
+
 AbstractSqlMigrationReader *Core::getMigrationReader(Storage *storage) {
   if(!storage)
     return 0;