in.lpd.c revision a18dc42fc967d11feba9b8be61c6727dc6c56b48
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
43b9c05035ac59f7f7a8e7827598db5a15f30ed3jacobs * Copyright 2008 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 /* 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 /* 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 switch (entry[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "Warning: cf message (%s) ignored",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* Undefined Extensions: SCO, Ultrix, AIX, ... */
36615d24946b849e48cedbbafa9adfb4a02b590cjacobssubmit_job(papi_service_t svc, FILE *ifp, char *printer, int rid, char *cf,
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]));
36615d24946b849e48cedbbafa9adfb4a02b590cjacobs status = submit_job(svc, ifp, printer, rid, cf, files);
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)
d978af5cd9e717f0cb0742b6e940c8fdd836504djacobs return (0); /* if it doesnt' resolve, we will fail later */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListGetString(list, NULL, "printer-uri-supported", &s);
d978af5cd9e717f0cb0742b6e940c8fdd836504djacobs 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);