forked from quinot/taylor-uucp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tstuu.c
1570 lines (1290 loc) · 32.6 KB
/
tstuu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* tstuu.c
Test the uucp package on a UNIX system.
Copyright (C) 1991, 1992, 1993, 1994, 1995, 2002 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
The author of the program may be contacted at [email protected].
*/
#include "uucp.h"
#if USE_RCS_ID
const char tstuu_rcsid[] = "$Id$";
#endif
#include "sysdep.h"
#include "system.h"
#include "getopt.h"
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#if HAVE_SYS_TIMES_H
#include <sys/times.h>
#endif
#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if HAVE_SELECT
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#endif
#if HAVE_POLL
#if HAVE_STROPTS_H
#include <stropts.h>
#endif
#if HAVE_POLL_H
#include <poll.h>
#endif
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#else
#if HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#endif
#ifndef O_RDONLY
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#endif
#if HAVE_TIME_H
#if ! HAVE_SYS_TIME_H || ! HAVE_SELECT || TIME_WITH_SYS_TIME
#include <time.h>
#endif
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#if HAVE_UNION_WAIT
typedef union wait wait_status;
#else
typedef int wait_status;
#endif
#if HAVE_STREAMS_PTYS
#include <termio.h>
extern char *ptsname ();
#endif
/* Get definitions for both O_NONBLOCK and O_NDELAY. */
#ifndef O_NDELAY
#ifdef FNDELAY
#define O_NDELAY FNDELAY
#else /* ! defined (FNDELAY) */
#define O_NDELAY 0
#endif /* ! defined (FNDELAY) */
#endif /* ! defined (O_NDELAY) */
#ifndef O_NONBLOCK
#ifdef FNBLOCK
#define O_NONBLOCK FNBLOCK
#else /* ! defined (FNBLOCK) */
#define O_NONBLOCK 0
#endif /* ! defined (FNBLOCK) */
#endif /* ! defined (O_NONBLOCK) */
#if O_NDELAY == 0 && O_NONBLOCK == 0
#error No way to do nonblocking I/O
#endif
/* Get definitions for EAGAIN, EWOULDBLOCK and ENODATA. */
#ifndef EAGAIN
#ifndef EWOULDBLOCK
#define EAGAIN (-1)
#define EWOULDBLOCK (-1)
#else /* defined (EWOULDBLOCK) */
#define EAGAIN EWOULDBLOCK
#endif /* defined (EWOULDBLOCK) */
#else /* defined (EAGAIN) */
#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN
#endif /* ! defined (EWOULDBLOCK) */
#endif /* defined (EAGAIN) */
#ifndef ENODATA
#define ENODATA EAGAIN
#endif
/* Make sure we have a CLK_TCK definition, even if it makes no sense.
This is in case TIMES_TICK is defined as CLK_TCK. */
#ifndef CLK_TCK
#define CLK_TCK (60)
#endif
/* Don't try too hard to get a TIMES_TICK value; it doesn't matter
that much. */
#if TIMES_TICK == 0
#undef TIMES_TICK
#define TIMES_TICK CLK_TCK
#endif
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif
#if 1
#define ZUUCICO_CMD "login uucp"
#define UUCICO_EXECL "/bin/login", "login", "uucp"
#else
#define ZUUCICO_CMD "su - nuucp"
#define UUCICO_EXECL "/bin/su", "su", "-", "nuucp"
#endif
#if ! HAVE_SELECT && ! HAVE_POLL
#error You need select or poll
#endif
#if ! HAVE_REMOVE
#undef remove
#define remove unlink
#endif
/* Buffer chain to hold data read from a uucico. */
#define BUFCHARS (512)
struct sbuf
{
struct sbuf *qnext;
int cstart;
int cend;
char ab[BUFCHARS];
};
/* Local functions. */
static void umake_file P((const char *zfile, int cextra));
static void uprepare_test P((boolean fmake, int itest,
boolean fcall_uucico,
const char *zsys));
static void ucheck_file P((const char *zfile, const char *zerr,
int cextra));
static void ucheck_test P((int itest, boolean fcall_uucico));
static RETSIGTYPE uchild P((int isig));
static int cpshow P((char *z, int bchar));
static void uchoose P((int *po1, int *po2));
static long cread P((int o, struct sbuf **));
static boolean fsend P((int o, int oslave, struct sbuf **));
static boolean fwritable P((int o));
static void xsystem P((const char *zcmd));
static FILE *xfopen P((const char *zname, const char *zmode));
static char *zDebug;
static int iTest;
static boolean fCall_uucico;
static int iPercent;
static pid_t iPid1, iPid2;
static int cFrom1, cFrom2;
static char abLogout1[sizeof "tstout /dev/ptyp0"];
static char abLogout2[sizeof "tstout /dev/ptyp0"];
static char *zProtocols;
int
main (int argc, char **argv)
{
int iopt;
const char *zcmd1, *zcmd2;
const char *zsys;
boolean fmake = TRUE;
int omaster1, oslave1, omaster2, oslave2;
char abpty1[sizeof "/dev/ptyp0"];
char abpty2[sizeof "/dev/ptyp0"];
struct sbuf *qbuf1, *qbuf2;
#if ! HAVE_TAYLOR_CONFIG
fprintf (stderr, "%s: only works when compiled with HAVE_TAYLOR_CONFIG\n",
argv[0]);
exit (1);
#endif
zcmd1 = NULL;
zcmd2 = NULL;
zsys = "test2";
while ((iopt = getopt (argc, argv, "c:np:s:t:ux:1:2:")) != EOF)
{
switch (iopt)
{
case 'c':
zProtocols = optarg;
break;
case 'n':
fmake = FALSE;
break;
case 'p':
iPercent = (int) strtol (optarg, (char **) NULL, 10);
srand ((unsigned int) ixsysdep_time ((long *) NULL));
break;
case 's':
zsys = optarg;
break;
case 't':
iTest = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'u':
fCall_uucico = TRUE;
break;
case 'x':
zDebug = optarg;
break;
case '1':
zcmd1 = optarg;
break;
case '2':
zcmd2 = optarg;
break;
default:
fprintf (stderr,
"Taylor UUCP %s, copyright (C) 1991, 92, 93, 94, 1995 Ian Lance Taylor\n",
VERSION);
fprintf (stderr,
"Usage: tstuu [-xn] [-t #] [-u] [-1 cmd] [-2 cmd]\n");
exit (EXIT_FAILURE);
}
}
if (fCall_uucico && zcmd2 == NULL)
zcmd2 = ZUUCICO_CMD;
uprepare_test (fmake, iTest, fCall_uucico, zsys);
(void) remove ("/usr/tmp/tstuu/spool1/core");
(void) remove ("/usr/tmp/tstuu/spool2/core");
omaster1 = -1;
oslave1 = -1;
omaster2 = -1;
oslave2 = -1;
#if ! HAVE_STREAMS_PTYS
{
char *zptyname;
const char *zpty;
zptyname = abpty1;
for (zpty = "pqrs"; *zpty != '\0'; ++zpty)
{
int ipty;
for (ipty = 0; ipty < 16; ipty++)
{
int om, os;
FILE *e;
sprintf (zptyname, "/dev/pty%c%c", *zpty,
"0123456789abcdef"[ipty]);
om = open (zptyname, O_RDWR);
if (om < 0)
continue;
zptyname[5] = 't';
os = open (zptyname, O_RDWR);
if (os < 0)
{
(void) close (om);
continue;
}
if (omaster1 == -1)
{
omaster1 = om;
oslave1 = os;
e = fopen ("/usr/tmp/tstuu/pty1", "w");
if (e == NULL)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (e, "%s", zptyname + 5);
if (fclose (e) != 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
zptyname = abpty2;
}
else
{
omaster2 = om;
oslave2 = os;
e = fopen ("/usr/tmp/tstuu/pty2", "w");
if (e == NULL)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (e, "%s", zptyname + 5);
if (fclose (e) != 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
break;
}
}
if (omaster1 != -1 && omaster2 != -1)
break;
}
}
#else /* HAVE_STREAMS_PTYS */
{
int ipty;
for (ipty = 0; ipty < 2; ipty++)
{
int om, os;
FILE *e;
char *znam;
struct termio stio;
om = open ((char *) "/dev/ptmx", O_RDWR);
if (om < 0)
break;
znam = ptsname (om);
if (znam == NULL)
break;
if (unlockpt (om) != 0
|| grantpt (om) != 0)
break;
os = open (znam, O_RDWR);
if (os < 0)
{
(void) close (om);
om = -1;
break;
}
if (ioctl (os, I_PUSH, "ptem") < 0
|| ioctl(os, I_PUSH, "ldterm") < 0)
{
perror ("ioctl");
exit (EXIT_FAILURE);
}
/* Can this really be right? */
memset (&stio, 0, sizeof (stio));
stio.c_cflag = B9600 | CS8 | CREAD | HUPCL;
if (ioctl(os, TCSETA, &stio) < 0)
{
perror ("TCSETA");
exit (EXIT_FAILURE);
}
if (omaster1 == -1)
{
strcpy (abpty1, znam);
omaster1 = om;
oslave1 = os;
e = fopen ("/usr/tmp/tstuu/pty1", "w");
if (e == NULL)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (e, "%s", znam + 5);
if (fclose (e) != 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
}
else
{
strcpy (abpty2, znam);
omaster2 = om;
oslave2 = os;
e = fopen ("/usr/tmp/tstuu/pty2", "w");
if (e == NULL)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (e, "%s", znam + 5);
if (fclose (e) != 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
}
}
}
#endif /* HAVE_STREAMS_PTYS */
if (omaster2 == -1)
{
fprintf (stderr, "No pseudo-terminals available\n");
exit (EXIT_FAILURE);
}
/* Make sure we can or these into an int for the select call. Most
systems could use 31 instead of 15, but it should never be a
problem. */
if (omaster1 > 15 || omaster2 > 15)
{
fprintf (stderr, "File descriptors are too large\n");
exit (EXIT_FAILURE);
}
/* Prepare to log out the command if it is a login command. On
Ultrix 4.0 uucico can only be run from login for some reason. */
if (zcmd1 == NULL
|| strncmp (zcmd1, "login", sizeof "login" - 1) != 0)
abLogout1[0] = '\0';
else
sprintf (abLogout1, "tstout %s", abpty1);
if (zcmd2 == NULL
|| strncmp (zcmd2, "login", sizeof "login" - 1) != 0)
abLogout2[0] = '\0';
else
sprintf (abLogout2, "tstout %s", abpty2);
iPid1 = fork ();
if (iPid1 < 0)
{
perror ("fork");
exit (EXIT_FAILURE);
}
else if (iPid1 == 0)
{
if (close (0) < 0
|| close (1) < 0
|| close (omaster1) < 0
|| close (omaster2) < 0
|| close (oslave2) < 0)
perror ("close");
if (dup2 (oslave1, 0) < 0
|| dup2 (oslave1, 1) < 0)
perror ("dup2");
if (close (oslave1) < 0)
perror ("close");
/* This is said to improve the tests on Linux. */
sleep (3);
if (zDebug != NULL)
fprintf (stderr, "About to exec first process\n");
if (zcmd1 != NULL)
exit (system ((char *) zcmd1));
else
{
(void) execl ("uucico", "uucico", "-I", "/usr/tmp/tstuu/Config1",
"-q", "-S", zsys, "-pstdin", (const char *) NULL);
perror ("execl failed");
exit (EXIT_FAILURE);
}
}
iPid2 = fork ();
if (iPid2 < 0)
{
perror ("fork");
kill (iPid1, SIGTERM);
exit (EXIT_FAILURE);
}
else if (iPid2 == 0)
{
if (close (0) < 0
|| close (1) < 0
|| close (omaster1) < 0
|| close (oslave1) < 0
|| close (omaster2) < 0)
perror ("close");
if (dup2 (oslave2, 0) < 0
|| dup2 (oslave2, 1) < 0)
perror ("dup2");
if (close (oslave2) < 0)
perror ("close");
/* This is said to improve the tests on Linux. */
sleep (5);
if (zDebug != NULL)
fprintf (stderr, "About to exec second process\n");
if (fCall_uucico)
{
(void) execl (UUCICO_EXECL, (const char *) NULL);
perror ("execl failed");
exit (EXIT_FAILURE);
}
else if (zcmd2 != NULL)
exit (system ((char *) zcmd2));
else
{
(void) execl ("uucico", "uucico", "-I", "/usr/tmp/tstuu/Config2",
"-lq", (const char *)NULL);
perror ("execl failed");
exit (EXIT_FAILURE);
}
}
signal (SIGCHLD, uchild);
if (fcntl (omaster1, F_SETFL, O_NDELAY | O_NONBLOCK) < 0
&& errno == EINVAL)
(void) fcntl (omaster1, F_SETFL, O_NONBLOCK);
if (fcntl (omaster2, F_SETFL, O_NDELAY | O_NONBLOCK) < 0
&& errno == EINVAL)
(void) fcntl (omaster2, F_SETFL, O_NONBLOCK);
qbuf1 = NULL;
qbuf2 = NULL;
while (TRUE)
{
int o1, o2;
boolean fcont;
o1 = omaster1;
o2 = omaster2;
uchoose (&o1, &o2);
if (o1 == -1 && o2 == -1)
{
if (zDebug != NULL)
fprintf (stderr, "Five second pause\n");
continue;
}
if (o1 != -1)
cFrom1 += cread (omaster1, &qbuf1);
if (o2 != -1)
cFrom2 += cread (omaster2, &qbuf2);
do
{
fcont = FALSE;
if (qbuf1 != NULL
&& fwritable (omaster2)
&& fsend (omaster2, oslave2, &qbuf1))
fcont = TRUE;
if (qbuf2 != NULL
&& fwritable (omaster1)
&& fsend (omaster1, oslave1, &qbuf2))
fcont = TRUE;
if (! fcont
&& (qbuf1 != NULL || qbuf2 != NULL))
{
long cgot1, cgot2;
cgot1 = cread (omaster1, &qbuf1);
cFrom1 += cgot1;
cgot2 = cread (omaster2, &qbuf2);
cFrom2 += cgot2;
fcont = TRUE;
}
}
while (fcont);
}
/*NOTREACHED*/
}
/* When a child dies, kill them both. */
static RETSIGTYPE
uchild (int isig ATTRIBUTE_UNUSED)
{
struct tms sbase, s1, s2;
signal (SIGCHLD, SIG_DFL);
/* Give the processes a chance to die on their own. */
sleep (2);
(void) kill (iPid1, SIGTERM);
(void) kill (iPid2, SIGTERM);
(void) times (&sbase);
#if HAVE_WAITPID
(void) waitpid (iPid1, (pointer) NULL, 0);
#else /* ! HAVE_WAITPID */
#if HAVE_WAIT4
(void) wait4 (iPid1, (pointer) NULL, 0, (struct rusage *) NULL);
#else /* ! HAVE_WAIT4 */
(void) wait ((wait_status *) NULL);
#endif /* ! HAVE_WAIT4 */
#endif /* ! HAVE_WAITPID */
(void) times (&s1);
#if HAVE_WAITPID
(void) waitpid (iPid2, (pointer) NULL, 0);
#else /* ! HAVE_WAITPID */
#if HAVE_WAIT4
(void) wait4 (iPid2, (wait_status *) NULL, 0, (struct rusage *) NULL);
#else /* ! HAVE_WAIT4 */
(void) wait ((wait_status *) NULL);
#endif /* ! HAVE_WAIT4 */
#endif /* ! HAVE_WAITPID */
(void) times (&s2);
fprintf (stderr,
" First child: user: %g; system: %g\n",
(double) (s1.tms_cutime - sbase.tms_cutime) / (double) TIMES_TICK,
(double) (s1.tms_cstime - sbase.tms_cstime) / (double) TIMES_TICK);
fprintf (stderr,
"Second child: user: %g; system: %g\n",
(double) (s2.tms_cutime - s1.tms_cutime) / (double) TIMES_TICK,
(double) (s2.tms_cstime - s1.tms_cstime) / (double) TIMES_TICK);
ucheck_test (iTest, fCall_uucico);
if (abLogout1[0] != '\0')
{
if (zDebug != NULL)
fprintf (stderr, "Executing %s\n", abLogout1);
(void) system (abLogout1);
}
if (abLogout2[0] != '\0')
{
if (zDebug != NULL)
fprintf (stderr, "Executing %s\n", abLogout2);
(void) system (abLogout2);
}
fprintf (stderr, "Wrote %d bytes from 1 to 2\n", cFrom1);
fprintf (stderr, "Wrote %d bytes from 2 to 1\n", cFrom2);
if (access ("/usr/tmp/tstuu/spool1/core", R_OK) == 0)
fprintf (stderr, "core file 1 exists\n");
if (access ("/usr/tmp/tstuu/spool2/core", R_OK) == 0)
fprintf (stderr, "core file 2 exists\n");
exit (EXIT_SUCCESS);
}
/* Open a file without error. */
static FILE *
xfopen (const char *zname, const char *zmode)
{
FILE *eret;
eret = fopen (zname, zmode);
if (eret == NULL)
{
perror (zname);
exit (EXIT_FAILURE);
}
return eret;
}
/* Close a file without error. */
static void xfclose P((FILE *e));
static void
xfclose (FILE *e)
{
if (fclose (e) != 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
}
/* Create a test file. */
static void
umake_file (const char *z, int c)
{
int i;
FILE *e;
e = xfopen (z, "w");
for (i = 0; i < 256; i++)
{
int i2;
for (i2 = 0; i2 < 256; i2++)
putc (i, e);
}
for (i = 0; i < c; i++)
putc (i, e);
xfclose (e);
}
/* Check a test file. */
static void
ucheck_file (const char *z, const char *zerr, int c)
{
int i;
FILE *e;
e = xfopen (z, "r");
for (i = 0; i < 256; i++)
{
int i2;
for (i2 = 0; i2 < 256; i2++)
{
int bread;
bread = getc (e);
if (bread == EOF)
{
fprintf (stderr,
"%s: Unexpected EOF at position %d,%d\n",
zerr, i, i2);
xfclose (e);
return;
}
if (bread != i)
fprintf (stderr,
"%s: At position %d,%d got %d expected %d\n",
zerr, i, i2, bread, i);
}
}
for (i = 0; i < c; i++)
{
int bread;
bread = getc (e);
if (bread == EOF)
{
fprintf (stderr, "%s: Unexpected EOF at extra %d\n", zerr, i);
xfclose (e);
return;
}
if (bread != i)
fprintf (stderr, "%s: At extra %d got %d expected %d\n",
zerr, i, bread, i);
}
if (getc (e) != EOF)
fprintf (stderr, "%s: File is too long", zerr);
xfclose (e);
}
/* Prepare all the configuration files for testing. */
static void
uprepare_test (boolean fmake, int itest, boolean fcall_uucico, const char *zsys)
{
FILE *e;
const char *zuucp1, *zuucp2;
const char *zuux1, *zuux2;
char ab[1000];
const char *zfrom;
const char *zto;
/* We must make /usr/tmp/tstuu world writeable or we won't be able to
receive files into it. */
(void) umask (0);
#ifndef S_IWOTH
#define S_IWOTH 02
#endif
if (mkdir ((char *) "/usr/tmp/tstuu",
IPUBLIC_DIRECTORY_MODE | S_IWOTH) != 0
&& errno != EEXIST)
{
perror ("mkdir");
exit (EXIT_FAILURE);
}
if (mkdir ((char *) "/usr/tmp/tstuu/spool1", IPUBLIC_DIRECTORY_MODE) != 0
&& errno != EEXIST)
{
perror ("mkdir");
exit (EXIT_FAILURE);
}
if (mkdir ((char *) "/usr/tmp/tstuu/spool2", IPUBLIC_DIRECTORY_MODE) != 0
&& errno != EEXIST)
{
perror ("mkdir");
exit (EXIT_FAILURE);
}
if (fmake)
{
e = xfopen ("/usr/tmp/tstuu/Config1", "w");
fprintf (e, "# First test configuration file\n");
fprintf (e, "nodename test1\n");
fprintf (e, "spool /usr/tmp/tstuu/spool1\n");
fprintf (e, "lockdir /usr/tmp/tstuu/spool1\n");
fprintf (e, "sysfile /usr/tmp/tstuu/System1\n");
fprintf (e, "sysfile /usr/tmp/tstuu/System1.2\n");
fprintf (e, "portfile /usr/tmp/tstuu/Port1\n");
(void) remove ("/usr/tmp/tstuu/Log1");
#if ! HAVE_HDB_LOGGING
fprintf (e, "logfile /usr/tmp/tstuu/Log1\n");
#else
fprintf (e, "%s\n", "logfile /usr/tmp/tstuu/Log1/%s/%s");
#endif
fprintf (e, "statfile /usr/tmp/tstuu/Stats1\n");
fprintf (e, "debugfile /usr/tmp/tstuu/Debug1\n");
fprintf (e, "callfile /usr/tmp/tstuu/Call1\n");
fprintf (e, "pubdir /usr/tmp/tstuu\n");
#if HAVE_V2_CONFIG
fprintf (e, "v2-files no\n");
#endif
#if HAVE_HDB_CONFIG
fprintf (e, "hdb-files no\n");
#endif
if (zDebug != NULL)
fprintf (e, "debug %s\n", zDebug);
xfclose (e);
e = xfopen ("/usr/tmp/tstuu/System1", "w");
fprintf (e, "# This file is ignored, to test multiple system files\n");
fprintf (e, "time never\n");
xfclose (e);
e = xfopen ("/usr/tmp/tstuu/System1.2", "w");
fprintf (e, "# First test system file\n");
fprintf (e, "time any\n");
fprintf (e, "port stdin\n");
fprintf (e, "# That was the defaults\n");
fprintf (e, "system %s\n", zsys);
if (! fcall_uucico)
{
FILE *eprog;
eprog = xfopen ("/usr/tmp/tstuu/Chat1", "w");
/* Wait for the other side to open the port and flush input. */
fprintf (eprog, "sleep 2\n");
fprintf (eprog,
"echo password $1 speed $2 1>&2\n");
fprintf (eprog, "echo test1\n");
fprintf (eprog, "exit 0\n");
xfclose (eprog);
if (chmod ("/usr/tmp/tstuu/Chat1",
S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0)
{
perror ("chmod (/usr/tmp/tstuu/Chat1)");
exit (EXIT_FAILURE);
}
fprintf (e, "chat-program /usr/tmp/tstuu/Chat1 \\P \\S\n");
fprintf (e, "chat word: \\P\n");
fprintf (e, "chat-fail login;\n");
fprintf (e, "call-login *\n");
fprintf (e, "call-password *\n");
}
else
fprintf (e, "chat \"\"\n");
fprintf (e, "call-transfer yes\n");
fprintf (e, "commands cat\n");
if (! fcall_uucico && iPercent == 0)
{
fprintf (e, "protocol-parameter g window 7\n");
fprintf (e, "protocol-parameter g packet-size 4096\n");
fprintf (e, "protocol-parameter j avoid \\377\n");
}
if (zProtocols != NULL)
fprintf (e, "protocol %s\n", zProtocols);
xfclose (e);
e = xfopen ("/usr/tmp/tstuu/Port1", "w");
fprintf (e, "port stdin\n");
fprintf (e, "type stdin\n");
xfclose (e);
e = xfopen ("/usr/tmp/tstuu/Call1", "w");
fprintf (e, "Call out password file\n");
fprintf (e, "%s test1 pass\\s1\n", zsys);
xfclose (e);
if (! fcall_uucico)
{
FILE *eprog;
e = xfopen ("/usr/tmp/tstuu/Config2", "w");
fprintf (e, "# Second test configuration file\n");
fprintf (e, "nodename test2\n");
fprintf (e, "spool /usr/tmp/tstuu/spool2\n");
fprintf (e, "lockdir /usr/tmp/tstuu/spool2\n");
fprintf (e, "sysfile /usr/tmp/tstuu/System2\n");
(void) remove ("/usr/tmp/tstuu/Log2");
#if ! HAVE_HDB_LOGGING
fprintf (e, "logfile /usr/tmp/tstuu/Log2\n");
#else
fprintf (e, "%s\n", "logfile /usr/tmp/tstuu/Log2/%s/%s");
#endif
fprintf (e, "statfile /usr/tmp/tstuu/Stats2\n");
fprintf (e, "debugfile /usr/tmp/tstuu/Debug2\n");
fprintf (e, "passwdfile /usr/tmp/tstuu/Pass2\n");
fprintf (e, "pubdir /usr/tmp/tstuu\n");
#if HAVE_V2_CONFIG
fprintf (e, "v2-files no\n");
#endif
#if HAVE_HDB_CONFIG
fprintf (e, "hdb-files no\n");
#endif
if (zDebug != NULL)
fprintf (e, "debug %s\n", zDebug);
xfclose (e);
e = xfopen ("/usr/tmp/tstuu/System2", "w");