• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.52
/src/shared/devnode-acl.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <errno.h>
4

5
#include "sd-device.h"
6

7
#include "acl-util.h"
8
#include "alloc-util.h"
9
#include "device-util.h"
10
#include "devnode-acl.h"
11
#include "dirent-util.h"
12
#include "errno-util.h"
13
#include "fd-util.h"
14
#include "format-util.h"
15
#include "fs-util.h"
16
#include "glyph-util.h"
17
#include "set.h"
18
#include "string-util.h"
19

20
static int flush_acl(acl_t acl) {
129✔
21
        acl_entry_t i;
129✔
22
        int found;
129✔
23
        bool changed = false;
129✔
24

25
        assert(acl);
129✔
26

27
        for (found = acl_get_entry(acl, ACL_FIRST_ENTRY, &i);
129✔
28
             found > 0;
516✔
29
             found = acl_get_entry(acl, ACL_NEXT_ENTRY, &i)) {
387✔
30

31
                acl_tag_t tag;
387✔
32

33
                if (acl_get_tag_type(i, &tag) < 0)
387✔
UNCOV
34
                        return -errno;
×
35

36
                if (tag != ACL_USER)
387✔
37
                        continue;
387✔
38

39
                if (acl_delete_entry(acl, i) < 0)
×
UNCOV
40
                        return -errno;
×
41

UNCOV
42
                changed = true;
×
43
        }
44

45
        if (found < 0)
129✔
UNCOV
46
                return -errno;
×
47

48
        return changed;
129✔
49
}
50

51
int devnode_acl(const char *path,
385✔
52
                bool flush,
53
                bool del, uid_t old_uid,
54
                bool add, uid_t new_uid) {
55

56
        _cleanup_(acl_freep) acl_t acl = NULL;
385✔
57
        int r;
385✔
58
        bool changed = false;
385✔
59

60
        assert(path);
385✔
61

62
        acl = acl_get_file(path, ACL_TYPE_ACCESS);
385✔
63
        if (!acl)
385✔
UNCOV
64
                return -errno;
×
65

66
        if (flush) {
385✔
67

68
                r = flush_acl(acl);
129✔
69
                if (r < 0)
129✔
70
                        return r;
71
                if (r > 0)
129✔
UNCOV
72
                        changed = true;
×
73

74
        } else if (del && old_uid > 0) {
256✔
UNCOV
75
                acl_entry_t entry;
×
76

77
                r = acl_find_uid(acl, old_uid, &entry);
×
78
                if (r < 0)
×
UNCOV
79
                        return r;
×
80

81
                if (r > 0) {
×
82
                        if (acl_delete_entry(acl, entry) < 0)
×
UNCOV
83
                                return -errno;
×
84

85
                        changed = true;
86
                }
87
        }
88

89
        if (add && new_uid > 0) {
385✔
90
                acl_entry_t entry;
×
91
                acl_permset_t permset;
×
UNCOV
92
                int rd, wt;
×
93

94
                r = acl_find_uid(acl, new_uid, &entry);
×
95
                if (r < 0)
×
UNCOV
96
                        return r;
×
97

98
                if (r == 0) {
×
99
                        if (acl_create_entry(&acl, &entry) < 0)
×
UNCOV
100
                                return -errno;
×
101

102
                        if (acl_set_tag_type(entry, ACL_USER) < 0 ||
×
103
                            acl_set_qualifier(entry, &new_uid) < 0)
×
UNCOV
104
                                return -errno;
×
105
                }
106

107
                if (acl_get_permset(entry, &permset) < 0)
×
UNCOV
108
                        return -errno;
×
109

110
                rd = acl_get_perm(permset, ACL_READ);
×
111
                if (rd < 0)
×
UNCOV
112
                        return -errno;
×
113

114
                wt = acl_get_perm(permset, ACL_WRITE);
×
115
                if (wt < 0)
×
UNCOV
116
                        return -errno;
×
117

UNCOV
118
                if (!rd || !wt) {
×
119

120
                        if (acl_add_perm(permset, ACL_READ|ACL_WRITE) < 0)
×
UNCOV
121
                                return -errno;
×
122

123
                        changed = true;
124
                }
125
        }
126

127
        if (!changed)
385✔
128
                return 0;
129

130
        if (acl_calc_mask(&acl) < 0)
×
UNCOV
131
                return -errno;
×
132

133
        if (acl_set_file(path, ACL_TYPE_ACCESS, acl) < 0)
×
UNCOV
134
                return -errno;
×
135

136
        return 0;
137
}
138

