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.100 11/21/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 "conf.h" 20 # include "useful.h" 21 22 # ifdef LOG 23 # include <syslog.h> 24 # endif LOG 25 /* 26 ** Address structure. 27 ** Addresses are stored internally in this structure. 28 */ 29 30 struct address 31 { 32 char *q_paddr; /* the printname for the address */ 33 char *q_user; /* user name */ 34 char *q_host; /* host name */ 35 struct mailer *q_mailer; /* mailer to use */ 36 u_short q_flags; /* status flags, see below */ 37 short q_uid; /* user-id of receiver (if known) */ 38 short q_gid; /* group-id of receiver (if known) */ 39 char *q_home; /* home dir (local mailer only) */ 40 char *q_fullname; /* full name if known */ 41 struct address *q_next; /* chain */ 42 struct address *q_alias; /* address this results from */ 43 struct address *q_tchain; /* temporary use chain */ 44 time_t q_timeout; /* timeout for this address */ 45 }; 46 47 typedef struct address ADDRESS; 48 49 # define QDONTSEND 000001 /* don't send to this address */ 50 # define QBADADDR 000002 /* this address is verified bad */ 51 # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 52 # define QPRIMARY 000010 /* set from argv */ 53 # define QQUEUEUP 000020 /* queue for later transmission */ 54 /* 55 ** Mailer definition structure. 56 ** Every mailer known to the system is declared in this 57 ** structure. It defines the pathname of the mailer, some 58 ** flags associated with it, and the argument vector to 59 ** pass to it. The flags are defined in conf.c 60 ** 61 ** The argument vector is expanded before actual use. All 62 ** words except the first are passed through the macro 63 ** processor. 64 */ 65 66 struct mailer 67 { 68 char *m_name; /* symbolic name of this mailer */ 69 char *m_mailer; /* pathname of the mailer to use */ 70 u_long m_flags; /* status flags, see below */ 71 short m_badstat; /* the status code to use on unknown error */ 72 short m_mno; /* mailer number internally */ 73 char **m_argv; /* template argument vector */ 74 short m_s_rwset; /* rewriting set for sender addresses */ 75 short m_r_rwset; /* rewriting set for recipient addresses */ 76 }; 77 78 typedef struct mailer MAILER; 79 80 /* bits for m_flags */ 81 # define M_FOPT 000000001L /* mailer takes picky -f flag */ 82 # define M_ROPT 000000002L /* mailer takes picky -r flag */ 83 # define M_QUIET 000000004L /* don't print error on bad status */ 84 # define M_RESTR 000000010L /* must be daemon to execute */ 85 # define M_NHDR 000000020L /* don't insert From line */ 86 # define M_LOCAL 000000040L /* delivery is to this host */ 87 # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 88 # define M_MUSER 000000200L /* can handle multiple users at once */ 89 # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 90 # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 91 # define M_MSGID 000002000L /* need Message-Id: field */ 92 # define M_CANONICAL 000004000L /* make addresses canonical "u@dom" */ 93 # define M_USR_UPPER 000010000L /* preserve user case distinction */ 94 # define M_HST_UPPER 000020000L /* preserve host case distinction */ 95 # define M_FULLNAME 000040000L /* want Full-Name field */ 96 # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 97 # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 98 # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 99 # define M_INTERNAL 001000000L /* SMTP to another sendmail site */ 100 101 # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 102 103 EXTERN MAILER *Mailer[MAXMAILERS+1]; 104 105 EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 106 EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 107 /* 108 ** Header structure. 109 ** This structure is used internally to store header items. 110 */ 111 112 struct header 113 { 114 char *h_field; /* the name of the field */ 115 char *h_value; /* the value of that field */ 116 struct header *h_link; /* the next header */ 117 u_short h_flags; /* status bits, see below */ 118 u_long h_mflags; /* m_flags bits needed */ 119 }; 120 121 typedef struct header HDR; 122 123 /* 124 ** Header information structure. 125 ** Defined in conf.c, this struct declares the header fields 126 ** that have some magic meaning. 127 */ 128 129 struct hdrinfo 130 { 131 char *hi_field; /* the name of the field */ 132 u_short hi_flags; /* status bits, see below */ 133 }; 134 135 extern struct hdrinfo HdrInfo[]; 136 137 /* bits for h_flags and hi_flags */ 138 # define H_EOH 00001 /* this field terminates header */ 139 # define H_RCPT 00002 /* contains recipient addresses */ 140 # define H_DEFAULT 00004 /* if another value is found, drop this */ 141 # define H_USED 00010 /* indicates that this has been output */ 142 # define H_CHECK 00020 /* check h_mflags against m_flags */ 143 # define H_ACHECK 00040 /* ditto, but always (not just default) */ 144 # define H_FORCE 00100 /* force this field, even if default */ 145 # define H_TRACE 00200 /* this field contains trace information */ 146 # define H_FROM 00400 /* this is a from-type field */ 147 /* 148 ** Envelope structure. 149 ** This structure defines the message itself. There is usually 150 ** only one of these -- for the message that we originally read 151 ** and which is our primary interest -- but other envelopes can 152 ** be generated during processing. For example, error messages 153 ** will have their own envelope. 154 */ 155 156 struct envelope 157 { 158 HDR *e_header; /* head of header list */ 159 long e_msgpriority; /* adjusted priority of this message */ 160 time_t e_ctime; /* time message appeared in the queue */ 161 bool e_queueup; /* queue this message */ 162 bool e_dontqueue; /* override queueing */ 163 bool e_oldstyle; /* use spaces (not commas) in hdrs */ 164 bool e_sendreceipt; /* actually send a receipt back */ 165 char *e_to; /* the target person */ 166 char *e_receiptto; /* return receipt address */ 167 ADDRESS e_from; /* the person it is from */ 168 char **e_fromdomain; /* the domain part of the sender */ 169 ADDRESS *e_sendqueue; /* list of message recipients */ 170 ADDRESS *e_errorqueue; /* the queue for error responses */ 171 long e_msgsize; /* size of the message in bytes */ 172 short e_class; /* msg class (priority, junk, etc.) */ 173 int (*e_puthdr)(); /* function to put header of message */ 174 int (*e_putbody)(); /* function to put body of message */ 175 struct envelope *e_parent; /* the message this one encloses */ 176 char *e_df; /* location of temp file */ 177 char *e_qf; /* queue control file */ 178 char *e_id; /* code for this entry in queue */ 179 char *e_macro[128]; /* macro definitions */ 180 }; 181 182 typedef struct envelope ENVELOPE; 183 184 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 185 /* 186 ** Work queue. 187 */ 188 189 struct work 190 { 191 char *w_name; /* name of control file */ 192 long w_pri; /* priority of message, see below */ 193 struct work *w_next; /* next in queue */ 194 }; 195 196 typedef struct work WORK; 197 198 EXTERN WORK *WorkQ; /* queue of things to be done */ 199 200 201 /* 202 ** Message priorities. 203 ** Priorities > 0 should be preemptive. 204 ** 205 ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 206 ** by the message priority and the amount of time the message 207 ** has been sitting around. Each priority point is worth 208 ** WKPRIFACT bytes of message, and each time we reprocess a 209 ** message the size gets reduced by WKTIMEFACT. 210 ** 211 ** The "class" is this number, unadjusted by the age or size of 212 ** this message. Classes with negative representations will have 213 ** error messages thrown away if they are not local. 214 */ 215 216 struct priority 217 { 218 char *pri_name; /* external name of priority */ 219 int pri_val; /* internal value for same */ 220 }; 221 222 EXTERN struct priority Priorities[MAXPRIORITIES]; 223 EXTERN int NumPriorities; /* pointer into Priorities */ 224 225 # define WKPRIFACT 1800 /* bytes each pri point is worth */ 226 # define WKTIMEFACT 400 /* bytes each time unit is worth */ 227 /* 228 ** Rewrite rules. 229 */ 230 231 struct rewrite 232 { 233 char **r_lhs; /* pattern match */ 234 char **r_rhs; /* substitution value */ 235 struct rewrite *r_next;/* next in chain */ 236 }; 237 238 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 239 240 /* 241 ** Special characters in rewriting rules. 242 ** These are used internally only. 243 ** The COND* rules are actually used in macros rather than in 244 ** rewriting rules, but are given here because they 245 ** cannot conflict. 246 */ 247 248 /* left hand side items */ 249 # define MATCHZANY '\020' /* match zero or more tokens */ 250 # define MATCHANY '\021' /* match one or more tokens */ 251 # define MATCHONE '\022' /* match exactly one token */ 252 # define MATCHCLASS '\023' /* match one token in a class */ 253 # define MATCHREPL '\024' /* replacement on RHS for above */ 254 255 /* right hand side items */ 256 # define CANONNET '\025' /* canonical net, next token */ 257 # define CANONHOST '\026' /* canonical host, next token */ 258 # define CANONUSER '\027' /* canonical user, next N tokens */ 259 # define CALLSUBR '\030' /* call another rewriting set */ 260 261 /* conditionals in macros */ 262 # define CONDIF '\031' /* conditional if-then */ 263 # define CONDELSE '\032' /* conditional else */ 264 # define CONDFI '\033' /* conditional fi */ 265 /* 266 ** Symbol table definitions 267 */ 268 269 struct symtab 270 { 271 char *s_name; /* name to be entered */ 272 char s_type; /* general type (see below) */ 273 struct symtab *s_next; /* pointer to next in chain */ 274 union 275 { 276 long sv_class; /* bit-map of word classes */ 277 ADDRESS *sv_addr; /* pointer to address header */ 278 MAILER *sv_mailer; /* pointer to mailer */ 279 char *sv_alias; /* alias */ 280 } s_value; 281 }; 282 283 typedef struct symtab STAB; 284 285 /* symbol types */ 286 # define ST_UNDEF 0 /* undefined type */ 287 # define ST_CLASS 1 /* class map */ 288 # define ST_ADDRESS 2 /* an address in parsed format */ 289 # define ST_MAILER 3 /* a mailer header */ 290 # define ST_ALIAS 4 /* an alias */ 291 292 # define s_class s_value.sv_class 293 # define s_address s_value.sv_addr 294 # define s_mailer s_value.sv_mailer 295 # define s_alias s_value.sv_alias 296 297 extern STAB *stab(); 298 299 /* opcodes to stab */ 300 # define ST_FIND 0 /* find entry */ 301 # define ST_ENTER 1 /* enter if not there */ 302 /* 303 ** STRUCT EVENT -- event queue. 304 ** 305 ** Maintained in sorted order. 306 ** 307 ** We store the pid of the process that set this event to insure 308 ** that when we fork we will not take events intended for the parent. 309 */ 310 311 struct event 312 { 313 time_t ev_time; /* time of the function call */ 314 int (*ev_func)(); /* function to call */ 315 int ev_arg; /* argument to ev_func */ 316 int ev_pid; /* pid that set this event */ 317 struct event *ev_link; /* link to next item */ 318 }; 319 320 typedef struct event EVENT; 321 322 EXTERN EVENT *EventQueue; /* head of event queue */ 323 /* 324 ** Statistics structure. 325 */ 326 327 struct statistics 328 { 329 time_t stat_itime; /* file initialization time */ 330 short stat_size; /* size of this structure */ 331 long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 332 long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 333 long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 334 long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 335 }; 336 337 EXTERN struct statistics Stat; 338 extern long kbytes(); /* for _bf, _bt */ 339 /* 340 ** Operation and send modes 341 ** 342 ** The operation mode describes the basic operation of sendmail. 343 ** This can be set from the command line, and is "send mail" by 344 ** default. 345 ** 346 ** The send mode tells how to send mail. It can be set in the 347 ** configuration file. It's setting determines how quickly the 348 ** mail will be delivered versus the load on your system. If the 349 ** -v (verbose) flag is given, it will be forced to SM_DELIVER 350 ** mode. 351 ** 352 ** The default send mode can be safely changed. 353 */ 354 355 EXTERN char OpMode; /* operation mode, see below */ 356 357 #define MD_DELIVER 'm' /* be a mail sender */ 358 #define MD_ARPAFTP 'a' /* old-style arpanet protocols */ 359 #define MD_SMTP 's' /* run SMTP on standard input */ 360 #define MD_DAEMON 'd' /* run as a daemon */ 361 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 362 #define MD_TEST 't' /* test mode: resolve addrs only */ 363 #define MD_INITALIAS 'i' /* initialize alias database */ 364 #define MD_PRINT 'p' /* print the queue */ 365 #define MD_FREEZE 'z' /* freeze the configuration file */ 366 367 368 EXTERN char SendMode; /* send mode, see below */ 369 370 #define SM_DELIVER 'i' /* interactive delivery */ 371 #define SM_QUICKD 'j' /* deliver w/o queueing */ 372 #define SM_FORK 'b' /* deliver in background */ 373 #define SM_QUEUE 'q' /* queue, don't deliver */ 374 #define SM_VERIFY 'v' /* verify only (used internally) */ 375 /* 376 ** Global variables. 377 */ 378 379 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 380 EXTERN bool MailBack; /* mail back response on error */ 381 EXTERN bool BerkNet; /* called from BerkNet */ 382 EXTERN bool WriteBack; /* write back response on error */ 383 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 384 EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 385 EXTERN bool MeToo; /* send to the sender also */ 386 EXTERN bool IgnrDot; /* don't let dot end messages */ 387 EXTERN bool SaveFrom; /* save leading "From" lines */ 388 EXTERN bool Verbose; /* set if blow-by-blow desired */ 389 EXTERN bool GrabTo; /* if set, get recipients from msg */ 390 EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 391 EXTERN bool NoReturn; /* don't return letter to sender */ 392 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 393 EXTERN bool QueueRun; /* currently running message from the queue */ 394 EXTERN bool HoldErrs; /* only output errors to transcript */ 395 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 396 EXTERN bool FatalErrors; /* set if fatal errors during processing */ 397 EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 398 EXTERN bool SafeAlias; /* alias file must have "@:@" to be complete */ 399 EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 400 EXTERN time_t TimeOut; /* time until timeout */ 401 EXTERN FILE *InChannel; /* input connection */ 402 EXTERN FILE *OutChannel; /* output connection */ 403 EXTERN FILE *TempFile; /* mail temp file */ 404 EXTERN FILE *Xscript; /* mail transcript file */ 405 EXTERN int RealUid; /* when Daemon, real uid of caller */ 406 EXTERN int RealGid; /* when Daemon, real gid of caller */ 407 EXTERN int DefUid; /* default uid to run as */ 408 EXTERN int DefGid; /* default gid to run as */ 409 EXTERN int OldUmask; /* umask when sendmail starts up */ 410 EXTERN int Errors; /* set if errors (local to single pass) */ 411 EXTERN int ExitStat; /* exit status code */ 412 EXTERN int HopCount; /* hop count */ 413 EXTERN int AliasLevel; /* depth of aliasing */ 414 EXTERN int MotherPid; /* proc id of parent process */ 415 EXTERN int LineNumber; /* line number in current input */ 416 EXTERN int ReadTimeout; /* timeout on reads */ 417 EXTERN int LogLevel; /* level of logging to perform */ 418 EXTERN int FileMode; /* mode on files */ 419 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 420 EXTERN char *HostName; /* name of this host for SMTP messages */ 421 EXTERN char *Transcript; /* the transcript file name */ 422 EXTERN char *AliasFile; /* location of alias file */ 423 EXTERN char *HelpFile; /* location of SMTP help file */ 424 EXTERN char *StatFile; /* location of statistics summary */ 425 EXTERN char *QueueDir; /* location of queue directory */ 426 EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */ 427 EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 428 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 429 extern char *ConfFile; /* location of configuration file [conf.c] */ 430 extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 431 extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */ 432 extern char SpaceSub; /* substitution for <lwsp> [conf.c] */ 433 /* 434 ** Trace information 435 */ 436 437 /* trace vector and macros for debugging flags */ 438 EXTERN u_char tTdvect[100]; 439 # define tTd(flag, level) (tTdvect[flag] >= level) 440 # define tTdlevel(flag) (tTdvect[flag]) 441 /* 442 ** Miscellaneous information. 443 */ 444 445 # include <sysexits.h> 446 447 # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 448 449 450 /* useful functions */ 451 452 extern char *newstr(); 453 extern ADDRESS *parse(); 454 extern char *xalloc(); 455 extern bool sameaddr(); 456 extern FILE *dfopen(); 457 extern EVENT *setevent(); 458 extern char *sfgets(); 459 extern char *queuename(); 460 extern time_t curtime(); 461