static void SSL_error_stack(void) { /* recursive dump of the error stack */ unsigned long err; char string[120]; err=ERR_get_error(); if(!err) return; SSL_error_stack(); ERR_error_string(err, string); joe_error("error stack: %lX : %s", err, string); }
/** * maps a file to our address space * and returns it the calling function. */ void load_file(URL *U, char *file) { FILE *fp; size_t len = 0; struct stat st; char *filename; char postdata[POST_BUF]; unichar ubuf[POST_BUF+1]; size_t ulen; filename = trim(file); memset(postdata, 0, POST_BUF); if((lstat(filename, &st) == 0) || (errno != ENOENT)){ len = st.st_size; if((fp = fopen(filename, "r")) == NULL){ joe_error("could not open file: %s", filename); return; } if((fread(postdata, 1, len, fp )) == len){ if(looks_ascii((unsigned char*)postdata,len,ubuf,&ulen)) trim(postdata); else if(looks_utf8((unsigned char*)postdata,len,ubuf,&ulen)) trim(postdata); } else { joe_error( "unable to read file: %s", filename ); } fclose(fp); } if(strlen(postdata) > 0){ U->conttype = xstrdup(get_content_type(filename)); U->postlen = strlen(postdata); U->postdata = malloc(U->postlen); memcpy(U->postdata, postdata, U->postlen); U->postdata[U->postlen] = 0; } return; }
/** * scout main */ int main( int argc, char *argv[] ) { int x, result; /* index, func. result*/ struct sigaction action; CLIENT *client; /* defined in setup.h */ init_config(); /* defined in init.h */ parse_cmdline(argc, argv); /* defined above */ if( my.config ){ /* see: init.h */ show_config( TRUE ); } memset( &action, 0, sizeof( action )); action.sa_handler = signal_handler; if( sigaction( SIGHUP, &action, NULL )) joe_error( "sigaction" ); if( sigaction( SIGINT, &action, NULL)) joe_error( "sigaction" ); if( sigaction( SIGTERM, &action, NULL)) joe_error( "sigaction" ); /* cookie is an EXTERN, defined in setup */ cookie = (COOKIE*)malloc( sizeof(COOKIE)); if( !cookie ){ joe_fatal( "memory exhausted" ); } cookie->first = NULL; client = (CLIENT*)malloc(sizeof(CLIENT)); if( !client ){ joe_fatal( "application memory exhausted" ); } http_client( client ); write_queue( my.showcodes ); /** * exit program. */ exit( EXIT_SUCCESS ); } /* end of int main **/
BOOLEAN SSL_initialize(CONN *C) { #ifdef HAVE_SSL int i; int serr; C->ssl = NULL; C->ctx = NULL; C->method = NULL; C->cert = NULL; SSL_load_error_strings(); SSL_library_init(); if(!my.ssl_key && my.ssl_cert) { my.ssl_key = my.ssl_cert; } if(!my.ssl_ciphers) { my.ssl_ciphers = stralloc(SSL_DEFAULT_CIPHER_LIST); } C->method = SSLv23_client_method(); if(C->method==NULL){ SSL_error_stack(); return FALSE; } C->ctx = SSL_CTX_new(C->method); if(C->ctx==NULL){ SSL_error_stack(); return FALSE; } SSL_CTX_set_mode(C->ctx, SSL_MODE_ENABLE_PARTIAL_WRITE|SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); SSL_CTX_set_session_cache_mode(C->ctx, SSL_SESS_CACHE_BOTH); SSL_CTX_set_timeout(C->ctx, my.ssl_timeout); if(my.ssl_ciphers){ if(!SSL_CTX_set_cipher_list(C->ctx, my.ssl_ciphers)){ joe_error("SSL_CTX_set_cipher_list"); return FALSE; } } if(my.ssl_cert){ if(!SSL_CTX_use_certificate_chain_file(C->ctx, my.ssl_cert)){ SSL_error_stack(); /* dump the error stack */ joe_fatal("Error reading certificate file: %s", my.ssl_cert); } for(i=0; i<3; i++){ if(SSL_CTX_use_PrivateKey_file(C->ctx, my.ssl_key, SSL_FILETYPE_PEM)) break; if(i<2 && ERR_GET_REASON(ERR_peek_error())==EVP_R_BAD_DECRYPT){ SSL_error_stack(); /* dump the error stack */ log_warning("Wrong pass phrase: retrying"); continue; } } if(!SSL_CTX_check_private_key(C->ctx)){ joe_error("Private key does not match the certificate"); return FALSE; } } C->ssl = SSL_new(C->ctx); if(C->ssl==NULL){ SSL_error_stack(); return FALSE; } SSL_set_fd(C->ssl, C->sock); serr = SSL_connect(C->ssl); return TRUE; #else return FALSE; #endif/*HAVE_SSL*/ }
/** * Reads filename into memory and populates * the config_t struct with the result. Uses * parse to ignore comments and empty lines. */ int read_cfg_file(LINES *l, char *filename) { /* file pointer */ FILE *file; HASH H; char *line; char *option; char *value; /* char array to hold contents */ /* make sure LINES has been initialized. */ if(!l){ printf("Structure not initialized!\n"); return -1; } if((file = fopen(filename, "r")) == NULL) { /* this is a fatal problem, but we want to enlighten the user before dying */ joe_error("unable to open file: %s", filename); display_help(); exit(EXIT_FAILURE); } line = xmalloc(BUFSIZE); H = new_hash(16); l->index = 0; memset(line, 0, sizeof(line)); while(fgets(line, BUFSIZE, file) != NULL){ int num; char *p = strchr(line, '\n'); /** * if the line is longer than our buffer, we're * just going to chuck it rather then fsck with it. */ if(p) { *p = '\0'; } else { /** * Small fix by Gargoyle - 19/07/2006 * Check to see if we are at the end of the file. If so * keep the line, otherwise throw it away! */ if((num = fgetc(file)) != EOF) { while((num = fgetc(file)) != EOF && num != '\n'); line[0]='\0'; } } parse(line); chomp(line); if(strlen(line) == 0); else if(is_variable_line(line)){ char *tmp = line; option = tmp; while(*tmp && !ISSPACE((int)*tmp) && !ISSEPARATOR(*tmp)) tmp++; *tmp++=0; while(ISSPACE((int)*tmp) || ISSEPARATOR(*tmp)) tmp++; value = tmp; while(*tmp) tmp++; *tmp++=0; hash_add(H, option, value); } else{ while(strstr(line, "$")){ line = evaluate(H, line); } l->line = (char**)realloc(l->line, sizeof(char *) * (l->index + 1)); l->line[l->index] = (char *)strdup( line ); l->index++; } memset(line, 0, sizeof(line)); } fclose(file); xfree(line); hash_destroy(H); return l->index; }