version 1.38, 2004/06/22 22:16:21
|
version 1.47, 2005/02/27 17:43:08
|
|
|
//%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: Dave Rosckes (rosckes@us.ibm.com) | // Modified By: Dave Rosckes (rosckes@us.ibm.com) |
// Terry Martin, Hewlett-Packard Company (terry.martin@hp.com) | // Terry Martin, Hewlett-Packard Company (terry.martin@hp.com) |
|
// Amit K Arora, IBM (amita@in.ibm.com) for Bug#1428 |
|
// Seema Gupta (gseema@in.ibm.com) for Bug#1617 |
|
// David Dillard, VERITAS Software Corp. |
|
// (david.dillard@veritas.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
#define ACCESS_EXISTS 0 |
#define PEGASUS_ACCESS_EXISTS 0 |
#define ACCESS_WRITE 2 |
#define PEGASUS_ACCESS_WRITE 2 |
#define ACCESS_READ 4 |
#define PEGASUS_ACCESS_READ 4 |
#define ACCESS_READ_AND_WRITE 6 |
#define PEGASUS_ACCESS_READ_AND_WRITE 6 |
| |
#define PW_BUFF_LEN 65 | #define PW_BUFF_LEN 65 |
| |
|
|
| |
Boolean System::exists(const char* path) | Boolean System::exists(const char* path) |
{ | { |
return _access(path, ACCESS_EXISTS) == 0; |
return _access(path, PEGASUS_ACCESS_EXISTS) == 0; |
} | } |
| |
Boolean System::canRead(const char* path) | Boolean System::canRead(const char* path) |
{ | { |
return _access(path, ACCESS_READ) == 0; |
return _access(path, PEGASUS_ACCESS_READ) == 0; |
} | } |
| |
Boolean System::canWrite(const char* path) | Boolean System::canWrite(const char* path) |
{ | { |
return _access(path, ACCESS_WRITE) == 0; |
return _access(path, PEGASUS_ACCESS_WRITE) == 0; |
} | } |
| |
Boolean System::getCurrentDirectory(char* path, Uint32 size) | Boolean System::getCurrentDirectory(char* path, Uint32 size) |
|
|
| |
String System::getFullyQualifiedHostName () | String System::getFullyQualifiedHostName () |
{ | { |
// |
static char FQHostName[PEGASUS_MAXHOSTNAMELEN]; |
// ATTN: Implement this method to return the fully qualified host name |
|
// |
if (!*FQHostName) |
|
{ |
|
String hostname = getHostName(); |
|
struct hostent* hostEnt; |
|
|
|
hostEnt = gethostbyname((const char *)hostname.getCString()); |
|
if (hostEnt == NULL) |
|
{ |
return String::EMPTY; | return String::EMPTY; |
} | } |
|
strcpy(FQHostName, hostEnt->h_name); |
|
} |
|
|
|
return FQHostName; |
|
} |
| |
String System::getSystemCreationClassName () | String System::getSystemCreationClassName () |
{ | { |
// |
return "CIM_ComputerSystem"; |
// ATTN: Implement this method to return the system creation class name |
|
// |
|
return String::EMPTY; |
|
} | } |
| |
Uint32 System::lookupPort( | Uint32 System::lookupPort( |
|
|
| |
Boolean System::isSystemUser(const char* userName) | Boolean System::isSystemUser(const char* userName) |
{ | { |
//ATTN: Implement this method to verify if user is vaild on the local system |
Boolean isSystemUser = false; |
// This is used in User Manager |
|
return true; |
char mUserName[UNLEN+1]; |
|
char mDomainName[UNLEN+1]; |
|
wchar_t wUserName[UNLEN+1]; |
|
wchar_t wDomainName[UNLEN+1]; |
|
char* pbs; |
|
bool usingDomain = false; |
|
|
|
LPBYTE pComputerName=NULL; |
|
DWORD dwLevel = 1; |
|
LPUSER_INFO_1 pUserInfo = NULL; |
|
NET_API_STATUS nStatus = NULL; |
|
|
|
//separate the domain and user name if both are present. |
|
if (NULL != (pbs = strchr(userName, '\\'))) |
|
{ |
|
*pbs = '\0'; |
|
strcpy(mDomainName, userName); |
|
strcpy(mUserName, pbs+1); |
|
usingDomain = true; |
|
|
|
} else if ((NULL != (pbs = (strchr(userName, '@')))) || |
|
(NULL != (pbs = (strchr(userName, '.'))))) |
|
{ |
|
*pbs = '\0'; |
|
strcpy(mDomainName, pbs+1); |
|
strcpy(mUserName, userName); |
|
usingDomain = true; |
|
|
|
} else |
|
{ |
|
strcpy(mDomainName, "."); |
|
strcpy(mUserName, userName); |
} | } |
| |
Boolean System::isPrivilegedUser(const String userName) |
//convert domain name to unicode |
|
if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1)) |
{ | { |
// ATTN: Implement this method to verify if user executing the current |
return false; |
// command is a priviliged user, when user name is not passed as |
} |
// as argument. If user name is passed the function checks |
|
// whether the given user is a priviliged user. |
//convert username to unicode |
// This is used in cimuser CLI and CIMOperationRequestAuthorizer |
if (!MultiByteToWideChar(CP_ACP, 0, mUserName, -1, wUserName, strlen(mUserName)+1)) |
return true; |
{ |
|
return false; |
|
} |
|
|
|
if (usingDomain) |
|
{ |
|
//get domain controller |
|
DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName); |
|
if (rc == NERR_Success) |
|
{ |
|
wcscpy(wDomainName, (LPWSTR) pComputerName); //this is automatically prefixed with "\\" |
|
} |
|
/* |
|
else |
|
{ |
|
// failover |
|
// ATTN: This is commented out until there is resolution on Bugzilla 2236. -hns 2/2005 |
|
// This needs to be more thoroughly tested when we uncomment it out. |
|
|
|
PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL; |
|
|
|
//this function does not take wide strings |
|
rc = DsGetDcName(NULL, |
|
mDomainName, |
|
NULL, |
|
NULL, |
|
DS_DIRECTORY_SERVICE_REQUIRED, //not sure what flags we want here |
|
&DomainControllerInfo); |
|
|
|
if (rc == ERROR_SUCCESS && DomainControllerInfo) |
|
{ |
|
strcpy(mDomainName, DomainControllerInfo->DomainName); |
|
NetApiBufferFree(DomainControllerInfo); |
|
|
|
if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1)) |
|
{ |
|
return false; |
|
} |
|
} |
|
} |
|
*/ |
|
} |
|
|
|
//get user info |
|
nStatus = NetUserGetInfo(wDomainName, |
|
wUserName, |
|
dwLevel, |
|
(LPBYTE *)&pUserInfo); |
|
|
|
if (nStatus == NERR_Success) |
|
{ |
|
isSystemUser = true; |
|
} |
|
|
|
if (pComputerName != NULL) |
|
{ |
|
NetApiBufferFree(pComputerName); |
|
} |
|
|
|
if (pUserInfo != NULL) |
|
{ |
|
NetApiBufferFree(pUserInfo); |
|
} |
|
|
|
return isSystemUser; |
|
} |
|
|
|
|
|
Boolean System::isPrivilegedUser(const String& userName) |
|
{ |
|
Boolean isPrivileged = false; |
|
|
|
char mUserName[UNLEN+1]; |
|
char mDomainName[UNLEN+1]; |
|
wchar_t wUserName[UNLEN+1]; |
|
wchar_t wDomainName[UNLEN+1]; |
|
char* pbs; |
|
char userStr[UNLEN+1]; |
|
bool usingDomain = false; |
|
|
|
LPBYTE pComputerName=NULL; |
|
DWORD dwLevel = 1; |
|
LPUSER_INFO_1 pUserInfo = NULL; |
|
NET_API_STATUS nStatus = NULL; |
|
|
|
//get the username in the correct format |
|
strcpy(userStr, (const char*)userName.getCString()); |
|
|
|
//separate the domain and user name if both are present. |
|
if (NULL != (pbs = strchr(userStr, '\\'))) |
|
{ |
|
*pbs = '\0'; |
|
strcpy(mDomainName, userStr); |
|
strcpy(mUserName, pbs+1); |
|
usingDomain = true; |
|
|
|
} else if ((NULL != (pbs = (strchr(userStr, '@')))) || |
|
(NULL != (pbs = (strchr(userStr, '.'))))) |
|
{ |
|
*pbs = '\0'; |
|
strcpy(mDomainName, pbs+1); |
|
strcpy(mUserName, userStr); |
|
usingDomain = true; |
|
|
|
} else |
|
{ |
|
strcpy(mDomainName, "."); |
|
strcpy(mUserName, userStr); |
|
} |
|
|
|
//convert domain name to unicode |
|
if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1)) |
|
{ |
|
return false; |
|
} |
|
|
|
//convert username to unicode |
|
if (!MultiByteToWideChar(CP_ACP, 0, mUserName, -1, wUserName, strlen(mUserName)+1)) |
|
{ |
|
return false; |
|
} |
|
|
|
if (usingDomain) |
|
{ |
|
//get domain controller |
|
DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName); |
|
if (rc == NERR_Success) |
|
{ |
|
wcscpy(wDomainName, (LPWSTR) pComputerName); //this is automatically prefixed with "\\" |
|
} |
|
/* |
|
else |
|
{ |
|
// failover |
|
// ATTN: This is commented out until there is resolution on Bugzilla 2236. -hns 2/2005 |
|
// This needs to be more thoroughly tested when we uncomment it out. |
|
|
|
PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL; |
|
|
|
//this function does not take wide strings |
|
rc = DsGetDcName(NULL, |
|
mDomainName, |
|
NULL, |
|
NULL, |
|
DS_DIRECTORY_SERVICE_REQUIRED, //not sure what flags we want here |
|
&DomainControllerInfo); |
|
|
|
if (rc == ERROR_SUCCESS && DomainControllerInfo) |
|
{ |
|
strcpy(mDomainName, DomainControllerInfo->DomainName); |
|
NetApiBufferFree(DomainControllerInfo); |
|
|
|
if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1)) |
|
{ |
|
return false; |
|
} |
|
} |
|
} |
|
*/ |
|
} |
|
|
|
//get privileges |
|
nStatus = NetUserGetInfo(wDomainName, |
|
wUserName, |
|
dwLevel, |
|
(LPBYTE *)&pUserInfo); |
|
|
|
if ((nStatus == NERR_Success) && |
|
(pUserInfo != NULL) && |
|
(pUserInfo->usri1_priv == USER_PRIV_ADMIN)) |
|
{ |
|
isPrivileged = true; |
|
} |
|
|
|
if (pComputerName != NULL) |
|
{ |
|
NetApiBufferFree(pComputerName); |
|
} |
|
|
|
if (pUserInfo != NULL) |
|
{ |
|
NetApiBufferFree(pUserInfo); |
|
} |
|
|
|
return isPrivileged; |
} | } |
| |
String System::getPrivilegedUserName() | String System::getPrivilegedUserName() |
|
|
return retVal; | return retVal; |
} | } |
| |
|
Boolean System::changeUserContext(const char* userName) |
|
{ |
|
// ATTN: Implement this method to change the process user context to the |
|
// specified user |
|
return false; |
|
} |
|
|
Uint32 System::getPID() | Uint32 System::getPID() |
{ | { |
return _getpid(); | return _getpid(); |
|
|
return true; | return true; |
} | } |
| |
void System::openlog(const String ident) |
Boolean System::verifyFileOwnership(const char* path) |
|
{ |
|
// ATTN: Implement this to check that the owner of the specified file is |
|
// the same as the effective user for this process. |
|
return true; |
|
} |
|
|
|
void System::openlog(const String &ident) |
{ | { |
return; | return; |
} | } |