xrootd
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"
37 #include "XrdSys/XrdSysPthread.hh"
38 
39 /******************************************************************************/
40 /* X r d A c c G r o u p L i s t */
41 /******************************************************************************/
42 
44 {
45 public:
46 
47 const char *First() {return grouptab[0];}
48 
49 const 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 
72 private:
73 const char *grouptab[NGROUPS_MAX+1];
74  int nextgroup;
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 {
98 public:
99 
100 // Domain() returns whatever we have for the NIS domain.
101 //
102 const 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 //
109 char *AddName(const XrdAccGroupType gtype, const char *name);
110 
111 // FindName() looks up a name in the static name table.
112 //
113 char *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 //
118 XrdAccGroupList *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 //
124 XrdAccGroupList *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 //
129 void PurgeCache();
130 
131 // Use by the configuration object to set group id's that must be looked up.
132 //
133 int Retran(const gid_t gid);
134 
135 // Use by the configuration object to establish the netgroup domain.
136 //
137 void SetDomain(const char *dname) {domain = dname;}
138 
139 // Used by the configuration object to set the cache lifetime.
140 //
141 void SetLifetime(const int seconds) {LifeTime = (int)seconds;}
142 
143 // Used by the configuration object to set various options
144 //
146 
147  XrdAccGroups();
148 
149  ~XrdAccGroups() {} // The group object never gets deleted!!
150 
151 private:
152 
153 int addGroup(const char *user, const gid_t gid, char *gname,
154  char **Gtab, int gtabi);
155 char *Dotran(const gid_t gid, char *gname);
156 
157 gid_t retrangid[128]; // Up to 128 retranslatable gids
158 int retrancnt; // Number of used entries
159 time_t LifeTime; // Seconds we can keep something in the cache
160 const char *domain; // NIS netgroup domain to use
161 
162 XrdAccGroups_Options options;// Various option values.
165 
168 
173 };
174 #endif
int addGroup(const char *user, const gid_t gid, char *gname, char **Gtab, int gtabi)
Definition: XrdAccGroups.hh:82
const char * grouptab[NGROUPS_MAX+1]
Definition: XrdAccGroups.hh:73
time_t LifeTime
Definition: XrdAccGroups.hh:159
const char * Next()
Definition: XrdAccGroups.hh:49
int nextgroup
Definition: XrdAccGroups.hh:74
const char * First()
Definition: XrdAccGroups.hh:47
XrdOucHash< char > Group_Names
Definition: XrdAccGroups.hh:171
int HaveGroups
Definition: XrdAccGroups.hh:163
XrdSysMutex Group_Cache_Context
Definition: XrdAccGroups.hh:167
Definition: XrdAccGroups.hh:90
XrdOucHash< XrdAccGroupList > NetGroup_Cache
Definition: XrdAccGroups.hh:169
XrdAccGroupList * Groups(const char *user)
~XrdAccGroupList()
Definition: XrdAccGroups.hh:70
Definition: XrdAccGroups.hh:96
XrdSysMutex Group_Name_Context
Definition: XrdAccGroups.hh:166
Definition: XrdSysPthread.hh:165
XrdAccGroupList(XrdAccGroupList &rv)
Definition: XrdAccGroups.hh:65
~XrdAccGroups()
Definition: XrdAccGroups.hh:149
XrdAccGroups_Options
Definition: XrdAccGroups.hh:81
const char * domain
Definition: XrdAccGroups.hh:160
const char * Domain()
Definition: XrdAccGroups.hh:102
Definition: XrdAccGroups.hh:81
XrdAccGroups_Options options
Definition: XrdAccGroups.hh:162
Definition: XrdAccGroups.hh:83
void PurgeCache()
gid_t retrangid[128]
Definition: XrdAccGroups.hh:157
Definition: XrdAccGroups.hh:43
char * FindName(const XrdAccGroupType gtype, const char *name)
int retrancnt
Definition: XrdAccGroups.hh:158
XrdOucHash< char > NetGroup_Names
Definition: XrdAccGroups.hh:172
void Reset()
Definition: XrdAccGroups.hh:53
void SetLifetime(const int seconds)
Definition: XrdAccGroups.hh:141
char * AddName(const XrdAccGroupType gtype, const char *name)
int HaveNetGroups
Definition: XrdAccGroups.hh:164
XrdAccGroupType
Definition: XrdAccGroups.hh:90
XrdAccGroupList(const int cnt=0, const char **gtable=0)
Definition: XrdAccGroups.hh:55
void SetOptions(XrdAccGroups_Options opts)
Definition: XrdAccGroups.hh:145
char * Dotran(const gid_t gid, char *gname)
void SetDomain(const char *dname)
Definition: XrdAccGroups.hh:137
XrdAccGroupList * NetGroups(const char *user, const char *host)
XrdSysMutex Group_Build_Context
Definition: XrdAccGroups.hh:166
Definition: XrdAccGroups.hh:90
int Retran(const gid_t gid)
XrdSysMutex NetGroup_Cache_Context
Definition: XrdAccGroups.hh:167
Definition: XrdAccGroups.hh:90
XrdOucHash< XrdAccGroupList > Group_Cache
Definition: XrdAccGroups.hh:170