XRootD
XrdAccGroups Class Reference

#include <XrdAccGroups.hh>

+ Collaboration diagram for XrdAccGroups:

Public Member Functions

 XrdAccGroups ()
 
 ~XrdAccGroups ()
 
char * AddName (const XrdAccGroupType gtype, const char *name)
 
const char * Domain ()
 
char * FindName (const XrdAccGroupType gtype, const char *name)
 
XrdAccGroupListGroups (const char *user)
 
XrdAccGroupListNetGroups (const char *user, const char *host)
 
void PurgeCache ()
 
int Retran (const gid_t gid)
 
void SetDomain (const char *dname)
 
void SetLifetime (const int seconds)
 
void SetOptions (XrdAccGroups_Options opts)
 

Detailed Description

Definition at line 96 of file XrdAccGroups.hh.

Constructor & Destructor Documentation

◆ XrdAccGroups()

XrdAccGroups::XrdAccGroups ( )

Definition at line 83 of file XrdAccGroups.cc.

84 {
85 
86 // Do standard initialization
87 //
88  retrancnt = 0;
89  HaveGroups = 0;
90  HaveNetGroups = 0;
91  options = No_Group_Opt;
92  domain = 0;
93  LifeTime = 60*60*12;
94 }
@ No_Group_Opt
Definition: XrdAccGroups.hh:83

References No_Group_Opt.

◆ ~XrdAccGroups()

XrdAccGroups::~XrdAccGroups ( )
inline

Definition at line 149 of file XrdAccGroups.hh.

149 {} // The group object never gets deleted!!

Member Function Documentation

◆ AddName()

char * XrdAccGroups::AddName ( const XrdAccGroupType  gtype,
const char *  name 
)

Definition at line 100 of file XrdAccGroups.cc.

101 {
102  char *np;
103  XrdOucHash<char> *hp;
104 
105 // Prepare to add a group name
106 //
107  if (gtype == XrdAccNetGroup) {hp = &NetGroup_Names; HaveNetGroups = 1;}
108  else {hp = &Group_Names; HaveGroups = 1;}
109 
110 // Lock the Name hash table
111 //
112  Group_Name_Context.Lock();
113 
114 // Add a name into the name hash table. We need to only keep a single
115 // read/only copy of the group name to speed multi-threading.
116 //
117  if (!(np = hp->Find(name)))
118  {hp->Add(name, 0, 0, Hash_data_is_key);
119  if (!(np = hp->Find(name)))
120  std::cerr <<"XrdAccGroups: Unable to add group " <<name <<std::endl;
121  }
122 
123 // All done.
124 //
125  Group_Name_Context.UnLock();
126  return np;
127 }
@ XrdAccNetGroup
Definition: XrdAccGroups.hh:90
@ Hash_data_is_key
Definition: XrdOucHash.hh:52
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
Definition: XrdOucHash.icc:61
T * Find(const char *KeyVal, time_t *KeyTime=0)
Definition: XrdOucHash.icc:160

References XrdOucHash< T >::Add(), XrdOucHash< T >::Find(), Hash_data_is_key, XrdSysMutex::Lock(), XrdSysMutex::UnLock(), and XrdAccNetGroup.

+ Here is the call graph for this function:

◆ Domain()

const char* XrdAccGroups::Domain ( )
inline

Definition at line 102 of file XrdAccGroups.hh.

102 {return domain;}

Referenced by XrdAccCheckNetGroup().

+ Here is the caller graph for this function:

◆ FindName()

char * XrdAccGroups::FindName ( const XrdAccGroupType  gtype,
const char *  name 
)

Definition at line 133 of file XrdAccGroups.cc.

134 {
135  char *np;
136 
137 // Lock the Name hash table
138 //
139  Group_Name_Context.Lock();
140 
141 // Lookup the actual name in the hash table
142 //
143  if (gtype == XrdAccNetGroup) np = NetGroup_Names.Find(name);
144  else np = Group_Names.Find(name);
145 
146 // All done.
147 //
148  Group_Name_Context.UnLock();
149  return np;
150 }

References XrdOucHash< T >::Find(), XrdSysMutex::Lock(), XrdSysMutex::UnLock(), and XrdAccNetGroup.

