Mercurial > illumos > illumos-gate
changeset 8966:ad150248f03c
6759604 general user on the lp client can cancel root user's print job
author | sonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM> |
---|---|
date | Mon, 02 Mar 2009 23:02:05 -0800 |
parents | 6adf6294c134 |
children | fa705deac3f5 |
files | usr/src/cmd/lp/lib/papi/job.c usr/src/cmd/print/bsd-sysv-commands/cancel.c usr/src/cmd/print/bsd-sysv-commands/common.c usr/src/lib/print/libpapi-lpd/common/lpd-cancel.c |
diffstat | 4 files changed, 75 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/lp/lib/papi/job.c Mon Mar 02 22:33:16 2009 -0800 +++ b/usr/src/cmd/lp/lib/papi/job.c Mon Mar 02 23:02:05 2009 -0800 @@ -33,7 +33,6 @@ #include <sys/stat.h> #include <papi_impl.h> - /* * for an older application that may have been linked with a pre-v1.0 * PAPI implementation. @@ -151,8 +150,24 @@ result = PAPI_OK; } - if ((result != PAPI_OK) && (strcmp(user, r->user) == 0)) - result = PAPI_OK; + if (result != PAPI_OK) { + if (strcmp(user, r->user) == 0) + result = PAPI_OK; + else { + /* + * user request r->user might contain the + * host info also + */ + char *token; + token = strtok(r->user, "@"); + + if (token != NULL) { + if (strcmp(user, token) == 0) + result = PAPI_OK; + free(token); + } + } + } freerequest(r); } else @@ -899,6 +914,9 @@ &user) == PAPI_OK) { REQUEST *r = getrequest(req_id); + if ((result = authorized(handle, job_id)) != PAPI_OK) + result = PAPI_NOT_AUTHORIZED; + if ((r != NULL) && (r->user != NULL) && (strcmp(r->user, user) != 0)) result = PAPI_NOT_AUTHORIZED;
--- a/usr/src/cmd/print/bsd-sysv-commands/cancel.c Mon Mar 02 22:33:16 2009 -0800 +++ b/usr/src/cmd/print/bsd-sysv-commands/cancel.c Mon Mar 02 23:02:05 2009 -0800 @@ -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. * */ @@ -60,7 +60,7 @@ int i, exit_code; if (pname == NULL) { - status = papiServiceCreate(&svc, NULL, user, NULL, + status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback, encryption, NULL); printers = interest_list(svc); papiServiceDestroy(svc); @@ -74,7 +74,7 @@ for (i = 0; printers[i] != NULL; i++) { char *printer = printers[i]; - status = papiServiceCreate(&svc, printer, user, NULL, + status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { @@ -129,7 +129,7 @@ (void) get_printer_id(av[c], &printer, &id); - status = papiServiceCreate(&svc, printer, user, NULL, + status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { fprintf(stderr,
--- a/usr/src/cmd/print/bsd-sysv-commands/common.c Mon Mar 02 22:33:16 2009 -0800 +++ b/usr/src/cmd/print/bsd-sysv-commands/common.c Mon Mar 02 23:02:05 2009 -0800 @@ -20,15 +20,13 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ /* $Id: common.c 162 2006-05-08 14:17:44Z njacobs $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -159,11 +157,11 @@ char *reason = ""; (void) papiAttributeListGetInteger(list, NULL, - "printer-state", &state); + "printer-state", &state); (void) papiAttributeListGetString(list, NULL, - "printer-state-reasons", &reason); + "printer-state-reasons", &reason); (void) papiAttributeListGetString(list, NULL, - "printer-name", &name); + "printer-name", &name); if ((state != 0x03) || (num_jobs != 0)) { fprintf(fp, "%s: %s", name, state_string(state)); @@ -192,42 +190,42 @@ char *suffix = "k"; (void) papiAttributeListGetInteger(list, NULL, - "job-id", &id); + "job-id", &id); (void) papiAttributeListGetInteger(list, NULL, - "job-id-requested", &id); + "job-id-requested", &id); (void) papiAttributeListGetString(list, NULL, - "job-originating-user-name", &user); + "job-originating-user-name", &user); (void) papiAttributeListGetString(list, NULL, - "job-originating-host-name", &host); + "job-originating-host-name", &host); /* if we are looking and it doesn't match, return early */ if ((ac > 0) && (match_job(id, user, ac, av) < 0)) return; (void) papiAttributeListGetInteger(list, NULL, - "copies", &copies); + "copies", &copies); (void) papiAttributeListGetInteger(list, NULL, - "number-of-intervening-jobs", &rank); + "number-of-intervening-jobs", &rank); if (papiAttributeListGetInteger(list, NULL, "job-octets", &size) - == PAPI_OK) + == PAPI_OK) suffix = "bytes"; else (void) papiAttributeListGetInteger(list, NULL, - "job-k-octets", &size); + "job-k-octets", &size); (void) papiAttributeListGetString(list, NULL, - "job-name", &name); + "job-name", &name); size *= copies; if (fmt == 3) { fprintf(fp, gettext("%s\t%-8.8s %d\t%-32.32s%d %s\n"), - rank_string(++rank), user, id, name, size, suffix); + rank_string(++rank), user, id, name, size, suffix); } else fprintf(fp, gettext( - "\n%s: %s\t\t\t\t[job %d %s]\n\t%-32.32s\t%d %s\n"), - user, rank_string(++rank), id, host, name, size, - suffix); + "\n%s: %s\t\t\t\t[job %d %s]\n\t%-32.32s\t%d %s\n"), + user, rank_string(++rank), id, host, name, size, + suffix); } /* @@ -245,11 +243,11 @@ char *mesg = gettext("cancelled"); papiAttributeListGetInteger(list, NULL, - "job-id", &id); + "job-id", &id); papiAttributeListGetInteger(list, NULL, - "job-id-requested", &rid); + "job-id-requested", &rid); papiAttributeListGetString(list, NULL, - "job-originating-user-name", &user); + "job-originating-user-name", &user); /* if we are looking and it doesn't match, return early */ if ((ac > 0) && (match_job(id, user, ac, av) < 0) && @@ -260,7 +258,10 @@ if (status != PAPI_OK) mesg = papiStatusString(status); - fprintf(fp, "%s-%d: %s\n", printer, id, mesg); + if (id != 0) + fprintf(fp, "%s-%d: %s\n", printer, id, mesg); + else + fprintf(fp, "%s-%d: %s\n", printer, rid, mesg); } int @@ -281,17 +282,17 @@ status = papiPrinterQuery(svc, dest, pattrs, NULL, &p); if (status != PAPI_OK) { fprintf(fp, gettext( - "Failed to query service for state of %s: %s\n"), - dest, verbose_papi_message(svc, status)); + "Failed to query service for state of %s: %s\n"), + dest, verbose_papi_message(svc, status)); return (-1); } status = papiPrinterListJobs(svc, dest, jattrs, PAPI_LIST_JOBS_ALL, - 0, &jobs); + 0, &jobs); if (status != PAPI_OK) { fprintf(fp, gettext( - "Failed to query service for jobs on %s: %s\n"), - dest, verbose_papi_message(svc, status)); + "Failed to query service for jobs on %s: %s\n"), + dest, verbose_papi_message(svc, status)); return (-1); } if (jobs != NULL) { @@ -325,11 +326,11 @@ "job-id-requested", NULL }; status = papiPrinterListJobs(svc, dest, jattrs, PAPI_LIST_JOBS_ALL, - 0, &jobs); + 0, &jobs); if (status != PAPI_OK) { fprintf(fp, gettext("Failed to query service for %s: %s\n"), - dest, verbose_papi_message(svc, status)); + dest, verbose_papi_message(svc, status)); return (-1); } @@ -381,7 +382,7 @@ strsplit(char *string, const char *seperators) { char *list[BUFSIZ], - **result; + **result; int length = 0; if ((string == NULL) || (seperators == NULL)) @@ -389,8 +390,8 @@ (void) memset(list, 0, sizeof (list)); for (list[length] = strtok(string, seperators); - (list[length] != NULL) && (length < (BUFSIZ - 2)); - list[length] = strtok(NULL, seperators)) + (list[length] != NULL) && (length < (BUFSIZ - 2)); + list[length] = strtok(NULL, seperators)) length++; if ((result = (char **)calloc(length+1, sizeof (char *))) != NULL) @@ -472,16 +473,16 @@ status = papiPrinterQuery(svc, "_all", list, NULL, &printer); if ((status == PAPI_OK) && (printer != NULL)) { papi_attribute_t **attributes = - papiPrinterGetAttributeList(printer); + papiPrinterGetAttributeList(printer); if (attributes != NULL) { void *iter = NULL; char *value = NULL; for (status = papiAttributeListGetString(attributes, - &iter, "member-names", &value); - status == PAPI_OK; - status = papiAttributeListGetString(attributes, - &iter, NULL, &value)) + &iter, "member-names", &value); + status == PAPI_OK; + status = papiAttributeListGetString(attributes, + &iter, NULL, &value)) list_append(&result, strdup(value)); } papiPrinterFree(printer); @@ -504,11 +505,11 @@ for (i = 0; printers[i] != NULL; i++) { papi_attribute_t **attributes = - papiPrinterGetAttributeList(printers[i]); + papiPrinterGetAttributeList(printers[i]); char *name = NULL; (void) papiAttributeListGetString(attributes, NULL, - "printer-name", &name); + "printer-name", &name); if ((name != NULL) && (strcmp(name, "_default") != 0)) list_append(&result, strdup(name)); } @@ -571,7 +572,7 @@ /* build the prompt string */ snprintf(prompt, sizeof (prompt), - gettext("passphrase for %s to access %s: "), user, svc_name); + gettext("passphrase for %s to access %s: "), user, svc_name); /* ask for the passphrase */ if ((passphrase = getpassphrase(prompt)) != NULL)
--- a/usr/src/lib/print/libpapi-lpd/common/lpd-cancel.c Mon Mar 02 22:33:16 2009 -0800 +++ b/usr/src/lib/print/libpapi-lpd/common/lpd-cancel.c Mon Mar 02 23:02:05 2009 -0800 @@ -20,15 +20,13 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ /* $Id: lpd-cancel.c 155 2006-04-26 02:34:54Z ktou $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - #define __EXTENSIONS__ /* for strtok_r() */ #include <stdio.h> #include <stdlib.h> @@ -58,10 +56,11 @@ if (fdgets(buf, sizeof (buf), fd) != NULL) { if (buf[0] == '\0') status = PAPI_NOT_FOUND; - else if (strstr(buf, "permission denied") != NULL) + else if ((strstr(buf, "permission denied") != NULL) || + (strstr(buf, "not-authorized") != NULL)) status = PAPI_NOT_AUTHORIZED; else if ((strstr(buf, "cancelled") != NULL) || - (strstr(buf, "removed") != NULL)) + (strstr(buf, "removed") != NULL)) status = PAPI_OK; } else status = PAPI_NOT_FOUND; @@ -100,15 +99,15 @@ ptr = strtok_r(buf, ":", &iter); papiAttributeListAddString(&attributes, PAPI_ATTR_EXCL, - "job-name", ptr); + "job-name", ptr); id = atoi(ptr); papiAttributeListAddInteger(&attributes, PAPI_ATTR_EXCL, - "job-id", id); + "job-id", id); papiAttributeListAddString(&attributes, PAPI_ATTR_EXCL, - "job-printer", queue); + "job-printer", queue); if ((job = (job_t *)calloc(1, (sizeof (*job)))) - != NULL) { + != NULL) { job->attributes = attributes; list_append(jobs, job); } else