[packagekit] packagekit: Branch 'master' - 11 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Oct 16 13:29:03 PDT 2007


 HACKING                            |   85 ++++++++++++++++++++++++++
 TODO                               |    3 
 backends/yum/helpers/yumBackend.py |   13 ----
 client/pk-console.c                |   59 +++++++-----------
 client/pk-monitor.c                |    2 
 docs/config.xsl                    |    1 
 libpackagekit/pk-common.c          |  100 +++++++++++++++++++++++++++++++
 libpackagekit/pk-common.h          |    1 
 libpackagekit/pk-task-list.c       |   31 ++++++---
 libpackagekit/pk-task-list.h       |    4 -
 src/pk-engine.c                    |  118 +++++++++++++++++++++++++++++++++++++
 src/pk-engine.h                    |    1 
 12 files changed, 359 insertions(+), 59 deletions(-)

New commits:
commit d48de972ab2d5e1acc74c6846b239f0452ec3cf6
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 21:27:11 2007 +0100

    be really paranoid about bad chars in user supplied strings

diff --git a/TODO b/TODO
index 50caeba..bb731c8 100644
--- a/TODO
+++ b/TODO
@@ -28,6 +28,3 @@ To do rollbacks sanely in PK we need a few things:
 *** Use resolve for pkcon operations ***
 'pkcon install zsh' should work as well as 'pkcon install "zsh;1.0;i386;repo"'
 
-*** check all user input for bad chars... ***
-Be really paranoid....
-
diff --git a/src/pk-engine.c b/src/pk-engine.c
index b69a405..bf5dc49 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -138,6 +138,7 @@ pk_engine_error_get_type (void)
 			ENUM_ENTRY (PK_ENGINE_ERROR_PACKAGE_ID_INVALID, "PackageIdInvalid"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_SEARCH_INVALID, "SearchInvalid"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_FILTER_INVALID, "FilterInvalid"),
+			ENUM_ENTRY (PK_ENGINE_ERROR_INPUT_INVALID, "InputInvalid"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_INVALID_STATE, "InvalidState"),
 			ENUM_ENTRY (PK_ENGINE_ERROR_INITIALIZE_FAILED, "InitializeFailed"),
 			{ 0, 0, 0 }
@@ -988,6 +989,7 @@ gboolean
 pk_engine_search_check (const gchar *search, GError **error)
 {
 	guint size;
+	gboolean ret;
 
 	/* ITS4: ignore, not used for allocation */
 	size = strlen (search);
@@ -1017,6 +1019,12 @@ pk_engine_search_check (const gchar *search, GError **error)
 			     "Invalid search containing '?'");
 		return FALSE;
 	}
+	ret = pk_validate_input (search);
+	if (ret == FALSE) {
+		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+			     "Invalid search term");
+		return FALSE;
+	}
 	return TRUE;
 }
 
