mirror of https://github.com/cutefishos/calamares
Add SetPasswordJob in Users module, hook it all up.
parent
8e3002bfbb
commit
b111027d57
@ -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
|
||||
)
|
||||
|
@ -0,0 +1,68 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <SetPasswordJob.h>
|
||||
|
||||
#include "JobQueue.h"
|
||||
#include "GlobalStorage.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/CalamaresUtilsSystem.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <crypt.h>
|
||||
|
||||
|
||||
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();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SETPASSWORDJOB_H
|
||||
#define SETPASSWORDJOB_H
|
||||
|
||||
#include <Job.h>
|
||||
|
||||
|
||||
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 */
|
Loading…
Reference in New Issue