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