1 /* 2 ** SENDMAIL.H -- Global definitions for sendmail. 3 */ 4 5 6 7 # ifdef _DEFINE 8 # define EXTERN 9 # ifndef lint 10 static char SmailSccsId[] = "@(#)sendmail.h 3.75 07/05/82"; 11 # endif lint 12 # else _DEFINE 13 # define EXTERN extern 14 # endif _DEFINE 15 16 # include <stdio.h> 17 # include <ctype.h> 18 # include <setjmp.h> 19 # include "useful.h" 20 21 /* 22 ** Configuration constants. 23 ** There shouldn't be much need to change these.... 24 */ 25 26 # define MAXLINE 256 /* max line length */ 27 # define MAXNAME 128 /* max length of a name */ 28 # define MAXFIELD 2500 /* max total length of a hdr field */ 29 # define MAXPV 40 /* max # of parms to mailers */ 30 # define MAXHOP 30 /* max value of HopCount */ 31 # define MAXATOM 30 /* max atoms per address */ 32 # define MAXMAILERS 10 /* maximum mailers known to system */ 33 # define SPACESUB ('.'|0200) /* substitution for <lwsp> */ 34 35 extern char Arpa_Info[]; /* the message number for Arpanet info */ 36 /* 37 ** Address structure. 38 ** Addresses are stored internally in this structure. 39 */ 40 41 struct address 42 { 43 char *q_paddr; /* the printname for the address */ 44 char *q_user; /* user name */ 45 char *q_host; /* host name */ 46 struct mailer *q_mailer; /* mailer to use */ 47 short q_rmailer; /* real mailer (before mapping) */ 48 u_short q_flags; /* status flags, see below */ 49 short q_uid; /* user-id of receiver (if known) */ 50 short q_gid; /* group-id of receiver (if known) */ 51 char *q_home; /* home dir (local mailer only) */ 52 char *q_fullname; /* full name if known */ 53 struct address *q_next; /* chain */ 54 struct address *q_alias; /* address this results from */ 55 struct address *q_tchain; /* temporary use chain */ 56 time_t q_timeout; /* timeout for this address */ 57 }; 58 59 typedef struct address ADDRESS; 60 61 # define QDONTSEND 000001 /* don't send to this address */ 62 # define QBADADDR 000002 /* this address is verified bad */ 63 # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 64 # define QPRIMARY 000010 /* set from argv */ 65 # define QQUEUEUP 000020 /* queue for later transmission */ 66 /* 67 ** Mailer definition structure. 68 ** Every mailer known to the system is declared in this 69 ** structure. It defines the pathname of the mailer, some 70 ** flags associated with it, and the argument vector to 71 ** pass to it. The flags are defined in conf.c 72 ** 73 ** The argument vector is expanded before actual use. All 74 ** words except the first are passed through the macro 75 ** processor. 76 */ 77 78 struct mailer 79 { 80 char *m_name; /* symbolic name of this mailer */ 81 char *m_mailer; /* pathname of the mailer to use */ 82 u_long m_flags; /* status flags, see below */ 83 short m_badstat; /* the status code to use on unknown error */ 84 short m_mno; /* mailer number internally */ 85 char *m_from; /* pattern for From: header */ 86 char **m_argv; /* template argument vector */ 87 }; 88 89 typedef struct mailer MAILER; 90 91 /* bits for m_flags */ 92 # define M_FOPT 000000001L /* mailer takes picky -f flag */ 93 # define M_ROPT 000000002L /* mailer takes picky -r flag */ 94 # define M_QUIET 000000004L /* don't print error on bad status */ 95 # define M_RESTR 000000010L /* must be daemon to execute */ 96 # define M_NHDR 000000020L /* don't insert From line */ 97 # define M_LOCAL 000000040L /* delivery is to this host */ 98 # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 99 # define M_MUSER 000000200L /* can handle multiple users at once */ 100 # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 101 # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 102 # define M_MSGID 000002000L /* need Message-Id: field */ 103 # define M_RELRCPT 000004000L /* make recipient addresses relative */ 104 # define M_USR_UPPER 000010000L /* preserve user case distinction */ 105 # define M_HST_UPPER 000020000L /* preserve host case distinction */ 106 # define M_FULLNAME 000040000L /* want Full-Name field */ 107 # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 108 # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 109 # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 110 111 # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 112 113 EXTERN MAILER *Mailer[MAXMAILERS+1]; 114 115 EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 116 EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 117 /* 118 ** Header structure. 119 ** This structure is used internally to store header items. 120 */ 121 122 struct header 123 { 124 char *h_field; /* the name of the field */ 125 char *h_value; /* the value of that field */ 126 struct header *h_link; /* the next header */ 127 u_short h_flags; /* status bits, see below */ 128 u_long h_mflags; /* m_flags bits needed */ 129 }; 130 131 typedef struct header HDR; 132 133 /* 134 ** Header information structure. 135 ** Defined in conf.c, this struct declares the header fields 136 ** that have some magic meaning. 137 */ 138 139 struct hdrinfo 140 { 141 char *hi_field; /* the name of the field */ 142 u_short hi_flags; /* status bits, see below */ 143 u_short hi_mflags; /* m_flags needed for this field */ 144 }; 145 146 extern struct hdrinfo HdrInfo[]; 147 148 /* bits for h_flags and hi_flags */ 149 # define H_EOH 00001 /* this field terminates header */ 150 # define H_RCPT 00002 /* contains recipient addresses */ 151 # define H_DEFAULT 00004 /* if another value is found, drop this */ 152 # define H_USED 00010 /* indicates that this has been output */ 153 # define H_CHECK 00020 /* check h_mflags against m_flags */ 154 # define H_ACHECK 00040 /* ditto, but always (not just default) */ 155 # define H_FORCE 00100 /* force this field, even if default */ 156 # define H_ADDR 00200 /* this field contains addresses */ 157 /* 158 ** Envelope structure. 159 ** This structure defines the message itself. There is usually 160 ** only one of these -- for the message that we originally read 161 ** and which is our primary interest -- but other envelopes can 162 ** be generated during processing. For example, error messages 163 ** will have their own envelope. 164 */ 165 166 struct envelope 167 { 168 HDR *e_header; /* head of header list */ 169 long e_msgpriority; /* adjusted priority of this message */ 170 bool e_queueup; /* queue this message */ 171 bool e_oldstyle; /* use spaces (not commas) in hdrs */ 172 bool e_retreceipt; /* give a return receipt */ 173 bool e_sendreceipt; /* actually send a receipt back */ 174 char *e_origfrom; /* the From: line first read */ 175 char *e_to; /* the target person */ 176 ADDRESS e_from; /* the person it is from */ 177 ADDRESS *e_sendqueue; /* list of message recipients */ 178 ADDRESS *e_errorqueue; /* the queue for error responses */ 179 long e_msgsize; /* size of the message in bytes */ 180 short e_class; /* msg class (priority, junk, etc.) */ 181 int (*e_puthdr)(); /* function to put header of message */ 182 int (*e_putbody)(); /* function to put body of message */ 183 struct envelope *e_parent; /* the message this one encloses */ 184 char *e_df; /* location of temp file */ 185 char *e_macro[128]; /* macro definitions */ 186 }; 187 188 typedef struct envelope ENVELOPE; 189 190 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 191 /* 192 ** Work queue. 193 */ 194 195 struct work 196 { 197 char *w_name; /* name of control file */ 198 long w_pri; /* priority of message, see below */ 199 struct work *w_next; /* next in queue */ 200 }; 201 202 typedef struct work WORK; 203 204 EXTERN WORK *WorkQ; /* queue of things to be done */ 205 206 207 /* 208 ** Message priorities. 209 ** Priorities > 0 should be preemptive. 210 ** 211 ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 212 ** by the message priority and the amount of time the message 213 ** has been sitting around. Each priority point is worth 214 ** WKPRIFACT bytes of message, and each time we reprocess a 215 ** message the size gets reduced by WKTIMEFACT. 216 ** 217 ** The "class" is this number, unadjusted by the age or size of 218 ** this message. Classes with negative representations will have 219 ** error messages thrown away if they are not local. 220 */ 221 222 # define PRI_ALERT 50 223 # define PRI_QUICK 30 224 # define PRI_FIRSTCL 10 225 # define PRI_NORMAL 0 226 # define PRI_SECONDCL -10 227 # define PRI_THIRDCL -40 228 # define PRI_JUNK -100 229 230 # define WKPRIFACT 1800 /* bytes each pri point is worth */ 231 # define WKTIMEFACT 400 /* bytes each time unit is worth */ 232 /* 233 ** Rewrite rules. 234 */ 235 236 struct rewrite 237 { 238 char **r_lhs; /* pattern match */ 239 char **r_rhs; /* substitution value */ 240 struct rewrite *r_next;/* next in chain */ 241 }; 242 243 extern struct rewrite *RewriteRules[]; 244 245 # define MATCHANY '\020' /* match one or more tokens */ 246 # define MATCHONE '\021' /* match exactly one token */ 247 # define MATCHCLASS '\022' /* match one token in a class */ 248 # define MATCHREPL '\023' /* replacement on RHS for above */ 249 250 # define CANONNET '\025' /* canonical net, next token */ 251 # define CANONHOST '\026' /* canonical host, next token */ 252 # define CANONUSER '\027' /* canonical user, next N tokens */ 253 254 # define CONDIF '\030' /* conditional if-then */ 255 # define CONDELSE '\031' /* conditional else */ 256 # define CONDFI '\032' /* conditional fi */ 257 /* 258 ** Symbol table definitions 259 */ 260 261 struct symtab 262 { 263 char *s_name; /* name to be entered */ 264 char s_type; /* general type (see below) */ 265 struct symtab *s_next; /* pointer to next in chain */ 266 union 267 { 268 long sv_class; /* bit-map of word classes */ 269 ADDRESS *sv_addr; /* pointer to address header */ 270 MAILER *sv_mailer; /* pointer to mailer */ 271 char *sv_alias; /* alias */ 272 } s_value; 273 }; 274 275 typedef struct symtab STAB; 276 277 /* symbol types */ 278 # define ST_UNDEF 0 /* undefined type */ 279 # define ST_CLASS 1 /* class map */ 280 # define ST_ADDRESS 2 /* an address in parsed format */ 281 # define ST_MAILER 3 /* a mailer header */ 282 # define ST_ALIAS 4 /* an alias */ 283 284 # define s_class s_value.sv_class 285 # define s_address s_value.sv_addr 286 # define s_mailer s_value.sv_mailer 287 # define s_alias s_value.sv_alias 288 289 extern STAB *stab(); 290 291 /* opcodes to stab */ 292 # define ST_FIND 0 /* find entry */ 293 # define ST_ENTER 1 /* enter if not there */ 294 /* 295 ** Statistics structure. 296 */ 297 298 struct statistics 299 { 300 time_t stat_itime; /* file initialization time */ 301 short stat_size; /* size of this structure */ 302 long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 303 long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 304 long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 305 long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 306 }; 307 308 EXTERN struct statistics Stat; 309 extern long kbytes(); /* for _bf, _bt */ 310 /* 311 ** Operation modes 312 ** The default operation mode can be safely changed (except 313 ** that the default cannot be MD_DAEMON). 314 */ 315 316 EXTERN char Mode; /* operation mode, see below */ 317 318 #define MD_DELIVER 'a' /* collect and deliver */ 319 #define MD_FORK 'f' /* verify & fork before delivery */ 320 #define MD_QUEUE 'q' /* collect & queue, don't deliver */ 321 #define MD_DAEMON 'd' /* run as a daemon */ 322 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 323 324 #define MD_DEFAULT MD_DELIVER /* default operation mode */ 325 /* 326 ** Global variables. 327 */ 328 329 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 330 EXTERN bool MailBack; /* mail back response on error */ 331 EXTERN bool BerkNet; /* called from BerkNet */ 332 EXTERN bool WriteBack; /* write back response on error */ 333 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 334 EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 335 EXTERN bool MeToo; /* send to the sender also */ 336 EXTERN bool IgnrDot; /* don't let dot end messages */ 337 EXTERN bool SaveFrom; /* save leading "From" lines */ 338 EXTERN bool Verbose; /* set if blow-by-blow desired */ 339 EXTERN bool GrabTo; /* if set, get recipients from msg */ 340 EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 341 EXTERN bool NoReturn; /* don't return letter to sender */ 342 EXTERN bool Smtp; /* using SMTP over connection */ 343 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 344 EXTERN bool QueueRun; /* currently running message from the queue */ 345 EXTERN bool HoldErrs; /* only output errors to transcript */ 346 EXTERN bool ArpaMode; /* set if running arpanet protocol */ 347 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 348 EXTERN bool FatalErrors; /* set if fatal errors during processing */ 349 extern time_t TimeOut; /* time until timeout */ 350 EXTERN FILE *InChannel; /* input connection */ 351 EXTERN FILE *OutChannel; /* output connection */ 352 EXTERN FILE *TempFile; /* mail temp file */ 353 EXTERN FILE *Xscript; /* mail transcript file */ 354 EXTERN int RealUid; /* when Daemon, real uid of caller */ 355 EXTERN int RealGid; /* when Daemon, real gid of caller */ 356 extern int DefUid; /* default uid to run as */ 357 extern int DefGid; /* default gid to run as */ 358 EXTERN int OldUmask; /* umask when sendmail starts up */ 359 EXTERN int Debug; /* debugging level */ 360 EXTERN int Errors; /* set if errors (local to single pass) */ 361 EXTERN int ExitStat; /* exit status code */ 362 EXTERN int HopCount; /* hop count */ 363 EXTERN int AliasLevel; /* depth of aliasing */ 364 EXTERN int MotherPid; /* proc id of parent process */ 365 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 366 EXTERN char *HostName; /* name of this host for SMTP messages */ 367 EXTERN char *Transcript; /* the transcript file name */ 368 extern char *XcriptFile; /* template for Transcript */ 369 extern char *AliasFile; /* location of alias file */ 370 extern char *ConfFile; /* location of configuration file */ 371 extern char *StatFile; /* location of statistics summary */ 372 extern char *QueueDir; /* location of queue directory */ 373 EXTERN char *ControlFile; /* when queued, name of control file temp */ 374 EXTERN time_t CurTime; /* time of this message */ 375 EXTERN jmp_buf TickFrame; /* frame for clock ticks to jump to */ 376 extern int ReadTimeout; /* timeout on reads before clock ticks */ 377 378 379 # include <sysexits.h> 380 381 # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 382 383 384 /* useful functions */ 385 386 extern char *newstr(); 387 extern ADDRESS *parse(); 388 extern char *xalloc(); 389 extern bool sameaddr(); 390 extern FILE *dfopen(); 391