summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print/bsd-sysv-commands
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands')
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/Makefile84
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/accept.c104
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/cancel.c127
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.c491
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.h66
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/disable.c149
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/enable.c104
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/in.lpd.c242
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lp.c328
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpc.c540
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpmove.c165
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpq.c134
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpr.c270
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lprm.c101
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpstat.c1015
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/reject.c108
16 files changed, 4028 insertions, 0 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/Makefile b/usr/src/cmd/print/bsd-sysv-commands/Makefile
new file mode 100644
index 0000000000..ee16f07879
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/Makefile
@@ -0,0 +1,84 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+UCBPROGS = lpr lpq lprm lpc
+BINPROGS = lp lpstat cancel enable disable $(UCBPROGS)
+
+SBINPROGS = accept reject lpmove
+
+
+OBJS = $(BINPROGS:=.o) $(SBINPROGS:=.o) common.o
+
+ROOTBINPROGS = $(BINPROGS:%=$(ROOTBIN)/%)
+ROOTUSRSBINPROGS = $(SBINPROGS:%=$(ROOTUSRSBIN)/%)
+
+
+FILEMODE = 0555
+OWNER = root
+
+include ../../Makefile.cmd
+
+CFLAGS += $(CCVERBOSE)
+CPPFLAGS += -I.
+CPPFLAGS += -I../../../lib/print/libpapi-common/common
+LDLIBS += -lpapi -lc
+
+# each program needs common.o as well
+$(BINPROGS) $(SBINPROGS): $(BINPROGS:%=%.c) $(SBINPROGS:%=%.c) common.o
+ $(LINK.c) -o $@ $@.c common.o $(LDLIBS)
+ $(POST_PROCESS)
+
+# ucb links (lptest is handled in usr/src/cmd/lp/cmd/Makefile)
+ROOTUSRUCB = $(ROOT)/usr/ucb
+ROOTUCBSYMLINKS = $(UCBPROGS:%=$(ROOTUSRUCB)/%)
+$(ROOTUSRUCB)/%: $(ROOTUSRUCB) %
+
+$(ROOTUCBSYMLINKS):
+ $(RM) $@; $(SYMLINK) ../bin/$(@F) $@
+
+# usr/lib links
+ROOTUSRLIBSYMLINKS = $(SBINPROGS:%=$(ROOTLIB)/%)
+$(ROOTLIB)/%: $(ROOTLIB) %
+
+$(ROOTUSRLIBSYMLINKS):
+ $(RM) $@; $(SYMLINK) ../sbin/$(@F) $@
+
+.KEEP_STATE:
+
+all: $(BINPROGS) $(SBINPROGS)
+
+install: $(BINPROGS) $(SBINPROGS) $(ROOTBINPROGS) $(ROOTUSRSBINPROGS) \
+ $(ROOTUCBSYMLINKS) $(ROOTUSRLIBSYMLINKS)
+
+clean:
+ $(RM) $(OBJS)
+
+CLOBBERFILES += $(BINPROGS) $(SBINPROGS)
+
+lint:
+
+include ../../Makefile.targ
diff --git a/usr/src/cmd/print/bsd-sysv-commands/accept.c b/usr/src/cmd/print/bsd-sysv-commands/accept.c
new file mode 100644
index 0000000000..c20f9344de
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/accept.c
@@ -0,0 +1,104 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: accept.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s destination ...\n"),
+ name);
+ exit(1);
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int exit_status = 0;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "E")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_ALWAYS;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if (ac == optind)
+ usage(av[0]);
+
+ for (c = optind; c < ac; c++) {
+ char *printer = av[c];
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ status = papiPrinterResume(svc, printer);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("accept: %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ papiServiceDestroy(svc);
+ }
+
+ return (exit_status);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/cancel.c b/usr/src/cmd/print/bsd-sysv-commands/cancel.c
new file mode 100644
index 0000000000..c95279ad5e
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/cancel.c
@@ -0,0 +1,127 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: cancel.c 147 2006-04-25 16:51:06Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout, "Usage: %s [-u user] (printer|request-id ...)\n", name);
+ exit(1);
+}
+
+int
+main(int ac, char *av[])
+{
+ int exit_code = 0;
+ char *user = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "Eu:")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ case 'u':
+ user = optarg;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ for (c = optind; c < ac; c++) {
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_job_t *jobs = NULL;
+ char *printer = NULL;
+ int32_t id = -1;
+
+ (void) get_printer_id(av[c], &printer, &id);
+
+ status = papiServiceCreate(&svc, printer, user, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ exit(1);
+ }
+
+#define OUT ((status == PAPI_OK) ? stdout : stderr)
+
+ if (id != -1) { /* it's a job */
+ char *mesg = "cancelled";
+
+ status = papiJobCancel(svc, printer, id);
+ if (status != PAPI_OK) {
+ mesg = verbose_papi_message(svc, status);
+ exit_code = 1;
+ }
+ fprintf(OUT, "%s-%d: %s\n", printer, id, mesg);
+ } else { /* it's a printer */
+ status = papiPrinterPurgeJobs(svc, printer, &jobs);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("PurgeJobs %s: %s\n"),
+ printer,
+ verbose_papi_message(svc, status));
+ exit_code = 1;
+ }
+
+ while ((jobs != NULL) && (*jobs != NULL))
+ fprintf(OUT, "%s-%d: %s\n", printer,
+ papiJobGetId(*jobs++), "cancelled");
+
+ papiJobListFree(jobs);
+ }
+
+ papiServiceDestroy(svc);
+ }
+
+ return (exit_code);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.c b/usr/src/cmd/print/bsd-sysv-commands/common.c
new file mode 100644
index 0000000000..5d70752563
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.c
@@ -0,0 +1,491 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 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>
+#include <alloca.h>
+#include <string.h>
+#include <libintl.h>
+#include <ctype.h>
+#include <pwd.h>
+#include <papi.h>
+#include "common.h"
+
+#ifndef HAVE_GETPASSPHRASE /* some systems don't have getpassphrase() */
+#define getpassphrase getpass
+#endif
+
+/* give the most verbose error message to the caller */
+char *
+verbose_papi_message(papi_service_t svc, papi_status_t status)
+{
+ char *mesg;
+
+ mesg = papiServiceGetStatusMessage(svc);
+
+ if (mesg == NULL)
+ mesg = papiStatusString(status);
+
+ return (mesg);
+}
+
+static int
+match_job(int id, char *user, int ac, char *av[])
+{
+ int i;
+
+ for (i = 0; i < ac; i++)
+ if (strcmp("-", av[i]) == 0)
+ return (0); /* "current" user match */
+ else if ((isdigit(av[i][0]) != 0) && (id == atoi(av[i])))
+ return (0); /* job-id match */
+ else if (strcmp(user, av[i]) == 0)
+ return (0); /* user match */
+
+ return (-1);
+}
+
+/*
+ * to support job/printer status
+ */
+static char *
+state_string(int state)
+{
+ switch (state) {
+ case 3:
+ return (gettext("idle"));
+ case 4:
+ return (gettext("processing"));
+ case 5:
+ return (gettext("stopped"));
+ default:
+ return (gettext("unknown"));
+ }
+}
+
+static char *_rank_suffixes[] = {
+ "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
+};
+
+static char *
+rank_string(const int rank)
+{
+ static char buf[12];
+
+ if (rank < 0)
+ snprintf(buf, sizeof (buf), gettext("invalid"));
+ else if (rank == 0)
+ snprintf(buf, sizeof (buf), gettext("active"));
+ else if ((rank > 10) && (rank < 14))
+ sprintf(buf, "%dth", rank);
+ else
+ sprintf(buf, "%d%s", rank, _rank_suffixes[rank % 10]);
+
+ return (buf);
+}
+
+static void
+printer_state_line(FILE *fp, papi_printer_t p, int num_jobs, char *name)
+{
+ papi_attribute_t **list = papiPrinterGetAttributeList(p);
+ int state = 0;
+ char *reason = "";
+
+ (void) papiAttributeListGetInteger(list, NULL,
+ "printer-state", &state);
+ (void) papiAttributeListGetString(list, NULL,
+ "printer-state-reasons", &reason);
+ (void) papiAttributeListGetString(list, NULL,
+ "printer-name", &name);
+
+ if ((state != 0x03) || (num_jobs != 0)) {
+ fprintf(fp, "%s: %s", name, state_string(state));
+ if (state == 0x05) /* stopped */
+ fprintf(fp, ": %s\n", reason);
+ else
+ fprintf(fp, "\n");
+ } else
+ fprintf(fp, "no entries\n");
+}
+
+static void
+print_header(FILE *fp)
+{
+ fprintf(fp, gettext("Rank\tOwner\t Job\tFile(s)\t\t\t\tTotal Size\n"));
+}
+
+static void
+print_job_line(FILE *fp, int count, papi_job_t job, int fmt, int ac, char *av[])
+{
+ papi_attribute_t **list = papiJobGetAttributeList(job);
+ int copies = 1, id = 0, rank = count, size = 0;
+ char *name = "print job";
+ char *user = "nobody";
+ char *host = "localhost";
+ char *suffix = "k";
+
+ (void) papiAttributeListGetInteger(list, NULL,
+ "job-id", &id);
+ (void) papiAttributeListGetString(list, NULL,
+ "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))
+ return;
+
+ (void) papiAttributeListGetInteger(list, NULL,
+ "copies", &copies);
+ (void) papiAttributeListGetInteger(list, NULL,
+ "number-of-intervening-jobs", &rank);
+
+ if (papiAttributeListGetInteger(list, NULL, "job-octets", &size)
+ == PAPI_OK)
+ suffix = "bytes";
+ else
+ (void) papiAttributeListGetInteger(list, NULL,
+ "job-k-octets", &size);
+ (void) papiAttributeListGetString(list, NULL,
+ "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);
+ } 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);
+}
+
+/*
+ * to support job cancelation
+ */
+static void
+cancel_job(papi_service_t svc, FILE *fp, char *printer, papi_job_t job,
+ int ac, char *av[])
+{
+ papi_status_t status;
+ papi_attribute_t **list = papiJobGetAttributeList(job);
+ int id = 0;
+ char *user = "";
+ char *mesg = gettext("cancelled");
+
+ papiAttributeListGetInteger(list, NULL,
+ "job-id", &id);
+ papiAttributeListGetString(list, NULL,
+ "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))
+ return;
+
+ status = papiJobCancel(svc, printer, id);
+ if (status != PAPI_OK)
+ mesg = papiStatusString(status);
+
+ fprintf(fp, "%s-%d: %s\n", printer, id, mesg);
+}
+
+int
+berkeley_queue_report(papi_service_t svc, FILE *fp, char *dest, int fmt,
+ int ac, char *av[])
+{
+ papi_status_t status;
+ papi_printer_t p = NULL;
+ papi_job_t *jobs = NULL;
+ char *pattrs[] = { "printer-name", "printer-state",
+ "printer-state-reasons", NULL };
+ char *jattrs[] = {
+ "job-name", "job-octets", "job-k-octets",
+ "job-originating-user-name", "job-id",
+ "number-of-intervening-jobs", NULL };
+ int num_jobs = 0;
+
+ 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));
+ return (-1);
+ }
+
+ status = papiPrinterListJobs(svc, dest, jattrs, PAPI_LIST_JOBS_ALL,
+ 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));
+ return (-1);
+ }
+ if (jobs != NULL) {
+ while (jobs[num_jobs] != NULL)
+ num_jobs++;
+ }
+
+ printer_state_line(fp, p, num_jobs, dest);
+ if (num_jobs > 0) {
+ int i;
+
+ if (fmt == 3)
+ print_header(fp);
+ for (i = 0; jobs[i] != NULL; i++)
+ print_job_line(fp, i, jobs[i], fmt, ac, av);
+ }
+
+ papiPrinterFree(p);
+ papiJobListFree(jobs);
+
+ return (num_jobs);
+}
+
+int
+berkeley_cancel_request(papi_service_t svc, FILE *fp, char *dest,
+ int ac, char *av[])
+{
+ papi_status_t status;
+ papi_job_t *jobs = NULL;
+ char *jattrs[] = { "job-originating-user-name", "job-id", NULL };
+
+ status = papiPrinterListJobs(svc, dest, jattrs, PAPI_LIST_JOBS_ALL,
+ 0, &jobs);
+
+ if (status != PAPI_OK) {
+ fprintf(fp, gettext("Failed to query service for %s: %s\n"),
+ dest, verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ /* cancel the job(s) */
+ if (jobs != NULL) {
+ int i;
+
+ for (i = 0; jobs[i] != NULL; i++)
+ cancel_job(svc, fp, dest, jobs[i], ac, av);
+ }
+
+ papiJobListFree(jobs);
+
+ return (0);
+}
+
+int
+get_printer_id(char *name, char **printer, int *id)
+{
+ int result = -1;
+
+ if (name != NULL) {
+ char *p = strrchr(name, '-');
+
+ *printer = name;
+ if (p != NULL) {
+ char *s = NULL;
+
+ *id = strtol(p + 1, &s, 10);
+ if (s[0] != '\0')
+ *id = -1;
+ else
+ *p = '\0';
+ result = 0;
+ } else
+ *id = -1;
+ }
+
+ return (result);
+}
+
+/*
+ * strsplit() splits a string into a NULL terminated array of substrings
+ * determined by a seperator. The original string is modified, and newly
+ * allocated space is only returned for the array itself. If more than
+ * 1024 substrings exist, they will be ignored.
+ */
+char **
+strsplit(char *string, const char *seperators)
+{
+ char *list[BUFSIZ],
+ **result;
+ int length = 0;
+
+ if ((string == NULL) || (seperators == NULL))
+ return (NULL);
+
+ (void) memset(list, 0, sizeof (list));
+ for (list[length] = strtok(string, seperators);
+ (list[length] != NULL) && (length < (BUFSIZ - 2));
+ list[length] = strtok(NULL, seperators))
+ length++;
+
+ if ((result = (char **)calloc(length+1, sizeof (char *))) != NULL)
+ (void) memcpy(result, list, length * sizeof (char *));
+
+ return (result);
+}
+
+papi_status_t
+jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list,
+ papi_job_t *job)
+{
+ papi_status_t status;
+ papi_stream_t stream = NULL;
+ int rc;
+ char buf[BUFSIZ];
+
+ status = papiJobStreamOpen(svc, printer, list, NULL, &stream);
+ while ((status == PAPI_OK) && ((rc = read(0, buf, sizeof (buf))) > 0))
+ status = papiJobStreamWrite(svc, stream, buf, rc);
+
+ if (status == PAPI_OK)
+ status = papiJobStreamClose(svc, stream, job);
+
+ return (status);
+}
+
+static char **
+all_list(papi_service_t svc)
+{
+ papi_status_t status;
+ papi_printer_t printer = NULL;
+ char *list[] = { "member-names", NULL };
+ char **result = NULL;
+
+ status = papiPrinterQuery(svc, "_all", list, NULL, &printer);
+ if ((status == PAPI_OK) && (printer != NULL)) {
+ papi_attribute_t **attributes =
+ 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))
+ list_append(&result, strdup(value));
+ }
+ papiPrinterFree(printer);
+ }
+
+ return (result);
+}
+
+static char **
+printers_list(papi_service_t svc)
+{
+ papi_status_t status;
+ papi_printer_t *printers = NULL;
+ char *keys[] = { "printer-name", NULL };
+ char **result = NULL;
+
+ status = papiPrintersList(svc, keys, NULL, &printers);
+ if ((status == PAPI_OK) && (printers != NULL)) {
+ int i;
+
+ for (i = 0; printers[i] != NULL; i++) {
+ papi_attribute_t **attributes =
+ papiPrinterGetAttributeList(printers[i]);
+ char *name = NULL;
+
+ (void) papiAttributeListGetString(attributes, NULL,
+ "printer-name", &name);
+ if ((name != NULL) && (strcmp(name, "_default") != 0))
+ list_append(&result, strdup(name));
+ }
+ papiPrinterListFree(printers);
+ }
+
+ return (result);
+}
+
+char **
+interest_list(papi_service_t svc)
+{
+ static char been_here;
+ static char **result;
+
+ if (been_here == 0) { /* only do this once */
+ been_here = 1;
+
+ if ((result = all_list(svc)) == NULL)
+ result = printers_list(svc);
+ }
+
+ return (result);
+}
+
+char *
+localhostname()
+{
+ static char *result;
+
+ if (result == NULL) {
+ static char buf[256];
+
+ if (gethostname(buf, sizeof (buf)) == 0)
+ result = buf;
+ }
+
+ return (result);
+}
+
+int
+cli_auth_callback(papi_service_t svc, void *app_data)
+{
+ char prompt[BUFSIZ];
+ char *user, *svc_name, *passphrase;
+
+ /* get the name of the service we are contacting */
+ if ((svc_name = papiServiceGetServiceName(svc)) == NULL)
+ return (-1);
+
+ /* find our who we are supposed to be */
+ if ((user = papiServiceGetUserName(svc)) == NULL) {
+ struct passwd *pw;
+
+ if ((pw = getpwuid(getuid())) != NULL)
+ user = pw->pw_name;
+ else
+ user = "nobody";
+ }
+
+ /* build the prompt string */
+ snprintf(prompt, sizeof (prompt),
+ gettext("passphrase for %s to access %s: "), user, svc_name);
+
+ /* ask for the passphrase */
+ if ((passphrase = getpassphrase(prompt)) != NULL)
+ papiServiceSetPassword(svc, passphrase);
+
+ return (0);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.h b/usr/src/cmd/print/bsd-sysv-commands/common.h
new file mode 100644
index 0000000000..92a2b5b66c
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.h
@@ -0,0 +1,66 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+#ifndef _BSD_SYSV_COMMON_H
+#define _BSD_SYSV_COMMON_H
+
+/* $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>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char **strsplit(char *string, const char *seperators);
+extern char *verbose_papi_message(papi_service_t svc, papi_status_t status);
+
+extern int berkeley_cancel_request(papi_service_t svc, FILE *fp, char *dest,
+ int ac, char *av[]);
+
+extern int get_printer_id(char *name, char **printer, int *id);
+
+extern int berkeley_queue_report(papi_service_t svc, FILE *fp, char *dest,
+ int fmt, int ac, char *av[]);
+
+extern papi_status_t jobSubmitSTDIN(papi_service_t svc, char *printer,
+ papi_attribute_t **list, papi_job_t *job);
+
+extern char **interest_list(papi_service_t svc);
+extern char *localhostname();
+
+extern int cli_auth_callback(papi_service_t svc, void *app_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BSD_SYSV_COMMON_H */
diff --git a/usr/src/cmd/print/bsd-sysv-commands/disable.c b/usr/src/cmd/print/bsd-sysv-commands/disable.c
new file mode 100644
index 0000000000..8b813b6d56
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/disable.c
@@ -0,0 +1,149 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: disable.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s [-c] [-W] [-r reason] destination ...\n"),
+ name);
+ exit(1);
+}
+
+static void
+cancel_active_job(papi_service_t svc, char *dest)
+{
+ papi_status_t status;
+ papi_job_t *j = NULL;
+ char *req_attrs[] = { "job-state", "job-id", NULL };
+
+ status = papiPrinterListJobs(svc, dest, req_attrs, 0, 0, &j);
+ if ((status == PAPI_OK) && (j != NULL)) {
+ int i;
+
+ for (i = 0; j[i] != NULL; j++) {
+ papi_attribute_t **a = papiJobGetAttributeList(j[i]);
+ int state = 0;
+
+ if (a == NULL)
+ continue;
+
+ (void) papiAttributeListGetInteger(a, NULL,
+ "job-state", &state);
+ if (state == 0x05) { /* processing */
+ int32_t id = papiJobGetId(j[i]);
+
+ (void) papiJobCancel(svc, dest, id);
+ }
+ }
+ papiJobListFree(j);
+ }
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int exit_status = 0;
+ int cancel = 0;
+ int pending = 0; /* not implemented */
+ char *reason = NULL;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "EcWr:")) != EOF)
+ switch (c) {
+ case 'c': /* cancel active job first */
+ cancel = 1;
+ break;
+ case 'W': /* wait for active request, not implemented */
+ pending = 1;
+ break;
+ case 'r': /* reason */
+ reason = optarg;
+ break;
+ case 'E':
+ encryption = PAPI_ENCRYPT_NEVER;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if (ac <= optind)
+ usage(av[0]);
+
+ while (optind < ac) {
+ char *printer = av[optind++];
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ status = papiPrinterDisable(svc, printer, reason);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("disable: %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ if (cancel != 0)
+ cancel_active_job(svc, printer);
+
+ papiServiceDestroy(svc);
+ }
+
+ return (exit_status);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/enable.c b/usr/src/cmd/print/bsd-sysv-commands/enable.c
new file mode 100644
index 0000000000..1bf7a0ccce
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/enable.c
@@ -0,0 +1,104 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: enable.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s destination ...\n"),
+ name);
+ exit(1);
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int exit_status = 0;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "E")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_ALWAYS;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if (ac == optind)
+ usage(av[0]);
+
+ for (c = optind; c < ac; c++) {
+ char *printer = av[c];
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ status = papiPrinterEnable(svc, printer);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("enable: %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ papiServiceDestroy(svc);
+ }
+
+ return (exit_status);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c
new file mode 100644
index 0000000000..465189daf1
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c
@@ -0,0 +1,242 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: in.lpd.c 170 2006-05-20 05:58:49Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <syslog.h>
+#include <libintl.h>
+
+#include <papi.h>
+#include "common.h"
+
+#define ACK(fp) { (void) fputc('\0', fp); (void) fflush(fp); }
+#define NACK(fp) { (void) fputc('\1', fp); (void) fflush(fp); }
+
+/*
+ * This file contains the front-end of the BSD Print Protocol adaptor. This
+ * code assumes a BSD Socket interface to the networking side.
+ */
+
+void
+fatal(FILE *fp, char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsyslog(LOG_DEBUG, fmt, ap);
+ vfprintf(fp, fmt, ap);
+ va_end(ap);
+}
+
+static void
+cleanup(char **files)
+{
+ if (files != NULL) {
+ int i;
+
+ for (i = 0; files[i] != NULL; i++)
+ unlink(files[i]);
+ }
+}
+
+static void
+berkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp)
+{
+ char line[BUFSIZ];
+ char **files = NULL; /* the job data files */
+
+ /* This should actually implement transfer job from RFC-1179 */
+ ACK(ofp);
+
+ while (fgets(line, sizeof (line), ifp) != NULL) {
+ switch (line[0]) {
+ case 0x01: /* Abort */
+ cleanup(files);
+ break;
+ case 0x02: /* Receive control file */
+
+ break;
+ case 0x03: { /* Receive data file */
+ char file[] = "lpdXXXXXX";
+ int fd;
+
+ fd = mkstemp(file);
+
+ list_append(&files, strdup(file));
+ }
+ break;
+ default:
+ fatal(ofp, "protocol screwup");
+ cleanup(files);
+ break;
+ }
+ }
+
+ cleanup(files);
+}
+
+static void
+berkeley_transfer_files(papi_service_t svc, FILE *ifp, FILE *ofp,
+ char *printer)
+{
+ papi_status_t status;
+ papi_printer_t p = NULL;
+ char *keys[] = { "printer-is-accepting", NULL };
+
+ status = papiPrinterQuery(svc, printer, keys, NULL, &p);
+ if ((status == PAPI_OK) && (p != NULL)) {
+ papi_attribute_t **attrs = papiPrinterGetAttributeList(p);
+ char accepting = PAPI_FALSE;
+
+ papiAttributeListGetBoolean(attrs, NULL,
+ "printer-is-accepting", &accepting);
+
+ if (accepting == PAPI_TRUE)
+ berkeley_receive_files(svc, ifp, ofp);
+ else
+ NACK(ofp);
+
+ papiPrinterFree(p);
+ } else
+ NACK(ofp);
+}
+
+/*
+ * This is the entry point for this program. The program takes the
+ * following options:
+ * (none)
+ */
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ FILE *ifp = stdin,
+ *ofp = stdout;
+ int c;
+ char buf[BUFSIZ],
+ **args,
+ *printer;
+
+ openlog("bsd-gw", LOG_PID, LOG_LPR);
+
+ while ((c = getopt(ac, av, "d")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_ALWAYS;
+ break;
+ case 'd':
+ default:
+ ;
+ }
+
+ if (fgets(buf, sizeof (buf), ifp) == NULL) {
+ if (feof(ifp) == 0)
+ syslog(LOG_ERR, "Error reading from connection: %s",
+ strerror(errno));
+ exit(1);
+ }
+
+ if ((buf[0] < 1) || (buf[0] > 5)) {
+ fatal(ofp, "Invalid protocol request (%d): %c%s\n",
+ buf[0], buf[0], buf);
+ exit(1);
+ }
+
+ args = strsplit(&buf[1], "\t\n ");
+ printer = *args++;
+
+ if (printer == NULL) {
+ fatal(ofp, "Can't determine requested printer");
+ exit(1);
+ }
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL, NULL,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fatal(ofp, "Failed to contact service for %s: %s\n", printer,
+ verbose_papi_message(svc, status));
+ exit(1);
+ }
+
+#ifdef HAVE_IS_SYSTEM_LABELED
+ if (is_system_labeled()) {
+ int fd = fileno(ifp);
+
+ (void) papiServiceSetPeer(svc, fd);
+ }
+#endif
+
+ switch (buf[0]) {
+ case '\1': /* restart printer */
+ ACK(ofp); /* there is no equivalent */
+ break;
+ case '\2': /* transfer job(s) */
+ berkeley_transfer_files(svc, ifp, ofp, printer);
+ break;
+ case '\3': /* show queue (short) */
+ case '\4': { /* show queue (long) */
+ int count;
+
+ for (count = 0; args[count] != 0; count++);
+
+ berkeley_queue_report(svc, ofp, printer, buf[0], count, args);
+ }
+ break;
+ case '\5': { /* cancel job(s) */
+ char *requestor = *args++;
+ int count;
+
+ status = papiServiceSetUserName(svc, requestor);
+ for (count = 0; args[count] != 0; count++);
+
+ berkeley_cancel_request(svc, ofp, printer, count, args);
+ }
+ break;
+ default:
+ fatal(ofp, "unsupported protocol request (%c), %s",
+ buf[0], &buf[1]);
+ }
+
+ (void) fflush(ofp);
+
+ syslog(LOG_DEBUG, "protocol request(%d) for %s completed: %s",
+ buf[0], printer, papiStatusString(status));
+ syslog(LOG_DEBUG, "detail: %s", verbose_papi_message(svc, status));
+
+ papiServiceDestroy(svc);
+
+ return (0);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lp.c b/usr/src/cmd/print/bsd-sysv-commands/lp.c
new file mode 100644
index 0000000000..702f1b8d00
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lp.c
@@ -0,0 +1,328 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lp.c 169 2006-05-20 05:58:14Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+#ifdef HAVE_LIBMAGIC /* for mimetype auto-detection */
+#include <magic.h>
+#endif /* HAVE_LIBMAGIC */
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s [-c] [-m] [-p] [-s] [-w] [-d destination] "
+ "[-f form-name] [-H special-handling] [-n number] "
+ "[-o option] [-P page-list] [-q priority-level] "
+ "[-S character-set | print-wheel] [-t title] [-v] "
+ "[-T content-type [-r]] [-y mode-list] [file...]\n"),
+ name);
+ exit(1);
+}
+
+static struct {
+ char *mime_type;
+ char *lp_type;
+} type_map[] = {
+ { "text/plain", "simple" },
+ { "application/octet-stream", "raw" },
+ { "application/octet-stream", "any" },
+ { "application/postscript", "postscript" },
+ { "application/postscript", "ps" },
+ { "application/x-cif", "cif" },
+ { "application/x-dvi", "dvi" },
+ { "application/x-plot", "plot" },
+ { "application/x-ditroff", "troff" },
+ { "application/x-troff", "otroff" },
+ { "application/x-pr", "pr" },
+ { "application/x-fortran", "fortran" },
+ { "application/x-raster", "raster" },
+ { NULL, NULL}
+};
+
+static char *
+lp_type_to_mime_type(char *lp_type)
+{
+ int i;
+
+ if (lp_type == NULL)
+ return ("application/octet-stream");
+
+ for (i = 0; type_map[i].lp_type != NULL; i++)
+ if (strcasecmp(type_map[i].lp_type, lp_type) == 0)
+ return (type_map[i].mime_type);
+
+ return (lp_type);
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_attribute_t **list = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ papi_job_t job = NULL;
+ char *printer = NULL;
+ char b = PAPI_TRUE;
+ int copy = 0;
+ int silent = 0;
+ int dump = 0;
+ int validate = 0;
+ int modify = -1;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "DEH:P:S:T:cd:f:i:mn:o:pq:rst:Vwy:")) != EOF)
+ switch (c) {
+ case 'H': /* handling */
+ if (strcasecmp(optarg, "hold") == 0)
+ papiAttributeListAddString(&list,
+ PAPI_ATTR_EXCL,
+ "job-hold-until", "indefinite");
+ else if (strcasecmp(optarg, "release") == 0)
+ papiAttributeListAddString(&list,
+ PAPI_ATTR_EXCL,
+ "job-hold-until", "no-hold");
+ else if (strcasecmp(optarg, "immediate") == 0)
+ papiAttributeListAddInteger(&list,
+ PAPI_ATTR_EXCL,
+ "job-priority", 100);
+ else
+ papiAttributeListAddString(&list,
+ PAPI_ATTR_EXCL,
+ "job-hold-until", optarg);
+ break;
+ case 'P': /* page list */
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "page-ranges", optarg);
+ break;
+ case 'S': /* charset */
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "lp-charset", optarg);
+ break;
+ case 'T': /* type */
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format",
+ lp_type_to_mime_type(optarg));
+ break;
+ case 'D': /* dump */
+ dump = 1;
+ break;
+ case 'c': /* copy */
+ copy = 1;
+ break;
+ case 'd': /* destination */
+ printer = optarg;
+ break;
+ case 'f': /* form */
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "media", optarg);
+ break;
+ case 'i': /* modify job */
+ if ((get_printer_id(optarg, &printer, &modify) < 0) ||
+ (modify < 0)) {
+ fprintf(stderr,
+ gettext("invalid request id: %s\n"),
+ optarg);
+ exit(1);
+ }
+ break;
+ case 'm': /* mail when complete */
+ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-mail", 1);
+ break;
+ case 'n': /* copies */
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
+ "copies", atoi(optarg));
+ break;
+ case 'o': /* lp "options" */
+ papiAttributeListFromString(&list,
+ PAPI_ATTR_REPLACE, optarg);
+ break;
+ case 'p': /* Solaris - notification */
+ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-mail", 1);
+ break;
+ case 'q': { /* priority */
+ int i = atoi(optarg);
+
+ i = 99 * (39 - i) / 39 + 1;
+ if ((i < 1) || (i > 100)) {
+ fprintf(stderr, gettext(
+ "priority must be between 0 and 39.\n"));
+ exit(1);
+ }
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
+ "priority", i);
+ }
+ break;
+ case 'r': /* "raw" mode */
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format",
+ "application/octet-stream");
+ papiAttributeListAddString(&list, PAPI_ATTR_APPEND,
+ "stty", "raw");
+ break;
+ case 's': /* suppress message */
+ silent = 1;
+ break;
+ case 't': /* title */
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "job-name", optarg);
+ break;
+ case 'V': /* validate */
+ validate = 1;
+ break;
+ case 'w':
+ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-mail", 1);
+ break;
+ case 'y': /* lp "modes" */
+ papiAttributeListAddString(&list, PAPI_ATTR_APPEND,
+ "lp-modes", optarg);
+ break;
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ /* convert "banner", "nobanner" to "job-sheet" */
+ if (papiAttributeListGetBoolean(list, NULL, "banner", &b) == PAPI_OK) {
+ (void) papiAttributeListDelete(&list, "banner");
+ if (b == PAPI_FALSE)
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "job-sheets", "none");
+ }
+
+ if ((printer == NULL) &&
+ ((printer = getenv("PRINTER")) == NULL) &&
+ ((printer = getenv("LPDEST")) == NULL))
+ printer = DEFAULT_DEST;
+
+ if (modify == -1) {
+ char *document_format = "application/octet-stream";
+
+#ifdef MAGIC_MIME
+ if (optind != ac) {
+ /* get the mime type of the file data */
+ magic_t ms = NULL;
+
+ if ((ms = magic_open(MAGIC_MIME)) != NULL) {
+ document_format = magic_file(ms, av[optind]);
+ magic_close(ms);
+ }
+ }
+#endif
+
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1);
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", document_format);
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "job-sheets", "standard");
+ }
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ exit(1);
+ }
+
+ if (modify != -1)
+ status = papiJobModify(svc, printer, modify, list, &job);
+ else if (optind == ac) /* no file list, use stdin */
+ status = jobSubmitSTDIN(svc, printer, list, &job);
+ else if (validate == 1) /* validate the request can be processed */
+ status = papiJobValidate(svc, printer, list,
+ NULL, &av[optind], &job);
+ else if (copy == 0) /* reference the files in the job, default */
+ status = papiJobSubmitByReference(svc, printer, list,
+ NULL, &av[optind], &job);
+ else /* copy the files before return, -c */
+ status = papiJobSubmit(svc, printer, list,
+ NULL, &av[optind], &job);
+
+ papiAttributeListFree(list);
+
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("%s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ papiJobFree(job);
+ papiServiceDestroy(svc);
+ exit(1);
+ }
+
+ if (((silent == 0) || (dump != 0)) &&
+ ((list = papiJobGetAttributeList(job)) != NULL)) {
+ char *dest = "unknown";
+ int32_t id = 0;
+
+ papiAttributeListGetString(list, NULL, "printer-name", &dest);
+ papiAttributeListGetInteger(list, NULL, "job-id", &id);
+ printf(gettext("request id is %s-%d "), dest, id);
+ if (ac != optind)
+ printf("(%d file(s))\n", ac - optind);
+ else
+ printf("(standard input)\n");
+
+ if (dump != 0) {
+ printf("job attributes:\n");
+ papiAttributeListPrint(stdout, list, "\t");
+ printf("\n");
+ }
+ }
+
+ papiJobFree(job);
+ papiServiceDestroy(svc);
+
+ return (0);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpc.c b/usr/src/cmd/print/bsd-sysv-commands/lpc.c
new file mode 100644
index 0000000000..6d0aa6135d
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpc.c
@@ -0,0 +1,540 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lpc.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+typedef int (cmd_handler_t)(papi_service_t, char **);
+
+static papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+
+/* ARGSUSED0 */
+static int
+lpc_exit(papi_service_t svc, char **args)
+{
+ exit(0);
+ /* NOTREACHED */
+ return (0);
+}
+
+static int
+lpc_status(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ papi_printer_t p = NULL;
+ char *pattrs[] = { "printer-state", "printer-state-reasons",
+ "printer-is-accepting-jobs", NULL };
+ char *destination = args[1];
+
+ status = papiPrinterQuery(svc, destination, pattrs, NULL, &p);
+ if (status == PAPI_OK) {
+ papi_attribute_t **list = papiPrinterGetAttributeList(p);
+ char accepting = 0;
+ int32_t state = 0;
+
+ printf("%s:\n", destination);
+
+ (void) papiAttributeListGetBoolean(list, NULL,
+ "printer-is-accepting-jobs", &accepting);
+ printf(gettext("\tqueueing is %s\n"),
+ (accepting ? gettext("enabled") : gettext("disabled")));
+
+ (void) papiAttributeListGetInteger(list, NULL,
+ "printer-state", &state);
+ printf("\tprinting is %s\n",
+ ((state != 0x05) ? gettext("enabled") :
+ gettext("disabled")));
+
+ if (state != 0x03) { /* !idle */
+ papi_job_t *jobs = NULL;
+ int i = 0;
+
+ (void) papiPrinterListJobs(svc, destination, NULL,
+ PAPI_LIST_JOBS_ALL, 0, &jobs);
+ if (jobs != NULL) {
+ for (i = 0; jobs[i] != NULL; i++);
+ papiJobListFree(jobs);
+ }
+ printf(gettext("\t%d entries in spool area\n"), i);
+ } else
+ printf(gettext("\tno entries\n"));
+
+ if (state == 0x04)
+ printf(gettext("\tdaemon present\n"));
+
+ } else {
+ fprintf(stderr, "%s: %s\n", destination,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ papiPrinterFree(p);
+
+ return (0);
+}
+
+static int
+lpc_abort(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ char *destination = args[1];
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: abort (destination)\n"));
+ return (-1);
+ }
+
+ status = papiPrinterPause(svc, destination, "paused via lpc abort");
+ if (status == PAPI_OK) {
+ printf(gettext("%s: processing disabled after current job\n"),
+ destination);
+ } else {
+ fprintf(stderr, "%s: %s\n", destination,
+ verbose_papi_message(svc, status));
+ }
+
+ return (0);
+}
+
+static int
+lpc_clean(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ papi_job_t *jobs = NULL;
+ char *destination = args[1];
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: clean (destination)\n"));
+ return (-1);
+ }
+
+ status = papiPrinterPurgeJobs(svc, destination, &jobs);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("clean: %s: %s\n"), destination,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ if (jobs != NULL) {
+ int i;
+
+ for (i = 0; jobs[i] != NULL; i++)
+ printf(gettext("\t%s-%d: cancelled\n"), destination,
+ papiJobGetId(jobs[i]));
+
+ papiJobListFree(jobs);
+ }
+
+ return (0);
+}
+
+static int
+lpc_disable(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ char *destination = args[1];
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: disable: (destination)\n"));
+ return (-1);
+ }
+
+ status = papiPrinterDisable(svc, destination, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("disable: %s: %s\n"), destination,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+lpc_enable(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ char *destination = args[1];
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: enable: (destination)\n"));
+ return (-1);
+ }
+
+ status = papiPrinterEnable(svc, destination);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("enable: %s: %s\n"), destination,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+lpc_restart(papi_service_t svc, char **args)
+{
+ int rc = 0;
+
+ rc += lpc_disable(svc, args);
+ rc += lpc_enable(svc, args);
+
+ return (rc);
+}
+
+static int
+lpc_start(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ char *destination = args[1];
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: start (destination)\n"));
+ return (-1);
+ }
+
+ status = papiPrinterResume(svc, destination);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("start: %s: %s\n"), destination,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+lpc_stop(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ char *destination = args[1];
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: stop (destination)\n"));
+ return (-1);
+ }
+
+ status = papiPrinterPause(svc, destination, "paused via lpc");
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("stop: %s: %s\n"), destination,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+lpc_topq(papi_service_t svc, char **args)
+{
+ papi_status_t status;
+ char *destination = args[1];
+ int32_t id = atoi(args[2]);
+
+ if (destination == NULL) {
+ fprintf(stderr, gettext("Usage: topq (destination) (id)\n"));
+ return (-1);
+ }
+
+ status = papiJobPromote(svc, destination, id);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("topq: %s %d: %s\n"), destination, id,
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+lpc_up(papi_service_t svc, char **args)
+{
+ int rc = 0;
+
+ rc += lpc_enable(svc, args);
+ rc += lpc_start(svc, args);
+
+ return (rc);
+}
+
+static int
+lpc_down(papi_service_t svc, char **args)
+{
+ int rc = 0;
+
+ rc += lpc_disable(svc, args);
+ rc += lpc_stop(svc, args);
+
+ return (rc);
+}
+
+static int lpc_help(papi_service_t svc, char **args); /* forward reference */
+
+static char help_help[] = "get help on commands";
+static char help_exit[] = "exit lpc";
+static char help_status[] = "show status of daemon and queue";
+static char help_abort[] =
+ "disable print queue terminating any active job processing";
+static char help_clean[] = "remove all jobs from a queue";
+static char help_disable[] = "turn off spooling to a queue";
+static char help_down[] =
+ "turn off queueing and printing for a queue and set a reason";
+static char help_enable[] = "turn on spooling to a queue";
+static char help_restart[] = "restart job processing for a queue";
+static char help_start[] = "turn on printing from a queue";
+static char help_stop[] = "turn off printing from a queue";
+static char help_up[] = "turn on queueing and printing for a queue";
+static char help_topq[] = "put a job at the top of the queue";
+
+static struct {
+ char *cmd;
+ int (*handler)(papi_service_t svc, char **args);
+ char *help_string;
+ int num_args;
+} cmd_tab[] = {
+ { "?", lpc_help, help_help, 0 },
+ { "help", lpc_help, help_help, 0 },
+ { "exit", lpc_exit, help_exit, 0 },
+ { "quit", lpc_exit, help_exit, 0 },
+ { "status", lpc_status, help_status, 1 },
+ { "abort", lpc_abort, help_abort, 1 },
+ { "clean", lpc_clean, help_clean, 1 },
+ { "disable", lpc_disable, help_disable, 1 },
+ { "down", lpc_down, help_down, 2 },
+ { "enable", lpc_enable, help_enable, 1 },
+ { "restart", lpc_restart, help_restart, 1 },
+ { "start", lpc_start, help_start, 1 },
+ { "stop", lpc_stop, help_stop, 1 },
+ { "up", lpc_up, help_up, 1 },
+ { "topq", lpc_topq, help_topq, 2 },
+ { NULL, NULL, NULL, 0 }
+};
+
+static int
+lpc_handler(char *cmd, cmd_handler_t **handler)
+{
+ int i;
+
+ for (i = 0; cmd_tab[i].cmd != NULL; i++)
+ if (strcmp(cmd, cmd_tab[i].cmd) == 0) {
+ *handler = cmd_tab[i].handler;
+ return (cmd_tab[i].num_args);
+ }
+ return (-1);
+}
+
+static char *
+lpc_helptext(char *cmd)
+{
+ int i;
+
+ for (i = 0; cmd_tab[i].cmd != NULL; i++)
+ if (strcmp(cmd, cmd_tab[i].cmd) == 0)
+ return (gettext(cmd_tab[i].help_string));
+ return (NULL);
+}
+
+/* ARGSUSED0 */
+static int
+lpc_help(papi_service_t svc, char **args)
+{
+ if (args[1] == NULL) {
+ int i;
+
+ printf(gettext("Commands are:\n\n"));
+ for (i = 0; cmd_tab[i].cmd != NULL; i++) {
+ printf("\t%s", cmd_tab[i].cmd);
+ if ((i % 7) == 6)
+ printf("\n");
+ }
+ if ((i % 7) != 6)
+ printf("\n");
+ } else {
+ char *helptext = lpc_helptext(args[1]);
+
+ if (helptext == NULL)
+ helptext = gettext("no such command");
+
+ printf("%s: %s\n", args[1], helptext);
+ }
+
+ return (0);
+}
+
+static int
+process_one(int (*handler)(papi_service_t, char **), char **av, int expected)
+{
+ int rc = -1;
+ papi_status_t status = PAPI_OK;
+ papi_service_t svc = NULL;
+ char *printer = av[1];
+
+ if ((printer != NULL) && (expected != 0)) {
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ }
+ }
+
+ if (status == PAPI_OK)
+ rc = handler(svc, av);
+
+ if (svc != NULL)
+ papiServiceDestroy(svc);
+
+ return (rc);
+}
+
+static int
+process_all(int (*handler)(papi_service_t, char **), char **av, int expected)
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ char **printers;
+ int rc = 0;
+
+ status = papiServiceCreate(&svc, NULL, NULL, NULL, NULL,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("Failed to contact service: %s\n"),
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ if ((printers = interest_list(svc)) != NULL) {
+ int i;
+
+ for (i = 0; printers[i] != NULL; i++) {
+ av[1] = printers[i];
+ rc += process_one(handler, av, expected);
+ }
+ }
+
+ papiServiceDestroy(svc);
+
+ return (rc);
+}
+
+static int
+process(int ac, char **av)
+{
+ int (*handler)(papi_service_t, char **) = NULL;
+ int num_args = -1;
+
+ char *printer = av[1];
+ int rc = -1;
+
+ if ((num_args = lpc_handler(av[0], &handler)) < 0) {
+ printf(gettext("%s: invalid command\n"), av[0]);
+ return (-1);
+ }
+
+ if (((printer != NULL) && (strcmp(printer, "all") != 0)) ||
+ (num_args <= ac))
+ rc = process_one(handler, av, num_args);
+ else
+ rc = process_all(handler, av, num_args);
+
+ return (rc);
+}
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s [ command [ parameter...]]\n"),
+ name);
+ exit(1);
+}
+
+static void
+lpc_shell()
+{
+ for (;;) {
+ char line[256];
+ char **av = NULL;
+ int ac = 0;
+
+ /* prompt */
+ fprintf(stdout, "lpc> ");
+ fflush(stdout);
+
+ /* get command */
+ if (fgets(line, sizeof (line), stdin) == NULL)
+ exit(1);
+ if ((av = strsplit(line, " \t\n")) != NULL)
+ for (ac = 0; av[ac] != NULL; ac++);
+
+ (void) process(ac, av);
+ free(av);
+ }
+}
+
+int
+main(int ac, char *av[])
+{
+ int result = 0;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "E")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_ALWAYS;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if (optind == ac)
+ lpc_shell();
+ else
+ result = process(optind - 2, &av[optind]);
+
+ return (result);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpmove.c b/usr/src/cmd/print/bsd-sysv-commands/lpmove.c
new file mode 100644
index 0000000000..cca6c3fcb1
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpmove.c
@@ -0,0 +1,165 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lpmove.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s [request-id] (destination)\n"
+ " %s (source) (destination)\n"), name);
+ exit(1);
+}
+
+static int
+move_job(papi_service_t svc, char *src, int32_t id, char *dest)
+{
+ int result = 0;
+ papi_status_t status;
+ char *mesg = gettext("moved");
+
+ status = papiJobMove(svc, src, id, dest);
+ if (status != PAPI_OK) {
+ mesg = (char *)verbose_papi_message(svc, status);
+ result = -1;
+ }
+ fprintf(stderr, gettext("%s-%d to %s: %s\n"), src, id, dest, mesg);
+
+ return (result);
+}
+
+int
+main(int ac, char *av[])
+{
+ int exit_code = 0;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ char *destination = NULL;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "E:")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if (optind >= ac - 1)
+ usage(av[0]);
+
+ destination = av[--ac];
+
+ for (c = optind; c < ac; c++) {
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_job_t *jobs = NULL;
+ char *printer = NULL;
+ int32_t id = -1;
+
+ (void) get_printer_id(av[c], &printer, &id);
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ exit(1);
+ }
+
+ if (id != -1) { /* it's a job */
+ if (move_job(svc, printer, id, destination) < 0)
+ exit_code = 1;
+ } else { /* it's a printer */
+ char message[128];
+ int count = 0;
+
+ snprintf(message, sizeof (message), "moved jobs to %s",
+ destination);
+ status = papiPrinterDisable(svc, printer, message);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("Disable %s: %s\n"),
+ printer,
+ verbose_papi_message(svc, status));
+ exit_code = 1;
+ } else
+ printf(gettext(
+ "destination %s is not accepting requests\n"),
+ printer);
+
+ status = papiPrinterListJobs(svc, printer, NULL,
+ 0, 0, &jobs);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("Jobs %s: %s\n"),
+ printer,
+ verbose_papi_message(svc, status));
+ exit_code = 1;
+ }
+
+ printf(gettext("move in progress ...\n"));
+ while ((jobs != NULL) && (*jobs != NULL)) {
+ id = papiJobGetId(*jobs++);
+ if (move_job(svc, printer, id, destination) < 0)
+ exit_code = 1;
+ else
+ count++;
+ }
+ printf(gettext(
+ "total of %d requests moved from %s to %s\n"),
+ count, printer, destination);
+
+ papiJobListFree(jobs);
+ }
+
+ papiServiceDestroy(svc);
+ }
+
+ return (exit_code);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpq.c b/usr/src/cmd/print/bsd-sysv-commands/lpq.c
new file mode 100644
index 0000000000..188a5669d6
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpq.c
@@ -0,0 +1,134 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lpq.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout, gettext("Usage: %s [-P printer] (user|id ...)\n"),
+ name);
+ exit(1);
+}
+
+static void
+clear_screen()
+{
+ static char buf[32];
+
+ /* quick and dirty for now, this should be fixed real soon */
+ if (buf[0] == '\0') {
+ FILE *fp = popen("/bin/tput clear", "r");
+ if (fp != NULL) {
+ fgets(buf, sizeof (buf), fp);
+ fclose(fp);
+ }
+ }
+ printf("%s", buf);
+}
+
+int
+main(int ac, char *av[])
+{
+ char *printer = NULL;
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int format = 3; /* lpq short format */
+ int interval = 0;
+ int num_jobs;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "EP:l")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ case 'P':
+ printer = optarg;
+ break;
+ case 'l':
+ format = 4; /* lpq long format */
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if ((optind < ac) && (av[optind][0] == '+'))
+ interval = atoi(av[optind++]);
+
+ if ((printer == NULL) &&
+ ((printer = getenv("PRINTER")) == NULL) &&
+ ((printer = getenv("LPDEST")) == NULL))
+ printer = DEFAULT_DEST;
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ exit(1);
+ }
+
+ do {
+ if (interval != 0)
+ clear_screen();
+
+ num_jobs = berkeley_queue_report(svc, stdout, printer, format,
+ ac - optind, &av[optind]);
+
+ if ((interval != 0) && (num_jobs > 0))
+ sleep(interval);
+ } while ((interval > 0) && (num_jobs > 0));
+
+ papiServiceDestroy(svc);
+
+ return (0);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpr.c b/usr/src/cmd/print/bsd-sysv-commands/lpr.c
new file mode 100644
index 0000000000..b273cfe6c0
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpr.c
@@ -0,0 +1,270 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lpr.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+#ifdef HAVE_LIBMAGIC /* for mimetype auto-detection */
+#include <magic.h>
+#endif /* HAVE_LIBMAGIC */
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s [-P printer] [-# copies] [-C class] "
+ "[-J job] [-T title] "
+ "[-p [-i indent] [-w width]] "
+ "[-1|-2|-3|-4 font] [-m] [-h] [-s] "
+ "[-filter_option] [file ..]\n"), name);
+ exit(1);
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_attribute_t **list = NULL;
+ papi_job_t job = NULL;
+ int exit_code = 0;
+ char *printer = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int dump = 0;
+ int validate = 0;
+ int remove = 0;
+ int copy = 1; /* default is to copy the data */
+ char *document_format = "application/octet-stream";
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av,
+ "EP:#:C:DVJ:T:w:i:hplrstdgvcfmn1:2:3:4:")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ case 'P':
+ printer = optarg;
+ break;
+ case '#':
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
+ "copies", atoi(optarg));
+ break;
+ case 'C':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-class", optarg);
+ break;
+ case 'D':
+ dump = 1;
+ break;
+ case 'J':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "job-name", optarg);
+ break;
+ case 'T':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "pr-title", optarg);
+ break;
+ case 'p':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-pr");
+ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
+ "pr-filter", 1);
+ break;
+ case 'i':
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
+ "pr-indent", atoi(optarg));
+ break;
+ case 'w':
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
+ "pr-width", atoi(optarg));
+ break;
+ case 'h':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "job-sheets", "none");
+ break;
+ case 'l':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/octet-stream");
+ break;
+ case 'o':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/postscript");
+ break;
+ case 'c':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-cif");
+ break;
+ case 'd':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-dvi");
+ break;
+ case 'f':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-fortran");
+ break;
+ case 'g':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-plot");
+ break;
+ case 'n':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-ditroff");
+ break;
+ case 't':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-troff");
+ break;
+ case 'v':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", "application/x-raster");
+ break;
+ case 'm':
+ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-mail", 1);
+ break;
+ case 'r':
+ remove = 1;
+ break;
+ case 's':
+ copy = 0;
+ break;
+ case 'V': /* validate */
+ validate = 1;
+ break;
+ case '1':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-font-r", optarg);
+ break;
+ case '2':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-font-i", optarg);
+ break;
+ case '3':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-font-b", optarg);
+ break;
+ case '4':
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "rfc-1179-font-s", optarg);
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if ((remove != 0) && (copy == 0)) {
+ fprintf(stderr, gettext(
+ "-r and -s may not be used together\n"));
+ exit(1);
+ }
+
+ if ((printer == NULL) &&
+ ((printer = getenv("PRINTER")) == NULL) &&
+ ((printer = getenv("LPDEST")) == NULL))
+ printer = DEFAULT_DEST;
+
+#ifdef MAGIC_MIME
+ if (optind != ac) {
+ /* get the mime type of the file data */
+ magic_t ms;
+
+ if ((ms = magic_open(MAGIC_MIME)) != NULL) {
+ document_format = magic_file(ms, av[optind]);
+ magic_close(ms);
+ }
+ }
+#endif
+
+ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1);
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "document-format", document_format);
+ papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
+ "job-sheets", "standard");
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ exit(1);
+ }
+
+ if (validate == 1) /* validate the request can be processed */
+ status = papiJobValidate(svc, printer, list,
+ NULL, &av[optind], &job);
+ else if (optind == ac) /* no file list, use stdin */
+ status = jobSubmitSTDIN(svc, printer, list, &job);
+ else if (copy == 0) /* reference the files in the job, default */
+ status = papiJobSubmitByReference(svc, printer, list,
+ NULL, &av[optind], &job);
+ else /* copy the files before return, -c */
+ status = papiJobSubmit(svc, printer, list,
+ NULL, &av[optind], &job);
+
+ papiAttributeListFree(list);
+
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("%s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ papiJobFree(job);
+ papiServiceDestroy(svc);
+ exit(1);
+ }
+
+ if (dump != 0) {
+ list = papiJobGetAttributeList(job);
+ printf("job attributes:\n");
+ papiAttributeListPrint(stdout, list, "\t");
+ printf("\n");
+ }
+
+ papiJobFree(job);
+ papiServiceDestroy(svc);
+
+ return (exit_code);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lprm.c b/usr/src/cmd/print/bsd-sysv-commands/lprm.c
new file mode 100644
index 0000000000..841a5da811
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lprm.c
@@ -0,0 +1,101 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lprm.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout, gettext("Usage: %s [-P printer] (user|id ...)\n"),
+ name);
+ exit(1);
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ char *printer = NULL;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "EP:")) != EOF)
+ switch (c) {
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ case 'P':
+ printer = optarg;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if ((printer == NULL) &&
+ ((printer = getenv("PRINTER")) == NULL) &&
+ ((printer = getenv("LPDEST")) == NULL))
+ printer = DEFAULT_DEST;
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (1);
+ }
+
+ berkeley_cancel_request(svc, stdout, printer,
+ ac - optind, &av[optind]);
+
+ papiServiceDestroy(svc);
+
+ return (0);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
new file mode 100644
index 0000000000..466025da9a
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c
@@ -0,0 +1,1015 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: lpstat.c 173 2006-05-25 04:52:06Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <pwd.h>
+#include <papi.h>
+#include <uri.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout, gettext("Usage: %s [-d] [-r] [-s] [-t] [-a [list]] "
+ "[-c [list]] [-o [list] [-l]] [-R [list] [-l]] "
+ "[-p [list] [-D] [-l]] [-v [list]] [-S [list] [-l]] "
+ "[-f [list] [-l]] [-u list]\n"),
+ name);
+ exit(1);
+}
+
+static char *
+nctime(time_t *t)
+{
+ static char buf[64];
+ struct tm *tm = localtime(t);
+
+ (void) strftime(buf, sizeof (buf), "%c", tm);
+
+ return (buf);
+}
+
+static char *
+printer_name(papi_printer_t printer)
+{
+ papi_attribute_t **attributes = papiPrinterGetAttributeList(printer);
+ char *result = NULL;
+
+ if (attributes != NULL)
+ papiAttributeListGetString(attributes, NULL,
+ "printer-name", &result);
+
+ return (result);
+}
+
+static int
+lpstat_default_printer(papi_encryption_t encryption)
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_printer_t p = NULL;
+ char *name = NULL;
+
+ status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status == PAPI_OK) {
+ char *req[] = { "printer-name", NULL };
+
+ status = papiPrinterQuery(svc, DEFAULT_DEST, req, NULL, &p);
+ if (p != NULL)
+ name = printer_name(p);
+ }
+ if (name != NULL)
+ printf(gettext("system default printer: %s\n"), name);
+ else
+ printf(gettext("no system default destination\n"));
+ papiPrinterFree(p);
+ papiServiceDestroy(svc);
+
+ return (0);
+}
+
+static int
+lpstat_service_status(papi_encryption_t encryption)
+{
+ int result = 0;
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ char *name = NULL;
+
+ if (((name = getenv("PAPI_SERVICE_URI")) == NULL) &&
+ ((name = getenv("IPP_SERVER")) == NULL) &&
+ ((name = getenv("CUPS_SERVER")) == NULL))
+ name = DEFAULT_SERVICE_URI;
+
+ status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ printf(gettext("scheduler is not running\n"));
+ result = -1;
+ } else
+ printf(gettext("scheduler is running\n"));
+ papiServiceDestroy(svc);
+
+ return (result);
+}
+
+static char *
+get_device_uri(papi_service_t svc, char *name)
+{
+ papi_status_t status;
+ papi_printer_t p = NULL;
+ char *keys[] = { "device-uri", NULL };
+ char *result = NULL;
+
+ status = papiPrinterQuery(svc, name, keys, NULL, &p);
+ if ((status == PAPI_OK) && (p != NULL)) {
+ papi_attribute_t **attrs = papiPrinterGetAttributeList(p);
+
+ (void) papiAttributeListGetString(attrs, NULL,
+ "device-uri", &result);
+ if (result != NULL)
+ result = strdup(result);
+
+ papiPrinterFree(p);
+ }
+
+ return (result);
+}
+
+static char *report_device_keys[] = { "printer-name", "printer-uri-supported",
+ NULL };
+/* ARGSUSED2 */
+static int
+report_device(papi_service_t svc, char *name, papi_printer_t printer,
+ int verbose, int description)
+{
+ papi_status_t status;
+ papi_attribute_t **attrs = papiPrinterGetAttributeList(printer);
+ char *uri = NULL;
+ char *device = NULL;
+ uri_t *u = NULL;
+
+ if (name == NULL) {
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-name", &name);
+ if (status != PAPI_OK)
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-uri-supported", &name);
+ }
+
+ if (name == NULL)
+ return (-1);
+
+ (void) papiAttributeListGetString(attrs, NULL,
+ "printer-uri-supported", &uri);
+
+ if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) {
+ char *nodename = localhostname();
+
+ if ((u->host == NULL) ||
+ (strcasecmp(u->host, "localhost") == 0) ||
+ (strcasecmp(u->host, nodename) == 0))
+ device = get_device_uri(svc, name);
+
+ if (device != NULL) {
+ printf(gettext("device for %s: %s\n"), name, device);
+ return (0);
+ } else if (uri != NULL) {
+ printf(gettext("system for %s: %s (as %s)\n"), name,
+ u->host, uri);
+ return (0);
+ }
+
+ uri_free(u);
+ }
+
+ return (0);
+}
+
+static char *report_accepting_keys[] = { "printer-name",
+ "printer-uri-supported", "printer-is-accepting-jobs",
+ "printer-up-time", "printer-state-time",
+ "lpsched-reject-date", "lpsched-reject-reason", NULL };
+/* ARGSUSED2 */
+static int
+report_accepting(papi_service_t svc, char *name, papi_printer_t printer,
+ int verbose, int description)
+{
+ papi_status_t status;
+ papi_attribute_t **attrs = papiPrinterGetAttributeList(printer);
+ time_t curr;
+ char boolean = PAPI_FALSE;
+
+ if (name == NULL) {
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-name", &name);
+ if (status != PAPI_OK)
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-uri-supported", &name);
+ }
+ if (name == NULL)
+ return (-1);
+
+ (void) papiAttributeListGetBoolean(attrs, NULL,
+ "printer-is-accepting-jobs", &boolean);
+ (void) time(&curr);
+ (void) papiAttributeListGetDatetime(attrs, NULL,
+ "printer-up-time", &curr);
+ (void) papiAttributeListGetDatetime(attrs, NULL,
+ "printer-state-time", &curr);
+ (void) papiAttributeListGetDatetime(attrs, NULL,
+ "lpsched-reject-date", &curr);
+
+ if (boolean == PAPI_TRUE) {
+ printf(gettext("%s accepting requests since %s\n"),
+ name, nctime(&curr));
+ } else {
+ char *reason = "unknown reason";
+
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-reject-reason", &reason);
+
+ printf(gettext("%s not accepting requests since %s\n\t%s\n"),
+ name, nctime(&curr), reason);
+ }
+
+ return (0);
+}
+
+static char *report_class_keys[] = { "printer-name", "printer-uri-supported",
+ "member-names", NULL };
+/* ARGSUSED2 */
+static int
+report_class(papi_service_t svc, char *name, papi_printer_t printer,
+ int verbose, int description)
+{
+ papi_status_t status;
+ papi_attribute_t **attrs = papiPrinterGetAttributeList(printer);
+ char *member = NULL;
+ void *iter = NULL;
+
+ status = papiAttributeListGetString(attrs, &iter,
+ "member-names", &member);
+ if (status == PAPI_NOT_FOUND) /* it's not a class */
+ return (0);
+
+ if (name == NULL) {
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-name", &name);
+ if (status != PAPI_OK)
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-uri-supported", &name);
+ }
+ if (name == NULL)
+ return (-1);
+
+ printf(gettext("members of class %s:\n\t%s\n"), name, member);
+ while (papiAttributeListGetString(attrs, &iter, NULL, &member)
+ == PAPI_OK)
+ printf("\t%s\n", member);
+
+ return (0);
+}
+
+static char *report_printer_keys[] = { "printer-name",
+ "printer-uri-supported", "printer-state",
+ "printer-up-time", "printer-state-time",
+ "lpsched-disable-date", "printer-state-reasons",
+ "lpsched-disable-reason", NULL };
+/* ARGSUSED2 */
+static int
+report_printer(papi_service_t svc, char *name, papi_printer_t printer,
+ int verbose, int description)
+{
+ papi_status_t status;
+ papi_attribute_t **attrs = papiPrinterGetAttributeList(printer);
+ time_t curr;
+ int32_t pstat = 0;
+ char *member = NULL;
+
+ status = papiAttributeListGetString(attrs, NULL,
+ "member-names", &member);
+ if (status == PAPI_OK) /* it's a class */
+ return (0);
+
+ if (name == NULL) {
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-name", &name);
+ if (status != PAPI_OK)
+ status = papiAttributeListGetString(attrs, NULL,
+ "printer-uri-supported", &name);
+ }
+ if (name == NULL)
+ return (-1);
+
+ printf(gettext("printer %s "), name);
+
+ status = papiAttributeListGetInteger(attrs, NULL,
+ "printer-state", &pstat);
+
+ switch (pstat) {
+ case 0x03: /* idle */
+ printf(gettext("idle. enabled"));
+ break;
+ case 0x04: { /* processing */
+ char *requested[] = { "job-id", NULL };
+ papi_job_t *j = NULL;
+ int32_t jobid = 0;
+
+ (void) papiPrinterListJobs(svc, name, requested, 0, 1, &j);
+ if ((j != NULL) && (j[0] != NULL))
+ jobid = papiJobGetId(j[0]);
+ papiJobListFree(j);
+
+ printf(gettext("now printing %s-%d. enabled"), name, jobid);
+ }
+ break;
+ case 0x05: /* stopped */
+ printf(gettext("disabled"));
+ break;
+ default:
+ printf(gettext("unknown state(0x%x)."), pstat);
+ break;
+ }
+
+ (void) time(&curr);
+ (void) papiAttributeListGetDatetime(attrs, NULL,
+ "printer-up-time", &curr);
+ (void) papiAttributeListGetDatetime(attrs, NULL,
+ "printer-state-time", &curr);
+ (void) papiAttributeListGetDatetime(attrs, NULL,
+ "lpsched-disable-date", &curr);
+ printf(gettext(" since %s. available.\n"), nctime(&curr));
+
+ if (pstat == 0x05) {
+ char *reason = "unknown reason";
+
+ (void) papiAttributeListGetString(attrs, NULL,
+ "printer-state-reasons", &reason);
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-disable-reason", &reason);
+ printf(gettext("\t%s\n"), reason);
+ }
+
+ if (verbose == 1) {
+ void *iter;
+ char *str;
+
+ str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "form-ready", &str);
+ printf(gettext("\tForm mounted: %s\n"), str);
+
+ str = "";
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "document-format-supported", &str);
+ printf(gettext("\tContent types: %s"), str);
+ while (papiAttributeListGetString(attrs, &iter, NULL, &str)
+ == PAPI_OK)
+ printf(", %s", str);
+ printf("\n");
+
+ str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "printer-info", &str);
+ printf(gettext("\tDescription: %s\n"), str);
+
+ str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-dial-info", &str);
+ printf(gettext("\tConnection: %s\n"),
+ ((str[0] != '\0') ? gettext("direct") : str));
+
+ str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-interface-script", &str);
+ printf(gettext("\tInterface: %s\n"), str);
+
+ str = NULL;
+ (void) papiAttributeListGetString(attrs, NULL,
+ "ppd-file-uri", &str);
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-ppd-source-path", &str);
+ if (str != NULL)
+ printf(gettext("\tPPD: %s\n"), str);
+
+ str = NULL;
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-fault-alert-command", &str);
+ if (str != NULL)
+ printf(gettext("\tOn fault: %s\n"), str);
+
+ str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "lpsched-fault-recovery", &str);
+ printf(gettext("\tAfter fault: %s\n"),
+ ((str[0] == '\0') ? gettext("continue") : str));
+
+ str = "(all)";
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "requesting-user-name-allowed", &str);
+ printf(gettext("\tUsers allowed:\n\t\t%s\n"),
+ ((str[0] == '\0') ? gettext("(none)") : str));
+ if ((str != NULL) && (str[0] != '\0'))
+ while (papiAttributeListGetString(attrs, &iter, NULL,
+ &str) == PAPI_OK)
+ printf("\t\t%s\n", str);
+
+ str = NULL;
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "requesting-user-name-denied", &str);
+ if (str != NULL) {
+ printf(gettext("\tUsers denied:\n\t\t%s\n"),
+ ((str[0] == '\0') ? gettext("(none)") : str));
+ if ((str != NULL) && (str[0] != '\0'))
+ while (papiAttributeListGetString(attrs, &iter,
+ NULL, &str) == PAPI_OK)
+ printf("\t\t%s\n", str);
+ }
+
+ str = "(none)";
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "form-supported", &str);
+ printf(gettext("\tForms allowed:\n\t\t%s\n"),
+ ((str[0] == '\0') ? gettext("(none)") : str));
+ if ((str != NULL) && (str[0] != '\0'))
+ while (papiAttributeListGetString(attrs, &iter, NULL,
+ &str) == PAPI_OK)
+ printf("\t\t%s\n", str);
+
+ str = "";
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "media-supported", &str);
+ printf(gettext("\tMedia supported:\n\t\t%s\n"),
+ ((str[0] == '\0') ? gettext("(none)") : str));
+ if ((str != NULL) && (str[0] != '\0'))
+ while (papiAttributeListGetString(attrs, &iter, NULL,
+ &str) == PAPI_OK)
+ printf("\t\t%s\n", str);
+
+ str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "job-sheets-supported", &str);
+ printf(gettext("\tBanner %s\n"),
+ (strcasecmp(str, "none") == 0 ?
+ gettext("not required") : gettext("required")));
+
+ str = "";
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "lpsched-print-wheels", &str);
+ printf(gettext("\tCharacter sets:\n\t\t%s\n"),
+ ((str[0] == '\0') ? gettext("(none)") : str));
+ if ((str != NULL) && (str[0] != '\0'))
+ while (papiAttributeListGetString(attrs, &iter, NULL,
+ &str) == PAPI_OK)
+ printf("\t\t%s\n", str);
+
+ printf(gettext("\tDefault pitch:\n"));
+ printf(gettext("\tDefault page size:\n"));
+ printf(gettext("\tDefault port setting:\n"));
+
+ str = "";
+ iter = NULL;
+ (void) papiAttributeListGetString(attrs, &iter,
+ "lpsched-options", &str);
+ if (str != NULL) {
+ printf(gettext("\tOptions: %s"), str);
+ while (papiAttributeListGetString(attrs, &iter, NULL,
+ &str) == PAPI_OK)
+ printf(", %s", str);
+ printf("\n");
+ }
+
+ } else if (description == 1) {
+ char *str = "";
+ (void) papiAttributeListGetString(attrs, NULL,
+ "printer-description", &str);
+ printf(gettext("\tDescription: %s\n"), str);
+ } else if (verbose > 1)
+ papiAttributeListPrint(stdout, attrs, "\t");
+
+ if (verbose > 0)
+ printf("\n");
+
+ return (0);
+}
+
+static int
+printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t,
+ int, int), papi_encryption_t encryption,
+ int verbose, int description)
+{
+ int result = 0;
+ papi_status_t status;
+ papi_service_t svc = NULL;
+
+ status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ name ? name : "(NULL)",
+ verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (-1);
+ }
+
+ if (name == NULL) { /* all */
+ char **interest = interest_list(svc);
+
+ if (interest != NULL) {
+ int i;
+
+ for (i = 0; interest[i] != NULL; i++)
+ result += printer_query(interest[i], report,
+ encryption, verbose,
+ description);
+ }
+ } else {
+ papi_printer_t printer = NULL;
+ char **keys = NULL;
+
+ /*
+ * Limit the query to only required data to reduce the need
+ * to go remote for information.
+ */
+ if (report == report_device)
+ keys = report_device_keys;
+ else if (report == report_class)
+ keys = report_class_keys;
+ else if (report == report_accepting)
+ keys = report_accepting_keys;
+ else if ((report == report_printer) && (verbose == 0))
+ keys = report_printer_keys;
+
+ status = papiPrinterQuery(svc, name, keys, NULL, &printer);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to get printer info for %s: %s\n"),
+ name, verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (-1);
+ }
+
+ if (printer != NULL)
+ result = report(svc, name, printer, verbose,
+ description);
+
+ papiPrinterFree(printer);
+ }
+
+ papiServiceDestroy(svc);
+
+ return (result);
+}
+
+static int
+match_user(char *user, char **list)
+{
+ int i;
+
+ for (i = 0; list[i] != NULL; i++) {
+ if (strcmp(user, list[i]) == 0)
+ return (0);
+ }
+
+ return (-1);
+}
+
+static char **users = NULL;
+
+static int
+report_job(papi_job_t job, int show_rank, int verbose)
+{
+ papi_attribute_t **attrs = papiJobGetAttributeList(job);
+ time_t clock = 0;
+ char date[24];
+ char request[26];
+ char *user = "unknown";
+ int32_t size = 0;
+ int32_t jstate = 0;
+
+ char *destination = "unknown";
+ int32_t id = -1;
+
+ (void) papiAttributeListGetString(attrs, NULL,
+ "job-originating-user-name", &user);
+
+ if ((users != NULL) && (match_user(user, users) < 0))
+ return (0);
+
+ (void) papiAttributeListGetInteger(attrs, NULL, "job-k-octets", &size);
+ size *= 1024; /* for the approximate byte size */
+ (void) papiAttributeListGetInteger(attrs, NULL, "job-octets", &size);
+
+ (void) time(&clock);
+ (void) papiAttributeListGetInteger(attrs, NULL,
+ "time-at-creation", (int32_t *)&clock);
+ (void) strftime(date, sizeof (date), "%b %d %R", localtime(&clock));
+
+ (void) papiAttributeListGetString(attrs, NULL,
+ "job-printer-uri", &destination);
+ (void) papiAttributeListGetString(attrs, NULL,
+ "printer-name", &destination);
+ (void) papiAttributeListGetInteger(attrs, NULL,
+ "job-id", &id);
+ snprintf(request, sizeof (request), "%s-%d", destination, id);
+
+ if (show_rank != 0) {
+ int32_t rank = -1;
+
+ (void) papiAttributeListGetInteger(attrs, NULL,
+ "number-of-intervening-jobs", &rank);
+ rank++;
+
+ printf("%3d %-21s %-14s %7ld %s",
+ rank, request, user, size, date);
+ } else
+ printf("%-23s %-14s %7ld %s", request, user, size, date);
+
+ (void) papiAttributeListGetInteger(attrs, NULL,
+ "job-state", &jstate);
+ if (jstate == 0x04)
+ printf(gettext(", being held"));
+ else if (jstate == 0x07)
+ printf(gettext(", cancelled"));
+ else if (jstate == 0x09)
+ printf(gettext(", complete"));
+
+ if (verbose == 1) {
+ (void) papiAttributeListGetString(attrs, NULL,
+ "output-device-assigned", &destination);
+ printf("\n\t assigned %s", destination);
+ } else if (verbose > 1) {
+ printf("\n");
+ papiAttributeListPrint(stdout, attrs, "\t");
+ }
+
+ printf("\n");
+
+ return (0);
+}
+
+static int
+job_query(char *request, int (*report)(papi_job_t, int, int),
+ papi_encryption_t encryption, int show_rank, int verbose)
+{
+ int result = 0;
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ char *printer = NULL;
+ int32_t id = -1;
+
+ get_printer_id(request, &printer, &id);
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ (printer ? printer : "all"),
+ verbose_papi_message(svc, status));
+ return (-1);
+ }
+
+ if (printer == NULL) { /* all */
+ char **interest = interest_list(svc);
+
+ if (interest != NULL) {
+ int i;
+
+ for (i = 0; interest[i] != NULL; i++)
+ result += job_query(interest[i], report,
+ encryption, show_rank, verbose);
+ }
+ } else if (id == -1) { /* a printer */
+ papi_job_t *jobs = NULL;
+
+ status = papiPrinterListJobs(svc, printer, NULL, 0, 0, &jobs);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to get job list: %s\n"),
+ verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (-1);
+ }
+
+ if (jobs != NULL) {
+ int i;
+
+ for (i = 0; jobs[i] != NULL; i++)
+ result += report(jobs[i], show_rank, verbose);
+ }
+
+ papiJobListFree(jobs);
+ } else { /* a job */
+ papi_job_t job = NULL;
+
+ status = papiJobQuery(svc, printer, id, NULL, &job);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to get job info for %s: %s\n"),
+ request, verbose_papi_message(svc, status));
+ papiServiceDestroy(svc);
+ return (-1);
+ }
+
+ if (job != NULL)
+ result = report(job, show_rank, verbose);
+
+ papiJobFree(job);
+ }
+
+ papiServiceDestroy(svc);
+
+ return (result);
+}
+
+static int
+report_form(char *name, papi_attribute_t **attrs, int verbose)
+{
+ papi_status_t status;
+ char *form = NULL;
+ void *iter = NULL;
+
+ for (status = papiAttributeListGetString(attrs, &iter,
+ "form-supported", &form);
+ status == PAPI_OK;
+ status = papiAttributeListGetString(attrs, &iter,
+ NULL, &form)) {
+ if ((name == NULL) || (strcmp(name, form) == 0)) {
+ printf(gettext("form %s is available to you\n"), form);
+ if (verbose != 0) {
+ char *detail = NULL;
+ status = papiAttributeListGetString(attrs, NULL,
+ "form-supported-detail",
+ &detail);
+ if (status == PAPI_OK)
+ printf("%s\n", detail);
+ }
+ }
+ }
+
+ return (0);
+}
+
+static int
+report_print_wheels(char *name, papi_attribute_t **attrs, int verbose)
+{
+ papi_status_t status;
+ char *pw = NULL;
+ void *iter = NULL;
+
+ for (status = papiAttributeListGetString(attrs, &iter,
+ "pw-supported", &pw);
+ status == PAPI_OK;
+ status = papiAttributeListGetString(attrs, &iter, NULL, &pw)) {
+ if ((name == NULL) || (strcmp(name, pw) == 0)) {
+ printf(gettext("charset %s is available\n"), pw);
+ if (verbose != 0) {
+ char *info = NULL;
+ status = papiAttributeListGetString(attrs, NULL,
+ "pw-supported-extra", &info);
+ if (status == PAPI_OK)
+ printf("%s\n", info);
+ }
+ }
+ }
+
+ return (0);
+}
+
+static int
+service_query(char *name, int (*report)(char *, papi_attribute_t **, int),
+ papi_encryption_t encryption, int verbose)
+{
+ int result = 0;
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_attribute_t **attrs = NULL;
+
+ status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback,
+ encryption, NULL);
+ if (status != PAPI_OK) {
+ papiServiceDestroy(svc);
+ return (-1);
+ }
+
+ attrs = papiServiceGetAttributeList(svc);
+ if (attrs != NULL) {
+ result = report(name, attrs, verbose);
+
+ if (verbose > 1) {
+ printf("\n");
+ papiAttributeListPrint(stdout, attrs, "\t");
+ printf("\n");
+ }
+ }
+
+ papiServiceDestroy(svc);
+
+ return (result);
+}
+
+int
+main(int ac, char *av[])
+{
+ int exit_code = 0;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ int rank = 0;
+ int verbose = 0;
+ int description = 0;
+ int c;
+ char **argv;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ argv = (char **)calloc((ac + 1), sizeof (char *));
+ for (c = 0; c < ac; c++)
+ argv[c] = av[c];
+ argv[c++] = "--";
+ ac = c;
+
+ /* preprocess argument list looking for '-l' or '-R' so it can trail */
+ while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF)
+ switch (c) {
+ case 'l':
+ if ((optarg == NULL) || (optarg[0] == '-'))
+ optarg = "1";
+ verbose = atoi(optarg);
+ break;
+ case 'D':
+ description = 1;
+ break;
+ case 'R':
+ rank = 1;
+ break;
+ case 'E':
+ encryption = PAPI_ENCRYPT_REQUIRED;
+ break;
+ default:
+ break;
+ }
+ optind = 1;
+
+ /* process command line arguments */
+ while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) {
+ switch (c) { /* these may or may not have an option */
+ case 'a':
+ case 'c':
+ case 'p':
+ case 'o':
+ case 'R':
+ case 'u':
+ case 'v':
+ case 'l':
+ case 'f':
+ case 'S':
+ if (optarg[0] == '-') {
+ /* this check stop a possible infinite loop */
+ if ((optind > 1) && (argv[optind-1][1] != c))
+ optind--;
+ optarg = NULL;
+ } else if (strcmp(optarg, "all") == 0)
+ optarg = NULL;
+ }
+
+ switch (c) {
+ case 'a':
+ exit_code += printer_query(optarg, report_accepting,
+ encryption, verbose, 0);
+ break;
+ case 'c':
+ exit_code += printer_query(optarg, report_class,
+ encryption, verbose, 0);
+ break;
+ case 'p':
+ exit_code += printer_query(optarg, report_printer,
+ encryption, verbose,
+ description);
+ break;
+ case 'd':
+ exit_code += lpstat_default_printer(encryption);
+ break;
+ case 'r':
+ exit_code += lpstat_service_status(encryption);
+ break;
+ case 'u':
+ if (optarg != NULL)
+ users = strsplit(optarg, ", \n");
+ exit_code += job_query(NULL, report_job,
+ encryption, rank, verbose);
+ if (users != NULL) {
+ free(users);
+ users = NULL;
+ }
+ break;
+ case 'v':
+ exit_code += printer_query(optarg, report_device,
+ encryption, verbose, 0);
+ break;
+ case 'o':
+ exit_code += job_query(optarg, report_job,
+ encryption, rank, verbose);
+ break;
+ case 'f':
+ exit_code += service_query(optarg, report_form,
+ encryption, verbose);
+ break;
+ case 'S':
+ exit_code += service_query(optarg, report_print_wheels,
+ encryption, verbose);
+ break;
+ case 's':
+ exit_code += lpstat_service_status(encryption);
+ exit_code += lpstat_default_printer(encryption);
+ exit_code += printer_query(NULL, report_class,
+ encryption, verbose, 0);
+ exit_code += printer_query(NULL, report_device,
+ encryption, verbose, 0);
+ exit_code += service_query(optarg, report_form,
+ encryption, verbose);
+ exit_code += service_query(optarg, report_print_wheels,
+ encryption, verbose);
+ break;
+ case 't':
+ exit_code += lpstat_service_status(encryption);
+ exit_code += lpstat_default_printer(encryption);
+ exit_code += printer_query(NULL, report_class,
+ encryption, verbose, 0);
+ exit_code += printer_query(NULL, report_device,
+ encryption, verbose, 0);
+ exit_code += printer_query(NULL, report_accepting,
+ encryption, verbose, 0);
+ exit_code += printer_query(NULL, report_printer,
+ encryption, verbose, 0);
+ exit_code += service_query(optarg, report_form,
+ encryption, verbose);
+ exit_code += service_query(optarg, report_print_wheels,
+ encryption, verbose);
+ exit_code += job_query(NULL, report_job,
+ encryption, rank, verbose);
+ break;
+ case 'L': /* local-only, ignored */
+ case 'l': /* increased verbose level in first pass */
+ case 'D': /* set "description" flag in first pass */
+ case 'R': /* set "rank" flag in first pass */
+ case 'E': /* set encryption in the first pass */
+ break;
+ default:
+ usage(av[0]);
+ }
+ }
+ ac--;
+
+ if (ac == 1) { /* report on my jobs */
+ struct passwd *pw = getpwuid(getuid());
+
+ if (pw != NULL)
+ users = strsplit(pw->pw_name, "");
+ exit_code += job_query(NULL, report_job, encryption,
+ rank, verbose);
+ if (users != NULL) {
+ free(users);
+ users = NULL;
+ }
+ } else {
+ for (c = optind; c < ac; c++)
+ exit_code += job_query(argv[c], report_job, encryption,
+ rank, verbose);
+ }
+
+
+ if (exit_code != 0)
+ exit_code = 1;
+
+ return (exit_code);
+}
diff --git a/usr/src/cmd/print/bsd-sysv-commands/reject.c b/usr/src/cmd/print/bsd-sysv-commands/reject.c
new file mode 100644
index 0000000000..58eb2829d0
--- /dev/null
+++ b/usr/src/cmd/print/bsd-sysv-commands/reject.c
@@ -0,0 +1,108 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/* $Id: reject.c 146 2006-03-24 00:26:54Z njacobs $ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include <papi.h>
+#include "common.h"
+
+static void
+usage(char *program)
+{
+ char *name;
+
+ if ((name = strrchr(program, '/')) == NULL)
+ name = program;
+ else
+ name++;
+
+ fprintf(stdout,
+ gettext("Usage: %s destination ...\n"),
+ name);
+ exit(1);
+}
+
+int
+main(int ac, char *av[])
+{
+ papi_status_t status;
+ papi_service_t svc = NULL;
+ papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
+ char *reason = NULL;
+ int exit_status = 0;
+ int c = 1;
+
+ (void) setlocale(LC_ALL, "");
+ (void) textdomain("SUNW_OST_OSCMD");
+
+ while ((c = getopt(ac, av, "Er:")) != EOF)
+ switch (c) {
+ case 'r': /* reason */
+ reason = optarg;
+ break;
+ case 'E':
+ encryption = PAPI_ENCRYPT_ALWAYS;
+ break;
+ default:
+ usage(av[0]);
+ }
+
+ if (ac <= optind)
+ usage(av[0]);
+
+ while (optind < ac) {
+ char *printer = av[optind++];
+
+ status = papiServiceCreate(&svc, printer, NULL, NULL,
+ cli_auth_callback, encryption, NULL);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext(
+ "Failed to contact service for %s: %s\n"),
+ printer, verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ status = papiPrinterPause(svc, printer, reason);
+ if (status != PAPI_OK) {
+ fprintf(stderr, gettext("reject: %s: %s\n"), printer,
+ verbose_papi_message(svc, status));
+ exit_status = 1;
+ }
+
+ papiServiceDestroy(svc);
+ }
+
+ return (exit_status);
+}