version 1.43, 2008/02/13 06:55:37
|
version 1.44, 2008/02/26 19:29:14
|
|
|
| |
String System::getEffectiveUserName() | String System::getEffectiveUserName() |
{ | { |
|
#if defined(PEGASUS_OS_ZOS) |
|
char effective_username[9]; |
|
__getuserid(effective_username, 9); |
|
__etoa_l(effective_username,9); |
|
return String(effective_username); |
|
#else |
String userName; | String userName; |
struct passwd* pwd = NULL; | struct passwd* pwd = NULL; |
|
|
#if defined(PEGASUS_OS_SOLARIS) || \ |
|
defined(PEGASUS_OS_HPUX) || \ |
|
defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_OS_VMS) |
|
|
|
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) != 0) | if (getpwuid_r(geteuid(), &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0) |
{ | { |
String errorMsg = String("getpwuid_r failure : ") + |
PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
String(strerror(errno)); |
"getpwuid_r failure: %s", strerror(errno))); |
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); |
|
} | } |
#elif defined(PEGASUS_OS_ZOS) |
else if (pwd == NULL) |
char effective_username[9]; |
|
__getuserid(effective_username, 9); |
|
__etoa_l(effective_username,9); |
|
userName.assign(effective_username); |
|
return userName; |
|
#else |
|
// |
|
// get the currently logged in user's UID. |
|
// |
|
pwd = getpwuid(geteuid()); |
|
#endif |
|
if (pwd == NULL) |
|
{ | { |
// L10N TODO - This message needs to be added. |
PEG_TRACE_CSTRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
//Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, |
"getpwuid_r failure; user may have been removed"); |
// "getpwuid_r failure, user may have been removed just after login"); |
|
PEG_TRACE_CSTRING(TRC_OS_ABSTRACTION, Tracer::LEVEL4, |
|
"getpwuid_r failure, user may have been removed just after login"); |
|
} | } |
else | else |
{ | { |
|
|
} | } |
| |
return userName; | return userName; |
|
#endif |
} | } |
| |
String System::encryptPassword(const char* password, const char* salt) | String System::encryptPassword(const char* password, const char* salt) |
|
|
| |
Boolean System::isSystemUser(const char* userName) | Boolean System::isSystemUser(const char* userName) |
{ | { |
#if defined(PEGASUS_OS_SOLARIS) || \ |
|
defined(PEGASUS_OS_HPUX) || \ |
|
defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_OS_VMS) |
|
|
|
const unsigned int PWD_BUFF_SIZE = 1024; | const unsigned int PWD_BUFF_SIZE = 1024; |
struct passwd pwd; | struct passwd pwd; |
struct passwd *result; | struct passwd *result; |
|
|
| |
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 : ") + |
PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
String(strerror(errno)); |
"getpwnam_r failure: %s", strerror(errno))); |
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 (result != NULL); |
return false; |
|
|
|
return true; |
|
|
|
#else /* default */ |
|
|
|
return getpwnam(userName) != NULL; |
|
|
|
#endif /* default */ |
|
} | } |
| |
Boolean System::isPrivilegedUser(const String& userName) | Boolean System::isPrivilegedUser(const String& userName) |
|
|
#endif | #endif |
} | } |
| |
static String _priviledgedUserName; |
static String _privilegedUserName; |
static Once _priviledgedUserNameOnce = PEGASUS_ONCE_INITIALIZER; |
static Once _privilegedUserNameOnce = PEGASUS_ONCE_INITIALIZER; |
| |
static void _initPrivilegedUserName() | static void _initPrivilegedUserName() |
{ | { |
struct passwd* pwd = NULL; | struct passwd* pwd = NULL; |
|
|
#if defined(PEGASUS_OS_SOLARIS) || \ |
|
defined(PEGASUS_OS_HPUX) || \ |
|
defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_OS_VMS) |
|
|
|
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]; |
|
|
#else | #else |
uid = 0; | uid = 0; |
#endif | #endif |
|
|
if (getpwuid_r(uid, &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0) | if (getpwuid_r(uid, &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0) |
{ | { |
String errorMsg = String("getpwuid_r failure : ") + |
PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2, |
String(strerror(errno)); |
"getpwuid_r failure: %s", strerror(errno))); |
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 if (pwd == NULL) |
#else /* default */ |
|
|
|
pwd = getpwuid(0); |
|
|
|
#endif /* default */ |
|
|
|
if ( pwd != NULL ) |
|
{ | { |
_priviledgedUserName.assign(pwd->pw_name); |
PEG_TRACE_CSTRING( |
|
TRC_OS_ABSTRACTION, Tracer::LEVEL4, |
|
"getpwuid_r: Could not find entry."); |
|
PEGASUS_ASSERT(0); |
} | } |
else | else |
{ | { |
PEG_TRACE_CSTRING( |
_privilegedUserName.assign(pwd->pw_name); |
TRC_OS_ABSTRACTION, Tracer::LEVEL4, "Could not find entry."); |
|
PEGASUS_ASSERT(0); |
|
} | } |
} | } |
| |
String System::getPrivilegedUserName() | String System::getPrivilegedUserName() |
{ | { |
once(&_priviledgedUserNameOnce, _initPrivilegedUserName); |
once(&_privilegedUserNameOnce, _initPrivilegedUserName); |
return _priviledgedUserName; |
return _privilegedUserName; |
} | } |
| |
#if !defined(PEGASUS_OS_VMS) || defined(PEGASUS_ENABLE_USERGROUP_AUTHORIZATION) | #if !defined(PEGASUS_OS_VMS) || defined(PEGASUS_ENABLE_USERGROUP_AUTHORIZATION) |