applied rransom's quark patch for FreeBSD compliance, thanks

This commit is contained in:
garbeam@gmail.com 2011-06-26 10:51:42 +01:00
parent d6cbb5b9d9
commit 3a9701d828
2 changed files with 21 additions and 17 deletions

View file

@ -1,14 +1,14 @@
/* quark configuration */ /* quark configuration */
static const char servername[] = "127.0.0.1"; static const char servername[] = "127.0.0.1";
static const char serverport[] = "80"; static const char serverport[] = "80";
static const char docroot[] = "."; static const char docroot[] = ".";
static const char docindex[] = "index.html"; static const char docindex[] = "index.html";
static const char user[] = "nobody"; static const char *user = "nobody";
static const char group[] = "nogroup"; static const char *group = "nogroup";
static const char cgi_dir[] = "/var/www/werc-dev/bin"; static const char cgi_dir[] = "/var/www/werc-dev/bin";
static const char cgi_script[] = "./werc.rc"; static const char cgi_script[] = "./werc.rc";
static const int cgi_mode = 0; static const int cgi_mode = 0;
static const MimeType servermimes[] = { static const MimeType servermimes[] = {
{ "html", "text/html; charset=UTF-8" }, { "html", "text/html; charset=UTF-8" },

20
quark.c
View file

@ -522,10 +522,12 @@ main(int argc, char *argv[]) {
die("usage: quark [-v]\n"); die("usage: quark [-v]\n");
/* sanity checks */ /* sanity checks */
if(!(upwd = getpwnam(user))) if(user)
die("error: invalid user %s\n", user); if(!(upwd = getpwnam(user)))
if(!(gpwd = getgrnam(group))) die("error: invalid user %s\n", user);
die("error: invalid group %s\n", group); if(group)
if(!(gpwd = getgrnam(group)))
die("error: invalid group %s\n", group);
signal(SIGCHLD, sighandler); signal(SIGCHLD, sighandler);
signal(SIGHUP, sighandler); signal(SIGHUP, sighandler);
@ -573,10 +575,12 @@ main(int argc, char *argv[]) {
if(chroot(".") == -1) if(chroot(".") == -1)
die("error: chroot .: %s\n", strerror(errno)); die("error: chroot .: %s\n", strerror(errno));
if(setgid(gpwd->gr_gid) == -1) if(gpwd)
die("error: cannot set group id\n"); if(setgid(gpwd->gr_gid) == -1)
if(setuid(upwd->pw_uid) == -1) die("error: cannot set group id\n");
die("error: cannot set user id\n"); if(upwd)
if(setuid(upwd->pw_uid) == -1)
die("error: cannot set user id\n");
if(getuid() == 0) if(getuid() == 0)
die("error: won't run with root permissions, choose another user\n"); die("error: won't run with root permissions, choose another user\n");