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