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