6869007 Multi print jobs deleted by cancel(1).
6891815 Job can be cancelled by using spool file number even though there is not such a job number
--- a/usr/src/cmd/print/bsd-sysv-commands/cancel.c Thu Dec 24 15:56:33 2009 +0800
+++ b/usr/src/cmd/print/bsd-sysv-commands/cancel.c Thu Dec 24 13:57:19 2009 +0530
@@ -172,19 +172,26 @@
* corresponding job-id and send it to cancel
*/
rid = job_to_be_queried(svc, printer, id);
- if (rid >= 0)
+ if (rid < 0) {
+ /*
+ * Either it is a remote job which cannot be
+ * cancelled based on job-id or job-id is
+ * not found
+ */
+ exit_code = 1;
+ fprintf(OUT, "%s-%d: not-found\n", printer, id);
+ } else {
status = papiJobCancel(svc, printer, rid);
- else
- status = papiJobCancel(svc, printer, id);
-
- if (status == PAPI_NOT_AUTHORIZED) {
- mesg = papiStatusString(status);
- exit_code = 1;
- } else if (status != PAPI_OK) {
- mesg = verbose_papi_message(svc, status);
- exit_code = 1;
+ if (status == PAPI_NOT_AUTHORIZED) {
+ mesg = papiStatusString(status);
+ exit_code = 1;
+ } else if (status != PAPI_OK) {
+ mesg =
+ verbose_papi_message(svc, status);
+ exit_code = 1;
+ }
+ fprintf(OUT, "%s-%d: %s\n", printer, id, mesg);
}
- fprintf(OUT, "%s-%d: %s\n", printer, id, mesg);
} else { /* it's a printer */
if (user == NULL) {
--- a/usr/src/cmd/print/bsd-sysv-commands/common.c Thu Dec 24 15:56:33 2009 +0800
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.c Thu Dec 24 13:57:19 2009 +0530
@@ -75,6 +75,26 @@
return (-1);
}
+/*
+ * return 0 : argument passed is job-id && job-id matches
+ * or argument passed is user
+ */
+static int
+match_job_rid(int id, int ac, char *av[])
+{
+ int i;
+
+ for (i = 0; i < ac; i++)
+ if (isdigit(av[i][0]) != 0) {
+ if (id == atoi(av[i]))
+ /* job-id match */
+ return (0);
+ } else
+ /* argument passed is user */
+ return (0);
+ return (-1);
+}
+
static struct {
char *mime_type;
char *lp_type;
@@ -237,10 +257,11 @@
{
papi_status_t status;
papi_attribute_t **list = papiJobGetAttributeList(job);
- int id = 0;
+ int id = -1;
int rid = -1;
char *user = "";
char *mesg = gettext("cancelled");
+ int i = 0;
papiAttributeListGetInteger(list, NULL,
"job-id", &id);
@@ -254,6 +275,16 @@
(match_job(rid, user, ac, av) < 0))
return;
+ /*
+ * A remote lpd job should be cancelled only based on
+ * job-id-requested
+ */
+ if (rid != -1) {
+ if (match_job_rid(rid, ac, av) == -1)
+ /* job-id mismatch */
+ return;
+ }
+
status = papiJobCancel(svc, printer, id);
if (status != PAPI_OK)
mesg = papiStatusString(status);
@@ -586,6 +617,7 @@
{
papi_job_t *jobs = NULL;
papi_status_t status;
+ int ret = -1;
char *jattrs[] = { "job-id",
"job-id-requested", NULL };
@@ -603,20 +635,41 @@
for (i = 0; jobs[i] != NULL; i++) {
int32_t rid = -1;
+ int32_t jid = -1;
papi_attribute_t **list =
papiJobGetAttributeList(jobs[i]);
papiAttributeListGetInteger(list, NULL,
"job-id-requested", &rid);
+ papiAttributeListGetInteger(list, NULL,
+ "job-id", &jid);
- /* check if this matches with id */
+ /*
+ * check if id matches with either rid or jid
+ */
if (rid == id) {
/* get the actual id and return it */
papiAttributeListGetInteger(list, NULL,
"job-id", &id);
return (id);
+ } else if (id == jid) {
+ if (rid != -1) {
+ /*
+ * It is a remote lpd job
+ * can be cancelled only
+ * using rid
+ */
+ ret = -1;
+ } else {
+ /*
+ * its local or
+ * remote ipp job
+ */
+ return (id);
+ }
}
}
+ return (ret);
}
return (id);
}
--- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c Thu Dec 24 15:56:33 2009 +0800
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c Thu Dec 24 13:57:19 2009 +0530
@@ -1082,7 +1082,6 @@
papiJobListFree(jobs);
} else { /* a job */
papi_job_t job = NULL;
- int rid = id;
/* Once a job has been found stop processing */
flag = 0;
@@ -1093,12 +1092,12 @@
*/
id = job_to_be_queried(svc, printer, id);
- if (id > 0)
+ if (id >= 0)
status = papiJobQuery(svc, printer, id,
NULL, &job);
else
- status = papiJobQuery(svc, printer, rid,
- NULL, &job);
+ /* id not found */
+ status = PAPI_NOT_FOUND;
if (status != PAPI_OK) {
if (!print_flag)