Patch attached.

For an description of the patch, see my post to the IBPP list

On 26/03/14 15:41, Fulvio Senore wrote:
> Thank you, I will be glad to test it.
>
> Fulvio
>
> Il 26/03/2014 16:25, Tony Whyman ha scritto:
>> Fluvio,
>>
>> It looks like the patch I submitted was stripped off before the post was
>> copied to the list. If you want to test it then I can send to you by
>> direct EMail.
>>
>> Regards
>>
>> Tony Whyman
>> MWA
>>
>> On 26/03/14 15:21, Fulvio Senore wrote:
>>> Tony,
>>>
>>> thank you for your clarification. I am using IBPP too and I have seen
>>> your bug report in that mailing list. It looks like we are developing
>>> programs in a similar way.
>>> I will carefully follow this thread since I am very interested in this
>>> problem. Please let me know if I can help in any way.
>>>
>>> Fulvio Senore
>>>
>>> Il 26/03/2014 15:36, Tony Whyman ha scritto:
>>>> Fulvio,
>>>>
>>>> I believe that there are two issues here. The first is that the FIREBIRD
>>>> environment variable seems to be being ignored in 2.5 when locating the
>>>> security database.
>>>>
>>>> The second is how to use the Firebird 2.5 libfbembed.so under Linux when
>>>> the current user is not a member of the firebird group.
>>>>
>>>> As Alex Peshkoff pointed out, your can do this provided that a user name
>>>> is not provided. For example, with isql, as long as the ISC_USER
>>>> environment variable is not set, when no "-user" argument is given to
>>>> isql, no attempt is made to access the security database and a local
>>>> database can be accessed as long as the user has r/w access to their
>>>> local database.
>>>>
>>>> My problem was coming from IBPP which helpfully?) checks the username
>>>> parameter when attempting to open a database and declares an error if
>>>> none is given. Under Firebird 2.1, this was not a problem as long as a
>>>> default security database was in the directory given by the FIREBIRD
>>>> environment variable. Under Firebird 2.5 there seems to be no workaround.
>>>>
>>>> I have already posted a bug report on the IBPP list about this. The
>>>> FIREBIRD environment variable issue probably needs to be progressed
>>>> separately.
>>>>
>>>> Tony Whyman
>>>> MWA
>>> ------------------------------------------------------------------------------
>>> Learn Graph Databases - Download FREE O'Reilly Book
>>> "Graph Databases" is the definitive new guide to graph databases and their
>>> applications. Written by three acclaimed leaders in the field,
>>> this first edition is now available. Download your free book today!
>>> http://p.sf.net/sfu/13534_NeoTech
>>> Firebird-Devel mailing list, web interface at 
>>> https://lists.sourceforge.net/lists/listinfo/firebird-devel
>>
>> ------------------------------------------------------------------------------
>> Learn Graph Databases - Download FREE O'Reilly Book
>> "Graph Databases" is the definitive new guide to graph databases and their
>> applications. Written by three acclaimed leaders in the field,
>> this first edition is now available. Download your free book today!
>> http://p.sf.net/sfu/13534_NeoTech
>> Firebird-Devel mailing list, web interface at 
>> https://lists.sourceforge.net/lists/listinfo/firebird-devel
>>
>>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> Firebird-Devel mailing list, web interface at 
> https://lists.sourceforge.net/lists/listinfo/firebird-devel

diff -rupN ibpp/core/database.cpp ibpp.patched/core/database.cpp
--- ibpp/core/database.cpp	2006-11-08 15:18:28.000000000 +0000
+++ ibpp.patched/core/database.cpp	2014-03-26 13:12:54.000000000 +0000
@@ -83,13 +83,11 @@ void DatabaseImpl::Connect()
 
 	if (mDatabaseName.empty())
 		throw LogicExceptionImpl("Database::Connect", _("Unspecified database name."));
-	if (mUserName.empty())
-		throw LogicExceptionImpl("Database::Connect", _("Unspecified user name."));
 
     // Build a DPB based on the properties
 	DPB dpb;
