logind-dbus.c revision 84c3361e129a5ae7a5a408b1562f7f2336b1de3a
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2011 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering***/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek#include <errno.h>
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek#include <string.h>
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include <unistd.h>
4ad7f2761da661853dcc29d542efb4727abb1101Nick Owens#include <pwd.h>
7263f72499e962b3fd54cdb7c79d49ca72121edeZbigniew Jędrzejewski-Szmek
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering#include "logind.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "dbus-common.h"
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering#include "strv.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "polkit.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "special.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering#define BUS_MANAGER_INTERFACE \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <interface name=\"org.freedesktop.login1.Manager\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"GetSession\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"GetSessionByPID\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"session\" type=\"o\" direction=\"out\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"GetUser\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"user\" type=\"o\" direction=\"out\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"GetSeat\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"ListSessions\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"sessions\" type=\"a(susso)\" direction=\"out\"/>\n" \
7c1ff6ac3d9e3acae1d601d40728cf7ccc9a7730Tom Gundersen " </method>\n" \
7c1ff6ac3d9e3acae1d601d40728cf7ccc9a7730Tom Gundersen " <method name=\"ListUsers\">\n" \
7c1ff6ac3d9e3acae1d601d40728cf7ccc9a7730Tom Gundersen " <arg name=\"users\" type=\"a(uso)\" direction=\"out\"/>\n" \
7c1ff6ac3d9e3acae1d601d40728cf7ccc9a7730Tom Gundersen " </method>\n" \
7c1ff6ac3d9e3acae1d601d40728cf7ccc9a7730Tom Gundersen " <method name=\"ListSeats\">\n" \
7c1ff6ac3d9e3acae1d601d40728cf7ccc9a7730Tom Gundersen " <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n" \
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen " </method>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <method name=\"CreateSession\">\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen " <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n" \
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen " <arg name=\"sevice\" type=\"s\" direction=\"in\"/>\n" \
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen " <arg name=\"type\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"vtnr\" type=\"u\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"tty\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"display\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"remote\" type=\"b\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"remote_user\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"remote_host\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"controllers\" type=\"as\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"reset_controllers\" type=\"as\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"kill_processes\" type=\"b\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"out\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"path\" type=\"o\" direction=\"out\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"runtime_path\" type=\"o\" direction=\"out\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"out\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"vtnr\" type=\"u\" direction=\"out\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " </method>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <method name=\"ActivateSession\">\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " </method>\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <method name=\"ActivateSessionOnSeat\">\n" \
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen " <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"LockSession\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"UnlockSession\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"KillSession\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"who\" type=\"s\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"signal\" type=\"s\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"KillUser\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"signal\" type=\"s\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"TerminateSession\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"TerminateUser\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"TerminateSeat\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"SetUserLinger\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"b\" type=\"b\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <method name=\"AttachDevice\">\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"sysfs\" type=\"s\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"FlushDevices\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"PowerOff\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"Reboot\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <signal name=\"SessionNew\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </signal>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <signal name=\"SessionRemoved\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </signal>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <signal name=\"UserNew\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"uid\" type=\"u\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </signal>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <signal name=\"UserRemoved\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"uid\" type=\"u\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </signal>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <signal name=\"SeatNew\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </signal>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <signal name=\"SeatRemoved\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"path\" type=\"o\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </signal>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"NAutoVTs\" type=\"u\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"KillOnlyUsers\" type=\"as\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"KillExcludeUsers\" type=\"as\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"KillUserProcesses\" type=\"b\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </interface>\n"
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering#define INTROSPECTION_BEGIN \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering "<node>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering BUS_MANAGER_INTERFACE \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering BUS_PROPERTIES_INTERFACE \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering BUS_PEER_INTERFACE \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering BUS_INTROSPECTABLE_INTERFACE
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering#define INTROSPECTION_END \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering "</node>\n"
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering#define INTERFACES_LIST \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering BUS_GENERIC_INTERFACES_LIST \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering "org.freedesktop.login1.Manager\0"
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic int bus_manager_append_idle_hint(DBusMessageIter *i, const char *property, void *data) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Manager *m = data;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering dbus_bool_t b;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(i);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(property);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(m);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering b = manager_get_idle_hint(m, NULL) > 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -ENOMEM;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poetteringstatic int bus_manager_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering Manager *m = data;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering dual_timestamp t;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering uint64_t u;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(i);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(property);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(m);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering manager_get_idle_hint(m, &t);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -ENOMEM;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Session *session = NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering User *user = NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering const char *type, *seat, *tty, *display, *remote_user, *remote_host, *service;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint32_t uid, leader, audit_id = 0;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering dbus_bool_t remote, kill_processes;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering char **controllers = NULL, **reset_controllers = NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering SessionType t;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering Seat *s;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering DBusMessageIter iter;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering char *id = NULL, *p;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering uint32_t vtnr = 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering int fifo_fd = -1;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering DBusMessage *reply = NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering bool b;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(m);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(message);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(_reply);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!dbus_message_iter_init(message, &iter) ||
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return -EINVAL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering dbus_message_iter_get_basic(&iter, &uid);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!dbus_message_iter_next(&iter) ||
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &leader);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (leader <= 0 ||
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering !dbus_message_iter_next(&iter) ||
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -EINVAL;
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen dbus_message_iter_get_basic(&iter, &service);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!dbus_message_iter_next(&iter) ||
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt return -EINVAL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering dbus_message_iter_get_basic(&iter, &type);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering t = session_type_from_string(type);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (t < 0 ||
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering !dbus_message_iter_next(&iter) ||
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -EINVAL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering dbus_message_iter_get_basic(&iter, &seat);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (isempty(seat))
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering s = NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering else {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering s = hashmap_get(m->seats, seat);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!s)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -ENOENT;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!dbus_message_iter_next(&iter) ||
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt return -EINVAL;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt dbus_message_iter_get_basic(&iter, &vtnr);
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_iter_next(&iter) ||
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -EINVAL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dbus_message_iter_get_basic(&iter, &tty);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (tty_is_vc(tty)) {
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen int v;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering s = m->vtconsole;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering else if (s != m->vtconsole)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -EINVAL;
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering v = vtnr_from_tty(tty);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (v <= 0)
23432a1c249b9c513e438bffe9778a7ce2ee74feZbigniew Jędrzejewski-Szmek return v < 0 ? v : -EINVAL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (vtnr <= 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering vtnr = (uint32_t) v;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering else if (vtnr != (uint32_t) v)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -EINVAL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering } else if (!isempty(tty) && s && seat_is_vtconsole(s))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (s) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (seat_can_multi_session(s)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (vtnr <= 0 || vtnr > 63)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (vtnr > 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering if (!dbus_message_iter_next(&iter) ||
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return -EINVAL;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering dbus_message_iter_get_basic(&iter, &display);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering if (!dbus_message_iter_next(&iter) ||
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return -EINVAL;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &remote);
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;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &remote_user);
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;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(&iter, &remote_host);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_next(&iter) ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EINVAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = bus_parse_strv_iter(&iter, &controllers);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r < 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -EINVAL;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (strv_contains(controllers, "systemd") ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering !dbus_message_iter_next(&iter) ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = -EINVAL;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek goto fail;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek }
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering r = bus_parse_strv_iter(&iter, &reset_controllers);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (r < 0)
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek goto fail;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (strv_contains(reset_controllers, "systemd") ||
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering !dbus_message_iter_next(&iter) ||
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek r = -EINVAL;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering goto fail;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek }
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering dbus_message_iter_get_basic(&iter, &kill_processes);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = manager_add_user_by_uid(m, uid, &user);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (r < 0)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering goto fail;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek audit_session_from_pid(leader, &audit_id);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (audit_id > 0) {
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek asprintf(&id, "%lu", (unsigned long) audit_id);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (!id) {
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen r = -ENOMEM;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen goto fail;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen }
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering session = hashmap_get(m->sessions, id);
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (session) {
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering free(id);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek fifo_fd = session_create_fifo(session);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (fifo_fd < 0) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek r = fifo_fd;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto fail;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek /* Session already exists, client is probably
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek * something like "su" which changes uid but
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen * is still the same audit session */
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen reply = dbus_message_new_method_return(message);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!reply) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = -ENOMEM;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen goto fail;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen }
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen p = session_bus_path(session);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!p) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen r = -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek goto fail;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek }
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek seat = session->seat ? session->seat->id : "";
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering vtnr = session->vtnr;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek b = dbus_message_append_args(
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering reply,
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek DBUS_TYPE_STRING, &session->id,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DBUS_TYPE_STRING, &session->user->runtime_path,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DBUS_TYPE_UNIX_FD, &fifo_fd,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DBUS_TYPE_STRING, &seat,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DBUS_TYPE_UINT32, &vtnr,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DBUS_TYPE_INVALID);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(p);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!b) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto fail;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering close_nointr_nofail(fifo_fd);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering *_reply = reply;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering strv_free(controllers);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering strv_free(reset_controllers);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } else {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering do {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering free(id);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering asprintf(&id, "c%lu", ++m->session_counter);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!id) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto fail;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering } while (hashmap_get(m->sessions, id));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = manager_add_session(m, user, id, &session);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering free(id);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering goto fail;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering session->leader = leader;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering session->audit_id = audit_id;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering session->type = t;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->remote = remote;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->controllers = controllers;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->reset_controllers = reset_controllers;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->kill_processes = kill_processes;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->vtnr = vtnr;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering controllers = reset_controllers = NULL;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!isempty(tty)) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->tty = strdup(tty);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!session->tty) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering r = -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering goto fail;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering }
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering }
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!isempty(display)) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->display = strdup(display);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!session->display) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering r = -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering goto fail;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering }
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering }
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!isempty(remote_user)) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering session->remote_user = strdup(remote_user);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!session->remote_user) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering r = -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering goto fail;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!isempty(remote_host)) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering session->remote_host = strdup(remote_host);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!session->remote_host) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering r = -ENOMEM;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering goto fail;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering if (!isempty(service)) {
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering session->service = strdup(service);
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering if (!session->service) {
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering r = -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto fail;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering fifo_fd = session_create_fifo(session);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (fifo_fd < 0) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = fifo_fd;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering goto fail;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (s) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = seat_attach_session(s, session);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering goto fail;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = session_start(session);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto fail;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek reply = dbus_message_new_method_return(message);
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann if (!reply) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering r = -ENOMEM;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek goto fail;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering p = session_bus_path(session);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!p) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering r = -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto fail;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering seat = s ? s->id : "";
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering b = dbus_message_append_args(
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering reply,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_STRING, &session->id,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_STRING, &session->user->runtime_path,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_UNIX_FD, &fifo_fd,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_STRING, &seat,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_UINT32, &vtnr,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering DBUS_TYPE_INVALID);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering free(p);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek if (!b) {
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek r = -ENOMEM;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek goto fail;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek }
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek close_nointr_nofail(fifo_fd);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek *_reply = reply;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return 0;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekfail:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek strv_free(controllers);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek strv_free(reset_controllers);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (session)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek session_add_to_gc_queue(session);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (user)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen user_add_to_gc_queue(user);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (fifo_fd >= 0)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen close_nointr_nofail(fifo_fd);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (reply)
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering dbus_message_unref(reply);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen return r;
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen}
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmekstatic int trigger_device(Manager *m, struct udev_device *d) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek struct udev_enumerate *e;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek struct udev_list_entry *first, *item;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek int r;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek assert(m);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek e = udev_enumerate_new(m->udev);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (!e) {
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn r = -ENOMEM;
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn goto finish;
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn }
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn if (d) {
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn if (udev_enumerate_add_match_parent(e, d) < 0) {
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn r = -EIO;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto finish;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (udev_enumerate_scan_devices(e) < 0) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek r = -EIO;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen goto finish;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen }
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen first = udev_enumerate_get_list_entry(e);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen udev_list_entry_foreach(item, first) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen char *t;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen const char *p;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen p = udev_list_entry_get_name(item);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen t = strappend(p, "/uevent");
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!t) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen r = -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto finish;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering write_one_line_file(t, "change");
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(t);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = 0;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekfinish:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (e)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek udev_enumerate_unref(e);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return r;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek}
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekstatic int attach_device(Manager *m, const char *seat, const char *sysfs) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek struct udev_device *d;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek char *rule = NULL, *file = NULL;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek const char *id_for_seat;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek int r;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert(m);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert(seat);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert(sysfs);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek d = udev_device_new_from_syspath(m->udev, sysfs);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!d)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENODEV;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!udev_device_has_tag(d, "seat")) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = -ENODEV;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek goto finish;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek }
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek id_for_seat = udev_device_get_property_value(d, "ID_FOR_SEAT");
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!id_for_seat) {
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen r = -ENODEV;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen goto finish;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen }
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0) {
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen r = -ENOMEM;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen goto finish;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen }
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) {
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen r = -ENOMEM;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen goto finish;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen }
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen mkdir_p("/etc/udev/rules.d", 0755);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = write_one_line_file_atomic(file, rule);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen goto finish;
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = trigger_device(m, d);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersenfinish:
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen free(rule);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen free(file);
2c1fb4f71206bf970d493294208c5d7597194856Lennart Poettering
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (d)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen udev_device_unref(d);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return r;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen}
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersenstatic int flush_devices(Manager *m) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen DIR *d;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
2c1fb4f71206bf970d493294208c5d7597194856Lennart Poettering assert(m);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen d = opendir("/etc/udev/rules.d");
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!d) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (errno != ENOENT)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen log_warning("Failed to open /etc/udev/rules.d: %m");
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen } else {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen struct dirent *de;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen while ((de = readdir(d))) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!dirent_is_file(de))
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen continue;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!startswith(de->d_name, "72-seat-"))
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering continue;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!endswith(de->d_name, ".rules"))
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering continue;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (unlinkat(dirfd(d), de->d_name, 0) < 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering log_warning("Failed to unlink %s: %m", de->d_name);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering }
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering closedir(d);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering }
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return trigger_device(m, NULL);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering}
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic const BusProperty bus_login_manager_properties[] = {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "ControlGroupHierarchy", bus_property_append_string, "s", offsetof(Manager, cgroup_path), true },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "Controllers", bus_property_append_strv, "as", offsetof(Manager, controllers), true },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "ResetControllers", bus_property_append_strv, "as", offsetof(Manager, reset_controllers), true },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "NAutoVTs", bus_property_append_unsigned, "u", offsetof(Manager, n_autovts) },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "KillOnlyUsers", bus_property_append_strv, "as", offsetof(Manager, kill_only_users), true },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "KillExcludeUsers", bus_property_append_strv, "as", offsetof(Manager, kill_exclude_users), true },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "KillUserProcesses", bus_property_append_bool, "b", offsetof(Manager, kill_user_processes) },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "IdleHint", bus_manager_append_idle_hint, "b", 0 },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "IdleSinceHint", bus_manager_append_idle_hint_since, "t", 0 },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { "IdleSinceHintMonotonic", bus_manager_append_idle_hint_since, "t", 0 },
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering { NULL, }
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering};
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic DBusHandlerResult manager_message_handler(
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering DBusConnection *connection,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering DBusMessage *message,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering void *userdata) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering Manager *m = userdata;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek DBusError error;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBusMessage *reply = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering int r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(connection);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(message);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(m);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dbus_error_init(&error);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSession")) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering const char *name;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering char *p;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering Session *session;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering bool b;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (!dbus_message_get_args(
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering message,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering &error,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering DBUS_TYPE_STRING, &name,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering DBUS_TYPE_INVALID))
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering session = hashmap_get(m->sessions, name);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!session)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering reply = dbus_message_new_method_return(message);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!reply)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering p = session_bus_path(session);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!p)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering b = dbus_message_append_args(
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering reply,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DBUS_TYPE_INVALID);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek free(p);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!b)
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek goto oom;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSessionByPID")) {
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek uint32_t pid;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek char *p;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek Session *session;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek bool b;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_get_args(
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering message,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering &error,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBUS_TYPE_UINT32, &pid,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBUS_TYPE_INVALID))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = manager_get_session_by_pid(m, pid, &session);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r <= 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return bus_send_error_reply(connection, message, NULL, r < 0 ? r : -ENOENT);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering reply = dbus_message_new_method_return(message);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!reply)
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek goto oom;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering p = session_bus_path(session);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!p)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering goto oom;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering b = dbus_message_append_args(
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering reply,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DBUS_TYPE_INVALID);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering free(p);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!b)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetUser")) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering uint32_t uid;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering char *p;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering User *user;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering bool b;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_get_args(
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering message,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering &error,
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek DBUS_TYPE_UINT32, &uid,
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek DBUS_TYPE_INVALID))
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return bus_send_error_reply(connection, message, &error, -EINVAL);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek if (!user)
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return bus_send_error_reply(connection, message, &error, -ENOENT);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek reply = dbus_message_new_method_return(message);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!reply)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek goto oom;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek p = user_bus_path(user);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!p)
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek goto oom;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek b = dbus_message_append_args(
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek reply,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek DBUS_TYPE_OBJECT_PATH, &p,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek DBUS_TYPE_INVALID);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek free(p);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!b)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek goto oom;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSeat")) {
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen const char *name;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen char *p;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen Seat *seat;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen bool b;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (!dbus_message_get_args(
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen message,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen &error,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen DBUS_TYPE_STRING, &name,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen DBUS_TYPE_INVALID))
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return bus_send_error_reply(connection, message, &error, -EINVAL);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen seat = hashmap_get(m->seats, name);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (!seat)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return bus_send_error_reply(connection, message, &error, -ENOENT);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen reply = dbus_message_new_method_return(message);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!reply)
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering goto oom;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering p = seat_bus_path(seat);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (!p)
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering goto oom;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek b = dbus_message_append_args(
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering reply,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering DBUS_TYPE_OBJECT_PATH, &p,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering DBUS_TYPE_INVALID);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering free(p);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek if (!b)
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek goto oom;
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListSessions")) {
1bf968f36393666f2c57953b1748e6219c027deeTom Gundersen char *p;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek Session *session;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek Iterator i;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBusMessageIter iter, sub;
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek const char *empty = "";
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek reply = dbus_message_new_method_return(message);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek if (!reply)
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek goto oom;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek dbus_message_iter_init_append(reply, &iter);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(susso)", &sub))
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek HASHMAP_FOREACH(session, m->sessions, i) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek DBusMessageIter sub2;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen uint32_t uid;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto oom;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
1bf968f36393666f2c57953b1748e6219c027deeTom Gundersen uid = session->user->uid;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek p = session_bus_path(session);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (!p)
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen goto oom;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->id) ||
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &uid) ||
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->user->name) ||
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, session->seat ? (const char**) &session->seat->id : &empty) ||
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen free(p);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto oom;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen free(p);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_close_container(&sub, &sub2))
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto oom;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_close_container(&iter, &sub))
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto oom;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListUsers")) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek char *p;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek User *user;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek Iterator i;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek DBusMessageIter iter, sub;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek reply = dbus_message_new_method_return(message);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (!reply)
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek goto oom;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen dbus_message_iter_init_append(reply, &iter);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(uso)", &sub))
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen goto oom;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen HASHMAP_FOREACH(user, m->users, i) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen DBusMessageIter sub2;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen uint32_t uid;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen goto oom;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen uid = user->uid;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen p = user_bus_path(user);
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering if (!p)
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen goto oom;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &uid) ||
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &user->name) ||
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen free(p);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen goto oom;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen }
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen free(p);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!dbus_message_iter_close_container(&sub, &sub2))
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen goto oom;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen }
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!dbus_message_iter_close_container(&iter, &sub))
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen goto oom;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListSeats")) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen char *p;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen Seat *seat;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen Iterator i;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen DBusMessageIter iter, sub;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen reply = dbus_message_new_method_return(message);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!reply)
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen goto oom;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek dbus_message_iter_init_append(reply, &iter);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(so)", &sub))
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek goto oom;
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen HASHMAP_FOREACH(seat, m->seats, i) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBusMessageIter sub2;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering p = seat_bus_path(seat);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!p)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &seat->id) ||
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(p);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering free(p);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CreateSession")) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = bus_manager_create_session(m, message, &reply);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering /* Don't delay the work on OOM here, since it might be
816b4547dac1b052239ad6ee3801c78c691e5cb4Daniel Mack * triggered by a low RLIMIT_NOFILE here (since we
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * send a dupped fd to the client), and we'd rather
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering * see this fail quickly then be retried later */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSession")) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering const char *name;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering Session *session;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!dbus_message_get_args(
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering message,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering &error,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering DBUS_TYPE_STRING, &name,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering DBUS_TYPE_INVALID))
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering session = hashmap_get(m->sessions, name);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!session)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering r = session_activate(session);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (r < 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return bus_send_error_reply(connection, message, NULL, r);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering reply = dbus_message_new_method_return(message);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!reply)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering goto oom;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ActivateSessionOnSeat")) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering const char *session_name, *seat_name;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering Session *session;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering Seat *seat;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
/* Same as ActivateSession() but refuses to work if
* the seat doesn't match */
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &session_name,
DBUS_TYPE_STRING, &seat_name,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
session = hashmap_get(m->sessions, session_name);
if (!session)
return bus_send_error_reply(connection, message, &error, -ENOENT);
seat = hashmap_get(m->seats, seat_name);
if (!seat)
return bus_send_error_reply(connection, message, &error, -ENOENT);
if (session->seat != seat)
return bus_send_error_reply(connection, message, &error, -EINVAL);
r = session_activate(session);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSession") ||
dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "UnlockSession")) {
const char *name;
Session *session;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
session = hashmap_get(m->sessions, name);
if (!session)
return bus_send_error_reply(connection, message, &error, -ENOENT);
if (session_send_lock(session, streq(dbus_message_get_member(message), "LockSession")) < 0)
goto oom;
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "KillSession")) {
const char *swho;
int32_t signo;
KillWho who;
const char *name;
Session *session;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &swho,
DBUS_TYPE_INT32, &signo,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
return bus_send_error_reply(connection, message, &error, -EINVAL);
}
if (signo <= 0 || signo >= _NSIG)
return bus_send_error_reply(connection, message, &error, -EINVAL);
session = hashmap_get(m->sessions, name);
if (!session)
return bus_send_error_reply(connection, message, &error, -ENOENT);
r = session_kill(session, who, signo);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "KillUser")) {
uint32_t uid;
User *user;
int32_t signo;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_UINT32, &uid,
DBUS_TYPE_INT32, &signo,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
if (signo <= 0 || signo >= _NSIG)
return bus_send_error_reply(connection, message, &error, -EINVAL);
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
return bus_send_error_reply(connection, message, &error, -ENOENT);
r = user_kill(user, signo);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSession")) {
const char *name;
Session *session;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
session = hashmap_get(m->sessions, name);
if (!session)
return bus_send_error_reply(connection, message, &error, -ENOENT);
r = session_stop(session);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateUser")) {
uint32_t uid;
User *user;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_UINT32, &uid,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
return bus_send_error_reply(connection, message, &error, -ENOENT);
r = user_stop(user);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSeat")) {
const char *name;
Seat *seat;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
seat = hashmap_get(m->seats, name);
if (!seat)
return bus_send_error_reply(connection, message, &error, -ENOENT);
r = seat_stop_sessions(seat);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "SetUserLinger")) {
uint32_t uid;
struct passwd *pw;
dbus_bool_t b, interactive;
char *path;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_UINT32, &uid,
DBUS_TYPE_BOOLEAN, &b,
DBUS_TYPE_BOOLEAN, &interactive,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
errno = 0;
pw = getpwuid(uid);
if (!pw)
return bus_send_error_reply(connection, message, NULL, errno ? -errno : -EINVAL);
r = verify_polkit(connection, message, "org.freedesktop.login1.set-user-linger", interactive, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
mkdir_p("/var/lib/systemd", 0755);
r = safe_mkdir("/var/lib/systemd/linger", 0755, 0, 0);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
path = strappend("/var/lib/systemd/linger/", pw->pw_name);
if (!path)
goto oom;
if (b) {
User *u;
r = touch(path);
free(path);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
if (manager_add_user_by_uid(m, uid, &u) >= 0)
user_start(u);
} else {
User *u;
r = unlink(path);
free(path);
if (r < 0 && errno != ENOENT)
return bus_send_error_reply(connection, message, &error, -errno);
u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (u)
user_add_to_gc_queue(u);
}
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "AttachDevice")) {
const char *sysfs, *seat;
dbus_bool_t interactive;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &seat,
DBUS_TYPE_STRING, &sysfs,
DBUS_TYPE_BOOLEAN, &interactive,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!path_startswith(sysfs, "/sys") || !seat_name_is_valid(seat))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
r = verify_polkit(connection, message, "org.freedesktop.login1.attach-device", interactive, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
r = attach_device(m, seat, sysfs);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, -EINVAL);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "FlushDevices")) {
dbus_bool_t interactive;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_BOOLEAN, &interactive,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
r = verify_polkit(connection, message, "org.freedesktop.login1.flush-devices", interactive, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
r = flush_devices(m);
if (r < 0)
return bus_send_error_reply(connection, message, NULL, -EINVAL);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "PowerOff") ||
dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "Reboot")) {
dbus_bool_t interactive;
bool multiple_sessions;
DBusMessage *forward, *freply;
const char *name;
const char *mode = "replace";
const char *action;
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_BOOLEAN, &interactive,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
multiple_sessions = hashmap_size(m->sessions) > 1;
if (!multiple_sessions) {
Session *s;
/* Hmm, there's only one session, but let's
* make sure it actually belongs to the user
* who is asking. If not, better be safe than
* sorry. */
s = hashmap_first(m->sessions);
if (s) {
unsigned long ul;
ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), &error);
if (ul == (unsigned long) -1)
return bus_send_error_reply(connection, message, &error, -EIO);
multiple_sessions = s->user->uid != ul;
}
}
if (streq(dbus_message_get_member(message), "PowerOff")) {
if (multiple_sessions)
action = "org.freedesktop.login1.power-off-multiple-sessions";
else
action = "org.freedesktop.login1.power-off";
name = SPECIAL_POWEROFF_TARGET;
} else {
if (multiple_sessions)
action = "org.freedesktop.login1.reboot-multiple-sessions";
else
action = "org.freedesktop.login1.reboot";
name = SPECIAL_REBOOT_TARGET;
}
r = verify_polkit(connection, message, action, interactive, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
forward = dbus_message_new_method_call(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit");
if (!forward)
return bus_send_error_reply(connection, message, NULL, -ENOMEM);
if (!dbus_message_append_args(forward,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &mode,
DBUS_TYPE_INVALID)) {
dbus_message_unref(forward);
return bus_send_error_reply(connection, message, NULL, -ENOMEM);
}
freply = dbus_connection_send_with_reply_and_block(connection, forward, -1, &error);
dbus_message_unref(forward);
if (!freply)
return bus_send_error_reply(connection, message, &error, -EIO);
dbus_message_unref(freply);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
char *introspection = NULL;
FILE *f;
Iterator i;
Session *session;
Seat *seat;
User *user;
size_t size;
char *p;
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
/* We roll our own introspection code here, instead of
* relying on bus_default_message_handler() because we
* need to generate our introspection string
* dynamically. */
if (!(f = open_memstream(&introspection, &size)))
goto oom;
fputs(INTROSPECTION_BEGIN, f);
HASHMAP_FOREACH(seat, m->seats, i) {
p = bus_path_escape(seat->id);
if (p) {
fprintf(f, "<node name=\"seat/%s\"/>", p);
free(p);
}
}
HASHMAP_FOREACH(user, m->users, i)
fprintf(f, "<node name=\"user/%llu\"/>", (unsigned long long) user->uid);
HASHMAP_FOREACH(session, m->sessions, i) {
p = bus_path_escape(session->id);
if (p) {
fprintf(f, "<node name=\"session/%s\"/>", p);
free(p);
}
}
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;
}