config.server_admin = cm_strdup(SERVER_ADMIN);
config.defined[0] = NULL;
gethostname(config.hostname, 1024);
+#ifdef HAS_CHROOT
+ tw_add_define("HAS_CHROOT");
+#endif
}
int tw_config_read(const char* path) {
if(current->sslcert != NULL) free(current->sslcert);
current->sslcert = cm_strdup(r[1]);
}
+#endif
+#ifdef HAS_CHROOT
+ } else if(cm_strcaseequ(r[0], "ChrootDirectory")) {
+ if(r[1] == NULL) {
+ cm_log("Config", "Missing path at line %d", ln);
+ stop = 1;
+ } else {
+ if(current->chroot_path != NULL) free(current->chroot_path);
+ current->chroot_path = cm_strdup(r[1]);
+ }
#endif
} else if(cm_strcaseequ(r[0], "ForceLog")) {
if(r[1] == NULL) {
if(current->root != NULL) free(current->root);
current->root = cm_strdup(strcmp(r[1], "/") == 0 ? "" : r[1]);
}
- } else if(cm_strcaseequ(r[0], "ServerRoot")) {
- if(r[1] == NULL) {
- cm_log("Config", "Missing path at line %d", ln);
- stop = 1;
- } else {
- if(config.server_root != NULL) free(config.server_root);
- config.server_root = cm_strdup(r[1]);
- }
} else if(cm_strcaseequ(r[0], "MIMEType")) {
if(r[1] == NULL) {
cm_log("Config", "Missing extension at line %d", ln);
return "403 Forbidden";
} else if(code == 404) {
return "404 Not Found";
+ } else if(code == 500) {
+ return "500 Internal Server Error";
} else {
return "400 Bad Request";
}
}
}
}
+ bool rej = false;
cm_log("Server", "Host is %s", vhost);
int port = s == NULL ? 80 : 443;
char* host = cm_strdup(vhost);
name = host;
cm_log("Server", "Hostname is `%s', port is `%d'", host, port);
struct tw_config_entry* vhost_entry = tw_vhost_match(host, port);
+#ifdef HAS_CHROOT
+ char* chrootpath = vhost_entry->chroot_path != NULL ? vhost_entry->chroot_path : config.root.chroot_path;
+ if(chrootpath != NULL) {
+ if(chdir(chrootpath) == 0) {
+ if(chroot(".") == 0) {
+ cm_log("Server", "Chroot successful");
+ }
+ } else {
+ cm_log("Server", "chdir() failed, cannot chroot");
+ tw_http_error(s, sock, 500, name, port, vhost_entry);
+ rej = true;
+ }
+ }
+#endif
for(i = 0; i < config.module_count; i++) {
tw_mod_request_t mod_req = (tw_mod_request_t)tw_module_symbol(config.modules[i], "mod_request");
if(mod_req != NULL) {
cm_log("Server", "Document root is %s", vhost_entry->root == NULL ? "not set" : vhost_entry->root);
char* path = cm_strcat(vhost_entry->root == NULL ? "" : vhost_entry->root, req.path);
cm_log("Server", "Filesystem path is %s", path);
- bool rej = false;
#ifdef __MINGW32__
char* rpath = cm_strdup(path);
for(i = strlen(rpath) - 1; i >= 0; i--) {
fclose(f);
}
} else {
- tw_http_error(s, sock, 404, name, port, vhost_entry);
+ if(!rej) {
+ tw_http_error(s, sock, 404, name, port, vhost_entry);
+ }
}
free(path);
}
printf("Readme README\n");
printf("\n");
printf("DocumentRoot %s/www\n", argv[1]);
- printf("\n");
printf("BeginDirectory %s/www\n", argv[1]);
- printf("\tAllow all\n");
+ printf(" Allow all\n");
printf("EndDirectory\n", argv[1]);
}