mirror of
https://github.com/systemd/systemd
synced 2024-09-06 08:46:19 +00:00
Merge pull request #31913 from YHNdnzj/dynamic-user-unref
core/dynamic-user: trivial modernization
This commit is contained in:
commit
84c72b53c7
|
@ -143,7 +143,6 @@ static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret)
|
|||
}
|
||||
|
||||
static int make_uid_symlinks(uid_t uid, const char *name, bool b) {
|
||||
|
||||
char path1[STRLEN("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1];
|
||||
const char *path2;
|
||||
int r = 0, k;
|
||||
|
@ -754,7 +753,6 @@ int dynamic_user_lookup_name(Manager *m, const char *name, uid_t *ret) {
|
|||
|
||||
int dynamic_creds_make(Manager *m, const char *user, const char *group, DynamicCreds **ret) {
|
||||
_cleanup_(dynamic_creds_unrefp) DynamicCreds *creds = NULL;
|
||||
bool acquired = false;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
@ -777,20 +775,14 @@ int dynamic_creds_make(Manager *m, const char *user, const char *group, DynamicC
|
|||
r = dynamic_user_acquire(m, user, &creds->user);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
acquired = true;
|
||||
}
|
||||
|
||||
if (creds->user && (!group || streq_ptr(user, group)))
|
||||
creds->group = dynamic_user_ref(creds->user);
|
||||
else if (group) {
|
||||
if (group && !streq_ptr(user, group)) {
|
||||
r = dynamic_user_acquire(m, group, &creds->group);
|
||||
if (r < 0) {
|
||||
if (acquired)
|
||||
creds->user = dynamic_user_unref(creds->user);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
} else
|
||||
creds->group = ASSERT_PTR(dynamic_user_ref(creds->user));
|
||||
|
||||
*ret = TAKE_PTR(creds);
|
||||
|
||||
|
|
|
@ -1403,7 +1403,7 @@ bool exec_context_maintains_privileges(const ExecContext *c) {
|
|||
if (!c->user)
|
||||
return true;
|
||||
|
||||
if (streq(c->user, "root") || streq(c->user, "0"))
|
||||
if (STR_IN_SET(c->user, "root", "0"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue