Commit 8026074b authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Checking the accessibility of the mock name server base path in each method...

Checking the accessibility of the mock name server base path in each method (of the mock name server) and reporting meaningful error
parent c3a7846a
......@@ -271,7 +271,8 @@ should look something like the following.
\begin{verbatim}
#sec.protocol unix
sec.protocol krb5 /etc/krb5.keytab.eos host/<host>@CERN.CH
#sec.protocol gsi -crl:0 -cert:/etc/grid-security/daemon/hostcert.pem -key:/etc/grid-security/daemon/hostkey.pem -gridmap:/etc/grid-security/gri
#sec.protocol gsi -crl:0 -cert:/etc/grid-security/daemon/hostcert.pem
-key:/etc/grid-security/daemon/hostkey.pem -gridmap:/etc/grid-security/gri
sec.protbind * only krb5 sss
mgmofs.broker root://devbox.cern.ch:1097//eos/
\end{verbatim}
......@@ -373,7 +374,8 @@ yum install binutils-devel
yum install zeromq3-devel
yum install libcap-devel
yum install openssl-devel
yum install castor-lib-client castor-lib-server <- this required CASTOR_SLC6.repo (or castor-jenkins.repo)
yum install castor-lib-client castor-lib-server
[this required CASTOR_SLC6.repo (or castor-jenkins.repo)]
yum install castor-tapegatewayd
yum install castor-tapegateway-server
yum install castor-libtapegatewayd
......
......@@ -33,10 +33,27 @@
#include "common/Utils.hpp"
#include "nameserver/mockNS/MockNameServer.hpp"
//------------------------------------------------------------------------------
// assertBasePathAccessible
//------------------------------------------------------------------------------
void cta::MockNameServer::assertBasePathAccessible() const {
std::string basePath = m_fsDir+"/";
DIR *const dp = opendir(basePath.c_str());
if(dp == NULL) {
std::ostringstream msg;
msg << __FUNCTION__ << " - Mock Nameserver base path " << basePath << " is not accessible by the xroot server plugin. Please check its existence and its permissions.\n";
throw(exception::Exception(msg.str()));
}
closedir(dp);
}
//------------------------------------------------------------------------------
// assertFsDirExists
//------------------------------------------------------------------------------
void cta::MockNameServer::assertFsDirExists(const std::string &path) const {
assertBasePathAccessible();
struct stat statResult;
if(::stat(path.c_str(), &statResult)) {
......@@ -58,6 +75,7 @@ void cta::MockNameServer::assertFsDirExists(const std::string &path) const {
// assertFsFileExists
//------------------------------------------------------------------------------
void cta::MockNameServer::assertFsFileExists(const std::string &path) const {
assertBasePathAccessible();
struct stat statResult;
if(::stat(path.c_str(), &statResult)) {
......@@ -80,6 +98,7 @@ void cta::MockNameServer::assertFsFileExists(const std::string &path) const {
//------------------------------------------------------------------------------
void cta::MockNameServer::assertFsPathDoesNotExist(const std::string &path)
const {
assertBasePathAccessible();
struct stat statResult;
if(::stat(path.c_str(), &statResult) == 0) {
......@@ -103,6 +122,7 @@ void cta::MockNameServer::createStorageClass(const SecurityIdentity &requester,
//------------------------------------------------------------------------------
void cta::MockNameServer::createStorageClass(const SecurityIdentity &requester,
const std::string &name, const uint16_t nbCopies, const uint32_t id) {
assertBasePathAccessible();
std::lock_guard<std::mutex> lock(m_mutex);
if(9999 < id) {
std::ostringstream msg;
......@@ -123,6 +143,7 @@ void cta::MockNameServer::createStorageClass(const SecurityIdentity &requester,
//------------------------------------------------------------------------------
void cta::MockNameServer::deleteStorageClass(const SecurityIdentity &requester,
const std::string &name) {
assertBasePathAccessible();
std::lock_guard<std::mutex> lock(m_mutex);
for(auto itor = m_storageClasses.begin(); itor != m_storageClasses.end();
itor++) {
......@@ -143,6 +164,7 @@ void cta::MockNameServer::deleteStorageClass(const SecurityIdentity &requester,
//------------------------------------------------------------------------------
void cta::MockNameServer::updateStorageClass(const SecurityIdentity &requester,
const std::string &name, const uint16_t nbCopies) {
assertBasePathAccessible();
std::lock_guard<std::mutex> lock(m_mutex);
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
}
......@@ -154,6 +176,7 @@ void cta::MockNameServer::assertStorageClassIsNotInUse(
const SecurityIdentity &requester,
const std::string &storageClass,
const std::string &path) const {
assertBasePathAccessible();
if(getDirStorageClass(requester, path) == storageClass) {
std::ostringstream msg;
......@@ -237,6 +260,7 @@ cta::NameServerTapeFile cta::MockNameServer::fromStringToNameServerTapeFile(cons
// addTapeFile
//------------------------------------------------------------------------------
void cta::MockNameServer::addTapeFile(const SecurityIdentity &requester, const std::string &path, const NameServerTapeFile &tapeFile) {
assertBasePathAccessible();
std::lock_guard<std::mutex> lock(m_mutex);
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
......@@ -255,6 +279,7 @@ void cta::MockNameServer::addTapeFile(const SecurityIdentity &requester, const s
// getTapeFiles
//------------------------------------------------------------------------------
std::list<cta::NameServerTapeFile> cta::MockNameServer::getTapeFiles(const SecurityIdentity &requester, const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
assertFsFileExists(fsPath);
......@@ -274,6 +299,7 @@ std::list<cta::NameServerTapeFile> cta::MockNameServer::getTapeFiles(const Secur
// deleteTapeFile
//------------------------------------------------------------------------------
void cta::MockNameServer::deleteTapeFile(const SecurityIdentity &requester, const std::string &path, const uint16_t copyNb) {
assertBasePathAccessible();
std::lock_guard<std::mutex> lock(m_mutex);
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
......@@ -312,10 +338,10 @@ cta::MockNameServer::MockNameServer(): m_fileIdCounter(0), m_deleteOnExit(true)
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::MockNameServer::MockNameServer(const std::string &path): m_fileIdCounter(0), m_deleteOnExit(false) {
cta::MockNameServer::MockNameServer(const std::string &path): m_fsDir(path), m_fileIdCounter(0), m_deleteOnExit(false) {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
assertFsDirExists(path);
m_fsDir = path;
}
//------------------------------------------------------------------------------
......@@ -335,6 +361,7 @@ cta::MockNameServer::~MockNameServer() throw() {
void cta::MockNameServer::setDirStorageClass(const SecurityIdentity &requester,
const std::string &path, const std::string &storageClassName) {
std::lock_guard<std::mutex> lock(m_mutex);
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
assertFsDirExists(fsPath);
......@@ -347,6 +374,7 @@ void cta::MockNameServer::setDirStorageClass(const SecurityIdentity &requester,
void cta::MockNameServer::clearDirStorageClass(
const SecurityIdentity &requester,
const std::string &path) {
assertBasePathAccessible();
setDirStorageClass(requester, path, "");
}
......@@ -356,6 +384,7 @@ void cta::MockNameServer::clearDirStorageClass(
std::string cta::MockNameServer::getDirStorageClass(
const SecurityIdentity &requester,
const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
assertFsDirExists(fsPath);
......@@ -373,6 +402,7 @@ void cta::MockNameServer::createFile(
const uint64_t size) {
{
std::lock_guard<std::mutex> lock(m_mutex);
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string dir = Utils::getEnclosingPath(path);
assertFsDirExists(m_fsDir + dir);
......@@ -420,6 +450,7 @@ void cta::MockNameServer::assertIsOwner(
const SecurityIdentity &requester,
const UserIdentity &user,
const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const UserIdentity owner = getOwner(requester, path);
......@@ -439,6 +470,7 @@ void cta::MockNameServer::setOwner(
const std::string &path,
const UserIdentity &owner) {
std::lock_guard<std::mutex> lock(m_mutex);
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string uidStr = Utils::toString(owner.uid);
const std::string gidStr = Utils::toString(owner.gid);
......@@ -454,6 +486,7 @@ void cta::MockNameServer::setOwner(
cta::UserIdentity cta::MockNameServer::getOwner(
const SecurityIdentity &requester,
const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
const std::string uidStr = Utils::getXattr(fsPath, "user.CTAuid");
......@@ -478,7 +511,8 @@ void cta::MockNameServer::createDir(const SecurityIdentity &requester,
const std::string &path, const mode_t mode) {
std::string inheritedStorageClass = "";
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<std::mutex> lock(m_mutex);
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string enclosingPath = Utils::getEnclosingPath(path);
assertFsDirExists(m_fsDir + enclosingPath);
......@@ -509,6 +543,7 @@ void cta::MockNameServer::createDir(const SecurityIdentity &requester,
//------------------------------------------------------------------------------
void cta::MockNameServer::deleteFile(const SecurityIdentity &requester, const std::string &path) {
std::lock_guard<std::mutex> lock(m_mutex);
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
......@@ -527,6 +562,7 @@ void cta::MockNameServer::deleteFile(const SecurityIdentity &requester, const st
void cta::MockNameServer::deleteDir(const SecurityIdentity &requester,
const std::string &path) {
std::lock_guard<std::mutex> lock(m_mutex);
assertBasePathAccessible();
if(path == "/") {
std::ostringstream msg;
msg << __FUNCTION__ << " - Cannot delete root directory";
......@@ -550,6 +586,7 @@ void cta::MockNameServer::deleteDir(const SecurityIdentity &requester,
std::unique_ptr<cta::ArchiveFileStatus> cta::MockNameServer::statFile(
const SecurityIdentity &requester,
const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string name = Utils::getEnclosedName(path);
const std::string enclosingPath = Utils::getEnclosingPath(path);
......@@ -578,7 +615,8 @@ std::unique_ptr<cta::ArchiveFileStatus> cta::MockNameServer::statFile(
//------------------------------------------------------------------------------
std::list<cta::ArchiveDirEntry> cta::MockNameServer::getDirEntries(
const SecurityIdentity &requester,
const std::string &path) const {
const std::string &path) const {
assertBasePathAccessible();
const std::string fsPath = m_fsDir + path;
DIR *const dp = opendir(fsPath.c_str());
......@@ -613,6 +651,7 @@ std::list<cta::ArchiveDirEntry> cta::MockNameServer::getDirEntries(
cta::ArchiveDirEntry cta::MockNameServer::getArchiveDirEntry(
const SecurityIdentity &requester,
const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string fsPath = m_fsDir + path;
......@@ -635,6 +674,7 @@ cta::ArchiveDirEntry cta::MockNameServer::getArchiveDirEntry(
const SecurityIdentity &requester,
const std::string &path,
const struct stat statResult) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
const std::string enclosingPath = Utils::getEnclosingPath(path);
const std::string name = Utils::getEnclosedName(path);
......@@ -679,6 +719,7 @@ cta::ArchiveDirEntry cta::MockNameServer::getArchiveDirEntry(
//------------------------------------------------------------------------------
cta::ArchiveDirIterator cta::MockNameServer::getDirContents(
const SecurityIdentity &requester, const std::string &path) const {
assertBasePathAccessible();
Utils::assertAbsolutePathSyntax(path);
assertFsDirExists(m_fsDir+path);
return getDirEntries(requester, path);
......@@ -691,6 +732,7 @@ std::string cta::MockNameServer::getVidOfFile(
const SecurityIdentity &requester,
const std::string &path,
const uint16_t copyNb) const {
assertBasePathAccessible();
if(copyNb!=1 || copyNb!=2) {
std::ostringstream msg;
msg << "cta::MockNameServer::getVidOfFile() - The mock nameserver only supports the copy number to be 1 or 2. Instead the one supplied is: " << copyNb;
......
......@@ -145,6 +145,8 @@ private:
std::string m_fsDir;
void assertBasePathAccessible() const;
void assertFsDirExists(const std::string &path) const;
void assertFsFileExists(const std::string &path) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment