summaryrefslogtreecommitdiff
path: root/UnityCore
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2016-12-20 16:54:28 +0000
committerAndrea Azzarone <azzaronea@gmail.com>2016-12-20 16:54:28 +0000
commit3c343a0393d50413fc428245dada79a40dccab4c (patch)
treecca3d2d852780e7ede814ee8cace36b27d7494c1 /UnityCore
parentc9ea395d1e6218fbd709fa32256a03b3905efafc (diff)
parent7a89ba2107a2f3ea02536aaac3dc63ab9201c4e1 (diff)
Merge with trunk.
(bzr r4213.2.1)
Diffstat (limited to 'UnityCore')
-rw-r--r--UnityCore/GnomeSessionManager.cpp50
-rw-r--r--UnityCore/GnomeSessionManager.h1
-rw-r--r--UnityCore/GnomeSessionManagerImpl.h1
-rw-r--r--UnityCore/SessionManager.h1
-rw-r--r--UnityCore/Variant.cpp5
5 files changed, 58 insertions, 0 deletions
diff --git a/UnityCore/GnomeSessionManager.cpp b/UnityCore/GnomeSessionManager.cpp
index 9fb1eb98c..b739b3663 100644
--- a/UnityCore/GnomeSessionManager.cpp
+++ b/UnityCore/GnomeSessionManager.cpp
@@ -575,13 +575,58 @@ bool GnomeManager::Impl::IsUserInGroup(std::string const& user_name, std::string
auto group = getgrnam(group_name.c_str());
if (group && group->gr_mem)
+ {
for (int i = 0; group->gr_mem[i]; ++i)
+ {
if (g_strcmp0(group->gr_mem[i], user_name.c_str()) == 0)
return true;
+ }
+ }
return false;
}
+bool GnomeManager::Impl::GetAutomaticLogin()
+{
+ auto proxy = std::make_shared<glib::DBusProxy>("org.freedesktop.Accounts",
+ "/org/freedesktop/Accounts",
+ "org.freedesktop.Accounts",
+ G_BUS_TYPE_SYSTEM);
+
+ glib::Error error;
+ glib::Object<GDBusConnection> bus(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
+
+ if (error)
+ {
+ LOG_ERROR(logger) << "Impossible to get the system bus, to know if auto-login is enabled: " << error;
+ return false;
+ }
+
+ glib::Variant user_path(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
+ "/org/freedesktop/Accounts", "org.freedesktop.Accounts",
+ "FindUserByName", g_variant_new("(s)",g_get_user_name()), nullptr,
+ G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
+
+ if (error)
+ {
+ LOG_ERROR(logger) << "Impossible to get the user path: " << error;
+ return false;
+ }
+
+ glib::Variant autologin(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
+ user_path.GetString().c_str(), "org.freedesktop.DBus.Properties",
+ "Get", g_variant_new("(ss)", "org.freedesktop.Accounts.User", "AutomaticLogin"), nullptr,
+ G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
+
+ if (error)
+ {
+ LOG_ERROR(logger) << "Impossible to get the AutomaticLogin property: " << error;
+ return false;
+ }
+
+ return autologin.GetBool();
+}
+
// Public implementation
GnomeManager::GnomeManager()
@@ -620,6 +665,11 @@ void GnomeManager::UserIconFile(std::function<void(std::string const&)> const& c
impl_->UserIconFile(callback);
}
+bool GnomeManager::GetAutomaticLogin() const
+{
+ return impl_->GetAutomaticLogin();
+}
+
void GnomeManager::ScreenSaverActivate()
{
screensaver_requested.emit(true);
diff --git a/UnityCore/GnomeSessionManager.h b/UnityCore/GnomeSessionManager.h
index c0894b087..a9e9d82eb 100644
--- a/UnityCore/GnomeSessionManager.h
+++ b/UnityCore/GnomeSessionManager.h
@@ -37,6 +37,7 @@ public:
std::string UserName() const;
std::string HostName() const;
void UserIconFile(std::function<void(std::string const&)> const&) const;
+ bool GetAutomaticLogin() const;
void ScreenSaverActivate();
void ScreenSaverDeactivate();
diff --git a/UnityCore/GnomeSessionManagerImpl.h b/UnityCore/GnomeSessionManagerImpl.h
index f3904e7eb..2cef5ad41 100644
--- a/UnityCore/GnomeSessionManagerImpl.h
+++ b/UnityCore/GnomeSessionManagerImpl.h
@@ -69,6 +69,7 @@ struct GnomeManager::Impl
void UpdateHaveOtherOpenSessions();
bool IsUserInGroup(std::string const& user_name, std::string const& group_name);
+ bool GetAutomaticLogin();
GnomeManager* manager_;
bool test_mode_;
diff --git a/UnityCore/SessionManager.h b/UnityCore/SessionManager.h
index 7a816f7c4..624f9ceed 100644
--- a/UnityCore/SessionManager.h
+++ b/UnityCore/SessionManager.h
@@ -46,6 +46,7 @@ public:
virtual std::string UserName() const = 0;
virtual std::string HostName() const = 0;
virtual void UserIconFile(std::function<void(std::string const&)> const&) const = 0;
+ virtual bool GetAutomaticLogin() const = 0;
virtual void ScreenSaverActivate() = 0;
virtual void ScreenSaverDeactivate() = 0;
diff --git a/UnityCore/Variant.cpp b/UnityCore/Variant.cpp
index 9de1d42e5..57cdb0fc8 100644
--- a/UnityCore/Variant.cpp
+++ b/UnityCore/Variant.cpp
@@ -161,6 +161,11 @@ std::string Variant::GetString() const
// As we're using the '&' prefix we don't need to free the string!
g_variant_get(variant_, "(&s)", &result);
}
+ else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE("(o)")))
+ {
+ // As we're using the '&' prefix we don't need to free the string!
+ g_variant_get(variant_, "(&o)", &result);
+ }
else
{
auto const& variant = get_variant(variant_);