diff options
author | jacobs <none@none> | 2008-08-01 11:46:18 -0700 |
---|---|---|
committer | jacobs <none@none> | 2008-08-01 11:46:18 -0700 |
commit | c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d (patch) | |
tree | 6cf34a99e9a8f197738703c42e7cb1fecfce7ace /usr/src/cmd | |
parent | 93ea613c68b755e9de237ea85e45b3acc3a797d2 (diff) | |
download | illumos-joyent-c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d.tar.gz |
6591929 lp prints postscript source from standard input
6720404 libprint contains a bunch of dead code
6723892 lpstat cores with the queues created with the "-s ipp://" or "-s lpd://" options
6724379 Crash when printing use firefox 3 in papiJobStreamOpen
6727979 printing fails due memory corruption in psm-lpsched.so
6729885 many lpd-port processes let remote printing nearly hang
6731181 pmodes complains about /var/cache/cups in sfw build
6732289 print-service(1m) should know when it's launched from the desktop.
--HG--
rename : usr/src/lib/print/libprint/common/job.c => deleted_files/usr/src/lib/print/libprint/common/job.c
rename : usr/src/lib/print/libprint/common/job.h => deleted_files/usr/src/lib/print/libprint/common/job.h
rename : usr/src/lib/print/libprint/common/misc.c => deleted_files/usr/src/lib/print/libprint/common/misc.c
rename : usr/src/lib/print/libprint/common/misc.h => deleted_files/usr/src/lib/print/libprint/common/misc.h
rename : usr/src/lib/print/libprint/common/network.c => deleted_files/usr/src/lib/print/libprint/common/network.c
rename : usr/src/lib/print/libprint/common/network.h => deleted_files/usr/src/lib/print/libprint/common/network.h
Diffstat (limited to 'usr/src/cmd')
-rw-r--r-- | usr/src/cmd/lp/lib/papi/job.c | 14 | ||||
-rw-r--r-- | usr/src/cmd/lp/model/netpr/Makefile | 15 | ||||
-rw-r--r-- | usr/src/cmd/lp/model/netpr/netpr.c | 118 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/common.c | 36 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/common.h | 4 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/lp.c | 9 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/lpr.c | 8 | ||||
-rw-r--r-- | usr/src/cmd/print/lpget/lpget.c | 3 | ||||
-rw-r--r-- | usr/src/cmd/print/lpset/lpset.c | 3 | ||||
-rwxr-xr-x | usr/src/cmd/print/selector/print-service | 2 |
10 files changed, 174 insertions, 38 deletions
diff --git a/usr/src/cmd/lp/lib/papi/job.c b/usr/src/cmd/lp/lib/papi/job.c index 4ee09858ce..dd46165bde 100644 --- a/usr/src/cmd/lp/lib/papi/job.c +++ b/usr/src/cmd/lp/lib/papi/job.c @@ -118,14 +118,15 @@ papiJobGetId(papi_job_t job) static REQUEST * create_request(papi_service_t svc, char *printer, papi_attribute_t **attributes) { - static REQUEST r; + REQUEST *r; - memset(&r, 0, sizeof (r)); - r.priority = -1; - r.destination = printer_name_from_uri_id(printer, -1); - job_attributes_to_lpsched_request(svc, &r, attributes); + if ((r = calloc(1, sizeof (*r))) != NULL) { + r->priority = -1; + r->destination = printer_name_from_uri_id(printer, -1); + job_attributes_to_lpsched_request(svc, r, attributes); + } - return (&r); + return (r); } static papi_status_t @@ -756,6 +757,7 @@ papiJobStreamClose(papi_service_t handle, "job-uri", tmp); free(s->meta_data_file); } + freerequest(s->request); free(s); return (PAPI_OK); diff --git a/usr/src/cmd/lp/model/netpr/Makefile b/usr/src/cmd/lp/model/netpr/Makefile index f9c5455147..e5e1c1394d 100644 --- a/usr/src/cmd/lp/model/netpr/Makefile +++ b/usr/src/cmd/lp/model/netpr/Makefile @@ -2,9 +2,8 @@ # 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. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -22,7 +21,7 @@ # # ident "%Z%%M% %I% %E% SMI" # -# Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # cmd/lp/model/netpr @@ -35,9 +34,6 @@ include ../../Makefile.lp PURIFYOPTS = -logfile=/tmp/errs.%p PURIFY = purify $(PURIFYOPTS) -LIBNPRT = -L$(ROOT)/usr/lib -lprint $(LIBINTL) - - CPPFLAGS = -I. -I$(LPINC) \ $(CPPFLAGS.master) @@ -67,8 +63,7 @@ LPLIBS = \ $(LIBOAM) \ $(LIBLP) \ $(LIBSEC) \ - $(LIBSYS) \ - $(LIBNPRT) + $(LIBSYS) SYSLIBS= -lnsl -lsocket @@ -116,7 +111,7 @@ strip: cstyle: cstyle $(SRCS) -LINTFLAGS += -L ../../../../lib/print -lprint -lnsl -lsocket +LINTFLAGS += -lnsl -lsocket lint: $(LINT.c) $(SRCS) $(LDLIBS) diff --git a/usr/src/cmd/lp/model/netpr/netpr.c b/usr/src/cmd/lp/model/netpr/netpr.c index ee2614b8f6..bdce543aa5 100644 --- a/usr/src/cmd/lp/model/netpr/netpr.c +++ b/usr/src/cmd/lp/model/netpr/netpr.c @@ -2,9 +2,8 @@ * 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. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,15 +35,126 @@ #include <unistd.h> #include <sys/mman.h> #include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> #include <fcntl.h> #include <syslog.h> +#include <sys/utsname.h> #include "netpr.h" + static void usage_exit(); static void pipehandler(int); char data_file_type = 0; +/* + * null() is to be used as a signal handler that does nothing. It is used in + * place of SIG_IGN, because we want the signal to be delivered and + * interupt the current system call. + */ +static void +null(int i) +{ + syslog(LOG_DEBUG, "null(%d)", i); +} + +/* + * net_open() opens a tcp connection to the printer port on the host specified + * in the arguments passed in. If the connection is not made in the + * timeout (in seconds) passed in, an error it returned. If the host is + * unknown, an error is returned. If all is well, a file descriptor is + * returned to be used for future communications. + */ +int +net_open(char *host, int timeout) +{ + struct hostent *hp; + struct servent *sp; + struct sockaddr_in6 sin; + void (*old_handler)(); + static struct utsname uts; + + int s, + lport, + err, + error_num; + unsigned timo = 1; + + syslog(LOG_DEBUG, "net_open(%s, %d)", (host != NULL ? host : "NULL"), + timeout); + /* + * Get the host address and port number to connect to. + */ + if (host == NULL) { + return (-1); + } + + (void) memset((char *)&sin, NULL, sizeof (sin)); + if ((hp = getipnodebyname(host, AF_INET6, AI_DEFAULT, + &error_num)) == NULL) { + syslog(LOG_DEBUG|LOG_ERR, "unknown host %s " + "getipnodebyname() returned %d", host, error_num); + return (NETWORK_ERROR_HOST); + } + (void) memcpy((caddr_t)&sin.sin6_addr, hp->h_addr, hp->h_length); + sin.sin6_family = hp->h_addrtype; + freehostent(hp); + + if ((sp = getservbyname("printer", "tcp")) == NULL) { + syslog(LOG_DEBUG|LOG_ERR, "printer/tcp: unknown service"); + return (NETWORK_ERROR_SERVICE); + } + sin.sin6_port = sp->s_port; + +retry: + /* + * Try connecting to the server. + * + * Use 0 as lport means that rresvport_af() will bind to a port in + * the anonymous privileged port range. + */ + lport = 0; + s = rresvport_af(&lport, AF_INET6); + if (s < 0) + return (NETWORK_ERROR_PORT); + + old_handler = signal(SIGALRM, null); + (void) alarm(timeout); + if (connect(s, (struct sockaddr *)&sin, sizeof (sin)) < 0) { + (void) alarm(0); + (void) signal(SIGALRM, old_handler); + err = errno; + (void) close(s); + errno = err; + if (errno == EADDRINUSE) { + goto retry; + } + /* + * If connecting to the local system fails, try + * again with "localhost" address instead. + */ + if (uts.nodename[0] == '\0') + (void) uname(&uts); + if (strcmp(host, uts.nodename) == 0) { + IN6_IPADDR_TO_V4MAPPED(htonl(INADDR_LOOPBACK), + &sin.sin6_addr); + sin.sin6_family = AF_INET6; + goto retry; + } + if (errno == ECONNREFUSED && timo <= 16) { + (void) sleep(timo); + timo *= 2; + goto retry; + } + return (NETWORK_ERROR_UNKNOWN); + } + (void) alarm(0); + (void) signal(SIGALRM, old_handler); + return (s); +} + int main(int argc, char *argv[]) { diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.c b/usr/src/cmd/print/bsd-sysv-commands/common.c index fbc68459f8..92a629f776 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/common.c +++ b/usr/src/cmd/print/bsd-sysv-commands/common.c @@ -400,8 +400,8 @@ strsplit(char *string, const char *seperators) } papi_status_t -jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list, - papi_job_t *job) +jobSubmitSTDIN(papi_service_t svc, char *printer, char *prefetch, int len, + papi_attribute_t **list, papi_job_t *job) { papi_status_t status; papi_stream_t stream = NULL; @@ -409,6 +409,10 @@ jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list, char buf[BUFSIZ]; status = papiJobStreamOpen(svc, printer, list, NULL, &stream); + + if (len > 0) + status = papiJobStreamWrite(svc, stream, prefetch, len); + while ((status == PAPI_OK) && ((rc = read(0, buf, sizeof (buf))) > 0)) status = papiJobStreamWrite(svc, stream, buf, rc); @@ -426,19 +430,12 @@ jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list, #define PS_MAGIC "%!" #define PC_PS_MAGIC "^D%!" int -is_postscript(const char *file) +is_postscript_stream(int fd, char *buf, int *len) { - char buf[3]; - int fd; - - if ((fd = open(file, O_RDONLY)) < 0) - return (-1); - - if (read(fd, buf, sizeof (buf)) < 0) { + if ((*len = read(fd, buf, *len)) < 0) { close(fd); return (-1); } - close(fd); if ((strncmp(buf, PS_MAGIC, sizeof (PS_MAGIC) - 1) == 0) || (strncmp(buf, PC_PS_MAGIC, sizeof (PC_PS_MAGIC) - 1) == 0)) @@ -447,6 +444,23 @@ is_postscript(const char *file) return (0); } +int +is_postscript(const char *file) +{ + int rc = -1; + int fd; + + if ((fd = open(file, O_RDONLY)) >= 0) { + char buf[3]; + int len = sizeof (buf); + + rc = is_postscript_stream(fd, buf, &len); + close(fd); + } + + return (rc); +} + static char ** all_list(papi_service_t svc) { diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.h b/usr/src/cmd/print/bsd-sysv-commands/common.h index e8169ed0da..4a74be0abf 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/common.h +++ b/usr/src/cmd/print/bsd-sysv-commands/common.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ @@ -52,12 +52,14 @@ extern int berkeley_queue_report(papi_service_t svc, FILE *fp, char *dest, int fmt, int ac, char *av[]); extern papi_status_t jobSubmitSTDIN(papi_service_t svc, char *printer, + char *prefetch, int len, papi_attribute_t **list, papi_job_t *job); extern char **interest_list(papi_service_t svc); extern char *localhostname(); extern char *lp_type_to_mime_type(char *lp_type); extern int is_postscript(const char *file); +extern int is_postscript_stream(int fd, char *buf, int *len); extern int cli_auth_callback(papi_service_t svc, void *app_data); diff --git a/usr/src/cmd/print/bsd-sysv-commands/lp.c b/usr/src/cmd/print/bsd-sysv-commands/lp.c index aeec532e54..c7f6b1d4a9 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/lp.c +++ b/usr/src/cmd/print/bsd-sysv-commands/lp.c @@ -70,6 +70,8 @@ main(int ac, char *av[]) papi_attribute_t **list = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; papi_job_t job = NULL; + char prefetch[3]; + int prefetch_len = sizeof (prefetch); char *printer = NULL; char b = PAPI_TRUE; int copy = 0; @@ -230,6 +232,10 @@ main(int ac, char *av[]) if (is_postscript(av[optind]) == 1) document_format = "application/postscript"; #endif + } else { + if (is_postscript_stream(0, prefetch, &prefetch_len) + == 1) + document_format = "application/postscript"; } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); @@ -257,7 +263,8 @@ main(int ac, char *av[]) if (modify != -1) status = papiJobModify(svc, printer, modify, list, &job); else if (optind == ac) /* no file list, use stdin */ - status = jobSubmitSTDIN(svc, printer, list, &job); + status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len, + list, &job); else if (validate == 1) /* validate the request can be processed */ status = papiJobValidate(svc, printer, list, NULL, &av[optind], &job); diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpr.c b/usr/src/cmd/print/bsd-sysv-commands/lpr.c index fe6c24a8bc..547e0df36f 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/lpr.c +++ b/usr/src/cmd/print/bsd-sysv-commands/lpr.c @@ -70,6 +70,8 @@ main(int ac, char *av[]) papi_job_t job = NULL; int exit_code = 0; char *printer = NULL; + char prefetch[3]; + int prefetch_len = sizeof (prefetch); papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; int dump = 0; int validate = 0; @@ -217,6 +219,9 @@ main(int ac, char *av[]) if (is_postscript(av[optind]) == 1) document_format = "application/postscript"; #endif + } else { + if (is_postscript_stream(0, prefetch, &prefetch_len) == 1) + document_format = "application/postscript"; } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); @@ -238,7 +243,8 @@ main(int ac, char *av[]) status = papiJobValidate(svc, printer, list, NULL, &av[optind], &job); else if (optind == ac) /* no file list, use stdin */ - status = jobSubmitSTDIN(svc, printer, list, &job); + status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len, + list, &job); else if (copy == 0) /* reference the files in the job, default */ status = papiJobSubmitByReference(svc, printer, list, NULL, &av[optind], &job); diff --git a/usr/src/cmd/print/lpget/lpget.c b/usr/src/cmd/print/lpget/lpget.c index 9e6b0e3f00..5c19480ae1 100644 --- a/usr/src/cmd/print/lpget/lpget.c +++ b/usr/src/cmd/print/lpget/lpget.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -38,7 +38,6 @@ #endif #include <ns.h> -#include <misc.h> #include <list.h> extern char *optarg; diff --git a/usr/src/cmd/print/lpset/lpset.c b/usr/src/cmd/print/lpset/lpset.c index 308c82cd58..d0a765caea 100644 --- a/usr/src/cmd/print/lpset/lpset.c +++ b/usr/src/cmd/print/lpset/lpset.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -41,7 +41,6 @@ #include <pwd.h> #include <ns.h> -#include <misc.h> #include <list.h> extern char *optarg; diff --git a/usr/src/cmd/print/selector/print-service b/usr/src/cmd/print/selector/print-service index f78a4d89dd..9fd672f565 100755 --- a/usr/src/cmd/print/selector/print-service +++ b/usr/src/cmd/print/selector/print-service @@ -64,6 +64,8 @@ my $SVC_CUPS_SCHEDULER = 'cups/scheduler'; my $SVC_CUPS_LPD = 'cups/in-lpd'; sub fatal { + ($ENV{"DESKTOP_LAUNCHED"}) && + exec("/bin/zenity", "--error", "--text=@_"); print STDERR @_; exit(1); } |