xref: /titanic_51/usr/src/cmd/bnu/uucleanup.c (revision 462be471126495414a94f9fa35e16c02dc462c04)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*462be471Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  *	uucleanup - This is a program based on the heuristics
357c478bd9Sstevel@tonic-gate  *	for cleaning up and doing something
367c478bd9Sstevel@tonic-gate  *	useful with old files left in the uucp queues.
377c478bd9Sstevel@tonic-gate  *	It also will send warning messags to users where requests are not
387c478bd9Sstevel@tonic-gate  *	going out due to failure to contact the remote system.
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  *	This program knows a lot about the construction and
417c478bd9Sstevel@tonic-gate  *	contents of the C., D. and X. files.  In addition, it
427c478bd9Sstevel@tonic-gate  *	thinks it knows what mail and netnews data files look like.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  *	At present, this is what is done:
457c478bd9Sstevel@tonic-gate  *	For WARNING messages:
467c478bd9Sstevel@tonic-gate  *	C. files of age given by -W option are read, looking for
477c478bd9Sstevel@tonic-gate  *		either user files to be sent or received, or
487c478bd9Sstevel@tonic-gate  *		mail to be sent.  (Other remote execution that
497c478bd9Sstevel@tonic-gate  *		does not involve sending user files is not checked
507c478bd9Sstevel@tonic-gate  *		for now.)  In either of the cases, the user is
517c478bd9Sstevel@tonic-gate  *		informed by mail that the request is not being
527c478bd9Sstevel@tonic-gate  *		processed due to lack of communications with the remote
537c478bd9Sstevel@tonic-gate  *		system, and the request will be deleted in the future
547c478bd9Sstevel@tonic-gate  *		if it the condition remains for several more days.
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  *	For DELETIONS:
577c478bd9Sstevel@tonic-gate  *	C. files - if they reference only D. files, the C. is
587c478bd9Sstevel@tonic-gate  *		merely deleted, because the D. files are usually
597c478bd9Sstevel@tonic-gate  *		mail or news, and the later D. processing will
607c478bd9Sstevel@tonic-gate  *		take care of them.
617c478bd9Sstevel@tonic-gate  *		- if they reference files from the file system,
627c478bd9Sstevel@tonic-gate  *		a message is constructed that will contain a
637c478bd9Sstevel@tonic-gate  *		lines like
647c478bd9Sstevel@tonic-gate  *		   We can't contact the remote.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  *		   local!file -> remote!otherfile
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  *		   can't be executed.
697c478bd9Sstevel@tonic-gate  *	X. files - merely deleted at present - D.s will be taken
707c478bd9Sstevel@tonic-gate  *		care of later. Besides, some of the D.s are
717c478bd9Sstevel@tonic-gate  *		missing or else the X. wouldn't be left around.
727c478bd9Sstevel@tonic-gate  *	D. files - mail type data is sent to a local person if that
737c478bd9Sstevel@tonic-gate  *		is where it originated.  If not, it is returned to the
747c478bd9Sstevel@tonic-gate  *		sender -- assumed to be from the first From line.  If
757c478bd9Sstevel@tonic-gate  *		a sender can't be determing, the file is merely deleted.
767c478bd9Sstevel@tonic-gate  *		- rnews: if locally generated, just delete.  If remote,
777c478bd9Sstevel@tonic-gate  *		the X. got lost, so execute rnews.
787c478bd9Sstevel@tonic-gate  *	other files - just delete them.
797c478bd9Sstevel@tonic-gate  *	.Workspace files over a day old
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  *	Deletions and executions are logged in
827c478bd9Sstevel@tonic-gate  *	(CLEANUPLOG)--/var/uucp/.Admin/uucleanup
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #include	"uucp.h"
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate #ifdef	V7
887c478bd9Sstevel@tonic-gate #define O_RDONLY	0
897c478bd9Sstevel@tonic-gate #endif
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define USAGE	"[-oDAYS] [-mSTRING] [-Cdays] [-Ddays] [-Wdays] [-Xdays] [-xLEVEL] [-sSYSTEM]"
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate extern int _age();		/* find the age of a file */
947c478bd9Sstevel@tonic-gate extern void procdtype(), oprocess(), xprocess(), cprocess();
957c478bd9Sstevel@tonic-gate extern void dXprocess(), dNprocess(), dMprocess(), dDprocess(), wprocess();
967c478bd9Sstevel@tonic-gate extern int toWho(), sendMail(), execRnews();
977c478bd9Sstevel@tonic-gate extern void logit();
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* need these dummys to satisy some .o files */
1007c478bd9Sstevel@tonic-gate void cleanup(){}
1017c478bd9Sstevel@tonic-gate void systat(){}
1027c478bd9Sstevel@tonic-gate void logent(){}
1037c478bd9Sstevel@tonic-gate 
104*462be471Sceastha static void cleanworkspace(void);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /* types of D. files */
1077c478bd9Sstevel@tonic-gate #define D_MAIL	1
1087c478bd9Sstevel@tonic-gate #define D_NEWS	2
1097c478bd9Sstevel@tonic-gate #define D_XFILE	3
1107c478bd9Sstevel@tonic-gate #define D_DATA	4
1117c478bd9Sstevel@tonic-gate #define FULLNAME(full,dir,file)	(void) sprintf(full, "%s/%s", dir, file);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate int _Ddays = 7;			/* D. limit */
1147c478bd9Sstevel@tonic-gate int _Cdays = 7;			/* C. limit */
1157c478bd9Sstevel@tonic-gate int _Xdays = 2;			/* X. limit */
1167c478bd9Sstevel@tonic-gate int _Odays = 2;			/* O. limit */
1177c478bd9Sstevel@tonic-gate int _Wdays = 1;			/* Warning limit for C. files */
1187c478bd9Sstevel@tonic-gate char _ShortLocal[6];		/* 5 char or less version of local name */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate char *_Undeliverable[] = {
1217c478bd9Sstevel@tonic-gate "Subject: Undeliverable Mail\n",
1227c478bd9Sstevel@tonic-gate "This mail message is undeliverable.\n",
1237c478bd9Sstevel@tonic-gate "(Probably to or from system '%s')\n",
1247c478bd9Sstevel@tonic-gate "It was sent to you or by you.\n",
1257c478bd9Sstevel@tonic-gate "Sorry for the inconvenience.\n",
1267c478bd9Sstevel@tonic-gate "",
1277c478bd9Sstevel@tonic-gate };
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #define CANT1	2	/* first line to fill in */
1307c478bd9Sstevel@tonic-gate #define CANT2	3	/* second line to fill in */
1317c478bd9Sstevel@tonic-gate char *_CantContact[] = {
1327c478bd9Sstevel@tonic-gate "Subject: Job Killed By uucp\n",
1337c478bd9Sstevel@tonic-gate "We can't contact machine '%s'.\n",
1347c478bd9Sstevel@tonic-gate " ",	/* uucleanup will fill in variable text here */
1357c478bd9Sstevel@tonic-gate " ",	/* fill in jobid of killed job */
1367c478bd9Sstevel@tonic-gate "",
1377c478bd9Sstevel@tonic-gate };
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define WARN1	2
1407c478bd9Sstevel@tonic-gate #define WARN2	5
1417c478bd9Sstevel@tonic-gate #define WARN3	6
1427c478bd9Sstevel@tonic-gate char *_Warning[] = {
1437c478bd9Sstevel@tonic-gate "Subject: Warning From uucp\n",
1447c478bd9Sstevel@tonic-gate "We have been unable to contact machine '%s' since you queued your job.\n",
1457c478bd9Sstevel@tonic-gate " ",	/*  wprocess FILLS IN THIS LINE OF TEXT */
1467c478bd9Sstevel@tonic-gate "Attempts will continue for a few more days.\n",
1477c478bd9Sstevel@tonic-gate "",
1487c478bd9Sstevel@tonic-gate " ",	/*  wprocess FILLS IN THIS LINE WITH:  uucp job id is JOBid. */
1497c478bd9Sstevel@tonic-gate " ",	/* FILL IN THE -m STRING IF SPECIFIED */
1507c478bd9Sstevel@tonic-gate "",
1517c478bd9Sstevel@tonic-gate };
1527c478bd9Sstevel@tonic-gate 
153*462be471Sceastha int
1547c478bd9Sstevel@tonic-gate main(argc, argv, envp)
155*462be471Sceastha int argc;
1567c478bd9Sstevel@tonic-gate char *argv[];
1577c478bd9Sstevel@tonic-gate char **envp;
1587c478bd9Sstevel@tonic-gate {
1597c478bd9Sstevel@tonic-gate 	DIR *jcdir, *machdir, *spooldir;
1607c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME], statfile[MAXFULLNAME], machname[MAXFULLNAME];
1617c478bd9Sstevel@tonic-gate 	char file1[NAMESIZE+1], file2[NAMESIZE+1], file3[NAMESIZE+1];
1627c478bd9Sstevel@tonic-gate 	char soptName[MAXFULLNAME], lockname[MAXFULLNAME];	/* name from -s option */
1637c478bd9Sstevel@tonic-gate 	int i, value;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	soptName[0] = NULLCHAR;
1667c478bd9Sstevel@tonic-gate 	(void) strcpy(Logfile, CLEANUPLOGFILE);
1677c478bd9Sstevel@tonic-gate 	uucpname(Myname);
1687c478bd9Sstevel@tonic-gate 	(void) strncpy(_ShortLocal, Myname, 5);
1697c478bd9Sstevel@tonic-gate 	_ShortLocal[5] = NULLCHAR;
1707c478bd9Sstevel@tonic-gate 	(void) strcpy(Progname, "uucleanup");
1717c478bd9Sstevel@tonic-gate 	while ((i = getopt(argc, argv, "C:D:W:X:m:o:s:x:")) != EOF) {
1727c478bd9Sstevel@tonic-gate 		switch(i){
1737c478bd9Sstevel@tonic-gate 		case 's':	/* for debugging - choose system */
1747c478bd9Sstevel@tonic-gate 			(void) strcpy(soptName, optarg);
1757c478bd9Sstevel@tonic-gate 			break;
1767c478bd9Sstevel@tonic-gate 		case 'x':
1777c478bd9Sstevel@tonic-gate 			Debug = atoi(optarg);
1787c478bd9Sstevel@tonic-gate 			if (Debug <= 0 || Debug >= 10) {
1797c478bd9Sstevel@tonic-gate 				fprintf(stderr,
1807c478bd9Sstevel@tonic-gate 				"WARNING: %s: invalid debug level %s ignored, using level 1\n",
1817c478bd9Sstevel@tonic-gate 					Progname, optarg);
1827c478bd9Sstevel@tonic-gate 				Debug = 1;
1837c478bd9Sstevel@tonic-gate 			}
1847c478bd9Sstevel@tonic-gate #ifdef SMALL
1857c478bd9Sstevel@tonic-gate 			fprintf(stderr,
1867c478bd9Sstevel@tonic-gate 				"WARNING: uucleanup built with SMALL flag defined -- no debug info available\n");
1877c478bd9Sstevel@tonic-gate #endif /* SMALL */
1887c478bd9Sstevel@tonic-gate 			break;
1897c478bd9Sstevel@tonic-gate 		case 'm':
1907c478bd9Sstevel@tonic-gate 			_Warning[WARN3] = optarg;
1917c478bd9Sstevel@tonic-gate 			break;
1927c478bd9Sstevel@tonic-gate 		default:
1937c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "\tusage: %s %s\n",
1947c478bd9Sstevel@tonic-gate 				Progname, USAGE);
1957c478bd9Sstevel@tonic-gate 			exit(1);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 		case 'C':
1987c478bd9Sstevel@tonic-gate 		case 'D':
1997c478bd9Sstevel@tonic-gate 		case 'W':
2007c478bd9Sstevel@tonic-gate 		case 'X':
2017c478bd9Sstevel@tonic-gate 		case 'o':
2027c478bd9Sstevel@tonic-gate 			value = atoi(optarg);
2037c478bd9Sstevel@tonic-gate 			if (value < 1) {
2047c478bd9Sstevel@tonic-gate 				fprintf(stderr," Options: CDWXo require value > 0\n");
2057c478bd9Sstevel@tonic-gate 				exit(1);
2067c478bd9Sstevel@tonic-gate 			}
2077c478bd9Sstevel@tonic-gate 			switch(i) {
2087c478bd9Sstevel@tonic-gate 			case 'C':
2097c478bd9Sstevel@tonic-gate 				_Cdays = value;
2107c478bd9Sstevel@tonic-gate 				break;
2117c478bd9Sstevel@tonic-gate 			case 'D':
2127c478bd9Sstevel@tonic-gate 				_Ddays = value;
2137c478bd9Sstevel@tonic-gate 				break;
2147c478bd9Sstevel@tonic-gate 			case 'W':
2157c478bd9Sstevel@tonic-gate 				_Wdays = value;
2167c478bd9Sstevel@tonic-gate 				break;
2177c478bd9Sstevel@tonic-gate 			case 'X':
2187c478bd9Sstevel@tonic-gate 				_Xdays = value;
2197c478bd9Sstevel@tonic-gate 				break;
2207c478bd9Sstevel@tonic-gate 			case 'o':
2217c478bd9Sstevel@tonic-gate 				_Odays = value;
2227c478bd9Sstevel@tonic-gate 				break;
2237c478bd9Sstevel@tonic-gate 			}
2247c478bd9Sstevel@tonic-gate 			break;
2257c478bd9Sstevel@tonic-gate 		}
2267c478bd9Sstevel@tonic-gate 	}
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	if (argc != optind) {
2297c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
2307c478bd9Sstevel@tonic-gate 		exit(1);
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	DEBUG(5, "Progname (%s): STARTED\n", Progname);
2347c478bd9Sstevel@tonic-gate 	DEBUG(5, "Myname (%s), ", Myname);
2357c478bd9Sstevel@tonic-gate 	DEBUG(5, "_ShortLocal (%s)\n", _ShortLocal);
2367c478bd9Sstevel@tonic-gate 	DEBUG(5, "Days C.(%d), ", _Cdays);
2377c478bd9Sstevel@tonic-gate 	DEBUG(5, "D.(%d), ", _Ddays);
2387c478bd9Sstevel@tonic-gate 	DEBUG(5, "W.(%d), ", _Wdays);
2397c478bd9Sstevel@tonic-gate 	DEBUG(5, "X.(%d), ", _Xdays);
2407c478bd9Sstevel@tonic-gate 	DEBUG(5, "other (%d)\n", _Odays);
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	cleanworkspace();
2437c478bd9Sstevel@tonic-gate 	if (chdir(SPOOL) != 0) {
2447c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T CHDIR (%s): errno (%d)\n",
2457c478bd9Sstevel@tonic-gate 			SPOOL, errno);
2467c478bd9Sstevel@tonic-gate 		exit(1);
2477c478bd9Sstevel@tonic-gate 	}
2487c478bd9Sstevel@tonic-gate 	if ((spooldir = opendir(SPOOL)) == NULL) {
2497c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
2507c478bd9Sstevel@tonic-gate 			SPOOL, errno);
2517c478bd9Sstevel@tonic-gate 		exit(1);
2527c478bd9Sstevel@tonic-gate 	}
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	while (gdirf(spooldir, file1, SPOOL) == TRUE) {
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 		if (*soptName && !EQUALS(soptName, file1))
2577c478bd9Sstevel@tonic-gate 			continue;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 		(void) strcpy(Rmtname, file1);
2607c478bd9Sstevel@tonic-gate 		(void) sprintf(machname, "%s/%s", SPOOL, file1);
2617c478bd9Sstevel@tonic-gate 		if ((machdir = opendir(machname)) == NULL) {
2627c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
2637c478bd9Sstevel@tonic-gate 				machname, errno);
2647c478bd9Sstevel@tonic-gate 			if (*soptName)
2657c478bd9Sstevel@tonic-gate 				break;
2667c478bd9Sstevel@tonic-gate 			else
2677c478bd9Sstevel@tonic-gate 				continue;
2687c478bd9Sstevel@tonic-gate 		}
2697c478bd9Sstevel@tonic-gate 		DEBUG(7, "Directory: (%s) is open\n", file1);
2707c478bd9Sstevel@tonic-gate 		while (gnamef(machdir, file2) == TRUE) {
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 			(void) sprintf(statfile, "%s/%s", machname, file2);
2737c478bd9Sstevel@tonic-gate 			if (DIRECTORY(statfile)) {
2747c478bd9Sstevel@tonic-gate 				(void) sprintf(lockname, "%s.%.*s.%s",
2757c478bd9Sstevel@tonic-gate 					LOCKPRE, SYSNSIZE, file1, file2);
2767c478bd9Sstevel@tonic-gate 				if (cklock(lockname))
2777c478bd9Sstevel@tonic-gate 					continue;
2787c478bd9Sstevel@tonic-gate 				if ((jcdir = opendir(statfile)) == NULL) {
2797c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr,
2807c478bd9Sstevel@tonic-gate 						"CAN'T OPEN (%s): errno (%d)\n",
2817c478bd9Sstevel@tonic-gate 						statfile, errno);
2827c478bd9Sstevel@tonic-gate 					continue;
2837c478bd9Sstevel@tonic-gate 				}
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 				DEBUG(7, "Directory: (%s) is open\n", file2);
2867c478bd9Sstevel@tonic-gate 				while (gnamef(jcdir, file3)) {
2877c478bd9Sstevel@tonic-gate 					DEBUG(9, "file: %s\n", file3);
2887c478bd9Sstevel@tonic-gate 					FULLNAME(fullname, statfile, file3);
2897c478bd9Sstevel@tonic-gate 					DEBUG(9,"Fullname is (%s)\n", fullname);
2907c478bd9Sstevel@tonic-gate 					if (EQUALSN(file3, "C.", 2)) {
2917c478bd9Sstevel@tonic-gate 						if (_age(fullname) >= _Cdays)
2927c478bd9Sstevel@tonic-gate 							cprocess(fullname);
2937c478bd9Sstevel@tonic-gate 						else if(_age(fullname) >= _Wdays)
2947c478bd9Sstevel@tonic-gate 							wprocess(statfile, file3);
2957c478bd9Sstevel@tonic-gate 					}
2967c478bd9Sstevel@tonic-gate 					else if (EQUALSN(file3, "D.", 2)) {
2977c478bd9Sstevel@tonic-gate 						if (_age(fullname) >= _Ddays)
2987c478bd9Sstevel@tonic-gate 							procdtype(statfile, file3);
2997c478bd9Sstevel@tonic-gate 					}
3007c478bd9Sstevel@tonic-gate 					else if (_age(fullname) >= _Odays)
3017c478bd9Sstevel@tonic-gate 						oprocess(fullname);
3027c478bd9Sstevel@tonic-gate 				}
3037c478bd9Sstevel@tonic-gate 				closedir(jcdir);
3047c478bd9Sstevel@tonic-gate 				continue;
3057c478bd9Sstevel@tonic-gate 			}
3067c478bd9Sstevel@tonic-gate 			DEBUG(9, "file: %s\n", file2);
3077c478bd9Sstevel@tonic-gate 			DEBUG(9, "Fullname is (%s)\n", statfile);
3087c478bd9Sstevel@tonic-gate 			if (EQUALSN(file2, "X.", 2)) {
3097c478bd9Sstevel@tonic-gate 				if (_age(statfile) >= _Xdays)
3107c478bd9Sstevel@tonic-gate 					xprocess(statfile);
3117c478bd9Sstevel@tonic-gate 			}
3127c478bd9Sstevel@tonic-gate 			else if (EQUALSN(file2, "D.", 2)) {
3137c478bd9Sstevel@tonic-gate 				if (_age(statfile) >= _Ddays)
3147c478bd9Sstevel@tonic-gate 					procdtype(machname, file2);
3157c478bd9Sstevel@tonic-gate 			}
3167c478bd9Sstevel@tonic-gate 			else if (_age(statfile) >= _Odays)
3177c478bd9Sstevel@tonic-gate 				oprocess(statfile);
3187c478bd9Sstevel@tonic-gate 		}
3197c478bd9Sstevel@tonic-gate 		closedir(machdir);
3207c478bd9Sstevel@tonic-gate 	}
3217c478bd9Sstevel@tonic-gate 	closedir(spooldir);
322*462be471Sceastha 	return (0);
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate /* procdtype - select the type of processing that a D. file should receive */
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate void
3287c478bd9Sstevel@tonic-gate procdtype(dir, file)
3297c478bd9Sstevel@tonic-gate char *dir, *file;
3307c478bd9Sstevel@tonic-gate {
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME];
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	FULLNAME(fullname, dir, file);
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	switch(dType(fullname)) {
3377c478bd9Sstevel@tonic-gate 	case D_DATA:
3387c478bd9Sstevel@tonic-gate 		dDprocess(fullname);
3397c478bd9Sstevel@tonic-gate 		break;
3407c478bd9Sstevel@tonic-gate 	case D_MAIL:
3417c478bd9Sstevel@tonic-gate 		dMprocess(dir, file);
3427c478bd9Sstevel@tonic-gate 		break;
3437c478bd9Sstevel@tonic-gate 	case D_NEWS:
3447c478bd9Sstevel@tonic-gate 		dNprocess(dir, file);
3457c478bd9Sstevel@tonic-gate 		break;
3467c478bd9Sstevel@tonic-gate 	case D_XFILE:
3477c478bd9Sstevel@tonic-gate 		dXprocess(fullname);
3487c478bd9Sstevel@tonic-gate 		break;
3497c478bd9Sstevel@tonic-gate 	default:
3507c478bd9Sstevel@tonic-gate 		break;
3517c478bd9Sstevel@tonic-gate 	}
3527c478bd9Sstevel@tonic-gate 	return;
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate /* xprocess - X. file processing -- just remove the X. for now */
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate void
3587c478bd9Sstevel@tonic-gate xprocess(fullname)
3597c478bd9Sstevel@tonic-gate char *fullname;
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	DEBUG(5, "xprocess(%s), ", fullname);
3647c478bd9Sstevel@tonic-gate 	DEBUG(5, "unlink(%s)\n", fullname);
3657c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "xprocess: unlink(%s)", fullname);
3667c478bd9Sstevel@tonic-gate 	errno = 0;
3677c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
3687c478bd9Sstevel@tonic-gate 	logit(text, errno);
3697c478bd9Sstevel@tonic-gate 	return;
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate /*
3737c478bd9Sstevel@tonic-gate  * cprocess - Process old C. files
3747c478bd9Sstevel@tonic-gate  *
3757c478bd9Sstevel@tonic-gate  */
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate #define CMFMT  "\n\t%s!%s -> %s!%s   (Date %2.2d/%2.2d)\n\nCan't be executed."
3787c478bd9Sstevel@tonic-gate #define XFMT  "\n\t%s!%s  (Date %2.2d/%2.2d)\n"
3797c478bd9Sstevel@tonic-gate #define XMFMT  "\n\tmail %s!%s   (Date %2.2d/%2.2d)\n"
3807c478bd9Sstevel@tonic-gate #define WFMT  "\n\t%s!%s -> %s!%s   (Date %2.2d/%2.2d)\n"
3817c478bd9Sstevel@tonic-gate void
3827c478bd9Sstevel@tonic-gate cprocess(fullname)
3837c478bd9Sstevel@tonic-gate char *fullname;
3847c478bd9Sstevel@tonic-gate {
3857c478bd9Sstevel@tonic-gate 	struct stat s;
386*462be471Sceastha 	struct tm *tp;
3877c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ], user[9];
3887c478bd9Sstevel@tonic-gate 	char file1[BUFSIZ], file2[BUFSIZ], file3[BUFSIZ], type[2], opt[256];
3897c478bd9Sstevel@tonic-gate 	char text[BUFSIZ], text1[BUFSIZ], text2[BUFSIZ];
3907c478bd9Sstevel@tonic-gate 	FILE *fp;
3917c478bd9Sstevel@tonic-gate 	int ret;
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	DEBUG(5, "cprocess(%s)\n", fullname);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	fp = fopen(fullname, "r");
3977c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
3987c478bd9Sstevel@tonic-gate 		DEBUG(5, "Can't open file (%s), ", fullname);
3997c478bd9Sstevel@tonic-gate 		DEBUG(5, "errno=%d -- skip it!\n", errno);
4007c478bd9Sstevel@tonic-gate 		return;
4017c478bd9Sstevel@tonic-gate 	}
4027c478bd9Sstevel@tonic-gate 	if (fstat(fileno(fp), &s) != 0) {
4037c478bd9Sstevel@tonic-gate 	    /* can't happen; _age() did stat of this file and file is opened */
4047c478bd9Sstevel@tonic-gate 	    (void) fclose(fp);
4057c478bd9Sstevel@tonic-gate 	    return;
4067c478bd9Sstevel@tonic-gate 	}
4077c478bd9Sstevel@tonic-gate 	tp = localtime(&s.st_mtime);
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	if (s.st_size == 0) { /* dummy C. for polling */
4107c478bd9Sstevel@tonic-gate 		DEBUG(5, "dummy C. -- unlink(%s)\n", fullname);
4117c478bd9Sstevel@tonic-gate 		(void) sprintf(text, "dDprocess: dummy C. unlinked(%s)",
4127c478bd9Sstevel@tonic-gate 			fullname);
4137c478bd9Sstevel@tonic-gate 		errno = 0;
4147c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
4157c478bd9Sstevel@tonic-gate 		logit(text, errno);
4167c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
4177c478bd9Sstevel@tonic-gate 		return;
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	/* Read the C. file and process it */
4217c478bd9Sstevel@tonic-gate 	while (fgets(buf, BUFSIZ, fp) != NULL) {
4227c478bd9Sstevel@tonic-gate 		buf[strlen(buf)-1] = NULLCHAR; /* remove \n */
4237c478bd9Sstevel@tonic-gate 		if (sscanf(buf,"%s%s%s%s%s%s", type, file1, file2,
4247c478bd9Sstevel@tonic-gate 			user, opt, file3) <5) {
4257c478bd9Sstevel@tonic-gate 			(void) sprintf(text, "cprocess: Bad C. %s, unlink(%s)",
4267c478bd9Sstevel@tonic-gate 				buf, fullname);
4277c478bd9Sstevel@tonic-gate 			break;
4287c478bd9Sstevel@tonic-gate 		}
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 		*text = NULLCHAR;
4317c478bd9Sstevel@tonic-gate 		ret = 0;
4327c478bd9Sstevel@tonic-gate 		/* fill in line 3 of text */
4337c478bd9Sstevel@tonic-gate 		(void) sprintf(text2, "Job (%s) killed!\n",
4347c478bd9Sstevel@tonic-gate 		BASENAME(fullname, '/')+2);
4357c478bd9Sstevel@tonic-gate 		_CantContact[CANT2] = text2;
4367c478bd9Sstevel@tonic-gate 		if (*type == 'S') {
4377c478bd9Sstevel@tonic-gate 			if (EQUALSN(file1, "D.", 2))
4387c478bd9Sstevel@tonic-gate 				/* generated file (mail/news) I think */
4397c478bd9Sstevel@tonic-gate 				/* D. processing will return it later */
4407c478bd9Sstevel@tonic-gate 				continue;
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 			/* some data was requested -- tell user */
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, CMFMT, Myname, file1, Rmtname, file2,
4457c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
4467c478bd9Sstevel@tonic-gate 			_CantContact[CANT1] = text1;
4477c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _CantContact);
4487c478bd9Sstevel@tonic-gate 		}
4497c478bd9Sstevel@tonic-gate 		else if (*type == 'R') {
4507c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, CMFMT, Rmtname, file1, Myname, file2,
4517c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
4527c478bd9Sstevel@tonic-gate 			_CantContact[CANT1] = text1;
4537c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _CantContact);
4547c478bd9Sstevel@tonic-gate 		}
4557c478bd9Sstevel@tonic-gate 	}
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	if (!*text) {
4587c478bd9Sstevel@tonic-gate 		(void) sprintf(text,
4597c478bd9Sstevel@tonic-gate 			"cprocess: C. %s, mail returned (%d), unlink(%s)",
4607c478bd9Sstevel@tonic-gate 			buf, ret, fullname);
4617c478bd9Sstevel@tonic-gate 	}
4627c478bd9Sstevel@tonic-gate 	DEBUG(3, "text (%s)\n", text);
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 	errno = 0;
4657c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
4667c478bd9Sstevel@tonic-gate 	logit(text, errno);
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
4697c478bd9Sstevel@tonic-gate 	return;
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate /*
4737c478bd9Sstevel@tonic-gate  * wprocess - send warning messages for C. == Wdays
4747c478bd9Sstevel@tonic-gate  */
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate void
4777c478bd9Sstevel@tonic-gate wprocess(dir, file)
4787c478bd9Sstevel@tonic-gate char *dir, *file;
4797c478bd9Sstevel@tonic-gate {
4807c478bd9Sstevel@tonic-gate 	struct stat s;
481*462be471Sceastha 	struct tm *tp;
4827c478bd9Sstevel@tonic-gate 	char fullname[BUFSIZ], xfile[BUFSIZ], xF_file[BUFSIZ];
4837c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ], user[BUFSIZ];
4847c478bd9Sstevel@tonic-gate 	char file1[BUFSIZ], file2[BUFSIZ], file3[BUFSIZ], type[2], opt[256];
4857c478bd9Sstevel@tonic-gate 	char text[BUFSIZ], text1[BUFSIZ], text2[BUFSIZ];
4867c478bd9Sstevel@tonic-gate 	char *realuser, uline_m[NAMESIZE], uline_u[BUFSIZ], retaddr[BUFSIZ];
4877c478bd9Sstevel@tonic-gate 	FILE *fp, *xfp;
4887c478bd9Sstevel@tonic-gate 	int ret;
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	FULLNAME(fullname, dir, file);
4917c478bd9Sstevel@tonic-gate 	DEBUG(5, "wprocess(%s)\n", fullname);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	fp = fopen(fullname, "r");
4947c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
4957c478bd9Sstevel@tonic-gate 		DEBUG(4, "Can't open file (%s), ", fullname);
4967c478bd9Sstevel@tonic-gate 		DEBUG(4, "errno=%d -- skip it!\n", errno);
4977c478bd9Sstevel@tonic-gate 		return;
4987c478bd9Sstevel@tonic-gate 	}
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 	if (fstat(fileno(fp), &s) != 0) {
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	/* can't happen; _age() did stat of this file and file is opened */
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
5057c478bd9Sstevel@tonic-gate 		return;
5067c478bd9Sstevel@tonic-gate 	}
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	tp = localtime(&s.st_mtime);
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	if (s.st_size == 0) { /* dummy C. for polling */
5117c478bd9Sstevel@tonic-gate 		DEBUG(5, "dummy C. -- skip(%s)\n", fullname);
5127c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
5137c478bd9Sstevel@tonic-gate 		return;
5147c478bd9Sstevel@tonic-gate 	}
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	/* read C. and process it */
5177c478bd9Sstevel@tonic-gate 	while (fgets(buf, BUFSIZ, fp) != NULL) {
5187c478bd9Sstevel@tonic-gate 		buf[strlen(buf)-1] = NULLCHAR; /* remove \n */
5197c478bd9Sstevel@tonic-gate 		if (sscanf(buf,"%s%s%s%s%s%s", type, file1, file2,
5207c478bd9Sstevel@tonic-gate 			user, opt, file3) <5) {
5217c478bd9Sstevel@tonic-gate 			DEBUG(5, "short line (%s): ", buf);
5227c478bd9Sstevel@tonic-gate 			DEBUG(5, "bad D. -- skip(%s)\n", fullname);
5237c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
5247c478bd9Sstevel@tonic-gate 			return;
5257c478bd9Sstevel@tonic-gate 		}
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 		/* set up the 6th text line of the mail message */
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 		(void) sprintf(text2,
5307c478bd9Sstevel@tonic-gate 			"\nuucp job id is %s.\n", BASENAME(fullname, '/')+2);
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 		_Warning[WARN2] = text2;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 		/* if Send type then do C. file processing */
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 		if (*type == 'S') {
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 		/* if this is a uux job - tell user about it */
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 			if (EQUALSN(file2, "X.", 2)) {
5417c478bd9Sstevel@tonic-gate 				FULLNAME(xfile, dir, file1);
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 				/* if X.file can't be read then skip it */
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 				if ((xfp = fopen(xfile, "r")) == NULL) {
5467c478bd9Sstevel@tonic-gate 					DEBUG(3, "Can't read %s\n", xfile);
5477c478bd9Sstevel@tonic-gate 					break;
5487c478bd9Sstevel@tonic-gate 				}
5497c478bd9Sstevel@tonic-gate 				*retaddr = *uline_u = *uline_m = *text = NULLCHAR;
5507c478bd9Sstevel@tonic-gate 				while (fgets(buf, BUFSIZ, xfp) != NULL) {
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 				/* remove \n from end of buffer */
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 					buf[strlen(buf)-1] = NULLCHAR;
5557c478bd9Sstevel@tonic-gate 					switch(*buf) {
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 					/* save the file name */
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 					case 'F':
5607c478bd9Sstevel@tonic-gate 						FULLNAME(xF_file, dir, &buf[2]);
5617c478bd9Sstevel@tonic-gate 						break;
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 					/* save return address */
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 					case 'R':
5667c478bd9Sstevel@tonic-gate 						sscanf(buf+2, "%s", retaddr);
5677c478bd9Sstevel@tonic-gate 						DEBUG(7, "retaddr (%s)\n", retaddr);
5687c478bd9Sstevel@tonic-gate 						break;
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 					/* save machine, user */
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate 					case 'U':
5737c478bd9Sstevel@tonic-gate 						sscanf(buf+2, "%s%s",
5747c478bd9Sstevel@tonic-gate 						    uline_u, uline_m);
5757c478bd9Sstevel@tonic-gate 						break;
5767c478bd9Sstevel@tonic-gate 					}
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 					if (buf[0] != 'C')
5797c478bd9Sstevel@tonic-gate 						continue;
5807c478bd9Sstevel@tonic-gate 					realuser = uline_u;
5817c478bd9Sstevel@tonic-gate 					if (*retaddr != NULLCHAR)
5827c478bd9Sstevel@tonic-gate 						realuser = retaddr;
5837c478bd9Sstevel@tonic-gate 					if (*realuser == NULLCHAR)
5847c478bd9Sstevel@tonic-gate 						strcpy(realuser, user);
5857c478bd9Sstevel@tonic-gate 					if (!EQUALS(uline_m, Myname))
5867c478bd9Sstevel@tonic-gate 						sprintf(user, "%s!%s",
5877c478bd9Sstevel@tonic-gate 						    uline_m, realuser);
5887c478bd9Sstevel@tonic-gate 					else
5897c478bd9Sstevel@tonic-gate 						strcpy(user, realuser);
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 					/* give mail special handling */
5927c478bd9Sstevel@tonic-gate 					if (EQUALSN(buf+2, "rmail ", 6))
5937c478bd9Sstevel@tonic-gate 						(void) sprintf(text1, XMFMT,
5947c478bd9Sstevel@tonic-gate 						    Rmtname, buf+8,
5957c478bd9Sstevel@tonic-gate 						    tp->tm_mon+1, tp->tm_mday);
5967c478bd9Sstevel@tonic-gate 					else
5977c478bd9Sstevel@tonic-gate 						(void) sprintf(text1, XFMT,
5987c478bd9Sstevel@tonic-gate 						    Rmtname, buf+2,
5997c478bd9Sstevel@tonic-gate 						    tp->tm_mon+1, tp->tm_mday);
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 					_Warning[WARN1] = text1;
6027c478bd9Sstevel@tonic-gate 					if (EQUALSN(&buf[2], "rmail", 5))
6037c478bd9Sstevel@tonic-gate 						/*
6047c478bd9Sstevel@tonic-gate 						 * this is mail; append
6057c478bd9Sstevel@tonic-gate 						 * user mail (xF_file).
6067c478bd9Sstevel@tonic-gate 						 */
6077c478bd9Sstevel@tonic-gate 						ret = sendMail((char *) NULL,
6087c478bd9Sstevel@tonic-gate 						    user, xF_file, _Warning);
6097c478bd9Sstevel@tonic-gate 					else
6107c478bd9Sstevel@tonic-gate 						ret = sendMail((char *) NULL,
6117c478bd9Sstevel@tonic-gate 						    user, "", _Warning);
6127c478bd9Sstevel@tonic-gate 					break;
6137c478bd9Sstevel@tonic-gate 				}
6147c478bd9Sstevel@tonic-gate 				(void) fclose(xfp);
6157c478bd9Sstevel@tonic-gate 				break;
6167c478bd9Sstevel@tonic-gate 			}
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 			/* if file1 is a D. file the it might be (mail/news) */
6197c478bd9Sstevel@tonic-gate 			/* if so then D. processing will take of it later */
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 			if (EQUALSN(file1, "D.", 2))
6227c478bd9Sstevel@tonic-gate 				continue;
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 			/* some data was requested -- tell user */
6257c478bd9Sstevel@tonic-gate 			/* set up the 2nd text line of the mail message */
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, WFMT, Myname, file1, Rmtname, file2,
6287c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
6297c478bd9Sstevel@tonic-gate 			_Warning[WARN1] = text1;
6307c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _Warning);
6317c478bd9Sstevel@tonic-gate 		}
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 		/* Receive C. file processing */
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 		else if (*type == 'R') {
6367c478bd9Sstevel@tonic-gate 			if (EQUALSN(file1, "D.", 2) && EQUALSN(file2, "D.", 2))
6377c478bd9Sstevel@tonic-gate 				continue;
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 			(void) sprintf(text1, WFMT, Rmtname, file1, Myname, file2,
6407c478bd9Sstevel@tonic-gate 				tp->tm_mon + 1, tp->tm_mday);
6417c478bd9Sstevel@tonic-gate 			_Warning[WARN1] = text1;
6427c478bd9Sstevel@tonic-gate 			ret = sendMail((char *) NULL, user, "", _Warning);
6437c478bd9Sstevel@tonic-gate 		}
6447c478bd9Sstevel@tonic-gate 	}	/* end while - read C. lines loop */
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	(void) sprintf(text,
6477c478bd9Sstevel@tonic-gate 		"wprocess: %s: %s, warning message sent to %s, returned (%d)",
6487c478bd9Sstevel@tonic-gate 		fullname, buf, user, ret);
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 	DEBUG(3, "text (%s)\n", text);
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 	logit(text, errno);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
6557c478bd9Sstevel@tonic-gate 	return;
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate /*
6587c478bd9Sstevel@tonic-gate  * oprocess - some unknown file just remove the file
6597c478bd9Sstevel@tonic-gate  */
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate void
6627c478bd9Sstevel@tonic-gate oprocess(fullname)
6637c478bd9Sstevel@tonic-gate char *fullname;
6647c478bd9Sstevel@tonic-gate {
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 	char *p, text[BUFSIZ];
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	p = BASENAME(fullname, '/');
6697c478bd9Sstevel@tonic-gate 	if (EQUALSN(p, "P.", 2) == 0)
6707c478bd9Sstevel@tonic-gate 		if (_age(fullname) <= _Cdays)
6717c478bd9Sstevel@tonic-gate 			return;
6727c478bd9Sstevel@tonic-gate 	DEBUG(5, "oprocess(%s), ", fullname);
6737c478bd9Sstevel@tonic-gate 	DEBUG(5, "unlink(%s)\n", fullname);
6747c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "oprocess: unlink(%s)", fullname);
6757c478bd9Sstevel@tonic-gate 	errno = 0;
6767c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
6777c478bd9Sstevel@tonic-gate 	logit(text, errno);
6787c478bd9Sstevel@tonic-gate 	return;
6797c478bd9Sstevel@tonic-gate }
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate /*
6827c478bd9Sstevel@tonic-gate  * dDprocess - random D. file (not mail or rnews)
6837c478bd9Sstevel@tonic-gate  *--just delete it for now
6847c478bd9Sstevel@tonic-gate  */
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate void
6877c478bd9Sstevel@tonic-gate dDprocess(fullname)
6887c478bd9Sstevel@tonic-gate char *fullname;
6897c478bd9Sstevel@tonic-gate {
6907c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	DEBUG(5, "dDprocess(%s), ", fullname);
6937c478bd9Sstevel@tonic-gate 	DEBUG(5, "unlink(%s)\n", fullname);
6947c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "dDprocess: unlink(%s)", fullname);
6957c478bd9Sstevel@tonic-gate 	errno = 0;
6967c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
6977c478bd9Sstevel@tonic-gate 	logit(text, errno);
6987c478bd9Sstevel@tonic-gate 	return;
6997c478bd9Sstevel@tonic-gate }
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate /*
7027c478bd9Sstevel@tonic-gate  * dXprocess - process D. files that are destined for X. on remote
7037c478bd9Sstevel@tonic-gate  * --for now just delete it
7047c478bd9Sstevel@tonic-gate  */
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate void
7077c478bd9Sstevel@tonic-gate dXprocess(fullname)
7087c478bd9Sstevel@tonic-gate char *fullname;
7097c478bd9Sstevel@tonic-gate {
7107c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 	DEBUG(5, "dXprocess(%s), ", fullname);
7137c478bd9Sstevel@tonic-gate 	DEBUG(5, "  unlink(%s)\n", fullname);
7147c478bd9Sstevel@tonic-gate 	(void) sprintf(text, "dXprocess: unlink(%s)", fullname);
7157c478bd9Sstevel@tonic-gate 	errno = 0;
7167c478bd9Sstevel@tonic-gate 	(void) unlink(fullname);
7177c478bd9Sstevel@tonic-gate 	logit(text, errno);
7187c478bd9Sstevel@tonic-gate 	return;
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate /*
7227c478bd9Sstevel@tonic-gate  * dMprocess - process ophan D. mail files
7237c478bd9Sstevel@tonic-gate  * There are two types: ones generated locally and
7247c478bd9Sstevel@tonic-gate  * others that are from remotes.  They can be identified
7257c478bd9Sstevel@tonic-gate  * by the system name following the D.
7267c478bd9Sstevel@tonic-gate  * Local ones have the local name.
7277c478bd9Sstevel@tonic-gate  */
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate void
7307c478bd9Sstevel@tonic-gate dMprocess(dir, file)
7317c478bd9Sstevel@tonic-gate char *dir, *file;
7327c478bd9Sstevel@tonic-gate {
7337c478bd9Sstevel@tonic-gate 	int ret;
7347c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME];
7357c478bd9Sstevel@tonic-gate 	char *toUser, *toSystem;
7367c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	(void) sprintf(fullname, "%s/%s", dir, file);
7397c478bd9Sstevel@tonic-gate 	DEBUG(5, "dMprocess(%s)\n", fullname);
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 	if (PREFIX(_ShortLocal, &file[2])) {
7437c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Local file %s: ", file);
7447c478bd9Sstevel@tonic-gate 	}
7457c478bd9Sstevel@tonic-gate 	else {
7467c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Remote file %s: ", file);
7477c478bd9Sstevel@tonic-gate 	}
7487c478bd9Sstevel@tonic-gate 	if (toWho(fullname, &toUser, &toSystem)) {
7497c478bd9Sstevel@tonic-gate 		DEBUG(5, "toUser %s, ", toUser);
7507c478bd9Sstevel@tonic-gate 		DEBUG(5, "toSystem %s  ", toSystem);
7517c478bd9Sstevel@tonic-gate 		ret = sendMail(toSystem, toUser, fullname, _Undeliverable);
7527c478bd9Sstevel@tonic-gate 		DEBUG(5, "Mail sent, unlink(%s)\n", fullname);
7537c478bd9Sstevel@tonic-gate 		(void) sprintf(text,
7547c478bd9Sstevel@tonic-gate 			"dMprocess: mail %s to %s!%s, returned (%d),  unlink(%s)",
7557c478bd9Sstevel@tonic-gate 			fullname, toSystem, toUser, ret, fullname);
7567c478bd9Sstevel@tonic-gate 		errno = 0;
7577c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
7587c478bd9Sstevel@tonic-gate 		logit(text, errno);
7597c478bd9Sstevel@tonic-gate 	}
7607c478bd9Sstevel@tonic-gate 	return;
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate /*
7647c478bd9Sstevel@tonic-gate  * dNprocess - process ophan D. netnews files
7657c478bd9Sstevel@tonic-gate  * There are two types: ones generated locally and
7667c478bd9Sstevel@tonic-gate  * others that are from remotes.  They can be identified
7677c478bd9Sstevel@tonic-gate  * by the system name following the D.
7687c478bd9Sstevel@tonic-gate  * Local ones have the local name.
7697c478bd9Sstevel@tonic-gate  */
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate void
7727c478bd9Sstevel@tonic-gate dNprocess(dir, file)
7737c478bd9Sstevel@tonic-gate char *dir, *file;
7747c478bd9Sstevel@tonic-gate {
7757c478bd9Sstevel@tonic-gate 	char fullname[MAXFULLNAME];
7767c478bd9Sstevel@tonic-gate 	char text[BUFSIZ];
7777c478bd9Sstevel@tonic-gate 	int ret;
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 	(void) sprintf(fullname, "%s/%s", dir, file);
7807c478bd9Sstevel@tonic-gate 	DEBUG(5, "dNprocess(%s)\n", fullname);
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 	if (PREFIX(_ShortLocal, &file[2])) {
7847c478bd9Sstevel@tonic-gate 	/* just delete it, the C. is gone */
7857c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Local file %s, ", file);
7867c478bd9Sstevel@tonic-gate 		DEBUG(5, "unlink(%s)\n", fullname);
7877c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
7887c478bd9Sstevel@tonic-gate 		(void) sprintf(text, "dNprocess: Local news item unlink(%s)",
7897c478bd9Sstevel@tonic-gate 			fullname);
7907c478bd9Sstevel@tonic-gate 		errno = 0;
7917c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
7927c478bd9Sstevel@tonic-gate 		logit(text, errno);
7937c478bd9Sstevel@tonic-gate 	}
7947c478bd9Sstevel@tonic-gate 	else {
7957c478bd9Sstevel@tonic-gate 	/* execute rnews with this file - the X. is missing */
7967c478bd9Sstevel@tonic-gate 		DEBUG(5, "  Remote file %s, ", file);
7977c478bd9Sstevel@tonic-gate 		DEBUG(5, "exec rnews(%s), ", fullname);
7987c478bd9Sstevel@tonic-gate 		ret = execRnews(fullname);
7997c478bd9Sstevel@tonic-gate 		DEBUG(5, "unlink(%s)\n", fullname);
8007c478bd9Sstevel@tonic-gate 		(void) sprintf(text,
8017c478bd9Sstevel@tonic-gate 			"dNprocess: Remote - exec rnews %s: returned (%d), unlink(%s)",
8027c478bd9Sstevel@tonic-gate 			fullname, ret, fullname);
8037c478bd9Sstevel@tonic-gate 		errno = 0;
8047c478bd9Sstevel@tonic-gate 		(void) unlink(fullname);
8057c478bd9Sstevel@tonic-gate 		logit(text, errno);
8067c478bd9Sstevel@tonic-gate 	}
8077c478bd9Sstevel@tonic-gate 	return;
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate static long _sec_per_day = 86400L;
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate /*
8157c478bd9Sstevel@tonic-gate  * _age - find the age of "file" in days
8167c478bd9Sstevel@tonic-gate  * return:
8177c478bd9Sstevel@tonic-gate  *	age of file
8187c478bd9Sstevel@tonic-gate  *	0 - if stat fails
8197c478bd9Sstevel@tonic-gate  */
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate int
8227c478bd9Sstevel@tonic-gate _age(fullname)
8237c478bd9Sstevel@tonic-gate char *fullname;
8247c478bd9Sstevel@tonic-gate {
8257c478bd9Sstevel@tonic-gate 	static time_t ptime = 0;
8267c478bd9Sstevel@tonic-gate 	time_t time();
8277c478bd9Sstevel@tonic-gate 	struct stat stbuf;
8287c478bd9Sstevel@tonic-gate 	int e;
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	if (!ptime)
8317c478bd9Sstevel@tonic-gate 		(void) time(&ptime);
8327c478bd9Sstevel@tonic-gate 	if (stat(fullname, &stbuf) != -1) {
8337c478bd9Sstevel@tonic-gate 		return ((int)((ptime - stbuf.st_mtime)/_sec_per_day));
8347c478bd9Sstevel@tonic-gate 	}
8357c478bd9Sstevel@tonic-gate 	e = errno;
8367c478bd9Sstevel@tonic-gate 	DEBUG(9, "_age: stat (%s) failed", fullname);
8377c478bd9Sstevel@tonic-gate 	DEBUG(9, ", errno %d\n", e);
8387c478bd9Sstevel@tonic-gate 	return(0);
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate /*
8427c478bd9Sstevel@tonic-gate  * dType - return the type of D. file
8437c478bd9Sstevel@tonic-gate  * return:
8447c478bd9Sstevel@tonic-gate  *	FAIL - can't read D. file
8457c478bd9Sstevel@tonic-gate  *	D_MAIL - mail message D. file
8467c478bd9Sstevel@tonic-gate  *	D_NEWS - netnews D. file
8477c478bd9Sstevel@tonic-gate  *	D_DATA - other kind of D. file
8487c478bd9Sstevel@tonic-gate  *	D_XFILE - destined for X. on destination machine
8497c478bd9Sstevel@tonic-gate  */
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate /* NLINES - number of lines of D. file to read to determine type */
8527c478bd9Sstevel@tonic-gate #define NLINES	10
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate int
8557c478bd9Sstevel@tonic-gate dType(fullname)
8567c478bd9Sstevel@tonic-gate char *fullname;
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
8597c478bd9Sstevel@tonic-gate 	FILE *fp;
8607c478bd9Sstevel@tonic-gate 	int i, type;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 	fp = fopen(fullname, "r");
8637c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
8647c478bd9Sstevel@tonic-gate 		DEBUG(4, "Can't open file (%s), ", fullname);
8657c478bd9Sstevel@tonic-gate 		DEBUG(4, "errno=%d -- skip it!\n", errno);
8667c478bd9Sstevel@tonic-gate 		return(FAIL);
8677c478bd9Sstevel@tonic-gate 	}
8687c478bd9Sstevel@tonic-gate 	type = D_DATA;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	/* read first NLINES lines to determine file type */
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate 	for (i=0; i<NLINES; i++) {
8737c478bd9Sstevel@tonic-gate 		if (fgets(buf, BUFSIZ, fp) == NULL)
8747c478bd9Sstevel@tonic-gate 			break;	/* no more lines */
8757c478bd9Sstevel@tonic-gate 		DEBUG(9, "buf: %s\n", buf);
8767c478bd9Sstevel@tonic-gate 		if (EQUALSN(buf, "From ", 5)) {
8777c478bd9Sstevel@tonic-gate 			type = D_MAIL;
8787c478bd9Sstevel@tonic-gate 			break;
8797c478bd9Sstevel@tonic-gate 		}
8807c478bd9Sstevel@tonic-gate 		if (EQUALSN(buf, "U ", 2)) {
8817c478bd9Sstevel@tonic-gate 			type = D_XFILE;
8827c478bd9Sstevel@tonic-gate 			break;
8837c478bd9Sstevel@tonic-gate 		}
8847c478bd9Sstevel@tonic-gate 		if (EQUALSN(buf, "Newsgroups: ", 12)) {
8857c478bd9Sstevel@tonic-gate 			type = D_NEWS;
8867c478bd9Sstevel@tonic-gate 			break;
8877c478bd9Sstevel@tonic-gate 		}
8887c478bd9Sstevel@tonic-gate 	}
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
8917c478bd9Sstevel@tonic-gate 	return(type);
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate /*
8957c478bd9Sstevel@tonic-gate  * sendMail - send mail file and message to user (local or remote)
8967c478bd9Sstevel@tonic-gate  * return:
8977c478bd9Sstevel@tonic-gate  *	the return from the pclose - mail exit status
8987c478bd9Sstevel@tonic-gate  */
8997c478bd9Sstevel@tonic-gate int
9007c478bd9Sstevel@tonic-gate sendMail(system, user, file, mtext)
9017c478bd9Sstevel@tonic-gate char *system, *user, *file;
9027c478bd9Sstevel@tonic-gate char *mtext[];
9037c478bd9Sstevel@tonic-gate {
904*462be471Sceastha 	FILE *fp, *fi;
9057c478bd9Sstevel@tonic-gate 	char cmd[BUFSIZ];
9067c478bd9Sstevel@tonic-gate 	char *p;
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate 	DEBUG(5, "Mail %s to ", file);
9097c478bd9Sstevel@tonic-gate 	DEBUG(5, "%s\n", user);
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	/* get rid of some stuff that could be dangerous */
9127c478bd9Sstevel@tonic-gate 	if (system != NULL && (p = strpbrk(system, Shchar)) != NULL) {
9137c478bd9Sstevel@tonic-gate 		*p = NULLCHAR;
9147c478bd9Sstevel@tonic-gate 	}
9157c478bd9Sstevel@tonic-gate 	if (user != NULL && (p = strpbrk(user, Shchar)) != NULL) {
9167c478bd9Sstevel@tonic-gate 		*p = NULLCHAR;
9177c478bd9Sstevel@tonic-gate 	}
9187c478bd9Sstevel@tonic-gate 	if (system != NULL && *system != '\0')
9197c478bd9Sstevel@tonic-gate 		(void) sprintf(cmd, "%s %s '%s!%s'", PATH, MAIL, system, user);
9207c478bd9Sstevel@tonic-gate 	else
9217c478bd9Sstevel@tonic-gate 		(void) sprintf(cmd, "%s %s '%s'", PATH, MAIL, user);
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 	DEBUG(7, "sendMail: %s\n", cmd);
9247c478bd9Sstevel@tonic-gate 	if ((fp = popen(cmd, "w")) == NULL)
9257c478bd9Sstevel@tonic-gate 		return(-errno);
9267c478bd9Sstevel@tonic-gate 	while (*mtext[0] )
9277c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, *mtext++, Rmtname);
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, "\n\tSincerely,\n\t%s!uucp\n", Myname);
9307c478bd9Sstevel@tonic-gate 	(void) fprintf(fp,
9317c478bd9Sstevel@tonic-gate 		"\n#############################################\n");
9327c478bd9Sstevel@tonic-gate 
9337c478bd9Sstevel@tonic-gate 	if (*file) {
9347c478bd9Sstevel@tonic-gate 	/*next statement should never happen;I read once */
9357c478bd9Sstevel@tonic-gate 		if ((fi= fopen(file, "r")) == NULL)
9367c478bd9Sstevel@tonic-gate 			return(pclose(fp));
9377c478bd9Sstevel@tonic-gate 		(void) fprintf(fp,
9387c478bd9Sstevel@tonic-gate 			"##### Data File: ############################\n");
9397c478bd9Sstevel@tonic-gate 		xfappend(fi, fp);
9407c478bd9Sstevel@tonic-gate 		(void) fclose(fi);
9417c478bd9Sstevel@tonic-gate 	}
9427c478bd9Sstevel@tonic-gate 	return(pclose(fp));
9437c478bd9Sstevel@tonic-gate }
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate /*
9467c478bd9Sstevel@tonic-gate  * execRnews - execute rnews command with stdin file
9477c478bd9Sstevel@tonic-gate  * return:
9487c478bd9Sstevel@tonic-gate  *	the return from the pclose - rnews exit status
9497c478bd9Sstevel@tonic-gate  */
9507c478bd9Sstevel@tonic-gate int
9517c478bd9Sstevel@tonic-gate execRnews(file)
9527c478bd9Sstevel@tonic-gate char *file;
9537c478bd9Sstevel@tonic-gate {
954*462be471Sceastha 	FILE *fp, *fi;
9557c478bd9Sstevel@tonic-gate 	char cmd[BUFSIZ];
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate 	DEBUG(5, "Rnews %s\n", file);
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd, "%s rnews ", PATH);
9607c478bd9Sstevel@tonic-gate 	if ((fp = popen(cmd, "w")) == NULL)
9617c478bd9Sstevel@tonic-gate 		return(-errno);
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	if ( (fi = fopen(file, "r")) == NULL) /* never happen - I read once */
9647c478bd9Sstevel@tonic-gate 		return(pclose(fp));
9657c478bd9Sstevel@tonic-gate 	xfappend(fi, fp);
9667c478bd9Sstevel@tonic-gate 	(void) fclose(fi);
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 	return(pclose(fp));
9697c478bd9Sstevel@tonic-gate }
9707c478bd9Sstevel@tonic-gate 
9717c478bd9Sstevel@tonic-gate /*
9727c478bd9Sstevel@tonic-gate  * toWho - figure out who to send this dead mail to
9737c478bd9Sstevel@tonic-gate  *	It is a guess;
9747c478bd9Sstevel@tonic-gate  *	If there is a local address, send it there.
9757c478bd9Sstevel@tonic-gate  *	If not, send it back where it came from.
9767c478bd9Sstevel@tonic-gate  * return:
9777c478bd9Sstevel@tonic-gate  *	0 - could not find system and user information
9787c478bd9Sstevel@tonic-gate  *	1 - found it
9797c478bd9Sstevel@tonic-gate  */
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate int
9827c478bd9Sstevel@tonic-gate toWho(file, user, system)
9837c478bd9Sstevel@tonic-gate char *file;	/* the D. mail message file */
9847c478bd9Sstevel@tonic-gate char **system;	/* pointer to the system name */
9857c478bd9Sstevel@tonic-gate char **user;	/* pointer to the user name */
9867c478bd9Sstevel@tonic-gate {
9877c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
9887c478bd9Sstevel@tonic-gate 	FILE *fp;
9897c478bd9Sstevel@tonic-gate 	int i;
9907c478bd9Sstevel@tonic-gate 	static char fuser[BUFSIZ], fsystem[MAXBASENAME+1];  /* from first From */
9917c478bd9Sstevel@tonic-gate 	static char luser[BUFSIZ], lsystem[MAXBASENAME+1];  /* from other From */
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate 	*fuser = NULLCHAR;
9947c478bd9Sstevel@tonic-gate 	DEBUG(5, "toWho(%s)\n", file);
9957c478bd9Sstevel@tonic-gate 	fp = fopen(file, "r");
9967c478bd9Sstevel@tonic-gate 	for (i=0; i<NLINES; i++) {
9977c478bd9Sstevel@tonic-gate 		if (fgets(buf, BUFSIZ, fp) == NULL)
9987c478bd9Sstevel@tonic-gate 			break;	/* no more lines */
9997c478bd9Sstevel@tonic-gate 		DEBUG(9, "buf: %s\n", buf);
10007c478bd9Sstevel@tonic-gate 		if (!analFrom(buf, luser, lsystem))
10017c478bd9Sstevel@tonic-gate 			continue;
10027c478bd9Sstevel@tonic-gate 		if ( !*fuser) {
10037c478bd9Sstevel@tonic-gate 			(void) strcpy(fuser, luser);
10047c478bd9Sstevel@tonic-gate 			(void) strcpy(fsystem, lsystem);
10057c478bd9Sstevel@tonic-gate 		}
10067c478bd9Sstevel@tonic-gate 		if (EQUALS(Myname, lsystem)) {
10077c478bd9Sstevel@tonic-gate 			*user = luser;
10087c478bd9Sstevel@tonic-gate 			*system = lsystem;
10097c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
10107c478bd9Sstevel@tonic-gate 			return(1);
10117c478bd9Sstevel@tonic-gate 		}
10127c478bd9Sstevel@tonic-gate 	}
10137c478bd9Sstevel@tonic-gate 
10147c478bd9Sstevel@tonic-gate 	/* could not find local user - use first line */
10157c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
10167c478bd9Sstevel@tonic-gate 	if (!*fuser)	/* didn't find all information */
10177c478bd9Sstevel@tonic-gate 		return(0);
10187c478bd9Sstevel@tonic-gate 	*user = fuser;
10197c478bd9Sstevel@tonic-gate 	*system = fsystem;
10207c478bd9Sstevel@tonic-gate 	return(1);
10217c478bd9Sstevel@tonic-gate }
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate /* analFrom - analyze From line
10247c478bd9Sstevel@tonic-gate  * return:
10257c478bd9Sstevel@tonic-gate  *	0 - didn't find both from and remote from info
10267c478bd9Sstevel@tonic-gate  *	1 - found info.
10277c478bd9Sstevel@tonic-gate  */
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate int
10307c478bd9Sstevel@tonic-gate analFrom(line, user, system)
10317c478bd9Sstevel@tonic-gate char *line, *user, *system;
10327c478bd9Sstevel@tonic-gate {
10337c478bd9Sstevel@tonic-gate 	char *s;
10347c478bd9Sstevel@tonic-gate 	int i;
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 	if (!PREFIX("From ", line) && !PREFIX(">From ", line))
10377c478bd9Sstevel@tonic-gate 		return(0);
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate 	s = strchr(line, ' ') + 1;
10407c478bd9Sstevel@tonic-gate 	for (i = 0;  *s && *s != ' ' && *s != '\n'; i++)
10417c478bd9Sstevel@tonic-gate 		user[i] = *s++;
10427c478bd9Sstevel@tonic-gate 	user[i] = NULLCHAR;
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate 	/* look for "remote from" */
10457c478bd9Sstevel@tonic-gate 	while (*s && ((s = strchr(s, ' ')) != NULL)) {
10467c478bd9Sstevel@tonic-gate 		s++;
10477c478bd9Sstevel@tonic-gate 		if (PREFIX("remote from ", s)) {	/* found it */
10487c478bd9Sstevel@tonic-gate 			s = s + strlen("remote from ");
10497c478bd9Sstevel@tonic-gate 			for (i = 0; (i<MAXBASENAME) && *s && *s != ' ' && *s != '\n'; i++)
10507c478bd9Sstevel@tonic-gate 				system[i] = *s++;
10517c478bd9Sstevel@tonic-gate 			system[i] = NULLCHAR;
10527c478bd9Sstevel@tonic-gate 			return(1);
10537c478bd9Sstevel@tonic-gate 		}
10547c478bd9Sstevel@tonic-gate 	}
10557c478bd9Sstevel@tonic-gate 	return(0);
10567c478bd9Sstevel@tonic-gate }
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate static FILE	*_Lf = NULL;
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate /*
10637c478bd9Sstevel@tonic-gate  * Make log entry
10647c478bd9Sstevel@tonic-gate  *	text	-> ptr to text string
10657c478bd9Sstevel@tonic-gate  *	status	errno number
10667c478bd9Sstevel@tonic-gate  * Returns:
10677c478bd9Sstevel@tonic-gate  *	none
10687c478bd9Sstevel@tonic-gate  */
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate void
10717c478bd9Sstevel@tonic-gate logit(text, status)
1072*462be471Sceastha char	*text;
10737c478bd9Sstevel@tonic-gate int status;
10747c478bd9Sstevel@tonic-gate {
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	if (Nstat.t_pid == 0)
10777c478bd9Sstevel@tonic-gate 		Nstat.t_pid = getpid();
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 	if (_Lf == NULL) {
10807c478bd9Sstevel@tonic-gate 		_Lf = fopen(Logfile, "a");
10817c478bd9Sstevel@tonic-gate 		(void) chmod(Logfile, LOGFILEMODE);
10827c478bd9Sstevel@tonic-gate 		if (_Lf == NULL)
10837c478bd9Sstevel@tonic-gate 			return;
10847c478bd9Sstevel@tonic-gate 		setbuf(_Lf, CNULL);
10857c478bd9Sstevel@tonic-gate 	}
10867c478bd9Sstevel@tonic-gate 	(void) fseek(_Lf, 0L, 2);
10877c478bd9Sstevel@tonic-gate 	(void) fprintf(_Lf, "%s ", Rmtname);
10887c478bd9Sstevel@tonic-gate 	(void) fprintf(_Lf, "(%s,%ld,%d) ", timeStamp(), (long) Nstat.t_pid, Seqn);
10897c478bd9Sstevel@tonic-gate 	(void) fprintf(_Lf, "%s (%d)\n", text, status);
10907c478bd9Sstevel@tonic-gate 	return;
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate 
1093*462be471Sceastha static void
1094*462be471Sceastha cleanworkspace(void)
10957c478bd9Sstevel@tonic-gate {
10967c478bd9Sstevel@tonic-gate 	DIR	*spooldir;
10977c478bd9Sstevel@tonic-gate 	char f[MAXFULLNAME];
10987c478bd9Sstevel@tonic-gate 
10997c478bd9Sstevel@tonic-gate 	if (chdir(WORKSPACE) != 0) {
11007c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T CHDIR (%s): errno (%d)\n", WORKSPACE, errno);
11017c478bd9Sstevel@tonic-gate 		return;
11027c478bd9Sstevel@tonic-gate 	}
11037c478bd9Sstevel@tonic-gate 	if ((spooldir = opendir(WORKSPACE)) == NULL) {
11047c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n", WORKSPACE, errno);
11057c478bd9Sstevel@tonic-gate 		return;
11067c478bd9Sstevel@tonic-gate 	}
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate 	while (gnamef(spooldir, f) == TRUE)
11097c478bd9Sstevel@tonic-gate 		if (_age(f) >= 1)
11107c478bd9Sstevel@tonic-gate 			if (unlink(f) != 0)
11117c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "CAN'T UNLINK (%s): errno (%d)\n", f, errno);
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate }
1114