From: <ale...@us...> - 2014-11-28 11:58:16
|
Revision: 60302 http://sourceforge.net/p/firebird/code/60302 Author: alexpeshkoff Date: 2014-11-28 11:58:08 +0000 (Fri, 28 Nov 2014) Log Message: ----------- Misc encryption enhancements Modified Paths: -------------- firebird/trunk/src/remote/remote.cpp firebird/trunk/src/remote/remote.h firebird/trunk/src/remote/server/server.cpp Modified: firebird/trunk/src/remote/remote.cpp =================================================================== --- firebird/trunk/src/remote/remote.cpp 2014-11-28 06:28:01 UTC (rev 60301) +++ firebird/trunk/src/remote/remote.cpp 2014-11-28 11:58:08 UTC (rev 60302) @@ -1666,8 +1666,8 @@ signed char wcCompatible[3][3] = { -/* DISABLED ENABLED REQUIRED */ -/* DISABLED */ {0, 0, -1}, -/* ENABLED */ {0, 1, 2}, -/* REQUIRED */ {-1, 2, 2} +/* DISABLED ENABLED REQUIRED */ +/* DISABLED */ {WIRECRYPT_DISABLED, WIRECRYPT_DISABLED, WIRECRYPT_BROKEN}, +/* ENABLED */ {WIRECRYPT_DISABLED, WIRECRYPT_ENABLED, WIRECRYPT_REQUIRED}, +/* REQUIRED */ {WIRECRYPT_BROKEN, WIRECRYPT_REQUIRED, WIRECRYPT_REQUIRED} }; Modified: firebird/trunk/src/remote/remote.h =================================================================== --- firebird/trunk/src/remote/remote.h 2014-11-28 06:28:01 UTC (rev 60301) +++ firebird/trunk/src/remote/remote.h 2014-11-28 11:58:08 UTC (rev 60302) @@ -739,6 +739,10 @@ AuthServerPlugins* plugins; Auth::WriterImplementation authBlockWriter; + // extractNewKeys flags + static const ULONG EXTRACT_PLUGINS_LIST = 0x1; + static const ULONG ONLY_CLEANUP = 0x2; + explicit SrvAuthBlock(rem_port* p_port) : port(p_port), userName(getPool()), pluginName(getPool()), pluginList(getPool()), @@ -771,7 +775,7 @@ void createPluginsItr(); void setDataForPlugin(const p_auth_continue* data); void reset(); - bool extractNewKeys(CSTRING* to, bool flagPlugList = false); + bool extractNewKeys(CSTRING* to, ULONG flags); bool hasDataForPlugin(); // Firebird::IServerBlock implementation @@ -810,6 +814,11 @@ const UCHAR TAG_KEY_PLUGINS = 1; const UCHAR TAG_KNOWN_PLUGINS = 2; +const signed char WIRECRYPT_BROKEN = -1; +const signed char WIRECRYPT_DISABLED = 0; +const signed char WIRECRYPT_ENABLED = 1; +const signed char WIRECRYPT_REQUIRED = 2; + // port_flags const USHORT PORT_symmetric = 0x0001; // Server/client architectures are symmetic const USHORT PORT_async = 0x0002; // Port is asynchronous channel for events @@ -916,11 +925,9 @@ ServerAuthBase* port_srv_auth; SrvAuthBlock* port_srv_auth_block; Firebird::HalfStaticArray<InternalCryptKey*, 2> port_crypt_keys; // available wire crypt keys - bool port_need_disk_crypt; // set when appropriate DPB/SPB item is present - // requires wire crypt active before attachDatabase() bool port_crypt_complete; // wire crypt init is complete one way or another, // up to being turned off in firebird.conf - bool port_required_encryption; // encryption is required on port + signed char port_crypt_level; // encryption level for port Firebird::ObjectsArray<KnownServerKey> port_known_server_keys; // Server sends to client // keys known by it, they are stored here Firebird::IWireCryptPlugin* port_crypt_plugin; // plugin used by port, when not NULL - crypts wire data @@ -966,8 +973,7 @@ port_requests_queued(0), port_xcc(0), port_deferred_packets(0), port_last_object_id(0), port_queue(getPool()), port_qoffset(0), port_srv_auth(NULL), port_srv_auth_block(NULL), - port_crypt_keys(getPool()), port_need_disk_crypt(false), port_crypt_complete(false), - port_required_encryption(true), // safe default + port_crypt_keys(getPool()), port_crypt_complete(false), port_crypt_level(WIRECRYPT_REQUIRED), port_known_server_keys(getPool()), port_crypt_plugin(NULL), port_client_crypt_callback(NULL), port_server_crypt_callback(NULL), port_buffer(FB_NEW(getPool()) UCHAR[rpt]), @@ -991,6 +997,13 @@ const Firebird::RefPtr<Config>& getPortConfig() const; void versionInfo(Firebird::string& version); + bool extractNewKeys(CSTRING* to, bool flagPlugList = false) + { + return port_srv_auth_block->extractNewKeys(to, + (flagPlugList ? SrvAuthBlock::EXTRACT_PLUGINS_LIST : 0) | + (port_crypt_level <= WIRECRYPT_DISABLED ? SrvAuthBlock::ONLY_CLEANUP : 0)); + } + template <typename T> void getHandle(T*& blk, OBJCT id) { Modified: firebird/trunk/src/remote/server/server.cpp =================================================================== --- firebird/trunk/src/remote/server/server.cpp 2014-11-28 06:28:01 UTC (rev 60301) +++ firebird/trunk/src/remote/server/server.cpp 2014-11-28 11:58:08 UTC (rev 60302) @@ -470,14 +470,14 @@ HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: send op_cond_accept\n")); send->p_operation = op_cond_accept; authPort->port_srv_auth_block->extractDataFromPluginTo(&send->p_acpd); - authPort->port_srv_auth_block->extractNewKeys(&send->p_acpd.p_acpt_keys); + authPort->extractNewKeys(&send->p_acpd.p_acpt_keys); } else { HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: send op_cont_auth\n")); send->p_operation = op_cont_auth; authPort->port_srv_auth_block->extractDataFromPluginTo(&send->p_auth_cont); - authPort->port_srv_auth_block->extractNewKeys(&send->p_auth_cont.p_keys); + authPort->extractNewKeys(&send->p_auth_cont.p_keys); } } else @@ -1575,7 +1575,7 @@ { if (port->port_type == rem_port::XNET) // local connection { - port->port_required_encryption = false; + port->port_crypt_level = WIRECRYPT_DISABLED; return false; } @@ -1592,13 +1592,13 @@ } int serverCrypt = port->getPortConfig()->getWireCrypt(WC_SERVER); - if (wcCompatible[clientCrypt][serverCrypt] < 0) + if (wcCompatible[clientCrypt][serverCrypt] == WIRECRYPT_BROKEN) { Arg::Gds(isc_wirecrypt_incompatible).raise(); } - port->port_required_encryption = wcCompatible[clientCrypt][serverCrypt] == 2; - return wcCompatible[clientCrypt][serverCrypt] > 0; + port->port_crypt_level = wcCompatible[clientCrypt][serverCrypt]; + return wcCompatible[clientCrypt][serverCrypt] >= WIRECRYPT_ENABLED; } @@ -1748,9 +1748,9 @@ return true; } - if (port->port_required_encryption) + if (port->port_crypt_level == WIRECRYPT_REQUIRED) { - HANDSHAKE_DEBUG(fprintf(stderr, "port_required_encryption, reset accepted\n")); + HANDSHAKE_DEBUG(fprintf(stderr, "WIRECRYPT_REQUIRED, reset accepted\n")); accepted = false; } } @@ -1858,7 +1858,7 @@ // extractNewKeys() will also send to client list of known plugins if (version >= PROTOCOL_VERSION13 && - port->port_srv_auth_block->extractNewKeys(&send->p_acpd.p_acpt_keys, returnData)) + port->extractNewKeys(&send->p_acpd.p_acpt_keys, returnData)) { returnData = true; } @@ -1883,7 +1883,7 @@ if (useResponse) { CSTRING* const s = &send->p_resp.p_resp_data; - authPort->port_srv_auth_block->extractNewKeys(s); + authPort->extractNewKeys(s); ISC_STATUS sv[] = {1, 0, 0}; authPort->send_response(send, 0, s->cstr_length, sv, false); } @@ -1891,7 +1891,7 @@ { send->p_operation = op_accept_data; CSTRING* const s = &send->p_acpd.p_acpt_keys; - authPort->port_srv_auth_block->extractNewKeys(s); + authPort->extractNewKeys(s); send->p_acpd.p_acpt_authenticated = 1; authPort->send(send); if (send->p_acpt.p_acpt_type & pflag_compress) @@ -2125,7 +2125,7 @@ * **************************************/ WIRECRYPT_DEBUG(fprintf(stderr, "Line encryption %sabled on attach\n", port->port_crypt_complete ? "en" : "dis")); - if (port->port_required_encryption && !port->port_crypt_complete) + if (port->port_crypt_level == WIRECRYPT_REQUIRED && !port->port_crypt_complete) { Arg::Gds(isc_miss_wirecrypt).raise(); } @@ -2213,7 +2213,7 @@ } CSTRING* const s = &send->p_resp.p_resp_data; - authPort->port_srv_auth_block->extractNewKeys(s); + authPort->extractNewKeys(s); authPort->send_response(send, 0, s->cstr_length, &status_vector, false); } @@ -5213,7 +5213,7 @@ static void attach_service(rem_port* port, P_ATCH* attach, PACKET* sendL) { WIRECRYPT_DEBUG(fprintf(stderr, "Line encryption %sabled on attach svc\n", port->port_crypt_complete ? "en" : "dis")); - if (port->port_required_encryption && !port->port_crypt_complete) + if (port->port_crypt_level == WIRECRYPT_REQUIRED && !port->port_crypt_complete) { Arg::Gds(isc_miss_wirecrypt).raise(); } @@ -5236,7 +5236,7 @@ void ServiceAttachAuth::accept(PACKET* sendL, Auth::WriterImplementation* authBlock) { authBlock->store(pb, isc_spb_auth_block); - authPort->port_srv_auth_block->extractNewKeys(&sendL->p_resp.p_resp_data); + authPort->extractNewKeys(&sendL->p_resp.p_resp_data); authPort->service_attach(managerName.c_str(), pb, sendL); } @@ -6410,23 +6410,27 @@ plugins = NULL; } -bool SrvAuthBlock::extractNewKeys(CSTRING* to, bool flagPluginsList) +bool SrvAuthBlock::extractNewKeys(CSTRING* to, ULONG flags) { lastExtractedKeys.reset(); - for (unsigned n = 0; n < newKeys.getCount(); ++n) + + if (!(flags & ONLY_CLEANUP)) { - const PathName& t = newKeys[n]; - PathName plugins = knownCryptKeyTypes()[t]; - if (plugins.hasData()) + for (unsigned n = 0; n < newKeys.getCount(); ++n) { - lastExtractedKeys.insertPath(TAG_KEY_TYPE, t); - lastExtractedKeys.insertPath(TAG_KEY_PLUGINS, plugins); + const PathName& t = newKeys[n]; + PathName plugins = knownCryptKeyTypes()[t]; + if (plugins.hasData()) + { + lastExtractedKeys.insertPath(TAG_KEY_TYPE, t); + lastExtractedKeys.insertPath(TAG_KEY_PLUGINS, plugins); + } } - } - if (flagPluginsList && dataFromPlugin.getCount() == 0) - { - lastExtractedKeys.insertPath(TAG_KNOWN_PLUGINS, pluginList); + if ((flags & EXTRACT_PLUGINS_LIST) && (dataFromPlugin.getCount() == 0)) + { + lastExtractedKeys.insertPath(TAG_KNOWN_PLUGINS, pluginList); + } } to->cstr_length = (ULONG) lastExtractedKeys.getBufferLength(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2014-11-28 13:46:32
|
Revision: 60303 http://sourceforge.net/p/firebird/code/60303 Author: alexpeshkoff Date: 2014-11-28 13:46:29 +0000 (Fri, 28 Nov 2014) Log Message: ----------- Establish uncompressed connection in case of missing zlib Modified Paths: -------------- firebird/trunk/src/remote/inet.cpp firebird/trunk/src/remote/remote.cpp firebird/trunk/src/remote/remote.h Modified: firebird/trunk/src/remote/inet.cpp =================================================================== --- firebird/trunk/src/remote/inet.cpp 2014-11-28 11:58:08 UTC (rev 60302) +++ firebird/trunk/src/remote/inet.cpp 2014-11-28 13:46:29 UTC (rev 60303) @@ -614,8 +614,11 @@ for (size_t i = 0; i < cnct->p_cnct_count; i++) { cnct->p_cnct_versions[i] = protocols_to_try[i]; - if (compression && cnct->p_cnct_versions[i].p_cnct_version >= PROTOCOL_VERSION13) + if (compression && cnct->p_cnct_versions[i].p_cnct_version >= PROTOCOL_VERSION13 && + rem_port::checkCompression()) + { cnct->p_cnct_versions[i].p_cnct_max_type |= pflag_compress; + } } rem_port* port = inet_try_connect(packet, rdb, file_name, node_name, dpb, config, ref_db_name); Modified: firebird/trunk/src/remote/remote.cpp =================================================================== --- firebird/trunk/src/remote/remote.cpp 2014-11-28 11:58:08 UTC (rev 60302) +++ firebird/trunk/src/remote/remote.cpp 2014-11-28 13:46:29 UTC (rev 60303) @@ -1389,8 +1389,6 @@ z.reset(ModuleLoader::fixAndLoadModule(name)); if (z) symbols(); - if (!z) - (Firebird::Arg::Gds(isc_random) << "Error loading zlib").raise(); } int ZEXPORT (*deflateInit_)(z_stream* strm, int level, const char *version, int stream_size); @@ -1620,10 +1618,19 @@ #endif } +bool rem_port::checkCompression() +{ +#ifdef WIRE_COMPRESS_SUPPORT + return zlib(); +#else + return false; +#endif +} + void rem_port::initCompression() { #ifdef WIRE_COMPRESS_SUPPORT - if (port_protocol >= PROTOCOL_VERSION13 && !port_compressed) + if (port_protocol >= PROTOCOL_VERSION13 && !port_compressed && zlib()) { port_send_stream.zalloc = allocFunc; port_send_stream.zfree = freeFunc; Modified: firebird/trunk/src/remote/remote.h =================================================================== --- firebird/trunk/src/remote/remote.h 2014-11-28 11:58:08 UTC (rev 60302) +++ firebird/trunk/src/remote/remote.h 2014-11-28 13:46:29 UTC (rev 60303) @@ -992,6 +992,7 @@ public: void initCompression(); + static bool checkCompression(); void linkParent(rem_port* const parent); void unlinkParent(); const Firebird::RefPtr<Config>& getPortConfig() const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2014-12-03 14:27:14
|
Revision: 60334 http://sourceforge.net/p/firebird/code/60334 Author: alexpeshkoff Date: 2014-12-03 14:27:11 +0000 (Wed, 03 Dec 2014) Log Message: ----------- Fixed CORE-4471: Legacy_Auth plugin does not connect from FB3 to FB2.5 server when tried after Win_Sspi Modified Paths: -------------- firebird/trunk/src/remote/client/interface.cpp firebird/trunk/src/remote/remot_proto.h firebird/trunk/src/remote/remote.cpp Modified: firebird/trunk/src/remote/client/interface.cpp =================================================================== --- firebird/trunk/src/remote/client/interface.cpp 2014-12-03 14:19:43 UTC (rev 60333) +++ firebird/trunk/src/remote/client/interface.cpp 2014-12-03 14:27:11 UTC (rev 60334) @@ -6116,6 +6116,16 @@ response->p_resp_data = temp; } +static bool useLegacyAuth(const char* nm, int protocol, ClumpletWriter& dpb) +{ + LegacyPlugin legacyAuth = REMOTE_legacy_auth(nm, protocol); + if (!legacyAuth) + return false; + + int requestedAuth = dpb.find(isc_dpb_user_name) ? PLUGIN_LEGACY : PLUGIN_TRUSTED; + return legacyAuth == requestedAuth; +} + // Let plugins try to add data to DPB in order to avoid extra network roundtrip static void authFillParametersBlock(ClntAuthBlock& cBlock, ClumpletWriter& dpb, const ParametersSet* tags, rem_port* port) @@ -6130,7 +6140,7 @@ for (; cBlock.plugins.hasData(); cBlock.plugins.next()) { if (port->port_protocol >= PROTOCOL_VERSION13 || - REMOTE_legacy_auth(cBlock.plugins.name(), port->port_protocol)) + useLegacyAuth(cBlock.plugins.name(), port->port_protocol, dpb)) { // OK to use plugin cBlock.resetDataFromPlugin(); Modified: firebird/trunk/src/remote/remot_proto.h =================================================================== --- firebird/trunk/src/remote/remot_proto.h 2014-12-03 14:19:43 UTC (rev 60333) +++ firebird/trunk/src/remote/remot_proto.h 2014-12-03 14:27:11 UTC (rev 60334) @@ -47,6 +47,7 @@ typedef bool PacketReceive(rem_port*, UCHAR*, SSHORT, SSHORT*); typedef bool PacketSend(rem_port*, const SCHAR*, SSHORT); typedef bool ProtoWrite(XDR*); +enum LegacyPlugin {PLUGIN_NEW = 0, PLUGIN_LEGACY, PLUGIN_TRUSTED}; void REMOTE_cleanup_transaction (struct Rtr *); USHORT REMOTE_compute_batch_size (rem_port*, USHORT, P_OP, const rem_fmt*); @@ -60,7 +61,7 @@ void REMOTE_reset_statement (struct Rsr *); void REMOTE_save_status_strings (ISC_STATUS *); bool_t REMOTE_getbytes (XDR*, SCHAR*, u_int); -bool REMOTE_legacy_auth(const char* nm, int protocol); +LegacyPlugin REMOTE_legacy_auth(const char* nm, int protocol); Firebird::RefPtr<Config> REMOTE_get_config(const Firebird::PathName* dbName, const Firebird::string* dpb_config = NULL); void REMOTE_parseList(Remote::ParsedList&, Firebird::PathName); Modified: firebird/trunk/src/remote/remote.cpp =================================================================== --- firebird/trunk/src/remote/remote.cpp 2014-12-03 14:19:43 UTC (rev 60333) +++ firebird/trunk/src/remote/remote.cpp 2014-12-03 14:27:11 UTC (rev 60334) @@ -884,22 +884,22 @@ return id; } -bool REMOTE_legacy_auth(const char* nm, int p) +LegacyPlugin REMOTE_legacy_auth(const char* nm, int p) { const char* legacyTrusted = "WIN_SSPI"; if (fb_utils::stricmp(legacyTrusted, nm) == 0 && (p == PROTOCOL_VERSION11 || p == PROTOCOL_VERSION12)) { - return true; + return PLUGIN_TRUSTED; } const char* legacyAuth = "LEGACY_AUTH"; if (fb_utils::stricmp(legacyAuth, nm) == 0 && p < PROTOCOL_VERSION13) { - return true; + return PLUGIN_LEGACY; } - return false; + return PLUGIN_NEW; } Firebird::PathName ClntAuthBlock::getPluginName() @@ -1183,6 +1183,8 @@ return; } + HANDSHAKE_DEBUG(fprintf(stderr, "Raising exception %d in checkResponse\n", vector[1] ? vector[1] : isc_net_read_err)); + if (!vector[1]) { Firebird::Arg::Gds(isc_net_read_err).raise(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2014-12-22 08:52:03
|
Revision: 60408 http://sourceforge.net/p/firebird/code/60408 Author: dimitr Date: 2014-12-22 08:51:56 +0000 (Mon, 22 Dec 2014) Log Message: ----------- Patches by Alexey Pavlov. Modified Paths: -------------- firebird/trunk/src/remote/inet.cpp firebird/trunk/src/remote/server/os/win32/srvr_w32.cpp Modified: firebird/trunk/src/remote/inet.cpp =================================================================== --- firebird/trunk/src/remote/inet.cpp 2014-12-22 00:15:05 UTC (rev 60407) +++ firebird/trunk/src/remote/inet.cpp 2014-12-22 08:51:56 UTC (rev 60408) @@ -1787,7 +1787,7 @@ THREAD_ENTRY_DECLARE forkThread(THREAD_ENTRY_PARAM arg) { - const USHORT flag = (USHORT) arg; + const USHORT flag = (USHORT)(U_IPTR) arg; while (!INET_shutting_down) { Modified: firebird/trunk/src/remote/server/os/win32/srvr_w32.cpp =================================================================== --- firebird/trunk/src/remote/server/os/win32/srvr_w32.cpp 2014-12-22 00:15:05 UTC (rev 60407) +++ firebird/trunk/src/remote/server/os/win32/srvr_w32.cpp 2014-12-22 08:51:56 UTC (rev 60408) @@ -295,7 +295,7 @@ else if (server_flag & SRVR_wnet) port = WNET_reconnect(connection_handle); else if (server_flag & SRVR_xnet) - port = XNET_reconnect((ULONG) connection_handle); + port = XNET_reconnect((ULONG_PTR) connection_handle); if (port) service_connection(port); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2014-12-29 16:15:53
|
Revision: 60448 http://sourceforge.net/p/firebird/code/60448 Author: alexpeshkoff Date: 2014-12-29 16:15:49 +0000 (Mon, 29 Dec 2014) Log Message: ----------- Cleanup - remove debris of pre-firebird authentication Modified Paths: -------------- firebird/trunk/src/remote/SockAddr.h firebird/trunk/src/remote/inet.cpp Modified: firebird/trunk/src/remote/SockAddr.h =================================================================== --- firebird/trunk/src/remote/SockAddr.h 2014-12-29 15:48:26 UTC (rev 60447) +++ firebird/trunk/src/remote/SockAddr.h 2014-12-29 16:15:49 UTC (rev 60448) @@ -68,7 +68,6 @@ unsigned length() const { return len; } unsigned short family() const; unsigned short port() const; - bool isLocalhost() const; void setPort(unsigned short x); int connect(SOCKET s) const; int accept(SOCKET s); @@ -169,29 +168,6 @@ } -inline bool SockAddr::isLocalhost() const -{ - const struct sockaddr* sa = (const struct sockaddr*) data; - - switch(sa->sa_family) - { - case AF_INET: - { - const struct sockaddr_in* sa4 = (const struct sockaddr_in*) data; - return ((ntohl(sa4->sin_addr.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET); - } - - case AF_INET6: - { - const struct sockaddr_in6* sa6 = (const struct sockaddr_in6*) data; - return (memcmp(&sa6->sin6_addr, &in6addr_loopback, sizeof(in6_addr)) == 0); - } - } - - return 0; // exception? -} - - // if address is embedded IPv4, convert it to normal IPv4 inline void SockAddr::unmapV4() { Modified: firebird/trunk/src/remote/inet.cpp =================================================================== --- firebird/trunk/src/remote/inet.cpp 2014-12-29 15:48:26 UTC (rev 60447) +++ firebird/trunk/src/remote/inet.cpp 2014-12-29 16:15:49 UTC (rev 60448) @@ -1142,7 +1142,6 @@ cnct->p_cnct_user_id.cstr_address, cnct->p_cnct_user_id.cstr_length); - bool user_verification = false; for (id.rewind(); !id.isEof(); id.moveNext()) { switch (id.getClumpTag()) @@ -1155,28 +1154,12 @@ id.getString(host_name); break; - // this case indicates that the client has requested that - // we force the user name/password to be verified against - // the security database - case CNCT_user_verification: - user_verification = true; - break; - default: break; } } #ifndef WIN_NT - // See if user exists. If not, reject connection - if (!user_verification) - { - if (!check_host(port)) - { - return false; - } - } - { // scope // If the environment variable ISC_INET_SERVER_HOME is set, // change the home directory to the specified directory. @@ -1528,28 +1511,7 @@ return new_port; } -#ifndef WIN_NT -static bool check_host(rem_port* port) -{ -/************************************** - * - * c h e c k _ h o s t ( n o n - W i n d o w s ) - * - ************************************** - * - * Functional description - * Check the host on the other end of the socket to see if it's localhost - * - **************************************/ - SockAddr address; - if (address.getpeername(port->port_handle) < 0) - return false; - - return address.isLocalhost(); -} -#endif // WIN_NT - #if !(defined WIN_NT) static THREAD_ENTRY_DECLARE waitThread(THREAD_ENTRY_PARAM) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2015-01-05 16:08:23
|
Revision: 60472 http://sourceforge.net/p/firebird/code/60472 Author: dimitr Date: 2015-01-05 16:08:21 +0000 (Mon, 05 Jan 2015) Log Message: ----------- Slightly refactored the BLR parser routines to avoid crazy error reporting and protect against NULL pointer dereference. The error handling still sucks, but it was the case before me ;-) Modified Paths: -------------- firebird/trunk/src/remote/client/interface.cpp firebird/trunk/src/remote/parse_proto.h firebird/trunk/src/remote/parser.cpp firebird/trunk/src/remote/protocol.cpp Modified: firebird/trunk/src/remote/client/interface.cpp =================================================================== --- firebird/trunk/src/remote/client/interface.cpp 2015-01-03 09:11:24 UTC (rev 60471) +++ firebird/trunk/src/remote/client/interface.cpp 2015-01-05 16:08:21 UTC (rev 60472) @@ -1203,9 +1203,8 @@ RMessage* message = PARSE_messages(blr, blr_length); USHORT max_msg = 0; - for (next = message; next; next = next->msg_next) { + for (next = message; next; next = next->msg_next) max_msg = MAX(max_msg, next->msg_number); - } // Allocate request block Rrq* request = new Rrq(max_msg + 1); @@ -1737,14 +1736,7 @@ // Parse the blr describing the message, if there is any. if (in_blr_length) - { - RMessage* message = PARSE_messages(in_blr, in_blr_length); - if (message != (RMessage*) - 1) - { - statement->rsr_bind_format = (rem_fmt*) message->msg_address; - delete message; - } - } + statement->rsr_bind_format = PARSE_msg_format(in_blr, in_blr_length); // Parse the blr describing the output message. This is not the fetch // message! That comes later. @@ -1754,12 +1746,7 @@ if (!port->port_statement) port->port_statement = new Rsr; - RMessage* message = PARSE_messages(out_blr, out_blr_length); - if (message != (RMessage*) - 1) - { - port->port_statement->rsr_select_format = (rem_fmt*) message->msg_address; - delete message; - } + port->port_statement->rsr_select_format = PARSE_msg_format(out_blr, out_blr_length); if (!port->port_statement->rsr_buffer) { @@ -1932,14 +1919,7 @@ // Parse the blr describing the message, if there is any. if (in_blr_length) - { - RMessage* message = PARSE_messages(in_blr, in_blr_length); - if (message != (RMessage*) -1) - { - statement->rsr_bind_format = (rem_fmt*) message->msg_address; - delete message; - } - } + statement->rsr_bind_format = PARSE_msg_format(in_blr, in_blr_length); RMessage* message = NULL; if (!statement->rsr_buffer) @@ -2113,23 +2093,10 @@ if (in_msg_length || out_msg_length) { if (in_blr_length) - { - RMessage* message = PARSE_messages(in_blr, in_blr_length); - if (message != (RMessage*) - 1) - { - statement->rsr_bind_format = (rem_fmt*) message->msg_address; - delete message; - } - } + statement->rsr_bind_format = PARSE_msg_format(in_blr, in_blr_length); + if (out_blr_length) - { - RMessage* message = PARSE_messages(out_blr, out_blr_length); - if (message != (RMessage*) - 1) - { - statement->rsr_select_format = (rem_fmt*) message->msg_address; - delete message; - } - } + statement->rsr_select_format = PARSE_msg_format(out_blr, out_blr_length); } RMessage* message = 0; @@ -2830,14 +2797,9 @@ { delete statement->rsr_user_select_format; } - RMessage* message = PARSE_messages(blr, blr_length); - if (message != (RMessage*) - 1) - { - statement->rsr_user_select_format = (rem_fmt*) message->msg_address; - delete message; - } - else - statement->rsr_user_select_format = NULL; + + statement->rsr_user_select_format = PARSE_msg_format(blr, blr_length); + if (statement->rsr_flags.test(Rsr::FETCHED)) blr_length = 0; else @@ -5034,36 +4996,31 @@ procedure->rpr_out_format = NULL; RMessage* message = PARSE_messages(blr, blr_length); - if (message != (RMessage*) - 1) + while (message) { - while (message) + switch (message->msg_number) { - switch (message->msg_number) - { - case 0: - procedure->rpr_in_msg = message; - procedure->rpr_in_format = (rem_fmt*) message->msg_address; - message->msg_address = const_cast<unsigned char*>(in_msg); - message = message->msg_next; - procedure->rpr_in_msg->msg_next = NULL; - break; - case 1: - procedure->rpr_out_msg = message; - procedure->rpr_out_format = (rem_fmt*) message->msg_address; - message->msg_address = out_msg; - message = message->msg_next; - procedure->rpr_out_msg->msg_next = NULL; - break; - default: - RMessage* temp = message; - message = message->msg_next; - delete temp; - break; - } + case 0: + procedure->rpr_in_msg = message; + procedure->rpr_in_format = (rem_fmt*) message->msg_address; + message->msg_address = const_cast<unsigned char*>(in_msg); + message = message->msg_next; + procedure->rpr_in_msg->msg_next = NULL; + break; + case 1: + procedure->rpr_out_msg = message; + procedure->rpr_out_format = (rem_fmt*) message->msg_address; + message->msg_address = out_msg; + message = message->msg_next; + procedure->rpr_out_msg->msg_next = NULL; + break; + default: + RMessage* temp = message; + message = message->msg_next; + delete temp; + break; } } - //else - // error PACKET* packet = &rdb->rdb_packet; Modified: firebird/trunk/src/remote/parse_proto.h =================================================================== --- firebird/trunk/src/remote/parse_proto.h 2015-01-03 09:11:24 UTC (rev 60471) +++ firebird/trunk/src/remote/parse_proto.h 2015-01-05 16:08:21 UTC (rev 60472) @@ -25,5 +25,6 @@ #define REMOTE_PARSE_PROTO_H struct RMessage* PARSE_messages(const UCHAR*, size_t); +struct rem_fmt* PARSE_msg_format(const UCHAR*, size_t); #endif // REMOTE_PARSE_PROTO_H Modified: firebird/trunk/src/remote/parser.cpp =================================================================== --- firebird/trunk/src/remote/parser.cpp 2015-01-03 09:11:24 UTC (rev 60471) +++ firebird/trunk/src/remote/parser.cpp 2015-01-05 16:08:21 UTC (rev 60472) @@ -36,7 +36,7 @@ #endif -static RMessage* parse_error(rem_fmt* format, RMessage* mesage); +static rem_fmt* parse_format(const UCHAR*& blr, size_t& blr_length); RMessage* PARSE_messages(const UCHAR* blr, size_t blr_length) @@ -49,252 +49,313 @@ * * Functional description * Parse the messages of a blr request. For each message, allocate - * a message (msg) and a format (fmt) block. Return the number of - * messages found. If an error occurs, return -1; + * a message (msg) and a format (fmt) block. * **************************************/ - if (blr_length < 2) - return (RMessage*) -1; - blr_length -= 2; + if (blr_length < 3) + return NULL; + blr_length -= 3; const SSHORT version = *blr++; if (version != blr_version4 && version != blr_version5) - return (RMessage*) -1; + return NULL; if (*blr++ != blr_begin) - return 0; + return NULL; RMessage* message = NULL; ULONG net_length = 0; + bool error = false; + while (*blr++ == blr_message) { - if (blr_length < 4) - return parse_error(0, message); - blr_length -= 4; + if (blr_length-- == 0) + { + error = true; + break; + } const USHORT msg_number = *blr++; - USHORT count = *blr++; - count += (*blr++) << 8; - rem_fmt* const format = new rem_fmt(count); -#ifdef DEBUG_REMOTE_MEMORY - printf("PARSE_messages allocate format %x\n", format); -#endif - ULONG offset = 0; - for (dsc* desc = format->fmt_desc.begin(); count; --count, ++desc) + + rem_fmt* const format = parse_format(blr, blr_length); + if (!format) { - if (blr_length-- == 0) - return parse_error(format, message); + error = true; + break; + } - USHORT align = 4; - switch (*blr++) - { - case blr_text: - if (blr_length < 2) - return parse_error(format, message); - blr_length -= 2; - desc->dsc_dtype = dtype_text; - desc->dsc_length = *blr++; - desc->dsc_length += (*blr++) << 8; - align = type_alignments[dtype_text]; - break; + RMessage* next = new RMessage(format->fmt_length); + next->msg_next = message; + message = next; + message->msg_address = reinterpret_cast<UCHAR*>(format); + message->msg_number = msg_number; - case blr_varying: - if (blr_length < 2) - return parse_error(format, message); - blr_length -= 2; - desc->dsc_dtype = dtype_varying; - desc->dsc_length = *blr++ + sizeof(SSHORT); - desc->dsc_length += (*blr++) << 8; - align = type_alignments[dtype_varying]; - break; + if (blr_length-- == 0) + { + error = true; + break; + } + } - case blr_cstring: - if (blr_length < 2) - return parse_error(format, message); - blr_length -= 2; - desc->dsc_dtype = dtype_cstring; - desc->dsc_length = *blr++; - desc->dsc_length += (*blr++) << 8; - align = type_alignments[dtype_cstring]; - break; + if (error) + { + for (RMessage* next = message; next; next = message) + { + message = message->msg_next; + delete next->msg_address; + delete next; + } - // Parse the tagged blr types correctly + return NULL; + } - case blr_text2: - if (blr_length < 4) - return parse_error(format, message); - blr_length -= 4; - desc->dsc_dtype = dtype_text; - desc->dsc_scale = *blr++; - desc->dsc_scale += (*blr++) << 8; - desc->dsc_length = *blr++; - desc->dsc_length += (*blr++) << 8; - align = type_alignments[dtype_text]; - break; + return message; +} - case blr_varying2: - if (blr_length < 4) - return parse_error(format, message); - blr_length -= 4; - desc->dsc_dtype = dtype_varying; - desc->dsc_scale = *blr++; - desc->dsc_scale += (*blr++) << 8; - desc->dsc_length = *blr++ + sizeof(SSHORT); - desc->dsc_length += (*blr++) << 8; - align = type_alignments[dtype_varying]; - break; - case blr_cstring2: - if (blr_length < 4) - return parse_error(format, message); - blr_length -= 4; - desc->dsc_dtype = dtype_cstring; - desc->dsc_scale = *blr++; - desc->dsc_scale += (*blr++) << 8; - desc->dsc_length = *blr++; - desc->dsc_length += (*blr++) << 8; - align = type_alignments[dtype_cstring]; - break; +rem_fmt* PARSE_msg_format(const UCHAR* blr, size_t blr_length) +{ +/************************************** + * + * P A R S E _ m s g _ f o r m a t + * + ************************************** + * + * Functional description + * Parse the message of a blr request and return its format. + * + **************************************/ - case blr_short: - if (blr_length-- == 0) - return parse_error(format, message); - desc->dsc_dtype = dtype_short; - desc->dsc_length = sizeof(SSHORT); - desc->dsc_scale = *blr++; - align = type_alignments[dtype_short]; - break; + if (blr_length < 4) + return NULL; + blr_length -= 4; - case blr_long: - if (blr_length-- == 0) - return parse_error(format, message); - desc->dsc_dtype = dtype_long; - desc->dsc_length = sizeof(SLONG); - desc->dsc_scale = *blr++; - align = type_alignments[dtype_long]; - break; + const SSHORT version = *blr++; + if (version != blr_version4 && version != blr_version5) + return NULL; - case blr_int64: - if (blr_length-- == 0) - return parse_error(format, message); - desc->dsc_dtype = dtype_int64; - desc->dsc_length = sizeof(SINT64); - desc->dsc_scale = *blr++; - align = type_alignments[dtype_int64]; - break; + if (*blr++ != blr_begin) + return NULL; - case blr_quad: - if (blr_length-- == 0) - return parse_error(format, message); - desc->dsc_dtype = dtype_quad; - desc->dsc_length = sizeof(SLONG) * 2; - desc->dsc_scale = *blr++; - align = type_alignments[dtype_quad]; - break; + if (*blr++ != blr_message) + return NULL; - case blr_float: - desc->dsc_dtype = dtype_real; - desc->dsc_length = sizeof(float); - align = type_alignments[dtype_real]; - break; + blr++; // skip message number - case blr_double: - case blr_d_float: - desc->dsc_dtype = dtype_double; - desc->dsc_length = sizeof(double); - align = type_alignments[dtype_double]; - break; + return parse_format(blr, blr_length); +} - // this case cannot occur as switch paramater is char and blr_blob - // is 261. blob_ids are actually passed around as blr_quad. +static rem_fmt* parse_format(const UCHAR*& blr, size_t& blr_length) +{ + if (blr_length < 2) + return NULL; + blr_length -= 2; - //case blr_blob: - // desc->dsc_dtype = dtype_blob; - // desc->dsc_length = sizeof (SLONG) * 2; - // align = type_alignments [dtype_blob]; - // break; + USHORT count = *blr++; + count += (*blr++) << 8; - case blr_blob2: - { - if (blr_length < 4) - return parse_error(format, message); - blr_length -= 4; - desc->dsc_dtype = dtype_blob; - desc->dsc_length = sizeof(SLONG) * 2; - desc->dsc_sub_type = *blr++; - desc->dsc_sub_type += (*blr++) << 8; + Firebird::AutoPtr<rem_fmt> format(new rem_fmt(count)); - USHORT textType = *blr++; - textType += (*blr++) << 8; - desc->setTextType(textType); + ULONG net_length = 0; + ULONG offset = 0; - align = type_alignments[dtype_blob]; - } - break; + for (dsc* desc = format->fmt_desc.begin(); count; --count, ++desc) + { + if (blr_length-- == 0) + return NULL; - case blr_timestamp: - desc->dsc_dtype = dtype_timestamp; + USHORT align = 4; + switch (*blr++) + { + case blr_text: + if (blr_length < 2) + return NULL; + blr_length -= 2; + desc->dsc_dtype = dtype_text; + desc->dsc_length = *blr++; + desc->dsc_length += (*blr++) << 8; + align = type_alignments[dtype_text]; + break; + + case blr_varying: + if (blr_length < 2) + return NULL; + blr_length -= 2; + desc->dsc_dtype = dtype_varying; + desc->dsc_length = *blr++ + sizeof(SSHORT); + desc->dsc_length += (*blr++) << 8; + align = type_alignments[dtype_varying]; + break; + + case blr_cstring: + if (blr_length < 2) + return NULL; + blr_length -= 2; + desc->dsc_dtype = dtype_cstring; + desc->dsc_length = *blr++; + desc->dsc_length += (*blr++) << 8; + align = type_alignments[dtype_cstring]; + break; + + // Parse the tagged blr types correctly + + case blr_text2: + if (blr_length < 4) + return NULL; + blr_length -= 4; + desc->dsc_dtype = dtype_text; + desc->dsc_scale = *blr++; + desc->dsc_scale += (*blr++) << 8; + desc->dsc_length = *blr++; + desc->dsc_length += (*blr++) << 8; + align = type_alignments[dtype_text]; + break; + + case blr_varying2: + if (blr_length < 4) + return NULL; + blr_length -= 4; + desc->dsc_dtype = dtype_varying; + desc->dsc_scale = *blr++; + desc->dsc_scale += (*blr++) << 8; + desc->dsc_length = *blr++ + sizeof(SSHORT); + desc->dsc_length += (*blr++) << 8; + align = type_alignments[dtype_varying]; + break; + + case blr_cstring2: + if (blr_length < 4) + return NULL; + blr_length -= 4; + desc->dsc_dtype = dtype_cstring; + desc->dsc_scale = *blr++; + desc->dsc_scale += (*blr++) << 8; + desc->dsc_length = *blr++; + desc->dsc_length += (*blr++) << 8; + align = type_alignments[dtype_cstring]; + break; + + case blr_short: + if (blr_length-- == 0) + return NULL; + desc->dsc_dtype = dtype_short; + desc->dsc_length = sizeof(SSHORT); + desc->dsc_scale = *blr++; + align = type_alignments[dtype_short]; + break; + + case blr_long: + if (blr_length-- == 0) + return NULL; + desc->dsc_dtype = dtype_long; + desc->dsc_length = sizeof(SLONG); + desc->dsc_scale = *blr++; + align = type_alignments[dtype_long]; + break; + + case blr_int64: + if (blr_length-- == 0) + return NULL; + desc->dsc_dtype = dtype_int64; + desc->dsc_length = sizeof(SINT64); + desc->dsc_scale = *blr++; + align = type_alignments[dtype_int64]; + break; + + case blr_quad: + if (blr_length-- == 0) + return NULL; + desc->dsc_dtype = dtype_quad; + desc->dsc_length = sizeof(SLONG) * 2; + desc->dsc_scale = *blr++; + align = type_alignments[dtype_quad]; + break; + + case blr_float: + desc->dsc_dtype = dtype_real; + desc->dsc_length = sizeof(float); + align = type_alignments[dtype_real]; + break; + + case blr_double: + case blr_d_float: + desc->dsc_dtype = dtype_double; + desc->dsc_length = sizeof(double); + align = type_alignments[dtype_double]; + break; + + // this case cannot occur as switch paramater is char and blr_blob + // is 261. blob_ids are actually passed around as blr_quad. + + //case blr_blob: + // desc->dsc_dtype = dtype_blob; + // desc->dsc_length = sizeof (SLONG) * 2; + // align = type_alignments [dtype_blob]; + // break; + + case blr_blob2: + { + if (blr_length < 4) + return NULL; + blr_length -= 4; + desc->dsc_dtype = dtype_blob; desc->dsc_length = sizeof(SLONG) * 2; - align = type_alignments[dtype_timestamp]; - break; + desc->dsc_sub_type = *blr++; + desc->dsc_sub_type += (*blr++) << 8; - case blr_sql_date: - desc->dsc_dtype = dtype_sql_date; - desc->dsc_length = sizeof(SLONG); - align = type_alignments[dtype_sql_date]; - break; + USHORT textType = *blr++; + textType += (*blr++) << 8; + desc->setTextType(textType); - case blr_sql_time: - desc->dsc_dtype = dtype_sql_time; - desc->dsc_length = sizeof(ULONG); - align = type_alignments[dtype_sql_time]; - break; + align = type_alignments[dtype_blob]; + } + break; - case blr_bool: - desc->dsc_dtype = dtype_boolean; - desc->dsc_length = sizeof(UCHAR); - align = type_alignments[dtype_boolean]; - break; + case blr_timestamp: + desc->dsc_dtype = dtype_timestamp; + desc->dsc_length = sizeof(SLONG) * 2; + align = type_alignments[dtype_timestamp]; + break; - default: - fb_assert(FALSE); - return parse_error(format, message); - } - if (desc->dsc_dtype == dtype_varying) - net_length += 4 + ((desc->dsc_length - 2 + 3) & ~3); - else - net_length += (desc->dsc_length + 3) & ~3; - if (align > 1) - offset = FB_ALIGN(offset, align); - desc->dsc_address = (UCHAR*) (IPTR) offset; - offset += desc->dsc_length; + case blr_sql_date: + desc->dsc_dtype = dtype_sql_date; + desc->dsc_length = sizeof(SLONG); + align = type_alignments[dtype_sql_date]; + break; + + case blr_sql_time: + desc->dsc_dtype = dtype_sql_time; + desc->dsc_length = sizeof(ULONG); + align = type_alignments[dtype_sql_time]; + break; + + case blr_bool: + desc->dsc_dtype = dtype_boolean; + desc->dsc_length = sizeof(UCHAR); + align = type_alignments[dtype_boolean]; + break; + + default: + fb_assert(false); + return NULL; } - format->fmt_length = offset; - format->fmt_net_length = net_length; - RMessage* next = new RMessage(format->fmt_length); -#ifdef DEBUG_REMOTE_MEMORY - printf("PARSE_messages allocate message %x\n", next); -#endif - next->msg_next = message; - message = next; - message->msg_address = reinterpret_cast<UCHAR*>(format); - message->msg_number = msg_number; - } - return message; -} + if (desc->dsc_dtype == dtype_varying) + net_length += 4 + ((desc->dsc_length - 2 + 3) & ~3); + else + net_length += (desc->dsc_length + 3) & ~3; + if (align > 1) + offset = FB_ALIGN(offset, align); -static RMessage* parse_error(rem_fmt* format, RMessage* message) -{ - delete format; - for (RMessage* next = message; next; next = message) - { - message = message->msg_next; - delete next->msg_address; - delete next; + desc->dsc_address = (UCHAR*) (IPTR) offset; + offset += desc->dsc_length; } - return (RMessage*) -1; + + format->fmt_length = offset; + format->fmt_net_length = net_length; + + return format.release(); } Modified: firebird/trunk/src/remote/protocol.cpp =================================================================== --- firebird/trunk/src/remote/protocol.cpp 2015-01-03 09:11:24 UTC (rev 60471) +++ firebird/trunk/src/remote/protocol.cpp 2015-01-05 16:08:21 UTC (rev 60472) @@ -1544,14 +1544,7 @@ // setting up a format if (blr->cstr_length) - { - RMessage* temp_msg = (RMessage*) PARSE_messages(blr->cstr_address, blr->cstr_length); - if (temp_msg != (RMessage*) -1) - { - *fmt_ptr = (rem_fmt*) temp_msg->msg_address; - delete temp_msg; - } - } + *fmt_ptr = PARSE_msg_format(blr->cstr_address, blr->cstr_length); } // If we know the length of the message, make sure there is a buffer @@ -1781,38 +1774,33 @@ procedure->rpr_out_format = NULL; RMessage* message = PARSE_messages(blr->cstr_address, blr->cstr_length); - if (message != (RMessage*) -1) + while (message) { - while (message) + switch (message->msg_number) { - switch (message->msg_number) + case 0: + procedure->rpr_in_msg = message; + procedure->rpr_in_format = (rem_fmt*) message->msg_address; + message->msg_address = message->msg_buffer; + message = message->msg_next; + procedure->rpr_in_msg->msg_next = NULL; + break; + case 1: + procedure->rpr_out_msg = message; + procedure->rpr_out_format = (rem_fmt*) message->msg_address; + message->msg_address = message->msg_buffer; + message = message->msg_next; + procedure->rpr_out_msg->msg_next = NULL; + break; + default: { - case 0: - procedure->rpr_in_msg = message; - procedure->rpr_in_format = (rem_fmt*) message->msg_address; - message->msg_address = message->msg_buffer; + RMessage* temp = message; message = message->msg_next; - procedure->rpr_in_msg->msg_next = NULL; - break; - case 1: - procedure->rpr_out_msg = message; - procedure->rpr_out_format = (rem_fmt*) message->msg_address; - message->msg_address = message->msg_buffer; - message = message->msg_next; - procedure->rpr_out_msg->msg_next = NULL; - break; - default: - { - RMessage* temp = message; - message = message->msg_next; - delete temp; - } - break; + delete temp; } + break; } } - else - fb_assert(FALSE); return TRUE; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2015-03-23 15:52:38
|
Revision: 61070 http://sourceforge.net/p/firebird/code/61070 Author: alexpeshkoff Date: 2015-03-23 15:52:30 +0000 (Mon, 23 Mar 2015) Log Message: ----------- Cleanup Modified Paths: -------------- firebird/trunk/src/remote/remot_proto.h firebird/trunk/src/remote/remote.cpp Modified: firebird/trunk/src/remote/remot_proto.h =================================================================== --- firebird/trunk/src/remote/remot_proto.h 2015-03-23 12:20:07 UTC (rev 61069) +++ firebird/trunk/src/remote/remot_proto.h 2015-03-23 15:52:30 UTC (rev 61070) @@ -59,7 +59,6 @@ void REMOTE_release_request (struct Rrq *); void REMOTE_reset_request (struct Rrq *, struct RMessage*); void REMOTE_reset_statement (struct Rsr *); -void REMOTE_save_status_strings (ISC_STATUS *); bool_t REMOTE_getbytes (XDR*, SCHAR*, u_int); LegacyPlugin REMOTE_legacy_auth(const char* nm, int protocol); Firebird::RefPtr<Config> REMOTE_get_config(const Firebird::PathName* dbName, Modified: firebird/trunk/src/remote/remote.cpp =================================================================== --- firebird/trunk/src/remote/remote.cpp 2015-03-23 12:20:07 UTC (rev 61069) +++ firebird/trunk/src/remote/remote.cpp 2015-03-23 15:52:30 UTC (rev 61070) @@ -581,26 +581,6 @@ } -void REMOTE_save_status_strings( ISC_STATUS* vector) -{ -/************************************** - * - * R E M O T E _ s a v e _ s t a t u s _ s t r i n g s - * - ************************************** - * - * Functional description - * There has been a failure during attach/create database. - * The included string have been allocated off of the database block, - * which is going to be released before the message gets passed - * back to the user. So, to preserve information, copy any included - * strings to a special buffer. - * - **************************************/ - Firebird::makePermanentVector(vector); -} - - // TMN: Beginning of C++ port - ugly but a start void rem_port::linkParent(rem_port* const parent) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2015-07-02 15:44:48
|
Revision: 61920 http://sourceforge.net/p/firebird/code/61920 Author: alexpeshkoff Date: 2015-07-02 15:44:45 +0000 (Thu, 02 Jul 2015) Log Message: ----------- Fixed CORE-4854: Client library incorrectly handles non-UTF8 representation of international characters in SPB Modified Paths: -------------- firebird/trunk/src/remote/client/interface.cpp firebird/trunk/src/remote/remote.cpp firebird/trunk/src/remote/remote.h Modified: firebird/trunk/src/remote/client/interface.cpp =================================================================== --- firebird/trunk/src/remote/client/interface.cpp 2015-07-02 15:35:51 UTC (rev 61919) +++ firebird/trunk/src/remote/client/interface.cpp 2015-07-02 15:44:45 UTC (rev 61920) @@ -7521,7 +7521,7 @@ void ClntAuthBlock::loadClnt(Firebird::ClumpletWriter& dpb, const ParametersSet* tags) { - bool uft8Convert = !dpb.find(isc_dpb_utf8_filename); + bool uft8Convert = !dpb.find(tags->utf8_filename); for (dpb.rewind(); !dpb.isEof(); dpb.moveNext()) { Modified: firebird/trunk/src/remote/remote.cpp =================================================================== --- firebird/trunk/src/remote/remote.cpp 2015-07-02 15:35:51 UTC (rev 61919) +++ firebird/trunk/src/remote/remote.cpp 2015-07-02 15:44:45 UTC (rev 61920) @@ -67,7 +67,8 @@ isc_dpb_remote_protocol, isc_dpb_host_name, isc_dpb_os_user, - isc_dpb_config + isc_dpb_config, + isc_dpb_utf8_filename }; const ParametersSet spbParam = @@ -89,7 +90,8 @@ isc_spb_remote_protocol, isc_spb_host_name, isc_spb_os_user, - isc_spb_config + isc_spb_config, + isc_spb_utf8_filename }; const ParametersSet connectParam = @@ -111,6 +113,7 @@ 0, CNCT_host, CNCT_user, + 0, 0 }; Modified: firebird/trunk/src/remote/remote.h =================================================================== --- firebird/trunk/src/remote/remote.h 2015-07-02 15:35:51 UTC (rev 61919) +++ firebird/trunk/src/remote/remote.h 2015-07-02 15:44:45 UTC (rev 61920) @@ -141,7 +141,8 @@ plugin_name, plugin_list, specific_data, address_path, process_id, process_name, encrypt_key, client_version, remote_protocol, - host_name, os_user, config_text; + host_name, os_user, config_text, + utf8_filename; }; extern const ParametersSet dpbParam, spbParam, connectParam; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2015-10-18 01:30:30
|
Revision: 62379 http://sourceforge.net/p/firebird/code/62379 Author: asfernandes Date: 2015-10-18 01:30:28 +0000 (Sun, 18 Oct 2015) Log Message: ----------- Misc. Modified Paths: -------------- firebird/trunk/src/remote/inet.cpp firebird/trunk/src/remote/server/server.cpp Modified: firebird/trunk/src/remote/inet.cpp =================================================================== --- firebird/trunk/src/remote/inet.cpp 2015-10-17 00:09:28 UTC (rev 62378) +++ firebird/trunk/src/remote/inet.cpp 2015-10-18 01:30:28 UTC (rev 62379) @@ -1566,7 +1566,7 @@ // is an attempt to return the socket to a state where a graceful shutdown can // occur. - // hvlad: for graceful shutdown linger should be turned on (despite of default + // hvlad: for graceful shutdown linger should be turned on (despite of default // setting by OS) { // scope struct linger lngr = {1, 10}; @@ -1575,7 +1575,7 @@ if (port->port_linger.l_onoff) lngr = port->port_linger; - setsockopt(port->port_handle, SOL_SOCKET, SO_LINGER, (SCHAR*)&lngr, sizeof(lngr)); + setsockopt(port->port_handle, SOL_SOCKET, SO_LINGER, (SCHAR*) &lngr, sizeof(lngr)); } if (port->port_handle != INVALID_SOCKET) @@ -1586,6 +1586,7 @@ FD_SET(port->port_handle, &fd); timeval tm = {10, 0}; int n = select(1, &fd, NULL, NULL, &tm); + while (n > 0) { char buff[256]; Modified: firebird/trunk/src/remote/server/server.cpp =================================================================== --- firebird/trunk/src/remote/server/server.cpp 2015-10-17 00:09:28 UTC (rev 62378) +++ firebird/trunk/src/remote/server/server.cpp 2015-10-18 01:30:28 UTC (rev 62379) @@ -720,8 +720,8 @@ return; RefMutexGuard portGuard(*port->port_sync, FB_FUNCTION); - - // hvlad: it is important to call IEvents::cancel() under protection + + // hvlad: it is important to call IEvents::cancel() under protection // of async port mutex to avoid crash in rem_port::que_events if (allowCancel && event->rvnt_iface) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2015-11-09 13:26:54
|
Revision: 62522 http://sourceforge.net/p/firebird/code/62522 Author: hvlad Date: 2015-11-09 13:26:52 +0000 (Mon, 09 Nov 2015) Log Message: ----------- Fixed bug CORE-4998 : Both client and server could not close connection after failed authentification Modified Paths: -------------- firebird/trunk/src/remote/client/interface.cpp firebird/trunk/src/remote/server/server.cpp Modified: firebird/trunk/src/remote/client/interface.cpp =================================================================== --- firebird/trunk/src/remote/client/interface.cpp 2015-11-09 09:52:24 UTC (rev 62521) +++ firebird/trunk/src/remote/client/interface.cpp 2015-11-09 13:26:52 UTC (rev 62522) @@ -5526,7 +5526,15 @@ if (!port) Arg::Gds(isc_unavailable).raise(); - secureAuthentication(cBlock, port); + try + { + secureAuthentication(cBlock, port); + } + catch (const Exception&) + { + disconnect(port); + throw; + } return port; } @@ -5905,12 +5913,14 @@ PACKET* packet = &rdb->rdb_packet; // Deliver the pending deferred packets - - for (rem_que_packet* p = port->port_deferred_packets->begin(); - p < port->port_deferred_packets->end(); p++) + if (port->port_deferred_packets) { - if (!p->sent) { - port->send(&p->packet); + for (rem_que_packet* p = port->port_deferred_packets->begin(); + p < port->port_deferred_packets->end(); p++) + { + if (!p->sent) { + port->send(&p->packet); + } } } Modified: firebird/trunk/src/remote/server/server.cpp =================================================================== --- firebird/trunk/src/remote/server/server.cpp 2015-11-09 09:52:24 UTC (rev 62521) +++ firebird/trunk/src/remote/server/server.cpp 2015-11-09 13:26:52 UTC (rev 62522) @@ -936,8 +936,7 @@ static void append_request_next(server_req_t*, server_req_t**); static void attach_database(rem_port*, P_OP, P_ATCH*, PACKET*); static void attach_service(rem_port*, P_ATCH*, PACKET*); -static void trusted_auth(rem_port*, const P_TRAU*, PACKET*); -static void continue_authentication(rem_port*, const p_auth_continue*, PACKET*); +static bool continue_authentication(rem_port*, PACKET*, PACKET*); static void aux_request(rem_port*, /*P_REQ*,*/ PACKET*); static bool bad_port_context(IStatus*, IReferenceCounted*, const ISC_STATUS); @@ -4179,11 +4178,9 @@ break; case op_trusted_auth: // PROTOCOL < 13 - trusted_auth(port, &receive->p_trau, sendL); - break; - case op_cont_auth: // PROTOCOL >= 13 - continue_authentication(port, &receive->p_auth_cont, sendL); + if (!continue_authentication(port, sendL, receive)) + return false; break; case op_update_account_info: @@ -4435,69 +4432,62 @@ } -static void trusted_auth(rem_port* port, const P_TRAU* p_trau, PACKET* send) +static bool continue_authentication(rem_port* port, PACKET* send, PACKET* receive) { /************************************** * - * t r u s t e d _ a u t h + * c o n t i n u e _ a u t h e n t i c a t i o n * ************************************** * * Functional description - * Server side of trusted auth handshake. + * Server side of multi-hop auth handshake. + * Returns false if auth failed and port was disconnected. * **************************************/ ServerAuthBase* sa = port->port_srv_auth; - if (! sa) + if (!sa) { send_error(port, send, isc_unavailable); } - - if (port->port_protocol < PROTOCOL_VERSION11 || port->port_protocol >= PROTOCOL_VERSION13) + else if (port->port_protocol < PROTOCOL_VERSION11 || + receive->p_operation == op_trusted_auth && port->port_protocol >= PROTOCOL_VERSION13 || + receive->p_operation == op_cont_auth && port->port_protocol < PROTOCOL_VERSION13) { send_error(port, send, (Arg::Gds(isc_random) << "Operation not supported for network protocol")); } + else try + { + if (receive->p_operation == op_trusted_auth) + { + HANDSHAKE_DEBUG(fprintf(stderr, "Srv: trusted_auth\n")); + port->port_srv_auth_block->setDataForPlugin(receive->p_trau.p_trau_data); + } + else if (receive->p_operation == op_cont_auth) + { + HANDSHAKE_DEBUG(fprintf(stderr, "Srv: continue_authentication\n")); + port->port_srv_auth_block->setDataForPlugin(&receive->p_auth_cont); + } - HANDSHAKE_DEBUG(fprintf(stderr, "Srv: trusted_auth\n")); - port->port_srv_auth_block->setDataForPlugin(p_trau->p_trau_data); - if (sa->authenticate(send, ServerAuth::CONT_AUTH)) - { - delete sa; - port->port_srv_auth = NULL; + if (sa->authenticate(send, ServerAuth::CONT_AUTH)) + { + delete sa; + port->port_srv_auth = NULL; + } + return true; } -} - - -static void continue_authentication(rem_port* port, const p_auth_continue* p_auth_c, PACKET* send) -{ -/************************************** - * - * c o n t i n u e _ a u t h e n t i c a t i o n - * - ************************************** - * - * Functional description - * Server side of multi-hop auth handshake. - * - **************************************/ - ServerAuthBase* sa = port->port_srv_auth; - if (! sa) + catch (const Exception& ex) { - send_error(port, send, isc_unavailable); - } + LocalStatus ls; + CheckStatusWrapper status_vector(&ls); + ex.stuffException(&status_vector); - if (port->port_protocol < PROTOCOL_VERSION13) - { - send_error(port, send, (Arg::Gds(isc_random) << "Operation not supported for network protocol")); + port->send_response(send, 0, 0, &status_vector, false); } - HANDSHAKE_DEBUG(fprintf(stderr, "Srv: continue_authentication\n")); - port->port_srv_auth_block->setDataForPlugin(p_auth_c); - if (sa->authenticate(send, ServerAuth::CONT_AUTH)) - { - delete sa; - port->port_srv_auth = NULL; - } + port->disconnect(send, receive); + + return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2015-11-12 13:43:40
|
Revision: 62552 http://sourceforge.net/p/firebird/code/62552 Author: alexpeshkoff Date: 2015-11-12 13:43:38 +0000 (Thu, 12 Nov 2015) Log Message: ----------- Fixed CORE-5014: Interrupt of aux connection during TCP setup phase causes unclear error messages in firebird.log Modified Paths: -------------- firebird/trunk/src/remote/inet.cpp firebird/trunk/src/remote/server/server.cpp Modified: firebird/trunk/src/remote/inet.cpp =================================================================== --- firebird/trunk/src/remote/inet.cpp 2015-11-12 07:23:08 UTC (rev 62551) +++ firebird/trunk/src/remote/inet.cpp 2015-11-12 13:43:38 UTC (rev 62552) @@ -147,14 +147,15 @@ static void SOCLOSE(SOCKET& socket) { - if (socket != INVALID_SOCKET) + SOCKET s = socket; + if (s != INVALID_SOCKET) { + socket = INVALID_SOCKET; #ifdef WIN_NT - closesocket(socket); + closesocket(s); #else - close(socket); + close(s); #endif - socket = INVALID_SOCKET; } } @@ -1366,6 +1367,9 @@ } } + if (port->port_channel == INVALID_SOCKET) + return NULL; + const SOCKET n = os_utils::accept(port->port_channel, NULL, NULL); inetErrNo = INET_ERRNO; Modified: firebird/trunk/src/remote/server/server.cpp =================================================================== --- firebird/trunk/src/remote/server/server.cpp 2015-11-12 07:23:08 UTC (rev 62551) +++ firebird/trunk/src/remote/server/server.cpp 2015-11-12 13:43:38 UTC (rev 62552) @@ -2288,20 +2288,25 @@ if (aux_port) { aux_port->port_flags |= PORT_connecting; + bool connected = false; try { - if (aux_port->connect(send)) + connected = aux_port->connect(send) != NULL; + if (connected) aux_port->port_context = rdb; } catch (const Exception& ex) { - aux_port->port_flags &= ~PORT_connecting; iscLogException("", ex); + } + + aux_port->port_flags &= ~PORT_connecting; + if (!connected) + { fb_assert(port->port_async == aux_port); port->port_async = NULL; aux_port->disconnect(); } - aux_port->port_flags &= ~PORT_connecting; } } catch (const Exception& ex) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2015-11-15 11:57:42
|
Revision: 62558 http://sourceforge.net/p/firebird/code/62558 Author: alexpeshkoff Date: 2015-11-15 11:57:39 +0000 (Sun, 15 Nov 2015) Log Message: ----------- Fixed CORE-5017: Interrupt of aux connection during TCP setup phase causes server exit due to unhandled exception Modified Paths: -------------- firebird/trunk/src/remote/inet.cpp firebird/trunk/src/remote/os/win32/wnet.cpp firebird/trunk/src/remote/os/win32/xnet.cpp firebird/trunk/src/remote/server/server.cpp Modified: firebird/trunk/src/remote/inet.cpp =================================================================== --- firebird/trunk/src/remote/inet.cpp 2015-11-14 00:10:02 UTC (rev 62557) +++ firebird/trunk/src/remote/inet.cpp 2015-11-15 11:57:39 UTC (rev 62558) @@ -1504,7 +1504,7 @@ } rem_port* const new_port = alloc_port(port->port_parent, - (port->port_flags & PORT_no_oob) | PORT_async); + (port->port_flags & PORT_no_oob) | PORT_async | PORT_connecting); port->port_async = new_port; new_port->port_dummy_packet_interval = port->port_dummy_packet_interval; new_port->port_dummy_timeout = new_port->port_dummy_packet_interval; @@ -1590,6 +1590,7 @@ MutexLockGuard guard(port_mutex, FB_FUNCTION); port->port_state = rem_port::DISCONNECTED; + port->port_flags &= ~PORT_connecting; if (port->port_async) { @@ -1935,7 +1936,8 @@ if (!REMOTE_inflate(port, packet_receive, buffer, bufsize, length)) { - if (port->port_flags & PORT_disconnect) { + if (port->port_flags & (PORT_disconnect | PORT_connecting)) + { continue; } *length = 0; Modified: firebird/trunk/src/remote/os/win32/wnet.cpp =================================================================== --- firebird/trunk/src/remote/os/win32/wnet.cpp 2015-11-14 00:10:02 UTC (rev 62557) +++ firebird/trunk/src/remote/os/win32/wnet.cpp 2015-11-15 11:57:39 UTC (rev 62558) @@ -631,9 +631,9 @@ const DWORD server_pid = (vport->port_server_flags & SRVR_multi_client) ? ++event_counter : GetCurrentProcessId(); rem_port* const new_port = alloc_port(vport->port_parent); + new_port->port_server_flags = vport->port_server_flags; + new_port->port_flags = (vport->port_flags & PORT_no_oob) | PORT_connecting; vport->port_async = new_port; - new_port->port_server_flags = vport->port_server_flags; - new_port->port_flags = vport->port_flags & PORT_no_oob; TEXT str_pid[32]; wnet_make_file_name(str_pid, server_pid); @@ -731,6 +731,7 @@ // If this is a sub-port, unlink it from its parent port->unlinkParent(); + port->port_flags &= ~PORT_connecting; if (port->port_server_flags & SRVR_server) { Modified: firebird/trunk/src/remote/os/win32/xnet.cpp =================================================================== --- firebird/trunk/src/remote/os/win32/xnet.cpp 2015-11-14 00:10:02 UTC (rev 62557) +++ firebird/trunk/src/remote/os/win32/xnet.cpp 2015-11-15 11:57:39 UTC (rev 62558) @@ -888,10 +888,10 @@ channel_s2c_client_ptr, xcc->xcc_send_channel->xch_size, channel_c2s_client_ptr, xcc->xcc_recv_channel->xch_size); - port->port_async = new_port; new_port->port_xcc = xcc; - new_port->port_flags = port->port_flags & PORT_no_oob; + new_port->port_flags = (port->port_flags & PORT_no_oob) | PORT_connecting; new_port->port_server_flags = port->port_server_flags; + port->port_async = new_port; P_RESP* response = &packet->p_resp; response->p_resp_data.cstr_length = 0; @@ -1441,6 +1441,7 @@ // If this is a sub-port, unlink it from it's parent port->unlinkParent(); + port->port_flags &= ~PORT_connecting; xnet_ports->unRegisterPort(port); cleanup_port(port); } Modified: firebird/trunk/src/remote/server/server.cpp =================================================================== --- firebird/trunk/src/remote/server/server.cpp 2015-11-14 00:10:02 UTC (rev 62557) +++ firebird/trunk/src/remote/server/server.cpp 2015-11-15 11:57:39 UTC (rev 62558) @@ -2289,20 +2289,22 @@ if (aux_port) { - aux_port->port_flags |= PORT_connecting; + fb_assert(aux_port->port_flags & PORT_connecting); bool connected = false; try { connected = aux_port->connect(send) != NULL; if (connected) + { aux_port->port_context = rdb; + aux_port->port_flags &= ~PORT_connecting; + } } catch (const Exception& ex) { iscLogException("", ex); } - aux_port->port_flags &= ~PORT_connecting; if (!connected) { fb_assert(port->port_async == aux_port); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |