Hello community,
here is the log from the commit of package cups-pk-helper for openSUSE:Factory
checked in at Fri Mar 6 00:23:13 CET 2009.
--------
--- cups-pk-helper/cups-pk-helper.changes 2009-02-21 23:48:08.000000000 +0100
+++ /mounts/work_src_done/STABLE/cups-pk-helper/cups-pk-helper.changes 2009-03-04 13:55:55.000000000 +0100
@@ -1,0 +2,15 @@
+Wed Mar 4 13:54:05 CET 2009 - vuntz@novell.com
+
+- Update to version 0.0.4:
+ + Remove bare send_interface lines in the DBus rules.
+ + Add job related functions.
+ + Reconnect to the cups server if necessary.
+ + Accept file: URI as local.
+ + Change default policy for job-edit to yes (jobs are owned by
+ the user).
+ + Add more checks for the new job-related functions.
+ + Code cleanups.
+- Drop cups-pk-helper-bnc468389-dbus-send-dest.patch: fixed
+ upstream.
+
+-------------------------------------------------------------------
calling whatdependson for head-i586
Old:
----
cups-pk-helper-0.0.3.tar.bz2
cups-pk-helper-bnc468389-dbus-send-dest.patch
New:
----
cups-pk-helper-0.0.4.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ cups-pk-helper.spec ++++++
--- /var/tmp/diff_new_pack.m26440/_old 2009-03-06 00:23:06.000000000 +0100
+++ /var/tmp/diff_new_pack.m26440/_new 2009-03-06 00:23:06.000000000 +0100
@@ -1,5 +1,5 @@
#
-# spec file for package cups-pk-helper (Version 0.0.3)
+# spec file for package cups-pk-helper (Version 0.0.4)
#
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
@@ -21,13 +21,11 @@
Name: cups-pk-helper
License: GPL v2 or later
Group: Hardware/Printing
-Version: 0.0.3
-Release: 2
+Version: 0.0.4
+Release: 1
Summary: PolicyKit helper to configure cups with fine-grained privileges
Url: http://www.vuntz.net/download/cups-pk-helper/
Source0: http://www.vuntz.net/download/cups-pk-helper/%{name}-%{version}.tar.bz2
-# PATCH-FIX-UPSTREAM cups-pk-helper-bnc468389-dbus-send-dest.patch bnc468389 vuntz@novell.com -- Fix the potential dbus security issue with send_interface
-Patch0: cups-pk-helper-bnc468389-dbus-send-dest.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: PolicyKit-devel
BuildRequires: cups-devel
@@ -51,7 +49,6 @@
%prep
%setup -q
-%patch0 -p1
%build
%configure --libexecdir=%{_libdir}/cups-pk-helper
@@ -72,5 +69,17 @@
%{_datadir}/PolicyKit/policy/org.opensuse.cupspkhelper.mechanism.policy
%changelog
+* Wed Mar 04 2009 vuntz@novell.com
+- Update to version 0.0.4:
+ + Remove bare send_interface lines in the DBus rules.
+ + Add job related functions.
+ + Reconnect to the cups server if necessary.
+ + Accept file: URI as local.
+ + Change default policy for job-edit to yes (jobs are owned by
+ the user).
+ + Add more checks for the new job-related functions.
+ + Code cleanups.
+- Drop cups-pk-helper-bnc468389-dbus-send-dest.patch: fixed
+ upstream.
* Sat Feb 21 2009 vuntz@novell.com
- Split from system-config-printer.
++++++ cups-pk-helper-0.0.3.tar.bz2 -> cups-pk-helper-0.0.4.tar.bz2 ++++++
++++ 17235 lines of diff (skipped)
++++ retrying with extended exclude list
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/cups-pk-helper-0.0.3/configure.ac new/cups-pk-helper-0.0.4/configure.ac
--- old/cups-pk-helper-0.0.3/configure.ac 2008-11-21 07:33:43.000000000 +0100
+++ new/cups-pk-helper-0.0.4/configure.ac 2009-03-04 13:43:52.000000000 +0100
@@ -1,4 +1,4 @@
-AC_INIT([cups-pk-helper], [0.0.3],
+AC_INIT([cups-pk-helper], [0.0.4],
[https://bugzilla.novell.com/enter_bug.cgi?classification=7340&product=openSUSE+11.1])
AC_CONFIG_SRCDIR(src/cups-pk-helper-mechanism.c)
AM_INIT_AUTOMAKE([1.9 no-dist-gzip dist-bzip2])
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/cups-pk-helper-0.0.3/NEWS new/cups-pk-helper-0.0.4/NEWS
--- old/cups-pk-helper-0.0.3/NEWS 2008-11-21 07:36:52.000000000 +0100
+++ new/cups-pk-helper-0.0.4/NEWS 2009-03-04 13:48:25.000000000 +0100
@@ -1,4 +1,16 @@
=============
+Version 0.0.4
+=============
+
++ Remove bare send_interface lines in the DBus rules.
++ Add job related functions. (Marek Kasik)
++ Reconnect to the cups server if necessary. (Marek Kasik)
++ Accept file: URI as local. (Marek Kasik)
++ Change default policy for job-edit to yes (jobs are owned by the user).
++ Add more checks for the new job-related functions.
++ Code cleanups.
+
+=============
Version 0.0.3
=============
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/cups-pk-helper-0.0.3/po/Makefile.in.in new/cups-pk-helper-0.0.4/po/Makefile.in.in
--- old/cups-pk-helper-0.0.3/po/Makefile.in.in 2008-11-17 16:58:23.000000000 +0100
+++ new/cups-pk-helper-0.0.4/po/Makefile.in.in 2009-03-04 13:50:25.000000000 +0100
@@ -56,7 +56,7 @@
PO_LINGUAS=$(shell if test -r $(srcdir)/LINGUAS; then grep -v "^\#" $(srcdir)/LINGUAS; else echo "$(ALL_LINGUAS)"; fi)
-USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep ^$$lang$$ $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep ^$$lang$$`"; then printf "$$lang "; fi; done; fi)
+USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep '^$$lang$$' $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep '^$$lang$$'`"; then printf "$$lang "; fi; done; fi)
USE_LINGUAS=$(shell if test -n "$(USER_LINGUAS)" -o -n "$(LINGUAS)"; then LLINGUAS="$(USER_LINGUAS)"; else if test -n "$(PO_LINGUAS)"; then LLINGUAS="$(PO_LINGUAS)"; else LLINGUAS="$(ALL_LINGUAS)"; fi; fi; for lang in $$LLINGUAS; do printf "$$lang "; done)
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/cups-pk-helper-0.0.3/src/cups.c new/cups-pk-helper-0.0.4/src/cups.c
--- old/cups-pk-helper-0.0.3/src/cups.c 2008-11-21 07:04:28.000000000 +0100
+++ new/cups-pk-helper-0.0.4/src/cups.c 2009-03-04 13:41:53.000000000 +0100
@@ -45,6 +45,12 @@
#include "cups.h"
+/* This is 0.1 second */
+#define RECONNECT_DELAY 100000
+/* We try to reconnect during 3 seconds. It's still a fairly long time even for
+ * restarting cups, so it should be fine */
+#define MAX_RECONNECT_ATTEMPTS 30
+
/*
getPrinters
getDests
@@ -55,11 +61,11 @@
getDevices
getJobs
getJobAttributes
- ! cancelJob
+~!+* cancelJob
! cancelAllJobs
! authenticateJob
- ! setJobHoldUntil
- ! restartJob
+~!+* setJobHoldUntil
+~!+* restartJob
~!+* getFile
~!+* putFile
~!+* addPrinter
@@ -174,6 +180,25 @@
cups->priv->internal_status = NULL;
}
+static gboolean
+cph_cups_reconnect (CphCups *cups)
+{
+ int return_value = -1;
+ int i;
+
+ for (i = 0; i < MAX_RECONNECT_ATTEMPTS; i++) {
+ return_value = httpReconnect (cups->priv->connection);
+ if (return_value == 0)
+ break;
+ g_usleep (RECONNECT_DELAY);
+ }
+
+ if (return_value == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
static void
cph_cups_finalize (GObject *object)
{
@@ -297,6 +322,22 @@
return FALSE;
}
+static gboolean
+_cph_cups_is_job_id_valid (CphCups *cups,
+ int job_id)
+{
+ char *error;
+
+ if (job_id > 0)
+ return TRUE;
+
+ error = g_strdup_printf ("\"%d\" is not a valid job id.", job_id);
+ _cph_cups_set_internal_status (cups, error);
+ g_free (error);
+
+ return FALSE;
+}
+
/* This is some text, but we could potentially do more checks. We don't do them
* because cups will already do them.
* + for the URI, we could check that the scheme is supported and that the
@@ -342,6 +383,7 @@
_CPH_CUPS_IS_VALID (info, "description", FALSE)
_CPH_CUPS_IS_VALID (location, "location", FALSE)
_CPH_CUPS_IS_VALID (reject_jobs_reason, "reason", FALSE)
+_CPH_CUPS_IS_VALID (job_hold_until, "job hold until", FALSE)
/* For put/get file: this is some text, but we could potentially do more
* checks. We don't do them because cups will already do them.
@@ -365,7 +407,7 @@
g_snprintf (uri, sizeof (uri),
"ipp://localhost/printers/%s", name);
ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, uri);
+ "printer-uri", NULL, uri);
}
static void
@@ -377,7 +419,19 @@
g_snprintf (uri, sizeof (uri),
"ipp://localhost/classes/%s", name);
ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, uri);
+ "printer-uri", NULL, uri);
+}
+
+static void
+_cph_cups_add_job_uri (ipp_t *request,
+ int job_id)
+{
+ char uri[HTTP_MAX_URI + 1];
+
+ g_snprintf (uri, sizeof (uri),
+ "ipp://localhost/jobs/%d", job_id);
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
+ "job-uri", NULL, uri);
}
static void
@@ -433,8 +487,7 @@
static const char *
_cph_cups_get_resource (CphResource resource)
{
- switch (resource)
- {
+ switch (resource) {
case CPH_RESOURCE_ROOT:
return "/";
case CPH_RESOURCE_ADMIN:
@@ -541,6 +594,51 @@
return _cph_cups_send_request (cups, request, CPH_RESOURCE_ADMIN);
}
+static gboolean
+_cph_cups_send_new_simple_job_request (CphCups *cups,
+ ipp_op_t op,
+ int job_id,
+ const char *user_name,
+ CphResource resource)
+{
+ ipp_t *request;
+
+ request = ippNewRequest (op);
+ _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);
+
+ return _cph_cups_send_request (cups, request, resource);
+}
+
+static gboolean
+_cph_cups_send_new_job_attributes_request (CphCups *cups,
+ int job_id,
+ const char *name,
+ const char *value,
+ const char *user_name,
+ CphResource resource)
+{
+ cups_option_t *options = NULL;
+ ipp_t *request;
+ int num_options = 0;
+
+ request = ippNewRequest (IPP_SET_JOB_ATTRIBUTES);
+ _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);
+
+ num_options = cupsAddOption (name, value,
+ num_options, &options);
+ cupsEncodeOptions (request, num_options, options);
+
+ return _cph_cups_send_request (cups, request, resource);
+}
+
static int
_cph_cups_class_has_printer (CphCups *cups,
const char *class_name,
@@ -692,7 +790,7 @@
request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
_cph_cups_add_class_uri (request, name);
ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", 1, NULL, attrs);
+ "requested-attributes", 1, NULL, attrs);
resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
reply = cupsDoRequest (cups->priv->connection,
@@ -731,7 +829,7 @@
request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
_cph_cups_add_printer_uri (request, printer_name);
ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", 1, NULL, attrs);
+ "requested-attributes", 1, NULL, attrs);
resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
reply = cupsDoRequest (cups->priv->connection,
@@ -801,6 +899,10 @@
const char *resource,
const char *filename)
{
+ struct stat file_stat;
+ uid_t uid;
+ gid_t gid;
+
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
if (!_cph_cups_is_resource_valid (cups, resource))
@@ -808,12 +910,35 @@
if (!_cph_cups_is_filename_valid (cups, filename))
return FALSE;
+ stat (filename, &file_stat);
+ uid = file_stat.st_uid;
+ gid = file_stat.st_gid;
+
/* reset the internal status: we'll use the cups status */
_cph_cups_set_internal_status (cups, NULL);
cups->priv->last_status = cupsGetFile (cups->priv->connection,
resource, filename);
+ /* FIXME: There's a bug where the cups connection can fail with EPIPE.
+ * We're work-arounding it here until it's fixed in cups. */
+ if (cups->priv->last_status != HTTP_OK) {
+ if (cph_cups_reconnect (cups)) {
+ int fd;
+
+ /* if cupsGetFile fail, then filename is unlinked */
+ fd = open (filename, O_CREAT, S_IRUSR | S_IWUSR);
+ close (fd);
+ chown (filename, uid, gid);
+
+ _cph_cups_set_internal_status (cups, NULL);
+
+ cups->priv->last_status = cupsGetFile (cups->priv->connection,
+ resource,
+ filename);
+ }
+ }
+
return cups->priv->last_status == HTTP_OK;
}
@@ -835,10 +960,15 @@
cups->priv->last_status = cupsPutFile (cups->priv->connection,
resource, filename);
+ /* CUPS is being restarted, so we need to reconnect */
+ cph_cups_reconnect (cups);
+
return (cups->priv->last_status == HTTP_OK ||
cups->priv->last_status == HTTP_CREATED);
}
+/* Functions that work on a printer */
+
gboolean
cph_cups_printer_add (CphCups *cups,
const char *printer_name,
@@ -1283,7 +1413,7 @@
request = ippNewRequest (CUPS_ADD_MODIFY_PRINTER);
_cph_cups_add_printer_uri (request, printer_name);
ippAddStrings (request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "job-sheets-default", 2, NULL, values);
+ "job-sheets-default", 2, NULL, values);
if (_cph_cups_send_request (cups, request, CPH_RESOURCE_ADMIN))
return TRUE;
@@ -1295,7 +1425,7 @@
request = ippNewRequest (CUPS_ADD_MODIFY_CLASS);
_cph_cups_add_class_uri (request, printer_name);
ippAddStrings (request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "job-sheets-default", 2, NULL, values);
+ "job-sheets-default", 2, NULL, values);
return _cph_cups_send_request (cups, request, CPH_RESOURCE_ADMIN);
}
@@ -1494,6 +1624,8 @@
return retval;
}
+/* Functions that are for the server in general */
+
GHashTable *
cph_cups_server_get_settings (CphCups *cups)
{
@@ -1566,6 +1698,9 @@
retval = cupsAdminSetServerSettings (cups->priv->connection,
num_settings, cups_settings);
+ /* CUPS is being restarted, so we need to reconnect */
+ cph_cups_reconnect (cups);
+
cupsFreeOptions (num_settings, cups_settings);
if (retval == 0) {
@@ -1581,6 +1716,97 @@
return TRUE;
}
+/* Functions that work on jobs */
+
+gboolean
+cph_cups_job_cancel (CphCups *cups,
+ int job_id,
+ const char *user_name)
+{
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
+
+ if (!_cph_cups_is_job_id_valid (cups, job_id))
+ return FALSE;
+ /* 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);
+}
+
+gboolean
+cph_cups_job_restart (CphCups *cups,
+ int job_id,
+ const char *user_name)
+{
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
+
+ if (!_cph_cups_is_job_id_valid (cups, job_id))
+ return FALSE;
+ /* 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_RESTART_JOB,
+ job_id,
+ user_name,
+ CPH_RESOURCE_JOBS);
+}
+
+gboolean
+cph_cups_job_set_hold_until (CphCups *cups,
+ int job_id,
+ const char *job_hold_until,
+ const char *user_name)
+{
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
+
+ if (!_cph_cups_is_job_id_valid (cups, job_id))
+ return FALSE;
+ if (!_cph_cups_is_job_hold_until_valid (cups, job_hold_until))
+ return FALSE;
+ /* 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_job_attributes_request (cups,
+ job_id,
+ "job-hold-until",
+ job_hold_until,
+ user_name,
+ CPH_RESOURCE_JOBS);
+}
+
+CphJobStatus
+cph_cups_job_get_status (CphCups *cups,
+ int job_id,
+ const char *user)
+{
+ CphJobStatus status = CPH_JOB_STATUS_INVALID;
+ cups_job_t *jobs;
+ int num_jobs;
+ int i;
+
+ g_return_val_if_fail (CPH_IS_CUPS (cups), CPH_JOB_STATUS_INVALID);
+
+ num_jobs = cupsGetJobs2 (cups->priv->connection, &jobs, NULL, 0, 0);
+
+ for (i = 0; i < num_jobs; i++) {
+ if (jobs[i].id == job_id) {
+ if (user != NULL &&
+ g_strcmp0 (jobs[i].user, user) == 0)
+ status = CPH_JOB_STATUS_OWNED_BY_USER;
+ else
+ status = CPH_JOB_STATUS_NOT_OWNED_BY_USER;
+ break;
+ }
+ }
+
+ cupsFreeJobs (num_jobs, jobs);
+
+ return status;
+}
+
/******************************************************
* Non-object functions
******************************************************/
@@ -1606,6 +1832,7 @@
g_str_has_prefix (lower_uri, "beh:") ||
g_str_has_prefix (lower_uri, "scsi:") ||
g_str_has_prefix (lower_uri, "serial:") ||
+ g_str_has_prefix (lower_uri, "file:") ||
g_str_has_prefix (lower_uri, "pipe:")) {
g_free (lower_uri);
return TRUE;
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/cups-pk-helper-0.0.3/src/cups.h new/cups-pk-helper-0.0.4/src/cups.h
--- old/cups-pk-helper-0.0.3/src/cups.h 2008-11-21 01:50:42.000000000 +0100
+++ new/cups-pk-helper-0.0.4/src/cups.h 2009-02-28 03:38:13.000000000 +0100
@@ -48,6 +48,13 @@
GObjectClass parent_class;
} CphCupsClass;
+typedef enum
+{
+ CPH_JOB_STATUS_INVALID,
+ CPH_JOB_STATUS_OWNED_BY_USER,
+ CPH_JOB_STATUS_NOT_OWNED_BY_USER
+} CphJobStatus;
+
GType cph_cups_get_type (void);
CphCups *cph_cups_new (void);
@@ -160,6 +167,23 @@
gboolean cph_cups_is_printer_uri_local (const char *uri);
+gboolean cph_cups_job_cancel (CphCups *cups,
+ int job_id,
+ const char *user_name);
+
+gboolean cph_cups_job_restart (CphCups *cups,
+ int job_id,
+ const char *user_name);
+
+gboolean cph_cups_job_set_hold_until (CphCups *cups,
+ int job_id,
+ const char *job_hold_until,
+ const char *user_name);
+
+CphJobStatus cph_cups_job_get_status (CphCups *cups,
+ int job_id,
+ const char *user);
+
G_END_DECLS
#endif /* CPH_CUPS_H */
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/cups-pk-helper-0.0.3/src/cups-pk-helper-mechanism.c new/cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c
--- old/cups-pk-helper-0.0.3/src/cups-pk-helper-mechanism.c 2008-11-21 07:28:20.000000000 +0100
+++ new/cups-pk-helper-0.0.4/src/cups-pk-helper-mechanism.c 2009-02-28 03:38:13.000000000 +0100
@@ -47,6 +47,8 @@
#include