








             Configuration Mechanisms in C News


                       Henry Spencer

                      Dept. of Zoology
                   University of Toronto





_I_n_t_r_o

There is an overall problem with news  stuff  in  that  some
pathnames  and  such are site-specific.  In C News this hits
both shell files and C programs,  the  former  a  particular
inconvenience  because they are not compiled and hence can't
easily pick it up from a library at compile time.  It's easy
to edit shell files, but there are too many of them for this
to be very convenient.

Several mechanisms are needed to solve the entire problem..

_C_o_n_f_i_g_u_r_a_t_i_o_n _P_a_r_a_m_e_t_e_r_s

Although there are many things that theoretically  could  be
site-specific, there are only a few that really crop up con-
stantly, are highly likely to change, and have to  be  known
to  running  code.   Here's  a tentative list, with internal
names and common defaults:

lll.     NEWSARTS        pathname     of     the     article
database        /usr/spool/news   NEWSCTL pathname   of  the
control-file  directory  /usr/lib/news  NEWSBIN pathname  of
the         program         directory       /usr/lib/newsbin
NEWSPATH        shell        PATH        setting         for
news     /bin:/usr/bin   NEWSUMASK       default  umask  for
file creation 002 NEWSMASTER      where to send  mail  about
trouble        usenet       NEWSCONFIG      see      "Subst"
section     /usr/lib/news/bin/config


_E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s

All C News programs that care about configuration parameters
are  expected to look at environment variables with the same
names as the parameters, and to use the  environment  values
to  override  internal defaults.  This is primarily aimed at
testing and special purposes rather than production use,  as
there is a fundamental problem: the environment is insecure.



                       5 Sept 1989





                           - 2 -


The environment variables are nevertheless very useful.

There is a need for a canned interface  to  the  environment
variables,  to simplify their use.  There is also a require-
ment for centrally-set defaults for normal  production  use.
These requirements are addressed differently for C and shell
programs.

_C _I_n_t_e_r_f_a_c_e

_L_i_b_c_n_e_w_s provides a set of inquiry functions:


     char *fullartfile(char *name);
          Returns a full pathname for the  NEWSARTS-relative
          file  _n_a_m_e;  if _n_a_m_e is NULL, returns the value of
          NEWSARTS.

     char *ctlfile(char *name);
          Returns a full pathname for  the  NEWSCTL-relative
          file  _n_a_m_e;  if _n_a_m_e is NULL, returns the value of
          NEWSCTL.

     char *binfile(char *name);
          Returns a full pathname for  the  NEWSBIN-relative
          file  _n_a_m_e;  if _n_a_m_e is NULL, returns the value of
          NEWSBIN.

     char *newspath(void);
          Returns the value of the NEWSPATH parameter.

     int newsumask(void);
          Returns the value of the NEWSUMASK parameter.

     char *newsmaster(void);
          Returns the value of NEWSMASTER.

Functions which return  string  values  return  pointers  to
areas  which  they may later re-use, so the values should be
copied if they are to persist past later  calls.   There  is
also  a  function _a_r_t_f_i_l_e which returns a relative pathname,
as a special-purpose optimization, and a function  _c_d  which
does  a  _c_h_d_i_r and notes the location for future use by _a_r_t_-
_f_i_l_e.

The first inquiry function to be invoked automatically  ini-
tializes their internal housekeeping.  Against the possibil-
ity of malicious setting of environment  variables,  if  any
environment  variables  are  in  fact  present  to  override
default values, and at least one value in fact differs  from
the  default, this initialization includes a call to a func-
tion the user must supply:





                       5 Sept 1989





                           - 3 -


     void unprivileged(char *reason);
          Drop any special powers that should not be  avail-
          able to a normal user program, e.g. those obtained
          by set-uid bit.  _R_e_a_s_o_n is the name of  the  first
          environment variable that caused trouble.

Programs that do not use the set-uid bit can normally have a
null   implementation  of  _u_n_p_r_i_v_i_l_e_g_e_d,  but  to  encourage
thought about the matter this is _n_o_t provided as a default.

Suitable external declarations for all these  functions  can
be  found in the include file _c_o_n_f_i_g._h in the C News include
directory.

_S_h_e_l_l _i_n_t_e_r_f_a_c_e

All shell files that want to know  configuration  parameters
should  execute NEWSCTL/bin/config using the `.' command; it
sets shell variables with the same names as the  parameters.
Note that it does not export these variables, so subordinate
shell files need to pick up _c_o_n_f_i_g themselves.  This  is  to
preserve the property that subordinate programs see environ-
ment variables set only if the user set them.

_S_u_b_s_t

The alert mind will have noticed a circularity in the previ-
ous  section:  it's  not possible to find NEWSCTL/bin/config
until one knows where NEWSCTL is.  There are also occasional
annoyances  in that documentation and such wants to know the
local defaults, and can't get them  from  either  the  C  or
shell interface.  Hence the use of _s_u_b_s_t.

_S_u_b_s_t does substitutions into source files (including  shell
files)  in  such  a way that it is not necessary to maintain
two versions of the file.  In the top-level directory of the
C  News  sources are four files: _s_u_b_s_t itself, the _s_u_b_s_t_i_t_u_-
_t_i_o_n_s file defining the values of the configuration  parame-
ters,  and  _s_u_b_s_t._h_s  and _s_u_b_s_t._g_c, which are lists of files
(relative to the top-level source directory) that need  sub-
stitutions  done.   (The  use of two `list' files reflects C
News's dual authorship.) See the _s_u_b_s_t(1)  manual  page  for
the gory details of the syntax.  The only C program affected
is the configuration-inquiry part of the  library,  but  all
shell  files  that  need any of the configuration parameters
need to be in one of the lists.

_P_r_o_g_r_a_m _s_t_a_r_t_u_p

As a result of all this, a C program which needs to  know  a
configuration parameter simply calls the appropriate inquiry
function, and is prepared for a return call to _u_n_p_r_i_v_i_l_e_g_e_d.
A  shell  program has to do a bit more work; it should start
with something on the order of:



                       5 Sept 1989





                           - 4 -



        #! /bin/sh
        # foobar - does foo, bar, and bletch

        # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
        . ${NEWSCONFIG-/var/local/lib/news/bin/config}

        PATH=$NEWSCTL/bin:$NEWSBIN/xxx:$NEWSBIN:$NEWSPATH ; export PATH
        umask $NEWSUMASK

(A prototype for this is in conf/proto.sh.) (See  an  accom-
panying  document  for  the  logic of the PATH setting.) The
NEWSCONFIG configuration parameter specifies the location of
the  configurer shell program, which is then executed to set
up the rest of the parameters.  The reason for doing it this
way  is  to  ensure that new parameters can be added without
having to change every shell file.








































                       5 Sept 1989


