Commit 066fa4bc authored by Daniele Kruse's avatar Daniele Kruse
Browse files

WIP Bringing in the OSDB and improved the commandline encoder to use base64 encoding

parent cc5900af
......@@ -5,4 +5,4 @@ find_package (xrootd REQUIRED)
include_directories (${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR})
add_executable (cta CTACmdMain.cpp CTACmd.cpp)
target_link_libraries (cta ${XROOTD_XRDCL_LIB} ctacommon)
target_link_libraries (cta ${XROOTD_XRDCL_LIB} ctacommon cryptopp)
......@@ -21,6 +21,9 @@
#include "XrdCl/XrdClCopyProcess.hh"
#include <cryptopp/base64.h>
#include <cryptopp/osrng.h>
#include <iostream>
//------------------------------------------------------------------------------
......@@ -89,12 +92,12 @@ int CTACopyCmd::sendCommand(const int argc, const char **argv) const {
//------------------------------------------------------------------------------
std::string CTACopyCmd::formatCommandPath(const int argc, const char **argv) const {
std::string cmdPath = "root://localhost//";
std::string arg = argv[0];
replaceAll(arg, "&", "_#_and_#_");
std::string arg = encode(std::string(argv[0]));
replaceAll(arg, "/", "_");
cmdPath += arg;
for(int i=1; i<argc; i++) {
std::string arg = argv[i];
replaceAll(arg, "&", "_#_and_#_");
std::string arg = encode(std::string(argv[i]));
replaceAll(arg, "/", "_");
cmdPath += "&";
cmdPath += arg;
}
......@@ -112,4 +115,14 @@ void CTACopyCmd::replaceAll(std::string& str, const std::string& from, const std
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
//------------------------------------------------------------------------------
// encode
//------------------------------------------------------------------------------
std::string CTACopyCmd::encode(const std::string msg) const {
std::string ret;
const bool noNewLineInBase64Output = false;
CryptoPP::StringSource ss1(msg, true, new CryptoPP::Base64Encoder(new CryptoPP::StringSink(ret), noNewLineInBase64Output));
return ret;
}
\ No newline at end of file
......@@ -66,5 +66,13 @@ protected:
* @param to The replacement string
*/
void replaceAll(std::string& str, const std::string& from, const std::string& to) const;
/**
* Encodes a string in base 64
*
* @param msg string to encode
* @return encoded string
*/
std::string encode(const std::string msg) const;
}; // class CTACopyCmd
......@@ -27,6 +27,19 @@
#include "common/Utils.hpp"
#include "remotens/MockRemoteNS.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::MockRemoteNS::MockRemoteNS() {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::MockRemoteNS::MockRemoteNS(std::map<RemotePath, RemoteFileStatus> &entries): m_entries(entries){
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......
......@@ -35,6 +35,16 @@ public:
* Destructor.
*/
~MockRemoteNS() throw();
/**
* Constructor.
*/
MockRemoteNS();
/**
* Constructor.
*/
MockRemoteNS(std::map<RemotePath, RemoteFileStatus> &entries);
/**
* Returns the status of the specified file or directory within the remote
......
......@@ -7,4 +7,4 @@ include_directories(${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR})
include_directories(${CMAKE_BINARY_DIR})
add_library (XrdProFst MODULE XrdProFilesystem.cpp XrdProFile.cpp)
target_link_libraries (XrdProFst ctascheduler ctacommon ctanameserver ctaremotens ctaOStoreSchedulerDB protobuf CTAObjectStore)
target_link_libraries (XrdProFst ctascheduler ctacommon ctanameserver ctaremotens ctaOStoreSchedulerDB protobuf CTAObjectStore cryptopp)
......@@ -36,6 +36,8 @@
#include "XrdSec/XrdSecEntity.hh"
#include <cryptopp/base64.h>
#include <cryptopp/osrng.h>
#include <iostream>
#include <pwd.h>
#include <sstream>
......@@ -126,6 +128,15 @@ void XrdProFile::commandDispatcher(const std::vector<std::string> &tokens, const
else {m_data = getGenericHelp(tokens[0]);}
}
//------------------------------------------------------------------------------
// decode
//------------------------------------------------------------------------------
std::string XrdProFile::decode(const std::string msg) const {
std::string ret;
CryptoPP::StringSource ss1(msg, true, new CryptoPP::Base64Decoder(new CryptoPP::StringSink(ret)));
return ret;
}
//------------------------------------------------------------------------------
// open
//------------------------------------------------------------------------------
......@@ -137,11 +148,19 @@ int XrdProFile::open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t c
return checkResult;
}
if(!strlen(fileName)) { //this should never happen
m_data = getGenericHelp("");
return SFS_OK;
}
fileName++;//let's skip the first slash which is always prepended since we are asking for an absolute path
std::vector<std::string> tokens;
std::stringstream ss(fileName);
std::string item;
while (std::getline(ss, item, '&')) {
replaceAll(item, "_#_and_#_", "&");
replaceAll(item, "_", "/");
item = decode(item);
tokens.push_back(item);
}
......
......@@ -57,6 +57,14 @@ protected:
*/
std::string m_data;
/**
* Decodes a string in base 64
*
* @param msg string to decode
* @return decoded string
*/
std::string decode(const std::string msg) const;
/**
* Checks whether client has correct permissions and fills the SecurityIdentity structure
*
......
......@@ -97,14 +97,18 @@ public:
} g_OStoreDB(g_backend, g_backendPopulator.getAgent());
cta::MockRemoteNS g_remotens;
extern "C"
{
XrdSfsFileSystem *XrdSfsGetFileSystem (XrdSfsFileSystem* native_fs, XrdSysLogger* lp, const char* configfn)
{
g_remotens.createEntry(cta::RemotePath("mock://file1"), cta::RemoteFileStatus(cta::UserIdentity(getuid(), getgid()), 0777, 12345));
return new XrdProFilesystem(
new cta::CastorNameServer(),
& g_OStoreDB,
new cta::MockRemoteNS());
&g_OStoreDB,
&g_remotens);
}
}
......
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