logind-dbus.c 95.1 KB
Newer Older
1 2 3 4 5 6 7 8
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/

/***
  This file is part of systemd.

  Copyright 2011 Lennart Poettering

  systemd is free software; you can redistribute it and/or modify it
9 10
  under the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 2.1 of the License, or
11 12 13 14 15
  (at your option) any later version.

  systemd is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
  Lesser General Public License for more details.
17

18
  You should have received a copy of the GNU Lesser General Public License
19 20 21
  along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/

22 23
#include <errno.h>
#include <string.h>
24
#include <unistd.h>
25
#include <pwd.h>
26

27 28
#include "logind.h"
#include "dbus-common.h"
29
#include "strv.h"
30
#include "mkdir.h"
Kay Sievers's avatar
Kay Sievers committed
31
#include "path-util.h"
32
#include "polkit.h"
33
#include "special.h"
34 35
#include "systemd/sd-id128.h"
#include "systemd/sd-messages.h"
36 37
#include "fileio-label.h"
#include "label.h"
38 39 40

#define BUS_MANAGER_INTERFACE                                           \
        " <interface name=\"org.freedesktop.login1.Manager\">\n"        \
41
        "  <method name=\"GetSession\">\n"                              \
42
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
43
        "   <arg name=\"session\" type=\"o\" direction=\"out\"/>\n"     \
44
        "  </method>\n"                                                 \
45 46 47 48
        "  <method name=\"GetSessionByPID\">\n"                         \
        "   <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n"          \
        "   <arg name=\"session\" type=\"o\" direction=\"out\"/>\n"     \
        "  </method>\n"                                                 \
49
        "  <method name=\"GetUser\">\n"                                 \
50
        "   <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n"          \
51 52
        "   <arg name=\"user\" type=\"o\" direction=\"out\"/>\n"        \
        "  </method>\n"                                                 \
53
        "  <method name=\"GetSeat\">\n"                                 \
54
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
55
        "   <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n"        \
56
        "  </method>\n"                                                 \
57
        "  <method name=\"ListSessions\">\n"                            \
58
        "   <arg name=\"sessions\" type=\"a(susso)\" direction=\"out\"/>\n" \
59 60 61 62
        "  </method>\n"                                                 \
        "  <method name=\"ListUsers\">\n"                               \
        "   <arg name=\"users\" type=\"a(uso)\" direction=\"out\"/>\n"  \
        "  </method>\n"                                                 \
63 64
        "  <method name=\"ListSeats\">\n"                               \
        "   <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n"   \
65 66 67 68
        "  </method>\n"                                                 \
        "  <method name=\"CreateSession\">\n"                           \
        "   <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n"          \
        "   <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n"       \
69
        "   <arg name=\"service\" type=\"s\" direction=\"in\"/>\n"      \
70
        "   <arg name=\"type\" type=\"s\" direction=\"in\"/>\n"         \
71
        "   <arg name=\"class\" type=\"s\" direction=\"in\"/>\n"        \
72
        "   <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n"         \
73
        "   <arg name=\"vtnr\" type=\"u\" direction=\"in\"/>\n"         \
74 75 76 77 78 79 80
        "   <arg name=\"tty\" type=\"s\" direction=\"in\"/>\n"          \
        "   <arg name=\"display\" type=\"s\" direction=\"in\"/>\n"      \
        "   <arg name=\"remote\" type=\"b\" direction=\"in\"/>\n"       \
        "   <arg name=\"remote_user\" type=\"s\" direction=\"in\"/>\n"  \
        "   <arg name=\"remote_host\" type=\"s\" direction=\"in\"/>\n"  \
        "   <arg name=\"controllers\" type=\"as\" direction=\"in\"/>\n" \
        "   <arg name=\"reset_controllers\" type=\"as\" direction=\"in\"/>\n" \
81
        "   <arg name=\"kill_processes\" type=\"b\" direction=\"in\"/>\n" \
82 83
        "   <arg name=\"id\" type=\"s\" direction=\"out\"/>\n"          \
        "   <arg name=\"path\" type=\"o\" direction=\"out\"/>\n"        \
84
        "   <arg name=\"runtime_path\" type=\"o\" direction=\"out\"/>\n" \
85
        "   <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n"          \
86 87
        "   <arg name=\"seat\" type=\"s\" direction=\"out\"/>\n"        \
        "   <arg name=\"vtnr\" type=\"u\" direction=\"out\"/>\n"        \
88
        "   <arg name=\"existing\" type=\"b\" direction=\"out\"/>\n"    \
89
        "  </method>\n"                                                 \
90 91 92
        "  <method name=\"ReleaseSession\">\n"                          \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "  </method>\n"                                                 \
93 94 95
        "  <method name=\"ActivateSession\">\n"                         \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "  </method>\n"                                                 \
96 97 98 99
        "  <method name=\"ActivateSessionOnSeat\">\n"                   \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "   <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n"         \
        "  </method>\n"                                                 \
100 101 102 103 104 105
        "  <method name=\"LockSession\">\n"                             \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "  </method>\n"                                                 \
        "  <method name=\"UnlockSession\">\n"                           \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "  </method>\n"                                                 \
106
        "  <method name=\"LockSessions\"/>\n"                           \
107
        "  <method name=\"UnlockSessions\"/>\n"                         \
108 109
        "  <method name=\"KillSession\">\n"                             \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
110 111
        "   <arg name=\"who\" type=\"s\" direction=\"in\"/>\n"          \
        "   <arg name=\"signal\" type=\"s\" direction=\"in\"/>\n"       \
112 113 114
        "  </method>\n"                                                 \
        "  <method name=\"KillUser\">\n"                                \
        "   <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n"          \
115
        "   <arg name=\"signal\" type=\"s\" direction=\"in\"/>\n"       \
116
        "  </method>\n"                                                 \
117 118 119 120
        "  <method name=\"TerminateSession\">\n"                        \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "  </method>\n"                                                 \
        "  <method name=\"TerminateUser\">\n"                           \
121
        "   <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n"          \
122 123 124 125
        "  </method>\n"                                                 \
        "  <method name=\"TerminateSeat\">\n"                           \
        "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
        "  </method>\n"                                                 \
126 127 128 129 130
        "  <method name=\"SetUserLinger\">\n"                           \
        "   <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n"          \
        "   <arg name=\"b\" type=\"b\" direction=\"in\"/>\n"            \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
131 132 133 134 135
        "  <method name=\"AttachDevice\">\n"                            \
        "   <arg name=\"seat\" type=\"s\" direction=\"in\"/>\n"         \
        "   <arg name=\"sysfs\" type=\"s\" direction=\"in\"/>\n"        \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
136 137 138
        "  <method name=\"FlushDevices\">\n"                            \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
139 140 141 142 143 144
        "  <method name=\"PowerOff\">\n"                                \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
        "  <method name=\"Reboot\">\n"                                  \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
145 146 147 148 149 150
        "  <method name=\"Suspend\">\n"                                 \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
        "  <method name=\"Hibernate\">\n"                               \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
151 152 153
        "  <method name=\"HybridSleep\">\n"                             \
        "   <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n"  \
        "  </method>\n"                                                 \
154 155 156 157 158 159
        "  <method name=\"CanPowerOff\">\n"                             \
        "   <arg name=\"result\" type=\"s\" direction=\"out\"/>\n"      \
        "  </method>\n"                                                 \
        "  <method name=\"CanReboot\">\n"                               \
        "   <arg name=\"result\" type=\"s\" direction=\"out\"/>\n"      \
        "  </method>\n"                                                 \
160 161 162 163 164 165
        "  <method name=\"CanSuspend\">\n"                              \
        "   <arg name=\"result\" type=\"s\" direction=\"out\"/>\n"      \
        "  </method>\n"                                                 \
        "  <method name=\"CanHibernate\">\n"                            \
        "   <arg name=\"result\" type=\"s\" direction=\"out\"/>\n"      \
        "  </method>\n"                                                 \
166 167 168
        "  <method name=\"CanHybridSleep\">\n"                          \
        "   <arg name=\"result\" type=\"s\" direction=\"out\"/>\n"      \
        "  </method>\n"                                                 \
169 170 171 172
        "  <method name=\"Inhibit\">\n"                                 \
        "   <arg name=\"what\" type=\"s\" direction=\"in\"/>\n"         \
        "   <arg name=\"who\" type=\"s\" direction=\"in\"/>\n"          \
        "   <arg name=\"why\" type=\"s\" direction=\"in\"/>\n"          \
173
        "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
174 175 176
        "   <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n"          \
        "  </method>\n"                                                 \
        "  <method name=\"ListInhibitors\">\n"                          \
177
        "   <arg name=\"inhibitors\" type=\"a(ssssuu)\" direction=\"out\"/>\n" \
178
        "  </method>\n"                                                 \
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        "  <signal name=\"SessionNew\">\n"                              \
        "   <arg name=\"id\" type=\"s\"/>\n"                            \
        "   <arg name=\"path\" type=\"o\"/>\n"                          \
        "  </signal>\n"                                                 \
        "  <signal name=\"SessionRemoved\">\n"                          \
        "   <arg name=\"id\" type=\"s\"/>\n"                            \
        "   <arg name=\"path\" type=\"o\"/>\n"                          \
        "  </signal>\n"                                                 \
        "  <signal name=\"UserNew\">\n"                                 \
        "   <arg name=\"uid\" type=\"u\"/>\n"                           \
        "   <arg name=\"path\" type=\"o\"/>\n"                          \
        "  </signal>\n"                                                 \
        "  <signal name=\"UserRemoved\">\n"                             \
        "   <arg name=\"uid\" type=\"u\"/>\n"                           \
        "   <arg name=\"path\" type=\"o\"/>\n"                          \
        "  </signal>\n"                                                 \
        "  <signal name=\"SeatNew\">\n"                                 \
        "   <arg name=\"id\" type=\"s\"/>\n"                            \
        "   <arg name=\"path\" type=\"o\"/>\n"                          \
        "  </signal>\n"                                                 \
        "  <signal name=\"SeatRemoved\">\n"                             \
        "   <arg name=\"id\" type=\"s\"/>\n"                            \
        "   <arg name=\"path\" type=\"o\"/>\n"                          \
        "  </signal>\n"                                                 \
203 204 205
        "  <signal name=\"PrepareForShutdown\">\n"                      \
        "   <arg name=\"active\" type=\"b\"/>\n"                        \
        "  </signal>\n"                                                 \
206 207 208
        "  <signal name=\"PrepareForSleep\">\n"                         \
        "   <arg name=\"active\" type=\"b\"/>\n"                        \
        "  </signal>\n"                                                 \
209 210 211 212 213 214 215
        "  <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
        "  <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
        "  <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
        "  <property name=\"NAutoVTs\" type=\"u\" access=\"read\"/>\n" \
        "  <property name=\"KillOnlyUsers\" type=\"as\" access=\"read\"/>\n" \
        "  <property name=\"KillExcludeUsers\" type=\"as\" access=\"read\"/>\n" \
        "  <property name=\"KillUserProcesses\" type=\"b\" access=\"read\"/>\n" \
216 217 218
        "  <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n"  \
        "  <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
        "  <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
219 220 221
        "  <property name=\"BlockInhibited\" type=\"s\" access=\"read\"/>\n" \
        "  <property name=\"DelayInhibited\" type=\"s\" access=\"read\"/>\n" \
        "  <property name=\"InhibitDelayMaxUSec\" type=\"t\" access=\"read\"/>\n" \
222
        "  <property name=\"HandlePowerKey\" type=\"s\" access=\"read\"/>\n" \
223 224
        "  <property name=\"HandleSuspendKey\" type=\"s\" access=\"read\"/>\n" \
        "  <property name=\"HandleHibernateKey\" type=\"s\" access=\"read\"/>\n" \
225
        "  <property name=\"HandleLidSwitch\" type=\"s\" access=\"read\"/>\n" \
226 227
        "  <property name=\"IdleAction\" type=\"s\" access=\"read\"/>\n" \
        "  <property name=\"IdleActionUSec\" type=\"t\" access=\"read\"/>\n" \
228 229
        "  <property name=\"PreparingForShutdown\" type=\"b\" access=\"read\"/>\n" \
        "  <property name=\"PreparingForSleep\" type=\"b\" access=\"read\"/>\n" \
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
        " </interface>\n"

#define INTROSPECTION_BEGIN                                             \
        DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
        "<node>\n"                                                      \
        BUS_MANAGER_INTERFACE                                           \
        BUS_PROPERTIES_INTERFACE                                        \
        BUS_PEER_INTERFACE                                              \
        BUS_INTROSPECTABLE_INTERFACE

#define INTROSPECTION_END                                               \
        "</node>\n"

#define INTERFACES_LIST                              \
        BUS_GENERIC_INTERFACES_LIST                  \
        "org.freedesktop.login1.Manager\0"

247 248
static int bus_manager_append_idle_hint(DBusMessageIter *i, const char *property, void *data) {
        Manager *m = data;
249
        dbus_bool_t b;
250 251 252 253 254

        assert(i);
        assert(property);
        assert(m);

255
        b = manager_get_idle_hint(m, NULL) > 0;
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
                return -ENOMEM;

        return 0;
}

static int bus_manager_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
        Manager *m = data;
        dual_timestamp t;
        uint64_t u;

        assert(i);
        assert(property);
        assert(m);

        manager_get_idle_hint(m, &t);
        u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic;

        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
                return -ENOMEM;

        return 0;
}

280 281 282 283 284
static int bus_manager_append_inhibited(DBusMessageIter *i, const char *property, void *data) {
        Manager *m = data;
        InhibitWhat w;
        const char *p;

285
        w = manager_inhibit_what(m, streq(property, "BlockInhibited") ? INHIBIT_BLOCK : INHIBIT_DELAY);
286 287 288 289 290 291 292 293
        p = inhibit_what_to_string(w);

        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &p))
                return -ENOMEM;

        return 0;
}

294 295 296 297 298 299 300 301
static int bus_manager_append_preparing(DBusMessageIter *i, const char *property, void *data) {
        Manager *m = data;
        dbus_bool_t b;

        assert(i);
        assert(property);

        if (streq(property, "PreparingForShutdown"))
302
                b = !!(m->action_what & INHIBIT_SHUTDOWN);
303
        else
304
                b = !!(m->action_what & INHIBIT_SLEEP);
305 306 307 308 309

        dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b);
        return 0;
}

310
static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) {
311
        const char *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *service;
312
        uint32_t uid, leader, audit_id = 0;
313
        dbus_bool_t remote, kill_processes, exists;
314 315
        _cleanup_strv_free_ char **controllers = NULL, **reset_controllers = NULL;
        _cleanup_free_ char *cgroup = NULL, *id = NULL, *p = NULL;
316
        SessionType t;
317
        SessionClass c;
318 319
        DBusMessageIter iter;
        int r;
320
        uint32_t vtnr = 0;
321
        _cleanup_close_ int fifo_fd = -1;
322
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
323 324 325
        Session *session = NULL;
        User *user = NULL;
        Seat *seat = NULL;
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
        bool b;

        assert(m);
        assert(message);
        assert(_reply);

        if (!dbus_message_iter_init(message, &iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &uid);

        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &leader);

        if (leader <= 0 ||
            !dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &service);

        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &type);
356 357 358 359 360 361 362
        if (isempty(type))
                t = _SESSION_TYPE_INVALID;
        else {
                t = session_type_from_string(type);
                if (t < 0)
                        return -EINVAL;
        }
363

364
        if (!dbus_message_iter_next(&iter) ||
365 366 367
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

368 369
        dbus_message_iter_get_basic(&iter, &class);
        if (isempty(class))
370 371
                c = _SESSION_CLASS_INVALID;
        else {
372
                c = session_class_from_string(class);
373 374 375
                if (c < 0)
                        return -EINVAL;
        }
376

377
        if (!dbus_message_iter_next(&iter) ||
378 379 380
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

381
        dbus_message_iter_get_basic(&iter, &cseat);
382

383 384
        if (isempty(cseat))
                seat = NULL;
385
        else {
386 387
                seat = hashmap_get(m->seats, cseat);
                if (!seat)
388 389 390
                        return -ENOENT;
        }

391 392 393 394 395 396
        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &vtnr);

397 398 399 400 401 402 403
        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &tty);

        if (tty_is_vc(tty)) {
404
                int v;
405

406 407 408
                if (!seat)
                        seat = m->vtconsole;
                else if (seat != m->vtconsole)
409 410
                        return -EINVAL;

411 412 413 414
                v = vtnr_from_tty(tty);

                if (v <= 0)
                        return v < 0 ? v : -EINVAL;
415 416

                if (vtnr <= 0)
417 418 419
                        vtnr = (uint32_t) v;
                else if (vtnr != (uint32_t) v)
                        return -EINVAL;
420 421
        } else if (tty_is_console(tty)) {

422 423 424
                if (!seat)
                        seat = m->vtconsole;
                else if (seat != m->vtconsole)
425 426 427 428
                        return -EINVAL;

                if (vtnr != 0)
                        return -EINVAL;
429
        }
430

431 432
        if (seat) {
                if (seat_can_multi_session(seat)) {
433
                        if (vtnr > 63)
434 435
                                return -EINVAL;
                } else {
436
                        if (vtnr != 0)
437 438 439 440
                                return -EINVAL;
                }
        }

441 442 443 444 445 446 447 448 449 450
        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &display);

        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
                return -EINVAL;

451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
        if (t == _SESSION_TYPE_INVALID) {
                if (!isempty(display))
                        t = SESSION_X11;
                else if (!isempty(tty))
                        t = SESSION_TTY;
                else
                        t = SESSION_UNSPECIFIED;
        }

        if (c == _SESSION_CLASS_INVALID) {
                if (!isempty(display) || !isempty(tty))
                        c = SESSION_USER;
                else
                        c = SESSION_BACKGROUND;
        }

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
        dbus_message_iter_get_basic(&iter, &remote);

        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &remote_user);

        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        dbus_message_iter_get_basic(&iter, &remote_host);

        if (!dbus_message_iter_next(&iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING)
                return -EINVAL;

        r = bus_parse_strv_iter(&iter, &controllers);
        if (r < 0)
                return -EINVAL;

490 491
        if (strv_contains(controllers, "systemd") ||
            !dbus_message_iter_next(&iter) ||
492 493 494 495 496 497 498 499 500 501
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING) {
                r = -EINVAL;
                goto fail;
        }

        r = bus_parse_strv_iter(&iter, &reset_controllers);
        if (r < 0)
                goto fail;

502 503
        if (strv_contains(reset_controllers, "systemd") ||
            !dbus_message_iter_next(&iter) ||
504 505 506 507 508 509 510
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN) {
                r = -EINVAL;
                goto fail;
        }

        dbus_message_iter_get_basic(&iter, &kill_processes);

511
        r = cg_pid_get_cgroup(leader, NULL, &cgroup);
512 513 514
        if (r < 0)
                goto fail;

515 516 517
        r = manager_get_session_by_cgroup(m, cgroup, &session);
        if (r < 0)
                goto fail;
518

519 520 521 522
        if (session) {
                fifo_fd = session_create_fifo(session);
                if (fifo_fd < 0) {
                        r = fifo_fd;
523 524
                        goto fail;
                }
525

526 527 528
                /* Session already exists, client is probably
                 * something like "su" which changes uid but
                 * is still the same audit session */
