class='cKeyword'>#include <windows.h>
class='cKeyword'>#include <unicode.h>
class='cKeyword'>#include <nmaslogininfo.h>
class='cKeyword'>#define BUFFER_LEN 256
static HANDLE threadExitedEvent = INVALID_HANDLE_VALUE;
static HANDLE threadHandle = INVALID_HANDLE_VALUE;
static LPFN_NMAS_SetLoginIdentity NMAS_SetLoginIdentity = NULL;
int localToUnicode(unicode *u, class='cKeyword'>char *s)
{
nptr localHandle;
nint err;
nuint32 len;
err = NWGetLocalToUnicodeHandle(&localHandle);
if(err)
{
*u = L'\0';
return err;
}
err = NWLocalToUnicode(localHandle, (punicode) u, (nuint32) strlen(s) + 1, (unsigned class='cKeyword'>char*)s, L'*', (unsigned int*) &len);
if(err)
{
*u = L'\0';
}
return err;
}
int getIDValue(class='cKeyword'>char *valueName, class='cKeyword'>char *valueData, int valueDataLen)
{
int err = 0;
HKEY hKey = 0;
DWORD type, dataSize;
err = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Novell\\NMAS\\MethodData\\IDPluginExample",
0,
KEY_QUERY_VALUE,
&hKey);
if(!err)
{
dataSize = valueDataLen;
err = RegQueryValueEx(hKey, valueName, 0, &type, (BYTE*)valueData, &dataSize);
}
if(hKey)
RegCloseKey(hKey);
return err;
}
DWORD APIENTRY getUserInfoFromDevice(void *param)
{
int err = 0;
class='cKeyword'>char data[BUFFER_LEN];
NMAS_LOGIN_IDENTITY identity;
memset(&identity, 0, sizeof(NMAS_LOGIN_IDENTITY));
identity.size = sizeof(NMAS_LOGIN_IDENTITY);
identity.validFields = 0;
if(!getIDValue("Username", data, BUFFER_LEN))
{
localToUnicode(identity.userName, data);
identity.validFields |= NLI_FIELD_USERNAME;
}
if(!getIDValue("Context", data, BUFFER_LEN))
{
localToUnicode(identity.context, data);
identity.validFields |= NLI_FIELD_CONTEXT;
}
if(!getIDValue("Sequence", data, BUFFER_LEN))
{
localToUnicode(identity.sequence, data);
identity.validFields |= NLI_FIELD_SEQUENCE;
}
if(!getIDValue("Clearance", data, BUFFER_LEN))
{
localToUnicode(identity.clearance, data);
identity.validFields |= NLI_FIELD_CLEARANCE;
}
if(!getIDValue("Server", data, BUFFER_LEN))
{
localToUnicode(identity.server, data);
identity.validFields |= NLI_FIELD_SERVER;
}
if(!getIDValue("Tree", data, BUFFER_LEN))
{
localToUnicode(identity.tree, data);
identity.validFields |= NLI_FIELD_TREE;
}
if(NMAS_SetLoginIdentity)
NMAS_SetLoginIdentity(&identity);
SetEvent(threadExitedEvent);
return err;
}
int StartIdentityPlugin()
{
DWORD threadId;
if(threadExitedEvent == INVALID_HANDLE_VALUE)
{
threadExitedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(threadExitedEvent && threadExitedEvent != INVALID_HANDLE_VALUE)
{
threadHandle = CreateThread(NULL,0, &getUserInfoFromDevice, NULL, 0, &threadId);
}
}
return 0;
}
int StopIdentityPlugin()
{
if(threadExitedEvent && threadExitedEvent != INVALID_HANDLE_VALUE)
{
WaitForSingleObject(threadExitedEvent, INFINITE);
if(threadExitedEvent)
CloseHandle(threadExitedEvent);
threadExitedEvent = INVALID_HANDLE_VALUE;
WaitForSingleObject(threadHandle, 3000);
threadHandle = INVALID_HANDLE_VALUE;
}
return 0;
}
int NMAS_RegisterIdentityPlugin(LPFN_NMAS_SetLoginIdentity setIdentity,
LPFN_NMAS_StartIdentityPlugin *startIdentityPlugin,
LPFN_NMAS_StopIdentityPlugin *stopIdentityPlugin)
{
NMAS_SetLoginIdentity = setIdentity;
*startIdentityPlugin = StartIdentityPlugin;
*stopIdentityPlugin = StopIdentityPlugin;
return 0;
}