diff options
author | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
---|---|---|
committer | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
commit | 7c478bd95313f5f23a4c958a745db2134aa03244 (patch) | |
tree | c871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/cmd/print | |
download | illumos-gate-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz |
OpenSolaris Launch
Diffstat (limited to 'usr/src/cmd/print')
177 files changed, 34933 insertions, 0 deletions
diff --git a/usr/src/cmd/print/Makefile b/usr/src/cmd/print/Makefile new file mode 100644 index 0000000000..ff02c70dbf --- /dev/null +++ b/usr/src/cmd/print/Makefile @@ -0,0 +1,110 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/print/Makefile +# + +include ../Makefile.cmd + +JAVA_SUBDIRS = printmgr + +PRINT_SUBDIRS = \ + scripts \ + lpget \ + lpset \ + lp \ + lpstat \ + cancel \ + lpmove \ + conv_fix \ + printer-info \ + gateway + +SUBDIRS = $(PRINT_SUBDIRS) $(JAVA_SUBDIRS) + +ROOTDIRS = $(ROOTLIB)/print \ + $(ROOTLIB)/print/bsd-adaptor + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +strip := TARGET= strip +_msg := TARGET = _msg + +# For testing message catalogs +_msg_test:= TARGET = _msg_test + +POFILE= print.po + +.KEEP_STATE: + +all install: $(ROOTDIRS) $(SUBDIRS) + +# +# We define our own definition for _msg here because most of these +# commands have the same PROG names as their counterparts in +# cmd/lp. Using the _msg rule defined in Makefile.cmd would +# result in clobbering the cmd/lp message files. +# To get around this we will define one message file "print.po" +# for these commands (except java printmgr). To build +# this file we find all of the .c files and run xgettext on them. +# Then concatenate this with the scripts.po file. +# +_msg: $(MSGDOMAIN) scripts $(JAVA_SUBDIRS) + @$(RM) $(POFILE) + $(XGETTEXT) -s `/bin/find . -type d -name SCCS -prune -o -type f -name '*.c' -print` + @/bin/cat messages.po scripts/scripts.po | sed '/domain/d' > $(POFILE) + @$(RM) messages.po + $(RM) $(MSGDOMAIN)/$(POFILE) + /bin/cp $(POFILE) $(MSGDOMAIN) + +# +# Create a message file to test with. +# +_msg_test: scripts + @$(RM) $(POFILE) + $(XGETTEXT) -s -m "xxx" `/bin/find . -print | grep '\.c$$' | sed '/SCCS/d'` + @/bin/cat messages.po scripts/scripts.po | sed '/domain/d' > $(POFILE) + echo 'domain "SUNW_OST_OSCMD"' > SUNW_OST_OSCMD.po + cat $(POFILE) >> SUNW_OST_OSCMD.po + msgfmt SUNW_OST_OSCMD.po + @$(RM) messages.po $(POFILE) SUNW_OST_OSCMD.po + +clean strip cstyle lint: $(SUBDIRS) + +clobber: $(SUBDIRS) + $(RM) $(POFILE) $(CLOBBERFILES) + +$(ROOTDIRS) $(MSGDOMAIN): + $(INS.dir) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/Makefile.sp b/usr/src/cmd/print/Makefile.sp new file mode 100644 index 0000000000..f4510a84a8 --- /dev/null +++ b/usr/src/cmd/print/Makefile.sp @@ -0,0 +1,124 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/print/Makefile.sp +# Common makefile definitions (should be) used by all print(lp) makefiles +# + +include $(SRC)/cmd/Makefile.cmd + +LPROOT= $(SRC)/cmd/lp +NPRTROOT= $(LPROOT) +ROOTVAR= $(ROOT)/var +ROOTVARSP= $(ROOT)/var/spool +ROOTVARSPOOLPRINT= $(ROOTVARSP)/print + +ROOTINIT_D= $(ROOTETC)/init.d +ROOTRC0_D= $(ROOTETC)/rc0.d +ROOTRCS_D= $(ROOTETC)/rcS.d +ROOTRC1_D= $(ROOTETC)/rc1.d +ROOTRC2_D= $(ROOTETC)/rc2.d + + +ROOTETCLP= $(ROOTETC)/lp +ROOTLIBLP= $(ROOTLIB)/lp +ROOTBINLP= $(ROOTBIN)/lp +ROOTLIBLPPOST = $(ROOTLIBLP)/postscript +ROOTLOCALLP= $(ROOTLIBLP)/local +ROOTLIBPRINT= $(ROOTLIB)/print +ROOTLIBPRINTBIN= $(ROOTLIBPRINT)/bin + +ROOTUSRUCB= $(ROOT)/usr/ucb + + + +# +# Typical owner and group for LP things. These can be overridden +# in the individual makefiles. +# +OWNER = root +GROUP = lp +SUPER = root + +$(ROOTINIT_D) := GROUP = sys +$(ROOTRC0_D) := GROUP = sys +$(ROOTRCS_D) := GROUP = sys +$(ROOTRC1_D) := GROUP = sys +$(ROOTRC2_D) := GROUP = sys +$(ROOTUSRUCB) := GROUP = bin +$(ROOTUSRSBIN) := GROUP = bin +$(ROOTBIN) := GROUP = bin +# +# $(EMODES): Modes for executables +# $(SMODES): Modes for setuid executables +# $(DMODES): Modes for directories +# +EMODES = 0555 +SMODES = 04555 +DMODES = 0755 + + +INC = $(ROOT)/usr/include +INCSYS = $(INC)/sys + +LPINC = $(SRC)/include +#NPRTINC = $(NPRTROOT)/include +NPRTINC = $(SRC)/lib +LPLIB = $(SRC)/lib +LDLIBS += -L$(LPLIB) + + +LIBNPRT = -L$(ROOT)/usr/lib -lprint + +# lint definitions + +LINTFLAGS += -L $(SRC)/lib/print -lprint -lnsl -lsocket + +all :=TARGET= all +install :=TARGET= install +clean :=TARGET= clean +clobber :=TARGET= clobber +lint :=TARGET= lint +strip :=TARGET= strip +_msg :=TARGET= _msg + +ROOTLIBLPPROG= $(PROG:%=$(ROOTLIBLP)/%) +ROOTBINLPPROG= $(PROG:%=$(ROOTBINLP)/%) +ROOTETCLPPROG= $(PROG:%=$(ROOTETCLP)/%) +ROOTUSRUCBPROG= $(PROG:%=$(ROOTUSRUCB)/%) +ROOTLOCALLPPROG= $(PROG:%=$(ROOTLOCALLP)/%) +ROOTLIBLPPOSTPROG= $(PROG:%=$(ROOTLIBLPPOST)/%) +ROOTLIBPRINTPROG= $(PROG:%=$(ROOTLIBPRINT)/%) + +$(ROOTLIBLP)/% \ +$(ROOTBINLP)/% \ +$(ROOTETCLP)/% \ +$(ROOTUSRUCB)/% \ +$(ROOTLOCALLP)/% \ +$(ROOTLIBLPPOST)/% \ +$(ROOTLIBPRINT)/% : % + $(INS.file) diff --git a/usr/src/cmd/print/cancel/Makefile b/usr/src/cmd/print/cancel/Makefile new file mode 100644 index 0000000000..c97f173699 --- /dev/null +++ b/usr/src/cmd/print/cancel/Makefile @@ -0,0 +1,81 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1994 by Sun Microsystems, Inc. +# All Rights Reserved +# +# cmd/lp/client/cancel/Makefile +# + +include ../Makefile.sp + +PROG= cancel + +SRCS= cancel.c cancel_list.c + +OBJS= $(SRCS:.c=.o) + +ROOTBINPROG= $(PROG:%=$(ROOTBIN)/%) +ROOTUSRBINSYMLINK= $(ROOTUSRUCB)/lprm + +FILEMODE= 04511 +OWNER= root + +CPPFLAGS += -I. -I$(NPRTINC) #$(CPPFLAGS.master) +LDLIBS += $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +install: all $(ROOTBIN) $(ROOTBINPROG) $(ROOTUSRBINSYMLINK) + +$(ROOTBIN): + $(INS.dir) + +$(ROOTUSRBINSYMLINK): + $(RM) $@; $(SYMLINK) ../bin/$(PROG) $@ + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(SRCS) $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) + diff --git a/usr/src/cmd/print/cancel/cancel.c b/usr/src/cmd/print/cancel/cancel.c new file mode 100644 index 0000000000..e57ce16dad --- /dev/null +++ b/usr/src/cmd/print/cancel/cancel.c @@ -0,0 +1,377 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <stdarg.h> +#include <unistd.h> +#include <string.h> +#include <syslog.h> +#include <ctype.h> +#include <locale.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/list.h> +#include <print/job.h> + +#include <cancel_list.h> + +extern char *optarg; +extern int optind, opterr, optopt, exit_code = 0; +extern char *getenv(const char *); + +static int all = 0; /* global for canceling everything */ + + + +static char * +vappend_list(void ** list) +{ + int current = 0; + char * string; + int stringlen; + int listlen; + int strsize = BUFSIZ; + + + string = malloc(strsize); + (void) memset(string, NULL, sizeof (string)); + + if (list != NULL) { + while (list[current] != NULL) { + stringlen = strlen(string); + listlen = strlen(list[current]); + if (strsize < (stringlen + listlen + 2)) { + strsize = stringlen + listlen + 2; + string = realloc(string, strsize); + } + + (void) strcat(string, " "); + (void) strcat(string, list[current]); + current++; + } + } + + return (string); +} + + +/* + * vcancel_local() attempts to cancel all locally spooled jobs that are + * are associated with a cancel_req_t structure. This function is + * intended to be called by list_iterate(). + */ +static int +vcancel_local(cancel_req_t *entry, va_list ap) +{ + char *user = va_arg(ap, char *); + job_t **list = NULL; + + list = job_list_append(list, entry->binding->printer, + entry->binding->server, SPOOL_DIR); + return (list_iterate((void **)list, (VFUNC_T)vjob_cancel, user, + entry->binding->printer, entry->binding->server, + entry->list)); +} + + +/* + * vcancel_remote() attempts to send a cancel request to a print server + * for any jobs that might be associated with the cancel_req_t structure + * passed in. This function is intended to be called by list_iterate(). + */ +static int +vcancel_remote(cancel_req_t *entry, va_list ap) +{ + char buf[BUFSIZ], + *user = va_arg(ap, char *), + *printer = entry->binding->printer, + *server = entry->binding->server; + int nd, + rc; + char * string; + + if ((nd = net_open(server, 15)) < 0) { + (void) fprintf(stderr, + gettext("could not talk to print service at %s\n"), + server); + return (-1); + } + + (void) memset(buf, NULL, sizeof (buf)); + + if (strcmp(user, "-all") != 0) + string = vappend_list((void *)entry->list); + + syslog(LOG_DEBUG, "vcancel_remote(): %s %s%s", printer, user, string); + rc = net_printf(nd, "%c%s %s%s\n", REMOVE_REQUEST, printer, user, + string); + if (rc < 0) + syslog(LOG_ERR, "net_printf() failed: %m"); + + while (memset(buf, NULL, sizeof (buf)) && + (net_read(nd, buf, sizeof (buf)) > 0)) + (void) printf("%s", buf); + + (void) net_close(nd); + return (0); +} + + +/* + * vsysv_printer() adds an entry to the cancel list with the items supplied. + */ +static void +vsysv_printer(char *printer, va_list ap) +{ + cancel_req_t ***list = va_arg(ap, cancel_req_t ***); + char **items = va_arg(ap, char **); + + *list = cancel_list_add_list(*list, printer, items); +} + +/* + * vsysv_binding() adds an entry to the cancel list with the items supplied. + */ +static void +vsysv_binding(ns_bsd_addr_t *binding, va_list ap) +{ + cancel_req_t ***list = va_arg(ap, cancel_req_t ***); + char **items = va_arg(ap, char **); + + *list = cancel_list_add_binding_list(*list, binding, items); +} + +/* + * sysv_remove() parses the command line arguments as defined for cancel + * and builds a list of cancel_req_t structures to return + */ +static cancel_req_t ** +sysv_remove(int ac, char **av) +{ + char *printer, + **printers = NULL, + **items = NULL; + int c; + int user = 0; + cancel_req_t **list = NULL; + + if (ac == 1) { + (void) fprintf(stderr, + gettext("printer, request-id, and/or user required\n")); + exit(-1); + } + + if ((printer = getenv((const char *)"LPDEST")) == NULL) + printer = getenv((const char *)"PRINTER"); + if (printer == NULL) + printer = NS_NAME_DEFAULT; + + while ((c = getopt(ac, av, "u")) != EOF) + switch (c) { + case 'u': + user++; + break; + default: + (void) fprintf(stderr, + "Usage:\t%s [-u user-list] [printer-list]\n", av[0]); + (void) fprintf(stderr, + "\t%s [request-list] [printer-list]\n", av[0]); + exit(-1); + } + + ac--; + while (optind <= ac) { /* pull printers off */ + char *p, + *q; + + if (((p = strrchr(av[ac], ':')) != NULL) && + ((q = strrchr(p, '-')) != NULL)) { + int req = 0; + while (*++q != NULL) + if (isdigit(*q) == 0) + req++; + if (req == 0) + break; + } + if ((ns_bsd_addr_get_name(av[ac])) != NULL) { + printers = (char **)list_append((void **)printers, + (void *)av[ac]); + } else + break; + ac--; + } + + while (optind <= ac) { /* get reqs or users */ + if (user != 0) { /* list o users */ + items = (char **)list_append((void **)items, + (void *)av[ac]); + } else { /* list o jobs */ + char *p; + + if ((p = strrchr(av[ac], '-')) != NULL) { /* job-id */ + *(p++) = NULL; + if (*p == NULL) { + (void) fprintf(stderr, + gettext("invalid job id: %s-\n"), + av[ac]); + exit(-1); + } + list = cancel_list_add_item(list, av[ac], p); + } else { /* just a number */ + list = cancel_list_add_item(list, av[ac], NULL); + } + } + ac--; + } + + if ((printers == NULL) && (items != NULL)) { /* handle "all" printers */ + ns_bsd_addr_t **addrs = NULL; + + if ((addrs = ns_bsd_addr_get_all(UNIQUE)) != NULL) + (void) list_iterate((void **)addrs, + (VFUNC_T)vsysv_binding, &list, items); + } + + if ((list == NULL) && (items == NULL)) + items = (char **)list_append((void **)items, NULL); + + (void) list_iterate((void **)printers, (VFUNC_T)vsysv_printer, + &list, items); + + return (list); +} + + +/* + * bsd_remove() parses the command line arguments as defined for lprm + * and builds a list of cancel_req_t structures to return + */ +static cancel_req_t ** +bsd_remove(int ac, char **av) +{ + char *printer; + int c; + cancel_req_t **list = NULL; + + if ((printer = getenv((const char *)"PRINTER")) == NULL) + printer = getenv((const char *)"LPDEST"); + if (printer == NULL) + printer = NS_NAME_DEFAULT; + + while ((c = getopt(ac, av, "P:-")) != EOF) + switch (c) { + case 'P': + printer = optarg; + break; + default: + (void) fprintf(stderr, + gettext("Usage: %s [-P printer] [-] [job # ...] [username ...]\n"), + av[0]); + exit(-1); + } + + while (optind < ac) + if (strcmp(av[optind++], "-") == 0) { + if (getuid() == 0) { + all = 1; + list = cancel_list_add_item(list, printer, + "-all"); + } else { + list = cancel_list_add_item(list, printer, + get_user_name()); + } + } else { + list = cancel_list_add_item(list, printer, + av[optind-1]); + } + + if (list == NULL) + list = cancel_list_add_item(list, printer, NULL); + + return (list); +} + + +/* + * main() calls the appropriate routine to parse the command line arguments + * and then calls the local remove routine, followed by the remote remove + * routine to remove jobs. + */ +int +main(int ac, char *av[]) +{ + int rc = 0; + char *program; + cancel_req_t **list = NULL; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + openlog(program, LOG_PID, LOG_LPR); + + if (check_client_spool(NULL) < 0) { + (void) fprintf(stderr, + gettext("couldn't validate local spool area (%s)\n"), + SPOOL_DIR); + return (-1); + } + + if (strcmp(program, "lprm") == 0) + list = bsd_remove(ac, av); + else + list = sysv_remove(ac, av); + + (void) chdir(SPOOL_DIR); + if (list_iterate((void **)list, (VFUNC_T)vcancel_local, + get_user_name()) != 0) + start_daemon(1); + + rc = list_iterate((void **)list, (VFUNC_T)vcancel_remote, + ((all == 0) ? get_user_name() : "-all")); + + if (exit_code == 0) + exit_code = rc; + + return (exit_code); +} diff --git a/usr/src/cmd/print/cancel/cancel_list.c b/usr/src/cmd/print/cancel/cancel_list.c new file mode 100644 index 0000000000..d9ad68ebab --- /dev/null +++ b/usr/src/cmd/print/cancel/cancel_list.c @@ -0,0 +1,185 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 1998-2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <stdarg.h> +#include <string.h> +#include <syslog.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/list.h> +#include <print/job.h> + +#include <cancel_list.h> + + +/* + * printer_compair() compares the printer name in the cancel request and the + * printer name passed in. If they match, 0 is returned. + */ +static int +printer_compair(cancel_req_t *cancel, char *printer) +{ + return (strcmp(cancel->printer, printer)); +} + +/* + * binding_compair() compares the binding in the cancel request and the + * binding passed in. If they match, 0 is returned. + */ +static int +binding_compair(cancel_req_t *cancel, ns_bsd_addr_t *binding) +{ + return (strcmp(cancel->binding->printer, binding->printer) || + strcmp(cancel->binding->server, binding->server)); +} + + +/* + * cancel_list_element() adds information to the cancel list. It either adds + * information to an existing cancel entry if the printers match, or + * adds a new entry to the cancel list. It returns the new list in either + * case. + */ +static cancel_req_t * +cancel_list_element(cancel_req_t ***list, char *printer) +{ + cancel_req_t *element = NULL; + + if ((element = (cancel_req_t *)list_locate((void **)*list, + (COMP_T)printer_compair, (void *)printer)) == NULL) { + if ((element = calloc(1, sizeof (*element))) != NULL) { + if ((element->binding = ns_bsd_addr_get_name(printer)) + == NULL) { + extern int exit_code; + + free(element); + if (strcmp(printer, NS_NAME_DEFAULT) == 0) + (void) fprintf(stderr, gettext( + "No default destination\n")); + else + (void) fprintf(stderr, gettext( + "%s: unknown printer\n"), + printer); + exit_code = -1; + return (NULL); + } + element->printer = strdup(printer); + *list = (cancel_req_t **)list_append((void **)*list, + (void *)element); + } + } + + return (element); +} + + +/* + * cancel_list_element_by_binding() returns an element in the cancel list + * passed in that matches the binding passed in. If none exists, then + * one is created, inserted and returned. + */ +static cancel_req_t * +cancel_list_element_by_binding(cancel_req_t ***list, ns_bsd_addr_t *binding) +{ + cancel_req_t *element = NULL; + + if ((element = (cancel_req_t *)list_locate((void **)*list, + (COMP_T)binding_compair, (void *)binding)) == NULL) { + if ((element = calloc(1, sizeof (*element))) != NULL) { + element->printer = strdup(binding->printer); + element->binding = binding; + *list = (cancel_req_t **)list_append((void **)*list, + (void *)element); + } + } + + return (element); +} + + +/* + * cancel_list_add_item() adds information to the cancel list. It either adds + * information to an existing cancel entry if the printers match, or + * adds a new entry to the cancel list. It returns the new list in either + * case. + */ +cancel_req_t ** +cancel_list_add_item(cancel_req_t **list, char *printer, char *item) +{ + cancel_req_t *element = NULL; + + if ((element = cancel_list_element(&list, printer)) != NULL) + element->list = (char **)list_append((void **)element->list, + (void *)item); + return (list); +} + + +/* + * cancel_list_add_list() adds information to the cancel list. It either adds + * information to an existing cancel entry if the printers match, or + * adds a new entry to the cancel list. It returns the new list in either + * case. + */ +cancel_req_t ** +cancel_list_add_list(cancel_req_t **list, char *printer, char **items) +{ + cancel_req_t *element = NULL; + + if ((element = cancel_list_element(&list, printer)) != NULL) + element->list = (char **)list_concatenate( + (void **)element->list, (void **)items); + return (list); +} + + +/* + * cancel_list_add_binding_list() adds information to the cancel list. It + * either adds information to an existing cancel entry if the bindings + * match, or adds a new entry to the cancel list. It returns the new + * list in either case. + */ +cancel_req_t ** +cancel_list_add_binding_list(cancel_req_t **list, ns_bsd_addr_t *binding, + char **items) +{ + cancel_req_t *element = NULL; + + if ((element = cancel_list_element_by_binding(&list, binding)) != NULL) + element->list = (char **)list_concatenate( + (void **)element->list, (void **)items); + return (list); +} diff --git a/usr/src/cmd/print/cancel/cancel_list.h b/usr/src/cmd/print/cancel/cancel_list.h new file mode 100644 index 0000000000..d535e0f3ff --- /dev/null +++ b/usr/src/cmd/print/cancel/cancel_list.h @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ifndef _CANCEL_LIST_H +#define _CANCEL_LIST_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _cancel_req cancel_req_t; +struct _cancel_req { + char *printer; + ns_bsd_addr_t *binding; + char **list; +}; + +extern cancel_req_t ** cancel_list_add_item(cancel_req_t **list, char *printer, + char *item); +extern cancel_req_t ** cancel_list_add_list(cancel_req_t **list, char *printer, + char **items); +extern cancel_req_t ** cancel_list_add_binding_list(cancel_req_t **list, + ns_bsd_addr_t *binding, char **items); + +#ifdef __cplusplus +} +#endif + +#endif /* _CANCEL_LIST_H */ diff --git a/usr/src/cmd/print/conv_fix/Makefile b/usr/src/cmd/print/conv_fix/Makefile new file mode 100644 index 0000000000..6bce653454 --- /dev/null +++ b/usr/src/cmd/print/conv_fix/Makefile @@ -0,0 +1,71 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994,1998,2001 by Sun Microsystems, Inc. +# All rights reserved. +# +#ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/client/conv_fix/Makefile +# + +include ../Makefile.sp + +PROG= conv_fix + +SRCS= $(PROG).c + +OBJS= $(SRCS:.c=.o) + +ROOTLIBPRINTPROG= $(PROG:%=$(ROOTLIBPRINT)/%) + +FILEMODE= 0555 +OWNER= root + +CPPFLAGS += -I$(NPRTINC) + +.KEEP_STATE: + +all: $(PROG) + +install: all $(ROOTLIBPRINTPROG) + +$(ROOTLIBPRINT)/%: % + $(INS.file) + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(PROG).c $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) diff --git a/usr/src/cmd/print/conv_fix/conv_fix.c b/usr/src/cmd/print/conv_fix/conv_fix.c new file mode 100644 index 0000000000..d0829c79dd --- /dev/null +++ b/usr/src/cmd/print/conv_fix/conv_fix.c @@ -0,0 +1,148 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 1999-2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <locale.h> +#include <sys/file.h> +#include <fcntl.h> +#include <errno.h> + +extern char *optarg; + +/* + * FUNCTION: + * static char *_file_getline(FILE *fp) + * INPUT: + * FILE *fp - file pointer to read from + * OUTPUT: + * char *(return) - an entry from the stream + * DESCRIPTION: + * This routine will read in a line at a time. If the line ends in a + * newline, it returns. If the line ends in a backslash newline, it + * continues reading more. It will ignore lines that start in # or + * blank lines. + */ +static char * +_file_getline(FILE *fp) +{ + char entry[BUFSIZ], *tmp; + int size; + + size = sizeof (entry); + tmp = entry; + + /* find an entry */ + while (fgets(tmp, size, fp)) { + if ((tmp == entry) && ((*tmp == '#') || (*tmp == '\n'))) { + continue; + } else { + if ((*tmp == '#') || (*tmp == '\n')) { + *tmp = NULL; + break; + } + + size -= strlen(tmp); + tmp += strlen(tmp); + + if (*(tmp-2) != '\\') + break; + + size -= 2; + tmp -= 2; + } + } + + if (tmp == entry) + return (NULL); + else + return (strdup(entry)); +} + +main(int ac, char *av[]) +{ + int c; + char file[80], ofile[80]; + char *cp; + FILE *fp, *fp2; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + while ((c = getopt(ac, av, "f:o:")) != EOF) + + switch (c) { + case 'f': + (void) strlcpy(file, optarg, sizeof (file)); + break; + case 'o': + (void) strlcpy(ofile, optarg, sizeof (ofile)); + break; + default: + (void) fprintf(stderr, + gettext("Usage: %s [-f file] [-o output file]\n"), + av[0]); + return (1); + } + + if ((fp = fopen(file, "r")) != NULL) { + int fd; + + fd = open(ofile, O_RDWR|O_APPEND); + if ((fd < 0) && (errno == ENOENT)) + fd = open(ofile, O_RDWR|O_CREAT|O_EXCL, 0644); + + if (fd < 0) { + (void) fprintf(stderr, + gettext("Error trying to open file.\n")); + return (1); + } + + lseek(fd, 0, SEEK_END); + + if ((fp2 = fdopen(fd, "a")) != NULL) { + while ((cp = _file_getline(fp)) != NULL) { + (void) fprintf(fp2, "%s", cp); + } + return (0); + } else { + (void) fprintf(stderr, + gettext("Error trying to open file.\n")); + return (1); + } + } else { + (void) fprintf(stderr, + gettext("Error trying to open file.\n")); + return (1); + } +} diff --git a/usr/src/cmd/print/gateway/Makefile b/usr/src/cmd/print/gateway/Makefile new file mode 100644 index 0000000000..854e08ea98 --- /dev/null +++ b/usr/src/cmd/print/gateway/Makefile @@ -0,0 +1,85 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# pragma ident "%Z%%M% %I% %E% SMI" +# +# server/gateway/adaptor/Makefile +# + +include ../Makefile.sp + +MANIFEST= rfc1179.xml + +ROOTMANIFESTDIR= $(ROOTSVCAPPLICATIONPRINT) +$(ROOTMANIFEST) := FILEMODE= 444 + +SUBDIRS= translators + +PROG= in.lpd + +SRCS= main.c adaptor.c + +OBJS= $(SRCS:.c=.o) + + +FILEMODE= 0555 +OWNER= root +GROUP= bin + + +CPPFLAGS += -I. -I$(NPRTINC) #$(CPPFLAGS.master) +LDLIBS += -lsocket -lnsl $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) $(SUBDIRS) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +install: all $(ROOTLIBPRINTPROG) $(SUBDIRS) $(ROOTMANIFEST) + +check: $(CHKMANIFEST) + +strip: $(SUBDIRS) + $(STRIP) $(PROG) + +cstyle: + cstyle $(SRCS) + +lint: + $(LINT.c) $(SRCS) $(LDLIBS) + +clean clobber: $(SUBDIRS) + $(RM) $(OBJS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/gateway/adaptor.c b/usr/src/cmd/print/gateway/adaptor.c new file mode 100644 index 0000000000..ebe6aa97a0 --- /dev/null +++ b/usr/src/cmd/print/gateway/adaptor.c @@ -0,0 +1,360 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998-2001 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <string.h> +#include <errno.h> +#include <dlfcn.h> +#include <sys/systeminfo.h> + +#include <syslog.h> + +#include <adaptor.h> +#include <print/ns.h> + +#ifndef RTLD_GLOBAL /* for OSF/1 */ +#define RTLD_GLOBAL 0 +#endif + +/* + * This file contains the implementation of the API used by the front half + * of the BSD Print protocol adaptor to select and glue in the back half of + * the print protocol adaptor dynamically. Most of the functions in this + * file are hollow shells that pick a back end, load it, and call the "real" + * function from the loaded object, with the arguments passed in. The loaded + * functions have the naming convention {paradigm}_{function}. + * These functions are in NO WAY MT-Safe. They are intended to be used by + * a single threaded adaptor, that is/may be called via inetd concurrently. + */ + + +static void *paradigm_handle = NULL; +static char *paradigm_name = NULL; +static int paradigm_version = -1; +static ns_printer_t *printer_object = NULL; +static char *primary_name = NULL; + +static int +is_localhost(char *name) +{ + char buf[BUFSIZ]; + + if (name == NULL) + return (0); + + if (strcasecmp(name, "localhost") == 0) + return (0); + + (void) sysinfo(SI_HOSTNAME, buf, sizeof (buf)); + + return (strcasecmp(name, buf)); +} + +int +syn_name(const char *str) +{ + register char *p; + + if (!str || !*str) + return (0); + + if (strlen(str) > (size_t)14) + return (0); + + for (p = (char *)str; *p; p++) + if (!isalnum(*p) && *p != '_' && *p != '-') + return (0); + + return (1); +} + +/* + * A hack for performance. This will look for a local LP based printer in + * the most efficient manner. If found, it will circumvent all future + * adaptor resolution and load the default lpsched translation module. + */ +static int +lpsched_adaptor_available(const char *printer) +{ + char buf[BUFSIZ], buf2[BUFSIZ]; + + syslog(LOG_DEBUG, "in.lpd:lpsched_adaptor_available: entry\n"); + + if (!syn_name(printer)) + return (-1); + + (void) snprintf(buf, sizeof (buf), "/etc/lp/interfaces/%s", printer); + (void) snprintf(buf2, sizeof (buf2), "/etc/lp/classes/%s", printer); + syslog(LOG_DEBUG, + "in.lpd:lpsched_adaptor_available: printer is %s\n", + printer); + if ((access(buf, F_OK) < 0) && (access(buf2, F_OK) < 0)) + return (-1); + + syslog(LOG_DEBUG, + "in.lpd:lpsched_adaptor_available: printer %s local\n", + printer); + + paradigm_handle = dlopen("/usr/lib/print/bsd-adaptor/bsd_lpsched.so", + RTLD_NOW|RTLD_GLOBAL); + if (paradigm_handle == NULL) + return (-1); + + paradigm_name = LPSCHED; + return (0); +} + +/* + * adaptor_avaliable() takes in the name of a printer, looks it up in the + * name service, and dynamically loads backend support for the print paradigm + * the printer is defined in. If the printer is undefined, UNDEFINED is + * returned. If the spooling paradigm is not defined, and the printer is + * remote, a "cascade" capability is loaded. + */ +int +adaptor_available(const char *printer) +{ + char *path, + *dir, + *tmp, + *tmp_path; + ns_bsd_addr_t *addr; + + /* + * for performance, check lpsched first and foremost. This will + * hide any NS information if there is an LP configuration, valid + * or not. + */ + if (lpsched_adaptor_available(printer) == 0) + return (0); + + errno = 0; + if (((printer_object = ns_printer_get_name(printer, + NS_SVC_ETC)) == NULL) && + (endprinterentry() == 0) && + ((printer_object = ns_printer_get_name(printer, NULL)) == NULL)) { + errno = ENOENT; + return (-1); + } + + if ((addr = ns_get_value(NS_KEY_BSDADDR, printer_object)) != NULL) + primary_name = addr->printer; + + if ((paradigm_name = ns_get_value_string(NS_KEY_ADAPTOR_NAME, + printer_object)) == NULL) { + if ((addr != NULL) && (is_localhost(addr->server) == 0)) + paradigm_name = LPSCHED; + else + paradigm_name = CASCADE; + } + + if ((tmp = strrchr(paradigm_name, ',')) != NULL) { + *tmp++ = NULL; + paradigm_version = atoi(tmp); + } + + if ((path = ns_get_value_string(NS_KEY_ADAPTOR_PATH, printer_object)) + == NULL) + path = ADAPTOR_PATH; + + tmp_path = strdup(path); + for (dir = strtok(tmp_path, ":,"); dir != NULL; + dir = strtok(NULL, ":,")) { + static char object[BUFSIZ]; + + if (paradigm_version < 0) + (void) snprintf(object, sizeof (object), "%s/bsd_%s.so", + dir, paradigm_name); + else + (void) snprintf(object, sizeof (object), + "%s/bsd_%s.so.%d", dir, paradigm_name, + paradigm_version); + if ((paradigm_handle = dlopen(object, RTLD_NOW|RTLD_GLOBAL)) + != NULL) + break; +#ifdef DEBUG + syslog(LOG_DEBUG, "dlopen(%d): %s", object, dlerror()); +#endif + } + free(tmp_path); + + return (paradigm_handle == NULL); +} + + +static void * +adaptor_function(const char *paradigm, const char *function) +{ + char name[128]; + void *fpt = NULL; + + if (paradigm_handle == NULL) + return (NULL); + + (void) snprintf(name, sizeof (name), "%s_%s", paradigm, function); + if ((fpt = dlsym(paradigm_handle, name)) == NULL) + syslog(LOG_ERR, "could not locate function: %s()", name); + + return (fpt); +} + + +int +adaptor_spooler_available(const char *printer) +{ + static int (*fpt)() = NULL; + + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "spooler_available")) != NULL)) + /* + * in the case of cascading, + * use the local name of the printer + */ + if (strcmp(paradigm_name, "cascade") == 0) + return ((int)(fpt)(printer)); + else + return ((int)(fpt) + (primary_name ? primary_name : printer)); + + return (-1); +} + + +int +adaptor_spooler_accepting_jobs(const char *printer) +{ + static int (*fpt)() = NULL; + + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "spooler_accepting_jobs")) != NULL)) + return ((int)(fpt)(primary_name ? primary_name : printer)); + + return (-1); +} + + +int +adaptor_client_access(const char *printer, const char *host) +{ + static int (*fpt)() = NULL; + + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "client_access")) != NULL)) + return ((int)(fpt)((primary_name ? primary_name : printer), + host)); + + return (-1); +} + + +int +adaptor_restart_printer(const char *printer) +{ + static int (*fpt)() = NULL; + + /* need a cast */ + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "restart_printer")) != NULL)) + return ((int)(fpt)(primary_name ? primary_name : printer)); + + return (-1); +} + + +char * +adaptor_temp_dir(const char *printer, const char *host) +{ + static char *(*fpt)() = NULL; + + /* need a cast */ + if ((fpt != NULL) || + ((fpt = (char *(*)())adaptor_function(paradigm_name, + "temp_dir")) != NULL)) + return ((char *)(fpt)((primary_name ? primary_name : printer), + host)); + + return (NULL); +} + + +int +adaptor_submit_job(const char *printer, const char *host, char *cf, + char **df_list) +{ + static int (*fpt)() = NULL; + + /* need a cast */ + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "submit_job")) != NULL)) + return ((int)(fpt)((primary_name ? primary_name : printer), + host, cf, df_list)); + + return (-1); +} + + +int +adaptor_show_queue(const char *printer, FILE *ofp, const int type, + char **list) +{ + static int (*fpt)() = NULL; + + /* need a cast */ + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "show_queue")) != NULL)) + return ((int)(fpt)((primary_name ? primary_name : printer), + ofp, type, list)); + + return (-1); +} + + +int +adaptor_cancel_job(const char *printer, FILE *ofp, const char *user, + const char *host, char **list) +{ + static int (*fpt)() = NULL; + + /* need a cast */ + if ((fpt != NULL) || + ((fpt = (int (*)())adaptor_function(paradigm_name, + "cancel_job")) != NULL)) + return ((int)(fpt)((primary_name ? primary_name : printer), + ofp, user, host, list)); + + return (-1); +} diff --git a/usr/src/cmd/print/gateway/adaptor.h b/usr/src/cmd/print/gateway/adaptor.h new file mode 100644 index 0000000000..a717c77ffc --- /dev/null +++ b/usr/src/cmd/print/gateway/adaptor.h @@ -0,0 +1,65 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ifndef _ADAPTOR_H +#define _ADAPTOR_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * The API used by the BSD print protocol adaptor to glue the front end + * request receiving code to the back end request fufilling code. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define ADAPTOR_PATH "/etc/print/bsd-adaptor,/usr/lib/print/bsd-adaptor" +#define NS_KEY_ADAPTOR_PATH "spooling-type-path" +#define NS_KEY_ADAPTOR_NAME "spooling-type" +#define CASCADE "cascade" +#define LPSCHED "lpsched" + +extern int adaptor_available(const char *printer); +extern int adaptor_spooler_available(const char *printer); +extern int adaptor_spooler_accepting_jobs(const char *printer); +extern int adaptor_client_access(const char *printer, const char *host); +extern int adaptor_restart_printer(const char *printer); +extern char *adaptor_temp_dir(const char *printer, const char *host); +extern int adaptor_submit_job(const char *printer, const char *host, + char *cf, char **df_list); +extern int adaptor_show_queue(const char *printer, FILE *ofp, + const int type, char **list); +extern int adaptor_cancel_job(const char *printer, FILE *ofp, + const char *user, const char *host, + char **list); + +#ifdef __cplusplus +} +#endif + +#endif /* _ADAPTOR_H */ diff --git a/usr/src/cmd/print/gateway/main.c b/usr/src/cmd/print/gateway/main.c new file mode 100644 index 0000000000..fd9dd13c4b --- /dev/null +++ b/usr/src/cmd/print/gateway/main.c @@ -0,0 +1,612 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libintl.h> +#include <sys/systeminfo.h> + +#include <ctype.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> + +#include <fcntl.h> +#include <sys/mman.h> + +#include <string.h> +#include <syslog.h> +#include <errno.h> +#include <libintl.h> + +#include <adaptor.h> + + +#define ACK(fp) { (void) fputc(NULL, fp); (void) fflush(fp); } +#define NACK(fp) { (void) fputc('\001', 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. + */ + +/* + * 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. + */ +static char ** +strsplit(char *string, const char *seperators) +{ + char *list[BUFSIZ], + **result; + int length = 0; + + if ((string == NULL) || (seperators == NULL)) + return (NULL); + + (void) memset(list, NULL, 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); +} + + +/* + * remote_host_name() gets the hostname of the "peer" on the socket + * connection. + */ +static char * +remote_host_name(FILE *fp) +{ + struct hostent *hp; + struct sockaddr_in6 peer; + socklen_t peer_len = sizeof (peer); + int fd = fileno(fp); + int error_num; + char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN]; + char *hostname; + + (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname)); + + /* who is our peer ? */ + if (getpeername(fd, (struct sockaddr *)&peer, &peer_len) < 0) { + if ((errno != ENOTSOCK) && (errno != EINVAL)) + return (NULL); + else + return (strdup(myname)); + } + + /* get their name or return a string containing their address */ + if ((hp = getipnodebyaddr((const char *)&peer.sin6_addr, + sizeof (struct in6_addr), AF_INET6, + &error_num)) == NULL) { + return (strdup(inet_ntop(peer.sin6_family, + &peer.sin6_addr, tmp_buf, sizeof (tmp_buf)))); + } + + /* is it "localhost" ? */ + if (strcasecmp(hp->h_name, "localhost") == 0) + return (strdup(myname)); + + /* duplicate the name because gethostbyXXXX() is not reentrant */ + hostname = strdup(hp->h_name); + + /* is it from one of my addresses ? */ + if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED, + &error_num)) != NULL) { + struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; + int i = 0; + + while (tmp[i] != NULL) { + if (memcmp(tmp[i++], &peer.sin6_addr, hp->h_length) + == 0) { + free(hostname); + return (strdup(myname)); + } + } + } + + /* It must be someone else */ + return (hostname); +} + + +static int +request_id_no(const char *filename) +{ + int id = -1; + + /* get the first number embedded in the string */ + while ((filename != NULL) && (*filename != NULL) && + (isdigit(*filename) == 0)) + filename++; + + if ((filename != NULL) && (*filename != NULL)) + id = atoi(filename); + + return (id); +} + + +static void +abort_transfer(char **files) +{ + syslog(LOG_DEBUG, "abort_transfer()"); + while ((files != NULL) && (*files != NULL)) + (void) unlink(*files++); +} + +static int lock_fd = -1; +static int lock_job_id = -1; + +static void +unlock_job() +{ + syslog(LOG_DEBUG, "unlock_job(): fd = %d, id = %d\n", lock_fd, + lock_job_id); + if (lock_fd != -1) { + char name[12]; + + snprintf(name, sizeof (name), "%d", lock_job_id); + unlink(name); + close(lock_fd); + lock_fd = -1; + lock_job_id = -1; + } +} + + +static void +lock_job(int job_id) +{ + int try = 5; + char name[12]; + + syslog(LOG_DEBUG, "lock_job(%d): fd = %d, id = %d\n", job_id, lock_fd, + lock_job_id); + if ((lock_job_id != -1) && (lock_job_id != job_id)) + unlock_job(); + + snprintf(name, sizeof (name), "%d", job_id); + while ((try > 0) && (lock_fd < 0)) { + if ((lock_fd = open(name, O_CREAT|O_EXCL|O_WRONLY, 0600)) < 0) { + if (errno == EEXIST) { + sleep(3); + lock_fd = open(name, O_WRONLY); + } + } + try--; + } + + if (lockf(lock_fd, F_LOCK, 0) < 0) { + syslog(LOG_DEBUG|LOG_INFO, + "failed to lock job: %d, file(%s), fd(%d): %m", + job_id, name, lock_fd); + close(lock_fd); + unlink(name); + job_id = lock_fd = -1; + } + + lock_job_id = job_id; +} + + +/* + * transfer_job() retrieves jobs being sent from a remote system and + * submits them as they are completely received. + */ +static int +transfer_job(const char *printer, const char *host, FILE *ifp, + FILE *ofp) +{ + char buf[BUFSIZ], + *tmp; + char *cf = NULL; + char *df_list[64]; /* don't allow more that 64 files */ + int file_no = 0; + int current_request = -1; + int tmp_id; + int psize; + + + (void) memset(&df_list, NULL, sizeof (df_list)); + + if (adaptor_spooler_accepting_jobs(printer) < 0) { + syslog(LOG_DEBUG, + "attempt to transfer job(s) to disabled printer" + " or unknown printer %s", printer); + return (-1); + } + + ACK(ofp); + /* start to receive job(s) */ + while (fgets(buf, sizeof (buf), ifp) != NULL) { + int size = 0; + char *name = NULL; + char *ptr; + int fd; + int count; + + /* + * When receiving jobs, buf[0] can only be 1,2 or 3 + * Anything else, abort transfer - rfc1179 + */ + if ((buf[0] < 1 || buf[0] > 3)) { + syslog(LOG_ERR, + "protocol error - bad message from client"); + syslog(LOG_DEBUG, "control file contained: (%s)", + (cf ? cf : "NULL")); + abort_transfer(df_list); + unlock_job(); + return (-1); + } + + if (strlen(&buf[1]) == 0) /* just a null */ + continue; + + count = size = atoi(strtok(&buf[1], "\n\t ")); + if ((tmp = strtok(NULL, "\n\t ")) != NULL) { + if ((name = strrchr(tmp, '/')) != NULL) { + /* for security */ + syslog(LOG_INFO|LOG_NOTICE, + "Attempt to tranfer Absolute path: %s", + tmp); + name++; + } else + name = tmp; + + tmp_id = request_id_no(name); + if ((cf != NULL) && (df_list[0] != NULL) && + (tmp_id != current_request)) { + if (adaptor_submit_job(printer, host, cf, + df_list) != 0) { + abort_transfer(df_list); + unlock_job(); + return (-1); + } + while (file_no-- > 0) + free(df_list[file_no]); + (void) memset(df_list, NULL, sizeof (df_list)); + file_no = 0; + free(cf); + cf = NULL; + } + if (tmp_id != current_request) + lock_job(tmp_id); + + } else if (buf[0] != 1) { + syslog(LOG_ERR, "Bad xfer message(%d), no file name", + buf[0]); + abort_transfer(df_list); + unlock_job(); + return (-1); + } + current_request = tmp_id; + tmp = NULL; + + switch (buf[0]) { + case '\1': /* Abort Transfer */ + /* remove files on file_list */ + abort_transfer(df_list); + unlock_job(); + return (-1); + case '\2': /* Transfer Control File */ + syslog(LOG_DEBUG, "control(%s, %d)", name, size); + if ((cf = malloc(size + 1)) == NULL) { + NACK(ofp); + break; + } + (void) memset(cf, NULL, size + 1); + ACK(ofp); + ptr = cf; + while (count > 0) + if (((fd = fread(ptr, 1, count, ifp)) == 0) && + (feof(ifp) != 0)) { + syslog(LOG_DEBUG, + "connection closed(%s): %m", + name); + abort_transfer(df_list); + unlock_job(); + return (-1); + } else { + ptr += fd; + count -= fd; + } + if (fgetc(ifp) != 0) { /* get ACK/NACK */ + abort_transfer(df_list); + unlock_job(); + return (-1); + } + ACK(ofp); + break; + case '\3': /* Transfer Data File */ + syslog(LOG_DEBUG, "data(%s, %d)", name, size); + if ((fd = open(name, O_RDWR|O_TRUNC|O_CREAT|O_EXCL, + 0640)) < 0) { + syslog(LOG_ERR, "open(%s): %m", name); + abort_transfer(df_list); + unlock_job(); + NACK(ofp); + return (-1); + } + if (ftruncate(fd, size) < 0) { + syslog(LOG_ERR, "ftruncate(%s): %m", name); + (void) close(fd); + (void) unlink(name); + abort_transfer(df_list); + unlock_job(); + NACK(ofp); + return (-1); + } + if ((size > 0) && + ((tmp = mmap((caddr_t)0, (size_t)size, + PROT_READ|PROT_WRITE, + (MAP_SHARED | MAP_NORESERVE), + fd, (off_t)0)) == (char *)MAP_FAILED)) { + syslog(LOG_ERR, "mmap(%d, %d): %m", size, fd); + (void) close(fd); + (void) unlink(name); + abort_transfer(df_list); + unlock_job(); + NACK(ofp); + return (-1); + } + + /* Make sure that there is adequate space */ + if ((psize = pwrite(fd, tmp, size, 0)) < size) { + syslog(LOG_ERR, + "pwrite(,, %d ,) returns:(%d) %m", + size, psize); + (void) close(fd); + (void) unlink(name); + (void) munmap(tmp, size); + abort_transfer(df_list); + unlock_job(); + NACK(ofp); + return (-1); + } + (void) close(fd); + ACK(ofp); + ptr = tmp; + while (count > 0) + if (((fd = fread(ptr, 1, count, ifp)) == 0) && + (feof(ifp) != 0)) { + syslog(LOG_DEBUG, + "connection closed(%s): %m", + name); + unlink(name); + abort_transfer(df_list); + unlock_job(); + return (-1); + } else { + ptr += fd; + count -= fd; + } + (void) munmap(tmp, size); + if (fgetc(ifp) != 0) { /* get ACK/NACK */ + unlink(name); + abort_transfer(df_list); + unlock_job(); + return (-1); + } + /* + * make sure we don't overflow df_list. + */ + if (file_no >= sizeof (df_list)/sizeof (df_list[0])) { + syslog(LOG_ALERT|LOG_AUTH, + "prevented in.lpd exploit from host %s", + host); + unlink(name); + abort_transfer(df_list); + return (-1); + } + + df_list[file_no++] = strdup(name); + ACK(ofp); + break; + default: + abort_transfer(df_list); + unlock_job(); + syslog(LOG_ERR, "protocol screwup"); + return (-1); + } + } + if ((cf != NULL) && (file_no != 0)) { + if (adaptor_submit_job(printer, host, cf, df_list) != 0) { + abort_transfer(df_list); + unlock_job(); + return (-1); + } + while (file_no-- > 0) + free(df_list[file_no]); + free(cf); + } else + abort_transfer(df_list); + unlock_job(); + + return (0); +} + + +/* + * This is the entry point for this program. The program takes the + * following options: + * (none) + */ +main(int ac, char *av[]) +{ + FILE *ifp = stdin, + *ofp = stdout; + int c, + rc; + char buf[BUFSIZ], + **args, + *host, + *dir, + *printer, + *requestor; + + + openlog("bsd-gw", LOG_PID, LOG_LPR); + + while ((c = getopt(ac, av, "d")) != EOF) + switch (c) { + 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); + } + +#ifdef DEBUG + if ((buf[0] > '0') && (buf[0] < '6')) + buf[0] -= '0'; +#endif + + if ((buf[0] < 1) || (buf[0] > 5)) { + syslog(LOG_ERR, "Invalid protocol request (%d): %c%s", + buf[0], buf[0], buf); + (void) fprintf(ofp, + gettext("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) { + syslog(LOG_ERR, "Can't determine requested printer"); + (void) fprintf(ofp, + gettext("Can't determine requested printer")); + exit(1); + } + + if ((host = remote_host_name(ifp)) == NULL) { + syslog(LOG_ERR, "Can't determine requesting host"); + (void) fprintf(ofp, + gettext("Can't determine requesting host\n")); + exit(1); + } + + if (adaptor_available(printer) < 0) { + if (errno == ENOENT) { + syslog(LOG_ERR, + "request to %s (unknown printer) from %s", + printer, host); + (void) fprintf(ofp, + gettext("%s: unknown printer\n"), printer); + } else { + syslog(LOG_ERR, + "Can't locate protocol adaptor for %s from %s", + printer, host); + (void) fprintf(ofp, gettext( + "Can't locate protocol adaptor for %s\n"), + printer); + } + exit(1); + } + + if (adaptor_spooler_available(printer) < 0) { + syslog(LOG_ERR, "Can't communicate with spooler for %s", + printer); + (void) fprintf(ofp, + gettext("Can't communicate with spooler for %s\n"), + printer); + exit(1); + } + + if (adaptor_client_access(printer, host) < 0) { + syslog(LOG_ERR, "%s doesn't have permission to talk to %s", + host, printer); + (void) fprintf(ofp, + gettext("%s doesn't have permission to talk to %s\n"), + host, printer); + exit(1); + } + + if ((dir = adaptor_temp_dir(printer, host)) == NULL) { + syslog(LOG_DEBUG, "failure to locate tmp dir"); + return (1); + } + + if (chdir(dir) < 0) { + syslog(LOG_DEBUG, "chdir(%s): %m", dir); + return (1); + } + + switch (buf[0]) { + case '\1': /* restart printer */ + if ((rc = adaptor_restart_printer(printer)) == 0) { + ACK(ofp); + } else { + NACK(ofp); + } + break; + case '\2': /* transfer job(s) */ + rc = transfer_job(printer, host, ifp, ofp); + break; + case '\3': /* show queue (short) */ + case '\4': /* show queue (long) */ + rc = adaptor_show_queue(printer, ofp, buf[0], args); + break; + case '\5': /* cancel job(s) */ + requestor = *args++; + rc = adaptor_cancel_job(printer, ofp, requestor, host, args); + break; + default: + /* NOTREACHED */ + /* your system would have to be completely hosed */ + syslog(LOG_ERR, "reboot or reinstall your system"); + rc = -1; + } + (void) fflush(ofp); + + syslog(LOG_DEBUG, + "protocol request(%d) for %s completed with status %d", + buf[0], printer, rc); + exit(0); +} diff --git a/usr/src/cmd/print/gateway/rfc1179.xml b/usr/src/cmd/print/gateway/rfc1179.xml new file mode 100644 index 0000000000..19fa0c3be7 --- /dev/null +++ b/usr/src/cmd/print/gateway/rfc1179.xml @@ -0,0 +1,100 @@ +<?xml version='1.0'?> +<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> + +<!-- + Copyright 2005 Sun Microsystems, Inc. All rights reserved. + Use is subject to license terms. + + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 + + pragma ident "%Z%%M% %I% %E% SMI" + + NOTE: This service manifest is not editable; its contents will + be overwritten by package or patch operations, including + operating system upgrade. Make customizations in a different + file. +--> + +<service_bundle type='manifest' name='SUNWpcr:rfc1179'> + +<service + name='application/print/rfc1179' + type='service' + version='1'> + + <create_default_instance enabled='true' /> + + <restarter> + <service_fmri value='svc:/network/inetd:default' /> + </restarter> + + <dependency + name='lpsched' + grouping='require_all' + restart_on='error' + type='service'> + <service_fmri value='svc:/application/print/server' /> + </dependency> + + <exec_method + type='method' + name='inetd_start' + exec='/usr/lib/print/in.lpd' + timeout_seconds='0'> + <method_context> + <method_credential user='root' group='root' /> + </method_context> + </exec_method> + + + <exec_method + type='method' + name='inetd_disable' + exec=':kill' + timeout_seconds='0'> + </exec_method> + + <property_group name='inetd' type='framework'> + <stability value='Evolving' /> + <propval name='endpoint_type' type='astring' value='stream' /> + <propval name='name' type='astring' value='printer' /> + <propval name='wait' type='boolean' value='false' /> + <propval name='isrpc' type='boolean' value='false' /> + <propval name='proto' type='astring' value='tcp6' /> + </property_group> + + <stability value='Unstable' /> + + <template> + <common_name> + <loctext xml:lang='C'> + BSD print protocol adapter + </loctext> + </common_name> + <documentation> + <manpage title='in.lpd' section='1M' + manpath='/usr/share/man' /> + </documentation> + </template> + +</service> + +</service_bundle> diff --git a/usr/src/cmd/print/gateway/translators/Makefile b/usr/src/cmd/print/gateway/translators/Makefile new file mode 100644 index 0000000000..f761f2c949 --- /dev/null +++ b/usr/src/cmd/print/gateway/translators/Makefile @@ -0,0 +1,50 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "%Z%%M% %I% %E% SMI" +# +# cmd/print/gateway/translators/Makefile +# + +SUBDIRS = test cascade + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +strip := TARGET= strip +_msg := TARGET= catalog + +.KEEP_STATE: + +all install: $(SUBDIRS) + +clean clobber strip cstyle lint: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/gateway/translators/cascade/Makefile b/usr/src/cmd/print/gateway/translators/cascade/Makefile new file mode 100644 index 0000000000..ee0cd19f03 --- /dev/null +++ b/usr/src/cmd/print/gateway/translators/cascade/Makefile @@ -0,0 +1,68 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 1996, 2002 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# + +LIBRARY = bsd_cascade.a +VERS=.1 + +OBJECTS = cascade.o + +include ../../../../../lib/Makefile.lib +include ../../../Makefile.sp + +ROOTLIBDIR= $(ROOT)/usr/lib/print/bsd-adaptor + +#CPPFLAGS += -I$(LPINC) +CPPFLAGS += -I$(NPRTINC) +LDLIBS += -lprint -lc # with XFN API +#LDLIBS += $(LIBCLS) $(LIBPRT) $(LIBMSG) + +LIBS = $(DYNLIB) # could be += for static and dynamic +SRCS= $(OBJECTS:%.o=%.c) + +CLOBBERFILES= llib-lbsd_cascade.a.ln lint.out + +.KEEP_STATE: + +all : $(LIBS) + +install: $(ROOTLIBDIR) $(ROOTLIBS) $(ROOTLINKS) + +cstyle: + cstyle $(SRCS) + +lint: + $(LINT.c) $(SRCS) +strip: + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +$(ROOTLIBDIR): + $(INS.dir) + +include ../../../../../lib/Makefile.targ diff --git a/usr/src/cmd/print/gateway/translators/cascade/cascade.c b/usr/src/cmd/print/gateway/translators/cascade/cascade.c new file mode 100644 index 0000000000..ad9a7d73ef --- /dev/null +++ b/usr/src/cmd/print/gateway/translators/cascade/cascade.c @@ -0,0 +1,322 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdarg.h> +#include <syslog.h> +#include <unistd.h> +#include <libintl.h> + +#include <print/ns.h> +#include <print/job.h> +#include <print/list.h> +#include <print/misc.h> +#include <print/network.h> + + +static ns_printer_t *printer_object = NULL; +static ns_bsd_addr_t *printer_addr = NULL; + + +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); +} + + + +/* + * cascade_spooler_available() always returns 0, because it is really + * used as a waiting space for contacting another spooler. + */ +int +cascade_spooler_available(const char *printer) +{ + syslog(LOG_DEBUG, "cascade_spooler_available(%s)", + (printer ? printer : "NULL")); + + if ((printer_object = ns_printer_get_name(printer, NULL)) == NULL) + return (-1); + + if ((printer_addr = ns_bsd_addr_get_name((char *)printer)) == NULL) + return (-1); + + return (0); +} + + +/* + * cascade_client_access() always returns 0, because all requestors should + * be allowed to cascade. + */ +int +cascade_client_access(const char *printer, const char *host) +{ + syslog(LOG_DEBUG, "cascade_client_access(%s, %s)", + (printer ? printer : "NULL"), (host ? host : "NULL")); + + return (0); +} + + +/* + * cascade_spooler_accepting_jobs() always returns 0, because all requestors + * should be allowed to cascade. + */ +int +cascade_spooler_accepting_jobs(const char *printer) +{ + syslog(LOG_DEBUG, "cascade_spooler_accepting_jobs(%s)", + (printer ? printer : "NULL")); + + return (0); +} + + +/* + * cascade_temp_dir() returns the directory to be used as the working + * directory for the cascaded spooler. All data files will be expected to + * be stored and retreived from this directory + */ +char * +cascade_temp_dir(const char *printer, const char *host) +{ + char *tmp = NULL; + + if ((tmp = ns_get_value_string("spool-dir", printer_object)) == NULL) + tmp = strdup("/var/spool/print"); + + syslog(LOG_DEBUG, "cascade_temp_dir(%s, %s) = %s", + (printer ? printer : "NULL"), (host ? host : "NULL"), tmp); + + if ((access((const char *)tmp, F_OK) < 0) && (mkdir(tmp, 0755) < 0)) + return (NULL); + + return (tmp); +} + + +/* + * cascade_restart_printer() always returns 0, because it should always be + * processing if a job is waiting to cascade. + */ +int +cascade_restart_printer(const char *printer) +{ + syslog(LOG_DEBUG, "cascade_restart_printer(%s)", + (printer ? printer : "NULL")); + + start_daemon(1); + + return (0); +} + + +/* + * cascade_submit_job() will save the control file data, write a binding + * file and attempt to start a transfer agent. + */ +int +cascade_submit_job(const char *printer, const char *host, char *cf, + char **df_list) +{ + FILE *fp; + + syslog(LOG_DEBUG, "cascade_submit_job(%s, %s, 0x%x, 0x%x)", + (printer ? printer : "NULL"), (host ? host : "NULL"), cf, + df_list); + + /* write the control file */ + df_list[0][0] = 'c'; + + /* + * Applying lock when bsd-gw is writing control file + * in /var/spool/print directory + */ + if (((fp = fopen(df_list[0], "w")) != NULL) && + ((lockf(fileno(fp), F_LOCK, 0)) == 0)) { + fprintf(fp, "%s", cf); + fclose(fp); + } else + return (-1); + + /* write a binding file */ + df_list[0][0] = 'x'; + + /* + * Applying lock when bsd-gw is writing xfile + * in /var/spool/print directory + */ + if (((fp = fopen(df_list[0], "w")) != NULL) && + ((lockf(fileno(fp), F_LOCK, 0)) == 0)) { + fprintf(fp, "%s:%s\n", printer_addr->server, + printer_addr->printer); + fclose(fp); + } else { + df_list[0][0] = 'c'; + unlink(df_list[0]); + return (-1); + } + + start_daemon(1); + + return (0); +} + + +/* + * cascade_show_queue() will relay job information from a remote spooler + * and then add any local jobs waiting to cascade to the same destination. + */ +int +cascade_show_queue(const char *printer, FILE *ofp, const int type, + const char **list) +{ + int fd; + job_t **jobs = NULL; + + syslog(LOG_DEBUG, "cascade_show_queue(%s, 0x%x, %d, 0x%x)", + (printer ? printer : "NULL"), ofp, type, list); + + /* get the remote list first */ + if ((fd = net_open(printer_addr->server, 5)) >= 0) { + char buf[BUFSIZ]; + char **jlist = (char **)list; + + snprintf(buf, sizeof (buf), "%c%s", type, + (printer_addr->printer ? printer_addr->printer : + printer)); + while ((jlist != NULL) && (*jlist != NULL)) { + strlcat(buf, " ", sizeof (buf)); + strlcat(buf, *jlist++, sizeof (buf)); + } + + net_printf(fd, "%s\n", buf); + while (net_gets(buf, sizeof (buf), fd) != NULL) + fputs(buf, ofp); + + close(fd); + } else + fprintf(ofp, gettext("can't connect to %s\n"), + printer_addr->server); + + /* list any "local" jobs */ + if ((jobs = job_list_append(NULL, (char *)printer, + NULL, ".")) != NULL) { + int rank = 1; + + while (*jobs != NULL) { + if (type == 3) { + fprintf(ofp, + gettext("%-7.7s %8.8s %5d " + "%-32.32s %8d bytes\n"), + rank_string(rank++), (*jobs)->job_user, + (*jobs)->job_id, "files", -1); + } else { + fprintf(ofp, + gettext("%-8s:%-7s\t\t\t[ job %d%s ]\n"), + (*jobs)->job_user, rank_string(rank++), + (*jobs)->job_id, (*jobs)->job_host); + + } + jobs++; + } + } + + return (0); +} + + +/* + * cascade_cancel_job() will remove any matching jobs waiting to cascade to + * the remote system, and then request the remote system to remove any + * matching jobs. + */ +int +cascade_cancel_job(const char *printer, FILE *ofp, const char *user, + const char *host, const char **list) +{ + int fd; + job_t **jobs = NULL; + + syslog(LOG_DEBUG, "cascade_cancel_job(%s, 0x%x, %s, %s, 0x%x)", + (printer ? printer : "NULL"), ofp, (user ? user : "NULL"), + (host ? host : "NULL"), list); + + /* cancel "local" jobs */ + if ((jobs = job_list_append(NULL, (char *)printer, + (char *)host, ".")) != NULL) + list_iterate((void **)jobs, (VFUNC_T)vjob_cancel, user, + printer, host, list); + + /* ask the remote system next */ + if ((fd = net_open(printer_addr->server, 5)) >= 0) { + char buf[BUFSIZ]; + char **jlist = (char **)list; + + snprintf(buf, sizeof (buf), "%c%s %s", 5, + (printer_addr->printer ? printer_addr->printer : + printer), user); + while ((jlist != NULL) && (*jlist != NULL)) { + strlcat(buf, " ", sizeof (buf)); + strlcat(buf, *jlist++, sizeof (buf)); + } + + net_printf(fd, "%s\n", buf); + while (net_gets(buf, sizeof (buf), fd) != NULL) + fputs(buf, ofp); + + close(fd); + } else + fprintf(ofp, gettext("can't connect to %s\n"), + printer_addr->server); + + return (0); +} diff --git a/usr/src/cmd/print/gateway/translators/test/Makefile b/usr/src/cmd/print/gateway/translators/test/Makefile new file mode 100644 index 0000000000..e237bab625 --- /dev/null +++ b/usr/src/cmd/print/gateway/translators/test/Makefile @@ -0,0 +1,68 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 1989, 2002 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# + +LIBRARY = bsd_test.a +VERS=.1 + +OBJECTS = test.o + +include ../../../../../lib/Makefile.lib +include ../../../Makefile.sp + +ROOTLIBDIR= $(ROOT)/usr/lib/print/bsd-adaptor + +#CPPFLAGS += -I$(LPINC) +CPPFLAGS += -I$(NPRTINC) +LDLIBS += -lprint -lc # with XFN API +#LDLIBS += $(LIBCLS) $(LIBPRT) $(LIBMSG) + +LIBS = $(DYNLIB) # could be += for static and dynamic +SRCS= $(OBJECTS:%.o=%.c) + +CLOBBERFILES= llib-lbsd_test.a.ln lint.out + +.KEEP_STATE: + +all : $(LIBS) + +install: $(ROOTLIBDIR) $(ROOTLIBS) $(ROOTLINKS) + +cstyle: + cstyle $(SRCS) + +lint: + $(LINT.c) $(SRCS) +strip: + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +$(ROOTLIBDIR): + $(INS.dir) + +include ../../../../../lib/Makefile.targ diff --git a/usr/src/cmd/print/gateway/translators/test/README b/usr/src/cmd/print/gateway/translators/test/README new file mode 100644 index 0000000000..229a57b38e --- /dev/null +++ b/usr/src/cmd/print/gateway/translators/test/README @@ -0,0 +1,60 @@ +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2000 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + ident "%Z%%M% %I% %E% SMI" + +This file describes how to use the "test" translator... + +The "test" translator is design to provide a simple method of testing the +printing protocol adaptor front-end, and BSD protocol client side functionality.The translator is a loadable module implementing the adaptor API. It relies +heavily on the naming interface (printers.conf) to determine the action it +should take. + +The following Keys have been defined: + +Key description +test-log log file name (string) +test-dir working dir (string) +test-spooler-available spooler running (boolean) +test-access access allowed (boolean) +test-restart restart allowed (boolean) +test-submit submission allowed (boolean) +test-show-queue-state status line (string) +test-show-queue-file status data file (string) +test-cancel-job-file cancel data file (string) + +a sample entry might look like: + +test:\ + :bsdaddr=test,localhost,Solaris:\ + :spooling-paradigm=test:\ + :test-log=/tmp/test_printer/log:\ + :test-dir=/tmp/test_printer:\ + :test-access=true:\ + :test-restart=true:\ + :test-submit=true:\ + :test-show-queue-state=out of paper:\ + :test-show-queue-file=/tmp/test_printer/show-queue:\ + :test-cancel-job-file=/tmp/test_printer/cancel-job: + diff --git a/usr/src/cmd/print/gateway/translators/test/test.c b/usr/src/cmd/print/gateway/translators/test/test.c new file mode 100644 index 0000000000..243da2f740 --- /dev/null +++ b/usr/src/cmd/print/gateway/translators/test/test.c @@ -0,0 +1,239 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <string.h> +#include <stdarg.h> +#include <syslog.h> + +#include <print/ns.h> + + +static ns_printer_t *printer_object = NULL; +static FILE *lfp = NULL; + + +static void +log_printf(char *fmt, ...) +{ + if (lfp != NULL) { + va_list ap; + + va_start(ap, fmt); + (void) vfprintf(lfp, fmt, ap); + va_end(ap); + (void) fflush(lfp); + } +} + + +int +test_spooler_available(const char *printer) +{ + int rc = 0; + char *tmp; + + if ((printer_object = ns_printer_get_name(printer, NULL)) == NULL) + return (-1); + + if ((tmp = ns_get_value_string("test-log", printer_object)) != NULL) + lfp = fopen(tmp, "a+"); + + if (((tmp = ns_get_value_string("test-spooler-available", + printer_object)) != NULL) && + (strcasecmp(tmp, "false") == 0)) + rc = -1; + + log_printf("test_spooler_available(%s): " + "test-spooler-available = %s (%d)\n", + (printer ? printer : "NULL"), (tmp ? tmp : "NULL"), rc); + + return (rc); +} + + +int +test_spooler_accepting_jobs(const char *printer) +{ + int rc = 0; + char *tmp; + + if (((tmp = ns_get_value_string("test-accepting", printer_object)) + != NULL) && (strcasecmp(tmp, "false") == 0)) + rc = -1; + + log_printf( + "test_spooler_accepting_jobs(%s): test-accepting = %s (%d)\n", + (printer ? printer : "NULL"), (tmp ? tmp : "NULL"), rc); + + return (rc); +} + + +int +test_client_access(const char *printer, const char *host) +{ + int rc = 0; + char *tmp; + + if (((tmp = ns_get_value_string("test-access", printer_object)) + != NULL) && (strcasecmp(tmp, "false") == 0)) + rc = -1; + + log_printf("test_client_access(%s, %s): test-access = %s (%d)\n", + (printer ? printer : "NULL"), (host ? host : "NULL"), + (tmp ? tmp : "NULL"), rc); + + return (rc); +} + + +char * +test_temp_dir(const char *printer, const char *host) +{ + char *tmp; + + if ((tmp = ns_get_value_string("test-dir", printer_object)) == NULL) + tmp = strdup("/tmp"); + + log_printf("test_temp_dir(%s, %s): test-dir = %s\n", + (printer ? printer : "NULL"), (host ? host : "NULL"), + (tmp ? tmp : "NULL")); + + return (tmp); +} + + +int +test_restart_printer(const char *printer) +{ + int rc = 0; + char *tmp; + + if (((tmp = ns_get_value_string("test-restart", printer_object)) + != NULL) && (strcasecmp(tmp, "false") == 0)) + rc = -1; + + log_printf("test_restart_printer(%s): test-restart = %s (%d)\n", + (printer ? printer : "NULL"), (tmp ? tmp : "NULL"), rc); + + return (rc); +} + + +int +test_submit_job(const char *printer, const char *host, char *cf, + char **df_list) +{ + FILE *fp; + char *tmp; + + if (((tmp = ns_get_value_string("test-submit", printer_object)) + != NULL) && (strcasecmp(tmp, "false") == 0)) + return (-1); + + df_list[0][0] = 'c'; + if ((fp = fopen(df_list[0], "w")) != 0) { + (void) fprintf(fp, "%s", cf); + (void) fclose(fp); + } + df_list[0][0] = 'c'; + + log_printf("test_submit_job(%s, %s): test-submit = %s\n", + (printer ? printer : "NULL"), (host ? host : "NULL"), + (tmp ? tmp : "NULL")); + log_printf("\tcontrol = %s\n", df_list[0]); + df_list[0][0] = 'd'; + while (*df_list != NULL) + log_printf("\tdata = %s\n", *df_list++); + + return (0); +} + + +int +test_show_queue(const char *printer, FILE *ofp, const int type, + const char **list) +{ + char *file = NULL; + FILE *fp; + + if (((file = ns_get_value_string("test-show-queue-file", + printer_object)) != NULL) && + ((fp = fopen(file, "r+")) != NULL)) { + char buf[1024]; + + while (fgets(buf, sizeof (buf), fp) != NULL) + (void) fputs(buf, ofp); + (void) fclose(fp); + } else + (void) fprintf(ofp, "no entries\n"); + + log_printf("test_show_queue(%s, 0x%x, %s):\n", + (printer ? printer : "NULL"), ofp, + (type == 3 ? "short" : "long")); + log_printf("\tfile = %s\n", (file ? file : "NULL")); + while (*list != NULL) + log_printf("\tjob or user = %s\n", *list++); + + return (0); +} + + +int +test_cancel_job(const char *printer, FILE *ofp, const char *user, + const char *host, const char **list) +{ + char *file = NULL; + + if ((file = ns_get_value_string("test-cancel-job-file", printer_object)) + != NULL) + + if (file != NULL) { + FILE *fp; + char buf[1024]; + + if ((fp = fopen(file, "r+")) != NULL) { + while (fgets(buf, sizeof (buf), fp) != NULL) + (void) fputs(buf, ofp); + (void) fclose(fp); + } + } + + log_printf("test_cancel_job(%s, 0x%x, %s, %s):\n", + (printer ? printer : "NULL"), ofp, (user ? user : "NULL"), + (host ? host : "NULL")); + while (*list != NULL) + log_printf("\tjob or user = %s\n", *list++); + + return (0); +} diff --git a/usr/src/cmd/print/lp/Makefile b/usr/src/cmd/print/lp/Makefile new file mode 100644 index 0000000000..942ebded74 --- /dev/null +++ b/usr/src/cmd/print/lp/Makefile @@ -0,0 +1,93 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/client/lp/Makefile +# + +include ../Makefile.sp + +PROG= lp + +MANIFEST= cleanup.xml + +SRCS= $(PROG).c + +ROOTMANIFESTDIR= $(ROOTSVCAPPLICATIONPRINT) +ROOTMETHOD= $(ROOTLIBSVCMETHOD)/print-cleanup +$(ROOTMANIFEST) := FILEMODE= 444 + +OBJS= $(SRCS:.c=.o) + +ROOTBINPROG= $(PROG:%=$(ROOTBIN)/%) +ROOTUSRBINSYMLINK= $(ROOTUSRUCB)/lpr +PRINTSYMLINK= $(ROOTLIB)/print/printd +$(ROOTLIB)/print := OWNER=root +$(ROOTLIB)/print := GROUP=lp +$(ROOTLIBSVCMETHOD)/print-cleanup := FILEMODE=555 + +FILEMODE= 04511 +OWNER= root + +CPPFLAGS += -I$(NPRTINC) +LDLIBS += $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) + +install: all $(ROOTBIN) $(ROOTLIB)/print $(ROOTBINPROG) \ + $(ROOTUSRBINSYMLINK) $(PRINTSYMLINK) $(ROOTMANIFEST) \ + $(ROOTMETHOD) + +check: $(CHKMANIFEST) + +$(ROOTBIN) $(ROOTLIB)/print: + $(INS.dir) + +$(ROOTUSRBINSYMLINK): + $(RM) $@; $(SYMLINK) ../bin/$(PROG) $@ + +$(PRINTSYMLINK): + $(RM) $@; $(SYMLINK) ../../bin/$(PROG) $@ + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(PROG).c $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) diff --git a/usr/src/cmd/print/lp/cleanup.xml b/usr/src/cmd/print/lp/cleanup.xml new file mode 100644 index 0000000000..50118847d2 --- /dev/null +++ b/usr/src/cmd/print/lp/cleanup.xml @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> +<!-- + Copyright 2005 Sun Microsystems, Inc. All rights reserved. + Use is subject to license terms. + + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 + + ident "%Z%%M% %I% %E% SMI" + + NOTE: This service manifest is not editable; its contents will + be overwritten by package or patch operations, including + operating system upgrade. Make customizations in a different + file. +--> + +<service_bundle type='manifest' name='SUNWpcr:printd'> + +<service + name='application/print/cleanup' + type='service' + version='1'> + + <create_default_instance enabled='false' /> + + <dependency + name='network' + grouping='require_any' + restart_on='error' + type='service'> + <service_fmri value='svc:/network/loopback' /> + <service_fmri value='svc:/network/physical' /> + </dependency> + + <dependency + name='filesystem' + grouping='require_all' + restart_on='none' + type='service'> + <service_fmri value='svc:/system/filesystem/minimal' /> + </dependency> + + <exec_method + type='method' + name='start' + exec='/lib/svc/method/print-cleanup start' + timeout_seconds='60' /> + + <exec_method + type='method' + name='stop' + exec=':true' + timeout_seconds='0' /> + + <property_group name='startd' type='framework'> + <propval name='duration' type='astring' value='transient' /> + </property_group> + + <stability value='Unstable' /> + + <template> + <common_name> + <loctext xml:lang='C'> + print cleanup + </loctext> + </common_name> + </template> +</service> + +</service_bundle> diff --git a/usr/src/cmd/print/lp/lp.c b/usr/src/cmd/print/lp/lp.c new file mode 100644 index 0000000000..b6bdb847b6 --- /dev/null +++ b/usr/src/cmd/print/lp/lp.c @@ -0,0 +1,1279 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <ctype.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/systeminfo.h> +#include <sys/param.h> +#include <stdarg.h> +#include <signal.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <syslog.h> +#include <termios.h> +#include <libintl.h> +#include <locale.h> +#include <pwd.h> +#include <grp.h> + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/list.h> +#include <print/job.h> + +/* + * lpr/lp + * This program will submit print jobs to a spooler using the BSD + * printing protcol as defined in RFC1179, plus some extension for + * support of additional lp functionality. + */ + +extern char *optarg; +extern int optind, opterr, optopt; +extern char *getenv(const char *); + +#define SEND_RETRY -1 +#define SEND_ABORT -2 + + +static int priority = -1, + copies = 1, + width = -1, /* pr width */ + indent = -1, /* pr indent */ + linked = 0, + mail = 0, + delete = 0, + suppress = 1, + banner = 1, + connection_failed = 0; +static char *printer = NULL, + *form = NULL, + *charset = NULL, + *title = NULL, /* pr title */ + *class = NULL, + *jobName = NULL, + *notification = NULL, + *handling = NULL, + *pages = NULL, + **mode = NULL, + **s5options = NULL, + *s5type = NULL, + *internal_type = NULL, + *fontR = NULL, + *fontI = NULL, + *fontB = NULL, + *fontS = NULL, + type = CF_PRINT_ASCII; + +static struct s5_types { + char *name; + char type; +} output_types[] = { /* known LP "-T" types */ +/* + * Switched to ASCII, because some BSD systems don't like the 'o' file + * type. + */ + { "postscript", CF_PRINT_ASCII }, + { "ps", CF_PRINT_ASCII }, + { "simple", CF_PRINT_ASCII }, + { "ascii", CF_PRINT_ASCII }, + { "raw", CF_PRINT_RAW }, + { "dvi", CF_PRINT_DVI }, + { "tex", CF_PRINT_DVI }, + { "raster", CF_PRINT_RAS }, + { "ditroff", CF_PRINT_DROFF }, + { "otroff", CF_PRINT_TROFF }, + { "troff", CF_PRINT_DROFF }, + { "cif", CF_PRINT_CIF }, + { "plot", CF_PRINT_PLOT }, + { "fortran", CF_PRINT_FORT }, + { "pr", CF_PRINT_PR }, + NULL +}; + +/*ARGSUSED*/ +static void sigbus_handler(int i) +{ + (void) fprintf(stderr, + gettext("No space in /var/spool/print to store job")); + exit(-1); +} + +/*ARGSUSED*/ +static void sigpipe_handler(int i) +{ + syslog(LOG_ERR, "Warning: Received SIGPIPE; continuing"); + (void) signal(SIGPIPE, sigpipe_handler); +} + + +#define OLD_LP "/usr/lib/lp/local/lp" /* for local lpsched printers */ +#ifdef OLD_LP +/* + * this will submit the job to a local lpsched using the old interface. + * the argument vector is rebuilt with a new destination, because + * the old name may have been an alias or because it was actually + * lpr(1b) that was called. + */ +static void +submit_local_lp(char *program, int ac, char *av[]) +{ + uid_t ruid = getuid(); + struct passwd *pw; + int argc = 0; + char **argv; + + /* + * We allocate the space for ac+5 items, which include all the file + * arguments(ac), generic arguments(OLD_LP, "-d" and "printer") and + * "-s" option of lpr. The extra item is just a cushion. + */ + if ((argv = (char **)calloc(ac + 5, sizeof (char *))) == NULL) { + (void) fprintf(stderr, + gettext("not enough memory for argument vector\n")); + exit(1); + } + argv[argc++] = OLD_LP; + argv[argc++] = "-d"; + argv[argc++] = printer; + + if (strcmp(program, "lp") == 0) { + int i = 0; + + while (++i < ac) + if (strncmp(av[i], "-d", 2) != 0) { + argv[argc++] = av[i]; + } else if (strlen(av[i]) == 2) + i++; + } else { /* convert lpr options */ + argv[argc++] = "-s"; /* supress id message */ + + if (linked == 0) + argv[argc++] = "-c"; + + if (copies > 1) { + char buf[12]; + (void) sprintf(buf, "%d", copies); + argv[argc++] = "-n"; + argv[argc++] = strdup(buf); + } + if (banner == 0) { + argv[argc++] = "-o"; + argv[argc++] = "nobanner"; + } + if (title != NULL) { + char buf[BUFSIZ]; + (void) snprintf(buf, sizeof (buf), "prtitle='%s'", + title); + argv[argc++] = "-y"; + argv[argc++] = strdup(buf); + } + if (width > 0) { + char buf[16]; + (void) sprintf(buf, "prwidth=%d", width); + argv[argc++] = "-y"; + argv[argc++] = strdup(buf); + } + if (indent > 0) { + char buf[16]; + (void) sprintf(buf, "indent=%d", indent); + argv[argc++] = "-y"; + argv[argc++] = strdup(buf); + } + if (mail != 0) + argv[argc++] = "-m"; + if ((jobName != NULL) || (class != NULL)) { + char buf[128]; + snprintf(buf, sizeof (buf), "%s%s%s", + (jobName ? jobName : ""), + (jobName && class ? "\\n#####\\n#####\\t\\t " + : ""), (class ? class : "")); + argv[argc++] = "-t"; + argv[argc++] = strdup(buf); + } + + if (type != CF_PRINT_ASCII) { + struct s5_types *tmp; + + for (tmp = output_types; tmp->name != NULL; tmp++) + if (tmp->type == type) { + argv[argc++] = "-T"; + argv[argc++] = tmp->name; + break; + } + } + + while (optind < ac) + argv[argc++] = av[optind++]; + + } + + ruid = getuid(); + if ((pw = getpwuid(ruid)) != NULL) + (void) initgroups(pw->pw_name, pw->pw_gid); + (void) setuid(ruid); + + argv[argc++] = NULL; + (void) execv(OLD_LP, argv); +} +#endif + + +/* + * cheat and look in the LP interface to determine if a local printer is + * rejecting. If so, don't queue the job. If the printer is remote or + * accepting, queue it. This approximates behaviour of previous releases + * The check is being done this way for performance. + */ +static int +rejecting(char *printer) +{ + int rc = 0, found = 0; + FILE *fp; + + if ((fp = fopen("/usr/spool/lp/system/pstatus", "r+")) != NULL) { + char buf[BUFSIZ]; + + while (fgets(buf, sizeof (buf), fp) != NULL) { + buf[strlen(buf)-1] = NULL; + if (strcmp(buf, printer) == 0) { + char *ptr; + + found = 1; + (void) fgets(buf, sizeof (buf), fp); + buf[strlen(buf)-1] = NULL; + ptr = strrchr(buf, ' '); + if (ptr && (strcmp(++ptr, "rejecting") == 0)) { + rc = 1; + break; + } + } + } + } + (void) fclose(fp); + + /* if we have'nt found the name it could be a class */ + if (!found) { + if ((fp = fopen("/usr/spool/lp/system/cstatus", + "r+")) != NULL) { + + char buf2[BUFSIZ]; + + while (fgets(buf2, sizeof (buf2), fp) != NULL) { + buf2[strlen(buf2)-1] = NULL; + if (strcmp(buf2, printer) == 0) { + fgets(buf2, sizeof (buf2), fp); + buf2[strlen(buf2)-1] = NULL; + if (strcmp(buf2, "rejecting") == 0) { + rc = 1; + break; + } + } + } + + } + } + + (void) fclose(fp); + return (rc); +} + +/* + * Remove special characters before popen (change them into '_'). + */ +static void +clean_string(char *ptr) +{ + char *cp; + wchar_t wc; + int len; + + for (cp = ptr; *cp != NULL; ) { + if ((len = mbtowc(&wc, cp, MB_CUR_MAX)) == -1) { + cp++; + continue; + } + + if (len == 1 && + ((wc == L'`') || (wc == L'&') || (wc == L';') || + (wc == L'|') || (wc == L'>') || (wc == L'^') || + (wc == L'$') || (wc == L'(') || (wc == L')') || + (wc == L'<') || (wc == L'*') || (wc == L'?') || + (wc == L'['))) + *cp = '_'; + cp += len; + } +} + + +static int _notified = 0; + +static void +error_notify(char *user, int id, char *msg, ...) +{ + if (_notified++ == 0) { + char *tmp; + char cmd[BUFSIZ]; + FILE *fp; + va_list ap; + + va_start(ap, msg); + tmp = strdup(user); + clean_string(tmp); + (void) snprintf(cmd, sizeof (cmd), + "/bin/write %s >/dev/null 2>&1", tmp); + free(tmp); + fp = popen(cmd, "w+"); + (void) fprintf(fp, + gettext("\n\tError transfering print job %d\n"), id); + (void) vfprintf(fp, msg, ap); + (void) pclose(fp); + va_end(ap); + } +} + + + +/* + * bsd_options() parses the command line using the BSD lpr semantics and sets + * several global variables for use in building the print request. + */ +static void +bsd_options(int ac, char *av[]) +{ + int c; + + while ((c = getopt(ac, av, + "P:#:C:J:T:w:i:hplrstdgvcfmn1:2:3:4:")) != EOF) + switch (c) { + case 'P': + printer = optarg; + break; + case '#': + copies = atoi(optarg); + break; + case 'C': + class = optarg; + break; + case 'J': + jobName = optarg; + break; + case 'T': + title = optarg; + break; + case 'w': + width = atoi(optarg); + break; + case 'm': + mail++; + break; + case 'i': /* this may or may not have an arguement */ + if (isdigit(optarg[0]) == 0) { + indent = 8; + optind--; + } else + indent = atoi(optarg); + break; + case 'h': + banner = 0; + break; + case 'r': + delete = 1; + break; + case 's': + linked = 1; + break; + case 'l' : + type = CF_PRINT_RAW; + break; + case 'd' : + type = CF_PRINT_DVI; + break; + case 't' : + type = CF_PRINT_TROFF; + break; + case 'g' : + type = CF_PRINT_PLOT; + break; + case 'v' : + type = CF_PRINT_RAS; + break; + case 'c' : + type = CF_PRINT_CIF; + break; + case 'f' : + type = CF_PRINT_FORT; + break; + case 'n' : + type = CF_PRINT_DROFF; + break; + case 'o' : + type = CF_PRINT_PS; + break; + case 'p' : + type = CF_PRINT_PR; + break; + case '1' : + fontR = optarg; + break; + case '2' : + fontI = optarg; + break; + case '3' : + fontB = optarg; + break; + case '4' : + fontS = optarg; + break; + default: + (void) fprintf(stderr, + gettext("Usage: %s [-Pprinter] [-#num] " + "[-Cclass] [-Jjob] [-Ttitle] [-i [indent]] " + "[-1234 font] [-wcols] [-m] [-h] [-s] " + "[-pltndgvcf] files ...\n"), + av[0]); + exit(1); + } + + /* + * The pr filter must be specified with the + * title, width, and indent options + */ + if ((title != NULL) && (type != CF_PRINT_PR)) + (void) fprintf(stderr, gettext( + "Warning: title option ignored as the pr " + "filter option was not specified\n")); + if ((width > 0) && (type != CF_PRINT_PR)) + (void) fprintf(stderr, gettext( + "Warning: width option ignored as the pr " + "filter option was not specified\n")); + if ((indent > 0) && (type != CF_PRINT_PR)) + (void) fprintf(stderr, gettext( + "Warning: indent option ignored as the pr " + "filter option was not specified\n")); +} + +/* + * sysv_options() parses the command line using the BSD lpr semantics and sets + * several global variables for use in building the print request. + */ +static void +sysv_options(int ac, char *av[]) +{ + int c; + +#ifdef OLD_LP + if ((ac > 2) && (strcmp(av[1], "-i") == 0)) { + if (access(OLD_LP, F_OK) == 0) { + /* + * limit ourselves to real user's perms before exec'ing + */ + (void) setuid(getuid()); + (void) execv(OLD_LP, av); + perror("exec local modify"); + } else + (void) printf(gettext( + "job modification not supported on clients\n")); + exit(-1); + } +#endif + + linked = 1; + suppress = 0; + while ((c = getopt(ac, av, "H:P:S:T:d:f:i:o:q:t:y:cmwn:prs")) != EOF) + switch (c) { + case 'q': + priority = atoi(optarg); + break; + case 'H': + handling = optarg; + break; + case 'f': + form = optarg; + break; + case 'd': + printer = optarg; + break; + case 'T': + { + struct s5_types *tmp; + int flag = 0; + + for (tmp = output_types; + ((flag == 0) && (tmp->name != NULL)); tmp++) + if (strcasecmp(tmp->name, optarg) == 0) { + type = tmp->type; + flag++; + } + if (flag == 0) + s5type = optarg; + else + internal_type = optarg; + break; + } + case 'S': + charset = optarg; + break; + case 'o': + { + char *p, *q = strdup(optarg); + + /* + * -o nobanner will no longer generate a warning or + * Onobanner in the control file. If "nobanner" is + * embedded in an option list, the option list will + * still generate a warning or 'O' message in the + * control file. + */ + if (strcmp("nobanner", optarg) != 0) + s5options = (char **)list_append( + (void**)s5options, + (void *)strdup(optarg)); + + for (p = strtok(q, "\t ,"); p != NULL; + p = strtok(NULL, "\t ,")) + if (strcmp(p, "nobanner") == 0) { + banner = 0; + break; + } + } + break; + case 'y': + { + char *p, *q = strdup(optarg); + + for (p = strtok(q, "\t ,"); p != NULL; + p = strtok(NULL, "\t ,")) + if (strcmp(p, "catv_filter") == 0) + type = CF_PRINT_RAW; + else + mode = (char **)list_append( + (void **)mode, + (void *)p); + } + break; + case 'P': + pages = optarg; + break; + case 'i': + (void) printf(gettext( + "job modification (-i) only supported on server\n")); + break; + case 'c': + linked = 0; + break; + case 'm': + mail++; + break; + case 'w': + mail++; + break; + case 'p': + notification = optarg; + break; + case 'n': + if ((optarg == 0) || (*optarg == '-')) { + (void) fprintf(stderr, gettext( + "-n requires a positive integer argument\n")); + exit(1); + } + copies = atoi(optarg); + break; + case 's': + suppress = 1; + break; + case 't': + jobName = optarg; + break; + case 'r': + /* not supported - raw */ + break; + default: + (void) fprintf(stderr, + gettext("Usage: %s [-d dest] [-cmwsr] [-n num] " + "[-t title] [-p notification] [-P page-list] " + "[-i job-id] [y modes] [-o options] " + "[-S char-set] [-T input-type] [H handling] " + "[-q priority] files ...\n"), + av[0]); + exit(1); + } +} + + +/* + * stdin_to_file() reads standard input into a file and returns the file name + * to the caller + */ +static char * +stdin_to_file() +{ + int fd, + rc; + char *name, + buf[BUFSIZ]; + + (void) putenv("TMPDIR="); /* stop user moving the temp file */ + + snprintf(buf, sizeof (buf), "/tmp/stdinXXXXXX"); + if ((fd = mkstemp(buf)) < 0) + return (NULL); + fchmod(fd, 0640); + if ((name = strdup(buf)) == NULL) { + close(fd); + return (NULL); + } + syslog(LOG_DEBUG, "stdin_to_file: %s", name); + while ((rc = read(0, buf, sizeof (buf))) > 0) + (void) write(fd, buf, rc); + (void) close(fd); + return (name); +} + + +static int +sendfile(jobfile_t *file, int nd, int type) +{ + int rc = -1; + + syslog(LOG_DEBUG, "sendfile(%s, %d, %d)", + ((file != NULL) ? file->jf_spl_path : "NULL"), nd, type); + if (file && file->jf_spl_path) { + rc = net_send_file(nd, file->jf_spl_path, file->jf_data, + file->jf_size, type); + } + return (rc); +} + + +/* + * send_job() sends a job to a remote print server. + */ +static int +send_job(job_t *job) +{ + int lockfd, + lock_size, + nd, + tmp, + rc = 0; + struct passwd *p = NULL; + char buf[BUFSIZ]; + + syslog(LOG_DEBUG, "send_job(%s, %s, %d): called", job->job_printer, + job->job_server, job->job_id); + if ((lockfd = get_lock(job->job_cf->jf_src_path, 0)) < 0) { + (void) close(lockfd); + return (SEND_RETRY); + } + + /* is job complete ? */ + + lock_size = file_size(job->job_cf->jf_src_path); + (void) sprintf(buf, "%ld\n", getpid()); /* add pid to lock file */ + (void) lseek(lockfd, 0, SEEK_END); + (void) write(lockfd, buf, strlen(buf)); + + syslog(LOG_DEBUG, "send_job(%s, %s, %d): have lock", job->job_printer, + job->job_server, job->job_id); + connection_failed = 0; + if ((nd = net_open(job->job_server, 5)) < 0) { + connection_failed = 1; + if ((nd != NETWORK_ERROR_UNKNOWN) && (nd != NETWORK_ERROR_PORT)) + job_destroy(job); + else + (void) ftruncate(lockfd, lock_size); + (void) close(lockfd); + return ((nd == NETWORK_ERROR_UNKNOWN) || + (nd == NETWORK_ERROR_PORT) ? SEND_RETRY : SEND_ABORT); + } + + if (net_send_message(nd, "%c%s\n", XFER_REQUEST, job->job_printer) + != 0) { + (void) net_close(nd); + syslog(LOG_WARNING, + "send_job failed job %d (%s@%s) check status\n", + job->job_id, job->job_printer, job->job_server); + error_notify(job->job_user, job->job_id, + gettext("\t\t check queue for (%s@%s)\n"), + job->job_printer, job->job_server); + (void) ftruncate(lockfd, lock_size); + (void) close(lockfd); + return (SEND_RETRY); + } + + syslog(LOG_DEBUG, "send_job(%s, %s, %d): send data", job->job_printer, + job->job_server, job->job_id); + + if ((p = getpwnam(job->job_user)) != NULL) { + /* + * attempt to become the job owner: uid, euid, gid, and + * supplementary groups while we try to send the job data. + * The real uid is changed with setreuid() separately from + * changing the effective uid so that we retain the saved + * uid to elevate privilege later. Combining these changes + * would result in a change to the saved uid also and a loss + * of the ability to elevate privilege later. + */ + (void) setuid(0); + (void) initgroups(job->job_user, p->pw_gid); + (void) setgid(p->pw_gid); + (void) setreuid(p->pw_uid, -1); + (void) seteuid(p->pw_uid); + } + + for (tmp = 0; job->job_df_list[tmp] != NULL; tmp++) + if ((rc = sendfile(job->job_df_list[tmp], nd, XFER_DATA)) < 0) + break; /* there was an error, quit now */ + tmp = errno; + if (p != NULL) { + /* + * lose the supplemental groups and elevate our effective + * uid to root so that we can destroy jobs and/or become + * other job owners later on. + */ + (void) seteuid(0); + (void) initgroups("root", 1); + } + errno = tmp; + + if (rc < 0) { + if (errno == ENOENT) { + (void) net_close(nd); + error_notify(job->job_user, job->job_id, gettext( + "\t\tdata removed before transfer, job " + "canceled.\n\t\tTry \"lp -c\" or \"lpr\"\n")); + job_destroy(job); + (void) close(lockfd); + return (SEND_ABORT); + } else if (errno == EACCES) { + /* probably trying to circumvent file security */ + (void) net_close(nd); + error_notify(job->job_user, job->job_id, gettext( + "\t\tunable to read job data.\n")); + job_destroy(job); + (void) close(lockfd); + return (SEND_ABORT); + } else { + (void) net_close(nd); + (void) ftruncate(lockfd, lock_size); + error_notify(job->job_user, job->job_id, + gettext("\t\t check queue for (%s@%s)\n"), + job->job_printer, job->job_server); + (void) close(lockfd); + return (SEND_RETRY); + } + } + + if (sendfile(job->job_cf, nd, XFER_CONTROL) < 0) { + (void) net_send_message(nd, "%c\n", XFER_CLEANUP); + (void) net_close(nd); + (void) ftruncate(lockfd, lock_size); + error_notify(job->job_user, job->job_id, + gettext("\t\t check queue for (%s@%s)\n"), + job->job_printer, job->job_server); + (void) close(lockfd); + return (SEND_RETRY); + } + + syslog(LOG_DEBUG, "send_job(%s, %s, %d): complete", job->job_printer, + job->job_server, job->job_id); + (void) net_close(nd); + job_destroy(job); + (void) close(lockfd); + return (0); +} + + +/* + * xfer_daemon() attempts to start up a daemon for transfering jobs to a remote + * print server. The daemon runs if it can get the master lock, and it + * runs until there are no jobs waiting for transfer. + */ +static void +xfer_daemon() +{ + job_t **list = NULL; + int i, + rc; + + + + closelog(); + closefrom(0); + + _notified = 1; + (void) open("/dev/null", O_RDONLY); + (void) open("/dev/null", O_WRONLY); + (void) dup(1); + + (void) setuid(0); + (void) setsid(); + openlog("printd", LOG_PID, LOG_LPR); + if (fork() != 0) + exit(0); + + if ((i = get_lock(MASTER_LOCK, 1)) < 0) + exit(0); + + (void) chdir(SPOOL_DIR); + while ((list = job_list_append(NULL, NULL, NULL, SPOOL_DIR)) != NULL) { + job_t **tmp; + + syslog(LOG_DEBUG, "got the queue..."); + for (tmp = list; *tmp != NULL; tmp++) { + /* + * Bugid: 4133175 printd dies when data is removed or + * permissions are changed. Memory is freed twice. + * Fix: Do not process anything else in the list + * if the return code is SEND_ABORT as the memory + * has already been freed by job_destroy(). + */ + rc = send_job(*tmp); + if ((rc != 0) && (rc != SEND_ABORT)) { + char *s = strdup((*tmp)->job_server); + char *p = strdup((*tmp)->job_printer); + + if (rc != SEND_ABORT) /* already free */ + job_free(*tmp); + + for (tmp++; ((*tmp != NULL) && + (strcmp(s, (*tmp)->job_server) == 0)); + tmp++) + if ((connection_failed == 0) && + (strcmp(p, + (*tmp)->job_printer) == 0)) + job_free(*tmp); + else + break; + tmp--; + free(s); + free(p); + } + } + free(list); + + /* look for more work to do before we sleep */ + if ((list = job_list_append(NULL, NULL, NULL, + SPOOL_DIR)) != NULL) { + (void) list_iterate((void **)list, (VFUNC_T)job_free); + free(list); + (void) sleep(60); + } + } + syslog(LOG_DEBUG, "daemon exiting..."); +} + +static void +append_string(char *s, va_list ap) +{ + char *buf = va_arg(ap, char *); + + if (strlen(buf) != 0) + (void) strcat(buf, " "); + (void) strcat(buf, s); +} + + +static char * +build_string(char **list) +{ + int size = 0; + char *buf = NULL; + + if (list != NULL) { + size = list_iterate((void **)list, (VFUNC_T)strlen); + size += 16; + buf = malloc(size); + (void) memset(buf, NULL, size); + (void) list_iterate((void **)list, (VFUNC_T)append_string, buf); + } + return (buf); +} + + +#define ADD_PRIMATIVE(job, primative, value) \ + if ((job != NULL) && (value != NULL)) \ + (void) job_primative(job, primative, value); +#define ADD_SVR4_PRIMATIVE(job, primative, value) \ + if ((job != NULL) && (value != NULL)) (void) job_svr4_primative(job, \ + primative, value); + +#define ADD_INT_PRIMATIVE(job, primative, value, ok) \ + if ((job != NULL) && (value != ok)) { \ + (void) sprintf(buf, "%d", value); \ + (void) job_primative(job, primative, buf); \ + } +#define ADD_SVR4_INT_PRIMATIVE(job, primative, value, ok) \ + if ((job != NULL) && (value != ok)) { \ + (void) sprintf(buf, "%d", value); \ + (void) job_svr4_primative(job, primative, \ + buf); \ + } + +#define OPTION_ERROR(option, value) \ + if (value != NULL) \ + (void) fprintf(stderr, gettext("\tignoring: %s %s\n"), \ + option, value); + +#define OPTION_ERROR_INT(option, value) \ + if (value != -1) \ + (void) fprintf(stderr, gettext("\tignoring: %s %d\n"), \ + option, value); + + + +/* + * Main program. if called with "lpr" use the BSD syntax, if called + * with "lp", use the SYSV syntax. If called by any other name, + * become a transfer daemon. In the lpr/lp case, build a job and + * attempt to send it to the print server. If the server doesn't + * respond, become a daemon if none is currently running and attempt + * to xfer all waiting jobs. + */ +main(int ac, char *av[]) +{ + ns_bsd_addr_t *binding = NULL; + int numFiles = 0, + queueStdin = 0, + exit_code = 0; + char *program, + *user, + hostname[128], + buf[BUFSIZ]; + job_t *job; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + openlog(program, LOG_PID, LOG_LPR); + + /* + * Bugid: 4013980 Application changed fd 1 to a pipe that has + * no reader; we write to stdout and catch a sigpipe and exit. + * Fix: catch signal, complain to syslog, and continue. + */ + (void) signal(SIGPIPE, sigpipe_handler); + + if (check_client_spool(NULL) < 0) { + (void) fprintf(stderr, + gettext("couldn't validate local spool area (%s)\n"), + SPOOL_DIR); + return (-1); + } + if (strcmp(program, "lpr") == 0) { + if ((printer = getenv((const char *)"PRINTER")) == NULL) + printer = getenv((const char *)"LPDEST"); + bsd_options(ac, av); + } else if (strcmp(program, "lp") == 0) { + if ((printer = getenv((const char *)"LPDEST")) == NULL) + printer = getenv((const char *)"PRINTER"); + sysv_options(ac, av); + } else { + xfer_daemon(); + return (0); + } + + if (printer == NULL) { + ns_printer_t *pobj = ns_printer_get_name(NS_NAME_DEFAULT, NULL); + + if (pobj != NULL) { + printer = ns_get_value_string(NS_KEY_USE, pobj); + ns_printer_destroy(pobj); + } + + if (printer == NULL) + printer = NS_NAME_DEFAULT; + } + + if (printer == NULL) { + (void) fprintf(stderr, gettext("No default destination\n")); + return (1); + } + + if ((binding = ns_bsd_addr_get_name(printer)) == NULL) { + (void) fprintf(stderr, gettext("%s: unknown printer\n"), + printer); + return (1); + } + + if (rejecting(binding->printer) != 0) { + (void) fprintf(stderr, gettext( + "%s: requests are not being accepted\n"), + printer); + return (1); + } + + (void) sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); +#ifdef OLD_LP + /* + * If the server is local, there is lp server configuration, and + * the old lp is still hanging around, use it to submit the job. + */ + { + char cpath[MAXPATHLEN], + ppath[MAXPATHLEN]; + + (void) snprintf(ppath, sizeof (ppath), + "/etc/lp/printers/%s/configuration", binding->printer); + (void) snprintf(cpath, sizeof (cpath), + "/etc/lp/classes/%s", binding->printer); + if ((strcasecmp(binding->server, hostname) == 0) && + ((access(ppath, F_OK) == 0) || + (access(cpath, F_OK) == 0)) && + (access(OLD_LP, F_OK) == 0)) { + printer = binding->printer; + submit_local_lp(program, ac, av); + } + } +#endif + + if ((job = job_create(strdup(binding->printer), strdup(binding->server), + SPOOL_DIR)) == NULL) { + syslog(LOG_ERR, + "Error creating job: check spooling directory: %s", + SPOOL_DIR); + (void) fprintf(stderr, gettext( + "Error creating job: check spooling directory: %s\n"), + SPOOL_DIR); + return (-1); + } + + (void) umask(0); + user = get_user_name(); + + ADD_PRIMATIVE(job, CF_HOST, hostname); + ADD_PRIMATIVE(job, CF_USER, user); + ADD_PRIMATIVE(job, CF_TITLE, title); + + + if (banner != 0) { + if (jobName != NULL) { + ADD_PRIMATIVE(job, CF_JOBNAME, jobName); + } else if ((av[optind] == NULL) || + (strcmp(av[optind], "-") == 0)) { + ADD_PRIMATIVE(job, CF_JOBNAME, "standard input"); + } else { + ADD_PRIMATIVE(job, CF_JOBNAME, av[optind]); + } + ADD_PRIMATIVE(job, CF_CLASS, (class ? class : hostname)); + ADD_PRIMATIVE(job, CF_PRINT_BANNER, user); + } + + if (mail != 0) { + (void) snprintf(buf, sizeof (buf), "%s@%s", user, hostname); + ADD_PRIMATIVE(job, CF_MAIL, buf); + } + + ADD_INT_PRIMATIVE(job, CF_INDENT, indent, -1); /* ASCII */ + ADD_INT_PRIMATIVE(job, CF_WIDTH, width, -1); + + if ((type == CF_PRINT_DVI) || (type == CF_PRINT_DROFF) || + (type == CF_PRINT_TROFF)) { + ADD_PRIMATIVE(job, CF_FONT_TROFF_R, fontR); + ADD_PRIMATIVE(job, CF_FONT_TROFF_I, fontI); + ADD_PRIMATIVE(job, CF_FONT_TROFF_B, fontB); + ADD_PRIMATIVE(job, CF_FONT_TROFF_S, fontS); + } + + if (binding->extension == NULL) + binding->extension = ""; + + if ((strcasecmp(binding->extension, NS_EXT_SOLARIS) == 0) || + (strcasecmp(binding->extension, NS_EXT_GENERIC) == 0)) { + /* RFC1179 compliant don't get this */ + syslog(LOG_DEBUG, "main(): add Solaris extensions"); + ADD_PRIMATIVE(job, CF_SYSV_OPTION, build_string(s5options)); + ADD_SVR4_INT_PRIMATIVE(job, CF_SYSV_PRIORITY, priority, -1); + ADD_SVR4_PRIMATIVE(job, CF_SYSV_FORM, form); + ADD_SVR4_PRIMATIVE(job, CF_SYSV_CHARSET, charset); + ADD_SVR4_PRIMATIVE(job, CF_SYSV_NOTIFICATION, notification); + ADD_SVR4_PRIMATIVE(job, CF_SYSV_HANDLING, handling); + ADD_SVR4_PRIMATIVE(job, CF_SYSV_PAGES, pages); + if (s5type != NULL) { + ADD_SVR4_PRIMATIVE(job, CF_SYSV_TYPE, s5type); + } else if (internal_type != NULL) + ADD_SVR4_PRIMATIVE(job, CF_SYSV_TYPE, internal_type); + ADD_SVR4_PRIMATIVE(job, CF_SYSV_MODE, build_string(mode)); + } else if (strcasecmp(binding->extension, NS_EXT_HPUX) == 0) { + syslog(LOG_DEBUG, "main(): add HP-UX extensions"); + if (s5options != NULL) { + char buf[BUFSIZ]; + + (void) snprintf(buf, sizeof (buf), " O%s", + build_string(s5options)); + ADD_PRIMATIVE(job, CF_SOURCE_NAME, buf); + } + } else { + if ((s5options != NULL) || (form != NULL) || (pages != NULL) || + (charset != NULL) || (notification != NULL) || + (handling != NULL) || (s5type != NULL) || (mode != NULL) || + (priority != -1)) + (void) fprintf(stderr, gettext( + "Warning: %s not configured to handle all lp options:\n"), + printer); + OPTION_ERROR("-o", build_string(s5options)); + OPTION_ERROR("-f", form); + OPTION_ERROR("-P", pages); + OPTION_ERROR("-S", charset); + OPTION_ERROR("-p", notification); + OPTION_ERROR("-H", handling); + OPTION_ERROR("-T", s5type); + OPTION_ERROR("-y", build_string(mode)); + OPTION_ERROR_INT("-q", priority); + } + + syslog(LOG_DEBUG, "main(): add files"); + if (ac-optind > 0) { + while (optind < ac) + if (strcmp(av[optind++], "-") == 0) + queueStdin++; + else if (job_add_data_file(job, av[optind-1], title, + type, copies, linked, delete) < 0) { + switch (errno) { + case EISDIR: + (void) fprintf(stderr, gettext( + "%s: not a regular file\n"), + av[optind-1]); + break; + case ESRCH: + (void) fprintf(stderr, gettext( + "%s: empty file\n"), + av[optind-1]); + break; + case ENFILE: + (void) fprintf(stderr, gettext( + "too many files, ignoring %s\n"), + av[optind-1]); + break; + case EOVERFLOW: + (void) fprintf(stderr, gettext( + "%s: largefile (>= 2GB), ignoring\n"), + av[optind-1]); + break; + default: + perror(av[optind-1]); + } + exit_code = -1; + } else + numFiles++; + } else + queueStdin++; + + if (queueStdin != 0) { + char *name; + + /* standard input */ + if ((name = stdin_to_file()) != NULL) { + if (job_add_data_file(job, name, + gettext("standard input"), + type, copies, 0, 0) < 0) { + switch (errno) { + case ESRCH: + (void) fprintf(stderr, gettext( + "standard input empty\n")); + break; + case ENFILE: + (void) fprintf(stderr, gettext( + "too many files, ignoring standard input\n")); + break; + default: + perror(name); + } + exit_code = -1; + } else + numFiles++; + (void) unlink(name); + free(name); + } + } + + if (numFiles == 0) + return (-1); + + if (seteuid(0) < 0) + perror("seteuid(0)"); + + (void) signal(SIGBUS, sigbus_handler); + (void) chdir(SPOOL_DIR); + (void) job_store(job); + + if (suppress == 0) + if (numFiles == 1) + (void) printf( + gettext("request id is %s-%d (%d file)\n"), + printer, job->job_id, numFiles); + else + (void) printf( + gettext("request id is %s-%d (%d files)\n"), + printer, job->job_id, numFiles); + (void) fflush(stdout); + + /* + * bgolden 10/2/96 + * BUG 1264627 + * when executed from xemacs, a sighup will kill + * the child before the job is sent. ignore the signal + */ + (void) signal(SIGHUP, SIG_IGN); + + switch (fork()) { /* for immediate response */ + case -1: + syslog(LOG_ERR, "fork() failed: %m"); + break; + case 0: + break; + default: + return (exit_code); + } + + if (send_job(job) == SEND_RETRY) { + syslog(LOG_DEBUG, "main(): transfer failed"); + start_daemon(0); + } + else + syslog(LOG_DEBUG, "main(): transfer succeeded"); + + return (0); +} diff --git a/usr/src/cmd/print/lp/print-cleanup b/usr/src/cmd/print/lp/print-cleanup new file mode 100644 index 0000000000..7780bcd68b --- /dev/null +++ b/usr/src/cmd/print/lp/print-cleanup @@ -0,0 +1,47 @@ +#!/sbin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#pragma ident "%Z%%M% %I% %E% SMI" + +. /lib/svc/share/smf_include.sh + +case "$1" in +'start') + if [ -f /usr/lib/print/printd ]; then + rm -f /var/spool/print/tf* >/dev/null 2>&1 + /usr/lib/print/printd & + else + echo "Error: /usr/lib/print/printd missing." + exit $SMF_EXIT_ERR_CONFIG + fi + ;; + +*) + echo "Usage: $0 { start }" + exit 1 + ;; +esac +exit $SMF_EXIT_OK diff --git a/usr/src/cmd/print/lpget/Makefile b/usr/src/cmd/print/lpget/Makefile new file mode 100644 index 0000000000..a877ca51e7 --- /dev/null +++ b/usr/src/cmd/print/lpget/Makefile @@ -0,0 +1,72 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/client/lpget/Makefile +# + +include ../Makefile.sp + +PROG= lpget + +SRCS= $(PROG).c + +OBJS= $(SRCS:.c=.o) + +ROOTBINPROG= $(PROG:%=$(ROOTBIN)/%) + +FILEMODE= 0511 +OWNER= root + +CPPFLAGS += -I$(NPRTINC) +LDLIBS += $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) + +install: all $(ROOTBIN) $(ROOTBINPROG) + +$(ROOTBIN): + $(INS.dir) + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(PROG).c $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) diff --git a/usr/src/cmd/print/lpget/lpget.c b/usr/src/cmd/print/lpget/lpget.c new file mode 100644 index 0000000000..abe52330e0 --- /dev/null +++ b/usr/src/cmd/print/lpget/lpget.c @@ -0,0 +1,176 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <stdarg.h> +#include <unistd.h> +#include <string.h> +#include <syslog.h> +#include <locale.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif + +#include <print/ns.h> +#include <print/misc.h> +#include <print/list.h> + +extern char *optarg; +extern int optind, opterr, optopt; +extern char *getenv(const char *); + + +static void +Usage(char *name) +{ + (void) fprintf(stderr, + gettext("Usage: %s [-k key] [list|(printer) ...]\n"), + name); + exit(1); +} + +static int +display_kvp(char *key, char *value) +{ + int rc = -1; + + if (value != NULL) { + rc = 0; + (void) printf("\n\t%s=%s", key, value); + } else + (void) printf(gettext("\n\t%s - undefined"), key); + + return (rc); +} + + +static int +display_value(ns_printer_t *printer, char *name, char **keys) +{ + int rc = -1; + + if (printer != NULL) { + rc = 0; + (void) printf("%s:", name); + if (keys != NULL) { + while (*keys != NULL) { + char *string = ns_get_value_string(*keys, + printer); + rc += display_kvp(*keys, string); + keys++; + } + } else { + ns_kvp_t **list = printer->attributes; + + for (list = printer->attributes; + (list != NULL && *list != NULL); list++) { + char *string; + if (((*list)->key[0] == '\t') || + ((*list)->key[0] == ' ')) + continue; + + string = ns_get_value_string((*list)->key, + printer); + rc += display_kvp((*list)->key, string); + } + } + (void) printf("\n"); + } else + (void) printf(gettext("%s: Not Found\n"), name); + + return (rc); +} + + +/* + * main() calls the appropriate routine to parse the command line arguments + * and then calls the local remove routine, followed by the remote remove + * routine to remove jobs. + */ +int +main(int ac, char *av[]) +{ + char *program; + int c; + char **keys = NULL; + char *ns = NULL; + int exit_code = 0; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + openlog(program, LOG_PID, LOG_LPR); + while ((c = getopt(ac, av, "k:t:n:")) != EOF) + switch (c) { + case 'k': + case 't': + keys = (char **)list_append((void **)keys, + (void *)optarg); + break; + case 'n': + ns = optarg; + break; + default: + Usage(program); + } + + if (optind >= ac) + Usage(program); + + ns = normalize_ns_name(ns); + + while (optind < ac) { + char *name = av[optind++]; + + if (strcmp(name, "list") == 0) { + ns_printer_t **printers = ns_printer_get_list(ns); + + while (printers != NULL && *printers != NULL) { + exit_code += display_value(*printers, + (*printers)->name, keys); + printers++; + } + } else + exit_code = display_value(ns_printer_get_name(name, ns), + name, keys); + + + } + return (exit_code); +} diff --git a/usr/src/cmd/print/lpmove/Makefile b/usr/src/cmd/print/lpmove/Makefile new file mode 100644 index 0000000000..7892c91c36 --- /dev/null +++ b/usr/src/cmd/print/lpmove/Makefile @@ -0,0 +1,77 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/client/lpmove/Makefile +# + +include ../Makefile.sp + +PROG= lpmove + +SRCS= $(PROG).c + +OBJS= $(SRCS:.c=.o) + +ROOTUSRSBINPROG= $(PROG:%=$(ROOTUSRSBIN)/%) +ROOTUSRLIBSYMLINK= $(PROG:%=$(ROOTLIB)/%) + +FILEMODE= 04511 +OWNER= root + +CPPFLAGS += -I$(NPRTINC) +LDLIBS += $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) + +install: all $(ROOTUSRSBIN) $(ROOTUSRSBINPROG) $(ROOTUSRLIBSYMLINK) + + +$(ROOTUSRSBIN): + $(INS.dir) + +$(ROOTUSRLIBSYMLINK): + $(RM) $@; $(SYMLINK) ../sbin/$(PROG) $@ + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(PROG).c $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) diff --git a/usr/src/cmd/print/lpmove/lpmove.c b/usr/src/cmd/print/lpmove/lpmove.c new file mode 100644 index 0000000000..c74f2fa406 --- /dev/null +++ b/usr/src/cmd/print/lpmove/lpmove.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, Version 1.0 only + * (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 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdarg.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <syslog.h> +#include <locale.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/list.h> +#include <print/job.h> + +/* + * lpr/lp + * This program will submit print jobs to a spooler using the BSD + * printing protcol as defined in RFC1179, plus some extension for + * support of additional lp functionality. + */ + +extern char *optarg; +extern int optind, opterr, optopt; +extern char *getenv(const char *); + + +/* + * creates a new job moves/modifies control data and data files. + * If a job is moved, we should return 1 regardless of whether we + * killed the daemon or not. This will allow us to attempt to start + * the transfer agent for any jobs in /var/spool/print. + */ +static int +vjob_reset_destination(job_t *job, va_list ap) +{ + char *user = va_arg(ap, char *), + buf[BUFSIZ]; + int id = va_arg(ap, int), + lock; + ns_bsd_addr_t *src = va_arg(ap, ns_bsd_addr_t *), + *dst = va_arg(ap, ns_bsd_addr_t *); + + + if ((id != -1) && (job->job_id != id)) + return (0); + if (strcmp(job->job_server, src->server) != 0) + return (0); + if ((strcmp(user, "root") != 0) && + (strcmp(user, job->job_user) != 0)) + return (0); + + while ((lock = get_lock(job->job_cf->jf_src_path, 0)) < 0) + (void) kill_process(job->job_cf->jf_src_path); + + /* just do it */ + (void) snprintf(buf, sizeof (buf), "%s:%s\n", dst->server, + dst->printer); + (void) ftruncate(lock, 0); + (void) write(lock, buf, strlen(buf)); + (void) close(lock); + (void) printf(gettext("moved: %s-%d to %s-%d\n"), src->printer, + job->job_id, dst->printer, job->job_id); + return (1); +} + + +static int +job_move(char *user, int id, ns_bsd_addr_t *src_binding, + ns_bsd_addr_t *dst_binding) +{ + job_t **list = NULL; + int rc = 0; + + if ((list = job_list_append(NULL, src_binding->printer, + src_binding->server, SPOOL_DIR)) != NULL) + rc = list_iterate((void **)list, + (VFUNC_T)vjob_reset_destination, user, id, + src_binding, dst_binding); + return (rc); + +} + +/* + * move print jobs from one queue to another. This gets the lock + * file (killing the locking process if necessary), Moves the jobs, and + * restarts the transfer daemon. + */ + +#define OLD_LPMOVE "/usr/lib/lp/local/lpmove" + +main(int ac, char *av[]) +{ + char *program = NULL, + *dst = NULL, + *user = get_user_name(); + char **argv = NULL; + int remote_moved = 0, + i, argc = 0; + ns_bsd_addr_t * dst_binding; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + openlog(program, LOG_PID, LOG_LPR); + + if (access(OLD_LPMOVE, F_OK) == 0) { /* copy args for local move */ + if ((argv = (char **)calloc(ac + 1, sizeof (char *))) == NULL) { + fprintf(stderr, gettext("lpmove: out of memory\n")); + exit(1); + } + + if (av[0] != NULL) + argv[argc++] = strdup(av[0]); + } + + (void) chdir(SPOOL_DIR); + + /* + * Get the destination; use binding to set it; the input may + * be an alias, not a printer name + */ + dst = av[--ac]; + if ((dst_binding = ns_bsd_addr_get_name(dst)) == NULL) { + (void) fprintf(stderr, gettext("%s: unknown printer\n"), dst); + return (-1); + } + + /* + * Decrement orig arg count so the following for() loop iterates for + * each source request or destination. Also, when we later check if + * there are local jobs to move, we will be comparing number of remote + * requests moved with the total number supplied. + */ + ac--; + + for (i = 1; i <= ac; i++) { + ns_bsd_addr_t *src_binding = NULL; + char *src = av[i], *s, *str; + int id = -1; + + /* + * if the argument contains a '-', see if it is a request + * or a printer. + */ + if ((s = strrchr(src, '-')) != NULL) { + *(s++) = NULL; + + errno = 0; + id = strtol(s, &str, 10); + if (((id <= 0) && (errno != 0)) || (*str != NULL)) { + id = -1; + *(--s) = '-'; + } + } + + /* + * get the binding for the printer, so we can use the printer + * name from the binding to move the job(s) + */ + if ((src_binding = ns_bsd_addr_get_name(src)) == NULL) { + (void) fprintf(stderr, + gettext("%s: unknown printer\n"), src); + return (-1); + } + + if (job_move(user, id, src_binding, dst_binding) == 0) { + /* + * There was nothing "remote" to move, so add it to the + * list of "local" items to move. Use the printer name + * from the binding, because that is the one that + * lpsched is most likely to understand. + */ + char buf[BUFSIZ]; + + (void) snprintf(buf, sizeof (buf), "%s%s%s", + src_binding->printer, + (id == -1 ? "" : "-"), + (id == -1 ? "" : s)); + argv[argc++] = strdup(buf); + } else + remote_moved++; + } + + /* if we moved a "remote" job(s), try to (re)start the transfer agent */ + if (remote_moved != 0) + start_daemon(1); + + /* if there is something "local" to move, try it */ + if ((argv != NULL) && (remote_moved != ac)) { + argv[argc++] = strdup(dst_binding->printer); + + /* limit ourselves to real user's perms before exec'ing */ + (void) setuid(getuid()); + (void) execv(OLD_LPMOVE, argv); + } + + return (0); +} diff --git a/usr/src/cmd/print/lpset/Makefile b/usr/src/cmd/print/lpset/Makefile new file mode 100644 index 0000000000..f284604b5e --- /dev/null +++ b/usr/src/cmd/print/lpset/Makefile @@ -0,0 +1,72 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/client/lpset/Makefile +# + +include ../Makefile.sp + +PROG= lpset + +SRCS= $(PROG).c + +OBJS= $(SRCS:.c=.o) + +ROOTBINPROG= $(PROG:%=$(ROOTBIN)/%) + +FILEMODE= 04511 +OWNER= root + +CPPFLAGS += -I$(NPRTINC) +LDLIBS += $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) + +install: all $(ROOTBIN) $(ROOTBINPROG) + +$(ROOTBIN): + $(INS.dir) + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(PROG).c $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) diff --git a/usr/src/cmd/print/lpset/lpset.c b/usr/src/cmd/print/lpset/lpset.c new file mode 100644 index 0000000000..716065c470 --- /dev/null +++ b/usr/src/cmd/print/lpset/lpset.c @@ -0,0 +1,537 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 1998-2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <stdarg.h> +#include <unistd.h> +#include <limits.h> +#include <string.h> +#include <syslog.h> +#include <errno.h> +#include <locale.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif +#include <pwd.h> + +#include <print/ns.h> +#include <print/misc.h> +#include <print/list.h> + +extern char *optarg; +extern int optind, opterr, optopt; +extern char *getenv(const char *); + +static void _decode_ldapResult(int result, char *printerName); + +static void +Usage(char *name) +{ + (void) fprintf(stderr, + gettext("Usage: %s [-n files | nisplus | ldap] [-x] " + "[-h ldaphost] [-D binddn] [-w passwd] " + "[-a key=value] [-d key] (printer)\n"), + name); + exit(1); +} + + +/* + * main() calls the appropriate routine to parse the command line arguments + * and then calls the local remove routine, followed by the remote remove + * routine to remove jobs. + */ +int +main(int ac, char *av[]) +{ + int result = 0; + int delete_printer = 0; + int c; + char *program = NULL, + *printer = NULL, + *host = NULL, + *binddn = NULL, + *passwd = NULL, + *ins = NULL, + *ons = "files"; + char **changes = NULL; + ns_cred_t *cred = NULL; + ns_printer_t *printer_obj = NULL; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + openlog(program, LOG_PID, LOG_LPR); + + if (ac < 2) + Usage(program); + + while ((c = getopt(ac, av, "a:d:D:h:n:r:w:x")) != EOF) + switch (c) { + case 'd': + if (strchr(optarg, '=') != NULL) + Usage(program); + /* FALLTHRU */ + case 'a': + changes = (char **)list_append((void**)changes, + (void *)strdup(optarg)); + break; + case 'D': + binddn = optarg; + break; + case 'h': + host = optarg; + break; + case 'n': + ons = optarg; + break; + case 'r': + ins = optarg; + break; + case 'w': + passwd = optarg; + break; + case 'x': + delete_printer++; + break; + default: + Usage(program); + } + + if (optind != ac-1) + Usage(program); + + /* + * Check required options have been given: [ -x | [ -a | -d ]] + */ + if ((changes == NULL) && (delete_printer == 0)) { + Usage(program); + } + + printer = av[optind]; + + if (strchr(printer, ':') != NULL) { + (void) fprintf(stderr, gettext( + "POSIX-Style names are not valid destinations (%s)\n"), + printer); + return (1); + } + + ins = normalize_ns_name(ins); + ons = normalize_ns_name(ons); + if (ins == NULL) + ins = ons; + + /* check / set the name service for writing */ + if (strcasecmp("user", ons) == 0) { + (void) setuid(getuid()); + ons = "user"; + } else if (strcasecmp("files", ons) == 0) { + struct passwd *pw = getpwnam("lp"); + uid_t uid, lpuid = 0; + + if (pw != NULL) + lpuid = pw->pw_uid; + uid = getuid(); + if ((uid != 0) && (uid != lpuid)) { + int len; + gid_t list[NGROUPS_MAX]; + + len = getgroups(sizeof (list), list); + if (len == -1) { + (void) fprintf(stderr, gettext( + "Call to getgroups failed with " + "errno %d\n"), errno); + return (1); + } + + for (; len >= 0; len--) + if (list[len] == 14) + break; + + if (len == -1) { + (void) fprintf(stderr, gettext( + "Permission denied: not in group 14\n")); + return (1); + } + } + ons = "files"; + } else if (strcasecmp("nisplus", ons) == 0) { + ons = "nisplus"; + } else if (strcasecmp("ldap", ons) == 0) { + if ((cred = calloc(1, sizeof (*cred))) == NULL) { + (void) fprintf(stderr, + gettext("could not initialize credential\n")); + return (1); + } + + if (binddn == NULL) { + (void) fprintf(stderr, + gettext("Distinguished Name is required.\n")); + return (1); + } + + if (passwd == NULL) { + passwd = getpassphrase(gettext("Bind Password:")); + } + + /* + * Setup LDAP bind credentials, so that it uses + * the default ldap port, and the NS domain for this + * ldapclient box. Note: passwdType is currently not + * used but once the ldap native function can select + * secure or insure password it will pass the user selected + * security type. + */ + cred->passwd = passwd; + cred->passwdType = NS_PW_INSECURE; /* use default */ + cred->binddn = binddn; + cred->host = host; + cred->port = 0; /* use default */ + cred->domainDN = NULL; /* use default */ + + ons = "ldap"; + (void) setuid(getuid()); + } else { + (void) fprintf(stderr, + gettext("%s is not a supported name service.\n"), + ons); + return (1); + } + + if (strcasecmp(NS_SVC_LDAP, ons) != 0) { + + /* Naming Service is not LDAP */ + + /* get the printer object */ + if ((printer_obj = ns_printer_get_name(printer, ins)) == NULL) { + if (delete_printer != 0) { + (void) fprintf(stderr, gettext("%s: unknown printer\n"), + printer); + return (1); + } + if ((printer_obj = calloc(1, sizeof (*printer_obj))) == NULL) { + (void) fprintf(stderr, gettext( + "could not initialize printer object\n")); + return (1); + } + printer_obj->name = strdup(printer); + } + + printer_obj->source = ons; + + if (cred != NULL) { + printer_obj->cred = cred; + } + + /* make the changes to it */ + while (changes != NULL && *changes != NULL) { + int has_equals = (strchr(*changes, '=') != NULL); + char *p, *key = NULL, *value = NULL; + + key = *(changes++); + + for (p = key; ((p != NULL) && (*p != NULL)); p++) + if (*p == '=') { + *p = NULL; + value = ++p; + break; + } else if (*p == '\\') + p++; + + if ((value != NULL) && (*value == NULL)) + value = NULL; + + if ((key != NULL) && (key[0] != NULL)) { + if ((value == NULL) && + (ns_get_value(key, printer_obj) == NULL) && + (has_equals == 0)) { + fprintf(stderr, + gettext("%s: unknown attribute\n"), + key); + result = 1; + } else + (void) ns_set_value_from_string(key, value, + printer_obj); + } + } + if (delete_printer != 0) + printer_obj->attributes = NULL; + + /* write it back */ + if (ns_printer_put(printer_obj) != 0) { + (void) fprintf(stderr, + gettext("Failed to write into %s database\n"), + ons); + result = 1; + } + } + + else { + /* + * Naming Service is LDAP + * + * Action the request by calling ns ldap functions to + * add, modify or delete the printer object. + */ + + if ((printer_obj = calloc(1, sizeof (*printer_obj))) == NULL) { + (void) fprintf(stderr, gettext( + "could not initialize printer object\n")); + return (1); + } + + if ((cred != NULL) && (printer_obj != NULL)) { + printer_obj->name = strdup(printer); + printer_obj->cred = cred; + printer_obj->cred->domainDN = NULL; /* use default */ + printer_obj->source = ons; + printer_obj->nsdata = malloc(sizeof (NS_LDAPDATA)); + + if (printer_obj->nsdata != NULL) { + /* + * Update the LDAP directory for this printer + */ + + if (delete_printer != 0) { + /* Delete the printer object */ + ((NS_LDAPDATA *) + (printer_obj->nsdata))->attrList = NULL; + } else { + /* Add or modify the printer object */ + ((NS_LDAPDATA *) + (printer_obj->nsdata))->attrList = + changes; + } + + result = ns_printer_put(printer_obj); + if (result != 0) { + /* display LDAP specific message */ + _decode_ldapResult(result, printer); + + (void) fprintf(stderr, gettext( + "Failed to update %s database\n"), ons); + result = 1; + } + + free(printer_obj->nsdata); + } + + else { + _decode_ldapResult(NSL_ERR_MEMORY, NULL); + result = 1; + } + } + + else { + result = 1; + (void) fprintf(stderr, + gettext("Error - no LDAP credentials\n")); + } + + if (printer_obj != NULL) { + if (printer_obj->name != NULL) { + free(printer_obj->name); + } + free(printer_obj); + } + + } + + return (result); +} /* main */ + + + + +/* + * ***************************************************************************** + * + * Function: _decode_ldapResult() + * + * Description: Decode the ldap_put_printer specific error codes and display + * the appropriate error message. + * + * Parameters: + * Input: int result - contains the NSL_RESULT codes + * char *printerName - name of printer + * Output: None + * + * Returns: void + * + * ***************************************************************************** + */ + +static void +_decode_ldapResult(int result, char *printerName) + +{ + NSL_RESULT lresult = (NSL_RESULT)result; + + /* ------------- */ + + switch (lresult) + { + case NSL_OK: + { + break; + } + + case NSL_ERR_INTERNAL: + { + (void) fprintf(stderr, + gettext("Unexpected software error\n")); + break; + } + + case NSL_ERR_ADD_FAILED: + { + (void) fprintf(stderr, "%s %s\n", + gettext("Failed to add printer:"), printerName); + break; + } + + case NSL_ERR_MOD_FAILED: + { + (void) fprintf(stderr, "%s %s\n", + gettext("Failed to modify printer:"), + printerName); + break; + } + + case NSL_ERR_DEL_FAILED: + { + (void) fprintf(stderr, "%s %s\n", + gettext("Failed to delete printer:"), + printerName); + break; + } + + + case NSL_ERR_UNKNOWN_PRINTER: + { + (void) fprintf(stderr, "%s %s\n", + gettext("Unknown printer:"), printerName); + break; + } + + case NSL_ERR_CREDENTIALS: + { + (void) fprintf(stderr, "%s\n", + gettext("Missing LDAP credential information for printer:")); + break; + } + + case NSL_ERR_CONNECT: + { + (void) fprintf(stderr, "%s\n", + gettext("Failed to connect to LDAP server")); + break; + } + + case NSL_ERR_BIND: + { + (void) fprintf(stderr, gettext("LDAP bind failed\n")); + break; + } + + case NSL_ERR_RENAME: + { + (void) fprintf(stderr, "%s %s\n", + gettext("Object rename not allowed for printer:"), + printerName); + break; + } + + case NSL_ERR_KVP: + { + (void) fprintf(stderr, "%s", + gettext("Setting sun-printer-kvp attribute is " + "not supported through this command.\n")); + break; + } + + case NSL_ERR_BSDADDR: + { + (void) fprintf(stderr, "%s", + gettext("Setting sun-printer-bsdaddr attribute is " + "not supported through this command.\n" + "Use the bsaddr attribute instead.\n")); + break; + } + + case NSL_ERR_PNAME: + { + (void) fprintf(stderr, "%s", + gettext("Setting printer-name attribute is " + "not supported through this command.\n")); + break; + } + + case NSL_ERR_MEMORY: + { + (void) fprintf(stderr, + gettext("Memory allocation error\n")); + break; + } + + case NSL_ERR_MULTIOP: + { + (void) fprintf(stderr, + gettext("Delete and add operation on the " + "same key attribute is not allowed\n")); + break; + } + + case NSL_ERR_NOTALLOWED: + { + (void) fprintf(stderr, + gettext("KVP attribute is not allowed\n")); + break; + } + + default: + { + (void) fprintf(stderr, + gettext("Error code = %d\n"), result); + break; + } + } + +} /* _decode_ldapResult */ diff --git a/usr/src/cmd/print/lpstat/Makefile b/usr/src/cmd/print/lpstat/Makefile new file mode 100644 index 0000000000..0759bea8d7 --- /dev/null +++ b/usr/src/cmd/print/lpstat/Makefile @@ -0,0 +1,80 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/client/lpstat/Makefile +# + +include ../Makefile.sp + +PROG= lpstat + +SRCS= lpstat.c sysv-functions.c bsd-functions.c parse_bsd.c + +OBJS= $(SRCS:.c=.o) + +ROOTBINPROG= $(PROG:%=$(ROOTBIN)/%) +ROOTUSRBINSYMLINK= $(ROOTUSRUCB)/lpq + +FILEMODE= 04511 +OWNER= root + +CPPFLAGS += -I. -I$(NPRTINC) +LDLIBS += $(LIBNPRT) + +.KEEP_STATE: + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +install: all $(ROOTBIN) $(ROOTBINPROG) $(ROOTUSRBINSYMLINK) + +$(ROOTBIN): + $(INS.dir) + +$(ROOTUSRBINSYMLINK): + $(RM) $@; $(SYMLINK) ../bin/$(PROG) $@ + +strip: + $(STRIP) $(PROG) + +lint: + $(LINT.c) $(SRCS) $(LDLIBS) + +cstyle: + cstyle $(SRCS) + +_msg: + @echo "Messages are made in usr/src/cmd/print" + +clean: + $(RM) $(OBJS) + +clobber: clean + -$(RM) $(PROG) $(CLOBBERFILES) diff --git a/usr/src/cmd/print/lpstat/bsd-functions.c b/usr/src/cmd/print/lpstat/bsd-functions.c new file mode 100644 index 0000000000..8b5b42fe46 --- /dev/null +++ b/usr/src/cmd/print/lpstat/bsd-functions.c @@ -0,0 +1,256 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/fcntl.h> +#include <ctype.h> +#include <string.h> +#include <unistd.h> +#include <stdarg.h> +#include <syslog.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif +extern char *getenv(const char *); + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/list.h> +#include <print/job.h> + +#include "bsd-functions.h" + + +static char *order[] = { + "", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th" }; + +static char * +show_rank(int i) +{ + static char rank[12]; + if ((i%100)/10 == 1) + (void) sprintf(rank, "%dth", i); + else + (void) sprintf(rank, "%d%s", i, order[i%10]); + return (rank); +} + + +static int +vadd_file(jobfile_t *file, va_list ap) +{ + char *mesg = va_arg(ap, char *); + + if (file != NULL) { + (void) strlcat(mesg, file->jf_name, BUFSIZ); + (void) strlcat(mesg, " ", BUFSIZ); + return (file->jf_size); + } + return (0); +} + +/*ARGSUSED*/ +static int +vprint_file(jobfile_t *file, va_list ap) +{ + if (file != NULL) + (void) printf("\t%-33.33s%ld bytes\n", file->jf_name, + file->jf_size); + return (0); +} + +static int +vprint_job(job_t *job, va_list ap) +{ + int jobSize = 0, + *rank, + format, + curr, + printIt = 0, + ac; + char fileList[BUFSIZ], + *printer, + **av; + + printer = va_arg(ap, char *); + format = va_arg(ap, int); + rank = va_arg(ap, int *); + ac = va_arg(ap, int); + av = va_arg(ap, char **); + + if (strcmp(job->job_printer, printer) != 0) + return (0); + + if (ac > 0) { + for (curr = 0; curr < ac; curr++) + if ((av[curr][0] >= '0') && (av[curr][0] <= '9') && + (job->job_id == atoi(av[curr])) || + (strcmp(job->job_user, av[curr]) == 0)) { + printIt++; + break; + } + } else + printIt++; + + if (printIt != 0) { + if (format == SHOW_QUEUE_SHORT_REQUEST) { + (void) memset(fileList, 0, sizeof (fileList)); + jobSize = list_iterate((void **)job->job_df_list, + (VFUNC_T)vadd_file, fileList); + (void) printf( + "%-7.7s%-8.8s %3.3d %-38.38s%d bytes\n", + show_rank((*rank)++), job->job_user, + job->job_id, fileList, jobSize); + } else { + (void) printf("%s: %-7.7s \t\t\t\t [job %.3d%s]\n", + job->job_user, show_rank((*rank)++), + job->job_id, job->job_host); + (void) list_iterate((void **)job->job_df_list, + (VFUNC_T)vprint_file); + (void) printf("\n"); + } + } + return (0); +} + +static int +vjob_count(job_t *job, va_list ap) +{ + int curr, + ac; + char *printer, + **av; + + printer = va_arg(ap, char *); + ac = va_arg(ap, int); + av = va_arg(ap, char **); + + if (strcmp(job->job_printer, printer) != 0) + return (0); + + if (ac == 0) + return (1); + + for (curr = 0; curr < ac; curr++) + if ((av[curr][0] >= '0') && (av[curr][0] <= '9') && + (job->job_id == atoi(av[curr])) || + (strcmp(job->job_user, av[curr]) == 0)) + return (1); + + return (0); +} + + +void +clear_screen() /* for now use tput rather than link in UCB stuff */ +{ + (void) system("/bin/tput clear"); +} + + +int +bsd_queue(ns_bsd_addr_t *binding, int format, int ac, char *av[]) +{ + char *server = NULL, + *printer = NULL; + job_t **list = NULL; + int nd = -1, + idle = 0, + rc; + + server = binding->server; + printer = binding->printer; + + if ((nd = net_open(server, 15)) >= 0) { + char buf[BUFSIZ]; + + (void) memset(buf, 0, sizeof (buf)); + while (ac--) { /* potential SEGV if av's are more than BUFSIZ */ + (void) strlcat(buf, av[ac], sizeof (buf)); + if (strlcat(buf, " ", sizeof (buf)) >= sizeof (buf)) { + syslog(LOG_ERR, "bsd_queue: buffer overflow"); + } + } + + rc = net_printf(nd, "%c%s %s\n", format, printer, buf); + if (rc < 0) + syslog(LOG_ERR, "net_printf() failed: %m"); +#ifdef SUNOS_4 + do { + (void) memset(buf, 0, sizeof (buf)); + if ((ac = net_read(nd, buf, sizeof (buf))) > 0) + (void) printf("%s", buf); + } while (ac > 0); +#else + while (memset(buf, 0, sizeof (buf)) && + (net_read(nd, buf, sizeof (buf)) > 0)) { + (void) printf("%s", buf); + if (strstr(buf, "no entries") != 0) + idle = 1; + } +#endif + + (void) net_close(nd); + } + + if (nd < 0) { + if (server != NULL) + (void) fprintf(stderr, gettext( + "could not talk to print service at %s\n"), + server); + else + (void) fprintf(stderr, gettext( + "could not locate server for printer: %s\n"), + printer); + } + + if (((list = job_list_append(NULL, printer, + server, SPOOL_DIR)) != NULL) && + (list_iterate((void **)list, (VFUNC_T)vjob_count, printer, + ac, av) != 0)) { + if ((nd < 0) && (format == SHOW_QUEUE_SHORT_REQUEST)) + (void) printf(gettext( + "Rank\tOwner Job\tFiles\t\t\t\t\tTotal Size\n")); + } + + if (format == SHOW_QUEUE_LONG_REQUEST) + (void) printf("\n"); + + nd = 1; + (void) list_iterate((void **)list, (VFUNC_T)vprint_job, printer, format, + &nd, ac, av); + + if ((idle == 1) && (list == NULL)) + return (1); + else + return (0); +} diff --git a/usr/src/cmd/print/lpstat/bsd-functions.h b/usr/src/cmd/print/lpstat/bsd-functions.h new file mode 100644 index 0000000000..b12adedc84 --- /dev/null +++ b/usr/src/cmd/print/lpstat/bsd-functions.h @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ifndef _BSD_FUNCTIONS_H +#define _BSD_FUNCTIONS_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +extern int bsd_queue(ns_bsd_addr_t *binding, int format, int ac, char *av[]); +extern void clear_screen(); + +#ifdef __cplusplus +} +#endif + + +#endif /* _BSD_FUNCTIONS_H */ diff --git a/usr/src/cmd/print/lpstat/lpstat.c b/usr/src/cmd/print/lpstat/lpstat.c new file mode 100644 index 0000000000..199d0aee52 --- /dev/null +++ b/usr/src/cmd/print/lpstat/lpstat.c @@ -0,0 +1,806 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 1998-2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/fcntl.h> +#include <ctype.h> +#include <string.h> +#include <stdarg.h> +#include <unistd.h> +#include <syslog.h> +#include <locale.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif +#include <sys/systeminfo.h> +#include <sys/param.h> +#include <errno.h> +#include <netdb.h> + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/list.h> +#include <print/job.h> + +#include "parse.h" +#include "sysv-functions.h" +#include "bsd-functions.h" + +extern char *optarg; +extern int optind, opterr, optopt; +extern char *getenv(const char *); +extern char *getname(void); + +static int exit_code = 0; +static int _processing_all = 0; + + +static ns_bsd_addr_t **_printer_bindings = NULL; +static ns_bsd_addr_t **_printer_bindings_unique = NULL; + + +static int sysvVerbose = 0; +static int sysvDesc = 0; +static int sysvLocal = 0; + +static int bsdFormat = SHOW_QUEUE_SHORT_REQUEST; +static int bsdInterval = 0; +static char **bsdv; +static int bsdc; + +typedef enum _work_type work_type_t; +typedef struct _work_entry work_entry_t; + +enum _work_type { ACCEPTING, DEFAULT, ENTRIES, STATUS, RUNNING, RANK, SUMMARY, + FULL, USER, DEVICE, FORMS, CLASSES, CHAR_SETS, BSD_QUEUE }; +struct _work_entry { + ns_bsd_addr_t *binding; + char *printer; + char *user; + int id; + work_type_t type; +}; + +static work_entry_t **workList = NULL; + + +static void +work_list_append(char *printer, char *user, int id, work_type_t type) +{ + work_entry_t *tmp = (work_entry_t *)calloc(1, sizeof (work_entry_t)); + + if (tmp == NULL) + return; + if (user != NULL) + tmp->user = strdup(user); + tmp->id = id; + tmp->type = type; + if (printer != NULL) { + tmp->printer = strdup(printer); + if ((tmp->binding = ns_bsd_addr_get_name(printer)) != NULL) + workList = (work_entry_t **)list_append( + (void **)workList, + (void *)tmp); + else if (strcmp(printer, NS_NAME_DEFAULT) == 0) { + (void) fprintf(stderr, + gettext("No default destination\n")); + exit_code = 1; + } else { + (void) fprintf(stderr, gettext("%s: unknown printer\n"), + printer); + exit_code = 1; + } + } else + workList = (work_entry_t **)list_append((void **)workList, + (void *)tmp); +} + + +static char * +check_for_req_id(char *name) +{ + char *p; + char *p1; + + /* request id has the form <name>-<number> */ + p1 = name + strlen(name); + if (p1 == name) + return (NULL); + p = p1 - 1; + while (p > name && isdigit(*p)) + p--; + if (*p != '-' || p == name) + return (NULL); + else + return (p); +} + +static void +work_list_append_list(char *list, work_type_t type) +{ + char *p; + char *elem; + + if (list == NULL) { + work_list_append(NULL, NULL, -1, type); + return; + } + + for (elem = strtok(list, "\t ,"); elem != NULL; + elem = strtok(NULL, "\t ,")) { + switch (type) { + case RANK: + case ACCEPTING: + case STATUS: + case DEVICE: + work_list_append(elem, NULL, -1, type); + break; + case CHAR_SETS: + case CLASSES: + case FORMS: + case USER: + work_list_append(NULL, elem, -1, type); + break; + case ENTRIES: + if ((p = check_for_req_id(elem)) == NULL) + work_list_append(elem, NULL, -1, ENTRIES); + else if (ns_bsd_addr_get_name(elem) != NULL) + work_list_append(elem, NULL, -1, ENTRIES); + else { + *p++ = '\0'; + work_list_append(elem, NULL, atoi(p), ENTRIES); + } + break; + } + } +} + +static char * +lpstat_opt(work_type_t type) +{ + switch (type) { + case STATUS: + return ("-p"); + case RANK: + return ("-R"); + case USER: + return ("-u"); + case ENTRIES: + return ("-o"); + default: + return (NULL); + } +} + +/* + * This function is for a performance improvement. + */ + +static int +is_local_printer(char *server, char *printer) +{ + static char *hostname, hbuf[MAXHOSTNAMELEN]; + char buf[MAXPATHLEN]; + + if ((server == NULL) || (printer == NULL)) { + errno = EINVAL; + return (-1); + } + + if (hostname == NULL) { + sysinfo(SI_HOSTNAME, hbuf, sizeof (hbuf)); + hostname = hbuf; + } + + if ((strcasecmp(server, hostname) != 0) && + (strcasecmp(server, "localhost") != 0)) + return (1); + + snprintf(buf, sizeof (buf), "/etc/lp/printers/%s/configuration", + printer); + if (access(buf, F_OK) != 0) { + /* OK its not a local printer but may be a local class */ + snprintf(buf, sizeof (buf), "/etc/lp/classes/%s", printer); + if (access(buf, F_OK) != 0) + return (1); + } + return (0); +} + +/* + * Determine if there are any local printers in the list + */ +static int +local_printers(ns_bsd_addr_t **printers) +{ + static local_printer_found = 0; + static already_looked = 0; + + if (already_looked == 0) { + already_looked = 1; + if ((printers == NULL) || (*printers == NULL)) { + return (0); + } + + /* Step through list and break out if we find a local printer */ + while (*printers != NULL) { + if (((*printers)->server == NULL) || + ((*printers)->printer == NULL)) + continue; + if (is_local_printer((*printers)->server, + (*printers)->printer) == 0) + break; + printers++; + } + + if ((printers != NULL) && (*printers != NULL)) + local_printer_found = 1; + } + + return (local_printer_found); +} + + +/* + * Determine if local status needs to be run. This is true + * if there are any local printers in the list with a local + * printer definition. + */ +static int +need_local_status(ns_bsd_addr_t **printers, ns_bsd_addr_t *binding) +{ + + return ((local_printers(_printer_bindings) == 1) || + ((binding != NULL) && + (is_local_printer(binding->server, + binding->printer) == 0))); +} + + +static int +work_execute(work_entry_t *work, int verb) +{ + char *printer = NULL; + char *server = NULL; + print_queue_t *qp; + int rank = 0; + int rc = 0; + + switch (work->type) { + case RUNNING: + sysv_running(); + return (0); + case DEFAULT: + sysv_default(); + return (0); + case FORMS: + return (sysv_local_status("-f", work->user, verb, 0, + gettext("form listing not supported on client\n"))); + case CLASSES: + return (sysv_local_status("-c", work->user, 0, 0, + gettext("class listing not supported on client\n"))); + case CHAR_SETS: + return (sysv_local_status("-S", work->user, verb, 0, + gettext("char set listing not supported on client\n"))); + } + + if ((work->binding->printer == NULL) && + (work->binding->server == NULL)) + return (0); + + /* + * If the printer is a local LP printer, we can use the local lpstat + * and it should be faster than going via the network. + */ + if ((is_local_printer(work->binding->server, + work->binding->printer) == 0) && + ((work->binding->pname == NULL) || + (strcmp(work->binding->printer, work->binding->pname) == 0) || + (strcmp(work->binding->pname, NS_NAME_DEFAULT) == 0))) { + char *option = lpstat_opt(work->type); + + if (option != NULL) { + /* + * If we are processing all printers + * (ie. -p, -o, -r, + * -u, -t), simply return, because the local lpstat + * was already run and all local printers were reported + * against. + */ + if (_processing_all != 0) + return (0); + + if (work->printer) + return (sysv_local_status(option, + work->printer, verb, sysvDesc, + gettext("can't execute \n"))); + else if (work->user) + return (sysv_local_status(option, + work->user, verb, sysvDesc, + gettext("can't execute \n"))); + else + return (sysv_local_status(option, + "", verb, sysvDesc, + gettext("can't execute \n"))); + } + } + + if ((printer = strchr(work->binding->printer, '|')) != NULL) + *printer = NULL; + printer = work->binding->printer; + server = work->binding->server; + + switch (work->type) { + case STATUS: + case RANK: + case USER: + case ENTRIES: + if ((qp = sysv_get_queue(work->binding, sysvLocal)) != NULL) { + qp->jobs = job_list_append(qp->jobs, printer, + server, SPOOL_DIR); + switch (work->type) { + case STATUS: + if (work->binding->pname) + rc += sysv_queue_state(qp, + work->binding->pname, verb, + sysvDesc); + else + rc += sysv_queue_state(qp, printer, + verb, sysvDesc); + break; + case ENTRIES: + case USER: + rank = -1; + /*FALLTHRU*/ + case RANK: + if ((work->binding->pname != NULL) && + (strcmp(work->binding->pname, + NS_NAME_DEFAULT) != 0)) + (void) list_iterate((void **)qp->jobs, + (VFUNC_T)vsysv_queue_entry, + work->binding->pname, work->user, + work->id, verb, &rank); + else + (void) list_iterate((void **)qp->jobs, + (VFUNC_T)vsysv_queue_entry, printer, + work->user, work->id, verb, &rank); + break; + } + if ((qp->state == RAW) && (qp->status != NULL)) { + (void) printf("%s", qp->status); + qp->status = NULL; + } + } + break; + default: + switch (work->type) { + case DEVICE: + rc += sysv_system(work->binding); + break; + case ACCEPTING: + rc += sysv_accept(work->binding); + break; + case BSD_QUEUE: + do { + int i; + + if (bsdInterval != 0) + clear_screen(); + if (bsd_queue(work->binding, bsdFormat, + bsdc, bsdv) != 0) + break; + if (bsdInterval != 0) + (void) sleep(bsdInterval); + } while (bsdInterval != 0); + break; + } + } + + return (rc); +} + + +static int +vbinding_execute(ns_bsd_addr_t *binding, va_list ap) +{ + work_entry_t *work = va_arg(ap, work_entry_t *); + int verbose = va_arg(ap, int); + + work->binding = binding; + return (work_execute(work, verbose)); +} + + + + + +static int +vwork_list_execute(work_entry_t *work, va_list ap) +{ + int verbose = va_arg(ap, int); + work_entry_t tmp; + int rc = 0; + + if ((work->binding == NULL) || ((work->binding->printer == NULL) && + (work->binding->server == NULL))) { + switch (work->type) { + case RUNNING: + case DEFAULT: + case CLASSES: + case FORMS: + case CHAR_SETS: + rc += work_execute(work, verbose); + break; + case STATUS: + case RANK: + case ENTRIES: + case ACCEPTING: + case DEVICE: + case SUMMARY: + case USER: + case FULL: + + if (_printer_bindings == NULL) { + if (sysvLocal == 0) { + _printer_bindings = + ns_bsd_addr_get_all(LOCAL_UNIQUE); + _printer_bindings_unique = + ns_bsd_addr_get_all(UNIQUE); + } else { + _printer_bindings = + ns_bsd_addr_get_list(LOCAL_UNIQUE); + _printer_bindings_unique = + ns_bsd_addr_get_list(UNIQUE); + } + } + + (void) memcpy(&tmp, work, sizeof (tmp)); + + if (work->type == FULL || work->type == SUMMARY) { + tmp.type = RUNNING; + rc += work_execute(&tmp, verbose); + + tmp.type = DEFAULT; + rc += work_execute(&tmp, verbose); + + tmp.type = CLASSES; + rc += work_execute(&tmp, verbose); + + tmp.type = DEVICE; + rc += list_iterate( + (void **)_printer_bindings, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + + tmp.type = CHAR_SETS; + rc += work_execute(&tmp, verbose); + + + if (work->type == FULL) { + _processing_all = 1; + tmp.type = ACCEPTING; + rc += list_iterate( + (void **)_printer_bindings, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + if (need_local_status(_printer_bindings, + work->binding) == 1) + sysv_local_status("-p", "", + verbose, sysvDesc, + gettext( + "can't execute \n")); + + tmp.type = STATUS; + rc += list_iterate( + (void **)_printer_bindings, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + if (need_local_status(_printer_bindings, + work->binding) == 1) + sysv_local_status("-o", "", + verbose, sysvDesc, + gettext( + "can't execute \n")); + + tmp.type = ENTRIES; + rc += list_iterate( + (void **)_printer_bindings_unique, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + _processing_all = 0; + } + + /* + * Put this here to preserve same ordering + * as found in previous releases. + */ + if (work->type == FULL || + work->type == SUMMARY) { + + tmp.type = FORMS; + rc += work_execute(&tmp, verbose); + } + + } else if ((work->type == ACCEPTING) || + (work->type == DEVICE)) { + tmp.type = work->type; + rc += list_iterate( + (void **)_printer_bindings, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + + } else if (work->type == USER || + work->type == STATUS || + work->type == ENTRIES || + work->type == RANK) { + + if (need_local_status(_printer_bindings, + work->binding) == 1) { + char *option = lpstat_opt(work->type); + if ((work->type == USER) && + (work->user != NULL)) { + sysv_local_status(option, + work->user, verbose, + sysvDesc, + gettext( + "can't execute \n")); + } else { + sysv_local_status(option, "", + verbose, sysvDesc, + gettext( + "can't execute \n")); + } + } + + _processing_all = 1; + tmp.type = work->type; + if (work->type == STATUS) { + rc += list_iterate( + (void **)_printer_bindings, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + } else { + rc += list_iterate( + (void **)_printer_bindings_unique, + (VFUNC_T)vbinding_execute, + &tmp, verbose); + } + _processing_all = 0; + } else + rc += list_iterate( + (void **)_printer_bindings, + (VFUNC_T)vbinding_execute, &tmp, + verbose); + return (rc); + default: + return (rc); + } + } else { + rc += work_execute(work, verbose); + } + return (rc); +} + +static void +sysv_options(int ac, char *av[]) +{ + char **argv, + *program; + int c; + int argc = 0; + char *user; + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + argv = (char **)calloc((ac + 1), sizeof (char *)); + + if (argv == NULL) { + fprintf(stderr, gettext("memory allocation failed\n")); + exit(1); + } + for (argc = 0; argc < ac; argc++) + argv[argc] = av[argc]; + argv[argc++] = "--"; + + while ((c = getopt(argc, argv, "R:a:c:f:o:p:u:v:DLSdlrst")) != EOF) { + switch (c) { /* these may or may not have an option */ + case 'R': + case 'a': + case 'c': + case 'f': + case 'o': + case 'p': + case 'u': + case 'v': + 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 'D': + sysvDesc++; + break; + case 'L': + sysvLocal++; + /* undocumented option that keeps it long and local */ + break; + case 'R': + work_list_append_list(optarg, RANK); + break; + case 'S': + work_list_append_list(optarg, CHAR_SETS); + break; + case 'a': + work_list_append_list(optarg, ACCEPTING); + break; + case 'c': + work_list_append_list(optarg, CLASSES); + break; + case 'd': + work_list_append(NULL, NULL, -1, DEFAULT); + break; + case 'f': + work_list_append_list(optarg, FORMS); + break; + case 'l': + sysvVerbose++; + break; + case 'o': + work_list_append_list(optarg, ENTRIES); + break; + case 'p': + work_list_append_list(optarg, STATUS); + break; + case 'r': + work_list_append(NULL, NULL, -1, RUNNING); + break; + case 's': + work_list_append(NULL, NULL, -1, SUMMARY); + break; + case 't': + work_list_append(NULL, NULL, -1, FULL); + break; + case 'u': + work_list_append_list(optarg, USER); + break; + case 'v': + work_list_append_list(optarg, DEVICE); + break; + default: + (void) fprintf(stderr, + gettext( + "Usage: %s [-drtslDL] [-R [list]] [-S [list]] " + "[-a [list]] [-c [list]] [-f [list]] " + "[-o [list]] [-p [printer]] [-u [list]] " + "[-v [list]] [list]\n"), + av[0]); + exit(1); + } + } + for (argc = optind; argc < ac; argc++) /* add requests */ + work_list_append_list(av[argc], ENTRIES); + + if ((workList == NULL) && (ac == 1)) { + user = get_user_name(); + work_list_append(NULL, user, -1, USER); + } +} + + +static void +bsd_options(int ac, char **av) +{ + char *printer; + int c; + + if ((bsdv = (char **)calloc(ac, sizeof (char *))) == NULL) + return; + + if ((printer = getenv((const char *)"PRINTER")) == NULL) + printer = getenv((const char *)"LPDEST"); + if (printer == NULL) + printer = NS_NAME_DEFAULT; + + while ((c = getopt(ac, av, "lP:+:")) != EOF) + switch (c) { + case 'l': + bsdFormat = SHOW_QUEUE_LONG_REQUEST; + break; + case 'P': + printer = optarg; + break; + default: + (void) fprintf(stderr, + gettext("Usage: %s [-P printer] [-l] [+ interval] [list]\n"), + av[0]); + exit(1); + } + + work_list_append(printer, NULL, -1, BSD_QUEUE); + + while (optind < ac) + if (av[optind][0] == '+') + bsdInterval = atoi(&av[optind++][1]); + else + bsdv[bsdc++] = av[optind++]; +} + + +int +main(int ac, char *av[]) +{ + char *program; + int rc = 0; + + (void) setlocale(LC_ALL, ""); + +#if !defined(TEXT_DOMAIN) +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); + + if ((program = strrchr(av[0], '/')) == NULL) + program = av[0]; + else + program++; + + openlog(program, LOG_PID, LOG_LPR); + + if (check_client_spool(NULL) < 0) { + (void) fprintf(stderr, gettext("couldn't validate local spool " + "area (%s)\n"), SPOOL_DIR); + return (1); + } + (void) chdir(SPOOL_DIR); + + if (strcmp(program, "lpq") == 0) + bsd_options(ac, av); + else { + sysv_options(ac, av); + } + + rc = list_iterate((void **)workList, (VFUNC_T)vwork_list_execute, + sysvVerbose, sysvDesc); + + if (exit_code == 0) + exit_code = rc; + + return (exit_code); +} diff --git a/usr/src/cmd/print/lpstat/parse.h b/usr/src/cmd/print/lpstat/parse.h new file mode 100644 index 0000000000..fb4abd3d9f --- /dev/null +++ b/usr/src/cmd/print/lpstat/parse.h @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ifndef _PARSE_H +#define _PARSE_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _print_queue { + ns_bsd_addr_t *binding; + char *status; + enum { RAW, IDLE, PRINTING, FAULTED, DISABLED } state; + job_t **jobs; +} print_queue_t; + +extern print_queue_t *parse_bsd_queue(ns_bsd_addr_t *binding, char *data, + int len); +#ifdef __cplusplus +} +#endif + +#endif /* _PARSE_H */ diff --git a/usr/src/cmd/print/lpstat/parse_bsd.c b/usr/src/cmd/print/lpstat/parse_bsd.c new file mode 100644 index 0000000000..963ea8f048 --- /dev/null +++ b/usr/src/cmd/print/lpstat/parse_bsd.c @@ -0,0 +1,171 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998-2001 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/fcntl.h> +#include <ctype.h> +#include <string.h> +#include <stdarg.h> +#include <libintl.h> + +#include <print/ns.h> +#include <print/network.h> +#include <print/misc.h> +#include <print/job.h> +#include <print/list.h> + +#include "parse.h" + + +#define MERR_NOMEM "ERROR: no memory\n" +#define STRNCASECMP(a, b) strncasecmp(a, b, strlen(b)) + +static job_t * +parse_bsd_entry(char *data) +{ + job_t *tmp; + char *p; + + tmp = (job_t *)malloc(sizeof (*tmp)); + if (tmp == NULL) { + (void) fprintf(stderr, gettext(MERR_NOMEM)); + return (NULL); + } + (void) memset(tmp, 0, sizeof (*tmp)); + + /* + * 1st line... + * user: rank [job (ID)(host)]\n + */ + if ((p = strtok(data, ": ")) == NULL) /* user: ... */ + return (NULL); + tmp->job_user = strdup(p); + p = strtok(NULL, "\t "); /* ...rank... */ + p = strtok(NULL, " "); /* ...[job ... */ + if ((p = strtok(NULL, "]\n")) == NULL) /* ... (id)(hostname)] */ + return (NULL); + while (isspace(*p)) p++; + tmp->job_id = atoi(p); + while (isdigit(*(++p))); + while (isspace(*p)) p++; + tmp->job_host = strdup(p); + + /* + * rest o lines + * file size bytes\n + */ + do { + jobfile_t *file; + + p = strtok(NULL, "\t "); + p = strtok(NULL, "\t "); /* file Name */ + if (p != NULL) { + file = (jobfile_t *)malloc(sizeof (*file)); + if (file == NULL) { + (void) fprintf(stderr, gettext(MERR_NOMEM)); + return (NULL); + } + file->jf_name = strdup(p); + if ((p = strtok(NULL, "\t ")) != NULL) + if ((file->jf_size = atoi(p)) == 0) + while ((p = strtok(NULL, "\t ")) + != NULL) + if (isdigit(p[0])) { + file->jf_size = atoi(p); + break; + } + tmp->job_df_list = (jobfile_t **)list_append((void **) + tmp->job_df_list, + (void *)file); + } + } while (p != NULL); + return (tmp); +} + + +/*ARGSUSED*/ +print_queue_t * +parse_bsd_queue(ns_bsd_addr_t *binding, char *data, int len) +{ + char *p; + print_queue_t *tmp; + + tmp = (print_queue_t *)malloc(sizeof (*tmp)); + if (tmp == NULL) { + (void) fprintf(stderr, gettext(MERR_NOMEM)); + return (NULL); + } + (void) memset(tmp, 0, sizeof (*tmp)); + tmp->state = RAW; + tmp->status = data; + tmp->binding = binding; + + if (data == NULL) + return (tmp); + + if ((p = strstr(data, "\n\n")) == NULL) { + if (strstr(data, "no entries") != NULL) + tmp->state = IDLE; + return (tmp); + } + + *(p++) = NULL; + tmp->status = strdup(data); + data = ++p; + + tmp->state = FAULTED; /* Error */ + if (STRNCASECMP(tmp->status, "no entries") == 0) + tmp->state = IDLE; + else if (STRNCASECMP((tmp->status + strlen(tmp->status) + - strlen("ready and printing")), + "ready and printing") == 0) + tmp->state = PRINTING; + + do { /* parse jobs */ + job_t *job; + char *q = data; + + if ((p = strstr(data, "\n\n")) != NULL) { + *(++p) = NULL; + data = ++p; + } + if ((job = parse_bsd_entry(q)) == NULL) + break; + + job->job_server = strdup(binding->server); + job->job_printer = strdup(binding->printer); + tmp->jobs = (job_t **)list_append((void **)tmp->jobs, + (void *)job); + } while (p != NULL); + + return (tmp); +} diff --git a/usr/src/cmd/print/lpstat/sysv-functions.c b/usr/src/cmd/print/lpstat/sysv-functions.c new file mode 100644 index 0000000000..35520fddd3 --- /dev/null +++ b/usr/src/cmd/print/lpstat/sysv-functions.c @@ -0,0 +1,619 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998-2001 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/fcntl.h> +#include <sys/wait.h> +#include <ctype.h> +#include <string.h> +#include <stdarg.h> +#include <unistd.h> +#include <errno.h> +#include <unistd.h> +#include <syslog.h> +#ifndef SUNOS_4 +#include <libintl.h> +#endif + +#include <print/ns.h> +#include <print/list.h> +#include <print/misc.h> +#include <print/job.h> +#include <print/network.h> + +#include "parse.h" +#include "sysv-functions.h" + +extern char *getenv(const char *); + +static print_queue_t **_queue_list = NULL; + +static int sysv_displayLocalLPSTAT(char *pname, char *aname); + +#define ALL "all" +static int +compair_user(char *full, char *user, char *host) +{ + char *u1, + *h1; + + if (full == NULL) + return (0); + + if ((strcmp(full, ALL) == 0) || strcmp(full, user) == 0) + return (0); + if ((u1 = strchr(full, '!')) == NULL) + return (-1); + h1 = strcdup(full, '!'); + u1++; + if (((strcmp(u1, ALL) == 0) || (strcmp(u1, user) == 0)) && + (strcmp(h1, host) == 0)) { + free(h1); + return (0); + } + if (((strcmp(h1, ALL) == 0) || (strcmp(h1, host) == 0)) && + (strcmp(u1, user) == 0)) { + free(h1); + return (0); + } + free(h1); + return (-1); +} + + +static int +compair_queue_binding(print_queue_t *queue, ns_bsd_addr_t *binding) +{ + if ((queue == NULL) || (binding == NULL)) + return (-1); + if ((strcmp(queue->binding->printer, binding->printer) == 0) && + (strcmp(queue->binding->server, binding->server) == 0)) + return (0); + return (-1); +} + + + +static char * +get_queue_buffer(ns_bsd_addr_t *binding) +{ + char *q = NULL, + *p = NULL, + *server, + *printer; + int nd, + rc, + count = 0, + q_size = 0, + p_left = 0; + + server = binding->server; + printer = binding->printer; + + if ((nd = net_open(server, 15)) < 0) { + char err[128]; + + (void) snprintf(err, sizeof (err), + gettext("server %s not responding\n\n"), + server); + return (strdup(err)); + } + + rc = net_printf(nd, "%c%s \n", SHOW_QUEUE_LONG_REQUEST, printer); + if (rc < 0) + syslog(LOG_ERR, "net_printf() failed: %m"); + + do { + p += count; + if ((p_left -= count) < 10) { + char *t; + +#ifdef SUNOS_4 + if (q == NULL) { + p = q = malloc(BUFSIZ); + (void) memset(p, NULL, BUFSIZ); + q_size = BUFSIZ; + } else { + q_size += BUFSIZ; + t = malloc(q_size); + (void) memset(t, NULL, q_size); + strcpy(t, q); + free(q); + p = t + (p - q); + q = t; + } +#else + if ((t = (char *)realloc(q, q_size += BUFSIZ)) != q) { + p = t + (p - q); + q = t; + } +#endif + p_left += BUFSIZ; + (void) memset(p, NULL, p_left); + } + } while ((count = net_read(nd, p, p_left)) > 0); + + (void) net_close(nd); + + return (q); +} + + + +print_queue_t * +sysv_get_queue(ns_bsd_addr_t *binding, int local) +{ + print_queue_t *qp = NULL; + char *buf; + + if (_queue_list != NULL) /* did we already get it ? */ + if ((qp = (print_queue_t *)list_locate((void **)_queue_list, + (COMP_T)compair_queue_binding, binding)) != NULL) + return (qp); + + if (local == 0) + buf = (char *)get_queue_buffer(binding); + else + buf = strdup("no entries\n"); + + if (buf != NULL) { + qp = parse_bsd_queue(binding, buf, strlen(buf)); + _queue_list = (print_queue_t **)list_append((void **) + _queue_list, (void *)qp); + } + return (qp); +} + + + + + + + /* + * SYSV (lpstat) specific routines + */ + +static int +vJobfile_size(jobfile_t *file) +{ + if (file != NULL) + return (file->jf_size); + return (0); +} + + +void +vsysv_queue_entry(job_t *job, va_list ap) +{ + char id[128], + user[128], + *printer = va_arg(ap, char *), + *in_user = va_arg(ap, char *); + int in_id = va_arg(ap, int), + verbose = va_arg(ap, int), + *rank = va_arg(ap, int *), + size = 0; + + if ((in_id != -1) && (in_id != job->job_id)) + return; + if (compair_user(in_user, job->job_user, job->job_host) != 0) + return; + + (void) sprintf(id, "%.16s-%-5d", printer, job->job_id); + (void) snprintf(user, sizeof (user), "%s@%s", job->job_user, + job->job_host); + size = list_iterate((void **)job->job_df_list, (VFUNC_T)vJobfile_size); + if (*rank >= 0) + (void) printf("%d ", (*rank)++); + (void) printf("%-*s %-*s %*d %s%s", (*rank >= 0 ? 20 : 22), id, 15, + user, 7, size, (*rank >= 0 ? "" : " "), short_date()); + if (verbose == 0) { + if (*rank == 1) + (void) printf(" on %s", printer); + (void) printf("\n"); + } else + (void) printf("\n\t%s %s\n", + ((*rank > 1) ? "on" : "assigned"), printer); +} + + +#define OLD_LPSTAT "/usr/lib/lp/local/lpstat" /* for -c -f -S */ +#ifdef OLD_LPSTAT +static int +local_printer(char *name) +{ + char buf[128]; + + (void) snprintf(buf, sizeof (buf), + "/etc/lp/printers/%s/configuration", name); + return (access(buf, F_OK)); +} + +static int +local_class(char *name) +{ + char buf[128]; + + (void) snprintf(buf, sizeof (buf), + "/etc/lp/classes/%s", name); + return (access(buf, F_OK)); +} + +int +sysv_local_status(char *option, char *arg, int verbose, + int description, char *invalid) +{ + pid_t stat; + + if (access(OLD_LPSTAT, F_OK) == 0) { + char buf[BUFSIZ]; + + /* + * Need the fflush to preserve output order when + * output re-directed to a file. Close of old lpstat + * flushes buffers causing old lpstat output to preceed + * all other output to the file. + */ + (void) fflush(stdout); + (void) fflush(stderr); + (void) snprintf(buf, sizeof (buf), + "%s %s %s%s%s", OLD_LPSTAT, option, + (arg ? arg : ""), (verbose ? " -l" : ""), + (description ? " -D" : "")); + stat = system(buf); + if (WIFEXITED(stat)) { + return (WEXITSTATUS(stat)); + } else { + if (stat == -1) + return (errno); + else + return (ENOMSG); + } + } else + (void) printf("%s", invalid); + + return (0); +} +#endif + + +int +sysv_queue_state(print_queue_t *qp, char *printer, int verbose, int description) +{ +#ifdef OLD_LPSTAT + pid_t stat; + + if ((local_printer(printer) == 0) && (access(OLD_LPSTAT, F_OK) == 0)) { + char buf[BUFSIZ]; + + /* see sysv_local_status for reason for fflush */ + (void) fflush(stdout); + (void) fflush(stderr); + (void) snprintf(buf, sizeof (buf), + "%s -p %s%s%s", OLD_LPSTAT, printer, + (verbose ? " -l" : ""), (description ? " -D" : "")); + stat = system(buf); + if (WIFEXITED(stat)) { + return (WEXITSTATUS(stat)); + } else { + if (stat == -1) + return (errno); + else + return (ENOMSG); + } + + + } +#endif + + (void) printf(gettext("printer %s "), printer); + switch (qp->state) { + case IDLE: + (void) printf(gettext("is idle. ")); + break; + case PRINTING: + (void) printf(gettext("now printing %s-%d. "), printer, + qp->jobs[0]->job_id); + break; + case FAULTED: + (void) printf(gettext("faulted printing %s-%d. "), printer, + (qp->jobs != NULL ? qp->jobs[0]->job_id : 0)); + break; + case RAW: + (void) printf(gettext("unknown state. ")); + break; + default: + (void) printf(gettext("disabled. ")); + } + (void) printf(gettext("enabled since %s. available.\n"), long_date()); + if (qp->state == FAULTED) + (void) printf("\t%s\n", qp->status); + if (description != 0) { + ns_printer_t *pobj; + char *desc; + + if (((pobj = ns_printer_get_name(qp->binding->printer, NULL)) + != NULL) && + ((desc = ns_get_value(NS_KEY_DESCRIPTION, pobj)) != NULL)) + (void) printf(gettext("\tDescription: %s\n"), desc); + else + (void) printf(gettext("\tDescription: %s@%s\n"), + qp->binding->printer, qp->binding->server); + } + if (verbose != 0) + (void) printf( + gettext("\tRemote Name: %s\n\tRemote Server: %s\n"), + qp->binding->printer, qp->binding->server); + + return (0); +} + + +int +sysv_accept(ns_bsd_addr_t *binding) +{ +#ifdef OLD_LPSTAT + int result = 0; + + if (((local_printer(binding->printer) == 0) || + (local_class(binding->printer) == 0)) && + (access(OLD_LPSTAT, F_OK) == 0)) { + /* + * Locally attached printer, so display its accept state using + * the old lpstat utility. + */ + result = sysv_displayLocalLPSTAT(binding->printer, + binding->pname); + return (result); + } +#endif + + + if (binding->pname != NULL) + (void) printf(gettext("%s accepting requests since %s\n"), + binding->pname, long_date()); + else + (void) printf(gettext("%s accepting requests since %s\n"), + binding->printer, long_date()); + + return (0); +} + + + +#ifdef OLD_LPSTAT +/* + * FUNCTION: sysv_displayLocalLPSTAT() + * + * DESCRIPTION: This function uses the old lpstat (/usr/lib/lp/local/lpstat) + * utility to display the accepting state (-a option) for locally + * attached printers. + * If an alias name is given then the output from lpstat is + * captured and modified to show the alias name instead of the + * printer's real name. Note: this is done because the old lpstat + * can not handle alias names. + * + * PARAMETERS: + * Input: char *pname - printers real name + * char *aname - printers alias name + * + * RETURNS: 0 = completed okay, otherwise error + * + */ + +static int +sysv_displayLocalLPSTAT(char *pname, char *aname) + +{ + int result = ENOMSG; + char buf[BUFSIZ]; + FILE *fd = NULL; + char *tmp = NULL; + + /* see sysv_local_status for reason for fflush */ + (void) fflush(stdout); + (void) fflush(stderr); + + if (((pname != NULL) && (aname != NULL)) && + (strcmp(pname, aname) != 0)) + { + /* + * This is a request to display status of an aliased local + * printer, so capture the output from the local lpstat for the + * real printer and then display that output with the alias + * name instead of the real name. + */ + + (void) snprintf(buf, sizeof (buf), "%s -a %s", + OLD_LPSTAT, pname); + + /* execute the local lpstat utility and display output */ + + fd = popen(buf, "r"); + if (fd != NULL) + { + tmp = fgets(buf, sizeof (buf), fd); + if (tmp != NULL) + { + result = 0; + + if (strncmp(buf, pname, strlen(pname)) == 0) + { + printf("%s", aname); + printf("%s", &(buf[strlen(pname)])); + + tmp = fgets(buf, sizeof (buf), fd); + } + + /* + * finish reading and displaying the + * output from the lpstat utility + */ + + while (tmp != NULL) + { + printf("%s", buf); + tmp = fgets(buf, sizeof (buf), fd); + } + } + + (void) pclose(fd); + } + } + + else + if (pname != NULL) + { + /* + * Not an alias so directly display output from the + * local lpstat utility + */ + (void) snprintf(buf, sizeof (buf), "%s -a %s", + OLD_LPSTAT, pname); + result = system(buf); + + if (WIFEXITED(result)) + { + result = WEXITSTATUS(result); + } + else + if (result == -1) + { + result = errno; + } + else + { + result = ENOMSG; + } + } + + return (result); +} /* sysv_displayLocalLPSTAT */ +#endif + + + +int +sysv_system(ns_bsd_addr_t *binding) +{ + char *host; + char *printer; + pid_t stat; + + if (binding->pname) + printer = binding->pname; + else + printer = binding->printer; + host = binding->server; +#ifdef OLD_LPSTAT + + if ((local_printer(printer) == 0) && (access(OLD_LPSTAT, F_OK) == 0)) { + char buf[BUFSIZ]; + + /* see sysv_local_status for reason for fflush */ + (void) fflush(stdout); + (void) fflush(stderr); + (void) snprintf(buf, sizeof (buf), + "%s -v %s", OLD_LPSTAT, printer); + stat = system(buf); + + if (WIFEXITED(stat)) { + return (WEXITSTATUS(stat)); + } else { + if (stat == -1) + return (errno); + else + return (ENOMSG); + } + } else +#endif + if (printer && host) { + if (strcmp(printer, binding->printer) == 0) + (void) printf(gettext("system for %s: %s\n"), printer, + host); + else + (void) printf( + gettext("system for %s: %s (as printer %s)\n"), + printer, host, binding->printer); + } + + return (0); +} + + +void +sysv_running() +{ + int lock; + struct stat st; + + lock = stat("/usr/spool/lp/SCHEDLOCK", &st); + if (lock < 0) + (void) printf(gettext("scheduler is not running\n")); + else + (void) printf(gettext("scheduler is running\n")); +} + + +void +sysv_default() +{ + char *printer; + + if ((printer = getenv((const char *)"LPDEST")) == NULL) + printer = getenv((const char *)"PRINTER"); + if (printer == NULL) { + ns_printer_t *p; + + if ((p = ns_printer_get_name(NS_NAME_DEFAULT, NULL)) != NULL) { + printer = ns_get_value(NS_KEY_USE, p); + /* + * Fall back to the printer name out of + * the "bsdaddr" attribute + */ + if (printer == NULL) { + ns_bsd_addr_t *a = + ns_get_value(NS_KEY_BSDADDR, p); + if ((a != NULL) && (a->printer != NULL)) { + static char buf[64]; + (void) snprintf(buf, sizeof (buf), "%s", + a->printer); + printer = buf; + } + } + } + } + if (printer != NULL) + (void) printf(gettext("system default destination: %s\n"), + printer); + else + (void) printf(gettext("no system default destination\n")); +} diff --git a/usr/src/cmd/print/lpstat/sysv-functions.h b/usr/src/cmd/print/lpstat/sysv-functions.h new file mode 100644 index 0000000000..eea04ecc4b --- /dev/null +++ b/usr/src/cmd/print/lpstat/sysv-functions.h @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 (c) 1998 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ifndef _SYSV_FUNCTIONS_H +#define _SYSV_FUNCTIONS_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void vsysv_queue_entry(job_t *job, va_list ap); +extern int sysv_queue_state(print_queue_t *qp, char *printer, int verbose, + int description); +extern int sysv_accept(ns_bsd_addr_t *binding); +extern int sysv_system(ns_bsd_addr_t *binding); +extern void sysv_running(); +extern void sysv_default(); +extern int sysv_local_status(char *, char *, int, int, char *); +extern print_queue_t *sysv_get_queue(ns_bsd_addr_t *binding, int local); + +#ifdef __cplusplus +} +#endif + +#endif /* _SYSV_FUNCTIONS_H */ diff --git a/usr/src/cmd/print/printer-info/Makefile b/usr/src/cmd/print/printer-info/Makefile new file mode 100644 index 0000000000..4bd90aeba9 --- /dev/null +++ b/usr/src/cmd/print/printer-info/Makefile @@ -0,0 +1,73 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# + +# + +include ../Makefile.sp + +ROOTLIBLPBIN = $(ROOTLIBLP)/bin + +PROG = printer-info +SRCS = $(PROG).c +OBJECTS = $(PROG).o + +ROOTPROG= $(PROG:%=$(ROOTLIBLPBIN)/%) +$(ROOTPROG) := OWNER=root +$(ROOTPROG) := GROUP=lp +$(ROOTPROG) := FILEMODE=555 + +.KEEP_STATE: + +all: $(PROG) + +$(ROOTLIBLPBIN): + $(INS.dir) + +$(ROOTLIBLPBIN)/%: % + $(INS.file) + +install: all $(ROOTLIBLPBIN) $(ROOTPROG) + +$(PROGRAM): $(OBJECTS) + $(CC) $(CFLAGS) -o $@ $(OBJECTS) + +clean: + $(RM) $(PROG) *.o + +cstyle: + cstyle $(SRCS) + +clobber: clean + +strip lint: + + + + + + diff --git a/usr/src/cmd/print/printer-info/printer-info.c b/usr/src/cmd/print/printer-info/printer-info.c new file mode 100644 index 0000000000..aebafe1af5 --- /dev/null +++ b/usr/src/cmd/print/printer-info/printer-info.c @@ -0,0 +1,196 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/prnio.h> +#include <fcntl.h> + +#define COMMAND_SET_MAX 16 /* more than 16 command sets is not likely */ +#define NP(x) (x ? x : "") + +typedef struct { + char *manufacturer; + char *model; + char *description; + char *class; + char *command_set[COMMAND_SET_MAX]; +} printer_description_t; + +int +get_printer_description(char *path, printer_description_t *info) +{ + int fd, rc; + struct prn_1284_device_id id; + char buf[BUFSIZ]; + char *s, *iter = NULL; + + /* open the device */ + if ((fd = open(path, O_RDWR)) < 0) + return (fd); + + /* get the 1284 device id */ + memset(&id, 0, sizeof (id)); + memset(&buf, 0, sizeof (buf)); + id.id_len = sizeof (buf); + id.id_data = buf; + + rc = ioctl(fd, PRNIOC_GET_1284_DEVID, &id); + /* close(fd); */ + if (rc < 0) + return (rc); + + memset(info, 0, sizeof (*info)); + + /* parse the 1284 device id string */ + for (s = (char *)strtok_r(buf, ";\n", &iter); s != NULL; + s = (char *)strtok_r(NULL, ";\n", &iter)) { + char *t, *u, *iter2 = NULL; + + if ((t = (char *)strtok_r(s, ":\n", &iter2)) == NULL) + continue; + + if ((u = (char *)strtok_r(NULL, ":\n", &iter2)) == NULL) + continue; + + if ((strcasecmp(t, "MFG") == 0) || + (strcasecmp(t, "MANUFACTURER") == 0)) + info->manufacturer = strdup(u); + else if ((strcasecmp(t, "MDL") == 0) || + (strcasecmp(t, "MODEL") == 0)) + info->model = strdup(u); + else if ((strcasecmp(t, "DES") == 0) || + (strcasecmp(t, "DESCRIPTION") == 0)) + info->description = strdup(u); + else if ((strcasecmp(t, "CLS") == 0) || + (strcasecmp(t, "CLASS") == 0)) + info->class = strdup(u); + else if ((strcasecmp(t, "CMD") == 0) || + (strcasecmp(t, "COMMAND SET") == 0)) { + /* this should be more dynamic, I got lazy */ + char *v, *iter3 = NULL; + int i = 0; + + for (v = (char *)strtok_r(u, ",\n", &iter3); + ((v != NULL) && (i < COMMAND_SET_MAX)); + v = (char *)strtok_r(NULL, ",\n", &iter3)) + info->command_set[i++] = strdup(v); + } + } + + return (0); +} + +static void +usage(char *name) +{ + char *program; + + if ((program = strrchr(name, '/')) == NULL) + program = name; + else + program++; + + printf("Usage: %s [-aMmdCc] (path) ...\n", program); +} + +int +main(int ac, char *av[]) +{ + int rc; + int manufacturer = 0, model = 0, description = 0, command_set = 0, + class = 0; + + while ((rc = getopt(ac, av, "aMmdCc")) != EOF) + switch (rc) { + case 'a': + manufacturer++; + model++; + description++; + command_set++; + class++; + break; + case 'M': + manufacturer++; + break; + case 'm': + model++; + break; + case 'd': + description++; + break; + case 'C': + command_set++; + break; + case 'c': + class++; + break; + default: + usage(av[0]); + exit(1); + } + + if (optind >= ac) { + usage(av[0]); + exit(1); + } + + while (optind < ac) { + char *path = av[optind++]; + printer_description_t info; + + rc = get_printer_description(path, &info); + if (rc == 0) { + int i = 0; + + printf("%s:\n", path); + if (manufacturer != 0) + printf("\tManufacturer: %s\n", + NP(info.manufacturer)); + if (model != 0) + printf("\tModel: %s\n", + NP(info.model)); + if (description != 0) + printf("\tDescription: %s\n", + NP(info.description)); + if (class != 0) + printf("\tClass: %s\n", + NP(info.class)); + if (command_set != 0) { + printf("\tCommand set:\n"); + while (info.command_set[i] != NULL) + printf("\t\tcmd[%d]: %s\n", i, + info.command_set[i++]); + } + } else + perror(path); + } + return (rc); +} diff --git a/usr/src/cmd/print/printmgr/Makefile b/usr/src/cmd/print/printmgr/Makefile new file mode 100644 index 0000000000..1eabd808ac --- /dev/null +++ b/usr/src/cmd/print/printmgr/Makefile @@ -0,0 +1,89 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Makefile for print manager +# +PROG = pmserver.jar pmclient.jar + +include $(SRC)/cmd/Makefile.cmd + +SUBDIRS = com bin + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +_msg := TARGET= _msg + +ROOTDIRS = $(ROOT)/usr/sadm/admin \ + $(ROOT)/usr/sadm/admin/printmgr \ + $(ROOT)/usr/sadm/admin/printmgr/classes + +ROOTBIN = $(ROOT)/usr/sadm/admin/printmgr/classes +ROOTBINPROG = $(PROG:%=$(ROOTBIN)/%) + +$(ROOTBINPROG):= FILEMODE = 644 +$(ROOTBINPROG):= OWNER = root +$(ROOTBINPROG):= GROUP = lp + +.KEEP_STATE: + +all: $(SUBDIRS) +install: $(SUBDIRS) $(ROOTDIRS) $(ROOTBINPROG) .WAIT links + +links: + $(RM) $(ROOTUSRSBIN)/printmgr + $(SYMLINK) ../../usr/sadm/admin/bin/printmgr \ + $(ROOTUSRSBIN)/printmgr + +clean clobber: $(SUBDIRS) + -$(RM) $(PROG) + +lint _msg: $(SUBDIRS) + +strip: + +$(PROG): FRC + @if [ $@ = "pmclient.jar" ]; \ + then $(JAR) cf $@ \ + com/sun/admin/pm/client/*class \ + com/sun/admin/pm/client/images/*gif 2>/dev/null; \ + else $(JAR) cf $@ \ + com/sun/admin/pm/server/*class 2>/dev/null; \ + fi + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +$(ROOTDIRS): + $(INS.dir) + +$(ROOTBIN)/%: % + $(INS.file) + +FRC: diff --git a/usr/src/cmd/print/printmgr/bin/Makefile b/usr/src/cmd/print/printmgr/bin/Makefile new file mode 100644 index 0000000000..d0cc89cefe --- /dev/null +++ b/usr/src/cmd/print/printmgr/bin/Makefile @@ -0,0 +1,58 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1999 by Sun Microsystems, Inc. +# All rights reserved. +# +# Makefile for print manager wrapper script +# +include $(SRC)/cmd/Makefile.cmd + +PROG = printmgr + +ROOTBIN = $(ROOT)/usr/sadm/admin/bin + +ROOTBINPROG = $(PROG:%=$(ROOTBIN)/%) + +ROOTDIRS = $(ROOT)/usr/sadm/admin \ + $(ROOT)/usr/sadm/admin/bin + +$(ROOTBINPROG):= OWNER = root +$(ROOTBINPROG):= GROUP = lp + +.KEEP_STATE: + +all: $(PROG) +install: all $(ROOTDIRS) $(ROOTBINPROG) + +$(ROOTBIN)/%: % + $(INS.file) + +$(ROOTDIRS): + $(INS.dir) + +lint strip _msg: + +clean clobber: + -$(RM) $(PROG) diff --git a/usr/src/cmd/print/printmgr/bin/printmgr.sh b/usr/src/cmd/print/printmgr/bin/printmgr.sh new file mode 100644 index 0000000000..c12d71cd86 --- /dev/null +++ b/usr/src/cmd/print/printmgr/bin/printmgr.sh @@ -0,0 +1,38 @@ +#! /usr/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +PMDIR="/usr/sadm/admin/printmgr" +CLSDIR="${PMDIR}/classes" +L10NDIR="/usr/share/lib/locale" + +CLASSPATH="${L10NDIR}:${CLSDIR}/pmclient.jar:${CLSDIR}/pmserver.jar" +LD_LIBRARY_PATH="${PMDIR}/lib" + +export CLASSPATH LD_LIBRARY_PATH + +exec /usr/java/bin/java com.sun.admin.pm.client.pmTop $1 diff --git a/usr/src/cmd/print/printmgr/com/Makefile b/usr/src/cmd/print/printmgr/com/Makefile new file mode 100644 index 0000000000..78a71dc67e --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/Makefile @@ -0,0 +1,46 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1999 by Sun Microsystems, Inc. +# All rights reserved. +# +# Makefile for print manager +# +include $(SRC)/cmd/Makefile.cmd + +SUBDIRS = sun + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +_msg := TARGET= _msg + +all install clean clobber lint _msg: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/printmgr/com/sun/Makefile b/usr/src/cmd/print/printmgr/com/sun/Makefile new file mode 100644 index 0000000000..9bfd4551f3 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/Makefile @@ -0,0 +1,46 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1999 by Sun Microsystems, Inc. +# All rights reserved. +# +# Makefile for print manager +# +include $(SRC)/cmd/Makefile.cmd + +SUBDIRS = admin + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +_msg := TARGET= _msg + +all install clean clobber lint _msg: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/Makefile b/usr/src/cmd/print/printmgr/com/sun/admin/Makefile new file mode 100644 index 0000000000..08b0c55bec --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/Makefile @@ -0,0 +1,46 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1999 by Sun Microsystems, Inc. +# All rights reserved. +# +# Makefile for print manager +# +include $(SRC)/cmd/Makefile.cmd + +SUBDIRS = pm + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +_msg := TARGET= _msg + +all install clean clobber lint _msg: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/Makefile b/usr/src/cmd/print/printmgr/com/sun/admin/pm/Makefile new file mode 100644 index 0000000000..efbf6fee75 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/Makefile @@ -0,0 +1,46 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1999 by Sun Microsystems, Inc. +# All rights reserved. +# +# Makefile for print manager +# +include $(SRC)/cmd/Makefile.cmd + +SUBDIRS = server client + +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +lint := TARGET= lint +_msg := TARGET= _msg + +all install clean clobber lint _msg: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/BST.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/BST.java new file mode 100644 index 0000000000..ee8014dc1a --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/BST.java @@ -0,0 +1,335 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * BST.java + * Simple binary search tree implementation for help articles + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; +import java.util.*; +import com.sun.admin.pm.server.*; + + +public class BST extends Object { + + // these should be protected... + public BST left = null; + public BST right = null; + public BST parent = null; + public BSTItem data; + + static public int comparisons; + + public BST(BSTItem theItem) { + // Debug.info("HELP: New BST(" + theItem + ")"); + + left = right = null; + data = theItem; + } + + + public BST() { + this(new BSTItem("", null)); + } + + public BST insert(String key, Object data) { + return insert(new BSTItem(key, data)); + } + + + // normal bst insertion + public BST insert(BSTItem theItem) { + + int comp = data.compare(theItem); + BST node = null; + + if (comp == 0) { + Debug.info("HELP: Duplicate insert: " + + theItem.toString()); + } else if (comp > 0) { + if (left != null) + left.insert(theItem); + else + left = node = new BST(theItem); + } else if (comp < 0) { + if (right != null) + right.insert(theItem); + else + right = node = new BST(theItem); + } + + return node; + } + + + public BST find_tree(String newKey) { + return find_tree(newKey, true); + } + + public BSTItem find(String newKey) { + return find(newKey, true); + } + + + public BST find_tree(String newKey, boolean exactMatch) { + /* + Debug.info("HELP: Finding " +(exactMatch ? "exact " : "partial ") + + newKey); + */ + + BST rv = null; + int comp = data.compare(newKey, exactMatch); + + ++comparisons; + + if (comp > 0) { + if (left != null) + rv = left.find_tree(newKey, exactMatch); + } else if (comp < 0) { + if (right != null) + rv = right.find_tree(newKey, exactMatch); + } else { + rv = this; + // Debug.info("HELP: Found " + newKey + " in " + data); + } + + return rv; + } + + public BSTItem find(String newKey, boolean exactMatch) { + Debug.info("HELP: Finding " +(exactMatch ? "exact " : "partial ") + + newKey); + + BSTItem rv = null; + int comp = data.compare(newKey, exactMatch); + + ++comparisons; + + if (comp > 0) { + if (left != null) + rv = left.find(newKey, exactMatch); + } else if (comp < 0) { + if (right != null) + rv = right.find(newKey, exactMatch); + } else { + Debug.info("HELP: Found " + newKey + " in " + data); + rv = this.data; + } + + return rv; + } + + + + public void traverse() { + if (left != null) + left.traverse(); + Debug.info("HELP: Traverse: " + data); + if (right != null) + right.traverse(); + } + + public void traverse_right() { + Debug.info("HELP: Traverse: " + data); + if (right != null) + right.traverse(); + } + + + public void traverse_find(String key) { + if (left != null) + left.traverse_find(key); + if (data.compare(key, false) < 0) + return; + Debug.info("HELP: Traverse_find: " + data.key); + if (right != null) + right.traverse_find(key); + } + + // empty search string is a wildcard... + public void traverse_find_vector(Vector v, String key) { + /* + * Debug.info("HELP: traverse_find_vector: node " + + * data.key + "[" +(left!=null?left.data.key:"null") + "]" + + * "[" +(right!=null ?right.data.key:"null") + "]" + + * " seeking " + key); + */ + int c = 0; + + if (key.length() > 0) + c = data.compare(key, false); + + /* + * Debug.info("HELP: traverse_find_vector: compare " + + * data.key + " to "+ key + " = " + c); + */ + + if (c >= 0 && left != null) + left.traverse_find_vector(v, key); + + if (c == 0) { + // Debug.info("HELP: traverse_find_vector: adding " + data.key); + v.addElement(data.data); + } + + if (c <= 0) { + if (right != null) + right.traverse_find_vector(v, key); + } + } + + + public void dump() { + Debug.info("HELP: \nDump: this = " + data.key); + + if (left != null) + Debug.info("HELP: Dump: left = " + left.data.key); + else + Debug.info("HELP: Dump: left = null"); + + + if (right != null) + Debug.info("HELP: Dump: right = " + right.data.key); + else + Debug.info("HELP: Dump: right = null"); + + if (left != null) + left.dump(); + if (right != null) + right.dump(); + + } + + public static void main(String args[]) { + BSTItem root = new BSTItem("Root"); + BSTItem a = new BSTItem("Alpha"); + BSTItem b = new BSTItem("Bravo"); + BSTItem c = new BSTItem("Charlie"); + BSTItem d = new BSTItem("Delta"); + BSTItem e = new BSTItem("Echo"); + BSTItem x = new BSTItem("Xray"); + BSTItem aa = new BSTItem("aspect"); + BSTItem ab = new BSTItem("assess"); + BSTItem ad = new BSTItem("assist"); + BSTItem ae = new BSTItem("asphalt"); + BSTItem af = new BSTItem("asap"); + BSTItem ag = new BSTItem("adroit"); + BSTItem ah = new BSTItem("adept"); + BSTItem ai = new BSTItem("asdf"); + + BST bst = new BST(root); + + BST.comparisons = 0; + bst.insert(a); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.insert(x); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.insert(e); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.insert(c); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.insert(b); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.insert(d); + System.out.println(BST.comparisons + + " comparisons\n"); + + bst.insert(aa); + bst.insert(ab); + bst.insert(ad); + bst.insert(ae); + bst.insert(af); + bst.insert(ag); + bst.insert(ah); + bst.insert(ai); + + bst.traverse(); + + BST.comparisons = 0; + bst.find("Echo"); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.find("Xray"); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.find("Delta"); + System.out.println(BST.comparisons + + " comparisons\n"); + BST.comparisons = 0; + bst.find("Root"); + System.out.println(BST.comparisons + + " comparisons\n"); + bst.find("Alpha"); + + bst.dump(); + if (bst.left != null) + bst.left.dump(); + if (bst.right != null) + bst.right.dump(); + + { + Debug.info("HELP: Looking for a"); + BST result = bst.find_tree("a", false); + result.traverse_find("a"); + + Debug.info("HELP: Looking for as"); + result = result.find_tree("as", false); + result.traverse_find("as"); + + Debug.info("HELP: Looking for ass"); + result = result.find_tree("ass", false); + result.traverse_find("ass"); + + Debug.info("HELP: Looking for ad"); + result = bst.find_tree("ad", false); + result.traverse_find("ad"); + } + } +} + + + + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/BSTItem.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/BSTItem.java new file mode 100644 index 0000000000..35099d7b2e --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/BSTItem.java @@ -0,0 +1,124 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * BSTItem.java + * Simple binary search tree implementation for help articles + */ + +package com.sun.admin.pm.client; + +import java.lang.*; +import com.sun.admin.pm.server.*; + +public class BSTItem extends Object { + public String key; + public Object data; + public int handle = UNINITIALIZED; + + static int serial = 0; + static final int UNINITIALIZED = -1; + + public BSTItem(String newKey) { + this(newKey, null); + } + + public BSTItem(String newKey, Object obj) { + key = newKey.toLowerCase(); + data = obj; + handle = serial++; + } + + public String toString() { + return new String("Item " + key + " (" + handle + ")"); + } + + public int compare(BSTItem otherItem, boolean exact) { + + return compare(otherItem.key, exact); + } + + + public int compare(BSTItem otherItem) { + return compare(otherItem, true); + } + + public int compare(String otherKey) { + return compare(otherKey, true); + } + + + public int compare(String otherKey, boolean exact) { + + /* + * System.out.println(this.toString() + " comparing " + + * (exact ? "exact" : "partial") + " to " + otherKey); + */ + + int rv = 0; + + if (otherKey != null && otherKey != "") + rv = exact ? + key.compareTo(otherKey) : + compareSub(otherKey.toLowerCase()); + + /* + * System.out.println( + * "Compare: " + key + " to " + otherKey + " -> " + rv); + */ + + return rv; + } + + + public int compareSub(String s) { + Debug.info("HELP: compareSub: " + key + " to " + s); + + int rv = 0; + try { + rv = key.substring(0, s.length()).compareTo(s); + } catch (Exception x) { + Debug.info("HELP: compareSub caught: " + x); + rv = -1; + } + return rv; + } +} + + + + + + + + + + + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/Constants.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/Constants.java new file mode 100644 index 0000000000..f6c8278db3 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/Constants.java @@ -0,0 +1,76 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Comment which describes the contents of this file. + * + * Constants.java + * Common constants for Printer Manager + */ + +package com.sun.admin.pm.client; + +/* + * pmConstants.java + * defines constants used with print manager + */ + +public interface Constants +{ + // Buttons + int OK = 1; + int APPLY = 2; + int RESET = 3; + int CANCEL = 4; + int HELP = 5; + + // Buttons for user access list + int ADD = 6; + int DELETE = 7; + + // Printer type to add/modify + int ADDLOCAL = 1; + int ADDNETWORK = 2; + int MODIFYATTACHED = 3; + int MODIFYREMOTE = 4; + int MODIFYNETWORK = 5; + + // Printer connection types + int ATTACHED = 1; + int NETWORK = 2; + + // Useful Constants + int MAXPNAMELEN = 20; + + // Combo Listener + int PORT = 1; + int TYPE = 2; + int MAKE = 3; + int MODEL = 4; + int PPD = 5; + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/Makefile b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/Makefile new file mode 100644 index 0000000000..829dfb4fd4 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/Makefile @@ -0,0 +1,150 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# Makefile for Java Print Manager client +# +include $(SRC)/Makefile.master +include $(SRC)/cmd/Makefile.cmd + + +CLASSPATH= $(SRC)/cmd/print/printmgr + +CLASSFILES = Constants.class \ + pmAuthOptions.class \ + pmHelpFrame.class \ + pmTop.class \ + pmResources.class \ + pmCopyright.class \ + pmUtility.class \ + pmCalls.class \ + pmLoad.class \ + pmDelete.class \ + pmAccess.class \ + pmButtonScreen.class \ + pmInstallScreen.class \ + pmInstallPrinter.class \ + pmOKCancelDialog.class \ + pmMessageDialog.class \ + pmLogin.class \ + pmLogDisplay.class \ + pmHelpDetailPanel.class \ + pmHelpContent.class \ + pmHelpController.class \ + pmHelpDetailPanel.class \ + pmHelpIndexPanel.class \ + pmHelpItem.class \ + pmHelpRepository.class \ + pmHelpSearchPanel.class \ + BST.class \ + BSTItem.class \ + pmGuiException.class \ + pmHelpException.class \ + pmAddAccessFailedException.class \ + pmAddPrinterFailedException.class \ + pmIncompleteFormException.class \ + pmLoginFailedException.class \ + pmModifyPrinterFailedException.class \ + pmPrinterExistsException.class \ + pmDeleteFailedException.class \ + pmMustBeRemoteServerException.class \ + pmUserCancelledException.class \ + pmNullSelectedPrinterException.class \ + pmNeedPPDCacheException.class \ + pmCacheMissingPPDException.class \ + pmFindFrame.class \ + pmAboutBox.class \ + pmFrame.class \ + pmButton.class \ + pmTextField.class \ + pmAuthOptions.class \ + pmOther.class + +JAVAFILES = $(CLASSFILES:.class=.java) + +MSGDIRS = $(ROOT)/usr/share/lib/locale \ + $(ROOT)/usr/share/lib/locale/com \ + $(ROOT)/usr/share/lib/locale/com/sun \ + $(ROOT)/usr/share/lib/locale/com/sun/admin \ + $(ROOT)/usr/share/lib/locale/com/sun/admin/pm \ + $(ROOT)/usr/share/lib/locale/com/sun/admin/pm/client + +MSGDIR = $(ROOT)/usr/share/lib/locale/com/sun/admin/pm/client +MSGJAVAFILES = pmResources.java pmHelpResources.java +MSGFILES = $(MSGJAVAFILES:%=$(MSGDIR)/%) + +$(MSGFILES):= OWNER = root +$(MSGFILES):= GROUP = lp +$(MSGFILES):= FILEMODE = 644 + +CLEANFILES= *.class pmHelpResources.java pmCopyright.java +CLOBBERFILES= + +# +# raw-text help files +# +HELPFILES= ./raw-help/*.rawhlp + +# +# text file containing comments to be bound into the help resource bundle +# +HELP_COMMENTS=./help-l10n-comments.txt + +install all: pmCopyright.java $(CLASSFILES) help + +pmCopyright.java: pm_gen_copyright + $(SH) ./pm_gen_copyright + +# +# pmHelpResources.java is generated by parsing raw help text +# +pmHelpResources.java: $(HELP_COMMENTS) \ + $$(HELPFILES) \ + helptools/parseMain.class \ + helptools/parsehelp + $(RM) pmHelpResources.* + cd helptools; $(MAKE) all + helptools/parsehelp -C $(HELP_COMMENTS) -D $(CLASSPATH) \ + -J $(JAVA_ROOT) $(HELPFILES) + +help: pmHelpResources.class + +_msg: $(MSGDIRS) help $(MSGFILES) + +$(MSGDIR)/%: % + $(INS.file) + +$(MSGDIRS): + $(INS.dir) + +jstyle: + jstyle $(JAVAFILES) + +lint: +clean: + $(RM) $(CLEANFILES) + cd helptools; $(MAKE) clean +clobber: clean diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/help-l10n-comments.txt b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/help-l10n-comments.txt new file mode 100644 index 0000000000..c4e6f05b72 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/help-l10n-comments.txt @@ -0,0 +1,243 @@ + +CDDL HEADER START + +The contents of this file are subject to the terms of the +Common Development and Distribution License, Version 1.0 only +(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 + +Localization Notes for the Solaris Print Manager +3/16/99 + +1. Overview + The help documentation tree consists of a collection of Articles, + each relating to a specific dialog, message, procedure, or + other topic. The text, keywords, and metadata comprising the + entire set of Articles is delivered in a single (large) + ResourceBundle per locale. + + Each article consists of several parts, all of which must be + defined within the ResourceBundle. These parts are called Tag, + Title, Content, Keywords, and See-Also. Title, Content, and + Keywords must be localized while Tag and See-Also must not. + + The Tag is an identifier unique to each Article. The application + uses Tags to refer to specific Articles. The ResourceBundle uses + each Article's Tag to form the keys which identify the + strings comprising the Article. + + The strings used as keys to identify the various parts of the + articles in the ResourceBundle are in the form of a dotted pair, + where the left side identifies the Tag of the Article to which + this string belongs and the right side describes which part of + that Article the string embodies. + + The suffixes used to identify the Tag, Title, Content, Keywords, + and See-Also parts of a help article's resources are ".tag", + ".title", ".content", ".keyword", and ".seealso" respectively. + + Examples: The key "ToAddPrinter.title" is associated with a + localizable string that represents the title of the article whose + tag is "ToAddPrinter". The key "ToDeletePrinter.content" refers to + a localizable string which contains the content of the help article + itself. + + +2. Structure of Help Articles + +2.1 Tags + Each Article is associated with a unique identifier called a Tag. + Tags are used internally and are never directly visible to users. + + A Tag is a case-sensitive string of alphanumeric 7-bit ASCII + characters containing no embedded whitespace or punctuation. + + For convenience, an article's Tag is usually formed by taking the + title and removing whitespace and punctuation; for example, + the article titled "Troubleshooting Printer Problems" might have + the Tag "TroubleShootingPrinterProblems". Note that this is a + mnemonic device only and in no way engenders a dependency between + the non-localizable Tag, which must be embedded in the + application's source code, and the article's title itself, which + must be localized. + + *TAGS ARE NOT TO BE LOCALIZED!* + + +2.2 Title and Content + Each Article must contain a Title and some Content. + + The Title is an arbitrary localizable string which will be + presented to the user upon viewing its associated Article. + + The Content of an Article consists of a block of localizable text + which may contain a limited set of embedded HTML tags (subject to + restrictions described below). + + Since the Content is displayed in a window whose size may be + adjusted by the user, its layout cannot be completely controlled by + the author. The Help display relies on word-wrapping and HTML + formatting to ensure correct appearance. + + The viewable Content of an Article is authored in a tiny subset of + HTML which can be reliably rendered in the Help component. The + intention is to provide a simple facility for controlling the + appearance of the text and for handling paragraph and line breaks. + + The supported capabilities are: + + . Emphasize sections of text by bolding: <b> ... </b> + + . Line breaks: <br> + + . Paragraph breaks: <p> + + No other HTML tags should be embedded in the Content as they + may not produce the expected results. No hyperlinks or images + are supported! + + Note that while the content itself may be localized, the HTML tags + embedded within the content should be left in ASCII. + + *BOTH TITLE AND CONTENT MUST BE LOCALIZED!* + + +2.3 Keywords + + Users may search the collection of help articles by specifying one + or more keywords (in the locale's representation) which are matched + against the set of Articles. Those articles whose keyword list has + one or more matches with the user's list will then be viewable. + + Each Article may specify a (possibly empty) list of keywords + separated by whitespace and containing no commas or punctuation. + The whitespace in this list of keywords is used only to separate + individual keywords. + + Each Keyword in the list must be a string of localizable + alphanumeric text containing no whitespace (punctuation marks such + as "-" may be OK). + + *KEYWORDS MUST BE LOCALIZED!* + + +2.4 See-Also + + Each article may refer to other Articles by presenting the user + with a "See-Also" list when the Article is viewed. This user's + view of this list contains the Titles of the specified articles, + and clicking a title causes that article to be presented. + + The See-Also list associated with a particular Article consists of + a (possibly empty) list containing Tags of other articles separated + by whitespace and containing no commas or punctuation. The list of + Titles corresponding to these Tags will be displayed to the user in + the same order that it appears in the definition of the Article. + + *SEE-ALSO ITEMS ARE NOT TO BE LOCALIZED!* + + +3. Notes on Representation of Content + + The internal representation of the Content component of each + article is as a single (long) Java String. + + Java permits the static initialization of Strings to use + catenation on the right-hand side of the assignment. + For example, the Java statements + String s = "foo bar"; + and + String s = "foo" + " " + bar; + will result in an identical assignment. + + Since the HTML rendering process which displays the resource to + the user ignores whitespace and line breaks, the initializations + of Content strings in the Help ResourceBundle exploit this approach + to make the code more readable and facilitate the localization + process. + + Note that the breaking up of the Content string into source lines is + transparent to the application; details of the source file's + appearance can change across localizations (assuming that tag names + are maintained correctly). + + As an example, consider the ResourceBundle entry which defines the + Content portion of a help article whose tag is "ToDeletePrinter". + This entry might appear in the ResourceBundle source as + + { "ToDeletePrinter.content", + + "This is some help content which would extend across several " + + "lines of text if it were all in a single long string. " + + "Since we can separate the one long string into several " + + "short ones, " + + "the source file is much more easily readable. " + } + + +4. Previewing Help Article Content + + It is possible to use an ordinary HTML browser to view the Content of + all the help Articles in a ResourceBundle. To do so requires the + extraction and formatting of the strings in the ResourceBundle which + comprise the Content portions of all included Articles. + + One approach is to create a simple script which acts as a filter; its + input is the pmHelpResources.java ResourceBundle source file and its + output is a stream of HTML which can be saved to a file and viewed in + a browser. + + The use of such a script can facilitate the localization process by + enabling localization teams to view a particular version of the + ResourceBundle as work on it progresses. + + An example of a script which performs the required formatting and + extraction is as follows: + + ----------------------- + #!/bin/ksh + # + # Copyright (c) 1999, by Sun Microsystems, Inc. + # All rights reserved. + # + # This filter accepts a pmHelpResources.java file as input + # and produces formatted HTML as output. + # + + while read line; do + echo "$line" | grep '^.*{".*\.tag"' > /dev/null + if [[ $? == 0 ]]; then + print -n "<br> <h2> " + print -n `echo "$line" | sed s/'\.'/\ / | \ + sed s/\"/\ /g | awk '{print \$2}'` + print " </h2>" + fi + + echo "$line" | grep '^\".*+$' | sed s/^\"//g | sed s/\"\ +\$// + + done + ----------------------- + + Usage of this script (assuming it is named 'extract') would be: + % extract < pmHelpResources.java > content.html + + +5. Support + + For further assistance please contact: + Claude Noshpitz, clauden@eng.sun.com. + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helpTest.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helpTest.java new file mode 100644 index 0000000000..8af71ace2a --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helpTest.java @@ -0,0 +1,196 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * helpTest.java + * Test harness for help subsystem + */ + +package com.sun.admin.pm.client; + +import java.util.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.JPanel; +import javax.swing.border.*; +import javax.swing.event.*; +import javax.swing.*; +import com.sun.admin.pm.server.*; + +class helpTest { + static private pmHelpFrame helpFrame = null; + + public static void main(String args[]) { + + Debug.setDebugLevel(Debug.ERROR); + + JFrame frame = new JFrame("Help Test Tool"); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) {System.exit(0); } + }); + + helpFrame = new pmHelpFrame(); + helpFrame.setLocation(180, 180); + + + JList theList = new JList(); + theList.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + JList l = (JList) e.getSource(); + int i = l.locationToIndex(e.getPoint()); + Debug.message("doubleclick index: " + i); + if (i >= 0) { + String s = (String) l.getModel().getElementAt(i); + Debug.message("doubleclick: " + s); + helpFrame.showHelp(s); + } + } + } + }); + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().setView(theList); + + JPanel tp = new JPanel(); + tp.setLayout(new GridBagLayout()); + GridBagConstraints pc = new GridBagConstraints(); + pc.insets = new Insets(5, 5, 0, 5); + // pc.fill = GridBagConstraints.HORIZONTAL; + pc.weightx = 1.0; + pc.anchor = GridBagConstraints.WEST; + pc.gridx = 0; + pc.gridy = GridBagConstraints.RELATIVE; + + tp.add(new JLabel("Double-click a tag to load it."), pc); + pc.insets = new Insets(0, 5, 5, 5); + tp.add(new JLabel(""), pc); + + JPanel p = new JPanel(); + p.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridheight = 1; + c.gridx = 0; + c.gridy = 0; + c.weightx = 1.0; + c.weighty = 0.0; + + c.anchor = GridBagConstraints.NORTH; + p.add(tp, c); + + JPanel pp = new JPanel(); + pp.setLayout(new BorderLayout()); + pp.add(scrollPane, "Center"); + + c.gridy = GridBagConstraints.RELATIVE; + c.gridheight = 0; + c.weighty = 1.0; + c.weightx = 0.0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.EAST; + + p.add(pp, c); + + p.setBorder(BorderFactory.createEtchedBorder()); + + frame.getContentPane().add("Center", p); + + helpTestButtonPanel bp = new helpTestButtonPanel(); + frame.getContentPane().add("South", bp); + + p = new JPanel(); + Vector v = new Vector(); + + ResourceBundle bundle = null; + + try { + bundle = ResourceBundle.getBundle( + "com.sun.admin.pm.client.pmHelpResources"); + } catch (MissingResourceException e) { + System.out.println("Could not load pmHelpResources file"); + System.exit(-1); + } + + Enumeration e = bundle.getKeys(); + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + if (key.endsWith(".tag")) { + String tagName = null; + try { + tagName = bundle.getString(key); + } catch (MissingResourceException x) { + System.out.println("Unable to find tag for " + key); + continue; + } + v.addElement(tagName); + } + } + + theList.setListData(v); + theList.removeSelectionInterval( + theList.getMinSelectionIndex(), + theList.getMaxSelectionIndex()); + // theList.addSelectionInterval(3, 5); + // theList.disable(); + + frame.pack(); + frame.setVisible(true); + frame.repaint(); + System.err.println("Hello from main"); + + } + + public void showHelpItem(String tag) { + helpFrame.showHelp(tag); + } + +} + + class helpTestButtonPanel extends JPanel { + JButton dismiss; + + public helpTestButtonPanel() { + add(dismiss = new JButton("Done")); + dismiss.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + } + } + + + + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/Makefile b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/Makefile new file mode 100644 index 0000000000..33a77b0348 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/Makefile @@ -0,0 +1,44 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright (c) 1999 by Sun Microsystems, Inc. +# All rights reserved. +# +# Makefile for Java Print Manager help tools +# +include $(SRC)/Makefile.master + +CLASSPATH= $(JAVA_ROOT)/jre/lib/rt.jar + +CLASSFILES = parseMain.class + +CLEANFILES= *.class +CLOBBERFILES= + +install all: $(CLASSFILES) + @$(CHMOD) +x ./parsehelp + +clobber: clean +clean: + $(RM) $(CLEANFILES) diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/extract b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/extract new file mode 100644 index 0000000000..b05f85fd20 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/extract @@ -0,0 +1,43 @@ +#!/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# Copyright (c) 1999, by Sun Microsystems, Inc. +# All rights reserved. +# +# This filter accepts a pmHelpResources.java file as input +# and produces formatted HTML as output. +# + +while read line; do + echo "$line" | grep '^.*{".*\.tag"' > /dev/null + if [[ $? == 0 ]]; then + print -n "<br> <h2> " + print -n `echo "$line" | sed s/'\.'/\ / | \ + sed s/\"/\ /g | awk '{print \$2}'` + print " </h2>" + fi + + echo "$line" | grep '^\".*+$' | sed s/^\"//g | sed s/\"\ +\$// + +done diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/parseMain.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/parseMain.java new file mode 100644 index 0000000000..4dbb34bb4e --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/parseMain.java @@ -0,0 +1,811 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +import java.io.*; +import java.util.*; +import java.lang.*; + + +class ResourceWriter { + + BufferedWriter theWriter = null; + String theTag = null; + + static final String NL = new String("\n"); + static final String LOCALIZE = new String("// LOCALIZE"); + static final String NOLOCALIZE = new String("// DO NOT LOCALIZE"); + static final String INDENT = new String(" "); + static final String INDENT_2 = new String(INDENT + INDENT); + static final String COMMENTBLOCK_START = new String("/*"); + static final String COMMENTBLOCK_END = new String(" */"); + static final String COMMENTLINE_START = new String(" * "); + + public ResourceWriter(BufferedWriter w) { + theWriter = w; + } + + public void close() throws IOException { + theWriter.flush(); + theWriter.close(); + } + + protected void writenl(String s) throws IOException { + theWriter.write(s, 0, s.length()); + theWriter.newLine(); + } + + protected void write(String s) throws IOException { + theWriter.write(s, 0, s.length()); + } + + public void fileheader() throws IOException { + writenl("/* "); + writenl(" * GENERATED CODE"); + writenl(" *"); + writenl(" * Copyright 1999 Sun Microsystems, Inc."); + writenl(" * All rights reserved."); + writenl(" *"); + writenl(" */"); + writenl(""); + writenl("package com.sun.admin.pm.client;"); + writenl("import java.util.*;"); + } + + public void classheader(String className) throws IOException { + writenl("public class " + className + + " extends ListResourceBundle {"); + writenl(INDENT + + "static final Object[][] pmHelpBundlecontents = {"); + } + + public void footer() throws IOException { + writenl(INDENT + "};"); + writenl(INDENT + "public Object[][] getContents() {"); + writenl(INDENT_2 + "return pmHelpBundlecontents;"); + writenl(INDENT + "}"); + writenl("}"); + } + + + public void setTag(String tag) throws IOException { + theTag = new String(tag); + } + + public void tag(String tag) throws IOException { + if (tag != null) { + writenl(NL + INDENT_2 + NOLOCALIZE); + writenl(INDENT_2 + + "{\"" + theTag + ".tag\", \"" + tag + "\"},"); + } + } + + public void title(String title) throws IOException { + if (title != null) { + writenl(NL + INDENT_2 + LOCALIZE); + writenl(INDENT_2 + + "{\"" + theTag + ".title\", \"" + title + "\"},"); + } + } + + public void seealso(String seealso) throws IOException { + if (seealso != null) { + writenl(NL + INDENT_2 + NOLOCALIZE); + writenl(INDENT_2 + + "{\"" + theTag + ".seealso\", \"" + seealso + "\"},"); + } + } + + public void keywords(String keywords) throws IOException { + if (keywords != null) { + writenl(NL + INDENT_2 + LOCALIZE); + writenl(INDENT_2 + + "{\"" + theTag + ".keywords\", \"" + keywords + "\"},"); + } + } + + public void content(Vector content) throws IOException { + if (content == null) + return; + + writenl(NL + INDENT_2 + LOCALIZE); + writenl(INDENT_2 + "{\"" + theTag + ".content\","); + + Enumeration e = content.elements(); + while (e.hasMoreElements()) { + String s = (String) e.nextElement(); + if (s.length() == 0) { + if (e.hasMoreElements()) + continue; + else { + writenl(INDENT_2 + " \"\"\n },"); + break; + } + } + String endOfLine = (e.hasMoreElements() ? + " +" : + "\n },"); + writenl(INDENT_2 + " \"" + s + " \"" + endOfLine); + } + } + + public void delimiter() throws IOException { + writenl(NL); + } + + public void commentStart() throws IOException { + writenl(COMMENTBLOCK_START); + } + + public void commentEnd() throws IOException { + writenl(COMMENTBLOCK_END); + } + + public void comment(String s) throws IOException { + writenl(COMMENTLINE_START + s); + } +} + + + + +class Article { + String theTitle; + String theKeywords; + String theSeeAlso; + Vector theContent; + String theTag; + + Reader r; + + public void read(Reader theReader) { + r = theReader; + + Tag theTag = null; + + try { + while (true) { + theTag = readNextTag(); + Debug.message("Article read: " + theTag); + + if (theTag instanceof CommentTag) { + Debug.message("Comment ignored"); + } else if (theTag instanceof TitleTag) { + theTitle = theTag.content; + } else if (theTag instanceof ContentTag) { + theContent = theTag.contentVector; + } else if (theTag instanceof SeeAlsoTag) { + theSeeAlso = theTag.content; + } else if (theTag instanceof KeywordsTag) { + theKeywords = theTag.content; + } else { + Debug.message("Unknown tag: " + theTag); + } + } + } catch (IOException x) { + Debug.message("Article read caught " + x); + } + + + } + + + int localread() throws IOException { + int ch = r.read(); + if (ch == -1) { + Debug.message("localread: eof"); + throw new IOException(); + } + // Debug.message("localread: " + ch); + return ch; + } + + + /* + * read the word within tagOpen/tagClose pair + */ + String readTagName() throws IOException { + String rv = null; + int ch; + StringBuffer b = new StringBuffer(); + + while (true) + if (localread() == HelpSyntax.tagOpen) + break; + + Debug.message("readTagName: got a tagOpen"); + + while (true) { + ch = localread(); + if (ch == HelpSyntax.tagClose) + break; + else + b.append((char) ch); + } + + Debug.message("readTagName: " + (new String(b)).trim()); + return (new String(b)).trim(); + } + + + Tag readNextTag() throws IOException { + Tag rv = null; + int ch; + StringBuffer b; + + String tag = readTagName(); + Debug.message("readNextTag name: " + tag); + + if (tag.equalsIgnoreCase(HelpSyntax.tagTitle)) { + rv = new TitleTag(); + rv.read(r); + } else if (tag.equalsIgnoreCase(HelpSyntax.tagKeywords)) { + rv = new KeywordsTag(); + rv.read(r); + } else if (tag.equalsIgnoreCase(HelpSyntax.tagSeeAlso)) { + rv = new SeeAlsoTag(); + rv.read(r); + } else if (tag.equalsIgnoreCase(HelpSyntax.tagContent)) { + rv = new ContentTag(); + rv.readMultipleLines(r); + } else { + Debug.message("Bad tag: " + tag); + } + return rv; + } + + + public String toString() { + return new String("Title <" + theTitle + + "> Keywords <" + theKeywords + + "> See-Also <" + theSeeAlso + + "> Content <" + theContent + ">"); + } +} + + +class HelpSyntax { + public final static int tagOpen = '<'; + public final static int tagClose = '>'; + public final static String startComment = "!-"; + public final static String endComment = "--"; + public final static String tagContent = "CONTENT"; + public final static String tagTitle = "TITLE"; + public final static String tagSeeAlso = "SEEALSO"; + public final static String tagKeywords = "KEYWORDS"; +} + +class ParseException extends Exception { +} + +class BadTagException extends ParseException { +} + +class SyntaxErrorException extends ParseException { +} + +abstract class Tag { + String content; + Vector contentVector; + protected String name; + protected boolean escapeQuotes = false; + + public Tag(String s) { + content = s; + } + + public Tag() { + this(null); + } + + public String toString() { + return new String(this.getClass().getName() + ": " + content); + } + + // respect line spacing, stuff contentVector + public void readMultipleLines(Reader r) throws IOException { + int ch; + StringBuffer b = new StringBuffer(); + Vector v = new Vector(); + boolean spaced = false; + + while (true) { + ch = r.read(); + if (ch == -1) + break; + + if (ch == '\n') { + v.addElement(new String(b)); + b = new StringBuffer(); + continue; + } + + if (Character.isWhitespace((char) ch)) { + if (spaced == false) { + b.append(" "); + spaced = true; + } + continue; + } + + if (escapeQuotes && ch == '\"') { + b.append("\\\""); + continue; + } + + spaced = false; + if (ch == HelpSyntax.tagOpen) { + boolean localspaced = false; + boolean localopen = true; + Debug.message("Tag: got a tagOpen"); + + StringBuffer tmp = new StringBuffer(); + while ((ch = r.read()) != HelpSyntax.tagClose) { + if (Character.isWhitespace((char) ch)) { + if (localspaced == false) { + tmp.append(" "); + localspaced = true; + } + continue; + } + tmp.append((char) ch); + } + + String t = new String(tmp); + + if ((t.trim()).equalsIgnoreCase("/" + this.name)) { + Debug.message("Tag: close tag = " + t); + break; + } else { + Debug.message("Tag: ignoring bad close tag = " + t); + b.append((char) HelpSyntax.tagOpen); + b.append(t); + b.append((char) HelpSyntax.tagClose); + } + } else { + b.append((char)ch); + } + } + contentVector = v; + Debug.message("Tag: contentVector = " + contentVector); + } + + // catenate input lines, eliminating whitespace + public void read(Reader r) throws IOException { + int ch; + StringBuffer b = new StringBuffer(); + boolean spaced = false; + + while (true) { + ch = r.read(); + if (ch == -1) + break; + + if (Character.isWhitespace((char) ch)) { + if (spaced == false) { + b.append(" "); + spaced = true; + } + continue; + } + + if (escapeQuotes && ch == '\"') { + b.append("\\\""); + continue; + } + + spaced = false; + if (ch == HelpSyntax.tagOpen) { + boolean localspaced = false; + boolean localopen = true; + Debug.message("Tag: got a tagOpen"); + + StringBuffer tmp = new StringBuffer(); + while ((ch = r.read()) != HelpSyntax.tagClose) { + if (Character.isWhitespace((char) ch)) { + if (localspaced == false) { + tmp.append(" "); + localspaced = true; + } + continue; + } + tmp.append((char) ch); + } + + String t = new String(tmp); + + if ((t.trim()).equalsIgnoreCase("/" + this.name)) { + Debug.message("Tag: close tag = " + t); + break; + } else { + Debug.message("Tag: ignoring bad close tag = " + t); + b.append((char) HelpSyntax.tagOpen); + b.append(t); + b.append((char) HelpSyntax.tagClose); + } + } else { + b.append((char)ch); + } + } + content = (new String(b)).trim(); + Debug.message("Tag: content = " + content); + } +} + +class TitleTag extends Tag { + public TitleTag() { + name = HelpSyntax.tagTitle; + } +} + +class SeeAlsoTag extends Tag { + public SeeAlsoTag() { + name = HelpSyntax.tagSeeAlso; + } +} + +class ContentTag extends Tag { + public ContentTag() { + name = HelpSyntax.tagContent; + escapeQuotes = true; + } +} + +class CommentTag extends Tag { + public CommentTag() { + name = null; + } +} + +class KeywordsTag extends Tag { + public KeywordsTag() { + name = HelpSyntax.tagKeywords; + escapeQuotes = true; + } +} + + + +class parseMain { + + static String outputFileName = "pmHelpResources.java"; + static String commentFileName = "comments.txt"; + static int firstFile = 0; + + // returns -1 if error, 0 otherwise + protected static int parseArgs(String[] args) { + int rv = 0; + int i; + + for (i = 0; i < args.length; ++i) { + if (args[i].compareTo("-d") == 0) { + if (args[i].length() > 2) { + outputFileName = args[i].substring(2); + } else { + outputFileName = args[++i]; + } + } else if (args[i].compareTo("-c") == 0) { + if (args[i].length() > 2) { + commentFileName = args[i].substring(2); + } else { + commentFileName = args[++i]; + } + } else if (args[i].compareTo("-v") == 0) { + Debug.setDebugLevel(Debug.WARNING); + } else + break; // unknown arg ==> list of files starts + + } + + firstFile = i; + + /* + * System.out.println("outputFileName = " + outputFileName + + * " commentFileName = " + commentFileName + + * " firstFile = " + firstFile); + */ + + return rv; + } + + + public static void main(String args[]) { + FileReader f = null; + FileWriter fw = null; + String filename = null; + + Debug.setDebugLevel(Debug.ERROR); + + // validate command line + if (args.length == 0) { + System.err.println("At least one filename required."); + System.exit(-1); + } + + if (parseArgs(args) < 0) + System.exit(-1); + + + outputFileName = outputFileName.trim(); + + Debug.warning("Writing to " + outputFileName); + + try { + + // create output file + fw = new FileWriter(outputFileName); + BufferedWriter w = new BufferedWriter(fw); + ResourceWriter rw = new ResourceWriter(w); + + // imports and package statement + rw.fileheader(); + + // comment block + File commentFile = new File(commentFileName); + if (commentFile.exists()) { + rw.delimiter(); + rw.commentStart(); + BufferedReader comments = + new BufferedReader(new FileReader(commentFileName)); + String commentLine; + while ((commentLine = comments.readLine()) != null) + rw.comment(commentLine); + comments.close(); + rw.commentEnd(); + rw.delimiter(); + } else { + Debug.error("Comment file " + commentFileName + + " not found."); + } + + // create class name w/o extension or leading path + File cf = new File(outputFileName); + String className = cf.getName(); + + // class name is output filename w/o extension + int dotIndex = className.indexOf("."); + if (dotIndex < 0) + dotIndex = className.length(); + + className = className.substring(0, dotIndex); + + // class definition + rw.classheader(className); + + // iterate over input files + for (int i = firstFile; i < args.length; ++i) { + filename = args[i]; + Debug.warning("Reading file " + filename); + + try { + f = new FileReader(filename); + } catch (Exception x) { + Debug.fatal(x.toString()); + return; + } + + BufferedReader r = new BufferedReader(f); + + Article a = new Article(); + a.read(r); + // System.out.println(a); + + // process the Article + + String tagName = filenameToTag(filename); + Debug.warning("Creating tag " + tagName); + + // HTML syntax checking on content + if (!validHTMLSyntax(a.theContent)) + throw new IOException( + "Bad HTML syntax in article " + tagName); + + + rw.setTag(tagName); + rw.tag(tagName); + rw.seealso(a.theSeeAlso); + rw.title(a.theTitle); + rw.keywords(a.theKeywords); + rw.content(a.theContent); + rw.delimiter(); + } + + rw.footer(); + rw.close(); + w.close(); + } catch (IOException x) { + Debug.fatal(x.toString()); + + // try to unlink the broken output file + boolean unlink = true; + + try { + fw.close(); + } catch (IOException xx) { + Debug.error(xx.toString()); + unlink = false; + } + + if (unlink) { + File theFile = new File(outputFileName); + + Debug.warning("Deleting file " + outputFileName); + + if (theFile.exists()) + theFile.delete(); + } + + System.exit(-2); + } + } + + + // return true if no syntax errors found + static boolean validHTMLSyntax(String s) { + + if (s == null) + return true; + + // check only for <b>..</b> pairs + + String src = s.toLowerCase(); // html tags are case-neutral + + int i; + + int opens = 0; + for (i = src.indexOf("<b>"); + i != -1; + i = src.indexOf("<b>", i + 1)) + ++opens; + + int closes = 0; + for (i = src.indexOf("</b>"); + i != -1; + i = src.indexOf("</b>", i + 1)) + ++closes; + + // System.out.println("syntax: " + opens + " " + closes); + + return opens == closes; + + } + + // return true if no syntax errors found + static boolean validHTMLSyntax(Vector v) { + String s = new String(); + Enumeration e = v.elements(); + while (e.hasMoreElements()) + s = s + (String) e.nextElement(); + return validHTMLSyntax(s); + } + + /* + * extract the tag name from a filename, possibly containing + * a fully qualified path as well as a complex extension. + */ + static String filenameToTag(String filename) { + + // the help tag is the filename exclusive of path or extensions + + File f = new File(filename); + String s = f.getName(); + int period = s.indexOf('.'); + // System.out.println("filename: " + s); + if (period < 0) + period = filename.length(); + // System.out.println("period = " + period); + return s.substring(0, period); + } + + +} + +class Debug { + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void fatal(String s) { + printIf(s, FATAL); + } + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void error(String s) { + printIf(s, ERROR); + } + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void warning(String s) { + printIf(s, WARNING); + } + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void message(String s) { + printIf(s, MESSAGE); + } + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void setDebugLevel(int lvl) { + if (lvl < ALL || lvl > NONE) + return; + + globalDebugLevel = lvl; + } + + private static void printIf(String s, int lvl) { + if (lvl < globalDebugLevel) + return; + DebugPrint(s); + } + + // here is where we could hide syslog or file destination... + private static void DebugPrint(String s) { + System.out.println(s); // for now + } + + + /** + * Verbosity level to suppress all messages. + */ + static public final int NONE = 5; + + /** + * Verbosity level to log only highest-priority messages. + */ + static public final int FATAL = 4; + + /** + * Verbosity level to log high- and highest-priority messages. + */ + static public final int ERROR = 3; + + /** + * Verbosity level to log medium-, high-, and + * highest-priority messages. + */ + static public final int WARNING = 2; + + /** + * Verbosity level to log low-, medium-, high-, and + * highest-priority messages. + */ + static public final int MESSAGE = 1; + + /** + * Verbosity level to log all messages. + */ + static public final int ALL = 0; + + private static int globalDebugLevel = ERROR; + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/parsehelp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/parsehelp new file mode 100644 index 0000000000..b2050c4ef3 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/helptools/parsehelp @@ -0,0 +1,83 @@ +#!/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# Copyright (c) 1999, by Sun Microsystems, Inc. +# All rights reserved. +# +# Helper script for processing raw help files. +# Parameters: +# -D <classpath> appends <classpath> to $CLASSPATH +# -J <java_dir> uses <java_dir>/bin/java. Default is /usr/java. +# -V enable verbose runtime messages + + +if [[ $# == 0 ]]; then + echo "One or more raw help files must be specified." + echo "Usage:" + echo " $0 [-D classpath] [-J java_home_dir] [-V] [-C comment_file] [-d destination-file] raw-help-file [raw-help-file]" + exit -1 +fi + +while getopts "D:J:C:V" opt; do + + case $opt in + D) DARG=$OPTARG;; + + J) JARG=$OPTARG;; + + C) COMMENT="-c "$OPTARG;; + + V) VERBOSE="-v";; + + esac +done + +shift $(($OPTIND - 1)) + +#echo "DARG: $DARG JARG: $JARG" +#echo "num left: " $# +#echo "args: $*" + +if [[ x$JARG == x ]]; then + # echo "Using default java" + JAVA_HOME="/usr/java" +else + JAVA_HOME=$JARG +fi + +DIR=$DARG + + +#PATH="$JAVA_HOME/bin:/usr/bin:/usr/sbin:/sbin:.:$PATH" +THREADS_FLAG="native" +CLASSPATH=":.:./helptools:$DIR" + +# echo "Path: $PATH" +# echo "CLASSPATH: $CLASSPATH" +# echo "Java: $JAVA_HOME/bin/java" + +echo "Processing raw help files..." +# $JAVA_HOME/bin/java -fullversion +$JAVA_HOME/bin/java -classpath $CLASSPATH parseMain $COMMENT $VERBOSE $* + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/images/appicon.gif b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/images/appicon.gif Binary files differnew file mode 100644 index 0000000000..76918b6467 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/images/appicon.gif diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAboutBox.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAboutBox.java new file mode 100644 index 0000000000..fe840bc5af --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAboutBox.java @@ -0,0 +1,117 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999-2001 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmAboutBox.java + * + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; + +import com.sun.admin.pm.server.*; + + +public class pmAboutBox extends pmFrame { + public pmButton cancel = null; + String title = pmUtility.getResource("About.Solaris.Print.Manager"); + String copyright = new String(pmUtility.getResource("info_copyright1") + + pmUtility.getCopyrightResource("copyright_year") + + pmUtility.getResource("info_copyright2")); + String version = pmUtility.getResource("info_version"); + String appname = pmUtility.getResource("info_name"); + String contents = new String(appname + "\n" + + version + "\n\n" + + copyright + "\n"); + + public pmAboutBox() { + + super(pmUtility.getResource("About.Solaris.Print.Manager")); + + cancel = new pmButton(pmUtility.getResource("Cancel")); + cancel.setMnemonic(pmUtility.getIntResource("Cancel.mnemonic")); + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + hideAboutBox(); + } + }); + + // Create a regular text field. + JTextArea textArea = new JTextArea(contents); + Font f = new pmJTextField().getFont(); + Font fb = new Font(f.getName(), f.PLAIN, f.getSize()); + textArea.setOpaque(false); + textArea.setFont(fb); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + textArea.setEditable(false); + textArea.setDisabledTextColor(Color.blue); + + JPanel j1 = new JPanel(); + j1.setBorder(new EmptyBorder(10, 10, 10, 10)); + j1.setLayout(new BorderLayout()); + JScrollPane areaScrollPane = new JScrollPane(textArea); + areaScrollPane.setPreferredSize(new Dimension(270, 175)); + j1.add(areaScrollPane, BorderLayout.CENTER); + + JPanel buttonPanel = new JPanel(); + buttonPanel.setBorder(new EmptyBorder(0, 0, 10, 10)); + buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); + buttonPanel.add(cancel); + + JPanel bottomPanel = new JPanel(new BorderLayout()); + bottomPanel.add(buttonPanel, BorderLayout.SOUTH); + + Container contentPane = getContentPane(); + contentPane.add(j1, BorderLayout.CENTER); + contentPane.add(bottomPanel, BorderLayout.SOUTH); + + // default button is cancel + cancel.setAsDefaultButton(); + + // handle Esc as cancel + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("HELP: cancel action"); + hideAboutBox(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + pack(); + repaint(); + + } + + public void hideAboutBox() { + this.setVisible(false); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAccess.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAccess.java new file mode 100644 index 0000000000..df18761f41 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAccess.java @@ -0,0 +1,520 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Comment which describes the contents of this file. + * + * pmAccess.java + * Add Access To Printer handling + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.util.Vector; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * Window for Edit -> Add Access to a Printer + */ + +public class pmAccess extends pmButtonScreen { + JComboBox portCombo; + pmFrame frame = new pmFrame( + pmUtility.getResource("SPM:Add.Access.To.Printer")); + pmTextField pnameText; + pmTextField snameText; + pmTextField descText; + Boolean makedefault; + JCheckBox defaultp; + Printer newpr = null; + pmTop mytop; + String printer = null; + String server = null; + + String cmdLog = null; + String errorLog = null; + String warnLog = null; + + + final static int OK = 1; + final static int APPLY = 2; + final static int RESET = 3; + final static int CANCEL = 4; + final static int HELP = 5; + + public pmAccess(pmTop mytop) { + + // ensure that pmButton hashtable gets cleaned up + frame.setClearButtonsOnClose(true); + + setLayout(new BorderLayout()); + + this.mytop = mytop; + + // Build the Frame + centerPanel(); + southPanel(); + + /* + * let's try doing this in Show... + * + * // default button is always OK, for now... + * frame.getRootPane().setDefaultButton(okButton); + * + * okButton.setAsDefaultButton(); + */ + + // handle Esc as cancel + this.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + actioncancelButton(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + // enable the pmFrame to set focus to our default comp on activation + frame.setDefaultComponent(pnameText); + + + // following is test code, I think... + Component glass = frame.getGlassPane(); + + glass.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent k) { + Debug.info("Glass: " + k); + } + public void keyReleased(KeyEvent k) { + Debug.info("Glass: " + k); + } + public void keyTyped(KeyEvent k) { + Debug.info("Glass: " + k); + } + }); + + } + + public void centerPanel() { + // Build center panel + JPanel center = new JPanel(); + center.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + // define center constraints + c.insets = new Insets(8, 5, 5, 5); + c.gridheight = 1; + c.gridwidth = 1; + + // build center components + // Create + c.gridx = 0; + c.weightx = c.weighty = 0.0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + + // Build the labels + c.gridy = 0; + center.add(new JLabel + (pmUtility.getResource("Printer.Name:")), c); + c.gridy = 1; + center.add(new JLabel + (pmUtility.getResource("Printer.Server:")), c); + c.gridy = 2; + center.add(new JLabel + (pmUtility.getResource("Description:")), c); + c.gridy = 3; + center.add(new JLabel + (pmUtility.getResource("Option:")), c); + + // Build the text fields + // Common constraints + c.gridx = 1; + c.ipadx = 15; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.WEST; + c.weightx = c.weighty = 1.0; + + c.gridy = 0; + pnameText = new pmTextField(14); + + center.add(pnameText, c); + + c.gridy = 1; + snameText = new pmTextField(25); + center.add(snameText, c); + + c.gridy = 2; + descText = new pmTextField(25); + center.add(descText, c); + + // Add Choice Menus - ComboBox + c.weightx = c.weighty = 0.0; + c.gridy = 3; + + defaultp = new JCheckBox( + pmUtility.getResource("Default.Printer")); + center.add(defaultp, c); + + add("Center", center); + } + + public void createAccess() throws pmGuiException { + boolean getHostOk = true; + String description = ""; + + newpr = new Printer(mytop.ns); + Debug.message("CLNT: createAccess()"); + pmCalls.debugShowPrinter(newpr); + printer = pnameText.getText().trim(); + server = snameText.getText().trim(); + description = descText.getText(); + + if (printer.equals("")) { + pnameText.requestFocus(); + Debug.message("CLNT:pmAccess:Printer name required."); + throw new pmIncompleteFormException( + pmUtility.getResource("Printer.name.required.")); + } + + if (!Valid.remotePrinterName(printer)) { + pnameText.requestFocus(); + Debug.message("CLNT:pmAccess:Printer name invalid: " + printer); + throw new pmIncompleteFormException( + pmUtility.getResource("Printer.name.invalid.")); + } + + if (server.equals("")) { + snameText.requestFocus(); + Debug.message("CLNT:pmAccess:Server name required."); + throw new pmIncompleteFormException( + pmUtility.getResource("Server.name.required.")); + } + + if (!Valid.serverName(server)) { + snameText.requestFocus(); + Debug.message("CLNT:pmAccess:Server name invalid."); + throw new pmIncompleteFormException( + pmUtility.getResource("Server.name.invalid.")); + } + + try { + if (server.equals(mytop.host.getLocalHostName())) { + snameText.requestFocus(); + getHostOk = false; + } + } catch (Exception e) { + Debug.warning( + "CLNT: pmAccess:createAccess:getLocalHostName exception"); + throw new pmGuiException( + pmUtility.getResource( + "Could.not.get.local.hostname " + e)); + } + + if (!getHostOk) { + Debug.warning( + "CLNT: pmAccess:createAccess:Server name required."); + throw new pmMustBeRemoteServerException( + pmUtility.getResource("Server.name.required.")); + } + + boolean exist; + try { + exist = PrinterUtil.exists(printer, mytop.ns); + } catch (Exception e) { + throw new pmGuiException(e.toString()); + } + + if (exist) { + throw new pmPrinterExistsException(); + } + + if (mytop.ns.getNameService().equals("nis") == true || + mytop.ns.getNameService().equals("ldap") == true) { + try { + if (!mytop.ns.isAuth()) { + pmUtility.doLogin(mytop, frame); + } + } catch (pmUserCancelledException e) { + Debug.message("CLNT:pmAccess:user cancelled login"); + throw new pmUserCancelledException( + pmUtility.getResource( + "User.cancelled.login.")); + } catch (pmGuiException e) { + Debug.message( + "CLNT:pmAccess:login nis/nis+/ldap failed: " + e); + throw new pmLoginFailedException(); + } catch (Exception e) { + Debug.message( + "CLNT:pmAccess:login nis/nis+/ldap failed: " + e); + throw new pmLoginFailedException(); + } + } + + Debug.message("CLNT:pmAccess:checkbox: " + defaultp.isSelected()); + + // Check for confirmation option + if (((mytop.getConfirmOption() == true) && (confirmAction() == true)) + || (mytop.getConfirmOption() == false)) { + + // Set the printer attributes + newpr.setPrinterName(printer); + newpr.setPrintServer(server); + newpr.setComment(description); + if (defaultp.isSelected()) + newpr.setIsDefaultPrinter(true); + + frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + boolean failed = false; + try { + newpr.addRemotePrinter(); + } catch (Exception e) { + failed = true; + Debug.warning( + "CLNT:pmAccess:addRemotePrinter caught:" + e); + } + + frame.setCursor(Cursor.getDefaultCursor()); + + gatherLogs(); + dumpLogs("CLNT:pmAccess:createAccess()"); + + pmCalls.debugShowPrinter(newpr); + + mytop.setLogData(cmdLog, errorLog, warnLog); + mytop.showLogData( + pmUtility.getResource("Add.Access.To.Printer")); + + mytop.pmsetPrinterList(); + mytop.clearSelected(); + mytop.listTable.clearSelection(); + + if (failed) + throw new pmAddAccessFailedException(errorLog); + + } + } + + public void clearAccessInput() { + try { + pnameText.setText(""); + snameText.setText(""); + descText.setText(""); + if (defaultp.isSelected()) + defaultp.doClick(); + } catch (Exception e) { + // ignore??? + // throw new pmGuiException("pmAccess: Error clearAccessInput: " + e); + Debug.warning("CLNT:pmAccess: Error clearAccessInput: " + e); + } + } + + + + public boolean confirmAction() { + if (mytop.getConfirmOption() == true) { + pmOKCancelDialog d = new pmOKCancelDialog(frame, + pmUtility.getResource("Action.Confirmation"), + pmUtility.getResource( + "Continue.creating.access.for.this.printer?")); + d.setVisible(true); + if (d.getValue() != JOptionPane.OK_OPTION) { + pmMessageDialog m = new pmMessageDialog(frame, + pmUtility.getResource("Warning"), + pmUtility.getResource("Operation.Cancelled")); + m.setVisible(true); + return false; + } + } + return true; + } + + void gatherLogs() { + cmdLog = newpr.getCmdLog(); + errorLog = newpr.getErrorLog(); + warnLog = newpr.getWarnLog(); + } + + + void dumpLogs(String who) { + Debug.message(who); + Debug.message(who + " command: " + cmdLog); + Debug.message(who + " warnings: " + warnLog); + Debug.message(who + " errors: " + errorLog); + } + + // returns true if success, false otherwise + boolean doAction() { + boolean rv = false; + + try { + createAccess(); + rv = true; // only if it didn't throw! + } catch (pmIncompleteFormException ix) { + Debug.warning( + "CLNT:pmAccess:incomplete form " + ix.getMessage()); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + ix.getMessage(), + mytop, + "AddAccessFailed"); + m.setVisible(true); + } catch (pmPrinterExistsException ex) { + Debug.warning("CLNT:pmAccess:printer exists"); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource("The.specified.printer.already.exists.")); + m.setVisible(true); + } catch (pmMustBeRemoteServerException rx) { + Debug.warning("CLNT:pmAccess:server must be remove."); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "The.server.must.be.a.remote.server."), + mytop, + "RemoteServer"); + m.setVisible(true); + + } catch (pmLoginFailedException lx) { + Debug.warning("CLNT:pmAccess:Required login failed"); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource("Required.login.failed."), + mytop, + "LoginFailed"); + m.setVisible(true); + + } catch (pmAddAccessFailedException ax) { + Debug.warning( + "CLNT:pmAccess:add access failed " + ax.getMessage()); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + ax.getMessage(), + mytop, + "AddAccessFailed"); + m.setVisible(true); + + } catch (pmUserCancelledException cx) { + Debug.message( + "CLNT:pmAccess:createAccess: User cancelled namespace login"); + } catch (pmGuiException gx) { + Debug.warning( + "CLNT:pmAccess:Application Error" + gx.getMessage()); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Application.Error"), + gx.getMessage()); + m.setVisible(true); + + } finally { + // clearAccessInput(); + } + return rv; + } + + + public void pmScreendispose() { + frame.dispose(); + } + + public void actionokButton() { + Debug.message("CLNT:pmAccess:actionokButton()"); + + if (doAction() == true) { + clearAccessInput(); + mytop.pmsetdefaultpLabel(); + frame.setVisible(false); + frame.repaint(); + // frame.dispose(); + mytop.scrollPane.revalidate(); + mytop.scrollPane.repaint(); + } else { + Debug.message("CLNT: pmAccess: doAction is false"); + } + + } + + public void actionapplyButton() { + Debug.message("CLNT:pmAccess:actionapplyButton()"); + + if (doAction() == true) { + mytop.pmsetdefaultpLabel(); + mytop.scrollPane.revalidate(); + mytop.scrollPane.repaint(); + + } + } + + + public void actionresetButton() { + Debug.message("CLNT:pmAccess:actionresetButton()"); + clearAccessInput(); + pnameText.requestFocus(); + } + + public void actioncancelButton() { + Debug.message("CLNT:pmAccess:actioncancelButton()"); + clearAccessInput(); + frame.setVisible(false); + frame.repaint(); + // frame.dispose(); + } + + public void actionhelpButton() { + Debug.message("CLNT:pmAccess:actionhelpButton()"); + mytop.showHelpItem("AddAccess"); + } + + + public void Show() { + + frame.getContentPane().add("North", this); + frame.pack(); + frame.setVisible(true); + frame.repaint(); + + frame.toFront(); + frame.requestFocus(); + + okButton.setAsDefaultButton(); + pnameText.requestFocus(); + Debug.message("CLNT:pmAccess:Show()"); + + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAddAccessFailedException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAddAccessFailedException.java new file mode 100644 index 0000000000..377d70fb61 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAddAccessFailedException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmAddAccessFailedException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmAddAccessFailedException extends pmGuiException { + public pmAddAccessFailedException(String s) { + super(s); + } + public pmAddAccessFailedException() { + super(); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAddPrinterFailedException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAddPrinterFailedException.java new file mode 100644 index 0000000000..08fccef1c0 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAddPrinterFailedException.java @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmAddPrinterFailedException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmAddPrinterFailedException extends pmGuiException { + public pmAddPrinterFailedException(String s) { + super(s); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAuthOptions.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAuthOptions.java new file mode 100644 index 0000000000..2bcfcba9bf --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmAuthOptions.java @@ -0,0 +1,433 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmAuthOptions.java + * Prompt for root password from printmgr. + * This a helper for printmgr which echoes YES, NO, or CANCEL to stdout. + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; +import com.sun.admin.pm.server.*; + + +public class pmAuthOptions { + + public static void main(String[] args) { + + boolean done = false; + String rv = "CANCEL"; + + pmAuthMessage o = new pmAuthMessage(null, + pmUtility.getResource("Authentication.required"), + pmUtility.getResource("Root.access.is.required")); + o.setVisible(true); + switch (o.getValue()) { + case JOptionPane.YES_OPTION: + break; + + case JOptionPane.NO_OPTION: + System.out.println("NO"); + System.exit(0); + break; + + case JOptionPane.CANCEL_OPTION: + default: + System.out.println("CANCEL"); + System.exit(0); + break; + } + + while (!done) { + pmAuthLogin d = new pmAuthLogin(null, + pmUtility.getResource("Root.authentication"), + pmUtility.getResource("Enter.root.password")); + d.setVisible(true); + if (d.getValue() != JOptionPane.OK_OPTION) + done = true; + else { + boolean ok = false; + String pw = new String(d.getPassword()); + try { + PrinterUtil.checkRootPasswd(pw); + ok = true; + } catch (Exception x) { + + } + if (!ok) { + pmOKCancelDialog m = new pmOKCancelDialog(null, + pmUtility.getResource("Error"), + pmUtility.getResource("Invalid.password")); + m.setVisible(true); + if (m.getValue() != JOptionPane.OK_OPTION) + done = true; + } else { + done = true; + rv = "YES"; + } + } + } + + System.out.println(rv); + System.exit(0); + } + + +} + + + + + + +/* + */ + +class pmAuthLogin extends pmDialog { + private String theTag = null; + + protected pmButton okButton = null; + protected pmButton cancelButton = null; + + public pmAuthLogin(JFrame f, String title, String msg) { + + super(f, title, true); // modal + + JLabel l; + JPanel p; + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.EAST; + + // top panel contains the desired message + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + l = new JLabel(msg, SwingConstants.CENTER); + p.add(l, c); + this.getContentPane().add(p, "North"); + + + // middle panel contains username and password + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + l = new JLabel(pmUtility.getResource("Hostname:"), + SwingConstants.RIGHT); + p.add(l, c); + + l = new JLabel(pmUtility.getResource("Password:"), + SwingConstants.RIGHT); + p.add(l, c); + + passwordField = new JPasswordField(12); + passwordField.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + okPressed(); + } + }); + l.setLabelFor(passwordField); + + // for consistency, don't implement this until all are... + // l.setDisplayedMnemonic( + // pmUtility.getIntResource("Password.mnemonic")); + + c.gridx = 1; + c.weightx = 1.0; + + c.anchor = GridBagConstraints.WEST; + + String hostname = null; + try { + hostname = (java.net.InetAddress.getLocalHost()).getHostName(); + } catch (java.net.UnknownHostException uhx) { + System.out.println(uhx); + } + + l = new JLabel(hostname, SwingConstants.LEFT); + p.add(l, c); + + + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridy = GridBagConstraints.RELATIVE; + + p.add(passwordField, c); + passwordField.setEchoChar('*'); + + this.getContentPane().add(p, "Center"); + + // bottom panel contains buttons + c.gridx = 0; + c.weightx = 1.0; + c.weighty = 0.0; + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + + JPanel thePanel = new JPanel(); + + okButton = new pmButton( + pmUtility.getResource("OK")); + okButton.setMnemonic( + pmUtility.getIntResource("OK.mnemonic")); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okPressed(); + } + }); + thePanel.add(okButton, c); + + cancelButton = new pmButton( + pmUtility.getResource("Cancel")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Cancel.mnemonic")); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + cancelPressed(); + } + }); + thePanel.add(cancelButton, c); + + this.getContentPane().add(thePanel, "South"); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + returnValue = JOptionPane.CANCEL_OPTION; + setVisible(false); + } + }); + + // handle Esc as cancel in any case + this.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + cancelPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + // lay out the dialog + this.pack(); + + // set focus and defaults after packing... + // this.getRootPane().setDefaultButton(okButton); + okButton.setAsDefaultButton(); + + passwordField.requestFocus(); + } + + public int getValue() { + return returnValue; + } + + + public void okPressed() { + returnValue = JOptionPane.OK_OPTION; + setVisible(false); + } + + public void cancelPressed() { + returnValue = JOptionPane.CANCEL_OPTION; + setVisible(false); + } + + + public void clearPressed() { + passwordField.setText(""); + } + + public char[] getPassword() { + return passwordField.getPassword(); + } + + + public JPasswordField passwordField = null; + + protected int returnValue = JOptionPane.CANCEL_OPTION; + +} + + + + + + + +class pmAuthMessage extends pmDialog { + private String theTag = null; + + protected pmButton authButton = null; + protected pmButton cancelButton = null; + protected pmButton contButton = null; + + public pmAuthMessage(JFrame f, String title, String msg) { + + super(f, title, true); // modal + + JPanel p; + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.EAST; + + // top panel contains the desired message + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + + JList l = new JList() { + public boolean isFocusable() { + return false; + } + }; + // pathetic hacks to make the list look the same as a label + JLabel tmp = new JLabel(); + l.setBackground(tmp.getBackground()); + l.setForeground(tmp.getForeground()); + l.setFont(tmp.getFont()); + tmp = null; + Vector v = new Vector(); + if (msg != null) { + StringTokenizer st = new StringTokenizer(msg, "\n", false); + try { + while (st.hasMoreTokens()) + v.addElement(st.nextToken()); + } catch (Exception x) { + } + l.setListData(v); + } + + + p.add(l, c); + this.getContentPane().add(p, "North"); + + + // bottom panel contains buttons + c.gridx = 0; + c.weightx = 1.0; + c.weighty = 0.0; + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + + JPanel thePanel = new JPanel(); + + authButton = new pmButton(pmUtility.getResource("Authenticate")); + authButton.setMnemonic( + pmUtility.getIntResource("Authenticate.mnemonic")); + authButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + authPressed(); + } + }); + thePanel.add(authButton, c); + + contButton = new pmButton(pmUtility.getResource("Continue")); + contButton.setMnemonic(pmUtility.getIntResource("Continue.mnemonic")); + contButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + contPressed(); + } + }); + thePanel.add(contButton, c); + + cancelButton = new pmButton(pmUtility.getResource("Cancel")); + cancelButton.setMnemonic(pmUtility.getIntResource("Cancel.mnemonic")); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + cancelPressed(); + } + }); + thePanel.add(cancelButton, c); + + this.getContentPane().add(thePanel, "South"); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + returnValue = JOptionPane.CANCEL_OPTION; + setVisible(false); + } + }); + + // handle Esc as cancel in any case + this.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + cancelPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + // lay out the dialog + this.pack(); + + // set focus and defaults after packing... + authButton.setAsDefaultButton(); + + } + + public int getValue() { + return returnValue; + } + + + public void authPressed() { + returnValue = JOptionPane.YES_OPTION; + setVisible(false); + } + + public void cancelPressed() { + returnValue = JOptionPane.CANCEL_OPTION; + setVisible(false); + } + + + public void contPressed() { + returnValue = JOptionPane.NO_OPTION; + setVisible(false); + } + + protected int returnValue = JOptionPane.CANCEL_OPTION; + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmButton.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmButton.java new file mode 100644 index 0000000000..e520679b6b --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmButton.java @@ -0,0 +1,221 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmButton.java + * + */ + +package com.sun.admin.pm.client; + +import java.util.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + +/* + * strategy: + * Keep a hashtable of root panes and their associated default buttons. + * Note that there is at present no way to remove a root pane entry + * from the table... + * + * Ideally there should be an interface to allow objects to + * remove themselves before disappearing. + */ + +public class pmButton extends JButton { + + // static JButton defaultButton = null; + + // map root panes to their true default buttons + static Hashtable map = new Hashtable(); + + public static Hashtable getHashtable() { + return map; + } + + /* + * make this button the default on this root pane + * retunrs true if success, false o/w + */ + boolean makeDefaultButton() { + return makeDefaultButton(this); + } + + /* + * make b the default on this root pane + * returns true if success, false otherwise + */ + boolean makeDefaultButton(JButton b) { + JRootPane r = this.getRootPane(); + + if (r == null) { + Debug.info("BUTTON: null root panel"); + return false; + } + + if (b == null) { + Debug.info("BUTTON: makeDefaultButton null on " + r); + } + + /* + * Debug.info("\nBUTTON: makeDefaultButton " + + * (b == null ? "null" : b.getText()) + + * " on " + r + "\n"); + */ + + if (b != null && b.isDefaultCapable() == false) { + Debug.info("BUTTON: false isDefaultCapable on " + r); + return false; + } + + // unfocus the old default, if it's different + JButton oldb; + if ((oldb = r.getDefaultButton()) != null && oldb != b) { + oldb.setFocusPainted(false); + } + + /* + * Debug.info("\nBUTTON: makeDefaultButton: old button was " + + * (oldb == null ? "null" : oldb.getText()) + "\n"); + */ + + r.setDefaultButton(b); + + return true; + } + + + public pmButton(String s) { + super(s); + + this.addFocusListener(new FocusAdapter() { + + // upon gaining focus: make this the root pane's default + public void focusGained(FocusEvent e) { + if (e.isTemporary()) { + /* + * Debug.info("BUTTON: " + getText() + + * " gained temp - ignoring"); + */ + return; + } + + Debug.info("BUTTON: " + getText() + " gained"); + + if (makeDefaultButton()) + setFocusPainted(true); + + } + + // upon losing focus: make 'true' default the default + public void focusLost(FocusEvent e) { + if (e.isTemporary()) { + /* + * Debug.info("BUTTON: " + getText() + + * " lost temp - ignoring"); + */ + return; + } + + Debug.info("BUTTON: " + getText() + " lost"); + + /* + * i thought it might make sense to test for the + * next focusable comp, but what if focus is being + * lost as the result of a mouse click?? + */ + + makeDefaultButton((JButton) map.get(getRootPane())); + // setFocusPainted(false); + } + + }); + } + + // make this the true default for this root pane + void setAsDefaultButton() { + setAsDefaultButton(this); + } + + // make b the true default for this root pane + void setAsDefaultButton(JButton b) { + JRootPane r = getRootPane(); + + /* + * Debug.message("BUTTON: setAsDefaultButton " + + * (b == null ? "null" : b.getText()) + + * " root = " + r); + */ + + // setting default to null removes state + if (b == null) + map.remove(r); + else + map.put(r, b); // creates a new entry if needed + makeDefaultButton(b); + } + + + // clean up component about to be removed + void unreference() { + JRootPane r = getRootPane(); + map.remove(r); + } + + public static void unreference(JComponent c) { + JRootPane r = c.getRootPane(); + map.remove(r); + } + + public static void unreference(JRootPane r) { + map.remove(r); + } + + + static boolean enableMnemonics = false; + + static void setEnableMnemonics(boolean m) { + enableMnemonics = m; + } + + public void setMnemonic(int mnemonic) { + setMnemonic((char)mnemonic); + } + + public void setMnemonic(char mnemonic) { + if (enableMnemonics) + super.setMnemonic(mnemonic); + } + +} + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmButtonScreen.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmButtonScreen.java new file mode 100644 index 0000000000..25eb756842 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmButtonScreen.java @@ -0,0 +1,179 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmButtonsScreen.java + * Common dialog superclass + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * Screen class for JPanels + */ + +public class pmButtonScreen extends JPanel { + + final static int OK = 1; + final static int APPLY = 2; + final static int RESET = 3; + final static int CANCEL = 4; + final static int HELP = 5; + + pmButton okButton; + pmButton applyButton; + pmButton resetButton; + pmButton cancelButton; + pmButton helpButton; + + + public void southPanel() { + + JPanel south = new JPanel(); + + south.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = c.weighty = 0.0; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridy = 0; + + okButton = new pmButton( + pmUtility.getResource("OK")); + okButton.setMnemonic( + pmUtility.getIntResource("OK.mnemonic")); + + applyButton = new pmButton( + pmUtility.getResource("Apply")); + applyButton.setMnemonic( + pmUtility.getIntResource("Apply.mnemonic")); + + resetButton = new pmButton( + pmUtility.getResource("Reset")); + resetButton.setMnemonic( + pmUtility.getIntResource("Reset.mnemonic")); + + cancelButton = new pmButton( + pmUtility.getResource("Cancel")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Cancel.mnemonic")); + + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + + okButton.addActionListener(new ButtonListener(OK)); + applyButton.addActionListener(new ButtonListener(APPLY)); + resetButton.addActionListener(new ButtonListener(RESET)); + cancelButton.addActionListener(new ButtonListener(CANCEL)); + helpButton.addActionListener(new ButtonListener(HELP)); + + c.insets = new Insets(15, 5, 10, 5); + c.gridx = 0; + south.add(okButton, c); + c.gridx = 1; + south.add(applyButton, c); + c.gridx = 2; + south.add(resetButton, c); + c.gridx = 3; + south.add(cancelButton, c); + c.gridx = 4; + south.add(helpButton, c); + + add("South", south); + } + + class ButtonListener implements ActionListener { + int activeButton; + + // Constructor + + public ButtonListener(int aButton) + { + activeButton = aButton; + } + + public void actionPerformed(ActionEvent e) + { + switch (activeButton) { + case OK: + actionokButton(); + break; + case APPLY: + actionapplyButton(); + break; + case RESET: + actionresetButton(); + break; + case CANCEL: + actioncancelButton(); + break; + case HELP: + actionhelpButton(); + break; + } + } + } + + public void actionokButton() + { + } + + public void actionapplyButton() + { + } + + public void actionresetButton() + { + } + + public void actioncancelButton() + { + } + + public void actionhelpButton() + { + } + + + +} + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmCacheMissingPPDException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmCacheMissingPPDException.java new file mode 100644 index 0000000000..4a2b171f68 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmCacheMissingPPDException.java @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmInstallPrinter.java + * Install and Modify Printer implementation + * + * pmCacheMissingPPDException + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +public class pmCacheMissingPPDException extends pmGuiException { + public pmCacheMissingPPDException(String s) { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmCalls.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmCalls.java new file mode 100644 index 0000000000..72a8124dd5 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmCalls.java @@ -0,0 +1,159 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmCalls.java + * Debug messages + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.applet.*; +import java.io.*; +import java.util.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * Class of calls to backend + */ + +public class pmCalls { + +/* + * Debugging routines + */ + + public static void testout(String out) { + Debug.info(out); + } + + public static void debugShowPrinter(Printer p) { + Debug.info("CLNT: debugShowPrinter"); + + if (p.getPrinterName() != null) { + Debug.info("CLNT: printer " + + p.getPrinterName()); + } + + if (p.getPrintServer() != null) + Debug.info("CLNT: server " + + p.getPrintServer()); + + if (p.getPrinterType() != null) + Debug.info("CLNT: printer type " + + p.getPrinterType()); + + if (p.getComment() != null) + Debug.info("CLNT: Comment " + + p.getComment()); + + if (p.getDevice() != null) + Debug.info("CLNT: Device " + + p.getDevice()); + + if (p.getMake() != null) + Debug.info("CLNT: Make " + + p.getMake()); + else + Debug.info("CLNT: Make is null"); + + if (p.getModel() != null) + Debug.info("CLNT: Model " + + p.getModel()); + else + Debug.info("CLNT: Model is null"); + + if (p.getPPD() != null) + Debug.info("CLNT: PPD " + + p.getPPD()); + else + Debug.info("CLNT: PPD is null"); + + if (p.getNotify() != null) + Debug.info("CLNT: Notify " + + p.getNotify()); + + if (p.getBanner() != null) + Debug.info("CLNT: Banner " + p.getBanner()); + + if (p.getProtocol() != null) + Debug.info("CLNT: Protocol " + + p.getProtocol()); + + if (p.getDestination() != null) + Debug.info("CLNT: Destination " + + p.getDestination()); + + if (p.getFileContents() != null) { + + String filedata[] = p.getFileContents(); + String filecontents = new String(); + + Debug.info("CLNT: File Contents: "); + + if (filedata != null) { + for (int i = 0; i < filedata.length; i++) { + Debug.info(" " + filedata[i]); + } + } + } + + if (p.getNotify() != null) { + Debug.info("CLNT: Fault Notification: " + p.getNotify()); + } + + String ua[] = p.getUserAllowList(); + Debug.info("CLNT: UserAllowList "); + if (ua != null) { + for (int i = 0; i < ua.length; i++) { + Debug.info(" " + ua[i]); + } + } + + Debug.info("CLNT: getIsDefaultPrinter is " + p.getIsDefaultPrinter()); + + } + + public static void debugshowPrinterList(NameService ns) { + + String[] list; + + try { + list = PrinterUtil.getPrinterList(ns); + for (int i = 0; i < list.length; i++) + Debug.info("CLNT: " + list[i]); + } catch (Exception e) { + Debug.info("CLNT: debugshowPrinterList(): exception " + e); + } + + } + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDelete.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDelete.java new file mode 100644 index 0000000000..eb35e916e0 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDelete.java @@ -0,0 +1,184 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmDelete.java + * Delete Printer implementation + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * Window for Edit -> Delete + */ + +//public class pmDelete extends JPanel { +public class pmDelete { + + Printer newpr = null; + pmTop mytop = null; + + public pmDelete(pmTop mytop) + { + this.mytop = mytop; + newpr = new Printer(mytop.ns); + + Debug.message("CLNT: pmDelete"); + + if (mytop.selectedPrinter.equals("")) { + Debug.warning("CLNT: pmDelete:error: selectedPrinter empty"); + // Display error window + actioncancelButton(); + } + + pmOKCancelDialog d = new pmOKCancelDialog( + mytop.parentFrame, + pmUtility.getResource("SPM:Delete.Printer"), + pmUtility.getResource("Please.confirm.deletion.of.printer") + + mytop.selectedPrinter, false); + d.setVisible(true); + + if (d.getValue() != JOptionPane.OK_OPTION) + actioncancelButton(); + else { + try { + actionokButton(); + } catch (pmUserCancelledException ce) { + Debug.message("CLNT: pmDelete:okButton: Login cancelled"); + } catch (pmLoginFailedException de) { + pmMessageDialog m = new pmMessageDialog( + mytop.parentFrame, + pmUtility.getResource("Error"), + pmUtility.getResource("Required.login.failed."), + mytop, + "LoginFailed"); + m.setVisible(true); + } catch (pmGuiException ge) { + pmMessageDialog m = new pmMessageDialog( + mytop.parentFrame, + pmUtility.getResource("Application.Error"), + ge.toString()); + m.setVisible(true); + } + } + + } + + public void actionokButton() throws pmGuiException { + int ret; + String cmd = null; + String warn = null; + String err = null; + + Debug.message("CLNT: pmDelete actionokButton()"); + + // handle authentication if needed + if (mytop.ns.getNameService().equals("nis") == true || + mytop.ns.getNameService().equals("ldap") == true) { + try { + if (!mytop.ns.isAuth()) { + pmUtility.doLogin(mytop, mytop.parentFrame); + } + } catch (pmUserCancelledException e) { + Debug.message("CLNT: pmDelete:User cancelled login"); + throw new pmUserCancelledException( + pmUtility.getResource("User.Cancelled.Login")); + } catch (pmGuiException e) { + Debug.warning("CLNT: pmDelete:login for nis/ldap failed"); + throw new pmLoginFailedException( + pmUtility.getResource("Login.Authorization.Failed")); + } catch (Exception e) { + Debug.warning("CLNT: pmDelete:login for nis/ldap failed"); + throw new pmLoginFailedException( + pmUtility.getResource("Login.Authorization.Failed")); + } + } + + newpr.setPrinterName(mytop.selectedPrinter); + + // delete the printer + boolean failed = false; + try { + newpr.deletePrinter(); + } catch (Exception e) { + Debug.warning("CLNT: pmDelete:deletePrinter exception " + e); + failed = true; + } + + cmd = newpr.getCmdLog(); + warn = newpr.getWarnLog(); + err = newpr.getErrorLog(); + + Debug.message("CLNT: pmDelete: delete cmd = " + cmd); + Debug.message("CLNT: pmDelete: delete err = " + err); + Debug.message("CLNT: pmDelete: delete warn = " + warn); + + if (failed) { + pmMessageDialog m = new pmMessageDialog( + mytop.parentFrame, + pmUtility.getResource("Error"), + ((err == null) ? + pmUtility.getResource( + "Printer.delete.operation.failed.") : + err), + mytop, + "DeletePrinterFailed"); + m.setVisible(true); + + } else { + Debug.message("CLNT: pmDelete return from deletePrinter ok"); + + // Deletion successful, change the table + if (mytop.selectedRow >= 0) { + // update table + mytop.pmsetPrinterList(); + mytop.clearSelected(); + mytop.listTable.clearSelection(); + mytop.pmsetdefaultpLabel(); + } else { + Debug.warning("CLNT: pmDelete:selectedRow invalid: " + + mytop.selectedRow); + } + } + mytop.setLogData(cmd, err, warn); + mytop.showLogData(pmUtility.getResource("Delete.Printer")); + } + + + public void actioncancelButton() { + Debug.message("CLNT: pmDelete: actioncancelButton()"); + } + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDeleteFailedException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDeleteFailedException.java new file mode 100644 index 0000000000..9edd59d063 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDeleteFailedException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmDeleteFailedException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmDeleteFailedException extends pmGuiException { + public pmDeleteFailedException(String s) { + super(s); + } + public pmDeleteFailedException() { + super(); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDialog.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDialog.java new file mode 100644 index 0000000000..87a9adbdf8 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDialog.java @@ -0,0 +1,125 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmDialog.java + * Extends JDialog to provide for better default location. + */ + +package com.sun.admin.pm.client; + +import java.net.*; +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +import com.sun.admin.pm.server.Debug; + +public class pmDialog extends JDialog implements pmDialogConstraints { + + public pmDialog(Frame owner) { + this(owner, null, false); + } + + public pmDialog(Frame owner, boolean modal) { + this(owner, null, modal); + } + + public pmDialog(Frame owner, String title) { + this(owner, title, false); + } + + public pmDialog(Frame f, String title, boolean modal) { + + super(f, title, modal); + + // determine a nice location relative to parent frame + Point newLocation = new Point(0, 0); // default + + if (f == null) { + // centered on screen + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + newLocation = new Point(screenSize.width / 2 - xoffset, + screenSize.height / 2 - yoffset); + + } else { + // centered over parent frame + Rectangle parentBounds = f.getBounds(); + newLocation = new Point( + parentBounds.x + parentBounds.width / 2 - xoffset, + parentBounds.y + parentBounds.height / 2 - yoffset); + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + Debug.info("dialog Window closing"); + cleanupButtons(); + } + public void windowClosed(WindowEvent e) { + Debug.info("dialog Window closed"); + cleanupButtons(); + } + public void windowDeactivated(WindowEvent e) { + Debug.info("dialog Window deactivated"); + // possible java bug: too many of these events generated! + // cleanupButtons(); + } + }); + } + setLocation(newLocation); + + // cannot set dialog icons under 1.1.... + /* + * try { + * String iconName = new String("images/appicon.gif"); + * Class thisClass = this.getClass(); + * URL iconUrl = thisClass.getResource(iconName); + * if (iconUrl == null) + * Debug.warning("Unable to resolve URL for icon " + iconName); + * else { + * Toolkit tk = Toolkit.getDefaultToolkit(); + * Image img = tk.getImage(iconUrl); + * // this.setIconImage(img); + * } + * } catch (Exception x) { + * Debug.warning(x.toString()); + * } + */ + + } + + public void cleanupButtons() { + // drop this rootPane from pmButton's hashtable + pmButton.unreference(this.getRootPane()); + } + + public void setVisible(boolean b) { + if (b == false) + cleanupButtons(); + super.setVisible(b); + } + +} + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDialogConstraints.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDialogConstraints.java new file mode 100644 index 0000000000..f7a90727c1 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmDialogConstraints.java @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmDialogConstraints.java + * Location constants for pmDialogs. + */ + +package com.sun.admin.pm.client; + +public interface pmDialogConstraints { + + /* + * These are offsets from origin of a pmDialog's parent frame + * at which to place the newly created dialog. + */ + static final int xoffset = 100; + static final int yoffset = 80; +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmFindFrame.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmFindFrame.java new file mode 100644 index 0000000000..9c0ce1fe43 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmFindFrame.java @@ -0,0 +1,229 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmFindFrame.java + * Find Printer dialog implementation + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +public class pmFindFrame extends pmFrame { + + JLabel statusText = null; + pmButton okButton = null; + pmButton cancelButton = null; + pmButton helpButton = null; + pmTop theTop = null; + + String label = pmUtility.getResource("Enter.name.of.printer.to.find"); + String helpTag = "ToFindPrinter"; + + public pmFindFrame(pmTop t) { + + super(pmUtility.getResource("SPM:Find.Printer")); + + setLocation(100, 100); + + theTop = t; + + + JLabel l; + JPanel p; + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 5, 10); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1.0; + + // top panel contains the message + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + l = new JLabel(label, SwingConstants.LEFT); + p.add(l, c); + + getContentPane().add(p, "North"); + + // middle panel contains "other" text field + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + printerName = new pmTextField(30); + printerName.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + okPressed(); + } + }); + l.setLabelFor(printerName); + + c.gridx = 1; + c.gridy = 0; + c.weightx = 1.0; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(0, 10, 5, 10); + + p.add(printerName, c); + + statusText = new JLabel(" ", SwingConstants.LEFT); + + c.gridy = GridBagConstraints.RELATIVE; + c.gridx = 0; + c.gridwidth = 2; + + c.insets = new Insets(5, 10, 5, 10); + p.add(statusText, c); + + getContentPane().add(p, "Center"); + + // bottom panel contains buttons + c.gridx = 0; + c.weightx = 1.0; + c.weighty = 0.0; + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(5, 10, 10, 10); + + JPanel thePanel = new JPanel(); + + okButton = new pmButton( + pmUtility.getResource("Find")); + okButton.setMnemonic( + pmUtility.getIntResource("Find.mnemonic")); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okPressed(); + } + }); + thePanel.add(okButton, c); + + cancelButton = new pmButton( + pmUtility.getResource("Dismiss")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Dismiss.mnemonic")); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + cancelPressed(); + } + }); + thePanel.add(cancelButton, c); + + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + helpButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + theTop.showHelpItem(helpTag); + } + }); + thePanel.add(helpButton, c); + + getContentPane().add(thePanel, "South"); + + // lay out the dialog + pack(); + + // handle Esc as dismiss in any case + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + cancelPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + + // set focus to initial field, depending on which action is tbd + // this seems to work best after pack() + + /** + frame.setVisible(true); + frame.repaint(); + */ + + // getRootPane().setDefaultButton (okButton); + okButton.setAsDefaultButton(); + + printerName.requestFocus(); + + // enable improved focus handling + setDefaultComponent(printerName); + + } + + + public void okPressed() { + Debug.message("CLNT: pmFindFrame:okPressed():" + + printerName.getText()); + + String name = printerName.getText(); + boolean result = theTop.findPrinterInList(name.trim()); + if (!result) + statusText.setText(new String( + pmUtility.getResource("Unable.to.find.printer") + name)); + else + statusText.setText(" "); + + // pmFindPanel.this.frame.setVisible (false); + + } + + public void cancelPressed() { + Debug.message("CLNT: pmFindFrame: cancelPressed()"); + statusText.setText(" "); + printerName.setText(""); + pmFindFrame.this.setVisible(false); + + } + + public pmTextField printerName = null; + +} + + + + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmFrame.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmFrame.java new file mode 100644 index 0000000000..97ac7eecae --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmFrame.java @@ -0,0 +1,136 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmFrame.java + * Extends JFrame to support better focus handling + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.net.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + +class pmFrame extends JFrame { + + // this comp gets focus on frame open + Component defaultComponent = null; + + // file path of icon; this does not provide for localization + private static final String iconName = "images/appicon.gif"; + + // if true, clean up pmButton state on frame close + private boolean clearButtonsOnClose; + + public pmFrame(String s) { + super(s); + + // default: do NOT clear default button state when frame is closed + clearButtonsOnClose = false; + + this.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + Debug.message("CLNT: pmFrame focus gained: " + e); + if (defaultComponent != null) { + Debug.message("CLNT: pmFrame focus to default comp"); + defaultComponent.requestFocus(); + } else + Debug.message("CLNT: pmFrame no default comp"); + } + public void focusLost(FocusEvent e) { + Debug.message("CLNT: frame focus lost: " + e); + } + }); + + this.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + Debug.info("frame Window closing"); + cleanupButtons(); + } + public void windowClosed(WindowEvent e) { + Debug.info("frame Window closed"); + cleanupButtons(); + } + }); + + try { + Class thisClass = this.getClass(); + URL iconUrl = thisClass.getResource(iconName); + // System.out.println("Icon: " + iconUrl); + if (iconUrl == null) + Debug.warning("Unable to resolve URL for icon " + iconName); + else { + Toolkit tk = Toolkit.getDefaultToolkit(); + Image img = tk.getImage(iconUrl); + this.setIconImage(img); + } + + } catch (Exception x) { + Debug.warning(x.toString()); + } + } + + + public void setDefaultComponent(Component c) { + defaultComponent = c; + } + + + // If the frame is a minimized icon, make it un-minimized first + public void setVisible(boolean isVisible) { + if (isVisible == true) { + try { + // this will fail in jdk 1.1 but work fine in 1.2 + setState(NORMAL); + } catch (Exception ssx) { + // restores an iconified window in JDK 1.1 + removeNotify(); + addNotify(); + } + } else + cleanupButtons(); + super.setVisible(isVisible); + } + + public void cleanupButtons() { + // drop this rootPane from pmButton's hashtable + if (clearButtonsOnClose) + pmButton.unreference(this.getRootPane()); + } + + protected void setClearButtonsOnClose(boolean b) { + clearButtonsOnClose = b; + } + + +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmGuiException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmGuiException.java new file mode 100644 index 0000000000..53824adee1 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmGuiException.java @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmGuiException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +public class pmGuiException extends Exception { + + String s = null; + + public pmGuiException(String s) { + super(s); + + } + + public pmGuiException() { + super(); + + } + +// XXX use localized strings + public String getLocalizedMessage() { + return getMessage(); + + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpContent.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpContent.java new file mode 100644 index 0000000000..1cd729028a --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpContent.java @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpContent.java + * Wrapper for content of help articles + */ + +package com.sun.admin.pm.client; + +class pmHelpContent extends Object { + private String text; + + public pmHelpContent(String content) { + text = content; + } + + public pmHelpContent(pmHelpContent other) { + text = new String(other.text); + } + + public String toString() { + return text; + } + + public String getText() { + return text; + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpController.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpController.java new file mode 100644 index 0000000000..8824a0e7aa --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpController.java @@ -0,0 +1,106 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpController.java + * Help subsystem implementation + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.io.*; +import javax.swing.JPanel; +import javax.swing.border.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + +class pmHelpController { + + public pmHelpFrame frame = null; + + /* + * request presentation of the specified help item. + */ + public void showHelpItem(String tag) { + Debug.info("HELP: controller.showHelpitem " + tag); + if (tag != null) { + pmHelpItem item = viewPanel.loadItemForTag(tag); + outerPanel.setSelectedComponent(viewPanel); + } + } + + public void showHelpItem(pmHelpItem item) { + if (item != null) + showHelpItem(item.tag); + } + + JTabbedPane outerPanel; + pmHelpDetailPanel viewPanel; + pmHelpIndexPanel indexPanel; + pmHelpSearchPanel searchPanel; + + Vector history; + + public JTabbedPane getTopPane() { + return outerPanel; + } + + public pmHelpController(pmHelpFrame f) { + + frame = f; + + outerPanel = new JTabbedPane(); + + viewPanel = new pmHelpDetailPanel(this); + indexPanel = new pmHelpIndexPanel(this); + searchPanel = new pmHelpSearchPanel(this); + + outerPanel.add(pmUtility.getResource("View"), viewPanel); + outerPanel.add(pmUtility.getResource("Index"), indexPanel); + outerPanel.add(pmUtility.getResource("Search"), searchPanel); + + pmHelpRepository.populateHelpItemDB(); + pmHelpRepository.populateHelpKeywordDB(); + pmHelpRepository.populateHelpTitleDB(); + + indexPanel.queryPanel.handleText(""); // prime it... ugly. + + history = new Vector(); + + frame.setDefaultComponent(outerPanel); + } + + +} + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpDetailPanel.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpDetailPanel.java new file mode 100644 index 0000000000..46640f42b4 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpDetailPanel.java @@ -0,0 +1,621 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 - 2001 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpDetailPanel.java + * View a help article + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.io.*; +import java.net.URL; +import javax.swing.JPanel; +import javax.swing.border.*; +import javax.swing.event.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + +class pmHelpLoc { + public pmHelpItem item; + public Point pos; + + public pmHelpLoc(pmHelpItem i) { + this(i, new Point(0, 0)); + } + + public pmHelpLoc(pmHelpItem i, Point p) { + item = i; + pos = p; + } + + public pmHelpLoc() { + this(null, new Point(0, 0)); + } +} + +public class pmHelpDetailPanel extends JPanel { + + pmHelpController controller; + pmHelpSeeAlsoPanel seeAlsoPanel; + pmHelpViewPanel viewPanel; + + pmHelpLoc history[]; + int historyIndex; + int historyLast; + + static final int MAX_HISTORY_ITEMS = 101; + + public pmHelpDetailPanel(pmHelpController ctrl) { + + controller = ctrl; + + // build subpanels + seeAlsoPanel = new pmHelpSeeAlsoPanel(this); + viewPanel = new pmHelpViewPanel(this); + + // lay out top panel + this.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.insets = new Insets(5, 5, 5, 5); + + c.gridwidth = GridBagConstraints.REMAINDER; + + c.gridx = 0; + c.gridy = 0; + + c.gridheight = 2; // GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1.0; + c.weighty = 6.0; + c.insets = new Insets(5, 5, 0, 5); + this.add(viewPanel, c); + + c.gridy = GridBagConstraints.RELATIVE; + // c.gridheight = GridBagConstraints.REMAINDER; + c.gridheight = 0; + c.weighty = 0.0; + c.weightx = 1.0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(0, 5, 5, 5); + this.add(seeAlsoPanel, c); + + this.setBorder(BorderFactory.createEtchedBorder()); + + history = new pmHelpLoc[MAX_HISTORY_ITEMS]; + historyIndex = 0; + historyLast = 0; + + // manage focus when we are tabbed or un-tabbed + controller.outerPanel.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + JTabbedPane tp = (JTabbedPane) e.getSource(); + Debug.info("HELP: Tab event!"); + if (!(tp.getSelectedComponent() instanceof + com.sun.admin.pm.client.pmHelpDetailPanel)) { + Debug.info("HELP: Tab event: resetting default"); + /* + controller.frame.getRootPane(). + setDefaultButton( + controller.frame.dismiss); + */ + if (controller.frame.dismiss != null) + controller.frame.dismiss. + setAsDefaultButton(); + } + } + }); + + addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + Debug.info("HELP: detailPanel gained focus"); + if (controller.frame.dismiss != null) + controller.frame.dismiss. + setAsDefaultButton(); + + } + }); + } + + // ask parent controller to show item + public void showItem(String tag) { + controller.showHelpItem(tag); + } + + public void showHistoryBackItem() { + Debug.message("HELP: showHistoryBackItem: index = " + + historyIndex + " last = " + + historyLast + + "\n\thistory = " + + history); + + // assuming item already visible, preserve its position + history[historyIndex].pos = viewPanel.getPos(); + + Debug.info("back: pos is " + history[historyIndex].pos); + + if (historyIndex > 1) { + pmHelpLoc l = history [--historyIndex]; + pmHelpItem item = l.item; + Point p = l.pos; + loadItem(item, p); + } + viewPanel.setNavButtons(historyIndex, historyLast); + } + + public void showHistoryForwardItem() { + Debug.message("HELP: showHistoryForwardItem: index = " + + historyIndex + + " last = " + historyLast + + "\n\thistory = " + history); + + // assuming already an item visible, preserve its position + history[historyIndex].pos = viewPanel.getPos(); + + Debug.info("HELP: fwd: pos is " + history[historyIndex].pos); + + if (historyIndex < historyLast) { + pmHelpLoc l = history [++historyIndex]; + pmHelpItem item = l.item; + Point p = l.pos; + loadItem(item, p); + } + viewPanel.setNavButtons(historyIndex, historyLast); + } + + + /* + * load the help item + * internal + */ + protected pmHelpItem loadItem(pmHelpItem item) { + return loadItem(item, new Point(0, 0)); + } + + protected pmHelpItem loadItem(pmHelpItem item, Point pos) { + Debug.message("HELP: View: loadItem " + item.tag); + seeAlsoPanel.setItems(item.seealso); + + Debug.info("loadItem: pos is " + pos); + + viewPanel.setItem(item.title, item.content); + viewPanel.setPos(pos); + return item; + } + + + /* + * load the help item corresponding to the specified tag + * external - called from helpController + * note that this is how see-also items are loadedes + */ + public pmHelpItem loadItemForTag(String tag) { + + pmHelpItem item; + + if (tag == null || + (item = pmHelpRepository.helpItemForTag(tag)) == null) { + Debug.warning("HELP: View: item not found"); + loadEmptyItem(tag); + return null; + } + + Debug.info("loadItem(before): index = " + historyIndex + + ", last = " + historyLast); + + // if there's already an item visible, preserve its position + if (historyIndex != 0 && historyLast != 0) + history[historyIndex].pos = viewPanel.getPos(); + + loadItem(item); + + Debug.info("HELP: loadItemForTag: index = " + historyIndex + + " last = " + historyLast + "\n\thistory = " + + history); + + /* + * make the new item the latest in history. + * if the history length is maxed out, the new item + * will replace the item that's currently last. + */ + + if (historyIndex < history.length - 1) { + // init pos to 0,0 + history [++historyIndex] = new pmHelpLoc(item); + } else { + // replace last item + history [historyIndex] = new pmHelpLoc(item); + } + historyLast = historyIndex; + + viewPanel.setNavButtons(historyIndex, historyLast); + + Debug.info("loadItem(after): index = " + historyIndex + + ", last = " + historyLast); + return item; + } + + private void loadEmptyItem(String itm) { + String msg = new String( + pmUtility.getResource("Item.not.found:") + itm); + viewPanel.setItem(msg, new pmHelpContent( + pmUtility.getResource("No.information.available."))); + seeAlsoPanel.setItems(null); + } + +} + + + +class pmHelpSeeAlsoPanel extends JPanel { + + pmHelpDetailPanel parentPanel = null; + Vector seeAlsoItems = null; + JComboBox theComboBox = null; + pmButton selectButton = null; + + private void layoutBox() { + + JPanel p = new JPanel(); + p.setLayout(new BorderLayout(5, 0)); + + p.add(new JPanel(), "North"); + p.add(new JPanel(), "South"); + + p.add(new JLabel( + pmUtility.getResource("See.also:")), "West"); + + theComboBox = new JComboBox(); + + Font f = theComboBox.getFont(); + Font fb = new Font(f.getName(), f.PLAIN, f.getSize()); + theComboBox.setFont(fb); + + theComboBox.setPreferredSize( + new Dimension(200, theComboBox.getPreferredSize().height)); + theComboBox.setMinimumSize( + new Dimension(20, theComboBox.getPreferredSize().height)); + theComboBox.setMaximumSize( + new Dimension(300, theComboBox.getPreferredSize().height)); + theComboBox.setEnabled(false); + + /* + theComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JComboBox src = (JComboBox) e.getSource(); + System.out.println("Combo: action = " + + e.getActionCommand()); + System.out.println("Combo: mod = " + + e.getModifiers()); + System.out.println("Combo: param = " + + e.paramString()); + System.out.println("Combo: item = " + + src.getSelectedItem()); + } + }); + */ + + p.add(theComboBox, "Center"); + + selectButton = new pmButton( + pmUtility.getResource("Show")); + selectButton.setMnemonic( + pmUtility.getIntResource("Show.mnemonic")); + selectButton.setEnabled(false); + + p.add(selectButton, "East"); + selectButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + pmHelpItem i = (pmHelpItem) theComboBox.getSelectedItem(); + Debug.message("HELP: got button: item is " + i); + // parentPanel.loadItemForTag(i.tag); + parentPanel.showItem(i.tag); + } + }); + + JPanel pp = new JPanel(); + pp.setLayout(new BorderLayout(5, 0)); + pp.add(p, "Center"); + + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + this.add(Box.createHorizontalStrut(10)); + this.add(pp); + this.add(Box.createHorizontalStrut(10)); + this.add(Box.createHorizontalGlue()); + + } + + public pmHelpSeeAlsoPanel(pmHelpDetailPanel p) { + parentPanel = p; + layoutBox(); + this.setBorder(BorderFactory.createEtchedBorder()); + } + + + /* + * set the titles of the pmHelpItems whose tags are + * passed into see-also combo box + */ + public void setItems(Vector tags) { + clearItems(); + + if (tags == null) + return; + + Enumeration e = tags.elements(); + while (e.hasMoreElements()) { + pmHelpItem i = + pmHelpRepository.helpItemForTag((String) e.nextElement()); + if (i != null) + theComboBox.addItem(i); + } + + selectButton.setEnabled(true); + theComboBox.setEnabled(true); + + + // repaint(); + } + + + public void clearItems() { + if (theComboBox.getItemCount() > 0) + theComboBox.removeAllItems(); + selectButton.setEnabled(false); + theComboBox.setEnabled(false); + } + +} + + +class pmHelpViewPanel extends JPanel { + // JTextArea helpView; + JEditorPane helpView; + JScrollPane scrollPane; + pmHelpHelpOnPanel titlePanel; + pmHelpDetailPanel parentPanel; + pmButton backButton; + pmButton forwardButton; + + public pmHelpViewPanel(pmHelpDetailPanel par) { + parentPanel = par; + + // helpView = new JTextArea(10, 32); + // helpView.setLineWrap(true); + + helpView = new JEditorPane(); + + helpView.setContentType("text/html"); + helpView.setEditable(false); + helpView.setEnabled(false); + helpView.setDisabledTextColor(Color.blue); + + scrollPane = new JScrollPane(helpView); + + this.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 10, 5, 10); + c.gridwidth = GridBagConstraints.REMAINDER; + + c.gridx = 0; + c.gridy = 0; + + c.gridheight = 1; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1.0; + // c.weighty = 1.0; + c.weighty = 0.05; + + titlePanel = new pmHelpHelpOnPanel(); + this.add(titlePanel, c); + + c.gridy = 1; + c.gridheight = 1; + + c.gridwidth = GridBagConstraints.REMAINDER; + c.weightx = 1.0; + c.weighty = 6.0; + c.fill = GridBagConstraints.BOTH; + c.insets = new Insets(5, 10, 5, 10); + // c.insets = new Insets(5, 5, 5, 5); // NEW + this.add(scrollPane, c); + + this.setBorder(BorderFactory.createEtchedBorder()); + + /* + */ + try { + helpView.setPage(new URL("file:///test.html")); + } catch (Exception x) { + Debug.info("setPage caught: " + x); + } + /* + */ + + // navigation buttons + JPanel p = new JPanel(); + p.setLayout(new GridBagLayout()); + GridBagConstraints pc = new GridBagConstraints(); + // pc.insets = new Insets(2, 2, 2, 2); + // pc.fill = GridBagConstraints.HORIZONTAL; + pc.weightx = 1.0; + pc.weighty = 1.0; + pc.gridx = 0; + pc.anchor = GridBagConstraints.WEST; + + backButton = new pmButton( + pmUtility.getResource("Back")); + backButton.setMnemonic( + pmUtility.getIntResource("Back.mnemonic")); + p.add(backButton, pc); + backButton.setEnabled(false); + backButton.setDefaultCapable(false); + backButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + parentPanel.showHistoryBackItem(); + } + }); + + + pc.gridx = 1; + pc.anchor = GridBagConstraints.EAST; + + forwardButton = new pmButton( + pmUtility.getResource("Forward")); + forwardButton.setMnemonic( + pmUtility.getIntResource("Forward.mnemonic")); + p.add(forwardButton, pc); + forwardButton.setEnabled(false); + forwardButton.setDefaultCapable(false); + forwardButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + parentPanel.showHistoryForwardItem(); + } + }); + + c.gridy = GridBagConstraints.RELATIVE; + c.gridheight = 1; // GridBagConstraints.REMAINDER; + c.gridwidth = GridBagConstraints.REMAINDER; + c.weightx = 1.0; + // c.weighty = 1.0; + c.weighty = 0.05; // NEW + + c.fill = GridBagConstraints.BOTH; + c.insets = new Insets(0, 10, 5, 10); + // c.insets = new Insets(0, 10, 5, 10); + c.insets = new Insets(5, 10, 5, 10); + // NEW + + add(p, c); + + } + + + public void setItem(String title, pmHelpContent content) { + helpView.setText(content.getText()); + // scrollPane.getViewport().setViewPosition(new Point(0, 0)); + titlePanel.helpTopic.setText(title); + } + + public void setPos(Point p) { + scrollPane.getViewport().setViewPosition(p); + } + + public Point getPos() { + return scrollPane.getViewport().getViewPosition(); + } + + public void setNavButtons(int index, int last) { + Debug.message("HELP: NavButtons " + index + " " + last); + + if (last > index) + forwardButton.setEnabled(true); + else + forwardButton.setEnabled(false); + + if (index > 1 && last > 1) + backButton.setEnabled(true); + else + backButton.setEnabled(false); + } + +} + + +class pmJTextField extends JTextField { + public boolean isFocusable() { + return false; + } +} + +class pmHelpHelpOnPanel extends JPanel { + + pmJTextField helpTopic; + + public pmHelpHelpOnPanel() { + + helpTopic = new pmJTextField(); + helpTopic.setEditable(false); + helpTopic.setText("Default help topic"); + helpTopic.setBackground(Color.white); + + Font f = helpTopic.getFont(); + Font fb = new Font(f.getName(), Font.BOLD, f.getSize()); + helpTopic.setFont(fb); + + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + JPanel p = new JPanel(); + p.setLayout(new BorderLayout(5, 0)); + p.add(new JLabel( + pmUtility.getResource("Help.on:")), + "West"); + p.add(helpTopic, "Center"); + + JPanel pp = new JPanel(); + pp.setLayout(new BorderLayout(0, 0)); + pp.add(p, "Center"); + + // this.add(Box.createHorizontalStrut(5)); + this.add(pp); + // this.add(Box.createHorizontalStrut(5)); + this.add(Box.createHorizontalGlue()); + + + // this.setBorder(BorderFactory.createEtchedBorder()); + + } + +} + + + + + + + + + + + + + + + + + + + + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpException.java new file mode 100644 index 0000000000..0079965950 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpException.java @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmHelpException extends Exception { +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpFrame.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpFrame.java new file mode 100644 index 0000000000..7ee794b6da --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpFrame.java @@ -0,0 +1,103 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpFrame.java + * Container for help subsystem GUI + */ + +package com.sun.admin.pm.client; + +import java.lang.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.io.*; +import javax.swing.JPanel; +import javax.swing.border.*; +import javax.swing.*; +import com.sun.admin.pm.server.*; + + +public class pmHelpFrame extends pmFrame { + + protected pmHelpController theController = null; + public pmButton dismiss = null; // expose for default button hacks + + public pmHelpFrame() { + super(pmUtility.getResource("SPM:Help")); + + theController = new pmHelpController(this); + getContentPane().add("Center", theController.getTopPane()); + + dismiss = new pmButton( + pmUtility.getResource("Dismiss")); + dismiss.setMnemonic( + pmUtility.getIntResource("Dismiss.mnemonic")); + dismiss.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + hideHelp(); + } + }); + + JPanel p = new JPanel(); + p.add(dismiss); + + getContentPane().add("South", p); + + this.pack(); + this.setVisible(false); + this.repaint(); + + // default button is dismiss + // getRootPane().setDefaultButton(dismiss); + dismiss.setAsDefaultButton(); + + // handle Esc as dismiss + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("HELP: dismiss action"); + hideHelp(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + } + + + public void hideHelp() { + this.setVisible(false); + } + + + public void showHelp(String tag) { + theController.showHelpItem(tag); + this.setVisible(true); + this.repaint(); + } + +} + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpIndexPanel.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpIndexPanel.java new file mode 100644 index 0000000000..fa145bcbb9 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpIndexPanel.java @@ -0,0 +1,391 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpIndexPanel.java + * Search help titles + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.JPanel; +import javax.swing.border.*; +import javax.swing.event.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +public class pmHelpIndexPanel extends JPanel { + + pmHelpController controller; + pmHelpIndexQueryPanel queryPanel; + pmHelpIndexResultPanel resultPanel; + JLabel textPanels[]; + + public pmHelpIndexPanel(pmHelpController ctrl) { + controller = ctrl; + + // build subpanels + queryPanel = new pmHelpIndexQueryPanel(this); + resultPanel = new pmHelpIndexResultPanel(this); + + textPanels = new JLabel[4]; + textPanels[0] = new JLabel( + pmUtility.getResource("To.search.the.index...")); + textPanels[1] = new JLabel( + pmUtility.getResource("type.your.query.below...")); + + // lay out top panel + this.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + c.gridwidth = GridBagConstraints.REMAINDER; + + c.gridx = 0; + c.gridy = 0; + + c.gridheight = 1; // GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1.0; + c.weighty = 0.0; + + JPanel p = new JPanel(); + p.setLayout(new GridBagLayout()); + GridBagConstraints pc = new GridBagConstraints(); + pc.insets = new Insets(5, 5, 0, 5); + // pc.fill = GridBagConstraints.HORIZONTAL; + pc.weightx = 1.0; + pc.anchor = GridBagConstraints.WEST; + pc.gridx = 0; + pc.gridy = GridBagConstraints.RELATIVE; + + p.add(textPanels[0], pc); + pc.insets = new Insets(0, 5, 5, 5); + p.add(textPanels[1], pc); + // p.add(textPanels[2]); + + this.add(p, c); + + p = new JPanel(); + p.setLayout(new BorderLayout()); + p.add(queryPanel, "North"); + p.add(resultPanel, "Center"); + p.setBorder(BorderFactory.createEtchedBorder()); + + c.gridy = GridBagConstraints.RELATIVE; + c.gridheight = 0; + c.weighty = 1.0; + c.weightx = 0.0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.EAST; + + this.add(p, c); + + this.setBorder(BorderFactory.createEtchedBorder()); + + + // figure out when we are un-tabbed + controller.outerPanel.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + JTabbedPane tp = (JTabbedPane) e.getSource(); + Debug.info("HELP: Tab event!"); + if (!(tp.getSelectedComponent() instanceof + com.sun.admin.pm.client.pmHelpIndexPanel)) { + Debug.info("HELP: Tab event: resetting default"); + /* + controller.frame.getRootPane(). + setDefaultButton( + controller.frame.dismiss); + */ + } else { + // allow tab to retain focus + // queryPanel.query.requestFocus(); + } + } + }); + + + } + + + // place item titles in search result panel + public void setSearchResults(Vector items) { + Vector v = new Vector(); + + if (items.size() == 0) { + resultPanel.setListEmpty(true); + v.addElement(pmUtility.getResource("Nothing.matched.")); + } else { + Enumeration e = items.elements(); + while (e.hasMoreElements()) { + pmHelpItem i = (pmHelpItem) e.nextElement(); + v.addElement(i); + } + resultPanel.setListEmpty(false); + } + + resultPanel.setResultList(v); + } + +} + + + +class pmHelpIndexResultPanel extends JPanel { + + JList resultList = null; + pmButton selectButton = null; + pmHelpIndexPanel parentPanel = null; + protected boolean listEmpty = true; + + + public pmHelpIndexResultPanel(pmHelpIndexPanel p) { + + parentPanel = p; + + this.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(10, 10, 10, 10); + c.fill = GridBagConstraints.NONE; + c.weightx = c.weighty = 0.0; + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.NORTHWEST; + + JLabel promptLabel = new JLabel( + pmUtility.getResource("Matching.entries:")); +/* + * MNEMONIC + * promptLabel.setDisplayedMnemonic( + * pmUtility.getIntResource("Matching.entries:.mnemonic")); + */ + + this.add(promptLabel, c); + + c.gridy = 1; + c.anchor = GridBagConstraints.WEST; + + selectButton = new pmButton( + pmUtility.getResource("Show")); + selectButton.setMnemonic( + pmUtility.getIntResource("Show.mnemonic")); + + selectButton.setEnabled(false); + + this.add(selectButton, c); + + selectButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + pmHelpItem selectedItem = (pmHelpItem) + resultList.getSelectedValue(); + Debug.message("Selected " + selectedItem); + parentPanel.controller.showHelpItem(selectedItem); + } + }); + + Vector resultItems = null; + try { + // resultItems = pmHelpIndexQueryPanel.helpDB.getPartialMatch(""); + resultItems = pmHelpRepository.helpItemsForString(""); + } catch (pmHelpException x) { + Debug.message("pmHelpIndexResultpanel init: " + x); + resultItems = new Vector(); + resultItems.addElement( + pmUtility.getResource("Nothing.matched.")); + } + + resultList = new JList(resultItems); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().setView(resultList); + resultList.setVisibleRowCount(8); + + promptLabel.setLabelFor(resultList); + + resultList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + if (!listEmpty) { + selectButton.setEnabled(true); + /* + parentPanel.controller.frame. + getRootPane().setDefaultButton(selectButton); + */ + selectButton.setAsDefaultButton(); + + } + }}); + + resultList.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + JList l = (JList) e.getSource(); + int i = l.locationToIndex(e.getPoint()); + Debug.message("doubleclick index: " + i); + if (!listEmpty && i >= 0) { + pmHelpItem item = + (pmHelpItem) l.getModel().getElementAt(i); + Debug.message("doubleclick: " + item.tag); + parentPanel.controller.showHelpItem(item); + } + } + } + }); + + c.gridwidth = 1; // 2; + c.gridx = 1; + c.gridy = 0; + c.weightx = c.weighty = 1.0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.EAST; + + this.add(scrollPane, c); + + } + + void setResultList(Vector v) { + + resultList.setListData(v); + + resultList.setSelectedValue(v.elementAt(0), true); + } + + void setListEmpty(boolean e) { + listEmpty = e; + selectButton.setEnabled(false); + /* + parentPanel.controller.frame.getRootPane(). + setDefaultButton(parentPanel.controller.frame.dismiss); + */ + if (parentPanel.controller.frame.dismiss != null) + parentPanel.controller.frame.dismiss. + setAsDefaultButton(); + } + +} + + +class pmHelpIndexQueryPanel extends JPanel { + + JTextField query; + pmHelpIndexPanel parentPanel; + + public pmHelpIndexQueryPanel(pmHelpIndexPanel p) { + + parentPanel = p; + + this.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(10, 10, 10, 10); + c.fill = GridBagConstraints.NONE; + c.weightx = c.weighty = 0.0; + c.anchor = GridBagConstraints.WEST; + + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 10, 10); + + JLabel promptLabel = + new JLabel(pmUtility.getResource("Search.help.index.for:")); +/* + * MNEMONIC + * promptLabel.setDisplayedMnemonic( + * pmUtility.getIntResource("Search.help.index.for:.mnemonic")); + */ + + this.add(promptLabel, c); + + query = new JTextField(); + query.setEditable(true); + query.setText(""); + + promptLabel.setLabelFor(query); + + query.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.info("HELP: Action!"); + parentPanel.resultPanel.selectButton.doClick(); + } + }); + + c.gridwidth = GridBagConstraints.REMAINDER; + c.gridx = 1; + c.weightx = 1.0; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.EAST; + + this.add(query, c); + + DocumentListener d = new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + // ignore + } + + public void insertUpdate(DocumentEvent e) { + handleText(query.getText()); + } + + public void removeUpdate(DocumentEvent e) { + handleText(query.getText()); + } + }; + + query.getDocument().addDocumentListener(d); + } + + public void handleText(String txt) { + + Debug.message("Got text " + txt); + + Vector v = null; + + try { + // v = helpDB.getPartialMatch(txt); + v = pmHelpRepository.helpItemsForString(txt); + } catch (pmHelpException x) { + Debug.warning("handleText: " + x); + } + parentPanel.setSearchResults(v); + + } + + // belongs in controller? + // static pmHelpRepository helpDB = new pmHelpRepository(); +} + + + + + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpItem.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpItem.java new file mode 100644 index 0000000000..5aad616907 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpItem.java @@ -0,0 +1,95 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpItem + * Abstraction of a help article + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +import com.sun.admin.pm.server.*; + +class pmHelpItem extends Object { + String title; + String tag; + Vector keywords; + Vector seealso; + pmHelpContent content; + + public pmHelpItem(String theTag) { + tag = theTag; + title = null; + keywords = null; + seealso = null; + content = null; + } + + public String toString() { + /* + String s = new String("Item: " + tag + "\n"); + s += ("\ttitle: " + title + "\n"); + s += ("\tkeywords: " + keywords + "\n"); + s += ("\tseealso: " + seealso + "\n"); + s += ("\tcontent: " + content + "\n"); + */ + return title; + } + + + public void setTag(String s) { + if (tag != null) + tag = new String(s); + } + + public void setTitle(String s) { + if (s != null) + title = new String(s); + } + + public void setKeywords(Vector v) { + if (v != null) + keywords = (Vector) v.clone(); + } + + public void setSeeAlso(Vector v) { + if (v != null) + seealso = (Vector) v.clone(); + } + + public void setContent(pmHelpContent c) { + if (c != null) + content = new pmHelpContent(c); + } + +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpRepository.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpRepository.java new file mode 100644 index 0000000000..99919179fa --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpRepository.java @@ -0,0 +1,295 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmHelpRepository.java + * Database of help articles + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +import com.sun.admin.pm.server.*; + + + +/* + * The help repository manages three distinct databases. + * + * helpItemDB: String tag -> pmHelpItem + * Returns a pmHelpItem given its unique tag. + * Used to resolve a reference from the app. + * + * helpKeywordDB: String -> Vector(of pmHelpItems) + * Returns a Vector containing all pmHelpItems whose `keywords' + * property contains the specifed keyword. + * + * helpTitleDB: String -> Vector (of pmHelpItems) + * Returns a Vector containing all pmHelpItems whose `title' + * property is a partial match for the specified string. + */ + +final class pmHelpRepository { + + private static Hashtable helpItemDB = null; + private static Hashtable helpKeywordDB = null; + private static BST helpTitleDB = null; + + + // database of HelpItems, by tag string + static void populateHelpItemDB() { + helpItemDB = new Hashtable(); + loadHelpItemDB(); + // Debug.message("HELP: helpItemDB: " + helpItemDB); + } + + // database of Vectors of HelpItems, by keyword string + static void populateHelpKeywordDB() { + if (helpItemDB == null) + return; + + /* + * Strategy: + * for each item + * for each keyword + * if kw not in db + * add ititem.tag + * add item to keyword entry + */ + + helpKeywordDB = new Hashtable(); + + Vector v = null; + Enumeration items = helpItemDB.elements(); + while (items.hasMoreElements()) { + pmHelpItem item = (pmHelpItem) items.nextElement(); + Enumeration keywords = item.keywords.elements(); + while (keywords.hasMoreElements()) { + String keyword = (String) keywords.nextElement(); + v = (Vector) helpKeywordDB.get(keyword); + if (v == null) + helpKeywordDB.put(keyword, v = new Vector()); + v.addElement(item); + } + } + + // Debug.message("HELP: KeywordDB: " + helpKeywordDB); + } + + + // database of HelpItems, by (partial) title string + static void populateHelpTitleDB() { + if (helpItemDB == null) + return; + + /* + * strategy: + * assume itemDB is loaded + * for each item in itemDB + * create an entry in titleDB + */ + + helpTitleDB = new BST(); + + Enumeration items = helpItemDB.elements(); + while (items.hasMoreElements()) { + pmHelpItem item = (pmHelpItem) items.nextElement(); + helpTitleDB.insert(item.title, item); + } + } + + + static public pmHelpItem helpItemForTag(String tag) { + if (helpItemDB == null || tag == null) + return null; + return (pmHelpItem) helpItemDB.get(tag); + } + + static public Vector helpItemsForKeyword(String keyword) { + if (helpKeywordDB == null) + return null; + + return (Vector) helpKeywordDB.get(keyword.toLowerCase()); + } + + + static public Vector helpItemsForString(String partialTitle) + throws pmHelpException { + + Debug.info("HELP: helpItemsForString: " + partialTitle); + + if (helpTitleDB == null) + return new Vector(); + + Vector v = new Vector(); + helpTitleDB.traverse_find_vector(v, partialTitle); + + Debug.info("HELP: helpItemsForString: vector contains " + + v.size() + " items"); + + return v; + } + + + + + // this should go in utils... + public static String getResource(String key) { + String keyvalue = null; + ResourceBundle bundle = null; + + Debug.message("HELP: getResource(" + key + ")"); + + try { + try { + bundle = ResourceBundle.getBundle( + "com.sun.admin.pm.client.pmHelpResources"); + } catch (MissingResourceException e) { + Debug.fatal("HELP: Could not load pmHelpResources file"); + } + + try { + keyvalue = bundle.getString(key); + } catch (MissingResourceException e) { + keyvalue = bundle.getString("Missing:") + key; + Debug.error("HELP: Missing: " + key); + } + } catch (Exception other) { + Debug.error("HELP: getResource(" + key + ") : " + other); + } + + return keyvalue; + } + + + // from resources, presumably + static public void loadHelpItemDB() { + + // Debug.setDebugLevel(new pmHelpRepository(), Debug.ALL); + + /* + * strategy: + * for each tag name (from pmHelpTagNameEnumerator): + * get the property values from the resource bundle + */ + + Debug.message("HELP: Starting help item load"); + + ResourceBundle bundle = null; + + try { + bundle = ResourceBundle.getBundle( + "com.sun.admin.pm.client.pmHelpResources"); + } catch (MissingResourceException e) { + Debug.fatal("HELP: Could not load pmHelpResources file"); + return; + } + Enumeration e = bundle.getKeys(); + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + if (key.endsWith(".tag")) { + String tagName = null; + try { + tagName = bundle.getString(key); + } catch (MissingResourceException x) { + Debug.warning("HELP: Unable to find tag for " + key); + continue; + } + + Debug.message("HELP: Making new item " + tagName); + + pmHelpItem item = new pmHelpItem(tagName); + + String theTitle = getResource(tagName + ".title"); + item.setTitle(theTitle); + + item.setContent(new pmHelpContent( + getResource(tagName + ".content"))); + + Vector v = null; + StringTokenizer st = null; + + String s = getResource(tagName + ".seealso"); + if (s != null) { + v = new Vector(); + st = new StringTokenizer(s); + while (st.hasMoreTokens()) + v.addElement(st.nextToken()); + item.setSeeAlso(v); + } + + v = new Vector(); + s = getResource(tagName + ".keywords"); + if (s != null) { + st = new StringTokenizer(s); + while (st.hasMoreTokens()) { + String word = st.nextToken(); + String quotelessWord = word.replace('\"', ' '); + v.addElement(quotelessWord.trim()); + } + } else + Debug.warning("HELP: Item " + tagName + + " keywords is empty"); + + + // insert item's title words into its keywords + st = new StringTokenizer(theTitle); + while (st.hasMoreTokens()) { + String word = (st.nextToken()).toLowerCase(); + + // ignore useless words + if (ignoreKeyTitleWords.indexOf(word) != -1) { + Debug.message("HELP: ignoring " + word + + " from " + theTitle); + continue; + } + + Debug.message("HELP: adding " + word + + " from " + theTitle); + + v.addElement(word); + } + + item.setKeywords(v); + + + Debug.message("HELP: New item: " + item); + + helpItemDB.put(item.tag, item); + } + } + } + + + // these words are not to be treated as keywords when they appear in title + static final private String + /* JSTYLED */ + ignoreKeyTitleWords = pmUtility.getResource("help.ignore.words"); +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpSearchPanel.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpSearchPanel.java new file mode 100644 index 0000000000..bfec055329 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmHelpSearchPanel.java @@ -0,0 +1,453 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHelpSearchPanel.java + * Search help keywords + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.JPanel; +import javax.swing.border.*; +import javax.swing.event.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +public class pmHelpSearchPanel extends JPanel { + + pmHelpController controller; + pmHelpSearchQueryPanel queryPanel; + pmHelpSearchResultPanel resultPanel; + JLabel textPanels[]; + + public pmHelpSearchPanel(pmHelpController ctrl) { + controller = ctrl; + + // build subpanels + queryPanel = new pmHelpSearchQueryPanel(this); + resultPanel = new pmHelpSearchResultPanel(this); + + textPanels = new JLabel[4]; + textPanels[0] = new JLabel( + pmUtility.getResource("To.find.help.articles...")); + textPanels[1] = new JLabel( + pmUtility.getResource("enter.keywords.below...")); + + // lay out top panel + this.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + c.gridwidth = GridBagConstraints.REMAINDER; + c.gridx = 0; + c.gridy = 0; + c.gridheight = 1; // GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1.0; + c.weighty = 0.0; + + JPanel p = new JPanel(); + p.setLayout(new GridBagLayout()); + GridBagConstraints pc = new GridBagConstraints(); + pc.insets = new Insets(5, 5, 0, 5); + // pc.fill = GridBagConstraints.HORIZONTAL; + pc.weightx = 1.0; + pc.anchor = GridBagConstraints.WEST; + pc.gridx = 0; + pc.gridy = GridBagConstraints.RELATIVE; + + p.add(textPanels[0], pc); + pc.insets = new Insets(0, 5, 5, 5); + p.add(textPanels[1], pc); + // p.add(textPanels[2]); + + this.add(p, c); + + + p = new JPanel(); + p.setLayout(new BorderLayout()); + queryPanel.setBorder(BorderFactory.createEtchedBorder()); + p.add(queryPanel, "North"); + resultPanel.setBorder(BorderFactory.createEtchedBorder()); + p.add(resultPanel, "Center"); + // p.setBorder(BorderFactory.createEtchedBorder()); + + c.gridy = 1; + // new stuff + c.gridy = GridBagConstraints.RELATIVE; + c.gridheight = 0; + c.weighty = 1.0; + c.weightx = 0.0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.EAST; + // end new stuff + + this.add(p, c); + this.setBorder(BorderFactory.createEtchedBorder()); + + + // figure out when we are tabbed or un-tabbed + controller.outerPanel.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + JTabbedPane tp = (JTabbedPane) e.getSource(); + Debug.info("HELP: Tab event!"); + if (!(tp.getSelectedComponent() instanceof + com.sun.admin.pm.client.pmHelpSearchPanel)) { + Debug.info("HELP: Tab event: resetting default"); + /* + controller.frame.getRootPane(). + setDefaultButton( + controller.frame.dismiss); + */ + /* + System.out.println(controller); + System.out.println(controller.frame); + System.out.println(controller.frame.dismiss); + */ + + if (controller.frame.dismiss != null) + controller.frame.dismiss. + setAsDefaultButton(); + } else { + // better to have the tab itself keep focus. + // queryPanel.query.requestFocus(); + } + } + }); + + } + + + // place item titles in search result panel + public void setSearchResults(Vector items) { + Vector v = new Vector(); + + if (items.size() == 0) { + resultPanel.setListEmpty(true); + v.addElement(pmUtility.getResource("Nothing.matched.")); + } else { + Enumeration e = items.elements(); + while (e.hasMoreElements()) { + pmHelpItem i = (pmHelpItem) e.nextElement(); + v.addElement(i); + } + resultPanel.setListEmpty(false); + } + resultPanel.setResultList(v); + } +} + + + +class pmHelpSearchResultPanel extends JPanel { + + JList resultList = null; + pmButton selectButton = null; + pmHelpSearchPanel parentPanel = null; + protected boolean listEmpty = true; + + + public pmHelpSearchResultPanel(pmHelpSearchPanel par) { + + parentPanel = par; + + this.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(10, 10, 10, 10); + c.fill = GridBagConstraints.NONE; + c.weightx = c.weighty = 0.0; + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.NORTHWEST; + + JLabel promptLabel = new JLabel( + pmUtility.getResource("Search.Results:")); +/* + * MNEMONIC + * promptLabel.setDisplayedMnemonic( + * pmUtility.getIntResource("Search.Results:.mnemonic")); + */ + + this.add(promptLabel, c); + + selectButton = new pmButton( + pmUtility.getResource("Show")); + selectButton.setMnemonic( + pmUtility.getIntResource("Show.mnemonic")); + + selectButton.setEnabled(false); + + selectButton.addActionListener(new ActionListener() { + // load the selected item into view panel + public void actionPerformed(ActionEvent e) { + pmHelpItem selectedItem = (pmHelpItem) + resultList.getSelectedValue(); + Debug.info("HELP: Selected " + selectedItem); + parentPanel.controller.showHelpItem(selectedItem); + + } + }); + + c.gridy = 1; + c.anchor = GridBagConstraints.SOUTHWEST; + this.add(selectButton, c); + + + Vector resultItems = new Vector(); + + resultList = new JList(resultItems); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().setView(resultList); + resultList.setVisibleRowCount(8); + + promptLabel.setLabelFor(resultList); + + resultList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + if (!listEmpty) { + selectButton.setEnabled(true); + /* + parentPanel.controller.frame. + getRootPane().setDefaultButton(selectButton); + */ + selectButton.setAsDefaultButton(); + + } + }}); + + + resultList.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + JList l = (JList) e.getSource(); + int i = l.locationToIndex(e.getPoint()); + Debug.info("HELP: doubleclick index: " + i); + if (!listEmpty && i >= 0) { + pmHelpItem item = (pmHelpItem) l.getModel(). + getElementAt(i); + Debug.info("HELP: doubleclick: " + item.tag); + parentPanel.controller.showHelpItem(item); + } + } + } + }); + + + c.gridwidth = 2; + c.gridx = 1; + c.gridy = 0; + c.weightx = c.weighty = 1.0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.WEST; + + this.add(scrollPane, c); + + } + + public void setResultList(Vector v) { + resultList.setListData(v); + resultList.setSelectedValue(v.elementAt(0), true); + + } + + void setListEmpty(boolean e) { + listEmpty = e; + selectButton.setEnabled(false); + /* + parentPanel.controller.frame.getRootPane(). + setDefaultButton(parentPanel.controller.frame.dismiss); + */ + parentPanel.controller.frame.dismiss.setAsDefaultButton(); + + } + + +} + + +class pmHelpSearchQueryPanel extends JPanel { + + JTextField query; + pmButton search; + pmHelpSearchPanel parentPanel = null; + + public pmHelpSearchQueryPanel(pmHelpSearchPanel par) { + + parentPanel = par; + + this.setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(10, 10, 10, 10); + c.fill = GridBagConstraints.NONE; + c.weightx = c.weighty = 0.0; + c.anchor = GridBagConstraints.WEST; + + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 1; + c.gridheight = 1; + + JLabel promptLabel = + new JLabel(pmUtility.getResource("Keywords:")); +/* + * MNEMONIC + * promptLabel.setDisplayedMnemonic( + * pmUtility.getIntResource("Keywords:.mnemonic")); + */ + + this.add(promptLabel, c); + + search = new pmButton( + pmUtility.getResource("Find")); + search.setMnemonic( + pmUtility.getIntResource("Find.mnemonic")); + + search.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // parse the keyword strings + Vector v = null; + StringTokenizer st = null; + String s = query.getText(); + if (s != null) { + v = new Vector(); + st = new StringTokenizer(s); + while (st.hasMoreTokens()) + v.addElement(st.nextToken()); + v = getItemsForKeywords(v); + parentPanel.setSearchResults(v); + + if (v != null && v.size() != 0) { + Debug.info("HELP: search vector full"); + parentPanel.resultPanel.resultList.requestFocus(); + } else { + Debug.info("HELP: search vector empty"); + } + } + + } + }); + + c.fill = GridBagConstraints.NONE; + c.gridx = 2; + c.gridy = 0; // GridBagConstraints.RELATIVE; + this.add(search, c); + + query = new JTextField(); + query.setEditable(true); + query.setText(" "); + + promptLabel.setLabelFor(query); + + query.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.info("HELP: Action!"); + pmHelpSearchQueryPanel.this.search.doClick(); + } + }); + + query.getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + // ignore + } + + public void insertUpdate(DocumentEvent e) { + // make search the default button + Debug.info("HELP: search doc inserted update"); + pmHelpSearchQueryPanel.this.search.setEnabled(true); + /* + parentPanel.controller.frame. + getRootPane().setDefaultButton( + pmHelpSearchQueryPanel.this.search); + */ + if (pmHelpSearchQueryPanel.this.search != null) + pmHelpSearchQueryPanel.this.search. + setAsDefaultButton(); + } + + public void removeUpdate(DocumentEvent e) { + Debug.info("HELP: search doc removed update"); + // restore the default button + if (query.getText().length() == 0) { + /* + parentPanel.controller.frame. + getRootPane().setDefaultButton( + parentPanel.controller.frame.dismiss); + */ + if (parentPanel.controller.frame.dismiss != null) + parentPanel.controller.frame.dismiss. + setAsDefaultButton(); + } + } + }); + + + + c.gridwidth = 1; // GridBagConstraints.REMAINDER; + c.gridx = 1; + c.weightx = 1.0; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.EAST; + + this.add(query, c); + + } + + + Vector getItemsForKeywords(Vector keywords) { + Vector result = new Vector(); + + Debug.info("HELP: getItemsForKeywords: " + keywords); + + Enumeration words = keywords.elements(); + while (words.hasMoreElements()) { + String s = (String) words.nextElement(); + Vector newItems = pmHelpRepository.helpItemsForKeyword(s); + Debug.info("HELP: getItemsForKeywords new items: " + newItems); + + if (newItems != null) { + Enumeration items = newItems.elements(); + while (items.hasMoreElements()) { + pmHelpItem i = (pmHelpItem) items.nextElement(); + Debug.info("HELP: getItemsForKeywords result: " + result); + Debug.info("HELP: getItemsForKeywords item: " + i); + + if (!result.contains(i)) + result.addElement(i); + } + } + } + return result; + } +} + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmIncompleteFormException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmIncompleteFormException.java new file mode 100644 index 0000000000..f242c95ec7 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmIncompleteFormException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmIncompleteFormException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmIncompleteFormException extends pmGuiException { + public pmIncompleteFormException(String s) { + super(s); + } + public pmIncompleteFormException() { + super(); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmInstallPrinter.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmInstallPrinter.java new file mode 100644 index 0000000000..8cf6e399ea --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmInstallPrinter.java @@ -0,0 +1,2175 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Install and Modify Printer implementation + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.Vector; +import javax.swing.JPanel; +import javax.swing.*; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.table.AbstractTableModel; + +import com.sun.admin.pm.server.*; + + +/* + * Window for Edit -> Install Printer + */ + +public class pmInstallPrinter extends pmInstallScreen { + + int action; + pmTop myTop; + pmFrame frame; + JScrollPane scrollPane; + String printer = null; + String server = null; + String description = null; + String port = null; + String ptype = null; + String fcontents = null; + String make = null; + String model = null; + String ppd = null; + String ppdfile = null; + String oldmake = new String("oldmake"); + String oldmodel = new String("oldmodel"); + String faultn = null; + String banner = null; + String destination = null; + String protocol = null; + String useraccesslist[] = null; + String oldptype = null; + String olddevice = null; + Printer workingPrinter; + + JList accessList; + JScrollPane ascrollPane; + accessListModel accessModel; + + String helpTag = null; + + String cmdLog = null; + String errorLog = null; + String warnLog = null; + + String actionName = null; + + // where to place initial focus + Component defaultComponent = null; + + boolean usePPD; + + public pmInstallPrinter(pmTop myTop, int action) throws pmGuiException { + boolean failed = false; + boolean cacheerr = false; + boolean ppdincacheerr = false; + + this.myTop = myTop; + this.action = action; + workingPrinter = new Printer(myTop.ns); + + usePPD = myTop.getUsePPD(); + + + + switch (action) { + + case Constants.ADDLOCAL: + + Debug.message("CLNT:pmInstPr: ADD LOCAL"); + frame = new pmFrame( + pmUtility.getResource("SPM:New.Attached.Printer")); + if (pmMisc.isppdCachefile() && usePPD) { + helpTag = "InstallLocalPPD"; + } else { + helpTag = "InstallLocal"; + } + actionName = + pmUtility.getResource("New.Attached.Printer"); + break; + + case Constants.ADDNETWORK: + + Debug.message("CLNT:pmInstPr: ADD NETWORK"); + frame = new pmFrame( + pmUtility.getResource("SPM:New.Network.Printer")); + if ((pmMisc.isppdCachefile()) && (usePPD)) { + helpTag = "InstallNetworkPPD"; + } else + helpTag = "InstallNetwork"; + actionName = pmUtility.getResource("New.Network.Printer"); + break; + + case Constants.MODIFYATTACHED: + + Debug.message("CLNT:pmInstPr: MODIFY ATTACHED"); + frame = new pmFrame( + pmUtility.getResource("SPM:Modify.Printer.Properties")); + workingPrinter.setPrinterName(myTop.selectedPrinter); + + failed = false; + try { + workingPrinter.getPrinterDetails(); + + } catch (pmNeedPPDCacheException e) { + cacheerr = true; + Debug.message("CLNT:pmInstPr:ModifyAttached caught: " + e); + + } catch (pmCacheMissingPPDException e) { + ppdincacheerr = true; + Debug.message("CLNT:pmInstPr:ModifyAttached caught: " + e); + + } catch (Exception e) { + failed = true; + Debug.message("CLNT:pmInsPr:ModifyAttached caught:" + e); + } + + gatherLogs(workingPrinter); + + if (cacheerr) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Cannot.modify.this.queue;ppdcache.file.missing.")); + + m.setVisible(true); + + throw new pmGuiException("No ppdcache file"); + } + + if (ppdincacheerr) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Cannot.modify.this.queue;PPD.file.not.in.ppdcache.")); + + m.setVisible(true); + + throw new pmGuiException("PPD file not in ppdcache"); + } + + if (failed) { + // error popup? + // throw something? + } + + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("ModifyAttached()"); + + if (workingPrinter.getPPD() != null) + helpTag = "ModifyPPD"; + else + helpTag = "Modify"; + + // helpTag = "ModifyAttached"; + + actionName = pmUtility.getResource("Modify.Printer.Properties"); + break; + + case Constants.MODIFYNETWORK: + + Debug.message("CLNT:pmInstPr: MODIFY NETWORK"); + frame = new pmFrame( + pmUtility.getResource("SPM:Modify.Printer.Properties")); + workingPrinter.setPrinterName(myTop.selectedPrinter); + + workingPrinter.setPrinterName(myTop.selectedPrinter); + failed = false; + + try { + workingPrinter.getPrinterDetails(); + } catch (Exception e) { + failed = true; + Debug.message("CLNT:pmInstPr:ModifyNetwork caught " + e); + } + + gatherLogs(workingPrinter); + + if (failed) { + // error popup? + // throw new pmGuiException(); + } + + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("ModifyNetwork()"); + + if (workingPrinter.getPPD() != null) + helpTag = "ModifyPPD"; + else + helpTag = "Modify"; + // helpTag = "ModifyNetwork"; + + actionName = pmUtility.getResource("Modify.Printer.Properties"); + + break; + + case Constants.MODIFYREMOTE: + Debug.message("CLNT:pmInstPr: MODIFY REMOTE"); + frame = new pmFrame( + pmUtility.getResource("SPM:Modify.Printer.Properties")); + + workingPrinter.setPrinterName(myTop.selectedPrinter); + + failed = false; + try { + workingPrinter.getPrinterDetails(); + } catch (Exception e) { + failed = true; + Debug.warning("CLNT:pmInstPr:ModifyRemote caught " + e); + } + gatherLogs(workingPrinter); + + if (failed) { + // error popup? + // throw something? + } + + + if (workingPrinter.getPPD() != null) + helpTag = "ModifyPPD"; + else + helpTag = "Modify"; + // helpTag = "ModifyRemote"; + + actionName = pmUtility.getResource("Modify.Printer.Properties"); + break; + + } + + // ensure that pmButton hashtable gets cleaned up + frame.setClearButtonsOnClose(true); + + setLayout(new BorderLayout()); + + // Build the Screen + northPanel(); + if (action != Constants.MODIFYREMOTE) { + centerPanel(); + } + + southPanel(); + + // default button is always OK, for now... + // frame.getRootPane().setDefaultButton (okButton); + // okButton.setAsDefaultButton (); + + // handle Esc as cancel + this.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + actioncancelButton(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + if (action == Constants.ADDLOCAL || action == Constants.ADDNETWORK) { + defaultComponent = pnameText; + } else { + defaultComponent = descText; + } + + frame.setDefaultComponent(defaultComponent); + + defaultComponent.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + Debug.info("\ncomponent focus gained: " + e); + } + public void focusLost(FocusEvent e) { + Debug.info("\ncomponent focus lost: " + e); + } + }); + + } + + + public class accessListModel extends AbstractListModel { + int numColumns; + Vector data; + Vector access = new Vector(1, 1); + + public accessListModel() { + numColumns = getColumnCount(); + } + + public void addaccessList(String data[]) { + + for (int i = 0; i < data.length; i++) { + access.addElement(data[i]); + + } + } + + public void addaccessList(String data) { + access.addElement(data); + } + + public boolean isduplicate(String d) { + if (access == null) + return false; + else + return access.contains(d); + } + + public void removeRow(int row) { + access.removeElementAt(row); + } + + public void removeListEntries() { + access.removeAllElements(); + } + + public int getRowCount() { + return access.size(); + } + + public int getSize() { + return access.size(); + } + + public int getColumnCount() { + return 1; + } + + public void addRow(Vector row) { + access.addElement(row); + } + + public Object getValueAt(int row) { + return access.elementAt(row); + } + + public Object getElementAt(int row) { + return access.elementAt(row); + } + + public Object getValueAt(int row, int col) { + return access.elementAt(row); + } + + public void setValueAt(String value, int row) { + access.setElementAt(value, row); + } + + public Vector getAccessList() { + return access; + } + + public void accesstoArray(String[] target) { + access.copyInto(target); + } + + } + + public void centerPanel() { + JPanel center = new JPanel(); + + accessModel = new accessListModel(); + accessList = new JList(accessModel); + accessList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + + center.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + ListSelectionModel rowSelectModel = accessList.getSelectionModel(); + rowSelectModel.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + ListSelectionModel accessSM = + (ListSelectionModel)e.getSource(); + } + }); + + c.insets = new Insets(5, 5, 5, 5); + + // Create the label + c.gridx = 0; + c.gridy = 0; + labelConstraints(c); + center.add(new JLabel + (pmUtility.getResource("User.Access.List:")), c); + + // Create User Access List + String[] tmp = workingPrinter.getUserAllowList(); + + + if (tmp == null) { + accessModel.addaccessList("all"); + } else { + accessModel.addaccessList(tmp); + } + + ascrollPane = new JScrollPane(accessList); + + c.gridwidth = 2; + c.gridx = 1; + c.weightx = c.weighty = 1.0; + c.fill = GridBagConstraints.BOTH; + center.add(ascrollPane, c); + + // Create Textfield + c.gridx = 1; + c.gridy = 1; + c.ipadx = 15; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.WEST; + c.weightx = c.weighty = 1.0; + userText = new pmTextField(25); + center.add(userText, c); + + // Add the Add/Delete Buttons + c.gridx = 1; + c.gridy = 2; + + adButtons(c); + + c.gridwidth = 1; + center.add(addButton, c); + + c.gridx = 2; + center.add(deleteButton, c); + + add("Center", center); + + } + + public void northPanel() { + JPanel north = new JPanel(); + north.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + northPanelConstraints(c); + + // Define the constraints and create the labels + + // All Add/Modify + labelConstraints(c); + c.gridx = 0; + c.gridy = 0; + printernameLabel(north, c); + c.gridy++; + servernameLabel(north, c); + c.gridy++; + descriptionLabel(north, c); + c.gridy++; + + // Add printers, modify local + if (action != Constants.MODIFYREMOTE) { + + if ((action == Constants.ADDLOCAL) || + (action == Constants.MODIFYATTACHED)) { + printerportLabel(north, c); + c.gridy++; + } + + if ((action == Constants.ADDLOCAL) || + (action == Constants.ADDNETWORK)) { + if ((pmMisc.isppdCachefile()) && (usePPD)) { + printermakeLabel(north, c); + c.gridy++; + printermodelsLabel(north, c); + c.gridy++; + ppdcontentsLabel(north, c); + } else { + printertypeLabel(north, c); + c.gridy++; + filecontentsLabel(north, c); + } + } + + if ((action == Constants.MODIFYATTACHED) || + (action == Constants.MODIFYNETWORK)) { + + // Show make/model/ppd or type/contents + + if (workingPrinter.getPPD() != null) { + + printermakeLabel(north, c); + c.gridy++; + printermodelsLabel(north, c); + c.gridy++; + ppdcontentsLabel(north, c); + } else { + printertypeLabel(north, c); + c.gridy++; + filecontentsLabel(north, c); + } + } + + c.gridy++; + faultnotLabel(north, c); + c.gridy++; + + if (action == Constants.ADDNETWORK || + action == Constants.MODIFYNETWORK) { + destinationLabel(north, c); + c.gridy++; + protocolLabel(north, c); + c.gridy++; + } + + optionsLabel(north, c); + c.gridy++; + bannerLabel(north, c); + } else { + optionLabel(north, c); + } + + // Define the constraints and create the fields + + // Add printers + c.gridx = 1; + c.gridy = 0; + + // Printer Name and Server Name + if ((action == Constants.ADDLOCAL) || + (action == Constants.ADDNETWORK)) { + + TextFieldConstraints(c); + printernameTextField(north, c); + c.gridy++; + labelConstraints(c); + try { + north.add(new JLabel( + myTop.host.getLocalHostName()), c); + } catch (Exception e) { + Debug.warning( + "CLNT:pmInstPr:getLocalHostName exception " + e); + north.add(new JLabel(" "), c); + } + c.gridy++; + } else { + labelConstraints(c); + north.add(new JLabel(myTop.selectedPrinter), c); + c.gridy++; + labelConstraints(c); + north.add(new JLabel(myTop.selprinterServer), c); + c.gridy++; + } + + // Description + TextFieldConstraints(c); + descriptionField(north, c); + if (action == Constants.MODIFYATTACHED || + action == Constants.MODIFYNETWORK || + action == Constants.MODIFYREMOTE) { + if (workingPrinter.getComment() != null) + descText.setText(workingPrinter.getComment()); + } + c.gridy++; + + if (action != Constants.MODIFYREMOTE) { + if (action == Constants.ADDLOCAL) { + comboboxConstraints(c); + printerportField(north, c); + c.gridy++; + + } else if (action == Constants.MODIFYATTACHED) { + labelConstraints(c); + north.add(new JLabel(workingPrinter.getDevice()), c); + c.gridy++; + } + + comboboxConstraints(c); + + if ((action == Constants.ADDLOCAL) || + (action == Constants.ADDNETWORK)) { + if ((pmMisc.isppdCachefile()) && (usePPD)) { + printermakeField(north, c); + c.gridy++; + printermodelsField(north, c); + c.gridy++; + ppdcontentsField(north, c); + } else { + printertypeField(north, c); + c.gridy++; + filecontentsField(north, c); + } + } + + if ((action == Constants.MODIFYATTACHED) || + (action == Constants.MODIFYNETWORK)) { + + if (workingPrinter.getPPD() != null) { + + printermakeField(north, c); + c.gridy++; + printermodelsField(north, c); + c.gridy++; + ppdcontentsField(north, c); + + setMake(); + setModel(); + setPPD(); + + } else { + // display with printer type and file contents + + printertypeField(north, c); + setPrinterType(); + + c.gridy++; + + filecontentsField(north, c); + setType(); + } + } + + c.gridy++; + + faultnotField(north, c); + if (action == Constants.MODIFYATTACHED || + action == Constants.MODIFYNETWORK) { + + setFault(); + } + c.gridy++; + + if (action == Constants.ADDNETWORK || + action == Constants.MODIFYNETWORK) { + + TextFieldConstraints(c); + destinationField(north, c); + if (action == Constants.MODIFYNETWORK) + setNetworkInfo(); + c.gridy++; + comboboxConstraints(c); + protocolField(north, c); + c.gridy++; + } + + optionsConstraints(c); + optionsFields(north, c); + if (action == Constants.MODIFYATTACHED || + action == Constants.MODIFYNETWORK) { + if (workingPrinter.getIsDefaultPrinter()) { + defaultp.doClick(); + } + setBanner(); + } + } else { + optionsConstraints(c); + defaultoptionField(north, c); + if (workingPrinter.getIsDefaultPrinter()) { + defaultp.doClick(); + } + } + + add("North", north); + } + + public void setNetworkInfo() { + String p = workingPrinter.getProtocol(); + + if (p != null) { + if (p.equals("bsd")) + protocolCombo.setSelectedItem("BSD"); + else if (p.equals("tcp")) + protocolCombo.setSelectedItem("TCP"); + else if (p.equals("uri")) + protocolCombo.setSelectedItem("URI"); + } + + if (destText != null) + destText.setText(workingPrinter.getDestination()); + } + + public void setMake() { + String make = workingPrinter.getMake(); + if (make != null) { + makeCombo.setSelectedItem(make); + } + } + public void setModel() { + String model = workingPrinter.getModel(); + if (model != null) + modelCombo.setSelectedItem(model); + } + public void setPPD() { + String ppd = workingPrinter.getPPD(); + if (ppd != null) + ppdCombo.setSelectedItem(ppd); + } + + public void setFault() { + String fault = workingPrinter.getNotify(); + + if (fault == null || fault == "none") + faultCombo.setSelectedItem( + pmUtility.getResource("None")); + + else if (fault.equals("write")) + faultCombo.setSelectedItem( + pmUtility.getResource("Write.to.Superuser")); + + else if (fault.equals("mail")) + faultCombo.setSelectedItem( + pmUtility.getResource("Mail.to.Superuser")); + else { + faultCombo.addItem(fault); + faultCombo.setSelectedItem(fault); + } + } + + public void setBanner() { + String banner = workingPrinter.getBanner(); + + if (banner == null) + bannerCombo.setSelectedItem( + pmUtility.getResource("Always.Print.Banner")); + + else if (banner.equals("never")) + bannerCombo.setSelectedItem( + pmUtility.getResource("Never.Print.Banner")); + + else if (banner.equals("always")) + bannerCombo.setSelectedItem( + pmUtility.getResource("Always.Print.Banner")); + + else if (banner.equals("optional")) + bannerCombo.setSelectedItem( + pmUtility.getResource("User.Selectable.Default.On")); + } + + public void setType() { + // lpadmin can combine things like: simple,any ... + + String filedata[] = workingPrinter.getFileContents(); + String filecontents = new String(); + + if (filedata == null) { + fileCombo.setSelectedItem( + pmUtility.getResource("None")); + } else { + for (int i = 0; i < filedata.length; i++) { + if (i > 0 && filedata[i] != null) + filecontents = filecontents.concat(","); + + filecontents = filecontents.concat(filedata[i]); + } + Debug.message("CLNT:pmInstPr:setType: filecontents = " + + filecontents); + + if (filecontents.equals("postscript")) { + fileCombo.setSelectedItem(pmUtility.getResource( + "PostScript")); + } else if (filecontents.equals("simple")) { + fileCombo.setSelectedItem(pmUtility.getResource("ASCII")); + } else if (filecontents.equals("postscript,simple")) { + fileCombo.setSelectedItem(pmUtility.getResource( + "Both.PostScript.and.ASCII")); + } else if (filecontents.equals("simple,postscript")) { + fileCombo.setSelectedItem(pmUtility.getResource( + "Both.PostScript.and.ASCII")); + } else if (filecontents.equals("none")) { + fileCombo.setSelectedItem( + pmUtility.getResource("None")); + } else if (filecontents.equals("any")) { + fileCombo.setSelectedItem( + pmUtility.getResource("Any")); + } else { + Debug.message( + "CLNT:pmInstPr:setType()unknown file contents type"); + fileCombo.addItem(filecontents); + fileCombo.setSelectedItem(filecontents); + } + } + } + + public void setPrinterType() { + int x = 0; + String type = workingPrinter.getPrinterType(); + Debug.message( + "CLNT:pmInstPrsetPrinterType(): printer type is " + type); + + if (type == null) + return; + + if (type.equals("PS")) { + typeCombo.setSelectedItem("PostScript"); + } else if (type.equals("hplaser")) { + typeCombo.setSelectedItem("HP Printer"); + } else if (type.equals("PSR")) { + typeCombo.setSelectedItem("Reverse PostScript"); + } else if (type.equals("epson2500")) { + typeCombo.setSelectedItem("Epson 2500"); + } else if (type.equals("ibmproprinter")) { + typeCombo.setSelectedItem("IBM ProPrinter"); + } else if (type.equals("qume5")) { + typeCombo.setSelectedItem("Qume Sprint 5"); + } else if (type.equals("daisy")) { + typeCombo.setSelectedItem("Daisy"); + } else if (type.equals("diablo")) { + typeCombo.setSelectedItem("Diablo"); + } else if (type.equals("datagraphix")) { + typeCombo.setSelectedItem("Datagraphix"); + } else if (type.equals("la100")) { + typeCombo.setSelectedItem("DEC LA100"); + } else if (type.equals("ln03")) { + typeCombo.setSelectedItem("DEC LN03"); + } else if (type.equals("decwriter")) { + typeCombo.setSelectedItem("Dec Writer"); + } else if (type.equals("ti800")) { + typeCombo.setSelectedItem("Texas Instruments 800"); + } else { + typeCombo.addItem(type); + typeCombo.setSelectedItem(type); + Debug.message( + "CLNT:pmInstPr:setPrinterType(): user defined type " + + type); + } + + } + + public void getMakeModelPPD() throws pmGuiException { + if (pmMisc.isppdCachefile()) { + getMake(); + + model = (String)modelCombo.getSelectedItem(); + ppd = (String)ppdCombo.getSelectedItem(); + } + } + + public void getTypeContents() throws pmGuiException { + ptype = (String)typeCombo.getSelectedItem(); + fcontents = (String)fileCombo.getSelectedItem(); + } + + public void getFault() throws pmGuiException { + faultn = (String)faultCombo.getSelectedItem(); + } + + public void getBanner() throws pmGuiException { + banner = (String)bannerCombo.getSelectedItem(); + } + + public void getPrinterServer() throws pmGuiException { + + // Printer Name is a required field. + printer = pnameText.getText(); + if (printer.equals("")) { + pnameText.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("Printer.name.required.")); + } + + if (!Valid.localPrinterName(printer)) { + pnameText.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("Printer.name.invalid.")); + } + + server = null; + try { + server = myTop.host.getLocalHostName(); + } catch (Exception e) { + Debug.warning( + "CLNT:pmInstPr:getLocalHostName exception " + e); + } + + Debug.message( + "CLNT:pmInstPr:getPrinterServer(): printer is: " + printer); + Debug.message( + "CLNT:pmInstPr:getPrinterServer(): server is: " + server); + + } + + public void getPort() throws pmGuiException { + port = (String)portCombo.getSelectedItem(); + if (port.equals(pmUtility.getResource("Not.Selected"))) { + portCombo.requestFocus(); + throw new pmIncompleteFormException + (pmUtility.getResource( + "Printer.Port.Selection.required")); + } + Debug.message("CLNT:pmInstPr:getPort(): port is: " + port); + } + + public void getMake() throws pmGuiException { + make = (String)makeCombo.getSelectedItem(); + if (make.equals(pmUtility.getResource("Not.Selected"))) { + makeCombo.requestFocus(); + throw new pmIncompleteFormException + (pmUtility.getResource( + "Printer.Make.Selection.required")); + } + Debug.message("CLNT:pmInstPr:getMake(): make is: " + make); + } + + public void getNetworkInfo() throws pmIncompleteFormException { + destination = destText.getText(); + if (destination.equals("")) { + destText.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("Destination.required.")); + } + + if (!Valid.destination(destination)) { + destText.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("Destination.invalid.")); + } + + protocol = (String)protocolCombo.getSelectedItem(); + port = new String("/dev/null"); + Debug.message( + "CLNT:pmInstPr:getNetworkInfo(): destination is: " + + destination); + Debug.message( + "CLNT:pmInstPr:getNetworkInfo(): protocol is: " + protocol); + } + + public void getDescription() { + + String messy; + + messy = descText.getText(); + description = messy.trim(); + Debug.message( + "CLNT:pmInstPr:getDescription():description: " + "<" + + description + ">"); + + if (workingPrinter.getComment() == null && description.equals("")) + description = null; + + } + + public void getUserAccess() { + + if (accessModel.getRowCount() != 0) { + useraccesslist = new String[accessModel.getRowCount()]; + accessModel.accesstoArray(useraccesslist); + } else { + useraccesslist = null; + } + } + + public String gui2lpptype(String t) { + String lp; + + if (t != null) { + if (t.equals("PostScript")) + lp = new String("PS"); + else if (t.equals("HP Printer")) + lp = new String("hplaser"); + else if (t.equals("Reverse PostScript")) + lp = new String("PSR"); + else if (t.equals("Epson 2500")) + lp = new String("epson2500"); + else if (t.equals("IBM ProPrinter")) + lp = new String("ibmproprinter"); + else if (t.equals("Qume Sprint 5")) + lp = new String("qume5"); + else if (t.equals("Daisy")) + lp = new String("daisy"); + else if (t.equals("Diablo")) + lp = new String("diablo"); + else if (t.equals("Datagraphix")) + lp = new String("datagraphix"); + else if (t.equals("DEC LA100")) + lp = new String("la100"); + else if (t.equals("DEC LN03")) + lp = new String("ln03"); + else if (t.equals("Dec Writer")) + lp = new String("decwriter"); + else if (t.equals("Texas Instruments 800")) + lp = new String("ti800"); + else { + Debug.message( + "CLNT:pmIns:gui2lptype: printer type unknown: " + t); + lp = new String(t); + } + } else { + Debug.message("CLNT:pmInstPr:gui2lptype: input printer type null"); + lp = new String(""); + } + + return lp; + } + + public String[] gui2lpfcontents(String f) { + + String[] lp = null; + + if (f != null) { + if (f.equals(pmUtility.getResource("PostScript"))) { + lp = new String[1]; + lp[0] = new String("postscript"); + } else if (f.equals(pmUtility.getResource("ASCII"))) { + lp = new String[1]; + lp[0] = new String("simple"); + } else if (f.equals(pmUtility.getResource( + "Both.PostScript.and.ASCII"))) { + lp = new String[2]; + lp[0] = new String("simple"); + lp[1] = new String("postscript"); + } else if (f.equals(pmUtility.getResource("Any"))) { + lp = new String[1]; + lp[0] = new String("any"); + } else if (f.equals(pmUtility.getResource("None"))) { + lp = new String[1]; + lp[0] = new String("none"); + } + } else { + Debug.message( + "CLNT:pmInstPr:gui2lpfcontents(): input string null"); + } + + return lp; + } + + public String gui2lpfaultn(String n) { + String lp = null; + if (n != null) { + if (n.equals(pmUtility.getResource("Write.to.Superuser"))) + lp = new String("write"); + else if (n.equals(pmUtility.getResource("Mail.to.Superuser"))) + lp = new String("mail"); + else if (n.equals(pmUtility.getResource("None"))) + lp = new String("none"); + + } else { + Debug.message( + "CLNT:pmInstPr:gui2lpfaultn():input faultnotify null"); + } + return lp; + } + + public String gui2lpprotocol(String p) { + String lp = null; + if (p.equals("TCP")) + lp = new String("tcp"); + else if (p.equals("BSD")) + lp = new String("bsd"); + else if (p.equals("URI")) + lp = new String("uri"); + else { + Debug.message( + "CLNT:pmInstPr:gui2lpprotocol: protocol is empty"); + } + return lp; + } + + public String gui2lpbanner(String p) { + String lp = null; + if (p.equals(pmUtility.getResource("Always.Print.Banner"))) + lp = new String("always"); + else if (p.equals(pmUtility.getResource("Never.Print.Banner"))) + lp = new String("never"); + else if (p.equals(pmUtility.getResource("User.Selectable.Default.On"))) + lp = new String("optional"); + else { + Debug.message( + "CLNT:pmInstPr:gui2lpbanner(): banner is empty"); + } + + if (lp != null) + Debug.message( + "CLNT:pmInstPr:gui2lpbanner(): banner is " + lp); + return lp; + + } + + public void updatePrinter() { + if (workingPrinter != null) { + if (printer != null) + workingPrinter.setPrinterName(printer); + if (server != null) + workingPrinter.setPrintServer(server); + if (description != null) + workingPrinter.setComment(description); + if ((port != null) && + (!port.equals(pmUtility.getResource("Not.Selected")))) + workingPrinter.setDevice(port); + if (make != null) { + workingPrinter.setMake(make); + } + if (model != null) { + workingPrinter.setModel(model); + } + if (ppd != null) { + workingPrinter.setPPD(ppd); + } + + workingPrinter.setUsePPD(usePPD); + + if (ptype != null) + workingPrinter.setPrinterType(gui2lpptype(ptype)); + if (fcontents != null) + workingPrinter.setFileContents(gui2lpfcontents(fcontents)); + if (faultn != null) + workingPrinter.setNotify(gui2lpfaultn(faultn)); + if (destination != null) + workingPrinter.setDestination(destination); + if (protocol != null) + workingPrinter.setProtocol(gui2lpprotocol(protocol)); + if (useraccesslist != null) + workingPrinter.setUserAllowList(useraccesslist); + else { + String[] a = new String[1]; + a[0] = new String("none"); + workingPrinter.setUserAllowList(a); + } + + if (defaultp != null) + workingPrinter.setIsDefaultPrinter(defaultp.isSelected()); + + if (banner != null) + workingPrinter.setBanner(gui2lpbanner(banner)); + + } else { + Debug.warning( + "CLNT:pmInstPr:updatePrinter(): workingPrinter null"); + } + } + + + void gatherLogs(Printer p) { + cmdLog = p.getCmdLog(); + errorLog = p.getErrorLog(); + warnLog = p.getWarnLog(); + } + + + void dumpLogs(String who) { + Debug.message(who); + Debug.message(who + " command: " + cmdLog); + Debug.message(who + " warnings: " + warnLog); + Debug.message(who + " errors: " + errorLog); + } + + + public void doAddLocal() throws pmGuiException { + + try { + getPrinterServer(); + getDescription(); + getPort(); + if ((pmMisc.isppdCachefile()) && (usePPD)) { + getMakeModelPPD(); + } else { + getTypeContents(); + } + getFault(); + getBanner(); + getUserAccess(); + updatePrinter(); + + } catch (pmIncompleteFormException ie) { + throw new pmIncompleteFormException(ie.getMessage()); + } + + + boolean exist; + boolean failed = false; + + // exists could throw an exception from the underyling cmds... + try { + exist = PrinterUtil.exists(printer, myTop.ns); + } catch (Exception e) { + throw new pmGuiException(); + } + + if (exist) { + throw new pmPrinterExistsException(); + } + + try { + workingPrinter.addLocalPrinter(); + } catch (Exception e) { + failed = true; + } finally { + gatherLogs(workingPrinter); + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("doAddLocal()"); + if (failed) + throw new pmAddPrinterFailedException(errorLog); + } + + } + + + public void doAddNetwork() throws pmGuiException { + try { + getPrinterServer(); + getDescription(); + getNetworkInfo(); + if ((pmMisc.isppdCachefile()) && (usePPD)) { + getMakeModelPPD(); + } else { + getTypeContents(); + } + getFault(); + getBanner(); + getUserAccess(); + updatePrinter(); + } catch (pmIncompleteFormException ie) { + throw new pmIncompleteFormException(ie.getMessage()); + } + + boolean exist = false; + + try { + exist = PrinterUtil.exists(printer, myTop.ns); + } catch (Exception e) { + Debug.message( + "CLNT:pmInstPr:doAddNetwork:printer exists " + e); + throw new pmGuiException(); + } + + if (exist) { + Debug.message( + "CLNT:pmInstPr:Trying to add existing printer: " + printer); + throw new pmPrinterExistsException(); + } + + boolean failed = false; + try { + workingPrinter.addLocalPrinter(); + } catch (Exception e) { + failed = true; + } finally { + gatherLogs(workingPrinter); + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("doAddNetwork()"); + if (failed) + throw new pmAddPrinterFailedException(errorLog); + } + } + + + public void doModifyLocalAttached() throws pmGuiException { + getDescription(); + getFault(); + getBanner(); + + if (workingPrinter.getPPD() != null) { + getMakeModelPPD(); + } else { + getTypeContents(); + } + getUserAccess(); + updatePrinter(); + + boolean failed = false; + try { + workingPrinter.modifyPrinter(); + } catch (Exception e) { + Debug.warning("CLNT:doModifyLocalAttached: " + e); + failed = true; + } finally { + gatherLogs(workingPrinter); + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("doModifyLocalAttached()"); + if (failed) + throw new pmModifyPrinterFailedException(errorLog); + } + + } + + public void doModifyLocalNetwork() throws pmGuiException { + getDescription(); + getNetworkInfo(); + getFault(); + getBanner(); + if (workingPrinter.getPPD() != null) { + getMakeModelPPD(); + } else { + getTypeContents(); + } + getUserAccess(); + updatePrinter(); + + boolean failed = false; + try { + workingPrinter.modifyPrinter(); + } catch (Exception e) { + Debug.warning("CLNT:pmInstPr:doModifyLocalAttached: " + e); + failed = true; + } finally { + gatherLogs(workingPrinter); + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("doModifyLocalNetwork()"); + if (failed) + throw new pmModifyPrinterFailedException(errorLog); + } + + } + + + public void doModifyRemote() throws pmGuiException { + getDescription(); + updatePrinter(); + + boolean failed = false; + try { + workingPrinter.modifyPrinter(); + } catch (Exception e) { + Debug.warning("CLNT:doModifyRemote: " + e); + failed = true; + } finally { + gatherLogs(workingPrinter); + pmCalls.debugShowPrinter(workingPrinter); + dumpLogs("doModifyRemote()"); + if (failed) + throw new pmModifyPrinterFailedException(errorLog); + } + + } + + + public void doClearFields() { + + if (pnameText != null) + pnameText.setText(""); + if (snameText != null) + snameText.setText(""); + if (descText != null) + descText.setText(""); + if (portCombo != null) + portCombo.setSelectedIndex(0); + if (makeCombo != null) + makeCombo.setSelectedIndex(0); + if (modelCombo != null) + modelCombo.setSelectedIndex(0); + if (ppdCombo != null) + ppdCombo.setSelectedIndex(0); + if (typeCombo != null) + typeCombo.setSelectedIndex(0); + if (faultCombo != null) + faultCombo.setSelectedIndex(0); + if (protocolCombo != null) + protocolCombo.setSelectedIndex(0); + if (destText != null) + destText.setText(""); + + if (defaultp.isSelected()) + defaultp.doClick(); + + if (bannerCombo != null) + bannerCombo.setSelectedIndex(0); + + accessModel.removeListEntries(); + accessModel.addaccessList("all"); + } + + public void doResetFields() { + + if (workingPrinter != null) { + try { + if (workingPrinter.getComment() != null) + descText.setText(workingPrinter.getComment()); + else + descText.setText(""); + } catch (Exception e) { + Debug.message( + "CLNT:pmInstallPr:doResetFields(): getComment() " + + "Exception: " + e); + } + + if (action == Constants.ADDLOCAL || + action == Constants.ADDNETWORK || + action == Constants.MODIFYATTACHED) { + try { + portCombo.setSelectedItem(workingPrinter.getDevice()); + } catch (Exception e) { + Debug.message( + "CLNT:pmInsPr:doResetFields(): getDevice() " + + "Exception: " + e); + } + } + + if (action != Constants.MODIFYREMOTE) { + if (workingPrinter.getPPD() != null) { + setMake(); + setModel(); + setPPD(); + } else { + setPrinterType(); + setType(); + } + + setFault(); + + if (action == Constants.MODIFYNETWORK) + setNetworkInfo(); + + try { + accessModel.removeListEntries(); + accessModel.addaccessList( + workingPrinter.getUserAllowList()); + accessList.setListData(accessModel.getAccessList()); + accessList.ensureIndexIsVisible(0); + } catch (Exception e) { + Debug.warning( + "CLNT:InstPr:doResetFields(): addaccessList() " + + "Exception: " + e); + } finally { + accessList.clearSelection(); + } + + + + // selected and banner object out of sync + setBanner(); + } + + // selected and printer object out of sync + if ((defaultp.isSelected() && + !workingPrinter.getIsDefaultPrinter()) || + + (!defaultp.isSelected() && + workingPrinter.getIsDefaultPrinter())) + + defaultp.doClick(); + + } + } + + + + public boolean isactionModify() { + + if (action == Constants.MODIFYATTACHED || + action == Constants.MODIFYNETWORK || + action == Constants.MODIFYREMOTE) + + return true; + else + return false; + } + + public void doReset() { + Debug.message("CLNT:pmInsPr:doReset()"); + if (action == Constants.ADDLOCAL || + action == Constants.ADDNETWORK) { + + doClearFields(); + } else { + doResetFields(); + } + + // as a side effect, the OK button will regain default status + if (defaultComponent != null) + defaultComponent.requestFocus(); + } + + public void doAction() throws pmGuiException { + + // if nameservice, check for login + + if (myTop.ns.getNameService().equals("nis") == true || + myTop.ns.getNameService().equals("ldap") == true) { + try { + if (!myTop.ns.isAuth()) { + pmUtility.doLogin(myTop, frame); + } + } catch (pmUserCancelledException e) { + throw new pmLoginFailedException( + pmUtility.getResource("User.cancelled.login.")); + } catch (pmGuiException ge) { + Debug.message("CLNT:pmInstPr: Required login failed."); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource("Required.login.failed."), + myTop, + "LoginFailed"); + m.setVisible(true); + Debug.message("CLNT:pmInstPr:required login failed."); + throw new pmLoginFailedException( + pmUtility.getResource("Required.login.failed.")); + } catch (Exception e) { + Debug.message("CLNT:pmInstPr:login exception: " + e); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource("Required.login.failed."), + myTop, + "LoginFailed"); + m.setVisible(true); + throw new pmLoginFailedException( + pmUtility.getResource("Required.login.failed.")); + } + } + + frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + Debug.message("CLNT:pmInstPr:doAction: action " + action); + + // Check for confirmation option + if (((myTop.getConfirmOption() == true) && (confirmAction() == true)) + || (myTop.getConfirmOption() == false)) { + + try { + + switch (action) { + + case Constants.ADDLOCAL: + doAddLocal(); + break; + case Constants.ADDNETWORK: + doAddNetwork(); + break; + case Constants.MODIFYATTACHED: + workingPrinter.getPrinterDetails(); + Debug.message( + "CLNT:pmInstPr:Printer Details: server is " + + workingPrinter.getPrintServer()); + doModifyLocalAttached(); + break; + case Constants.MODIFYNETWORK: + // add dest and protocol + workingPrinter.getPrinterDetails(); + Debug.message("CLNT:pmInstPr:Printer Details: server is " + + workingPrinter.getPrintServer()); + doModifyLocalNetwork(); + break; + case Constants.MODIFYREMOTE: + workingPrinter.getPrinterDetails(); + doModifyRemote(); + break; + } + + } catch (pmIncompleteFormException fe) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + fe.getMessage()); // "FormError" + m.setVisible(true); + throw new pmIncompleteFormException(); + } catch (pmPrinterExistsException ee) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "The.specified.printer.already.exists.")); + m.setVisible(true); + } catch (pmNullSelectedPrinterException ne) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "The.selected.printer.does.not.exist.")); + m.setVisible(true); + cleanup(); + // frame.dispose(); + } catch (pmAddPrinterFailedException ae) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + ae.getMessage(), + myTop, + "AddPrinterFailed"); + m.setVisible(true); + + } catch (pmModifyPrinterFailedException me) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + me.getMessage(), + myTop, + "ModifyFailed"); + m.setVisible(true); + } catch (pmGuiException ge) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Application.Error"), + ge.toString()); + m.setVisible(true); + + } catch (pmCmdFailedException cfe) { + String msg = cfe.getMessage(); + if (msg == null || msg.length() == 0) + msg = pmUtility.getResource( + "error.message.command-failed"); + + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Command.Failed.Error"), + msg); + m.setVisible(true); + + } catch (Exception e) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Unknown.Application.Error"), + e.toString()); + m.setVisible(true); + + } finally { + frame.setCursor(Cursor.getDefaultCursor()); + myTop.setLogData(cmdLog, errorLog, warnLog); + myTop.showLogData(actionName); + } + + // Update the list of printers + myTop.pmsetPrinterList(); + } + + } + + public boolean confirmAction() { + if (myTop.getConfirmOption() == true) { + pmOKCancelDialog d = new pmOKCancelDialog(frame, + pmUtility.getResource("Action.Confirmation"), + pmUtility.getResource( + "Continue.action.for.this.printer?")); + d.setVisible(true); + if (d.getValue() != JOptionPane.OK_OPTION) { + pmMessageDialog m = + new pmMessageDialog( + frame, + pmUtility.getResource("Warning"), + pmUtility.getResource("Operation.Cancelled")); + m.setVisible(true); + return false; + } + } + return true; + } + + + public void actionportCombo() { + Debug.message("CLNT:pmInstPr:actionportCombo()"); + port = (String)portCombo.getSelectedItem(); + if (port.equals(pmUtility.getResource("Other..."))) { + pmOther o = new pmOther( + frame, + pmUtility.getResource("SPM:Specify.Printer.Port"), + pmUtility.getResource("Enter.printer.port.or.file"), + myTop, + "PrinterPort"); + + o.setVisible(true); + if (o.getValue() == JOptionPane.OK_OPTION) { + port = o.deviceName.getText(); + int idx = portCombo.getItemCount(); + try { + if (!port.equals("") && Valid.device(port)) { + portCombo.insertItemAt( + port, (idx > 0) ? idx -1 : idx); + portCombo.setSelectedItem(port); + } else if (!port.equals("")) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Device.missing.or.not.writeable."), + myTop, + "PrinterPort"); // "InvalidDevice" + m.setVisible(true); + if (olddevice == null) + portCombo.setSelectedIndex(0); + else + portCombo.setSelectedItem(olddevice); + } else { + if (olddevice == null) + portCombo.setSelectedIndex(0); + else + portCombo.setSelectedItem(olddevice); + } + } catch (Exception de) { + Debug.warning( + "CLNT:pmInstPr:error validating device" + de); + } + + } else { // Cancelled out of Other window + if (olddevice == null) + portCombo.setSelectedIndex(0); + else + portCombo.setSelectedItem(olddevice); + } + } + olddevice = (String)portCombo.getSelectedItem(); + if (!port.equals(pmUtility.getResource("Not.Selected"))) { + portCombo.removeItem(pmUtility.getResource("Not.Selected")); + if ((pmMisc.isppdCachefile()) && (usePPD)) { + String makemodel[] = null; + String tmake; + int idx; + String models[] = null; + int i; + + makemodel = PrinterUtil.getProbePrinter(olddevice); + if (makemodel != null) { + if ((makemodel[0] != null) && + (!makemodel[0].equals(null))) { + + idx = (makemodel[0]).indexOf(" "); + + Debug.message( + "CLNT: makemodel[0] = " + makemodel[0]); + Debug.message( + "CLNT: makemodel[1] = " + makemodel[1]); + + if (idx != -1) + tmake = new String(makemodel[0].substring(0, idx)); + else + tmake = new String(makemodel[0]); + + // Some Manufacturers have multiple names + // Collapse them + if ((tmake.equals("hp")) || + (tmake.equals("Hewlett-Packard")) || + (tmake.equals("HEWLETT-PACKARD"))) + tmake = new String("HP"); + + if ((tmake.equals("MINOLTA-QMS")) || + (tmake.equals("MINOLTA"))) + tmake = new String("Minolta"); + + if ((tmake.equals("OKI")) || + (tmake.equals("OKI DATA CORP"))) + tmake = new String("Okidata"); + + if (tmake.equals("XEROX")) + tmake = new String("Xerox"); + + if (tmake.equals("EPSON")) + tmake = new String("Epson"); + + Debug.message("CLNT:pmInstPr:Probe:make: " + tmake); + + if ((makemodel[1] != null) && + (!makemodel[1].equals(null))) { + + Debug.message( + "CLNT:pmInstPr:Probe:model: " + makemodel[1]); + + try { + models = PrinterUtil.getModelsList( + tmake.trim()); + } catch (Exception e) { + Debug.warning( + "CLNT:pmInstPr:getModelsList: exception" + e); + } + + boolean havemodel = false; + boolean addmake = false; + + if (models == null) { + Debug.warning( + "CLNT:pmInstPr:Probe:no models for " + + tmake); + } else { + for (i = 0; i < models.length; i++) { + if (models[i].equalsIgnoreCase( + makemodel[1].trim())) { + havemodel = true; + } + } + // Some Printers do not preceed the model + // name with the Make. If fail, try adding + // Make to front of model + if (!havemodel) { + for (i = 0; i < models.length; i++) { + if (models[i].equalsIgnoreCase( + tmake.trim() + + " " + makemodel[1].trim())) { + havemodel = true; + addmake = true; + + } + } + } + + if (havemodel) { + makeCombo.setSelectedItem(tmake); + if (!addmake) { + modelCombo.setSelectedItem(makemodel[1]); + Debug.message("CLNT:pmInstPr:model is " + + makemodel[1]); + } else { + modelCombo.setSelectedItem(tmake.trim() + + " " + makemodel[1]); + Debug.message("CLNT:pmInstPr:model is " + + tmake.trim() + " " + makemodel[1]); + } + + } + } + } + } + } + } + } + } + + public void actiontypeCombo() { + + Debug.message("CLNT:pmInstPr:actiontypeCombo()"); + ptype = (String)typeCombo.getSelectedItem(); + + if (ptype.equals(pmUtility.getResource("Other..."))) { + pmOther o = new pmOther( + frame, + pmUtility.getResource("SPM:Specify.Printer.Type"), + pmUtility.getResource("Enter.printer.type:"), + myTop, + "PrinterType"); + o.setVisible(true); + if (o.getValue() == JOptionPane.OK_OPTION) { + ptype = o.deviceName.getText(); + int idx = typeCombo.getItemCount(); + try { + if (!ptype.equals("") && Valid.printerType(ptype)) { + typeCombo.insertItemAt( + ptype, (idx > 0) ? idx -1 : idx); + typeCombo.setSelectedItem(ptype); + } else if (!ptype.equals("")) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Invalid.printer.type."), + myTop, + "PrinterType"); + m.setVisible(true); + if (oldptype == null) + typeCombo.setSelectedIndex(0); + else + typeCombo.setSelectedItem(oldptype); + } else { + if (oldptype == null) + typeCombo.setSelectedIndex(0); + else + typeCombo.setSelectedItem(oldptype); + } + + } catch (Exception pte) { + Debug.message( + "CLNT:pmInstPr:error validating printertype" + + pte); + } + + } else { // Cancelled out of Other window + if (oldptype == null) + typeCombo.setSelectedIndex(0); + else + typeCombo.setSelectedItem(oldptype); + } + } + oldptype = (String)typeCombo.getSelectedItem(); + } + + // Printer make has been selected + public void actionmakeCombo() { + int i; + + make = (String)makeCombo.getSelectedItem(); + if (!make.equals(pmUtility.getResource("Not.Selected"))) + makeCombo.removeItem(pmUtility.getResource("Not.Selected")); + + + if (!oldmake.equals(make)) + modelCombo.removeAllItems(); + + oldmake = make; + } + + + // Get Model + public void actionmodelCombo() { + int i; + String models[] = null; + + if (!oldmake.equals(make)) { + try { + models = PrinterUtil.getModelsList(make); + } catch (Exception e) { + Debug.warning( + "CLNT:pmInstPr:actionmodelCombo: exception" + e); + } + + if (models == null) { + Debug.warning( + "CLNT:pmInstPr:actionmodelCombo:no models for " + + make); + modelCombo.removeAllItems(); + modelCombo.addItem(pmUtility.getResource( + "No.Models.Found")); + } else { + for (i = 0; i < models.length; i++) + modelCombo.addItem(models[i]); + } + } + + model = (String)modelCombo.getSelectedItem(); + if (!oldmodel.equals(model)) + ppdCombo.removeAllItems(); + + oldmodel = model; + } + + + public void actionppdCombo() { + int i; + int rec = -1; + int idx = -1; + String ppds[] = null; + + if (!oldmodel.equals(model)) { + + try { + ppds = PrinterUtil.getPPDList(make, model); + + } catch (Exception e) { + Debug.warning( + "CLNT:pmInstPr:actionmodelCombo: exception" +e); + } + + // Get the ppd files list + // If a recommended ppd is in the list, display it first + if (ppds == null) { + Debug.warning( + "CLNT:pmInstPr:actionmodelCombo: no ppds for " + + make + "/" + model); + ppdCombo.addItem( + pmUtility.getResource("No.PPD.Files.Found")); + } else { + for (i = 0; i < ppds.length; i++) { + ppdCombo.addItem(ppds[i]); + rec = ppds[i].indexOf("recommended"); + if (rec != -1) + idx = i; + } + + if (idx != -1) + ppdCombo.setSelectedIndex(idx); + } + } + + ppd = (String)ppdCombo.getSelectedItem(); + + if (!ppd.equals("")) + ppdCombo.removeItem(""); + + } + + + public void actionaddButton() { + + String tmp = null; + String trimtmp; + Debug.message("CLNT:pmInstPr:actionaddButton()"); + try { + tmp = userText.getText(); + } catch (Exception e) { + Debug.message( + "CLNT:pmInstPr:actionaddButton:UserAccessList empty"); + } + + if (tmp == null || tmp.equals("") || tmp.trim().equals("")) { + Debug.message("CLNT:pmInstPr:no username to add"); + } else { + trimtmp = tmp.trim(); + if (accessModel.isduplicate(trimtmp)) + Debug.message("CLNT:pmInstPr:duplicate user"); + + else if (!Valid.user(trimtmp)) { + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource("Invalid.username")); + // "FormError" + m.setVisible(true); + + } else { + if (accessModel.getRowCount() > 0 && + (accessModel.getElementAt(0).equals("all") || + accessModel.getElementAt(0).equals("none"))) + accessModel.removeRow(0); + + if (trimtmp.equals("all") || + trimtmp.equals("none")) { + accessModel.removeListEntries(); + } + + accessModel.addaccessList(trimtmp); + accessList.setListData(accessModel.getAccessList()); + int rw = accessModel.getRowCount(); + accessList.setSelectedIndex(rw - 1); + accessList.ensureIndexIsVisible(rw -1); + } + + } + userText.setText(""); + userText.requestFocus(); + + ascrollPane.revalidate(); + ascrollPane.repaint(); + + frame.repaint(); + } + + public void actiondeleteButton() { + Debug.message("CLNT:pmInstPr:actiondeleteButton()"); + int row; + int rcount; + int idx; + + row = accessList.getSelectedIndex(); + rcount = accessModel.getRowCount(); + + if ((row >= 0 && rcount > 0) && (!accessList.isSelectionEmpty())) { + accessModel.removeRow(row); + rcount = accessModel.getRowCount(); + if (rcount != 0) { + if (row == rcount) + accessList.setSelectedIndex(row - 1); + idx = accessList.getFirstVisibleIndex(); + if (idx > 0 && idx < rcount) + accessList.ensureIndexIsVisible(idx - 1); + } + } + userText.requestFocus(); + frame.repaint(); + } + + + // For ok/cancel + public void cleanup() { + + if (action == Constants.ADDLOCAL) { + myTop.localinstallView = null; + } + + if (action == Constants.ADDNETWORK) { + myTop.networkinstallView = null; + } + + } + + public void pmScreendispose() { + frame.dispose(); + } + + public void actionokButton() { + + Debug.message("CLNT:pmInstPr:actionokButton()"); + boolean incomplete = false; + + try { + doAction(); + } catch (pmLoginFailedException le) { + // User already notified + Debug.message("CLNT:pmInstPr:pmLoginFailedException caught"); + } catch (pmIncompleteFormException fe) { + // User already notified + incomplete = true; + } catch (pmGuiException ge) { + Debug.message("CLNT:pmInstPr:login Exception, task cancelled"); + } + + if (!incomplete) { + cleanup(); + myTop.pmsetdefaultpLabel(); + Debug.message("CLNT:pmInstPr:actionokbutton(): work done"); + pmCalls.debugShowPrinter(workingPrinter); + frame.setVisible(false); + frame.repaint(); + // frame.dispose(); + myTop.scrollPane.revalidate(); + myTop.scrollPane.repaint(); + } + } + + public void actionapplyButton() { + + Debug.message("CLNT:pmInstPr:actionapplyButton()"); + + try { + doAction(); + } catch (pmLoginFailedException le) { + // User already notified + Debug.message("CLNT:pmInstPr:pmLoginFailedException caught"); + } catch (pmGuiException ge) { + Debug.message("CLNT:pmInstPr:login Exception, task cancelled"); + } + + myTop.pmsetdefaultpLabel(); + Debug.message("CLNT:pmInstPr:actionapplybutton(): work done"); + pmCalls.debugShowPrinter(workingPrinter); + myTop.scrollPane.revalidate(); + myTop.scrollPane.repaint(); + } + + + public void actionresetButton() { + Debug.message("CLNT:pmInstPr:actionresetButton()"); + doReset(); + frame.repaint(); + } + + public void actioncancelButton() { + Debug.message("CLNT:pmInstPr:actioncancelButton()"); + cleanup(); + frame.setVisible(false); + frame.repaint(); + // frame.dispose(); + } + + public void actionhelpButton() { + Debug.message("CLNT:pmInstPr:actionhelpButton()"); + myTop.showHelpItem(helpTag); + } + + public void Show() { + + Debug.message("CLNT:pmInstPr:Show()"); + frame.getContentPane().add("North", this); + frame.pack(); + frame.setVisible(true); + frame.repaint(); + + // set focus to initial field, depending on which action is tbd + // this seems to work best after pack() + + // default button is always OK, for now... + // frame.getRootPane().setDefaultButton (okButton); + okButton.setAsDefaultButton(); + + + Debug.info("Show: default comp is " + defaultComponent); + if (defaultComponent != null) { + defaultComponent.requestFocus(); + } + + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmInstallScreen.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmInstallScreen.java new file mode 100644 index 0000000000..a52fdfc4d5 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmInstallScreen.java @@ -0,0 +1,495 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmInstallScreen.java + * Create add/modify GUI + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.Vector; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + +/* + * Screen for Installing/Modifying local and network printers + */ + +public class pmInstallScreen extends pmButtonScreen { + + pmTextField pnameText; + pmTextField snameText; + pmTextField descText; + pmTextField userText; + JComboBox portCombo; + JComboBox faultCombo; + +// For printers configured without using make/model/PPD files + JComboBox fileCombo; + JComboBox typeCombo; + +// For printers configured using make/model/PPD files + JComboBox ppdCombo; + JComboBox makeCombo; + JComboBox modelCombo; + + pmTextField destText; + JComboBox protocolCombo; + JCheckBox defaultp; + JComboBox bannerCombo; + pmButton addButton; + pmButton deleteButton; + JList userList; + Vector userData; + + public pmInstallScreen() {} + + + public void printernameLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Name:")), c); + } + public void printernameTextField(JPanel north, GridBagConstraints c) { + pnameText = new pmTextField(14); + north.add(pnameText, c); + } + public void printernameStaticField(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Server:")), c); + } + + public void servernameLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Server:")), c); + } + public void servernameTextField(JPanel north, GridBagConstraints c) { + snameText = new pmTextField(30); + north.add(snameText, c); + } + public void servernameStaticField(JPanel north, GridBagConstraints c) { + } + + public void descriptionLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Description:")), c); + } + public void descriptionField(JPanel north, GridBagConstraints c) { + descText = new pmTextField(25); + north.add(descText, c); + } + + public void printerportLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Port:")), c); + } + + public void devnullLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel("/dev/null")); + } + + public void printerportField(JPanel north, GridBagConstraints c) { + + String devices[]; + int i; + + try { + devices = PrinterUtil.getDeviceList(); + } catch (Exception e) { + Debug.warning("CLNT: pmAccess:getDeviceList caught " + e); + devices = new String[1]; + devices[0] = ""; + } + portCombo = new JComboBox(devices); + portCombo.insertItemAt(pmUtility.getResource("Not.Selected"), 0); + portCombo.setSelectedIndex(0); + + portCombo.addItem(pmUtility.getResource("Other...")); + portCombo.addActionListener(new ComboListener(Constants.PORT)); + + north.add(portCombo, c); + + } + public void printertypeLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Type:")), c); + } + public void printertypeField(JPanel north, GridBagConstraints c) { + typeCombo = new JComboBox(); + typeCombo.addItem("PostScript"); + typeCombo.addItem("HP Printer"); + typeCombo.addItem("Reverse PostScript"); + typeCombo.addItem("Epson 2500"); + typeCombo.addItem("IBM ProPrinter"); + typeCombo.addItem("Qume Sprint 5"); + typeCombo.addItem("Daisy"); + typeCombo.addItem("Diablo"); + typeCombo.addItem("Datagraphix"); + typeCombo.addItem("DEC LA100"); + typeCombo.addItem("DEC LN03"); + typeCombo.addItem("Dec Writer"); + typeCombo.addItem("Texas Instruments 800"); + typeCombo.addItem(pmUtility.getResource("Other...")); + typeCombo.addActionListener(new ComboListener(Constants.TYPE)); + north.add(typeCombo, c); + } + + public void filecontentsLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("File.Contents:")), c); + } + public void filecontentsField(JPanel north, GridBagConstraints c) { + fileCombo = new JComboBox(); + fileCombo.addItem(pmUtility.getResource("PostScript")); + fileCombo.addItem(pmUtility.getResource("ASCII")); + fileCombo.addItem( + pmUtility.getResource("Both.PostScript.and.ASCII")); + fileCombo.addItem(pmUtility.getResource("None")); + fileCombo.addItem(pmUtility.getResource("Any")); + north.add(fileCombo, c); + } + + + public void printermakeLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Make:")), c); + } + public void printermakeField(JPanel north, GridBagConstraints c) { + + String makes[]; + + try { + makes = PrinterUtil.getMakesList(); + } catch (Exception e) { + Debug.warning("CLNT: pmAccess:getMakeList caught" +e); + makes = new String[1]; + makes[0] = ""; + } + + makeCombo = new JComboBox(makes); + makeCombo.insertItemAt( + pmUtility.getResource("Not.Selected"), 0); + makeCombo.setSelectedIndex(0); + + + makeCombo.addActionListener(new ComboListener(Constants.MAKE)); + north.add(makeCombo, c); + } + + public void printermodelsLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Model:")), c); + } + + public void printermodelsField(JPanel north, GridBagConstraints c) { + String models[]; + modelCombo = new JComboBox(); + modelCombo.addItem(" "); + modelCombo.addActionListener( + new ComboListener(Constants.MODEL)); + north.add(modelCombo, c); + } + + public void ppdcontentsLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Printer.Driver:")), c); + } + public void ppdcontentsField(JPanel north, GridBagConstraints c) { + ppdCombo = new JComboBox(); + ppdCombo.addItem(" "); + ppdCombo.addActionListener(new ComboListener(Constants.PPD)); + north.add(ppdCombo, c); + } + + public void faultnotLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Fault.Notification:")), c); + } + public void faultnotField(JPanel north, GridBagConstraints c) { + faultCombo = new JComboBox(); + + faultCombo.addItem(pmUtility.getResource("Write.to.Superuser")); + faultCombo.addItem(pmUtility.getResource("Mail.to.Superuser")); + faultCombo.addItem(pmUtility.getResource("None")); + north.add(faultCombo, c); + } + + public void destinationLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Destination:")), c); + } + public void destinationField(JPanel north, GridBagConstraints c) { + destText = new pmTextField(25); + north.add(destText, c); + } + + public void protocolLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Protocol:")), c); + } + public void protocolField(JPanel north, GridBagConstraints c) { + protocolCombo = new JComboBox(); + protocolCombo.addItem("BSD"); + protocolCombo.addItem("TCP"); + protocolCombo.addItem("URI"); + north.add(protocolCombo, c); + } + + public void optionsLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Options:")), c); + } + + public void bannerLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Banner:")), c); + } + + public void optionLabel(JPanel north, GridBagConstraints c) { + north.add(new JLabel + (pmUtility.getResource("Option:")), c); + } + + public void optionsFields(JPanel north, GridBagConstraints c) { + defaultp = new JCheckBox( + pmUtility.getResource("Default.Printer")); + + north.add(defaultp, c); + + c.gridy++; + bannerCombo = new JComboBox(); + bannerCombo.addItem(pmUtility.getResource + ("Always.Print.Banner")); + bannerCombo.addItem(pmUtility.getResource + ("User.Selectable.Default.On")); + bannerCombo.addItem(pmUtility.getResource + ("Never.Print.Banner")); + + north.add(bannerCombo, c); + } + + public void defaultoptionField(JPanel north, GridBagConstraints c) { + defaultp = new JCheckBox( + pmUtility.getResource("Default.Printer")); + + north.add(defaultp, c); + } + + public void northPanelConstraints(GridBagConstraints c) { + c.weightx = c.weighty = 0.0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(8, 5, 5, 5); + c.gridheight = 1; + c.gridwidth = 1; + } + + public void labelConstraints(GridBagConstraints c) { + c.weightx = c.weighty = 0.0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + } + public void TextFieldConstraints(GridBagConstraints c) { + c.ipadx = 15; + c.fill = GridBagConstraints.HORIZONTAL; + // c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + c.weightx = c.weighty = 1.0; + } + public void comboboxConstraints(GridBagConstraints c) { + c.weightx = c.weighty = 0.0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + } + + public void optionsConstraints(GridBagConstraints c) { + c.fill = GridBagConstraints.NONE; + c.weightx = c.weighty = 0.0; + } + + class ComboListener implements ActionListener { + int activeCombo; + + // Constructor + public ComboListener(int aCombo) + { + activeCombo = aCombo; + } + + public void actionPerformed(ActionEvent e) { + + switch (activeCombo) + { + case Constants.PORT: + actionportCombo(); + break; + + case Constants.TYPE: + actiontypeCombo(); + break; + + case Constants.MAKE: + actionmakeCombo(); + break; + + case Constants.MODEL: + actionmodelCombo(); + break; + + case Constants.PPD: + actionppdCombo(); + break; + + } + } + } + + public void actionportCombo() {} + + public void actiontypeCombo() {} + + public void actionmakeCombo() {} + + public void actionmodelCombo() {} + + public void actionppdCombo() {} + + class adddelButtonListener implements ActionListener + { + int activeButton; + + public adddelButtonListener(int aButton) + { + activeButton = aButton; + } + + public void actionPerformed(ActionEvent e) { + + switch (activeButton) + { + case Constants.ADD: + actionaddButton(); + break; + case Constants.DELETE: + actiondeleteButton(); + break; + } + } + } + + public void actionaddButton() {} + + public void actiondeleteButton() {} + + public void useraccessLabel(JPanel center, GridBagConstraints c) { + center.add(new JLabel + (pmUtility.getResource("User.Access.List:")), c); + } + + public void adButtons(GridBagConstraints c) { + + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + + addButton = new pmButton(pmUtility.getResource("Add")); + deleteButton = new pmButton(pmUtility.getResource("Delete")); + addButton.addActionListener( + new adddelButtonListener(Constants.ADD)); + deleteButton.addActionListener( + new adddelButtonListener(Constants.DELETE)); + } + + public void xxcenterPanel() { + + JPanel center = new JPanel(); + center.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.insets = new Insets(15, 15, 15, 15); + c.anchor = GridBagConstraints.WEST; + + // Create the label + c.gridx = 0; + c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.weightx = c.weighty = 0.0; + c.anchor = GridBagConstraints.NORTHWEST; + center.add(new JLabel + (pmUtility.getResource("User.Access.List:")), c); + + // Create the User Access List as JList + userList = new JList(); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().setView(userList); + + c.gridwidth = 2; + c.gridx = 1; + c.weightx = c.weighty = 1.0; + c.fill = GridBagConstraints.BOTH; + center.add(scrollPane, c); + + // Create the text field for adding users + c.gridx = 1; + c.gridy = 1; + c.ipadx = 15; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.WEST; + c.weightx = c.weighty = 1.0; + + userText = new pmTextField(25); + center.add(userText, c); + + // Create the add/delete buttons + c.gridx = 1; + c.gridy = 2; + + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + + addButton = new pmButton(pmUtility.getResource("Add")); + deleteButton = new pmButton(pmUtility.getResource("Delete")); + addButton.addActionListener( + new adddelButtonListener(Constants.ADD)); + deleteButton.addActionListener( + new adddelButtonListener(Constants.DELETE)); + + + c.gridwidth = 1; + center.add(addButton, c); + + c.gridx = 2; + center.add(deleteButton, c); + + add("Center", center); + + } + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoad.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoad.java new file mode 100644 index 0000000000..dd4b81909d --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoad.java @@ -0,0 +1,284 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmLoad.java + * Load a Naming Context implementation + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + +public class pmLoad extends JPanel { + + final static int OK = 1; + final static int APPLY = 2; + final static int RESET = 3; + final static int CANCEL = 4; + final static int HELP = 5; + + final static int NIS = 6; + final static int NISPLUS = 7; + final static int NONE = 8; + + pmFrame frame = new pmFrame( + pmUtility.getResource("SPM:Select.Naming.Service")); + JComboBox nameserviceCombo = new JComboBox(); + pmTop mytop = null; + int resetIndex; + + pmButton okButton = null; + pmButton cancelButton = null; + pmButton resetButton = null; + pmButton helpButton = null; + + + public pmLoad(pmTop mytop) { + this.mytop = mytop; + + Debug.message("CLNT:pmLoad()"); + setLayout(new BorderLayout()); + resetIndex = mytop.actionindex; + + northPanel(); + southPanel(); + + + } + + public void northPanel() { + JPanel north = new JPanel(); + north.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.weightx = c.weighty = 0.0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + c.insets = new Insets(15, 15, 5, 15); + c.gridheight = 1; + c.gridwidth = 1; + + c.gridy = 1; + c.gridx = 0; + north.add(new JLabel + (pmUtility.getResource("Naming.Service:")), c); + + c.gridy = 1; + c.gridx = 2; + c.ipadx = 15; + + nameserviceCombo.addItem("files"); + + if (mytop.nisns != null) + nameserviceCombo.addItem("NIS"); + + if (mytop.nisplusns != null) + nameserviceCombo.addItem("NIS+"); + + if (mytop.ldapns != null) + nameserviceCombo.addItem("LDAP"); + + nameserviceCombo.setSelectedIndex(mytop.actionindex); + north.add(nameserviceCombo, c); + + nameserviceCombo.addActionListener(new nsListener()); + nameserviceCombo.addItemListener(mytop.new topnsListener()); + + add("North", north); + + } + + class nsListener implements ActionListener { + public nsListener() {} + + public void actionPerformed(ActionEvent e) + { + mytop.actionindex = nameserviceCombo.getSelectedIndex(); + if (mytop.actionindex == 0) { + Debug.message("CLNT:pmLoad:0: NONE"); + } else if (mytop.actionindex == 1) { + Debug.message("CLNT:pmLoad:1: NIS"); + } else if (mytop.actionindex == 3) { + Debug.message("CLNT:pmLoad:2: NISPLUS"); + } else if (mytop.actionindex == 4) { + Debug.message("CLNT:pmLoad:2: LDAP"); + } + }; + } + + public void southPanel() { + JPanel south = new JPanel(); + + south.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = c.weighty = 1.0; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.insets = new Insets(15, 15, 15, 15); + c.gridy = 0; + + okButton = new pmButton( + pmUtility.getResource("OK")); + okButton.setMnemonic( + pmUtility.getIntResource("OK.mnemonic")); + + resetButton = new pmButton( + pmUtility.getResource("Reset")); + resetButton.setMnemonic( + pmUtility.getIntResource("Reset.mnemonic")); + + cancelButton = new pmButton( + pmUtility.getResource("Cancel")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Cancel.mnemonic")); + + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + + okButton.addActionListener(new ButtonListener(OK)); + resetButton.addActionListener(new ButtonListener(RESET)); + cancelButton.addActionListener(new ButtonListener(CANCEL)); + helpButton.addActionListener(new ButtonListener(HELP)); + + c.gridx = 0; + south.add(okButton, c); + c.gridx = 1; + south.add(resetButton, c); + c.gridx = 2; + south.add(cancelButton, c); + c.gridx = 3; + south.add(helpButton, c); + + add("South", south); + } + + class ButtonListener implements ActionListener { + int activeButton; + + // Constructor + public ButtonListener(int aButton) + { + activeButton = aButton; + } + + // Select Active Button and call routine + + public void actionPerformed(ActionEvent e) + { + + switch (activeButton) { + case OK: + actionokButton(); + break; + case RESET: + actionresetButton(); + break; + case CANCEL: + actioncancelButton(); + break; + case HELP: + actionhelpButton(); + break; + } + + } + } + + public void pmScreendispose() { + frame.dispose(); + } + + // Action for buttons + + public void actionokButton() { + Debug.message("CLNT:pmLoad:actionokButton()"); + mytop.pmsetNS(); + mytop.pmsetNSLabel(); + mytop.pmsetPrinterList(); + mytop.pmsetdefaultpLabel(); + frame.setVisible(false); + frame.repaint(); + frame.dispose(); + } + + public void actionresetButton() { + Debug.message("CLNT:pmLoad:actionresetButton()"); + nameserviceCombo.setSelectedIndex(resetIndex); + frame.repaint(); + } + + public void actioncancelButton() { + Debug.message("CLNT:pmLoad:actioncancelButton()"); + nameserviceCombo.setSelectedIndex(resetIndex); + frame.setVisible(false); + frame.repaint(); + frame.dispose(); + } + + public void actionhelpButton() { + Debug.message("CLNT:pmLoad:actionhelpButton()"); + mytop.showHelpItem("NameService"); + } + + public void Show() { + Debug.message("CLNT:pmLoad:Show()"); + + frame.getContentPane().add("North", this); + frame.pack(); + + // handle Esc as cancel + frame.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + actioncancelButton(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + // default button is always OK, for now... + okButton.setAsDefaultButton(); + + frame.setDefaultComponent(nameserviceCombo); + + nameserviceCombo.requestFocus(); + + frame.setVisible(true); + frame.repaint(); + + } + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLogDisplay.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLogDisplay.java new file mode 100644 index 0000000000..93976a72ee --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLogDisplay.java @@ -0,0 +1,247 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright(c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmLogDisplay.java + * Command Log implementation + */ + +package com.sun.admin.pm.client; + +import javax.swing.*; + +import java.awt.*; +import java.util.*; +import java.awt.event.*; + +import com.sun.admin.pm.server.*; + +public class pmLogDisplay extends pmFrame { + + pmButton helpButton = null; + pmButton okButton = null; + pmButton clearButton = null; + pmTop theTop = null; + String helpTag = null; + JTextArea theList = null; + String theContents = null; + + public pmLogDisplay() { + this(null, null); + } + + + public pmLogDisplay(pmTop t, String h) { + super(pmUtility.getResource("SPM:Command-Line.Console")); + + theTop = t; + helpTag = h; + + setLocation(150, 200); // relative to parent frame + + // top panel + JPanel p = new JPanel(); + p.setLayout(new BorderLayout()); + + theContents = new String(); + theList = new JTextArea(12, 36); + theList.setLineWrap(false); + theList.setEditable(false); + + theList.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + copyPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, Event.CTRL_MASK), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + theList.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + copyPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + + JScrollPane scroll = new JScrollPane(); + scroll.getViewport().setView(theList); + + p.add(scroll, "Center"); + + this.getContentPane().add(p, "Center"); + + p = new JPanel(); + + okButton = new pmButton( + pmUtility.getResource("Dismiss")); + okButton.setMnemonic( + pmUtility.getIntResource("Dismiss.mnemonic")); + p.add(okButton); + + clearButton = new pmButton( + pmUtility.getResource("Clear")); + clearButton.setMnemonic( + pmUtility.getIntResource("Clear.mnemonic")); + p.add(clearButton); + + if (theTop != null && helpTag != null) { + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + p.add(helpButton); + helpButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + Debug.message("Help button event"); + theTop.showHelpItem(helpTag); + } + }); + } + + this.getContentPane().add(p, "South"); + + this.pack(); + + this.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + returnValue = JOptionPane.CLOSED_OPTION; + pmLogDisplay.this.setVisible(false); + if (pmLogDisplay.this.theTop != null) + pmLogDisplay.this.theTop.setLogOption(false); + } + }); + + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okPressed(); + } + }); + + clearButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + pmLogDisplay.this.clear(); + } + }); + + // handle Esc as dismiss in any case + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + okPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + // getRootPane().setDefaultButton(okButton); + okButton.setAsDefaultButton(); + + theList.requestFocus(); + + } + + protected void copyPressed() { + theList.copy(); + } + + + protected void okPressed() { + returnValue = JOptionPane.OK_OPTION; + pmLogDisplay.this.setVisible(false); + if (pmLogDisplay.this.theTop != null) + pmLogDisplay.this.theTop.setLogOption(false); + } + + public int getValue() { + // Debug.message("getValue"); + return returnValue; + } + + // i.e. a solid line, or spaces, or... + public void addSeparator() { + theContents = theContents + "\n\r"; + theList.setText(theContents); + } + + // tricky: s may have embedded newlines... + public void addText(String s) { + theContents = theContents + s; + + /* + * StringTokenizer st = new StringTokenizer(s, "\n\r", false); + * try { + * while(st.hasMoreTokens()) { + * String ss = st.nextToken(); + * theContents.addElement(ss); + * } + * } catch(Exception x) { + * Debug.warning("CLNT: Log addText caught: " + x); + * } + */ + + /* + * Debug.message("Log contents len = " + theContents.size()); + * for (int i = 0; i < theContents.size(); ++i) + * Debug.message("\t" + i + ": " + theContents.elementAt(i)); + */ + + // conveniently, this forces the last line to be scrolled to. + theList.setText(theContents); + + } + + public void clear() { + theContents = null; + theContents = new String(); + theList.setText(theContents); + } + + public void disableText(boolean d) { + // theText.setEnabled(!d); + } + + public static void main(String[] args) { + JFrame f = new JFrame("Test Dialog"); + f.setSize(300, 100); + + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + System.exit(0); + } + }); + + f.setVisible(true); + + pmLogDisplay d = new pmLogDisplay(); + d.addText("A\nB\nC\nD\nE\nF\nG\nH\nI\nJ"); + d.setVisible(true); + } + + + protected int returnValue = JOptionPane.CLOSED_OPTION; +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLogin.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLogin.java new file mode 100644 index 0000000000..fbb50a69b2 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLogin.java @@ -0,0 +1,424 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmLogin.java + * Login dialog + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.*; +import com.sun.admin.pm.server.*; + + + +/* + * a panel dialog which captures a username and password. + */ + +public class pmLogin extends pmDialog { + private pmTop theTop = null; + private String theTag = null; + private JFrame theFrame = null; + + protected pmButton okButton = null; + protected pmButton cancelButton = null; + protected pmButton helpButton = null; + + public pmLogin(JFrame f, String title, String msg) { + this(f, title, msg, null, null); + } + + public pmLogin(JFrame f, String title, String msg, pmTop t, String h) { + + super(f, title, true); // modal + + theTop = t; + theTag = h; + theFrame = f; + + JLabel l; + JPanel p; + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.EAST; + + // top panel contains the desired message + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + l = new JLabel(msg, SwingConstants.CENTER); + p.add(l, c); + this.getContentPane().add(p, "North"); + + // NIS middle panel + // contains username and password + if (t.ns.getNameService().equals("nis")) { + + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + l = new JLabel(pmUtility.getResource("Hostname:"), + SwingConstants.RIGHT); + p.add(l, c); + + l = new JLabel(pmUtility.getResource("Username:"), + SwingConstants.RIGHT); + p.add(l, c); + + l = new JLabel(pmUtility.getResource("Password:"), + SwingConstants.RIGHT); + p.add(l, c); + + passwordField = new JPasswordField(12); + passwordField.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + okPressed(); + } + }); + l.setLabelFor(passwordField); + // for consistency, don't implement this until all are... + // l.setDisplayedMnemonic( + // pmUtility.getIntResource("Password.mnemonic")); + + c.gridx = 1; + c.weightx = 1.0; + + String nisMaster; + try { + nisMaster = theTop.host.getNisMaster(); + } catch (Exception e) { + nisMaster = new String("Unknown"); + Debug.warning("pmLogin: getNisMaster() returns exception: " + e); + } + + c.anchor = GridBagConstraints.WEST; + + l = new JLabel(nisMaster, SwingConstants.LEFT); + p.add(l, c); + + l = new JLabel(("root"), SwingConstants.LEFT); + p.add(l, c); + + + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridy = GridBagConstraints.RELATIVE; + + p.add(passwordField, c); + passwordField.setEchoChar('*'); + + this.getContentPane().add(p, "Center"); + + } else if (t.ns.getNameService().equals("ldap")) { + + // middle panel contains LDAP server name, distinguished name, + // and password + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + // LDAP Server Name + l = new JLabel(pmUtility.getResource("LDAP.Server:"), + SwingConstants.RIGHT); + p.add(l, c); + + serverField = new pmTextField(25); + serverField.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + okPressed(); + } + }); + + String ldapMaster; + try { + ldapMaster = theTop.host.getLDAPMaster(); + } catch (Exception e) { + ldapMaster = new String(""); + Debug.warning( + "pmLdap: getLDAPMaster() returns exception: " + e); + } + + serverField.setText(ldapMaster); + c.gridx = 1; + p.add(serverField, c); + + + // Distinguished Name + c.gridx = 0; + l = new JLabel(pmUtility.getResource("Distinguished.Name:"), + SwingConstants.RIGHT); + p.add(l, c); + + dnField = new pmTextField(25); + dnField.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + okPressed(); + } + }); + + String defaultDN; + try { + defaultDN = theTop.host.getDefaultAdminDN(); + } catch (Exception e) { + defaultDN = new String(""); + Debug.warning( + "pmLdap: getDefaultAdminDN() returns exception: " + e); + } + + dnField.setText(defaultDN); + c.gridx = 1; + p.add(dnField, c); + + // Password + c.gridx = 0; + l = new JLabel(pmUtility.getResource("Password:"), + SwingConstants.RIGHT); + p.add(l, c); + + passwordField = new JPasswordField(12); + passwordField.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + okPressed(); + } + }); + l.setLabelFor(passwordField); + // for consistency, don't implement this until all are... + // l.setDisplayedMnemonic( + // pmUtility.getIntResource("Password.mnemonic")); + + c.gridx = 1; + c.weightx = 1.0; + + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.gridy = GridBagConstraints.RELATIVE; + + p.add(passwordField, c); + passwordField.setEchoChar('*'); + + this.getContentPane().add(p, "Center"); + + } + + + // bottom panel contains buttons + c.gridx = 0; + c.weightx = 1.0; + c.weighty = 0.0; + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + + JPanel thePanel = new JPanel(); + + okButton = new pmButton( + pmUtility.getResource("OK")); + okButton.setMnemonic( + pmUtility.getIntResource("OK.mnemonic")); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okPressed(); + } + }); + thePanel.add(okButton, c); + + cancelButton = new pmButton( + pmUtility.getResource("Cancel")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Cancel.mnemonic")); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + cancelPressed(); + } + }); + thePanel.add(cancelButton, c); + + if (theTag != null && theTop != null) { + + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + p.add(helpButton); + helpButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + helpPressed(); + } + }); + thePanel.add(helpButton, c); + } + + this.getContentPane().add(thePanel, "South"); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + returnValue = JOptionPane.CLOSED_OPTION; + pmLogin.this.setVisible(false); + } + }); + + // handle Esc as cancel in any case + this.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + cancelPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + // lay out the dialog + this.pack(); + + // set focus and defaults after packing... + // this.getRootPane().setDefaultButton(okButton); + okButton.setAsDefaultButton(); + + passwordField.requestFocus(); + } + + public int getValue() { + return returnValue; + } + + public void getLDAPServer() throws pmIncompleteFormException { + // LDAP Server name is required + String LDAPserver = null; + LDAPserver = serverField.getText(); + if (LDAPserver.equals("")) { + serverField.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("LDAP.server.name.required.")); + } + } + + public void getLDAPDN() throws pmIncompleteFormException { + // LDAP Distinguished name is required + String LDAPdn = null; + LDAPdn = dnField.getText(); + if (LDAPdn.equals("")) { + dnField.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("LDAP.Distinguished.name.required.")); + } + } + + public void getLDAPPassword() throws pmIncompleteFormException { + + // LDAP password is required + + String tmpp = new String(passwordField.getPassword()); + String LDAPpass = new String(tmpp.trim()); + + if (LDAPpass.equals("")) { + passwordField.requestFocus(); + throw new pmIncompleteFormException( + pmUtility.getResource("LDAP.Password.required.")); + } + } + + public void okPressed() { + + // For LDAP, Check Server, Distinguished Name and Password + boolean complete = true; + + if (theTop.ns.getNameService().equals("ldap")) { + complete = false; + try { + getLDAPServer(); + getLDAPDN(); + getLDAPPassword(); + complete = true; + } catch (pmIncompleteFormException fe) { + pmMessageDialog m = new pmMessageDialog( + theFrame, + pmUtility.getResource("Error"), + fe.getMessage()); // "FormError" + m.setVisible(true); + } + } + + if (complete) { + returnValue = JOptionPane.OK_OPTION; + pmLogin.this.setVisible(false); + } + } + + + + public void cancelPressed() { + returnValue = JOptionPane.CANCEL_OPTION; + pmLogin.this.setVisible(false); + } + + + public void clearPressed() { + + passwordField.setText(""); + } + + public void helpPressed() { + theTop.showHelpItem(theTag); + } + + public static void main(String[] args) { + JFrame f = new JFrame("Password test"); + + f.setSize(300, 100); + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + f.setVisible(true); + + while (true) { + pmLogin d = new pmLogin(f, "Test Login", + "NIS/LDAP Authentication."); + d.setVisible(true); + + + } + // System.exit(0); + } + + public JPasswordField passwordField = null; + public pmTextField serverField = null; + public pmTextField dnField = null; + + protected int returnValue = JOptionPane.CLOSED_OPTION; + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoginFailedException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoginFailedException.java new file mode 100644 index 0000000000..513322d4e6 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoginFailedException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmLoginFailedException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmLoginFailedException extends pmGuiException { + public pmLoginFailedException(String s) { + super(s); + } + public pmLoginFailedException() { + super(); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmMessageDialog.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmMessageDialog.java new file mode 100644 index 0000000000..32fd19a3b2 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmMessageDialog.java @@ -0,0 +1,207 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmMessageDialog.java + * Common info message dialog + */ + +package com.sun.admin.pm.client; + +import javax.swing.*; +import java.util.*; +import java.awt.*; +import java.awt.event.*; +import com.sun.admin.pm.server.*; + +public class pmMessageDialog extends pmDialog { + + pmButton helpButton = null; + pmButton okButton = null; + JList theText = null; + pmTop theTop = null; + String helpTag = null; + + + public pmMessageDialog(String title, String msg) { + this(null, title, msg, null, null); + } + + public pmMessageDialog(Frame f, String title, String msg) { + this(f, title, msg, null, null); + } + + public pmMessageDialog(Frame f, + String title, + String msg, + pmTop top, + String h) { + + super(f, title, true); // modal + + theTop = top; + helpTag = h; + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.EAST; + + // top panel + JPanel p = new JPanel(); + p.setLayout(new GridBagLayout()); + // p.setLayout(new BoxLayout(BoxLayout.X_AXIS)); + + // JLabel label = new JLabel(msg, SwingConstants.CENTER); + JList theText = new JList() { + public boolean isFocusable() { + return false; + } + }; + + Vector v = new Vector(); + + Debug.message("CLNT: MessageDialog: " + title + " , " + msg); + + if (msg != null) { + StringTokenizer st = new StringTokenizer(msg, "\n", false); + try { + while (st.hasMoreTokens()) + v.addElement(st.nextToken()); + } catch (Exception x) { + Debug.warning("CLNT: pmMessageDialog caught " + x); + } + theText.setListData(v); + } + + theText.setBackground(p.getBackground()); + + // p.add(theText, "Center"); + p.add(theText, c); + + this.getContentPane().add(p, "Center"); + + okButton = new pmButton( + pmUtility.getResource("Dismiss")); + okButton.setMnemonic( + pmUtility.getIntResource("Dismiss.mnemonic")); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + actionOKButton(); + } + }); + + // handle Esc as dismiss in any case + this.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + actionOKButton(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + p = new JPanel(); + p.add(okButton); + + if (theTop != null && helpTag != null) { + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + p.add(helpButton); + helpButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + theTop.showHelpItem(helpTag); + } + }); + } + + this.getContentPane().add(p, "South"); + this.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + actionOKButton(); + } + }); + + this.pack(); + + // this.getRootPane().setDefaultButton(okButton); + okButton.setAsDefaultButton(); + + // okButton.requestFocus(); + okButton.grabFocus(); + + } + + + protected void actionOKButton() { + returnValue = JOptionPane.OK_OPTION; + pmMessageDialog.this.setVisible(false); + } + + + public int getValue() { + return returnValue; + } + + + public static void main(String[] args) { + JFrame f = new JFrame("Test Dialog"); + f.setSize(300, 100); + + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + System.exit(0); + } + }); + + f.setVisible(true); + + while (true) { + System.out.println("creating a new dialog instance..."); + pmMessageDialog d = + new pmMessageDialog(null, + "Dialog Test", + "Dumb test message.", + null, + null); + d.setVisible(true); + System.out.println("Dialog returns " + d.getValue()); + + d.dispose(); + + } + + } + + + protected int returnValue = JOptionPane.CLOSED_OPTION; +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmModifyPrinterFailedException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmModifyPrinterFailedException.java new file mode 100644 index 0000000000..0de6d10bad --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmModifyPrinterFailedException.java @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmModifyPrinterFailedException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmModifyPrinterFailedException extends pmGuiException { + public pmModifyPrinterFailedException(String s) { + super(s); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmMustBeRemoteServerException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmMustBeRemoteServerException.java new file mode 100644 index 0000000000..9153523d7d --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmMustBeRemoteServerException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmDeleteFailedException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmMustBeRemoteServerException extends pmGuiException { + public pmMustBeRemoteServerException(String s) { + super(s); + } + public pmMustBeRemoteServerException() { + super(); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmNeedPPDCacheException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmNeedPPDCacheException.java new file mode 100644 index 0000000000..2f2265070a --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmNeedPPDCacheException.java @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmInstallPrinter.java + * Install and Modify Printer implementation + * + * pmNeedPPDCache.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +public class pmNeedPPDCacheException extends pmGuiException { + public pmNeedPPDCacheException(String s) { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmNullSelectedPrinterException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmNullSelectedPrinterException.java new file mode 100644 index 0000000000..943e5cdeb7 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmNullSelectedPrinterException.java @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmNullSelectedPrinterException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmNullSelectedPrinterException extends pmGuiException { + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOKCancelDialog.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOKCancelDialog.java new file mode 100644 index 0000000000..9d2e8ff3ea --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOKCancelDialog.java @@ -0,0 +1,243 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmOKCancelDialog.java + * Common dialog + */ + +package com.sun.admin.pm.client; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import com.sun.admin.pm.server.Debug; + + +public class pmOKCancelDialog extends pmDialog { + private pmTop theTop; + private String theTag; + protected boolean defaultIsOK = true; + + public pmOKCancelDialog(Frame f, String title, String msg) { + this(f, title, msg, null, null, true); + } + + public pmOKCancelDialog(Frame f, String title, String msg, boolean ok) { + this(f, title, msg, null, null, ok); + } + + public pmOKCancelDialog(Frame f, String title, String msg, + pmTop t, String h) { + this(f, title, msg, t, h, true); + } + + public pmOKCancelDialog(Frame f, String title, String msg, + pmTop t, String h, boolean ok) { + super(f, title, true); // modal + + theTop = t; + theTag = h; + defaultIsOK = ok; + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.EAST; + + // top panel + JPanel p = new JPanel(); + p.setLayout(new GridBagLayout()); + + JLabel label = new JLabel(msg, SwingConstants.CENTER); + p.add(label, c); + + this.getContentPane().add(p, "Center"); + + this.getContentPane().add( + buttonPanel(defaultIsOK, theTop != null && theTag != null), + "South"); + + this.pack(); + + this.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + returnValue = JOptionPane.CLOSED_OPTION; + pmOKCancelDialog.this.setVisible(false); + } + }); + + if (defaultIsOK) { + // this.getRootPane().setDefaultButton(okButton); + okButton.setAsDefaultButton(); + okButton.requestFocus(); + } else { + // this.getRootPane().setDefaultButton(cancelButton); + cancelButton.setAsDefaultButton(); + cancelButton.requestFocus(); + } + + // handle Esc as cancel in any case + this.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + actionCancelButton(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + } + + public JPanel buttonPanel(boolean okDefault, boolean useHelp) { + JPanel panel = new JPanel(); + + panel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.gridheight = 1; + c.gridwidth = 1; + c.weightx = c.weighty = 0.0; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridy = 0; + + + if (okDefault) + c.gridx = 0; + else + c.gridx = 1; + + okButton = new pmButton( + pmUtility.getResource("OK")); + okButton.setMnemonic( + pmUtility.getIntResource("OK.mnemonic")); + + if (okDefault) + c.gridx = 1; + else + c.gridx = 0; + + cancelButton = new pmButton( + pmUtility.getResource("Cancel")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Cancel.mnemonic")); + + helpButton = null; + + if (useHelp) { + c.gridx = 2; + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + } + + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + actionOKButton(); + } + }); + + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + actionCancelButton(); + } + }); + + if (helpButton != null) { + helpButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + theTop.showHelpItem(theTag); + } + }); + } + + c.insets = new Insets(15, 15, 15, 15); + c.gridx = 0; + panel.add(okButton, c); + c.gridx = 1; + panel.add(cancelButton, c); + c.gridx = 2; + if (helpButton != null) + panel.add(helpButton, c); + + return panel; + } + + protected void actionOKButton() { + returnValue = JOptionPane.OK_OPTION; + pmOKCancelDialog.this.setVisible(false); + } + + protected void actionCancelButton() { + returnValue = JOptionPane.CANCEL_OPTION; + pmOKCancelDialog.this.setVisible(false); + } + + + + public int getValue() { + return returnValue; + } + + + public static void main(String[] args) { + JFrame f = new JFrame("Test Dialog"); + f.setSize(300, 100); + + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + System.exit(0); + } + }); + + f.setVisible(true); + + while (true) { + System.out.println("creating a new dialog instance..."); + pmOKCancelDialog d = + new pmOKCancelDialog( + null, "Dialog Test", "Some message.", false); + d.setVisible(true); + System.out.println("Dialog returns " + d.getValue()); + + d.dispose(); + + } + + } + + + pmButton helpButton = null; + pmButton okButton = null; + pmButton cancelButton = null; + + protected int returnValue = JOptionPane.CLOSED_OPTION; +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOther.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOther.java new file mode 100644 index 0000000000..d37ce9fa7b --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOther.java @@ -0,0 +1,233 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmOther.java + * + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * panel dialog which captures "other" + */ + +public class pmOther extends pmDialog { + + private pmTop theTop; + private String theTag; + pmButton okButton = null; + pmButton cancelButton = null; + pmButton helpButton = null; + + public pmOther(JFrame f, String title, String msg) { + this(f, title, msg, null, null); + } + + public pmOther(JFrame f, String title, String msg, pmTop t, String h) { + + super(f, title, true); // modal + + theTop = t; + theTag = h; + + JLabel l; + pmButton b; + JPanel p; + + Debug.message("CLNT:pmOther()"); + + // initialize constraints + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = 1; + c.gridheight = 1; + c.insets = new Insets(10, 10, 5, 10); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.HORIZONTAL; + c.weightx = 1.0; + + // top panel contains the message + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + l = new JLabel(msg, SwingConstants.LEFT); + p.add(l, c); + this.getContentPane().add(p, "North"); + + c.insets = new Insets(5, 10, 5, 10); + + // middle panel contains "other" text field + p = new JPanel(); + p.setLayout(new GridBagLayout()); + + deviceName.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okPressed(); + } + }); + + l.setLabelFor(deviceName); + + c.gridx = 1; + c.gridy = 0; + c.weightx = 1.0; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + + p.add(deviceName, c); + + c.gridy = GridBagConstraints.RELATIVE; + + this.getContentPane().add(p, "Center"); + + // bottom panel contains buttons + c.gridx = 0; + c.weightx = 1.0; + c.weighty = 0.0; + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(5, 10, 10, 10); + + JPanel thePanel = new JPanel(); + okButton = new pmButton( + pmUtility.getResource("OK")); + okButton.setMnemonic( + pmUtility.getIntResource("OK.mnemonic")); + thePanel.add(okButton, c); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okPressed(); + } + }); + + cancelButton = new pmButton( + pmUtility.getResource("Cancel")); + cancelButton.setMnemonic( + pmUtility.getIntResource("Cancel.mnemonic")); + thePanel.add(cancelButton, c); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + cancelPressed(); + } + }); + + if (theTop != null && theTag != null) { + helpButton = new pmButton( + pmUtility.getResource("Help")); + helpButton.setMnemonic( + pmUtility.getIntResource("Help.mnemonic")); + thePanel.add(helpButton, c); + helpButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + theTop.showHelpItem(theTag); + } + }); + } + + + this.getContentPane().add(thePanel, "South"); + + // lay out the dialog + this.pack(); + + this.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent evt) { + returnValue = JOptionPane.CLOSED_OPTION; + pmOther.this.setVisible(false); + } + }); + + // this.getRootPane().setDefaultButton(okButton); + okButton.setAsDefaultButton(); + + // handle Esc as cancel in any case + this.getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: default cancel action"); + cancelPressed(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + deviceName.requestFocus(); + + } + + public int getValue() { + return returnValue; + } + + + public void okPressed() { + Debug.message("CLNT:pmOther: " + deviceName.getText()); + returnValue = JOptionPane.OK_OPTION; + pmOther.this.setVisible(false); + } + + public void cancelPressed() { + Debug.message("CLNT:pmOther: cancelPressed"); + pmOther.this.dispose(); + } + + + public static void main(String[] args) { + JFrame f = new JFrame("Other test"); + + f.setSize(300, 100); + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + f.setVisible(true); + + while (true) { + pmOther d = new pmOther(f, "Test pmOther", "Enter Printer Port"); + d.setVisible(true); + + Debug.message("CLNT:pmOther: Dialog login returns " + d.getValue()); + + } + // System.exit(0); + } + + + public pmTextField deviceName = new pmTextField(30); + protected int returnValue = JOptionPane.CLOSED_OPTION; + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmPrinterExistsException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmPrinterExistsException.java new file mode 100644 index 0000000000..1912ab5f52 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmPrinterExistsException.java @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmPrinterExistsException.java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmPrinterExistsException extends pmGuiException { + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmResources.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmResources.java new file mode 100644 index 0000000000..658a122df9 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmResources.java @@ -0,0 +1,614 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * + * pmResources.java + * Localizable resource strings + */ + +package com.sun.admin.pm.client; + +import java.util.*; + +/* + * In accordance with the ResourceBundle pattern, + * each line in this file defines a tuple containing + * two strings: + * string 1 is the key used by the app -- DO NOT LOCALIZE + * string 2 is the string to be localized + * + * For example, in the tuple + * {"info_name", "Solaris Print Manager"} + * + * "info_name" is the resource key that must + * not be modified in any way + * + * "Solaris Print Manager" is the corresponding + * text to be localized + */ + +public class pmResources extends ListResourceBundle { + static final Object[][] pmBundlecontents = { + + /* + * Descriptive strings used in the 'About' dialog + */ + {"info_name", "Solaris Print Manager"}, + {"info_version", "Version 1.0"}, + {"info_authors", "Authors: Wendy Phillips"}, + + // Note: the copyright notice is displayed on two lines. + {"info_copyright1", "Copyright \251 "}, + /* JSTYLED */ + {"info_copyright2", " Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Sun, Sun Microsystems, the Sun logo and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Federal Acquisitions: Commercial Software - Government Users Subject to Standard License Terms and Conditions."}, + + + /* + * Main window title, the application name + */ + {"Solaris.Print.Manager", "Solaris Print Manager"}, + + + /* + * Main window column labels for printer list + */ + {"Printer.Name", "Printer Name"}, + {"Printer.Server", "Printer Server"}, + {"Description", "Description"}, + + + /* + * Main window menu titles and mnemonics + */ + {"Print.Manager", "Print Manager"}, + {"Print.Manager.mnemonic", "M"}, + + {"Printer", "Printer" }, + {"Printer.mnemonic", "P"}, + + {"Tools", "Tools" }, + {"Tools.mnemonic", "T"}, + + {"Help", "Help"}, + {"Help.mnemonic", "H"}, + + + /* + * Main window data labels + */ + {"Default.Printer:", "Default Printer:"}, + {"Domain:", "Domain:"}, + {"Host:", "Host:"}, + + + /* + * 'Printer Manager' menu item labels and mnemonics + */ + {"Select.Naming.Service", "Select Naming Service..."}, + {"Select.Naming.Service.mnemonic", "N"}, + + {"Show.Command-Line.Console", "Show Command-Line Console"}, + {"Show.Command-Line.Console.mnemonic", "L"}, + + {"Confirm.All.Actions", "Confirm All Actions"}, + {"Confirm.All.Actions.mnemonic", "C"}, + + {"Use.PPD.files", "Use PPD files"}, + {"Use.PPD.files.mnemonic", "U"}, + + {"Exit", "Exit"}, + {"Exit.mnemonic", "X"}, + + /* + * 'Printer' menu item labels and mnemonics + */ + {"Add.Access.to.Printer...", "Add Access to Printer..."}, + {"Add.Access.to.Printer.mnemonic", "A"}, + + {"New.Attached.Printer...", "New Attached Printer..."}, + {"New.Attached.Printer.mnemonic", "T"}, + + {"New.Network.Printer...", "New Network Printer..."}, + {"New.Network.Printer.mnemonic", "N"}, + + {"Modify.Printer.Properties...", "Modify Printer Properties..."}, + {"Modify.Printer.Properties.mnemonic", "M"}, + + {"Delete.Printer...", "Delete Printer..."}, + {"Delete.Printer.mnemonic", "D"}, + + + /* + * 'Tools' menu item labels + */ + {"Find.Printer", "Find Printer..."}, + {"Find.Printer.mnemonic", "F"}, + + + /* + * 'Help' menu item labels + */ + {"Overview", "Overview"}, + {"Overview.mnemonic", "O"}, + + {"On.Help", "On Help"}, + {"On.Help.mnemonic", "H"}, + + {"About.Print.Manager", "About Print Manager..."}, + {"About.Print.Manager.mnemonic", "A"}, + + + /* + * 'Select Naming Service' dialog title + */ + {"SPM:Select.Naming.Service", + "Solaris Print Manager: Select Naming Service"}, + + + /* + * 'Command-Line Console' dialog title + */ + {"SPM:Command-Line.Console", + "Solaris Print Manager: Command-Line Console"}, + + + /* + * 'Delete Printer' confirmation dialog title + */ + {"SPM:Delete.Printer", "Solaris Print Manager: Delete Printer"}, + + + /* + * 'Add Access to Printer' dialog title + */ + {"SPM:Add.Access.To.Printer", + "Solaris Print Manager: Add Access to Printer"}, + + + /* + * 'Add Attached Printer' dialog title + */ + {"SPM:New.Attached.Printer", + "Solaris Print Manager: New Attached Printer"}, + + + /* + * 'Add Network Printer' dialog title + */ + {"SPM:New.Network.Printer", + "Solaris Print Manager: New Network Printer"}, + + + /* + * 'Modify Printer Properties' dialog title + */ + {"SPM:Modify.Printer.Properties", + "Solaris Print Manager: Modify Printer Properties"}, + + + /* + * 'Find Printer' dialog title + */ + {"SPM:Find.Printer", "Solaris Print Manager: Find Printer"}, + + + /* + * 'Help' dialog title + */ + {"SPM:Help", "Solaris Print Manager: Help"}, + + + /* + * 'About Print Manager' dialog title + */ + {"About.Solaris.Print.Manager", "About Solaris Print Manager"}, + + + /* + * 'User Input of Printer Port' dialog title + */ + {"SPM:Specify.Printer.Port", + "Solaris Print Manager: Specify Printer Port"}, + + + /* + * 'User Input of Printer Type' dialog title + */ + {"SPM:Specify.Printer.Type", + "Solaris Print Manager: Specify Printer Type"}, + + + /* + * 'NIS Authentication' dialog title + */ + {"NIS.Authentication", "NIS Authentication"}, + + /* + * 'LDAP Authentication' dialog title + */ + {"LDAP.Authentication", "LDAP Authentication"}, + + + /* + * 'Action Confirmation' dialog title + */ + {"Action.Confirmation", "Action Confirmation"}, + + + /* + * Button labels and mnemonics + */ + {"Apply", "Apply"}, + {"Apply.mnemonic", "P"}, + + {"Cancel", "Cancel"}, + {"Cancel.mnemonic", "C"}, + + {"Clear", "Clear"}, + {"Clear.mnemonic", "L"}, + + {"Dismiss", "Dismiss"}, + {"Dismiss.mnemonic", "D"}, + + // {"Button Help", "Help"}, + // {"Button.Help.mnemonic", "H"}, + + {"OK", "OK"}, + {"OK.mnemonic", "O"}, + + {"Reset", "Reset"}, + {"Reset.mnemonic", "R"}, + + {"Find", "Find"}, + {"Find.mnemonic", "F"}, + + {"Show", "Show"}, + {"Show.mnemonic", "S"}, + + {"Forward", "Forward"}, + {"Forward.mnemonic", "W"}, + + {"Back", "Back"}, + {"Back.mnemonic", "B"}, + + {"Add", "Add"}, + {"Add.mnemonic", "A"}, + + {"Delete", "Delete"}, + {"Delete.mnemonic", "D"}, + + + /* + * Actions performed by the application + * as displayed in the Command-Line Console + */ + {"New.Attached.Printer", "New Attached Printer"}, + {"New.Network.Printer", "New Network Printer"}, + {"Modify.Printer.Properties", "Modify Printer Properties"}, + {"Delete.Printer", "Delete Printer"}, + {"Add.Access.To.Printer", "Add Access To Printer"}, + + + /* + * Prompts: messages to user describing required input. + */ + {"Enter.name.of.printer.to.find", + "Enter the name of a printer to find:"}, + {"Please.confirm.deletion.of.printer", + "Please confirm deletion of printer "}, + {"Enter.printer.type:", "Enter printer type:"}, + {"Enter.printer.port.or.file", "Enter printer port or file:"}, + + + /* + * 'Help' dialog tabbed-pane tab selection labels + */ + {"View", "View"}, + {"Index", "Index"}, + {"Search", "Search"}, + + + /* + * 'Help' dialog prompts, labels, and mnemonics + */ + {"Help.on:", "Help on:"}, + {"See.also:", "See also:"}, + + {"Matching.entries:", "Matching entries:"}, + {"Matching.entries:.mnemonic", "M"}, + + {"Search.help.index.for:", "Search help index for: "}, + {"Search.help.index.for:.mnemonic", "S"}, + + {"Search.Results:", "Search Results:"}, + {"Search.Results:.mnemonic", "R"}, + + {"Keywords:", "Keywords: "}, + {"Keywords:.mnemonic", "K"}, + + + /* + * 'Help' dialog descriptive messages to provide + * assistance in using the features. + */ + + /* + * The following two labels create one message, displayed on + * two adjacent lines. + */ + {"To.search.the.index...", + "To search the index of help articles alphabetically,"}, + {"type.your.query.below...", + "type your query below then select the desired article."}, + + /* + * The following two labels create one message, displayed on + * two adjacent lines. + */ + {"To.find.help.articles...", + "To find help articles about a particular topic,"}, + {"enter.keywords.below...", + "enter keywords below then press the Find button."}, + + + /* + * Prompts/labels on 'Install Printer' and 'Modify Printer' dialogs + */ + {"Printer.Name:", "Printer Name:"}, + {"Printer.Server:", "Printer Server:"}, + {"Description:", "Description:"}, + {"Printer.Port:", "Printer Port:"}, + {"Not.Selected", "Not Selected"}, + {"Printer.Type:", "Printer Type:"}, + {"Printer.Driver:", "Printer Driver:"}, + {"No.PPD.Files.Found", "No PPD files found"}, + {"Printer.Make:", "Printer Make:"}, + {"Printer.Model:", "Printer Model:"}, + {"No.Models.Found", "No Models Found"}, + {"File.Contents:", "File Contents:"}, + {"Fault.Notification:", "Fault Notification:"}, + {"Destination:", "Destination:"}, + {"Protocol:", "Protocol:"}, + {"Options:", "Options:"}, + {"Banner:", "Banner:"}, + {"Options.mnemonic", "O"}, + {"Option:", "Option:"}, + {"User.Access.List:", "User Access List:"}, + + + /* + * Combo item allowing custom 'Printer Port' selection + * See "Printer.Port:" above. + */ + {"Other...", "Other..."}, + + + /* + * Combo items specifying printer 'File Contents' + * See "File.Contents" above. + */ + {"PostScript", "PostScript"}, + {"ASCII", "ASCII"}, + {"None", "None"}, + {"Any", "Any"}, + {"Both.PostScript.and.ASCII", "Both PostScript and ASCII"}, + + + /* + * Combo items specifying 'Fault Notification' options. + * See "Fault.Notification" above. + */ + {"Write.to.Superuser", "Write to Superuser"}, + {"Mail.to.Superuser", "Mail to Superuser"}, + + + /* + * Labels for checkboxes used in 'Install Printer' and + * 'Modify Printer' dialogs + */ + {"Default.Printer", "Default Printer"}, + {"Always.Print.Banner", "Always Print Banner"}, + {"User.Selectable.Default.On", "User Selectable - Default=on"}, + {"Never.Print.Banner", "Never Print Banner"}, + + + /* + * Prompt for 'Select Naming Service' combo + */ + {"Naming.Service:", "Naming Service:"}, + + + /* + * Descriptive label for 'NIS Authentication' dialog + */ + {"Enter.NIS.authentication.data.", "Enter NIS authentication data."}, + + /* + * Descriptive label for 'LDAP Authentication' dialog + */ + {"Enter.LDAP.authentication.data.", "Enter LDAP authentication data."}, + + + /* + * Prompts and mnemonics for 'NIS Authentication' dialog + */ + {"Hostname:", "Hostname:"}, + {"Hostname.mnemonic", "H"}, + + {"Username:", "Username:"}, + {"Username.mnemonic", "U"}, + + {"Password:", "Password:"}, + {"Password.mnemonic", "P"}, + + /* + * Prompts for 'LDAP Authentication' dialog + */ + {"LDAP.Server:", "LDAP Server:"}, + {"Distinguished.Name:", "Distinguished Name:"}, + {"Password:", "Password:"}, + + + /* + * Error dialog titles + */ + {"Application.Error", "Application Error"}, + {"Unknown.Application.Error", "Unknown Application Error"}, + {"Command.Failed.Error", "Command Failed Error"}, + {"Error", "Error"}, + {"Warning", "Warning"}, + + + /* + * Error messages displayed to user + */ + {"Item.not.found:", "Item not found: "}, + {"No.information.available.", "No information available."}, + {"Unable.to.find.printer", "Unable to find printer "}, + {"Printer.delete.operation.failed.", + "Printer delete operation failed."}, + {"Invalid.printer.type.", "Invalid printer type."}, + {"Device.missing.or.not.writeable.", + "Device missing or not writeable."}, + {"Printer.name.required.", "Printer name required."}, + {"Printer.Port.Selection.required", "Printer Port Selection required."}, + {"Printer.Make.Selection.required", "Printer Make Selection required."}, + {"Printer.name.invalid.", "Printer name invalid."}, + {"Server.name.required.", "Server name required."}, + {"Server.name.invalid.", "Server name invalid."}, + {"User.Cancelled.Login", "User Cancelled Login"}, + {"Destination.required.", "Destination required."}, + {"User.Cancelled.Login", "User Cancelled Login"}, + {"Destination.invalid.", "Destination invalid."}, + {"Operation.Cancelled", "Operation Cancelled"}, + {"Login.Failure", "Login Failure"}, + {"Required.login.failed.", "Required login failed."}, + {"Login.Authorization.Failed", "Login Authorization Failed"}, + {"Cannot.modify.this.queue;ppdcache.file.missing.", + "Cannot modify this queue; ppdcache file missing."}, + {"Cannot.modify.this.queue;PPD.file.not.in.ppdcache.", + "Cannot modify this queue; PPD file not in ppdcache."}, + {"Request.cannot.be.completed.", "Request cannot be completed."}, + {"Could.not.get.local.hostname", "Could not get local hostname"}, + {"The.specified.printer.already.exists.", + "The specified printer already exists."}, + {"The.server.must.be.a.remote.server.", + "The server must be a remote server."}, + {"Required.login.failed.", "Required login failed."}, + {"Invalid.printer.type.", "Invalid printer type."}, + {"Invalid.username", "Invalid username"}, + {"Device.missing.or.not.writeable.", + "Device missing or not writeable."}, + {"User.cancelled.login.", "User cancelled login."}, + {"Nothing.matched.", "Nothing matched."}, + {"The.specified.printer.already.exists.", + "The specified printer already exists."}, + {"The.selected.printer.does.not.exist.", + "The selected printer does not exist."}, + {"User.not.authorized.to.modify.this.namespace.", + "User not authorized to modify this namespace."}, + {"Cannot.get.list.of.printers.Exiting.", + "Cannot get list of printers. Exiting."}, + {"LDAP.server.name.required.", + "LDAP Server Name required."}, + {"LDAP.Distinguished.name.required.", + "LDAP Distinguished Name required."}, + {"LDAP.Password.required.", + "LDAP Password required."}, + + + /* + * Prompts for 'Confirm Action' dialogs + */ + {"Continue.action.for.this.printer?", + "Continue action for this printer?"}, + {"Continue.creating.access.for.this.printer?", + "Continue creating access for this printer?"}, + + + /* + * The help subsystem builds a database of searchable + * keywords based in part on the title of each help + * article. In order to avoid excessive false hits, the + * following words are ignored when adding title words + * to the searchable keyword list. + * + * If this list is left empty, all the words in the title of + * each help article will be added to the keywords database. + */ + {"help.ignore.words", "to an a of if the and or"}, + + + + /* + * Title for the authorization dialog which is invoked by + * the printmgr executable. + */ + {"Authentication.required", "Authentication Required"}, + + /* + * Prompt for the printmgr authorization dialog. + * This is displayed with line breaks. + */ + /* JSTYLED */ + {"Root.access.is.required", "Root access is required for full functionality.\nYou may authenticate as root or continue\nwith limited functionality."}, + + /* + * Buttons for the authorization dialog. + */ + {"Authenticate", "Authenticate"}, + {"Authenticate.mnemonic", "A"}, + + {"Continue", "Continue"}, + {"Continue.mnemonic", "N"}, + + /* + * Title for the root password request dialog invoked by printmgr. + */ + {"Root.authentication", "Root Authentication"}, + + /* + * Prompt for the root password request dialog. + */ + {"Enter.root.password", "Enter root password"}, + + /* + * Prompt for the root password request dialog. + */ + {"Invalid.password", "Invalid password entered. Retry?"}, + + /* + * Just a placeholder, never used. + */ + {"dummy", ""} + }; + + public Object[][] getContents() { + return pmBundlecontents; + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmTextField.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmTextField.java new file mode 100644 index 0000000000..93a9b3e228 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmTextField.java @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmTextField.java + * Extension of JTextField which accepts only 8-bit-ASCII. + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.text.*; + +public class pmTextField extends JTextField { + public pmTextField(int n) { + this(null, n); + } + + public pmTextField(String s) { + this(s, 0); + } + + public pmTextField(String s, int n) { + super(s, n); + } + + protected Document createDefaultModel() { + return new pmFilterDoc(); + } + + /* + * This doc implementation will disallow insertion of a + * string containing any characters which are non-8-bit-ascii. + */ + private class pmFilterDoc extends PlainDocument { + public void insertString(int offset, String str, AttributeSet a) + throws BadLocationException { + int i, c; + char[] buf = str.toCharArray(); + + for (i = 0; i < buf.length; i++) { + c = (new Character(buf[i])).charValue(); + if (c > 0x00ff) + break; + } + if (i == buf.length) + super.insertString(offset, str, a); + else + Toolkit.getDefaultToolkit().beep(); + } + } + + public static void main(String args[]) { + JFrame f = new JFrame(); + f.getContentPane().add(new pmTextField(20)); + f.pack(); + f.setVisible(true); + f.repaint(); + } + +} + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmTop.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmTop.java new file mode 100644 index 0000000000..f6bfa2da6f --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmTop.java @@ -0,0 +1,1273 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmTop.java + * Top level + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.util.Vector; +import java.lang.*; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.table.AbstractTableModel; +import javax.swing.text.*; +import javax.swing.border.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * Top window for printer manager + */ + +public class pmTop extends JPanel { + + static private pmTop myTop = null; + static private pmHelpFrame helpFrame = null; + static private pmAboutBox aboutBox = null; + static private pmLogDisplay commandLog = null; + static private pmFindFrame findFrame = null; + + JLabel nameserviceLabel = new JLabel(); + JLabel domainhostLabel; + JLabel defaultpLabel; + String defaultPrinter; + JScrollPane scrollPane; + JTable listTable; + Host host = new Host(); + private JPanel north = new JPanel(); + JPanel center; + listTableModel listModel; + ListSelectionModel listSM; + + JMenuBar menuBar; + JFrame parentFrame; + JCheckBoxMenuItem logCheck; + JCheckBoxMenuItem confirmCheck; + JCheckBoxMenuItem usePPD; + JMenuItem modifyMenuItem = null; + JMenuItem deleteMenuItem = null; + + JMenuItem access; + JMenuItem local; + JMenuItem network; + + int actionindex = 0; + private String newNS; + NameService ns = null; + NameService nisns = null; + NameService systemns = null; + NameService nisplusns = null; + NameService ldapns = null; + + pmAccess accessView = null; + pmInstallPrinter localinstallView = null; + pmInstallPrinter networkinstallView = null; + pmDelete deleteView = null; + pmInstallPrinter modifyView = null; + pmLoad loadView = null; + + String clickedPrinter; + String selectedPrinter = null; + String selprinterServer = null; + int selectedRow = -1; + + String cmdLog = null; + String errorLog = null; + String warningLog = null; + + boolean runningAuth = false; + boolean isRoot = false; + + pmFrame frame; + + + public pmTop(JFrame parent) { + parentFrame = parent; + setLayout(new BorderLayout()); + pmTopInit(); + + } + + public void pmTopInit() { + + try { + systemns = new NameService("system"); + } catch (Exception e) { + Debug.message("CLNT: system:Nameservice exception " + e); + } + try { + nisns = new NameService("nis"); + } catch (Exception e) { + Debug.message("CLNT: nis:Nameservice exception " + e); + } + try { + nisplusns = new NameService("nisplus"); + } catch (Exception e) { + Debug.message("CLNT: nisplus:Nameservice exception " + e); + } + try { + ldapns = new NameService("ldap"); + } catch (Exception e) { + Debug.message("CLNT: ldap:Nameservice exception " + e); + } + + ns = systemns; + newNS = "files"; + + // determine root privileges + try { + ns.checkAuth(); + } catch (Exception ax) { + Debug.message("CLNT: checkAuth threw " + ax); + } + + if (ns.isAuth()) { + runningAuth = true; + isRoot = true; + Debug.message("CLNT: Running as root"); + } else + Debug.message("CLNT: Not running as root"); + + northPanel(); + centerPanel(); + southPanel(); + + } + + // Set values so that printer selection null + public void clearSelected() { + selectedPrinter = null; + selprinterServer = null; + selectedRow = -1; + enableEditMenuItems(false); + } + + + // Create north panel with GridBagLayout + public void northPanel() { + + menuBar = new JMenuBar(); + menuBar.setBorder(new EmptyBorder(5, 5, 5, 5)); + menuBar.add(appMenu()); + menuBar.add(objectMenu()); + menuBar.add(toolsMenu()); + menuBar.add(Box.createHorizontalGlue()); + menuBar.add(helpMenu()); + + parentFrame.setJMenuBar(menuBar); + } + + public class listTableModel extends AbstractTableModel { + int numColumns; + + String[] columnNames = { + pmUtility.getResource("Printer.Name"), + pmUtility.getResource("Printer.Server"), + pmUtility.getResource("Description") + + }; + + // Initialize for JTable calls from SWING classes + Vector data = new Vector(0, 0); + + public listTableModel() { + numColumns = getColumnCount(); + } + + public void insertlistTable(String rowDataList[], int numcols) { + Vector rowData = new Vector(3, 1); + data = new Vector(100, 5); + int j = 0; + + if ((rowDataList.length) <= 1) { + return; + } + + for (int i = 0; i < rowDataList.length; i = i + 3) { + rowData = new Vector(3, 1); + for (j = 0; j < 3; j++) { + rowData.addElement( + rowDataList[i + j]); + } + data.addElement(rowData); + } + } + + public void removeRow(int row) { + data.removeElementAt(row); + } + + public int getRowCount() { + return data.size(); + } + + public int getColumnCount() { + return columnNames.length; + } + + public String getColumnName(int col) { + return columnNames[col]; + } + + public Object getValueAt(int row, int col) { + Vector rowVector = (Vector)data.elementAt(row); + return rowVector.elementAt(col); + } + + public void setValueAt(String value, int row, int col) { + Vector rowVector = (Vector)data.elementAt(row); + rowVector.setElementAt(value, col); + } + + public void addRow(Vector row) { + data.addElement(row); + } + + public int findValue(String value) { + for (int i = 0; i < data.size(); i++) { + if (getValueAt(i, 0).equals(value)) + return i; + } + return -1; + } + + }; + + + // called on enter or double-click + void modifySelectedPrinter() { + + ListSelectionModel m = listTable.getSelectionModel(); + + if (m.isSelectionEmpty()) { + Debug.message("CLNT: list selection is empty"); + return; + } + + int selectedRow = m.getMinSelectionIndex(); + + Debug.message("CLNT: list row selected is " + selectedRow); + + selectedPrinter = + (String) listTable.getModel().getValueAt(selectedRow, 0); + selprinterServer = + (String)listTable.getModel().getValueAt(selectedRow, 1); + + Debug.message("CLNT: selectedPrinter is " + selectedPrinter); + + doModify(); + } + + + // Create printer list in center panel + public void centerPanel() { + + center = new JPanel(); + + listModel = new listTableModel(); + listTable = new JTable(listModel); + listTable.setColumnSelectionAllowed(false); + listTable.setRowSelectionAllowed(true); + listTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listTable.setShowGrid(false); + listTable.registerKeyboardAction(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: enter action"); + if (runningAuth) + modifySelectedPrinter(); + else + Toolkit.getDefaultToolkit().beep(); + }}, + KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), + JComponent.WHEN_IN_FOCUSED_WINDOW); + + + listTable.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + Point pt = e.getPoint(); + int rowIndex = listTable.rowAtPoint(pt); + int colIndex = listTable.columnAtPoint(pt); + int clickCount = e.getClickCount(); + + Debug.message("CLNT: getClickCount() is " + clickCount); + + if (clickCount == 2) { + if (rowIndex == -1) { + Debug.message("CLNT: clicked outside table"); + } else { + if (runningAuth) + modifySelectedPrinter(); + else + Toolkit.getDefaultToolkit().beep(); + } + } + } + }); + + // Add selection listener + ListSelectionModel rowSelectModel = listTable.getSelectionModel(); + + rowSelectModel.addListSelectionListener(new ListSelectionListener() { + + public void valueChanged(ListSelectionEvent e) { + + listSM = (ListSelectionModel)e.getSource(); + Debug.message("CLNT: listSM is " + listSM); + + if (listSM.isSelectionEmpty()) { + Debug.message("CLNT: list selection is empty"); + enableEditMenuItems(false); + } else { + selectedRow = listSM.getMinSelectionIndex(); + Debug.message( + "CLNT: list element selected" + selectedRow); + selectedPrinter = + (String)listTable.getModel().getValueAt(selectedRow, 0); + selprinterServer = + (String)listTable.getModel().getValueAt(selectedRow, 1); + Debug.message( + "CLNT: selectedPrinter is " + selectedPrinter); + enableEditMenuItems(true); + } + } + }); + + GridBagConstraints c = new GridBagConstraints(); + center.setLayout(new BorderLayout()); + + c.insets = new Insets(35, 50, 35, 50); + + try { + listModel.insertlistTable(PrinterUtil.getPrinterList(ns), + listModel.getColumnCount()); + } catch (Exception e) { + Debug.fatal("CLNT: pmTop:getPrinterList() caught " + e); + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Cannot.get.list.of.printers.Exiting."), + myTop, + "getPrinterListFailed"); + m.setVisible(true); + System.exit(-1); + } + + scrollPane = new JScrollPane(); + scrollPane.setViewportView(listTable); + + listTable.setPreferredScrollableViewportSize( + new Dimension(500, 500)); + scrollPane.getViewport().setView(listTable); + center.add(scrollPane); + add("Center", center); + } + + // Create south panel with grid layout + + public void southPanel() { + JPanel south = new JPanel(); + GridBagConstraints c = new GridBagConstraints(); + south.setLayout(new GridBagLayout()); + + // Constraints applied across all entries + c.fill = GridBagConstraints.BOTH; + c.insets = new Insets(6, 6, 6, 6); + c.gridheight = 1; + c.gridwidth = 1; + c.gridy = 1; + + // Create the labels + c.gridx = 0; + c.weightx = c.weighty = 1.0; + + try { + defaultpLabel = + new JLabel(pmUtility.getResource("Default.Printer:") + + " " + PrinterUtil.getDefaultPrinter(ns)); + + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getDefaultPrinter() caught " + e); + defaultpLabel = new JLabel( + pmUtility.getResource("Default.Printer:")); + } + + south.add(defaultpLabel, c); + + + if (newNS.startsWith("files")) { + try { + domainhostLabel = new JLabel(pmUtility.getResource( + "Host:") + " " + host.getLocalHostName()); + + nameserviceLabel.setText(" "); + + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getLocalHostName caught " + e); + } + + } else { + try { + nameserviceLabel.setText( + pmUtility.getResource("Naming.Service:") + " " + newNS); + domainhostLabel = new JLabel( + pmUtility.getResource("Domain:") + " " + + host.getDomainName()); + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getDomainName caught " + e); + } + } + + c.weightx = c.weighty = 1.0; + c.gridx = 2; + south.add(nameserviceLabel, c); + c.gridx = 3; + south.add(domainhostLabel, c); + add("South", south); + } + + + public JMenu appMenu() { + // name service + // --- + // cmd line console + // confirm all actions + // use ppd file + // --- + // exit + + JMenu appMenu = new JMenu(pmUtility.getResource("Print.Manager")); + appMenu.setMnemonic( + pmUtility.getIntResource("Print.Manager.mnemonic")); + + appMenu.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + Debug.message("CLNT: appMenu MouseListener"); + if (pmMisc.isppdCachefile()) { + usePPD.setEnabled(true); + } else { + usePPD.setEnabled(false); + } + }; + }); + + + JMenuItem load = new JMenuItem( + pmUtility.getResource("Select.Naming.Service"), + pmUtility.getIntResource("Select.Naming.Service.mnemonic")); + + load.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from load action"); + if (loadView != null) + loadView.setVisible(true); + else + loadView = new pmLoad(myTop); + loadView.Show(); + + }; + }); + load.setEnabled(true); + appMenu.add(load); + + appMenu.addSeparator(); + + logCheck = new JCheckBoxMenuItem( + pmUtility.getResource("Show.Command-Line.Console")); + logCheck.setMnemonic( + pmUtility.getIntResource("Show.Command-Line.Console.mnemonic")); + + logCheck.addActionListener(new AbstractAction() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from checkbox action"); + JCheckBoxMenuItem c = (JCheckBoxMenuItem) e.getSource(); + if (c.isSelected() == true) { + commandLog.setVisible(true); + } else { + commandLog.setVisible(false); + } + } + }); + + if (!runningAuth) + logCheck.setEnabled(false); + + appMenu.add(logCheck); + + confirmCheck = new JCheckBoxMenuItem( + pmUtility.getResource("Confirm.All.Actions"), false); + confirmCheck.setMnemonic( + pmUtility.getIntResource("Confirm.All.Actions.mnemonic")); + if (!runningAuth) + confirmCheck.setEnabled(false); + + appMenu.add(confirmCheck); + + usePPD = new JCheckBoxMenuItem( + pmUtility.getResource("Use.PPD.files"), true); + usePPD.setMnemonic(pmUtility.getIntResource("Use.PPD.files.mnemonic")); + + if (!runningAuth) + usePPD.setEnabled(false); + appMenu.add(usePPD); + + appMenu.addSeparator(); + + JMenuItem exit = new JMenuItem( + pmUtility.getResource("Exit"), + pmUtility.getIntResource("Exit.mnemonic")); + + exit.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from exit action"); + System.exit(0); + }; + }); + + exit.setEnabled(true); + appMenu.add(exit); + return appMenu; + } + + // disable everything is not running as root + public JMenu objectMenu() { + // add access to printer... + // --- + // new local printer... + // new network printer... + // --- + // delete printer + // modify properties... + + JMenu objectMenu = new JMenu( + pmUtility.getResource("Printer")); + + objectMenu.setMnemonic( + pmUtility.getIntResource("Printer.mnemonic")); + + access = new JMenuItem( + pmUtility.getResource("Add.Access.to.Printer..."), + pmUtility.getIntResource("Add.Access.to.Printer.mnemonic")); + + access.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from access action"); + if (accessView != null) + accessView.setVisible(true); + else + accessView = new pmAccess(myTop); + accessView.Show(); + }; + }); + + if (!runningAuth) + access.setEnabled(false); + + objectMenu.add(access); + objectMenu.addSeparator(); + + local = new JMenuItem( + pmUtility.getResource("New.Attached.Printer..."), + pmUtility.getIntResource("New.Attached.Printer.mnemonic")); + + local.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from localinstall action"); + if (localinstallView != null) + localinstallView.setVisible(true); + else { + try { + localinstallView = new pmInstallPrinter( + myTop, Constants.ADDLOCAL); + } catch (Exception ex) { + Debug.message("CLNT:pmTop:caught exception" + ex); + } + } + localinstallView.Show(); + }; + }); + + if (!runningAuth) + local.setEnabled(false); + + objectMenu.add(local); + + network = new JMenuItem( + pmUtility.getResource("New.Network.Printer..."), + pmUtility.getIntResource("New.Network.Printer.mnemonic")); + + network.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from networkinstall action"); + if (networkinstallView != null) + networkinstallView.setVisible(true); + else { + try { + networkinstallView = new + pmInstallPrinter(myTop, Constants.ADDNETWORK); + } catch (Exception ex) { + Debug.message("CLNT:pmTop:caught exception" + ex); + } + } + + networkinstallView.Show(); + }; + }); + + if (!runningAuth) + network.setEnabled(false); + + objectMenu.add(network); + objectMenu.addSeparator(); + + modifyMenuItem = new JMenuItem( + pmUtility.getResource("Modify.Printer.Properties..."), + pmUtility.getIntResource("Modify.Printer.Properties.mnemonic")); + + modifyMenuItem.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + + Debug.message("CLNT: Modify " + selectedPrinter); + Debug.message("CLNT: Modify " + selprinterServer); + + doModify(); + }; + }); + + modifyMenuItem.setEnabled(false); + objectMenu.add(modifyMenuItem); + + deleteMenuItem = new JMenuItem( + pmUtility.getResource("Delete.Printer..."), + pmUtility.getIntResource("Delete.Printer.mnemonic")); + + deleteMenuItem.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from delete action"); + if (selectedPrinter == null) { + Debug.warning("CLNT: selectedPrinter is null"); + Debug.message("CLNT: cannot call pmDelete"); + // show error window + } else { + deleteView = new pmDelete(myTop); + } + }; + }); + deleteMenuItem.setEnabled(false); + objectMenu.add(deleteMenuItem); + return objectMenu; + } + + // returns true iff name was found in the printer list + public boolean findPrinterInList(String name) { + + int row = -1; + + try { + String p = name.trim(); + row = listModel.findValue(p); + } catch (Exception ee) { + Debug.warning("CLNT: pmTop:find ActionList: caught " + ee); + } + + if (row != -1) { + selectedRow = row; + listTable.clearSelection(); + listTable.setRowSelectionInterval(row, row); + listTable.scrollRectToVisible(listTable.getCellRect(row, 0, true)); + listTable.revalidate(); + scrollPane.revalidate(); + scrollPane.repaint(); + } + return row != -1; + } + + public JMenu toolsMenu() { + + // find printer... + JMenu toolsMenu = new JMenu( + pmUtility.getResource("Tools")); + toolsMenu.setMnemonic( + pmUtility.getIntResource("Tools.mnemonic")); + + JMenuItem find = new JMenuItem( + pmUtility.getResource("Find.Printer"), + pmUtility.getIntResource("Find.Printer.mnemonic")); + find.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from find action"); + findFrame.setVisible(true); + } + }); + + toolsMenu.add(find); + return toolsMenu; + } + + // Create help Menu + + public JMenu helpMenu() { + JMenu helpMenu = new JMenu(pmUtility.getResource("Help")); + helpMenu.setMnemonic(pmUtility.getIntResource("Help.mnemonic")); + + JMenuItem ov = new JMenuItem( + pmUtility.getResource("Overview"), + pmUtility.getIntResource("Overview.mnemonic")); + ov.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + myTop.showHelpItem("Overview"); + }; + }); + + helpMenu.add(ov); + + JMenuItem on = new JMenuItem( + pmUtility.getResource("On.Help"), + pmUtility.getIntResource("On.Help.mnemonic")); + on.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + myTop.showHelpItem("HelpOnHelp"); + }; + }); + + helpMenu.add(on); + helpMenu.addSeparator(); + + JMenuItem about = new JMenuItem( + pmUtility.getResource("About.Print.Manager"), + pmUtility.getIntResource("About.Print.Manager.mnemonic")); + about.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Debug.message("CLNT: call from about help action"); + aboutBox.setVisible(true); + }; + }); + + helpMenu.add(about); + return helpMenu; + } + + public void actionPerformed(java.awt.event.ActionEvent e) { + } + + public void doModify() { + + if (modifyView != null) + modifyView.pmScreendispose(); + + try { + + if (selectedPrinter == null || selprinterServer == null) { + + } else { + + if ((host.getLocalHostName()).equals(selprinterServer)) { + + if (isNetwork()) { + modifyView = new + pmInstallPrinter( + myTop, Constants.MODIFYNETWORK); + } else { + modifyView = new + pmInstallPrinter( + myTop, Constants.MODIFYATTACHED); + } + + modifyView.Show(); + + } else { + + try { + modifyView = new pmInstallPrinter( + myTop, Constants.MODIFYREMOTE); + } catch (Exception e) { + Debug.message( + "CLNT:pmTop:caught exception" + e); + } + modifyView.Show(); + } + } + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getLocalHostName() caught " + e); + } + } // doModify() + + + public boolean isNetwork() { + + Printer newpr = new Printer(myTop.ns); + newpr.setPrinterName(selectedPrinter); + + try { + newpr.getPrinterDetails(); + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getPrinterDetails() caught " + e); + } + + pmCalls.debugShowPrinter(newpr); + + if (newpr.getDestination() != null) { + Debug.message("CLNT: isNetwork:getDestination " + + newpr.getDestination()); + return true; + } else { + Debug.message("CLNT: isNetwork:getDestination is null"); + return false; + } + } + + // Set the new namespace + public void pmsetNS() { + + String serverNS; + + // translate from gui to server + if (newNS.startsWith("files")) { + serverNS = new String("system"); + } else if (newNS.equals("NIS")) { + serverNS = new String("nis"); + } else if (newNS.equals("NIS+")) { + serverNS = new String("nisplus"); + } else if (newNS.equals("LDAP")) { + serverNS = new String("ldap"); + } else + serverNS = new String("system"); + + Debug.message("CLNT: newNS: " + newNS + + "\n serverNS: " + serverNS + + "\n ns.getNameService(): " + ns.getNameService()); + + if (!serverNS.equals(ns.getNameService())) { + + if (newNS.startsWith("files")) { + ns = systemns; + } else if (newNS.equals("NIS")) { + ns = nisns; + } else if (newNS.equals("NIS+")) { + ns = nisplusns; + } else if (newNS.equals("LDAP")) { + ns = ldapns; + } else + ns = systemns; + } + + // This tool is read-only unless the user is root on the + // print server. Thus, don't check for namespace authorization + // if user is not root. + + if (isRoot) { + // Check if user is authorized with this nameservice + if (ns.isAuth()) { + runningAuth = true; + } else { + // nis/ldap is a special case + // need to login to nis/ldap server + if (ns.getNameService().equals("nis") == true || + ns.getNameService().equals("ldap") == true) { + + try { + if (!ns.isAuth()) { + pmUtility.doLogin(myTop, loadView.frame); + runningAuth = true; + } + } catch (pmUserCancelledException e) { + Debug.message( + "CLNT:pmTop:user cancelled login"); + runningAuth = false; + } catch (pmGuiException e) { + Debug.message( + "CLNT:pmTop:login nis/ldap failed: " + e); + runningAuth = false; + pmMessageDialog m = new pmMessageDialog( + loadView.frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Required.login.failed."), + myTop, + "LoginFailed"); + m.setVisible(true); + } catch (Exception e) { + Debug.message( + "CLNT:pmTop:login nis/nis+/ldap failed: " + e); + runningAuth = false; + pmMessageDialog m = new pmMessageDialog( + loadView.frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "Required.login.failed."), + myTop, + "LoginFailed"); + m.setVisible(true); + } + } else { + try { + ns.checkAuth(); + runningAuth = true; + } catch (Exception ca) { + runningAuth = false; + pmMessageDialog m = new pmMessageDialog( + loadView.frame, + pmUtility.getResource("Error"), + pmUtility.getResource( + "User.not.authorized.to.modify.this.namespace."), + myTop, + "AuthorizationFailed"); + m.setVisible(true); + } + } + } + + if (!serverNS.equals(ns.getNameService())) { + deleteAllScreens(); + } + + // Change front panel as unauthorized to modify + if (!runningAuth) { + logCheck.setEnabled(false); + confirmCheck.setEnabled(false); + usePPD.setEnabled(false); + access.setEnabled(false); + local.setEnabled(false); + network.setEnabled(false); + modifyMenuItem.setEnabled(false); + deleteMenuItem.setEnabled(false); + } else { + logCheck.setEnabled(true); + confirmCheck.setEnabled(true); + access.setEnabled(true); + local.setEnabled(true); + network.setEnabled(true); + if (pmMisc.isppdCachefile()) + usePPD.setEnabled(true); + else + usePPD.setEnabled(false); + + } + + } else { + runningAuth = false; + } + + + Debug.message("CLNT: NEW ns.getNameService(): " + + ns.getNameService()); + + } + + class topnsListener implements ItemListener { + public topnsListener() {} + + public void itemStateChanged(ItemEvent e) { + Debug.message("CLNT: hello from topnsListener" + e.getItem()); + if (e.getStateChange() == ItemEvent.SELECTED) { + newNS = (String)e.getItem(); + } + } + } + + public void pmsetdefaultpLabel() { + try { + defaultpLabel.setText( + pmUtility.getResource("Default.Printer:") + + " " + PrinterUtil.getDefaultPrinter(ns)); + + Debug.message( + "CLNT: pmTop:pmsetdefaultpLabel(): default printer: " + + PrinterUtil.getDefaultPrinter(ns)); + + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getDefaultPrinter() caught " + e); + } + } + + public boolean getLogOption() { + return logCheck.getState(); + } + + public void setLogOption(boolean val) { + logCheck.setState(val); + } + + public boolean getConfirmOption() { + return confirmCheck.getState(); + } + + public boolean getUsePPD() { + return usePPD.getState(); + } + + public void doFind(String printer) { + } + + public void deleteAllScreens() { + + if (accessView != null) + accessView.pmScreendispose(); + accessView = null; + + if (localinstallView != null) + localinstallView.pmScreendispose(); + localinstallView = null; + + if (networkinstallView != null) + networkinstallView.pmScreendispose(); + networkinstallView = null; + + if (modifyView != null) + modifyView.pmScreendispose(); + modifyView = null; + + if (loadView != null) + loadView.pmScreendispose(); + loadView = null; + } + + + /* + * enable/disable modify and delete items + * this must be called when: + * . an existing printer is selected + * . the selection is disabled + */ + void enableEditMenuItems(boolean state) { + if (!runningAuth) + return; + modifyMenuItem.setEnabled(state); + deleteMenuItem.setEnabled(state); + } + + /* + * set the log/error state for the current operation + */ + void setLogData(String cmd, String err, String warn) { + cmdLog = cmd; + errorLog = err; + warningLog = warn; + } + + /* + * display current log state for the specified action + * if the cmdLog is empty nothing at all will be displayed! + */ + void showLogData(String actionName) { + + // Debug.info("CLNT: showLogData():actionName: " + actionName); + // Debug.info("CLNT: showLogData():cmdLog: " + cmdLog); + + if (cmdLog == null) + return; + + addToCommandLog(actionName + "\n"); + + // iterate over multiline cmds + StringTokenizer st = new StringTokenizer( + cmdLog, "\n\r", false); + while (st.hasMoreTokens()) { + addToCommandLog("% " + st.nextToken()); + addToCommandLog("\n"); + } + + if (errorLog != null) { + st = new StringTokenizer(errorLog, "\n\r", false); + while (st.hasMoreTokens()) { + addToCommandLog(st.nextToken()); + addToCommandLog("\n"); + } + } + + if (warningLog != null) { + st = new StringTokenizer(warningLog, "\n\r", false); + while (st.hasMoreTokens()) { + addToCommandLog(st.nextToken()); + addToCommandLog("\n"); + } + } + + addToCommandLog("***\n"); + } + + private void addToCommandLog(String s) { + commandLog.addText(s); + } + + public void showHelpItem(String tag) { + if (helpFrame != null) + helpFrame.showHelp(tag); + else + Toolkit.getDefaultToolkit().beep(); + } + + public void pmsetNSLabel() { + + if (newNS.startsWith("files")) { + + nameserviceLabel.setText(" "); + Debug.message("CLNT: pmsetNSLabel:nameserviceLabel is : " + + nameserviceLabel.getText()); + + try { + domainhostLabel.setText( + pmUtility.getResource("Host:") + " " + + host.getLocalHostName()); + } catch (Exception e) { + Debug.warning( + "CLNT: pmTop:getLocalHostName caught " + e); + } + + } else { + nameserviceLabel.setText( + pmUtility.getResource("Naming.Service:") + newNS); + Debug.message( + "CLNT: pmsetNSLabel:nameserviceLabel is : " + + nameserviceLabel.getText()); + + try { + domainhostLabel.setText( + pmUtility.getResource("Domain:") + " " + + host.getDomainName()); + } catch (Exception e) { + Debug.warning( + "CLNT: pmTop:getDomainName caught " + e); + } + } + } + + // Update the list of printers + // Printer list will change if nameservice changes and when user + // adds/deletes/changes printers + + public void pmsetPrinterList() { + + Debug.message("CLNT: pmsetPrinterList() ns is :" + + ns.getNameService()); + + try { + listModel.insertlistTable(PrinterUtil.getPrinterList(ns), + listModel.getColumnCount()); + } catch (Exception e) { + Debug.warning("CLNT: pmTop:getPrinterList() caught " + e); + } + + listTable.clearSelection(); + scrollPane.getViewport().setView(listTable); + scrollPane.revalidate(); + scrollPane.repaint(); + } + + + // returns -1 if error, 0 otherwise + protected static int parseArgs(String[] args) { + int rv = 0; + + for (int i = 0; i < args.length; ++i) { + if (args[i].compareTo("-debugall") == 0) + Debug.setDebugLevel(Debug.ALL); + else if (args[i].compareTo("-debugnone") == 0) + Debug.setDebugLevel(Debug.NONE); + else if (args[i].compareTo("-debugwarn") == 0) + Debug.setDebugLevel(Debug.WARNING); + else if (args[i].compareTo("-debugerr") == 0) + Debug.setDebugLevel(Debug.ERROR); + else if (args[i].compareTo("-debugfatal") == 0) + Debug.setDebugLevel(Debug.FATAL); + else if (args[i].compareTo("-debugmsg") == 0) + Debug.setDebugLevel(Debug.MESSAGE); + else if (args[i].compareTo("-debuginfo") == 0) + Debug.setDebugLevel(Debug.INFO); + } + + return rv; + } + + public static void main(String[] args) { + + if (parseArgs(args) < 0) + System.exit(-1); + + // use pmFrame to get app icon + pmFrame frame = new pmFrame(pmUtility.getResource("info_name")); + + myTop = new pmTop(frame); + + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + frame.getContentPane().add("Center", myTop); + frame.pack(); + frame.setVisible(true); + frame.repaint(); + + pmLoad firstload = new pmLoad(myTop); + myTop.loadView = firstload; + firstload.Show(); + + aboutBox = new pmAboutBox(); + commandLog = new pmLogDisplay(myTop, "ShowCommandConsole"); + findFrame = new pmFindFrame(myTop); + + /* + * Make sure to open the help frame after the about box, + * command log, and find frame windows have been opened. + * Otherwise it might cause null pointer exceptions as it + * takes a long time for the help frame to load. + */ + helpFrame = new pmHelpFrame(); + + } + + // disable Enter action **for all JTextFields** + static { + JTextField f = new JTextField(); + KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); + Keymap map = f.getKeymap(); + map.removeKeyStrokeBinding(enter); + } + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmUserCancelledException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmUserCancelledException.java new file mode 100644 index 0000000000..a6ccb9dd68 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmUserCancelledException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmUserCancelledException .java + * + */ + +package com.sun.admin.pm.client; + +import java.lang.*; + +class pmUserCancelledException extends pmGuiException { + public pmUserCancelledException(String s) { + super(s); + } + public pmUserCancelledException() { + super(); + } +} + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmUtility.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmUtility.java new file mode 100644 index 0000000000..09a34ab396 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmUtility.java @@ -0,0 +1,217 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * pmUtility.java + * Resource loading and utility classes + */ + +package com.sun.admin.pm.client; + +import java.awt.*; +import java.applet.*; +import java.io.*; +import java.util.*; +import javax.swing.*; + +import com.sun.admin.pm.server.*; + + +/* + * Utility class to provide common functions to the printing + * manager classes + */ + +public class pmUtility { + +/* + * Gets the localized string from the named bundle + */ + + public static String getCopyrightResource(String key) { + String keyvalue = null; + ResourceBundle bundle = null; + + + try { + bundle = ResourceBundle.getBundle( + "com.sun.admin.pm.client.pmCopyright"); + } catch (MissingResourceException e) { + Debug.fatal("Could not load pmCopyright file"); + } + + try { + keyvalue = bundle.getString(key); + } catch (MissingResourceException e) { + Debug.error("CLNT: getCopyrightResource: Missing: " + key); + keyvalue = new String("<<" + key + ">>"); + } + + return keyvalue; + } + + public static String getResource(String key) { + String keyvalue = null; + ResourceBundle bundle = null; + + + try { + bundle = ResourceBundle.getBundle( + "com.sun.admin.pm.client.pmResources"); + } catch (MissingResourceException e) { + Debug.fatal("Could not load pmResources file"); + } + + try { + keyvalue = bundle.getString(key); + } catch (MissingResourceException e) { + Debug.error("CLNT: getResource: Missing: " + key); + keyvalue = new String("<<" + key + ">>"); + } + + return keyvalue; + } + + public static int getIntResource(String key) { + int keyvalue = 0; + String s = null; + ResourceBundle bundle = null; + + try { + bundle = ResourceBundle.getBundle( + "com.sun.admin.pm.client.pmResources"); + } catch (MissingResourceException e) { + Debug.fatal("Could not load pmResources file"); + } + + try { + s = bundle.getString(key); + } catch (MissingResourceException e) { + Debug.error("Missing: " + key); + } + + Debug.message("Resource: " + key + " Value: " + s); + + if (s != null) { + try { + keyvalue = s.charAt(0); + } catch (Exception x) { + Debug.error("Resource: " + key + " threw: " + x); + } + } + + return keyvalue; + } + + public static void doLogin( + pmTop mytop, JFrame frame) throws pmGuiException { + + pmLogin l; + + if (mytop.ns.getNameService().equals("nis") || + mytop.ns.getNameService().equals("ldap")) { + + if (mytop.ns.getNameService().equals("nis")) { + + l = new pmLogin( + frame, + pmUtility.getResource("NIS.Authentication"), + pmUtility.getResource("Enter.NIS.authentication.data."), + mytop, + "NISAuthentication"); + + } else { // LDAP + + l = new pmLogin( + frame, + pmUtility.getResource("LDAP.Authentication"), + pmUtility.getResource("Enter.LDAP.authentication.data."), + mytop, + "LDAPAuthentication"); + } + + l.setVisible(true); + + if ((l.getValue() != JOptionPane.OK_OPTION) && + (l.getValue() != JOptionPane.CANCEL_OPTION)) { + + pmMessageDialog m = new pmMessageDialog( + frame, + pmUtility.getResource("Login.Failure"), + pmUtility.getResource( + "Request.cannot.be.completed.")); + m.setVisible(true); + throw new pmGuiException + ("pmAccess: Cannot create Login screen"); + } + + + if (l.getValue() == JOptionPane.CANCEL_OPTION) { + throw new pmUserCancelledException("User.Cancelled.Login"); + } else { + + // Pass data to backend + + // getPassword sends back untrimmed string that is invalid + // as a password as it's too long + String tmpp = new String(l.passwordField.getPassword()); + mytop.ns.setPasswd(tmpp.trim()); + + if (mytop.ns.getNameService().equals("ldap")) { + // setUser for binddn + mytop.ns.setUser(l.dnField.getText()); + // setNameServiceHost overloaded for LDAP server name + mytop.ns.setNameServiceHost(l.serverField.getText()); + } + + try { + mytop.ns.checkAuth(); + Debug.message("doLogin():checkauth() OK"); + } catch (Exception e) { + Debug.warning("doLogin:checkAuth()exception " + e); + throw new pmGuiException("Login.Authorization.Failed"); + } + } + + + // User has not put in printer or server + } else { + pmMessageDialog m = + new pmMessageDialog( + frame, + pmUtility.getResource("Login.Failure"), + pmUtility.getResource("Request.cannot.be.completed."), + mytop, "LoginFailed"); + + m.setVisible(true); + throw new pmGuiException("pmAccess: Cannot create Login screen"); + } + + } + + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pm_gen_copyright b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pm_gen_copyright new file mode 100644 index 0000000000..0f8310dd38 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pm_gen_copyright @@ -0,0 +1,64 @@ +#!/usr/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# This script generates the pmCopyright.java file +# which contains the copyright data needed by +# the Solaris Print Manager. The pmCopyright.java +# file is generated during a make in order to update +# the copyright with the correct date info, eliminating +# the need to update the copyright notice with every +# release. + +PMFILE=pmCopyright.java +DATE=`/usr/bin/date '+%Y'` + +/usr/bin/rm -f ${PMFILE} +/usr/bin/cat > ${PMFILE} <<END +/* + * GENERATED CODE + * + * Copyright ${DATE} Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +package com.sun.admin.pm.client; +import java.util.*; + +public class pmCopyright extends ListResourceBundle { + static final Object[][] pmHelpBundlecontents = { + + {"copyright_year", "1999-${DATE}"}, + {"dummy", ""} + }; + + public Object[][] getContents() { + return pmHelpBundlecontents; + } +} +END diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddAccess.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddAccess.rawhlp new file mode 100644 index 0000000000..9030aef3c8 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddAccess.rawhlp @@ -0,0 +1,100 @@ +<TITLE> Dialog: Add Access to Printer</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=AddAccess --> + +<CONTENT> + +<p> + +Use the Add Access to Printer dialog to make an installed printer +accessible to print client computers. See the printers.conf(4) man +page if you need more information about print client commands. + +<p> + +<b>Printer Name:</b> The name of the printer you wish to add access +to. The printer name must be a text string composed of uppercase or +lowercase alphabetical characters (a-z, A-Z), digits (0-9), hyphens, or +underscores. A printer name can be a maximum of 14 characters long. +<p> + +<b>Printer Server:</b> The name of the printer server the named printer is +installed on. The printer may be physically connected to +the server or it may be a network printer. + +<p> + +<b>NOTE:</b> Solaris Print Manager does not check for the validity of +Printer Name or Printer Server. + +<p> + +<b>Description:</b> [Optional] A description of the printer, including, +for example, the type and location of the printer. +<p> + +<b>Option: Default Printer:</b> If checked and no naming service is +being used, this printer is designated as the default printer for the +computer on which you are running Solaris Print Manager. If checked +and a naming service is being used, designates this as the default +printer for the naming service. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> + +</CONTENT> + +<KEYWORDS> +access "add access" description "default printer" "naming service" +"printer name" "printer server" dialog: add printer +</KEYWORDS> + +<p> + +<SEEALSO> +ToAddAccess +ToModify +ToDelete +ToInstallLocal +ToInstallNetwork +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddAccessFailed.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddAccessFailed.rawhlp new file mode 100644 index 0000000000..b0153bb465 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddAccessFailed.rawhlp @@ -0,0 +1,62 @@ +<TITLE> If Add Access Fails</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=AddAccessFailed --> + +<CONTENT> + +<p> + +You must enter a printer name and a printer server name; the printer +server must be a remote server (not the current server). See the man +page for lpadmin(1M) for more information. + +<p> + +Display the Command-Line Console to help pinpoint where the error +may have occurred. Choose Show Command-Line Console from the Print +Manager menu to display the Command-Line Console. + +</CONTENT> + +<p> + +<KEYWORDS> +add access fail failure fails +</KEYWORDS> + +<p> + +<SEEALSO> +AddAccess +ToAddAccess +ToShowCommand +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddPrinterFailed.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddPrinterFailed.rawhlp new file mode 100644 index 0000000000..948abce0f6 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/AddPrinterFailed.rawhlp @@ -0,0 +1,68 @@ +<TITLE> If New Printer Action Fails</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=AddPrinterFailed --> + +<CONTENT> + +<p> + +The printer name must be a text string composed of uppercase or +lowercase alphabetical characters (a-z, A-Z), digits (0-9), hyphens, +or underscores. A printer name can be a maximum of 14 characters long. + +<p> + +Display the Command-Line Console to help pinpoint where the error +may have occurred. Choose Show Command-Line Console from the Print +Manager menu to display the Command-Line Console. See the man +page for lpadmin(1M) for more information. + +<p> + +</CONTENT> + +<p> + +<KEYWORDS> +install fail failure "new attached" "new network" new printer action +fails +</KEYWORDS> + +<p> + +<SEEALSO> +InstallLocal +InstallNetwork +ToInstallLocal +ToInstallNetwork +ToShowCommand +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/DeletePrinterFailed.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/DeletePrinterFailed.rawhlp new file mode 100644 index 0000000000..ea10c85462 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/DeletePrinterFailed.rawhlp @@ -0,0 +1,56 @@ +<TITLE> If Delete Printer Fails</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=DeletePrinterFailed --> + +<CONTENT> + +<p> + +If the Delete printer process fails, follow the instructions in the +error dialog. If the instructions are incomplete or unclear, display +the Command-Line Console to help pinpoint where the error may have +occurred. Choose Show Command-Line Console from the Print Manager menu +to display the Command-Line Console. See the man page for lpadmin(1M) +for more information. + +<p> + +</CONTENT> + +<KEYWORDS> +delete fail failure printer fails +</KEYWORDS> + +<p> + +<SEEALSO> +ToDelete +ToShowCommand +Overview +MainWindow +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/HelpOnHelp.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/HelpOnHelp.rawhlp new file mode 100644 index 0000000000..9c86739709 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/HelpOnHelp.rawhlp @@ -0,0 +1,130 @@ +<TITLE> Help on Help </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 1999 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=HelpOnHelp --> + +<CONTENT> + +<p> + +Solaris Print Manager help is displayed if you choose one of the help +items from the Help menu in the Print Manager main window or if you +click on a Help button in any of the Print Manager windows or dialogs. + +<p> + +<b> Viewing a help article </b> + +<p> + +When you click on a Help button or choose a help item from the Help +menu, help for the selected topic is displayed in the help viewer. See +the headings labeled Navigation, Index, and Search below for +instructions for viewing other help articles. + +<p> + +<b> Navigation </b> + +<p> + +To move around in an article, click on the scroll bar to the right of +the article text. Note that you can expand or contract the help window +by grabbing a corner with the mouse cursor and moving the mouse. See +below for instructions for viewing other help articles. + +<p> + +Back button: Click to move to the last article viewed. +<br> +Forward button: Click to move to the article viewed prior to clicking +the Back button. +<br> +See also pulldown menu: Select an item from the menu and click Show to display +the selected article. +<br> +Show button: After selecting an item from the See also menu, click Show +to display it. + +<p> + +<b> Index </b> + +<p> + +1. Click the Index tab at the top of the help window to display the index +search tool. + +<p> + +By default the Search field is blank and all help articles are listed. +To limit the index listing, enter the first letters of a help article; +the articles that start with the entered letters will be displayed as +you type. To see all the task descriptions, for instance, enter "to" +and a blank. + +<p> + +2. To view an article, double-click on it or select it and click +Show. The article is displayed in view mode. + +<p> + +<b> Search </b> + +<p> + +Click the Search tab at the top of the help window to display the +search tool. + +<p> + +Enter a word or phrase in the Keywords field and click Search. + +<p> + +All articles with the entered keyword or phrase marked as a keyword +will be displayed in the Search Results list. + +<p> + +To view an article, double-click on it or select it and click +Show. The article is displayed in view mode. + +<p> + +</CONTENT> + +<KEYWORDS> +view index search show back forward "see also" help keywords +</KEYWORDS> + +<p> + +<SEEALSO> +Overview +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallLocal.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallLocal.rawhlp new file mode 100644 index 0000000000..bc73a37689 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallLocal.rawhlp @@ -0,0 +1,174 @@ +<TITLE> Dialog: New Attached Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2004 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=InstallLocal --> + +<CONTENT> + +<p> + +Once you have physically connected the printer to the printer server, +use the New Attached Printer dialog to install the printer, which +makes the printer available for printing from the computer on which +you are running Solaris Print Manager. + +<p> + +<b> Printer Name:</b> + Specifies a unique name for the printer. The + printer name must be a text string composed of + uppercase or lowercase alphabetical characters + (a-z, A-Z), digits (0-9), hyphens, or + underscores. A printer name can be a maximum of + 14 characters long. +<p> + +<b> Printer Server:</b> This is the computer you have selected to act +as the server for print actions. You must be logged on to this +computer and be running Solaris Print Manager on it. Solaris Print +Manager sets up this system with the appropriate software to manage +local and remote printers. + +<p> +<b> Description:</b> + [Optional] Describes the printer, including the printer type and + location, possibly, or provides other information about the + printer. + +<p> + +<b> Printer Port:</b> + +Specifies the hardware port, such as /dev/term/a, that the printer is +connected to. +<p> + +<b> Printer Type:</b> + Specifies the generic name for a type of + printer. Supported printer types correspond to + items listed in the /usr/share/lib/terminfo + directories. Examples are PostScript, Daisy, and Diablo. + +<p> + +<b> File Contents:</b> + Specifies the format of files that can be + printed without any special filtering by the + print software. PostScript is the default and is + probably correct most of the time. +<p> + +<b> Fault Notification:</b> + Specifies how the superuser will be notified in + case of a printer error. + +<p> + +<b> Options: Default Printer:</b> If checked, designates this printer +as the default printer for printing jobs from the computer on which +you are running Solaris Print Manager. If you are using a naming +service, this printer will be the default printer for the naming +service, also. + +<p> + +Note that this is the last place the print subsystem looks to +determine where a particular print job will be printed; the +destination option of the lp command is the first place looked, and +other environment variables are checked before this one. See the man +page for printers.conf(4) for a full explanation of the search order. + +<p> + +<b> Options: Banner:</b> Specifies whether a banner +page will be printed between jobs. +<br> +<br> +"Aways Print Banner" stipulates that a banner will always be printed +and may not be turned off by the user. +<br> +"User Selectable - Default=on" stipulates that a banner will be printed +unless the user selects +to turn the banner off. +<br> +"Never Print Banner" stipulates that a banner will never be printed +and may not be turned on by the user. + +<p> + +<b> User Access List:</b> +Specifies the print clients that can + print to this printer. By default, all print + clients have access to this printer, as designated by the word +"all" in the list. + +<p> + +If you want to restrict its use to individual users, enter a user name +in the text field below the list and click Add. Other legal constructs +are system-name!login-ID (user "login-ID" on system "system-name"), +system-name!all (all users on system "system-name"), and all!login-ID +(user "login-ID" on all systems). Use the lpadmin(1M) command to deny +access to users. + +<p> + +To delete a user from the list, select the user in the list and click +Delete. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> +</CONTENT> + +<KEYWORDS> +install "local printer" "printer name" server description port +"printer type" "file contents" fault "fault notification" "default +printer" banner "attached printer" new nobanner dialog: new attached + +</KEYWORDS> + +<p> + +<SEEALSO> +ToInstallLocal +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallLocalPPD.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallLocalPPD.rawhlp new file mode 100644 index 0000000000..a70ecf7e3c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallLocalPPD.rawhlp @@ -0,0 +1,175 @@ +<TITLE> Dialog: New Attached Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2004 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=InstallLocal --> + +<CONTENT> + +<p> + +Once you have physically connected the printer to the printer server, +use the New Attached Printer dialog to install the printer, which +makes the printer available for printing from the computer on which +you are running Solaris Print Manager. + +<p> + +<b> Printer Name:</b> + Specifies a unique name for the printer. The + printer name must be a text string composed of + uppercase or lowercase alphabetical characters + (a-z, A-Z), digits (0-9), hyphens, or + underscores. A printer name can be a maximum of + 14 characters long. +<p> + +<b> Printer Server:</b> This is the computer you have selected to act +as the server for print actions. You must be logged on to this +computer and be running Solaris Print Manager on it. Solaris Print +Manager sets up this system with the appropriate software to manage +local and remote printers. + +<p> +<b> Description:</b> + [Optional] Describes the printer, including the printer type and + location, possibly, or provides other information about the + printer. + +<p> + +<b> Printer Port:</b> + +Specifies the hardware port, such as /dev/term/a, that the printer is +connected to. +<p> + +<b> Printer Make:</b> + Specifies the printer make, or manufacturer. This + information is on the printer and/or in the documentation + that is delivered with the printer. +<p> + +<b> Printer Model:</b> + Specifies the printer model. This information + is found on the printer and/or in the documentation that is + delivered with the printer. +<p> + +<b> Printer Driver:</b> + Specifies the printer driver to use with this printer. +<p> + +<b> Fault Notification:</b> + Specifies how the superuser will be notified in + case of a printer error. + +<p> + +<b> Options: Default Printer:</b> If checked, designates this printer +as the default printer for printing jobs from the computer on which +you are running Solaris Print Manager. If you are using a naming +service, this printer will be the default printer for the naming +service, also. + +<p> + +Note that this is the last place the print subsystem looks to +determine where a particular print job will be printed; the +destination option of the lp command is the first place looked, and +other environment variables are checked before this one. See the man +page for printers.conf(4) for a full explanation of the search order. + +<p> + +<b> Options: Banner:</b> Specifies whether a banner +page will be printed between jobs. +<br> +<br> +"Aways Print Banner" stipulates that a banner will always be printed +and may not be turned off by the user. +<br> +"User Selectable - Default=on" stipulates that a banner will be printed +unless the user selects +to turn the banner off. +<br> +"Never Print Banner" stipulates that a banner will never be printed +and may not be turned on by the user. + +<p> + +<b> User Access List:</b> +Specifies the print clients that can + print to this printer. By default, all print + clients have access to this printer, as designated by the word +"all" in the list. + +<p> + +If you want to restrict its use to individual users, enter a user name +in the text field below the list and click Add. Other legal constructs +are system-name!login-ID (user "login-ID" on system "system-name"), +system-name!all (all users on system "system-name"), and all!login-ID +(user "login-ID" on all systems). Use the lpadmin(1M) command to deny +access to users. + +<p> + +To delete a user from the list, select the user in the list and click +Delete. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> +</CONTENT> + +<KEYWORDS> +install "local printer" "printer name" server description port +"printer make" "printer model" "printer driver" fault "fault notification" "default +printer" banner "attached printer" new nobanner dialog: new attached + +</KEYWORDS> + +<p> + +<SEEALSO> +ToInstallLocal +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallNetwork.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallNetwork.rawhlp new file mode 100644 index 0000000000..55f58f98da --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallNetwork.rawhlp @@ -0,0 +1,179 @@ +<title> Dialog: New Network Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2005 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=InstallNetwork --> + +<CONTENT> + +<p> + +Use the New Network Printer dialog to install a network printer, +thus making the printer available for printing from the network. + +<p> + +<b> Printer Name:</b> + Specifies a unique name for the printer. The + printer name must be a text string composed of + uppercase or lowercase alphabetical characters + (a-z, A-Z), digits (0-9), hyphens, or + underscores. A printer name can be a maximum of + 14 characters long. +<p> + +<b> Printer Server:</b> This is the computer you have selected to act +as the server for print actions. You must be logged on to this +computer and be running Solaris Print Manager on it. Solaris Print +Manager sets up this system with the appropriate software to manage +local and remote printers. + +<p> +<b> Description:</b> + [Optional] Describes the printer, including the printer type and + location, possibly, or provides other information about the + printer. + +<p> + +<b> Printer Type:</b> + Specifies the generic name for a type of + printer. Supported printer types correspond to + entries in the /usr/share/lib/terminfo + directory. Examples are PostScript, Daisy, and Diablo. +<p> + +<b> File Contents:</b> + Specifies the format of files that can be + printed without any special filtering by the + print software. PostScript is the default and is + probably correct most of the time. +<p> + +<b> Fault Notification:</b> + Specifies how the superuser will be notified in + case of a printer error. + +<p> +<b> Destination:</b> +<br> +For <b>BSD</b> Protocol, the network name of the printer followed by a colon +and the printer-vendor-supplied queue name. +<br> +For <b>TCP</b> Protocol, the network name of the printer followed by a colon +and the tcp port number to connect to. +<br> +For <b>URI</b> Protocol, a printer URI to be used in connecting to the remote +printer. For example: "smb://user@printer-host/printer-name". +<p> + +<b> Protocol:</b> +The internet protocol for file transfer; choices are BSD, TCP, or URI. +<p> + +<b> Options: Default Printer:</b> If checked, this printer is +designated as the default printer for printing jobs sent to this +server. If another printer had been designated as the default printer +for the network, this printer will replace it as the default. If you +are using a naming service, this printer will be the default printer +for the naming service, also. + +<p> Note that this is the last place the print subsystem looks to +determine where a particular print job will be printed; the +destination option of the lp command is the first place looked, and +other environment variables are checked before this one. See the man +page for printers.conf(4) for a full explanation of the search order. + +<p> + +<b> Options: Banner:</b> Specifies whether a banner +page will be printed between jobs. +<br> +<br> +"Aways Print Banner" stipulates that a banner will always be printed +and may not be turned off by the user. +<br> +"User Selectable - Default=on" stipulates that a banner will be printed +unless the user selects +to turn the banner off. +<br> +"Never Print Banner" stipulates that a banner will never be printed +and may not be turned on by the user. + +<p> + +<b> User Access List:</b> +Specifies the print clients that can + print to this printer. By default, all print + clients have access to this printer, as designated by the word +"all" in the list. +<p> + +To add a user to the list, type a user name in the blank text field +below the list and click Add. Note that this user name replaces "all" +or "none" if either "all" or "none" is in the user access list. If +"all" or "none" is added as a user, "all" or "none" will replace the +names in the list. + +<p> + +To delete a user from the list, select the user in the list and click +Delete. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> + +</CONTENT> + +<KEYWORDS> + +install "network printer" "printer name" server description port +"printer type" "file contents" fault "fault notification" "default +printer" banner new dialog: network printer + +</KEYWORDS> + +<p> + +<SEEALSO> +ToInstallNetwork +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallNetworkPPD.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallNetworkPPD.rawhlp new file mode 100644 index 0000000000..e43620b4c8 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/InstallNetworkPPD.rawhlp @@ -0,0 +1,185 @@ +<TITLE> Dialog: New Network Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2005 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=InstallNetwork --> + +<CONTENT> + +<p> + +Use the New Network Printer dialog to install a network printer, +thus making the printer available for printing from the network. + +<p> + +<b> Printer Name:</b> + Specifies a unique name for the printer. The + printer name must be a text string composed of + uppercase or lowercase alphabetical characters + (a-z, A-Z), digits (0-9), hyphens, or + underscores. A printer name can be a maximum of + 14 characters long. +<p> + +<b> Printer Server:</b> This is the computer you have selected to act +as the server for print actions. You must be logged on to this +computer and be running Solaris Print Manager on it. Solaris Print +Manager sets up this system with the appropriate software to manage +local and remote printers. + +<p> +<b> Description:</b> + [Optional] Describes the printer, including the printer type and + location, possibly, or provides other information about the + printer. + +<p> + +<b> Printer Make:</b> + Specifies the printer make, or manufacturer. This + information is on the printer and/or in the documentation + that is delivered with the printer. +<p> + +<b> Printer Model:</b> + Specifies the printer model. This information + is found on the printer and/or in the documentation that is + delivered with the printer. + +<p> + +<b> Printer Driver:</b> + Specifies the printer driver to use with this printer. +<p> + + +<b> Fault Notification:</b> + Specifies how the superuser will be notified in + case of a printer error. + +<p> +<b> Destination:</b> +<br> +For <b>BSD</b> Protocol, the network name of the printer followed by a colon +and the printer-vendor-supplied queue name. +<br> +For <b>TCP</b> Protocol, the network name of the printer followed by a colon +and the tcp port number to connect to. +<br> +For <b>URI</b> Protocol, a printer URI to be used in connecting to the remote +printer. For example: "smb://user@printer-host/printer-name". +<p> + +<b> Protocol:</b> +The internet protocol for file transfer; choices are BSD, TCP, or URI. +<p> + +<b> Options: Default Printer:</b> If checked, this printer is +designated as the default printer for printing jobs sent to this +server. If another printer had been designated as the default printer +for the network, this printer will replace it as the default. If you +are using a naming service, this printer will be the default printer +for the naming service, also. + +<p> Note that this is the last place the print subsystem looks to +determine where a particular print job will be printed; the +destination option of the lp command is the first place looked, and +other environment variables are checked before this one. See the man +page for printers.conf(4) for a full explanation of the search order. + +<p> + +<b> Options: Banner:</b> Specifies whether a banner +page will be printed between jobs. +<br> +<br> +"Aways Print Banner" stipulates that a banner will always be printed +and may not be turned off by the user. +<br> +"User Selectable - Default=on" stipulates that a banner will be printed +unless the user selects +to turn the banner off. +<br> +"Never Print Banner" stipulates that a banner will never be printed +and may not be turned on by the user. + +<p> + +<p> + +<b> User Access List:</b> +Specifies the print clients that can + print to this printer. By default, all print + clients have access to this printer, as designated by the word +"all" in the list. +<p> + +To add a user to the list, type a user name in the blank text field +below the list and click Add. Note that this user name replaces "all" +or "none" if either "all" or "none" is in the user access list. If +"all" or "none" is added as a user, "all" or "none" will replace the +names in the list. + +<p> + +To delete a user from the list, select the user in the list and click +Delete. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> + +</CONTENT> + +<KEYWORDS> + +install "network printer" "printer name" server description port +"printer make" "printer model" "printer driver" fault "fault notification" "default +printer" banner new dialog: network printer + +</KEYWORDS> + +<p> + +<SEEALSO> +ToInstallNetwork +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/LDAPAuthentication.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/LDAPAuthentication.rawhlp new file mode 100644 index 0000000000..901876a7cd --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/LDAPAuthentication.rawhlp @@ -0,0 +1,135 @@ +<TITLE> LDAP Authentication</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=LDAPAuthentication --> + +<CONTENT> + +<p> + +If you are using the LDAP naming service, you will need the distinguished +name and password for a user who has update privileges to make any changes. +Before making changes to the LDAP directory the user should be fully aware of +the items in the <b>notes</b> below. +The LDAP Authentication dialog is displayed when you select LDAP as the +naming service. + +<p> + +1. Check the LDAP server name for correctness. You may select a +different server name if appropriate. + +<p> + +2. Check the Distinguished Name (DN) for correctness. You may enter a +different distinguished name of another user if appropriate. This may be the DN +of any directory user who has permissions (directory update privileges) to +update printer entries in the LDAP directory for the current ldapclient (1M) +naming service (NS) domain. + +<p> + +3. Enter the password for the user's Distinguished Name. + +<p> + +4. Click OK. + +<p> + +The entries you have made will be validated against the LDAP directory and then +saved, the LDAP Authentication dialog will be dismissed. + +<p> + +Click Cancel if you don't know the password for the Distinguished Name. + +<p> + +<b>Note:</b> Keep the following in mind if you are using Solaris Print +Manager to update printer information in the LDAP naming service: + +<p> + +If the LDAP server is the Netscape Directory Server (NSDS) then +the default distinguished name is "cn=Directory Manager". +If the LDAP server is Sun Directory Server then an example +of the distinguished name is "cn=admin, dc=XYZ, dc=COM". + +The Solaris Print Manager uses ldapclient(1M) to determine +the default LDAP server name. If there is more than one +server specified then the first one will be used. + +<p> + +The Print Manager always displays printer entries from the current +ldapclient (1M) server. If this is not the domain Master LDAP server then +the list of printers displayed may <b>not</b> be the current list of printers, +this is because the ldapclient replica server may not have been updated by the +master server and so be out of sync with the master. Replica servers can have +various update replication agreements, for example; updated immediately there +is a change on the master, or updated once a day from the master. + +<p> + +If the selected LDAP server is a replica LDAP server, any <b>updates</b> will be +referred to the master server and done there. This again means the printer list +could be out of sync with the master. For example, a deleted printer may still +appear in the displayed printer list until the replica is updated from +the master. + +<p> + +Users can use the ldap command line utilities (ldapadd (1) & ldapmodify (1)) +to update printer entries in the directory, but this is not recommended. If +these utilities are used then the user <b>must ensure</b> that the printer-name +attribute value is unique within the ou=printers container. If it is not unique +the result of modifies done by the print manager (or lpset (1M)) may not be +predictable. + +<p> + +</CONTENT> + +<p> + +<KEYWORDS> + +LDAP ldap "LDAP server" authentication login password naming "naming +service" files "replica server" replica replication referral ldapclient +"distinguished name" DN + +</KEYWORDS> + +<p> + +<SEEALSO> +NameService +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/LoginFailed.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/LoginFailed.rawhlp new file mode 100644 index 0000000000..fc5dc0bbd1 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/LoginFailed.rawhlp @@ -0,0 +1,64 @@ +<TITLE> If Login Fails</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2003 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=LoginFailed --> + +<CONTENT> + +<p> + +If the NIS naming service is being used, you will need to know the +password for the naming service master. If LDAP is being used then +a fully distinguished name with update privilege and password will +be required. Note that default values may need to be overridden. For NIS+ +you may need to configure permissions to allow updates +before the tool is started. See the man page for lpadmin(1M) and the +help articles, "About Naming Services" and "NIS Authentication," for +further information. + +<p> + +</CONTENT> + +<p> + +<KEYWORDS> +"login failed" login fail failure fails +</KEYWORDS> + +<p> + +<SEEALSO> +ToStart +ToShowCommand +NISAuthentication +NameService +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/MainWindow.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/MainWindow.rawhlp new file mode 100644 index 0000000000..2e5f2b8897 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/MainWindow.rawhlp @@ -0,0 +1,120 @@ +<TITLE> Solaris Print Manager Main Window </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2003 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=MainWindow --> + +<CONTENT> + +<p> + +The main window is the starting point for any Solaris Print Manager +activities. + +<p> +<b> Print Manager Menu: </b> Select Naming Service, Show +Command-Line Console, Confirm All Actions, Exit + +<p> +<b> Printer Menu: </b> Add Access to Printer, New Attached +Printer, New Network Printer, Modify Printer Properties, +Delete Printer + +<p> +<b> Tools Menu: </b> Find Printer + +<p> +<b> Help Menu: </b> Overview, On Help, About Print Manager +<p> + +<b> List of Printers: </b> This is the list of printers installed on +the computer on which you are running Solaris Print Manager, or, if a +naming service is being used, all printers in the naming service. + +<p> +There are three columns in the list: +<p> + +<b> Printer Name:</b> The name of the printer as specified during printer +installation. +<p> + +<b> Printer Server:</b> The name of the printer server for the printer +specified in the Printer Name column. +<p> + +<b> Description:</b> A description of the printer as specified during +printer installation (New Attached Printer or New Network +Printer) or modification (Modify Printer Properties). The +description might include the location of the printer and its printer +type. + +<p> + +The footer panel at the bottom of the window has two or three entries: + +<p> + +<b> Default Printer: </b> If no naming service is being used, the +default printer for the computer on which you are running Solaris +Print Manager. If a naming service is being used, the default printer +for the naming service. + +<p> + +<b> Naming Service: </b> The naming service -- NIS, LDAP, or NIS+ -- +that is being used for printing. This is not displayed if no naming +service is being used. + +<p> + +<b> Domain or Host: </b> The network domain you are working in or the +current host (if no naming service is being used). If you are +using a naming service, the list of printers includes all printers in +this domain. + +<p> + +</CONTENT> + +<KEYWORDS> +"Print Manager menu" "Printer menu" "Tools menu" "Help menu" "list +of printers" printers "printer name" "printer server" description +"default printer" "naming service" domain solaris print manager main +window +</KEYWORDS> + +<p> + +<SEEALSO> +Overview +ToAddAccess +ToInstallLocal +ToInstallNetwork +ToModify +ToDelete +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/Modify.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/Modify.rawhlp new file mode 100644 index 0000000000..dab09ff14c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/Modify.rawhlp @@ -0,0 +1,170 @@ +<TITLE> Dialog: Modify Printer Properties </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2004 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=Modify --> + +<CONTENT> + +<p> + +Use the Modify Printer Properties dialog to modify an installed +printer. Note that you can modify the Description field only if this +is not an attached printer. You can also check or uncheck the Default +Printer box. + +<p> + +<b> Printer Name:</b> Cannot be modified. + +<p> + +<b> Printer Server:</b> Cannot be modified. +This is the computer you have selected to act +as the server for print actions. You must be logged on to this +computer and be running Solaris Print Manager on it. + +<p> + +<b> Description:</b> + [Optional] Describes the printer, including the printer type and + location, possibly, or provides other information about the + printer. + +<p> + +<b> Printer Port:</b> Cannot be modified. +Specifies the hardware port, such as /dev/term/a, that the printer is +connected to. + +<p> + +<b> Printer Type:</b> + Specifies the generic name for a type of + printer. Supported printer types correspond to + items listed in the /usr/share/lib/terminfo + directories. Examples are PostScript, Daisy, and Diablo. + +<p> + +<b> File Contents:</b> + Specifies the format of files that can be + printed without any special filtering by the + print software. PostScript is the default and is + probably correct most of the time. +<p> + +<b> Fault Notification:</b> + Specifies how the superuser will be notified in + case of a printer error. + +<p> + +<b> Options: Default Printer:</b> If checked, designates this printer +as the default printer for printing jobs from the computer on which +you are running Solaris Print Manager. If you are using a naming +service, this printer will be the default printer for the naming +service, also. + +<p> + +Note that this is the last place the print subsystem looks to +determine where a particular print job will be printed; the +destination option of the lp command is the first place looked, and +other environment variables are checked before this one. See the man +page for printers.conf(4) for a full explanation of the search order. + +<p> + +<b> Options: Banner:</b> Specifies whether a banner +page will be printed between jobs. +<br> +<br> +"Aways Print Banner" stipulates that a banner will always be printed +and may not be turned off by the user. +<br> +"User Selectable - Default=on" stipulates that a banner will be printed +unless the user selects +to turn the banner off. +<br> +"Never Print Banner" stipulates that a banner will never be printed +and may not be turned on by the user. + +<p> + +<b> User Access List:</b> +Specifies the print clients that can + print to this printer. By default, all print + clients have access to this printer, as designated by the word +"all" in the list. + +<p> + +If you want to restrict its use to individual users, enter a user name +in the text field below the list and click Add. Other legal constructs +are system-name!login-ID (user "login-ID" on system "system-name"), +system-name!all (all users on system "system-name"), and all!login-ID +(user "login-ID" on all systems). Use the lpadmin(1M) command to deny +access to users. + +<p> + +To delete a user from the list, select the user in the list and click +Delete. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> +</CONTENT> + +<KEYWORDS> modify properties "printer properties" "attached printer" +"printer name" server description port "printer type" "file contents" +fault "fault notification" "default printer" banner "attached printer" +new nobanner dialog: printer + +</KEYWORDS> + +<p> + +<SEEALSO> +ToModify +ModifyFailed +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ModifyFailed.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ModifyFailed.rawhlp new file mode 100644 index 0000000000..97a59c6a46 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ModifyFailed.rawhlp @@ -0,0 +1,62 @@ +<TITLE> If Modify Printer Fails</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ModifyFailed --> + +<CONTENT> + +<p> + +An attempt to modify printer properties failed. It is possible that +someone has deleted the printer before this modify operation completed. + +<p> + +Display the Command-Line Console to help pinpoint where the error +may have occurred. Choose Show Command-Line Console from the Print +Manager menu to display the Command-Line Console. See the man page for +lpadmin(1M) for further information. + +</CONTENT> + +<p> + +<KEYWORDS> +modify "modify printer" fail failure printer fails +</KEYWORDS> + +<p> + +<SEEALSO> +ToModify +Modify +ToShowCommand +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ModifyPPD.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ModifyPPD.rawhlp new file mode 100644 index 0000000000..f3b46825a4 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ModifyPPD.rawhlp @@ -0,0 +1,174 @@ +<TITLE> Dialog: Modify Printer Properties </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2004 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ModifyPPD --> + +<CONTENT> + +<p> + +Use the Modify Printer Properties dialog to modify an installed +printer. Note that you can modify the Description field only if this +is not an attached printer. You can also check or uncheck the Default +Printer box. + +<p> + +<b> Printer Name:</b> Cannot be modified. + +<p> + +<b> Printer Server:</b> Cannot be modified. +This is the computer you have selected to act +as the server for print actions. You must be logged on to this +computer and be running Solaris Print Manager on it. + +<p> + +<b> Description:</b> + [Optional] Describes the printer, including the printer type and + location, possibly, or provides other information about the + printer. + +<p> + +<b> Printer Port:</b> Cannot be modified. +Specifies the hardware port, such as /dev/term/a, that the printer is +connected to. + +<p> + +<b> Printer Make:</b> + Specifies the printer make, or manufacturer. This + information is on the printer and/or in the documentation + that is delivered with the printer. + +<p> + +<b> Printer Model:</b> + Specifies the printer model. This information + is found on the printer and/or in the documentation that is + delivered with the printer. +<p> + +<b> Printer Driver:</b> + Specifies the printer driver to use with this printer. +<p> + + +<b> Fault Notification:</b> + Specifies how the superuser will be notified in + case of a printer error. + +<p> + +<b> Options: Default Printer:</b> If checked, designates this printer +as the default printer for printing jobs from the computer on which +you are running Solaris Print Manager. If you are using a naming +service, this printer will be the default printer for the naming +service, also. + +<p> + +Note that this is the last place the print subsystem looks to +determine where a particular print job will be printed; the +destination option of the lp command is the first place looked, and +other environment variables are checked before this one. See the man +page for printers.conf(4) for a full explanation of the search order. + +<p> + +<b> Options: Banner:</b> Specifies whether a banner +page will be printed between jobs. +<br> +<br> +"Aways Print Banner" stipulates that a banner will always be printed +and may not be turned off by the user. +<br> +"User Selectable - Default=on" stipulates that a banner will be printed +unless the user selects +to turn the banner off. +<br> +"Never Print Banner" stipulates that a banner will never be printed +and may not be turned on by the user. + +<p> + +<b> User Access List:</b> +Specifies the print clients that can + print to this printer. By default, all print + clients have access to this printer, as designated by the word +"all" in the list. + +<p> + +If you want to restrict its use to individual users, enter a user name +in the text field below the list and click Add. Other legal constructs +are system-name!login-ID (user "login-ID" on system "system-name"), +system-name!all (all users on system "system-name"), and all!login-ID +(user "login-ID" on all systems). Use the lpadmin(1M) command to deny +access to users. + +<p> + +To delete a user from the list, select the user in the list and click +Delete. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> +</CONTENT> + +<KEYWORDS> modify properties "printer properties" "attached printer" +"printer name" server description port "printer make" "printer model" +"printer driver" fault "fault notification" "default printer" banner +"attached printer" +new nobanner dialog: printer + +</KEYWORDS> + +<p> + +<SEEALSO> +ToModify +ModifyFailed +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/NISAuthentication.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/NISAuthentication.rawhlp new file mode 100644 index 0000000000..8a45d2b181 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/NISAuthentication.rawhlp @@ -0,0 +1,100 @@ +<TITLE> NIS Authentication</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2000 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=NISAuthentication --> + +<CONTENT> + +<p> + +If you are using the NIS naming service, you will need the root +password for the NIS master computer to make any changes. The NIS +Authentication dialog is displayed when you select NIS as the +naming service. + +<p> + +1. Enter the password for the NIS master. + +<p> + +2. Click OK. + +<p> + +The entries you have made will be saved and the NIS Authentication +dialog will be dismissed. + +<p> + +Click Cancel if you don't know the password for the NIS master. + +<p> + +<b>Note:</b> Keep the following in mind if you are using Solaris Print +Manager to update printer information in the NIS name service: + +<p> + +- If your network is set up with NIS master and slave servers, +the NIS slaves may not see the updated printer information +until the NIS slaves are updated. See ypmake(1M) for more +information. + +<p> + +- If your NIS servers are running Solaris 2.5 and compatible +versions, you must have explicit permissions on the NIS master +server to update the maps. This means an entry for your system +name must reside in root's .rhosts file on the NIS master server. + +<p> + +- If you have modified the yp makefile to use something other +than /etc/printers.conf as the source for the NIS map, +printers.conf.byname, do not use Solaris Print Manager to modify NIS. + +</CONTENT> + +<p> + +<KEYWORDS> + +NIS "NIS master" master authentication login password naming "naming +service" files .rhosts + +</KEYWORDS> + +<p> + +<SEEALSO> +NameService +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/NameService.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/NameService.rawhlp new file mode 100644 index 0000000000..01d5d21b83 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/NameService.rawhlp @@ -0,0 +1,181 @@ +<TITLE> About Naming Services </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2003 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=NameService --> + +<CONTENT> + +<p> + +You can select "files" or a naming service (NIS, LDAP, or NIS+) when you +start up Solaris Print Manager or when you choose Select Naming +Service from the Print Manager menu. See the descriptions of each +of the choices below. + +<p> + +Once you select a naming service, Print Manager will retrieve and update +printer information in the database for the specified naming service +when you add, modify, or delete a printer. Note that in addition to +the naming service map, when updating attached or network printers +the file /etc/printers.conf is also updated when a naming service +is being used. + +<p> + +When you make a remote printer accessible by choosing Add Access to +Printer from the Printer menu, either the naming service map is +updated or /etc/printers.conf is updated (if "files" is selected and +no naming service is being used). + +<p> + +<b>files</b>: Retrieve or update printer information from +the file /etc/printers.conf. + +<p> + +<b>NIS</b>: Use the printers.conf.byname map stored in the Network +Information Service for retrieving or updating printer information. +See the ypserv(1M) man page for more information. + +<p> + +<b>Note: </b>When a site is set up with a NIS master and slaves, if the +host binds to a slave, a user may not see NIS updates made through +Print Manager until the slave computers are updated. See the ypmake(1M) +man page for more information. + +<p> + +<b>LDAP</b>: Use the printers map stored in the LDAP +naming service for retrieving or updating printer information. +See the ldap(1) man page for more information. + +<p> + +To used the LDAP naming service the host computer must be configured as a +LDAP client, see ldapclient(1M). + +<p> + +<b>Note:</b>If the host binds to a replica LDAP server, a user may not see +updates made through Print Manager until the replica is updated from the master +LDAP server. + +<p> + +<b>NIS+</b>: Use the printers.org_dir map stored in the NIS+ +naming service for retrieving or updating printer information. +See the nis+(1) man page for more information. + + +<p> + +The following privileges are needed for each naming service: + +<p> + +<b>For files:</b> + +<p> + +The tool must be started as root. + +<p> + +<b>For NIS:</b> + +<p> + +1) The tool must be started as root. + +<p> + +2) The password for the NIS master will be required when you select +this naming service. + +<p> + +3) For NIS servers running pre-2.6 Solaris, you need to set up an +rhosts entry on the NIS server allowing root on the print server root +access on the NIS server. You must have explicit permissions on the +NIS master server to update the maps. This means an entry for your +host name must reside in root's .rhosts file on the NIS master server. +See the hosts.equiv(4) man page for more information. + +<p> + +<b>For LDAP:</b> + +<p> + +1) The tool must be started as root. + +<p> + +2) A fully distinguished name (DN) with update privilege and password will + be required when you select this naming service. + +<p> + +<b>For NIS+:</b> +<p> + +1) The computer that Solaris Print Manager is running on must be added to the list +of principals authorized to update the NIS+ map printers.org_dir. +See the nisgrpadm(1) man page for more information. + +<p> + +2) Solaris Print Manager must be started as root. Depending on +configuration the user may also need to do a keylogin. See the +keylogin(1) man page for more information. + +<p> + +</CONTENT> + +<p> + +<KEYWORDS> + +"name service" "naming service" name naming nis none ldap nis+ +keylogin printers.conf service files +hosts.equiv nisgrpadm about services + +</KEYWORDS> + +<p> + +<SEEALSO> +ToStart +ToSelectName +Overview +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/Overview.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/Overview.rawhlp new file mode 100644 index 0000000000..b51ab7d6e8 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/Overview.rawhlp @@ -0,0 +1,125 @@ +<TITLE> Overview </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 1999 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=Overview --> + +<CONTENT> + +<p> + +Use Solaris Print Manager to select a naming service, to install attached +or network printers, and to add, modify, or remove access to installed +printers. Five windows or dialogs and 11 tasks -- listed below -- are described +in the help volume. To view one of the help articles, select it +in the See also pulldown menu and click the Show button. + +<p> + +If you need more information about printing, see the "Solaris Print +Manager Administration Guide" AnswerBook or the "Setting Up Printers" +chapter in the Solaris System Administrator AnswerBook. + +<p> + +<b> Windows and Dialogs </b> +<p> +Main Window +<br> +Add Access to Printer +<br> +New Attached Printer +<br> +New Network Printer +<br> +Modify Printer Properties + +<p> +<b>Tasks</b> +<p> +To Start Solaris Print Manager +<br> +To Add Access to an Installed Printer +<br> +To Install an Attached Printer +<br> +To Install a Network Printer +<br> +To Modify Printer Properties +<br> +To Delete a Printer +<br> +To Select a Naming Service +<br> +To Exit Solaris Print Manager +<br> +To Find a Printer +<br> +To Show the Command-Line Console +<br> +To Confirm All Actions +<p> + +<b>More About Printing and Solaris Print Manager </b> + +<p> + +If you need more information about printing or about Solaris Print +Manager, including a description of mouseless navigation, see the +"Solaris Print Manager Administration Guide" AnswerBook or the +"Setting Up Printers" chapter in the Solaris System Administrator +AnswerBook. + +<p> + +</CONTENT> + +<KEYWORDS> +overview contents task dialog +</KEYWORDS> + +<p> + +<SEEALSO> +MainWindow +AddAccess +InstallLocal +InstallNetwork +Modify +ToAddAccess +ToStart +ToInstallLocal +ToInstallNetwork +ToModify +ToDelete +ToSelectName +ToExit +ToFindPrinter +ToShowCommand +ToConfirmActions +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/PrinterPort.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/PrinterPort.rawhlp new file mode 100644 index 0000000000..23d11c054f --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/PrinterPort.rawhlp @@ -0,0 +1,67 @@ +<TITLE> Specify Printer Port </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=PrinterPort --> + +<CONTENT> + +<p> + +The printer port is the device name (typically, /dev/term/a, +/dev/term/b, or /dev/bpp0) corresponding to the port to which a +locally attached printer is physically connected. You usually connect +printer cables to a serial port (/dev/term/a or /dev/term/b, for +example) but in some cases you can use a parallel port (/dev/bpp0, for +example). See the printer vendor's documentation and your system's +installation documentation for information about switch settings and +cabling requirements. + +<p> + +Note that the device name must exist and have write permissions +set. + +<p> + +</CONTENT> + +<KEYWORDS> +port "printer port" other specify printer +</KEYWORDS> + +<p> + +<SEEALSO> +InstallLocal +ToInstallLocal +Overview +MainWindow +HelpOnHelp +</SEEALSO> + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/PrinterType.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/PrinterType.rawhlp new file mode 100644 index 0000000000..5ef9a49fce --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/PrinterType.rawhlp @@ -0,0 +1,64 @@ +<TITLE> Specify Printer Type </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=PrinterType --> + +<CONTENT> + +<p> + +When you configure a printer, you must identify the manufacturer +and model of the printer in a way that the LP print service +understands the printer type. Examples are PostScript, Daisy, and Diablo. + +<p> + +If you have a PostScript printer, for example, select PostScript as +the Printer Type. To install a printer type that is not listed select +Other. The printer type you enter must correspond to an entry in the +/usr/share/lib/terminfo directories. See the terminfo(4) man page for +more information. + +<p> + +</CONTENT> + +<KEYWORDS> +"printer type" type specify printer +</KEYWORDS> + +<p> + +<SEEALSO> +InstallLocal +InstallNetwork +ToInstallLocal +ToInstallNetwork +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/RemoteServer.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/RemoteServer.rawhlp new file mode 100644 index 0000000000..2188adb1c1 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/RemoteServer.rawhlp @@ -0,0 +1,53 @@ +<TITLE> Specify Remote Server </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=RemoteServer --> + +<CONTENT> + +<p> + +A printer server must be specified; the printer server is the computer +on which the software for the remote printer is installed. + +<p> + +</CONTENT> + +<KEYWORDS> +remote "remote printer" server "printer server" fail failure specify +</KEYWORDS> + +<p> + +<SEEALSO> +AddAccess +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ShowCommandConsole.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ShowCommandConsole.rawhlp new file mode 100644 index 0000000000..cfaa20b1c4 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ShowCommandConsole.rawhlp @@ -0,0 +1,87 @@ +<TITLE> Command-Line Console</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ShowCommandConsole --> + +<CONTENT> + +<p> + +The Command-Line Console displays the command-line version of add, +modify, and delete actions. Errors and warnings may also be +displayed after the command. + +<p> + +For example, if you choose Add Access to Printer from the Print +Manager menu and enter Printer Name = MyPrinter, Printer Server = +PrintServer2, Description = Local Printer, the Command-line Console +will display: + +<p> + +Add Access to printer +<br> +% /usr/sbin/lpadmin -p MyPrinter -s PrintServer2 -D "Local Printer" + +<p> + +The Command-line Console is displayed if the Show Command-Line Console box +is checked in the Print Manager menu. + +<p> + +<b>Note: </b>When updating the NIS naming service, there are some +cases where there is no command line equivalent for what Solaris Print +Manager is doing. In these cases what gets reported to the +Command-Line console is: "rsh [nis_master] ..." or +"rexec([nis_master]) ..." + +<p> + +<b>Note: </b>When updating the LDAP naming service, the Solaris Print +Manager uses native (or compiled) code to process updates. This +is done to enhance security related to the LDAP password. The command-line +used to update the LDAP database is not displayed for security reasons, but +the log will include the entry "ldap ..." to indicate that the LDAP database +has been updated. + +<p> + +</CONTENT> + +<KEYWORDS> +"command-line" log command console show +</KEYWORDS> + +<p> + +<SEEALSO> +Overview +MainWindow +ToShowCommand +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToAddAccess.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToAddAccess.rawhlp new file mode 100644 index 0000000000..1fc8e8a7aa --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToAddAccess.rawhlp @@ -0,0 +1,144 @@ +<TITLE>To Add Access to an Installed Printer</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToAddAccess --> + +<CONTENT> + +<p> + +Do the following to make an installed printer accessible to print +client computers. See the printers.conf(4) man page for more +information about print client commands. + +<p> + +<b>Note:</b> If you are using a naming service, use this procedure to +add access to a private printer (one that is not listed in the naming +service) or to make the printer usable even if the naming service +server is down. This adds access for all users in the naming service +domain; see the man page for domainname(1M) for more information about +domains. + +<p> + +If a naming service is not being used for printing, use this procedure +to add access to a remote printer. + +<p> + +1. Choose Add Access to Printer from the Printer menu. + +<p> + + The Add Access To Printer dialog is displayed. + +<p> + +2. Enter a printer name, printer server name, and description (optional). + +<p> + +Note that Solaris Print Manager does not check for the validity of +Printer Name or Printer Server. + +<p> + +3. Click Default Printer if you want this printer to be the default +printer. + +<p> + +If a naming service is being used, this printer will be designated as +the default printer for all users in the domain. + +<p> + +If no naming service is being used, this printer will be designated as +the default printer for the computer on which you are running Solaris +Print Manager. + +<p> + +Note that this is the last place the print commands will look to +determine the printer for a specific print command; see the +man page for printers.conf(4) for more information about resolving +printer conflicts. + +<p> + +4. Click OK or Apply to add access for the specified printer. + +<p> + +<b> Note:</b> If you are using the NIS naming service, you have to know the +root password for the NIS master. If you are using the LDAP naming service, +you must know a fully distinguished name which has update privilege and +the corresponding password. Default values may need to be overridden. You +will be prompted for the password when you click Apply or OK. Enter the +password and click OK. + +<p> + The list of printers displayed in the Solaris Print Manager main window + is updated to include the new printer. +<p> + The Add Access dialog will remain displayed if you click Apply, +allowing you to add access to additional printers. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> + +</CONTENT> + +<KEYWORDS> +access "add access" description "default printer" "naming service" +"printer name" "printer server" add installed printer +</KEYWORDS> + +<p> + +<SEEALSO> +AddAccess +ToModify +ToDelete +MainWindow +HelpOnHelp +</SEEALSO> + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToConfirmActions.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToConfirmActions.rawhlp new file mode 100644 index 0000000000..2454ba6cfc --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToConfirmActions.rawhlp @@ -0,0 +1,69 @@ +<TITLE> To Confirm All Actions </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToConfirmActions --> + +<CONTENT> + +<p> + +Do the following to require that all Solaris Print Manager actions be +confirmed before being executed, or to turn off this option. + +<p> + +1. Choose Confirm All Actions from the Print Manager menu. + +<p> + +If the Confirm All Actions box was not checked, it will be checked +and all subsequent Solaris Print Manager actions will require +confirmation before being performed. + +<p> + +If the Confirm All Actions box was checked, it will no longer be checked +and subsequent Solaris Print Manager actions will NOT require +confirmation before being performed. Note that some actions, such as +Delete Printer, require confirmation regardless of the setting of the +Confirm All Actions box. + +<p> + +</CONTENT> + +<KEYWORDS> +confirm action all actions +</KEYWORDS> + +<p> + +<SEEALSO> +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToDelete.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToDelete.rawhlp new file mode 100644 index 0000000000..9efb3415c2 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToDelete.rawhlp @@ -0,0 +1,84 @@ +<TITLE> To Delete a Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToDelete --> + +<CONTENT> + +<p> + +Do the following to delete a printer from the printer list. + +<p> 1. Select the printer in the list of printers in the Solaris +Print Manager main window. + +<p> + +2. Choose Delete Printer from the Printer menu. + +<p> + +A dialog is displayed, +asking if you really want to delete the selected printer. + +<p> <b>Note:</b> If the printer is a local printer (one installed on +the current server), the printer will be uninstalled; if a naming +service has been selected, the entry for this printer will also be +removed from the naming service. + +<p> +3. Click OK to delete the printer. +<p> + A window is displayed asking you to confirm the + deletion. +<p> +4. Click Delete. +<p> +The selected printer is deleted from the Solaris Print Manager main +window. + +<p> + +</CONTENT> + +<KEYWORDS> +delete uninstall "local printer" "network printer" "attached printer" +printer +</KEYWORDS> + +<p> + +<SEEALSO> +ToAddAccess +AddAccess +MainWindow +Overview +HelpOnHelp +</SEEALSO> + + + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToExit.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToExit.rawhlp new file mode 100644 index 0000000000..03cc6494c0 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToExit.rawhlp @@ -0,0 +1,56 @@ +<TITLE> To Exit Solaris Print Manager </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToExit --> + +<CONTENT> + +<p> + +1. Choose Exit from the Print Manager menu. + +<p> + +The Solaris Print Manager main window and any other open Print Manager +dialogs are closed. + +<p> + +</CONTENT> + +<KEYWORDS> +exit close solaris print manager +</KEYWORDS> + +<p> + +<SEEALSO> +ToStart +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToFindPrinter.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToFindPrinter.rawhlp new file mode 100644 index 0000000000..cfb7df6b0a --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToFindPrinter.rawhlp @@ -0,0 +1,71 @@ +<TITLE> To Find a Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToFindPrinter --> + +<CONTENT> + +<p> + +Do the following to find a printer in the Solaris Print Manager list +of printers. + +<p> + +1. Choose Find Printer from the Tools menu. + +<p> + +A dialog will be displayed, asking you to enter the name of a printer to find. + +<p> + +2. Type a printer name in the text field and click Find. + +<p> + +If the exact printer name is found in the list, it will be selected; +the list will scroll, if necessary. If the printer is not found, a +message will be displayed, indicating that the named printer was not +found in the current list. + +<p> + +</CONTENT> + +<KEYWORDS> +find "printer name" tool printer +</KEYWORDS> + +<p> + +<SEEALSO> +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToInstallLocal.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToInstallLocal.rawhlp new file mode 100644 index 0000000000..3d5163245c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToInstallLocal.rawhlp @@ -0,0 +1,179 @@ +<TITLE> To Install an Attached Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2004 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToInstallLocal --> + +<CONTENT> + +<p> + +Once you have physically connected the printer to the printer server, +do the following to install the printer, which makes the printer +available for printing from the computer on which you are running +Solaris Print Manager. + +<p> + +<b> Note:</b> The computer on which you are running Solaris Print +Manager becomes the printer server for the printer being installed. + +<p> + +1. Choose New Attached Printer from the Printer menu. + +<p> + +The New Attached Printer dialog will be displayed. + +<p> + +2. Enter a name in Printer Name. +<p> + +3. [Optional] Enter a description of the printer. + +<p> +This might include the location and the type of printer. + +<p> +4. Select a port from the Printer Port pulldown menu. + +<p> +This is the hardware port where the printer is plugged into the +server. If you choose Other, a dialog will pop up asking you to +specify a port. Enter a port and click OK. + +<p> +5. Select a printer type from the Printer Type pulldown menu. + +<p> + +Scroll the list if necessary. If the printer type is not in the list, +select Other; you will be asked to specify a printer type. Enter a +printer type and click OK. + +<p> +6. Select an item in the File Contents pulldown menu. + +<p> +Choices include PostScript and ASCII; the default is PostScript, which +will work in most cases. + +<p> +7. Select an item in the Fault Notification pulldown menu. + +<p> + +The default is Write to Superuser. + +<p> +8. [Optional] Click Default Printer if you want this printer to be the default +printer for this server. + +<p> + +9. [Optional] Select option to define whether a banner +page is to be printed between jobs. "Always Print Banner" +specifies that a banner will be printed and the user may not specify +otherwise. "User Selectable - Default=on" specifies that the user may +specify to turn off the banner in the print command; if the user does +not specify, the banner will be printed. "Never Print Banner" specifies +that a banner will not be printed and the user may not specify +otherwise. The default action is to always print the banner. + +<p> + +10. Modify the User Access List, if necessary. + +<p> + +The default value is "all," meaning that anyone can use this printer. +If you want to restrict its use to individual users, enter a user name +in the text field below the list and click Add. Other legal constructs +are system-name!login-ID (user "login-ID" on system "system-name"), +system-name!all (all users on system "system-name"), and all!login-ID +(user "login-ID" on all systems). Use the lpadmin(1M) command to deny +access to users. + +<p> + +To remove a name from the list, select it and click Delete. + +<p> + +<b> Note:</b> If you enter "all" or "none" in the text field and click +Add, all individual user names will be deleted from the list and +replaced by "all" or "none." + +<p> +11. Click OK or Apply to install the printer. + +<p> +The window will remain if you click Apply, allowing you to install +additional printers. + +<p> + +<b> Note:</b> If you are using the NIS naming service, you have to know +the root password for the NIS master. If you are using the LDAP naming +service you must know a fully distinguished name which has update +privilege and the corresponding password. Default values may need to be +overridden. You will be prompted for the password when you click Apply or OK. +Enter the password and click OK. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> + +</CONTENT> + +<KEYWORDS> +install "local printer" "printer name" server description port +"printer type" "file contents" fault "fault notification" "default +printer" banner nobanner "attached printer" new attached printer + +</KEYWORDS> + +<p> + +<SEEALSO> +InstallLocal +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToInstallNetwork.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToInstallNetwork.rawhlp new file mode 100644 index 0000000000..a725815265 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToInstallNetwork.rawhlp @@ -0,0 +1,184 @@ +<TITLE> To Install a Network Printer </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2005 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToInstallNetwork --> + +<CONTENT> + +<p> + +Once you have physically connected the printer to the network, +do the following to install the printer, which makes the printer +available for printing from the network. + +<p> + +<b> Note:</b> The computer on which you are running Solaris Print +Manager becomes the printer server for the printer being installed. + +<p> + +1. Choose New Network Printer from the Printer menu. + +<p> + +The New Attached Printer dialog will be displayed. + +<p> + +2. Enter a name in Printer Name. + +<p> + +3. [Optional] Enter a description of the printer. + +<p> +This might include the location and the type of printer. + +<p> +4. Select a printer type from the Printer Type pulldown menu. + +<p> + +Scroll the list if necessary. If the printer type is not in the list, +select Other; you will be asked to specify a printer type. Enter a +printer type and click OK. + +<p> +5. Select an item in the File Contents pulldown menu. + +<p> +Choices include PostScript and ASCII; the default is PostScript, which +will work in most cases. + +<p> +6. Select an item in the Fault Notification pulldown menu. + +<p> + +The default is Write to Superuser. + +<p> +7a. If the printer uses BSD protocol, enter the network name of the printer +in the Destination field, followed by a colon and the printer-vendor-supplied +queue name. +<p> +7b. If the printer uses TCP protocol, enter the network name of the printer +in the Destination field, followed by a colon and port number to be used in the +tcp connection to the printer. +<p> +7c. If the printer uses a printer URI, enter the the URI for the printer +in the Destination field (for example: +"smb://printer-host/printer-name"). + +<p> +8. Select either BSD, TCP, or URI from the Protocol pulldown menu. + +<p> +9. [Optional] Click Default Printer if you want this printer to be the default +printer for this server. + +<p> + +10. [Optional] Select option to define whether a banner +page is to be printed between jobs. "Always Print Banner" +specifies that a banner will be printed and the user may not specify +otherwise. "User Selectable - Default=on" specifies that the user may +specify to turn off the banner in the print command; if the user does +not specify, the banner will be printed. "Never Print Banner" specifies +that a banner will not be printed and the user may not specify +otherwise. The default action is to always print the banner. + +<p> +11. Modify the User Access List, if necessary. + +<p> + + +The default value is "all," meaning that anyone can use this printer. +If you want to restrict its use to individual users, enter a user name +in the text field below the list and click Add. Other legal constructs +are system-name!login-ID (user "login-ID" on system "system-name"), +system-name!all (all users on system "system-name"), and all!login-ID +(user "login-ID" on all systems). Use the lpadmin(1M) command to deny +access to users. + +<p> + +<b> Note:</b> If you enter "all" or "none" in the text field and click +Add, all individual user names will be deleted from the list and +replaced by "all" or "none." + +<p> +12. Click OK or Apply to install the printer. + +<p> +The window will remain if you click Apply, allowing you to install +additional printers. + +<p> + +<b> Note:</b> If you are using the NIS naming service, you have to know +the root password for the NIS master. If you are using the LDAP naming +service, you must know a fully distinguished name which has update privilege +and the corresponding password. Default values may need to be overridden. +You will be prompted for the password when you click Apply or OK. +Enter the password and click OK. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> + +</CONTENT> + +<KEYWORDS> + +install network "network printer" "printer name" server description +port "printer type" "file contents" fault "fault notification" +"default printer" banner destination protocol new bsd tcp printer + +</KEYWORDS> + +<p> + +<SEEALSO> +InstallNetwork +ToAddAccess +Overview +MainWindow +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToModify.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToModify.rawhlp new file mode 100644 index 0000000000..0b81437d20 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToModify.rawhlp @@ -0,0 +1,122 @@ +<TITLE> To Modify Printer Properties </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToModify --> + +<CONTENT> + +<p> + +Do the following to modify the properties of an installed printer. + +<p> + +1. Double-click the printer in the Solaris Print Manager main window +<p> + OR +<p> + Select the printer in the Solaris Print Manager main window and choose + Modify Printer Properties from the Printer menu. +<p> + The Modify Printer Properties dialog is displayed. + +<p> +2. Modify the printer configuration, as needed. +<p> + +If this is an attached printer (one installed on the computer on which +you are running Solaris Print Manager) you can modify the Description, +Printer Port, Printer Type, File Contents, Fault Notification, +Options, and User Access List. + +<p> + +If this is not an attached printer, only the Description field can be +modified. You can also check or uncheck the Default Printer box. + +<p> +3. Click OK. +<p> + +The changes you made are saved and the Modify Printer Properties +dialog is dismissed. + +<p> + + If you modified the Description field, the new description is +displayed in the Solaris Print Manager main window. + +<p> + +<b> Note:</b> If you are using the NIS naming service, you have to know +the root password for the NIS master. If you are using the LDAP naming service, +you must know a fully distinguished name which has update privilege and +the corresponding password. Default values may need to be overridden. +You will be prompted for the password when you select the NIS or +LDAP naming service. Enter the password and click OK. + +<p> + +<b> Note:</b> To modify the Printer Name or Printer Server field, +delete the printer and add it with a new printer and/or server name. + +<p> + +<b>OK:</b> Apply changes and dismiss the window. +<br> +<b>Apply:</b> Apply the changes and leave the window displayed. +<br> +<b>Reset:</b> Reset all fields to last Apply +<br> +<b>Cancel:</b> Dismiss the window. +<br> +<b>Help:</b> Display help for the current window or dialog. + +<p> +</CONTENT> + +<KEYWORDS> +modify "Printer menu" "local printer" nis "nis master" "naming service" +ldap LDAP attached "network printer" local network printer properties +</KEYWORDS> + +<p> + +<SEEALSO> +Modify +ModifyFailed +InstallLocal +InstallNetwork +ToInstallLocal +ToInstallNetwork +ToAddAccess +ToDelete +AddAccess +MainWindow +Overview +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToSelectName.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToSelectName.rawhlp new file mode 100644 index 0000000000..1482d28973 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToSelectName.rawhlp @@ -0,0 +1,86 @@ +<TITLE> To Select a Naming Service </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 1999 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToSelectName --> + +<CONTENT> + +<p> + +Do the following to select a naming service for Solaris Print Manager or +to change from using a naming service to using no naming service. + +<p> + +When you select a naming service you are specifying where Solaris +Print Manager will retrieve printer information from, and where +changes made in Print Manager will be made. If a naming service is +selected, additions and deletions will be made in the printing +configuration database for the selected naming service. If you choose +"files," the /etc/printers.conf file will be used to determine which +printers are available, and changes will be made there. + +<p> + +1. Choose Select Naming Service from the Print Manager menu. + +<p> + +A dialog is displayed, asking you to choose a naming service. + +<p> + +2. Choose a naming service (or "files," if no naming service is to be +used) and click OK. + +<p> + +The Solaris Print Manager main window is displayed, listing all the +accessible printers, which includes all printers in the selected +naming service's printer configuration database. + + +<p> + +See the man page for printers.conf(4) for more information. + +</CONTENT> + +<KEYWORDS> +select "name service" "naming service" name naming service +</KEYWORDS> + +<p> + +<SEEALSO> +NameService +ToStart +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToShowCommand.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToShowCommand.rawhlp new file mode 100644 index 0000000000..448c6f3c93 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToShowCommand.rawhlp @@ -0,0 +1,78 @@ +<TITLE> To Show Command-Line Console</TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 1999 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToShowCommand --> + +<CONTENT> + +<p> + +Do the following to cause the command-line version of add, modify, and +delete actions to be displayed in the Solaris Print Manager +Command-Line Console -- or to turn off this option if it was +previously turned on. Errors and warnings may also be +displayed after the command. + +<p> + +1. Choose Show Command-Line Console from the Print Manager menu. + +<p> + +If the Show Command-line Console box was not checked when you chose +it, it will be checked and the Show Command-line Console will be +displayed; Solaris Print Manager actions will be displayed in the +Console. + +<p> + +Note that errors and warnings may also appear in the Console, after +the commands used to complete the action. + +<p> + +If the Show Command-line Console box was checked when you chose it, +it will no longer be checked and the Show Command-line Console will be +closed. + +<p> + +</CONTENT> + +<KEYWORDS> +"command-line" log command show console +</KEYWORDS> + +<p> + +<SEEALSO> +ShowCommandConsole +Overview +MainWindow +HelpOnHelp +</SEEALSO> + diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToStart.rawhlp b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToStart.rawhlp new file mode 100644 index 0000000000..d8e0fe4c1f --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/raw-help/ToStart.rawhlp @@ -0,0 +1,84 @@ +<TITLE> To Start Solaris Print Manager </TITLE> +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License, Version 1.0 only + (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 2001 Sun Microsystems, Inc. All rights reserved. +-- Use is subject to license terms. +-- +-- ident "%Z%%M% %I% %E% SMI" +--> +<!-- Tag=ToStart --> + +<CONTENT> + +<p> + +If you have installed SUNWppm package, do the following to start +Solaris Print Manager. Note that you must be root to run Print +Manager; if you attempt to launch it from Solaris Management Console +you will be prompted for the root password. + +<p> + +1. Double-click the Solaris Print Manager icon in Solaris Management +Console + +<p> + + OR + +<p> + +cd to the directory /usr/sadm/admin/bin and as root type ./printmgr + +<p> + +A dialog is displayed, asking you to choose a naming service. + +<p> + +2. Choose a naming service (or files, if no naming service is to be +used) and click OK. + +<p> + +The Solaris Print Manager main window is displayed, listing all the +printers accessible from the computer on which you are running Solaris +Print Manager. + +<p> + +</CONTENT> + +<KEYWORDS> +start startup load "name service" "naming service" SUNWppm "Solaris Management Console" +"the Console" solaris print manager +</KEYWORDS> + +<p> + +<SEEALSO> +ToSelectName +ToExit +Mainwindow +Overview +HelpOnHelp +</SEEALSO> diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Debug.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Debug.java new file mode 100644 index 0000000000..ed216885fe --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Debug.java @@ -0,0 +1,315 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * Debug class + */ + +package com.sun.admin.pm.server; + +import java.util.*; + +/** + * A simple configurable debug logging class. + * <p> + * + * Calling member classes <b>message()</b>, <b>warning()</b>, + * <b>error()</b>, and <b>fatal()</b> causes a log entry to be + * generated if the current verbosity level is greater than or equal + * to the specified severity. + * <p> + * + * Calling <b>setDebugLevel()</b> sets the verbosity level, which is a + * threshold of severity below which messages will not be logged. The + * verbosity level can be set at any time. + * <p> + * + * For example, setting the verbosity level to <b>Debug.ERROR</b> + * means that only <b>error()</b> and <b>fatal()</b> calls will + * generate log entries, while setting the level to <b>WARNING</b> + * will log <b>warning()</b> calls as well as <b>error()</b> and + * <b>fatal()</b> while ignoring <b>message()</b>. + * <p> + * + * Setting the verbosity level to <b>ALL</b> is equivalent to setting + * it to <b>MESSAGE</b>; all calls are logged. The constant + * <b>NONE</b> suppresses logging of all calls. + * <p> + * + * The verbosity level can be set globally or on a class-by-class + * basis. Use the form of <b>setDebugLevel()</b> which takes an + * argument of type Object to set the level for all instances of the + * specified class. + * <p> + * + * Using the forms of <b>message()</b>, <b>warning()</b>, + * <b>error()</b>, and <b>fatal()</b> which accept an argument of type + * Object will use the verbosity value associated with the specified + * class. If no value has been explicitly set for the class, the + * global default will be used. + * <p> + * + * At present log messages are written only to stdout. + * An enhancement would be to implement an interface to the syslog facility. + */ + + +public class Debug { + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void fatal(String s) { + printIf(s, FATAL); + } + + /** + * Log a high-priority message. + * @param String s The message to be logged. + */ + static public void error(String s) { + printIf(s, ERROR); + } + + /** + * Log a medium-priority message. + * @param String s The message to be logged. + */ + static public void warning(String s) { + printIf(s, WARNING); + } + + /** + * Log a low-priority message. + * @param String s The message to be logged. + */ + static public void message(String s) { + printIf(s, MESSAGE); + } + + + /** + * Log a lowest-priority message. + * @param String s The message to be logged. + */ + static public void info(String s) { + printIf(s, INFO); + } + + + /** + * Log a highest-priority message. + * @param String s The message to be logged. + */ + static public void fatal(Object o, String s) { + printIf(o, s, FATAL); + } + + /** + * Log a high-priority message. + * @param String s The message to be logged. + */ + static public void error(Object o, String s) { + printIf(o, s, ERROR); + } + + /** + * Log a medium-priority message. + * @param String s The message to be logged. + */ + static public void warning(Object o, String s) { + printIf(o, s, WARNING); + } + + /** + * Log a low-priority message. + * @param String s The message to be logged. + */ + static public void message(Object o, String s) { + printIf(o, s, MESSAGE); + } + + /** + * Log a lowest-priority message. + * @param String s The message to be logged. + */ + static public void info(Object o, String s) { + printIf(o, s, INFO); + } + + /** + * Set the verbosity level to the specified severity. + * @param String s The message to be logged. + */ + static public void setDebugLevel(int lvl) { + if (lvl < ALL || lvl > NONE) + return; + + globalDebugLevel = lvl; + } + + /** + * Set the verbosity level to the specified severity. + * @param String s The message to be logged. + */ + static public void setDebugLevel(Object o, int lvl) { + if (lvl < ALL || lvl > NONE) + return; + + classDB.put(o.getClass(), new Integer(lvl)); + + /* + System.out.println("Debug: class " + o.getClass().getName() + + " level = " + classDB.get(o.getClass())); + */ + } + + static public void setDebugLevel(String classname, int lvl) { + if (lvl < ALL || lvl > NONE) + return; + + try { + classDB.put(Class.forName(classname), new Integer(lvl)); + } catch (Exception x) { + System.out.println("setDebugLevel: " + x); + } + } + + + private static void printIf(String s, int lvl) { + if (lvl < globalDebugLevel) + return; + debugPrint(s); + } + + private static void printIf(Object o, String s, int lvl) { + if (lvl < getLevelForClass(o)) + return; + debugPrint(s); + } + + + /* + * get debug level for o's class, if already there + * otherwise create an entry for o and set it to the global level + */ + private synchronized static int getLevelForClass(Object o) { + int lvl = globalDebugLevel; + Object g; + if ((g = classDB.get(o.getClass())) != null) + lvl = ((Integer) g).intValue(); + else + classDB.put(o.getClass(), new Integer(lvl)); + + /* + System.out.println("Debug: getLevelForClass " + + o.getClass().getName() + + " = " + lvl); + */ + + return lvl; + } + + // here is where we could hide syslog or file destination... + private static void debugPrint(String s) { + System.out.println(s); // for now + } + + Object theInstance = null; + + public Debug(Object o) { + theInstance = o; + } + + public void SetDebugLevel(int lvl) { + if (lvl < ALL || lvl > NONE) + return; + setDebugLevel(theInstance, lvl); + } + + public void Fatal(String s) { + fatal(theInstance, s); + } + + public void Warning(String s) { + warning(theInstance, s); + } + + public void Error(String s) { + error(theInstance, s); + } + + public void Message(String s) { + message(theInstance, s); + } + + public void Info(String s) { + info(theInstance, s); + } + + /* + * Verbosity level to suppress all messages. + */ + static public final int NONE = 6; + + /* + * Verbosity level to log only highest-priority messages. + */ + static public final int FATAL = 5; + + /* + * Verbosity level to log high- and highest-priority messages. + */ + static public final int ERROR = 4; + + /* + * Verbosity level to log medium-, high-, and highest-priority messages. + */ + static public final int WARNING = 3; + + /* + * Verbosity level to log low-, medium-, high-, and + * highest-priority messages. + */ + static public final int MESSAGE = 2; + + /* + * Verbosity level to log lowest-, low-, medium-, high-, and + * highest-priority messages. + */ + static public final int INFO = 1; + + + /* + * Verbosity level to log all messages. + */ + static public final int ALL = 0; + + private static int globalDebugLevel = FATAL; + private static Hashtable classDB = new Hashtable(); + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterAdd.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterAdd.java new file mode 100644 index 0000000000..a9eaa25c6c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterAdd.java @@ -0,0 +1,551 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * DoPrinterAdd class + * Worker class for adding local and remote printers. + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +public class DoPrinterAdd { + + public static void main(String[] args) { + // + // Set attributes for testing + // + NameService ns = new NameService(); + + String file_contents[] = new String[1]; + file_contents[0] = "any"; + String user_allow_list[] = new String[1]; + user_allow_list[0] = "allow1"; + String user_deny_list[] = new String[1]; + user_deny_list[0] = "deny1"; + + Printer p = new Printer(ns); + p.setPrinterName("javatest"); + p.setPrinterType("PS"); + p.setPrintServer("zelkova"); + p.setComment("This is a comment"); + p.setDevice("/var/tmp/test"); + p.setNotify("none"); + p.setProtocol("bsd"); + p.setDestination(null); + p.setFileContents(file_contents); + p.setUserAllowList(user_allow_list); + p.setIsDefaultPrinter(false); + p.setBanner("never"); + p.setEnable(true); + p.setAccept(true); + p.setLocale(null); + + try { + add(p, ns); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + System.out.println("Commands:\n" + p.getCmdLog()); + System.out.println("Errors:\n" + p.getErrorLog()); + System.out.println("Warnings:\n" + p.getWarnLog()); + System.exit(0); + } + + // + // Interface to Printer object. + // + public static void add( + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterAdd.add()"); + + String device = p.getDevice(); + if (device == null) { + addRemote(p, ns); + } else { + addLocal(p, ns); + } + return; + } + + // + // Do the work of adding a local printer. + // + private static void addLocal( + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterAdd.addLocal()"); + + int exitvalue = 0; + String err = null; + String cmd = null; + SysCommand syscmd = null; + + // Since it's local set extensions. + // Eventually the gui should do this. + p.setExtensions("Solaris"); + + String printername = p.getPrinterName(); + String printertype = p.getPrinterType(); + String printserver = p.getPrintServer(); + String comment = p.getComment(); + String device = p.getDevice(); + String make = p.getMake(); + String model = p.getModel(); + String ppd = p.getPPD(); + String notify = p.getNotify(); + String protocol = p.getProtocol(); + String destination = p.getDestination(); + String[] file_contents = p.getFileContents(); + String[] user_allow_list = p.getUserAllowList(); + String[] user_deny_list = p.getUserDenyList(); + boolean default_printer = p.getIsDefaultPrinter(); + String banner = p.getBanner(); + boolean enable = p.getEnable(); + boolean accept = p.getAccept(); + + String nameservice = ns.getNameService(); + String ppdfile = null; + + // + // "uri" is a pseudo protocol and means that the device is + // specified in the destination. + // + if ((protocol != null) && (protocol.equals("uri"))) { + device = destination; + destination = null; + protocol = null; + } + + if (ppd != null) { + ppdfile = new String( + DoPrinterUtil.getPPDFile(make, model, ppd)); + } + + cmd = "/usr/sbin/lpadmin -p " + printername; + if (device != null) { + cmd = cmd.concat(" -v " + device); + + if (device.indexOf("://") != -1) + cmd = cmd.concat(" -m uri"); + else { + if (destination != null) + cmd = cmd.concat(" -m netstandard"); + else + cmd = cmd.concat(" -m standard"); + if (ppd != null) + cmd = cmd.concat("_foomatic"); + } + } + if (printertype != null) + cmd = cmd.concat(" -T " + printertype); + if (notify != null) + cmd = cmd.concat(" -A " + notify); + if (ppdfile != null) { + cmd = cmd.concat(" -n " + ppdfile); + } + + + if (destination != null) + cmd = cmd.concat(" -o dest=" + destination); + if (protocol != null) + cmd = cmd.concat(" -o protocol=" + protocol); + if (banner != null) + cmd = cmd.concat(" -o banner=" + banner); + + if ((file_contents != null) && (file_contents.length != 0)) { + String tmpstr = file_contents[0]; + for (int i = 1; i < file_contents.length; i++) { + tmpstr = tmpstr.concat("," + file_contents[i]); + } + cmd = cmd.concat(" -I " + tmpstr); + } else { + cmd = cmd.concat(" -I postscript"); + } + if ((user_allow_list != null) && (user_allow_list.length != 0)) { + String tmpstr = user_allow_list[0]; + for (int i = 1; i < user_allow_list.length; i++) { + tmpstr = tmpstr.concat("," + user_allow_list[i]); + } + cmd = cmd.concat(" -u allow:" + tmpstr); + } + + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + syscmd = null; + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } else { + p.setWarnLog(err); + } + syscmd = null; + + // + // lpadmin won't take allow and deny lists together + // so do the deny seperately. + // + if ((user_deny_list != null) && (user_deny_list.length != 0)) { + String tmpstr = user_deny_list[0]; + for (int i = 1; i < user_deny_list.length; i++) { + tmpstr = tmpstr.concat("," + user_deny_list[i]); + } + cmd = "/usr/sbin/lpadmin -p " + printername + + " -u deny:" + tmpstr; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + if ((comment != null) && (!comment.equals(""))) { + // + // Have to use a command array here since + // exec(String) doesn't parse quoted strings. + // + String cmd_array[] = + { "/usr/sbin/lpadmin", "-p", printername, + "-D", comment }; + cmd = "/usr/sbin/lpadmin -p " + printername + " -D " + + "\"" + comment + "\""; + p.setCmdLog(cmd); + + syscmd = new SysCommand(); + syscmd.exec(cmd_array); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // If this is the default printer set it. + // If it fails warn user. + if (default_printer) { + cmd = "/usr/sbin/lpadmin -d " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // Check to see if we should enable it. + // If it fails warn user. + if (enable) { + cmd = "/usr/bin/enable " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + // Check to see if we should accept it. + // If it fails warn user. + if (accept) { + cmd = "/usr/sbin/accept " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + doFilters(p); + + // + // Take care of name service now. + // + if (!nameservice.equals("system")) { + try { + DoPrinterNS.set("add", p, ns); + } + catch (Exception e) { + p.clearLogs(); + NameService localns = new NameService(); + // + // Back out the local printer. + // + try { + DoPrinterDelete.delete(p, localns); + } + catch (Exception e2) { + Debug.message("SVR:" + e2.getMessage()); + } + p.clearLogs(); + throw(e); + } + } + return; + } + + // + // Do the work of adding a remote printer. + // + private static void addRemote( + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterAdd.addRemote()"); + + int exitvalue = 0; + String err = null; + String cmd = ""; + String cmd_array[] = new String[7]; + SysCommand syscmd = null; + + String printername = p.getPrinterName(); + String printserver = p.getPrintServer(); + String comment = p.getComment(); + boolean default_printer = p.getIsDefaultPrinter(); + String nameservice = ns.getNameService(); + + boolean isnismaster = false; + if (nameservice.equals("nis")) { + // + // Find out if we are the nis master + // + String nshost = ns.getNameServiceHost(); + Host h = new Host(); + String lh = h.getLocalHostName(); + if (lh.equals(nshost)) + isnismaster = true; + h = null; + } + + // + // If the name service is not system and we are + // not the nis master then do the name service + // update and return. + // + if ((!nameservice.equals("system")) && (!isnismaster)) { + DoPrinterNS.set("add", p, ns); + return; + } + + cmd_array[0] = "/usr/sbin/lpadmin"; + cmd_array[1] = "-p"; + cmd_array[2] = printername; + cmd_array[3] = "-s"; + cmd_array[4] = printserver; + + if ((comment != null) && (!comment.equals(""))) { + cmd_array[5] = "-D"; + cmd_array[6] = comment; + } + + // + // Fix up cmd so we can log it. + // + for (int i = 0; i < cmd_array.length; i++) { + if (cmd_array[i] == null) + continue; + if (i == 6) { + cmd = cmd.concat("\"" + comment + "\""); + continue; + } + cmd = cmd.concat(cmd_array[i] + " "); + } + + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd_array); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + + // If this is the default printer set it. + // If it fails warn user. + if (default_printer) { + cmd = "/usr/sbin/lpadmin -d " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // + // If it's nis and we are here then we are the nis + // master. This call will do the make for us. + // + if (nameservice.equals("nis")) { + try { + DoPrinterNS.set("add", p, ns); + } + catch (Exception e) { + p.clearLogs(); + try { + // + // Back out the local printer. + // + DoPrinterDelete.delete(p, ns); + } + catch (Exception e2) + { + Debug.message("SVR:" + e2.getMessage()); + } + p.clearLogs(); + throw e; + } + } + return; + } + + + // + // Configure filters + // Look in /etc/lp/fd and configure each filter if it hasn't + // already been configured. We'll add warning messages if + // there are problems but don't consider anything here fatal. + // + private static void doFilters(Printer p) throws Exception + { + Debug.message("SVR: DoPrinterAdd.doFilters()"); + + int i = 0; + int j = 0; + String o = null; + String err = null; + String cmd = null; + String psfilters[] = null; + SysCommand syscmd = null; + + // + // Get list of potential filters + // + cmd = "/usr/bin/ls /etc/lp/fd"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + syscmd = null; + return; + } + o = syscmd.getOutput(); + syscmd = null; + if (o == null) { + return; + } + + StringTokenizer st = new StringTokenizer(o); + if (st.countTokens() == 0) { + return; + } + psfilters = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + psfilters[i] = st.nextToken(); + } + // + // Remove .fd suffix and empty slots that aren't filters. + // + for (i = 0; i < psfilters.length; i++) { + if (psfilters[i].endsWith(".fd")) { + j = psfilters[i].indexOf(".fd"); + psfilters[i] = psfilters[i].substring(0, j); + } else { + psfilters[i] = ""; + } + } + + // Get list of currently configured filters + cmd = "/usr/sbin/lpfilter -l -f all"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + + o = null; + if (syscmd.getExitValue() != 0) { + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + return; + } else { + o = syscmd.getOutput(); + } + + for (i = 0; i < psfilters.length; i++) { + if (psfilters[i].equals("")) + continue; + + // If we have filters see if this one is + // already configured. + if (o != null) { + if (o.indexOf("\"" + psfilters[i] + "\"") > -1) + continue; + } + + // Add the filter + cmd = "/usr/sbin/lpfilter -f " + psfilters[i] + + " -F /etc/lp/fd/" + psfilters[i] + ".fd"; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + + if (syscmd.getExitValue() != 0) { + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + } + syscmd = null; + } + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterDelete.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterDelete.java new file mode 100644 index 0000000000..ceeb721d84 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterDelete.java @@ -0,0 +1,197 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * DoPrinterDelete class + * Worker class for deleting a printer. + */ + +package com.sun.admin.pm.server; + +import java.io.*; + +public class DoPrinterDelete { + + // + // main for testing + // + public static void main(String[] args) { + + Printer p = null; + try { + NameService ns = new NameService(); + + p = new Printer(ns); + p.setPrinterName("javatest"); + + delete(p, ns); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + System.out.println("Commands:\n" + p.getCmdLog()); + System.out.println("Errors:\n" + p.getErrorLog()); + System.out.println("Warnings:\n" + p.getWarnLog()); + System.exit(0); + } + + // + // Interface to Printer object. + // + public static void delete( + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterDelete.delete()"); + + boolean success = true; + String err = null; + String cmd = null; + SysCommand syscmd = null; + + String printername = p.getPrinterName(); + String nameservice = ns.getNameService(); + + boolean islocal = DoPrinterUtil.isLocal(printername); + + // Take care of locally installed case first. + if (islocal) { + // See if printer is already rejected. + // Don't disable so queue can drain. + Printer curr = new Printer(); + curr.setPrinterName(printername); + try { + DoPrinterView.view(curr, ns); + } + catch (Exception e) { + Debug.message("SVR:" + e.getMessage()); + curr.setAccept(false); + } + + if (curr.getAccept()) { + cmd = "/usr/sbin/reject " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + curr = null; + try { + deleteLocal(p); + } + catch (Exception e) { + Debug.message("SVR:" + e.getMessage()); + success = false; + } + } + + // + // Check if we already removed it from /etc/printers.conf + // + boolean exists; + exists = DoPrinterUtil.exists(printername, "system"); + if (nameservice.equals("system")) { + if (exists) { + try { + deleteLocal(p); + } + catch (Exception e) { + Debug.message("SVR:" + e.getMessage()); + success = false; + } + } + } else { + if ((nameservice.equals("nis")) && exists) { + // + // Special case if we are nis master + // + Host h = new Host(); + String nshost = ns.getNameServiceHost(); + String lh = h.getLocalHostName(); + if (lh.equals(nshost)) { + try { + deleteLocal(p); + } + catch (Exception e) { + Debug.message("SVR:" + e.getMessage()); + success = false; + } + } + h = null; + } + DoPrinterNS.set("delete", p, ns); + } + if (!success) { + throw new pmException(); + } + return; + } + + private static void deleteLocal(Printer p) throws Exception + { + Debug.message("SVR: DoPrinterDelete.deleteLocal()"); + + String cmd = null; + String err = null; + SysCommand syscmd = null; + String printername = null; + + printername = p.getPrinterName(); + + // Workaround for lpadmin bug not removing default + String def = DoPrinterUtil.getDefault("system"); + if ((def != null) && (def.equals(printername))) { + cmd = "/usr/sbin/lpadmin -x _default"; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + cmd = "/usr/sbin/lpadmin -x " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (err != null) { + p.setWarnLog(err); + } + if (syscmd.getExitValue() != 0) { + syscmd = null; + throw new pmException(err); + } + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterMod.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterMod.java new file mode 100644 index 0000000000..8a991d3726 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterMod.java @@ -0,0 +1,810 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * DoPrinterMod class + * Worker class for modifying a printer. + */ + +package com.sun.admin.pm.server; + +import java.io.*; + +public class DoPrinterMod { + + // + // main for testing + // + public static void main(String[] args) { + NameService ns = new NameService(); + + String[] arr; + arr = new String[1]; + + Printer p = new Printer(); + + p.setPrinterName("javatest"); + p.setPrinterType("hplaser"); + p.setPrintServer("zelkova"); + p.setComment("This is a new comment"); + p.setDevice("/var/tmp/test"); + p.setNotify("none"); + p.setProtocol("bsd"); + p.setDestination(""); + p.setIsDefaultPrinter(true); + p.setBanner("never"); + p.setEnable(true); + p.setAccept(false); + + arr[0] = "any"; + p.setFileContents(arr); + arr[0] = "one"; + p.setUserAllowList(arr); + arr[0] = "two"; + p.setUserDenyList(arr); + + p.setLocale(null); + + try { + modify(p, ns); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + System.out.println("Commands:\n" + p.getCmdLog()); + System.out.println("Errors:\n" + p.getErrorLog()); + System.out.println("Warnings:\n" + p.getWarnLog()); + System.exit(0); + + } + + // + // Interface to Printer object. + // + public static void modify( + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterMod.modify()"); + + Printer curr = new Printer(ns); + curr.setPrinterName(p.getPrinterName()); + try { + DoPrinterView.view(curr, ns); + } + catch (Exception e) { + String err = curr.getErrorLog(); + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } + + boolean islocal = DoPrinterUtil.isLocal(p.getPrinterName()); + if (islocal) { + modifyLocal(p, curr, ns); + } else { + modifyRemote(p, curr, ns); + } + return; + } + + // + // Do the work of modifying a local printer. + // + private static void modifyLocal( + Printer p, + Printer curr, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterMod.modifyLocal()"); + + String err = null; + String cmd = null; + SysCommand syscmd = null; + + // Since it's local set extensions + // Eventually the gui should do this. + p.setExtensions("Solaris"); + + String nameservice = ns.getNameService(); + + String printername = p.getPrinterName(); + String printertype = null; + String printserver = null; + String comment = null; + String device = null; + String notify = null; + String make = null; + String model = null; + String ppd = null; + String protocol = null; + String destination = null; + String[] file_contents = null; + String[] user_allow_list = null; + String[] user_deny_list = null; + boolean default_printer = false; + String banner = null; + boolean enable = false; + boolean accept = false; + + boolean allow_changed = false; + boolean default_printer_changed = false; + boolean banner_req_changed = false; + boolean enable_changed = false; + boolean accept_changed = false; + + String ppdfile = null; + + + // + // Set the things that have changed. + // + if (!strings_equal(curr.getPrinterType(), p.getPrinterType())) + printertype = p.getPrinterType(); + if (!strings_equal(curr.getComment(), p.getComment())) { + comment = p.getComment(); + if (comment == null) { + // Comment changed to empty. + p.setComment(""); + comment = ""; + } + } + if (!strings_equal(curr.getDevice(), p.getDevice())) + device = p.getDevice(); + if (!strings_equal(curr.getNotify(), p.getNotify())) + notify = p.getNotify(); + if (!strings_equal(curr.getProtocol(), p.getProtocol())) + protocol = p.getProtocol(); + if (!strings_equal(curr.getDestination(), p.getDestination())) + destination = p.getDestination(); + + if ((!strings_equal(curr.getMake(), p.getMake())) || + (!strings_equal(curr.getModel(), p.getModel())) || + (!strings_equal(curr.getPPD(), p.getPPD()))) { + + model = p.getModel(); + make = p.getMake(); + ppd = p.getPPD(); + } + + + if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) { + default_printer = p.getIsDefaultPrinter(); + default_printer_changed = true; + } + if (curr.getEnable() != p.getEnable()) { + enable = p.getEnable(); + enable_changed = true; + } + + if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) { + default_printer = p.getIsDefaultPrinter(); + default_printer_changed = true; + } + if (curr.getEnable() != p.getEnable()) { + enable = p.getEnable(); + enable_changed = true; + } + + if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) { + default_printer = p.getIsDefaultPrinter(); + default_printer_changed = true; + } + if (curr.getEnable() != p.getEnable()) { + enable = p.getEnable(); + enable_changed = true; + } + if (curr.getAccept() != p.getAccept()) { + accept = p.getAccept(); + accept_changed = true; + } + if (!strings_equal(curr.getBanner(), p.getBanner())) { + banner = p.getBanner(); + banner_req_changed = true; + } + + if (!arrays_equal(curr.getFileContents(), p.getFileContents())) + file_contents = p.getFileContents(); + + if (!arrays_equal(curr.getUserAllowList(), p.getUserAllowList())) { + allow_changed = true; + // If the current value is "none" and the new + // value is null nothing is changing. + String[] arr = curr.getUserAllowList(); + if ((arr != null) && (arr.length != 0)) { + if (arr[0].equals("none")) { + if (p.getUserAllowList() == null) { + allow_changed = false; + } + } + } + } + if (!arrays_equal(curr.getUserDenyList(), p.getUserDenyList())) { + allow_changed = true; + } + if (allow_changed) { + user_allow_list = p.getUserAllowList(); + user_deny_list = p.getUserDenyList(); + } + + // + // if we transitioned from a "uri" pseudo protocol to a real + // network protocol supported by netstandard* / netpr, + // the device should be reset to /dev/null + // + if ((protocol != null) && (!protocol.equals("uri")) && + ((strings_equal(curr.getProtocol(), "uri")))) + device = "/dev/null"; + + // + // "uri" is a pseudo protocol and really means that the + // destination contains a device name + // + if (((protocol != null) && (protocol.equals("uri"))) || + ((destination != null) && + (strings_equal(curr.getProtocol(), "uri")))) { + device = destination; + destination = null; + protocol = null; + } + + // + // Return if nothing changed. + // + if ((printertype == null) && + (comment == null) && + (device == null) && + (notify == null) && + (protocol == null) && + (destination == null) && + (make == null) && + (model == null) && + (ppd == null) && + (file_contents == null) && + (!allow_changed) && + (!default_printer_changed) && + (!enable_changed) && + (!accept_changed) && + (!banner_req_changed)) { + return; + } + + // If this is the default printer set it. + if (default_printer_changed) { + if (default_printer) { + cmd = "/usr/sbin/lpadmin -d " + printername; + } else { + cmd = "/usr/sbin/lpadmin -x _default"; + } + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // + // If this is only a default printer change then possibly + // update the name service and return. + if ((printertype == null) && + (comment == null) && + (device == null) && + (notify == null) && + (protocol == null) && + (destination == null) && + (make == null) && + (model == null) && + (ppd == null) && + (file_contents == null) && + (!allow_changed) && + (!enable_changed) && + (!accept_changed) && + (!banner_req_changed)) { + if (nameservice.equals("system")) { + return; + } + p.modhints = "defaultonly"; + + DoPrinterNS.set("modify", p, ns); + p.modhints = ""; + return; + } + + // + // Do enable/accept + // + if (enable_changed) { + if (p.getEnable() == true) { + cmd = "/usr/bin/enable " + printername; + } else { + cmd = "/usr/bin/disable " + printername; + } + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + if (accept_changed) { + if (p.getAccept() == true) { + cmd = "/usr/sbin/accept " + printername; + } else { + cmd = "/usr/sbin/reject " + printername; + } + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // + // Build the modify command + // + cmd = "/usr/sbin/lpadmin -p " + printername; + if (device != null) { + cmd = cmd.concat(" -v " + device); + + // + // If the device is a device uri, it must use the "uri" + // model/interface script. If it's "/dev/null" and the + // protocol is set (to something other than "uri"), it should + // be reset to netstandard or netstandard_foomatic + // + if (device.indexOf("://") != 0) + cmd = cmd.concat(" -m uri"); + else if ((!device.equals("/dev/null")) && (protocol != null) && + (!protocol.equals("uri"))) { + cmd = cmd.concat(" -m netstandard"); + if (ppd != null) + cmd = cmd.concat("_foomatic"); + } + } + + if (printertype != null) + cmd = cmd.concat(" -T " + printertype); + + if (ppd != null) { + ppdfile = new String(DoPrinterUtil.getPPDFile(make, + model, ppd)); + + Debug.message("SVR:modifyLocal:ppdfile: " + ppdfile); + + cmd = cmd.concat(" -n " + ppdfile); + } + + if (notify != null) + cmd = cmd.concat(" -A " + notify); + + if (destination != null) { + cmd = cmd.concat(" -o dest=" + destination); + } + if ((protocol != null) && (!protocol.equals("uri"))) + cmd = cmd.concat(" -o protocol=" + protocol); + + if ((file_contents != null) && (file_contents.length != 0)) { + String tmpstr = file_contents[0]; + for (int i = 1; i < file_contents.length; i++) { + tmpstr = tmpstr.concat("," + file_contents[i]); + } + cmd = cmd.concat(" -I " + tmpstr); + } + + if (banner_req_changed) { + if (banner != null) { + cmd = cmd.concat(" -o banner=" + banner); + } + } + + // + // Has any of the above changed. + // + if (!cmd.equals("/usr/sbin/lpadmin -p " + printername)) { + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // + // If the user allow list changed delete all then re-add + // + if (allow_changed) { + cmd = "/usr/sbin/lpadmin -p " + printername + + " -u allow:none"; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + + if ((user_deny_list != null) && + (user_deny_list.length != 0)) { + String tmpstr = user_deny_list[0]; + for (int i = 1; i < user_deny_list.length; i++) { + tmpstr = tmpstr.concat("," + + user_deny_list[i]); + } + cmd = "/usr/sbin/lpadmin -p " + printername + + " -u deny:" + tmpstr; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + if ((user_allow_list != null) && + (user_allow_list.length != 0) && + (!user_allow_list[0].equals("none"))) { + String tmpstr = user_allow_list[0]; + for (int i = 1; i < user_allow_list.length; i++) { + tmpstr = tmpstr.concat("," + + user_allow_list[i]); + } + cmd = "/usr/sbin/lpadmin -p " + printername + + " -u allow:" + tmpstr; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + } + + if (comment != null) { + // + // Have to use a command array here since + // exec(String) doesn't parse quoted strings. + // Use lpadmin so the comment in /etc/printers.conf + // and /etc/lp/printers/comment stay in sync. + // + String cmd_array[] = + { "/usr/sbin/lpadmin", "-D", + comment, "-p", printername }; + cmd = "/usr/sbin/lpadmin -D " + + "\"" + comment + "\"" + " -p " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd_array); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + if (comment.equals("")) { + // + // LPADMIN BUG. Comment not cleared in printers.conf + // so force it with lpset. + // + cmd = "/usr/bin/lpset -a description= " + printername; + syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + err = syscmd.getError(); + p.setWarnLog(err); + } + syscmd = null; + } + } + + // + // Return if we don't need to touch the name service. + // + if (nameservice.equals("system")) { + return; + } + if ((comment == null) && (!default_printer_changed)) { + return; + } + + DoPrinterNS.set("modify", p, ns); + return; + } + + // + // Do the work of modifying a remote printer. + // + private static void modifyRemote( + Printer p, + Printer curr, + NameService ns) throws Exception + { + int exitvalue = 0; + String err = null; + String cmd = null; + String cmd_array[] = new String[4]; + SysCommand syscmd = null; + + String printername = null; + String printserver = null; + String comment = null; + String extensions = null; + boolean default_printer = false; + boolean default_printer_changed = false; + + String nameservice = ns.getNameService(); + + printername = p.getPrinterName(); + if (!strings_equal(curr.getPrintServer(), p.getPrintServer())) + printserver = p.getPrintServer(); + if (!strings_equal(curr.getComment(), p.getComment())) { + comment = p.getComment(); + if (comment == null) { + // The comment changed to empty. + p.setComment(""); + comment = ""; + } + } +// +// Don't support extensions in the gui yet. +// If they exist leave them alone. +// EXTENSIONS + p.setExtensions(curr.getExtensions()); + if (!strings_equal(curr.getExtensions(), p.getExtensions())) + extensions = p.getExtensions(); + if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) { + default_printer = p.getIsDefaultPrinter(); + default_printer_changed = true; + } + + // + // Return if nothing changed. + // + if ((printserver == null) && + (extensions == null) && + (comment == null) && + (!default_printer_changed)) { + return; + } + + // + // If this is only a default printer change then set modhints + // + if ((printserver == null) && + (extensions == null) && + (comment == null)) { + p.modhints = "defaultonly"; + } + + + // + // Find out if we are the nis master + // + boolean isnismaster = false; + if (nameservice.equals("nis")) { + String nshost = ns.getNameServiceHost(); + Host h = new Host(); + String lh = h.getLocalHostName(); + if (lh.equals(nshost)) + isnismaster = true; + h = null; + } + + // + // If we are not updating system and we are not the nis + // master then update the name service and return. + // + if ((!nameservice.equals("system")) && (!isnismaster)) { + DoPrinterNS.set("modify", p, ns); + p.modhints = ""; + return; + } + p.modhints = ""; + + // + // Take care of the bsdaddr attribute + // + // EXTENSIONS + // The gui doesn't support extensions yet so the goal + // here is to prepare for it but don't actually + // modify them. + // + if ((printserver != null) || (extensions != null)) { + // If printserver is null we are changing + // extensions. Set printserver to its current + // value. + if (printserver == null) { + printserver = curr.getPrintServer(); + } + String bsdaddr = "bsdaddr=" + printserver + "," + + printername; + // + // Leave the extensions alone + // EXTENSIONS + // + extensions = curr.getExtensions(); + if (extensions != null) { + bsdaddr = bsdaddr.concat("," + extensions); + } + cmd = "/usr/bin/lpset -a " + bsdaddr + " " + printername; + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + if (comment != null) { + cmd = "/usr/bin/lpset" + " -a description=" + + "\"" + comment + "\"" + + " " + printername; + cmd_array[0] = "/usr/bin/lpset"; + cmd_array[1] = "-a"; + cmd_array[2] = "description=" + comment; + cmd_array[3] = printername; + + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd_array); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // If this is the default printer set it. + if (default_printer_changed) { + if (default_printer) { + cmd = "/usr/sbin/lpadmin -d " + printername; + } else { + cmd = "/usr/sbin/lpadmin -x _default"; + } + p.setCmdLog(cmd); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } + if (err != null) { + p.setWarnLog(err); + } + syscmd = null; + } + + // + // If it's nis and we are here then we are the nis + // master. This call will do the make for us. + // + if (nameservice.equals("nis")) { + DoPrinterNS.set("modify", p, ns); + } + return; + } + + private static boolean arrays_equal(String[] arr1, String[] arr2) + { + if ((arr1 == null) && (arr2 == null)) { + return (true); + } + if ((arr1 == null) || (arr2 == null)) { + return (false); + } + if (arr1.length != arr2.length) { + return (false); + } + + int i, j; + String str; + boolean found; + for (i = 0; i < arr1.length; i++) { + found = false; + str = arr1[i]; + for (j = 0; j < arr2.length; j++) { + if (str.equals(arr2[j])) { + found = true; + } + } + if (found == false) { + return (false); + } + } + return (true); + } + + private static boolean strings_equal(String str1, String str2) + { + if ((str1 == null) && (str2 == null)) { + return (true); + } + if ((str1 == null) || (str2 == null)) { + return (false); + } + + return (str1.equals(str2)); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterNS.c b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterNS.c new file mode 100644 index 0000000000..2cd059860d --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterNS.c @@ -0,0 +1,276 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* LINTLIBRARY */ + +#include <stdio.h> +#include <strings.h> +#include <libintl.h> +#include "com_sun_admin_pm_server_DoPrinterNS.h" + +jstring glob_jstdout = NULL; +jstring glob_jstderr = NULL; + +extern char glob_stdout[]; +extern char glob_stderr[]; + +void set_stderr(JNIEnv *env); +void set_stdout(JNIEnv *env); +extern int _dorexec( + const char *host, + const char *user, + const char *passwd, + const char *cmd, + const char *locale); + +extern int _updateoldyp( + const char *action, + const char *printername, + const char *printserver, + const char *extensions, + const char *comment, + const char *isdefault); + +extern int _updateldap( + const char *action, + const char *host, + const char *user, + const char *passwd, + const char *printername, + const char *printserver, + const char *extensions, + const char *comment, + const char *isdefault); + +JNIEXPORT jint JNICALL +Java_com_sun_admin_pm_server_DoPrinterNS_dorexec( + JNIEnv *env, + jclass class, + jstring jhost, + jstring juser, + jstring jpasswd, + jstring jcmd, + jstring jlocale) +{ + const char *host; + const char *user; + const char *passwd; + const char *cmd; + const char *locale; + + int ret = 0; + jstring empty = (*env)->NewStringUTF(env, ""); + glob_jstdout = (*env)->NewGlobalRef(env, empty); + glob_jstderr = (*env)->NewGlobalRef(env, empty); + + host = (*env)->GetStringUTFChars(env, jhost, 0); + user = (*env)->GetStringUTFChars(env, juser, 0); + passwd = (*env)->GetStringUTFChars(env, jpasswd, 0); + cmd = (*env)->GetStringUTFChars(env, jcmd, 0); + locale = (*env)->GetStringUTFChars(env, jlocale, 0); + + ret = _dorexec(host, user, passwd, cmd, locale); + + if (ret != 0) { + (void) set_stderr(env); + return (ret); + } + (void) set_stderr(env); + (void) set_stdout(env); + return (ret); +} + +JNIEXPORT jstring JNICALL +Java_com_sun_admin_pm_server_DoPrinterNS_getstderr(JNIEnv *env, jclass class) +{ + return (glob_jstderr); +} + +JNIEXPORT jstring JNICALL +Java_com_sun_admin_pm_server_DoPrinterNS_getstdout(JNIEnv *env, jclass class) +{ + return (glob_jstdout); +} + +void +set_stderr(JNIEnv *env) +{ + static jstring jerrstr; + static char errbuf[BUFSIZ]; + + if (*glob_stderr == '\0') { + (void) strcpy(errbuf, ""); + } else { + (void) strcpy(errbuf, glob_stderr); + } + + jerrstr = (*env)->NewStringUTF(env, ""); + if (glob_jstderr != NULL) { + (*env)->DeleteGlobalRef(env, glob_jstderr); + } + + jerrstr = (*env)->NewStringUTF(env, errbuf); + glob_jstderr = (*env)->NewGlobalRef(env, jerrstr); +} + +void +set_stdout(JNIEnv *env) +{ + static jstring joutstr; + static char outbuf[BUFSIZ]; + + if (*glob_stdout == '\0') { + (void) strcpy(outbuf, ""); + } else { + (void) strcpy(outbuf, glob_stdout); + } + + joutstr = (*env)->NewStringUTF(env, ""); + if (glob_jstdout != NULL) { + (*env)->DeleteGlobalRef(env, glob_jstdout); + } + + joutstr = (*env)->NewStringUTF(env, outbuf); + glob_jstdout = (*env)->NewGlobalRef(env, joutstr); +} + +JNIEXPORT jint JNICALL +Java_com_sun_admin_pm_server_DoPrinterNS_updateoldyp( + JNIEnv *env, + jclass class, + jstring jaction, + jstring jprintername, + jstring jprintserver, + jstring jextensions, + jstring jcomment, + jstring jisdefault) +{ + const char *action = NULL; + const char *printername = NULL; + const char *printserver = NULL; + const char *extensions = NULL; + const char *comment = NULL; + const char *isdefault = NULL; + + int ret = 0; + jstring empty = (*env)->NewStringUTF(env, ""); + glob_jstdout = (*env)->NewGlobalRef(env, empty); + glob_jstderr = (*env)->NewGlobalRef(env, empty); + + action = (*env)->GetStringUTFChars(env, jaction, 0); + printername = (*env)->GetStringUTFChars(env, jprintername, 0); + if (jprintserver != NULL) { + printserver = + (*env)->GetStringUTFChars(env, jprintserver, 0); + } + if (jextensions != NULL) { + extensions = + (*env)->GetStringUTFChars(env, jextensions, 0); + } + if (jcomment != NULL) { + comment = + (*env)->GetStringUTFChars(env, jcomment, 0); + } + isdefault = (*env)->GetStringUTFChars(env, jisdefault, 0); + + ret = _updateoldyp(action, printername, printserver, + extensions, comment, isdefault); + + if (ret != 0) { + (void) set_stderr(env); + return (ret); + } + (void) set_stderr(env); + (void) set_stdout(env); + return (ret); +} + +JNIEXPORT jint JNICALL +Java_com_sun_admin_pm_server_DoPrinterNS_updateldap( + JNIEnv *env, + jclass class, + jstring jaction, + jstring jhost, + jstring jbinddn, + jstring jpasswd, + jstring jprintername, + jstring jprintserver, + jstring jextensions, + jstring jcomment, + jstring jisdefault) +{ + const char *action = NULL; + const char *host = NULL; + const char *binddn = NULL; + const char *passwd = NULL; + const char *printername = NULL; + const char *printserver = NULL; + const char *extensions = NULL; + const char *comment = NULL; + const char *isdefault = NULL; + + int ret = 0; + jstring empty = (*env)->NewStringUTF(env, ""); + glob_jstdout = (*env)->NewGlobalRef(env, empty); + glob_jstderr = (*env)->NewGlobalRef(env, empty); + + action = (*env)->GetStringUTFChars(env, jaction, 0); + printername = (*env)->GetStringUTFChars(env, jprintername, 0); + if (jhost != NULL) { + host = (*env)->GetStringUTFChars(env, jhost, 0); + } + if (jbinddn != NULL) { + binddn = (*env)->GetStringUTFChars(env, jbinddn, 0); + } + if (jpasswd != NULL) { + passwd = (*env)->GetStringUTFChars(env, jpasswd, 0); + } + if (jprintserver != NULL) { + printserver = + (*env)->GetStringUTFChars(env, jprintserver, 0); + } + if (jextensions != NULL) { + extensions = + (*env)->GetStringUTFChars(env, jextensions, 0); + } + if (jcomment != NULL) { + comment = + (*env)->GetStringUTFChars(env, jcomment, 0); + } + isdefault = (*env)->GetStringUTFChars(env, jisdefault, 0); + + ret = _updateldap(action, host, binddn, passwd, printername, + printserver, extensions, comment, isdefault); + + if (ret != 0) { + (void) set_stderr(env); + return (ret); + } + (void) set_stderr(env); + (void) set_stdout(env); + return (ret); +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterNS.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterNS.java new file mode 100644 index 0000000000..3be06520b4 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterNS.java @@ -0,0 +1,649 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * DoPrinterNS class + * Worker class for updating name services. + * Interfaces to JNI code. + */ + +package com.sun.admin.pm.server; + +public class DoPrinterNS +{ + // + // JNI member functions + // + private synchronized static native int dorexec(String nshost, + String user, String passwd, String cmd, String locale); + private synchronized static native int updateoldyp(String action, + String printername, String printserver, String extensions, + String comment, String isdefault); + private synchronized static native int updateldap(String action, + String host, String binddn, String passwd, + String printername, String printserver, String extensions, + String comment, String isdefault); + private synchronized static native String getstderr(); + private synchronized static native String getstdout(); + + // + // Load JNI. + // + static + { + System.loadLibrary("pmgr"); + } + + // + // main for testing + // + public static void main(String[] args) { + // + // Set attributes for testing. + // + NameService ns = null; + try { + ns = new NameService("nis"); + } + catch (Exception e) { + System.out.println(e); + System.exit(1); + } + ns.setPasswd(""); + + Printer p = new Printer(ns); + p.setPrinterName("javatest"); + p.setPrintServer("zelkova"); + p.setComment("This is a comment"); + p.setIsDefaultPrinter(false); + p.setLocale(null); + + String action = "add"; + if (args.length >= 1) + action = args[0]; + try { + set(action, p, ns); + } + catch (Exception e) { + System.out.println(e); + } + System.out.println("Commands:\n" + p.getCmdLog()); + System.out.println("Errors:\n" + p.getErrorLog()); + System.out.println("Warnings:\n" + p.getWarnLog()); + System.exit(0); + } + + // + // Interface to DoPrinter[add|mod|delete] + // + public static void set( + String action, + Printer p, + NameService ns) throws Exception + { + String nameservice = ns.getNameService(); + + if (nameservice.equals("system")) { + return; + } else if (nameservice.equals("nis")) { + setNIS(action, p, ns); + return; + } + setNS(action, p, ns); + return; + } + + private static void setNIS( + String action, + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterNS.setNIS(): " + action); + + String printername = p.getPrinterName(); + String printserver = p.getPrintServer(); + String comment = p.getComment(); + String extensions = p.getExtensions(); + boolean default_printer = p.getIsDefaultPrinter(); + String locale = p.getLocale(); + if (locale == null) + locale = "C"; + + String nameservice = ns.getNameService(); + String nshost = ns.getNameServiceHost(); + String user = ns.getUser(); + String passwd = ns.getPasswd(); + + String cmd = null; + String err = null; + int ret = 0; + int exitvalue = 0; + + // + // If this is the nis master we only need to do the make + // locally. + // + Host h = new Host(); + String lh = h.getLocalHostName(); + if (lh.equals(nshost)) { + cmd = "/usr/ccs/bin/make -f /var/yp/Makefile"; + cmd = cmd.concat(" -f /usr/lib/print/Makefile.yp "); + cmd = cmd.concat("printers.conf"); + + p.setCmdLog(cmd); + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else { + // ignore touch warning + // p.setWarnLog(err); + } + syscmd = null; + return; + } + + String cmdprefix = "rexec(" + nshost + "): "; + + cmd = "/usr/bin/echo"; + Debug.message("SVR: " + cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + if (ret != 0) { + throw new pmAuthException(getstderr()); + } + // + // Do we have lpset + // + cmd = "/usr/bin/ls /usr/bin/lpset"; + Debug.message("SVR: " + cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + if (ret != 0) { + throw new pmCmdFailedException(getstderr()); + } + String tmpstr = getstdout(); + tmpstr = tmpstr.trim(); + if (!tmpstr.equals("/usr/bin/lpset")) { + Debug.message("SVR: No lpset found. Checking rhosts."); + + // Are we set up in rhosts? + cmd = "rsh "; + cmd = cmd.concat(nshost); + cmd = cmd.concat(" echo"); + + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + syscmd = null; + throw new pmAuthRhostException(err); + } + syscmd = null; + // + // We don't have lpset. Must be pre-2.6 master. + // We are set up in rhosts so use libprint + // to update it. + // + p.setCmdLog("rsh " + nshost + "..."); + String def = "false"; + if (default_printer) + def = "true"; + + Debug.message("SVR: updateoldyp(): "); + Debug.message("SVR: action=" + action); + Debug.message("SVR: printername=" + printername); + Debug.message("SVR: printserver=" + printserver); + Debug.message("SVR: extensions=" + extensions); + Debug.message("SVR: comment=" + comment); + Debug.message("SVR: default=" + def); + + ret = updateoldyp(action, printername, + printserver, extensions, comment, def); + if (ret != 0) { + throw new pmCmdFailedException("libprint"); + } + return; + } + + // + // Add and modify are the same + // + boolean domake = false; + if (!action.equals("delete")) { + // + // If we are here from a modify and only need + // to change the default printer ... + // + if (!p.modhints.equals("defaultonly")) { + String bsdaddr = "bsdaddr=" + printserver + "," + + printername; + if (extensions != null) { + bsdaddr = bsdaddr.concat("," + extensions); + } + cmd = "/usr/bin/lpset -a " + bsdaddr; + if (comment != null) { + cmd = cmd.concat(" -a " + "description=" + + "\"" + comment + "\""); + } + cmd = cmd.concat(" " + printername); + + Debug.message("SVR: " + cmdprefix + cmd); + p.setCmdLog(cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + err = getstderr(); + if (ret != 0) { + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } + if (!err.equals("")) { + p.setWarnLog(err); + } + domake = true; + } + + cmd = null; + String def = DoPrinterUtil.getDefault("nis"); + if (default_printer) { + if (!printername.equals(def)) { + cmd = "/usr/bin/lpset -a " + "use=" + + printername + " _default"; + } + } else { + if ((def != null) && (def.equals(printername))) { + // + // It was the default but not any more. + // + cmd = "/usr/bin/lpset -x _default"; + } + } + if (cmd != null) { + Debug.message("SVR: " + cmdprefix + cmd); + p.setCmdLog(cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + err = getstderr(); + if (ret != 0) { + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } + if (!err.equals("")) { + p.setWarnLog(err); + } + domake = true; + } + } else { + if (DoPrinterUtil.exists(printername, "nis")) { + // delete + cmd = "/usr/bin/lpset -x " + printername; + Debug.message("SVR: " + cmdprefix + cmd); + p.setCmdLog(cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + err = getstderr(); + if (ret != 0) { + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } + if (!err.equals("")) { + p.setWarnLog(err); + } + domake = true; + } + String def = DoPrinterUtil.getDefault("nis"); + if ((def != null) && (def.equals(printername))) { + cmd = "/usr/bin/lpset -x _default"; + Debug.message("SVR: " + cmdprefix + cmd); + p.setCmdLog(cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + err = getstderr(); + if (ret != 0) { + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } + if (!err.equals("")) { + p.setWarnLog(err); + } + domake = true; + } + } + if (!domake) { + return; + } + + cmd = "cd /var/yp; /usr/ccs/bin/make -f /var/yp/Makefile"; + cmd = cmd.concat(" -f /usr/lib/print/Makefile.yp printers.conf"); + Debug.message("SVR: " + cmdprefix + cmd); + p.setCmdLog(cmdprefix + cmd); + ret = dorexec(nshost, user, passwd, cmd, locale); + err = getstderr(); + if (ret != 0) { + p.setErrorLog(err); + throw new pmCmdFailedException(err); + } + if (!err.equals("")) { + p.setWarnLog(err); + } + return; + } + + private static void setNS( + String action, + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterNS.setNS(): " + action); + + String printername = p.getPrinterName(); + String printserver = p.getPrintServer(); + String extensions = p.getExtensions(); + String comment = p.getComment(); + boolean default_printer = p.getIsDefaultPrinter(); + + String nameservice = ns.getNameService(); + + String nshost = ns.getNameServiceHost(); + String user = ns.getUser(); + String passwd = ns.getPasswd(); + + int exitvalue; + SysCommand syscmd = null; + String err; + String cmd = null; + String cmd_log = null; + String cmd_array[] = new String[14]; + + int index = 0; + String base_cmd = "/usr/bin/lpset -n " + nameservice; + String base_cmd_log = "/usr/bin/lpset -n " + nameservice; + + cmd_array[index++] = "/usr/bin/lpset"; + cmd_array[index++] = "-n"; + cmd_array[index++] = nameservice; + + /* + * Use jni to update ldap since the passwd is sensitive. + */ + if (nameservice.equals("ldap")) { + + if ((nshost == null) || (nshost.equals(""))) { + throw new pmInternalErrorException( + "Missing LDAP host for ldap operation"); + } + if ((user == null) && (user.equals(""))) { + throw new pmInternalErrorException( + "Missing Binddn for ldap operation"); + } + if ((passwd == null) && (passwd.equals(""))) { + throw new pmInternalErrorException( + "Missing passwd for ldap operation"); + } + + p.setCmdLog("ldap ..."); + + String def = "false"; + if (default_printer) + def = "true"; + + Debug.message("SVR: updateldap(): "); + Debug.message("SVR: action=" + action); + Debug.message("SVR: host=" + nshost); + Debug.message("SVR: binddn=" + user); + Debug.message("SVR: passwd=****"); + Debug.message("SVR: printername=" + printername); + Debug.message("SVR: printserver=" + printserver); + Debug.message("SVR: extensions=" + extensions); + Debug.message("SVR: comment=" + comment); + Debug.message("SVR: default=" + def); + + exitvalue = updateldap(action, nshost, user, passwd, + printername, printserver, extensions, comment, + def); + + if (exitvalue != 0) { + throw new pmCmdFailedException("libprint"); + } + return; + } + + // + // Add and modify are the same + // + if (!action.equals("delete")) { + // + // If we are here for a modify and we're only setting + // the default printer ... + // + if (!p.modhints.equals("defaultonly")) { + String bsdaddr = "bsdaddr=" + printserver + "," + + printername; + if (extensions != null) { + bsdaddr = bsdaddr.concat("," + extensions); + } + cmd_array[index++] = "-a"; + cmd_array[index++] = bsdaddr; + cmd_log = base_cmd_log + " -a " + bsdaddr; + if (comment != null) { + cmd_array[index++] = "-a"; + cmd_array[index++] = "description=" + comment; + cmd_log = cmd_log.concat(" -a " + + "description=" + "\"" + comment + "\""); + } + cmd_array[index++] = printername; + cmd_log = cmd_log.concat(" " + printername); + + p.setCmdLog(cmd_log); + syscmd = new SysCommand(); + syscmd.exec(cmd_array); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else { + p.setWarnLog(err); + } + syscmd = null; + } + cmd = null; + cmd_log = null; + String args = null; + String def = DoPrinterUtil.getDefault(nameservice); + if (default_printer) { + if (!printername.equals(def)) { + args = " -a " + "use=" + printername + + " _default"; + cmd = base_cmd + args; + cmd_log = base_cmd_log + args; + } + } else { + if ((def != null) && (def.equals(printername))) { + // + // It was the default but not any more. + // + args = " -x _default"; + cmd = base_cmd + args; + cmd_log = base_cmd_log + args; + } + } + if (cmd != null) { + p.setCmdLog(cmd_log); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else { + p.setWarnLog(err); + } + syscmd = null; + } + } else { + if (DoPrinterUtil.exists(printername, nameservice)) { + // delete + cmd = base_cmd + " -x " + printername; + cmd_log = base_cmd_log + " -x " + printername; + p.setCmdLog(cmd_log); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else { + p.setWarnLog(err); + } + syscmd = null; + + } + String def = DoPrinterUtil.getDefault(nameservice); + if ((def != null) && (def.equals(printername))) { + cmd = base_cmd + " -x _default"; + cmd_log = base_cmd_log + " -x _default"; + p.setCmdLog(cmd_log); + syscmd = new SysCommand(); + syscmd.exec(cmd); + err = syscmd.getError(); + if (syscmd.getExitValue() != 0) { + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } else { + p.setWarnLog(err); + } + syscmd = null; + } + } + return; + } + + public static boolean doAuth(NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterNS.checkAuth()"); + + String nsname = ns.getNameService(); + String host = ns.getNameServiceHost(); + String user = ns.getUser(); + String passwd = ns.getPasswd(); + + if (nsname.equals("system")) { + if (!isRoot()) { + Debug.error( + "SVR: User does not have root priveleges."); + throw new pmAuthException(); + } + } else if (nsname.equals("nis")) { + Host h = new Host(); + String lh = h.getLocalHostName(); + String nm = h.getNisHost("master"); + if (lh.equals(nm)) { + // Since we are on the NIS master the + // check is the same as for "system". + Debug.message("SVR: Host is NIS master."); + if (!isRoot()) { + Debug.error( + "SVR: User does not have root access."); + throw new pmAuthException(); + } + } + int ret = dorexec(host, user, passwd, "/usr/bin/echo", "C"); + if (ret != 0) { + Debug.error( + "SVR: User does not have NIS update access."); + throw new pmAuthException(getstderr()); + } + } else if (nsname.equals("nisplus")) { + String cmd = null; + SysCommand syscmd = new SysCommand(); + + cmd = "/usr/bin/lpset -n " + nsname; + cmd = cmd.concat(" -a testauth=true _pmTestAuthToken"); + syscmd.exec(cmd); + int ret = syscmd.getExitValue(); + String err = syscmd.getError(); + syscmd = null; + if (ret != 0) { + Debug.error( + "SVR: User does not have NIS+ update priveleges."); + syscmd = null; + throw new pmAuthException(err); + } + syscmd = new SysCommand(); + cmd = "/usr/bin/lpset -n " + nsname + " -x _pmTestAuthToken"; + syscmd.exec(cmd); + syscmd = null; + } else if (nsname.equals("ldap")) { + int ret = updateldap("add", host, user, passwd, + "_pmTestAuthToken", null, null, null, "false"); + + if (ret != 0) { + Debug.error( + "SVR: User does not have LDAP update priveleges."); + throw new pmAuthException(); + } + ret = updateldap("delete", host, user, passwd, + "_pmTestAuthToken", null, null, null, "false"); + + } else { + throw new pmInternalErrorException( + "doAuth(): Invalid name service: " + nsname); + } + return (true); + } + + public static void doCheckRootPasswd(String p) + throws Exception + { + Host h = new Host(); + String lh = h.getLocalHostName(); + + int ret = dorexec(lh, "root", p, "/usr/bin/echo", "C"); + if (ret != 0) { + throw new pmAuthException(getstderr()); + } + return; + } + + public static boolean isRoot() + throws Exception + { + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/id", "LC_ALL=C"); + + String o = syscmd.getOutput(); + + if (o == null) { + throw new pmCmdFailedException(syscmd.getError()); + } + if (o.indexOf("uid=0(") == -1) { + return (false); + } + return (true); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterUtil.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterUtil.java new file mode 100644 index 0000000000..274cd51116 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterUtil.java @@ -0,0 +1,533 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * DoPrinterUtil class + * Worker utility class. + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +public class DoPrinterUtil { + + public static String getDefault(String ns) throws Exception + { + Debug.message("SVR: DoPrinterUtil.getDefault()"); + Debug.message("SVR: name service equals " + ns); + + String o = null; + String cmd = "/usr/bin/lpget -n " + ns + " _default"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + o = syscmd.getOutput(); + syscmd = null; + + if (o == null) { + return (null); + } + int i = o.indexOf("use="); + if (i == -1) { + return (null); + } + o = o.substring(i); + String dflt = DoPrinterView.getToken(o + "\n", "use="); + + Debug.message("SVR: default is " + dflt); + return (new String(dflt)); + } + + public static String[] getDevices() throws Exception + { + Debug.message("SVR: DoPrinterUtil.getDevices()"); + + int i = 0; + String dev = ""; + String devices = ""; + + String serial_possibilities[] = {"a", "b", "c", "d", + "e", "f", "g", "h", "i", "j", "k", "l", "m", + "n", "o", "p", "q", "r", "s", "t", "u", "v", + "w", "x", "y", "z"}; + + String cmd = "/usr/bin/find /dev -print"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + + String o = syscmd.getOutput(); + syscmd = null; + + if (o == null) { + return (null); + } + o = o.concat("\n"); + + for (i = 0; i < serial_possibilities.length; i++) { + dev = "/dev/term/" + serial_possibilities[i] + "\n"; + if (o.indexOf(dev) != -1) { + devices = devices.concat(" " + dev + " "); + } + } + // sparc bpp parallel ports + for (i = 0; i < 100; i++) { + dev = "/dev/bpp" + i + "\n"; + if (o.indexOf(dev) != -1) { + devices = devices.concat(" " + dev + " "); + } + } + // sparc ecpp parallel ports + for (i = 0; i < 100; i++) { + dev = "/dev/ecpp" + i + "\n"; + if (o.indexOf(dev) != -1) { + devices = devices.concat(" " + dev + " "); + } + } + // intel parallel ports + for (i = 0; i < 100; i++) { + dev = "/dev/lp" + i + "\n"; + if (o.indexOf(dev) != -1) { + devices = devices.concat(" " + dev + " "); + } + } + + // USB + for (i = 0; i < 100; i++) { + dev = "/dev/printers/" + i + "\n"; + if (o.indexOf(dev) != -1) { + devices = devices.concat(" " + dev + " "); + } + } + + // SunPics + dev = "/dev/lpvi\n"; + if (o.indexOf(dev) != -1) { + devices = devices.concat(" " + dev + " "); + } + + o = null; + + if (devices.equals("")) { + return (null); + } + + String ret[]; + StringTokenizer st = new StringTokenizer(devices); + if (st.countTokens() == 0) { + return (null); + } else { + ret = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + ret[i] = st.nextToken(); + } + } + return (ret); + } + + public static String[] getMakes() throws Exception + { + int i; + + Debug.message("SVR: DoPrinterUtil.getMakes()"); + + String cmd = "/usr/lib/lp/bin/getmakes"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + String makes = syscmd.getOutput(); + + String ret[]; + StringTokenizer st = new StringTokenizer(makes); + if (st.countTokens() == 0) { + return (null); + } else { + ret = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + ret[i] = st.nextToken(); + + } + } + return (ret); + + } + public static String[] getModels(String make) throws Exception + { + int i; + String ret[]; + + Debug.message("SVR:getModels()"); + + if (make == null) { + Debug.message("SVR:getModels: make is null"); + return (null); + } + // Make call for models for this make + String cmd = "/usr/lib/lp/bin/getmodels " + make; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + String models = syscmd.getOutput(); + + if (models != null) { + StringTokenizer st = new StringTokenizer(models, "\n"); + if (st.countTokens() == 0) { + Debug.message("SVR:String tokenizer count is zero"); + return (null); + } else { + ret = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + ret[i] = st.nextToken(); + + } + } + return (ret); + } else + return (null); + } + + public static String[] getPPDs(String make, String model) throws Exception + { + int i; + String ret[]; + ret = new String[2]; + if ((make == null) || (model == null)) { + return null; + } + // get ppd files for this make/model + String cmd = "/usr/lib/lp/bin/getppds " + make + " " + model; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + String ppds = syscmd.getOutput(); + StringTokenizer st = new StringTokenizer(ppds, "\n"); + if (st.countTokens() == 0) { + return (null); + } else { + ret = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + ret[i] = st.nextToken(); + + } + } + return (ret); + } + + public static String[] getMakeModelNick(String ppdfilename) throws Exception + { + int i; + String ret[] = null; + if (ppdfilename == null) { + return (null); + } + // get ppd files for this make/model + String cmd = "/usr/lib/lp/bin/ppdfilename2mmp " + ppdfilename; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + String mmp = syscmd.getOutput(); + + if (mmp != null) { + ret = new String[2]; + + StringTokenizer st = new StringTokenizer(mmp, "\n"); + if (st.countTokens() == 0) { + return (null); + } else { + ret = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + ret[i] = st.nextToken(); + + } + } + } + return (ret); + } + + public static String getPPDFile( + String make, String model, String ppd) throws Exception + { + int i; + String ret[]; + ret = new String[2]; + if (ppd == null) { + return (null); + } + // get ppd path/filename for this ppd + String cmd = "/usr/lib/lp/bin/getppdfile " + + make + ":" + " " + model + ":" + " " + ppd + ":"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + String ppdfile = syscmd.getOutput(); + + return (ppdfile); + } + + + public static String[] getProbe(String device) + { + int i; + String pmake = null; + String pmodel = null; + String tokens[] = null; + String ret[]; + ret = new String[2]; + + if (device == null) + return (null); + + Debug.message("SVR: DoPrinterUtil.getProbe()"); + + // Get Manufacturer and Model for printer in this port + String cmd = "/usr/lib/lp/bin/printer-info -M -m " + device; + SysCommand syscmd = new SysCommand(); + try { + syscmd.exec(cmd); + } catch (Exception e) { + System.out.println(e); + } + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + return (null); + } + + String mm = syscmd.getOutput(); + if (mm != null) { + int numtokens; + StringTokenizer st = new StringTokenizer(mm, ":" + "\n"); + if (st.countTokens() == 0) { + return (null); + } else { + numtokens = st.countTokens(); + tokens = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + tokens[i] = st.nextToken(); + } + } + for (i = 0; i < numtokens; i++) { + if ((tokens[i].trim()).equals("Manufacturer")) { + pmake = new String(tokens[i + 1].trim()); + } else { if ((tokens[i].trim()).equals("Model")) + pmodel = new String(tokens[i + 1].trim()); + } + } + + if (pmake != null) + ret[0] = pmake; + if (pmodel != null) + ret[1] = pmodel; + + return (ret); + } + return (null); + + } + + public static boolean isMakeModel( + String make, + String model) + { + int exitvalue; + + Debug.message("SVR: DoPrinterUtil.isMakeModel() " + make + " " + model); + + SysCommand syscmd = new SysCommand(); + // syscmd.exec("/usr/bin/lpget -n " + ns + " " + name); + exitvalue = syscmd.getExitValue(); + syscmd = null; + if (exitvalue == 0) { + return (true); + } + return (false); + } + + + public static String[] getList(String nsarg) + throws Exception + { + Debug.message("SVR: DoPrinterUtil.getList()"); + + int i = 0; + int j = 0; + int listi = 0; + + String cmd = null; + String printername = ""; + String printserver = ""; + String comment = ""; + String nameservice; + String list[]; + + String o = null; + cmd = "/usr/bin/lpget -n " + nsarg + " list"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String errstr = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(errstr); + } + o = syscmd.getOutput(); + syscmd = null; + + if (o == null) { + return (null); + } + + // Count entries + int index = 0; + while ((index = o.indexOf("bsdaddr=", index)) != -1) { + index = index + 8; + i++; + } + if (i <= 0) + return (null); + + list = new String [i*3]; + + int colon = 0; + int nextcolon = 0; + while ((colon = o.indexOf(":\n", colon + 1)) != -1) { + nextcolon = o.indexOf(":\n", colon + 1); + if (nextcolon == -1) + nextcolon = o.length(); + // Extract printername + i = colon; + while ((o.charAt(i) != '\n') && (i != 0)) { + i--; + } + if (i == 0) + printername = o.substring(i, colon); + else + printername = o.substring(i + 1, colon); + + // Skip _all and _default keywords + if (printername.equals("_all")) { + continue; + } + if (printername.equals("_default")) { + continue; + } + + // Extract servername + i = o.indexOf("bsdaddr=", colon); + if ((i != -1) && (i < nextcolon)) { + j = o.indexOf(",", i); + if (j != -1) + printserver = o.substring(i + 8, j); + } + // Skip entries without a server. + if (printserver.equals("")) { + Debug.warning( + "SVR: printer does not have a server: " + + printername); + continue; + } + + // Extract description + i = o.indexOf("description=", colon); + if ((i != -1) && (i < nextcolon)) { + j = i; + while (j < o.length()) { + if (o.charAt(j) == '\n') + break; + j++; + } + comment = o.substring(i + 12, j); + } + + list[listi++] = printername; + list[listi++] = printserver; + list[listi++] = comment; + printername = ""; + printserver = ""; + comment = ""; + } + return (list); + } + + public static boolean exists( + String name, + String ns) throws Exception + { + int exitvalue; + + Debug.message("SVR: DoPrinterUtil.exists() " + ns); + + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/lpget -n " + ns + " " + name); + exitvalue = syscmd.getExitValue(); + syscmd = null; + if (exitvalue == 0) { + return (true); + } + return (false); + } + + public static boolean isLocal( + String pn) throws Exception + { + int exitvalue; + + Debug.message("SVR: DoPrinterUtil.isLocal()"); + + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/test -d /etc/lp/printers/" + pn); + exitvalue = syscmd.getExitValue(); + syscmd = null; + if (exitvalue != 0) { + return (false); + } + return (true); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterView.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterView.java new file mode 100644 index 0000000000..a3148f3707 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterView.java @@ -0,0 +1,488 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * DoPrinterView class + * Worker class for gathering printer information. + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +import com.sun.admin.pm.client.pmNeedPPDCacheException; +import com.sun.admin.pm.client.pmCacheMissingPPDException; +// import com.sun.admin.pm.client.pmGuiException; + +public class DoPrinterView { + + public static void main(String[] args) { + Debug.setDebugLevel(Debug.ALL); + + Printer p = new Printer(); + p.setPrinterName("petite"); + NameService ns = new NameService(); + + try { + view(p, ns); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + PrinterDebug.printObj(p); + + System.out.println("Commands:\n" + p.getCmdLog()); + System.out.println("Errors:\n" + p.getErrorLog()); + System.out.println("Warnings:\n" + p.getWarnLog()); + System.exit(0); + } + + // + // Interface to Printer object. + // + public static void view( + Printer p, + NameService ns) throws Exception + { + boolean islocal = + DoPrinterUtil.isLocal(p.getPrinterName()); + if (islocal) { + viewLocal(p, ns); + } else { + viewRemote(p, ns); + } + + return; + } + + // + // Do the work getting Remote printer attributes. + // + private static void viewRemote( + Printer p, + NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterView.viewRemote()"); + + int exitvalue = 0; + int i, j; + String o = null; + String printername = p.getPrinterName(); + String printserver = null; + String comment = null; + String extensions = null; + boolean default_printer = false; + + String nsarg = ns.getNameService(); + + String err = null; + + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/lpget -n " + nsarg + " " + + printername, "LC_ALL=C"); + + if (syscmd.getExitValue() != 0) { + err = syscmd.getError(); + p.setErrorLog(err); + // Add stdout since thats where lpget sends errors. + err = syscmd.getOutput(); + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } + o = syscmd.getOutput(); + syscmd = null; + + if (o == null) { + throw new pmCmdFailedException(err); + } + // For easier parsing. + o = o.concat("\n"); + + i = o.indexOf("bsdaddr="); + if (i == -1) { + Debug.message("SVR: Can't parse bsdaddr for " + printername); + throw new pmException(); + } + i = i + 8; + j = o.indexOf(",", i); + if (j == -1) { + Debug.message("SVR: Can't parse bsdaddr for " + printername); + throw new pmException(); + } + printserver = o.substring(i, j); + + i = o.indexOf(",Solaris"); + if (i != -1) { + extensions = "Solaris"; + } + + i = o.indexOf("description="); + if (i != -1) { + i = i + 12; + j = o.indexOf("\n", i); + if (j != -1) { + comment = o.substring(i, j); + } + } + + String def = DoPrinterUtil.getDefault(nsarg); + if ((def != null) && (def.equals(printername))) { + default_printer = true; + } + p.setPrintServer(printserver); + p.setExtensions(extensions); + p.setComment(comment); + p.setIsDefaultPrinter(default_printer); + return; + } + + // + // Do the work getting printer attributes. + // + private static void viewLocal( + Printer p, NameService ns) throws Exception + { + Debug.message("SVR: DoPrinterView.viewLocal()"); + + int i = -1; + int exitvalue = 0; + String str = null; + String o = null; + + String printername = p.getPrinterName(); + String printertype = null; + String printserver = null; + String comment = null; + String device = null; + String make = null; + String model = null; + String ppd = null; + String notify = null; + String protocol = null; + String destination = null; + String extensions = "Solaris"; + String[] file_contents = null; + String[] user_allow_list = null; + String[] user_deny_list = null; + boolean default_printer = false; + String banner = null; + boolean enable = false; + boolean accept = false; + + String ppdfile = null; + + String def = DoPrinterUtil.getDefault("system"); + if ((def != null) && (def.equals(printername))) { + default_printer = true; + } + + // + // Parse lpstat output + // + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/lpstat -L -l -a " + + printername + " -p " + printername, "LC_ALL=C"); + + if (syscmd.getExitValue() != 0) { + String err = syscmd.getError(); + p.setErrorLog(err); + syscmd = null; + throw new pmCmdFailedException(err); + } + + o = syscmd.getOutput(); + syscmd = null; + + // Append a newline to make parsing easier. + o = o.concat("\n"); + + comment = getToken(o, "\tDescription:"); + if (comment.equals("")) { + comment = null; + } + + // Get the PPD path/filename from lpstat + // Get the make/model/ppd nickname using ppd-filename + ppdfile = getToken(o, "\tPPD:"); + if (ppdfile.equals("none")) { + ppdfile = null; + } else { + // Set the make/model/ppd + + if (!pmMisc.isppdCachefile()) { + throw new pmNeedPPDCacheException("ppdcache missing"); + } + String ret[]; + ret = new String[3]; + ret = DoPrinterUtil.getMakeModelNick(ppdfile); + + if ((ret != null) && (!ret.equals(""))) { + make = ret[0]; + model = ret[1]; + ppd = ret[2]; + } else { + throw new pmCacheMissingPPDException( + "PPD file not in cache"); + } + } + + int j = -1; + Host h = new Host(); + + printserver = h.getLocalHostName(); + + printertype = getToken(o, "Printer types:"); + i = o.indexOf("enabled since"); + if (i != -1) { + enable = true; + } + i = o.indexOf("not accepting requests"); + if (i == -1) { + accept = true; + } + + i = o.indexOf("Banner not required"); + if (i != -1) { + banner = "optional"; + } + i = o.indexOf("Banner required"); + if (i != -1) { + banner = "always"; + } + i = o.indexOf("Banner page never printed"); + if (i != -1) { + banner = "never"; + } + + + + // If we have Options then look for destination and protocol. + protocol = "bsd"; + str = "Options:"; + i = o.indexOf(str); + if (i != -1) { + // Set str to the substring containing only the options line. + j = o.indexOf("\n", i); + str = o.substring(i, j); + + // Append a comma to make parsing easier. + str = str.concat(","); + i = str.indexOf("dest="); + if (i != -1) { + i += 5; + j = str.indexOf(",", i); + destination = str.substring(i, j); + destination = destination.trim(); + } + i = str.indexOf("protocol="); + if (i != -1) { + i += 9; + j = str.indexOf(",", i); + protocol = str.substring(i, j); + protocol = protocol.trim(); + } + } + + StringTokenizer st; + + // Build array of content types. + str = getToken(o, "Content types:"); + if (str != null) { + str = str.replace(',', ' '); + st = new StringTokenizer(str); + if (st.countTokens() != 0) { + file_contents = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + file_contents[i] = st.nextToken(); + } + } + } + + // + // User allow list. + // + str = "Users allowed:\n"; + i = o.indexOf(str); + if (i != -1) { + i += str.length(); + // Grab the substring containing only users. + j = o.indexOf("\tForms"); + if (j != -1) { + str = o.substring(i, j); + st = new StringTokenizer(str); + if (st.countTokens() != 0) { + user_allow_list = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + user_allow_list[i] = st.nextToken(); + } + } + } + } + if (user_allow_list == null) { + } else if (user_allow_list[0].equals("(all)")) { + user_allow_list[0] = "all"; + } else if (user_allow_list[0].equals("(none)")) { + user_allow_list[0] = "none"; + } + // + // User deny list + // + syscmd = new SysCommand(); + String cmd = "/bin/cat /etc/lp/printers/" + printername + "/users.deny"; + syscmd.exec(cmd); + if (syscmd.getExitValue() == 0) { + str = syscmd.getOutput(); + if ((str != null) && (str.length() != 0)) { + st = new StringTokenizer(str); + if (st.countTokens() != 0) { + user_deny_list = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + user_deny_list[i] = st.nextToken(); + } + } + } + } + syscmd = null; + + // + // Get fault action + // + str = getToken(o, "On fault:"); + if (str != null) { + if (!str.equals("")) { + if (str.indexOf("write to") != -1) { + notify = "write"; + } else if (str.indexOf("mail to") != -1) { + notify = "mail"; + } else if (str.indexOf("no alert") != -1) { + notify = "none"; + } else if (str.indexOf("alert with") != -1) { + i = str.indexOf("\""); + if (i != -1) { + j = str.lastIndexOf("\""); + if (j > i) { + notify = str.substring(++i, j); + } + } + } else if (str.indexOf(" quiet ") != -1) { + notify = "quiet"; + } else { + notify = "unknown"; + } + } + } + syscmd = null; + // + // Get the printers device + // + syscmd = new SysCommand(); + syscmd.exec("/usr/bin/lpstat -L -v " + printername, + "LC_ALL=C"); + + o = syscmd.getOutput(); + if (o != null) { + o = o.concat("\n"); + device = getToken(o, ":"); + } + + Debug.message("SVR: DEVICE (" + device + ")"); + // + // If the device is in URI form (scheme:// ...), set the protocol + // for the "network attached" modify screen. + // + if (device.indexOf("://") != -1) { + protocol = "uri"; + destination = device; + device = null; + } + + syscmd = null; + + p.setPrinterType(printertype); + p.setPrintServer(printserver); + p.setFileContents(file_contents); + p.setComment(comment); + p.setDevice(device); + p.setMake(make); + p.setModel(model); + p.setPPD(ppd); + p.setPPDFile(ppdfile); + p.setNotify(notify); + p.setProtocol(protocol); + p.setDestination(destination); + p.setExtensions(extensions); + p.setIsDefaultPrinter(default_printer); + p.setBanner(banner); + p.setEnable(enable); + p.setAccept(accept); + p.setUserAllowList(user_allow_list); + p.setUserDenyList(user_deny_list); + + if (ns.getNameService().equals("system")) + return; + Debug.message( + "SVR: Overlaying name service attributes on local printer"); + try { + viewRemote(p, ns); + } + catch (Exception e) + { + Debug.warning( + "SVR: Overlay of name service attributes failed."); + Debug.warning("SVR: " + e.getMessage()); + } + return; + } + + // + // Return substring starting at sub + 1 and ending with + // a newline. + // + public static String getToken(String str, String sub) + { + int i = -1; + int j = -1; + String result = null; + + i = str.indexOf(sub); + if (i != -1) { + if (str.charAt(i + sub.length()) == '\n') { + return (null); + } + i = i + sub.length(); + j = str.indexOf("\n", i); + if (j != -1) { + result = str.substring(i, j); + result = result.trim(); + } + } + return (result); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Host.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Host.java new file mode 100644 index 0000000000..58338600ac --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Host.java @@ -0,0 +1,375 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Host class + * Methods associated with a host. + */ + +package com.sun.admin.pm.server; + +import java.io.*; + +public class Host +{ + public static void main(String[] args) + { + try { + System.out.println(getLocalHostName()); + System.out.println(getDomainName()); + System.out.println(getNisHost("master")); + } + catch (Exception e) { + System.out.println(e); + } + System.exit(0); + } + + // + // Get the local hostname + // Return an empty string if we don't find one. + // + public synchronized static String getLocalHostName() + throws Exception + { + Debug.message("SVR: Host.getLocalHostName()"); + + String cmd = "/usr/bin/hostname"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + + if (syscmd.getExitValue() != 0) { + String err = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(err); + } + String o = syscmd.getOutput(); + syscmd = null; + + if (o == null) + return (new String("")); + return (new String(o)); + } + + // + // Get the domainname + // Return an empty string if we don't find one. + // + public synchronized static String getDomainName() + throws Exception + { + Debug.message("SVR: Host.getDomainName()"); + + String cmd = "/usr/bin/domainname"; + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + String err = syscmd.getError(); + syscmd = null; + throw new pmCmdFailedException(err); + } + + String o = syscmd.getOutput(); + syscmd = null; + + if (o == null) + return (new String("")); + return (new String(o)); + } + + public synchronized static void pingHost(String host) + throws Exception + { + int exitvalue; + + Debug.message("SVR: Host.pingHost()"); + + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/sbin/ping " + host); + exitvalue = syscmd.getExitValue(); + syscmd = null; + + if (exitvalue != 0) { + String err = syscmd.getError(); + throw new pmHostNotPingableException(err); + } + } + + public synchronized static String getNisMaster() + throws Exception + { + return (getNisHost("master")); + } + + // + // Look for the nis server. + // If we are looking for the master server first try + // the printers.conf.byname map. If that fails + // look for passwd. + // + public synchronized static String getNisHost(String type) + throws Exception + { + Debug.message("SVR: Host.getNisHost() " + type); + + SysCommand syscmd = null; + String cmd = null; + int exitvalue = 0; + + if (type.equals("master")) { + cmd = "/usr/bin/ypwhich -m printers.conf.byname"; + } else { + cmd = "/usr/bin/ypwhich"; + } + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + if ((exitvalue != 0) && (type.equals("master"))) { + Debug.message("SVR: printers.conf NIS host not found."); + Debug.message("SVR: Looking for NIS passwd host."); + cmd = "/usr/bin/ypwhich -m passwd"; + + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + } + if (exitvalue != 0) { + Debug.error("SVR: NIS server could not be found"); + String err = syscmd.getError(); + syscmd = null; + throw new pmNSNotConfiguredException(err); + } + + String o = syscmd.getOutput(); + syscmd = null; + + if (o == null) { + throw new pmCmdFailedException(syscmd.getError()); + } + o = o.trim(); + return (new String(o)); + } + + /* + * Return the name of the first server listed by ldapclient + */ + public synchronized static String getLDAPMaster() + throws Exception + { + SysCommand syscmd = null; + String cmd = null; + int exitvalue = 0; + + /* ldapclient will hang if we are not root. */ + if (!DoPrinterNS.isRoot()) { + Debug.error("SVR: Not root. Can't determine LDAP master."); + return null; + } + + cmd = "/usr/sbin/ldapclient list"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + + if (exitvalue != 0) { + Debug.error("SVR: ldapclient failed."); + Debug.error("SVR: " + syscmd.getError()); + syscmd = null; + return null; + } + String o = syscmd.getOutput(); + syscmd = null; + + String master = DoPrinterView.getToken(o + "\n", "NS_LDAP_SERVERS="); + if (master == null) { + Debug.error("SVR: ldapclient did not return NS_LDAP_SERVERS."); + syscmd = null; + return null; + } + + /* Extract the first address from the NS_LDAP_SERVERS list */ + + for (int i = 0; i < master.length(); i++) { + if ((master.charAt(i) == ',') || + (master.charAt(i) == ' ') || + (master.charAt(i) == '\t')) { + master = master.substring(0, i); + break; + } + } + master = master.trim(); + + return (new String(master)); + } + + /* + * Get a default admin DN. + */ + public synchronized static String getDefaultAdminDN() + throws Exception + { + SysCommand syscmd = null; + String cmd = null; + int exitvalue = 0; + + try { + String master = getLDAPMaster(); + cmd = "/usr/bin/ldapsearch -h " + master + + " -b o=NetScapeRoot o=NetscapeRoot"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + if (exitvalue == 0) { + String on = syscmd.getOutput(); + syscmd = null; + if (on != null) { + if (on.indexOf("NetscapeRoot") != -1) { + return ("cn=Directory Manager"); + } + } + } + syscmd = null; + } + catch (Exception e) { + Debug.message("SVR: ldapsearch for NSDS failed. Continuing"); + } + + cmd = "/usr/bin/ldaplist -d printers"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + + if (exitvalue != 0) { + Debug.error("SVR: ldaplist printers failed."); + Debug.error("SVR: " + syscmd.getError()); + syscmd = null; + return null; + } + String o = syscmd.getOutput(); + syscmd = null; + + if (o == null) { + return null; + } + + String dn = DoPrinterView.getToken(o + "\n", "ou=printers,"); + if (dn == null) { + return null; + } + dn = "cn=admin," + dn; + dn = dn.trim(); + + return (new String(dn)); + } + + // + // Check to see if a name service is configured + // + public synchronized static void isNSConfigured(String ns) + throws Exception + { + Debug.message("SVR: Host.isNSConfigured() " + ns); + + int exitvalue; + String cmd = null; + String err = null; + SysCommand syscmd = null; + + if (ns.equals("system")) { + return; + } else if (ns.equals("nis")) { + cmd = "/usr/bin/ypwhich"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + err = syscmd.getError(); + syscmd = null; + + if (exitvalue != 0) { + throw new pmNSNotConfiguredException(err); + } + + cmd = "/usr/bin/ypcat cred"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + syscmd = null; + if (exitvalue == 0) { + Debug.warning( + "SVR: Discovered NIS+ server in yp compat mode."); + Debug.warning( + "SVR: Unable to update this configuration."); + throw new pmNSNotConfiguredException(); + } + } else if (ns.equals("nisplus")) { + cmd = "/usr/bin/grep printers: /etc/nsswitch.conf"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + syscmd = null; + Debug.message( + "SVR: nisplus is not supported for this system"); + throw new pmNSNotConfiguredException(); + } + cmd = "/usr/bin/nisls"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + err = syscmd.getError(); + syscmd = null; + throw new pmNSNotConfiguredException(err); + } + syscmd = null; + } else if (ns.equals("ldap")) { + /* + * Check if the ldap-client is configured by first checking + * if the config file exists and then invoking ldaplist + * Note: we need to check if the config file exists before + * invoking ldaplist so that we don't get its error message + */ + + File ldapConfig = new File("/var/ldap/ldap_client_file"); + if (ldapConfig.isFile()) { + // Config file exists + + cmd = "/usr/bin/ldaplist -d printers"; + syscmd = new SysCommand(); + syscmd.exec(cmd); + exitvalue = syscmd.getExitValue(); + syscmd = null; + + if (exitvalue != 0) { + throw new pmNSNotConfiguredException(); + } + } else { + throw new pmNSNotConfiguredException(); + } + } else { + throw new pmInternalErrorException( + "Unkown name service " + ns); + } + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Makefile b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Makefile new file mode 100644 index 0000000000..ce9fecbf20 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Makefile @@ -0,0 +1,121 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# Makefile for Java Print Manager server +# + +LIBRARY = libpmgr.a +VERS = .1 + +JNIHDR_FILES = com_sun_admin_pm_server_DoPrinterNS.h + +OBJECTS = DoPrinterNS.o NS.o + +CLASSFILES = Printer.class \ + Host.class \ + SysCommand.class \ + NameService.class \ + PrinterUtil.class \ + DoPrinterView.class \ + DoPrinterAdd.class \ + DoPrinterDelete.class \ + DoPrinterUtil.class \ + DoPrinterMod.class \ + DoPrinterNS.class \ + Valid.class \ + Test.class \ + Debug.class \ + PrinterDebug.class \ + pmException.class \ + pmAuthException.class \ + pmAuthRhostException.class \ + pmCmdFailedException.class \ + pmInternalErrorException.class \ + pmHostNotPingableException.class \ + pmNSNotConfiguredException.class \ + pmMisc.class + +JNICLASSFILES = DoPrinterNS.class + +include $(SRC)/lib/Makefile.lib + +CLASSPATH= $(SRC)/cmd/print/printmgr + +JAVAFILES = $(CLASSFILES:.class=.java) + +ROOTDIRS = $(ROOT)/usr/sadm/admin \ + $(ROOT)/usr/sadm/admin/printmgr \ + $(ROOT)/usr/sadm/admin/printmgr/lib + +# override ROOTLIBDIR and ROOTLINKS +ROOTLIBDIR = $(ROOT)/usr/sadm/admin/printmgr/lib +ROOTLIBS= $(LIBS:%=$(ROOTLIBDIR)/%) + +$(ROOTLINKS):= OWNER = root +$(ROOTLINKS):= GROUP = lp + +# Following variables define where to find header files +CPPFLAGS += -I$(JAVA_ROOT)/include -I$(JAVA_ROOT)/include/solaris -I. + +LDLIBS += -lprint -lnsl -lsocket -lc + +CLEANFILES= *.class $(LINTLIB) $(LINTOUT) +CLOBBERFILES= $(JNIHDR_FILES) $(LIBLINKS) + +all: $(CLASSFILES) $(JNIHDR_FILES) $(DYNLIB) + +install: all $(ROOTDIRS) $(ROOTLINKS) + +# +# Build jni header file +# Use $@ instead of the "unreliable" $* +# +$(JNIHDR_FILES): $(JNICLASSFILES) + $(JAVAH) -jni -classpath $(CLASSPATH) \ + `echo $@ | sed 's/.h$$//' | tr _ .` + +# +# Build standalone programs for testing +# +NS: NS.c + $(CC) NS.c -g $(ILDOFF) -o NS -DMAIN=1 $(ENVLDLIBS1) $(ENVLIBS2) \ + -lprint -lnsl -lsocket + +lint: $(JNIHDR_FILES) lintcheck + +cstyle: + cstyle $(SRCS) + +jstyle: + jstyle $(JAVAFILES) + +_msg: + +$(ROOTDIRS): + $(INS.dir) + +include $(SRC)/lib/Makefile.targ diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/NS.c b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/NS.c new file mode 100644 index 0000000000..eeeefdd31c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/NS.c @@ -0,0 +1,821 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/*LINTLIBRARY*/ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <netdb.h> +#include <unistd.h> +#include <stdlib.h> +#include <arpa/inet.h> +#include <rpcsvc/ypclnt.h> + +char glob_stdout[BUFSIZ]; +char glob_stderr[BUFSIZ]; + +void f_cleanup(FILE *fp, char *tmpf); +void fd_cleanup(int fd1, int fd2); +static void _freeList(char ***list); + +extern void **list_append(void **list, void *item); + +#ifdef MAIN + +#define THOSTNAME "cherwell" +#define TPRINTERNAME "c" + +int +main() { + char *host = THOSTNAME; + const char *user = "cn=Directory Manager"; + const char *passwd = "directorymanager"; + int result = 0; + + result = _updateldap("add", host, user, passwd, + "_pmTestAuthToken", NULL, NULL, "new comment", "false"); + if (result != 0) { + printf("Add 1 failed, err code = %d\n"); + } + + result = _updateldap("delete", host, user, passwd, + "_pmTestAuthToken", NULL, NULL, NULL, "false"); + if (result != 0) { + printf("Delete 1 failed, err code = %d\n"); + } + + result = _updateldap("delete", host, user, passwd, TPRINTERNAME, + THOSTNAME, "", "new comment", "true"); + if (result != 0) { + printf("delete failed, err code = %d\n"); + } + + result = _updateldap("delete", host, user, passwd, "_default", + THOSTNAME, "", "new comment", "true"); + if (result != 0) { + printf("delete failed, err code = %d\n"); + } + + result = _updateldap("add", host, user, passwd, TPRINTERNAME, + THOSTNAME, "Solaris", "new comment", "true"); + if (result != 0) { + printf("add failed, err code = %d\n"); + } + + result = _updateldap("modify", host, user, passwd, TPRINTERNAME, + THOSTNAME, "", "modified comment", "true"); + if (result != 0) { + printf("modify failed, err code = %d\n"); + } + + result = _updateldap("modify", host, user, passwd, TPRINTERNAME, + THOSTNAME, "", NULL, "false"); + if (result != 0) { + printf("modify failed, err code = %d\n"); + } + + + exit(0); +} +#endif + + +int +_dorexec( + const char *host, + const char *user, + const char *passwd, + const char *cmd, + const char *locale) { + + int ret = 0; + int fd = 0; + int fd2 = 1; + + FILE *fderr; + char *ferr; + + (void) memset(glob_stdout, 0, BUFSIZ); + (void) memset(glob_stderr, 0, BUFSIZ); + + /* + * Re-direct stderr to a file + */ + ferr = tempnam(NULL, NULL); + if (ferr != NULL) { + fderr = freopen(ferr, "w+", stderr); + } + + fd = rexec((char **)&host, htons(512), user, + passwd, cmd, &fd2); + + if (fd > -1) { + /* + * rexec worked. Clean up stderr file. + */ + f_cleanup(fderr, ferr); + + ret = read(fd, glob_stdout, BUFSIZ - 1); + if (ret < 0) { + (void) strncpy(glob_stderr, strerror(errno), + (BUFSIZ - 1)); + fd_cleanup(fd, fd2); + return (errno); + } + + ret = read(fd2, glob_stderr, BUFSIZ - 1); + if (ret < 0) { + (void) strncpy(glob_stderr, strerror(errno), + (BUFSIZ - 1)); + fd_cleanup(fd, fd2); + return (errno); + } + } else { + /* + * rexec failed. Read from the stderr file. + */ + if (fderr != NULL) { + char tmpbuf[BUFSIZ]; + + (void) rewind(fderr); + strcpy(glob_stderr, ""); + while (fgets(tmpbuf, BUFSIZ - 1, + fderr) != NULL) { + if ((strlen(glob_stderr) + + strlen(tmpbuf)) > BUFSIZ - 1) { + break; + } else { + (void) strcat(glob_stderr, tmpbuf); + } + } + } + f_cleanup(fderr, ferr); + fd_cleanup(fd, fd2); + return (1); + } + fd_cleanup(fd, fd2); + return (0); +} + +void +fd_cleanup(int fd, int fd2) +{ + if (fd > 0) { + (void) close(fd); + } + if (fd2 > 0) { + (void) close(fd2); + } +} + +void +f_cleanup(FILE *fp, char *tmpf) +{ + if (fp != NULL) { + (void) fclose(fp); + } + if (tmpf != NULL) { + (void) unlink(tmpf); + (void) free(tmpf); + } +} + +struct ns_bsd_addr { + char *server; /* server name */ + char *printer; /* printer name or NULL */ + char *extension; /* RFC-1179 conformance */ + char *pname; /* Local printer name */ +}; +typedef struct ns_bsd_addr ns_bsd_addr_t; + +/* Key/Value pair structure */ +struct ns_kvp { + char *key; /* key */ + void *value; /* value converted */ +}; +typedef struct ns_kvp ns_kvp_t; + +/* + * Information needed to update a name service. + * Currently only used for ldap. (see lib/print/ns.h) + */ + +/* LDAP bind password security type */ + +typedef enum NS_PASSWD_TYPE { + NS_PW_INSECURE = 0, + NS_PW_SECURE = 1 +} NS_PASSWD_TYPE; + + +struct ns_cred { + char *binddn; + char *passwd; + char *host; + int port; /* LDAP port, 0 = default */ + NS_PASSWD_TYPE passwdType; /* password security type */ + uchar_t *domainDN; /* NS domain DN */ +}; +typedef struct ns_cred ns_cred_t; + +/* LDAP specific NS Data */ + +typedef struct NS_LDAPDATA { + char **attrList; /* list of user defined Key Value Pairs */ +} NS_LDAPDATA; + +/* Printer Object structure */ +struct ns_printer { + char *name; /* primary name of printer */ + char **aliases; /* aliases for printer */ + char *source; /* name service derived from */ + ns_kvp_t **attributes; /* key/value pairs. */ + ns_cred_t *cred; /* info to update name service */ + void *nsdata; /* name service specific data */ +}; +typedef struct ns_printer ns_printer_t; + +extern ns_printer_t *ns_printer_get_name(const char *, const char *); +extern int ns_printer_put(const ns_printer_t *); +extern char *ns_get_value_string(const char *, const ns_printer_t *); +extern int ns_set_value(const char *, const void *, ns_printer_t *); +extern int ns_set_value_from_string(const char *, const char *, + ns_printer_t *); +extern ns_bsd_addr_t *bsd_addr_create(const char *, const char *, + const char *); +extern char *bsd_addr_to_string(const ns_bsd_addr_t *); +extern void ns_printer_destroy(ns_printer_t *); + +int +_updateoldyp( + const char *action, + const char *printername, + const char *printserver, + const char *extensions, + const char *comment, + const char *isdefault) { + + ns_printer_t *printer; + ns_bsd_addr_t *addr; + int status = 0; + + char mkcmd[BUFSIZ]; + char *domain = NULL; + char *host = NULL; + + /* + * libprint returns before we know that the printers.conf + * map is made. So we'll make it again. + */ + (void) yp_get_default_domain(&domain); + + if ((yp_master(domain, "printers.conf.byname", &host) != 0) && + (yp_master(domain, "passwd.byname", &host) != 0)) { + strcpy(mkcmd, "/usr/bin/sleep 1"); + } else { + sprintf(mkcmd, "/usr/bin/rsh -n %s 'cd /var/yp; " + "/usr/ccs/bin/make -f /var/yp/Makefile " + "-f /var/yp/Makefile.print printers.conf " + "> /dev/null'", host); + } + + if (strcmp(action, "delete") == 0) { + if ((printer = (ns_printer_t *) + ns_printer_get_name(printername, "nis")) == NULL) { + return (0); + } + + printer->attributes = NULL; + status = ns_printer_put(printer); + if (status != 0) { + (void) free(printer); + return (status); + } + + if ((printer = (ns_printer_t *) + ns_printer_get_name("_default", "nis")) != NULL) { + char *dflt = (char *) + ns_get_value_string("use", printer); + if ((dflt != NULL) && + (strcmp(dflt, printername) == 0)) { + printer->attributes = NULL; + status = ns_printer_put(printer); + if (status != 0) { + (void) free(printer); + return (status); + } + } + } + (void) free(printer); + (void) system(mkcmd); + return (0); + + } else if (strcmp(action, "add") == 0) { + printer = (ns_printer_t *)malloc(sizeof (*printer)); + memset(printer, 0, sizeof (*printer)); + printer->name = (char *)printername; + printer->source = "nis"; + + addr = (ns_bsd_addr_t *)malloc(sizeof (*addr)); + memset(addr, 0, sizeof (*addr)); + addr->printer = (char *)printername; + addr->server = (char *)printserver; + if ((extensions != NULL) && + (strlen(extensions) > 0)) { + addr->extension = (char *)extensions; + } + ns_set_value("bsdaddr", addr, printer); + + if ((comment != NULL) && (strlen(comment) > 0)) { + ns_set_value_from_string("description", + comment, printer); + } + status = ns_printer_put(printer); + if (status != 0) { + (void) free(addr); + (void) free(printer); + return (status); + } + + if (strcmp(isdefault, "true") == 0) { + printer->name = "_default"; + printer->attributes = NULL; + ns_set_value_from_string("use", printername, printer); + status = ns_printer_put(printer); + if (status != 0) { + (void) free(addr); + (void) free(printer); + return (status); + } + } + (void) free(addr); + (void) free(printer); + (void) system(mkcmd); + return (0); + } + + /* + * Modify + */ + if ((printer = (ns_printer_t *) + ns_printer_get_name(printername, "nis")) == NULL) { + return (1); + } + if ((comment != NULL) && (strlen(comment) > 0)) { + ns_set_value_from_string("description", comment, printer); + } else { + ns_set_value_from_string("description", + NULL, printer); + } + status = ns_printer_put(printer); + if (status != 0) { + (void) free(printer); + return (status); + } + + if ((printer = (ns_printer_t *) + ns_printer_get_name("_default", "nis")) != NULL) { + char *dflt = (char *)ns_get_value_string("use", printer); + if (strcmp(printername, dflt) == 0) { + if (strcmp(isdefault, "false") == 0) { + /* + * We were the default printer but not + * any more. + */ + printer->attributes = NULL; + status = ns_printer_put(printer); + if (status != 0) { + (void) free(printer); + return (status); + } + } + } else { + if (strcmp(isdefault, "true") == 0) { + ns_set_value_from_string("use", + printername, printer); + status = ns_printer_put(printer); + if (status != 0) { + (void) free(printer); + return (status); + } + } + } + } else { + printer = (ns_printer_t *)malloc(sizeof (*printer)); + memset(printer, 0, sizeof (*printer)); + printer->name = "_default"; + printer->source = "nis"; + ns_set_value_from_string("use", printername, printer); + status = ns_printer_put(printer); + if (status != 0) { + (void) free(printer); + return (status); + } + } + (void) system(mkcmd); + return (0); +} + +int +_updateldap( + const char *action, + const char *host, + const char *binddn, + const char *passwd, + const char *printername, + const char *printserver, + const char *extensions, + const char *comment, + const char *isdefault) + +{ + ns_printer_t *printer; + ns_bsd_addr_t *addr; + ns_cred_t *cred; + + char *item = NULL; + char **attrList = NULL; + + int status; + + if (printserver == NULL) { + /* printserver not given so use host */ + printserver = host; + } + + cred = (ns_cred_t *)malloc(sizeof (*cred)); + (void) memset(cred, '\0', sizeof (*cred)); + cred->passwd = strdup((char *)passwd); + cred->binddn = strdup((char *)binddn); + cred->host = strdup((char *)host); + + cred->passwdType = NS_PW_INSECURE; /* use default */ + cred->port = 0; /* use default */ + cred->domainDN = NULL; /* use default */ + + if (strcmp(action, "delete") == 0) { + /* + * Delete printer object from LDAP directory DIT + */ + + if ((printer = (ns_printer_t *) + ns_printer_get_name(printername, "ldap")) == NULL) { + return (0); + } + + printer->attributes = NULL; + printer->nsdata = malloc(sizeof (NS_LDAPDATA)); + if (printer->nsdata == NULL) { + return (1); + } + ((NS_LDAPDATA *)(printer->nsdata))->attrList = NULL; + printer->cred = cred; + printer->source = strdup("ldap"); + status = ns_printer_put(printer); + free(printer->nsdata); + (void) ns_printer_destroy(printer); + + if (status != 0) { + return (status); + } + + if ((printer = (ns_printer_t *) + ns_printer_get_name("_default", "ldap")) != NULL) { + char *dflt = (char *) + ns_get_value_string("use", printer); + if ((dflt != NULL) && + (strcmp(dflt, printername) == 0)) { + printer->attributes = NULL; + printer->nsdata = malloc(sizeof (NS_LDAPDATA)); + if (printer->nsdata == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + ((NS_LDAPDATA *)(printer->nsdata))->attrList = NULL; + printer->cred = cred; + printer->source = strdup("ldap"); + status = ns_printer_put(printer); + free(printer->nsdata); + if (status != 0) { + (void) ns_printer_destroy(printer); + return (status); + } + } + + (void) ns_printer_destroy(printer); + } + return (0); + + } else if (strcmp(action, "add") == 0) { + /* + * Add new printer object into LDAP directory DIT + */ + + printer = (ns_printer_t *)malloc(sizeof (*printer)); + if (printer == NULL) { + return (1); + } + (void) memset(printer, 0, sizeof (*printer)); + printer->name = strdup((char *)printername); + printer->source = strdup("ldap"); + + printer->cred = cred; + + /* set BSD address in attribute list */ + + if (extensions == NULL) { + item = (char *)malloc(strlen("bsdaddr") + + strlen(printserver) + + strlen(printername) + + strlen("Solaris") + 6); + } else { + item = (char *)malloc(strlen("bsdaddr") + + strlen(printserver) + + strlen(printername) + + strlen(extensions) + 6); + } + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + + if (extensions == NULL) { + sprintf(item, "%s=%s,%s,%s", "bsdaddr", + printserver, printername, "Solaris"); + } else { + sprintf(item, "%s=%s,%s,%s", "bsdaddr", + printserver, printername, extensions); + } + + attrList = (char **)list_append((void**)attrList, + (void *)item); + if ((comment != NULL) && (strlen(comment) > 0)) { + item = (char *)malloc(strlen("description") + + strlen(comment) + 4); + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + sprintf(item, "%s=%s", "description", comment); + attrList = (char **)list_append((void**)attrList, + (void *)item); + } + + printer->attributes = NULL; + printer->nsdata = malloc(sizeof (NS_LDAPDATA) + 2); + if (printer->nsdata == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + ((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList; + + status = ns_printer_put(printer); + _freeList(&attrList); + if (status != 0) { + free(printer->nsdata); + (void) ns_printer_destroy(printer); + return (status); + } + + if (strcmp(isdefault, "true") == 0) { + (void) free(printer->name); + + printer->name = strdup("_default"); + printer->attributes = NULL; + + attrList = NULL; + item = (char *)malloc(strlen("use") + + strlen(printername) + 4); + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + sprintf(item, "%s=%s", "use", printername); + attrList = (char **)list_append((void**)attrList, + (void *)item); + + ((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList; + + status = ns_printer_put(printer); + _freeList(&attrList); + free(printer->nsdata); + if (status != 0) { + (void) ns_printer_destroy(printer); + return (status); + } + } + (void) ns_printer_destroy(printer); + return (0); + } + + /* + * Modify printer object in the LDAP directory DIT + */ + + if ((printer = (ns_printer_t *) + ns_printer_get_name(printername, "ldap")) == NULL) { + return (1); + } + printer->cred = cred; + printer->source = strdup("ldap"); + + if ((comment != NULL) && (strlen(comment) > 0)) { + item = (char *)malloc(strlen("description") + + strlen(comment) + 4); + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + sprintf(item, "%s=%s", "description", comment); + attrList = (char **)list_append((void**)attrList, (void *)item); + } else { + item = (char *)malloc(strlen("description") + 4); + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + sprintf(item, "%s=", "description"); + attrList = (char **)list_append((void**)attrList, (void *)item); + } + + printer->attributes = NULL; + printer->nsdata = malloc(sizeof (NS_LDAPDATA)); + if (printer->nsdata == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + ((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList; + + status = ns_printer_put(printer); + _freeList(&attrList); + free(printer->nsdata); + if (status != 0) { + (void) ns_printer_destroy(printer); + return (status); + } + + /* + * Handle the default printer. + */ + if ((printer = (ns_printer_t *) + ns_printer_get_name("_default", "ldap")) != NULL) { + char *dflt = (char *)ns_get_value_string("use", printer); + + printer->source = strdup("ldap"); + printer->cred = cred; + if (strcmp(printername, dflt) == 0) { + if (strcmp(isdefault, "false") == 0) { + /* + * We were the default printer but not + * any more. So delete the default entry + */ + printer->attributes = NULL; + printer->nsdata = malloc(sizeof (NS_LDAPDATA)); + if (printer->nsdata == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + ((NS_LDAPDATA *)(printer->nsdata))->attrList = NULL; + status = ns_printer_put(printer); + free(printer->nsdata); + if (status != 0) { + (void) ns_printer_destroy(printer); + return (status); + } + } + } else if (strcmp(isdefault, "true") == 0) { + /* + * Modify this default entry to use us. + */ + printer->attributes = NULL; + printer->nsdata = malloc(sizeof (NS_LDAPDATA)); + if (printer->nsdata == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + attrList = NULL; + item = (char *)malloc(strlen("use") + + strlen(printername) + 4); + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + sprintf(item, "%s=%s", "use", printername); + attrList = (char **)list_append((void**)attrList, + (void *)item); + + ((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList; + + status = ns_printer_put(printer); + _freeList(&attrList); + free(printer->nsdata); + + if (status != 0) { + (void) ns_printer_destroy(printer); + return (status); + } + } + } else if (strcmp(isdefault, "true") == 0) { + /* + * No default entry existed and we need one. + */ + printer = (ns_printer_t *)malloc(sizeof (*printer)); + (void) memset(printer, 0, sizeof (*printer)); + printer->name = strdup("_default"); + printer->source = strdup("ldap"); + printer->cred = cred; + + printer->nsdata = malloc(sizeof (NS_LDAPDATA)); + if (printer->nsdata == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + + attrList = NULL; + item = (char *)malloc(strlen("use") + strlen(printername) + 4); + if (item == NULL) { + (void) ns_printer_destroy(printer); + return (1); + } + sprintf(item, "%s=%s", "use", printername); + attrList = (char **)list_append((void**)attrList, (void *)item); + + ((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList; + + status = ns_printer_put(printer); + _freeList(&attrList); + free(printer->nsdata); + + if (status != 0) { + (void) ns_printer_destroy(printer); + return (status); + } + } + + (void) ns_printer_destroy(printer); + return (0); +} + + + + +/* + * ***************************************************************************** + * + * Function: _freeList() + * + * Description: Free the list created by list_append() where the items in + * the list have been strdup'ed. + * + * Parameters: + * Input: char ***list - returned set of kvp values + * + * Result: void + * + * ***************************************************************************** + */ + +static void +_freeList(char ***list) + +{ + int i = 0; + + /* ------ */ + + if (list != NULL) { + if (*list != NULL) { + for (i = 0; (*list)[i] != NULL; i++) { + free((*list)[i]); + } + free(*list); + } + + *list = NULL; + } +} /* _freeList */ diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/NameService.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/NameService.java new file mode 100644 index 0000000000..5cda468e14 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/NameService.java @@ -0,0 +1,144 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * NameService class + * Methods and state associated with a name service. + */ + +package com.sun.admin.pm.server; + +import java.io.*; + +public class NameService +{ + private String nameservice = null; + private String nshost = null; + private String user = null; + private String passwd = null; + private boolean boundtonisslave = false; + private boolean isauth = false; + + // + // Constructors + // + // This constructor is used internally in the server package. + public NameService() + { + nameservice = "system"; + isauth = true; + } + // This constructor should always be used by the client. + public NameService(String nsname) throws Exception + { + if ((nsname.equals("system")) || + (nsname.equals("nis")) || + (nsname.equals("nisplus")) || + (nsname.equals("ldap"))) { + nameservice = nsname; + } else { + throw new pmInternalErrorException( + "Unknown name service: " + nsname); + } + + Host h = new Host(); + h.isNSConfigured(nameservice); + + if (nsname.equals("nis")) { + String nm = h.getNisHost("master"); + String nb = h.getNisHost("bound"); + if (!nm.equals(nb)) { + boundtonisslave = true; + } + setUser("root"); + setNameServiceHost(nm); + setPasswd(""); + } else if (nsname.equals("ldap")) { + String master = h.getLDAPMaster(); + if (master == null) { + setNameServiceHost(""); + } else { + setNameServiceHost(master); + } + + String admin = h.getDefaultAdminDN(); + if (admin == null) { + setUser(""); + } else { + setUser(admin); + } + + setPasswd(""); + } + + } + + public void setNameServiceHost(String arg) + { + nshost = arg; + } + public void setUser(String arg) + { + user = arg; + } + public void setPasswd(String arg) + { + passwd = arg; + } + + public String getNameService() + { + return (nameservice); + } + public String getNameServiceHost() + { + return (nshost); + } + public String getUser() + { + return (user); + } + public String getPasswd() + { + return (passwd); + } + public boolean getBoundToNisSlave() + { + return (boundtonisslave); + } + public boolean isAuth() + { + return (isauth); + } + + public void checkAuth() throws Exception + { + Debug.message("SVR: NameService.checkAuth()"); + + DoPrinterNS.doAuth(this); + isauth = true; + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Printer.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Printer.java new file mode 100644 index 0000000000..1f75989a3c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Printer.java @@ -0,0 +1,497 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Printer class + * Printer object containing attributes and methods for + * updating printers. + */ + +package com.sun.admin.pm.server; + +public class Printer +{ + // + // Printer object attributes + // + private String printername = null; + private String printertype = null; + private String printserver = null; + private String comment = null; + private String device = null; + private String make = null; + private String model = null; + private String ppd = null; + private String ppdfile = null; + private String notify = null; + private String protocol = null; + private String destination = null; + private String extensions = null; + private String[] file_contents = null; + private String[] user_allow_list = null; + private String[] user_deny_list = null; + private boolean use_ppd_file = true; + private boolean default_printer = false; + private String banner = null; + private boolean enable = true; + private boolean accept = true; + + private String locale = null; // Possible future use + + private NameService nscontext; + + // + // Logs + // + private String warnlog = null; + private String errlog = null; + private String cmdlog = null; + + // + // Constructors + // + public Printer() + { + Debug.message("SVR: Printer constructor called empty."); + nscontext = new NameService(); + PrinterDebug.printObj(nscontext); + } + public Printer(NameService ns) + { + Debug.message("SVR: Printer constructor called with NS."); + nscontext = ns; + PrinterDebug.printObj(ns); + } + + // + // Is a printer local to this machine + // + public synchronized boolean isPrinterLocal(String printername) + throws Exception + { + Debug.message("SVR: Printer.isPrinterLocal()"); + return (DoPrinterUtil.isLocal(printername)); + } + + // + // Get details of a printer. + // + public synchronized void getPrinterDetails() + throws Exception + { + Debug.message("SVR: Printer.getPrinterDetails()"); + + if (printername == null) { + throw new pmInternalErrorException( + "Printer.getPrinterDetails(): printername must be set"); + } + DoPrinterView.view(this, nscontext); + } + + // + // Add a local printer + // + public synchronized void addLocalPrinter() + throws Exception + { + Debug.message("SVR: Printer.addLocalPrinter()"); + + if (printername == null) { + throw new pmInternalErrorException( + "Printer.addLocalPrinter(): printername must be set"); + } + if (printserver == null) { + Host h = new Host(); + printserver = h.getLocalHostName(); + h = null; + } + if (device == null) { + throw new pmInternalErrorException( + "Printer.addLocalPrinter(): device must be set"); + } + if ((pmMisc.isppdCachefile()) && use_ppd_file) { + if (make == null) { + throw new pmInternalErrorException( + "Printer.addLocalPrinter(): make must be set"); + } + if (model == null) { + throw new pmInternalErrorException( + "Printer.addLocalPrinter(): model must be set"); + } + if (ppd == null) { + throw new pmInternalErrorException( + "Printer.addLocalPrinter(): ppd file must be selected"); + } + } + + + PrinterDebug.printObj(this); + + clearLogs(); + DoPrinterAdd.add(this, nscontext); + } + + // + // Add access to a remote printer + // + public synchronized void addRemotePrinter() + throws Exception + { + Debug.message("SVR: Printer.addRemotePrinter()"); + + if (printername == null) { + throw new pmInternalErrorException( + "Printer.addRemotePrinter(): printername must be set"); + } + if (printserver == null) { + throw new pmInternalErrorException( + "Printer.addRemotePrinter(): printserver must be set"); + } + PrinterDebug.printObj(this); + + clearLogs(); + DoPrinterAdd.add(this, nscontext); + } + + // + // Delete a printer + // + public synchronized void deletePrinter() + throws Exception + { + Debug.message("SVR: Printer.deletePrinter()"); + + if (printername == null) { + throw new pmInternalErrorException( + "Printer.deletePrinter(): printername must be set"); + } + PrinterDebug.printObj(this); + + clearLogs(); + DoPrinterDelete.delete(this, nscontext); + } + + // + // Modify a printer + // + public synchronized void modifyPrinter() + throws Exception + { + Debug.message("SVR: Printer.modifyPrinter()"); + + if (printername == null) { + throw new pmInternalErrorException( + "Printer.modifyPrinter(): printername must be set"); + } + PrinterDebug.printObj(this); + + clearLogs(); + DoPrinterMod.modify(this, nscontext); + } + + // + // Set list of commands executed + // + public synchronized void setCmdLog(String newcmds) + { + if (newcmds == null) { + return; + } + if (!newcmds.endsWith("\n")) { + newcmds = newcmds.concat("\n"); + } + if (cmdlog == null) { + cmdlog = new String(newcmds); + return; + } + cmdlog = cmdlog.concat(newcmds); + } + + // + // Set an error message. + // + public synchronized void setErrorLog(String errs) + { + if (errs == null) { + return; + } + if (!errs.endsWith("\n")) { + errs = errs.concat("\n"); + } + if (errlog == null) { + errlog = new String(errs); + return; + } else { + errlog = errlog.concat(errs); + } + } + + // + // Set an warning message. + // + public synchronized void setWarnLog(String warning) + { + if (warning == null) { + return; + } + if (!warning.endsWith("\n")) { + warning = warning.concat("\n"); + } + if (warnlog == null) { + warnlog = new String(warning); + return; + } else { + warnlog = warnlog.concat(warning); + } + } + + // + // Get commands executed. + // + public String getCmdLog() + { + if (cmdlog == null) { + return (null); + } + return (new String(cmdlog.trim())); + } + + // + // Get error messages + // + public String getErrorLog() + { + if (errlog == null) { + return (null); + } + return (new String(errlog.trim())); + } + + // + // Get warning messages + // + public String getWarnLog() + { + if (warnlog == null) { + return (null); + } + return (new String(warnlog.trim())); + } + + // + // Set printer attributes + // + public synchronized void setPrinterName(String arg) + { + printername = arg; + } + public synchronized void setPrinterType(String arg) + { + printertype = arg; + } + public synchronized void setPrintServer(String arg) + { + printserver = arg; + } + public synchronized void setComment(String arg) + { + comment = arg; + } + public synchronized void setMake(String arg) + { + make = arg; + } + public synchronized void setModel(String arg) + { + model = arg; + } + public synchronized void setPPD(String arg) + { + ppd = arg; + } + public synchronized void setPPDFile(String arg) + { + ppdfile = arg; + } + public synchronized void setDevice(String arg) + { + device = arg; + } + public synchronized void setUsePPD(boolean arg) + { + use_ppd_file = arg; + } + public synchronized void setNotify(String arg) + { + notify = arg; + } + public synchronized void setProtocol(String arg) + { + protocol = arg; + } + public synchronized void setDestination(String arg) + { + destination = arg; + } + public synchronized void setExtensions(String arg) + { + extensions = arg; + } + public synchronized void setFileContents(String[] arg) + { + file_contents = arg; + } + public synchronized void setUserAllowList(String[] arg) + { + user_allow_list = arg; + } + public synchronized void setUserDenyList(String[] arg) + { + user_deny_list = arg; + } + public synchronized void setIsDefaultPrinter(boolean arg) + { + default_printer = arg; + } + public synchronized void setBanner(String arg) + { + banner = arg; + } + public synchronized void setEnable(boolean arg) + { + enable = arg; + } + public synchronized void setAccept(boolean arg) + { + accept = arg; + } + public synchronized void setLocale(String arg) + { + locale = arg; + } + + // + // Get printer attributes. + // + public String getPrinterName() + { + return (printername); + } + public String getPrinterType() + { + return (printertype); + } + public String getPrintServer() + { + return (printserver); + } + public String getComment() + { + return (comment); + } + public String getDevice() + { + return (device); + } + public boolean getUsePPD() + { + return (use_ppd_file); + } + public String getMake() + { + return (make); + } + public String getModel() + { + return (model); + } + public String getPPD() + { + return (ppd); + } + public String getPPDFile() + { + return (ppdfile); + } + public String getNotify() + { + return (notify); + } + public String getProtocol() + { + return (protocol); + } + public String getDestination() + { + return (destination); + } + public String getExtensions() + { + return (extensions); + } + public String[] getFileContents() + { + return (file_contents); + } + public String[] getUserAllowList() + { + return (user_allow_list); + } + public String[] getUserDenyList() + { + return (user_deny_list); + } + public boolean getIsDefaultPrinter() + { + return (default_printer); + } + public String getBanner() + { + return (banner); + } + public boolean getEnable() + { + return (enable); + } + public boolean getAccept() + { + return (accept); + } + public String getLocale() + { + return (locale); + } + + protected void clearLogs() + { + warnlog = null; + errlog = null; + cmdlog = null; + } + + // Hints for optimizing printer modifications + protected String modhints = ""; +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterDebug.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterDebug.java new file mode 100644 index 0000000000..1997111b1c --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterDebug.java @@ -0,0 +1,126 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * PrinterDebug class + * Helper class to print attributes in objects. + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +public class PrinterDebug { + + public static void printObj(Printer p) + { + String arr[]; + int i; + + Debug.message("SVR: PrinterDebug.print_obj(Printer)"); + + Debug.message("SVR: \tName:\t\t" + p.getPrinterName()); + Debug.message("SVR: \tType:\t\t" + p.getPrinterType()); + Debug.message("SVR: \tServer:\t\t" + p.getPrintServer()); + Debug.message("SVR: \tComment:\t" + p.getComment()); + Debug.message("SVR: \tDevice:\t\t" + p.getDevice()); + Debug.message("SVR: \tMake:\t\t" + p.getMake()); + Debug.message("SVR: \tModel:\t\t" + p.getModel()); + Debug.message("SVR: \tPPD:\t\t" + p.getPPD()); + Debug.message("SVR: \tNotify:\t\t" + p.getNotify()); + Debug.message("SVR: \tProtocol:\t" + p.getProtocol()); + Debug.message("SVR: \tDest:\t\t" + p.getDestination()); + Debug.message("SVR: \tExtensions:\t" + p.getExtensions()); + Debug.message("SVR: \tDefault:\t" + p.getIsDefaultPrinter()); + Debug.message("SVR: \tBanner:\t\t" + p.getBanner()); + Debug.message("SVR: \tEnable:\t\t" + p.getEnable()); + Debug.message("SVR: \tAccept:\t\t" + p.getAccept()); + + arr = p.getFileContents(); + if (arr == null) { + Debug.message("SVR: \tContents:\tNULL"); + } else { + Debug.message("SVR: \tContents:"); + for (i = 0; i < arr.length; i++) { + Debug.message("SVR: \t\t\t" + arr[i]); + } + } + arr = p.getUserAllowList(); + if (arr == null) { + Debug.message("SVR: \tUser allow:\tNULL"); + } else { + Debug.message("SVR: \tUser allow:"); + for (i = 0; i < arr.length; i++) { + Debug.message("SVR: \t\t\t" + arr[i]); + } + } + arr = p.getUserDenyList(); + if (arr == null) { + Debug.message("SVR: \tUser deny:\tNULL"); + } else { + Debug.message("SVR: \tUser deny:"); + for (i = 0; i < arr.length; i++) { + Debug.message("SVR: \t\t\t" + arr[i]); + } + } + } + + public static void printObj(NameService ns) + { + Debug.message("SVR: PrinterDebug.printObj(NameService)"); + + // Keep passwd secret. + String passwd = ns.getPasswd(); + if (passwd != null) { + passwd = "*****"; + } + Debug.message("SVR: \tnameservice:\t" + ns.getNameService()); + Debug.message("SVR: \tnshost:\t\t" + ns.getNameServiceHost()); + Debug.message("SVR: \tuser:\t\t" + ns.getUser()); + Debug.message("SVR: \tpasswd:\t\t" + passwd); + Debug.message("SVR: \tboundtonisslave:" + ns.getBoundToNisSlave()); + Debug.message("SVR: \tisAuth:\t\t" + ns.isAuth()); + } + + public static String arr_to_str(String[] arr) + { + if (arr == null) { + return (new String("NULL")); + } + if (arr.length == 0) { + return (new String("0 length array")); + } + String str = ""; + for (int i = 0; i < arr.length; i++) { + if (arr[i] == null) { + break; + } + str = str.concat(arr[i] + " "); + } + return (str); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterUtil.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterUtil.java new file mode 100644 index 0000000000..ff5e947dcf --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterUtil.java @@ -0,0 +1,206 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * PrinterUtil class + * Methods not associated with a printer instance. + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +public class PrinterUtil { + + // + // main for testing + // + public static void main(String[] args) { + String dp = null; + String devs[] = null; + String printers[] = null; + + try { + NameService ns = new NameService("ldap"); +// checkRootPasswd("xxx"); + dp = getDefaultPrinter(ns); + devs = getDeviceList(); + printers = getPrinterList(ns); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + System.out.println("Default printer is: " + dp); + for (int i = 0; i < devs.length; i++) { + System.out.println(devs[i]); + } + for (int i = 0; i < printers.length; i += 3) { + System.out.println("printername: " + printers[i]); + System.out.println("servername: " + printers[i+1]); + System.out.println("comment: " + printers[i+2]); + } + System.exit(0); + } + + // + // Get the default printer for a specified name space + // + public synchronized static String getDefaultPrinter( + NameService ns) throws Exception + { + Debug.message("SVR: PrinterUtil.getDefaultPrinter()"); + + String nsarg = ns.getNameService(); + String ret = DoPrinterUtil.getDefault(nsarg); + if (ret == null) { + return (new String("")); + } + return (new String(ret)); + } + + // + // Get a list of possible printer devices for this machine. + // + public synchronized static String[] getDeviceList() throws Exception + { + Debug.message("SVR: PrinterUtil.getDeviceList()"); + + String emptylist[] = new String[1]; + emptylist[0] = ""; + + String ret[] = DoPrinterUtil.getDevices(); + if (ret == null) { + return (emptylist); + } + return (ret); + } + + // + // Get the list of supported Printer Makes (Manufacturers) + // If supported, a PPD file exists for this Make + // + public synchronized static String[] getMakesList() throws Exception + { + Debug.message("SVR: PrinterUtil.getMakesList()"); + + String emptylist[] = new String[1]; + emptylist[0] = ""; + + String ret[] = DoPrinterUtil.getMakes(); + if (ret == null) { + return (emptylist); + } + return (ret); + } + + public synchronized static String[] getModelsList( + String make) throws Exception + + { + Debug.message("SVR: PrinterUtil.getModelsList()"); + + String emptylist[] = new String[1]; + emptylist[0] = ""; + + String ret[] = DoPrinterUtil.getModels(make); + return (ret); + } + + public synchronized static String[] getPPDList( + String make, String model) throws Exception + + { + Debug.message("SVR: PrinterUtil.getPPDList()"); + + String emptylist[] = new String[1]; + emptylist[0] = ""; + + String ret[] = DoPrinterUtil.getPPDs(make, model); + if (ret == null) { + return (emptylist); + } + return (ret); + } + + public synchronized static String[] getProbePrinter(String device) + { + Debug.message("SVR: PrinterUtil.getProbePrinter()"); + + String ret[] = DoPrinterUtil.getProbe(device); + return (ret); + } + + + // + // Get a list of printers in the specified name service. + // + public synchronized static String[] getPrinterList( + NameService ns) throws Exception + { + Debug.message("SVR: PrinterUtil.getPrinterList()"); + + String emptylist[] = new String[1]; + emptylist[0] = ""; + + String nsarg = ns.getNameService(); + String[] ret = DoPrinterUtil.getList(nsarg); + if (ret == null) { + return (emptylist); + } + return (ret); + } + + // + // Does this printer already exist in the specified + // name service + // + public synchronized static boolean exists( + String name, + NameService ns) throws Exception + { + Debug.message("SVR: PrinterUtil.exists()"); + + String nsname = ns.getNameService(); + return (DoPrinterUtil.exists(name, nsname)); + } + + public synchronized static boolean isLocal( + String printername) throws Exception + { + Debug.message("SVR: PrinterUtil.isLocal()"); + + return (DoPrinterUtil.isLocal(printername)); + } + + public synchronized static void checkRootPasswd( + String passwd) throws Exception + { + DoPrinterNS.doCheckRootPasswd(passwd); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/SysCommand.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/SysCommand.java new file mode 100644 index 0000000000..2a5ddb9bb3 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/SysCommand.java @@ -0,0 +1,246 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * SysCommand + * Execute a command and capture stdout/stderr. + * + */ + +package com.sun.admin.pm.server; + +import java.io.*; + +public class SysCommand +{ + + private Process p = null; + private String out = null; + private String err = null; + private int status = 0; + + public static void main(String[] args) { + SysCommand syscmd = new SysCommand(); + String cmd = "ypcat hosts"; + String o = ""; + try { + syscmd.exec(cmd); + } + catch (Exception e) { + System.out.println(e); + } + o = syscmd.getOutput(); + System.out.println(o); + } + + /* + * Execute a system command. + * @param String cmd The command to be executed. + */ + public void exec(String cmd) throws Exception + { + if (cmd == null) { + throw new pmInternalErrorException( + "SysCommand.exec(): null command"); + } + + debug_log(cmd); + + p = Runtime.getRuntime().exec(cmd); + if (p == null) { + throw new pmInternalErrorException( + "SysCommand.exec(): null process"); + } + out = readOut(); + err = readErr(); + p.waitFor(); + status = getStatus(); + dispose(); + } + + public void exec(String[] cmd) throws Exception + { + if (cmd == null) { + throw new pmInternalErrorException( + "SysCommand.exec(): null command"); + } + + // Trim command arrays with nulls at the end. + int i; + for (i = 0; i < cmd.length; i++) { + if (cmd[i] == null) { + break; + } + } + if (i != cmd.length) { + String[] newcmd = new String[i]; + + for (i = 0; i < newcmd.length; i++) { + newcmd[i] = cmd[i]; + } + debug_log(PrinterDebug.arr_to_str(newcmd)); + p = Runtime.getRuntime().exec(newcmd); + } else { + debug_log(PrinterDebug.arr_to_str(cmd)); + p = Runtime.getRuntime().exec(cmd); + } + if (p == null) { + throw new pmInternalErrorException( + "SysCommand.exec(): null process"); + } + out = readOut(); + err = readErr(); + p.waitFor(); + status = getStatus(); + dispose(); + } + + + public void exec(String cmd, String locale) throws Exception + { + if (cmd == null) { + throw new pmInternalErrorException( + "SysCommand.exec(): null command"); + } + + debug_log(locale + "; " + cmd); + + String [] envp = new String[1]; + envp[0] = locale; + p = Runtime.getRuntime().exec(cmd, envp); + if (p == null) { + throw new pmInternalErrorException( + "SysCommand.exec(): null process"); + } + out = readOut(); + err = readErr(); + p.waitFor(); + status = getStatus(); + dispose(); + } + + public String getOutput() { + if (out == null) + return (null); + return (new String(out)); + } + public String getError() { + if (err == null) + return (null); + return (new String(err)); + } + public int getExitValue() { + return (status); + } + + + private String readOut() throws Exception + { + String result = null; + String line = null; + BufferedReader out = null; + + out = new BufferedReader( + new InputStreamReader(p.getInputStream())); + while ((line = out.readLine()) != null) { + if (result == null) + result = line; + else + result = result.concat("\n" + line); + } + return (result); + } + + private String readErr() throws Exception + { + String errstr = null; + String line = null; + BufferedReader err = null; + + err = new BufferedReader( + new InputStreamReader(p.getErrorStream())); + while ((line = err.readLine()) != null) { + if (errstr == null) { + errstr = line; + } else { + errstr = errstr.concat("\n" + line); + } + } + return (errstr); + } + + private int getStatus() throws Exception + { + return (p.exitValue()); + } + + /* + * Clean up opened file descriptors. + */ + private void dispose() { + + try { + p.getInputStream().close(); + p.getOutputStream().close(); + p.getErrorStream().close(); + p.destroy(); + } + catch (Exception e) { + Debug.message("SVR:" + e.getMessage()); + } + } + + /* + * Log all commands as is except lpset with a password. + */ + private void debug_log(String cmd) + { + if ((cmd.indexOf("lpset") != -1) && + (cmd.indexOf(" -w ") != -1)) { + String clean = ""; + int i = cmd.indexOf(" -w "); + int j = 0; + + try { + i += 4; + clean = cmd.substring(0, i); + clean = clean.concat("**** "); + while (cmd.charAt(i) != ' ') { + i++; + } + } catch (Exception e) { + Debug.message("SVR: lpset command with a passwd."); + return; + } + + clean = clean.concat(cmd.substring(i, cmd.length())); + Debug.message("SVR: " + clean); + + } else { + Debug.message("SVR: " + cmd); + } + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Test.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Test.java new file mode 100644 index 0000000000..31e9339f10 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Test.java @@ -0,0 +1,369 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Test + * Command line front end to Printer class + * + * Takes one argument - the name of a test file + * The format of the file is: + * Required: + * action=[add,delete,modify,view,list] + * + * Optional: + * printername= + * printertype= + * printserver= + * comment= + * device= + * notify= + * protocol= + * destination= + * extensions= + * default_printer=[true,false] + * banner= + * enable=[true,false] + * accept=[true,false] + * file_contents=[space seperated list] + * user_allow_list=[space seperated list] + * user_deny_list=[space seperated list] + * nameservice=[system,nis] + * nshost= + * user= + * passwd= + * locale= + * + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +public class Test { + public static void main(String[] args) { + String tmpstr; + int i; + String testfile = ""; + if (args.length == 1) { + testfile = args[0]; + } else { + System.out.println("Usage: Test testfile"); + System.exit(1); + } + + String cmd = "/usr/bin/cat " + testfile; + String o = null; + try { + SysCommand syscmd = new SysCommand(); + syscmd.exec(cmd); + if (syscmd.getExitValue() != 0) { + System.out.println("Problem opening test file"); + System.exit(1); + } + o = syscmd.getOutput(); + syscmd = null; + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + o = o.concat("\n"); + + String action = getToken(o, "action="); + String printername = getToken(o, "printername="); + String printertype = getToken(o, "printertype="); + String printserver = getToken(o, "printserver="); + String comment = getToken(o, "comment="); + String device = getToken(o, "device="); + String notify = getToken(o, "notify="); + String banner = getToken(o, "banner="); + String protocol = getToken(o, "protocol="); + String destination = getToken(o, "destination="); + String extensions = getToken(o, "extensions="); + + String[] file_contents = null; + String[] user_allow_list = null; + String[] user_deny_list = null; + + StringTokenizer st; + tmpstr = getToken(o, "file_contents="); + if (tmpstr != null) { + st = new StringTokenizer(tmpstr); + if (st.countTokens() != 0) { + file_contents = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + file_contents[i] = st.nextToken(); + } + } + } + tmpstr = getToken(o, "user_allow_list="); + if (tmpstr != null) { + st = new StringTokenizer(tmpstr); + if (st.countTokens() != 0) { + user_allow_list = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + user_allow_list[i] = st.nextToken(); + } + } + } + tmpstr = getToken(o, "user_deny_list="); + if (tmpstr != null) { + st = new StringTokenizer(tmpstr); + if (st.countTokens() != 0) { + user_deny_list = new String[st.countTokens()]; + for (i = 0; st.hasMoreTokens(); i++) { + user_deny_list[i] = st.nextToken(); + } + } + } + + boolean default_printer = false; + boolean enable = false; + boolean accept = false; + + tmpstr = getToken(o, "default_printer="); + if (tmpstr != null) { + if (tmpstr.equals("true")) { + default_printer = true; + } + } + tmpstr = getToken(o, "enable="); + if (tmpstr != null) { + if (tmpstr.equals("true")) { + enable = true; + } + } + tmpstr = getToken(o, "accept="); + if (tmpstr != null) { + if (tmpstr.equals("true")) { + accept = true; + } + } + + String nameservice = getToken(o, "nameservice="); + String nshost = getToken(o, "nshost="); + String user = getToken(o, "user="); + String passwd = getToken(o, "passwd="); + String locale = getToken(o, "locale="); + + // + // Done parsing. Let's do the work. + // + Debug.setDebugLevel(Debug.ALL); + + NameService ns = null; + try { + ns = new NameService(nameservice); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + if (nameservice.equals("nis") || nameservice.equals("ldap")) { + if (nshost != null) + ns.setNameServiceHost(nshost); + if (user != null) + ns.setUser(user); + if (passwd != null) + ns.setPasswd(passwd); + } + try { + ns.checkAuth(); + } + catch (Exception e) { + System.out.println(e); + } + + Printer p = new Printer(ns); + + p.setPrinterName(printername); + p.setPrinterType(printertype); + p.setPrintServer(printserver); + p.setFileContents(file_contents); + p.setComment(comment); + p.setDevice(device); + p.setNotify(notify); + p.setProtocol(protocol); + p.setDestination(destination); + p.setIsDefaultPrinter(default_printer); + p.setBanner(banner); + p.setEnable(enable); + p.setAccept(accept); + p.setUserAllowList(user_allow_list); + p.setUserDenyList(user_deny_list); + p.setLocale(locale); + + if (action.equals("list")) { + String[] plist = null; + try { + plist = PrinterUtil.getPrinterList(ns); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + if (plist == null) { + System.out.println("No printers"); + } else { + printPList(plist); + } + } else if (action.equals("view")) { + try { + p.getPrinterDetails(); + } + catch (Exception e) + { + System.out.println(e); + } + printView(p); + } else if (action.equals("add")) { + try { + if (device == null) { + p.addRemotePrinter(); + } else { + p.addLocalPrinter(); + } + } + catch (Exception e) + { + System.out.println(e); + } + } else if (action.equals("modify")) { + try { + p.modifyPrinter(); + } + catch (Exception e) + { + System.out.println(e); + } + } else if (action.equals("delete")) { + try { + p.deletePrinter(); + } + catch (Exception e) + { + System.out.println(e); + } + } else { + System.out.println("unknown action"); + System.exit(1); + } + System.out.println("============================"); + System.out.println("Commands:\n" + p.getCmdLog()); + System.out.println("Errors:\n" + p.getErrorLog()); + System.out.println("Warnings:\n" + p.getWarnLog()); + System.exit(0); + } + + private static String getToken(String str, String sub) + { + int i = -1; + int j = -1; + String result = null; + + i = str.indexOf(sub); + if (i != -1) { + i = i + sub.length(); + j = str.indexOf("\n", i); + if (j != -1) { + result = str.substring(i, j); + result = result.trim(); + if (result.equals("")) + result = null; + } + } + return (result); + } + + private static void printPList(String[] list) + { + if (list == null) + return; + if (list[0].equals("")) { + System.out.println("No printers found"); + return; + } + + for (int i = 0; i < list.length; ) { + System.out.println("name: " + list[i++]); + System.out.println("server: " + list[i++]); + System.out.println("comment: " + list[i++]); + } + } + + private static void printView(Printer p) + { + String arr[]; + int i; + + System.out.println("Name: " + p.getPrinterName()); + System.out.println("Type: " + p.getPrinterType()); + System.out.println("Server: " + p.getPrintServer()); + System.out.println("Comment: " + p.getComment()); + System.out.println("Device: " + p.getDevice()); + System.out.println("Notify: " + p.getNotify()); + System.out.println("Protocol: " + p.getProtocol()); + System.out.println("Dest: " + p.getDestination()); + System.out.println("Extensions: " + p.getExtensions()); + System.out.println("Default: " + p.getIsDefaultPrinter()); + System.out.println("Banner: " + p.getBanner()); + System.out.println("Enable: " + p.getEnable()); + System.out.println("Accept: " + p.getAccept()); + + arr = p.getFileContents(); + if (arr == null) { + System.out.println("Contents: NULL"); + } else { + System.out.println("Contents:"); + for (i = 0; i < arr.length; i++) { + System.out.println("\t\t" + arr[i]); + } + } + arr = p.getUserAllowList(); + if (arr == null) { + System.out.println("Users allow: NULL"); + } else { + System.out.println("Users allow:"); + for (i = 0; i < arr.length; i++) { + System.out.println("\t\t" + arr[i]); + } + } + arr = p.getUserDenyList(); + if (arr == null) { + System.out.println("Users deny: NULL"); + } else { + System.out.println("Users deny:"); + for (i = 0; i < arr.length; i++) { + System.out.println("\t\t" + arr[i]); + } + } + + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Valid.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Valid.java new file mode 100644 index 0000000000..4b1d1284cf --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/Valid.java @@ -0,0 +1,396 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Valid + * Check user input. We are mostly concerned with characters + * we know will cause problems for the sub-system. + * multi-byte characters will be screened out by the gui. + */ + +package com.sun.admin.pm.server; + +import java.io.*; +import java.util.*; + +public class Valid { + + static String spaces = "\t "; + /* JSTYLED */ + static String badmetas = "\"\\$^&*(){}`'|;:?<>"; + /* JSTYLED */ + static String baddestmetas = "\"\\$^&*(){}`'|;?<>"; + + // lpadmin only takes 14. + static int validlocalprinternamelength = 14; + // MAXHOSTNAMELEN seems reasonable. + static int validremoteprinternamelength = 256; + + static int validdestinationlength = 1023; // BUFSIZ-1 seems generous + static int validcommentlength = 256; // From admintool + static int validservernamelength = 256; // MAXHOSTNAMELEN = 256 + static int validusernamelength = 128; // LOGNAME_MAX = 8 but since + // it's not enforced ... + static int validmakelength = 256; // MAXNAMELEN = 256 + + // + // main for testing + // + public static void main(String[] args) { + String[] users_arr = { "one", "two", "th`ee" }; + try { + System.out.println(localPrinterName("foo/bar")); + System.out.println(comment("abad:comment")); + System.out.println(device("/dev/term/a")); + System.out.println(printerType(" ")); + System.out.println(serverName(",bad")); + System.out.println(users(users_arr)); + } + catch (Exception e) + { + System.out.println(e); + System.exit(1); + } + System.exit(0); + } + + // + // Valid comment + // + public static boolean comment(String cstr) + { + Debug.message("SVR: Valid.comment()"); + Debug.message("SVR: comment=" + cstr); + + if (cstr == null) + return (false); + if (cstr.length() > validcommentlength) + return (false); + + String c = cstr.substring(0, 1); + // Causes problems in lpadmin + if (c.equals(",")) { + return (false); + } + if (c.equals("-")) { + return (false); + } + + return (validString(cstr, badmetas + "=")); + } + + // + // Valid local printer name + // + public static boolean localPrinterName(String pn) + { + Debug.message("SVR: Valid.localPrinterName()"); + Debug.message("SVR: printerName=" + pn); + + if (pn == null) + return (false); + if (pn.length() == 0) + return (false); + if (pn.length() > validlocalprinternamelength) + return (false); + + String c = pn.substring(0, 1); + if (c.equals(".")) { + return (false); + } + if (c.equals("!")) { + return (false); + } + if (c.equals("=")) { + return (false); + } + + // Keywords for the sub-system + if (pn.equals("_default")) + return (false); + if (pn.equals("_all")) + return (false); + + return (validString(pn, badmetas + spaces + "/#:,")); + } + + // + // Valid remote printer name + // + public static boolean remotePrinterName(String pn) + { + Debug.message("SVR: Valid.remotePrinterName()"); + Debug.message("SVR: printerName=" + pn); + + if (pn == null) + return (false); + if (pn.length() == 0) + return (false); + if (pn.length() > validremoteprinternamelength) + return (false); + + // Keywords for the sub-system + if (pn.equals("_default")) + return (false); + if (pn.equals("_all")) + return (false); + + String c = pn.substring(0, 1); + if (c.equals(".")) { + return (false); + } + if (c.equals("!")) { + return (false); + } + if (c.equals("=")) { + return (false); + } + + return (validString(pn, badmetas + spaces + "/#:,")); + } + + // + // Valid device + // Does it exist and is it writable. + // + public static boolean device(String dev) + throws Exception + { + int exitvalue; + + Debug.message("SVR: Valid.device()"); + Debug.message("SVR: device=" + dev); + + if (dev == null) + return (false); + if (dev.length() == 0) + return (false); + if (dev.indexOf("://") != 0) // don't test if it's a URI + return (true); + + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/test -w " + dev); + exitvalue = syscmd.getExitValue(); + syscmd = null; + + if (exitvalue != 0) + return (false); + return (true); + } + + // + // Valid Printer Make + // Does a directory of that name exist, and is it readable. + // + + public static boolean make(String dir) + throws Exception + { + int exitvalue; + + Debug.message("SVR: Valid.make()"); + Debug.message("SVR: dir=" + dir); + + if (dir == null) + return (false); + if ((dir.length() == 0) || (dir.length() > validmakelength)) + return (false); + + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/test -d -r " + dir); + exitvalue = syscmd.getExitValue(); + syscmd = null; + + if (exitvalue != 0) + return (false); + return (true); + } + + // + // Valid printer type + // + public static boolean printerType(String pt) + throws Exception + { + int exitvalue; + + Debug.message("SVR: Valid.printerType()"); + Debug.message("SVR: printerType=" + pt); + + if (pt == null) + return (false); + if (pt.length() == 0) + return (false); + + if (pt.equals("/")) + return (false); + + if (pt.indexOf(" ") != -1) { + return (false); + } + if (pt.indexOf("\t") != -1) { + return (false); + } + + String c = pt.substring(0, 1); + String path = "/usr/share/lib/terminfo/" + c + "/" + pt; + SysCommand syscmd = new SysCommand(); + syscmd.exec("/usr/bin/test -r " + path); + exitvalue = syscmd.getExitValue(); + syscmd = null; + + if (exitvalue != 0) + return (false); + return (true); + } + + // + // Valid destination + // + public static boolean destination(String d) + { + Debug.message("SVR: Valid.destination()"); + Debug.message("SVR: destination=" + d); + + if (d == null) + return (false); + if (d.length() == 0) + return (false); + if (d.length() > validdestinationlength) + return (false); + + return (validString(d, baddestmetas + spaces)); + } + + // + // Valid Server name + // + public static boolean serverName(String s) + { + Debug.message("SVR: Valid.serverName()"); + Debug.message("SVR: serverName=" + s); + + if (s == null) + return (false); + if (s.length() == 0) + return (false); + if (s.length() > validservernamelength) + return (false); + + String c = s.substring(0, 1); + if (c.equals("!")) { + return (false); + } + if (c.equals("=")) { + return (false); + } + + return (validString(s, badmetas + spaces + "#,:")); + } + + // + // Users + // + public static boolean users(String[] u) + { + Debug.message("SVR: Valid.users()"); + Debug.message("SVR: users = " + PrinterDebug.arr_to_str(u)); + + if (u == null) { + return (false); + } + if (u.length == 0) { + return (false); + } + + for (int i = 0; i < u.length; i++) { + if (u[i] == null) { + return (false); + } + if (u[i].length() == 0) { + return (false); + } + if (u[i].length() > validusernamelength) { + return (false); + } + if (!validString(u[i], badmetas + spaces)) { + return (false); + } + } + return (true); + } + + // + // User + // + public static boolean user(String u) + { + Debug.message("SVR: Valid.users()"); + Debug.message("SVR: users = " + u); + + if (u == null) { + return (false); + } + if (u.length() == 0) { + return (false); + } + + if (u == null) { + return (false); + } + if (u.length() == 0) { + return (false); + } + if (u.length() > validusernamelength) { + return (false); + } + if (!validString(u, badmetas + spaces)) { + return (false); + } + return (true); + } + + + // + // Check to see if a string contains an invalid character + // + private static boolean validString(String str, String badchars) + { + // Can't start with a hyphen + String start = str.substring(0, 1); + if (start.equals("-")) + return (false); + + char[] badchars_arr = badchars.toCharArray(); + + for (int i = 0; i < badchars_arr.length; i++) { + if (str.indexOf(badchars_arr[i]) != -1) { + return (false); + } + } + return (true); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmAuthException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmAuthException.java new file mode 100644 index 0000000000..3c24fa53d2 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmAuthException.java @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmAuthException class + * User is not authorized to perform an operation. + */ + +package com.sun.admin.pm.server; + +public class pmAuthException extends pmException +{ + public pmAuthException() + { + super(); + } + + public pmAuthException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmAuthRhostException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmAuthRhostException.java new file mode 100644 index 0000000000..2f6b41e5f3 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmAuthRhostException.java @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmAuthRhostException class + * A .rhosts entry has not been set up allowing updates of + * pre-2.6 nis servers. + * + */ + +package com.sun.admin.pm.server; + +public class pmAuthRhostException extends pmAuthException +{ + public pmAuthRhostException() + { + super(); + } + + public pmAuthRhostException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmCmdFailedException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmCmdFailedException.java new file mode 100644 index 0000000000..26925a1d97 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmCmdFailedException.java @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmCmdFailedException class + * A command unexpectedly failed. + */ + +package com.sun.admin.pm.server; + +public class pmCmdFailedException extends pmException +{ + public pmCmdFailedException() + { + super(); + } + + public pmCmdFailedException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmException.java new file mode 100644 index 0000000000..cbb247e550 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmException.java @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmException class + * General print manager exceptions + */ + +package com.sun.admin.pm.server; + +public class pmException extends Exception +{ + public pmException() + { + super(); + } + + public pmException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmHostNotPingableException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmHostNotPingableException.java new file mode 100644 index 0000000000..cc8464a17b --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmHostNotPingableException.java @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmHostNotPingableException class + * A host is not accessible using ping. + */ + +package com.sun.admin.pm.server; + +public class pmHostNotPingableException extends pmException +{ + public pmHostNotPingableException() + { + super(); + } + + public pmHostNotPingableException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmInternalErrorException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmInternalErrorException.java new file mode 100644 index 0000000000..08f50dbc8f --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmInternalErrorException.java @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmInternalErrorException class + * An internal error has occuured. This is often associated + * with the server not getting enough information to perform + * an action. + */ + +package com.sun.admin.pm.server; + +public class pmInternalErrorException extends pmException +{ + public pmInternalErrorException() + { + super(); + } + + public pmInternalErrorException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmMisc.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmMisc.java new file mode 100644 index 0000000000..31adf7dad1 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmMisc.java @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Miscellaneous functions which don't apply to printer object + */ + +package com.sun.admin.pm.server; + +import java.io.*; + +/* + * Class is miscellaneous routines + */ + +public class pmMisc { + + public static boolean isppdCachefile() + { + File ppdcache = new File("/usr/lib/lp/model/ppd/ppdcache"); + return (ppdcache.isFile()); + } + +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmNSNotConfiguredException.java b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmNSNotConfiguredException.java new file mode 100644 index 0000000000..1ffd8ccd50 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmNSNotConfiguredException.java @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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 + */ +/* + * ident "%Z%%M% %I% %E% SMI" + * + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * pmNSNotConfiguredException class + * The selected name service does not appear to be configured + * on the host. + */ + +package com.sun.admin.pm.server; + +public class pmNSNotConfiguredException extends pmException +{ + public pmNSNotConfiguredException() + { + super(); + } + + public pmNSNotConfiguredException(String s) + { + super(s); + } +} diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmtest b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmtest new file mode 100644 index 0000000000..70a7770530 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/pmtest @@ -0,0 +1,28 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 1999 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" + +/usr/bin/java com.sun.admin.pm.server.Test $1 diff --git a/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/tests/template b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/tests/template new file mode 100644 index 0000000000..4096d9bae5 --- /dev/null +++ b/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/tests/template @@ -0,0 +1,27 @@ +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#pragma ident "%Z%%M% %I% %E% SMI" + +action= +printername= +printertype= +printserver= +file_contents= +comment= +device= +notify= +protocol= +destination= +default_printer= +banner= +enable= +accept= +user_allow_list= +user_deny_list= +nameservice= +nshost= +user= +passwd= +locale= diff --git a/usr/src/cmd/print/scripts/Makefile b/usr/src/cmd/print/scripts/Makefile new file mode 100644 index 0000000000..5012684790 --- /dev/null +++ b/usr/src/cmd/print/scripts/Makefile @@ -0,0 +1,136 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "%Z%%M% %I% %E% SMI" +# +# cmd/lp/etc/Makefile +# + +include ../Makefile.sp + +ROOTPRINTLIB = $(ROOTLIB)/print +ROOTLIBLPBIN = $(ROOTLIBLP)/bin + +$(ROOTVARSPOOLPRINT) := OWNER=root + +OWNER = root +GROUP = lp +FILEMODE = 0755 + +MSGFILES = accept lpadmin +POFILE = scripts.po + +PROG = conv_lp conv_lpd Makefile.yp +ROOTLIBPRINTPROG= $(PROG:%=$(ROOTPRINTLIB)/%) +$(ROOTLIBPRINTPROG) := FILEMODE=0555 +$(ROOTPRINTLIB)/Makefile.yp := FILEMODE=0444 + +USRSBINPROG= accept lpsystem lpadmin +ROOTUSRSBINPROG= $(USRSBINPROG:%=$(ROOTUSRSBIN)/%) +$(ROOTUSRSBINPROG) := FILEMODE=555 + +PCONF= printers.conf +ROOTPCONF= $(PCONF:%=$(ROOTETC)/%) +$(ROOTPCONF) := OWNER=root +$(ROOTPCONF) := GROUP=sys +$(ROOTPCONF) := FILEMODE=644 + +PPDPROGS= getmakes getmodels getppdfile getppds ppdfilename2mmp +ROOTPPDPROGS= $(PPDPROGS:%=$(ROOTLIBLPBIN)/%) +$(ROOTPPDPROGS) := OWNER=root +$(ROOTPPDPROGS) := GROUP=lp +$(ROOTPPDPROGS) := FILEMODE=555 + +ACCEPTLINKS= $(ROOTUSRSBIN)/reject $(ROOTBIN)/enable \ + $(ROOTBIN)/disable $(ROOTLIB)/accept \ + $(ROOTLIB)/reject + +LIBLINKS= $(ROOTLIB)/lpadmin $(ROOTLIB)/lpsystem + + +.KEEP_STATE: + +all : $(PROG) + +$(ROOTLIB)/print/% $(ROOTINIT_D)/%: % + $(INS.file) + +$(ROOTLIBLPBIN)/%: % + $(INS.file) + +$(ROOTINIT_D) $(ROOTUSRSBIN) $(ROOTVARSPOOLPRINT): + $(INS.dir) + +$(ROOTLIB)/lpadmin: + $(RM) $@; $(SYMLINK) ../sbin/lpadmin $@ + +$(ROOTLIB)/lpsystem: + $(RM) $@; $(SYMLINK) ../sbin/lpsystem $@ + +$(ACCEPTLINKS): + $(RM) $@; $(SYMLINK) ../sbin/accept $@ + +$(ROOTLNKPROGS) : $(ROOTSTARTPROG) + $(RM) $@; $(LN) $(ROOTSTARTPROG) $@ + +_msg: $(POFILE) + +$(POFILE): $(MSGFILES) + grep gettext $(MSGFILES) | tr '`' ' ' | sed -e "s/gettext \"/gettext \(\"/" | sed -e "s/$$/);/" > $(POFILE).i + $(XGETTEXT) -s $(POFILE).i + $(RM) $@ $(POFILE).i + mv messages.po $(POFILE) + +# +# Create a message file to test with +# +_msg_test: + grep gettext $(MSGFILES) | tr '`' ' ' | sed -e "s/gettext \"/gettext \(\"/" | sed -e "s/$$/);/" > $(POFILE).i + $(XGETTEXT) -s -m "xxx" $(POFILE).i + $(RM) $@ $(POFILE).i + mv messages.po $(POFILE) + +install: $(ROOTINIT_D) $(ROOTLNKPROGS) \ + $(ROOTLIBPRINTPROG) $(ROOTSTARTPROG) \ + $(ROOTUSRSBIN) $(ROOTUSRSBINPROG) \ + $(ROOTVARSPOOLPRINT) $(ROOTPCONF) \ + $(ROOTPPDPROGS) \ + $(LIBLINKS) $(ACCEPTLINKS) + +$(SYMLINKS1): + $(RM) $@; $(SYMLINK) ../sbin/$(SBINPROG1) $@ + +$(SYMLINKS2): + $(RM) $@; $(SYMLINK) ../sbin/$(SBINPROG2) $@ + +$(REJECTLINK): + $(RM) $@; $(SYMLINK) accept $@ + +clean: + $(RM) $(POFILE) + +clobber: clean + +strip lint: diff --git a/usr/src/cmd/print/scripts/Makefile.yp b/usr/src/cmd/print/scripts/Makefile.yp new file mode 100644 index 0000000000..2e5647f4f1 --- /dev/null +++ b/usr/src/cmd/print/scripts/Makefile.yp @@ -0,0 +1,58 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# Copyrights (c) 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# Example pieces of NIS Makefile. +# +# ident "%Z%%M% %I% %E% SMI" +# + +# +# Printers conf Rules +# +DIR=/etc +# +$(DOM)/printers.conf.time: $(DIR)/printers.conf + -@if [ -f $(DIR)/printers.conf ]; then \ + (sed -e '/^#/d' -e s/#.*$$// -e 's/[ ][ ]*$$//' \ + -e '/\\$$/s/\\$$/ /' $(DIR)/printers.conf $(CHKPIPE))\ + |( awk '/ $$/ {printf "%s", $$0} !/ $$/ {print}' $(CHKPIPE))\ + |( sed -e 's/[ ][ ]*/ /g' -e 's/:[ ]*:/:/' \ + $(CHKPIPE))\ + | awk -F: '{n=split($$1, nm, "|"); for (i=1; i<=n; i++) \ + print nm[i], $$0}' \ + | $(MAKEDBM) - $(YPDBDIR)/$(DOM)/printers.conf.byname ; \ + touch $(DOM)/printers.conf.time; \ + echo "updated printers.conf"; \ + if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOM) printers.conf.byname; \ + fi ; \ + if [ ! $(NOPUSH) ]; then echo "pushed printers.conf"; fi ; \ + else \ + echo "couldn't find $(DIR)/printers.conf"; \ + fi + +# +# Dependency +# +printers.conf: $(DOM)/printers.conf.time diff --git a/usr/src/cmd/print/scripts/accept b/usr/src/cmd/print/scripts/accept new file mode 100644 index 0000000000..8d2fb4a995 --- /dev/null +++ b/usr/src/cmd/print/scripts/accept @@ -0,0 +1,141 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +PATH=/usr/ucb:/bin:/usr/bin:/usr/sbin export PATH +cmd_name=`basename $0` +args="" +reason="" +destinations="" +exit_code=0 +local_exit=0 + +TEXTDOMAIN="SUNW_OST_OSCMD" +export TEXTDOMAIN + +# +# check for some options +# +if [ $# -lt 1 ] ; then + gettext "Usage: " + echo -n $cmd_name $valid_opts + gettext " printer ..." + echo + exit 1 +fi + +# set variables for command +case $cmd_name in + accept) + valid_opts="" + options="\?" + ;; + enable) + valid_opts="" + options="\?" + ;; + reject) + valid_opts="[ -r reason ]" + options="r:" + ;; + disable) + valid_opts="[ -c | -W ] [ -r reason ]" + options="Wcr:" + ;; + *) + gettext "Error: " + echo -n $cmd_name + gettext " - invalid name" + echo + exit 1 + ;; +esac + +# Strip off legal options +while getopts $options arg +do + case $arg in + c|W) + args="${args} -$arg" + ;; + r) + reason=${OPTARG} + ;; + \?) + gettext "Usage: " + echo -n $cmd_name $valid_opts + gettext " printer ..." + echo + exit 1 + ;; + esac +done +shift `expr $OPTIND - 1` + + +if [ "$*" = "" ] ; then + gettext "No destination specified" + echo + exit 1 +fi + +# Each destination +for printer in $* +do + if [ -f /etc/lp/classes/$printer -o -d /etc/lp/printers/$printer -a \ + -f /usr/lib/lp/local/$cmd_name ] + then + destinations="${destinations} ${printer}" + else + check=`lpstat -v $printer -L` + if [ -n "$check" ] + then + gettext "Warning: " + echo -n $printer + gettext " is remote, $cmd_name has no meaning." + echo + else + exit_code=1 + fi + fi +done + +if [ -n "$destinations" ] +then + if [ -n "$reason" ] ; then + /usr/lib/lp/local/$cmd_name -r "$reason" $args $destinations + else + /usr/lib/lp/local/$cmd_name $args $destinations + fi + local_exit=$? +fi + +if [ ${local_exit} -ne 0 ] ; then + exit ${local_exit} +else + exit ${exit_code} +fi diff --git a/usr/src/cmd/print/scripts/conv_lp b/usr/src/cmd/print/scripts/conv_lp new file mode 100644 index 0000000000..286ba6f682 --- /dev/null +++ b/usr/src/cmd/print/scripts/conv_lp @@ -0,0 +1,102 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +# This script will automatically generate a "printcap" file +# from the currently configured LP printer configuration. +# +PATH=/bin:/usr/bin:/usr/sbin + +TEXTDOMAIN="SUNW_OST_OSCMD" +export TEXTDOMAIN + +export PATH +umask 022 + +set -- `getopt d:f: $*` +if [ $? != 0 ] ; then + echo "Usage: $0 [-d dir] [-f file]" + exit 1 +fi + +for OPTION in $* +do + case $OPTION in + -f) SYSTEM_FILE=$2; shift 2;; + -d) BASE_DIR=$2; shift 2;; + --) shift; break;; + esac +done + +SYSTEM_FILE=${SYSTEM_FILE:-"${BASE_DIR}/etc/printers.conf"} + +if [ ! -d ${BASE_DIR}/etc/lp/printers ] ; then + gettext "Exit $0: There is no directory ${BASE_DIR}/etc/lp/printers\n\tfrom which to create /etc/printers.conf." + exit 0 +fi + +if [ -f ${BASE_DIR}/etc/lp/default ] ; then + DEFAULT_PRINTER=`cat ${BASE_DIR}/etc/lp/default` + lpset -n system -a "use=${DEFAULT_PRINTER}" _default + mv ${BASE_DIR}/etc/lp/default ${BASE_DIR}/etc/default.orig +fi + +cd ${BASE_DIR}/etc/lp/printers # get the list of locally configured printers +PRINTERS=`echo *` + +for PRINTER in ${PRINTERS} # for each printer get config info +do + if [ "${PRINTER}" = "*" ] ; then + continue + fi + + RNAME=${PRINTER} + DESC="" + RHOST="" + + if [ -f ${PRINTER}/comment ] ; then + DESC=`cat ${PRINTER}/comment` + fi + + REMOTE=`grep Remote: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Remote: //"` + DEVICE=`grep Device: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Device: //"` + + if [ -n "${DEVICE}" ] ; then + RHOST=`uname -n` + elif [ `echo ${REMOTE} | grep -c \!` -ne 0 ] ; then + RHOST=`echo $REMOTE | cut -d \! -f 1` + RNAME=`echo $REMOTE | cut -d \! -f 2` + else + RHOST=${REMOTE} + fi + + lpset -n system -a "bsdaddr=${RHOST},${RNAME}" -a "description=${DESC}" \ + ${PRINTER} + +done + +exit 0 diff --git a/usr/src/cmd/print/scripts/conv_lpd b/usr/src/cmd/print/scripts/conv_lpd new file mode 100644 index 0000000000..e75d411ba8 --- /dev/null +++ b/usr/src/cmd/print/scripts/conv_lpd @@ -0,0 +1,213 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# +# Printcap <-> Printers.conf conversion utility... +# +# Usage: conv_lpd [ -c (printers|printcap) ] [ -n ] (file) +# + +TEXTDOMAIN="SUNW_OST_OSCMD" +export TEXTDOMAIN + +USAGE=`gettext "Usage: conv_lpd [ -c (printers|printcap) ] [ -n ] (file)\n"` + +PATH=/usr/bin:/bin:/usr/sbin export PATH +conversion="printers" +namelist=0 + +umask 022 + +for i in $* +do + case $1 in + -c*) + conversion=$2; + shift ; shift ; + ;; + -n*) + namelist=1; + shift ; + ;; + *) + break ; + ;; + esac +done + +TMPF1=/tmp/tinput1.$$ +TMPF2=/tmp/tinput2.$$ +FILE=/tmp/input.$$ + +# Any remaining arg is the "file" specification. It is a required arg. +if [ -z "$1" ]; then + echo $USAGE + exit 1 +else + cp $1 $TMPF1 +fi + +echo >>$TMPF1 +echo "_done" >>$TMPF1 + +# +# First, strip all continuation characters, leaving one, single line +# for each printer entry. +# + CONV_FIX=/usr/lib/print/conv_fix + + if [ -f $CONV_FIX ]; then + $CONV_FIX -f $TMPF1 -o $TMPF2 + if [ $? != 0 ]; then + echo "$0:" + gettext "Fatal Error: $CONV_FIX failed.\n" + gettext "Please contact your Sun support representative.\n" + exit 1 + fi + else + gettext "$0: Fatal: Cannot locate $CONV_FIX binary.\n" + gettext "Please contact your Sun support representative.\n" + exit 1 + fi + +# +# Continuation characters are now stripped. Continue processing. +# + /bin/sed -e "s/:[ ]*:/:/g" $TMPF2 > $FILE + +# +# Empty colons ":[ <TAB>]*:" are now stripped. Continue processing. +# + +nawk ' +BEGIN { + "uname -n" | getline ; + host = $0 ; + found = 0 ; + local_pr = 0; +} + +{ + FS=":"; OFS=":" ; + if ($0 !~ /^#/) + { + if ($0 ~ /^[_a-zA-Z0-9_]/) { # New entry + if ( found != 0 ) { + if ( "'$namelist'" == 1 ) + printer = names ; + else + printer = name[1] ; + + if ( "'$conversion'" == "printers" ) { + printf "\n%s:", names ; + for (key in values) { + if ((key != "rp") && + (key != "rm")) { + printf "\\\n\t:%s=%s:", + key, values[key] ; + delete values[key]; + } + } + if (values["rm"] != "") { + printf "\\\n\t:bsdaddr=%s,%s:", \ + values["rm"], \ + values["rp"] ; + if (values["rm"] == host) local_pr++; + } else { + printf "\\\n\t:bsdaddr=%s,%s:", \ + host, printer ; + local_pr++; + } + delete values["rp"]; + delete values["rm"]; + } else { + printf "\n%s:", names ; + for (key in values) { + if (key == "bsdaddr") { + split(values[key], + pair, ","); + printf "\\\n\t:%s=%s:", \ + "rm", pair[1] ; + if (pair[2] == "") + pair[2] = printer; + printf "\\\n\t:%s=%s:", \ + "rp", pair[2] ; + + } else if ((key == "br") || \ + (key == "fc") || \ + (key == "fs") || \ + (key == "mc") || \ + (key == "mx") || \ + (key == "pc") || \ + (key == "pl") || \ + (key == "pw") || \ + (key == "px") || \ + (key == "py") || \ + (key == "xc") || \ + (key == "xs")) + printf "\\\n\t:%s#%s:", \ + key, \ + values[key] ; + else if (values[key] == "true") + printf "\\\n\t:%s:", \ + key ; + else if (values[key] != "false") + printf "\\\n\t:%s=%s:", \ + key, \ + values[key] ; + delete values[key]; + } + } + } + split( $1, name, "|"); + names = $1 ; + found++; + } + + for ( i = 1 ; i <= NF ; i++ ) { + if (($i == names) || ($i == "") || \ + ($i == "\t")) + continue ; + if ((split( $i, pair, "=" ) != 2) && \ + (split( $i, pair, "\#") != 2)) + pair[2] = "true"; + + if (pair[1] != "" && pair[1] != " ") + values[pair[1]] = pair[2] ; + } + } +} +END { + printf "\n" ; + if (local_pr != 0) + printf "One or more printers are local, you may want to run lpadmin to configure LP server side operation\n" | "cat 1>&2" ; + +}' ${FILE} + +/bin/rm -f ${TMPF1} ${TMP2} ${FILE} + +exit 0 diff --git a/usr/src/cmd/print/scripts/getmakes b/usr/src/cmd/print/scripts/getmakes new file mode 100644 index 0000000000..2c36b203b0 --- /dev/null +++ b/usr/src/cmd/print/scripts/getmakes @@ -0,0 +1,43 @@ +#!/usr/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# get a list of the Manufacturers from the ppdcache +# + +if [[ -f /usr/lib/lp/model/ppd/ppdcache ]]; then + /bin/cat /usr/lib/lp/model/ppd/ppdcache | + nawk '{FS=":"; print $1}' | + nawk '{print $1}' | + /bin/sort -u + + exit 0 +else + exit 1 +fi diff --git a/usr/src/cmd/print/scripts/getmodels b/usr/src/cmd/print/scripts/getmodels new file mode 100644 index 0000000000..61d1eb9961 --- /dev/null +++ b/usr/src/cmd/print/scripts/getmodels @@ -0,0 +1,43 @@ +#!/usr/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# get a list of the Models for this Model from the ppdcache +# + +if [[ $# -lt 1 ]]; then + exit 1 +fi + +if [[ -f /usr/lib/lp/model/ppd/ppdcache ]]; then + /bin/grep ^$1 /usr/lib/lp/model/ppd/ppdcache | nawk '{FS=":"; print $2}' | uniq + exit 0 +else + exit 1 +fi diff --git a/usr/src/cmd/print/scripts/getppdfile b/usr/src/cmd/print/scripts/getppdfile new file mode 100644 index 0000000000..b299bf25c6 --- /dev/null +++ b/usr/src/cmd/print/scripts/getppdfile @@ -0,0 +1,54 @@ +#!/usr/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Get the path/filename for this ppd NickName +# + +if [[ $# -lt 3 ]]; then + exit 1 +fi + +if [[ -f /usr/lib/lp/model/ppd/ppdcache ]]; then + typeset make=$1 + shift + modelppd=$* + typeset model=$(echo $modelppd | nawk '{FS=":"; print $1}') + typeset ppd=$(echo $modelppd | nawk '{FS=":"; print $2}' | + sed -e 's/^[ ]*//') + + /bin/grep ^$1 /usr/lib/lp/model/ppd/ppdcache | + /bin/grep "${model}:" | + /bin/grep "${ppd}:" | + nawk '{FS=":"; print $4}' + + exit 0 +else + exit 1 +fi diff --git a/usr/src/cmd/print/scripts/getppds b/usr/src/cmd/print/scripts/getppds new file mode 100644 index 0000000000..5e88538e69 --- /dev/null +++ b/usr/src/cmd/print/scripts/getppds @@ -0,0 +1,52 @@ +#!/usr/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +# +# get a list of the Models for this Model from the ppdcache +# + +if [[ $# -lt 2 ]]; then + exit 1 +fi + +typeset model + +if [[ -f /usr/lib/lp/model/ppd/ppdcache ]]; then + typeset make=$1 + shift + + /bin/grep $make /usr/lib/lp/model/ppd/ppdcache | + /bin/grep "$*:" | + nawk '{FS=":"; print $3}' + + exit 0 +else + exit 1 +fi diff --git a/usr/src/cmd/print/scripts/lpadmin b/usr/src/cmd/print/scripts/lpadmin new file mode 100644 index 0000000000..0daea176a1 --- /dev/null +++ b/usr/src/cmd/print/scripts/lpadmin @@ -0,0 +1,390 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +PATH=/bin:/usr/bin:/usr/sbin export PATH + +TEXTDOMAIN="SUNW_OST_OSCMD" +export TEXTDOMAIN + +LPSET=/usr/bin/lpset +LPGET=/usr/bin/lpget + +HOST=`/bin/uname -n` +PID=$$ + +cmd_name=lpadmin +exit_code=0 + +usage() { + gettext "Usage:\n" 1>&2 + gettext " lpadmin -p (printer) (options)\n" 1>&2 + gettext " lpadmin -x (dest)\n" 1>&2 + gettext " lpadmin -d (dest)\n" 1>&2 + gettext " lpadmin -S print-wheel -A alert-type [ -W minutes ]\n" 1>&2 + gettext " [ -Q requests ]\n" 1>&2 + gettext " lpadmin -M -f form-name [ -a [ -o filebreak ]\n" 1>&2 + gettext " [ -t tray-number ]]\n" 1>&2 + exit 1 +} + +# +# Delete entries in /etc/printers.conf for local printers/classes that no longer +# exist in the /etc/lp database +# + +delete_local() { + +# Get printer names for each local printer +# grep /etc/printers.conf for each bsdaddr for this server +# get printer name from that line + +for LINE in `grep bsdaddr=${HOST}, /etc/printers.conf` +do + PRINTER=`echo ${LINE} | sed -e 's/^:bsdaddr='$HOST',//' -e 's/[,:].*//'` + +# If there is not an entry for this printer in +# /etc/lp/printers or /etc/lp/classes +# Then delete the entry for this printer in /etc/printers.conf + + if [ ! -d /etc/lp/printers/${PRINTER} -a ! -f /etc/lp/classes/${PRINTER} ] ; + then + logger -p lpr.debug -t "lpadmin[${PID}]" \ + "Removing $PRINTER entry from /etc/printers.conf" + ${LPSET} -x ${PRINTER} + status=$? + + if [ ${status} -ne 0 ] ; then + gettext "Warning: error removing ${PRINTER} " 1>&2 + gettext "entry from /etc/printers.conf\n" 1>&2 + logger -p lpr.debug -t "lpadmin[${PID}]" \ + "Call to lpset -x $PRINTER exits with ${status}" + exit_code=1 + fi + fi +done + +# +# shutdown scheduler if there are no local printers +# +CONFIGS=/etc/lp/printers/*/configuration + +printers_configured=`echo $CONFIGS` +if [ "$printers_configured" = "$CONFIGS" ]; then + svcprop -q svc:/application/print/server:default && + svcadm disable svc:/application/print/server:default +fi +} + +delete_entries() { +if [ ! -f /etc/printers.conf ] ; then + logger -p lpr.debug -t "lpadmin[${PID}]" \ + "System error: Cannot access /etc/printers.conf" + gettext "lpadmin: System error; Cannot access /etc/printers.conf\n" 1>&2 + exit 1 +fi + +# remove _default + +DEFAULTP=`${LPGET} _default | grep use | sed -e 's/[ ]*use=//'` +${LPGET} -k bsdaddr ${DEFAULTP} >/dev/null 2>&1 +status=$? + +if [ ${status} -eq 0 ] ; then + ${LPSET} -x _default + status=$? + if [ ${status} -ne 0 ] ; then + gettext "Warning: error removing _default entry from /etc/printers.conf\n" 1>&2 + logger -p lpr.debug -t "lpadmin[${PID}]" \ + "Call to lpset -x _default exits with ${status}" + exit_code=1 + fi +fi + +# delete entries in /etc/printers.conf for printers/classes that have +# been deleted + +delete_local + +# Delete all the remote printers using bsdaddr + +for LINE in `grep bsdaddr /etc/printers.conf | grep -v ${HOST}` +do + PRINTER=`echo $LINE | sed -e 's/^:bsdaddr=[^,]*,//' -e 's/[,:].*//'` + ${LPSET} -x $PRINTER + status=$? + + if [ ${status} -ne 0 ] ; then + gettext "Warning: error removing ${PRINTER} entry from /etc/printers.conf\n" 1>&2 + logger -p lpr.debug -t "lpadmin[${PID}]" \ + "Call to lpset -x $PRINTER exits with ${status}" + exit_code=1 + fi +done +} + +if [ $# -lt 1 ] ; then + usage + exit 1 +fi + +# Deal with the -d option independently since getopts does not handle +# options that may or may not have arguments +# +first=$1 +second=$2 +third=$3 + +if [ ${first} = "-d" ] ; then + # check that there are no extra arguments + if [ -n "${third}" ] ; then + usage + exit 1 + fi + + + # be sure we have lpset and lpget + if [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then + gettext "lpadmin: System error; cannot set default printer\n" 1>&2 + exit 2 + fi + + if [ ! -n "${second}" ] ; then + ${LPGET} -n system _default >/dev/null 2>&1 + exit_code=$? + if [ ${exit_code} -eq 0 ] ; then + # delete _default entry in /etc/printers.conf + ${LPSET} -n system -x _default + exit_code=$? + if [ ${exit_code} -ne 0 ] ; then + gettext "lpadmin: System error while trying to delete default printer\n" 1>&2 + fi + else + # there was no _default, the work is done + exit_code=0 + fi + else + # add/change _default entry in /etc/printers.conf + ${LPGET} -k bsdaddr ${second} >/dev/null 2>&1 + exit_code=$? + if [ $exit_code -eq 0 ] ; then + ${LPSET} -n system -a use=${second} _default + exit_code=$? + else + echo "${second}: " 1>&2 + gettext "undefined printer\n" 1>&2 + fi + + fi + exit ${exit_code} +fi + +# Strip off legal options +while getopts "A:ac:D:e:f:F:H:hi:I:lm:Mn:o:p:Q:r:S:s:T:u:U:v:W:x:t:P:" arg +do + case $arg in + D) + description="${OPTARG}" + ;; + p) + if [ -n "${delete}" ] ; then + usage + fi + printer=${OPTARG} + ;; + s) + server=${OPTARG} + ;; + v|U) + device=${OPTARG} + server=`uname -n` + ;; + x) + if [ -n "${printer}" -o -n "${server}" -o \ + -n "${device}" -o -n "${description}" ] ; then + usage + fi + delete=${OPTARG} + printer=${OPTARG} + if [ ${printer} = "all" ] ; then + local="true" + fi + ;; + S|M|A) + local="true" + ;; + c) + class=${OPTARG} + local="true" + if [ ! -f ${LPGET} ] ; then + gettext "lpadmin: System error; cannot set class\n " 1>&2 + exit 2 + fi + + ${LPGET} "${class}" > /dev/null 2>&1 + lpget_class=$? + if [ ${lpget_class} -eq 0 -a ! -r /etc/lp/classes/"${class}" ] ; then + gettext "lpadmin: ERROR: Can't create class ${class}.\n" 1>&2 + gettext " TO FIX: This is an existing printer name;\n" 1>&2 + gettext " choose another name.\n" 1>&2 + exit 1 + fi + ;; + r) + pconflocalclean="true" + local="true" + ;; + esac +done + +# +# We don't have anything to do; let user know and bail +# +if [ ! -n "${printer}" -a ! -n "${delete}" -a ! -n "${local}" ] ; then + gettext "lpadmin: ERROR: Nothing to do.\n" 1>&2 + gettext " TO FIX: You must give one of these options:\n" 1>&2 + gettext " -p, -d, -x -S\n" 1>&2 + exit 1 +fi + +# +# Printer does not exist +# To be consistent with 2.5, assume adding local printer +# +if [ ! -n "${device}" -a ! -n "${server}" -a ! -n "${delete}" \ + -a ! -n "${local}" ] ; then + ${LPGET} "${printer}" > /dev/null 2>&1 + lpget_stat=$? + if [ ${lpget_stat} -ne 0 ] ; then + gettext "lpadmin: ERROR: Missing -U or -v option.\n" 1>&2 + gettext " TO FIX: Local printers must have\n" 1>&2 + gettext " a port defined (-v option) or\n" 1>&2 + gettext " have dial-out instructions (-U option).\n" 1>&2 + exit 1 + fi +fi + +# +# Do the LP configuration for a local printer served by lpsched +# +if [ -f /usr/lib/lp/local/$cmd_name ] ; then + if [ -f /etc/lp/printers/${printer}/configuration -o -n "${device}" -o \ + -f /etc/lp/classes/${printer} -o -n "${local}" ] ; then + # to deal with multi-word arguments + CMD="/usr/lib/lp/local/$cmd_name" + while [ -n "$*" ] ; do + CMD="$CMD \"$1\"" + shift + done + case "$CMD" in + *\"-D\") + CMD="$CMD \"\"" + ;; + esac + # if adding a printer, make sure scheduler is running + if [ -n "${printer}" -a ! -n "${delete}" -a \ + ! -p /var/spool/lp/fifos/FIFO ]; then + svcadm enable svc:/application/print/server:default + fi + eval $CMD + exit_code=$? + fi +fi + +if [ $exit_code != 0 ] ; then + exit $exit_code +fi + + +# split the "server" into printer and server +if [ -n "${server}" ] ; then + if [ `echo ${server} | grep -c !` = 1 ] ; then + rem_printer=`echo ${server} | cut -d! -f2` + fi + server=`echo ${server} | cut -d! -f1` +fi + +if [ -z "${rem_printer}" ] ; then + rem_printer=${printer} +fi + + + +# +# Do the Solstice Print Configuration in /etc +# +if [ ! -f ${LPSET} -o ! -f ${LPGET} ] ; then + exit_code=2 +else + if [ -n "${delete}" ] ; then + if [ "${delete}" = "all" ] ; then + delete_entries + else + ${LPSET} -n system -x ${delete} + exit_code=$? + delete_local + fi + fi + + if [ -n "${printer}" -a -n "${server}" ] ; then + ${LPSET} -n system \ + -a "bsdaddr=${server},${rem_printer},Solaris" \ + ${printer} + exit_code=$? + fi + if [ -n "${printer}" -a -n "${description}" ] ; then + ${LPSET} -n system -a "description=${description}" ${printer} + exit_code=$? + fi + +# Add class for local printers only + + if [ -n "${class}" -a -n "${printer}" \ + -a -f /etc/lp/printers/${printer}/configuration ] ; then + + ${LPGET} "${class}" > /dev/null 2>&1 + lpget_class=$? + +# If the class doesn't already exist in printers.conf, add it. + + if [ ${lpget_class} -ne 0 ] ; then + this_server=`uname -n` + ${LPSET} -n system \ + -a "bsdaddr=${this_server},${class},Solaris" ${class} + exit_code=$? + fi + fi +fi + +# /usr/lib/lp/local/lpadmin has changed the database. This cleans up cruft in the +# /etc/printers.conf file that refers to deleted objects. + + if [ -n "${pconflocalclean}" ] ; then + delete_local + fi + +exit $exit_code diff --git a/usr/src/cmd/print/scripts/lpsystem b/usr/src/cmd/print/scripts/lpsystem new file mode 100644 index 0000000000..ff2412666a --- /dev/null +++ b/usr/src/cmd/print/scripts/lpsystem @@ -0,0 +1,34 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 (c) 1994, 1995, 1996 by Sun Microsystems, Inc. +# All Rights Reserved +# +# ident "%Z%%M% %I% %E% SMI" +# + +cmd_name=`basename $0` + +if [ -f /usr/lib/lp/local/$cmd_name ] ; then + exec /usr/lib/lp/local/$cmd_name $* +fi diff --git a/usr/src/cmd/print/scripts/ppdfilename2mmp b/usr/src/cmd/print/scripts/ppdfilename2mmp new file mode 100644 index 0000000000..3338f1808a --- /dev/null +++ b/usr/src/cmd/print/scripts/ppdfilename2mmp @@ -0,0 +1,78 @@ +#!/usr/bin/ksh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 +# +# +# ident "%Z%%M% %I% %E% SMI" +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Get the make/model/nickname from ppdfilename +# + +if [[ $# -lt 1 ]]; then + exit 1 +fi + +if [[ -f /usr/lib/lp/model/ppd/ppdcache ]]; then + + ppdfile=`/bin/grep $1 /usr/lib/lp/model/ppd/ppdcache` + + if [[ -z "$ppdfile" ]]; then + + # Perhaps this is an old configuration file + # look for ppd file in new directories + + # Get last two fields from arg1: full path/filename of ppd + # file. Separate with /. + # arg1: /usr/lib/lp/model/ppd/<MANU>/<filename> + + manufile=`echo $1 | /bin/nawk -F/ '{ print $7 "/" $8 }` + + # search for ppd file in all the directories under system + # Use the first one found + + for dir in /usr/lib/lp/model/ppd/system/*; do + if [[ -d "$dir" ]]; then + target=$dir/$manufile + found=`/bin/grep $target /usr/lib/lp/model/ppd/ppdcache` + + if [[ -z "$ppdfile" && -n "$found" ]]; then + ppdfile=$found + fi + + + fi + done + + fi + + if [[ -z "$ppdfile" ]]; then + exit 1 + else + echo $ppdfile | + nawk '{FS=":"; print $1; print $2; print $3}' + exit 0 + fi +fi diff --git a/usr/src/cmd/print/scripts/printers.conf b/usr/src/cmd/print/scripts/printers.conf new file mode 100644 index 0000000000..69327e9915 --- /dev/null +++ b/usr/src/cmd/print/scripts/printers.conf @@ -0,0 +1,31 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (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 1996 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" + +# +# If you hand edit this file, comments and structure may change. +# The prefered method of modifying this file is though the use of +# lpset(1M) or lpadmin(1M) +# |