529

530 531 532 533 534
                reply = dbus_message_new_method_return(message);
                if (!reply) {
                        r = -ENOMEM;
                        goto fail;
                }
535

536 537 538 539 540
                p = session_bus_path(session);
                if (!p) {
                        r = -ENOMEM;
                        goto fail;
                }
541

542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
                cseat = session->seat ? session->seat->id : "";
                vtnr = session->vtnr;
                exists = true;

                b = dbus_message_append_args(
                                reply,
                                DBUS_TYPE_STRING, &session->id,
                                DBUS_TYPE_OBJECT_PATH, &p,
                                DBUS_TYPE_STRING, &session->user->runtime_path,
                                DBUS_TYPE_UNIX_FD, &fifo_fd,
                                DBUS_TYPE_STRING, &cseat,
                                DBUS_TYPE_UINT32, &vtnr,
                                DBUS_TYPE_BOOLEAN, &exists,
                                DBUS_TYPE_INVALID);
                if (!b) {
                        r = -ENOMEM;
                        goto fail;
                }
560

561
                *_reply = reply;
562
                reply = NULL;
563

564 565
                return 0;
        }
566

567 568 569
        audit_session_from_pid(leader, &audit_id);
        if (audit_id > 0) {
                /* Keep our session IDs and the audit session IDs in sync */
570

571 572 573 574
                if (asprintf(&id, "%lu", (unsigned long) audit_id) < 0) {
                        r = -ENOMEM;
                        goto fail;
                }
575

576 577 578 579 580 581
                /* Wut? There's already a session by this name and we
                 * didn't find it above? Weird, then let's not trust
                 * the audit data and let's better register a new
                 * ID */
                if (hashmap_get(m->sessions, id)) {
                        audit_id = 0;
582

583 584
                        free(id);
                        id = NULL;
585
                }
586
        }
