home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / sendmail.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-14  |  26.0 KB  |  784 lines

  1. /*
  2.  * Copyright (c) 1983 Eric P. Allman
  3.  * Copyright (c) 1988 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted provided
  7.  * that: (1) source distributions retain this entire copyright notice and
  8.  * comment, and (2) distributions including binaries display the following
  9.  * acknowledgement:  ``This product includes software developed by the
  10.  * University of California, Berkeley and its contributors'' in the
  11.  * documentation or other materials provided with the distribution and in
  12.  * all advertising materials mentioning features or use of this software.
  13.  * Neither the name of the University nor the names of its contributors may
  14.  * be used to endorse or promote products derived from this software without
  15.  * specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  *
  20.  *    @(#)sendmail.h    5.16 (Berkeley) 6/1/90
  21.  */
  22.  
  23. /*
  24. **  SENDMAIL.H -- Global definitions for sendmail.
  25. */
  26.  
  27. # ifdef _DEFINE
  28. #  define EXTERN
  29. #  ifndef lint
  30. static char SmailSccsId[] =    "@(#)sendmail.h    5.16        6/1/90";
  31. static char SmailRcsId[] =    "@(#)$Id: sendmail.h,v 5.16.0.24 1991/08/14 18:28:19 paul Exp $";
  32. #  endif /* lint */
  33. # else  /* !_DEFINE */
  34. #  define EXTERN extern
  35. # endif /* _DEFINE */
  36.  
  37. # include "conf.h"
  38. # include <stdio.h>
  39. # ifdef SYSV
  40. #  include <signal.h>
  41. # else /* !SYSV */
  42. #  include <sys/signal.h>
  43. # endif /* SYSV */
  44. # if defined(SYSV) 
  45. #  include <time.h>
  46. # else /* !SYSV */
  47. #  include <sys/time.h>
  48. # endif /* SYSV */
  49. # include "useful.h"
  50. # include <ctype.h>
  51. # include <setjmp.h>
  52. # include <sysexits.h>
  53. # ifdef BIT8
  54. #  include "../ida/charset/charset.h"
  55. # endif /* BIT8 */
  56. # include <sys/file.h>
  57. # ifndef LOCK_EX
  58. #  include "flock.h"
  59. # endif /* !LOCK_EX */
  60.  
  61. # if defined(hpux) || defined(_CONVEX_SOURCE) || defined(DGUX)
  62. #  define XPG3           /* X-Open Portability Guide 3 */
  63. #  include <unistd.h>
  64. #  ifndef direct
  65. #   include <dirent.h>
  66. #   define direct dirent
  67. #  endif /* !direct */
  68. # endif /* hpux || _CONVEX_SOURCE || DGUX */
  69.  
  70. # ifdef LOG
  71. #  if defined(hpux) || defined(ISC)
  72. #   include <syslog.h>
  73. #  else /* !hpux && !ISC */
  74. #   include <sys/syslog.h>
  75. #  endif /* hpux || ISC */
  76. # endif /* LOG */
  77.  
  78. # if defined(VMUNIX) || defined(ISC)
  79. #  include <sys/socket.h>
  80. #  include <netinet/in.h>
  81. #  ifndef INADDR_NONE
  82. #   define INADDR_NONE 0xffffffff
  83. #  endif /* !INADDR_NONE */
  84. # endif /* VMUNIX || ISC */
  85.  
  86. # if defined(__STDC__)
  87. #  include <stdarg.h>
  88. # else /* !__STDC__ */
  89. #  include <varargs.h>
  90. # endif /* __STDC__ */
  91.  
  92. # define PSBUFSIZE    (MAXNAME + MAXATOM)    /* size of prescan buffer */
  93.  
  94.  
  95. /*
  96. **  Data structure for bit maps.
  97. **
  98. **    Each bit in this map can be referenced by an ascii character.
  99. **    This is 128 possible bits, or 16 8-bit bytes.
  100. */
  101.  
  102. #define BITMAPBYTES    16    /* number of bytes in a bit map */
  103. #define BYTEBITS    8    /* number of bits in a byte */
  104.  
  105. /* internal macros */
  106. #define _BITWORD(bit)    (bit / (BYTEBITS * sizeof (int)))
  107. #define _BITBIT(bit)    (1 << (bit % (BYTEBITS * sizeof (int))))
  108.  
  109. typedef unsigned int    BITMAP[BITMAPBYTES / sizeof (int)];
  110.  
  111. /* test bit number N */
  112. #define bitnset(bit, map)    ((map)[_BITWORD(bit)] & _BITBIT(bit))
  113.  
  114. /* set bit number N */
  115. #define setbitn(bit, map)    (map)[_BITWORD(bit)] |= _BITBIT(bit)
  116.  
  117. /* clear bit number N */
  118. #define clrbitn(bit, map)    (map)[_BITWORD(bit)] &= ~_BITBIT(bit)
  119.  
  120. /* clear an entire bit map */
  121. #define clrbitmap(map)        bzero((char *) map, BITMAPBYTES)
  122. /*
  123. **  Address structure.
  124. **    Addresses are stored internally in this structure.
  125. */
  126.  
  127. struct address
  128. {
  129.     char        *q_paddr;    /* the printname for the address */
  130.     char        *q_user;    /* user name */
  131.     char        *q_ruser;    /* real user name, or NULL if q_user */
  132.     char        *q_host;    /* host name */
  133.     struct mailer    *q_mailer;    /* mailer to use */
  134.     u_short        q_flags;    /* status flags, see below */
  135.     short        q_uid;        /* user-id of receiver (if known) */
  136.     short        q_gid;        /* group-id of receiver (if known) */
  137.     char        *q_home;    /* home dir (local mailer only) */
  138.     char        *q_fullname;    /* full name if known */
  139.     struct address    *q_next;    /* chain */
  140.     struct address    *q_alias;    /* address this results from */
  141.     struct address    *q_tchain;    /* temporary use chain */
  142.     TIME_TYPE    q_timeout;    /* timeout for this address */
  143. };
  144.  
  145. typedef struct address ADDRESS;
  146.  
  147. # define QDONTSEND    000001    /* don't send to this address */
  148. # define QBADADDR    000002    /* this address is verified bad */
  149. # define QGOODUID    000004    /* the q_uid q_gid fields are good */
  150. # define QPRIMARY    000010    /* set from argv */
  151. # define QQUEUEUP    000020    /* queue for later transmission */
  152. # define QSELFREF    000040    /* self-reference in alias/forward expansion */
  153. /*
  154. **  Mailer definition structure.
  155. **    Every mailer known to the system is declared in this
  156. **    structure.  It defines the pathname of the mailer, some
  157. **    flags associated with it, and the argument vector to
  158. **    pass to it.  The flags are defined in conf.c
  159. **
  160. **    The argument vector is expanded before actual use.  All
  161. **    words except the first are passed through the macro
  162. **    processor.
  163. */
  164.  
  165. /* m_flags is a #define in <include/sysmacros.h under HP-UX */
  166. #ifdef m_flags
  167. # undef m_flags
  168. #endif /* m_flags */
  169.  
  170. struct mailer
  171. {
  172.     char    *m_name;    /* symbolic name of this mailer */
  173.     char    *m_mailer;    /* pathname of the mailer to use */
  174.     BITMAP    m_flags;    /* status flags, see below */
  175.     short    m_mno;        /* mailer number internally */
  176.     char    **m_argv;    /* template argument vector */
  177.     short    m_se_rwset;    /* rewriting ruleset for envelope senders */
  178.     short    m_sh_rwset;    /* rewriting ruleset for header senders */
  179.     short    m_re_rwset;    /* rewriting ruleset for envelope recipients */
  180.     short    m_rh_rwset;    /* rewriting ruleset for header recipient */
  181.     char    *m_eol;        /* end of line string */
  182.     long    m_maxsize;    /* size limit on message to this mailer */
  183. # ifdef BIT8
  184.     CHARSET    *m_charset;    /* default character set */
  185.     short    m_esc;        /* escape character */
  186. # endif /* BIT8 */
  187. };
  188.  
  189. typedef struct mailer    MAILER;
  190.  
  191. /* bits for m_flags */
  192. # define M_BSMTP    'B'    /* don't wait for SMTP responses */
  193. # define M_CANONICAL    'C'    /* make addresses canonical "u@dom" */
  194. # define M_EXPENSIVE    'e'    /* it costs to use this mailer.... */
  195. # define M_ESCFROM    'E'    /* escape From lines to >From */
  196. # define M_FOPT        'f'    /* mailer takes picky -f flag */
  197. # define M_HST_UPPER    'h'    /* preserve host case distinction */
  198. # define M_INTERNAL    'I'    /* SMTP to another sendmail site */
  199. # define M_LOCAL    'l'    /* delivery is to this host */
  200. # define M_LIMITS    'L'    /* must enforce SMTP line limits */
  201. # define M_MUSER    'm'    /* can handle multiple users at once */
  202. # define M_NHDR        'n'    /* don't insert From line */
  203. # define M_FROMPATH    'p'    /* use reverse-path in MAIL FROM: */
  204. # define M_ROPT        'r'    /* mailer takes picky -r flag */
  205. # define M_SECURE_PORT    'R'    /* try to send on a reserved TCP port */
  206. # define M_STRIPQ    's'    /* strip quote chars from user/host */
  207. # define M_RESTR    'S'    /* must be daemon to execute */
  208. # define M_USR_UPPER    'u'    /* preserve user case distinction */
  209. # define M_UGLYUUCP    'U'    /* this wants an ugly UUCP from line */
  210. # define M_RELATIVIZE    'V'    /* !-relativize all addresses */
  211. # define M_XDOT        'X'    /* use hidden-dot algorithm */
  212. # ifdef MAIL11V3
  213. #  define M_PREHEAD    'H'    /* preview headers */
  214. #  define M_MANYSTATUS    'N'    /* mailer returns multi-status for DATA cmd */
  215. # endif /* MAIL11V3 */
  216.  
  217. EXTERN MAILER    *Mailer[MAXMAILERS+1];
  218. EXTERN MAILER    *LocalMailer;        /* ptr to local mailer */
  219. EXTERN MAILER    *ProgMailer;        /* ptr to program mailer */
  220.  
  221. # ifdef BIT8
  222. EXTERN CHARSET *ascii;
  223. # endif /* BIT8 */
  224. /*
  225. **  Header structure.
  226. **    This structure is used internally to store header items.
  227. */
  228.  
  229. struct header
  230. {
  231.     char        *h_field;    /* the name of the field */
  232.     char        *h_value;    /* the value of that field */
  233.     struct header    *h_link;    /* the next header */
  234.     u_short        h_flags;    /* status bits, see below */
  235.     BITMAP        h_mflags;    /* m_flags bits needed */
  236. };
  237.  
  238. typedef struct header    HDR;
  239.  
  240. /*
  241. **  Header information structure.
  242. **    Defined in conf.c, this struct declares the header fields
  243. **    that have some magic meaning.
  244. */
  245.  
  246. struct hdrinfo
  247. {
  248.     char    *hi_field;    /* the name of the field */
  249.     u_short    hi_flags;    /* status bits, see below */
  250. };
  251.  
  252. extern struct hdrinfo    HdrInfo[];
  253.  
  254. /* bits for h_flags and hi_flags */
  255. # define H_EOH        00001    /* this field terminates header */
  256. # define H_RCPT        00002    /* contains recipient addresses */
  257. # define H_DEFAULT    00004    /* if another value is found, drop this */
  258. # define H_RESENT    00010    /* this address is a "Resent-..." address */
  259. # define H_CHECK    00020    /* check h_mflags against m_flags */
  260. # define H_ACHECK    00040    /* ditto, but always (not just default) */
  261. # define H_FORCE    00100    /* force this field, even if default */
  262. # define H_TRACE    00200    /* this field contains trace information */
  263. # define H_FROM        00400    /* this is a from-type field */
  264. # define H_VALID    01000    /* this field has a validated value */
  265. /*
  266. **  Envelope structure.
  267. **    This structure defines the message itself.  There is usually
  268. **    only one of these -- for the message that we originally read
  269. **    and which is our primary interest -- but other envelopes can
  270. **    be generated during processing.  For example, error messages
  271. **    will have their own envelope.
  272. */
  273.  
  274. struct envelope
  275. {
  276.     HDR        *e_header;    /* head of header list */
  277.     long        e_msgpriority;    /* adjusted priority of this message */
  278.     TIME_TYPE    e_ctime;    /* time message appeared in the queue */
  279.     char        *e_to;        /* the target person */
  280.     char        *e_receiptto;    /* return receipt address */
  281.     ADDRESS        e_from;        /* the person it is from */
  282.     char        **e_fromdomain;    /* the domain part of the sender */
  283.     ADDRESS        *e_sendqueue;    /* list of message recipients */
  284.     ADDRESS        *e_errorqueue;    /* the queue for error responses */
  285.     long        e_msgsize;    /* size of the message in bytes */
  286.     int        e_nrcpts;    /* number of recipients */
  287.     short        e_class;    /* msg class (priority, junk, etc.) */
  288.     short        e_flags;    /* flags, see below */
  289.     short        e_hopcount;    /* number of times processed */
  290.     void        (*e_puthdr)();    /* function to put header of message */
  291.     void        (*e_putbody)();    /* function to put body of message */
  292.     struct envelope    *e_parent;    /* the message this one encloses */
  293.     struct envelope *e_sibling;    /* the next envelope of interest */
  294.     char        *e_df;        /* location of temp file */
  295.     FILE        *e_dfp;        /* temporary file */
  296.     char        *e_id;        /* code for this entry in queue */
  297.     FILE        *e_xfp;        /* transcript file */
  298.     char        *e_message;    /* error message */
  299.     char        *e_macro[128];    /* macro definitions */
  300. };
  301.  
  302. typedef struct envelope    ENVELOPE;
  303.  
  304. /* values for e_flags */
  305. #define EF_OLDSTYLE    000001        /* use spaces (not commas) in hdrs */
  306. #define EF_INQUEUE    000002        /* this message is fully queued */
  307. #define EF_TIMEOUT    000004        /* this message is too old */
  308. #define EF_CLRQUEUE    000010        /* disk copy is no longer needed */
  309. #define EF_SENDRECEIPT    000020        /* send a return receipt */
  310. #define EF_FATALERRS    000040        /* fatal errors occured */
  311. #define EF_KEEPQUEUE    000100        /* keep queue files always */
  312. #define EF_RESPONSE    000200        /* this is an error or return receipt */
  313. #define EF_RESENT    000400        /* this message is being forwarded */
  314.  
  315. /* special shadowing null for e_macro's */
  316. #define MACNULL        ((char *) 1)    /* don't check parent's value */
  317.  
  318. EXTERN ENVELOPE    *CurEnv;    /* envelope currently being processed */
  319. /*
  320. **  Message priority classes.
  321. **
  322. **    The message class is read directly from the Priority: header
  323. **    field in the message.
  324. **
  325. **    CurEnv->e_msgpriority is the number of bytes in the message plus
  326. **    the creation time (so that jobs ``tend'' to be ordered correctly),
  327. **    adjusted by the message class, the number of recipients, and the
  328. **    amount of time the message has been sitting around.  This number
  329. **    is used to order the queue.  Higher values mean LOWER priority.
  330. **
  331. **    Each priority class point is worth WkClassFact priority points;
  332. **    each recipient is worth WkRecipFact priority points.  Each time
  333. **    we reprocess a message the priority is adjusted by WkTimeFact.
  334. **    WkTimeFact should normally decrease the priority so that jobs
  335. **    that have historically failed will be run later; thanks go to
  336. **    Jay Lepreau at Utah for pointing out the error in my thinking.
  337. **
  338. **    The "class" is this number, unadjusted by the age or size of
  339. **    this message.  Classes with negative representations will have
  340. **    error messages thrown away if they are not local.
  341. */
  342.  
  343. struct priority
  344. {
  345.     char    *pri_name;    /* external name of priority */
  346.     int    pri_val;    /* internal value for same */
  347. };
  348.  
  349. EXTERN struct priority    Priorities[MAXPRIORITIES];
  350. EXTERN int        NumPriorities;    /* pointer into Priorities */
  351. /*
  352. **  Rewrite rules.
  353. */
  354.  
  355. struct rewrite
  356. {
  357.     char    **r_lhs;    /* pattern match */
  358.     char    **r_rhs;    /* substitution value */
  359.     struct rewrite    *r_next;/* next in chain */
  360. };
  361.  
  362. EXTERN struct rewrite    *RewriteRules[MAXRWSETS];
  363.  
  364. /*
  365. **  Special characters in rewriting rules.
  366. **    These are used internally only.
  367. **    The COND* rules are actually used in macros rather than in
  368. **        rewriting rules, but are given here because they
  369. **        cannot conflict.
  370. */
  371.  
  372. /* left hand side items */
  373. # define MATCHZANY    '\020'    /* match zero or more tokens */
  374. # define MATCHANY    '\021'    /* match one or more tokens */
  375. # define MATCHONE    '\022'    /* match exactly one token */
  376. # define MATCHCLASS    '\023'    /* match one token in a class */
  377. # define MATCHNCLASS    '\024'    /* match anything not in class */
  378. # define MATCHREPL    '\025'    /* replacement on RHS for above */
  379. # define MATCHMAP    '\013'    /* found in dbm/map */
  380. # define MATCHNMAP    '\014'    /* not found in dbm/map */
  381.  
  382. /* right hand side items */
  383. # define CANONNET    '\026'    /* canonical net, next token */
  384. # define CANONHOST    '\027'    /* canonical host, next token */
  385. # define CANONUSER    '\030'    /* canonical user, next N tokens */
  386. # define CALLSUBR    '\031'    /* call another rewriting set */
  387.  
  388. /* conditionals in macros */
  389. # define CONDIF        '\032'    /* conditional if-then */
  390. # define CONDELSE    '\033'    /* conditional else */
  391. # define CONDFI        '\034'    /* conditional fi */
  392.  
  393. /* bracket characters for host name & database keyed lookup */
  394. # define HOSTBEGIN    '\035'    /* hostname lookup begin */
  395. # define HOSTEND    '\036'    /* hostname lookup end */
  396. # define KEYBEGIN    '\037'    /* keyed lookup begin */
  397. # define KEYEND        '\017'    /* keyed lookup end */
  398.  
  399. /* other miscellaneous */
  400. # define MACVALUE    '\016'    /* delayed macro expansion $& */
  401. # define QUOTE822    '\015'    /* quote next macro if RFC822 requires it */
  402.  
  403. /* \001 is also reserved as the macro expansion character */
  404. /*
  405. **  Information about hosts that we have looked up recently.
  406. **
  407. **    This stuff is 4.2/3bsd specific.
  408. */
  409.  
  410. # ifdef DAEMON
  411. #  ifdef VMUNIX
  412.  
  413. #   define HOSTINFO    struct hostinfo
  414.  
  415. HOSTINFO
  416. {
  417.     char        *ho_name;    /* name of this host */
  418.     struct in_addr    ho_inaddr;    /* internet address */
  419.     short        ho_flags;    /* flag bits, see below */
  420.     short        ho_errno;    /* error number on last connection */
  421.     short        ho_exitstat;    /* exit status from last connection */
  422. };
  423.  
  424.  
  425. /* flag bits */
  426. #   define HOF_VALID    00001        /* this entry is valid */
  427.  
  428. #  endif /* VMUNIX */
  429. # endif /* DAEMON */
  430. /*
  431. **  Symbol table definitions
  432. */
  433.  
  434. struct symtab
  435. {
  436.     char        *s_name;    /* name to be entered */
  437.     char        s_type;        /* general type (see below) */
  438.     struct symtab    *s_next;    /* pointer to next in chain */
  439.     union
  440.     {
  441.         BITMAP        sv_class;    /* bit-map of word classes */
  442.         ADDRESS        *sv_addr;    /* pointer to address header */
  443.         MAILER        *sv_mailer;    /* pointer to mailer */
  444.         char        *sv_alias;    /* alias */
  445. # ifdef HOSTINFO
  446.         HOSTINFO    sv_host;    /* host information */
  447. # endif /* HOSTINFO */
  448.     }    s_value;
  449. };
  450.  
  451. typedef struct symtab    STAB;
  452.  
  453. /* symbol types */
  454. # define ST_UNDEF    0    /* undefined type */
  455. # define ST_CLASS    1    /* class map */
  456. # define ST_ADDRESS    2    /* an address in parsed format */
  457. # define ST_MAILER    3    /* a mailer header */
  458. # define ST_ALIAS    4    /* an alias */
  459. # define ST_HOST    5    /* host information */
  460.  
  461. /* s_host is defined is /usr/include/whatever on Suns */
  462. # ifdef s_host
  463. #  undef s_host
  464. # endif /* s_host */
  465.  
  466. # define s_class    s_value.sv_class
  467. # define s_address    s_value.sv_addr
  468. # define s_mailer    s_value.sv_mailer
  469. # define s_alias    s_value.sv_alias
  470. # define s_host        s_value.sv_host
  471.  
  472. extern STAB    *stab();
  473.  
  474. /* opcodes to stab */
  475. # define ST_FIND    0    /* find entry */
  476. # define ST_ENTER    1    /* enter if not there */
  477. /*
  478. **  STRUCT EVENT -- event queue.
  479. **
  480. **    Maintained in sorted order.
  481. **
  482. **    We store the pid of the process that set this event to insure
  483. **    that when we fork we will not take events intended for the parent.
  484. */
  485.  
  486. struct event
  487. {
  488.     TIME_TYPE    ev_time;    /* time of the function call */
  489.     void        (*ev_func)();    /* function to call */
  490.     int        ev_arg;        /* argument to ev_func */
  491.     int        ev_pid;        /* pid that set this event */
  492.     struct event    *ev_link;    /* link to next item */
  493. };
  494.  
  495. typedef struct event    EVENT;
  496.  
  497. EXTERN EVENT    *EventQueue;        /* head of event queue */
  498. /*
  499. **  Operation, send, and error modes
  500. **
  501. **    The operation mode describes the basic operation of sendmail.
  502. **    This can be set from the command line, and is "send mail" by
  503. **    default.
  504. **
  505. **    The send mode tells how to send mail.  It can be set in the
  506. **    configuration file.  It's setting determines how quickly the
  507. **    mail will be delivered versus the load on your system.  If the
  508. **    -v (verbose) flag is given, it will be forced to SM_DELIVER
  509. **    mode.
  510. **
  511. **    The error mode tells how to return errors.
  512. */
  513.  
  514. EXTERN char    OpMode;        /* operation mode, see below */
  515.  
  516. #define MD_DELIVER    'm'        /* be a mail sender */
  517. #define MD_ARPAFTP    'a'        /* old-style arpanet protocols */
  518. #define MD_SMTP        's'        /* run SMTP on standard input */
  519. #define MD_DAEMON    'd'        /* run as a daemon */
  520. #define MD_VERIFY    'v'        /* verify: don't collect or deliver */
  521. #define MD_TEST        't'        /* test mode: resolve addrs only */
  522. #define MD_INITALIAS    'i'        /* initialize alias database */
  523. #define MD_PRINT    'p'        /* print the queue */
  524. #define MD_FREEZE    'z'        /* freeze the configuration file */
  525.  
  526.  
  527. EXTERN char    SendMode;    /* send mode, see below */
  528. #define MD_BSMTP    'b'        /* batched smtp mode */
  529.  
  530. #define SM_DELIVER    'i'        /* interactive delivery */
  531. #define SM_QUICKD    'j'        /* deliver w/o queueing */
  532. #define SM_FORK        'b'        /* deliver in background */
  533. #define SM_QUEUE    'q'        /* queue, don't deliver */
  534. #define SM_VERIFY    'v'        /* verify only (used internally) */
  535.  
  536. /* used only as a parameter to sendall */
  537. #define SM_DEFAULT    '\0'        /* unspecified, use SendMode */
  538.  
  539.  
  540. EXTERN char    ErrorMode;    /* error mode, see below */
  541.  
  542. #define EM_PRINT    'p'        /* print errors */
  543. #define EM_MAIL        'm'        /* mail back errors */
  544. #define EM_WRITE    'w'        /* write back errors */
  545. #define EM_BERKNET    'e'        /* special berknet processing */
  546. #define EM_QUIET    'q'        /* don't print messages (stat only) */
  547.  
  548. /* offset used to issure that the error messages for name server error
  549.  * codes are unique.
  550.  */
  551. #define    MAX_ERRNO    100
  552. /*
  553. **  Database ([n]dbm) definitions.
  554. */
  555.  
  556. #ifndef DBM
  557. # undef DBM_AUTOBUILD /* can't autobuild w/o DBM of some type */
  558. #else /* DBM */
  559.  
  560. typedef struct {
  561.     char    *dptr;
  562.     int    dsize;
  563. } XDATUM;
  564.  
  565. # ifndef MDBM
  566. #  define DB_DIREXT    ".dir"
  567. #  define DB_PAGEXT    ".pag"
  568. # endif /* !MDBM */
  569.  
  570. # ifdef GDBM
  571. #  define OTHERDBM
  572. #  undef DB_DIREXT
  573. #  define DB_DIREXT    ".pag"
  574. # endif /* GDBM */
  575.  
  576. # ifdef SDBM
  577. #  ifdef OTHERDBM
  578.     MULTIPLE_DBM_TYPES_DEFINED
  579. #  else
  580. #   define OTHERDBM
  581. #  endif /* OTHERDBM */
  582. # endif /* SDBM */
  583.  
  584. # ifdef MDBM
  585. #  ifdef OTHERDBM
  586.     MULTIPLE_DBM_TYPES_DEFINED
  587. #  else
  588. #   define OTHERDBM
  589. #  endif /* OTHERDBM */
  590. # endif /* MDBM */
  591.  
  592. # ifdef HDBM
  593. #  ifdef OTHERDBM
  594.     MULTIPLE_DBM_TYPES_DEFINED
  595. #  else
  596. #   define OTHERDBM
  597. #  endif /* OTHERDBM */
  598. # endif /* HDBM */
  599.  
  600. # if defined(NDBM) && defined(OTHERDBM)
  601.     MULTIPLE_DBM_TYPES_DEFINED
  602. # endif /* NDBM && OTHERDBM */
  603.  
  604. # if defined(NDBM) || defined(OTHERDBM)
  605. #  undef DBM            /* while including ndbm.h */
  606. #  ifdef GDBM
  607. #   include <ndbm.h>        /* DBM is typedef'ed here */
  608. #  endif /* GDBM */
  609. #  ifdef NDBM
  610. #   include <ndbm.h>        /* DBM is typedef'ed here */
  611. #  endif /* NDBM */
  612. #  ifdef SDBM
  613. #   include <sdbm.h>        /* DBM is typedef'ed here */
  614. #  endif /* SDBM */
  615. #  ifdef HDBM
  616. #   include <ndbm.h>        /* DBM is typedef'ed here */
  617. #  endif /* HDBM */
  618. #  ifdef MDBM
  619. #   include <mdbm.h>        /* DBM *not* typedef'ed here */
  620. #   define DB_DIREXT        ".map"
  621. #   define DB_PAGEXT        ".dat"
  622. #   define DBM_INSERT        MDBM_INSERT
  623. #   define DBM_REPLACE        MDBM_REPLACE
  624. #   define dbm_open(x,y,z)    mdbm_open(x,y,z,(int *)0, (int *)0, (char *)0)
  625. #   define dbm_close        mdbm_close
  626. #   define dbm_fetch        mdbm_fetch
  627. #   define dbm_store        mdbm_store
  628. typedef    struct mdbm DBMFILE;
  629. #  else /* !MDBM */
  630. typedef DBM DBMFILE;        /* move typedef to DBMFILE */
  631. #  endif /* MDBM */
  632. #  define DBM            /* and restore DBM definition */
  633. #  ifndef gould
  634. #   include <fcntl.h>        /* needed for dbm_open */
  635. #  endif /* gould */
  636.  
  637. # define XDATUM datum        /* use the definition in ndbm.h */
  638.  
  639. struct dbm_table {
  640.   char *db_name;        /* database file name */
  641. # ifdef DBM_AUTOBUILD
  642.   char *db_source;        /* text file to remake dbm */
  643.   char *db_rule;        /* program path name or fscanf string */
  644. # else /* !DBM_AUTOBUILD */
  645.   TIME_TYPE db_mtime;        /* last modify time */
  646. # endif /* !DBM_AUTOBUILD */
  647.   DBMFILE *db_dbm;        /* dbm file descriptor */
  648. };
  649.  
  650. # define DB_NOSUCHFILE    ((DBMFILE *)  0) /* file could not be found */
  651. # define DB_NOTYETOPEN    ((DBMFILE *) -1) /* file has not yet been opened */
  652.  
  653. # define DB_ALIAS    '@'    /* "name" of aliases database */
  654. # define AliasFile    DbmTab[DB_ALIAS].db_name
  655. # define AliasDbm    DbmTab[DB_ALIAS].db_dbm
  656.  
  657. # endif /* NDBM || OTHERDBM */
  658. #endif /* !DBM */
  659. /*
  660. **  Global variables.
  661. */
  662.  
  663. EXTERN bool    FromFlag;    /* if set, "From" person is explicit */
  664. EXTERN bool    NoAlias;    /* if set, don't do any aliasing */
  665. EXTERN bool    ForceMail;    /* if set, mail even if already got a copy */
  666. EXTERN bool    MeToo;        /* send to the sender also */
  667. EXTERN bool    IgnrDot;    /* don't let dot end messages */
  668. EXTERN bool    SaveFrom;    /* save leading "From" lines */
  669. EXTERN bool    Verbose;    /* set if blow-by-blow desired */
  670. EXTERN bool    GrabTo;        /* if set, get recipients from msg */
  671. EXTERN bool    NoReturn;    /* don't return letter to sender */
  672. EXTERN bool    SuprErrs;    /* set if we are suppressing errors */
  673. EXTERN bool    QueueRun;    /* currently running message from the queue */
  674. EXTERN bool    HoldErrs;    /* only output errors to transcript */
  675. EXTERN bool    NoConnect;    /* don't connect to non-local mailers */
  676. EXTERN bool    SuperSafe;    /* be extra careful, even if expensive */
  677. EXTERN bool    ForkQueueRuns;    /* fork for each job when running the queue */
  678. EXTERN bool    AutoRebuild;    /* auto-rebuild the alias database as needed */
  679. EXTERN bool    CheckAliases;    /* parse addresses during newaliases */
  680. EXTERN bool    UseNameServer;    /* use internet domain name server */
  681. # ifdef MAIL11V3
  682. EXTERN bool    SmtpManyStatus; /* receive multiple status' from DATA cmd */
  683. # endif /* MAIL11V3 */
  684. EXTERN int    SafeAlias;    /* minutes to wait until @:@ in alias file */
  685. EXTERN TIME_TYPE TimeOut;    /* time until timeout */
  686. EXTERN FILE    *InChannel;    /* input connection */
  687. EXTERN FILE    *OutChannel;    /* output connection */
  688. EXTERN int    RealUid;    /* when Daemon, real uid of caller */
  689. EXTERN int    RealGid;    /* when Daemon, real gid of caller */
  690. EXTERN int    DefUid;        /* default uid to run as */
  691. #if defined(__convex__) && defined(SHARE)
  692. EXTERN int    DefShareUid;    /* default share uid to assign process to */
  693. #endif /* __convex__ && SHARE */
  694. EXTERN char    *DefUser;    /* default user to run as (from DefUid) */
  695. EXTERN int    DefGid;        /* default gid to run as */
  696. EXTERN int    OldUmask;    /* umask when sendmail starts up */
  697. EXTERN int    Errors;        /* set if errors (local to single pass) */
  698. EXTERN int    ExitStat;    /* exit status code */
  699. EXTERN int    AliasLevel;    /* depth of aliasing */
  700. EXTERN int    MotherPid;    /* proc id of parent process */
  701. EXTERN int    LineNumber;    /* line number in current input */
  702. EXTERN TIME_TYPE ReadTimeout;    /* timeout on reads */
  703. EXTERN int    LogLevel;    /* level of logging to perform */
  704. EXTERN int    FileMode;    /* mode on files */
  705. EXTERN int    QueueLA;    /* load average starting forced queueing */
  706. EXTERN int    RefuseLA;    /* load average refusing connections are */
  707. EXTERN int    QueueFactor;    /* slope of queue function */
  708. EXTERN TIME_TYPE QueueIntvl;    /* intervals between running the queue */
  709. #if !defined(NDBM) && !defined(OTHERDBM)
  710. EXTERN char    *AliasFile;    /* location of alias file */
  711. #endif /* !NDBM && !OTHERDBM */
  712. EXTERN char    *HelpFile;    /* location of SMTP help file */
  713. EXTERN char    *StatFile;    /* location of statistics summary */
  714. EXTERN char    *QueueDir;    /* location of queue directory */
  715. EXTERN char    *FileName;    /* name to print on error messages */
  716. EXTERN char    *SmtpPhase;    /* current phase in SMTP processing */
  717. EXTERN char    *MyHostName;    /* name of this host for SMTP messages */
  718. EXTERN char    *RealHostName;    /* name of host we are talking to */
  719. EXTERN char    *DeclHostName;    /* declared name of host we are talking to */
  720. EXTERN struct    sockaddr_in RealHostAddr;/* address of host we are talking to */
  721. EXTERN char    *CurHostName;    /* current host we are dealing with */
  722. EXTERN jmp_buf    TopFrame;    /* branch-to-top-of-loop-on-error frame */
  723. EXTERN bool    QuickAbort;    /*  .... but only if we want a quick abort */
  724. extern char    *ConfFile;    /* location of configuration file [conf.c] */
  725. extern char    *FreezeFile;    /* location of frozen memory image [conf.c] */
  726. extern char    Arpa_Info[];    /* the reply code for Arpanet info [conf.c] */
  727. extern ADDRESS    NullAddress;    /* a null (template) address [main.c] */
  728. EXTERN char    SpaceSub;    /* substitution for <lwsp> */
  729. EXTERN int    WkClassFact;    /* multiplier for message class -> priority */
  730. EXTERN int    WkRecipFact;    /* multiplier for # of recipients -> priority */
  731. EXTERN int    WkTimeFact;    /* priority offset each time this job is run */
  732. EXTERN int    CheckPointLimit;    /* deliveries before checkpointing */
  733. EXTERN int    Nmx;            /* number of MX RRs */
  734. EXTERN char    *PostMasterCopy;    /* address to get errs cc's */
  735. EXTERN bool    SplitRewriting;    /* use split envelope/header rewriting */
  736. EXTERN char    *MxHosts[MAXMXHOSTS+1];    /* for MX RRs */
  737. EXTERN char    *TrustedUsers[MAXTRUST+1];    /* list of trusted users */
  738. /*
  739. **  Trace information
  740. */
  741. #if defined(NDBM) || defined(OTHERDBM)
  742. EXTERN struct dbm_table DbmTab[128];    /* keyed database table */
  743. # ifdef YP
  744. #  define YPMARK    '%'        /* yellow pages indicator */
  745. # endif /* YP */
  746. #endif /* NDBM || OTHERDBM */
  747.  
  748. /* trace vector and macros for debugging flags */
  749. EXTERN u_char    tTdvect[100];
  750. # define tTd(flag, level)    (tTdvect[flag] >= level)
  751. # define tTdlevel(flag)        (tTdvect[flag])
  752. /*
  753. **  Miscellaneous information.
  754. */
  755.  
  756. /*
  757. **  Some in-line functions
  758. */
  759.  
  760. /* set exit status */
  761. #define setstat(s)    { \
  762.                 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
  763.                     ExitStat = s; \
  764.             }
  765.  
  766. /* make a copy of a string */
  767. #define newstr(s)    strcpy(xalloc(strlen(s) + 1), s)
  768. #define dbm_newstr(s)    strncpy(xalloc(s.dsize + 1), s.dptr, s.dsize)
  769.  
  770. #define STRUCTCOPY(s, d)    d = s
  771.  
  772. /*
  773. **  Metamacro definitions.
  774. */
  775.  
  776. struct metamac
  777. {
  778.     char    metaname;
  779.     char    metaval;
  780. };
  781.  
  782. extern struct metamac    MetaMacros[];
  783. # include "def.h"
  784.