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
|
2019-01-12 21:43:48 +00:00
|
|
|
// Copyright (C) 2019 University of California
|
2004-07-13 13:54:09 +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.
|
2004-07-13 13:54:09 +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
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <string>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cassert>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-11-06 09:03:55 +00:00
|
|
|
#include "error_numbers.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "parse.h"
|
2004-09-24 21:28:12 +00:00
|
|
|
#include "sched_config.h"
|
2015-10-22 13:21:06 +00:00
|
|
|
#include "str_replace.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-18 20:40:22 +00:00
|
|
|
#define OUTFILE_MACRO "<OUTFILE_"
|
2002-05-14 23:13:17 +00:00
|
|
|
#define UPLOAD_URL_MACRO "<UPLOAD_URL/>"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2011-07-20 20:08:05 +00:00
|
|
|
// Add a signature at the end of every <file_info> element,
|
2002-11-06 09:03:55 +00:00
|
|
|
//
|
|
|
|
int add_signatures(char* xml, R_RSA_PRIVATE_KEY& key) {
|
2013-12-13 08:07:36 +00:00
|
|
|
char* p = xml, *q1, *q2, buf[BLOB_SIZE], buf2[BLOB_SIZE];
|
2008-03-31 16:19:45 +00:00
|
|
|
char signature_hex[BLOB_SIZE];
|
|
|
|
char signature_xml[BLOB_SIZE];
|
2011-07-20 20:08:05 +00:00
|
|
|
char signed_xml[1024];
|
2002-11-06 09:03:55 +00:00
|
|
|
int retval, len;
|
|
|
|
|
|
|
|
while (1) {
|
2002-11-09 20:26:50 +00:00
|
|
|
q1 = strstr(p, "<file_info>\n");
|
2002-11-06 09:03:55 +00:00
|
|
|
if (!q1) break;
|
|
|
|
q2 = strstr(q1, "</file_info>");
|
|
|
|
if (!q2) {
|
|
|
|
fprintf(stderr, "add_signatures: malformed XML: %s\n", xml);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2005-08-03 06:04:07 +00:00
|
|
|
|
2002-11-09 20:26:50 +00:00
|
|
|
q1 += strlen("<file_info>\n");
|
2002-11-06 09:03:55 +00:00
|
|
|
len = q2 - q1;
|
|
|
|
memcpy(buf, q1, len);
|
|
|
|
buf[len] = 0;
|
2011-07-20 20:08:05 +00:00
|
|
|
char name[1024];
|
|
|
|
if (!parse_str(buf, "<name>", name, sizeof(name))) {
|
|
|
|
fprintf(stderr, "add_signatures: missing name: %s", buf);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
double max_nbytes;
|
|
|
|
if (!parse_double(buf, "<max_nbytes>", max_nbytes)) {
|
|
|
|
fprintf(stderr, "add_signatures: missing max_nbytes: %s", buf);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
sprintf(signed_xml, "<name>%s</name><max_nbytes>%.0f</max_nbytes>",
|
|
|
|
name, max_nbytes
|
|
|
|
);
|
|
|
|
retval = generate_signature(signed_xml, signature_hex, key);
|
2005-12-14 23:43:50 +00:00
|
|
|
sprintf(signature_xml,
|
|
|
|
"<xml_signature>\n%s</xml_signature>\n", signature_hex
|
|
|
|
);
|
2002-11-06 09:03:55 +00:00
|
|
|
if (retval) return retval;
|
2015-10-22 13:21:06 +00:00
|
|
|
safe_strcpy(buf2, q2);
|
2002-11-07 19:31:34 +00:00
|
|
|
strcpy(q1, buf);
|
2005-12-14 23:43:50 +00:00
|
|
|
strcat(q1, signature_xml);
|
2002-11-07 19:31:34 +00:00
|
|
|
strcat(q1, buf2);
|
|
|
|
p = q1;
|
2002-11-06 09:03:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-30 23:05:16 +00:00
|
|
|
#if 0 // is this used anywhere??
|
|
|
|
|
2002-11-06 09:03:55 +00:00
|
|
|
// remove file upload signatures from a result XML doc
|
|
|
|
//
|
|
|
|
int remove_signatures(char* xml) {
|
|
|
|
char* p, *q;
|
|
|
|
while (1) {
|
|
|
|
p = strstr(xml, "<xml_signature>");
|
|
|
|
if (!p) break;
|
|
|
|
q = strstr(p, "</xml_signature>");
|
|
|
|
if (!q) {
|
|
|
|
fprintf(stderr, "remove_signatures: invalid XML:\n%s", xml);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2003-04-04 20:56:51 +00:00
|
|
|
q += strlen("</xml_signature>\n");
|
2002-11-06 09:03:55 +00:00
|
|
|
strcpy(p, q);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-30 23:05:16 +00:00
|
|
|
#endif
|
2002-11-06 09:03:55 +00:00
|
|
|
|
|
|
|
// macro-substitute a result template:
|
|
|
|
// - replace OUTFILE_x with base_filename_x, etc.
|
|
|
|
// - add signatures for file uploads
|
2011-06-29 22:26:45 +00:00
|
|
|
// - strip enclosing <output_template> tags
|
2002-11-06 09:03:55 +00:00
|
|
|
//
|
2004-04-13 23:55:05 +00:00
|
|
|
// This is called only from the transitioner,
|
|
|
|
// to create a new result for a WU
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int process_result_template(
|
2002-11-06 09:03:55 +00:00
|
|
|
char* result_template,
|
2002-07-05 05:33:40 +00:00
|
|
|
R_RSA_PRIVATE_KEY& key,
|
2002-10-09 04:56:41 +00:00
|
|
|
char* base_filename,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
SCHED_CONFIG& config_loc
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2002-11-06 09:03:55 +00:00
|
|
|
char* p,*q;
|
2015-11-18 20:40:22 +00:00
|
|
|
char temp[BLOB_SIZE], buf[256];
|
2004-12-08 07:03:43 +00:00
|
|
|
int retval;
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2002-11-06 09:03:55 +00:00
|
|
|
while (1) {
|
|
|
|
p = strstr(result_template, OUTFILE_MACRO);
|
|
|
|
if (p) {
|
|
|
|
q = p+strlen(OUTFILE_MACRO);
|
2004-12-06 22:41:19 +00:00
|
|
|
char* endptr = strstr(q, "/>");
|
|
|
|
if (!endptr) return ERR_XML_PARSE;
|
|
|
|
if (strchr(q, '>') != endptr+1) return ERR_XML_PARSE;
|
|
|
|
*endptr = 0;
|
|
|
|
strcpy(buf, q);
|
|
|
|
strcpy(temp, endptr+2);
|
2002-11-06 09:03:55 +00:00
|
|
|
strcpy(p, base_filename);
|
2004-12-06 22:41:19 +00:00
|
|
|
strcat(p, buf);
|
2002-11-06 09:03:55 +00:00
|
|
|
strcat(p, temp);
|
2002-07-05 05:33:40 +00:00
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-11-06 09:03:55 +00:00
|
|
|
p = strstr(result_template, UPLOAD_URL_MACRO);
|
|
|
|
if (p) {
|
|
|
|
strcpy(temp, p+strlen(UPLOAD_URL_MACRO));
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
strcpy(p, config_loc.upload_url);
|
2002-11-06 09:03:55 +00:00
|
|
|
strcat(p, temp);
|
2002-07-05 05:33:40 +00:00
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-11-06 09:03:55 +00:00
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
if (!config_loc.dont_generate_upload_certificates) {
|
2004-09-24 21:28:12 +00:00
|
|
|
retval = add_signatures(result_template, key);
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
2011-06-29 22:26:45 +00:00
|
|
|
|
2011-08-27 16:52:04 +00:00
|
|
|
// strip enclosing <output_template> tags, if any
|
|
|
|
//
|
|
|
|
p = strstr(result_template, "<output_template>");
|
|
|
|
if (p) {
|
2015-10-22 13:21:06 +00:00
|
|
|
safe_strcpy(temp, result_template+strlen("<output_template>"));
|
2011-08-27 16:52:04 +00:00
|
|
|
q = strstr(temp, "</output_template>");
|
|
|
|
if (q) *q = 0;
|
|
|
|
strcpy(result_template, temp);
|
|
|
|
}
|
|
|
|
strip_whitespace(result_template);
|
2004-09-24 21:28:12 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|