xref: /titanic_51/usr/src/cmd/mail/init.c (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33  /*
34   * All global externs defined in mail.h. All variables are initialized
35   * here!
36   *
37   * !!!!!IF YOU CHANGE (OR ADD) IT HERE, DO IT THERE ALSO !!!!!!!!
38   *
39   */
40 #include	"mail.h"
41 
42 int		ac;		/* argument list count */
43 char		**av;		/* argument list */
44 int		affbytecnt;     /* Total bytes of Auto-Fwd. info in msg. */
45 int		affcnt;		/* Number of Auto-Fwd.-From: lines in msg. */
46 int		Daffbytecnt;    /* Hold affbytecnt when sending Delivery Notification */
47 int		Daffcnt;	/* Hold affcnt when sending Delivery Notification */
48 char		binmsg[] = "*** Message content is not printable: delete, write or save it to a file ***";
49 int		changed;	/* > 0 says mailfile has changed */
50 char		datestring[60];	/* Today's date and time */
51 char		dbgfname[20];
52 FILE		*dbgfp;
53 char		dead[] = "/dead.letter";	/* name of dead.letter */
54 int		debug;	/* Controls debugging level. 0 ==> no debugging */
55 int		delflg = 1;
56 int		dflag = 0;	/* 1 says returning unsendable mail */
57 char		*errlist[]= {
58 		"",
59 		"Unknown system",
60 		"Problem with mailfile",
61 		"Space problem",
62 		"Unable to forward mail, check permissions and group",
63 		"Syntax error",
64 		"Forwarding loop",
65 		"Invalid sender",
66 		"Invalid recipient",
67 		"Too many From lines",
68 		"Invalid permissions",
69 		"Cannot open mbox",
70 		"Temporary file problem",
71 		"Cannot create dead.letter",
72 		"Unbounded forwarding",
73 		"Cannot create lock file",
74 		"No group id of 'mail'",
75 		"Problem allocating memory",
76 		"Could not fork",
77 		"Cannot pipe",
78 		"Must be owner to modify mailfile",
79 		"Permission denied by /etc/mail/mailsurr file",
80 		"Surrogate command failed"
81 };
82 int		error = 0;	/* Local value for error */
83 char		*failsafe;	/* $FAILSAFE */
84 int		file_size;
85 int		flge = 0;	/* 1 ==> 'e' option specified */
86 int		flgE = 0;	/* 1 ==> 'E' option specified */
87 int		flgF = 0;	/* 1 ==> Installing/Removing  Forwarding */
88 int		flgf = 0;	/* 1 ==> 'f' option specified */
89 int		flgh = 0;	/* 1 ==> 'h' option specified */
90 int		flgm;
91 int		flgp = 0;	/* 1 ==> 'p' option specified */
92 int		flgP = 0;	/* 1 ==> 'P' option specified */
93 int		flgr = 0;	/* 1 ==> 'r' option -- print in fifo order */
94 int		flgt = 0;	/* 1 ==> 't' option -- add To: line to letter */
95 int		flgT = 0;	/* 1 ==> 'T' option specified */
96 int		flgw = 0;	/* 1 ==> 'w' option specified */
97 int		fnuhdrtype = 0;	/* type of first non-UNIX header line */
98 char		forwmsg[] = " forwarded by %s\n";
99 char		fromS[1024];	/* stored here by sendmail for sendsurg */
100 char		fromU[1024];	/* stored here by sendmail for sendsurg */
101 char		frwlmsg[] = "     %s: Forwarding loop detected in %s's mailfile.\n";
102 char		frwrd[] = "Forward to ";	/* forwarding sentinel */
103 char		fwdFrom[1024];
104 int		goerr = 0;	/* counts parsing errors */
105 struct group	*grpptr;	/* pointer to struct group */
106 struct hdrlines	hdrlines[H_CONT];
107 /* Default_display indicates whether to display this header line to the TTY */
108 /* when in default mode. Can be overridden via 'P' command at ? prompt */
109 struct hdr	header[] = {
110 		"",				FALSE,
111 		"Auto-Forward-Count:",		FALSE,
112 		"Auto-Forwarded-From:",		FALSE,
113 		"Content-Length:",		TRUE,
114 		"Content-Type:",		FALSE,
115 		"Date:",			TRUE,
116 		"Default-Options:",		FALSE,
117 		"End-of-Header:",		FALSE,
118 		"From ",			TRUE,
119 		">From ",			TRUE,
120 		"From:",			TRUE,
121 		"MIME-Version:",		FALSE,
122 		"MTS-Message-ID:",		FALSE,
123 		"Message-Type:",		FALSE,
124 		"Message-Version:",		FALSE,
125 		"Message-Service:",		TRUE,
126 		"Received:",			FALSE,
127 		"Report-Version:",		FALSE,
128 		"Subject:",			TRUE,
129 		"To:",				TRUE,
130 		">To:",				FALSE,
131 		"Transport-Options:",		FALSE,
132 		"UA-Content-ID:",		FALSE,
133 
134 		/*Dummy place holders for H_DAFWDFROM,*/
135 		/*H_DTCOPY and H_RECEIVED. Should */
136 		/* match above first...*/
137 		"Hold-Auto-Forwarded-From:",	FALSE,
138 		"Hold->To:",			FALSE,
139 		"Hold-Received:",		FALSE,
140 		"Continue:",			FALSE,
141 		"Name-Value:",			FALSE,
142 };
143 char		*help[] = {
144 		"?\t\tprint this help message\n",
145 		"#\t\tdisplay message number #\n",
146 		"-\t\tprint previous\n",
147 		"+\t\tnext (no delete)\n",
148 		"! cmd\t\texecute cmd\n",
149 		"<CR>\t\tnext (no delete)\n",
150 		"a\t\tposition at and read newly arrived mail\n",
151 		"d [#]\t\tdelete message # (default current message)\n",
152 		"dp\t\tdelete current message and print the next\n",
153 		"dq\t\tdelete current message and exit\n",
154 		"h a\t\tdisplay all headers\n",
155 		"h d\t\tdisplay headers of letters scheduled for deletion\n",
156 		"h [#]\t\tdisplay headers around # (default current message)\n",
157 		"m user  \tmail (and delete) current message to user\n",
158 		"n\t\tnext (no delete)\n",
159 		"p\t\tprint (override any warnings of binary content)\n",
160 		"P\t\toverride default 'brief' mode and display ALL header lines\n",
161 		"q, ^D\t\tquit\n",
162 		"r [args]\treply to (and delete) current letter via mail [args]\n",
163 		"s [files]\tsave (and delete) current message (default mbox)\n",
164 		"u [#]\t\tundelete message # (default current message)\n",
165 		"w [files]\tsave (and delete) current message without header\n",
166 		"x\t\texit without changing mail\n",
167 		"y [files]\tsave (and delete) current message (default mbox)\n",
168 		0
169 };
170 char		*hmbox;		/* pointer to $HOME/mbox */
171 char		*hmdead;	/* pointer to $HOME/dead.letter */
172 char		*home;		/* pointer to $HOME */
173 time_t		iop;
174 int		interactive = 0;	/* 1 says user is interactive */
175 int		ismail = TRUE;		/* default to program=mail */
176 int             deliverflag = FALSE;    /* -d flag, skip sendmail
177 					 * deliver directly to mailbox
178 					 */
179 int             fromflag = FALSE;   /* -f from_user, set a user
180 					 * when going into a mailbox
181 					 */
182 int		keepdbgfile;
183 struct let	let[MAXLET];
184 char		*lettmp;		/* pointer to tmp filename */
185 char		lfil[MAXFILENAME];
186 char		line[LSIZE];	/* holds a line of a letter in many places */
187 char		*mailfile;	/* pointer to mailfile */
188 char		mailcnfg[] = MAILCNFG;	/* configuration file */
189 char		maildir[] = MAILDIR;	/* directory for mail files */
190 gid_t		mailgrp;	/* numeric id of group 'mail' */
191 char		mailsave[] = SAVEDIR;	/* dir for save files */
192 char		*mailsurr = MAILSURR;	/* surrogate file name */
193 FILE		*malf;		/* File pointer for mailfile */
194 int		maxerr = 0;	/* largest value of error */
195 char		mbox[] = "/mbox";	/* name for mbox */
196 uid_t		mf_uid;		/* uid of users mailfile */
197 gid_t		mf_gid;		/* gid of users mailfile */
198 char		*msgtype;
199 char		my_name[1024];	/* user's name who invoked this command */
200 char		from_user[1024];	/* user's name specified w/ -f when sending */
201 uid_t		my_euid;	/* user's euid */
202 gid_t		my_egid;	/* user's egid */
203 uid_t		my_uid;		/* user's uid */
204 gid_t		my_gid;		/* user's gid */
205 int		nlet	= 0;	/* current number of letters in mailfile */
206 int		onlet	= 0;	/* number of letters in mailfile at startup*/
207 int		optcnt = 0;	/* Number of options specified */
208 int		orig_aff = 0;	/* orig. msg. contained H_AFWDFROM lines */
209 int		orig_dbglvl;	/* argument to -x invocation option */
210 int		orig_rcv = 0;	/* orig. msg. contained H_RECEIVED lines */
211 int		orig_tcopy = 0;	/* orig. msg. contained H_TCOPY lines */
212 struct passwd	*pwd;		/* holds passwd entry for this user */
213 int		pflg = 0;	/* binary message display override flag */
214 int		Pflg = 0;	/* Selective display flag; 1 ==> display all */
215 char		*program;	/* program name */
216 int		rcvbytecnt;     /* Total bytes of Received: info in msg. */
217 int		Drcvbytecnt;    /* Hold rcvbytecnt when sending Delivery Notification */
218 char		*recipname;		/* full recipient name/address */
219 int		replying = 0;	/* 1 says we are replying to a letter */
220 char		RFC822datestring[60];/* Date in RFC822 date format */
221 char		Rpath[1024];	/* return path to sender of message */
222 char		rmtmsg[] =	" remote from %s\n";
223 char		rtrnmsg[] =	"***** UNDELIVERABLE MAIL sent to %s, being returned by %s *****\n";
224 int		sav_errno;
225 char		savefile[MAXFILENAME];	/* holds filename of save file */
226 void		(*saveint)();
227 /* Any header line prefixes listed here WILL be displayed in default mode */
228 /* If it's not here, it won't be shown. Can be overridden via 'P' command */
229 /* at ? prompt */
230 char		*seldisp[] = {
231 		"Cc:",
232 		"Bcc:",
233 		"Paper-",
234 		"Phone:",
235 		"Message-",
236 		"Original-",
237 		"Confirming-",
238 		"Delivered-",
239 		"Deliverable-",
240 		"Not-",
241 		"En-Route-To:",
242 		0
243 };
244 int		sending;	/* TRUE==>sending mail; FALSE==>printing mail */
245 char		m_sendto[1024];
246 jmp_buf		sjbuf;
247 int		surg_rc = 0;	/* exit code of surrogate command */
248 int		surr_len = 0;
249 char		*SURRcmdstr = (char *)NULL; /* save in case of FAILURE */
250 FILE		*SURRerrfile;	/* stderr from surrogate in case of FAILURE */
251 char		*thissys;	/* Holds name of the system we are on */
252 FILE		*tmpf;		/* file pointer for temporary files */
253 mode_t		umsave;
254 struct		utsname utsn;
255 static struct utimbuf	utims;
256 struct utimbuf	*utimep = &utims;
257 char		uval[1024];
258 
259 int init()
260 {
261 	utims.actime = utims.modtime = -1;
262 	return (xsetenv(mailcnfg));
263 }
264