From 26f40757711d5a0a994f66be06bfcb046882c17a Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 6 Jan 2015 21:05:12 +0000 Subject: [PATCH] - Cleaned up style in several places git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/trunk@5325 82007160-df01-0410-b94d-b575c5fd34c7 --- src/libopm/src/config.c | 262 ++++++------ src/libopm/src/libopm.c | 876 ++++++++++++++++++---------------------- src/libopm/src/proxy.c | 184 +++++---- 3 files changed, 611 insertions(+), 711 deletions(-) diff --git a/src/libopm/src/config.c b/src/libopm/src/config.c index 93727de..40b84ea 100644 --- a/src/libopm/src/config.c +++ b/src/libopm/src/config.c @@ -23,6 +23,8 @@ #include "setup.h" +#include + #include "malloc.h" #include "config.h" #include "inet.h" @@ -31,21 +33,19 @@ #include "opm_common.h" #include "list.h" -#include - -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}, +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 @@ -56,57 +56,55 @@ static OPM_CONFIG_HASH_T HASH[] = { * Return: * Pointer to allocated OPM_CONFIG_T struct */ - -OPM_CONFIG_T *libopm_config_create() +OPM_CONFIG_T * +libopm_config_create(void) { - int num, i; - OPM_CONFIG_T *ret; - - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); + int num; + OPM_CONFIG_T *ret; - ret = xcalloc(sizeof(OPM_CONFIG_T)); - ret->vars = xcalloc(sizeof(void *) * num); + num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); + ret = xcalloc(sizeof(OPM_CONFIG_T)); + ret->vars = xcalloc(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 + /* + * 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 (int i = 0; i < num; i++) + { + switch (libopm_config_gettype(i)) + { + case OPM_TYPE_INT: + ret->vars[i] = xcalloc(sizeof(int)); + *(int *)ret->vars[i] = 0; + break; - for(i = 0; i < num; i++) - { - switch(libopm_config_gettype(i)) - { - case OPM_TYPE_INT: - ret->vars[i] = xcalloc(sizeof(int)); - *(int *) ret->vars[i] = 0; - break; - - case OPM_TYPE_STRING: - ret->vars[i] = libopm_xstrdup(""); - break; - - case OPM_TYPE_ADDRESS: - ret->vars[i] = xcalloc(sizeof(opm_sockaddr)); - memset((opm_sockaddr *) ret->vars[i], 0, sizeof(opm_sockaddr)); - break; - - case OPM_TYPE_STRINGLIST: - ret->vars[i] = libopm_list_create(); - break; - default: - ret->vars[i] = NULL; - } - } - return ret; -} + case OPM_TYPE_STRING: + ret->vars[i] = libopm_xstrdup(""); + break; + case OPM_TYPE_ADDRESS: + ret->vars[i] = xcalloc(sizeof(opm_sockaddr)); + memset((opm_sockaddr *) ret->vars[i], 0, sizeof(opm_sockaddr)); + break; + case OPM_TYPE_STRINGLIST: + ret->vars[i] = libopm_list_create(); + break; + default: + ret->vars[i] = NULL; + } + } + return ret; +} /* config_free * @@ -114,46 +112,46 @@ OPM_CONFIG_T *libopm_config_create() * * Parameters: * config: Structure to free/cleanup - * + * * Return: * None */ - -void libopm_config_free(OPM_CONFIG_T *config) +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); -} + int num; + OPM_NODE_T *p, *next; + OPM_LIST_T *list; + + num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); + for (int 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 * @@ -162,87 +160,81 @@ void libopm_config_free(OPM_CONFIG_T *config) * Parameters: * config: Config struct to set parameters on * key: Variable within the struct to set - * value: Address of value 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, const void *value) +OPM_ERR_T +libopm_config_set(OPM_CONFIG_T *config, int key, const void *value) { + int num; + OPM_NODE_T *node; - int num; - OPM_NODE_T *node; + num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - - if(key < 0 || key >= num) - return OPM_ERR_BADKEY; /* Return appropriate error code eventually */ + 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]); - config->vars[key] = libopm_xstrdup(value); - break; + switch (libopm_config_gettype(key)) + { + case OPM_TYPE_STRING: + if ((char *) config->vars[key]) + MyFree(config->vars[key]); - case OPM_TYPE_INT: - *(int *) config->vars[key] = *(const int *) value; - break; + config->vars[key] = libopm_xstrdup(value); + break; - case OPM_TYPE_ADDRESS: - if (inet_pton(AF_INET, value, &(((opm_sockaddr *)config->vars[key])->sa4.sin_addr)) <= 0) - return OPM_ERR_BADVALUE; /* return appropriate err code */ + case OPM_TYPE_INT: + *(int *) config->vars[key] = *(const int *) value; + break; - break; + case OPM_TYPE_ADDRESS: + if (inet_pton(AF_INET, value, &(((opm_sockaddr *)config->vars[key])->sa4.sin_addr)) <= 0) + return OPM_ERR_BADVALUE; /* Return appropriate err code */ - case OPM_TYPE_STRINGLIST: - node = libopm_node_create(libopm_xstrdup(value)); - libopm_list_add((OPM_LIST_T *) config->vars[key], node); - break; + break; - default: - return OPM_ERR_BADKEY; /* return appropriate err code */ - - } + case OPM_TYPE_STRINGLIST: + node = libopm_node_create(libopm_xstrdup(value)); + libopm_list_add((OPM_LIST_T *)config->vars[key], node); + break; - return OPM_SUCCESS; + 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 +libopm_config_gettype(int key) { - int num, i; + int num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); - num = sizeof(HASH) / sizeof(OPM_CONFIG_HASH_T); + for (int i = 0; i < num; i++) + if (HASH[i].key == key) + return HASH[i].type; - for(i = 0; i < num; i++) - if(HASH[i].key == key) - return HASH[i].type; - - return 0; + return 0; } /* config * * Retrieve a specific config variable from - * an OPM_CONFIG_T struct. This is basically a + * an OPM_CONFIG_T struct. This is basically a * wrapper to extracting the variable from the * array. * @@ -254,8 +246,8 @@ int libopm_config_gettype(int key) * -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) +void * +libopm_config(OPM_CONFIG_T *config, int key) { - return config->vars[key]; + return config->vars[key]; } diff --git a/src/libopm/src/libopm.c b/src/libopm/src/libopm.c index 7bcf4dc..5ef6e42 100644 --- a/src/libopm/src/libopm.c +++ b/src/libopm/src/libopm.c @@ -70,7 +70,6 @@ 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 *); @@ -83,56 +82,51 @@ static OPM_REMOTE_T *libopm_setup_remote(OPM_REMOTE_T *, OPM_CONNECTION_T *); * 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} +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 + * + * Return * Pointer to new OPM_T (scanner) */ - -OPM_T *opm_create() +OPM_T * +opm_create(void) { - int i; - OPM_T *ret; - - ret = xcalloc(sizeof *ret); + int i; + OPM_T *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 = xcalloc(sizeof(OPM_CALLBACK_T) * CBLEN); - for(i = 0; i < CBLEN; i++) - { - ret->callbacks[i].func = NULL; - ret->callbacks[i].data = NULL; - } + ret = xcalloc(sizeof *ret); - return 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 = xcalloc(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 * @@ -146,33 +140,29 @@ OPM_T *opm_create() * Address of OPM_REMOTE_T created * */ +OPM_REMOTE_T * +opm_remote_create(const char *ip) +{ + OPM_REMOTE_T *ret; -OPM_REMOTE_T *opm_remote_create(const char *ip) -{ - OPM_REMOTE_T *ret; - - - ret = xcalloc(sizeof *ret); - - /* Do initializations */ - if(ip == NULL) - return NULL; + ret = xcalloc(sizeof *ret); - ret->ip = libopm_xstrdup(ip); + /* Do initializations */ + if (ip == NULL) + return NULL; - ret->port = 0; - ret->protocol = 0; - ret->bytes_read = 0; + ret->ip = libopm_xstrdup(ip); - ret->data = NULL; + ret->port = 0; + ret->protocol = 0; + ret->bytes_read = 0; + ret->data = NULL; - ret->protocols = libopm_list_create(); /* setup protocol list */ + ret->protocols = libopm_list_create(); /* Setup protocol list */ - return ret; + return ret; } - - /* opm_remote_free * * Free OPM_REMOTE_T struct and cleanup @@ -183,32 +173,28 @@ OPM_REMOTE_T *opm_remote_create(const char *ip) * Return: * None */ - -void opm_remote_free(OPM_REMOTE_T *remote) +void +opm_remote_free(OPM_REMOTE_T *remote) { + OPM_NODE_T *p, *next; + OPM_PROTOCOL_CONFIG_T *ppc; - OPM_NODE_T *p, *next; - OPM_PROTOCOL_CONFIG_T *ppc; + MyFree(remote->ip); - MyFree(remote->ip); + LIST_FOREACH_SAFE(p, next, remote->protocols->head) + { + ppc = p->data; - LIST_FOREACH_SAFE(p, next, remote->protocols->head) - { - ppc = p->data; + libopm_protocol_config_free(ppc); + libopm_list_remove(remote->protocols, p); + libopm_node_free(p); + } - libopm_protocol_config_free(ppc); - libopm_list_remove(remote->protocols, p); - libopm_node_free(p); - } + libopm_list_free(remote->protocols); - libopm_list_free(remote->protocols); - - MyFree(remote); + MyFree(remote); } - - - /* opm_callback * Register scanner level callback * @@ -219,20 +205,18 @@ void opm_remote_free(OPM_REMOTE_T *remote) * Error code */ -OPM_ERR_T opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_FUNC *function, void *data) +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; + if (type < 0 || type >= (CBLEN + 1)) + return OPM_ERR_CBNOTFOUND; - scanner->callbacks[type].func = function; - scanner->callbacks[type].data = data; + scanner->callbacks[type].func = function; + scanner->callbacks[type].data = data; - return OPM_SUCCESS; + return OPM_SUCCESS; } - - - /* opm_free * * Free OPM_T (scanner) and cleanup @@ -243,50 +227,49 @@ OPM_ERR_T opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_FUNC *function, vo * Return: * None */ - -void opm_free(OPM_T *scanner) +void +opm_free(OPM_T *scanner) { - OPM_NODE_T *p, *next; - OPM_PROTOCOL_CONFIG_T *ppc; - OPM_SCAN_T *scan; + 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 = p->data; + libopm_config_free(scanner->config); - libopm_protocol_config_free(ppc); - libopm_list_remove(scanner->protocols, p); - libopm_node_free(p); - } + LIST_FOREACH_SAFE(p, next, scanner->protocols->head) + { + ppc = p->data; - LIST_FOREACH_SAFE(p, next, scanner->scans->head) - { - scan = p->data; - libopm_scan_free(scan); - libopm_list_remove(scanner->scans, p); - libopm_node_free(p); - } + libopm_protocol_config_free(ppc); + libopm_list_remove(scanner->protocols, p); + libopm_node_free(p); + } - LIST_FOREACH_SAFE(p, next, scanner->queue->head) - { - scan = p->data; - libopm_scan_free(scan); - libopm_list_remove(scanner->queue, p); - libopm_node_free(p); - } + LIST_FOREACH_SAFE(p, next, scanner->scans->head) + { + scan = p->data; - libopm_list_free(scanner->protocols); - libopm_list_free(scanner->scans); - libopm_list_free(scanner->queue); + libopm_scan_free(scan); + libopm_list_remove(scanner->scans, p); + libopm_node_free(p); + } - MyFree(scanner->callbacks); - MyFree(scanner); -} + LIST_FOREACH_SAFE(p, next, scanner->queue->head) + { + scan = 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 * @@ -301,20 +284,17 @@ void opm_free(OPM_T *scanner) * Return: * OPM_ERR_T containing error code */ - -OPM_ERR_T opm_config(OPM_T *scanner, int key, const void *value) +OPM_ERR_T +opm_config(OPM_T *scanner, int key, const void *value) { - return libopm_config_set((scanner->config), key, value); + return libopm_config_set((scanner->config), key, value); } - - - /* opm_addtype * - * Add a proxy type and port to the list of protocols + * 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) @@ -323,35 +303,32 @@ OPM_ERR_T opm_config(OPM_T *scanner, int key, const void *value) * 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) +OPM_ERR_T +opm_addtype(OPM_T *scanner, int type, unsigned short int port) { - unsigned int i; + unsigned int i; - OPM_NODE_T *node; - OPM_PROTOCOL_CONFIG_T *protocol_config; + 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(); + 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; - protocol_config->type = &OPM_PROTOCOLS[i]; - protocol_config->port = port; - - node = libopm_node_create(protocol_config); - libopm_list_add(scanner->protocols, node); + node = libopm_node_create(protocol_config); + libopm_list_add(scanner->protocols, node); - return OPM_SUCCESS; + return OPM_SUCCESS; + } + } - } - } - return OPM_ERR_BADPROTOCOL; + return OPM_ERR_BADPROTOCOL; } - - /* opm_remote_addtype * * Add a proxy type and port to the list of protocols @@ -365,35 +342,31 @@ OPM_ERR_T opm_addtype(OPM_T *scanner, int type, unsigned short int port) * 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; + unsigned int i; - OPM_NODE_T *node; - OPM_PROTOCOL_CONFIG_T *protocol_config; + 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(); + 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; - protocol_config->type = &OPM_PROTOCOLS[i]; - protocol_config->port = port; + node = libopm_node_create(protocol_config); + libopm_list_add(remote->protocols, node); - node = libopm_node_create(protocol_config); - libopm_list_add(remote->protocols, node); + return OPM_SUCCESS; + } + } - return OPM_SUCCESS; - } - } - return OPM_ERR_BADPROTOCOL; + return OPM_ERR_BADPROTOCOL; } - - - /* libopm_protocol_create * * Create OPM_PROTOCOL_T struct. @@ -406,47 +379,43 @@ OPM_ERR_T opm_remote_addtype(OPM_REMOTE_T *remote, int type, unsigned short int * XXX - does not appear to be used anywhere? * -grifferz */ - #if 0 static OPM_PROTOCOL_T *libopm_protocol_create(void) { - OPM_PROTOCOL_T *ret; - ret = xcalloc(sizeof(OPM_PROTOCOL_T)); - - ret->type = 0; - ret->write_function = NULL; - ret->read_function = NULL; - - return ret; + OPM_PROTOCOL_T *ret; + ret = xcalloc(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 + * 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) +static void +libopm_protocol_free(OPM_PROTOCOL_T *protocol) { - MyFree(protocol); + MyFree(protocol); } #endif - - /* libopm_protocol_config_create * * Allocate and return address of a new OPM_PROTOCOL_CONFIG_T @@ -457,18 +426,15 @@ static void libopm_protocol_free(OPM_PROTOCOL_T *protocol) * Return: * Address of new OPM_PROTOCOL_CONFIG_T */ - -static OPM_PROTOCOL_CONFIG_T *libopm_protocol_config_create(void) +static OPM_PROTOCOL_CONFIG_T * +libopm_protocol_config_create(void) { - OPM_PROTOCOL_CONFIG_T *ret; - ret = xcalloc(sizeof *ret); + OPM_PROTOCOL_CONFIG_T *ret; + ret = xcalloc(sizeof *ret); - return ret; + return ret; } - - - /* protocol_config_free * * Free OPM_PROTOCOL_CONFIG_T struct @@ -479,15 +445,12 @@ static OPM_PROTOCOL_CONFIG_T *libopm_protocol_config_create(void) * Return: * None */ - -static void libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *protocol) +static void +libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *protocol) { - MyFree(protocol); + MyFree(protocol); } - - - /* opm_scan * * Scan remote host. The opm_scan function takes an OPM_REMOTE_T @@ -497,43 +460,37 @@ static void libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *protocol) * 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_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; + 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); + fd_limit = *(int *)libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); - if(LIST_SIZE(scanner->protocols) == 0 && + if (LIST_SIZE(scanner->protocols) == 0 && LIST_SIZE(remote->protocols) == 0) - { - return OPM_ERR_NOPROTOCOLS; - } + return OPM_ERR_NOPROTOCOLS; - scan = libopm_scan_create(scanner, remote); + 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; - } + 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); + node = libopm_node_create(scan); + libopm_list_add(scanner->queue, node); - return OPM_SUCCESS; + return OPM_SUCCESS; } - - - /* opm_end * * End a scan prematurely. @@ -542,53 +499,50 @@ OPM_ERR_T opm_scan(OPM_T *scanner, OPM_REMOTE_T *remote) * scanner: Scanner to end scan on * remote: Pointer to remote struct to search for and end * - * Return: + * Return: * No return. OPM_CALLBACK_END will still be called as normal. */ - -void opm_end(OPM_T *scanner, OPM_REMOTE_T *remote) +void +opm_end(OPM_T *scanner, OPM_REMOTE_T *remote) { - OPM_NODE_T *node1, *node2, *next1, *next2; + OPM_NODE_T *node1, *node2, *next1, *next2; + OPM_SCAN_T *scan; + OPM_CONNECTION_T *conn; - OPM_SCAN_T *scan; - OPM_CONNECTION_T *conn; + /* End active scans */ + opm_endscan(scanner, remote); - /* 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 */ + /* + * 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 = node1->data; - LIST_FOREACH_SAFE(node1, next1, scanner->queue->head) - { - scan = node1->data; - if(scan->remote == remote) + if (scan->remote == remote) + { + /* Free all connections */ + LIST_FOREACH_SAFE(node2, next2, scan->connections->head) { - /* Free all connections */ - LIST_FOREACH_SAFE(node2, next2, scan->connections->head) - { - - conn = 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); + conn = node2->data; - /* Free up the scan */ - libopm_list_remove(scanner->queue, node1); - libopm_scan_free(scan); - libopm_node_free(node1); + 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 * @@ -603,38 +557,34 @@ void opm_end(OPM_T *scanner, OPM_REMOTE_T *remote) * Return: * No return. OPM_CALLBACK_END will still be called as normal. */ - -void opm_endscan(OPM_T *scanner, OPM_REMOTE_T *remote) +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 + 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 = node1->data; + LIST_FOREACH(node1, scanner->scans->head) + { + scan = node1->data; - if(scan->remote == remote) + if (scan->remote == remote) + { + LIST_FOREACH(node2, scan->connections->head) { - LIST_FOREACH(node2, scan->connections->head) - { - conn = (OPM_CONNECTION_T *) node2->data; - conn->state = OPM_STATE_CLOSED; - } + conn = (OPM_CONNECTION_T *) node2->data; + conn->state = OPM_STATE_CLOSED; } - } + } + } } - - - -/* opm_active +/* opm_active Return number of scans in a scanner left. @@ -644,19 +594,17 @@ void opm_endscan(OPM_T *scanner, OPM_REMOTE_T *remote) Return: Number of active scans, both queued and active. */ - -size_t opm_active(OPM_T *scanner) +size_t +opm_active(OPM_T *scanner) { - return LIST_SIZE(scanner->queue) + LIST_SIZE(scanner->scans); + return LIST_SIZE(scanner->queue) + LIST_SIZE(scanner->scans); } - - /* scan_create * * Create new OPM_SCAN_T struct * - * Parameters: + * Parameters: * scanner: Scanner the scan is being created for. This * is needed to get information on currently set * protocols/config. @@ -666,53 +614,49 @@ size_t opm_active(OPM_T *scanner) * Return * Address of new struct */ -static OPM_SCAN_T *libopm_scan_create(OPM_T *scanner, OPM_REMOTE_T *remote) +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; + OPM_SCAN_T *ret; + OPM_CONNECTION_T *conn; + OPM_NODE_T *node, *p; - ret = xcalloc(sizeof *ret); + ret = xcalloc(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(); + ret->remote = remote; + ret->connections = libopm_list_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); - } + /* Setup list of connections, one for each protocol */ + LIST_FOREACH(p, scanner->protocols->head) + { + conn = libopm_connection_create(); - /* Do the same for any specific protocols the remote struct might be configured - with */ + conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; + conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; - LIST_FOREACH(p, remote->protocols->head) - { - conn = libopm_connection_create(); + node = libopm_node_create(conn); - conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; - conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; + libopm_list_add(ret->connections, node); + } - node = libopm_node_create(conn); + /* + * Do the same for any specific protocols the remote struct might be configured with + */ + LIST_FOREACH(p, remote->protocols->head) + { + conn = libopm_connection_create(); - libopm_list_add(ret->connections, node); - } + conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; + conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; - memset(&(ret->addr), 0, sizeof(opm_sockaddr)); + node = libopm_node_create(conn); + libopm_list_add(ret->connections, node); + } - return ret; + memset(&(ret->addr), 0, sizeof(opm_sockaddr)); + return ret; } - - - /* scan_free * * Free and cleanup OPM_SCAN_T struct @@ -723,27 +667,25 @@ static OPM_SCAN_T *libopm_scan_create(OPM_T *scanner, OPM_REMOTE_T *remote) * Return: * None */ - -static void libopm_scan_free(OPM_SCAN_T *scan) +static void +libopm_scan_free(OPM_SCAN_T *scan) { - OPM_NODE_T *p, *next; - OPM_CONNECTION_T *conn; + OPM_NODE_T *p, *next; + OPM_CONNECTION_T *conn; - LIST_FOREACH_SAFE(p, next, scan->connections->head) - { - conn = p->data; - libopm_connection_free(conn); - - libopm_list_remove(scan->connections, p); - libopm_node_free(p); - } - libopm_list_free(scan->connections); - - MyFree(scan); -} + LIST_FOREACH_SAFE(p, next, scan->connections->head) + { + conn = 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 * @@ -755,25 +697,23 @@ static void libopm_scan_free(OPM_SCAN_T *scan) * Return: * Address of new OPM_CONNECTION_T */ - -static OPM_CONNECTION_T *libopm_connection_create(void) +static OPM_CONNECTION_T * +libopm_connection_create(void) { - OPM_CONNECTION_T *ret; - ret = xcalloc(sizeof *ret); + OPM_CONNECTION_T *ret; - ret->fd = 0; - ret->bytes_read = 0; - ret->readlen = 0; - ret->protocol = 0; - ret->port = 0; - - ret->state = OPM_STATE_UNESTABLISHED; - - return ret; -} + ret = xcalloc(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 * @@ -785,13 +725,12 @@ static OPM_CONNECTION_T *libopm_connection_create(void) * Return: * None */ - -static void libopm_connection_free(OPM_CONNECTION_T *conn) +static void +libopm_connection_free(OPM_CONNECTION_T *conn) { - MyFree(conn); + MyFree(conn); } - /* opm_cycle * * Perform tasks (called by client's loop) @@ -801,18 +740,15 @@ static void libopm_connection_free(OPM_CONNECTION_T *conn) * Return: * None */ - -void opm_cycle(OPM_T *scanner) +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 */ + 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 @@ -824,8 +760,8 @@ void opm_cycle(OPM_T *scanner) * Return: * None */ - -static void libopm_check_queue(OPM_T *scanner) +static void +libopm_check_queue(OPM_T *scanner) { OPM_NODE_T *node; OPM_SCAN_T *scan; @@ -861,9 +797,6 @@ static void libopm_check_queue(OPM_T *scanner) } - - - /* check_establish * * Make new connections if there are free file descriptors and connections @@ -874,41 +807,39 @@ static void libopm_check_queue(OPM_T *scanner) * Return: * None */ - -static void libopm_check_establish(OPM_T *scanner) +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; + 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 (LIST_SIZE(scanner->scans) == 0) + return; - if(scanner->fd_use >= fd_limit) - return; + fd_limit = *(int *)libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); - LIST_FOREACH(node1, scanner->scans->head) - { - scan = node1->data; - LIST_FOREACH(node2, scan->connections->head) - { - /* Only scan if we have free file descriptors */ - if(scanner->fd_use >= fd_limit) - return; + if (scanner->fd_use >= fd_limit) + return; - conn = node2->data; - if(conn->state == OPM_STATE_UNESTABLISHED) - libopm_do_connect(scanner, scan, conn); - } - } -} + LIST_FOREACH(node1, scanner->scans->head) + { + scan = node1->data; + LIST_FOREACH(node2, scan->connections->head) + { + /* Only scan if we have free file descriptors */ + if (scanner->fd_use >= fd_limit) + return; + conn = node2->data; + if (conn->state == OPM_STATE_UNESTABLISHED) + libopm_do_connect(scanner, scan, conn); + } + } +} /* check_closed * @@ -925,8 +856,8 @@ static void libopm_check_establish(OPM_T *scanner) * Return: * None */ - -static void libopm_check_closed(OPM_T *scanner) +static void +libopm_check_closed(OPM_T *scanner) { time_t present; @@ -995,9 +926,6 @@ static void libopm_check_closed(OPM_T *scanner) } } - - - /* do_connect * * Call socket() and connect() to start a scan. @@ -1008,8 +936,8 @@ static void libopm_check_closed(OPM_T *scanner) * Return: * None */ - -static void libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +static void +libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { opm_sockaddr *bind_ip; @@ -1058,7 +986,6 @@ static void libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_ time(&(conn->creation)); /* Stamp creation time, for timeout */ } - /* check_poll * * Check sockets for ready read/write @@ -1068,8 +995,8 @@ static void libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_ * Return: * None */ - -static void libopm_check_poll(OPM_T *scanner) +static void +libopm_check_poll(OPM_T *scanner) { OPM_NODE_T *node1, *node2; OPM_SCAN_T *scan; @@ -1164,9 +1091,6 @@ static void libopm_check_poll(OPM_T *scanner) } } - - - /* do_readready * * Remote connection is read ready, read the data into a buffer and check it against @@ -1180,8 +1104,8 @@ static void libopm_check_poll(OPM_T *scanner) * Return: * None */ - -static void libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +static void +libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { int max_read; @@ -1244,15 +1168,12 @@ static void libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION } } - - - /* do_read * * A line of data has been read from the socket, check it against * target string. * - * + * * * Parameters: * scanner: Scanner doing the scan @@ -1262,27 +1183,28 @@ static void libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION * Return: * None */ - -static void libopm_do_read(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +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 = node->data; - if(strstr(conn->readbuf, target_string)) - { - libopm_do_openproxy(scanner, scan, conn); - break; - } - } + 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 = 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 @@ -1296,23 +1218,20 @@ static void libopm_do_read(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *c * Return: * None */ - -static void libopm_do_openproxy(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +static void +libopm_do_openproxy(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - OPM_REMOTE_T *remote; + OPM_REMOTE_T *remote; - remote = scan->remote; + remote = scan->remote; - /* Mark the connection for close */ - conn->state = OPM_STATE_CLOSED; + /* 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); + /* 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 @@ -1326,24 +1245,21 @@ static void libopm_do_openproxy(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION * Return: * None */ - -static void libopm_do_writeready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +static void +libopm_do_writeready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - OPM_PROTOCOL_T *protocol; + OPM_PROTOCOL_T *protocol; - protocol = conn->protocol; + protocol = conn->protocol; - /* Call write function for specific protocol */ - if(protocol->write_function) - protocol->write_function(scanner, scan, conn); + /* 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; + /* Flag as NEGSENT so we don't have to send data again*/ + conn->state = OPM_STATE_NEGSENT; } - - - /* do_hup * * Connection ended prematurely @@ -1356,22 +1272,19 @@ static void libopm_do_writeready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTIO * Return: * None */ - -static void libopm_do_hup(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +static void +libopm_do_hup(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - OPM_REMOTE_T *remote; + OPM_REMOTE_T *remote; - remote = scan->remote; + remote = scan->remote; /* Mark the connection for close */ - conn->state = OPM_STATE_CLOSED; + conn->state = OPM_STATE_CLOSED; - libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_NEGFAIL, 0); + libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_NEGFAIL, 0); } - - - /* do_callback * * Call callback @@ -1384,20 +1297,17 @@ static void libopm_do_hup(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *co * Return: * None */ - -static void libopm_do_callback(OPM_T *scanner, OPM_REMOTE_T *remote, int type, int var) +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; + /* 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); + 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 @@ -1405,16 +1315,16 @@ static void libopm_do_callback(OPM_T *scanner, OPM_REMOTE_T *remote, int type, i * * Parameters: * remote, conn - * + * * Return: * remote */ - -static OPM_REMOTE_T *libopm_setup_remote(OPM_REMOTE_T *remote, OPM_CONNECTION_T *conn) +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; + remote->port = conn->port; + remote->bytes_read = conn->bytes_read; + remote->protocol = conn->protocol->type; - return remote; + return remote; } diff --git a/src/libopm/src/proxy.c b/src/libopm/src/proxy.c index 9a8f29e..14fa3cf 100644 --- a/src/libopm/src/proxy.c +++ b/src/libopm/src/proxy.c @@ -37,18 +37,18 @@ static char SENDBUF[SENDBUFLEN + 1]; -int libopm_proxy_http_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +int +libopm_proxy_http_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - 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; -} + 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 @@ -60,33 +60,32 @@ int libopm_proxy_http_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T * * * 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) +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; - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); + struct in_addr addr; + unsigned long laddr; + int len, scan_port; + char *scan_ip; - if (inet_pton(AF_INET, scan_ip, &addr) <= 0) - ; /* handle error */ + 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); + if (inet_pton(AF_INET, scan_ip, &addr) <= 0) + ; /* handle error */ - 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); + laddr = htonl(addr.s_addr); - send(conn->fd, SENDBUF, (unsigned int)len, 0); + 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); - return OPM_SUCCESS; -} + send(conn->fd, SENDBUF, (unsigned int)len, 0); + return OPM_SUCCESS; +} /* * Send version authentication selection message to socks5 @@ -127,63 +126,63 @@ int libopm_proxy_socks4_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T * * */ - -int libopm_proxy_socks5_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +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; - - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - - if (inet_pton(AF_INET, 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, + struct in_addr addr; + unsigned long laddr; + int len, scan_port; + char *scan_ip; + + scan_ip = (char *)libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); + scan_port = *(int *)libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); + + if (inet_pton(AF_INET, 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); + send(conn->fd, SENDBUF, (unsigned int)len, 0); - return OPM_SUCCESS; + 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 +libopm_proxy_wingate_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - int scan_port, len; - char *scan_ip; + int scan_port, len; + char *scan_ip; - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); + 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); + len = snprintf(SENDBUF, SENDBUFLEN, "%s:%d\r\n", scan_ip, scan_port); + send(conn->fd, SENDBUF, (unsigned int)len, 0); - return OPM_SUCCESS; + return OPM_SUCCESS; } - /* * Cisco scanning * @@ -191,45 +190,44 @@ int libopm_proxy_wingate_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_ * 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 +libopm_proxy_router_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - int len, scan_port; - char *scan_ip; + int len, scan_port; + char *scan_ip; - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); + 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, "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); + len = snprintf(SENDBUF, SENDBUFLEN, "telnet %s %d\r\n", scan_ip, scan_port); + send(conn->fd, SENDBUF, (unsigned int)len, 0); - return OPM_SUCCESS; + return OPM_SUCCESS; } - /* * HTTP POST Scanning * */ - -int libopm_proxy_httppost_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) +int +libopm_proxy_httppost_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) { - int len, scan_port; - char *scan_ip; + int len, scan_port; + char *scan_ip; - scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); - scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); + 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); + 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); + send(conn->fd, SENDBUF, (unsigned int)len, 0); - return OPM_SUCCESS; + return OPM_SUCCESS; } -- 2.30.2