This active response returns the common name (cn) of the user, if the user belongs to the organizational unit specified in the parameter (param) field of the active response expression.
<@ lib="SmAzAPI" func="activeResponse" param="Human Resources" @>
***********************************************************
int SM_EXTERN activeResponse(
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 attribute value */
const int nBytesErrBuf,
/* the maximum size of the error message buffer */
char* lpszErrBuf)
/* the output buffer to hold the null-terminated error message */
{
memset(lpszOutBuf, 0, sizeof(lpszOutBuf));
if(!lpUserContext->bIsUserContext)
{
strncpy (lpszErrBuf, "No User Context ", nBytesErrBuf);
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
/* Store all the organizational units to which the user belongs. */
char lpszOrgUnit[30];
memset(lpszOrgUnit, 0, sizeof(lpszOrgUnit));
/* store the common name of the user. */
char lpszCN[30];
memset(lpszCN, 0, sizeof(lpszCN));
/* Check to see if a parameter is requested. */
if(lpszParam == NULL || strlen(lpszParam) == 0)
{
strncpy (lpszErrBuf, "Organizational unit is not entered ",
nBytesErrBuf);
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
/* Get all the organization units to which the user belongs. */
int getResult = lpUserContext->fGetProp (
lpUserContext->lpParam,
"ou", /* Attribute name */
sizeof (lpszOrgUnit), lpszOrgUnit);
if (getResult < 0)
{
strncpy (lpszErrBuf,
"Failed to get organization unit for the user's profile ",
nBytesErrBuf);
strncat( (lpszErrBuf + strlen(lpszErrBuf)),
lpUserContext->lpszUserName,
(nBytesErrBuf-strlen(lpszErrBuf)));
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
else
{
/* Check if the user belongs to the organization unit that is requested. */
if(strstr(lpszOrgUnit, lpszParam) != NULL)
{
if((lpUserContext->fGetProp(lpUserContext->lpParam,
"cn",sizeof(lpszCN),lpszCN)) > 0)
{
strncpy(lpszOutBuf, lpszCN, nBytesOutBuf);
lpszOutBuf[nBytesOutBuf-1] = '\0';
return strlen(lpszOutBuf);
} /* end of fGetProp */
else
{
strncpy (lpszErrBuf,
"Failed to get user common name from user's profile attribute ",
nBytesErrBuf);
strncat( (lpszErrBuf + strlen(lpszErrBuf)),
lpUserContext->lpszUserName,
(nBytesErrBuf-strlen(lpszErrBuf)));
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
} /* end of strstr */
else
{
strncpy (lpszErrBuf,
"The user does not belong to the requested organizational unit ",
nBytesErrBuf);
lpszErrBuf[nBytesErrBuf-1] = '\0';
return -1;
}
}
/* everything failed.... */
return 0;
}
#ifndef _WIN32
}
#endif
| Copyright © 2010 CA. All rights reserved. | Email CA about this topic |