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