From 7743d9008dee8643fd4e5c3b12b880a5c83aaf06 Mon Sep 17 00:00:00 2001 From: Luiz Sardinha Date: Sat, 21 Feb 2026 18:18:07 +0100 Subject: [PATCH] refactor: checking for server config files read permissions upon start --- src/lib/gui/MainWindow.cpp | 17 +++++++++++------ src/lib/gui/core/CoreProcess.cpp | 17 ++++++++++++----- src/lib/gui/core/CoreProcess.h | 2 +- translations/deskflow_es.ts | 28 ++++++++++++++++++++-------- translations/deskflow_it.ts | 28 ++++++++++++++++++++-------- translations/deskflow_ja.ts | 28 ++++++++++++++++++++-------- translations/deskflow_ko.ts | 28 ++++++++++++++++++++-------- translations/deskflow_ru.ts | 28 ++++++++++++++++++++-------- translations/deskflow_zh_CN.ts | 28 ++++++++++++++++++++-------- 9 files changed, 144 insertions(+), 60 deletions(-) diff --git a/src/lib/gui/MainWindow.cpp b/src/lib/gui/MainWindow.cpp index 81d0da3ce..08d9275c1 100644 --- a/src/lib/gui/MainWindow.cpp +++ b/src/lib/gui/MainWindow.cpp @@ -383,12 +383,17 @@ void MainWindow::coreProcessError(CoreProcess::Error error) ); } else if (error == CoreProcess::Error::StartFailed) { show(); - QMessageBox::warning( - this, tr("Core cannot be started"), - tr("The Core executable could not be successfully started, " - "although it does exist. " - "Please check if you have sufficient permissions to run this program.") - ); + auto message = tr("The Core executable could not be started.\n" + "Please check if you have sufficient permissions to run %1.") + .arg(kCoreBinName); + + if (Settings::value(Settings::Core::CoreMode) == Settings::CoreMode::Server) { + const auto mode = + Settings::value(Settings::Server::ExternalConfigFile).toBool() ? tr("read") : tr("read and write"); + message.append(tr("\nAdditionally, check you are able to %1 the server config file: %2") + .arg(mode, Settings::serverConfigFile())); + } + QMessageBox::warning(this, kAppName, message); } } diff --git a/src/lib/gui/core/CoreProcess.cpp b/src/lib/gui/core/CoreProcess.cpp index 6e600c0ee..a52127573 100644 --- a/src/lib/gui/core/CoreProcess.cpp +++ b/src/lib/gui/core/CoreProcess.cpp @@ -330,11 +330,17 @@ void CoreProcess::start(std::optional processModeOption) QStringList args = {coreMode}; if (m_mode == Settings::CoreMode::Server) { - const auto configFilename = persistServerConfig(); + const auto [hasNeededPermissions, configFilename] = persistServerConfig(); if (configFilename.isEmpty()) { qFatal("config file name empty for server args"); return; } + if (!hasNeededPermissions) { + setProcessState(ProcessState::Stopped); + setConnectionState(ConnectionState::Disconnected); + Q_EMIT error(Error::StartFailed); + return; + } qInfo("core config file: %s", qPrintable(configFilename)); } @@ -417,21 +423,22 @@ void CoreProcess::cleanup() } } -QString CoreProcess::persistServerConfig() const +QPair CoreProcess::persistServerConfig() const { if (Settings::value(Settings::Server::ExternalConfig).toBool()) { - return Settings::value(Settings::Server::ExternalConfigFile).toString(); + return {Settings::isServerConfigFileReadable(), Settings::value(Settings::Server::ExternalConfigFile).toString()}; } const auto configFilePath = Settings::defaultValue(Settings::Server::ExternalConfigFile).toString(); QFile configFile(configFilePath); if (!configFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - qFatal("failed to open core config file for write: %s", qPrintable(configFile.fileName())); + qWarning() << "failed to open core config file for write:" << configFilePath; + return {false, configFile.fileName()}; } m_serverConfig.save(configFile); configFile.close(); - return configFile.fileName(); + return {Settings::isServerConfigFileReadable(), configFile.fileName()}; } void CoreProcess::setConnectionState(ConnectionState state) diff --git a/src/lib/gui/core/CoreProcess.h b/src/lib/gui/core/CoreProcess.h index e59743241..71632010f 100644 --- a/src/lib/gui/core/CoreProcess.h +++ b/src/lib/gui/core/CoreProcess.h @@ -101,7 +101,7 @@ private: void startProcessFromDaemon(const QStringList &args); void stopForegroundProcess() const; void stopProcessFromDaemon(); - QString persistServerConfig() const; + QPair persistServerConfig() const; void setConnectionState(ConnectionState state); void setProcessState(ProcessState state); void checkLogLine(const QString &line); diff --git a/translations/deskflow_es.ts b/translations/deskflow_es.ts index 426f85006..166373255 100644 --- a/translations/deskflow_es.ts +++ b/translations/deskflow_es.ts @@ -402,10 +402,6 @@ Do you want to connect to the server? Please enter the hostname or IP address of the other computer. Introduzca el nombre de host o la dirección IP de la otra computadora. - - Core cannot be started - No se puede iniciar el núcleo - Save server configuration as... Guardar la configuración del servidor como... @@ -523,10 +519,6 @@ Nombres válidos: This computer's name: Nombre de esta computadora: - - The Core executable could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. - No se pudo iniciar el archivo ejecutable principal, aunque existe. Compruebe si tiene permisos suficientes para ejecutar este programa. - &Configure Client &Configurar cliente @@ -539,6 +531,26 @@ Nombres válidos: <html>Hostname or IP address of the server computer.<br/>May contain a comma seperated list.</html> <html>Nome host o indirizzo IP del computer server.<br/>Può contenere un elenco separato da virgole.</html> + + read + leer + + + read and write + leer y escribir + + + The Core executable could not be started. +Please check if you have sufficient permissions to run %1. + No se pudo iniciar el ejecutable Core. +Verifique si tiene permisos suficientes para ejecutar %1. + + + +Additionally, check you are able to %1 the server config file: %2 + +Además, verifique que puede %1 el archivo de configuración del servidor: %2 + NewScreenWidget diff --git a/translations/deskflow_it.ts b/translations/deskflow_it.ts index 5546713a1..323886818 100644 --- a/translations/deskflow_it.ts +++ b/translations/deskflow_it.ts @@ -390,10 +390,6 @@ Vuoi connetterti al server? Please enter the hostname or IP address of the other computer. Inserisci l'hostname o l'indirizzo IP dell'altro computer. - - Core cannot be started - Impossibile avviare il core - Save server configuration as... Salva configurazione server come... @@ -523,10 +519,6 @@ Nomi validi: Usa mouse e tastiera di un altro computer (imposta questo computer come client) - - The Core executable could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. - Non è stato possibile avviare correttamente l'eseguibile Core, sebbene esista. Verifica di disporre delle autorizzazioni necessarie per eseguire questo programma. - &Configure Client &Configurare il client @@ -539,6 +531,26 @@ Nomi validi: <html>Hostname or IP address of the server computer.<br/>May contain a comma seperated list.</html> <html>Nome host o indirizzo IP del computer server.<br/>Può contenere un elenco separato da virgole.</html> + + read + leggere + + + read and write + leggere e scrivere + + + The Core executable could not be started. +Please check if you have sufficient permissions to run %1. + Impossibile avviare l'eseguibile Core. +Verifica di avere i permessi sufficienti per eseguire %1. + + + +Additionally, check you are able to %1 the server config file: %2 + +Inoltre, verifica di poter %1 il file di configurazione del server: %2 + NewScreenWidget diff --git a/translations/deskflow_ja.ts b/translations/deskflow_ja.ts index 166d06fb8..ee3832d26 100644 --- a/translations/deskflow_ja.ts +++ b/translations/deskflow_ja.ts @@ -358,10 +358,6 @@ Do you want to connect to the server? Please enter the hostname or IP address of the other computer. 他のコンピューターのIPアドレスかホスト名を入力してください。 - - Core cannot be started - コアが起動できません - Save server configuration as... サーバー設定を保存… @@ -523,10 +519,6 @@ Valid names: Suggested IP: 推奨IPアドレス: - - The Core executable could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. - コア実行ファイルは存在していますが、起動できませんでした。このプログラムを実行するのに十分な権限があることを確認してください。 - &Configure Client クライアント設定 (&C) @@ -539,6 +531,26 @@ Valid names: <html>Hostname or IP address of the server computer.<br/>May contain a comma seperated list.</html> <html>サーバーコンピューターのホスト名または IP アドレス。<br/>カンマ区切りのリストを含めることができます。</html> + + read + 読み取り + + + read and write + 読み書き + + + The Core executable could not be started. +Please check if you have sufficient permissions to run %1. + Coreの実行ファイルを起動できませんでした。 +%1を実行するための十分な権限があるか確認してください。 + + + +Additionally, check you are able to %1 the server config file: %2 + +また、サーバー設定ファイルを%1できることを確認してください: %2 + NewScreenWidget diff --git a/translations/deskflow_ko.ts b/translations/deskflow_ko.ts index a89e4ccd5..1d299c0ee 100644 --- a/translations/deskflow_ko.ts +++ b/translations/deskflow_ko.ts @@ -358,10 +358,6 @@ Do you want to connect to the server? Please enter the hostname or IP address of the other computer. 다른 컴퓨터의 호스트 이름 또는 IP 주소를 입력하세요. - - Core cannot be started - 코어를 시작할 수 없습니다 - Save server configuration as... 서버 설정을 다른 이름으로 저장... @@ -523,10 +519,6 @@ Valid names: Suggested IP: 추천 IP: - - The Core executable could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. - 코어 실행 파일이 존재하지만 정상적으로 시작할 수 없습니다. 이 프로그램을 실행할 권한이 충분한지 확인하세요. - &Configure Client 클라이언트 구성 (&C) @@ -539,6 +531,26 @@ Valid names: <html>Hostname or IP address of the server computer.<br/>May contain a comma seperated list.</html> <html>서버 컴퓨터의 호스트 이름 또는 IP 주소입니다.<br/>목록 요소는 쉼표로 구분됩니다.</html> + + read + 읽기 + + + read and write + 읽기 및 쓰기 + + + The Core executable could not be started. +Please check if you have sufficient permissions to run %1. + Core 실행 파일을 시작할 수 없습니다. +%1을 실행할 수 있는 충분한 권한이 있는지 확인하세요. + + + +Additionally, check you are able to %1 the server config file: %2 + +또한 서버 구성 파일을 %1할 수 있는지 확인하세요: %2 + NewScreenWidget diff --git a/translations/deskflow_ru.ts b/translations/deskflow_ru.ts index 0c0482cc9..ec3369327 100644 --- a/translations/deskflow_ru.ts +++ b/translations/deskflow_ru.ts @@ -358,10 +358,6 @@ Do you want to connect to the server? Please enter the hostname or IP address of the other computer. Пожалуйста, введите имя хоста или IP-адрес другого компьютера. - - Core cannot be started - Не удалось запустить ядро - Save server configuration as... Сохранить конфигурацию сервера как... @@ -523,10 +519,6 @@ Valid names: Suggested IP: Рекомендуемый IP-адрес: - - The Core executable could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. - Не удалось запустить исполняемый файл ядра, хотя он существует. Проверьте наличие прав на запуск программы. - &Configure Client &Настройка клиента @@ -539,6 +531,26 @@ Valid names: <html>Hostname or IP address of the server computer.<br/>May contain a comma seperated list.</html> <html>Имя хоста или IP-адрес серверного компьютера.<br/>Может содержать список, разделенный запятыми.</html> + + read + прочитать + + + read and write + читать и записывать + + + The Core executable could not be started. +Please check if you have sufficient permissions to run %1. + Не удалось запустить исполняемый файл Core. +Проверьте, достаточно ли у вас прав для запуска %1. + + + +Additionally, check you are able to %1 the server config file: %2 + +Также убедитесь, что вы можете %1 файл конфигурации сервера: %2 + NewScreenWidget diff --git a/translations/deskflow_zh_CN.ts b/translations/deskflow_zh_CN.ts index bb8aecdfc..563a61563 100644 --- a/translations/deskflow_zh_CN.ts +++ b/translations/deskflow_zh_CN.ts @@ -358,10 +358,6 @@ Do you want to connect to the server? Please enter the hostname or IP address of the other computer. 请输入另一台计算机的主机名或 IP 地址。 - - Core cannot be started - 核心服务无法启动 - Save server configuration as... 另存服务器配置为... @@ -523,10 +519,6 @@ Valid names: Suggested IP: 建议 IP: - - The Core executable could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. - Core 可执行文件虽然存在,但无法成功启动。请检查您是否拥有运行此程序的足够权限。 - &Configure Client 配置客户端(&C) @@ -539,6 +531,26 @@ Valid names: <html>Hostname or IP address of the server computer.<br/>May contain a comma seperated list.</html> <html>服务器计算机的主机名或 IP 地址。<br/>可以包含以逗号分隔的列表。</html> + + read + 读取 + + + read and write + 读取和写入 + + + The Core executable could not be started. +Please check if you have sufficient permissions to run %1. + 无法启动Core可执行文件。 +请检查您是否有足够的权限来运行%1。 + + + +Additionally, check you are able to %1 the server config file: %2 + +另外,请检查您是否能够%1服务器配置文件:%2 + NewScreenWidget