Print this page
5218 posix definition of NULL
correct unistd.h and iso/stddef_iso.h
update gate source affected
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/lp/cmd/lpsched/fncs.c
+++ new/usr/src/cmd/lp/cmd/lpsched/fncs.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
31 31
32 32 #include "unistd.h"
33 33 #include "sys/types.h"
34 34 #include "sys/stat.h"
35 35 #include "errno.h"
36 36 #include "fcntl.h"
37 37 #include "stdlib.h"
38 38 #include "string.h"
39 39
40 40 #include "lpsched.h"
41 41
42 42 static int __list_increment = 16;
43 43
44 44 int
45 45 list_append(void ***list, void *item)
46 46 {
47 47 int count;
48 48
49 49 if ((list == NULL) || (item == NULL)) {
50 50 errno = EINVAL;
51 51 return (-1);
52 52 }
53 53
54 54 if (item != NULL) {
55 55 if (*list == NULL)
56 56 *list = (void **)calloc(__list_increment,
57 57 sizeof (void *));
58 58
59 59 if (*list == NULL)
60 60 return (-1);
61 61
62 62 for (count = 0; (*list)[count] != NULL; count++);
63 63
64 64 if ((count + 1) % __list_increment == 0) { /* expand the list */ void **new_list = NULL;
65 65 int new_size = (((count + 1) / __list_increment) + 1) *
66 66 __list_increment;
67 67
68 68 new_list = (void **)calloc(new_size, sizeof (void *));
69 69 if (new_list == NULL)
70 70 return (-1);
71 71
72 72 for (count = 0; (*list)[count] != NULL; count++)
73 73 new_list[count] = (*list)[count];
74 74 free(*list);
75 75 *list = new_list;
76 76 }
77 77
78 78 (*list)[count] = item;
79 79 }
80 80
81 81 return (0);
82 82 }
83 83
84 84 void
85 85 list_remove(void ***list, void *item)
86 86 {
87 87 int i, count;
88 88 void **tmp = NULL;
89 89
90 90 if ((list == NULL) || (*list == NULL) || (item == NULL))
91 91 return;
92 92
93 93 for (count = 0; (*list)[count] != NULL; count++)
94 94 ;
95 95
96 96 if (count > 0) {
97 97 int new_size = (((count + 1) / __list_increment) + 1) *
98 98 __list_increment;
99 99
100 100 if ((tmp = (void **)calloc(new_size, sizeof (void *))) == NULL)
101 101 tmp = *list;
102 102
103 103 /* copy up to item */
104 104 for (i = 0; (((*list)[i] != NULL) && ((*list)[i] != item)); i++)
105 105 tmp[i] = (*list)[i];
106 106 /* copy after item */
107 107 if ((*list)[i] == item)
108 108 for (++i; ((*list)[i] != NULL); i++)
109 109 tmp[i-1] = (*list)[i];
110 110 }
111 111
112 112 /* replace the list */
113 113 if (tmp != *list) {
114 114 free(*list);
115 115 *list = tmp;
116 116 }
117 117 }
118 118
119 119 void
120 120 free_exec(EXEC *ep)
121 121 {
122 122 if (ep != NULL) {
123 123 free(ep);
124 124 list_remove((void ***)&Exec_Table, (void *)ep);
125 125 }
126 126 }
127 127
128 128 EXEC *
129 129 new_exec(int type, void *ex)
130 130 {
131 131 EXEC *result = calloc(1, sizeof (*result));
132 132
133 133 if (result != NULL) {
134 134 result->type = type;
135 135 switch (type) {
136 136 case EX_ALERT:
137 137 case EX_INTERF:
138 138 case EX_FAULT_MESSAGE:
139 139 result->ex.printer = ex;
140 140 break;
141 141 case EX_FALERT:
142 142 result->ex.form = ex;
143 143 break;
144 144 case EX_PALERT:
145 145 result->ex.pwheel = ex;
146 146 break;
147 147 case EX_SLOWF:
148 148 case EX_NOTIFY:
149 149 break;
150 150 }
151 151 list_append((void ***)&Exec_Table, (void *)result);
152 152 }
153 153
154 154 return (result);
155 155 }
156 156
157 157 void
158 158 free_alert(ALERT *ap)
159 159 {
160 160 if (ap != NULL) {
161 161 if (ap->msgfile != NULL)
162 162 free(ap->msgfile);
163 163 if (ap->exec != NULL)
164 164 free_exec(ap->exec);
165 165 free(ap);
166 166 }
167 167 }
168 168
169 169 ALERT *
170 170 new_alert(char *fmt, int i)
171 171 {
172 172 ALERT *result = calloc(1, sizeof (*result));
173 173
174 174 if (result != NULL) {
175 175 char buf[15];
176 176
177 177 snprintf(buf, sizeof (buf), fmt, i);
178 178 result->msgfile = makepath(Lp_Temp, buf, (char *)0);
179 179 (void) Unlink(result->msgfile);
180 180 }
181 181
182 182 return (result);
183 183 }
184 184
185 185 void
186 186 free_pstatus(PSTATUS *psp)
187 187 {
188 188 if (psp != NULL) {
189 189 if (psp->alert != NULL)
190 190 free_alert(psp->alert);
191 191 if (psp->exec != NULL)
192 192 free_exec(psp->exec);
193 193 if (psp->fault_exec != NULL)
194 194 free_exec(psp->fault_exec);
195 195 if (psp->printer != NULL)
196 196 freeprinter(psp->printer);
197 197 if (psp->pwheel_name != NULL)
198 198 free(psp->pwheel_name);
199 199 if (psp->dis_reason != NULL)
200 200 free(psp->dis_reason);
201 201 if (psp->rej_reason != NULL)
202 202 free(psp->rej_reason);
203 203 if (psp->users_allowed != NULL)
204 204 unload_list(&psp->users_allowed);
205 205 if (psp->users_denied != NULL)
206 206 unload_list(&psp->users_denied);
207 207 if (psp->forms_allowed != NULL)
208 208 unload_list(&psp->forms_allowed);
209 209 if (psp->forms_denied != NULL)
210 210 unload_list(&psp->forms_denied);
211 211 if (psp->cpi != NULL)
212 212 free(psp->cpi);
213 213 if (psp->lpi != NULL)
214 214 free(psp->lpi);
215 215 if (psp->plen != NULL)
216 216 free(psp->plen);
217 217 if (psp->pwid != NULL)
218 218 free(psp->pwid);
219 219 if (psp->fault_reason != NULL)
220 220 free(psp->fault_reason);
221 221 if (psp->paper_allowed != NULL)
222 222 unload_list(&psp->paper_allowed);
223 223 free(psp);
224 224 }
225 225 }
226 226
227 227 void
228 228 pstatus_add_printer(PSTATUS *ps, PRINTER *p)
229 229 {
230 230 if ((ps != NULL) && (p != NULL)) {
231 231 char **paperDenied = NULL;
232 232
233 233 ps->printer = p;
234 234 load_userprinter_access(p->name, &(ps->users_allowed),
235 235 &(ps->users_denied));
236 236 load_formprinter_access(p->name, &(ps->forms_allowed),
237 237 &(ps->forms_denied));
238 238 load_paperprinter_access(p->name, &ps->paper_allowed,
239 239 &paperDenied);
240 240 freelist(paperDenied);
241 241 load_sdn(&(ps->cpi), p->cpi);
242 242 load_sdn(&(ps->lpi), p->lpi);
243 243 load_sdn(&(ps->plen), p->plen);
244 244 load_sdn(&(ps->pwid), p->pwid);
245 245 }
246 246 }
247 247
248 248 PSTATUS *
249 249 new_pstatus(PRINTER *p)
250 250 {
251 251 PSTATUS *result = calloc(1, sizeof (*result));
252 252
253 253 if (result != NULL) {
254 254 static int i = 0;
255 255 char **paperDenied = NULL;
256 256
257 257 result->alert = new_alert("A-%d", i++);
258 258 result->alert->exec = new_exec(EX_ALERT, result);
259 259 result->exec = new_exec(EX_INTERF, result);
260 260 result->fault_exec = new_exec(EX_FAULT_MESSAGE, result);
261 261
262 262 if (p != NULL)
263 263 pstatus_add_printer(result, p);
264 264
265 265 list_append((void ***)&PStatus, (void *)result);
266 266 }
267 267
268 268 return (result);
269 269 }
270 270
271 271 void
272 272 free_cstatus(CLSTATUS *csp)
273 273 {
274 274 if (csp != NULL) {
275 275 if (csp->rej_reason != NULL)
276 276 free(csp->rej_reason);
277 277 if (csp->class != NULL)
278 278 freeclass(csp->class);
279 279 free(csp);
280 280 }
281 281 }
282 282
283 283 CLSTATUS *
284 284 new_cstatus(CLASS *c)
285 285 {
286 286 CLSTATUS *result = calloc(1, sizeof (*result));
287 287
288 288 if (result != NULL) {
289 289 if (c != NULL)
290 290 result->class = c;
291 291 else
292 292 result->class = calloc(1, sizeof (CLASS));
293 293
294 294 list_append((void ***)&CStatus, result);
295 295 }
296 296
297 297 return (result);
298 298 }
299 299
300 300 void
301 301 free_fstatus(FSTATUS *fsp)
302 302 {
303 303 if (fsp != NULL) {
304 304 if (fsp->form != NULL)
305 305 free_form(fsp->form);
306 306 if (fsp->alert != NULL)
307 307 free_alert(fsp->alert);
308 308 if (fsp->users_allowed != NULL)
309 309 unload_list(&fsp->users_allowed);
310 310 if (fsp->users_denied != NULL)
311 311 unload_list(&fsp->users_denied);
312 312 if (fsp->cpi != NULL)
313 313 free(fsp->cpi);
314 314 if (fsp->lpi != NULL)
315 315 free(fsp->lpi);
316 316 if (fsp->plen != NULL)
317 317 free(fsp->plen);
318 318 if (fsp->pwid != NULL)
319 319 free(fsp->pwid);
320 320 free(fsp);
321 321 }
322 322 }
323 323
324 324 FSTATUS *
325 325 new_fstatus(_FORM *f)
326 326 {
327 327 FSTATUS *result = calloc(1, sizeof (*result));
328 328
329 329 if (result != NULL) {
330 330 static int i = 0;
331 331
332 332 if (f != NULL)
333 333 result->form = f;
334 334 else
335 335 result->form = calloc(1, sizeof (_FORM));
336 336
337 337 result->alert = new_alert("F-%d", i++);
338 338 result->alert->exec = new_exec(EX_FALERT, result);
339 339 result->trigger = result->form->alert.Q;
340 340
341 341 if (f != NULL) {
342 342 load_userform_access(f->name, &(result->users_allowed),
343 343 &(result->users_denied));
344 344 load_sdn (&(result->cpi), f->cpi);
345 345 load_sdn (&(result->lpi), f->lpi);
346 346 load_sdn (&(result->plen), f->plen);
347 347 load_sdn (&(result->pwid), f->pwid);
348 348 }
349 349
350 350 list_append((void ***)&FStatus, (void *)result);
351 351 }
352 352
353 353 return (result);
354 354 }
355 355
356 356 void
357 357 free_pwstatus(PWSTATUS *pwp)
358 358 {
359 359 if (pwp != NULL) {
360 360 if (pwp->pwheel)
361 361 freepwheel(pwp->pwheel);
362 362 if (pwp->alert != NULL)
363 363 free_alert(pwp->alert);
364 364 free(pwp);
365 365 }
366 366 }
367 367
368 368 PWSTATUS *
369 369 new_pwstatus(PWHEEL *p)
370 370 {
371 371 PWSTATUS *result = calloc(1, sizeof (*result));
372 372
373 373 if (result != NULL) {
374 374 static int i = 0;
375 375
376 376 if (p != NULL)
377 377 result->pwheel = p;
378 378 else
379 379 result->pwheel = calloc(1, sizeof (*result));
380 380
381 381 result->alert = new_alert("P-%d", i++);
382 382 result->alert->exec = new_exec(EX_PALERT, result);
383 383 result->trigger = result->pwheel->alert.Q;
384 384
385 385 list_append((void ***)&PWStatus, (void *)result);
386 386 }
387 387
388 388 return (result);
389 389 }
390 390
391 391 void
392 392 free_rstatus(RSTATUS *rsp)
393 393 {
394 394 if (rsp != NULL) {
395 395 remover(rsp);
396 396
397 397 if (rsp->request != NULL)
398 398 freerequest(rsp->request);
399 399 if (rsp->secure != NULL)
400 400 freesecure(rsp->secure);
401 401 if (rsp->req_file)
402 402 Free (rsp->req_file);
403 403 if (rsp->slow)
404 404 Free (rsp->slow);
405 405 if (rsp->fast)
406 406 Free (rsp->fast);
407 407 if (rsp->pwheel_name)
408 408 Free (rsp->pwheel_name);
409 409 if (rsp->printer_type)
410 410 Free (rsp->printer_type);
411 411 if (rsp->output_type)
412 412 Free (rsp->output_type);
413 413 if (rsp->cpi)
414 414 Free (rsp->cpi);
415 415 if (rsp->lpi)
416 416 Free (rsp->lpi);
417 417 if (rsp->plen)
418 418 Free (rsp->plen);
419 419 if (rsp->pwid)
420 420 Free (rsp->pwid);
421 421 free(rsp);
422 422 }
423 423 }
424 424
425 425 RSTATUS *
426 426 new_rstatus(REQUEST *r, SECURE *s)
427 427 {
428 428 RSTATUS *result = calloc(1, sizeof (*result));
429 429
430 430 if (result != NULL) {
431 431 if ((result->request = r) == NULL)
432 432 result->request = calloc(1, sizeof (REQUEST));
433 433 if ((result->secure = s) == NULL)
434 434 result->secure = calloc(1, sizeof (SECURE));
435 435 }
436 436
437 437 return (result);
438 438 }
439 439
440 440 /**
441 441 ** search_pstatus() - SEARCH PRINTER TABLE
442 442 ** search_fstatus() - SEARCH FORMS TABLE
443 443 ** search_cstatus() - SEARCH CLASS TABLE
444 444 ** search_pwstatus() - SEARCH PRINT WHEEL TABLE
445 445 **/
446 446
447 447 PSTATUS *
448 448 search_pstatus(register char *name)
449 449 {
450 450 PSTATUS *ps = NULL;
451 451
452 452 if (name != NULL) {
453 453 if (PStatus != NULL) {
454 454 int i;
455 455
456 456 for (i = 0; ((PStatus[i] != NULL) && (ps == NULL)); i++)
457 457 if (SAME(PStatus[i]->printer->name, name))
458 458 ps = PStatus[i];
459 459 }
460 460 } else
461 461 ps = new_pstatus(NULL);
462 462
463 463 return (ps);
464 464 }
465 465
466 466
467 467 FSTATUS *
468 468 search_fstatus(register char *name)
469 469 {
470 470 FSTATUS *ps = NULL;
471 471
472 472 if (name != NULL) {
473 473 if (FStatus != NULL) {
474 474 int i;
475 475
476 476 for (i = 0; ((FStatus[i] != NULL) && (ps == NULL)); i++)
477 477 if (SAME(FStatus[i]->form->name, name))
478 478 ps = FStatus[i];
479 479 }
480 480 } else
481 481 ps = new_fstatus(NULL);
482 482
483 483 return (ps);
484 484 }
485 485
486 486 FSTATUS *
487 487 search_fptable(register char *paper)
488 488 {
489 489 FSTATUS *ps = NULL;
490 490 int i;
491 491
492 492 if (FStatus != NULL) {
493 493 for (i = 0; ((FStatus[i] != NULL) && (ps == NULL)); i++)
494 494 if (SAME(FStatus[i]->form->paper, paper)) {
495 495 if (ps->form->isDefault)
496 496 ps = FStatus[i];
497 497 }
498 498 }
499 499
500 500 return (ps);
501 501 }
502 502
503 503 CLSTATUS *
504 504 search_cstatus(register char *name)
505 505 {
506 506 CLSTATUS *ps = NULL;
507 507
508 508 if (name != NULL) {
509 509 if (CStatus != NULL) {
510 510 int i;
511 511
512 512 for (i = 0; ((CStatus[i] != NULL) && (ps == NULL)); i++)
513 513 if (SAME(CStatus[i]->class->name, name))
514 514 ps = CStatus[i];
515 515 }
516 516 } else
517 517 ps = new_cstatus(NULL);
518 518
519 519 return (ps);
520 520 }
521 521
522 522 PWSTATUS *
523 523 search_pwstatus(register char *name)
524 524 {
525 525 PWSTATUS *ps = NULL;
526 526
527 527 if (name != NULL) {
528 528 if (PWStatus != NULL) {
529 529 int i;
530 530
531 531 for (i = 0; ((PWStatus[i] != NULL) && (ps == NULL)); i++)
532 532 if (SAME(PWStatus[i]->pwheel->name, name))
533 533 ps = PWStatus[i];
534 534 }
535 535 } else
536 536 ps = new_pwstatus(NULL);
537 537
538 538 return (ps);
539 539 }
540 540
541 541
542 542 /**
543 543 ** load_str() - LOAD STRING WHERE ALLOC'D STRING MAY BE
544 544 ** unload_str() - REMOVE POSSIBLE ALLOC'D STRING
545 545 **/
546 546
547 547 void
548 548 load_str(char **pdst, char *src)
549 549 {
550 550 if (*pdst)
551 551 Free (*pdst);
552 552 *pdst = Strdup(src);
553 553 return;
554 554 }
555 555
556 556 void
557 557 unload_str(char **pdst)
558 558 {
559 559 if (*pdst)
560 560 Free (*pdst);
561 561 *pdst = 0;
562 562 return;
563 563 }
564 564
565 565 /**
566 566 ** unload_list() - REMOVE POSSIBLE ALLOC'D LIST
567 567 **/
568 568
569 569 void
570 570 unload_list(char ***plist)
571 571 {
572 572 if (*plist)
573 573 freelist (*plist);
574 574 *plist = 0;
575 575 return;
576 576 }
577 577
578 578 /**
579 579 ** load_sdn() - LOAD STRING WITH ASCII VERSION OF SCALED DECIMAL NUMBER
580 580 **/
581 581
582 582 void
583 583 load_sdn(char **p, SCALED sdn)
584 584 {
585 585 if (!p)
586 586 return;
587 587
588 588 if (*p)
589 589 Free (*p);
590 590 *p = 0;
591 591
592 592 if (sdn.val <= 0 || 999999 < sdn.val)
593 593 return;
594 594
595 595 *p = Malloc(sizeof("999999.999x"));
596 596 sprintf (
597 597 *p,
598 598 "%.3f%s",
599 599 sdn.val,
600 600 (sdn.sc == 'c'? "c" : (sdn.sc == 'i'? "i" : ""))
601 601 );
602 602
603 603 return;
604 604 }
605 605
606 606 /**
607 607 ** Getform() - EASIER INTERFACE TO "getform()"
608 608 **/
609 609
610 610 _FORM *
611 611 Getform(char *form)
612 612 {
613 613 _FORM *_form;
614 614
615 615 FORM formbuf;
616 616
617 617 FALERT alertbuf;
618 618
619 619 int ret;
620 620
621 621
622 622 while (
623 623 (ret = getform(form, &formbuf, &alertbuf, (FILE **)0)) == -1
624 624 && errno == EINTR
625 625 )
626 626 ;
627 627 if (ret == -1)
628 628 return (0);
629 629
630 630 _form = calloc(1, sizeof (*_form));
631 631 _form->plen = formbuf.plen;
632 632 _form->pwid = formbuf.pwid;
633 633 _form->lpi = formbuf.lpi;
634 634 _form->cpi = formbuf.cpi;
635 635 _form->np = formbuf.np;
636 636 _form->chset = formbuf.chset;
637 637 _form->mandatory = formbuf.mandatory;
638 638 _form->rcolor = formbuf.rcolor;
639 639 _form->comment = formbuf.comment;
640 640 _form->conttype = formbuf.conttype;
641 641 _form->name = formbuf.name;
642 642 _form->paper = formbuf.paper;
643 643 _form->isDefault = formbuf.isDefault;
644 644
645 645 if ((_form->alert.shcmd = alertbuf.shcmd) != NULL) {
646 646 _form->alert.Q = alertbuf.Q;
647 647 _form->alert.W = alertbuf.W;
648 648 } else {
649 649 _form->alert.Q = 0;
650 650 _form->alert.W = 0;
651 651 }
652 652
653 653 return (_form);
654 654 }
655 655
656 656 /**
657 657 ** Getprinter()
658 658 ** Getrequest()
659 659 ** Getuser()
660 660 ** Getclass()
661 661 ** Getpwheel()
662 662 ** Getsecure()
663 663 ** Loadfilters()
664 664 **/
665 665
666 666 PRINTER *
667 667 Getprinter(char *name)
668 668 {
669 669 register PRINTER *ret;
670 670
671 671 while (!(ret = getprinter(name)) && errno == EINTR)
672 672 ;
673 673 return (ret);
674 674 }
675 675
676 676 REQUEST *
677 677 Getrequest(char *file)
678 678 {
679 679 register REQUEST *ret;
680 680
681 681 while (!(ret = getrequest(file)) && errno == EINTR)
682 682 ;
683 683 return (ret);
684 684 }
685 685
686 686 USER *
687 687 Getuser(char *name)
688 688 {
689 689 register USER *ret;
690 690
691 691 while (!(ret = getuser(name)) && errno == EINTR)
692 692 ;
693 693 return (ret);
694 694 }
695 695
696 696 CLASS *
697 697 Getclass(char *name)
698 698 {
699 699 register CLASS *ret;
700 700
701 701 while (!(ret = getclass(name)) && errno == EINTR)
702 702 ;
703 703 return (ret);
704 704 }
705 705
706 706 PWHEEL *
707 707 Getpwheel(char *name)
708 708 {
709 709 register PWHEEL *ret;
710 710
711 711 while (!(ret = getpwheel(name)) && errno == EINTR)
712 712 ;
713 713 return (ret);
714 714 }
715 715
716 716 SECURE *
717 717 Getsecure(char *file)
718 718 {
719 719 register SECURE *ret;
720 720
721 721 while (!(ret = getsecure(file)) && errno == EINTR)
722 722 ;
723 723 return ((SECURE *) ret);
724 724 }
725 725
726 726
727 727 int
728 728 Loadfilters(char *file)
729 729 {
730 730 register int ret;
731 731
732 732 while ((ret = loadfilters(file)) == -1 && errno == EINTR)
733 733 ;
734 734 return (ret);
735 735 }
736 736
737 737 /**
738 738 ** free_form() - FREE MEMORY ALLOCATED FOR _FORM STRUCTURE
739 739 **/
740 740
741 741 void
742 742 free_form(register _FORM *pf)
743 743 {
744 744 if (!pf)
745 745 return;
746 746 if (pf->chset)
747 747 Free (pf->chset);
748 748 if (pf->rcolor)
749 749 Free (pf->rcolor);
750 750 if (pf->comment)
751 751 Free (pf->comment);
752 752 if (pf->conttype)
753 753 Free (pf->conttype);
754 754 if (pf->name)
755 755 Free (pf->name);
756 756 if (pf->paper)
757 757 Free (pf->paper);
758 758 pf->name = 0;
759 759 if (pf->alert.shcmd)
760 760 Free (pf->alert.shcmd);
761 761 return;
762 762 }
763 763
764 764 /**
765 765 ** getreqno() - GET NUMBER PART OF REQUEST ID
766 766 **/
767 767
768 768 char *
769 769 getreqno(char *req_id)
770 770 {
771 771 register char *cp;
772 772
773 773
774 774 if (!(cp = strrchr(req_id, '-')))
775 775 cp = req_id;
776 776 else
777 777 cp++;
778 778 return (cp);
779 779 }
780 780
781 781 /* Putsecure(): Insurance for writing out the secure request file.
782 782 * input: char ptr to name of the request file,
783 783 * ptr to the SECURE structure to be written.
784 784 * ouput: 0 if successful, -1 otherwise.
785 785 *
786 786 * Description:
787 787 * The normal call to putsecure() is woefully lacking.
788 788 * The bottom line here is that there
789 789 * is no way to make sure that the file has been written out
790 790 * as expected. This can cause rude behaviour later on.
791 791 *
792 792 * This routine calls putsecure(), and then does a getsecure().
793 793 * The results are compared to the original structure. If the
794 794 * info obtained by getsecure() doesn't match, we retry a few
795 795 * times before giving up (presumably something is very seriously
796 796 * wrong at that point).
797 797 */
798 798
799 799
800 800 int
801 801 Putsecure(char *file, SECURE *secbufp)
802 802 {
803 803 SECURE *pls;
804 804 int retries = 5; /* # of attempts */
805 805 int status; /* 0 = success, nonzero otherwise */
806 806
807 807
808 808 while (retries--) {
809 809 status = 1; /* assume the worst, hope for the best */
810 810 if (putsecure(file, secbufp) == -1) {
811 811 rmsecure(file);
812 812 continue;
813 813 }
814 814
815 815 if ((pls = getsecure(file)) == (SECURE *) NULL) {
816 816 rmsecure(file);
817 817 status = 2;
818 818 continue;
819 819 }
820 820
821 821 /* now compare each field */
822 822
823 823 /*
824 824 * A comparison is only valid if secbufp and pls point to
825 825 * different locations. In reality getsecure() will have
826 826 * already been called, allocating the same STATIC memory
827 827 * location to both structures making the following compare
828 828 * meaningless.
829 829 * Therefore test for this condition to prevent us from
830 830 * calling freesecure which will destroy uid and
831 831 * req_id fields in the strucure
832 832 */
833 833
834 834 status = 0;
835 835 if (secbufp != pls) {
836 836 if (strcmp(pls->req_id, secbufp->req_id) != 0) {
837 837 rmsecure(file);
838 838 status = 3;
839 839 continue;
840 840 }
841 841
842 842 if (pls->uid != secbufp->uid) {
843 843 rmsecure(file);
844 844 status = 4;
845 845 continue;
846 846 }
847 847
848 848 if (strcmp(pls->user, secbufp->user) != 0) {
849 849 rmsecure(file);
850 850 status = 5;
851 851 continue;
852 852 }
853 853
854 854 if (pls->gid != secbufp->gid) {
855 855 rmsecure(file);
856 856 status = 6;
857 857 continue;
858 858 }
859 859
860 860 if (pls->size != secbufp->size) {
861 861 rmsecure(file);
862 862 status = 7;
863 863 continue;
864 864 }
865 865
866 866 if (pls->date != secbufp->date) {
867 867 rmsecure(file);
868 868 status = 8;
869 869 continue;
870 870 }
871 871
872 872 freesecure(pls);
873 873 }
874 874 break;
875 875 }
876 876
877 877 if (status != 0) {
878 878 note("Putsecure failed, status=%d\n", status);
879 879 return -1;
880 880 }
881 881
882 882 return 0;
883 883 }
884 884
885 885 void GetRequestFiles(REQUEST *req, char *buffer, int length)
886 886 {
887 887 char buf[BUFSIZ];
888 888
889 889 memset(buf, 0, sizeof(buf));
890 890
↓ open down ↓ |
890 lines elided |
↑ open up ↑ |
891 891 if (req->title) {
892 892 char *r = req->title;
893 893 char *ptr = buf;
894 894
895 895 while ( *r && strncmp(r,"\\n",2)) {
896 896 *ptr++ = *r++;
897 897 }
898 898 } else if (req->file_list)
899 899 strlcpy(buf, *req->file_list, sizeof (buf));
900 900
901 - if (*buf == NULL || !strncmp(buf, SPOOLDIR, sizeof(SPOOLDIR)-1))
901 + if (*buf == '\0' || !strncmp(buf, SPOOLDIR, sizeof(SPOOLDIR)-1))
902 902 strcpy(buf, "<File name not available>");
903 903
904 904 if (strlen(buf) > (size_t) 24) {
905 905 char *r;
906 906
907 907 if (r = strrchr(buf, '/'))
908 908 r++;
909 909 else
910 910 r = buf;
911 911
912 912 snprintf(buffer, length, "%-.24s", r);
913 913 } else
914 914 strlcpy(buffer, buf, length);
915 915 return;
916 916 }
917 917
918 918
919 919 /**
920 920 ** _Malloc()
921 921 ** _Realloc()
922 922 ** _Calloc()
923 923 ** _Strdup()
924 924 ** _Free()
925 925 **/
926 926
927 927 void (*lp_alloc_fail_handler)( void ) = 0;
928 928
929 929 typedef void *alloc_type;
930 930
931 931 alloc_type
932 932 _Malloc(size_t size, const char *file, int line)
933 933 {
934 934 alloc_type ret;
935 935
936 936 ret = malloc(size);
937 937 if (!ret) {
938 938 if (lp_alloc_fail_handler)
939 939 (*lp_alloc_fail_handler)();
940 940 errno = ENOMEM;
941 941 }
942 942 return (ret);
943 943 }
944 944
945 945 alloc_type
946 946 _Realloc(void *ptr, size_t size, const char *file, int line)
947 947 {
948 948 alloc_type ret = realloc(ptr, size);
949 949
950 950 if (!ret) {
951 951 if (lp_alloc_fail_handler)
952 952 (*lp_alloc_fail_handler)();
953 953 errno = ENOMEM;
954 954 }
955 955 return (ret);
956 956 }
957 957
958 958 alloc_type
959 959 _Calloc(size_t nelem, size_t elsize, const char *file, int line)
960 960 {
961 961 alloc_type ret = calloc(nelem, elsize);
962 962
963 963 if (!ret) {
964 964 if (lp_alloc_fail_handler)
965 965 (*lp_alloc_fail_handler)();
966 966 errno = ENOMEM;
967 967 }
968 968 return (ret);
969 969 }
970 970
971 971 char *
972 972 _Strdup(const char *s, const char *file, int line)
973 973 {
974 974 char * ret;
975 975
976 976 if (!s)
977 977 return( (char *) 0);
978 978
979 979 ret = strdup(s);
980 980
981 981 if (!ret) {
982 982 if (lp_alloc_fail_handler)
983 983 (*lp_alloc_fail_handler)();
984 984 errno = ENOMEM;
985 985 }
986 986 return (ret);
987 987 }
988 988
989 989 void
990 990 _Free(void *ptr, const char *file, int line)
991 991 {
992 992 free (ptr);
993 993 return;
994 994 }
↓ open down ↓ |
83 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX