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 } 00060 memset((void *)&grouptab[cnt], 0, 00061 (size_t)((NGROUPS_MAX-j+1)*sizeof(char *))); 00062 nextgroup = 0; 00063 } 00064 00065 XrdAccGroupList(XrdAccGroupList & rv) 00066 {memcpy((void *)grouptab,(const void *)rv.grouptab,sizeof(grouptab)); 00067 nextgroup = 0; 00068 } 00069 00070 ~XrdAccGroupList() {} 00071 00072 private: 00073 const char *grouptab[NGROUPS_MAX+1]; 00074 int nextgroup; 00075 }; 00076 00077 /******************************************************************************/ 00078 /* G r o u p s O p t i o n s */ 00079 /******************************************************************************/ 00080 00081 enum XrdAccGroups_Options { Primary_Only = 0x0001, 00082 Groups_Debug = 0x8000, 00083 No_Group_Opt = 0x0000 00084 }; 00085 00086 /******************************************************************************/ 00087 /* G r o u p T y p e s */ 00088 /******************************************************************************/ 00089 00090 enum XrdAccGroupType {XrdAccNoGroup = 0, XrdAccUnixGroup, XrdAccNetGroup}; 00091 00092 /******************************************************************************/ 00093 /* X r d A c c G r o u p s */ 00094 /******************************************************************************/ 00095 00096 class XrdAccGroups 00097 { 00098 public: 00099 00100 // Domain() returns whatever we have for the NIS domain. 00101 // 00102 const char *Domain() {return domain;} 00103 00104 // AddName() registers a name in the static name table. This allows us to 00105 // avoid copying the strings a table points to when returning a table copy. 00106 // If the name was added successfully, a pointer to the name is returned. 00107 // Otherwise, zero is returned. 00108 // 00109 char *AddName(const XrdAccGroupType gtype, const char *name); 00110 00111 // FindName() looks up a name in the static name table. 00112 // 00113 char *FindName(const XrdAccGroupType gtype, const char *name); 00114 00115 // Groups() returns all of the relevant groups that a user belongs to. A 00116 // null pointer may be returned if no groups are applicable. 00117 // 00118 XrdAccGroupList *Groups(const char *user); 00119 00120 // NetGroups() returns all of the relevant netgroups that the user/host 00121 // combination belongs to. A null pointer may be returned is no netgroups 00122 // are applicable. 00123 // 00124 XrdAccGroupList *NetGroups(const char *user, const char *host); 00125 00126 // PurgeCache() removes all entries in the various caches. It is called 00127 // whenever a new set of access tables has been instantiated. 00128 // 00129 void PurgeCache(); 00130 00131 // Use by the configuration object to set group id's that must be looked up. 00132 // 00133 int Retran(const gid_t gid); 00134 00135 // Use by the configuration object to establish the netgroup domain. 00136 // 00137 void SetDomain(const char *dname) {domain = dname;} 00138 00139 // Used by the configuration object to set the cache lifetime. 00140 // 00141 void SetLifetime(const int seconds) {LifeTime = (int)seconds;} 00142 00143 // Used by the configuration object to set various options 00144 // 00145 void SetOptions(XrdAccGroups_Options opts) {options = opts;} 00146 00147 XrdAccGroups(); 00148 00149 ~XrdAccGroups() {} // The group object never gets deleted!! 00150 00151 private: 00152 00153 int addGroup(const char *user, const gid_t gid, char *gname, 00154 char **Gtab, int gtabi); 00155 char *Dotran(const gid_t gid, char *gname); 00156 00157 gid_t retrangid[128]; // Up to 128 retranslatable gids 00158 int retrancnt; // Number of used entries 00159 time_t LifeTime; // Seconds we can keep something in the cache 00160 const char *domain; // NIS netgroup domain to use 00161 00162 XrdAccGroups_Options options;// Various option values. 00163 int HaveGroups; 00164 int HaveNetGroups; 00165 00166 XrdSysMutex Group_Build_Context, Group_Name_Context; 00167 XrdSysMutex Group_Cache_Context, NetGroup_Cache_Context; 00168 00169 XrdOucHash<XrdAccGroupList> NetGroup_Cache; 00170 XrdOucHash<XrdAccGroupList> Group_Cache; 00171 XrdOucHash<char> Group_Names; 00172 XrdOucHash<char> NetGroup_Names; 00173 }; 00174 #endif