home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / getparam.c < prev    next >
Text File  |  1994-09-25  |  16KB  |  538 lines

  1. /*  getparam.c   This routine reads global or user's parameters files.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26. #include "uucico.h"
  27. #ifndef _OSK
  28. #include <password.h>
  29. #endif
  30.  
  31. #define WORDSIZE  10
  32.  
  33. #ifdef _OSK
  34. #define PWNSIZ 28
  35. #endif
  36.  
  37. QQ char *scratchdir   = "/dd",
  38.         *scratchbig   = "/dd",
  39.         *uucphost     = '\0',
  40.         *inhost       = '\0',
  41.         *bithost      = '\0',
  42.         *organization = '\0',
  43.         *nodename     = '\0',
  44.         *sitename     = '\0',
  45.         *name         = '\0',
  46.         *pager        = '\0';                /* optional reader for MailX */
  47.  
  48. /* Pointer to the host that provides our Usenet newsfeed.  This can be either
  49.    our UUCP, Internet or Bitnet host.  If no host is given in the global
  50.    parameter file, the default host becomes the first system listed in the
  51.    /DD/SYS/UUCP/Systems file.  This default can be overridden by -S in
  52.    POSTNEWS. */
  53.  
  54. QQ char *newshost = '\0';
  55.  
  56. /* bounced mail goes here unless overridden in Parameters file */
  57. QQ char *errorsto = "postmaster";
  58.  
  59. QQ char quotechar = '>';              /* quote character used in ~m in mail */
  60.                                       /* and postnews */
  61. QQ char sepsym = '@';                 /* mail separator symbol -- BAS       */
  62. QQ int rec_window = 1;                /* default window size for gproto()   */
  63. QQ int rec_segment = K64;             /* default segment size for gproto()  */
  64. QQ flag fullheader = TRUE;            /* default to showing full header     */
  65. QQ flag auto_rot  = FALSE;            /* made direct page variables         */
  66. QQ flag cc_prompt = FALSE;            /*                                    */
  67. QQ flag fsactive  = FALSE;            /* assume file server is turned off   */
  68. QQ flag dropDTR   = FALSE;            /* +++ATH to hand up modem.           */
  69.                                       /* Default is use +++ATH              */
  70. QQ unsigned myuid;
  71.  
  72. /* Global temp variable.  NEVER used to return a value, nor across a
  73.    subroutine call which might use this temp.  May be used to parse a string
  74.    into words via getargs(). */
  75.  
  76. char temp[1024];
  77.  
  78. /* global temp variable which contains a filename.  Use only long enough
  79.    to open a file. */
  80.  
  81. char fname[100];
  82.  
  83. char tz[10] = "";
  84. char user[PWNSIZ+1] = "";
  85.  
  86.  
  87.  
  88. /* getparam -- read parameter file + get other parameters */
  89.  
  90. int getparam()
  91. {
  92.      myuid = getuid();
  93.      sprintf (fname, "%s/Parameters", UUCPSYS);
  94.      return (readparam (fname, TRUE));
  95. }
  96.  
  97.  
  98.  
  99. /* readparam  -- read parameter file for system parameters */
  100.  
  101. int readparam (filename, global)
  102. char *filename;                  /* parameter file filename */
  103. int global;                      /* is this the system-wide parameter file? */
  104. {
  105.      char line[132];
  106.      FILE *file;
  107.      register char *p;
  108.      char *words[WORDSIZE], *tmp_ptr;
  109.      int n, which, linecount;
  110.  
  111.      asetuid (0);
  112.  
  113.      if ((file = fopen (filename, "r")) == NULL)
  114.        {
  115.           if (!global)              /* it's OK if we can't find a user's */
  116.             {
  117.                asetuid (myuid);
  118.                return (TRUE);       /* parameter file */
  119.             }
  120.           fputs ("readparam: cannot open Parameters\n", stderr);
  121.           asetuid (myuid);
  122.           return (FALSE);
  123.        }
  124.      asetuid (myuid);
  125.      p = line;
  126.      linecount = 0;
  127.  
  128.      /* ignored comments lines starting with #, *, <space>, <tab> or <cr> */
  129.      while (mfgets (p, sizeof (line), file) != NULL)
  130.        {
  131.           ++linecount;
  132.  
  133.           if (ISCOMMENT (*p) )
  134.                continue;
  135.  
  136.           strcpy (temp, p);
  137.  
  138.           /* Changed to prevent bus errors on incomplete entries -- BGP */
  139.           if ((n = getargs (words, temp, WORDSIZE)) == 1)
  140.             {
  141.                badentry (p, line, FALSE);
  142.                continue;
  143.             }
  144.  
  145.           if (words[1][0] != '=')
  146.             {
  147.                fprintf (stderr,
  148.                         "readparam: illegal parameter line: %s at line %d\n",
  149.                         p, linecount);
  150.                return (FALSE);
  151.             }
  152.  
  153.           /*-----> Parameters in either mailrc or global param file <-----*/
  154.  
  155.           /* organization */
  156.           else if (strucmp (*words, "organization") == 0)
  157.             {
  158.                if (n < 3)
  159.                  {
  160.                     badentry (p, linecount, FALSE);
  161.                     continue;
  162.                  }
  163.  
  164.                if (*organization == '\0')
  165.                     if ((organization = strdup (words[2])) == NULL)
  166.                          badentry("organization", linecount, TRUE);
  167.             }
  168.  
  169.           /* prompt Cc:? */
  170.           else if (strucmp (*words, "cc_prompt") == 0
  171.                    || strucmp (*words, "askcc") == 0)
  172.             {
  173.                if (n < 3)
  174.                     badentry (p, linecount, FALSE);
  175.                else
  176.                     cc_prompt = setonoff (*(words+2), linecount);
  177.             }
  178.  
  179.           /* Automatically un-rot rot13'ed news articles? */
  180.           else if (strucmp (*words, "auto_rot") == 0)
  181.             {
  182.                if (n < 3)
  183.                     badentry (p, linecount, FALSE);
  184.                else
  185.                     auto_rot = setonoff (*(words+2), linecount);
  186.             }
  187.  
  188.           /* get real name */
  189.           else if (strucmp (*words, "realname") == 0)
  190.             {
  191.                if (n < 3)
  192.                  {
  193.                     badentry (p, linecount, FALSE);
  194.                     continue;
  195.                  }
  196.  
  197.                if ((name = strdup (words[2])) == NULL)
  198.                     badentry ("realname", linecount, TRUE);
  199.             }
  200.  
  201.           /* Get file viewer such as MORE, VU for reading mail. */
  202.           else if (strucmp (*words, "pager") == 0)
  203.             {
  204.                if (n < 3)
  205.                  {
  206.                     badentry (p, linecount, FALSE);
  207.                     continue;
  208.                  }
  209.  
  210.                if ((pager = strdup (words[2])) == NULL)
  211.                     badentry ("pager", linecount, TRUE);
  212.             }
  213.  
  214.           /* Set default quote char for ~m in mail and postnews */
  215.           else if (strucmp (*words, "quote") == 0)
  216.             {
  217.                if (n < 3)
  218.                     badentry (p, linecount, FALSE);
  219.                else
  220.                     quotechar = words[2][0];
  221.             }
  222.  
  223.           /* This allows for something besides a '@' character between a user
  224.              and their address -BAS */
  225.  
  226.           else if (strucmp (*words, "separatesym") == 0)
  227.             {
  228.                if (n < 3)
  229.                     badentry (p, linecount, FALSE);
  230.                else
  231.                     sepsym = words[2][0];
  232.             }
  233.  
  234.           else if (strucmp (*words, "fullheader") == 0)
  235.             {
  236.                if (n < 3)
  237.                     badentry (p, linecount, FALSE);
  238.                else
  239.                     fullheader = setonoff (*(words+2), linecount);
  240.             }
  241.  
  242.           else if (!global)              /* allow following parameters only */
  243.                continue;                 /* in /dd/sys/uucp/Parameters */
  244.  
  245.           /*------> Parameters only from global parameter file <------*/
  246.  
  247.           /* use +++ATH or drop DTR to hang up modem? */
  248.           else if (strucmp (*words, "hangup") == 0)
  249.             {
  250.                if (n < 3)
  251.                     badentry (p, linecount, FALSE);
  252.                else
  253.                     dropDTR = (strucmp (*(words+2), "DTR") == 0) ? TRUE
  254.                                                                  : FALSE;
  255.             }
  256.  
  257.           /* who to send bounced mail to.  Default is 'postmaster'. */
  258.           else if (strucmp (*words, "errorsto") == 0)
  259.             {      
  260.                if (n < 3)
  261.                  {
  262.                     badentry (p, linecount, FALSE);
  263.                     continue;
  264.                  }
  265.                else
  266.                     tmp_ptr = errorsto;
  267.  
  268.                if ((errorsto = strdup (words[2])) == NULL)
  269.                     errorsto = tmp_ptr;
  270.             }
  271.  
  272.           /* nodename */
  273.           else if (strucmp (*words, "nodename") == 0)
  274.             {
  275.                if (n < 3)
  276.                  {
  277.                     badentry (p, linecount, FALSE);
  278.                     continue;
  279.                  }
  280.  
  281.                if ((nodename = strdup (words[2])) == NULL)
  282.                     badentry ("nodename", linecount, TRUE);
  283.             }
  284.  
  285.           /* sitename (nodename plus domain) */
  286.           else if (strucmp (*words, "sitename") == 0)
  287.             {
  288.                if (n < 3)
  289.                  {
  290.                     badentry (p, linecount, FALSE);
  291.                     continue;
  292.                  }
  293.  
  294.                if (*(words+2) != '\0')
  295.                  {
  296.                     if ((sitename = strdup (words[2])) == NULL)
  297.                          badentry ("sitename", linecount, TRUE);
  298.                  }
  299.                else
  300.                  {
  301.                     sitename = (char *) malloc (strlen (nodename) + 6);
  302.                     strcat (strcpy (sitename, nodename), ".UUCP");
  303.                  }
  304.             }
  305.  
  306.           /* timezone */
  307.           else if (strucmp (*words, "tz") == 0)
  308.                switch (n)
  309.                  {
  310.                     case 3:
  311.                          /* if given only one TZ string, return it */
  312.                          strcpy (tz, *(words+2));
  313.                          break;
  314.  
  315.                     case 4:
  316.                          strcpy (tz, isdst() ? *(words+3) : *(words+2));
  317.                          break;
  318.  
  319.                     default:
  320.                          badentry (p, linecount, FALSE);
  321.                          break;
  322.                  }
  323.  
  324.           /* scratch directory */
  325.           else if (strucmp (*words, "scratch") == 0)
  326.             {
  327.                if (n < 3)
  328.                  {
  329.                     badentry (p, linecount, FALSE);
  330.                     continue;
  331.                  }
  332.                else
  333.                     tmp_ptr = scratchdir;
  334.  
  335.                if ((scratchdir = strdup (words[2])) == NULL)
  336.                     scratchdir = tmp_ptr;
  337.             }
  338.  
  339.           /* big scratch directory */
  340.           else if (strucmp (*words, "bigscratch") == 0)
  341.             {
  342.                if (n < 3)
  343.                  {
  344.                     badentry (p, linecount, FALSE);
  345.                     continue;
  346.                  }
  347.                else
  348.                     tmp_ptr = scratchbig;
  349.  
  350.                if ((scratchbig = strdup (words[2])) == NULL)
  351.                     scratchbig = tmp_ptr;
  352.             }
  353.  
  354.           /* UUCP smart host */
  355.           else if (strucmp (*words, "uucphost") == 0)
  356.             {
  357.                if (n < 3)
  358.                  {
  359.                     badentry (p, linecount, FALSE);
  360.                     continue;
  361.                  }
  362.  
  363.                if ((uucphost = (char *) malloc (strlen (words[2])+2)) == NULL)
  364.                      badentry ("uucphost", linecount, TRUE);
  365.  
  366.                strcat (strcpy (uucphost, words[2]), "!");
  367.             }
  368.  
  369.           /* Internet smart host */
  370.           else if (strucmp (*words, "inhost") == 0)
  371.             {
  372.                if (n < 3)
  373.                  {
  374.                     badentry (p, linecount, FALSE);
  375.                     continue;
  376.                  }
  377.  
  378.                if ((inhost = (char *) malloc (strlen (words[2])+2)) == NULL)
  379.                      badentry ("inhost", linecount, TRUE);
  380.  
  381.                strcat (strcpy (inhost, words[2]), "!");
  382.             }
  383.  
  384.           /* Bitnet smart host */
  385.           else if (strucmp (*words, "bithost") == 0)
  386.             {
  387.                if ((bithost = (char *) malloc (strlen (words[2])+2)) == NULL)
  388.                      badentry ("bithost", linecount, TRUE);
  389.  
  390.                strcat (strcpy (bithost, words[2]), "!");
  391.             }
  392.  
  393.           /* Default Usenet newsfeed host. */
  394.           else if (strucmp (*words, "newshost") == 0)
  395.             {
  396.                if (n < 3)
  397.                  {
  398.                     badentry (p, linecount, FALSE);
  399.                     continue;
  400.                  }
  401.  
  402.                if ((newshost = (char *) malloc (strlen (words[2])+1)) == NULL)
  403.                      badentry ("newshost", linecount, TRUE);
  404.  
  405.                strcpy (newshost, words[2]);
  406.             }
  407.  
  408.           /* UUCP receiving window size */
  409.           else if (strucmp (*words, "window") == 0)
  410.             {
  411.                if (n < 3)
  412.                  {
  413.                     badentry (p, linecount, FALSE);
  414.                     continue;
  415.                  }
  416.                else
  417.                     rec_window = atoi (*(words+2));
  418.  
  419.                if (rec_window < 1 || rec_window > 7)
  420.                  {
  421.                     fprintf (stderr, "readparam: illegal window size: %s at line %d\n",
  422.                                words[2], linecount);
  423.                     return (FALSE);
  424.                  }
  425.             }
  426.  
  427.           /* file server turned on? */
  428.           else if (strucmp (*words, "server") == 0)
  429.             {
  430.                if (n < 3)
  431.                     badentry (p, linecount, FALSE);
  432.                else
  433.                     fsactive = setonoff (*(words+2), linecount);
  434.             }
  435.        }
  436.  
  437.      if (global  &&  *inhost == '\0'  &&  *bithost == '\0')
  438.        {
  439.           fputs ("readparam: must have either 'inhost' or 'bithost' parameter\n",
  440.                  stderr);
  441.           return (FALSE);
  442.        }
  443.  
  444.      return (TRUE);
  445. }
  446.  
  447.  
  448.  
  449. int setonoff (word, thisline)
  450. register char *word;
  451. int thisline;
  452. {
  453.      if ((strucmp (word, "on") == 0)  ||  (strucmp(word, "yes") == 0))
  454.           return (TRUE);
  455.  
  456.      if ((strucmp (word, "off") == 0) ||  (strucmp(word, "no") == 0))
  457.           return (FALSE);
  458.  
  459.      fprintf (stderr,
  460.               "readparam: illegal setonoff() value: '%s' at line %d\n",
  461.               word, thisline);
  462.      exit (ABORT);
  463. }
  464.  
  465.  
  466.  
  467. int badentry (param, line, isdup)
  468. char *param;
  469. int line;
  470. flag isdup;
  471. {
  472.      char *getparam = "getparam: ";
  473.  
  474.      if (isdup)
  475.        {
  476.           sprintf (temp, "%scan't dup parameter '%s' at line %d...error %d",
  477.                          getparam, param, line, errno);
  478.           fatal (temp);
  479.        }
  480.      else
  481.        {
  482.           fprintf (stderr, "%sbad parameter line: %s at line %d\n",
  483.                            getparam, param, line);
  484.        }
  485. }
  486.  
  487.  
  488.  
  489. /* Are we in Daylight Savings Time?  Return TRUE if we are.  FALSE if we
  490.    are not. */
  491.  
  492. int isdst()
  493. {
  494.      struct tm *ltime;
  495. #ifdef _OSK
  496.      time_t t;
  497. #else
  498.      long t;
  499. #endif
  500.  
  501.      time (&t);
  502.      ltime = localtime (&t);
  503.  
  504.      /* DST run from 2 a.m. of *first* Sunday in April till last Sunday in
  505.         October.  Fixed wrong DST start day. --REB */
  506.  
  507.      /* Jan-Mar, Nov-Dec */
  508.      if ((ltime->tm_mon < 3) || (ltime->tm_mon > 9))
  509.           return (FALSE);
  510.  
  511.      /* May-Sep */
  512.      else if ((ltime->tm_mon > 3) && (ltime->tm_mon < 9))
  513.           return (TRUE);
  514.  
  515.      else if (ltime->tm_mon == 3)
  516.        {
  517.           /* after 2 a.m. of the *first* Sunday of April? */
  518.           if (((ltime->tm_mday - ltime->tm_wday + 7) > 7)
  519.                 && (ltime->tm_hour >= 2))
  520.             {
  521.                return (TRUE);                /* DST */
  522.             }
  523.           else
  524.                return (FALSE);
  525.        }
  526.      else
  527.        {
  528.           /* after 2am of the last Sunday of Oct? */
  529.           if (((ltime->tm_mday - ltime->tm_wday + 7) > 31)
  530.                 && (ltime->tm_hour >= 2))
  531.             {
  532.                return (FALSE);
  533.             }
  534.           else
  535.                return (TRUE);                 /* DST */
  536.        }
  537. }
  538.