X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fipaddressacl.cpp;h=2f6295507ffa3b62b6c731fd7f01bb3a2f258dfd;hp=0516c1d67c422f843786cfea8b5186f0a52a61b3;hb=026dc6b2bc548c945359c4e166eff514f2c47c6a;hpb=dec33c63afafabf83c3039e916725cac6faef9b3 diff --git a/src/ipaddressacl.cpp b/src/ipaddressacl.cpp index 0516c1d..2f62955 100644 --- a/src/ipaddressacl.cpp +++ b/src/ipaddressacl.cpp @@ -12,7 +12,7 @@ IPAddressACL::IPAddressACL():m_allowbydefault(true) const bool IPAddressACL::Add(const std::string &aclentry) { bool allow=m_allowbydefault; - int maskbits=0; + int maskbits=32; std::string::size_type strpos=std::string::npos; std::string entrystr=aclentry; @@ -63,18 +63,32 @@ const bool IPAddressACL::Add(const std::string &aclentry) const std::string IPAddressACL::CreateMask(const int maskbits) { +/* int bitsleft=maskbits; - int parts[4]={255,255,255,255}; + int parts[4]={0,0,0,0}; std::ostringstream ipstr; - for(int i=3; i>=0; i--) + for(int i=0; i<4; i++) { - for(int b=0; b<8 && bitsleft>0; b++) + for(int b=7; b>=0 && bitsleft>0; b--) { - parts[i]-=pow((float)2,b); + parts[i]+=pow((float)2,b); bitsleft--; } } +*/ + int bits=maskbits; + bits>32 ? bits=32 : false; + bits<0 ? bits=0 : false; + int parts[4]={0,0,0,0}; + std::ostringstream ipstr; + + unsigned long maskval=(((unsigned long)pow((float)2,bits)-1) << (32-bits)); + + parts[0]=((maskval >> 24) & 0xff); + parts[1]=((maskval >> 16) & 0xff); + parts[2]=((maskval >> 8) & 0xff); + parts[3]=(maskval & 0xff); ipstr << parts[0] << "." << parts[1] << "." << parts[2] << "." << parts[3]; @@ -86,7 +100,7 @@ const bool IPAddressACL::IsAllowed(const Poco::Net::IPAddress &addr) bool found=false; bool rval=m_allowbydefault; - for(std::vector::iterator i=m_entries.begin(); i!=m_entries.end() && found==false; i++) + for(std::vector::reverse_iterator i=m_entries.rbegin(); i!=m_entries.rend() && found==false; i++) { Poco::Net::IPAddress ip1=addr; Poco::Net::IPAddress ip2=(*i).m_addr; @@ -94,8 +108,11 @@ const bool IPAddressACL::IsAllowed(const Poco::Net::IPAddress &addr) //ip1.mask((*i).m_mask); //ip2.mask((*i).m_mask); - ip1=MaskAddress(ip1,(*i).m_mask); - ip2=MaskAddress(ip2,(*i).m_mask); + if(ip1.family()==Poco::Net::IPAddress::IPv4 && ip2.family()==Poco::Net::IPAddress::IPv4) + { + ip1=MaskAddress(ip1,(*i).m_mask); + ip2=MaskAddress(ip2,(*i).m_mask); + } if(ip1==ip2) {