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 / conf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  11.5 KB  |  586 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.  
  21. #ifndef lint
  22. static char sccsid[] = "@(#)conf.c    5.26 (Berkeley) 6/1/90";
  23. static char rcsid[] = "@(#)$Id: conf.c,v 5.26.0.25 1991/06/21 12:38:29 paul Exp $";
  24. #endif /* not lint */
  25.  
  26. #include "sendmail.h"
  27. #include <sys/ioctl.h>
  28. #include <sys/param.h>
  29. #include <pwd.h>
  30. #if defined(__convex__) && defined(SHARE)
  31. # include <shares.h>
  32. #endif /* __convex__ && SHARE */
  33.  
  34. #ifdef __STDC__
  35. extern char *ttyname(int), *getlogin(void);
  36. #else /* !__STDC__ */
  37. extern char *ttyname(), *getlogin();
  38. #endif /* __STDC__ */
  39.  
  40. /*
  41. **  CONF.C -- Sendmail Configuration Tables.
  42. **
  43. **    Defines the configuration of this installation.
  44. **
  45. **    Compilation Flags:
  46. **        VMUNIX -- running on a Berkeley UNIX system.
  47. **
  48. **    Configuration Variables:
  49. **        HdrInfo -- a table describing well-known header fields.
  50. **            Each entry has the field name and some flags,
  51. **            which are described in sendmail.h.
  52. **
  53. **    Notes:
  54. **        I have tried to put almost all the reasonable
  55. **        configuration information into the configuration
  56. **        file read at runtime.  My intent is that anything
  57. **        here is a function of the version of UNIX you
  58. **        are running, or is really static -- for example
  59. **        the headers are a superset of widely used
  60. **        protocols.  If you find yourself playing with
  61. **        this file too much, you may be making a mistake!
  62. */
  63.  
  64.  
  65. /*
  66. **  Header info table
  67. **    Final (null) entry contains the flags used for any other field.
  68. **
  69. **    Not all of these are actually handled specially by sendmail
  70. **    at this time.  They are included as placeholders, to let
  71. **    you know that "someday" I intend to have sendmail do
  72. **    something with them.
  73. */
  74.  
  75. struct hdrinfo    HdrInfo[] =
  76. {
  77.         /* originator fields, most to least significant  */
  78.     "resent-sender",    H_FROM|H_RESENT,
  79.     "resent-from",        H_FROM|H_RESENT,
  80.     "resent-reply-to",    H_FROM|H_RESENT,
  81.     "sender",        H_FROM,
  82.     "from",            H_FROM,
  83.     "reply-to",        H_FROM,
  84.     "full-name",        H_ACHECK,
  85.     "return-receipt-to",    H_FROM,
  86.     "errors-to",        H_FROM,
  87.         /* destination fields */
  88.     "to",            H_RCPT,
  89.     "resent-to",        H_RCPT|H_RESENT,
  90.     "cc",            H_RCPT,
  91.     "resent-cc",        H_RCPT|H_RESENT,
  92.     "bcc",            H_RCPT|H_ACHECK,
  93.     "resent-bcc",        H_RCPT|H_ACHECK|H_RESENT,
  94.     "apparently-to",    H_RCPT,
  95.         /* message identification and control */
  96.     "message-id",        0,
  97.     "resent-message-id",    H_RESENT,
  98.     "message",        H_EOH,
  99.     "text",            H_EOH,
  100.         /* date fields */
  101.     "date",            0,
  102.     "resent-date",        H_RESENT,
  103.         /* trace fields */
  104.     "received",        H_TRACE|H_FORCE,
  105.     "via",            H_TRACE|H_FORCE,
  106.     "mail-from",        H_TRACE|H_FORCE,
  107.     "x400-received",    H_TRACE,
  108.  
  109.     NULL,            0,
  110. };
  111.  
  112.  
  113. /*
  114. **  ARPANET error message numbers.
  115. */
  116.  
  117. char    Arpa_Info[] =        "050";    /* arbitrary info */
  118. char    Arpa_TSyserr[] =    "451";    /* some (transient) system error */
  119. char    Arpa_PSyserr[] =    "554";    /* some (permanent) system error */
  120. char    Arpa_Usrerr[] =        "554";    /* some (fatal) user error */
  121.  
  122.  
  123.  
  124. /*
  125. **  Location of system files/databases/etc.
  126. */
  127.  
  128. char    *ConfFile =    _PATH_SENDMAILCF;    /* runtime configuration */
  129.  
  130. #ifdef _PATH_SENDMAILFC
  131. char    *FreezeFile =    _PATH_SENDMAILFC;    /* frozen version of above */
  132. #endif /* _PATH_SENDMAILFC */
  133.  
  134. #ifdef _PATH_SENDMAILPID
  135. char    *PidFile =    _PATH_SENDMAILPID;    /* sendmail daemon PID */
  136. #endif /* _PATH_SENDMAILPID */
  137.  
  138.  
  139.  
  140. /*
  141. **  Miscellaneous stuff.
  142. */
  143. extern int la;                /* load average */
  144. /*
  145. **  SETDEFAULTS -- set default values
  146. **
  147. **    Because of the way freezing is done, these must be initialized
  148. **    using direct code.
  149. **
  150. **    Parameters:
  151. **        none.
  152. **
  153. **    Returns:
  154. **        none.
  155. **
  156. **    Side Effects:
  157. **        Initializes a bunch of global variables to their
  158. **        default values.
  159. */
  160.  
  161. void
  162. setdefaults()
  163. {
  164.     int c;
  165.  
  166.     QueueLA = 8;
  167.     QueueFactor = 10000;
  168.     RefuseLA = 12;
  169.     SpaceSub = ' ';
  170.     WkRecipFact = 1000;
  171.     WkClassFact = 1800;
  172.     WkTimeFact = 9000;
  173.     FileMode = 0644;
  174.     DefUid = 1;
  175.     DefGid = 1;
  176.  
  177. #if defined(NDBM) || defined(OTHERDBM)
  178.     for (c = 0; c < 128; c++)
  179.         DbmTab[c].db_dbm = DB_NOTYETOPEN;
  180. #endif /* NDBM || OTHERDBM */
  181. }
  182.  
  183.  
  184. /*
  185. **  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
  186. */
  187.  
  188. void
  189. setdefuser()
  190. {
  191.     struct passwd *defpwent;
  192.  
  193.     if (DefUser != NULL)
  194.         free(DefUser);
  195.     if ((defpwent = getpwuid(DefUid)) != NULL)
  196.         DefUser = newstr(defpwent->pw_name);
  197.     else
  198.         DefUser = newstr("nobody");
  199. }
  200.  
  201.  
  202. /*
  203. **  GETRUID -- get real user id (V7)
  204. */
  205.  
  206. int
  207. getruid()
  208. {
  209.     if (OpMode == MD_DAEMON)
  210.         return (RealUid);
  211.     else
  212.         return (getuid());
  213. }
  214.  
  215.  
  216. /*
  217. **  GETRGID -- get real group id (V7).
  218. */
  219.  
  220. int
  221. getrgid()
  222. {
  223.     if (OpMode == MD_DAEMON)
  224.         return (RealGid);
  225.     else
  226.         return (getgid());
  227. }
  228.  
  229. /*
  230. **  USERNAME -- return the user id of the logged in user.
  231. **
  232. **    Parameters:
  233. **        none.
  234. **
  235. **    Returns:
  236. **        The login name of the logged in user.
  237. **
  238. **    Side Effects:
  239. **        none.
  240. **
  241. **    Notes:
  242. **        The return value is statically allocated.
  243. */
  244.  
  245. char *
  246. username()
  247. {
  248.     static char *myname = NULL;
  249.     register struct passwd *pw;
  250.  
  251.     /* cache the result */
  252.     if (myname == NULL)
  253.     {
  254.         myname = getlogin();
  255.         if (myname == NULL || myname[0] == '\0')
  256.         {
  257.  
  258.             pw = getpwuid(getruid());
  259.             if (pw != NULL)
  260.                 myname = newstr(pw->pw_name);
  261.         }
  262.         else
  263.         {
  264.  
  265.             myname = newstr(myname);
  266.             if ((pw = getpwnam(myname)) == NULL ||
  267.                   getuid() != pw->pw_uid)
  268.             {
  269.                 pw = getpwuid(getuid());
  270.                 if (pw != NULL)
  271.                 {
  272.                     if (myname)
  273.                         free(myname);
  274.                     myname = newstr(pw->pw_name);
  275.                 }
  276.             }
  277.         }
  278.         if (myname == NULL || myname[0] == '\0')
  279.         {
  280.             syserr("Who are you?");
  281.             myname = "postmaster";
  282.         }
  283.     }
  284.  
  285.     return (myname);
  286. }
  287. /*
  288. **  TTYPATH -- Get the path of the user's tty
  289. **
  290. **    Returns the pathname of the user's tty.  Returns NULL if
  291. **    the user is not logged in or if s/he has write permission
  292. **    denied.
  293. **
  294. **    Parameters:
  295. **        none
  296. **
  297. **    Returns:
  298. **        pathname of the user's tty.
  299. **        NULL if not logged in or write permission denied.
  300. **
  301. **    Side Effects:
  302. **        none.
  303. **
  304. **    WARNING:
  305. **        Return value is in a local buffer.
  306. **
  307. **    Called By:
  308. **        savemail
  309. */
  310.  
  311. #include <sys/stat.h>
  312.  
  313. char *
  314. ttypath()
  315. {
  316.     struct stat stbuf;
  317.     register char *pathn;
  318.  
  319.     /* compute the pathname of the controlling tty */
  320.     if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
  321.         (pathn = ttyname(0)) == NULL)
  322.     {
  323.         errno = 0;
  324.         return (NULL);
  325.     }
  326.  
  327.     /* see if we have write permission */
  328.     if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
  329.     {
  330.         errno = 0;
  331.         return (NULL);
  332.     }
  333.  
  334.     /* see if the user is logged in */
  335.     if (getlogin() == NULL)
  336.         return (NULL);
  337.  
  338.     /* looks good */
  339.     return (pathn);
  340. }
  341. /*
  342. **  CHECKCOMPAT -- check for From and To person compatible.
  343. **
  344. **    This routine can be supplied on a per-installation basis
  345. **    to determine whether a person is allowed to send a message.
  346. **    This allows restriction of certain types of internet
  347. **    forwarding or registration of users.
  348. **
  349. **    If the hosts are found to be incompatible, an error
  350. **    message should be given using "usrerr" and FALSE should
  351. **    be returned.
  352. **
  353. **    'NoReturn' can be set to suppress the return-to-sender
  354. **    function; this should be done on huge messages.
  355. **
  356. **    Parameters:
  357. **        to -- the person being sent to.
  358. **
  359. **    Returns:
  360. **        TRUE -- ok to send.
  361. **        FALSE -- not ok.
  362. **
  363. **    Side Effects:
  364. **        none (unless you include the usrerr stuff)
  365. */
  366.  
  367. bool
  368. checkcompat(to)
  369.     register ADDRESS *to;
  370. {
  371. #ifdef lint
  372.     if (to == NULL)
  373.         to++;
  374. #endif /* lint */
  375. #ifdef EXAMPLE_CODE
  376.     /* this code is intended as an example only */
  377.     register STAB *s;
  378.  
  379.     s = stab("arpa", ST_MAILER, ST_FIND);
  380.     if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer &&
  381.         to->q_mailer == s->s_mailer)
  382.     {
  383.         usrerr("No ARPA mail through this machine: see your system administration");
  384.         /* NoReturn = TRUE; to supress return copy */
  385.         return (FALSE);
  386.     }
  387. #endif /* EXAMPLE_CODE */
  388.     return (TRUE);
  389. }
  390. /*
  391. **  HOLDSIGS -- arrange to hold all signals
  392. **
  393. **    Parameters:
  394. **        none.
  395. **
  396. **    Returns:
  397. **        none.
  398. **
  399. **    Side Effects:
  400. **        Arranges that signals are held.
  401. */
  402.  
  403. void
  404. holdsigs()
  405. {
  406. }
  407. /*
  408. **  RLSESIGS -- arrange to release all signals
  409. **
  410. **    This undoes the effect of holdsigs.
  411. **
  412. **    Parameters:
  413. **        none.
  414. **
  415. **    Returns:
  416. **        none.
  417. **
  418. **    Side Effects:
  419. **        Arranges that signals are released.
  420. */
  421.  
  422. void
  423. rlsesigs()
  424. {
  425. }
  426. /*
  427. **  GETLA -- get the current load average
  428. **
  429. **    Calls getloadavg() which is derived from the X11R4 'xload' utility.
  430. **
  431. **    Parameters:
  432. **        none.
  433. **
  434. **    Returns:
  435. **        The current load average as an integer.
  436. **
  437. **    Side Effects:
  438. **        none.
  439. */
  440.  
  441. int
  442. getla()
  443. {
  444.         double avenrun;
  445.  
  446.         if (getloadavg((caddr_t) &avenrun) < 0)
  447.     {
  448.         if (tTd(3, 1))
  449.             printf("Load average: getloadavg() returned -1\n");
  450.                 return (0);
  451.     }
  452.  
  453.     /* same test used in main.c */
  454.     if (tTd(3, 1))
  455.         printf("Load average: %3.1f\n", avenrun);
  456.         return ((int) (avenrun + 0.5));
  457. }
  458. /*
  459. **  SHOULDQUEUE -- should this message be queued or sent?
  460. **
  461. **    Compares the message cost to the load average to decide.
  462. **
  463. **    Parameters:
  464. **        pri -- the priority of the message in question.
  465. **
  466. **    Returns:
  467. **        TRUE -- if this message should be queued up for the
  468. **            time being.
  469. **        FALSE -- if the load is low enough to send this message.
  470. **
  471. **    Side Effects:
  472. **        none.
  473. */
  474.  
  475. bool
  476. shouldqueue(pri)
  477.     long pri;
  478. {
  479.     if (la < QueueLA)
  480.         return (FALSE);
  481.     return (pri > (QueueFactor / (la - QueueLA + 1)));
  482. }
  483. /*
  484. **  SETPROCTITLE -- set process title for ps
  485. **
  486. **    Parameters:
  487. **        fmt -- a printf style format string.
  488. **        a, b, c -- possible parameters to fmt.
  489. **
  490. **    Returns:
  491. **        none.
  492. **
  493. **    Side Effects:
  494. **        Clobbers argv of our main procedure so ps(1) will
  495. **        display the title.
  496. */
  497.  
  498. /*VARARGS1*/
  499. void
  500. #ifdef __STDC__
  501. setproctitle(const char *fmt, ...)
  502. #else /* !__STDC__ */
  503. setproctitle(fmt, va_alist)
  504.     const char *fmt;
  505. va_dcl
  506. #endif /* __STDC__ */
  507. {
  508. #if defined(SETPROCTITLE) && !defined(SYSV)
  509.     va_list    args;
  510.     register char *p;
  511.     register int i;
  512.     extern char **Argv;
  513.     extern char *LastArgv;
  514.     char buf[MAXLINE];
  515.  
  516. # ifdef __STDC__
  517.     va_start(args, fmt);
  518. # else /* !__STDC__ */
  519.     va_start(args);
  520. # endif /* __STDC__ */
  521.     (void) vsprintf(buf, fmt, args);
  522.     va_end(args);
  523.  
  524.     /* make ps print "(sendmail)" */
  525.     p = Argv[0];
  526.     *p++ = '-';
  527.  
  528.     i = strlen(buf);
  529.     if (i > LastArgv - p - 2)
  530.     {
  531.         i = LastArgv - p - 2;
  532.         buf[i] = '\0';
  533.     }
  534.     (void) strcpy(p, buf);
  535.     p += i;
  536.     while (p < LastArgv)
  537.         *p++ = ' ';
  538. #endif /* SETPROCTITLE && !SYSV */
  539. }
  540. /*
  541. **  REAPCHILD -- pick up the body of my child, lest it become a zombie
  542. **
  543. **    Parameters:
  544. **        none.
  545. **
  546. **    Returns:
  547. **        none.
  548. **
  549. **    Side Effects:
  550. **        Picks up extant zombies.
  551. */
  552.  
  553. #ifdef VMUNIX
  554. # include <sys/wait.h>
  555. #endif /* VMUNIX */
  556.  
  557. SIG_TYPE
  558. reapchild()
  559. {
  560.     int pid;
  561. #ifdef LACK_WAIT3
  562.     int status;
  563.  
  564.     if ((pid = wait(&status)) > 0)
  565.         if (tTd(4, 2))
  566.             printf("reapchild: wait (pid = %d)\n", pid);
  567.  
  568.     /* reset handler */
  569.     (void) signal(SIGCHLD, reapchild);
  570. #else /* !LACK_WAIT3 */
  571.     union wait status;
  572.  
  573.     while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
  574.     {
  575.         if (tTd(4, 2))
  576.             printf("reapchild: wait3 (pid = %d)\n", pid);
  577.         continue;
  578.     }
  579. #endif /* LACK_WAIT3 */
  580. #ifdef notdef
  581. #if ( SIG_TYPE == int )
  582.     return 0;
  583. #endif /* SIG_TYPE == int */
  584. #endif /* notdef */
  585. }
  586.