|
xrootd
|
00001 #ifndef _ACC_GROUPS_H 00002 #define _ACC_GROUPS_H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d A c c G r o u p s . h h */ 00006 /* */ 00007 /* (C) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Deprtment of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <grp.h> 00034 #include <limits.h> 00035 00036 #include "XrdOuc/XrdOucHash.hh" 00037 #include "XrdSys/XrdSysPthread.hh" 00038 00039 /******************************************************************************/ 00040 /* X r d A c c G r o u p L i s t */ 00041 /******************************************************************************/ 00042 00043 class XrdAccGroupList 00044 { 00045 public: 00046 00047 const char *First() {return grouptab[0];} 00048 00049 const char *Next() {if (grouptab[nextgroup]) return grouptab[nextgroup++]; 00050 return (const char *)0; 00051 } 00052 00053 void Reset() {nextgroup = 0;} 00054 00055 XrdAccGroupList(const int cnt=0, const char **gtable=0) 00056 {int j = (cnt > NGROUPS_MAX ? NGROUPS_MAX : cnt); 00057 if (cnt) memcpy((void *)grouptab, (const void *)gtable, 00058 (size_t)(j * sizeof(char *))); 00059 memset((void *)&grouptab[cnt], 0, 00060 (size_t)((NGROUPS_MAX-j+1)*sizeof(char *))); 00061 nextgroup = 0; 00062 } 00063 00064 XrdAccGroupList(XrdAccGroupList & rv) 00065 {memcpy((void *)grouptab,(const void *)rv.grouptab,sizeof(grouptab)); 00066 nextgroup = 0; 00067 } 00068 00069 ~XrdAccGroupList() {} 00070 00071 private: 00072 const char *grouptab[NGROUPS_MAX+1]; 00073 int nextgroup; 00074 }; 00075 00076 /******************************************************************************/ 00077 /* G r o u p s O p t i o n s */ 00078 /******************************************************************************/ 00079 00080 enum XrdAccGroups_Options { Primary_Only = 0x0001, 00081 Groups_Debug = 0x8000, 00082 No_Group_Opt = 0x0000 00083 }; 00084 00085 /******************************************************************************/ 00086 /* G r o u p T y p e s */ 00087 /******************************************************************************/ 00088 00089 enum XrdAccGroupType {XrdAccNoGroup = 0, XrdAccUnixGroup, XrdAccNetGroup}; 00090 00091 /******************************************************************************/ 00092 /* X r d A c c G r o u p s */ 00093 /******************************************************************************/ 00094 00095 class XrdAccGroups 00096 { 00097 public: 00098 00099 // Domain() returns whatever we have for the NIS domain. 00100 // 00101 const char *Domain() {return domain;} 00102 00103 // AddName() registers a name in the static name table. This allows us to 00104 // avoid copying the strings a table points to when returning a table copy. 00105 // If the name was added successfully, a pointer to the name is returned. 00106 // Otherwise, zero is returned. 00107 // 00108 char *AddName(const XrdAccGroupType gtype, const char *name); 00109 00110 // FindName() looks up a name in the static name table. 00111 // 00112 char *FindName(const XrdAccGroupType gtype, const char *name); 00113 00114 // Groups() returns all of the relevant groups that a user belongs to. A 00115 // null pointer may be returned if no groups are applicable. 00116 // 00117 XrdAccGroupList *Groups(const char *user); 00118 00119 // NetGroups() returns all of the relevant netgroups that the user/host 00120 // combination belongs to. A null pointer may be returned is no netgroups 00121 // are applicable. 00122 // 00123 XrdAccGroupList *NetGroups(const char *user, const char *host); 00124 00125 // PurgeCache() removes all entries in the various caches. It is called 00126 // whenever a new set of access tables has been instantiated. 00127 // 00128 void PurgeCache(); 00129 00130 // Use by the configuration object to set group id's that must be looked up. 00131 // 00132 int Retran(const gid_t gid); 00133 00134 // Use by the configuration object to establish the netgroup domain. 00135 // 00136 void SetDomain(const char *dname) {domain = dname;} 00137 00138 // Used by the configuration object to set the cache lifetime. 00139 // 00140 void SetLifetime(const int seconds) {LifeTime = (int)seconds;} 00141 00142 // Used by the configuration object to set various options 00143 // 00144 void SetOptions(XrdAccGroups_Options opts) {options = opts;} 00145 00146 XrdAccGroups(); 00147 00148 ~XrdAccGroups() {} // The group object never gets deleted!! 00149 00150 private: 00151 00152 int addGroup(const char *user, const gid_t gid, char *gname, 00153 char **Gtab, int gtabi); 00154 char *Dotran(const gid_t gid, char *gname); 00155 00156 gid_t retrangid[128]; // Up to 128 retranslatable gids 00157 int retrancnt; // Number of used entries 00158 time_t LifeTime; // Seconds we can keep something in the cache 00159 const char *domain; // NIS netgroup domain to use 00160 00161 XrdAccGroups_Options options;// Various option values. 00162 int HaveGroups; 00163 int HaveNetGroups; 00164 00165 XrdSysMutex Group_Build_Context, Group_Name_Context; 00166 XrdSysMutex Group_Cache_Context, NetGroup_Cache_Context; 00167 00168 XrdOucHash<XrdAccGroupList> NetGroup_Cache; 00169 XrdOucHash<XrdAccGroupList> Group_Cache; 00170 XrdOucHash<char> Group_Names; 00171 XrdOucHash<char> NetGroup_Names; 00172 }; 00173 #endif
1.7.6.1