journalctl: give a nice hint about group membership based on ACLs of /var/log/journal

If we notice that we unprivileged and not in any of the groups which
have access to /var/log/journal, print a nice message about which groups
do.

This checks and prints all groups that are in the default ACL for
/var/log/journal, which is not necessarily correct for all journal
files, but pretty close.
This commit is contained in:
Lennart Poettering
2013-03-22 17:44:19 +01:00
parent 8e70580bb0
commit 4468addca6
5 changed files with 145 additions and 20 deletions
+23 -12
View File
@@ -387,11 +387,29 @@ fail:
return NULL;
}
int strv_extend(char ***l, const char *value) {
int strv_push(char ***l, char *value) {
char **c;
char *v;
unsigned n;
if (!value)
return 0;
n = strv_length(*l);
c = realloc(*l, sizeof(char*) * (n + 2));
if (!c)
return -ENOMEM;
c[n] = value;
c[n+1] = NULL;
*l = c;
return 0;
}
int strv_extend(char ***l, const char *value) {
char *v;
int r;
if (!value)
return 0;
@@ -399,18 +417,11 @@ int strv_extend(char ***l, const char *value) {
if (!v)
return -ENOMEM;
n = strv_length(*l);
c = realloc(*l, sizeof(char*) * (n + 2));
if (!c) {
r = strv_push(l, v);
if (r < 0)
free(v);
return -ENOMEM;
}
c[n] = v;
c[n+1] = NULL;
*l = c;
return 0;
return r;
}
char **strv_uniq(char **l) {
+1
View File
@@ -41,6 +41,7 @@ char **strv_merge(char **a, char **b);
char **strv_merge_concat(char **a, char **b, const char *suffix);
char **strv_append(char **l, const char *s);
int strv_extend(char ***l, const char *value);
int strv_push(char ***l, char *value);
char **strv_remove(char **l, const char *s);
char **strv_remove_prefix(char **l, const char *s);
+30 -6
View File
@@ -4190,6 +4190,23 @@ char* uid_to_name(uid_t uid) {
return r;
}
char* gid_to_name(gid_t gid) {
struct group *p;
char *r;
if (gid == 0)
return strdup("root");
p = getgrgid(gid);
if (p)
return strdup(p->gr_name);
if (asprintf(&r, "%lu", (unsigned long) gid) < 0)
return NULL;
return r;
}
int get_group_creds(const char **groupname, gid_t *gid) {
struct group *g;
gid_t id;
@@ -4228,14 +4245,10 @@ int get_group_creds(const char **groupname, gid_t *gid) {
return 0;
}
int in_group(const char *name) {
gid_t gid, *gids;
int in_gid(gid_t gid) {
gid_t *gids;
int ngroups_max, r, i;
r = get_group_creds(&name, &gid);
if (r < 0)
return r;
if (getgid() == gid)
return 1;
@@ -4258,6 +4271,17 @@ int in_group(const char *name) {
return 0;
}
int in_group(const char *name) {
int r;
gid_t gid;
r = get_group_creds(&name, &gid);
if (r < 0)
return r;
return in_gid(gid);
}
int glob_exists(const char *path) {
glob_t g;
int r, k;
+2
View File
@@ -429,9 +429,11 @@ int socket_from_display(const char *display, char **path);
int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
int get_group_creds(const char **groupname, gid_t *gid);
int in_gid(gid_t gid);
int in_group(const char *name);
char* uid_to_name(uid_t uid);
char* gid_to_name(gid_t gid);
int glob_exists(const char *path);