static void timer_cb(struct ev_loop *loop, struct ev_timer *w, int revents) { g_debug("%s w %p revents %i", __PRETTY_FUNCTION__, w, revents); CURLMcode rc; do { rc = curl_multi_socket_action(curl_runtime.multi, CURL_SOCKET_TIMEOUT, 0, &curl_runtime.active); } while( rc == CURLM_CALL_MULTI_PERFORM ); check_run_count(); }
/* Called by glib when our timeout expires */ static gboolean timer_cb(gpointer data) { GlobalInfo *g = (GlobalInfo *)data; CURLMcode rc; do { rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running); } while (rc == CURLM_CALL_MULTI_PERFORM); mcode_or_die("timer_cb: curl_multi_socket", rc); check_run_count(g); return FALSE; }
/* Called by libevent when our timeout expires */ static void timer_cb(EV_P_ struct ev_timer *w, int revents) { DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents); GlobalInfo *g = (GlobalInfo *)w->data; CURLMcode rc; do { rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); } while ( rc == CURLM_CALL_MULTI_PERFORM ); mcode_or_die("timer_cb: curl_multi_socket", rc); check_run_count(g); }
/* Called by glib when we get action on a multi socket */ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) { GlobalInfo *g = (GlobalInfo*) data; CURLMcode rc; int fd=g_io_channel_unix_get_fd(ch); do { rc = curl_multi_socket(g->multi, fd, &g->still_running); } while (rc == CURLM_CALL_MULTI_PERFORM); mcode_or_die("event_cb: curl_multi_socket", rc); check_run_count(g); if(g->still_running) { return TRUE; } else { MSG_OUT("last transfer done, kill timeout\n"); if (g->timer_event) { g_source_remove(g->timer_event); } return FALSE; } }
static void session_download_new(struct incident *i, char *url) { g_debug("%s incident %p", __PRETTY_FUNCTION__, i); struct session *session = session_new(); session->type = session_type_download; session->url = g_strdup(url); struct connection *con = NULL; if( incident_value_con_get(i, "con", &con) ) { session->laddr = g_strdup(con->local.ip_string); curl_easy_setopt(session->easy, CURLOPT_INTERFACE, session->laddr); connection_ref(con); } curl_easy_setopt(session->easy, CURLOPT_URL, session->url); curl_easy_setopt(session->easy, CURLOPT_WRITEFUNCTION, curl_writefunction_cb); curl_easy_setopt(session->easy, CURLOPT_WRITEDATA, session); curl_easy_setopt(session->easy, CURLOPT_DEBUGFUNCTION, curl_debugfunction_cb); curl_easy_setopt(session->easy, CURLOPT_VERBOSE, 1L); curl_easy_setopt(session->easy, CURLOPT_ERRORBUFFER, session->error); curl_easy_setopt(session->easy, CURLOPT_PRIVATE, session); curl_easy_setopt(session->easy, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(session->easy, CURLOPT_FOLLOWLOCATION, 10); curl_easy_setopt(session->easy, CURLOPT_PROGRESSFUNCTION, curl_progressfunction_cb); curl_easy_setopt(session->easy, CURLOPT_PROGRESSDATA, session); curl_easy_setopt(session->easy, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(session->easy, CURLOPT_LOW_SPEED_LIMIT, 10L); curl_easy_setopt(session->easy, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); session->action.download.file = tempfile_new(curl_runtime.download_dir, "http-"); session->action.download.ctxcon = con; g_debug("session %p file %i path %s", session, session->action.download.file->fd, session->action.download.file->path); g_debug("Adding easy %p to multi %p (%s)", session->easy, curl_runtime.multi, url); curl_multi_add_handle(curl_runtime.multi, session->easy); curl_runtime.queued++; check_run_count(); }
static void event_cb(struct ev_loop *loop, struct ev_io *w, int revents) { g_debug("%s w %p revents %i", __PRETTY_FUNCTION__, w, revents); CURLMcode rc; int action = (revents&EV_READ?CURL_POLL_IN:0)|(revents&EV_WRITE?CURL_POLL_OUT:0); do { rc = curl_multi_socket_action(curl_runtime.multi, w->fd, action, &curl_runtime.active); } while( rc == CURLM_CALL_MULTI_PERFORM ); check_run_count(); if( curl_runtime.queued <= 0 ) { g_debug("last transfer done, kill timeout"); ev_timer_stop(g_dionaea->loop, &curl_runtime.timer_event); } }
/* Called by libevent when we get action on a multi socket */ static void event_cb(EV_P_ struct ev_io *w, int revents) { DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents); GlobalInfo *g = (GlobalInfo*) w->data; CURLMcode rc; int action = (revents&EV_READ?CURL_POLL_IN:0)| (revents&EV_WRITE?CURL_POLL_OUT:0); do { rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running); } while ( rc == CURLM_CALL_MULTI_PERFORM ); mcode_or_die("event_cb: curl_multi_socket", rc); check_run_count(g); if ( g->still_running <= 0 ) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); ev_timer_stop(g->loop, &g->timer_event); } }
/* Create a new easy handle, and add it to the global curl_multi */ static void new_conn(char *url, GlobalInfo *g ) { ConnInfo *conn; CURLMcode rc; conn = g_malloc0(sizeof(ConnInfo)); conn->error[0]='\0'; conn->easy = curl_easy_init(); if (!conn->easy) { MSG_OUT("curl_easy_init() failed, exiting!\n"); exit(2); } conn->global = g; conn->url = g_strdup(url); curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url); curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb); curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, &conn); curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, (long)SHOW_VERBOSE); curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, SHOW_PROGRESS?0L:1L); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); curl_easy_setopt(conn->easy, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(conn->easy, CURLOPT_CONNECTTIMEOUT, 30L); curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 1L); curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 30L); MSG_OUT("Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); rc =curl_multi_add_handle(g->multi, conn->easy); mcode_or_die("new_conn: curl_multi_add_handle", rc); g->requested++; do { rc = curl_multi_socket_all(g->multi, &g->still_running); } while (CURLM_CALL_MULTI_PERFORM == rc); mcode_or_die("new_conn: curl_multi_socket_all", rc); check_run_count(g); }
/* Create a new easy handle, and add it to the global curl_multi */ static void new_conn(char *url, GlobalInfo *g ) { ConnInfo *conn; CURLMcode rc; conn = calloc(1, sizeof(ConnInfo)); memset(conn, 0, sizeof(ConnInfo)); conn->error[0]='\0'; conn->easy = curl_easy_init(); if ( !conn->easy ) { fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n"); exit(2); } conn->global = g; conn->url = strdup(url); curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url); curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb); curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, &conn); curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, 1L); curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 10L); fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); rc =curl_multi_add_handle(g->multi, conn->easy); mcode_or_die("new_conn: curl_multi_add_handle", rc); mcode_or_die("new_conn: curl_multi_socket_all", rc); check_run_count(g); }
void session_upload_new(struct incident *i) { GHashTableIter iter; gpointer key, value; GString *gstemp; struct session *session = NULL; char *url = NULL; if (incident_value_string_get(i, "_url", &gstemp) == false ) { g_debug("dionaea.upload.request got no _url in incident!"); return; } session = session_new(); session->type = session_type_upload; url = gstemp->str; session->url = g_strdup(url); g_hash_table_iter_init (&iter, i->data); while( g_hash_table_iter_next (&iter, &key, &value) ) { char *name = key; struct opaque_data *d = value; char name_and_param[1024]; if( d->type == opaque_type_int ) { g_warning("incident key %s has integer value. all post fields must be string values.", name); } else if( d->type == opaque_type_string) { /* ignore help field values */ if( strstr(name, "_ct") != NULL || strcmp(name, "_url") == 0) continue; if( strcmp(name, "_callback") == 0 ) { /* incident callback */ session->action.upload.callback = g_strdup(d->opaque.string->str); session->action.upload.file = tempfile_new(curl_runtime.download_dir, "httpupload-"); }else if( strcmp(name, "_userdata") == 0 ) { /* incident callback userdata */ session->action.upload.userdata = g_strdup(d->opaque.string->str); }else if( strcmp(name, "user") == 0 ) { /* http auth user */ session->action.upload.username = g_strdup(d->opaque.string->str); curl_easy_setopt(session->easy, CURLOPT_USERNAME, session->action.upload.username); }else if( strcmp(name, "pass") == 0 ) { /* http auth password */ session->action.upload.password = g_strdup(d->opaque.string->str); curl_easy_setopt(session->easy, CURLOPT_PASSWORD, session->action.upload.password); }else if( strncmp(name, "file://", 7) == 0 ) { /* we upload this file */ curl_formadd(&session->action.upload.formpost, &session->action.upload.last, CURLFORM_COPYNAME, name + 7, CURLFORM_FILE, d->opaque.string->str, CURLFORM_END); }else { /* all other values */ snprintf(name_and_param, 1024, "%s_ct", name); if ( incident_value_string_get(i, name_and_param, &gstemp) == true) { /* with content type */ curl_formadd(&session->action.upload.formpost, &session->action.upload.last, CURLFORM_COPYNAME, name, CURLFORM_CONTENTTYPE, gstemp->str, CURLFORM_COPYCONTENTS, d->opaque.string->str, CURLFORM_END); } else { /* without content type */ curl_formadd(&session->action.upload.formpost, &session->action.upload.last, CURLFORM_COPYNAME, name, CURLFORM_COPYCONTENTS, d->opaque.string->str, CURLFORM_END); } } } } char buf[] = "Expect:"; session->action.upload.headers = curl_slist_append(session->action.upload.headers, buf); curl_easy_setopt(session->easy, CURLOPT_URL, session->url); curl_easy_setopt(session->easy, CURLOPT_HTTPPOST, session->action.upload.formpost); curl_easy_setopt(session->easy, CURLOPT_HTTPHEADER, session->action.upload.headers); curl_easy_setopt(session->easy, CURLOPT_WRITEFUNCTION, curl_writefunction_cb); curl_easy_setopt(session->easy, CURLOPT_WRITEDATA, session); curl_easy_setopt(session->easy, CURLOPT_DEBUGFUNCTION, curl_debugfunction_cb); // curl_easy_setopt(session->easy, CURLOPT_VERBOSE, 1L); curl_easy_setopt(session->easy, CURLOPT_ERRORBUFFER, session->error); curl_easy_setopt(session->easy, CURLOPT_PRIVATE, session); curl_easy_setopt(session->easy, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(session->easy, CURLOPT_PROGRESSFUNCTION, curl_progressfunction_cb); curl_easy_setopt(session->easy, CURLOPT_PROGRESSDATA, session); curl_easy_setopt(session->easy, CURLOPT_LOW_SPEED_TIME, 3L); curl_easy_setopt(session->easy, CURLOPT_LOW_SPEED_LIMIT, 10L); curl_easy_setopt(session->easy, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); curl_easy_setopt(session->easy, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(session->easy, CURLOPT_SSL_VERIFYHOST, 0); g_debug("Adding easy %p to multi %p (%s)", session->easy, curl_runtime.multi, url); curl_multi_add_handle(curl_runtime.multi, session->easy); curl_runtime.queued++; check_run_count(); }