6815222 lpstat -o reports incorrect job# for general user
authorsonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>
Thu, 09 Apr 2009 23:37:50 -0700
changeset 9331 d77964aece3d
parent 9330 ecc7651c9e05
child 9332 53f0cd254166
6815222 lpstat -o reports incorrect job# for general user
usr/src/cmd/lp/cmd/lpsched/disp1.c
usr/src/cmd/print/bsd-sysv-commands/cancel.c
usr/src/cmd/print/bsd-sysv-commands/common.c
usr/src/cmd/print/bsd-sysv-commands/common.h
usr/src/cmd/print/bsd-sysv-commands/lpstat.c
--- a/usr/src/cmd/lp/cmd/lpsched/disp1.c	Fri Apr 10 11:36:51 2009 +0530
+++ b/usr/src/cmd/lp/cmd/lpsched/disp1.c	Thu Apr 09 23:37:50 2009 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -113,7 +113,7 @@
     {
 	req_file = reqpath(file, &idno);
 	path = makepath(Lp_Tmp, req_file, (char *)0);
-	(void) chownmod(path, Lp_Uid, Lp_Gid, 0600);
+	(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
 	Free (path);
     
 	if (!(r = Getrequest(req_file)))
@@ -261,7 +261,7 @@
 			 * IPP job attribute file exists for this job so
 			 * change permissions and ownership of the file
 			 */
-			(void) chownmod(path, Lp_Uid, Lp_Gid, 0600); 
+			(void) chownmod(path, Lp_Uid, Lp_Gid, 0644); 
 			Free(path);
 		}
 		else
@@ -450,7 +450,7 @@
 	status = MNOSTART;
     else {
 	path = makepath(Lp_Tmp, rp->req_file, (char *)0);
-	(void) chownmod(path, Lp_Uid, Lp_Gid, 0600);
+	(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
 	Free (path);
 
 
@@ -475,7 +475,7 @@
 		 * IPP job attribute file exists for this job so
 		 * change permissions and ownership of the file
 		 */
-		(void) chownmod(path, Lp_Uid, Lp_Gid, 0600);
+		(void) chownmod(path, Lp_Uid, Lp_Gid, 0644);
 		Free (path);
 	}
 	else
--- a/usr/src/cmd/print/bsd-sysv-commands/cancel.c	Fri Apr 10 11:36:51 2009 +0530
+++ b/usr/src/cmd/print/bsd-sysv-commands/cancel.c	Thu Apr 09 23:37:50 2009 -0700
@@ -51,6 +51,17 @@
 	exit(1);
 }
 
+static int32_t
+get_job_id_requested(papi_job_t job) {
+	int32_t rid = -1;
+
+	papi_attribute_t **list = papiJobGetAttributeList(job);
+	papiAttributeListGetInteger(list, NULL,
+	    "job-id-requested", &rid);
+
+	return (rid);
+}
+
 int
 cancel_jobs_for_user(char *user, papi_encryption_t encryption, char *pname) {
 
@@ -101,6 +112,7 @@
 	char *user = NULL;
 	papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
 	int c;
+	int32_t rid = 0;
 
 	(void) setlocale(LC_ALL, "");
 	(void) textdomain("SUNW_OST_OSCMD");
@@ -143,7 +155,17 @@
 		if (id != -1) {	/* it's a job */
 			char *mesg = "cancelled";
 
-			status = papiJobCancel(svc, printer, id);
+			/*
+			 * Check if the job-id is job-id-requested
+			 * or job-id. If it is job-id-requested then find
+			 * corresponding job-id and send it to cancel
+			 */
+			rid = job_to_be_queried(svc, printer, id);
+			if (rid > 0)
+				status = papiJobCancel(svc, printer, rid);
+			else
+				status = papiJobCancel(svc, printer, id);
+
 			if (status == PAPI_NOT_AUTHORIZED) {
 				mesg = papiStatusString(status);
 				exit_code = 1;
@@ -183,9 +205,17 @@
 						    svc, status);
 						exit_code = 1;
 					}
-					fprintf(OUT, "%s-%d: %s\n", printer,
-					    id, mesg);
-
+					/*
+					 * If job-id-requested exists for this
+					 * job-id then that should be displayed
+					 */
+					rid = get_job_id_requested(*jobs);
+					if (rid > 0)
+						fprintf(OUT, "%s-%d: %s\n",
+						    printer, rid, mesg);
+					else
+						fprintf(OUT, "%s-%d: %s\n",
+						    printer, id, mesg);
 				}
 				papiJobListFree(jobs);
 
--- a/usr/src/cmd/print/bsd-sysv-commands/common.c	Fri Apr 10 11:36:51 2009 +0530
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.c	Thu Apr 09 23:37:50 2009 -0700
@@ -580,3 +580,43 @@
 
 	return (0);
 }
