Completed the Authtoken Validate Service changes.
This commit is contained in:
@@ -26,6 +26,12 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
//===[ Manifest constants ]================================================
|
||||
|
||||
#define APPLICATION_NOT_MULTI_THREADED "CASA_APPLICATION_NOT_MULTI_THREADED"
|
||||
|
||||
#define DOMAIN_SOCKET_FILE_NAME "/var/lib/CASA/authtoken/validate/socket"
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//===[ Function prototypes ]===============================================
|
||||
@@ -41,10 +47,23 @@ int DebugLevel = 0;
|
||||
static
|
||||
bool g_moduleInitialized = false;
|
||||
|
||||
//
|
||||
// Configuration variables
|
||||
//
|
||||
bool g_multiThreadedApplication = true;
|
||||
|
||||
//
|
||||
// IPC Client Sub-system variables
|
||||
//
|
||||
uint32_t atvsEndPointHandle; // Authentication Token Validation Service endpoint handle
|
||||
//
|
||||
PFN_IpcClientInit g_ipcInitPtr = NULL;
|
||||
PFN_IpcClientShutdown g_ipcShutdownPtr = NULL;
|
||||
//PFN_IpcClientOpenInetRemoteEndPoint g_ipcOpenEndPointPtr = NULL;
|
||||
PFN_IpcClientOpenUnixRemoteEndPoint g_ipcOpenEndPointPtr = NULL;
|
||||
PFN_IpcClientCloseRemoteEndPoint g_ipcCloseEndPointPtr = NULL;
|
||||
PFN_IpcClientSubmitReq g_ipcSubmitReq = NULL;
|
||||
|
||||
uint32_t g_atvsEndPointHandle; // Authentication Token Validation Service endpoint handle
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus SSCS_CALL
|
||||
@@ -131,35 +150,73 @@ ValidateAuthToken(
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Initialize the Client Ipc Subsystem
|
||||
if (IpcClientInit("CASA_AuthTokenValidate",
|
||||
true,
|
||||
DebugLevel,
|
||||
false) == 0)
|
||||
//
|
||||
// First load the library. We load it itself to keep the system
|
||||
// from unloading it in-case that the application unloads us. Some
|
||||
// applications such as PAM application will repeateadly load and
|
||||
// unload us.
|
||||
void* libHandle = OpenLibrary(IpcClientLibraryPath);
|
||||
if (libHandle)
|
||||
{
|
||||
// Open endpoint for the Authentication Token Validation Service
|
||||
if (IpcClientOpenInetRemoteEndPoint(5000,
|
||||
0x7F000001,
|
||||
0,
|
||||
&atvsEndPointHandle) == 0)
|
||||
// The Ipc library has been loaded, now get the symbols that we need.
|
||||
g_ipcInitPtr = GetFunctionPtr(libHandle, "IpcClientInit");
|
||||
g_ipcShutdownPtr = GetFunctionPtr(libHandle, "IpcClientShutdown");
|
||||
//g_ipcOpenEndPointPtr = GetFunctionPtr(libHandle, "IpcClientOpenInetRemoteEndPoint");
|
||||
g_ipcOpenEndPointPtr = GetFunctionPtr(libHandle, "IpcClientOpenUnixRemoteEndPoint");
|
||||
g_ipcCloseEndPointPtr = GetFunctionPtr(libHandle, "IpcClientCloseRemoteEndPoint");
|
||||
g_ipcSubmitReq = GetFunctionPtr(libHandle, "IpcClientSubmitReq");
|
||||
if (g_ipcInitPtr == NULL
|
||||
|| g_ipcShutdownPtr == NULL
|
||||
|| g_ipcOpenEndPointPtr == NULL
|
||||
|| g_ipcCloseEndPointPtr == NULL
|
||||
|| g_ipcSubmitReq == NULL)
|
||||
{
|
||||
// Success
|
||||
g_moduleInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ValidateAuthToken- Failed to open remote endpoint\n", 0);
|
||||
IpcClientShutdown();
|
||||
DbgTrace(0, "-ValidateAuthToken- Failed to get needed Ipc library function pointer\n", 0);
|
||||
IdenTokenUninit();
|
||||
PrincipalIfUninit();
|
||||
ConfigIfUninit();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((g_ipcInitPtr)("CASA_AuthTokenValidate",
|
||||
g_multiThreadedApplication,
|
||||
DebugLevel,
|
||||
false) == 0)
|
||||
{
|
||||
// Open endpoint for the Authentication Token Validation Service
|
||||
//if ((g_ipcOpenEndPointPtr)(5000,
|
||||
// 0x7F000001,
|
||||
// 0,
|
||||
// &g_atvsEndPointHandle) == 0)
|
||||
if ((g_ipcOpenEndPointPtr)(DOMAIN_SOCKET_FILE_NAME,
|
||||
0,
|
||||
&g_atvsEndPointHandle) == 0)
|
||||
{
|
||||
// Success
|
||||
g_moduleInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ValidateAuthToken- Failed to open remote endpoint\n", 0);
|
||||
(g_ipcShutdownPtr)();
|
||||
IdenTokenUninit();
|
||||
PrincipalIfUninit();
|
||||
ConfigIfUninit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ValidateAuthToken- Ipc subsystem initialization failed\n", 0);
|
||||
(g_ipcShutdownPtr)();
|
||||
IdenTokenUninit();
|
||||
PrincipalIfUninit();
|
||||
ConfigIfUninit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-ValidateAuthToken- Ipc subsystem initialization failed\n", 0);
|
||||
IdenTokenUninit();
|
||||
PrincipalIfUninit();
|
||||
ConfigIfUninit();
|
||||
DbgTrace(0, "-ValidateAuthToken- Failed to load Ipc library, error = %d\n", dlerror());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -193,13 +250,18 @@ ValidateAuthToken(
|
||||
char *pIdenTokenData;
|
||||
int idenTokenDataLen;
|
||||
|
||||
// Assume failure
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_AUTHENTICATION_FAILURE);
|
||||
|
||||
// Token was decoded successfully, now submit the authentication token to the
|
||||
// authentication token validation service.
|
||||
if (IpcClientSubmitReq(atvsEndPointHandle,
|
||||
pDecodedTokenBuf,
|
||||
decodedTokenBufLen,
|
||||
&pIdenTokenData,
|
||||
&idenTokenDataLen) == 0)
|
||||
if ((g_ipcSubmitReq)(g_atvsEndPointHandle,
|
||||
pDecodedTokenBuf,
|
||||
decodedTokenBufLen,
|
||||
&pIdenTokenData,
|
||||
&idenTokenDataLen) == 0)
|
||||
{
|
||||
// The submit succeeded, make sure that we got some identity data back.
|
||||
if (pIdenTokenData)
|
||||
@@ -287,6 +349,51 @@ exit:
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static void __attribute__((constructor))
|
||||
so_init()
|
||||
//
|
||||
// Arguments In: None.
|
||||
//
|
||||
// Arguments Out: None.
|
||||
//
|
||||
// Returns: Nothing.
|
||||
//
|
||||
// Abstract: Library initialization routine.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
// Check for environment variable specifying that the application is
|
||||
// multi-threaded.
|
||||
if (getenv(APPLICATION_NOT_MULTI_THREADED) != NULL)
|
||||
{
|
||||
// The parameter has been configured, remember it.
|
||||
g_multiThreadedApplication = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
static void __attribute__((destructor))
|
||||
so_fini()
|
||||
//
|
||||
// Arguments In: None.
|
||||
//
|
||||
// Arguments Out: None.
|
||||
//
|
||||
// Returns: Nothing.
|
||||
//
|
||||
// Abstract: Library un-initialization routine.
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
if (g_ipcShutdownPtr)
|
||||
(g_ipcShutdownPtr)();
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
||||
Reference in New Issue
Block a user