logind-dbus.c revision 2154761fbbc931e3e3d83100fa42609c99cd2536
/*-*- 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 <unistd.h>
#include <pwd.h>
#include "logind.h"
#include "dbus-common.h"
#include "strv.h"
#include "mkdir.h"
#include "path-util.h"
#include "polkit.h"
#include "special.h"
#define BUS_MANAGER_INTERFACE \
" <interface name=\"org.freedesktop.login1.Manager\">\n" \
" <method name=\"GetSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"GetSessionByPID\">\n" \
" <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"GetUser\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"user\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"GetSeat\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ListSessions\">\n" \
" <arg name=\"sessions\" type=\"a(susso)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ListUsers\">\n" \
" <arg name=\"users\" type=\"a(uso)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ListSeats\">\n" \
" <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"CreateSession\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"sevice\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"type\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"class\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"vtnr\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"tty\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"display\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"remote\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"remote_user\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"remote_host\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"controllers\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"reset_controllers\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"kill_processes\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"id\" type=\"s\" direction=\"out\"/>\n" \
" <arg name=\"path\" type=\"o\" direction=\"out\"/>\n" \
" <arg name=\"runtime_path\" type=\"o\" direction=\"out\"/>\n" \
" <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n" \
" <arg name=\"seat\" type=\"s\" direction=\"out\"/>\n" \
" <arg name=\"vtnr\" type=\"u\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ReleaseSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"ActivateSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"ActivateSessionOnSeat\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"LockSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"UnlockSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"KillSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"signal\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"KillUser\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"signal\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"TerminateSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"TerminateUser\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"TerminateSeat\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"SetUserLinger\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"b\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"AttachDevice\">\n" \
" <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"sysfs\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"FlushDevices\">\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"PowerOff\">\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"Reboot\">\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"Suspend\">\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"Hibernate\">\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"CanPowerOff\">\n" \
" <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"CanReboot\">\n" \
" <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"CanSuspend\">\n" \
" <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"CanHibernate\">\n" \
" <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"Inhibit\">\n" \
" <arg name=\"what\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"why\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ListInhibitors\">\n" \
" <arg name=\"inhibitors\" type=\"a(ssssuu)\" direction=\"out\"/>\n" \
" </method>\n" \
" <signal name=\"SessionNew\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"SessionRemoved\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"UserNew\">\n" \
" <arg name=\"uid\" type=\"u\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"UserRemoved\">\n" \
" <arg name=\"uid\" type=\"u\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"SeatNew\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"SeatRemoved\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"PrepareForShutdown\">\n" \
" <arg name=\"active\" type=\"b\"/>\n" \
" </signal>\n" \
" <signal name=\"PrepareForSleep\">\n" \
" <arg name=\"active\" type=\"b\"/>\n" \
" </signal>\n" \
" <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"NAutoVTs\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"KillOnlyUsers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"KillExcludeUsers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"KillUserProcesses\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"BlockInhibited\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"DelayInhibited\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"InhibitDelayMaxUSec\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"HandlePowerKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleSleepKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleLidSwitch\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION_BEGIN \
"<node>\n" \
#define INTROSPECTION_END \
"</node>\n"
#define INTERFACES_LIST \
"org.freedesktop.login1.Manager\0"
dbus_bool_t b;
assert(i);
assert(m);
b = manager_get_idle_hint(m, NULL) > 0;
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
static int bus_manager_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
uint64_t u;
assert(i);
assert(m);
manager_get_idle_hint(m, &t);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
return -ENOMEM;
return 0;
}
InhibitWhat w;
const char *p;
p = inhibit_what_to_string(w);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &p))
return -ENOMEM;
return 0;
}
SessionType t;
SessionClass c;
Seat *s;
int r;
int fifo_fd = -1;
bool b;
assert(m);
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (leader <= 0 ||
!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
t = session_type_from_string(type);
if (t < 0 ||
!dbus_message_iter_next(&iter) ||
return -EINVAL;
c = SESSION_USER;
else
if (c < 0 ||
!dbus_message_iter_next(&iter) ||
return -EINVAL;
s = NULL;
else {
if (!s)
return -ENOENT;
}
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
int v;
if (!s)
s = m->vtconsole;
else if (s != m->vtconsole)
return -EINVAL;
v = vtnr_from_tty(tty);
if (v <= 0)
return v < 0 ? v : -EINVAL;
if (vtnr <= 0)
return -EINVAL;
} else if (tty_is_console(tty)) {
if (!s)
s = m->vtconsole;
else if (s != m->vtconsole)
return -EINVAL;
if (vtnr != 0)
return -EINVAL;
return -EINVAL;
if (s) {
if (seat_can_multi_session(s)) {
if (vtnr > 63)
return -EINVAL;
} else {
if (vtnr != 0)
return -EINVAL;
}
}
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (!dbus_message_iter_next(&iter) ||
return -EINVAL;
if (r < 0)
return -EINVAL;
!dbus_message_iter_next(&iter) ||
r = -EINVAL;
goto fail;
}
if (r < 0)
goto fail;
!dbus_message_iter_next(&iter) ||
r = -EINVAL;
goto fail;
}
if (r < 0)
goto fail;
if (audit_id > 0) {
if (!id) {
r = -ENOMEM;
goto fail;
}
if (session) {
if (fifo_fd < 0) {
r = fifo_fd;
goto fail;
}
/* Session already exists, client is probably
* something like "su" which changes uid but
* is still the same audit session */
if (!reply) {
r = -ENOMEM;
goto fail;
}
p = session_bus_path(session);
if (!p) {
r = -ENOMEM;
goto fail;
}
free(p);
if (!b) {
r = -ENOMEM;
goto fail;
}
return 0;
}
} else {
do {
r = -ENOMEM;
goto fail;
}
}
if (r < 0)
goto fail;
r = -ENOMEM;
goto fail;
}
}
r = -ENOMEM;
goto fail;
}
}
if (!isempty(remote_user)) {
if (!session->remote_user) {
r = -ENOMEM;
goto fail;
}
}
if (!isempty(remote_host)) {
if (!session->remote_host) {
r = -ENOMEM;
goto fail;
}
}
r = -ENOMEM;
goto fail;
}
}
if (fifo_fd < 0) {
r = fifo_fd;
goto fail;
}
if (s) {
r = seat_attach_session(s, session);
if (r < 0)
goto fail;
}
r = session_start(session);
if (r < 0)
goto fail;
if (!reply) {
r = -ENOMEM;
goto fail;
}
p = session_bus_path(session);
if (!p) {
r = -ENOMEM;
goto fail;
}
free(p);
if (!b) {
r = -ENOMEM;
goto fail;
}
return 0;
fail:
if (session)
if (user)
if (fifo_fd >= 0)
if (reply)
return r;
}
static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessage *message, DBusError *error, DBusMessage **_reply) {
InhibitWhat w;
unsigned long ul;
int r, fifo_fd = -1;
assert(m);
if (!dbus_message_get_args(
r = -EIO;
goto fail;
}
w = inhibit_what_from_string(what);
if (w <= 0) {
r = -EINVAL;
goto fail;
}
if (mm < 0) {
r = -EINVAL;
goto fail;
}
m == INHIBIT_BLOCK ?
"org.freedesktop.login1.inhibit-block" :
if (r < 0)
goto fail;
if (ul == (unsigned long) -1) {
r = -EIO;
goto fail;
}
if (pid <= 0) {
r = -EIO;
goto fail;
}
do {
r = -ENOMEM;
goto fail;
}
r = manager_add_inhibitor(m, id, &i);
if (r < 0)
goto fail;
i->what = w;
r = -ENOMEM;
goto fail;
}
fifo_fd = inhibitor_create_fifo(i);
if (fifo_fd < 0) {
r = fifo_fd;
goto fail;
}
if (!reply) {
r = -ENOMEM;
goto fail;
}
if (!dbus_message_append_args(
r = -ENOMEM;
goto fail;
}
inhibitor_start(i);
return 0;
fail:
if (i)
inhibitor_free(i);
if (fifo_fd >= 0)
if (reply)
return r;
}
struct udev_enumerate *e;
int r;
assert(m);
e = udev_enumerate_new(m->udev);
if (!e) {
r = -ENOMEM;
goto finish;
}
if (d) {
if (udev_enumerate_add_match_parent(e, d) < 0) {
r = -EIO;
goto finish;
}
}
if (udev_enumerate_scan_devices(e) < 0) {
r = -EIO;
goto finish;
}
char *t;
const char *p;
p = udev_list_entry_get_name(item);
t = strappend(p, "/uevent");
if (!t) {
r = -ENOMEM;
goto finish;
}
write_one_line_file(t, "change");
free(t);
}
r = 0;
if (e)
return r;
}
struct udev_device *d;
const char *id_for_seat;
int r;
assert(m);
if (!d)
return -ENODEV;
if (!udev_device_has_tag(d, "seat")) {
r = -ENODEV;
goto finish;
}
if (!id_for_seat) {
r = -ENODEV;
goto finish;
}
r = -ENOMEM;
goto finish;
}
if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) {
r = -ENOMEM;
goto finish;
}
if (r < 0)
goto finish;
r = trigger_device(m, d);
if (d)
return r;
}
static int flush_devices(Manager *m) {
DIR *d;
assert(m);
if (!d) {
log_warning("Failed to open /etc/udev/rules.d: %m");
} else {
if (!dirent_is_file(de))
continue;
continue;
continue;
}
closedir(d);
}
return trigger_device(m, NULL);
}
static int have_multiple_sessions(
Manager *m,
Iterator i;
unsigned long ul;
assert(m);
if (ul == (unsigned long) -1)
return -EIO;
/* Check for other users' sessions. Greeter sessions do not count. */
return true;
return false;
}
const char *mode = "replace";
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit");
if (!message)
return -ENOMEM;
return -ENOMEM;
}
if (!reply)
return -EIO;
return 0;
}
static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
[INHIBIT_SHUTDOWN] = "PrepareForShutdown",
[INHIBIT_SLEEP] = "PrepareForSleep"
};
int r = 0;
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
assert(signal_name[w]);
message = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", signal_name[w]);
if (!message)
return -ENOMEM;
r = -ENOMEM;
return r;
}
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
send_prepare_for(m, w, true);
/* Update timestamp for timeout */
if (!m->delayed_unit)
/* Remember what we want to do, possibly overriding what kind
* of unit we previously queued. */
m->delayed_unit = unit_name;
m->delayed_what = w;
return 0;
}
static int bus_manager_can_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
const char *action,
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_type,
DBusMessage **_reply) {
const char *result;
int r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
if (sleep_type) {
r = can_sleep(sleep_type);
if (r < 0)
return r;
if (r == 0) {
result = "na";
goto finish;
}
}
if (r < 0)
return r;
multiple_sessions = r > 0;
if (multiple_sessions) {
if (r < 0)
return r;
if (r > 0)
result = "yes";
else if (challenge)
result = "challenge";
else
result = "no";
}
if (blocked) {
if (r < 0)
return r;
if (r > 0 && !result)
result = "yes";
result = "challenge";
else
result = "no";
}
if (!multiple_sessions && !blocked) {
/* If neither inhibit nor multiple sessions
* apply then just check the normal policy */
if (r < 0)
return r;
if (r > 0)
result = "yes";
else if (challenge)
result = "challenge";
else
result = "no";
}
if (!reply)
return -ENOMEM;
if (!b) {
return -ENOMEM;
}
return 0;
}
Manager *m,
const char *unit_name,
InhibitWhat w,
bool delayed;
int r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
delayed =
m->inhibit_delay_max > 0 &&
if (delayed)
/* Shutdown is delayed, keep in mind what we
* want to do, and start a timeout */
r = delay_shutdown_or_sleep(m, w, unit_name);
else
/* Shutdown is not delayed, execute it
* immediately */
return r;
}
static int bus_manager_do_shutdown_or_sleep(
Manager *m,
const char *unit_name,
InhibitWhat w,
const char *action,
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_type,
DBusMessage **_reply) {
bool multiple_sessions, blocked;
int r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
if (!dbus_message_get_args(
return -EINVAL;
if (sleep_type) {
r = can_sleep(sleep_type);
if (r < 0)
return r;
if (r == 0)
return -ENOTSUP;
}
if (r < 0)
return r;
multiple_sessions = r > 0;
if (multiple_sessions) {
if (r < 0)
return r;
}
if (blocked) {
if (r < 0)
return r;
}
if (!multiple_sessions && !blocked) {
if (r < 0)
return r;
}
if (r < 0)
return r;
if (!reply)
return -ENOMEM;
return 0;
}
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_handle_button, handle_button, HandleButton);
static const BusProperty bus_login_manager_properties[] = {
{ "KillExcludeUsers", bus_property_append_strv, "as", offsetof(Manager, kill_exclude_users), true },
{ NULL, }
};
void *userdata) {
int r;
assert(m);
const char *name;
char *p;
bool b;
if (!dbus_message_get_args(
&error,
if (!session)
if (!reply)
goto oom;
p = session_bus_path(session);
if (!p)
goto oom;
free(p);
if (!b)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSessionByPID")) {
char *p;
bool b;
if (!dbus_message_get_args(
&error,
if (r <= 0)
if (!reply)
goto oom;
p = session_bus_path(session);
if (!p)
goto oom;
free(p);
if (!b)
goto oom;
char *p;
bool b;
if (!dbus_message_get_args(
&error,
if (!user)
if (!reply)
goto oom;
p = user_bus_path(user);
if (!p)
goto oom;
free(p);
if (!b)
goto oom;
const char *name;
char *p;
bool b;
if (!dbus_message_get_args(
&error,
if (!seat)
if (!reply)
goto oom;
p = seat_bus_path(seat);
if (!p)
goto oom;
free(p);
if (!b)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListSessions")) {
char *p;
Iterator i;
const char *empty = "";
if (!reply)
goto oom;
goto oom;
goto oom;
p = session_bus_path(session);
if (!p)
goto oom;
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, session->seat ? (const char**) &session->seat->id : &empty) ||
free(p);
goto oom;
}
free(p);
goto oom;
}
goto oom;
char *p;
Iterator i;
if (!reply)
goto oom;
goto oom;
goto oom;
p = user_bus_path(user);
if (!p)
goto oom;
free(p);
goto oom;
}
free(p);
goto oom;
}
goto oom;
char *p;
Iterator i;
if (!reply)
goto oom;
goto oom;
goto oom;
p = seat_bus_path(seat);
if (!p)
goto oom;
free(p);
goto oom;
}
free(p);
goto oom;
}
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListInhibitors")) {
Iterator i;
if (!reply)
goto oom;
goto oom;
goto oom;
goto oom;
goto oom;
}
goto oom;
if (r < 0)
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CreateSession")) {
/* Don't delay the work on OOM here, since it might be
* triggered by a low RLIMIT_NOFILE here (since we
* send a dupped fd to the client), and we'd rather
* see this fail quickly then be retried later */
if (r < 0)
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ReleaseSession")) {
const char *name;
if (!dbus_message_get_args(
&error,
if (!session)
/* We use the FIFO to detect stray sessions where the
process invoking PAM dies abnormally. We need to make
sure that that process is not killed if at the clean
end of the session it closes the FIFO. Hence, with
this call explicitly turn off the FIFO logic, so that
the PAM code can finish clean up on its own */
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSession")) {
const char *name;
if (!dbus_message_get_args(
&error,
if (!session)
r = session_activate(session);
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSessionOnSeat")) {
const char *session_name, *seat_name;
/* Same as ActivateSession() but refuses to work if
* the seat doesn't match */
if (!dbus_message_get_args(
&error,
if (!session)
if (!seat)
r = session_activate(session);
if (r < 0)
if (!reply)
goto oom;
const char *name;
if (!dbus_message_get_args(
&error,
if (!session)
goto oom;
if (!reply)
goto oom;
const char *swho;
const char *name;
if (!dbus_message_get_args(
&error,
else {
if (who < 0)
}
if (!session)
if (r < 0)
if (!reply)
goto oom;
if (!dbus_message_get_args(
&error,
if (!user)
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSession")) {
const char *name;
if (!dbus_message_get_args(
&error,
if (!session)
r = session_stop(session);
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateUser")) {
if (!dbus_message_get_args(
&error,
if (!user)
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSeat")) {
const char *name;
if (!dbus_message_get_args(
&error,
if (!seat)
r = seat_stop_sessions(seat);
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "SetUserLinger")) {
char *path;
if (!dbus_message_get_args(
&error,
DBUS_TYPE_BOOLEAN, &b,
errno = 0;
if (!pw)
r = verify_polkit(connection, message, "org.freedesktop.login1.set-user-linger", interactive, NULL, &error);
if (r < 0)
if (r < 0)
if (!path)
goto oom;
if (b) {
User *u;
if (r < 0)
if (manager_add_user_by_uid(m, uid, &u) >= 0)
user_start(u);
} else {
User *u;
if (u)
}
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "AttachDevice")) {
if (!dbus_message_get_args(
&error,
r = verify_polkit(connection, message, "org.freedesktop.login1.attach-device", interactive, NULL, &error);
if (r < 0)
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "FlushDevices")) {
if (!dbus_message_get_args(
&error,
r = verify_polkit(connection, message, "org.freedesktop.login1.flush-devices", interactive, NULL, &error);
if (r < 0)
r = flush_devices(m);
if (r < 0)
if (!reply)
goto oom;
m, connection, message,
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
NULL,
if (r < 0)
m, connection, message,
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
NULL,
if (r < 0)
m, connection, message,
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
"mem",
if (r < 0)
m, connection, message,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"disk",
if (r < 0)
m, connection, message,
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
NULL,
if (r < 0)
m, connection, message,
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
NULL,
if (r < 0)
m, connection, message,
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
"mem",
if (r < 0)
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CanHibernate")) {
m, connection, message,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"disk",
if (r < 0)
} else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
char *introspection = NULL;
FILE *f;
Iterator i;
char *p;
goto oom;
/* We roll our own introspection code here, instead of
* relying on bus_default_message_handler() because we
* need to generate our introspection string
* dynamically. */
goto oom;
fputs(INTROSPECTION_BEGIN, f);
if (p) {
fprintf(f, "<node name=\"seat/%s\"/>", p);
free(p);
}
}
if (p) {
fprintf(f, "<node name=\"session/%s\"/>", p);
free(p);
}
}
fputs(INTROSPECTION_END, f);
if (ferror(f)) {
fclose(f);
goto oom;
}
fclose(f);
if (!introspection)
goto oom;
goto oom;
}
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.login1.Manager", bus_login_manager_properties, m },
{ NULL, }
};
}
if (reply) {
goto oom;
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
const DBusObjectPathVTable bus_manager_vtable = {
};
void *userdata) {
assert(m);
const char *cgroup;
else
}
}
DBusMessage *m;
int r = -ENOMEM;
m = bus_properties_changed_new("/org/freedesktop/login1", "org.freedesktop.login1.Manager", properties);
if (!m)
goto finish;
goto finish;
r = 0;
if (m)
return r;
}
const char *unit_name;
bool delayed;
int r;
if (!manager->delayed_unit)
return 0;
/* Continue delay? */
delayed =
if (delayed)
return 0;
/* Reset delay data */
/* Actually do the shutdown */
if (r < 0) {
return r;
}
/* Tell people about it */
return 1;
}