ATLAS Offline Software
Loading...
Searching...
No Matches
VomsProxySvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10// Please feel free to contact me (krumnack@iastate.edu) for bug
11// reports, feature suggestions, praise and complaints.
12
13
14//
15// includes
16//
17
19
24#include <errno.h>
25#include <unistd.h>
26#include <sys/types.h>
27#include <sys/stat.h>
28#include <fcntl.h>
29#include <unistd.h>
30#include <sys/types.h>
31#include <fstream>
32#include <TSystem.h>
33
34//
35// method implementations
36//
37
39
40namespace EL
41{
42 const std::string& VomsProxySvc ::
43 algServiceName ()
44 {
45 static std::string result = "VomsProxySvc";
46 return result;
47 }
48
49
50
51 void VomsProxySvc ::
52 testInvariant () const
53 {
54 RCU_INVARIANT (this != nullptr);
55 }
56
57
58
59 StatusCode VomsProxySvc ::
60 setupJob (Job& /*job*/)
61 {
64
65 const char *X509_USER_PROXY = getenv ("X509_USER_PROXY");
66 std::string file;
67 if (X509_USER_PROXY)
68 {
69 file = X509_USER_PROXY;
70 } else
71 {
72 std::ostringstream str;
73 str << "/tmp/x509up_u" << getuid();
74 file = str.str();
75 }
76 if (file.empty() || gSystem->AccessPathName (file.c_str()) != false)
77 RCU_THROW_MSG ("failed to find X509 proxy file: " + file);
78
79 {
80 std::ifstream stream (file);
81 char ch;
82 while (stream.get (ch))
83 m_proxyData += ch;
84 if (!stream.eof())
85 RCU_THROW_MSG ("error reading: " + file);
86 }
87
88 return StatusCode::FAILURE;
89 }
90
91
92
93 const char *VomsProxySvc ::
94 GetName () const
95 {
96 RCU_READ_INVARIANT (this);
97 return name().c_str();
98 }
99
100
101
102 StatusCode VomsProxySvc ::
103 histInitialize ()
104 {
105 RCU_READ_INVARIANT (this);
106 if (!SH::checkVomsProxy())
107 {
108 int fd = open (m_fileName.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
109 if (fd == -1)
110 {
111 auto myerrno = errno;
112 ANA_MSG_ERROR ("failed to create file \"" << m_fileName << "\": " << strerror (myerrno));
113 return EL::StatusCode::FAILURE;
114 }
115 int written = write (fd, &m_proxyData[0], m_proxyData.size());
116 if (written == -1)
117 {
118 auto myerrno = errno;
119 ANA_MSG_ERROR ("failed to write to file \"" << m_fileName << "\": " << strerror (myerrno));
120 close (fd);
121 return EL::StatusCode::FAILURE;
122 }
123 if (written < int (m_proxyData.size()))
124 {
125 ANA_MSG_ERROR ("only wrote " << written << " of " << m_proxyData.size() << " bytes to file \"" << m_fileName << "\"");
126 close (fd);
127 return EL::StatusCode::FAILURE;
128 }
129 if (close (fd) == -1)
130 {
131 auto myerrno = errno;
132 ANA_MSG_ERROR ("failed to close file \"" << m_fileName << "\": " << strerror (myerrno));
133 return EL::StatusCode::FAILURE;
134 }
135 if (setenv ("X509_USER_PROXY", m_fileName.c_str(), true) == -1)
136 {
137 auto myerrno = errno;
138 ANA_MSG_ERROR ("failed to set X509_USER_PROXY: " << strerror (myerrno));
139 return EL::StatusCode::FAILURE;
140 }
141 }
142 return EL::StatusCode::SUCCESS;
143 }
144}
#define RCU_INVARIANT(x)
Definition Assert.h:201
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
macros for messaging and checking status codes
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
ClassImp(EL::VomsProxySvc) namespace EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
void ensureVomsProxy()
ensure that we have a valid VOMS proxy available
bool checkVomsProxy()
return whether we have a valid VOMS proxy available
TFile * file