summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hscript/user.cc20
-rw-r--r--ui/qt5/accountpage.cc27
-rw-r--r--ui/qt5/accountpage.hh4
-rw-r--r--util/user.hh36
4 files changed, 62 insertions, 25 deletions
diff --git a/hscript/user.cc b/hscript/user.cc
index 5a1d6cf..eb8813a 100644
--- a/hscript/user.cc
+++ b/hscript/user.cc
@@ -3,7 +3,7 @@
* libhscript, the HorizonScript library for
* Project Horizon
*
- * Copyright (c) 2019-2020 Adélie Linux and contributors. All rights reserved.
+ * Copyright (c) 2019-2024 Adélie Linux and contributors. All rights reserved.
* This code is licensed under the AGPL 3.0 license, as noted in the
* LICENSE-code file in the root directory of this repository.
*
@@ -21,26 +21,10 @@
#include "util/filesystem.hh"
#include "util/net.hh"
#include "util/output.hh"
+#include "util/user.hh"
using namespace Horizon::Keys;
-const static std::set<std::string> system_names = {
- "root", "bin", "daemon", "adm", "lp", "sync", "shutdown", "halt", "mail",
- "news", "uucp", "operator", "man", "postmaster", "cron", "ftp", "sshd",
- "at", "squid", "xfs", "games", "postgres", "cyrus", "vpopmail", "utmp",
- "catchlog", "alias", "qmaild", "qmailp", "qmailq", "qmailr", "qmails",
- "qmaill", "ntp", "smmsp", "guest", "nobody"
-};
-
-const static std::set<std::string> system_groups = {
- "root", "bin", "daemon", "sys", "adm", "tty", "disk", "lp", "mem", "kmem",
- "wheel", "floppy", "mail", "news", "uucp", "man", "cron", "console",
- "audio", "cdrom", "dialout", "ftp", "sshd", "input", "at", "tape", "video",
- "netdev", "readproc", "squid", "xfs", "kvm", "games", "shadow", "postgres",
- "cdrw", "usb", "vpopmail", "users", "catchlog", "ntp", "nofiles", "qmail",
- "qmaill", "smmsp", "locate", "abuild", "utmp", "ping", "nogroup", "nobody"
-};
-
/*
* is_valid_name is from shadow libmisc/chkname.c:
diff --git a/ui/qt5/accountpage.cc b/ui/qt5/accountpage.cc
index f4be6ac..bc0eb2f 100644
--- a/ui/qt5/accountpage.cc
+++ b/ui/qt5/accountpage.cc
@@ -11,12 +11,15 @@
*/
#include "accountpage.hh"
+#include "util/user.hh"
+
#ifdef HAS_INSTALL_ENV
# include "commitpage.hh"
#endif /* HAS_INSTALL_ENV */
#include <algorithm>
#include <QLabel>
+#include <QMessageBox>
#include <QVBoxLayout>
AccountPage::AccountPage(QWidget *parent) : HorizonWizardPage(parent) {
@@ -48,19 +51,35 @@ AccountPage::AccountPage(QWidget *parent) : HorizonWizardPage(parent) {
}
bool AccountPage::isComplete() const {
- return std::all_of(accountWidgets.begin(), accountWidgets.end(),
+ return std::all_of(accountWidgets.cbegin(), accountWidgets.cend(),
[](UserAccountWidget *widget) {
if(widget == nullptr) return true;
return widget->isValid();
});
}
-#ifdef HAS_INSTALL_ENV
bool AccountPage::validatePage() {
+#ifdef HAS_INSTALL_ENV
/* hack to re-initialise page in case the user goes back */
horizonWizard()->removePage(HorizonWizard::Page_Commit);
horizonWizard()->setPage(HorizonWizard::Page_Commit, new CommitPage);
+#endif /* HAS_INSTALL_ENV */
- return true;
+ return std::all_of(accountWidgets.cbegin(), accountWidgets.cend(),
+ [this](const auto &widget) {
+ auto accountText = widget->accountText();
+ if(accountText.isEmpty()) return true;
+
+ auto username = accountText.toStdString();
+ if(system_names.find(username) != system_names.end() ||
+ system_groups.find(username) != system_groups.end()) {
+ QMessageBox::critical(this, tr("Invalid Username"),
+ tr("The username you have chosen (%1) is reserved "
+ "by the system. Choose a different username.")
+ .arg(accountText));
+ return false;
+ }
+
+ return true;
+ });
}
-#endif /* HAS_INSTALL_ENV */
diff --git a/ui/qt5/accountpage.hh b/ui/qt5/accountpage.hh
index 9ca7577..cf1a4ff 100644
--- a/ui/qt5/accountpage.hh
+++ b/ui/qt5/accountpage.hh
@@ -20,11 +20,9 @@
class AccountPage : public HorizonWizardPage {
public:
- AccountPage(QWidget *parent = nullptr);
+ explicit AccountPage(QWidget *parent = nullptr);
bool isComplete() const override;
-#ifdef HAS_INSTALL_ENV
bool validatePage() override;
-#endif
std::array<UserAccountWidget *, 4> accountWidgets;
};
diff --git a/util/user.hh b/util/user.hh
new file mode 100644
index 0000000..dea2ff2
--- /dev/null
+++ b/util/user.hh
@@ -0,0 +1,36 @@
+/*
+ * user.hh - User account constant definitions
+ * util, the utility library for
+ * Project Horizon
+ *
+ * Copyright (c) 2024 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#ifndef HORIZON_USER_HH_
+#define HORIZON_USER_HH_
+
+#include <set>
+#include <string>
+
+const static std::set<std::string> system_names = {
+ "root", "bin", "daemon", "adm", "lp", "sync", "shutdown", "halt", "mail",
+ "news", "uucp", "operator", "man", "postmaster", "cron", "ftp", "sshd",
+ "at", "squid", "xfs", "games", "postgres", "cyrus", "vpopmail", "utmp",
+ "catchlog", "alias", "qmaild", "qmailp", "qmailq", "qmailr", "qmails",
+ "qmaill", "ntp", "smmsp", "guest", "nobody"
+};
+
+const static std::set<std::string> system_groups = {
+ "root", "bin", "daemon", "sys", "adm", "tty", "disk", "lp", "mem", "kmem",
+ "wheel", "floppy", "mail", "news", "uucp", "man", "cron", "console",
+ "audio", "cdrom", "dialout", "ftp", "sshd", "input", "at", "tape", "video",
+ "netdev", "readproc", "squid", "xfs", "kvm", "games", "shadow", "postgres",
+ "cdrw", "usb", "vpopmail", "users", "catchlog", "ntp", "nofiles", "qmail",
+ "qmaill", "smmsp", "locate", "abuild", "utmp", "ping", "nogroup", "nobody"
+};
+
+#endif /* !HORIZON_USER_HH_ */