2 * manage device node user ACL
4 * Copyright 2010-2012 Kay Sievers <kay@vrfy.org>
5 * Copyright 2010 Lennart Poettering
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 #include <systemd/sd-daemon.h>
33 #include <systemd/sd-login.h>
34 #include "logind-acl.h"
38 static int builtin_uaccess(struct udev_device
*dev
, int argc
, char *argv
[], bool test
)
41 const char *path
= NULL
, *seat
;
42 bool changed_acl
= false;
45 log_set_target(LOG_TARGET_AUTO
);
46 log_parse_environment();
51 /* don't muck around with ACLs when the system is not running systemd */
55 path
= udev_device_get_devnode(dev
);
56 seat
= udev_device_get_property_value(dev
, "ID_SEAT");
60 r
= sd_seat_get_active(seat
, NULL
, &uid
);
62 /* No active session on this seat */
66 log_error("Failed to determine active user on seat %s.", seat
);
70 r
= devnode_acl(path
, true, false, 0, true, uid
);
72 log_error("Failed to apply ACL on %s: %s", path
, strerror(-r
));
80 if (path
&& !changed_acl
) {
83 /* Better be safe than sorry and reset ACL */
84 k
= devnode_acl(path
, true, false, 0, false, 0);
86 log_error("Failed to apply ACL on %s: %s", path
, strerror(-k
));
92 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;
95 const struct udev_builtin udev_builtin_uaccess
= {
97 .cmd
= builtin_uaccess
,
98 .help
= "manage device node user ACL",