1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23*0Sstevel@tonic-gate /* All Rights Reserved */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate #include "mail.h"
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate Routine creates dead.letter
31*0Sstevel@tonic-gate */
mkdead()32*0Sstevel@tonic-gate void mkdead()
33*0Sstevel@tonic-gate {
34*0Sstevel@tonic-gate static char pn[] = "mkdead";
35*0Sstevel@tonic-gate int aret;
36*0Sstevel@tonic-gate char *dotdead = &dead[1];
37*0Sstevel@tonic-gate gid_t egid = getegid();
38*0Sstevel@tonic-gate struct stat st;
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate malf = (FILE *)NULL;
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate Make certain that there's something to copy.
44*0Sstevel@tonic-gate */
45*0Sstevel@tonic-gate if (!tmpf)
46*0Sstevel@tonic-gate return;
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate /*
49*0Sstevel@tonic-gate Try to create dead letter in current directory
50*0Sstevel@tonic-gate or in home directory
51*0Sstevel@tonic-gate */
52*0Sstevel@tonic-gate umask(umsave);
53*0Sstevel@tonic-gate setgid(getgid());
54*0Sstevel@tonic-gate if ((aret = legal(dotdead)) && stat(dotdead, &st) == 0)
55*0Sstevel@tonic-gate malf = fopen(dotdead, "a");
56*0Sstevel@tonic-gate if ((malf == NULL) || (aret == 0)) {
57*0Sstevel@tonic-gate /*
58*0Sstevel@tonic-gate try to create in $HOME
59*0Sstevel@tonic-gate */
60*0Sstevel@tonic-gate if((hmdead = malloc(strlen(home) + strlen(dead) + 1)) == NULL) {
61*0Sstevel@tonic-gate fprintf(stderr, "%s: Can't malloc\n",program);
62*0Sstevel@tonic-gate Dout(pn, 0, "Cannot malloc.\n");
63*0Sstevel@tonic-gate goto out;
64*0Sstevel@tonic-gate }
65*0Sstevel@tonic-gate cat(hmdead, home, dead);
66*0Sstevel@tonic-gate if ((aret=legal(hmdead)) && !(stat(hmdead, &st) < 0 &&
67*0Sstevel@tonic-gate errno == EOVERFLOW))
68*0Sstevel@tonic-gate malf = fopen(hmdead, "a");
69*0Sstevel@tonic-gate if ((malf == NULL) || (aret == 0)) {
70*0Sstevel@tonic-gate fprintf(stderr,
71*0Sstevel@tonic-gate "%s: Cannot create %s\n",
72*0Sstevel@tonic-gate program,dotdead);
73*0Sstevel@tonic-gate Dout(pn, 0, "Cannot create %s\n", dotdead);
74*0Sstevel@tonic-gate out:
75*0Sstevel@tonic-gate fclose(tmpf);
76*0Sstevel@tonic-gate error = E_FILE;
77*0Sstevel@tonic-gate Dout(pn, 0, "error set to %d\n", error);
78*0Sstevel@tonic-gate umask(7);
79*0Sstevel@tonic-gate setegid(egid);
80*0Sstevel@tonic-gate return;
81*0Sstevel@tonic-gate } else {
82*0Sstevel@tonic-gate chmod(hmdead, DEADPERM);
83*0Sstevel@tonic-gate fprintf(stderr,"%s: Mail saved in %s\n",program,hmdead);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate } else {
86*0Sstevel@tonic-gate chmod(dotdead, DEADPERM);
87*0Sstevel@tonic-gate fprintf(stderr,"%s: Mail saved in %s\n",program,dotdead);
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate Copy letter into dead letter box
92*0Sstevel@tonic-gate */
93*0Sstevel@tonic-gate umask(7);
94*0Sstevel@tonic-gate aret = fseek(tmpf,0L,0);
95*0Sstevel@tonic-gate if (aret)
96*0Sstevel@tonic-gate errmsg(E_DEAD,"");
97*0Sstevel@tonic-gate if (!copystream(tmpf, malf))
98*0Sstevel@tonic-gate errmsg(E_DEAD,"");
99*0Sstevel@tonic-gate fclose(malf);
100*0Sstevel@tonic-gate setegid(egid);
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate
savdead()103*0Sstevel@tonic-gate void savdead()
104*0Sstevel@tonic-gate {
105*0Sstevel@tonic-gate static char pn[] = "savdead";
106*0Sstevel@tonic-gate setsig(SIGINT, saveint);
107*0Sstevel@tonic-gate dflag = 2; /* do not send back letter on interrupt */
108*0Sstevel@tonic-gate Dout(pn, 0, "dflag set to 2\n");
109*0Sstevel@tonic-gate if (!error) {
110*0Sstevel@tonic-gate error = E_REMOTE;
111*0Sstevel@tonic-gate Dout(pn, 0, "error set to %d\n", error);
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate maxerr = error;
114*0Sstevel@tonic-gate Dout(pn, 0, "maxerr set to %d\n", maxerr);
115*0Sstevel@tonic-gate }
116