Shared Services Migration and User Management API Example
/*
Declaration of Include files
*/
#if defined _WIN32 || defined _WINDOWS
#include
#endif
#include
#include
#include
#pragma pack (1)
#include
#include
#pragma pack ()
/***************************************************************************************/
/*-------------------------- Example Usage Starts Here --------------------------------*/
/***************************************************************************************/
/*
ESS_FUNC_M EssSetSSSecurityMode(ESS_HCTX_T hCtx,
ESS_USHORT_T Option,
ESS_STR_T Password);
*/
ESS_FUNC_M ESS_SS_SetSSSecurityMode(ESS_HCTX_T hCtx)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_STR_T newpassword = ESS_NULL;
ESS_USHORT_T option;
/* New Shared Services Native User Password Option:
*
* 0 to use user provided password
* 1 to use the user name as password
* 2 to automatically generate a password
**/
option = 1; /* Using user name as password */
sts = EssSetSSSecurityMode(hCtx, option, newpassword);
if(sts)
printf("Failed to migrate Analytic Services Server to Shared Services mode.\n");
return (sts);
}
/*
ESS_FUNC_M EssGetEssbaseSecurityMode (ESS_HCTX_T hCtx,
ESS_PSECURITY_MODE_T mode);
*/
ESS_FUNC_M ESS_SS_GetEssbaseSecurityMode(ESS_HCTX_T hCtx)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_SECURITY_MODE_T mode;
sts = EssGetEssbaseSecurityMode(hCtx, &mode);
if(sts)
{
printf("Failed to get Essbase Security mode.\n");
}
else
{
printf("Essbase Security Mode : %d\n", mode);
}
return(sts);
}
/*
ESS_FUNC_M EssListSSMigrFailedUsers(ESS_HCTX_T,
ESS_PUSHORT_T,
ESS_PPUSERNAME_T);
*/
ESS_FUNC_M ESS_SS_ListSSMigrFailedUsers(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_PUSERNAME_T pNativeUserList = NULL;
ESS_USHORT_T Count = 0,
index;
sts = EssListSSMigrFailedUsers(hCtx, &Count, &pNativeUserList);
if (!sts)
{
if (Count && pNativeUserList)
{
printf ("\n------- User List -------\n\n");
for (index = 0; index < Count; index++)
{
if (pNativeUserList[index])
printf ("%s\n", pNativeUserList[index]);
}
EssFree(hInst, pNativeUserList);
}
else
printf("\nUser list is empty\n\n");
}
else
printf("Failed to get Shared Services migration failed Users list.\n");
return (sts);
}
/*
ESS_FUNC_M EssListSSMigrFailedGroups(ESS_HCTX_T,
ESS_PUSHORT_T,
ESS_PPUSERNAME_T);
*/
ESS_FUNC_M ESS_SS_ListSSMigrFailedGroups(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_PUSERNAME_T pNativeUserList = NULL;
ESS_USHORT_T Count = 0,
index;
sts = EssListSSMigrFailedGroups(hCtx, &Count, &pNativeUserList);
if (!sts)
{
if (Count && pNativeUserList)
{
printf ("\n------- Group List -------\n\n");
for (index = 0; index < Count; index++)
{
if (pNativeUserList[index])
printf ("%s\n", pNativeUserList[index]);
}
EssFree(hInst, pNativeUserList);
}
else
printf("\nGroup list is empty\n\n");
}
else
printf("Failed to get Shared Services migration failed Groups list.\n");
return (sts);
}
/*
ESS_FUNC_M EssSetUserToSS (ESS_HCTX_T hCtx,
ESS_STR_T UserName,
ESS_USHORT_T Option,
ESS_STR_T Password);
*/
ESS_FUNC_M ESS_SS_SetUserToSS(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_USHORT_T option;
ESS_STR_T userName = ESS_NULL;
ESS_STR_T newpassword = ESS_NULL;
sts = EssAlloc(hInst, sizeof(ESS_USERNAME_T), &userName);
if(sts)
return (sts);
memset(userName, 0, sizeof(ESS_USERNAME_T));
strcpy( userName, "essexer");
/* New Shared Services Native User Password Option:
*
* 0 to use user provided password
* 1 to use the user name as password
* 2 to automatically generate a password
**/
option = 1; /* Using user name as password */
sts = EssSetUserToSS(hCtx, userName, option, newpassword);
if(sts)
printf("Failed to migrate User %s to Shared Services mode.\n", userName);
if (userName)
EssFree(hInst, userName);
return (sts);
}
/*
ESS_FUNC_M EssSetGroupToSS (ESS_HCTX_T hCtx,
ESS_STR_T GroupName);
*/
ESS_FUNC_M ESS_SS_SetGroupToSS(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_STR_T groupName = ESS_NULL;
sts = EssAlloc(hInst, sizeof(ESS_USERNAME_T), &groupName);
if(sts)
return (sts);
memset(groupName, 0, sizeof(ESS_USERNAME_T));
strcpy( groupName, "essgrp");
sts = EssSetGroupToSS(hCtx, groupName);
if(sts)
printf("Failed to migrate Group %s to Shared Services mode.\n", groupName);
if (groupName)
EssFree(hInst, groupName);
return (sts);
}
/*
ESS_FUNC_M EssSetUsersToSS(ESS_HCTX_T hCtx,
ESS_USHORT_T Option,
ESS_STR_T Password);
*/
ESS_FUNC_M ESS_SS_SetUsersToSS(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_USHORT_T option;
ESS_STR_T newpassword = ESS_NULL;
/* New Shared Services Native User Password Option:
*
* 0 to use user provided password
* 1 to use the user name as password
* 2 to automatically generate a password
**/
option = 0; /* Using user provided password */
sts = EssAlloc(hInst, sizeof(ESS_PASSWORD_T), &newpassword);
if(sts)
return (sts);
memset(newpassword, 0, sizeof(ESS_PASSWORD_T));
strcpy( newpassword, "password");
sts = EssSetUsersToSS(hCtx, option, newpassword);
if(sts)
printf("Failed to migrate Users to Shared Services mode.\n");
if (newpassword)
EssFree(hInst, newpassword);
return (sts);
}
/*
ESS_FUNC_M EssSetGroupsToSS(ESS_HCTX_T hCtx);
*/
ESS_FUNC_M ESS_SS_SetGroupsToSS(ESS_HCTX_T hCtx)
{
ESS_STS_T sts = ESS_STS_NOERR;
sts = EssSetGroupsToSS(hCtx);
if(sts)
printf("Failed to migrate Groups to Shared Services mode.\n");
return (sts);
}
/*
ESS_FUNC_M EssSetEasLocation (ESS_HCTX_T hCtx,
ESS_STR_T EasLocation);
*/
ESS_FUNC_M ESS_SS_SetEasLocation(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_STR_T easLoc = ESS_NULL;
/* Eas Location */
sts = EssAlloc(hInst, sizeof(ESS_PATHLEN), &easLoc);
if(sts)
return (sts);
memset(easLoc, 0, sizeof(ESS_PATHLEN));
strcpy( easLoc, "localhost:10080");
sts = EssSetEasLocation(hCtx, easLoc);
if (sts)
printf("Failed to set EAS Location.\n");
if (easLoc)
EssFree(hInst, easLoc);
return (sts);
}
/*
ESS_FUNC_M EssReRegisterApplication (ESS_HCTX_T hCtx,
ESS_STR_T AppName,
ESS_BOOL_T AllApps);
*/
ESS_FUNC_M ESS_SS_ReRegisterApplication(ESS_HCTX_T hCtx, ESS_HINST_T hInst)
{
ESS_STS_T sts = ESS_STS_NOERR;
ESS_BOOL_T allApps;
ESS_STR_T appName = ESS_NULL;
sts = EssAlloc(hInst, sizeof(ESS_APPNAME_T), &appName);
if(sts)
return (sts);
memset(appName, 0, sizeof(ESS_APPNAME_T));
strcpy( appName, "Sample");
/* Do you want All applications re-registered?
* Enter ESS_TRUE for Yes
* ESS_FALSE for No
**/
allApps = ESS_FALSE; /* Re-registering only 1 application */
sts = EssReRegisterApplication(hCtx, appName, allApps);
if (sts)
printf("Failed to Re-register Application %s.\n", appName);
if (appName)
EssFree(hInst, appName);
return (sts);
}
/***************************************************************************************/
/*-------------------------- Example Usage Starts Here --------------------------------*/
/***************************************************************************************/
/***************************************************************************************/
/*--------------------------------- Testing API ---------------------------------------*/
/***************************************************************************************/
/*
Declaration of handles and connection information variables
*/
/*****************************************************/
/*************** MAIN FUNCTION ***********************/
/*****************************************************/
main()
{
ESS_HINST_T hInst;
ESS_HCTX_T hCtx;
ESS_SVRNAME_T srvrName = "localhost";
ESS_USERNAME_T userName = "essexer";
ESS_PASSWORD_T pswd = "password";
ESS_STS_T sts = ESS_STS_NOERR;
ESS_USHORT_T Items;
ESS_PAPPDB_T pAppsDbs = ESS_NULL;
ESS_INIT_T InitStruct = {ESS_API_VERSION,
ESS_NULL,
0L,
255,
ESS_NULL,
ESS_NULL,
ESS_NULL,
ESS_NULL,
ESS_NULL,
ESS_NULL,
ESS_NULL,
0L
};
sts = EssInit(&InitStruct, &hlnst);
if (sts)
{
printf("EssInit failure: %ld\n", sts);
exit ((int) sts);
}
sts = EssLogin(hInst, srvrName, userName, pswd, &Items, &pAppsDbs, &hCtx);
if (sts)
{
printf("EssLogin failure: %ld\n", sts);
exit ((int) sts);
}
sts = ESS_SS_SetSSSecurityMode(hCtx);
if (sts)
printf("ESS_SS_SetSSSecurityMode failed: %ld\n", sts);
sts = ESS_SS_GetEssbaseSecurityMode(hCtx);
if (sts)
printf("ESS_SS_GetEssbaseSecurityMode failed: %ld\n", sts);
sts = ESS_SS_ListSSMigrFailedUsers(hCtx, hInst);
if (sts)
printf("ESS_SS_ListSSMigrFailedUsers failed: %ld\n", sts);
sts = ESS_SS_ListSSMigrFailedGroups(hCtx, hInst);
if (sts)
printf("ESS_SS_ListSSMigrFailedGroups failed: %ld\n", sts);
sts = ESS_SS_SetUserToSS(hCtx, hInst);
if (sts)
printf("ESS_SS_SetUserToSS failed: %ld\n", sts);
sts = ESS_SS_SetGroupToSS(hCtx, hInst);
if (sts)
printf("ESS_SS_SetGroupToSS failed: %ld\n", sts);
sts = ESS_SS_SetUsersToSS(hCtx, hInst);
if (sts)
printf("ESS_SS_SetUsersToSS failed: %ld\n", sts);
sts = ESS_SS_SetGroupsToSS(hCtx);
if (sts)
printf("ESS_SS_SetGroupsToSS failed: %ld\n", sts);
sts = ESS_SS_SetEasLocation(hCtx, hInst);
if (sts)
printf("ESS_SS_SetEasLocation failed: %ld\n", sts);
sts = ESS_SS_ReRegisterApplication(hCtx, hInst);
if (sts)
printf("ESS_SS_ReRegisterApplication failed: %ld\n", sts);
sts = EssLogout(hCtx);
sts = EssTerm(hInst);
}