diff options
author | Vincent Untz <vuntz@novell.com> | 2009-02-28 03:17:28 +0100 |
---|---|---|
committer | Vincent Untz <vuntz@novell.com> | 2009-02-28 03:17:28 +0100 |
commit | 10024dbff8720f99e5ef12a78d8a3639ccbcf22a (patch) | |
tree | b08ac81a4522720253ff3fd7ab9d8b7cdb2e7e5f | |
parent | d6379339afde8b13005eb0ca45d547cbd190e636 (diff) |
Add checks for job id validity.
Also add a comment on why we don't check the user name for the
job-related functions.
-rw-r--r-- | src/cups.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -180,8 +180,8 @@ cph_cups_init (CphCups *cups) static gboolean cph_cups_reconnect (CphCups *cups) { - int return_value = -1; - int i; + int return_value = -1; + int i; for (i = 0; i < MAX_RECONNECT_ATTEMPTS; i++) { return_value = httpReconnect (cups->priv->connection); @@ -319,6 +319,22 @@ _cph_cups_is_class_name_valid (CphCups *cups, 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 @@ -1699,6 +1715,11 @@ cph_cups_job_cancel (CphCups *cups, { 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, @@ -1712,6 +1733,11 @@ cph_cups_job_restart (CphCups *cups, { 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, @@ -1726,8 +1752,12 @@ cph_cups_job_set_hold_until (CphCups *cups, { 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, |