-    dpb.Insert(isc_dpb_user_name, mUserName.c_str());
-    dpb.Insert(isc_dpb_password, mUserPassword.c_str());
+    if (! mUserName.empty()) dpb.Insert(isc_dpb_user_name, mUserName.c_str());
+    if (! mUserName.empty() && ! mUserPassword.empty()) dpb.Insert(isc_dpb_password, mUserPassword.c_str());
     if (! mRoleName.empty()) dpb.Insert(isc_dpb_sql_role_name, mRoleName.c_str());
     if (! mCharSet.empty()) dpb.Insert(isc_dpb_lc_ctype, mCharSet.c_str());
 
diff -rupN ibpp/core/_ibpp.cpp ibpp.patched/core/_ibpp.cpp
--- ibpp/core/_ibpp.cpp	2006-05-12 10:40:52.000000000 +0100
+++ ibpp.patched/core/_ibpp.cpp	2014-03-26 13:34:54.000000000 +0000
@@ -45,6 +45,18 @@
 #define FB_DEFAULT_INSTANCE	  	"DefaultInstance"
 #endif
 
+#ifdef IBPP_UNIX
+#ifdef IBPP_LATE_BIND
+
+#include <dlfcn.h>
+#include <stdlib.h>
+
+//empty string terminated list of Firebird SO libraries o try in turn
+static const char* fblibs[] = {"libfbembed.so.2.5","libfbembed.so.2.1","libfbclient.so.2",""};
+
+#endif
+#endif
+
 namespace ibpp_internals
 {
 	const double consts::dscales[19] = {
@@ -214,6 +226,30 @@ GDS* GDS::Call()
 		}
 #endif
 
+#ifdef IBPP_UNIX
+#ifdef IBPP_LATE_BIND
+
+		mHandle = 0;
+		if (getenv("FBLIB") != 0)
+			mHandle = dlopen(getenv("FBLIB"),RTLD_LAZY);
+		else
+		{
+			int ixlib = 0;
+			while (fblibs[ixlib] != "")
+			{
+				mHandle = dlopen(fblibs[ixlib],RTLD_LAZY);
+				if (mHandle != 0) break;
+				ixlib++;
+			}
+		}
+
+		if (mHandle == 0)
+					throw LogicExceptionImpl("GDS::Call()",
+						_("Can't find or load the Firebird Client Library"));
+		
+#endif
+#endif
+
 		mGDSVersion = 60;
 
 		// Get the entry points that we need
@@ -223,10 +259,16 @@ GDS* GDS::Call()
 			if ((m_##X = (proto_##X*)GetProcAddress(mHandle, "isc_"#X)) == 0) \
 				throw LogicExceptionImpl("GDS:gds()", _("Entry-point isc_"#X" not found"))
 #endif
+
 #ifdef IBPP_UNIX
-/* TODO : perform a late-bind on unix --- not so important, well I think (OM) */
+#ifdef IBPP_LATE_BIND
+#define IB_ENTRYPOINT(X) \
+			if ((m_##X = (proto_##X*)dlsym(mHandle,"isc_"#X)) == 0) \
+				throw LogicExceptionImpl("GDS:gds()", _("Entry-point isc_"#X" not found"))
+#else
 #define IB_ENTRYPOINT(X) m_##X = (proto_##X*)isc_##X
 #endif
+#endif
 
 		IB_ENTRYPOINT(create_database);
 		IB_ENTRYPOINT(attach_database);
diff -rupN ibpp/core/_ibpp.h ibpp.patched/core/_ibpp.h
--- ibpp/core/_ibpp.h	2006-04-11 15:18:54.000000000 +0100
+++ ibpp.patched/core/_ibpp.h	2014-03-24 23:48:23.000000000 +0000
@@ -64,6 +64,7 @@
 #include <vector>
 #include <sstream>
 #include <cstdarg>
+#include <string.h>
 
 #ifdef _DEBUG
 #define ASSERTION(x)	{if (!(x)) {throw LogicExceptionImpl("ASSERTION", \
@@ -399,6 +400,12 @@ struct GDS
 	std::string mSearchPaths;	// Optional additional search paths
 #endif
 
+#ifdef IBPP_UNIX
+#ifdef IBPP_LATE_BIND
+		void *mHandle;
+#endif
+#endif
+
 	GDS* Call();
 
 	// GDS32 Entry Points
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to