Home | History | Annotate | Download | only in lpadmin
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
     28 /*	  All Rights Reserved  	*/
     29 
     30 
     31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
     32 
     33 #include "stdio.h"
     34 #include "string.h"
     35 #include "sys/types.h"
     36 
     37 #include "lp.h"
     38 #include "msgs.h"
     39 #include "printers.h"
     40 #include "form.h"
     41 #include "access.h"
     42 
     43 #define	WHO_AM_I	I_AM_LPADMIN
     44 #include "oam.h"
     45 
     46 #include "lpadmin.h"
     47 
     48 extern FORM		formbuf;
     49 
     50 void			mount_unmount();
     51 
     52 short			printer_status;
     53 
     54 static char		*cur_pwheel;
     55 char			*disable_reason,
     56 			*reject_reason;
     57 
     58 static void		inquire_printer_status();
     59 
     60 /**
     61  ** do_mount() - MOUNT/UNMOUNT A FORM/PRINT-WHEEL
     62  **/
     63 
     64 void			do_mount (printer, form, pwheel)
     65 	char			*printer,
     66 				*form,
     67 				*pwheel;
     68 {
     69 	/*
     70 	 * Take care of unmounts, first.
     71 	 */
     72 
     73 	if (form && STREQU(form, NAME_NONE))
     74 		form = "";
     75 	if (pwheel && (STREQU(pwheel, NAME_ANY) || STREQU(pwheel, NAME_NONE)))
     76 		pwheel = "";
     77 
     78 	if (form && !*form && a)
     79 		LP_ERRMSG (WARNING, E_ADM_UNALIGN);
     80 
     81 	if (form && !*form && pwheel && !*pwheel) {
     82 		mount_unmount (S_UNMOUNT, printer, NAME_NONE, NAME_ANY);
     83 		form = 0;
     84 		pwheel = 0;
     85 	} else if (form && !*form) {
     86 		mount_unmount (S_UNMOUNT, printer, NAME_NONE, "");
     87 		form = 0;
     88 	} else if (pwheel && !*pwheel) {
     89 		mount_unmount (S_UNMOUNT, printer, "", NAME_ANY);
     90 		pwheel = 0;
     91 	}
     92 
     93 	if (!form && !pwheel)
     94 		return;
     95 
     96 	/*
     97 	 * See if the form will work on the printer. We do this even if
     98 	 * the form has already been allowed, just in case the form has
     99 	 * changed since then. Also, the check reads the form definition
    100 	 * into a global that we can use for subsequent checks.
    101 	 */
    102 	if (!s) { /* a local printer */
    103 
    104 	if (form && *form)
    105 		switch (verify_form(form)) {
    106 		case -1:
    107 			LP_ERRMSG (WARNING, E_ADM_BADMOUNT);
    108 			break;
    109 		case -2:
    110 			LP_ERRMSG1 (ERROR, E_ADM_MANDCHSET, formbuf.chset);
    111 			done (1);
    112 		}
    113 
    114 	/*
    115 	 * Is the form allowed on the printer?
    116 	 */
    117 	if (form && *form && !is_form_allowed_printer(form, printer))
    118 		LP_ERRMSG2 (WARNING, E_ADM_ICKFORM, form, printer);
    119 
    120 
    121 	/*
    122 	 * Does the printer take print wheels?
    123 	 * For us to be here, "daisy" must have been set.
    124 	 * (-S requires knowing printer type (T), and knowing
    125 	 * T caused call to "tidbit()" to set "daisy").
    126 	 */
    127 	if (pwheel && *pwheel && !daisy) {
    128 		LP_ERRMSG (ERROR, E_ADM_NOPWHEEL);
    129 		done (1);
    130 	}
    131 
    132 	/*
    133 	 * If the form requires a particular print wheel, make sure
    134 	 * it is either mounted already, or is being mounted now.
    135 	 */
    136 	if (form && *form) {
    137 		/*
    138 		 * The printer status is also needed for "do_align()".
    139 		 */
    140 		inquire_printer_status (printer);
    141 
    142 		/*
    143 		 * The "!daisy" case was investigated in "verify_form()".
    144 		 */
    145 		if (daisy && formbuf.mandatory && formbuf.chset)
    146 			if (!pwheel || !*pwheel) {
    147 				if (!STREQU(formbuf.chset, cur_pwheel))
    148 					LP_ERRMSG1 (
    149 						WARNING,
    150 						E_ADM_MANDPWHEEL1,
    151 						formbuf.chset
    152 					);
    153 			} else if (!STREQU(formbuf.chset, pwheel)) {
    154 				LP_ERRMSG1 (
    155 					WARNING,
    156 					E_ADM_MANDPWHEEL2,
    157 					formbuf.chset
    158 				);
    159 			}
    160 	}
    161 
    162 	/*
    163 	 * Is the print wheel listed for this printer?
    164 	 * The information that will tell us is either in the
    165 	 * original info. we read in ("oldp->char_sets") if this
    166 	 * is an existing printer, or--if this is a new printer--we
    167 	 * don't have it (ambiguous -S options, mate!)
    168 	 */
    169 	if (
    170 		pwheel
    171 	     && *pwheel
    172 	     && !(
    173 			oldp
    174 		     && searchlist(pwheel, oldp->char_sets)
    175 		)
    176 	)
    177 		LP_ERRMSG2 (WARNING, E_ADM_ICKPWHEEL, pwheel, printer);
    178 
    179 	}
    180 
    181 	/*
    182 	 * Do the mount with the printing of the alignment pattern,
    183 	 * if required and possible. Otherwise, just mount the form
    184 	 * (and print-wheel).
    185 	 */
    186 	if (!a || !do_align(printer, form, pwheel))
    187 		mount_unmount (S_MOUNT, printer, NB(form), NB(pwheel));
    188 
    189 	return;
    190 }
    191 
    192 void			mount_unmount (type, printer, form, pwheel)
    193 	int			type;
    194 	char			*printer,
    195 				*form,
    196 				*pwheel;
    197 {
    198 	int			rc;
    199 
    200 	if (t) {  /* tray specified */
    201 		type = (type == S_MOUNT ? S_MOUNT_TRAY : S_UNMOUNT_TRAY);
    202 		send_message(type, printer, form, pwheel, t);
    203 	} else
    204 		send_message(type, printer, form, pwheel);
    205 
    206 	rc = output(type + 1);
    207 
    208 	switch(rc) {
    209 
    210 	case MOK:
    211 		break;
    212 
    213 	case MNOMEDIA:
    214 		LP_ERRMSG (ERROR, E_ADM_NOMEDIA);
    215 		done (1);
    216 		/*NOTREACHED*/
    217 
    218 	case MNODEST:
    219 		LP_ERRMSG1 (ERROR, E_ADM_NODEST, printer);
    220 		done (1);
    221 		/*NOTREACHED*/
    222 
    223 	case MBUSY:
    224 		LP_ERRMSG (ERROR, E_ADM_MNTLATER);
    225 		done (1);
    226 		/*NOTREACHED*/
    227 
    228 	case MNOTRAY:
    229 		LP_ERRMSG (ERROR, E_ADM_BADTRAY);
    230 		done (1);
    231 		/*NOTREACHED*/
    232 
    233 	case MNOPERM:	/* taken care of up front */
    234 	default:
    235 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
    236 		done (1);
    237 		/*NOTREACHED*/
    238 
    239 	}
    240 	return;
    241 }
    242 
    243 void
    244 do_max_trays(char *printer)
    245 {
    246 	int			rc;
    247 
    248 	if (t)  /* tray specified */
    249 		send_message(S_MAX_TRAYS, printer, t);
    250 
    251 	rc = output(R_MAX_TRAYS);
    252 
    253 	switch(rc) {
    254 
    255 	case MOK:
    256 		break;
    257 
    258 	case MNOMEDIA:
    259 		LP_ERRMSG (ERROR, E_ADM_NOMEDIA);
    260 		done (1);
    261 		/*NOTREACHED*/
    262 
    263 	case MNODEST:
    264 		LP_ERRMSG1 (ERROR, E_ADM_NODEST, printer);
    265 		done (1);
    266 		/*NOTREACHED*/
    267 
    268 	case MBUSY:
    269 		LP_ERRMSG (ERROR, E_ADM_MNTLATER);
    270 		done (1);
    271 		/*NOTREACHED*/
    272 
    273 	case MNOTRAY:
    274 		LP_ERRMSG (ERROR, E_ADM_MAXTRAY);
    275 		done (1);
    276 		/*NOTREACHED*/
    277 
    278 	case MNOPERM:	/* taken care of up front */
    279 	default:
    280 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
    281 		done (1);
    282 		/*NOTREACHED*/
    283 
    284 	}
    285 	return;
    286 }
    287 
    288 /**
    289  ** inquire_printer_status()
    290  **/
    291 
    292 static void		inquire_printer_status (printer)
    293 	char			*printer;
    294 {
    295 	short			status;
    296 
    297 	char			*s_ignore,
    298 				buffer[MSGMAX];
    299 
    300 	long			l_ignore;
    301 
    302 
    303 	send_message (S_INQUIRE_PRINTER_STATUS, printer);
    304 	if (mrecv(buffer, MSGMAX) != R_INQUIRE_PRINTER_STATUS) {
    305 		LP_ERRMSG (ERROR, E_LP_MRECV);
    306 		done (1);
    307 	}
    308 	(void)getmessage (
    309 		buffer,
    310 		R_INQUIRE_PRINTER_STATUS,
    311 		&status,
    312 		&s_ignore,
    313 		&s_ignore,
    314 		&cur_pwheel,
    315 		&disable_reason,
    316 		&reject_reason,
    317 		&printer_status,
    318 		&s_ignore,
    319 		&l_ignore,
    320 		&l_ignore
    321 	);
    322 
    323 	switch (status) {
    324 	case MOK:
    325 		disable_reason = strdup(disable_reason);
    326 		reject_reason = strdup(reject_reason);
    327 		cur_pwheel = strdup(cur_pwheel);
    328 		break;
    329 
    330 	case MNODEST:
    331 		LP_ERRMSG1 (ERROR, E_LP_PGONE, printer);
    332 		done (1);
    333 	}
    334 
    335 	return;
    336 }
    337