xrootd
XrdSecsssKT.hh
Go to the documentation of this file.
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 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032   
00033 #include <string.h>
00034 #include <time.h>
00035 #include "XrdSys/XrdSysPthread.hh"
00036 
00037 class XrdOucErrInfo;
00038 class XrdOucStream;
00039 
00040 class XrdSecsssKT
00041 {
00042 public:
00043 
00044 class ktEnt
00045 {
00046 public:
00047 
00048 static const int maxKLen = 128;
00049 static const int NameSZ  = 192;
00050 static const int UserSZ  = 128;
00051 static const int GrupSZ  = 64;
00052 
00053 struct ktData
00054        {long long ID;
00055         time_t    Crt;
00056         time_t    Exp;
00057         int       Opts;
00058         int       Len;
00059         char      Val[maxKLen];// Key strings are 1024 bits or less
00060         char      Name[NameSZ];// Key names are null terminated
00061         char      User[UserSZ];// Usr names are null terminated
00062         char      Grup[GrupSZ];// Grp names are null terminated
00063        }          Data;
00064 
00065 static const int anyUSR = 2;
00066 static const int anyGRP = 4;
00067 static const int usrGRP = 8;
00068 
00069        void      NUG(ktEnt *ktP) {strcpy(Data.Name, ktP->Data.Name);
00070                                   strcpy(Data.User, ktP->Data.User);
00071                                   strcpy(Data.Grup, ktP->Data.Grup);
00072                                  }
00073        void      Set(ktEnt &rhs) {Data.ID=rhs.Data.ID; Data.Len = rhs.Data.Len;
00074                                   memcpy(Data.Val, rhs.Data.Val, Data.Len);
00075                                   Data.Crt=rhs.Data.Crt; Data.Exp=rhs.Data.Exp;
00076                                  }
00077        ktEnt    *Next;
00078 
00079        ktEnt() : Next(0) { Data.ID   = -1;   Data.Opts = 0;
00080                           *Data.Val = '\0'; *Data.Name = '\0';
00081                           *Data.User= '\0'; *Data.Grup = '\0';
00082                          }
00083       ~ktEnt() {}
00084 };
00085 
00086 void   addKey(ktEnt &ktNew);
00087 
00088 int    delKey(ktEnt &ktDel);
00089 
00090 static
00091 char  *genFN();
00092 
00093 static
00094 void   genKey(char *Buff, int blen);
00095 
00096 int    getKey(ktEnt &ktEql);
00097 
00098 ktEnt *keyList() {return ktList;}
00099 
00100 void   Refresh();
00101 
00102 time_t RefrTime() {return ktRefT;}
00103 
00104 int    Rewrite(int Keep, int &numKeys, int &numTot, int &numExp);
00105 
00106 int    Same(const char *path) {return (ktPath && !strcmp(ktPath, path));}
00107 
00108 void   setPath(const char *Path) 
00109               {if (ktPath) free(ktPath); ktPath = strdup(Path);}
00110 
00111 enum   xMode {isAdmin = 0, isClient, isServer};
00112 
00113        XrdSecsssKT(XrdOucErrInfo *, const char *, xMode, int refr=60*60);
00114       ~XrdSecsssKT();
00115 
00116 private:
00117 int    eMsg(const char *epn, int rc, const char *txt1,
00118             const char *txt2=0, const char *txt3=0, const char *txt4=0);
00119 ktEnt *getKeyTab(XrdOucErrInfo *eInfo, time_t Mtime, mode_t Amode);
00120 mode_t fileMode(const char *Path);
00121 int    isKey(ktEnt &ktRef, ktEnt *ktP, int Full=1);
00122 void   keyB2X(ktEnt *theKT, char *buff);
00123 void   keyX2B(ktEnt *theKT, char *xKey);
00124 ktEnt *ktDecode0(XrdOucStream &kTab, XrdOucErrInfo *eInfo);
00125 
00126 XrdSysMutex myMutex;
00127 char       *ktPath;
00128 ktEnt      *ktList;
00129 time_t      ktMtime;
00130 xMode       ktMode;
00131 time_t      ktRefT;
00132 int         kthiID;
00133 pthread_t   ktRefID;
00134 static int  randFD;
00135 };
00136 #endif