587

588
        if (!id) {
589 590
                do {
                        free(id);
591
                        id = NULL;
592

593
                        if (asprintf(&id, "c%lu", ++m->session_counter) < 0) {
594 595 596 597 598
                                r = -ENOMEM;
                                goto fail;
                        }

                } while (hashmap_get(m->sessions, id));
599 600
        }

601 602 603 604
        r = manager_add_user_by_uid(m, uid, &user);
        if (r < 0)
                goto fail;

605 606 607 608 609 610 611
        r = manager_add_session(m, user, id, &session);
        if (r < 0)
                goto fail;

        session->leader = leader;
        session->audit_id = audit_id;
        session->type = t;
612
        session->class = c;
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
        session->remote = remote;
        session->controllers = controllers;
        session->reset_controllers = reset_controllers;
        session->kill_processes = kill_processes;
        session->vtnr = vtnr;

        controllers = reset_controllers = NULL;

        if (!isempty(tty)) {
                session->tty = strdup(tty);
                if (!session->tty) {
                        r = -ENOMEM;
                        goto fail;
                }
        }

        if (!isempty(display)) {
                session->display = strdup(display);
                if (!session->display) {
                        r = -ENOMEM;
                        goto fail;
                }
        }

        if (!isempty(remote_user)) {
                session->remote_user = strdup(remote_user);
                if (!session->remote_user) {
                        r = -ENOMEM;
                        goto fail;
                }
        }

        if (!isempty(remote_host)) {
                session->remote_host = strdup(remote_host);
                if (!session->remote_host) {
                        r = -ENOMEM;
                        goto fail;
                }
        }

        if (!isempty(service)) {
                session->service = strdup(service);
                if (!session->service) {
                        r = -ENOMEM;
                        goto fail;
                }
        }

