Make ppd-name parameter optional

Readd patch for allowing authentication for any and inactive users
Readd patch for check of result of polkit authorization check
Resolves: #724959
This commit is contained in:
Marek Kasik 2011-09-02 12:10:34 +02:00
parent 130b5d9bec
commit 71ab25b460
10 changed files with 63 additions and 1049 deletions

View File

@ -1,8 +1,8 @@
--- cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-12-02 16:43:41.000000000 +0100
+++ cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-12-03 14:13:47.000000000 +0100
@@ -15,7 +15,8 @@
<description>Set a printer as default printer</description>
<message>Privileges are required to set a printer, or a class, as default printer.</message>
--- cups-pk-helper-0.1.3/src/org.opensuse.cupspkhelper.mechanism.policy.in 2011-07-05 14:07:05.000000000 +0200
+++ cups-pk-helper-0.1.3/src/org.opensuse.cupspkhelper.mechanism.policy.in 2011-09-02 11:34:12.000000000 +0200
@@ -12,7 +12,8 @@
<_description>Get/Set server settings</_description>
<_message>Privileges are required to get/set server settings.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -10,9 +10,9 @@
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -27,7 +28,8 @@
<description>Enable/Disable a printer</description>
<message>Privileges are required to enable/disable a printer, or a class.</message>
@@ -21,7 +22,8 @@
<_description>Get list of available devices</_description>
<_message>Privileges are required to get list of available devices.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -20,9 +20,9 @@
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -36,7 +38,8 @@
<description>Add/Remove/Edit a local printer</description>
<message>Privileges are required to add/remove/edit a local printer.</message>
@@ -33,7 +35,8 @@
<_description>Set a printer as default printer</_description>
<_message>Privileges are required to set a printer, or a class, as default printer.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -31,8 +31,8 @@
</defaults>
</action>
@@ -45,7 +48,8 @@
<description>Add/Remove/Edit a remote printer</description>
<message>Privileges are required to add/remove/edit a remote printer.</message>
<_description>Enable/Disable a printer</_description>
<_message>Privileges are required to enable/disable a printer, or a class.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -41,8 +41,8 @@
</defaults>
</action>
@@ -54,7 +58,8 @@
<description>Add/Remove/Edit a class</description>
<message>Privileges are required to add/remove/edit a class.</message>
<_description>Add/Remove/Edit a local printer</_description>
<_message>Privileges are required to add/remove/edit a local printer.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -51,8 +51,8 @@
</defaults>
</action>
@@ -63,7 +68,8 @@
<description>Get/Set server settings</description>
<message>Privileges are required to get/set server settings.</message>
<_description>Add/Remove/Edit a remote printer</_description>
<_message>Privileges are required to add/remove/edit a remote printer.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -61,8 +61,18 @@
</defaults>
</action>
@@ -72,7 +78,8 @@
<description>Restart/Cancel/Edit a job</description>
<message>Privileges are required to restart/cancel/edit a job.</message>
<_description>Add/Remove/Edit a class</_description>
<_message>Privileges are required to add/remove/edit a class.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
+ <allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -81,7 +88,8 @@
<_description>Restart/Cancel/Edit a job</_description>
<_message>Privileges are required to restart/cancel/edit a job.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -70,19 +80,9 @@
<allow_active>yes</allow_active>
</defaults>
</action>
@@ -81,7 +88,8 @@
<description>Restart/Cancel/Edit a job owned by another user</description>
<message>Privileges are required to restart/cancel/edit a job owned by another user.</message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
+ <allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -90,7 +98,8 @@
<description>Get devices</description>
<message>Privileges are required to get devices.</message>
<_description>Restart/Cancel/Edit a job owned by another user</_description>
<_message>Privileges are required to restart/cancel/edit a job owned by another user.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
@ -90,9 +90,19 @@
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -100,7 +109,8 @@
<description>Add/Remove/Edit a printer</description>
<message>Privileges are required to add/remove/edit a printer.</message>
@@ -99,7 +108,8 @@
<_description>Change printer settings</_description>
<_message>Privileges are required to change printer settings. This should only be needed from the Printers system settings panel.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>
+ <allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -109,7 +119,8 @@
<_description>Add/Remove/Edit a printer</_description>
<_message>Privileges are required to add/remove/edit a printer.</_message>
<defaults>
- <allow_inactive>no</allow_inactive>
+ <allow_any>auth_admin</allow_any>

View File

@ -1,115 +0,0 @@
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c.invalid-job 2010-02-23 13:21:27.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2010-02-23 13:33:08.000000000 +0100
@@ -439,8 +439,11 @@ _cph_mechanism_return_error (CphMechanis
{
const char *error;
- if (failed)
+ if (failed) {
error = cph_cups_last_status_to_string (mechanism->priv->cups);
+ if (!error || error[0] == '\0')
+ error = "Unknown error";
+ }
else
error = "";
@@ -455,8 +458,11 @@ _cph_mechanism_return_error_and_value (C
{
const char *error;
- if (failed)
+ if (failed) {
error = cph_cups_last_status_to_string (mechanism->priv->cups);
+ if (!error || error[0] == '\0')
+ error = "Unknown error";
+ }
else
error = "";
@@ -996,18 +1002,25 @@ cph_mechanism_job_cancel (CphMechanism
case CPH_JOB_STATUS_OWNED_BY_USER: {
if (!_check_polkit_for_action_v (mechanism, context,
"job-edit",
- NULL))
+ NULL)) {
+ g_free (user_name);
return FALSE;
+ }
break;
}
case CPH_JOB_STATUS_NOT_OWNED_BY_USER: {
if (!_check_polkit_for_action (mechanism, context,
- "job-not-owned-edit"))
+ "job-not-owned-edit")) {
+ g_free (user_name);
return FALSE;
+ }
break;
}
- case CPH_JOB_STATUS_INVALID:
+ case CPH_JOB_STATUS_INVALID: {
+ _cph_mechanism_return_error (mechanism, context, TRUE);
+ g_free (user_name);
return FALSE;
+ }
}
ret = cph_cups_job_cancel (mechanism->priv->cups, id, user_name);
@@ -1037,18 +1050,25 @@ cph_mechanism_job_restart (CphMechanism
case CPH_JOB_STATUS_OWNED_BY_USER: {
if (!_check_polkit_for_action_v (mechanism, context,
"job-edit",
- NULL))
+ NULL)) {
+ g_free (user_name);
return FALSE;
+ }
break;
}
case CPH_JOB_STATUS_NOT_OWNED_BY_USER: {
if (!_check_polkit_for_action (mechanism, context,
- "job-not-owned-edit"))
+ "job-not-owned-edit")) {
+ g_free (user_name);
return FALSE;
+ }
break;
}
- case CPH_JOB_STATUS_INVALID:
+ case CPH_JOB_STATUS_INVALID: {
+ _cph_mechanism_return_error (mechanism, context, TRUE);
+ g_free (user_name);
return FALSE;
+ }
}
ret = cph_cups_job_restart (mechanism->priv->cups, id, user_name);
@@ -1079,18 +1099,25 @@ cph_mechanism_job_set_hold_until (CphMec
case CPH_JOB_STATUS_OWNED_BY_USER: {
if (!_check_polkit_for_action_v (mechanism, context,
"job-edit",
- NULL))
+ NULL)) {
+ g_free (user_name);
return FALSE;
+ }
break;
}
case CPH_JOB_STATUS_NOT_OWNED_BY_USER: {
if (!_check_polkit_for_action (mechanism, context,
- "job-not-owned-edit"))
+ "job-not-owned-edit")) {
+ g_free (user_name);
return FALSE;
+ }
break;
}
- case CPH_JOB_STATUS_INVALID:
+ case CPH_JOB_STATUS_INVALID: {
+ _cph_mechanism_return_error (mechanism, context, TRUE);
+ g_free (user_name);
return FALSE;
+ }
}
ret = cph_cups_job_set_hold_until (mechanism->priv->cups, id, job_hold_until, user_name);

View File

@ -1,55 +0,0 @@
--- cups-pk-helper-0.0.4/src/cups.c.job-status 2010-02-23 13:21:27.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups.c 2010-02-23 13:21:27.000000000 +0100
@@ -1787,19 +1787,34 @@ cph_cups_job_get_status (CphCups *cup
int job_id,
const char *user)
{
- CphJobStatus status = CPH_JOB_STATUS_INVALID;
- cups_job_t *jobs;
- int num_jobs;
- int i;
+ const char * const attrs[1] = { "job-originating-user-name" };
+ ipp_t *request;
+ const char *resource_char;
+ ipp_t *reply;
+ ipp_attribute_t *attr;
+ CphJobStatus status = CPH_JOB_STATUS_INVALID;
g_return_val_if_fail (CPH_IS_CUPS (cups), CPH_JOB_STATUS_INVALID);
- num_jobs = cupsGetJobs2 (cups->priv->connection, &jobs, NULL, 0, 0);
+ if (!_cph_cups_is_job_id_valid (cups, job_id))
+ return CPH_JOB_STATUS_INVALID;
+
+ request = ippNewRequest (IPP_GET_JOB_ATTRIBUTES);
+ _cph_cups_add_job_uri (request, job_id);
+ ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes", 1, NULL, attrs);
+
+ resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
+ reply = cupsDoRequest (cups->priv->connection,
+ request, resource_char);
- for (i = 0; i < num_jobs; i++) {
- if (jobs[i].id == job_id) {
- if (user != NULL &&
- g_strcmp0 (jobs[i].user, user) == 0)
+ if (!reply || reply->request.status.status_code > IPP_OK_CONFLICT)
+ return CPH_JOB_STATUS_INVALID;
+
+ for (attr = reply->attrs; attr; attr = attr->next) {
+ if (attr->name &&
+ strcmp (attr->name, "job-originating-user-name") == 0) {
+ if (g_strcmp0 (attr->values[0].string.text, user) == 0)
status = CPH_JOB_STATUS_OWNED_BY_USER;
else
status = CPH_JOB_STATUS_NOT_OWNED_BY_USER;
@@ -1807,7 +1822,7 @@ cph_cups_job_get_status (CphCups *cup
}
}
- cupsFreeJobs (num_jobs, jobs);
+ ippDelete (reply);
return status;
}

View File

@ -1,113 +0,0 @@
--- cups-pk-helper-0.0.4/src/cups.c 2010-03-22 15:41:36.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups.c 2010-03-22 15:41:36.000000000 +0100
@@ -1726,8 +1726,11 @@ cph_cups_server_set_settings (CphCups
gboolean
cph_cups_job_cancel (CphCups *cups,
int job_id,
+ gboolean purge_job,
const char *user_name)
{
+ ipp_t *request;
+
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
if (!_cph_cups_is_job_id_valid (cups, job_id))
@@ -1735,10 +1738,19 @@ cph_cups_job_cancel (CphCups *cups,
/* we don't check if the user name is valid or not because it comes
* from getpwuid(), and not dbus */
- return _cph_cups_send_new_simple_job_request (cups, IPP_CANCEL_JOB,
- job_id,
- user_name,
- CPH_RESOURCE_JOBS);
+ request = ippNewRequest (IPP_CANCEL_JOB);
+ _cph_cups_add_job_uri (request, job_id);
+
+ if (user_name != NULL)
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "requesting-user-name", NULL, user_name);
+
+#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1
+ if (purge_job)
+ ippAddBoolean (request, IPP_TAG_OPERATION, "purge-job", 1);
+#endif
+
+ return _cph_cups_send_request (cups, request, CPH_RESOURCE_JOBS);
}
gboolean
--- cups-pk-helper-0.0.4/src/cups.h 2010-03-22 15:41:36.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups.h 2010-03-22 15:41:36.000000000 +0100
@@ -169,6 +169,7 @@ gboolean cph_cups_is_printer_uri_local (
gboolean cph_cups_job_cancel (CphCups *cups,
int job_id,
+ gboolean purge_job,
const char *user_name);
gboolean cph_cups_job_restart (CphCups *cups,
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2010-03-22 15:41:36.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2010-03-22 15:43:33.000000000 +0100
@@ -988,6 +988,15 @@ cph_mechanism_job_cancel (CphMechanism
int id,
DBusGMethodInvocation *context)
{
+ return cph_mechanism_job_cancel_purge (mechanism, id, FALSE, context);
+}
+
+gboolean
+cph_mechanism_job_cancel_purge (CphMechanism *mechanism,
+ int id,
+ gboolean purge,
+ DBusGMethodInvocation *context)
+{
CphJobStatus job_status;
gboolean ret;
char *user_name;
@@ -1023,7 +1032,7 @@ cph_mechanism_job_cancel (CphMechanism
}
}
- ret = cph_cups_job_cancel (mechanism->priv->cups, id, user_name);
+ ret = cph_cups_job_cancel (mechanism->priv->cups, id, purge, user_name);
_cph_mechanism_return_error (mechanism, context, !ret);
g_free (user_name);
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.h 2010-03-22 15:41:36.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.h 2010-03-22 15:41:36.000000000 +0100
@@ -226,6 +226,12 @@ cph_mechanism_job_cancel (CphMechanism
DBusGMethodInvocation *context);
gboolean
+cph_mechanism_job_cancel_purge (CphMechanism *mechanism,
+ int id,
+ gboolean purge,
+ DBusGMethodInvocation *context);
+
+gboolean
cph_mechanism_job_restart (CphMechanism *mechanism,
int id,
DBusGMethodInvocation *context);
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.xml 2010-03-22 15:41:36.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.xml 2010-03-22 15:44:36.000000000 +0100
@@ -174,12 +174,20 @@
<arg name="error" direction="out" type="s"/>
</method>
+ <!-- JobCancel is deprecated; JobCancelPurge should be used instead -->
<method name="JobCancel">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="jobid" direction="in" type="i"/>
<arg name="error" direction="out" type="s"/>
</method>
+ <method name="JobCancelPurge">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="jobid" direction="in" type="i"/>
+ <arg name="purge" direction="in" type="b"/>
+ <arg name="error" direction="out" type="s"/>
+ </method>
+
<method name="JobRestart">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="jobid" direction="in" type="i"/>

View File

@ -1,29 +0,0 @@
--- cups-pk-helper-0.0.4/src/cups.c 2009-09-30 10:38:21.895761263 +0100
+++ cups-pk-helper-0.0.4/src/cups.c 2009-09-30 10:44:07.794636125 +0100
@@ -2,8 +2,9 @@
* vim: set et ts=8 sw=8:
*
* Copyright (C) 2008 Novell, Inc.
+ * Copyright (C) 2009 Red Hat, Inc.
*
- * Authors: Vincent Untz
+ * Authors: Vincent Untz, Tim Waugh
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -997,11 +998,13 @@ cph_cups_printer_add (CphCups *cups,
ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_NAME,
"printer-name", NULL, printer_name);
- ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_URI,
- "device-uri", NULL, printer_uri);
ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_NAME,
"ppd-name", NULL, ppd_file);
+ if (printer_uri && printer_uri[0] != '\0') {
+ ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_URI,
+ "device-uri", NULL, printer_uri);
+ }
if (info && info[0] != '\0') {
ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_TEXT,
"printer-info", NULL, info);

View File

@ -1,6 +1,6 @@
Name: cups-pk-helper
Version: 0.1.3
Release: 1%{?dist}
Release: 2%{?dist}
Summary: A helper that makes system-config-printer use PolicyKit
Group: System Environment/Base
@ -9,6 +9,9 @@ URL: http://www.vuntz.net/download/cups-pk-helper/
Source0: http://cgit.freedesktop.org/cups-pk-helper/snapshot/cups-pk-helper-%{version}.tar.bz2
Patch0: cups-pk-helper-check-mechanism.patch
Patch1: cups-pk-helper-add-printer-ppd-optional.patch
Patch2: polkit_result.patch
Patch3: allow_authentication.patch
BuildRequires: libtool >= 1.4.3
BuildRequires: cups-devel >= 1.2
@ -38,6 +41,10 @@ interfaces available under control of PolicyKit.
%setup -q
%patch0 -p1 -b .check-mechanism
%patch1 -p1 -b .ppd
%patch2 -p1 -b .polkit-result
%patch3 -p1 -b .allow_auth
%build
# grr, tarball without configure
@ -64,6 +71,12 @@ make install DESTDIR=$RPM_BUILD_ROOT
%changelog
* Fri Sep 2 2011 Marek Kasik <mkasik@redhat.com> - 0.1.3-2
- Make ppd-name parameter optional
- Readd patch for allowing authentication for any and inactive users
- Readd patch for check of result of polkit authorization check
- Resolves: #724959
* Fri Aug 5 2011 Marek Kasik <mkasik@redhat.com> - 0.1.3-1
- Update to 0.1.3
- Fix #724959

View File

@ -1,26 +0,0 @@
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-08-18 18:50:55.000000000 +0200
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-08-18 18:51:28.000000000 +0200
@@ -995,7 +995,6 @@ cph_mechanism_job_cancel (CphMechanism
switch (job_status) {
case CPH_JOB_STATUS_OWNED_BY_USER: {
if (!_check_polkit_for_action_v (mechanism, context,
- "job-not-owned-edit",
"job-edit",
NULL))
return FALSE;
@@ -1037,7 +1036,6 @@ cph_mechanism_job_restart (CphMechanism
switch (job_status) {
case CPH_JOB_STATUS_OWNED_BY_USER: {
if (!_check_polkit_for_action_v (mechanism, context,
- "job-not-owned-edit",
"job-edit",
NULL))
return FALSE;
@@ -1080,7 +1078,6 @@ cph_mechanism_job_set_hold_until (CphMec
switch (job_status) {
case CPH_JOB_STATUS_OWNED_BY_USER: {
if (!_check_polkit_for_action_v (mechanism, context,
- "job-not-owned-edit",
"job-edit",
NULL))
return FALSE;

View File

@ -1,299 +0,0 @@
--- cups-pk-helper-0.0.4/src/cups.c 2009-03-04 13:41:53.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups.c 2009-08-13 12:15:47.000000000 +0200
@@ -58,7 +58,7 @@
getPPDs
getServerPPD
getDocument
- getDevices
+~!+* getDevices
getJobs
getJobAttributes
~!+* cancelJob
@@ -1807,6 +1807,192 @@ cph_cups_job_get_status (CphCups *cup
return status;
}
+struct _CphCupsGetDevices {
+ int iter;
+ GHashTable *hash;
+};
+
+static void
+_cph_cups_get_devices_cb (const char *device_class,
+ const char *device_id,
+ const char *device_info,
+ const char *device_make_and_model,
+ const char *device_uri,
+ const char *device_location,
+ void *user_data)
+{
+ struct _CphCupsGetDevices *data = user_data;
+
+ g_return_if_fail (data != NULL);
+
+ if (device_class && device_class[0] != '\0')
+ g_hash_table_replace (data->hash,
+ g_strdup_printf ("device-class:%d",
+ data->iter),
+ g_strdup (device_class));
+ if (device_id && device_id[0] != '\0')
+ g_hash_table_replace (data->hash,
+ g_strdup_printf ("device-id:%d",
+ data->iter),
+ g_strdup (device_id));
+ if (device_info && device_info[0] != '\0')
+ g_hash_table_replace (data->hash,
+ g_strdup_printf ("device-info:%d",
+ data->iter),
+ g_strdup (device_info));
+ if (device_make_and_model && device_make_and_model[0] != '\0')
+ g_hash_table_replace (data->hash,
+ g_strdup_printf ("device-make-and-model:%d",
+ data->iter),
+ g_strdup (device_make_and_model));
+ if (device_uri && device_uri[0] != '\0')
+ g_hash_table_replace (data->hash,
+ g_strdup_printf ("device-uri:%d",
+ data->iter),
+ g_strdup (device_uri));
+ if (device_location && device_location[0] != '\0')
+ g_hash_table_replace (data->hash,
+ g_strdup_printf ("device-location:%d ",
+ data->iter),
+ g_strdup (device_location));
+
+ data->iter++;
+}
+
+GHashTable *
+cph_cups_devices_get (CphCups *cups,
+ int timeout,
+ const char *include_schemes,
+ const char *exclude_schemes)
+{
+ struct _CphCupsGetDevices data;
+ char *error_str;
+
+ g_return_val_if_fail (CPH_IS_CUPS (cups), NULL);
+
+ data.iter = 0;
+ data.hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_free);
+
+#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1
+ ipp_status_t retval;
+ int timeout_param = CUPS_TIMEOUT_DEFAULT;
+ char *include_schemes_param = (char *) CUPS_INCLUDE_ALL;
+ char *exclude_schemes_param = (char *) CUPS_EXCLUDE_NONE;
+
+ if (timeout > 0)
+ timeout_param = timeout;
+
+ if (include_schemes && strlen (include_schemes) > 0)
+ include_schemes_param = g_strdup (include_schemes);
+
+ if (exclude_schemes && strlen (exclude_schemes) > 0)
+ exclude_schemes_param = g_strdup (exclude_schemes);
+
+ retval = cupsGetDevices (cups->priv->connection,
+ timeout_param,
+ include_schemes_param,
+ exclude_schemes_param,
+ _cph_cups_get_devices_cb,
+ &data);
+
+ g_free (include_schemes_param);
+ g_free (exclude_schemes_param);
+
+ if (retval != IPP_OK)
+ goto error;
+#else
+ ipp_t *request;
+ const char *resource_char;
+ ipp_t *reply;
+ ipp_attribute_t *attr;
+ const char *device_class;
+ const char *device_id;
+ const char *device_info;
+ const char *device_location;
+ const char *device_make_and_model;
+ const char *device_uri;
+
+ request = ippNewRequest (CUPS_GET_DEVICES);
+ resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
+ reply = cupsDoRequest (cups->priv->connection,
+ request, resource_char);
+
+ if (!reply)
+ goto error;
+
+ for (attr = reply->attrs; attr; attr = attr->next) {
+ while (attr && attr->group_tag != IPP_TAG_PRINTER)
+ attr = attr->next;
+
+ if (attr == NULL)
+ break;
+
+ device_class = NULL;
+ device_id = NULL;
+ device_info = NULL;
+ device_location = "";
+ device_make_and_model = NULL;
+ device_uri = NULL;
+
+ while (attr && attr->group_tag == IPP_TAG_PRINTER) {
+ g_message ("name: %s", attr->name);
+ if (attr->name &&
+ strcmp (attr->name, "device-class") == 0 &&
+ attr->value_tag == IPP_TAG_KEYWORD)
+ device_class = g_strdup (attr->values[0].string.text);
+ else if (attr->name &&
+ strcmp (attr->name, "device-id") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ device_id = g_strdup (attr->values[0].string.text);
+ else if (attr->name &&
+ strcmp (attr->name, "device-info") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ device_info = g_strdup (attr->values[0].string.text);
+ else if (attr->name &&
+ strcmp (attr->name, "device-location") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ device_location = g_strdup (attr->values[0].string.text);
+ else if (attr->name &&
+ strcmp (attr->name, "device-make-and-model") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ device_make_and_model = g_strdup (attr->values[0].string.text);
+ else if (attr->name &&
+ strcmp (attr->name, "device-uri") == 0 &&
+ attr->value_tag == IPP_TAG_URI)
+ device_uri = g_strdup (attr->values[0].string.text);
+
+ attr = attr->next;
+ }
+
+ if (device_class && device_id && device_info && device_make_and_model &&
+ device_uri)
+ _cph_cups_get_devices_cb (device_class,
+ device_id,
+ device_info,
+ device_make_and_model,
+ device_uri,
+ device_location,
+ &data);
+
+ if (attr == NULL)
+ break;
+ }
+
+ ippDelete (reply);
+#endif
+
+ return data.hash;
+
+error:
+ error_str = g_strdup ("Can not get devices.");
+ _cph_cups_set_internal_status (cups, error_str);
+ g_hash_table_destroy (data.hash);
+ g_free (error_str);
+
+ return NULL;
+}
+
/******************************************************
* Non-object functions
******************************************************/
--- cups-pk-helper-0.0.4/src/cups.h 2009-02-28 03:38:13.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups.h 2009-08-13 12:16:08.000000000 +0200
@@ -184,6 +184,11 @@ CphJobStatus cph_cups_job_get_status (Cp
int job_id,
const char *user);
+GHashTable *cph_cups_devices_get (CphCups *cups,
+ int timeout,
+ const char *include_schemes,
+ const char *exclude_schemes);
+
G_END_DECLS
#endif /* CPH_CUPS_H */
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-08-13 12:14:09.000000000 +0200
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-08-13 12:16:48.000000000 +0200
@@ -1103,3 +1103,27 @@ cph_mechanism_job_set_hold_until (CphMec
return TRUE;
}
+
+gboolean
+cph_mechanism_devices_get (CphMechanism *mechanism,
+ int timeout,
+ const char *include_schemes,
+ const char *exclude_schemes,
+ DBusGMethodInvocation *context)
+{
+ GHashTable *devices;
+
+ reset_killtimer (mechanism);
+
+ if (!_check_polkit_for_action (mechanism, context, "devices-get"))
+ return FALSE;
+
+ devices = cph_cups_devices_get (mechanism->priv->cups,
+ timeout,
+ include_schemes,
+ exclude_schemes);
+ _cph_mechanism_return_error_and_value (mechanism, context,
+ devices == NULL, devices);
+
+ return TRUE;
+}
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.h 2009-02-28 03:38:13.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.h 2009-08-13 12:17:10.000000000 +0200
@@ -236,6 +236,13 @@ cph_mechanism_job_set_hold_until (CphMec
const char *job_hold_until,
DBusGMethodInvocation *context);
+gboolean
+cph_mechanism_devices_get (CphMechanism *mechanism,
+ int timeout,
+ const char *include_schemes,
+ const char *exclude_schemes,
+ DBusGMethodInvocation *context);
+
G_END_DECLS
#endif /* CPH_MECHANISM_H */
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.xml 2009-02-28 03:38:13.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.xml 2009-08-13 12:17:36.000000000 +0200
@@ -192,5 +192,14 @@
<arg name="job_hold_until" direction="in" type="s"/>
<arg name="error" direction="out" type="s"/>
</method>
+
+ <method name="DevicesGet">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="timeout" direction="in" type="i"/>
+ <arg name="include_schemes" direction="in" type="s"/>
+ <arg name="exclude_schemes" direction="in" type="s"/>
+ <arg name="error" direction="out" type="s"/>
+ <arg name="devices" direction="out" type="a{ss}"/>
+ </method>
</interface>
</node>
--- cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-08-13 12:14:09.000000000 +0200
+++ cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-08-13 12:18:24.000000000 +0200
@@ -86,6 +86,15 @@
</defaults>
</action>
+ <action id="org.opensuse.cupspkhelper.mechanism.devices-get">
+ <_description>Get devices</_description>
+ <_message>Privileges are required to get devices.</_message>
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin_keep</allow_active>
+ </defaults>
+ </action>
+
<!-- Deprecated -->
<action id="org.opensuse.cupspkhelper.mechanism.printeraddremove">
<_description>Add/Remove/Edit a printer</_description>

View File

@ -1,260 +0,0 @@
--- cups-pk-helper-0.0.4/configure.ac 2009-03-04 13:43:52.000000000 +0100
+++ cups-pk-helper-0.0.4/configure.ac 2009-06-18 13:37:25.000000000 +0200
@@ -42,8 +42,8 @@ fi
GLIB_REQUIRED=2.14.0
DBUS_REQUIRED=1.1.2
DBUS_GLIB_REQUIRED=0.74
-POLKIT_DBUS_REQUIRED=0.8
GTK_REQUIRED=2.12.0
+POLKIT_REQUIRED=0.92
# pkg-config dependency checks
PKG_CHECK_MODULES(CUPS_PK, glib-2.0 >= $GLIB_REQUIRED \
@@ -52,7 +52,7 @@ PKG_CHECK_MODULES(CUPS_PK, glib-2.0 >= $
gthread-2.0 \
dbus-1 >= $DBUS_REQUIRED \
dbus-glib-1 >= $DBUS_GLIB_REQUIRED \
- polkit-dbus >= $POLKIT_DBUS_REQUIRED)
+ polkit-gobject-1 >= $POLKIT_REQUIRED)
AC_SUBST(CUPS_PK_CFLAGS)
AC_SUBST(CUPS_PK_LIBS)
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-02-28 03:38:13.000000000 +0100
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-06-18 14:24:13.000000000 +0200
@@ -45,7 +45,7 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <polkit-dbus/polkit-dbus.h>
+#include <polkit/polkit.h>
#include <pwd.h>
@@ -124,7 +124,7 @@ G_DEFINE_TYPE (CphMechanism, cph_mechani
struct CphMechanismPrivate
{
DBusGConnection *system_bus_connection;
- PolKitContext *pol_ctx;
+ PolkitAuthority *pol_auth;
CphCups *cups;
};
@@ -201,59 +201,11 @@ cph_mechanism_finalize (GObject *object)
}
static gboolean
-pk_io_watch_have_data (GIOChannel *channel,
- GIOCondition condition,
- gpointer user_data)
-{
- int fd;
- PolKitContext *pk_context;
-
- pk_context = user_data;
- fd = g_io_channel_unix_get_fd (channel);
- polkit_context_io_func (pk_context, fd);
-
- return TRUE;
-}
-
-static int
-pk_io_add_watch (PolKitContext *pk_context,
- int fd)
-{
- guint id;
- GIOChannel *channel;
-
- channel = g_io_channel_unix_new (fd);
- if (channel == NULL)
- return 0;
-
- id = g_io_add_watch (channel, G_IO_IN,
- pk_io_watch_have_data, pk_context);
-
- return id;
-}
-
-static void
-pk_io_remove_watch (PolKitContext *pk_context,
- int watch_id)
-{
- g_source_remove (watch_id);
-}
-
-static gboolean
register_mechanism (CphMechanism *mechanism)
{
GError *error;
- mechanism->priv->pol_ctx = polkit_context_new ();
-
- polkit_context_set_io_watch_functions (mechanism->priv->pol_ctx,
- pk_io_add_watch,
- pk_io_remove_watch);
-
- if (!polkit_context_init (mechanism->priv->pol_ctx, NULL)) {
- g_critical ("cannot initialize libpolkit");
- return FALSE;
- }
+ mechanism->priv->pol_auth = polkit_authority_get ();
error = NULL;
mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
@@ -299,11 +251,10 @@ _check_polkit_for_action_internal (CphMe
const char *action_method,
GError **error)
{
- const char *sender;
+ char *sender;
DBusError dbus_error;
- PolKitCaller *pk_caller;
- PolKitAction *pk_action;
- PolKitResult pk_result;
+ PolkitSubject *pk_caller;
+ PolkitAuthorizationResult *pk_result;
char *action;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -315,44 +266,30 @@ _check_polkit_for_action_internal (CphMe
sender = dbus_g_method_get_sender (context);
dbus_error_init (&dbus_error);
- pk_caller = polkit_caller_new_from_dbus_name (
- dbus_g_connection_get_connection (mechanism->priv->system_bus_connection),
- sender,
- &dbus_error);
-
- if (pk_caller == NULL) {
- g_set_error (error,
- CPH_MECHANISM_ERROR, CPH_MECHANISM_ERROR_GENERAL,
- "Error getting information about caller: %s: %s",
- dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- g_free (action);
-
- return FALSE;
- }
+ pk_caller = polkit_system_bus_name_new (sender);
+ g_free (sender);
- pk_action = polkit_action_new ();
- polkit_action_set_action_id (pk_action, action);
- pk_result = polkit_context_is_caller_authorized (mechanism->priv->pol_ctx,
- pk_action, pk_caller,
- FALSE, NULL);
- polkit_caller_unref (pk_caller);
- polkit_action_unref (pk_action);
+ pk_result = polkit_authority_check_authorization_sync (mechanism->priv->pol_auth,
+ pk_caller,
+ action,
+ NULL,
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
+ NULL,
+ NULL);
+ g_object_unref (pk_caller);
- if (pk_result != POLKIT_RESULT_YES) {
+ if (!polkit_authorization_result_get_is_authorized (pk_result)) {
g_set_error (error,
CPH_MECHANISM_ERROR,
CPH_MECHANISM_ERROR_NOT_PRIVILEGED,
- "%s %s <-- (action, result)",
- action,
- polkit_result_to_string_representation (pk_result));
- dbus_error_free (&dbus_error);
+ "Not Authorized: %s", action);
g_free (action);
return FALSE;
}
g_free (action);
+ g_object_unref (pk_result);
return TRUE;
}
--- cups-pk-helper-0.0.4/src/Makefile.am 2008-09-19 18:25:12.000000000 +0200
+++ cups-pk-helper-0.0.4/src/Makefile.am 2009-06-18 13:37:25.000000000 +0200
@@ -46,7 +46,7 @@ BUILT_SOURCES = cups-pk-helper-mechanism
dbus_servicesdir = $(datadir)/dbus-1/system-services
dbus_confdir = $(sysconfdir)/dbus-1/system.d
-polkitdir = $(datadir)/PolicyKit/policy
+polkitdir = $(datadir)/polkit-1/actions
dbus_services_in_files = org.opensuse.CupsPkHelper.Mechanism.service.in
polkit_in_files = org.opensuse.cupspkhelper.mechanism.policy.in
--- cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-28 03:38:13.000000000 +0100
+++ cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-06-18 13:37:25.000000000 +0200
@@ -16,7 +16,7 @@
<_message>Privileges are required to set a printer, or a class, as default printer.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -28,7 +28,7 @@
<_message>Privileges are required to enable/disable a printer, or a class.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -37,7 +37,7 @@
<_message>Privileges are required to add/remove/edit a local printer.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -46,7 +46,7 @@
<_message>Privileges are required to add/remove/edit a remote printer.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -55,7 +55,7 @@
<_message>Privileges are required to add/remove/edit a class.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -64,7 +64,7 @@
<_message>Privileges are required to get/set server settings.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -82,7 +82,7 @@
<_message>Privileges are required to restart/cancel/edit a job owned by another user.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
@@ -92,7 +92,7 @@
<_message>Privileges are required to add/remove/edit a printer.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
- <allow_active>auth_admin</allow_active>
+ <allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
</policyconfig>

View File

@ -1,123 +1,11 @@
--- cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c.polkit-result 2009-08-17 14:55:52.000000000 +0200
+++ cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-08-17 14:55:52.000000000 +0200
@@ -278,7 +278,7 @@ _check_polkit_for_action_internal (CphMe
NULL);
g_object_unref (pk_caller);
--- cups-pk-helper-0.1.3/src/cups-pk-helper-mechanism.c 2011-09-02 11:30:26.000000000 +0200
+++ cups-pk-helper-0.1.3/src/cups-pk-helper-mechanism.c 2011-09-02 11:31:34.000000000 +0200
@@ -291,7 +291,7 @@ _check_polkit_for_action_internal (CphMe
return FALSE;
}
- if (!polkit_authorization_result_get_is_authorized (pk_result)) {
+ if (pk_result == NULL || !polkit_authorization_result_get_is_authorized (pk_result)) {
g_set_error (error,
CPH_MECHANISM_ERROR,
CPH_MECHANISM_ERROR_NOT_PRIVILEGED,
--- cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in.polkit-result 2009-08-17 14:55:52.000000000 +0200
+++ cups-pk-helper-0.0.4/src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-08-17 14:55:52.000000000 +0200
@@ -12,8 +12,8 @@
operation: if some authorization is required, then the PolicyKit helper
will fallback on printer-X-edit. -->
<action id="org.opensuse.cupspkhelper.mechanism.printer-set-default">
- <_description>Set a printer as default printer</_description>
- <_message>Privileges are required to set a printer, or a class, as default printer.</_message>
+ <description>Set a printer as default printer</description>
+ <message>Privileges are required to set a printer, or a class, as default printer.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -24,8 +24,8 @@
operation: if some authorization is required, then the PolicyKit helper
will fallback on printer-X-edit. -->
<action id="org.opensuse.cupspkhelper.mechanism.printer-enable">
- <_description>Enable/Disable a printer</_description>
- <_message>Privileges are required to enable/disable a printer, or a class.</_message>
+ <description>Enable/Disable a printer</description>
+ <message>Privileges are required to enable/disable a printer, or a class.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -33,8 +33,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.printer-local-edit">
- <_description>Add/Remove/Edit a local printer</_description>
- <_message>Privileges are required to add/remove/edit a local printer.</_message>
+ <description>Add/Remove/Edit a local printer</description>
+ <message>Privileges are required to add/remove/edit a local printer.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -42,8 +42,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.printer-remote-edit">
- <_description>Add/Remove/Edit a remote printer</_description>
- <_message>Privileges are required to add/remove/edit a remote printer.</_message>
+ <description>Add/Remove/Edit a remote printer</description>
+ <message>Privileges are required to add/remove/edit a remote printer.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -51,8 +51,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.class-edit">
- <_description>Add/Remove/Edit a class</_description>
- <_message>Privileges are required to add/remove/edit a class.</_message>
+ <description>Add/Remove/Edit a class</description>
+ <message>Privileges are required to add/remove/edit a class.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -60,8 +60,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.server-settings">
- <_description>Get/Set server settings</_description>
- <_message>Privileges are required to get/set server settings.</_message>
+ <description>Get/Set server settings</description>
+ <message>Privileges are required to get/set server settings.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -69,8 +69,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.job-edit">
- <_description>Restart/Cancel/Edit a job</_description>
- <_message>Privileges are required to restart/cancel/edit a job.</_message>
+ <description>Restart/Cancel/Edit a job</description>
+ <message>Privileges are required to restart/cancel/edit a job.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
@@ -78,8 +78,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.job-not-owned-edit">
- <_description>Restart/Cancel/Edit a job owned by another user</_description>
- <_message>Privileges are required to restart/cancel/edit a job owned by another user.</_message>
+ <description>Restart/Cancel/Edit a job owned by another user</description>
+ <message>Privileges are required to restart/cancel/edit a job owned by another user.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -87,8 +87,8 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.devices-get">
- <_description>Get devices</_description>
- <_message>Privileges are required to get devices.</_message>
+ <description>Get devices</description>
+ <message>Privileges are required to get devices.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
@@ -97,8 +97,8 @@
<!-- Deprecated -->
<action id="org.opensuse.cupspkhelper.mechanism.printeraddremove">
- <_description>Add/Remove/Edit a printer</_description>
- <_message>Privileges are required to add/remove/edit a printer.</_message>
+ <description>Add/Remove/Edit a printer</description>
+ <message>Privileges are required to add/remove/edit a printer.</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>