XRootD
Loading...
Searching...
No Matches
XrdTlsTempCA::TempCAGuard Class Reference

#include <XrdTlsTempCA.hh>

+ Collaboration diagram for XrdTlsTempCA::TempCAGuard:

Public Member Functions

 TempCAGuard (const TempCAGuard &)=delete
 
 ~TempCAGuard ()
 
bool commit ()
 
int getCAFD () const
 
std::string getCAFilename () const
 
int getCRLFD () const
 
std::string getCRLFilename () const
 

Static Public Member Functions

static std::unique_ptr< TempCAGuardcreate (XrdSysError &, const std::string &ca_tmp_dir)
 

Detailed Description

Manages the temporary file associated with the curl handle

Definition at line 74 of file XrdTlsTempCA.hh.

Constructor & Destructor Documentation

◆ TempCAGuard()

XrdTlsTempCA::TempCAGuard::TempCAGuard ( const TempCAGuard & )
delete

References TempCAGuard().

Referenced by TempCAGuard(), and create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~TempCAGuard()

XrdTlsTempCA::TempCAGuard::~TempCAGuard ( )

Definition at line 295 of file XrdTlsTempCA.cc.

295 {
296 if (m_ca_fd >= 0) {
297 unlink(m_ca_fname.c_str());
298 close(m_ca_fd);
299 }
300 if (m_crl_fd >= 0) {
301 unlink(m_crl_fname.c_str());
302 close(m_crl_fd);
303 }
304}
#define close(a)
Definition XrdPosix.hh:48
#define unlink(a)
Definition XrdPosix.hh:113

References close, and unlink.

Member Function Documentation

◆ commit()

bool XrdTlsTempCA::TempCAGuard::commit ( )

Move temporary file to the permanent location.

Definition at line 308 of file XrdTlsTempCA.cc.

308 {
309 if (m_ca_fd < 0 || m_ca_tmp_dir.empty()) {return false;}
310 close(m_ca_fd);
311 m_ca_fd = -1;
312 std::string ca_fname = m_ca_tmp_dir + "/ca_file.pem";
313 if (-1 == rename(m_ca_fname.c_str(), ca_fname.c_str())) {
314 return false;
315 }
316 m_ca_fname = ca_fname;
317
318 if (m_crl_fd < 0 || m_ca_tmp_dir.empty()) {return false;}
319 close(m_crl_fd);
320 m_crl_fd = -1;
321 std::string crl_fname = m_ca_tmp_dir + "/crl_file.pem";
322 if (-1 == rename(m_crl_fname.c_str(), crl_fname.c_str())) {
323 return false;
324 }
325 m_crl_fname = crl_fname;
326
327 return true;
328}
#define rename(a, b)
Definition XrdPosix.hh:92

References close, and rename.

◆ create()

std::unique_ptr< XrdTlsTempCA::TempCAGuard > XrdTlsTempCA::TempCAGuard::create ( XrdSysError & err,
const std::string & ca_tmp_dir )
static

Definition at line 262 of file XrdTlsTempCA.cc.

262 {
263
264 if (-1 == mkdir(ca_tmp_dir.c_str(), S_IRWXU) && errno != EEXIST) {
265 err.Emsg("TempCA", "Unable to create CA temp directory", ca_tmp_dir.c_str(), strerror(errno));
266 }
267
268 std::stringstream ss;
269 ss << ca_tmp_dir << "/ca_file.XXXXXX.pem";
270 std::vector<char> ca_fname;
271 ca_fname.resize(ss.str().size() + 1);
272 memcpy(ca_fname.data(), ss.str().c_str(), ss.str().size());
273
274 int ca_fd = mkstemps(ca_fname.data(), 4);
275 if (ca_fd < 0) {
276 err.Emsg("TempCA", "Failed to create temp file:", strerror(errno));
277 return std::unique_ptr<TempCAGuard>();
278 }
279
280 std::stringstream ss2;
281 ss2 << ca_tmp_dir << "/crl_file.XXXXXX.pem";
282 std::vector<char> crl_fname;
283 crl_fname.resize(ss2.str().size() + 1);
284 memcpy(crl_fname.data(), ss2.str().c_str(), ss2.str().size());
285
286 int crl_fd = mkstemps(crl_fname.data(), 4);
287 if (crl_fd < 0) {
288 err.Emsg("TempCA", "Failed to create temp file:", strerror(errno));
289 return std::unique_ptr<TempCAGuard>();
290 }
291 return std::unique_ptr<TempCAGuard>(new TempCAGuard(ca_fd, crl_fd, ca_tmp_dir, ca_fname.data(), crl_fname.data()));
292}
#define mkdir(a, b)
Definition XrdPosix.hh:74
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
TempCAGuard(const TempCAGuard &)=delete

References TempCAGuard(), XrdSysError::Emsg(), and mkdir.

+ Here is the call graph for this function:

◆ getCAFD()

int XrdTlsTempCA::TempCAGuard::getCAFD ( ) const
inline

Definition at line 78 of file XrdTlsTempCA.hh.

78{return m_ca_fd;}

◆ getCAFilename()

std::string XrdTlsTempCA::TempCAGuard::getCAFilename ( ) const
inline

Definition at line 79 of file XrdTlsTempCA.hh.

79{return m_ca_fname;}

◆ getCRLFD()

int XrdTlsTempCA::TempCAGuard::getCRLFD ( ) const
inline

Definition at line 81 of file XrdTlsTempCA.hh.

81{return m_crl_fd;}

◆ getCRLFilename()

std::string XrdTlsTempCA::TempCAGuard::getCRLFilename ( ) const
inline

Definition at line 82 of file XrdTlsTempCA.hh.

82{return m_crl_fname;}

The documentation for this class was generated from the following files: