(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.30 and 1.48

version 1.30, 2002/03/21 18:49:58 version 1.48, 2002/09/03 13:29:14
Line 1 
Line 1 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
   // The Open Group, Tivoli Systems
 // //
 // 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 23 
Line 24 
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // 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)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
Line 34 
Line 33 
 # include <dl.h> # include <dl.h>
 #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 # include <dll.h> # include <dll.h>
   #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
   #  include <fcntl.h>
   #  include <mih/rslvsp.h>            /* rslvsp()                       */
   #  include <mih/micommon.h>          /* _AUTH_EXECUTE                  */
   #  include <mih/miobjtyp.h>          /* WLI_SRVPGM                     */
   #  include <pointer.h>               /* _SYSPTR                        */
   #  include <qusec.h>                 /* Qus_EC_t                       */
   #  include <qleawi.h>                /* QleActBndPgm(),QleGetExp()     */
   #  include <unistd.cleinc>
 #else #else
 # include <dlfcn.h> # include <dlfcn.h>
 #endif #endif
Line 42 
Line 50 
 #include <dirent.h> #include <dirent.h>
 #include <pwd.h> #include <pwd.h>
  
 #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM  #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
 #include <crypt.h> #include <crypt.h>
 #else  
 #include <unistd.h>  
 #endif #endif
  
 #include "System.h"  
 #include <sys/stat.h> #include <sys/stat.h>
 #include <sys/types.h> #include <sys/types.h>
 #include <cstdio> #include <cstdio>
 #include <time.h> #include <time.h>
   #include <sys/time.h>
 #include <netdb.h> #include <netdb.h>
   #include "System.h"
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/Destroyer.h> #include <Pegasus/Common/Destroyer.h>
 #include <Pegasus/Common/Exception.h>  #include <Pegasus/Common/InternalException.h>
   
 #ifdef PEGASUS_PLATFORM_LINUX_IX86_GNU  
 #include <pwd.h>  
 #endif  
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 #include <sys/time.h>  #if defined(PEGASUS_OS_HPUX)
 #include <unistd.h>  Boolean System::bindVerbose = false;
   #endif
   
   #if defined(PEGASUS_OS_OS400)
   char os400ExceptionID[8] = {0};
   #endif
  
 inline void sleep_wrapper(Uint32 seconds) inline void sleep_wrapper(Uint32 seconds)
 { {
Line 76 
Line 84 
 { {
     timeval tv;     timeval tv;
     gettimeofday(&tv, 0);     gettimeofday(&tv, 0);
     seconds = int(tv.tv_sec);      seconds = Uint32(tv.tv_sec);
     milliseconds = int(tv.tv_usec) / 1000;      milliseconds = Uint32(tv.tv_usec) / 1000;
 } }
  
 String System::getCurrentASCIITime() String System::getCurrentASCIITime()
Line 86 
Line 94 
     time_t  rawTime;     time_t  rawTime;
  
     time(&rawTime);     time(&rawTime);
     strftime(str, 40,"%T-%D", localtime(&rawTime));      strftime(str, 40,"%m/%d/%Y-%T", localtime(&rawTime));
     String time = str;     String time = str;
     return time;     return time;
 } }
Line 167 
Line 175 
  
 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName) DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
 { {
     const char METHOD_NAME[] = "System::loadDynamicLibrary()";      PEG_METHOD_ENTER(TRC_OS_ABSTRACTION, "System::loadDynamicLibrary()");
   
     PEG_FUNC_ENTER(TRC_OS_ABSTRACTION, METHOD_NAME);  
  
     Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,     Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                   "Attempting to load library %s", fileName);                   "Attempting to load library %s", fileName);
  
 #if defined(PEGASUS_OS_HPUX) #if defined(PEGASUS_OS_HPUX)
     void* handle = shl_load(fileName, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);      void* handle;
       if (bindVerbose)
       {
           handle = shl_load(fileName,
                        BIND_IMMEDIATE | DYNAMIC_PATH | BIND_VERBOSE, 0L);
       }
       else
       {
           handle = shl_load(fileName, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);
       }
     Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,     Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                   "After loading lib %s, error code is %d", fileName, errno);                    "After loading lib %s, error code is %d", fileName,
                     (handle == (void *)0)?errno:0);
  
     PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);      PEG_METHOD_EXIT();
     return DynamicLibraryHandle(handle);     return DynamicLibraryHandle(handle);
 #elif defined(PEGASUS_OS_TRU64) #elif defined(PEGASUS_OS_TRU64)
     PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);      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)
     PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);      PEG_METHOD_EXIT();
     return DynamicLibraryHandle(dllload(fileName));     return DynamicLibraryHandle(dllload(fileName));
   #elif defined(PEGASUS_OS_OS400)
       // Activate the service program.
   
       // Parse out the library and srvpgm names.
       // Note: the fileName passed in must be in OS/400 form - library/srvpgm
       if (fileName == NULL || strlen(fileName) == 0 || strlen(fileName) >= 200)
          return 0;
   
       // More checking here!
       char name[200];
       strcpy(name, fileName);
   
       char* lib = strtok(name, "/");
       if (lib == NULL || strlen(lib) == 0)
          return 0;
   
       char* srvpgm = strtok(NULL,"/");
       if (srvpgm == NULL || strlen(srvpgm) == 0)
          return 0;
   
       /*----------------------------------------------------------------*/
       /* Resolve to the service program                                 */
       /*----------------------------------------------------------------*/
       _OBJ_TYPE_T objectType = WLI_SRVPGM;
       _SYSPTR sysP = rslvsp(objectType, srvpgm, lib, _AUTH_NONE);
   
       /*----------------------------------------------------------------*/
       /* Activate the service program                                   */
       /*----------------------------------------------------------------*/
       Qle_ABP_Info_t activationInfo;
       int actInfoLen = sizeof(activationInfo);
       int hdl;
   
       Qus_EC_t os400ErrorCode = {0};
       os400ErrorCode.Bytes_Provided = sizeof(Qus_EC_t);
       os400ErrorCode.Bytes_Available = 0;
   
       QleActBndPgm(&sysP,
                   &hdl,
                   &activationInfo,
                   &actInfoLen,
                   &os400ErrorCode);
   
       if (os400ErrorCode.Bytes_Available)
       {
          // Got an error.
          memset(os400ExceptionID, '\0', 8);
          strncpy(os400ExceptionID, os400ErrorCode.Exception_Id, 7);
          Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                     "Error activating service program. Exception Id = %s", os400ExceptionID);
          return 0;
       }
   
       PEG_METHOD_EXIT();
       return DynamicLibraryHandle(hdl);
   
 #else #else
     PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);      PEG_METHOD_EXIT();
     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW | RTLD_GLOBAL));     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW | RTLD_GLOBAL));
 #endif #endif
  
