xref: /csrg-svn/usr.bin/uucp/sdmail.c (revision 13667)
1*13667Ssam #ifndef lint
2*13667Ssam static char sccsid[] = "@(#)sdmail.c	5.1 (Berkeley) 07/02/83";
3*13667Ssam #endif
4*13667Ssam 
5*13667Ssam #include "uucp.h"
6*13667Ssam #include <pwd.h>
7*13667Ssam 
8*13667Ssam /*******
9*13667Ssam  *	sdmail(file, uid)
10*13667Ssam  *
11*13667Ssam  *	sdmail  -  this routine will determine the owner
12*13667Ssam  *	of the file (file), create a message string and
13*13667Ssam  *	call "mailst" to send the cleanup message.
14*13667Ssam  *	This is only implemented for local system
15*13667Ssam  *	mail at this time.
16*13667Ssam  */
17*13667Ssam 
18*13667Ssam sdmail(file, uid)
19*13667Ssam char *file;
20*13667Ssam register int uid;
21*13667Ssam {
22*13667Ssam 	static struct passwd *pwd = NULL;
23*13667Ssam 	struct passwd *getpwuid();
24*13667Ssam 	char mstr[40];
25*13667Ssam 
26*13667Ssam 	sprintf(mstr, "uuclean deleted file %s\n", file);
27*13667Ssam 	if (pwd != NULL && pwd->pw_uid == uid) {
28*13667Ssam 		mailst(pwd->pw_name, mstr);
29*13667Ssam 		return(0);
30*13667Ssam 	}
31*13667Ssam 
32*13667Ssam 	if ((pwd = getpwuid(uid)) != NULL) {
33*13667Ssam 		mailst(pwd->pw_name, mstr);
34*13667Ssam 	}
35*13667Ssam 	return(0);
36*13667Ssam }
37*13667Ssam 
38*13667Ssam 
39*13667Ssam /***
40*13667Ssam  *	mailst(user, str)
41*13667Ssam  *	char *user, *str;
42*13667Ssam  *
43*13667Ssam  *	mailst  -  this routine will fork and execute
44*13667Ssam  *	a mail command sending string (str) to user (user).
45*13667Ssam  */
46*13667Ssam 
47*13667Ssam mailst(user, str)
48*13667Ssam char *user, *str;
49*13667Ssam {
50*13667Ssam 	register FILE *fp;
51*13667Ssam 	extern FILE *popen(), *pclose();
52*13667Ssam 	char cmd[100];
53*13667Ssam 
54*13667Ssam 	sprintf(cmd, "mail %s", user);
55*13667Ssam 	if ((fp = popen(cmd, "w")) == NULL)
56*13667Ssam 		return;
57*13667Ssam /* \n added to mail message.  uw-beave!jim (Jim Rees) */
58*13667Ssam 	fprintf(fp, "%s\n", str);
59*13667Ssam 	pclose(fp);
60*13667Ssam 	return;
61*13667Ssam }
62