xrootd
XrdAccCapability.hh
Go to the documentation of this file.
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-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 <stdlib.h>
00034 #include <string.h>
00035 #include <strings.h>
00036 
00037 #include "XrdAcc/XrdAccPrivs.hh"
00038 
00039 /******************************************************************************/
00040 /*                      X r d A c c C a p a b i l i t y                       */
00041 /******************************************************************************/
00042   
00043 class XrdAccCapability
00044 {
00045 public:
00046 void                Add(XrdAccCapability *newcap) {next = newcap;}
00047 
00048 XrdAccCapability   *Next() {return next;}
00049 
00050 // Privs() searches the associated capability for a prefix matching path. If one
00051 // is found, the privileges are or'd into the passed XrdAccPrivCaps struct and
00052 // a 1 is returned. Otherwise, 0 is returned and XrdAccPrivCaps is unchanged.
00053 //
00054 int                 Privs(      XrdAccPrivCaps &pathpriv,
00055                           const char           *pathname,
00056                           const int             pathlen,
00057                           const unsigned long   pathhash,
00058                           const char           *pathsub=0);
00059 
00060 int                 Privs(      XrdAccPrivCaps &pathpriv,
00061                           const char           *pathname,
00062                           const int             pathlen,
00063                           const char           *pathsub=0)
00064                           {extern unsigned long XrdOucHashVal2(const char *,int);
00065                            return Privs(pathpriv, pathname, pathlen,
00066                                   XrdOucHashVal2(pathname,(int)pathlen),pathsub);}
00067 
00068 int                 Privs(      XrdAccPrivCaps &pathpriv,
00069                           const char           *pathname,
00070                           const char           *pathsub=0)
00071                           {extern unsigned long XrdOucHashVal2(const char *,int);
00072                            int pathlen = strlen(pathname);
00073                            return Privs(pathpriv, pathname, pathlen,
00074                                   XrdOucHashVal2(pathname, pathlen), pathsub);}
00075 
00076 int                 Subcomp(const char *pathname, const int pathlen,
00077                             const char *pathsub,  const int sublen);
00078 
00079                   XrdAccCapability(char *pathval, XrdAccPrivCaps &privval);
00080 
00081                   XrdAccCapability(XrdAccCapability *taddr)
00082                         {next = 0; ctmp = taddr;
00083                          pkey = 0; path = 0; plen = 0; pins = 0; prem = 0;
00084                         }
00085 
00086                  ~XrdAccCapability();
00087 private:
00088 XrdAccCapability *next;      // -> Next capability
00089 XrdAccCapability *ctmp;      // -> Capability template
00090 
00091 /*----------- The below fields are valid when template is zero -----------*/
00092 
00093 XrdAccPrivCaps   priv;
00094 unsigned long    pkey;
00095 char            *path;
00096 int              plen;
00097 int              pins;    // index of @=
00098 int              prem;    // remaining length after @=
00099 };
00100 
00101 /******************************************************************************/
00102 /*                         X r d A c c C a p N a m e                          */
00103 /******************************************************************************/
00104 
00105 class XrdAccCapName
00106 {
00107 public:
00108 void              Add(XrdAccCapName *cnp) {next = cnp;}
00109 
00110 XrdAccCapability *Find(const char *name);
00111 
00112        XrdAccCapName(char *name, XrdAccCapability *cap)
00113                     {next = 0; CapName = strdup(name); CNlen = strlen(name);
00114                      C_List = cap;
00115                     }
00116       ~XrdAccCapName();
00117 private:
00118 XrdAccCapName    *next;
00119 char             *CapName;
00120 int               CNlen;
00121 XrdAccCapability *C_List;
00122 };
00123 #endif