home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / uuconf.subproj / tcalou.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  4.7 KB  |  208 lines

  1. /* tcalou.c
  2.    Find callout login name and password from Taylor UUCP configuration files.
  3.  
  4.    Copyright (C) 1992, 1993 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP uuconf library.
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Library General Public License
  10.    as published by the Free Software Foundation; either version 2 of
  11.    the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Library General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Library General Public
  19.    License along with this library; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucnfi.h"
  27.  
  28. #if USE_RCS_ID
  29. const char _uuconf_tcalou_rcsid[] = "$Id: tcalou.c,v 1.8 1995/06/21 19:24:24 ian Rel $";
  30. #endif
  31.  
  32. #include <errno.h>
  33.  
  34. static int icsys P((pointer pglobal, int argc, char **argv, pointer pvar,
  35.             pointer pinfo));
  36.  
  37. /* Find the callout login name and password for a system from the
  38.    Taylor UUCP configuration files.  */
  39.  
  40. int
  41. uuconf_taylor_callout (pglobal, qsys, pzlog, pzpass)
  42.      pointer pglobal;
  43.      const struct uuconf_system *qsys;
  44.      char **pzlog;
  45.      char **pzpass;
  46. {
  47.   struct sglobal *qglobal = (struct sglobal *) pglobal;
  48.   boolean flookup;
  49.   struct uuconf_cmdtab as[2];
  50.   char **pz;
  51.   int iret;
  52.   pointer pinfo;
  53.  
  54.   *pzlog = NULL;
  55.   *pzpass = NULL;
  56.  
  57.   flookup = FALSE;
  58.  
  59.   if (qsys->uuconf_zcall_login != NULL)
  60.     {
  61.       if (strcmp (qsys->uuconf_zcall_login, "*") == 0)
  62.     flookup = TRUE;
  63.       else
  64.     {
  65.       *pzlog = strdup (qsys->uuconf_zcall_login);
  66.       if (*pzlog == NULL)
  67.         {
  68.           qglobal->ierrno = errno;
  69.           return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
  70.         }
  71.     }
  72.     }
  73.  
  74.   if (qsys->uuconf_zcall_password != NULL)
  75.     {
  76.       if (strcmp (qsys->uuconf_zcall_password, "*") == 0)
  77.     flookup = TRUE;
  78.       else
  79.     {
  80.       *pzpass = strdup (qsys->uuconf_zcall_password);
  81.       if (*pzpass == NULL)
  82.         {
  83.           qglobal->ierrno = errno;
  84.           if (*pzlog != NULL)
  85.         {
  86.           free ((pointer) *pzlog);
  87.           *pzlog = NULL;
  88.         }
  89.           return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
  90.         }
  91.     }
  92.     }
  93.  
  94.   if (! flookup)
  95.     {
  96.       if (*pzlog == NULL && *pzpass == NULL)
  97.     return UUCONF_NOT_FOUND;
  98.       return UUCONF_SUCCESS;
  99.     }
  100.  
  101.   as[0].uuconf_zcmd = qsys->uuconf_zname;
  102.   as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 0;
  103.   if (*pzlog == NULL)
  104.     as[0].uuconf_pvar = (pointer) pzlog;
  105.   else
  106.     as[0].uuconf_pvar = NULL;
  107.   as[0].uuconf_pifn = icsys;
  108.  
  109.   as[1].uuconf_zcmd = NULL;
  110.  
  111.   if (*pzpass == NULL)
  112.     pinfo = (pointer) pzpass;
  113.   else
  114.     pinfo = NULL;
  115.  
  116.   iret = UUCONF_SUCCESS;
  117.  
  118.   for (pz = qglobal->qprocess->pzcallfiles; *pz != NULL; pz++)
  119.     {
  120.       FILE *e;
  121.  
  122.       e = fopen (*pz, "r");
  123.       if (e == NULL)
  124.     {
  125.       if (FNO_SUCH_FILE ())
  126.         continue;
  127.       qglobal->ierrno = errno;
  128.       iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
  129.       break;
  130.     }
  131.  
  132.       iret = uuconf_cmd_file (pglobal, e, as, pinfo,
  133.                   (uuconf_cmdtabfn) NULL, 0,
  134.                   qsys->uuconf_palloc);
  135.       (void) fclose (e);
  136.  
  137.       if (iret != UUCONF_SUCCESS)
  138.     break;
  139.       if (*pzlog != NULL)
  140.     break;
  141.     }
  142.  
  143.   if (iret != UUCONF_SUCCESS)
  144.     {
  145.       qglobal->zfilename = *pz;
  146.       return iret | UUCONF_ERROR_FILENAME;
  147.     }
  148.  
  149.   if (*pzlog == NULL && *pzpass == NULL)
  150.     return UUCONF_NOT_FOUND;
  151.  
  152.   return UUCONF_SUCCESS;
  153. }
  154.  
  155. /* Copy the login name and password onto the heap and set the
  156.    pointers.  The pzlog argument is passed in pvar, and the pzpass
  157.    argument is passed in pinfo.  */
  158.  
  159. static int
  160. icsys (pglobal, argc, argv, pvar, pinfo)
  161.      pointer pglobal;
  162.      int argc;
  163.      char **argv;
  164.      pointer pvar;
  165.      pointer pinfo;
  166. {
  167.   struct sglobal *qglobal = (struct sglobal *) pglobal;
  168.   char **pzlog = (char **) pvar;
  169.   char **pzpass = (char **) pinfo;
  170.  
  171.   if (argc < 2 || argc > 3)
  172.     return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
  173.  
  174.   if (pzlog != NULL)
  175.     {
  176.       *pzlog = strdup (argv[1]);
  177.       if (*pzlog == NULL)
  178.     {
  179.       qglobal->ierrno = errno;
  180.       return (UUCONF_MALLOC_FAILED
  181.           | UUCONF_ERROR_ERRNO
  182.           | UUCONF_CMDTABRET_EXIT);
  183.     }
  184.     }
  185.  
  186.   if (pzpass != NULL)
  187.     {
  188.       if (argc < 3)
  189.     *pzpass = strdup ("");
  190.       else
  191.     *pzpass = strdup (argv[2]);
  192.       if (*pzpass == NULL)
  193.     {
  194.       qglobal->ierrno = errno;
  195.       if (pzlog != NULL)
  196.         {
  197.           free ((pointer) *pzlog);
  198.           *pzlog = NULL;
  199.         }
  200.       return (UUCONF_MALLOC_FAILED
  201.           | UUCONF_ERROR_ERRNO
  202.           | UUCONF_CMDTABRET_EXIT);
  203.     }
  204.     }
  205.  
  206.   return UUCONF_CMDTABRET_EXIT;
  207. }
  208.