summaryrefslogtreecommitdiffstats
path: root/Settings.c
diff options
context:
space:
mode:
authorMichael Klein <michael.klein@puffin.lb.shuttle.de>2015-12-02 23:42:10 +0100
committerMichael Klein <michael.klein@puffin.lb.shuttle.de>2015-12-02 23:42:10 +0100
commit42b08f223395eb8cfcd0d36389803f329ea493f7 (patch)
tree7d456b5e4c6a7eaf41a70dd4a0e8baad4623e983 /Settings.c
parentd18e9a4895599a479df264a6c7380b8805abb434 (diff)
drop privileges during Settings_read()/Settings_write()
Diffstat (limited to 'Settings.c')
-rw-r--r--Settings.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Settings.c b/Settings.c
index 65e49bfc..6a674549 100644
--- a/Settings.c
+++ b/Settings.c
@@ -154,7 +154,12 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
}
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)
return false;
@@ -260,7 +265,11 @@ static void writeMeterModes(Settings* this, FILE* fd, int column) {
bool Settings_write(Settings* this) {
FILE* fd;
+ uid_t euid = geteuid();
+
+ seteuid(getuid());
fd = fopen(this->filename, "w");
+ seteuid(euid);
if (fd == NULL) {
return false;
}
@@ -345,6 +354,8 @@ Settings* Settings_new(int cpuCount) {
htopDir = String_cat(home, "/.config/htop");
}
legacyDotfile = String_cat(home, "/.htoprc");
+ uid_t euid = geteuid();
+ seteuid(getuid());
(void) mkdir(configDir, 0700);
(void) mkdir(htopDir, 0700);
free(htopDir);
@@ -357,6 +368,7 @@ Settings* Settings_new(int cpuCount) {
free(legacyDotfile);
legacyDotfile = NULL;
}
+ seteuid(euid);
}
this->colorScheme = 0;
this->changed = false;

© 2014-2024 Faster IT GmbH | imprint | privacy policy