+ Here is the call graph for this function:

◆ Groups()

XrdAccGroupList * XrdAccGroups::Groups ( const char *  user)

Definition at line 158 of file XrdAccGroups.cc.

159 {
160 struct group *gr;
161 struct passwd *pw;
162 char **cp;
163 XrdAccGroupList *glist;
164 int gtabi;
165 char *Gtab[NGROUPS_MAX];
166 
167 // Check if we have any referenced groups
168 //
169  if (!HaveGroups) return (XrdAccGroupList *)0;
170 
171 
172 // Check if we already have this user in the group cache. Since we may be
173 // modifying the cache, we need to have exclusive control over it. We must
174 // copy the group cache because the original may be deleted at any time.
175 //
176  Group_Cache_Context.Lock();
177  if ((glist = Group_Cache.Find(user)))
178  {if (glist->First()) glist = new XrdAccGroupList(*glist);
179  else glist = 0;
180  Group_Cache_Context.UnLock();
181  return glist;
182  }
183  Group_Cache_Context.UnLock();
184 
185 // If the user has no password file entry, then we have no groups for user.
186 // All code that tries to construct a group list is protected by the
187 // Group_Build_Context mutex, obtained after we get the pwd entry.
188 //
189  XrdSysPwd thePwd(user, &pw);
190  if (pw == NULL) return (XrdAccGroupList *)0;
191 
192 // Build first entry for the primary group. We will ignore the primary group
193 // listing later. We do this to ensure that the user has at least one group
194 // regardless of what the groups file actually says.
195 //
196  Group_Build_Context.Lock();
197  gtabi = addGroup(user, pw->pw_gid, 0, Gtab, 0);
198 
199 // Now run through all of the group entries getting the list of user's groups
200 // Do this only when Primary_Only is not turned on (i.e., SVR5 semantics)
201 //
202  if (!(options & Primary_Only))
203  {
204  setgrent() ;
205  while ((gr = getgrent()))
206  {
207  if (pw->pw_gid == gr->gr_gid) continue; /*Already have this one.*/
208  for (cp = gr->gr_mem; cp && *cp; cp++)
209  if (strcmp(*cp, user) == 0)
210  gtabi = addGroup(user, gr->gr_gid,
211  Dotran(gr->gr_gid,gr->gr_name),
212  Gtab, gtabi);
213  }
214  endgrent();
215  }
216 
217 // All done with non mt-safe routines
218 //
219  Group_Build_Context.UnLock();
220 
221 // Allocate a new GroupList object
222 //
223  glist = new XrdAccGroupList(gtabi, (const char **)Gtab);
224 
225 // Add this user to the group cache to speed things up the next time
226 //
227  Group_Cache_Context.Lock();
228  Group_Cache.Add(user, glist, LifeTime);
229  Group_Cache_Context.UnLock();
230 
231 // Return a copy of the group list since the original may be deleted
232 //
233  if (!gtabi) return (XrdAccGroupList *)0;
234  return new XrdAccGroupList(gtabi, (const char **)Gtab);
235 }
@ Primary_Only
Definition: XrdAccGroups.hh:81
const char * First()
Definition: XrdAccGroups.hh:47

References XrdOucHash< T >::Add(), XrdOucHash< T >::Find(), XrdAccGroupList::First(), XrdSysMutex::Lock(), Primary_Only, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ NetGroups()

XrdAccGroupList * XrdAccGroups::NetGroups ( const char *  user,
const char *  host 
)

Definition at line 241 of file XrdAccGroups.cc.

242 {
243 XrdAccGroupList *glist;
244 int i, j;
245 char uh_key[MAXHOSTNAMELEN+96];
246 struct XrdAccGroupArgs GroupTab;
247 int XrdAccCheckNetGroup(const char *netgroup, char *key, void *Arg);
248 
249 // Check if we have any Netgroups
250 //
251  if (!HaveNetGroups) return (XrdAccGroupList *)0;
252 
253 // Construct the key for this user
254 //
255  i = strlen(user); j = strlen(host);
256  if (i+j+2 > (int)sizeof(uh_key)) return (XrdAccGroupList *)0;
257  strcpy(uh_key, user);
258  uh_key[i] = '@';
259  strcpy(&uh_key[i+1], host);
260 
261 // Check if we already have this user in the group cache. Since we may be
262 // modifying the cache, we need to have exclusive control over it. We must
263 // copy the group cache entry because the original may be deleted at any time.
264 //
265  NetGroup_Cache_Context.Lock();
266  if ((glist = NetGroup_Cache.Find(uh_key)))
267  {if (glist->First()) glist = new XrdAccGroupList(*glist);
268  else glist = 0;
269  NetGroup_Cache_Context.UnLock();
270  return glist;
271  }
272  NetGroup_Cache_Context.UnLock();
273 
274 // For each known netgroup, check to see if the user is in the netgroup.
275 //
276  GroupTab.user = user;
277  GroupTab.host = host;
278  GroupTab.gtabi = 0;
279  Group_Name_Context.Lock();
280  NetGroup_Names.Apply(XrdAccCheckNetGroup, (void *)&GroupTab);
281  Group_Name_Context.UnLock();
282 
283 // Allocate a new GroupList object
284 //
285  glist = new XrdAccGroupList(GroupTab.gtabi,
286  (const char **)GroupTab.Gtab);
287 
288 // Add this user to the group cache to speed things up the next time
289 //
290  NetGroup_Cache_Context.Lock();
291  NetGroup_Cache.Add((const char *)uh_key, glist, LifeTime);
292  NetGroup_Cache_Context.UnLock();
293 
294 // Return a copy of the group list
295 //
296  if (!GroupTab.gtabi) return (XrdAccGroupList *)0;
297  return new XrdAccGroupList(GroupTab.gtabi,
298  (const char **)GroupTab.Gtab);
299 }
const char * user
Definition: XrdAccGroups.cc:73
int XrdAccCheckNetGroup(const char *netgroup, char *key, void *Arg)
const char * host
Definition: XrdAccGroups.cc:74
T * Apply(int(*func)(const char *, T *, void *), void *Arg)
Definition: XrdOucHash.icc:102

References XrdOucHash< T >::Add(), XrdOucHash< T >::Apply(), XrdOucHash< T >::Find(), XrdAccGroupList::First(), XrdAccGroupArgs::Gtab, XrdAccGroupArgs::gtabi, XrdAccGroupArgs::host, XrdSysMutex::Lock(), XrdSysMutex::UnLock(), XrdAccGroupArgs::user, and XrdAccCheckNetGroup().

Referenced by XrdAccAccess::Access().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PurgeCache()

void XrdAccGroups::PurgeCache ( )

Definition at line 305 of file XrdAccGroups.cc.

306 {
307 
308 // Purge the group cache
309 //
310  Group_Cache_Context.Lock();
311  Group_Cache.Purge();
312  Group_Cache_Context.UnLock();
313 
314 // Purge the netgroup cache
315 //
316  NetGroup_Cache_Context.Lock();
317  NetGroup_Cache.Purge();
318  NetGroup_Cache_Context.UnLock();
319 }
void Purge()
Definition: XrdOucHash.icc:193

References XrdSysMutex::Lock(), XrdOucHash< T >::Purge(), and XrdSysMutex::UnLock().

Referenced by XrdAccAccess::SwapTabs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Retran()

int XrdAccGroups::Retran ( const gid_t  gid)

Definition at line 325 of file XrdAccGroups.cc.

326 {
327  if ((int)gid < 0) retrancnt = 0;
328  else {if (retrancnt > (int)(sizeof(retrangid)/sizeof(gid_t))) return -1;
329  retrangid[retrancnt++] = gid;
330  }
331  return 0;
332 }

◆ SetDomain()

void XrdAccGroups::SetDomain ( const char *  dname)
inline

Definition at line 137 of file XrdAccGroups.hh.

137 {domain = dname;}

◆ SetLifetime()

void XrdAccGroups::SetLifetime ( const int  seconds)
inline

Definition at line 141 of file XrdAccGroups.hh.

141 {LifeTime = (int)seconds;}

◆ SetOptions()

void XrdAccGroups::SetOptions ( XrdAccGroups_Options  opts)
inline

Definition at line 145 of file XrdAccGroups.hh.

145 {options = opts;}
struct myOpts opts

References opts.


The documentation for this class was generated from the following files: