Compare commits
No commits in common. "d2c3270b4b09d67374f88548efab0301ef00ae98" and "7781c2b960c50b495d1045b364043315e10f4c76" have entirely different histories.
d2c3270b4b
...
7781c2b960
1 changed files with 32 additions and 26 deletions
58
feuille.c
58
feuille.c
|
@ -218,7 +218,6 @@ int main(int argc, char *argv[])
|
||||||
if (argc != 0)
|
if (argc != 0)
|
||||||
usage(1);
|
usage(1);
|
||||||
|
|
||||||
|
|
||||||
/* output folder checks */
|
/* output folder checks */
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
|
@ -233,20 +232,6 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
chdir(path);
|
chdir(path);
|
||||||
|
|
||||||
/* user checks */
|
|
||||||
if (strlen(settings.user) == 0)
|
|
||||||
settings.user = "nobody";
|
|
||||||
|
|
||||||
verbose(2, "getting uid and gid of user `%s'...", settings.user);
|
|
||||||
|
|
||||||
struct passwd *user;
|
|
||||||
if ((user = getpwnam(settings.user)) == NULL)
|
|
||||||
die(1, "User `%s' doesn't exist\n", settings.user);
|
|
||||||
|
|
||||||
int uid = user->pw_uid;
|
|
||||||
int gid = user->pw_gid;
|
|
||||||
|
|
||||||
|
|
||||||
/* server socket creation (before dropping root permissions) */
|
/* server socket creation (before dropping root permissions) */
|
||||||
verbose(1, "initializing server socket...");
|
verbose(1, "initializing server socket...");
|
||||||
|
|
||||||
|
@ -254,17 +239,20 @@ int main(int argc, char *argv[])
|
||||||
if ((server = initialize_server()) == -1)
|
if ((server = initialize_server()) == -1)
|
||||||
die(errno, "Failed to initialize server socket: %s\n", strerror(errno));
|
die(errno, "Failed to initialize server socket: %s\n", strerror(errno));
|
||||||
|
|
||||||
/* make feuille run in the background */
|
|
||||||
if (!settings.foreground) {
|
|
||||||
verbose(1, "making feuille run in the background...");
|
|
||||||
verbose(2, "closing input / output file descriptors...");
|
|
||||||
|
|
||||||
daemon(1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* chroot and drop root permissions */
|
/* chroot and drop root permissions */
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
|
if (strlen(settings.user) == 0)
|
||||||
|
settings.user = "nobody";
|
||||||
|
|
||||||
|
verbose(2, "getting uid and gid of user `%s'...", settings.user);
|
||||||
|
|
||||||
|
struct passwd *user;
|
||||||
|
if ((user = getpwnam(settings.user)) == NULL)
|
||||||
|
die(1, "User `%s' doesn't exist\n", settings.user);
|
||||||
|
|
||||||
|
int uid = user->pw_uid;
|
||||||
|
int gid = user->pw_gid;
|
||||||
|
|
||||||
verbose(2, "setting owner of `%s' to `%s'...", path, settings.user);
|
verbose(2, "setting owner of `%s' to `%s'...", path, settings.user);
|
||||||
chown(path, uid, gid);
|
chown(path, uid, gid);
|
||||||
|
|
||||||
|
@ -284,12 +272,31 @@ int main(int argc, char *argv[])
|
||||||
puts("");
|
puts("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* run feuille in the background */
|
||||||
|
if (!settings.foreground) {
|
||||||
|
verbose(1, "making feuille run in the background...");
|
||||||
|
verbose(2, "closing input / output file descriptors...");
|
||||||
|
|
||||||
|
int pid;
|
||||||
|
if ((pid = fork()) < 0)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
else if (pid > 0)
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
if (setsid() < 0)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
freopen("/dev/null", "r", stdin);
|
||||||
|
freopen("/dev/null", "w", stdout);
|
||||||
|
freopen("/dev/null", "w", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
/* OpenBSD-only security measures */
|
/* OpenBSD-only security measures */
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
pledge("proc stdio rpath wpath cpath inet", "stdio rpath wpath cpath inet");
|
pledge("proc stdio rpath wpath cpath inet", "stdio rpath wpath cpath inet");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* create a thread pool for incoming connections */
|
/* create a thread pool for incoming connections */
|
||||||
verbose(1, "initializing worker pool...");
|
verbose(1, "initializing worker pool...");
|
||||||
|
|
||||||
|
@ -372,7 +379,6 @@ int main(int argc, char *argv[])
|
||||||
die(errno, "Could not initialize worker n. %d: %s\n", i, strerror(errno));
|
die(errno, "Could not initialize worker n. %d: %s\n", i, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
verbose(1, "all workers have been initialized.");
|
verbose(1, "all workers have been initialized.");
|
||||||
|
|
Reference in a new issue