diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index b057244f1..9772279c7 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -1,15 +1,21 @@ include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) + +list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" ) +find_package( Crypt ) + calamares_add_plugin( users TYPE viewmodule EXPORT_MACRO PLUGINDLLEXPORT_PRO CONFIG_FILE module.conf SOURCES CreateUserJob.cpp + SetPasswordJob.cpp UsersViewStep.cpp UsersPage.cpp UI page_usersetup.ui LINK_LIBRARIES calamaresui + ${CRYPT_LIBRARIES} SHARED_LIB ) diff --git a/src/modules/users/SetPasswordJob.cpp b/src/modules/users/SetPasswordJob.cpp new file mode 100644 index 000000000..9ec9500fe --- /dev/null +++ b/src/modules/users/SetPasswordJob.cpp @@ -0,0 +1,68 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include + +#include "JobQueue.h" +#include "GlobalStorage.h" +#include "utils/Logger.h" +#include "utils/CalamaresUtilsSystem.h" + +#include + +#include + + +SetPasswordJob::SetPasswordJob( const QString& userName, const QString& newPassword ) + : Calamares::Job() + , m_userName( userName ) + , m_newPassword( newPassword ) +{ +} + + +QString +SetPasswordJob::prettyName() const +{ + return tr( "Set password for user %1" ).arg( m_userName ); +} + + +Calamares::JobResult +SetPasswordJob::exec() +{ + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + QDir destDir( gs->value( "rootMountPoint" ).toString() ); + if ( !destDir.exists() ) + return Calamares::JobResult::error( tr( "Bad destination system path." ), + tr( "rootMountPoint is %1" ).arg( destDir.absolutePath() ) ); + + QByteArray data = crypt( m_newPassword.toLatin1(), QString( "$6$%1$" ).arg( m_userName ).toLatin1() ); + + int ec = CalamaresUtils::chrootCall( { "usermod", + "-p", + QString::fromLatin1( data ), + m_userName } ); + if ( ec ) + return Calamares::JobResult::error( tr( "Cannot set password for user %1." ) + .arg( m_userName ), + tr( "usermod terminated with error code %1." ) + .arg( ec ) ); + + return Calamares::JobResult::ok(); +} diff --git a/src/modules/users/SetPasswordJob.h b/src/modules/users/SetPasswordJob.h new file mode 100644 index 000000000..be23d39ec --- /dev/null +++ b/src/modules/users/SetPasswordJob.h @@ -0,0 +1,39 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef SETPASSWORDJOB_H +#define SETPASSWORDJOB_H + +#include + + +class SetPasswordJob : public Calamares::Job +{ + Q_OBJECT +public: + SetPasswordJob( const QString& userName, + const QString& newPassword ); + QString prettyName() const override; + Calamares::JobResult exec() override; + +private: + QString m_userName; + QString m_newPassword; +}; + +#endif /* SETPASSWORDJOB_H */ diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 7daa84024..646cde6c6 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -22,6 +22,10 @@ #include "UsersPage.h" #include "ui_page_usersetup.h" +#include "CreateUserJob.h" +#include "SetPasswordJob.h" +#include "JobQueue.h" +#include "GlobalStorage.h" #include #include @@ -70,6 +74,34 @@ UsersPage::isReady() } +QList< Calamares::job_ptr > +UsersPage::createJobs() +{ + QList< Calamares::job_ptr > list; + if ( !isReady() ) + return list; + + Calamares::Job* j; + j = new CreateUserJob( ui->textBoxUsername->text(), + QString(), + ui->checkBoxLoginAuto->isChecked() ); + list.append( Calamares::job_ptr( j ) ); + + j = new SetPasswordJob( ui->textBoxUsername->text(), + ui->textBoxUserPassword->text() ); + list.append( Calamares::job_ptr( j ) ); + + j = new SetPasswordJob( "root", + ui->textBoxRootPassword->text() ); + list.append( Calamares::job_ptr( j ) ); + + Calamares::JobQueue::instance()-> + globalStorage()->insert( "hostname", ui->textBoxHostname->text() ); + + return list; +} + + void UsersPage::onUsernameTextChanged( const QString& textRef ) { diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index bce927015..e25e5266b 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -23,6 +23,8 @@ #ifndef USERSPAGE_H #define USERSPAGE_H +#include "Typedefs.h" + #include namespace Ui { @@ -38,6 +40,8 @@ public: bool isReady(); + QList< Calamares::job_ptr > createJobs(); + protected slots: void onUsernameTextChanged( const QString& ); void onHostnameTextChanged( const QString& ); diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index c4a0ec574..2ed806c9d 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -87,6 +87,15 @@ UsersViewStep::isAtEnd() const QList< Calamares::job_ptr > UsersViewStep::jobs() const { - return QList< Calamares::job_ptr >(); + return m_jobs; +} + + +void +UsersViewStep::onLeave() +{ + m_jobs.clear(); + + m_jobs.append( m_widget->createJobs() ); } diff --git a/src/modules/users/UsersViewStep.h b/src/modules/users/UsersViewStep.h index 28a9f2853..9f3024776 100644 --- a/src/modules/users/UsersViewStep.h +++ b/src/modules/users/UsersViewStep.h @@ -51,8 +51,11 @@ public: QList< Calamares::job_ptr > jobs() const override; + void onLeave() override; + private: UsersPage* m_widget; + QList< Calamares::job_ptr > m_jobs; }; #endif // USERSPAGEPLUGIN_H