Mailing List Archive

NessusClient/nessus comm.h,1.3,1.4 comm.c,1.13,1.14
Update of /usr/local/cvs/NessusClient/nessus
In directory raccoon.nessus.org:/tmp/cvs-serv58932/nessus

Modified Files:
comm.h comm.c
Log Message:
Move the code to refactor a preference into a separate function so that
we can use it elsewhere too.


Index: comm.h
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/comm.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- comm.h 11 Feb 2006 01:32:30 -0000 1.3
+++ comm.h 25 Apr 2006 14:52:34 -0000 1.4
@@ -65,5 +65,7 @@
harglst * comm_get_detached_sessions(struct context *);
#endif

+int comm_parse_preference(struct context *, struct arglist *, struct arglist *,
+ struct arglist *, char *, char *);

#endif

Index: comm.c
===================================================================
RCS file: /usr/local/cvs/NessusClient/nessus/comm.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- comm.c 3 Feb 2006 21:00:49 -0000 1.13
+++ comm.c 25 Apr 2006 14:52:34 -0000 1.14
@@ -268,6 +268,165 @@
}


+/* Parse a preference and add it to the context. The preference may
+ * either be anything the server sends in the PREFERENCES message.
+ * Depending on the type of the preferences it will be stored in
+ * serv_prefs, serv_infos or plugs_prefs. If the caller knows that the
+ * preference is a plugin preference the serv_prefs and serv_infos
+ * parameters may be NULL.
+ */
+int
+comm_parse_preference(struct context *context,
+ struct arglist *serv_prefs, struct arglist *serv_infos,
+ struct arglist *plugs_prefs, char *buf, char *value)
+{
+ char *pref;
+ char *v;
+ char *a = NULL, *b = NULL, *c = NULL;
+
+ pref = buf;
+
+ v = emalloc(strlen(value) + 1);
+ strncpy(v, value, strlen(value));
+ a = strchr(pref, '[');
+ if(a)
+ b = strchr(a, ']');
+ if(b)
+ c = strchr(b, ':');
+
+ if ((!a) || (!b) || (!c))
+ {
+#ifdef ENABLE_SAVE_TESTS
+ if (!strcmp(pref, "ntp_save_sessions"))
+ context->sessions_saved = 1;
+ else if (!strcmp(pref, "ntp_detached_sessions"))
+ context->detached_sessions_saved = 1;
+ else
+#endif
+ if (!strncmp(pref, "server_info_", strlen("server_info_")))
+ {
+ if (serv_infos == NULL)
+ {
+ fprintf(stderr, "comm_parse_preference: server info preference given"
+ " but serv_infos is NULL\n");
+ return 0;
+ }
+ arg_add_value(serv_infos, pref, ARG_STRING, strlen(v), v);
+ }
+ else
+ {
+ if (serv_prefs == NULL)
+ {
+ fprintf(stderr, "comm_parse_preference: server preference given"
+ " but serv_prefs is NULL\n");
+ return 0;
+ }
+ /* Don't set the value if set already */
+ if (arg_get_type(serv_prefs, pref) < 0)
+ arg_add_value(serv_prefs, pref, ARG_STRING, strlen(v), v);
+ }
+ }
+ else if (F_quiet_mode)
+ {
+ /*
+ * Note that when using the cli,
+ * the plugin prefs are not stored the same way in memory
+ */
+ if (arg_get_type(plugs_prefs, pref) < 0)
+ {
+ char *x = strchr(v, ';');
+
+ if (!ListOnly && x)
+ x[0] = '\0';
+ arg_add_value(plugs_prefs, pref, ARG_STRING, strlen(v), v);
+ }
+ }
+ else
+ {
+ /* the format of the pref name is xxxx[xxxx] : this is a plugin pref */
+ char *plugname;
+ char *type;
+ char *name;
+ struct arglist *pprefs, *prf;
+ char *fullname = strdup(pref);
+ struct nessus_plugin * plugin = NULL;
+
+ while (fullname[strlen(fullname) - 1] == ' ')
+ fullname[strlen(fullname) - 1] = '\0';
+ a[0] = 0;
+ plugname = emalloc(strlen(pref) + 1);
+ strncpy(plugname, pref, strlen(pref));
+
+ a[0] = '[';
+ a++;
+ b[0] = 0;
+ type = emalloc(strlen(a) + 1);
+ strncpy(type, a, strlen(a));
+ b[0] = ']';
+ c++;
+ name = emalloc(strlen(c) + 1);
+ strncpy(name, c, strlen(c));
+
+ plugin = nessus_plugin_get_by_name(context->plugins, plugname);
+ if (plugin == NULL)
+ {
+ plugin = nessus_plugin_get_by_name(context->scanners, plugname);
+ if (plugin == NULL)
+ {
+ fprintf(stderr,
+ _("Error : we received a preference (%s) for the plugin %s\n"),
+ name, plugname);
+ fprintf(stderr,
+ _("but apparently the server has not loaded it\n"));
+ return 0;
+ }
+ }
+ pprefs = plugin->plugin_prefs;
+ if (pprefs == NULL)
+ {
+ pprefs = emalloc(sizeof(struct arglist));
+ plugin->plugin_prefs = pprefs;
+ }
+
+ if (arg_get_value(pprefs, name) == NULL)
+ {
+ char * value = NULL;
+
+ prf = emalloc(sizeof(struct arglist));
+
+ /*
+ * No default value for files to upload (we don't want the
+ * server to suggest we upload /etc/shadow ;)
+ */
+
+ if (arg_get_type(plugs_prefs, fullname) == ARG_INT)
+ {
+ int d = (int)arg_get_value(plugs_prefs, fullname);
+ if (d == 0) value = "no";
+ else value = "yes";
+ }
+ else if (arg_get_type(plugs_prefs, fullname) == ARG_STRING)
+ value = arg_get_value(plugs_prefs, fullname);
+ else
+ {
+ if (!strcmp(type, PREF_FILE))
+ value = "";
+ else
+ value = v;
+ }
+
+ arg_add_value(prf, "value", ARG_STRING, strlen(value), value);
+ arg_add_value(prf, "type", ARG_STRING, strlen(type), type);
+ arg_add_value(prf, "fullname", ARG_STRING, strlen(fullname), fullname);
+ arg_add_value(pprefs, name, ARG_ARGLIST, -1, prf);
+ }
+ }
+
+ return 0;
+}
+
+
+
/*
* Retrieves the server preferences
* we must make a difference between the prefs of the
@@ -280,7 +439,6 @@
char *buf = emalloc(32768);
int finished = 0;
struct arglist *serv_prefs, *serv_infos, *plugs_prefs = NULL;
- struct nessus_plugin * plugin = NULL;
struct arglist *prefs = context->prefs;

#ifdef ENABLE_SAVE_TESTS
@@ -324,142 +482,16 @@
finished = 1;
else
{
- char *pref;
char *value;
- char *v;
- char *a = NULL, *b = NULL, *c = NULL;
-
- pref = buf;
- v = strchr(buf, '<');
- if(!v)
+ char *v = strchr(buf, '<');
+ if (!v)
continue;
v -= 1;
v[0] = 0;
-
value = v + 5;
- v = emalloc(strlen(value) + 1);
- strncpy(v, value, strlen(value));
- a = strchr(pref, '[');
- if(a)
- b = strchr(a, ']');
- if(b)
- c = strchr(b, ':');
- if((!a) || (!b) || (!c))
- {
-#ifdef ENABLE_SAVE_TESTS
- if(!strcmp(pref, "ntp_save_sessions"))
- context->sessions_saved = 1;
- else if(!strcmp(pref, "ntp_detached_sessions"))
- context->detached_sessions_saved = 1;
- else
-#endif
- if(!strncmp(pref, "server_info_", strlen("server_info_")))
- {
- arg_add_value(serv_infos, pref, ARG_STRING, strlen(v), v);
- }
- else
- {
- /* Don't set the value if set already */
- if(arg_get_type(serv_prefs, pref) < 0)
- arg_add_value(serv_prefs, pref, ARG_STRING, strlen(v), v);
- }
- }
- else if(F_quiet_mode)
- {
- /*
- * Note that when using the cli,
- * the plugin prefs are not stored the same way in memory
- */
- if(arg_get_type(plugs_prefs, pref) < 0)
- {
- char *x = strchr(v, ';');
-
- if(!ListOnly && x)
- x[0] = '\0';
- arg_add_value(plugs_prefs, pref, ARG_STRING, strlen(v), v);
- }
- }
- else
- {
- /* the format of the pref name is xxxx[xxxx] : this is a plugin pref */
- char *plugname;
- char *type;
- char *name;
- struct arglist *pprefs, *prf;
- char *fullname = strdup(pref);

- while(fullname[strlen(fullname) - 1] == ' ')
- fullname[strlen(fullname) - 1] = '\0';
- a[0] = 0;
- plugname = emalloc(strlen(pref) + 1);
- strncpy(plugname, pref, strlen(pref));
-
- a[0] = '[';
- a++;
- b[0] = 0;
- type = emalloc(strlen(a) + 1);
- strncpy(type, a, strlen(a));
- b[0] = ']';
- c++;
- name = emalloc(strlen(c) + 1);
- strncpy(name, c, strlen(c));
-
- plugin = nessus_plugin_get_by_name(context->plugins, plugname);
- if( plugin == NULL )
- {
- plugin = nessus_plugin_get_by_name(context->scanners, plugname);
- if(plugin == NULL )
- {
- fprintf(stderr,
- _("Error : we received a preference (%s) for the plugin %s\n"),
- name, plugname);
- fprintf(stderr,
- _("but apparently the server has not loaded it\n"));
- continue;
- }
- }
- pprefs = plugin->plugin_prefs;
- if( pprefs == NULL )
- {
- pprefs = emalloc(sizeof(struct arglist));
- plugin->plugin_prefs = pprefs;
- }
-
- if ( arg_get_value(pprefs, name) == NULL )
- {
- char * value = NULL;
-
-
- prf = emalloc(sizeof(struct arglist));
-
- /*
- * No default value for files to upload (we don't want the
- * server to suggest we upload /etc/shadow ;)
- */
-
- if ( arg_get_type(plugs_prefs, fullname) == ARG_INT )
- {
- int d = (int)arg_get_value(plugs_prefs, fullname);
- if ( d == 0 ) value = "no";
- else value = "yes";
- }
- else if ( arg_get_type(plugs_prefs, fullname) == ARG_STRING )
- value = arg_get_value(plugs_prefs, fullname);
- else
- {
- if(!strcmp(type, PREF_FILE))
- value = "";
- else
- value = v;
- }
-
- arg_add_value(prf, "value", ARG_STRING, strlen(value), value);
-
- arg_add_value(prf, "type", ARG_STRING, strlen(type), type);
- arg_add_value(prf, "fullname", ARG_STRING, strlen(fullname), fullname);
- arg_add_value(pprefs, name, ARG_ARGLIST, -1, prf);
- }
- }
+ comm_parse_preference(context, serv_prefs, serv_infos, plugs_prefs,
+ buf, value);
}
}
}

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