Skip to content
This repository was archived by the owner on Jul 18, 2019. It is now read-only.

Commit 4e7b57e

Browse files
authored
Merge pull request systemd#6497 from yuwata/bus-prop
core: add missing properties in bus_exec_context_set_transient_property()
2 parents 8c759b3 + cffaed8 commit 4e7b57e

File tree

14 files changed

+1023
-91
lines changed

14 files changed

+1023
-91
lines changed

src/basic/cap-list.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include <errno.h>
2121
#include <string.h>
2222

23+
#include "alloc-util.h"
24+
#include "capability-util.h"
2325
#include "cap-list.h"
26+
#include "extract-word.h"
2427
#include "macro.h"
2528
#include "missing.h"
2629
#include "parse-util.h"
@@ -64,3 +67,65 @@ int capability_from_name(const char *name) {
6467
int capability_list_length(void) {
6568
return (int) ELEMENTSOF(capability_names);
6669
}
70+
71+
int capability_set_to_string_alloc(uint64_t set, char **s) {
72+
_cleanup_free_ char *str = NULL;
73+
unsigned long i;
74+
size_t allocated = 0, n = 0;
75+
76+
assert(s);
77+
78+
for (i = 0; i < cap_last_cap(); i++)
79+
if (set & (UINT64_C(1) << i)) {
80+
const char *p;
81+
size_t add;
82+
83+
p = capability_to_name(i);
84+
if (!p)
85+
return -EINVAL;
86+
87+
add = strlen(p);
88+
89+
if (!GREEDY_REALLOC0(str, allocated, n + add + 2))
90+
return -ENOMEM;
91+
92+
strcpy(mempcpy(str + n, p, add), " ");
93+
n += add + 1;
94+
}
95+
96+
if (n != 0)
97+
str[n - 1] = '\0';
98+
99+
*s = str;
100+
str = NULL;
101+
102+
return 0;
103+
}
104+
105+
int capability_set_from_string(const char *s, uint64_t *set) {
106+
uint64_t val = 0;
107+
const char *p;
108+
109+
assert(set);
110+
111+
for (p = s;;) {
112+
_cleanup_free_ char *word = NULL;
113+
int r;
114+
115+
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
116+
if (r == -ENOMEM)
117+
return r;
118+
if (r <= 0)
119+
break;
120+
121+
r = capability_from_name(word);
122+
if (r < 0)
123+
continue;
124+
125+
val |= ((uint64_t) UINT64_C(1)) << (uint64_t) r;
126+
}
127+
128+
*set = val;
129+
130+
return 0;
131+
}

src/basic/cap-list.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
const char *capability_to_name(int id);
2323
int capability_from_name(const char *name);
2424
int capability_list_length(void);
25+
26+
int capability_set_to_string_alloc(uint64_t set, char **s);
27+
int capability_set_from_string(const char *s, uint64_t *set);

src/basic/cpu-set-util.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,49 @@ int parse_cpu_set_and_warn(
112112

113113
return (int) ncpus;
114114
}
115+
116+
int parse_cpu_set(
117+
const char *rvalue,
118+
cpu_set_t **cpu_set) {
119+
120+
_cleanup_cpu_free_ cpu_set_t *c = NULL;
121+
unsigned ncpus = 0;
122+
123+
assert(rvalue);
124+
125+
for (;;) {
126+
_cleanup_free_ char *word = NULL;
127+
unsigned cpu, cpu_lower, cpu_upper;
128+
int r;
129+
130+
r = extract_first_word(&rvalue, &word, WHITESPACE ",", EXTRACT_QUOTES);
131+
if (r == -ENOMEM)
132+
return r;
133+
if (r <= 0)
134+
break;
135+
136+
if (!c) {
137+
c = cpu_set_malloc(&ncpus);
138+
if (!c)
139+
return -ENOMEM;
140+
}
141+
142+
r = parse_range(word, &cpu_lower, &cpu_upper);
143+
if (r < 0)
144+
return r;
145+
if (cpu_lower >= ncpus || cpu_upper >= ncpus)
146+
return -EINVAL;
147+
148+
if (cpu_lower <= cpu_upper)
149+
for (cpu = cpu_lower; cpu <= cpu_upper; cpu++)
150+
CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
151+
}
152+
153+
/* On success, sets *cpu_set and returns ncpus for the system. */
154+
if (c) {
155+
*cpu_set = c;
156+
c = NULL;
157+
}
158+
159+
return (int) ncpus;
160+
}

src/basic/cpu-set-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
3030
cpu_set_t* cpu_set_malloc(unsigned *ncpus);
3131

3232
int parse_cpu_set_and_warn(const char *rvalue, cpu_set_t **cpu_set, const char *unit, const char *filename, unsigned line, const char *lvalue);
33+
int parse_cpu_set(const char *rvalue, cpu_set_t **cpu_set);

src/basic/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ basic_sources_plain = files('''
139139
rm-rf.c
140140
rm-rf.h
141141
securebits.h
142+
securebits-util.c
143+
securebits-util.h
142144
selinux-util.c
143145
selinux-util.h
144146
set.h

src/basic/process-util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
***/
2121

2222
#include <alloca.h>
23+
#include <sched.h>
2324
#include <signal.h>
2425
#include <stdbool.h>
2526
#include <stddef.h>
@@ -110,6 +111,14 @@ static inline bool nice_is_valid(int n) {
110111
return n >= PRIO_MIN && n < PRIO_MAX;
111112
}
112113

114+
static inline bool sched_policy_is_valid(int i) {
115+
return IN_SET(i, SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_FIFO, SCHED_RR);
116+
}
117+
118+
static inline bool sched_priority_is_valid(int i) {
119+
return i >= 0 && i <= sched_get_priority_max(SCHED_RR);
120+
}
121+
113122
static inline bool ioprio_class_is_valid(int i) {
114123
return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE);
115124
}

src/basic/securebits-util.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/***
2+
This file is part of systemd.
3+
4+
Copyright 2017 Yu Watanabe
5+
6+
systemd is free software; you can redistribute it and/or modify it
7+
under the terms of the GNU Lesser General Public License as published by
8+
the Free Software Foundation; either version 2.1 of the License, or
9+
(at your option) any later version.
10+
11+
systemd is distributed in the hope that it will be useful, but
12+
WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public License
17+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
18+
***/
19+
20+
#include <errno.h>
21+
22+
#include "alloc-util.h"
23+
#include "extract-word.h"
24+
#include "securebits.h"
25+
#include "securebits-util.h"
26+
#include "string-util.h"
27+
28+
int secure_bits_to_string_alloc(int i, char **s) {
29+
_cleanup_free_ char *str = NULL;
30+
size_t len;
31+
int r;
32+
33+
assert(s);
34+
35+
r = asprintf(&str, "%s%s%s%s%s%s",
36+
(i & (1 << SECURE_KEEP_CAPS)) ? "keep-caps " : "",
37+
(i & (1 << SECURE_KEEP_CAPS_LOCKED)) ? "keep-caps-locked " : "",
38+
(i & (1 << SECURE_NO_SETUID_FIXUP)) ? "no-setuid-fixup " : "",
39+
(i & (1 << SECURE_NO_SETUID_FIXUP_LOCKED)) ? "no-setuid-fixup-locked " : "",
40+
(i & (1 << SECURE_NOROOT)) ? "noroot " : "",
41+
(i & (1 << SECURE_NOROOT_LOCKED)) ? "noroot-locked " : "");
42+
if (r < 0)
43+
return -ENOMEM;
44+
45+
len = strlen(str);
46+
if (len != 0)
47+
str[len - 1] = '\0';
48+
49+
*s = str;
50+
str = NULL;
51+
52+
return 0;
53+
}
54+
55+
int secure_bits_from_string(const char *s) {
56+
int secure_bits = 0;
57+
const char *p;
58+
int r;
59+
60+
for (p = s;;) {
61+
_cleanup_free_ char *word = NULL;
62+
63+
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
64+
if (r == -ENOMEM)
65+
return r;
66+
if (r <= 0)
67+
break;
68+
69+
if (streq(word, "keep-caps"))
70+
secure_bits |= 1 << SECURE_KEEP_CAPS;
71+
else if (streq(word, "keep-caps-locked"))
72+
secure_bits |= 1 << SECURE_KEEP_CAPS_LOCKED;
73+
else if (streq(word, "no-setuid-fixup"))
74+
secure_bits |= 1 << SECURE_NO_SETUID_FIXUP;
75+
else if (streq(word, "no-setuid-fixup-locked"))
76+
secure_bits |= 1 << SECURE_NO_SETUID_FIXUP_LOCKED;
77+
else if (streq(word, "noroot"))
78+
secure_bits |= 1 << SECURE_NOROOT;
79+
else if (streq(word, "noroot-locked"))
80+
secure_bits |= 1 << SECURE_NOROOT_LOCKED;
81+
}
82+
83+
return secure_bits;
84+
}

src/basic/securebits-util.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
/***
4+
This file is part of systemd.
5+
6+
Copyright 2017 Yu Watanabe
7+
8+
systemd is free software; you can redistribute it and/or modify it
9+
under the terms of the GNU Lesser General Public License as published by
10+
the Free Software Foundation; either version 2.1 of the License, or
11+
(at your option) any later version.
12+
13+
systemd is distributed in the hope that it will be useful, but
14+
WITHOUT ANY WARRANTY; without even the implied warranty of
15+
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+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
20+
***/
21+
22+
#include "securebits.h"
23+
24+
int secure_bits_to_string_alloc(int i, char **s);
25+
int secure_bits_from_string(const char *s);
26+
static inline bool secure_bits_is_valid(int i) {
27+
return ((SECURE_ALL_BITS | SECURE_ALL_LOCKS) & i) == i;
28+
}

0 commit comments

Comments
 (0)