(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.33 and 1.38

version 1.33, 2003/11/12 18:21:34 version 1.38, 2004/06/22 22:16:21
Line 26 
Line 26 
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com) // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
 //  
 //              Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com) //              Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
   //              Bapu Patil (bapu_patil@hp.com)
 // //
 // Modified By: Dave Rosckes (rosckes@us.ibm.com) // Modified By: Dave Rosckes (rosckes@us.ibm.com)
   //              Terry Martin, Hewlett-Packard Company (terry.martin@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include "System.h" #include "System.h"
  
 PEGASUS_NAMESPACE_BEGIN  
   
 #include <windows.h> #include <windows.h>
 #ifndef _WINSOCKAPI_ #ifndef _WINSOCKAPI_
 #include <winsock2.h> #include <winsock2.h>
Line 48 
Line 47 
 #include <io.h> #include <io.h>
 #include <conio.h> #include <conio.h>
 #include <direct.h> #include <direct.h>
 #include <sys/stat.h>  
 #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
  
 #define ACCESS_EXISTS 0 #define ACCESS_EXISTS 0
 #define ACCESS_WRITE 2 #define ACCESS_WRITE 2
Line 179 
Line 180 
  
 String System::getHostName() String System::getHostName()
 { {
     static char hostname[64];      static char hostname[PEGASUS_MAXHOSTNAMELEN];
  
     if (!*hostname)     if (!*hostname)
         gethostname(hostname, sizeof(hostname));         gethostname(hostname, sizeof(hostname));
Line 362 
Line 363 
     return (String("Administrator"));     return (String("Administrator"));
 } }
  
   Boolean System::isGroupMember(const char* userName, const char* groupName)
   {
      Boolean retVal = false;
   
      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()
 { {
     return _getpid();     return _getpid();
Line 399 
Line 534 
   return (strcasecmp(_fullpath( full, path_slash, _MAX_PATH ), path_slash) == 0) ? true : false;   return (strcasecmp(_fullpath( full, path_slash, _MAX_PATH ), path_slash) == 0) ? true : false;
 } }
  
   // Changes file permissions on the given file.
   Boolean System::changeFilePermissions(const char* path, mode_t mode)
   {
       // ATTN: File permissions are not currently defined in Windows
       return true;
   }
   
 void System::openlog(const String ident) void System::openlog(const String ident)
 { {
     return;     return;


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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2