(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.20 and 1.21

version 1.20, 2001/07/16 22:28:06 version 1.21, 2001/12/13 14:54:02
Line 22 
Line 22 
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By:  // Modified By: Ben Heilbronn (ben_heilbronn@hp.com)
   //
   //              Sushma Fernandes (sushma_fernandes@hp.com)
   //
   //              Nag Boranna (nagaraja_boranna@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifdef PEGASUS_OS_HPUX #ifdef PEGASUS_OS_HPUX
 # include <dl.h> # include <dl.h>
   #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
   # include <dll.h>
 #else #else
 # include <dlfcn.h> # include <dlfcn.h>
 #endif #endif
  
 # include <unistd.h> # include <unistd.h>
 #include <dirent.h> #include <dirent.h>
   #include <pwd.h>
   #include <crypt.h>
 #include "System.h" #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 <Pegasus/Common/Tracer.h>
   
   #ifdef PEGASUS_PLATFORM_LINUX_IX86_GNU
   #include <pwd.h>
   #endif
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 145 
Line 158 
  
 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName) DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
 { {
 #if defined(PEGASUS_OS_HPUX)      const char METHOD_NAME[] = "System::loadDynamicLibrary()";
     char* p = strcpy(new char[strlen(fileName) + 4], fileName);  
     char* dot = strrchr(p, '.');  
  
     if (!dot)      PEG_FUNC_ENTER(TRC_OS_ABSTRACTION, METHOD_NAME);
         return 0;  
  
     *dot = '\0';      Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
     strcat(p, ".sl");                    "Attempting to load library %s", fileName);
  
     void* handle = shl_load(p, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);  #if defined(PEGASUS_OS_HPUX)
     delete [] p;      void* handle = shl_load(fileName, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);
  
     return DynamicLibraryHandle(handle);      Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
 #else                    "After loading lib %s, error code is %d", fileName, errno);
  
 # ifdef PEGASUS_OS_TRU64      PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);
       return DynamicLibraryHandle(handle);
   #elif defined(PEGASUS_OS_TRU64)
       PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);
     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));
   #elif defined(PEGASUS_OS_ZOS)
       PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);
       return DynamicLibraryHandle(dllload(fileName));
 # else # else
       PEG_FUNC_EXIT(TRC_OS_ABSTRACTION, METHOD_NAME);
     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW | RTLD_GLOBAL));     return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW | RTLD_GLOBAL));
 # endif # endif
  
   }
   
   void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
   {
       // ATTN: Should this method indicate success/failure?
   #ifdef PEGASUS_OS_LINUX
       dlclose(libraryHandle);
   #endif
   
   #ifdef PEGASUS_OS_HPUX
       // Note: shl_unload will unload the library even if it has been loaded
       // multiple times.  No reference count is kept.
       int ignored = shl_unload(shl_t(libraryHandle));
 #endif #endif
 } }
  
 String System::dynamicLoadError() { String System::dynamicLoadError() {
       // ATTN: Is this safe in a multi-threaded process?  Should this string
       // be returned from loadDynamicLibrary?
 #ifdef PEGASUS_OS_HPUX #ifdef PEGASUS_OS_HPUX
       // ATTN: If shl_load() returns NULL, this value should be strerror(errno)
       return String();
   #elif defined(PEGASUS_OS_ZOS)
     return String();     return String();
 #else #else
     String dlerr = dlerror();     String dlerr = dlerror();
Line 203 
Line 238 
  
     return 0;     return 0;
  
   #elif defined(PEGASUS_OS_ZOS)
       return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle,
                                  (char*)symbolName));
 #else #else
  
     return DynamicSymbolHandle(dlsym(libraryHandle, (char*)symbolName));     return DynamicSymbolHandle(dlsym(libraryHandle, (char*)symbolName));
Line 220 
Line 258 
     return hostname;     return hostname;
 } }
  
   String System::getPassword(const char* prompt)
   {
   
       String password;
   
       password = String(getpass( prompt ));
   
       return password;
   }
   
   String System::getCurrentLoginName()
   {
       String userName = String::EMPTY;
       struct passwd*   pwd = NULL;
   
       //
       //  get the currently logged in user's UID.
       //
       pwd = getpwuid(getuid());
       if ( pwd == NULL )
       {
           //ATTN: Log a message
           // "User might have been removed just after login"
       }
       else
       {
           //
           //  get the user name
           //
           userName.assign(pwd->pw_name);
       }
   
       return(userName);
   }
   
   String System::encryptPassword(const char* password, const char* salt)
   {
       return ( String(crypt( password,salt)) );
   }
   
   Boolean System::isSystemUser(char* userName)
   {
       //
       //  get the password entry for the user
       //
       if  ( getpwnam(userName) == NULL )
       {
           return false;
       }
       return true;
   }
   
   Boolean System::isPrivilegedUser()
   {
       //
       // Get the effective UID for the user
       //
       if ( geteuid() != 0 )
       {
           return false;
       }
       return true;
   }
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2