diff --git a/CMakeLists.txt b/CMakeLists.txt index 86944e9..9a4ee42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required (VERSION 2.6) project (LiveProxies) -set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_BUILD_TYPE RelWithDebInfo) +set (CMAKE_C_FLAGS "-DDEBUG -g ${CMAKE_C_FLAGS}") if (WIN32) set (CMAKE_C_FLAGS "--std=gnu99 -Wall ${CMAKE_C_FLAGS}") diff --git a/Harvester.c b/Harvester.c index aa4cda2..c290533 100644 --- a/Harvester.c +++ b/Harvester.c @@ -116,17 +116,17 @@ void HarvestLoop() HANDLE d = NULL; size_t harvestersPathLen = strlen(HarvestersPath); - char *fullPath = malloc((harvestersPathLen + 4) * sizeof(char)); { + char *fullPath = malloc((harvestersPathLen + 3) * sizeof(char)); { strcpy(fullPath, HarvestersPath); - if (HarvestersPath[harvestersPathLen - 1] == '\\') { - strcat(fullPath, "*.*"); - HarvestersPath[harvestersPathLen + 3] = 0x00; - } else - strcat(fullPath, "\\*.*"); - HarvestersPath[harvestersPathLen + 4] = 0x00; - - if ((d = FindFirstFile(WINDOWS_LOCAL_HTML_PATH"*.*", &fdFile)) == INVALID_HANDLE_VALUE) { - d = false; + strcat(fullPath, "\\*"); + fullPath[harvestersPathLen + 2] = 0x00; + + if ((d = FindFirstFile(WINDOWS_LOCAL_HTML_PATH"\\*.*", &fdFile)) == INVALID_HANDLE_VALUE) { + Log(LOG_LEVEL_DEBUG, "WIN32: Failed to search files: %d (%s)", GetLastError(), WINDOWS_LOCAL_HTML_PATH"*.*"); + if ((d = FindFirstFile(fullPath, &fdFile)) == INVALID_HANDLE_VALUE) { + Log(LOG_LEVEL_ERROR, "WIN32: Failed to search files: %d (%s)", GetLastError(), fullPath); + d = false; + } } } free(fullPath); #endif @@ -158,17 +158,13 @@ void HarvestLoop() sourceType = URL; if (sourceType == NONE) continue; - char *path = (char*)malloc(10 + strlen(name) + 1 /* NULL */); sprintf(path, "%s", name); path[strlen(path) - (sourceType == SCRIPT ? 3 : 4)] = '\0'; - Log(LOG_LEVEL_SUCCESS, "Executing %s... (%s)", path, ProxySourceTypeToString(sourceType)); - char *result; uint32_t added = 0, addedPrev = 0, total = 0; PROXY_TYPE curType = PROXY_TYPE_HTTP; - if (sourceType == SCRIPT) { pName = PyString_FromString(path); pModule = PyImport_Import(pName); @@ -214,9 +210,13 @@ void HarvestLoop() } free(pathFull); } if (sourceType == URL) { - char pathFull = malloc((strlen(HarvestersPath) + 1 + fileNameLen) * sizeof(char)); { + char *pathFull = malloc((strlen(HarvestersPath) + 1 + fileNameLen) * sizeof(char) + 1); { strcpy(pathFull, HarvestersPath); +#ifdef __linux__ strcat(pathFull, "/"); +#elif defined _WIN32 || defined _WIN64 + strcat(pathFull, "\\"); +#endif strcat(pathFull, name); FILE *hFile = fopen(pathFull, "r"); { @@ -243,15 +243,13 @@ void HarvestLoop() if (url[strlen(url) - 1] == '\n') url[strlen(url) - 1] = 0x00; - result = malloc(1); + result = malloc(0); CURL *hCurl = curl_easy_init(); { curl_easy_setopt(hCurl, CURLOPT_URL, url); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, &result); curl_easy_setopt(hCurl, CURLOPT_USERAGENT, REQUEST_UA); - CURLcode res = curl_easy_perform(hCurl); - if (res != CURLE_OK) { Log(LOG_LEVEL_WARNING, "Request to %s failed: %s", url, curl_easy_strerror(res)); } else { diff --git a/Interface.c b/Interface.c index 61be69d..d322428 100644 --- a/Interface.c +++ b/Interface.c @@ -107,7 +107,7 @@ static bool AuthVerify(char *Buff, struct evbuffer *OutBuff, int Fd, WEB_INTERFA } pthread_mutex_unlock(&AuthWebLock); } /* End authorize by cookie */ endCookie: - + if (!AllowOnlyCookie) { /* Authorize by login */ char *username, *password; char *authStr; @@ -164,6 +164,8 @@ static bool AuthVerify(char *Buff, struct evbuffer *OutBuff, int Fd, WEB_INTERFA char *pbkdf2 = PBKDF2_HMAC_SHA_512Ex(password, strlen(password), salt, saltLen, iterations); // TODO: Possible DoS, needs login limit free(salt); + Log(LOG_LEVEL_DEBUG, "PBKDF2 CMP: %s vs %s", AuthLocalList[x]->password, pbkdf2); + if (strcmp(AuthLocalList[x]->password, pbkdf2) == 0) { pthread_mutex_unlock(&AuthLocalLock); free(pbkdf2); diff --git a/LiveProxies.c b/LiveProxies.c index 88924b6..a73769d 100644 --- a/LiveProxies.c +++ b/LiveProxies.c @@ -443,8 +443,8 @@ int main(int argc, char** argv) "Accept-Encoding: gzip, deflate, sdch\r\n" "Accept-Language: en-US,en;q=0.8\r\n" "{KEY_NAME}: {KEY_VAL}") - // Host and LPKey is injected upon request - StrReplaceOrig(&RequestString, "{VERSION}", VERSION); + // Host and LPKey is injected upon request + StrReplaceOrig(&RequestString, "{VERSION}", VERSION); StrReplaceOrig(&RequestString, "{UA}", RequestUA); StrReplaceOrig(&RequestString, "{KEY_NAME}", RequestHeaderKey); RequestStringLen = strlen(RequestString); @@ -459,23 +459,40 @@ int main(int argc, char** argv) /* Auth init */ { config_t cfg; config_init(&cfg); - bool noAuth = false; + bool authExists = true; AuthLocalList = NULL; AuthLocalCount = 0; - if (config_read_file(&cfg, "passwd.conf") == CONFIG_FALSE) { - Log(LOG_LEVEL_DEBUG, "Failed to open passwd.conf in working directory, opening in global...: %s (line %d)", config_error_text(&cfg), config_error_line(&cfg)); - noAuth = true; +#ifdef __linux__ + globalPath = "/etc/liveproxies/passwd.conf"; +#elif defined _WIN32 || defined _WIN64 + globalPath = malloc((strlen(WinAppData) + 29) * sizeof(char) + 1); + strcpy(globalPath, WinAppData); + strcat(globalPath, "\\liveproxies\\passwd.conf"); +#endif +#ifdef __linux__ + localPath = "./passwd.conf"; +#elif defined _WIN32 || defined _WIN64 + localPath = ".\\passwd.conf"; +#endif + + if (config_read_file(&cfg, localPath) == CONFIG_FALSE) { + Log(LOG_LEVEL_DEBUG, "Failed to open %s in working directory, opening in global...: %s (line %d)", localPath, config_error_text(&cfg), config_error_line(&cfg)); + authExists = false; } - if (noAuth) { - if (config_read_file(&cfg, "/etc/liveproxies/passwd.conf") == CONFIG_FALSE) - Log(LOG_LEVEL_DEBUG, "Failed to open /etc/liveproxies/passwd.conf: %s (line %d)", config_error_text(&cfg), config_error_line(&cfg)); + if (!authExists) { + if (config_read_file(&cfg, globalPath) == CONFIG_FALSE) + Log(LOG_LEVEL_DEBUG, "Failed to open %s: %s (line %d)", globalPath, config_error_text(&cfg), config_error_line(&cfg)); else - noAuth = false; + authExists = false; } - if (!noAuth) { +#if defined _WIN32 || defined _WIN64 + free(globalPath); +#endif + + if (authExists) { pthread_mutex_init(&AuthLocalLock, NULL); config_setting_t *cfgRoot = config_root_setting(&cfg); size_t x = 0; @@ -495,6 +512,7 @@ int main(int argc, char** argv) AuthLocalList[AuthLocalCount - 1]->username = malloc((strlen(val) * sizeof(char)) + 1); strcpy((char*)AuthLocalList[AuthLocalCount - 1]->username, val); + Log(LOG_LEVEL_DEBUG, "Added user %s", AuthLocalList[AuthLocalCount - 1]->username); } else { AuthLocalList[AuthLocalCount - 1]->password = malloc((strlen(val) * sizeof(char)) + 1); strcpy((char*)AuthLocalList[AuthLocalCount - 1]->password, val); diff --git a/Logger.c b/Logger.c index f72493d..78cfbe1 100644 --- a/Logger.c +++ b/Logger.c @@ -4,12 +4,10 @@ #include #include -#define DEBUG 1 - void _Log(char *File, int Line, LOG_LEVEL Level, const char *Format, ...) { if (Level == LOG_LEVEL_DEBUG) { -#if !DEBUG +#ifndef DEBUG return; #endif } diff --git a/Server.c b/Server.c index e816a81..8c67e4a 100644 --- a/Server.c +++ b/Server.c @@ -29,7 +29,7 @@ #include "HtmlTemplate.h" #include "Websocket.h" #include -#if DEBUG +#if defined DEBUG && defined __linux__ #include #endif #include @@ -411,7 +411,7 @@ void ServerRead(struct bufferevent *BuffEvent, void *Ctx) char *buff = malloc(len + 1); evbuffer_copyout(evBuff, buff, len); -#if DEBUG +#if defined DEBUG && defined __linux__ VALGRIND_MAKE_MEM_DEFINED(buff, len + 1); #endif diff --git a/bin/win32_mingw/LiveProxies.exe b/bin/win32_mingw/LiveProxies.exe index 9406fcc..fc3d116 100644 Binary files a/bin/win32_mingw/LiveProxies.exe and b/bin/win32_mingw/LiveProxies.exe differ