printd.c revision 355b4669e025ff377602b6fc7caaf30dbc218371
/*
* 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 2006 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 <ctype.h>
#include <fcntl.h>
#include <sys/systeminfo.h>
#include <stdarg.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include <termios.h>
#include <libintl.h>
#include <locale.h>
#include <pwd.h>
#include <grp.h>
#include <ns.h>
#include <network.h>
#include <misc.h>
#include <list.h>
#include <job.h>
static int connection_failed = 0;
/*
* This program will submit print jobs to a spooler using the BSD
* printing protcol as defined in RFC1179, plus some extension for
* support of additional lp functionality.
*/
#define SEND_RETRY -1
#define SEND_ABORT -2
/*ARGSUSED*/
static void sigpipe_handler(int i)
{
}
static int
{
int rc = -1;
}
return (rc);
}
/*
* send_job() sends a job to a remote print server.
*/
static int
{
int lockfd,
nd,
tmp,
rc = 0;
return (SEND_RETRY);
}
/* is job complete ? */
connection_failed = 0;
connection_failed = 1;
else
return ((nd == NETWORK_ERROR_UNKNOWN) ||
}
!= 0) {
"send_job failed job %d (%s@%s) check status\n",
return (SEND_RETRY);
}
/*
* attempt to become the job owner: uid, euid, gid, and
* supplementary groups while we try to send the job data.
* The real uid is changed with setreuid() separately from
* changing the effective uid so that we retain the saved
* uid to elevate privilege later. Combining these changes
* would result in a change to the saved uid also and a loss
* of the ability to elevate privilege later.
*/
(void) setuid(0);
}
break; /* there was an error, quit now */
if (p != NULL) {
/*
* lose the supplemental groups and elevate our effective
* other job owners later on.
*/
(void) seteuid(0);
}
if (rc < 0) {
return (SEND_ABORT);
/* probably trying to circumvent file security */
return (SEND_ABORT);
} else {
return (SEND_RETRY);
}
}
return (SEND_RETRY);
}
return (0);
}
/*
* xfer_daemon() attempts to start up a daemon for transfering jobs to a remote
* print server. The daemon runs if it can get the master lock, and it
* runs until there are no jobs waiting for transfer.
*/
static void
{
int i,
rc;
closelog();
closefrom(0);
(void) dup(1);
(void) setuid(0);
(void) setsid();
if (fork() != 0)
exit(0);
exit(0);
/*
* Bugid: 4133175 printd dies when data is removed or
* permissions are changed. Memory is freed twice.
* Fix: Do not process anything else in the list
* if the return code is SEND_ABORT as the memory
* has already been freed by job_destroy().
*/
tmp++)
if ((connection_failed == 0) &&
(strcmp(p,
(*tmp)->job_printer) == 0))
else
break;
tmp--;
free(s);
free(p);
}
}
/* look for more work to do before we sleep */
(void) sleep(60);
}
}
}
int
{
int numFiles = 0,
queueStdin = 0,
exit_code = 0;
char *program,
*user,
hostname[128],
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
else
program++;
/*
* Bugid: 4013980 Application changed fd 1 to a pipe that has
* no reader; we write to stdout and catch a sigpipe and exit.
* Fix: catch signal, complain to syslog, and continue.
*/
if (check_client_spool(NULL) < 0) {
gettext("couldn't validate local spool area (%s)\n"),
return (-1);
}
xfer_daemon();
exit(0);
}