661 662 663
        fifo_fd = session_create_fifo(session);
        if (fifo_fd < 0) {
                r = fifo_fd;
664 665 666
                goto fail;
        }

667 668
        if (seat) {
                r = seat_attach_session(seat, session);
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
                if (r < 0)
                        goto fail;
        }

        r = session_start(session);
        if (r < 0)
                goto fail;

        reply = dbus_message_new_method_return(message);
        if (!reply) {
                r = -ENOMEM;
                goto fail;
        }

        p = session_bus_path(session);
        if (!p) {
                r = -ENOMEM;
                goto fail;
        }

689
        cseat = seat ? seat->id : "";
690
        exists = false;
691 692 693 694 695
        b = dbus_message_append_args(
                        reply,
                        DBUS_TYPE_STRING, &session->id,
                        DBUS_TYPE_OBJECT_PATH, &p,
                        DBUS_TYPE_STRING, &session->user->runtime_path,
696
                        DBUS_TYPE_UNIX_FD, &fifo_fd,
697
                        DBUS_TYPE_STRING, &cseat,
698
                        DBUS_TYPE_UINT32, &vtnr,
699
                        DBUS_TYPE_BOOLEAN, &exists,
700 701 702 703 704 705 706 707
                        DBUS_TYPE_INVALID);

        if (!b) {
                r = -ENOMEM;
                goto fail;
        }

        *_reply = reply;
