version 1.73.2.4, 2004/04/24 21:02:05
|
version 1.111, 2005/10/14 18:22:30
|
|
|
//%2003//////////////////////////////////////////////////////////////////////// |
//%2005//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L. P., IBM Corp., 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.; | // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; |
// IBM Corp.; EMC Corporation, The Open Group. | // 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. |
|
// Copyright (c) 2005 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 |
|
|
// 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) |
// Dave Rosckes (rosckes@us.ibm.com) |
|
// Amit K Arora (amita@in.ibm.com) for PEP101 |
|
// David Dillard, VERITAS Software Corp. |
|
// (david.dillard@veritas.com) |
|
// Yi Zhou (yi.zhou@hp.com) |
|
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3194 |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#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) | #if defined(PEGASUS_OS_SOLARIS) |
#include <string.h> | #include <string.h> |
#endif | #endif |
#include <errno.h> |
|
| |
#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 <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> |
|
#include <Pegasus/Common/IPC.h> |
#ifdef PEGASUS_ZOS_SECURITY | #ifdef PEGASUS_ZOS_SECURITY |
#include "DynamicLibraryzOS_inline.h" | #include "DynamicLibraryzOS_inline.h" |
#endif | #endif |
| |
PEGASUS_NAMESPACE_BEGIN |
#if defined(PEGASUS_OS_LSB) |
|
#include <netinet/in.h> |
#if defined(PEGASUS_OS_HPUX) |
#include <termios.h> |
Boolean System::bindVerbose = false; |
#include <stdio.h> |
|
#include <stdlib.h> |
#endif | #endif |
| |
|
PEGASUS_NAMESPACE_BEGIN |
|
|
#ifdef PEGASUS_OS_OS400 | #ifdef PEGASUS_OS_OS400 |
typedef struct os400_pnstruct | typedef struct os400_pnstruct |
{ | { |
|
|
{ | { |
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) |
|
|
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_GLOBAL|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 |
| |
|
|
// 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) |
|
|
| |
String System::getHostName() | String System::getHostName() |
{ | { |
static char hostname[64]; |
static char hostname[PEGASUS_MAXHOSTNAMELEN + 1]; |
| |
if (!*hostname) | if (!*hostname) |
{ | { |
gethostname(hostname, sizeof(hostname)); | gethostname(hostname, sizeof(hostname)); |
|
hostname[sizeof(hostname)-1] = 0; |
#if defined(PEGASUS_OS_OS400) | #if defined(PEGASUS_OS_OS400) |
EtoA(hostname); | EtoA(hostname); |
#endif | #endif |
|
|
| |
String System::getFullyQualifiedHostName () | String System::getFullyQualifiedHostName () |
{ | { |
#ifdef PEGASUS_OS_HPUX |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_OS400) |
char hostName [MAXHOSTNAMELEN]; |
char hostName[PEGASUS_MAXHOSTNAMELEN + 1]; |
struct hostent *he; | struct hostent *he; |
String fqName; | String fqName; |
| |
if (gethostname (hostName, MAXHOSTNAMELEN) != 0) |
if (gethostname(hostName, sizeof(hostName)) != 0) |
{ | { |
return String::EMPTY; | return String::EMPTY; |
} | } |
|
hostName[sizeof(hostName)-1] = 0; |
| |
if (he = gethostbyname (hostName)) |
if ((he = gethostbyname (hostName))) |
{ | { |
strcpy (hostName, he->h_name); |
strncpy(hostName, he->h_name, sizeof(hostName)-1); |
} | } |
| |
|
#if defined(PEGASUS_OS_OS400) |
|
EtoA(hostName); |
|
#endif |
|
|
fqName.assign (hostName); | fqName.assign (hostName); |
| |
return fqName; | return fqName; |
|
#elif defined(PEGASUS_OS_ZOS) |
|
char hostName[PEGASUS_MAXHOSTNAMELEN + 1]; |
|
char *domainName; |
|
String fqName; |
|
// receive short name of the local host |
|
if (gethostname(hostName, sizeof(hostName)) != 0) |
|
{ |
|
return String::EMPTY; |
|
} |
|
hostName[sizeof(hostName)-1] = 0; |
|
// 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 |
|
|
| |
String System::getSystemCreationClassName () | String System::getSystemCreationClassName () |
{ | { |
#ifdef PEGASUS_OS_HPUX |
|
return "CIM_ComputerSystem"; |
|
#else |
|
// | // |
// ATTN: Implement this method to return the system creation class name |
// 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 |
// | // |
return String::EMPTY; |
return "CIM_ComputerSystem"; |
#endif |
|
} | } |
| |
Uint32 System::lookupPort( | Uint32 System::lookupPort( |
|
|
// | // |
// Get wbem-local port from /etc/services | // Get wbem-local port from /etc/services |
// | // |
#if !defined(PEGASUS_OS_OS400) |
|
#ifdef PEGASUS_OS_SOLARIS | #ifdef PEGASUS_OS_SOLARIS |
#define SERV_BUFF_SIZE 1024 | #define SERV_BUFF_SIZE 1024 |
struct servent serv_result; | struct servent serv_result; |
|
|
| |
if ( (serv = getservbyname_r(serviceName, TCP, &serv_result, | if ( (serv = getservbyname_r(serviceName, TCP, &serv_result, |
buf, SERV_BUFF_SIZE)) != NULL ) | buf, SERV_BUFF_SIZE)) != NULL ) |
|
#elif defined(PEGASUS_OS_OS400) |
|
struct servent serv_result; |
|
serv = &serv_result; |
|
struct servent_data buf; |
|
memset(&buf, 0x00, sizeof(struct servent_data)); |
|
|
|
char srvnameEbcdic[256]; |
|
strcpy(srvnameEbcdic, serviceName); |
|
AtoE(srvnameEbcdic); |
|
|
|
char tcpEbcdic[64]; |
|
strcpy(tcpEbcdic, TCP); |
|
AtoE(tcpEbcdic); |
|
|
|
if ( (getservbyname_r(srvnameEbcdic, tcpEbcdic, &serv_result, |
|
&buf)) == 0 ) |
#else // PEGASUS_OS_SOLARIS | #else // PEGASUS_OS_SOLARIS |
if ( (serv = getservbyname(serviceName, TCP)) != NULL ) | if ( (serv = getservbyname(serviceName, TCP)) != NULL ) |
#endif // PEGASUS_OS_SOLARIS | #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 |
|
if ( (serv = getservbyname((char *)serviceName, TCP)) != NULL ) |
|
#endif // !PEGASUS_OS_OS400 |
|
{ | { |
localPort = htons((uint16_t)serv->s_port); | localPort = htons((uint16_t)serv->s_port); |
} | } |
|
|
| |
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) |
{ | { |
|
|
| |
#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; |
|
|
| |
#if defined(PEGASUS_OS_SOLARIS) || \ | #if defined(PEGASUS_OS_SOLARIS) || \ |
defined(PEGASUS_OS_HPUX) || \ | defined(PEGASUS_OS_HPUX) || \ |
defined(PEGASUS_OS_LINUX) |
defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_OS_OS400) |
| |
const unsigned int PWD_BUFF_SIZE = 1024; | const unsigned int PWD_BUFF_SIZE = 1024; |
struct passwd local_pwd; | struct passwd local_pwd; |
|
|
{ | { |
String errorMsg = String("getpwuid_r failure : ") + | String errorMsg = String("getpwuid_r failure : ") + |
String(strerror(errno)); | String(strerror(errno)); |
Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg); |
errorMsg); |
// L10N TODO - This message needs to be added. |
// l10n TODO - Need to add this message |
|
//Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, | //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
// errorMsg); | // errorMsg); |
return userName; |
|
} | } |
#else | #else |
// | // |
|
|
#endif | #endif |
if ( pwd == NULL ) | if ( pwd == NULL ) |
{ | { |
// l10n TODO - Need to add this message |
// L10N TODO - This message needs to be added. |
// Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, | // Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
// "getpwuid_r failure, user may have been removed just after login"); | // "getpwuid_r failure, user may have been removed just after login"); |
Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4, | Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4, |
|
|
| |
#if defined(PEGASUS_OS_SOLARIS) || \ | #if defined(PEGASUS_OS_SOLARIS) || \ |
defined(PEGASUS_OS_HPUX) || \ | defined(PEGASUS_OS_HPUX) || \ |
defined(PEGASUS_OS_LINUX) |
defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_OS_OS400) |
| |
const unsigned int PWD_BUFF_SIZE = 1024; | const unsigned int PWD_BUFF_SIZE = 1024; |
struct passwd pwd; | struct passwd pwd; |
|
|
{ | { |
String errorMsg = String("getpwnam_r failure : ") + | String errorMsg = String("getpwnam_r failure : ") + |
String(strerror(errno)); | String(strerror(errno)); |
Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg); |
errorMsg); |
// L10N TODO - This message needs to be added. |
// l10n TODO - Need to add this message |
|
// Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, | // Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
// errorMsg); | // errorMsg); |
return false; |
|
} | } |
if (result == NULL) | if (result == NULL) |
{ | { |
|
|
#if defined(PEGASUS_OS_OS400) | #if defined(PEGASUS_OS_OS400) |
EtoA((char *)userName); | EtoA((char *)userName); |
#endif | #endif |
|
|
return true; | return true; |
} | } |
| |
Boolean System::isPrivilegedUser(const String userName) |
Boolean System::isPrivilegedUser(const String& userName) |
{ | { |
// | // |
// Check if the given user is a privileged user | // Check if the given user is a privileged user |
|
|
const unsigned int PWD_BUFF_SIZE = 1024; | const unsigned int PWD_BUFF_SIZE = 1024; |
char pwdBuffer[PWD_BUFF_SIZE]; | char pwdBuffer[PWD_BUFF_SIZE]; |
| |
if (getpwnam_r(userName.getCString(), &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0) |
if (getpwnam_r( |
|
userName.getCString(), &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0) |
{ | { |
String errorMsg = String("getpwnam_r failure : ") + | String errorMsg = String("getpwnam_r failure : ") + |
String(strerror(errno)); | String(strerror(errno)); |
Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg); |
errorMsg); |
// L10N TODO - This message needs to be added. |
// l10n TODO - Need to add this message |
|
//Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, | //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
// errorMsg); | // errorMsg); |
return false; |
|
} | } |
| |
// Check if the requested entry was found. If not return false. | // Check if the requested entry was found. If not return false. |
|
|
AtoE((char *)tmp); | AtoE((char *)tmp); |
return ycmCheckUserCmdAuthorities(tmp); | return ycmCheckUserCmdAuthorities(tmp); |
#endif | #endif |
|
|
} | } |
| |
String System::getPrivilegedUserName() | String System::getPrivilegedUserName() |
|
|
struct passwd* pwd = NULL; | struct passwd* pwd = NULL; |
#if defined(PEGASUS_OS_SOLARIS) || \ | #if defined(PEGASUS_OS_SOLARIS) || \ |
defined(PEGASUS_OS_HPUX) || \ | defined(PEGASUS_OS_HPUX) || \ |
defined(PEGASUS_OS_LINUX) |
defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_OS_OS400) |
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]; |
|
|
{ | { |
String errorMsg = String("getpwuid_r failure : ") + | String errorMsg = String("getpwuid_r failure : ") + |
String(strerror(errno)); | String(strerror(errno)); |
Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg); |
errorMsg); |
// L10N TODO - This message needs to be added. |
// l10n TODO - Need to add this message |
|
// Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, | // Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
// errorMsg); | // errorMsg); |
return userName; |
|
} | } |
#else | #else |
// | // |
|
|
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)); |
|
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)); |
|
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)); |
|
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; |
|
} |
|
#ifndef PEGASUS_OS_OS400 |
|
Boolean System::changeUserContext(const char* userName) |
|
{ |
|
const unsigned int PWD_BUFF_SIZE = 1024; |
|
struct passwd pwd; |
|
struct passwd *result; |
|
char pwdBuffer[PWD_BUFF_SIZE]; |
|
|
|
# if defined(PEGASUS_OS_OS400) |
|
AtoE((char *)userName); |
|
# endif |
|
|
|
int rc = getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result); |
|
|
|
# if defined(PEGASUS_OS_OS400) |
|
EtoA((char *)userName); |
|
# endif |
|
|
|
if (rc != 0) |
|
{ |
|
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
|
String("getpwnam_r failed: ") + String(strerror(errno))); |
|
return false; |
|
} |
|
|
|
if (result == 0) |
|
{ |
|
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
|
"getpwnam_r failed."); |
|
return false; |
|
} |
|
|
|
Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL4, |
|
"Changing user context to: uid = %d, gid = %d", |
|
(int)pwd.pw_uid, (int)pwd.pw_gid); |
|
|
|
if (setgid(pwd.pw_gid) != 0) |
|
{ |
|
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
|
String("setgid failed: ") + String(strerror(errno))); |
|
return false; |
|
} |
|
|
|
if (setuid(pwd.pw_uid) != 0) |
|
{ |
|
PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
|
String("setuid failed: ") + String(strerror(errno))); |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
|
#endif |
Uint32 System::getPID() | Uint32 System::getPID() |
{ | { |
// | // |
|
|
return ( ret != -1 ); | return ( ret != -1 ); |
} | } |
| |
void System::openlog(const String ident) |
Boolean System::verifyFileOwnership(const char* path) |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
struct stat st; |
// ATTN: Hard-code the "cimserver" identifier until the infrastructure |
|
// is set up to pass this as the "ident" string. |
|
//::openlog(ident.getCString(), LOG_PID|LOG_CONS, LOG_DAEMON); |
|
::openlog("cimserver", LOG_PID, LOG_DAEMON); |
|
| |
|
#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 (lstat(path, &st) != 0) |
|
{ |
|
return false; |
|
} |
#endif | #endif |
| |
return; |
return ((st.st_uid == geteuid()) && // Verify the file owner |
|
S_ISREG(st.st_mode) && // Verify it is a regular file |
|
(st.st_nlink == 1)); // Verify it is not a hard link |
} | } |
| |
void System::syslog(Uint32 severity, const char *data) |
void System::syslog(const String& ident, Uint32 severity, const char* message) |
|
{ |
|
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) |
|
|
|
// Since the openlog(), syslog(), and closelog() function calls must be |
|
// coordinated (see below), we need a thread control. |
|
|
|
static Mutex logMutex; |
|
|
|
AutoMutex loglock(logMutex); |
|
|
|
// Get a const char* representation of the identifier string. Note: The |
|
// character string passed to the openlog() function must persist until |
|
// closelog() is called. The syslog() method uses this pointer directly |
|
// rather than a copy of the string it refers to. |
|
|
|
CString identCString = ident.getCString(); |
|
openlog(identCString, LOG_PID, LOG_DAEMON); |
|
|
|
// Map from the Logger log level to the system log level. |
|
|
|
Uint32 syslogLevel; |
|
if (severity & Logger::FATAL) |
|
{ |
|
syslogLevel = LOG_CRIT; |
|
} |
|
else if (severity & Logger::SEVERE) |
|
{ |
|
syslogLevel = LOG_ERR; |
|
} |
|
else if (severity & Logger::WARNING) |
|
{ |
|
syslogLevel = LOG_WARNING; |
|
} |
|
else if (severity & Logger::INFORMATION) |
|
{ |
|
syslogLevel = LOG_INFO; |
|
} |
|
else // if (severity & Logger::TRACE) |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
syslogLevel = LOG_DEBUG; |
|
} |
| |
// FUTURE-SF-P3-20020517 : Use the Syslog on HP-UX. Eventually only |
// Write the message to the system log. |
// certain messages will go to the Syslog and others to the |
|
// Pegasus Logger. |
|
Uint32 syslogLevel = LOG_DEBUG; |
|
| |
// Map the log levels. |
::syslog(syslogLevel, "%s", message); |
if (severity & Logger::TRACE) syslogLevel = LOG_DEBUG; |
|
if (severity & Logger::INFORMATION) syslogLevel = LOG_INFO; |
|
if (severity & Logger::WARNING) syslogLevel = LOG_WARNING; |
|
if (severity & Logger::SEVERE) syslogLevel = LOG_ERR; |
|
if (severity & Logger::FATAL) syslogLevel = LOG_CRIT; |
|
| |
::syslog(syslogLevel, "%s", data); |
closelog(); |
| |
#elif defined(PEGASUS_OS_OS400) | #elif defined(PEGASUS_OS_OS400) |
| |
std::string replacementData = data; |
std::string replacementData = message; |
// All messages will go to the joblog. In the future | // All messages will go to the joblog. In the future |
// some messages may go to other message queues yet | // some messages may go to other message queues yet |
// to be determined. | // to be determined. |
|
|
// turn into ycmMessage so we can put it in the job log | // turn into ycmMessage so we can put it in the job log |
#pragma convert(37) | #pragma convert(37) |
ycmMessage theMessage("CPIDF80", | ycmMessage theMessage("CPIDF80", |
data, |
message, |
strlen(data), |
strlen(message), |
"Logger", | "Logger", |
ycmCTLCIMID, | ycmCTLCIMID, |
TRUE); | TRUE); |
|
|
// turn into ycmMessage so we can put it in the job log | // turn into ycmMessage so we can put it in the job log |
#pragma convert(37) | #pragma convert(37) |
ycmMessage theMessage("CPDDF82", | ycmMessage theMessage("CPDDF82", |
data, |
message, |
strlen(data), |
strlen(message), |
"Logger", | "Logger", |
ycmCTLCIMID, | ycmCTLCIMID, |
TRUE); | TRUE); |
|
|
} | } |
| |
#endif | #endif |
|
|
return; |
|
} | } |
| |
void System::closelog() |
// System ID constants for Logger::put and Logger::trace |
|
#if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) |
|
const String System::CIMSERVER = "qycmcimom"; // Server system ID |
|
#else |
|
const String System::CIMSERVER = "cimserver"; // Server system ID |
|
#endif |
|
|
|
|
|
|
|
|
|
// |
|
// System Initializater for AIX |
|
// |
|
#ifdef PEGASUS_OS_AIX |
|
#include <cstdlib> |
|
|
|
class SystemInitializer |
{ | { |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
|
| |
::closelog(); |
public: |
|
/** |
|
* |
|
* Default constructor. |
|
* |
|
*/ |
|
SystemInitializer(); |
|
}; |
|
|
| |
#endif |
|
| |
return; |
SystemInitializer::SystemInitializer() |
|
{ |
|
putenv("XPG_SUS_ENV=ON"); |
} | } |
| |
// System ID constants for Logger::put and Logger::trace |
static SystemInitializer initializer; |
#if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) |
|
const String System::CIMSERVER = "qycmcimom"; // Server system ID |
|
#else |
|
const String System::CIMSERVER = "cimserver"; // Server system ID |
|
#endif | #endif |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |