db2secServerAuthPluginInit - Initialize server authentication plug-in
The db2secServerAuthPluginInit API is the initialization API for the server authentication plug-in that the Db2® database manager calls immediately after loading the plug-in.
In the case of GSS-API, the plug-in is responsible for filling in the server's principal name in the serverPrincipalName parameter inside the gssapi_server_auth_functions structure at initialization time and providing the server's credential handle in the serverCredHandle parameter inside the gssapi_server_auth_functions structure. The freeing of the memory allocated to hold the principal name and the credential handle must be done by the db2secServerAuthPluginTerm API by calling the gss_release_name and gss_release_cred APIs.
API and data structure syntax
SQL_API_RC SQL_API_FN db2secServerAuthPluginInit
( db2int32 version,
void *server_fns,
db2secGetConDetails *getConDetails_fn,
db2secLogMessage *logMessage_fn,
char **errormsg,
db2int32 *errormsglen );
db2secServerAuthPluginInit API parameters
- version
- Input. The highest version number of the API that the Db2 database manager currently supports. The DB2SEC_API_VERSION value (in db2secPlugin.h) contains the latest version number of the API that the Db2 database manager currently supports.
- server_fns
- Output. A pointer to memory provided by the Db2 database manager for
a db2secGssapiServerAuthFunctions_<version_number> structure (also known as
gssapi_server_auth_functions_<version_number>), if GSS-API authentication
is used, or a db2secUseridPasswordServerAuthFunctions_<version_number>
structure (also known as
userid_password_server_auth_functions_<version_number>), if userid/password
authentication is used. The
db2secGssapiServerAuthFunctions_<version_number> structure and
db2secUseridPasswordServerAuthFunctions_<version_number> structure contain
pointers to the APIs implemented for the GSS-API authentication plug-in and userid/password
authentication plug-in. The server_fns parameter is cast as a pointer to the gssapi_server_auth_functions_<version_number> structure corresponding to the version the plug-in has implemented. The first parameter of the gssapi_server_auth_functions_<version_number> structure or the userid_password_server_auth_functions_<version_number> structure tells theDb2 database manager the version of the APIs that the plug-in has implemented.Note: The casting is done only if the Db2 version is higher or equal to the version of the APIs that the plug-in has implemented.
Inside the gssapi_server_auth_functions_<version_number> or userid_password_server_auth_functions_<version_number> structure, the plugintype parameter should be set to one of DB2SEC_PLUGIN_TYPE_USERID_PASSWORD, DB2SEC_PLUGIN_TYPE_GSSAPI, or DB2SEC_PLUGIN_TYPE_KERBEROS. Other values can be defined in future versions of the API.
- getConDetails_fn
- Input. Pointer to the db2secGetConDetails API, which is implemented by
Db2. The
db2secServerAuthPluginInit API can call the
db2secGetConDetails API in any one of the other authentication APIs to obtain
details related to the database connection. These details include information about the
communication mechanism associated with the connection (such as the IP address, in the case of
TCP/IP), which the plug-in writer might need to reference when making authentication decisions. For
example, the plug-in could disallow a connection for a particular user, unless that user is
connecting from a particular IP address. The use of the db2secGetConDetails API
is optional.
If the db2secGetConDetails API is called in a situation not involving a database connection, it returns the value DB2SEC_PLUGIN_NO_CON_DETAILS, otherwise, it returns 0 on success.
The db2secGetConDetails API takes two input parameters; pConDetails, which is a pointer to the db2sec_con_details_<version_number> structure, and conDetailsVersion, which is a version number indicating which db2sec_con_details structure to use. Possible values are DB2SEC_CON_DETAILS_VERSION_1 when db2sec_con_details1 is used or DB2SEC_CON_DETAILS_VERSION_2 when db2sec_con_details2. The recommended version number to use is DB2SEC_CON_DETAILS_VERSION_2.
Upon a successful return, the db2sec_con_details structure (either db2sec_con_details1 or db2sec_con_details2) will contain the following information:- The protocol used for the connection to the server. The listing of protocol definitions can be found in the file sqlenv.h (located in the include directory) (SQL_PROTOCOL_*). This information is filled out in the clientProtocol parameter.
- The TCP/IP address of the inbound connect to the server if the clientProtocol is SQL_PROTOCOL_TCPIP or SQL_PROTOCOL_TCPIP4. This information is filled out in the clientIPAddress parameter.
- The database name the client is attempting to connect to. This will not be set for instance attachments. This information is filled out in the dbname and dbnameLen parameters.
- A connection information bit-map that contains the same details as documented in the connection_details parameter of the db2secValidatePassword API. This information is filled out in the connect_info_bitmap parameter.
- The TCP/IP address of the inbound connect to the server if the clientProtocol is SQL_PROTOCOL_TCPIP6. This information is filled out in the clientIP6Address parameter and it is only available if DB2SEC_CON_DETAILS_VERSION_2 is used for db2secGetConDetails API call.
- logMessage_fn
- Input. A pointer to the db2secLogMessage API, which is implemented by the Db2 database manager. The db2secClientAuthPluginInit API can call the db2secLogMessage API to log messages to the db2diag log files for debugging or informational purposes. The first parameter (level) of db2secLogMessage API specifies the type of diagnostic errors that will be recorded in the db2diag log files and the last two parameters are the message string and its length. The valid values for the first parameter of db2secLogMessage API (defined in db2secPlugin.h) are:
- DB2SEC_LOG_NONE (0): No logging
- DB2SEC_LOG_CRITICAL (1): Severe Error encountered
- DB2SEC_LOG_ERROR (2): Error encountered
- DB2SEC_LOG_WARNING (3): Warning
- DB2SEC_LOG_INFO (4): Informational
The message text will appear in the db2diag log files only if the value of the level parameter of the db2secLogMessage API is less than or equal to the diaglevel database manager configuration parameter.
So for example, if you use the DB2SEC_LOG_INFO value, the message text will appear in the db2diag log files only if the diaglevel database manager configuration parameter is set to 4.
- errormsg
- Output. A pointer to the address of an ASCII error message string allocated by the plug-in that can be returned in this parameter if the db2secServerAuthPluginInit API execution is not successful.
- errormsglen
- Output. A pointer to an integer that indicates the length in bytes of the error message string in errormsg parameter.