logind-dbus.c revision d1122ad5e3222cc17bfb556c23273598a5fb60fa
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/***
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen This file is part of systemd.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen Copyright 2011 Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen systemd is free software; you can redistribute it and/or modify it
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen under the terms of the GNU Lesser General Public License as published by
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen (at your option) any later version.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen systemd is distributed in the hope that it will be useful, but
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen Lesser General Public License for more details.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen You should have received a copy of the GNU Lesser General Public License
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen***/
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#include <errno.h>
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#include <string.h>
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering#include <unistd.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <pwd.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "logind.h"
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#include "dbus-common.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "strv.h"
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#include "mkdir.h"
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#include "polkit.h"
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#include "special.h"
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define BUS_MANAGER_INTERFACE \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <interface name=\"org.freedesktop.login1.Manager\">\n" \
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering " <method name=\"GetSession\">\n" \
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering " <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering " </method>\n" \
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering " <method name=\"GetSessionByPID\">\n" \
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering " <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"GetUser\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"user\" type=\"o\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"GetSeat\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ListSessions\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"sessions\" type=\"a(susso)\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ListUsers\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"users\" type=\"a(uso)\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ListSeats\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"CreateSession\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"sevice\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"type\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"class\" type=\"s\" direction=\"in\"/>\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <arg name=\"vtnr\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"tty\" type=\"s\" direction=\"in\"/>\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <arg name=\"display\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"remote\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"remote_user\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"remote_host\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"controllers\" type=\"as\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"reset_controllers\" type=\"as\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"kill_processes\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"runtime_path\" type=\"o\" direction=\"out\"/>\n" \
21d73c87b09ec2b8642424bc714ce9af3da4fc40Lennart Poettering " <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n" \
21d73c87b09ec2b8642424bc714ce9af3da4fc40Lennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"out\"/>\n" \
21d73c87b09ec2b8642424bc714ce9af3da4fc40Lennart Poettering " <arg name=\"vtnr\" type=\"u\" direction=\"out\"/>\n" \
21d73c87b09ec2b8642424bc714ce9af3da4fc40Lennart Poettering " </method>\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <method name=\"ReleaseSession\">\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ActivateSession\">\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ActivateSessionOnSeat\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"LockSession\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"UnlockSession\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"KillSession\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"signal\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"KillUser\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"signal\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"TerminateSession\">\n" \
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"TerminateUser\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"TerminateSeat\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"SetUserLinger\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"b\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"AttachDevice\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"sysfs\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"FlushDevices\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"PowerOff\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"Reboot\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"CanPowerOff\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"CanReboot\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"Inhibit\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"what\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"why\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ListInhibitors\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"inhibitors\" type=\"a(sssuu)\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"SessionNew\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"SessionRemoved\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"UserNew\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"UserRemoved\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"uid\" type=\"u\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"SeatNew\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"SeatRemoved\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"NAutoVTs\" type=\"u\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"KillOnlyUsers\" type=\"as\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"KillExcludeUsers\" type=\"as\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"KillUserProcesses\" type=\"b\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"Inhibited\" type=\"s\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </interface>\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define INTROSPECTION_BEGIN \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "<node>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_MANAGER_INTERFACE \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_PROPERTIES_INTERFACE \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_PEER_INTERFACE \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_INTROSPECTABLE_INTERFACE
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define INTROSPECTION_END \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "</node>\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define INTERFACES_LIST \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_GENERIC_INTERFACES_LIST \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "org.freedesktop.login1.Manager\0"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_append_idle_hint(DBusMessageIter *i, const char *property, void *data) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *m = data;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_bool_t b;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(i);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(property);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering b = manager_get_idle_hint(m, NULL) > 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *m = data;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dual_timestamp t;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint64_t u;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(i);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(property);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering manager_get_idle_hint(m, &t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_append_inhibited(DBusMessageIter *i, const char *property, void *data) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *m = data;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering InhibitWhat w;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering w = manager_inhibit_what(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering p = inhibit_what_to_string(w);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &p))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Session *session = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering User *user = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *type, *class, *seat, *tty, *display, *remote_user, *remote_host, *service;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t uid, leader, audit_id = 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_bool_t remote, kill_processes;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char **controllers = NULL, **reset_controllers = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering SessionType t;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering SessionClass c;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Seat *s;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessageIter iter;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *id = NULL, *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t vtnr = 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int fifo_fd = -1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessage *reply = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool b;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(message);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(_reply);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_init(message, &iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &uid);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_next(&iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &leader);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (leader <= 0 ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_next(&iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &service);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_next(&iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
0014a4ad505d119c7ac4346d9d774c3f17f663a5Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &type);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering t = session_type_from_string(type);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (t < 0 ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_next(&iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &class);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (isempty(class))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering c = SESSION_USER;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering else
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering c = session_class_from_string(class);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (c < 0 ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_next(&iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_basic(&iter, &seat);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (isempty(seat))
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering s = NULL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering else {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering s = hashmap_get(m->seats, seat);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!s)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -ENOENT;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering }
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!dbus_message_iter_next(&iter) ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_basic(&iter, &vtnr);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!dbus_message_iter_next(&iter) ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_basic(&iter, &tty);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (tty_is_vc(tty)) {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering int v;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!s)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering s = m->vtconsole;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering else if (s != m->vtconsole)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering v = vtnr_from_tty(tty);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (v <= 0)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return v < 0 ? v : -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (vtnr <= 0)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering vtnr = (uint32_t) v;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering else if (vtnr != (uint32_t) v)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering } else if (tty_is_console(tty)) {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!s)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering s = m->vtconsole;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering else if (s != m->vtconsole)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (vtnr != 0)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering } else if (!isempty(tty) && s && seat_is_vtconsole(s))
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (s) {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (seat_can_multi_session(s)) {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (vtnr > 63)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering } else {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (vtnr != 0)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering }
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering }
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!dbus_message_iter_next(&iter) ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_basic(&iter, &display);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!dbus_message_iter_next(&iter) ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_basic(&iter, &remote);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!dbus_message_iter_next(&iter) ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_basic(&iter, &remote_user);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!dbus_message_iter_next(&iter) ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return -EINVAL;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_basic(&iter, &remote_host);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (!dbus_message_iter_next(&iter) ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING)
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering return -EINVAL;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = bus_parse_strv_iter(&iter, &controllers);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (r < 0)
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering return -EINVAL;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (strv_contains(controllers, "systemd") ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering !dbus_message_iter_next(&iter) ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING) {
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = -EINVAL;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering goto fail;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering }
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = bus_parse_strv_iter(&iter, &reset_controllers);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (r < 0)
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering goto fail;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (strv_contains(reset_controllers, "systemd") ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering !dbus_message_iter_next(&iter) ||
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN) {
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = -EINVAL;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering goto fail;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering }
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering dbus_message_iter_get_basic(&iter, &kill_processes);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = manager_add_user_by_uid(m, uid, &user);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (r < 0)
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering goto fail;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering audit_session_from_pid(leader, &audit_id);
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering if (audit_id > 0) {
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering asprintf(&id, "%lu", (unsigned long) audit_id);
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering if (!id) {
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering r = -ENOMEM;
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering goto fail;
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering }
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering session = hashmap_get(m->sessions, id);
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering if (session) {
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering free(id);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering fifo_fd = session_create_fifo(session);
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering if (fifo_fd < 0) {
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = fifo_fd;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering goto fail;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering }
90ab504273a7f186ebb76e6acfb778b4e0d7c91bLennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering /* Session already exists, client is probably
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * something like "su" which changes uid but
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * is still the same audit session */
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering reply = dbus_message_new_method_return(message);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!reply) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = -ENOMEM;
c92e531c82a9815ec349aa1bf31236b86b2d5311Lennart Poettering goto fail;
c92e531c82a9815ec349aa1bf31236b86b2d5311Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen p = session_bus_path(session);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!p) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering seat = session->seat ? session->seat->id : "";
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering vtnr = session->vtnr;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering b = dbus_message_append_args(
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering reply,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_STRING, &session->id,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_STRING, &session->user->runtime_path,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_UNIX_FD, &fifo_fd,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_STRING, &seat,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_UINT32, &vtnr,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_INVALID);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen free(p);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!b) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = -ENOMEM;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen goto fail;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering close_nointr_nofail(fifo_fd);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering *_reply = reply;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering strv_free(controllers);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering strv_free(reset_controllers);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering do {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(id);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering id = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (asprintf(&id, "c%lu", ++m->session_counter) < 0) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } while (hashmap_get(m->sessions, id));
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = manager_add_session(m, user, id, &session);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen free(id);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (r < 0)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen goto fail;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->leader = leader;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->audit_id = audit_id;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->type = t;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->class = c;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->remote = remote;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->controllers = controllers;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->reset_controllers = reset_controllers;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->kill_processes = kill_processes;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering session->vtnr = vtnr;
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering controllers = reset_controllers = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!isempty(tty)) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen session->tty = strdup(tty);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!session->tty) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
f0e1546763304aedc90e91d70dab9eeb7c966cf8Lennart Poettering
f0e1546763304aedc90e91d70dab9eeb7c966cf8Lennart Poettering if (!isempty(display)) {
f0e1546763304aedc90e91d70dab9eeb7c966cf8Lennart Poettering session->display = strdup(display);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!session->display) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering }
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
f0e1546763304aedc90e91d70dab9eeb7c966cf8Lennart Poettering if (!isempty(remote_user)) {
f0e1546763304aedc90e91d70dab9eeb7c966cf8Lennart Poettering session->remote_user = strdup(remote_user);
f0e1546763304aedc90e91d70dab9eeb7c966cf8Lennart Poettering if (!session->remote_user) {
096b6773886bd7a0c8c97aa684b0b67dfae58355Lennart Poettering r = -ENOMEM;
096b6773886bd7a0c8c97aa684b0b67dfae58355Lennart Poettering goto fail;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!isempty(remote_host)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering session->remote_host = strdup(remote_host);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!session->remote_host) {
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering r = -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto fail;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!isempty(service)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering session->service = strdup(service);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!session->service) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto fail;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering }
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering }
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering fifo_fd = session_create_fifo(session);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (fifo_fd < 0) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = fifo_fd;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (s) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = seat_attach_session(s, session);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (r < 0)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = session_start(session);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (r < 0)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering reply = dbus_message_new_method_return(message);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (!reply) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = -ENOMEM;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering p = session_bus_path(session);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (!p) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = -ENOMEM;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering seat = s ? s->id : "";
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering b = dbus_message_append_args(
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering reply,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_STRING, &session->id,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_STRING, &session->user->runtime_path,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_UNIX_FD, &fifo_fd,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_STRING, &seat,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_UINT32, &vtnr,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_INVALID);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering free(p);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (!b) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = -ENOMEM;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering close_nointr_nofail(fifo_fd);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering *_reply = reply;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering return 0;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poetteringfail:
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering strv_free(controllers);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering strv_free(reset_controllers);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (session)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering session_add_to_gc_queue(session);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (user)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering user_add_to_gc_queue(user);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (fifo_fd >= 0)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering close_nointr_nofail(fifo_fd);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (reply)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering dbus_message_unref(reply);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering return r;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering}
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poetteringstatic int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessage *message, DBusError *error, DBusMessage **_reply) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering Inhibitor *i = NULL;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering char *id = NULL;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering const char *who, *why, *what;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering pid_t pid;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering InhibitWhat w;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering unsigned long ul;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering int r, fifo_fd = -1;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBusMessage *reply = NULL;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering assert(m);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering assert(connection);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering assert(message);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering assert(error);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering assert(_reply);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (!dbus_message_get_args(
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering message,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering error,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_STRING, &what,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_STRING, &who,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_STRING, &why,
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBUS_TYPE_INVALID)) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = -EIO;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering w = inhibit_what_from_string(what);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (w <= 0) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = -EINVAL;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = verify_polkit(connection, message, "org.freedesktop.login1.inhibit", false, NULL, error);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (r < 0)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering if (ul == (unsigned long) -1) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering r = -EIO;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto fail;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering }
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering pid = bus_get_unix_process_id(connection, dbus_message_get_sender(message), error);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (pid <= 0) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = -EIO;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen do {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(id);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering id = NULL;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = -ENOMEM;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen goto fail;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering } while (hashmap_get(m->inhibitors, id));
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = manager_add_inhibitor(m, id, &i);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen free(id);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (r < 0)
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen goto fail;
a9feff3d774eaa1cc1b59189e8f344c01e69f888Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen i->what = w;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen i->pid = pid;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen i->uid = (uid_t) ul;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen i->why = strdup(why);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen i->who = strdup(who);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (!i->why || !i->who) {
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen r = -ENOMEM;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen goto fail;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen }
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen fifo_fd = inhibitor_create_fifo(i);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (fifo_fd < 0) {
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen r = fifo_fd;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen goto fail;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen }
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen reply = dbus_message_new_method_return(message);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (!reply) {
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!dbus_message_append_args(
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen reply,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_UNIX_FD, &fifo_fd,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_INVALID)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto fail;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen close_nointr_nofail(fifo_fd);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen *_reply = reply;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering inhibitor_start(i);
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering return 0;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poetteringfail:
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering if (i)
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering inhibitor_free(i);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (fifo_fd >= 0)
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen close_nointr_nofail(fifo_fd);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering if (reply)
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering dbus_message_unref(reply);
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering return r;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering}
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poetteringstatic int trigger_device(Manager *m, struct udev_device *d) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering struct udev_enumerate *e;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering struct udev_list_entry *first, *item;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen int r;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen assert(m);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering e = udev_enumerate_new(m->udev);
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering if (!e) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering r = -ENOMEM;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering goto finish;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering }
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering if (d) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering if (udev_enumerate_add_match_parent(e, d) < 0) {
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen r = -EIO;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen goto finish;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen }
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen }
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (udev_enumerate_scan_devices(e) < 0) {
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen r = -EIO;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen goto finish;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen }
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen first = udev_enumerate_get_list_entry(e);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen udev_list_entry_foreach(item, first) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering char *t;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering const char *p;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering p = udev_list_entry_get_name(item);
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering t = strappend(p, "/uevent");
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering if (!t) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering r = -ENOMEM;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering goto finish;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering }
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
b686acb27ea4de042320fa196cfb14e08f30165bTom Gundersen write_one_line_file(t, "change");
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen free(t);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = 0;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenfinish:
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (e)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen udev_enumerate_unref(e);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen return r;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen}
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poetteringstatic int attach_device(Manager *m, const char *seat, const char *sysfs) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering struct udev_device *d;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering char *rule = NULL, *file = NULL;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen const char *id_for_seat;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen int r;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen assert(m);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen assert(seat);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen assert(sysfs);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen d = udev_device_new_from_syspath(m->udev, sysfs);
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (!d)
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen return -ENODEV;
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen if (!udev_device_has_tag(d, "seat")) {
bda2c408f8a739c19161818bcc842107f60652a2Tom Gundersen r = -ENODEV;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto finish;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering id_for_seat = udev_device_get_property_value(d, "ID_FOR_SEAT");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!id_for_seat) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENODEV;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto finish;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0) {
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto finish;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto finish;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering mkdir_p("/etc/udev/rules.d", 0755);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = write_one_line_file_atomic(file, rule);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (r < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto finish;
40a1eebde6be7ac3f1885147fc24e06ad1da260cDavid Herrmann
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering r = trigger_device(m, d);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringfinish:
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering free(rule);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(file);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (d)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering udev_device_unref(d);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int flush_devices(Manager *m) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DIR *d;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering d = opendir("/etc/udev/rules.d");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!d) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (errno != ENOENT)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering log_warning("Failed to open /etc/udev/rules.d: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct dirent *de;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering while ((de = readdir(d))) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dirent_is_file(de))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering continue;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!startswith(de->d_name, "72-seat-"))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering continue;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!endswith(de->d_name, ".rules"))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering continue;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (unlinkat(dirfd(d), de->d_name, 0) < 0)
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering log_warning("Failed to unlink %s: %m", de->d_name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering closedir(d);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return trigger_device(m, NULL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic int have_multiple_sessions(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBusConnection *connection,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Manager *m,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessage *message,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBusError *error) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering Session *s;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert(m);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (hashmap_size(m->sessions) > 1)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return true;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering /* Hmm, there's only one session, but let's make sure it
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering * actually belongs to the user who is asking. If not, better
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering * be safe than sorry. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering s = hashmap_first(m->sessions);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (s) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering unsigned long ul;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (ul == (unsigned long) -1)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EIO;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return s->user->uid != ul;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return false;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering}
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic const BusProperty bus_login_manager_properties[] = {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "ControlGroupHierarchy", bus_property_append_string, "s", offsetof(Manager, cgroup_path), true },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "Controllers", bus_property_append_strv, "as", offsetof(Manager, controllers), true },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "ResetControllers", bus_property_append_strv, "as", offsetof(Manager, reset_controllers), true },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "NAutoVTs", bus_property_append_unsigned, "u", offsetof(Manager, n_autovts) },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "KillOnlyUsers", bus_property_append_strv, "as", offsetof(Manager, kill_only_users), true },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "KillExcludeUsers", bus_property_append_strv, "as", offsetof(Manager, kill_exclude_users), true },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "KillUserProcesses", bus_property_append_bool, "b", offsetof(Manager, kill_user_processes) },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "IdleHint", bus_manager_append_idle_hint, "b", 0 },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "IdleSinceHint", bus_manager_append_idle_hint_since, "t", 0 },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "IdleSinceHintMonotonic", bus_manager_append_idle_hint_since, "t", 0 },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "Inhibited", bus_manager_append_inhibited, "s", 0 },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { NULL, }
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering};
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenstatic DBusHandlerResult manager_message_handler(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBusConnection *connection,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBusMessage *message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering void *userdata) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Manager *m = userdata;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusError error;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBusMessage *reply = NULL;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering int r;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert(connection);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering dbus_error_init(&error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSession")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering const char *name;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering char *p;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering Session *session;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering bool b;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!dbus_message_get_args(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering &error,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_STRING, &name,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_INVALID))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering session = hashmap_get(m->sessions, name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!session)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering reply = dbus_message_new_method_return(message);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (!reply)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering p = session_bus_path(session);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!p)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering b = dbus_message_append_args(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering reply,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (!b)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSessionByPID")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t pid;
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Session *session;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool b;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering message,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering &error,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_UINT32, &pid,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen DBUS_TYPE_INVALID))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen r = manager_get_session_by_pid(m, pid, &session);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r <= 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, NULL, r < 0 ? r : -ENOENT);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering p = session_bus_path(session);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!p)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering b = dbus_message_append_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_INVALID);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering free(p);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!b)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetUser")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t uid;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering User *user;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool b;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen if (!dbus_message_get_args(
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering message,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering &error,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_UINT32, &uid,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_INVALID))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!user)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen p = user_bus_path(user);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!p)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering b = dbus_message_append_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!b)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSeat")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *name;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Seat *seat;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool b;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_get_args(
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering message,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering &error,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_STRING, &name,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBUS_TYPE_INVALID))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering seat = hashmap_get(m->seats, name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!seat)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering reply = dbus_message_new_method_return(message);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!reply)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering p = seat_bus_path(seat);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!p)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering b = dbus_message_append_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!b)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListSessions")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Session *session;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Iterator i;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessageIter iter, sub;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *empty = "";
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_init_append(reply, &iter);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(susso)", &sub))
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering HASHMAP_FOREACH(session, m->sessions, i) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessageIter sub2;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t uid;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uid = session->user->uid;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering p = session_bus_path(session);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!p)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->id) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &uid) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->user->name) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, session->seat ? (const char**) &session->seat->id : &empty) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering }
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListUsers")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering char *p;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering User *user;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Iterator i;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessageIter iter, sub;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering reply = dbus_message_new_method_return(message);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!reply)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering dbus_message_iter_init_append(reply, &iter);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(uso)", &sub))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering HASHMAP_FOREACH(user, m->users, i) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessageIter sub2;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t uid;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uid = user->uid;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering p = user_bus_path(user);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!p)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &uid) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &user->name) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListSeats")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering char *p;
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering Seat *seat;
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering Iterator i;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBusMessageIter iter, sub;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering dbus_message_iter_init_append(reply, &iter);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(so)", &sub))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering HASHMAP_FOREACH(seat, m->seats, i) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DBusMessageIter sub2;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto oom;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering p = seat_bus_path(seat);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!p)
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering goto oom;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &seat->id) ||
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering free(p);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering }
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering free(p);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering }
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListInhibitors")) {
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering Inhibitor *inhibitor;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering Iterator i;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering DBusMessageIter iter, sub;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering reply = dbus_message_new_method_return(message);
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering if (!reply)
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_init_append(reply, &iter);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sssuu)", &sub))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering HASHMAP_FOREACH(inhibitor, m->inhibitors, i) {
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering DBusMessageIter sub2;
5cb36f41f01cf4b1f4395abfffd1b33116591e58Lennart Poettering dbus_uint32_t uid, pid;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *what, *who, *why;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering what = inhibit_what_to_string(inhibitor->what);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering who = strempty(inhibitor->who);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering why = strempty(inhibitor->why);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering uid = (dbus_uint32_t) inhibitor->uid;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering pid = (dbus_uint32_t) inhibitor->pid;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &what) ||
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &who) ||
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &why) ||
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &uid) ||
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &pid))
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "Inhibit")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering r = bus_manager_inhibit(m, connection, message, &error, &reply);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r < 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CreateSession")) {
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = bus_manager_create_session(m, message, &reply);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Don't delay the work on OOM here, since it might be
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * triggered by a low RLIMIT_NOFILE here (since we
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * send a dupped fd to the client), and we'd rather
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * see this fail quickly then be retried later */
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (r < 0)
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering return bus_send_error_reply(connection, message, NULL, r);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ReleaseSession")) {
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering const char *name;
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering Session *session;
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering if (!dbus_message_get_args(
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering message,
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering &error,
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering DBUS_TYPE_STRING, &name,
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering DBUS_TYPE_INVALID))
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering session = hashmap_get(m->sessions, name);
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering if (!session)
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering /* We use the FIFO to detect stray sessions where the
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering process invoking PAM dies abnormally. We need to make
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering sure that that process is not killed if at the clean
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering end of the session it closes the FIFO. Hence, with
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering this call explicitly turn off the FIFO logic, so that
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering the PAM code can finish clean up on its own */
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering session_remove_fifo(session);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSession")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering const char *name;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Session *session;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering message,
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering &error,
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering DBUS_TYPE_STRING, &name,
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering DBUS_TYPE_INVALID))
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering session = hashmap_get(m->sessions, name);
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering if (!session)
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = session_activate(session);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering if (r < 0)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering return bus_send_error_reply(connection, message, NULL, r);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering reply = dbus_message_new_method_return(message);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering if (!reply)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSessionOnSeat")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering const char *session_name, *seat_name;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering Session *session;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Seat *seat;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering /* Same as ActivateSession() but refuses to work if
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering * the seat doesn't match */
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering message,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering &error,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_STRING, &session_name,
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering DBUS_TYPE_STRING, &seat_name,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering session = hashmap_get(m->sessions, session_name);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!session)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering seat = hashmap_get(m->seats, seat_name);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!seat)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering if (session->seat != seat)
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering r = session_activate(session);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (r < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSession") ||
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "UnlockSession")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering const char *name;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Session *session;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering message,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering &error,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_STRING, &name,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering session = hashmap_get(m->sessions, name);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!session)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (session_send_lock(session, streq(dbus_message_get_member(message), "LockSession")) < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "KillSession")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering const char *swho;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering int32_t signo;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering KillWho who;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering const char *name;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Session *session;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering message,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering &error,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_STRING, &name,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_STRING, &swho,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INT32, &signo,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (isempty(swho))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering who = KILL_ALL;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering else {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering who = kill_who_from_string(swho);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (who < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering }
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (signo <= 0 || signo >= _NSIG)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering session = hashmap_get(m->sessions, name);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!session)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering r = session_kill(session, who, signo);
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering if (r < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "KillUser")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering uint32_t uid;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering User *user;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering int32_t signo;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering if (!dbus_message_get_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering message,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering &error,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_UINT32, &uid,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INT32, &signo,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID))
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (signo <= 0 || signo >= _NSIG)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!user)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering r = user_kill(user, signo);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (r < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSession")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering const char *name;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering Session *session;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering message,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering &error,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_STRING, &name,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering session = hashmap_get(m->sessions, name);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!session)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering r = session_stop(session);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (r < 0)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering reply = dbus_message_new_method_return(message);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!reply)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering goto oom;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateUser")) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering uint32_t uid;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering User *user;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!dbus_message_get_args(
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering message,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering &error,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_UINT32, &uid,
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering DBUS_TYPE_INVALID))
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (!user)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = user_stop(user);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering return bus_send_error_reply(connection, message, NULL, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering reply = dbus_message_new_method_return(message);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!reply)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering goto oom;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSeat")) {
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering const char *name;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering Seat *seat;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering if (!dbus_message_get_args(
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering &error,
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering DBUS_TYPE_STRING, &name,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_INVALID))
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering seat = hashmap_get(m->seats, name);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering if (!seat)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = seat_stop_sessions(seat);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering reply = dbus_message_new_method_return(message);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!reply)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "SetUserLinger")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering uint32_t uid;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering struct passwd *pw;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering dbus_bool_t b, interactive;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering char *path;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!dbus_message_get_args(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering &error,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_UINT32, &uid,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_BOOLEAN, &b,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_BOOLEAN, &interactive,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_INVALID))
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering errno = 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering pw = getpwuid(uid);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!pw)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, NULL, errno ? -errno : -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = verify_polkit(connection, message, "org.freedesktop.login1.set-user-linger", interactive, NULL, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering mkdir_p("/var/lib/systemd", 0755);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = safe_mkdir("/var/lib/systemd/linger", 0755, 0, 0);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering path = strappend("/var/lib/systemd/linger/", pw->pw_name);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!path)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (b) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering User *u;
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = touch(path);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering free(path);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (manager_add_user_by_uid(m, uid, &u) >= 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering user_start(u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering User *u;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = unlink(path);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering free(path);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0 && errno != ENOENT)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, -errno);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (u)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering user_add_to_gc_queue(u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering reply = dbus_message_new_method_return(message);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!reply)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "AttachDevice")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering const char *sysfs, *seat;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering dbus_bool_t interactive;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!dbus_message_get_args(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering &error,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_STRING, &seat,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_STRING, &sysfs,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_BOOLEAN, &interactive,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_INVALID))
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!path_startswith(sysfs, "/sys") || !seat_name_is_valid(seat))
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, NULL, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = verify_polkit(connection, message, "org.freedesktop.login1.attach-device", interactive, NULL, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = attach_device(m, seat, sysfs);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, NULL, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering reply = dbus_message_new_method_return(message);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!reply)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "FlushDevices")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering dbus_bool_t interactive;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!dbus_message_get_args(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering &error,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_BOOLEAN, &interactive,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_INVALID))
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = verify_polkit(connection, message, "org.freedesktop.login1.flush-devices", interactive, NULL, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = flush_devices(m);
bf3f1271e2cc0c22b11c8a805a997578dabe9191Lennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, NULL, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering reply = dbus_message_new_method_return(message);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!reply)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto oom;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "PowerOff") ||
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "Reboot")) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering dbus_bool_t interactive;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering bool multiple_sessions, inhibit;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBusMessage *forward, *freply;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering const char *name, *action;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering const char *mode = "replace";
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!dbus_message_get_args(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering message,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering &error,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_BOOLEAN, &interactive,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DBUS_TYPE_INVALID))
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = have_multiple_sessions(connection, m, message, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering multiple_sessions = r > 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering inhibit = manager_is_inhibited(m, INHIBIT_SHUTDOWN, NULL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (multiple_sessions) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering action = streq(dbus_message_get_member(message), "PowerOff") ?
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.login1.power-off-multiple-sessions" :
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.login1.reboot-multiple-sessions";
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = verify_polkit(connection, message, action, interactive, NULL, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (inhibit) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering action = streq(dbus_message_get_member(message), "PowerOff") ?
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.login1.power-off-ignore-inhibit" :
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.login1.reboot-ignore-inhibit";
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = verify_polkit(connection, message, action, interactive, NULL, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!multiple_sessions && !inhibit) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering action = streq(dbus_message_get_member(message), "PowerOff") ?
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.login1.power-off" :
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.login1.reboot";
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = verify_polkit(connection, message, action, interactive, NULL, &error);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, &error, r);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering forward = dbus_message_new_method_call(
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.systemd1",
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "/org/freedesktop/systemd1",
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "org.freedesktop.systemd1.Manager",
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering "StartUnit");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!forward)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return bus_send_error_reply(connection, message, NULL, -ENOMEM);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering name = streq(dbus_message_get_member(message), "PowerOff") ?
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering SPECIAL_POWEROFF_TARGET : SPECIAL_REBOOT_TARGET;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!dbus_message_append_args(forward,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DBUS_TYPE_STRING, &name,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DBUS_TYPE_STRING, &mode,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DBUS_TYPE_INVALID)) {
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering dbus_message_unref(forward);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering return bus_send_error_reply(connection, message, NULL, -ENOMEM);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering }
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering freply = dbus_connection_send_with_reply_and_block(connection, forward, -1, &error);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering dbus_message_unref(forward);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (!freply)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering return bus_send_error_reply(connection, message, &error, -EIO);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_unref(freply);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering reply = dbus_message_new_method_return(message);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering if (!reply)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering goto oom;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CanPowerOff") ||
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CanReboot")) {
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering bool multiple_sessions, challenge, inhibit, b;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering const char *action, *result;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering r = have_multiple_sessions(connection, m, message, &error);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r < 0)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering multiple_sessions = r > 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering inhibit = manager_is_inhibited(m, INHIBIT_SHUTDOWN, NULL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (multiple_sessions) {
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering action = streq(dbus_message_get_member(message), "CanPowerOff") ?
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering "org.freedesktop.login1.power-off-multiple-sessions" :
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering "org.freedesktop.login1.reboot-multiple-sessions";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering r = verify_polkit(connection, message, action, false, &challenge, &error);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r < 0)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r > 0)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "yes";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering else if (challenge)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "challenge";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering else
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering result = "no";
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering }
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering if (inhibit) {
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering action = streq(dbus_message_get_member(message), "CanPowerOff") ?
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering "org.freedesktop.login1.power-off-ignore-inhibit" :
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering "org.freedesktop.login1.reboot-ignore-inhibit";
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering
556a22945fcc88ca27ae7ecc46c9bb2727e37895Lennart Poettering r = verify_polkit(connection, message, action, false, &challenge, &error);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r < 0)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r > 0 && !result)
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering result = "yes";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering else if (challenge && (!result || streq(result, "yes")))
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "challenge";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering else
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "no";
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!multiple_sessions && !inhibit) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering /* If neither inhibit nor multiple sessions
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * apply then just check the normal policy */
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering action = streq(dbus_message_get_member(message), "CanPowerOff") ?
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering "org.freedesktop.login1.power-off" :
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering "org.freedesktop.login1.reboot";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering r = verify_polkit(connection, message, action, false, &challenge, &error);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r < 0)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (r > 0)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "yes";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering else if (challenge)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "challenge";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering else
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering result = "no";
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering }
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering reply = dbus_message_new_method_return(message);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering if (!reply)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering goto oom;
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering b = dbus_message_append_args(
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering reply,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering DBUS_TYPE_STRING, &result,
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering DBUS_TYPE_INVALID);
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering if (!b)
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering goto oom;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering char *introspection = NULL;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering FILE *f;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering Iterator i;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering Session *session;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering Seat *seat;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering User *user;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering size_t size;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering char *p;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering if (!(reply = dbus_message_new_method_return(message)))
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering goto oom;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering /* We roll our own introspection code here, instead of
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering * relying on bus_default_message_handler() because we
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering * need to generate our introspection string
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering * dynamically. */
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering if (!(f = open_memstream(&introspection, &size)))
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering goto oom;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering fputs(INTROSPECTION_BEGIN, f);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering HASHMAP_FOREACH(seat, m->seats, i) {
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering p = bus_path_escape(seat->id);
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering if (p) {
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering fprintf(f, "<node name=\"seat/%s\"/>", p);
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering free(p);
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering }
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering }
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering HASHMAP_FOREACH(user, m->users, i)
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering fprintf(f, "<node name=\"user/%llu\"/>", (unsigned long long) user->uid);
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering HASHMAP_FOREACH(session, m->sessions, i) {
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering p = bus_path_escape(session->id);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (p) {
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering fprintf(f, "<node name=\"session/%s\"/>", p);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering free(p);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering }
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering }
fputs(INTROSPECTION_END, f);
if (ferror(f)) {
fclose(f);
free(introspection);
goto oom;
}
fclose(f);
if (!introspection)
goto oom;
if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
free(introspection);
goto oom;
}
free(introspection);
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.login1.Manager", bus_login_manager_properties, m },
{ NULL, }
};
return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, bps);
}
if (reply) {
if (!dbus_connection_send(connection, reply, NULL))
goto oom;
dbus_message_unref(reply);
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
dbus_message_unref(reply);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
const DBusObjectPathVTable bus_manager_vtable = {
.message_function = manager_message_handler
};
DBusHandlerResult bus_message_filter(
DBusConnection *connection,
DBusMessage *message,
void *userdata) {
Manager *m = userdata;
DBusError error;
assert(m);
assert(connection);
assert(message);
dbus_error_init(&error);
if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) {
const char *cgroup;
if (!dbus_message_get_args(message, &error,
DBUS_TYPE_STRING, &cgroup,
DBUS_TYPE_INVALID))
log_error("Failed to parse Released message: %s", bus_error_message(&error));
else
manager_cgroup_notify_empty(m, cgroup);
}
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
int manager_send_changed(Manager *manager, const char *properties) {
DBusMessage *m;
int r = -ENOMEM;
assert(manager);
m = bus_properties_changed_new("/org/freedesktop/login1", "org.freedesktop.login1.Manager", properties);
if (!m)
goto finish;
if (!dbus_connection_send(manager->bus, m, NULL))
goto finish;
r = 0;
finish:
if (m)
dbus_message_unref(m);
return r;
}