- Update to 0.0.4
This commit is contained in:
parent
35801778dd
commit
19f4fe8e85
@ -1 +1 @@
|
||||
cups-pk-helper-0.0.3.tar.bz2
|
||||
cups-pk-helper-0.0.4.tar.bz2
|
||||
|
@ -1,639 +0,0 @@
|
||||
--- src/cups.c 2009-02-27 14:55:03.000000000 +0100
|
||||
+++ src/cups.c 2009-02-27 14:53:40.000000000 +0100
|
||||
@@ -182,17 +182,16 @@ cph_cups_init (CphCups *cups)
|
||||
gboolean
|
||||
cph_cups_reconnect (CphCups *cups)
|
||||
{
|
||||
- gint return_value = -1;
|
||||
- gint i;
|
||||
+ int return_value = -1;
|
||||
+ int i;
|
||||
|
||||
cups->priv->reconnecting = TRUE;
|
||||
|
||||
for (i = 0; i < MAX_RECONNECT_ATTEMPTS; i++) {
|
||||
- return_value = httpReconnect (cups->priv->connection);
|
||||
- if (return_value == 0) {
|
||||
- break;
|
||||
- }
|
||||
- g_usleep (RECONNECT_DELAY);
|
||||
+ return_value = httpReconnect (cups->priv->connection);
|
||||
+ if (return_value == 0)
|
||||
+ break;
|
||||
+ g_usleep (RECONNECT_DELAY);
|
||||
}
|
||||
|
||||
cups->priv->reconnecting = FALSE;
|
||||
@@ -347,6 +346,7 @@ _CPH_CUPS_IS_VALID (ppd_filename, "PPD f
|
||||
_CPH_CUPS_IS_VALID (job_sheet, "job sheet", FALSE)
|
||||
_CPH_CUPS_IS_VALID (error_policy, "error policy", FALSE)
|
||||
_CPH_CUPS_IS_VALID (op_policy, "op policy", FALSE)
|
||||
+_CPH_CUPS_IS_VALID (job_hold_until, "job hold until", FALSE)
|
||||
|
||||
/* Check for users. Those are some printable strings, which souldn't be NULL.
|
||||
* They should also not be empty, but it appears that it's possible to carry
|
||||
@@ -411,7 +411,7 @@ _cph_cups_add_class_uri (ipp_t *req
|
||||
|
||||
static void
|
||||
_cph_cups_add_job_uri (ipp_t *request,
|
||||
- gint job_id)
|
||||
+ int job_id)
|
||||
{
|
||||
char uri[HTTP_MAX_URI + 1];
|
||||
|
||||
@@ -585,12 +585,18 @@ _cph_cups_send_new_printer_class_request
|
||||
static gboolean
|
||||
_cph_cups_send_new_simple_job_request (CphCups *cups,
|
||||
ipp_op_t op,
|
||||
- gint job_id,
|
||||
+ int job_id,
|
||||
+ const char *user_name,
|
||||
CphResource resource)
|
||||
{
|
||||
ipp_t *request;
|
||||
|
||||
request = ippNewRequest (op);
|
||||
+
|
||||
+ if (user_name != NULL)
|
||||
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
|
||||
+ "requesting-user-name", NULL, user_name);
|
||||
+
|
||||
_cph_cups_add_job_uri (request, job_id);
|
||||
|
||||
return _cph_cups_send_request (cups, request, resource);
|
||||
@@ -598,18 +604,23 @@ _cph_cups_send_new_simple_job_request (C
|
||||
|
||||
static gboolean
|
||||
_cph_cups_send_new_job_attributes_request (CphCups *cups,
|
||||
- gint job_id,
|
||||
+ int job_id,
|
||||
const char *name,
|
||||
const char *value,
|
||||
+ const char *user_name,
|
||||
CphResource resource)
|
||||
{
|
||||
cups_option_t *options = NULL;
|
||||
ipp_t *request;
|
||||
- gint num_options = 0;
|
||||
+ 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);
|
||||
@@ -894,6 +905,7 @@ cph_cups_file_get (CphCups *cups,
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -908,6 +920,7 @@ cph_cups_file_get (CphCups *cups,
|
||||
chown (filename, uid, gid);
|
||||
|
||||
_cph_cups_set_internal_status (cups, NULL);
|
||||
+
|
||||
cups->priv->last_status = cupsGetFile (cups->priv->connection,
|
||||
resource, filename);
|
||||
}
|
||||
@@ -1687,41 +1700,78 @@ cph_cups_server_set_settings (CphCups
|
||||
}
|
||||
|
||||
gboolean
|
||||
-cph_cups_job_cancel (CphCups *cups,
|
||||
- gint job_id)
|
||||
+cph_cups_job_cancel (CphCups *cups,
|
||||
+ int job_id,
|
||||
+ const char *user_name)
|
||||
{
|
||||
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
|
||||
return _cph_cups_send_new_simple_job_request (cups, IPP_CANCEL_JOB,
|
||||
job_id,
|
||||
+ user_name,
|
||||
CPH_RESOURCE_ADMIN);
|
||||
}
|
||||
|
||||
gboolean
|
||||
-cph_cups_job_restart (CphCups *cups,
|
||||
- gint job_id)
|
||||
+cph_cups_job_restart (CphCups *cups,
|
||||
+ int job_id,
|
||||
+ const char *user_name)
|
||||
{
|
||||
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
|
||||
return _cph_cups_send_new_simple_job_request (cups, IPP_RESTART_JOB,
|
||||
job_id,
|
||||
+ user_name,
|
||||
CPH_RESOURCE_ADMIN);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cph_cups_job_set_hold_until (CphCups *cups,
|
||||
- gint job_id,
|
||||
- const char *job_hold_until)
|
||||
+ 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_hold_until_valid (cups, job_hold_until))
|
||||
+ return FALSE;
|
||||
+
|
||||
return _cph_cups_send_new_job_attributes_request (cups,
|
||||
job_id,
|
||||
"job-hold-until",
|
||||
job_hold_until,
|
||||
+ user_name,
|
||||
CPH_RESOURCE_ADMIN);
|
||||
}
|
||||
|
||||
+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 = 0;
|
||||
+ 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) {
|
||||
+ status = CPH_JOB_STATUS_NOT_OWNED_BY_USER;
|
||||
+ if (user != NULL && g_strcmp0 (jobs[i].user, user) == 0)
|
||||
+ status = CPH_JOB_STATUS_OWNED_BY_USER;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ cupsFreeJobs (num_jobs, jobs);
|
||||
+
|
||||
+ return status;
|
||||
+}
|
||||
+
|
||||
/******************************************************
|
||||
* Non-object functions
|
||||
******************************************************/
|
||||
@@ -1788,28 +1838,3 @@ cph_cups_is_printer_uri_local (const cha
|
||||
/* we don't know, so we assume it's not local */
|
||||
return FALSE;
|
||||
}
|
||||
-
|
||||
-gboolean
|
||||
-cph_cups_is_job_owner (CphCups *cups,
|
||||
- gint job_id,
|
||||
- const char *user)
|
||||
-{
|
||||
- cups_job_t *jobs;
|
||||
- gboolean user_job = FALSE;
|
||||
- gint num_jobs = 0;
|
||||
- gint i;
|
||||
-
|
||||
- g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
-
|
||||
- if (user == NULL)
|
||||
- return FALSE;
|
||||
-
|
||||
- num_jobs = cupsGetJobs2 (cups->priv->connection, &jobs, NULL, 0, 0);
|
||||
-
|
||||
- for (i = 0; i < num_jobs; i++) {
|
||||
- if (jobs[i].id == job_id && g_strcmp0 (jobs[i].user, user) == 0)
|
||||
- user_job = TRUE;
|
||||
- }
|
||||
-
|
||||
- return user_job;
|
||||
-}
|
||||
--- src/cups.h 2009-02-27 14:55:03.000000000 +0100
|
||||
+++ src/cups.h 2009-02-27 14:53:40.000000000 +0100
|
||||
@@ -48,6 +48,13 @@ typedef struct
|
||||
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);
|
||||
@@ -161,18 +168,21 @@ gboolean cph_cups_is_printer_local (CphC
|
||||
gboolean cph_cups_is_printer_uri_local (const char *uri);
|
||||
|
||||
gboolean cph_cups_job_cancel (CphCups *cups,
|
||||
- gint job_id);
|
||||
+ int job_id,
|
||||
+ const char *user_name);
|
||||
|
||||
gboolean cph_cups_job_restart (CphCups *cups,
|
||||
- gint job_id);
|
||||
+ int job_id,
|
||||
+ const char *user_name);
|
||||
|
||||
gboolean cph_cups_job_set_hold_until (CphCups *cups,
|
||||
- gint job_id,
|
||||
- const char *job_hold_until);
|
||||
-
|
||||
-gboolean cph_cups_is_job_owner (CphCups *cups,
|
||||
- gint job_id,
|
||||
- const char *user);
|
||||
+ 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
|
||||
|
||||
--- src/cups-pk-helper-mechanism.c 2009-02-27 14:55:03.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.c 2009-02-27 14:53:40.000000000 +0100
|
||||
@@ -47,8 +47,6 @@
|
||||
|
||||
#include <polkit-dbus/polkit-dbus.h>
|
||||
|
||||
-#include <cups/cups.h>
|
||||
-
|
||||
#include <pwd.h>
|
||||
|
||||
#include "cups-pk-helper-mechanism.h"
|
||||
@@ -470,6 +468,28 @@ _cph_mechanism_get_action_for_name (CphM
|
||||
return "printer-remote-edit";
|
||||
}
|
||||
|
||||
+char *
|
||||
+_cph_mechanism_get_callers_user_name (CphMechanism *mechanism,
|
||||
+ DBusGMethodInvocation *context)
|
||||
+{
|
||||
+ unsigned long sender_uid;
|
||||
+ struct passwd *password_entry;
|
||||
+ DBusError dbus_error;
|
||||
+ gchar *sender;
|
||||
+ char *user_name = NULL;
|
||||
+
|
||||
+ sender = dbus_g_method_get_sender (context);
|
||||
+ dbus_error_init (&dbus_error);
|
||||
+ sender_uid = dbus_bus_get_unix_user (dbus_g_connection_get_connection (mechanism->priv->system_bus_connection), sender, &dbus_error);
|
||||
+ password_entry = getpwuid ((uid_t) sender_uid);
|
||||
+
|
||||
+ if (password_entry != NULL)
|
||||
+ user_name = g_strdup (password_entry->pw_name);
|
||||
+
|
||||
+ g_free (sender);
|
||||
+
|
||||
+ return user_name;
|
||||
+}
|
||||
|
||||
/* helpers */
|
||||
|
||||
@@ -902,18 +922,21 @@ cph_mechanism_printer_set_default (CphMe
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
gboolean ret;
|
||||
- const char *action;
|
||||
+ const char *last_action;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
+ last_action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
if (!_check_polkit_for_action_v (mechanism, context,
|
||||
"printeraddremove",
|
||||
+ /* this is not the last check because
|
||||
+ * it's likely most useful to the user
|
||||
+ * to give "printer-X-edit" powers */
|
||||
+ "printer-default",
|
||||
/* quite important, since it's
|
||||
* automatically called after adding a
|
||||
* printer */
|
||||
- action,
|
||||
- "printer-set-default",
|
||||
+ last_action,
|
||||
NULL))
|
||||
return FALSE;
|
||||
|
||||
@@ -930,19 +953,21 @@ cph_mechanism_printer_set_enabled (CphMe
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
gboolean ret;
|
||||
- const char *action;
|
||||
+ const char *last_action;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
-
|
||||
+ last_action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
if (!_check_polkit_for_action_v (mechanism, context,
|
||||
"printeraddremove",
|
||||
+ /* this is not the last check because
|
||||
+ * it's likely most useful to the user
|
||||
+ * to give "printer-X-edit" powers */
|
||||
+ "printer-enable",
|
||||
/* quite important, since it's
|
||||
* automatically called after adding a
|
||||
* printer */
|
||||
- action,
|
||||
- "printer-enable",
|
||||
+ last_action,
|
||||
NULL))
|
||||
return FALSE;
|
||||
|
||||
@@ -1013,115 +1038,114 @@ cph_mechanism_server_set_settings (CphMe
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
-gchar *
|
||||
-cph_mechanism_get_callers_user_name (CphMechanism *mechanism,
|
||||
- DBusGMethodInvocation *context)
|
||||
-{
|
||||
- unsigned long sender_uid;
|
||||
- struct passwd *password_entry;
|
||||
- const gchar *sender;
|
||||
- DBusError dbus_error;
|
||||
- gchar *user_name = NULL;
|
||||
-
|
||||
- sender = dbus_g_method_get_sender (context);
|
||||
- dbus_error_init (&dbus_error);
|
||||
- sender_uid = dbus_bus_get_unix_user (dbus_g_connection_get_connection (mechanism->priv->system_bus_connection), sender, &dbus_error);
|
||||
- password_entry = getpwuid ((uid_t) sender_uid);
|
||||
-
|
||||
- if (password_entry != NULL) {
|
||||
- user_name = g_strdup(password_entry->pw_name);
|
||||
- }
|
||||
-
|
||||
- return user_name;
|
||||
-}
|
||||
-
|
||||
gboolean
|
||||
cph_mechanism_job_cancel (CphMechanism *mechanism,
|
||||
- gint id,
|
||||
+ int id,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
- gboolean ret;
|
||||
- gboolean callers_job = FALSE;
|
||||
- char *user_name = NULL;
|
||||
+ CphJobStatus job_status;
|
||||
+ gboolean ret;
|
||||
+ char *user_name = NULL;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- user_name = cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
- callers_job = cph_cups_is_job_owner (mechanism->priv->cups, id, user_name);
|
||||
- g_free (user_name);
|
||||
+ user_name = _cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
+ job_status = cph_cups_job_get_status (mechanism->priv->cups, id, user_name);
|
||||
|
||||
- if (callers_job) {
|
||||
- if (!_check_polkit_for_action (mechanism, context, "job-cancel"))
|
||||
- return FALSE;
|
||||
- }
|
||||
- else {
|
||||
- if (!_check_polkit_for_action (mechanism, context, "job-cancel-another-owner"))
|
||||
+ 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;
|
||||
+ break;
|
||||
+ }
|
||||
+ case CPH_JOB_STATUS_NOT_OWNED_BY_USER: {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-not-owned-edit"))
|
||||
+ return FALSE;
|
||||
+ break;
|
||||
+ }
|
||||
+ case CPH_JOB_STATUS_INVALID:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
- ret = cph_cups_job_cancel (mechanism->priv->cups, id);
|
||||
+ ret = cph_cups_job_cancel (mechanism->priv->cups, id, user_name);
|
||||
_cph_mechanism_return_error (mechanism, context, !ret);
|
||||
|
||||
+ g_free (user_name);
|
||||
+
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cph_mechanism_job_restart (CphMechanism *mechanism,
|
||||
- gint id,
|
||||
+ int id,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
- gboolean ret;
|
||||
- gboolean callers_job = FALSE;
|
||||
- char *user_name = NULL;
|
||||
+ CphJobStatus job_status;
|
||||
+ gboolean ret;
|
||||
+ char *user_name = NULL;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- user_name = cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
- callers_job = cph_cups_is_job_owner (mechanism->priv->cups, id, user_name);
|
||||
- g_free (user_name);
|
||||
+ user_name = _cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
+ job_status = cph_cups_job_get_status (mechanism->priv->cups, id, user_name);
|
||||
|
||||
- if (callers_job) {
|
||||
- if (!_check_polkit_for_action (mechanism, context, "job-restart"))
|
||||
- return FALSE;
|
||||
- }
|
||||
- else {
|
||||
- if (!_check_polkit_for_action (mechanism, context, "job-restart-another-owner"))
|
||||
+ 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;
|
||||
+ break;
|
||||
+ }
|
||||
+ case CPH_JOB_STATUS_NOT_OWNED_BY_USER: {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-not-owned-edit"))
|
||||
+ return FALSE;
|
||||
+ break;
|
||||
+ }
|
||||
+ case CPH_JOB_STATUS_INVALID:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
- ret = cph_cups_job_restart (mechanism->priv->cups, id);
|
||||
+ ret = cph_cups_job_restart (mechanism->priv->cups, id, user_name);
|
||||
_cph_mechanism_return_error (mechanism, context, !ret);
|
||||
|
||||
+ g_free (user_name);
|
||||
+
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
|
||||
- gint id,
|
||||
+ int id,
|
||||
const char *job_hold_until,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
- gboolean ret;
|
||||
- gboolean callers_job = FALSE;
|
||||
- char *user_name = NULL;
|
||||
+ CphJobStatus job_status;
|
||||
+ gboolean ret;
|
||||
+ char *user_name = NULL;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- user_name = cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
- callers_job = cph_cups_is_job_owner (mechanism->priv->cups, id, user_name);
|
||||
- g_free (user_name);
|
||||
+ user_name = _cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
+ job_status = cph_cups_job_get_status (mechanism->priv->cups, id, user_name);
|
||||
|
||||
- if (callers_job) {
|
||||
- if (!_check_polkit_for_action (mechanism, context, "job-set-hold-until"))
|
||||
- return FALSE;
|
||||
- }
|
||||
- else {
|
||||
- if (!_check_polkit_for_action (mechanism, context, "job-set-hold-until-another-owner"))
|
||||
+ 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;
|
||||
+ break;
|
||||
+ }
|
||||
+ case CPH_JOB_STATUS_NOT_OWNED_BY_USER: {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-not-owned-edit"))
|
||||
+ return FALSE;
|
||||
+ break;
|
||||
+ }
|
||||
+ case CPH_JOB_STATUS_INVALID:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
- ret = cph_cups_job_set_hold_until (mechanism->priv->cups, id, job_hold_until);
|
||||
+ ret = cph_cups_job_set_hold_until (mechanism->priv->cups, id, job_hold_until, user_name);
|
||||
_cph_mechanism_return_error (mechanism, context, !ret);
|
||||
|
||||
+ g_free (user_name);
|
||||
+
|
||||
return TRUE;
|
||||
}
|
||||
--- src/cups-pk-helper-mechanism.h 2009-02-27 14:55:03.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.h 2009-02-27 14:53:40.000000000 +0100
|
||||
@@ -222,17 +222,17 @@ cph_mechanism_server_set_settings (CphMe
|
||||
|
||||
gboolean
|
||||
cph_mechanism_job_cancel (CphMechanism *mechanism,
|
||||
- gint id,
|
||||
+ int id,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
gboolean
|
||||
cph_mechanism_job_restart (CphMechanism *mechanism,
|
||||
- gint id,
|
||||
+ int id,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
gboolean
|
||||
cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
|
||||
- gint id,
|
||||
+ int id,
|
||||
const char *job_hold_until,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
--- src/org.opensuse.CupsPkHelper.Mechanism.conf 2008-09-19 12:48:34.000000000 +0200
|
||||
+++ src/org.opensuse.CupsPkHelper.Mechanism.conf 2009-02-06 15:39:25.000000000 +0100
|
||||
@@ -8,12 +8,11 @@
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="org.opensuse.CupsPkHelper.Mechanism"/>
|
||||
- <allow send_interface="org.opensuse.CupsPkHelper.Mechanism"/>
|
||||
</policy>
|
||||
|
||||
<!-- Allow anyone to invoke methods on the interfaces -->
|
||||
<policy context="default">
|
||||
- <allow send_interface="org.opensuse.CupsPkHelper.Mechanism"/>
|
||||
+ <allow send_destination="org.opensuse.CupsPkHelper.Mechanism"/>
|
||||
</policy>
|
||||
|
||||
</busconfig>
|
||||
--- src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-27 14:55:03.000000000 +0100
|
||||
+++ src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-27 14:53:40.000000000 +0100
|
||||
@@ -68,54 +68,18 @@
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
- <action id="org.opensuse.cupspkhelper.mechanism.job-cancel">
|
||||
- <_description>Cancel a job</_description>
|
||||
- <_message>Privileges are required to cancel a job.</_message>
|
||||
+ <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>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>auth_self</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
- <action id="org.opensuse.cupspkhelper.mechanism.job-cancel-another-owner">
|
||||
- <_description>Cancel a job owned by another user</_description>
|
||||
- <_message>Privileges are required to cancel a job owned by another user.</_message>
|
||||
- <defaults>
|
||||
- <allow_inactive>no</allow_inactive>
|
||||
- <allow_active>auth_admin</allow_active>
|
||||
- </defaults>
|
||||
- </action>
|
||||
-
|
||||
- <action id="org.opensuse.cupspkhelper.mechanism.job-restart">
|
||||
- <_description>Restart a job</_description>
|
||||
- <_message>Privileges are required to restart a job.</_message>
|
||||
- <defaults>
|
||||
- <allow_inactive>no</allow_inactive>
|
||||
- <allow_active>yes</allow_active>
|
||||
- </defaults>
|
||||
- </action>
|
||||
-
|
||||
- <action id="org.opensuse.cupspkhelper.mechanism.job-restart-another-owner">
|
||||
- <_description>Restart a job owned by another user</_description>
|
||||
- <_message>Privileges are required to restart a job owned by another user.</_message>
|
||||
- <defaults>
|
||||
- <allow_inactive>no</allow_inactive>
|
||||
- <allow_active>auth_admin</allow_active>
|
||||
- </defaults>
|
||||
- </action>
|
||||
-
|
||||
- <action id="org.opensuse.cupspkhelper.mechanism.job-set-hold-until">
|
||||
- <_description>Set hold-until time of a job</_description>
|
||||
- <_message>Privileges are required to set hold-until time of a job.</_message>
|
||||
- <defaults>
|
||||
- <allow_inactive>no</allow_inactive>
|
||||
- <allow_active>yes</allow_active>
|
||||
- </defaults>
|
||||
- </action>
|
||||
-
|
||||
- <action id="org.opensuse.cupspkhelper.mechanism.job-set-hold-until-another-owner">
|
||||
- <_description>Set hold-until time of a job owned by another user</_description>
|
||||
- <_message>Privileges are required to set hold-until time of a job owned by another user.</_message>
|
||||
+ <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>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>auth_admin</allow_active>
|
@ -1,150 +0,0 @@
|
||||
--- src/cups.c 2009-02-13 11:55:38.000000000 +0100
|
||||
+++ src/cups.c 2009-02-13 11:57:39.000000000 +0100
|
||||
@@ -45,6 +45,9 @@
|
||||
|
||||
#include "cups.h"
|
||||
|
||||
+#define MAX_RECONNECT_ATTEMPTS 100
|
||||
+#define RECONNECT_DELAY 100000
|
||||
+
|
||||
/*
|
||||
getPrinters
|
||||
getDests
|
||||
@@ -114,6 +117,7 @@ struct CphCupsPrivate
|
||||
http_t *connection;
|
||||
ipp_status_t last_status;
|
||||
char *internal_status;
|
||||
+ gboolean reconnecting;
|
||||
};
|
||||
|
||||
static GObject *cph_cups_constructor (GType type,
|
||||
@@ -172,6 +176,31 @@ cph_cups_init (CphCups *cups)
|
||||
cups->priv->connection = NULL;
|
||||
cups->priv->last_status = IPP_OK;
|
||||
cups->priv->internal_status = NULL;
|
||||
+ cups->priv->reconnecting = FALSE;
|
||||
+}
|
||||
+
|
||||
+gboolean
|
||||
+cph_cups_reconnect (CphCups *cups)
|
||||
+{
|
||||
+ gint return_value = -1;
|
||||
+ gint i;
|
||||
+
|
||||
+ cups->priv->reconnecting = TRUE;
|
||||
+
|
||||
+ for (i = 0; i < MAX_RECONNECT_ATTEMPTS; i++) {
|
||||
+ return_value = httpReconnect (cups->priv->connection);
|
||||
+ if (return_value == 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+ g_usleep (RECONNECT_DELAY);
|
||||
+ }
|
||||
+
|
||||
+ cups->priv->reconnecting = FALSE;
|
||||
+
|
||||
+ if (return_value == 0)
|
||||
+ return TRUE;
|
||||
+ else
|
||||
+ return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -848,6 +877,10 @@ cph_cups_file_get (CphCups *cups,
|
||||
const char *resource,
|
||||
const char *filename)
|
||||
{
|
||||
+ struct stat file_stat;
|
||||
+ uid_t uid = 0;
|
||||
+ gid_t gid = 0;
|
||||
+
|
||||
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
|
||||
if (!_cph_cups_is_resource_valid (cups, resource))
|
||||
@@ -855,12 +888,31 @@ cph_cups_file_get (CphCups *cups,
|
||||
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);
|
||||
|
||||
+ if (cups->priv->last_status != HTTP_OK) {
|
||||
+ int fd;
|
||||
+
|
||||
+ if (cph_cups_reconnect (cups)) {
|
||||
+
|
||||
+ /* if cupsGetFile fail then filename is erased */
|
||||
+ 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;
|
||||
}
|
||||
|
||||
@@ -882,6 +934,9 @@ cph_cups_file_put (CphCups *cups,
|
||||
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);
|
||||
}
|
||||
@@ -1613,6 +1668,9 @@ cph_cups_server_set_settings (CphCups
|
||||
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) {
|
||||
--- src/cups-pk-helper-mechanism.c 2009-02-13 11:55:38.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.c 2009-02-13 11:55:52.000000000 +0100
|
||||
@@ -60,7 +60,8 @@
|
||||
static gboolean
|
||||
do_exit (gpointer user_data)
|
||||
{
|
||||
- g_object_unref (CPH_MECHANISM (user_data));
|
||||
+ if (user_data != NULL)
|
||||
+ g_object_unref (CPH_MECHANISM (user_data));
|
||||
|
||||
exit (0);
|
||||
|
||||
@@ -540,10 +541,6 @@ cph_mechanism_file_put (CphMechanism
|
||||
ret = cph_cups_file_put (mechanism->priv->cups, resource, filename);
|
||||
_cph_mechanism_return_error (mechanism, context, !ret);
|
||||
|
||||
- /* TODO: this is a workaround for bnc#447422
|
||||
- * https://bugzilla.novell.com/show_bug.cgi?id=447422 */
|
||||
- do_exit (NULL);
|
||||
-
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
--- src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-13 11:55:38.000000000 +0100
|
||||
+++ src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-13 11:55:52.000000000 +0100
|
||||
@@ -114,7 +114,7 @@
|
||||
</action>
|
||||
|
||||
<action id="org.opensuse.cupspkhelper.mechanism.job-set-hold-until-another-owner">
|
||||
- <_description>Set hold-until time of a job owned by another</_description>
|
||||
+ <_description>Set hold-until time of a job owned by another user</_description>
|
||||
<_message>Privileges are required to set hold-until time of a job owned by another user.</_message>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
@ -1,6 +1,6 @@
|
||||
Name: cups-pk-helper
|
||||
Version: 0.0.3
|
||||
Release: 6%{?dist}
|
||||
Version: 0.0.4
|
||||
Release: 1%{?dist}
|
||||
Summary: A helper that makes system-config-printer use PolicyKit
|
||||
|
||||
Group: System Environment/Base
|
||||
@ -8,12 +8,6 @@ License: GPLv2+
|
||||
URL: http://www.vuntz.net/download/cups-pk-helper/
|
||||
Source0: http://www.vuntz.net/download/cups-pk-helper/cups-pk-helper-%{version}.tar.bz2
|
||||
|
||||
Patch0: dependencies.patch
|
||||
Patch1: pk_order.patch
|
||||
Patch2: pk_jobs.patch
|
||||
Patch3: cph_reconnect.patch
|
||||
Patch4: cph_policies.patch
|
||||
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
|
||||
BuildRequires: cups-devel >= 1.2
|
||||
@ -26,6 +20,10 @@ BuildRequires: intltool >= 0.40.0
|
||||
BuildRequires: gettext-devel >= 0.17
|
||||
|
||||
Requires: python >= 2.4
|
||||
Requires: cups-libs >= 1.2
|
||||
Requires: dbus >= 1.2
|
||||
Requires: dbus-glib >= 0.74
|
||||
Requires: glib2 >= 2.14.0
|
||||
|
||||
|
||||
%description
|
||||
@ -35,12 +33,6 @@ interfaces available under control of PolicyKit.
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%patch0 -p0 -b .dependencies
|
||||
%patch1 -p0 -b .pk-order
|
||||
%patch2 -p0 -b .pk-jobs
|
||||
%patch3 -p0 -b .cph-reconnect
|
||||
%patch4 -p0 -b .cph-policies
|
||||
|
||||
%build
|
||||
%configure
|
||||
make %{?_smp_mflags}
|
||||
@ -66,6 +58,9 @@ rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
|
||||
%changelog
|
||||
* Tue Mar 31 2009 Marek Kasik <mkasik@redhat.com> - 0.0.4-1
|
||||
- Update to 0.0.4
|
||||
|
||||
* Fri Feb 27 2009 Marek Kasik <mkasik@redhat.com> - 0.0.3-6
|
||||
- Replace job-cancel, job-restart and job-set-hold-until with job-edit
|
||||
- Replace job-cancel-another-owner, job-restart-another-owner
|
||||
|
@ -1,16 +0,0 @@
|
||||
diff -up ./configure.ac.orig ./configure.ac
|
||||
--- ./configure.ac.orig 2008-11-21 07:33:43.000000000 +0100
|
||||
+++ ./configure.ac 2009-01-14 13:49:17.000000000 +0100
|
||||
@@ -56,9 +56,9 @@ PKG_CHECK_MODULES(CUPS_PK, glib-2.0 >= $
|
||||
AC_SUBST(CUPS_PK_CFLAGS)
|
||||
AC_SUBST(CUPS_PK_LIBS)
|
||||
|
||||
-PKG_CHECK_MODULES(CUPS_PK_GNOME, gtk+-2.0 >= $GTK_REQUIRED \
|
||||
- dbus-1 >= $DBUS_REQUIRED \
|
||||
- dbus-glib-1 >= $DBUS_GLIB_REQUIRED)
|
||||
+PKG_CHECK_MODULES(CUPS_PK_GNOME, gtk2 >= $GTK_REQUIRED \
|
||||
+ dbus >= $DBUS_REQUIRED \
|
||||
+ dbus-glib >= $DBUS_GLIB_REQUIRED)
|
||||
AC_SUBST(CUPS_PK_GNOME_CFLAGS)
|
||||
AC_SUBST(CUPS_PK_GNOME_LIBS)
|
||||
|
402
pk_jobs.patch
402
pk_jobs.patch
@ -1,402 +0,0 @@
|
||||
--- src/cups.c 2009-01-28 12:51:49.000000000 +0100
|
||||
+++ src/cups.c 2009-01-28 10:59:36.000000000 +0100
|
||||
@@ -381,6 +381,18 @@ _cph_cups_add_class_uri (ipp_t *req
|
||||
}
|
||||
|
||||
static void
|
||||
+_cph_cups_add_job_uri (ipp_t *request,
|
||||
+ gint 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
|
||||
_cph_cups_set_internal_status (CphCups *cups,
|
||||
const char *status)
|
||||
{
|
||||
@@ -541,6 +553,41 @@ _cph_cups_send_new_printer_class_request
|
||||
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,
|
||||
+ gint job_id,
|
||||
+ CphResource resource)
|
||||
+{
|
||||
+ ipp_t *request;
|
||||
+
|
||||
+ request = ippNewRequest (op);
|
||||
+ _cph_cups_add_job_uri (request, job_id);
|
||||
+
|
||||
+ return _cph_cups_send_request (cups, request, resource);
|
||||
+}
|
||||
+
|
||||
+static gboolean
|
||||
+_cph_cups_send_new_job_attributes_request (CphCups *cups,
|
||||
+ gint job_id,
|
||||
+ const char *name,
|
||||
+ const char *value,
|
||||
+ CphResource resource)
|
||||
+{
|
||||
+ cups_option_t *options = NULL;
|
||||
+ ipp_t *request;
|
||||
+ gint num_options = 0;
|
||||
+
|
||||
+ request = ippNewRequest (IPP_SET_JOB_ATTRIBUTES);
|
||||
+ _cph_cups_add_job_uri (request, job_id);
|
||||
+
|
||||
+ 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,
|
||||
@@ -1581,6 +1628,42 @@ cph_cups_server_set_settings (CphCups
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
+gboolean
|
||||
+cph_cups_job_cancel (CphCups *cups,
|
||||
+ gint job_id)
|
||||
+{
|
||||
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
+
|
||||
+ return _cph_cups_send_new_simple_job_request (cups, IPP_CANCEL_JOB,
|
||||
+ job_id,
|
||||
+ CPH_RESOURCE_ADMIN);
|
||||
+}
|
||||
+
|
||||
+gboolean
|
||||
+cph_cups_job_restart (CphCups *cups,
|
||||
+ gint job_id)
|
||||
+{
|
||||
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
+
|
||||
+ return _cph_cups_send_new_simple_job_request (cups, IPP_RESTART_JOB,
|
||||
+ job_id,
|
||||
+ CPH_RESOURCE_ADMIN);
|
||||
+}
|
||||
+
|
||||
+gboolean
|
||||
+cph_cups_job_set_hold_until (CphCups *cups,
|
||||
+ gint job_id,
|
||||
+ const char *job_hold_until)
|
||||
+{
|
||||
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
+
|
||||
+ return _cph_cups_send_new_job_attributes_request (cups,
|
||||
+ job_id,
|
||||
+ "job-hold-until",
|
||||
+ job_hold_until,
|
||||
+ CPH_RESOURCE_ADMIN);
|
||||
+}
|
||||
+
|
||||
/******************************************************
|
||||
* Non-object functions
|
||||
******************************************************/
|
||||
@@ -1647,3 +1730,28 @@ cph_cups_is_printer_uri_local (const cha
|
||||
/* we don't know, so we assume it's not local */
|
||||
return FALSE;
|
||||
}
|
||||
+
|
||||
+gboolean
|
||||
+cph_cups_is_job_owner (CphCups *cups,
|
||||
+ gint job_id,
|
||||
+ const char *user)
|
||||
+{
|
||||
+ cups_job_t *jobs;
|
||||
+ gboolean user_job = FALSE;
|
||||
+ gint num_jobs = 0;
|
||||
+ gint i;
|
||||
+
|
||||
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
|
||||
+
|
||||
+ if (user == NULL)
|
||||
+ return FALSE;
|
||||
+
|
||||
+ num_jobs = cupsGetJobs2 (cups->priv->connection, &jobs, NULL, 0, 0);
|
||||
+
|
||||
+ for (i = 0; i < num_jobs; i++) {
|
||||
+ if (jobs[i].id == job_id && g_strcmp0 (jobs[i].user, user) == 0)
|
||||
+ user_job = TRUE;
|
||||
+ }
|
||||
+
|
||||
+ return user_job;
|
||||
+}
|
||||
--- src/cups.h 2008-11-21 01:50:42.000000000 +0100
|
||||
+++ src/cups.h 2009-01-27 17:33:00.000000000 +0100
|
||||
@@ -160,6 +160,20 @@ gboolean cph_cups_is_printer_local (CphC
|
||||
|
||||
gboolean cph_cups_is_printer_uri_local (const char *uri);
|
||||
|
||||
+gboolean cph_cups_job_cancel (CphCups *cups,
|
||||
+ gint job_id);
|
||||
+
|
||||
+gboolean cph_cups_job_restart (CphCups *cups,
|
||||
+ gint job_id);
|
||||
+
|
||||
+gboolean cph_cups_job_set_hold_until (CphCups *cups,
|
||||
+ gint job_id,
|
||||
+ const char *job_hold_until);
|
||||
+
|
||||
+gboolean cph_cups_is_job_owner (CphCups *cups,
|
||||
+ gint job_id,
|
||||
+ const char *user);
|
||||
+
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* CPH_CUPS_H */
|
||||
--- src/cups-pk-helper-mechanism.c 2009-01-28 12:51:49.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.c 2009-01-28 11:39:16.000000000 +0100
|
||||
@@ -47,6 +47,10 @@
|
||||
|
||||
#include <polkit-dbus/polkit-dbus.h>
|
||||
|
||||
+#include <cups/cups.h>
|
||||
+
|
||||
+#include <pwd.h>
|
||||
+
|
||||
#include "cups-pk-helper-mechanism.h"
|
||||
#include "cups-pk-helper-mechanism-glue.h"
|
||||
#include "cups.h"
|
||||
@@ -1011,3 +1015,116 @@ cph_mechanism_server_set_settings (CphMe
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
+
|
||||
+gchar *
|
||||
+cph_mechanism_get_callers_user_name (CphMechanism *mechanism,
|
||||
+ DBusGMethodInvocation *context)
|
||||
+{
|
||||
+ unsigned long sender_uid;
|
||||
+ struct passwd *password_entry;
|
||||
+ const gchar *sender;
|
||||
+ DBusError dbus_error;
|
||||
+ gchar *user_name = NULL;
|
||||
+
|
||||
+ sender = dbus_g_method_get_sender (context);
|
||||
+ dbus_error_init (&dbus_error);
|
||||
+ sender_uid = dbus_bus_get_unix_user (dbus_g_connection_get_connection (mechanism->priv->system_bus_connection), sender, &dbus_error);
|
||||
+ password_entry = getpwuid ((uid_t) sender_uid);
|
||||
+
|
||||
+ if (password_entry != NULL) {
|
||||
+ user_name = g_strdup(password_entry->pw_name);
|
||||
+ }
|
||||
+
|
||||
+ return user_name;
|
||||
+}
|
||||
+
|
||||
+gboolean
|
||||
+cph_mechanism_job_cancel (CphMechanism *mechanism,
|
||||
+ gint id,
|
||||
+ DBusGMethodInvocation *context)
|
||||
+{
|
||||
+ gboolean ret;
|
||||
+ gboolean callers_job = FALSE;
|
||||
+ char *user_name = NULL;
|
||||
+
|
||||
+ reset_killtimer (mechanism);
|
||||
+
|
||||
+ user_name = cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
+ callers_job = cph_cups_is_job_owner (mechanism->priv->cups, id, user_name);
|
||||
+ g_free (user_name);
|
||||
+
|
||||
+ if (callers_job) {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-cancel"))
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+ else {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-cancel-another-owner"))
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
+ ret = cph_cups_job_cancel (mechanism->priv->cups, id);
|
||||
+ _cph_mechanism_return_error (mechanism, context, !ret);
|
||||
+
|
||||
+ return TRUE;
|
||||
+}
|
||||
+
|
||||
+gboolean
|
||||
+cph_mechanism_job_restart (CphMechanism *mechanism,
|
||||
+ gint id,
|
||||
+ DBusGMethodInvocation *context)
|
||||
+{
|
||||
+ gboolean ret;
|
||||
+ gboolean callers_job = FALSE;
|
||||
+ char *user_name = NULL;
|
||||
+
|
||||
+ reset_killtimer (mechanism);
|
||||
+
|
||||
+ user_name = cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
+ callers_job = cph_cups_is_job_owner (mechanism->priv->cups, id, user_name);
|
||||
+ g_free (user_name);
|
||||
+
|
||||
+ if (callers_job) {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-restart"))
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+ else {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-restart-another-owner"))
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
+ ret = cph_cups_job_restart (mechanism->priv->cups, id);
|
||||
+ _cph_mechanism_return_error (mechanism, context, !ret);
|
||||
+
|
||||
+ return TRUE;
|
||||
+}
|
||||
+
|
||||
+gboolean
|
||||
+cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
|
||||
+ gint id,
|
||||
+ const char *job_hold_until,
|
||||
+ DBusGMethodInvocation *context)
|
||||
+{
|
||||
+ gboolean ret;
|
||||
+ gboolean callers_job = FALSE;
|
||||
+ char *user_name = NULL;
|
||||
+
|
||||
+ reset_killtimer (mechanism);
|
||||
+
|
||||
+ user_name = cph_mechanism_get_callers_user_name (mechanism, context);
|
||||
+ callers_job = cph_cups_is_job_owner (mechanism->priv->cups, id, user_name);
|
||||
+ g_free (user_name);
|
||||
+
|
||||
+ if (callers_job) {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-set-hold-until"))
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+ else {
|
||||
+ if (!_check_polkit_for_action (mechanism, context, "job-set-hold-until-another-owner"))
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
+ ret = cph_cups_job_set_hold_until (mechanism->priv->cups, id, job_hold_until);
|
||||
+ _cph_mechanism_return_error (mechanism, context, !ret);
|
||||
+
|
||||
+ return TRUE;
|
||||
+}
|
||||
--- src/cups-pk-helper-mechanism.h 2008-11-21 01:57:03.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.h 2009-01-27 17:31:20.000000000 +0100
|
||||
@@ -220,6 +220,22 @@ cph_mechanism_server_set_settings (CphMe
|
||||
GHashTable *settings,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
+gboolean
|
||||
+cph_mechanism_job_cancel (CphMechanism *mechanism,
|
||||
+ gint id,
|
||||
+ DBusGMethodInvocation *context);
|
||||
+
|
||||
+gboolean
|
||||
+cph_mechanism_job_restart (CphMechanism *mechanism,
|
||||
+ gint id,
|
||||
+ DBusGMethodInvocation *context);
|
||||
+
|
||||
+gboolean
|
||||
+cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
|
||||
+ gint id,
|
||||
+ const char *job_hold_until,
|
||||
+ DBusGMethodInvocation *context);
|
||||
+
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* CPH_MECHANISM_H */
|
||||
--- src/cups-pk-helper-mechanism.xml 2008-11-21 01:55:52.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.xml 2009-01-27 17:26:57.000000000 +0100
|
||||
@@ -174,5 +174,23 @@
|
||||
<arg name="error" direction="out" type="s"/>
|
||||
</method>
|
||||
|
||||
+ <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="JobRestart">
|
||||
+ <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="JobSetHoldUntil">
|
||||
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
+ <arg name="jobid" direction="in" type="i"/>
|
||||
+ <arg name="job_hold_until" direction="in" type="s"/>
|
||||
+ <arg name="error" direction="out" type="s"/>
|
||||
+ </method>
|
||||
</interface>
|
||||
</node>
|
||||
--- src/org.opensuse.cupspkhelper.mechanism.policy.in 2008-11-21 00:58:16.000000000 +0100
|
||||
+++ src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-01-28 12:47:49.000000000 +0100
|
||||
@@ -68,6 +68,60 @@
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
+ <action id="org.opensuse.cupspkhelper.mechanism.job-cancel">
|
||||
+ <_description>Cancel a job</_description>
|
||||
+ <_message>Privileges are required to cancel a job.</_message>
|
||||
+ <defaults>
|
||||
+ <allow_inactive>no</allow_inactive>
|
||||
+ <allow_active>auth_self</allow_active>
|
||||
+ </defaults>
|
||||
+ </action>
|
||||
+
|
||||
+ <action id="org.opensuse.cupspkhelper.mechanism.job-cancel-another-owner">
|
||||
+ <_description>Cancel a job owned by another user</_description>
|
||||
+ <_message>Privileges are required to cancel a job owned by another user.</_message>
|
||||
+ <defaults>
|
||||
+ <allow_inactive>no</allow_inactive>
|
||||
+ <allow_active>auth_admin</allow_active>
|
||||
+ </defaults>
|
||||
+ </action>
|
||||
+
|
||||
+ <action id="org.opensuse.cupspkhelper.mechanism.job-restart">
|
||||
+ <_description>Restart a job</_description>
|
||||
+ <_message>Privileges are required to restart a job.</_message>
|
||||
+ <defaults>
|
||||
+ <allow_inactive>no</allow_inactive>
|
||||
+ <allow_active>yes</allow_active>
|
||||
+ </defaults>
|
||||
+ </action>
|
||||
+
|
||||
+ <action id="org.opensuse.cupspkhelper.mechanism.job-restart-another-owner">
|
||||
+ <_description>Restart a job owned by another user</_description>
|
||||
+ <_message>Privileges are required to restart a job owned by another user.</_message>
|
||||
+ <defaults>
|
||||
+ <allow_inactive>no</allow_inactive>
|
||||
+ <allow_active>auth_admin</allow_active>
|
||||
+ </defaults>
|
||||
+ </action>
|
||||
+
|
||||
+ <action id="org.opensuse.cupspkhelper.mechanism.job-set-hold-until">
|
||||
+ <_description>Set hold-until time of a job</_description>
|
||||
+ <_message>Privileges are required to set hold-until time of a job.</_message>
|
||||
+ <defaults>
|
||||
+ <allow_inactive>no</allow_inactive>
|
||||
+ <allow_active>yes</allow_active>
|
||||
+ </defaults>
|
||||
+ </action>
|
||||
+
|
||||
+ <action id="org.opensuse.cupspkhelper.mechanism.job-set-hold-until-another-owner">
|
||||
+ <_description>Set hold-until time of a job owned by another</_description>
|
||||
+ <_message>Privileges are required to set hold-until time of a job owned by another user.</_message>
|
||||
+ <defaults>
|
||||
+ <allow_inactive>no</allow_inactive>
|
||||
+ <allow_active>auth_admin</allow_active>
|
||||
+ </defaults>
|
||||
+ </action>
|
||||
+
|
||||
<!-- Deprecated -->
|
||||
<action id="org.opensuse.cupspkhelper.mechanism.printeraddremove">
|
||||
<_description>Add/Remove/Edit a printer</_description>
|
@ -1,65 +0,0 @@
|
||||
--- src/cups.c 2008-11-21 07:04:28.000000000 +0100
|
||||
+++ src/cups.c 2009-01-23 16:28:07.000000000 +0100
|
||||
@@ -1606,6 +1606,7 @@ cph_cups_is_printer_uri_local (const cha
|
||||
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;
|
||||
--- src/cups-pk-helper-mechanism.c 2008-11-21 07:28:20.000000000 +0100
|
||||
+++ src/cups-pk-helper-mechanism.c 2009-01-26 13:54:44.000000000 +0100
|
||||
@@ -901,21 +901,18 @@ cph_mechanism_printer_set_default (CphMe
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
gboolean ret;
|
||||
- const char *last_action;
|
||||
+ const char *action;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- last_action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
+ action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
if (!_check_polkit_for_action_v (mechanism, context,
|
||||
"printeraddremove",
|
||||
- /* this is not the last check because
|
||||
- * it's likely most useful to the user
|
||||
- * to give "printer-X-edit" powers */
|
||||
- "printer-default",
|
||||
/* quite important, since it's
|
||||
* automatically called after adding a
|
||||
* printer */
|
||||
- last_action,
|
||||
+ action,
|
||||
+ "printer-set-default",
|
||||
NULL))
|
||||
return FALSE;
|
||||
|
||||
@@ -932,21 +929,19 @@ cph_mechanism_printer_set_enabled (CphMe
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
gboolean ret;
|
||||
- const char *last_action;
|
||||
+ const char *action;
|
||||
|
||||
reset_killtimer (mechanism);
|
||||
|
||||
- last_action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
+ action = _cph_mechanism_get_action_for_name (mechanism, name);
|
||||
+
|
||||
if (!_check_polkit_for_action_v (mechanism, context,
|
||||
"printeraddremove",
|
||||
- /* this is not the last check because
|
||||
- * it's likely most useful to the user
|
||||
- * to give "printer-X-edit" powers */
|
||||
- "printer-enable",
|
||||
/* quite important, since it's
|
||||
* automatically called after adding a
|
||||
* printer */
|
||||
- last_action,
|
||||
+ action,
|
||||
+ "printer-enable",
|
||||
NULL))
|
||||
return FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user