34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
40 #include <sys/types.h>
43 #include "XrdSys/XrdWin32.hh"
51 #if defined(MUSL) || defined(WIN32)
52 int innetgr(
const char *netgroup,
const char *host,
const char *user,
78 #define DEBUG(x) if (eTrace) {SYSTRACE(eTrace->, 0, TraceID, 0, x)}
84 const char *XrdNetSecurity::TraceID =
"NetSecurity";
96 if (!index(hname,
'*') && addHIP(hname))
return;
106 DEBUG(hname <<
" (" <<hname <<
") added to authorized hosts.");
119 tlp->
next = NetGroups;
125 DEBUG(gname <<
" added to authorized netgroups.");
138 if (theAddr.
Set(hSpec, -1094))
return false;
162 if (OKHosts.
Find(ipAddr)) {okHMutex.
UnLock();
return true;}
166 if (!chkNetLst && !chkNetGrp) {okHMutex.
UnLock();
return false;}
167 if (!(hName = addr.
Name())) hName = ipAddr;
171 if ((tlp = NetGroups))
172 do {
if (innetgr(tlp->
text, hName, 0, 0))
173 return hostOK(hName, ipAddr,
"netgroup");
174 }
while ((tlp = tlp->
next));
178 if (chkNetLst && HostList.
Find(hName))
179 return hostOK(hName, ipAddr,
"host");
184 DEBUG(hName <<
" not authorized");
199 while((np = srcp->HostList.
Pop())) HostList.
Replace(np);
203 while((sp = srcp->NetGroups))
204 {tp = NetGroups; srcp->NetGroups = sp->
next;
205 while(tp)
if (!strcmp(tp->
text, sp->
text))
break;
208 else {sp->
next = NetGroups;
225 bool XrdNetSecurity::addHIP(
const char *hname)
237 {
DEBUG(hname <<
"IP add to authorized hosts failed; " <<eTxt);
243 for (i = 0; i < iN; i++)
246 DEBUG(ipbuff <<
" (" <<hname <<
") added to authorized hosts.");
259 bool XrdNetSecurity::hostOK(
const char *hname,
const char *ipname,
268 DEBUG(hname <<
" authorized via " <<why);
static const int noPort
Do not add port number.
static const int old6Map4
Use deprecated IPV6 mapped format.
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
bool Authorize(const char *hSpec)
void AddHost(char *hname)
void AddNetGroup(char *hname)
void Merge(XrdNetSecurity *srcp)
XrdNetTextList(char *newtext)
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
T * Find(const char *KeyVal, time_t *KeyTime=0)
void Insert(XrdOucNList *newitem)
XrdOucNList * Find(const char *name)
void Replace(const char *name, int nval)