xref: /titanic_50/usr/src/cmd/mail/mail.h (revision d0698e0d179f97729cacdbc2f13446a6b0a3f22a)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 #ifndef _MAIL_H
30 #define	_MAIL_H
31 
32  /*
33   * All global externs defined here. All variables are initialized
34   * in init.c
35   *
36   * !!!!!IF YOU CHANGE (OR ADD) IT HERE, DO IT THERE ALSO !!!!!!!!
37   *
38   */
39 #include	<errno.h>
40 #include	<fcntl.h>
41 #include	<stdio.h>
42 #include	<ctype.h>
43 #include	<sys/types.h>
44 #include	<errno.h>
45 #include	<pwd.h>
46 #include	<signal.h>
47 #include	<string.h>
48 #include	<grp.h>
49 /* The following is a kludge to allow for inconsistent header files in SVR4 */
50 #define		_CLOCK_T
51 #include	<time.h>
52 #include	<sys/stat.h>
53 #include	<setjmp.h>
54 #include	<sys/utsname.h>
55 #include        <limits.h>
56 
57 #ifdef SVR3
58    struct utimbuf {
59 	time_t	actime;
60 	time_t	modtime;
61    };
62 #else
63 #  include	<utime.h>
64 #endif
65 #include	"libmail.h"
66 
67 /* The following typedefs must be used in SVR4 */
68 #ifdef SVR3
69 # ifndef sun
70 typedef int gid_t;
71 typedef int uid_t;
72 # endif
73 typedef int pid_t;
74 #endif
75 
76 #define CHILD		0
77 #define SAME		0
78 
79 #define	BELL		07
80 
81 #   define	PIPER	"/usr/lib/mail/mail_pipe"
82 
83 #define SENDMAIL "/usr/lib/sendmail"
84 
85 #define CERROR		-1
86 #define CSUCCESS	0
87 
88 #define TRUE	1
89 #define FALSE	0
90 
91 #define	HEAD	1
92 #define TAIL	0
93 
94 #define	REAL	1
95 #define DEFAULT	0
96 
97 /* findSurg() return values */
98 #define	NOMATCH		-1
99 #define	DELIVER		0
100 #define	POSTDELIVER	1
101 #define	DENY		2
102 #define	TRANSLATE	3
103 
104 /* sendsurg() return values */
105 #define	FAILURE		0
106 #define	CONTINUE	1
107 #define	SUCCESS		2
108 /*	TRANSLATE	3 */
109 
110 #define	HDRSIZ	1024	/* maximum length of header line */
111 
112 #define E_FLGE	1	/* flge error */
113 #define E_FLGE_OM 2	/* flgE error, mail present but already accessed */
114 #define	E_REMOTE 1	/* unknown remote */
115 #define E_FILE	2	/* file error */
116 #define E_SPACE	3	/* no space */
117 #define E_FRWD	4	/* cannot forward */
118 #define E_SYNTAX 5      /* syntax error */
119 #define E_FRWL	6	/* forwarding loop */
120 #define E_SNDR  7	/* invalid sender */
121 #define E_USER  8	/* invalid user */
122 #define E_FROM  9	/* too many From lines */
123 #define E_PERM  10 	/* bad permissions */
124 #define E_MBOX  11 	/* mbox problem */
125 #define E_TMP	12 	/* temporary file problem */
126 #define E_DEAD  13 	/* Cannot create dead.letter */
127 #define E_UNBND 14 	/* Unbounded forwarding */
128 #define E_LOCK  15 	/* cannot create lock file */
129 #define E_GROUP	16	/* no group id of 'mail' */
130 #define	E_MEM	17	/* malloc failure */
131 #define E_FORK	18	/* could not fork */
132 #define	E_PIPE	19	/* could not pipe */
133 #define	E_OWNR	20	/* invoker does not own mailfile */
134 #define	E_DENY	21	/* permission denied by mailsurr file */
135 #define E_SURG	22	/* surrogate command failed - rc != 0 || 99 */
136 
137 #define	H_AFWDCNT		1	/* "Auto-Forward-Count:"  */
138 #define	H_AFWDFROM		2	/* "Auto-Forwarded-From:" */
139 #define	H_CLEN			3	/* "Content-Length:"      */
140 #define	H_CTYPE			4	/* "Content-Type:"        */
141 #define	H_DATE			5	/* "Date:" 		  */
142 #define	H_DEFOPTS		6	/* "Default-Options:" 	  */
143 #define	H_EOH			7	/* "End-of-Header:" 	  */
144 #define	H_FROM			8	/* "From " 		  */
145 #define	H_FROM1			9	/* ">From " 		  */
146 #define	H_FROM2			10	/* "From: " 		  */
147 #define	H_MIMEVERS		11	/* "MIME-Version:"        */
148 #define	H_MTSID			12	/* "MTS-Message-ID:" 	  */
149 #define	H_MTYPE			13	/* "Message-Type:" 	  */
150 #define	H_MVERS			14	/* "Message-Version:" 	  */
151 #define	H_MSVC			15	/* "Message-Service:" 	  */
152 #define	H_RECEIVED		16	/* "Received:"	 	  */
153 #define	H_RVERS			17	/* "Report-Version:" 	  */
154 #define	H_SUBJ			18	/* "Subject:" 		  */
155 #define	H_TO			19	/* "To:" 		  */
156 #define	H_TCOPY			20	/* ">To:" 		  */
157 #define	H_TROPTS		21	/* "Transport-Options:"   */
158 #define	H_UAID			22	/* "UA-Content-ID:"	  */
159 #define	H_DAFWDFROM		23	/* Hold A-F-F when sending Del. Notf. */
160 #define	H_DTCOPY		24	/* Hold ">To:" when sending Del. Notf.*/
161 #define	H_DRECEIVED		25	/* Hold Rcvd: when sending Del. Notf.*/
162 #define	H_CONT			26	/* Continuation of previous line */
163 #define	H_NAMEVALUE		27	/* unrecognized "name: value" hdr line*/
164 
165 /* MTA Transport Options */
166 #define	DELIVERY	001
167 #define	NODELIVERY	002
168 #define	REPORT		010
169 #define	RETURN		020
170 #define	IGNORE		040
171 
172 /*
173 	copylet flags
174 */
175 #define	REMOTE		1		/* remote mail, add rmtmsg */
176 #define ORDINARY	2
177 #define ZAP		3		/* zap header and trailing empty line */
178 #define FORWARD		4
179 #define TTY		5		/* suppress binary to tty */
180 
181 #define	LSIZE		(2*BUFSIZ)	/* maximum size of a line */
182 #define	MAXLET		1000		/* maximum number of letters */
183 #define FROMLEVELS	20		/* maxium number of forwards */
184 #ifdef FILENAME_MAX
185 # define MAXFILENAME	FILENAME_MAX	/* max length of a filename */
186 #else
187 # define MAXFILENAME	512		/* max length of a filename */
188 #endif
189 #define DEADPERM	0600		/* permissions of dead.letter */
190 
191 #ifndef	MFMODE
192 #define	MFMODE		0660		/* create mode for `/var/mail' files */
193 #endif
194 
195 #define A_OK		0		/* return value for access */
196 #define A_EXECUTE	1
197 #define A_EXIST		0		/* access check for existence */
198 #define A_WRITE		2		/* access check for write permission */
199 #define A_READ		4		/* access check for read permission */
200 
201 #  define MAILSURR "/etc/mail/mailsurr"
202 #  define MAILCNFG "/etc/mail/mailcnfg"
203 
204 struct hdr {
205 	char	*tag;
206 	int	default_display;
207 };
208 
209 struct hdrs {
210 	struct	hdrs	*next;
211 	struct	hdrs	*prev;
212 	struct	hdrs	*cont;	/* Continuation lines */
213 		char	value[HDRSIZ+1];
214 };
215 
216 struct hdrlines {
217 	struct	hdrs	*head;
218 	struct	hdrs	*tail;
219 };
220 
221 typedef struct recip {
222 	struct recip	*next;
223 	char		*name;
224 } recip;
225 
226 typedef struct reciplist {
227 	recip *last_recip;
228 	recip recip_list;
229 } reciplist;
230 
231 struct let {
232 	long	adr;		/* offset in mailfile of letter n */
233 	char	change;		/* disposition status of letter n */
234 	char	text;		/* 1 ==> text content, 0 ==> binary content.
235 				 * This is determined INDEPENDENTLY of what
236 				 * the Content-type, if present, says...
237 				 */
238 };
239 
240 typedef enum t_surrtype
241 {
242     t_eof, t_transport = '<',
243     t_accept = 'a', t_deny = 'd',
244     t_translate = 't', t_postprocess = '>'
245 } t_surrtype;
246 
247 typedef struct t_surrfile
248 {
249     /* originator's regular expression */
250     string *orig_pattern;
251     char *orig_regex;
252     int orig_reglen;
253     int orig_nbra;
254 
255     /* recipient's regular expression */
256     string *recip_pattern;
257     char *recip_regex;
258     int recip_reglen;
259     int recip_nbra;
260 
261     /* the type of the command string */
262     t_surrtype surr_type;
263 
264     int batchsize;	/* transport	translate	postprocess */
265     char *statlist;	/* transport				    */
266     string *cmd_left;	/* transport	translate	postprocess */
267     string *cmd_right;	/* transport	translate	postprocess */
268     int fullyresolved;	/*		translate		    */
269 } t_surrfile;
270 
271 #include <stdlib.h>
272 #include <unistd.h>
273 
274 extern	void	Dout(char *subname, int level, char *fmt, ...);
275 extern	void	Tout(char *subname, char *msg, ...);
276 extern	int	add_recip(reciplist *plist, char *name, int checkdups);
277 extern	char	*altcompile(const char *instring, char *expbuf, char *endbuf);
278 extern	int	areforwarding(char *mailfile);
279 extern	void	cat(char*, char*, char*);
280 extern	int	ckdlivopts(int tcopy_hdr, int *svopts);
281 extern	void	cksaved(char *user);
282 extern	int	cksurg_rc(int surr_num, int rc);
283 extern	void	clr_hinfo(void);
284 extern	void	clrhdr(int hdrtype);
285 extern	void	cmdexpand(int letnum, string *instr, string *outstr, char **lbraslist, char **lbraelist);
286 extern	void	copyback(void);
287 extern	int	copylet(int letnum, FILE *f, int type);
288 extern	void	copymt(FILE *f1, FILE *f2);
289 extern	void	createmf(uid_t uid, char *file);
290 extern	void	del_reciplist (reciplist *list);
291 extern	void	delete(int);
292 extern	void	doFopt(void);
293 extern	void	done(int) __NORETURN;
294 extern	void	sig_done(int);
295 extern	FILE	*doopen(char *file, char *type, int errnum);
296 extern	int	dowait(pid_t pidval);
297 extern	void	dumpaff(int type, int htype, int *didafflines, int *suppress, FILE *f);
298 extern	void	dumprcv(int type, int htype, int *didrcvlines, int *suppress, FILE *f);
299 extern	void	errmsg(int error_value, char *error_message);
300 extern	int	findSurg(int letnum, string *execbuf, int flag, int *psurr_num, int *paccept, string *lorig, string *lrecipname);
301 extern	void	gendeliv(FILE *fp, int rc, char *name);
302 extern	int	getcomment(char *s, char *q);
303 extern	int	gethead(int	current, int all);
304 extern	int	getaline(char *ptr2line, int max, FILE *f);
305 extern	int	getnumbr(char *s);
306 extern	int	getsurr(FILE *fp, string *buf, int firstfield);
307 extern	void	goback(int letnum);
308 extern	int	init(void);
309 extern	void	initsurrfile(void);
310 extern	int	isheader(char *lp, int *ctfp);
311 extern	int	isit(char *lp, int type);
312 extern	int	islocal(char *user, uid_t *puid);
313 extern	int	istext(unsigned char *s, int size);
314 extern	int	legal(char *file);
315 extern	void	lock(char	*user);
316 extern	void	madd_recip(reciplist *plist, char *name, int checkdups);
317 extern	char	*mailcompile(string *pattern, int *retlen, int *retnbra);
318 extern	void	mkdead(void);
319 extern	void	mktmp(void);
320 extern	void	mta_ercode(FILE *outfile);
321 extern	void	new_reciplist (reciplist *list);
322 extern	int	notme(char *fto, char *myname);
323 extern	int	parse(int argc, char **argv);
324 extern	int	pckaffspot(void);
325 extern	int	pckrcvspot(void);
326 extern	void	pickFrom(char *lineptr);
327 extern	int	pipletr(int letter, char *command, int cltype);
328 extern	void	poplist (int hdrtype, int where);
329 extern	int	printhdr (int type, int hdrtype, struct hdrs *hptr, FILE *fp);
330 extern	void	printmail(void);
331 extern	void	pushlist(int hdrtype, int where, char *s, int contflg);
332 extern	void	savdead(void);
333 extern	void	savehdrs(char *s, int hdrtype);
334 extern	int	sel_disp (int type, int hdrtype, char *s);
335 extern	int	sendlist(reciplist *list, int letnum, int level);
336 extern	void	sendmail(int argc, char **argv);
337 extern	int	sendsurg(reciplist *plist, int  letnum, int flag, int local);
338 extern	void	setletr(int letter, int status);
339 extern	void	(*setsig(int i, void(*f)()))();
340 extern	void	setsurg_bt(string *st, int *pbatchsize, int *presolved);
341 extern	char	*setsurg_rc(string *st, int defreal, int *pbatchsize);
342 extern	char	**setup_exec(char*);
343 extern	void	stamp(void);
344 extern	int	systm(char *s);
345 extern	void	tmperr(void);
346 extern	string	*tokdef(string *fld, string *tok, char *name);
347 extern	int	translate(reciplist *plist, char *cmdstr, char *origname);
348 extern	void	unlock(void);
349 extern	int	validmsg(int);
350 extern	int	wtmpf(char *str, int length);
351 
352 extern	int	ac;		/* argument list count */
353 extern	char	**av;		/* argument list */
354 extern	int	affbytecnt;     /* Total bytes of Auto-Fwd. info in msg. */
355 extern	int	affcnt;		/* Number of Auto-Fwd.-From: lines in msg. */
356 extern	int	Daffbytecnt;    /* Hold affbytecnt when sending Deliv. Notif. */
357 extern	int	Daffcnt;	/* Hold affcnt when sending Deliv. Notif. */
358 extern	char	binmsg[];
359 extern	int	changed;	/* > 0 says mailfile has changed */
360 extern	char	datestring[60];
361 extern	char	dbgfname[20];	/* name of file for debugging output */
362 extern	FILE	*dbgfp;		/* FILE* for debugging output */
363 extern	char	dead[];		/* name of dead.letter */
364 extern	int	debug;		/* Controls debugging level. 0 ==> no debugging */
365 extern	int	delflg;
366 extern	int	dflag;		/* 1 says returning unsendable mail */
367 extern	char	*errlist[];
368 extern	int	error;		/* Local value for error */
369 extern	char	*failsafe;	/* $FAILSAFE */
370 extern	int	file_size;
371 extern	int	flge;		/* 1 ==> 'e' option specified */
372 extern  int     flgE;		/* 1 ==> 'E' option specified */
373 extern	int	flgF;		/* 1 ==> Installing/Removing  Forwarding */
374 extern	int	flgf;		/* 1 ==> 'f' option specified */
375 extern	int	flgh;		/* 1 ==> 'h' option specified */
376 extern	int	flgm;
377 extern	int	flgp;		/* 1 ==> 'p' option specified */
378 extern	int	flgP;		/* 1 ==> 'P' option specified */
379 extern	int	flgr;		/* 1 ==> 'r' option -- print in fifo order */
380 extern	int	flgt;		/* 1 ==> 't' option -- add To: line to letter */
381 extern	int	flgT;		/* 1 ==> 'T' option specified */
382 extern	int	flgw;		/* 1 ==> 'w' option specified */
383 extern	int	fnuhdrtype;	/* type of first non-UNIX header line */
384 extern	char	forwmsg[];	/* " forwarded by %s" */
385 extern	char	frwlmsg[];	/* "Forwarding loop detected in mailfile" */
386 extern	char	fromS[1024];	/* stored here by sendmail for sendsurg */
387 extern	char	fromU[1024];	/* stored here by sendmail for sendsurg */
388 extern	char	frwrd[];	/* forwarding sentinel */
389 extern	char	fwdFrom[1024];
390 extern	int	goerr;		/* counts parsing errors */
391 extern	struct	group *grpptr;	/* pointer to struct group */
392 extern	struct hdrlines hdrlines[H_CONT];
393 extern	struct hdr header[];	/* H_* #define's used to index into array */
394 extern	char	*help[];
395 extern	char	*hmbox;		/* pointer to $HOME/mbox */
396 extern	char	*hmdead;	/* pointer to $HOME/dead.letter */
397 extern	char	*home;		/* pointer to $HOME */
398 extern	time_t	iop;
399 extern	int	interactive;	/* 1 says user is interactive */
400 extern	int	ismail;		/* default to program=mail */
401 extern  int     deliverflag;     /* -d flag, bypass sendmail and go to mbox */
402 extern  int     fromflag;       /* -f from_user while sending */
403 extern	int	keepdbgfile;	/* does debug file get deleted at end? */
404 extern	struct let let[MAXLET];
405 extern	char	*lettmp;	/* pointer to tmp filename */
406 extern	char	lfil[MAXFILENAME];
407 extern	char	line[LSIZE];	/* holds a line of a letter in many places */
408 extern	char	*mailfile;	/* pointer to mailfile */
409 extern	char	mailcnfg[];	/* /etc/mail/mailcnfg */
410 extern	char	maildir[];	/* directory for mail files */
411 extern	gid_t	mailgrp;	/* numeric id of group 'mail' */
412 extern	char	mailsave[];	/* dir for save files */
413 extern	char	*mailsurr;	/* surrogate file name */
414 extern	FILE	*malf;		/* File pointer for mailfile */
415 extern	int	maxerr;		/* largest value of error */
416 extern	char	mbox[];		/* name for mbox */
417 extern	uid_t	mf_uid;		/* uid of user's mailfile */
418 extern	gid_t	mf_gid;		/* gid of user's mailfile */
419 extern	char	*msgtype;
420 extern	char	my_name[1024];	/* user's name who invoked this command */
421 extern	char	from_user[1024];/* name of user mail's from, used w/ -f */
422 extern	uid_t	my_euid;	/* user's euid */
423 extern	gid_t	my_egid;	/* user's egid */
424 extern	uid_t	my_uid;		/* user's uid */
425 extern	gid_t	my_gid;		/* user's gid */
426 extern	int	nlet;		/* current number of letters in mailfile */
427 extern	int	onlet;		/* number of letters in mailfile at startup*/
428 extern	int	optcnt;		/* Number of options specified */
429 extern	int	orig_aff;	/* orig. msg. contained H_AFWDFROM lines */
430 extern	int	orig_dbglvl;	/* argument to -x invocation option */
431 extern	int	orig_rcv;	/* orig. msg. contained H_RECEIVED lines */
432 extern	int	orig_tcopy;	/* orig. msg. contained H_TCOPY lines */
433 extern	struct	passwd *pwd;	/* holds passwd entry for this user */
434 extern	int	pflg;		/* binary message display override flag */
435 extern	int	Pflg;		/* Selective display flag; 1 ==> display all */
436 extern	char	*program;	/* program name */
437 extern	int	rcvbytecnt;     /* Total bytes of Received: info in msg. */
438 extern	int	Drcvbytecnt;    /* Hold rcvbytecnt when sending Del. Notif. */
439 extern	char	*recipname;	/* full recipient name/address */
440 extern	int	replying;	/* 1 says we are replying to a letter */
441 extern	char	RFC822datestring[60];/* Date in RFC822 date format */
442 extern	char	rmtmsg[];	/* "remote from %s" */
443 extern	char	Rpath[1024];	/* return path to sender of message */
444 extern	char	rtrnmsg[];	/* "UNDELIVERABLE MAIL being returned by %s" */
445 extern	int	sav_errno;
446 extern	char	savefile[MAXFILENAME];	/* holds filename of save file */
447 extern	void	(*saveint)(int);
448 extern	char	*seldisp[];
449 extern	int	sending;	/* TRUE==>sending mail; FALSE==>printing mail */
450 extern	char	m_sendto[1024];
451 extern	jmp_buf	sjbuf;
452 extern	int	surg_rc;	/* exit code of surrogate command */
453 extern	t_surrfile *surrfile;	/* the compiled surrogate file */
454 extern	int	surr_len;	/* # entries in surrogate file */
455 extern	char	*SURRcmdstr;	/* save in case of FAILURE */
456 extern	FILE	*SURRerrfile;	/* stderr from surrogate in case of failure */
457 extern	char	*thissys;	/* Holds name of the system we are on */
458 extern	FILE	*tmpf;		/* file pointer for temporary files */
459 extern	mode_t	umsave;
460 extern	struct	utsname utsn;
461 extern	struct utimbuf *utimep;
462 extern	char	uval[1024];
463 
464 #ifdef NOTDEF
465 #ifdef sun
466 #define _NFILE getdtablesize()
467 #endif
468 #endif /* NOTDEF */
469 
470 #endif /* _MAIL_H */
471