Mailing List Archive

nessus-core/nessusd save_kb.c, 1.55.2.1, 1.55.2.2 save_kb.h, 1.8, 1.8.2.1 attack.c, 1.205.2.7, 1.205.2.8
Update of /usr/local/cvs/nessus-core/nessusd
In directory raccoon.nessus.org:/tmp/cvs-serv33107

Modified Files:
Tag: NESSUS_2_2
save_kb.c save_kb.h attack.c
Log Message:
patch by Hubert Seiwert and Richard Moore (Westpoint.co.uk) : save the KB of a hostname as 'hostname_ip'

Index: save_kb.c
===================================================================
RCS file: /usr/local/cvs/nessus-core/nessusd/save_kb.c,v
retrieving revision 1.55.2.1
retrieving revision 1.55.2.2
diff -u -d -r1.55.2.1 -r1.55.2.2
--- save_kb.c 30 Jan 2006 20:56:57 -0000 1.55.2.1
+++ save_kb.c 17 Jan 2007 14:11:14 -0000 1.55.2.2
@@ -121,9 +121,11 @@
/*----------------------------------------------------------------

From <hostname>, return
- /path/to/var/nessus/<username>/kb/<hostname>
+ /path/to/var/nessus/<username>/kb/<hostname>_<ip>

+ Hubert Seiwert 2006-01-15: added kb_fname_ip()
------------------------------------------------------------------*/
+
static char*
kb_fname(globals, hostname)
struct arglist * globals;
@@ -142,6 +144,27 @@
return ret;
}

+static char*
+kb_fname_ip(globals, hostname, ip)
+ struct arglist * globals;
+ char * hostname;
+ char * ip;
+{
+ char * dir;
+ char * ret;
+ char * hn;
+
+ dir = kb_dirname(globals);
+ hn = strdup(hostname);
+
+ hn = filter_odd_name(hn);
+
+ ret = emalloc(strlen(dir) + strlen(hn) + strlen(ip) + 3);
+ sprintf(ret, "%s/%s_%s", dir, hn, ip);
+ efree(&dir);
+ efree(&hn);
+ return ret;
+}

