Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb34557' into 'master'
[libsignon-qt5] Initialize secrets db on start. Fixes JB#34557

See merge request mer-core/libsignon!2
  • Loading branch information
kende committed Nov 8, 2018
2 parents 91ed876 + 8bbfaf4 commit 3ba347c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
12 changes: 12 additions & 0 deletions libsignon/libexec/libexec.pro
@@ -0,0 +1,12 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
TARGET = signon-storage-perm

INCLUDEPATH += ../src ../lib
SOURCES += signon-storage-perm.c

target.path = $${INSTALL_PREFIX}/usr/libexec

INSTALLS += target
44 changes: 44 additions & 0 deletions libsignon/libexec/signon-storage-perm.c
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
#include <error.h>
#include <errno.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/stat.h>

#include <stdbool.h>
#include "signond/signond-common.h"

#define PATH_LEN 256
#define PRIVILEGED_USER "privileged"

int main()
{
char path[PATH_LEN];
// Get user home dir
struct passwd *pwd = getpwuid(getuid());
if (!pwd) {
error(ENOENT, ENOENT, "User id %d not found", getuid());
}
if ((strlen(pwd->pw_dir) + strlen(signonDefaultStoragePath)) > PATH_LEN) {
error(ENAMETOOLONG, ENAMETOOLONG, "File name too long");
}
strcpy(path, pwd->pw_dir);
// Skip the first ~ char
strcat(path, &signonDefaultStoragePath[1]);

// Get privileged user id and group
pwd = getpwnam(PRIVILEGED_USER);
if (!pwd) {
error(ENOENT, ENOENT, "User %s not found", PRIVILEGED_USER);
}

// Set permissions
if (chown(path, pwd->pw_uid, pwd->pw_gid)) {
perror("chown");
}
if (chmod(path, 0770)) {
perror("chmod");
}
return 0;
}
2 changes: 1 addition & 1 deletion libsignon/signon.pro
@@ -1,7 +1,7 @@
include( common-vars.pri )

TEMPLATE = subdirs
SUBDIRS = lib src server tests
SUBDIRS = lib src server tests libexec
src.depends = lib
tests.depends = lib src

Expand Down
11 changes: 11 additions & 0 deletions libsignon/src/signond/signondaemon.cpp
Expand Up @@ -372,6 +372,17 @@ SignonDaemon *SignonDaemon::instance()
qFatal("SignonDaemon requires a QCoreApplication instance to be "
"constructed first");

// Initialize storage
QString path = QString::fromLocal8Bit(signonDefaultStoragePath);
if (path.startsWith(QLatin1Char('~'))) {
path = path.replace(0, 1, QDir::homePath());
}
QDir dir;
dir.mkpath(path);
if (QProcess::execute(QLatin1String("/usr/libexec/signon-storage-perm"))) {
TRACE() << "Storage init failed";
}

TRACE() << "Creating new daemon instance.";
m_instance = new SignonDaemon(app);
return m_instance;
Expand Down
1 change: 1 addition & 0 deletions rpm/libsignon-qt5.spec
Expand Up @@ -38,6 +38,7 @@ Obsoletes: signon
%config %{_sysconfdir}/signond.conf
%{_libdir}/signon/libpasswordplugin.so
%{_oneshotdir}/signon-storage-perm
%attr(4710, root, privileged) %{_libexecdir}/signon-storage-perm

%package -n libsignon-qt5
Summary: Single Sign On Qt library
Expand Down

0 comments on commit 3ba347c

Please sign in to comment.