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< TempCAGuard > create (XrdSysError &, const std::string &ca_tmp_dir)

Detailed Description

Manages the temporary file associated with the curl handle

Definition at line 110 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 294 of file XrdTlsTempCA.cc.

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

References close, and unlink.

Member Function Documentation

◆ commit()

bool XrdTlsTempCA::TempCAGuard::commit ( )

Move temporary file to the permanent location.

Definition at line 307 of file XrdTlsTempCA.cc.

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

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 261 of file XrdTlsTempCA.cc.

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

114{return m_ca_fd;}

◆ getCAFilename()

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

Definition at line 115 of file XrdTlsTempCA.hh.

115{return m_ca_fname;}

◆ getCRLFD()

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

Definition at line 117 of file XrdTlsTempCA.hh.

117{return m_crl_fd;}

◆ getCRLFilename()

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

Definition at line 118 of file XrdTlsTempCA.hh.

118{return m_crl_fname;}

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