The example below returns true if the user has special access permission to view the realm. If the user has directory manager privileges, the user can view the realm.
<@ lib="SmAzAPI" func="activeRule" param="" @>
*************************************************************
int SM_EXTERN activeRule(
const Sm_Api_Context_t* lpApiContext,
// the structure that provides API context
const Sm_Api_UserContext_t* lpUserContext,
// the structure that provides user context
const Sm_Api_RequestContext_t* lpReqContext,
// the structure that provides request context
const char* lpszParam,
// the parameter string (null-terminated)
const int nBytesOutBuf,
// the maximum size of the output buffer
char* lpszOutBuf,
// the output buffer to hold the null-terminated result
const int nBytesErrBuf,
// the maximum size of the error message buffer
char* lpszErrBuf)
// the output buffer to hold the null-terminated error message
{
/* User Context is required to use the functions like fGetProp, fSetProp.. */
if(!lpUserContext->bIsUserContext)
{
strncpy (lpszErrBuf, "No User Context ", nBytesErrBuf);
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
/*
// The DN to look for the attribute "uniquemember"
// If the user is listed as the member of the above attribute,
// it has directory manager privileges.
*/
char lpszDn[] = "cn=Directory Administrators,ou=Groups,o=airius.com";
char lpszDnvalue[256];
memset(lpszDnvalue, 0, sizeof(lpszDnvalue));
/*
// fGetDnProp function is used to retrieve an attribute value
// in a directory entry.
*/
int getResult = lpUserContext->fGetDnProp(
lpUserContext->lpParam,
lpszDn,
"uniquemember",
sizeof(lpszDnvalue),
lpszDnvalue);
/*
// If no error occurs, fGenDnProp will return the length of the
// buffer lpszDnvalue. Otherwise the function returns 0.
*/
if(getResult > 0)
{
/* Check to see if the user is present in the list. */
if(strpbrk(lpszDnvalue, lpUserContext->lpszUserName) != NULL)
{
/* The result "true" is placed in the output buffer. */
strncpy(lpszOutBuf, "true", nBytesOutBuf);
lpszOutBuf[nBytesOutBuf-1] = '\0';
return strlen(lpszOutBuf);
}
else
{
strncpy(lpszOutBuf, "false", nBytesOutBuf);
lpszOutBuf[nBytesOutBuf-1] = '\0';
return strlen(lpszOutBuf);
}
}
else
{
strncpy(lpszErrBuf, "Failed to get attribute value for the DN ",
nBytesErrBuf);
strncat( (lpszErrBuf + strlen(lpszErrBuf)), lpszDn,
(nBytesErrBuf-strlen(lpszErrBuf)));
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
/* everything failed.... */
return 0;
}
| Copyright © 2010 CA. All rights reserved. | Email CA about this topic |