1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18 // A sample assimilator that:
19 // 1) if success, copy the output file(s) to a directory
20 // 2) if failure, append a message to an error log
25 #include <sys/types.h>
32 #include "error_numbers.h"
34 #include "sched_msgs.h"
35 #include "validate_util.h"
36 #include "sched_config.h"
40 int write_error(char* p) {
43 f = fopen("../../results/errors", "a");
44 if (!f) return ERR_FOPEN;
51 int GetNumFilesInDir(char *dir)
55 if((partsdir = opendir(dir)) == NULL) {
59 while ((part = readdir(partsdir)) != NULL)
61 char *partname = part->d_name;
62 if(partname != "." && partname != "..")
70 int assimilate_handler(
71 WORKUNIT& wu, vector<RESULT>& /*results*/, RESULT& canonical_result
81 retval = frt.open("rainbowtables-distrrtgen", config.db_host, config.db_user, config.db_passwd);
83 log_messages.printf(MSG_CRITICAL, "can't open db rainbowtables-distrrtgen\n");
88 const char *pos = strchr(wu.name, '_');
89 char partnum[256] = {0};
90 strncpy(partnum, wu.name, pos - wu.name);
91 int lookupid = atoi(partnum);
92 log_messages.printf(MSG_DEBUG, "Handling lookupid %i\n", lookupid);
95 if (wu.canonical_resultid) {
96 sprintf(query, "DELETE FROM rainbowcrack_cracker_verificationqueue WHERE lookupid = %i", lookupid);
98 if(retval) goto cleanup;
101 vector<FILE_INFO> output_files;
103 get_output_file_infos(canonical_result, output_files);
104 unsigned int n = output_files.size();
107 log_messages.printf(MSG_CRITICAL, "No files found!\n");
111 FILE_INFO& fi = output_files[0];
113 read_file_string(fi.path.c_str(), filedata);
114 if(strcmp(filedata.c_str(),"0x00") != 0)
116 sprintf(query, "UPDATE rainbowcrack_cracker_hashlist SET password = '%s' WHERE lookupid = %i", filedata.c_str(), lookupid);
117 log_messages.printf(MSG_CRITICAL, "BINGO! Password %s is belonging to %i\n", filedata.c_str(), lookupid);
118 log_messages.printf(MSG_CRITICAL, "%s\n", query);
120 else log_messages.printf(MSG_DEBUG, "Ew. Password NOT found in %i (%s)\n", lookupid, filedata.c_str());
121 sprintf(query, "DELETE FROM rainbowcrack_cracker_verificationqueue WHERE lookupid = %i", lookupid);
123 if(retval) goto cleanup;
124 sprintf(query, "UPDATE rainbowcrack_cracker_lookups SET status = 2 WHERE lookupid = %i", lookupid);
126 if(retval) goto cleanup;
129 sprintf(buf, "%s: 0x%x\n", wu.name, wu.error_mask);
130 return write_error(buf);