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.93 10/28/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 ** Configuration constants. 26 ** There shouldn't be much need to change these.... 27 */ 28 29 # define MAXLINE 256 /* max line length */ 30 # define MAXNAME 128 /* max length of a name */ 31 # define MAXFIELD 2500 /* max total length of a hdr field */ 32 # define MAXPV 40 /* max # of parms to mailers */ 33 # define MAXHOP 30 /* max value of HopCount */ 34 # define MAXATOM 100 /* max atoms per address */ 35 # define MAXMAILERS 25 /* maximum mailers known to system */ 36 # define MAXRWSETS 30 /* max # of sets of rewriting rules */ 37 # define MAXPRIORITIES 25 /* max values for Precedence: field */ 38 # define MAXTRUST 30 /* maximum number of trusted users */ 39 # define SPACESUB ('.'|0200) /* substitution for <lwsp> */ 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 u_short q_flags; /* status flags, see below */ 52 short q_uid; /* user-id of receiver (if known) */ 53 short q_gid; /* group-id of receiver (if known) */ 54 char *q_home; /* home dir (local mailer only) */ 55 char *q_fullname; /* full name if known */ 56 struct address *q_next; /* chain */ 57 struct address *q_alias; /* address this results from */ 58 struct address *q_tchain; /* temporary use chain */ 59 time_t q_timeout; /* timeout for this address */ 60 }; 61 62 typedef struct address ADDRESS; 63 64 # define QDONTSEND 000001 /* don't send to this address */ 65 # define QBADADDR 000002 /* this address is verified bad */ 66 # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 67 # define QPRIMARY 000010 /* set from argv */ 68 # define QQUEUEUP 000020 /* queue for later transmission */ 69 /* 70 ** Mailer definition structure. 71 ** Every mailer known to the system is declared in this 72 ** structure. It defines the pathname of the mailer, some 73 ** flags associated with it, and the argument vector to 74 ** pass to it. The flags are defined in conf.c 75 ** 76 ** The argument vector is expanded before actual use. All 77 ** words except the first are passed through the macro 78 ** processor. 79 */ 80 81 struct mailer 82 { 83 char *m_name; /* symbolic name of this mailer */ 84 char *m_mailer; /* pathname of the mailer to use */ 85 u_long m_flags; /* status flags, see below */ 86 short m_badstat; /* the status code to use on unknown error */ 87 short m_mno; /* mailer number internally */ 88 char **m_argv; /* template argument vector */ 89 short m_s_rwset; /* rewriting set for sender addresses */ 90 short m_r_rwset; /* rewriting set for recipient addresses */ 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_CANONICAL 000004000L /* make addresses canonical "u@dom" */ 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_TRACE 00200 /* this field contains trace information */ 161 # define H_FROM 00400 /* this is a from-type field */ 162 /* 163 ** Envelope structure. 164 ** This structure defines the message itself. There is usually 165 ** only one of these -- for the message that we originally read 166 ** and which is our primary interest -- but other envelopes can 167 ** be generated during processing. For example, error messages 168 ** will have their own envelope. 169 */ 170 171 struct envelope 172 { 173 HDR *e_header; /* head of header list */ 174 long e_msgpriority; /* adjusted priority of this message */ 175 time_t e_ctime; /* time message appeared in the queue */ 176 bool e_queueup; /* queue this message */ 177 bool e_dontqueue; /* override queueing */ 178 bool e_oldstyle; /* use spaces (not commas) in hdrs */ 179 bool e_sendreceipt; /* actually send a receipt back */ 180 char *e_to; /* the target person */ 181 char *e_receiptto; /* return receipt address */ 182 ADDRESS e_from; /* the person it is from */ 183 char **e_fromdomain; /* the domain part of the sender */ 184 ADDRESS *e_sendqueue; /* list of message recipients */ 185 ADDRESS *e_errorqueue; /* the queue for error responses */ 186 long e_msgsize; /* size of the message in bytes */ 187 short e_class; /* msg class (priority, junk, etc.) */ 188 int (*e_puthdr)(); /* function to put header of message */ 189 int (*e_putbody)(); /* function to put body of message */ 190 struct envelope *e_parent; /* the message this one encloses */ 191 char *e_df; /* location of temp file */ 192 char *e_qf; /* queue control file */ 193 char *e_id; /* code for this entry in queue */ 194 char *e_macro[128]; /* macro definitions */ 195 }; 196 197 typedef struct envelope ENVELOPE; 198 199 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 200 /* 201 ** Work queue. 202 */ 203 204 struct work 205 { 206 char *w_name; /* name of control file */ 207 long w_pri; /* priority of message, see below */ 208 struct work *w_next; /* next in queue */ 209 }; 210 211 typedef struct work WORK; 212 213 EXTERN WORK *WorkQ; /* queue of things to be done */ 214 215 216 /* 217 ** Message priorities. 218 ** Priorities > 0 should be preemptive. 219 ** 220 ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 221 ** by the message priority and the amount of time the message 222 ** has been sitting around. Each priority point is worth 223 ** WKPRIFACT bytes of message, and each time we reprocess a 224 ** message the size gets reduced by WKTIMEFACT. 225 ** 226 ** The "class" is this number, unadjusted by the age or size of 227 ** this message. Classes with negative representations will have 228 ** error messages thrown away if they are not local. 229 */ 230 231 struct priority 232 { 233 char *pri_name; /* external name of priority */ 234 int pri_val; /* internal value for same */ 235 }; 236 237 EXTERN struct priority Priorities[MAXPRIORITIES]; 238 EXTERN int NumPriorities; /* pointer into Priorities */ 239 240 # define WKPRIFACT 1800 /* bytes each pri point is worth */ 241 # define WKTIMEFACT 400 /* bytes each time unit is worth */ 242 /* 243 ** Rewrite rules. 244 */ 245 246 struct rewrite 247 { 248 char **r_lhs; /* pattern match */ 249 char **r_rhs; /* substitution value */ 250 struct rewrite *r_next;/* next in chain */ 251 }; 252 253 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 254 255 /* 256 ** Special characters in rewriting rules. 257 ** These are used internally only. 258 ** The COND* rules are actually used in macros rather than in 259 ** rewriting rules, but are given here because they 260 ** cannot conflict. 261 */ 262 263 /* left hand side items */ 264 # define MATCHZANY '\020' /* match zero or more tokens */ 265 # define MATCHANY '\021' /* match one or more tokens */ 266 # define MATCHONE '\022' /* match exactly one token */ 267 # define MATCHCLASS '\023' /* match one token in a class */ 268 # define MATCHREPL '\024' /* replacement on RHS for above */ 269 270 /* right hand side items */ 271 # define CANONNET '\025' /* canonical net, next token */ 272 # define CANONHOST '\026' /* canonical host, next token */ 273 # define CANONUSER '\027' /* canonical user, next N tokens */ 274 # define CALLSUBR '\030' /* call another rewriting set */ 275 276 /* conditionals in macros */ 277 # define CONDIF '\031' /* conditional if-then */ 278 # define CONDELSE '\032' /* conditional else */ 279 # define CONDFI '\033' /* conditional fi */ 280 /* 281 ** Symbol table definitions 282 */ 283 284 struct symtab 285 { 286 char *s_name; /* name to be entered */ 287 char s_type; /* general type (see below) */ 288 struct symtab *s_next; /* pointer to next in chain */ 289 union 290 { 291 long sv_class; /* bit-map of word classes */ 292 ADDRESS *sv_addr; /* pointer to address header */ 293 MAILER *sv_mailer; /* pointer to mailer */ 294 char *sv_alias; /* alias */ 295 } s_value; 296 }; 297 298 typedef struct symtab STAB; 299 300 /* symbol types */ 301 # define ST_UNDEF 0 /* undefined type */ 302 # define ST_CLASS 1 /* class map */ 303 # define ST_ADDRESS 2 /* an address in parsed format */ 304 # define ST_MAILER 3 /* a mailer header */ 305 # define ST_ALIAS 4 /* an alias */ 306 307 # define s_class s_value.sv_class 308 # define s_address s_value.sv_addr 309 # define s_mailer s_value.sv_mailer 310 # define s_alias s_value.sv_alias 311 312 extern STAB *stab(); 313 314 /* opcodes to stab */ 315 # define ST_FIND 0 /* find entry */ 316 # define ST_ENTER 1 /* enter if not there */ 317 /* 318 ** STRUCT EVENT -- event queue. 319 ** 320 ** Maintained in sorted order. 321 ** 322 ** We store the pid of the process that set this event to insure 323 ** that when we fork we will not take events intended for the parent. 324 */ 325 326 struct event 327 { 328 time_t ev_time; /* time of the function call */ 329 int (*ev_func)(); /* function to call */ 330 int ev_arg; /* argument to ev_func */ 331 int ev_pid; /* pid that set this event */ 332 struct event *ev_link; /* link to next item */ 333 }; 334 335 typedef struct event EVENT; 336 337 EXTERN EVENT *EventQueue; /* head of event queue */ 338 /* 339 ** Statistics structure. 340 */ 341 342 struct statistics 343 { 344 time_t stat_itime; /* file initialization time */ 345 short stat_size; /* size of this structure */ 346 long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 347 long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 348 long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 349 long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 350 }; 351 352 EXTERN struct statistics Stat; 353 extern long kbytes(); /* for _bf, _bt */ 354 /* 355 ** Operation modes 356 ** The default operation mode can be safely changed (except 357 ** that the default cannot be MD_DAEMON). 358 */ 359 360 EXTERN char Mode; /* operation mode, see below */ 361 362 #define MD_DELIVER 'a' /* collect and deliver */ 363 #define MD_FORK 'f' /* verify & fork before delivery */ 364 #define MD_QUEUE 'q' /* collect & queue, don't deliver */ 365 #define MD_DAEMON 'd' /* run as a daemon */ 366 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 367 #define MD_TEST 't' /* test mode: resolve addrs only */ 368 369 #define MD_DEFAULT MD_DELIVER /* default operation mode */ 370 /* 371 ** Global variables. 372 */ 373 374 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 375 EXTERN bool MailBack; /* mail back response on error */ 376 EXTERN bool BerkNet; /* called from BerkNet */ 377 EXTERN bool WriteBack; /* write back response on error */ 378 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 379 EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 380 EXTERN bool MeToo; /* send to the sender also */ 381 EXTERN bool IgnrDot; /* don't let dot end messages */ 382 EXTERN bool SaveFrom; /* save leading "From" lines */ 383 EXTERN bool Verbose; /* set if blow-by-blow desired */ 384 EXTERN bool GrabTo; /* if set, get recipients from msg */ 385 EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 386 EXTERN bool NoReturn; /* don't return letter to sender */ 387 EXTERN bool Smtp; /* using SMTP over connection */ 388 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 389 EXTERN bool QueueRun; /* currently running message from the queue */ 390 EXTERN bool HoldErrs; /* only output errors to transcript */ 391 EXTERN bool ArpaMode; /* set if running arpanet protocol */ 392 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 393 EXTERN bool FatalErrors; /* set if fatal errors during processing */ 394 EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 395 EXTERN bool SafeAlias; /* alias file must have "@:@" to be complete */ 396 EXTERN time_t TimeOut; /* time until timeout */ 397 EXTERN FILE *InChannel; /* input connection */ 398 EXTERN FILE *OutChannel; /* output connection */ 399 EXTERN FILE *TempFile; /* mail temp file */ 400 EXTERN FILE *Xscript; /* mail transcript file */ 401 EXTERN int RealUid; /* when Daemon, real uid of caller */ 402 EXTERN int RealGid; /* when Daemon, real gid of caller */ 403 EXTERN int DefUid; /* default uid to run as */ 404 EXTERN int DefGid; /* default gid to run as */ 405 EXTERN int OldUmask; /* umask when sendmail starts up */ 406 EXTERN int Errors; /* set if errors (local to single pass) */ 407 EXTERN int ExitStat; /* exit status code */ 408 EXTERN int HopCount; /* hop count */ 409 EXTERN int AliasLevel; /* depth of aliasing */ 410 EXTERN int MotherPid; /* proc id of parent process */ 411 EXTERN int LineNumber; /* line number in current input */ 412 EXTERN int ReadTimeout; /* timeout on reads */ 413 EXTERN int LogLevel; /* level of logging to perform */ 414 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 415 EXTERN char *HostName; /* name of this host for SMTP messages */ 416 EXTERN char *Transcript; /* the transcript file name */ 417 EXTERN char *AliasFile; /* location of alias file */ 418 EXTERN char *HelpFile; /* location of SMTP help file */ 419 EXTERN char *StatFile; /* location of statistics summary */ 420 EXTERN char *QueueDir; /* location of queue directory */ 421 EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */ 422 EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 423 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 424 extern char *XcriptFile; /* template for Transcript [conf.c] */ 425 extern char *ConfFile; /* location of configuration file [conf.c] */ 426 extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */ 427 /* 428 ** Trace information 429 */ 430 431 /* trace vector and macros for debugging flags */ 432 EXTERN u_char tTdvect[100]; 433 # define tTd(flag, level) (tTdvect[flag] >= level) 434 # define tTdlevel(flag) (tTdvect[flag]) 435 /* 436 ** Miscellaneous information. 437 */ 438 439 # include <sysexits.h> 440 441 # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 442 443 444 /* useful functions */ 445 446 extern char *newstr(); 447 extern ADDRESS *parse(); 448 extern char *xalloc(); 449 extern bool sameaddr(); 450 extern FILE *dfopen(); 451 extern EVENT *setevent(); 452 extern char *sfgets(); 453 extern char *queuename(); 454 extern time_t curtime(); 455