Mark... See my post on the developer forum

This commit is contained in:
Fish 2003-10-22 12:51:44 +00:00
parent aed5ea096d
commit ca1ed1aef6
4 changed files with 373 additions and 0 deletions

1
.gitattributes vendored
View file

@ -31,6 +31,7 @@ libopm/proxy.c -text
libopm/proxy.h -text
libopm/snprintf.c -text
libopm/snprintf.h -text
libopm/test.c -text
/modconfig.h.in -text
/opsb.c -text
/opsb.h -text

View file

@ -1175,7 +1175,126 @@ static void libopm_check_poll(OPM_T *scanner)
}
}
}
/* 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, struct pollfd *ufds)
{
OPM_NODE_T *node1, *node2;
OPM_SCAN_T *scan;
OPM_CONNECTION_T *conn;
unsigned int maxsize, size;
size = 0;
libopm_check_queue(scanner); /* Move scans from the queue to the live scan list */
libopm_check_establish(scanner); /* Make new connections if possible */
printf("prepoll %d\n", (int)size);
// 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;
printf("%d %d\n", ufds[size].fd, size);
/* 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++;
}
}
printf("mysize %d\n", 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, struct pollfd *ufds, unsigned int ufdssize)
{
OPM_NODE_T *node1, *node2;
OPM_SCAN_T *scan;
OPM_CONNECTION_T *conn;
int i;
printf("after\n");
if (opm_active(scanner) < 1) {
return;
}
printf("list\n");
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))
{
printf("doing something\n");
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);
}
}
}
}
MyFree(ufds);
libopm_check_closed(scanner); /* Check for closed or timed out connections */
}

View file

@ -10,6 +10,7 @@
#define OPM_H
#include "opm_common.h"
#include <sys/poll.h>
/* Stuff to shut up warnings about rcsid being unused. */
#define USE_VAR(var) static char sizeof##var = sizeof(sizeof##var) + sizeof(var)
@ -75,6 +76,10 @@ OPM_ERR_T opm_callback(OPM_T *, int, OPM_CALLBACK_FUNC *, void *);
void opm_cycle(OPM_T *);
void libopm_after_poll(OPM_T *, struct pollfd *, unsigned int );
int libopm_before_poll(OPM_T *, struct pollfd *);
size_t opm_active(OPM_T *);
#endif /* OPM_H */

248
libopm/test.c Normal file
View file

@ -0,0 +1,248 @@
/*
* 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 "modconfig.h"
#include <stdio.h>
#include "opm.h"
#include "opm_error.h"
#include "opm_types.h"
#include "compat.h"
#include <sys/poll.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#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);
printf("test %d\n", size);
printf("ha %d\n", ufds[0].fd);
err = poll(ufds, size, 0);
// printf("poll said %d\n", err);
libopm_after_poll(scanner, ufds, size);
printf("after\n");
switch (err)
{
case -1:
/* error in select/poll */
printf("poll barked\n");
return;
case 0:
/* Nothing to do */
continue;
default:
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);
}
}