struct post_state *ureport_attach_rhbz(const char *bthash, int rhbz_bug_id, struct ureport_server_config *config) { int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG; if (config->ur_ssl_verify) flags |= POST_WANT_SSL_VERIFY; struct post_state *post_state = new_post_state(flags); static const char *headers[] = { "Accept: application/json", "Connection: close", NULL, }; char *str_bug_id = xasprintf("%d", rhbz_bug_id); char *json_attachment = new_json_attachment(bthash, "RHBZ", str_bug_id); post_string_as_form_data(post_state, config->ur_url, "application/json", headers, json_attachment); free(str_bug_id); free(json_attachment); return post_state; }
static GHashTable *bodhi_query_list(const char *query, const char *release) { char *bodhi_url_bugs = xasprintf("%s/?%s", bodhi_url, query); post_state_t *post_state = new_post_state(POST_WANT_BODY | POST_WANT_SSL_VERIFY | POST_WANT_ERROR_MSG); const char *headers[] = { "Accept: application/json", NULL }; get(post_state, bodhi_url_bugs, "application/x-www-form-urlencoded", headers); if (post_state->http_resp_code != 200 && post_state->http_resp_code != 400) { char *errmsg = post_state->curl_error_msg; if (errmsg && errmsg[0]) error_msg_and_die("%s '%s'", errmsg, bodhi_url_bugs); } free(bodhi_url_bugs); // log_warning("%s", post_state->body); json_object *json = json_tokener_parse(post_state->body); if (is_error(json)) error_msg_and_die("fatal: unable parse response from bodhi server"); /* we must check the http_resp_code because only error responses contain * 'status' item. 'bodhi_read_value' function prints an error message in * the case it did not found the item */ if (post_state->http_resp_code != 200) { char *status_item = NULL; bodhi_read_value(json, "status", &status_item, BODHI_READ_STR); if (status_item != NULL && strcmp(status_item, "error") == 0) { free(status_item); bodhi_print_errors_from_json(json); json_object_put(json); xfunc_die(); // error_msg are printed in bodhi_print_errors_from_json } } GHashTable *bodhi_table = bodhi_parse_json(json, release); json_object_put(json); free_post_state(post_state); return bodhi_table; }
static int interactive_upload_file(const char *url, const char *file_name, map_string_t *settings, char **remote_name) { post_state_t *state = new_post_state(POST_WANT_ERROR_MSG); state->username = get_map_string_item_or_NULL(settings, "UploadUsername"); char *password_inp = NULL; if (state->username != NULL && state->username[0] != '\0') { /* Load Password only if Username is configured, it doesn't make */ /* much sense to load Password without Username. */ state->password = get_map_string_item_or_NULL(settings, "UploadPassword"); if (state->password == NULL) { /* Be permissive and nice, ask only once and don't check */ /* the result. User can dismiss this prompt but the upload */ /* may work somehow??? */ char *msg = xasprintf(_("Please enter password for uploading:"), state->username); state->password = password_inp = ask_password(msg); free(msg); } } /* set SSH keys */ state->client_ssh_public_keyfile = get_map_string_item_or_NULL(settings, "SSHPublicKey"); state->client_ssh_private_keyfile = get_map_string_item_or_NULL(settings, "SSHPrivateKey"); if (state->client_ssh_public_keyfile != NULL) log_debug("Using SSH public key '%s'", state->client_ssh_public_keyfile); if (state->client_ssh_private_keyfile != NULL) log_debug("Using SSH private key '%s'", state->client_ssh_private_keyfile); char *tmp = upload_file_ext(state, url, file_name, UPLOAD_FILE_HANDLE_ACCESS_DENIALS); if (remote_name) *remote_name = tmp; else free(tmp); free(password_inp); free_post_state(state); /* return 0 on success */ return tmp == NULL; }
struct post_state *post_ureport(const char *json_ureport, struct ureport_server_config *config) { int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG; if (config->ur_ssl_verify) flags |= POST_WANT_SSL_VERIFY; struct post_state *post_state = new_post_state(flags); static const char *headers[] = { "Accept: application/json", "Connection: close", NULL, }; post_string_as_form_data(post_state, config->ur_url, "application/json", headers, json_ureport); return post_state; }
static GHashTable *bodhi_query_list(const char *query, const char *release) { char *bodhi_url_bugs = xasprintf("%s/list", bodhi_url); post_state_t *post_state = new_post_state(POST_WANT_BODY | POST_WANT_SSL_VERIFY | POST_WANT_ERROR_MSG); const char *headers[] = { "Accept: application/json", NULL }; post_string(post_state, bodhi_url_bugs, "application/x-www-form-urlencoded", headers, query); if (post_state->http_resp_code != 200) { char *errmsg = post_state->curl_error_msg; if (errmsg && errmsg[0]) error_msg_and_die("%s '%s'", errmsg, bodhi_url_bugs); } free(bodhi_url_bugs); // log("%s", post_state->body); json_object *json = json_tokener_parse(post_state->body); if (is_error(json)) error_msg_and_die("fatal: unable parse response from bodhi server"); GHashTable *bodhi_table = bodhi_parse_json(json, release); json_object_put(json); free_post_state(post_state); return bodhi_table; }
static int create_and_upload_archive( const char *dump_dir_name, map_string_t *settings) { int result = 1; /* error */ pid_t child; TAR* tar = NULL; const char* errmsg = NULL; char* tempfile = NULL; struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) xfunc_die(); /* error msg is already logged by dd_opendir */ /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */ log(_("Compressing data")); //TODO: //Encrypt = yes //ArchiveType = .tar.bz2 //ExcludeFiles = foo,bar*,b*z const char* opt = getenv("Upload_URL"); if (!opt) opt = get_map_string_item_or_empty(settings, "URL"); char *url = opt[0] != '\0' ? xstrdup(opt) : ask_url(_("Please enter a URL (scp, ftp, etc.) where the problem data is to be exported:")); /* Create a child gzip which will compress the data */ /* SELinux guys are not happy with /tmp, using /var/run/abrt */ /* Reverted back to /tmp for ABRT2 */ /* Changed again to /var/tmp because of Fedora feature tmp-on-tmpfs */ tempfile = concat_path_basename(LARGE_DATA_TMP_DIR, dump_dir_name); tempfile = append_to_malloced_string(tempfile, ".tar.gz"); int pipe_from_parent_to_child[2]; xpipe(pipe_from_parent_to_child); child = vfork(); if (child == 0) { /* child */ close(pipe_from_parent_to_child[1]); xmove_fd(pipe_from_parent_to_child[0], 0); xmove_fd(xopen3(tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600), 1); execlp("gzip", "gzip", NULL); perror_msg_and_die("Can't execute '%s'", "gzip"); } close(pipe_from_parent_to_child[0]); /* If child died (say, in xopen), then parent might get SIGPIPE. * We want to properly unlock dd, therefore we must not die on SIGPIPE: */ signal(SIGPIPE, SIG_IGN); /* Create tar writer object */ if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile, /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0) { errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR; goto ret; } /* Write data to the tarball */ { string_vector_ptr_t exclude_from_report = get_global_always_excluded_elements(); dd_init_next_file(dd); char *short_name, *full_name; while (dd_get_next_file(dd, &short_name, &full_name)) { if (exclude_from_report && is_in_string_list(short_name, (const_string_vector_const_ptr_t)exclude_from_report)) goto next; // dd_get_next_file guarantees that it's a REG: //struct stat stbuf; //if (stat(full_name, &stbuf) != 0) // || !S_ISREG(stbuf.st_mode) //) { // goto next; //} if (tar_append_file(tar, full_name, short_name) != 0) { errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR; free(short_name); free(full_name); goto ret; } next: free(short_name); free(full_name); } } dd_close(dd); dd = NULL; /* Close tar writer... */ if (tar_append_eof(tar) != 0 || tar_close(tar) != 0) { errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR; goto ret; } tar = NULL; /* ...and check that gzip child finished successfully */ int status; safe_waitpid(child, &status, 0); child = -1; if (status != 0) { /* We assume the error was out-of-disk-space or out-of-quota */ errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR; goto ret; } /* Upload the tarball */ /* Upload from /tmp to /tmp + deletion -> BAD, exclude this possibility */ if (url && url[0] && strcmp(url, "file://"LARGE_DATA_TMP_DIR"/") != 0) { post_state_t *state = new_post_state(POST_WANT_ERROR_MSG); state->username = getenv("Upload_Username"); char *password_inp = NULL; if (state->username != NULL && state->username[0] != '\0') { /* Load Password only if Username is configured, it doesn't make */ /* much sense to load Password without Username. */ state->password = getenv("Upload_Password"); if (state->password == NULL) { /* Be permissive and nice, ask only once and don't check */ /* the result. User can dismiss this prompt but the upload */ /* may work somehow??? */ char *msg = xasprintf(_("Please enter password for uploading:"), state->username); state->password = password_inp = ask_password(msg); free(msg); } } char *remote_name = upload_file_ext(state, url, tempfile, UPLOAD_FILE_HANDLE_ACCESS_DENIALS); result = (remote_name == NULL); /* error if NULL */ free(remote_name); free(password_inp); free_post_state(state); /* cleanup code will delete tempfile */ } else { result = 0; /* success */ log(_("Archive is created: '%s'"), tempfile); free(tempfile); tempfile = NULL; } ret: free(url); dd_close(dd); if (tar) tar_close(tar); /* close(pipe_from_parent_to_child[1]); - tar_close() does it itself */ if (child > 0) safe_waitpid(child, NULL, 0); if (tempfile) { unlink(tempfile); free(tempfile); } if (errmsg) error_msg_and_die("%s", errmsg); return result; }
const char *clean_url = strrchr(url, '@'); if (clean_url) clean_url++; else clean_url = url; log(_("Sending %s to %s"), filename, clean_url); char *whole_url; unsigned len = strlen(url); if (len > 0 && url[len-1] == '/') whole_url = concat_path_file(url, strrchr(filename, '/') ? : filename); else whole_url = xstrdup(url); post_state_t *state = new_post_state(POST_WANT_ERROR_MSG); post(state, whole_url, /*content_type:*/ "application/octet-stream", /*additional_headers:*/ NULL, /*data:*/ filename, POST_DATA_FROMFILE_PUT ); int error = (state->curl_result != 0); if (error) { if (state->curl_error_msg) error_msg("Error while uploading: '%s'", state->curl_error_msg); else /* for example, when source file can't be opened */