version 1.33, 2003/11/12 18:21:34
|
version 1.41, 2004/07/23 07:51:25
|
|
|
// Author: Mike Brasher (mbrasher@bmc.com) | // Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// Modified By: Sushma Fernandes (sushma_fernandes@hp.com) | // Modified By: Sushma Fernandes (sushma_fernandes@hp.com) |
// |
|
// Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com) | // Nag Boranna, Hewlett-Packard Company (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) |
|
// 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 |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "System.h" | #include "System.h" |
| |
PEGASUS_NAMESPACE_BEGIN |
|
|
|
#include <windows.h> | #include <windows.h> |
#ifndef _WINSOCKAPI_ | #ifndef _WINSOCKAPI_ |
#include <winsock2.h> | #include <winsock2.h> |
|
|
#include <io.h> | #include <io.h> |
#include <conio.h> | #include <conio.h> |
#include <direct.h> | #include <direct.h> |
#include <sys/stat.h> |
|
#include <sys/types.h> | #include <sys/types.h> |
#include <windows.h> | #include <windows.h> |
#include <process.h> | #include <process.h> |
|
#include <lm.h> |
|
|
|
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::getHostName() | String System::getHostName() |
{ | { |
static char hostname[64]; |
static char hostname[PEGASUS_MAXHOSTNAMELEN]; |
| |
if (!*hostname) | if (!*hostname) |
gethostname(hostname, sizeof(hostname)); | gethostname(hostname, sizeof(hostname)); |
|
|
| |
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( |
|
|
return (String("Administrator")); | return (String("Administrator")); |
} | } |
| |
|
Boolean System::isGroupMember(const char* userName, const char* groupName) |
|
{ |
|
Boolean retVal = false; |
|
|
|
LPLOCALGROUP_USERS_INFO_0 pBuf = NULL; |
|
DWORD dwLevel = 0; |
|
DWORD dwFlags = LG_INCLUDE_INDIRECT ; |
|
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH; |
|
DWORD dwEntriesRead = 0; |
|
DWORD dwTotalEntries = 0; |
|
NET_API_STATUS nStatus; |
|
|
|
|
|
// |
|
// Call the NetUserGetLocalGroups function |
|
// specifying information level 0. |
|
// |
|
// The LG_INCLUDE_INDIRECT flag specifies that the |
|
// function should also return the names of the local |
|
// groups in which the user is indirectly a member. |
|
// |
|
nStatus = NetUserGetLocalGroups(NULL, |
|
(LPCWSTR)userName, |
|
dwLevel, |
|
dwFlags, |
|
(LPBYTE *) &pBuf, |
|
dwPrefMaxLen, |
|
&dwEntriesRead, |
|
&dwTotalEntries); |
|
|
|
// |
|
// If the call succeeds, |
|
// |
|
if (nStatus == NERR_Success) |
|
{ |
|
LPLOCALGROUP_USERS_INFO_0 pTmpBuf; |
|
DWORD i; |
|
DWORD dwTotalCount = 0; |
|
|
|
if ((pTmpBuf = pBuf) != NULL) |
|
{ |
|
// |
|
// Loop through the local groups that the user belongs |
|
// and find the matching group name. |
|
// |
|
for (i = 0; i < dwEntriesRead; i++) |
|
{ |
|
// |
|
// Compare the user's group name to groupName. |
|
// |
|
if ( strcmp ((char *)pTmpBuf->lgrui0_name, groupName) == 0 ) |
|
{ |
|
// User is a member of the group. |
|
retVal = true; |
|
break; |
|
} |
|
|
|
pTmpBuf++; |
|
dwTotalCount++; |
|
} |
|
} |
|
} |
|
|
|
// |
|
// Free the allocated memory. |
|
// |
|
if (pBuf != NULL) |
|
NetApiBufferFree(pBuf); |
|
|
|
// |
|
// If the given user and group are not found in the local group |
|
// then try on the global groups. |
|
// |
|
if (!retVal) |
|
{ |
|
LPGROUP_USERS_INFO_0 pBuf = NULL; |
|
dwLevel = 0; |
|
dwPrefMaxLen = MAX_PREFERRED_LENGTH; |
|
dwEntriesRead = 0; |
|
dwTotalEntries = 0; |
|
|
|
// |
|
// Call the NetUserGetGroups function, specifying level 0. |
|
// |
|
nStatus = NetUserGetGroups(NULL, |
|
(LPCWSTR)userName, |
|
dwLevel, |
|
(LPBYTE*)&pBuf, |
|
dwPrefMaxLen, |
|
&dwEntriesRead, |
|
&dwTotalEntries); |
|
// |
|
// If the call succeeds, |
|
// |
|
if (nStatus == NERR_Success) |
|
{ |
|
LPGROUP_USERS_INFO_0 pTmpBuf; |
|
DWORD i; |
|
DWORD dwTotalCount = 0; |
|
|
|
if ((pTmpBuf = pBuf) != NULL) |
|
{ |
|
// |
|
// Loop through the global groups to which the user belongs |
|
// and find the matching group name. |
|
// |
|
for (i = 0; i < dwEntriesRead; i++) |
|
{ |
|
// |
|
// Compare the user's group name to groupName. |
|
// |
|
if ( strcmp ((char *)pTmpBuf->grui0_name, groupName) == 0 ) |
|
{ |
|
// User is a member of the group. |
|
retVal = true; |
|
break; |
|
} |
|
|
|
pTmpBuf++; |
|
dwTotalCount++; |
|
} |
|
} |
|
} |
|
|
|
// |
|
// Free the allocated buffer. |
|
// |
|
if (pBuf != NULL) |
|
NetApiBufferFree(pBuf); |
|
} |
|
|
|
return retVal; |
|
} |
|
|
Uint32 System::getPID() | Uint32 System::getPID() |
{ | { |
return _getpid(); | return _getpid(); |
|
|
return (strcasecmp(_fullpath( full, path_slash, _MAX_PATH ), path_slash) == 0) ? true : false; | return (strcasecmp(_fullpath( full, path_slash, _MAX_PATH ), path_slash) == 0) ? true : false; |
} | } |
| |
|
// Changes file permissions on the given file. |
|
Boolean System::changeFilePermissions(const char* path, mode_t mode) |
|
{ |
|
// ATTN: File permissions are not currently defined in Windows |
|
return true; |
|
} |
|
|
void System::openlog(const String ident) | void System::openlog(const String ident) |
{ | { |
return; | return; |