/*
* mmap() tends to sometimes act weirdly
@@ -395,9 +418,10 @@

-------------------------------------------------------------------*/
int
-save_kb_new(globals, hostname)
+save_kb_new(globals, hostname, ip)
struct arglist * globals;
char * hostname;
+ char * ip;
{
char * fname;
char * dir;
@@ -411,7 +435,7 @@
kb_mkdir(dir);
efree(&dir);

- fname = kb_fname(globals, hostname);
+ fname = kb_fname_ip(globals, hostname, ip);

if(file_locked(fname))
{
@@ -441,12 +465,13 @@


void
-save_kb_close(globals, hostname)
+save_kb_close(globals, hostname, ip)
struct arglist * globals;
char * hostname;
+ char * ip;
{
int fd = (int)arg_get_value(globals, "save_kb");
- char* fname = kb_fname(globals, hostname);
+ char* fname = kb_fname_ip(globals, hostname, ip);
if(fd > 0)close(fd);
file_unlock(fname);
efree(&fname);
@@ -459,11 +484,12 @@
* (returns true if a knowledge base exists)
*/
int
-save_kb_exists(globals, hostname)
+save_kb_exists(globals, hostname, ip)
struct arglist * globals;
char * hostname;
+ char * ip;
{
- char * fname = kb_fname(globals, hostname);
+ char * fname = kb_fname_ip(globals, hostname, ip);
FILE *f;

if(file_locked(fname))
@@ -517,11 +543,12 @@
* Restores a copy of the knowledge base
*/
int
-save_kb_restore_backup(globals, hostname)
+save_kb_restore_backup(globals, hostname, ip)
struct arglist * globals;
char*hostname;
+ char *ip;
{
- char * fname = kb_fname(globals, hostname);
+ char * fname = kb_fname_ip(globals, hostname, ip);
char * bakname;
int fd;

@@ -542,11 +569,12 @@
*/

int
-save_kb_backup(globals, hostname)
+save_kb_backup(globals, hostname, ip)
struct arglist * globals;
char* hostname;
+ char* ip;
{
- char * fname = kb_fname(globals, hostname);
+ char * fname = kb_fname_ip(globals, hostname, ip);
char * newname = NULL;
int fd_src = -1, fd_dst = -1;

@@ -618,11 +646,12 @@
* entries starting by '/tmp/'
*/
struct kb_item **
-save_kb_load_kb(globals, hostname)
+save_kb_load_kb(globals, hostname, ip)
struct arglist * globals;
char * hostname;
+ char * ip;
{
- char * fname = kb_fname(globals, hostname);
+ char * fname = kb_fname_ip(globals, hostname, ip);
FILE * f;
int fd;
struct kb_item ** kb;

Index: save_kb.h
===================================================================
RCS file: /usr/local/cvs/nessus-core/nessusd/save_kb.h,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1
--- save_kb.h 12 Jun 2004 14:12:49 -0000 1.8
+++ save_kb.h 17 Jan 2007 14:11:15 -0000 1.8.2.1
@@ -2,17 +2,17 @@
#define SAVE_KB_H__


-int save_kb_new(struct arglist*, char *);
-void save_kb_close(struct arglist*, char*);
+int save_kb_new(struct arglist*, char *, char *);
+void save_kb_close(struct arglist*, char*, char *);

-int save_kb_backup(struct arglist*, char*);
-int save_kb_restore_backup(struct arglist*, char*);
+int save_kb_backup(struct arglist*, char*, char *);
+int save_kb_restore_backup(struct arglist*, char*, char *);

int save_kb_write_int(struct arglist*, char*, char*, int);
int save_kb_write_str(struct arglist*, char*, char*, char*);

-int save_kb_exists(struct arglist*, char*);
-struct kb_item ** save_kb_load_kb(struct arglist*, char*);
+int save_kb_exists(struct arglist*, char*, char *);
+struct kb_item ** save_kb_load_kb(struct arglist*, char*, char*);

/*
* Preferences set by the user

Index: attack.c
===================================================================
RCS file: /usr/local/cvs/nessus-core/nessusd/attack.c,v
retrieving revision 1.205.2.7
retrieving revision 1.205.2.8
diff -u -d -r1.205.2.7 -r1.205.2.8
--- attack.c 30 Jan 2006 20:56:53 -0000 1.205.2.7
+++ attack.c 17 Jan 2007 14:11:15 -0000 1.205.2.8
@@ -282,10 +282,10 @@
attack_user_name(globals),
hostname);
pluginlaunch_stop();
- if(new_kb)save_kb_close(globals, hostname);
+ if(new_kb)save_kb_close(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP")));
if(kb_item_get_int(kb, "Host/ping_failed") > 0)
{
- save_kb_restore_backup(globals, hostname);
+ save_kb_restore_backup(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP")));
}

plugin_set_running_state(sched, plugin, PLUGIN_STATUS_DONE);
@@ -342,16 +342,16 @@

if(save_kb(globals))
{
- if( save_kb_exists(globals, hostname) != 0 &&
+ if( save_kb_exists(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP"))) != 0 &&
save_kb_pref_restore(globals) != 0 )
{
- save_kb_backup(globals, hostname);
- kb = save_kb_load_kb(globals, hostname);
+ save_kb_backup(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP")));
+ kb = save_kb_load_kb(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP")));
kb_restored = 1;
}
else
{
- save_kb_new(globals, hostname);
+ save_kb_new(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP")));
kb = kb_new();
new_kb = 1;
}
@@ -422,7 +422,7 @@
arg_free(tmp);
pluginlaunch_stop();
plugins_scheduler_free(sched);
- if(new_kb)save_kb_close(globals, hostname);
+ if(new_kb)save_kb_close(globals, hostname, inet_ntoa(*(struct in_addr *)arg_get_value(hostinfos, "IP")));
}

/*-----------------------------------------------------------------
@@ -707,7 +707,7 @@
{
if(save_kb_pref_tested_hosts_only(globals))
{
- if(!save_kb_exists(globals, hostname))
+ if(!save_kb_exists(globals, hostname, inet_ntoa(host_ip)))
{
log_write("user %s : not testing %s because it has never been tested before\n",
attack_user_name(globals),
@@ -724,7 +724,7 @@
else if(save_kb_pref_untested_hosts_only(globals))
{
/* XXX */
- if(save_kb_exists(globals, hostname))
+ if(save_kb_exists(globals, hostname, inet_ntoa(host_ip)))
{
log_write("user %s : not testing %s because it has already been tested before\n",
attack_user_name(globals),

_______________________________________________
Nessus-cvs mailing list
Nessus-cvs@list.nessus.org
http://mail.nessus.org/mailman/listinfo/nessus-cvs