Mailing List Archive

NessusClient/nessus plugin_cache.h, 1.2, 1.3 plugin_cache.c, 1.3, 1.4 context.h, 1.12, 1.13 context.c, 1.10, 1.11 comm.c, 1.16, 1.17
Update of /usr/local/cvs/NessusClient/nessus
In directory raccoon.nessus.org:/tmp/cvs-serv62776/nessus

Modified Files:
plugin_cache.h plugin_cache.c context.h context.c comm.c
Log Message:
Avoid unnecessary reloading of the plugin cache when connecting. To
this end we have to store the md5sum read from the cache in the context
and move the logic to determine whether the cache is outdated from
plugin_cache.c to comm.c.


Index: plugin_cache.h
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/plugin_cache.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- plugin_cache.h 4 Feb 2006 00:14:09 -0000 1.2
+++ plugin_cache.h 27 Apr 2006 20:16:47 -0000 1.3
@@ -30,7 +30,7 @@
#define _NESSUSC_PLUGIN_CACHE_H

int plugin_cache_write(struct context*, const char *);
-int plugin_cache_read(struct context *, const char *);
+int plugin_cache_read(struct context *);


#endif

Index: plugin_cache.c
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/plugin_cache.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- plugin_cache.c 11 Apr 2006 15:23:26 -0000 1.3
+++ plugin_cache.c 27 Apr 2006 20:16:47 -0000 1.4
@@ -532,22 +532,19 @@
}


-/* Read the file header and check the md5sum
+/* Read the file header
*
* The file header is the first line of the file with the md5sum for the
* md5sum originally reported by the server.
*
* If the header could not be read successfully, the function returns a
- * value < 0.
- *
- * If the header could be read, but the md5sums are different, the
- * function returns 1.
+ * value < 0. Otherwise the return value is 0.
*
- * if the header could be read and the md5sums are equal, the function
- * returns 0.
+ * The md5sum will be stored in a string newly allocated with emalloc in
+ * *server_md5sum.
*/
static int
-check_header(FILE * file, const char * server_md5sum)
+check_header(FILE * file, char ** server_md5sum)
{
char *items[MAX_HEADER_ITEMS];
int nitems = read_cache_line(file, items, MAX_HEADER_ITEMS);
@@ -581,15 +578,7 @@
}
else
{
- /* compare the md5sums */
- if (strcmp(server_md5sum, items[2]) == 0)
- {
- result = 0;
- }
- else
- {
- result = 1;
- }
+ *server_md5sum = estrdup(items[2]);
}
}
else
@@ -619,13 +608,14 @@
* outdated.
*/
int
-plugin_cache_read(struct context * context, const char * server_md5sum)
+plugin_cache_read(struct context * context)
{
int result = 0;
int is_current = 0;
int end_found = 0;
char *filename;
FILE *file;
+ char *server_md5sum = NULL;

filename = plugin_cache_get_filename(context);
if (!filename)
@@ -648,14 +638,10 @@
}

/* check the header and compare md5sums */
- result = is_current = check_header(file, server_md5sum);
+ result = is_current = check_header(file, &server_md5sum);
if (result < 0)
goto fail;

- /* read the cache even if it's outdated so that we hopefully only have
- * to fetch individual plugins later */
- result = 0;
-
/* read the rest of the lines */
while (result == 0)
{
@@ -715,8 +701,11 @@
efree(&items[0]);
}

+ context_set_plugins_md5sum(context, server_md5sum);
+
fail:
efree(&filename);
+ efree(&server_md5sum);
if (file != NULL)
fclose(file);
return result ? result : is_current;

Index: context.h
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/context.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- context.h 27 Apr 2006 19:54:53 -0000 1.12
+++ context.h 27 Apr 2006 20:16:47 -0000 1.13
@@ -46,6 +46,7 @@
context_action action;

struct arglist *prefs;
+ char * plugins_md5sum;
struct nessus_plugin *plugins;
struct nessus_plugin *scanners;
struct arglist *dependencies;
@@ -85,6 +86,7 @@
void context_reset_plugin_tree(struct context*);
void context_add_plugin(struct context*, struct nessus_plugin*);
void context_load_plugin_cache(struct context *context);
+void context_set_plugins_md5sum(struct context *context, const char *md5sum);
void context_reset_plugins(struct context *context);
#ifdef USE_GTK
void context_collect(struct context*);

