version 1.22, 2005/02/19 02:46:42
|
version 1.31.8.1, 2007/03/23 21:53:51
|
|
|
//%2005//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// 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. |
|
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; | // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
// EMC Corporation; VERITAS Software Corporation; The Open Group. | // EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec 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 |
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com) |
|
// |
|
// Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01 |
|
// added nsk platform support |
|
// Amit K Arora, IBM (amita@in.ibm.com) for Bug#1527 |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com) |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <fstream> |
|
#include <iostream> |
|
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/TraceFileHandler.h> | #include <Pegasus/Common/TraceFileHandler.h> |
|
#include <Pegasus/Common/Executor.h> |
| |
#if defined(PEGASUS_OS_TYPE_WINDOWS) | #if defined(PEGASUS_OS_TYPE_WINDOWS) |
# include <Pegasus/Common/TraceFileHandlerWindows.cpp> | # include <Pegasus/Common/TraceFileHandlerWindows.cpp> |
#elif defined(PEGASUS_OS_TYPE_UNIX) |
#elif defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS) |
# include <Pegasus/Common/TraceFileHandlerUnix.cpp> |
# include <Pegasus/Common/TraceFileHandlerPOSIX.cpp> |
#elif defined(PEGASUS_OS_TYPE_NSK) |
|
# include <Pegasus/Common/TraceFileHandlerNsk.cpp> |
|
#elif defined(PEGASUS_OS_VMS) |
|
# include <Pegasus/Common/TraceFileHandlerVms.cpp> |
|
#else | #else |
# error "Unsupported platform" | # error "Unsupported platform" |
#endif | #endif |
|
|
{ | { |
fclose(_fileHandle); | fclose(_fileHandle); |
} | } |
if (_fileName) |
|
{ |
|
delete []_fileName; | delete []_fileName; |
} |
|
#ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU | #ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU |
if (_baseFileName) |
|
{ |
|
delete []_baseFileName; | delete []_baseFileName; |
} |
|
#endif | #endif |
} | } |
| |
|
|
{ | { |
return 1; | return 1; |
} | } |
|
|
_fileHandle = _openFile(fileName); | _fileHandle = _openFile(fileName); |
if (!_fileHandle) | if (!_fileHandle) |
{ | { |
|
|
| |
FILE* TraceFileHandler::_openFile(const char* fileName) | FILE* TraceFileHandler::_openFile(const char* fileName) |
{ | { |
FILE* fileHandle = fopen(fileName,"a+"); |
#ifdef PEGASUS_OS_VMS |
|
FILE* fileHandle = fopen(fileName,"w", "shr=get,put,upd"); |
|
#else |
|
FILE* fileHandle = Executor::openFile(fileName, 'a'); |
|
#endif |
if (!fileHandle) | if (!fileHandle) |
{ | { |
// Unable to open file, log a message | // Unable to open file, log a message |
Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING, |
Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING, |
"Common.TraceFileHandler.FAILED_TO_OPEN_FILE", | "Common.TraceFileHandler.FAILED_TO_OPEN_FILE", |
"Failed to open file $0", fileName); | "Failed to open file $0", fileName); |
return 0; | return 0; |
} | } |
| |
|
// We are done if the executor was used to perform this. Otherwise, we |
|
// must proceed to fix file ownership and permissions. |
|
|
|
if (Executor::detectExecutor() == 0) |
|
return fileHandle; |
|
|
|
// |
|
// Verify that the file has the correct owner |
|
// |
|
if (!System::verifyFileOwnership(fileName)) |
|
{ |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING, |
|
"Common.TraceFileHandler.UNEXPECTED_FILE_OWNER", |
|
"File $0 is not owned by user $1.", fileName, |
|
System::getEffectiveUserName()); |
|
fclose(fileHandle); |
|
return 0; |
|
} |
|
|
// | // |
// Set the file permissions to 0600 | // Set the file permissions to 0600 |
// | // |
|
|
String(fileName), (_S_IREAD|_S_IWRITE)) ) | String(fileName), (_S_IREAD|_S_IWRITE)) ) |
#endif | #endif |
{ | { |
Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING, |
Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING, |
"Common.TraceFileHandler.FAILED_TO_SET_FILE_PERMISSIONS", | "Common.TraceFileHandler.FAILED_TO_SET_FILE_PERMISSIONS", |
"Failed to set permissions on file $0", fileName); | "Failed to set permissions on file $0", fileName); |
fclose(fileHandle); | fclose(fileHandle); |
return 0; | return 0; |
} | } |
| |
// |
return fileHandle; |
// Verify that the file has the correct owner |
|
// |
|
if (!System::verifyFileOwnership(fileName)) |
|
{ |
|
Logger::put_l(Logger::ERROR_LOG, "Tracer", Logger::WARNING, |
|
"Common.TraceFileHandler.UNEXPECTED_FILE_OWNER", |
|
"File $0 is not owned by user $1.", fileName, |
|
System::getEffectiveUserName()); |
|
fclose(fileHandle); |
|
return 0; |
|
} | } |
| |
return fileHandle; |
static bool _canWrite(const String& path) |
|
{ |
|
if (Executor::detectExecutor() == 0) |
|
return true; |
|
else |
|
return FileSystem::canWrite(path); |
} | } |
| |
Boolean TraceFileHandler::isValidFilePath(const char* filePath) | Boolean TraceFileHandler::isValidFilePath(const char* filePath) |
|
|
// Check if the file exists and is writable | // Check if the file exists and is writable |
if (FileSystem::exists(fileName)) | if (FileSystem::exists(fileName)) |
{ | { |
if (!FileSystem::canWrite(fileName)) |
if (!_canWrite(fileName)) |
{ | { |
return 0; | return 0; |
} | } |
|
|
{ | { |
return 0; | return 0; |
} | } |
if (!FileSystem::canWrite(dirName) ) |
if (!_canWrite(dirName) ) |
{ | { |
return 0; | return 0; |
} | } |
|
|
// current working directory | // current working directory |
FileSystem::getCurrentDirectory(currentDir); | FileSystem::getCurrentDirectory(currentDir); |
| |
if (!FileSystem::canWrite(currentDir)) |
if (!_canWrite(currentDir)) |
{ | { |
return 0; | return 0; |
} | } |
|
|
} | } |
PEGASUS_UNREACHABLE(return 1;) | PEGASUS_UNREACHABLE(return 1;) |
} | } |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |