[Openvas-commits] r3438 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed May 20 12:27:44 CEST 2009
Author: mattm
Date: 2009-05-20 12:27:44 +0200 (Wed, 20 May 2009)
New Revision: 3438
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.c
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tasks_fs.h
trunk/openvas-manager/src/tasks_sql.h
Log:
Add task UUIDs.
* src/tasks_fs.h (task_uuid): New function.
(task_id_string): Remove.
(save_tasks, delete_task): Use task_uuid instead of task_id_string.
* src/tasks_sql.h (task_uuid): New function.
(task_id_string): Switch to UUID alternative. Rename task_uuid.
(make_task): Also insert UUID.
(save_tasks, delete_task): Use task_uuid instead of task_id_string.
(find_task): Switch to UUID alternative.
* src/manage.c (make_task_uuid): New function.
(create_report_file, delete_reports): Use task_uuid instead of
task_id_string.
* src/manage.h: Update headers.
* src/omp.c: Use task_uuid instead of task_id_string.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-05-20 09:40:58 UTC (rev 3437)
+++ trunk/openvas-manager/ChangeLog 2009-05-20 10:27:44 UTC (rev 3438)
@@ -1,3 +1,24 @@
+2009-05-20 Matthew Mundell <mmundell at intevation.de>
+
+ Add task UUIDs.
+
+ * src/tasks_fs.h (task_uuid): New function.
+ (task_id_string): Remove.
+ (save_tasks, delete_task): Use task_uuid instead of task_id_string.
+
+ * src/tasks_sql.h (task_uuid): New function.
+ (task_id_string): Switch to UUID alternative. Rename task_uuid.
+ (make_task): Also insert UUID.
+ (save_tasks, delete_task): Use task_uuid instead of task_id_string.
+ (find_task): Switch to UUID alternative.
+
+ * src/manage.c (make_task_uuid): New function.
+ (create_report_file, delete_reports): Use task_uuid instead of
+ task_id_string.
+ * src/manage.h: Update headers.
+
+ * src/omp.c: Use task_uuid instead of task_id_string.
+
2009-05-19 Matthew Mundell <mmundell at intevation.de>
Add real authentication.
Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c 2009-05-20 09:40:58 UTC (rev 3437)
+++ trunk/openvas-manager/src/manage.c 2009-05-20 10:27:44 UTC (rev 3438)
@@ -168,7 +168,7 @@
if (ret)
{
fprintf (stderr,
- "Failed create UUID structure: %s.\n",
+ "Failed to create UUID structure: %s.\n",
uuid_error (ret));
return NULL;
}
@@ -482,6 +482,18 @@
/* General task facilities. */
/**
+ * @brief Make a new universal identifier for a task.
+ *
+ * @return A newly allocated string holding the identifier on success, or NULL
+ * on failure.
+ */
+char*
+make_task_uuid ()
+{
+ return make_report_id ();
+}
+
+/**
* @brief Get the name of the status of a task.
*
* @param[in] task The task.
@@ -552,7 +564,7 @@
static int
create_report_file (task_t task)
{
- const char* id;
+ char* tsk_uuid;
char* report_id;
gchar* user_dir_name;
gchar* dir_name;
@@ -574,7 +586,7 @@
}
#endif
- if (task_id_string (task, &id)) return -2;
+ if (task_uuid (task, &tsk_uuid)) return -2;
user_dir_name = g_build_filename (PREFIX
"/var/lib/openvas/mgr/users/",
@@ -606,10 +618,11 @@
"/var/lib/openvas/mgr/users/",
current_credentials.username,
"tasks",
- id,
+ tsk_uuid,
"reports",
report_id,
NULL);
+ free (tsk_uuid);
symlink_name = g_build_filename (user_dir_name, report_id, NULL);
free (report_id);
@@ -1103,12 +1116,12 @@
static int
delete_reports (task_t task)
{
- const char* id;
+ char* tsk_uuid;
gchar* dir_name;
struct dirent ** names = NULL;
int count, index;
- if (task_id_string (task, &id)) return -1;
+ if (task_uuid (task, &tsk_uuid)) return -1;
if (current_credentials.username == NULL) return -1;
@@ -1116,9 +1129,10 @@
"/var/lib/openvas/mgr/users/",
current_credentials.username,
"tasks",
- id,
+ tsk_uuid,
"reports",
NULL);
+ free (tsk_uuid);
count = scandir (dir_name, &names, NULL, alphasort);
if (count < 0)
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2009-05-20 09:40:58 UTC (rev 3437)
+++ trunk/openvas-manager/src/manage.h 2009-05-20 10:27:44 UTC (rev 3438)
@@ -191,7 +191,7 @@
task_id (task_t);
int
-task_id_string (task_t, /*@out@*/ const char **);
+task_uuid (task_t, /*@out@*/ char **);
char*
task_name (task_t);
@@ -310,6 +310,9 @@
/* General task facilities. */
+char*
+make_task_uuid ();
+
const char*
task_run_status_name (task_t task);
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-05-20 09:40:58 UTC (rev 3437)
+++ trunk/openvas-manager/src/omp.c 2009-05-20 10:27:44 UTC (rev 3438)
@@ -850,7 +850,7 @@
*
* @param[in] task The task.
*
- * @return 0 success, -1 task name error, -2 credentials missing,
+ * @return 0 success, -1 task ID error, -2 credentials missing,
* failed to open task dir, -4 out of space in to_client.
*/
static int
@@ -859,24 +859,27 @@
// FIX Abstract report iterator and move it to manage.c.
gchar* dir_name;
- const char* id;
+ char* tsk_uuid;
struct dirent ** names;
int count, index;
gchar* msg;
- // FIX return error code?
- if (task_id_string (task, &id)) return -1;
+ if (task_uuid (task, &tsk_uuid)) return -1;
- // FIX return error code
- if (current_credentials.username == NULL) return -2;
+ if (current_credentials.username == NULL)
+ {
+ free (tsk_uuid);
+ return -2;
+ }
dir_name = g_build_filename (PREFIX
"/var/lib/openvas/mgr/users/",
current_credentials.username,
"tasks",
- id,
+ tsk_uuid,
"reports",
NULL);
+ free (tsk_uuid);
count = scandir (dir_name, &names, NULL, alphasort);
if (count < 0)
@@ -995,8 +998,10 @@
case CLIENT_ABORT_TASK:
if (current_task_task_id)
{
+ task_t task;
+
assert (current_client_task == (task_t) NULL);
- task_t task;
+
if (find_task (current_task_task_id, &task))
SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
"<status>407</status>"
@@ -1201,6 +1206,7 @@
case CLIENT_DELETE_REPORT:
assert (strncasecmp ("DELETE_REPORT", element_name, 13) == 0);
SEND_TO_CLIENT_OR_FAIL ("<delete_report_response>");
+ // FIX current_uuid
if (current_task_task_id)
{
int ret = delete_report (current_task_task_id);
@@ -1483,24 +1489,36 @@
case CLIENT_NEW_TASK:
{
- gchar* msg;
+ char* tsk_uuid;
+
assert (strncasecmp ("NEW_TASK", element_name, 7) == 0);
assert (current_client_task != (task_t) NULL);
+
// FIX if all rqrd fields given then ok, else respond fail
// FIX only here should the task be added to tasks
// eg on err half task could be saved (or saved with base64 file)
- msg = g_strdup_printf ("<new_task_response>"
- "<status>201</status>"
- "<task_id>%u</task_id>"
- "</new_task_response>",
- task_id (current_client_task));
- if (send_to_client (msg))
+
+ if (task_uuid (current_client_task, &tsk_uuid))
+ SEND_TO_CLIENT_OR_FAIL ("<new_task_response>"
+ "<status>400</status>"
+ "</new_task_response>");
+ else
{
+ gchar* msg;
+ msg = g_strdup_printf ("<new_task_response>"
+ "<status>201</status>"
+ "<task_id>%s</task_id>"
+ "</new_task_response>",
+ tsk_uuid);
+ free (tsk_uuid);
+ if (send_to_client (msg))
+ {
+ g_free (msg);
+ error_send_to_client (error);
+ return;
+ }
g_free (msg);
- error_send_to_client (error);
- return;
}
- g_free (msg);
current_client_task = (task_t) NULL;
set_client_state (CLIENT_AUTHENTIC);
break;
@@ -1568,40 +1586,53 @@
"<status>407</status>");
else
{
- int ret;
- gchar* response;
- char* name = task_name (task);
- SEND_TO_CLIENT_OR_FAIL ("<status_response><status>200</status>");
- response = g_strdup_printf ("<task_id>%u</task_id>"
- "<identifier>%s</identifier>"
- "<status>%s</status>"
- "<messages>"
- "<debug>%i</debug>"
- "<hole>%i</hole>"
- "<info>%i</info>"
- "<log>%i</log>"
- "<warning>%i</warning>"
- "</messages>"
- "<report_count>%u</report_count>",
- task_id (task),
- name,
- task_run_status_name (task),
- task_debugs_size (task),
- task_holes_size (task),
- task_infos_size (task),
- task_logs_size (task),
- task_notes_size (task),
- task_report_count (task));
- ret = send_to_client (response);
- g_free (response);
- g_free (name);
- if (ret)
+ char* tsk_uuid;
+
+ if (task_uuid (task, &tsk_uuid))
+ SEND_TO_CLIENT_OR_FAIL ("<status_response>"
+ "<status>400</status>"
+ "</status_response>");
+ else
{
- error_send_to_client (error);
- return;
+ int ret;
+ gchar* response;
+ char* name;
+
+ name = task_name (task);
+ response = g_strdup_printf ("<status_response>"
+ "<status>200</status>"
+ "<task_id>%s</task_id>"
+ "<identifier>%s</identifier>"
+ "<status>%s</status>"
+ "<messages>"
+ "<debug>%i</debug>"
+ "<hole>%i</hole>"
+ "<info>%i</info>"
+ "<log>%i</log>"
+ "<warning>%i</warning>"
+ "</messages>"
+ "<report_count>%u</report_count>",
+ tsk_uuid,
+ name,
+ task_run_status_name (task),
+ task_debugs_size (task),
+ task_holes_size (task),
+ task_infos_size (task),
+ task_logs_size (task),
+ task_notes_size (task),
+ task_report_count (task));
+ ret = send_to_client (response);
+ g_free (response);
+ g_free (name);
+ g_free (tsk_uuid);
+ if (ret)
+ {
+ error_send_to_client (error);
+ return;
+ }
+ // FIX need to handle err cases before send status
+ (void) send_reports (task);
}
- // FIX need to handle err cases before send status
- (void) send_reports (task);
}
free_string_var (¤t_task_task_id);
}
@@ -1627,8 +1658,13 @@
{
gchar* line;
char* name = task_name (index);
+ char* tsk_uuid;
+
+ // FIX buffer entire response so this can respond on err
+ if (task_uuid (index, &tsk_uuid)) abort ();
+
line = g_strdup_printf ("<task>"
- "<task_id>%u</task_id>"
+ "<task_id>%s</task_id>"
"<identifier>%s</identifier>"
"<status>%s</status>"
"<messages>"
@@ -1639,7 +1675,7 @@
"<warning>%i</warning>"
"</messages>"
"</task>",
- task_id (index),
+ tsk_uuid,
name,
task_run_status_name (index),
task_debugs_size (index),
@@ -1648,6 +1684,7 @@
task_logs_size (index),
task_notes_size (index));
free (name);
+ free (tsk_uuid);
if (send_to_client (line))
{
g_free (line);
Modified: trunk/openvas-manager/src/tasks_fs.h
===================================================================
--- trunk/openvas-manager/src/tasks_fs.h 2009-05-20 09:40:58 UTC (rev 3437)
+++ trunk/openvas-manager/src/tasks_fs.h 2009-05-20 10:27:44 UTC (rev 3438)
@@ -63,6 +63,8 @@
/**
* @brief Initialize the manage library.
*
+ * \todo TODO: Implement.
+ *
* @return 0 on success, else -1.
*/
int
@@ -70,8 +72,6 @@
{
/* Set requested and running tasks to stopped. */
- // TODO: Implement.
-
return 0;
}
@@ -158,27 +158,21 @@
}
/**
- * @brief Return a string version of the ID of a task.
+ * @brief Return the UUID of a task.
*
+ * \todo TODO: Implement FS task UUIDs.
+ *
* @param[in] task Task.
* @param[out] id Pointer to a string. On successful return contains a
- * pointer to a static buffer with the task ID as a string.
- * The static buffer is overwritten across successive calls.
+ * pointer to a newly allocated buffer with the task ID
+ * as a string.
*
* @return 0 success, -1 error.
*/
int
-task_id_string (task_t task, const char ** id)
+task_uuid (task_t task, char ** id)
{
- static char buffer[11]; /* (expt 2 32) => 4294967296 */
- int length = snprintf (buffer, 11, "%010u", task->id);
- assert (length < 11);
- if (length < 1 || length > 10)
- {
- *id = NULL;
- return -1;
- }
- *id = buffer;
+ *id = g_strdup_printf ("%010u", task->id);
return 0;
}
@@ -1043,19 +1037,20 @@
{
if (index->name)
{
- const char* id;
+ char* tsk_uuid;
gchar* file_name;
tracef (" %u\n", index->id);
- if (task_id_string (index, &id))
+ if (task_uuid (index, &tsk_uuid))
{
g_free (dir_name);
return -1;
}
file_name = g_build_filename (dir_name,
- id,
+ tsk_uuid,
NULL);
+ free (tsk_uuid);
if (save_task (index, file_name))
{
g_free (dir_name);
@@ -1163,26 +1158,31 @@
delete_task (task_t task)
{
gboolean success;
- const char* id;
+ char* tsk_uuid;
gchar* name;
GError* error;
- tracef (" delete task %u\n", task->id);
+ tracef (" delete task %u\n", task_id (task));
if (current_credentials.username == NULL) return -1;
- if (task_id_string (task, &id)) return -1;
+ if (task_uuid (task, &tsk_uuid)) return -1;
// FIX may be atomic problems here
- if (delete_reports (task)) return -1;
+ if (delete_reports (task))
+ {
+ free (tsk_uuid);
+ return -1;
+ }
name = g_build_filename (PREFIX
"/var/lib/openvas/mgr/users/",
current_credentials.username,
"tasks",
- id,
+ tsk_uuid,
NULL);
+ free (tsk_uuid);
error = NULL;
success = rmdir_recursively (name, &error);
if (success == FALSE)
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-05-20 09:40:58 UTC (rev 3437)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-05-20 10:27:44 UTC (rev 3438)
@@ -501,27 +501,20 @@
}
/**
- * @brief Return a string version of the ID of a task.
+ * @brief Return the UUID of a task.
*
* @param[in] task Task.
- * @param[out] id Pointer to a string.
+ * @param[out] id Pointer to a newly allocated string.
*
* @return 0.
*/
int
-task_id_string (task_t task, const char ** id)
+task_uuid (task_t task, char ** id)
{
-#if 0
- const unsigned char* str;
- str = sql_string (0, 0,
+ *id = sql_string (0, 0,
"SELECT uuid FROM tasks_%s WHERE ROWID = %llu;",
current_credentials.username,
task);
- // FIX caller must free
- *id = (const char*) str;
-#else
- *id = g_strdup_printf ("%llu", task);
-#endif
return 0;
}
@@ -912,14 +905,18 @@
* @param[in] time The period of the task, in seconds.
* @param[in] comment A comment associated the task.
*
- * @return A pointer to the new task or NULL when out of memory (in which
- * case caller must free name and comment).
+ * @return A pointer to the new task or the NULL task on error (in which
+ * case the caller must free name and comment).
*/
task_t
make_task (char* name, unsigned int time, char* comment)
{
- sql ("INSERT into tasks_%s (name, time, comment) VALUES (%s, %u, %s);",
- current_credentials.username, name, time, comment);
+ char* uuid = make_task_uuid ();
+ if (uuid == NULL) return (task_t) NULL;
+ // TODO: Escape name and comment.
+ sql ("INSERT into tasks_%s (uuid, name, time, comment) VALUES (%s, %s, %u, %s);",
+ uuid, current_credentials.username, name, time, comment);
+ free (uuid);
free (name);
free (comment);
return sqlite3_last_insert_rowid (task_db);
@@ -1047,7 +1044,7 @@
delete_task (task_t task)
{
gboolean success;
- const char* id;
+ char* tsk_uuid;
gchar* name;
GError* error;
@@ -1055,7 +1052,7 @@
if (current_credentials.username == NULL) return -1;
- if (task_id_string (task, &id)) return -1;
+ if (task_uuid (task, &tsk_uuid)) return -1;
// FIX may be atomic problems here
@@ -1067,8 +1064,9 @@
"/var/lib/openvas/mgr/users/",
current_credentials.username,
"tasks",
- id,
+ tsk_uuid,
NULL);
+ free (tsk_uuid);
error = NULL;
success = rmdir_recursively (name, &error);
if (success == FALSE)
@@ -1181,28 +1179,9 @@
gboolean
find_task (const char* uuid, task_t* task)
{
-#if 0
*task = sql_int64 (0, 0,
- "SELECT ROWID FROM tasks_%s WHERE uuid = %llu;",
+ "SELECT ROWID FROM tasks_%s WHERE uuid = %s;",
current_credentials.username,
uuid);
return TRUE;
-#else
- int count;
- unsigned long long int result;
- errno = 0;
- result = strtoull (uuid, NULL, 10);
- if (errno) return TRUE;
-
- count = sql_int (0, 0,
- "SELECT count(*) FROM tasks_%s where ROWID = %llu",
- current_credentials.username,
- result);
- if (count == 1)
- {
- *task = result;
- return FALSE;
- }
- return TRUE;
-#endif
}
More information about the Openvas-commits
mailing list