From 3a9701d8282a3eb1639b6ba01a442eee39006d77 Mon Sep 17 00:00:00 2001 From: "garbeam@gmail.com" Date: Sun, 26 Jun 2011 10:51:42 +0100 Subject: [PATCH] applied rransom's quark patch for FreeBSD compliance, thanks --- config.def.h | 18 +++++++++--------- quark.c | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/config.def.h b/config.def.h index f79db7b..86e4afd 100644 --- a/config.def.h +++ b/config.def.h @@ -1,14 +1,14 @@ /* quark configuration */ -static const char servername[] = "127.0.0.1"; -static const char serverport[] = "80"; -static const char docroot[] = "."; -static const char docindex[] = "index.html"; -static const char user[] = "nobody"; -static const char group[] = "nogroup"; -static const char cgi_dir[] = "/var/www/werc-dev/bin"; -static const char cgi_script[] = "./werc.rc"; -static const int cgi_mode = 0; +static const char servername[] = "127.0.0.1"; +static const char serverport[] = "80"; +static const char docroot[] = "."; +static const char docindex[] = "index.html"; +static const char *user = "nobody"; +static const char *group = "nogroup"; +static const char cgi_dir[] = "/var/www/werc-dev/bin"; +static const char cgi_script[] = "./werc.rc"; +static const int cgi_mode = 0; static const MimeType servermimes[] = { { "html", "text/html; charset=UTF-8" }, diff --git a/quark.c b/quark.c index 49dfe9b..660a405 100644 --- a/quark.c +++ b/quark.c @@ -522,10 +522,12 @@ main(int argc, char *argv[]) { die("usage: quark [-v]\n"); /* sanity checks */ - if(!(upwd = getpwnam(user))) - die("error: invalid user %s\n", user); - if(!(gpwd = getgrnam(group))) - die("error: invalid group %s\n", group); + if(user) + if(!(upwd = getpwnam(user))) + die("error: invalid user %s\n", user); + if(group) + if(!(gpwd = getgrnam(group))) + die("error: invalid group %s\n", group); signal(SIGCHLD, sighandler); signal(SIGHUP, sighandler); @@ -573,10 +575,12 @@ main(int argc, char *argv[]) { if(chroot(".") == -1) die("error: chroot .: %s\n", strerror(errno)); - if(setgid(gpwd->gr_gid) == -1) - die("error: cannot set group id\n"); - if(setuid(upwd->pw_uid) == -1) - die("error: cannot set user id\n"); + if(gpwd) + if(setgid(gpwd->gr_gid) == -1) + die("error: cannot set group id\n"); + if(upwd) + if(setuid(upwd->pw_uid) == -1) + die("error: cannot set user id\n"); if(getuid() == 0) die("error: won't run with root permissions, choose another user\n");