From: Maxim Mamontov Date: Mon, 4 Apr 2011 18:56:29 +0000 (+0300) Subject: Obsolete hostallow library removed X-Git-Tag: 2.407-rc3~87 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/38fcd6e6cc9517f35a349042b88fbdb3a52c5389 Obsolete hostallow library removed --- diff --git a/stglibs/hostallow.lib/Makefile b/stglibs/hostallow.lib/Makefile deleted file mode 100644 index 97f9c0c0..00000000 --- a/stglibs/hostallow.lib/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# $Id: Makefile,v 1.3 2007/05/08 14:29:20 faust Exp $ -############################################################################### - -LIB_NAME = hostallow -PROG = lib$(LIB_NAME) - -SRCS = hostallow.cpp - -INCS = hostallow.h - -include ../Makefile.in diff --git a/stglibs/hostallow.lib/hostallow.cpp b/stglibs/hostallow.lib/hostallow.cpp deleted file mode 100644 index 9fedbbfc..00000000 --- a/stglibs/hostallow.lib/hostallow.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Date: 27.10.2002 - */ - -/* - * Author : Boris Mikhailenko - */ - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostallow.h" -//----------------------------------------------------------------------------- -HOSTALLOW::HOSTALLOW() -{ - -} -//----------------------------------------------------------------------------- -int HOSTALLOW::ParseHosts(const char * str, int hostsType) -{ -/* -ðÒÏÉÚ×ÏÄÉÍ ÒÁÚÂÏÒ ÓÔÒÏËÉ ×ÉÄÁ host host host ... -ÇÄÅ host ÍÏÖÅÔ ÉÍÅÔØ ×ÉÄ a.b.c.d ÉÌÉ a.b.c.d/e -ÉÌÉ all. -ÐÒÉÞÅÍ × ÓÌÕÞÁÅ ÓÅÔÉ ÍÁÓËÁ É ÁÄÒÅÓ ÄÏÌÖÎÙ ÂÙÔØ -ÓÏÏÔ×ÅÔÓÔ×ÕÀÝÉÍÉ ÄÒÕÇ ÄÒÕÇÕ. - -òÅÚÕÌØÔÁÔÙ ÚÁÎÏÓÉÍ × ÓÏÏÔ×ÅÔÓÔ×ÕÀÝÉÊ ÓÐÉÓÏË - * */ - -int len; -char *s; -char * tok; -uint32_t ip; -uint32_t mask; -//INETADDR inetAddr; - -if (strcasecmp(str, "all") == 0) - { - if (hostsType == hostsAllow) - hostAllowList.push_back(INETADDR()); - else - hostDenyList.push_back(INETADDR()); - return 0; - } -else - { - len = strlen(str); - - s = new char[len + 1]; - - strcpy(s, str); - - tok = strtok(s, " "); - - while (tok) - { - if (ParseIPMask(tok, &ip, &mask) != 0) - { - return -1; - delete[] s; - } - //printfd(__FILE__, "ParseHosts tok %s\n", tok); - tok = strtok(NULL, " "); - if (hostsType == hostsAllow) - { - //printfd(__FILE__, "ParseHosts APPEND allow %X %X\n", ip, mask); - hostAllowList.push_back(INETADDR(ip, mask)); - } - else - { - //printfd(__FILE__, "ParseHosts APPEND deny %X %X\n", ip, mask); - hostDenyList.push_back(INETADDR(ip, mask)); - } - } - } - -delete[] s; -return 0; -} -//----------------------------------------------------------------------------- -int HOSTALLOW::ParseIPMask(const char * s, uint32_t * ip, uint32_t * mask) -{ -/* -òÁÚÂÏÒ ÓÔÒÏËÉ ×ÉÄÁ a.b.c.d/e ÉÌÉ a.b.c.d - -123.123.123.123/30 - * */ -int len; -char * host; - -int i = 0, msk; - -len = strlen(s); -host = new char[len + 1]; - -while (s[i] != 0 && s[i] != '/') - { - host[i] = s[i]; - i++; - } - -host[i] = 0; - -if (inet_addr(host) == INADDR_NONE) - { - delete[] host; - sprintf(errMsg, "Icorrect IP address %s", host); - return -1; - } - -*ip = inet_addr(host); - -char *res; - -if (s[i] == '/') - { - msk = strtol(&s[i+1], &res, 10); - if (*res != 0) - { - sprintf(errMsg, "Icorrect mask %s", &s[i+1]); - delete[] host; - return -1; - } - - if (msk < 0 || msk > 32) - { - sprintf(errMsg, "Icorrect mask %s", &s[i+1]); - delete[] host; - *mask = 0; - return 0; - } - - uint32_t m = 0; - m = htonl(0xFFffFFff<<(32 - msk)); - - *mask = m; - } -else - { - *mask = 0xFFffFFff; - } - -if ((*ip & *mask) != *ip) - { - sprintf(errMsg, "Address does'n match mask.\n"); - delete[] host; - return -1; - } - -delete[] host; -return 0; -} -//----------------------------------------------------------------------------- -int HOSTALLOW::ParseOrder(const char * str) -{ -/* -ÐÒÏÉÚ×ÏÄÉÍ ÒÁÚÂÏÒ ÓÔÒÏËÉ ×ÉÄÁ allow deny ÉÌÉ deny allow - */ - -if (strcasecmp(str, "allow,deny") == 0) - { - order = orderAllow; - return 0; - } - -if (strcasecmp(str, "deny,allow") == 0) - { - order = orderDeny; - return 0; - } - -sprintf(errMsg, "Parameter \'order\' must be \'allow,deny\' or \'deny,allow\'"); -return -1; -} -//----------------------------------------------------------------------------- -int HOSTALLOW::GetError() -{ -/* -÷ÏÚ×ÒÁÝÁÅÍ ËÏÄ ÏÛÉÂËÉ É ÓÂÒÁÓÙ×ÁÅÍ ÅÅ. - * */ -return 0; -} -//----------------------------------------------------------------------------- -bool HOSTALLOW::HostAllowed(uint32_t ip) -{ -/* -ðÒÏ×ÅÒÑÅÍ Ñ×ÌÑÅÔÓÑ ÌÉ éð ÒÁÚÒÅÛÅÎÎÙÍ ÉÌÉ ÎÅÔ - * */ - -if (order == orderDeny) - { - if (IsHostInDeniedList(ip)) - { - return false; - } - - if (IsHostInAllowedList(ip)) - { - return true; - } - } -else - { - if (IsHostInAllowedList(ip)) - { - return true; - } - - if (IsHostInDeniedList(ip)) - { - return false; - } - } - -return false; -} -//----------------------------------------------------------------------------- -int HOSTALLOW::IsIPInSubnet(uint32_t checkedIP, INETADDR &ia) -{ -//uint32_t checkedIP; -if ((ia.mask & checkedIP) == (ia.ip)) - return true; -return false; -} -//----------------------------------------------------------------------------- -bool HOSTALLOW::IsHostInAllowedList(uint32_t ip) -{ -/* -îÁÈÏÄÉÔÓÑ ÌÉ éð × ÓÐÉÓËÅ ÒÁÚÒÅÛÅÎÎÙÈ - * */ -list::iterator li; - -li = hostAllowList.begin(); - -while(li != hostAllowList.end()) - { - if (IsIPInSubnet(ip, *li)) - return true; - } - -return false; -} -//----------------------------------------------------------------------------- -bool HOSTALLOW::IsHostInDeniedList(uint32_t ip) -{ -/* -îÁÈÏÄÉÔÓÑ ÌÉ éð × ÓÐÉÓËÅ ÚÁÐÒÅÝÅÎÎÙÈ - * */ -list::iterator li; - -li = hostDenyList.begin(); - -while(li != hostDenyList.end()) - { - if (IsIPInSubnet(ip, *li)) - return true; - } - -return false; -} -//----------------------------------------------------------------------------- -const char * HOSTALLOW::GetStrError() -{ -/* -÷ÏÚ×ÒÁÝÁÅÍ ÔÅËÓÔÏ×ÏÅ ÏÐÉÓÁÎÉÅ ÏÛÉÂËÉ. - * */ -return errMsg; -} -//----------------------------------------------------------------------------- - diff --git a/stglibs/hostallow.lib/hostallow.h b/stglibs/hostallow.lib/hostallow.h deleted file mode 100644 index 034cdb3f..00000000 --- a/stglibs/hostallow.lib/hostallow.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Date: 27.10.2002 - */ - -/* - * Author : Boris Mikhailenko - */ - - -#ifndef HOSTALLOW_H -#define HOSTALLOW_H - -#include "os_int.h" - -#include - -using namespace std; - -#define HA_ERR_MSG_LEN (255) -//----------------------------------------------------------------------------- -enum ORDER -{ - orderAllow = 0, - orderDeny -}; -//----------------------------------------------------------------------------- -enum -{ - hostsAllow = 0, - hostsDeny -}; -//----------------------------------------------------------------------------- -struct INETADDR -{ - INETADDR(uint32_t i, uint8_t m) {ip = i; mask = m;}; - INETADDR() {ip = 0; mask = 0;}; - uint32_t ip; - uint8_t mask; -}; -//----------------------------------------------------------------------------- -class HOSTALLOW -{ -public: - HOSTALLOW(); - int ParseHosts(const char *, int hostsType); - int ParseOrder(const char *); - int GetError(); - bool HostAllowed(uint32_t ip); - const char * GetStrError(); - -private: - int ParseIPMask(const char * s, uint32_t * ip, uint32_t * mask); - bool IsHostInDeniedList(uint32_t ip); - bool IsHostInAllowedList(uint32_t ip); - //int IsIPInSubnet(INETADDR &ia); - int IsIPInSubnet(uint32_t checkedIP, INETADDR &ia); - list hostAllowList; - list hostDenyList; - char errMsg[HA_ERR_MSG_LEN]; - int order; - char src[16 + 1]; - char dst[16 + 1]; - -}; -//----------------------------------------------------------------------------- - -#endif