Mercurial > hg > quicktun
comparison src/common.c @ 49:b4de2326e9f7
Added chroot support
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Thu, 30 May 2013 01:12:23 +0200 |
parents | e896392f7e03 |
children | 3115f8af98bb |
comparison
equal
deleted
inserted
replaced
48:f80422b612ab | 49:b4de2326e9f7 |
---|---|
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 static int drop_privileges() { | 264 static int drop_privileges() { |
265 char* envval; | 265 char* envval; |
266 struct passwd *pw = NULL; | |
266 if (envval = getconf("SETUID")) { | 267 if (envval = getconf("SETUID")) { |
268 pw = getpwnam(envval); | |
269 if (!pw) return errorexitp("getpwnam"); | |
270 } | |
271 if (envval = getconf("CHROOT")) { | |
272 if (chroot(envval)) return errorexitp("chroot"); | |
273 if (chdir("/")) return errorexitp("chdir /"); | |
274 } | |
275 if (pw) { | |
267 if (setgroups(0, NULL) == -1) return errorexitp("setgroups"); | 276 if (setgroups(0, NULL) == -1) return errorexitp("setgroups"); |
268 struct passwd *pw = getpwnam(envval); | |
269 if (!pw) return errorexitp("getpwnam"); | |
270 if (setgid(pw->pw_gid) == -1) return errorexitp("setgid"); | 277 if (setgid(pw->pw_gid) == -1) return errorexitp("setgid"); |
271 if (setuid(pw->pw_uid) == -1) return errorexitp("setuid"); | 278 if (setuid(pw->pw_uid) == -1) return errorexitp("setuid"); |
272 } | 279 } |
273 chdir("/"); | |
274 } | 280 } |
275 | 281 |
276 static void qtsendnetworkpacket(struct qtsession* session, char* msg, int len) { | 282 static void qtsendnetworkpacket(struct qtsession* session, char* msg, int len) { |
277 if (session->remote_float == 0) { | 283 if (session->remote_float == 0) { |
278 len = write(session->fd_socket, msg, len); | 284 len = write(session->fd_socket, msg, len); |