1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.11 */ 32*0Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include "stdio.h" 35*0Sstevel@tonic-gate #include "string.h" 36*0Sstevel@tonic-gate #include "errno.h" 37*0Sstevel@tonic-gate #include "sys/types.h" 38*0Sstevel@tonic-gate #include "sys/utsname.h" 39*0Sstevel@tonic-gate #include "stdlib.h" 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #include "lp.h" 42*0Sstevel@tonic-gate #include "requests.h" 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate extern struct { 45*0Sstevel@tonic-gate char *v; 46*0Sstevel@tonic-gate short len; 47*0Sstevel@tonic-gate } reqheadings[]; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate /** 50*0Sstevel@tonic-gate ** putrequest() - WRITE REQUEST STRUCTURE TO DISK FILE 51*0Sstevel@tonic-gate **/ 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate int 54*0Sstevel@tonic-gate #if defined(__STDC__) 55*0Sstevel@tonic-gate putrequest ( 56*0Sstevel@tonic-gate char * file, 57*0Sstevel@tonic-gate REQUEST * reqbufp 58*0Sstevel@tonic-gate ) 59*0Sstevel@tonic-gate #else 60*0Sstevel@tonic-gate putrequest (file, reqbufp) 61*0Sstevel@tonic-gate char *file; 62*0Sstevel@tonic-gate REQUEST *reqbufp; 63*0Sstevel@tonic-gate #endif 64*0Sstevel@tonic-gate { 65*0Sstevel@tonic-gate char **pp, 66*0Sstevel@tonic-gate *path; 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate int fd; 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate int fld; 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate /* 73*0Sstevel@tonic-gate * First go through the structure and see if we have 74*0Sstevel@tonic-gate * anything strange. 75*0Sstevel@tonic-gate */ 76*0Sstevel@tonic-gate if ( 77*0Sstevel@tonic-gate reqbufp->copies <= 0 78*0Sstevel@tonic-gate || !(reqbufp->destination) 79*0Sstevel@tonic-gate || !reqbufp->file_list || !*(reqbufp->file_list) 80*0Sstevel@tonic-gate || (reqbufp->actions & (ACT_MAIL|ACT_WRITE)) 81*0Sstevel@tonic-gate && (reqbufp->alert && *(reqbufp->alert)) 82*0Sstevel@tonic-gate || reqbufp->priority < -1 || 39 < reqbufp->priority 83*0Sstevel@tonic-gate ) { 84*0Sstevel@tonic-gate errno = EINVAL; 85*0Sstevel@tonic-gate return (-1); 86*0Sstevel@tonic-gate } 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate /* 89*0Sstevel@tonic-gate * Now open the file and write out the request. 90*0Sstevel@tonic-gate */ 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate /* 93*0Sstevel@tonic-gate * Full pathname? If so the file must lie in LP's 94*0Sstevel@tonic-gate * regular temporary directory. 95*0Sstevel@tonic-gate */ 96*0Sstevel@tonic-gate if (*file == '/') { 97*0Sstevel@tonic-gate if (!STRNEQU(file, Lp_Tmp, strlen(Lp_Tmp))) { 98*0Sstevel@tonic-gate errno = EINVAL; 99*0Sstevel@tonic-gate return (-1); 100*0Sstevel@tonic-gate } 101*0Sstevel@tonic-gate path = Strdup(file); 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate /* 104*0Sstevel@tonic-gate * A relative pathname (such as system/name)? 105*0Sstevel@tonic-gate * If so we'll locate it under LP's regular temporary 106*0Sstevel@tonic-gate * directory. 107*0Sstevel@tonic-gate */ 108*0Sstevel@tonic-gate } else if (strchr(file, '/')) { 109*0Sstevel@tonic-gate if (!(path = makepath(Lp_Tmp, file, (char *)0))) 110*0Sstevel@tonic-gate return (-1); 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate /* 113*0Sstevel@tonic-gate * If must be a simple name. Locate this under the 114*0Sstevel@tonic-gate * special temporary directory that is linked to the 115*0Sstevel@tonic-gate * regular place for the local system. 116*0Sstevel@tonic-gate */ 117*0Sstevel@tonic-gate } else if (!(path = makepath(Lp_Temp, file, (char *)0))) 118*0Sstevel@tonic-gate return (-1); 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate if ((fd = open_locked(path, "w", MODE_NOREAD)) < 0) { 121*0Sstevel@tonic-gate Free (path); 122*0Sstevel@tonic-gate return (-1); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate Free (path); 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate for (fld = 0; fld < RQ_MAX; fld++) switch (fld) { 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate #define HEAD reqheadings[fld].v 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate case RQ_COPIES: 131*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->copies); 132*0Sstevel@tonic-gate break; 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate case RQ_DEST: 135*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->destination); 136*0Sstevel@tonic-gate break; 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate case RQ_FILE: 139*0Sstevel@tonic-gate for (pp = reqbufp->file_list; *pp; pp++) 140*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, *pp); 141*0Sstevel@tonic-gate break; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate case RQ_FORM: 144*0Sstevel@tonic-gate if (reqbufp->form) 145*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->form); 146*0Sstevel@tonic-gate break; 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate case RQ_HANDL: 149*0Sstevel@tonic-gate if ((reqbufp->actions & ACT_SPECIAL) == ACT_IMMEDIATE) 150*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, NAME_IMMEDIATE); 151*0Sstevel@tonic-gate else if ((reqbufp->actions & ACT_SPECIAL) == ACT_RESUME) 152*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, NAME_RESUME); 153*0Sstevel@tonic-gate else if ((reqbufp->actions & ACT_SPECIAL) == ACT_HOLD) 154*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, NAME_HOLD); 155*0Sstevel@tonic-gate break; 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate case RQ_NOTIFY: 158*0Sstevel@tonic-gate if (reqbufp->actions & ACT_MAIL) 159*0Sstevel@tonic-gate (void)fdprintf(fd, "%sM\n", HEAD); 160*0Sstevel@tonic-gate else if (reqbufp->actions & ACT_WRITE) 161*0Sstevel@tonic-gate (void)fdprintf(fd, "%sW\n", HEAD); 162*0Sstevel@tonic-gate else if (reqbufp->actions & ACT_NOTIFY) 163*0Sstevel@tonic-gate (void)fdprintf(fd, "%sN\n", HEAD); 164*0Sstevel@tonic-gate else if (reqbufp->alert && *(reqbufp->alert)) 165*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->alert); 166*0Sstevel@tonic-gate break; 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate case RQ_OPTS: 169*0Sstevel@tonic-gate if (reqbufp->options) 170*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->options); 171*0Sstevel@tonic-gate break; 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate case RQ_PRIOR: 174*0Sstevel@tonic-gate if (reqbufp->priority != -1) 175*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->priority); 176*0Sstevel@tonic-gate break; 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate case RQ_PAGES: 179*0Sstevel@tonic-gate if (reqbufp->pages) 180*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->pages); 181*0Sstevel@tonic-gate break; 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate case RQ_CHARS: 184*0Sstevel@tonic-gate if (reqbufp->charset) 185*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->charset); 186*0Sstevel@tonic-gate break; 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate case RQ_TITLE: 189*0Sstevel@tonic-gate if (reqbufp->title) 190*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->title); 191*0Sstevel@tonic-gate break; 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate case RQ_MODES: 194*0Sstevel@tonic-gate if (reqbufp->modes) 195*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->modes); 196*0Sstevel@tonic-gate break; 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate case RQ_TYPE: 199*0Sstevel@tonic-gate if (reqbufp->input_type) 200*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->input_type); 201*0Sstevel@tonic-gate break; 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate case RQ_USER: 204*0Sstevel@tonic-gate if (reqbufp->user) 205*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%s\n", HEAD, reqbufp->user); 206*0Sstevel@tonic-gate break; 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate case RQ_RAW: 209*0Sstevel@tonic-gate if (reqbufp->actions & ACT_RAW) 210*0Sstevel@tonic-gate (void)fdprintf(fd, "%s\n", HEAD); 211*0Sstevel@tonic-gate break; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate case RQ_FAST: 214*0Sstevel@tonic-gate if (reqbufp->actions & ACT_FAST) 215*0Sstevel@tonic-gate (void)fdprintf(fd, "%s\n", HEAD); 216*0Sstevel@tonic-gate break; 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate case RQ_STAT: 219*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%#6.4x\n", HEAD, reqbufp->outcome); 220*0Sstevel@tonic-gate break; 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate case RQ_VERSION: 223*0Sstevel@tonic-gate (void)fdprintf(fd, "%s%d\n", HEAD, reqbufp->version); 224*0Sstevel@tonic-gate break; 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate } 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate close(fd); 229*0Sstevel@tonic-gate return (0); 230*0Sstevel@tonic-gate } 231