+
+int32_t
+job_to_be_queried(papi_service_t svc, char *printer, int32_t id)
+{
+	papi_job_t *jobs = NULL;
+	papi_status_t status;
+	char *jattrs[] = { "job-id",
+			"job-id-requested", NULL };
+
+	status = papiPrinterListJobs(svc, printer, jattrs, PAPI_LIST_JOBS_ALL,
+	    0, &jobs);
+
+	if (status != PAPI_OK) {
+		fprintf(stderr, gettext("Failed to query service for %s: %s\n"),
+		    printer, verbose_papi_message(svc, status));
+		return (-1);
+	}
+
+	if (jobs != NULL) {
+		int i = 0;
+
+		for (i = 0; jobs[i] != NULL; i++) {
+			int32_t rid = -1;
+			papi_attribute_t **list =
+			    papiJobGetAttributeList(jobs[i]);
+
+			papiAttributeListGetInteger(list, NULL,
+			    "job-id-requested", &rid);
+
+			/* check if this matches with id */
+			if (rid == id) {
+				/* get the actual id and return it */
+				papiAttributeListGetInteger(list, NULL,
+				    "job-id", &id);
+				return (id);
+			}
+		}
+	}
+	return (id);
+}
--- a/usr/src/cmd/print/bsd-sysv-commands/common.h	Fri Apr 10 11:36:51 2009 +0530
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.h	Thu Apr 09 23:37:50 2009 -0700
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  */
@@ -30,8 +30,6 @@
 
 /* $Id: common.h 162 2006-05-08 14:17:44Z njacobs $ */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <papi.h>
 
 #include <config-site.h>
@@ -63,6 +61,8 @@
 
 extern int cli_auth_callback(papi_service_t svc, void *app_data);
 
+extern int32_t job_to_be_queried(papi_service_t svc, char *printer, int32_t id);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c	Fri Apr 10 11:36:51 2009 +0530
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c	Thu Apr 09 23:37:50 2009 -0700
@@ -797,6 +797,7 @@
 	(void) papiAttributeListGetInteger(attrs, NULL,
 	    "job-id-requested", &id);
 
+
 	snprintf(request, sizeof (request), "%s-%d", printer, id);
 
 	if (show_rank != 0) {
@@ -813,6 +814,7 @@
 
 	(void) papiAttributeListGetInteger(attrs, NULL,
 	    "job-state", &jstate);
+
 	if (jstate == 0x0001)
 		printf(gettext(" being held"));
 	else if (jstate == 0x0800)
@@ -930,11 +932,22 @@
 			papiJobListFree(jobs);
 		} else {	/* a job */
 			papi_job_t job = NULL;
+			int rid = id;
 
 			/* Once a job has been found stop processing */
 			flag = 0;
 
-			status = papiJobQuery(svc, printer, id, NULL, &job);
+			/*
+			 * Job-id could be the job-id requested
+			 * Check if it is job-id or job-id-requested
+			 */
+			id = job_to_be_queried(svc, printer, id);
+
+			if (id > 0)
+				status = papiJobQuery(svc, printer, id, NULL, &job);
+			else
+				status = papiJobQuery(svc, printer, rid, NULL, &job);
+
 			if (status != PAPI_OK) {
 				if (!print_flag)
 					fprintf(stderr, gettext(