@@ -1028,6 +1036,14 @@ pk_engine_filter_check (const gchar *filter, GError **error)
 {
 	gboolean ret;
 
+	/* check for invalid input */
+	ret = pk_validate_input (filter);
+	if (ret == FALSE) {
+		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+			     "Invalid filter term");
+		return FALSE;
+	}
+
 	/* check for invalid filter */
 	ret = pk_filter_check (filter);
 	if (ret == FALSE) {
@@ -1262,6 +1278,14 @@ pk_engine_resolve (PkEngine *engine, const gchar *tid, const gchar *package, GEr
 		return FALSE;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package);
+	if (ret == FALSE) {
+		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+			     "Invalid input passed to daemon");
+		return FALSE;
+	}
+
 	/* create a new backend */
 	item->backend = pk_engine_backend_new (engine);
 	if (item->backend == NULL) {
@@ -1301,6 +1325,14 @@ pk_engine_get_depends (PkEngine *engine, const gchar *tid, const gchar *package_
 		return FALSE;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				      "Invalid input passed to daemon");
+		return FALSE;
+	}
+
 	/* check package_id */
 	ret = pk_package_id_check (package_id);
 	if (ret == FALSE) {
@@ -1348,6 +1380,14 @@ pk_engine_get_requires (PkEngine *engine, const gchar *tid, const gchar *package
 		return FALSE;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				      "Invalid input passed to daemon");
+		return FALSE;
+	}
+
 	/* check package_id */
 	ret = pk_package_id_check (package_id);
 	if (ret == FALSE) {
@@ -1395,6 +1435,14 @@ pk_engine_get_update_detail (PkEngine *engine, const gchar *tid, const gchar *pa
 		return FALSE;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				      "Invalid input passed to daemon");
+		return FALSE;
+	}
+
 	/* check package_id */
 	ret = pk_package_id_check (package_id);
 	if (ret == FALSE) {
@@ -1442,6 +1490,22 @@ pk_engine_get_description (PkEngine *engine, const gchar *tid, const gchar *pack
 		return FALSE;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				      "Invalid input passed to daemon");
+		return FALSE;
+	}
+
+	/* check package_id */
+	ret = pk_package_id_check (package_id);
+	if (ret == FALSE) {
+		*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
+				      "The package id '%s' is not valid", package_id);
+		return FALSE;
+	}
+
 	/* create a new backend */
 	item->backend = pk_engine_backend_new (engine);
 	if (item->backend == NULL) {
@@ -1542,6 +1606,15 @@ pk_engine_remove_package (PkEngine *engine, const gchar *tid, const gchar *packa
 		return;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				     "Invalid input passed to daemon");
+		dbus_g_method_return_error (context, error);
+		return;
+	}
+
 	/* check package_id */
 	ret = pk_package_id_check (package_id);
 	if (ret == FALSE) {
@@ -1604,6 +1677,15 @@ pk_engine_install_package (PkEngine *engine, const gchar *tid, const gchar *pack
 		return;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				     "Invalid input passed to daemon");
+		dbus_g_method_return_error (context, error);
+		return;
+	}
+
 	/* check package_id */
 	ret = pk_package_id_check (package_id);
 	if (ret == FALSE) {
@@ -1728,6 +1810,15 @@ pk_engine_rollback (PkEngine *engine, const gchar *tid, const gchar *transaction
 		return;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (transaction_id);
+	if (ret == FALSE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				     "Invalid input passed to daemon");
+		dbus_g_method_return_error (context, error);
+		return;
+	}
+
 	/* check with PolicyKit if the action is allowed from this client - if not, set an error */
 	ret = pk_engine_action_is_allowed (engine, context, PK_ROLE_ENUM_ROLLBACK, &error);
 	if (ret == FALSE) {
@@ -1781,6 +1872,15 @@ pk_engine_update_package (PkEngine *engine, const gchar *tid, const gchar *packa
 		return;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (package_id);
+	if (ret == FALSE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				     "Invalid input passed to daemon");
+		dbus_g_method_return_error (context, error);
+		return;
+	}
+
 	/* check package_id */
 	ret = pk_package_id_check (package_id);
 	if (ret == FALSE) {
@@ -1882,6 +1982,15 @@ pk_engine_repo_enable (PkEngine *engine, const gchar *tid, const gchar *repo_id,
 		return;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (repo_id);
+	if (ret == FALSE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				     "Invalid input passed to daemon");
+		dbus_g_method_return_error (context, error);
+		return;
+	}
+
 	/* check with PolicyKit if the action is allowed from this client - if not, set an error */
 	ret = pk_engine_action_is_allowed (engine, context, PK_ROLE_ENUM_REPO_ENABLE, &error);
 	if (ret == FALSE) {
@@ -1936,6 +2045,15 @@ pk_engine_repo_set_data (PkEngine *engine, const gchar *tid, const gchar *repo_i
 		return;
 	}
 
+	/* check for sanity */
+	ret = pk_validate_input (repo_id);
+	if (ret == FALSE) {
+		error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_INPUT_INVALID,
+				     "Invalid input passed to daemon");
+		dbus_g_method_return_error (context, error);
+		return;
+	}
+
 	/* check with PolicyKit if the action is allowed from this client - if not, set an error */
 	ret = pk_engine_action_is_allowed (engine, context, PK_ROLE_ENUM_REPO_SET_DATA, &error);
 	if (ret == FALSE) {
diff --git a/src/pk-engine.h b/src/pk-engine.h
index 06f1af1..d725527 100644
--- a/src/pk-engine.h
+++ b/src/pk-engine.h
@@ -64,6 +64,7 @@ typedef enum
 	PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
 	PK_ENGINE_ERROR_SEARCH_INVALID,
 	PK_ENGINE_ERROR_FILTER_INVALID,
+	PK_ENGINE_ERROR_INPUT_INVALID,
 	PK_ENGINE_ERROR_INVALID_STATE,
 	PK_ENGINE_ERROR_INITIALIZE_FAILED,
 	PK_ENGINE_ERROR_LAST
commit d519939318b933e4b517b4d6b14ae290989022bb
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 21:23:34 2007 +0100

    only wait in pkcon if the command succeeded

diff --git a/client/pk-console.c b/client/pk-console.c
index 6bc6e82..eac675b 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -201,6 +201,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 	const gchar *mode;
 	const gchar *value = NULL;
 	const gchar *details = NULL;
+	gboolean wait = FALSE;
 	guint remove;
 	PkEnumList *elist;
 
@@ -224,8 +225,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_search_name (client, "none", details);
-				pk_client_wait ();
+				wait = pk_client_search_name (client, "none", details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "details") == 0) {
@@ -234,8 +234,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_search_details (client, "none", details);
-				pk_client_wait ();
+				wait = pk_client_search_details (client, "none", details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "group") == 0) {
@@ -244,8 +243,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_search_group (client, "none", details);
-				pk_client_wait ();
+				wait = pk_client_search_group (client, "none", details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "file") == 0) {
@@ -254,8 +252,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_search_file (client, "none", details);
-				pk_client_wait ();
+				wait = pk_client_search_file (client, "none", details);
 				remove = 3;
 			}
 		} else {
@@ -267,8 +264,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			remove = 1;
 			goto out;
 		} else {
-			pk_client_install_package (client, value);
-			pk_client_wait ();
+			wait = pk_client_install_package (client, value);
 			remove = 2;
 		}
 	} else if (strcmp (mode, "remove") == 0) {
@@ -277,8 +273,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			remove = 1;
 			goto out;
 		} else {
-			pk_client_remove_package (client, value, FALSE);
-			pk_client_wait ();
+			wait = pk_client_remove_package (client, value, FALSE);
 			remove = 2;
 		}
 	} else if (strcmp (mode, "update") == 0) {
@@ -287,8 +282,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			remove = 1;
 			goto out;
 		} else {
-			pk_client_update_package (client, value);
-			pk_client_wait ();
+			wait = pk_client_update_package (client, value);
 			remove = 2;
 		}
 	} else if (strcmp (mode, "resolve") == 0) {
@@ -297,8 +291,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			remove = 1;
 			goto out;
 		} else {
-			pk_client_resolve (client, value);
-			pk_client_wait ();
+			wait = pk_client_resolve (client, value);
 			remove = 2;
 		}
 	} else if (strcmp (mode, "enable-repo") == 0) {
@@ -316,7 +309,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			remove = 1;
 			goto out;
 		} else {
-			pk_client_repo_enable (client, value, FALSE);
+			wait = pk_client_repo_enable (client, value, FALSE);
 			remove = 2;
 		}
 	} else if (strcmp (mode, "get") == 0) {
@@ -330,8 +323,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_get_depends (client, details);
-				pk_client_wait ();
+				wait = pk_client_get_depends (client, details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "updatedetail") == 0) {
@@ -340,8 +332,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_get_update_detail (client, details);
-				pk_client_wait ();
+				wait = pk_client_get_update_detail (client, details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "requires") == 0) {
@@ -350,8 +341,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_get_requires (client, details);
-				pk_client_wait ();
+				wait = pk_client_get_requires (client, details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "description") == 0) {
@@ -360,13 +350,11 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 				remove = 2;
 				goto out;
 			} else {
-				pk_client_get_description (client, details);
-				pk_client_wait ();
+				wait = pk_client_get_description (client, details);
 				remove = 3;
 			}
 		} else if (strcmp (value, "updates") == 0) {
-			pk_client_get_updates (client);
-			pk_client_wait ();
+			wait = pk_client_get_updates (client);
 			remove = 2;
 		} else if (strcmp (value, "actions") == 0) {
 			elist = pk_client_get_actions (client);
@@ -379,8 +367,7 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			g_object_unref (elist);
 			remove = 2;
 		} else if (strcmp (value, "repos") == 0) {
-			pk_client_get_repo_list (client);
-			pk_client_wait ();
+			wait = pk_client_get_repo_list (client);
 			remove = 2;
 		} else if (strcmp (value, "groups") == 0) {
 			elist = pk_client_get_groups (client);
@@ -388,22 +375,26 @@ pk_console_parse_multiple_commands (PkClient *client, GPtrArray *array, GError *
 			g_object_unref (elist);
 			remove = 2;
 		} else if (strcmp (value, "transactions") == 0) {
-			pk_client_get_old_transactions (client, 10);
-			pk_client_wait ();
+			wait = pk_client_get_old_transactions (client, 10);
 			remove = 2;
 		} else {
 			g_set_error (error, 0, 0, "invalid get type");
 		}
 	} else if (strcmp (mode, "update-system") == 0) {
-		pk_client_update_system (client);
+		wait = pk_client_update_system (client);
 	} else if (strcmp (mode, "refresh") == 0) {
-		pk_client_refresh_cache (client, FALSE);
+		wait = pk_client_refresh_cache (client, FALSE);
 	} else if (strcmp (mode, "force-refresh") == 0) {
-		pk_client_refresh_cache (client, TRUE);
+		wait = pk_client_refresh_cache (client, TRUE);
 	} else {
 		g_set_error (error, 0, 0, "option not yet supported");
 	}
 
+	/* only wait if success */
+	if (wait == TRUE) {
+		pk_client_wait ();
+	}
+
 out:
 	/* remove the right number of items from the pointer index */
 	g_ptr_array_remove_index (array, 0);
commit b6ed41ce83115b585597a0f3453702d6a375b74f
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 20:14:08 2007 +0100

    add funtionality to validate input

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index e36b427..e5c5d4d 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -114,6 +114,59 @@ out:
 }
 
 /**
+ * pk_validate_input_char:
+ **/
+static gboolean
+pk_validate_input_char (gchar item)
+{
+	switch (item) {
+	case ' ':
+	case '$':
+	case '`':
+	case '\'':
+	case '"':
+	case '^':
+	case '[':
+	case ']':
+	case '{':
+	case '}':
+	case '@':
+	case '#':
+	case '/':
+	case '\\':
+	case '<':
+	case '>':
+	case '|':
+		return FALSE;
+	}
+	return TRUE;
+}
+
+/**
+ * pk_validate_input:
+ **/
+gboolean
+pk_validate_input (const gchar *text)
+{
+	guint i;
+	guint length;
+
+	/* ITS4: ignore, not used for allocation and checked for oversize */
+	length = strlen (text);
+	for (i=0; i<length; i++) {
+		if (i > 1024) {
+			pk_debug ("input too long!");
+			return FALSE;
+		}
+		if (pk_validate_input_char (text[i]) == FALSE) {
+			pk_debug ("invalid char in text!");
+			return FALSE;
+		}
+	}
+	return TRUE;
+}
+
+/**
  * pk_string_id_split:
  *
  * You need to use g_strfreev on the returned value
@@ -237,6 +290,53 @@ libst_common (LibSelfTest *test)
 	}
 
 	/************************************************************
+	 ****************        validate text         **************
+	 ************************************************************/
+	libst_title (test, "validate correct char 1");
+	ret = pk_validate_input_char ('a');
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "validate correct char 2");
+	ret = pk_validate_input_char ('~');
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "validate incorrect char");
+	ret = pk_validate_input_char ('$');
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "validate incorrect text");
+	ret = pk_validate_input ("richard$hughes");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "validate correct text");
+	ret = pk_validate_input ("richardhughes");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************
 	 ****************          string_id         ****************
 	 ************************************************************/
 	libst_title (test, "test pass 1");
diff --git a/libpackagekit/pk-common.h b/libpackagekit/pk-common.h
index 9877227..194cf07 100644
--- a/libpackagekit/pk-common.h
+++ b/libpackagekit/pk-common.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 #define	PK_DBUS_PATH			"/org/freedesktop/PackageKit"
 #define	PK_DBUS_INTERFACE		"org.freedesktop.PackageKit"
 
+gboolean	 pk_validate_input			(const gchar	*text);
 gboolean	 pk_filter_check			(const gchar	*filter);
 gchar		**pk_string_id_split			(const gchar	*id,
 							 guint		 parts);
commit 5283dedcff3b6fc8bcd61f7c9de4443766046662
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 19:13:18 2007 +0100

    don't use pk_task_list_get_lastest, instead use get_length an get_item to avoid exposing the private array data

diff --git a/client/pk-monitor.c b/client/pk-monitor.c
index 457e3c5..e65da20 100644
--- a/client/pk-monitor.c
+++ b/client/pk-monitor.c
@@ -68,7 +68,6 @@ main (int argc, char *argv[])
 {
 	PkTaskList *tlist;
 	gboolean ret;
-	GPtrArray *task_list;
 	GMainLoop *loop;
 	PkConnection *pconnection;
 	gboolean connected;
@@ -122,7 +121,6 @@ main (int argc, char *argv[])
 	if (ret == FALSE) {
 		g_error ("cannot refresh transaction list");
 	}
-	task_list = pk_task_list_get_latest (tlist);
 	pk_task_list_print (tlist);
 
 	g_main_loop_run (loop);
diff --git a/libpackagekit/pk-task-list.c b/libpackagekit/pk-task-list.c
index 88ac84f..352f415 100644
--- a/libpackagekit/pk-task-list.c
+++ b/libpackagekit/pk-task-list.c
@@ -266,16 +266,29 @@ pk_task_list_refresh (PkTaskList *tlist)
 }
 
 /**
- * pk_task_list_get_latest:
- *
- * DO NOT FREE THIS.
+ * pk_task_list_get_size:
  **/
