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