Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure all file access is done with Sandbox::map()
"All" where it makes sence.
  • Loading branch information
martyone committed Oct 14, 2013
1 parent 9146fb3 commit 0812c21
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions libssu/ssu.cpp
Expand Up @@ -16,6 +16,7 @@
#include <pwd.h>

#include "ssu.h"
#include "sandbox_p.h"
#include "ssulog.h"
#include "ssuvariables.h"
#include "ssucoreconfig.h"
Expand Down Expand Up @@ -474,6 +475,8 @@ void Ssu::storeAuthorizedKeys(QByteArray data){
} else
return;

homePath = Sandbox::map(homePath);

if (dir.exists(homePath + "/.ssh/authorized_keys")){
ssuLog->print(LOG_DEBUG, QString(".ssh/authorized_keys already exists in %1")
.arg(homePath));
Expand Down
5 changes: 3 additions & 2 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -15,6 +15,7 @@ extern "C" {
#include <boardname.h>
}

#include "sandbox_p.h"
#include "ssudeviceinfo.h"
#include "ssucoreconfig.h"
#include "ssulog.h"
Expand Down Expand Up @@ -165,7 +166,7 @@ QString SsuDeviceInfo::deviceModel(){
// check if the device can be identified by testing for a file
foreach (const QString &key, keys){
QString value = boardMappings->value(key).toString();
if (dir.exists(value)){
if (dir.exists(Sandbox::map(value))){
cachedModel = key;
break;
}
Expand Down Expand Up @@ -224,7 +225,7 @@ QString SsuDeviceInfo::deviceModel(){
*/

// check if the device can be identified by a string in /proc/cpuinfo
procCpuinfo.setFileName("/proc/cpuinfo");
procCpuinfo.setFileName(Sandbox::map("/proc/cpuinfo"));
procCpuinfo.open(QIODevice::ReadOnly | QIODevice::Text);
if (procCpuinfo.isOpen()){
QTextStream in(&procCpuinfo);
Expand Down
7 changes: 4 additions & 3 deletions libssu/ssurepomanager.cpp
Expand Up @@ -9,6 +9,7 @@
#include <QRegExp>
#include <QDirIterator>

#include "sandbox_p.h"
#include "ssudeviceinfo.h"
#include "ssurepomanager.h"
#include "ssucoreconfig.h"
Expand Down Expand Up @@ -152,7 +153,7 @@ void SsuRepoManager::update(){
// assume configuration error if there are no device repos, and don't delete
// anything, even in strict mode
if ((deviceMode & Ssu::LenientMode) != Ssu::LenientMode && !repos.isEmpty()){
QDirIterator it(ZYPP_REPO_PATH, QDir::AllEntries|QDir::NoDot|QDir::NoDotDot);
QDirIterator it(Sandbox::map(ZYPP_REPO_PATH), QDir::AllEntries|QDir::NoDot|QDir::NoDotDot);
while (it.hasNext()){
it.next();
if (it.fileName().left(4) != "ssu_"){
Expand All @@ -164,7 +165,7 @@ void SsuRepoManager::update(){

// ... delete all ssu-managed repositories not valid for this device ...
ssuFilters.append("ssu_*");
QDirIterator it(ZYPP_REPO_PATH, ssuFilters);
QDirIterator it(Sandbox::map(ZYPP_REPO_PATH), ssuFilters);
while (it.hasNext()){
QString f = it.next();

Expand All @@ -190,7 +191,7 @@ void SsuRepoManager::update(){
}

QString repoFilePath = QString("%1/ssu_%2_%3.repo")
.arg(ZYPP_REPO_PATH)
.arg(Sandbox::map(ZYPP_REPO_PATH))
.arg(repo)
.arg(rndMode ? "rnd" : "release");

Expand Down
19 changes: 12 additions & 7 deletions ssuurlresolver/ssuurlresolver.cpp
Expand Up @@ -12,6 +12,7 @@
#include <QStringList>
#include <systemd/sd-journal.h>

#include "libssu/sandbox_p.h"
#include "libssu/ssulog.h"

SsuUrlResolver::SsuUrlResolver(): QObject(){
Expand All @@ -30,7 +31,16 @@ void SsuUrlResolver::error(QString message){
QCoreApplication::exit(1);
}

bool SsuUrlResolver::writeCredentials(QString filePath, QString credentialsScope){
bool SsuUrlResolver::writeZyppCredentialsIfNeeded(QString credentialsScope){
QString filePath = Sandbox::map("/etc/zypp/credentials.d/" + credentialsScope);
QFileInfo credentialsFileInfo(filePath);

if (credentialsFileInfo.exists() &&
credentialsFileInfo.lastModified() > ssu.lastCredentialsUpdate()){
// zypp credentials up to date
return true;
}

QFile credentialsFile(filePath);
QPair<QString, QString> credentials = ssu.credentials(credentialsScope);
SsuLog *ssuLog = SsuLog::instance();
Expand Down Expand Up @@ -126,12 +136,7 @@ void SsuUrlResolver::run(){
QString credentialsScope = ssu.credentialsScope(repo, isRnd);
if (!credentialsScope.isEmpty()){
headerList.append(QString("credentials=%1").arg(credentialsScope));

QFileInfo credentialsFileInfo("/etc/zypp/credentials.d/" + credentialsScope);
if (!credentialsFileInfo.exists() ||
credentialsFileInfo.lastModified() <= ssu.lastCredentialsUpdate()){
writeCredentials(credentialsFileInfo.filePath(), credentialsScope);
}
writeZyppCredentialsIfNeeded(credentialsScope);
} else
ssuLog->print(LOG_DEBUG, "Skipping credential update due to missing credentials scope");
}
Expand Down
2 changes: 1 addition & 1 deletion ssuurlresolver/ssuurlresolver.h
Expand Up @@ -55,7 +55,7 @@ class SsuUrlResolver: public QObject {
Ssu ssu;
void error(QString message);
void printJournal(int priority, QString message);
bool writeCredentials(QString filePath, QString credentialsScope);
bool writeZyppCredentialsIfNeeded(QString credentialsScope);

public slots:
void run();
Expand Down

0 comments on commit 0812c21

Please sign in to comment.