diff options
author | jacobs <none@none> | 2006-11-15 19:19:07 -0800 |
---|---|---|
committer | jacobs <none@none> | 2006-11-15 19:19:07 -0800 |
commit | 0a44ef6d9afbfe052a7e975f55ea0d2954b62a82 (patch) | |
tree | afca18ba6ad0fb467b29e368f05399e53a19ec4a /usr/src/cmd/print/bsd-sysv-commands | |
parent | 3383b6dda001791704e0e66f7b78dd0dfe74f547 (diff) | |
download | illumos-joyent-0a44ef6d9afbfe052a7e975f55ea0d2954b62a82.tar.gz |
4634017 Lpadmin's new printer limit needs to be increased.
4941143 lpsched leaks memory in freeprinter()
6480891 lpsched fixes unused files
6486772 in.lpd should use libpapi
6486967 print-svc refers to /usr/sbin/cut
6487898 lpadmin doesn't add remote access
6488443 printmr/lpadmin should prefer IPP support when it's available
6490445 psm-lpd has incorrect mime type in it's translation table
6490453 lpr uses the wrong default mime type
6491971 in.lpd and the ipp listener should detect cycles
6491978 libhttp-core should build when -DDEBUG is specified
6492414 lpstat -o -l should report on requested form when available
--HG--
rename : usr/src/cmd/lp/cmd/adaptor/Makefile => deleted_files/usr/src/cmd/lp/cmd/adaptor/Makefile
rename : usr/src/cmd/lp/cmd/adaptor/cancel_job.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/cancel_job.c
rename : usr/src/cmd/lp/cmd/adaptor/misc.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/misc.c
rename : usr/src/cmd/lp/cmd/adaptor/misc.h => deleted_files/usr/src/cmd/lp/cmd/adaptor/misc.h
rename : usr/src/cmd/lp/cmd/adaptor/show_queue.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/show_queue.c
rename : usr/src/cmd/lp/cmd/adaptor/submit_job.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/submit_job.c
rename : usr/src/cmd/print/gateway/Makefile => deleted_files/usr/src/cmd/print/gateway/Makefile
rename : usr/src/cmd/print/gateway/adaptor.c => deleted_files/usr/src/cmd/print/gateway/adaptor.c
rename : usr/src/cmd/print/gateway/adaptor.h => deleted_files/usr/src/cmd/print/gateway/adaptor.h
rename : usr/src/cmd/print/gateway/cleanup.xml => deleted_files/usr/src/cmd/print/gateway/cleanup.xml
rename : usr/src/cmd/print/gateway/main.c => deleted_files/usr/src/cmd/print/gateway/main.c
rename : usr/src/cmd/print/gateway/print-cleanup => deleted_files/usr/src/cmd/print/gateway/print-cleanup
rename : usr/src/cmd/print/gateway/printd.c => deleted_files/usr/src/cmd/print/gateway/printd.c
rename : usr/src/cmd/print/gateway/translators/Makefile => deleted_files/usr/src/cmd/print/gateway/translators/Makefile
rename : usr/src/cmd/print/gateway/translators/cascade/Makefile => deleted_files/usr/src/cmd/print/gateway/translators/cascade/Makefile
rename : usr/src/cmd/print/gateway/translators/cascade/cascade.c => deleted_files/usr/src/cmd/print/gateway/translators/cascade/cascade.c
rename : usr/src/cmd/print/gateway/translators/test/Makefile => deleted_files/usr/src/cmd/print/gateway/translators/test/Makefile
rename : usr/src/cmd/print/gateway/translators/test/README => deleted_files/usr/src/cmd/print/gateway/translators/test/README
rename : usr/src/cmd/print/gateway/translators/test/test.c => deleted_files/usr/src/cmd/print/gateway/translators/test/test.c
rename : usr/src/cmd/print/gateway/rfc1179.xml => usr/src/cmd/print/bsd-sysv-commands/rfc1179.xml
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands')
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/Makefile | 20 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/common.c | 75 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/common.h | 2 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/in.lpd.c | 635 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/lp.c | 52 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/lpr.c | 9 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/lpstat.c | 6 | ||||
-rw-r--r-- | usr/src/cmd/print/bsd-sysv-commands/rfc1179.xml | 99 |
8 files changed, 807 insertions, 91 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/Makefile b/usr/src/cmd/print/bsd-sysv-commands/Makefile index ee16f07879..6599510e04 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/Makefile +++ b/usr/src/cmd/print/bsd-sysv-commands/Makefile @@ -25,16 +25,20 @@ # ident "%Z%%M% %I% %E% SMI" # +include ../Makefile.sp + UCBPROGS = lpr lpq lprm lpc BINPROGS = lp lpstat cancel enable disable $(UCBPROGS) SBINPROGS = accept reject lpmove +LIBPRINTPROGS = in.lpd -OBJS = $(BINPROGS:=.o) $(SBINPROGS:=.o) common.o +OBJS = $(BINPROGS:=.o) $(SBINPROGS:=.o) $(LIBPRINTPROGS:=.o) common.o ROOTBINPROGS = $(BINPROGS:%=$(ROOTBIN)/%) ROOTUSRSBINPROGS = $(SBINPROGS:%=$(ROOTUSRSBIN)/%) +ROOTLIBPRINTPROGS = $(LIBPRINTPROGS:%=$(ROOTLIBPRINT)/%) FILEMODE = 0555 @@ -42,13 +46,20 @@ OWNER = root include ../../Makefile.cmd +MANIFEST= rfc1179.xml +ROOTMANIFESTDIR= $(ROOTSVCAPPLICATIONPRINT) +$(ROOTMANIFEST) := FILEMODE= 444 + CFLAGS += $(CCVERBOSE) CPPFLAGS += -I. CPPFLAGS += -I../../../lib/print/libpapi-common/common +CPPFLAGS += -I$(ROOT)/usr/include LDLIBS += -lpapi -lc +in.lpd:= CFLAGS += -DSOLARIS_PRIVATE_POST_0_9 +in.lpd:= LDLIBS += -lnsl -lsocket # each program needs common.o as well -$(BINPROGS) $(SBINPROGS): $(BINPROGS:%=%.c) $(SBINPROGS:%=%.c) common.o +$(BINPROGS) $(SBINPROGS) $(LIBPRINTPROGS): $(BINPROGS:%=%.c) $(SBINPROGS:%=%.c) $(LIBPRINTPROGS:%=%.c) common.o $(LINK.c) -o $@ $@.c common.o $(LDLIBS) $(POST_PROCESS) @@ -72,12 +83,15 @@ $(ROOTUSRLIBSYMLINKS): all: $(BINPROGS) $(SBINPROGS) install: $(BINPROGS) $(SBINPROGS) $(ROOTBINPROGS) $(ROOTUSRSBINPROGS) \ + $(ROOTLIBPRINT) $(ROOTLIBPRINTPROGS) $(ROOTMANIFEST) \ $(ROOTUCBSYMLINKS) $(ROOTUSRLIBSYMLINKS) +check: $(CHKMANIFEST) + clean: $(RM) $(OBJS) -CLOBBERFILES += $(BINPROGS) $(SBINPROGS) +CLOBBERFILES += $(BINPROGS) $(SBINPROGS) $(LIBPRINTPROGS) lint: diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.c b/usr/src/cmd/print/bsd-sysv-commands/common.c index 5d70752563..73483957ff 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/common.c +++ b/usr/src/cmd/print/bsd-sysv-commands/common.c @@ -32,6 +32,9 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include <alloca.h> #include <string.h> #include <libintl.h> @@ -74,6 +77,41 @@ match_job(int id, char *user, int ac, char *av[]) return (-1); } +static struct { + char *mime_type; + char *lp_type; +} type_map[] = { + { "text/plain", "simple" }, + { "application/octet-stream", "raw" }, + { "application/octet-stream", "any" }, + { "application/postscript", "postscript" }, + { "application/postscript", "ps" }, + { "application/x-cif", "cif" }, + { "application/x-dvi", "dvi" }, + { "application/x-plot", "plot" }, + { "application/x-ditroff", "troff" }, + { "application/x-troff", "otroff" }, + { "application/x-pr", "pr" }, + { "application/x-fortran", "fortran" }, + { "application/x-raster", "raster" }, + { NULL, NULL} +}; + +char * +lp_type_to_mime_type(char *lp_type) +{ + int i; + + if (lp_type == NULL) + return ("application/octet-stream"); + + for (i = 0; type_map[i].lp_type != NULL; i++) + if (strcasecmp(type_map[i].lp_type, lp_type) == 0) + return (type_map[i].mime_type); + + return (lp_type); +} + /* * to support job/printer status */ @@ -157,6 +195,8 @@ print_job_line(FILE *fp, int count, papi_job_t job, int fmt, int ac, char *av[]) "job-id", &id); (void) papiAttributeListGetString(list, NULL, "job-originating-user-name", &user); + (void) papiAttributeListGetString(list, NULL, + "job-originating-host-name", &host); /* if we are looking and it doesn't match, return early */ if ((ac > 0) && (match_job(id, user, ac, av) < 0)) @@ -226,9 +266,9 @@ berkeley_queue_report(papi_service_t svc, FILE *fp, char *dest, int fmt, papi_job_t *jobs = NULL; char *pattrs[] = { "printer-name", "printer-state", "printer-state-reasons", NULL }; - char *jattrs[] = { - "job-name", "job-octets", "job-k-octets", - "job-originating-user-name", "job-id", + char *jattrs[] = { "job-name", "job-octets", "job-k-octets", "job-id", + "job-originating-user-name", + "job-originating-host-name", "number-of-intervening-jobs", NULL }; int num_jobs = 0; @@ -371,6 +411,35 @@ jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list, return (status); } +/* + * is_postscript() will detect if the file passed in contains postscript + * data. A one is returned if the file contains postscript, zero is returned + * if the file is not postscript, and -1 is returned if an error occurs + */ +#define PS_MAGIC "%!" +#define PC_PS_MAGIC "^D%!" +int +is_postscript(const char *file) +{ + char buf[3]; + int fd; + + if ((fd = open(file, O_RDONLY)) < 0) + return (-1); + + if (read(fd, buf, sizeof (buf)) < 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)) + return (1); + else + return (0); +} + 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 92a2b5b66c..e8169ed0da 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/common.h +++ b/usr/src/cmd/print/bsd-sysv-commands/common.h @@ -56,6 +56,8 @@ extern papi_status_t jobSubmitSTDIN(papi_service_t svc, char *printer, 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 cli_auth_callback(papi_service_t svc, void *app_data); diff --git a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c index 465189daf1..18487c51d8 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c +++ b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c @@ -31,13 +31,25 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> #include <stdarg.h> #include <string.h> #include <errno.h> #include <syslog.h> #include <libintl.h> +#include <pwd.h> +#include <grp.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <sys/systeminfo.h> #include <papi.h> +#include <uri.h> #include "common.h" #define ACK(fp) { (void) fputc('\0', fp); (void) fflush(fp); } @@ -48,7 +60,61 @@ * code assumes a BSD Socket interface to the networking side. */ -void +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; + + /* who is our peer ? */ + if (getpeername(fd, (struct sockaddr *)&peer, &peer_len) < 0) { + if ((errno != ENOTSOCK) && (errno != EINVAL)) + return (NULL); + else + return (strdup("localhost")); + } + + /* 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("localhost")); + + /* duplicate the name because gethostbyXXXX() is not reentrant */ + hostname = strdup(hp->h_name); + (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname)); + + /* 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("localhost")); + } + } + } + + /* It must be someone else */ + return (hostname); +} + +static void fatal(FILE *fp, char *fmt, ...) { va_list ap; @@ -57,62 +123,440 @@ fatal(FILE *fp, char *fmt, ...) vsyslog(LOG_DEBUG, fmt, ap); vfprintf(fp, fmt, ap); va_end(ap); + exit(1); } static void -cleanup(char **files) +cleanup(char ***files, char **cf) { - if (files != NULL) { + if (*files != NULL) { int i; - for (i = 0; files[i] != NULL; i++) - unlink(files[i]); + for (i = 0; (*files)[i] != NULL; i++) { + (void) unlink((*files)[i]); + free((*files)[i]); + } + free(*files); + *files = NULL; + } + + if (*cf != NULL) { + free(*cf); + *cf = NULL; } } -static void -berkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp) +static papi_attribute_t ** +parse_cf(papi_service_t svc, char *cf, char **files) { - char line[BUFSIZ]; - char **files = NULL; /* the job data files */ + papi_attribute_t **list = NULL; + char previous = NULL, + *entry, + *s, + text[BUFSIZ]; + int count = 0, + copies_set = 0, + copies = 0; + + for (entry = strtok(cf, "\n"); entry != NULL; + entry = strtok(NULL, "\n")) { + char *format = NULL; + + /* count the copies */ + if ((entry[0] >= 'a') && (entry[0] <= 'z') && + (copies_set == 0) && (previous == entry[0])) + copies++; + else if ((previous >= 'a') && (previous <= 'z')) + copies_set = 1; + previous = entry[0]; + + /* process the control message */ + switch (entry[0]) { + /* RFC-1179 options */ + case 'J': /* RFC-1179 Banner Job Name */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-name", ++entry); + break; + case 'C': /* RFC-1179 Banner Class Name */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-class", ++entry); + break; + case 'L': /* RFC-1179 Banner toggle */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-sheets", "standard"); + break; + case 'T': /* RFC-1179 Title (pr) */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "pr-title", ++entry); + break; + case 'H': /* RFC-1179 Host */ + /* + * use the host as known by us, not by them + * + * papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + * "job-originating-host-name", ++entry); + */ + break; + case 'P': /* RFC-1179 User */ + ++entry; + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "requesting-user-name", entry); + papiServiceSetUserName(svc, entry); + break; + case 'M': /* RFC-1179 Mail to User */ + papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, + "rfc-1179-mail", 1); + break; + case 'W': /* RFC-1179 Width (pr) */ + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "pr-width", atoi(++entry)); + break; + case 'I': /* RFC-1179 Indent (pr) */ + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "pr-indent", atoi(++entry)); + break; + case 'N': /* RFC-1179 Filename */ + /* could have HPUX extension embedded */ + if (entry[1] != ' ') { /* real pathname */ +#ifdef DEBUG + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "flist", ++entry); +#endif + } else if (entry[2] == 'O') /* HPUX lp -o options */ + papiAttributeListFromString(&list, + PAPI_ATTR_APPEND, ++entry); + break; + case 'U': /* RFC-1179 Unlink */ + break; /* ignored */ + case '1': /* RFC-1179 TROFF Font R */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-r", ++entry); + break; + case '2': /* RFC-1179 TROFF Font I */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-i", ++entry); + break; + case '3': /* RFC-1179 TROFF Font B */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-b", ++entry); + break; + case '4': /* RFC-1179 TROFF Font S */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-s", ++entry); + break; + case 'f': /* RFC-1179 ASCII file (print) */ + format = "text/plain"; + if (is_postscript(files[0]) == 1) + format = "application/postscript"; + break; + case 'l': /* RFC-1179 CATV file (print) */ + format = "application/octet-stream"; + if (is_postscript(files[0]) == 1) + format = "application/postscript"; + break; + case 'o': /* RFC-1179 Postscript file (print) */ + format = "application/postscript"; + break; + case 'p': /* RFC-1179 PR file (print) */ + format = "application/x-pr"; + papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, + "pr-filter", 1); + break; + case 't': /* RFC-1179 TROFF file (print) */ + format = "application/x-troff"; + break; + case 'n': /* RFC-1179 DITROFF file (print) */ + format = "application/x-ditroff"; + break; + case 'd': /* RFC-1179 DVI file (print) */ + format = "application/x-dvi"; + break; + case 'g': /* RFC-1179 GRAPH file (print) */ + format = "application/x-plot"; + break; + case 'c': /* RFC-1179 CIF file (print) */ + format = "application/x-cif"; + break; + case 'v': /* RFC-1179 RASTER file (print) */ + format = "application/x-raster"; + break; + case 'r': /* RFC-1179 FORTRAN file (print) */ + format = "application/x-fortran"; + break; + /* Sun Solaris Extensions */ + case 'O': + ++entry; + do { + if (*entry != '"') + text[count++] = *entry; + } while (*entry++); + papiAttributeListFromString(&list, PAPI_ATTR_APPEND, + text); + break; + case '5': + ++entry; + switch (entry[0]) { + case 'f': /* Solaris form */ + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "form", ++entry); + break; + case 'H': /* Solaris handling */ + ++entry; + if (strcasecmp(entry, "hold") == 0) + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "job-hold-until", "indefinite"); + else if (strcasecmp(entry, "release") == 0) + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "job-hold-until", "no-hold"); + else if (strcasecmp(entry, "immediate") == 0) + papiAttributeListAddInteger(&list, + PAPI_ATTR_EXCL, + "job-priority", 100); + else + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "job-hold-until", entry); + break; + case 'p': /* Solaris notification */ + papiAttributeListAddBoolean(&list, + PAPI_ATTR_EXCL, "rfc-1179-mail", 1); + break; + case 'P': /* Solaris page list */ + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "page-ranges", ++entry); + break; + case 'q': { /* Solaris priority */ + int i = atoi(optarg); + + i = 99 * (39 - i) / 39 + 1; + if ((i < 1) || (i > 100)) + i = 50; + papiAttributeListAddInteger(&list, + PAPI_ATTR_EXCL, "priority", i); + } + break; + case 'S': /* Solaris character set */ + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, "lp-charset", + ++entry); + break; + case 'T': /* Solaris type */ + format = lp_type_to_mime_type(++entry); + break; + case 'y': /* Solaris mode */ + papiAttributeListAddString(&list, + PAPI_ATTR_APPEND, "lp-modes", ++entry); + break; + default: + syslog(LOG_INFO|LOG_DEBUG, + "Warning: cf message (%s) ignored", + entry); + break; + } + break; + /* Undefined Extensions: SCO, Ultrix, AIX, ... */ + + default: + syslog(LOG_INFO|LOG_DEBUG, + "Warning: cf message (%s) ignored", entry); + break; + } + + if (format != NULL) + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "document-format", format); + } - /* This should actually implement transfer job from RFC-1179 */ + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "copies", ++copies); + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-sheets", "none"); + + return (list); +} + +static papi_status_t +submit_job(papi_service_t svc, FILE *ifp, char *printer, char *cf, char **files) +{ + papi_attribute_t **list = NULL; + papi_status_t status; + papi_job_t job = NULL; + char *format = ""; + + if ((list = parse_cf(svc, cf, files)) != NULL) { + /* use the host as known by us, not by them */ + char *host = remote_host_name(ifp); + + if (host != NULL) { + papiAttributeListAddString(&list, PAPI_ATTR_REPLACE, + "job-originating-host-name", host); + free(host); + } + } + + status = papiJobSubmit(svc, printer, list, NULL, files, &job); + syslog(LOG_DEBUG, "submit: %s", papiStatusString(status)); + if (status != PAPI_OK) { + char *tmp = papiServiceGetStatusMessage(svc); + + syslog(LOG_DEBUG, "submit-detail: %s", tmp ? tmp : "none"); + } + papiJobFree(job); + + return (status); +} + +static char * +receive_control_file(papi_service_t svc, FILE *ifp, FILE *ofp, int size) +{ + char *ptr, *cf_data; + + if ((ptr = cf_data = calloc(1, size + 1)) == NULL) { + NACK(ofp); + return (NULL); + } else + ACK(ofp); + + while (size > 0) { + int rc; + + if (((rc = fread(ptr, 1, size, ifp)) == 0) && + (feof(ifp) != 0)) { + free(cf_data); + return (NULL); + } else { + ptr += rc; + size -= rc; + } + } + syslog(LOG_DEBUG, "cf_data(%s)", cf_data); + + if (fgetc(ifp) != 0) { + free(cf_data); + return (NULL); + } + ACK(ofp); + + return (cf_data); +} + +static char * +receive_data_file(FILE *ifp, FILE *ofp, int size) +{ + char file[] = "lpdXXXXXX"; + char buf[BUFSIZ]; + int fd; + + if ((fd = mkstemp(file)) < 0) { + NACK(ofp); + return (NULL); + } else + ACK(ofp); + + while (size > 0) { + int rc = ((size > BUFSIZ) ? BUFSIZ : size); + + if (((rc = fread(buf, 1, rc, ifp)) == 0) && + (feof(ifp) != 0)) { + close(fd); + unlink(file); + return (NULL); + } else { + char *ptr = buf; + + while (rc > 0) { + int wrc = write(fd, ptr, rc); + + if (wrc < 0) { + close(fd); + unlink(file); + return(NULL); + } + + ptr += wrc; + size -= wrc; + rc -= wrc; + } + } + } + close(fd); + if (fgetc(ifp) != 0) { + unlink(file); + return (NULL); + } ACK(ofp); - while (fgets(line, sizeof (line), ifp) != NULL) { - switch (line[0]) { + return (strdup(file)); +} + +static papi_status_t +berkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp, char *printer) +{ + papi_status_t status = PAPI_OK; + char *file, **files = NULL; /* the job data files */ + char *cf = NULL; + char buf[BUFSIZ]; + + while (fgets(buf, sizeof (buf), ifp) != NULL) { + int size; + + syslog(LOG_DEBUG, "XFER CMD: (%d)%s\n", buf[0], &buf[1]); +#ifdef DEBUG /* translate [1-3]... messages to \[1-3] to run by hand */ + if ((buf[0] > '0') && (buf[0] < '4')) + buf[0] -= '0'; +#endif + switch (buf[0]) { case 0x01: /* Abort */ - cleanup(files); + cleanup(&files, &cf); break; - case 0x02: /* Receive control file */ - + case 0x02: { /* Receive control file */ + cf = receive_control_file(svc, ifp, ofp, atoi(&buf[1])); + if (cf == NULL) { + cleanup(&files, &cf); + return (PAPI_BAD_REQUEST); + } else if (files != NULL) { + status = submit_job(svc, ifp, printer, cf, + files); + cleanup(&files, &cf); + } + } break; case 0x03: { /* Receive data file */ - char file[] = "lpdXXXXXX"; - int fd; - - fd = mkstemp(file); - - list_append(&files, strdup(file)); + file = receive_data_file(ifp, ofp, atoi(&buf[1])); + if (file == NULL) { + cleanup(&files, &cf); + return (PAPI_TEMPORARY_ERROR); + } + list_append(&files, file); } break; default: + cleanup(&files, &cf); fatal(ofp, "protocol screwup"); - cleanup(files); break; } } - cleanup(files); + if ((cf != NULL) && (files != NULL)) + status = submit_job(svc, ifp, printer, cf, files); + + cleanup(&files, &cf); + + return (status); } -static void +static papi_status_t berkeley_transfer_files(papi_service_t svc, FILE *ifp, FILE *ofp, char *printer) { papi_status_t status; papi_printer_t p = NULL; - char *keys[] = { "printer-is-accepting", NULL }; + char *keys[] = { "printer-is-accepting-jobs", NULL }; status = papiPrinterQuery(svc, printer, keys, NULL, &p); if ((status == PAPI_OK) && (p != NULL)) { @@ -120,18 +564,68 @@ berkeley_transfer_files(papi_service_t svc, FILE *ifp, FILE *ofp, char accepting = PAPI_FALSE; papiAttributeListGetBoolean(attrs, NULL, - "printer-is-accepting", &accepting); + "printer-is-accepting-jobs", &accepting); - if (accepting == PAPI_TRUE) - berkeley_receive_files(svc, ifp, ofp); - else + if (accepting == PAPI_TRUE) { + ACK(ofp); + status = berkeley_receive_files(svc, ifp, ofp, printer); + } else NACK(ofp); papiPrinterFree(p); } else NACK(ofp); + + return (status); +} + +static int +cyclical_service_check(char *svc_name) +{ + papi_attribute_t **list; + char buf[BUFSIZ]; + uri_t *uri = NULL; + char *s = NULL; + + /* was there a printer? */ + if (svc_name == NULL) + return (0); + + if ((list = getprinterbyname(svc_name, NULL)) == NULL) + return (0); /* if it doesnt' resolve, we will fail later */ + + papiAttributeListGetString(list, NULL, "printer-uri-supported", &s); + if ((s == NULL) || (strcasecmp(svc_name, s) != 0)) + return (0); /* they don't match */ + + /* is it in uri form? */ + if (uri_from_string(s, &uri) < 0) + return (0); + + if ((uri == NULL) || (uri->scheme == NULL) || (uri->host == NULL)) { + uri_free(uri); + return (0); + } + + /* is it in lpd form? */ + if (strcasecmp(uri->scheme, "lpd") != 0) { + uri_free(uri); + return (0); + } + + /* is it the local host? */ + sysinfo(SI_HOSTNAME, buf, sizeof (buf)); + if ((strcasecmp(uri->host, "localhost") != 0) && + (strcasecmp(uri->host, buf) != 0)) { + uri_free(uri); + return (0); + } + + uri_free(uri); + return (1); } + /* * This is the entry point for this program. The program takes the * following options: @@ -148,20 +642,54 @@ main(int ac, char *av[]) int c; char buf[BUFSIZ], **args, - *printer; + *printer, + *run_dir = "/var/run/in.lpd", + *run_user = NULL; + struct passwd *pw = NULL; + (void) chdir("/tmp"); /* run in /tmp by default */ openlog("bsd-gw", LOG_PID, LOG_LPR); - while ((c = getopt(ac, av, "d")) != EOF) + while ((c = getopt(ac, av, "Ed:u:")) != EOF) switch (c) { case 'E': encryption = PAPI_ENCRYPT_ALWAYS; break; - case 'd': + case 'd': /* run where they tell you */ + run_dir = optarg; + break; + case 'u': /* run as */ + run_user = optarg; + break; default: ; } + if (run_user != NULL) /* get the requested user info */ + pw = getpwnam(run_user); + + if (run_dir != NULL) { /* setup the run_dir */ + (void) mkdir(run_dir, 0700); + if (pw != NULL) + (void) chown(run_dir, pw->pw_uid, pw->pw_gid); + } + + if (pw != NULL) { /* run as the requested user */ + syslog(LOG_DEBUG, "name: %s, uid: %d, gid: %d", + pw->pw_name, pw->pw_uid, pw->pw_gid); + initgroups(pw->pw_name, pw->pw_gid); + setgid(pw->pw_gid); + setuid(pw->pw_uid); + } + + if (run_dir != NULL) /* move to the run_dir */ + if (chdir(run_dir) < 0) { + syslog(LOG_DEBUG, "failed to chdir(%s)", run_dir); + exit(1); + } + + syslog(LOG_DEBUG, "$CWD = %s", getwd(NULL)); + if (fgets(buf, sizeof (buf), ifp) == NULL) { if (feof(ifp) == 0) syslog(LOG_ERR, "Error reading from connection: %s", @@ -169,6 +697,13 @@ main(int ac, char *av[]) exit(1); } + syslog(LOG_DEBUG, "CMD: (%d)%s\n", buf[0], &buf[1]); + +#ifdef DEBUG /* translate [1-5]... messages to \[1-5] to run by hand */ + if ((buf[0] > '0') && (buf[0] < '6')) + buf[0] -= '0'; +#endif + if ((buf[0] < 1) || (buf[0] > 5)) { fatal(ofp, "Invalid protocol request (%d): %c%s\n", buf[0], buf[0], buf); @@ -183,6 +718,11 @@ main(int ac, char *av[]) exit(1); } + if (cyclical_service_check(printer) != 0) { + fatal(ofp, "%s is cyclical\n", printer); + exit(1); + } + status = papiServiceCreate(&svc, printer, NULL, NULL, NULL, encryption, NULL); if (status != PAPI_OK) { @@ -191,20 +731,19 @@ main(int ac, char *av[]) exit(1); } -#ifdef HAVE_IS_SYSTEM_LABELED - if (is_system_labeled()) { - int fd = fileno(ifp); - - (void) papiServiceSetPeer(svc, fd); - } -#endif + /* + * Trusted Solaris can't be trusting of intermediaries. Pass + * the socket connection to the print service to retrieve the + * sensativity label off of a multi-level port. + */ + (void) papiServiceSetPeer(svc, fileno(ifp)); switch (buf[0]) { case '\1': /* restart printer */ ACK(ofp); /* there is no equivalent */ break; case '\2': /* transfer job(s) */ - berkeley_transfer_files(svc, ifp, ofp, printer); + status = berkeley_transfer_files(svc, ifp, ofp, printer); break; case '\3': /* show queue (short) */ case '\4': { /* show queue (long) */ @@ -216,10 +755,18 @@ main(int ac, char *av[]) } break; case '\5': { /* cancel job(s) */ - char *requestor = *args++; + char *user = *args++; + char *host = remote_host_name(ifp); int count; - status = papiServiceSetUserName(svc, requestor); + if (host != NULL) { + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "%s@%s", user, host); + status = papiServiceSetUserName(svc, buf); + } else + status = papiServiceSetUserName(svc, user); + for (count = 0; args[count] != 0; count++); berkeley_cancel_request(svc, ofp, printer, count, args); @@ -234,7 +781,9 @@ main(int ac, char *av[]) syslog(LOG_DEBUG, "protocol request(%d) for %s completed: %s", buf[0], printer, papiStatusString(status)); - syslog(LOG_DEBUG, "detail: %s", verbose_papi_message(svc, status)); + if (status != PAPI_OK) + syslog(LOG_DEBUG, "detail: %s", + verbose_papi_message(svc, status)); papiServiceDestroy(svc); diff --git a/usr/src/cmd/print/bsd-sysv-commands/lp.c b/usr/src/cmd/print/bsd-sysv-commands/lp.c index 3b6631fe6a..5abe7ae7e8 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/lp.c +++ b/usr/src/cmd/print/bsd-sysv-commands/lp.c @@ -62,41 +62,6 @@ usage(char *program) exit(1); } -static struct { - char *mime_type; - char *lp_type; -} type_map[] = { - { "text/plain", "simple" }, - { "application/octet-stream", "raw" }, - { "application/octet-stream", "any" }, - { "application/postscript", "postscript" }, - { "application/postscript", "ps" }, - { "application/x-cif", "cif" }, - { "application/x-dvi", "dvi" }, - { "application/x-plot", "plot" }, - { "application/x-ditroff", "troff" }, - { "application/x-troff", "otroff" }, - { "application/x-pr", "pr" }, - { "application/x-fortran", "fortran" }, - { "application/x-raster", "raster" }, - { NULL, NULL} -}; - -static char * -lp_type_to_mime_type(char *lp_type) -{ - int i; - - if (lp_type == NULL) - return ("application/octet-stream"); - - for (i = 0; type_map[i].lp_type != NULL; i++) - if (strcasecmp(type_map[i].lp_type, lp_type) == 0) - return (type_map[i].mime_type); - - return (lp_type); -} - int main(int ac, char *av[]) { @@ -161,7 +126,7 @@ main(int ac, char *av[]) break; case 'f': /* form */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, - "media", optarg); + "form", optarg); break; case 'i': /* modify job */ if ((get_printer_id(optarg, &printer, &modify) < 0) || @@ -250,19 +215,22 @@ main(int ac, char *av[]) optind = ac; if (modify == -1) { - char *document_format = "application/octet-stream"; + char *document_format = "text/plain"; -#ifdef MAGIC_MIME if (optind != ac) { /* get the mime type of the file data */ +#ifdef MAGIC_MIME magic_t ms = NULL; if ((ms = magic_open(MAGIC_MIME)) != NULL) { document_format = magic_file(ms, av[optind]); magic_close(ms); } - } +#else + if (is_postscript(av[optind]) == 1) + document_format = "application/postscript"; #endif + } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, @@ -280,6 +248,12 @@ main(int ac, char *av[]) exit(1); } + if (dump != 0) { + printf("requesting attributes:\n"); + papiAttributeListPrint(stdout, list, "\t"); + printf("\n"); + } + if (modify != -1) status = papiJobModify(svc, printer, modify, list, &job); else if (optind == ac) /* no file list, use stdin */ diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpr.c b/usr/src/cmd/print/bsd-sysv-commands/lpr.c index 4d64ddb635..cfa66c54db 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/lpr.c +++ b/usr/src/cmd/print/bsd-sysv-commands/lpr.c @@ -75,7 +75,7 @@ main(int ac, char *av[]) int validate = 0; int remove = 0; int copy = 1; /* default is to copy the data */ - char *document_format = "application/octet-stream"; + char *document_format = "text/plain"; int c; (void) setlocale(LC_ALL, ""); @@ -210,17 +210,20 @@ main(int ac, char *av[]) if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0)) optind = ac; -#ifdef MAGIC_MIME if (optind != ac) { /* get the mime type of the file data */ +#ifdef MAGIC_MIME magic_t ms; if ((ms = magic_open(MAGIC_MIME)) != NULL) { document_format = magic_file(ms, av[optind]); magic_close(ms); } - } +#else + if (is_postscript(av[optind]) == 1) + document_format = "application/postscript"; #endif + } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c index 466025da9a..a9ce4dc054 100644 --- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c +++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c @@ -664,9 +664,15 @@ report_job(papi_job_t job, int show_rank, int verbose) printf(gettext(", complete")); if (verbose == 1) { + char *form = NULL; + (void) papiAttributeListGetString(attrs, NULL, "output-device-assigned", &destination); printf("\n\t assigned %s", destination); + + (void) papiAttributeListGetString(attrs, NULL, "form", &form); + if (form != NULL) + printf(", form %s", form); } else if (verbose > 1) { printf("\n"); papiAttributeListPrint(stdout, attrs, "\t"); diff --git a/usr/src/cmd/print/bsd-sysv-commands/rfc1179.xml b/usr/src/cmd/print/bsd-sysv-commands/rfc1179.xml new file mode 100644 index 0000000000..c9ee75e326 --- /dev/null +++ b/usr/src/cmd/print/bsd-sysv-commands/rfc1179.xml @@ -0,0 +1,99 @@ +<?xml version='1.0'?> +<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> + +<!-- + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License (the "License"). + You may not use this file except in compliance with the License. + + You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + or http://www.opensolaris.org/os/licensing. + See the License for the specific language governing permissions + and limitations under the License. + + When distributing Covered Code, include this CDDL HEADER in each + file and include the License file at usr/src/OPENSOLARIS.LICENSE. + If applicable, add the following below this CDDL HEADER, with the + fields enclosed by brackets "[]" replaced with your own identifying + information: Portions Copyright [yyyy] [name of copyright owner] + + CDDL HEADER END + + Copyright 2006 Sun Microsystems, Inc. All rights reserved. + Use is subject to license terms. + + ident "%Z%%M% %I% %E% SMI" + + 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 -u lp -d /var/run/in.lpd' + timeout_seconds='0'> + <method_context> + <method_credential user='root' group='lp' /> + </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> |