xrootd
Loading...
Searching...
No Matches
XrdAccGroups.hh
Go to the documentation of this file.
1#ifndef _ACC_GROUPS_H
2#define _ACC_GROUPS_H
3/******************************************************************************/
4/* */
5/* X r d A c c G r o u p s . 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 Deprtment 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 <grp.h>
34#include <limits.h>
35
36#include "XrdOuc/XrdOucHash.hh"
38
39/******************************************************************************/
40/* X r d A c c G r o u p L i s t */
41/******************************************************************************/
42
44{
45public:
46
47const char *First() {return grouptab[0];}
48
49const char *Next() {if (grouptab[nextgroup]) return grouptab[nextgroup++];
50 return (const char *)0;
51 }
52
53 void Reset() {nextgroup = 0;}
54
55 XrdAccGroupList(const int cnt=0, const char **gtable=0)
56 {int j = (cnt > NGROUPS_MAX ? NGROUPS_MAX : cnt);
57 if (cnt){memcpy((void *)grouptab, (const void *)gtable,
58 (size_t)(j * sizeof(char *)));
59 }
60 memset((void *)&grouptab[cnt], 0,
61 (size_t)((NGROUPS_MAX-j+1)*sizeof(char *)));
62 nextgroup = 0;
63 }
64
66 {memcpy((void *)grouptab,(const void *)rv.grouptab,sizeof(grouptab));
67 nextgroup = 0;
68 }
69
71
72private:
73const char *grouptab[NGROUPS_MAX+1];
75};
76
77/******************************************************************************/
78/* G r o u p s O p t i o n s */
79/******************************************************************************/
80
82 Groups_Debug = 0x8000,
83 No_Group_Opt = 0x0000
84 };
85
86/******************************************************************************/
87/* G r o u p T y p e s */
88/******************************************************************************/
89
91
92/******************************************************************************/
93/* X r d A c c G r o u p s */
94/******************************************************************************/
95
97{
98public:
99
100// Domain() returns whatever we have for the NIS domain.
101//
102const char *Domain() {return domain;}
103
104// AddName() registers a name in the static name table. This allows us to
105// avoid copying the strings a table points to when returning a table copy.
106// If the name was added successfully, a pointer to the name is returned.
107// Otherwise, zero is returned.
108//
109char *AddName(const XrdAccGroupType gtype, const char *name);
110
111// FindName() looks up a name in the static name table.
112//
113char *FindName(const XrdAccGroupType gtype, const char *name);
114
115// Groups() returns all of the relevant groups that a user belongs to. A
116// null pointer may be returned if no groups are applicable.
117//
118XrdAccGroupList *Groups(const char *user);
119
120// NetGroups() returns all of the relevant netgroups that the user/host
121// combination belongs to. A null pointer may be returned is no netgroups
122// are applicable.
123//
124XrdAccGroupList *NetGroups(const char *user, const char *host);
125
126// PurgeCache() removes all entries in the various caches. It is called
127// whenever a new set of access tables has been instantiated.
128//
130
131// Use by the configuration object to set group id's that must be looked up.
132//
133int Retran(const gid_t gid);
134
135// Use by the configuration object to establish the netgroup domain.
136//
137void SetDomain(const char *dname) {domain = dname;}
138
139// Used by the configuration object to set the cache lifetime.
140//
141void SetLifetime(const int seconds) {LifeTime = (int)seconds;}
142
143// Used by the configuration object to set various options
144//
146
148
149 ~XrdAccGroups() {} // The group object never gets deleted!!
150
151private:
152
153int addGroup(const char *user, const gid_t gid, char *gname,
154 char **Gtab, int gtabi);
155char *Dotran(const gid_t gid, char *gname);
156
157gid_t retrangid[128]; // Up to 128 retranslatable gids
158int retrancnt; // Number of used entries
159time_t LifeTime; // Seconds we can keep something in the cache
160const char *domain; // NIS netgroup domain to use
161
162XrdAccGroups_Options options;// Various option values.
165
168
173};
174#endif
XrdAccGroupType
Definition XrdAccGroups.hh:90
@ XrdAccNoGroup
Definition XrdAccGroups.hh:90
@ XrdAccNetGroup
Definition XrdAccGroups.hh:90
@ XrdAccUnixGroup
Definition XrdAccGroups.hh:90
XrdAccGroups_Options
Definition XrdAccGroups.hh:81
@ Groups_Debug
Definition XrdAccGroups.hh:82
@ No_Group_Opt
Definition XrdAccGroups.hh:83
@ Primary_Only
Definition XrdAccGroups.hh:81
Definition XrdAccGroups.hh:44
const char * Next()
Definition XrdAccGroups.hh:49
~XrdAccGroupList()
Definition XrdAccGroups.hh:70
XrdAccGroupList(XrdAccGroupList &rv)
Definition XrdAccGroups.hh:65
const char * First()
Definition XrdAccGroups.hh:47
XrdAccGroupList(const int cnt=0, const char **gtable=0)
Definition XrdAccGroups.hh:55
const char * grouptab[NGROUPS_MAX+1]
Definition XrdAccGroups.hh:73
int nextgroup
Definition XrdAccGroups.hh:74
void Reset()
Definition XrdAccGroups.hh:53
Definition XrdAccGroups.hh:97
XrdOucHash< char > NetGroup_Names
Definition XrdAccGroups.hh:172
void PurgeCache()
time_t LifeTime
Definition XrdAccGroups.hh:159
char * AddName(const XrdAccGroupType gtype, const char *name)
int Retran(const gid_t gid)
char * Dotran(const gid_t gid, char *gname)
gid_t retrangid[128]
Definition XrdAccGroups.hh:157
int HaveNetGroups
Definition XrdAccGroups.hh:164
int HaveGroups
Definition XrdAccGroups.hh:163
XrdOucHash< XrdAccGroupList > NetGroup_Cache
Definition XrdAccGroups.hh:169
XrdAccGroups_Options options
Definition XrdAccGroups.hh:162
XrdSysMutex NetGroup_Cache_Context
Definition XrdAccGroups.hh:167
XrdAccGroupList * Groups(const char *user)
XrdSysMutex Group_Build_Context
Definition XrdAccGroups.hh:166
XrdOucHash< char > Group_Names
Definition XrdAccGroups.hh:171
int retrancnt
Definition XrdAccGroups.hh:158
const char * domain
Definition XrdAccGroups.hh:160
XrdAccGroupList * NetGroups(const char *user, const char *host)
void SetOptions(XrdAccGroups_Options opts)
Definition XrdAccGroups.hh:145
XrdOucHash< XrdAccGroupList > Group_Cache
Definition XrdAccGroups.hh:170
void SetLifetime(const int seconds)
Definition XrdAccGroups.hh:141
int addGroup(const char *user, const gid_t gid, char *gname, char **Gtab, int gtabi)
~XrdAccGroups()
Definition XrdAccGroups.hh:149
char * FindName(const XrdAccGroupType gtype, const char *name)
XrdSysMutex Group_Name_Context
Definition XrdAccGroups.hh:166
const char * Domain()
Definition XrdAccGroups.hh:102
XrdSysMutex Group_Cache_Context
Definition XrdAccGroups.hh:167
void SetDomain(const char *dname)
Definition XrdAccGroups.hh:137
Definition XrdOucHash.hh:128
Definition XrdSysPthread.hh:165