(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.47 and 1.60

version 1.47, 2005/02/27 17:43:08 version 1.60, 2005/11/02 22:03:17
Line 60 
Line 60 
 #include <process.h> #include <process.h>
 #include <lm.h> #include <lm.h>
  
   #define SECURITY_WIN32
   #include <security.h>
   
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 #define PEGASUS_ACCESS_EXISTS 0 #define PEGASUS_ACCESS_EXISTS 0
Line 82 
Line 85 
     milliseconds = milliseconds / 1000;     milliseconds = milliseconds / 1000;
 } }
  
   void System::getCurrentTimeUsec(Uint32& seconds, Uint32& microseconds)
   {
       FILETIME ft;
       GetSystemTimeAsFileTime(&ft);
       ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
       largeInt.QuadPart -= 0x19db1ded53e8000;
       seconds = long(largeInt.QuadPart / (10000 * 1000));
       microseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
   }
   
 String System::getCurrentASCIITime() String System::getCurrentASCIITime()
 { {
     char tmpbuf[128];     char tmpbuf[128];
Line 188 
Line 201 
  
 String System::getHostName() String System::getHostName()
 { {
     static char hostname[PEGASUS_MAXHOSTNAMELEN];      static char hostname[PEGASUS_MAXHOSTNAMELEN + 1];
  
     if (!*hostname)     if (!*hostname)
       {
         gethostname(hostname, sizeof(hostname));         gethostname(hostname, sizeof(hostname));
       }
       hostname[sizeof(hostname)-1] = 0;
  
     return hostname;     return hostname;
 } }
  
 String System::getFullyQualifiedHostName () String System::getFullyQualifiedHostName ()
 { {
     static char FQHostName[PEGASUS_MAXHOSTNAMELEN];      static char FQHostName[PEGASUS_MAXHOSTNAMELEN + 1];
  
     if (!*FQHostName)     if (!*FQHostName)
     {     {
Line 210 
Line 226 
         {         {
             return String::EMPTY;             return String::EMPTY;
         }         }
         strcpy(FQHostName, hostEnt->h_name);          strncpy(FQHostName, hostEnt->h_name, sizeof(FQHostName)-1);
     }     }
  
     return FQHostName;     return FQHostName;
Line 230 
Line 246 
     struct servent *serv;     struct servent *serv;
  
     //     //
     // Get wbem-local port from /etc/services      // Get the port number.
     //     //
     if (  (serv = getservbyname(serviceName, TCP)) != NULL )     if (  (serv = getservbyname(serviceName, TCP)) != NULL )
     {     {
         localPort = serv->s_port;          localPort = ntohs(serv->s_port);
     }     }
     else     else
     {     {
Line 324 
Line 340 
  
 String System::getEffectiveUserName() String System::getEffectiveUserName()
 { {
   #if (_MSC_VER >= 1300) || defined(PEGASUS_WINDOWS_SDK_HOME)
   
           //Bug 3076 fix
           wchar_t fullUserName[UNLEN+1];
           DWORD userNameSize = sizeof(fullUserName)/sizeof(fullUserName[0]);
           wchar_t computerName[MAX_COMPUTERNAME_LENGTH+1];
       DWORD computerNameSize = sizeof(computerName)/sizeof(computerName[0]);
           wchar_t userName[UNLEN+1];
       wchar_t userDomain[UNLEN+1];
           String userId;
   
           if (!GetUserNameExW(NameSamCompatible, fullUserName, &userNameSize))
           {
                   return String();
           }
   
           wchar_t* index = wcschr(fullUserName, '\\');
           *index = 0;
           wcscpy(userDomain, fullUserName);
           wcscpy(userName, index + 1);
   
           //The above function will return the system name as the domain if
           //the user is not on a real domain.  Strip this out so that the rest of
           //our windows user functions work.  What if the system name and the domain
           //name are the same?
       GetComputerNameW(computerName, &computerNameSize);
   
           if (wcscmp(computerName, userDomain) != 0)
           {
           //userId.append(userDomain);
           Uint32 n = wcslen(userDomain);
           for(unsigned long i = 0; i < n; i++)
           {
               userId.append(Char16(userDomain[i]));
           }
                   userId.append("\\");
                   //userId.append(userName);
           n = wcslen(userName);
           for(unsigned long i = 0; i < n; i++)
           {
               userId.append(Char16(userName[i]));
           }
   
           } else
           {
                   //userId.append(userName);
           Uint32 n = wcslen(userName);
           for(unsigned long i = 0; i < n; i++)
           {
               userId.append(Char16(userName[i]));
           }
   
           }
   
           return userId;
   
   #else //original getEffectiveUserName function
   
   int retcode = 0;   int retcode = 0;
  
   // UNLEN (256) is the limit, not including null   // UNLEN (256) is the limit, not including null
   char pUserName[256+1] = {0};      wchar_t pUserName[256+1] = {0};
   DWORD nSize = sizeof(pUserName);      DWORD nSize = sizeof(pUserName)/sizeof(pUserName[0]);
  
   retcode = GetUserName(pUserName, &nSize);      retcode = GetUserNameW(pUserName, &nSize);
   if (retcode == 0)   if (retcode == 0)
     {     {
       // zero is failure       // zero is failure
       return String();       return String();
     }     }
       String userId;
       Uint32 n = wcslen(pUserName);
       for(unsigned long i = 0; i < n; i++)
       {
           userId.append(Char16(pUserName[i]));
       }
   
  
   return String(pUserName);      return userId;
   #endif
 } }
  
 String System::encryptPassword(const char* password, const char* salt) String System::encryptPassword(const char* password, const char* salt)
Line 361 
Line 443 
  
     char mUserName[UNLEN+1];     char mUserName[UNLEN+1];
     char mDomainName[UNLEN+1];     char mDomainName[UNLEN+1];
       char tUserName[UNLEN+1];
     wchar_t wUserName[UNLEN+1];     wchar_t wUserName[UNLEN+1];
     wchar_t wDomainName[UNLEN+1];     wchar_t wDomainName[UNLEN+1];
     char* pbs;     char* pbs;
Line 371 
Line 454 
     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
       // declared as const and strchr() may modify the string.
       strncpy(tUserName, userName, sizeof(tUserName) - 1);
       tUserName[sizeof(tUserName)- 1] = '\0';
   
     //separate the domain and user name if both are present.     //separate the domain and user name if both are present.
     if (NULL != (pbs = strchr(userName, '\\')))      if (NULL != (pbs = strchr(tUserName, '\\')))
     {     {
         *pbs = '\0';         *pbs = '\0';
         strcpy(mDomainName, userName);          strcpy(mDomainName, tUserName);
         strcpy(mUserName, pbs+1);         strcpy(mUserName, pbs+1);
         usingDomain = true;         usingDomain = true;
  
     } else if ((NULL != (pbs = (strchr(userName, '@')))) ||      } else if ((NULL != (pbs = (strchr(tUserName, '@')))) ||
                (NULL != (pbs = (strchr(userName, '.')))))                 (NULL != (pbs = (strchr(tUserName, '.')))))
     {     {
         *pbs = '\0';         *pbs = '\0';
         strcpy(mDomainName, pbs+1);         strcpy(mDomainName, pbs+1);
         strcpy(mUserName, userName);          strcpy(mUserName, tUserName);
         usingDomain = true;         usingDomain = true;
  
     } else     } else
     {     {
         strcpy(mDomainName, ".");         strcpy(mDomainName, ".");
         strcpy(mUserName, userName);          strcpy(mUserName, tUserName);
     }     }
  
     //convert domain name to unicode     //convert domain name to unicode
Line 746 
Line 834 
     const char* path,     const char* path,
     size_t newSize)     size_t newSize)
 { {
     int fd = open(path, O_RDWR);  
   
     if (fd == -1)  
         return false;  
  
     if (chsize(fd, newSize) != 0)      Boolean rv = false;
     return false;      int fd = open(path, O_RDWR);
       if (fd != -1)
       {
           if (chsize(fd, newSize) == 0)
           {
               rv = true;
           }
  
     close(fd);     close(fd);
     return true;      }
   
       return rv;
 } }
  
 // Is absolute path? // Is absolute path?
Line 769 
Line 861 
   path_slash[_MAX_PATH-1] = '\0';   path_slash[_MAX_PATH-1] = '\0';
  
   for(p = path_slash; p < path_slash + strlen(path_slash); p++)   for(p = path_slash; p < path_slash + strlen(path_slash); p++)
     if (*p == '/') *p = '\\';        if (*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) ? true : false;
 } }
Line 788 
Line 881 
     return true;     return true;
 } }
  
 void System::openlog(const String &ident)  void System::syslog(const String& ident, Uint32 severity, const char* message)
 {  
     return;  
 }  
   
 void System::syslog(Uint32 severity, const char *data)  
 {  
     return;  
 }  
   
 void System::closelog()  
 { {
     return;      // Not implemented
 } }
  
 // System ID constants for Logger::put and Logger::trace // System ID constants for Logger::put and Logger::trace


Legend:
Removed from v.1.47  
changed lines
  Added in v.1.60

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2