forked from quinot/taylor-uucp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuucico.c
3062 lines (2679 loc) · 79.6 KB
/
uucico.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
/* uucico.c
This is the main UUCP communication program.
Copyright (C) 1991, 1992, 1993, 1994, 1995, 2002, 2003 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 uucico_rcsid[] = "$Id$";
#endif
#include <ctype.h>
#if HAVE_LIMITS_H
#include <limits.h>
#else
#define LONG_MAX 2147483647L
#endif
#include "getopt.h"
#include "uudefs.h"
#include "uuconf.h"
#include "conn.h"
#include "prot.h"
#include "trans.h"
#include "system.h"
#if HAVE_ENCRYPTED_PASSWORDS
#ifndef crypt
extern char *crypt ();
#endif
#endif
/* Coherent already had a different meaning for the -c option. What a
pain. */
#ifdef __COHERENT__
#define COHERENT_C_OPTION 1
#else
#define COHERENT_C_OPTION 0
#endif
/* Define the known protocols. */
#define TCP_PROTO \
(UUCONF_RELIABLE_ENDTOEND \
| UUCONF_RELIABLE_RELIABLE \
| UUCONF_RELIABLE_EIGHT)
static const struct sprotocol asProtocols[] =
{
{ 't', TCP_PROTO, 1, TRUE,
asTproto_params, ftstart, ftshutdown, ftsendcmd, ztgetspace,
ftsenddata, ftwait, ftfile },
{ 'e', TCP_PROTO, 1, TRUE,
asEproto_params, festart, feshutdown, fesendcmd, zegetspace,
fesenddata, fewait, fefile },
{ 'i', UUCONF_RELIABLE_EIGHT, 7, TRUE,
asIproto_params, fistart, fishutdown, fisendcmd, zigetspace,
fisenddata, fiwait, NULL },
{ 'a', UUCONF_RELIABLE_EIGHT, 1, TRUE,
asZproto_params, fzstart, fzshutdown, fzsendcmd, zzgetspace,
fzsenddata, fzwait, fzfile },
{ 'g', UUCONF_RELIABLE_EIGHT, 1, TRUE,
asGproto_params, fgstart, fgshutdown, fgsendcmd, zggetspace,
fgsenddata, fgwait, NULL },
{ 'G', UUCONF_RELIABLE_EIGHT, 1, TRUE,
asGproto_params, fbiggstart, fgshutdown, fgsendcmd, zggetspace,
fgsenddata, fgwait, NULL },
{ 'j', UUCONF_RELIABLE_EIGHT, 7, TRUE,
asIproto_params, fjstart, fjshutdown, fisendcmd, zigetspace,
fisenddata, fiwait, NULL },
{ 'f', UUCONF_RELIABLE_RELIABLE, 1, FALSE,
asFproto_params, ffstart, ffshutdown, ffsendcmd, zfgetspace,
ffsenddata, ffwait, fffile },
{ 'v', UUCONF_RELIABLE_EIGHT, 1, TRUE,
asGproto_params, fvstart, fgshutdown, fgsendcmd, zggetspace,
fgsenddata, fgwait, NULL },
{ 'y', UUCONF_RELIABLE_RELIABLE | UUCONF_RELIABLE_EIGHT, 1, TRUE,
asYproto_params, fystart, fyshutdown, fysendcmd, zygetspace,
fysenddata, fywait, fyfile }
};
#define CPROTOCOLS (sizeof asProtocols / sizeof asProtocols[0])
/* Locked system. */
static boolean fLocked_system;
static struct uuconf_system sLocked_system;
/* Daemon structure holding information about the remote system (must
be global so the error handler can see it. */
static struct sdaemon sDaemon;
/* Open connection. */
static struct sconnection *qConn;
/* uuconf global pointer; need to close the connection after a fatal
error. */
static pointer pUuconf;
/* This structure is passed to iuport_lock via uuconf_find_port. */
struct spass
{
boolean fmatched;
boolean flocked;
struct sconnection *qconn;
};
/* Local functions. */
static void uusage P((void));
static void uhelp P((void));
static void uabort P((void));
static boolean fcall P((pointer puuconf, const char *zconfig, boolean fuuxqt,
const struct uuconf_system *qsys,
struct uuconf_port *qport, boolean fifwork,
boolean fforce, boolean fdetach,
boolean fquiet, boolean ftrynext));
static boolean fconn_call P((struct sdaemon *qdaemon,
struct uuconf_port *qport,
struct sstatus *qstat, int cretry,
boolean *pfcalled));
static boolean fdo_call P((struct sdaemon *qdaemon,
struct sstatus *qstat,
const struct uuconf_dialer *qdialer,
boolean *pfcalled, enum tstatus_type *pterr));
static int iuport_lock P((struct uuconf_port *qport, pointer pinfo));
static boolean flogin_prompt P((pointer puuconf, const char *zconfig,
boolean fuuxqt, struct sconnection *qconn,
const char *zlogin, const char **pzsystem));
static int icallin_cmp P((int iwhich, pointer pinfo, const char *zfile));
static boolean faccept_call P((pointer puuconf, const char *zconfig,
boolean fuuxqt, const char *zlogin,
struct sconnection *qconn,
const char **pzsystem));
static void uaccept_call_cleanup P((pointer puuconf,
struct uuconf_system *qfreesys,
struct uuconf_port *qport,
struct uuconf_port *qfreeport,
char *zloc));
static void uapply_proto_params P((pointer puuconf, int bproto,
struct uuconf_cmdtab *qcmds,
struct uuconf_proto_param *pas));
static boolean fsend_uucp_cmd P((struct sconnection *qconn,
const char *z));
static char *zget_uucp_cmd P((struct sconnection *qconn,
boolean frequired, boolean fstrip));
static char *zget_typed_line P((struct sconnection *qconn,
boolean fstrip));
/* Long getopt options. */
static const struct option asLongopts[] =
{
{ "quiet", no_argument, NULL, 2 },
{ "ifwork", no_argument, NULL, 'C' },
{ "nodetach", no_argument, NULL, 'D' },
{ "loop", no_argument, NULL, 'e' },
{ "force", no_argument, NULL, 'f'},
{ "stdin", required_argument, NULL, 'i' },
{ "prompt", no_argument, NULL, 'l' },
{ "port", required_argument, NULL, 'p' },
{ "nouuxqt", no_argument, NULL, 'q' },
{ "master", no_argument, NULL, 3 },
{ "slave", no_argument, NULL, 4 },
{ "system", required_argument, NULL, 's' },
{ "login", required_argument, NULL, 'u' },
{ "wait", no_argument, NULL, 'w' },
{ "try-next", no_argument, NULL, 'z' },
{ "config", required_argument, NULL, 'I' },
{ "debug", required_argument, NULL, 'x' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 1 },
{ NULL, 0, NULL, 0 }
};
int
main (int argc, char **argv)
{
/* -c: Whether to be quiet. */
boolean fquiet = FALSE;
/* -C: Only call the system if there is work. */
boolean fifwork = FALSE;
/* -D: don't detach from controlling terminal. */
boolean fdetach = TRUE;
/* -e: Whether to do an endless loop of accepting calls. */
boolean fendless = FALSE;
/* -f: Whether to force a call despite status of previous call. */
boolean fforce = FALSE;
/* -i type: type of port to use for stdin. */
enum uuconf_porttype tstdintype = UUCONF_PORTTYPE_STDIN;
/* -I file: configuration file name. */
const char *zconfig = NULL;
/* -l: Whether to give a single login prompt. */
boolean flogin = FALSE;
/* -P port: port to use; in master mode, call out on this port. In
slave mode, accept logins on this port. If port not specified,
then in master mode figure it out for each system, and in slave
mode use stdin and stdout. */
const char *zport = NULL;
/* -q: Whether to start uuxqt when done. */
boolean fuuxqt = TRUE;
/* -r1: Whether we are the master. */
boolean fmaster = FALSE;
/* -s,-S system: system to call. */
const char *zsystem = NULL;
/* -u: Login name to use. */
const char *zlogin = NULL;
/* -w: Whether to wait for a call after doing one. */
boolean fwait = FALSE;
/* -z: Try next alternate if call fails. */
boolean ftrynext = FALSE;
const char *zopts;
int iopt;
struct uuconf_port *qport;
struct uuconf_port sport;
boolean fret = TRUE;
pointer puuconf;
int iuuconf;
#if DEBUG > 1
int iholddebug;
#endif
zProgram = argv[0];
/* When uucico is invoked by login, the first character of the
program will be a dash. We don't want that. */
if (*zProgram == '-')
++zProgram;
#if COHERENT_C_OPTION
zopts = "c:CDefi:I:lp:qr:s:S:u:x:X:vwz";
#else
zopts = "cCDefi:I:lp:qr:s:S:u:x:X:vwz";
#endif
while ((iopt = getopt_long (argc, argv, zopts,
asLongopts, (int *) NULL)) != EOF)
{
#if COHERENT_C_OPTION
if (iopt == 'c')
{
iopt = 's';
fifwork = TRUE;
}
#endif
switch (iopt)
{
case 2:
case 'c':
/* Don't warn if a call is attempted at a bad time, and
don't print the "No work" message. */
fquiet = TRUE;
break;
case 'C':
fifwork = TRUE;
break;
case 'D':
/* Don't detach from controlling terminal. */
fdetach = FALSE;
break;
case 'e':
/* Do an endless loop of accepting calls. */
fendless = TRUE;
break;
case 'f':
/* Force a call even if it hasn't been long enough since the last
failed call. */
fforce = TRUE;
break;
case 'i':
/* Type of port to use for standard input. Only TLI is
supported here, and only if HAVE_TLI is true. This
permits the Network Listener to tell uucico to use TLI
I/O calls. */
if (strcasecmp (optarg, "tli") != 0)
fprintf (stderr, "%s: unsupported port type \"%s\"\n",
zProgram, optarg);
else
{
#if HAVE_TLI
tstdintype = UUCONF_PORTTYPE_TLI;
#else
fprintf (stderr, "%s: not compiled with TLI support\n",
zProgram);
#endif
}
break;
case 'l':
/* Prompt for login name and password. */
flogin = TRUE;
break;
case 'p':
/* Port to use */
zport = optarg;
break;
case 'q':
/* Don't start uuxqt. */
fuuxqt = FALSE;
break;
case 'r':
/* Set mode: -r1 for master, -r0 for slave (default) */
if (strcmp (optarg, "1") == 0)
fmaster = TRUE;
else if (strcmp (optarg, "0") == 0)
fmaster = FALSE;
else
uusage ();
break;
case 's':
/* Set system name */
zsystem = optarg;
fmaster = TRUE;
break;
case 'S':
/* Set system name and force call like -f */
zsystem = optarg;
fforce = TRUE;
fmaster = TRUE;
break;
case 'u':
/* Some versions of uucpd invoke uucico with a -u argument
specifying the login name. If invoked by a privileged
user, we use it instead of the result of
zsysdep_login_name. */
if (fsysdep_privileged ())
zlogin = optarg;
else
fprintf (stderr,
"%s: ignoring command line login name: not a privileged user\n",
zProgram);
break;
case 'w':
/* Call out and then wait for a call in */
fwait = TRUE;
break;
case 'z':
/* Try next alternate if call fails. */
ftrynext = TRUE;
break;
case 'I':
/* Set configuration file name (default is in sysdep.h). */
if (fsysdep_other_config (optarg))
zconfig = optarg;
break;
case 'x':
case 'X':
#if DEBUG > 1
/* Set debugging level. */
iDebug |= idebug_parse (optarg);
#endif
break;
case 'v':
/* Print version and exit. */
printf ("uucico (Taylor UUCP) %s\n", VERSION);
printf ("Copyright (C) 1991, 92, 93, 94, 1995, 2002, 2003 Ian Lance Taylor\n");
printf ("This program is free software; you may redistribute it under the terms of\n");
printf ("the GNU General Public LIcense. This program has ABSOLUTELY NO WARRANTY.\n");
exit (EXIT_SUCCESS);
/*NOTREACHED*/
case 4:
/* --slave. */
fmaster = FALSE;
break;
case 3:
/* --master. */
fmaster = TRUE;
break;
case 1:
/* --help. */
uhelp ();
exit (EXIT_SUCCESS);
/*NOTREACHED*/
case 0:
/* Long option found, and flag value set. */
break;
default:
uusage ();
/*NOTREACHED*/
}
}
if (optind != argc)
uusage ();
if (fwait && zport == NULL)
{
fprintf (stderr, "%s: -w requires -p", zProgram);
uusage ();
}
iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
pUuconf = puuconf;
#if DEBUG > 1
{
const char *zdebug;
iuuconf = uuconf_debuglevel (puuconf, &zdebug);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (zdebug != NULL)
iDebug |= idebug_parse (zdebug);
}
#endif
/* If a port was named, get its information. */
if (zport == NULL)
qport = NULL;
else
{
iuuconf = uuconf_find_port (puuconf, zport, (long) 0, (long) 0,
(int (*) P((struct uuconf_port *,
pointer))) NULL,
(pointer) NULL, &sport);
if (iuuconf == UUCONF_NOT_FOUND)
ulog (LOG_FATAL, "%s: port not found", zport);
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
qport = &sport;
}
#ifdef SIGINT
usysdep_signal (SIGINT);
#endif
#ifdef SIGHUP
usysdep_signal (SIGHUP);
#endif
#ifdef SIGQUIT
usysdep_signal (SIGQUIT);
#endif
#ifdef SIGTERM
usysdep_signal (SIGTERM);
#endif
#ifdef SIGPIPE
usysdep_signal (SIGPIPE);
#endif
usysdep_initialize (puuconf, INIT_SUID);
ulog_to_file (puuconf, TRUE);
ulog_fatal_fn (uabort);
if (fmaster)
{
if (zsystem != NULL)
{
/* A system was named. Call it. */
iuuconf = uuconf_system_info (puuconf, zsystem,
&sLocked_system);
if (iuuconf == UUCONF_NOT_FOUND)
ulog (LOG_FATAL, "%s: System not found", zsystem);
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
/* Detach from the controlling terminal for the call. This
probably makes sense only on Unix. We want the modem
line to become the controlling terminal. */
if (fdetach &&
(qport == NULL
|| qport->uuconf_ttype != UUCONF_PORTTYPE_STDIN))
usysdep_detach ();
ulog_system (sLocked_system.uuconf_zname);
#if DEBUG > 1
iholddebug = iDebug;
if (sLocked_system.uuconf_zdebug != NULL)
iDebug |= idebug_parse (sLocked_system.uuconf_zdebug);
#endif
if (! fsysdep_lock_system (&sLocked_system))
{
ulog (LOG_ERROR, "System already locked");
fret = FALSE;
}
else
{
fLocked_system = TRUE;
fret = fcall (puuconf, zconfig, fuuxqt, &sLocked_system, qport,
fifwork, fforce, fdetach, fquiet, ftrynext);
if (fLocked_system)
{
(void) fsysdep_unlock_system (&sLocked_system);
fLocked_system = FALSE;
}
}
#if DEBUG > 1
iDebug = iholddebug;
#endif
ulog_system ((const char *) NULL);
(void) uuconf_system_free (puuconf, &sLocked_system);
}
else
{
char **pznames, **pz;
int c, i;
boolean fdidone;
/* Call all systems which have work to do. */
fret = TRUE;
fdidone = FALSE;
iuuconf = uuconf_system_names (puuconf, &pznames, 0);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
/* Randomize the order in which we call the systems. */
c = 0;
for (pz = pznames; *pz != NULL; pz++)
c++;
srand ((unsigned int) ixsysdep_time ((long *) NULL));
for (i = c - 1; i > 0; i--)
{
int iuse;
char *zhold;
iuse = rand () % (i + 1);
zhold = pznames[i];
pznames[i] = pznames[iuse];
pznames[iuse] = zhold;
}
for (pz = pznames; *pz != NULL && ! FGOT_SIGNAL (); pz++)
{
iuuconf = uuconf_system_info (puuconf, *pz,
&sLocked_system);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
xfree ((pointer) *pz);
continue;
}
if (fsysdep_has_work (&sLocked_system))
{
fdidone = TRUE;
/* Detach from the controlling terminal. On Unix
this means that we will wind up forking a new
process for each system we call. */
if (fdetach
&& (qport == NULL
|| qport->uuconf_ttype != UUCONF_PORTTYPE_STDIN))
usysdep_detach ();
ulog_system (sLocked_system.uuconf_zname);
#if DEBUG > 1
iholddebug = iDebug;
if (sLocked_system.uuconf_zdebug != NULL)
iDebug |= idebug_parse (sLocked_system.uuconf_zdebug);
#endif
if (! fsysdep_lock_system (&sLocked_system))
{
ulog (LOG_ERROR, "System already locked");
fret = FALSE;
}
else
{
fLocked_system = TRUE;
if (! fcall (puuconf, zconfig, fuuxqt, &sLocked_system,
qport, TRUE, fforce, fdetach, fquiet,
ftrynext))
fret = FALSE;
/* Now ignore any SIGHUP that we got. */
afSignal[INDEXSIG_SIGHUP] = FALSE;
if (fLocked_system)
{
(void) fsysdep_unlock_system (&sLocked_system);
fLocked_system = FALSE;
}
}
#if DEBUG > 1
iDebug = iholddebug;
#endif
ulog_system ((const char *) NULL);
}
(void) uuconf_system_free (puuconf, &sLocked_system);
xfree ((pointer) *pz);
}
xfree ((pointer) pznames);
if (! fdidone && ! fquiet)
ulog (LOG_NORMAL, "No work");
}
/* If requested, wait for calls after dialing out. */
if (fwait)
{
fendless = TRUE;
fmaster = FALSE;
}
}
if (! fmaster)
{
struct sconnection sconn;
boolean flocked;
/* If a port was specified by name, we go into endless loop
mode. In this mode, we wait for calls and prompt them with
"login:" and "Password:", so that they think we are a regular
UNIX system. If we aren't in endless loop mode, we have been
called by some other system. If flogin is TRUE, we prompt
with "login:" and "Password:" a single time. */
fret = TRUE;
zsystem = NULL;
if (! fconn_init (qport, &sconn, tstdintype))
fret = FALSE;
if (qport != NULL)
{
/* We are not using standard input. Detach from the
controlling terminal, so that the port we are about to
use becomes our controlling terminal. */
if (fdetach
&& qport->uuconf_ttype != UUCONF_PORTTYPE_STDIN)
usysdep_detach ();
}
if (fconn_lock (&sconn, TRUE, FALSE))
flocked = TRUE;
else
{
flocked = FALSE;
ulog (LOG_ERROR, "%s: Port already locked",
qport->uuconf_zname);
fret = FALSE;
}
if (fret)
{
if (! fconn_open (&sconn, (long) 0, (long) 0, TRUE, FALSE))
fret = FALSE;
qConn = &sconn;
}
if (fret)
{
if (fendless)
{
while (! FGOT_SIGNAL ()
&& flogin_prompt (puuconf, zconfig, fuuxqt, &sconn,
(const char *) NULL,
(const char **) NULL))
{
/* Close and reopen the port in between calls. */
if (! fconn_close (&sconn, puuconf,
(struct uuconf_dialer *) NULL,
TRUE)
|| ! fconn_open (&sconn, (long) 0, (long) 0, TRUE,
FALSE))
break;
}
fret = FALSE;
}
else
{
if (flogin)
fret = flogin_prompt (puuconf, zconfig, fuuxqt, &sconn,
zlogin, &zsystem);
else
{
#if DEBUG > 1
iholddebug = iDebug;
#endif
if (zlogin == NULL)
zlogin = zsysdep_login_name ();
fret = faccept_call (puuconf, zconfig, fuuxqt, zlogin,
&sconn, &zsystem);
#if DEBUG > 1
iDebug = iholddebug;
#endif
}
}
}
if (qConn != NULL)
{
if (! fconn_close (&sconn, puuconf, (struct uuconf_dialer *) NULL,
fret))
fret = FALSE;
qConn = NULL;
}
if (flocked)
(void) fconn_unlock (&sconn);
uconn_free (&sconn);
}
ulog_close ();
ustats_close ();
/* If we got a SIGTERM, perhaps because the system is going down,
don't run uuxqt. We go ahead and run it for any other signal,
since I think they indicate more temporary conditions. */
if (afSignal[INDEXSIG_SIGTERM])
fuuxqt = FALSE;
if (fuuxqt)
{
int irunuuxqt;
iuuconf = uuconf_runuuxqt (puuconf, &irunuuxqt);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
else if (irunuuxqt == UUCONF_RUNUUXQT_ONCE)
{
/* Detach from the controlling terminal before starting up uuxqt,
so that it runs as a true daemon. */
if (fdetach)
usysdep_detach ();
if (! fspawn_uuxqt (FALSE, zsystem, zconfig))
fret = FALSE;
}
}
usysdep_exit (fret);
/* Avoid complaints about not returning. */
return 0;
}
/* Print out a usage message and die. */
static void
uusage (void)
{
fprintf (stderr, "Usage: %s [options]\n", zProgram);
fprintf (stderr, "Use %s --help for help\n", zProgram);
exit (EXIT_FAILURE);
}
/* Print a help message. */
static void
uhelp (void)
{
printf ("Taylor UUCP %s, copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n",
VERSION);
printf ("Usage: %s [options]\n", zProgram);
printf (" -s,-S,--system system: Call system (-S implies -f)\n");
printf (" -f,--force: Force call despite system status\n");
printf (" -r state: 1 for master, 0 for slave (default)\n");
printf (" --master: Act as master\n");
printf (" --slave: Act as slave (default)\n");
printf (" -p,--port port: Specify port\n");
printf (" -l,--prompt: Prompt for login name and password\n");
printf (" -e,--loop: Endless loop of login prompts and daemon execution\n");
printf (" -w,--wait: After calling out, wait for incoming calls\n");
printf (" -q,--nouuxqt: Don't start uuxqt when done\n");
printf (" -c,--quiet: Don't log bad time or no work warnings\n");
printf (" -C,--ifwork: Only call named system if there is work\n");
printf (" -D,--nodetach: Don't detach from controlling terminal\n");
printf (" -u,--login: Set login name (privileged users only)\n");
printf (" -i,--stdin type: Type of standard input (only TLI supported)\n");
printf (" -z,--try-next: If a call fails, try the next alternate\n");
printf (" -x,-X,--debug debug: Set debugging level\n");
#if HAVE_TAYLOR_CONFIG
printf (" -I,--config file: Set configuration file to use\n");
#endif /* HAVE_TAYLOR_CONFIG */
printf (" -v,--version: Print version and exit\n");
printf (" --help: Print help and exit\n");
printf ("Report bugs to [email protected]\n");
}
/* This function is called when a LOG_FATAL error occurs. */
static void
uabort (void)
{
if (fLocked_system)
ufailed (&sDaemon);
ulog_user ((const char *) NULL);
if (qConn != NULL)
{
(void) fconn_close (qConn, pUuconf, (struct uuconf_dialer *) NULL,
FALSE);
(void) fconn_unlock (qConn);
uconn_free (qConn);
}
if (fLocked_system)
{
(void) fsysdep_unlock_system (&sLocked_system);
fLocked_system = FALSE;
}
ulog_system ((const char *) NULL);
ulog_close ();
ustats_close ();
usysdep_exit (FALSE);
}
/* The number of seconds in one day. We must cast to long for this
to be calculated correctly on a machine with 16 bit ints. */
#define SECS_PER_DAY ((long) 24 * (long) 60 * (long) 60)
/* Call another system, trying all the possible sets of calling
instructions. The qsys argument is the system to call. The qport
argument is the port to use, and may be NULL. If the fifwork
argument is TRUE, the call is only placed if there is work to be
done. If the fforce argument is TRUE, a call is forced even if not
enough time has passed since the last failed call. If the fquiet
argument is FALSE (the normal case), then a warning is given if
calls are not permitted at this time. */
static boolean
fcall (puuconf, zconfig, fuuxqt, qorigsys, qport, fifwork, fforce, fdetach,
fquiet, ftrynext)
pointer puuconf;
const char *zconfig;
boolean fuuxqt;
const struct uuconf_system *qorigsys;
struct uuconf_port *qport;
boolean fifwork;
boolean fforce;
boolean fdetach;
boolean fquiet;
boolean ftrynext;
{
struct sstatus sstat;
long inow;
boolean fbadtime, fnevertime, ffoundwork;
const struct uuconf_system *qsys;
if (! fsysdep_get_status (qorigsys, &sstat, (boolean *) NULL))
return FALSE;
ubuffree (sstat.zstring);
/* Make sure it's been long enough since the last failed call, and
that we haven't exceeded the maximum number of retries. Even if
we are over the limit on retries, we permit a call to be made if
24 hours have passed. This 24 hour limit is still controlled by
the retry time. We ignore times in the future, presumably the
result of some sort of error. */
inow = ixsysdep_time ((long *) NULL);
if (! fforce)
{
if (qorigsys->uuconf_cmax_retries > 0
&& sstat.cretries >= qorigsys->uuconf_cmax_retries
&& sstat.ilast <= inow
&& sstat.ilast + SECS_PER_DAY > inow)
{
ulog (LOG_ERROR, "Too many retries");
return FALSE;
}
if ((sstat.ttype == STATUS_COMPLETE
? sstat.ilast + qorigsys->uuconf_csuccess_wait > inow
: sstat.ilast + sstat.cwait > inow)
&& sstat.ilast <= inow)
{
ulog (LOG_NORMAL, "Retry time not reached");
return FALSE;
}
}
sDaemon.puuconf = puuconf;
sDaemon.zconfig = zconfig;
if (! fuuxqt)
sDaemon.irunuuxqt = UUCONF_RUNUUXQT_NEVER;
else
{
int iuuconf;
iuuconf = uuconf_runuuxqt (puuconf, &sDaemon.irunuuxqt);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
}
fbadtime = TRUE;
fnevertime = TRUE;
ffoundwork = FALSE;
for (qsys = qorigsys; qsys != NULL; qsys = qsys->uuconf_qalternate)
{
int cretry;
boolean fany, fret, fcalled;
if (FGOT_SIGNAL ())
return FALSE;
if (! qsys->uuconf_fcall || qsys->uuconf_qtimegrade == NULL)
continue;
/* If a port was specified, and this alternate does not use the
specified port, but a later alternate does use the specified
port, skip this alternate. This permits specifying a port as
a way to select a particular alternate. There probably ought
to be a way to select a specific alternate, but there isn't. */
if (qport != NULL
&& (qsys->uuconf_qport != NULL
|| (qsys->uuconf_zport != NULL
&& strcmp (qport->uuconf_zname, qsys->uuconf_zport) != 0)))
{
const struct uuconf_system *ql;
for (ql = qsys->uuconf_qalternate;
ql != NULL;
ql = ql->uuconf_qalternate)
{
if (ql->uuconf_qport == NULL
&& ql->uuconf_zport != NULL
&& strcmp (ql->uuconf_zport, qport->uuconf_zname) == 0)
break;
}
if (ql != NULL)
continue;
}
fnevertime = FALSE;
/* Make sure this is a legal time to call. */
if (! ftimespan_match (qsys->uuconf_qtimegrade, (long *) NULL,
&cretry))
continue;
fbadtime = FALSE;
sDaemon.qsys = qsys;
sDaemon.zlocalname = NULL;
sDaemon.qconn = NULL;
sDaemon.qproto = NULL;
sDaemon.cchans = 1;
sDaemon.clocal_size = -1;
sDaemon.cremote_size = -1;
sDaemon.cmax_ever = -2;
sDaemon.cmax_receive = -1;
sDaemon.csent = 0;
sDaemon.creceived = 0;
sDaemon.cxfiles_received = 0;
sDaemon.ifeatures = 0;
sDaemon.frequest_hangup = FALSE;
sDaemon.fhangup_requested = FALSE;
sDaemon.fhangup = FALSE;
sDaemon.fmaster = TRUE;
sDaemon.fcaller = TRUE;
sDaemon.ireliable = 0;
sDaemon.bgrade = '\0';
/* Queue up any work there is to do. */
if (! fqueue (&sDaemon, &fany))