Annotation of 42BSD/usr.lib/sendmail/src/sendmail.h, revision 1.1.1.1

1.1       root        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 4.2             8/28/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: #define EF_RESENT      000400          /* this message is being forwarded */
                    220: 
                    221: EXTERN ENVELOPE        *CurEnv;        /* envelope currently being processed */
                    222: /*
                    223: **  Message priorities.
                    224: **     Priorities > 0 should be preemptive.
                    225: **
                    226: **     CurEnv->e_msgpriority is the number of bytes in the message adjusted
                    227: **     by the message priority and the amount of time the message
                    228: **     has been sitting around.  Each priority point is worth
                    229: **     WKPRIFACT bytes of message, and each time we reprocess a
                    230: **     message the size gets reduced by WKTIMEFACT.
                    231: **
                    232: **     WKTIMEFACT is negative since jobs that fail once have a high
                    233: **     probability of failing again.  Making it negative tends to force
                    234: **     them to the back rather than the front of the queue, where they
                    235: **     only clog things.  Thanks go to Jay Lepreau at Utah for pointing
                    236: **     out the error in my thinking.
                    237: **
                    238: **     The "class" is this number, unadjusted by the age or size of
                    239: **     this message.  Classes with negative representations will have
                    240: **     error messages thrown away if they are not local.
                    241: */
                    242: 
                    243: struct priority
                    244: {
                    245:        char    *pri_name;      /* external name of priority */
                    246:        int     pri_val;        /* internal value for same */
                    247: };
                    248: 
                    249: EXTERN struct priority Priorities[MAXPRIORITIES];
                    250: EXTERN int             NumPriorities;  /* pointer into Priorities */
                    251: 
                    252: # define WKPRIFACT     1800            /* bytes each pri point is worth */
                    253: # define WKTIMEFACT    (-600)          /* bytes each reprocessing is worth */
                    254: /*
                    255: **  Rewrite rules.
                    256: */
                    257: 
                    258: struct rewrite
                    259: {
                    260:        char    **r_lhs;        /* pattern match */
                    261:        char    **r_rhs;        /* substitution value */
                    262:        struct rewrite  *r_next;/* next in chain */
                    263: };
                    264: 
                    265: EXTERN struct rewrite  *RewriteRules[MAXRWSETS];
                    266: 
                    267: /*
                    268: **  Special characters in rewriting rules.
                    269: **     These are used internally only.
                    270: **     The COND* rules are actually used in macros rather than in
                    271: **             rewriting rules, but are given here because they
                    272: **             cannot conflict.
                    273: */
                    274: 
                    275: /* left hand side items */
                    276: # define MATCHZANY     '\020'  /* match zero or more tokens */
                    277: # define MATCHANY      '\021'  /* match one or more tokens */
                    278: # define MATCHONE      '\022'  /* match exactly one token */
                    279: # define MATCHCLASS    '\023'  /* match one token in a class */
                    280: # define MATCHNCLASS   '\034'  /* match anything not in class */
                    281: # define MATCHREPL     '\024'  /* replacement on RHS for above */
                    282: 
                    283: /* right hand side items */
                    284: # define CANONNET      '\025'  /* canonical net, next token */
                    285: # define CANONHOST     '\026'  /* canonical host, next token */
                    286: # define CANONUSER     '\027'  /* canonical user, next N tokens */
                    287: # define CALLSUBR      '\030'  /* call another rewriting set */
                    288: 
                    289: /* conditionals in macros */
                    290: # define CONDIF                '\031'  /* conditional if-then */
                    291: # define CONDELSE      '\032'  /* conditional else */
                    292: # define CONDFI                '\033'  /* conditional fi */
                    293: /*
                    294: **  Symbol table definitions
                    295: */
                    296: 
                    297: struct symtab
                    298: {
                    299:        char            *s_name;        /* name to be entered */
                    300:        char            s_type;         /* general type (see below) */
                    301:        struct symtab   *s_next;        /* pointer to next in chain */
                    302:        union
                    303:        {
                    304:                BITMAP  sv_class;       /* bit-map of word classes */
                    305:                ADDRESS *sv_addr;       /* pointer to address header */
                    306:                MAILER  *sv_mailer;     /* pointer to mailer */
                    307:                char    *sv_alias;      /* alias */
                    308:        }       s_value;
                    309: };
                    310: 
                    311: typedef struct symtab  STAB;
                    312: 
                    313: /* symbol types */
                    314: # define ST_UNDEF      0       /* undefined type */
                    315: # define ST_CLASS      1       /* class map */
                    316: # define ST_ADDRESS    2       /* an address in parsed format */
                    317: # define ST_MAILER     3       /* a mailer header */
                    318: # define ST_ALIAS      4       /* an alias */
                    319: 
                    320: # define s_class       s_value.sv_class
                    321: # define s_address     s_value.sv_addr
                    322: # define s_mailer      s_value.sv_mailer
                    323: # define s_alias       s_value.sv_alias
                    324: 
                    325: extern STAB    *stab();
                    326: 
                    327: /* opcodes to stab */
                    328: # define ST_FIND       0       /* find entry */
                    329: # define ST_ENTER      1       /* enter if not there */
                    330: /*
                    331: **  STRUCT EVENT -- event queue.
                    332: **
                    333: **     Maintained in sorted order.
                    334: **
                    335: **     We store the pid of the process that set this event to insure
                    336: **     that when we fork we will not take events intended for the parent.
                    337: */
                    338: 
                    339: struct event
                    340: {
                    341:        time_t          ev_time;        /* time of the function call */
                    342:        int             (*ev_func)();   /* function to call */
                    343:        int             ev_arg;         /* argument to ev_func */
                    344:        int             ev_pid;         /* pid that set this event */
                    345:        struct event    *ev_link;       /* link to next item */
                    346: };
                    347: 
                    348: typedef struct event   EVENT;
                    349: 
                    350: EXTERN EVENT   *EventQueue;            /* head of event queue */
                    351: /*
                    352: **  Operation, send, and error modes
                    353: **
                    354: **     The operation mode describes the basic operation of sendmail.
                    355: **     This can be set from the command line, and is "send mail" by
                    356: **     default.
                    357: **
                    358: **     The send mode tells how to send mail.  It can be set in the
                    359: **     configuration file.  It's setting determines how quickly the
                    360: **     mail will be delivered versus the load on your system.  If the
                    361: **     -v (verbose) flag is given, it will be forced to SM_DELIVER
                    362: **     mode.
                    363: **
                    364: **     The error mode tells how to return errors.
                    365: */
                    366: 
                    367: EXTERN char    OpMode;         /* operation mode, see below */
                    368: 
                    369: #define MD_DELIVER     'm'             /* be a mail sender */
                    370: #define MD_ARPAFTP     'a'             /* old-style arpanet protocols */
                    371: #define MD_SMTP                's'             /* run SMTP on standard input */
                    372: #define MD_DAEMON      'd'             /* run as a daemon */
                    373: #define MD_VERIFY      'v'             /* verify: don't collect or deliver */
                    374: #define MD_TEST                't'             /* test mode: resolve addrs only */
                    375: #define MD_INITALIAS   'i'             /* initialize alias database */
                    376: #define MD_PRINT       'p'             /* print the queue */
                    377: #define MD_FREEZE      'z'             /* freeze the configuration file */
                    378: 
                    379: 
                    380: EXTERN char    SendMode;       /* send mode, see below */
                    381: 
                    382: #define SM_DELIVER     'i'             /* interactive delivery */
                    383: #define SM_QUICKD      'j'             /* deliver w/o queueing */
                    384: #define SM_FORK                'b'             /* deliver in background */
                    385: #define SM_QUEUE       'q'             /* queue, don't deliver */
                    386: #define SM_VERIFY      'v'             /* verify only (used internally) */
                    387: 
                    388: /* used only as a parameter to sendall */
                    389: #define SM_DEFAULT     '\0'            /* unspecified, use SendMode */
                    390: 
                    391: 
                    392: EXTERN char    ErrorMode;      /* error mode, see below */
                    393: 
                    394: #define EM_PRINT       'p'             /* print errors */
                    395: #define EM_MAIL                'm'             /* mail back errors */
                    396: #define EM_WRITE       'w'             /* write back errors */
                    397: #define EM_BERKNET     'e'             /* special berknet processing */
                    398: #define EM_QUIET       'q'             /* don't print messages (stat only) */
                    399: /*
                    400: **  Global variables.
                    401: */
                    402: 
                    403: EXTERN bool    FromFlag;       /* if set, "From" person is explicit */
                    404: EXTERN bool    NoAlias;        /* if set, don't do any aliasing */
                    405: EXTERN bool    ForceMail;      /* if set, mail even if already got a copy */
                    406: EXTERN bool    MeToo;          /* send to the sender also */
                    407: EXTERN bool    IgnrDot;        /* don't let dot end messages */
                    408: EXTERN bool    SaveFrom;       /* save leading "From" lines */
                    409: EXTERN bool    Verbose;        /* set if blow-by-blow desired */
                    410: EXTERN bool    GrabTo;         /* if set, get recipients from msg */
                    411: EXTERN bool    NoReturn;       /* don't return letter to sender */
                    412: EXTERN bool    SuprErrs;       /* set if we are suppressing errors */
                    413: EXTERN bool    QueueRun;       /* currently running message from the queue */
                    414: EXTERN bool    HoldErrs;       /* only output errors to transcript */
                    415: EXTERN bool    NoConnect;      /* don't connect to non-local mailers */
                    416: EXTERN bool    SuperSafe;      /* be extra careful, even if expensive */
                    417: EXTERN bool    SafeAlias;      /* alias file must have "@:@" to be complete */
                    418: EXTERN bool    AutoRebuild;    /* auto-rebuild the alias database as needed */
                    419: EXTERN time_t  TimeOut;        /* time until timeout */
                    420: EXTERN FILE    *InChannel;     /* input connection */
                    421: EXTERN FILE    *OutChannel;    /* output connection */
                    422: EXTERN int     RealUid;        /* when Daemon, real uid of caller */
                    423: EXTERN int     RealGid;        /* when Daemon, real gid of caller */
                    424: EXTERN int     DefUid;         /* default uid to run as */
                    425: EXTERN int     DefGid;         /* default gid to run as */
                    426: EXTERN int     OldUmask;       /* umask when sendmail starts up */
                    427: EXTERN int     Errors;         /* set if errors (local to single pass) */
                    428: EXTERN int     ExitStat;       /* exit status code */
                    429: EXTERN int     AliasLevel;     /* depth of aliasing */
                    430: EXTERN int     MotherPid;      /* proc id of parent process */
                    431: EXTERN int     LineNumber;     /* line number in current input */
                    432: EXTERN int     ReadTimeout;    /* timeout on reads */
                    433: EXTERN int     LogLevel;       /* level of logging to perform */
                    434: EXTERN int     FileMode;       /* mode on files */
                    435: EXTERN time_t  QueueIntvl;     /* intervals between running the queue */
                    436: EXTERN char    *HostName;      /* name of this host for SMTP messages */
                    437: EXTERN char    *AliasFile;     /* location of alias file */
                    438: EXTERN char    *HelpFile;      /* location of SMTP help file */
                    439: EXTERN char    *StatFile;      /* location of statistics summary */
                    440: EXTERN char    *QueueDir;      /* location of queue directory */
                    441: EXTERN char    *FileName;      /* name to print on error messages */
                    442: EXTERN char    *TrustedUsers[MAXTRUST+1];      /* list of trusted users */
                    443: EXTERN jmp_buf TopFrame;       /* branch-to-top-of-loop-on-error frame */
                    444: EXTERN bool    QuickAbort;     /*  .... but only if we want a quick abort */
                    445: extern char    *ConfFile;      /* location of configuration file [conf.c] */
                    446: extern char    *FreezeFile;    /* location of frozen memory image [conf.c] */
                    447: extern char    Arpa_Info[];    /* the reply code for Arpanet info [conf.c] */
                    448: extern char    SpaceSub;       /* substitution for <lwsp> [conf.c] */
                    449: /*
                    450: **  Trace information
                    451: */
                    452: 
                    453: /* trace vector and macros for debugging flags */
                    454: EXTERN u_char  tTdvect[100];
                    455: # define tTd(flag, level)      (tTdvect[flag] >= level)
                    456: # define tTdlevel(flag)                (tTdvect[flag])
                    457: /*
                    458: **  Miscellaneous information.
                    459: */
                    460: 
                    461: # include      <sysexits.h>
                    462: 
                    463: 
                    464: /*
                    465: **  Some in-line functions
                    466: */
                    467: 
                    468: /* set exit status */
                    469: #define setstat(s)     { \
                    470:                                if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
                    471:                                        ExitStat = s; \
                    472:                        }
                    473: 
                    474: /* make a copy of a string */
                    475: #define newstr(s)      strcpy(xalloc(strlen(s) + 1), s)
                    476: 
                    477: 
                    478: /*
                    479: **  Declarations of useful functions
                    480: */
                    481: 
                    482: extern ADDRESS *parseaddr();
                    483: extern char    *xalloc();
                    484: extern bool    sameaddr();
                    485: extern FILE    *dfopen();
                    486: extern EVENT   *setevent();
                    487: extern char    *sfgets();
                    488: extern char    *queuename();
                    489: extern time_t  curtime();

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.