xrootd
Loading...
Searching...
No Matches
XrdVomsMapfile.hh
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d V o m s M a p f i l e . h h */
4/* */
5/* This file is part of the XRootD software suite. */
6/* */
7/* XRootD is free software: you can redistribute it and/or modify it under */
8/* the terms of the GNU Lesser General Public License as published by the */
9/* Free Software Foundation, either version 3 of the License, or (at your */
10/* option) any later version. */
11/* */
12/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
13/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
14/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
15/* License for more details. */
16/* */
17/* You should have received a copy of the GNU Lesser General Public License */
18/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
19/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
20/* */
21/* The copyright holder's institutional names and contributor's names may not */
22/* be used to endorse or promote products derived from this software without */
23/* specific prior written permission of the institution or contributor. */
24/******************************************************************************/
25
27#include "XrdSys/XrdSysError.hh"
29
30#include <atomic>
31#include <memory>
32#include <string>
33#include <vector>
34
35#define VOMS_MAP_FAILED ((XrdVomsMapfile *)-1)
36
38
39public:
40 virtual ~XrdVomsMapfile();
41
42 // Returns `nullptr` if the mapfile was not configured; returns
43 // VOMS_MAP_FAILED (`(void*)-1`) if the mapfile was configured but it
44 // was unable to be parsed (or other error occurred).
47
49
50 bool IsValid() const {return m_is_valid;}
51
52private:
54 void SetErrorStream(XrdSysError *erp) {if (erp) {m_edest = erp;}}
55
56 XrdVomsMapfile(XrdSysError *erp, const std::string &mapfile);
57
58 enum LogMask {
59 Debug = 0x01,
60 Info = 0x02,
61 Warning = 0x04,
62 Error = 0x08,
63 All = 0xff
64 };
65
66 struct MapfileEntry {
67 std::vector<std::string> m_path;
68 std::string m_target;
69 };
70
71 bool ParseMapfile(const std::string &mapfile);
72 bool ParseLine(const std::string &line, std::vector<std::string> &entry, std::string &target);
73
74 std::string Map(const std::vector<std::string> &fqan);
75 bool Compare(const MapfileEntry &entry, const std::vector<std::string> &fqan);
76 std::vector<std::string> MakePath(const XrdOucString &group);
77
78 // A continuously-running thread for maintenance tasks (reloading the mapfile)
79 static void *MaintenanceThread(void *myself_raw);
80
81 // Set to true if the last maintenance attempt succeeded.
82 bool m_is_valid = false;
83 // Time of the last observed status change of file.
84 struct timespec m_mapfile_ctime{0, 0};
85
86 std::string m_mapfile;
87 std::shared_ptr<const std::vector<MapfileEntry>> m_entries;
89
90 // After success, how long to wait until the next mapfile check.
91 static constexpr unsigned m_update_interval = 30;
92
93 // Singleton
94 static std::unique_ptr<XrdVomsMapfile> mapper;
95 // There are multiple protocol objects that may need the mapfile object;
96 // if we already tried-and-failed configuration once, this singleton will
97 // help us avoid failing again.
98 static bool tried_configure;
99};
Definition XrdOucString.hh:254
Definition XrdSecEntity.hh:65
Definition XrdSysError.hh:90
Definition XrdVomsMapfile.hh:37
static XrdVomsMapfile * Get()
std::string m_mapfile
Definition XrdVomsMapfile.hh:86
bool Reconfigure()
std::shared_ptr< const std::vector< MapfileEntry > > m_entries
Definition XrdVomsMapfile.hh:87
XrdSysError * m_edest
Definition XrdVomsMapfile.hh:88
static bool tried_configure
Definition XrdVomsMapfile.hh:98
void SetErrorStream(XrdSysError *erp)
Definition XrdVomsMapfile.hh:54
static void * MaintenanceThread(void *myself_raw)
static constexpr unsigned m_update_interval
Definition XrdVomsMapfile.hh:91
bool ParseMapfile(const std::string &mapfile)
virtual ~XrdVomsMapfile()
std::vector< std::string > MakePath(const XrdOucString &group)
static XrdVomsMapfile * Configure(XrdSysError *)
bool IsValid() const
Definition XrdVomsMapfile.hh:50
static std::unique_ptr< XrdVomsMapfile > mapper
Definition XrdVomsMapfile.hh:94
bool Compare(const MapfileEntry &entry, const std::vector< std::string > &fqan)
bool m_is_valid
Definition XrdVomsMapfile.hh:82
std::string Map(const std::vector< std::string > &fqan)
bool ParseLine(const std::string &line, std::vector< std::string > &entry, std::string &target)
XrdVomsMapfile(XrdSysError *erp, const std::string &mapfile)
LogMask
Definition XrdVomsMapfile.hh:58
@ Error
Definition XrdVomsMapfile.hh:62
@ All
Definition XrdVomsMapfile.hh:63
@ Warning
Definition XrdVomsMapfile.hh:61
@ Info
Definition XrdVomsMapfile.hh:60
@ Debug
Definition XrdVomsMapfile.hh:59
int Apply(XrdSecEntity &)
Definition XrdVomsMapfile.hh:66
std::string m_target
Definition XrdVomsMapfile.hh:68
std::vector< std::string > m_path
Definition XrdVomsMapfile.hh:67
Definition XrdVomsMapfile.hh:84