/*
* 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
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <locale.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include <syslog.h>
#include "netpr.h"
static void usage_exit();
static void pipehandler(int);
char data_file_type = 0;
/*
* null() is to be used as a signal handler that does nothing. It is used in
* place of SIG_IGN, because we want the signal to be delivered and
* interupt the current system call.
*/
static void
null(int i)
{
}
/*
* net_open() opens a tcp connection to the printer port on the host specified
* in the arguments passed in. If the connection is not made in the
* timeout (in seconds) passed in, an error it returned. If the host is
* unknown, an error is returned. If all is well, a file descriptor is
* returned to be used for future communications.
*/
int
{
void (*old_handler)();
int s,
err,
timeout);
/*
* Get the host address and port number to connect to.
*/
return (-1);
}
return (NETWORK_ERROR_HOST);
}
return (NETWORK_ERROR_SERVICE);
}
/*
* Try connecting to the server.
*
* Use 0 as lport means that rresvport_af() will bind to a port in
* the anonymous privileged port range.
*/
lport = 0;
if (s < 0)
return (NETWORK_ERROR_PORT);
(void) alarm(0);
(void) close(s);
if (errno == EADDRINUSE) {
goto retry;
}
/*
* If connecting to the local system fails, try
* again with "localhost" address instead.
*/
goto retry;
}
timo *= 2;
goto retry;
}
return (NETWORK_ERROR_UNKNOWN);
}
(void) alarm(0);
return (s);
}
int
{
extern char *optarg;
extern int optind;
int opt;
int sockfd;
int fd;
int jobstatus;
int exit_status = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* reduce privileges until needed to open reserved port */
}
}
switch (opt) {
case 'f':
data_file_type = optarg[0];
break;
case 'I': /* foo-49 */
break;
case 'U': /* awe172-126!wendyp */
break;
case 'p': /* foo */
break;
case 'd': /* server for printer */
break;
break;
case 'P':
else
usage_exit();
break;
case 't':
usage_exit();
break;
case 'c':
else
usage_exit();
break;
case 'b':
break;
case '?':
usage_exit();
}
usage_exit();
/*
* Check that there is a file
*/
usage_exit();
}
/*
* Sanity check the file
* returns filesize
*/
switch (errno) {
case EISDIR:
gettext("Netpr: %s: Not a regular file\n"),
break;
case ESRCH:
gettext("Netpr: %s: Empty file\n"),
break;
default:
gettext("Netpr: Cannot access file %s\n"),
break;
}
/*
* This file not valid, so bail
* Exit with zero so system will keep printing
*/
exit(0);
}
/*
* file looks ok, open and mmap it
*/
}
}
bsdjob = (np_bsdjob_t *)
} else {
}
/*
* Parse destination
*/
if (vendor_pr_name != NULL) {
bsdjob->np_printer);
}
} else {
DEST_SEP);
}
if (destination == NULL ||
gettext("Netpr: system error parsing destination %s\n"),
}
} else {
}
/*
* We are now ready to open a connection to the printer
* and print each of the files
*/
/* set privileges to get reserved port */
if (seteuid(0)) {
}
gettext("Netpr: Cannot open connection to <%s>\n"),
"Cannot open connection to %s: retrying",
}
} else {
}
}
/* lower privileges as we now have the reserved port */
}
/* Set SO_KEEPALIVE on socket to keep open */
}
gettext("Netpr: Error return from bsd_print <%d>\n"),
"Error return from bsd_print <%d>", jobstatus);
}
} else {
if ((jobstatus =
gettext("Netpr: Error return from tcp_print <%d>\n"),
"Error return from tcp_print <%d>", jobstatus);
}
}
return (exit_status);
}
static void
{
gettext("Usage: netpr -I request_id -p printer -d destination\n"));
gettext("\t\t-U username [ -f type ] [ -T title ] [ -P protocol ]\n"));
gettext("\t\t[-t timeout] [ -c ] [ -b ]\n"));
}
/*ARGSUSED*/
void
pipehandler(int i)
{
}