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
50a44ef6dSjacobs * Common Development and Distribution License (the "License").
60a44ef6dSjacobs * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
210a44ef6dSjacobs
227c478bd9Sstevel@tonic-gate /*
230a44ef6dSjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27f928ce67Sceastha /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28f928ce67Sceastha /* All Rights Reserved */
29f928ce67Sceastha
307c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include "unistd.h"
337c478bd9Sstevel@tonic-gate #include "sys/types.h"
347c478bd9Sstevel@tonic-gate #include "sys/stat.h"
357c478bd9Sstevel@tonic-gate #include "errno.h"
367c478bd9Sstevel@tonic-gate #include "fcntl.h"
377c478bd9Sstevel@tonic-gate #include "stdlib.h"
387c478bd9Sstevel@tonic-gate #include "string.h"
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include "lpsched.h"
417c478bd9Sstevel@tonic-gate
420a44ef6dSjacobs static int __list_increment = 16;
430a44ef6dSjacobs
440a44ef6dSjacobs int
list_append(void *** list,void * item)450a44ef6dSjacobs list_append(void ***list, void *item)
460a44ef6dSjacobs {
470a44ef6dSjacobs int count;
487c478bd9Sstevel@tonic-gate
490a44ef6dSjacobs if ((list == NULL) || (item == NULL)) {
500a44ef6dSjacobs errno = EINVAL;
510a44ef6dSjacobs return (-1);
520a44ef6dSjacobs }
537c478bd9Sstevel@tonic-gate
540a44ef6dSjacobs if (item != NULL) {
550a44ef6dSjacobs if (*list == NULL)
560a44ef6dSjacobs *list = (void **)calloc(__list_increment,
570a44ef6dSjacobs sizeof (void *));
580a44ef6dSjacobs
590a44ef6dSjacobs if (*list == NULL)
600a44ef6dSjacobs return (-1);
610a44ef6dSjacobs
620a44ef6dSjacobs for (count = 0; (*list)[count] != NULL; count++);
630a44ef6dSjacobs
640a44ef6dSjacobs if ((count + 1) % __list_increment == 0) { /* expand the list */ void **new_list = NULL;
650a44ef6dSjacobs int new_size = (((count + 1) / __list_increment) + 1) *
660a44ef6dSjacobs __list_increment;
670a44ef6dSjacobs
680a44ef6dSjacobs new_list = (void **)calloc(new_size, sizeof (void *));
690a44ef6dSjacobs if (new_list == NULL)
700a44ef6dSjacobs return (-1);
710a44ef6dSjacobs
720a44ef6dSjacobs for (count = 0; (*list)[count] != NULL; count++)
730a44ef6dSjacobs new_list[count] = (*list)[count];
740a44ef6dSjacobs free(*list);
750a44ef6dSjacobs *list = new_list;
760a44ef6dSjacobs }
770a44ef6dSjacobs
780a44ef6dSjacobs (*list)[count] = item;
790a44ef6dSjacobs }
800a44ef6dSjacobs
810a44ef6dSjacobs return (0);
820a44ef6dSjacobs }
830a44ef6dSjacobs
840a44ef6dSjacobs void
list_remove(void *** list,void * item)850a44ef6dSjacobs list_remove(void ***list, void *item)
867c478bd9Sstevel@tonic-gate {
870a44ef6dSjacobs int i, count;
880a44ef6dSjacobs void **tmp = NULL;
890a44ef6dSjacobs
900a44ef6dSjacobs if ((list == NULL) || (*list == NULL) || (item == NULL))
910a44ef6dSjacobs return;
920a44ef6dSjacobs
930a44ef6dSjacobs for (count = 0; (*list)[count] != NULL; count++)
940a44ef6dSjacobs ;
957c478bd9Sstevel@tonic-gate
960a44ef6dSjacobs if (count > 0) {
970a44ef6dSjacobs int new_size = (((count + 1) / __list_increment) + 1) *
980a44ef6dSjacobs __list_increment;
990a44ef6dSjacobs
1000a44ef6dSjacobs if ((tmp = (void **)calloc(new_size, sizeof (void *))) == NULL)
1010a44ef6dSjacobs tmp = *list;
102*55fea89dSDan Cross
1030a44ef6dSjacobs /* copy up to item */
1040a44ef6dSjacobs for (i = 0; (((*list)[i] != NULL) && ((*list)[i] != item)); i++)
1050a44ef6dSjacobs tmp[i] = (*list)[i];
1060a44ef6dSjacobs /* copy after item */
1070a44ef6dSjacobs if ((*list)[i] == item)
1080a44ef6dSjacobs for (++i; ((*list)[i] != NULL); i++)
1090a44ef6dSjacobs tmp[i-1] = (*list)[i];
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1120a44ef6dSjacobs /* replace the list */
1130a44ef6dSjacobs if (tmp != *list) {
1140a44ef6dSjacobs free(*list);
1150a44ef6dSjacobs *list = tmp;
1160a44ef6dSjacobs }
1170a44ef6dSjacobs }
1187c478bd9Sstevel@tonic-gate
1190a44ef6dSjacobs void
free_exec(EXEC * ep)1200a44ef6dSjacobs free_exec(EXEC *ep)
1210a44ef6dSjacobs {
1220a44ef6dSjacobs if (ep != NULL) {
1230a44ef6dSjacobs free(ep);
1240a44ef6dSjacobs list_remove((void ***)&Exec_Table, (void *)ep);
1250a44ef6dSjacobs }
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate
1280a44ef6dSjacobs EXEC *
new_exec(int type,void * ex)1290a44ef6dSjacobs new_exec(int type, void *ex)
1300a44ef6dSjacobs {
1310a44ef6dSjacobs EXEC *result = calloc(1, sizeof (*result));
1320a44ef6dSjacobs
1330a44ef6dSjacobs if (result != NULL) {
1340a44ef6dSjacobs result->type = type;
1350a44ef6dSjacobs switch (type) {
1360a44ef6dSjacobs case EX_ALERT:
1370a44ef6dSjacobs case EX_INTERF:
1380a44ef6dSjacobs case EX_FAULT_MESSAGE:
1390a44ef6dSjacobs result->ex.printer = ex;
1400a44ef6dSjacobs break;
1410a44ef6dSjacobs case EX_FALERT:
1420a44ef6dSjacobs result->ex.form = ex;
1430a44ef6dSjacobs break;
1440a44ef6dSjacobs case EX_PALERT:
1450a44ef6dSjacobs result->ex.pwheel = ex;
1460a44ef6dSjacobs break;
1470a44ef6dSjacobs case EX_SLOWF:
1480a44ef6dSjacobs case EX_NOTIFY:
1490a44ef6dSjacobs break;
1500a44ef6dSjacobs }
1510a44ef6dSjacobs list_append((void ***)&Exec_Table, (void *)result);
1520a44ef6dSjacobs }
1530a44ef6dSjacobs
1540a44ef6dSjacobs return (result);
1550a44ef6dSjacobs }
1560a44ef6dSjacobs
1570a44ef6dSjacobs void
free_alert(ALERT * ap)1580a44ef6dSjacobs free_alert(ALERT *ap)
1597c478bd9Sstevel@tonic-gate {
1600a44ef6dSjacobs if (ap != NULL) {
1610a44ef6dSjacobs if (ap->msgfile != NULL)
1620a44ef6dSjacobs free(ap->msgfile);
1630a44ef6dSjacobs if (ap->exec != NULL)
1640a44ef6dSjacobs free_exec(ap->exec);
1650a44ef6dSjacobs free(ap);
1660a44ef6dSjacobs }
1670a44ef6dSjacobs }
1687c478bd9Sstevel@tonic-gate
1690a44ef6dSjacobs ALERT *
new_alert(char * fmt,int i)1700a44ef6dSjacobs new_alert(char *fmt, int i)
1710a44ef6dSjacobs {
1720a44ef6dSjacobs ALERT *result = calloc(1, sizeof (*result));
1730a44ef6dSjacobs
1740a44ef6dSjacobs if (result != NULL) {
1750a44ef6dSjacobs char buf[15];
1760a44ef6dSjacobs
1770a44ef6dSjacobs snprintf(buf, sizeof (buf), fmt, i);
1780a44ef6dSjacobs result->msgfile = makepath(Lp_Temp, buf, (char *)0);
1790a44ef6dSjacobs (void) Unlink(result->msgfile);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate
1820a44ef6dSjacobs return (result);
1830a44ef6dSjacobs }
1847c478bd9Sstevel@tonic-gate
1850a44ef6dSjacobs void
free_pstatus(PSTATUS * psp)1860a44ef6dSjacobs free_pstatus(PSTATUS *psp)
1870a44ef6dSjacobs {
1880a44ef6dSjacobs if (psp != NULL) {
1890a44ef6dSjacobs if (psp->alert != NULL)
1900a44ef6dSjacobs free_alert(psp->alert);
1910a44ef6dSjacobs if (psp->exec != NULL)
1920a44ef6dSjacobs free_exec(psp->exec);
1930a44ef6dSjacobs if (psp->fault_exec != NULL)
1940a44ef6dSjacobs free_exec(psp->fault_exec);
1950a44ef6dSjacobs if (psp->printer != NULL)
1960a44ef6dSjacobs freeprinter(psp->printer);
1970a44ef6dSjacobs if (psp->pwheel_name != NULL)
1980a44ef6dSjacobs free(psp->pwheel_name);
1990a44ef6dSjacobs if (psp->dis_reason != NULL)
2000a44ef6dSjacobs free(psp->dis_reason);
2010a44ef6dSjacobs if (psp->rej_reason != NULL)
2020a44ef6dSjacobs free(psp->rej_reason);
2030a44ef6dSjacobs if (psp->users_allowed != NULL)
2040a44ef6dSjacobs unload_list(&psp->users_allowed);
2050a44ef6dSjacobs if (psp->users_denied != NULL)
2060a44ef6dSjacobs unload_list(&psp->users_denied);
2070a44ef6dSjacobs if (psp->forms_allowed != NULL)
2080a44ef6dSjacobs unload_list(&psp->forms_allowed);
2090a44ef6dSjacobs if (psp->forms_denied != NULL)
2100a44ef6dSjacobs unload_list(&psp->forms_denied);
2110a44ef6dSjacobs if (psp->cpi != NULL)
2120a44ef6dSjacobs free(psp->cpi);
2130a44ef6dSjacobs if (psp->lpi != NULL)
2140a44ef6dSjacobs free(psp->lpi);
2150a44ef6dSjacobs if (psp->plen != NULL)
2160a44ef6dSjacobs free(psp->plen);
2170a44ef6dSjacobs if (psp->pwid != NULL)
2180a44ef6dSjacobs free(psp->pwid);
2190a44ef6dSjacobs if (psp->fault_reason != NULL)
2200a44ef6dSjacobs free(psp->fault_reason);
2210a44ef6dSjacobs if (psp->paper_allowed != NULL)
2220a44ef6dSjacobs unload_list(&psp->paper_allowed);
2230a44ef6dSjacobs free(psp);
2240a44ef6dSjacobs }
2250a44ef6dSjacobs }
2260a44ef6dSjacobs
2270a44ef6dSjacobs void
pstatus_add_printer(PSTATUS * ps,PRINTER * p)2280a44ef6dSjacobs pstatus_add_printer(PSTATUS *ps, PRINTER *p)
2290a44ef6dSjacobs {
2300a44ef6dSjacobs if ((ps != NULL) && (p != NULL)) {
2310a44ef6dSjacobs char **paperDenied = NULL;
2320a44ef6dSjacobs
2330a44ef6dSjacobs ps->printer = p;
2340a44ef6dSjacobs load_userprinter_access(p->name, &(ps->users_allowed),
2350a44ef6dSjacobs &(ps->users_denied));
2360a44ef6dSjacobs load_formprinter_access(p->name, &(ps->forms_allowed),
2370a44ef6dSjacobs &(ps->forms_denied));
2380a44ef6dSjacobs load_paperprinter_access(p->name, &ps->paper_allowed,
2390a44ef6dSjacobs &paperDenied);
2400a44ef6dSjacobs freelist(paperDenied);
2410a44ef6dSjacobs load_sdn(&(ps->cpi), p->cpi);
2420a44ef6dSjacobs load_sdn(&(ps->lpi), p->lpi);
2430a44ef6dSjacobs load_sdn(&(ps->plen), p->plen);
2440a44ef6dSjacobs load_sdn(&(ps->pwid), p->pwid);
2450a44ef6dSjacobs }
2460a44ef6dSjacobs }
2470a44ef6dSjacobs
2480a44ef6dSjacobs PSTATUS *
new_pstatus(PRINTER * p)2490a44ef6dSjacobs new_pstatus(PRINTER *p)
2500a44ef6dSjacobs {
2510a44ef6dSjacobs PSTATUS *result = calloc(1, sizeof (*result));
252*55fea89dSDan Cross
2530a44ef6dSjacobs if (result != NULL) {
2540a44ef6dSjacobs static int i = 0;
2550a44ef6dSjacobs char **paperDenied = NULL;
2560a44ef6dSjacobs
2570a44ef6dSjacobs result->alert = new_alert("A-%d", i++);
2580a44ef6dSjacobs result->alert->exec = new_exec(EX_ALERT, result);
2590a44ef6dSjacobs result->exec = new_exec(EX_INTERF, result);
2600a44ef6dSjacobs result->fault_exec = new_exec(EX_FAULT_MESSAGE, result);
2610a44ef6dSjacobs
2620a44ef6dSjacobs if (p != NULL)
2630a44ef6dSjacobs pstatus_add_printer(result, p);
2640a44ef6dSjacobs
2650a44ef6dSjacobs list_append((void ***)&PStatus, (void *)result);
2660a44ef6dSjacobs }
2670a44ef6dSjacobs
2680a44ef6dSjacobs return (result);
2690a44ef6dSjacobs }
2700a44ef6dSjacobs
2710a44ef6dSjacobs void
free_cstatus(CLSTATUS * csp)27219d32b9aSRobert Mustacchi free_cstatus(CLSTATUS *csp)
2730a44ef6dSjacobs {
2740a44ef6dSjacobs if (csp != NULL) {
2750a44ef6dSjacobs if (csp->rej_reason != NULL)
2760a44ef6dSjacobs free(csp->rej_reason);
2770a44ef6dSjacobs if (csp->class != NULL)
2780a44ef6dSjacobs freeclass(csp->class);
2790a44ef6dSjacobs free(csp);
2800a44ef6dSjacobs }
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
28319d32b9aSRobert Mustacchi CLSTATUS *
new_cstatus(CLASS * c)2840a44ef6dSjacobs new_cstatus(CLASS *c)
2857c478bd9Sstevel@tonic-gate {
28619d32b9aSRobert Mustacchi CLSTATUS *result = calloc(1, sizeof (*result));
287*55fea89dSDan Cross
2880a44ef6dSjacobs if (result != NULL) {
2890a44ef6dSjacobs if (c != NULL)
2900a44ef6dSjacobs result->class = c;
2910a44ef6dSjacobs else
2920a44ef6dSjacobs result->class = calloc(1, sizeof (CLASS));
2937c478bd9Sstevel@tonic-gate
2940a44ef6dSjacobs list_append((void ***)&CStatus, result);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2970a44ef6dSjacobs return (result);
2980a44ef6dSjacobs }
2997c478bd9Sstevel@tonic-gate
3000a44ef6dSjacobs void
free_fstatus(FSTATUS * fsp)3010a44ef6dSjacobs free_fstatus(FSTATUS *fsp)
3020a44ef6dSjacobs {
3030a44ef6dSjacobs if (fsp != NULL) {
3040a44ef6dSjacobs if (fsp->form != NULL)
3050a44ef6dSjacobs free_form(fsp->form);
3060a44ef6dSjacobs if (fsp->alert != NULL)
3070a44ef6dSjacobs free_alert(fsp->alert);
3080a44ef6dSjacobs if (fsp->users_allowed != NULL)
3090a44ef6dSjacobs unload_list(&fsp->users_allowed);
3100a44ef6dSjacobs if (fsp->users_denied != NULL)
3110a44ef6dSjacobs unload_list(&fsp->users_denied);
3120a44ef6dSjacobs if (fsp->cpi != NULL)
3130a44ef6dSjacobs free(fsp->cpi);
3140a44ef6dSjacobs if (fsp->lpi != NULL)
3150a44ef6dSjacobs free(fsp->lpi);
3160a44ef6dSjacobs if (fsp->plen != NULL)
3170a44ef6dSjacobs free(fsp->plen);
3180a44ef6dSjacobs if (fsp->pwid != NULL)
3190a44ef6dSjacobs free(fsp->pwid);
3200a44ef6dSjacobs free(fsp);
3210a44ef6dSjacobs }
3220a44ef6dSjacobs }
3230a44ef6dSjacobs
3240a44ef6dSjacobs FSTATUS *
new_fstatus(_FORM * f)3250a44ef6dSjacobs new_fstatus(_FORM *f)
3260a44ef6dSjacobs {
3270a44ef6dSjacobs FSTATUS *result = calloc(1, sizeof (*result));
328*55fea89dSDan Cross
3290a44ef6dSjacobs if (result != NULL) {
3300a44ef6dSjacobs static int i = 0;
3310a44ef6dSjacobs
3320a44ef6dSjacobs if (f != NULL)
3330a44ef6dSjacobs result->form = f;
3340a44ef6dSjacobs else
3350a44ef6dSjacobs result->form = calloc(1, sizeof (_FORM));
3360a44ef6dSjacobs
3370a44ef6dSjacobs result->alert = new_alert("F-%d", i++);
3380a44ef6dSjacobs result->alert->exec = new_exec(EX_FALERT, result);
3390a44ef6dSjacobs result->trigger = result->form->alert.Q;
3400a44ef6dSjacobs
341*55fea89dSDan Cross if (f != NULL) {
3420a44ef6dSjacobs load_userform_access(f->name, &(result->users_allowed),
3430a44ef6dSjacobs &(result->users_denied));
3440a44ef6dSjacobs load_sdn (&(result->cpi), f->cpi);
3450a44ef6dSjacobs load_sdn (&(result->lpi), f->lpi);
3460a44ef6dSjacobs load_sdn (&(result->plen), f->plen);
3470a44ef6dSjacobs load_sdn (&(result->pwid), f->pwid);
3480a44ef6dSjacobs }
3490a44ef6dSjacobs
3500a44ef6dSjacobs list_append((void ***)&FStatus, (void *)result);
3510a44ef6dSjacobs }
3520a44ef6dSjacobs
3530a44ef6dSjacobs return (result);
3540a44ef6dSjacobs }
3550a44ef6dSjacobs
3560a44ef6dSjacobs void
free_pwstatus(PWSTATUS * pwp)3570a44ef6dSjacobs free_pwstatus(PWSTATUS *pwp)
3580a44ef6dSjacobs {
3590a44ef6dSjacobs if (pwp != NULL) {
3600a44ef6dSjacobs if (pwp->pwheel)
3610a44ef6dSjacobs freepwheel(pwp->pwheel);
3620a44ef6dSjacobs if (pwp->alert != NULL)
3630a44ef6dSjacobs free_alert(pwp->alert);
3640a44ef6dSjacobs free(pwp);
3650a44ef6dSjacobs }
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate PWSTATUS *
new_pwstatus(PWHEEL * p)3690a44ef6dSjacobs new_pwstatus(PWHEEL *p)
3707c478bd9Sstevel@tonic-gate {
3710a44ef6dSjacobs PWSTATUS *result = calloc(1, sizeof (*result));
3720a44ef6dSjacobs
3730a44ef6dSjacobs if (result != NULL) {
3740a44ef6dSjacobs static int i = 0;
3757c478bd9Sstevel@tonic-gate
3760a44ef6dSjacobs if (p != NULL)
377*55fea89dSDan Cross result->pwheel = p;
3780a44ef6dSjacobs else
3790a44ef6dSjacobs result->pwheel = calloc(1, sizeof (*result));
380*55fea89dSDan Cross
3810a44ef6dSjacobs result->alert = new_alert("P-%d", i++);
3820a44ef6dSjacobs result->alert->exec = new_exec(EX_PALERT, result);
3830a44ef6dSjacobs result->trigger = result->pwheel->alert.Q;
3840a44ef6dSjacobs
3850a44ef6dSjacobs list_append((void ***)&PWStatus, (void *)result);
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate
3880a44ef6dSjacobs return (result);
3890a44ef6dSjacobs }
3907c478bd9Sstevel@tonic-gate
3910a44ef6dSjacobs void
free_rstatus(RSTATUS * rsp)3920a44ef6dSjacobs free_rstatus(RSTATUS *rsp)
3930a44ef6dSjacobs {
3940a44ef6dSjacobs if (rsp != NULL) {
3950a44ef6dSjacobs remover(rsp);
3960a44ef6dSjacobs
3970a44ef6dSjacobs if (rsp->request != NULL)
3980a44ef6dSjacobs freerequest(rsp->request);
3990a44ef6dSjacobs if (rsp->secure != NULL)
4000a44ef6dSjacobs freesecure(rsp->secure);
4010a44ef6dSjacobs if (rsp->req_file)
4020a44ef6dSjacobs Free (rsp->req_file);
4030a44ef6dSjacobs if (rsp->slow)
4040a44ef6dSjacobs Free (rsp->slow);
4050a44ef6dSjacobs if (rsp->fast)
4060a44ef6dSjacobs Free (rsp->fast);
4070a44ef6dSjacobs if (rsp->pwheel_name)
4080a44ef6dSjacobs Free (rsp->pwheel_name);
4090a44ef6dSjacobs if (rsp->printer_type)
4100a44ef6dSjacobs Free (rsp->printer_type);
4110a44ef6dSjacobs if (rsp->output_type)
4120a44ef6dSjacobs Free (rsp->output_type);
4130a44ef6dSjacobs if (rsp->cpi)
4140a44ef6dSjacobs Free (rsp->cpi);
4150a44ef6dSjacobs if (rsp->lpi)
4160a44ef6dSjacobs Free (rsp->lpi);
4170a44ef6dSjacobs if (rsp->plen)
4180a44ef6dSjacobs Free (rsp->plen);
4190a44ef6dSjacobs if (rsp->pwid)
4200a44ef6dSjacobs Free (rsp->pwid);
4210a44ef6dSjacobs free(rsp);
4220a44ef6dSjacobs }
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate
4250a44ef6dSjacobs RSTATUS *
new_rstatus(REQUEST * r,SECURE * s)4260a44ef6dSjacobs new_rstatus(REQUEST *r, SECURE *s)
4270a44ef6dSjacobs {
4280a44ef6dSjacobs RSTATUS *result = calloc(1, sizeof (*result));
4290a44ef6dSjacobs
4300a44ef6dSjacobs if (result != NULL) {
4310a44ef6dSjacobs if ((result->request = r) == NULL)
4320a44ef6dSjacobs result->request = calloc(1, sizeof (REQUEST));
4330a44ef6dSjacobs if ((result->secure = s) == NULL)
4340a44ef6dSjacobs result->secure = calloc(1, sizeof (SECURE));
4350a44ef6dSjacobs }
4360a44ef6dSjacobs
4370a44ef6dSjacobs return (result);
4380a44ef6dSjacobs }
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate /**
4410a44ef6dSjacobs ** search_pstatus() - SEARCH PRINTER TABLE
4420a44ef6dSjacobs ** search_fstatus() - SEARCH FORMS TABLE
4430a44ef6dSjacobs ** search_cstatus() - SEARCH CLASS TABLE
4440a44ef6dSjacobs ** search_pwstatus() - SEARCH PRINT WHEEL TABLE
4457c478bd9Sstevel@tonic-gate **/
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate PSTATUS *
search_pstatus(register char * name)4480a44ef6dSjacobs search_pstatus(register char *name)
449*55fea89dSDan Cross {
4500a44ef6dSjacobs PSTATUS *ps = NULL;
4517c478bd9Sstevel@tonic-gate
4520a44ef6dSjacobs if (name != NULL) {
4530a44ef6dSjacobs if (PStatus != NULL) {
4540a44ef6dSjacobs int i;
4557c478bd9Sstevel@tonic-gate
4560a44ef6dSjacobs for (i = 0; ((PStatus[i] != NULL) && (ps == NULL)); i++)
4570a44ef6dSjacobs if (SAME(PStatus[i]->printer->name, name))
4580a44ef6dSjacobs ps = PStatus[i];
4590a44ef6dSjacobs }
4600a44ef6dSjacobs } else
4610a44ef6dSjacobs ps = new_pstatus(NULL);
4627c478bd9Sstevel@tonic-gate
463*55fea89dSDan Cross return (ps);
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate FSTATUS *
search_fstatus(register char * name)4680a44ef6dSjacobs search_fstatus(register char *name)
469*55fea89dSDan Cross {
4700a44ef6dSjacobs FSTATUS *ps = NULL;
4717c478bd9Sstevel@tonic-gate
4720a44ef6dSjacobs if (name != NULL) {
4730a44ef6dSjacobs if (FStatus != NULL) {
4740a44ef6dSjacobs int i;
4757c478bd9Sstevel@tonic-gate
4760a44ef6dSjacobs for (i = 0; ((FStatus[i] != NULL) && (ps == NULL)); i++)
4770a44ef6dSjacobs if (SAME(FStatus[i]->form->name, name))
4780a44ef6dSjacobs ps = FStatus[i];
4790a44ef6dSjacobs }
4800a44ef6dSjacobs } else
4810a44ef6dSjacobs ps = new_fstatus(NULL);
4827c478bd9Sstevel@tonic-gate
483*55fea89dSDan Cross return (ps);
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate FSTATUS *
search_fptable(register char * paper)4877c478bd9Sstevel@tonic-gate search_fptable(register char *paper)
488*55fea89dSDan Cross {
4890a44ef6dSjacobs FSTATUS *ps = NULL;
4900a44ef6dSjacobs int i;
4910a44ef6dSjacobs
4920a44ef6dSjacobs if (FStatus != NULL) {
4930a44ef6dSjacobs for (i = 0; ((FStatus[i] != NULL) && (ps == NULL)); i++)
4940a44ef6dSjacobs if (SAME(FStatus[i]->form->paper, paper)) {
4950a44ef6dSjacobs if (ps->form->isDefault)
4960a44ef6dSjacobs ps = FStatus[i];
4970a44ef6dSjacobs }
4980a44ef6dSjacobs }
4997c478bd9Sstevel@tonic-gate
500*55fea89dSDan Cross return (ps);
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate
50319d32b9aSRobert Mustacchi CLSTATUS *
search_cstatus(register char * name)5040a44ef6dSjacobs search_cstatus(register char *name)
505*55fea89dSDan Cross {
50619d32b9aSRobert Mustacchi CLSTATUS *ps = NULL;
5077c478bd9Sstevel@tonic-gate
5080a44ef6dSjacobs if (name != NULL) {
5090a44ef6dSjacobs if (CStatus != NULL) {
5100a44ef6dSjacobs int i;
5117c478bd9Sstevel@tonic-gate
5120a44ef6dSjacobs for (i = 0; ((CStatus[i] != NULL) && (ps == NULL)); i++)
5130a44ef6dSjacobs if (SAME(CStatus[i]->class->name, name))
5140a44ef6dSjacobs ps = CStatus[i];
5150a44ef6dSjacobs }
5160a44ef6dSjacobs } else
5170a44ef6dSjacobs ps = new_cstatus(NULL);
5187c478bd9Sstevel@tonic-gate
519*55fea89dSDan Cross return (ps);
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate PWSTATUS *
search_pwstatus(register char * name)5230a44ef6dSjacobs search_pwstatus(register char *name)
524*55fea89dSDan Cross {
5250a44ef6dSjacobs PWSTATUS *ps = NULL;
5267c478bd9Sstevel@tonic-gate
5270a44ef6dSjacobs if (name != NULL) {
5280a44ef6dSjacobs if (PWStatus != NULL) {
5290a44ef6dSjacobs int i;
5307c478bd9Sstevel@tonic-gate
5310a44ef6dSjacobs for (i = 0; ((PWStatus[i] != NULL) && (ps == NULL)); i++)
5320a44ef6dSjacobs if (SAME(PWStatus[i]->pwheel->name, name))
5330a44ef6dSjacobs ps = PWStatus[i];
5340a44ef6dSjacobs }
5350a44ef6dSjacobs } else
5360a44ef6dSjacobs ps = new_pwstatus(NULL);
5377c478bd9Sstevel@tonic-gate
538*55fea89dSDan Cross return (ps);
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate /**
5437c478bd9Sstevel@tonic-gate ** load_str() - LOAD STRING WHERE ALLOC'D STRING MAY BE
5447c478bd9Sstevel@tonic-gate ** unload_str() - REMOVE POSSIBLE ALLOC'D STRING
5457c478bd9Sstevel@tonic-gate **/
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate void
load_str(char ** pdst,char * src)5487c478bd9Sstevel@tonic-gate load_str(char **pdst, char *src)
5497c478bd9Sstevel@tonic-gate {
5507c478bd9Sstevel@tonic-gate if (*pdst)
5517c478bd9Sstevel@tonic-gate Free (*pdst);
5527c478bd9Sstevel@tonic-gate *pdst = Strdup(src);
5537c478bd9Sstevel@tonic-gate return;
5547c478bd9Sstevel@tonic-gate }
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate void
unload_str(char ** pdst)5577c478bd9Sstevel@tonic-gate unload_str(char **pdst)
5587c478bd9Sstevel@tonic-gate {
5597c478bd9Sstevel@tonic-gate if (*pdst)
5607c478bd9Sstevel@tonic-gate Free (*pdst);
5617c478bd9Sstevel@tonic-gate *pdst = 0;
5627c478bd9Sstevel@tonic-gate return;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate /**
5667c478bd9Sstevel@tonic-gate ** unload_list() - REMOVE POSSIBLE ALLOC'D LIST
5677c478bd9Sstevel@tonic-gate **/
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate void
unload_list(char *** plist)5707c478bd9Sstevel@tonic-gate unload_list(char ***plist)
5717c478bd9Sstevel@tonic-gate {
5727c478bd9Sstevel@tonic-gate if (*plist)
5737c478bd9Sstevel@tonic-gate freelist (*plist);
5747c478bd9Sstevel@tonic-gate *plist = 0;
5757c478bd9Sstevel@tonic-gate return;
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /**
5797c478bd9Sstevel@tonic-gate ** load_sdn() - LOAD STRING WITH ASCII VERSION OF SCALED DECIMAL NUMBER
5807c478bd9Sstevel@tonic-gate **/
5817c478bd9Sstevel@tonic-gate
5827c478bd9Sstevel@tonic-gate void
load_sdn(char ** p,SCALED sdn)5837c478bd9Sstevel@tonic-gate load_sdn(char **p, SCALED sdn)
5847c478bd9Sstevel@tonic-gate {
5857c478bd9Sstevel@tonic-gate if (!p)
5867c478bd9Sstevel@tonic-gate return;
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate if (*p)
5897c478bd9Sstevel@tonic-gate Free (*p);
5907c478bd9Sstevel@tonic-gate *p = 0;
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate if (sdn.val <= 0 || 999999 < sdn.val)
5937c478bd9Sstevel@tonic-gate return;
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate *p = Malloc(sizeof("999999.999x"));
5967c478bd9Sstevel@tonic-gate sprintf (
5977c478bd9Sstevel@tonic-gate *p,
5987c478bd9Sstevel@tonic-gate "%.3f%s",
5997c478bd9Sstevel@tonic-gate sdn.val,
6007c478bd9Sstevel@tonic-gate (sdn.sc == 'c'? "c" : (sdn.sc == 'i'? "i" : ""))
6017c478bd9Sstevel@tonic-gate );
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate return;
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate /**
6077c478bd9Sstevel@tonic-gate ** Getform() - EASIER INTERFACE TO "getform()"
6087c478bd9Sstevel@tonic-gate **/
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate _FORM *
Getform(char * form)6117c478bd9Sstevel@tonic-gate Getform(char *form)
6127c478bd9Sstevel@tonic-gate {
6130a44ef6dSjacobs _FORM *_form;
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate FORM formbuf;
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate FALERT alertbuf;
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate int ret;
6207c478bd9Sstevel@tonic-gate
6217c478bd9Sstevel@tonic-gate
6227c478bd9Sstevel@tonic-gate while (
6237c478bd9Sstevel@tonic-gate (ret = getform(form, &formbuf, &alertbuf, (FILE **)0)) == -1
6247c478bd9Sstevel@tonic-gate && errno == EINTR
6257c478bd9Sstevel@tonic-gate )
6267c478bd9Sstevel@tonic-gate ;
6277c478bd9Sstevel@tonic-gate if (ret == -1)
6287c478bd9Sstevel@tonic-gate return (0);
6297c478bd9Sstevel@tonic-gate
6300a44ef6dSjacobs _form = calloc(1, sizeof (*_form));
6310a44ef6dSjacobs _form->plen = formbuf.plen;
6320a44ef6dSjacobs _form->pwid = formbuf.pwid;
6330a44ef6dSjacobs _form->lpi = formbuf.lpi;
6340a44ef6dSjacobs _form->cpi = formbuf.cpi;
6350a44ef6dSjacobs _form->np = formbuf.np;
6360a44ef6dSjacobs _form->chset = formbuf.chset;
6370a44ef6dSjacobs _form->mandatory = formbuf.mandatory;
6380a44ef6dSjacobs _form->rcolor = formbuf.rcolor;
6390a44ef6dSjacobs _form->comment = formbuf.comment;
6400a44ef6dSjacobs _form->conttype = formbuf.conttype;
6410a44ef6dSjacobs _form->name = formbuf.name;
6420a44ef6dSjacobs _form->paper = formbuf.paper;
6430a44ef6dSjacobs _form->isDefault = formbuf.isDefault;
6440a44ef6dSjacobs
6450a44ef6dSjacobs if ((_form->alert.shcmd = alertbuf.shcmd) != NULL) {
6460a44ef6dSjacobs _form->alert.Q = alertbuf.Q;
6470a44ef6dSjacobs _form->alert.W = alertbuf.W;
6487c478bd9Sstevel@tonic-gate } else {
6490a44ef6dSjacobs _form->alert.Q = 0;
6500a44ef6dSjacobs _form->alert.W = 0;
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate
6530a44ef6dSjacobs return (_form);
6547c478bd9Sstevel@tonic-gate }
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate /**
6577c478bd9Sstevel@tonic-gate ** Getprinter()
6587c478bd9Sstevel@tonic-gate ** Getrequest()
6597c478bd9Sstevel@tonic-gate ** Getuser()
6607c478bd9Sstevel@tonic-gate ** Getclass()
6617c478bd9Sstevel@tonic-gate ** Getpwheel()
6627c478bd9Sstevel@tonic-gate ** Getsecure()
6637c478bd9Sstevel@tonic-gate ** Loadfilters()
6647c478bd9Sstevel@tonic-gate **/
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate PRINTER *
Getprinter(char * name)6677c478bd9Sstevel@tonic-gate Getprinter(char *name)
6687c478bd9Sstevel@tonic-gate {
6697c478bd9Sstevel@tonic-gate register PRINTER *ret;
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate while (!(ret = getprinter(name)) && errno == EINTR)
6727c478bd9Sstevel@tonic-gate ;
6737c478bd9Sstevel@tonic-gate return (ret);
6747c478bd9Sstevel@tonic-gate }
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate REQUEST *
Getrequest(char * file)6777c478bd9Sstevel@tonic-gate Getrequest(char *file)
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate register REQUEST *ret;
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate while (!(ret = getrequest(file)) && errno == EINTR)
6827c478bd9Sstevel@tonic-gate ;
6837c478bd9Sstevel@tonic-gate return (ret);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate USER *
Getuser(char * name)6877c478bd9Sstevel@tonic-gate Getuser(char *name)
6887c478bd9Sstevel@tonic-gate {
6897c478bd9Sstevel@tonic-gate register USER *ret;
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate while (!(ret = getuser(name)) && errno == EINTR)
6927c478bd9Sstevel@tonic-gate ;
6937c478bd9Sstevel@tonic-gate return (ret);
6947c478bd9Sstevel@tonic-gate }
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate CLASS *
Getclass(char * name)6977c478bd9Sstevel@tonic-gate Getclass(char *name)
6987c478bd9Sstevel@tonic-gate {
6997c478bd9Sstevel@tonic-gate register CLASS *ret;
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate while (!(ret = getclass(name)) && errno == EINTR)
7027c478bd9Sstevel@tonic-gate ;
7037c478bd9Sstevel@tonic-gate return (ret);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate PWHEEL *
Getpwheel(char * name)7077c478bd9Sstevel@tonic-gate Getpwheel(char *name)
7087c478bd9Sstevel@tonic-gate {
7097c478bd9Sstevel@tonic-gate register PWHEEL *ret;
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate while (!(ret = getpwheel(name)) && errno == EINTR)
7127c478bd9Sstevel@tonic-gate ;
7137c478bd9Sstevel@tonic-gate return (ret);
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate SECURE *
Getsecure(char * file)7177c478bd9Sstevel@tonic-gate Getsecure(char *file)
7187c478bd9Sstevel@tonic-gate {
7197c478bd9Sstevel@tonic-gate register SECURE *ret;
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate while (!(ret = getsecure(file)) && errno == EINTR)
7227c478bd9Sstevel@tonic-gate ;
7237c478bd9Sstevel@tonic-gate return ((SECURE *) ret);
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate
7277c478bd9Sstevel@tonic-gate int
Loadfilters(char * file)7287c478bd9Sstevel@tonic-gate Loadfilters(char *file)
7297c478bd9Sstevel@tonic-gate {
7307c478bd9Sstevel@tonic-gate register int ret;
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate while ((ret = loadfilters(file)) == -1 && errno == EINTR)
7337c478bd9Sstevel@tonic-gate ;
7347c478bd9Sstevel@tonic-gate return (ret);
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate /**
7387c478bd9Sstevel@tonic-gate ** free_form() - FREE MEMORY ALLOCATED FOR _FORM STRUCTURE
7397c478bd9Sstevel@tonic-gate **/
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate void
free_form(register _FORM * pf)7427c478bd9Sstevel@tonic-gate free_form(register _FORM *pf)
7437c478bd9Sstevel@tonic-gate {
7447c478bd9Sstevel@tonic-gate if (!pf)
7457c478bd9Sstevel@tonic-gate return;
7467c478bd9Sstevel@tonic-gate if (pf->chset)
7477c478bd9Sstevel@tonic-gate Free (pf->chset);
7487c478bd9Sstevel@tonic-gate if (pf->rcolor)
7497c478bd9Sstevel@tonic-gate Free (pf->rcolor);
7507c478bd9Sstevel@tonic-gate if (pf->comment)
7517c478bd9Sstevel@tonic-gate Free (pf->comment);
7527c478bd9Sstevel@tonic-gate if (pf->conttype)
7537c478bd9Sstevel@tonic-gate Free (pf->conttype);
7547c478bd9Sstevel@tonic-gate if (pf->name)
7557c478bd9Sstevel@tonic-gate Free (pf->name);
7567c478bd9Sstevel@tonic-gate if (pf->paper)
7577c478bd9Sstevel@tonic-gate Free (pf->paper);
7587c478bd9Sstevel@tonic-gate pf->name = 0;
7597c478bd9Sstevel@tonic-gate if (pf->alert.shcmd)
7607c478bd9Sstevel@tonic-gate Free (pf->alert.shcmd);
7617c478bd9Sstevel@tonic-gate return;
7627c478bd9Sstevel@tonic-gate }
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate /**
7657c478bd9Sstevel@tonic-gate ** getreqno() - GET NUMBER PART OF REQUEST ID
7667c478bd9Sstevel@tonic-gate **/
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate char *
getreqno(char * req_id)7697c478bd9Sstevel@tonic-gate getreqno(char *req_id)
7707c478bd9Sstevel@tonic-gate {
7717c478bd9Sstevel@tonic-gate register char *cp;
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate
7747c478bd9Sstevel@tonic-gate if (!(cp = strrchr(req_id, '-')))
7757c478bd9Sstevel@tonic-gate cp = req_id;
7767c478bd9Sstevel@tonic-gate else
7777c478bd9Sstevel@tonic-gate cp++;
7787c478bd9Sstevel@tonic-gate return (cp);
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate /* Putsecure(): Insurance for writing out the secure request file.
7827c478bd9Sstevel@tonic-gate * input: char ptr to name of the request file,
7837c478bd9Sstevel@tonic-gate * ptr to the SECURE structure to be written.
7847c478bd9Sstevel@tonic-gate * ouput: 0 if successful, -1 otherwise.
7857c478bd9Sstevel@tonic-gate *
7867c478bd9Sstevel@tonic-gate * Description:
7877c478bd9Sstevel@tonic-gate * The normal call to putsecure() is woefully lacking.
7887c478bd9Sstevel@tonic-gate * The bottom line here is that there
7897c478bd9Sstevel@tonic-gate * is no way to make sure that the file has been written out
7907c478bd9Sstevel@tonic-gate * as expected. This can cause rude behaviour later on.
7917c478bd9Sstevel@tonic-gate *
7927c478bd9Sstevel@tonic-gate * This routine calls putsecure(), and then does a getsecure().
7937c478bd9Sstevel@tonic-gate * The results are compared to the original structure. If the
7947c478bd9Sstevel@tonic-gate * info obtained by getsecure() doesn't match, we retry a few
7957c478bd9Sstevel@tonic-gate * times before giving up (presumably something is very seriously
7967c478bd9Sstevel@tonic-gate * wrong at that point).
7977c478bd9Sstevel@tonic-gate */
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate int
Putsecure(char * file,SECURE * secbufp)8017c478bd9Sstevel@tonic-gate Putsecure(char *file, SECURE *secbufp)
8027c478bd9Sstevel@tonic-gate {
8037c478bd9Sstevel@tonic-gate SECURE *pls;
8047c478bd9Sstevel@tonic-gate int retries = 5; /* # of attempts */
8057c478bd9Sstevel@tonic-gate int status; /* 0 = success, nonzero otherwise */
8067c478bd9Sstevel@tonic-gate
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate while (retries--) {
8097c478bd9Sstevel@tonic-gate status = 1; /* assume the worst, hope for the best */
8107c478bd9Sstevel@tonic-gate if (putsecure(file, secbufp) == -1) {
8117c478bd9Sstevel@tonic-gate rmsecure(file);
8127c478bd9Sstevel@tonic-gate continue;
8137c478bd9Sstevel@tonic-gate }
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate if ((pls = getsecure(file)) == (SECURE *) NULL) {
8167c478bd9Sstevel@tonic-gate rmsecure(file);
8177c478bd9Sstevel@tonic-gate status = 2;
8187c478bd9Sstevel@tonic-gate continue;
8197c478bd9Sstevel@tonic-gate }
8207c478bd9Sstevel@tonic-gate
8217c478bd9Sstevel@tonic-gate /* now compare each field */
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate /*
8247c478bd9Sstevel@tonic-gate * A comparison is only valid if secbufp and pls point to
8257c478bd9Sstevel@tonic-gate * different locations. In reality getsecure() will have
8267c478bd9Sstevel@tonic-gate * already been called, allocating the same STATIC memory
8277c478bd9Sstevel@tonic-gate * location to both structures making the following compare
8287c478bd9Sstevel@tonic-gate * meaningless.
8297c478bd9Sstevel@tonic-gate * Therefore test for this condition to prevent us from
8300a44ef6dSjacobs * calling freesecure which will destroy uid and
8317c478bd9Sstevel@tonic-gate * req_id fields in the strucure
8327c478bd9Sstevel@tonic-gate */
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate status = 0;
8357c478bd9Sstevel@tonic-gate if (secbufp != pls) {
8367c478bd9Sstevel@tonic-gate if (strcmp(pls->req_id, secbufp->req_id) != 0) {
8377c478bd9Sstevel@tonic-gate rmsecure(file);
8387c478bd9Sstevel@tonic-gate status = 3;
8397c478bd9Sstevel@tonic-gate continue;
8407c478bd9Sstevel@tonic-gate }
8417c478bd9Sstevel@tonic-gate
8427c478bd9Sstevel@tonic-gate if (pls->uid != secbufp->uid) {
8437c478bd9Sstevel@tonic-gate rmsecure(file);
8447c478bd9Sstevel@tonic-gate status = 4;
8457c478bd9Sstevel@tonic-gate continue;
8467c478bd9Sstevel@tonic-gate }
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate if (strcmp(pls->user, secbufp->user) != 0) {
8497c478bd9Sstevel@tonic-gate rmsecure(file);
8507c478bd9Sstevel@tonic-gate status = 5;
8517c478bd9Sstevel@tonic-gate continue;
8527c478bd9Sstevel@tonic-gate }
8537c478bd9Sstevel@tonic-gate
8547c478bd9Sstevel@tonic-gate if (pls->gid != secbufp->gid) {
8557c478bd9Sstevel@tonic-gate rmsecure(file);
8567c478bd9Sstevel@tonic-gate status = 6;
8577c478bd9Sstevel@tonic-gate continue;
8587c478bd9Sstevel@tonic-gate }
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate if (pls->size != secbufp->size) {
8617c478bd9Sstevel@tonic-gate rmsecure(file);
8627c478bd9Sstevel@tonic-gate status = 7;
8637c478bd9Sstevel@tonic-gate continue;
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate if (pls->date != secbufp->date) {
8677c478bd9Sstevel@tonic-gate rmsecure(file);
8687c478bd9Sstevel@tonic-gate status = 8;
8697c478bd9Sstevel@tonic-gate continue;
8707c478bd9Sstevel@tonic-gate }
8717c478bd9Sstevel@tonic-gate
8727c478bd9Sstevel@tonic-gate freesecure(pls);
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate break;
8757c478bd9Sstevel@tonic-gate }
8767c478bd9Sstevel@tonic-gate
8777c478bd9Sstevel@tonic-gate if (status != 0) {
8787c478bd9Sstevel@tonic-gate note("Putsecure failed, status=%d\n", status);
8797c478bd9Sstevel@tonic-gate return -1;
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate return 0;
8837c478bd9Sstevel@tonic-gate }
8847c478bd9Sstevel@tonic-gate
GetRequestFiles(REQUEST * req,char * buffer,int length)8857c478bd9Sstevel@tonic-gate void GetRequestFiles(REQUEST *req, char *buffer, int length)
8867c478bd9Sstevel@tonic-gate {
8877c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate memset(buf, 0, sizeof(buf));
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate if (req->title) {
8927c478bd9Sstevel@tonic-gate char *r = req->title;
8937c478bd9Sstevel@tonic-gate char *ptr = buf;
8947c478bd9Sstevel@tonic-gate
8957c478bd9Sstevel@tonic-gate while ( *r && strncmp(r,"\\n",2)) {
8967c478bd9Sstevel@tonic-gate *ptr++ = *r++;
8977c478bd9Sstevel@tonic-gate }
8987c478bd9Sstevel@tonic-gate } else if (req->file_list)
8997c478bd9Sstevel@tonic-gate strlcpy(buf, *req->file_list, sizeof (buf));
900*55fea89dSDan Cross
901e4fb8a5fSToomas Soome if (*buf == '\0' || !strncmp(buf, SPOOLDIR, sizeof(SPOOLDIR)-1))
9027c478bd9Sstevel@tonic-gate strcpy(buf, "<File name not available>");
9037c478bd9Sstevel@tonic-gate
9047c478bd9Sstevel@tonic-gate if (strlen(buf) > (size_t) 24) {
9057c478bd9Sstevel@tonic-gate char *r;
9067c478bd9Sstevel@tonic-gate
9077c478bd9Sstevel@tonic-gate if (r = strrchr(buf, '/'))
9087c478bd9Sstevel@tonic-gate r++;
9097c478bd9Sstevel@tonic-gate else
9107c478bd9Sstevel@tonic-gate r = buf;
911*55fea89dSDan Cross
912*55fea89dSDan Cross snprintf(buffer, length, "%-.24s", r);
9137c478bd9Sstevel@tonic-gate } else
9147c478bd9Sstevel@tonic-gate strlcpy(buffer, buf, length);
9157c478bd9Sstevel@tonic-gate return;
9167c478bd9Sstevel@tonic-gate }
9177c478bd9Sstevel@tonic-gate
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate /**
9207c478bd9Sstevel@tonic-gate ** _Malloc()
9217c478bd9Sstevel@tonic-gate ** _Realloc()
9227c478bd9Sstevel@tonic-gate ** _Calloc()
9237c478bd9Sstevel@tonic-gate ** _Strdup()
9247c478bd9Sstevel@tonic-gate ** _Free()
9257c478bd9Sstevel@tonic-gate **/
9267c478bd9Sstevel@tonic-gate
9277c478bd9Sstevel@tonic-gate void (*lp_alloc_fail_handler)( void ) = 0;
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate typedef void *alloc_type;
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate alloc_type
_Malloc(size_t size,const char * file,int line)9327c478bd9Sstevel@tonic-gate _Malloc(size_t size, const char *file, int line)
9337c478bd9Sstevel@tonic-gate {
9347c478bd9Sstevel@tonic-gate alloc_type ret;
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gate ret = malloc(size);
9377c478bd9Sstevel@tonic-gate if (!ret) {
9387c478bd9Sstevel@tonic-gate if (lp_alloc_fail_handler)
9397c478bd9Sstevel@tonic-gate (*lp_alloc_fail_handler)();
9407c478bd9Sstevel@tonic-gate errno = ENOMEM;
9417c478bd9Sstevel@tonic-gate }
9427c478bd9Sstevel@tonic-gate return (ret);
9437c478bd9Sstevel@tonic-gate }
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate alloc_type
_Realloc(void * ptr,size_t size,const char * file,int line)9467c478bd9Sstevel@tonic-gate _Realloc(void *ptr, size_t size, const char *file, int line)
9477c478bd9Sstevel@tonic-gate {
9487c478bd9Sstevel@tonic-gate alloc_type ret = realloc(ptr, size);
9497c478bd9Sstevel@tonic-gate
9507c478bd9Sstevel@tonic-gate if (!ret) {
9517c478bd9Sstevel@tonic-gate if (lp_alloc_fail_handler)
9527c478bd9Sstevel@tonic-gate (*lp_alloc_fail_handler)();
9537c478bd9Sstevel@tonic-gate errno = ENOMEM;
9547c478bd9Sstevel@tonic-gate }
9557c478bd9Sstevel@tonic-gate return (ret);
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate alloc_type
_Calloc(size_t nelem,size_t elsize,const char * file,int line)9597c478bd9Sstevel@tonic-gate _Calloc(size_t nelem, size_t elsize, const char *file, int line)
9607c478bd9Sstevel@tonic-gate {
9617c478bd9Sstevel@tonic-gate alloc_type ret = calloc(nelem, elsize);
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate if (!ret) {
9647c478bd9Sstevel@tonic-gate if (lp_alloc_fail_handler)
9657c478bd9Sstevel@tonic-gate (*lp_alloc_fail_handler)();
9667c478bd9Sstevel@tonic-gate errno = ENOMEM;
9677c478bd9Sstevel@tonic-gate }
9687c478bd9Sstevel@tonic-gate return (ret);
9697c478bd9Sstevel@tonic-gate }
9707c478bd9Sstevel@tonic-gate
9717c478bd9Sstevel@tonic-gate char *
_Strdup(const char * s,const char * file,int line)9727c478bd9Sstevel@tonic-gate _Strdup(const char *s, const char *file, int line)
9737c478bd9Sstevel@tonic-gate {
9747c478bd9Sstevel@tonic-gate char * ret;
9757c478bd9Sstevel@tonic-gate
9767c478bd9Sstevel@tonic-gate if (!s)
9777c478bd9Sstevel@tonic-gate return( (char *) 0);
9787c478bd9Sstevel@tonic-gate
9797c478bd9Sstevel@tonic-gate ret = strdup(s);
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate if (!ret) {
9827c478bd9Sstevel@tonic-gate if (lp_alloc_fail_handler)
9837c478bd9Sstevel@tonic-gate (*lp_alloc_fail_handler)();
9847c478bd9Sstevel@tonic-gate errno = ENOMEM;
9857c478bd9Sstevel@tonic-gate }
9867c478bd9Sstevel@tonic-gate return (ret);
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate
9897c478bd9Sstevel@tonic-gate void
_Free(void * ptr,const char * file,int line)9907c478bd9Sstevel@tonic-gate _Free(void *ptr, const char *file, int line)
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate free (ptr);
9937c478bd9Sstevel@tonic-gate return;
9947c478bd9Sstevel@tonic-gate }
995