15 #include <openssl/x509.h>
16 #include <openssl/pem.h>
18 #define UPDATE_STATISTIC(x) m_##x = x;
20 #define UPDATE_AND_OUTPUT_STATISTIC(x) \
21 os << "\"" #x "\":" << (x - m_##x) << ", "; \
27 #define HOST_NAME_MAX 128
30 #define JOB_UNIQUE_ID_ENV "CRAB_UNIQUE_JOB_ID"
31 #define JOB_UNIQUE_ID_ENV_V2 "DashboardJobId"
36 : m_read_single_operations(0),
37 m_read_single_bytes(0),
38 m_read_single_square(0),
39 m_read_vector_operations(0),
40 m_read_vector_bytes(0),
41 m_read_vector_square(0),
42 m_read_vector_count_sum(0),
43 m_read_vector_count_square(0),
44 m_start_time(
time(nullptr)) {}
48 ssize_t read_single_operations = 0;
49 ssize_t read_single_bytes = 0;
50 ssize_t read_single_square = 0;
51 ssize_t read_vector_operations = 0;
52 ssize_t read_vector_bytes = 0;
53 ssize_t read_vector_square = 0;
54 ssize_t read_vector_count_sum = 0;
55 ssize_t read_vector_count_square = 0;
57 for (StorageAccount::StorageStats::const_iterator
i =
stats.begin();
i !=
stats.end(); ++
i) {
58 if (
i->first ==
token.value()) {
61 for (StorageAccount::OperationStats::const_iterator
j =
i->second.begin();
j !=
i->second.end(); ++
j) {
63 read_vector_operations +=
j->second.attempts;
64 read_vector_bytes +=
j->second.amount;
65 read_vector_count_square +=
j->second.vector_square;
66 read_vector_square +=
j->second.amount_square;
67 read_vector_count_sum +=
j->second.vector_count;
69 read_single_operations +=
j->second.attempts;
70 read_single_bytes +=
j->second.amount;
71 read_single_square +=
j->second.amount_square;
75 int64_t single_op_count = read_single_operations - m_read_single_operations;
76 if (single_op_count > 0) {
77 double single_sum = read_single_bytes - m_read_single_bytes;
78 double single_average = single_sum / static_cast<double>(single_op_count);
79 os <<
"\"read_single_sigma\":"
80 <<
sqrt((static_cast<double>(read_single_square - m_read_single_square) -
81 single_average * single_average * single_op_count) /
82 static_cast<double>(single_op_count))
84 os <<
"\"read_single_average\":" << single_average <<
", ";
86 m_read_single_square = read_single_square;
87 int64_t vector_op_count = read_vector_operations - m_read_vector_operations;
88 if (vector_op_count > 0) {
89 double vector_average =
90 static_cast<double>(read_vector_bytes - m_read_vector_bytes) / static_cast<double>(vector_op_count);
91 os <<
"\"read_vector_average\":" << vector_average <<
", ";
92 os <<
"\"read_vector_sigma\":"
93 <<
sqrt((static_cast<double>(read_vector_square - m_read_vector_square) -
94 vector_average * vector_average * vector_op_count) /
95 static_cast<double>(vector_op_count))
97 double vector_count_average =
98 static_cast<double>(read_vector_count_sum - m_read_vector_count_sum) / static_cast<double>(vector_op_count);
99 os <<
"\"read_vector_count_average\":" << vector_count_average <<
", ";
100 os <<
"\"read_vector_count_sigma\":"
101 <<
sqrt((static_cast<double>(read_vector_count_square - m_read_vector_count_square) -
102 vector_count_average * vector_count_average * vector_op_count) /
103 static_cast<double>(vector_op_count))
106 m_read_vector_square = read_vector_square;
107 m_read_vector_count_square = read_vector_count_square;
108 m_read_vector_count_sum = read_vector_count_sum;
110 os <<
"\"read_bytes\":" << (read_vector_bytes + read_single_bytes - m_read_vector_bytes - m_read_single_bytes)
112 os <<
"\"read_bytes_at_close\":"
113 << (read_vector_bytes + read_single_bytes - m_read_vector_bytes - m_read_single_bytes) <<
", ";
121 os <<
"\"start_time\":" << m_start_time <<
", ";
122 m_start_time =
time(
nullptr);
124 os <<
"\"end_time\":" << m_start_time;
152 size_t dot_pos = servername.find(
'.');
155 if (dot_pos == std::string::npos) {
156 serverhost = servername.substr(0, servername.find(
':'));
157 serverdomain =
"unknown";
159 serverhost = servername.substr(0, dot_pos);
160 serverdomain = servername.substr(dot_pos + 1, servername.find(
':') - dot_pos - 1);
161 if (serverdomain.empty()) {
162 serverdomain =
"unknown";
189 ((
info->find(
"dn") ==
info->end()) || (
info->find(
"nodn") !=
info->end()))) {
196 for (
const struct addrinfo *address = addresses; address !=
nullptr; address = address->ai_next) {
197 int sock = socket(address->ai_family, address->ai_socktype, address->ai_protocol);
201 auto close_del = [](
int *iSocket) { close(*iSocket); };
203 if (sendto(sock,
results.c_str(),
results.size(), 0, address->ai_addr, address->ai_addrlen) >= 0) {
220 if (dot_pos == std::string::npos) {
229 std::ostringstream os;
233 if (!siteName.empty()) {
234 os <<
"\"site_name\":\"" << siteName <<
"\", ";
237 os <<
"\"fallback\": true, ";
247 os <<
"\"user_dn\":\"" <<
m_userdn <<
"\", ";
250 os <<
"\"server_host\":\"" << serverhost <<
"\", ";
251 os <<
"\"server_domain\":\"" << serverdomain <<
"\", ";
253 os <<
"\"file_lfn\":\"" <<
m_filelfn <<
"\", ";
258 os <<
"\"app_info\":\"" << jobId <<
"\", ";
262 os <<
"\"file_size\":" <<
m_size <<
", ";
288 int depth = sk_X509_num(certstack);
293 char *priorsubject =
nullptr;
294 char *subject =
nullptr;
295 X509 *x509cert = sk_X509_value(certstack,
idx);
296 for (; x509cert &&
idx > 0;
idx--) {
297 subject = X509_NAME_oneline(X509_get_subject_name(x509cert),
nullptr, 0);
298 if (subject && priorsubject && (strncmp(subject, priorsubject, strlen(subject)) != 0)) {
301 x509cert = sk_X509_value(certstack,
idx);
303 OPENSSL_free(subject);
308 OPENSSL_free(subject);
316 STACK_OF(
X509) *certs =
nullptr;
317 char *subject =
nullptr;
318 unsigned char *
data =
nullptr;
320 char *
name =
nullptr;
323 if ((biof = BIO_new_file(
filename.c_str(),
"r"))) {
324 certs = sk_X509_new_null();
325 bool encountered_error =
false;
326 while ((!encountered_error) && (!BIO_eof(biof)) && PEM_read_bio(biof, &
name, &
header, &
data, &len)) {
327 if (strcmp(
name, PEM_STRING_X509) == 0 || strcmp(
name, PEM_STRING_X509_OLD) == 0) {
328 X509 *tmp_cert =
nullptr;
331 const unsigned char *
p;
333 tmp_cert = d2i_X509(&tmp_cert, &
p, len);
335 sk_X509_push(certs, tmp_cert);
337 encountered_error =
true;
353 X509 *x509cert =
nullptr;
354 if (!encountered_error && sk_X509_num(certs)) {
358 subject = X509_NAME_oneline(X509_get_subject_name(x509cert),
nullptr, 0);
362 sk_X509_pop_free(certs, X509_free);
368 OPENSSL_free(subject);
376 char *
filename = std::getenv(
"X509_USER_PROXY");
380 std::stringstream
ss;
381 ss <<
"/tmp/x509up_u" << geteuid();