Line 205 
Line 276 
 #ifdef PEGASUS_OS_HPUX #ifdef PEGASUS_OS_HPUX
     // Note: shl_unload will unload the library even if it has been loaded     // Note: shl_unload will unload the library even if it has been loaded
     // multiple times.  No reference count is kept.     // multiple times.  No reference count is kept.
     int ignored = shl_unload(shl_t(libraryHandle));      int ignored = shl_unload(reinterpret_cast<shl_t>(libraryHandle));
 #endif #endif
 } }
  
Line 217 
Line 288 
     return String();     return String();
 #elif defined(PEGASUS_OS_ZOS) #elif defined(PEGASUS_OS_ZOS)
     return String();     return String();
   #elif defined(PEGASUS_OS_OS400)
       return String(os400ExceptionID);
 #else #else
     String dlerr = dlerror();     String dlerr = dlerror();
     return dlerr;     return dlerr;
Line 232 
Line 305 
     char* p = (char*)symbolName;     char* p = (char*)symbolName;
     void* proc = 0;     void* proc = 0;
  
     if (shl_findsym((shl_t*)&libraryHandle, p, TYPE_UNDEFINED, &proc) == 0)      if (shl_findsym((shl_t*)&libraryHandle, symbolName, TYPE_UNDEFINED,
                       &proc) == 0)
       {
         return DynamicSymbolHandle(proc);         return DynamicSymbolHandle(proc);
       }
  
     p = strcpy(new char[strlen(symbolName) + 2], symbolName);      if (shl_findsym((shl_t*)libraryHandle,
     strcpy(p, "_");                      (String("_") + symbolName).getCString(),
     strcat(p, symbolName);                      TYPE_UNDEFINED,
                       &proc) == 0)
     if (shl_findsym((shl_t*)libraryHandle, p, TYPE_UNDEFINED, &proc) == 0)  
     {     {
         delete [] p;  
         return DynamicSymbolHandle(proc);         return DynamicSymbolHandle(proc);
     }     }
  
Line 250 
Line 324 
 #elif defined(PEGASUS_OS_ZOS) #elif defined(PEGASUS_OS_ZOS)
     return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle,     return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle,
                                (char*)symbolName));                                (char*)symbolName));
   
   #elif defined(PEGASUS_OS_OS400)
      /*----------------------------------------------------------------*/
      /* Get procedure pointer and return it to caller                  */
      /*----------------------------------------------------------------*/
   
       Qus_EC_t os400ErrorCode = {0};
       os400ErrorCode.Bytes_Provided = sizeof(Qus_EC_t);
       os400ErrorCode.Bytes_Available = 0;
   
       int exportType;
       int hdl = (int)libraryHandle;
       void * procAddress = NULL;
   
       QleGetExp(&hdl,
                0,
                0,
                (char *)symbolName,
                &procAddress,
                &exportType,
                &os400ErrorCode);
   
       if (os400ErrorCode.Bytes_Available)
       {
         // Got an error.
          memset(os400ExceptionID, '\0', 8);
          strncpy(os400ExceptionID, os400ErrorCode.Exception_Id, 7);
          Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                     "Error getting export. Exception Id = %s", os400ExceptionID);
          return 0;
       }
   
       return DynamicSymbolHandle(procAddress);
   
 #else #else
  
     return DynamicSymbolHandle(dlsym(libraryHandle, (char*)symbolName));     return DynamicSymbolHandle(dlsym(libraryHandle, (char*)symbolName));
