Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radvd: save pwnam if no user or root is passed #166

Merged
merged 1 commit into from
Feb 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions radvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,6 @@ static int check_conffile_perm(const char *username, const char *conf_file)
}
fclose(fp);

if (!username)
username = "root";

struct passwd *pw = getpwnam(username);
if (!pw) {
return -1;
}

struct stat stbuf;
if (0 != stat(conf_file, &stbuf)) {
Expand All @@ -883,11 +876,19 @@ static int check_conffile_perm(const char *username, const char *conf_file)
return -1;
}

/* for non-root: must not be writable by self/own group */
if (strncmp(username, "root", 5) != 0 && ((stbuf.st_mode & S_IWGRP && pw->pw_gid == stbuf.st_gid) ||
(stbuf.st_mode & S_IWUSR && pw->pw_uid == stbuf.st_uid))) {
flog(LOG_ERR, "Insecure file permissions (writable by self/group): %s", conf_file);
return -1;
if(username != NULL && strncmp(username, "root", 5) != 0) {
struct passwd *pw = getpwnam(username);
if (!pw) {
return -1;
}

/* for non-root: must not be writable by self/own group */
/* TODO: this should check supplementary groups as well, via getgroups and looping */
if ((stbuf.st_mode & S_IWGRP && pw->pw_gid == stbuf.st_gid) ||
(stbuf.st_mode & S_IWUSR && pw->pw_uid == stbuf.st_uid)) {
flog(LOG_ERR, "Insecure file permissions (writable by self/group): %s", conf_file);
return -1;
}
}

return 0;
Expand Down