Commit c66cee94 authored by Ray Strode's avatar Ray Strode

user: add new Session/SessionType properties to replace XSession

Having a property called XSession in the API makes little
sense when wayland has taken the world by storm.

This commit adds new "Session" property without the "X" in the name,
and an additional property "SessionType" that can be either
"wayland" or "x11".
parent 74fed8d9
......@@ -168,6 +168,89 @@
<doc:para>
The expectation is that display managers will log the user in to this
specified session, if available.
Note this call is deprecated and has been superceded by SetSession since
not all graphical sessions use X as the display server.
</doc:para>
</doc:description>
<doc:permission>
The caller needs one of the following PolicyKit authorizations:
<doc:list>
<doc:item>
<doc:term>org.freedesktop.accounts.change-own-user-data</doc:term>
<doc:definition>To change his own language</doc:definition>
</doc:item>
<doc:item>
<doc:term>org.freedesktop.accounts.user-administration</doc:term>
<doc:definition>To change the language of another user</doc:definition>
</doc:item>
</doc:list>
</doc:permission>
<doc:errors>
<doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error>
<doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error>
</doc:errors>
</doc:doc>
</method>
<method name="SetSession">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="user_set_session"/>
<arg name="session" direction="in" type="s">
<doc:doc>
<doc:summary>
The new session to start (e.g. "gnome-xorg")
</doc:summary>
</doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>
Sets the users wayland or x session.
</doc:para>
<doc:para>
The expectation is that display managers will log the user in to this
specified session, if available.
</doc:para>
</doc:description>
<doc:permission>
The caller needs one of the following PolicyKit authorizations:
<doc:list>
<doc:item>
<doc:term>org.freedesktop.accounts.change-own-user-data</doc:term>
<doc:definition>To change his own language</doc:definition>
</doc:item>
<doc:item>
<doc:term>org.freedesktop.accounts.user-administration</doc:term>
<doc:definition>To change the language of another user</doc:definition>
</doc:item>
</doc:list>
</doc:permission>
<doc:errors>
<doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error>
<doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error>
</doc:errors>
</doc:doc>
</method>
<method name="SetSessionType">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="user_set_session_type"/>
<arg name="session_type" direction="in" type="s">
<doc:doc>
<doc:summary>
The type of the new session to start (e.g. "wayland" or "x11")
</doc:summary>
</doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>
Sets the session type of the users session.
</doc:para>
<doc:para>
Display managers may use this property to decide what type of display server to use when
loading the session
</doc:para>
</doc:description>
<doc:permission>
......@@ -668,6 +751,26 @@
</doc:doc>
</property>
<property name="Session" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
The users Wayland or X session.
</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="SessionType" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
The type of session the user should use (e.g. "wayland" or "x11")
</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="XSession" type="s" access="read">
<doc:doc>
<doc:description>
......
......@@ -1026,6 +1026,44 @@ act_user_get_x_session (ActUser *user)
return accounts_user_get_xsession (user->accounts_proxy);
}
/**
* act_user_get_session:
* @user: a #ActUser
*
* Returns the path to the configured session for @user.
*
* Returns: (transfer none): a path to an icon
*/
const char *
act_user_get_session (ActUser *user)
{
g_return_val_if_fail (ACT_IS_USER (user), NULL);
if (user->accounts_proxy == NULL)
return NULL;
return accounts_user_get_session (user->accounts_proxy);
}
/**
* act_user_get_session_type:
* @user: a #ActUser
*
* Returns the type of the configured session for @user.
*
* Returns: (transfer none): a path to an icon
*/
const char *
act_user_get_session_type (ActUser *user)
{
g_return_val_if_fail (ACT_IS_USER (user), NULL);
if (user->accounts_proxy == NULL)
return NULL;
return accounts_user_get_session_type (user->accounts_proxy);
}
/**
* act_user_get_object_path:
* @user: a #ActUser
......@@ -1337,6 +1375,61 @@ act_user_set_x_session (ActUser *user,
}
}
/**
* act_user_set_session:
* @user: the user object to alter.
* @session: a session (e.g. gnome)
*
* Assigns a new session for @user.
*
* Note this function is synchronous and ignores errors.
**/
void
act_user_set_session (ActUser *user,
const char *session)
{
g_autoptr(GError) error = NULL;
g_return_if_fail (ACT_IS_USER (user));
g_return_if_fail (session != NULL);
g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));
if (!accounts_user_call_set_session_sync (user->accounts_proxy,
session,
NULL,
&error)) {
g_warning ("SetSession call failed: %s", error->message);
return;
}
}
/**
* act_user_set_session_type:
* @user: the user object to alter.
* @session_type: a type of session (e.g. "wayland" or "x11")
*
* Assigns a type to the session for @user.
*
* Note this function is synchronous and ignores errors.
**/
void
act_user_set_session_type (ActUser *user,
const char *session_type)
{
g_autoptr(GError) error = NULL;
g_return_if_fail (ACT_IS_USER (user));
g_return_if_fail (session_type != NULL);
g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));
if (!accounts_user_call_set_session_type_sync (user->accounts_proxy,
session_type,
NULL,
&error)) {
g_warning ("SetSessionType call failed: %s", error->message);
return;
}
}
/**
* act_user_set_location:
......
......@@ -78,6 +78,8 @@ gboolean act_user_is_nonexistent (ActUser *user);
const char *act_user_get_icon_file (ActUser *user);
const char *act_user_get_language (ActUser *user);
const char *act_user_get_x_session (ActUser *user);
const char *act_user_get_session (ActUser *user);
const char *act_user_get_session_type (ActUser *user);
const char *act_user_get_primary_session_id (ActUser *user);
gint act_user_collate (ActUser *user1,
......@@ -98,6 +100,10 @@ void act_user_set_language (ActUser *user,
const char *language);
void act_user_set_x_session (ActUser *user,
const char *x_session);
void act_user_set_session (ActUser *user,
const char *session);
void act_user_set_session_type (ActUser *user,
const char *session_type);
void act_user_set_location (ActUser *user,
const char *location);
void act_user_set_user_name (ActUser *user,
......
......@@ -259,6 +259,21 @@ user_update_from_keyfile (User *user,
s = g_key_file_get_string (keyfile, "User", "XSession", NULL);
if (s != NULL) {
accounts_user_set_xsession (ACCOUNTS_USER (user), s);
/* for backward compat */
accounts_user_set_session (ACCOUNTS_USER (user), s);
g_clear_pointer (&s, g_free);
}
s = g_key_file_get_string (keyfile, "User", "Session", NULL);
if (s != NULL) {
accounts_user_set_session (ACCOUNTS_USER (user), s);
g_clear_pointer (&s, g_free);
}
s = g_key_file_get_string (keyfile, "User", "SessionType", NULL);
if (s != NULL) {
accounts_user_set_session_type (ACCOUNTS_USER (user), s);
g_clear_pointer (&s, g_free);
}
......@@ -326,6 +341,12 @@ user_save_to_keyfile (User *user,
if (accounts_user_get_language (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "Language", accounts_user_get_language (ACCOUNTS_USER (user)));
if (accounts_user_get_session (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "Session", accounts_user_get_session (ACCOUNTS_USER (user)));
if (accounts_user_get_session_type (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "SessionType", accounts_user_get_session_type (ACCOUNTS_USER (user)));
if (accounts_user_get_xsession (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "XSession", accounts_user_get_xsession (ACCOUNTS_USER (user)));
......@@ -1023,6 +1044,104 @@ user_set_language (AccountsUser *auser,
return TRUE;
}
static void
user_change_session_authorized_cb (Daemon *daemon,
User *user,
GDBusMethodInvocation *context,
gpointer user_data)
{
const gchar *session = user_data;
if (g_strcmp0 (accounts_user_get_session (ACCOUNTS_USER (user)), session) != 0) {
accounts_user_set_session (ACCOUNTS_USER (user), session);
save_extra_data (user);
}
accounts_user_complete_set_session (ACCOUNTS_USER (user), context);
}
static gboolean
user_set_session (AccountsUser *auser,
GDBusMethodInvocation *context,
const gchar *session)
{
User *user = (User*)auser;
int uid;
const gchar *action_id;
if (!get_caller_uid (context, &uid)) {
throw_error (context, ERROR_FAILED, "identifying caller failed");
return FALSE;
}
if (accounts_user_get_uid (ACCOUNTS_USER (user)) == (uid_t) uid)
action_id = "org.freedesktop.accounts.change-own-user-data";
else
action_id = "org.freedesktop.accounts.user-administration";
daemon_local_check_auth (user->daemon,
user,
action_id,
TRUE,
user_change_session_authorized_cb,
context,
g_strdup (session),
(GDestroyNotify) g_free);
return TRUE;
}
static void
user_change_session_type_authorized_cb (Daemon *daemon,
User *user,
GDBusMethodInvocation *context,
gpointer user_data)
{
const gchar *session_type = user_data;
if (g_strcmp0 (accounts_user_get_session_type (ACCOUNTS_USER (user)), session_type) != 0) {
accounts_user_set_session_type (ACCOUNTS_USER (user), session_type);
save_extra_data (user);
}
accounts_user_complete_set_session_type (ACCOUNTS_USER (user), context);
}
static gboolean
user_set_session_type (AccountsUser *auser,
GDBusMethodInvocation *context,
const gchar *session_type)
{
User *user = (User*)auser;
int uid;
const gchar *action_id;
if (!get_caller_uid (context, &uid)) {
throw_error (context, ERROR_FAILED, "identifying caller failed");
return FALSE;
}
if (accounts_user_get_uid (ACCOUNTS_USER (user)) == (uid_t) uid)
action_id = "org.freedesktop.accounts.change-own-user-data";
else
action_id = "org.freedesktop.accounts.user-administration";
daemon_local_check_auth (user->daemon,
user,
action_id,
TRUE,
user_change_session_type_authorized_cb,
context,
g_strdup (session_type),
(GDestroyNotify) g_free);
return TRUE;
}
static void
user_change_x_session_authorized_cb (Daemon *daemon,
User *user,
......@@ -1993,6 +2112,8 @@ user_accounts_user_iface_init (AccountsUserIface *iface)
iface->handle_set_shell = user_set_shell;
iface->handle_set_user_name = user_set_user_name;
iface->handle_set_xsession = user_set_x_session;
iface->handle_set_session = user_set_session;
iface->handle_set_session_type = user_set_session_type;
iface->handle_get_password_expiration_policy = user_get_password_expiration_policy;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment