version 1.47, 2005/02/27 17:43:08
|
version 1.54, 2005/06/10 18:28:45
|
|
|
#include <process.h> | #include <process.h> |
#include <lm.h> | #include <lm.h> |
| |
|
#define SECURITY_WIN32 |
|
#include <security.h> |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
#define PEGASUS_ACCESS_EXISTS 0 | #define PEGASUS_ACCESS_EXISTS 0 |
|
|
struct servent *serv; | struct servent *serv; |
| |
// | // |
// Get wbem-local port from /etc/services |
// Get the port number. |
// | // |
if ( (serv = getservbyname(serviceName, TCP)) != NULL ) | if ( (serv = getservbyname(serviceName, TCP)) != NULL ) |
{ | { |
localPort = serv->s_port; |
localPort = ntohs(serv->s_port); |
} | } |
else | else |
{ | { |
|
|
| |
String System::getEffectiveUserName() | String System::getEffectiveUserName() |
{ | { |
|
#if (_MSC_VER >= 1300) || defined(PEGASUS_WINDOWS_SDK_HOME) |
|
|
|
//Bug 3076 fix |
|
char fullUserName[UNLEN+1]; |
|
DWORD userNameSize = sizeof(fullUserName); |
|
char computerName[MAX_COMPUTERNAME_LENGTH+1]; |
|
DWORD computerNameSize = sizeof(computerName); |
|
char userName[UNLEN+1]; |
|
char userDomain[UNLEN+1]; |
|
String userId; |
|
|
|
if (!GetUserNameEx(NameSamCompatible, fullUserName, &userNameSize)) |
|
{ |
|
return String(); |
|
} |
|
|
|
char* index = strchr(fullUserName, '\\'); |
|
*index = '\0'; |
|
strcpy(userDomain, fullUserName); |
|
strcpy(userName, index + 1); |
|
|
|
//The above function will return the system name as the domain if |
|
//the user is not on a real domain. Strip this out so that the rest of |
|
//our windows user functions work. What if the system name and the domain |
|
//name are the same? |
|
GetComputerName(computerName, &computerNameSize); |
|
|
|
if (strcmp(computerName, userDomain) != 0) |
|
{ |
|
userId.append(userDomain); |
|
userId.append("\\"); |
|
userId.append(userName); |
|
} else |
|
{ |
|
userId.append(userName); |
|
} |
|
|
|
return userId; |
|
|
|
#else //original getEffectiveUserName function |
|
|
int retcode = 0; | int retcode = 0; |
| |
// UNLEN (256) is the limit, not including null | // UNLEN (256) is the limit, not including null |
|
|
} | } |
| |
return String(pUserName); | return String(pUserName); |
|
#endif |
} | } |
| |
String System::encryptPassword(const char* password, const char* salt) | String System::encryptPassword(const char* password, const char* salt) |
|
|
| |
char mUserName[UNLEN+1]; | char mUserName[UNLEN+1]; |
char mDomainName[UNLEN+1]; | char mDomainName[UNLEN+1]; |
|
char tUserName[UNLEN+1]; |
wchar_t wUserName[UNLEN+1]; | wchar_t wUserName[UNLEN+1]; |
wchar_t wDomainName[UNLEN+1]; | wchar_t wDomainName[UNLEN+1]; |
char* pbs; | char* pbs; |
|
|
LPUSER_INFO_1 pUserInfo = NULL; | LPUSER_INFO_1 pUserInfo = NULL; |
NET_API_STATUS nStatus = NULL; | NET_API_STATUS nStatus = NULL; |
| |
|
// Make a copy of the specified username, it cannot be used directly because it's |
|
// declared as const and strchr() may modify the string. |
|
strncpy(tUserName, userName, sizeof(tUserName) - 1); |
|
tUserName[sizeof(tUserName)- 1] = '\0'; |
|
|
//separate the domain and user name if both are present. | //separate the domain and user name if both are present. |
if (NULL != (pbs = strchr(userName, '\\'))) |
if (NULL != (pbs = strchr(tUserName, '\\'))) |
{ | { |
*pbs = '\0'; | *pbs = '\0'; |
strcpy(mDomainName, userName); |
strcpy(mDomainName, tUserName); |
strcpy(mUserName, pbs+1); | strcpy(mUserName, pbs+1); |
usingDomain = true; | usingDomain = true; |
| |
} else if ((NULL != (pbs = (strchr(userName, '@')))) || |
} else if ((NULL != (pbs = (strchr(tUserName, '@')))) || |
(NULL != (pbs = (strchr(userName, '.'))))) |
(NULL != (pbs = (strchr(tUserName, '.'))))) |
{ | { |
*pbs = '\0'; | *pbs = '\0'; |
strcpy(mDomainName, pbs+1); | strcpy(mDomainName, pbs+1); |
strcpy(mUserName, userName); |
strcpy(mUserName, tUserName); |
usingDomain = true; | usingDomain = true; |
| |
} else | } else |
{ | { |
strcpy(mDomainName, "."); | strcpy(mDomainName, "."); |
strcpy(mUserName, userName); |
strcpy(mUserName, tUserName); |
} | } |
| |
//convert domain name to unicode | //convert domain name to unicode |
|
|
const char* path, | const char* path, |
size_t newSize) | size_t newSize) |
{ | { |
int fd = open(path, O_RDWR); |
|
| |
if (fd == -1) |
Boolean rv = false; |
return false; |
int fd = open(path, O_RDWR); |
|
if (fd != -1) |
if (chsize(fd, newSize) != 0) |
{ |
return false; |
if (chsize(fd, newSize) == 0) |
|
{ |
|
rv = true; |
|
} |
| |
close(fd); | close(fd); |
return true; |
} |
|
|
|
return rv; |
} | } |
| |
// Is absolute path? | // Is absolute path? |
|
|
path_slash[_MAX_PATH-1] = '\0'; | path_slash[_MAX_PATH-1] = '\0'; |
| |
for(p = path_slash; p < path_slash + strlen(path_slash); p++) | for(p = path_slash; p < path_slash + strlen(path_slash); p++) |
if (*p == '/') *p = '\\'; |
if (*p == '/') |
|
*p = '\\'; |
| |
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; |
} | } |
|
|
return true; | return true; |
} | } |
| |
void System::openlog(const String &ident) |
void System::syslog(const String& ident, Uint32 severity, const char* message) |
{ |
|
return; |
|
} |
|
|
|
void System::syslog(Uint32 severity, const char *data) |
|
{ |
|
return; |
|
} |
|
|
|
void System::closelog() |
|
{ | { |
return; |
// Not implemented |
} | } |
| |
// System ID constants for Logger::put and Logger::trace | // System ID constants for Logger::put and Logger::trace |