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