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
|
2004-06-16 19:21:11 +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-06-16 19:21:11 +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.
|
2004-06-16 19:21:11 +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/>.
|
2004-06-16 19:21:11 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
|
2005-12-16 03:45:01 +00:00
|
|
|
#else
|
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2004-06-16 19:21:11 +00:00
|
|
|
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2006-04-08 11:00:45 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
#include "parse.h"
|
2008-11-05 20:11:45 +00:00
|
|
|
#include "util.h"
|
2004-06-17 17:00:14 +00:00
|
|
|
#include "file_names.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "error_numbers.h"
|
2008-11-05 20:11:45 +00:00
|
|
|
#include "mac_address.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
|
|
|
|
#include "hostinfo.h"
|
|
|
|
|
2004-06-17 17:00:14 +00:00
|
|
|
// get domain name and IP address of this host
|
2004-06-16 19:21:11 +00:00
|
|
|
//
|
2006-06-23 20:41:47 +00:00
|
|
|
int HOST_INFO::get_local_network_info() {
|
2004-06-17 17:09:03 +00:00
|
|
|
struct in_addr addr;
|
2006-04-08 11:00:45 +00:00
|
|
|
struct hostent* he;
|
|
|
|
|
2007-08-11 03:34:38 +00:00
|
|
|
strcpy(domain_name, "");
|
|
|
|
strcpy(ip_addr, "");
|
2007-12-27 21:40:20 +00:00
|
|
|
|
|
|
|
// it seems like we should use getdomainname() instead of gethostname(),
|
|
|
|
// but on FC6 it returns "(none)".
|
|
|
|
//
|
2007-08-11 03:34:38 +00:00
|
|
|
if (gethostname(domain_name, 256)) return ERR_GETHOSTBYNAME;
|
|
|
|
he = gethostbyname(domain_name);
|
2004-06-16 19:21:11 +00:00
|
|
|
if (!he || !he->h_addr_list[0]) {
|
2007-08-14 02:38:38 +00:00
|
|
|
//msg_printf(NULL, MSG_ERROR, "gethostbyname (%s) failed", domain_name);
|
2004-06-16 19:21:11 +00:00
|
|
|
return ERR_GETHOSTBYNAME;
|
|
|
|
}
|
|
|
|
memcpy(&addr, he->h_addr_list[0], sizeof(addr));
|
2006-06-23 20:41:47 +00:00
|
|
|
strlcpy(ip_addr, inet_ntoa(addr), sizeof(ip_addr));
|
2004-06-16 19:21:11 +00:00
|
|
|
return 0;
|
2004-06-17 17:54:05 +00:00
|
|
|
}
|
|
|
|
|
2008-11-05 20:11:45 +00:00
|
|
|
// make a random string using host info.
|
|
|
|
// Not recommended for password generation;
|
|
|
|
// use as a last resort if more secure methods fail
|
|
|
|
//
|
|
|
|
void HOST_INFO::make_random_string(const char* salt, char* out) {
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
sprintf(buf, "%f%s%s%f%s", dtime(), domain_name, ip_addr, d_free, salt);
|
|
|
|
md5_block((const unsigned char*) buf, (int)strlen(buf), out);
|
|
|
|
}
|
|
|
|
|
|
|
|
// make a host cross-project ID.
|
|
|
|
// Should be unique across hosts with very high probability
|
|
|
|
//
|
|
|
|
void HOST_INFO::generate_host_cpid() {
|
|
|
|
#if defined(__linux__) || defined(_WIN32) || defined(__APPLE__ )
|
|
|
|
char buffer[8192] = "";
|
|
|
|
// must be big enough to accommodate aa:bb:cc:dd:ee:ff
|
|
|
|
// times the number of network interfaces,
|
2008-11-05 20:27:04 +00:00
|
|
|
// plus the domain name, IP addr, and OS name.
|
2008-11-05 20:11:45 +00:00
|
|
|
// 8K should suffice
|
|
|
|
|
|
|
|
if (!get_mac_addresses(buffer) || ! strcmp(buffer, "")) {
|
|
|
|
make_random_string("", host_cpid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcat(buffer, domain_name);
|
|
|
|
strcat(buffer, ip_addr);
|
2008-11-05 20:27:04 +00:00
|
|
|
strcat(buffer, os_name);
|
2008-11-05 20:11:45 +00:00
|
|
|
md5_block((unsigned char*)buffer, (int)strlen(buffer), host_cpid);
|
|
|
|
#else
|
|
|
|
make_random_string("", host_cpid);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_9275b20aa5 = "$Id$";
|