8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 20:03:02 +01:00
This commit is contained in:
robocop 2004-11-16 08:52:29 +00:00
parent 4a13773274
commit bc845125c7
3 changed files with 54 additions and 61 deletions

View File

@ -3,7 +3,7 @@
/* from Peter C. Gutmann's implementation as found in */ /* from Peter C. Gutmann's implementation as found in */
/* Applied Cryptography by Bruce Schneier */ /* Applied Cryptography by Bruce Schneier */
/* This code is in the public domain */ /* This code is in the public domain */
/* $Id: sha.cpp,v 1.1 2004-11-14 18:08:41 alexpeshkoff Exp $ */ /* $Id: sha.cpp,v 1.2 2004-11-16 08:52:29 robocop Exp $ */
// Adopted and added to firebird cvs tree - A.Peshkov, 2004 // Adopted and added to firebird cvs tree - A.Peshkov, 2004
@ -71,7 +71,7 @@ void sha_final(unsigned char [SHA_DIGESTSIZE], SHA_INFO *);
* *
* This code is in the public domain * This code is in the public domain
* *
* $Id: sha.cpp,v 1.1 2004-11-14 18:08:41 alexpeshkoff Exp $ * $Id: sha.cpp,v 1.2 2004-11-16 08:52:29 robocop Exp $
*/ */
/* UNRAVEL should be fastest & biggest */ /* UNRAVEL should be fastest & biggest */
@ -135,10 +135,9 @@ void sha_final(unsigned char [SHA_DIGESTSIZE], SHA_INFO *);
static void sha_transform(SHA_INFO *sha_info) static void sha_transform(SHA_INFO *sha_info)
{ {
int i; int i;
BYTE *dp; LONG T, W[80];
LONG T, A, B, C, D, E, W[80], *WP;
dp = sha_info->data; const BYTE* dp = sha_info->data;
/* /*
the following makes sure that at least one code block below is the following makes sure that at least one code block below is
@ -200,12 +199,12 @@ nether regions of the anatomy...
W[i] = R32(W[i], 1); W[i] = R32(W[i], 1);
#endif /* SHA_VERSION */ #endif /* SHA_VERSION */
} }
A = sha_info->digest[0]; LONG A = sha_info->digest[0];
B = sha_info->digest[1]; LONG B = sha_info->digest[1];
C = sha_info->digest[2]; LONG C = sha_info->digest[2];
D = sha_info->digest[3]; LONG D = sha_info->digest[3];
E = sha_info->digest[4]; LONG E = sha_info->digest[4];
WP = W; const LONG* WP = W;
#ifdef UNRAVEL #ifdef UNRAVEL
FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1); FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1);
FE(1); FT(1); FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1);
@ -262,17 +261,14 @@ void sha_init(SHA_INFO *sha_info)
void sha_update(SHA_INFO *sha_info, const BYTE *buffer, int count) void sha_update(SHA_INFO *sha_info, const BYTE *buffer, int count)
{ {
int i; const LONG clo = T32(sha_info->count_lo + ((LONG) count << 3));
LONG clo;
clo = T32(sha_info->count_lo + ((LONG) count << 3));
if (clo < sha_info->count_lo) { if (clo < sha_info->count_lo) {
++sha_info->count_hi; ++sha_info->count_hi;
} }
sha_info->count_lo = clo; sha_info->count_lo = clo;
sha_info->count_hi += (LONG) count >> 29; sha_info->count_hi += (LONG) count >> 29;
if (sha_info->local) { if (sha_info->local) {
i = SHA_BLOCKSIZE - sha_info->local; int i = SHA_BLOCKSIZE - sha_info->local;
if (i > count) { if (i > count) {
i = count; i = count;
} }
@ -300,12 +296,9 @@ void sha_update(SHA_INFO *sha_info, const BYTE *buffer, int count)
void sha_final(unsigned char digest[SHA_DIGESTSIZE], SHA_INFO *sha_info) void sha_final(unsigned char digest[SHA_DIGESTSIZE], SHA_INFO *sha_info)
{ {
int count; const LONG lo_bit_count = sha_info->count_lo;
LONG lo_bit_count, hi_bit_count; const LONG hi_bit_count = sha_info->count_hi;
int count = (int) ((lo_bit_count >> 3) & 0x3f);
lo_bit_count = sha_info->count_lo;
hi_bit_count = sha_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f);
((BYTE *) sha_info->data)[count++] = 0x80; ((BYTE *) sha_info->data)[count++] = 0x80;
if (count > SHA_BLOCKSIZE - 8) { if (count > SHA_BLOCKSIZE - 8) {
memset(((BYTE *) sha_info->data) + count, 0, SHA_BLOCKSIZE - count); memset(((BYTE *) sha_info->data) + count, 0, SHA_BLOCKSIZE - count);
@ -362,7 +355,7 @@ void base64(Firebird::string& b64, const BinHash& bin)
{ {
if (i >= 3) if (i >= 3)
{ {
ULONG l = (ULONG(f[0]) << 16) | const ULONG l = (ULONG(f[0]) << 16) |
(ULONG(f[1]) << 8) | f[2]; (ULONG(f[1]) << 8) | f[2];
b64 += conv_bin2ascii(l >> 18); b64 += conv_bin2ascii(l >> 18);
b64 += conv_bin2ascii(l >> 12); b64 += conv_bin2ascii(l >> 12);
@ -372,8 +365,9 @@ void base64(Firebird::string& b64, const BinHash& bin)
else else
{ {
ULONG l = ULONG(f[0]) << 16; ULONG l = ULONG(f[0]) << 16;
if (i == 2) l |= (ULONG(f[1]) << 8); if (i == 2)
b64 += conv_bin2ascii(l >> 18); l |= (ULONG(f[1]) << 8);
b64 += conv_bin2ascii(l >> 18);
b64 += conv_bin2ascii(l >> 12); b64 += conv_bin2ascii(l >> 12);
b64 += (i == 1 ? '=' : conv_bin2ascii(l >> 6)); b64 += (i == 1 ? '=' : conv_bin2ascii(l >> 6));
b64 += '='; b64 += '=';
@ -387,7 +381,7 @@ void Jrd::CryptSupport::hash(Firebird::string& hashValue, const Firebird::string
{ {
SHA_INFO si; SHA_INFO si;
sha_init(&si); sha_init(&si);
sha_update(&si, reinterpret_cast<const unsigned char *>(data.c_str()), data.length()); sha_update(&si, reinterpret_cast<const unsigned char*>(data.c_str()), data.length());
BinHash bh; BinHash bh;
sha_final(bh.getBuffer(SHA_DIGESTSIZE), &si); sha_final(bh.getBuffer(SHA_DIGESTSIZE), &si);
base64(hashValue, bh); base64(hashValue, bh);
@ -400,3 +394,4 @@ void Jrd::CryptSupport::random(Firebird::string& randomValue, size_t length)
base64(randomValue, binRand); base64(randomValue, binRand);
randomValue.resize(length, '$'); randomValue.resize(length, '$');
} }

View File

@ -864,18 +864,16 @@ ISC_STATUS SVC_query2(Service* service,
SCHAR item; SCHAR item;
char buffer[MAXPATHLEN]; char buffer[MAXPATHLEN];
USHORT l, length, version, get_flags; USHORT l, length, version, get_flags;
ISC_STATUS *status;
USHORT timeout;
THREAD_EXIT(); THREAD_EXIT();
/* Setup the status vector */ /* Setup the status vector */
status = tdbb->tdbb_status_vector; ISC_STATUS* status = tdbb->tdbb_status_vector;
*status++ = isc_arg_gds; *status++ = isc_arg_gds;
/* Process the send portion of the query first. */ /* Process the send portion of the query first. */
timeout = 0; USHORT timeout = 0;
const SCHAR* items = send_items; const SCHAR* items = send_items;
const SCHAR* const end_items = items + send_item_length; const SCHAR* const end_items = items + send_item_length;
while (items < end_items && *items != isc_info_end) while (items < end_items && *items != isc_info_end)
@ -957,12 +955,11 @@ ISC_STATUS SVC_query2(Service* service,
case isc_info_svc_svr_db_info: case isc_info_svc_svr_db_info:
{ {
UCHAR dbbuf[1024]; UCHAR dbbuf[1024];
USHORT num_dbs = 0, num = 0; USHORT num_dbs = 0;
USHORT num_att = 0; USHORT num_att = 0;
TEXT *ptr, *ptr2;
*info++ = item; *info++ = item;
ptr = TEXT* const ptr =
JRD_num_attachments(reinterpret_cast<char*>(dbbuf), JRD_num_attachments(reinterpret_cast<char*>(dbbuf),
sizeof(dbbuf), JRD_info_dbnames, sizeof(dbbuf), JRD_info_dbnames,
&num_att, &num_dbs); &num_att, &num_dbs);
@ -979,8 +976,9 @@ ISC_STATUS SVC_query2(Service* service,
ADD_SPB_NUMERIC(info, num_dbs); ADD_SPB_NUMERIC(info, num_dbs);
/* Move db names into the info buffer */ /* Move db names into the info buffer */
if (ptr2 = ptr) { TEXT* ptr2 = ptr;
num = (USHORT) isc_vax_integer(ptr2, sizeof(USHORT)); if (ptr2) {
USHORT num = (USHORT) isc_vax_integer(ptr2, sizeof(USHORT));
fb_assert(num == num_dbs); fb_assert(num == num_dbs);
ptr2 += sizeof(USHORT); ptr2 += sizeof(USHORT);
for (; num; num--) { for (; num; num--) {
@ -990,14 +988,17 @@ ISC_STATUS SVC_query2(Service* service,
if (! if (!
(info = (info =
INF_put_item(isc_spb_dbname, length, ptr2, info, INF_put_item(isc_spb_dbname, length, ptr2, info,
end))) { end)))
{
// CVC: Shouldn't this place try to free ptr
// if it's different than dbbuf, too?
THREAD_ENTER(); THREAD_ENTER();
return 0; return 0;
} }
ptr2 += length; ptr2 += length;
} }
if (ptr != reinterpret_cast < TEXT * >(dbbuf)) if (ptr != reinterpret_cast<TEXT*>(dbbuf))
gds__free(ptr); /* memory has been allocated by gds__free(ptr); /* memory has been allocated by
JRD_num_attachments() */ JRD_num_attachments() */
} }
@ -1157,7 +1158,8 @@ ISC_STATUS SVC_query2(Service* service,
SecurityDatabase::getPath(buffer); SecurityDatabase::getPath(buffer);
if (!(info = INF_put_item(item, strlen(buffer), buffer, if (!(info = INF_put_item(item, strlen(buffer), buffer,
info, end))) { info, end)))
{
THREAD_ENTER(); THREAD_ENTER();
return 0; return 0;
} }
@ -1196,7 +1198,7 @@ ISC_STATUS SVC_query2(Service* service,
THREAD_EXIT(); THREAD_EXIT();
} }
service_get(service, service_get(service,
reinterpret_cast < char *>(service->svc_resp_buf), reinterpret_cast<char*>(service->svc_resp_buf),
l, GET_BINARY, 0, &length); l, GET_BINARY, 0, &length);
service->svc_resp_ptr = service->svc_resp_buf; service->svc_resp_ptr = service->svc_resp_buf;
service->svc_resp_len = l; service->svc_resp_len = l;
@ -1226,8 +1228,7 @@ ISC_STATUS SVC_query2(Service* service,
service_put(service, &item, 1); service_put(service, &item, 1);
service_get(service, &item, 1, GET_BINARY, 0, &length); service_get(service, &item, 1, GET_BINARY, 0, &length);
service_get(service, buffer, 2, GET_BINARY, 0, &length); service_get(service, buffer, 2, GET_BINARY, 0, &length);
l = l = (USHORT) gds__vax_integer(reinterpret_cast<
(USHORT) gds__vax_integer(reinterpret_cast <
UCHAR*>(buffer), 2); UCHAR*>(buffer), 2);
service_get(service, buffer, l, GET_BINARY, 0, &length); service_get(service, buffer, l, GET_BINARY, 0, &length);
if (!(info = INF_put_item(item, length, buffer, info, end))) { if (!(info = INF_put_item(item, length, buffer, info, end))) {
@ -1326,13 +1327,12 @@ void SVC_query(Service* service,
char buffer[256]; char buffer[256];
TEXT PathBuffer[MAXPATHLEN]; TEXT PathBuffer[MAXPATHLEN];
USHORT l, length, version, get_flags; USHORT l, length, version, get_flags;
USHORT timeout;
THREAD_EXIT(); THREAD_EXIT();
/* Process the send portion of the query first. */ /* Process the send portion of the query first. */
timeout = 0; USHORT timeout = 0;
const SCHAR* items = send_items; const SCHAR* items = send_items;
const SCHAR* const end_items = items + send_item_length; const SCHAR* const end_items = items + send_item_length;
while (items < end_items && *items != isc_info_end) while (items < end_items && *items != isc_info_end)
@ -1719,10 +1719,6 @@ void* SVC_start(Service* service, USHORT spb_length, const SCHAR* spb)
* *
**************************************/ **************************************/
#ifndef SUPERSERVER
TEXT service_path[MAXPATHLEN];
#endif
/* NOTE: The parameter RESERVED must not be used /* NOTE: The parameter RESERVED must not be used
* for any purpose as there are networking issues * for any purpose as there are networking issues
* involved (as with any handle that goes over the * involved (as with any handle that goes over the
@ -1871,6 +1867,8 @@ void* SVC_start(Service* service, USHORT spb_length, const SCHAR* spb)
ERR_post(isc_bad_spb_form, 0); ERR_post(isc_bad_spb_form, 0);
#ifndef SUPERSERVER #ifndef SUPERSERVER
TEXT service_path[MAXPATHLEN];
if (serv->serv_executable) { if (serv->serv_executable) {
gds__prefix(service_path, serv->serv_executable); gds__prefix(service_path, serv->serv_executable);
service->svc_flags = SVC_forked; service->svc_flags = SVC_forked;
@ -1974,7 +1972,7 @@ void* SVC_start(Service* service, USHORT spb_length, const SCHAR* spb)
if (serv->serv_thd) { if (serv->serv_thd) {
#pragma FB_COMPILER_MESSAGE("Fix! Probable bug!") #pragma FB_COMPILER_MESSAGE("Fix! Probable bug!")
event_t* evnt_ptr = event_t* evnt_ptr =
reinterpret_cast<event_t*> (&(service->svc_start_event)); reinterpret_cast<event_t*>(&(service->svc_start_event));
THREAD_EXIT(); THREAD_EXIT();
/* create an event for the service. The event will be signaled once the /* create an event for the service. The event will be signaled once the
@ -2045,7 +2043,6 @@ THREAD_ENTRY_DECLARE SVC_read_ib_log(THREAD_ENTRY_PARAM arg)
* log file into the service buffers. * log file into the service buffers.
* *
**************************************/ **************************************/
TEXT name[MAXPATHLEN], buffer[100];
bool svc_started = false; bool svc_started = false;
Service* service = (Service*)arg; Service* service = (Service*)arg;
#ifdef SUPERSERVER #ifdef SUPERSERVER
@ -2053,6 +2050,7 @@ THREAD_ENTRY_DECLARE SVC_read_ib_log(THREAD_ENTRY_PARAM arg)
*status++ = isc_arg_gds; *status++ = isc_arg_gds;
#endif #endif
TEXT name[MAXPATHLEN];
gds__prefix(name, LOGFILE); gds__prefix(name, LOGFILE);
FILE* file = fopen(name, "r"); FILE* file = fopen(name, "r");
if (file != NULL) { if (file != NULL) {
@ -2062,6 +2060,7 @@ THREAD_ENTRY_DECLARE SVC_read_ib_log(THREAD_ENTRY_PARAM arg)
#endif #endif
service->svc_started(); service->svc_started();
svc_started = true; svc_started = true;
TEXT buffer[100];
while (!feof(file) && !ferror(file)) { while (!feof(file) && !ferror(file)) {
fgets(buffer, sizeof(buffer), file); fgets(buffer, sizeof(buffer), file);
#ifdef SUPERSERVER #ifdef SUPERSERVER
@ -2295,13 +2294,11 @@ static void service_fork(TEXT* service_path, Service* service)
the file created. This handle will be used in subsequent the file created. This handle will be used in subsequent
calls to the windows API functions for working with the files calls to the windows API functions for working with the files
*/ */
int tmp;
char *fname;
char tmpPath[MAXPATHLEN]; char tmpPath[MAXPATHLEN];
GetTempPath(MAXPATHLEN, tmpPath); GetTempPath(MAXPATHLEN, tmpPath);
fname = _tempnam(tmpPath, "ibsvc"); const char* fname = _tempnam(tmpPath, "ibsvc");
tmp = int tmp =
_open(fname, _O_RDWR | _O_CREAT | _O_TEMPORARY, _open(fname, _O_RDWR | _O_CREAT | _O_TEMPORARY,
_S_IREAD | _S_IWRITE); _S_IREAD | _S_IWRITE);
my_input = (HANDLE) _get_osfhandle(tmp); my_input = (HANDLE) _get_osfhandle(tmp);
@ -2688,7 +2685,10 @@ static USHORT service_full(Service* service)
* *
**************************************/ **************************************/
if (service_add_one(service_add_one(service->svc_stdout_tail)) == if (service_add_one(service_add_one(service->svc_stdout_tail)) ==
service->svc_stdout_head) return (1); service->svc_stdout_head)
{
return (1);
}
else else
return (0); return (0);
} }
@ -2816,7 +2816,6 @@ static void service_get(Service* service,
* *
**************************************/ **************************************/
int ch = 'Z'; int ch = 'Z';
time_t elapsed_time;
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
struct timeval start_time, end_time; struct timeval start_time, end_time;
@ -2834,10 +2833,10 @@ static void service_get(Service* service,
THREAD_SLEEP(1); THREAD_SLEEP(1);
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
GETTIMEOFDAY(&end_time); GETTIMEOFDAY(&end_time);
elapsed_time = end_time.tv_sec - start_time.tv_sec; const time_t elapsed_time = end_time.tv_sec - start_time.tv_sec;
#else #else
time(&end_time); time(&end_time);
elapsed_time = end_time - start_time; const time_t elapsed_time = end_time - start_time;
#endif #endif
if ((timeout) && (elapsed_time >= timeout)) { if ((timeout) && (elapsed_time >= timeout)) {
service->svc_flags &= SVC_timeout; service->svc_flags &= SVC_timeout;

View File

@ -800,8 +800,6 @@ void ThreadData::start(ThreadEntryPoint* routine,
* *
**************************************/ **************************************/
HANDLE handle;
DWORD thread_id;
int priority; int priority;
switch (priority_arg) { switch (priority_arg) {
@ -838,14 +836,15 @@ void ThreadData::start(ThreadEntryPoint* routine,
* CreateThread() can lead to memory leaks caused by C-runtime library. * CreateThread() can lead to memory leaks caused by C-runtime library.
* Advanced Windows by Richter pg. # 109. */ * Advanced Windows by Richter pg. # 109. */
DWORD thread_id;
unsigned long real_handle = unsigned long real_handle =
_beginthreadex(NULL, 0, THREAD_ENTRYPOINT, THREAD_ARG, CREATE_SUSPENDED, _beginthreadex(NULL, 0, THREAD_ENTRYPOINT, THREAD_ARG, CREATE_SUSPENDED,
reinterpret_cast <unsigned *>(&thread_id)); reinterpret_cast<unsigned*>(&thread_id));
if (!real_handle) if (!real_handle)
{ {
Firebird::system_call_failed::raise("_beginthreadex", GetLastError()); Firebird::system_call_failed::raise("_beginthreadex", GetLastError());
} }
handle = reinterpret_cast<HANDLE>(real_handle); HANDLE handle = reinterpret_cast<HANDLE>(real_handle);
SetThreadPriority(handle, priority); SetThreadPriority(handle, priority);