XRootD
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 
26 #include "XrdOuc/XrdOucString.hh"
27 #include "XrdSys/XrdSysError.hh"
28 #include "XrdSec/XrdSecEntity.hh"
29 
30 #include <atomic>
31 #include <memory>
32 #include <string>
33 #include <vector>
34 
35 #define VOMS_MAP_FAILED ((XrdVomsMapfile *)-1)
36 
38 
39 public:
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).
46  static XrdVomsMapfile *Get();
47 
48  int Apply(XrdSecEntity &);
49 
50  bool IsValid() const {return m_is_valid;}
51 
52 private:
53  bool Reconfigure();
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;
88  XrdSysError *m_edest{nullptr};
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 };
static XrdVomsMapfile * Get()
bool IsValid() const
static XrdVomsMapfile * Configure(XrdSysError *)
virtual ~XrdVomsMapfile()
int Apply(XrdSecEntity &)