Line 264 
Line 372 
     if (!*hostname)     if (!*hostname)
         gethostname(hostname, sizeof(hostname));         gethostname(hostname, sizeof(hostname));
  
   #ifdef PEGASUS_PLATFORM_AIX_RS_IBMCXX
       char *dot = strchr(hostname, '.');
       if (dot != NULL) *dot = '\0';
   #endif
   
     return hostname;     return hostname;
 } }
  
Line 318 
Line 431 
     //     //
     // Get wbem-local port from /etc/services     // Get wbem-local port from /etc/services
     //     //
   #if !defined(PEGASUS_OS_OS400)
     if (  (serv = getservbyname(serviceName, TCP)) != NULL )     if (  (serv = getservbyname(serviceName, TCP)) != NULL )
   #else
       // Need to cast on OS/400
       if ( (serv = getservbyname((char *)serviceName, TCP)) != NULL )
   #endif
     {     {
   #ifndef PEGASUS_PLATFORM_LINUX_IX86_GNU
         localPort = serv->s_port;         localPort = serv->s_port;
   #else
           localPort = htons((uint16_t)serv->s_port);
   #endif
     }     }
     else     else
     {     {
Line 335 
Line 457 
  
     String password;     String password;
  
   #if !defined(PEGASUS_OS_OS400)
       // Not supported on OS/400, and we don't need it.
     password = String(getpass( prompt ));     password = String(getpass( prompt ));
   #endif
  
     return password;     return password;
 } }
  
 String System::getCurrentLoginName()  String System::getEffectiveUserName()
 { {
     String userName = String::EMPTY;     String userName = String::EMPTY;
     struct passwd*   pwd = NULL;     struct passwd*   pwd = NULL;
Line 348 
Line 473 
     //     //
     //  get the currently logged in user's UID.     //  get the currently logged in user's UID.
     //     //
     pwd = getpwuid(getuid());      pwd = getpwuid(geteuid());
     if ( pwd == NULL )     if ( pwd == NULL )
     {     {
         //ATTN: Log a message         //ATTN: Log a message
Line 367 
Line 492 
  
 String System::encryptPassword(const char* password, const char* salt) String System::encryptPassword(const char* password, const char* salt)
 { {
   #if !defined(PEGASUS_OS_OS400)
     return ( String(crypt( password,salt)) );     return ( String(crypt( password,salt)) );
   #else
       // Not supported on OS400, and we don't need it.
       return ( String(password) );
   #endif
 } }
  
 Boolean System::isSystemUser(char* userName)  Boolean System::isSystemUser(const char* userName)
 { {
     //     //
     //  get the password entry for the user     //  get the password entry for the user
Line 385 
Line 515 
 Boolean System::isPrivilegedUser(const String userName) Boolean System::isPrivilegedUser(const String userName)
 { {
     //     //
     // Check if username has been passed  
     //  
     if ( userName != String::EMPTY )  
     {  
         //  
         // Check if the given user is a privileged user         // Check if the given user is a privileged user
         //         //
         struct passwd   pwd;         struct passwd   pwd;
         struct passwd   *result;         struct passwd   *result;
         char            pwdBuffer[1024];         char            pwdBuffer[1024];
  
         ArrayDestroyer<char> userName_(userName.allocateCString());      if (getpwnam_r(userName.getCString(), &pwd, pwdBuffer, 1024, &result) == 0)
         if (getpwnam_r(userName_.getPointer(), &pwd, pwdBuffer, 1024, &result) == 0)  
         {         {
             if ( pwd.pw_uid == 0 )             if ( pwd.pw_uid == 0 )
             {             {
                 return true;                 return true;
             }             }
             return false;  
         }  
     }     }
     else  
     {  
         //  
         // Get the effective UID for the user  
         //  
         if ( geteuid() != 0 )  
         {  
             return false;             return false;
         }         }
         return true;  
     }  
 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM  
     return false; // keep the compiler happy  
 #endif  
 }  
  
 String System::getPrivilegedUserName() String System::getPrivilegedUserName()
 { {
Line 464 
Line 573 
     const char* path,     const char* path,
     size_t newSize)     size_t newSize)
 { {
   #if !defined(PEGASUS_OS_OS400)
     return (truncate(path, newSize) == 0);     return (truncate(path, newSize) == 0);
   #else
       int fd = open(path, O_WRONLY);
       if (fd != -1)
       {
          int rc = ftruncate(fd, newSize);
          close(fd);
          return (rc == 0);
       }
   
       return false;
   #endif
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.30  
changed lines
  Added in v.1.48

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2