Commit 42b08f22 authored by Michael Klein's avatar Michael Klein
Browse files

drop privileges during Settings_read()/Settings_write()

parent d18e9a48
...@@ -154,7 +154,12 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { ...@@ -154,7 +154,12 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
} }
static bool Settings_read(Settings* this, const char* fileName) { static bool Settings_read(Settings* this, const char* fileName) {
FILE* fd = fopen(fileName, "r"); FILE* fd;
uid_t euid = geteuid();
seteuid(getuid());
fd = fopen(fileName, "w");
seteuid(euid);
if (!fd) if (!fd)
return false; return false;
...@@ -260,7 +265,11 @@ static void writeMeterModes(Settings* this, FILE* fd, int column) { ...@@ -260,7 +265,11 @@ static void writeMeterModes(Settings* this, FILE* fd, int column) {
bool Settings_write(Settings* this) { bool Settings_write(Settings* this) {
FILE* fd; FILE* fd;
uid_t euid = geteuid();
seteuid(getuid());
fd = fopen(this->filename, "w"); fd = fopen(this->filename, "w");
seteuid(euid);
if (fd == NULL) { if (fd == NULL) {
return false; return false;
} }
...@@ -345,6 +354,8 @@ Settings* Settings_new(int cpuCount) { ...@@ -345,6 +354,8 @@ Settings* Settings_new(int cpuCount) {
htopDir = String_cat(home, "/.config/htop"); htopDir = String_cat(home, "/.config/htop");
} }
legacyDotfile = String_cat(home, "/.htoprc"); legacyDotfile = String_cat(home, "/.htoprc");
uid_t euid = geteuid();
seteuid(getuid());
(void) mkdir(configDir, 0700); (void) mkdir(configDir, 0700);
(void) mkdir(htopDir, 0700); (void) mkdir(htopDir, 0700);
free(htopDir); free(htopDir);
...@@ -357,6 +368,7 @@ Settings* Settings_new(int cpuCount) { ...@@ -357,6 +368,7 @@ Settings* Settings_new(int cpuCount) {
free(legacyDotfile); free(legacyDotfile);
legacyDotfile = NULL; legacyDotfile = NULL;
} }
seteuid(euid);
} }
this->colorScheme = 0; this->colorScheme = 0;
this->changed = false; this->changed = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment