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
70typedef int gid_t;
71typedef int uid_t;
72# endif
73typedef 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
204struct hdr {
205	char	*tag;
206	int	default_display;
207};
208
209struct hdrs {
210	struct	hdrs	*next;
211	struct	hdrs	*prev;
212	struct	hdrs	*cont;	/* Continuation lines */
213		char	value[HDRSIZ+1];
214};
215
216struct hdrlines {
217	struct	hdrs	*head;
218	struct	hdrs	*tail;
219};
220
221typedef struct recip {
222	struct recip	*next;
223	char		*name;
224} recip;
225
226typedef struct reciplist {
227	recip *last_recip;
228	recip recip_list;
229} reciplist;
230
231struct 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
240typedef 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
247typedef 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
274extern	void	Dout(char *subname, int level, char *fmt, ...);
275extern	void	Tout(char *subname, char *msg, ...);
276extern	int	add_recip(reciplist *plist, char *name, int checkdups);
277extern	char	*altcompile(const char *instring, char *expbuf, char *endbuf);
278extern	int	areforwarding(char *mailfile);
279extern	void	cat(char*, char*, char*);
280extern	int	ckdlivopts(int tcopy_hdr, int *svopts);
281extern	void	cksaved(char *user);
282extern	int	cksurg_rc(int surr_num, int rc);
283extern	void	clr_hinfo(void);
284extern	void	clrhdr(int hdrtype);
285extern	void	cmdexpand(int letnum, string *instr, string *outstr, char **lbraslist, char **lbraelist);
286extern	void	copyback(void);
287extern	int	copylet(int letnum, FILE *f, int type);
288extern	void	copymt(FILE *f1, FILE *f2);
289extern	void	createmf(uid_t uid, char *file);
290extern	void	del_reciplist (reciplist *list);
291extern	void	delete(int);
292extern	void	doFopt(void);
293extern	void	done(int) __NORETURN;
294extern	void	sig_done(int);
295extern	FILE	*doopen(char *file, char *type, int errnum);
296extern	int	dowait(pid_t pidval);
297extern	void	dumpaff(int type, int htype, int *didafflines, int *suppress, FILE *f);
298extern	void	dumprcv(int type, int htype, int *didrcvlines, int *suppress, FILE *f);
299extern	void	errmsg(int error_value, char *error_message);
300extern	int	findSurg(int letnum, string *execbuf, int flag, int *psurr_num, int *paccept, string *lorig, string *lrecipname);
301extern	void	gendeliv(FILE *fp, int rc, char *name);
302extern	int	getcomment(char *s, char *q);
303extern	int	gethead(int	current, int all);
304extern	int	getaline(char *ptr2line, int max, FILE *f);
305extern	int	getnumbr(char *s);
306extern	int	getsurr(FILE *fp, string *buf, int firstfield);
307extern	void	goback(int letnum);
308extern	int	init(void);
309extern	void	initsurrfile(void);
310extern	int	isheader(char *lp, int *ctfp);
311extern	int	isit(char *lp, int type);
312extern	int	islocal(char *user, uid_t *puid);
313extern	int	istext(unsigned char *s, int size);
314extern	int	legal(char *file);
315extern	void	lock(char	*user);
316extern	void	madd_recip(reciplist *plist, char *name, int checkdups);
317extern	char	*mailcompile(string *pattern, int *retlen, int *retnbra);
318extern	void	mkdead(void);
319extern	void	mktmp(void);
320extern	void	mta_ercode(FILE *outfile);
321extern	void	new_reciplist (reciplist *list);
322extern	int	notme(char *fto, char *myname);
323extern	int	parse(int argc, char **argv);
324extern	int	pckaffspot(void);
325extern	int	pckrcvspot(void);
326extern	void	pickFrom(char *lineptr);
327extern	int	pipletr(int letter, char *command, int cltype);
328extern	void	poplist (int hdrtype, int where);
329extern	int	printhdr (int type, int hdrtype, struct hdrs *hptr, FILE *fp);
330extern	void	printmail(void);
331extern	void	pushlist(int hdrtype, int where, char *s, int contflg);
332extern	void	savdead(void);
333extern	void	savehdrs(char *s, int hdrtype);
334extern	int	sel_disp (int type, int hdrtype, char *s);
335extern	int	sendlist(reciplist *list, int letnum, int level);
336extern	void	sendmail(int argc, char **argv);
337extern	int	sendsurg(reciplist *plist, int  letnum, int flag, int local);
338extern	void	setletr(int letter, int status);
339extern	void	(*setsig(int i, void(*f)()))();
340extern	void	setsurg_bt(string *st, int *pbatchsize, int *presolved);
341extern	char	*setsurg_rc(string *st, int defreal, int *pbatchsize);
342extern	char	**setup_exec(char*);
343extern	void	stamp(void);
344extern	int	systm(char *s);
345extern	void	tmperr(void);
346extern	string	*tokdef(string *fld, string *tok, char *name);
347extern	int	translate(reciplist *plist, char *cmdstr, char *origname);
348extern	void	unlock(void);
349extern	int	validmsg(int);
350extern	int	wtmpf(char *str, int length);
351
352extern	int	ac;		/* argument list count */
353extern	char	**av;		/* argument list */
354extern	int	affbytecnt;     /* Total bytes of Auto-Fwd. info in msg. */
355extern	int	affcnt;		/* Number of Auto-Fwd.-From: lines in msg. */
356extern	int	Daffbytecnt;    /* Hold affbytecnt when sending Deliv. Notif. */
357extern	int	Daffcnt;	/* Hold affcnt when sending Deliv. Notif. */
358extern	char	binmsg[];
359extern	int	changed;	/* > 0 says mailfile has changed */
360extern	char	datestring[60];
361extern	char	dbgfname[20];	/* name of file for debugging output */
362extern	FILE	*dbgfp;		/* FILE* for debugging output */
363extern	char	dead[];		/* name of dead.letter */
364extern	int	debug;		/* Controls debugging level. 0 ==> no debugging */
365extern	int	delflg;
366extern	int	dflag;		/* 1 says returning unsendable mail */
367extern	char	*errlist[];
368extern	int	error;		/* Local value for error */
369extern	char	*failsafe;	/* $FAILSAFE */
370extern	int	file_size;
371extern	int	flge;		/* 1 ==> 'e' option specified */
372extern  int     flgE;		/* 1 ==> 'E' option specified */
373extern	int	flgF;		/* 1 ==> Installing/Removing  Forwarding */
374extern	int	flgf;		/* 1 ==> 'f' option specified */
375extern	int	flgh;		/* 1 ==> 'h' option specified */
376extern	int	flgm;
377extern	int	flgp;		/* 1 ==> 'p' option specified */
378extern	int	flgP;		/* 1 ==> 'P' option specified */
379extern	int	flgr;		/* 1 ==> 'r' option -- print in fifo order */
380extern	int	flgt;		/* 1 ==> 't' option -- add To: line to letter */
381extern	int	flgT;		/* 1 ==> 'T' option specified */
382extern	int	flgw;		/* 1 ==> 'w' option specified */
383extern	int	fnuhdrtype;	/* type of first non-UNIX header line */
384extern	char	forwmsg[];	/* " forwarded by %s" */
385extern	char	frwlmsg[];	/* "Forwarding loop detected in mailfile" */
386extern	char	fromS[1024];	/* stored here by sendmail for sendsurg */
387extern	char	fromU[1024];	/* stored here by sendmail for sendsurg */
388extern	char	frwrd[];	/* forwarding sentinel */
389extern	char	fwdFrom[1024];
390extern	int	goerr;		/* counts parsing errors */
391extern	struct	group *grpptr;	/* pointer to struct group */
392extern	struct hdrlines hdrlines[H_CONT];
393extern	struct hdr header[];	/* H_* #define's used to index into array */
394extern	char	*help[];
395extern	char	*hmbox;		/* pointer to $HOME/mbox */
396extern	char	*hmdead;	/* pointer to $HOME/dead.letter */
397extern	char	*home;		/* pointer to $HOME */
398extern	time_t	iop;
399extern	int	interactive;	/* 1 says user is interactive */
400extern	int	ismail;		/* default to program=mail */
401extern  int     deliverflag;     /* -d flag, bypass sendmail and go to mbox */
402extern  int     fromflag;       /* -f from_user while sending */
403extern	int	keepdbgfile;	/* does debug file get deleted at end? */
404extern	struct let let[MAXLET];
405extern	char	*lettmp;	/* pointer to tmp filename */
406extern	char	lfil[MAXFILENAME];
407extern	char	line[LSIZE];	/* holds a line of a letter in many places */
408extern	char	*mailfile;	/* pointer to mailfile */
409extern	char	mailcnfg[];	/* /etc/mail/mailcnfg */
410extern	char	maildir[];	/* directory for mail files */
411extern	gid_t	mailgrp;	/* numeric id of group 'mail' */
412extern	char	mailsave[];	/* dir for save files */
413extern	char	*mailsurr;	/* surrogate file name */
414extern	FILE	*malf;		/* File pointer for mailfile */
415extern	int	maxerr;		/* largest value of error */
416extern	char	mbox[];		/* name for mbox */
417extern	uid_t	mf_uid;		/* uid of user's mailfile */
418extern	gid_t	mf_gid;		/* gid of user's mailfile */
419extern	char	*msgtype;
420extern	char	my_name[1024];	/* user's name who invoked this command */
421extern	char	from_user[1024];/* name of user mail's from, used w/ -f */
422extern	uid_t	my_euid;	/* user's euid */
423extern	gid_t	my_egid;	/* user's egid */
424extern	uid_t	my_uid;		/* user's uid */
425extern	gid_t	my_gid;		/* user's gid */
426extern	int	nlet;		/* current number of letters in mailfile */
427extern	int	onlet;		/* number of letters in mailfile at startup*/
428extern	int	optcnt;		/* Number of options specified */
429extern	int	orig_aff;	/* orig. msg. contained H_AFWDFROM lines */
430extern	int	orig_dbglvl;	/* argument to -x invocation option */
431extern	int	orig_rcv;	/* orig. msg. contained H_RECEIVED lines */
432extern	int	orig_tcopy;	/* orig. msg. contained H_TCOPY lines */
433extern	struct	passwd *pwd;	/* holds passwd entry for this user */
434extern	int	pflg;		/* binary message display override flag */
435extern	int	Pflg;		/* Selective display flag; 1 ==> display all */
436extern	char	*program;	/* program name */
437extern	int	rcvbytecnt;     /* Total bytes of Received: info in msg. */
438extern	int	Drcvbytecnt;    /* Hold rcvbytecnt when sending Del. Notif. */
439extern	char	*recipname;	/* full recipient name/address */
440extern	int	replying;	/* 1 says we are replying to a letter */
441extern	char	RFC822datestring[60];/* Date in RFC822 date format */
442extern	char	rmtmsg[];	/* "remote from %s" */
443extern	char	Rpath[1024];	/* return path to sender of message */
444extern	char	rtrnmsg[];	/* "UNDELIVERABLE MAIL being returned by %s" */
445extern	int	sav_errno;
446extern	char	savefile[MAXFILENAME];	/* holds filename of save file */
447extern	void	(*saveint)(int);
448extern	char	*seldisp[];
449extern	int	sending;	/* TRUE==>sending mail; FALSE==>printing mail */
450extern	char	m_sendto[1024];
451extern	jmp_buf	sjbuf;
452extern	int	surg_rc;	/* exit code of surrogate command */
453extern	t_surrfile *surrfile;	/* the compiled surrogate file */
454extern	int	surr_len;	/* # entries in surrogate file */
455extern	char	*SURRcmdstr;	/* save in case of FAILURE */
456extern	FILE	*SURRerrfile;	/* stderr from surrogate in case of failure */
457extern	char	*thissys;	/* Holds name of the system we are on */
458extern	FILE	*tmpf;		/* file pointer for temporary files */
459extern	mode_t	umsave;
460extern	struct	utsname utsn;
461extern	struct utimbuf *utimep;
462extern	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