-GPtrArray *
-pk_task_list_get_latest (PkTaskList *tlist)
+guint
+pk_task_list_get_size (PkTaskList *tlist)
 {
-	g_return_val_if_fail (tlist != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_TASK_LIST (tlist), FALSE);
-	return tlist->priv->task_list;
+	g_return_val_if_fail (tlist != NULL, 0);
+	g_return_val_if_fail (PK_IS_TASK_LIST (tlist), 0);
+	return tlist->priv->task_list->len;
+}
+
+/**
+ * pk_task_list_get_item:
+ **/
+PkTaskListItem *
+pk_task_list_get_item (PkTaskList *tlist, guint item)
+{
+	g_return_val_if_fail (tlist != NULL, NULL);
+	g_return_val_if_fail (PK_IS_TASK_LIST (tlist), NULL);
+	if (item >= tlist->priv->task_list->len) {
+		pk_debug ("item too large!");
+		return NULL;
+	}
+	return g_ptr_array_index (tlist->priv->task_list, item);
 }
 
 /**
@@ -336,7 +349,7 @@ pk_task_list_init (PkTaskList *tlist)
 	tlist->priv->task_list = g_ptr_array_new ();
 
 	/* force a refresh so we have valid data*/
-	pk_task_list_get_latest (tlist);
+	pk_task_list_refresh (tlist);
 }
 
 /**
diff --git a/libpackagekit/pk-task-list.h b/libpackagekit/pk-task-list.h
index d03c54b..f5eb779 100644
--- a/libpackagekit/pk-task-list.h
+++ b/libpackagekit/pk-task-list.h
@@ -66,7 +66,9 @@ gboolean	 pk_task_list_print			(PkTaskList	*tlist);
 gboolean	 pk_task_list_free			(PkTaskList	*tlist);
 gboolean	 pk_task_list_contains_role		(PkTaskList	*tlist,
 							 PkRoleEnum	 role);
-GPtrArray	*pk_task_list_get_latest		(PkTaskList	*tlist);
+guint		 pk_task_list_get_size			(PkTaskList	*tlist);
+PkTaskListItem	*pk_task_list_get_item			(PkTaskList	*tlist,
+							 guint		 item);
 
 G_END_DECLS
 
commit ef1018a15a85a41a01047473f8f1215fe9d48cbe
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 19:12:32 2007 +0100

    update TODO

diff --git a/TODO b/TODO
index 29edde6..50caeba 100644
--- a/TODO
+++ b/TODO
@@ -27,3 +27,7 @@ To do rollbacks sanely in PK we need a few things:
 
 *** Use resolve for pkcon operations ***
 'pkcon install zsh' should work as well as 'pkcon install "zsh;1.0;i386;repo"'
+
+*** check all user input for bad chars... ***
+Be really paranoid....
+
commit b67f344af6bcceea275598bb80042c5cb5ba9f00
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 19:11:07 2007 +0100

    add some more details to HACKING

diff --git a/HACKING b/HACKING
index 91f724c..5e037e5 100644
--- a/HACKING
+++ b/HACKING
@@ -14,6 +14,60 @@ Please consider enabling git's default pre-commit hook:
 This hook will run before every checkin, and check your changes for
 suspicious use of whitespace.
 
+In the C files use the following convention.
+The number of spaces and tabs are very important!
+
+	/* map the roles to policykit rules */
+	if (role == PK_ROLE_ENUM_UPDATE_PACKAGE ||
+	    role == PK_ROLE_ENUM_UPDATE_SYSTEM) {
+		policy = "org.freedesktop.packagekit.update";
+	} else if (role == PK_ROLE_ENUM_REMOVE_PACKAGE) {
+		policy = "org.freedesktop.packagekit.remove";
+	}
+
+and please DO NOT use "!" for a null pointer or boolean - it's too easy to miss
+in an audit...
+
+	/* check the search term */
+	ret = pk_engine_search_check (search, error);
+	if (ret == FALSE) {
+		return FALSE;
+	}
+
+Functions are nearly always the same format, gtk-doc is optional:
+
+/**
+ * pk_engine_search_name:
+ **/
+gboolean
+pk_engine_search_name (PkEngine *engine, const gchar *search, GError **error)
+{
+	gboolean ret;
+	PkTransactionItem *item;
+
+	g_return_val_if_fail (engine != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
+
+	return TRUE;
+}
+
+Finally: DO NOT COMMIT TRAILING WHITESPACE.
+
+Security
+--------
+Remember:
+* The daemon is running as the root user
+ - no FIXME or TODO code please
+* If the daemon crashes, then that's a DOS
+* Text from the user (over the dbus interface) is insecure!
+ - even filters and enumerated values can be wrong
+ - users can use dbus-send to do bad stuff as users
+* Never allocate a buffer on user input
+* Output from backends is trusted, they are run from standard locations
+
+Use flawfinder to find obvious security problems. Use "ITS4: ignore" if you are
+totally 100% sure that it's not a problem.
+
 Submitting Patches
 ------------------
 Use 'git format-patch' to generate patches against a checked out copy
@@ -32,3 +86,4 @@ For Example:
 
 Send these patches in an introductory email as attachments to
 packagekit-list at lists.freedesktop.org
+
commit 2c6696725a8ac58fd9fdf0ad32c3b48df42ca79d
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Tue Oct 16 13:58:32 2007 -0400

    HACKING: mention the pre-commit hook for whitespace

diff --git a/HACKING b/HACKING
index eea5ad1..91f724c 100644
--- a/HACKING
+++ b/HACKING
@@ -3,7 +3,16 @@ Hacking PackageKit
 Coding Style
 ------------
 Please stick to the existing coding style.
-Tabs should be set equivalent to 8 spaces.
+Tabs should be hard (not expanded to spaces), and set equivalent to
+8 spaces.
+
+Please consider enabling git's default pre-commit hook:
+
+	$> cd PackageKit
+	$> chmod +x .git/hooks/pre-commit
+
+This hook will run before every checkin, and check your changes for
+suspicious use of whitespace.
 
 Submitting Patches
 ------------------
commit b496d15c569045fdfae340c0ef340597fd2d4327
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Tue Oct 16 13:42:39 2007 -0400

    TODO: add note about pkcon falling back to resolve

diff --git a/TODO b/TODO
index 42de879..29edde6 100644
--- a/TODO
+++ b/TODO
@@ -25,3 +25,5 @@ Have different permissions for signed and unsigned repos.
 To do rollbacks sanely in PK we need a few things:
  * allow transaction data to be changed in _db
 
+*** Use resolve for pkcon operations ***
+'pkcon install zsh' should work as well as 'pkcon install "zsh;1.0;i386;repo"'
commit cc23644fa1844fec29831502faef0b923c6372ca
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Tue Oct 16 09:26:33 2007 -0400

    HACKING: Add a 'Submitting Patches' section

diff --git a/HACKING b/HACKING
index 739058e..eea5ad1 100644
--- a/HACKING
+++ b/HACKING
@@ -4,3 +4,22 @@ Coding Style
 ------------
 Please stick to the existing coding style.
 Tabs should be set equivalent to 8 spaces.
+
+Submitting Patches
+------------------
+Use 'git format-patch' to generate patches against a checked out copy
+of the source.
+
+For Example:
+
+	$> cd PackageKit
+	HACK HACK HACK
+	$> git commit -m "My first commit"
+	HACK HACK HACK
+	$> git commit -m "My second commit"
+	$> git format-patch -M HEAD^^
+	0001-My-first-commit.patch
+	0002-My-second-commit.patch
+
+Send these patches in an introductory email as attachments to
+packagekit-list at lists.freedesktop.org
commit 9ab797a4efcbd0a9c1d68f24693659262d6ea6a9
Author: James Bowes <jbowes at dangerouslyinc.com>
Date:   Tue Oct 16 09:16:51 2007 -0400

    yum: Move _setup_yum calls to _init__, since everything uses it.

diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index 3981486..dda133a 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -51,6 +51,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
     def __init__(self,args):
         PackageKitBaseBackend.__init__(self,args)
         self.yumbase = PackageKitYumBase()
+        self._setup_yum()
 
     def _get_package_ver(self,po):
         ''' return the a ver as epoch:version-release or version-release, if epoch=0'''
@@ -162,7 +163,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.percentage(None)
         
-        self._setup_yum()
         #self.yumbase.conf.cache = 1 # Only look in cache.
         fltlist = filters.split(';')
         found = {}
@@ -314,7 +314,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.percentage(None)
 
-        self._setup_yum()
         name = package.split(';')[0]
         pkg,inst = self._findPackage(package)
         results = {}
@@ -341,7 +340,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(False)
         self.percentage(0)
 
-        self._setup_yum()
         txmbr = self.yumbase.update() # Add all updates to Transaction
         if txmbr:
             self._runYumTransaction()
@@ -355,7 +353,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True);
         self.percentage(0)
 
