-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuuxqt.c
1787 lines (1543 loc) · 43.9 KB
/
uuxqt.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
/* uuxqt.c
Run uux commands.
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 ian@airs.com.
*/
#include "uucp.h"
#if USE_RCS_ID
const char uuxqt_rcsid[] = "$Id$";
#endif
#include <errno.h>
#include <ctype.h>
#include "getopt.h"
#include "uudefs.h"
#include "uuconf.h"
#include "system.h"
/* Static variables used to unlock things if we get a fatal error. */
static int iQlock_seq = -1;
static const char *zQunlock_cmd;
static const char *zQunlock_file;
static boolean fQunlock_directory;
int cQmaxuuxqts;
/* Static variables to free in uqcleanup. */
static char *zQoutput;
static char *zQmail;
/* Local functions. */
static void uqusage P((void));
static void uqhelp P((void));
static void uqabort P((void));
static void uqdo_xqt_file P((pointer puuconf, const char *zfile,
const char *zbase,
const struct uuconf_system *qsys,
const char *zlocalname,
const char *zcmd, boolean *pfprocessed));
static void uqcleanup P((const char *zfile, int iflags));
static int isave_files P((const struct uuconf_system *, const char *zmail,
const char *zfile, int iclean));
static boolean fqforward P((const char *zfile, char **pzallowed,
const char *zlog, const char *zmail));
/* Long getopt options. */
static const struct option asQlongopts[] =
{
{ "command", required_argument, 0, 'c' },
{ "system", required_argument, 0, 's' },
{ "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)
{
/* The type of command to execute (NULL for any type). */
const char *zcmd = NULL;
/* The configuration file name. */
const char *zconfig = NULL;
/* The system to execute commands for. */
const char *zdosys = NULL;
int iopt;
pointer puuconf;
int iuuconf;
const char *zlocalname;
boolean fany;
char *z, *zgetsys;
boolean ferr;
boolean fsys;
struct uuconf_system ssys;
zProgram = argv[0];
while ((iopt = getopt_long (argc, argv, "c:I:s:vx:", asQlongopts,
(int *) NULL)) != EOF)
{
switch (iopt)
{
case 'c':
/* Set the type of command to execute. */
zcmd = optarg;
break;
case 'I':
/* Set the configuration file name. */
if (fsysdep_other_config (optarg))
zconfig = optarg;
break;
case 's':
zdosys = optarg;
break;
case 'x':
#if DEBUG > 1
/* Set the debugging level. */
iDebug |= idebug_parse (optarg);
#endif
break;
case 'v':
/* Print version and exit. */
printf ("uuxqt (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 (EXIT_SUCCESS);
/*NOTREACHED*/
case 1:
/* --help. */
uqhelp ();
exit (EXIT_SUCCESS);
/*NOTREACHED*/
case 0:
/* Long option found and flag set. */
break;
default:
uqusage ();
break;
}
}
if (optind != argc)
uqusage ();
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
iuuconf = uuconf_maxuuxqts (puuconf, &cQmaxuuxqts);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
#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 (uqabort);
iuuconf = uuconf_localname (puuconf, &zlocalname);
if (iuuconf == UUCONF_NOT_FOUND)
{
zlocalname = zsysdep_localname ();
if (zlocalname == NULL)
exit (EXIT_FAILURE);
}
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
fsys = FALSE;
/* If we were given a system name, canonicalize it. */
if (zdosys != NULL)
{
iuuconf = uuconf_system_info (puuconf, zdosys, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (strcmp (zdosys, zlocalname) == 0)
{
iuuconf = uuconf_system_local (puuconf, &ssys);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
ssys.uuconf_zname = (char *) zlocalname;
}
else
{
if (! funknown_system (puuconf, zdosys, &ssys))
ulog (LOG_FATAL, "%s: system not found", zdosys);
}
}
zdosys = zbufcpy (ssys.uuconf_zname);
fsys = TRUE;
}
/* Limit the number of uuxqt processes, and make sure we're the only
uuxqt daemon running for this command. */
iQlock_seq = ixsysdep_lock_uuxqt (zcmd, cQmaxuuxqts);
if (iQlock_seq < 0)
{
ulog_close ();
usysdep_exit (TRUE);
}
zQunlock_cmd = zcmd;
/* Keep scanning the execute files until we don't process any of
them. */
do
{
fany = FALSE;
/* Look for each execute file, and run it. */
if (! fsysdep_get_xqt_init (zdosys))
{
ulog_close ();
usysdep_exit (FALSE);
}
while ((z = zsysdep_get_xqt (zdosys, &zgetsys, &ferr)) != NULL)
{
const char *zloc;
boolean fprocessed;
char *zbase;
/* Get the system information for the system returned by
zsysdep_get_xqt. */
if (! fsys || strcmp (ssys.uuconf_zname, zgetsys) != 0)
{
if (fsys)
(void) uuconf_system_free (puuconf, &ssys);
iuuconf = uuconf_system_info (puuconf, zgetsys,
&ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf != UUCONF_NOT_FOUND)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
ubuffree (z);
ubuffree (zgetsys);
continue;
}
else if (strcmp (zgetsys, zlocalname) == 0)
{
iuuconf = uuconf_system_local (puuconf, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
ubuffree (z);
ubuffree (zgetsys);
continue;
}
ssys.uuconf_zname = (char *) zlocalname;
}
else
{
if (! funknown_system (puuconf, zgetsys, &ssys))
{
ulog (LOG_ERROR,
"%s: Execute file for unknown system %s",
z, zgetsys);
(void) remove (z);
ubuffree (z);
ubuffree (zgetsys);
continue;
}
}
}
fsys = TRUE;
}
/* If we've received a signal, get out of the loop. */
if (FGOT_SIGNAL ())
{
ubuffree (z);
ubuffree (zgetsys);
break;
}
/* Make sure we are supposed to be executing jobs for this
system. */
if (zdosys != NULL && strcmp (zdosys, ssys.uuconf_zname) != 0)
{
ubuffree (z);
ubuffree (zgetsys);
continue;
}
zloc = ssys.uuconf_zlocalname;
if (zloc == NULL)
zloc = zlocalname;
ulog_system (ssys.uuconf_zname);
zbase = zsysdep_base_name (z);
uqdo_xqt_file (puuconf, z, zbase, &ssys, zloc, zcmd, &fprocessed);
ubuffree (zbase);
ulog_system ((const char *) NULL);
ulog_user ((const char *) NULL);
if (fprocessed)
fany = TRUE;
ubuffree (z);
ubuffree (zgetsys);
}
usysdep_get_xqt_free (zdosys);
}
while (fany && ! FGOT_SIGNAL ());
(void) fsysdep_unlock_uuxqt (iQlock_seq, zcmd, cQmaxuuxqts);
iQlock_seq = -1;
ulog_close ();
if (FGOT_SIGNAL ())
ferr = TRUE;
usysdep_exit (! ferr);
/* Avoid errors about not returning a value. */
return 0;
}
static void
uqhelp (void)
{
printf ("Taylor UUCP %s, copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n",
VERSION);
printf ("Usage: %s [-c,--command cmd] [-s,--system system]\n", zProgram);
printf (" -c,--command cmd: Set type of command to execute\n");
printf (" -s,--system system: Execute commands only for named system\n");
printf (" -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 taylor-uucp@gnu.org\n");
}
static void
uqusage (void)
{
fprintf (stderr,
"Usage: %s [-c,--command cmd] [-s,--system system]\n", zProgram);
fprintf (stderr, "Use %s --help for help\n", zProgram);
exit (EXIT_FAILURE);
}
/* This is the abort function called when we get a fatal error. */
static void
uqabort (void)
{
#if ! HAVE_HDB_LOGGING
/* When using HDB logging, it's a pain to have no system name. */
ulog_system ((const char *) NULL);
#endif
ulog_user ((const char *) NULL);
if (fQunlock_directory)
(void) fsysdep_unlock_uuxqt_dir (iQlock_seq);
if (zQunlock_file != NULL)
(void) fsysdep_unlock_uuxqt_file (zQunlock_file);
if (iQlock_seq >= 0)
(void) fsysdep_unlock_uuxqt (iQlock_seq, zQunlock_cmd, cQmaxuuxqts);
ulog_close ();
usysdep_exit (FALSE);
}
/* An execute file is a series of lines. The first character of each
line is a command. The following commands are defined:
C command-line
I standard-input
O standard-output [ system ]
F required-file filename-to-use
R requestor-address
U user system
Z (acknowledge if command failed; default)
N (no acknowledgement on failure)
n (acknowledge if command succeeded)
B (return command input on error)
e (process with sh)
E (process with exec)
M status-file
Q (C, I, O, F, R, U, M arguments are backslash quoted)
# comment
Unrecognized commands are ignored. We actually do not recognize
the Z command, since it requests default behaviour. We always send
mail on failure, unless the N command appears. We never send mail
on success, unless the n command appears.
This code does not currently support the B or M commands. */
/* Command arguments. */
static char **azQargs;
/* Command as a complete string. */
static char *zQcmd;
/* Standard input file name. */
static char *zQinput;
/* Standard output file name. */
static char *zQoutfile;
/* Standard output system. */
static char *zQoutsys;
/* Number of required files. */
static int cQfiles;
/* Names of required files. */
static char **azQfiles;
/* Names required files should be renamed to (NULL if original is OK). */
static char **azQfiles_to;
/* Requestor address (this is where mail should be sent). */
static char *zQrequestor;
/* User name. */
static const char *zQuser;
/* System name. */
static const char *zQsystem;
/* This is set by the N flag, meaning that no acknowledgement should
be mailed on failure. */
static boolean fQno_ack;
/* This is set by the n flag, meaning that acknowledgement should be
mailed if the command succeeded. */
static boolean fQsuccess_ack;
/* This is set by the B flag, meaning that command input should be
mailed to the requestor if an error occurred. */
static boolean fQsend_input;
/* This is set by the E flag, meaning that exec should be used to
execute the command. */
static boolean fQuse_exec;
/* The status should be copied to this file on the requesting host. */
static const char *zQstatus_file;
/* Whether the entries in the file are backslash quoted. */
static boolean fQquoted;
#if ALLOW_SH_EXECUTION
/* This is set by the e flag, meaning that sh should be used to
execute the command. */
static boolean fQuse_sh;
#endif /* ALLOW_SH_EXECUTION */
static int iqcmd P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int iqout P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int iqfile P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int iqrequestor P((pointer puuconf, int argc, char **argv,
pointer pvar, pointer pinfo));
static int iquser P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int iqset P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
/* We are lax about the number of arguments the functions accept,
because there is a lot of variation in what other (buggy) UUCP
packages generate. Unused arguments are ignored. */
static const struct uuconf_cmdtab asQcmds[] =
{
{ "C", UUCONF_CMDTABTYPE_FN | 0, NULL, iqcmd },
{ "I", UUCONF_CMDTABTYPE_STRING, (pointer) &zQinput, NULL },
{ "O", UUCONF_CMDTABTYPE_FN | 0, NULL, iqout },
{ "F", UUCONF_CMDTABTYPE_FN | 0, NULL, iqfile },
{ "R", UUCONF_CMDTABTYPE_FN | 0, NULL, iqrequestor },
{ "U", UUCONF_CMDTABTYPE_FN | 0, NULL, iquser },
{ "N", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQno_ack, iqset },
{ "n", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQsuccess_ack, iqset },
{ "B", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQsend_input, iqset },
#if ALLOW_SH_EXECUTION
{ "e", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQuse_sh, iqset },
#endif
{ "E", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQuse_exec, iqset },
{ "M", UUCONF_CMDTABTYPE_STRING, (pointer) &zQstatus_file, NULL },
{ "Q", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQquoted, iqset },
{ NULL, 0, NULL, NULL }
};
/* Handle the C command: store off the arguments. */
/*ARGSUSED*/
static int
iqcmd (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
int i;
size_t clen;
if (argc <= 1)
return UUCONF_CMDTABRET_CONTINUE;
azQargs = (char **) xmalloc (argc * sizeof (char *));
clen = 0;
for (i = 1; i < argc; i++)
{
azQargs[i - 1] = zbufcpy (argv[i]);
clen += strlen (argv[i]) + 1;
}
azQargs[i - 1] = NULL;
zQcmd = (char *) xmalloc (clen);
zQcmd[0] = '\0';
for (i = 1; i < argc - 1; i++)
{
strcat (zQcmd, argv[i]);
strcat (zQcmd, " ");
}
strcat (zQcmd, argv[i]);
return UUCONF_CMDTABRET_CONTINUE;
}
/* Handle the O command, which may have one or two arguments. */
/*ARGSUSED*/
static int
iqout (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
if (argc > 1)
zQoutfile = zbufcpy (argv[1]);
if (argc > 2)
zQoutsys = zbufcpy (argv[2]);
return UUCONF_CMDTABRET_CONTINUE;
}
/* Handle the F command, which may have one or two arguments. */
/*ARGSUSED*/
static int
iqfile (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
if (argc < 2)
return UUCONF_CMDTABRET_CONTINUE;
/* If this file is not in the spool directory, just ignore it. */
if (! fspool_file (argv[1]))
return UUCONF_CMDTABRET_CONTINUE;
++cQfiles;
azQfiles = (char **) xrealloc ((pointer) azQfiles,
cQfiles * sizeof (char *));
azQfiles_to = (char **) xrealloc ((pointer) azQfiles_to,
cQfiles * sizeof (char *));
azQfiles[cQfiles - 1] = zbufcpy (argv[1]);
if (argc > 2)
azQfiles_to[cQfiles - 1] = zbufcpy (argv[2]);
else
azQfiles_to[cQfiles - 1] = NULL;
return UUCONF_CMDTABRET_CONTINUE;
}
/* Handle the R command, which may have one or two arguments. */
/*ARGSUSED*/
static int
iqrequestor (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
/* We normally have a single argument, which is the ``requestor''
address, to which we should send any success or error messages.
Apparently the DOS program UUPC sends two arguments, which are
the username and the host. */
if (argc == 2)
zQrequestor = zbufcpy (argv[1]);
else if (argc > 2)
{
zQrequestor = zbufalc (strlen (argv[1]) + strlen (argv[2])
+ sizeof "!");
sprintf (zQrequestor, "%s!%s", argv[2], argv[1]);
}
return UUCONF_CMDTABRET_CONTINUE;
}
/* Handle the U command, which takes two arguments. */
/*ARGSUSED*/
static int
iquser (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
if (argc > 1)
zQuser = argv[1];
if (argc > 2)
zQsystem = argv[2];
return UUCONF_CMDTABRET_KEEP;
}
/* Handle various commands which just set boolean variables. */
/*ARGSUSED*/
static int
iqset (pointer puuconf ATTRIBUTE_UNUSED, int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED, pointer pvar, pointer pinfo ATTRIBUTE_UNUSED)
{
boolean *pf = (boolean *) pvar;
*pf = TRUE;
return UUCONF_CMDTABRET_CONTINUE;
}
/* The execution processing does a lot of things that have to be
cleaned up. Rather than try to add the appropriate statements
to each return point, we keep a set of flags indicating what
has to be cleaned up. The actual clean up is done by the
function uqcleanup. */
#define REMOVE_FILE (01)
#define REMOVE_NEEDED (02)
#define FREE_QINPUT (04)
#define REMOVE_QINPUT (010)
#define FREE_OUTPUT (020)
#define FREE_MAIL (040)
/* Process an execute file. The zfile argument is the name of the
execute file. The zbase argument is the base name of zfile. The
qsys argument describes the system it came from. The zcmd argument
is the name of the command we are executing (from the -c option) or
NULL if any command is OK. This sets *pfprocessed to TRUE if the
file is ready to be executed. */
static void
uqdo_xqt_file (pointer puuconf, const char *zfile, const char *zbase, const struct uuconf_system *qsys, const char *zlocalname, const char *zcmd, boolean *pfprocessed)
{
char *zabsolute;
boolean ferr;
FILE *e;
int iuuconf;
int i;
int iclean;
const char *zmail;
char *zoutput;
char *zinput;
boolean fbadname;
char abtemp[CFILE_NAME_LEN];
char abdata[CFILE_NAME_LEN];
char *zerror;
struct uuconf_system soutsys;
const struct uuconf_system *qoutsys;
boolean fshell;
size_t clen;
char *zfullcmd;
boolean ftemp;
*pfprocessed = FALSE;
e = fopen (zfile, "r");
if (e == NULL)
return;
azQargs = NULL;
zQcmd = NULL;
zQinput = NULL;
zQoutfile = NULL;
zQoutsys = NULL;
cQfiles = 0;
azQfiles = NULL;
azQfiles_to = NULL;
zQrequestor = NULL;
zQuser = NULL;
zQsystem = NULL;
fQno_ack = FALSE;
fQsuccess_ack = FALSE;
fQsend_input = FALSE;
fQuse_exec = FALSE;
zQstatus_file = NULL;
fQquoted = FALSE;
#if ALLOW_SH_EXECUTION
fQuse_sh = FALSE;
#endif
iuuconf = uuconf_cmd_file (puuconf, e, asQcmds, (pointer) zbase,
(uuconf_cmdtabfn) NULL,
(UUCONF_CMDTABFLAG_CASE
| UUCONF_CMDTABFLAG_NOCOMMENTS),
(pointer) NULL);
(void) fclose (e);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
/* If we got a non-transient error, we notify the administrator.
We can't bounce it back to the original requestor, because we
don't know how to read the file to figure out who it is (it
would probably be possible to read the file and work it out,
but it doesn't seem worth it for such an unlikely error). */
if (UUCONF_ERROR_VALUE (iuuconf) == UUCONF_SYNTAX_ERROR
|| UUCONF_ERROR_VALUE (iuuconf) == UUCONF_UNKNOWN_COMMAND)
{
const char *az[20];
char *znew;
i = 0;
az[i++] = "The execution file\n\t";
az[i++] = zfile;
az[i++] = "\nfor system\n\t";
az[i++] = qsys->uuconf_zname;
az[i++] = "\nwas corrupt. ";
znew = zsysdep_save_corrupt_file (zfile);
if (znew == NULL)
{
az[i++] = "The file could not be preserved.\n";
(void) remove (zfile);
}
else
{
az[i++] = "It has been moved to\n\t";
az[i++] = znew;
az[i++] = "\n";
}
(void) fsysdep_mail (OWNER, "Corrupt execution file", i, az);
ubuffree (znew);
}
return;
}
if (fQquoted)
{
if (azQargs != NULL)
{
for (i = 0; azQargs[i] != NULL; ++i)
(void) cescape (azQargs[i]);
}
if (zQcmd != NULL)
(void) cescape (zQcmd);
if (zQinput != NULL)
(void) cescape (zQinput);
if (zQoutfile != NULL)
(void) cescape (zQoutfile);
if (zQoutsys != NULL)
(void) cescape (zQoutsys);
for (i = 0; i < cQfiles; ++i)
{
(void) cescape (azQfiles[i]);
if (azQfiles_to[i] != NULL)
(void) cescape (azQfiles_to[i]);
}
if (zQrequestor != NULL)
(void) cescape (zQrequestor);
if (zQuser != NULL)
(void) cescape ((char *) zQuser);
if (zQsystem != NULL)
(void) cescape ((char *) zQsystem);
if (zQstatus_file != NULL)
(void) cescape ((char *) zQstatus_file);
}
iclean = 0;
if (azQargs == NULL)
{
ulog (LOG_ERROR, "%s: No command given", zbase);
uqcleanup (zfile, iclean | REMOVE_FILE);
return;
}
if (zcmd != NULL)
{
if (strcmp (zcmd, azQargs[0]) != 0)
{
uqcleanup (zfile, iclean);
return;
}
}
else
{
/* If there is a lock file for this particular command already,
it means that some other uuxqt is supposed to handle it. */
if (fsysdep_uuxqt_locked (azQargs[0]))
{
uqcleanup (zfile, iclean);
return;
}
}
/* Lock this particular file. */
if (! fsysdep_lock_uuxqt_file (zfile))
{
uqcleanup (zfile, iclean);
return;
}
zQunlock_file = zfile;
/* Now that we have the file locked, make sure it still exists.
Otherwise another uuxqt could have just finished processing it
and removed the lock file. */
if (! fsysdep_file_exists (zfile))
{
uqcleanup (zfile, iclean);
return;
}
if (zQuser != NULL)
ulog_user (zQuser);
else if (zQrequestor != NULL)
ulog_user (zQrequestor);
else
ulog_user ("unknown");
/* zQsystem, if it is set, comes from the execution file, which
means that we do not trust it. We only retain it if
qsys->uuconf_zname is a prefix of it, since that can happen with
a job from an anonymous system on certain spool directory types,
and is unlikely to cause any trouble anyhow. */
if (zQsystem == NULL
|| strncmp (zQsystem, qsys->uuconf_zname,
strlen (qsys->uuconf_zname)) != 0)
zQsystem = qsys->uuconf_zname;
/* Make sure that all the required files exist, and get their
full names in the spool directory. */
for (i = 0; i < cQfiles; i++)
{
char *zreal;
zreal = zsysdep_spool_file_name (qsys, azQfiles[i], (pointer) NULL);
if (zreal == NULL)
{
uqcleanup (zfile, iclean);
return;
}
if (! fsysdep_file_exists (zreal))
{
uqcleanup (zfile, iclean);
return;
}
ubuffree (azQfiles[i]);
azQfiles[i] = zbufcpy (zreal);
ubuffree (zreal);
}
/* Lock the execution directory. */
if (! fsysdep_lock_uuxqt_dir (iQlock_seq))
{
ulog (LOG_ERROR, "Could not lock execute directory");
uqcleanup (zfile, iclean);
return;
}
fQunlock_directory = TRUE;
iclean |= REMOVE_FILE | REMOVE_NEEDED;
*pfprocessed = TRUE;
/* Get the address to mail results to. Prepend the system from
which the execute file originated, since mail addresses are
relative to it. */
zmail = NULL;
if (zQrequestor != NULL)
zmail = zQrequestor;
else if (zQuser != NULL)
zmail = zQuser;
if (zmail != NULL
#if HAVE_INTERNET_MAIL
&& strchr (zmail, '@') == NULL
#endif
&& strcmp (zQsystem, zlocalname) != 0)
{
char *zset;
zset = zbufalc (strlen (zQsystem) + strlen (zmail) + 2);
sprintf (zset, "%s!%s", zQsystem, zmail);
zmail = zset;
zQmail = zset;
iclean |= FREE_MAIL;
}
/* The command "uucp" is handled specially. We make sure that the
appropriate forwarding is permitted, and we add a -u argument to
specify the user. */
if (strcmp (azQargs[0], "uucp") == 0)
{
char *zfrom, *zto;
boolean fmany;
boolean finoptions;
char **azargs;
const char *zuser;
zfrom = NULL;
zto = NULL;
fmany = FALSE;
finoptions = TRUE;
/* Skip all the options, and get the from and to specs. We
don't permit multiple arguments. We have to do mini-getopt
processing here. */
for (i = 1; azQargs[i] != NULL; i++)
{
if (azQargs[i][0] == '-' && finoptions)
{
if (azQargs[i][1] == '-')
{
if (azQargs[i][2] == '\0')
finoptions = FALSE;
/* The --grade, --notify, and --status options take
an argument. */
else if (strncmp (azQargs[i] + 2, "g", 1) == 0
|| strncmp (azQargs[i] + 2, "not", 3) == 0
|| strncmp (azQargs[i] + 2, "s", 1) == 0)
{
if (strchr (azQargs[i] + 2, '=') == NULL)
++i;
}
/* The --config, --user, and --debug options are not
permitted. */
else if (strncmp (azQargs[i] + 2, "con", 3) == 0
|| strncmp (azQargs[i] + 2, "us", 2) == 0
|| strncmp (azQargs[i] + 2, "de", 2) == 0)
{
azQargs[i][1] = 'r';
azQargs[i][2] = '\0';
if (strchr (azQargs[i] + 3, '=') == NULL)
{
++i;
azQargs[i] = zbufcpy ("-r");
}
}
}
else
{
char *zopts;
for (zopts = azQargs[i] + 1; *zopts != '\0'; zopts++)
{
/* The -g, -n, and -s options take an argument. */
if (*zopts == 'g' || *zopts == 'n' || *zopts == 's')
{
if (zopts[1] == '\0')
++i;
break;
}
/* The -I, -u and -x options are not permitted. */
if (*zopts == 'I' || *zopts == 'u' || *zopts == 'x')
{
*zopts = 'r';
if (zopts[1] != '\0')
zopts[1] = '\0';
else
{
++i;
azQargs[i] = zbufcpy ("-r");
}
break;
}
}
}
}
else if (zfrom == NULL)
zfrom = azQargs[i];
else if (zto == NULL)
zto = azQargs[i];
else
{
fmany = TRUE;
break;
}