diff options
Diffstat (limited to 'src/htsmodules.c')
-rw-r--r-- | src/htsmodules.c | 199 |
1 files changed, 118 insertions, 81 deletions
diff --git a/src/htsmodules.c b/src/htsmodules.c index 4c37047..e1d2ec6 100644 --- a/src/htsmodules.c +++ b/src/htsmodules.c @@ -17,18 +17,15 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Important notes: - We hereby ask people using this source NOT to use it in purpose of grabbing emails addresses, or collecting any other private information on persons. This would disgrace our work, and spoil the many hours we spent on it. - Please visit our Website: http://www.httrack.com */ - /* ------------------------------------------------------------ */ /* File: htsmodules.c subroutines: */ /* external modules (parsers) */ @@ -44,7 +41,7 @@ Please visit our Website: http://www.httrack.com #include "htsbasenet.h" #include "htslib.h" -extern int fspc(httrackp *opt,FILE* fp,const char* type); +extern int fspc(httrackp * opt, FILE * fp, const char *type); #ifndef _WIN32 #if HTS_DLOPEN @@ -60,6 +57,7 @@ extern int fspc(httrackp *opt,FILE* fp,const char* type); /* >>> Put all modules variables here */ int gz_is_available = 0; + #if 0 t_gzopen gzopen = NULL; t_gzread gzread = NULL; @@ -88,18 +86,22 @@ t_SSL_load_error_strings SSL_load_error_strings = NULL; int V6_is_available = HTS_INET6; -static char WHAT_is_available[64]=""; +static char WHAT_is_available[64] = ""; + /* <<< */ -HTSEXT_API const char* hts_get_version_info(httrackp *opt) { +HTSEXT_API const char *hts_get_version_info(httrackp * opt) { size_t size; int i; + strcpy(opt->state.HTbuff, WHAT_is_available); size = strlen(opt->state.HTbuff); - for(i = 0 ; i < opt->libHandles.count ; i++) { + for(i = 0; i < opt->libHandles.count; i++) { const char *name = opt->libHandles.handles[i].moduleName; + if (name != NULL) { size_t nsize = strlen(name) + sizeof("+"); + size += nsize; if (size + 1 >= sizeof(opt->state.HTbuff)) break; @@ -113,24 +115,30 @@ HTSEXT_API const char* hts_get_version_info(httrackp *opt) { /* memory checks */ HTSEXT_API htsErrorCallback htsCallbackErr = NULL; HTSEXT_API int htsMemoryFastXfr = 1; /* fast xfr by default */ -void abortLog__fnc(char* msg, char* file, int line); -void abortLog__fnc(char* msg, char* file, int line) { - FILE* fp = fopen("CRASH.TXT", "wb"); - if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); - if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); - if (!fp) fp = fopen("CRASH.TXT", "wb"); +void abortLog__fnc(char *msg, char *file, int line); +void abortLog__fnc(char *msg, char *file, int line) { + FILE *fp = fopen("CRASH.TXT", "wb"); + + if (!fp) + fp = fopen("/tmp/CRASH.TXT", "wb"); + if (!fp) + fp = fopen("C:\\CRASH.TXT", "wb"); + if (!fp) + fp = fopen("CRASH.TXT", "wb"); if (fp) { - fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '%s', line %d\r\n", file, line); + fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '%s', line %d\r\n", + file, line); fprintf(fp, "Reason:\r\n%s\r\n", msg); fflush(fp); fclose(fp); } } -HTSEXT_API t_abortLog abortLog__ = abortLog__fnc; /* avoid VC++ inlining */ -static void htspe_log(htsmoduleStruct* str, const char* msg); +HTSEXT_API t_abortLog abortLog__ = abortLog__fnc; /* avoid VC++ inlining */ + +static void htspe_log(htsmoduleStruct * str, const char *msg); -int hts_parse_externals(htsmoduleStruct* str) { +int hts_parse_externals(htsmoduleStruct * str) { str->wrapper_name = "wrapper-lib"; /* External callback */ @@ -138,7 +146,8 @@ int hts_parse_externals(htsmoduleStruct* str) { if (str->wrapper_name == NULL) str->wrapper_name = "wrapper-lib"; /* Blacklisted */ - if (multipleStringMatch(str->wrapper_name, StringBuff(str->opt->mod_blacklist))) { + if (multipleStringMatch + (str->wrapper_name, StringBuff(str->opt->mod_blacklist))) { return -1; } else { htspe_log(str, str->wrapper_name); @@ -162,13 +171,14 @@ int hts_parse_externals(htsmoduleStruct* str) { // chain->moduleHandle = moduleHandle; //} -void clearCallbacks(htscallbacks* chain_); -void clearCallbacks(htscallbacks* chain_) { - htscallbacks* chain; +void clearCallbacks(htscallbacks * chain_); +void clearCallbacks(htscallbacks * chain_) { + htscallbacks *chain; + chain = chain_; while(chain != NULL) { if (chain->exitFnc != NULL) { - (void) chain->exitFnc(); /* result ignored */ + (void) chain->exitFnc(); /* result ignored */ chain->exitFnc = NULL; } chain = chain->next; @@ -184,18 +194,20 @@ void clearCallbacks(htscallbacks* chain_) { } chain = chain->next; } - chain = chain_->next; // Don't free the block #0 + chain = chain_->next; // Don't free the block #0 while(chain != NULL) { - htscallbacks* nextchain = chain->next; + htscallbacks *nextchain = chain->next; + freet(chain); chain = nextchain; } - chain_->next = NULL; // Empty + chain_->next = NULL; // Empty } -void* openFunctionLib(const char* file_) { - void* handle; +void *openFunctionLib(const char *file_) { + void *handle; char *file = malloct(strlen(file_) + 32); + strcpy(file, file_); #ifdef _WIN32 handle = LoadLibraryA(file); @@ -214,7 +226,7 @@ void* openFunctionLib(const char* file_) { return handle; } -void closeFunctionLib(void* handle) { +void closeFunctionLib(void *handle) { #ifdef _WIN32 FreeLibrary(handle); #else @@ -222,19 +234,20 @@ void closeFunctionLib(void* handle) { #endif } -void* getFunctionPtr(void* handle, const char* fncname_) { +void *getFunctionPtr(void *handle, const char *fncname_) { if (handle) { - void* userfunction = NULL; + void *userfunction = NULL; char *fncname = strdupt(fncname_); /* Strip optional comma */ char *comma; - if ((comma = strchr(fncname, ',')) != NULL) { /* empty arg */ + + if ((comma = strchr(fncname, ',')) != NULL) { /* empty arg */ *comma++ = '\0'; } - + /* the function itself */ - userfunction = (void*) DynamicGet(handle, (char*)fncname); + userfunction = (void *) DynamicGet(handle, (char *) fncname); freet(fncname); @@ -243,34 +256,37 @@ void* getFunctionPtr(void* handle, const char* fncname_) { return NULL; } -void* ssl_handle = NULL; +void *ssl_handle = NULL; + #ifdef _WIN32 -void* ssl_handle_2 = NULL; +void *ssl_handle_2 = NULL; #endif void htspe_init(void) { static int initOk = 0; + if (!initOk) { initOk = 1; /* See CVE-2010-5252 */ #if (defined(_WIN32) && (!defined(_DEBUG))) /* See KB 2389418 - "If this parameter is an empty string (""), the call removes the - current directory from the default DLL search order" */ + "If this parameter is an empty string (""), the call removes the + current directory from the default DLL search order" */ if (!SetDllDirectory("")) { - assertf(! "SetDllDirectory failed"); + assertf(!"SetDllDirectory failed"); } #endif - + /* Zlib is now statically linked */ gz_is_available = 1; /* OpenSSL */ #if HTS_DLOPEN { - void* handle; + void *handle; + #ifdef _WIN32 - handle = LoadLibraryA((char*)"ssleay32"); + handle = LoadLibraryA((char *) "ssleay32"); #else /* We are compatible with 0.9.6/7/8/8b and potentially above */ static const char *const libs[] = { @@ -288,62 +304,82 @@ void htspe_init(void) { "libssl.so.0.9.8n", "libssl.so.0.9.8m", "libssl.so.0.9.8l", - "libssl.so.0.9.8k", /* (Debarshi Ray) */ - "libssl.so.0.9.8j", /* (Debarshi Ray) */ - "libssl.so.0.9.8g", /* Added 8g release too (Debarshi Ray) */ + "libssl.so.0.9.8k", /* (Debarshi Ray) */ + "libssl.so.0.9.8j", /* (Debarshi Ray) */ + "libssl.so.0.9.8g", /* Added 8g release too (Debarshi Ray) */ "libssl.so.0.9.8b", "libssl.so.0.9.8", "libssl.so.0.9.7", "libssl.so.0.9.6", - "libssl.so", /* Try harder with devel link */ + "libssl.so", /* Try harder with devel link */ NULL }; int i; - for(i = 0, handle = NULL ; handle == NULL && libs[i] != NULL ; i++) { + + for(i = 0, handle = NULL; handle == NULL && libs[i] != NULL; i++) { handle = dlopen(libs[i], RTLD_LAZY); } #endif ssl_handle = handle; if (handle != NULL) { - SSL_shutdown = (t_SSL_shutdown) DynamicGet(handle, (char*)"SSL_shutdown"); - SSL_free = (t_SSL_free) DynamicGet(handle, (char*)"SSL_free"); - SSL_new = (t_SSL_new) DynamicGet(handle, (char*)"SSL_new"); - SSL_clear = (t_SSL_clear) DynamicGet(handle, (char*)"SSL_clear"); - SSL_set_fd = (t_SSL_set_fd) DynamicGet(handle, (char*)"SSL_set_fd"); - SSL_set_connect_state = (t_SSL_set_connect_state) DynamicGet(handle, (char*)"SSL_set_connect_state"); - SSL_connect = (t_SSL_connect) DynamicGet(handle, (char*)"SSL_connect"); - SSL_get_error = (t_SSL_get_error) DynamicGet(handle, (char*)"SSL_get_error"); - SSL_write = (t_SSL_write) DynamicGet(handle, (char*)"SSL_write"); - SSL_read = (t_SSL_read) DynamicGet(handle, (char*)"SSL_read"); - SSL_library_init = (t_SSL_library_init) DynamicGet(handle, (char*)"SSL_library_init"); - ERR_load_SSL_strings = (t_ERR_load_SSL_strings) DynamicGet(handle, (char*)"ERR_load_SSL_strings"); - SSLv23_client_method = (t_SSLv23_client_method) DynamicGet(handle, (char*)"SSLv23_client_method"); - SSL_CTX_new = (t_SSL_CTX_new) DynamicGet(handle, (char*)"SSL_CTX_new"); - SSL_load_error_strings = (t_SSL_load_error_strings) DynamicGet(handle, (char*)"SSL_load_error_strings"); - SSL_CTX_ctrl = (t_SSL_CTX_ctrl) DynamicGet(handle, (char*)"SSL_CTX_ctrl"); + SSL_shutdown = + (t_SSL_shutdown) DynamicGet(handle, (char *) "SSL_shutdown"); + SSL_free = (t_SSL_free) DynamicGet(handle, (char *) "SSL_free"); + SSL_new = (t_SSL_new) DynamicGet(handle, (char *) "SSL_new"); + SSL_clear = (t_SSL_clear) DynamicGet(handle, (char *) "SSL_clear"); + SSL_set_fd = (t_SSL_set_fd) DynamicGet(handle, (char *) "SSL_set_fd"); + SSL_set_connect_state = + (t_SSL_set_connect_state) DynamicGet(handle, + (char *) + "SSL_set_connect_state"); + SSL_connect = + (t_SSL_connect) DynamicGet(handle, (char *) "SSL_connect"); + SSL_get_error = + (t_SSL_get_error) DynamicGet(handle, (char *) "SSL_get_error"); + SSL_write = (t_SSL_write) DynamicGet(handle, (char *) "SSL_write"); + SSL_read = (t_SSL_read) DynamicGet(handle, (char *) "SSL_read"); + SSL_library_init = + (t_SSL_library_init) DynamicGet(handle, (char *) "SSL_library_init"); + ERR_load_SSL_strings = + (t_ERR_load_SSL_strings) DynamicGet(handle, + (char *) "ERR_load_SSL_strings"); + SSLv23_client_method = + (t_SSLv23_client_method) DynamicGet(handle, + (char *) "SSLv23_client_method"); + SSL_CTX_new = + (t_SSL_CTX_new) DynamicGet(handle, (char *) "SSL_CTX_new"); + SSL_load_error_strings = + (t_SSL_load_error_strings) DynamicGet(handle, + (char *) + "SSL_load_error_strings"); + SSL_CTX_ctrl = + (t_SSL_CTX_ctrl) DynamicGet(handle, (char *) "SSL_CTX_ctrl"); #ifdef _WIN32 - handle = LoadLibraryA((char*)"libeay32"); + handle = LoadLibraryA((char *) "libeay32"); ssl_handle_2 = handle; #endif - ERR_load_crypto_strings = (t_ERR_load_crypto_strings) DynamicGet(handle, (char*)"ERR_load_crypto_strings"); - ERR_error_string = (t_ERR_error_string) DynamicGet(handle, (char*)"ERR_error_string"); - - if (SSL_shutdown && SSL_free && SSL_CTX_ctrl && SSL_new && SSL_clear && - SSL_set_fd && SSL_set_connect_state && SSL_connect && SSL_get_error && SSL_write - && SSL_read && SSL_library_init && SSLv23_client_method && SSL_CTX_new - && SSL_load_error_strings && ERR_error_string) { + ERR_load_crypto_strings = + (t_ERR_load_crypto_strings) DynamicGet(handle, + (char *) + "ERR_load_crypto_strings"); + ERR_error_string = + (t_ERR_error_string) DynamicGet(handle, (char *) "ERR_error_string"); + + if (SSL_shutdown && SSL_free && SSL_CTX_ctrl && SSL_new && SSL_clear + && SSL_set_fd && SSL_set_connect_state && SSL_connect + && SSL_get_error && SSL_write && SSL_read && SSL_library_init + && SSLv23_client_method && SSL_CTX_new && SSL_load_error_strings + && ERR_error_string) { SSL_is_available = 1; } } } #endif /* */ - + /* Options availability */ - sprintf(WHAT_is_available, "%s%s%s", - V6_is_available ? "" : "-noV6", - gz_is_available ? "" : "-nozip", - SSL_is_available ? "" : "-nossl"); + sprintf(WHAT_is_available, "%s%s%s", V6_is_available ? "" : "-noV6", + gz_is_available ? "" : "-nozip", SSL_is_available ? "" : "-nossl"); } } @@ -359,13 +395,14 @@ void htspe_uninit(void) { #endif } -static void htspe_log(htsmoduleStruct* str, const char* msg) { - const char* savename = str->filename; - httrackp* opt = (httrackp*) str->opt; - hts_log_print(opt, LOG_DEBUG, "(External module): parsing %s using module %s", - savename, msg); +static void htspe_log(htsmoduleStruct * str, const char *msg) { + const char *savename = str->filename; + httrackp *opt = (httrackp *) str->opt; + + hts_log_print(opt, LOG_DEBUG, "(External module): parsing %s using module %s", + savename, msg); } -HTSEXT_API const char* hts_is_available(void) { +HTSEXT_API const char *hts_is_available(void) { return WHAT_is_available; } |