Index: context.c
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/context.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- context.c 27 Apr 2006 19:54:53 -0000 1.10
+++ context.c 27 Apr 2006 20:16:47 -0000 1.11
@@ -43,6 +43,7 @@
(*context)->parent = parent;
(*context)->type = parent?parent->type+1:CONTEXT_GLOBAL;
(*context)->prefs = NULL;
+ (*context)->plugins_md5sum = NULL;
(*context)->plugins = NULL;
(*context)->scanners = NULL;
(*context)->dependencies = NULL;
@@ -107,6 +108,7 @@
nessus_plugin_free(context->scanners);
context->plugins = NULL;
context->scanners = NULL;
+ efree(&context->plugins_md5sum);
context_reset_plugin_tree(context);
}

@@ -152,6 +154,13 @@
}


+void
+context_set_plugins_md5sum(struct context *context, const char *md5sum)
+{
+ efree(&context->plugins_md5sum);
+ context->plugins_md5sum = estrdup(md5sum);
+}
+
#ifdef USE_GTK
struct context **
context_find_child_ptr(context, child)
@@ -587,7 +596,7 @@
* ignore this as the most likely reason is that there simply isn't
* any plugin cache stored with the report, but it would be nicer to
* produce a message about it. */
- plugin_cache_read(context, "");
+ plugin_cache_read(context);
context->report_plugin_cache_loaded = 1;
fill_plugin_prefs(context);
context_reset_plugin_tree(context);

Index: comm.c
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/comm.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- comm.c 27 Apr 2006 19:54:53 -0000 1.16
+++ comm.c 27 Apr 2006 20:16:48 -0000 1.17
@@ -1144,7 +1144,13 @@
char * server_md5sum = NULL;
int cache_status = -1;

- context_reset_plugins(context);
+ /* without the plugins_md5sum we can't reliably update the plugins
+ * incrementally, so we have to make sure that all of the plugins are
+ * reloaded */
+ if (context->plugins_md5sum == NULL)
+ {
+ context_reset_plugins(context);
+ }

bufsz = 1024 * 1024;
buf = emalloc(bufsz);
@@ -1174,7 +1180,15 @@
}

/* Read and check the cache */
- cache_status = plugin_cache_read(context, server_md5sum);
+ if (context->plugins_md5sum == NULL)
+ {
+ cache_status = plugin_cache_read(context);
+ }
+ else
+ {
+ /* The cache was already loaded */
+ cache_status = 0;
+ }
if (cache_status < 0)
{
/* the cache could not be read for some reason. Most likely an
@@ -1182,14 +1196,22 @@
network_printf(context->socket, "CLIENT <|> COMPLETE_LIST <|> CLIENT\n");
network_gets(context->socket, buf, 27);
}
- else if (cache_status > 0)
+ else if (strcmp(context->plugins_md5sum, server_md5sum) != 0)
{
+ /* the cache is outdated so we update the individual plugins. We
+ * set the plugins_md5sum temporarily to a different value because
+ * neither the old md5sum nor the new md5sum just read from the
+ * server correspond to the plugin information in the context
+ * while the update is being performed.
+ */
+ context_set_plugins_md5sum(context, "");
if (update_individual_plugins(context, buf, bufsz) < 0)
{
show_error(_("Error while updating the cached plugin information"));
result = -1;
goto fail;
}
+ context_set_plugins_md5sum(context, server_md5sum);
}
}

@@ -1197,6 +1219,7 @@
* md5sum in the first place or if the cache wasn't current. */
if (strncmp(buf, "SERVER <|> PLUGIN_LIST <|>", 26) == 0)
{
+ context_reset_plugins(context);
for(;;)
{
comm_update_ui(context, COMM_GET_PLUGINS);
@@ -1230,6 +1253,7 @@
* it should continue. Also, write the cache. */
if (server_md5sum != NULL)
{
+ context_set_plugins_md5sum(context, server_md5sum);
plugin_cache_write(context, server_md5sum);
network_printf(context->socket, "CLIENT <|> GO ON <|> CLIENT\n");
}

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