2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// add.C - add items to the DB
|
|
|
|
//
|
|
|
|
// usages:
|
2002-08-25 07:54:33 +00:00
|
|
|
// add project -project_name x
|
|
|
|
// add project
|
2002-04-30 22:22:54 +00:00
|
|
|
// add app -app_name x
|
|
|
|
// add application
|
|
|
|
// create DB record
|
|
|
|
// add platform -platform_name x
|
|
|
|
// create DB record
|
|
|
|
// add app_version
|
2002-07-29 00:39:45 +00:00
|
|
|
// -app_name x -platform_name y -version a
|
2002-08-14 20:31:27 +00:00
|
|
|
// -download_dir d -download_url e
|
2002-07-29 00:39:45 +00:00
|
|
|
// -exec_dir b
|
|
|
|
// [ -exec_files file1 file2 ... ]
|
|
|
|
// [ -signed_exec_files file1 sign1 file2 sign2 ... ]
|
2002-04-30 22:22:54 +00:00
|
|
|
// create DB record
|
|
|
|
// copy exec to data directory
|
|
|
|
// add user -email_addr x -name y -web_password z -authenticator a
|
2002-09-27 06:12:50 +00:00
|
|
|
// [ -global_prefs_file y ]
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "db.h"
|
|
|
|
#include "backend_lib.h"
|
|
|
|
#include "md5_file.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
APP app;
|
|
|
|
PLATFORM platform;
|
|
|
|
APP_VERSION app_version;
|
|
|
|
USER user;
|
2002-08-25 07:54:33 +00:00
|
|
|
PROJECT project;
|
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
int version, retval, nexec_files;
|
2002-05-29 23:25:21 +00:00
|
|
|
double nbytes;
|
2002-07-29 00:39:45 +00:00
|
|
|
bool signed_exec_files;
|
2002-05-29 23:25:21 +00:00
|
|
|
char buf[256], md5_cksum[64];
|
2002-10-03 18:33:46 +00:00
|
|
|
char *db_name=0, *db_passwd=0, *app_name=0, *platform_name=0, *project_name=0;
|
2002-07-29 00:39:45 +00:00
|
|
|
char* exec_dir=0, *exec_files[10], *signature_files[10];
|
2002-05-29 23:25:21 +00:00
|
|
|
char *email_addr=0, *user_name=0, *web_password=0, *authenticator=0;
|
2002-09-27 06:12:50 +00:00
|
|
|
char *global_prefs_file=0, *download_dir, *download_url;
|
2002-10-03 18:33:46 +00:00
|
|
|
char* code_sign_keyfile=0;
|
2002-05-29 23:25:21 +00:00
|
|
|
char *message=0, *message_priority=0;
|
|
|
|
|
2002-08-25 07:54:33 +00:00
|
|
|
void add_project() {
|
|
|
|
int retval;
|
|
|
|
|
2002-11-19 19:37:01 +00:00
|
|
|
if (!project_name) {
|
|
|
|
fprintf( stderr, "Project name not specified.\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-25 07:54:33 +00:00
|
|
|
memset(&project, 0, sizeof(project));
|
|
|
|
strcpy(project.name, project_name);
|
|
|
|
retval = db_project_new(project);
|
|
|
|
if (retval) {
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_project_new");
|
2002-08-25 07:54:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
void add_app() {
|
|
|
|
int retval;
|
|
|
|
|
2002-11-19 19:37:01 +00:00
|
|
|
if (!app_name) {
|
|
|
|
fprintf( stderr, "Application name not specified.\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-29 23:25:21 +00:00
|
|
|
memset(&app, 0, sizeof(app));
|
|
|
|
strcpy(app.name, app_name);
|
|
|
|
app.create_time = time(0);
|
2002-07-29 00:39:45 +00:00
|
|
|
app.min_version = version;
|
2002-05-29 23:25:21 +00:00
|
|
|
retval = db_app_new(app);
|
|
|
|
if (retval) {
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_app_new");
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_platform() {
|
|
|
|
int retval;
|
|
|
|
|
2002-11-19 19:37:01 +00:00
|
|
|
if (!platform_name) {
|
|
|
|
fprintf( stderr, "Platform name not specified.\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-29 23:25:21 +00:00
|
|
|
memset(&platform, 0, sizeof(platform));
|
|
|
|
strcpy(platform.name, platform_name);
|
|
|
|
platform.create_time = time(0);
|
|
|
|
retval = db_platform_new(platform);
|
|
|
|
if (retval) {
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_platform_new");
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
int sign_executable(char* path, char* signature_text) {
|
2002-07-07 20:39:24 +00:00
|
|
|
DATA_BLOCK signature;
|
2002-07-09 00:10:58 +00:00
|
|
|
unsigned char signature_buf[SIGNATURE_SIZE_BINARY];
|
2002-07-29 00:39:45 +00:00
|
|
|
R_RSA_PRIVATE_KEY code_sign_key;
|
2002-10-14 23:10:12 +00:00
|
|
|
retval = read_key_file(code_sign_keyfile, code_sign_key);
|
2002-07-29 00:39:45 +00:00
|
|
|
if (retval) {
|
2002-10-14 23:10:12 +00:00
|
|
|
fprintf(stderr, "add: can't read key\n");
|
2002-07-29 00:39:45 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
signature.data = signature_buf;
|
|
|
|
sign_file(path, code_sign_key, signature);
|
|
|
|
sprint_hex_data(signature_text, signature);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_app_version() {
|
|
|
|
char path[256];
|
|
|
|
char signature_text[1024], longbuf[MAX_BLOB_SIZE];
|
|
|
|
int i;
|
2002-07-07 20:39:24 +00:00
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
memset(&app_version, 0, sizeof(app_version));
|
|
|
|
|
2002-11-19 19:37:01 +00:00
|
|
|
if (!app_name) {
|
|
|
|
fprintf( stderr, "Application name not specified.\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-29 23:25:21 +00:00
|
|
|
strcpy(app.name, app_name);
|
|
|
|
retval = db_app_lookup_name(app);
|
|
|
|
if (retval) {
|
2002-06-10 06:14:18 +00:00
|
|
|
fprintf(stderr, "add_app_version(): can't find app %s\n", app_name);
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_app_lookup_name");
|
2002-05-29 23:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
app_version.appid = app.id;
|
|
|
|
strcpy(platform.name, platform_name);
|
|
|
|
retval = db_platform_lookup_name(platform);
|
|
|
|
if (retval) {
|
2002-06-10 06:14:18 +00:00
|
|
|
fprintf(stderr, "add_app_version(): can't find platform %s\n", platform_name);
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_platform_lookup_name");
|
2002-05-29 23:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
app_version.platformid = platform.id;
|
|
|
|
app_version.version_num = version;
|
|
|
|
if (message) strcpy(app_version.message, message);
|
|
|
|
if (message_priority) strcpy(app_version.message, message_priority);
|
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
strcpy(app_version.xml_doc, "");
|
2002-05-29 23:25:21 +00:00
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
// copy executables to download directory and sign them
|
2002-05-29 23:25:21 +00:00
|
|
|
//
|
2002-07-29 00:39:45 +00:00
|
|
|
for (i=0; i<nexec_files; i++) {
|
|
|
|
sprintf(
|
|
|
|
buf,
|
|
|
|
"cp %s/%s %s/%s",
|
|
|
|
exec_dir, exec_files[i], download_dir, exec_files[i]
|
|
|
|
);
|
|
|
|
retval = system(buf);
|
|
|
|
if (retval) {
|
|
|
|
printf("failed: %s\n", buf);
|
|
|
|
return;
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
if (signed_exec_files) {
|
|
|
|
read_filename(signature_files[i], signature_text);
|
|
|
|
} else {
|
|
|
|
sprintf(path, "%s/%s", exec_dir, exec_files[i]);
|
|
|
|
sign_executable(path, signature_text);
|
|
|
|
}
|
2002-05-29 23:25:21 +00:00
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
md5_file(path, md5_cksum, nbytes);
|
|
|
|
|
|
|
|
// generate the XML doc directly.
|
|
|
|
// TODO: use a template, as in create_work (??)
|
|
|
|
//
|
|
|
|
sprintf(longbuf,
|
|
|
|
"<file_info>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <url>%s/%s</url>\n"
|
|
|
|
" <executable/>\n"
|
|
|
|
" <file_signature>\n%s"
|
|
|
|
" </file_signature>\n"
|
|
|
|
" <nbytes>%f</nbytes>\n"
|
|
|
|
"</file_info>\n",
|
|
|
|
exec_files[i],
|
2002-08-14 20:31:27 +00:00
|
|
|
download_url, exec_files[i],
|
2002-07-29 00:39:45 +00:00
|
|
|
signature_text,
|
|
|
|
nbytes
|
|
|
|
);
|
|
|
|
strcat(app_version.xml_doc, longbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(longbuf,
|
2002-05-29 23:25:21 +00:00
|
|
|
"<app_version>\n"
|
|
|
|
" <app_name>%s</app_name>\n"
|
2002-07-29 00:39:45 +00:00
|
|
|
" <version_num>%d</version_num>\n",
|
2002-05-29 23:25:21 +00:00
|
|
|
app_name,
|
2002-07-29 00:39:45 +00:00
|
|
|
version
|
2002-05-29 23:25:21 +00:00
|
|
|
);
|
2002-07-29 00:39:45 +00:00
|
|
|
strcat(app_version.xml_doc, longbuf);
|
|
|
|
for (i=0; i<nexec_files; i++) {
|
|
|
|
sprintf(longbuf,
|
|
|
|
" <file_ref>\n"
|
|
|
|
" <file_name>%s</file_name>\n"
|
|
|
|
"%s"
|
|
|
|
" </file_ref>\n",
|
|
|
|
exec_files[i],
|
|
|
|
i?"":" <main_program/>\n"
|
|
|
|
);
|
|
|
|
strcat(app_version.xml_doc, longbuf);
|
|
|
|
}
|
|
|
|
strcat(app_version.xml_doc, "</app_version>\n");
|
2002-05-29 23:25:21 +00:00
|
|
|
|
|
|
|
app_version.create_time = time(0);
|
|
|
|
retval = db_app_version_new(app_version);
|
|
|
|
if (retval) {
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_app_version_new");
|
2002-05-29 23:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_user() {
|
|
|
|
memset(&user, 0, sizeof(user));
|
|
|
|
user.create_time = time(0);
|
|
|
|
strcpy(user.email_addr, email_addr);
|
|
|
|
strcpy(user.name, user_name);
|
|
|
|
strcpy(user.web_password, web_password);
|
|
|
|
strcpy(user.authenticator, authenticator);
|
|
|
|
strcpy(user.country, "United States");
|
|
|
|
strcpy(user.postal_code, "94703");
|
2002-09-27 06:12:50 +00:00
|
|
|
if (global_prefs_file) {
|
|
|
|
retval = read_filename(global_prefs_file, user.global_prefs);
|
2002-05-29 23:25:21 +00:00
|
|
|
if (retval) {
|
2002-09-27 06:12:50 +00:00
|
|
|
printf("read_file: %s", global_prefs_file);
|
2002-05-29 23:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = db_user_new(user);
|
|
|
|
if (retval) {
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_print_error("db_user_new");
|
2002-05-29 23:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int main(int argc, char** argv) {
|
2002-08-14 05:26:51 +00:00
|
|
|
int i, retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
for (i=2; i<argc; i++) {
|
2002-10-03 18:33:46 +00:00
|
|
|
if (!strcmp(argv[i], "-db_name")) {
|
|
|
|
db_name = argv[++i];
|
|
|
|
} else if (!strcmp(argv[i], "-db_passwd")) {
|
|
|
|
db_passwd = argv[++i];
|
|
|
|
} else if (!strcmp(argv[i], "-project_name")) {
|
2002-08-25 07:54:33 +00:00
|
|
|
i++;
|
|
|
|
project_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-app_name")) {
|
2002-04-30 22:22:54 +00:00
|
|
|
i++;
|
|
|
|
app_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-platform_name")) {
|
|
|
|
i++;
|
|
|
|
platform_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-exec_dir")) {
|
|
|
|
i++;
|
|
|
|
exec_dir = argv[i];
|
2002-07-29 00:39:45 +00:00
|
|
|
} else if (!strcmp(argv[i], "-exec_files")) {
|
|
|
|
signed_exec_files = false;
|
|
|
|
i++;
|
|
|
|
nexec_files = 0;
|
|
|
|
while (i < argc) {
|
|
|
|
exec_files[nexec_files++] = argv[i++];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (!strcmp(argv[i], "-signed_exec_files")) {
|
|
|
|
signed_exec_files = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
i++;
|
2002-07-29 00:39:45 +00:00
|
|
|
nexec_files = 0;
|
|
|
|
while (i < argc) {
|
|
|
|
exec_files[nexec_files] = argv[i++];
|
|
|
|
signature_files[nexec_files] = argv[i++];
|
|
|
|
nexec_files++;
|
|
|
|
}
|
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-exec_dir")) {
|
|
|
|
i++;
|
|
|
|
exec_dir = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-email_addr")) {
|
|
|
|
i++;
|
|
|
|
email_addr = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-user_name")) {
|
|
|
|
i++;
|
|
|
|
user_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-web_password")) {
|
|
|
|
i++;
|
|
|
|
web_password = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-authenticator")) {
|
|
|
|
i++;
|
|
|
|
authenticator = argv[i];
|
2002-09-27 06:12:50 +00:00
|
|
|
} else if (!strcmp(argv[i], "-global_prefs_file")) {
|
2002-04-30 22:22:54 +00:00
|
|
|
i++;
|
2002-09-27 06:12:50 +00:00
|
|
|
global_prefs_file = argv[i];
|
2002-08-14 20:31:27 +00:00
|
|
|
} else if (!strcmp(argv[i], "-download_url")) {
|
2002-04-30 22:22:54 +00:00
|
|
|
i++;
|
2002-08-14 20:37:48 +00:00
|
|
|
download_url = argv[i];
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-download_dir")) {
|
|
|
|
i++;
|
|
|
|
download_dir = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-version")) {
|
|
|
|
i++;
|
|
|
|
version = atoi(argv[i]);
|
2002-05-17 22:33:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-message")) {
|
|
|
|
i++;
|
|
|
|
message = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-message_priority")) {
|
|
|
|
i++;
|
|
|
|
message_priority = argv[i];
|
2002-07-07 20:39:24 +00:00
|
|
|
} else if (!strcmp(argv[i], "-code_sign_keyfile")) {
|
|
|
|
i++;
|
|
|
|
code_sign_keyfile = argv[i];
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-09 07:24:27 +00:00
|
|
|
retval = boinc_db_open(db_name, db_passwd);
|
2002-10-03 18:33:46 +00:00
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "can't open DB %s\n", db_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-25 07:54:33 +00:00
|
|
|
if (!strcmp(argv[1], "project")) {
|
|
|
|
add_project();
|
|
|
|
} else if (!strcmp(argv[1], "app")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_app();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[1], "platform")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_platform();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[1], "app_version")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_app_version();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[1], "user")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_user();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
printf("Unrecognized command\n");
|
|
|
|
}
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_close();
|
2002-04-30 22:22:54 +00:00
|
|
|
exit(0);
|
|
|
|
}
|