139
int devnode_acl_all(const char *seat,
64✔
140
                    bool flush,
141
                    bool del, uid_t old_uid,
142
                    bool add, uid_t new_uid) {
143

144
        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
64✔
UNCOV
145
        _cleanup_set_free_ Set *nodes = NULL;
×
146
        _cleanup_closedir_ DIR *dir = NULL;
64✔
147
        char *n;
64✔
148
        int r;
64✔
149

150
        r = sd_device_enumerator_new(&e);
64✔
151
        if (r < 0)
64✔
152
                return r;
153

154
        if (isempty(seat))
64✔
155
                seat = "seat0";
156

157
        /* We can only match by one tag in libudev. We choose
158
         * "uaccess" for that. If we could match for two tags here we
159
         * could add the seat name as second match tag, but this would
160
         * be hardly optimizable in libudev, and hence checking the
161
         * second tag manually in our loop is a good solution. */
162
        r = sd_device_enumerator_add_match_tag(e, "uaccess");
64✔
163
        if (r < 0)
64✔
164
                return r;
165

166
        FOREACH_DEVICE(e, d) {
192✔
167
                const char *node, *sn;
128✔
168

169
                /* Make sure the tag is still in place */
170
                if (sd_device_has_current_tag(d, "uaccess") <= 0)
128✔
UNCOV
171
                        continue;
×
172

173
                if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
128✔
174
                        sn = "seat0";
128✔
175

176
                if (!streq(seat, sn))
128✔
UNCOV
177
                        continue;
×
178

179
                /* In case people mistag devices with nodes, we need to ignore this */
180
                if (sd_device_get_devname(d, &node) < 0)
128✔
UNCOV
181
                        continue;
×
182

183
                log_device_debug(d, "Found udev node %s for seat %s", node, seat);
128✔
184
                r = set_put_strdup_full(&nodes, &path_hash_ops_free, node);
128✔
185
                if (r < 0)
128✔
UNCOV
186
                        return r;
×
187
        }
188

189
        /* udev exports "dead" device nodes to allow module on-demand loading,
190
         * these devices are not known to the kernel at this moment */
191
        dir = opendir("/run/udev/static_node-tags/uaccess");
64✔
192
        if (dir) {
64✔
193
                FOREACH_DIRENT(de, dir, return -errno) {
320✔
194
                        r = readlinkat_malloc(dirfd(dir), de->d_name, &n);
128✔
195
                        if (r == -ENOENT)
128✔
UNCOV
196
                                continue;
×
197
                        if (r < 0) {
128✔
UNCOV
198
                                log_debug_errno(r,
×
199
                                                "Unable to read symlink '/run/udev/static_node-tags/uaccess/%s', ignoring: %m",
200
                                                de->d_name);
UNCOV
201
                                continue;
×
202
                        }
203

204
                        log_debug("Found static node %s for seat %s", n, seat);
128✔
205
                        r = set_ensure_consume(&nodes, &path_hash_ops_free, n);
128✔
206
                        if (r < 0)
128✔
207
                                return r;
208
                }
209
        }
210

211
        r = 0;
64✔
212
        SET_FOREACH(n, nodes) {
320✔
213
                int k;
256✔
214

215
                log_debug("Changing ACLs at %s for seat %s (uid "UID_FMT"%s"UID_FMT"%s%s)",
640✔
216
                          n, seat, old_uid, glyph(GLYPH_ARROW_RIGHT), new_uid,
217
                          del ? " del" : "", add ? " add" : "");
218

219
                k = devnode_acl(n, flush, del, old_uid, add, new_uid);
256✔
220
                if (k == -ENOENT)
256✔
UNCOV
221
                        log_debug("Device %s disappeared while setting ACLs", n);
×
222
                else
223
                        RET_GATHER(r, k);
256✔
224
        }
225

226
        return r;
64✔
227
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc