Changed user for security

This commit is contained in:
Nate Choe
2022-01-30 12:56:05 -06:00
parent e05896356f
commit f3694d3b43
3 changed files with 22 additions and 288 deletions

View File

@@ -22,9 +22,11 @@
#include <assert.h>
#include <stdint.h>
#include <pwd.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include <util.h>
#include <runner.h>
@@ -90,7 +92,6 @@ int main(int argc, char **argv) {
}
}
if (sitefile == NULL) {
fprintf(stderr, "No sitefile configured\n");
exit(EXIT_FAILURE);
@@ -122,6 +123,24 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
{
struct passwd *swebs = getpwnam("swebs");
if (swebs == NULL)
createLog("Couldn't find swebs user");
else
if (seteuid(swebs->pw_uid))
createLog("seteuid() failed");
struct passwd *root = getpwnam("root");
if (root == NULL) {
createLog("Couldn't find root user, quitting");
exit(EXIT_FAILURE);
}
if (geteuid() == root->pw_uid) {
createLog("swebs should not be run as root");
exit(EXIT_FAILURE);
}
}
int *pending = calloc(processes - 1, sizeof(int));
int (*notify)[2] = malloc(sizeof(int[2]) * (processes - 1));
pthread_t *threads = malloc(sizeof(pthread_t) * (processes - 1));