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-AC03-76-SFO0515 with the Deprtment of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include <grp.h> 00016 #include <limits.h> 00017 00018 #include "XrdOuc/XrdOucHash.hh" 00019 #include "XrdSys/XrdSysPthread.hh" 00020 00021 /******************************************************************************/ 00022 /* X r d A c c G r o u p L i s t */ 00023 /******************************************************************************/ 00024 00025 class XrdAccGroupList 00026 { 00027 public: 00028 00029 const char *First() {return grouptab[0];} 00030 00031 const char *Next() {if (grouptab[nextgroup]) return grouptab[nextgroup++]; 00032 return (const char *)0; 00033 } 00034 00035 void Reset() {nextgroup = 0;} 00036 00037 XrdAccGroupList(const int cnt=0, const char **gtable=0) 00038 {int j = (cnt > NGROUPS_MAX ? NGROUPS_MAX : cnt); 00039 if (cnt) memcpy((void *)grouptab, (const void *)gtable, 00040 (size_t)(j * sizeof(char *))); 00041 memset((void *)&grouptab[cnt], 0, 00042 (size_t)((NGROUPS_MAX-j+1)*sizeof(char *))); 00043 nextgroup = 0; 00044 } 00045 00046 XrdAccGroupList(XrdAccGroupList & rv) 00047 {memcpy((void *)grouptab,(const void *)rv.grouptab,sizeof(grouptab)); 00048 nextgroup = 0; 00049 } 00050 00051 ~XrdAccGroupList() {} 00052 00053 private: 00054 const char *grouptab[NGROUPS_MAX+1]; 00055 int nextgroup; 00056 }; 00057 00058 /******************************************************************************/ 00059 /* G r o u p s O p t i o n s */ 00060 /******************************************************************************/ 00061 00062 enum XrdAccGroups_Options { Primary_Only = 0x0001, 00063 Groups_Debug = 0x8000, 00064 No_Group_Opt = 0x0000 00065 }; 00066 00067 /******************************************************************************/ 00068 /* G r o u p T y p e s */ 00069 /******************************************************************************/ 00070 00071 enum XrdAccGroupType {XrdAccNoGroup = 0, XrdAccUnixGroup, XrdAccNetGroup}; 00072 00073 /******************************************************************************/ 00074 /* X r d A c c G r o u p s */ 00075 /******************************************************************************/ 00076 00077 class XrdAccGroups 00078 { 00079 public: 00080 00081 // Domain() returns whatever we have for the NIS domain. 00082 // 00083 const char *Domain() {return domain;} 00084 00085 // AddName() registers a name in the static name table. This allows us to 00086 // avoid copying the strings a table points to when returning a table copy. 00087 // If the name was added successfully, a pointer to the name is returned. 00088 // Otherwise, zero is returned. 00089 // 00090 char *AddName(const XrdAccGroupType gtype, const char *name); 00091 00092 // FindName() looks up a name in the static name table. 00093 // 00094 char *FindName(const XrdAccGroupType gtype, const char *name); 00095 00096 // Groups() returns all of the relevant groups that a user belongs to. A 00097 // null pointer may be returned if no groups are applicable. 00098 // 00099 XrdAccGroupList *Groups(const char *user); 00100 00101 // NetGroups() returns all of the relevant netgroups that the user/host 00102 // combination belongs to. A null pointer may be returned is no netgroups 00103 // are applicable. 00104 // 00105 XrdAccGroupList *NetGroups(const char *user, const char *host); 00106 00107 // PurgeCache() removes all entries in the various caches. It is called 00108 // whenever a new set of access tables has been instantiated. 00109 // 00110 void PurgeCache(); 00111 00112 // Use by the configuration object to set group id's that must be looked up. 00113 // 00114 int Retran(const gid_t gid); 00115 00116 // Use by the configuration object to establish the netgroup domain. 00117 // 00118 void SetDomain(const char *dname) {domain = dname;} 00119 00120 // Used by the configuration object to set the cache lifetime. 00121 // 00122 void SetLifetime(const int seconds) {LifeTime = (int)seconds;} 00123 00124 // Used by the configuration object to set various options 00125 // 00126 void SetOptions(XrdAccGroups_Options opts) {options = opts;} 00127 00128 XrdAccGroups(); 00129 00130 ~XrdAccGroups() {} // The group object never gets deleted!! 00131 00132 private: 00133 00134 int addGroup(const char *user, const gid_t gid, char *gname, 00135 char **Gtab, int gtabi); 00136 char *Dotran(const gid_t gid, char *gname); 00137 00138 gid_t retrangid[128]; // Up to 128 retranslatable gids 00139 int retrancnt; // Number of used entries 00140 time_t LifeTime; // Seconds we can keep something in the cache 00141 const char *domain; // NIS netgroup domain to use 00142 00143 XrdAccGroups_Options options;// Various option values. 00144 int HaveGroups; 00145 int HaveNetGroups; 00146 00147 XrdSysMutex Group_Build_Context, Group_Name_Context; 00148 XrdSysMutex Group_Cache_Context, NetGroup_Cache_Context; 00149 00150 XrdOucHash<XrdAccGroupList> NetGroup_Cache; 00151 XrdOucHash<XrdAccGroupList> Group_Cache; 00152 XrdOucHash<char> Group_Names; 00153 XrdOucHash<char> NetGroup_Names; 00154 }; 00155 #endif