[packagekit] [PATCH] Allow plugins to override PolicyKit action IDs

Colin Watson cjwatson at ubuntu.com
Wed Jul 17 04:48:29 PDT 2013


On Tue, Jul 16, 2013 at 03:03:15PM +0100, Richard Hughes wrote:
> On 16 July 2013 14:07, Colin Watson <cjwatson at ubuntu.com> wrote:
> > much the same way that Matthias handles the Listaller plugin - is
> > that OK?  I realise it means I have to keep up with PK API changes.
> 
> Yes, that's fine. I can provide a pkgconfig file if that makes things easier.

There's packagekit-plugin.pc, which seems adequate.

> > That's a point I hadn't thought of, but I think it can be handled with
> > just a bit more care in the plugin: only change the action if all
> > packages requested belong to the plugin.  If the user asks to install
> > both Click packages and system packages in a single transaction, then we
> > can ask for admin auth (or whatever's configured) and that will be
> > adequate for both.
> 
> Sure, I guess that works.

OK.  My current implementation looks like this, FWIW:

  const gchar *
  pk_plugin_transaction_get_action (PkPlugin *plugin, PkTransaction *transaction,
                                    const gchar *action_id)
  {
          const gchar *install_actions[] = {
                  "org.freedesktop.packagekit.package-install",
                  "org.freedesktop.packagekit.package-install-untrusted",
                  NULL
          };
          const gchar **install_action;
          gchar **full_paths;
          gint i;
  
          if (!action_id)
                  return NULL;
  
          for (install_action = install_actions; *install_action;
               ++install_action) {
                  if (strcmp (action_id, *install_action) == 0) {
                          /* Use an action with weaker auth requirements if
                           * and only if all the packages in the list are
                           * Click packages.
                           */
                          full_paths = pk_transaction_get_full_paths
                                  (transaction);
                          for (i = 0; full_paths[i]; ++i) {
                                  if (!click_is_click_package (full_paths[i]))
                                          break;
                          }
                          if (!full_paths[i])
                                  return "com.ubuntu.click.package-install";
                  }
          }
  
          return action_id;
  }

On 0.7, this also requires backporting part of
e37591aee89839b44119669b4faa2164511e051a from master, to call
pk_transaction_set_full_paths before pk_transaction_obtain_authorization
in pk_transaction_install_files; and of course it will require extra
code to handle the InstallPackages case when I get that far.  But the
general idea is simple enough.

Is there anything else I need to address before this could go into
master?

Thanks,

-- 
Colin Watson                                       [cjwatson at ubuntu.com]


More information about the PackageKit mailing list