708
        reply = NULL;
709 710 711 712 713 714 715 716 717 718 719 720 721

        return 0;

fail:
        if (session)
                session_add_to_gc_queue(session);

        if (user)
                user_add_to_gc_queue(user);

        return r;
}

722 723 724 725 726 727 728
static int bus_manager_inhibit(
                Manager *m,
                DBusConnection *connection,
                DBusMessage *message,
                DBusError *error,
                DBusMessage **_reply) {

729 730
        Inhibitor *i = NULL;
        char *id = NULL;
731
        const char *who, *why, *what, *mode;
732 733
        pid_t pid;
        InhibitWhat w;
734
        InhibitMode mm;
735 736
        unsigned long ul;
        int r, fifo_fd = -1;
737
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
738 739 740 741 742 743 744 745 746 747 748 749 750

        assert(m);
        assert(connection);
        assert(message);
        assert(error);
        assert(_reply);

        if (!dbus_message_get_args(
                            message,
                            error,
                            DBUS_TYPE_STRING, &what,
                            DBUS_TYPE_STRING, &who,
                            DBUS_TYPE_STRING, &why,
751
                            DBUS_TYPE_STRING, &mode,
752 753 754 755 756 757 758 759 760 761 762
                            DBUS_TYPE_INVALID)) {
                r = -EIO;
                goto fail;
        }

        w = inhibit_what_from_string(what);
        if (w <= 0) {
                r = -EINVAL;
                goto fail;
        }

763 764 765 766 767 768
        mm = inhibit_mode_from_string(mode);
        if (mm < 0) {
                r = -EINVAL;
                goto fail;
        }

769 770 771 772 773 774
        /* Delay is only supported for shutdown/sleep */
        if (mm == INHIBIT_DELAY && (w & ~(INHIBIT_SHUTDOWN|INHIBIT_SLEEP))) {
                r = -EINVAL;
                goto fail;
        }

775 776 777 778 779 780 781 782 783
        /* Don't allow taking delay locks while we are already
         * executing the operation. We shouldn't create the impression
         * that the lock was successful if the machine is about to go
         * down/suspend any moment. */
        if (m->action_what & w) {
                r = -EALREADY;
                goto fail;
        }

784
        r = verify_polkit(connection, message,
785 786 787 788 789 790 791
                          w == INHIBIT_SHUTDOWN             ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") :
                          w == INHIBIT_SLEEP                ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep"    : "org.freedesktop.login1.inhibit-delay-sleep") :
                          w == INHIBIT_IDLE                 ? "org.freedesktop.login1.inhibit-block-idle" :
                          w == INHIBIT_HANDLE_POWER_KEY     ? "org.freedesktop.login1.inhibit-handle-power-key" :
                          w == INHIBIT_HANDLE_SUSPEND_KEY   ? "org.freedesktop.login1.inhibit-handle-suspend-key" :
                          w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" :
                                                              "org.freedesktop.login1.inhibit-handle-lid-switch",
792
                          false, NULL, error);
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
        if (r < 0)
                goto fail;

        ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
        if (ul == (unsigned long) -1) {
                r = -EIO;
                goto fail;
        }

        pid = bus_get_unix_process_id(connection, dbus_message_get_sender(message), error);
        if (pid <= 0) {
                r = -EIO;
                goto fail;
        }

        do {
                free(id);
                id = NULL;

                if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0) {
                        r = -ENOMEM;
                        goto fail;
                }
        } while (hashmap_get(m->inhibitors, id));

        r = manager_add_inhibitor(m, id, &i);
        free(id);

        if (r < 0)
                goto fail;

        i->what = w;
825
        i->mode = mm;
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
        i->pid = pid;
        i->uid = (uid_t) ul;
        i->why = strdup(why);
        i->who = strdup(who);

        if (!i->why || !i->who) {
                r = -ENOMEM;
                goto fail;
        }

        fifo_fd = inhibitor_create_fifo(i);
        if (fifo_fd < 0) {
                r = fifo_fd;
                goto fail;
        }

        reply = dbus_message_new_method_return(message);
        if (!reply) {
                r = -ENOMEM;
                goto fail;
        }

        if (!dbus_message_append_args(
                            reply,
                            DBUS_TYPE_UNIX_FD, &fifo_fd,
                            DBUS_TYPE_INVALID)) {
                r = -ENOMEM;
                goto fail;
        }

        close_nointr_nofail(fifo_fd);
        *_reply = reply;
858
        reply = NULL;
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873

        inhibitor_start(i);

        return 0;

fail:
        if (i)
                inhibitor_free(i);

        if (fifo_fd >= 0)
                close_nointr_nofail(fifo_fd);

        return r;
}

874
static int trigger_device(Manager *m, struct udev_device *d) {
875 876 877 878 879 880 881 882 883 884 885 886
        struct udev_enumerate *e;
        struct udev_list_entry *first, *item;
        int r;

        assert(m);

        e = udev_enumerate_new(m->udev);
        if (!e) {
                r = -ENOMEM;
                goto finish;
        }

887 888 889 890 891 892 893
        if (d) {
                if (udev_enumerate_add_match_parent(e, d) < 0) {
                        r = -EIO;
                        goto finish;
                }
        }

894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
        if (udev_enumerate_scan_devices(e) < 0) {
                r = -EIO;
                goto finish;
        }

        first = udev_enumerate_get_list_entry(e);
        udev_list_entry_foreach(item, first) {
                char *t;
                const char *p;

                p = udev_list_entry_get_name(item);

                t = strappend(p, "/uevent");
                if (!t) {
                        r = -ENOMEM;
                        goto finish;
                }

912
                write_string_file(t, "change");
913 914 915 916 917 918 919 920 921 922 923 924
                free(t);
        }

        r = 0;

finish:
        if (e)
                udev_enumerate_unref(e);

        return r;
}

925 926
static int attach_device(Manager *m, const char *seat, const char *sysfs) {
        struct udev_device *d;
927
        char _cleanup_free_ *rule = NULL, *file = NULL;
928
        const char *id_for_seat;
929 930 931 932 933 934 935 936 937 938
        int r;

        assert(m);
        assert(seat);
        assert(sysfs);

        d = udev_device_new_from_syspath(m->udev, sysfs);
        if (!d)
                return -ENODEV;

939
        if (!udev_device_has_tag(d, "seat")) {
940 941 942 943
                r = -ENODEV;
                goto finish;
        }

944 945
        id_for_seat = udev_device_get_property_value(d, "ID_FOR_SEAT");
        if (!id_for_seat) {
946 947 948 949
                r = -ENODEV;
                goto finish;
        }

950
        if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0) {
951 952 953 954
                r = -ENOMEM;
                goto finish;
        }

955
        if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) {
956 957 958 959
                r = -ENOMEM;
                goto finish;
        }

960
        mkdir_p_label("/etc/udev/rules.d", 0755);
961
        label_init("/etc");
962
        r = write_string_file_atomic_label(file, rule);
963 964 965
        if (r < 0)
                goto finish;

966
        r = trigger_device(m, d);
967 968 969 970 971 972 973 974

finish:
        if (d)
                udev_device_unref(d);

        return r;
}

975
static int flush_devices(Manager *m) {
976
        DIR _cleanup_closedir_ *d;
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005

        assert(m);

        d = opendir("/etc/udev/rules.d");
        if (!d) {
                if (errno != ENOENT)
                        log_warning("Failed to open /etc/udev/rules.d: %m");
        } else {
                struct dirent *de;

                while ((de = readdir(d))) {

                        if (!dirent_is_file(de))
                                continue;

                        if (!startswith(de->d_name, "72-seat-"))
                                continue;

                        if (!endswith(de->d_name, ".rules"))
                                continue;

                        if (unlinkat(dirfd(d), de->d_name, 0) < 0)
                                log_warning("Failed to unlink %s: %m", de->d_name);
                }
        }

        return trigger_device(m, NULL);
}

1006 1007
static int have_multiple_sessions(
                Manager *m,
1008
                uid_t uid) {
1009

1010 1011
        Session *session;
        Iterator i;
1012 1013 1014

        assert(m);

1015 1016
        /* Check for other users' sessions. Greeter sessions do not
         * count, and non-login sessions do not count either. */
1017
        HASHMAP_FOREACH(session, m->sessions, i)
1018 1019
                if (session->class == SESSION_USER &&
                    session->user->uid != uid)
1020
                        return true;
1021 1022 1023 1024

        return false;
}

1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
static int bus_manager_log_shutdown(
                Manager *m,
                InhibitWhat w,
                const char *unit_name) {

        const char *p, *q;

        assert(m);
        assert(unit_name);

        if (w != INHIBIT_SHUTDOWN)
                return 0;

        if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) {
                p = "MESSAGE=System is powering down.";
                q = "SHUTDOWN=power-off";
        } else if (streq(unit_name, SPECIAL_HALT_TARGET)) {
                p = "MESSAGE=System is halting.";
                q = "SHUTDOWN=halt";
        } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) {
                p = "MESSAGE=System is rebooting.";
                q = "SHUTDOWN=reboot";
        } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) {
                p = "MESSAGE=System is rebooting with kexec.";
                q = "SHUTDOWN=kexec";
        } else {
                p = "MESSAGE=System is shutting down.";
                q = NULL;
        }

        return log_struct(LOG_NOTICE, MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
                          p,
                          q, NULL);
}

static int execute_shutdown_or_sleep(
                Manager *m,
                InhibitWhat w,
                const char *unit_name,
                DBusError *error) {

1066
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
1067
        const char *mode = "replace-irreversibly", *p;
1068 1069
        int r;
        char *c;
1070

1071
        assert(m);
1072 1073
        assert(w >= 0);
        assert(w < _INHIBIT_WHAT_MAX);
1074
        assert(unit_name);
1075

1076 1077
        bus_manager_log_shutdown(m, w, unit_name);

1078 1079
        r = bus_method_call_with_reply(
                        m->bus,
1080 1081 1082
                        "org.freedesktop.systemd1",
                        "/org/freedesktop/systemd1",
                        "org.freedesktop.systemd1.Manager",
1083
                        "StartUnit",
1084 1085
                        &reply,
                        error,
1086 1087 1088
                        DBUS_TYPE_STRING, &unit_name,
                        DBUS_TYPE_STRING, &mode,
                        DBUS_TYPE_INVALID);
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
        if (r < 0)
                return r;

        if (!dbus_message_get_args(
                            reply,
                            error,
                            DBUS_TYPE_OBJECT_PATH, &p,
                            DBUS_TYPE_INVALID))
                return -EINVAL;

        c = strdup(p);
        if (!c)
                return -ENOMEM;

1103
        m->action_unit = unit_name;
1104 1105
        free(m->action_job);
        m->action_job = c;
1106
        m->action_what = w;
1107 1108

        return 0;
1109 1110
}

