xrootd
|
00001 #ifndef __ACC_CAPABILITY__ 00002 #define __ACC_CAPABILITY__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d A c c C a p a b i l i t y . h h */ 00006 /* */ 00007 /* (c) 2003 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-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include <stdlib.h> 00016 #include <string.h> 00017 #include <strings.h> 00018 00019 #include "XrdAcc/XrdAccPrivs.hh" 00020 00021 /******************************************************************************/ 00022 /* X r d A c c C a p a b i l i t y */ 00023 /******************************************************************************/ 00024 00025 class XrdAccCapability 00026 { 00027 public: 00028 void Add(XrdAccCapability *newcap) {next = newcap;} 00029 00030 XrdAccCapability *Next() {return next;} 00031 00032 // Privs() searches the associated capability for a prefix matching path. If one 00033 // is found, the privileges are or'd into the passed XrdAccPrivCaps struct and 00034 // a 1 is returned. Otherwise, 0 is returned and XrdAccPrivCaps is unchanged. 00035 // 00036 int Privs( XrdAccPrivCaps &pathpriv, 00037 const char *pathname, 00038 const int pathlen, 00039 const unsigned long pathhash, 00040 const char *pathsub=0); 00041 00042 int Privs( XrdAccPrivCaps &pathpriv, 00043 const char *pathname, 00044 const int pathlen, 00045 const char *pathsub=0) 00046 {extern unsigned long XrdOucHashVal2(const char *,int); 00047 return Privs(pathpriv, pathname, pathlen, 00048 XrdOucHashVal2(pathname,(int)pathlen),pathsub);} 00049 00050 int Privs( XrdAccPrivCaps &pathpriv, 00051 const char *pathname, 00052 const char *pathsub=0) 00053 {extern unsigned long XrdOucHashVal2(const char *,int); 00054 int pathlen = strlen(pathname); 00055 return Privs(pathpriv, pathname, pathlen, 00056 XrdOucHashVal2(pathname, pathlen), pathsub);} 00057 00058 int Subcomp(const char *pathname, const int pathlen, 00059 const char *pathsub, const int sublen); 00060 00061 XrdAccCapability(char *pathval, XrdAccPrivCaps &privval); 00062 00063 XrdAccCapability(XrdAccCapability *taddr) 00064 {next = 0; ctmp = taddr; 00065 pkey = 0; path = 0; plen = 0; pins = 0; prem = 0; 00066 } 00067 00068 ~XrdAccCapability(); 00069 private: 00070 XrdAccCapability *next; // -> Next capability 00071 XrdAccCapability *ctmp; // -> Capability template 00072 00073 /*----------- The below fields are valid when template is zero -----------*/ 00074 00075 XrdAccPrivCaps priv; 00076 unsigned long pkey; 00077 char *path; 00078 int plen; 00079 int pins; // index of @= 00080 int prem; // remaining length after @= 00081 }; 00082 00083 /******************************************************************************/ 00084 /* X r d A c c C a p N a m e */ 00085 /******************************************************************************/ 00086 00087 class XrdAccCapName 00088 { 00089 public: 00090 void Add(XrdAccCapName *cnp) {next = cnp;} 00091 00092 XrdAccCapability *Find(const char *name); 00093 00094 XrdAccCapName(char *name, XrdAccCapability *cap) 00095 {next = 0; CapName = strdup(name); CNlen = strlen(name); 00096 C_List = cap; 00097 } 00098 ~XrdAccCapName(); 00099 private: 00100 XrdAccCapName *next; 00101 char *CapName; 00102 int CNlen; 00103 XrdAccCapability *C_List; 00104 }; 00105 #endif