UDF Library Placement
Go Up to Declaring a UDF to a Database
Earlier versions of InterBase had few requirements about the placement of UDF libraries. For security reasons, current versions of InterBase have the following requirements for the placement of UDF libraries:
- On any platform, the module can be referenced with no path name if it is in <<InterBase_home>>
/UDF
or <<InterBase_home>>/intl
. - If the library in a directory other than
<InterBase_home>/UDF
or <<InterBase_home>>/intl
, you must specify its location in InterBase configuration file (ibconfig
) using theEXTERNAL_FUNCTION_DIRECTORY
parameter. Give the complete pathname to the library, including a drive letter in the case of a Windows server.
When either of the above conditions is met, InterBase finds the library. You do not need to specify a path in the declaration.
The library must reside on the same machine as the InterBase server.
To specify a location for UDF libraries in ibconfig
, enter a line such as the following:
Windows:
EXTERNAL_FUNCTION_DIRECTORY "C:\<InterBase_home>\Mylibraries"
Unix:
EXTERNAL_FUNCTION_DIRECTORY "/usr/interbase/Mylibraries"
Note that it is no longer sufficient to include a complete path name for the module in the DECLARE EXTERNAL FUNCTION
statement. You must list the path in the EXTERNAL_FUNCTION_DIRECTORY
parameter of the InterBase configuration file if the library is not located in <InterBase_home>/UDF
or <InterBase_home>/intl
.
For security reasons, InterBase strongly recommends that you place your compiled libraries in directories that are dedicated to InterBase libraries. Placing InterBase libraries in directories such as
C:\WINNT\system32
or /usr/lib
permits access to all libraries in those directories and is a serious security hole.Example: The following statement declares the TOPS()
UDF to a database:
DECLARE EXTERNAL FUNCTION TOPS
CHAR(256), INTEGER, BLOB
RETURNS INTEGER BY VALUE
ENTRY_POINT 'TE1' MODULE_NAME 'TM1';
This example does not need the FREE_IT
keyword because only cstrings, CHAR
, and VARCHAR
return types require memory allocation. The module must be in InterBase UDF
directory or in a directory that is named in the configuration file.
Example: The following isql
script declares UDFs, ABS
() and TRIM
(), to the employee.gdb
database:
CONNECT 'employee.gdb';
DECLARE EXTERNAL FUNCTION ABS
DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'fn_abs' MODULE_NAME 'ib_udf';
DECLARE EXTERNAL FUNCTION TRIM
SMALLINT, CSTRING(256), SMALLINT
RETURNS CSTRING(256) FREE_IT
ENTRY_POINT 'fn_trim' MODULE_NAME 'ib_udf';
COMMIT;
Note that no extension is supplied for the module name. This creates a portable module. Windows machines add a dll
extension automatically.