xrootd
|
00001 #ifndef __SecsssKT__ 00002 #define __SecsssKT__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S e c s s s K T . h h */ 00006 /* */ 00007 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include <string.h> 00016 #include <time.h> 00017 #include "XrdSys/XrdSysPthread.hh" 00018 00019 class XrdOucErrInfo; 00020 class XrdOucStream; 00021 00022 class XrdSecsssKT 00023 { 00024 public: 00025 00026 class ktEnt 00027 { 00028 public: 00029 00030 static const int maxKLen = 128; 00031 static const int NameSZ = 192; 00032 static const int UserSZ = 128; 00033 static const int GrupSZ = 64; 00034 00035 struct ktData 00036 {long long ID; 00037 time_t Crt; 00038 time_t Exp; 00039 int Opts; 00040 int Len; 00041 char Val[maxKLen];// Key strings are 1024 bits or less 00042 char Name[NameSZ];// Key names are null terminated 00043 char User[UserSZ];// Usr names are null terminated 00044 char Grup[GrupSZ];// Grp names are null terminated 00045 } Data; 00046 00047 static const int anyUSR = 2; 00048 static const int anyGRP = 4; 00049 static const int usrGRP = 8; 00050 00051 void NUG(ktEnt *ktP) {strcpy(Data.Name, ktP->Data.Name); 00052 strcpy(Data.User, ktP->Data.User); 00053 strcpy(Data.Grup, ktP->Data.Grup); 00054 } 00055 void Set(ktEnt &rhs) {Data.ID=rhs.Data.ID; Data.Len = rhs.Data.Len; 00056 memcpy(Data.Val, rhs.Data.Val, Data.Len); 00057 Data.Crt=rhs.Data.Crt; Data.Exp=rhs.Data.Exp; 00058 } 00059 ktEnt *Next; 00060 00061 ktEnt() : Next(0) { Data.ID = -1; Data.Opts = 0; 00062 *Data.Val = '\0'; *Data.Name = '\0'; 00063 *Data.User= '\0'; *Data.Grup = '\0'; 00064 } 00065 ~ktEnt() {} 00066 }; 00067 00068 void addKey(ktEnt &ktNew); 00069 00070 int delKey(ktEnt &ktDel); 00071 00072 static 00073 char *genFN(); 00074 00075 static 00076 void genKey(char *Buff, int blen); 00077 00078 int getKey(ktEnt &ktEql); 00079 00080 ktEnt *keyList() {return ktList;} 00081 00082 void Refresh(); 00083 00084 time_t RefrTime() {return ktRefT;} 00085 00086 int Rewrite(int Keep, int &numKeys, int &numTot, int &numExp); 00087 00088 int Same(const char *path) {return (ktPath && !strcmp(ktPath, path));} 00089 00090 void setPath(const char *Path) 00091 {if (ktPath) free(ktPath); ktPath = strdup(Path);} 00092 00093 enum xMode {isAdmin = 0, isClient, isServer}; 00094 00095 XrdSecsssKT(XrdOucErrInfo *, const char *, xMode, int refr=60*60); 00096 ~XrdSecsssKT(); 00097 00098 private: 00099 int eMsg(const char *epn, int rc, const char *txt1, 00100 const char *txt2=0, const char *txt3=0, const char *txt4=0); 00101 ktEnt *getKeyTab(XrdOucErrInfo *eInfo, time_t Mtime, mode_t Amode); 00102 mode_t fileMode(const char *Path); 00103 int isKey(ktEnt &ktRef, ktEnt *ktP, int Full=1); 00104 void keyB2X(ktEnt *theKT, char *buff); 00105 void keyX2B(ktEnt *theKT, char *xKey); 00106 ktEnt *ktDecode0(XrdOucStream &kTab, XrdOucErrInfo *eInfo); 00107 00108 XrdSysMutex myMutex; 00109 char *ktPath; 00110 ktEnt *ktList; 00111 time_t ktMtime; 00112 xMode ktMode; 00113 time_t ktRefT; 00114 int kthiID; 00115 static int randFD; 00116 }; 00117 #endif