Mercurial > hg > quicktun
changeset 49:b4de2326e9f7
Added chroot support
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Thu, 30 May 2013 01:12:23 +0200 |
parents | f80422b612ab |
children | 02b4a9a139da |
files | src/common.c |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/common.c Fri May 24 17:14:51 2013 +0200 +++ b/src/common.c Thu May 30 01:12:23 2013 +0200 @@ -263,14 +263,20 @@ static int drop_privileges() { char* envval; + struct passwd *pw = NULL; if (envval = getconf("SETUID")) { + pw = getpwnam(envval); + if (!pw) return errorexitp("getpwnam"); + } + if (envval = getconf("CHROOT")) { + if (chroot(envval)) return errorexitp("chroot"); + if (chdir("/")) return errorexitp("chdir /"); + } + if (pw) { if (setgroups(0, NULL) == -1) return errorexitp("setgroups"); - struct passwd *pw = getpwnam(envval); - if (!pw) return errorexitp("getpwnam"); if (setgid(pw->pw_gid) == -1) return errorexitp("setgid"); if (setuid(pw->pw_uid) == -1) return errorexitp("setuid"); } - chdir("/"); } static void qtsendnetworkpacket(struct qtsession* session, char* msg, int len) {