XRootD
Loading...
Searching...
No Matches
XrdAccCapability.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d A c c C a p a b i l i t y . c c */
4/* */
5/* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
32
33/******************************************************************************/
34/* E x t e r n a l R e f e r e n c e s */
35/******************************************************************************/
36
37extern unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen);
38
39/******************************************************************************/
40/* C o n s t r u c t o r */
41/******************************************************************************/
42
44{
45 int i;
46
47// Do common initialization
48//
49 next = 0; ctmp = 0;
50 priv.pprivs = privval.pprivs; priv.nprivs = privval.nprivs;
51 plen = strlen(pathval); pins = 0; prem = 0;
52 pkey = XrdOucHashVal2((const char *)pathval, plen);
53 path = strdup(pathval);
54
55// Now set up for @= insertions. We do this eventhough it might never be used
56//
57 for (i = 0; i < plen; i++)
58 if (path[i] == '@' && path[i+1] == '=')
59 {pins = i; prem = plen - i - 2; break;}
60}
61
62/******************************************************************************/
63/* D e s t r u c t o r */
64/******************************************************************************/
65
66// This is a tricky destructor because deleting any item in the list must
67// delete all subsequent items in the list (but only once).
68//
70{
71 XrdAccCapability *cp, *np = next;
72
73 if (path) {free(path); path = 0;}
74
75 while(np) {cp = np; np = np->next; cp->next = 0; delete cp;}
76 next = 0;
77}
78/******************************************************************************/
79/* P r i v s */
80/******************************************************************************/
81
83 const char *pathname,
84 const int pathlen,
85 const unsigned long pathhash,
86 const char *pathsub)
87{XrdAccCapability *cp=this;
88 const int psl = (pathsub ? strlen(pathsub) : 0);
89
90 do {if (cp->ctmp)
91 {if (cp->ctmp->Privs(pathpriv,pathname,pathlen,pathhash,pathsub))
92 return 1;
93 }
94 else if (pathlen >= cp->plen)
95 if ((!pathsub && !strncmp(pathname, cp->path, cp->plen))
96 || (pathsub && cp->Subcomp(pathname,pathlen,pathsub,psl)))
97 {pathpriv.pprivs = (XrdAccPrivs)(pathpriv.pprivs |
98 cp->priv.pprivs);
99 pathpriv.nprivs = (XrdAccPrivs)(pathpriv.nprivs |
100 cp->priv.nprivs);
101 return 1;
102 }
103 } while ((cp = cp->next));
104 return 0;
105}
106
107/******************************************************************************/
108/* S u b c o m p */
109/******************************************************************************/
110
111int XrdAccCapability::Subcomp(const char *pathname, const int pathlen,
112 const char *pathsub, const int sublen)
113{ int ncmp;
114
115// First check if the prefix matches
116//
117 if (strncmp(pathname, path, pins)) return 0;
118
119// Now, check if the substitution appears in the source path
120//
121 if (strncmp(&pathname[pins], pathsub, sublen)) return 0;
122
123// Now check if we can match the tail
124//
125 ncmp = pins + sublen;
126 if ((pathlen - ncmp) < prem) return 0;
127
128// Return the results of matching the tail (prem should never be 0, but hey)
129//
130 if (prem) return !strncmp(&path[pins+2], &pathname[ncmp], prem);
131 return 1;
132}
133
134/******************************************************************************/
135/* X r d A c c C a p N a m e */
136/******************************************************************************/
137/******************************************************************************/
138/* D e s t r u c t o r */
139/******************************************************************************/
140
142{
143 XrdAccCapName *cp, *np = next;
144
145// Free regular storage
146//
147 next = 0;
148 if (CapName) free(CapName);
149 if (C_List) delete C_List;
150
151// Delete list in a non-recursive way
152//
153 while(np) {cp = np; np = np->next; cp->next = 0; delete cp;}
154}
155
156/******************************************************************************/
157/* F i n d */
158/******************************************************************************/
159
161{
162 int nlen = strlen(name);
163 XrdAccCapName *ncp = this;
164
165 do {if (ncp->CNlen <= nlen && !strcmp(ncp->CapName,name+(nlen - ncp->CNlen)))
166 return ncp->C_List;
167 ncp = ncp->next;
168 } while(ncp);
169 return (XrdAccCapability *)0;
170}
unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen)
unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen)
XrdAccPrivs
XrdAccCapability * Find(const char *name)
XrdAccCapName(char *name, XrdAccCapability *cap)
int Subcomp(const char *pathname, const int pathlen, const char *pathsub, const int sublen)
XrdAccCapability(char *pathval, XrdAccPrivCaps &privval)
int Privs(XrdAccPrivCaps &pathpriv, const char *pathname, const int pathlen, const unsigned long pathhash, const char *pathsub=0)
XrdAccPrivs nprivs
XrdAccPrivs pprivs