Overview
SHA1 Hash: | 7ba10f1a6ae0d828af9250e257e162a6c5ffc4c4 |
---|---|
Date: | 2009-08-31 00:48:44 |
User: | drh |
Comment: | When the "http" command is run as root, automatically set up a chroot jail and drop root privileges prior to reading any input. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/main.c from [65c875517e] to [97f8036e59].
@@ -27,10 +27,13 @@ #include "config.h" #include "main.h" #include <string.h> #include <time.h> #include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + #if INTERFACE /* ** Number of elements in an array @@ -680,10 +683,29 @@ void cmd_http(void){ const char *zIpAddr; if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){ cgi_panic("no repository specified"); } +#if !defined(__MINGW32__) + if( g.argc==3 && getuid()==0 ){ + int i; + char *zRepo = g.argv[2]; + struct stat sStat; + for(i=strlen(zRepo)-1; i>0 && zRepo[i]!='/'; i--){} + if( zRepo[i]=='/' ){ + zRepo[i] = 0; + chdir(g.argv[2]); + chroot(g.argv[2]); + g.argv[2] = &zRepo[i+1]; + } + if( stat(g.argv[2], &sStat)!=0 ){ + fossil_fatal("cannot stat() repository: %s", g.argv[2]); + } + setgid(sStat.st_gid); + setuid(sStat.st_uid); + } +#endif g.cgiPanic = 1; g.fullHttpReply = 1; if( g.argc==6 ){ g.httpIn = fopen(g.argv[3], "rb"); g.httpOut = fopen(g.argv[4], "wb");
Modified src/style.c from [4ab2cc74bf] to [29d8d356cd].
@@ -410,10 +410,13 @@ /* ** WEBPAGE: test_env */ void page_test_env(void){ style_header("Environment Test"); +#if !defined(__MINGW32__) + @ uid=%d(getuid()), gid=%d(getgid())<br> +#endif @ g.zBaseURL = %h(g.zBaseURL)<br> @ g.zTop = %h(g.zTop)<br> cgi_print_all(); style_footer(); }