1/* hunk.c
2   Get information about an unknown system from the HDB Permissions file.
3
4   Copyright (C) 1992 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.
23   */
24
25#include "uucnfi.h"
26
27#if USE_RCS_ID
28const char _uuconf_hunk_rcsid[] = "$Id: hunk.c,v 1.7 2002/03/05 19:10:42 ian Rel $";
29#endif
30
31#include <errno.h>
32
33/* Get information about an unknown system from the HDB Permissions
34   file.  This doesn't run the remote.unknown shell script, because
35   that's too system dependent.  */
36
37int
38uuconf_hdb_system_unknown (pglobal, qsys)
39     pointer pglobal;
40     struct uuconf_system *qsys;
41{
42  struct sglobal *qglobal = (struct sglobal *) pglobal;
43  int iret;
44  boolean ffirst;
45  struct shpermissions *qperm;
46  struct uuconf_system *qalt;
47
48  if (! qglobal->qprocess->fhdb_read_permissions)
49    {
50      iret = _uuconf_ihread_permissions (qglobal);
51      if (iret != UUCONF_SUCCESS)
52	return iret;
53    }
54
55  _uuconf_uclear_system (qsys);
56  qsys->uuconf_palloc = uuconf_malloc_block ();
57  if (qsys->uuconf_palloc == NULL)
58    {
59      qglobal->ierrno = errno;
60      return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
61    }
62
63  ffirst = TRUE;
64
65  for (qperm = qglobal->qprocess->qhdb_permissions;
66       qperm != NULL;
67       qperm = qperm->qnext)
68    {
69      char **pz;
70
71      if (qperm->pzlogname == NULL
72	  || qperm->pzlogname == (char **) &_uuconf_unset)
73	continue;
74
75      for (pz = qperm->pzlogname; *pz != NULL; pz++)
76	{
77	  if (ffirst)
78	    {
79	      qalt = qsys;
80	      ffirst = FALSE;
81	    }
82	  else
83	    {
84	      struct uuconf_system **pq;
85
86	      qalt = ((struct uuconf_system *)
87		      uuconf_malloc (qsys->uuconf_palloc,
88				     sizeof (struct uuconf_system)));
89	      if (qalt == NULL)
90		{
91		  qglobal->ierrno = errno;
92		  return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
93		}
94
95	      _uuconf_uclear_system (qalt);
96	      for (pq = &qsys->uuconf_qalternate;
97		   *pq != NULL;
98		   pq = &(*pq)->uuconf_qalternate)
99		;
100	      *pq = qalt;
101	    }
102
103	  /* We recognize LOGNAME=OTHER specially, although this
104	     appears to be an SCO innovation.  */
105	  if (strcmp (*pz, "OTHER") == 0)
106	    qalt->uuconf_zcalled_login = (char *) "ANY";
107	  else
108	    qalt->uuconf_zcalled_login = *pz;
109	  qalt->uuconf_fcall = FALSE;
110	  qsys->uuconf_fcalled = TRUE;
111	  if (qperm->frequest >= 0)
112	    qsys->uuconf_fsend_request = qperm->frequest;
113	  else
114	    qsys->uuconf_fsend_request = FALSE;
115	  qsys->uuconf_fcalled_transfer = qperm->fsendfiles;
116	  qsys->uuconf_pzremote_send = qperm->pzread;
117	  qsys->uuconf_pzremote_receive = qperm->pzwrite;
118	  qsys->uuconf_fcallback = qperm->fcallback;
119	  qsys->uuconf_zlocalname = qperm->zmyname;
120	  qsys->uuconf_zpubdir = qperm->zpubdir;
121	}
122    }
123
124  if (ffirst)
125    return UUCONF_NOT_FOUND;
126
127  /* HDB permits local requests to receive to any directory, which is
128     not the default put in by _uuconf_isystem_basic_default.  We set
129     it here instead.  */
130  for (qalt = qsys; qalt != NULL; qalt = qalt->uuconf_qalternate)
131    {
132      iret = _uuconf_iadd_string (qglobal, (char *) ZROOTDIR,
133				  FALSE, FALSE,
134				  &qalt->uuconf_pzlocal_receive,
135				  qsys->uuconf_palloc);
136      if (iret != UUCONF_SUCCESS)
137	return iret;
138    }
139
140  return _uuconf_isystem_basic_default (qglobal, qsys);
141}
142