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