-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdSecEntity.cc
238 lines (195 loc) · 8.23 KB
/
XrdSecEntity.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/******************************************************************************/
/* */
/* X r d S e c E n t i t y . h h */
/* */
/* (c) 2019 by the Board of Trustees of the Leland Stanford, Jr., University */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <map>
#include <string.h>
#include <vector>
#include "XrdSec/XrdSecAttr.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdSys/XrdSysPthread.hh"
/******************************************************************************/
/* L o c a l C l a s s e s */
/******************************************************************************/
class XrdSecEntityXtra
{
public:
XrdSysMutex xMutex;
std::vector<XrdSecAttr *> attrVec;
std::map<std::string, std::string> attrMap;
XrdSecEntityXtra() {}
~XrdSecEntityXtra() {}
};
/******************************************************************************/
/* A d d */
/******************************************************************************/
bool XrdSecEntity::Add(XrdSecAttr &attr)
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
std::vector<XrdSecAttr*>::iterator it;
// Check if this attribute already exists
//
for (it = entXtra->attrVec.begin(); it != entXtra->attrVec.end(); it++)
if ((*it)->Signature == attr.Signature) return false;
// Add the attribute object to our list of objects
//
entXtra->attrVec.push_back(&attr);
return true;
}
/******************************************************************************/
bool XrdSecEntity::Add(const std::string &key,
const std::string &val, bool replace)
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
std::map<std::string, std::string>::iterator it;
bool found = false;
// Check if this attribute already exists
//
it = entXtra->attrMap.find(key);
if (it != entXtra->attrMap.end())
{if (!replace) return false;
found = true;
}
// Add or replace the value
//
if (found) it->second = val;
else entXtra->attrMap.insert(std::make_pair(key, val));
return true;
}
/******************************************************************************/
/* G e t */
/******************************************************************************/
XrdSecAttr *XrdSecEntity::Get(const void *sigkey)
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
std::vector<XrdSecAttr*>::iterator it;
// Return pointer to the attribute if it exists
//
for (it = entXtra->attrVec.begin(); it != entXtra->attrVec.end(); it++)
if ((*it)->Signature == sigkey) return *it;
// Attribute not found
//
return (XrdSecAttr *)0;
}
/******************************************************************************/
bool XrdSecEntity::Get(const std::string &key, std::string &val)
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
std::map<std::string, std::string>::iterator it;
// Return pointer to the attribute if it exists
//
it = entXtra->attrMap.find(key);
if (it != entXtra->attrMap.end())
{val = it->second;
return true;
}
// The key does not exists
//
return false;
}
/******************************************************************************/
/* K e y s */
/******************************************************************************/
std::vector<std::string> XrdSecEntity::Keys()
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
std::map<std::string, std::string>::iterator itM;
std::vector<std::string> keyVec;
for (itM = entXtra->attrMap.begin();
itM != entXtra->attrMap.end(); itM++) keyVec.push_back(itM->first);
return keyVec;
}
/******************************************************************************/
/* L i s t */
/******************************************************************************/
void XrdSecEntity::List(XrdSecEntityAttrCB &attrCB)
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
std::map<std::string, std::string>::iterator itM;
std::vector<const char *> attrDel;
std::vector<const char *>::iterator itV;
XrdSecEntityAttrCB::Action rc;
for (itM = entXtra->attrMap.begin();
itM != entXtra->attrMap.end(); itM++)
{rc = attrCB.Attr(itM->first.c_str(), itM->second.c_str());
if (rc == XrdSecEntityAttrCB::Stop) break;
else if (rc == XrdSecEntityAttrCB::Delete)
attrDel.push_back(itM->first.c_str());
}
if (rc != XrdSecEntityAttrCB::Stop) attrCB.Attr(0, 0);
for (itV = attrDel.begin(); itV != attrDel.end(); itV++)
entXtra->attrMap.erase(std::string(*itV));
}
/******************************************************************************/
/* R e s e t */
/******************************************************************************/
void XrdSecEntity::Reset(bool isnew, const char *spV, const char *dpV)
{
memset( pros, 0, sizeof(pros) );
if (dpV) strncpy(pros, dpV, sizeof(prot)-1);
memset( prot, 0, sizeof(prot) );
if (spV) strncpy(prot, spV, sizeof(prot)-1);
name = 0;
host = 0;
vorg = 0;
role = 0;
grps = 0;
endorsements = 0;
moninfo = 0;
creds = 0;
credslen = 0;
rsvd = 0;
addrInfo = 0;
tident = 0;
sessvar = 0;
uid = 0;
gid = 0;
memset(future, 0, sizeof(future));
if (isnew) entXtra = new XrdSecEntityXtra;
else ResetXtra();
}
/******************************************************************************/
/* R e s e t X t r a */
/******************************************************************************/
void XrdSecEntity::ResetXtra(bool dodel)
{
XrdSysMutexHelper mHelp(entXtra->xMutex);
// Cleanup the key-value map
//
entXtra->attrMap.clear();
// Run through attribute objects, deleting each one
//
std::vector<XrdSecAttr*>::iterator it;
for (it = entXtra->attrVec.begin(); it != entXtra->attrVec.end(); it++)
{(*it)->Delete();}
// Now clear the whole vector
//
entXtra->attrVec.clear();
// Delete the extension if so wanted
//
if (dodel) {delete entXtra; entXtra = 0;}
}