Commit c2247666 authored by Elvin Sindrilaru's avatar Elvin Sindrilaru
Browse files

Remove redundant functionality from rtcpd when building the XRootD path - drop the rtcpToXroot

function and build the XRootD path inside the rtcpd_xroot_stat function. This will also append
the opaque information used for the authorization check at the XRootD diskserver.
parent 27fbb74b
......@@ -41,8 +41,8 @@
#include <Cns.h>
int rtcp_CheckReqStructures (int *,
rtcpClientInfo_t *,
tape_list_t *);
rtcpClientInfo_t *,
tape_list_t *);
#define SET_REQUEST_ERR(X,Z) {\
(X)->err.severity = (Z); \
......@@ -57,34 +57,6 @@ static int max_cpretry = MAX_CPRETRY;
extern char *getconfent(char *, char *, int);
extern int rtcp_CallVMGR (tape_list_t *, char *);
/**
* Convert the server:/path string to xroot root://server:port//path
* @param rtcpPath the path to be converted.
* @param xrootFilePath the variable to return xroot path.
* @return 0 if convertion succeed and -1 in error case.
*/
static int rtcpToXroot(const char *const rtcpPath,
char *const xrootFilePath) {
const char *const xrootPort="1095";
const char *pathWithoutServer;
*xrootFilePath='\0';
if ( CA_MAXPATHLEN < (strlen("root://")+strlen(xrootPort)+strlen(rtcpPath)+1) ) {
return (-1);
}
if ( NULL == (pathWithoutServer=strchr(rtcpPath,'/'))) {
return (-1);
}
/* protocol */
strcat(xrootFilePath,"root://");
/* server name */
strncat(xrootFilePath,rtcpPath, pathWithoutServer-rtcpPath);
/* port */
strcat(xrootFilePath,xrootPort);
/* path itself */
strcat(xrootFilePath,"/");
strcat(xrootFilePath,pathWithoutServer);
return 0;
}
static int rtcp_CheckTapeReq(tape_list_t *tape) {
file_list_t *file = NULL;
......@@ -476,17 +448,9 @@ static int rtcp_CheckFileReq(file_list_t *file) {
rtcp_log(LOG_DEBUG,"rtcp_CheckFileReq(%d,%s) (tpwrite) stat64() remote file\n",
filereq->tape_fseq,filereq->file_path);
/* we have to convert the path to xroot */
/* we have to convert the path to xroot and add opaque info */
struct stat xrootStat;
char xrootFilePath[CA_MAXPATHLEN+1];
if ( -1 == rtcpToXroot(filereq->file_path,xrootFilePath) ) {
serrno = EFAULT; /* sets "Bad address" errno */
rc = -1;
} else {
rc = rtcp_xroot_stat(xrootFilePath,&xrootStat);
st.st_mode=xrootStat.st_mode;
st.st_size=xrootStat.st_size;
}
rc = rtcp_xroot_stat(filereq->file_path,&xrootStat);
if ( rc == -1 ) {
serrno = errno;
......@@ -494,6 +458,10 @@ static int rtcp_CheckFileReq(file_list_t *file) {
SET_REQUEST_ERR(filereq,RTCP_USERR | RTCP_FAILED);
if ( rc == -1 ) return(rc);
}
else {
st.st_mode=xrootStat.st_mode;
st.st_size=xrootStat.st_size;
}
/*
* Is it a directory?
*/
......@@ -508,7 +476,7 @@ static int rtcp_CheckFileReq(file_list_t *file) {
/*
* Zero size?
*/
/* Commentimg out the following log statement because it logs */
/* Commentimg out the following log statement because it logs */
/* st_size modulus 4GB. The log statement is therefore more */
/* confusing than useful. If anybody wishes to fix the following */
/* log line then they MUST test their fix by migrating a file */
......@@ -570,18 +538,16 @@ static int rtcp_CheckFileReq(file_list_t *file) {
filereq->tape_fseq,filereq->file_path);
{
serrno = 0;
/* we have to convert the path to xroot and add opaque info */
struct stat xrootStat;
char xrootFilePath[CA_MAXPATHLEN+1];
if ( -1 == rtcpToXroot(filereq->file_path,
xrootFilePath) ) {
errno = EFAULT; /* sets "Bad address" errno */
rc = -1;
} else {
rc = rtcp_xroot_stat(xrootFilePath,&xrootStat);
st.st_mode=xrootStat.st_mode;
rc = rtcp_xroot_stat(filereq->file_path,&xrootStat);
if ( rc != -1 ) {
st.st_mode=xrootStat.st_mode;
st.st_size=xrootStat.st_size;
rtcp_log(LOG_DEBUG,"rtcp_CheckFileReq(%d,%s) st_mode=0%o\n",
filereq->tape_fseq,filereq->file_path,st.st_mode);
}
if ( rc != -1 ) rtcp_log(LOG_DEBUG,"rtcp_CheckFileReq(%d,%s) st_mode=0%o\n",
filereq->tape_fseq,filereq->file_path,st.st_mode);
if ( rc != -1 && (((st.st_mode) & S_IFMT) == S_IFDIR) ) {
serrno = EISDIR;
sprintf(errmsgtxt,RT110,CMD(mode),sstrerror(serrno));
......@@ -601,15 +567,7 @@ static int rtcp_CheckFileReq(file_list_t *file) {
}
struct stat xrootStat;
char xrootFilePath[CA_MAXPATHLEN+1];
if ( -1 == rtcpToXroot(filereq->file_path,
xrootFilePath) ) {
errno = EFAULT; /* sets "Bad address" errno */
rc = -1;
} else {
rc = rtcp_xroot_stat(xrootFilePath,&xrootStat);
st.st_mode=xrootStat.st_mode;
}
rc = rtcp_xroot_stat(filereq->file_path,&xrootStat);
if ( rc == -1 ) {
serrno = errno;
......@@ -618,6 +576,9 @@ static int rtcp_CheckFileReq(file_list_t *file) {
SET_REQUEST_ERR(filereq,RTCP_USERR | RTCP_FAILED);
if ( rc == -1 ) return(rc);
}
else {
st.st_mode=xrootStat.st_mode;
}
/*
* Couldn't find S_ISDIR() macro under NT.
*/
......
......@@ -8,7 +8,7 @@
/*
** An xroot wrapper for file commands used by rtcpd.
** We need it to be able to use any compilation flags specific only for xroot
*/
*/
extern "C" {
#include <rtcp_xroot.h>
......@@ -90,7 +90,7 @@ static int signXrootUrl(const std::string& input, std::string& signature) {
// cleanup context
EVP_MD_CTX_cleanup(&md_ctx);
// base64 encode
// base64 encode
BIO *b64 = BIO_new(BIO_f_base64());
BIO *bmem = BIO_new(BIO_s_mem());
if (NULL == b64 || NULL == bmem) {
......@@ -114,7 +114,7 @@ static int signXrootUrl(const std::string& input, std::string& signature) {
/**
* Convert the server:/path string to the CASTOR xroot
* root://server:port//dummy?castor2fs.pfn1=path
* root://server:port//path?castor2fs... all the opaque tags
* @param rtcpPath the path to be converted.
* @param xrootFilePath the variable to return xroot path.
* @return 0 if convertion succeed and -1 in error case.
......@@ -128,21 +128,22 @@ static std::string rtcpToCastorXroot(const char *const rtcpPath) {
}
// start of URL
std::ostringstream ss;
ss << "root://" << path.substr(0, slashPos) << "1095//dummy?";
ss << "root://" << path.substr(0, slashPos) << "1095/"
<< path.substr(slashPos) << "?";
// "opaque" info
time_t exptime = time(NULL) + 3600;
std::ostringstream opaque;
opaque << "castor2fs.sfn=&"
<< "castor2fs.pfn1=" << path.substr(slashPos) << "&"
<< "castor2fs.pfn2=&"
<< "castor2fs.id=&"
<< "castor2fs.id=&"
<< "castor2fs.client_sec_uid=&"
<< "castor2fs.client_sec_gid=&"
<< "castor2fs.accessop=0&"
<< "castor2fs.exptime=" << exptime << "&"
<< "castor2fs.manager=&"
<< "castor2fs.signature=";
ss << opaque.str();
// signature
std::string signature;
......@@ -152,15 +153,21 @@ static std::string rtcpToCastorXroot(const char *const rtcpPath) {
if (signXrootUrl(sdata.str(), signature)) {
throw castor::exception::Exception();
}
ss << signature;
return ss.str();
}
extern "C" {
int rtcp_xroot_stat(const char *path, struct stat *buf) {
return XrdPosix_Stat(path,buf);
try {
std::string xrootdURL = rtcpToCastorXroot(path);
return XrdPosix_Stat(xrootdURL.c_str(), buf);
} catch (castor::exception::Exception e) {
errno = EFAULT; /* sets "Bad address" errno */
return -1;
}
}
int rtcp_xroot_open(const char *path, int oflag, int mode) {
......@@ -181,7 +188,7 @@ int rtcp_xroot_close(int fildes) {
return XrdPosix_Close(fildes);
}
long long rtcp_xroot_write(int fildes, const void *buf,
long long rtcp_xroot_write(int fildes, const void *buf,
unsigned long long nbyte) {
return XrdPosix_Write(fildes, buf, nbyte);
}
......
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