Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

AccessList.cc File Reference

#include "util.h"
#include "AccessList.h"
#include <strstream>
#include <algorithm>

Go to the source code of this file.

Defines

#define STRN_EQ(x, y, l)   (strncasecmp((x),(y),(l)) == 0)
#define STRN_NE(x, y, l)   (strncasecmp((x),(y),(l)) != 0)
#define STR_EQ(x, y)   (strcasecmp((x),(y)) == 0)
#define STR_NE(x, y)   (strcasecmp((x),(y)) != 0)
#define NOT_INADDR(s)   (s[strspn(s,"01234567890./")] != 0)
#define ACCESSLIST_SET_FILTERS

Functions

ostream & operator<< (ostream &os, const AccessEntry &ae)
int in_domain (const char *name, const char *domain)
int matchaddress (const char *pattern, const char *name, const struct in_addr &host_addr)


Define Documentation

#define ACCESSLIST_SET_FILTERS
 

Value:

if (!(filter_set&0x01)) cur.list=a1; \
      if (!(filter_set&0x02)) cur.read=a1; \
      if (!(filter_set&0x04)) cur.postTo=a1;

Definition at line 133 of file AccessList.cc.

Referenced by AccessList::readClient().

#define NOT_INADDR  )     (s[strspn(s,"01234567890./")] != 0)
 

Definition at line 46 of file AccessList.cc.

Referenced by matchaddress().

#define STR_EQ x,
 )     (strcasecmp((x),(y)) == 0)
 

Definition at line 42 of file AccessList.cc.

Referenced by in_domain().

#define STR_NE x,
 )     (strcasecmp((x),(y)) != 0)
 

Definition at line 43 of file AccessList.cc.

#define STRN_EQ x,
y,
 )     (strncasecmp((x),(y),(l)) == 0)
 

Definition at line 40 of file AccessList.cc.

Referenced by in_domain().

#define STRN_NE x,
y,
 )     (strncasecmp((x),(y),(l)) != 0)
 

Definition at line 41 of file AccessList.cc.


Function Documentation

int in_domain const char *  name,
const char *  domain
 

Definition at line 48 of file AccessList.cc.

References STR_EQ, and STRN_EQ.

Referenced by matchaddress().

00049 {
00050         int name_len = strlen(name);
00051         int domain_len = strlen(domain);
00052 
00053         if (domain[domain_len - 1] == '.') {    /* prefix */
00054                 return STRN_EQ(name, domain, domain_len);
00055         } else if (domain[0] == '.') {  /* suffix */
00056                 int n = name_len - domain_len;
00057                 return n > 0 && STR_EQ(name + n, domain);
00058         } else {                /* exact match */
00059                 return STR_EQ(name, domain);
00060         }
00061 }

int matchaddress const char *  pattern,
const char *  name,
const struct in_addr &  host_addr
 

Definition at line 63 of file AccessList.cc.

References in_domain(), and NOT_INADDR.

Referenced by AccessList::client().

00065 {
00066         const char *p = pattern;
00067 
00068         while (*p && *p != '/')
00069                 ++p;
00070 
00071         if (*p) {
00072                 string net(pattern, p - pattern);
00073                 string mask(p + 1);
00074 
00075                 struct in_addr net_addr, mask_addr;
00076                 if (!inet_aton(net.c_str(), &net_addr))
00077                         return 0;
00078                 if (!inet_aton(mask.c_str(), &mask_addr))
00079                         return 0;
00080 
00081                 return (host_addr.s_addr & mask_addr.s_addr) ==
00082                     net_addr.s_addr;
00083         } else {                /* anything else */
00084                 return NOT_INADDR(name) && in_domain(name, pattern);
00085         }
00086 }

ostream& operator<< std::ostream &  os,
const AccessEntry ae
 

Definition at line 14 of file AccessList.cc.

References AccessEntry::access_flags, AccessEntry::authentication, AccessEntry::hostname, AccessEntry::list, AccessEntry::PAMServicename, AccessEntry::postTo, AccessEntry::printAccessFlags(), Authentication::printParameters(), and AccessEntry::read.

00015 {
00016 #ifdef HAVE_SSTREAM
00017         stringstream sb;
00018 #else
00019         strstream sb;
00020 #endif
00021 
00022         os << ae.hostname << '{' << endl;
00023         os << "  access_flags=" << ae.access_flags << " (";
00024         ae.printAccessFlags(&os);
00025         os << ")"<< endl;
00026         os << "  list=" << ae.list << endl;
00027         os << "  read=" << ae.read << endl;
00028         os << "  postto=" << ae.postTo << endl;
00029         ae.authentication.printParameters (&sb);
00030         os << "  PAMServicename " << ae.PAMServicename << endl;
00031         string t = sb.str();
00032         // replace \t\tAuthentication with ""
00033         t.replace(0, 17, "");
00034         os << "  authentication=" << t << endl;
00035         os << '}';
00036 
00037         return os;
00038 }


Generated on Fri Aug 20 10:58:08 2004 for NewsCache by doxygen 1.3.6-20040222