X-Git-Url: http://git.wpitchoune.net/gitweb/?p=psensor.git;a=blobdiff_plain;f=src%2Fserver%2Fserver.c;h=95998c8deb916813798042df837170f2600170c4;hp=d0a97094d68c7344bfdde6825b8085d01631d700;hb=8b10426dcc0246c1712a99460dd470dcb1cc4d9c;hpb=ed8be50bd23e5b85e88639baf54d99e93b9712da diff --git a/src/server/server.c b/src/server/server.c index d0a9709..95998c8 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -23,6 +23,7 @@ #include #define _(str) gettext(str) +#include #include #include #include @@ -81,7 +82,7 @@ static pthread_mutex_t mutex; static int server_stop_requested; -static void print_version() +static void print_version(void) { printf("psensor-server %s\n", VERSION); printf(_("Copyright (C) %s jeanfi@gmail.com\n" @@ -92,7 +93,7 @@ static void print_version() "2010-2012"); } -static void print_help() +static void print_help(void) { printf(_("Usage: %s [OPTION]...\n"), program_name); @@ -245,14 +246,25 @@ static struct MHD_Response *create_response_file(const char *nurl, static struct MHD_Response * create_response(const char *nurl, const char *method, unsigned int *rp_code) { + char *page, *fpath, *rpath; struct MHD_Response *resp = NULL; + int n; if (!strncmp(nurl, URL_BASE_API_1_1, strlen(URL_BASE_API_1_1))) { resp = create_response_api(nurl, method, rp_code); } else { - char *fpath = get_path(nurl, server_data.www_dir); - - resp = create_response_file(nurl, method, rp_code, fpath); + fpath = get_path(nurl, server_data.www_dir); + + rpath = realpath(fpath, NULL); + if (rpath) { + n = strlen(server_data.www_dir); + if (!strncmp(server_data.www_dir, rpath, n)) + resp = create_response_file(nurl, + method, + rp_code, + fpath); + free(rpath); + } free(fpath); } @@ -260,7 +272,7 @@ create_response(const char *nurl, const char *method, unsigned int *rp_code) if (resp) return resp; - char *page = strdup(PAGE_NOT_FOUND); + page = strdup(PAGE_NOT_FOUND); *rp_code = MHD_HTTP_NOT_FOUND; return MHD_create_response_from_data(strlen(page), @@ -348,7 +360,7 @@ int main(int argc, char *argv[]) switch (optc) { case 'w': if (optarg) - server_data.www_dir = strdup(optarg); + server_data.www_dir = realpath(optarg, NULL); break; case 'p': if (optarg) @@ -387,8 +399,14 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if (!server_data.www_dir) - server_data.www_dir = strdup(DEFAULT_WWW_DIR); + if (!server_data.www_dir) { + server_data.www_dir = realpath(DEFAULT_WWW_DIR, NULL); + if (!server_data.www_dir) { + fprintf(stderr, + _("Webserver directory does not exist.\n")); + exit(EXIT_FAILURE); + } + } if (!log_file) log_file = strdup(DEFAULT_LOG_FILE); @@ -464,7 +482,7 @@ int main(int argc, char *argv[]) psensor_free(server_data.cpu_usage); #endif free(server_data.www_dir); - sensors_cleanup(); + lmsensor_cleanup(); #ifdef HAVE_GTOP sysinfo_cleanup();