XRootD
XrdSecsssKT.hh
Go to the documentation of this file.
1 #ifndef __SecsssKT__
2 #define __SecsssKT__
3 /******************************************************************************/
4 /* */
5 /* X r d S e c s s s K T . h h */
6 /* */
7 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <cstring>
34 #include <ctime>
35 #include "XrdSys/XrdSysPthread.hh"
36 
37 class XrdOucErrInfo;
38 class XrdOucStream;
39 
41 {
42 public:
43 
44 class ktEnt
45 {
46 public:
47 
48 static const int maxKLen = 128;
49 static const int NameSZ = 192;
50 static const int UserSZ = 128;
51 static const int GrupSZ = 64;
52 
53 struct ktData
54  {long long ID;
55  long long Flags; // Future!
56  time_t Crt;
57  time_t Exp;
58  int Opts;
59  int Len;
60  char Val[maxKLen];// Key strings are 1024 bits or less
61  char Name[NameSZ];// Key names are null terminated
62  char User[UserSZ];// Usr names are null terminated
63  char Grup[GrupSZ];// Grp names are null terminated
64  } Data;
65 
66 static const int allUSR = 1;
67 static const int anyUSR = 2;
68 static const int anyGRP = 4;
69 static const int usrGRP = 8;
70 static const int noIPCK =16;
71 
72  void NUG(ktEnt *ktP) {strcpy(Data.Name, ktP->Data.Name);
73  strcpy(Data.User, ktP->Data.User);
74  strcpy(Data.Grup, ktP->Data.Grup);
75  }
76  void Set(ktEnt &rhs) {Data.ID=rhs.Data.ID; Data.Len = rhs.Data.Len;
77  memcpy(Data.Val, rhs.Data.Val, Data.Len);
78  Data.Crt=rhs.Data.Crt; Data.Exp=rhs.Data.Exp;
79  }
81 
82  ktEnt() : Next(0) { Data.ID = -1; Data.Flags= 0; Data.Opts = 0;
83  *Data.Val = '\0'; *Data.Name = '\0';
84  *Data.User= '\0'; *Data.Grup = '\0';
85  }
86  ~ktEnt() {}
87 };
88 
89 void addKey(ktEnt &ktNew);
90 
91 int delKey(ktEnt &ktDel);
92 
93 static
94 char *genFN();
95 
96 static
97 void genKey(char *Buff, int blen);
98 
99 int getKey(ktEnt &ktEql, bool andKeyID=false);
100 
101 ktEnt *keyList() {return ktList;}
102 
103 void Refresh();
104 
105 time_t RefrTime() {return ktRefT;}
106 
107 int Rewrite(int Keep, int &numKeys, int &numTot, int &numExp);
108 
109 int Same(const char *path) {return (ktPath && !strcmp(ktPath, path));}
110 
111 void setPath(const char *Path)
112  {if (ktPath) free(ktPath); ktPath = strdup(Path);}
113 
115 
116  XrdSecsssKT(XrdOucErrInfo *, const char *, xMode, int refr=60*60);
117  ~XrdSecsssKT();
118 
119 private:
120 int eMsg(const char *epn, int rc, const char *txt1,
121  const char *txt2=0, const char *txt3=0, const char *txt4=0);
122 ktEnt *getKeyTab(XrdOucErrInfo *eInfo, time_t Mtime, mode_t Amode);
123 mode_t fileMode(const char *Path);
124 int isKey(ktEnt &ktRef, ktEnt *ktP, int Full=1);
125 void keyB2X(ktEnt *theKT, char *buff);
126 void keyX2B(ktEnt *theKT, char *xKey);
127 ktEnt *ktDecode0(XrdOucStream &kTab, XrdOucErrInfo *eInfo);
128 
129 XrdSysMutex myMutex;
130 char *ktPath;
131 ktEnt *ktList;
132 time_t ktMtime;
133 xMode ktMode;
134 time_t ktRefT;
135 int kthiID;
136 pthread_t ktRefID;
137 static int randFD;
138 };
139 #endif
XrdOucString Path
static const int anyUSR
Definition: XrdSecsssKT.hh:67
static const int UserSZ
Definition: XrdSecsssKT.hh:50
struct XrdSecsssKT::ktEnt::ktData Data
static const int noIPCK
Definition: XrdSecsssKT.hh:70
void NUG(ktEnt *ktP)
Definition: XrdSecsssKT.hh:72
static const int anyGRP
Definition: XrdSecsssKT.hh:68
static const int GrupSZ
Definition: XrdSecsssKT.hh:51
void Set(ktEnt &rhs)
Definition: XrdSecsssKT.hh:76
static const int maxKLen
Definition: XrdSecsssKT.hh:48
static const int allUSR
Definition: XrdSecsssKT.hh:66
static const int usrGRP
Definition: XrdSecsssKT.hh:69
static const int NameSZ
Definition: XrdSecsssKT.hh:49
int Same(const char *path)
Definition: XrdSecsssKT.hh:109
void setPath(const char *Path)
Definition: XrdSecsssKT.hh:111
int delKey(ktEnt &ktDel)
Definition: XrdSecsssKT.cc:185
int Rewrite(int Keep, int &numKeys, int &numTot, int &numExp)
Definition: XrdSecsssKT.cc:339
static char * genFN()
Definition: XrdSecsssKT.cc:249
void Refresh()
Definition: XrdSecsssKT.cc:311
int getKey(ktEnt &ktEql, bool andKeyID=false)
Definition: XrdSecsssKT.cc:207
ktEnt * keyList()
Definition: XrdSecsssKT.hh:101
time_t RefrTime()
Definition: XrdSecsssKT.hh:105
static void genKey(char *Buff, int blen)
Definition: XrdSecsssKT.cc:268
void addKey(ktEnt &ktNew)
Definition: XrdSecsssKT.cc:158
XrdSecsssKT(XrdOucErrInfo *, const char *, xMode, int refr=60 *60)
Definition: XrdSecsssKT.cc:78