8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 04:03:04 +01:00

Committed (slightly modified) PR #88 by Dmitry Sibiryakov

This commit is contained in:
Alex Peshkoff 2017-07-01 13:12:09 +03:00
parent 8837ea3d7e
commit 2be6cf316a
4 changed files with 60 additions and 28 deletions

View File

@ -227,6 +227,15 @@ int SecurityDatabaseManagement::release()
}
#define STR_STORE(to, from) fb_utils::copy_terminate(to, from, sizeof(to))
#define STR_VSTORE(to, from) string2vary(&to, from, sizeof(to))
static void string2vary(void* to, Firebird::string& from, size_t to_size)
{
size_t len = MIN(to_size - sizeof(USHORT), from.size());
paramvary* v = reinterpret_cast<paramvary*>(to);
v->vary_length = len;
memcpy(v->vary_string, from.c_str(), len);
}
int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebird::IUser* user,
Firebird::IListUsers* callback)
@ -371,7 +380,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
{
ENC_crypt(encrypted1, sizeof encrypted1, user->password()->get(), LEGACY_PASSWORD_SALT);
LegacyHash::hash(encrypted2, user->userName()->get(), &encrypted1[2]);
STR_STORE(U.PLG$PASSWD, encrypted2.c_str());
STR_VSTORE(U.PLG$PASSWD, encrypted2);
U.PLG$PASSWD.NULL = ISC_FALSE;
}
else
@ -456,7 +465,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
{
ENC_crypt(encrypted1, sizeof encrypted1, user->password()->get(), LEGACY_PASSWORD_SALT);
LegacyHash::hash(encrypted2, user->userName()->get(), &encrypted1[2]);
STR_STORE(U.PLG$PASSWD, encrypted2.c_str());
STR_VSTORE(U.PLG$PASSWD, encrypted2);
U.PLG$PASSWD.NULL = ISC_FALSE;
}
else if (user->password()->specified())

View File

@ -1901,7 +1901,11 @@ static void gen_emodify( const act* action, int column)
align(column);
gen_name(s1, source, true);
gen_name(s2, reference, true);
if (field->fld_dtype > dtype_cstring || (field->fld_sub_type == 1 && field->fld_length == 1))
if (field->fld_dtype == dtype_varying && field->fld_sub_type == dsc_text_type_fixed)
{
fprintf(gpreGlob.out_file, "memcpy (&%s, &%s, %d);", s2, s1, field->fld_length + sizeof(USHORT));
}
else if (field->fld_dtype > dtype_cstring || (field->fld_sub_type == dsc_text_type_fixed && field->fld_length == 1))
{
fprintf(gpreGlob.out_file, "%s = %s;", s2, s1);
}
@ -3717,6 +3721,10 @@ static void make_port(const gpre_port* port, int column)
dtype = DCL_LONG;
break;
case dtype_varying:
fprintf(gpreGlob.out_file, " struct { ISC_USHORT length; ISC_UCHAR data[%d]; } isc_%d;\t/* %s */", field->fld_length, reference->ref_ident, name);
continue;
case dtype_cstring:
case dtype_text:
dtype = "char ";

View File

@ -788,7 +788,7 @@ static void cmp_field( gpre_req* request, const gpre_fld* field,
break;
case dtype_varying:
if (!(field->fld_flags & FLD_charset) && field->fld_ttype)
if (!(field->fld_flags & FLD_charset) && field->fld_ttype >= dsc_text_type_metadata)
{
request->add_byte(blr_varying);
request->add_word(field->fld_length);
@ -1731,17 +1731,20 @@ static gpre_port* make_port( gpre_req* request, ref* reference)
CPR_bugcheck("missing prototype field for value");
if (temp->ref_value && (temp->ref_flags & REF_array_elem))
field = field->fld_array;
if ((field->fld_length & 7) == 0)
FLD_LENGTH len = field->fld_length;
if (field->fld_dtype == dtype_varying)
len += sizeof(USHORT);
if ((len & 7) == 0)
{
temp->ref_next = alignments[2];
alignments[2] = temp;
}
else if ((field->fld_length & 3) == 0)
else if ((len & 3) == 0)
{
temp->ref_next = alignments[1];
alignments[1] = temp;
}
else if ((field->fld_length & 1) == 0)
else if ((len & 1) == 0)
{
temp->ref_next = alignments[0];
alignments[0] = temp;
@ -1774,7 +1777,10 @@ static gpre_port* make_port( gpre_req* request, ref* reference)
#ifdef GPRE_FORTRAN
reference->ref_offset = port->por_length;
#endif
port->por_length += field->fld_length;
FLD_LENGTH len = field->fld_length;
if (field->fld_dtype == dtype_varying)
len += sizeof(USHORT);
port->por_length += len;
}
return port;

View File

@ -878,85 +878,94 @@ USHORT MET_get_dtype(USHORT blr_dtype, USHORT sub_type, USHORT char_length, USHO
{
USHORT dtype;
USHORT l = *length;
USHORT corr_length = *length;
switch (blr_dtype)
{
case blr_varying:
case blr_text:
if (char_length != 0 && sub_type != dsc_text_type_none && sub_type != dsc_text_type_fixed)
l = char_length * 4;
if (char_length != 0 && sub_type >= dsc_text_type_metadata) // subtypes below are single byte characters
corr_length = char_length * 4;
dtype = dtype_text;
if (gpreGlob.sw_cstring && sub_type != dsc_text_type_fixed)
if (sub_type == dsc_text_type_fixed)
{
++l;
if (blr_dtype == blr_varying)
{
dtype = dtype_varying;
// Round up size of field to get right alignment and workaround message length mismatch error
corr_length = (corr_length + 1) & ~1U;
}
}
else if (gpreGlob.sw_cstring)
{
++corr_length;
dtype = dtype_cstring;
}
break;
case blr_cstring:
dtype = dtype_cstring;
if (char_length != 0 && sub_type != dsc_text_type_none && sub_type != dsc_text_type_fixed)
l = char_length * 4;
++l;
if (char_length != 0 && sub_type >= dsc_text_type_metadata) // subtypes below are single byte characters
corr_length = char_length * 4;
++corr_length;
break;
case blr_short:
dtype = dtype_short;
l = sizeof(SSHORT);
corr_length = sizeof(SSHORT);
break;
case blr_long:
dtype = dtype_long;
l = sizeof(SLONG);
corr_length = sizeof(SLONG);
break;
case blr_quad:
dtype = dtype_quad;
l = sizeof(ISC_QUAD);
corr_length = sizeof(ISC_QUAD);
break;
case blr_float:
dtype = dtype_real;
l = sizeof(float);
corr_length = sizeof(float);
break;
case blr_double:
dtype = dtype_double;
l = sizeof(double);
corr_length = sizeof(double);
break;
case blr_blob:
dtype = dtype_blob;
l = sizeof(ISC_QUAD);
corr_length = sizeof(ISC_QUAD);
break;
// Begin sql date/time/timestamp
case blr_sql_date:
dtype = dtype_sql_date;
l = sizeof(ISC_DATE);
corr_length = sizeof(ISC_DATE);
break;
case blr_sql_time:
dtype = dtype_sql_time;
l = sizeof(ISC_TIME);
corr_length = sizeof(ISC_TIME);
break;
case blr_timestamp:
dtype = dtype_timestamp;
l = sizeof(ISC_TIMESTAMP);
corr_length = sizeof(ISC_TIMESTAMP);
break;
// End sql date/time/timestamp
case blr_int64:
dtype = dtype_int64;
l = sizeof(ISC_INT64);
corr_length = sizeof(ISC_INT64);
break;
case blr_bool:
dtype = dtype_boolean;
l = sizeof(UCHAR);
corr_length = sizeof(UCHAR);
break;
default:
@ -964,7 +973,7 @@ USHORT MET_get_dtype(USHORT blr_dtype, USHORT sub_type, USHORT char_length, USHO
return 0; // silence non initialized warning
}
*length = l;
*length = corr_length;
return dtype;
}