aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2025-05-30 21:55:44 +0200
committerKate <26026535+provokateurin@users.noreply.github.com>2025-06-10 11:16:28 +0200
commitd11d5b765f24013d36826299fa58bbb36ceda612 (patch)
treec2c001ee8ab910b611d505321fa809fb4b0edbfe
parent9a121269f38f03c3c196c3a2195d5f820afad1ce (diff)
downloadnextcloud-server-feat/core/install-without-admin-user.tar.gz
nextcloud-server-feat/core/install-without-admin-user.zip
feat(core): Add option to disable creating an admin user when installingfeat/core/install-without-admin-user
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r--core/Command/Maintenance/Install.php7
-rw-r--r--lib/private/Setup.php79
2 files changed, 48 insertions, 38 deletions
diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php
index 84fd832e016..48fcb335583 100644
--- a/core/Command/Maintenance/Install.php
+++ b/core/Command/Maintenance/Install.php
@@ -44,6 +44,7 @@ class Install extends Command {
->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'Login to connect to the database')
->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null)
+ ->addOption('disable-admin-user', null, InputOption::VALUE_NONE, 'Disable the creation of an admin user')
->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'Login of the admin account', 'admin')
->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account')
@@ -120,6 +121,7 @@ class Install extends Command {
if ($input->hasParameterOption('--database-pass')) {
$dbPass = (string)$input->getOption('database-pass');
}
+ $disableAdminUser = (bool)$input->getOption('disable-admin-user');
$adminLogin = $input->getOption('admin-user');
$adminPassword = $input->getOption('admin-pass');
$adminEmail = $input->getOption('admin-email');
@@ -142,7 +144,7 @@ class Install extends Command {
}
}
- if (is_null($adminPassword)) {
+ if (!$disableAdminUser && $adminPassword === null) {
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new Question('What is the password you like to use for the admin account <' . $adminLogin . '>?');
@@ -151,7 +153,7 @@ class Install extends Command {
$adminPassword = $helper->ask($input, $output, $question);
}
- if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
+ if (!$disableAdminUser && $adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
}
@@ -161,6 +163,7 @@ class Install extends Command {
'dbpass' => $dbPass,
'dbname' => $dbName,
'dbhost' => $dbHost,
+ 'admindisable' => $disableAdminUser,
'adminlogin' => $adminLogin,
'adminpass' => $adminPassword,
'adminemail' => $adminEmail,
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 44fa582f89c..c8b5060076a 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -304,11 +304,15 @@ class Setup {
$error = [];
$dbType = $options['dbtype'];
- if (empty($options['adminlogin'])) {
- $error[] = $l->t('Set an admin Login.');
- }
- if (empty($options['adminpass'])) {
- $error[] = $l->t('Set an admin password.');
+ $disableAdminUser = (bool)($options['admindisable'] ?? false);
+
+ if (!$disableAdminUser) {
+ if (empty($options['adminlogin'])) {
+ $error[] = $l->t('Set an admin Login.');
+ }
+ if (empty($options['adminpass'])) {
+ $error[] = $l->t('Set an admin password.');
+ }
}
if (empty($options['directory'])) {
$options['directory'] = \OC::$SERVERROOT . '/data';
@@ -318,8 +322,6 @@ class Setup {
$dbType = 'sqlite';
}
- $username = htmlspecialchars_decode($options['adminlogin']);
- $password = htmlspecialchars_decode($options['adminpass']);
$dataDir = htmlspecialchars_decode($options['directory']);
$class = self::$dbSetupClasses[$dbType];
@@ -405,19 +407,22 @@ class Setup {
return $error;
}
- $this->outputDebug($output, 'Create admin account');
-
- // create the admin account and group
$user = null;
- try {
- $user = Server::get(IUserManager::class)->createUser($username, $password);
- if (!$user) {
- $error[] = "Account <$username> could not be created.";
+ if (!$disableAdminUser) {
+ $username = htmlspecialchars_decode($options['adminlogin']);
+ $password = htmlspecialchars_decode($options['adminpass']);
+ $this->outputDebug($output, 'Create admin account');
+
+ try {
+ $user = Server::get(IUserManager::class)->createUser($username, $password);
+ if (!$user) {
+ $error[] = "Account <$username> could not be created.";
+ return $error;
+ }
+ } catch (Exception $exception) {
+ $error[] = $exception->getMessage();
return $error;
}
- } catch (Exception $exception) {
- $error[] = $exception->getMessage();
- return $error;
}
$config = Server::get(IConfig::class);
@@ -432,7 +437,7 @@ class Setup {
}
$group = Server::get(IGroupManager::class)->createGroup('admin');
- if ($group instanceof IGroup) {
+ if ($user !== null && $group instanceof IGroup) {
$group->addUser($user);
}
@@ -464,26 +469,28 @@ class Setup {
$bootstrapCoordinator = Server::get(\OC\AppFramework\Bootstrap\Coordinator::class);
$bootstrapCoordinator->runInitialRegistration();
- // Create a session token for the newly created user
- // The token provider requires a working db, so it's not injected on setup
- /** @var \OC\User\Session $userSession */
- $userSession = Server::get(IUserSession::class);
- $provider = Server::get(PublicKeyTokenProvider::class);
- $userSession->setTokenProvider($provider);
- $userSession->login($username, $password);
- $user = $userSession->getUser();
- if (!$user) {
- $error[] = 'No account found in session.';
- return $error;
- }
- $userSession->createSessionToken($request, $user->getUID(), $username, $password);
+ if (!$disableAdminUser) {
+ // Create a session token for the newly created user
+ // The token provider requires a working db, so it's not injected on setup
+ /** @var \OC\User\Session $userSession */
+ $userSession = Server::get(IUserSession::class);
+ $provider = Server::get(PublicKeyTokenProvider::class);
+ $userSession->setTokenProvider($provider);
+ $userSession->login($username, $password);
+ $user = $userSession->getUser();
+ if (!$user) {
+ $error[] = 'No account found in session.';
+ return $error;
+ }
+ $userSession->createSessionToken($request, $user->getUID(), $username, $password);
- $session = $userSession->getSession();
- $session->set('last-password-confirm', Server::get(ITimeFactory::class)->getTime());
+ $session = $userSession->getSession();
+ $session->set('last-password-confirm', Server::get(ITimeFactory::class)->getTime());
- // Set email for admin
- if (!empty($options['adminemail'])) {
- $user->setSystemEMailAddress($options['adminemail']);
+ // Set email for admin
+ if (!empty($options['adminemail'])) {
+ $user->setSystemEMailAddress($options['adminemail']);
+ }
}
return $error;