/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* SVr4.0 1.11.1.10 */
/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
#include "lpsched.h"
#include "validate.h"
#include <syslog.h>
#include <errno.h>
#include <deflt.h>
#include <auth_list.h>
#define register auto
unsigned long chkprinter_result = 0;
char * o_cpi = 0;
char * o_lpi = 0;
char * o_width = 0;
char * o_length = 0;
static int wants_nobanner = 0;
static int wants_nolabels = 0;
static int lp_or_root = 0;
static void free_candidate ( CANDIDATE * );
static int tsol_check_printer_label_range(char *, const char *);
static int tsol_lpauth(char *, char *);
static int secpolicy_chkpolicy(char *policyp);
/**
** _validate() - FIND A PRINTER TO HANDLE A REQUEST
**/
short
int moving)
{
*pcend,
*best_pc = 0;
size_t n;
int i;
short ret;
chkprinter_result = 0;
wants_nobanner = 0;
wants_nolabels = 0;
/*
* If the system is labeled, the printing of postscript files
* is restricted. All users can print postscript files if the
* (this is checked by secpolicy_chkpolicy). Otherwise the
* user must have PRINT_POSTSCRIPT_AUTH to print postscript files.
*/
if ((is_system_labeled() &&
(secpolicy_chkpolicy("PRINT_POSTSCRIPT=") == 0)) {
== 0) {
goto Return;
}
}
lp_or_root = 0;
lp_or_root = 1;
if (prefixp)
/*
* If a destination other than "any" was given,
* see if it exists in our internal tables.
*/
/*EMPTY*/;
else {
goto Return;
}
/*
* If we are trying to avoid a printer, but the request
* was destined for just that printer, we're out.
*/
goto Return;
}
/*
* If a form was given, see if it exists; if so,
* see if the user is allowed to use it.
* If a remote printer was specified, then don't use any local
* form knowledge.
*/
/*EMPTY*/;
else {
ret = MDENYMEDIA;
goto Return;
}
} else {
goto Return;
}
}
/*
* If the request includes -o options there may be pitch and
* size and no-banner requests that have to be checked. One
* could argue that this shouldn't be in the Spooler, because
* the Spooler's job is SPOOLING, not PRINTING. That's right,
* except that the Spooler will be making a choice of printers
* so it has to evaluate carefully: E.g. user wants ANY printer,
*
* Parse out the important stuff here so we have it when we
* need it.
*/
{
register char **list,
**pl;
if (
) {
wants_nobanner = 1;
wants_nolabels = 1;
}
}
/*
* This macro checks that a form has a mandatory print wheel
* (or character set).
*/
( \
(PFS) \
)
/*
* This macro checks that the user is allowed to use the
* printer.
*/
( \
|| allowed( \
(PPS)->users_allowed, \
(PPS)->users_denied \
) \
)
/*
* This macro checks that the form is allowed on the printer,
* or is already mounted there.
* Note: By doing this check we don't have to check that the
* characteristics of the form, such as pitch, size, or
* character set, against the printer's capabilities, ASSUMING,
* of course, that the allow list is correct. That is, the
* allow list lists forms that have already been checked against
* the printer!
*/
( \
|| allowed( \
(PPS)->forms_allowed, \
(PPS)->forms_denied \
) \
)
/*
* This macro checks that the print wheel is acceptable
* for the printer or is mounted. Note: If the printer doesn't
* take print wheels, the check passes. The check for printers
* that don't take print wheels is below.
*/
( \
|| ( \
(PPS)->pwheel_name \
) \
)
/*
* This macro checks the pitch, page size, and (if need be)
* the character set. The character set isn't checked if the
* printer takes print wheels, or if the character set is
* listed in the printer's alias list.
* The form has to be checked as well; while we're sure that
* at least one type for each printer can handle the form's
* sure that ALL the types work.
*/
/*
* This macro checks the acceptance status of a printer.
* If the request is already assigned to that printer,
* then it's okay. It's ambiguous what should happen if
* originally a "-d any" request was accepted, temporarily
* assigned one printer, then the administrator (1) rejected
* further requests for the printers and (2) made the
* temporarily assigned printer unusable for the request.
* What will happen, of course, is that the request will
* be canceled, even though the other printers would be okay
* if not rejecting....but if we were to say, gee it's okay,
* the request has already been accepted, we may be allowing
* it on printers that were NEVER accepting. Thus we can
* continue to accept it only for the printer already assigned.
*/
( \
|| moving \
)
/*
* If a print wheel or character set is given, see if it
* is allowed on the form.
*/
if (
)
/*EMPTY*/;
else {
ret = MDENYMEDIA;
goto Return;
}
/*
* If a single printer was named, check the request against it.
* useful information to the user.
*/
if (pps) {
/* Does the printer allow the user? */
goto Return;
}
/* Check printer label range */
goto Return;
}
}
/* Does the printer allow the form? */
goto Return;
}
/* Does the printer allow the pwheel? */
if (
) {
goto Return;
}
goto Return;
}
/* Is the printer allowing requests? */
goto Return;
}
/* Is there a filter which will convert the input? */
goto Return;
}
goto Return;
}
/*
* Do the acceptance check on the class (if we have one)
* now so we can proceed with checks on individual printers
* in the class. Don't toss out the request if it is already
* assigned a printer just because the class is NOW rejecting.
*/
if (
&& !moving
) {
goto Return;
}
/*
* Construct a list of printers based on the destination
* given. Cross off those that aren't accepting requests,
* that can't take the form, or which the user can't use.
* See if the list becomes empty.
*/
if (pcs)
else {
}
/*
* Start with a list of printers that are accepting requests.
* Don't skip a printer if it's rejecting but the request
* has already been accepted for it.
*/
if (pcs) {
register char **pn;
if (
)
} else
}
goto Return;
}
/*
* Clean out printers that the user can't use. We piggy-back
* is given (strange, eh?).
*/
{
else
free_candidate (pc);
}
goto Return;
}
}
/*
* Clean out printers that can't mount the form,
* EXCEPT for printers that already have it mounted:
*/
if (pfs) {
else
free_candidate (pc);
goto Return;
}
}
/*
* Clean out printers that can't take the print wheel
* EXCEPT for printers that already have it mounted
* or printers for which it is a selectable character set:
*/
else
free_candidate (pc);
goto Return;
}
}
/*
* Clean out printers that can't handle the printing
* and for which there's no filter to convert the input.
*
*/
/*
* Is the form mounted, or is none needed?
*/
/*
* Is the print-wheel mounted, or is none needed?
*/
/*
* Do we NOT need a special character set, or can we select
* it on the printer? Note: Getting this far means that IF
* the printer has selectable character sets (!daisy) then
* it can select the one we want.
*/
( \
)
/*
* Is the printer able to print now?
*/
/*
* Is the printer not busy printing another request, or
* not awaiting an auto-retry after a fault?
*/
{
/*
* Compute a ``weight'' for this printer,
* based on its status. We'll later pick
* the printer with the highest weight.
*/
#if defined(FILTER_EARLY_OUT)
/*
* This is the one!
*/
goto Return;
}
#endif
/*
* This is a candidate!
*/
} else
/*
* No filter for this one!
*/
free_candidate (pc);
goto Return;
}
}
goto Return;
}
/*
* Clean out local printers
* where the request is outside the printer label range.
*/
{
if (is_system_labeled()) {
else
}
}
goto Return;
}
}
#if defined(OTHER_FACTORS)
/*
* Here you might want to add code that considers
* other factors: the size of the file(s) to be
* printed ("prs->secure->size") in relation to the
* printer (e.g. printer A gets mostly large
* files, printer B gets mostly small files); the
* number/total-size of requests currently queued
* for the printer; etc.
*
* If your code includes eliminating printers drop them
* from the list (as done in several places above).
* Otherwise, your code should add weights to the weight
* already computed. Change the WEIGHT_MAX, increase the
* other WEIGHT_X values to compensate, etc., as appropriate.
*/
;
#endif
/*
* Pick the best printer from a list of eligible candidates.
*/
/*
*/
register char *pwheel_name;
/*
* We are going to accept this print request, having
* found a printer for it. This printer will be assigned
* to the request, although this assignment may be
* temporary if other printers qualify and this printer
* is changed to no longer qualify. Qualification in
* this context includes being ready to print!
*/
/*
* Assign the form (if any) to the request. Adjust
* the number of requests queued for old and new form
* accordingly.
*/
unqueue_form (prs);
}
/*
* Ditto for the print wheel, except include here the
* print wheel needed by the form.
* CAUTION: When checking this request later, don't
* refuse to service it if the print wheel for the
* form isn't mounted but the form is; a mounted form
* overrides its other needs. Don't be confused by the
* name of the bit, RSS_PWMAND; a printer that prints
* this request MUST have the print wheel mounted
* (if it takes print wheels) if the user asked for
* a particular print wheel.
*/
else
}
/*
* Adjust the priority to lie within the limits allowed
* for the user (this is a silent adjustment as required).
* CURRENTLY, ONLY NEW REQUESTS WILL GET QUEUED ACCORDING
* TO THIS PRIORITY. EXISTING REQUESTS BEING (RE)EVALUATED
* WILL NOT BE REQUEUED.
* A wild priority is changed to the default, or the
* limit, whichever is the lower priority (higher value).
*/
/*
* If a filter is involved, change the number of
* copies to 1 (if the filter handles it).
*/
if (
)
else
/*
* We use two ".copies" because we don't
* want to lose track of the number requested,
* but do want to mark the number the interface
* program is to handle. Here is the best
* place to know this.
*/
/*
* If the filter has changed, the request will
* have to be refiltered. This may mean stopping
* a currently running filter or interface.
*/
if (
) {
} else if (
) {
}
}
/* Assumption: if there is a slow filter,
* there is an output_type
*/
} else
"|",
(char *)0
);
} else
}
}
/*
* Free the space allocated for the candidates, INCLUDING
* the one chosen. Any allocated space in the chosen candidate
* that has to be saved should have been COPIED already.
*/
if (arena) {
free_candidate (pc);
} else if (best_pc)
if (o_length)
if (o_width)
if (o_lpi)
if (o_cpi)
/*
* The following value is valid ONLY IF the request
* is canceled or rejected. Not all requests that
* we fail in this routine are tossed out!
*/
return (ret);
}
/**
** _chkopts() - CHECK -o OPTIONS
**/
static int
{
unsigned long ret = 0;
unsigned long chk = 0;
char * charset;
char * cpi = 0;
char * lpi = 0;
char * width = 0;
char * length = 0;
char ** pt;
int nobanner_not_allowed = 0;
/*
* If we have a form, it overrides whatever print characteristics
* the user gave.
*/
if (pfs) {
} else {
}
/*
* If the printer takes print wheels, or the character set
* the user wants is listed in the character set map for this
* printer, we needn't check if the printer can handle the
* character set. (Note: The check for the print wheel case
* is done elsewhere.)
*/
charset = 0;
else
pc->printer_types = 0;
unsigned long this;
if (paper) {
} else {
}
} else {
charset);
if (this == 0)
}
}
if (!pc->printer_types)
/*
* If the sytem is labeled, then user who wants 'nolabels' must
* have PRINT_UNLABELED_AUTH authorizations to allow it.
*/
/* if not authorized, remove "nolabels" from options */
register char **list;
}
}
}
/* delete "nobanner" */
char **list;
/*
* If the system is labeled, users must have
* PRINT_NOBANNER_AUTH authorization to print
* without a banner.
*/
if (is_system_labeled()) {
if (wants_nobanner == 1) {
nobanner_not_allowed = 1;
}
}
}
nobanner_not_allowed = 1;
}
if (nobanner_not_allowed == 1) {
/* Take out 'nobanner' from request options. */
}
}
if (wants_nobanner == 0) {
/* add "nobanner" */
}
}
} else /* if (pc->pps->printer->banner == BAN_OPTIONAL) */ {
/* it is optional, leave it alone */
}
chkprinter_result |= ret;
return (ret == 0);
}
/**
** free_candidate()
**/
static void
{
if (pc->printer_types) {
pc->printer_types = 0;
}
if (pc->printer_type)
if (pc->output_type)
return;
}
static int
{
int in_range = 0;
int err = 0;
return (0);
if ((err =
== -1) {
/* stobsl error on printer max label */
return (0);
}
return (0);
}
/* blinrange returns true (1) if in range, false (0) if not */
return (in_range);
}
/*
* Given a character string with a "username" or "system!username"
* this function returns a pointer to "username"
*/
static int
{
char *cp;
int res;
/* user@system */
*cp = '\0';
*cp = '@';
/* system!user */
else
/* user */
return (res);
}
int
{
char *option;
int opt_val;
return (0);
opt_val = 0;
if (defopen(POLICY_FILE) == 0) {
}
return (opt_val);
}