logind-session-dbus.c revision 190700621f95160d364f8ec1d3e360246c41ce75
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <string.h>
#include "util.h"
#include "strv.h"
#include "bus-util.h"
#include "bus-common-errors.h"
#include "bus-label.h"
#include "logind.h"
#include "logind-session.h"
#include "logind-session-device.h"
static int property_get_user(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
assert(s);
p = user_bus_path(s->user);
if (!p)
return -ENOMEM;
}
static int property_get_name(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
assert(s);
}
static int property_get_seat(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
assert(s);
if (!p)
return -ENOMEM;
}
static int property_get_active(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
assert(s);
}
static int property_get_state(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
assert(s);
}
static int property_get_idle_hint(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
assert(s);
}
static int property_get_idle_since_hint(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
uint64_t u;
int r;
assert(s);
r = session_get_idle_hint(s, &t);
if (r < 0)
return r;
}
int r;
assert(s);
"org.freedesktop.login1.manage",
false,
&s->manager->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
r = session_stop(s, true);
if (r < 0)
return r;
}
int r;
assert(s);
r = session_activate(s);
if (r < 0)
return r;
}
int r;
assert(s);
"org.freedesktop.login1.lock-sessions",
false,
&s->manager->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (r < 0)
return r;
}
int r, b;
assert(s);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may set idle hint");
session_set_idle_hint(s, b);
}
const char *swho;
int r;
assert(s);
if (r < 0)
return r;
else {
if (who < 0)
}
"org.freedesktop.login1.manage",
false,
&s->manager->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (r < 0)
return r;
}
int r, force;
assert(s);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may take control");
if (r < 0)
return r;
}
assert(s);
return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
}
int r;
assert(s);
if (r < 0)
return r;
return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
if (sd)
/* We don't allow retrieving a device multiple times.
* The related ReleaseDevice call is not ref-counted.
* The caller should use dup() if it requires more
* than one fd (it would be functionally
* equivalent). */
if (r < 0)
return r;
if (r < 0)
return r;
}
int r;
assert(s);
if (r < 0)
return r;
return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
if (!sd)
}
static int method_pause_device_complete(sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(s);
if (r < 0)
return r;
return sd_bus_error_setf(error, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
if (!sd)
}
const sd_bus_vtable session_vtable[] = {
BUS_PROPERTY_DUAL_TIMESTAMP("Timestamp", offsetof(Session, timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Remote", "b", bus_property_get_bool, offsetof(Session, remote), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RemoteHost", "s", NULL, offsetof(Session, remote_host), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RemoteUser", "s", NULL, offsetof(Session, remote_user), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Leader", "u", bus_property_get_pid, offsetof(Session, leader), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Session, type), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Class", "s", property_get_class, offsetof(Session, class), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("IdleSinceHint", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("IdleSinceHintMonotonic", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_METHOD("PauseDeviceComplete", "uu", NULL, method_pause_device_complete, SD_BUS_VTABLE_UNPRIVILEGED),
};
int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
int r;
assert(m);
const char *name;
if (!message)
return 0;
if (r < 0)
return r;
if (r < 0)
return r;
} else {
_cleanup_free_ char *e = NULL;
const char *p;
if (!p)
return 0;
e = bus_label_unescape(p);
if (!e)
return -ENOMEM;
}
if (!session)
return 0;
return 1;
}
char *session_bus_path(Session *s) {
_cleanup_free_ char *t = NULL;
assert(s);
t = bus_label_escape(s->id);
if (!t)
return NULL;
return strappend("/org/freedesktop/login1/session/", t);
}
int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
Iterator i;
int r;
char *p;
p = session_bus_path(session);
if (!p)
return -ENOMEM;
r = strv_consume(&l, p);
if (r < 0)
return r;
}
if (message) {
const char *name;
if (r >= 0) {
if (r >= 0) {
if (session) {
r = strv_extend(&l, "/org/freedesktop/login1/session/self");
if (r < 0)
return r;
}
}
}
}
*nodes = l;
l = NULL;
return 1;
}
_cleanup_free_ char *p = NULL;
assert(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_emit_signal(
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"so", s->id, p);
}
_cleanup_free_ char *p = NULL;
char **l;
assert(s);
if (!s->started)
return 0;
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_emit_properties_changed_strv(s->manager->bus, p, "org.freedesktop.login1.Session", l);
}
_cleanup_free_ char *p = NULL;
assert(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_emit_signal(
p,
"org.freedesktop.login1.Session",
NULL);
}
Iterator i;
int r = 0;
assert(m);
int k;
if (k < 0)
r = k;
}
return r;
}
_cleanup_free_ char *p = NULL;
assert(s);
/* This is called after the session scope and the user service
* were successfully created, and finishes where
* bus_manager_create_session() left off. */
if (!s->create_message)
return 0;
return 0;
c = s->create_message;
s->create_message = NULL;
if (error)
return sd_bus_reply_method_error(c, error);
fifo_fd = session_create_fifo(s);
if (fifo_fd < 0)
return fifo_fd;
/* Update the session state file before we notify the client
* about the result. */
session_save(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
log_debug("Sending reply about created session: "
"id=%s object_path=%s uid=%u runtime_path=%s "
"session_fd=%d seat=%s vtnr=%u",
s->id,
p,
s->user->runtime_path,
return sd_bus_reply_method_return(
c, "soshusub",
s->id,
p,
s->user->runtime_path,
false);
}