in.lpd.c revision 0a44ef6d9afbfe052a7e975f55ea0d2954b62a82
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER START
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
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 *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * or http://www.opensolaris.org/os/licensing.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * See the License for the specific language governing permissions
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * and limitations under the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
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 *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER END
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Use is subject to license terms.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $Id: in.lpd.c 170 2006-05-20 05:58:49Z njacobs $ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#pragma ident "%Z%%M% %I% %E% SMI"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdio.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdlib.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <unistd.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <fcntl.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdarg.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <string.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <errno.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <syslog.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <libintl.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <pwd.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <grp.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <sys/types.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <sys/stat.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <sys/socket.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <netinet/in.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <arpa/inet.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <netdb.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <sys/systeminfo.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <papi.h>
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#include <uri.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "common.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define ACK(fp) { (void) fputc('\0', fp); (void) fflush(fp); }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define NACK(fp) { (void) fputc('\1', fp); (void) fflush(fp); }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
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.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic char *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsremote_host_name(FILE *fp)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs struct hostent *hp;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs struct sockaddr_in6 peer;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs socklen_t peer_len = sizeof (peer);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int fd = fileno(fp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int error_num;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *hostname;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* who is our peer ? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (getpeername(fd, (struct sockaddr *)&peer, &peer_len) < 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((errno != ENOTSOCK) && (errno != EINVAL))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs else
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (strdup("localhost"));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* get their name or return a string containing their address */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((hp = getipnodebyaddr((const char *)&peer.sin6_addr,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs sizeof (struct in6_addr), AF_INET6,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs &error_num)) == NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (strdup(inet_ntop(peer.sin6_family,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs &peer.sin6_addr, tmp_buf, sizeof (tmp_buf))));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it "localhost" ? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (strcasecmp(hp->h_name, "localhost") == 0)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (strdup("localhost"));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* duplicate the name because gethostbyXXXX() is not reentrant */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs hostname = strdup(hp->h_name);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it from one of my addresses ? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs &error_num)) != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int i = 0;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (tmp[i] != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (memcmp(tmp[i++], &peer.sin6_addr, hp->h_length)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs == 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free(hostname);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (strdup("localhost"));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* It must be someone else */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (hostname);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs}
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic void
355b4669e025ff377602b6fc7caaf30dbc218371jacobsfatal(FILE *fp, char *fmt, ...)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs va_list ap;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs va_start(ap, fmt);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs vsyslog(LOG_DEBUG, fmt, ap);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs vfprintf(fp, fmt, ap);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs va_end(ap);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs exit(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobscleanup(char ***files, char **cf)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (*files != NULL) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int i;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs for (i = 0; (*files)[i] != NULL; i++) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) unlink((*files)[i]);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free((*files)[i]);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free(*files);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *files = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (*cf != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free(*cf);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *cf = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic papi_attribute_t **
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsparse_cf(papi_service_t svc, char *cf, char **files)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papi_attribute_t **list = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char previous = NULL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *entry,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *s,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs text[BUFSIZ];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int count = 0,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs copies_set = 0,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs copies = 0;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs for (entry = strtok(cf, "\n"); entry != NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs entry = strtok(NULL, "\n")) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *format = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* count the copies */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((entry[0] >= 'a') && (entry[0] <= 'z') &&
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (copies_set == 0) && (previous == entry[0]))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs copies++;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs else if ((previous >= 'a') && (previous <= 'z'))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs copies_set = 1;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs previous = entry[0];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* process the control message */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs switch (entry[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* RFC-1179 options */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'J': /* RFC-1179 Banner Job Name */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-name", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'C': /* RFC-1179 Banner Class Name */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "rfc-1179-class", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'L': /* RFC-1179 Banner toggle */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-sheets", "standard");
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'T': /* RFC-1179 Title (pr) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "pr-title", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'H': /* RFC-1179 Host */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /*
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * use the host as known by us, not by them
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs * "job-originating-host-name", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'P': /* RFC-1179 User */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ++entry;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "requesting-user-name", entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiServiceSetUserName(svc, entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'M': /* RFC-1179 Mail to User */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "rfc-1179-mail", 1);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'W': /* RFC-1179 Width (pr) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "pr-width", atoi(++entry));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'I': /* RFC-1179 Indent (pr) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "pr-indent", atoi(++entry));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'N': /* RFC-1179 Filename */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* could have HPUX extension embedded */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (entry[1] != ' ') { /* real pathname */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#ifdef DEBUG
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "flist", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#endif
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else if (entry[2] == 'O') /* HPUX lp -o options */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListFromString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_APPEND, ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'U': /* RFC-1179 Unlink */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break; /* ignored */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case '1': /* RFC-1179 TROFF Font R */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "rfc-1179-font-r", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case '2': /* RFC-1179 TROFF Font I */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "rfc-1179-font-i", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case '3': /* RFC-1179 TROFF Font B */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "rfc-1179-font-b", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case '4': /* RFC-1179 TROFF Font S */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "rfc-1179-font-s", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'f': /* RFC-1179 ASCII file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "text/plain";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (is_postscript(files[0]) == 1)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/postscript";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'l': /* RFC-1179 CATV file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/octet-stream";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (is_postscript(files[0]) == 1)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/postscript";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'o': /* RFC-1179 Postscript file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/postscript";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'p': /* RFC-1179 PR file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-pr";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "pr-filter", 1);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 't': /* RFC-1179 TROFF file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-troff";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'n': /* RFC-1179 DITROFF file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-ditroff";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'd': /* RFC-1179 DVI file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-dvi";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'g': /* RFC-1179 GRAPH file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-plot";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'c': /* RFC-1179 CIF file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-cif";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'v': /* RFC-1179 RASTER file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-raster";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'r': /* RFC-1179 FORTRAN file (print) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = "application/x-fortran";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* Sun Solaris Extensions */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'O':
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ++entry;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs do {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (*entry != '"')
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs text[count++] = *entry;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } while (*entry++);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListFromString(&list, PAPI_ATTR_APPEND,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs text);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case '5':
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ++entry;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs switch (entry[0]) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'f': /* Solaris form */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "form", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'H': /* Solaris handling */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ++entry;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (strcasecmp(entry, "hold") == 0)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-hold-until", "indefinite");
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs else if (strcasecmp(entry, "release") == 0)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-hold-until", "no-hold");
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs else if (strcasecmp(entry, "immediate") == 0)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddInteger(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-priority", 100);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs else
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-hold-until", entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'p': /* Solaris notification */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddBoolean(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL, "rfc-1179-mail", 1);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'P': /* Solaris page list */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "page-ranges", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'q': { /* Solaris priority */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int i = atoi(optarg);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs i = 99 * (39 - i) / 39 + 1;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((i < 1) || (i > 100))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs i = 50;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddInteger(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL, "priority", i);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'S': /* Solaris character set */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_EXCL, "lp-charset",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'T': /* Solaris type */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs format = lp_type_to_mime_type(++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'y': /* Solaris mode */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs PAPI_ATTR_APPEND, "lp-modes", ++entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs default:
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_INFO|LOG_DEBUG,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "Warning: cf message (%s) ignored",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* Undefined Extensions: SCO, Ultrix, AIX, ... */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs default:
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_INFO|LOG_DEBUG,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "Warning: cf message (%s) ignored", entry);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (format != NULL)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "document-format", format);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "copies", ++copies);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-sheets", "none");
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (list);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs}
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic papi_status_t
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobssubmit_job(papi_service_t svc, FILE *ifp, char *printer, char *cf, char **files)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papi_attribute_t **list = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papi_status_t status;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papi_job_t job = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *format = "";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((list = parse_cf(svc, cf, files)) != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* use the host as known by us, not by them */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *host = remote_host_name(ifp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (host != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListAddString(&list, PAPI_ATTR_REPLACE,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "job-originating-host-name", host);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free(host);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = papiJobSubmit(svc, printer, list, NULL, files, &job);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "submit: %s", papiStatusString(status));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (status != PAPI_OK) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *tmp = papiServiceGetStatusMessage(svc);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "submit-detail: %s", tmp ? tmp : "none");
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiJobFree(job);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (status);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs}
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic char *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsreceive_control_file(papi_service_t svc, FILE *ifp, FILE *ofp, int size)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *ptr, *cf_data;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((ptr = cf_data = calloc(1, size + 1)) == NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs NACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (size > 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int rc;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (((rc = fread(ptr, 1, size, ifp)) == 0) &&
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (feof(ifp) != 0)) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free(cf_data);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ptr += rc;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs size -= rc;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "cf_data(%s)", cf_data);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (fgetc(ifp) != 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs free(cf_data);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (cf_data);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs}
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic char *
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsreceive_data_file(FILE *ifp, FILE *ofp, int size)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char file[] = "lpdXXXXXX";
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char buf[BUFSIZ];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int fd;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((fd = mkstemp(file)) < 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs NACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (size > 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int rc = ((size > BUFSIZ) ? BUFSIZ : size);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (((rc = fread(buf, 1, rc, ifp)) == 0) &&
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (feof(ifp) != 0)) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs close(fd);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs unlink(file);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *ptr = buf;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (rc > 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int wrc = write(fd, ptr, rc);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (wrc < 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs close(fd);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs unlink(file);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return(NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ptr += wrc;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs size -= wrc;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs rc -= wrc;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs close(fd);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (fgetc(ifp) != 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs unlink(file);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (NULL);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ACK(ofp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (strdup(file));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs}
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic papi_status_t
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsberkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp, char *printer)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papi_status_t status = PAPI_OK;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *file, **files = NULL; /* the job data files */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *cf = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char buf[BUFSIZ];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while (fgets(buf, sizeof (buf), ifp) != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs int size;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
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 if ((buf[0] > '0') && (buf[0] < '4'))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs buf[0] -= '0';
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#endif
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs switch (buf[0]) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case 0x01: /* Abort */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cleanup(&files, &cf);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 0x02: { /* Receive control file */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cf = receive_control_file(svc, ifp, ofp, atoi(&buf[1]));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (cf == NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cleanup(&files, &cf);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (PAPI_BAD_REQUEST);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else if (files != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = submit_job(svc, ifp, printer, cf,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs files);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cleanup(&files, &cf);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case 0x03: { /* Receive data file */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs file = receive_data_file(ifp, ofp, atoi(&buf[1]));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (file == NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cleanup(&files, &cf);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (PAPI_TEMPORARY_ERROR);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs list_append(&files, file);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs default:
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cleanup(&files, &cf);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fatal(ofp, "protocol screwup");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((cf != NULL) && (files != NULL))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = submit_job(svc, ifp, printer, cf, files);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs cleanup(&files, &cf);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (status);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic papi_status_t
355b4669e025ff377602b6fc7caaf30dbc218371jacobsberkeley_transfer_files(papi_service_t svc, FILE *ifp, FILE *ofp,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *printer)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_status_t status;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_printer_t p = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *keys[] = { "printer-is-accepting-jobs", NULL };
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiPrinterQuery(svc, printer, keys, NULL, &p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((status == PAPI_OK) && (p != NULL)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char accepting = PAPI_FALSE;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiAttributeListGetBoolean(attrs, NULL,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs "printer-is-accepting-jobs", &accepting);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (accepting == PAPI_TRUE) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = berkeley_receive_files(svc, ifp, ofp, printer);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NACK(ofp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiPrinterFree(p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NACK(ofp);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (status);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs}
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobsstatic int
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobscyclical_service_check(char *svc_name)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs{
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papi_attribute_t **list;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char buf[BUFSIZ];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs uri_t *uri = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *s = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* was there a printer? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (svc_name == NULL)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((list = getprinterbyname(svc_name, NULL)) == NULL)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0); /* if it doesnt' resolve, we will fail later */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListGetString(list, NULL, "printer-uri-supported", &s);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((s == NULL) || (strcasecmp(svc_name, s) != 0))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0); /* they don't match */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it in uri form? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (uri_from_string(s, &uri) < 0)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((uri == NULL) || (uri->scheme == NULL) || (uri->host == NULL)) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs uri_free(uri);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it in lpd form? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (strcasecmp(uri->scheme, "lpd") != 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs uri_free(uri);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it the local host? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs sysinfo(SI_HOSTNAME, buf, sizeof (buf));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((strcasecmp(uri->host, "localhost") != 0) &&
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (strcasecmp(uri->host, buf) != 0)) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs uri_free(uri);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs uri_free(uri);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * This is the entry point for this program. The program takes the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * following options:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * (none)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobsint
355b4669e025ff377602b6fc7caaf30dbc218371jacobsmain(int ac, char *av[])
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_status_t status;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_service_t svc = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs FILE *ifp = stdin,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *ofp = stdout;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int c;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char buf[BUFSIZ],
355b4669e025ff377602b6fc7caaf30dbc218371jacobs **args,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *printer,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *run_dir = "/var/run/in.lpd",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs *run_user = NULL;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs struct passwd *pw = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) chdir("/tmp"); /* run in /tmp by default */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs openlog("bsd-gw", LOG_PID, LOG_LPR);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs while ((c = getopt(ac, av, "Ed:u:")) != EOF)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (c) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case 'E':
355b4669e025ff377602b6fc7caaf30dbc218371jacobs encryption = PAPI_ENCRYPT_ALWAYS;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'd': /* run where they tell you */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs run_dir = optarg;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs case 'u': /* run as */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs run_user = optarg;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs default:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (run_user != NULL) /* get the requested user info */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs pw = getpwnam(run_user);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (run_dir != NULL) { /* setup the run_dir */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) mkdir(run_dir, 0700);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (pw != NULL)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) chown(run_dir, pw->pw_uid, pw->pw_gid);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (pw != NULL) { /* run as the requested user */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "name: %s, uid: %d, gid: %d",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs pw->pw_name, pw->pw_uid, pw->pw_gid);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs initgroups(pw->pw_name, pw->pw_gid);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs setgid(pw->pw_gid);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs setuid(pw->pw_uid);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (run_dir != NULL) /* move to the run_dir */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (chdir(run_dir) < 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "failed to chdir(%s)", run_dir);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs exit(1);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "$CWD = %s", getwd(NULL));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (fgets(buf, sizeof (buf), ifp) == NULL) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (feof(ifp) == 0)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs syslog(LOG_ERR, "Error reading from connection: %s",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs strerror(errno));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "CMD: (%d)%s\n", buf[0], &buf[1]);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#ifdef DEBUG /* translate [1-5]... messages to \[1-5] to run by hand */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((buf[0] > '0') && (buf[0] < '6'))
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs buf[0] -= '0';
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs#endif
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((buf[0] < 1) || (buf[0] > 5)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fatal(ofp, "Invalid protocol request (%d): %c%s\n",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs buf[0], buf[0], buf);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs args = strsplit(&buf[1], "\t\n ");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs printer = *args++;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (printer == NULL) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fatal(ofp, "Can't determine requested printer");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (cyclical_service_check(printer) != 0) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs fatal(ofp, "%s is cyclical\n", printer);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs exit(1);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs }
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiServiceCreate(&svc, printer, NULL, NULL, NULL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs encryption, NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fatal(ofp, "Failed to contact service for %s: %s\n", printer,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs verbose_papi_message(svc, status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs exit(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /*
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.
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) papiServiceSetPeer(svc, fileno(ifp));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (buf[0]) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case '\1': /* restart printer */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ACK(ofp); /* there is no equivalent */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case '\2': /* transfer job(s) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = berkeley_transfer_files(svc, ifp, ofp, printer);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case '\3': /* show queue (short) */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case '\4': { /* show queue (long) */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int count;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (count = 0; args[count] != 0; count++);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs berkeley_queue_report(svc, ofp, printer, buf[0], count, args);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case '\5': { /* cancel job(s) */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *user = *args++;
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char *host = remote_host_name(ifp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int count;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (host != NULL) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs char buf[BUFSIZ];
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs snprintf(buf, sizeof (buf), "%s@%s", user, host);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = papiServiceSetUserName(svc, buf);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs } else
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs status = papiServiceSetUserName(svc, user);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (count = 0; args[count] != 0; count++);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs berkeley_cancel_request(svc, ofp, printer, count, args);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs default:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fatal(ofp, "unsupported protocol request (%c), %s",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs buf[0], &buf[1]);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) fflush(ofp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs syslog(LOG_DEBUG, "protocol request(%d) for %s completed: %s",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs buf[0], printer, papiStatusString(status));
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if (status != PAPI_OK)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs syslog(LOG_DEBUG, "detail: %s",
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs verbose_papi_message(svc, status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiServiceDestroy(svc);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (0);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}