2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-01-30 22:19:19 +00:00
|
|
|
// The "policy" part of file transfer is here.
|
|
|
|
// The "mechanism" part is in pers_file_xfer.C and file_xfer.C
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2002-06-06 18:42:01 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2003-07-23 22:24:28 +00:00
|
|
|
#include <cassert>
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <sys/stat.h>
|
2002-06-06 18:42:01 +00:00
|
|
|
#include <sys/types.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "md5_file.h"
|
2002-07-07 20:39:24 +00:00
|
|
|
#include "crypt.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "filesys.h"
|
2008-09-04 12:50:54 +00:00
|
|
|
#include "cert_sig.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "error_numbers.h"
|
2006-01-17 22:48:09 +00:00
|
|
|
|
2012-02-06 20:41:26 +00:00
|
|
|
#include "async_file.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "file_names.h"
|
2002-06-01 20:26:21 +00:00
|
|
|
#include "client_types.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "client_state.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "file_xfer.h"
|
2012-04-30 21:00:28 +00:00
|
|
|
#include "project.h"
|
2012-02-09 01:06:15 +00:00
|
|
|
#include "sandbox.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2003-03-02 19:24:09 +00:00
|
|
|
// Decide whether to consider starting a new file transfer
|
2002-08-30 22:11:36 +00:00
|
|
|
//
|
2003-12-02 22:47:32 +00:00
|
|
|
bool CLIENT_STATE::start_new_file_xfer(PERS_FILE_XFER& pfx) {
|
|
|
|
unsigned int i;
|
2007-02-20 04:18:02 +00:00
|
|
|
int ntotal=0, nproj=0;
|
2003-12-02 22:47:32 +00:00
|
|
|
|
2005-12-24 06:32:07 +00:00
|
|
|
if (network_suspended) return false;
|
2010-04-26 19:31:28 +00:00
|
|
|
if (file_xfers_suspended) return false;
|
2003-12-02 22:47:32 +00:00
|
|
|
|
2006-10-23 21:00:36 +00:00
|
|
|
|
2003-12-02 22:47:32 +00:00
|
|
|
// limit the number of file transfers per project
|
2007-02-20 04:18:02 +00:00
|
|
|
// (uploads and downloads are limited separately)
|
2003-12-02 22:47:32 +00:00
|
|
|
//
|
|
|
|
for (i=0; i<file_xfers->file_xfers.size(); i++) {
|
|
|
|
FILE_XFER* fxp = file_xfers->file_xfers[i];
|
2007-02-20 04:18:02 +00:00
|
|
|
if (pfx.is_upload == fxp->is_upload) {
|
|
|
|
ntotal++;
|
|
|
|
if (pfx.fip->project == fxp->fip->project) {
|
|
|
|
nproj++;
|
|
|
|
}
|
2003-12-02 22:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-08 07:51:18 +00:00
|
|
|
if (nproj >= cc_config.max_file_xfers_per_project) return false;
|
|
|
|
if (ntotal >= cc_config.max_file_xfers) return false;
|
2003-12-02 22:47:32 +00:00
|
|
|
return true;
|
2002-08-30 22:11:36 +00:00
|
|
|
}
|
|
|
|
|
2003-03-02 19:24:09 +00:00
|
|
|
// Make a directory for each of the projects in the client state
|
2002-08-22 21:29:58 +00:00
|
|
|
//
|
|
|
|
int CLIENT_STATE::make_project_dirs() {
|
|
|
|
unsigned int i;
|
2003-03-08 23:48:05 +00:00
|
|
|
int retval;
|
2002-08-22 21:29:58 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = make_project_dir(*projects[i]);
|
|
|
|
if (retval) return retval;
|
2002-08-22 21:29:58 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-04 12:17:58 +00:00
|
|
|
// Is app signed by one of the Application Certifiers?
|
|
|
|
//
|
|
|
|
bool FILE_INFO::verify_file_certs() {
|
2012-09-02 20:05:20 +00:00
|
|
|
char file[MAXPATHLEN];
|
2008-09-04 12:17:58 +00:00
|
|
|
bool retval = false;
|
|
|
|
|
|
|
|
if (!is_dir(CERTIFICATE_DIRECTORY)) return false;
|
|
|
|
DIRREF dir = dir_open(CERTIFICATE_DIRECTORY);
|
2012-09-02 20:05:20 +00:00
|
|
|
while (!dir_scan(file, dir, sizeof(file))) {
|
2008-09-04 12:50:54 +00:00
|
|
|
if (cert_verify_file(cert_sigs, file, CERTIFICATE_DIRECTORY)) {
|
2008-09-04 12:17:58 +00:00
|
|
|
msg_printf(project, MSG_INFO,
|
2008-09-04 12:50:54 +00:00
|
|
|
"Signature verified using certificate %s", file
|
2008-09-04 12:17:58 +00:00
|
|
|
);
|
|
|
|
retval = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dir_close(dir);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-02-09 00:47:04 +00:00
|
|
|
#ifndef SIM
|
2012-02-06 20:41:26 +00:00
|
|
|
// Check the existence and/or validity of a file.
|
|
|
|
// Return 0 if it exists and is valid.
|
|
|
|
//
|
2012-02-08 19:30:57 +00:00
|
|
|
// verify_contents
|
|
|
|
// if true, validate the contents of the file based either on =
|
|
|
|
// the digital signature of the file or its MD5 checksum.
|
|
|
|
// Otherwise just check its existence and size.
|
|
|
|
// show_errors
|
|
|
|
// write log msg on failure
|
|
|
|
// allow_async
|
|
|
|
// whether the operation can be done asynchronously.
|
|
|
|
// If this is true, and verify_contents is set
|
|
|
|
// (i.e. we have to read the file)
|
|
|
|
// and the file size is above a threshold,
|
|
|
|
// then we do the operation asynchronously.
|
|
|
|
// In this case the file status is set to FILE_VERIFY_PENDING
|
|
|
|
// and we return ERR_IN_PROGRESS.
|
|
|
|
// When the asynchronous op is complete,
|
|
|
|
// the status is set to FILE_PRESENT.
|
2006-06-20 17:36:28 +00:00
|
|
|
//
|
2005-04-12 22:53:35 +00:00
|
|
|
// This is called
|
2012-02-08 19:30:57 +00:00
|
|
|
// 1) right after a download is finished
|
2013-04-03 00:23:37 +00:00
|
|
|
// (CLIENT_STATE::create_and_delete_pers_file_xfers() in cs_files.cpp)
|
|
|
|
// precondition: status is FILE_NOT_PRESENT
|
|
|
|
// verify_contents: true
|
2012-02-08 19:30:57 +00:00
|
|
|
// show_errors: true
|
|
|
|
// allow_async: true
|
2012-02-06 20:41:26 +00:00
|
|
|
// 2) to see if a file marked as NOT_PRESENT is actually on disk
|
2013-04-03 00:23:37 +00:00
|
|
|
// (PERS_FILE_XFER::create_xfer() in pers_file_xfer.cpp)
|
|
|
|
// precondition: status is FILE_NOT_PRESENT
|
|
|
|
// verify_contents: true
|
2012-02-08 19:30:57 +00:00
|
|
|
// show_errors: false
|
|
|
|
// allow_async: true
|
2012-02-06 20:41:26 +00:00
|
|
|
// 3) when checking whether a result's input files are available
|
2013-04-03 00:23:37 +00:00
|
|
|
// (CLIENT_STATE::input_files_available( in cs_apps.cpp)).
|
|
|
|
// precondition: status is FILE_PRESENT
|
|
|
|
// verify_contents: either true or false
|
2012-02-08 19:30:57 +00:00
|
|
|
// show_errors: true
|
|
|
|
// allow_async: false
|
2005-06-07 23:12:47 +00:00
|
|
|
//
|
2012-02-08 19:30:57 +00:00
|
|
|
// If a failure occurs, set the file's "status" field to an error number.
|
2012-02-06 20:41:26 +00:00
|
|
|
// This will cause the app_version or workunit that used the file to error out
|
|
|
|
// (via APP_VERSION::had_download_failure() or WORKUNIT::had_download_failure())
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2012-02-08 19:30:57 +00:00
|
|
|
int FILE_INFO::verify_file(
|
|
|
|
bool verify_contents, bool show_errors, bool allow_async
|
|
|
|
) {
|
2012-09-02 20:05:20 +00:00
|
|
|
char cksum[64], pathname[MAXPATHLEN];
|
2002-07-07 20:39:24 +00:00
|
|
|
bool verified;
|
|
|
|
int retval;
|
2006-07-25 21:21:50 +00:00
|
|
|
double size, local_nbytes;
|
2002-07-07 20:39:24 +00:00
|
|
|
|
2012-02-09 00:47:04 +00:00
|
|
|
if (log_flags.async_file_debug) {
|
|
|
|
msg_printf(project, MSG_INFO, "[async] verify file (%s): %s",
|
|
|
|
verify_contents?"strict":"not strict", name
|
|
|
|
);
|
|
|
|
}
|
2012-02-06 21:13:04 +00:00
|
|
|
|
2013-04-03 00:23:37 +00:00
|
|
|
if (status == FILE_VERIFY_PENDING) return ERR_IN_PROGRESS;
|
2012-02-06 20:41:26 +00:00
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_pathname(this, pathname, sizeof(pathname));
|
2005-06-07 23:12:47 +00:00
|
|
|
|
2012-01-26 23:13:00 +00:00
|
|
|
strcpy(cksum, "");
|
|
|
|
|
2012-01-24 20:41:22 +00:00
|
|
|
// see if we need to unzip it
|
|
|
|
//
|
|
|
|
if (download_gzipped && !boinc_file_exists(pathname)) {
|
2012-05-09 16:11:50 +00:00
|
|
|
char gzpath[MAXPATHLEN];
|
- client: add a mechanism for restartable download of compressed files.
(It turns out that the compression schemes supported by
Apache and libcurl, suprisingly, aren't restartable.)
if a <file_info> from the server contains <gzipped_url> tags,
use those instead of the <url> tags,
and flag the file as "download_gzipped".
If this is the case, download NAME.gz and save it as NAME.gzt.
When the download is complete, rename NAME.gzt to NAME.gz,
and uncompress it to NAME.
(this ensures that if NAME.gz is present, it's complete).
Also do the uncompression, if needed, in verify_file().
This ensures that the uncompression will eventually get done
even if the client quits are crashes in the middle.
- update_versions: if <gzip> is present in a <file_info>,
add a gzipped copy in the download directory
and add a <gzipped_url> elements to the app version's xml_doc.
svn path=/trunk/boinc/; revision=25112
2012-01-20 23:34:15 +00:00
|
|
|
sprintf(gzpath, "%s.gz", pathname);
|
2012-01-24 20:41:22 +00:00
|
|
|
if (boinc_file_exists(gzpath) ) {
|
2013-04-03 00:23:37 +00:00
|
|
|
if (allow_async && nbytes > ASYNC_FILE_THRESHOLD) {
|
|
|
|
ASYNC_VERIFY* avp = new ASYNC_VERIFY;
|
|
|
|
retval = avp->init(this);
|
2012-02-06 23:33:23 +00:00
|
|
|
if (retval) {
|
|
|
|
status = retval;
|
|
|
|
return retval;
|
|
|
|
}
|
2013-04-03 00:23:37 +00:00
|
|
|
status = FILE_VERIFY_PENDING;
|
|
|
|
return ERR_IN_PROGRESS;
|
|
|
|
}
|
2012-01-26 23:13:00 +00:00
|
|
|
retval = gunzip(cksum);
|
- client: add a mechanism for restartable download of compressed files.
(It turns out that the compression schemes supported by
Apache and libcurl, suprisingly, aren't restartable.)
if a <file_info> from the server contains <gzipped_url> tags,
use those instead of the <url> tags,
and flag the file as "download_gzipped".
If this is the case, download NAME.gz and save it as NAME.gzt.
When the download is complete, rename NAME.gzt to NAME.gz,
and uncompress it to NAME.
(this ensures that if NAME.gz is present, it's complete).
Also do the uncompression, if needed, in verify_file().
This ensures that the uncompression will eventually get done
even if the client quits are crashes in the middle.
- update_versions: if <gzip> is present in a <file_info>,
add a gzipped copy in the download directory
and add a <gzipped_url> elements to the app version's xml_doc.
svn path=/trunk/boinc/; revision=25112
2012-01-20 23:34:15 +00:00
|
|
|
if (retval) return retval;
|
2012-01-24 20:41:22 +00:00
|
|
|
} else {
|
|
|
|
strcat(gzpath, "t");
|
|
|
|
if (!boinc_file_exists(gzpath)) {
|
|
|
|
status = FILE_NOT_PRESENT;
|
|
|
|
}
|
|
|
|
return ERR_FILE_MISSING;
|
- client: add a mechanism for restartable download of compressed files.
(It turns out that the compression schemes supported by
Apache and libcurl, suprisingly, aren't restartable.)
if a <file_info> from the server contains <gzipped_url> tags,
use those instead of the <url> tags,
and flag the file as "download_gzipped".
If this is the case, download NAME.gz and save it as NAME.gzt.
When the download is complete, rename NAME.gzt to NAME.gz,
and uncompress it to NAME.
(this ensures that if NAME.gz is present, it's complete).
Also do the uncompression, if needed, in verify_file().
This ensures that the uncompression will eventually get done
even if the client quits are crashes in the middle.
- update_versions: if <gzip> is present in a <file_info>,
add a gzipped copy in the download directory
and add a <gzipped_url> elements to the app version's xml_doc.
svn path=/trunk/boinc/; revision=25112
2012-01-20 23:34:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-07 23:12:47 +00:00
|
|
|
// If the file isn't there at all, set status to FILE_NOT_PRESENT;
|
|
|
|
// this will trigger a new download rather than erroring out
|
|
|
|
//
|
2005-04-12 21:54:40 +00:00
|
|
|
if (file_size(pathname, size)) {
|
2005-04-12 22:53:35 +00:00
|
|
|
status = FILE_NOT_PRESENT;
|
2005-04-12 21:54:40 +00:00
|
|
|
return ERR_FILE_MISSING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gstate.global_prefs.dont_verify_images
|
|
|
|
&& is_image_file(name)
|
|
|
|
&& size>0
|
|
|
|
) {
|
2005-04-06 19:41:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 21:54:40 +00:00
|
|
|
|
2014-05-08 07:51:18 +00:00
|
|
|
if (nbytes && (nbytes != size) && (!cc_config.dont_check_file_sizes)) {
|
2009-09-18 20:49:54 +00:00
|
|
|
if (show_errors) {
|
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
|
|
|
"File %s has wrong size: expected %.0f, got %.0f",
|
|
|
|
name, nbytes, size
|
|
|
|
);
|
|
|
|
}
|
2005-06-07 23:12:47 +00:00
|
|
|
status = ERR_WRONG_SIZE;
|
2005-04-12 21:54:40 +00:00
|
|
|
return ERR_WRONG_SIZE;
|
|
|
|
}
|
2005-04-12 22:53:35 +00:00
|
|
|
|
2012-02-06 20:41:26 +00:00
|
|
|
if (!verify_contents) return 0;
|
2005-04-12 22:53:35 +00:00
|
|
|
|
2004-09-02 16:23:21 +00:00
|
|
|
if (signature_required) {
|
2008-09-04 12:50:54 +00:00
|
|
|
if (!strlen(file_signature) && !cert_sigs) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Application file %s missing signature", name
|
|
|
|
);
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"BOINC cannot accept this file"
|
|
|
|
);
|
2004-09-02 16:23:21 +00:00
|
|
|
error_msg = "missing signature";
|
2005-06-07 23:12:47 +00:00
|
|
|
status = ERR_NO_SIGNATURE;
|
2002-08-30 20:56:02 +00:00
|
|
|
return ERR_NO_SIGNATURE;
|
|
|
|
}
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.use_certs || cc_config.use_certs_only) {
|
2008-09-04 12:17:58 +00:00
|
|
|
if (verify_file_certs()) {
|
|
|
|
verified = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.use_certs_only) {
|
2008-09-04 12:17:58 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
|
|
|
"Unable to verify %s using certificates", name
|
|
|
|
);
|
|
|
|
return ERR_NO_SIGNATURE;
|
|
|
|
}
|
2013-04-03 00:23:37 +00:00
|
|
|
if (allow_async && nbytes > ASYNC_FILE_THRESHOLD) {
|
|
|
|
ASYNC_VERIFY* avp = new ASYNC_VERIFY();
|
|
|
|
retval = avp->init(this);
|
2012-02-06 23:33:23 +00:00
|
|
|
if (retval) {
|
|
|
|
status = retval;
|
|
|
|
return retval;
|
|
|
|
}
|
2013-04-03 00:23:37 +00:00
|
|
|
status = FILE_VERIFY_PENDING;
|
|
|
|
return ERR_IN_PROGRESS;
|
|
|
|
}
|
2012-02-06 22:57:36 +00:00
|
|
|
if (!strlen(cksum)) {
|
|
|
|
double file_length;
|
|
|
|
retval = md5_file(pathname, cksum, file_length);
|
|
|
|
if (retval) {
|
|
|
|
status = retval;
|
|
|
|
msg_printf(project, MSG_INFO,
|
|
|
|
"md5_file failed for %s: %s",
|
|
|
|
pathname, boincerror(retval)
|
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 06:06:44 +00:00
|
|
|
retval = check_file_signature2(
|
2012-02-06 22:57:36 +00:00
|
|
|
cksum, file_signature, project->code_sign_key, verified
|
2002-07-07 20:39:24 +00:00
|
|
|
);
|
2002-08-15 21:52:04 +00:00
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Signature verification error for %s",
|
2004-09-02 16:23:21 +00:00
|
|
|
name
|
2003-10-13 00:41:02 +00:00
|
|
|
);
|
2004-09-02 16:23:21 +00:00
|
|
|
error_msg = "signature verification error";
|
2005-06-07 23:12:47 +00:00
|
|
|
status = ERR_RSA_FAILED;
|
2002-08-15 21:52:04 +00:00
|
|
|
return ERR_RSA_FAILED;
|
2002-07-11 01:09:53 +00:00
|
|
|
}
|
2007-01-19 20:56:49 +00:00
|
|
|
if (!verified && show_errors) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Signature verification failed for %s",
|
2004-09-02 16:23:21 +00:00
|
|
|
name
|
2003-10-13 00:41:02 +00:00
|
|
|
);
|
2004-09-02 16:23:21 +00:00
|
|
|
error_msg = "signature verification failed";
|
2005-06-07 23:12:47 +00:00
|
|
|
status = ERR_RSA_FAILED;
|
2002-08-13 22:36:54 +00:00
|
|
|
return ERR_RSA_FAILED;
|
2002-07-11 01:09:53 +00:00
|
|
|
}
|
2004-09-02 16:23:21 +00:00
|
|
|
} else if (strlen(md5_cksum)) {
|
2012-01-26 23:13:00 +00:00
|
|
|
if (!strlen(cksum)) {
|
2013-04-03 00:23:37 +00:00
|
|
|
if (allow_async && nbytes > ASYNC_FILE_THRESHOLD) {
|
|
|
|
ASYNC_VERIFY* avp = new ASYNC_VERIFY();
|
|
|
|
retval = avp->init(this);
|
2012-02-06 23:33:23 +00:00
|
|
|
if (retval) {
|
|
|
|
status = retval;
|
|
|
|
return retval;
|
|
|
|
}
|
2013-04-03 00:23:37 +00:00
|
|
|
status = FILE_VERIFY_PENDING;
|
|
|
|
return ERR_IN_PROGRESS;
|
|
|
|
}
|
2012-01-26 23:13:00 +00:00
|
|
|
retval = md5_file(pathname, cksum, local_nbytes);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
|
|
|
"MD5 computation error for %s: %s\n",
|
|
|
|
name, boincerror(retval)
|
|
|
|
);
|
|
|
|
error_msg = "MD5 computation error";
|
|
|
|
status = retval;
|
|
|
|
return retval;
|
|
|
|
}
|
2003-11-29 02:41:28 +00:00
|
|
|
}
|
2004-09-02 16:23:21 +00:00
|
|
|
if (strcmp(cksum, md5_cksum)) {
|
2007-01-19 20:56:49 +00:00
|
|
|
if (show_errors) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2007-01-19 20:56:49 +00:00
|
|
|
"MD5 check failed for %s", name
|
|
|
|
);
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2007-01-19 20:56:49 +00:00
|
|
|
"expected %s, got %s\n", md5_cksum, cksum
|
|
|
|
);
|
|
|
|
}
|
2004-09-02 16:23:21 +00:00
|
|
|
error_msg = "MD5 check failed";
|
2005-06-07 23:12:47 +00:00
|
|
|
status = ERR_MD5_FAILED;
|
2002-08-15 21:52:04 +00:00
|
|
|
return ERR_MD5_FAILED;
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-13 19:05:18 +00:00
|
|
|
// scan FILE_INFOs and create PERS_FILE_XFERs as needed.
|
|
|
|
// NOTE: this doesn't start the file transfers
|
|
|
|
// scan PERS_FILE_XFERs and delete finished ones.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2011-11-04 20:25:30 +00:00
|
|
|
bool CLIENT_STATE::create_and_delete_pers_file_xfers() {
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
FILE_INFO* fip;
|
2002-08-07 22:52:10 +00:00
|
|
|
PERS_FILE_XFER *pfx;
|
2002-04-30 22:22:54 +00:00
|
|
|
bool action = false;
|
2003-11-02 22:51:49 +00:00
|
|
|
int retval;
|
2004-10-14 22:01:05 +00:00
|
|
|
static double last_time;
|
|
|
|
|
2013-03-15 03:43:29 +00:00
|
|
|
if (!clock_change && now - last_time < PERS_FILE_XFER_START_PERIOD) return false;
|
2007-05-10 16:23:10 +00:00
|
|
|
last_time = now;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-02-20 00:06:07 +00:00
|
|
|
// Look for FILE_INFOs for which we should start a transfer,
|
|
|
|
// and make PERS_FILE_XFERs for them
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
fip = file_infos[i];
|
2002-08-07 22:52:10 +00:00
|
|
|
pfx = fip->pers_file_xfer;
|
2002-08-28 21:50:51 +00:00
|
|
|
if (pfx) continue;
|
2011-07-20 19:12:10 +00:00
|
|
|
if (fip->downloadable() && fip->status == FILE_NOT_PRESENT) {
|
2002-08-07 22:52:10 +00:00
|
|
|
pfx = new PERS_FILE_XFER;
|
2002-08-15 21:52:04 +00:00
|
|
|
pfx->init(fip, false);
|
2002-08-07 22:52:10 +00:00
|
|
|
fip->pers_file_xfer = pfx;
|
2003-07-29 23:26:32 +00:00
|
|
|
pers_file_xfers->insert(fip->pers_file_xfer);
|
2002-04-30 22:22:54 +00:00
|
|
|
action = true;
|
2011-07-20 19:12:10 +00:00
|
|
|
} else if (fip->uploadable() && fip->status == FILE_PRESENT && !fip->uploaded) {
|
2002-08-07 22:52:10 +00:00
|
|
|
pfx = new PERS_FILE_XFER;
|
2002-08-23 00:53:00 +00:00
|
|
|
pfx->init(fip, true);
|
2002-08-07 22:52:10 +00:00
|
|
|
fip->pers_file_xfer = pfx;
|
2003-07-29 23:26:32 +00:00
|
|
|
pers_file_xfers->insert(fip->pers_file_xfer);
|
2002-04-30 22:22:54 +00:00
|
|
|
action = true;
|
2004-08-05 21:42:26 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-21 19:12:42 +00:00
|
|
|
|
2003-02-20 00:06:07 +00:00
|
|
|
// Scan existing PERS_FILE_XFERs, looking for those that are done,
|
|
|
|
// and deleting them
|
|
|
|
//
|
|
|
|
vector<PERS_FILE_XFER*>::iterator iter;
|
2003-07-29 23:26:32 +00:00
|
|
|
iter = pers_file_xfers->pers_file_xfers.begin();
|
|
|
|
while (iter != pers_file_xfers->pers_file_xfers.end()) {
|
2003-02-20 00:06:07 +00:00
|
|
|
pfx = *iter;
|
2002-08-23 00:53:00 +00:00
|
|
|
|
2002-08-21 19:12:42 +00:00
|
|
|
// If the transfer finished, remove the PERS_FILE_XFER object
|
|
|
|
// from the set and delete it
|
2002-08-28 21:50:51 +00:00
|
|
|
//
|
2004-09-04 05:21:33 +00:00
|
|
|
if (pfx->pers_xfer_done) {
|
2003-11-02 22:51:49 +00:00
|
|
|
fip = pfx->fip;
|
2011-07-20 19:12:10 +00:00
|
|
|
if (pfx->is_upload) {
|
2003-11-02 22:51:49 +00:00
|
|
|
// file has been uploaded - delete if not sticky
|
|
|
|
//
|
|
|
|
if (!fip->sticky) {
|
|
|
|
fip->delete_file();
|
|
|
|
}
|
|
|
|
fip->uploaded = true;
|
2005-04-28 23:19:58 +00:00
|
|
|
active_tasks.upload_notify_app(fip);
|
2005-03-10 00:43:22 +00:00
|
|
|
} else if (fip->status >= 0) {
|
|
|
|
// file transfer did not fail (non-negative status)
|
2003-11-02 22:51:49 +00:00
|
|
|
|
- client: add a mechanism for restartable download of compressed files.
(It turns out that the compression schemes supported by
Apache and libcurl, suprisingly, aren't restartable.)
if a <file_info> from the server contains <gzipped_url> tags,
use those instead of the <url> tags,
and flag the file as "download_gzipped".
If this is the case, download NAME.gz and save it as NAME.gzt.
When the download is complete, rename NAME.gzt to NAME.gz,
and uncompress it to NAME.
(this ensures that if NAME.gz is present, it's complete).
Also do the uncompression, if needed, in verify_file().
This ensures that the uncompression will eventually get done
even if the client quits are crashes in the middle.
- update_versions: if <gzip> is present in a <file_info>,
add a gzipped copy in the download directory
and add a <gzipped_url> elements to the app version's xml_doc.
svn path=/trunk/boinc/; revision=25112
2012-01-20 23:34:15 +00:00
|
|
|
// If this was a compressed download, rename .gzt to .gz
|
|
|
|
//
|
|
|
|
if (fip->download_gzipped) {
|
2012-05-09 16:11:50 +00:00
|
|
|
char path[MAXPATHLEN], from_path[MAXPATHLEN], to_path[MAXPATHLEN];
|
- client: add a mechanism for restartable download of compressed files.
(It turns out that the compression schemes supported by
Apache and libcurl, suprisingly, aren't restartable.)
if a <file_info> from the server contains <gzipped_url> tags,
use those instead of the <url> tags,
and flag the file as "download_gzipped".
If this is the case, download NAME.gz and save it as NAME.gzt.
When the download is complete, rename NAME.gzt to NAME.gz,
and uncompress it to NAME.
(this ensures that if NAME.gz is present, it's complete).
Also do the uncompression, if needed, in verify_file().
This ensures that the uncompression will eventually get done
even if the client quits are crashes in the middle.
- update_versions: if <gzip> is present in a <file_info>,
add a gzipped copy in the download directory
and add a <gzipped_url> elements to the app version's xml_doc.
svn path=/trunk/boinc/; revision=25112
2012-01-20 23:34:15 +00:00
|
|
|
get_pathname(fip, path, sizeof(path));
|
|
|
|
sprintf(from_path, "%s.gzt", path);
|
|
|
|
sprintf(to_path, "%s.gz", path);
|
|
|
|
boinc_rename(from_path, to_path);
|
|
|
|
}
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
// verify the file with RSA or MD5, and change permissions
|
|
|
|
//
|
2012-02-08 19:30:57 +00:00
|
|
|
retval = fip->verify_file(true, true, true);
|
2013-04-03 00:23:37 +00:00
|
|
|
if (retval == ERR_IN_PROGRESS) {
|
|
|
|
// do nothing
|
|
|
|
} else if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(fip->project, MSG_INTERNAL_ERROR,
|
2005-03-01 19:56:30 +00:00
|
|
|
"Checksum or signature error for %s", fip->name
|
|
|
|
);
|
2003-11-02 22:51:49 +00:00
|
|
|
fip->status = retval;
|
|
|
|
} else {
|
|
|
|
// Set the appropriate permissions depending on whether
|
|
|
|
// it's an executable or normal file
|
|
|
|
//
|
|
|
|
retval = fip->set_permissions();
|
|
|
|
fip->status = FILE_PRESENT;
|
|
|
|
}
|
|
|
|
|
2006-06-26 19:08:00 +00:00
|
|
|
// if it's a user file, tell running apps to reread prefs
|
2003-11-02 22:51:49 +00:00
|
|
|
//
|
|
|
|
if (fip->is_user_file) {
|
|
|
|
active_tasks.request_reread_prefs(fip->project);
|
|
|
|
}
|
2006-06-26 22:58:24 +00:00
|
|
|
|
|
|
|
// if it's a project file, make a link in project dir
|
|
|
|
//
|
|
|
|
if (fip->is_project_file) {
|
|
|
|
PROJECT* p = fip->project;
|
2006-07-25 21:07:14 +00:00
|
|
|
p->write_symlink_for_project_file(fip);
|
2006-10-12 19:43:55 +00:00
|
|
|
p->update_project_files_downloaded_time();
|
2006-06-26 22:58:24 +00:00
|
|
|
}
|
2003-11-02 22:51:49 +00:00
|
|
|
}
|
2003-07-29 23:26:32 +00:00
|
|
|
iter = pers_file_xfers->pers_file_xfers.erase(iter);
|
2002-08-21 19:12:42 +00:00
|
|
|
delete pfx;
|
|
|
|
action = true;
|
2003-07-23 22:24:28 +00:00
|
|
|
// `delete pfx' should have set pfx->fip->pfx to NULL
|
2003-11-02 22:51:49 +00:00
|
|
|
assert (fip == NULL || fip->pers_file_xfer == NULL);
|
2003-02-20 00:58:55 +00:00
|
|
|
} else {
|
|
|
|
iter++;
|
2002-08-21 19:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
return action;
|
|
|
|
}
|
2010-09-24 20:02:42 +00:00
|
|
|
#endif
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2012-06-26 20:30:56 +00:00
|
|
|
// called at startup to ensure that if the client
|
2012-02-09 00:47:04 +00:00
|
|
|
// thinks a file is there, it actually is, and is the right size
|
2006-07-25 16:45:21 +00:00
|
|
|
//
|
|
|
|
void CLIENT_STATE::check_file_existence() {
|
|
|
|
unsigned int i;
|
2012-05-09 16:11:50 +00:00
|
|
|
char path[MAXPATHLEN];
|
2006-07-25 16:45:21 +00:00
|
|
|
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
FILE_INFO* fip = file_infos[i];
|
2013-03-21 20:53:17 +00:00
|
|
|
if (fip->status < 0 && fip->downloadable()) {
|
|
|
|
// file had an error; reset it so that we download again
|
|
|
|
get_pathname(fip, path, sizeof(path));
|
|
|
|
msg_printf(NULL, MSG_INFO, "Resetting file %s: %s", path, boincerror(fip->status));
|
|
|
|
fip->reset();
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.dont_check_file_sizes) continue;
|
2006-07-25 16:45:21 +00:00
|
|
|
if (fip->status == FILE_PRESENT) {
|
2007-03-13 19:33:27 +00:00
|
|
|
get_pathname(fip, path, sizeof(path));
|
2012-02-09 00:47:04 +00:00
|
|
|
double size;
|
|
|
|
int retval = file_size(path, size);
|
2013-01-05 22:20:26 +00:00
|
|
|
if (retval) {
|
|
|
|
delete_project_owned_file(path, true);
|
|
|
|
fip->status = FILE_NOT_PRESENT;
|
|
|
|
msg_printf(NULL, MSG_INFO, "File %s not found", path);
|
|
|
|
} else if (fip->nbytes && (size != fip->nbytes)) {
|
|
|
|
if (gstate.global_prefs.dont_verify_images && is_image_file(path)) continue;
|
2012-02-09 01:06:15 +00:00
|
|
|
delete_project_owned_file(path, true);
|
2006-07-25 16:45:21 +00:00
|
|
|
fip->status = FILE_NOT_PRESENT;
|
2013-01-05 22:20:26 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"File %s has wrong size: expected %.0f, got %.0f",
|
|
|
|
path, fip->nbytes, size
|
|
|
|
);
|
2006-07-25 16:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-28 23:19:58 +00:00
|
|
|
|