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 74 typedef int gid_t; 75 typedef int uid_t; 76 # endif 77 typedef 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 208 struct hdr { 209 char *tag; 210 int default_display; 211 }; 212 213 struct hdrs { 214 struct hdrs *next; 215 struct hdrs *prev; 216 struct hdrs *cont; /* Continuation lines */ 217 char value[HDRSIZ+1]; 218 }; 219 220 struct hdrlines { 221 struct hdrs *head; 222 struct hdrs *tail; 223 }; 224 225 typedef struct recip { 226 struct recip *next; 227 char *name; 228 } recip; 229 230 typedef struct reciplist { 231 recip *last_recip; 232 recip recip_list; 233 } reciplist; 234 235 struct 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 244 typedef 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 251 typedef 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 279 extern int chmod(); 280 extern int close(); 281 extern char *ctime(); 282 extern int errno; 283 extern int execl(); 284 extern int execvp(); 285 extern void exit(); 286 extern char *getenv(); 287 extern char *getlogin(); 288 extern long ftell(); 289 extern struct group *getgrnam(); 290 extern struct passwd *getpwent(); 291 extern struct passwd *getpwnam(); 292 extern struct passwd *getpwuid(); 293 extern char *malloc(); 294 extern char *memcpy(); 295 extern char *memmove(); 296 extern char *mktemp(); 297 extern char *realloc(); 298 extern void setpwent(); 299 extern unsigned sleep(); 300 extern char *strchr(); 301 extern char *strcpy(); 302 extern char *strncpy(); 303 extern char *strpbrk(); 304 extern char *strrchr(); 305 extern time_t time(); 306 extern char *tempnam(); 307 extern FILE *tmpfile(); 308 extern int unlink(); 309 #endif 310 311 extern char *optarg; /* for getopt */ 312 extern int optind; 313 extern char *sys_errlist[]; 314 315 #ifdef __STDC__ 316 extern void Dout(char *subname, int level, char *fmt, ...); 317 extern void Tout(char *subname, char *msg, ...); 318 extern int add_recip(reciplist *plist, char *name, int checkdups); 319 extern char *altcompile(const char *instring, char *expbuf, char *endbuf); 320 extern int areforwarding(char *mailfile); 321 extern void cat(char*, char*, char*); 322 extern int ckdlivopts(int tcopy_hdr, int *svopts); 323 extern void cksaved(char *user); 324 extern int cksurg_rc(int surr_num, int rc); 325 extern void clr_hinfo(void); 326 extern void clrhdr(int hdrtype); 327 extern void cmdexpand(int letnum, string *instr, string *outstr, char **lbraslist, char **lbraelist); 328 extern void copyback(void); 329 extern int copylet(int letnum, FILE *f, int type); 330 extern void copymt(FILE *f1, FILE *f2); 331 extern void createmf(uid_t uid, char *file); 332 extern void del_reciplist (reciplist *list); 333 extern void delete(int); 334 extern void doFopt(void); 335 extern void done(int); 336 extern void sig_done(int); 337 extern FILE *doopen(char *file, char *type, int errnum); 338 extern int dowait(pid_t pidval); 339 extern void dumpaff(int type, int htype, int *didafflines, int *suppress, FILE *f); 340 extern void dumprcv(int type, int htype, int *didrcvlines, int *suppress, FILE *f); 341 extern void errmsg(int error_value, char *error_message); 342 extern int findSurg(int letnum, string *execbuf, int flag, int *psurr_num, int *paccept, string *lorig, string *lrecipname); 343 extern void gendeliv(FILE *fp, int rc, char *name); 344 extern int getcomment(char *s, char *q); 345 extern int gethead(int current, int all); 346 extern int getline(char *ptr2line, int max, FILE *f); 347 extern int getnumbr(char *s); 348 extern int getsurr(FILE *fp, string *buf, int firstfield); 349 extern void goback(int letnum); 350 extern int init(void); 351 extern void initsurrfile(void); 352 extern int isheader(char *lp, int *ctfp); 353 extern int isit(char *lp, int type); 354 extern int islocal(char *user, uid_t *puid); 355 extern int istext(unsigned char *s, int size); 356 extern int legal(char *file); 357 extern void lock(char *user); 358 extern int madd_recip(reciplist *plist, char *name, int checkdups); 359 extern char *mailcompile(string *pattern, int *retlen, int *retnbra); 360 extern void mkdead(void); 361 extern void mktmp(void); 362 extern void mta_ercode(FILE *outfile); 363 extern void new_reciplist (reciplist *list); 364 extern int notme(char *fto, char *myname); 365 extern int parse(int argc, char **argv); 366 extern int pckaffspot(void); 367 extern int pckrcvspot(void); 368 extern void pickFrom(char *lineptr); 369 extern int pipletr(int letter, char *command, int cltype); 370 extern void poplist (int hdrtype, int where); 371 extern int printhdr (int type, int hdrtype, struct hdrs *hptr, FILE *fp); 372 extern void printmail(void); 373 extern void pushlist(int hdrtype, int where, char *s, int contflg); 374 extern void savdead(void); 375 extern void savehdrs(char *s, int hdrtype); 376 extern int sel_disp (int type, int hdrtype, char *s); 377 extern int sendlist(reciplist *list, int letnum, int level); 378 extern void sendmail(int argc, char **argv); 379 extern int sendsurg(reciplist *plist, int letnum, int flag, int local); 380 extern void setletr(int letter, int status); 381 extern void (*setsig(int i, void(*f)()))(); 382 extern void setsurg_bt(string *st, int *pbatchsize, int *presolved); 383 extern char *setsurg_rc(string *st, int defreal, int *pbatchsize); 384 extern char **setup_exec(char*); 385 extern void stamp(void); 386 extern int systm(char *s); 387 extern void tmperr(void); 388 extern string *tokdef(string *fld, string *tok, char *name); 389 extern int translate(reciplist *plist, char *cmdstr, char *origname); 390 extern void unlock(void); 391 extern int validmsg(int); 392 extern int wtmpf(char *str, int length); 393 #else 394 extern void Dout(); 395 extern void Tout(); 396 extern int add_recip(); 397 extern char *altcompile(); 398 extern int areforwarding(); 399 extern void cat(); 400 extern int ckdlivopts(); 401 extern void cksaved(); 402 extern int cksurg_rc(); 403 extern void clr_hinfo(); 404 extern void clrhdr(); 405 extern void cmdexpand(); 406 extern void copyback(); 407 extern int copylet(); 408 extern void copymt(); 409 extern void createmf(); 410 extern void del_reciplist (); 411 extern void delete(); 412 extern void doFopt(); 413 extern void done(); 414 extern void sig_done(); 415 extern FILE *doopen(); 416 extern int dowait(); 417 extern void dumpaff(); 418 extern void dumprcv(); 419 extern void errmsg(); 420 extern int findSurg(); 421 extern void gendeliv(); 422 extern int getcomment(); 423 extern int gethead(); 424 extern int getline(); 425 extern int getnumbr(); 426 extern int getsurr(); 427 extern void goback(); 428 extern int init(); 429 extern void initsurrfile(); 430 extern int isheader(); 431 extern int isit(); 432 extern int islocal(); 433 extern int istext(); 434 extern int legal(); 435 extern void lock(); 436 extern int madd_recip(); 437 extern char *mailcompile(); 438 extern void mkdead(); 439 extern void mktmp(); 440 extern void mta_ercode(); 441 extern void new_reciplist (); 442 extern int notme(); 443 extern int parse(); 444 extern int pckaffspot(); 445 extern int pckrcvspot(); 446 extern void pickFrom (); 447 extern int pipletr(); 448 extern void poplist (); 449 extern int printhdr (); 450 extern void printmail(); 451 extern void pushlist(); 452 extern void savdead(); 453 extern void savehdrs(); 454 extern int sel_disp (); 455 extern int sendlist(); 456 extern void sendmail(); 457 extern int sendsurg(); 458 extern void setletr(); 459 extern void (*setsig())(); 460 extern void setsurg_bt(); 461 extern char *setsurg_rc(); 462 extern char **setup_exec(); 463 extern void stamp(); 464 extern int systm(); 465 extern void tmperr(); 466 extern string *tokdef(); 467 extern int translate(); 468 extern void unlock(); 469 extern int validmsg(); 470 extern int wtmpf(); 471 #endif 472 473 extern int ac; /* argument list count */ 474 extern char **av; /* argument list */ 475 extern int affbytecnt; /* Total bytes of Auto-Fwd. info in msg. */ 476 extern int affcnt; /* Number of Auto-Fwd.-From: lines in msg. */ 477 extern int Daffbytecnt; /* Hold affbytecnt when sending Deliv. Notif. */ 478 extern int Daffcnt; /* Hold affcnt when sending Deliv. Notif. */ 479 extern char binmsg[]; 480 extern int changed; /* > 0 says mailfile has changed */ 481 extern char datestring[60]; 482 extern char dbgfname[20]; /* name of file for debugging output */ 483 extern FILE *dbgfp; /* FILE* for debugging output */ 484 extern char dead[]; /* name of dead.letter */ 485 extern int debug; /* Controls debugging level. 0 ==> no debugging */ 486 extern int delflg; 487 extern int dflag; /* 1 says returning unsendable mail */ 488 extern char *errlist[]; 489 extern int error; /* Local value for error */ 490 extern char *failsafe; /* $FAILSAFE */ 491 extern int file_size; 492 extern int flge; /* 1 ==> 'e' option specified */ 493 extern int flgE; /* 1 ==> 'E' option specified */ 494 extern int flgF; /* 1 ==> Installing/Removing Forwarding */ 495 extern int flgf; /* 1 ==> 'f' option specified */ 496 extern int flgh; /* 1 ==> 'h' option specified */ 497 extern int flgm; 498 extern int flgp; /* 1 ==> 'p' option specified */ 499 extern int flgP; /* 1 ==> 'P' option specified */ 500 extern int flgr; /* 1 ==> 'r' option -- print in fifo order */ 501 extern int flgt; /* 1 ==> 't' option -- add To: line to letter */ 502 extern int flgT; /* 1 ==> 'T' option specified */ 503 extern int flgw; /* 1 ==> 'w' option specified */ 504 extern int fnuhdrtype; /* type of first non-UNIX header line */ 505 extern char forwmsg[]; /* " forwarded by %s" */ 506 extern char frwlmsg[]; /* "Forwarding loop detected in mailfile" */ 507 extern char fromS[1024]; /* stored here by sendmail for sendsurg */ 508 extern char fromU[1024]; /* stored here by sendmail for sendsurg */ 509 extern char frwrd[]; /* forwarding sentinel */ 510 extern char fwdFrom[1024]; 511 extern int goerr; /* counts parsing errors */ 512 extern struct group *grpptr; /* pointer to struct group */ 513 extern struct hdrlines hdrlines[H_CONT]; 514 extern struct hdr header[]; /* H_* #define's used to index into array */ 515 extern char *help[]; 516 extern char *hmbox; /* pointer to $HOME/mbox */ 517 extern char *hmdead; /* pointer to $HOME/dead.letter */ 518 extern char *home; /* pointer to $HOME */ 519 extern time_t iop; 520 extern int interactive; /* 1 says user is interactive */ 521 extern int ismail; /* default to program=mail */ 522 extern int deliverflag; /* -d flag, bypass sendmail and go to mbox */ 523 extern int fromflag; /* -f from_user while sending */ 524 extern int keepdbgfile; /* does debug file get deleted at end? */ 525 extern struct let let[MAXLET]; 526 extern char *lettmp; /* pointer to tmp filename */ 527 extern char lfil[MAXFILENAME]; 528 extern char line[LSIZE]; /* holds a line of a letter in many places */ 529 extern char *mailfile; /* pointer to mailfile */ 530 extern char mailcnfg[]; /* /etc/mail/mailcnfg */ 531 extern char maildir[]; /* directory for mail files */ 532 extern gid_t mailgrp; /* numeric id of group 'mail' */ 533 extern char mailsave[]; /* dir for save files */ 534 extern char *mailsurr; /* surrogate file name */ 535 extern FILE *malf; /* File pointer for mailfile */ 536 extern int maxerr; /* largest value of error */ 537 extern char mbox[]; /* name for mbox */ 538 extern uid_t mf_uid; /* uid of user's mailfile */ 539 extern gid_t mf_gid; /* gid of user's mailfile */ 540 extern char *msgtype; 541 extern char my_name[1024]; /* user's name who invoked this command */ 542 extern char from_user[1024];/* name of user mail's from, used w/ -f */ 543 extern uid_t my_euid; /* user's euid */ 544 extern gid_t my_egid; /* user's egid */ 545 extern uid_t my_uid; /* user's uid */ 546 extern gid_t my_gid; /* user's gid */ 547 extern int nlet; /* current number of letters in mailfile */ 548 extern int onlet; /* number of letters in mailfile at startup*/ 549 extern int optcnt; /* Number of options specified */ 550 extern int orig_aff; /* orig. msg. contained H_AFWDFROM lines */ 551 extern int orig_dbglvl; /* argument to -x invocation option */ 552 extern int orig_rcv; /* orig. msg. contained H_RECEIVED lines */ 553 extern int orig_tcopy; /* orig. msg. contained H_TCOPY lines */ 554 extern struct passwd *pwd; /* holds passwd entry for this user */ 555 extern int pflg; /* binary message display override flag */ 556 extern int Pflg; /* Selective display flag; 1 ==> display all */ 557 extern char *program; /* program name */ 558 extern int rcvbytecnt; /* Total bytes of Received: info in msg. */ 559 extern int Drcvbytecnt; /* Hold rcvbytecnt when sending Del. Notif. */ 560 extern char *recipname; /* full recipient name/address */ 561 extern int replying; /* 1 says we are replying to a letter */ 562 extern char RFC822datestring[60];/* Date in RFC822 date format */ 563 extern char rmtmsg[]; /* "remote from %s" */ 564 extern char Rpath[1024]; /* return path to sender of message */ 565 extern char rtrnmsg[]; /* "UNDELIVERABLE MAIL being returned by %s" */ 566 extern int sav_errno; 567 extern char savefile[MAXFILENAME]; /* holds filename of save file */ 568 #ifdef __STDC__ 569 extern void (*saveint)(int); 570 #else 571 extern void (*saveint)(); 572 #endif 573 extern char *seldisp[]; 574 extern int sending; /* TRUE==>sending mail; FALSE==>printing mail */ 575 extern char m_sendto[1024]; 576 extern jmp_buf sjbuf; 577 extern int surg_rc; /* exit code of surrogate command */ 578 extern t_surrfile *surrfile; /* the compiled surrogate file */ 579 extern int surr_len; /* # entries in surrogate file */ 580 extern char *SURRcmdstr; /* save in case of FAILURE */ 581 extern FILE *SURRerrfile; /* stderr from surrogate in case of failure */ 582 extern char *thissys; /* Holds name of the system we are on */ 583 extern FILE *tmpf; /* file pointer for temporary files */ 584 extern mode_t umsave; 585 extern struct utsname utsn; 586 extern struct utimbuf *utimep; 587 extern 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