diff --git a/.gitattributes b/.gitattributes index 06d1dbd..251020b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,30 +11,6 @@ /configure.in -text /html.css -text /install-sh -text -libopm/.cvsignore -text -libopm/LICENSE -text -libopm/Makefile.in -text -libopm/README -text -libopm/compat.c -text -libopm/compat.h -text -libopm/config.c -text -libopm/config.h -text -libopm/inet.c -text -libopm/inet.h -text -libopm/libopm.c -text -libopm/libopm.h -text -libopm/libopm.vcproj -text -libopm/malloc.c -text -libopm/malloc.h -text -libopm/opm.h -text -libopm/opm_common.h -text -libopm/opm_error.h -text -libopm/opm_types.h -text -libopm/opmlist.c -text -libopm/opmlist.h -text -libopm/proxy.c -text -libopm/proxy.h -text -libopm/test.c -text /modconfig.h.in -text /modconfigwin32.h -text /opsb.Settings -text diff --git a/libopm/.cvsignore b/libopm/.cvsignore deleted file mode 100644 index b00cfec..0000000 --- a/libopm/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -*.sw[op] -Makefile -*.lo -*.la -setup.h -stamp-h* -.deps -.libs -test -test_debug diff --git a/libopm/LICENSE b/libopm/LICENSE deleted file mode 100644 index a43ea21..0000000 --- a/libopm/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - Appendix: How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/libopm/Makefile.in b/libopm/Makefile.in deleted file mode 100644 index ee2ac15..0000000 --- a/libopm/Makefile.in +++ /dev/null @@ -1,45 +0,0 @@ -#Neostats Module Makefile! -CC = @CC@ -CFLAGS = @CFLAGS@ -LDFLAGS = @LDFLAGS@ -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_DATA = @INSTALL_DATA@ -DIRECTORY = @DIRINST@/dl/ -INCLUDES = -I. -I.. -I@DIRINST@/include/ - -SRCS= compat.c config.c inet.c libopm.c opmlist.c malloc.c proxy.c -OBJS= ${SRCS:.c=.o} - -TARGET= libopm.a -DOCS= - -all: libopm.a - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $< - - -libopm.a: $(OBJS) - ar cru $(TARGET) ${OBJS} - ranlib $(TARGET) - -clean: - /bin/rm -rf $(TARGET) *.o Makefile - -install: - -dist: - -$(OBJS): Makefile -compat.o: compat.c ../modconfig.h compat.h opm.h opm_common.h -config.o: config.c ../modconfig.h malloc.h config.h libopm.h inet.h \ - opm_common.h opm.h opm_error.h opm_types.h opmlist.h -inet.o: inet.c ../modconfig.h inet.h opm.h opm_common.h -libopm.o: libopm.c ../modconfig.h config.h libopm.h inet.h opm_common.h \ - opm.h malloc.h opm_error.h opm_types.h opmlist.h proxy.h -list.o: opmlist.c ../modconfig.h opm_common.h opmlist.h malloc.h opm.h -malloc.o: malloc.c ../modconfig.h malloc.h opm.h opm_common.h -proxy.o: proxy.c ../modconfig.h inet.h compat.h config.h libopm.h \ - opm_common.h opm.h proxy.h opm_types.h opm_error.h - diff --git a/libopm/README b/libopm/README deleted file mode 100644 index 9ee5cba..0000000 --- a/libopm/README +++ /dev/null @@ -1,11 +0,0 @@ -This is libopm, a open proxy detection library written by Erik Fears and the -Blitzed team. (www.blitzed.org, strtok@blitzed.org) -More information about this library can be found at www.blitzed.org (This -library powers BOPM, blitzed version of the open proxy monitoring library.) - -There are a few modifications to this library to enable it to plug in -cleaning to OPSB, but the majority of credit must be given to them. - -If your interested in using this library in your software, checked out the -blitzed webpages for more informationa and documentation. - diff --git a/libopm/compat.c b/libopm/compat.c deleted file mode 100644 index e1a3478..0000000 --- a/libopm/compat.c +++ /dev/null @@ -1,77 +0,0 @@ -/* vim: set shiftwidth=3 softtabstop=3 expandtab: */ - -/* - * Copyright (C) 2002 Andy Smith - * - * 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 - */ - -#ifdef WIN32 -#include "modconfigwin32.h" -#include -#else -#include "modconfig.h" -#endif - -#include - -#ifdef STDC_HEADERS -# include -#endif - -#ifndef HAVE_INET_ATON -#ifndef WIN32 -# include -#endif -#endif - -#include "compat.h" -#include "opm.h" - -RCSID("$Id$"); - -#ifndef HAVE_INET_ATON -/* - * An implementation of inet_aton for those systems that don't have it - * (Solaris, ...) - */ -int libopm_inet_aton(const char *cp, struct in_addr *inp) -{ - unsigned int a1, a2, a3, a4; - unsigned long ret; - - if (strcmp(cp, "255.255.255.255") == 0) { - inp->s_addr = (unsigned) -1; - return 0; - } - - if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 || - a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) { - return 0; - } - - ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4; - - inp->s_addr = htonl(ret); - - if (inp->s_addr == (unsigned) -1) { - return 0; - } - return 1; -} -#endif diff --git a/libopm/compat.h b/libopm/compat.h deleted file mode 100644 index 71b2a54..0000000 --- a/libopm/compat.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef COMPAT_H -#define COMPAT_H - -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - -#ifndef HAVE_INET_ATON -#undef inet_aton -#define inet_aton libopm_inet_aton -extern int libopm_inet_aton(const char *cp, struct in_addr *inp); -#endif - -#ifndef HAVE_SNPRINTF -#undef snprintf -#define snprintf ircsnprintf -#endif - -#ifndef HAVE_VSNPRINTF -#undef vsnprintf -#define vsnprintf ircvsnprintf -#endif - -#ifndef HAVE_INET_PTON -#undef inet_pton -#define inet_pton libopm_inet_pton -#endif - -#endif diff --git a/libopm/config.c b/libopm/config.c deleted file mode 100644 index 345469b..0000000 --- a/libopm/config.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (C) 2002 Erik Fears - * - * 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. - * - * - */ - -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#include "malloc.h" -#include "config.h" -#include "inet.h" -#include "opm_error.h" -#include "opm_types.h" -#include "opm_common.h" -#include "opmlist.h" - -#ifdef STDC_HEADERS -# include -#endif - -RCSID("$Id$"); - -static OPM_CONFIG_HASH_T HASH[] = { - {OPM_CONFIG_FD_LIMIT, OPM_TYPE_INT}, - {OPM_CONFIG_BIND_IP , OPM_TYPE_ADDRESS}, - {OPM_CONFIG_DNSBL_HOST, OPM_TYPE_STRING}, - {OPM_CONFIG_TARGET_STRING, OPM_TYPE_STRINGLIST}, - {OPM_CONFIG_SCAN_IP, OPM_TYPE_STRING}, - {OPM_CONFIG_SCAN_PORT, OPM_TYPE_INT}, - {OPM_CONFIG_MAX_READ, OPM_TYPE_INT}, - {OPM_CONFIG_TIMEOUT, OPM_TYPE_INT}, -}; - - -/* config_create - * - * Create an OPM_CONFIG_T struct, set default values and return it - * - * Parameters: - * None; - * - * Return: - * Pointer to allocated OPM_CONFIG_T struct - */ - -OPM_CONFIG_T *libopm_config_create() -{ - int num, i; - OPM_CONFIG_T *ret; - - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - - ret = MyMalloc(sizeof(OPM_CONFIG_T)); - ret->vars = MyMalloc(sizeof(void *) * num); - - - /* Set default config items. This in the future would be much better - if it could set realistic defaults for each individual config item. - - OPM_TYPE_INT = 0 - OPM_TYPE_STRING = "" - OPM_TYPE_ADDRESS = 0.0.0.0 - OPM_TYPE_STRINGLIST = empty list - */ - - for(i = 0; i < num; i++) - { - switch(libopm_config_gettype(i)) - { - case OPM_TYPE_INT: - ret->vars[i] = MyMalloc(sizeof(int)); - *(int *) ret->vars[i] = 0; - break; - - case OPM_TYPE_STRING: - (char *) ret->vars[i] = strdup(""); - break; - - case OPM_TYPE_ADDRESS: - (opm_sockaddr *) ret->vars[i] = MyMalloc(sizeof(opm_sockaddr)); - memset((opm_sockaddr *) ret->vars[i], 0, sizeof(opm_sockaddr)); - break; - - case OPM_TYPE_STRINGLIST: - (OPM_LIST_T *) ret->vars[i] = libopm_list_create(); - break; - default: - ret->vars[i] = NULL; - } - } - return ret; -} - - - - -/* config_free - * - * Free config structure and clean up - * - * Parameters: - * config: Structure to free/cleanup - * - * Return: - * None - */ - -void libopm_config_free(OPM_CONFIG_T *config) -{ - int num, i; - OPM_NODE_T *p, *next; - OPM_LIST_T *list; - - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - - for(i = 0; i < num; i++) - { - if(config->vars[i] == NULL) - continue; - - switch(libopm_config_gettype(i)) - { - case OPM_TYPE_STRINGLIST: - list = (OPM_LIST_T *) config->vars[i]; - LIST_FOREACH_SAFE(p, next, list->head) - { - MyFree(p->data); - MyFree(p); - } - break; - default: - MyFree(config->vars[i]); - break; - } - } - - MyFree(config->vars); - MyFree(config); -} - - - - -/* config_set - * - * Set configuration options on config struct. - * - * Parameters: - * config: Config struct to set parameters on - * key: Variable within the struct to set - * value: Address of value to set - * - * Return: - * 1: Variable was set - * 0: Some error occured - */ - -OPM_ERR_T libopm_config_set(OPM_CONFIG_T *config, int key, void *value) -{ - - int num; - OPM_NODE_T *node; - - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - - if(key < 0 || key >= num) - return OPM_ERR_BADKEY; /* Return appropriate error code eventually */ - - switch(libopm_config_gettype(key)) - { - case OPM_TYPE_STRING: - if((char *) config->vars[key] != NULL) - MyFree(config->vars[key]); - (char *) config->vars[key] = strdup((char *) value); - break; - - case OPM_TYPE_INT: - *(int *) config->vars[key] = *(int *) value; - break; - - case OPM_TYPE_ADDRESS: - if( inet_pton(AF_INET, (char *) value, &( ((opm_sockaddr *)config->vars[key])->sa4.sin_addr)) - <= 0) - return OPM_ERR_BADVALUE; /* return appropriate err code */ - break; - - case OPM_TYPE_STRINGLIST: - node = libopm_node_create(strdup((char *) value)); - libopm_list_add((OPM_LIST_T *) config->vars[key], node); - break; - - default: - return OPM_ERR_BADKEY; /* return appropriate err code */ - - } - - return OPM_SUCCESS; - -} - - - - -/* config_gettype - * - * Get type of key. - * - * Parameters: - * key: Key to get type of. - * - * Return: - * TYPE_? of key - */ - -int libopm_config_gettype(int key) -{ - int num, i; - - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - - for(i = 0; i < num; i++) - if(HASH[i].key == key) - return HASH[i].type; - - return 0; -} - -/* config - * - * Retrieve a specific config variable from - * an OPM_CONFIG_T struct. This is basically a - * wrapper to extracting the variable from the - * array. - * - * Parameters: - * config: Config struct to extract from - * key: Value to extract - * - * Return: - * -ADDRESS- to extracted value in array. This address - * will have to be cast on the return end to be any use. - */ - -void *libopm_config(OPM_CONFIG_T *config, int key) -{ - return config->vars[key]; -} diff --git a/libopm/config.h b/libopm/config.h deleted file mode 100644 index 2b6f0c6..0000000 --- a/libopm/config.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#include "libopm.h" - -typedef struct _opm_config_hash OPM_CONFIG_HASH_T; - -struct _opm_config_hash { - int key; - int type; -}; - -void libopm_config_free(OPM_CONFIG_T *); -void *libopm_config(OPM_CONFIG_T *, int); -int libopm_config_gettype(int); -OPM_CONFIG_T *libopm_config_create(void); -OPM_ERR_T libopm_config_set(OPM_CONFIG_T *, int , void *); - - -#endif /* CONFIG_H */ diff --git a/libopm/inet.c b/libopm/inet.c deleted file mode 100644 index e358cd9..0000000 --- a/libopm/inet.c +++ /dev/null @@ -1,542 +0,0 @@ -/* -Copyright (C) 2002 by the past and present ircd coders, and others. - -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. - -*/ - -/* - * This code is borrowed from ircd-hybrid version 7 - * -TimeMr14C - */ - -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#include -#include -#include -#if STDC_HEADERS -# include -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif -#include -#ifdef WIN32 -#include -#else -#include -#include -#include -#endif - -#include "inet.h" -#include "opm.h" - -#ifndef INADDRSZ -#define INADDRSZ 4 -#endif - -#ifdef IPV6 -#ifndef IN6ADDRSZ -#define IN6ADDRSZ 16 -#endif -#endif - - -#ifndef INT16SZ -#define INT16SZ 2 -#endif - -#ifdef IPV6 -#define HOSTIPLEN 53 -#else -#define HOSTIPLEN 15 -#endif - -RCSID("$Id$"); - -extern const unsigned char ToLowerTab[]; -#define ToLower(c) (ToLowerTab[(unsigned char)(c)]) - -/* - * From: Thomas Helvey - */ -#if 0 -static const char *IpQuadTab[] = { - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", - "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", - "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", - "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", - "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", - "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", - "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", - "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", - "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", - "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", - "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", - "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", - "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", - "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", - "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", - "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", - "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", - "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", - "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", - "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", - "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", - "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", - "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", - "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", - "250", "251", "252", "253", "254", "255" -}; -#endif - -/* - * inetntoa - in_addr to string - * changed name to remove collision possibility and - * so behaviour is guaranteed to take a pointer arg. - * -avalon 23/11/92 - * inet_ntoa -- returned the dotted notation of a given - * internet number - * argv 11/90). - * inet_ntoa -- its broken on some Ultrix/Dynix too. -avalon - * - * XXX - Again not used anywhere? - * -grifferz - */ - -#if 0 -static char *inetntoa(char *in) -{ - static char buf[16]; - register char *bufptr = buf; - register const unsigned char *a = (const unsigned char *) in; - register const char *n; - - n = IpQuadTab[*a++]; - while (*n) - *bufptr++ = *n++; - *bufptr++ = '.'; - n = IpQuadTab[*a++]; - while (*n) - *bufptr++ = *n++; - *bufptr++ = '.'; - n = IpQuadTab[*a++]; - while (*n) - *bufptr++ = *n++; - *bufptr++ = '.'; - n = IpQuadTab[*a]; - while (*n) - *bufptr++ = *n++; - *bufptr = '\0'; - return buf; -} -#endif - -/* - * Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -/* - * XXX - this does not seem to be used anywhere currently. - * -grifferz - */ -#if 0 -static const char *inet_ntop4(const u_char *src, char *dst, unsigned int size); -#endif - -#ifdef IPV6 -static const char *inet_ntop6(const u_char *src, char *dst, unsigned int size); -#endif - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - * - * XXX - this does not seem to be used anywhere currently. - * -grifferz - */ -#if 0 -static const char *inet_ntop4(const unsigned char *src, char *dst, unsigned int size) -{ - if (size < 15) - return NULL; - return strcpy(dst, inetntoa((char *) src)); -} -#endif - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -#ifdef IPV6 -static const char *inet_ntop6(const unsigned char *src, char *dst, unsigned int size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; - struct { - int base, len; - } best, cur; - u_int words[IN6ADDRSZ / INT16SZ]; - int i; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < IN6ADDRSZ; i += 2) - words[i / 2] = (src[i] << 8) | src[i + 1]; - best.base = -1; - cur.base = -1; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen(tp); - break; - } - tp += sprintf(tp, "%x", words[i]); - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) - *tp++ = ':'; - - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - - if ((tp - tmp) > size) { - return (NULL); - } - return strcpy(dst, tmp); -} -#endif - -#if 0 - -/* - * This code doesn't seem to be used anywhere currently? - * -grifferz - */ - -/* char * - * inetntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char *inetntop(int af, const void *src, char *dst, unsigned int size) -{ - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); -#ifdef IPV6 - case AF_INET6: - if (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *) src) || - IN6_IS_ADDR_V4COMPAT((const struct in6_addr *) src)) - return (inet_ntop4 - ((unsigned char *) &((struct in6_addr *) src)->s6_addr[12], dst, size)); - else - return (inet_ntop6(src, dst, size)); - -#endif - default: - return (NULL); - } - /* NOTREACHED */ -} -#endif - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ - -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ - -#ifndef HAVE_INET_PTON - -static int inet_pton4(src, dst) - const char *src; - unsigned char *dst; -{ -int saw_digit, octets, ch; -unsigned char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - - if (ch >= '0' && ch <= '9') { -unsigned int new = *tp * 10 + (ch - '0'); - - if (new > 255) - return (0); - *tp = new; - if (!saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - memcpy(dst, tmp, INADDRSZ); - return (1); -} - -#ifdef IPV6 -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ - -static int inet_pton6(src, dst) - const char *src; - unsigned char *dst; -{ -static const char xdigits[] = "0123456789abcdef"; -unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; -const char *curtok; -int ch, saw_xdigit; -unsigned int val; - - tp = memset(tmp, '\0', IN6ADDRSZ); - endp = tp + IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - saw_xdigit = 0; - val = 0; - while ((ch = ToLower(*src++)) != '\0') { -const char *pch; - - pch = strchr(xdigits, ch); - if (pch != NULL) { - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } else if (*src == '\0') { - return (0); - } - if (tp + INT16SZ > endp) - return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } - - if (*src != '\0' && ch == '.') { - if (((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - } else - continue; - return (0); - } - if (saw_xdigit) { - if (tp + INT16SZ > endp) - return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ -const int n = tp - colonp; -int i; - - if (tp == endp) - return (0); - for (i = 1; i <= n; i++) { - endp[-i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, IN6ADDRSZ); - return (1); -} -#endif /* IPv6 */ - -int inet_pton(af, src, dst) - int af; - const char *src; - void *dst; -{ - switch (af) { - case AF_INET: - return (inet_pton4(src, dst)); -#ifdef IPV6 - case AF_INET6: - /* Somebody might have passed as an IPv4 address this is sick but it works */ - if (inet_pton4(src, dst)) { -char tmp[HOSTIPLEN]; - sprintf(tmp, "::ffff:%s", src); - return (inet_pton6(tmp, dst)); - } else - return (inet_pton6(src, dst)); -#endif /* IPv6 */ - default: - return (-1); - } - /* NOTREACHED */ -} - -#endif diff --git a/libopm/inet.h b/libopm/inet.h deleted file mode 100644 index fe9fcbc..0000000 --- a/libopm/inet.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef INET_H -#define INET_H - -#include -#ifdef WIN32 -#include -#else -#include -#include -#include -#include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#include - -#ifdef HAVE_SYS_POLL_H -# include -#endif - -#ifndef AF_INET6 -# define AF_INET6 10 -#endif - -typedef struct _opm_sockaddr opm_sockaddr; -typedef struct _opm_inaddr opm_inaddr; - -struct _opm_sockaddr { - struct sockaddr_in sa4; -}; - -struct _opm_inaddr { - struct in_addr in4; -}; - -#ifndef HAVE_INET_PTON -extern int inet_pton(int, const char *, void *); -#endif -extern const char *inetntop(int, const void *, char *, unsigned int); -extern struct hostent *opm_gethostbyname(const char *); - - -#endif /* INET_H */ diff --git a/libopm/libopm.c b/libopm/libopm.c deleted file mode 100644 index 035da29..0000000 --- a/libopm/libopm.c +++ /dev/null @@ -1,1577 +0,0 @@ -/* - * Copyright (C) 2002-2003 Erik Fears - * - * 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. - * - * - */ - -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#include -#include -#include "config.h" -#include "libopm.h" -#include "malloc.h" -#include "opm_error.h" -#include "opm_types.h" -#include "opm_common.h" -#include "opmlist.h" -#include "inet.h" -#include "proxy.h" - -#include -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_STRING_H -# include -#endif - - - -RCSID("$Id$"); - -static OPM_PROTOCOL_CONFIG_T *libopm_protocol_config_create(void); -static void libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *); - -/* - * XXX - does not appear to be used anywhere? - * -grifferz - */ -#if 0 -static OPM_PROTOCOL_T *libopm_protocol_create(void); -static void libopm_protocol_free(OPM_PROTOCOL_T *); -#endif - -static OPM_SCAN_T *libopm_scan_create(OPM_T *, OPM_REMOTE_T *); -static void libopm_scan_free(OPM_SCAN_T *); - -static OPM_CONNECTION_T *libopm_connection_create(void); -static void libopm_connection_free(OPM_CONNECTION_T *); - -static void libopm_check_establish(OPM_T *); -static void libopm_check_poll(OPM_T *); -static void libopm_check_closed(OPM_T *); -static void libopm_check_queue(OPM_T *); - -static void libopm_do_connect(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -static void libopm_do_readready(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -static void libopm_do_writeready(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -static void libopm_do_hup(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -static void libopm_do_read(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -static void libopm_do_openproxy(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); - -static void libopm_do_callback(OPM_T *, OPM_REMOTE_T *, int, int); - -static OPM_REMOTE_T *libopm_setup_remote(OPM_REMOTE_T *, OPM_CONNECTION_T *); - - -/* OPM_PROTOCOLS hash - * - * OPM_PPROTOCOLS hashes the protocol types (int) to functions - * which handle the protocol (sending/receiving protocol specific - * data). - * - */ - -static OPM_PROTOCOL_T OPM_PROTOCOLS[] = { - {OPM_TYPE_HTTP, libopm_proxy_http_write, NULL}, - {OPM_TYPE_SOCKS4, libopm_proxy_socks4_write, NULL}, - {OPM_TYPE_SOCKS5, libopm_proxy_socks5_write, NULL}, - {OPM_TYPE_ROUTER, libopm_proxy_router_write, NULL}, - {OPM_TYPE_WINGATE, libopm_proxy_wingate_write, NULL}, - {OPM_TYPE_HTTPPOST, libopm_proxy_httppost_write, NULL} -}; - - - - -/* opm_create - * - * Initialize a new scanner and return a pointer to it. - * - * Parameters: - * None - * - * Return - * Pointer to new OPM_T (scanner) - */ - -OPM_T *opm_create() -{ - int i; - OPM_T *ret; - - ret = MyMalloc(sizeof *ret); - - ret->config = libopm_config_create(); - ret->scans = libopm_list_create(); - ret->queue = libopm_list_create(); - ret->protocols = libopm_list_create(); - ret->fd_use = 0; - - /* Setup callbacks */ - ret->callbacks = MyMalloc(sizeof(OPM_CALLBACK_T) * CBLEN); - for(i = 0; i < CBLEN; i++) - { - ret->callbacks[i].func = NULL; - ret->callbacks[i].data = NULL; - } - - return ret; -} - - - - -/* opm_remote_create - * - * Create OPM_REMOTE_T struct, fill it with neccessary - * default values and return it to the client. - * - * Parameters: - * ip: IP of remote host - * - * Return: - * Address of OPM_REMOTE_T created - * - */ - -OPM_REMOTE_T *opm_remote_create(const char *ip) -{ - OPM_REMOTE_T *ret; - - - ret = MyMalloc(sizeof *ret); - - /* Do initializations */ - if(ip == NULL) - return NULL; - - ret->ip = (char*) strdup(ip); /* replace with custom strdup function */ - - ret->port = 0; - ret->protocol = 0; - ret->bytes_read = 0; - - ret->data = NULL; - - ret->protocols = libopm_list_create(); /* setup protocol list */ - - return ret; -} - - - -/* opm_remote_free - * - * Free OPM_REMOTE_T struct and cleanup - * - * Parameters: - * remote: Struct to free - * - * Return: - * None - */ - -void opm_remote_free(OPM_REMOTE_T *remote) -{ - - OPM_NODE_T *p, *next; - OPM_PROTOCOL_CONFIG_T *ppc; - - MyFree(remote->ip); - - LIST_FOREACH_SAFE(p, next, remote->protocols->head) - { - ppc = (OPM_PROTOCOL_CONFIG_T *) p->data; - - libopm_protocol_config_free(ppc); - libopm_list_remove(remote->protocols, p); - libopm_node_free(p); - } - - libopm_list_free(remote->protocols); - - MyFree(remote); -} - - - - -/* opm_callback - * Register scanner level callback - * - * Parameters - * scanner: scanner struct - * type: callback type - * Return: - * Error code - */ - -OPM_ERR_T opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_FUNC *function, void *data) -{ - if(type < 0 || type >= (CBLEN + 1)) - return OPM_ERR_CBNOTFOUND; - - scanner->callbacks[type].func = function; - scanner->callbacks[type].data = data; - - return OPM_SUCCESS; -} - - - - -/* opm_free - * - * Free OPM_T (scanner) and cleanup - * - * Parameters: - * scanner: Address of OPM_T to cleanup - * - * Return: - * None - */ - -void opm_free(OPM_T *scanner) -{ - OPM_NODE_T *p, *next; - OPM_PROTOCOL_CONFIG_T *ppc; - OPM_SCAN_T *scan; - - libopm_config_free(scanner->config); - - LIST_FOREACH_SAFE(p, next, scanner->protocols->head) - { - ppc = (OPM_PROTOCOL_CONFIG_T *) p->data; - - libopm_protocol_config_free(ppc); - libopm_list_remove(scanner->protocols, p); - libopm_node_free(p); - } - - LIST_FOREACH_SAFE(p, next, scanner->scans->head) - { - scan = (OPM_SCAN_T *) p->data; - libopm_scan_free(scan); - libopm_list_remove(scanner->scans, p); - libopm_node_free(p); - } - - LIST_FOREACH_SAFE(p, next, scanner->queue->head) - { - scan = (OPM_SCAN_T *) p->data; - libopm_scan_free(scan); - libopm_list_remove(scanner->queue, p); - libopm_node_free(p); - } - - libopm_list_free(scanner->protocols); - libopm_list_free(scanner->scans); - libopm_list_free(scanner->queue); - - MyFree(scanner->callbacks); - MyFree(scanner); -} - - - - -/* opm_config - * - * Wrapper to config_set. Set configuration variables - * on the config struct. - * - * Parameters: - * scanner: OPM_T struct the config struct resides in - * key: Variable within the config struct to set - * value: Address of value to set variable (key) to - * - * Return: - * OPM_ERR_T containing error code - */ - -OPM_ERR_T opm_config(OPM_T *scanner, int key, void *value) -{ - return libopm_config_set((scanner->config), key, value); -} - - - - -/* opm_addtype - * - * Add a proxy type and port to the list of protocols - * a scanner will use. - * - * Parameters: - * scanner: pointer to scanner struct - * type: type of proxy to scan (used in hashing to the functions) - * port: port this specific type/protocol will scan on - * Return: - * OPM_SUCCESS: Successful protocol add - * OPM_ERR_BADPROTOCOL: Protocol is unknown - */ - -OPM_ERR_T opm_addtype(OPM_T *scanner, int type, unsigned short int port) -{ - unsigned int i; - - OPM_NODE_T *node; - OPM_PROTOCOL_CONFIG_T *protocol_config; - - for(i = 0; i < sizeof(OPM_PROTOCOLS) / sizeof(OPM_PROTOCOL_T); i++) - { - if(type == OPM_PROTOCOLS[i].type) - { - protocol_config = libopm_protocol_config_create(); - - protocol_config->type = &OPM_PROTOCOLS[i]; - protocol_config->port = port; - - node = libopm_node_create(protocol_config); - libopm_list_add(scanner->protocols, node); - - return OPM_SUCCESS; - - } - } - return OPM_ERR_BADPROTOCOL; -} - - - -/* opm_remote_addtype - * - * Add a proxy type and port to the list of protocols - * a scanner will use. - * - * Parameters: - * remote: pointer to scanner struct - * type: type of proxy to scan (used in hashing to the functions) - * port: port this specific type/protocol will scan on - * Return: - * OPM_SUCCESS: Successful protocol add - * OPM_ERR_BADPROTOCOL: Protocol is unknown - */ - -OPM_ERR_T opm_remote_addtype(OPM_REMOTE_T *remote, int type, unsigned short int port) -{ - unsigned int i; - - OPM_NODE_T *node; - OPM_PROTOCOL_CONFIG_T *protocol_config; - - for(i = 0; i < sizeof(OPM_PROTOCOLS) / sizeof(OPM_PROTOCOL_T); i++) - { - if(type == OPM_PROTOCOLS[i].type) - { - protocol_config = libopm_protocol_config_create(); - - protocol_config->type = &OPM_PROTOCOLS[i]; - protocol_config->port = port; - - node = libopm_node_create(protocol_config); - libopm_list_add(remote->protocols, node); - - return OPM_SUCCESS; - } - } - return OPM_ERR_BADPROTOCOL; -} - - - - -/* libopm_protocol_create - * - * Create OPM_PROTOCOL_T struct. - * - * Parameters: - * None - * Return: - * Pointer to new struct - * - * XXX - does not appear to be used anywhere? - * -grifferz - */ - -#if 0 -static OPM_PROTOCOL_T *libopm_protocol_create(void) -{ - OPM_PROTOCOL_T *ret; - ret = MyMalloc(sizeof(OPM_PROTOCOL_T)); - - ret->type = 0; - ret->write_function = NULL; - ret->read_function = NULL; - - return ret; -} -#endif - - -/* libopm_protocol_free - * - * Free an OPM_PROTOCOL_T struct. Assume that if - * format is not NULL, it is pointed to dynamically - * allocated memory and free it. - * - * Parameters: - * protocol: struct to free - * - * Return: - * None - * - * XXX - apparently no longer used? - * -grifferz - */ - -#if 0 -static void libopm_protocol_free(OPM_PROTOCOL_T *protocol) -{ - MyFree(protocol); -} -#endif - - - -/* libopm_protocol_config_create - * - * Allocate and return address of a new OPM_PROTOCOL_CONFIG_T - * - * Parameters: - * None - * - * Return: - * Address of new OPM_PROTOCOL_CONFIG_T - */ - -static OPM_PROTOCOL_CONFIG_T *libopm_protocol_config_create(void) -{ - OPM_PROTOCOL_CONFIG_T *ret; - ret = MyMalloc(sizeof *ret); - - return ret; -} - - - - -/* protocol_config_free - * - * Free OPM_PROTOCOL_CONFIG_T struct - * - * Parameters: - * protocol: struct to free - * - * Return: - * None - */ - -static void libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *protocol) -{ - MyFree(protocol); -} - - - - -/* opm_scan - * - * Scan remote host. The opm_scan function takes an OPM_REMOTE_T - * struct, calculates the in_addr of the remote host, and creates - * a scan list based on protocols defined in the scanner. - * - * Parameters: - * scanner: Scanner to scan host on - * remote: OPM_REMOTE_T defining remote host - * - * Return: - * (to be written) - */ - -OPM_ERR_T opm_scan(OPM_T *scanner, OPM_REMOTE_T *remote) -{ - OPM_SCAN_T *scan; /* New scan for OPM_T */ - OPM_NODE_T *node; /* Node we'll add scan to - when we link it to scans */ - unsigned int fd_limit; - - fd_limit = *(int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); - - if(LIST_SIZE(scanner->protocols) == 0 && - LIST_SIZE(remote->protocols) == 0) - { - return OPM_ERR_NOPROTOCOLS; - } - - scan = libopm_scan_create(scanner, remote); - - if(inet_pton(AF_INET, remote->ip, &(scan->addr.sa4.sin_addr) ) <= 0) - { - libopm_scan_free(scan); - return OPM_ERR_BADADDR; - } - - node = libopm_node_create(scan); - libopm_list_add(scanner->queue, node); - - return OPM_SUCCESS; -} - - - - -/* opm_end - * - * End a scan prematurely. - * - * Parameters: - * scanner: Scanner to end scan on - * remote: Pointer to remote struct to search for and end - * - * Return: - * No return. OPM_CALLBACK_END will still be called as normal. - */ - -void opm_end(OPM_T *scanner, OPM_REMOTE_T *remote) -{ - OPM_NODE_T *node1, *node2, *next1, *next2; - - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - - /* End active scans */ - opm_endscan(scanner, remote); - - /* Secondly remove all traces of it in the queue. Once removed we have to call - OPM_CALLBACK_END */ - - LIST_FOREACH_SAFE(node1, next1, scanner->queue->head) - { - scan = (OPM_SCAN_T *) node1->data; - if(scan->remote == remote) - { - /* Free all connections */ - LIST_FOREACH_SAFE(node2, next2, scan->connections->head) - { - - conn = (OPM_CONNECTION_T *) node2->data; - - libopm_list_remove(scan->connections, node2); - libopm_connection_free(conn); - libopm_node_free(node2); - continue; - } - - /* OPM_CALLBACK_END because check_closed normally handles this */ - libopm_do_callback(scanner, scan->remote, OPM_CALLBACK_END, 0); - - /* Free up the scan */ - libopm_list_remove(scanner->queue, node1); - libopm_scan_free(scan); - libopm_node_free(node1); - } - } -} - - - - -/* opm_endscan - * - * End a scan prematurely. Only end non-queued scans. This is useful - * because it only checks the active scan list (saving time), where - * opm_end checks both the scan and the possibly large queue. - * - * Parameters: - * scanner: Scanner to end scan on - * remote: Pointer to remote struct to search for and end - * - * Return: - * No return. OPM_CALLBACK_END will still be called as normal. - */ - -void opm_endscan(OPM_T *scanner, OPM_REMOTE_T *remote) -{ - OPM_NODE_T *node1, *node2; - - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - - /* - First check to see if it's in the queue, if it is set all connections closed - Next cycle of libopm_check_closed will take care of the garbage and handle - OPM_CALLBACK_END - */ - LIST_FOREACH(node1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - - if(scan->remote == remote) - { - LIST_FOREACH(node2, scan->connections->head) - { - conn = (OPM_CONNECTION_T *) node2->data; - conn->state = OPM_STATE_CLOSED; - } - } - } -} - - - - -/* opm_active - - Return number of scans in a scanner left. - - Parameters: - scanner: Scanner to return active scans on - - Return: - Number of active scans, both queued and active. -*/ - -size_t opm_active(OPM_T *scanner) -{ - return LIST_SIZE(scanner->queue) + LIST_SIZE(scanner->scans); -} - - - -/* scan_create - * - * Create new OPM_SCAN_T struct - * - * Parameters: - * scanner: Scanner the scan is being created for. This - * is needed to get information on currently set - * protocols/config. - * - * remote: Remote host this scan will be scanning - * - * Return - * Address of new struct - */ -static OPM_SCAN_T *libopm_scan_create(OPM_T *scanner, OPM_REMOTE_T *remote) -{ - OPM_SCAN_T *ret; - OPM_CONNECTION_T *conn; - OPM_NODE_T *node, *p; - - ret = MyMalloc(sizeof *ret); - - ret->remote = remote; - ret->connections = libopm_list_create(); - - /* Setup list of connections, one for each protocol */ - LIST_FOREACH(p, scanner->protocols->head) - { - conn = libopm_connection_create(); - - conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; - conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; - - node = libopm_node_create(conn); - - libopm_list_add(ret->connections, node); - } - - /* Do the same for any specific protocols the remote struct might be configured - with */ - - LIST_FOREACH(p, remote->protocols->head) - { - conn = libopm_connection_create(); - - conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; - conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; - - node = libopm_node_create(conn); - - libopm_list_add(ret->connections, node); - } - - memset(&(ret->addr), 0, sizeof(opm_sockaddr)); - - return ret; -} - - - - -/* scan_free - * - * Free and cleanup OPM_SCAN_T struct - * - * Parametsr: - * scan: Scan struct to free - * - * Return: - * None - */ - -static void libopm_scan_free(OPM_SCAN_T *scan) -{ - OPM_NODE_T *p, *next; - OPM_CONNECTION_T *conn; - - LIST_FOREACH_SAFE(p, next, scan->connections->head) - { - conn = (OPM_CONNECTION_T *) p->data; - libopm_connection_free(conn); - - libopm_list_remove(scan->connections, p); - libopm_node_free(p); - } - libopm_list_free(scan->connections); - - MyFree(scan); -} - - - - -/* connection_create - * - * Allocate new OPM_CONNECTION_T - * - * Parameters: - * None - * - * Return: - * Address of new OPM_CONNECTION_T - */ - -static OPM_CONNECTION_T *libopm_connection_create(void) -{ - OPM_CONNECTION_T *ret; - ret = MyMalloc(sizeof *ret); - - ret->fd = 0; - ret->bytes_read = 0; - ret->readlen = 0; - ret->protocol = 0; - ret->port = 0; - - ret->state = OPM_STATE_UNESTABLISHED; - - return ret; -} - - - - -/* connection_free - * - * Free OPM_CONNECTION_T struct - * - * Parameters: - * conn: Address of struct to free - * - * Return: - * None - */ - -static void libopm_connection_free(OPM_CONNECTION_T *conn) -{ - MyFree(conn); -} - - -/* opm_cycle - * - * Perform tasks (called by client's loop) - * - * Parameters: - * None - * Return: - * None - */ - -void opm_cycle(OPM_T *scanner) -{ - libopm_check_queue(scanner); /* Move scans from the queue to the live scan list */ - libopm_check_establish(scanner); /* Make new connections if possible */ - libopm_check_poll(scanner); /* Poll connections for IO and proxy test */ - libopm_check_closed(scanner); /* Check for closed or timed out connections */ -} - - - - -/* check_queue - * - * Move scans from the queue to the live scan list as long as there is - * room. - * - * Parameters: - * scanner: Scanner to check queue on - * - * Return: - * None - */ - -static void libopm_check_queue(OPM_T *scanner) -{ - OPM_NODE_T *node; - OPM_SCAN_T *scan; - - unsigned int protocols, projected, fd_limit; - - if(LIST_SIZE(scanner->queue) == 0) - return; - - fd_limit = *(int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); - - projected = scanner->fd_use; - - /* We want to keep the live scan list as small as possible, so only - move queued scans to the live list if they will not push above fd_limit */ - while(LIST_SIZE(scanner->queue) > 0) - { - - /* Grab the top scan */ - scan = (OPM_SCAN_T *) scanner->queue->head->data; - protocols = LIST_SIZE(scan->connections); - - /* Check if it will fit in the live scan list */ - if((protocols + projected) > fd_limit) - break; - - /* Scans on the top of the queue were added first, swap the head off the - top of the queue and add it to the tail of the live scan list */ - node = libopm_list_remove(scanner->queue, scanner->queue->head); - libopm_list_add(scanner->scans, node); - projected += protocols; - } - -} - - - - -/* check_establish - * - * Make new connections if there are free file descriptors and connections - * to be made. - * - * Parameters: - * scanner: Scanner to check for establish on - * Return: - * None - */ - -static void libopm_check_establish(OPM_T *scanner) -{ - OPM_NODE_T *node1, *node2; - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - - unsigned int fd_limit; - - if(LIST_SIZE(scanner->scans) == 0) - return; - - fd_limit = *(int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); - - if(scanner->fd_use >= fd_limit) - return; - - LIST_FOREACH(node1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - LIST_FOREACH(node2, scan->connections->head) - { - /* Only scan if we have free file descriptors */ - if(scanner->fd_use >= fd_limit) - return; - - conn = (OPM_CONNECTION_T *) node2->data; - if(conn->state == OPM_STATE_UNESTABLISHED) - libopm_do_connect(scanner, scan, conn); - } - } -} - - - - -/* check_closed - * - * Check for connections which have timed out or are - * closed. Connections timed out still need to be closed. - * - * Remove the connection from the list of connections, free - * the connection struct and free the list node. Then if this is - * the last connection of the scan, consider the scan completed and - * free the scan aswell (and callback that the scan ended). - * - * Parameters: - * scanner: Scanner to check on - * Return: - * None - */ - -static void libopm_check_closed(OPM_T *scanner) -{ - - time_t present; - OPM_NODE_T *node1, *node2, *next1, *next2; - int timeout; - - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - - if(LIST_SIZE(scanner->scans) == 0) - return; - - time(&present); - - timeout = *(int *) libopm_config(scanner->config, OPM_CONFIG_TIMEOUT); - - LIST_FOREACH_SAFE(node1, next1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - LIST_FOREACH_SAFE(node2, next2, scan->connections->head) - { - - conn = (OPM_CONNECTION_T *) node2->data; - - if(conn->state == OPM_STATE_CLOSED) - { - if(conn->fd > 0) - close(conn->fd); - - scanner->fd_use--; - - libopm_list_remove(scan->connections, node2); - libopm_connection_free(conn); - libopm_node_free(node2); - continue; - } - - if(((present - conn->creation) >= timeout) && - conn->state != OPM_STATE_UNESTABLISHED) - { - - close(conn->fd); - scanner->fd_use--; - - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_TIMEOUT, 0); - - libopm_list_remove(scan->connections, node2); - libopm_connection_free(conn); - libopm_node_free(node2); - - continue; - } - } - - /* No more connections left in this scan, let the - client know the scan has ended, then remove the - scan from the scanner, and free it up */ - if(LIST_SIZE(scan->connections) == 0) - { - libopm_do_callback(scanner, scan->remote, OPM_CALLBACK_END, 0); - - libopm_list_remove(scanner->scans, node1); - libopm_scan_free(scan); - libopm_node_free(node1); - } - } -} - - - - -/* do_connect - * - * Call socket() and connect() to start a scan. - * - * Parametsr: - * scan: Scan struct containing the connection - * conn: Connection to establish - * Return: - * None - */ - -static void libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - opm_sockaddr *bind_ip; - struct timeval timeout; - struct sockaddr_in *addr; /* Outgoing host */ - char tmpbuf[BUFSIZE]; -#if 0 - struct sockaddr_in local_addr; /* For binding */ -#endif - addr = (struct sockaddr_in *) &(scan->addr.sa4); /* Already have the IP in byte format from opm_scan */ - - addr->sin_family = AF_INET; - addr->sin_port = htons(conn->port); - - - bind_ip = (opm_sockaddr *) libopm_config(scanner->config, OPM_CONFIG_BIND_IP); - - conn->fd = sock_connect(SOCK_STREAM, scan->addr.sa4.sin_addr, conn->port); - if (conn->fd == -1) - { - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_ERROR, OPM_ERR_NOFD); - conn->state = OPM_STATE_CLOSED; - return; - } - ircsnprintf(tmpbuf, BUFSIZE, "OPSB-%d-%d", conn->fd, conn->port); - timeout.tv_sec = *(int *) libopm_config(scanner->config, OPM_CONFIG_TIMEOUT); - timeout.tv_usec = 0; - conn->Sock = AddSock(SOCK_NATIVE, tmpbuf, conn->fd, libopm_do_readready, libopm_do_writeready, EV_WRITE|EV_TIMEOUT, (void *)conn, &timeout); - - -#if 0 - conn->fd = socket(PF_INET, SOCK_STREAM, 0); - scanner->fd_use++; /* Increase file descriptor use */ - - if(conn->fd == -1) - { - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_ERROR, OPM_ERR_NOFD); - conn->state = OPM_STATE_CLOSED; - return; - } - - if(bind_ip != NULL) - { - memset(&local_addr, 0, sizeof(local_addr)); - local_addr.sin_addr.s_addr = bind_ip->sa4.sin_addr.s_addr; - local_addr.sin_family = AF_INET; - local_addr.sin_port = htons(0); - - if(bind(conn->fd, (struct sockaddr *) &(local_addr), sizeof(local_addr)) == -1) - { - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_ERROR, OPM_ERR_BIND); - conn->state = OPM_STATE_CLOSED; - return; - } - } - - /* Set socket non blocking */ -#ifdef WIN32 - { - int flags = 1; - ioctlsocket(conn->fd, FIONBIO, &flags); - } -#else - fcntl(conn->fd, F_SETFL, O_NONBLOCK); -#endif - connect(conn->fd, (struct sockaddr *) addr, sizeof(*addr)); -#endif /* new sock code */ - - conn->state = OPM_STATE_ESTABLISHED; - time(&(conn->creation)); /* Stamp creation time, for timeout */ -} - - -#if 0 - -/* check_poll - * - * Check sockets for ready read/write - * - * Parameters: - * scanner: Scanner to isolate check on - * Return: - * None - */ - -static void libopm_check_poll(OPM_T *scanner) -{ - OPM_NODE_T *node1, *node2; - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - - static unsigned int ufds_size; - static struct pollfd *ufds = NULL; - - unsigned int size, i; - size = 0; - - /* Grow pollfd array (ufds) as needed */ - if(ufds_size < (*(unsigned int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT))) - { - MyFree(ufds); - ufds = MyMalloc((sizeof *ufds) * (*(unsigned int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT))); - ufds_size = (*(unsigned int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT)); - } - - if(LIST_SIZE(scanner->scans) == 0) - return; - - LIST_FOREACH(node1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - LIST_FOREACH(node2, scan->connections->head) - { - if(size >= ufds_size) - break; - - conn = (OPM_CONNECTION_T *) node2->data; - - if(conn->state < OPM_STATE_ESTABLISHED || - conn->state == OPM_STATE_CLOSED) - continue; - - ufds[size].events = 0; - ufds[size].revents = 0; - ufds[size].fd = conn->fd; - - /* Check for HUNG UP. */ - ufds[size].events |= POLLHUP; - /* Check for INVALID FD */ - ufds[size].events |= POLLNVAL; - - switch(conn->state) - { - case OPM_STATE_ESTABLISHED: - ufds[size].events |= POLLOUT; - break; - case OPM_STATE_NEGSENT: - ufds[size].events |= POLLIN; - break; - } - size++; - } - - } - - switch (poll(ufds, size, 0)) - { - case -1: - /* error in select/poll */ - return; - case 0: - /* Nothing to do */ - return; - /* Pass pointer to connection to handler. */ - } - - LIST_FOREACH(node1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - - LIST_FOREACH(node2, scan->connections->head) - { - conn = (OPM_CONNECTION_T *) node2->data; - - for(i = 0; i < size; i++) - { - if((ufds[i].fd == conn->fd) && (conn->state != OPM_STATE_CLOSED)) - { - if(ufds[i].revents & POLLIN) - libopm_do_readready(scanner, scan, conn); - if(ufds[i].revents & POLLOUT) - libopm_do_writeready(scanner, scan, conn); - if(ufds[i].revents & POLLHUP) - libopm_do_hup(scanner, scan, conn); - } - } - } - } -} -/* before_poll - * - * external select/poll routine to setup our fd checks - * - * Parameters: - * scanner: Scanner to isolate check on - * Return: - * pollfds struct. - */ - -int libopm_before_poll(OPM_T *scanner, pollfd *ufds) -{ - OPM_NODE_T *node1, *node2; - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - unsigned int maxsize, size; - - size = 0; - libopm_check_closed(scanner); /* Check for closed or timed out connections */ - libopm_check_queue(scanner); /* Move scans from the queue to the live scan list */ - libopm_check_establish(scanner); /* Make new connections if possible */ - - -/* ufds = MyMalloc((sizeof *ufds) * (*(unsigned int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT))); */ - maxsize = (*(unsigned int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT)); - - if(LIST_SIZE(scanner->scans) == 0) - return -1; - - LIST_FOREACH(node1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - LIST_FOREACH(node2, scan->connections->head) - { - if(size >= maxsize) - break; - - conn = (OPM_CONNECTION_T *) node2->data; - - if(conn->state < OPM_STATE_ESTABLISHED || - conn->state == OPM_STATE_CLOSED) - continue; - - ufds[size].events = 0; - ufds[size].revents = 0; - ufds[size].fd = conn->fd; - - /* Check for HUNG UP. */ - ufds[size].events |= POLLHUP; - /* Check for INVALID FD */ - ufds[size].events |= POLLNVAL; - - switch(conn->state) - { - case OPM_STATE_ESTABLISHED: - ufds[size].events |= POLLOUT; - break; - case OPM_STATE_NEGSENT: - ufds[size].events |= POLLIN; - break; - } - size++; - } - - } - return size; -} -/* after_poll - * - * external select/poll routine to check what our fd check - * - * Parameters: - * scanner: Scanner to isolate check on - * Return: - * pollfds struct. - */ - -void libopm_after_poll(OPM_T *scanner, pollfd *ufds, unsigned int ufdssize) -{ - OPM_NODE_T *node1, *node2; - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; - - int i; - if (opm_active(scanner) < 1) { - return; - } - LIST_FOREACH(node1, scanner->scans->head) - { - scan = (OPM_SCAN_T *) node1->data; - - LIST_FOREACH(node2, scan->connections->head) - { - conn = (OPM_CONNECTION_T *) node2->data; - - for(i = 0; i < (int)ufdssize; i++) - { - if((ufds[i].fd == conn->fd) && (conn->state != OPM_STATE_CLOSED)) - { - if(ufds[i].revents & POLLIN) - libopm_do_readready(scanner, scan, conn); - if(ufds[i].revents & POLLOUT) - libopm_do_writeready(scanner, scan, conn); - if(ufds[i].revents & POLLHUP) - libopm_do_hup(scanner, scan, conn); - } - } - } - } - -} - -#endif - -/* do_readready - * - * Remote connection is read ready, read the data into a buffer and check it against - * the target_string if neccessary - * - * Parameters: - * scanner: Scanner doing the scan - * scan: Specific scan - * conn: Specific connection in the scan - * - * Return: - * None - */ - -static void libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - - int max_read; - char c; - - /* If protocol has a specific read function, call that instead of - reading data from here. */ - if(conn->protocol->read_function) - { - conn->protocol->read_function(scanner, scan, conn); - return; - } - - max_read = *(int *) libopm_config(scanner->config, OPM_CONFIG_MAX_READ); - - while(1) - { - switch (read(conn->fd, &c, 1)) - { - case 0: - libopm_do_hup(scanner, scan, conn); - return; - - case -1: - if(errno != EAGAIN) - libopm_do_hup(scanner, scan, conn); - return; - - default: - - conn->bytes_read++; - - if(conn->bytes_read >= max_read) - { - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_ERROR, OPM_ERR_MAX_READ); - conn->state = OPM_STATE_CLOSED; - return; - } - - if(c == '\0' || c == '\r') - continue; - - if(c == '\n') - { - conn->readbuf[conn->readlen] = '\0'; - conn->readlen = 0; - libopm_do_read(scanner, scan, conn); - - if(conn->state == OPM_STATE_CLOSED) - return; - - continue; - } - - if(conn->readlen < READBUFLEN) - { /* -1 to pad for null term */ - conn->readbuf[++(conn->readlen) - 1] = c; - } - } - } -} - - - - -/* do_read - * - * A line of data has been read from the socket, check it against - * target string. - * - * - * - * Parameters: - * scanner: Scanner doing the scan - * scan: Specific scan - * conn: Specific connection in the scan - * - * Return: - * None - */ - -static void libopm_do_read(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - OPM_LIST_T *list; - OPM_NODE_T *node; - char *target_string; - - /* Check readbuf against target strings */ - list = (OPM_LIST_T *) libopm_config(scanner->config, OPM_CONFIG_TARGET_STRING); - LIST_FOREACH(node, list->head) - { - target_string = (char *) node->data; - if(strstr(conn->readbuf, target_string)) - { - libopm_do_openproxy(scanner, scan, conn); - break; - } - } -} - - -/* do_openproxy - * - * An open proxy was found on connection conn. Cleanup the connection and - * call the appropriate callback to let the client know the proxy was found. - * - * Parameters: - * scanner: Scanner doing the scan - * scan: Specific scan - * conn: Specific connection in the scan - * - * Return: - * None - */ - -static void libopm_do_openproxy(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - OPM_REMOTE_T *remote; - - remote = scan->remote; - - /* Mark the connection for close */ - conn->state = OPM_STATE_CLOSED; - - /* Call client's open proxy callback */ - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_OPENPROXY, 0); -} - - - - -/* do_writeready - * - * Remote connection is write ready, call the specific protocol - * function for writing to this socket. - * - * Parameters: - * scanner: Scanner doing the scan - * scan: Specific scan - * conn: Specific connection in the scan - * - * Return: - * None - */ - -static void libopm_do_writeready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - OPM_PROTOCOL_T *protocol; - - protocol = conn->protocol; - - /* Call write function for specific protocol */ - if(protocol->write_function) - protocol->write_function(scanner, scan, conn); - - /* Flag as NEGSENT so we don't have to send data again*/ - conn->state = OPM_STATE_NEGSENT; -} - - - - -/* do_hup - * - * Connection ended prematurely - * - * Parameters: - * scanner: Scanner doing the scan - * scan: Specific scan - * conn: Specific connection in the scan - * error: OPM_ERR_T containing the error type - * Return: - * None - */ - -static void libopm_do_hup(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - OPM_REMOTE_T *remote; - - remote = scan->remote; - - /* Mark the connection for close */ - conn->state = OPM_STATE_CLOSED; - - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_NEGFAIL, 0); -} - - - - -/* do_callback - * - * Call callback - * - * Parameters: - * scanner: scanner remote is on - * remote: remote callback is for - * type: callback type - * var: optional var passed back (error codes, etc ) - * Return: - * None - */ - -static void libopm_do_callback(OPM_T *scanner, OPM_REMOTE_T *remote, int type, int var) -{ - /* Callback is out of range */ - if(type < 0 || type >= (CBLEN + 1)) - return; - - if(scanner->callbacks[type].func) - (scanner->callbacks[type].func) (scanner, remote, var, scanner->callbacks[type].data); -} - - - - -/* setup_remote - * - * Setup an OPM_REMOTE_T with information from an OPM_CONNECTION_T - * for callback - * - * Parameters: - * remote, conn - * - * Return: - * remote - */ - -static OPM_REMOTE_T *libopm_setup_remote(OPM_REMOTE_T *remote, OPM_CONNECTION_T *conn) -{ - remote->port = conn->port; - remote->bytes_read = conn->bytes_read; - remote->protocol = conn->protocol->type; - - return remote; -} diff --git a/libopm/libopm.h b/libopm/libopm.h deleted file mode 100644 index 41fae78..0000000 --- a/libopm/libopm.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef LIBOPM_H -#define LIBOPM_H - -#include -#include "config.h" -#include "inet.h" -#include "opm_common.h" -#include "opm.h" - -#define CBLEN 5 /* Number of callback functions */ -#define READBUFLEN 128 /* Size of conn->readbuf */ -#define SENDBUFLEN 512 /* Size of sendbuffer in proxy.c */ - -typedef struct _OPM_SCAN OPM_SCAN_T; -typedef struct _OPM_CONNECTION OPM_CONNECTION_T; -typedef struct _OPM_PROTOCOL_CONFIG OPM_PROTOCOL_CONFIG_T; -typedef struct _OPM_PROTOCOL OPM_PROTOCOL_T; - -/* Types of hard coded proxy READ/WRITE functions which are - setup in a table in libopm.c */ - -typedef int OPM_PROXYWRITE_T (OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -typedef int OPM_PROXYREAD_T (OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); - -struct _OPM_SCAN { - opm_sockaddr addr; /* Address in byte order of remote client */ - OPM_REMOTE_T *remote; /* Pointed to the OPM_REMOTE_T for this scan, passed by client */ - OPM_LIST_T *connections; /* List of individual connections of this scan (1 for each protocol) */ -}; - -struct _OPM_CONNECTION { - - OPM_PROTOCOL_T *protocol; /* Pointer to specific protocol this connection handles */ - unsigned short int port; /* Some protocols have multiple ports, eg. HTTP */ - Sock *Sock; - int fd; /* Allocated file descriptor, 0 if not yet allocated */ - unsigned short int bytes_read; /* Bytes read so far in this connection */ - char readbuf[READBUFLEN + 1]; /* 128 byte read buffer, anything over 128 is probably not of use */ - unsigned short int readlen; /* Length of readbuf */ - unsigned short int state; /* State of connection */ - time_t creation; /* When this connection was established */ -}; - -struct _OPM_PROTOCOL_CONFIG -{ - OPM_PROTOCOL_T *type; /* Protocol type */ - unsigned short int port; /* Port to connect on */ - -}; - -struct _OPM_PROTOCOL -{ - int type; /* Protocol type */ - - OPM_PROXYWRITE_T *write_function; /* Write function handler for this protocol */ - OPM_PROXYREAD_T *read_function; /* Read function handler for this protocol */ -}; - -#endif /* LIBOPM_H */ diff --git a/libopm/libopm.vcproj b/libopm/libopm.vcproj deleted file mode 100755 index b706880..0000000 --- a/libopm/libopm.vcproj +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libopm/malloc.c b/libopm/malloc.c deleted file mode 100644 index 6b5d482..0000000 --- a/libopm/malloc.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2002 Erik Fears - * - * 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. - * - * - */ - -#include -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#include "malloc.h" -#include "opm.h" - -RCSID("$Id$"); - - -/* MyMalloc - * - * A wrapper function for malloc(), for catching memory issues - * and error handling. - * - * Parameters - * bytes: amount in bytes to allocate - * - * Return: - * Pointer to allocated memory - */ - -void *libopm_MyMalloc(size_t bytes) -{ - void *ret = calloc(1, bytes); - - assert(ret); - - return ret; -} - - - -/* MyFree - * - * Free memory allocated with MyMalloc - * - * Parameters: - * var: pointer to memory to free - * - * Return: - * None - */ - -void libopm_MyFree(void **var) -{ - if(*var != NULL) - free(*var); - *var = NULL; -} diff --git a/libopm/malloc.h b/libopm/malloc.h deleted file mode 100644 index c3ae06a..0000000 --- a/libopm/malloc.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MALLOC_H -#define MALLOC_H - -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#ifdef STDC_HEADERS -# include -#endif - -#define MyMalloc(SIZE) libopm_MyMalloc(SIZE) -#define MyFree(X) libopm_MyFree((void **) &X) - -void *libopm_MyMalloc(size_t bytes); -void libopm_MyFree(void **var); - -#endif /* MALLOC_H */ diff --git a/libopm/opm.h b/libopm/opm.h deleted file mode 100644 index 4ef89b2..0000000 --- a/libopm/opm.h +++ /dev/null @@ -1,88 +0,0 @@ -/* vim: set shiftwidth=3 softtabstop=3 expandtab: */ - -/** \file opm.h - * \brief Main header for libopm. - * \author Erik Fears - * \version $Id$ - */ - -#ifndef OPM_H -#define OPM_H - -#include "opm_common.h" -#ifndef WIN32 -#include -#endif - -/* Stuff to shut up warnings about rcsid being unused. */ -#define USE_VAR(var) static char sizeof##var = sizeof(sizeof##var) + sizeof(var) -/* RCS tag. */ -#define RCSID(x) static char rcsid[] = x; USE_VAR(rcsid); - - -typedef struct _OPM_CONFIG OPM_CONFIG_T; -typedef struct _OPM OPM_T; -typedef struct _OPM_REMOTE OPM_REMOTE_T; -typedef struct _OPM_CALLBACK OPM_CALLBACK_T; - -typedef int OPM_ERR_T; - -typedef void OPM_CALLBACK_FUNC (OPM_T *, OPM_REMOTE_T *, int, void *); - -struct _OPM_CALLBACK { - OPM_CALLBACK_FUNC *func; - void *data; -}; - -struct _OPM_CONFIG { - void **vars; -}; - -struct _OPM { - OPM_CONFIG_T *config; /* Individual scanner configuration */ - OPM_LIST_T *queue; /* List of scans in the queue (not yet established) */ - OPM_LIST_T *scans; /* List of scans (each scan containing a list of connections) */ - OPM_LIST_T *protocols; /* List of protocols this scanner handles */ - unsigned int fd_use; /* Number of file descriptors in use */ - - OPM_CALLBACK_T *callbacks; /* Scanner wide callbacks */ -}; - -struct _OPM_REMOTE { - - char *ip; /* Readable IP address */ - - unsigned short int port; /* Port passed back on certain callbacks */ - unsigned short int protocol; /* Protocol passed back on certain callbacks */ - unsigned short int bytes_read; /* Bytes read passed back on certain callbacks */ - - OPM_LIST_T *protocols; /* Remote specific protocols */ - - void *data; /* Arbitrary data that the client can point to for any purpose*/ -}; - -OPM_T *opm_create(void); -void opm_free(OPM_T *); - -OPM_REMOTE_T *opm_remote_create(const char *); -void opm_remote_free(OPM_REMOTE_T *); - -OPM_ERR_T opm_config(OPM_T *, int, void *); -OPM_ERR_T opm_scan(OPM_T *, OPM_REMOTE_T *); -void opm_end(OPM_T *, OPM_REMOTE_T *); -void opm_endscan(OPM_T *, OPM_REMOTE_T *); - -OPM_ERR_T opm_addtype(OPM_T *, int, unsigned short int); -OPM_ERR_T opm_remote_addtype(OPM_REMOTE_T *, int, unsigned short int); -OPM_ERR_T opm_callback(OPM_T *, int, OPM_CALLBACK_FUNC *, void *); - -void opm_cycle(OPM_T *); -typedef struct pollfd pollfd; - -void libopm_after_poll(OPM_T *, pollfd *, unsigned int ); -int libopm_before_poll(OPM_T *, pollfd *); - - -size_t opm_active(OPM_T *); - -#endif /* OPM_H */ diff --git a/libopm/opm_common.h b/libopm/opm_common.h deleted file mode 100644 index 18aeda8..0000000 --- a/libopm/opm_common.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef OPM_COMMON_H -#define OPM_COMMON_H - -typedef struct _libopm_node OPM_NODE_T; -typedef struct _libopm_list OPM_LIST_T; - - -struct _libopm_list { - - struct _libopm_node *head; - struct _libopm_node *tail; - - int elements; -}; - -struct _libopm_node { - - struct _libopm_node *next; - struct _libopm_node *prev; - - void *data; -}; - -#endif /* OPM_COMMON_H */ diff --git a/libopm/opm_error.h b/libopm/opm_error.h deleted file mode 100644 index 9c11388..0000000 --- a/libopm/opm_error.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef LIBOPM_ERROR_H -#define LIBOPM_ERROR_H - -/* Success */ -#define OPM_SUCCESS 1 - -/* Configuration Errors */ -#define OPM_ERR_BADKEY 2 /* Unknown or bad key value */ -#define OPM_ERR_BADVALUE 3 /* Bad value matching key */ -#define OPM_ERR_BADPROTOCOL 4 /* Unknown protocol in config */ - -/* Read Errors */ -#define OPM_ERR_MAX_READ 5 /* Socket reached MAX_READ */ - -/* Callback Registration Errors */ -#define OPM_ERR_CBNOTFOUND 6 /* Callback is out of range */ - -/* opm_scan errors */ -#define OPM_ERR_BADADDR 7 /* IP in remote struct is bad */ -#define OPM_ERR_NOPROTOCOLS 8 /* No protocols to scan! */ - -/* bind/connect errors */ -#define OPM_ERR_BIND 9 /* Error binding to BIND_IP */ -#define OPM_ERR_NOFD 10/* Unable to allocate file descriptor */ - -#endif /* LIBOPM_ERROR_H */ diff --git a/libopm/opm_types.h b/libopm/opm_types.h deleted file mode 100644 index 3c17384..0000000 --- a/libopm/opm_types.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef OPM_TYPES_H -#define OPM_TYPES_H - -/* Configuration Directives */ -#define OPM_CONFIG_FD_LIMIT 0 -#define OPM_CONFIG_BIND_IP 1 -#define OPM_CONFIG_DNSBL_HOST 2 -#define OPM_CONFIG_TARGET_STRING 3 -#define OPM_CONFIG_SCAN_IP 4 -#define OPM_CONFIG_SCAN_PORT 5 -#define OPM_CONFIG_MAX_READ 6 -#define OPM_CONFIG_TIMEOUT 7 - -/* Configuration Variable Types */ -#define OPM_TYPE_INT 1 -#define OPM_TYPE_STRING 2 -#define OPM_TYPE_ADDRESS 3 -#define OPM_TYPE_STRINGLIST 4 - -/* Protocols */ -#define OPM_TYPE_HTTP 1 -#define OPM_TYPE_SOCKS4 2 -#define OPM_TYPE_SOCKS5 3 -#define OPM_TYPE_WINGATE 4 -#define OPM_TYPE_ROUTER 5 -#define OPM_TYPE_HTTPPOST 6 - -/* States */ -#define OPM_STATE_UNESTABLISHED 1 -#define OPM_STATE_ESTABLISHED 2 -#define OPM_STATE_NEGSENT 3 -#define OPM_STATE_CLOSED 4 - - -/* Callbacks -- If more callback types are added, - CBLEN will need to be changed in libopm.h accordingly */ - -#define OPM_CALLBACK_OPENPROXY 0 /* An open proxy has been found REMOTE/SCANNER */ -#define OPM_CALLBACK_NEGFAIL 1 /* Negotiation to a proxy has failed REMOTE/SCANNER */ -#define OPM_CALLBACK_END 2 /* A scan has ended REMOTE/SCANNER */ -#define OPM_CALLBACK_ERROR 3 /* An unrecoverable error has occured */ -#define OPM_CALLBACK_TIMEOUT 4 /* Specific scan (protocol) on host has timed out */ - -#endif /* OPM_TYPES_H */ diff --git a/libopm/opmlist.c b/libopm/opmlist.c deleted file mode 100644 index 0440c13..0000000 --- a/libopm/opmlist.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2002-2003 Erik Fears - * - * 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. - * - * - */ - -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#include "opm_common.h" -#include "opmlist.h" -#include "malloc.h" -#include "opm.h" - -RCSID("$Id$"); - -OPM_NODE_T *libopm_node_create(void *data) -{ - OPM_NODE_T *node = MyMalloc(sizeof *node); - node->next = NULL; - node->prev = NULL; - node->data = (void *) data; - - return node; -} - -OPM_LIST_T *libopm_list_create() -{ - OPM_LIST_T *list = MyMalloc(sizeof *list); - - list->head = NULL; - list->tail = NULL; - - list->elements = 0; - - return list; -} - -OPM_NODE_T *libopm_list_add(OPM_LIST_T *list, OPM_NODE_T *node) -{ - - if(list == NULL || node == NULL) - return NULL; - - if(list->tail == NULL) - { - list->head = node; - list->tail = node; - - node->next = NULL; - node->prev = NULL; - } - else - { - node->prev = list->tail; - list->tail->next = node; - list->tail = node; - node->next = NULL; - } - - list->elements++; - return node; -} - -OPM_NODE_T *libopm_list_remove(OPM_LIST_T *list, OPM_NODE_T *node) -{ - - if(list == NULL || node == NULL) - return NULL; - - if(node == list->head) - { - list->head = node->next; - - if(node->next) - node->next->prev = NULL; - else - list->tail = NULL; - } - else if(node == list->tail) - { - list->tail = list->tail->prev; - list->tail->next = NULL; - } - else - { - node->prev->next = node->next; - node->next->prev = node->prev; - } - - list->elements--; - return node; -} - -void libopm_list_free(OPM_LIST_T *list) -{ - MyFree(list); -} - -void libopm_node_free(OPM_NODE_T *node) -{ - MyFree(node); -} diff --git a/libopm/opmlist.h b/libopm/opmlist.h deleted file mode 100644 index 094bd76..0000000 --- a/libopm/opmlist.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef OPMLIST_H -#define OPMLIST_H - - -/* Copyright (C) 2002 by the past and present ircd coders, and others. - * Adapted from Hybrid7 DLINK macros - * - * 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. - * - */ - -#define LIST_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next) -#define LIST_FOREACH_SAFE(pos, n, head) for (pos = (head), n = pos ? pos->next : NULL; pos != NULL; pos = n, n = pos ? pos->next : NULL) -#define LIST_FOREACH_PREV(pos, head) for (pos = (head); pos != NULL; pos = pos->prev) -#define LIST_SIZE(list) list->elements -/* End Copyright */ - -OPM_NODE_T *libopm_node_create(void *); -OPM_LIST_T *libopm_list_create(void); - -OPM_NODE_T *libopm_list_add(OPM_LIST_T *, OPM_NODE_T *); -OPM_NODE_T *libopm_list_remove(OPM_LIST_T *, OPM_NODE_T *); - -void libopm_list_free(OPM_LIST_T *); -void libopm_node_free(OPM_NODE_T *); - -#endif /* LIST_H */ diff --git a/libopm/proxy.c b/libopm/proxy.c deleted file mode 100644 index 584ade4..0000000 --- a/libopm/proxy.c +++ /dev/null @@ -1,250 +0,0 @@ -/* vim: set shiftwidth=3 softtabstop=3 expandtab: */ - -/* Copyright (C) 2002 Erik Fears - * - * 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. - * - * - */ - -#ifdef WIN32 -#include "modconfigwin32.h" -#else -#include "modconfig.h" -#endif - -#include - -#ifdef STDC_HEADERS -# include -# include -#endif - -#include "inet.h" -#include "compat.h" -#include "config.h" -#include "proxy.h" -#include "opm_common.h" -#include "opm_types.h" -#include "opm_error.h" -#include "libopm.h" - -RCSID("$Id$"); - -static char SENDBUF[SENDBUFLEN + 1]; - -int libopm_proxy_http_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - USE_VAR(scan); - - snprintf(SENDBUF, SENDBUFLEN, "CONNECT %s:%d HTTP/1.0\r\n\r\n", - (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP), - *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT)); - - if(send(conn->fd, SENDBUF, strlen(SENDBUF), 0) == -1) - return 0; /* Return error code ? */ - - return OPM_SUCCESS; -} - - -/* - * CONNECT request byte order for socks4 - * - * +----+----+----+----+----+----+----+----+----+----+....+----+ - * | VN | CD | DSTPORT | DSTIP | USERID |NULL| - * +----+----+----+----+----+----+----+----+----+----+....+----+ - * # of bytes: 1 1 2 4 variable 1 - * - * VN = Version, CD = Command Code (1 is connect request) - */ - -int libopm_proxy_socks4_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - struct in_addr addr; - unsigned long laddr; - int len, scan_port; - char *scan_ip; - USE_VAR(scan); - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - - laddr = htonl(addr.s_addr); - - len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c%c%c%c%c%c%c", 4, 1, - (((unsigned short) scan_port) >> 8) & 0xFF, - (((unsigned short) scan_port) & 0xFF), - (char) (laddr >> 24) & 0xFF, (char) (laddr >> 16) & 0xFF, - (char) (laddr >> 8) & 0xFF, (char) laddr & 0xFF, 0); - - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - return OPM_SUCCESS; -} - - -/* - * Send version authentication selection message to socks5 - * - * +----+----------+----------+ - * |VER | NMETHODS | METHODS | - * +----+----------+----------+ - * | 1 | 1 | 1 to 255 | - * +----+----------+----------+ - * - * VER always contains 5, for socks version 5 - * Method 0 is 'No authentication required' - * - * - * - * The SOCKS request is formed as follows: - * - * +----+-----+-------+------+----------+----------+ - * |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT | - * +----+-----+-------+------+----------+----------+ - * | 1 | 1 | X'00' | 1 | Variable | 2 | - * +----+-----+-------+------+----------+----------+ - * - * - * o VER protocol version: X'05' - * o CMD - * o CONNECT X'01' - * o BIND X'02' - * o UDP ASSOCIATE X'03' - * o RSV RESERVED - * o ATYP address type of following address - * o IP V4 address: X'01' - * o DOMAINNAME: X'03' - * o IP V6 address: X'04' - * o DST.ADDR desired destination address - * o DST.PORT desired destination port in network octet - * order - * - * - */ - -int libopm_proxy_socks5_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - struct in_addr addr; - unsigned long laddr; - int len, scan_port; - char *scan_ip; - USE_VAR(scan); - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - - if (inet_aton(scan_ip, &addr) == 0) - ; /* handle error */ - - laddr = htonl(addr.s_addr); - - /* Form authentication string */ - /* Version 5, 1 number of methods, 0 method (no auth). */ - len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c", 5, 1, 0); - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - /* Form request string */ - - /* Will need to write ipv6 support here in future - * as socks5 is ipv6 compatible - */ - len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c%c%c%c%c%c%c%c", 5, 1, 0, 1, - (char) (laddr >> 24) & 0xFF, (char) (laddr >> 16) & 0xFF, - (char) (laddr >> 8) & 0xFF, (char) laddr & 0xFF, - (((unsigned short) scan_port) >> 8) & 0xFF, - (((unsigned short) scan_port) & 0xFF)); - - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - return OPM_SUCCESS; -} - -/* - * Open wingates require no authentication, they will send a prompt when - * connect. - */ - -int libopm_proxy_wingate_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - int scan_port, len; - char *scan_ip; - USE_VAR(scan); - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - - len = snprintf(SENDBUF, SENDBUFLEN, "%s:%d\r\n", scan_ip, scan_port); - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - return OPM_SUCCESS; -} - - -/* - * Cisco scanning - * - * Some cisco routers have 'cisco' set as password which allow open telnet - * relay. Attempt to connect using cisco as a password, then give command for - * telnet to the scanip/scanport - */ - -int libopm_proxy_router_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - int len, scan_port; - char *scan_ip; - USE_VAR(scan); - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - - len = snprintf(SENDBUF, SENDBUFLEN, "cisco\r\n"); - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - len = snprintf(SENDBUF, SENDBUFLEN, "telnet %s %d\r\n", scan_ip, scan_port); - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - return OPM_SUCCESS; -} - - -/* - * HTTP POST Scanning - * - */ - -int libopm_proxy_httppost_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) -{ - int len, scan_port; - char *scan_ip; - USE_VAR(scan); - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - - len = snprintf(SENDBUF, SENDBUFLEN, "POST http://%s:%d/ HTTP/1.0\r\n" - "Content-type: text/plain\r\n" - "Content-length: 5\r\n\r\n" - "quit\r\n\r\n", - scan_ip, scan_port); - - send(conn->fd, SENDBUF, (unsigned int)len, 0); - - return OPM_SUCCESS; -} diff --git a/libopm/proxy.h b/libopm/proxy.h deleted file mode 100644 index ef21d5e..0000000 --- a/libopm/proxy.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PROXY_H -#define PROXY_H - -#include "libopm.h" - -int libopm_proxy_http_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -int libopm_proxy_socks4_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -int libopm_proxy_socks5_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -int libopm_proxy_wingate_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -int libopm_proxy_router_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); -int libopm_proxy_httppost_write(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); - - -#endif /* PROXY_H */ diff --git a/libopm/test.c b/libopm/test.c deleted file mode 100644 index c4a766b..0000000 --- a/libopm/test.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (C) 2002 Erik Fears - * - * 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. - * - * - */ - -#ifdef WIN32 -#include "win32modconfig.h" -#else -#include "modconfig.h" -#endif - -#include -#include "opm.h" -#include "opm_error.h" -#include "opm_types.h" -#include "compat.h" -#include -#ifdef HAVE_UNISTD_H -# include -#endif - -RCSID("$Id: test.c,v 1.36 2003/06/20 04:55:14 andy Exp $"); - -#define ARRAY_SIZEOF(x) (sizeof(x) / sizeof((x)[0])) - -void open_proxy(OPM_T *, OPM_REMOTE_T *, int, void *); -void negotiation_failed(OPM_T *, OPM_REMOTE_T *, int, void *); -void timeout(OPM_T *, OPM_REMOTE_T *, int, void *); -void end(OPM_T *, OPM_REMOTE_T *, int, void *); -void handle_error(OPM_T *, OPM_REMOTE_T *, int, void *); - -int complete = 0; - -int main(int argc, char **argv) -{ - OPM_ERR_T err; - int fdlimit = 1024; - int scan_port = 6667; - int max_read = 4096; - int scantimeout = 10; - struct pollfd *ufds; - unsigned int size; - unsigned int i, s; - - unsigned short http_ports[] = { - 8000, 8080, 3128, 80 - }; - - unsigned short wingate_ports[] = { - 23 - }; - - unsigned short router_ports[] = { - 23 - }; - - unsigned short socks4_ports[] = { - 1080 - }; - - unsigned short socks5_ports[] = { - 1080 - }; - - unsigned short httppost_ports[] = { - 80, 8090, 3128 - }; - - OPM_T *scanner; - OPM_REMOTE_T *remote; - - scanner = opm_create(); - - if(argc >= 2) - remote = opm_remote_create(argv[1]); - else - remote = opm_remote_create("127.0.0.1"); - - /* Setup callbacks */ - opm_callback(scanner, OPM_CALLBACK_OPENPROXY, &open_proxy, NULL); - opm_callback(scanner, OPM_CALLBACK_NEGFAIL, &negotiation_failed, NULL); - opm_callback(scanner, OPM_CALLBACK_TIMEOUT, &timeout, NULL); - opm_callback(scanner, OPM_CALLBACK_END, &end, NULL); - opm_callback(scanner, OPM_CALLBACK_ERROR, &handle_error, NULL); - - - /* Setup the scanner configuration */ - opm_config(scanner, OPM_CONFIG_FD_LIMIT, &fdlimit); - opm_config(scanner, OPM_CONFIG_SCAN_IP, "216.175.104.202"); - opm_config(scanner, OPM_CONFIG_SCAN_PORT, &scan_port); - opm_config(scanner, OPM_CONFIG_TARGET_STRING, "*** Looking up your hostname..."); - opm_config(scanner, OPM_CONFIG_TARGET_STRING, "ERROR :Trying to reconnect too fast."); - opm_config(scanner, OPM_CONFIG_TIMEOUT, &scantimeout); - opm_config(scanner, OPM_CONFIG_MAX_READ, &max_read); - - /* Setup the protocol configuration */ - for (s = ARRAY_SIZEOF(http_ports), i = 0; i < s; i++) { - opm_addtype(scanner, OPM_TYPE_HTTP, http_ports[i]); - } - - for (s = ARRAY_SIZEOF(wingate_ports), i = 0; i < s; i++) { - opm_addtype(scanner, OPM_TYPE_WINGATE, wingate_ports[i]); - } - - for (s = ARRAY_SIZEOF(router_ports), i = 0; i < s; i++) { - opm_addtype(scanner, OPM_TYPE_ROUTER, router_ports[i]); - } - - for (s = ARRAY_SIZEOF(socks4_ports), i = 0; i < s; i++) { - opm_addtype(scanner, OPM_TYPE_SOCKS4, socks4_ports[i]); - } - - for (s = ARRAY_SIZEOF(socks5_ports), i = 0; i < s; i++) { - opm_addtype(scanner, OPM_TYPE_SOCKS5, socks5_ports[i]); - } - - for (s = ARRAY_SIZEOF(httppost_ports), i = 0; i < s; i++) { - opm_addtype(scanner, OPM_TYPE_HTTPPOST, httppost_ports[i]); - } - - /* Remote structs can also have their own extended protocol configurations. For instance - if the target hostname contains strings such as 'proxy' or 'www', extended ports could - be scanned. */ - opm_remote_addtype(remote, OPM_TYPE_HTTP, 8001); - opm_remote_addtype(remote, OPM_TYPE_HTTP, 8002); - - switch(err = opm_scan(scanner, remote)) - { - case OPM_SUCCESS: - break; - case OPM_ERR_BADADDR: - printf("Bad address\n"); - opm_free(scanner); - opm_remote_free(remote); - return 0; - default: - printf("Unknown Error %d\n", err); - return 0; - } - - while (!complete) { - ufds = malloc((sizeof *ufds) * (*(unsigned int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT))); - size = libopm_before_poll(scanner, ufds); - - err = poll(ufds, size, 0); - switch (err) - { - case -1: - /* error in select/poll */ - printf("poll barked\n"); - return; - case 0: - /* Nothing to do */ - continue; - default: - libopm_after_poll(scanner, ufds, size); - continue; - - /* Pass pointer to connection to handler. */ - } - } - opm_free(scanner); - - return 0; -} - -void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, - void *data) -{ - USE_VAR(notused); - USE_VAR(data); - - printf("Open proxy on %s:%d [%d bytes read]\n", remote->ip, - remote->port, remote->bytes_read); - opm_end(scanner, remote); -} - -void negotiation_failed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, - void *data) -{ - USE_VAR(scanner); - USE_VAR(notused); - USE_VAR(data); - - printf("Negotiation on %s:%d failed [%d bytes read]\n", remote->ip, - remote->port, remote->bytes_read); -} - -void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data) -{ - USE_VAR(scanner); - USE_VAR(notused); - USE_VAR(data); - - printf("Negotiation timed out on %s:%d\n", remote->ip, remote->port); -} - -void end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data) -{ - USE_VAR(scanner); - USE_VAR(notused); - USE_VAR(data); - - printf("Scan on %s has ended\n", remote->ip); - opm_remote_free(remote); - complete = 1; -} - -void handle_error(OPM_T *scanner, OPM_REMOTE_T *remote, int err, void *data) -{ - USE_VAR(scanner); - USE_VAR(data); - - switch(err) - { - case OPM_ERR_MAX_READ: - printf("Reached MAX READ on %s:%d\n", remote->ip, remote->port); - break; - case OPM_ERR_BIND: - printf("Unable to bind for %s:%d\n", remote->ip, remote->port); - break; - case OPM_ERR_NOFD: - printf("Unable to allocate file descriptor for %s:%d\n", - remote->ip, remote->port); - break; - default: - printf("Unknown error on %s:%d, err = %d\n", remote->ip, - remote->port, err); - } -}