[Autosec-devel] sonar/src target.c,1.16,1.17 target.h,1.6,1.7 plugin.c,1.33,1.34 plugin.h,1.42,1.43
Brought to you by:
red0x
From: Jacob F. <ph...@us...> - 2004-04-11 04:57:53
|
Update of /cvsroot/autosec/sonar/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25286/src Modified Files: target.c target.h plugin.c plugin.h Log Message: Changed the way the default ports are pulled from /etc/services - they're only pulled once and then copied to every new target, rather than scanning /etc/services every time for every new target. Index: plugin.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/plugin.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** plugin.c 9 Apr 2004 07:03:28 -0000 1.33 --- plugin.c 11 Apr 2004 04:44:18 -0000 1.34 *************** *** 31,34 **** --- 31,35 ---- #include "plugin.h" + #include "target.h" #include "util.h" #include "error.h" *************** *** 192,195 **** --- 193,199 ---- void *(*plugin_init) (void *); struct stat *my_buf; + + /* fill the port array from /etc/services */ + load_default_ports_array(); /* try to get the owner and mode of sonar */ if((my_buf = get_stats(mthis->my_name)) == NULL) Index: target.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/target.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** target.h 17 Jan 2004 03:12:32 -0000 1.6 --- target.h 11 Apr 2004 04:44:18 -0000 1.7 *************** *** 28,31 **** --- 28,32 ---- target_t *sonar_find_target(sonar_t *this, struct addrinfo *ai); int sonar_add_target(sonar_t * this, char *entry); + void load_default_ports_array(); #ifdef DEBUG Index: target.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/target.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** target.c 8 Apr 2004 21:10:41 -0000 1.16 --- target.c 11 Apr 2004 04:44:18 -0000 1.17 *************** *** 36,39 **** --- 36,40 ---- extern sonar_t mthis; + static int portmask[MAX_PORTS]; static const char rcsid[] = *************** *** 46,60 **** int sonar_add_target(sonar_t * this, char *entry) { ! struct addrinfo *addr; ! target_t *target, *ent; char *hostname; char *ports; char *mask; ! int len,i=0; unsigned int num_ports = 0, num_hosts = 0; int imask = 32; ! assert(this != NULL); ! assert(entry != NULL); len = strlen(entry); --- 47,61 ---- int sonar_add_target(sonar_t * this, char *entry) { ! struct addrinfo *addr; ! target_t *target, *ent; char *hostname; char *ports; char *mask; ! int len,i=0; unsigned int num_ports = 0, num_hosts = 0; int imask = 32; ! assert(this != NULL); ! assert(entry != NULL); len = strlen(entry); *************** *** 252,256 **** if(!*target) *target = Malloc(sizeof(target_t)); ! memset((*target)->ports, PORT_DONTSCAN, 65537); /* get default ports from /etc/services */ if(!ports) --- 253,257 ---- if(!*target) *target = Malloc(sizeof(target_t)); ! memset((*target)->ports, PORT_DONTSCAN, MAX_PORTS); /* get default ports from /etc/services */ if(!ports) *************** *** 263,267 **** { log_write(LOG_DBUG, " setting all ports to scan\n"); ! for( i = 0; i < 65536; i++) { (*target)->ports[i] = PORT_SCAN; --- 264,268 ---- { log_write(LOG_DBUG, " setting all ports to scan\n"); ! for( i = 0; i < MAX_PORTS; i++) { (*target)->ports[i] = PORT_SCAN; *************** *** 299,311 **** } static int load_default_ports(target_t **target) { ! struct servent *se; assert(*target != NULL); (*target)->num_ports = 0; ! while((se = getservent()) != NULL) { ! (*target)->ports[se->s_port] = PORT_SCAN; ! (*target)->num_ports++; } endservent(); --- 300,320 ---- } + void load_default_ports_array() { + struct servent *se; + memset(portmask,PORT_DONTSCAN,MAX_PORTS); + while((se = getservent()) != NULL) + portmask[se->s_port] = PORT_SCAN; + } + static int load_default_ports(target_t **target) { ! int i; assert(*target != NULL); (*target)->num_ports = 0; ! for(i=0;i<MAX_PORTS;i++) { ! (*target)->ports[i] = portmask[i]; ! if(portmask[i] == PORT_SCAN) ! (*target)->num_ports++; } endservent(); Index: plugin.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/plugin.h,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** plugin.h 9 Apr 2004 07:03:28 -0000 1.42 --- plugin.h 11 Apr 2004 04:44:18 -0000 1.43 *************** *** 96,99 **** --- 96,101 ---- //@} + #define MAX_PORTS 65537 + #define PORT_DONTSCAN 0 *************** *** 125,129 **** char *entry; /// list of ports to scan ! int ports[65537]; /// address info, including family, protocol, and socket type struct addrinfo *addrinfo; --- 127,131 ---- char *entry; /// list of ports to scan ! int ports[MAX_PORTS]; /// address info, including family, protocol, and socket type struct addrinfo *addrinfo; |