(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.68 and 1.79.2.1

version 1.68, 2006/10/31 19:47:32 version 1.79.2.1, 2008/02/13 08:27:02
Line 46 
Line 46 
 #include <windows.h> #include <windows.h>
 #include <process.h> #include <process.h>
 #include <lm.h> #include <lm.h>
   #include <Pegasus/Common/Tracer.h>
  
 #define SECURITY_WIN32 #define SECURITY_WIN32
 #include <security.h> #include <security.h>
Line 166 
Line 167 
  
 String System::getHostName() String System::getHostName()
 { {
     static char hostname[PEGASUS_MAXHOSTNAMELEN + 1];      static String _hostname;
       if (0 == _hostname.size())
     if (!*hostname)  
     {     {
           char hostname[PEGASUS_MAXHOSTNAMELEN + 1];
           //initialize the buffer to handle the case where gethostname fails.
           hostname[0] = 0;
         gethostname(hostname, sizeof(hostname));         gethostname(hostname, sizeof(hostname));
     }  
     hostname[sizeof(hostname)-1] = 0;     hostname[sizeof(hostname)-1] = 0;
           _hostname.assign(hostname);
     return hostname;      }
       return _hostname;
 } }
  
 String System::getFullyQualifiedHostName () String System::getFullyQualifiedHostName ()
Line 186 
Line 189 
         String hostname = getHostName();         String hostname = getHostName();
         struct hostent* hostEnt;         struct hostent* hostEnt;
  
         hostEnt = gethostbyname((const char *)hostname.getCString());          hostEnt = getHostByName((const char *)hostname.getCString());
         if (hostEnt == NULL)         if (hostEnt == NULL)
         {         {
             return String::EMPTY;             return String::EMPTY;
Line 335 
Line 338 
         if (wcscmp(computerName, userDomain) != 0)         if (wcscmp(computerName, userDomain) != 0)
         {         {
         //userId.append(userDomain);         //userId.append(userDomain);
         Uint32 n = wcslen(userDomain);          Uint32 n = (Uint32)wcslen(userDomain);
         for(unsigned long i = 0; i < n; i++)         for(unsigned long i = 0; i < n; i++)
         {         {
             userId.append(Char16(userDomain[i]));             userId.append(Char16(userDomain[i]));
         }         }
                 userId.append("\\");                 userId.append("\\");
                 //userId.append(userName);                 //userId.append(userName);
         n = wcslen(userName);          n = (Uint32)wcslen(userName);
         for(unsigned long i = 0; i < n; i++)         for(unsigned long i = 0; i < n; i++)
         {         {
             userId.append(Char16(userName[i]));             userId.append(Char16(userName[i]));
         }         }
  
         } else      }
       else
         {         {
                 //userId.append(userName);                 //userId.append(userName);
         Uint32 n = wcslen(userName);          Uint32 n = (Uint32)wcslen(userName);
         for(unsigned long i = 0; i < n; i++)         for(unsigned long i = 0; i < n; i++)
         {         {
             userId.append(Char16(userName[i]));             userId.append(Char16(userName[i]));
Line 382 
Line 386 
         userId.append(Char16(pUserName[i]));         userId.append(Char16(pUserName[i]));
     }     }
  
   
     return userId;     return userId;
 #endif #endif
 } }
Line 394 
Line 397 
     char pcSalt[3] = {0};     char pcSalt[3] = {0};
  
     strncpy(pcSalt, salt, 2);     strncpy(pcSalt, salt, 2);
     dwByteCount = strlen(password);      dwByteCount = (DWORD)strlen(password);
     memcpy(pbBuffer, password, dwByteCount);     memcpy(pbBuffer, password, dwByteCount);
     for (DWORD i=0; (i<dwByteCount) || (i>=PW_BUFF_LEN); i++)     for (DWORD i=0; (i<dwByteCount) || (i>=PW_BUFF_LEN); i++)
             (i%2 == 0) ? pbBuffer[i] ^= pcSalt[1] : pbBuffer[i] ^= pcSalt[0];             (i%2 == 0) ? pbBuffer[i] ^= pcSalt[1] : pbBuffer[i] ^= pcSalt[0];
Line 437 
Line 440 
     LPUSER_INFO_1 pUserInfo = NULL;     LPUSER_INFO_1 pUserInfo = NULL;
     NET_API_STATUS nStatus = NULL;     NET_API_STATUS nStatus = NULL;
  
     // Make a copy of the specified username, it cannot be used directly because it's      // Make a copy of the specified username, it cannot be used directly
     // declared as const and strchr() may modify the string.      // because it's declared as const and strchr() may modify the string.
     strncpy(tUserName, userName, sizeof(tUserName) - 1);     strncpy(tUserName, userName, sizeof(tUserName) - 1);
     tUserName[sizeof(tUserName)- 1] = '\0';     tUserName[sizeof(tUserName)- 1] = '\0';
  
Line 450 
Line 453 
         strcpy(mUserName, pbs+1);         strcpy(mUserName, pbs+1);
         usingDomain = true;         usingDomain = true;
  
     } else if ((NULL != (pbs = (strchr(tUserName, '@')))) ||      }
       else if ((NULL != (pbs = (strchr(tUserName, '@')))) ||
                (NULL != (pbs = (strchr(tUserName, '.')))))                (NULL != (pbs = (strchr(tUserName, '.')))))
     {     {
         *pbs = '\0';         *pbs = '\0';
Line 458 
Line 462 
         strcpy(mUserName, tUserName);         strcpy(mUserName, tUserName);
         usingDomain = true;         usingDomain = true;
  
     } else      }
       else
     {     {
         strcpy(mDomainName, ".");         strcpy(mDomainName, ".");
         strcpy(mUserName, tUserName);         strcpy(mUserName, tUserName);
     }     }
  
     //convert domain name to unicode     //convert domain name to unicode
     if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))      if (!MultiByteToWideChar(
               CP_ACP, 0, mDomainName, -1, wDomainName,
               (int)(strlen(mDomainName) + 1)))
     {     {
         return false;         return false;
     }     }
  
     //convert username to unicode     //convert username to unicode
     if (!MultiByteToWideChar(CP_ACP, 0, mUserName, -1, wUserName, strlen(mUserName)+1))      if (!MultiByteToWideChar(
               CP_ACP, 0, mUserName, -1, wUserName, (int)(strlen(mUserName) + 1)))
     {     {
         return false;         return false;
     }     }
