1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate /* 34*0Sstevel@tonic-gate * All global externs defined in mail.h. All variables are initialized 35*0Sstevel@tonic-gate * here! 36*0Sstevel@tonic-gate * 37*0Sstevel@tonic-gate * !!!!!IF YOU CHANGE (OR ADD) IT HERE, DO IT THERE ALSO !!!!!!!! 38*0Sstevel@tonic-gate * 39*0Sstevel@tonic-gate */ 40*0Sstevel@tonic-gate #include "mail.h" 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate int ac; /* argument list count */ 43*0Sstevel@tonic-gate char **av; /* argument list */ 44*0Sstevel@tonic-gate int affbytecnt; /* Total bytes of Auto-Fwd. info in msg. */ 45*0Sstevel@tonic-gate int affcnt; /* Number of Auto-Fwd.-From: lines in msg. */ 46*0Sstevel@tonic-gate int Daffbytecnt; /* Hold affbytecnt when sending Delivery Notification */ 47*0Sstevel@tonic-gate int Daffcnt; /* Hold affcnt when sending Delivery Notification */ 48*0Sstevel@tonic-gate char binmsg[] = "*** Message content is not printable: delete, write or save it to a file ***"; 49*0Sstevel@tonic-gate int changed; /* > 0 says mailfile has changed */ 50*0Sstevel@tonic-gate char datestring[60]; /* Today's date and time */ 51*0Sstevel@tonic-gate char dbgfname[20]; 52*0Sstevel@tonic-gate FILE *dbgfp; 53*0Sstevel@tonic-gate char dead[] = "/dead.letter"; /* name of dead.letter */ 54*0Sstevel@tonic-gate int debug; /* Controls debugging level. 0 ==> no debugging */ 55*0Sstevel@tonic-gate int delflg = 1; 56*0Sstevel@tonic-gate int dflag = 0; /* 1 says returning unsendable mail */ 57*0Sstevel@tonic-gate char *errlist[]= { 58*0Sstevel@tonic-gate "", 59*0Sstevel@tonic-gate "Unknown system", 60*0Sstevel@tonic-gate "Problem with mailfile", 61*0Sstevel@tonic-gate "Space problem", 62*0Sstevel@tonic-gate "Unable to forward mail, check permissions and group", 63*0Sstevel@tonic-gate "Syntax error", 64*0Sstevel@tonic-gate "Forwarding loop", 65*0Sstevel@tonic-gate "Invalid sender", 66*0Sstevel@tonic-gate "Invalid recipient", 67*0Sstevel@tonic-gate "Too many From lines", 68*0Sstevel@tonic-gate "Invalid permissions", 69*0Sstevel@tonic-gate "Cannot open mbox", 70*0Sstevel@tonic-gate "Temporary file problem", 71*0Sstevel@tonic-gate "Cannot create dead.letter", 72*0Sstevel@tonic-gate "Unbounded forwarding", 73*0Sstevel@tonic-gate "Cannot create lock file", 74*0Sstevel@tonic-gate "No group id of 'mail'", 75*0Sstevel@tonic-gate "Problem allocating memory", 76*0Sstevel@tonic-gate "Could not fork", 77*0Sstevel@tonic-gate "Cannot pipe", 78*0Sstevel@tonic-gate "Must be owner to modify mailfile", 79*0Sstevel@tonic-gate "Permission denied by /etc/mail/mailsurr file", 80*0Sstevel@tonic-gate "Surrogate command failed" 81*0Sstevel@tonic-gate }; 82*0Sstevel@tonic-gate int error = 0; /* Local value for error */ 83*0Sstevel@tonic-gate char *failsafe; /* $FAILSAFE */ 84*0Sstevel@tonic-gate int file_size; 85*0Sstevel@tonic-gate int flge = 0; /* 1 ==> 'e' option specified */ 86*0Sstevel@tonic-gate int flgE = 0; /* 1 ==> 'E' option specified */ 87*0Sstevel@tonic-gate int flgF = 0; /* 1 ==> Installing/Removing Forwarding */ 88*0Sstevel@tonic-gate int flgf = 0; /* 1 ==> 'f' option specified */ 89*0Sstevel@tonic-gate int flgh = 0; /* 1 ==> 'h' option specified */ 90*0Sstevel@tonic-gate int flgm; 91*0Sstevel@tonic-gate int flgp = 0; /* 1 ==> 'p' option specified */ 92*0Sstevel@tonic-gate int flgP = 0; /* 1 ==> 'P' option specified */ 93*0Sstevel@tonic-gate int flgr = 0; /* 1 ==> 'r' option -- print in fifo order */ 94*0Sstevel@tonic-gate int flgt = 0; /* 1 ==> 't' option -- add To: line to letter */ 95*0Sstevel@tonic-gate int flgT = 0; /* 1 ==> 'T' option specified */ 96*0Sstevel@tonic-gate int flgw = 0; /* 1 ==> 'w' option specified */ 97*0Sstevel@tonic-gate int fnuhdrtype = 0; /* type of first non-UNIX header line */ 98*0Sstevel@tonic-gate char forwmsg[] = " forwarded by %s\n"; 99*0Sstevel@tonic-gate char fromS[1024]; /* stored here by sendmail for sendsurg */ 100*0Sstevel@tonic-gate char fromU[1024]; /* stored here by sendmail for sendsurg */ 101*0Sstevel@tonic-gate char frwlmsg[] = " %s: Forwarding loop detected in %s's mailfile.\n"; 102*0Sstevel@tonic-gate char frwrd[] = "Forward to "; /* forwarding sentinel */ 103*0Sstevel@tonic-gate char fwdFrom[1024]; 104*0Sstevel@tonic-gate int goerr = 0; /* counts parsing errors */ 105*0Sstevel@tonic-gate struct group *grpptr; /* pointer to struct group */ 106*0Sstevel@tonic-gate struct hdrlines hdrlines[H_CONT]; 107*0Sstevel@tonic-gate /* Default_display indicates whether to display this header line to the TTY */ 108*0Sstevel@tonic-gate /* when in default mode. Can be overridden via 'P' command at ? prompt */ 109*0Sstevel@tonic-gate struct hdr header[] = { 110*0Sstevel@tonic-gate "", FALSE, 111*0Sstevel@tonic-gate "Auto-Forward-Count:", FALSE, 112*0Sstevel@tonic-gate "Auto-Forwarded-From:", FALSE, 113*0Sstevel@tonic-gate "Content-Length:", TRUE, 114*0Sstevel@tonic-gate "Content-Type:", FALSE, 115*0Sstevel@tonic-gate "Date:", TRUE, 116*0Sstevel@tonic-gate "Default-Options:", FALSE, 117*0Sstevel@tonic-gate "End-of-Header:", FALSE, 118*0Sstevel@tonic-gate "From ", TRUE, 119*0Sstevel@tonic-gate ">From ", TRUE, 120*0Sstevel@tonic-gate "From:", TRUE, 121*0Sstevel@tonic-gate "MIME-Version:", FALSE, 122*0Sstevel@tonic-gate "MTS-Message-ID:", FALSE, 123*0Sstevel@tonic-gate "Message-Type:", FALSE, 124*0Sstevel@tonic-gate "Message-Version:", FALSE, 125*0Sstevel@tonic-gate "Message-Service:", TRUE, 126*0Sstevel@tonic-gate "Received:", FALSE, 127*0Sstevel@tonic-gate "Report-Version:", FALSE, 128*0Sstevel@tonic-gate "Subject:", TRUE, 129*0Sstevel@tonic-gate "To:", TRUE, 130*0Sstevel@tonic-gate ">To:", FALSE, 131*0Sstevel@tonic-gate "Transport-Options:", FALSE, 132*0Sstevel@tonic-gate "UA-Content-ID:", FALSE, 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate /*Dummy place holders for H_DAFWDFROM,*/ 135*0Sstevel@tonic-gate /*H_DTCOPY and H_RECEIVED. Should */ 136*0Sstevel@tonic-gate /* match above first...*/ 137*0Sstevel@tonic-gate "Hold-Auto-Forwarded-From:", FALSE, 138*0Sstevel@tonic-gate "Hold->To:", FALSE, 139*0Sstevel@tonic-gate "Hold-Received:", FALSE, 140*0Sstevel@tonic-gate "Continue:", FALSE, 141*0Sstevel@tonic-gate "Name-Value:", FALSE, 142*0Sstevel@tonic-gate }; 143*0Sstevel@tonic-gate char *help[] = { 144*0Sstevel@tonic-gate "?\t\tprint this help message\n", 145*0Sstevel@tonic-gate "#\t\tdisplay message number #\n", 146*0Sstevel@tonic-gate "-\t\tprint previous\n", 147*0Sstevel@tonic-gate "+\t\tnext (no delete)\n", 148*0Sstevel@tonic-gate "! cmd\t\texecute cmd\n", 149*0Sstevel@tonic-gate "<CR>\t\tnext (no delete)\n", 150*0Sstevel@tonic-gate "a\t\tposition at and read newly arrived mail\n", 151*0Sstevel@tonic-gate "d [#]\t\tdelete message # (default current message)\n", 152*0Sstevel@tonic-gate "dp\t\tdelete current message and print the next\n", 153*0Sstevel@tonic-gate "dq\t\tdelete current message and exit\n", 154*0Sstevel@tonic-gate "h a\t\tdisplay all headers\n", 155*0Sstevel@tonic-gate "h d\t\tdisplay headers of letters scheduled for deletion\n", 156*0Sstevel@tonic-gate "h [#]\t\tdisplay headers around # (default current message)\n", 157*0Sstevel@tonic-gate "m user \tmail (and delete) current message to user\n", 158*0Sstevel@tonic-gate "n\t\tnext (no delete)\n", 159*0Sstevel@tonic-gate "p\t\tprint (override any warnings of binary content)\n", 160*0Sstevel@tonic-gate "P\t\toverride default 'brief' mode and display ALL header lines\n", 161*0Sstevel@tonic-gate "q, ^D\t\tquit\n", 162*0Sstevel@tonic-gate "r [args]\treply to (and delete) current letter via mail [args]\n", 163*0Sstevel@tonic-gate "s [files]\tsave (and delete) current message (default mbox)\n", 164*0Sstevel@tonic-gate "u [#]\t\tundelete message # (default current message)\n", 165*0Sstevel@tonic-gate "w [files]\tsave (and delete) current message without header\n", 166*0Sstevel@tonic-gate "x\t\texit without changing mail\n", 167*0Sstevel@tonic-gate "y [files]\tsave (and delete) current message (default mbox)\n", 168*0Sstevel@tonic-gate 0 169*0Sstevel@tonic-gate }; 170*0Sstevel@tonic-gate char *hmbox; /* pointer to $HOME/mbox */ 171*0Sstevel@tonic-gate char *hmdead; /* pointer to $HOME/dead.letter */ 172*0Sstevel@tonic-gate char *home; /* pointer to $HOME */ 173*0Sstevel@tonic-gate time_t iop; 174*0Sstevel@tonic-gate int interactive = 0; /* 1 says user is interactive */ 175*0Sstevel@tonic-gate int ismail = TRUE; /* default to program=mail */ 176*0Sstevel@tonic-gate int deliverflag = FALSE; /* -d flag, skip sendmail 177*0Sstevel@tonic-gate * deliver directly to mailbox 178*0Sstevel@tonic-gate */ 179*0Sstevel@tonic-gate int fromflag = FALSE; /* -f from_user, set a user 180*0Sstevel@tonic-gate * when going into a mailbox 181*0Sstevel@tonic-gate */ 182*0Sstevel@tonic-gate int keepdbgfile; 183*0Sstevel@tonic-gate struct let let[MAXLET]; 184*0Sstevel@tonic-gate char *lettmp; /* pointer to tmp filename */ 185*0Sstevel@tonic-gate char lfil[MAXFILENAME]; 186*0Sstevel@tonic-gate char line[LSIZE]; /* holds a line of a letter in many places */ 187*0Sstevel@tonic-gate char *mailfile; /* pointer to mailfile */ 188*0Sstevel@tonic-gate char mailcnfg[] = MAILCNFG; /* configuration file */ 189*0Sstevel@tonic-gate char maildir[] = MAILDIR; /* directory for mail files */ 190*0Sstevel@tonic-gate gid_t mailgrp; /* numeric id of group 'mail' */ 191*0Sstevel@tonic-gate char mailsave[] = SAVEDIR; /* dir for save files */ 192*0Sstevel@tonic-gate char *mailsurr = MAILSURR; /* surrogate file name */ 193*0Sstevel@tonic-gate FILE *malf; /* File pointer for mailfile */ 194*0Sstevel@tonic-gate int maxerr = 0; /* largest value of error */ 195*0Sstevel@tonic-gate char mbox[] = "/mbox"; /* name for mbox */ 196*0Sstevel@tonic-gate uid_t mf_uid; /* uid of users mailfile */ 197*0Sstevel@tonic-gate gid_t mf_gid; /* gid of users mailfile */ 198*0Sstevel@tonic-gate char *msgtype; 199*0Sstevel@tonic-gate char my_name[1024]; /* user's name who invoked this command */ 200*0Sstevel@tonic-gate char from_user[1024]; /* user's name specified w/ -f when sending */ 201*0Sstevel@tonic-gate uid_t my_euid; /* user's euid */ 202*0Sstevel@tonic-gate gid_t my_egid; /* user's egid */ 203*0Sstevel@tonic-gate uid_t my_uid; /* user's uid */ 204*0Sstevel@tonic-gate gid_t my_gid; /* user's gid */ 205*0Sstevel@tonic-gate int nlet = 0; /* current number of letters in mailfile */ 206*0Sstevel@tonic-gate int onlet = 0; /* number of letters in mailfile at startup*/ 207*0Sstevel@tonic-gate int optcnt = 0; /* Number of options specified */ 208*0Sstevel@tonic-gate int orig_aff = 0; /* orig. msg. contained H_AFWDFROM lines */ 209*0Sstevel@tonic-gate int orig_dbglvl; /* argument to -x invocation option */ 210*0Sstevel@tonic-gate int orig_rcv = 0; /* orig. msg. contained H_RECEIVED lines */ 211*0Sstevel@tonic-gate int orig_tcopy = 0; /* orig. msg. contained H_TCOPY lines */ 212*0Sstevel@tonic-gate struct passwd *pwd; /* holds passwd entry for this user */ 213*0Sstevel@tonic-gate int pflg = 0; /* binary message display override flag */ 214*0Sstevel@tonic-gate int Pflg = 0; /* Selective display flag; 1 ==> display all */ 215*0Sstevel@tonic-gate char *program; /* program name */ 216*0Sstevel@tonic-gate int rcvbytecnt; /* Total bytes of Received: info in msg. */ 217*0Sstevel@tonic-gate int Drcvbytecnt; /* Hold rcvbytecnt when sending Delivery Notification */ 218*0Sstevel@tonic-gate char *recipname; /* full recipient name/address */ 219*0Sstevel@tonic-gate int replying = 0; /* 1 says we are replying to a letter */ 220*0Sstevel@tonic-gate char RFC822datestring[60];/* Date in RFC822 date format */ 221*0Sstevel@tonic-gate char Rpath[1024]; /* return path to sender of message */ 222*0Sstevel@tonic-gate char rmtmsg[] = " remote from %s\n"; 223*0Sstevel@tonic-gate char rtrnmsg[] = "***** UNDELIVERABLE MAIL sent to %s, being returned by %s *****\n"; 224*0Sstevel@tonic-gate int sav_errno; 225*0Sstevel@tonic-gate char savefile[MAXFILENAME]; /* holds filename of save file */ 226*0Sstevel@tonic-gate void (*saveint)(); 227*0Sstevel@tonic-gate /* Any header line prefixes listed here WILL be displayed in default mode */ 228*0Sstevel@tonic-gate /* If it's not here, it won't be shown. Can be overridden via 'P' command */ 229*0Sstevel@tonic-gate /* at ? prompt */ 230*0Sstevel@tonic-gate char *seldisp[] = { 231*0Sstevel@tonic-gate "Cc:", 232*0Sstevel@tonic-gate "Bcc:", 233*0Sstevel@tonic-gate "Paper-", 234*0Sstevel@tonic-gate "Phone:", 235*0Sstevel@tonic-gate "Message-", 236*0Sstevel@tonic-gate "Original-", 237*0Sstevel@tonic-gate "Confirming-", 238*0Sstevel@tonic-gate "Delivered-", 239*0Sstevel@tonic-gate "Deliverable-", 240*0Sstevel@tonic-gate "Not-", 241*0Sstevel@tonic-gate "En-Route-To:", 242*0Sstevel@tonic-gate 0 243*0Sstevel@tonic-gate }; 244*0Sstevel@tonic-gate int sending; /* TRUE==>sending mail; FALSE==>printing mail */ 245*0Sstevel@tonic-gate char m_sendto[1024]; 246*0Sstevel@tonic-gate jmp_buf sjbuf; 247*0Sstevel@tonic-gate int surg_rc = 0; /* exit code of surrogate command */ 248*0Sstevel@tonic-gate int surr_len = 0; 249*0Sstevel@tonic-gate char *SURRcmdstr = (char *)NULL; /* save in case of FAILURE */ 250*0Sstevel@tonic-gate FILE *SURRerrfile; /* stderr from surrogate in case of FAILURE */ 251*0Sstevel@tonic-gate char *thissys; /* Holds name of the system we are on */ 252*0Sstevel@tonic-gate FILE *tmpf; /* file pointer for temporary files */ 253*0Sstevel@tonic-gate mode_t umsave; 254*0Sstevel@tonic-gate struct utsname utsn; 255*0Sstevel@tonic-gate static struct utimbuf utims; 256*0Sstevel@tonic-gate struct utimbuf *utimep = &utims; 257*0Sstevel@tonic-gate char uval[1024]; 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate int init() 260*0Sstevel@tonic-gate { 261*0Sstevel@tonic-gate utims.actime = utims.modtime = -1; 262*0Sstevel@tonic-gate return (xsetenv(mailcnfg)); 263*0Sstevel@tonic-gate } 264