XrdAccCapability.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                   X r d A c c C a p a b i l i t y . c c                    */
00004 /*                                                                            */
00005 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //         $Id: XrdAccCapability.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 const char *XrdAccCapabilityCVSID = "$Id: XrdAccCapability.cc 24468 2008-06-22 16:47:03Z ganis $";
00014 
00015 #include "XrdAcc/XrdAccCapability.hh"
00016 
00017 /******************************************************************************/
00018 /*                   E x t e r n a l   R e f e r e n c e s                    */
00019 /******************************************************************************/
00020   
00021 extern unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen);
00022 
00023 /******************************************************************************/
00024 /*                           C o n s t r u c t o r                            */
00025 /******************************************************************************/
00026   
00027 XrdAccCapability::XrdAccCapability(char *pathval, XrdAccPrivCaps &privval)
00028 {
00029    int i;
00030 
00031 // Do common initialization
00032 //
00033    next = 0; ctmp = 0;
00034    priv.pprivs = privval.pprivs; priv.nprivs = privval.nprivs;
00035    plen = strlen(pathval); pins = 0; prem = 0;
00036    pkey = XrdOucHashVal2((const char *)pathval, plen);
00037    path = strdup(pathval);
00038 
00039 // Now set up for @= insertions. We do this eventhough it might never be used
00040 //
00041    for (i = 0; i < plen; i++)
00042        if (path[i] == '@' && path[i+1] == '=')
00043           {pins = i; prem = plen - i - 2; break;}
00044 }
00045 
00046 /******************************************************************************/
00047 /*                            D e s t r u c t o r                             */
00048 /******************************************************************************/
00049   
00050 // This is a tricky destructor because deleting any item in the list must
00051 // delete all subsequent items in the list (but only once).
00052 //
00053 XrdAccCapability::~XrdAccCapability()
00054 {
00055      XrdAccCapability *cp, *np = next;
00056 
00057      if (path) {free(path); path = 0;}
00058 
00059      while(np) {cp = np; np = np->next; cp->next = 0; delete cp;}
00060      next = 0;
00061 }
00062 /******************************************************************************/
00063 /*                                 P r i v s                                  */
00064 /******************************************************************************/
00065   
00066 int XrdAccCapability::Privs(      XrdAccPrivCaps &pathpriv,
00067                             const char           *pathname,
00068                             const int             pathlen,
00069                             const unsigned long   pathhash,
00070                             const char           *pathsub)
00071 {XrdAccCapability *cp=this;
00072  const int psl = (pathsub ? strlen(pathsub) : 0);
00073 
00074  do {if (cp->ctmp)
00075        {if (cp->ctmp->Privs(pathpriv,pathname,pathlen,pathhash,pathsub))
00076            return 1;
00077        }
00078         else if (pathlen >= cp->plen)
00079                 if ((!pathsub && !strncmp(pathname, cp->path, cp->plen))
00080                 ||  (pathsub &&  cp->Subcomp(pathname,pathlen,pathsub,psl)))
00081                    {pathpriv.pprivs = (XrdAccPrivs)(pathpriv.pprivs |
00082                                                     cp->priv.pprivs);
00083                     pathpriv.nprivs = (XrdAccPrivs)(pathpriv.nprivs |
00084                                                     cp->priv.nprivs);
00085                     return 1;
00086                    }
00087     } while ((cp = cp->next));
00088  return 0;
00089 }
00090 
00091 /******************************************************************************/
00092 /*                               S u b c o m p                                */
00093 /******************************************************************************/
00094   
00095 int XrdAccCapability::Subcomp(const char *pathname, const int pathlen,
00096                               const char *pathsub,  const int sublen)
00097 {  int ncmp;
00098 
00099 // First check if the prefix matches
00100 //
00101    if (strncmp(pathname, path, pins)) return 0;
00102 
00103 // Now, check if the substitution appears in the source path
00104 //
00105    if (strncmp(&pathname[pins], pathsub, sublen)) return 0;
00106 
00107 // Now check if we can match the tail
00108 //
00109    ncmp = pins + sublen;
00110    if ((pathlen - ncmp) < prem) return 0;
00111 
00112 // Return the results of matching the tail (prem should never be 0, but hey)
00113 //
00114    if (prem) return !strncmp(&path[pins+2], &pathname[ncmp], prem);
00115    return 1;
00116 }
00117 
00118 /******************************************************************************/
00119 /*                         X r d A c c C a p N a m e                          */
00120 /******************************************************************************/
00121 /******************************************************************************/
00122 /*                            D e s t r u c t o r                             */
00123 /******************************************************************************/
00124 
00125 XrdAccCapName::~XrdAccCapName()
00126 {
00127    XrdAccCapName *cp, *np = next;
00128 
00129 // Free regular storage
00130 //
00131    next = 0;
00132    if (CapName) free(CapName);
00133    if (C_List)  delete C_List;
00134 
00135 // Delete list in a non-recursive way
00136 //
00137    while(np) {cp = np; np = np->next; cp->next = 0; delete cp;}
00138 }
00139   
00140 /******************************************************************************/
00141 /*                                  F i n d                                   */
00142 /******************************************************************************/
00143   
00144 XrdAccCapability *XrdAccCapName::Find(const char *name)
00145 {
00146    int nlen = strlen(name);
00147    XrdAccCapName *ncp = this;
00148 
00149    do {if (ncp->CNlen <= nlen && !strcmp(ncp->CapName,name+(nlen - ncp->CNlen)))
00150           return ncp->C_List;
00151        ncp = ncp->next;
00152       } while(ncp);
00153    return (XrdAccCapability *)0;
00154 }

Generated on Tue Jul 5 14:46:15 2011 for ROOT_528-00b_version by  doxygen 1.5.1