/****************************************************************************
 *
 *                               GBase.
 *
 *                           PROPRIETARY DATA
 *
 * Licensed Material - Property Of GBase
 *
 * "Restricted Materials of GBase"
 *
 * GBase Client SDK
 *
 *  Copyright GBASE  2002,2007. All rights reserved.
 *
 ****************************************************************************
 */

#include <windows.h>
#include "login.h"

HINSTANCE GhinstDll;


#ifndef STATIC_LIB
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason,
		LPVOID lpvReserved)
{
	switch (fdwReason)
	{
		case DLL_PROCESS_ATTACH:
			GhinstDll = hinstDLL;
			break;
	}

	return (TRUE);
}
#endif /* STATIC_LIB */

/* The authorization should now be done by sqlauthEx2. All authorization initially being
   done by sqlauth should now be done/moved here.
 */
#ifndef STATIC_LIB
BOOL __declspec( dllexport ) sqlauthEx2 ( HostInfoStructEx2 *pHostInfoEx2 )
{
#else
BOOL  sqlauthEx2 ( HostInfoStructEx2 *pHostInfoEx2 )
{
#endif /*STATIC_LIB*/
    switch (pHostInfoEx2->StructLen)
    {
    case (sizeof (HostInfoStructEx2)):
        break;
    default:
        return ERROR_INVALID_PARAMETER;
        break;
    }

    /* Actual authorization code here.
     */
	return TRUE;
}

#ifndef STATIC_LIB
BOOL __declspec( dllexport ) sqlauth ( HostInfoStruct *pHostInfo )
{
#else
BOOL  sqlauth ( HostInfoStruct *pHostInfo )
{
#endif /* STATIC_LIB */
    HostInfoStructEx2   tmpHostInfo = {sizeof (HostInfoStructEx2)};
    BOOL                result;

    strcpy (tmpHostInfo.InfxServer, pHostInfo->InfxServer);
    strcpy (tmpHostInfo.Host, pHostInfo->Host);
    strcpy (tmpHostInfo.User, pHostInfo->User);
    strcpy (tmpHostInfo.Pass, pHostInfo->Pass);
    strcpy (tmpHostInfo.AskPassAtConnect, pHostInfo->AskPassAtConnect);
    strcpy (tmpHostInfo.Service, pHostInfo->Service);
    strcpy (tmpHostInfo.Protocol, pHostInfo->Protocol);
    strcpy (tmpHostInfo.Options, pHostInfo->Options);

    result = sqlauthEx2 (&tmpHostInfo);

    if ((strlen (tmpHostInfo.InfxServer) >= sizeof(pHostInfo->InfxServer)) ||
        (strlen (tmpHostInfo.Host) >= sizeof(pHostInfo->Host)) ||
        (strlen (tmpHostInfo.User) >= sizeof(pHostInfo->User)) ||
        (strlen (tmpHostInfo.Pass) >= sizeof(pHostInfo->Pass)) ||
        (strlen (tmpHostInfo.AskPassAtConnect) >= sizeof(pHostInfo->AskPassAtConnect)) ||
        (strlen (tmpHostInfo.Service) >= sizeof(pHostInfo->Service)) ||
        (strlen (tmpHostInfo.Protocol) >= sizeof(pHostInfo->Protocol)) ||
        (strlen (tmpHostInfo.Options) >= sizeof(pHostInfo->Options)))
        return ERROR_OUTOFMEMORY;

    strcpy (pHostInfo->InfxServer, tmpHostInfo.InfxServer);
    strcpy (pHostInfo->Host, tmpHostInfo.Host);
    strcpy (pHostInfo->User, tmpHostInfo.User);
    strcpy (pHostInfo->Pass, tmpHostInfo.Pass);
    strcpy (pHostInfo->AskPassAtConnect, tmpHostInfo.AskPassAtConnect);
    strcpy (pHostInfo->Service, tmpHostInfo.Service);
    strcpy (pHostInfo->Protocol, tmpHostInfo.Protocol);
    strcpy (pHostInfo->Options, tmpHostInfo.Options);
	return result;
}
