XRootD
XrdAccCapability.hh
Go to the documentation of this file.
1 #ifndef __ACC_CAPABILITY__
2 #define __ACC_CAPABILITY__
3 /******************************************************************************/
4 /* */
5 /* X r d A c c C a p a b i l i t y . h h */
6 /* */
7 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <cstdlib>
34 #include <cstring>
35 #include <strings.h>
36 
37 #include "XrdAcc/XrdAccPrivs.hh"
38 
39 /******************************************************************************/
40 /* X r d A c c C a p a b i l i t y */
41 /******************************************************************************/
42 
44 {
45 public:
46 void Add(XrdAccCapability *newcap) {next = newcap;}
47 
48 XrdAccCapability *Next() {return next;}
49 
50 // Privs() searches the associated capability for a prefix matching path. If one
51 // is found, the privileges are or'd into the passed XrdAccPrivCaps struct and
52 // a 1 is returned. Otherwise, 0 is returned and XrdAccPrivCaps is unchanged.
53 //
54 int Privs( XrdAccPrivCaps &pathpriv,
55  const char *pathname,
56  const int pathlen,
57  const unsigned long pathhash,
58  const char *pathsub=0);
59 
60 int Privs( XrdAccPrivCaps &pathpriv,
61  const char *pathname,
62  const int pathlen,
63  const char *pathsub=0)
64  {extern unsigned long XrdOucHashVal2(const char *,int);
65  return Privs(pathpriv, pathname, pathlen,
66  XrdOucHashVal2(pathname,(int)pathlen),pathsub);}
67 
68 int Privs( XrdAccPrivCaps &pathpriv,
69  const char *pathname,
70  const char *pathsub=0)
71  {extern unsigned long XrdOucHashVal2(const char *,int);
72  int pathlen = strlen(pathname);
73  return Privs(pathpriv, pathname, pathlen,
74  XrdOucHashVal2(pathname, pathlen), pathsub);}
75 
76 int Subcomp(const char *pathname, const int pathlen,
77  const char *pathsub, const int sublen);
78 
79  XrdAccCapability(char *pathval, XrdAccPrivCaps &privval);
80 
82  {next = 0; ctmp = taddr;
83  pkey = 0; path = 0; plen = 0; pins = 0; prem = 0;
84  }
85 
87 private:
88 XrdAccCapability *next; // -> Next capability
89 XrdAccCapability *ctmp; // -> Capability template
90 
91 /*----------- The below fields are valid when template is zero -----------*/
92 
93 XrdAccPrivCaps priv;
94 unsigned long pkey;
95 char *path;
96 int plen;
97 int pins; // index of @=
98 int prem; // remaining length after @=
99 };
100 
101 /******************************************************************************/
102 /* X r d A c c C a p N a m e */
103 /******************************************************************************/
104 
106 {
107 public:
108 void Add(XrdAccCapName *cnp) {next = cnp;}
109 
110 XrdAccCapability *Find(const char *name);
111 
112  XrdAccCapName(char *name, XrdAccCapability *cap)
113  {next = 0; CapName = strdup(name); CNlen = strlen(name);
114  C_List = cap;
115  }
116  ~XrdAccCapName();
117 private:
118 XrdAccCapName *next;
119 char *CapName;
120 int CNlen;
121 XrdAccCapability *C_List;
122 };
123 #endif
unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen)
void Add(XrdAccCapName *cnp)
XrdAccCapability * Find(const char *name)
XrdAccCapName(char *name, XrdAccCapability *cap)
XrdAccCapability * Next()
int Subcomp(const char *pathname, const int pathlen, const char *pathsub, const int sublen)
XrdAccCapability(char *pathval, XrdAccPrivCaps &privval)
void Add(XrdAccCapability *newcap)
XrdAccCapability(XrdAccCapability *taddr)
int Privs(XrdAccPrivCaps &pathpriv, const char *pathname, const char *pathsub=0)
int Privs(XrdAccPrivCaps &pathpriv, const char *pathname, const int pathlen, const char *pathsub=0)
int Privs(XrdAccPrivCaps &pathpriv, const char *pathname, const int pathlen, const unsigned long pathhash, const char *pathsub=0)