on xenial help sign in
Switch to g_get_user_name()
commit65c54d9d5261468f479092041df8fa5007ec357b authorTed Gould <ted@gould.cx> dateTue 19 Apr 2016, 15:36 (10 years ago) parent89e5cb4
14 files changed+40−42
plugins/AccountsService/AccountsService.cpp+2−10 plugins/AccountsService/CMakeLists.txt+5 plugins/SessionBroadcast/CMakeLists.txt+5 plugins/SessionBroadcast/SessionBroadcast.cpp+2−5 plugins/Unity/Launcher/CMakeLists.txt+2 plugins/Unity/Launcher/asadapter.cpp+2−5 plugins/Unity/Session/CMakeLists.txt+2 plugins/Unity/Session/dbusunitysessionservice.cpp+4−6 tests/plugins/AccountsService/CMakeLists.txt+5 tests/plugins/IntegratedLightDM/CMakeLists.txt+1 tests/plugins/IntegratedLightDM/pam.cpp+2−5 tests/plugins/Unity/Launcher/CMakeLists.txt+2 tests/plugins/Unity/Launcher/launchermodeltest.cpp+4−11 tests/plugins/Unity/Session/CMakeLists.txt+2
plugins/AccountsService/AccountsService.cpp+2−10
@@ -22,9 +22,7 @@
2222#include <QStringList>
2323#include <QDebug>
2424
25−#include <unistd.h>
26−#include <sys/types.h>
27−#include <pwd.h>
25+#include <glib.h>
2826
2927#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
3028#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
@@ -77,12 +75,6 @@ QVariant primaryButtonConverter(const QVariant &value)
7775 }
7876}
7977
80−QString systemUsername ()
81−{
82− auto pw = getpwuid(getuid());
83− return pw->pw_name;
84−}
85−
8678AccountsService::AccountsService(QObject* parent, const QString &user)
8779 : QObject(parent)
8880 , m_service(new AccountsServiceDBusAdaptor(this))
@@ -136,7 +128,7 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
136128 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
137129 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
138130
139− setUser(!user.isEmpty() ? user : systemUsername());
131+ setUser(!user.isEmpty() ? user : QString::fromUtf8(g_get_user_name()));
140132}
141133
142134QString AccountsService::user() const
plugins/AccountsService/CMakeLists.txt+5
@@ -1,4 +1,5 @@
11add_definitions(-DSM_BUSNAME=systemBus)
2+include_directories(${GLIB_INCLUDE_DIRS})
23
34add_library(AccountsService-qml MODULE
45 AccountsService.cpp
@@ -8,6 +9,10 @@ add_library(AccountsService-qml MODULE
89
910qt5_use_modules(AccountsService-qml DBus Qml)
1011
12+target_link_libraries(AccountsService-qml
13+ ${GLIB_LIBRARIES}
14+ )
15+
1116add_unity8_plugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
1217
1318set(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})
12add_definitions(-DSM_BUSNAME=systemBus)
23
34add_library(SessionBroadcast-qml MODULE
@@ -7,4 +8,8 @@ add_library(SessionBroadcast-qml MODULE
78
89qt5_use_modules(SessionBroadcast-qml DBus Qml)
910
11+target_link_libraries(SessionBroadcast-qml
12+ ${GLIB_LIBRARIES}
13+ )
14+
1015add_unity8_plugin(SessionBroadcast 0.1 SessionBroadcast TARGETS SessionBroadcast-qml)
plugins/SessionBroadcast/SessionBroadcast.cpp+2−5
@@ -19,15 +19,12 @@
1919#include "SessionBroadcast.h"
2020#include <QDBusConnection>
2121
22−#include <unistd.h>
23−#include <sys/types.h>
24−#include <pwd.h>
22+#include <glib.h>
2523
2624SessionBroadcast::SessionBroadcast(QObject* parent)
2725 : QObject(parent)
2826{
29− auto pw = getpwuid(getuid());
30− m_username = pw->pw_name;
27+ m_username = QString::fromUtf8(g_get_user_name());
3128
3229 auto connection = QDBusConnection::SM_BUSNAME();
3330
plugins/Unity/Launcher/CMakeLists.txt+2
@@ -7,6 +7,7 @@ include_directories(
77 ${CMAKE_CURRENT_SOURCE_DIR}
88 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
99 ${GSETTINGS_QT_INCLUDE_DIRS}
10+ ${GLIB_INCLUDE_DIRS}
1011 ${libunity8-private_SOURCE_DIR}
1112)
1213
@@ -34,6 +35,7 @@ add_library(UnityLauncher-qml MODULE
3435target_link_libraries(UnityLauncher-qml
3536 unity8-private
3637 ${GSETTINGS_QT_LDFLAGS}
38+ ${GLIB_LIBRARIES}
3739 )
3840
3941qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
plugins/Unity/Launcher/asadapter.cpp+2−5
@@ -18,9 +18,7 @@
1818#include "launcheritem.h"
1919#include "AccountsServiceDBusAdaptor.h"
2020
21−#include <unistd.h>
22−#include <sys/types.h>
23−#include <pwd.h>
21+#include <glib.h>
2422
2523#include <QDebug>
2624
@@ -28,8 +26,7 @@ ASAdapter::ASAdapter()
2826{
2927 m_accounts = new AccountsServiceDBusAdaptor();
3028
31− auto pw = getpwuid(getuid());
32− m_user = pw->pw_name;
29+ m_user = QString::fromUtf8(g_get_user_name());
3330
3431 if (m_user.isEmpty()) {
3532 qWarning() << "username not valid. Account Service integration will not work.";
plugins/Unity/Session/CMakeLists.txt+2
@@ -2,6 +2,7 @@ include_directories(
22 ${CMAKE_CURRENT_SOURCE_DIR}
33 ${CMAKE_CURRENT_BINARY_DIR}
44 ${GIO_INCLUDE_DIRS}
5+ ${GLIB_INCLUDE_DIRS}
56 ${libunity8-private_SOURCE_DIR}
67)
78
@@ -19,6 +20,7 @@ qt5_use_modules(UnitySession-qml DBus Qml)
1920target_link_libraries(UnitySession-qml
2021 unity8-private
2122 ${GIO_LDFLAGS}
23+ ${GLIB_LIBRARIES}
2224 )
2325
2426# export the qmldir and qmltypes files
plugins/Unity/Session/dbusunitysessionservice.cpp+4−6
@@ -30,6 +30,9 @@
3030#include <QDateTime>
3131#include <QDBusUnixFileDescriptor>
3232
33+// Glib
34+#include <glib.h>
35+
3336#define LOGIN1_SERVICE QStringLiteral("org.freedesktop.login1")
3437#define LOGIN1_PATH QStringLiteral("/org/freedesktop/login1")
3538#define LOGIN1_IFACE QStringLiteral("org.freedesktop.login1.Manager")
@@ -295,12 +298,7 @@ bool DBusUnitySessionService::CanLock() const
295298
296299QString DBusUnitySessionService::UserName() const
297300{
298− struct passwd *p = getpwuid(geteuid());
299− if (p) {
300− return QString::fromUtf8(p->pw_name);
301− }
302−
303− return QString();
301+ return QString::fromUtf8(g_get_user_name());
304302}
305303
306304QString DBusUnitySessionService::RealName() const
tests/plugins/AccountsService/CMakeLists.txt+5
@@ -19,11 +19,16 @@ make_dbus_class(AccountsPrivate com.canonical.unity.AccountsService.Private)
1919make_dbus_class(UscInput com.canonical.Unity.Input)
2020
2121include_directories(
22+ ${GLIB_INCLUDE_DIRS}
2223 ${CMAKE_CURRENT_BINARY_DIR}
2324 ${CMAKE_CURRENT_SOURCE_DIR}
2425 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
2526 )
2627
28+link_libraries(
29+ ${GLIB_LIBRARIES}
30+ )
31+
2732add_definitions(-DSM_BUSNAME=sessionBus)
2833
2934add_executable(mock-server
tests/plugins/IntegratedLightDM/CMakeLists.txt+1
@@ -2,6 +2,7 @@ add_definitions(
22 -DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
33 )
44include_directories(
5+ ${GLIB_INCLUDE_DIRS}
56 ${CMAKE_CURRENT_BINARY_DIR}
67 )
78
tests/plugins/IntegratedLightDM/pam.cpp+2−5
@@ -18,9 +18,7 @@
1818
1919#include <QtTest>
2020
21−#include <unistd.h>
22−#include <sys/types.h>
23−#include <pwd.h>
21+#include <glib.h>
2422
2523class GreeterPamTest : public QObject
2624{
@@ -41,8 +39,7 @@ private Q_SLOTS:
4139
4240 void testRapidFireAuthentication()
4341 {
44− auto pw = getpwuid(getuid());
45− m_greeterpriv->authenticationUser = pw->pw_name;
42+ m_greeterpriv->authenticationUser = QString::fromUtf8(g_get_user_name());
4643 for (int i = 0; i < 100; i++) {
4744 m_greeterpriv->handleAuthenticate();
4845 }
tests/plugins/Unity/Launcher/CMakeLists.txt+2
@@ -7,6 +7,7 @@ include_directories(
77 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
88 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
99 ${GSETTINGS_QT_INCLUDE_DIRS}
10+ ${GLIB_INCLUDE_DIRS}
1011 ${libunity8-private_SOURCE_DIR}
1112 )
1213
@@ -35,6 +36,7 @@ add_executable(launchermodeltestExec
3536target_link_libraries(launchermodeltestExec
3637 unity8-private
3738 ${GSETTINGS_QT_LDFLAGS}
39+ ${GLIB_LIBRARIES}
3840 )
3941add_dependencies(launchermodeltestExec mock-server)
4042qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
tests/plugins/Unity/Launcher/launchermodeltest.cpp+4−11
@@ -34,9 +34,7 @@
3434#include <QDBusMetaType>
3535#include <QDomDocument>
3636
37−#include <unistd.h>
38−#include <sys/types.h>
39−#include <pwd.h>
37+#include <glib.h>
4038
4139// This is a mock, specifically to test the LauncherModel
4240class MockApp: public unity::shell::application::ApplicationInfoInterface
@@ -76,11 +74,6 @@ private:
7674 bool m_focused;
7775};
7876
79−QString getUsername () {
80− auto pw = getpwuid(getuid());
81− return pw->pw_name;
82−}
83−
8477// This is a mock, specifically to test the LauncherModel
8578class MockAppManager: public unity::shell::application::ApplicationManagerInterface
8679{
@@ -151,7 +144,7 @@ private:
151144
152145 QList<QVariantMap> getASConfig() {
153146 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()),
155148 "com.canonical.unity.AccountsService",
156149 "LauncherItems");
157150 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
@@ -176,7 +169,7 @@ private Q_SLOTS:
176169 QStringLiteral("/org/freedesktop/Accounts"),
177170 QStringLiteral("org.freedesktop.Accounts"));
178171 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
179− getUsername());
172+ QString::fromUtf8(g_get_user_name()));
180173 QVERIFY(addReply.isValid());
181174 QCOMPARE(addReply.value(), true);
182175
@@ -202,7 +195,7 @@ private Q_SLOTS:
202195 QStringLiteral("/org/freedesktop/Accounts"),
203196 QStringLiteral("org.freedesktop.Accounts"));
204197 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
205− getUsername());
198+ QString::fromUtf8(g_get_user_name()));
206199 QVERIFY(removeReply.isValid());
207200 QCOMPARE(removeReply.value(), true);
208201 }
tests/plugins/Unity/Session/CMakeLists.txt+2
@@ -2,6 +2,7 @@ include_directories(
22 ${CMAKE_CURRENT_BINARY_DIR}
33 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
44 ${libunity8-private_SOURCE_DIR}
5+ ${GLIB_INCLUDE_DIRS}
56)
67
78add_definitions(-DSM_BUSNAME=sessionBus)
@@ -15,6 +16,7 @@ add_executable(sessionbackendtestExec
1516)
1617target_link_libraries(sessionbackendtestExec
1718 unity8-private
19+ ${GLIB_LIBRARIES}
1820 )
1921qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)
2022