Previous Topic: SmEventRelease()

Next Topic: Configuring the Policy Server for the Event Handler

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.

<@ lib="SmAzAPI" func="activePolicy" param="Accounting" @>
*************************************************************
int SM_EXTERN activePolicy(
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
{
/* 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 is
   requested. */
   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;
}


Copyright © 2010 CA. All rights reserved. Email CA about this topic