17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include "stdio.h"
317c478bd9Sstevel@tonic-gate #include "string.h"
327c478bd9Sstevel@tonic-gate #include "sys/types.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include "lp.h"
357c478bd9Sstevel@tonic-gate #include "msgs.h"
367c478bd9Sstevel@tonic-gate #include "printers.h"
377c478bd9Sstevel@tonic-gate #include "form.h"
387c478bd9Sstevel@tonic-gate #include "access.h"
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #define WHO_AM_I I_AM_LPADMIN
417c478bd9Sstevel@tonic-gate #include "oam.h"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #include "lpadmin.h"
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate extern FORM formbuf;
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate void mount_unmount();
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate short printer_status;
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static char *cur_pwheel;
527c478bd9Sstevel@tonic-gate char *disable_reason,
537c478bd9Sstevel@tonic-gate *reject_reason;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate static void inquire_printer_status();
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /**
587c478bd9Sstevel@tonic-gate ** do_mount() - MOUNT/UNMOUNT A FORM/PRINT-WHEEL
597c478bd9Sstevel@tonic-gate **/
607c478bd9Sstevel@tonic-gate
do_mount(printer,form,pwheel)617c478bd9Sstevel@tonic-gate void do_mount (printer, form, pwheel)
627c478bd9Sstevel@tonic-gate char *printer,
637c478bd9Sstevel@tonic-gate *form,
647c478bd9Sstevel@tonic-gate *pwheel;
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate * Take care of unmounts, first.
687c478bd9Sstevel@tonic-gate */
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate if (form && STREQU(form, NAME_NONE))
717c478bd9Sstevel@tonic-gate form = "";
727c478bd9Sstevel@tonic-gate if (pwheel && (STREQU(pwheel, NAME_ANY) || STREQU(pwheel, NAME_NONE)))
737c478bd9Sstevel@tonic-gate pwheel = "";
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate if (form && !*form && a)
767c478bd9Sstevel@tonic-gate LP_ERRMSG (WARNING, E_ADM_UNALIGN);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate if (form && !*form && pwheel && !*pwheel) {
797c478bd9Sstevel@tonic-gate mount_unmount (S_UNMOUNT, printer, NAME_NONE, NAME_ANY);
807c478bd9Sstevel@tonic-gate form = 0;
817c478bd9Sstevel@tonic-gate pwheel = 0;
827c478bd9Sstevel@tonic-gate } else if (form && !*form) {
837c478bd9Sstevel@tonic-gate mount_unmount (S_UNMOUNT, printer, NAME_NONE, "");
847c478bd9Sstevel@tonic-gate form = 0;
857c478bd9Sstevel@tonic-gate } else if (pwheel && !*pwheel) {
867c478bd9Sstevel@tonic-gate mount_unmount (S_UNMOUNT, printer, "", NAME_ANY);
877c478bd9Sstevel@tonic-gate pwheel = 0;
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate if (!form && !pwheel)
917c478bd9Sstevel@tonic-gate return;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate * See if the form will work on the printer. We do this even if
957c478bd9Sstevel@tonic-gate * the form has already been allowed, just in case the form has
967c478bd9Sstevel@tonic-gate * changed since then. Also, the check reads the form definition
977c478bd9Sstevel@tonic-gate * into a global that we can use for subsequent checks.
987c478bd9Sstevel@tonic-gate */
997c478bd9Sstevel@tonic-gate if (!s) { /* a local printer */
100*2a8bcb4eSToomas Soome
1017c478bd9Sstevel@tonic-gate if (form && *form)
1027c478bd9Sstevel@tonic-gate switch (verify_form(form)) {
1037c478bd9Sstevel@tonic-gate case -1:
1047c478bd9Sstevel@tonic-gate LP_ERRMSG (WARNING, E_ADM_BADMOUNT);
1057c478bd9Sstevel@tonic-gate break;
1067c478bd9Sstevel@tonic-gate case -2:
1077c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_ADM_MANDCHSET, formbuf.chset);
1087c478bd9Sstevel@tonic-gate done (1);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate * Is the form allowed on the printer?
1137c478bd9Sstevel@tonic-gate */
1147c478bd9Sstevel@tonic-gate if (form && *form && !is_form_allowed_printer(form, printer))
1157c478bd9Sstevel@tonic-gate LP_ERRMSG2 (WARNING, E_ADM_ICKFORM, form, printer);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate * Does the printer take print wheels?
1207c478bd9Sstevel@tonic-gate * For us to be here, "daisy" must have been set.
1217c478bd9Sstevel@tonic-gate * (-S requires knowing printer type (T), and knowing
1227c478bd9Sstevel@tonic-gate * T caused call to "tidbit()" to set "daisy").
1237c478bd9Sstevel@tonic-gate */
1247c478bd9Sstevel@tonic-gate if (pwheel && *pwheel && !daisy) {
1257c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_NOPWHEEL);
1267c478bd9Sstevel@tonic-gate done (1);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * If the form requires a particular print wheel, make sure
1317c478bd9Sstevel@tonic-gate * it is either mounted already, or is being mounted now.
1327c478bd9Sstevel@tonic-gate */
1337c478bd9Sstevel@tonic-gate if (form && *form) {
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate * The printer status is also needed for "do_align()".
1367c478bd9Sstevel@tonic-gate */
1377c478bd9Sstevel@tonic-gate inquire_printer_status (printer);
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * The "!daisy" case was investigated in "verify_form()".
1417c478bd9Sstevel@tonic-gate */
1427c478bd9Sstevel@tonic-gate if (daisy && formbuf.mandatory && formbuf.chset)
1437c478bd9Sstevel@tonic-gate if (!pwheel || !*pwheel) {
1447c478bd9Sstevel@tonic-gate if (!STREQU(formbuf.chset, cur_pwheel))
1457c478bd9Sstevel@tonic-gate LP_ERRMSG1 (
1467c478bd9Sstevel@tonic-gate WARNING,
1477c478bd9Sstevel@tonic-gate E_ADM_MANDPWHEEL1,
1487c478bd9Sstevel@tonic-gate formbuf.chset
1497c478bd9Sstevel@tonic-gate );
1507c478bd9Sstevel@tonic-gate } else if (!STREQU(formbuf.chset, pwheel)) {
1517c478bd9Sstevel@tonic-gate LP_ERRMSG1 (
1527c478bd9Sstevel@tonic-gate WARNING,
1537c478bd9Sstevel@tonic-gate E_ADM_MANDPWHEEL2,
1547c478bd9Sstevel@tonic-gate formbuf.chset
1557c478bd9Sstevel@tonic-gate );
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate * Is the print wheel listed for this printer?
1617c478bd9Sstevel@tonic-gate * The information that will tell us is either in the
1627c478bd9Sstevel@tonic-gate * original info. we read in ("oldp->char_sets") if this
1637c478bd9Sstevel@tonic-gate * is an existing printer, or--if this is a new printer--we
1647c478bd9Sstevel@tonic-gate * don't have it (ambiguous -S options, mate!)
1657c478bd9Sstevel@tonic-gate */
1667c478bd9Sstevel@tonic-gate if (
1677c478bd9Sstevel@tonic-gate pwheel
1687c478bd9Sstevel@tonic-gate && *pwheel
1697c478bd9Sstevel@tonic-gate && !(
1707c478bd9Sstevel@tonic-gate oldp
1717c478bd9Sstevel@tonic-gate && searchlist(pwheel, oldp->char_sets)
1727c478bd9Sstevel@tonic-gate )
1737c478bd9Sstevel@tonic-gate )
1747c478bd9Sstevel@tonic-gate LP_ERRMSG2 (WARNING, E_ADM_ICKPWHEEL, pwheel, printer);
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate * Do the mount with the printing of the alignment pattern,
1807c478bd9Sstevel@tonic-gate * if required and possible. Otherwise, just mount the form
1817c478bd9Sstevel@tonic-gate * (and print-wheel).
1827c478bd9Sstevel@tonic-gate */
1837c478bd9Sstevel@tonic-gate if (!a || !do_align(printer, form, pwheel))
1847c478bd9Sstevel@tonic-gate mount_unmount (S_MOUNT, printer, NB(form), NB(pwheel));
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate return;
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate
mount_unmount(type,printer,form,pwheel)1897c478bd9Sstevel@tonic-gate void mount_unmount (type, printer, form, pwheel)
1907c478bd9Sstevel@tonic-gate int type;
1917c478bd9Sstevel@tonic-gate char *printer,
1927c478bd9Sstevel@tonic-gate *form,
1937c478bd9Sstevel@tonic-gate *pwheel;
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate int rc;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate if (t) { /* tray specified */
1987c478bd9Sstevel@tonic-gate type = (type == S_MOUNT ? S_MOUNT_TRAY : S_UNMOUNT_TRAY);
1997c478bd9Sstevel@tonic-gate send_message(type, printer, form, pwheel, t);
2007c478bd9Sstevel@tonic-gate } else
2017c478bd9Sstevel@tonic-gate send_message(type, printer, form, pwheel);
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate rc = output(type + 1);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate switch(rc) {
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate case MOK:
2087c478bd9Sstevel@tonic-gate break;
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate case MNOMEDIA:
2117c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_NOMEDIA);
2127c478bd9Sstevel@tonic-gate done (1);
2137c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate case MNODEST:
2167c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_ADM_NODEST, printer);
2177c478bd9Sstevel@tonic-gate done (1);
2187c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate case MBUSY:
2217c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_MNTLATER);
2227c478bd9Sstevel@tonic-gate done (1);
2237c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate case MNOTRAY:
2267c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_BADTRAY);
2277c478bd9Sstevel@tonic-gate done (1);
2287c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate case MNOPERM: /* taken care of up front */
2317c478bd9Sstevel@tonic-gate default:
2327c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
2337c478bd9Sstevel@tonic-gate done (1);
2347c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate return;
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate void
do_max_trays(char * printer)2417c478bd9Sstevel@tonic-gate do_max_trays(char *printer)
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate int rc;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate if (t) /* tray specified */
2467c478bd9Sstevel@tonic-gate send_message(S_MAX_TRAYS, printer, t);
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate rc = output(R_MAX_TRAYS);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate switch(rc) {
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate case MOK:
2537c478bd9Sstevel@tonic-gate break;
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate case MNOMEDIA:
2567c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_NOMEDIA);
2577c478bd9Sstevel@tonic-gate done (1);
2587c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate case MNODEST:
2617c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_ADM_NODEST, printer);
2627c478bd9Sstevel@tonic-gate done (1);
2637c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate case MBUSY:
2667c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_MNTLATER);
2677c478bd9Sstevel@tonic-gate done (1);
2687c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate case MNOTRAY:
2717c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_ADM_MAXTRAY);
2727c478bd9Sstevel@tonic-gate done (1);
2737c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate case MNOPERM: /* taken care of up front */
2767c478bd9Sstevel@tonic-gate default:
2777c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
2787c478bd9Sstevel@tonic-gate done (1);
2797c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate return;
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate /**
2867c478bd9Sstevel@tonic-gate ** inquire_printer_status()
2877c478bd9Sstevel@tonic-gate **/
2887c478bd9Sstevel@tonic-gate
inquire_printer_status(printer)2897c478bd9Sstevel@tonic-gate static void inquire_printer_status (printer)
2907c478bd9Sstevel@tonic-gate char *printer;
2917c478bd9Sstevel@tonic-gate {
2927c478bd9Sstevel@tonic-gate short status;
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate char *s_ignore,
2957c478bd9Sstevel@tonic-gate buffer[MSGMAX];
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate long l_ignore;
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate send_message (S_INQUIRE_PRINTER_STATUS, printer);
3017c478bd9Sstevel@tonic-gate if (mrecv(buffer, MSGMAX) != R_INQUIRE_PRINTER_STATUS) {
3027c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_MRECV);
3037c478bd9Sstevel@tonic-gate done (1);
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate (void)getmessage (
3067c478bd9Sstevel@tonic-gate buffer,
3077c478bd9Sstevel@tonic-gate R_INQUIRE_PRINTER_STATUS,
3087c478bd9Sstevel@tonic-gate &status,
3097c478bd9Sstevel@tonic-gate &s_ignore,
3107c478bd9Sstevel@tonic-gate &s_ignore,
3117c478bd9Sstevel@tonic-gate &cur_pwheel,
3127c478bd9Sstevel@tonic-gate &disable_reason,
3137c478bd9Sstevel@tonic-gate &reject_reason,
3147c478bd9Sstevel@tonic-gate &printer_status,
3157c478bd9Sstevel@tonic-gate &s_ignore,
3167c478bd9Sstevel@tonic-gate &l_ignore,
3177c478bd9Sstevel@tonic-gate &l_ignore
3187c478bd9Sstevel@tonic-gate );
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate switch (status) {
3217c478bd9Sstevel@tonic-gate case MOK:
3227c478bd9Sstevel@tonic-gate disable_reason = strdup(disable_reason);
3237c478bd9Sstevel@tonic-gate reject_reason = strdup(reject_reason);
3247c478bd9Sstevel@tonic-gate cur_pwheel = strdup(cur_pwheel);
3257c478bd9Sstevel@tonic-gate break;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate case MNODEST:
3287c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_PGONE, printer);
3297c478bd9Sstevel@tonic-gate done (1);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate return;
3337c478bd9Sstevel@tonic-gate }
334