-        self._setup_yum()
         pct = 0
         try:
             if len(self.yumbase.repos.listEnabled()) == 0:
@@ -387,8 +384,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True);
         self.percentage(None)
 
-        self._setup_yum()
-
         # Get installed packages
         installedByKey = self.yumbase.rpmdb.searchNevra(name=name)
         for pkg in installedByKey:
@@ -412,7 +407,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(False)
         self.percentage(0)
     
-        self._setup_yum()
         pkg,inst = self._findPackage(package)
         if pkg:
             if inst:
@@ -512,7 +506,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.percentage(0)
 
         pkgs_to_inst = []
-        self._setup_yum()
         self.yumbase.conf.gpgcheck=0
         self._localInstall(inst_file)
         try:
@@ -532,7 +525,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(False);
         self.percentage(0)
 
-        self._setup_yum()
         pkg,inst = self._findPackage(package)
         if pkg:
             txmbr = self.yumbase.update(name=pkg.name)
@@ -610,7 +602,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(False);
         self.percentage(0)
 
-        self._setup_yum()
         pkg,inst = self._findPackage( package)
         if pkg and inst:
             txmbr = self.yumbase.remove(name=pkg.name)
@@ -632,7 +623,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.percentage(None)
 
-        self._setup_yum()
         pkg,inst = self._findPackage(package)
         if pkg:
             pkgver = self._get_package_ver(pkg)
@@ -673,7 +663,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         self.allow_interrupt(True)
         self.percentage(None)
 
-        self._setup_yum()
         md = UpdateMetadata()
         # Added extra Update Metadata
         for repo in self.yumbase.repos.listEnabled():
commit 6df03eea8616654de72b36068c0dd3d5200725d2
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 16 18:37:40 2007 +0100

    make the html reference file utf8

diff --git a/docs/config.xsl b/docs/config.xsl
index 1ae0c22..1cb097e 100644
--- a/docs/config.xsl
+++ b/docs/config.xsl
@@ -5,5 +5,6 @@
   <xsl:param name="html.stylesheet" select="'docbook.css'"/>
   <xsl:param name="use.id.as.filename" select="1"/>
   <xsl:param name="chunk.section.depth" select="0"/>
+  <xsl:output method="html" encoding="UTF-8" indent="no"/>
   
 </xsl:stylesheet>



More information about the PackageKit mailing list