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  memset((void *)&grouptab[cnt], 0,
60  (size_t)((NGROUPS_MAX-j+1)*sizeof(char *)));
61  nextgroup = 0;
62  }
63 
65  {memcpy((void *)grouptab,(const void *)rv.grouptab,sizeof(grouptab));
66  nextgroup = 0;
67  }
68 
70 
71 private:
72 const char *grouptab[NGROUPS_MAX+1];
73  int nextgroup;
74 };
75 
76 /******************************************************************************/
77 /* G r o u p s O p t i o n s */
78 /******************************************************************************/
79 
81  Groups_Debug = 0x8000,
82  No_Group_Opt = 0x0000
83  };
84 
85 /******************************************************************************/
86 /* G r o u p T y p e s */
87 /******************************************************************************/
88 
90 
91 /******************************************************************************/
92 /* X r d A c c G r o u p s */
93 /******************************************************************************/
94 
96 {
97 public:
98 
99 // Domain() returns whatever we have for the NIS domain.
100 //
101 const char *Domain() {return domain;}
102 
103 // AddName() registers a name in the static name table. This allows us to
104 // avoid copying the strings a table points to when returning a table copy.
105 // If the name was added successfully, a pointer to the name is returned.
106 // Otherwise, zero is returned.
107 //
108 char *AddName(const XrdAccGroupType gtype, const char *name);
109 
110 // FindName() looks up a name in the static name table.
111 //
112 char *FindName(const XrdAccGroupType gtype, const char *name);
113 
114 // Groups() returns all of the relevant groups that a user belongs to. A
115 // null pointer may be returned if no groups are applicable.
116 //
117 XrdAccGroupList *Groups(const char *user);
118 
119 // NetGroups() returns all of the relevant netgroups that the user/host
120 // combination belongs to. A null pointer may be returned is no netgroups
121 // are applicable.
122 //
123 XrdAccGroupList *NetGroups(const char *user, const char *host);
124 
125 // PurgeCache() removes all entries in the various caches. It is called
126 // whenever a new set of access tables has been instantiated.
127 //
128 void PurgeCache();
129 
130 // Use by the configuration object to set group id's that must be looked up.
131 //
132 int Retran(const gid_t gid);
133 
134 // Use by the configuration object to establish the netgroup domain.
135 //
136 void SetDomain(const char *dname) {domain = dname;}
137 
138 // Used by the configuration object to set the cache lifetime.
139 //
140 void SetLifetime(const int seconds) {LifeTime = (int)seconds;}
141 
142 // Used by the configuration object to set various options
143 //
145 
146  XrdAccGroups();
147 
148  ~XrdAccGroups() {} // The group object never gets deleted!!
149 
150 private:
151 
152 int addGroup(const char *user, const gid_t gid, char *gname,
153  char **Gtab, int gtabi);
154 char *Dotran(const gid_t gid, char *gname);
155 
156 gid_t retrangid[128]; // Up to 128 retranslatable gids
157 int retrancnt; // Number of used entries
158 time_t LifeTime; // Seconds we can keep something in the cache
159 const char *domain; // NIS netgroup domain to use
160 
161 XrdAccGroups_Options options;// Various option values.
164 
167 
172 };
173 #endif