1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * manage device node user ACL
5 * Copyright 2010-2012 Kay Sievers <kay@vrfy.org>
6 * Copyright 2010 Lennart Poettering
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "login-util.h"
29 #include "logind-acl.h"
33 static int builtin_uaccess(struct udev_device
*dev
, int argc
, char *argv
[], bool test
) {
35 const char *path
= NULL
, *seat
;
36 bool changed_acl
= false;
41 /* don't muck around with ACLs when the system is not running systemd */
42 if (!logind_running())
45 path
= udev_device_get_devnode(dev
);
46 seat
= udev_device_get_property_value(dev
, "ID_SEAT");
50 r
= sd_seat_get_active(seat
, NULL
, &uid
);
51 if (IN_SET(r
, -ENXIO
, -ENODATA
)) {
52 /* No active session on this seat */
56 log_error("Failed to determine active user on seat %s.", seat
);
60 r
= devnode_acl(path
, true, false, 0, true, uid
);
62 log_full_errno(r
== -ENOENT
? LOG_DEBUG
: LOG_ERR
, r
, "Failed to apply ACL on %s: %m", path
);
70 if (path
&& !changed_acl
) {
73 /* Better be safe than sorry and reset ACL */
74 k
= devnode_acl(path
, true, false, 0, false, 0);
76 log_full_errno(errno
== ENOENT
? LOG_DEBUG
: LOG_ERR
, k
, "Failed to apply ACL on %s: %m", path
);
82 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;
85 const struct udev_builtin udev_builtin_uaccess
= {
87 .cmd
= builtin_uaccess
,
88 .help
= "Manage device node user ACL",