Line 482 
Line 490 
         DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName);         DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName);
         if (rc == NERR_Success)         if (rc == NERR_Success)
         {         {
             wcscpy(wDomainName, (LPWSTR) pComputerName); //this is automatically prefixed with "\\"              // this is automatically prefixed with "\\"
               wcscpy(wDomainName, (LPWSTR) pComputerName);
         }         }
         /*         /*
         else         else
         {         {
             // failover             // failover
             // ATTN: This is commented out until there is resolution on Bugzilla 2236. -hns 2/2005              // ATTN: This is commented out until there is resolution on
               // Bugzilla 2236. -hns 2/2005
             // This needs to be more thoroughly tested when we uncomment it out.             // This needs to be more thoroughly tested when we uncomment it out.
  
             PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL;             PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL;
Line 498 
Line 508 
                              mDomainName,                              mDomainName,
                              NULL,                              NULL,
                              NULL,                              NULL,
                              DS_DIRECTORY_SERVICE_REQUIRED,  //not sure what flags we want here                               //not sure what flags we want here
                                DS_DIRECTORY_SERVICE_REQUIRED,
                              &DomainControllerInfo);                              &DomainControllerInfo);
  
             if (rc == ERROR_SUCCESS && DomainControllerInfo)             if (rc == ERROR_SUCCESS && DomainControllerInfo)
Line 506 
Line 517 
                 strcpy(mDomainName, DomainControllerInfo->DomainName);                 strcpy(mDomainName, DomainControllerInfo->DomainName);
                 NetApiBufferFree(DomainControllerInfo);                 NetApiBufferFree(DomainControllerInfo);
  
                 if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))                  if (!MultiByteToWideChar(
                           CP_ACP, 0, mDomainName, -1, wDomainName,
                           strlen(mDomainName) + 1))
                 {                 {
                     return false;                     return false;
                 }                 }
Line 568 
Line 581 
         strcpy(mUserName, pbs+1);         strcpy(mUserName, pbs+1);
         usingDomain = true;         usingDomain = true;
  
     } else if ((NULL != (pbs = (strchr(userStr, '@')))) ||      }
       else if ((NULL != (pbs = (strchr(userStr, '@')))) ||
                (NULL != (pbs = (strchr(userStr, '.')))))                (NULL != (pbs = (strchr(userStr, '.')))))
     {     {
         *pbs = '\0';         *pbs = '\0';
Line 576 
Line 590 
         strcpy(mUserName, userStr);         strcpy(mUserName, userStr);
         usingDomain = true;         usingDomain = true;
  
     } else      }
       else
     {     {
         strcpy(mDomainName, ".");         strcpy(mDomainName, ".");
         strcpy(mUserName, userStr);         strcpy(mUserName, userStr);
     }     }
  
     //convert domain name to unicode     //convert domain name to unicode
     if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))      if (!MultiByteToWideChar(
               CP_ACP, 0, mDomainName, -1, wDomainName,
               (int)(strlen(mDomainName) + 1)))
     {     {
         return false;         return false;
     }     }
  
     //convert username to unicode     //convert username to unicode
     if (!MultiByteToWideChar(CP_ACP, 0, mUserName, -1, wUserName, strlen(mUserName)+1))      if (!MultiByteToWideChar(
               CP_ACP, 0, mUserName, -1, wUserName, (int)(strlen(mUserName) + 1)))
     {     {
         return false;         return false;
     }     }
Line 600 
Line 618 
         DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName);         DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName);
         if (rc == NERR_Success)         if (rc == NERR_Success)
         {         {
             wcscpy(wDomainName, (LPWSTR) pComputerName); //this is automatically prefixed with "\\"              // this is automatically prefixed with "\\"
               wcscpy(wDomainName, (LPWSTR) pComputerName);
         }         }
         /*         /*
         else         else
         {         {
             // failover             // failover
             // ATTN: This is commented out until there is resolution on Bugzilla 2236. -hns 2/2005              // ATTN: This is commented out until there is resolution on
               // Bugzilla 2236. -hns 2/2005
             // This needs to be more thoroughly tested when we uncomment it out.             // This needs to be more thoroughly tested when we uncomment it out.
  
             PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL;             PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL;
Line 616 
Line 636 
                              mDomainName,                              mDomainName,
                              NULL,                              NULL,
                              NULL,                              NULL,
                              DS_DIRECTORY_SERVICE_REQUIRED,  //not sure what flags we want here                               // not sure what flags we want here
                                DS_DIRECTORY_SERVICE_REQUIRED,
                              &DomainControllerInfo);                              &DomainControllerInfo);
  
             if (rc == ERROR_SUCCESS && DomainControllerInfo)             if (rc == ERROR_SUCCESS && DomainControllerInfo)
Line 624 
Line 645 
                 strcpy(mDomainName, DomainControllerInfo->DomainName);                 strcpy(mDomainName, DomainControllerInfo->DomainName);
                 NetApiBufferFree(DomainControllerInfo);                 NetApiBufferFree(DomainControllerInfo);
  
                 if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))                  if (!MultiByteToWideChar(
                           CP_ACP, 0, mDomainName, -1, wDomainName,
                           strlen(mDomainName) + 1))
                 {                 {
                     return false;                     return false;
                 }                 }
Line 664 
Line 687 
     // ATTN-NB-03-20000304: Implement better way to get the privileged     // ATTN-NB-03-20000304: Implement better way to get the privileged
     // user on the system.     // user on the system.
  
     return (String("Administrator"));      return String("Administrator");
 } }
  
 Boolean System::isGroupMember(const char* userName, const char* groupName) Boolean System::isGroupMember(const char* userName, const char* groupName)
Line 678 
Line 701 
     DWORD dwEntriesRead = 0;     DWORD dwEntriesRead = 0;
     DWORD dwTotalEntries = 0;     DWORD dwTotalEntries = 0;
     NET_API_STATUS nStatus;     NET_API_STATUS nStatus;
       wchar_t wcUserName[UNLEN+1];
       wchar_t wcGroupName[UNLEN+1];
  
       //Convert user name to unicode
       if (!MultiByteToWideChar(CP_ACP,0,userName, -1, wcUserName,
           strlen(userName)+1))
       {
           return false;
       }
   
       //Convert group name to unicode
       if (!MultiByteToWideChar(CP_ACP, 0, groupName, -1, wcGroupName,
           strlen(groupName)+1))
       {
           return false;
       }
  
     //     //
     // Call the NetUserGetLocalGroups function     // Call the NetUserGetLocalGroups function
Line 688 
Line 726 
     // function should also return the names of the local     // function should also return the names of the local
     // groups in which the user is indirectly a member.     // groups in which the user is indirectly a member.
     //     //
     nStatus = NetUserGetLocalGroups(NULL,      nStatus = NetUserGetLocalGroups(
                                    (LPCWSTR)userName,          NULL,
           (LPCWSTR)wcUserName,
                                    dwLevel,                                    dwLevel,
                                    dwFlags,                                    dwFlags,
                                    (LPBYTE *) &pBuf,                                    (LPBYTE *) &pBuf,
Line 717 
Line 756 
                 //                 //
                 // Compare the user's group name to groupName.                 // Compare the user's group name to groupName.
                 //                 //
                 if ( strcmp ((char *)pTmpBuf->lgrui0_name, groupName) == 0 )  
                   if (wcscmp(pTmpBuf->lgrui0_name, wcGroupName) == 0)
                 {                 {
                     // User is a member of the group.                     // User is a member of the group.
                     retVal = true;                     retVal = true;
Line 751 
Line 791 
         //         //
         // Call the NetUserGetGroups function, specifying level 0.         // Call the NetUserGetGroups function, specifying level 0.
         //         //
         nStatus = NetUserGetGroups(NULL,          nStatus = NetUserGetGroups(
                                   (LPCWSTR)userName,              NULL,
               (LPCWSTR)wcUserName,
                                   dwLevel,                                   dwLevel,
                                   (LPBYTE*)&pBuf,                                   (LPBYTE*)&pBuf,
                                   dwPrefMaxLen,                                   dwPrefMaxLen,
                                   &dwEntriesRead,                                   &dwEntriesRead,
                                   &dwTotalEntries);                                   &dwTotalEntries);
   
         //         //
         // If the call succeeds,         // If the call succeeds,
         //         //
Line 778 
Line 820 
                     //                     //
                     // Compare the user's group name to groupName.                     // Compare the user's group name to groupName.
                     //                     //
                     if ( strcmp ((char *)pTmpBuf->grui0_name, groupName) == 0 )                      if (wcscmp(pTmpBuf->grui0_name, wcGroupName) == 0)
                     {                     {
                         // User is a member of the group.                         // User is a member of the group.
                         retVal = true;                         retVal = true;
Line 810 
Line 852 
     return false;     return false;
 } }
  
 Boolean System::changeUserContext(  Boolean System::changeUserContext_SingleThreaded(
       const char* userName,
     const PEGASUS_UID_T& uid,     const PEGASUS_UID_T& uid,
     const PEGASUS_GID_T& gid)     const PEGASUS_GID_T& gid)
 { {
Line 833 
Line 876 
     int fd = open(path, O_RDWR);     int fd = open(path, O_RDWR);
     if (fd != -1)     if (fd != -1)
     {     {
         if (chsize(fd, newSize) == 0)          if (chsize(fd, (long)newSize) == 0)
         {         {
             rv = true;             rv = true;
         }         }
Line 858 
Line 901 
       if (*p == '/')       if (*p == '/')
           *p = '\\';           *p = '\\';
  
     return (strcasecmp(_fullpath( full, path_slash, _MAX_PATH ), path_slash) == 0) ? true : false;      return (strcasecmp(
           _fullpath(full, path_slash, _MAX_PATH), path_slash) == 0);
 } }
  
 // Changes file permissions on the given file. // Changes file permissions on the given file.
Line 880 
Line 924 
     // Not implemented     // Not implemented
 } }
  
   void System::openlog(const char *ident, int logopt, int facility)
   {
       // Not implemented
   }
   
   void System::closelog()
   {
       // Not implemented
   }
   
   
   
 // System ID constants for Logger::put and Logger::trace // System ID constants for Logger::put and Logger::trace
 const String System::CIMSERVER = "cimserver";  // Server system ID const String System::CIMSERVER = "cimserver";  // Server system ID
  
Line 926 
Line 982 
                 {                 {
                     free(output_buf);                     free(output_buf);
                     closesocket(sock);                     closesocket(sock);
                     return(true);                      return true;
                   }
                 }                 }
             }             }
         } else {          else
           {
             free(output_buf);             free(output_buf);
             return false;             return false;
         }         }
Line 939 
Line 997 
     return false;     return false;
 } }
  
   String System::getErrorMSG_NLS(int errorCode,int errorCode2)
   {
       LPVOID winErrorMsg = NULL;
   
       if (FormatMessage(
               FORMAT_MESSAGE_ALLOCATE_BUFFER |
               FORMAT_MESSAGE_FROM_SYSTEM |
               FORMAT_MESSAGE_IGNORE_INSERTS,
               NULL,
               errorCode,
               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
               (LPTSTR)&winErrorMsg,
               0,
               NULL))
       {
           MessageLoaderParms parms(
               "Common.System.ERROR_MESSAGE.STANDARD",
               "$0 (error code $1)",(char*)winErrorMsg,errorCode);
           LocalFree(winErrorMsg);
           return MessageLoader::getMessage(parms);
       }
   
       MessageLoaderParms parms(
           "Common.System.ERROR_MESSAGE.STANDARD",
           "$0 (error code $1)","",errorCode);
       return MessageLoader::getMessage(parms);
   
   }
   
   String System::getErrorMSG(int errorCode,int errorCode2)
   {
   
       String buffer;
       LPVOID winErrorMsg = NULL;
   
       char strErrorCode[32];
       sprintf(strErrorCode, "%d", errorCode);
   
       if (FormatMessage(
               FORMAT_MESSAGE_ALLOCATE_BUFFER |
               FORMAT_MESSAGE_FROM_SYSTEM |
               FORMAT_MESSAGE_IGNORE_INSERTS,
               NULL,
               errorCode,
               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
               (LPTSTR)&winErrorMsg,
               0,
               NULL))
       {
           buffer.append((char*)winErrorMsg);
           LocalFree(winErrorMsg);
       }
  
       buffer.append(" (error code ");
       buffer.append(strErrorCode);
       buffer.append(")");
   
       return buffer;
   }
  
 /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
 // AutoFileLock class // AutoFileLock class
Line 947 
Line 1063 
  
 AutoFileLock::AutoFileLock(const char* fileName) AutoFileLock::AutoFileLock(const char* fileName)
 { {
     // ATTN: Not implemented     // Repeat createFile, if there is a sharing violation.
      do
      {
          _hFile = CreateFile (fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
              OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
      }while ((GetLastError() == ERROR_SHARING_VIOLATION));
   
      // If this conditon succeeds, There is an error opening the file. Hence
      // returning from here  as Lock can not be acquired.
      if((_hFile == INVALID_HANDLE_VALUE)
          && (GetLastError() != ERROR_ALREADY_EXISTS)
          && (GetLastError() != ERROR_SUCCESS))
      {
          PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
             "AutoFileLock: Failed to open lock file '%s', error code %d.",
             fileName, GetLastError()));
          return;
      }
   
      OVERLAPPED l={0,0,0,0,0};
      if(LockFileEx(_hFile,LOCKFILE_EXCLUSIVE_LOCK, 0, 0, 0, &l) == 0)
      {
          PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
              "AutoFileLock: Failed to Acquire lock on file %s, error code %d.",
              fileName, GetLastError()));
          CloseHandle(_hFile);
          _hFile = INVALID_HANDLE_VALUE;
      }
 } }
  
 AutoFileLock::~AutoFileLock() AutoFileLock::~AutoFileLock()
 { {
     // ATTN: Not implemented      if(_hFile != INVALID_HANDLE_VALUE)
       {
           OVERLAPPED l={0,0,0,0,0};
           if(UnlockFileEx (_hFile, 0, 0, 0, &l) == 0)
           {
              PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
                  "AutoFileLock: Failed to unlock file, error code %d.",
                   GetLastError()));
           }
           CloseHandle(_hFile);
       }
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.68  
changed lines
  Added in v.1.79.2.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2