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

Diff for /pegasus/src/Pegasus/Common/SystemUnix.cpp between version 1.60 and 1.92

version 1.60, 2003/07/28 13:20:28 version 1.92, 2004/10/17 20:39:17
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2004////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // The Open Group, Tivoli Systems  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 26 
Line 30 
 // Modified By: Ben Heilbronn (ben_heilbronn@hp.com) // Modified By: Ben Heilbronn (ben_heilbronn@hp.com)
 //              Sushma Fernandes (sushma_fernandes@hp.com) //              Sushma Fernandes (sushma_fernandes@hp.com)
 //              Nag Boranna (nagaraja_boranna@hp.com) //              Nag Boranna (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)
   //              Amit K Arora (amita@in.ibm.com) for PEP101
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 37 
Line 43 
 # include <dll.h> # include <dll.h>
 #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
 #  include <fcntl.h> #  include <fcntl.h>
 #  include <qycmutiltyUtility.H>  #  include <qycmutilu2.H>
 #  include <unistd.cleinc> #  include <unistd.cleinc>
 #  include "qycmmsgclsMessage.H" // ycmMessage class #  include "qycmmsgclsMessage.H" // ycmMessage class
 #  include "OS400SystemState.h"  // OS400LoadDynamicLibrary, etc #  include "OS400SystemState.h"  // OS400LoadDynamicLibrary, etc
   #include "OS400ConvertChar.h"
 #else #else
 # include <dlfcn.h> # include <dlfcn.h>
 #endif #endif
Line 48 
Line 55 
 #include <unistd.h> #include <unistd.h>
 #include <dirent.h> #include <dirent.h>
 #include <pwd.h> #include <pwd.h>
   #include <grp.h>
   
   #include <errno.h>
   #if defined(PEGASUS_OS_SOLARIS)
   #  include <string.h>
   #endif
  
 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)  #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) && !defined(PEGASUS_PLATFORM_DARWIN_PPC_GNU)
 #include <crypt.h> #include <crypt.h>
 #endif #endif
  
 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
 #include <arpa/inet.h> #include <arpa/inet.h>
   #include <__ftp.h>
 #endif #endif
  
 #if defined(PEGASUS_USE_SYSLOGS) #if defined(PEGASUS_USE_SYSLOGS)
Line 69 
Line 83 
 #include <netdb.h> #include <netdb.h>
 #include "System.h" #include "System.h"
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/Destroyer.h>  
 #include <Pegasus/Common/InternalException.h> #include <Pegasus/Common/InternalException.h>
   #ifdef PEGASUS_ZOS_SECURITY
   #include "DynamicLibraryzOS_inline.h"
   #endif
   
   #if defined(PEGASUS_OS_LSB)
   #include <netinet/in.h>
   #include <termios.h>
   #include <stdio.h>
   #include <stdlib.h>
   #endif
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 #if defined(PEGASUS_OS_HPUX)  #ifdef PEGASUS_OS_OS400
 Boolean System::bindVerbose = false;  typedef struct os400_pnstruct
   {
     Qlg_Path_Name_T qlg_struct;
     char * pn;
   } OS400_PNSTRUCT;
 #endif #endif
  
 inline void sleep_wrapper(Uint32 seconds) inline void sleep_wrapper(Uint32 seconds)
Line 95 
Line 122 
 { {
     char    str[50];     char    str[50];
     time_t  rawTime;     time_t  rawTime;
       struct tm tmBuffer;
  
     time(&rawTime);     time(&rawTime);
     strftime(str, 40,"%m/%d/%Y-%T", localtime(&rawTime));      strftime(str, 40,"%m/%d/%Y-%T", localtime_r(&rawTime, &tmBuffer));
     String time = str;      return String(str);
     return time;  
 } }
  
 void System::sleep(Uint32 seconds) void System::sleep(Uint32 seconds)
Line 109 
Line 136 
  
 Boolean System::exists(const char* path) Boolean System::exists(const char* path)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgAccess((Qlg_Path_Name_T *)&pathname, F_OK) == 0;
   #else
     return access(path, F_OK) == 0;     return access(path, F_OK) == 0;
   #endif
 } }
  
 Boolean System::canRead(const char* path) Boolean System::canRead(const char* path)
 { {
   
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgAccess((Qlg_Path_Name_T *)&pathname, R_OK) == 0;
   #else
     return access(path, R_OK) == 0;     return access(path, R_OK) == 0;
   #endif
 } }
  
 Boolean System::canWrite(const char* path) Boolean System::canWrite(const char* path)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgAccess((Qlg_Path_Name_T *)&pathname, W_OK) == 0;
   #else
     return access(path, W_OK) == 0;     return access(path, W_OK) == 0;
   #endif
 } }
  
 Boolean System::getCurrentDirectory(char* path, Uint32 size) Boolean System::getCurrentDirectory(char* path, Uint32 size)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgGetcwd((Qlg_Path_Name_T *)&pathname, size) == 0;
   #else
     return getcwd(path, size) != NULL;     return getcwd(path, size) != NULL;
   #endif
 } }
  
 Boolean System::isDirectory(const char* path) Boolean System::isDirectory(const char* path)
 { {
     struct stat st;     struct stat st;
  
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
           return false;
   #else
     if (stat(path, &st) != 0)     if (stat(path, &st) != 0)
         return false;         return false;
   #endif
     return S_ISDIR(st.st_mode);     return S_ISDIR(st.st_mode);
 } }
  
 Boolean System::changeDirectory(const char* path) Boolean System::changeDirectory(const char* path)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgChdir((Qlg_Path_Name_T *)&pathname) == 0;
   #else
     return chdir(path) == 0;     return chdir(path) == 0;
   #endif
 } }
  
 Boolean System::makeDirectory(const char* path) Boolean System::makeDirectory(const char* path)
 { {
   
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgMkdir((Qlg_Path_Name_T *)&pathname, 0777) == 0;
   #else
     return mkdir(path, 0777) == 0;     return mkdir(path, 0777) == 0;
   #endif
   
 } }
  
 Boolean System::getFileSize(const char* path, Uint32& size) Boolean System::getFileSize(const char* path, Uint32& size)
 { {
     struct stat st;     struct stat st;
  
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
           return false;
   #else
     if (stat(path, &st) != 0)     if (stat(path, &st) != 0)
         return false;         return false;
   #endif
  
     size = st.st_size;     size = st.st_size;
     return true;     return true;
Line 160 
Line 319 
  
 Boolean System::removeDirectory(const char* path) Boolean System::removeDirectory(const char* path)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgRmdir((Qlg_Path_Name_T *)&pathname) == 0;
   #else
     return rmdir(path) == 0;     return rmdir(path) == 0;
   #endif
 } }
  
 Boolean System::removeFile(const char* path) Boolean System::removeFile(const char* path)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       return QlgUnlink((Qlg_Path_Name_T *)&pathname) == 0;
   #else
     return unlink(path) == 0;     return unlink(path) == 0;
   #endif
 } }
  
 Boolean System::renameFile(const char* oldPath, const char* newPath) Boolean System::renameFile(const char* oldPath, const char* newPath)
 { {
   #if defined(PEGASUS_OS_OS400)
       OS400_PNSTRUCT oldpathname;
       memset((void*)&oldpathname, 0x00, sizeof(OS400_PNSTRUCT));
       oldpathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(oldpathname.qlg_struct.Country_ID,"US",2);
       memcpy(oldpathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       oldpathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       oldpathname.qlg_struct.Path_Length = strlen(oldPath);
       oldpathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       oldpathname.pn = (char *)oldPath;
   
       OS400_PNSTRUCT newpathname;
       memset((void*)&newpathname, 0x00, sizeof(OS400_PNSTRUCT));
       newpathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(newpathname.qlg_struct.Country_ID,"US",2);
       memcpy(newpathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       newpathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       newpathname.qlg_struct.Path_Length = strlen(newPath);
       newpathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       newpathname.pn = (char *)newPath;
   
       if (QlgLink((Qlg_Path_Name_T *)&oldpathname,
                   (Qlg_Path_Name_T *)&newpathname) != 0)
       {
           return false;
       }
   
       return QlgUnlink((Qlg_Path_Name_T *)&oldpathname) == 0;
   #else
   
     if (link(oldPath, newPath) != 0)     if (link(oldPath, newPath) != 0)
         return false;         return false;
  
     return unlink(oldPath) == 0;     return unlink(oldPath) == 0;
   #endif
 } }
  
 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName) DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
Line 204 
Line 430 
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));
 #elif defined(PEGASUS_OS_ZOS) #elif defined(PEGASUS_OS_ZOS)
           #if defined(PEGASUS_ZOS_SECURITY)
                   if (!hasProgramControl(fileName))
                   {
                           PEG_METHOD_EXIT();
                           return 0;
                   }
           #endif
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return DynamicLibraryHandle(dllload(fileName));     return DynamicLibraryHandle(dllload(fileName));
 #elif defined(PEGASUS_OS_OS400) #elif defined(PEGASUS_OS_OS400)
Line 211 
Line 444 
     return DynamicLibraryHandle(OS400_LoadDynamicLibrary(fileName));     return DynamicLibraryHandle(OS400_LoadDynamicLibrary(fileName));
 #else #else
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW | RTLD_GLOBAL));      return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));
 #endif #endif
  
 } }
Line 219 
Line 452 
 void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle) void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
 { {
     // ATTN: Should this method indicate success/failure?     // ATTN: Should this method indicate success/failure?
 #ifdef PEGASUS_OS_LINUX  #if defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_DARWIN)
     dlclose(libraryHandle);     dlclose(libraryHandle);
 #endif #endif
  
Line 232 
Line 465 
 #ifdef PEGASUS_OS_OS400 #ifdef PEGASUS_OS_OS400
    OS400_UnloadDynamicLibrary((int)libraryHandle);    OS400_UnloadDynamicLibrary((int)libraryHandle);
 #endif #endif
   
   #ifdef PEGASUS_OS_AIX
       dlclose(libraryHandle);
   #endif
   
   #ifdef PEGASUS_OS_ZOS
           dllfree(reinterpret_cast<dllhandle *> (libraryHandle));
   #endif
 } }
  
 String System::dynamicLoadError() { String System::dynamicLoadError() {
     // ATTN: Is this safe in a multi-threaded process?  Should this string     // ATTN: Is this safe in a multi-threaded process?  Should this string
     // be returned from loadDynamicLibrary?     // be returned from loadDynamicLibrary?
 #ifdef PEGASUS_OS_HPUX #ifdef PEGASUS_OS_HPUX
     // ATTN: If shl_load() returns NULL, this value should be strerror(errno)      // If shl_load() returns NULL, errno is set to indicate the error
     return String();      return strerror(errno);
 #elif defined(PEGASUS_OS_ZOS) #elif defined(PEGASUS_OS_ZOS)
     return String();     return String();
 #elif defined(PEGASUS_OS_OS400) #elif defined(PEGASUS_OS_OS400)
Line 291 
Line 532 
  
 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));
   #if defined(PEGASUS_OS_OS400)
           EtoA(hostname);
   #endif
       }
  
     return hostname;     return hostname;
 } }
  
 String System::getFullyQualifiedHostName () String System::getFullyQualifiedHostName ()
 { {
 #ifdef PEGASUS_OS_HPUX  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_LINUX)
     char hostName [MAXHOSTNAMELEN];      char hostName [PEGASUS_MAXHOSTNAMELEN];
     struct hostent *he;     struct hostent *he;
     String fqName;     String fqName;
  
     if (gethostname (hostName, MAXHOSTNAMELEN) != 0)      if (gethostname (hostName, PEGASUS_MAXHOSTNAMELEN) != 0)
     {     {
         return String::EMPTY;         return String::EMPTY;
     }     }
  
     if (he = gethostbyname (hostName))      if ((he = gethostbyname (hostName)))
     {     {
        strcpy (hostName, he->h_name);        strcpy (hostName, he->h_name);
     }     }
Line 319 
Line 565 
     fqName.assign (hostName);     fqName.assign (hostName);
  
     return fqName;     return fqName;
   #elif defined(PEGASUS_OS_ZOS)
           char hostName [PEGASUS_MAXHOSTNAMELEN];
           char *domainName;
           String fqName;
           // receive short name of the local host
           if (gethostname(hostName, PEGASUS_MAXHOSTNAMELEN) != 0)
           {
                   return String::EMPTY;
           }
           // get domain name of the local host
           domainName= __ipDomainName();
           if (domainName == 0)
           {
                   return String::EMPTY;
           }
           // build fully qualified hostname
           fqName.assign(hostName);
           fqName.append(".");
           fqName.append(domainName);
   
           return fqName;
 #else #else
     //     //
     //  ATTN: Implement this method to return the fully qualified host name     //  ATTN: Implement this method to return the fully qualified host name
Line 329 
Line 596 
  
 String System::getSystemCreationClassName () String System::getSystemCreationClassName ()
 { {
 #ifdef PEGASUS_OS_HPUX      //
       //  The value returned should match the value of the CreationClassName key
       //  property used in the instrumentation of the CIM_ComputerSystem class
       //  as determined by the provider for the CIM_ComputerSystem class
       //
   #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)
     return "CIM_ComputerSystem";     return "CIM_ComputerSystem";
 #else #else
     //     //
Line 351 
Line 623 
     // Get wbem-local port from /etc/services     // Get wbem-local port from /etc/services
     //     //
 #if !defined(PEGASUS_OS_OS400) #if !defined(PEGASUS_OS_OS400)
   #ifdef PEGASUS_OS_SOLARIS
   #define SERV_BUFF_SIZE  1024
       struct servent      serv_result;
       char                buf[SERV_BUFF_SIZE];
   
       if ( (serv = getservbyname_r(serviceName, TCP, &serv_result,
                                   buf, SERV_BUFF_SIZE)) != NULL )
   #else // PEGASUS_OS_SOLARIS
     if ( (serv = getservbyname(serviceName, TCP)) != NULL )     if ( (serv = getservbyname(serviceName, TCP)) != NULL )
 #else  #endif // PEGASUS_OS_SOLARIS
   #else  // !PEGASUS_OS_OS400
       // Note - serviceName came from Constants.h - no need to
       // convert to EBCDIC
     // Need to cast on OS/400     // Need to cast on OS/400
     if ( (serv = getservbyname((char *)serviceName, TCP)) != NULL )     if ( (serv = getservbyname((char *)serviceName, TCP)) != NULL )
 #endif  #endif  // !PEGASUS_OS_OS400
     {     {
         localPort = htons((uint16_t)serv->s_port);         localPort = htons((uint16_t)serv->s_port);
     }     }
Line 366 
Line 649 
  
     return localPort;     return localPort;
 } }
   #if defined(PEGASUS_OS_LSB)
   /*
      getpass equivalent.
      Adapted from example implementation described in GLIBC documentation
      (http://www.dusek.ch/manual/glibc/libc_32.html) and
      "Advanced Programming in the UNIX Environment" by Richard Stevens,
      pg. 350.
   
   */
   #define MAX_PASS_LEN 1024
   char *getpassword(const char *prompt)
   {
     static char buf[MAX_PASS_LEN];
     struct termios old, new_val;
     char *ptr;
     int c;
   
     buf[0] = 0;
   
     /* Turn echoing off and fail if we can't. */
     if (tcgetattr (fileno (stdin), &old) != 0)
       return buf;
     new_val = old;
     new_val.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
     if (tcsetattr (fileno (stdin), TCSAFLUSH, &new_val) != 0)
       return buf;
   
     /* Read the password. */
     fputs (prompt, stdin);
     ptr = buf;
     while ( (c = getc(stdin)) != EOF && c != '\n') {
       if (ptr < &buf[MAX_PASS_LEN])
         *ptr++ = c;
     }
     *ptr = 0;
     putc('\n', stdin);
   
     /* Restore terminal. */
     (void) tcsetattr (fileno (stdin), TCSAFLUSH, &old);
     fclose(stdin);
     return buf;
   }
   #endif
  
 String System::getPassword(const char* prompt) String System::getPassword(const char* prompt)
 { {
Line 374 
Line 700 
  
 #if !defined(PEGASUS_OS_OS400) #if !defined(PEGASUS_OS_OS400)
     // Not supported on OS/400, and we don't need it.     // Not supported on OS/400, and we don't need it.
       // 'getpass' is DEPRECATED
     #if !defined(PEGASUS_OS_LSB)
     password = String(getpass( prompt ));     password = String(getpass( prompt ));
     #else
       password = String(getpassword( prompt ));
     #endif
   
 #endif #endif
  
     return password;     return password;
Line 385 
Line 717 
     String userName = String::EMPTY;     String userName = String::EMPTY;
     struct passwd*   pwd = NULL;     struct passwd*   pwd = NULL;
  
   #if defined(PEGASUS_OS_SOLARIS) || \
       defined(PEGASUS_OS_HPUX) || \
       defined(PEGASUS_OS_LINUX)
   
       const unsigned int PWD_BUFF_SIZE = 1024;
       struct passwd       local_pwd;
       char                buf[PWD_BUFF_SIZE];
   
       if(getpwuid_r(geteuid(), &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0)
       {
           String errorMsg = String("getpwuid_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           // L10N TODO - This message needs to be added.
           //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
           //                          errorMsg);
       }
   #else
     //     //
     //  get the currently logged in user's UID.     //  get the currently logged in user's UID.
     //     //
     pwd = getpwuid(geteuid());     pwd = getpwuid(geteuid());
   #endif
     if ( pwd == NULL )     if ( pwd == NULL )
     {     {
         //ATTN: Log a message           // L10N TODO - This message needs to be added.
         // "User might have been removed just after login"           //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
            //  "getpwuid_r failure, user may have been removed just after login");
            Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4,
                "getpwuid_r failure, user may have been removed just after login");
     }     }
     else     else
     {     {
   #if defined(PEGASUS_OS_OS400)
           EtoA(pwd->pw_name);
   #endif
         //         //
         //  get the user name         //  get the user name
         //         //
Line 417 
Line 775 
  
 Boolean System::isSystemUser(const char* userName) Boolean System::isSystemUser(const char* userName)
 { {
   #if defined(PEGASUS_OS_OS400)
       AtoE((char *)userName);
   #endif
   
   #if defined(PEGASUS_OS_SOLARIS) || \
       defined(PEGASUS_OS_HPUX) || \
       defined(PEGASUS_OS_LINUX)
   
       const unsigned int PWD_BUFF_SIZE = 1024;
       struct passwd   pwd;
       struct passwd   *result;
       char            pwdBuffer[PWD_BUFF_SIZE];
   
       if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
       {
           String errorMsg = String("getpwnam_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           // L10N TODO - This message needs to be added.
           //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
           //                          errorMsg);
       }
       if (result == NULL)
       {
           return false;
       }
   #else
     //     //
     //  get the password entry for the user     //  get the password entry for the user
     //     //
     if  ( getpwnam(userName) == NULL )     if  ( getpwnam(userName) == NULL )
     {     {
   #if defined(PEGASUS_OS_OS400)
           EtoA((char *)userName);
   #endif
         return false;         return false;
     }     }
   #endif
   #if defined(PEGASUS_OS_OS400)
       EtoA((char *)userName);
   #endif
   
     return true;     return true;
 } }
  
Line 435 
Line 829 
 #if !defined(PEGASUS_OS_OS400) #if !defined(PEGASUS_OS_OS400)
     struct passwd   pwd;     struct passwd   pwd;
     struct passwd   *result;     struct passwd   *result;
     char            pwdBuffer[1024];      const unsigned int PWD_BUFF_SIZE = 1024;
       char            pwdBuffer[PWD_BUFF_SIZE];
   
       if (getpwnam_r(
             userName.getCString(), &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
       {
           String errorMsg = String("getpwnam_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           // L10N TODO - This message needs to be added.
           //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
           //                          errorMsg);
       }
  
     if (getpwnam_r(userName.getCString(), &pwd, pwdBuffer, 1024, &result) == 0)      // Check if the requested entry was found. If not return false.
       if ( result != NULL )
     {     {
           // Check if the uid is 0.
         if ( pwd.pw_uid == 0 )         if ( pwd.pw_uid == 0 )
         {         {
             return true;             return true;
         }         }
     }     }
     return false;     return false;
   
 #else #else
     return ycmCheckUserCmdAuthorities(userName.getCString());      CString user = userName.getCString();
       const char * tmp = (const char *)user;
       AtoE((char *)tmp);
       return ycmCheckUserCmdAuthorities(tmp);
 #endif #endif
   
 } }
  
 String System::getPrivilegedUserName() String System::getPrivilegedUserName()
Line 457 
Line 871 
     if (userName == String::EMPTY)     if (userName == String::EMPTY)
     {     {
         struct passwd*   pwd = NULL;         struct passwd*   pwd = NULL;
   #if defined(PEGASUS_OS_SOLARIS) || \
       defined(PEGASUS_OS_HPUX) || \
       defined(PEGASUS_OS_LINUX)
           const unsigned int PWD_BUFF_SIZE = 1024;
           struct passwd   local_pwd;
           char            buf[PWD_BUFF_SIZE];
   
           if(getpwuid_r(0, &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0)
           {
               String errorMsg = String("getpwuid_r failure : ") +
                               String(strerror(errno));
               Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
               // L10N TODO - This message needs to be added.
               //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
               //                      errorMsg);
           }
   #else
         //         //
         //  get the privileged user's UID.         //  get the privileged user's UID.
         //         //
         //  (on OS/400, this is QSECOFR)         //  (on OS/400, this is QSECOFR)
         pwd = getpwuid(0);         pwd = getpwuid(0);
   #endif
         if ( pwd != NULL )         if ( pwd != NULL )
         {         {
   #if defined(PEGASUS_OS_OS400)
               EtoA(pwd->pw_name);
   #endif
             //             //
             //  get the user name             //  get the user name
             //             //
Line 472 
Line 907 
         }         }
         else         else
         {         {
               Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4,
                          "Could not find entry.");
             PEGASUS_ASSERT(0);             PEGASUS_ASSERT(0);
         }         }
     }     }
Line 479 
Line 916 
     return (userName);     return (userName);
 } }
  
   Boolean System::isGroupMember(const char* userName, const char* groupName)
   {
       struct group                        grp;
       char                                *member;
       Boolean                             retVal = false;
       const unsigned int                  PWD_BUFF_SIZE = 1024;
       const unsigned int                  GRP_BUFF_SIZE = 1024;
       struct passwd                       pwd;
       struct passwd                       *result;
       struct group                        *grpresult;
       char                                pwdBuffer[PWD_BUFF_SIZE];
       char                                grpBuffer[GRP_BUFF_SIZE];
   
       //
       // Search Primary group information.
       //
   
       // Find the entry that matches "userName"
   
       if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
       {
           String errorMsg = String("getpwnam_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
                                     errorMsg);
           throw InternalSystemError();
       }
   
       if ( result != NULL )
       {
           // User found, check for group information.
           gid_t           group_id;
           group_id = pwd.pw_gid;
   
           // Get the group name using group_id and compare with group passed.
           if ( getgrgid_r(group_id, &grp,
                    grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0)
           {
               String errorMsg = String("getgrgid_r failure : ") +
                                    String(strerror(errno));
               Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                         errorMsg);
               Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
                                     errorMsg);
               throw InternalSystemError();
           }
   
           // Compare the user's group name to groupName.
           if ( strcmp (grp.gr_name, groupName) == 0 )
           {
                // User is a member of the group.
                return true;
           }
       }
   
       //
       // Search supplemental groups.
       // Get a user group entry
       //
   #if defined(PEGASUS_OS_LSB)
       if ( getgrnam_r((char *)groupName, &grp,
                 grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 )
   #else
       if ( getgrnam_r(groupName, &grp,
                 grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 )
   
   #endif
       {
           String errorMsg = String("getgrnam_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
                                     errorMsg);
           throw InternalSystemError();
       }
   
       // Check if the requested group was found.
       if (grpresult == NULL)
       {
           return false;
       }
   
       Uint32 j = 0;
   
       //
       // Get all the members of the group
       //
       member = grp.gr_mem[j++];
   
       while (member)
       {
           //
           // Check if the user is a member of the group
           //
           if ( strcmp(userName, member) == 0 )
           {
               retVal = true;
               break;
           }
           member = grp.gr_mem[j++];
       }
   
       return retVal;
   }
   
 Uint32 System::getPID() Uint32 System::getPID()
 { {
     //     //
Line 496 
Line 1041 
 #if !defined(PEGASUS_OS_OS400) #if !defined(PEGASUS_OS_OS400)
     return (truncate(path, newSize) == 0);     return (truncate(path, newSize) == 0);
 #else #else
     int fd = open(path, O_WRONLY);      OS400_PNSTRUCT pathname;
       memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
       pathname.qlg_struct.CCSID = 1208;
   #pragma convert(37)
       memcpy(pathname.qlg_struct.Country_ID,"US",2);
       memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
   #pragma convert(0)
       pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
       pathname.qlg_struct.Path_Length = strlen(path);
       pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
       pathname.pn = (char *)path;
   
       int fd = QlgOpen((Qlg_Path_Name_T *)&pathname, O_WRONLY);
     if (fd != -1)     if (fd != -1)
     {     {
        int rc = ftruncate(fd, newSize);        int rc = ftruncate(fd, newSize);
Line 520 
Line 1077 
   return false;   return false;
 } }
  
 void System::openlog(const String ident)  // Changes file permissions on the given file.
   Boolean System::changeFilePermissions(const char* path, mode_t mode)
 { {
 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)      Sint32 ret = 0;
   
       const char * tmp = path;
   
   #if defined(PEGASUS_OS_OS400)
       // ATTN: Update this code to handle UTF8 when path contains UTF8
       AtoE((char *)tmp);
   #endif
   
       ret = ::chmod(tmp, mode);
  
       return ( ret != -1 );
   }
   
   void System::openlog(const String ident)
   {
   #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
     // ATTN: Hard-code the "cimserver" identifier until the infrastructure     // ATTN: Hard-code the "cimserver" identifier until the infrastructure
     // is set up to pass this as the "ident" string.     // is set up to pass this as the "ident" string.
     //::openlog(ident.getCString(), LOG_PID|LOG_CONS, LOG_DAEMON);     //::openlog(ident.getCString(), LOG_PID|LOG_CONS, LOG_DAEMON);
     ::openlog("cimserver", LOG_PID|LOG_CONS, LOG_DAEMON);      ::openlog("cimserver", LOG_PID, LOG_DAEMON);
  
 #endif #endif
  
Line 536 
Line 1109 
  
 void System::syslog(Uint32 severity, const char *data) void System::syslog(Uint32 severity, const char *data)
 { {
 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
  
     // FUTURE-SF-P3-20020517 : Use the Syslog on HP-UX. Eventually only     // FUTURE-SF-P3-20020517 : Use the Syslog on HP-UX. Eventually only
     // certain messages will go to the Syslog and others to the     // certain messages will go to the Syslog and others to the
Line 563 
Line 1136 
     {     {
  
         // turn into ycmMessage so we can put it in the job log         // turn into ycmMessage so we can put it in the job log
         ycmMessage theMessage(msgCPxDF80,  #pragma convert(37)
                               CPIprefix,          ycmMessage theMessage("CPIDF80",
                               replacementData,                                    data,
                               "Logger",ycmCTLCIMID);                                strlen(data),
                                     "Logger",
                                 ycmCTLCIMID,
                                     TRUE);
   #pragma convert(0)
  
         // put the message in the joblog         // put the message in the joblog
         theMessage.joblogIt(UnitOfWorkError,         theMessage.joblogIt(UnitOfWorkError,
Line 578 
Line 1155 
         (severity & Logger::FATAL))         (severity & Logger::FATAL))
     {     {
         // turn into ycmMessage so we can put it in the job log         // turn into ycmMessage so we can put it in the job log
         ycmMessage theMessage(msgCPxDF82,  #pragma convert(37)
                               CPDprefix,          ycmMessage theMessage("CPDDF82",
                               replacementData,                                    data,
                               "Logger",ycmCTLCIMID);                                strlen(data),
                                     "Logger",
                                 ycmCTLCIMID,
                                     TRUE);
   #pragma convert(0)
         // put the message in the joblog         // put the message in the joblog
         theMessage.joblogIt(UnitOfWorkError,         theMessage.joblogIt(UnitOfWorkError,
                             ycmMessage::Diagnostic);                             ycmMessage::Diagnostic);
Line 595 
Line 1175 
  
 void System::closelog() void System::closelog()
 { {
 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
  
     ::closelog();     ::closelog();
  


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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2