version 1.66, 2003/08/27 01:38:18
|
version 1.84, 2004/06/21 18:44:39
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2003//////////////////////////////////////////////////////////////////////// |
// | // |
// 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. |
// | // |
// 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 |
|
|
// 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) |
// | // |
|
|
# 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 <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) |
|
|
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Common/Destroyer.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 |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
#if defined(PEGASUS_OS_HPUX) |
|
Boolean System::bindVerbose = false; |
|
#endif |
|
|
|
#ifdef PEGASUS_OS_OS400 | #ifdef PEGASUS_OS_OS400 |
typedef struct os400_pnstruct | typedef struct os400_pnstruct |
{ | { |
|
|
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) |
|
|
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 |
| |
} | } |
|
|
void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle) | void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle) |
{ | { |
// ATTN: Should this method indicate success/failure? | // ATTN: Should this method indicate success/failure? |
#if defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_SOLARIS) |
#if defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_DARWIN) |
dlclose(libraryHandle); | dlclose(libraryHandle); |
#endif | #endif |
| |
|
|
dlclose(libraryHandle); | dlclose(libraryHandle); |
#endif | #endif |
| |
|
#ifdef PEGASUS_OS_ZOS |
|
dllfree(reinterpret_cast<dllhandle *> (libraryHandle)); |
|
#endif |
} | } |
| |
String System::dynamicLoadError() { | String System::dynamicLoadError() { |
|
|
| |
String System::getHostName() | String System::getHostName() |
{ | { |
static char hostname[64]; |
static char hostname[PEGASUS_MAXHOSTNAMELEN]; |
| |
if (!*hostname) | if (!*hostname) |
{ | { |
|
|
String System::getFullyQualifiedHostName () | String System::getFullyQualifiedHostName () |
{ | { |
#ifdef PEGASUS_OS_HPUX | #ifdef PEGASUS_OS_HPUX |
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; |
} | } |
|
|
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 |
|
|
const unsigned int PWD_BUFF_SIZE = 1024; | const unsigned int PWD_BUFF_SIZE = 1024; |
struct passwd local_pwd; | struct passwd local_pwd; |
char buf[PWD_BUFF_SIZE]; | char buf[PWD_BUFF_SIZE]; |
if(getpwuid_r(geteuid(), &local_pwd, buf, PWD_BUFF_SIZE, &pwd)) { |
|
pwd = (struct passwd *)NULL; |
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 | #else |
// | // |
|
|
#endif | #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 |
{ | { |
|
|
char pwdBuffer[PWD_BUFF_SIZE]; | char pwdBuffer[PWD_BUFF_SIZE]; |
| |
if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0) | 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 | #else |
// | // |
// get the password entry for the user | // get the password entry for the user |
// | // |
if ( getpwnam(userName) == NULL ) | if ( getpwnam(userName) == NULL ) |
#endif |
|
{ | { |
#if defined(PEGASUS_OS_OS400) | #if defined(PEGASUS_OS_OS400) |
EtoA((char *)userName); | EtoA((char *)userName); |
#endif | #endif |
return false; | return false; |
} | } |
|
#endif |
#if defined(PEGASUS_OS_OS400) | #if defined(PEGASUS_OS_OS400) |
EtoA((char *)userName); | EtoA((char *)userName); |
#endif | #endif |
|
|
return true; | return true; |
} | } |
| |
|
|
#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, 1024, &result) == 0) |
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); |
|
} |
|
|
|
// 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 |
CString user = userName.getCString(); | CString user = userName.getCString(); |
const char * tmp = (const char *)user; | const char * tmp = (const char *)user; |
AtoE((char *)tmp); | AtoE((char *)tmp); |
return ycmCheckUserCmdAuthorities(tmp); | return ycmCheckUserCmdAuthorities(tmp); |
#endif | #endif |
|
|
} | } |
| |
String System::getPrivilegedUserName() | String System::getPrivilegedUserName() |
|
|
const unsigned int PWD_BUFF_SIZE = 1024; | const unsigned int PWD_BUFF_SIZE = 1024; |
struct passwd local_pwd; | struct passwd local_pwd; |
char buf[PWD_BUFF_SIZE]; | char buf[PWD_BUFF_SIZE]; |
if(getpwuid_r(0, &local_pwd, buf, PWD_BUFF_SIZE, &pwd)) { |
|
pwd = (struct passwd *)NULL; |
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 | #else |
// | // |
|
|
} | } |
else | else |
{ | { |
|
Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4, |
|
"Could not find entry."); |
PEGASUS_ASSERT(0); | PEGASUS_ASSERT(0); |
} | } |
} | } |
|
|
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 ( getgrnam_r(groupName, &grp, |
|
grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 ) |
|
{ |
|
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() |
{ | { |
// | // |
|
|
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 |
| |
|
|
| |
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 |
|
|
{ | { |
| |
// 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, |
|
CPIprefix, |
|
replacementData, |
|
#pragma convert(37) | #pragma convert(37) |
|
ycmMessage theMessage("CPIDF80", |
|
data, |
|
strlen(data), |
"Logger", | "Logger", |
#pragma convert(0) |
|
ycmCTLCIMID, | ycmCTLCIMID, |
utf8); |
TRUE); |
|
#pragma convert(0) |
| |
// put the message in the joblog | // put the message in the joblog |
theMessage.joblogIt(UnitOfWorkError, | theMessage.joblogIt(UnitOfWorkError, |
|
|
(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, |
|
CPDprefix, |
|
replacementData, |
|
#pragma convert(37) | #pragma convert(37) |
|
ycmMessage theMessage("CPDDF82", |
|
data, |
|
strlen(data), |
"Logger", | "Logger", |
#pragma convert(0) |
|
ycmCTLCIMID, | ycmCTLCIMID, |
utf8); |
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); |
|
|
| |
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(); |
| |