xref: /titanic_53/usr/src/cmd/bnu/uucleanup.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  *	uucleanup - This is a program based on the heuristics
35*7c478bd9Sstevel@tonic-gate  *	for cleaning up and doing something
36*7c478bd9Sstevel@tonic-gate  *	useful with old files left in the uucp queues.
37*7c478bd9Sstevel@tonic-gate  *	It also will send warning messags to users where requests are not
38*7c478bd9Sstevel@tonic-gate  *	going out due to failure to contact the remote system.
39*7c478bd9Sstevel@tonic-gate  *
40*7c478bd9Sstevel@tonic-gate  *	This program knows a lot about the construction and
41*7c478bd9Sstevel@tonic-gate  *	contents of the C., D. and X. files.  In addition, it
42*7c478bd9Sstevel@tonic-gate  *	thinks it knows what mail and netnews data files look like.
43*7c478bd9Sstevel@tonic-gate  *
44*7c478bd9Sstevel@tonic-gate  *	At present, this is what is done:
45*7c478bd9Sstevel@tonic-gate  *	For WARNING messages:
46*7c478bd9Sstevel@tonic-gate  *	C. files of age given by -W option are read, looking for
47*7c478bd9Sstevel@tonic-gate  *		either user files to be sent or received, or
48*7c478bd9Sstevel@tonic-gate  *		mail to be sent.  (Other remote execution that
49*7c478bd9Sstevel@tonic-gate  *		does not involve sending user files is not checked
50*7c478bd9Sstevel@tonic-gate  *		for now.)  In either of the cases, the user is
51*7c478bd9Sstevel@tonic-gate  *		informed by mail that the request is not being
52*7c478bd9Sstevel@tonic-gate  *		processed due to lack of communications with the remote
53*7c478bd9Sstevel@tonic-gate  *		system, and the request will be deleted in the future
54*7c478bd9Sstevel@tonic-gate  *		if it the condition remains for several more days.
55*7c478bd9Sstevel@tonic-gate  *
56*7c478bd9Sstevel@tonic-gate  *	For DELETIONS:
57*7c478bd9Sstevel@tonic-gate  *	C. files - if they reference only D. files, the C. is
58*7c478bd9Sstevel@tonic-gate  *		merely deleted, because the D. files are usually
59*7c478bd9Sstevel@tonic-gate  *		mail or news, and the later D. processing will
60*7c478bd9Sstevel@tonic-gate  *		take care of them.
61*7c478bd9Sstevel@tonic-gate  *		- if they reference files from the file system,
62*7c478bd9Sstevel@tonic-gate  *		a message is constructed that will contain a
63*7c478bd9Sstevel@tonic-gate  *		lines like
64*7c478bd9Sstevel@tonic-gate  *		   We can't contact the remote.
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  *		   local!file -> remote!otherfile
67*7c478bd9Sstevel@tonic-gate  *
68*7c478bd9Sstevel@tonic-gate  *		   can't be executed.
69*7c478bd9Sstevel@tonic-gate  *	X. files - merely deleted at present - D.s will be taken
70*7c478bd9Sstevel@tonic-gate  *		care of later. Besides, some of the D.s are
71*7c478bd9Sstevel@tonic-gate  *		missing or else the X. wouldn't be left around.
72*7c478bd9Sstevel@tonic-gate  *	D. files - mail type data is sent to a local person if that
73*7c478bd9Sstevel@tonic-gate  *		is where it originated.  If not, it is returned to the
74*7c478bd9Sstevel@tonic-gate  *		sender -- assumed to be from the first From line.  If
75*7c478bd9Sstevel@tonic-gate  *		a sender can't be determing, the file is merely deleted.
76*7c478bd9Sstevel@tonic-gate  *		- rnews: if locally generated, just delete.  If remote,
77*7c478bd9Sstevel@tonic-gate  *		the X. got lost, so execute rnews.
78*7c478bd9Sstevel@tonic-gate  *	other files - just delete them.
79*7c478bd9Sstevel@tonic-gate  *	.Workspace files over a day old
80*7c478bd9Sstevel@tonic-gate  *
81*7c478bd9Sstevel@tonic-gate  *	Deletions and executions are logged in
82*7c478bd9Sstevel@tonic-gate  *	(CLEANUPLOG)--/var/uucp/.Admin/uucleanup
83*7c478bd9Sstevel@tonic-gate */
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate #include	"uucp.h"
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate #ifdef	V7
88*7c478bd9Sstevel@tonic-gate #define O_RDONLY	0
89*7c478bd9Sstevel@tonic-gate #endif
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate #define USAGE	"[-oDAYS] [-mSTRING] [-Cdays] [-Ddays] [-Wdays] [-Xdays] [-xLEVEL] [-sSYSTEM]"
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate extern int _age();		/* find the age of a file */
94*7c478bd9Sstevel@tonic-gate extern void procdtype(), oprocess(), xprocess(), cprocess();
95*7c478bd9Sstevel@tonic-gate extern void dXprocess(), dNprocess(), dMprocess(), dDprocess(), wprocess();
96*7c478bd9Sstevel@tonic-gate extern int toWho(), sendMail(), execRnews();
97*7c478bd9Sstevel@tonic-gate extern void logit();
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /* need these dummys to satisy some .o files */
100*7c478bd9Sstevel@tonic-gate void cleanup(){}
101*7c478bd9Sstevel@tonic-gate void systat(){}
102*7c478bd9Sstevel@tonic-gate void logent(){}
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate /* types of D. files */
106*7c478bd9Sstevel@tonic-gate #define D_MAIL	1
107*7c478bd9Sstevel@tonic-gate #define D_NEWS	2
108*7c478bd9Sstevel@tonic-gate #define D_XFILE	3
109*7c478bd9Sstevel@tonic-gate #define D_DATA	4
110*7c478bd9Sstevel@tonic-gate #define FULLNAME(full,dir,file)	(void) sprintf(full, "%s/%s", dir, file);
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate int _Ddays = 7;			/* D. limit */
113*7c478bd9Sstevel@tonic-gate int _Cdays = 7;			/* C. limit */
114*7c478bd9Sstevel@tonic-gate int _Xdays = 2;			/* X. limit */
115*7c478bd9Sstevel@tonic-gate int _Odays = 2;			/* O. limit */
116*7c478bd9Sstevel@tonic-gate int _Wdays = 1;			/* Warning limit for C. files */
117*7c478bd9Sstevel@tonic-gate char _ShortLocal[6];		/* 5 char or less version of local name */
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate char *_Undeliverable[] = {
120*7c478bd9Sstevel@tonic-gate "Subject: Undeliverable Mail\n",
121*7c478bd9Sstevel@tonic-gate "This mail message is undeliverable.\n",
122*7c478bd9Sstevel@tonic-gate "(Probably to or from system '%s')\n",
123*7c478bd9Sstevel@tonic-gate "It was sent to you or by you.\n",
124*7c478bd9Sstevel@tonic-gate "Sorry for the inconvenience.\n",
125*7c478bd9Sstevel@tonic-gate "",
126*7c478bd9Sstevel@tonic-gate };
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate #define CANT1	2	/* first line to fill in */
129*7c478bd9Sstevel@tonic-gate #define CANT2	3	/* second line to fill in */
130*7c478bd9Sstevel@tonic-gate char *_CantContact[] = {
131*7c478bd9Sstevel@tonic-gate "Subject: Job Killed By uucp\n",
132*7c478bd9Sstevel@tonic-gate "We can't contact machine '%s'.\n",
133*7c478bd9Sstevel@tonic-gate " ",	/* uucleanup will fill in variable text here */
134*7c478bd9Sstevel@tonic-gate " ",	/* fill in jobid of killed job */
135*7c478bd9Sstevel@tonic-gate "",
136*7c478bd9Sstevel@tonic-gate };
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate #define WARN1	2
139*7c478bd9Sstevel@tonic-gate #define WARN2	5
140*7c478bd9Sstevel@tonic-gate #define WARN3	6
141*7c478bd9Sstevel@tonic-gate char *_Warning[] = {
142*7c478bd9Sstevel@tonic-gate "Subject: Warning From uucp\n",
143*7c478bd9Sstevel@tonic-gate "We have been unable to contact machine '%s' since you queued your job.\n",
144*7c478bd9Sstevel@tonic-gate " ",	/*  wprocess FILLS IN THIS LINE OF TEXT */
145*7c478bd9Sstevel@tonic-gate "Attempts will continue for a few more days.\n",
146*7c478bd9Sstevel@tonic-gate "",
147*7c478bd9Sstevel@tonic-gate " ",	/*  wprocess FILLS IN THIS LINE WITH:  uucp job id is JOBid. */
148*7c478bd9Sstevel@tonic-gate " ",	/* FILL IN THE -m STRING IF SPECIFIED */
149*7c478bd9Sstevel@tonic-gate "",
150*7c478bd9Sstevel@tonic-gate };
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate main(argc, argv, envp)
153*7c478bd9Sstevel@tonic-gate char *argv[];
154*7c478bd9Sstevel@tonic-gate char **envp;
155*7c478bd9Sstevel@tonic-gate {
156*7c478bd9Sstevel@tonic-gate 	DIR *jcdir, *machdir, *spooldir;
157*7c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME], statfile[MAXFULLNAME], machname[MAXFULLNAME];
158*7c478bd9Sstevel@tonic-gate 	char file1[NAMESIZE+1], file2[NAMESIZE+1], file3[NAMESIZE+1];
159*7c478bd9Sstevel@tonic-gate 	char soptName[MAXFULLNAME], lockname[MAXFULLNAME];	/* name from -s option */
160*7c478bd9Sstevel@tonic-gate 	int i, value;
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	soptName[0] = NULLCHAR;
163*7c478bd9Sstevel@tonic-gate 	(void) strcpy(Logfile, CLEANUPLOGFILE);
164*7c478bd9Sstevel@tonic-gate 	uucpname(Myname);
165*7c478bd9Sstevel@tonic-gate 	(void) strncpy(_ShortLocal, Myname, 5);
166*7c478bd9Sstevel@tonic-gate 	_ShortLocal[5] = NULLCHAR;
167*7c478bd9Sstevel@tonic-gate 	(void) strcpy(Progname, "uucleanup");
168*7c478bd9Sstevel@tonic-gate 	while ((i = getopt(argc, argv, "C:D:W:X:m:o:s:x:")) != EOF) {
169*7c478bd9Sstevel@tonic-gate 		switch(i){
170*7c478bd9Sstevel@tonic-gate 		case 's':	/* for debugging - choose system */
171*7c478bd9Sstevel@tonic-gate 			(void) strcpy(soptName, optarg);
172*7c478bd9Sstevel@tonic-gate 			break;
173*7c478bd9Sstevel@tonic-gate 		case 'x':
174*7c478bd9Sstevel@tonic-gate 			Debug = atoi(optarg);
175*7c478bd9Sstevel@tonic-gate 			if (Debug <= 0 || Debug >= 10) {
176*7c478bd9Sstevel@tonic-gate 				fprintf(stderr,
177*7c478bd9Sstevel@tonic-gate 				"WARNING: %s: invalid debug level %s ignored, using level 1\n",
178*7c478bd9Sstevel@tonic-gate 					Progname, optarg);
179*7c478bd9Sstevel@tonic-gate 				Debug = 1;
180*7c478bd9Sstevel@tonic-gate 			}
181*7c478bd9Sstevel@tonic-gate #ifdef SMALL
182*7c478bd9Sstevel@tonic-gate 			fprintf(stderr,
183*7c478bd9Sstevel@tonic-gate 				"WARNING: uucleanup built with SMALL flag defined -- no debug info available\n");
184*7c478bd9Sstevel@tonic-gate #endif /* SMALL */
185*7c478bd9Sstevel@tonic-gate 			break;
186*7c478bd9Sstevel@tonic-gate 		case 'm':
187*7c478bd9Sstevel@tonic-gate 			_Warning[WARN3] = optarg;
188*7c478bd9Sstevel@tonic-gate 			break;
189*7c478bd9Sstevel@tonic-gate 		default:
190*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "\tusage: %s %s\n",
191*7c478bd9Sstevel@tonic-gate 				Progname, USAGE);
192*7c478bd9Sstevel@tonic-gate 			exit(1);
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 		case 'C':
195*7c478bd9Sstevel@tonic-gate 		case 'D':
196*7c478bd9Sstevel@tonic-gate 		case 'W':
197*7c478bd9Sstevel@tonic-gate 		case 'X':
198*7c478bd9Sstevel@tonic-gate 		case 'o':
199*7c478bd9Sstevel@tonic-gate 			value = atoi(optarg);
200*7c478bd9Sstevel@tonic-gate 			if (value < 1) {
201*7c478bd9Sstevel@tonic-gate 				fprintf(stderr," Options: CDWXo require value > 0\n");
202*7c478bd9Sstevel@tonic-gate 				exit(1);
203*7c478bd9Sstevel@tonic-gate 			}
204*7c478bd9Sstevel@tonic-gate 			switch(i) {
205*7c478bd9Sstevel@tonic-gate 			case 'C':
206*7c478bd9Sstevel@tonic-gate 				_Cdays = value;
207*7c478bd9Sstevel@tonic-gate 				break;
208*7c478bd9Sstevel@tonic-gate 			case 'D':
209*7c478bd9Sstevel@tonic-gate 				_Ddays = value;
210*7c478bd9Sstevel@tonic-gate 				break;
211*7c478bd9Sstevel@tonic-gate 			case 'W':
212*7c478bd9Sstevel@tonic-gate 				_Wdays = value;
213*7c478bd9Sstevel@tonic-gate 				break;
214*7c478bd9Sstevel@tonic-gate 			case 'X':
215*7c478bd9Sstevel@tonic-gate 				_Xdays = value;
216*7c478bd9Sstevel@tonic-gate 				break;
217*7c478bd9Sstevel@tonic-gate 			case 'o':
218*7c478bd9Sstevel@tonic-gate 				_Odays = value;
219*7c478bd9Sstevel@tonic-gate 				break;
220*7c478bd9Sstevel@tonic-gate 			}
221*7c478bd9Sstevel@tonic-gate 			break;
222*7c478bd9Sstevel@tonic-gate 		}
223*7c478bd9Sstevel@tonic-gate 	}
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	if (argc != optind) {
226*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
227*7c478bd9Sstevel@tonic-gate 		exit(1);
228*7c478bd9Sstevel@tonic-gate 	}
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "Progname (%s): STARTED\n", Progname);
231*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "Myname (%s), ", Myname);
232*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "_ShortLocal (%s)\n", _ShortLocal);
233*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "Days C.(%d), ", _Cdays);
234*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "D.(%d), ", _Ddays);
235*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "W.(%d), ", _Wdays);
236*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "X.(%d), ", _Xdays);
237*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "other (%d)\n", _Odays);
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate 	cleanworkspace();
240*7c478bd9Sstevel@tonic-gate 	if (chdir(SPOOL) != 0) {
241*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T CHDIR (%s): errno (%d)\n",
242*7c478bd9Sstevel@tonic-gate 			SPOOL, errno);
243*7c478bd9Sstevel@tonic-gate 		exit(1);
244*7c478bd9Sstevel@tonic-gate 	}
245*7c478bd9Sstevel@tonic-gate 	if ((spooldir = opendir(SPOOL)) == NULL) {
246*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
247*7c478bd9Sstevel@tonic-gate 			SPOOL, errno);
248*7c478bd9Sstevel@tonic-gate 		exit(1);
249*7c478bd9Sstevel@tonic-gate 	}
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	while (gdirf(spooldir, file1, SPOOL) == TRUE) {
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 		if (*soptName && !EQUALS(soptName, file1))
254*7c478bd9Sstevel@tonic-gate 			continue;
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 		(void) strcpy(Rmtname, file1);
257*7c478bd9Sstevel@tonic-gate 		(void) sprintf(machname, "%s/%s", SPOOL, file1);
258*7c478bd9Sstevel@tonic-gate 		if ((machdir = opendir(machname)) == NULL) {
259*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
260*7c478bd9Sstevel@tonic-gate 				machname, errno);
261*7c478bd9Sstevel@tonic-gate 			if (*soptName)
262*7c478bd9Sstevel@tonic-gate 				break;
263*7c478bd9Sstevel@tonic-gate 			else
264*7c478bd9Sstevel@tonic-gate 				continue;
265*7c478bd9Sstevel@tonic-gate 		}
266*7c478bd9Sstevel@tonic-gate 		DEBUG(7, "Directory: (%s) is open\n", file1);
267*7c478bd9Sstevel@tonic-gate 		while (gnamef(machdir, file2) == TRUE) {
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate 			(void) sprintf(statfile, "%s/%s", machname, file2);
270*7c478bd9Sstevel@tonic-gate 			if (DIRECTORY(statfile)) {
271*7c478bd9Sstevel@tonic-gate 				(void) sprintf(lockname, "%s.%.*s.%s",
272*7c478bd9Sstevel@tonic-gate 					LOCKPRE, SYSNSIZE, file1, file2);
273*7c478bd9Sstevel@tonic-gate 				if (cklock(lockname))
274*7c478bd9Sstevel@tonic-gate 					continue;
275*7c478bd9Sstevel@tonic-gate 				if ((jcdir = opendir(statfile)) == NULL) {
276*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr,
277*7c478bd9Sstevel@tonic-gate 						"CAN'T OPEN (%s): errno (%d)\n",
278*7c478bd9Sstevel@tonic-gate 						statfile, errno);
279*7c478bd9Sstevel@tonic-gate 					continue;
280*7c478bd9Sstevel@tonic-gate 				}
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 				DEBUG(7, "Directory: (%s) is open\n", file2);
283*7c478bd9Sstevel@tonic-gate 				while (gnamef(jcdir, file3)) {
284*7c478bd9Sstevel@tonic-gate 					DEBUG(9, "file: %s\n", file3);
285*7c478bd9Sstevel@tonic-gate 					FULLNAME(fullname, statfile, file3);
286*7c478bd9Sstevel@tonic-gate 					DEBUG(9,"Fullname is (%s)\n", fullname);
287*7c478bd9Sstevel@tonic-gate 					if (EQUALSN(file3, "C.", 2)) {
288*7c478bd9Sstevel@tonic-gate 						if (_age(fullname) >= _Cdays)
289*7c478bd9Sstevel@tonic-gate 							cprocess(fullname);
290*7c478bd9Sstevel@tonic-gate 						else if(_age(fullname) >= _Wdays)
291*7c478bd9Sstevel@tonic-gate 							wprocess(statfile, file3);
292*7c478bd9Sstevel@tonic-gate 					}
293*7c478bd9Sstevel@tonic-gate 					else if (EQUALSN(file3, "D.", 2)) {
294*7c478bd9Sstevel@tonic-gate 						if (_age(fullname) >= _Ddays)
295*7c478bd9Sstevel@tonic-gate 							procdtype(statfile, file3);
296*7c478bd9Sstevel@tonic-gate 					}
297*7c478bd9Sstevel@tonic-gate 					else if (_age(fullname) >= _Odays)
298*7c478bd9Sstevel@tonic-gate 						oprocess(fullname);
299*7c478bd9Sstevel@tonic-gate 				}
300*7c478bd9Sstevel@tonic-gate 				closedir(jcdir);
301*7c478bd9Sstevel@tonic-gate 				continue;
302*7c478bd9Sstevel@tonic-gate 			}
303*7c478bd9Sstevel@tonic-gate 			DEBUG(9, "file: %s\n", file2);
304*7c478bd9Sstevel@tonic-gate 			DEBUG(9, "Fullname is (%s)\n", statfile);
305*7c478bd9Sstevel@tonic-gate 			if (EQUALSN(file2, "X.", 2)) {
306*7c478bd9Sstevel@tonic-gate 				if (_age(statfile) >= _Xdays)
307*7c478bd9Sstevel@tonic-gate 					xprocess(statfile);
308*7c478bd9Sstevel@tonic-gate 			}
309*7c478bd9Sstevel@tonic-gate 			else if (EQUALSN(file2, "D.", 2)) {
310*7c478bd9Sstevel@tonic-gate 				if (_age(statfile) >= _Ddays)
311*7c478bd9Sstevel@tonic-gate 					procdtype(machname, file2);
312*7c478bd9Sstevel@tonic-gate 			}
313*7c478bd9Sstevel@tonic-gate 			else if (_age(statfile) >= _Odays)
314*7c478bd9Sstevel@tonic-gate 				oprocess(statfile);
315*7c478bd9Sstevel@tonic-gate 		}
316*7c478bd9Sstevel@tonic-gate 		closedir(machdir);
317*7c478bd9Sstevel@tonic-gate 	}
318*7c478bd9Sstevel@tonic-gate 	closedir(spooldir);
319*7c478bd9Sstevel@tonic-gate 	exit(0);
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
322*7c478bd9Sstevel@tonic-gate }
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate /* procdtype - select the type of processing that a D. file should receive */
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate void
327*7c478bd9Sstevel@tonic-gate procdtype(dir, file)
328*7c478bd9Sstevel@tonic-gate char *dir, *file;
329*7c478bd9Sstevel@tonic-gate {
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME];
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 	FULLNAME(fullname, dir, file);
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 	switch(dType(fullname)) {
336*7c478bd9Sstevel@tonic-gate 	case D_DATA:
337*7c478bd9Sstevel@tonic-gate 		dDprocess(fullname);
338*7c478bd9Sstevel@tonic-gate 		break;
339*7c478bd9Sstevel@tonic-gate 	case D_MAIL:
340*7c478bd9Sstevel@tonic-gate 		dMprocess(dir, file);
341*7c478bd9Sstevel@tonic-gate 		break;
342*7c478bd9Sstevel@tonic-gate 	case D_NEWS:
343*7c478bd9Sstevel@tonic-gate 		dNprocess(dir, file);
344*7c478bd9Sstevel@tonic-gate 		break;
345*7c478bd9Sstevel@tonic-gate 	case D_XFILE:
346*7c478bd9Sstevel@tonic-gate 		dXprocess(fullname);
347*7c478bd9Sstevel@tonic-gate 		break;
348*7c478bd9Sstevel@tonic-gate 	default:
349*7c478bd9Sstevel@tonic-gate 		break;
350*7c478bd9Sstevel@tonic-gate 	}
351*7c478bd9Sstevel@tonic-gate 	return;
352*7c478bd9Sstevel@tonic-gate }
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate /* xprocess - X. file processing -- just remove the X. for now */
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate void
357*7c478bd9Sstevel@tonic-gate xprocess(fullname)
358*7c478bd9Sstevel@tonic-gate char *fullname;
359*7c478bd9Sstevel@tonic-gate {
360*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "xprocess(%s), ", fullname);
363*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "unlink(%s)\n", fullname);
364*7c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "xprocess: unlink(%s)", fullname);
365*7c478bd9Sstevel@tonic-gate 	errno = 0;
366*7c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
367*7c478bd9Sstevel@tonic-gate 	logit(text, errno);
368*7c478bd9Sstevel@tonic-gate 	return;
369*7c478bd9Sstevel@tonic-gate }
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate /*
372*7c478bd9Sstevel@tonic-gate  * cprocess - Process old C. files
373*7c478bd9Sstevel@tonic-gate  *
374*7c478bd9Sstevel@tonic-gate  */
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate #define CMFMT  "\n\t%s!%s -> %s!%s   (Date %2.2d/%2.2d)\n\nCan't be executed."
377*7c478bd9Sstevel@tonic-gate #define XFMT  "\n\t%s!%s  (Date %2.2d/%2.2d)\n"
378*7c478bd9Sstevel@tonic-gate #define XMFMT  "\n\tmail %s!%s   (Date %2.2d/%2.2d)\n"
379*7c478bd9Sstevel@tonic-gate #define WFMT  "\n\t%s!%s -> %s!%s   (Date %2.2d/%2.2d)\n"
380*7c478bd9Sstevel@tonic-gate void
381*7c478bd9Sstevel@tonic-gate cprocess(fullname)
382*7c478bd9Sstevel@tonic-gate char *fullname;
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate 	struct stat s;
385*7c478bd9Sstevel@tonic-gate 	register struct tm *tp;
386*7c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ], user[9];
387*7c478bd9Sstevel@tonic-gate 	char file1[BUFSIZ], file2[BUFSIZ], file3[BUFSIZ], type[2], opt[256];
388*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ], text1[BUFSIZ], text2[BUFSIZ];
389*7c478bd9Sstevel@tonic-gate 	FILE *fp;
390*7c478bd9Sstevel@tonic-gate 	int ret;
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "cprocess(%s)\n", fullname);
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate 	fp = fopen(fullname, "r");
396*7c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
397*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "Can't open file (%s), ", fullname);
398*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "errno=%d -- skip it!\n", errno);
399*7c478bd9Sstevel@tonic-gate 		return;
400*7c478bd9Sstevel@tonic-gate 	}
401*7c478bd9Sstevel@tonic-gate 	if (fstat(fileno(fp), &s) != 0) {
402*7c478bd9Sstevel@tonic-gate 	    /* can't happen; _age() did stat of this file and file is opened */
403*7c478bd9Sstevel@tonic-gate 	    (void) fclose(fp);
404*7c478bd9Sstevel@tonic-gate 	    return;
405*7c478bd9Sstevel@tonic-gate 	}
406*7c478bd9Sstevel@tonic-gate 	tp = localtime(&s.st_mtime);
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	if (s.st_size == 0) { /* dummy C. for polling */
409*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "dummy C. -- unlink(%s)\n", fullname);
410*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text, "dDprocess: dummy C. unlinked(%s)",
411*7c478bd9Sstevel@tonic-gate 			fullname);
412*7c478bd9Sstevel@tonic-gate 		errno = 0;
413*7c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
414*7c478bd9Sstevel@tonic-gate 		logit(text, errno);
415*7c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
416*7c478bd9Sstevel@tonic-gate 		return;
417*7c478bd9Sstevel@tonic-gate 	}
418*7c478bd9Sstevel@tonic-gate 
419*7c478bd9Sstevel@tonic-gate 	/* Read the C. file and process it */
420*7c478bd9Sstevel@tonic-gate 	while (fgets(buf, BUFSIZ, fp) != NULL) {
421*7c478bd9Sstevel@tonic-gate 		buf[strlen(buf)-1] = NULLCHAR; /* remove \n */
422*7c478bd9Sstevel@tonic-gate 		if (sscanf(buf,"%s%s%s%s%s%s", type, file1, file2,
423*7c478bd9Sstevel@tonic-gate 			user, opt, file3) <5) {
424*7c478bd9Sstevel@tonic-gate 			(void) sprintf(text, "cprocess: Bad C. %s, unlink(%s)",
425*7c478bd9Sstevel@tonic-gate 				buf, fullname);
426*7c478bd9Sstevel@tonic-gate 			break;
427*7c478bd9Sstevel@tonic-gate 		}
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 		*text = NULLCHAR;
430*7c478bd9Sstevel@tonic-gate 		ret = 0;
431*7c478bd9Sstevel@tonic-gate 		/* fill in line 3 of text */
432*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text2, "Job (%s) killed!\n",
433*7c478bd9Sstevel@tonic-gate 		BASENAME(fullname, '/')+2);
434*7c478bd9Sstevel@tonic-gate 		_CantContact[CANT2] = text2;
435*7c478bd9Sstevel@tonic-gate 		if (*type == 'S') {
436*7c478bd9Sstevel@tonic-gate 			if (EQUALSN(file1, "D.", 2))
437*7c478bd9Sstevel@tonic-gate 				/* generated file (mail/news) I think */
438*7c478bd9Sstevel@tonic-gate 				/* D. processing will return it later */
439*7c478bd9Sstevel@tonic-gate 				continue;
440*7c478bd9Sstevel@tonic-gate 
441*7c478bd9Sstevel@tonic-gate 			/* some data was requested -- tell user */
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, CMFMT, Myname, file1, Rmtname, file2,
444*7c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
445*7c478bd9Sstevel@tonic-gate 			_CantContact[CANT1] = text1;
446*7c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _CantContact);
447*7c478bd9Sstevel@tonic-gate 		}
448*7c478bd9Sstevel@tonic-gate 		else if (*type == 'R') {
449*7c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, CMFMT, Rmtname, file1, Myname, file2,
450*7c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
451*7c478bd9Sstevel@tonic-gate 			_CantContact[CANT1] = text1;
452*7c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _CantContact);
453*7c478bd9Sstevel@tonic-gate 		}
454*7c478bd9Sstevel@tonic-gate 	}
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate 	if (!*text) {
457*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text,
458*7c478bd9Sstevel@tonic-gate 			"cprocess: C. %s, mail returned (%d), unlink(%s)",
459*7c478bd9Sstevel@tonic-gate 			buf, ret, fullname);
460*7c478bd9Sstevel@tonic-gate 	}
461*7c478bd9Sstevel@tonic-gate 	DEBUG(3, "text (%s)\n", text);
462*7c478bd9Sstevel@tonic-gate 
463*7c478bd9Sstevel@tonic-gate 	errno = 0;
464*7c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
465*7c478bd9Sstevel@tonic-gate 	logit(text, errno);
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
468*7c478bd9Sstevel@tonic-gate 	return;
469*7c478bd9Sstevel@tonic-gate }
470*7c478bd9Sstevel@tonic-gate 
471*7c478bd9Sstevel@tonic-gate /*
472*7c478bd9Sstevel@tonic-gate  * wprocess - send warning messages for C. == Wdays
473*7c478bd9Sstevel@tonic-gate  */
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate void
476*7c478bd9Sstevel@tonic-gate wprocess(dir, file)
477*7c478bd9Sstevel@tonic-gate char *dir, *file;
478*7c478bd9Sstevel@tonic-gate {
479*7c478bd9Sstevel@tonic-gate 	struct stat s;
480*7c478bd9Sstevel@tonic-gate 	register struct tm *tp;
481*7c478bd9Sstevel@tonic-gate 	char fullname[BUFSIZ], xfile[BUFSIZ], xF_file[BUFSIZ];
482*7c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ], user[BUFSIZ];
483*7c478bd9Sstevel@tonic-gate 	char file1[BUFSIZ], file2[BUFSIZ], file3[BUFSIZ], type[2], opt[256];
484*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ], text1[BUFSIZ], text2[BUFSIZ];
485*7c478bd9Sstevel@tonic-gate 	char *realuser, uline_m[NAMESIZE], uline_u[BUFSIZ], retaddr[BUFSIZ];
486*7c478bd9Sstevel@tonic-gate 	FILE *fp, *xfp;
487*7c478bd9Sstevel@tonic-gate 	int ret;
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 	FULLNAME(fullname, dir, file);
490*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "wprocess(%s)\n", fullname);
491*7c478bd9Sstevel@tonic-gate 
492*7c478bd9Sstevel@tonic-gate 	fp = fopen(fullname, "r");
493*7c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
494*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "Can't open file (%s), ", fullname);
495*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "errno=%d -- skip it!\n", errno);
496*7c478bd9Sstevel@tonic-gate 		return;
497*7c478bd9Sstevel@tonic-gate 	}
498*7c478bd9Sstevel@tonic-gate 
499*7c478bd9Sstevel@tonic-gate 	if (fstat(fileno(fp), &s) != 0) {
500*7c478bd9Sstevel@tonic-gate 
501*7c478bd9Sstevel@tonic-gate 	/* can't happen; _age() did stat of this file and file is opened */
502*7c478bd9Sstevel@tonic-gate 
503*7c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
504*7c478bd9Sstevel@tonic-gate 		return;
505*7c478bd9Sstevel@tonic-gate 	}
506*7c478bd9Sstevel@tonic-gate 
507*7c478bd9Sstevel@tonic-gate 	tp = localtime(&s.st_mtime);
508*7c478bd9Sstevel@tonic-gate 
509*7c478bd9Sstevel@tonic-gate 	if (s.st_size == 0) { /* dummy C. for polling */
510*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "dummy C. -- skip(%s)\n", fullname);
511*7c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
512*7c478bd9Sstevel@tonic-gate 		return;
513*7c478bd9Sstevel@tonic-gate 	}
514*7c478bd9Sstevel@tonic-gate 
515*7c478bd9Sstevel@tonic-gate 	/* read C. and process it */
516*7c478bd9Sstevel@tonic-gate 	while (fgets(buf, BUFSIZ, fp) != NULL) {
517*7c478bd9Sstevel@tonic-gate 		buf[strlen(buf)-1] = NULLCHAR; /* remove \n */
518*7c478bd9Sstevel@tonic-gate 		if (sscanf(buf,"%s%s%s%s%s%s", type, file1, file2,
519*7c478bd9Sstevel@tonic-gate 			user, opt, file3) <5) {
520*7c478bd9Sstevel@tonic-gate 			DEBUG(5, "short line (%s): ", buf);
521*7c478bd9Sstevel@tonic-gate 			DEBUG(5, "bad D. -- skip(%s)\n", fullname);
522*7c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
523*7c478bd9Sstevel@tonic-gate 			return;
524*7c478bd9Sstevel@tonic-gate 		}
525*7c478bd9Sstevel@tonic-gate 
526*7c478bd9Sstevel@tonic-gate 		/* set up the 6th text line of the mail message */
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text2,
529*7c478bd9Sstevel@tonic-gate 			"\nuucp job id is %s.\n", BASENAME(fullname, '/')+2);
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate 		_Warning[WARN2] = text2;
532*7c478bd9Sstevel@tonic-gate 
533*7c478bd9Sstevel@tonic-gate 		/* if Send type then do C. file processing */
534*7c478bd9Sstevel@tonic-gate 
535*7c478bd9Sstevel@tonic-gate 		if (*type == 'S') {
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate 		/* if this is a uux job - tell user about it */
538*7c478bd9Sstevel@tonic-gate 
539*7c478bd9Sstevel@tonic-gate 			if (EQUALSN(file2, "X.", 2)) {
540*7c478bd9Sstevel@tonic-gate 				FULLNAME(xfile, dir, file1);
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate 				/* if X.file can't be read then skip it */
543*7c478bd9Sstevel@tonic-gate 
544*7c478bd9Sstevel@tonic-gate 				if ((xfp = fopen(xfile, "r")) == NULL) {
545*7c478bd9Sstevel@tonic-gate 					DEBUG(3, "Can't read %s\n", xfile);
546*7c478bd9Sstevel@tonic-gate 					break;
547*7c478bd9Sstevel@tonic-gate 				}
548*7c478bd9Sstevel@tonic-gate 				*retaddr = *uline_u = *uline_m = *text = NULLCHAR;
549*7c478bd9Sstevel@tonic-gate 				while (fgets(buf, BUFSIZ, xfp) != NULL) {
550*7c478bd9Sstevel@tonic-gate 
551*7c478bd9Sstevel@tonic-gate 				/* remove \n from end of buffer */
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate 					buf[strlen(buf)-1] = NULLCHAR;
554*7c478bd9Sstevel@tonic-gate 					switch(*buf) {
555*7c478bd9Sstevel@tonic-gate 
556*7c478bd9Sstevel@tonic-gate 					/* save the file name */
557*7c478bd9Sstevel@tonic-gate 
558*7c478bd9Sstevel@tonic-gate 					case 'F':
559*7c478bd9Sstevel@tonic-gate 						FULLNAME(xF_file, dir, &buf[2]);
560*7c478bd9Sstevel@tonic-gate 						break;
561*7c478bd9Sstevel@tonic-gate 
562*7c478bd9Sstevel@tonic-gate 					/* save return address */
563*7c478bd9Sstevel@tonic-gate 
564*7c478bd9Sstevel@tonic-gate 					case 'R':
565*7c478bd9Sstevel@tonic-gate 						sscanf(buf+2, "%s", retaddr);
566*7c478bd9Sstevel@tonic-gate 						DEBUG(7, "retaddr (%s)\n", retaddr);
567*7c478bd9Sstevel@tonic-gate 						break;
568*7c478bd9Sstevel@tonic-gate 
569*7c478bd9Sstevel@tonic-gate 					/* save machine, user */
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate 					case 'U':
572*7c478bd9Sstevel@tonic-gate 						sscanf(buf+2, "%s%s",
573*7c478bd9Sstevel@tonic-gate 						    uline_u, uline_m);
574*7c478bd9Sstevel@tonic-gate 						break;
575*7c478bd9Sstevel@tonic-gate 					}
576*7c478bd9Sstevel@tonic-gate 
577*7c478bd9Sstevel@tonic-gate 					if (buf[0] != 'C')
578*7c478bd9Sstevel@tonic-gate 						continue;
579*7c478bd9Sstevel@tonic-gate 					realuser = uline_u;
580*7c478bd9Sstevel@tonic-gate 					if (*retaddr != NULLCHAR)
581*7c478bd9Sstevel@tonic-gate 						realuser = retaddr;
582*7c478bd9Sstevel@tonic-gate 					if (*realuser == NULLCHAR)
583*7c478bd9Sstevel@tonic-gate 						strcpy(realuser, user);
584*7c478bd9Sstevel@tonic-gate 					if (!EQUALS(uline_m, Myname))
585*7c478bd9Sstevel@tonic-gate 						sprintf(user, "%s!%s",
586*7c478bd9Sstevel@tonic-gate 						    uline_m, realuser);
587*7c478bd9Sstevel@tonic-gate 					else
588*7c478bd9Sstevel@tonic-gate 						strcpy(user, realuser);
589*7c478bd9Sstevel@tonic-gate 
590*7c478bd9Sstevel@tonic-gate 					/* give mail special handling */
591*7c478bd9Sstevel@tonic-gate 					if (EQUALSN(buf+2, "rmail ", 6))
592*7c478bd9Sstevel@tonic-gate 						(void) sprintf(text1, XMFMT,
593*7c478bd9Sstevel@tonic-gate 						    Rmtname, buf+8,
594*7c478bd9Sstevel@tonic-gate 						    tp->tm_mon+1, tp->tm_mday);
595*7c478bd9Sstevel@tonic-gate 					else
596*7c478bd9Sstevel@tonic-gate 						(void) sprintf(text1, XFMT,
597*7c478bd9Sstevel@tonic-gate 						    Rmtname, buf+2,
598*7c478bd9Sstevel@tonic-gate 						    tp->tm_mon+1, tp->tm_mday);
599*7c478bd9Sstevel@tonic-gate 
600*7c478bd9Sstevel@tonic-gate 					_Warning[WARN1] = text1;
601*7c478bd9Sstevel@tonic-gate 					if (EQUALSN(&buf[2], "rmail", 5))
602*7c478bd9Sstevel@tonic-gate 						/*
603*7c478bd9Sstevel@tonic-gate 						 * this is mail; append
604*7c478bd9Sstevel@tonic-gate 						 * user mail (xF_file).
605*7c478bd9Sstevel@tonic-gate 						 */
606*7c478bd9Sstevel@tonic-gate 						ret = sendMail((char *) NULL,
607*7c478bd9Sstevel@tonic-gate 						    user, xF_file, _Warning);
608*7c478bd9Sstevel@tonic-gate 					else
609*7c478bd9Sstevel@tonic-gate 						ret = sendMail((char *) NULL,
610*7c478bd9Sstevel@tonic-gate 						    user, "", _Warning);
611*7c478bd9Sstevel@tonic-gate 					break;
612*7c478bd9Sstevel@tonic-gate 				}
613*7c478bd9Sstevel@tonic-gate 				(void) fclose(xfp);
614*7c478bd9Sstevel@tonic-gate 				break;
615*7c478bd9Sstevel@tonic-gate 			}
616*7c478bd9Sstevel@tonic-gate 
617*7c478bd9Sstevel@tonic-gate 			/* if file1 is a D. file the it might be (mail/news) */
618*7c478bd9Sstevel@tonic-gate 			/* if so then D. processing will take of it later */
619*7c478bd9Sstevel@tonic-gate 
620*7c478bd9Sstevel@tonic-gate 			if (EQUALSN(file1, "D.", 2))
621*7c478bd9Sstevel@tonic-gate 				continue;
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate 			/* some data was requested -- tell user */
624*7c478bd9Sstevel@tonic-gate 			/* set up the 2nd text line of the mail message */
625*7c478bd9Sstevel@tonic-gate 
626*7c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, WFMT, Myname, file1, Rmtname, file2,
627*7c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
628*7c478bd9Sstevel@tonic-gate 			_Warning[WARN1] = text1;
629*7c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _Warning);
630*7c478bd9Sstevel@tonic-gate 		}
631*7c478bd9Sstevel@tonic-gate 
632*7c478bd9Sstevel@tonic-gate 		/* Receive C. file processing */
633*7c478bd9Sstevel@tonic-gate 
634*7c478bd9Sstevel@tonic-gate 		else if (*type == 'R') {
635*7c478bd9Sstevel@tonic-gate 			if (EQUALSN(file1, "D.", 2) && EQUALSN(file2, "D.", 2))
636*7c478bd9Sstevel@tonic-gate 				continue;
637*7c478bd9Sstevel@tonic-gate 
638*7c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, WFMT, Rmtname, file1, Myname, file2,
639*7c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
640*7c478bd9Sstevel@tonic-gate 			_Warning[WARN1] = text1;
641*7c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _Warning);
642*7c478bd9Sstevel@tonic-gate 		}
643*7c478bd9Sstevel@tonic-gate 	}	/* end while - read C. lines loop */
644*7c478bd9Sstevel@tonic-gate 
645*7c478bd9Sstevel@tonic-gate 	(void) sprintf(text,
646*7c478bd9Sstevel@tonic-gate 		"wprocess: %s: %s, warning message sent to %s, returned (%d)",
647*7c478bd9Sstevel@tonic-gate 		fullname, buf, user, ret);
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate 	DEBUG(3, "text (%s)\n", text);
650*7c478bd9Sstevel@tonic-gate 
651*7c478bd9Sstevel@tonic-gate 	logit(text, errno);
652*7c478bd9Sstevel@tonic-gate 
653*7c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
654*7c478bd9Sstevel@tonic-gate 	return;
655*7c478bd9Sstevel@tonic-gate }
656*7c478bd9Sstevel@tonic-gate /*
657*7c478bd9Sstevel@tonic-gate  * oprocess - some unknown file just remove the file
658*7c478bd9Sstevel@tonic-gate  */
659*7c478bd9Sstevel@tonic-gate 
660*7c478bd9Sstevel@tonic-gate void
661*7c478bd9Sstevel@tonic-gate oprocess(fullname)
662*7c478bd9Sstevel@tonic-gate char *fullname;
663*7c478bd9Sstevel@tonic-gate {
664*7c478bd9Sstevel@tonic-gate 
665*7c478bd9Sstevel@tonic-gate 	char *p, text[BUFSIZ];
666*7c478bd9Sstevel@tonic-gate 
667*7c478bd9Sstevel@tonic-gate 	p = BASENAME(fullname, '/');
668*7c478bd9Sstevel@tonic-gate 	if (EQUALSN(p, "P.", 2) == 0)
669*7c478bd9Sstevel@tonic-gate 		if (_age(fullname) <= _Cdays)
670*7c478bd9Sstevel@tonic-gate 			return;
671*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "oprocess(%s), ", fullname);
672*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "unlink(%s)\n", fullname);
673*7c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "oprocess: unlink(%s)", fullname);
674*7c478bd9Sstevel@tonic-gate 	errno = 0;
675*7c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
676*7c478bd9Sstevel@tonic-gate 	logit(text, errno);
677*7c478bd9Sstevel@tonic-gate 	return;
678*7c478bd9Sstevel@tonic-gate }
679*7c478bd9Sstevel@tonic-gate 
680*7c478bd9Sstevel@tonic-gate /*
681*7c478bd9Sstevel@tonic-gate  * dDprocess - random D. file (not mail or rnews)
682*7c478bd9Sstevel@tonic-gate  *--just delete it for now
683*7c478bd9Sstevel@tonic-gate  */
684*7c478bd9Sstevel@tonic-gate 
685*7c478bd9Sstevel@tonic-gate void
686*7c478bd9Sstevel@tonic-gate dDprocess(fullname)
687*7c478bd9Sstevel@tonic-gate char *fullname;
688*7c478bd9Sstevel@tonic-gate {
689*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "dDprocess(%s), ", fullname);
692*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "unlink(%s)\n", fullname);
693*7c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "dDprocess: unlink(%s)", fullname);
694*7c478bd9Sstevel@tonic-gate 	errno = 0;
695*7c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
696*7c478bd9Sstevel@tonic-gate 	logit(text, errno);
697*7c478bd9Sstevel@tonic-gate 	return;
698*7c478bd9Sstevel@tonic-gate }
699*7c478bd9Sstevel@tonic-gate 
700*7c478bd9Sstevel@tonic-gate /*
701*7c478bd9Sstevel@tonic-gate  * dXprocess - process D. files that are destined for X. on remote
702*7c478bd9Sstevel@tonic-gate  * --for now just delete it
703*7c478bd9Sstevel@tonic-gate  */
704*7c478bd9Sstevel@tonic-gate 
705*7c478bd9Sstevel@tonic-gate void
706*7c478bd9Sstevel@tonic-gate dXprocess(fullname)
707*7c478bd9Sstevel@tonic-gate char *fullname;
708*7c478bd9Sstevel@tonic-gate {
709*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
710*7c478bd9Sstevel@tonic-gate 
711*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "dXprocess(%s), ", fullname);
712*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "  unlink(%s)\n", fullname);
713*7c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "dXprocess: unlink(%s)", fullname);
714*7c478bd9Sstevel@tonic-gate 	errno = 0;
715*7c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
716*7c478bd9Sstevel@tonic-gate 	logit(text, errno);
717*7c478bd9Sstevel@tonic-gate 	return;
718*7c478bd9Sstevel@tonic-gate }
719*7c478bd9Sstevel@tonic-gate 
720*7c478bd9Sstevel@tonic-gate /*
721*7c478bd9Sstevel@tonic-gate  * dMprocess - process ophan D. mail files
722*7c478bd9Sstevel@tonic-gate  * There are two types: ones generated locally and
723*7c478bd9Sstevel@tonic-gate  * others that are from remotes.  They can be identified
724*7c478bd9Sstevel@tonic-gate  * by the system name following the D.
725*7c478bd9Sstevel@tonic-gate  * Local ones have the local name.
726*7c478bd9Sstevel@tonic-gate  */
727*7c478bd9Sstevel@tonic-gate 
728*7c478bd9Sstevel@tonic-gate void
729*7c478bd9Sstevel@tonic-gate dMprocess(dir, file)
730*7c478bd9Sstevel@tonic-gate char *dir, *file;
731*7c478bd9Sstevel@tonic-gate {
732*7c478bd9Sstevel@tonic-gate 	int ret;
733*7c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME];
734*7c478bd9Sstevel@tonic-gate 	char *toUser, *toSystem;
735*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
736*7c478bd9Sstevel@tonic-gate 
737*7c478bd9Sstevel@tonic-gate 	(void) sprintf(fullname, "%s/%s", dir, file);
738*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "dMprocess(%s)\n", fullname);
739*7c478bd9Sstevel@tonic-gate 
740*7c478bd9Sstevel@tonic-gate 
741*7c478bd9Sstevel@tonic-gate 	if (PREFIX(_ShortLocal, &file[2])) {
742*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Local file %s: ", file);
743*7c478bd9Sstevel@tonic-gate 	}
744*7c478bd9Sstevel@tonic-gate 	else {
745*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Remote file %s: ", file);
746*7c478bd9Sstevel@tonic-gate 	}
747*7c478bd9Sstevel@tonic-gate 	if (toWho(fullname, &toUser, &toSystem)) {
748*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "toUser %s, ", toUser);
749*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "toSystem %s  ", toSystem);
750*7c478bd9Sstevel@tonic-gate 		ret = sendMail(toSystem, toUser, fullname, _Undeliverable);
751*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "Mail sent, unlink(%s)\n", fullname);
752*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text,
753*7c478bd9Sstevel@tonic-gate 			"dMprocess: mail %s to %s!%s, returned (%d),  unlink(%s)",
754*7c478bd9Sstevel@tonic-gate 			fullname, toSystem, toUser, ret, fullname);
755*7c478bd9Sstevel@tonic-gate 		errno = 0;
756*7c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
757*7c478bd9Sstevel@tonic-gate 		logit(text, errno);
758*7c478bd9Sstevel@tonic-gate 	}
759*7c478bd9Sstevel@tonic-gate 	return;
760*7c478bd9Sstevel@tonic-gate }
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate /*
763*7c478bd9Sstevel@tonic-gate  * dNprocess - process ophan D. netnews files
764*7c478bd9Sstevel@tonic-gate  * There are two types: ones generated locally and
765*7c478bd9Sstevel@tonic-gate  * others that are from remotes.  They can be identified
766*7c478bd9Sstevel@tonic-gate  * by the system name following the D.
767*7c478bd9Sstevel@tonic-gate  * Local ones have the local name.
768*7c478bd9Sstevel@tonic-gate  */
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate void
771*7c478bd9Sstevel@tonic-gate dNprocess(dir, file)
772*7c478bd9Sstevel@tonic-gate char *dir, *file;
773*7c478bd9Sstevel@tonic-gate {
774*7c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME];
775*7c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
776*7c478bd9Sstevel@tonic-gate 	int ret;
777*7c478bd9Sstevel@tonic-gate 
778*7c478bd9Sstevel@tonic-gate 	(void) sprintf(fullname, "%s/%s", dir, file);
779*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "dNprocess(%s)\n", fullname);
780*7c478bd9Sstevel@tonic-gate 
781*7c478bd9Sstevel@tonic-gate 
782*7c478bd9Sstevel@tonic-gate 	if (PREFIX(_ShortLocal, &file[2])) {
783*7c478bd9Sstevel@tonic-gate 	/* just delete it, the C. is gone */
784*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Local file %s, ", file);
785*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "unlink(%s)\n", fullname);
786*7c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
787*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text, "dNprocess: Local news item unlink(%s)",
788*7c478bd9Sstevel@tonic-gate 			fullname);
789*7c478bd9Sstevel@tonic-gate 		errno = 0;
790*7c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
791*7c478bd9Sstevel@tonic-gate 		logit(text, errno);
792*7c478bd9Sstevel@tonic-gate 	}
793*7c478bd9Sstevel@tonic-gate 	else {
794*7c478bd9Sstevel@tonic-gate 	/* execute rnews with this file - the X. is missing */
795*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Remote file %s, ", file);
796*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "exec rnews(%s), ", fullname);
797*7c478bd9Sstevel@tonic-gate 		ret = execRnews(fullname);
798*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "unlink(%s)\n", fullname);
799*7c478bd9Sstevel@tonic-gate 		(void) sprintf(text,
800*7c478bd9Sstevel@tonic-gate 			"dNprocess: Remote - exec rnews %s: returned (%d), unlink(%s)",
801*7c478bd9Sstevel@tonic-gate 			fullname, ret, fullname);
802*7c478bd9Sstevel@tonic-gate 		errno = 0;
803*7c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
804*7c478bd9Sstevel@tonic-gate 		logit(text, errno);
805*7c478bd9Sstevel@tonic-gate 	}
806*7c478bd9Sstevel@tonic-gate 	return;
807*7c478bd9Sstevel@tonic-gate }
808*7c478bd9Sstevel@tonic-gate 
809*7c478bd9Sstevel@tonic-gate 
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate static long _sec_per_day = 86400L;
812*7c478bd9Sstevel@tonic-gate 
813*7c478bd9Sstevel@tonic-gate /*
814*7c478bd9Sstevel@tonic-gate  * _age - find the age of "file" in days
815*7c478bd9Sstevel@tonic-gate  * return:
816*7c478bd9Sstevel@tonic-gate  *	age of file
817*7c478bd9Sstevel@tonic-gate  *	0 - if stat fails
818*7c478bd9Sstevel@tonic-gate  */
819*7c478bd9Sstevel@tonic-gate 
820*7c478bd9Sstevel@tonic-gate int
821*7c478bd9Sstevel@tonic-gate _age(fullname)
822*7c478bd9Sstevel@tonic-gate char *fullname;
823*7c478bd9Sstevel@tonic-gate {
824*7c478bd9Sstevel@tonic-gate 	static time_t ptime = 0;
825*7c478bd9Sstevel@tonic-gate 	time_t time();
826*7c478bd9Sstevel@tonic-gate 	struct stat stbuf;
827*7c478bd9Sstevel@tonic-gate 	int e;
828*7c478bd9Sstevel@tonic-gate 
829*7c478bd9Sstevel@tonic-gate 	if (!ptime)
830*7c478bd9Sstevel@tonic-gate 		(void) time(&ptime);
831*7c478bd9Sstevel@tonic-gate 	if (stat(fullname, &stbuf) != -1) {
832*7c478bd9Sstevel@tonic-gate 		return ((int)((ptime - stbuf.st_mtime)/_sec_per_day));
833*7c478bd9Sstevel@tonic-gate 	}
834*7c478bd9Sstevel@tonic-gate 	e = errno;
835*7c478bd9Sstevel@tonic-gate 	DEBUG(9, "_age: stat (%s) failed", fullname);
836*7c478bd9Sstevel@tonic-gate 	DEBUG(9, ", errno %d\n", e);
837*7c478bd9Sstevel@tonic-gate 	return(0);
838*7c478bd9Sstevel@tonic-gate }
839*7c478bd9Sstevel@tonic-gate 
840*7c478bd9Sstevel@tonic-gate /*
841*7c478bd9Sstevel@tonic-gate  * dType - return the type of D. file
842*7c478bd9Sstevel@tonic-gate  * return:
843*7c478bd9Sstevel@tonic-gate  *	FAIL - can't read D. file
844*7c478bd9Sstevel@tonic-gate  *	D_MAIL - mail message D. file
845*7c478bd9Sstevel@tonic-gate  *	D_NEWS - netnews D. file
846*7c478bd9Sstevel@tonic-gate  *	D_DATA - other kind of D. file
847*7c478bd9Sstevel@tonic-gate  *	D_XFILE - destined for X. on destination machine
848*7c478bd9Sstevel@tonic-gate  */
849*7c478bd9Sstevel@tonic-gate 
850*7c478bd9Sstevel@tonic-gate /* NLINES - number of lines of D. file to read to determine type */
851*7c478bd9Sstevel@tonic-gate #define NLINES	10
852*7c478bd9Sstevel@tonic-gate 
853*7c478bd9Sstevel@tonic-gate int
854*7c478bd9Sstevel@tonic-gate dType(fullname)
855*7c478bd9Sstevel@tonic-gate char *fullname;
856*7c478bd9Sstevel@tonic-gate {
857*7c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
858*7c478bd9Sstevel@tonic-gate 	FILE *fp;
859*7c478bd9Sstevel@tonic-gate 	int i, type;
860*7c478bd9Sstevel@tonic-gate 
861*7c478bd9Sstevel@tonic-gate 	fp = fopen(fullname, "r");
862*7c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
863*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "Can't open file (%s), ", fullname);
864*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "errno=%d -- skip it!\n", errno);
865*7c478bd9Sstevel@tonic-gate 		return(FAIL);
866*7c478bd9Sstevel@tonic-gate 	}
867*7c478bd9Sstevel@tonic-gate 	type = D_DATA;
868*7c478bd9Sstevel@tonic-gate 
869*7c478bd9Sstevel@tonic-gate 	/* read first NLINES lines to determine file type */
870*7c478bd9Sstevel@tonic-gate 
871*7c478bd9Sstevel@tonic-gate 	for (i=0; i<NLINES; i++) {
872*7c478bd9Sstevel@tonic-gate 		if (fgets(buf, BUFSIZ, fp) == NULL)
873*7c478bd9Sstevel@tonic-gate 			break;	/* no more lines */
874*7c478bd9Sstevel@tonic-gate 		DEBUG(9, "buf: %s\n", buf);
875*7c478bd9Sstevel@tonic-gate 		if (EQUALSN(buf, "From ", 5)) {
876*7c478bd9Sstevel@tonic-gate 			type = D_MAIL;
877*7c478bd9Sstevel@tonic-gate 			break;
878*7c478bd9Sstevel@tonic-gate 		}
879*7c478bd9Sstevel@tonic-gate 		if (EQUALSN(buf, "U ", 2)) {
880*7c478bd9Sstevel@tonic-gate 			type = D_XFILE;
881*7c478bd9Sstevel@tonic-gate 			break;
882*7c478bd9Sstevel@tonic-gate 		}
883*7c478bd9Sstevel@tonic-gate 		if (EQUALSN(buf, "Newsgroups: ", 12)) {
884*7c478bd9Sstevel@tonic-gate 			type = D_NEWS;
885*7c478bd9Sstevel@tonic-gate 			break;
886*7c478bd9Sstevel@tonic-gate 		}
887*7c478bd9Sstevel@tonic-gate 	}
888*7c478bd9Sstevel@tonic-gate 
889*7c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
890*7c478bd9Sstevel@tonic-gate 	return(type);
891*7c478bd9Sstevel@tonic-gate }
892*7c478bd9Sstevel@tonic-gate 
893*7c478bd9Sstevel@tonic-gate /*
894*7c478bd9Sstevel@tonic-gate  * sendMail - send mail file and message to user (local or remote)
895*7c478bd9Sstevel@tonic-gate  * return:
896*7c478bd9Sstevel@tonic-gate  *	the return from the pclose - mail exit status
897*7c478bd9Sstevel@tonic-gate  */
898*7c478bd9Sstevel@tonic-gate int
899*7c478bd9Sstevel@tonic-gate sendMail(system, user, file, mtext)
900*7c478bd9Sstevel@tonic-gate char *system, *user, *file;
901*7c478bd9Sstevel@tonic-gate char *mtext[];
902*7c478bd9Sstevel@tonic-gate {
903*7c478bd9Sstevel@tonic-gate 	register FILE *fp, *fi;
904*7c478bd9Sstevel@tonic-gate 	char cmd[BUFSIZ];
905*7c478bd9Sstevel@tonic-gate 	char *p;
906*7c478bd9Sstevel@tonic-gate 
907*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "Mail %s to ", file);
908*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "%s\n", user);
909*7c478bd9Sstevel@tonic-gate 
910*7c478bd9Sstevel@tonic-gate 	/* get rid of some stuff that could be dangerous */
911*7c478bd9Sstevel@tonic-gate 	if (system != NULL && (p = strpbrk(system, Shchar)) != NULL) {
912*7c478bd9Sstevel@tonic-gate 		*p = NULLCHAR;
913*7c478bd9Sstevel@tonic-gate 	}
914*7c478bd9Sstevel@tonic-gate 	if (user != NULL && (p = strpbrk(user, Shchar)) != NULL) {
915*7c478bd9Sstevel@tonic-gate 		*p = NULLCHAR;
916*7c478bd9Sstevel@tonic-gate 	}
917*7c478bd9Sstevel@tonic-gate 	if (system != NULL && *system != '\0')
918*7c478bd9Sstevel@tonic-gate 		(void) sprintf(cmd, "%s %s '%s!%s'", PATH, MAIL, system, user);
919*7c478bd9Sstevel@tonic-gate 	else
920*7c478bd9Sstevel@tonic-gate 		(void) sprintf(cmd, "%s %s '%s'", PATH, MAIL, user);
921*7c478bd9Sstevel@tonic-gate 
922*7c478bd9Sstevel@tonic-gate 	DEBUG(7, "sendMail: %s\n", cmd);
923*7c478bd9Sstevel@tonic-gate 	if ((fp = popen(cmd, "w")) == NULL)
924*7c478bd9Sstevel@tonic-gate 		return(-errno);
925*7c478bd9Sstevel@tonic-gate 	while (*mtext[0] )
926*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, *mtext++, Rmtname);
927*7c478bd9Sstevel@tonic-gate 
928*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, "\n\tSincerely,\n\t%s!uucp\n", Myname);
929*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fp,
930*7c478bd9Sstevel@tonic-gate 		"\n#############################################\n");
931*7c478bd9Sstevel@tonic-gate 
932*7c478bd9Sstevel@tonic-gate 	if (*file) {
933*7c478bd9Sstevel@tonic-gate 	/*next statement should never happen;I read once */
934*7c478bd9Sstevel@tonic-gate 		if ((fi= fopen(file, "r")) == NULL)
935*7c478bd9Sstevel@tonic-gate 			return(pclose(fp));
936*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp,
937*7c478bd9Sstevel@tonic-gate 			"##### Data File: ############################\n");
938*7c478bd9Sstevel@tonic-gate 		xfappend(fi, fp);
939*7c478bd9Sstevel@tonic-gate 		(void) fclose(fi);
940*7c478bd9Sstevel@tonic-gate 	}
941*7c478bd9Sstevel@tonic-gate 	return(pclose(fp));
942*7c478bd9Sstevel@tonic-gate }
943*7c478bd9Sstevel@tonic-gate 
944*7c478bd9Sstevel@tonic-gate /*
945*7c478bd9Sstevel@tonic-gate  * execRnews - execute rnews command with stdin file
946*7c478bd9Sstevel@tonic-gate  * return:
947*7c478bd9Sstevel@tonic-gate  *	the return from the pclose - rnews exit status
948*7c478bd9Sstevel@tonic-gate  */
949*7c478bd9Sstevel@tonic-gate int
950*7c478bd9Sstevel@tonic-gate execRnews(file)
951*7c478bd9Sstevel@tonic-gate char *file;
952*7c478bd9Sstevel@tonic-gate {
953*7c478bd9Sstevel@tonic-gate 	register FILE *fp, *fi;
954*7c478bd9Sstevel@tonic-gate 	char cmd[BUFSIZ];
955*7c478bd9Sstevel@tonic-gate 
956*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "Rnews %s\n", file);
957*7c478bd9Sstevel@tonic-gate 
958*7c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd, "%s rnews ", PATH);
959*7c478bd9Sstevel@tonic-gate 	if ((fp = popen(cmd, "w")) == NULL)
960*7c478bd9Sstevel@tonic-gate 		return(-errno);
961*7c478bd9Sstevel@tonic-gate 
962*7c478bd9Sstevel@tonic-gate 	if ( (fi = fopen(file, "r")) == NULL) /* never happen - I read once */
963*7c478bd9Sstevel@tonic-gate 		return(pclose(fp));
964*7c478bd9Sstevel@tonic-gate 	xfappend(fi, fp);
965*7c478bd9Sstevel@tonic-gate 	(void) fclose(fi);
966*7c478bd9Sstevel@tonic-gate 
967*7c478bd9Sstevel@tonic-gate 	return(pclose(fp));
968*7c478bd9Sstevel@tonic-gate }
969*7c478bd9Sstevel@tonic-gate 
970*7c478bd9Sstevel@tonic-gate /*
971*7c478bd9Sstevel@tonic-gate  * toWho - figure out who to send this dead mail to
972*7c478bd9Sstevel@tonic-gate  *	It is a guess;
973*7c478bd9Sstevel@tonic-gate  *	If there is a local address, send it there.
974*7c478bd9Sstevel@tonic-gate  *	If not, send it back where it came from.
975*7c478bd9Sstevel@tonic-gate  * return:
976*7c478bd9Sstevel@tonic-gate  *	0 - could not find system and user information
977*7c478bd9Sstevel@tonic-gate  *	1 - found it
978*7c478bd9Sstevel@tonic-gate  */
979*7c478bd9Sstevel@tonic-gate 
980*7c478bd9Sstevel@tonic-gate int
981*7c478bd9Sstevel@tonic-gate toWho(file, user, system)
982*7c478bd9Sstevel@tonic-gate char *file;	/* the D. mail message file */
983*7c478bd9Sstevel@tonic-gate char **system;	/* pointer to the system name */
984*7c478bd9Sstevel@tonic-gate char **user;	/* pointer to the user name */
985*7c478bd9Sstevel@tonic-gate {
986*7c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
987*7c478bd9Sstevel@tonic-gate 	FILE *fp;
988*7c478bd9Sstevel@tonic-gate 	int i;
989*7c478bd9Sstevel@tonic-gate 	static char fuser[BUFSIZ], fsystem[MAXBASENAME+1];  /* from first From */
990*7c478bd9Sstevel@tonic-gate 	static char luser[BUFSIZ], lsystem[MAXBASENAME+1];  /* from other From */
991*7c478bd9Sstevel@tonic-gate 
992*7c478bd9Sstevel@tonic-gate 	*fuser = NULLCHAR;
993*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "toWho(%s)\n", file);
994*7c478bd9Sstevel@tonic-gate 	fp = fopen(file, "r");
995*7c478bd9Sstevel@tonic-gate 	for (i=0; i<NLINES; i++) {
996*7c478bd9Sstevel@tonic-gate 		if (fgets(buf, BUFSIZ, fp) == NULL)
997*7c478bd9Sstevel@tonic-gate 			break;	/* no more lines */
998*7c478bd9Sstevel@tonic-gate 		DEBUG(9, "buf: %s\n", buf);
999*7c478bd9Sstevel@tonic-gate 		if (!analFrom(buf, luser, lsystem))
1000*7c478bd9Sstevel@tonic-gate 			continue;
1001*7c478bd9Sstevel@tonic-gate 		if ( !*fuser) {
1002*7c478bd9Sstevel@tonic-gate 			(void) strcpy(fuser, luser);
1003*7c478bd9Sstevel@tonic-gate 			(void) strcpy(fsystem, lsystem);
1004*7c478bd9Sstevel@tonic-gate 		}
1005*7c478bd9Sstevel@tonic-gate 		if (EQUALS(Myname, lsystem)) {
1006*7c478bd9Sstevel@tonic-gate 			*user = luser;
1007*7c478bd9Sstevel@tonic-gate 			*system = lsystem;
1008*7c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
1009*7c478bd9Sstevel@tonic-gate 			return(1);
1010*7c478bd9Sstevel@tonic-gate 		}
1011*7c478bd9Sstevel@tonic-gate 	}
1012*7c478bd9Sstevel@tonic-gate 
1013*7c478bd9Sstevel@tonic-gate 	/* could not find local user - use first line */
1014*7c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
1015*7c478bd9Sstevel@tonic-gate 	if (!*fuser)	/* didn't find all information */
1016*7c478bd9Sstevel@tonic-gate 		return(0);
1017*7c478bd9Sstevel@tonic-gate 	*user = fuser;
1018*7c478bd9Sstevel@tonic-gate 	*system = fsystem;
1019*7c478bd9Sstevel@tonic-gate 	return(1);
1020*7c478bd9Sstevel@tonic-gate }
1021*7c478bd9Sstevel@tonic-gate 
1022*7c478bd9Sstevel@tonic-gate /* analFrom - analyze From line
1023*7c478bd9Sstevel@tonic-gate  * return:
1024*7c478bd9Sstevel@tonic-gate  *	0 - didn't find both from and remote from info
1025*7c478bd9Sstevel@tonic-gate  *	1 - found info.
1026*7c478bd9Sstevel@tonic-gate  */
1027*7c478bd9Sstevel@tonic-gate 
1028*7c478bd9Sstevel@tonic-gate int
1029*7c478bd9Sstevel@tonic-gate analFrom(line, user, system)
1030*7c478bd9Sstevel@tonic-gate char *line, *user, *system;
1031*7c478bd9Sstevel@tonic-gate {
1032*7c478bd9Sstevel@tonic-gate 	char *s;
1033*7c478bd9Sstevel@tonic-gate 	int i;
1034*7c478bd9Sstevel@tonic-gate 
1035*7c478bd9Sstevel@tonic-gate 	if (!PREFIX("From ", line) && !PREFIX(">From ", line))
1036*7c478bd9Sstevel@tonic-gate 		return(0);
1037*7c478bd9Sstevel@tonic-gate 
1038*7c478bd9Sstevel@tonic-gate 	s = strchr(line, ' ') + 1;
1039*7c478bd9Sstevel@tonic-gate 	for (i = 0;  *s && *s != ' ' && *s != '\n'; i++)
1040*7c478bd9Sstevel@tonic-gate 		user[i] = *s++;
1041*7c478bd9Sstevel@tonic-gate 	user[i] = NULLCHAR;
1042*7c478bd9Sstevel@tonic-gate 
1043*7c478bd9Sstevel@tonic-gate 	/* look for "remote from" */
1044*7c478bd9Sstevel@tonic-gate 	while (*s && ((s = strchr(s, ' ')) != NULL)) {
1045*7c478bd9Sstevel@tonic-gate 		s++;
1046*7c478bd9Sstevel@tonic-gate 		if (PREFIX("remote from ", s)) {	/* found it */
1047*7c478bd9Sstevel@tonic-gate 			s = s + strlen("remote from ");
1048*7c478bd9Sstevel@tonic-gate 			for (i = 0; (i<MAXBASENAME) && *s && *s != ' ' && *s != '\n'; i++)
1049*7c478bd9Sstevel@tonic-gate 				system[i] = *s++;
1050*7c478bd9Sstevel@tonic-gate 			system[i] = NULLCHAR;
1051*7c478bd9Sstevel@tonic-gate 			return(1);
1052*7c478bd9Sstevel@tonic-gate 		}
1053*7c478bd9Sstevel@tonic-gate 	}
1054*7c478bd9Sstevel@tonic-gate 	return(0);
1055*7c478bd9Sstevel@tonic-gate }
1056*7c478bd9Sstevel@tonic-gate 
1057*7c478bd9Sstevel@tonic-gate 
1058*7c478bd9Sstevel@tonic-gate 
1059*7c478bd9Sstevel@tonic-gate static FILE	*_Lf = NULL;
1060*7c478bd9Sstevel@tonic-gate 
1061*7c478bd9Sstevel@tonic-gate /*
1062*7c478bd9Sstevel@tonic-gate  * Make log entry
1063*7c478bd9Sstevel@tonic-gate  *	text	-> ptr to text string
1064*7c478bd9Sstevel@tonic-gate  *	status	errno number
1065*7c478bd9Sstevel@tonic-gate  * Returns:
1066*7c478bd9Sstevel@tonic-gate  *	none
1067*7c478bd9Sstevel@tonic-gate  */
1068*7c478bd9Sstevel@tonic-gate 
1069*7c478bd9Sstevel@tonic-gate void
1070*7c478bd9Sstevel@tonic-gate logit(text, status)
1071*7c478bd9Sstevel@tonic-gate register char	*text;
1072*7c478bd9Sstevel@tonic-gate int status;
1073*7c478bd9Sstevel@tonic-gate {
1074*7c478bd9Sstevel@tonic-gate 
1075*7c478bd9Sstevel@tonic-gate 	if (Nstat.t_pid == 0)
1076*7c478bd9Sstevel@tonic-gate 		Nstat.t_pid = getpid();
1077*7c478bd9Sstevel@tonic-gate 
1078*7c478bd9Sstevel@tonic-gate 	if (_Lf == NULL) {
1079*7c478bd9Sstevel@tonic-gate 		_Lf = fopen(Logfile, "a");
1080*7c478bd9Sstevel@tonic-gate 		(void) chmod(Logfile, LOGFILEMODE);
1081*7c478bd9Sstevel@tonic-gate 		if (_Lf == NULL)
1082*7c478bd9Sstevel@tonic-gate 			return;
1083*7c478bd9Sstevel@tonic-gate 		setbuf(_Lf, CNULL);
1084*7c478bd9Sstevel@tonic-gate 	}
1085*7c478bd9Sstevel@tonic-gate 	(void) fseek(_Lf, 0L, 2);
1086*7c478bd9Sstevel@tonic-gate 	(void) fprintf(_Lf, "%s ", Rmtname);
1087*7c478bd9Sstevel@tonic-gate 	(void) fprintf(_Lf, "(%s,%ld,%d) ", timeStamp(), (long) Nstat.t_pid, Seqn);
1088*7c478bd9Sstevel@tonic-gate 	(void) fprintf(_Lf, "%s (%d)\n", text, status);
1089*7c478bd9Sstevel@tonic-gate 	return;
1090*7c478bd9Sstevel@tonic-gate }
1091*7c478bd9Sstevel@tonic-gate 
1092*7c478bd9Sstevel@tonic-gate cleanworkspace()
1093*7c478bd9Sstevel@tonic-gate {
1094*7c478bd9Sstevel@tonic-gate 	DIR	*spooldir;
1095*7c478bd9Sstevel@tonic-gate 	char f[MAXFULLNAME];
1096*7c478bd9Sstevel@tonic-gate 
1097*7c478bd9Sstevel@tonic-gate 	if (chdir(WORKSPACE) != 0) {
1098*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T CHDIR (%s): errno (%d)\n", WORKSPACE, errno);
1099*7c478bd9Sstevel@tonic-gate 		return;
1100*7c478bd9Sstevel@tonic-gate 	}
1101*7c478bd9Sstevel@tonic-gate 	if ((spooldir = opendir(WORKSPACE)) == NULL) {
1102*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n", WORKSPACE, errno);
1103*7c478bd9Sstevel@tonic-gate 		return;
1104*7c478bd9Sstevel@tonic-gate 	}
1105*7c478bd9Sstevel@tonic-gate 
1106*7c478bd9Sstevel@tonic-gate 	while (gnamef(spooldir, f) == TRUE)
1107*7c478bd9Sstevel@tonic-gate 		if (_age(f) >= 1)
1108*7c478bd9Sstevel@tonic-gate 			if (unlink(f) != 0)
1109*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "CAN'T UNLINK (%s): errno (%d)\n", f, errno);
1110*7c478bd9Sstevel@tonic-gate 
1111*7c478bd9Sstevel@tonic-gate }
1112