on xenial help sign in
Switch to using uid/pwdent for getting username

Approved by: Michael Terry

commit1bf8bc0220f2e373ded223da1aacb4f84192d52e authorTed Gould <ted@gould.cx> dateWed 27 Apr 2016, 15:00 (10 years ago) parent034c32c65c54d9
15 files changed+53−14
plugins/AccountsService/AccountsService.cpp+3−1 plugins/AccountsService/CMakeLists.txt+5 plugins/SessionBroadcast/CMakeLists.txt+5 plugins/SessionBroadcast/SessionBroadcast.cpp+5−1 plugins/SessionBroadcast/SessionBroadcast.h+3 plugins/Unity/Launcher/CMakeLists.txt+2 plugins/Unity/Launcher/asadapter.cpp+6−2 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+3−1 tests/plugins/Unity/Launcher/CMakeLists.txt+2 tests/plugins/Unity/Launcher/launchermodeltest.cpp+5−3 tests/plugins/Unity/Session/CMakeLists.txt+2
plugins/AccountsService/AccountsService.cpp+3−1
@@ -22,6 +22,8 @@
2222#include <QStringList>
2323#include <QDebug>
2424
25+#include <glib.h>
26+
2527#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
2628#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
2729#define IFACE_UBUNTU_INPUT QStringLiteral("com.ubuntu.AccountsService.Input")
@@ -126,7 +128,7 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
126128 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
127129 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
128130
129− setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
131+ setUser(!user.isEmpty() ? user : QString::fromUtf8(g_get_user_name()));
130132}
131133
132134QString 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+5−1
@@ -19,9 +19,13 @@
1919#include "SessionBroadcast.h"
2020#include <QDBusConnection>
2121
22+#include <glib.h>
23+
2224SessionBroadcast::SessionBroadcast(QObject* parent)
2325 : QObject(parent)
2426{
27+ m_username = QString::fromUtf8(g_get_user_name());
28+
2529 auto connection = QDBusConnection::SM_BUSNAME();
2630
2731 connection.connect(QStringLiteral("com.canonical.Unity.Greeter.Broadcast"),
@@ -35,7 +39,7 @@ SessionBroadcast::SessionBroadcast(QObject* parent)
3539void SessionBroadcast::onShowHome(const QString &username)
3640{
3741 // Only listen to requests meant for us
38− if (username == qgetenv("USER")) {
42+ if (username == m_username) {
3943 Q_EMIT showHome();
4044 }
4145}
plugins/SessionBroadcast/SessionBroadcast.h+3
@@ -36,6 +36,9 @@ Q_SIGNALS:
3636
3737private Q_SLOTS:
3838 void onShowHome(const QString &username);
39+
40+private:
41+ QString m_username;
3942};
4043
4144#endif
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+6−2
@@ -18,14 +18,18 @@
1818#include "launcheritem.h"
1919#include "AccountsServiceDBusAdaptor.h"
2020
21+#include <glib.h>
22+
2123#include <QDebug>
2224
2325ASAdapter::ASAdapter()
2426{
2527 m_accounts = new AccountsServiceDBusAdaptor();
26− m_user = qgetenv("USER");
28+
29+ m_user = QString::fromUtf8(g_get_user_name());
30+
2731 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.";
2933 }
3034}
3135
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+3−1
@@ -18,6 +18,8 @@
1818
1919#include <QtTest>
2020
21+#include <glib.h>
22+
2123class GreeterPamTest : public QObject
2224{
2325 Q_OBJECT
@@ -37,7 +39,7 @@ private Q_SLOTS:
3739
3840 void testRapidFireAuthentication()
3941 {
40− m_greeterpriv->authenticationUser = qgetenv("USER");
42+ m_greeterpriv->authenticationUser = QString::fromUtf8(g_get_user_name());
4143 for (int i = 0; i < 100; i++) {
4244 m_greeterpriv->handleAuthenticate();
4345 }
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+5−3
@@ -34,6 +34,8 @@
3434#include <QDBusMetaType>
3535#include <QDomDocument>
3636
37+#include <glib.h>
38+
3739// This is a mock, specifically to test the LauncherModel
3840class MockApp: public unity::shell::application::ApplicationInfoInterface
3941{
@@ -141,7 +143,7 @@ private:
141143
142144 QList<QVariantMap> getASConfig() {
143145 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()),
145147 "com.canonical.unity.AccountsService",
146148 "LauncherItems");
147149 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
@@ -166,7 +168,7 @@ private Q_SLOTS:
166168 QStringLiteral("/org/freedesktop/Accounts"),
167169 QStringLiteral("org.freedesktop.Accounts"));
168170 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
169− QString(qgetenv("USER")));
171+ QString::fromUtf8(g_get_user_name()));
170172 QVERIFY(addReply.isValid());
171173 QCOMPARE(addReply.value(), true);
172174
@@ -192,7 +194,7 @@ private Q_SLOTS:
192194 QStringLiteral("/org/freedesktop/Accounts"),
193195 QStringLiteral("org.freedesktop.Accounts"));
194196 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
195− QString(qgetenv("USER")));
197+ QString::fromUtf8(g_get_user_name()));
196198 QVERIFY(removeReply.isValid());
197199 QCOMPARE(removeReply.value(), true);
198200 }
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