1111 1112 1113 1114
static int delay_shutdown_or_sleep(
                Manager *m,
                InhibitWhat w,
                const char *unit_name) {
1115 1116

        assert(m);
1117 1118
        assert(w >= 0);
        assert(w < _INHIBIT_WHAT_MAX);
1119
        assert(unit_name);
1120

1121 1122 1123
        m->action_timestamp = now(CLOCK_MONOTONIC);
        m->action_unit = unit_name;
        m->action_what = w;
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136

        return 0;
}

static int bus_manager_can_shutdown_or_sleep(
                Manager *m,
                DBusConnection *connection,
                DBusMessage *message,
                InhibitWhat w,
                const char *action,
                const char *action_multiple_sessions,
                const char *action_ignore_inhibit,
                const char *sleep_type,
1137
                const char *sleep_disk_type,
1138 1139 1140 1141 1142
                DBusError *error,
                DBusMessage **_reply) {

        bool multiple_sessions, challenge, blocked, b;
        const char *result;
1143
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
1144
        int r;
1145
        unsigned long ul;
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162

        assert(m);
        assert(connection);
        assert(message);
        assert(w >= 0);
        assert(w <= _INHIBIT_WHAT_MAX);
        assert(action);
        assert(action_multiple_sessions);
        assert(action_ignore_inhibit);
        assert(error);
        assert(_reply);

        if (sleep_type) {
                r = can_sleep(sleep_type);
                if (r < 0)
                        return r;

1163 1164 1165 1166
                if (r == 0) {
                        result = "na";
                        goto finish;
                }
1167 1168
        }

1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
        if (sleep_disk_type) {
                r = can_sleep_disk(sleep_disk_type);
                if (r < 0)
                        return r;

                if (r == 0) {
                        result = "na";
                        goto finish;
                }
        }

1180 1181 1182 1183 1184
        ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
        if (ul == (unsigned long) -1)
                return -EIO;

        r = have_multiple_sessions(m, (uid_t) ul);
1185 1186 1187 1188
        if (r < 0)
                return r;

        multiple_sessions = r > 0;
1189
        blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, (uid_t) ul);
1190 1191 1192 1193 1194 1195 1196 1197

        if (multiple_sessions) {
                r = verify_polkit(connection, message, action_multiple_sessions, false, &challenge, error);
                if (r < 0)
                        return r;

                if (r > 0)
                        result = "yes";
Lennart Poettering's avatar
Lennart Poettering committed
1198 1199 1200 1201 1202
                else if (challenge)
                        result = "challenge";
                else
                        result = "no";
        }
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241

        if (blocked) {
                r = verify_polkit(connection, message, action_ignore_inhibit, false, &challenge, error);
                if (r < 0)
                        return r;

                if (r > 0 && !result)
                        result = "yes";
                else if (challenge && (!result || streq(result, "yes")))
                        result = "challenge";
                else
                        result = "no";
        }

        if (!multiple_sessions && !blocked) {
                /* If neither inhibit nor multiple sessions
                 * apply then just check the normal policy */

                r = verify_polkit(connection, message, action, false, &challenge, error);
                if (r < 0)
                        return r;

                if (r > 0)
                        result = "yes";
                else if (challenge)
                        result = "challenge";
                else
                        result = "no";
        }

finish:
        reply = dbus_message_new_method_return(message);
        if (!reply)
                return -ENOMEM;

        b = dbus_message_append_args(
                        reply,
                        DBUS_TYPE_STRING, &result,
                        DBUS_TYPE_INVALID);
1242
        if (!b)
1243 1244 1245
                return -ENOMEM;

        *_reply = reply;
1246
        reply = NULL;
1247 1248 1249
        return 0;
}

1250 1251 1252 1253 1254
static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
        static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
                [INHIBIT_SHUTDOWN] = "PrepareForShutdown",
                [INHIBIT_SLEEP] = "PrepareForSleep"
        };
1255

1256 1257
        dbus_bool_t active = _active;
        _cleanup_dbus_message_unref_ DBusMessage *message = NULL;
1258 1259

        assert(m);
1260 1261 1262
        assert(w >= 0);
        assert(w < _INHIBIT_WHAT_MAX);
        assert(signal_name[w]);
1263

1264 1265 1266
        message = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", signal_name[w]);
        if (!message)
                return -ENOMEM;