on xenial help sign in
Switch to g_get_user_name()
65c54d9Ted Gould
plugins/AccountsService/AccountsService.cpp+2−10
@@ -22,9 +22,7 @@
22#include <QStringList>
22#include <QStringList>
23#include <QDebug>
23#include <QDebug>
24
24
25−#include <unistd.h>
25+#include <glib.h>
26−#include <sys/types.h>
27−#include <pwd.h>
28
26
29#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
27#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
30#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
28#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
@@ -77,12 +75,6 @@ QVariant primaryButtonConverter(const QVariant &value)
77 }
75 }
78}
76}
79
77
80−QString systemUsername ()
81−{
82− auto pw = getpwuid(getuid());
83− return pw->pw_name;
84−}
85−
86AccountsService::AccountsService(QObject* parent, const QString &user)
78AccountsService::AccountsService(QObject* parent, const QString &user)
87 : QObject(parent)
79 : QObject(parent)
88 , m_service(new AccountsServiceDBusAdaptor(this))
80 , m_service(new AccountsServiceDBusAdaptor(this))
@@ -136,7 +128,7 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
136 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
128 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
137 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
129 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
138
130
139− setUser(!user.isEmpty() ? user : systemUsername());
131+ setUser(!user.isEmpty() ? user : QString::fromUtf8(g_get_user_name()));
140}
132}
141
133
142QString 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+2−5
@@ -19,15 +19,12 @@
19#include "SessionBroadcast.h"
19#include "SessionBroadcast.h"
20#include <QDBusConnection>
20#include <QDBusConnection>
21
21
22−#include <unistd.h>
22+#include <glib.h>
23−#include <sys/types.h>
24−#include <pwd.h>
25
23
26SessionBroadcast::SessionBroadcast(QObject* parent)
24SessionBroadcast::SessionBroadcast(QObject* parent)
27 : QObject(parent)
25 : QObject(parent)
28{
26{
29− auto pw = getpwuid(getuid());
27+ m_username = QString::fromUtf8(g_get_user_name());
30− m_username = pw->pw_name;
31
28
32 auto connection = QDBusConnection::SM_BUSNAME();
29 auto connection = QDBusConnection::SM_BUSNAME();
33
30
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+2−5
@@ -18,9 +18,7 @@
18#include "launcheritem.h"
18#include "launcheritem.h"
19#include "AccountsServiceDBusAdaptor.h"
19#include "AccountsServiceDBusAdaptor.h"
20
20
21−#include <unistd.h>
21+#include <glib.h>
22−#include <sys/types.h>
23−#include <pwd.h>
24
22
25#include <QDebug>
23#include <QDebug>
26
24
@@ -28,8 +26,7 @@ ASAdapter::ASAdapter()
28{
26{
29 m_accounts = new AccountsServiceDBusAdaptor();
27 m_accounts = new AccountsServiceDBusAdaptor();
30
28
31− auto pw = getpwuid(getuid());
29+ m_user = QString::fromUtf8(g_get_user_name());
32− m_user = pw->pw_name;
33
30
34 if (m_user.isEmpty()) {
31 if (m_user.isEmpty()) {
35 qWarning() << "username not valid. Account Service integration will not work.";
32 qWarning() << "username not valid. Account Service integration will not work.";
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+2−5
@@ -18,9 +18,7 @@
18
18
19#include <QtTest>
19#include <QtTest>
20
20
21−#include <unistd.h>
21+#include <glib.h>
22−#include <sys/types.h>
23−#include <pwd.h>
24
22
25class GreeterPamTest : public QObject
23class GreeterPamTest : public QObject
26{
24{
@@ -41,8 +39,7 @@ private Q_SLOTS:
41
39
42 void testRapidFireAuthentication()
40 void testRapidFireAuthentication()
43 {
41 {
44− auto pw = getpwuid(getuid());
45− m_greeterpriv->authenticationUser = pw->pw_name;
42+ m_greeterpriv->authenticationUser = QString::fromUtf8(g_get_user_name());
46 for (int i = 0; i < 100; i++) {
43 for (int i = 0; i < 100; i++) {
47 m_greeterpriv->handleAuthenticate();
44 m_greeterpriv->handleAuthenticate();
48 }
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+4−11
@@ -34,9 +34,7 @@
34#include <QDBusMetaType>
34#include <QDBusMetaType>
35#include <QDomDocument>
35#include <QDomDocument>
36
36
37−#include <unistd.h>
37+#include <glib.h>
38−#include <sys/types.h>
39−#include <pwd.h>
40
38
41// This is a mock, specifically to test the LauncherModel
39// This is a mock, specifically to test the LauncherModel
42class MockApp: public unity::shell::application::ApplicationInfoInterface
40class MockApp: public unity::shell::application::ApplicationInfoInterface
@@ -76,11 +74,6 @@ private:
76 bool m_focused;
74 bool m_focused;
77};
75};
78
76
79−QString getUsername () {
80− auto pw = getpwuid(getuid());
81− return pw->pw_name;
82−}
83−
84// This is a mock, specifically to test the LauncherModel
77// This is a mock, specifically to test the LauncherModel
85class MockAppManager: public unity::shell::application::ApplicationManagerInterface
78class MockAppManager: public unity::shell::application::ApplicationManagerInterface
86{
79{
@@ -151,7 +144,7 @@ private:
151
144
152 QList<QVariantMap> getASConfig() {
145 QList<QVariantMap> getASConfig() {
153 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
146 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
154− QDBusReply<QVariant> reply = as->getUserPropertyAsync(getUsername(),
147+ QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString::fromUtf8(g_get_user_name()),
155 "com.canonical.unity.AccountsService",
148 "com.canonical.unity.AccountsService",
156 "LauncherItems");
149 "LauncherItems");
157 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
150 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
@@ -176,7 +169,7 @@ private Q_SLOTS:
176 QStringLiteral("/org/freedesktop/Accounts"),
169 QStringLiteral("/org/freedesktop/Accounts"),
177 QStringLiteral("org.freedesktop.Accounts"));
170 QStringLiteral("org.freedesktop.Accounts"));
178 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
171 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
179− getUsername());
172+ QString::fromUtf8(g_get_user_name()));
180 QVERIFY(addReply.isValid());
173 QVERIFY(addReply.isValid());
181 QCOMPARE(addReply.value(), true);
174 QCOMPARE(addReply.value(), true);
182
175
@@ -202,7 +195,7 @@ private Q_SLOTS:
202 QStringLiteral("/org/freedesktop/Accounts"),
195 QStringLiteral("/org/freedesktop/Accounts"),
203 QStringLiteral("org.freedesktop.Accounts"));
196 QStringLiteral("org.freedesktop.Accounts"));
204 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
197 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
205− getUsername());
198+ QString::fromUtf8(g_get_user_name()));
206 QVERIFY(removeReply.isValid());
199 QVERIFY(removeReply.isValid());
207 QCOMPARE(removeReply.value(), true);
200 QCOMPARE(removeReply.value(), true);
208 }
201 }
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