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 */
/* Applied Cryptography by Bruce Schneier */
/* 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
@ -71,7 +71,7 @@ void sha_final(unsigned char [SHA_DIGESTSIZE], SHA_INFO *);
*
* 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 */
@ -135,10 +135,9 @@ void sha_final(unsigned char [SHA_DIGESTSIZE], SHA_INFO *);
static void sha_transform(SHA_INFO *sha_info)
{
int i;
BYTE *dp;
LONG T, A, B, C, D, E, W[80], *WP;
LONG T, W[80];
dp = sha_info->data;
const BYTE* dp = sha_info->data;
/*
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);
#endif /* SHA_VERSION */
}
A = sha_info->digest[0];
B = sha_info->digest[1];
C = sha_info->digest[2];
D = sha_info->digest[3];
E = sha_info->digest[4];
WP = W;
LONG A = sha_info->digest[0];
LONG B = sha_info->digest[1];
LONG C = sha_info->digest[2];
LONG D = sha_info->digest[3];
LONG E = sha_info->digest[4];
const LONG* WP = W;
#ifdef UNRAVEL
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);
@ -262,17 +261,14 @@ void sha_init(SHA_INFO *sha_info)
void sha_update(SHA_INFO *sha_info, const BYTE *buffer, int count)
{
int i;
LONG clo;
clo = T32(sha_info->count_lo + ((LONG) count << 3));
const LONG clo = T32(sha_info->count_lo + ((LONG) count << 3));
if (clo < sha_info->count_lo) {
++sha_info->count_hi;
}
sha_info->count_lo = clo;
sha_info->count_hi += (LONG) count >> 29;
if (sha_info->local) {
i = SHA_BLOCKSIZE - sha_info->local;
int i = SHA_BLOCKSIZE - sha_info->local;
if (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)
{
int count;
LONG lo_bit_count, hi_bit_count;
lo_bit_count = sha_info->count_lo;
hi_bit_count = sha_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f);
const LONG lo_bit_count = sha_info->count_lo;
const LONG hi_bit_count = sha_info->count_hi;
int count = (int) ((lo_bit_count >> 3) & 0x3f);
((BYTE *) sha_info->data)[count++] = 0x80;
if (count > SHA_BLOCKSIZE - 8) {
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)
{
ULONG l = (ULONG(f[0]) << 16) |
const ULONG l = (ULONG(f[0]) << 16) |
(ULONG(f[1]) << 8) | f[2];
b64 += conv_bin2ascii(l >> 18);
b64 += conv_bin2ascii(l >> 12);
@ -372,7 +365,8 @@ void base64(Firebird::string& b64, const BinHash& bin)
else
{
ULONG l = ULONG(f[0]) << 16;
if (i == 2) l |= (ULONG(f[1]) << 8);
if (i == 2)
l |= (ULONG(f[1]) << 8);
b64 += conv_bin2ascii(l >> 18);
b64 += conv_bin2ascii(l >> 12);
b64 += (i == 1 ? '=' : conv_bin2ascii(l >> 6));
@ -400,3 +394,4 @@ void Jrd::CryptSupport::random(Firebird::string& randomValue, size_t length)
base64(randomValue, binRand);
randomValue.resize(length, '$');
}

View File

@ -864,18 +864,16 @@ ISC_STATUS SVC_query2(Service* service,
SCHAR item;
char buffer[MAXPATHLEN];
USHORT l, length, version, get_flags;
ISC_STATUS *status;
USHORT timeout;
THREAD_EXIT();
/* Setup the status vector */
status = tdbb->tdbb_status_vector;
ISC_STATUS* status = tdbb->tdbb_status_vector;
*status++ = isc_arg_gds;
/* Process the send portion of the query first. */
timeout = 0;
USHORT timeout = 0;
const SCHAR* items = send_items;
const SCHAR* const end_items = items + send_item_length;
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:
{
UCHAR dbbuf[1024];
USHORT num_dbs = 0, num = 0;
USHORT num_dbs = 0;
USHORT num_att = 0;
TEXT *ptr, *ptr2;
*info++ = item;
ptr =
TEXT* const ptr =
JRD_num_attachments(reinterpret_cast<char*>(dbbuf),
sizeof(dbbuf), JRD_info_dbnames,
&num_att, &num_dbs);
@ -979,8 +976,9 @@ ISC_STATUS SVC_query2(Service* service,
ADD_SPB_NUMERIC(info, num_dbs);
/* Move db names into the info buffer */
if (ptr2 = ptr) {
num = (USHORT) isc_vax_integer(ptr2, sizeof(USHORT));
TEXT* ptr2 = ptr;
if (ptr2) {
USHORT num = (USHORT) isc_vax_integer(ptr2, sizeof(USHORT));
fb_assert(num == num_dbs);
ptr2 += sizeof(USHORT);
for (; num; num--) {
@ -990,7 +988,10 @@ ISC_STATUS SVC_query2(Service* service,
if (!
(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();
return 0;
}
@ -1157,7 +1158,8 @@ ISC_STATUS SVC_query2(Service* service,
SecurityDatabase::getPath(buffer);
if (!(info = INF_put_item(item, strlen(buffer), buffer,
info, end))) {
info, end)))
{
THREAD_ENTER();
return 0;
}
@ -1226,8 +1228,7 @@ ISC_STATUS SVC_query2(Service* service,
service_put(service, &item, 1);
service_get(service, &item, 1, GET_BINARY, 0, &length);
service_get(service, buffer, 2, GET_BINARY, 0, &length);
l =
(USHORT) gds__vax_integer(reinterpret_cast <
l = (USHORT) gds__vax_integer(reinterpret_cast<
UCHAR*>(buffer), 2);
service_get(service, buffer, l, GET_BINARY, 0, &length);
if (!(info = INF_put_item(item, length, buffer, info, end))) {
@ -1326,13 +1327,12 @@ void SVC_query(Service* service,
char buffer[256];
TEXT PathBuffer[MAXPATHLEN];
USHORT l, length, version, get_flags;
USHORT timeout;
THREAD_EXIT();
/* Process the send portion of the query first. */
timeout = 0;
USHORT timeout = 0;
const SCHAR* items = send_items;
const SCHAR* const end_items = items + send_item_length;
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
* for any purpose as there are networking issues
* 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);
#ifndef SUPERSERVER
TEXT service_path[MAXPATHLEN];
if (serv->serv_executable) {
gds__prefix(service_path, serv->serv_executable);
service->svc_flags = SVC_forked;
@ -2045,7 +2043,6 @@ THREAD_ENTRY_DECLARE SVC_read_ib_log(THREAD_ENTRY_PARAM arg)
* log file into the service buffers.
*
**************************************/
TEXT name[MAXPATHLEN], buffer[100];
bool svc_started = false;
Service* service = (Service*)arg;
#ifdef SUPERSERVER
@ -2053,6 +2050,7 @@ THREAD_ENTRY_DECLARE SVC_read_ib_log(THREAD_ENTRY_PARAM arg)
*status++ = isc_arg_gds;
#endif
TEXT name[MAXPATHLEN];
gds__prefix(name, LOGFILE);
FILE* file = fopen(name, "r");
if (file != NULL) {
@ -2062,6 +2060,7 @@ THREAD_ENTRY_DECLARE SVC_read_ib_log(THREAD_ENTRY_PARAM arg)
#endif
service->svc_started();
svc_started = true;
TEXT buffer[100];
while (!feof(file) && !ferror(file)) {
fgets(buffer, sizeof(buffer), file);
#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
calls to the windows API functions for working with the files
*/
int tmp;
char *fname;
char tmpPath[MAXPATHLEN];
GetTempPath(MAXPATHLEN, tmpPath);
fname = _tempnam(tmpPath, "ibsvc");
tmp =
const char* fname = _tempnam(tmpPath, "ibsvc");
int tmp =
_open(fname, _O_RDWR | _O_CREAT | _O_TEMPORARY,
_S_IREAD | _S_IWRITE);
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)) ==
service->svc_stdout_head) return (1);
service->svc_stdout_head)
{
return (1);
}
else
return (0);
}
@ -2816,7 +2816,6 @@ static void service_get(Service* service,
*
**************************************/
int ch = 'Z';
time_t elapsed_time;
#ifdef HAVE_GETTIMEOFDAY
struct timeval start_time, end_time;
@ -2834,10 +2833,10 @@ static void service_get(Service* service,
THREAD_SLEEP(1);
#ifdef HAVE_GETTIMEOFDAY
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
time(&end_time);
elapsed_time = end_time - start_time;
const time_t elapsed_time = end_time - start_time;
#endif
if ((timeout) && (elapsed_time >= timeout)) {
service->svc_flags &= SVC_timeout;

View File

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