in.lpd.c revision 0a44ef6d9afbfe052a7e975f55ea0d2954b62a82
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER START
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * The contents of this file are subject to the terms of the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Common Development and Distribution License (the "License").
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You may not use this file except in compliance with the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * See the License for the specific language governing permissions
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * and limitations under the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * When distributing Covered Code, include this CDDL HEADER in each
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * If applicable, add the following below this CDDL HEADER, with the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * fields enclosed by brackets "[]" replaced with your own identifying
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * information: Portions Copyright [yyyy] [name of copyright owner]
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER END
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Use is subject to license terms.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $Id: in.lpd.c 170 2006-05-20 05:58:49Z njacobs $ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#pragma ident "%Z%%M% %I% %E% SMI"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define ACK(fp) { (void) fputc('\0', fp); (void) fflush(fp); }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define NACK(fp) { (void) fputc('\1', fp); (void) fflush(fp); }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * This file contains the front-end of the BSD Print Protocol adaptor. This
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * code assumes a BSD Socket interface to the networking side.
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic char *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* who is our peer ? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (getpeername(fd, (struct sockaddr *)&peer, &peer_len) < 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* get their name or return a string containing their address */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((hp = getipnodebyaddr((const char *)&peer.sin6_addr,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it "localhost" ? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* duplicate the name because gethostbyXXXX() is not reentrant */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it from one of my addresses ? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* It must be someone else */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* count the copies */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* process the control message */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs switch (entry[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* RFC-1179 options */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * use the host as known by us, not by them
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * "job-originating-host-name", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* could have HPUX extension embedded */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break; /* ignored */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* Sun Solaris Extensions */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } while (*entry++);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs switch (entry[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "Warning: cf message (%s) ignored",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* Undefined Extensions: SCO, Ultrix, AIX, ... */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobssubmit_job(papi_service_t svc, FILE *ifp, char *printer, char *cf, char **files)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* use the host as known by us, not by them */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = papiJobSubmit(svc, printer, list, NULL, files, &job);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "submit: %s", papiStatusString(status));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "submit-detail: %s", tmp ? tmp : "none");
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic char *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsreceive_control_file(papi_service_t svc, FILE *ifp, FILE *ofp, int size)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (size > 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic char *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (size > 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (rc > 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsberkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp, char *printer)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "XFER CMD: (%d)%s\n", buf[0], &buf[1]);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#ifdef DEBUG /* translate [1-3]... messages to \[1-3] to run by hand */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs switch (buf[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cf = receive_control_file(svc, ifp, ofp, atoi(&buf[1]));
355b4669e025ff377602b6fc7caaf30dbc218371jacobsberkeley_transfer_files(papi_service_t svc, FILE *ifp, FILE *ofp,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *keys[] = { "printer-is-accepting-jobs", NULL };
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiPrinterQuery(svc, printer, keys, NULL, &p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(p);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = berkeley_receive_files(svc, ifp, ofp, printer);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* was there a printer? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((list = getprinterbyname(svc_name, NULL)) == NULL)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0); /* if it doesnt' resolve, we will fail later */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListGetString(list, NULL, "printer-uri-supported", &s);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0); /* they don't match */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it in uri form? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((uri == NULL) || (uri->scheme == NULL) || (uri->host == NULL)) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it in lpd form? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it the local host? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * This is the entry point for this program. The program takes the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * following options:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (c) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (run_user != NULL) /* get the requested user info */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#ifdef DEBUG /* translate [1-5]... messages to \[1-5] to run by hand */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiServiceCreate(&svc, printer, NULL, NULL, NULL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fatal(ofp, "Failed to contact service for %s: %s\n", printer,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * Trusted Solaris can't be trusting of intermediaries. Pass
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * the socket connection to the print service to retrieve the
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * sensativity label off of a multi-level port.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (buf[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = berkeley_transfer_files(svc, ifp, ofp, printer);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs berkeley_queue_report(svc, ofp, printer, buf[0], count, args);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs berkeley_cancel_request(svc, ofp, printer, count, args);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs syslog(LOG_DEBUG, "protocol request(%d) for %s completed: %s",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (0);