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 <string.h>
34 #include <time.h>
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 
130 char *ktPath;
132 time_t ktMtime;
134 time_t ktRefT;
135 int kthiID;
136 pthread_t ktRefID;
137 static int randFD;
138 };
139 #endif
int delKey(ktEnt &ktDel)
void Set(ktEnt &rhs)
Definition: XrdSecsssKT.hh:76
Definition: XrdSecsssKT.hh:114
static const int usrGRP
Definition: XrdSecsssKT.hh:69
Definition: XrdSecsssKT.hh:53
static const int UserSZ
Definition: XrdSecsssKT.hh:50
void setPath(const char *Path)
Definition: XrdSecsssKT.hh:111
static const int NameSZ
Definition: XrdSecsssKT.hh:49
int Same(const char *path)
Definition: XrdSecsssKT.hh:109
void keyX2B(ktEnt *theKT, char *xKey)
time_t RefrTime()
Definition: XrdSecsssKT.hh:105
time_t Exp
Definition: XrdSecsssKT.hh:57
Definition: XrdOucStream.hh:46
char Name[NameSZ]
Definition: XrdSecsssKT.hh:61
time_t ktMtime
Definition: XrdSecsssKT.hh:132
static const int anyUSR
Definition: XrdSecsssKT.hh:67
XrdSysMutex myMutex
Definition: XrdSecsssKT.hh:129
void NUG(ktEnt *ktP)
Definition: XrdSecsssKT.hh:72
ktEnt()
Definition: XrdSecsssKT.hh:82
pthread_t ktRefID
Definition: XrdSecsssKT.hh:136
int Len
Definition: XrdSecsssKT.hh:59
static int randFD
Definition: XrdSecsssKT.hh:137
time_t ktRefT
Definition: XrdSecsssKT.hh:134
ktEnt * ktList
Definition: XrdSecsssKT.hh:131
Definition: XrdSysPthread.hh:165
ktEnt * ktDecode0(XrdOucStream &kTab, XrdOucErrInfo *eInfo)
struct XrdSecsssKT::ktEnt::ktData Data
static void genKey(char *Buff, int blen)
char User[UserSZ]
Definition: XrdSecsssKT.hh:62
Definition: XrdSecsssKT.hh:40
static const int noIPCK
Definition: XrdSecsssKT.hh:70
Definition: XrdSecsssKT.hh:114
void Refresh()
static const int anyGRP
Definition: XrdSecsssKT.hh:68
Definition: XrdOucErrInfo.hh:100
XrdSecsssKT(XrdOucErrInfo *, const char *, xMode, int refr=60 *60)
ktEnt * getKeyTab(XrdOucErrInfo *eInfo, time_t Mtime, mode_t Amode)
void keyB2X(ktEnt *theKT, char *buff)
ktEnt * keyList()
Definition: XrdSecsssKT.hh:101
Definition: XrdSecsssKT.hh:114
static char * genFN()
char Val[maxKLen]
Definition: XrdSecsssKT.hh:60
int eMsg(const char *epn, int rc, const char *txt1, const char *txt2=0, const char *txt3=0, const char *txt4=0)
Definition: XrdSecsssKT.hh:44
~ktEnt()
Definition: XrdSecsssKT.hh:86
char * ktPath
Definition: XrdSecsssKT.hh:130
xMode
Definition: XrdSecsssKT.hh:114
long long Flags
Definition: XrdSecsssKT.hh:55
int getKey(ktEnt &ktEql, bool andKeyID=false)
xMode ktMode
Definition: XrdSecsssKT.hh:133
static const int maxKLen
Definition: XrdSecsssKT.hh:48
ktEnt * Next
Definition: XrdSecsssKT.hh:80
mode_t fileMode(const char *Path)
int Opts
Definition: XrdSecsssKT.hh:58
long long ID
Definition: XrdSecsssKT.hh:54
char Grup[GrupSZ]
Definition: XrdSecsssKT.hh:63
void addKey(ktEnt &ktNew)
int Rewrite(int Keep, int &numKeys, int &numTot, int &numExp)
time_t Crt
Definition: XrdSecsssKT.hh:56
static const int GrupSZ
Definition: XrdSecsssKT.hh:51
static const int allUSR
Definition: XrdSecsssKT.hh:66
int isKey(ktEnt &ktRef, ktEnt *ktP, int Full=1)
int kthiID
Definition: XrdSecsssKT.hh:135