chiark / gitweb /
manager: merge serialization and desrialization counter into one, and increase it...
[elogind.git] / src / logind-session-dbus.c
index 0ce880c590b80f9323a404d33fa753af762b04b7..0ef6558851fe46dd4323b150f2df747194dc418f 100644 (file)
@@ -49,6 +49,7 @@
         "  <property name=\"Remote\" type=\"b\" access=\"read\"/>\n"    \
         "  <property name=\"RemoteHost\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"RemoteUser\" type=\"s\" access=\"read\"/>\n" \
+        "  <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"Leader\" type=\"u\" access=\"read\"/>\n"    \
         "  <property name=\"Audit\" type=\"u\" access=\"read\"/>\n"     \
         "  <property name=\"Type\" type=\"s\" access=\"read\"/>\n"      \
@@ -144,7 +145,7 @@ static int bus_session_append_user(DBusMessageIter *i, const char *property, voi
 
 static int bus_session_append_active(DBusMessageIter *i, const char *property, void *data) {
         Session *s = data;
-        bool b;
+        dbus_bool_t b;
 
         assert(i);
         assert(property);
@@ -159,13 +160,13 @@ static int bus_session_append_active(DBusMessageIter *i, const char *property, v
 
 static int bus_session_append_idle_hint(DBusMessageIter *i, const char *property, void *data) {
         Session *s = data;
-        bool b;
+        int b;
 
         assert(i);
         assert(property);
         assert(s);
 
-        b = session_get_idle_hint(s, NULL);
+        b = session_get_idle_hint(s, NULL) > 0;
         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
                 return -ENOMEM;
 
@@ -236,6 +237,7 @@ static DBusHandlerResult session_message_dispatch(
                 { "org.freedesktop.login1.Session", "Remote",             bus_property_append_bool,     "b",    &s->remote              },
                 { "org.freedesktop.login1.Session", "RemoteUser",         bus_property_append_string,   "s",    s->remote_user          },
                 { "org.freedesktop.login1.Session", "RemoteHost",         bus_property_append_string,   "s",    s->remote_host          },
+                { "org.freedesktop.login1.Session", "Service",            bus_property_append_string,   "s",    s->service              },
                 { "org.freedesktop.login1.Session", "Leader",             bus_property_append_pid,      "u",    &s->leader              },
                 { "org.freedesktop.login1.Session", "Audit",              bus_property_append_uint32,   "u",    &s->audit_id            },
                 { "org.freedesktop.login1.Session", "Type",               bus_session_append_type,      "s",    &s->type                },
@@ -300,6 +302,7 @@ static DBusHandlerResult session_message_dispatch(
 
         } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "SetIdleHint")) {
                 dbus_bool_t b;
+                unsigned long ul;
 
                 if (!dbus_message_get_args(
                                     message,
@@ -308,6 +311,13 @@ static DBusHandlerResult session_message_dispatch(
                                     DBUS_TYPE_INVALID))
                         return bus_send_error_reply(connection, message, &error, -EINVAL);
 
+                ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), &error);
+                if (ul == (unsigned long) -1)
+                        return bus_send_error_reply(connection, message, &error, -EIO);
+
+                if (ul != 0 && ul != s->user->uid)
+                        return bus_send_error_reply(connection, message, NULL, -EPERM);
+
                 session_set_idle_hint(s, b);
 
                 reply = dbus_message_new_method_return(message);
@@ -427,6 +437,9 @@ int session_send_changed(Session *s, const char *properties) {
 
         assert(s);
 
+        if (!s->started)
+                return 0;
+
         p = session_bus_path(s);
         if (!p)
                 return -ENOMEM;