-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuux.c
1712 lines (1478 loc) · 42.7 KB
/
uux.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
/* uux.c
Prepare to execute a command on a remote 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 uux_rcsid[] = "$Id$";
#endif
#include "uudefs.h"
#include "uuconf.h"
#include "system.h"
#include "sysdep.h"
#include "getopt.h"
#include <ctype.h>
#include <errno.h>
#if HAVE_SYSEXITS_H
#include <sysexits.h>
#endif
#ifndef EX_OK
#define EX_OK (0)
#endif
#ifndef EX_USAGE
#define EX_USAGE (64)
#endif
#ifndef EX_DATAERR
#define EX_DATAERR (65)
#endif
#ifndef EX_NOINPUT
#define EX_NOINPUT (66)
#endif
#ifndef EX_UNAVAILABLE
#define EX_UNAVAILABLE (69)
#endif
#ifndef EX_OSERR
#define EX_OSERR (71)
#endif
#ifndef EX_CANTCREAT
#define EX_CANTCREAT (73)
#endif
#ifndef EX_TEMPFAIL
#define EX_TEMPFAIL (75)
#endif
#ifndef EX_CONFIG
#define EX_CONFIG (78)
#endif
/* These character lists should, perhaps, be in sysdep.h. */
/* This is the list of shell metacharacters that we check for. If one
of these is present, we request uuxqt to execute the command with
/bin/sh. Otherwise we let it execute using execve. */
#define ZSHELLCHARS "\"'`*?[;&()|<>\\$"
/* This is the list of word separators. We break filename arguments
at these characters. */
#define ZSHELLSEPS ";&*|<> \t"
/* This is the list of word separators without the redirection
operators. */
#define ZSHELLNONREDIRSEPS ";&*| \t"
/* Whether we need to backslash quote the entries in the execution
file. */
static boolean fXquote;
/* Whether we have output the 'Q' command required for quoting. */
static boolean fXquote_output;
/* Whether this execution is occurring on the local system. */
static boolean fXxqtlocal;
/* The execution system. */
static struct uuconf_system sXxqtsys;
/* The name of local system from the point of view of the execution
system. */
static const char *zXxqtloc;
/* The job grade to use. */
static char bXgrade = BDEFAULT_UUX_GRADE;
/* The temporary file name of the execute file. */
static char abXxqt_tname[CFILE_NAME_LEN];
/* The name of the execute file on the remote system. */
static char abXxqt_xname[CFILE_NAME_LEN];
/* The execute file we are creating. */
static FILE *eXxqt_file;
/* A list of commands to be spooled. */
static struct scmd *pasXcmds;
static int cXcmds;
/* A file to close if we're forced to exit. */
static FILE *eXclose;
/* A list of file names which will match the file names which appear
in the uucico logs. */
static char *zXnames;
/* Local functions. */
static void uxusage P((void));
static void uxhelp P((void));
static void uxadd_xqt_line P((int bchar, const char *z1, const char *z2));
static void uxadd_send_file P((const char *zfrom, const char *zto,
const char *zoptions, const char *ztemp,
const char *zforward));
static void uxcopy_stdin P((FILE *e));
static void uxrecord_file P((const char *zfile));
static void uxfatal P((void));
static void uxabort P((int istat));
static void uxadd_name P((const char *));
/* Long getopt options. */
static const struct option asXlongopts[] =
{
{ "requestor", required_argument, NULL, 'a' },
{ "return-stdin", no_argument, NULL, 'b' },
{ "nocopy", no_argument, NULL, 'c' },
{ "copy", no_argument, NULL, 'C' },
{ "grade", required_argument, NULL, 'g' },
{ "jobid", no_argument, NULL, 'j' },
{ "link", no_argument, NULL, 'l' },
{ "notification", required_argument, NULL, 2 },
{ "stdin", no_argument, NULL, 'p' },
{ "nouucico", no_argument, NULL, 'r' },
{ "status", required_argument, NULL, 's' },
{ "noexpand", no_argument, NULL, 'W' },
{ "config", required_argument, NULL, 'I' },
{ "debug", required_argument, NULL, 'x' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 1 },
{ NULL, 0, NULL, 0 }
};
/* The main routine. */
int
main (int argc, char **argv)
{
/* -a: requestor address for status reports. */
const char *zrequestor = NULL;
/* -b: if true, return standard input on error. */
boolean fretstdin = FALSE;
/* -c,-C: if true, copy to spool directory. */
boolean fcopy = FALSE;
/* -c: set if -c appears explicitly; if it and -l appear, then if the
link fails we don't copy the file. */
boolean fdontcopy = FALSE;
/* -I: configuration file name. */
const char *zconfig = NULL;
/* -j: output job id. */
boolean fjobid = FALSE;
/* -l: link file to spool directory. */
boolean flink = FALSE;
/* -n: do not notify upon command completion. */
boolean fno_ack = FALSE;
/* -p: read standard input for command standard input. */
boolean fread_stdin = FALSE;
/* -r: do not start uucico when finished. */
boolean fuucico = TRUE;
/* -s: report status to named file. */
const char *zstatus_file = NULL;
/* -W: only expand local file names. */
boolean fexpand = TRUE;
/* -z: report status only on error. */
boolean ferror_ack = FALSE;
int iopt;
pointer puuconf;
int iuuconf;
const char *zlocalname;
int i;
size_t clen;
char *zargs;
char *zarg;
char *zcmd;
const char *zsys;
char *zexclam;
boolean fgetcwd;
const char *zuser;
char *zforward;
char **pzargs;
int calloc_args;
int cargs;
const char *zinput_from;
const char *zinput_to;
const char *zinput_temp;
boolean finputcopied;
char *zcall_system;
boolean fcall_any;
struct uuconf_system slocalsys;
boolean fneedshell;
char *zfullcmd;
boolean fpoll;
char aboptions[10];
zProgram = argv[0];
ulog_fatal_fn (uxfatal);
/* We need to be able to read a single - as an option, which getopt
won't do. We handle this by using getopt to scan the argument
list multiple times, replacing any single "-" with "-p". */
opterr = 0;
while (1)
{
while (getopt_long (argc, argv, "+a:bcCg:I:jlnprs:Wvx:z",
asXlongopts, (int *) NULL) != EOF)
;
if (optind >= argc || strcmp (argv[optind], "-") != 0)
break;
argv[optind] = zbufcpy ("-p");
optind = 0;
}
opterr = 1;
optind = 0;
/* The leading + in the getopt string means to stop processing
options as soon as a non-option argument is seen. */
while ((iopt = getopt_long (argc, argv, "+a:bcCg:I:jlnprs:Wvx:z",
asXlongopts, (int *) NULL)) != EOF)
{
switch (iopt)
{
case 'a':
/* Set requestor name: mail address to which status reports
should be sent. */
zrequestor = optarg;
break;
case 'b':
/* Return standard input on error. */
fretstdin = TRUE;
break;
case 'c':
/* Do not copy local files to spool directory. */
fcopy = FALSE;
fdontcopy = TRUE;
break;
case 'C':
/* Copy local files to spool directory. */
fcopy = TRUE;
break;
case 'I':
/* Configuration file name. */
if (fsysdep_other_config (optarg))
zconfig = optarg;
break;
case 'j':
/* Output jobid. */
fjobid = TRUE;
break;
case 'g':
/* Set job grade. */
bXgrade = optarg[0];
break;
case 'l':
/* Link file to spool directory. */
flink = TRUE;
break;
case 'n':
/* Do not notify upon command completion. */
fno_ack = TRUE;
break;
case 'p':
/* Read standard input for command standard input. */
fread_stdin = TRUE;
break;
case 'r':
/* Do not start uucico when finished. */
fuucico = FALSE;
break;
case 's':
/* Report status to named file. */
zstatus_file = optarg;
break;
case 'W':
/* Only expand local file names. */
fexpand = FALSE;
break;
case 'x':
#if DEBUG > 1
/* Set debugging level. */
iDebug |= idebug_parse (optarg);
#endif
break;
case 'z':
/* Report status only on error. */
ferror_ack = TRUE;
break;
case 2:
/* --notify={true,false,error}. */
if (*optarg == 't'
|| *optarg == 'T'
|| *optarg == 'y'
|| *optarg == 'Y'
|| *optarg == 'e'
|| *optarg == 'E')
{
ferror_ack = TRUE;
fno_ack = FALSE;
}
else if (*optarg == 'f'
|| *optarg == 'F'
|| *optarg == 'n'
|| *optarg == 'N')
{
ferror_ack = FALSE;
fno_ack = TRUE;
}
break;
case 'v':
/* Print version and exit. */
printf ("uux (Taylor UUCP) %s\n", VERSION);
printf ("Copyright (C) 1991, 92, 93, 94, 1995, 2002 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 (EX_OK);
/*NOTREACHED*/
case 1:
/* --help. */
uxhelp ();
exit (EX_OK);
/*NOTREACHED*/
case 0:
/* Long option found and flag set. */
break;
default:
uxusage ();
break;
}
}
if (! UUCONF_GRADE_LEGAL (bXgrade)
|| ((bXgrade < '0' || bXgrade > '9')
&& (bXgrade < 'a' || bXgrade > 'z')
&& (bXgrade < 'A' || bXgrade > 'Z')))
{
ulog (LOG_ERROR, "Ignoring illegal grade");
bXgrade = BDEFAULT_UUX_GRADE;
}
/* Check whether we need backslash quoting in the executable file.
We always break up the command arguments at spaces anyhow, so we
don't have to worry about them. Note that this means that
certain commands aren't supported. */
if ((zrequestor != NULL
&& zrequestor[strcspn (zrequestor, " \t\n")] != '\0')
|| (zstatus_file != NULL
&& zstatus_file[strcspn (zstatus_file, " \t\n")] != '\0'))
fXquote = TRUE;
if (optind == argc)
uxusage ();
iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
#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
/* The command and files arguments could be quoted in any number of
ways, so we split them apart ourselves. We do this before
calling usysdep_initialize because we want to set fgetcwd
correctly. */
clen = 1;
for (i = optind; i < argc; i++)
clen += strlen (argv[i]) + 1;
zargs = zbufalc (clen);
*zargs = '\0';
for (i = optind; i < argc; i++)
{
strcat (zargs, argv[i]);
strcat (zargs, " ");
}
/* The first argument is the command to execute. */
clen = strcspn (zargs, ZSHELLSEPS);
zcmd = zbufalc (clen + 1);
strncpy (zcmd, zargs, clen);
zcmd[clen] = '\0';
zargs += clen;
/* Split the arguments out into an array. We break the arguments
into alternating sequences of characters not in ZSHELLSEPS
and characters in ZSHELLSEPS. We remove whitespace. We
separate the redirection characters '>' and '<' into their
own arguments to make them easier to process below. */
calloc_args = 10;
pzargs = (char **) xmalloc (calloc_args * sizeof (char *));
cargs = 0;
for (zarg = strtok (zargs, " \t");
zarg != NULL;
zarg = strtok ((char *) NULL, " \t"))
{
while (*zarg != '\0')
{
if (cargs + 1 >= calloc_args)
{
calloc_args += 10;
pzargs = (char **) xrealloc ((pointer) pzargs,
calloc_args * sizeof (char *));
}
if (*zarg == '(')
clen = strlen (zarg);
else
clen = strcspn (zarg, ZSHELLSEPS);
if (clen > 0)
{
pzargs[cargs] = zbufalc (clen + 1);
memcpy (pzargs[cargs], zarg, clen);
pzargs[cargs][clen] = '\0';
++cargs;
zarg += clen;
}
/* We deliberately separate '>' and '<' out. */
if (*zarg != '\0')
{
clen = strspn (zarg, ZSHELLNONREDIRSEPS);
if (clen == 0)
clen = 1;
pzargs[cargs] = zbufalc (clen + 1);
memcpy (pzargs[cargs], zarg, clen);
pzargs[cargs][clen] = '\0';
++cargs;
zarg += clen;
}
}
}
/* Now look through the arguments to see if we are going to need the
current working directory. We don't try to make a precise
determination, just a conservative one. The basic idea is that
we don't want to get the cwd for 'foo!rmail - user' (note that we
don't examine the command itself). */
fgetcwd = FALSE;
for (i = 0; i < cargs; i++)
{
if (pzargs[i][0] == '(')
continue;
zexclam = strrchr (pzargs[i], '!');
if (zexclam != NULL && fsysdep_needs_cwd (zexclam + 1))
{
fgetcwd = TRUE;
break;
}
if ((pzargs[i][0] == '<' || pzargs[i][0] == '>')
&& i + 1 < cargs
&& strchr (pzargs[i + 1], '!') == NULL
&& fsysdep_needs_cwd (pzargs[i + 1]))
{
fgetcwd = TRUE;
break;
}
}
#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 | (fgetcwd ? INIT_GETCWD : 0));
zuser = zsysdep_login_name ();
/* Get the local system name. */
iuuconf = uuconf_localname (puuconf, &zlocalname);
if (iuuconf == UUCONF_NOT_FOUND)
{
zlocalname = zsysdep_localname ();
if (zlocalname == NULL)
exit (EX_CONFIG);
}
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
/* Get the local system information. */
iuuconf = uuconf_system_info (puuconf, zlocalname, &slocalsys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
iuuconf = uuconf_system_local (puuconf, &slocalsys);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
slocalsys.uuconf_zname = (char *) zlocalname;
}
/* Figure out which system the command is to be executed on. */
zcmd = zremove_local_sys (&slocalsys, zcmd);
zexclam = strchr (zcmd, '!');
if (zexclam == NULL)
{
zsys = zlocalname;
fXxqtlocal = TRUE;
zforward = NULL;
}
else
{
*zexclam = '\0';
zsys = zcmd;
zcmd = zexclam + 1;
fXxqtlocal = FALSE;
/* See if we must forward this command through other systems
(e.g. uux a!b!cmd). */
zexclam = strrchr (zcmd, '!');
if (zexclam == NULL)
zforward = NULL;
else
{
clen = zexclam - zcmd;
zforward = zbufalc (clen + 1);
memcpy (zforward, zcmd, clen);
zforward[clen] = '\0';
zcmd = zexclam + 1;
}
}
if (fXxqtlocal)
sXxqtsys = slocalsys;
else
{
iuuconf = uuconf_system_info (puuconf, zsys, &sXxqtsys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (! funknown_system (puuconf, zsys, &sXxqtsys))
ulog (LOG_FATAL, "%s: System not found", zsys);
}
}
/* Get the local name the remote system know us as. */
zXxqtloc = sXxqtsys.uuconf_zlocalname;
if (zXxqtloc == NULL)
zXxqtloc = zlocalname;
/* Look through the arguments. Any argument containing an
exclamation point character is interpreted as a file name, and is
sent to the appropriate system. */
zinput_from = NULL;
zinput_to = NULL;
zinput_temp = NULL;
finputcopied = FALSE;
zcall_system = NULL;
fcall_any = FALSE;
for (i = 0; i < cargs; i++)
{
const char *zsystem;
char *zfile;
char *zforw;
boolean finput, foutput;
boolean flocal, fonxqt;
/* Check for a parenthesized argument; remove the parentheses
and otherwise ignore it (this is how an exclamation point is
quoted). */
if (pzargs[i][0] == '(')
{
clen = strlen (pzargs[i]);
if (pzargs[i][clen - 1] != ')')
ulog (LOG_ERROR, "Mismatched parentheses");
else
pzargs[i][clen - 1] = '\0';
++pzargs[i];
continue;
}
/* Check whether we are doing a redirection. */
finput = FALSE;
foutput = FALSE;
if (i + 1 < cargs)
{
if (pzargs[i][0] == '<')
finput = TRUE;
else if (pzargs[i][0] == '>')
foutput = TRUE;
if (finput || foutput)
{
pzargs[i] = NULL;
i++;
}
}
zexclam = strchr (pzargs[i], '!');
/* If there is no exclamation point and no redirection, this
argument is left untouched. */
if (zexclam == NULL && ! finput && ! foutput)
continue;
if (zexclam != NULL)
{
pzargs[i] = zremove_local_sys (&slocalsys, pzargs[i]);
zexclam = strchr (pzargs[i], '!');
}
/* Get the system name and file name for this file. */
if (zexclam == NULL)
{
zsystem = zlocalname;
zfile = pzargs[i];
flocal = TRUE;
zforw = NULL;
}
else
{
*zexclam = '\0';
zsystem = pzargs[i];
zfile = zexclam + 1;
flocal = FALSE;
zexclam = strrchr (zfile, '!');
if (zexclam == NULL)
zforw = NULL;
else
{
*zexclam = '\0';
zforw = zfile;
zfile = zexclam + 1;
}
}
/* Check if the file is already on the execution system. */
if (flocal)
fonxqt = fXxqtlocal;
else if (fXxqtlocal)
fonxqt = FALSE;
else if (zforward == NULL ? zforw != NULL : zforw == NULL)
fonxqt = FALSE;
else if (zforward != NULL
&& zforw != NULL
&& strcmp (zforward, zforw) != 0)
fonxqt = FALSE;
else if (strcmp (zsystem, sXxqtsys.uuconf_zname) == 0)
fonxqt = TRUE;
else if (sXxqtsys.uuconf_pzalias == NULL)
fonxqt = FALSE;
else
{
char **pzal;
fonxqt = FALSE;
for (pzal = sXxqtsys.uuconf_pzalias; *pzal != NULL; pzal++)
{
if (strcmp (zsystem, *pzal) == 0)
{
fonxqt = TRUE;
break;
}
}
}
/* Turn the file into an absolute path. */
if (flocal)
zfile = zsysdep_local_file_cwd (zfile, sXxqtsys.uuconf_zpubdir,
(boolean *) NULL);
else if (fexpand)
zfile = zsysdep_add_cwd (zfile);
if (zfile == NULL)
uxabort (EX_OSERR);
/* Check for output redirection. */
if (foutput)
{
if (flocal)
{
if (! fin_directory_list (zfile,
sXxqtsys.uuconf_pzremote_receive,
sXxqtsys.uuconf_zpubdir, TRUE,
FALSE, (const char *) NULL))
ulog (LOG_FATAL, "Not permitted to create %s", zfile);
}
/* There are various cases of output redirection.
uux cmd >out: The command is executed on the local
system, and the output file is placed on the local
system (fonxqt is TRUE).
uux cmd >a!out: The command is executed on the local
system, and the output file is sent to a.
uux a!cmd >out: The command is executed on a, and the
output file is returned to the local system (flocal
is TRUE).
uux a!cmd >a!out: The command is executed on a, and the
output file is left on a (fonxqt is TRUE).
uux a!cmd >b!out: The command is executed on a, and the
output file is sent to b; traditionally, I believe
that b is relative to a, rather than to the local
system. However, this essentially contradicts the
previous two cases, in which the output file is
relative to the local system.
Now, the cases that we don't handle.
uux cmd >a!b!out: The command is executed on the local
system, and the output file is sent to b via a. This
requires the local uuxqt to support forwarding of the
output file.
uux a!b!cmd >out: The command is executed on b, which is
reached via a. Probably the output file is intended
for the local system, in which case the uuxqt on b
must support forwarding of the output file.
uux a!b!cmd >c!out: Is c relative to b or to the local
system? If it's relative to b this is easy to
handle. Otherwise, we must arrange for the file to
be sent back to the local system and for the local
system to send it on to c.
There are many variations of the last case. It's not at
all clear to me how they should be handled. */
if (zforward != NULL || zforw != NULL)
ulog (LOG_FATAL, "May not forward standard output");
if (fonxqt)
uxadd_xqt_line ('O', zfile, (const char *) NULL);
else if (flocal)
uxadd_xqt_line ('O', zfile, zXxqtloc);
else
uxadd_xqt_line ('O', zfile, zsystem);
pzargs[i] = NULL;
continue;
}
if (finput)
{
if (fread_stdin)
ulog (LOG_FATAL, "Standard input specified twice");
pzargs[i] = NULL;
}
if (flocal)
{
char *zuse;
char *zdata;
char abtname[CFILE_NAME_LEN];
char abdname[CFILE_NAME_LEN];
/* It's a local file. If requested by -C, copy the file to
the spool directory. If requested by -l, link the file
to the spool directory; if the link fails, we copy the
file, unless -c was explictly used. If the execution is
occurring on the local system, we force the copy as well,
because otherwise we would have to have some way to tell
uuxqt not to move the file. If the file is being shipped
to another system, we must set up a transfer request.
First make sure the user has legitimate access, since we
are running setuid. */
if (! fsysdep_access (zfile))
uxabort (EX_NOINPUT);
zdata = zsysdep_data_file_name (&sXxqtsys, zXxqtloc, bXgrade, FALSE,
abtname, abdname, (char *) NULL);
if (zdata == NULL)
uxabort (EX_OSERR);
if (fcopy || flink || fXxqtlocal)
{
boolean fdid;
uxrecord_file (zdata);
fdid = FALSE;
if (flink)
{
boolean fworked;
if (! fsysdep_link (zfile, zdata, &fworked))
uxabort (EX_OSERR);
if (fworked)
fdid = TRUE;
else if (fdontcopy)
ulog (LOG_FATAL, "%s: Can't link to spool directory",
zfile);
}
if (! fdid)
{
openfile_t efile;
efile = esysdep_user_fopen (zfile, TRUE, TRUE);
if (! ffileisopen (efile))
uxabort (EX_NOINPUT);
if (! fcopy_open_file (efile, zdata, FALSE, TRUE, TRUE))
uxabort (EX_CANTCREAT);
(void) ffileclose (efile);
}
zuse = abtname;
}
else
{
/* We don't actually use the spool file name, but we
need a name to use as the destination. */
ubuffree (zdata);
/* Make sure the daemon can access the file. */
if (! fsysdep_daemon_access (zfile))
uxabort (EX_NOINPUT);
if (! fin_directory_list (zfile, sXxqtsys.uuconf_pzlocal_send,
sXxqtsys.uuconf_zpubdir, TRUE,
TRUE, zuser))
ulog (LOG_FATAL, "Not permitted to send from %s",
zfile);
zuse = zfile;
}
if (fXxqtlocal)
{
if (finput)
uxadd_xqt_line ('I', zuse, (char *) NULL);
else
pzargs[i] = zuse;
}
else
{
finputcopied = fcopy || flink;
if (finput)
{
zinput_from = zuse;
zinput_to = zbufcpy (abdname);
zinput_temp = zbufcpy (abtname);
}
else
{
char *zbase;
uxadd_send_file (zuse, abdname,
finputcopied ? "C" : "c",
abtname, zforward);
zbase = zsysdep_base_name (zfile);
if (zbase == NULL)
uxabort (EX_OSERR);
uxadd_xqt_line ('F', abdname, zbase);
pzargs[i] = zbase;
}
}
}
else if (fonxqt)
{
/* The file is already on the system where the command is to
be executed. */
if (finput)
uxadd_xqt_line ('I', zfile, (const char *) NULL);
else
pzargs[i] = zfile;
}
else
{
struct uuconf_system sfromsys;
char abtname[CFILE_NAME_LEN];
struct scmd s;
char *zjobid;
/* We need to request a remote file. */
iuuconf = uuconf_system_info (puuconf, zsystem, &sfromsys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (! funknown_system (puuconf, zsystem, &sfromsys))
ulog (LOG_FATAL, "%s: System not found", zsystem);
}
if (fonxqt)
{
/* The file is already on the system where the command is to
be executed. */
if (finput)
uxadd_xqt_line ('I', zfile, (const char *) NULL);
else
pzargs[i] = zfile;
}
else
{
char *zdata;
boolean ftemp;
if (! sfromsys.uuconf_fcall_transfer
&& ! sfromsys.uuconf_fcalled_transfer)
ulog (LOG_FATAL,
"Not permitted to transfer files to or from %s",
sfromsys.uuconf_zname);
if (zforw != NULL)
{
/* This is ``uux cmd a!b!file''. To make this work,
we would have to be able to set up a request to a
to fetch file from b and send it to us. But it
turns out that that will not work, because when a
sends us the file we will put it in a's spool
directory, not the local system spool directory.
So we won't have any way to find it. This is not
a conceptual problem, and it could doubtless be
solved. Please feel free to solve it and send me
the solution. */
ulog (LOG_FATAL, "File forwarding not supported");
}
/* We must request the file from the remote system to
this one. */
zdata = zsysdep_data_file_name (&slocalsys, zXxqtloc, bXgrade,
FALSE, abtname, (char *) NULL,
(char *) NULL);
if (zdata == NULL)
uxabort (EX_OSERR);
ubuffree (zdata);
/* Request the file. The special option '9' is a signal
to uucico that it's OK to receive a file into the
spool directory; normally such requests are rejected.
This privilege is easy to abuse. */
s.bcmd = 'R';