diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-03-14 19:54:22 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-03-14 19:54:22 +0100 |
commit | 4367379907f40cbe7df6a64e51c36f34dd854197 (patch) | |
tree | efe65c0b74d10f0b98a6c1638890c35a78023c07 /src/util.c | |
parent | 18da49531e4c6b31bd2439b4d738dc1bb9660af1 (diff) |
journalctl: warn if the user is not in the adm group
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 73481abee6..20cbc2b0db 100644 --- a/src/util.c +++ b/src/util.c @@ -5608,6 +5608,36 @@ int get_group_creds(const char **groupname, gid_t *gid) { return 0; } +int in_group(const char *name) { + gid_t gid, *gids; + int ngroups_max, r, i; + + r = get_group_creds(&name, &gid); + if (r < 0) + return r; + + if (getgid() == gid) + return 1; + + if (getegid() == gid) + return 1; + + ngroups_max = sysconf(_SC_NGROUPS_MAX); + assert(ngroups_max > 0); + + gids = alloca(sizeof(gid_t) * ngroups_max); + + r = getgroups(ngroups_max, gids); + if (r < 0) + return -errno; + + for (i = 0; i < r; i++) + if (gids[i] == gid) + return 1; + + return 0; +} + int glob_exists(const char *path) { glob_t g; int r, k; |