-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuustat.c
2412 lines (2097 loc) · 57.6 KB
/
uustat.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
/* uustat.c
UUCP status program
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 uustat_rcsid[] = "$Id$";
#endif
#include <ctype.h>
#include <errno.h>
#if TM_IN_SYS_TIME
#include <sys/time.h>
#else
#include <time.h>
#endif
#include "getopt.h"
#include "uudefs.h"
#include "uuconf.h"
#include "system.h"
/* The uustat program permits various listings and manipulations of
files in the spool directory. This implementation supports the
following switches:
-a list all jobs
-Blines number of lines of standard input to mail
-ccommand list only executions of specified command
-Ccommand list only jobs other than executions of specified command
-e list execute jobs rather than command requests
-i ask user whether to kill each listed job
-Ifile set configuration file name
-kjobid kill job with specified ID
-K kill each listed job
-m report status for all remote machines
-M mail uucp about each job killed with -K
-N mail requestor about each job killed with -K
-ohour report jobs older than specified number of hours
-p do "ps -flp" on all processes holding lock files (Unix specific)
-q list number of jobs for all systems
-Q don't list jobs, just do -K processing
-rjobid rejuvenate job with specified ID
-ssystem report on all jobs for specified system
-Ssystem report on all jobs other than for specified system
-uuser report on all jobs for specified user
-Uuser report on all jobs other than for specified user
-Wcomment comment to include in mail messages
-xdebug set debugging level
-yhour report jobs younger than specified number of hours */
/* What to do with a job that matches the selection criteria; these
values may be or'red together. */
#define JOB_SHOW (01)
#define JOB_INQUIRE (02)
#define JOB_KILL (04)
#define JOB_REJUVENATE (010)
#define JOB_MAIL (020)
#define JOB_NOTIFY (040)
/* This structure is used to accumulate all the lines in a single
command file, so that they can all be displayed at once and so that
executions can be displayed reasonably. */
struct scmdlist
{
struct scmdlist *qnext;
struct scmd s;
long itime;
};
/* Local functions. */
static void ususage P((void));
static void ushelp P((void));
static boolean fsxqt_file_read P((pointer puuconf, FILE *));
static void usxqt_file_free P((void));
static int isxqt_cmd P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int isxqt_file P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static int isxqt_user P((pointer puuconf, int argc, char **argv, pointer pvar,
pointer pinfo));
static boolean fsworkfiles P((pointer puuconf, int icmd, int csystems,
char **pazsystems, boolean fnotsystems,
int cusers, char **pazusers,
boolean fnotusers, long iold, long iyoung,
int ccommands, char **pazcommands,
boolean fnotcommands, const char *zcomment,
int cstdin));
static boolean fsworkfiles_system P((pointer puuconf,int icmd,
const struct uuconf_system *qsys,
int cusers, char **pazusers,
boolean fnotusers, long iold,
long iyoung, int ccommands,
char **pazcommands,
boolean fnotcommands,
const char *zcomment, int cstdin));
static boolean fsworkfile_show P((pointer puuconf, int icmd,
const struct uuconf_system *qsys,
const struct scmd *qcmd,
long itime, int ccommands,
char **pazcommands, boolean fnotcommands,
const char *zcomment, int cstdin));
static void usworkfile_header P((const struct uuconf_system *qsys,
const struct scmd *qcmd,
const char *zjobid,
long itime, boolean ffirst));
static boolean fsexecutions P((pointer puuconf, int icmd, int csystems,
char **pazsystems, boolean fnotsystems,
int cusers, char **pazusers,
boolean fnotusers, long iold, long iyoung,
int ccommands, char **pazcommands,
boolean fnotcommands, const char *zcomment,
int cstdin));
static boolean fsnotify P((pointer puuconf, int icmd, const char *zcomment,
int cstdin, boolean fkilled, const char *zcmd,
struct scmdlist *qcmd, const char *zid,
long itime, const char *zuser,
const struct uuconf_system *qsys,
const char *zstdin, pointer pstdinseq,
const char *zrequestor));
static boolean fsquery P((pointer puuconf, int csystems,
char **pazsystems, boolean fnotsystems,
long iold, long iyoung));
static int csunits_show P((long idiff));
static boolean fsmachines P((void));
/* Long getopt options. */
static const struct option asSlongopts[] =
{
{ "all", no_argument, NULL, 'a' },
{ "mail-lines", required_argument, NULL, 'B' },
{ "command", required_argument, NULL, 'c' },
{ "not-command", required_argument, NULL, 'C' },
{ "executions", no_argument, NULL, 'e' },
{ "prompt", no_argument, NULL, 'i' },
{ "kill", required_argument, NULL, 'k' },
{ "kill-all", no_argument, NULL, 'K' },
{ "status", no_argument, NULL, 'm' },
{ "mail", no_argument, NULL, 'M' },
{ "notify", no_argument, NULL, 'N' },
{ "older-than", required_argument, NULL, 'o' },
{ "ps", no_argument, NULL, 'p' },
{ "list", no_argument, NULL, 'q' },
{ "no-list", no_argument, NULL, 'Q' },
{ "rejuvenate", required_argument, NULL, 'r' },
{ "rejuvenate-all", no_argument, NULL, 'R' },
{ "system", required_argument, NULL, 's' },
{ "not-system", required_argument, NULL, 'S' },
{ "user", required_argument, NULL, 'u' },
{ "not-user", required_argument, NULL, 'U' },
{ "comment", required_argument, NULL, 'W' },
{ "younger-than", required_argument, NULL, 'y' },
{ "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)
{
/* -a: list all jobs. */
boolean fall = FALSE;
/* -B lines: number of lines of standard input to mail. */
int cstdin = 100;
/* -c,-C command: list only specified command. */
int ccommands = 0;
char **pazcommands = NULL;
boolean fnotcommands = FALSE;
/* -e: list execute jobs. */
boolean fexecute = FALSE;
/* -k jobid: kill specified job. */
int ckills = 0;
char **pazkills = NULL;
/* -m: report machine status. */
boolean fmachine = FALSE;
/* -o hour: report jobs older than given number of hours. */
int ioldhours = -1;
/* -p: report status of jobs holding lock files. */
boolean fps = FALSE;
/* -q: list number of jobs for each system. */
boolean fquery = FALSE;
/* -r jobid: rejuvenate specified job. */
int crejuvs = 0;
char **pazrejuvs = NULL;
/* -s,-S system: list all jobs for specified system. */
int csystems = 0;
char **pazsystems = NULL;
boolean fnotsystems = FALSE;
/* -u,-U user: list all jobs for specified user. */
int cusers = 0;
char **pazusers = NULL;
boolean fnotusers = FALSE;
/* -W comment: comment to include in mail messages. */
const char *zcomment = NULL;
/* -y hour: report jobs younger than given number of hours. */
int iyounghours = -1;
/* -I file: set configuration file. */
const char *zconfig = NULL;
/* -Q, -i, -K, -M, -N: what to do with each job. */
int icmd = JOB_SHOW;
int ccmds;
int iopt;
pointer puuconf;
int iuuconf;
long iold;
long iyoung;
const char *azoneuser[1];
boolean fret;
zProgram = argv[0];
while ((iopt = getopt_long (argc, argv,
"aB:c:C:eiI:k:KmMNo:pqQr:Rs:S:u:U:vW:x:y:",
asSlongopts, (int *) NULL)) != EOF)
{
switch (iopt)
{
case 'a':
/* List all jobs. */
fall = TRUE;
break;
case 'B':
/* Number of lines of standard input to mail. */
cstdin = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'C':
/* List jobs for other than specified command. */
fnotcommands = TRUE;
/* Fall through. */
case 'c':
/* List specified command. */
++ccommands;
pazcommands = (char **) xrealloc ((pointer) pazcommands,
ccommands * sizeof (char *));
pazcommands[ccommands - 1] = optarg;
break;
case 'e':
/* List execute jobs. */
fexecute = TRUE;
break;
case 'i':
/* Prompt the user whether to kill each job. */
icmd |= JOB_INQUIRE;
break;
case 'I':
/* Set configuration file name. */
if (fsysdep_other_config (optarg))
zconfig = optarg;
break;
case 'k':
/* Kill specified job. */
++ckills;
pazkills = (char **) xrealloc ((pointer) pazkills,
ckills * sizeof (char *));
pazkills[ckills - 1] = optarg;
break;
case 'K':
/* Kill each listed job. */
icmd |= JOB_KILL;
break;
case 'm':
/* Report machine status. */
fmachine = TRUE;
break;
case 'M':
/* Mail to uucp action taken on each job. */
icmd |= JOB_MAIL;
break;
case 'N':
/* Mail to requestor action taken on each job. */
icmd |= JOB_NOTIFY;
break;
case 'o':
/* Report old jobs. */
ioldhours = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'p':
/* Get status of processes holding locks. */
fps = TRUE;
break;
case 'q':
/* List number of jobs for each system. */
fquery = TRUE;
break;
case 'Q':
/* Don't list jobs, just do -K processing. */
icmd &=~ JOB_SHOW;
break;
case 'r':
/* Rejuvenate specified job. */
++crejuvs;
pazrejuvs = (char **) xrealloc ((pointer) pazrejuvs,
crejuvs * sizeof (char *));
pazrejuvs[crejuvs - 1] = optarg;
break;
case 'R':
/* Rejuvenate each listed job. */
icmd |= JOB_REJUVENATE;
break;
case 'S':
/* List jobs for other than specified system. */
fnotsystems = TRUE;
/* Fall through. */
case 's':
/* List jobs for specified system. */
++csystems;
pazsystems = (char **) xrealloc ((pointer) pazsystems,
csystems * sizeof (char *));
pazsystems[csystems - 1] = optarg;
break;
case 'U':
/* List jobs for other than specified user. */
fnotusers = TRUE;
/* Fall through. */
case 'u':
/* List jobs for specified user. */
++cusers;
pazusers = (char **) xrealloc ((pointer) pazusers,
cusers * sizeof (char *));
pazusers[cusers - 1] = optarg;
break;
case 'W':
/* Comment to include in mail messages. */
zcomment = optarg;
break;
case 'x':
#if DEBUG > 1
/* Set debugging level. */
iDebug |= idebug_parse (optarg);
#endif
break;
case 'y':
/* List jobs younger than given number of hours. */
iyounghours = (int) strtol (optarg, (char **) NULL, 10);
break;
case 'v':
/* Print version and exit. */
printf ("uustat (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. */
ushelp ();
exit (EXIT_SUCCESS);
/*NOTREACHED*/
case 0:
/* Long option found and flag set. */
break;
default:
ususage ();
/*NOTREACHED*/
}
}
if (optind != argc)
ususage ();
/* To avoid confusion, most options are only permitted by
themselves. This restriction might be removed later, but it is
imposed by most implementations. We do permit any combination of
-c, -s, -u, -o and -y, and any combination of -k and -r. */
ccmds = 0;
if (fall)
++ccmds;
if (ckills > 0 || crejuvs > 0)
++ccmds;
if (fmachine)
++ccmds;
if (fps)
++ccmds;
if (fexecute || fquery || csystems > 0 || cusers > 0 || ioldhours != -1
|| iyounghours != -1 || ccommands > 0)
++ccmds;
if (fexecute && fquery)
++ccmds;
if (ccmds > 1)
{
fprintf (stderr, "%s: too many options\n", zProgram);
ususage ();
}
if ((icmd & JOB_KILL) != 0
&& (icmd & JOB_REJUVENATE) != 0)
{
fprintf (stderr, "%s: can not both rejuvenate and kill jobs\n",
zProgram);
ususage ();
}
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
usysdep_initialize (puuconf, INIT_SUID);
/* If no commands were specified, we list all commands for the given
user. */
if (ccmds == 0)
{
cusers = 1;
azoneuser[0] = zsysdep_login_name ();
pazusers = (char **) azoneuser;
}
/* Canonicalize the system names. */
if (csystems > 0)
{
int i;
for (i = 0; i < csystems; i++)
{
struct uuconf_system ssys;
iuuconf = uuconf_system_info (puuconf, pazsystems[i], &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf == UUCONF_NOT_FOUND)
ulog (LOG_FATAL, "%s: System not found", pazsystems[i]);
else
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
}
if (strcmp (pazsystems[i], ssys.uuconf_zname) != 0)
pazsystems[i] = zbufcpy (ssys.uuconf_zname);
(void) uuconf_system_free (puuconf, &ssys);
}
}
if (ioldhours == -1)
iold = (long) -1;
else
{
iold = (ixsysdep_time ((long *) NULL)
- (long) ioldhours * (long) 60 * (long) 60);
if (iold < 0L)
iold = 0L;
}
if (iyounghours == -1)
iyoung = (long) -1;
else
{
iyoung = (ixsysdep_time ((long *) NULL)
- (long) iyounghours * (long) 60 * (long) 60);
if (iyoung < 0L)
iyoung = 0L;
}
if (! fexecute
&& ! fquery
&& (fall
|| csystems > 0
|| cusers > 0
|| ioldhours != -1
|| iyounghours != -1
|| ccommands > 0))
fret = fsworkfiles (puuconf, icmd, csystems, pazsystems, fnotsystems,
cusers, pazusers, fnotusers, iold, iyoung,
ccommands, pazcommands, fnotcommands, zcomment,
cstdin);
else if (fexecute)
fret = fsexecutions (puuconf, icmd, csystems, pazsystems, fnotsystems,
cusers, pazusers, fnotusers, iold, iyoung,
ccommands, pazcommands, fnotcommands, zcomment,
cstdin);
else if (icmd != JOB_SHOW)
{
ulog (LOG_ERROR,
"-i, -K, -M, -N, -Q, -R not supported with -k, -m, -p, -q, -r");
ususage ();
fret = FALSE;
}
else if (fquery)
{
if (cusers > 0 || ccommands > 0)
{
ulog (LOG_ERROR, "-u, -c not supported with -q");
ususage ();
fret = FALSE;
}
else
fret = fsquery (puuconf, csystems, pazsystems, fnotsystems,
iold, iyoung);
}
else if (fmachine)
fret = fsmachines ();
else if (ckills > 0 || crejuvs > 0)
{
int i;
fret = TRUE;
for (i = 0; i < ckills; i++)
if (! fsysdep_kill_job (puuconf, pazkills[i]))
fret = FALSE;
for (i = 0; i < crejuvs; i++)
if (! fsysdep_rejuvenate_job (puuconf, pazrejuvs[i]))
fret = FALSE;
}
else if (fps)
fret = fsysdep_lock_status ();
else
{
#if DEBUG > 0
ulog (LOG_FATAL, "Can't happen");
#endif
fret = FALSE;
}
ulog_close ();
usysdep_exit (fret);
/* Avoid errors about not returning a value. */
return 0;
}
/* Print a usage message and die. */
static void
ususage (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
ushelp (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 (" -a,--all: list all UUCP jobs\n");
printf (" -B,--mail-lines num: number of lines to return in -M or -N mail message\n");
printf (" -c,--command command: list requests for named command\n");
printf (" -C,--not-command command: list requests for other than named command\n");
printf (" -e,--executions: list queued executions rather than job requests\n");
printf (" -i,--prompt: prompt for whether to kill each listed job\n");
printf (" -k,--kill job: kill specified UUCP job\n");
printf (" -K,--kill-all: kill each listed job\n");
printf (" -m,--status: report status for all remote machines\n");
printf (" -M,--mail: mail report on each listed job to UUCP administrator\n");
printf (" -N,--notify: mail report on each listed job to requestor\n");
printf (" -o,--older-than hours: list all jobs older than given number of hours\n");
printf (" -p,--ps: show status of all processes holding UUCP locks\n");
printf (" -q,--list: list number of jobs for each system\n");
printf (" -Q,--no-list: don't list jobs, just take actions (-i, -K, -M, -N)\n");
printf (" -r,--rejuvenate job: rejuvenate specified UUCP job\n");
printf (" -R,--rejuvenate-all: rejuvenate each listed job\n");
printf (" -s,--system system: list all jobs for specified system\n");
printf (" -S,--not-system system: list all jobs for other than specified system\n");
printf (" -u,--user user: list all jobs for specified user\n");
printf (" -U,--not-user user: list all jobs for other than specified user\n");
printf (" -W,--comment comment: comment to include in mail messages\n");
printf (" -y,--younger-than hours: list all jobs younger than given number of hours\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 [email protected]\n");
}
/* We need to be able to read information from an execution file. */
/* The user name extracted from an execution file. */
static char *zSxqt_user;
/* The system name from an execution file. */
static char *zSxqt_system;
/* Address of requesting user (who to send mail to). */
static const char *zSxqt_requestor;
/* The command (no arguments) from an execution file. */
static char *zSxqt_prog;
/* The full command line from an execution file. */
static char *zSxqt_cmd;
/* Number of files associated with an execution file. */
static int cSxqt_files;
/* Names of files associated with execution file. */
static char **pazSxqt_files;
/* Standard input file name. */
static const char *zSxqt_stdin;
/* A command table used to dispatch an execution file. */
static const struct uuconf_cmdtab asSxqt_cmds[] =
{
{ "C", UUCONF_CMDTABTYPE_FN | 0, NULL, isxqt_cmd },
{ "I", UUCONF_CMDTABTYPE_STRING, (pointer) &zSxqt_stdin, NULL },
{ "F", UUCONF_CMDTABTYPE_FN | 0, NULL, isxqt_file },
{ "R", UUCONF_CMDTABTYPE_STRING, (pointer) &zSxqt_requestor, NULL },
{ "U", UUCONF_CMDTABTYPE_FN | 3, NULL, isxqt_user },
{ NULL, 0, NULL, NULL }
};
/* Read an execution file, setting the above variables. */
static boolean
fsxqt_file_read (pointer puuconf, FILE *e)
{
int iuuconf;
boolean fret;
zSxqt_user = NULL;
zSxqt_system = NULL;
zSxqt_stdin = NULL;
zSxqt_requestor = NULL;
zSxqt_prog = NULL;
zSxqt_cmd = NULL;
cSxqt_files = 0;
pazSxqt_files = NULL;
iuuconf = uuconf_cmd_file (puuconf, e, asSxqt_cmds, (pointer) NULL,
(uuconf_cmdtabfn) NULL,
UUCONF_CMDTABFLAG_CASE, (pointer) NULL);
if (iuuconf == UUCONF_SUCCESS)
fret = TRUE;
else
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
}
if (zSxqt_user == NULL)
zSxqt_user = zbufcpy ("*unknown*");
if (zSxqt_system == NULL)
zSxqt_system = zbufcpy ("*unknown*");
if (zSxqt_prog == NULL)
{
zSxqt_prog = zbufcpy ("*none*");
zSxqt_cmd = zbufcpy ("*none*");
}
return fret;
}
/* Free up the information read from an execution file. */
static void
usxqt_file_free (void)
{
int i;
ubuffree (zSxqt_user);
zSxqt_user = NULL;
ubuffree (zSxqt_system);
zSxqt_system = NULL;
ubuffree (zSxqt_prog);
zSxqt_prog = NULL;
ubuffree (zSxqt_cmd);
zSxqt_cmd = NULL;
for (i = 0; i < cSxqt_files; i++)
ubuffree (pazSxqt_files[i]);
cSxqt_files = 0;
xfree ((pointer) pazSxqt_files);
pazSxqt_files = NULL;
zSxqt_stdin = NULL;
zSxqt_requestor = NULL;
}
/* Get the command from an execution file. */
/*ARGSUSED*/
static int
isxqt_cmd (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
size_t clen;
int i;
if (argc <= 1)
return UUCONF_CMDTABRET_CONTINUE;
zSxqt_prog = zbufcpy (argv[1]);
clen = 0;
for (i = 1; i < argc; i++)
clen += strlen (argv[i]) + 1;
zSxqt_cmd = zbufalc (clen);
zSxqt_cmd[0] = '\0';
for (i = 1; i < argc - 1; i++)
{
strcat (zSxqt_cmd, argv[i]);
strcat (zSxqt_cmd, " ");
}
strcat (zSxqt_cmd, argv[i]);
return UUCONF_CMDTABRET_CONTINUE;
}
/* Get the associated files from an execution file. */
/*ARGSUSED*/
static int
isxqt_file (pointer puuconf ATTRIBUTE_UNUSED, int argc, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
if (argc != 2 && argc != 3)
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;
++cSxqt_files;
pazSxqt_files = (char **) xrealloc ((pointer) pazSxqt_files,
cSxqt_files * sizeof (char *));
pazSxqt_files[cSxqt_files - 1] = zbufcpy (argv[1]);
return UUCONF_CMDTABRET_CONTINUE;
}
/* Get the requesting user and system from an execution file. */
/*ARGSUSED*/
static int
isxqt_user (pointer puuconf ATTRIBUTE_UNUSED, int argc ATTRIBUTE_UNUSED, char **argv, pointer pvar ATTRIBUTE_UNUSED, pointer pinfo ATTRIBUTE_UNUSED)
{
zSxqt_user = zbufcpy (argv[1]);
zSxqt_system = zbufcpy (argv[2]);
return UUCONF_CMDTABRET_CONTINUE;
}
/* Handle various possible requests to look at work files. */
static boolean
fsworkfiles (puuconf, icmd, csystems, pazsystems, fnotsystems, cusers,
pazusers, fnotusers, iold, iyoung, ccommands, pazcommands,
fnotcommands, zcomment, cstdin)
pointer puuconf;
int icmd;
int csystems;
char **pazsystems;
boolean fnotsystems;
int cusers;
char **pazusers;
boolean fnotusers;
long iold;
long iyoung;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
boolean fret;
int i;
int iuuconf;
struct uuconf_system ssys;
fret = TRUE;
if (csystems > 0 && ! fnotsystems)
{
for (i = 0; i < csystems; i++)
{
iuuconf = uuconf_system_info (puuconf, pazsystems[i], &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
if (iuuconf == UUCONF_NOT_FOUND)
ulog (LOG_ERROR, "%s: System not found", pazsystems[i]);
else
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
continue;
}
if (! fsworkfiles_system (puuconf, icmd, &ssys, cusers, pazusers,
fnotusers, iold, iyoung, ccommands,
pazcommands, fnotcommands, zcomment,
cstdin))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
}
}
else
{
char **pznames, **pz;
iuuconf = uuconf_system_names (puuconf, &pznames, 0);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
return FALSE;
}
for (pz = pznames; *pz != NULL; pz++)
{
if (csystems > 0)
{
for (i = 0; i < csystems; i++)
if (strcmp (*pz, pazsystems[i]) == 0)
break;
if (i < csystems)
continue;
}
iuuconf = uuconf_system_info (puuconf, *pz, &ssys);
if (iuuconf != UUCONF_SUCCESS)
{
ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
fret = FALSE;
continue;
}
if (! fsworkfiles_system (puuconf, icmd, &ssys, cusers, pazusers,
fnotusers, iold, iyoung, ccommands,
pazcommands, fnotcommands, zcomment,
cstdin))
fret = FALSE;
(void) uuconf_system_free (puuconf, &ssys);
xfree ((pointer) *pz);
}
xfree ((pointer) pznames);
}
return fret;
}
/* Look at the work files for a particular system. */
static boolean
fsworkfiles_system (puuconf, icmd, qsys, cusers, pazusers, fnotusers, iold,
iyoung, ccommands, pazcommands, fnotcommands, zcomment,
cstdin)
pointer puuconf;
int icmd;
const struct uuconf_system *qsys;
int cusers;
char **pazusers;
boolean fnotusers;
long iold;
long iyoung;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
boolean fret;
if (! fsysdep_get_work_init (qsys, UUCONF_GRADE_LOW, 0))
return FALSE;
while (TRUE)
{
struct scmd s;
long itime;
if (! fsysdep_get_work (qsys, UUCONF_GRADE_LOW, 0, &s))
{
usysdep_get_work_free (qsys);
return FALSE;
}
if (s.bcmd == 'H')
break;
if (cusers > 0)
{
boolean fmatch;
int i;
fmatch = fnotusers;
for (i = 0; i < cusers; i++)
{
if (s.zuser != NULL
&& strcmp (pazusers[i], s.zuser) == 0)
{
fmatch = ! fmatch;
break;
}
}
if (! fmatch)
continue;
}
itime = ixsysdep_work_time (qsys, s.pseq);
if (iold != (long) -1 && itime > iold)
continue;
if (iyoung != (long) -1 && itime < iyoung)
continue;
if (! fsworkfile_show (puuconf, icmd, qsys, &s, itime, ccommands,
pazcommands, fnotcommands, zcomment, cstdin))
{
usysdep_get_work_free (qsys);
return FALSE;
}
}
fret = fsworkfile_show (puuconf, icmd, qsys, (const struct scmd *) NULL,
0L, ccommands, pazcommands, fnotcommands, zcomment,
cstdin);
usysdep_get_work_free (qsys);
return fret;
}
/* Show a single workfile. This is actually called once for each line
in the workfile, so we accumulate the lines and show them all at
once. This lets us show an execution in a useful fashion. */
static boolean
fsworkfile_show (puuconf, icmd, qsys, qcmd, itime, ccommands, pazcommands,
fnotcommands, zcomment, cstdin)
pointer puuconf;
int icmd;
const struct uuconf_system *qsys;
const struct scmd *qcmd;
long itime;
int ccommands;
char **pazcommands;
boolean fnotcommands;
const char *zcomment;
int cstdin;
{
static struct scmdlist *qlist;
static char *zlistid;
char *zid;