// ALWAYS generates an HTML reply // int handle_file_upload(FILE* in, R_RSA_PUBLIC_KEY& key) { char buf[256], path[MAXPATHLEN], signed_xml[1024]; char name[256], stemp[256]; double max_nbytes=-1; char xml_signature[1024]; int retval; double offset=0, nbytes = -1; bool is_valid, btemp; strcpy(name, ""); strcpy(xml_signature, ""); bool found_data = false; while (fgets(buf, 256, in)) { #if 1 log_messages.printf(MSG_NORMAL, "got:%s\n", buf); #endif if (match_tag(buf, "<file_info>")) continue; if (match_tag(buf, "</file_info>")) continue; if (match_tag(buf, "<signed_xml>")) continue; if (match_tag(buf, "</signed_xml>")) continue; if (parse_bool(buf, "generated_locally", btemp)) continue; if (parse_bool(buf, "upload_when_present", btemp)) continue; if (parse_str(buf, "<url>", stemp, sizeof(stemp))) continue; if (parse_str(buf, "<md5_cksum>", stemp, sizeof(stemp))) continue; if (match_tag(buf, "<xml_signature>")) { copy_element_contents( in, "</xml_signature>", xml_signature, sizeof(xml_signature) ); continue; } if (parse_str(buf, "<name>", name, sizeof(name))) { strcpy(this_filename, name); continue; } if (parse_double(buf, "<max_nbytes>", max_nbytes)) continue; if (parse_double(buf, "<offset>", offset)) continue; if (parse_double(buf, "<nbytes>", nbytes)) continue; if (match_tag(buf, "<data>")) { found_data = true; break; } log_messages.printf(MSG_CRITICAL, "unrecognized: %s", buf); } if (strlen(name) == 0) { return return_error(ERR_PERMANENT, "Missing name"); } if (!found_data) { return return_error(ERR_PERMANENT, "Missing <data> tag"); } if (!config.ignore_upload_certificates) { if (strlen(xml_signature) == 0) { return return_error(ERR_PERMANENT, "missing signature"); } if (max_nbytes < 0) { return return_error(ERR_PERMANENT, "missing max_nbytes"); } sprintf(signed_xml, "<name>%s</name><max_nbytes>%.0f</max_nbytes>", name, max_nbytes ); retval = check_string_signature( signed_xml, xml_signature, key, is_valid ); if (retval || !is_valid) { log_messages.printf(MSG_CRITICAL, "check_string_signature() [%s] [%s] retval %d, is_valid = %d\n", signed_xml, xml_signature, retval, is_valid ); log_messages.printf(MSG_NORMAL, "signed xml: %s\n", signed_xml ); log_messages.printf(MSG_NORMAL, "signature: %s\n", xml_signature ); return return_error(ERR_PERMANENT, "invalid signature"); } } if (nbytes < 0) { return return_error(ERR_PERMANENT, "nbytes missing or negative"); } // enforce limits in signed XML // if (!config.ignore_upload_certificates) { if (nbytes > max_nbytes) { sprintf(buf, "file size (%d KB) exceeds limit (%d KB)", (int)(nbytes/1024), (int)(max_nbytes/1024) ); copy_socket_to_null(in); return return_error(ERR_PERMANENT, buf); } } // make sure filename is legit // if (strstr(name, "..")) { return return_error(ERR_PERMANENT, "file_upload_handler: .. found in filename: %s", name ); } if (strlen(name) == 0) { return return_error(ERR_PERMANENT, "file_upload_handler: no filename; nbytes %f", nbytes ); } retval = dir_hier_path( name, config.upload_dir, config.uldl_dir_fanout, path, true ); if (retval) { log_messages.printf(MSG_CRITICAL, "Failed to find/create directory for file '%s' in '%s'\n", name, config.upload_dir ); return return_error(ERR_TRANSIENT, "can't open file"); } log_messages.printf(MSG_NORMAL, "Starting upload of %s from %s [offset=%.0f, nbytes=%.0f]\n", name, get_remote_addr(), offset, nbytes ); #ifndef _USING_FCGI_ fflush(stderr); #endif if (offset >= nbytes) { log_messages.printf(MSG_CRITICAL, "ERROR: offset >= nbytes!!\n" ); return return_success(0); } retval = copy_socket_to_file(in, path, offset, nbytes); log_messages.printf(MSG_NORMAL, "Ended upload of %s from %s; retval %d\n", name, get_remote_addr(), retval ); #ifndef _USING_FCGI_ fflush(stderr); #endif return retval; }
// return an error message or NULL // const char* SCHEDULER_REQUEST::parse(FILE* fin) { char buf[256]; RESULT result; int retval; strcpy(authenticator, ""); strcpy(platform.name, ""); strcpy(cross_project_id, ""); hostid = 0; core_client_major_version = 0; core_client_minor_version = 0; core_client_release = 0; rpc_seqno = 0; work_req_seconds = 0; cpu_req_secs = 0; cpu_req_instances = 0; resource_share_fraction = 1.0; rrs_fraction = 1.0; prrs_fraction = 1.0; cpu_estimated_delay = 0; strcpy(global_prefs_xml, ""); strcpy(working_global_prefs_xml, ""); strcpy(code_sign_key, ""); memset(&global_prefs, 0, sizeof(global_prefs)); memset(&host, 0, sizeof(host)); have_other_results_list = false; have_ip_results_list = false; have_time_stats_log = false; client_cap_plan_class = false; sandbox = -1; coproc_cuda = 0; coproc_ati = 0; fgets(buf, sizeof(buf), fin); if (!match_tag(buf, "<scheduler_request>")) return "no start tag"; while (fgets(buf, sizeof(buf), fin)) { // If a line is too long, ignore it. // This can happen e.g. if the client has bad global_prefs.xml // This won't be necessary if we rewrite this using XML_PARSER // if (!strchr(buf, '\n')) { while (fgets(buf, sizeof(buf), fin)) { if (strchr(buf, '\n')) break; } continue; } if (match_tag(buf, "</scheduler_request>")) { core_client_version = 10000*core_client_major_version + 100*core_client_minor_version + core_client_release; return NULL; } if (parse_str(buf, "<authenticator>", authenticator, sizeof(authenticator))) { remove_quotes(authenticator); continue; } if (parse_str(buf, "<cross_project_id>", cross_project_id, sizeof(cross_project_id))) continue; if (parse_int(buf, "<hostid>", hostid)) continue; if (parse_int(buf, "<rpc_seqno>", rpc_seqno)) continue; if (parse_str(buf, "<platform_name>", platform.name, sizeof(platform.name))) continue; if (match_tag(buf, "<alt_platform>")) { CLIENT_PLATFORM cp; retval = cp.parse(fin); if (!retval) { alt_platforms.push_back(cp); } continue; } if (match_tag(buf, "<app_versions>")) { while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "</app_versions>")) break; if (match_tag(buf, "<app_version>")) { CLIENT_APP_VERSION cav; retval = cav.parse(fin); if (retval) { g_reply->insert_message( "Invalid app version description", "high" ); } else { client_app_versions.push_back(cav); } } } continue; } if (parse_int(buf, "<core_client_major_version>", core_client_major_version)) continue; if (parse_int(buf, "<core_client_minor_version>", core_client_minor_version)) continue; if (parse_int(buf, "<core_client_release>", core_client_release)) continue; if (parse_double(buf, "<work_req_seconds>", work_req_seconds)) continue; if (parse_double(buf, "<cpu_req_secs>", cpu_req_secs)) continue; if (parse_double(buf, "<cpu_req_instances>", cpu_req_instances)) continue; if (parse_double(buf, "<resource_share_fraction>", resource_share_fraction)) continue; if (parse_double(buf, "<rrs_fraction>", rrs_fraction)) continue; if (parse_double(buf, "<prrs_fraction>", prrs_fraction)) continue; if (parse_double(buf, "<estimated_delay>", cpu_estimated_delay)) continue; if (parse_double(buf, "<duration_correction_factor>", host.duration_correction_factor)) continue; if (match_tag(buf, "<global_preferences>")) { strcpy(global_prefs_xml, "<global_preferences>\n"); while (fgets(buf, sizeof(buf), fin)) { if (strstr(buf, "</global_preferences>")) break; safe_strcat(global_prefs_xml, buf); } safe_strcat(global_prefs_xml, "</global_preferences>\n"); continue; } if (match_tag(buf, "<working_global_preferences>")) { while (fgets(buf, sizeof(buf), fin)) { if (strstr(buf, "</working_global_preferences>")) break; safe_strcat(working_global_prefs_xml, buf); } continue; } if (parse_str(buf, "<global_prefs_source_email_hash>", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue; if (match_tag(buf, "<host_info>")) { host.parse(fin); continue; } if (match_tag(buf, "<time_stats>")) { host.parse_time_stats(fin); continue; } if (match_tag(buf, "<time_stats_log>")) { handle_time_stats_log(fin); have_time_stats_log = true; continue; } if (match_tag(buf, "<net_stats>")) { host.parse_net_stats(fin); continue; } if (match_tag(buf, "<disk_usage>")) { host.parse_disk_usage(fin); continue; } if (match_tag(buf, "<result>")) { result.parse_from_client(fin); static int max_results = 200; --max_results; if (max_results >= 0) results.push_back(result); continue; } if (match_tag(buf, "<code_sign_key>")) { copy_element_contents(fin, "</code_sign_key>", code_sign_key, sizeof(code_sign_key)); continue; } if (match_tag(buf, "<msg_from_host>")) { MSG_FROM_HOST_DESC md; retval = md.parse(fin); if (!retval) { msgs_from_host.push_back(md); } continue; } if (match_tag(buf, "<file_info>")) { FILE_INFO fi; retval = fi.parse(fin); if (!retval) { file_infos.push_back(fi); } continue; } if (match_tag(buf, "<host_venue>")) { continue; } if (match_tag(buf, "<other_results>")) { have_other_results_list = true; while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "</other_results>")) break; if (match_tag(buf, "<other_result>")) { OTHER_RESULT o_r; retval = o_r.parse(fin); if (!retval) { other_results.push_back(o_r); } } } continue; } if (match_tag(buf, "<in_progress_results>")) { have_ip_results_list = true; int i = 0; double now = time(0); while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "</in_progress_results>")) break; if (match_tag(buf, "<ip_result>")) { IP_RESULT ir; retval = ir.parse(fin); if (!retval) { if (!strlen(ir.name)) { sprintf(ir.name, "ip%d", i++); } ir.report_deadline -= now; ip_results.push_back(ir); } } } continue; } if (match_tag(buf, "coprocs")) { MIOFILE mf; mf.init_file(fin); coprocs.parse(mf); coproc_cuda = (COPROC_CUDA*)coprocs.lookup("CUDA"); coproc_ati = (COPROC_ATI*)coprocs.lookup("ATI"); continue; } if (parse_bool(buf, "client_cap_plan_class", client_cap_plan_class)) continue; if (parse_int(buf, "<sandbox>", sandbox)) continue; if (match_tag(buf, "<active_task_set>")) continue; if (match_tag(buf, "<app>")) continue; if (match_tag(buf, "<app_version>")) continue; if (match_tag(buf, "<duration_variability>")) continue; if (match_tag(buf, "<new_version_check_time>")) continue; if (match_tag(buf, "<newer_version>")) continue; if (match_tag(buf, "<project>")) continue; if (match_tag(buf, "<project_files>")) continue; if (match_tag(buf, "<proxy_info>")) continue; if (match_tag(buf, "<user_network_request>")) continue; if (match_tag(buf, "<user_run_request>")) continue; if (match_tag(buf, "<master_url>")) continue; if (match_tag(buf, "<project_name>")) continue; if (match_tag(buf, "<user_name>")) continue; if (match_tag(buf, "<team_name>")) continue; if (match_tag(buf, "<email_hash>")) continue; if (match_tag(buf, "<user_total_credit>")) continue; if (match_tag(buf, "<user_expavg_credit>")) continue; if (match_tag(buf, "<user_create_time>")) continue; if (match_tag(buf, "<host_total_credit>")) continue; if (match_tag(buf, "<host_expavg_credit>")) continue; if (match_tag(buf, "<host_create_time>")) continue; if (match_tag(buf, "<nrpc_failures>")) continue; if (match_tag(buf, "<master_fetch_failures>")) continue; if (match_tag(buf, "<min_rpc_time>")) continue; if (match_tag(buf, "<short_term_debt>")) continue; if (match_tag(buf, "<long_term_debt>")) continue; if (match_tag(buf, "<resource_share>")) continue; if (match_tag(buf, "<scheduler_url>")) continue; if (match_tag(buf, "</project>")) continue; if (match_tag(buf, "<?xml")) continue; strip_whitespace(buf); if (!strlen(buf)) continue; log_messages.printf(MSG_NORMAL, "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf ); MIOFILE mf; mf.init_file(fin); retval = skip_unrecognized(buf, mf); if (retval) return "unterminated unrecognized XML"; } return "no end tag"; }
// parse project fields from client_state.xml // int PROJECT::parse_state(XML_PARSER& xp) { char buf[256]; std::string sched_url, stemp; string str1, str2; int retval, rt; double x; bool btemp; init(); while (!xp.get_tag()) { if (xp.match_tag("/project")) { if (cpid_time == 0) { cpid_time = user_create_time; } if (dont_use_dcf) { duration_correction_factor = 1; } return 0; } if (xp.parse_string("scheduler_url", sched_url)) { scheduler_urls.push_back(sched_url); continue; } if (xp.parse_str("master_url", master_url, sizeof(master_url))) continue; if (xp.parse_str("project_name", project_name, sizeof(project_name))) continue; if (xp.parse_str("symstore", symstore, sizeof(symstore))) continue; if (xp.parse_str("user_name", user_name, sizeof(user_name))) continue; if (xp.parse_str("team_name", team_name, sizeof(team_name))) continue; if (xp.parse_str("host_venue", host_venue, sizeof(host_venue))) continue; if (xp.parse_str("email_hash", email_hash, sizeof(email_hash))) continue; if (xp.parse_str("cross_project_id", cross_project_id, sizeof(cross_project_id))) continue; if (xp.parse_str("external_cpid", external_cpid, sizeof(external_cpid))) continue; if (xp.parse_double("cpid_time", cpid_time)) continue; if (xp.parse_double("user_total_credit", user_total_credit)) continue; if (xp.parse_double("user_expavg_credit", user_expavg_credit)) continue; if (xp.parse_double("user_create_time", user_create_time)) continue; if (xp.parse_int("rpc_seqno", rpc_seqno)) continue; if (xp.parse_int("userid", userid)) continue; if (xp.parse_int("teamid", teamid)) continue; if (xp.parse_int("hostid", hostid)) continue; if (xp.parse_double("host_total_credit", host_total_credit)) continue; if (xp.parse_double("host_expavg_credit", host_expavg_credit)) continue; if (xp.parse_double("host_create_time", host_create_time)) continue; if (xp.match_tag("code_sign_key")) { retval = copy_element_contents( xp.f->f, "</code_sign_key>", code_sign_key, sizeof(code_sign_key) ); if (retval) return retval; strip_whitespace(code_sign_key); continue; } if (xp.parse_int("nrpc_failures", nrpc_failures)) continue; if (xp.parse_int("master_fetch_failures", master_fetch_failures)) continue; if (xp.parse_double("min_rpc_time", x)) continue; if (xp.parse_bool("master_url_fetch_pending", master_url_fetch_pending)) continue; if (xp.parse_int("sched_rpc_pending", sched_rpc_pending)) continue; if (xp.parse_double("next_rpc_time", next_rpc_time)) continue; if (xp.parse_bool("trickle_up_pending", trickle_up_pending)) continue; if (xp.parse_int("send_time_stats_log", send_time_stats_log)) continue; if (xp.parse_int("send_job_log", send_job_log)) continue; if (xp.parse_bool("send_full_workload", send_full_workload)) continue; if (xp.parse_bool("dont_use_dcf", dont_use_dcf)) continue; if (xp.parse_bool("non_cpu_intensive", non_cpu_intensive)) continue; if (xp.parse_bool("verify_files_on_app_start", verify_files_on_app_start)) continue; if (xp.parse_bool("suspended_via_gui", suspended_via_gui)) continue; if (xp.parse_bool("dont_request_more_work", dont_request_more_work)) continue; if (xp.parse_bool("detach_when_done", detach_when_done)) continue; if (xp.parse_bool("ended", ended)) continue; if (xp.parse_double("rec", pwf.rec)) continue; if (xp.parse_double("rec_time", pwf.rec_time)) continue; if (xp.parse_double("cpu_backoff_interval", rsc_pwf[0].backoff_interval)) continue; if (xp.parse_double("cpu_backoff_time", rsc_pwf[0].backoff_time)) { if (rsc_pwf[0].backoff_time > gstate.now + 28*SECONDS_PER_DAY) { rsc_pwf[0].backoff_time = gstate.now + 28*SECONDS_PER_DAY; } continue; } if (xp.match_tag("rsc_backoff_interval")) { if (parse_rsc_param(xp, "/rsc_backoff_interval", rt, x)) { rsc_pwf[rt].backoff_interval = x; } continue; } if (xp.match_tag("rsc_backoff_time")) { if (parse_rsc_param(xp, "/rsc_backoff_time", rt, x)) { rsc_pwf[rt].backoff_time = x; } continue; } if (xp.parse_double("resource_share", resource_share)) continue; // not authoritative if (xp.parse_double("duration_correction_factor", duration_correction_factor)) continue; if (xp.parse_bool("attached_via_acct_mgr", attached_via_acct_mgr)) continue; if (xp.parse_bool("no_cpu_apps", btemp)) { if (btemp) handle_no_rsc_apps(this, "CPU"); continue; } // deprecated if (xp.parse_bool("no_cuda_apps", btemp)) { if (btemp) handle_no_rsc_apps(this, GPU_TYPE_NVIDIA); continue; } if (xp.parse_bool("no_ati_apps", btemp)) { if (btemp) handle_no_rsc_apps(this, GPU_TYPE_ATI); continue; } if (xp.parse_str("no_rsc_apps", buf, sizeof(buf))) { handle_no_rsc_apps(this, buf); continue; } if (xp.parse_bool("no_cpu_ams", btemp)) { if (btemp) handle_no_rsc_ams(this, "CPU"); continue; } if (xp.parse_bool("no_cuda_ams", btemp)) { if (btemp) handle_no_rsc_ams(this, GPU_TYPE_NVIDIA); continue; } if (xp.parse_bool("no_ati_ams", btemp)) { if (btemp) handle_no_rsc_ams(this, GPU_TYPE_ATI); continue; } if (xp.parse_bool("no_intel_gpu_ams", btemp)) { if (btemp) handle_no_rsc_ams(this, GPU_TYPE_INTEL); continue; } if (xp.parse_str("no_rsc_ams", buf, sizeof(buf))) { handle_no_rsc_ams(this, buf); continue; } if (xp.parse_str("no_rsc_pref", buf, sizeof(buf))) { handle_no_rsc_pref(this, buf); continue; } // backwards compat - old state files had ams_resource_share = 0 if (xp.parse_double("ams_resource_share_new", ams_resource_share)) continue; if (xp.parse_double("ams_resource_share", x)) { if (x > 0) ams_resource_share = x; continue; } if (xp.parse_bool("scheduler_rpc_in_progress", btemp)) continue; if (xp.parse_bool("use_symlinks", use_symlinks)) continue; if (xp.parse_bool("anonymous_platform", btemp)) continue; if (xp.parse_string("trickle_up_url", stemp)) { trickle_up_ops.push_back(new TRICKLE_UP_OP(stemp)); continue; } if (xp.parse_double("desired_disk_usage", desired_disk_usage)) continue; if (xp.parse_int("njobs_success", njobs_success)) continue; if (xp.parse_int("njobs_error", njobs_error)) continue; if (xp.parse_double("elapsed_time", elapsed_time)) continue; if (xp.parse_double("last_rpc_time", last_rpc_time)) continue; #ifdef SIM if (xp.match_tag("available")) { available.parse(xp, "/available"); continue; } #endif if (log_flags.unparsed_xml) { msg_printf(0, MSG_INFO, "[unparsed_xml] PROJECT::parse_state(): unrecognized: %s", xp.parsed_tag ); } xp.skip_unexpected(); } return ERR_XML_PARSE; }
// parse RPC reply from account manager // int ACCT_MGR_OP::parse(FILE* f) { string message; int retval; MIOFILE mf; mf.init_file(f); XML_PARSER xp(&mf); accounts.clear(); error_str = ""; error_num = 0; repeat_sec = 0; safe_strcpy(host_venue, ""); safe_strcpy(ami.opaque, ""); ami.no_project_notices = false; ami.dynamic = false; rss_feeds.clear(); if (!xp.parse_start("acct_mgr_reply")) return ERR_XML_PARSE; while (!xp.get_tag()) { if (!xp.is_tag) { if (log_flags.unparsed_xml) { msg_printf(0, MSG_INFO, "[unparsed_xml] ACCT_MGR_OP::parse: unexpected text %s", xp.parsed_tag ); } continue; } if (xp.match_tag("/acct_mgr_reply")) return 0; if (xp.parse_str("name", ami.project_name, 256)) continue; if (xp.parse_str("user_name", ami.user_name, sizeof(ami.user_name))) { xml_unescape(ami.user_name); continue; } if (xp.parse_str("team_name", ami.team_name, sizeof(ami.team_name))) { xml_unescape(ami.team_name); continue; } if (xp.parse_str("authenticator", ami.authenticator, 256)) continue; if (xp.parse_int("error_num", error_num)) continue; if (xp.parse_string("error", error_str)) continue; if (xp.parse_string("error_msg", error_str)) continue; if (xp.parse_double("repeat_sec", repeat_sec)) continue; if (xp.parse_bool("dynamic", ami.dynamic)) continue; if (xp.parse_string("message", message)) { msg_printf(NULL, MSG_INFO, "Account manager: %s", message.c_str()); continue; } if (xp.match_tag("opaque")) { retval = xp.element_contents("</opaque>", ami.opaque, sizeof(ami.opaque)); if (retval) return retval; continue; } if (xp.match_tag("signing_key")) { retval = xp.element_contents("</signing_key>", ami.signing_key, sizeof(ami.signing_key)); if (retval) return retval; continue; } if (xp.match_tag("account")) { AM_ACCOUNT account; retval = account.parse(xp); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse account in account manager reply: %s", boincerror(retval) ); } else { accounts.push_back(account); } continue; } if (xp.match_tag("global_preferences")) { retval = copy_element_contents( f, "</global_preferences>", global_prefs_xml ); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse global prefs in account manager reply: %s", boincerror(retval) ); return retval; } continue; } if (xp.parse_str("host_venue", host_venue, sizeof(host_venue))) { continue; } if (xp.match_tag("rss_feeds")) { got_rss_feeds = true; parse_rss_feed_descs(xp, rss_feeds); continue; } if (xp.parse_bool("no_project_notices", ami.no_project_notices)) { continue; } if (xp.match_tag("user_keywords")) { retval = ami.user_keywords.parse(xp); if (retval) return retval; continue; } if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, "[unparsed_xml] ACCT_MGR_OP::parse: unrecognized tag <%s>", xp.parsed_tag ); } xp.skip_unexpected(log_flags.unparsed_xml, "ACCT_MGR_OP::parse"); } return ERR_XML_PARSE; }