version 1.84, 2004/06/21 18:44:39
|
version 1.92, 2004/10/17 20:39:17
|
|
|
//%2003//////////////////////////////////////////////////////////////////////// |
//%2004//////////////////////////////////////////////////////////////////////// |
// | // |
// 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. |
// | // |
// 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 |
|
|
// Bapu Patil (bapu_patil@hp.com) | // Bapu Patil (bapu_patil@hp.com) |
// | // |
// Modified By: Dave Rosckes (rosckes@us.ibm.com) | // Modified By: Dave Rosckes (rosckes@us.ibm.com) |
|
// Amit K Arora (amita@in.ibm.com) for PEP101 |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#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> |
#ifdef PEGASUS_ZOS_SECURITY | #ifdef PEGASUS_ZOS_SECURITY |
#include "DynamicLibraryzOS_inline.h" | #include "DynamicLibraryzOS_inline.h" |
#endif | #endif |
| |
|
#if defined(PEGASUS_OS_LSB) |
|
#include <netinet/in.h> |
|
#include <termios.h> |
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#endif |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
#ifdef PEGASUS_OS_OS400 | #ifdef PEGASUS_OS_OS400 |
|
|
{ | { |
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) |
|
|
// 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::getFullyQualifiedHostName () | String System::getFullyQualifiedHostName () |
{ | { |
#ifdef PEGASUS_OS_HPUX |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_LINUX) |
char hostName [PEGASUS_MAXHOSTNAMELEN]; | char hostName [PEGASUS_MAXHOSTNAMELEN]; |
struct hostent *he; | struct hostent *he; |
String fqName; | String fqName; |
|
|
return String::EMPTY; | return String::EMPTY; |
} | } |
| |
if (he = gethostbyname (hostName)) |
if ((he = gethostbyname (hostName))) |
{ | { |
strcpy (hostName, he->h_name); | strcpy (hostName, he->h_name); |
} | } |
|
|
| |
String System::getSystemCreationClassName () | String System::getSystemCreationClassName () |
{ | { |
#ifdef PEGASUS_OS_HPUX |
// |
|
// 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 |
|
// |
|
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) |
return "CIM_ComputerSystem"; | return "CIM_ComputerSystem"; |
#else | #else |
// | // |
|
|
| |
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; |
|
|
// Search supplemental groups. | // Search supplemental groups. |
// Get a user group entry | // 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, | if ( getgrnam_r(groupName, &grp, |
grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 ) | grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 ) |
|
|
|
#endif |
{ | { |
String errorMsg = String("getgrnam_r failure : ") + | String errorMsg = String("getgrnam_r failure : ") + |
String(strerror(errno)); | String(strerror(errno)); |