Example of an Active Policy
This function returns true if the user belongs to the organizational unit specified in the parameter (param) field of the active policy expression.
casso126
This function returns true if the user belongs to the organizational unit specified in the parameter
(param
) field of the active policy expression.<@ lib="SmAzAPI" func="activePolicy" param="Accounting" @>*************************************************************int SM_EXTERN activePolicy(const Sm_Api_Context_t* lpApiContext,// the structure that provides API contextconst Sm_Api_UserContext_t* lpUserContext,// the structure that provides user contextconst Sm_Api_RequestContext_t* lpReqContext,// the structure that provides request contextconst char* lpszParam,// the parameter string (null-terminated)const int nBytesOutBuf,// the maximum size of the output bufferchar* lpszOutBuf,// the output buffer to hold the null-terminated attribute valueconst int nBytesErrBuf,// the maximum size of the error message bufferchar* 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;}/* Buffer to store all the organizational units user belongs to. */char lpszOrgUnit[30];memset(lpszOrgUnit, 0, sizeof(lpszOrgUnit));/*// Check to see if an organizational unit has been// entered in the parameter.*/if(lpszParam == NULL || strlen(lpszParam) == 0){strncpy (lpszErrBuf, "Organizational unit is not entered ",nBytesErrBuf);lpszErrBuf[nBytesErrBuf-1] = '\0';return -1;}/* Get all the organizational 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 user password from user's profile attribute ",nBytesErrBuf);lpszErrBuf[nBytesErrBuf-1] = '\0';return -1;}else{/* Check if the user belongs to the organization unit that isrequested. */if(strstr(lpszOrgUnit, lpszParam) != NULL){/*// Yes the user belongs to the organization unit// mentioned in the parameter field of active policy.*/strncpy(lpszOutBuf, "true", nBytesOutBuf);lpszOutBuf[nBytesOutBuf-1] = '\0';return strlen(lpszOutBuf);}else{strncpy (lpszErrBuf,"The user does not belong to the requested organizational unit ",nBytesErrBuf);lpszErrBuf[nBytesErrBuf-1] = '\0';return -1;}}/* everything failed.... */return 0;}