on xenial help sign in
Switch to using uid/pwdent for getting username
1bf8bc0Ted Gould
plugins/AccountsService/AccountsService.cpp+3−1
@@ -22,6 +22,8 @@
22#include <QStringList>
22#include <QStringList>
23#include <QDebug>
23#include <QDebug>
24
24
25+#include <glib.h>
26+
25#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
27#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
26#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
28#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
27#define IFACE_UBUNTU_INPUT QStringLiteral("com.ubuntu.AccountsService.Input")
29#define IFACE_UBUNTU_INPUT QStringLiteral("com.ubuntu.AccountsService.Input")
@@ -126,7 +128,7 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
126 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
128 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
127 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
129 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
128
130
129− setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
131+ setUser(!user.isEmpty() ? user : QString::fromUtf8(g_get_user_name()));
130}
132}
131
133
132QString AccountsService::user() const
134QString AccountsService::user() const
plugins/AccountsService/CMakeLists.txt+5
@@ -1,4 +1,5 @@
1add_definitions(-DSM_BUSNAME=systemBus)
1add_definitions(-DSM_BUSNAME=systemBus)
2+include_directories(${GLIB_INCLUDE_DIRS})
2
3
3add_library(AccountsService-qml MODULE
4add_library(AccountsService-qml MODULE
4 AccountsService.cpp
5 AccountsService.cpp
@@ -8,6 +9,10 @@ add_library(AccountsService-qml MODULE
8
9
9qt5_use_modules(AccountsService-qml DBus Qml)
10qt5_use_modules(AccountsService-qml DBus Qml)
10
11
12+target_link_libraries(AccountsService-qml
13+ ${GLIB_LIBRARIES}
14+ )
15+
11add_unity8_plugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
16add_unity8_plugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
12
17
13set(DBUS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces")
18set(DBUS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces")
plugins/SessionBroadcast/CMakeLists.txt+5
@@ -1,3 +1,4 @@
1+include_directories(${GLIB_INCLUDE_DIRS})
1add_definitions(-DSM_BUSNAME=systemBus)
2add_definitions(-DSM_BUSNAME=systemBus)
2
3
3add_library(SessionBroadcast-qml MODULE
4add_library(SessionBroadcast-qml MODULE
@@ -7,4 +8,8 @@ add_library(SessionBroadcast-qml MODULE
7
8
8qt5_use_modules(SessionBroadcast-qml DBus Qml)
9qt5_use_modules(SessionBroadcast-qml DBus Qml)
9
10
11+target_link_libraries(SessionBroadcast-qml
12+ ${GLIB_LIBRARIES}
13+ )
14+
10add_unity8_plugin(SessionBroadcast 0.1 SessionBroadcast TARGETS SessionBroadcast-qml)
15add_unity8_plugin(SessionBroadcast 0.1 SessionBroadcast TARGETS SessionBroadcast-qml)
plugins/SessionBroadcast/SessionBroadcast.cpp+5−1
@@ -19,9 +19,13 @@
19#include "SessionBroadcast.h"
19#include "SessionBroadcast.h"
20#include <QDBusConnection>
20#include <QDBusConnection>
21
21
22+#include <glib.h>
23+
22SessionBroadcast::SessionBroadcast(QObject* parent)
24SessionBroadcast::SessionBroadcast(QObject* parent)
23 : QObject(parent)
25 : QObject(parent)
24{
26{
27+ m_username = QString::fromUtf8(g_get_user_name());
28+
25 auto connection = QDBusConnection::SM_BUSNAME();
29 auto connection = QDBusConnection::SM_BUSNAME();
26
30
27 connection.connect(QStringLiteral("com.canonical.Unity.Greeter.Broadcast"),
31 connection.connect(QStringLiteral("com.canonical.Unity.Greeter.Broadcast"),
@@ -35,7 +39,7 @@ SessionBroadcast::SessionBroadcast(QObject* parent)
35void SessionBroadcast::onShowHome(const QString &username)
39void SessionBroadcast::onShowHome(const QString &username)
36{
40{
37 // Only listen to requests meant for us
41 // Only listen to requests meant for us
38− if (username == qgetenv("USER")) {
42+ if (username == m_username) {
39 Q_EMIT showHome();
43 Q_EMIT showHome();
40 }
44 }
41}
45}
plugins/SessionBroadcast/SessionBroadcast.h+3
@@ -36,6 +36,9 @@ Q_SIGNALS:
36
36
37private Q_SLOTS:
37private Q_SLOTS:
38 void onShowHome(const QString &username);
38 void onShowHome(const QString &username);
39+
40+private:
41+ QString m_username;
39};
42};
40
43
41#endif
44#endif
plugins/Unity/Launcher/CMakeLists.txt+2
@@ -7,6 +7,7 @@ include_directories(
7 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${CMAKE_CURRENT_SOURCE_DIR}
8 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
8 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
9 ${GSETTINGS_QT_INCLUDE_DIRS}
9 ${GSETTINGS_QT_INCLUDE_DIRS}
10+ ${GLIB_INCLUDE_DIRS}
10 ${libunity8-private_SOURCE_DIR}
11 ${libunity8-private_SOURCE_DIR}
11)
12)
12
13
@@ -34,6 +35,7 @@ add_library(UnityLauncher-qml MODULE
34target_link_libraries(UnityLauncher-qml
35target_link_libraries(UnityLauncher-qml
35 unity8-private
36 unity8-private
36 ${GSETTINGS_QT_LDFLAGS}
37 ${GSETTINGS_QT_LDFLAGS}
38+ ${GLIB_LIBRARIES}
37 )
39 )
38
40
39qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
41qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
plugins/Unity/Launcher/asadapter.cpp+6−2
@@ -18,14 +18,18 @@
18#include "launcheritem.h"
18#include "launcheritem.h"
19#include "AccountsServiceDBusAdaptor.h"
19#include "AccountsServiceDBusAdaptor.h"
20
20
21+#include <glib.h>
22+
21#include <QDebug>
23#include <QDebug>
22
24
23ASAdapter::ASAdapter()
25ASAdapter::ASAdapter()
24{
26{
25 m_accounts = new AccountsServiceDBusAdaptor();
27 m_accounts = new AccountsServiceDBusAdaptor();
26− m_user = qgetenv("USER");
28+
29+ m_user = QString::fromUtf8(g_get_user_name());
30+
27 if (m_user.isEmpty()) {
31 if (m_user.isEmpty()) {
28− qWarning() << "$USER not valid. Account Service integration will not work.";
32+ qWarning() << "username not valid. Account Service integration will not work.";
29 }
33 }
30}
34}
31
35
plugins/Unity/Session/CMakeLists.txt+2
@@ -2,6 +2,7 @@ include_directories(
2 ${CMAKE_CURRENT_SOURCE_DIR}
2 ${CMAKE_CURRENT_SOURCE_DIR}
3 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_CURRENT_BINARY_DIR}
4 ${GIO_INCLUDE_DIRS}
4 ${GIO_INCLUDE_DIRS}
5+ ${GLIB_INCLUDE_DIRS}
5 ${libunity8-private_SOURCE_DIR}
6 ${libunity8-private_SOURCE_DIR}
6)
7)
7
8
@@ -19,6 +20,7 @@ qt5_use_modules(UnitySession-qml DBus Qml)
19target_link_libraries(UnitySession-qml
20target_link_libraries(UnitySession-qml
20 unity8-private
21 unity8-private
21 ${GIO_LDFLAGS}
22 ${GIO_LDFLAGS}
23+ ${GLIB_LIBRARIES}
22 )
24 )
23
25
24# export the qmldir and qmltypes files
26# export the qmldir and qmltypes files
plugins/Unity/Session/dbusunitysessionservice.cpp+4−6
@@ -30,6 +30,9 @@
30#include <QDateTime>
30#include <QDateTime>
31#include <QDBusUnixFileDescriptor>
31#include <QDBusUnixFileDescriptor>
32
32
33+// Glib
34+#include <glib.h>
35+
33#define LOGIN1_SERVICE QStringLiteral("org.freedesktop.login1")
36#define LOGIN1_SERVICE QStringLiteral("org.freedesktop.login1")
34#define LOGIN1_PATH QStringLiteral("/org/freedesktop/login1")
37#define LOGIN1_PATH QStringLiteral("/org/freedesktop/login1")
35#define LOGIN1_IFACE QStringLiteral("org.freedesktop.login1.Manager")
38#define LOGIN1_IFACE QStringLiteral("org.freedesktop.login1.Manager")
@@ -295,12 +298,7 @@ bool DBusUnitySessionService::CanLock() const
295
298
296QString DBusUnitySessionService::UserName() const
299QString DBusUnitySessionService::UserName() const
297{
300{
298− struct passwd *p = getpwuid(geteuid());
299− if (p) {
300− return QString::fromUtf8(p->pw_name);
301+ return QString::fromUtf8(g_get_user_name());
301− }
302−
303− return QString();
304}
302}
305
303
306QString DBusUnitySessionService::RealName() const
304QString DBusUnitySessionService::RealName() const
tests/plugins/AccountsService/CMakeLists.txt+5
@@ -19,11 +19,16 @@ make_dbus_class(AccountsPrivate com.canonical.unity.AccountsService.Private)
19make_dbus_class(UscInput com.canonical.Unity.Input)
19make_dbus_class(UscInput com.canonical.Unity.Input)
20
20
21include_directories(
21include_directories(
22+ ${GLIB_INCLUDE_DIRS}
22 ${CMAKE_CURRENT_BINARY_DIR}
23 ${CMAKE_CURRENT_BINARY_DIR}
23 ${CMAKE_CURRENT_SOURCE_DIR}
24 ${CMAKE_CURRENT_SOURCE_DIR}
24 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
25 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
25 )
26 )
26
27
28+link_libraries(
29+ ${GLIB_LIBRARIES}
30+ )
31+
27add_definitions(-DSM_BUSNAME=sessionBus)
32add_definitions(-DSM_BUSNAME=sessionBus)
28
33
29add_executable(mock-server
34add_executable(mock-server
tests/plugins/IntegratedLightDM/CMakeLists.txt+1
@@ -2,6 +2,7 @@ add_definitions(
2 -DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
2 -DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
3 )
3 )
4include_directories(
4include_directories(
5+ ${GLIB_INCLUDE_DIRS}
5 ${CMAKE_CURRENT_BINARY_DIR}
6 ${CMAKE_CURRENT_BINARY_DIR}
6 )
7 )
7
8
tests/plugins/IntegratedLightDM/pam.cpp+3−1
@@ -18,6 +18,8 @@
18
18
19#include <QtTest>
19#include <QtTest>
20
20
21+#include <glib.h>
22+
21class GreeterPamTest : public QObject
23class GreeterPamTest : public QObject
22{
24{
23 Q_OBJECT
25 Q_OBJECT
@@ -37,7 +39,7 @@ private Q_SLOTS:
37
39
38 void testRapidFireAuthentication()
40 void testRapidFireAuthentication()
39 {
41 {
40− m_greeterpriv->authenticationUser = qgetenv("USER");
42+ m_greeterpriv->authenticationUser = QString::fromUtf8(g_get_user_name());
41 for (int i = 0; i < 100; i++) {
43 for (int i = 0; i < 100; i++) {
42 m_greeterpriv->handleAuthenticate();
44 m_greeterpriv->handleAuthenticate();
43 }
45 }
tests/plugins/Unity/Launcher/CMakeLists.txt+2
@@ -7,6 +7,7 @@ include_directories(
7 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
7 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
8 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
8 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
9 ${GSETTINGS_QT_INCLUDE_DIRS}
9 ${GSETTINGS_QT_INCLUDE_DIRS}
10+ ${GLIB_INCLUDE_DIRS}
10 ${libunity8-private_SOURCE_DIR}
11 ${libunity8-private_SOURCE_DIR}
11 )
12 )
12
13
@@ -35,6 +36,7 @@ add_executable(launchermodeltestExec
35target_link_libraries(launchermodeltestExec
36target_link_libraries(launchermodeltestExec
36 unity8-private
37 unity8-private
37 ${GSETTINGS_QT_LDFLAGS}
38 ${GSETTINGS_QT_LDFLAGS}
39+ ${GLIB_LIBRARIES}
38 )
40 )
39add_dependencies(launchermodeltestExec mock-server)
41add_dependencies(launchermodeltestExec mock-server)
40qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
42qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
tests/plugins/Unity/Launcher/launchermodeltest.cpp+5−3
@@ -34,6 +34,8 @@
34#include <QDBusMetaType>
34#include <QDBusMetaType>
35#include <QDomDocument>
35#include <QDomDocument>
36
36
37+#include <glib.h>
38+
37// This is a mock, specifically to test the LauncherModel
39// This is a mock, specifically to test the LauncherModel
38class MockApp: public unity::shell::application::ApplicationInfoInterface
40class MockApp: public unity::shell::application::ApplicationInfoInterface
39{
41{
@@ -141,7 +143,7 @@ private:
141
143
142 QList<QVariantMap> getASConfig() {
144 QList<QVariantMap> getASConfig() {
143 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
145 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
144− QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString(qgetenv("USER")),
146+ QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString::fromUtf8(g_get_user_name()),
145 "com.canonical.unity.AccountsService",
147 "com.canonical.unity.AccountsService",
146 "LauncherItems");
148 "LauncherItems");
147 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
149 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
@@ -166,7 +168,7 @@ private Q_SLOTS:
166 QStringLiteral("/org/freedesktop/Accounts"),
168 QStringLiteral("/org/freedesktop/Accounts"),
167 QStringLiteral("org.freedesktop.Accounts"));
169 QStringLiteral("org.freedesktop.Accounts"));
168 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
170 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
169− QString(qgetenv("USER")));
171+ QString::fromUtf8(g_get_user_name()));
170 QVERIFY(addReply.isValid());
172 QVERIFY(addReply.isValid());
171 QCOMPARE(addReply.value(), true);
173 QCOMPARE(addReply.value(), true);
172
174
@@ -192,7 +194,7 @@ private Q_SLOTS:
192 QStringLiteral("/org/freedesktop/Accounts"),
194 QStringLiteral("/org/freedesktop/Accounts"),
193 QStringLiteral("org.freedesktop.Accounts"));
195 QStringLiteral("org.freedesktop.Accounts"));
194 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
196 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
195− QString(qgetenv("USER")));
197+ QString::fromUtf8(g_get_user_name()));
196 QVERIFY(removeReply.isValid());
198 QVERIFY(removeReply.isValid());
197 QCOMPARE(removeReply.value(), true);
199 QCOMPARE(removeReply.value(), true);
198 }
200 }
tests/plugins/Unity/Session/CMakeLists.txt+2
@@ -2,6 +2,7 @@ include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}
2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
3 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
4 ${libunity8-private_SOURCE_DIR}
4 ${libunity8-private_SOURCE_DIR}
5+ ${GLIB_INCLUDE_DIRS}
5)
6)
6
7
7add_definitions(-DSM_BUSNAME=sessionBus)
8add_definitions(-DSM_BUSNAME=sessionBus)
@@ -15,6 +16,7 @@ add_executable(sessionbackendtestExec
15)
16)
16target_link_libraries(sessionbackendtestExec
17target_link_libraries(sessionbackendtestExec
17 unity8-private
18 unity8-private
19+ ${GLIB_LIBRARIES}
18 )
20 )
19qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)
21qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)
20
22