(file) Return to SystemWindows.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/SystemWindows.cpp between version 1.37 and 1.38

version 1.37, 2004/05/26 17:04:39 version 1.38, 2004/06/22 22:16:21
Line 50 
Line 50 
 #include <sys/types.h> #include <sys/types.h>
 #include <windows.h> #include <windows.h>
 #include <process.h> #include <process.h>
   #include <lm.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 364 
Line 365 
  
 Boolean System::isGroupMember(const char* userName, const char* groupName) Boolean System::isGroupMember(const char* userName, const char* groupName)
 { {
     //ATTN: Implement this method to verify that the user name     Boolean retVal = false;
     //      is a member of the group  
     return true;     LPLOCALGROUP_USERS_INFO_0 pBuf = NULL;
      DWORD dwLevel = 0;
      DWORD dwFlags = LG_INCLUDE_INDIRECT ;
      DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
      DWORD dwEntriesRead = 0;
      DWORD dwTotalEntries = 0;
      NET_API_STATUS nStatus;
   
   
      //
      // Call the NetUserGetLocalGroups function
      // specifying information level 0.
      //
      // The LG_INCLUDE_INDIRECT flag specifies that the
      // function should also return the names of the local
      // groups in which the user is indirectly a member.
      //
      nStatus = NetUserGetLocalGroups(NULL,
                                      (LPCWSTR)userName,
                                      dwLevel,
                                      dwFlags,
                                      (LPBYTE *) &pBuf,
                                      dwPrefMaxLen,
                                      &dwEntriesRead,
                                      &dwTotalEntries);
   
      //
      // If the call succeeds,
      //
      if (nStatus == NERR_Success)
      {
         LPLOCALGROUP_USERS_INFO_0 pTmpBuf;
         DWORD i;
         DWORD dwTotalCount = 0;
   
         if ((pTmpBuf = pBuf) != NULL)
         {
            //
            // Loop through the local groups that the user belongs
            // and find the matching group name.
            //
            for (i = 0; i < dwEntriesRead; i++)
            {
               //
               // Compare the user's group name to groupName.
               //
               if ( strcmp ((char *)pTmpBuf->lgrui0_name, groupName) == 0 )
               {
                    // User is a member of the group.
                    retVal = true;
                    break;
               }
   
               pTmpBuf++;
               dwTotalCount++;
            }
         }
      }
   
      //
      // Free the allocated memory.
      //
      if (pBuf != NULL)
         NetApiBufferFree(pBuf);
   
      //
      // If the given user and group are not found in the local group
      // then try on the global groups.
      //
      if (!retVal)
      {
          LPGROUP_USERS_INFO_0 pBuf = NULL;
          dwLevel = 0;
          dwPrefMaxLen = MAX_PREFERRED_LENGTH;
          dwEntriesRead = 0;
          dwTotalEntries = 0;
   
          //
          // Call the NetUserGetGroups function, specifying level 0.
          //
          nStatus = NetUserGetGroups(NULL,
                                     (LPCWSTR)userName,
                                     dwLevel,
                                     (LPBYTE*)&pBuf,
                                     dwPrefMaxLen,
                                     &dwEntriesRead,
                                     &dwTotalEntries);
          //
          // If the call succeeds,
          //
          if (nStatus == NERR_Success)
          {
             LPGROUP_USERS_INFO_0 pTmpBuf;
             DWORD i;
             DWORD dwTotalCount = 0;
   
             if ((pTmpBuf = pBuf) != NULL)
             {
                //
                // Loop through the global groups to which the user belongs
                // and find the matching group name.
                //
                for (i = 0; i < dwEntriesRead; i++)
                {
                   //
                   // Compare the user's group name to groupName.
                   //
                   if ( strcmp ((char *)pTmpBuf->grui0_name, groupName) == 0 )
                   {
                        // User is a member of the group.
                        retVal = true;
                        break;
                   }
   
                   pTmpBuf++;
                   dwTotalCount++;
                }
             }
          }
   
          //
          // Free the allocated buffer.
          //
          if (pBuf != NULL)
             NetApiBufferFree(pBuf);
      }
   
      return retVal;
 } }
  
 Uint32 System::getPID() Uint32 System::getPID()


Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2