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